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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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
40 /* GPU extensions support */
46 typedef struct GPUTexture GPUTexture;
48 struct GPUFrameBuffer;
49 typedef struct GPUFrameBuffer GPUFrameBuffer;
52 typedef struct GPUShader GPUShader;
54 void GPU_extensions_disable(void);
55 void GPU_extensions_init(void); /* call this before running any of the functions below */
56 void GPU_extensions_exit(void);
57 int GPU_extensions_minimum_support(void);
58 int GPU_print_error(char *str);
61 - always returns unsigned char RGBA textures
62 - if texture with non square dimensions is created, depending on the
63 graphics card capabilities the texture may actually be stored in a
64 larger texture with power of two dimensions. the actual dimensions
65 may be queried with GPU_texture_opengl_width/height. GPU_texture_coord_2f
66 calls glTexCoord2f with the coordinates adjusted for this.
67 - can use reference counting:
68 - reference counter after GPU_texture_create is 1
69 - GPU_texture_ref increases by one
70 - GPU_texture_free decreases by one, and frees if 0
71 - if created with from_blender, will not free the texture
74 GPUTexture *GPU_texture_create_1D(int w, float *pixels);
75 GPUTexture *GPU_texture_create_2D(int w, int h, float *pixels);
76 GPUTexture *GPU_texture_create_3D(int w, int h, int depth, float *fpixels);
77 GPUTexture *GPU_texture_create_depth(int w, int h);
78 GPUTexture *GPU_texture_from_blender(struct Image *ima,
79 struct ImageUser *iuser, double time, int mipmap);
80 void GPU_texture_free(GPUTexture *tex);
82 void GPU_texture_ref(GPUTexture *tex);
84 void GPU_texture_bind(GPUTexture *tex, int number);
85 void GPU_texture_unbind(GPUTexture *tex);
87 GPUFrameBuffer *GPU_texture_framebuffer(GPUTexture *tex);
89 int GPU_texture_target(GPUTexture *tex);
90 int GPU_texture_opengl_width(GPUTexture *tex);
91 int GPU_texture_opengl_height(GPUTexture *tex);
94 - this is a wrapper for an OpenGL framebuffer object (FBO). in practice
95 multiple FBO's may be created, to get around limitations on the number
96 of attached textures and the dimension requirements.
97 - after any of the GPU_framebuffer_* functions, GPU_framebuffer_restore must
98 be called before rendering to the window framebuffer again */
100 GPUFrameBuffer *GPU_framebuffer_create();
101 int GPU_framebuffer_texture_attach(GPUFrameBuffer *fb, GPUTexture *tex);
102 void GPU_framebuffer_texture_detach(GPUFrameBuffer *fb, GPUTexture *tex);
103 void GPU_framebuffer_texture_bind(GPUFrameBuffer *fb, GPUTexture *tex);
104 void GPU_framebuffer_texture_unbind(GPUFrameBuffer *fb, GPUTexture *tex);
105 void GPU_framebuffer_free(GPUFrameBuffer *fb);
107 void GPU_framebuffer_restore();
110 - only for fragment shaders now
111 - must call texture bind before setting a texture as uniform! */
113 GPUShader *GPU_shader_create(const char *vertexcode, const char *fragcode, const char *libcode); /*GPUShader *lib);*/
114 /*GPUShader *GPU_shader_create_lib(const char *code);*/
115 void GPU_shader_free(GPUShader *shader);
117 void GPU_shader_bind(GPUShader *shader);
118 void GPU_shader_unbind();
120 int GPU_shader_get_uniform(GPUShader *shader, char *name);
121 void GPU_shader_uniform_vector(GPUShader *shader, int location, int length,
122 int arraysize, float *value);
123 void GPU_shader_uniform_texture(GPUShader *shader, int location, GPUTexture *tex);
125 int GPU_shader_get_attribute(GPUShader *shader, char *name);
127 /* Vertex attributes for shaders */
129 #define GPU_MAX_ATTRIB 32
131 typedef struct GPUVertexAttribs {
136 } layer[GPU_MAX_ATTRIB];