4 * ***** BEGIN GPL LICENSE BLOCK *****
6 * This shader is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version. The Blender
10 * Foundation also sells licenses for use in proprietary software under
11 * the Blender License. See http://www.blender.org/BL/ for information
14 * This shader is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this shader; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 * The Original Code is Copyright (C) 2005 Blender Foundation.
24 * All rights reserved.
26 * The Original Code is: all of this file.
28 * Contributor(s): Brecht Van Lommel.
30 * ***** END GPL LICENSE BLOCK *****
33 #ifndef GPU_EXTENSIONS_H
34 #define GPU_EXTENSIONS_H
44 typedef struct GPUTexture GPUTexture;
46 struct GPUFrameBuffer;
47 typedef struct GPUFrameBuffer GPUFrameBuffer;
50 typedef struct GPUOffScreen GPUOffScreen;
53 typedef struct GPUShader GPUShader;
55 /* GPU extensions support */
57 void GPU_extensions_disable(void);
58 void GPU_extensions_init(void); /* call this before running any of the functions below */
59 void GPU_extensions_exit(void);
60 int GPU_print_error(char *str);
62 int GPU_glsl_support(void);
63 int GPU_non_power_of_two_support(void);
64 int GPU_color_depth(void);
68 typedef enum GPUDeviceType {
69 GPU_DEVICE_NVIDIA = (1<<0),
70 GPU_DEVICE_ATI = (1<<1),
71 GPU_DEVICE_INTEL = (1<<2),
72 GPU_DEVICE_SOFTWARE = (1<<3),
73 GPU_DEVICE_UNKNOWN = (1<<4),
74 GPU_DEVICE_ANY = (0xff)
77 typedef enum GPUOSType {
80 GPU_OS_UNIX = (1<<18),
84 typedef enum GPUDriverType {
85 GPU_DRIVER_OFFICIAL = (1<<24),
86 GPU_DRIVER_OPENSOURCE = (1<<25),
87 GPU_DRIVER_SOFTWARE = (1<<26),
88 GPU_DRIVER_UNKNOWN = (0xff0000)
91 int GPU_type_matches(GPUDeviceType device, GPUOSType os, GPUDriverType driver);
94 - always returns unsigned char RGBA textures
95 - if texture with non square dimensions is created, depending on the
96 graphics card capabilities the texture may actually be stored in a
97 larger texture with power of two dimensions. the actual dimensions
98 may be queried with GPU_texture_opengl_width/height. GPU_texture_coord_2f
99 calls glTexCoord2f with the coordinates adjusted for this.
100 - can use reference counting:
101 - reference counter after GPU_texture_create is 1
102 - GPU_texture_ref increases by one
103 - GPU_texture_free decreases by one, and frees if 0
104 - if created with from_blender, will not free the texture
107 GPUTexture *GPU_texture_create_1D(int w, float *pixels);
108 GPUTexture *GPU_texture_create_2D(int w, int h, float *pixels);
109 GPUTexture *GPU_texture_create_3D(int w, int h, int depth, float *fpixels);
110 GPUTexture *GPU_texture_create_depth(int w, int h);
111 GPUTexture *GPU_texture_from_blender(struct Image *ima,
112 struct ImageUser *iuser, double time, int mipmap);
113 void GPU_texture_free(GPUTexture *tex);
115 void GPU_texture_ref(GPUTexture *tex);
117 void GPU_texture_bind(GPUTexture *tex, int number);
118 void GPU_texture_unbind(GPUTexture *tex);
120 GPUFrameBuffer *GPU_texture_framebuffer(GPUTexture *tex);
122 int GPU_texture_target(GPUTexture *tex);
123 int GPU_texture_opengl_width(GPUTexture *tex);
124 int GPU_texture_opengl_height(GPUTexture *tex);
127 - this is a wrapper for an OpenGL framebuffer object (FBO). in practice
128 multiple FBO's may be created, to get around limitations on the number
129 of attached textures and the dimension requirements.
130 - after any of the GPU_framebuffer_* functions, GPU_framebuffer_restore must
131 be called before rendering to the window framebuffer again */
133 GPUFrameBuffer *GPU_framebuffer_create();
134 int GPU_framebuffer_texture_attach(GPUFrameBuffer *fb, GPUTexture *tex);
135 void GPU_framebuffer_texture_detach(GPUFrameBuffer *fb, GPUTexture *tex);
136 void GPU_framebuffer_texture_bind(GPUFrameBuffer *fb, GPUTexture *tex);
137 void GPU_framebuffer_texture_unbind(GPUFrameBuffer *fb, GPUTexture *tex);
138 void GPU_framebuffer_free(GPUFrameBuffer *fb);
140 void GPU_framebuffer_restore();
143 - wrapper around framebuffer and texture for simple offscreen drawing */
145 GPUOffScreen *GPU_offscreen_create(int width, int height);
146 void GPU_offscreen_free(GPUOffScreen *ofs);
147 void GPU_offscreen_bind(GPUOffScreen *ofs);
148 void GPU_offscreen_unbind(GPUOffScreen *ofs);
151 - only for fragment shaders now
152 - must call texture bind before setting a texture as uniform! */
154 GPUShader *GPU_shader_create(const char *vertexcode, const char *fragcode, const char *libcode); /*GPUShader *lib);*/
155 /*GPUShader *GPU_shader_create_lib(const char *code);*/
156 void GPU_shader_free(GPUShader *shader);
158 void GPU_shader_bind(GPUShader *shader);
159 void GPU_shader_unbind();
161 int GPU_shader_get_uniform(GPUShader *shader, char *name);
162 void GPU_shader_uniform_vector(GPUShader *shader, int location, int length,
163 int arraysize, float *value);
164 void GPU_shader_uniform_texture(GPUShader *shader, int location, GPUTexture *tex);
166 int GPU_shader_get_attribute(GPUShader *shader, char *name);
168 /* Vertex attributes for shaders */
170 #define GPU_MAX_ATTRIB 32
172 typedef struct GPUVertexAttribs {
177 } layer[GPU_MAX_ATTRIB];