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
39 #include "main/glheader.h"
40 #include "main/context.h"
41 #include "main/dispatch.h"
42 #include "main/mtypes.h"
43 #include "main/shaderapi.h"
44 #include "main/shaderobj.h"
45 #include "main/uniforms.h"
46 #include "program/prog_parameter.h"
47 #include "program/prog_statevars.h"
48 #include "program/prog_uniform.h"
49 #include "program/prog_instruction.h"
53 base_uniform_type(GLenum type
)
56 #if 0 /* not needed, for now */
69 case GL_UNSIGNED_INT_VEC2
:
70 case GL_UNSIGNED_INT_VEC3
:
71 case GL_UNSIGNED_INT_VEC4
:
72 return GL_UNSIGNED_INT
;
79 _mesa_problem(NULL
, "Invalid type in base_uniform_type()");
84 static struct gl_builtin_uniform_element gl_DepthRange_elements
[] = {
85 {"near", {STATE_DEPTH_RANGE
, 0, 0}, SWIZZLE_XXXX
},
86 {"far", {STATE_DEPTH_RANGE
, 0, 0}, SWIZZLE_YYYY
},
87 {"diff", {STATE_DEPTH_RANGE
, 0, 0}, SWIZZLE_ZZZZ
},
90 static struct gl_builtin_uniform_element gl_ClipPlane_elements
[] = {
91 {NULL
, {STATE_CLIPPLANE
, 0, 0}, SWIZZLE_XYZW
}
94 static struct gl_builtin_uniform_element gl_Point_elements
[] = {
95 {"size", {STATE_POINT_SIZE
}, SWIZZLE_XXXX
},
96 {"sizeMin", {STATE_POINT_SIZE
}, SWIZZLE_YYYY
},
97 {"sizeMax", {STATE_POINT_SIZE
}, SWIZZLE_ZZZZ
},
98 {"fadeThresholdSize", {STATE_POINT_SIZE
}, SWIZZLE_WWWW
},
99 {"distanceConstantAttenuation", {STATE_POINT_ATTENUATION
}, SWIZZLE_XXXX
},
100 {"distanceLinearAttenuation", {STATE_POINT_ATTENUATION
}, SWIZZLE_YYYY
},
101 {"distanceQuadraticAttenuation", {STATE_POINT_ATTENUATION
}, SWIZZLE_ZZZZ
},
104 static struct gl_builtin_uniform_element gl_FrontMaterial_elements
[] = {
105 {"emission", {STATE_MATERIAL
, 0, STATE_EMISSION
}, SWIZZLE_XYZW
},
106 {"ambient", {STATE_MATERIAL
, 0, STATE_AMBIENT
}, SWIZZLE_XYZW
},
107 {"diffuse", {STATE_MATERIAL
, 0, STATE_DIFFUSE
}, SWIZZLE_XYZW
},
108 {"specular", {STATE_MATERIAL
, 0, STATE_SPECULAR
}, SWIZZLE_XYZW
},
109 {"shininess", {STATE_MATERIAL
, 0, STATE_SHININESS
}, SWIZZLE_XXXX
},
112 static struct gl_builtin_uniform_element gl_BackMaterial_elements
[] = {
113 {"emission", {STATE_MATERIAL
, 1, STATE_EMISSION
}, SWIZZLE_XYZW
},
114 {"ambient", {STATE_MATERIAL
, 1, STATE_AMBIENT
}, SWIZZLE_XYZW
},
115 {"diffuse", {STATE_MATERIAL
, 1, STATE_DIFFUSE
}, SWIZZLE_XYZW
},
116 {"specular", {STATE_MATERIAL
, 1, STATE_SPECULAR
}, SWIZZLE_XYZW
},
117 {"shininess", {STATE_MATERIAL
, 1, STATE_SHININESS
}, SWIZZLE_XXXX
},
120 static struct gl_builtin_uniform_element gl_LightSource_elements
[] = {
121 {"ambient", {STATE_LIGHT
, 0, STATE_AMBIENT
}, SWIZZLE_XYZW
},
122 {"diffuse", {STATE_LIGHT
, 0, STATE_DIFFUSE
}, SWIZZLE_XYZW
},
123 {"specular", {STATE_LIGHT
, 0, STATE_SPECULAR
}, SWIZZLE_XYZW
},
124 {"position", {STATE_LIGHT
, 0, STATE_POSITION
}, SWIZZLE_XYZW
},
125 {"halfVector", {STATE_LIGHT
, 0, STATE_HALF_VECTOR
}, SWIZZLE_XYZW
},
126 {"spotDirection", {STATE_LIGHT
, 0, STATE_SPOT_DIRECTION
},
127 MAKE_SWIZZLE4(SWIZZLE_X
,
131 {"spotCosCutoff", {STATE_LIGHT
, 0, STATE_SPOT_DIRECTION
}, SWIZZLE_WWWW
},
132 {"spotCutoff", {STATE_LIGHT
, 0, STATE_SPOT_CUTOFF
}, SWIZZLE_XXXX
},
133 {"spotExponent", {STATE_LIGHT
, 0, STATE_ATTENUATION
}, SWIZZLE_WWWW
},
134 {"constantAttenuation", {STATE_LIGHT
, 0, STATE_ATTENUATION
}, SWIZZLE_XXXX
},
135 {"linearAttenuation", {STATE_LIGHT
, 0, STATE_ATTENUATION
}, SWIZZLE_YYYY
},
136 {"quadraticAttenuation", {STATE_LIGHT
, 0, STATE_ATTENUATION
}, SWIZZLE_ZZZZ
},
139 static struct gl_builtin_uniform_element gl_LightModel_elements
[] = {
140 {"ambient", {STATE_LIGHTMODEL_AMBIENT
, 0}, SWIZZLE_XYZW
},
143 static struct gl_builtin_uniform_element gl_FrontLightModelProduct_elements
[] = {
144 {"sceneColor", {STATE_LIGHTMODEL_SCENECOLOR
, 0}, SWIZZLE_XYZW
},
147 static struct gl_builtin_uniform_element gl_BackLightModelProduct_elements
[] = {
148 {"sceneColor", {STATE_LIGHTMODEL_SCENECOLOR
, 1}, SWIZZLE_XYZW
},
151 static struct gl_builtin_uniform_element gl_FrontLightProduct_elements
[] = {
152 {"ambient", {STATE_LIGHTPROD
, 0, 0, STATE_AMBIENT
}, SWIZZLE_XYZW
},
153 {"diffuse", {STATE_LIGHTPROD
, 0, 0, STATE_DIFFUSE
}, SWIZZLE_XYZW
},
154 {"specular", {STATE_LIGHTPROD
, 0, 0, STATE_SPECULAR
}, SWIZZLE_XYZW
},
157 static struct gl_builtin_uniform_element gl_BackLightProduct_elements
[] = {
158 {"ambient", {STATE_LIGHTPROD
, 0, 1, STATE_AMBIENT
}, SWIZZLE_XYZW
},
159 {"diffuse", {STATE_LIGHTPROD
, 0, 1, STATE_DIFFUSE
}, SWIZZLE_XYZW
},
160 {"specular", {STATE_LIGHTPROD
, 0, 1, STATE_SPECULAR
}, SWIZZLE_XYZW
},
163 static struct gl_builtin_uniform_element gl_TextureEnvColor_elements
[] = {
164 {NULL
, {STATE_TEXENV_COLOR
, 0}, SWIZZLE_XYZW
},
167 static struct gl_builtin_uniform_element gl_EyePlaneS_elements
[] = {
168 {NULL
, {STATE_TEXGEN
, 0, STATE_TEXGEN_EYE_S
}, SWIZZLE_XYZW
},
171 static struct gl_builtin_uniform_element gl_EyePlaneT_elements
[] = {
172 {NULL
, {STATE_TEXGEN
, 0, STATE_TEXGEN_EYE_T
}, SWIZZLE_XYZW
},
175 static struct gl_builtin_uniform_element gl_EyePlaneR_elements
[] = {
176 {NULL
, {STATE_TEXGEN
, 0, STATE_TEXGEN_EYE_R
}, SWIZZLE_XYZW
},
179 static struct gl_builtin_uniform_element gl_EyePlaneQ_elements
[] = {
180 {NULL
, {STATE_TEXGEN
, 0, STATE_TEXGEN_EYE_Q
}, SWIZZLE_XYZW
},
183 static struct gl_builtin_uniform_element gl_ObjectPlaneS_elements
[] = {
184 {NULL
, {STATE_TEXGEN
, 0, STATE_TEXGEN_OBJECT_S
}, SWIZZLE_XYZW
},
187 static struct gl_builtin_uniform_element gl_ObjectPlaneT_elements
[] = {
188 {NULL
, {STATE_TEXGEN
, 0, STATE_TEXGEN_OBJECT_T
}, SWIZZLE_XYZW
},
191 static struct gl_builtin_uniform_element gl_ObjectPlaneR_elements
[] = {
192 {NULL
, {STATE_TEXGEN
, 0, STATE_TEXGEN_OBJECT_R
}, SWIZZLE_XYZW
},
195 static struct gl_builtin_uniform_element gl_ObjectPlaneQ_elements
[] = {
196 {NULL
, {STATE_TEXGEN
, 0, STATE_TEXGEN_OBJECT_Q
}, SWIZZLE_XYZW
},
199 static struct gl_builtin_uniform_element gl_Fog_elements
[] = {
200 {"color", {STATE_FOG_COLOR
}, SWIZZLE_XYZW
},
201 {"density", {STATE_FOG_PARAMS
}, SWIZZLE_XXXX
},
202 {"start", {STATE_FOG_PARAMS
}, SWIZZLE_YYYY
},
203 {"end", {STATE_FOG_PARAMS
}, SWIZZLE_ZZZZ
},
204 {"scale", {STATE_FOG_PARAMS
}, SWIZZLE_WWWW
},
207 static struct gl_builtin_uniform_element gl_NormalScale_elements
[] = {
208 {NULL
, {STATE_NORMAL_SCALE
}, SWIZZLE_XXXX
},
211 #define MATRIX(name, statevar, modifier) \
212 static struct gl_builtin_uniform_element name ## _elements[] = { \
213 { NULL, { statevar, 0, 0, 0, modifier}, SWIZZLE_XYZW }, \
214 { NULL, { statevar, 0, 1, 1, modifier}, SWIZZLE_XYZW }, \
215 { NULL, { statevar, 0, 2, 2, modifier}, SWIZZLE_XYZW }, \
216 { NULL, { statevar, 0, 3, 3, modifier}, SWIZZLE_XYZW }, \
219 MATRIX(gl_ModelViewMatrix
,
220 STATE_MODELVIEW_MATRIX
, STATE_MATRIX_TRANSPOSE
);
221 MATRIX(gl_ModelViewMatrixInverse
,
222 STATE_MODELVIEW_MATRIX
, STATE_MATRIX_INVTRANS
);
223 MATRIX(gl_ModelViewMatrixTranspose
,
224 STATE_MODELVIEW_MATRIX
, 0);
225 MATRIX(gl_ModelViewMatrixInverseTranspose
,
226 STATE_MODELVIEW_MATRIX
, STATE_MATRIX_INVERSE
);
228 MATRIX(gl_ProjectionMatrix
,
229 STATE_PROJECTION_MATRIX
, STATE_MATRIX_TRANSPOSE
);
230 MATRIX(gl_ProjectionMatrixInverse
,
231 STATE_PROJECTION_MATRIX
, STATE_MATRIX_INVTRANS
);
232 MATRIX(gl_ProjectionMatrixTranspose
,
233 STATE_PROJECTION_MATRIX
, 0);
234 MATRIX(gl_ProjectionMatrixInverseTranspose
,
235 STATE_PROJECTION_MATRIX
, STATE_MATRIX_INVERSE
);
237 MATRIX(gl_ModelViewProjectionMatrix
,
238 STATE_MVP_MATRIX
, STATE_MATRIX_TRANSPOSE
);
239 MATRIX(gl_ModelViewProjectionMatrixInverse
,
240 STATE_MVP_MATRIX
, STATE_MATRIX_INVTRANS
);
241 MATRIX(gl_ModelViewProjectionMatrixTranspose
,
242 STATE_MVP_MATRIX
, 0);
243 MATRIX(gl_ModelViewProjectionMatrixInverseTranspose
,
244 STATE_MVP_MATRIX
, STATE_MATRIX_INVERSE
);
246 MATRIX(gl_TextureMatrix
,
247 STATE_TEXTURE_MATRIX
, STATE_MATRIX_TRANSPOSE
);
248 MATRIX(gl_TextureMatrixInverse
,
249 STATE_TEXTURE_MATRIX
, STATE_MATRIX_INVTRANS
);
250 MATRIX(gl_TextureMatrixTranspose
,
251 STATE_TEXTURE_MATRIX
, 0);
252 MATRIX(gl_TextureMatrixInverseTranspose
,
253 STATE_TEXTURE_MATRIX
, STATE_MATRIX_INVERSE
);
255 static struct gl_builtin_uniform_element gl_NormalMatrix_elements
[] = {
256 { NULL
, { STATE_MODELVIEW_MATRIX
, 0, 0, 0, STATE_MATRIX_INVERSE
},
258 { NULL
, { STATE_MODELVIEW_MATRIX
, 0, 1, 1, STATE_MATRIX_INVERSE
},
260 { NULL
, { STATE_MODELVIEW_MATRIX
, 0, 2, 2, STATE_MATRIX_INVERSE
},
266 #define STATEVAR(name) {#name, name ## _elements, Elements(name ## _elements)}
268 const struct gl_builtin_uniform_desc _mesa_builtin_uniform_desc
[] = {
269 STATEVAR(gl_DepthRange
),
270 STATEVAR(gl_ClipPlane
),
272 STATEVAR(gl_FrontMaterial
),
273 STATEVAR(gl_BackMaterial
),
274 STATEVAR(gl_LightSource
),
275 STATEVAR(gl_LightModel
),
276 STATEVAR(gl_FrontLightModelProduct
),
277 STATEVAR(gl_BackLightModelProduct
),
278 STATEVAR(gl_FrontLightProduct
),
279 STATEVAR(gl_BackLightProduct
),
280 STATEVAR(gl_TextureEnvColor
),
281 STATEVAR(gl_EyePlaneS
),
282 STATEVAR(gl_EyePlaneT
),
283 STATEVAR(gl_EyePlaneR
),
284 STATEVAR(gl_EyePlaneQ
),
285 STATEVAR(gl_ObjectPlaneS
),
286 STATEVAR(gl_ObjectPlaneT
),
287 STATEVAR(gl_ObjectPlaneR
),
288 STATEVAR(gl_ObjectPlaneQ
),
291 STATEVAR(gl_ModelViewMatrix
),
292 STATEVAR(gl_ModelViewMatrixInverse
),
293 STATEVAR(gl_ModelViewMatrixTranspose
),
294 STATEVAR(gl_ModelViewMatrixInverseTranspose
),
296 STATEVAR(gl_ProjectionMatrix
),
297 STATEVAR(gl_ProjectionMatrixInverse
),
298 STATEVAR(gl_ProjectionMatrixTranspose
),
299 STATEVAR(gl_ProjectionMatrixInverseTranspose
),
301 STATEVAR(gl_ModelViewProjectionMatrix
),
302 STATEVAR(gl_ModelViewProjectionMatrixInverse
),
303 STATEVAR(gl_ModelViewProjectionMatrixTranspose
),
304 STATEVAR(gl_ModelViewProjectionMatrixInverseTranspose
),
306 STATEVAR(gl_TextureMatrix
),
307 STATEVAR(gl_TextureMatrixInverse
),
308 STATEVAR(gl_TextureMatrixTranspose
),
309 STATEVAR(gl_TextureMatrixInverseTranspose
),
311 STATEVAR(gl_NormalMatrix
),
312 STATEVAR(gl_NormalScale
),
318 is_boolean_type(GLenum type
)
333 is_sampler_type(GLenum type
)
339 case GL_SAMPLER_CUBE
:
340 case GL_SAMPLER_1D_SHADOW
:
341 case GL_SAMPLER_2D_SHADOW
:
342 case GL_SAMPLER_2D_RECT_ARB
:
343 case GL_SAMPLER_2D_RECT_SHADOW_ARB
:
344 case GL_SAMPLER_1D_ARRAY_EXT
:
345 case GL_SAMPLER_2D_ARRAY_EXT
:
346 case GL_SAMPLER_1D_ARRAY_SHADOW_EXT
:
347 case GL_SAMPLER_2D_ARRAY_SHADOW_EXT
:
355 static struct gl_program_parameter
*
356 get_uniform_parameter(const struct gl_shader_program
*shProg
, GLuint index
)
358 const struct gl_program
*prog
= NULL
;
361 progPos
= shProg
->Uniforms
->Uniforms
[index
].VertPos
;
363 prog
= &shProg
->VertexProgram
->Base
;
366 progPos
= shProg
->Uniforms
->Uniforms
[index
].FragPos
;
368 prog
= &shProg
->FragmentProgram
->Base
;
370 progPos
= shProg
->Uniforms
->Uniforms
[index
].GeomPos
;
372 prog
= &shProg
->GeometryProgram
->Base
;
377 if (!prog
|| progPos
< 0)
378 return NULL
; /* should never happen */
380 return &prog
->Parameters
->Parameters
[progPos
];
385 * Called by glGetActiveUniform().
388 _mesa_get_active_uniform(struct gl_context
*ctx
, GLuint program
, GLuint index
,
389 GLsizei maxLength
, GLsizei
*length
, GLint
*size
,
390 GLenum
*type
, GLchar
*nameOut
)
392 const struct gl_shader_program
*shProg
;
393 const struct gl_program
*prog
= NULL
;
394 const struct gl_program_parameter
*param
;
397 shProg
= _mesa_lookup_shader_program_err(ctx
, program
, "glGetActiveUniform");
401 if (!shProg
->Uniforms
|| index
>= shProg
->Uniforms
->NumUniforms
) {
402 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetActiveUniform(index)");
406 progPos
= shProg
->Uniforms
->Uniforms
[index
].VertPos
;
408 prog
= &shProg
->VertexProgram
->Base
;
411 progPos
= shProg
->Uniforms
->Uniforms
[index
].FragPos
;
413 prog
= &shProg
->FragmentProgram
->Base
;
415 progPos
= shProg
->Uniforms
->Uniforms
[index
].GeomPos
;
417 prog
= &shProg
->GeometryProgram
->Base
;
422 if (!prog
|| progPos
< 0)
423 return; /* should never happen */
425 ASSERT(progPos
< prog
->Parameters
->NumParameters
);
426 param
= &prog
->Parameters
->Parameters
[progPos
];
429 _mesa_copy_string(nameOut
, maxLength
, length
, param
->Name
);
433 GLint typeSize
= _mesa_sizeof_glsl_type(param
->DataType
);
434 if ((GLint
) param
->Size
> typeSize
) {
436 * Array elements are placed on vector[4] boundaries so they're
437 * a multiple of four floats. We round typeSize up to next multiple
438 * of four to get the right size below.
440 typeSize
= (typeSize
+ 3) & ~3;
442 /* Note that the returned size is in units of the <type>, not bytes */
443 *size
= param
->Size
/ typeSize
;
447 *type
= param
->DataType
;
454 get_matrix_dims(GLenum type
, GLint
*rows
, GLint
*cols
)
460 case GL_FLOAT_MAT2x3
:
464 case GL_FLOAT_MAT2x4
:
472 case GL_FLOAT_MAT3x2
:
476 case GL_FLOAT_MAT3x4
:
484 case GL_FLOAT_MAT4x2
:
488 case GL_FLOAT_MAT4x3
:
499 * Determine the number of rows and columns occupied by a uniform
500 * according to its datatype. For non-matrix types (such as GL_FLOAT_VEC4),
501 * the number of rows = 1 and cols = number of elements in the vector.
504 get_uniform_rows_cols(const struct gl_program_parameter
*p
,
505 GLint
*rows
, GLint
*cols
)
507 get_matrix_dims(p
->DataType
, rows
, cols
);
508 if (*rows
== 0 && *cols
== 0) {
509 /* not a matrix type, probably a float or vector */
515 *rows
= p
->Size
/ 4 + 1;
516 if (p
->Size
% 4 == 0)
526 * Helper for get_uniform[fi]v() functions.
527 * Given a shader program name and uniform location, return a pointer
528 * to the shader program and return the program parameter position.
531 lookup_uniform_parameter(struct gl_context
*ctx
, GLuint program
, GLint location
,
532 struct gl_program
**progOut
, GLint
*paramPosOut
)
534 struct gl_shader_program
*shProg
535 = _mesa_lookup_shader_program_err(ctx
, program
, "glGetUniform[if]v");
536 struct gl_program
*prog
= NULL
;
539 /* if shProg is NULL, we'll have already recorded an error */
542 if (!shProg
->Uniforms
||
544 location
>= (GLint
) shProg
->Uniforms
->NumUniforms
) {
545 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetUniformfv(location)");
548 /* OK, find the gl_program and program parameter location */
549 progPos
= shProg
->Uniforms
->Uniforms
[location
].VertPos
;
551 prog
= &shProg
->VertexProgram
->Base
;
554 progPos
= shProg
->Uniforms
->Uniforms
[location
].FragPos
;
556 prog
= &shProg
->FragmentProgram
->Base
;
558 progPos
= shProg
->Uniforms
->Uniforms
[location
].GeomPos
;
560 prog
= &shProg
->GeometryProgram
->Base
;
568 *paramPosOut
= progPos
;
573 * GLGL uniform arrays and structs require special handling.
575 * The GL_ARB_shader_objects spec says that if you use
576 * glGetUniformLocation to get the location of an array, you CANNOT
577 * access other elements of the array by adding an offset to the
578 * returned location. For example, you must call
579 * glGetUniformLocation("foo[16]") if you want to set the 16th element
580 * of the array with glUniform().
582 * HOWEVER, some other OpenGL drivers allow accessing array elements
583 * by adding an offset to the returned array location. And some apps
584 * seem to depend on that behaviour.
586 * Mesa's gl_uniform_list doesn't directly support this since each
587 * entry in the list describes one uniform variable, not one uniform
588 * element. We could insert dummy entries in the list for each array
589 * element after [0] but that causes complications elsewhere.
591 * We solve this problem by encoding two values in the location that's
592 * returned by glGetUniformLocation():
593 * a) index into gl_uniform_list::Uniforms[] for the uniform
594 * b) an array/field offset (0 for simple types)
596 * These two values are encoded in the high and low halves of a GLint.
597 * By putting the uniform number in the high part and the offset in the
598 * low part, we can support the unofficial ability to index into arrays
599 * by adding offsets to the location value.
602 merge_location_offset(GLint
*location
, GLint offset
)
604 *location
= (*location
<< 16) | offset
;
609 * Separate the uniform location and parameter offset. See above.
612 split_location_offset(GLint
*location
, GLint
*offset
)
614 *offset
= *location
& 0xffff;
615 *location
= *location
>> 16;
621 * Called via glGetUniformfv().
624 _mesa_get_uniformfv(struct gl_context
*ctx
, GLuint program
, GLint location
,
627 struct gl_program
*prog
;
631 split_location_offset(&location
, &offset
);
633 lookup_uniform_parameter(ctx
, program
, location
, &prog
, ¶mPos
);
636 const struct gl_program_parameter
*p
=
637 &prog
->Parameters
->Parameters
[paramPos
];
638 GLint rows
, cols
, i
, j
, k
;
640 get_uniform_rows_cols(p
, &rows
, &cols
);
643 for (i
= 0; i
< rows
; i
++) {
644 for (j
= 0; j
< cols
; j
++ ) {
645 params
[k
++] = prog
->Parameters
->ParameterValues
[paramPos
+i
][j
];
653 * Called via glGetUniformiv().
654 * \sa _mesa_get_uniformfv, only difference is a cast.
657 _mesa_get_uniformiv(struct gl_context
*ctx
, GLuint program
, GLint location
,
660 struct gl_program
*prog
;
664 split_location_offset(&location
, &offset
);
666 lookup_uniform_parameter(ctx
, program
, location
, &prog
, ¶mPos
);
669 const struct gl_program_parameter
*p
=
670 &prog
->Parameters
->Parameters
[paramPos
];
671 GLint rows
, cols
, i
, j
, k
;
673 get_uniform_rows_cols(p
, &rows
, &cols
);
676 for (i
= 0; i
< rows
; i
++) {
677 for (j
= 0; j
< cols
; j
++ ) {
678 params
[k
++] = (GLint
) prog
->Parameters
->ParameterValues
[paramPos
+i
][j
];
686 * Called via glGetUniformuiv().
687 * New in GL_EXT_gpu_shader4, OpenGL 3.0
688 * \sa _mesa_get_uniformfv, only difference is a cast.
691 _mesa_get_uniformuiv(struct gl_context
*ctx
, GLuint program
, GLint location
,
694 struct gl_program
*prog
;
698 split_location_offset(&location
, &offset
);
700 lookup_uniform_parameter(ctx
, program
, location
, &prog
, ¶mPos
);
703 const struct gl_program_parameter
*p
=
704 &prog
->Parameters
->Parameters
[paramPos
];
705 GLint rows
, cols
, i
, j
, k
;
707 get_uniform_rows_cols(p
, &rows
, &cols
);
710 for (i
= 0; i
< rows
; i
++) {
711 for (j
= 0; j
< cols
; j
++ ) {
712 params
[k
++] = (GLuint
) prog
->Parameters
->ParameterValues
[paramPos
+i
][j
];
720 * Called via glGetUniformLocation().
722 * The return value will encode two values, the uniform location and an
723 * offset (used for arrays, structs).
726 _mesa_get_uniform_location(struct gl_context
*ctx
, struct gl_shader_program
*shProg
,
729 GLint offset
= 0, location
= -1;
731 if (shProg
->LinkStatus
== GL_FALSE
) {
732 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetUniformfv(program)");
736 /* XXX we should return -1 if the uniform was declared, but not
740 /* XXX we need to be able to parse uniform names for structs and arrays
747 /* handle 1-dimension arrays here... */
748 char *c
= strchr(name
, '[');
750 /* truncate name at [ */
751 const GLint len
= c
- name
;
752 GLchar
*newName
= malloc(len
+ 1);
754 return -1; /* out of mem */
755 memcpy(newName
, name
, len
);
758 location
= _mesa_lookup_uniform(shProg
->Uniforms
, newName
);
760 const GLint element
= atoi(c
+ 1);
762 /* get type of the uniform array element */
763 struct gl_program_parameter
*p
;
764 p
= get_uniform_parameter(shProg
, location
);
767 get_matrix_dims(p
->DataType
, &rows
, &cols
);
770 offset
= element
* rows
;
780 location
= _mesa_lookup_uniform(shProg
->Uniforms
, name
);
784 merge_location_offset(&location
, offset
);
793 * Update the vertex/fragment program's TexturesUsed array.
795 * This needs to be called after glUniform(set sampler var) is called.
796 * A call to glUniform(samplerVar, value) causes a sampler to point to a
797 * particular texture unit. We know the sampler's texture target
798 * (1D/2D/3D/etc) from compile time but the sampler's texture unit is
799 * set by glUniform() calls.
801 * So, scan the program->SamplerUnits[] and program->SamplerTargets[]
802 * information to update the prog->TexturesUsed[] values.
803 * Each value of TexturesUsed[unit] is one of zero, TEXTURE_1D_INDEX,
804 * TEXTURE_2D_INDEX, TEXTURE_3D_INDEX, etc.
805 * We'll use that info for state validation before rendering.
808 _mesa_update_shader_textures_used(struct gl_program
*prog
)
812 memset(prog
->TexturesUsed
, 0, sizeof(prog
->TexturesUsed
));
814 for (s
= 0; s
< MAX_SAMPLERS
; s
++) {
815 if (prog
->SamplersUsed
& (1 << s
)) {
816 GLuint unit
= prog
->SamplerUnits
[s
];
817 GLuint tgt
= prog
->SamplerTargets
[s
];
818 assert(unit
< MAX_TEXTURE_IMAGE_UNITS
);
819 assert(tgt
< NUM_TEXTURE_TARGETS
);
820 prog
->TexturesUsed
[unit
] |= (1 << tgt
);
827 * Check if the type given by userType is allowed to set a uniform of the
828 * target type. Generally, equivalence is required, but setting Boolean
829 * uniforms can be done with glUniformiv or glUniformfv.
832 compatible_types(GLenum userType
, GLenum targetType
)
834 if (userType
== targetType
)
837 if (targetType
== GL_BOOL
&& (userType
== GL_FLOAT
||
838 userType
== GL_UNSIGNED_INT
||
842 if (targetType
== GL_BOOL_VEC2
&& (userType
== GL_FLOAT_VEC2
||
843 userType
== GL_UNSIGNED_INT_VEC2
||
844 userType
== GL_INT_VEC2
))
847 if (targetType
== GL_BOOL_VEC3
&& (userType
== GL_FLOAT_VEC3
||
848 userType
== GL_UNSIGNED_INT_VEC3
||
849 userType
== GL_INT_VEC3
))
852 if (targetType
== GL_BOOL_VEC4
&& (userType
== GL_FLOAT_VEC4
||
853 userType
== GL_UNSIGNED_INT_VEC4
||
854 userType
== GL_INT_VEC4
))
857 if (is_sampler_type(targetType
) && userType
== GL_INT
)
865 * Set the value of a program's uniform variable.
866 * \param program the program whose uniform to update
867 * \param index the index of the program parameter for the uniform
868 * \param offset additional parameter slot offset (for arrays)
869 * \param type the incoming datatype of 'values'
870 * \param count the number of uniforms to set
871 * \param elems number of elements per uniform (1, 2, 3 or 4)
872 * \param values the new values, of datatype 'type'
875 set_program_uniform(struct gl_context
*ctx
, struct gl_program
*program
,
876 GLint index
, GLint offset
,
877 GLenum type
, GLsizei count
, GLint elems
,
880 const struct gl_program_parameter
*param
=
881 &program
->Parameters
->Parameters
[index
];
887 if (!compatible_types(type
, param
->DataType
)) {
888 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glUniform(type mismatch)");
892 if (index
+ offset
> (GLint
) program
->Parameters
->Size
) {
897 if (param
->Type
== PROGRAM_SAMPLER
) {
898 /* This controls which texture unit which is used by a sampler */
899 GLboolean changed
= GL_FALSE
;
902 /* this should have been caught by the compatible_types() check */
903 ASSERT(type
== GL_INT
);
905 /* loop over number of samplers to change */
906 for (i
= 0; i
< count
; i
++) {
908 (GLuint
) program
->Parameters
->ParameterValues
[index
+ offset
+ i
][0];
909 GLuint texUnit
= ((GLuint
*) values
)[i
];
911 /* check that the sampler (tex unit index) is legal */
912 if (texUnit
>= ctx
->Const
.MaxTextureImageUnits
) {
913 _mesa_error(ctx
, GL_INVALID_VALUE
,
914 "glUniform1(invalid sampler/tex unit index for '%s')",
919 /* This maps a sampler to a texture unit: */
920 if (sampler
< MAX_SAMPLERS
) {
922 printf("Set program %p sampler %d '%s' to unit %u\n",
923 program
, sampler
, param
->Name
, texUnit
);
925 if (program
->SamplerUnits
[sampler
] != texUnit
) {
926 program
->SamplerUnits
[sampler
] = texUnit
;
933 /* When a sampler's value changes it usually requires rewriting
934 * a GPU program's TEX instructions since there may not be a
935 * sampler->texture lookup table. We signal this with the
936 * ProgramStringNotify() callback.
938 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
| _NEW_PROGRAM
);
939 _mesa_update_shader_textures_used(program
);
940 /* Do we need to care about the return value here?
941 * This should not be the first time the driver was notified of
944 (void) ctx
->Driver
.ProgramStringNotify(ctx
, program
->Target
, program
);
948 /* ordinary uniform variable */
949 const GLboolean isUniformBool
= is_boolean_type(param
->DataType
);
950 const GLenum basicType
= base_uniform_type(type
);
951 const GLint slots
= (param
->Size
+ 3) / 4;
952 const GLint typeSize
= _mesa_sizeof_glsl_type(param
->DataType
);
955 if ((GLint
) param
->Size
> typeSize
) {
957 /* we'll ignore extra data below */
960 /* non-array: count must be at most one; count == 0 is handled by the loop below */
962 _mesa_error(ctx
, GL_INVALID_OPERATION
,
963 "glUniform(uniform '%s' is not an array)",
969 /* loop over number of array elements */
970 for (k
= 0; k
< count
; k
++) {
973 if (offset
+ k
>= slots
) {
974 /* Extra array data is ignored */
978 /* uniformVal (the destination) is always float[4] */
979 uniformVal
= program
->Parameters
->ParameterValues
[index
+ offset
+ k
];
981 if (basicType
== GL_INT
) {
982 /* convert user's ints to floats */
983 const GLint
*iValues
= ((const GLint
*) values
) + k
* elems
;
984 for (i
= 0; i
< elems
; i
++) {
985 uniformVal
[i
] = (GLfloat
) iValues
[i
];
988 else if (basicType
== GL_UNSIGNED_INT
) {
989 /* convert user's uints to floats */
990 const GLuint
*iValues
= ((const GLuint
*) values
) + k
* elems
;
991 for (i
= 0; i
< elems
; i
++) {
992 uniformVal
[i
] = (GLfloat
) iValues
[i
];
996 const GLfloat
*fValues
= ((const GLfloat
*) values
) + k
* elems
;
997 assert(basicType
== GL_FLOAT
);
998 for (i
= 0; i
< elems
; i
++) {
999 uniformVal
[i
] = fValues
[i
];
1003 /* if the uniform is bool-valued, convert to 1.0 or 0.0 */
1004 if (isUniformBool
) {
1005 for (i
= 0; i
< elems
; i
++) {
1006 uniformVal
[i
] = uniformVal
[i
] ? 1.0f
: 0.0f
;
1015 * Called via glUniform*() functions.
1018 _mesa_uniform(struct gl_context
*ctx
, struct gl_shader_program
*shProg
,
1019 GLint location
, GLsizei count
,
1020 const GLvoid
*values
, GLenum type
)
1022 struct gl_uniform
*uniform
;
1023 GLint elems
, offset
;
1025 if (!shProg
|| !shProg
->LinkStatus
) {
1026 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glUniform(program not linked)");
1031 return; /* The standard specifies this as a no-op */
1033 if (location
< -1) {
1034 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glUniform(location=%d)",
1039 split_location_offset(&location
, &offset
);
1041 if (location
< 0 || location
>= (GLint
) shProg
->Uniforms
->NumUniforms
) {
1042 _mesa_error(ctx
, GL_INVALID_VALUE
, "glUniform(location=%d)", location
);
1047 _mesa_error(ctx
, GL_INVALID_VALUE
, "glUniform(count < 0)");
1051 elems
= _mesa_sizeof_glsl_type(type
);
1053 FLUSH_VERTICES(ctx
, _NEW_PROGRAM_CONSTANTS
);
1055 uniform
= &shProg
->Uniforms
->Uniforms
[location
];
1057 if (ctx
->Shader
.Flags
& GLSL_UNIFORMS
) {
1058 const GLenum basicType
= base_uniform_type(type
);
1060 printf("Mesa: set program %u uniform %s (loc %d) to: ",
1061 shProg
->Name
, uniform
->Name
, location
);
1062 if (basicType
== GL_INT
) {
1063 const GLint
*v
= (const GLint
*) values
;
1064 for (i
= 0; i
< count
* elems
; i
++) {
1065 printf("%d ", v
[i
]);
1068 else if (basicType
== GL_UNSIGNED_INT
) {
1069 const GLuint
*v
= (const GLuint
*) values
;
1070 for (i
= 0; i
< count
* elems
; i
++) {
1071 printf("%u ", v
[i
]);
1075 const GLfloat
*v
= (const GLfloat
*) values
;
1076 assert(basicType
== GL_FLOAT
);
1077 for (i
= 0; i
< count
* elems
; i
++) {
1078 printf("%g ", v
[i
]);
1084 /* A uniform var may be used by both a vertex shader and a fragment
1085 * shader. We may need to update one or both shader's uniform here:
1087 if (shProg
->VertexProgram
) {
1088 /* convert uniform location to program parameter index */
1089 GLint index
= uniform
->VertPos
;
1091 set_program_uniform(ctx
, &shProg
->VertexProgram
->Base
,
1092 index
, offset
, type
, count
, elems
, values
);
1096 if (shProg
->FragmentProgram
) {
1097 /* convert uniform location to program parameter index */
1098 GLint index
= uniform
->FragPos
;
1100 set_program_uniform(ctx
, &shProg
->FragmentProgram
->Base
,
1101 index
, offset
, type
, count
, elems
, values
);
1105 if (shProg
->GeometryProgram
) {
1106 /* convert uniform location to program parameter index */
1107 GLint index
= uniform
->GeomPos
;
1109 set_program_uniform(ctx
, &shProg
->GeometryProgram
->Base
,
1110 index
, offset
, type
, count
, elems
, values
);
1114 uniform
->Initialized
= GL_TRUE
;
1119 * Set a matrix-valued program parameter.
1122 set_program_uniform_matrix(struct gl_context
*ctx
, struct gl_program
*program
,
1123 GLuint index
, GLuint offset
,
1124 GLuint count
, GLuint rows
, GLuint cols
,
1125 GLboolean transpose
, const GLfloat
*values
)
1127 GLuint mat
, row
, col
;
1129 const struct gl_program_parameter
* param
= &program
->Parameters
->Parameters
[index
];
1130 const GLuint slots
= (param
->Size
+ 3) / 4;
1131 const GLint typeSize
= _mesa_sizeof_glsl_type(param
->DataType
);
1134 /* check that the number of rows, columns is correct */
1135 get_matrix_dims(param
->DataType
, &nr
, &nc
);
1136 if (rows
!= nr
|| cols
!= nc
) {
1137 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1138 "glUniformMatrix(matrix size mismatch)");
1142 if ((GLint
) param
->Size
<= typeSize
) {
1143 /* non-array: count must be at most one; count == 0 is handled by the loop below */
1145 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1146 "glUniformMatrix(uniform is not an array)");
1152 * Note: the _columns_ of a matrix are stored in program registers, not
1153 * the rows. So, the loops below look a little funny.
1154 * XXX could optimize this a bit...
1157 /* loop over matrices */
1158 for (mat
= 0; mat
< count
; mat
++) {
1161 for (col
= 0; col
< cols
; col
++) {
1163 if (offset
>= slots
) {
1164 /* Ignore writes beyond the end of (the used part of) an array */
1167 v
= program
->Parameters
->ParameterValues
[index
+ offset
];
1168 for (row
= 0; row
< rows
; row
++) {
1170 v
[row
] = values
[src
+ row
* cols
+ col
];
1173 v
[row
] = values
[src
+ col
* rows
+ row
];
1180 src
+= rows
* cols
; /* next matrix */
1186 * Called by glUniformMatrix*() functions.
1187 * Note: cols=2, rows=4 ==> array[2] of vec4
1190 _mesa_uniform_matrix(struct gl_context
*ctx
, struct gl_shader_program
*shProg
,
1191 GLint cols
, GLint rows
,
1192 GLint location
, GLsizei count
,
1193 GLboolean transpose
, const GLfloat
*values
)
1195 struct gl_uniform
*uniform
;
1198 if (!shProg
|| !shProg
->LinkStatus
) {
1199 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1200 "glUniformMatrix(program not linked)");
1205 return; /* The standard specifies this as a no-op */
1207 if (location
< -1) {
1208 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glUniformMatrix(location)");
1212 split_location_offset(&location
, &offset
);
1214 if (location
< 0 || location
>= (GLint
) shProg
->Uniforms
->NumUniforms
) {
1215 _mesa_error(ctx
, GL_INVALID_VALUE
, "glUniformMatrix(location)");
1218 if (values
== NULL
) {
1219 _mesa_error(ctx
, GL_INVALID_VALUE
, "glUniformMatrix");
1223 FLUSH_VERTICES(ctx
, _NEW_PROGRAM_CONSTANTS
);
1225 uniform
= &shProg
->Uniforms
->Uniforms
[location
];
1227 if (shProg
->VertexProgram
) {
1228 /* convert uniform location to program parameter index */
1229 GLint index
= uniform
->VertPos
;
1231 set_program_uniform_matrix(ctx
, &shProg
->VertexProgram
->Base
,
1233 count
, rows
, cols
, transpose
, values
);
1237 if (shProg
->FragmentProgram
) {
1238 /* convert uniform location to program parameter index */
1239 GLint index
= uniform
->FragPos
;
1241 set_program_uniform_matrix(ctx
, &shProg
->FragmentProgram
->Base
,
1243 count
, rows
, cols
, transpose
, values
);
1247 if (shProg
->GeometryProgram
) {
1248 /* convert uniform location to program parameter index */
1249 GLint index
= uniform
->GeomPos
;
1251 set_program_uniform_matrix(ctx
, &shProg
->GeometryProgram
->Base
,
1253 count
, rows
, cols
, transpose
, values
);
1257 uniform
->Initialized
= GL_TRUE
;
1262 _mesa_Uniform1fARB(GLint location
, GLfloat v0
)
1264 GET_CURRENT_CONTEXT(ctx
);
1265 _mesa_uniform(ctx
, ctx
->Shader
.ActiveProgram
, location
, 1, &v0
, GL_FLOAT
);
1269 _mesa_Uniform2fARB(GLint location
, GLfloat v0
, GLfloat v1
)
1271 GET_CURRENT_CONTEXT(ctx
);
1275 _mesa_uniform(ctx
, ctx
->Shader
.ActiveProgram
, location
, 1, v
, GL_FLOAT_VEC2
);
1279 _mesa_Uniform3fARB(GLint location
, GLfloat v0
, GLfloat v1
, GLfloat v2
)
1281 GET_CURRENT_CONTEXT(ctx
);
1286 _mesa_uniform(ctx
, ctx
->Shader
.ActiveProgram
, location
, 1, v
, GL_FLOAT_VEC3
);
1290 _mesa_Uniform4fARB(GLint location
, GLfloat v0
, GLfloat v1
, GLfloat v2
,
1293 GET_CURRENT_CONTEXT(ctx
);
1299 _mesa_uniform(ctx
, ctx
->Shader
.ActiveProgram
, location
, 1, v
, GL_FLOAT_VEC4
);
1303 _mesa_Uniform1iARB(GLint location
, GLint v0
)
1305 GET_CURRENT_CONTEXT(ctx
);
1306 _mesa_uniform(ctx
, ctx
->Shader
.ActiveProgram
, location
, 1, &v0
, GL_INT
);
1310 _mesa_Uniform2iARB(GLint location
, GLint v0
, GLint v1
)
1312 GET_CURRENT_CONTEXT(ctx
);
1316 _mesa_uniform(ctx
, ctx
->Shader
.ActiveProgram
, location
, 1, v
, GL_INT_VEC2
);
1320 _mesa_Uniform3iARB(GLint location
, GLint v0
, GLint v1
, GLint v2
)
1322 GET_CURRENT_CONTEXT(ctx
);
1327 _mesa_uniform(ctx
, ctx
->Shader
.ActiveProgram
, location
, 1, v
, GL_INT_VEC3
);
1331 _mesa_Uniform4iARB(GLint location
, GLint v0
, GLint v1
, GLint v2
, GLint v3
)
1333 GET_CURRENT_CONTEXT(ctx
);
1339 _mesa_uniform(ctx
, ctx
->Shader
.ActiveProgram
, location
, 1, v
, GL_INT_VEC4
);
1343 _mesa_Uniform1fvARB(GLint location
, GLsizei count
, const GLfloat
* value
)
1345 GET_CURRENT_CONTEXT(ctx
);
1346 _mesa_uniform(ctx
, ctx
->Shader
.ActiveProgram
, location
, count
, value
, GL_FLOAT
);
1350 _mesa_Uniform2fvARB(GLint location
, GLsizei count
, const GLfloat
* value
)
1352 GET_CURRENT_CONTEXT(ctx
);
1353 _mesa_uniform(ctx
, ctx
->Shader
.ActiveProgram
, location
, count
, value
, GL_FLOAT_VEC2
);
1357 _mesa_Uniform3fvARB(GLint location
, GLsizei count
, const GLfloat
* value
)
1359 GET_CURRENT_CONTEXT(ctx
);
1360 _mesa_uniform(ctx
, ctx
->Shader
.ActiveProgram
, location
, count
, value
, GL_FLOAT_VEC3
);
1364 _mesa_Uniform4fvARB(GLint location
, GLsizei count
, const GLfloat
* value
)
1366 GET_CURRENT_CONTEXT(ctx
);
1367 _mesa_uniform(ctx
, ctx
->Shader
.ActiveProgram
, location
, count
, value
, GL_FLOAT_VEC4
);
1371 _mesa_Uniform1ivARB(GLint location
, GLsizei count
, const GLint
* value
)
1373 GET_CURRENT_CONTEXT(ctx
);
1374 _mesa_uniform(ctx
, ctx
->Shader
.ActiveProgram
, location
, count
, value
, GL_INT
);
1378 _mesa_Uniform2ivARB(GLint location
, GLsizei count
, const GLint
* value
)
1380 GET_CURRENT_CONTEXT(ctx
);
1381 _mesa_uniform(ctx
, ctx
->Shader
.ActiveProgram
, location
, count
, value
, GL_INT_VEC2
);
1385 _mesa_Uniform3ivARB(GLint location
, GLsizei count
, const GLint
* value
)
1387 GET_CURRENT_CONTEXT(ctx
);
1388 _mesa_uniform(ctx
, ctx
->Shader
.ActiveProgram
, location
, count
, value
, GL_INT_VEC3
);
1392 _mesa_Uniform4ivARB(GLint location
, GLsizei count
, const GLint
* value
)
1394 GET_CURRENT_CONTEXT(ctx
);
1395 _mesa_uniform(ctx
, ctx
->Shader
.ActiveProgram
, location
, count
, value
, GL_INT_VEC4
);
1399 /** OpenGL 3.0 GLuint-valued functions **/
1401 _mesa_Uniform1ui(GLint location
, GLuint v0
)
1403 GET_CURRENT_CONTEXT(ctx
);
1404 _mesa_uniform(ctx
, ctx
->Shader
.ActiveProgram
, location
, 1, &v0
, GL_UNSIGNED_INT
);
1408 _mesa_Uniform2ui(GLint location
, GLuint v0
, GLuint v1
)
1410 GET_CURRENT_CONTEXT(ctx
);
1414 _mesa_uniform(ctx
, ctx
->Shader
.ActiveProgram
, location
, 1, v
, GL_UNSIGNED_INT_VEC2
);
1418 _mesa_Uniform3ui(GLint location
, GLuint v0
, GLuint v1
, GLuint v2
)
1420 GET_CURRENT_CONTEXT(ctx
);
1425 _mesa_uniform(ctx
, ctx
->Shader
.ActiveProgram
, location
, 1, v
, GL_UNSIGNED_INT_VEC3
);
1429 _mesa_Uniform4ui(GLint location
, GLuint v0
, GLuint v1
, GLuint v2
, GLuint v3
)
1431 GET_CURRENT_CONTEXT(ctx
);
1437 _mesa_uniform(ctx
, ctx
->Shader
.ActiveProgram
, location
, 1, v
, GL_UNSIGNED_INT_VEC4
);
1441 _mesa_Uniform1uiv(GLint location
, GLsizei count
, const GLuint
*value
)
1443 GET_CURRENT_CONTEXT(ctx
);
1444 _mesa_uniform(ctx
, ctx
->Shader
.ActiveProgram
, location
, count
, value
, GL_UNSIGNED_INT
);
1448 _mesa_Uniform2uiv(GLint location
, GLsizei count
, const GLuint
*value
)
1450 GET_CURRENT_CONTEXT(ctx
);
1451 _mesa_uniform(ctx
, ctx
->Shader
.ActiveProgram
, location
, count
, value
, GL_UNSIGNED_INT_VEC2
);
1455 _mesa_Uniform3uiv(GLint location
, GLsizei count
, const GLuint
*value
)
1457 GET_CURRENT_CONTEXT(ctx
);
1458 _mesa_uniform(ctx
, ctx
->Shader
.ActiveProgram
, location
, count
, value
, GL_UNSIGNED_INT_VEC3
);
1462 _mesa_Uniform4uiv(GLint location
, GLsizei count
, const GLuint
*value
)
1464 GET_CURRENT_CONTEXT(ctx
);
1465 _mesa_uniform(ctx
, ctx
->Shader
.ActiveProgram
, location
, count
, value
, GL_UNSIGNED_INT_VEC4
);
1471 _mesa_UniformMatrix2fvARB(GLint location
, GLsizei count
, GLboolean transpose
,
1472 const GLfloat
* value
)
1474 GET_CURRENT_CONTEXT(ctx
);
1475 _mesa_uniform_matrix(ctx
, ctx
->Shader
.ActiveProgram
,
1476 2, 2, location
, count
, transpose
, value
);
1480 _mesa_UniformMatrix3fvARB(GLint location
, GLsizei count
, GLboolean transpose
,
1481 const GLfloat
* value
)
1483 GET_CURRENT_CONTEXT(ctx
);
1484 _mesa_uniform_matrix(ctx
, ctx
->Shader
.ActiveProgram
,
1485 3, 3, location
, count
, transpose
, value
);
1489 _mesa_UniformMatrix4fvARB(GLint location
, GLsizei count
, GLboolean transpose
,
1490 const GLfloat
* value
)
1492 GET_CURRENT_CONTEXT(ctx
);
1493 _mesa_uniform_matrix(ctx
, ctx
->Shader
.ActiveProgram
,
1494 4, 4, location
, count
, transpose
, value
);
1499 * Non-square UniformMatrix are OpenGL 2.1
1502 _mesa_UniformMatrix2x3fv(GLint location
, GLsizei count
, GLboolean transpose
,
1503 const GLfloat
*value
)
1505 GET_CURRENT_CONTEXT(ctx
);
1506 _mesa_uniform_matrix(ctx
, ctx
->Shader
.ActiveProgram
,
1507 2, 3, location
, count
, transpose
, value
);
1511 _mesa_UniformMatrix3x2fv(GLint location
, GLsizei count
, GLboolean transpose
,
1512 const GLfloat
*value
)
1514 GET_CURRENT_CONTEXT(ctx
);
1515 _mesa_uniform_matrix(ctx
, ctx
->Shader
.ActiveProgram
,
1516 3, 2, location
, count
, transpose
, value
);
1520 _mesa_UniformMatrix2x4fv(GLint location
, GLsizei count
, GLboolean transpose
,
1521 const GLfloat
*value
)
1523 GET_CURRENT_CONTEXT(ctx
);
1524 _mesa_uniform_matrix(ctx
, ctx
->Shader
.ActiveProgram
,
1525 2, 4, location
, count
, transpose
, value
);
1529 _mesa_UniformMatrix4x2fv(GLint location
, GLsizei count
, GLboolean transpose
,
1530 const GLfloat
*value
)
1532 GET_CURRENT_CONTEXT(ctx
);
1533 _mesa_uniform_matrix(ctx
, ctx
->Shader
.ActiveProgram
,
1534 4, 2, location
, count
, transpose
, value
);
1538 _mesa_UniformMatrix3x4fv(GLint location
, GLsizei count
, GLboolean transpose
,
1539 const GLfloat
*value
)
1541 GET_CURRENT_CONTEXT(ctx
);
1542 _mesa_uniform_matrix(ctx
, ctx
->Shader
.ActiveProgram
,
1543 3, 4, location
, count
, transpose
, value
);
1547 _mesa_UniformMatrix4x3fv(GLint location
, GLsizei count
, GLboolean transpose
,
1548 const GLfloat
*value
)
1550 GET_CURRENT_CONTEXT(ctx
);
1551 _mesa_uniform_matrix(ctx
, ctx
->Shader
.ActiveProgram
,
1552 4, 3, location
, count
, transpose
, value
);
1557 _mesa_GetUniformfvARB(GLhandleARB program
, GLint location
, GLfloat
*params
)
1559 GET_CURRENT_CONTEXT(ctx
);
1560 _mesa_get_uniformfv(ctx
, program
, location
, params
);
1565 _mesa_GetUniformivARB(GLhandleARB program
, GLint location
, GLint
*params
)
1567 GET_CURRENT_CONTEXT(ctx
);
1568 _mesa_get_uniformiv(ctx
, program
, location
, params
);
1574 _mesa_GetUniformuiv(GLhandleARB program
, GLint location
, GLuint
*params
)
1576 GET_CURRENT_CONTEXT(ctx
);
1577 _mesa_get_uniformuiv(ctx
, program
, location
, params
);
1583 _mesa_GetUniformLocationARB(GLhandleARB programObj
, const GLcharARB
*name
)
1585 struct gl_shader_program
*shProg
;
1587 GET_CURRENT_CONTEXT(ctx
);
1589 shProg
= _mesa_lookup_shader_program_err(ctx
, programObj
,
1590 "glGetUniformLocation");
1594 return _mesa_get_uniform_location(ctx
, shProg
, name
);
1599 _mesa_GetActiveUniformARB(GLhandleARB program
, GLuint index
,
1600 GLsizei maxLength
, GLsizei
* length
, GLint
* size
,
1601 GLenum
* type
, GLcharARB
* name
)
1603 GET_CURRENT_CONTEXT(ctx
);
1604 _mesa_get_active_uniform(ctx
, program
, index
, maxLength
, length
, size
,
1610 * Plug in shader uniform-related functions into API dispatch table.
1613 _mesa_init_shader_uniform_dispatch(struct _glapi_table
*exec
)
1616 SET_Uniform1fARB(exec
, _mesa_Uniform1fARB
);
1617 SET_Uniform2fARB(exec
, _mesa_Uniform2fARB
);
1618 SET_Uniform3fARB(exec
, _mesa_Uniform3fARB
);
1619 SET_Uniform4fARB(exec
, _mesa_Uniform4fARB
);
1620 SET_Uniform1iARB(exec
, _mesa_Uniform1iARB
);
1621 SET_Uniform2iARB(exec
, _mesa_Uniform2iARB
);
1622 SET_Uniform3iARB(exec
, _mesa_Uniform3iARB
);
1623 SET_Uniform4iARB(exec
, _mesa_Uniform4iARB
);
1624 SET_Uniform1fvARB(exec
, _mesa_Uniform1fvARB
);
1625 SET_Uniform2fvARB(exec
, _mesa_Uniform2fvARB
);
1626 SET_Uniform3fvARB(exec
, _mesa_Uniform3fvARB
);
1627 SET_Uniform4fvARB(exec
, _mesa_Uniform4fvARB
);
1628 SET_Uniform1ivARB(exec
, _mesa_Uniform1ivARB
);
1629 SET_Uniform2ivARB(exec
, _mesa_Uniform2ivARB
);
1630 SET_Uniform3ivARB(exec
, _mesa_Uniform3ivARB
);
1631 SET_Uniform4ivARB(exec
, _mesa_Uniform4ivARB
);
1632 SET_UniformMatrix2fvARB(exec
, _mesa_UniformMatrix2fvARB
);
1633 SET_UniformMatrix3fvARB(exec
, _mesa_UniformMatrix3fvARB
);
1634 SET_UniformMatrix4fvARB(exec
, _mesa_UniformMatrix4fvARB
);
1636 SET_GetActiveUniformARB(exec
, _mesa_GetActiveUniformARB
);
1637 SET_GetUniformLocationARB(exec
, _mesa_GetUniformLocationARB
);
1638 SET_GetUniformfvARB(exec
, _mesa_GetUniformfvARB
);
1639 SET_GetUniformivARB(exec
, _mesa_GetUniformivARB
);
1642 SET_UniformMatrix2x3fv(exec
, _mesa_UniformMatrix2x3fv
);
1643 SET_UniformMatrix3x2fv(exec
, _mesa_UniformMatrix3x2fv
);
1644 SET_UniformMatrix2x4fv(exec
, _mesa_UniformMatrix2x4fv
);
1645 SET_UniformMatrix4x2fv(exec
, _mesa_UniformMatrix4x2fv
);
1646 SET_UniformMatrix3x4fv(exec
, _mesa_UniformMatrix3x4fv
);
1647 SET_UniformMatrix4x3fv(exec
, _mesa_UniformMatrix4x3fv
);
1650 /* XXX finish dispatch */
1651 SET_Uniform1uiEXT(exec
, _mesa_Uniform1ui
);
1652 SET_Uniform2uiEXT(exec
, _mesa_Uniform2ui
);
1653 SET_Uniform3uiEXT(exec
, _mesa_Uniform3ui
);
1654 SET_Uniform4uiEXT(exec
, _mesa_Uniform4ui
);
1655 SET_Uniform1uivEXT(exec
, _mesa_Uniform1uiv
);
1656 SET_Uniform2uivEXT(exec
, _mesa_Uniform2uiv
);
1657 SET_Uniform3uivEXT(exec
, _mesa_Uniform3uiv
);
1658 SET_Uniform4uivEXT(exec
, _mesa_Uniform4uiv
);
1659 SET_GetUniformuivEXT(exec
, _mesa_GetUniformuiv
);
1662 #endif /* FEATURE_GL */