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 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
22 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
23 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24 * OTHER DEALINGS IN THE SOFTWARE.
29 * Functions related to GLSL uniform variables.
35 * 1. Check that the right error code is generated for all _mesa_error() calls.
36 * 2. Insert FLUSH_VERTICES calls in various places
39 #include "main/glheader.h"
40 #include "main/context.h"
41 #include "main/dispatch.h"
42 #include "main/shaderapi.h"
43 #include "main/shaderobj.h"
44 #include "main/uniforms.h"
45 #include "main/enums.h"
46 #include "ir_uniform.h"
47 #include "glsl_types.h"
50 * Update the vertex/fragment program's TexturesUsed array.
52 * This needs to be called after glUniform(set sampler var) is called.
53 * A call to glUniform(samplerVar, value) causes a sampler to point to a
54 * particular texture unit. We know the sampler's texture target
55 * (1D/2D/3D/etc) from compile time but the sampler's texture unit is
56 * set by glUniform() calls.
58 * So, scan the program->SamplerUnits[] and program->SamplerTargets[]
59 * information to update the prog->TexturesUsed[] values.
60 * Each value of TexturesUsed[unit] is one of zero, TEXTURE_1D_INDEX,
61 * TEXTURE_2D_INDEX, TEXTURE_3D_INDEX, etc.
62 * We'll use that info for state validation before rendering.
65 _mesa_update_shader_textures_used(struct gl_shader_program
*shProg
,
66 struct gl_program
*prog
)
70 memcpy(prog
->SamplerUnits
, shProg
->SamplerUnits
, sizeof(prog
->SamplerUnits
));
71 memset(prog
->TexturesUsed
, 0, sizeof(prog
->TexturesUsed
));
73 for (s
= 0; s
< MAX_SAMPLERS
; s
++) {
74 if (prog
->SamplersUsed
& (1 << s
)) {
75 GLuint unit
= shProg
->SamplerUnits
[s
];
76 GLuint tgt
= shProg
->SamplerTargets
[s
];
77 assert(unit
< Elements(prog
->TexturesUsed
));
78 assert(tgt
< NUM_TEXTURE_TARGETS
);
79 prog
->TexturesUsed
[unit
] |= (1 << tgt
);
85 * Connect a piece of driver storage with a part of a uniform
87 * \param uni The uniform with which the storage will be associated
88 * \param element_stride Byte-stride between array elements.
89 * \sa gl_uniform_driver_storage::element_stride.
90 * \param vector_stride Byte-stride between vectors (in a matrix).
91 * \sa gl_uniform_driver_storage::vector_stride.
92 * \param format Conversion from native format to driver format
93 * required by the driver.
94 * \param data Location to dump the data.
97 _mesa_uniform_attach_driver_storage(struct gl_uniform_storage
*uni
,
98 unsigned element_stride
,
99 unsigned vector_stride
,
100 enum gl_uniform_driver_format format
,
103 uni
->driver_storage
=
104 realloc(uni
->driver_storage
,
105 sizeof(struct gl_uniform_driver_storage
)
106 * (uni
->num_driver_storage
+ 1));
108 uni
->driver_storage
[uni
->num_driver_storage
].element_stride
= element_stride
;
109 uni
->driver_storage
[uni
->num_driver_storage
].vector_stride
= vector_stride
;
110 uni
->driver_storage
[uni
->num_driver_storage
].format
= (uint8_t) format
;
111 uni
->driver_storage
[uni
->num_driver_storage
].data
= data
;
113 uni
->num_driver_storage
++;
117 * Sever all connections with all pieces of driver storage for all uniforms
120 * This function does \b not release any of the \c data pointers
121 * previously passed in to \c _mesa_uniform_attach_driver_stoarge.
124 _mesa_uniform_detach_all_driver_storage(struct gl_uniform_storage
*uni
)
126 free(uni
->driver_storage
);
127 uni
->driver_storage
= NULL
;
128 uni
->num_driver_storage
= 0;
132 _mesa_Uniform1f(GLint location
, GLfloat v0
)
134 GET_CURRENT_CONTEXT(ctx
);
135 _mesa_uniform(ctx
, ctx
->Shader
.ActiveProgram
, location
, 1, &v0
, GL_FLOAT
);
139 _mesa_Uniform2f(GLint location
, GLfloat v0
, GLfloat v1
)
141 GET_CURRENT_CONTEXT(ctx
);
145 _mesa_uniform(ctx
, ctx
->Shader
.ActiveProgram
, location
, 1, v
, GL_FLOAT_VEC2
);
149 _mesa_Uniform3f(GLint location
, GLfloat v0
, GLfloat v1
, GLfloat v2
)
151 GET_CURRENT_CONTEXT(ctx
);
156 _mesa_uniform(ctx
, ctx
->Shader
.ActiveProgram
, location
, 1, v
, GL_FLOAT_VEC3
);
160 _mesa_Uniform4f(GLint location
, GLfloat v0
, GLfloat v1
, GLfloat v2
,
163 GET_CURRENT_CONTEXT(ctx
);
169 _mesa_uniform(ctx
, ctx
->Shader
.ActiveProgram
, location
, 1, v
, GL_FLOAT_VEC4
);
173 _mesa_Uniform1i(GLint location
, GLint v0
)
175 GET_CURRENT_CONTEXT(ctx
);
176 _mesa_uniform(ctx
, ctx
->Shader
.ActiveProgram
, location
, 1, &v0
, GL_INT
);
180 _mesa_Uniform2i(GLint location
, GLint v0
, GLint v1
)
182 GET_CURRENT_CONTEXT(ctx
);
186 _mesa_uniform(ctx
, ctx
->Shader
.ActiveProgram
, location
, 1, v
, GL_INT_VEC2
);
190 _mesa_Uniform3i(GLint location
, GLint v0
, GLint v1
, GLint v2
)
192 GET_CURRENT_CONTEXT(ctx
);
197 _mesa_uniform(ctx
, ctx
->Shader
.ActiveProgram
, location
, 1, v
, GL_INT_VEC3
);
201 _mesa_Uniform4i(GLint location
, GLint v0
, GLint v1
, GLint v2
, GLint v3
)
203 GET_CURRENT_CONTEXT(ctx
);
209 _mesa_uniform(ctx
, ctx
->Shader
.ActiveProgram
, location
, 1, v
, GL_INT_VEC4
);
213 _mesa_Uniform1fv(GLint location
, GLsizei count
, const GLfloat
* value
)
215 GET_CURRENT_CONTEXT(ctx
);
216 _mesa_uniform(ctx
, ctx
->Shader
.ActiveProgram
, location
, count
, value
, GL_FLOAT
);
220 _mesa_Uniform2fv(GLint location
, GLsizei count
, const GLfloat
* value
)
222 GET_CURRENT_CONTEXT(ctx
);
223 _mesa_uniform(ctx
, ctx
->Shader
.ActiveProgram
, location
, count
, value
, GL_FLOAT_VEC2
);
227 _mesa_Uniform3fv(GLint location
, GLsizei count
, const GLfloat
* value
)
229 GET_CURRENT_CONTEXT(ctx
);
230 _mesa_uniform(ctx
, ctx
->Shader
.ActiveProgram
, location
, count
, value
, GL_FLOAT_VEC3
);
234 _mesa_Uniform4fv(GLint location
, GLsizei count
, const GLfloat
* value
)
236 GET_CURRENT_CONTEXT(ctx
);
237 _mesa_uniform(ctx
, ctx
->Shader
.ActiveProgram
, location
, count
, value
, GL_FLOAT_VEC4
);
241 _mesa_Uniform1iv(GLint location
, GLsizei count
, const GLint
* value
)
243 GET_CURRENT_CONTEXT(ctx
);
244 _mesa_uniform(ctx
, ctx
->Shader
.ActiveProgram
, location
, count
, value
, GL_INT
);
248 _mesa_Uniform2iv(GLint location
, GLsizei count
, const GLint
* value
)
250 GET_CURRENT_CONTEXT(ctx
);
251 _mesa_uniform(ctx
, ctx
->Shader
.ActiveProgram
, location
, count
, value
, GL_INT_VEC2
);
255 _mesa_Uniform3iv(GLint location
, GLsizei count
, const GLint
* value
)
257 GET_CURRENT_CONTEXT(ctx
);
258 _mesa_uniform(ctx
, ctx
->Shader
.ActiveProgram
, location
, count
, value
, GL_INT_VEC3
);
262 _mesa_Uniform4iv(GLint location
, GLsizei count
, const GLint
* value
)
264 GET_CURRENT_CONTEXT(ctx
);
265 _mesa_uniform(ctx
, ctx
->Shader
.ActiveProgram
, location
, count
, value
, GL_INT_VEC4
);
269 /** OpenGL 3.0 GLuint-valued functions **/
271 _mesa_Uniform1ui(GLint location
, GLuint v0
)
273 GET_CURRENT_CONTEXT(ctx
);
274 _mesa_uniform(ctx
, ctx
->Shader
.ActiveProgram
, location
, 1, &v0
, GL_UNSIGNED_INT
);
278 _mesa_Uniform2ui(GLint location
, GLuint v0
, GLuint v1
)
280 GET_CURRENT_CONTEXT(ctx
);
284 _mesa_uniform(ctx
, ctx
->Shader
.ActiveProgram
, location
, 1, v
, GL_UNSIGNED_INT_VEC2
);
288 _mesa_Uniform3ui(GLint location
, GLuint v0
, GLuint v1
, GLuint v2
)
290 GET_CURRENT_CONTEXT(ctx
);
295 _mesa_uniform(ctx
, ctx
->Shader
.ActiveProgram
, location
, 1, v
, GL_UNSIGNED_INT_VEC3
);
299 _mesa_Uniform4ui(GLint location
, GLuint v0
, GLuint v1
, GLuint v2
, GLuint v3
)
301 GET_CURRENT_CONTEXT(ctx
);
307 _mesa_uniform(ctx
, ctx
->Shader
.ActiveProgram
, location
, 1, v
, GL_UNSIGNED_INT_VEC4
);
311 _mesa_Uniform1uiv(GLint location
, GLsizei count
, const GLuint
*value
)
313 GET_CURRENT_CONTEXT(ctx
);
314 _mesa_uniform(ctx
, ctx
->Shader
.ActiveProgram
, location
, count
, value
, GL_UNSIGNED_INT
);
318 _mesa_Uniform2uiv(GLint location
, GLsizei count
, const GLuint
*value
)
320 GET_CURRENT_CONTEXT(ctx
);
321 _mesa_uniform(ctx
, ctx
->Shader
.ActiveProgram
, location
, count
, value
, GL_UNSIGNED_INT_VEC2
);
325 _mesa_Uniform3uiv(GLint location
, GLsizei count
, const GLuint
*value
)
327 GET_CURRENT_CONTEXT(ctx
);
328 _mesa_uniform(ctx
, ctx
->Shader
.ActiveProgram
, location
, count
, value
, GL_UNSIGNED_INT_VEC3
);
332 _mesa_Uniform4uiv(GLint location
, GLsizei count
, const GLuint
*value
)
334 GET_CURRENT_CONTEXT(ctx
);
335 _mesa_uniform(ctx
, ctx
->Shader
.ActiveProgram
, location
, count
, value
, GL_UNSIGNED_INT_VEC4
);
341 _mesa_UniformMatrix2fv(GLint location
, GLsizei count
, GLboolean transpose
,
342 const GLfloat
* value
)
344 GET_CURRENT_CONTEXT(ctx
);
345 _mesa_uniform_matrix(ctx
, ctx
->Shader
.ActiveProgram
,
346 2, 2, location
, count
, transpose
, value
);
350 _mesa_UniformMatrix3fv(GLint location
, GLsizei count
, GLboolean transpose
,
351 const GLfloat
* value
)
353 GET_CURRENT_CONTEXT(ctx
);
354 _mesa_uniform_matrix(ctx
, ctx
->Shader
.ActiveProgram
,
355 3, 3, location
, count
, transpose
, value
);
359 _mesa_UniformMatrix4fv(GLint location
, GLsizei count
, GLboolean transpose
,
360 const GLfloat
* value
)
362 GET_CURRENT_CONTEXT(ctx
);
363 _mesa_uniform_matrix(ctx
, ctx
->Shader
.ActiveProgram
,
364 4, 4, location
, count
, transpose
, value
);
369 * Non-square UniformMatrix are OpenGL 2.1
372 _mesa_UniformMatrix2x3fv(GLint location
, GLsizei count
, GLboolean transpose
,
373 const GLfloat
*value
)
375 GET_CURRENT_CONTEXT(ctx
);
376 _mesa_uniform_matrix(ctx
, ctx
->Shader
.ActiveProgram
,
377 2, 3, location
, count
, transpose
, value
);
381 _mesa_UniformMatrix3x2fv(GLint location
, GLsizei count
, GLboolean transpose
,
382 const GLfloat
*value
)
384 GET_CURRENT_CONTEXT(ctx
);
385 _mesa_uniform_matrix(ctx
, ctx
->Shader
.ActiveProgram
,
386 3, 2, location
, count
, transpose
, value
);
390 _mesa_UniformMatrix2x4fv(GLint location
, GLsizei count
, GLboolean transpose
,
391 const GLfloat
*value
)
393 GET_CURRENT_CONTEXT(ctx
);
394 _mesa_uniform_matrix(ctx
, ctx
->Shader
.ActiveProgram
,
395 2, 4, location
, count
, transpose
, value
);
399 _mesa_UniformMatrix4x2fv(GLint location
, GLsizei count
, GLboolean transpose
,
400 const GLfloat
*value
)
402 GET_CURRENT_CONTEXT(ctx
);
403 _mesa_uniform_matrix(ctx
, ctx
->Shader
.ActiveProgram
,
404 4, 2, location
, count
, transpose
, value
);
408 _mesa_UniformMatrix3x4fv(GLint location
, GLsizei count
, GLboolean transpose
,
409 const GLfloat
*value
)
411 GET_CURRENT_CONTEXT(ctx
);
412 _mesa_uniform_matrix(ctx
, ctx
->Shader
.ActiveProgram
,
413 3, 4, location
, count
, transpose
, value
);
417 _mesa_UniformMatrix4x3fv(GLint location
, GLsizei count
, GLboolean transpose
,
418 const GLfloat
*value
)
420 GET_CURRENT_CONTEXT(ctx
);
421 _mesa_uniform_matrix(ctx
, ctx
->Shader
.ActiveProgram
,
422 4, 3, location
, count
, transpose
, value
);
427 _mesa_GetnUniformfvARB(GLhandleARB program
, GLint location
,
428 GLsizei bufSize
, GLfloat
*params
)
430 GET_CURRENT_CONTEXT(ctx
);
431 _mesa_get_uniform(ctx
, program
, location
, bufSize
, GLSL_TYPE_FLOAT
, params
);
435 _mesa_GetUniformfv(GLhandleARB program
, GLint location
, GLfloat
*params
)
437 _mesa_GetnUniformfvARB(program
, location
, INT_MAX
, params
);
442 _mesa_GetnUniformivARB(GLhandleARB program
, GLint location
,
443 GLsizei bufSize
, GLint
*params
)
445 GET_CURRENT_CONTEXT(ctx
);
446 _mesa_get_uniform(ctx
, program
, location
, bufSize
, GLSL_TYPE_INT
, params
);
450 _mesa_GetUniformiv(GLhandleARB program
, GLint location
, GLint
*params
)
452 _mesa_GetnUniformivARB(program
, location
, INT_MAX
, params
);
458 _mesa_GetnUniformuivARB(GLhandleARB program
, GLint location
,
459 GLsizei bufSize
, GLuint
*params
)
461 GET_CURRENT_CONTEXT(ctx
);
462 _mesa_get_uniform(ctx
, program
, location
, bufSize
, GLSL_TYPE_UINT
, params
);
466 _mesa_GetUniformuiv(GLhandleARB program
, GLint location
, GLuint
*params
)
468 _mesa_GetnUniformuivARB(program
, location
, INT_MAX
, params
);
474 _mesa_GetnUniformdvARB(GLhandleARB program
, GLint location
,
475 GLsizei bufSize
, GLdouble
*params
)
477 GET_CURRENT_CONTEXT(ctx
);
485 _mesa_get_uniform(ctx, program, location, bufSize, GLSL_TYPE_DOUBLE, params);
487 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetUniformdvARB"
488 "(GL_ARB_gpu_shader_fp64 not implemented)");
492 _mesa_GetUniformdv(GLhandleARB program
, GLint location
, GLdouble
*params
)
494 _mesa_GetnUniformdvARB(program
, location
, INT_MAX
, params
);
499 _mesa_GetUniformLocation(GLhandleARB programObj
, const GLcharARB
*name
)
501 struct gl_shader_program
*shProg
;
502 GLuint index
, offset
;
504 GET_CURRENT_CONTEXT(ctx
);
506 shProg
= _mesa_lookup_shader_program_err(ctx
, programObj
,
507 "glGetUniformLocation");
511 /* Page 80 (page 94 of the PDF) of the OpenGL 2.1 spec says:
513 * "If program has not been successfully linked, the error
514 * INVALID_OPERATION is generated."
516 if (shProg
->LinkStatus
== GL_FALSE
) {
517 _mesa_error(ctx
, GL_INVALID_OPERATION
,
518 "glGetUniformLocation(program not linked)");
522 index
= _mesa_get_uniform_location(ctx
, shProg
, name
, &offset
);
523 if (index
== GL_INVALID_INDEX
)
526 /* From the GL_ARB_uniform_buffer_object spec:
528 * "The value -1 will be returned if <name> does not correspond to an
529 * active uniform variable name in <program>, if <name> is associated
530 * with a named uniform block, or if <name> starts with the reserved
533 if (shProg
->UniformStorage
[index
].block_index
!= -1)
536 return _mesa_uniform_merge_location_offset(index
, offset
);
540 _mesa_GetUniformBlockIndex(GLuint program
,
541 const GLchar
*uniformBlockName
)
543 GET_CURRENT_CONTEXT(ctx
);
545 struct gl_shader_program
*shProg
;
547 if (!ctx
->Extensions
.ARB_uniform_buffer_object
) {
548 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetUniformBlockIndex");
549 return GL_INVALID_INDEX
;
552 shProg
= _mesa_lookup_shader_program_err(ctx
, program
,
553 "glGetUniformBlockIndex");
555 return GL_INVALID_INDEX
;
557 for (i
= 0; i
< shProg
->NumUniformBlocks
; i
++) {
558 if (!strcmp(shProg
->UniformBlocks
[i
].Name
, uniformBlockName
))
562 return GL_INVALID_INDEX
;
566 _mesa_GetUniformIndices(GLuint program
,
567 GLsizei uniformCount
,
568 const GLchar
* const *uniformNames
,
569 GLuint
*uniformIndices
)
571 GET_CURRENT_CONTEXT(ctx
);
573 struct gl_shader_program
*shProg
;
575 if (!ctx
->Extensions
.ARB_uniform_buffer_object
) {
576 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetUniformIndices");
580 shProg
= _mesa_lookup_shader_program_err(ctx
, program
,
581 "glGetUniformIndices");
585 if (uniformCount
< 0) {
586 _mesa_error(ctx
, GL_INVALID_VALUE
,
587 "glGetUniformIndices(uniformCount < 0)");
591 for (i
= 0; i
< uniformCount
; i
++) {
593 uniformIndices
[i
] = _mesa_get_uniform_location(ctx
, shProg
,
594 uniformNames
[i
], &offset
);
599 _mesa_UniformBlockBinding(GLuint program
,
600 GLuint uniformBlockIndex
,
601 GLuint uniformBlockBinding
)
603 GET_CURRENT_CONTEXT(ctx
);
604 struct gl_shader_program
*shProg
;
606 if (!ctx
->Extensions
.ARB_uniform_buffer_object
) {
607 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glUniformBlockBinding");
611 shProg
= _mesa_lookup_shader_program_err(ctx
, program
,
612 "glUniformBlockBinding");
616 if (uniformBlockIndex
>= shProg
->NumUniformBlocks
) {
617 _mesa_error(ctx
, GL_INVALID_VALUE
,
618 "glUniformBlockBinding(block index %u >= %u)",
619 uniformBlockIndex
, shProg
->NumUniformBlocks
);
623 if (uniformBlockBinding
>= ctx
->Const
.MaxUniformBufferBindings
) {
624 _mesa_error(ctx
, GL_INVALID_VALUE
,
625 "glUniformBlockBinding(block binding %u >= %u)",
626 uniformBlockBinding
, ctx
->Const
.MaxUniformBufferBindings
);
630 if (shProg
->UniformBlocks
[uniformBlockIndex
].Binding
!=
631 uniformBlockBinding
) {
634 FLUSH_VERTICES(ctx
, _NEW_BUFFER_OBJECT
);
635 shProg
->UniformBlocks
[uniformBlockIndex
].Binding
= uniformBlockBinding
;
637 for (i
= 0; i
< MESA_SHADER_TYPES
; i
++) {
638 int stage_index
= shProg
->UniformBlockStageIndex
[i
][uniformBlockIndex
];
640 if (stage_index
!= -1) {
641 struct gl_shader
*sh
= shProg
->_LinkedShaders
[i
];
642 sh
->UniformBlocks
[stage_index
].Binding
= uniformBlockBinding
;
649 _mesa_GetActiveUniformBlockiv(GLuint program
,
650 GLuint uniformBlockIndex
,
654 GET_CURRENT_CONTEXT(ctx
);
655 struct gl_shader_program
*shProg
;
656 struct gl_uniform_block
*block
;
659 if (!ctx
->Extensions
.ARB_uniform_buffer_object
) {
660 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetActiveUniformBlockiv");
664 shProg
= _mesa_lookup_shader_program_err(ctx
, program
,
665 "glGetActiveUniformBlockiv");
669 if (uniformBlockIndex
>= shProg
->NumUniformBlocks
) {
670 _mesa_error(ctx
, GL_INVALID_VALUE
,
671 "glGetActiveUniformBlockiv(block index %u >= %u)",
672 uniformBlockIndex
, shProg
->NumUniformBlocks
);
676 block
= &shProg
->UniformBlocks
[uniformBlockIndex
];
679 case GL_UNIFORM_BLOCK_BINDING
:
680 params
[0] = block
->Binding
;
683 case GL_UNIFORM_BLOCK_DATA_SIZE
:
684 params
[0] = block
->UniformBufferSize
;
687 case GL_UNIFORM_BLOCK_NAME_LENGTH
:
688 params
[0] = strlen(block
->Name
) + 1;
691 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS
:
692 params
[0] = block
->NumUniforms
;
695 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES
:
696 for (i
= 0; i
< block
->NumUniforms
; i
++) {
698 params
[i
] = _mesa_get_uniform_location(ctx
, shProg
,
699 block
->Uniforms
[i
].IndexName
,
704 case GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER
:
705 params
[0] = shProg
->UniformBlockStageIndex
[MESA_SHADER_VERTEX
][uniformBlockIndex
] != -1;
708 case GL_UNIFORM_BLOCK_REFERENCED_BY_GEOMETRY_SHADER
:
709 params
[0] = shProg
->UniformBlockStageIndex
[MESA_SHADER_GEOMETRY
][uniformBlockIndex
] != -1;
712 case GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER
:
713 params
[0] = shProg
->UniformBlockStageIndex
[MESA_SHADER_FRAGMENT
][uniformBlockIndex
] != -1;
717 _mesa_error(ctx
, GL_INVALID_ENUM
,
718 "glGetActiveUniformBlockiv(pname 0x%x (%s))",
719 pname
, _mesa_lookup_enum_by_nr(pname
));
725 _mesa_GetActiveUniformBlockName(GLuint program
,
726 GLuint uniformBlockIndex
,
729 GLchar
*uniformBlockName
)
731 GET_CURRENT_CONTEXT(ctx
);
732 struct gl_shader_program
*shProg
;
733 struct gl_uniform_block
*block
;
735 if (!ctx
->Extensions
.ARB_uniform_buffer_object
) {
736 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetActiveUniformBlockiv");
741 _mesa_error(ctx
, GL_INVALID_VALUE
,
742 "glGetActiveUniformBlockName(bufSize %d < 0)",
747 shProg
= _mesa_lookup_shader_program_err(ctx
, program
,
748 "glGetActiveUniformBlockiv");
752 if (uniformBlockIndex
>= shProg
->NumUniformBlocks
) {
753 _mesa_error(ctx
, GL_INVALID_VALUE
,
754 "glGetActiveUniformBlockiv(block index %u >= %u)",
755 uniformBlockIndex
, shProg
->NumUniformBlocks
);
759 block
= &shProg
->UniformBlocks
[uniformBlockIndex
];
761 if (uniformBlockName
) {
762 _mesa_copy_string(uniformBlockName
, bufSize
, length
, block
->Name
);
767 _mesa_GetActiveUniformName(GLuint program
, GLuint uniformIndex
,
768 GLsizei bufSize
, GLsizei
*length
,
771 GET_CURRENT_CONTEXT(ctx
);
772 struct gl_shader_program
*shProg
;
774 if (!ctx
->Extensions
.ARB_uniform_buffer_object
) {
775 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetActiveUniformBlockiv");
780 _mesa_error(ctx
, GL_INVALID_VALUE
,
781 "glGetActiveUniformName(bufSize %d < 0)",
786 shProg
= _mesa_lookup_shader_program_err(ctx
, program
, "glGetActiveUniformName");
791 if (uniformIndex
>= shProg
->NumUserUniformStorage
) {
792 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetActiveUniform(index)");
797 _mesa_get_uniform_name(& shProg
->UniformStorage
[uniformIndex
],
798 bufSize
, length
, uniformName
);
803 _mesa_get_uniform_name(const struct gl_uniform_storage
*uni
,
804 GLsizei maxLength
, GLsizei
*length
,
810 length
= &localLength
;
812 _mesa_copy_string(nameOut
, maxLength
, length
, uni
->name
);
814 /* Page 61 (page 73 of the PDF) in section 2.11 of the OpenGL ES 3.0
817 * "If the active uniform is an array, the uniform name returned in
818 * name will always be the name of the uniform array appended with
821 * The same text also appears in the OpenGL 4.2 spec. It does not,
822 * however, appear in any previous spec. Previous specifications are
823 * ambiguous in this regard. However, either name can later be passed
824 * to glGetUniformLocation (and related APIs), so there shouldn't be any
825 * harm in always appending "[0]" to uniform array names.
827 if (uni
->array_elements
!= 0) {
830 /* The comparison is strange because *length does *NOT* include the
831 * terminating NUL, but maxLength does.
833 for (i
= 0; i
< 3 && (*length
+ i
+ 1) < maxLength
; i
++)
834 nameOut
[*length
+ i
] = "[0]"[i
];
836 nameOut
[*length
+ i
] = '\0';