[[MESA]
[reactos.git] / reactos / dll / opengl / mesa / src / mesa / main / uniforms.h
1 /*
2 * Mesa 3-D graphics library
3 *
4 * Copyright (C) 2010 VMware, Inc. All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
20 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23
24
25 #ifndef UNIFORMS_H
26 #define UNIFORMS_H
27
28 #include "glheader.h"
29 #include "program/prog_parameter.h"
30 #include "../glsl/glsl_types.h"
31 #include "../glsl/ir_uniform.h"
32
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36
37
38 struct gl_program;
39 struct _glapi_table;
40
41 extern void GLAPIENTRY
42 _mesa_Uniform1fARB(GLint, GLfloat);
43
44 extern void GLAPIENTRY
45 _mesa_Uniform2fARB(GLint, GLfloat, GLfloat);
46
47 extern void GLAPIENTRY
48 _mesa_Uniform3fARB(GLint, GLfloat, GLfloat, GLfloat);
49
50 extern void GLAPIENTRY
51 _mesa_Uniform4fARB(GLint, GLfloat, GLfloat, GLfloat, GLfloat);
52
53 extern void GLAPIENTRY
54 _mesa_Uniform1iARB(GLint, GLint);
55
56 extern void GLAPIENTRY
57 _mesa_Uniform2iARB(GLint, GLint, GLint);
58
59 extern void GLAPIENTRY
60 _mesa_Uniform3iARB(GLint, GLint, GLint, GLint);
61
62 extern void GLAPIENTRY
63 _mesa_Uniform4iARB(GLint, GLint, GLint, GLint, GLint);
64
65 extern void GLAPIENTRY
66 _mesa_Uniform1fvARB(GLint, GLsizei, const GLfloat *);
67
68 extern void GLAPIENTRY
69 _mesa_Uniform2fvARB(GLint, GLsizei, const GLfloat *);
70
71 extern void GLAPIENTRY
72 _mesa_Uniform3fvARB(GLint, GLsizei, const GLfloat *);
73
74 extern void GLAPIENTRY
75 _mesa_Uniform4fvARB(GLint, GLsizei, const GLfloat *);
76
77 extern void GLAPIENTRY
78 _mesa_Uniform1ivARB(GLint, GLsizei, const GLint *);
79
80 extern void GLAPIENTRY
81 _mesa_Uniform2ivARB(GLint, GLsizei, const GLint *);
82
83 extern void GLAPIENTRY
84 _mesa_Uniform3ivARB(GLint, GLsizei, const GLint *);
85
86 extern void GLAPIENTRY
87 _mesa_Uniform4ivARB(GLint, GLsizei, const GLint *);
88
89 extern void GLAPIENTRY
90 _mesa_Uniform1ui(GLint location, GLuint v0);
91
92 extern void GLAPIENTRY
93 _mesa_Uniform2ui(GLint location, GLuint v0, GLuint v1);
94
95 extern void GLAPIENTRY
96 _mesa_Uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2);
97
98 extern void GLAPIENTRY
99 _mesa_Uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3);
100
101 extern void GLAPIENTRY
102 _mesa_Uniform1uiv(GLint location, GLsizei count, const GLuint *value);
103
104 extern void GLAPIENTRY
105 _mesa_Uniform2uiv(GLint location, GLsizei count, const GLuint *value);
106
107 extern void GLAPIENTRY
108 _mesa_Uniform3uiv(GLint location, GLsizei count, const GLuint *value);
109
110 extern void GLAPIENTRY
111 _mesa_Uniform4uiv(GLint location, GLsizei count, const GLuint *value);
112
113
114 extern void GLAPIENTRY
115 _mesa_UniformMatrix2fvARB(GLint, GLsizei, GLboolean, const GLfloat *);
116
117 extern void GLAPIENTRY
118 _mesa_UniformMatrix3fvARB(GLint, GLsizei, GLboolean, const GLfloat *);
119
120 extern void GLAPIENTRY
121 _mesa_UniformMatrix4fvARB(GLint, GLsizei, GLboolean, const GLfloat *);
122
123 extern void GLAPIENTRY
124 _mesa_UniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose,
125 const GLfloat *value);
126
127 extern void GLAPIENTRY
128 _mesa_UniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose,
129 const GLfloat *value);
130
131 extern void GLAPIENTRY
132 _mesa_UniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose,
133 const GLfloat *value);
134
135 extern void GLAPIENTRY
136 _mesa_UniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose,
137 const GLfloat *value);
138
139 extern void GLAPIENTRY
140 _mesa_UniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose,
141 const GLfloat *value);
142
143 extern void GLAPIENTRY
144 _mesa_UniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose,
145 const GLfloat *value);
146
147
148 extern void GLAPIENTRY
149 _mesa_GetActiveUniformARB(GLhandleARB, GLuint, GLsizei, GLsizei *,
150 GLint *, GLenum *, GLcharARB *);
151
152 extern void GLAPIENTRY
153 _mesa_GetUniformfvARB(GLhandleARB, GLint, GLfloat *);
154
155 extern void GLAPIENTRY
156 _mesa_GetnUniformfvARB(GLhandleARB, GLint, GLsizei, GLfloat *);
157
158 extern void GLAPIENTRY
159 _mesa_GetUniformivARB(GLhandleARB, GLint, GLint *);
160
161 extern void GLAPIENTRY
162 _mesa_GetnUniformivARB(GLhandleARB, GLint, GLsizei, GLint *);
163
164 extern void GLAPIENTRY
165 _mesa_GetUniformuiv(GLhandleARB, GLint, GLuint *);
166
167 extern void GLAPIENTRY
168 _mesa_GetnUniformuivARB(GLhandleARB, GLint, GLsizei, GLuint *);
169
170 extern void GLAPIENTRY
171 _mesa_GetUniformdv(GLhandleARB, GLint, GLdouble *);
172
173 extern void GLAPIENTRY
174 _mesa_GetnUniformdvARB(GLhandleARB, GLint, GLsizei, GLdouble *);
175
176 extern GLint GLAPIENTRY
177 _mesa_GetUniformLocationARB(GLhandleARB, const GLcharARB *);
178
179 GLint
180 _mesa_get_uniform_location(struct gl_context *ctx, struct gl_shader_program *shProg,
181 const GLchar *name);
182
183 void
184 _mesa_uniform(struct gl_context *ctx, struct gl_shader_program *shader_program,
185 GLint location, GLsizei count,
186 const GLvoid *values, GLenum type);
187
188 void
189 _mesa_uniform_matrix(struct gl_context *ctx, struct gl_shader_program *shProg,
190 GLuint cols, GLuint rows,
191 GLint location, GLsizei count,
192 GLboolean transpose, const GLfloat *values);
193
194 void
195 _mesa_get_uniform(struct gl_context *ctx, GLuint program, GLint location,
196 GLsizei bufSize, enum glsl_base_type returnType,
197 GLvoid *paramsOut);
198
199 extern void
200 _mesa_uniform_attach_driver_storage(struct gl_uniform_storage *,
201 unsigned element_stride,
202 unsigned vector_stride,
203 enum gl_uniform_driver_format format,
204 void *data);
205
206 extern void
207 _mesa_uniform_detach_all_driver_storage(struct gl_uniform_storage *uni);
208
209 extern void
210 _mesa_propagate_uniforms_to_driver_storage(struct gl_uniform_storage *uni,
211 unsigned array_index,
212 unsigned count);
213
214 extern void
215 _mesa_update_shader_textures_used(struct gl_shader_program *shProg,
216 struct gl_program *prog);
217
218 extern bool
219 _mesa_sampler_uniforms_are_valid(const struct gl_shader_program *shProg,
220 char *errMsg, size_t errMsgLength);
221
222 extern void
223 _mesa_init_shader_uniform_dispatch(struct _glapi_table *exec);
224
225 extern const struct gl_program_parameter *
226 get_uniform_parameter(struct gl_shader_program *shProg, GLint index);
227
228 struct gl_builtin_uniform_element {
229 const char *field;
230 int tokens[STATE_LENGTH];
231 int swizzle;
232 };
233
234 struct gl_builtin_uniform_desc {
235 const char *name;
236 struct gl_builtin_uniform_element *elements;
237 unsigned int num_elements;
238 };
239
240 extern const struct gl_builtin_uniform_desc _mesa_builtin_uniform_desc[];
241
242 /**
243 * \name GLSL uniform arrays and structs require special handling.
244 *
245 * The GL_ARB_shader_objects spec says that if you use
246 * glGetUniformLocation to get the location of an array, you CANNOT
247 * access other elements of the array by adding an offset to the
248 * returned location. For example, you must call
249 * glGetUniformLocation("foo[16]") if you want to set the 16th element
250 * of the array with glUniform().
251 *
252 * HOWEVER, some other OpenGL drivers allow accessing array elements
253 * by adding an offset to the returned array location. And some apps
254 * seem to depend on that behaviour.
255 *
256 * Mesa's gl_uniform_list doesn't directly support this since each
257 * entry in the list describes one uniform variable, not one uniform
258 * element. We could insert dummy entries in the list for each array
259 * element after [0] but that causes complications elsewhere.
260 *
261 * We solve this problem by encoding two values in the location that's
262 * returned by glGetUniformLocation():
263 * a) index into gl_uniform_list::Uniforms[] for the uniform
264 * b) an array/field offset (0 for simple types)
265 *
266 * These two values are encoded in the high and low halves of a GLint.
267 * By putting the uniform number in the high part and the offset in the
268 * low part, we can support the unofficial ability to index into arrays
269 * by adding offsets to the location value.
270 */
271 /*@{*/
272 /**
273 * Combine the uniform's base location and the offset
274 */
275 static inline GLint
276 _mesa_uniform_merge_location_offset(unsigned base_location, unsigned offset)
277 {
278 return (base_location << 16) | offset;
279 }
280
281 /**
282 * Separate the uniform base location and parameter offset
283 */
284 static inline void
285 _mesa_uniform_split_location_offset(GLint location, unsigned *base_location,
286 unsigned *offset)
287 {
288 *offset = location & 0xffff;
289 *base_location = location >> 16;
290 }
291 /*@}*/
292
293
294 #ifdef __cplusplus
295 }
296 #endif
297
298
299 #endif /* UNIFORMS_H */