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_shader.h
32 #ifndef __GPU_SHADER_H__
33 #define __GPU_SHADER_H__
39 typedef struct GPUShader GPUShader;
41 struct GPUUniformBuffer;
44 * - only for fragment shaders now
45 * - must call texture bind before setting a texture as uniform! */
47 typedef enum GPUShaderTFBType {
48 GPU_SHADER_TFB_NONE = 0, /* Transform feedback unsupported. */
49 GPU_SHADER_TFB_POINTS = 1,
50 GPU_SHADER_TFB_LINES = 2,
51 GPU_SHADER_TFB_TRIANGLES = 3,
54 GPUShader *GPU_shader_create(
55 const char *vertexcode,
60 const char *shader_name);
61 GPUShader *GPU_shader_create_ex(
62 const char *vertexcode,
67 const GPUShaderTFBType tf_type,
68 const char **tf_names,
70 const char *shader_name);
71 void GPU_shader_free(GPUShader *shader);
73 void GPU_shader_bind(GPUShader *shader);
74 void GPU_shader_unbind(void);
76 /* Returns true if transform feedback was successfully enabled. */
77 bool GPU_shader_transform_feedback_enable(GPUShader *shader, unsigned int vbo_id);
78 void GPU_shader_transform_feedback_disable(GPUShader *shader);
80 int GPU_shader_get_program(GPUShader *shader);
82 void *GPU_shader_get_interface(GPUShader *shader);
84 int GPU_shader_get_uniform(GPUShader *shader, const char *name);
85 int GPU_shader_get_builtin_uniform(GPUShader *shader, int builtin);
86 int GPU_shader_get_uniform_block(GPUShader *shader, const char *name);
87 void GPU_shader_uniform_vector(
88 GPUShader *shader, int location, int length,
89 int arraysize, const float *value);
90 void GPU_shader_uniform_vector_int(
91 GPUShader *shader, int location, int length,
92 int arraysize, const int *value);
94 void GPU_shader_uniform_buffer(GPUShader *shader, int location, struct GPUUniformBuffer *ubo);
95 void GPU_shader_uniform_texture(GPUShader *shader, int location, struct GPUTexture *tex);
96 void GPU_shader_uniform_float(GPUShader *shader, int location, float value);
97 void GPU_shader_uniform_int(GPUShader *shader, int location, int value);
99 int GPU_shader_get_attribute(GPUShader *shader, const char *name);
101 /* Builtin/Non-generated shaders */
102 typedef enum GPUBuiltinShader {
103 /* specialized drawing */
105 GPU_SHADER_TEXT_SIMPLE,
106 GPU_SHADER_EDGES_FRONT_BACK_PERSP,
107 GPU_SHADER_EDGES_FRONT_BACK_ORTHO,
108 GPU_SHADER_EDGES_OVERLAY_SIMPLE,
109 GPU_SHADER_EDGES_OVERLAY,
110 GPU_SHADER_KEYFRAME_DIAMOND,
111 GPU_SHADER_SIMPLE_LIGHTING,
112 GPU_SHADER_SIMPLE_LIGHTING_FLAT_COLOR,
113 GPU_SHADER_SIMPLE_LIGHTING_SMOOTH_COLOR,
114 GPU_SHADER_SIMPLE_LIGHTING_SMOOTH_COLOR_ALPHA,
116 /* for simple 2D drawing */
118 * Take a single color for all the vertices and a 2D position for each vertex.
120 * \param color: uniform vec4
121 * \param pos: in vec2
123 GPU_SHADER_2D_UNIFORM_COLOR,
125 * Take a 2D position and color for each vertex without color interpolation.
127 * \param color: in vec4
128 * \param pos: in vec2
130 GPU_SHADER_2D_FLAT_COLOR,
132 * Take a 2D position and color for each vertex with linear interpolation in window space.
134 * \param color: in vec4
135 * \param pos: in vec2
137 GPU_SHADER_2D_SMOOTH_COLOR,
138 GPU_SHADER_2D_SMOOTH_COLOR_DITHER,
140 GPU_SHADER_2D_IMAGE_COLOR,
141 GPU_SHADER_2D_IMAGE_DESATURATE_COLOR,
142 GPU_SHADER_2D_IMAGE_ALPHA_COLOR,
143 GPU_SHADER_2D_IMAGE_ALPHA,
144 GPU_SHADER_2D_IMAGE_RECT_COLOR,
145 GPU_SHADER_2D_IMAGE_MULTI_RECT_COLOR,
146 GPU_SHADER_2D_IMAGE_MULTISAMPLE_2,
147 GPU_SHADER_2D_IMAGE_MULTISAMPLE_4,
148 GPU_SHADER_2D_IMAGE_MULTISAMPLE_8,
149 GPU_SHADER_2D_IMAGE_MULTISAMPLE_16,
150 GPU_SHADER_2D_IMAGE_MULTISAMPLE_2_DEPTH_TEST,
151 GPU_SHADER_2D_IMAGE_MULTISAMPLE_4_DEPTH_TEST,
152 GPU_SHADER_2D_IMAGE_MULTISAMPLE_8_DEPTH_TEST,
153 GPU_SHADER_2D_IMAGE_MULTISAMPLE_16_DEPTH_TEST,
154 GPU_SHADER_2D_CHECKER,
155 GPU_SHADER_2D_DIAG_STRIPES,
156 /* for simple 3D drawing */
158 * Take a single color for all the vertices and a 3D position for each vertex.
160 * \param color: uniform vec4
161 * \param pos: in vec3
163 GPU_SHADER_3D_UNIFORM_COLOR,
164 GPU_SHADER_3D_UNIFORM_COLOR_INSTANCE,
166 * Take a 3D position and color for each vertex without color interpolation.
168 * \param color: in vec4
169 * \param pos: in vec3
171 GPU_SHADER_3D_FLAT_COLOR,
173 * Take a 3D position and color for each vertex with perspective correct interpolation.
175 * \param color: in vec4
176 * \param pos: in vec3
178 GPU_SHADER_3D_SMOOTH_COLOR,
180 * Take a 3D position for each vertex and output only depth.
182 * \param pos: in vec3
184 GPU_SHADER_3D_DEPTH_ONLY,
185 GPU_SHADER_3D_CLIPPED_UNIFORM_COLOR,
186 /* basic image drawing */
187 GPU_SHADER_2D_IMAGE_LINEAR_TO_SRGB,
188 GPU_SHADER_2D_IMAGE_SHUFFLE_COLOR,
189 GPU_SHADER_2D_IMAGE_MASK_UNIFORM_COLOR,
191 * Draw texture with alpha. Take a 3D position and a 2D texture coordinate for each vertex.
193 * \param alpha: uniform float
194 * \param image: uniform sampler2D
195 * \param texCoord: in vec2
196 * \param pos: in vec3
198 GPU_SHADER_3D_IMAGE_MODULATE_ALPHA,
200 * Draw linearized depth texture relate to near and far distances.
201 * Take a 3D position and a 2D texture coordinate for each vertex.
203 * \param znear: uniform float
204 * \param zfar: uniform float
205 * \param image: uniform sampler2D
206 * \param texCoord: in vec2
207 * \param pos: in vec3
209 GPU_SHADER_3D_IMAGE_DEPTH,
210 GPU_SHADER_3D_IMAGE_DEPTH_COPY,
212 GPU_SHADER_2D_IMAGE_INTERLACE,
215 * Draw round points with a hardcoded size.
216 * Take a single color for all the vertices and a 2D position for each vertex.
218 * \param color: uniform vec4
219 * \param pos: in vec2
221 GPU_SHADER_2D_POINT_FIXED_SIZE_UNIFORM_COLOR,
223 * Draw round points with a constant size.
224 * Take a single color for all the vertices and a 2D position for each vertex.
226 * \param size: uniform float
227 * \param color: uniform vec4
228 * \param pos: in vec2
230 GPU_SHADER_2D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_AA,
232 * Draw round points with a constant size and an outline.
233 * Take a single color for all the vertices and a 2D position for each vertex.
235 * \param size: uniform float
236 * \param outlineWidth: uniform float
237 * \param color: uniform vec4
238 * \param outlineColor: uniform vec4
239 * \param pos: in vec2
241 GPU_SHADER_2D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_OUTLINE_AA,
243 * Draw round points with a constant size and an outline. Take a 2D position and a color for each vertex.
245 * \param size: uniform float
246 * \param outlineWidth: uniform float
247 * \param outlineColor: uniform vec4
248 * \param color: in vec4
249 * \param pos: in vec2
251 GPU_SHADER_2D_POINT_UNIFORM_SIZE_VARYING_COLOR_OUTLINE_AA,
253 * Draw round points with a constant size and an outline. Take a 2D position and a color for each vertex.
255 * \param size: in float
256 * \param color: in vec4
257 * \param pos: in vec2
259 GPU_SHADER_2D_POINT_VARYING_SIZE_VARYING_COLOR,
261 * Draw round points with a hardcoded size.
262 * Take a single color for all the vertices and a 3D position for each vertex.
264 * \param color: uniform vec4
265 * \param pos: in vec3
267 GPU_SHADER_3D_POINT_FIXED_SIZE_UNIFORM_COLOR,
269 * Draw round points with a hardcoded size.
270 * Take a single color for all the vertices and a 3D position for each vertex.
272 * \param color: uniform vec4
273 * \param pos: in vec3
275 GPU_SHADER_3D_POINT_FIXED_SIZE_VARYING_COLOR,
277 * Draw round points with a constant size.
278 * Take a single color for all the vertices and a 3D position for each vertex.
280 * \param size: uniform float
281 * \param color: uniform vec4
282 * \param pos: in vec3
284 GPU_SHADER_3D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_AA,
286 * Draw round points with a constant size and an outline.
287 * Take a single color for all the vertices and a 3D position for each vertex.
289 * \param size: uniform float
290 * \param outlineWidth: uniform float
291 * \param color: uniform vec4
292 * \param outlineColor: uniform vec4
293 * \param pos: in vec3
295 GPU_SHADER_3D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_OUTLINE_AA,
297 * Draw round points with a constant size and an outline.
298 * Take a single color for all the vertices and a 3D position for each vertex.
300 * \param color: uniform vec4
301 * \param size: in float
302 * \param pos: in vec3
304 GPU_SHADER_3D_POINT_VARYING_SIZE_UNIFORM_COLOR,
306 * Draw round points with a constant size and an outline. Take a 3D position and a color for each vertex.
308 * \param size: in float
309 * \param color: in vec4
310 * \param pos: in vec3
312 GPU_SHADER_3D_POINT_VARYING_SIZE_VARYING_COLOR,
314 GPU_SHADER_2D_LINE_DASHED_UNIFORM_COLOR,
315 GPU_SHADER_3D_LINE_DASHED_UNIFORM_COLOR,
317 GPU_SHADER_3D_GROUNDPOINT,
318 GPU_SHADER_3D_GROUNDLINE,
319 GPU_SHADER_3D_SCREENSPACE_VARIYING_COLOR,
321 GPU_SHADER_3D_OBJECTSPACE_VARIYING_COLOR,
322 GPU_SHADER_3D_OBJECTSPACE_SIMPLE_LIGHTING_VARIYING_COLOR,
325 /* distance in front of objects */
326 GPU_SHADER_DISTANCE_LINES,
328 GPU_SHADER_3D_INSTANCE_SCREEN_ALIGNED_AXIS,
329 GPU_SHADER_3D_INSTANCE_SCREEN_ALIGNED,
331 GPU_SHADER_INSTANCE_UNIFORM_COLOR,
332 GPU_SHADER_INSTANCE_VARIYING_ID_VARIYING_SIZE, /* Uniformly scaled */
333 GPU_SHADER_INSTANCE_VARIYING_COLOR_VARIYING_SIZE, /* Uniformly scaled */
334 GPU_SHADER_INSTANCE_VARIYING_COLOR_VARIYING_SCALE,
335 GPU_SHADER_INSTANCE_EDGES_VARIYING_COLOR,
336 /* grease pencil drawing */
337 GPU_SHADER_GPENCIL_STROKE,
338 GPU_SHADER_GPENCIL_FILL,
339 /* specialized for widget drawing */
340 GPU_SHADER_2D_AREA_EDGES,
341 GPU_SHADER_2D_WIDGET_BASE,
342 GPU_SHADER_2D_WIDGET_BASE_INST,
343 GPU_SHADER_2D_WIDGET_SHADOW,
344 GPU_SHADER_2D_NODELINK,
345 GPU_SHADER_2D_NODELINK_INST,
346 /* specialized for edituv drawing */
347 GPU_SHADER_2D_UV_VERTS,
348 GPU_SHADER_2D_UV_FACEDOTS,
349 GPU_SHADER_2D_UV_EDGES,
350 GPU_SHADER_2D_UV_EDGES_SMOOTH,
351 GPU_SHADER_2D_UV_FACES,
352 GPU_SHADER_2D_UV_FACES_STRETCH,
354 GPU_SHADER_3D_FLAT_SELECT_ID,
355 GPU_SHADER_3D_UNIFORM_SELECT_ID,
357 GPU_NUM_BUILTIN_SHADERS /* (not an actual shader) */
360 /** Keep these in sync with:
361 * - `gpu_shader_image_interlace_frag.glsl`
362 * - `gpu_shader_image_rect_interlace_frag.glsl`
364 typedef enum GPUInterlaceShader {
365 GPU_SHADER_INTERLACE_ROW = 0,
366 GPU_SHADER_INTERLACE_COLUMN = 1,
367 GPU_SHADER_INTERLACE_CHECKER = 2,
368 } GPUInterlaceShader;
370 GPUShader *GPU_shader_get_builtin_shader(GPUBuiltinShader shader);
372 void GPU_shader_get_builtin_shader_code(
373 GPUBuiltinShader shader,
374 const char **r_vert, const char **r_frag,
375 const char **r_geom, const char **r_defines);
377 void GPU_shader_free_builtin_shaders(void);
379 /* Vertex attributes for shaders */
381 #define GPU_MAX_ATTRIB 32
383 typedef struct GPUVertexAttribs {
390 char name[64]; /* MAX_CUSTOMDATA_LAYER_NAME */
391 } layer[GPU_MAX_ATTRIB];
400 #endif /* __GPU_SHADER_H__ */