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/shaderapi.h"
43 #include "main/shaderobj.h"
44 #include "main/uniforms.h"
45 #include "program/prog_parameter.h"
46 #include "program/prog_statevars.h"
47 #include "program/prog_uniform.h"
48 #include "program/prog_instruction.h"
52 base_uniform_type(GLenum type
)
55 #if 0 /* not needed, for now */
68 case GL_UNSIGNED_INT_VEC2
:
69 case GL_UNSIGNED_INT_VEC3
:
70 case GL_UNSIGNED_INT_VEC4
:
71 return GL_UNSIGNED_INT
;
78 _mesa_problem(NULL
, "Invalid type in base_uniform_type()");
83 static struct gl_builtin_uniform_element gl_DepthRange_elements
[] = {
84 {"near", {STATE_DEPTH_RANGE
, 0, 0}, SWIZZLE_XXXX
},
85 {"far", {STATE_DEPTH_RANGE
, 0, 0}, SWIZZLE_YYYY
},
86 {"diff", {STATE_DEPTH_RANGE
, 0, 0}, SWIZZLE_ZZZZ
},
89 static struct gl_builtin_uniform_element gl_ClipPlane_elements
[] = {
90 {NULL
, {STATE_CLIPPLANE
, 0, 0}, SWIZZLE_XYZW
}
93 static struct gl_builtin_uniform_element gl_Point_elements
[] = {
94 {"size", {STATE_POINT_SIZE
}, SWIZZLE_XXXX
},
95 {"sizeMin", {STATE_POINT_SIZE
}, SWIZZLE_YYYY
},
96 {"sizeMax", {STATE_POINT_SIZE
}, SWIZZLE_ZZZZ
},
97 {"fadeThresholdSize", {STATE_POINT_SIZE
}, SWIZZLE_WWWW
},
98 {"distanceConstantAttenuation", {STATE_POINT_ATTENUATION
}, SWIZZLE_XXXX
},
99 {"distanceLinearAttenuation", {STATE_POINT_ATTENUATION
}, SWIZZLE_YYYY
},
100 {"distanceQuadraticAttenuation", {STATE_POINT_ATTENUATION
}, SWIZZLE_ZZZZ
},
103 static struct gl_builtin_uniform_element gl_FrontMaterial_elements
[] = {
104 {"emission", {STATE_MATERIAL
, 0, STATE_EMISSION
}, SWIZZLE_XYZW
},
105 {"ambient", {STATE_MATERIAL
, 0, STATE_AMBIENT
}, SWIZZLE_XYZW
},
106 {"diffuse", {STATE_MATERIAL
, 0, STATE_DIFFUSE
}, SWIZZLE_XYZW
},
107 {"specular", {STATE_MATERIAL
, 0, STATE_SPECULAR
}, SWIZZLE_XYZW
},
108 {"shininess", {STATE_MATERIAL
, 0, STATE_SHININESS
}, SWIZZLE_XXXX
},
111 static struct gl_builtin_uniform_element gl_BackMaterial_elements
[] = {
112 {"emission", {STATE_MATERIAL
, 1, STATE_EMISSION
}, SWIZZLE_XYZW
},
113 {"ambient", {STATE_MATERIAL
, 1, STATE_AMBIENT
}, SWIZZLE_XYZW
},
114 {"diffuse", {STATE_MATERIAL
, 1, STATE_DIFFUSE
}, SWIZZLE_XYZW
},
115 {"specular", {STATE_MATERIAL
, 1, STATE_SPECULAR
}, SWIZZLE_XYZW
},
116 {"shininess", {STATE_MATERIAL
, 1, STATE_SHININESS
}, SWIZZLE_XXXX
},
119 static struct gl_builtin_uniform_element gl_LightSource_elements
[] = {
120 {"ambient", {STATE_LIGHT
, 0, STATE_AMBIENT
}, SWIZZLE_XYZW
},
121 {"diffuse", {STATE_LIGHT
, 0, STATE_DIFFUSE
}, SWIZZLE_XYZW
},
122 {"specular", {STATE_LIGHT
, 0, STATE_SPECULAR
}, SWIZZLE_XYZW
},
123 {"position", {STATE_LIGHT
, 0, STATE_POSITION
}, SWIZZLE_XYZW
},
124 {"halfVector", {STATE_LIGHT
, 0, STATE_HALF_VECTOR
}, SWIZZLE_XYZW
},
125 {"spotDirection", {STATE_LIGHT
, 0, STATE_SPOT_DIRECTION
},
126 MAKE_SWIZZLE4(SWIZZLE_X
,
130 {"spotCosCutoff", {STATE_LIGHT
, 0, STATE_SPOT_DIRECTION
}, SWIZZLE_WWWW
},
131 {"spotCutoff", {STATE_LIGHT
, 0, STATE_SPOT_CUTOFF
}, SWIZZLE_XXXX
},
132 {"spotExponent", {STATE_LIGHT
, 0, STATE_ATTENUATION
}, SWIZZLE_WWWW
},
133 {"constantAttenuation", {STATE_LIGHT
, 0, STATE_ATTENUATION
}, SWIZZLE_XXXX
},
134 {"linearAttenuation", {STATE_LIGHT
, 0, STATE_ATTENUATION
}, SWIZZLE_YYYY
},
135 {"quadraticAttenuation", {STATE_LIGHT
, 0, STATE_ATTENUATION
}, SWIZZLE_ZZZZ
},
138 static struct gl_builtin_uniform_element gl_LightModel_elements
[] = {
139 {"ambient", {STATE_LIGHTMODEL_AMBIENT
, 0}, SWIZZLE_XYZW
},
142 static struct gl_builtin_uniform_element gl_FrontLightModelProduct_elements
[] = {
143 {"sceneColor", {STATE_LIGHTMODEL_SCENECOLOR
, 0}, SWIZZLE_XYZW
},
146 static struct gl_builtin_uniform_element gl_BackLightModelProduct_elements
[] = {
147 {"sceneColor", {STATE_LIGHTMODEL_SCENECOLOR
, 1}, SWIZZLE_XYZW
},
150 static struct gl_builtin_uniform_element gl_FrontLightProduct_elements
[] = {
151 {"ambient", {STATE_LIGHTPROD
, 0, 0, STATE_AMBIENT
}, SWIZZLE_XYZW
},
152 {"diffuse", {STATE_LIGHTPROD
, 0, 0, STATE_DIFFUSE
}, SWIZZLE_XYZW
},
153 {"specular", {STATE_LIGHTPROD
, 0, 0, STATE_SPECULAR
}, SWIZZLE_XYZW
},
156 static struct gl_builtin_uniform_element gl_BackLightProduct_elements
[] = {
157 {"ambient", {STATE_LIGHTPROD
, 0, 1, STATE_AMBIENT
}, SWIZZLE_XYZW
},
158 {"diffuse", {STATE_LIGHTPROD
, 0, 1, STATE_DIFFUSE
}, SWIZZLE_XYZW
},
159 {"specular", {STATE_LIGHTPROD
, 0, 1, STATE_SPECULAR
}, SWIZZLE_XYZW
},
162 static struct gl_builtin_uniform_element gl_TextureEnvColor_elements
[] = {
163 {NULL
, {STATE_TEXENV_COLOR
, 0}, SWIZZLE_XYZW
},
166 static struct gl_builtin_uniform_element gl_EyePlaneS_elements
[] = {
167 {NULL
, {STATE_TEXGEN
, 0, STATE_TEXGEN_EYE_S
}, SWIZZLE_XYZW
},
170 static struct gl_builtin_uniform_element gl_EyePlaneT_elements
[] = {
171 {NULL
, {STATE_TEXGEN
, 0, STATE_TEXGEN_EYE_T
}, SWIZZLE_XYZW
},
174 static struct gl_builtin_uniform_element gl_EyePlaneR_elements
[] = {
175 {NULL
, {STATE_TEXGEN
, 0, STATE_TEXGEN_EYE_R
}, SWIZZLE_XYZW
},
178 static struct gl_builtin_uniform_element gl_EyePlaneQ_elements
[] = {
179 {NULL
, {STATE_TEXGEN
, 0, STATE_TEXGEN_EYE_Q
}, SWIZZLE_XYZW
},
182 static struct gl_builtin_uniform_element gl_ObjectPlaneS_elements
[] = {
183 {NULL
, {STATE_TEXGEN
, 0, STATE_TEXGEN_OBJECT_S
}, SWIZZLE_XYZW
},
186 static struct gl_builtin_uniform_element gl_ObjectPlaneT_elements
[] = {
187 {NULL
, {STATE_TEXGEN
, 0, STATE_TEXGEN_OBJECT_T
}, SWIZZLE_XYZW
},
190 static struct gl_builtin_uniform_element gl_ObjectPlaneR_elements
[] = {
191 {NULL
, {STATE_TEXGEN
, 0, STATE_TEXGEN_OBJECT_R
}, SWIZZLE_XYZW
},
194 static struct gl_builtin_uniform_element gl_ObjectPlaneQ_elements
[] = {
195 {NULL
, {STATE_TEXGEN
, 0, STATE_TEXGEN_OBJECT_Q
}, SWIZZLE_XYZW
},
198 static struct gl_builtin_uniform_element gl_Fog_elements
[] = {
199 {"color", {STATE_FOG_COLOR
}, SWIZZLE_XYZW
},
200 {"density", {STATE_FOG_PARAMS
}, SWIZZLE_XXXX
},
201 {"start", {STATE_FOG_PARAMS
}, SWIZZLE_YYYY
},
202 {"end", {STATE_FOG_PARAMS
}, SWIZZLE_ZZZZ
},
203 {"scale", {STATE_FOG_PARAMS
}, SWIZZLE_WWWW
},
206 static struct gl_builtin_uniform_element gl_NormalScale_elements
[] = {
207 {NULL
, {STATE_NORMAL_SCALE
}, SWIZZLE_XXXX
},
210 #define MATRIX(name, statevar, modifier) \
211 static struct gl_builtin_uniform_element name ## _elements[] = { \
212 { NULL, { statevar, 0, 0, 0, modifier}, SWIZZLE_XYZW }, \
213 { NULL, { statevar, 0, 1, 1, modifier}, SWIZZLE_XYZW }, \
214 { NULL, { statevar, 0, 2, 2, modifier}, SWIZZLE_XYZW }, \
215 { NULL, { statevar, 0, 3, 3, modifier}, SWIZZLE_XYZW }, \
218 MATRIX(gl_ModelViewMatrix
,
219 STATE_MODELVIEW_MATRIX
, STATE_MATRIX_TRANSPOSE
);
220 MATRIX(gl_ModelViewMatrixInverse
,
221 STATE_MODELVIEW_MATRIX
, STATE_MATRIX_INVTRANS
);
222 MATRIX(gl_ModelViewMatrixTranspose
,
223 STATE_MODELVIEW_MATRIX
, 0);
224 MATRIX(gl_ModelViewMatrixInverseTranspose
,
225 STATE_MODELVIEW_MATRIX
, STATE_MATRIX_INVERSE
);
227 MATRIX(gl_ProjectionMatrix
,
228 STATE_PROJECTION_MATRIX
, STATE_MATRIX_TRANSPOSE
);
229 MATRIX(gl_ProjectionMatrixInverse
,
230 STATE_PROJECTION_MATRIX
, STATE_MATRIX_INVTRANS
);
231 MATRIX(gl_ProjectionMatrixTranspose
,
232 STATE_PROJECTION_MATRIX
, 0);
233 MATRIX(gl_ProjectionMatrixInverseTranspose
,
234 STATE_PROJECTION_MATRIX
, STATE_MATRIX_INVERSE
);
236 MATRIX(gl_ModelViewProjectionMatrix
,
237 STATE_MVP_MATRIX
, STATE_MATRIX_TRANSPOSE
);
238 MATRIX(gl_ModelViewProjectionMatrixInverse
,
239 STATE_MVP_MATRIX
, STATE_MATRIX_INVTRANS
);
240 MATRIX(gl_ModelViewProjectionMatrixTranspose
,
241 STATE_MVP_MATRIX
, 0);
242 MATRIX(gl_ModelViewProjectionMatrixInverseTranspose
,
243 STATE_MVP_MATRIX
, STATE_MATRIX_INVERSE
);
245 MATRIX(gl_TextureMatrix
,
246 STATE_TEXTURE_MATRIX
, STATE_MATRIX_TRANSPOSE
);
247 MATRIX(gl_TextureMatrixInverse
,
248 STATE_TEXTURE_MATRIX
, STATE_MATRIX_INVTRANS
);
249 MATRIX(gl_TextureMatrixTranspose
,
250 STATE_TEXTURE_MATRIX
, 0);
251 MATRIX(gl_TextureMatrixInverseTranspose
,
252 STATE_TEXTURE_MATRIX
, STATE_MATRIX_INVERSE
);
254 static struct gl_builtin_uniform_element gl_NormalMatrix_elements
[] = {
255 { NULL
, { STATE_MODELVIEW_MATRIX
, 0, 0, 0, STATE_MATRIX_INVERSE
},
257 { NULL
, { STATE_MODELVIEW_MATRIX
, 0, 1, 1, STATE_MATRIX_INVERSE
},
259 { NULL
, { STATE_MODELVIEW_MATRIX
, 0, 2, 2, STATE_MATRIX_INVERSE
},
265 #define STATEVAR(name) {#name, name ## _elements, Elements(name ## _elements)}
267 const struct gl_builtin_uniform_desc _mesa_builtin_uniform_desc
[] = {
268 STATEVAR(gl_DepthRange
),
269 STATEVAR(gl_ClipPlane
),
271 STATEVAR(gl_FrontMaterial
),
272 STATEVAR(gl_BackMaterial
),
273 STATEVAR(gl_LightSource
),
274 STATEVAR(gl_LightModel
),
275 STATEVAR(gl_FrontLightModelProduct
),
276 STATEVAR(gl_BackLightModelProduct
),
277 STATEVAR(gl_FrontLightProduct
),
278 STATEVAR(gl_BackLightProduct
),
279 STATEVAR(gl_TextureEnvColor
),
280 STATEVAR(gl_EyePlaneS
),
281 STATEVAR(gl_EyePlaneT
),
282 STATEVAR(gl_EyePlaneR
),
283 STATEVAR(gl_EyePlaneQ
),
284 STATEVAR(gl_ObjectPlaneS
),
285 STATEVAR(gl_ObjectPlaneT
),
286 STATEVAR(gl_ObjectPlaneR
),
287 STATEVAR(gl_ObjectPlaneQ
),
290 STATEVAR(gl_ModelViewMatrix
),
291 STATEVAR(gl_ModelViewMatrixInverse
),
292 STATEVAR(gl_ModelViewMatrixTranspose
),
293 STATEVAR(gl_ModelViewMatrixInverseTranspose
),
295 STATEVAR(gl_ProjectionMatrix
),
296 STATEVAR(gl_ProjectionMatrixInverse
),
297 STATEVAR(gl_ProjectionMatrixTranspose
),
298 STATEVAR(gl_ProjectionMatrixInverseTranspose
),
300 STATEVAR(gl_ModelViewProjectionMatrix
),
301 STATEVAR(gl_ModelViewProjectionMatrixInverse
),
302 STATEVAR(gl_ModelViewProjectionMatrixTranspose
),
303 STATEVAR(gl_ModelViewProjectionMatrixInverseTranspose
),
305 STATEVAR(gl_TextureMatrix
),
306 STATEVAR(gl_TextureMatrixInverse
),
307 STATEVAR(gl_TextureMatrixTranspose
),
308 STATEVAR(gl_TextureMatrixInverseTranspose
),
310 STATEVAR(gl_NormalMatrix
),
311 STATEVAR(gl_NormalScale
),
317 is_boolean_type(GLenum type
)
332 is_sampler_type(GLenum type
)
338 case GL_SAMPLER_CUBE
:
339 case GL_SAMPLER_1D_SHADOW
:
340 case GL_SAMPLER_2D_SHADOW
:
341 case GL_SAMPLER_2D_RECT_ARB
:
342 case GL_SAMPLER_2D_RECT_SHADOW_ARB
:
343 case GL_SAMPLER_1D_ARRAY_EXT
:
344 case GL_SAMPLER_2D_ARRAY_EXT
:
345 case GL_SAMPLER_1D_ARRAY_SHADOW_EXT
:
346 case GL_SAMPLER_2D_ARRAY_SHADOW_EXT
:
354 static struct gl_program_parameter
*
355 get_uniform_parameter(const struct gl_shader_program
*shProg
, GLuint index
)
357 const struct gl_program
*prog
= NULL
;
360 progPos
= shProg
->Uniforms
->Uniforms
[index
].VertPos
;
362 prog
= &shProg
->VertexProgram
->Base
;
365 progPos
= shProg
->Uniforms
->Uniforms
[index
].FragPos
;
367 prog
= &shProg
->FragmentProgram
->Base
;
369 progPos
= shProg
->Uniforms
->Uniforms
[index
].GeomPos
;
371 prog
= &shProg
->GeometryProgram
->Base
;
376 if (!prog
|| progPos
< 0)
377 return NULL
; /* should never happen */
379 return &prog
->Parameters
->Parameters
[progPos
];
384 * Called by glGetActiveUniform().
387 _mesa_get_active_uniform(struct gl_context
*ctx
, GLuint program
, GLuint index
,
388 GLsizei maxLength
, GLsizei
*length
, GLint
*size
,
389 GLenum
*type
, GLchar
*nameOut
)
391 const struct gl_shader_program
*shProg
;
392 const struct gl_program
*prog
= NULL
;
393 const struct gl_program_parameter
*param
;
396 shProg
= _mesa_lookup_shader_program_err(ctx
, program
, "glGetActiveUniform");
400 if (!shProg
->Uniforms
|| index
>= shProg
->Uniforms
->NumUniforms
) {
401 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetActiveUniform(index)");
405 progPos
= shProg
->Uniforms
->Uniforms
[index
].VertPos
;
407 prog
= &shProg
->VertexProgram
->Base
;
410 progPos
= shProg
->Uniforms
->Uniforms
[index
].FragPos
;
412 prog
= &shProg
->FragmentProgram
->Base
;
414 progPos
= shProg
->Uniforms
->Uniforms
[index
].GeomPos
;
416 prog
= &shProg
->GeometryProgram
->Base
;
421 if (!prog
|| progPos
< 0)
422 return; /* should never happen */
424 ASSERT(progPos
< prog
->Parameters
->NumParameters
);
425 param
= &prog
->Parameters
->Parameters
[progPos
];
428 _mesa_copy_string(nameOut
, maxLength
, length
, param
->Name
);
432 GLint typeSize
= _mesa_sizeof_glsl_type(param
->DataType
);
433 if ((GLint
) param
->Size
> typeSize
) {
435 * Array elements are placed on vector[4] boundaries so they're
436 * a multiple of four floats. We round typeSize up to next multiple
437 * of four to get the right size below.
439 typeSize
= (typeSize
+ 3) & ~3;
441 /* Note that the returned size is in units of the <type>, not bytes */
442 *size
= param
->Size
/ typeSize
;
446 *type
= param
->DataType
;
453 get_matrix_dims(GLenum type
, GLint
*rows
, GLint
*cols
)
459 case GL_FLOAT_MAT2x3
:
463 case GL_FLOAT_MAT2x4
:
471 case GL_FLOAT_MAT3x2
:
475 case GL_FLOAT_MAT3x4
:
483 case GL_FLOAT_MAT4x2
:
487 case GL_FLOAT_MAT4x3
:
498 * Determine the number of rows and columns occupied by a uniform
499 * according to its datatype. For non-matrix types (such as GL_FLOAT_VEC4),
500 * the number of rows = 1 and cols = number of elements in the vector.
503 get_uniform_rows_cols(const struct gl_program_parameter
*p
,
504 GLint
*rows
, GLint
*cols
)
506 get_matrix_dims(p
->DataType
, rows
, cols
);
507 if (*rows
== 0 && *cols
== 0) {
508 /* not a matrix type, probably a float or vector */
514 *rows
= p
->Size
/ 4 + 1;
515 if (p
->Size
% 4 == 0)
525 * Helper for get_uniform[fi]v() functions.
526 * Given a shader program name and uniform location, return a pointer
527 * to the shader program and return the program parameter position.
530 lookup_uniform_parameter(struct gl_context
*ctx
, GLuint program
, GLint location
,
531 struct gl_program
**progOut
, GLint
*paramPosOut
)
533 struct gl_shader_program
*shProg
534 = _mesa_lookup_shader_program_err(ctx
, program
, "glGetUniform[if]v");
535 struct gl_program
*prog
= NULL
;
538 /* if shProg is NULL, we'll have already recorded an error */
541 if (!shProg
->Uniforms
||
543 location
>= (GLint
) shProg
->Uniforms
->NumUniforms
) {
544 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetUniformfv(location)");
547 /* OK, find the gl_program and program parameter location */
548 progPos
= shProg
->Uniforms
->Uniforms
[location
].VertPos
;
550 prog
= &shProg
->VertexProgram
->Base
;
553 progPos
= shProg
->Uniforms
->Uniforms
[location
].FragPos
;
555 prog
= &shProg
->FragmentProgram
->Base
;
557 progPos
= shProg
->Uniforms
->Uniforms
[location
].GeomPos
;
559 prog
= &shProg
->GeometryProgram
->Base
;
567 *paramPosOut
= progPos
;
572 * GLGL uniform arrays and structs require special handling.
574 * The GL_ARB_shader_objects spec says that if you use
575 * glGetUniformLocation to get the location of an array, you CANNOT
576 * access other elements of the array by adding an offset to the
577 * returned location. For example, you must call
578 * glGetUniformLocation("foo[16]") if you want to set the 16th element
579 * of the array with glUniform().
581 * HOWEVER, some other OpenGL drivers allow accessing array elements
582 * by adding an offset to the returned array location. And some apps
583 * seem to depend on that behaviour.
585 * Mesa's gl_uniform_list doesn't directly support this since each
586 * entry in the list describes one uniform variable, not one uniform
587 * element. We could insert dummy entries in the list for each array
588 * element after [0] but that causes complications elsewhere.
590 * We solve this problem by encoding two values in the location that's
591 * returned by glGetUniformLocation():
592 * a) index into gl_uniform_list::Uniforms[] for the uniform
593 * b) an array/field offset (0 for simple types)
595 * These two values are encoded in the high and low halves of a GLint.
596 * By putting the uniform number in the high part and the offset in the
597 * low part, we can support the unofficial ability to index into arrays
598 * by adding offsets to the location value.
601 merge_location_offset(GLint
*location
, GLint offset
)
603 *location
= (*location
<< 16) | offset
;
608 * Separate the uniform location and parameter offset. See above.
611 split_location_offset(GLint
*location
, GLint
*offset
)
613 *offset
= *location
& 0xffff;
614 *location
= *location
>> 16;
620 * Called via glGetUniformfv().
623 _mesa_get_uniformfv(struct gl_context
*ctx
, GLuint program
, GLint location
,
626 struct gl_program
*prog
;
630 split_location_offset(&location
, &offset
);
632 lookup_uniform_parameter(ctx
, program
, location
, &prog
, ¶mPos
);
635 const struct gl_program_parameter
*p
=
636 &prog
->Parameters
->Parameters
[paramPos
];
637 GLint rows
, cols
, i
, j
, k
;
639 get_uniform_rows_cols(p
, &rows
, &cols
);
642 for (i
= 0; i
< rows
; i
++) {
643 for (j
= 0; j
< cols
; j
++ ) {
644 params
[k
++] = prog
->Parameters
->ParameterValues
[paramPos
+i
][j
];
652 * Called via glGetUniformiv().
653 * \sa _mesa_get_uniformfv, only difference is a cast.
656 _mesa_get_uniformiv(struct gl_context
*ctx
, GLuint program
, GLint location
,
659 struct gl_program
*prog
;
663 split_location_offset(&location
, &offset
);
665 lookup_uniform_parameter(ctx
, program
, location
, &prog
, ¶mPos
);
668 const struct gl_program_parameter
*p
=
669 &prog
->Parameters
->Parameters
[paramPos
];
670 GLint rows
, cols
, i
, j
, k
;
672 get_uniform_rows_cols(p
, &rows
, &cols
);
675 for (i
= 0; i
< rows
; i
++) {
676 for (j
= 0; j
< cols
; j
++ ) {
677 params
[k
++] = (GLint
) prog
->Parameters
->ParameterValues
[paramPos
+i
][j
];
685 * Called via glGetUniformLocation().
687 * The return value will encode two values, the uniform location and an
688 * offset (used for arrays, structs).
691 _mesa_get_uniform_location(struct gl_context
*ctx
, struct gl_shader_program
*shProg
,
694 GLint offset
= 0, location
= -1;
696 if (shProg
->LinkStatus
== GL_FALSE
) {
697 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetUniformfv(program)");
701 /* XXX we should return -1 if the uniform was declared, but not
705 /* XXX we need to be able to parse uniform names for structs and arrays
712 /* handle 1-dimension arrays here... */
713 char *c
= strchr(name
, '[');
715 /* truncate name at [ */
716 const GLint len
= c
- name
;
717 GLchar
*newName
= malloc(len
+ 1);
719 return -1; /* out of mem */
720 memcpy(newName
, name
, len
);
723 location
= _mesa_lookup_uniform(shProg
->Uniforms
, newName
);
725 const GLint element
= atoi(c
+ 1);
727 /* get type of the uniform array element */
728 struct gl_program_parameter
*p
;
729 p
= get_uniform_parameter(shProg
, location
);
732 get_matrix_dims(p
->DataType
, &rows
, &cols
);
735 offset
= element
* rows
;
745 location
= _mesa_lookup_uniform(shProg
->Uniforms
, name
);
749 merge_location_offset(&location
, offset
);
758 * Update the vertex/fragment program's TexturesUsed array.
760 * This needs to be called after glUniform(set sampler var) is called.
761 * A call to glUniform(samplerVar, value) causes a sampler to point to a
762 * particular texture unit. We know the sampler's texture target
763 * (1D/2D/3D/etc) from compile time but the sampler's texture unit is
764 * set by glUniform() calls.
766 * So, scan the program->SamplerUnits[] and program->SamplerTargets[]
767 * information to update the prog->TexturesUsed[] values.
768 * Each value of TexturesUsed[unit] is one of zero, TEXTURE_1D_INDEX,
769 * TEXTURE_2D_INDEX, TEXTURE_3D_INDEX, etc.
770 * We'll use that info for state validation before rendering.
773 _mesa_update_shader_textures_used(struct gl_program
*prog
)
777 memset(prog
->TexturesUsed
, 0, sizeof(prog
->TexturesUsed
));
779 for (s
= 0; s
< MAX_SAMPLERS
; s
++) {
780 if (prog
->SamplersUsed
& (1 << s
)) {
781 GLuint unit
= prog
->SamplerUnits
[s
];
782 GLuint tgt
= prog
->SamplerTargets
[s
];
783 assert(unit
< MAX_TEXTURE_IMAGE_UNITS
);
784 assert(tgt
< NUM_TEXTURE_TARGETS
);
785 prog
->TexturesUsed
[unit
] |= (1 << tgt
);
792 * Check if the type given by userType is allowed to set a uniform of the
793 * target type. Generally, equivalence is required, but setting Boolean
794 * uniforms can be done with glUniformiv or glUniformfv.
797 compatible_types(GLenum userType
, GLenum targetType
)
799 if (userType
== targetType
)
802 if (targetType
== GL_BOOL
&& (userType
== GL_FLOAT
||
803 userType
== GL_UNSIGNED_INT
||
807 if (targetType
== GL_BOOL_VEC2
&& (userType
== GL_FLOAT_VEC2
||
808 userType
== GL_UNSIGNED_INT_VEC2
||
809 userType
== GL_INT_VEC2
))
812 if (targetType
== GL_BOOL_VEC3
&& (userType
== GL_FLOAT_VEC3
||
813 userType
== GL_UNSIGNED_INT_VEC3
||
814 userType
== GL_INT_VEC3
))
817 if (targetType
== GL_BOOL_VEC4
&& (userType
== GL_FLOAT_VEC4
||
818 userType
== GL_UNSIGNED_INT_VEC4
||
819 userType
== GL_INT_VEC4
))
822 if (is_sampler_type(targetType
) && userType
== GL_INT
)
830 * Set the value of a program's uniform variable.
831 * \param program the program whose uniform to update
832 * \param index the index of the program parameter for the uniform
833 * \param offset additional parameter slot offset (for arrays)
834 * \param type the incoming datatype of 'values'
835 * \param count the number of uniforms to set
836 * \param elems number of elements per uniform (1, 2, 3 or 4)
837 * \param values the new values, of datatype 'type'
840 set_program_uniform(struct gl_context
*ctx
, struct gl_program
*program
,
841 GLint index
, GLint offset
,
842 GLenum type
, GLsizei count
, GLint elems
,
845 const struct gl_program_parameter
*param
=
846 &program
->Parameters
->Parameters
[index
];
852 if (!compatible_types(type
, param
->DataType
)) {
853 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glUniform(type mismatch)");
857 if (index
+ offset
> (GLint
) program
->Parameters
->Size
) {
862 if (param
->Type
== PROGRAM_SAMPLER
) {
863 /* This controls which texture unit which is used by a sampler */
864 GLboolean changed
= GL_FALSE
;
867 /* this should have been caught by the compatible_types() check */
868 ASSERT(type
== GL_INT
);
870 /* loop over number of samplers to change */
871 for (i
= 0; i
< count
; i
++) {
873 (GLuint
) program
->Parameters
->ParameterValues
[index
+ offset
+ i
][0];
874 GLuint texUnit
= ((GLuint
*) values
)[i
];
876 /* check that the sampler (tex unit index) is legal */
877 if (texUnit
>= ctx
->Const
.MaxTextureImageUnits
) {
878 _mesa_error(ctx
, GL_INVALID_VALUE
,
879 "glUniform1(invalid sampler/tex unit index for '%s')",
884 /* This maps a sampler to a texture unit: */
885 if (sampler
< MAX_SAMPLERS
) {
887 printf("Set program %p sampler %d '%s' to unit %u\n",
888 program
, sampler
, param
->Name
, texUnit
);
890 if (program
->SamplerUnits
[sampler
] != texUnit
) {
891 program
->SamplerUnits
[sampler
] = texUnit
;
898 /* When a sampler's value changes it usually requires rewriting
899 * a GPU program's TEX instructions since there may not be a
900 * sampler->texture lookup table. We signal this with the
901 * ProgramStringNotify() callback.
903 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
| _NEW_PROGRAM
);
904 _mesa_update_shader_textures_used(program
);
905 /* Do we need to care about the return value here?
906 * This should not be the first time the driver was notified of
909 (void) ctx
->Driver
.ProgramStringNotify(ctx
, program
->Target
, program
);
913 /* ordinary uniform variable */
914 const GLboolean isUniformBool
= is_boolean_type(param
->DataType
);
915 const GLenum basicType
= base_uniform_type(type
);
916 const GLint slots
= (param
->Size
+ 3) / 4;
917 const GLint typeSize
= _mesa_sizeof_glsl_type(param
->DataType
);
920 if ((GLint
) param
->Size
> typeSize
) {
922 /* we'll ignore extra data below */
925 /* non-array: count must be at most one; count == 0 is handled by the loop below */
927 _mesa_error(ctx
, GL_INVALID_OPERATION
,
928 "glUniform(uniform '%s' is not an array)",
934 /* loop over number of array elements */
935 for (k
= 0; k
< count
; k
++) {
938 if (offset
+ k
>= slots
) {
939 /* Extra array data is ignored */
943 /* uniformVal (the destination) is always float[4] */
944 uniformVal
= program
->Parameters
->ParameterValues
[index
+ offset
+ k
];
946 if (basicType
== GL_INT
) {
947 /* convert user's ints to floats */
948 const GLint
*iValues
= ((const GLint
*) values
) + k
* elems
;
949 for (i
= 0; i
< elems
; i
++) {
950 uniformVal
[i
] = (GLfloat
) iValues
[i
];
953 else if (basicType
== GL_UNSIGNED_INT
) {
954 /* convert user's uints to floats */
955 const GLuint
*iValues
= ((const GLuint
*) values
) + k
* elems
;
956 for (i
= 0; i
< elems
; i
++) {
957 uniformVal
[i
] = (GLfloat
) iValues
[i
];
961 const GLfloat
*fValues
= ((const GLfloat
*) values
) + k
* elems
;
962 assert(basicType
== GL_FLOAT
);
963 for (i
= 0; i
< elems
; i
++) {
964 uniformVal
[i
] = fValues
[i
];
968 /* if the uniform is bool-valued, convert to 1.0 or 0.0 */
970 for (i
= 0; i
< elems
; i
++) {
971 uniformVal
[i
] = uniformVal
[i
] ? 1.0f
: 0.0f
;
980 * Called via glUniform*() functions.
983 _mesa_uniform(struct gl_context
*ctx
, struct gl_shader_program
*shProg
,
984 GLint location
, GLsizei count
,
985 const GLvoid
*values
, GLenum type
)
987 struct gl_uniform
*uniform
;
990 if (!shProg
|| !shProg
->LinkStatus
) {
991 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glUniform(program not linked)");
996 return; /* The standard specifies this as a no-op */
999 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glUniform(location=%d)",
1004 split_location_offset(&location
, &offset
);
1006 if (location
< 0 || location
>= (GLint
) shProg
->Uniforms
->NumUniforms
) {
1007 _mesa_error(ctx
, GL_INVALID_VALUE
, "glUniform(location=%d)", location
);
1012 _mesa_error(ctx
, GL_INVALID_VALUE
, "glUniform(count < 0)");
1016 elems
= _mesa_sizeof_glsl_type(type
);
1018 FLUSH_VERTICES(ctx
, _NEW_PROGRAM_CONSTANTS
);
1020 uniform
= &shProg
->Uniforms
->Uniforms
[location
];
1022 if (ctx
->Shader
.Flags
& GLSL_UNIFORMS
) {
1023 const GLenum basicType
= base_uniform_type(type
);
1025 printf("Mesa: set program %u uniform %s (loc %d) to: ",
1026 shProg
->Name
, uniform
->Name
, location
);
1027 if (basicType
== GL_INT
) {
1028 const GLint
*v
= (const GLint
*) values
;
1029 for (i
= 0; i
< count
* elems
; i
++) {
1030 printf("%d ", v
[i
]);
1033 else if (basicType
== GL_UNSIGNED_INT
) {
1034 const GLuint
*v
= (const GLuint
*) values
;
1035 for (i
= 0; i
< count
* elems
; i
++) {
1036 printf("%u ", v
[i
]);
1040 const GLfloat
*v
= (const GLfloat
*) values
;
1041 assert(basicType
== GL_FLOAT
);
1042 for (i
= 0; i
< count
* elems
; i
++) {
1043 printf("%g ", v
[i
]);
1049 /* A uniform var may be used by both a vertex shader and a fragment
1050 * shader. We may need to update one or both shader's uniform here:
1052 if (shProg
->VertexProgram
) {
1053 /* convert uniform location to program parameter index */
1054 GLint index
= uniform
->VertPos
;
1056 set_program_uniform(ctx
, &shProg
->VertexProgram
->Base
,
1057 index
, offset
, type
, count
, elems
, values
);
1061 if (shProg
->FragmentProgram
) {
1062 /* convert uniform location to program parameter index */
1063 GLint index
= uniform
->FragPos
;
1065 set_program_uniform(ctx
, &shProg
->FragmentProgram
->Base
,
1066 index
, offset
, type
, count
, elems
, values
);
1070 if (shProg
->GeometryProgram
) {
1071 /* convert uniform location to program parameter index */
1072 GLint index
= uniform
->GeomPos
;
1074 set_program_uniform(ctx
, &shProg
->GeometryProgram
->Base
,
1075 index
, offset
, type
, count
, elems
, values
);
1079 uniform
->Initialized
= GL_TRUE
;
1084 * Set a matrix-valued program parameter.
1087 set_program_uniform_matrix(struct gl_context
*ctx
, struct gl_program
*program
,
1088 GLuint index
, GLuint offset
,
1089 GLuint count
, GLuint rows
, GLuint cols
,
1090 GLboolean transpose
, const GLfloat
*values
)
1092 GLuint mat
, row
, col
;
1094 const struct gl_program_parameter
* param
= &program
->Parameters
->Parameters
[index
];
1095 const GLuint slots
= (param
->Size
+ 3) / 4;
1096 const GLint typeSize
= _mesa_sizeof_glsl_type(param
->DataType
);
1099 /* check that the number of rows, columns is correct */
1100 get_matrix_dims(param
->DataType
, &nr
, &nc
);
1101 if (rows
!= nr
|| cols
!= nc
) {
1102 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1103 "glUniformMatrix(matrix size mismatch)");
1107 if ((GLint
) param
->Size
<= typeSize
) {
1108 /* non-array: count must be at most one; count == 0 is handled by the loop below */
1110 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1111 "glUniformMatrix(uniform is not an array)");
1117 * Note: the _columns_ of a matrix are stored in program registers, not
1118 * the rows. So, the loops below look a little funny.
1119 * XXX could optimize this a bit...
1122 /* loop over matrices */
1123 for (mat
= 0; mat
< count
; mat
++) {
1126 for (col
= 0; col
< cols
; col
++) {
1128 if (offset
>= slots
) {
1129 /* Ignore writes beyond the end of (the used part of) an array */
1132 v
= program
->Parameters
->ParameterValues
[index
+ offset
];
1133 for (row
= 0; row
< rows
; row
++) {
1135 v
[row
] = values
[src
+ row
* cols
+ col
];
1138 v
[row
] = values
[src
+ col
* rows
+ row
];
1145 src
+= rows
* cols
; /* next matrix */
1151 * Called by glUniformMatrix*() functions.
1152 * Note: cols=2, rows=4 ==> array[2] of vec4
1155 _mesa_uniform_matrix(struct gl_context
*ctx
, struct gl_shader_program
*shProg
,
1156 GLint cols
, GLint rows
,
1157 GLint location
, GLsizei count
,
1158 GLboolean transpose
, const GLfloat
*values
)
1160 struct gl_uniform
*uniform
;
1163 if (!shProg
|| !shProg
->LinkStatus
) {
1164 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1165 "glUniformMatrix(program not linked)");
1170 return; /* The standard specifies this as a no-op */
1172 if (location
< -1) {
1173 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glUniformMatrix(location)");
1177 split_location_offset(&location
, &offset
);
1179 if (location
< 0 || location
>= (GLint
) shProg
->Uniforms
->NumUniforms
) {
1180 _mesa_error(ctx
, GL_INVALID_VALUE
, "glUniformMatrix(location)");
1183 if (values
== NULL
) {
1184 _mesa_error(ctx
, GL_INVALID_VALUE
, "glUniformMatrix");
1188 FLUSH_VERTICES(ctx
, _NEW_PROGRAM_CONSTANTS
);
1190 uniform
= &shProg
->Uniforms
->Uniforms
[location
];
1192 if (shProg
->VertexProgram
) {
1193 /* convert uniform location to program parameter index */
1194 GLint index
= uniform
->VertPos
;
1196 set_program_uniform_matrix(ctx
, &shProg
->VertexProgram
->Base
,
1198 count
, rows
, cols
, transpose
, values
);
1202 if (shProg
->FragmentProgram
) {
1203 /* convert uniform location to program parameter index */
1204 GLint index
= uniform
->FragPos
;
1206 set_program_uniform_matrix(ctx
, &shProg
->FragmentProgram
->Base
,
1208 count
, rows
, cols
, transpose
, values
);
1212 if (shProg
->GeometryProgram
) {
1213 /* convert uniform location to program parameter index */
1214 GLint index
= uniform
->GeomPos
;
1216 set_program_uniform_matrix(ctx
, &shProg
->GeometryProgram
->Base
,
1218 count
, rows
, cols
, transpose
, values
);
1222 uniform
->Initialized
= GL_TRUE
;
1227 _mesa_Uniform1fARB(GLint location
, GLfloat v0
)
1229 GET_CURRENT_CONTEXT(ctx
);
1230 _mesa_uniform(ctx
, ctx
->Shader
.ActiveProgram
, location
, 1, &v0
, GL_FLOAT
);
1234 _mesa_Uniform2fARB(GLint location
, GLfloat v0
, GLfloat v1
)
1236 GET_CURRENT_CONTEXT(ctx
);
1240 _mesa_uniform(ctx
, ctx
->Shader
.ActiveProgram
, location
, 1, v
, GL_FLOAT_VEC2
);
1244 _mesa_Uniform3fARB(GLint location
, GLfloat v0
, GLfloat v1
, GLfloat v2
)
1246 GET_CURRENT_CONTEXT(ctx
);
1251 _mesa_uniform(ctx
, ctx
->Shader
.ActiveProgram
, location
, 1, v
, GL_FLOAT_VEC3
);
1255 _mesa_Uniform4fARB(GLint location
, GLfloat v0
, GLfloat v1
, GLfloat v2
,
1258 GET_CURRENT_CONTEXT(ctx
);
1264 _mesa_uniform(ctx
, ctx
->Shader
.ActiveProgram
, location
, 1, v
, GL_FLOAT_VEC4
);
1268 _mesa_Uniform1iARB(GLint location
, GLint v0
)
1270 GET_CURRENT_CONTEXT(ctx
);
1271 _mesa_uniform(ctx
, ctx
->Shader
.ActiveProgram
, location
, 1, &v0
, GL_INT
);
1275 _mesa_Uniform2iARB(GLint location
, GLint v0
, GLint v1
)
1277 GET_CURRENT_CONTEXT(ctx
);
1281 _mesa_uniform(ctx
, ctx
->Shader
.ActiveProgram
, location
, 1, v
, GL_INT_VEC2
);
1285 _mesa_Uniform3iARB(GLint location
, GLint v0
, GLint v1
, GLint v2
)
1287 GET_CURRENT_CONTEXT(ctx
);
1292 _mesa_uniform(ctx
, ctx
->Shader
.ActiveProgram
, location
, 1, v
, GL_INT_VEC3
);
1296 _mesa_Uniform4iARB(GLint location
, GLint v0
, GLint v1
, GLint v2
, GLint v3
)
1298 GET_CURRENT_CONTEXT(ctx
);
1304 _mesa_uniform(ctx
, ctx
->Shader
.ActiveProgram
, location
, 1, v
, GL_INT_VEC4
);
1308 _mesa_Uniform1fvARB(GLint location
, GLsizei count
, const GLfloat
* value
)
1310 GET_CURRENT_CONTEXT(ctx
);
1311 _mesa_uniform(ctx
, ctx
->Shader
.ActiveProgram
, location
, count
, value
, GL_FLOAT
);
1315 _mesa_Uniform2fvARB(GLint location
, GLsizei count
, const GLfloat
* value
)
1317 GET_CURRENT_CONTEXT(ctx
);
1318 _mesa_uniform(ctx
, ctx
->Shader
.ActiveProgram
, location
, count
, value
, GL_FLOAT_VEC2
);
1322 _mesa_Uniform3fvARB(GLint location
, GLsizei count
, const GLfloat
* value
)
1324 GET_CURRENT_CONTEXT(ctx
);
1325 _mesa_uniform(ctx
, ctx
->Shader
.ActiveProgram
, location
, count
, value
, GL_FLOAT_VEC3
);
1329 _mesa_Uniform4fvARB(GLint location
, GLsizei count
, const GLfloat
* value
)
1331 GET_CURRENT_CONTEXT(ctx
);
1332 _mesa_uniform(ctx
, ctx
->Shader
.ActiveProgram
, location
, count
, value
, GL_FLOAT_VEC4
);
1336 _mesa_Uniform1ivARB(GLint location
, GLsizei count
, const GLint
* value
)
1338 GET_CURRENT_CONTEXT(ctx
);
1339 _mesa_uniform(ctx
, ctx
->Shader
.ActiveProgram
, location
, count
, value
, GL_INT
);
1343 _mesa_Uniform2ivARB(GLint location
, GLsizei count
, const GLint
* value
)
1345 GET_CURRENT_CONTEXT(ctx
);
1346 _mesa_uniform(ctx
, ctx
->Shader
.ActiveProgram
, location
, count
, value
, GL_INT_VEC2
);
1350 _mesa_Uniform3ivARB(GLint location
, GLsizei count
, const GLint
* value
)
1352 GET_CURRENT_CONTEXT(ctx
);
1353 _mesa_uniform(ctx
, ctx
->Shader
.ActiveProgram
, location
, count
, value
, GL_INT_VEC3
);
1357 _mesa_Uniform4ivARB(GLint location
, GLsizei count
, const GLint
* value
)
1359 GET_CURRENT_CONTEXT(ctx
);
1360 _mesa_uniform(ctx
, ctx
->Shader
.ActiveProgram
, location
, count
, value
, GL_INT_VEC4
);
1364 /** OpenGL 3.0 GLuint-valued functions **/
1366 _mesa_Uniform1ui(GLint location
, GLuint v0
)
1368 GET_CURRENT_CONTEXT(ctx
);
1369 _mesa_uniform(ctx
, ctx
->Shader
.ActiveProgram
, location
, 1, &v0
, GL_UNSIGNED_INT
);
1373 _mesa_Uniform2ui(GLint location
, GLuint v0
, GLuint v1
)
1375 GET_CURRENT_CONTEXT(ctx
);
1379 _mesa_uniform(ctx
, ctx
->Shader
.ActiveProgram
, location
, 1, v
, GL_UNSIGNED_INT_VEC2
);
1383 _mesa_Uniform3ui(GLint location
, GLuint v0
, GLuint v1
, GLuint v2
)
1385 GET_CURRENT_CONTEXT(ctx
);
1390 _mesa_uniform(ctx
, ctx
->Shader
.ActiveProgram
, location
, 1, v
, GL_UNSIGNED_INT_VEC3
);
1394 _mesa_Uniform4ui(GLint location
, GLuint v0
, GLuint v1
, GLuint v2
, GLuint v3
)
1396 GET_CURRENT_CONTEXT(ctx
);
1402 _mesa_uniform(ctx
, ctx
->Shader
.ActiveProgram
, location
, 1, v
, GL_UNSIGNED_INT_VEC4
);
1406 _mesa_Uniform1uiv(GLint location
, GLsizei count
, const GLuint
*value
)
1408 GET_CURRENT_CONTEXT(ctx
);
1409 _mesa_uniform(ctx
, ctx
->Shader
.ActiveProgram
, location
, count
, value
, GL_UNSIGNED_INT
);
1413 _mesa_Uniform2uiv(GLint location
, GLsizei count
, const GLuint
*value
)
1415 GET_CURRENT_CONTEXT(ctx
);
1416 _mesa_uniform(ctx
, ctx
->Shader
.ActiveProgram
, location
, count
, value
, GL_UNSIGNED_INT_VEC2
);
1420 _mesa_Uniform3uiv(GLint location
, GLsizei count
, const GLuint
*value
)
1422 GET_CURRENT_CONTEXT(ctx
);
1423 _mesa_uniform(ctx
, ctx
->Shader
.ActiveProgram
, location
, count
, value
, GL_UNSIGNED_INT_VEC3
);
1427 _mesa_Uniform4uiv(GLint location
, GLsizei count
, const GLuint
*value
)
1429 GET_CURRENT_CONTEXT(ctx
);
1430 _mesa_uniform(ctx
, ctx
->Shader
.ActiveProgram
, location
, count
, value
, GL_UNSIGNED_INT_VEC4
);
1436 _mesa_UniformMatrix2fvARB(GLint location
, GLsizei count
, GLboolean transpose
,
1437 const GLfloat
* value
)
1439 GET_CURRENT_CONTEXT(ctx
);
1440 _mesa_uniform_matrix(ctx
, ctx
->Shader
.ActiveProgram
,
1441 2, 2, location
, count
, transpose
, value
);
1445 _mesa_UniformMatrix3fvARB(GLint location
, GLsizei count
, GLboolean transpose
,
1446 const GLfloat
* value
)
1448 GET_CURRENT_CONTEXT(ctx
);
1449 _mesa_uniform_matrix(ctx
, ctx
->Shader
.ActiveProgram
,
1450 3, 3, location
, count
, transpose
, value
);
1454 _mesa_UniformMatrix4fvARB(GLint location
, GLsizei count
, GLboolean transpose
,
1455 const GLfloat
* value
)
1457 GET_CURRENT_CONTEXT(ctx
);
1458 _mesa_uniform_matrix(ctx
, ctx
->Shader
.ActiveProgram
,
1459 4, 4, location
, count
, transpose
, value
);
1464 * Non-square UniformMatrix are OpenGL 2.1
1467 _mesa_UniformMatrix2x3fv(GLint location
, GLsizei count
, GLboolean transpose
,
1468 const GLfloat
*value
)
1470 GET_CURRENT_CONTEXT(ctx
);
1471 _mesa_uniform_matrix(ctx
, ctx
->Shader
.ActiveProgram
,
1472 2, 3, location
, count
, transpose
, value
);
1476 _mesa_UniformMatrix3x2fv(GLint location
, GLsizei count
, GLboolean transpose
,
1477 const GLfloat
*value
)
1479 GET_CURRENT_CONTEXT(ctx
);
1480 _mesa_uniform_matrix(ctx
, ctx
->Shader
.ActiveProgram
,
1481 3, 2, location
, count
, transpose
, value
);
1485 _mesa_UniformMatrix2x4fv(GLint location
, GLsizei count
, GLboolean transpose
,
1486 const GLfloat
*value
)
1488 GET_CURRENT_CONTEXT(ctx
);
1489 _mesa_uniform_matrix(ctx
, ctx
->Shader
.ActiveProgram
,
1490 2, 4, location
, count
, transpose
, value
);
1494 _mesa_UniformMatrix4x2fv(GLint location
, GLsizei count
, GLboolean transpose
,
1495 const GLfloat
*value
)
1497 GET_CURRENT_CONTEXT(ctx
);
1498 _mesa_uniform_matrix(ctx
, ctx
->Shader
.ActiveProgram
,
1499 4, 2, location
, count
, transpose
, value
);
1503 _mesa_UniformMatrix3x4fv(GLint location
, GLsizei count
, GLboolean transpose
,
1504 const GLfloat
*value
)
1506 GET_CURRENT_CONTEXT(ctx
);
1507 _mesa_uniform_matrix(ctx
, ctx
->Shader
.ActiveProgram
,
1508 3, 4, location
, count
, transpose
, value
);
1512 _mesa_UniformMatrix4x3fv(GLint location
, GLsizei count
, GLboolean transpose
,
1513 const GLfloat
*value
)
1515 GET_CURRENT_CONTEXT(ctx
);
1516 _mesa_uniform_matrix(ctx
, ctx
->Shader
.ActiveProgram
,
1517 4, 3, location
, count
, transpose
, value
);
1522 _mesa_GetUniformfvARB(GLhandleARB program
, GLint location
, GLfloat
*params
)
1524 GET_CURRENT_CONTEXT(ctx
);
1525 _mesa_get_uniformfv(ctx
, program
, location
, params
);
1530 _mesa_GetUniformivARB(GLhandleARB program
, GLint location
, GLint
*params
)
1532 GET_CURRENT_CONTEXT(ctx
);
1533 _mesa_get_uniformiv(ctx
, program
, location
, params
);
1538 _mesa_GetUniformLocationARB(GLhandleARB programObj
, const GLcharARB
*name
)
1540 struct gl_shader_program
*shProg
;
1542 GET_CURRENT_CONTEXT(ctx
);
1544 shProg
= _mesa_lookup_shader_program_err(ctx
, programObj
,
1545 "glGetUniformLocation");
1549 return _mesa_get_uniform_location(ctx
, shProg
, name
);
1554 _mesa_GetActiveUniformARB(GLhandleARB program
, GLuint index
,
1555 GLsizei maxLength
, GLsizei
* length
, GLint
* size
,
1556 GLenum
* type
, GLcharARB
* name
)
1558 GET_CURRENT_CONTEXT(ctx
);
1559 _mesa_get_active_uniform(ctx
, program
, index
, maxLength
, length
, size
,
1565 * Plug in shader uniform-related functions into API dispatch table.
1568 _mesa_init_shader_uniform_dispatch(struct _glapi_table
*exec
)
1571 SET_Uniform1fARB(exec
, _mesa_Uniform1fARB
);
1572 SET_Uniform2fARB(exec
, _mesa_Uniform2fARB
);
1573 SET_Uniform3fARB(exec
, _mesa_Uniform3fARB
);
1574 SET_Uniform4fARB(exec
, _mesa_Uniform4fARB
);
1575 SET_Uniform1iARB(exec
, _mesa_Uniform1iARB
);
1576 SET_Uniform2iARB(exec
, _mesa_Uniform2iARB
);
1577 SET_Uniform3iARB(exec
, _mesa_Uniform3iARB
);
1578 SET_Uniform4iARB(exec
, _mesa_Uniform4iARB
);
1579 SET_Uniform1fvARB(exec
, _mesa_Uniform1fvARB
);
1580 SET_Uniform2fvARB(exec
, _mesa_Uniform2fvARB
);
1581 SET_Uniform3fvARB(exec
, _mesa_Uniform3fvARB
);
1582 SET_Uniform4fvARB(exec
, _mesa_Uniform4fvARB
);
1583 SET_Uniform1ivARB(exec
, _mesa_Uniform1ivARB
);
1584 SET_Uniform2ivARB(exec
, _mesa_Uniform2ivARB
);
1585 SET_Uniform3ivARB(exec
, _mesa_Uniform3ivARB
);
1586 SET_Uniform4ivARB(exec
, _mesa_Uniform4ivARB
);
1587 SET_UniformMatrix2fvARB(exec
, _mesa_UniformMatrix2fvARB
);
1588 SET_UniformMatrix3fvARB(exec
, _mesa_UniformMatrix3fvARB
);
1589 SET_UniformMatrix4fvARB(exec
, _mesa_UniformMatrix4fvARB
);
1591 SET_GetActiveUniformARB(exec
, _mesa_GetActiveUniformARB
);
1592 SET_GetUniformLocationARB(exec
, _mesa_GetUniformLocationARB
);
1593 SET_GetUniformfvARB(exec
, _mesa_GetUniformfvARB
);
1594 SET_GetUniformivARB(exec
, _mesa_GetUniformivARB
);
1597 SET_UniformMatrix2x3fv(exec
, _mesa_UniformMatrix2x3fv
);
1598 SET_UniformMatrix3x2fv(exec
, _mesa_UniformMatrix3x2fv
);
1599 SET_UniformMatrix2x4fv(exec
, _mesa_UniformMatrix2x4fv
);
1600 SET_UniformMatrix4x2fv(exec
, _mesa_UniformMatrix4x2fv
);
1601 SET_UniformMatrix3x4fv(exec
, _mesa_UniformMatrix3x4fv
);
1602 SET_UniformMatrix4x3fv(exec
, _mesa_UniformMatrix4x3fv
);
1605 /* XXX finish dispatch */
1606 (void) _mesa_Uniform1ui
;
1607 (void) _mesa_Uniform2ui
;
1608 (void) _mesa_Uniform3ui
;
1609 (void) _mesa_Uniform4ui
;
1610 (void) _mesa_Uniform1uiv
;
1611 (void) _mesa_Uniform2uiv
;
1612 (void) _mesa_Uniform3uiv
;
1613 (void) _mesa_Uniform4uiv
;
1614 #endif /* FEATURE_GL */