2 * Mesa 3-D graphics library
4 * Copyright (C) 2004-2008 Brian Paul All Rights Reserved.
5 * Copyright (C) 2009-2010 VMware, Inc. All Rights Reserved.
6 * Copyright © 2010 Intel Corporation
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 * Functions related to GLSL uniform variables.
34 * 1. Check that the right error code is generated for all _mesa_error() calls.
35 * 2. Insert FLUSH_VERTICES calls in various places
38 #include "main/glheader.h"
39 #include "main/context.h"
40 #include "main/dispatch.h"
41 #include "main/shaderapi.h"
42 #include "main/shaderobj.h"
43 #include "main/uniforms.h"
44 #include "main/enums.h"
45 #include "ir_uniform.h"
46 #include "glsl_types.h"
49 * Update the vertex/fragment program's TexturesUsed array.
51 * This needs to be called after glUniform(set sampler var) is called.
52 * A call to glUniform(samplerVar, value) causes a sampler to point to a
53 * particular texture unit. We know the sampler's texture target
54 * (1D/2D/3D/etc) from compile time but the sampler's texture unit is
55 * set by glUniform() calls.
57 * So, scan the program->SamplerUnits[] and program->SamplerTargets[]
58 * information to update the prog->TexturesUsed[] values.
59 * Each value of TexturesUsed[unit] is one of zero, TEXTURE_1D_INDEX,
60 * TEXTURE_2D_INDEX, TEXTURE_3D_INDEX, etc.
61 * We'll use that info for state validation before rendering.
64 _mesa_update_shader_textures_used(struct gl_shader_program *shProg,
65 struct gl_program *prog)
69 memcpy(prog->SamplerUnits, shProg->SamplerUnits, sizeof(prog->SamplerUnits));
70 memset(prog->TexturesUsed, 0, sizeof(prog->TexturesUsed));
72 for (s = 0; s < MAX_SAMPLERS; s++) {
73 if (prog->SamplersUsed & (1 << s)) {
74 GLuint unit = shProg->SamplerUnits[s];
75 GLuint tgt = shProg->SamplerTargets[s];
76 assert(unit < Elements(prog->TexturesUsed));
77 assert(tgt < NUM_TEXTURE_TARGETS);
78 prog->TexturesUsed[unit] |= (1 << tgt);
84 * Connect a piece of driver storage with a part of a uniform
86 * \param uni The uniform with which the storage will be associated
87 * \param element_stride Byte-stride between array elements.
88 * \sa gl_uniform_driver_storage::element_stride.
89 * \param vector_stride Byte-stride between vectors (in a matrix).
90 * \sa gl_uniform_driver_storage::vector_stride.
91 * \param format Conversion from native format to driver format
92 * required by the driver.
93 * \param data Location to dump the data.
96 _mesa_uniform_attach_driver_storage(struct gl_uniform_storage *uni,
97 unsigned element_stride,
98 unsigned vector_stride,
99 enum gl_uniform_driver_format format,
102 uni->driver_storage = (struct gl_uniform_driver_storage*)
103 realloc(uni->driver_storage,
104 sizeof(struct gl_uniform_driver_storage)
105 * (uni->num_driver_storage + 1));
107 uni->driver_storage[uni->num_driver_storage].element_stride = element_stride;
108 uni->driver_storage[uni->num_driver_storage].vector_stride = vector_stride;
109 uni->driver_storage[uni->num_driver_storage].format = (uint8_t) format;
110 uni->driver_storage[uni->num_driver_storage].data = data;
112 uni->num_driver_storage++;
116 * Sever all connections with all pieces of driver storage for all uniforms
119 * This function does \b not release any of the \c data pointers
120 * previously passed in to \c _mesa_uniform_attach_driver_stoarge.
123 _mesa_uniform_detach_all_driver_storage(struct gl_uniform_storage *uni)
125 free(uni->driver_storage);
126 uni->driver_storage = NULL;
127 uni->num_driver_storage = 0;
131 _mesa_Uniform1fARB(GLint location, GLfloat v0)
133 GET_CURRENT_CONTEXT(ctx);
134 _mesa_uniform(ctx, ctx->Shader.ActiveProgram, location, 1, &v0, GL_FLOAT);
138 _mesa_Uniform2fARB(GLint location, GLfloat v0, GLfloat v1)
140 GET_CURRENT_CONTEXT(ctx);
144 _mesa_uniform(ctx, ctx->Shader.ActiveProgram, location, 1, v, GL_FLOAT_VEC2);
148 _mesa_Uniform3fARB(GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
150 GET_CURRENT_CONTEXT(ctx);
155 _mesa_uniform(ctx, ctx->Shader.ActiveProgram, location, 1, v, GL_FLOAT_VEC3);
159 _mesa_Uniform4fARB(GLint location, GLfloat v0, GLfloat v1, GLfloat v2,
162 GET_CURRENT_CONTEXT(ctx);
168 _mesa_uniform(ctx, ctx->Shader.ActiveProgram, location, 1, v, GL_FLOAT_VEC4);
172 _mesa_Uniform1iARB(GLint location, GLint v0)
174 GET_CURRENT_CONTEXT(ctx);
175 _mesa_uniform(ctx, ctx->Shader.ActiveProgram, location, 1, &v0, GL_INT);
179 _mesa_Uniform2iARB(GLint location, GLint v0, GLint v1)
181 GET_CURRENT_CONTEXT(ctx);
185 _mesa_uniform(ctx, ctx->Shader.ActiveProgram, location, 1, v, GL_INT_VEC2);
189 _mesa_Uniform3iARB(GLint location, GLint v0, GLint v1, GLint v2)
191 GET_CURRENT_CONTEXT(ctx);
196 _mesa_uniform(ctx, ctx->Shader.ActiveProgram, location, 1, v, GL_INT_VEC3);
200 _mesa_Uniform4iARB(GLint location, GLint v0, GLint v1, GLint v2, GLint v3)
202 GET_CURRENT_CONTEXT(ctx);
208 _mesa_uniform(ctx, ctx->Shader.ActiveProgram, location, 1, v, GL_INT_VEC4);
212 _mesa_Uniform1fvARB(GLint location, GLsizei count, const GLfloat * value)
214 GET_CURRENT_CONTEXT(ctx);
215 _mesa_uniform(ctx, ctx->Shader.ActiveProgram, location, count, value, GL_FLOAT);
219 _mesa_Uniform2fvARB(GLint location, GLsizei count, const GLfloat * value)
221 GET_CURRENT_CONTEXT(ctx);
222 _mesa_uniform(ctx, ctx->Shader.ActiveProgram, location, count, value, GL_FLOAT_VEC2);
226 _mesa_Uniform3fvARB(GLint location, GLsizei count, const GLfloat * value)
228 GET_CURRENT_CONTEXT(ctx);
229 _mesa_uniform(ctx, ctx->Shader.ActiveProgram, location, count, value, GL_FLOAT_VEC3);
233 _mesa_Uniform4fvARB(GLint location, GLsizei count, const GLfloat * value)
235 GET_CURRENT_CONTEXT(ctx);
236 _mesa_uniform(ctx, ctx->Shader.ActiveProgram, location, count, value, GL_FLOAT_VEC4);
240 _mesa_Uniform1ivARB(GLint location, GLsizei count, const GLint * value)
242 GET_CURRENT_CONTEXT(ctx);
243 _mesa_uniform(ctx, ctx->Shader.ActiveProgram, location, count, value, GL_INT);
247 _mesa_Uniform2ivARB(GLint location, GLsizei count, const GLint * value)
249 GET_CURRENT_CONTEXT(ctx);
250 _mesa_uniform(ctx, ctx->Shader.ActiveProgram, location, count, value, GL_INT_VEC2);
254 _mesa_Uniform3ivARB(GLint location, GLsizei count, const GLint * value)
256 GET_CURRENT_CONTEXT(ctx);
257 _mesa_uniform(ctx, ctx->Shader.ActiveProgram, location, count, value, GL_INT_VEC3);
261 _mesa_Uniform4ivARB(GLint location, GLsizei count, const GLint * value)
263 GET_CURRENT_CONTEXT(ctx);
264 _mesa_uniform(ctx, ctx->Shader.ActiveProgram, location, count, value, GL_INT_VEC4);
268 /** OpenGL 3.0 GLuint-valued functions **/
270 _mesa_Uniform1ui(GLint location, GLuint v0)
272 GET_CURRENT_CONTEXT(ctx);
273 _mesa_uniform(ctx, ctx->Shader.ActiveProgram, location, 1, &v0, GL_UNSIGNED_INT);
277 _mesa_Uniform2ui(GLint location, GLuint v0, GLuint v1)
279 GET_CURRENT_CONTEXT(ctx);
283 _mesa_uniform(ctx, ctx->Shader.ActiveProgram, location, 1, v, GL_UNSIGNED_INT_VEC2);
287 _mesa_Uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
289 GET_CURRENT_CONTEXT(ctx);
294 _mesa_uniform(ctx, ctx->Shader.ActiveProgram, location, 1, v, GL_UNSIGNED_INT_VEC3);
298 _mesa_Uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
300 GET_CURRENT_CONTEXT(ctx);
306 _mesa_uniform(ctx, ctx->Shader.ActiveProgram, location, 1, v, GL_UNSIGNED_INT_VEC4);
310 _mesa_Uniform1uiv(GLint location, GLsizei count, const GLuint *value)
312 GET_CURRENT_CONTEXT(ctx);
313 _mesa_uniform(ctx, ctx->Shader.ActiveProgram, location, count, value, GL_UNSIGNED_INT);
317 _mesa_Uniform2uiv(GLint location, GLsizei count, const GLuint *value)
319 GET_CURRENT_CONTEXT(ctx);
320 _mesa_uniform(ctx, ctx->Shader.ActiveProgram, location, count, value, GL_UNSIGNED_INT_VEC2);
324 _mesa_Uniform3uiv(GLint location, GLsizei count, const GLuint *value)
326 GET_CURRENT_CONTEXT(ctx);
327 _mesa_uniform(ctx, ctx->Shader.ActiveProgram, location, count, value, GL_UNSIGNED_INT_VEC3);
331 _mesa_Uniform4uiv(GLint location, GLsizei count, const GLuint *value)
333 GET_CURRENT_CONTEXT(ctx);
334 _mesa_uniform(ctx, ctx->Shader.ActiveProgram, location, count, value, GL_UNSIGNED_INT_VEC4);
340 _mesa_UniformMatrix2fvARB(GLint location, GLsizei count, GLboolean transpose,
341 const GLfloat * value)
343 GET_CURRENT_CONTEXT(ctx);
344 _mesa_uniform_matrix(ctx, ctx->Shader.ActiveProgram,
345 2, 2, location, count, transpose, value);
349 _mesa_UniformMatrix3fvARB(GLint location, GLsizei count, GLboolean transpose,
350 const GLfloat * value)
352 GET_CURRENT_CONTEXT(ctx);
353 _mesa_uniform_matrix(ctx, ctx->Shader.ActiveProgram,
354 3, 3, location, count, transpose, value);
358 _mesa_UniformMatrix4fvARB(GLint location, GLsizei count, GLboolean transpose,
359 const GLfloat * value)
361 GET_CURRENT_CONTEXT(ctx);
362 _mesa_uniform_matrix(ctx, ctx->Shader.ActiveProgram,
363 4, 4, location, count, transpose, value);
368 * Non-square UniformMatrix are OpenGL 2.1
371 _mesa_UniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose,
372 const GLfloat *value)
374 GET_CURRENT_CONTEXT(ctx);
375 _mesa_uniform_matrix(ctx, ctx->Shader.ActiveProgram,
376 2, 3, location, count, transpose, value);
380 _mesa_UniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose,
381 const GLfloat *value)
383 GET_CURRENT_CONTEXT(ctx);
384 _mesa_uniform_matrix(ctx, ctx->Shader.ActiveProgram,
385 3, 2, location, count, transpose, value);
389 _mesa_UniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose,
390 const GLfloat *value)
392 GET_CURRENT_CONTEXT(ctx);
393 _mesa_uniform_matrix(ctx, ctx->Shader.ActiveProgram,
394 2, 4, location, count, transpose, value);
398 _mesa_UniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose,
399 const GLfloat *value)
401 GET_CURRENT_CONTEXT(ctx);
402 _mesa_uniform_matrix(ctx, ctx->Shader.ActiveProgram,
403 4, 2, location, count, transpose, value);
407 _mesa_UniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose,
408 const GLfloat *value)
410 GET_CURRENT_CONTEXT(ctx);
411 _mesa_uniform_matrix(ctx, ctx->Shader.ActiveProgram,
412 3, 4, location, count, transpose, value);
416 _mesa_UniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose,
417 const GLfloat *value)
419 GET_CURRENT_CONTEXT(ctx);
420 _mesa_uniform_matrix(ctx, ctx->Shader.ActiveProgram,
421 4, 3, location, count, transpose, value);
426 _mesa_GetnUniformfvARB(GLhandleARB program, GLint location,
427 GLsizei bufSize, GLfloat *params)
429 GET_CURRENT_CONTEXT(ctx);
430 _mesa_get_uniform(ctx, program, location, bufSize, GLSL_TYPE_FLOAT, params);
434 _mesa_GetUniformfvARB(GLhandleARB program, GLint location, GLfloat *params)
436 _mesa_GetnUniformfvARB(program, location, INT_MAX, params);
441 _mesa_GetnUniformivARB(GLhandleARB program, GLint location,
442 GLsizei bufSize, GLint *params)
444 GET_CURRENT_CONTEXT(ctx);
445 _mesa_get_uniform(ctx, program, location, bufSize, GLSL_TYPE_INT, params);
449 _mesa_GetUniformivARB(GLhandleARB program, GLint location, GLint *params)
451 _mesa_GetnUniformivARB(program, location, INT_MAX, params);
457 _mesa_GetnUniformuivARB(GLhandleARB program, GLint location,
458 GLsizei bufSize, GLuint *params)
460 GET_CURRENT_CONTEXT(ctx);
461 _mesa_get_uniform(ctx, program, location, bufSize, GLSL_TYPE_UINT, params);
465 _mesa_GetUniformuiv(GLhandleARB program, GLint location, GLuint *params)
467 _mesa_GetnUniformuivARB(program, location, INT_MAX, params);
473 _mesa_GetnUniformdvARB(GLhandleARB program, GLint location,
474 GLsizei bufSize, GLdouble *params)
476 GET_CURRENT_CONTEXT(ctx);
484 _mesa_get_uniform(ctx, program, location, bufSize, GLSL_TYPE_DOUBLE, params);
486 _mesa_error(ctx, GL_INVALID_OPERATION, "glGetUniformdvARB"
487 "(GL_ARB_gpu_shader_fp64 not implemented)");
491 _mesa_GetUniformdv(GLhandleARB program, GLint location, GLdouble *params)
493 _mesa_GetnUniformdvARB(program, location, INT_MAX, params);
498 _mesa_GetUniformLocationARB(GLhandleARB programObj, const GLcharARB *name)
500 struct gl_shader_program *shProg;
501 GLuint index, offset;
503 GET_CURRENT_CONTEXT(ctx);
505 shProg = _mesa_lookup_shader_program_err(ctx, programObj,
506 "glGetUniformLocation");
510 /* Page 80 (page 94 of the PDF) of the OpenGL 2.1 spec says:
512 * "If program has not been successfully linked, the error
513 * INVALID_OPERATION is generated."
515 if (shProg->LinkStatus == GL_FALSE) {
516 _mesa_error(ctx, GL_INVALID_OPERATION,
517 "glGetUniformLocation(program not linked)");
521 index = _mesa_get_uniform_location(ctx, shProg, name, &offset);
522 if (index == GL_INVALID_INDEX)
525 /* From the GL_ARB_uniform_buffer_object spec:
527 * "The value -1 will be returned if <name> does not correspond to an
528 * active uniform variable name in <program>, if <name> is associated
529 * with a named uniform block, or if <name> starts with the reserved
532 if (shProg->UniformStorage[index].block_index != -1)
535 return _mesa_uniform_merge_location_offset(index, offset);
538 static GLuint GLAPIENTRY
539 _mesa_GetUniformBlockIndex(GLuint program,
540 const GLchar *uniformBlockName)
542 GET_CURRENT_CONTEXT(ctx);
544 struct gl_shader_program *shProg;
546 if (!ctx->Extensions.ARB_uniform_buffer_object) {
547 _mesa_error(ctx, GL_INVALID_OPERATION, "glGetUniformBlockIndex");
548 return GL_INVALID_INDEX;
551 shProg = _mesa_lookup_shader_program_err(ctx, program,
552 "glGetUniformBlockIndex");
554 return GL_INVALID_INDEX;
556 for (i = 0; i < shProg->NumUniformBlocks; i++) {
557 if (!strcmp(shProg->UniformBlocks[i].Name, uniformBlockName))
561 return GL_INVALID_INDEX;
564 static void GLAPIENTRY
565 _mesa_GetUniformIndices(GLuint program,
566 GLsizei uniformCount,
567 const GLchar * const *uniformNames,
568 GLuint *uniformIndices)
570 GET_CURRENT_CONTEXT(ctx);
572 struct gl_shader_program *shProg;
574 if (!ctx->Extensions.ARB_uniform_buffer_object) {
575 _mesa_error(ctx, GL_INVALID_OPERATION, "glGetUniformIndices");
579 shProg = _mesa_lookup_shader_program_err(ctx, program,
580 "glGetUniformIndices");
584 if (uniformCount < 0) {
585 _mesa_error(ctx, GL_INVALID_VALUE,
586 "glGetUniformIndices(uniformCount < 0)");
590 for (i = 0; i < uniformCount; i++) {
592 uniformIndices[i] = _mesa_get_uniform_location(ctx, shProg,
593 uniformNames[i], &offset);
597 static void GLAPIENTRY
598 _mesa_UniformBlockBinding(GLuint program,
599 GLuint uniformBlockIndex,
600 GLuint uniformBlockBinding)
602 GET_CURRENT_CONTEXT(ctx);
603 struct gl_shader_program *shProg;
605 if (!ctx->Extensions.ARB_uniform_buffer_object) {
606 _mesa_error(ctx, GL_INVALID_OPERATION, "glUniformBlockBinding");
610 shProg = _mesa_lookup_shader_program_err(ctx, program,
611 "glUniformBlockBinding");
615 if (uniformBlockIndex >= shProg->NumUniformBlocks) {
616 _mesa_error(ctx, GL_INVALID_VALUE,
617 "glUniformBlockBinding(block index %d >= %d)",
618 uniformBlockIndex, shProg->NumUniformBlocks);
622 if (uniformBlockBinding >= ctx->Const.MaxUniformBufferBindings) {
623 _mesa_error(ctx, GL_INVALID_VALUE,
624 "glUniformBlockBinding(block binding %d >= %d)",
625 uniformBlockBinding, ctx->Const.MaxUniformBufferBindings);
629 if (shProg->UniformBlocks[uniformBlockIndex].Binding !=
630 uniformBlockBinding) {
633 FLUSH_VERTICES(ctx, _NEW_BUFFER_OBJECT);
634 shProg->UniformBlocks[uniformBlockIndex].Binding = uniformBlockBinding;
636 for (i = 0; i < MESA_SHADER_TYPES; i++) {
637 int stage_index = shProg->UniformBlockStageIndex[i][uniformBlockIndex];
639 if (stage_index != -1) {
640 struct gl_shader *sh = shProg->_LinkedShaders[i];
641 sh->UniformBlocks[stage_index].Binding = uniformBlockBinding;
647 static void GLAPIENTRY
648 _mesa_GetActiveUniformBlockiv(GLuint program,
649 GLuint uniformBlockIndex,
653 GET_CURRENT_CONTEXT(ctx);
654 struct gl_shader_program *shProg;
655 struct gl_uniform_block *block;
658 if (!ctx->Extensions.ARB_uniform_buffer_object) {
659 _mesa_error(ctx, GL_INVALID_OPERATION, "glGetActiveUniformBlockiv");
663 shProg = _mesa_lookup_shader_program_err(ctx, program,
664 "glGetActiveUniformBlockiv");
668 if (uniformBlockIndex >= shProg->NumUniformBlocks) {
669 _mesa_error(ctx, GL_INVALID_VALUE,
670 "glGetActiveUniformBlockiv(block index %d >= %d)",
671 uniformBlockIndex, shProg->NumUniformBlocks);
675 block = &shProg->UniformBlocks[uniformBlockIndex];
678 case GL_UNIFORM_BLOCK_BINDING:
679 params[0] = block->Binding;
682 case GL_UNIFORM_BLOCK_DATA_SIZE:
683 params[0] = block->UniformBufferSize;
686 case GL_UNIFORM_BLOCK_NAME_LENGTH:
687 params[0] = strlen(block->Name) + 1;
690 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS:
691 params[0] = block->NumUniforms;
694 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES:
695 for (i = 0; i < block->NumUniforms; i++) {
697 params[i] = _mesa_get_uniform_location(ctx, shProg,
698 block->Uniforms[i].Name,
703 case GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER:
704 params[0] = shProg->UniformBlockStageIndex[MESA_SHADER_VERTEX][uniformBlockIndex] != -1;
707 case GL_UNIFORM_BLOCK_REFERENCED_BY_GEOMETRY_SHADER:
708 params[0] = shProg->UniformBlockStageIndex[MESA_SHADER_GEOMETRY][uniformBlockIndex] != -1;
711 case GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER:
712 params[0] = shProg->UniformBlockStageIndex[MESA_SHADER_FRAGMENT][uniformBlockIndex] != -1;
716 _mesa_error(ctx, GL_INVALID_ENUM,
717 "glGetActiveUniformBlockiv(pname 0x%x (%s))",
718 pname, _mesa_lookup_enum_by_nr(pname));
723 static void GLAPIENTRY
724 _mesa_GetActiveUniformBlockName(GLuint program,
725 GLuint uniformBlockIndex,
728 GLchar *uniformBlockName)
730 GET_CURRENT_CONTEXT(ctx);
731 struct gl_shader_program *shProg;
732 struct gl_uniform_block *block;
734 if (!ctx->Extensions.ARB_uniform_buffer_object) {
735 _mesa_error(ctx, GL_INVALID_OPERATION, "glGetActiveUniformBlockiv");
740 _mesa_error(ctx, GL_INVALID_VALUE,
741 "glGetActiveUniformBlockName(bufSize %d < 0)",
746 shProg = _mesa_lookup_shader_program_err(ctx, program,
747 "glGetActiveUniformBlockiv");
751 if (uniformBlockIndex >= shProg->NumUniformBlocks) {
752 _mesa_error(ctx, GL_INVALID_VALUE,
753 "glGetActiveUniformBlockiv(block index %d >= %d)",
754 uniformBlockIndex, shProg->NumUniformBlocks);
758 block = &shProg->UniformBlocks[uniformBlockIndex];
760 if (uniformBlockName) {
761 _mesa_copy_string(uniformBlockName, bufSize, length, block->Name);
765 static void GLAPIENTRY
766 _mesa_GetActiveUniformName(GLuint program, GLuint uniformIndex,
767 GLsizei bufSize, GLsizei *length,
770 GET_CURRENT_CONTEXT(ctx);
771 struct gl_shader_program *shProg;
773 if (!ctx->Extensions.ARB_uniform_buffer_object) {
774 _mesa_error(ctx, GL_INVALID_OPERATION, "glGetActiveUniformBlockiv");
779 _mesa_error(ctx, GL_INVALID_VALUE,
780 "glGetActiveUniformName(bufSize %d < 0)",
785 ASSERT_OUTSIDE_BEGIN_END(ctx);
787 shProg = _mesa_lookup_shader_program_err(ctx, program, "glGetActiveUniformName");
792 if (uniformIndex >= shProg->NumUserUniformStorage) {
793 _mesa_error(ctx, GL_INVALID_VALUE, "glGetActiveUniform(index)");
798 _mesa_copy_string(uniformName, bufSize, length,
799 shProg->UniformStorage[uniformIndex].name);
804 * Plug in shader uniform-related functions into API dispatch table.
807 _mesa_init_shader_uniform_dispatch(const struct gl_context *ctx,
808 struct _glapi_table *exec)
811 SET_Uniform1fARB(exec, _mesa_Uniform1fARB);
812 SET_Uniform2fARB(exec, _mesa_Uniform2fARB);
813 SET_Uniform3fARB(exec, _mesa_Uniform3fARB);
814 SET_Uniform4fARB(exec, _mesa_Uniform4fARB);
815 SET_Uniform1iARB(exec, _mesa_Uniform1iARB);
816 SET_Uniform2iARB(exec, _mesa_Uniform2iARB);
817 SET_Uniform3iARB(exec, _mesa_Uniform3iARB);
818 SET_Uniform4iARB(exec, _mesa_Uniform4iARB);
819 SET_Uniform1fvARB(exec, _mesa_Uniform1fvARB);
820 SET_Uniform2fvARB(exec, _mesa_Uniform2fvARB);
821 SET_Uniform3fvARB(exec, _mesa_Uniform3fvARB);
822 SET_Uniform4fvARB(exec, _mesa_Uniform4fvARB);
823 SET_Uniform1ivARB(exec, _mesa_Uniform1ivARB);
824 SET_Uniform2ivARB(exec, _mesa_Uniform2ivARB);
825 SET_Uniform3ivARB(exec, _mesa_Uniform3ivARB);
826 SET_Uniform4ivARB(exec, _mesa_Uniform4ivARB);
827 SET_UniformMatrix2fvARB(exec, _mesa_UniformMatrix2fvARB);
828 SET_UniformMatrix3fvARB(exec, _mesa_UniformMatrix3fvARB);
829 SET_UniformMatrix4fvARB(exec, _mesa_UniformMatrix4fvARB);
831 SET_GetActiveUniformARB(exec, _mesa_GetActiveUniformARB);
832 SET_GetUniformLocationARB(exec, _mesa_GetUniformLocationARB);
833 SET_GetUniformfvARB(exec, _mesa_GetUniformfvARB);
834 SET_GetUniformivARB(exec, _mesa_GetUniformivARB);
837 if (ctx->API != API_OPENGLES2 || _mesa_is_gles3(ctx)) {
838 SET_UniformMatrix2x3fv(exec, _mesa_UniformMatrix2x3fv);
839 SET_UniformMatrix3x2fv(exec, _mesa_UniformMatrix3x2fv);
840 SET_UniformMatrix2x4fv(exec, _mesa_UniformMatrix2x4fv);
841 SET_UniformMatrix4x2fv(exec, _mesa_UniformMatrix4x2fv);
842 SET_UniformMatrix3x4fv(exec, _mesa_UniformMatrix3x4fv);
843 SET_UniformMatrix4x3fv(exec, _mesa_UniformMatrix4x3fv);
846 SET_Uniform1uiEXT(exec, _mesa_Uniform1ui);
847 SET_Uniform2uiEXT(exec, _mesa_Uniform2ui);
848 SET_Uniform3uiEXT(exec, _mesa_Uniform3ui);
849 SET_Uniform4uiEXT(exec, _mesa_Uniform4ui);
850 SET_Uniform1uivEXT(exec, _mesa_Uniform1uiv);
851 SET_Uniform2uivEXT(exec, _mesa_Uniform2uiv);
852 SET_Uniform3uivEXT(exec, _mesa_Uniform3uiv);
853 SET_Uniform4uivEXT(exec, _mesa_Uniform4uiv);
854 SET_GetUniformuivEXT(exec, _mesa_GetUniformuiv);
856 /* GL_ARB_robustness */
857 SET_GetnUniformfvARB(exec, _mesa_GetnUniformfvARB);
858 SET_GetnUniformivARB(exec, _mesa_GetnUniformivARB);
859 SET_GetnUniformuivARB(exec, _mesa_GetnUniformuivARB);
860 SET_GetnUniformdvARB(exec, _mesa_GetnUniformdvARB); /* GL 4.0 */
862 /* GL_ARB_uniform_buffer_object / GL 3.1 */
863 SET_GetUniformBlockIndex(exec, _mesa_GetUniformBlockIndex);
864 SET_GetUniformIndices(exec, _mesa_GetUniformIndices);
865 SET_GetActiveUniformsiv(exec, _mesa_GetActiveUniformsiv);
866 SET_GetActiveUniformBlockiv(exec, _mesa_GetActiveUniformBlockiv);
867 SET_GetActiveUniformBlockName(exec, _mesa_GetActiveUniformBlockName);
868 SET_GetActiveUniformName(exec, _mesa_GetActiveUniformName);
869 SET_UniformBlockBinding(exec, _mesa_UniformBlockBinding);
871 #endif /* FEATURE_GL */