2 * Mesa 3-D graphics library
4 * Copyright (C) 2010 VMware, Inc. All Rights Reserved.
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:
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
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 OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
30 #include "program/prog_parameter.h"
31 #include "../glsl/glsl_types.h"
32 #include "../glsl/ir_uniform.h"
43 _mesa_Uniform1f(GLint
, GLfloat
);
45 _mesa_Uniform2f(GLint
, GLfloat
, GLfloat
);
47 _mesa_Uniform3f(GLint
, GLfloat
, GLfloat
, GLfloat
);
49 _mesa_Uniform4f(GLint
, GLfloat
, GLfloat
, GLfloat
, GLfloat
);
51 _mesa_Uniform1i(GLint
, GLint
);
53 _mesa_Uniform2i(GLint
, GLint
, GLint
);
55 _mesa_Uniform3i(GLint
, GLint
, GLint
, GLint
);
57 _mesa_Uniform4i(GLint
, GLint
, GLint
, GLint
, GLint
);
59 _mesa_Uniform1fv(GLint
, GLsizei
, const GLfloat
*);
61 _mesa_Uniform2fv(GLint
, GLsizei
, const GLfloat
*);
63 _mesa_Uniform3fv(GLint
, GLsizei
, const GLfloat
*);
65 _mesa_Uniform4fv(GLint
, GLsizei
, const GLfloat
*);
67 _mesa_Uniform1iv(GLint
, GLsizei
, const GLint
*);
69 _mesa_Uniform2iv(GLint
, GLsizei
, const GLint
*);
71 _mesa_Uniform3iv(GLint
, GLsizei
, const GLint
*);
73 _mesa_Uniform4iv(GLint
, GLsizei
, const GLint
*);
75 _mesa_Uniform1ui(GLint location
, GLuint v0
);
77 _mesa_Uniform2ui(GLint location
, GLuint v0
, GLuint v1
);
79 _mesa_Uniform3ui(GLint location
, GLuint v0
, GLuint v1
, GLuint v2
);
81 _mesa_Uniform4ui(GLint location
, GLuint v0
, GLuint v1
, GLuint v2
, GLuint v3
);
83 _mesa_Uniform1uiv(GLint location
, GLsizei count
, const GLuint
*value
);
85 _mesa_Uniform2uiv(GLint location
, GLsizei count
, const GLuint
*value
);
87 _mesa_Uniform3uiv(GLint location
, GLsizei count
, const GLuint
*value
);
89 _mesa_Uniform4uiv(GLint location
, GLsizei count
, const GLuint
*value
);
91 _mesa_UniformMatrix2fv(GLint
, GLsizei
, GLboolean
, const GLfloat
*);
93 _mesa_UniformMatrix3fv(GLint
, GLsizei
, GLboolean
, const GLfloat
*);
95 _mesa_UniformMatrix4fv(GLint
, GLsizei
, GLboolean
, const GLfloat
*);
97 _mesa_UniformMatrix2x3fv(GLint location
, GLsizei count
, GLboolean transpose
,
98 const GLfloat
*value
);
100 _mesa_UniformMatrix3x2fv(GLint location
, GLsizei count
, GLboolean transpose
,
101 const GLfloat
*value
);
103 _mesa_UniformMatrix2x4fv(GLint location
, GLsizei count
, GLboolean transpose
,
104 const GLfloat
*value
);
106 _mesa_UniformMatrix4x2fv(GLint location
, GLsizei count
, GLboolean transpose
,
107 const GLfloat
*value
);
109 _mesa_UniformMatrix3x4fv(GLint location
, GLsizei count
, GLboolean transpose
,
110 const GLfloat
*value
);
112 _mesa_UniformMatrix4x3fv(GLint location
, GLsizei count
, GLboolean transpose
,
113 const GLfloat
*value
);
116 _mesa_ProgramUniform1f(GLuint program
, GLint
, GLfloat
);
118 _mesa_ProgramUniform2f(GLuint program
, GLint
, GLfloat
, GLfloat
);
120 _mesa_ProgramUniform3f(GLuint program
, GLint
, GLfloat
, GLfloat
, GLfloat
);
122 _mesa_ProgramUniform4f(GLuint program
, GLint
, GLfloat
, GLfloat
, GLfloat
, GLfloat
);
124 _mesa_ProgramUniform1i(GLuint program
, GLint
, GLint
);
126 _mesa_ProgramUniform2i(GLuint program
, GLint
, GLint
, GLint
);
128 _mesa_ProgramUniform3i(GLuint program
, GLint
, GLint
, GLint
, GLint
);
130 _mesa_ProgramUniform4i(GLuint program
, GLint
, GLint
, GLint
, GLint
, GLint
);
132 _mesa_ProgramUniform1fv(GLuint program
, GLint
, GLsizei
, const GLfloat
*);
134 _mesa_ProgramUniform2fv(GLuint program
, GLint
, GLsizei
, const GLfloat
*);
136 _mesa_ProgramUniform3fv(GLuint program
, GLint
, GLsizei
, const GLfloat
*);
138 _mesa_ProgramUniform4fv(GLuint program
, GLint
, GLsizei
, const GLfloat
*);
140 _mesa_ProgramUniform1iv(GLuint program
, GLint
, GLsizei
, const GLint
*);
142 _mesa_ProgramUniform2iv(GLuint program
, GLint
, GLsizei
, const GLint
*);
144 _mesa_ProgramUniform3iv(GLuint program
, GLint
, GLsizei
, const GLint
*);
146 _mesa_ProgramUniform4iv(GLuint program
, GLint
, GLsizei
, const GLint
*);
148 _mesa_ProgramUniform1ui(GLuint program
, GLint location
, GLuint v0
);
150 _mesa_ProgramUniform2ui(GLuint program
, GLint location
, GLuint v0
, GLuint v1
);
152 _mesa_ProgramUniform3ui(GLuint program
, GLint location
, GLuint v0
, GLuint v1
,
155 _mesa_ProgramUniform4ui(GLuint program
, GLint location
, GLuint v0
, GLuint v1
,
156 GLuint v2
, GLuint v3
);
158 _mesa_ProgramUniform1uiv(GLuint program
, GLint location
, GLsizei count
,
159 const GLuint
*value
);
161 _mesa_ProgramUniform2uiv(GLuint program
, GLint location
, GLsizei count
,
162 const GLuint
*value
);
164 _mesa_ProgramUniform3uiv(GLuint program
, GLint location
, GLsizei count
,
165 const GLuint
*value
);
167 _mesa_ProgramUniform4uiv(GLuint program
, GLint location
, GLsizei count
,
168 const GLuint
*value
);
170 _mesa_ProgramUniformMatrix2fv(GLuint program
, GLint
, GLsizei
, GLboolean
,
173 _mesa_ProgramUniformMatrix3fv(GLuint program
, GLint
, GLsizei
, GLboolean
,
176 _mesa_ProgramUniformMatrix4fv(GLuint program
, GLint
, GLsizei
, GLboolean
,
179 _mesa_ProgramUniformMatrix2x3fv(GLuint program
, GLint location
, GLsizei count
,
180 GLboolean transpose
, const GLfloat
*value
);
182 _mesa_ProgramUniformMatrix3x2fv(GLuint program
, GLint location
, GLsizei count
,
183 GLboolean transpose
, const GLfloat
*value
);
185 _mesa_ProgramUniformMatrix2x4fv(GLuint program
, GLint location
, GLsizei count
,
186 GLboolean transpose
, const GLfloat
*value
);
188 _mesa_ProgramUniformMatrix4x2fv(GLuint program
, GLint location
, GLsizei count
,
189 GLboolean transpose
, const GLfloat
*value
);
191 _mesa_ProgramUniformMatrix3x4fv(GLuint program
, GLint location
, GLsizei count
,
192 GLboolean transpose
, const GLfloat
*value
);
194 _mesa_ProgramUniformMatrix4x3fv(GLuint program
, GLint location
, GLsizei count
,
195 GLboolean transpose
, const GLfloat
*value
);
198 _mesa_GetnUniformfvARB(GLuint
, GLint
, GLsizei
, GLfloat
*);
200 _mesa_GetUniformfv(GLuint
, GLint
, GLfloat
*);
202 _mesa_GetnUniformivARB(GLuint
, GLint
, GLsizei
, GLint
*);
204 _mesa_GetUniformuiv(GLuint
, GLint
, GLuint
*);
206 _mesa_GetnUniformuivARB(GLuint
, GLint
, GLsizei
, GLuint
*);
208 _mesa_GetUniformuiv(GLuint program
, GLint location
, GLuint
*params
);
210 _mesa_GetnUniformdvARB(GLuint
, GLint
, GLsizei
, GLdouble
*);
212 _mesa_GetUniformdv(GLuint
, GLint
, GLdouble
*);
214 _mesa_GetUniformLocation(GLuint
, const GLcharARB
*);
216 _mesa_GetUniformBlockIndex(GLuint program
,
217 const GLchar
*uniformBlockName
);
219 _mesa_GetUniformIndices(GLuint program
,
220 GLsizei uniformCount
,
221 const GLchar
* const *uniformNames
,
222 GLuint
*uniformIndices
);
224 _mesa_UniformBlockBinding(GLuint program
,
225 GLuint uniformBlockIndex
,
226 GLuint uniformBlockBinding
);
228 _mesa_GetActiveAtomicCounterBufferiv(GLuint program
, GLuint bufferIndex
,
229 GLenum pname
, GLint
*params
);
231 _mesa_GetActiveUniformBlockiv(GLuint program
,
232 GLuint uniformBlockIndex
,
236 _mesa_GetActiveUniformBlockName(GLuint program
,
237 GLuint uniformBlockIndex
,
240 GLchar
*uniformBlockName
);
242 _mesa_GetActiveUniformName(GLuint program
, GLuint uniformIndex
,
243 GLsizei bufSize
, GLsizei
*length
,
244 GLchar
*uniformName
);
246 _mesa_GetActiveUniform(GLuint
, GLuint
, GLsizei
, GLsizei
*,
247 GLint
*, GLenum
*, GLcharARB
*);
249 _mesa_GetActiveUniformsiv(GLuint program
,
250 GLsizei uniformCount
,
251 const GLuint
*uniformIndices
,
255 _mesa_GetUniformiv(GLuint
, GLint
, GLint
*);
258 _mesa_parse_program_resource_name(const GLchar
*name
,
259 const GLchar
**out_base_name_end
);
262 _mesa_get_uniform_location(struct gl_context
*ctx
, struct gl_shader_program
*shProg
,
263 const GLchar
*name
, unsigned *offset
);
266 _mesa_uniform(struct gl_context
*ctx
, struct gl_shader_program
*shader_program
,
267 GLint location
, GLsizei count
,
268 const GLvoid
*values
, GLenum type
);
271 _mesa_uniform_matrix(struct gl_context
*ctx
, struct gl_shader_program
*shProg
,
272 GLuint cols
, GLuint rows
,
273 GLint location
, GLsizei count
,
274 GLboolean transpose
, const GLfloat
*values
);
277 _mesa_get_uniform(struct gl_context
*ctx
, GLuint program
, GLint location
,
278 GLsizei bufSize
, enum glsl_base_type returnType
,
282 _mesa_uniform_attach_driver_storage(struct gl_uniform_storage
*,
283 unsigned element_stride
,
284 unsigned vector_stride
,
285 enum gl_uniform_driver_format format
,
289 _mesa_uniform_detach_all_driver_storage(struct gl_uniform_storage
*uni
);
292 _mesa_propagate_uniforms_to_driver_storage(struct gl_uniform_storage
*uni
,
293 unsigned array_index
,
297 _mesa_update_shader_textures_used(struct gl_shader_program
*shProg
,
298 struct gl_program
*prog
);
301 _mesa_sampler_uniforms_are_valid(const struct gl_shader_program
*shProg
,
302 char *errMsg
, size_t errMsgLength
);
304 _mesa_sampler_uniforms_pipeline_are_valid(struct gl_pipeline_object
*);
306 extern const struct gl_program_parameter
*
307 get_uniform_parameter(struct gl_shader_program
*shProg
, GLint index
);
310 _mesa_get_uniform_name(const struct gl_uniform_storage
*uni
,
311 GLsizei maxLength
, GLsizei
*length
,
314 struct gl_builtin_uniform_element
{
316 int tokens
[STATE_LENGTH
];
320 struct gl_builtin_uniform_desc
{
322 struct gl_builtin_uniform_element
*elements
;
323 unsigned int num_elements
;
327 * \name GLSL uniform arrays and structs require special handling.
329 * The GL_ARB_shader_objects spec says that if you use
330 * glGetUniformLocation to get the location of an array, you CANNOT
331 * access other elements of the array by adding an offset to the
332 * returned location. For example, you must call
333 * glGetUniformLocation("foo[16]") if you want to set the 16th element
334 * of the array with glUniform().
336 * HOWEVER, some other OpenGL drivers allow accessing array elements
337 * by adding an offset to the returned array location. And some apps
338 * seem to depend on that behaviour.
340 * Mesa's gl_uniform_list doesn't directly support this since each
341 * entry in the list describes one uniform variable, not one uniform
342 * element. We could insert dummy entries in the list for each array
343 * element after [0] but that causes complications elsewhere.
345 * We solve this problem by creating multiple entries for uniform arrays
346 * in the UniformRemapTable so that their elements get sequential locations.
348 * Utility functions below offer functionality to split UniformRemapTable
349 * location in to location of the uniform in UniformStorage + offset to the
350 * array element (0 if not an array) and also merge it back again as the
351 * UniformRemapTable location.
356 * Combine the uniform's storage index and the array index
359 _mesa_uniform_merge_location_offset(const struct gl_shader_program
*prog
,
360 unsigned storage_index
,
361 unsigned uniform_array_index
)
363 /* location in remap table + array element offset */
364 return prog
->UniformStorage
[storage_index
].remap_location
+
369 * Separate the uniform storage index and array index
372 _mesa_uniform_split_location_offset(const struct gl_shader_program
*prog
,
373 GLint location
, unsigned *storage_index
,
374 unsigned *uniform_array_index
)
376 *storage_index
= prog
->UniformRemapTable
[location
] - prog
->UniformStorage
;
377 *uniform_array_index
= location
-
378 prog
->UniformRemapTable
[location
]->remap_location
;
380 /*gl_uniform_storage in UniformStorage with the calculated base_location
381 * must match with the entry in remap table
383 assert(&prog
->UniformStorage
[*storage_index
] ==
384 prog
->UniformRemapTable
[location
]);
394 #endif /* UNIFORMS_H */