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