c73aab3c1d56079e22696c9138ff081750ca7af6
[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 struct gl_program;
34 struct _glapi_table;
35
36 extern void GLAPIENTRY
37 _mesa_Uniform1fARB(GLint, GLfloat);
38
39 extern void GLAPIENTRY
40 _mesa_Uniform2fARB(GLint, GLfloat, GLfloat);
41
42 extern void GLAPIENTRY
43 _mesa_Uniform3fARB(GLint, GLfloat, GLfloat, GLfloat);
44
45 extern void GLAPIENTRY
46 _mesa_Uniform4fARB(GLint, GLfloat, GLfloat, GLfloat, GLfloat);
47
48 extern void GLAPIENTRY
49 _mesa_Uniform1iARB(GLint, GLint);
50
51 extern void GLAPIENTRY
52 _mesa_Uniform2iARB(GLint, GLint, GLint);
53
54 extern void GLAPIENTRY
55 _mesa_Uniform3iARB(GLint, GLint, GLint, GLint);
56
57 extern void GLAPIENTRY
58 _mesa_Uniform4iARB(GLint, GLint, GLint, GLint, GLint);
59
60 extern void GLAPIENTRY
61 _mesa_Uniform1fvARB(GLint, GLsizei, const GLfloat *);
62
63 extern void GLAPIENTRY
64 _mesa_Uniform2fvARB(GLint, GLsizei, const GLfloat *);
65
66 extern void GLAPIENTRY
67 _mesa_Uniform3fvARB(GLint, GLsizei, const GLfloat *);
68
69 extern void GLAPIENTRY
70 _mesa_Uniform4fvARB(GLint, GLsizei, const GLfloat *);
71
72 extern void GLAPIENTRY
73 _mesa_Uniform1ivARB(GLint, GLsizei, const GLint *);
74
75 extern void GLAPIENTRY
76 _mesa_Uniform2ivARB(GLint, GLsizei, const GLint *);
77
78 extern void GLAPIENTRY
79 _mesa_Uniform3ivARB(GLint, GLsizei, const GLint *);
80
81 extern void GLAPIENTRY
82 _mesa_Uniform4ivARB(GLint, GLsizei, const GLint *);
83
84 extern void GLAPIENTRY
85 _mesa_Uniform1ui(GLint location, GLuint v0);
86
87 extern void GLAPIENTRY
88 _mesa_Uniform2ui(GLint location, GLuint v0, GLuint v1);
89
90 extern void GLAPIENTRY
91 _mesa_Uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2);
92
93 extern void GLAPIENTRY
94 _mesa_Uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3);
95
96 extern void GLAPIENTRY
97 _mesa_Uniform1uiv(GLint location, GLsizei count, const GLuint *value);
98
99 extern void GLAPIENTRY
100 _mesa_Uniform2uiv(GLint location, GLsizei count, const GLuint *value);
101
102 extern void GLAPIENTRY
103 _mesa_Uniform3uiv(GLint location, GLsizei count, const GLuint *value);
104
105 extern void GLAPIENTRY
106 _mesa_Uniform4uiv(GLint location, GLsizei count, const GLuint *value);
107
108
109 extern void GLAPIENTRY
110 _mesa_UniformMatrix2fvARB(GLint, GLsizei, GLboolean, const GLfloat *);
111
112 extern void GLAPIENTRY
113 _mesa_UniformMatrix3fvARB(GLint, GLsizei, GLboolean, const GLfloat *);
114
115 extern void GLAPIENTRY
116 _mesa_UniformMatrix4fvARB(GLint, GLsizei, GLboolean, const GLfloat *);
117
118 extern void GLAPIENTRY
119 _mesa_UniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose,
120 const GLfloat *value);
121
122 extern void GLAPIENTRY
123 _mesa_UniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose,
124 const GLfloat *value);
125
126 extern void GLAPIENTRY
127 _mesa_UniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose,
128 const GLfloat *value);
129
130 extern void GLAPIENTRY
131 _mesa_UniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose,
132 const GLfloat *value);
133
134 extern void GLAPIENTRY
135 _mesa_UniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose,
136 const GLfloat *value);
137
138 extern void GLAPIENTRY
139 _mesa_UniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose,
140 const GLfloat *value);
141
142
143 extern void GLAPIENTRY
144 _mesa_GetActiveUniformARB(GLhandleARB, GLuint, GLsizei, GLsizei *,
145 GLint *, GLenum *, GLcharARB *);
146
147 extern void GLAPIENTRY
148 _mesa_GetUniformfvARB(GLhandleARB, GLint, GLfloat *);
149
150 extern void GLAPIENTRY
151 _mesa_GetnUniformfvARB(GLhandleARB, GLint, GLsizei, GLfloat *);
152
153 extern void GLAPIENTRY
154 _mesa_GetUniformivARB(GLhandleARB, GLint, GLint *);
155
156 extern void GLAPIENTRY
157 _mesa_GetnUniformivARB(GLhandleARB, GLint, GLsizei, GLint *);
158
159 extern void GLAPIENTRY
160 _mesa_GetUniformuiv(GLhandleARB, GLint, GLuint *);
161
162 extern void GLAPIENTRY
163 _mesa_GetnUniformuivARB(GLhandleARB, GLint, GLsizei, GLuint *);
164
165 extern void GLAPIENTRY
166 _mesa_GetUniformdv(GLhandleARB, GLint, GLdouble *);
167
168 extern void GLAPIENTRY
169 _mesa_GetnUniformdvARB(GLhandleARB, GLint, GLsizei, GLdouble *);
170
171 extern GLint GLAPIENTRY
172 _mesa_GetUniformLocationARB(GLhandleARB, const GLcharARB *);
173
174 GLint
175 _mesa_get_uniform_location(struct gl_context *ctx, struct gl_shader_program *shProg,
176 const GLchar *name);
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_program *prog);
211
212
213 extern void
214 _mesa_init_shader_uniform_dispatch(struct _glapi_table *exec);
215
216 extern const struct gl_program_parameter *
217 get_uniform_parameter(struct gl_shader_program *shProg, GLint index);
218
219 struct gl_builtin_uniform_element {
220 const char *field;
221 int tokens[STATE_LENGTH];
222 int swizzle;
223 };
224
225 struct gl_builtin_uniform_desc {
226 const char *name;
227 struct gl_builtin_uniform_element *elements;
228 unsigned int num_elements;
229 };
230
231 extern const struct gl_builtin_uniform_desc _mesa_builtin_uniform_desc[];
232
233 /**
234 * \name GLSL uniform arrays and structs require special handling.
235 *
236 * The GL_ARB_shader_objects spec says that if you use
237 * glGetUniformLocation to get the location of an array, you CANNOT
238 * access other elements of the array by adding an offset to the
239 * returned location. For example, you must call
240 * glGetUniformLocation("foo[16]") if you want to set the 16th element
241 * of the array with glUniform().
242 *
243 * HOWEVER, some other OpenGL drivers allow accessing array elements
244 * by adding an offset to the returned array location. And some apps
245 * seem to depend on that behaviour.
246 *
247 * Mesa's gl_uniform_list doesn't directly support this since each
248 * entry in the list describes one uniform variable, not one uniform
249 * element. We could insert dummy entries in the list for each array
250 * element after [0] but that causes complications elsewhere.
251 *
252 * We solve this problem by encoding two values in the location that's
253 * returned by glGetUniformLocation():
254 * a) index into gl_uniform_list::Uniforms[] for the uniform
255 * b) an array/field offset (0 for simple types)
256 *
257 * These two values are encoded in the high and low halves of a GLint.
258 * By putting the uniform number in the high part and the offset in the
259 * low part, we can support the unofficial ability to index into arrays
260 * by adding offsets to the location value.
261 */
262 /*@{*/
263 /**
264 * Combine the uniform's base location and the offset
265 */
266 static inline GLint
267 _mesa_uniform_merge_location_offset(unsigned base_location, unsigned offset)
268 {
269 return (base_location << 16) | offset;
270 }
271
272 /**
273 * Separate the uniform base location and parameter offset
274 */
275 static inline void
276 _mesa_uniform_split_location_offset(GLint location, unsigned *base_location,
277 unsigned *offset)
278 {
279 *offset = location & 0xffff;
280 *base_location = location >> 16;
281 }
282 /*@}*/
283
284 #endif /* UNIFORMS_H */