2 * ***** BEGIN GPL LICENSE BLOCK *****
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * The Original Code is Copyright (C) 2005 Blender Foundation.
19 * All rights reserved.
21 * The Original Code is: all of this file.
23 * Contributor(s): Brecht Van Lommel.
25 * ***** END GPL LICENSE BLOCK *****
28 /** \file GPU_extensions.h
32 #ifndef __GPU_EXTENSIONS_H__
33 #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 int GPU_print_error(const char *str);
60 int GPU_glsl_support(void);
61 int GPU_non_power_of_two_support(void);
62 int GPU_display_list_support(void);
63 int GPU_color_depth(void);
64 void GPU_code_generate_glsl_lib(void);
65 int GPU_bicubic_bump_support(void);
66 int GPU_max_texture_size (void);
71 typedef enum GPUDeviceType {
72 GPU_DEVICE_NVIDIA = (1<<0),
73 GPU_DEVICE_ATI = (1<<1),
74 GPU_DEVICE_INTEL = (1<<2),
75 GPU_DEVICE_SOFTWARE = (1<<3),
76 GPU_DEVICE_UNKNOWN = (1<<4),
77 GPU_DEVICE_ANY = (0xff)
80 typedef enum GPUOSType {
83 GPU_OS_UNIX = (1<<10),
87 typedef enum GPUDriverType {
88 GPU_DRIVER_OFFICIAL = (1<<16),
89 GPU_DRIVER_OPENSOURCE = (1<<17),
90 GPU_DRIVER_SOFTWARE = (1<<18),
91 GPU_DRIVER_ANY = (0xff0000)
94 int GPU_type_matches(GPUDeviceType device, GPUOSType os, GPUDriverType driver);
97 * - always returns unsigned char RGBA textures
98 * - if texture with non square dimensions is created, depending on the
99 * graphics card capabilities the texture may actually be stored in a
100 * larger texture with power of two dimensions. the actual dimensions
101 * may be queried with GPU_texture_opengl_width/height. GPU_texture_coord_2f
102 * calls glTexCoord2f with the coordinates adjusted for this.
103 * - can use reference counting:
104 * - reference counter after GPU_texture_create is 1
105 * - GPU_texture_ref increases by one
106 * - GPU_texture_free decreases by one, and frees if 0
107 * - if created with from_blender, will not free the texture
110 GPUTexture *GPU_texture_create_1D(int w, float *pixels, char err_out[256]);
111 GPUTexture *GPU_texture_create_2D(int w, int h, float *pixels, char err_out[256]);
112 GPUTexture *GPU_texture_create_3D(int w, int h, int depth, int channels, float *fpixels);
113 GPUTexture *GPU_texture_create_depth(int w, int h, char err_out[256]);
114 GPUTexture *GPU_texture_create_vsm_shadow_map(int size, char err_out[256]);
115 GPUTexture *GPU_texture_from_blender(struct Image *ima,
116 struct ImageUser *iuser, bool is_data, double time, int mipmap);
117 GPUTexture *GPU_texture_from_preview(struct PreviewImage *prv, int mipmap);
118 void GPU_invalid_tex_init(void);
119 void GPU_invalid_tex_bind(int mode);
120 void GPU_invalid_tex_free(void);
122 void GPU_texture_free(GPUTexture *tex);
124 void GPU_texture_ref(GPUTexture *tex);
126 void GPU_texture_bind(GPUTexture *tex, int number);
127 void GPU_texture_unbind(GPUTexture *tex);
129 GPUFrameBuffer *GPU_texture_framebuffer(GPUTexture *tex);
131 int GPU_texture_target(GPUTexture *tex);
132 int GPU_texture_opengl_width(GPUTexture *tex);
133 int GPU_texture_opengl_height(GPUTexture *tex);
134 int GPU_texture_opengl_bindcode(GPUTexture *tex);
137 * - this is a wrapper for an OpenGL framebuffer object (FBO). in practice
138 * multiple FBO's may be created, to get around limitations on the number
139 * of attached textures and the dimension requirements.
140 * - after any of the GPU_framebuffer_* functions, GPU_framebuffer_restore must
141 * be called before rendering to the window framebuffer again */
143 GPUFrameBuffer *GPU_framebuffer_create(void);
144 int GPU_framebuffer_texture_attach(GPUFrameBuffer *fb, GPUTexture *tex, char err_out[256]);
145 void GPU_framebuffer_texture_detach(GPUFrameBuffer *fb, GPUTexture *tex);
146 void GPU_framebuffer_texture_bind(GPUFrameBuffer *fb, GPUTexture *tex, int w, int h);
147 void GPU_framebuffer_texture_unbind(GPUFrameBuffer *fb, GPUTexture *tex);
148 void GPU_framebuffer_free(GPUFrameBuffer *fb);
150 void GPU_framebuffer_restore(void);
151 void GPU_framebuffer_blur(GPUFrameBuffer *fb, GPUTexture *tex, GPUFrameBuffer *blurfb, GPUTexture *blurtex);
154 * - wrapper around framebuffer and texture for simple offscreen drawing
155 * - changes size if graphics card can't support it */
157 GPUOffScreen *GPU_offscreen_create(int width, int height, char err_out[256]);
158 void GPU_offscreen_free(GPUOffScreen *ofs);
159 void GPU_offscreen_bind(GPUOffScreen *ofs);
160 void GPU_offscreen_unbind(GPUOffScreen *ofs);
161 void GPU_offscreen_read_pixels(GPUOffScreen *ofs, int type, void *pixels);
162 int GPU_offscreen_width(GPUOffScreen *ofs);
163 int GPU_offscreen_height(GPUOffScreen *ofs);
166 * - only for fragment shaders now
167 * - must call texture bind before setting a texture as uniform! */
169 GPUShader *GPU_shader_create(const char *vertexcode, const char *fragcode, const char *libcode, const char *defines);
170 void GPU_shader_free(GPUShader *shader);
172 void GPU_shader_bind(GPUShader *shader);
173 void GPU_shader_unbind(void);
175 int GPU_shader_get_uniform(GPUShader *shader, const char *name);
176 void GPU_shader_uniform_vector(GPUShader *shader, int location, int length,
177 int arraysize, float *value);
178 void GPU_shader_uniform_texture(GPUShader *shader, int location, GPUTexture *tex);
179 void GPU_shader_uniform_int(GPUShader *shader, int location, int value);
181 int GPU_shader_get_attribute(GPUShader *shader, const char *name);
183 /* Builtin/Non-generated shaders */
184 typedef enum GPUBuiltinShader {
185 GPU_SHADER_VSM_STORE = (1<<0),
186 GPU_SHADER_SEP_GAUSSIAN_BLUR = (1<<1),
189 GPUShader *GPU_shader_get_builtin_shader(GPUBuiltinShader shader);
190 void GPU_shader_free_builtin_shaders(void);
192 /* Vertex attributes for shaders */
194 #define GPU_MAX_ATTRIB 32
196 typedef struct GPUVertexAttribs {
202 char name[64]; /* MAX_CUSTOMDATA_LAYER_NAME */
203 } layer[GPU_MAX_ATTRIB];
212 #endif /* __GPU_EXTENSIONS_H__ */