mesa: Change "BRIAN PAUL" to "THE AUTHORS" in license text.
[mesa.git] / 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 void GLAPIENTRY
42 _mesa_Uniform1f(GLint, GLfloat);
43 void GLAPIENTRY
44 _mesa_Uniform2f(GLint, GLfloat, GLfloat);
45 void GLAPIENTRY
46 _mesa_Uniform3f(GLint, GLfloat, GLfloat, GLfloat);
47 void GLAPIENTRY
48 _mesa_Uniform4f(GLint, GLfloat, GLfloat, GLfloat, GLfloat);
49 void GLAPIENTRY
50 _mesa_Uniform1i(GLint, GLint);
51 void GLAPIENTRY
52 _mesa_Uniform2i(GLint, GLint, GLint);
53 void GLAPIENTRY
54 _mesa_Uniform3i(GLint, GLint, GLint, GLint);
55 void GLAPIENTRY
56 _mesa_Uniform4i(GLint, GLint, GLint, GLint, GLint);
57 void GLAPIENTRY
58 _mesa_Uniform1fv(GLint, GLsizei, const GLfloat *);
59 void GLAPIENTRY
60 _mesa_Uniform2fv(GLint, GLsizei, const GLfloat *);
61 void GLAPIENTRY
62 _mesa_Uniform3fv(GLint, GLsizei, const GLfloat *);
63 void GLAPIENTRY
64 _mesa_Uniform4fv(GLint, GLsizei, const GLfloat *);
65 void GLAPIENTRY
66 _mesa_Uniform1iv(GLint, GLsizei, const GLint *);
67 void GLAPIENTRY
68 _mesa_Uniform2iv(GLint, GLsizei, const GLint *);
69 void GLAPIENTRY
70 _mesa_Uniform3iv(GLint, GLsizei, const GLint *);
71 void GLAPIENTRY
72 _mesa_Uniform4iv(GLint, GLsizei, const GLint *);
73 void GLAPIENTRY
74 _mesa_Uniform1ui(GLint location, GLuint v0);
75 void GLAPIENTRY
76 _mesa_Uniform2ui(GLint location, GLuint v0, GLuint v1);
77 void GLAPIENTRY
78 _mesa_Uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2);
79 void GLAPIENTRY
80 _mesa_Uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3);
81 void GLAPIENTRY
82 _mesa_Uniform1uiv(GLint location, GLsizei count, const GLuint *value);
83 void GLAPIENTRY
84 _mesa_Uniform2uiv(GLint location, GLsizei count, const GLuint *value);
85 void GLAPIENTRY
86 _mesa_Uniform3uiv(GLint location, GLsizei count, const GLuint *value);
87 void GLAPIENTRY
88 _mesa_Uniform4uiv(GLint location, GLsizei count, const GLuint *value);
89 void GLAPIENTRY
90 _mesa_UniformMatrix2fv(GLint, GLsizei, GLboolean, const GLfloat *);
91 void GLAPIENTRY
92 _mesa_UniformMatrix3fv(GLint, GLsizei, GLboolean, const GLfloat *);
93 void GLAPIENTRY
94 _mesa_UniformMatrix4fv(GLint, GLsizei, GLboolean, const GLfloat *);
95 void GLAPIENTRY
96 _mesa_UniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose,
97 const GLfloat *value);
98 void GLAPIENTRY
99 _mesa_UniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose,
100 const GLfloat *value);
101 void GLAPIENTRY
102 _mesa_UniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose,
103 const GLfloat *value);
104 void GLAPIENTRY
105 _mesa_UniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose,
106 const GLfloat *value);
107 void GLAPIENTRY
108 _mesa_UniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose,
109 const GLfloat *value);
110 void GLAPIENTRY
111 _mesa_UniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose,
112 const GLfloat *value);
113 void GLAPIENTRY
114 _mesa_GetnUniformfvARB(GLhandleARB, GLint, GLsizei, GLfloat *);
115 void GLAPIENTRY
116 _mesa_GetUniformfv(GLhandleARB, GLint, GLfloat *);
117 void GLAPIENTRY
118 _mesa_GetnUniformivARB(GLhandleARB, GLint, GLsizei, GLint *);
119 void GLAPIENTRY
120 _mesa_GetUniformuiv(GLhandleARB, GLint, GLuint *);
121 void GLAPIENTRY
122 _mesa_GetnUniformuivARB(GLhandleARB, GLint, GLsizei, GLuint *);
123 void GLAPIENTRY
124 _mesa_GetUniformuiv(GLhandleARB program, GLint location, GLuint *params);
125 void GLAPIENTRY
126 _mesa_GetnUniformdvARB(GLhandleARB, GLint, GLsizei, GLdouble *);
127 void GLAPIENTRY
128 _mesa_GetUniformdv(GLhandleARB, GLint, GLdouble *);
129 GLint GLAPIENTRY
130 _mesa_GetUniformLocation(GLhandleARB, const GLcharARB *);
131 GLuint GLAPIENTRY
132 _mesa_GetUniformBlockIndex(GLuint program,
133 const GLchar *uniformBlockName);
134 void GLAPIENTRY
135 _mesa_GetUniformIndices(GLuint program,
136 GLsizei uniformCount,
137 const GLchar * const *uniformNames,
138 GLuint *uniformIndices);
139 void GLAPIENTRY
140 _mesa_UniformBlockBinding(GLuint program,
141 GLuint uniformBlockIndex,
142 GLuint uniformBlockBinding);
143 void GLAPIENTRY
144 _mesa_GetActiveUniformBlockiv(GLuint program,
145 GLuint uniformBlockIndex,
146 GLenum pname,
147 GLint *params);
148 void GLAPIENTRY
149 _mesa_GetActiveUniformBlockName(GLuint program,
150 GLuint uniformBlockIndex,
151 GLsizei bufSize,
152 GLsizei *length,
153 GLchar *uniformBlockName);
154 void GLAPIENTRY
155 _mesa_GetActiveUniformName(GLuint program, GLuint uniformIndex,
156 GLsizei bufSize, GLsizei *length,
157 GLchar *uniformName);
158 void GLAPIENTRY
159 _mesa_GetActiveUniform(GLhandleARB, GLuint, GLsizei, GLsizei *,
160 GLint *, GLenum *, GLcharARB *);
161 void GLAPIENTRY
162 _mesa_GetActiveUniformsiv(GLuint program,
163 GLsizei uniformCount,
164 const GLuint *uniformIndices,
165 GLenum pname,
166 GLint *params);
167 void GLAPIENTRY
168 _mesa_GetUniformiv(GLhandleARB, GLint, GLint *);
169
170 long
171 _mesa_parse_program_resource_name(const GLchar *name,
172 const GLchar **out_base_name_end);
173
174 unsigned
175 _mesa_get_uniform_location(struct gl_context *ctx, struct gl_shader_program *shProg,
176 const GLchar *name, unsigned *offset);
177
178 void
179 _mesa_uniform(struct gl_context *ctx, struct gl_shader_program *shader_program,
180 GLint location, GLsizei count,
181 const GLvoid *values, GLenum type);
182
183 void
184 _mesa_uniform_matrix(struct gl_context *ctx, struct gl_shader_program *shProg,
185 GLuint cols, GLuint rows,
186 GLint location, GLsizei count,
187 GLboolean transpose, const GLfloat *values);
188
189 void
190 _mesa_get_uniform(struct gl_context *ctx, GLuint program, GLint location,
191 GLsizei bufSize, enum glsl_base_type returnType,
192 GLvoid *paramsOut);
193
194 extern void
195 _mesa_uniform_attach_driver_storage(struct gl_uniform_storage *,
196 unsigned element_stride,
197 unsigned vector_stride,
198 enum gl_uniform_driver_format format,
199 void *data);
200
201 extern void
202 _mesa_uniform_detach_all_driver_storage(struct gl_uniform_storage *uni);
203
204 extern void
205 _mesa_propagate_uniforms_to_driver_storage(struct gl_uniform_storage *uni,
206 unsigned array_index,
207 unsigned count);
208
209 extern void
210 _mesa_update_shader_textures_used(struct gl_shader_program *shProg,
211 struct gl_program *prog);
212
213 extern bool
214 _mesa_sampler_uniforms_are_valid(const struct gl_shader_program *shProg,
215 char *errMsg, size_t errMsgLength);
216
217 extern const struct gl_program_parameter *
218 get_uniform_parameter(struct gl_shader_program *shProg, GLint index);
219
220 extern void
221 _mesa_get_uniform_name(const struct gl_uniform_storage *uni,
222 GLsizei maxLength, GLsizei *length,
223 GLchar *nameOut);
224
225 struct gl_builtin_uniform_element {
226 const char *field;
227 int tokens[STATE_LENGTH];
228 int swizzle;
229 };
230
231 struct gl_builtin_uniform_desc {
232 const char *name;
233 struct gl_builtin_uniform_element *elements;
234 unsigned int num_elements;
235 };
236
237 /**
238 * \name GLSL uniform arrays and structs require special handling.
239 *
240 * The GL_ARB_shader_objects spec says that if you use
241 * glGetUniformLocation to get the location of an array, you CANNOT
242 * access other elements of the array by adding an offset to the
243 * returned location. For example, you must call
244 * glGetUniformLocation("foo[16]") if you want to set the 16th element
245 * of the array with glUniform().
246 *
247 * HOWEVER, some other OpenGL drivers allow accessing array elements
248 * by adding an offset to the returned array location. And some apps
249 * seem to depend on that behaviour.
250 *
251 * Mesa's gl_uniform_list doesn't directly support this since each
252 * entry in the list describes one uniform variable, not one uniform
253 * element. We could insert dummy entries in the list for each array
254 * element after [0] but that causes complications elsewhere.
255 *
256 * We solve this problem by encoding two values in the location that's
257 * returned by glGetUniformLocation():
258 * a) index into gl_uniform_list::Uniforms[] for the uniform
259 * b) an array/field offset (0 for simple types)
260 *
261 * These two values are encoded in the high and low halves of a GLint.
262 * By putting the uniform number in the high part and the offset in the
263 * low part, we can support the unofficial ability to index into arrays
264 * by adding offsets to the location value.
265 */
266 /*@{*/
267 /**
268 * Combine the uniform's base location and the offset
269 */
270 static inline GLint
271 _mesa_uniform_merge_location_offset(unsigned base_location, unsigned offset)
272 {
273 return (base_location << 16) | offset;
274 }
275
276 /**
277 * Separate the uniform base location and parameter offset
278 */
279 static inline void
280 _mesa_uniform_split_location_offset(GLint location, unsigned *base_location,
281 unsigned *offset)
282 {
283 *offset = location & 0xffff;
284 *base_location = location >> 16;
285 }
286 /*@}*/
287
288
289 #ifdef __cplusplus
290 }
291 #endif
292
293
294 #endif /* UNIFORMS_H */