st/mesa: silence int/float and double/float conversion warnings
[mesa.git] / src / mesa / main / uniforms.c
1 /*
2 * Mesa 3-D graphics library
3 *
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
7 *
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:
14 *
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
17 *
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.
24 */
25
26 /**
27 * \file uniforms.c
28 * Functions related to GLSL uniform variables.
29 * \author Brian Paul
30 */
31
32 /**
33 * XXX things to do:
34 * 1. Check that the right error code is generated for all _mesa_error() calls.
35 * 2. Insert FLUSH_VERTICES calls in various places
36 */
37
38
39 #include "main/glheader.h"
40 #include "main/context.h"
41 #include "main/dispatch.h"
42 #include "main/image.h"
43 #include "main/mfeatures.h"
44 #include "main/mtypes.h"
45 #include "main/shaderapi.h"
46 #include "main/shaderobj.h"
47 #include "main/uniforms.h"
48 #include "program/prog_parameter.h"
49 #include "program/prog_statevars.h"
50 #include "program/prog_uniform.h"
51 #include "program/prog_instruction.h"
52
53
54 static GLenum
55 base_uniform_type(GLenum type)
56 {
57 switch (type) {
58 #if 0 /* not needed, for now */
59 case GL_BOOL:
60 case GL_BOOL_VEC2:
61 case GL_BOOL_VEC3:
62 case GL_BOOL_VEC4:
63 return GL_BOOL;
64 #endif
65 case GL_FLOAT:
66 case GL_FLOAT_VEC2:
67 case GL_FLOAT_VEC3:
68 case GL_FLOAT_VEC4:
69 return GL_FLOAT;
70 case GL_UNSIGNED_INT:
71 case GL_UNSIGNED_INT_VEC2:
72 case GL_UNSIGNED_INT_VEC3:
73 case GL_UNSIGNED_INT_VEC4:
74 return GL_UNSIGNED_INT;
75 case GL_INT:
76 case GL_INT_VEC2:
77 case GL_INT_VEC3:
78 case GL_INT_VEC4:
79 return GL_INT;
80 default:
81 _mesa_problem(NULL, "Invalid type in base_uniform_type()");
82 return GL_FLOAT;
83 }
84 }
85
86
87 static GLboolean
88 is_boolean_type(GLenum type)
89 {
90 switch (type) {
91 case GL_BOOL:
92 case GL_BOOL_VEC2:
93 case GL_BOOL_VEC3:
94 case GL_BOOL_VEC4:
95 return GL_TRUE;
96 default:
97 return GL_FALSE;
98 }
99 }
100
101
102 static GLboolean
103 is_sampler_type(GLenum type)
104 {
105 switch (type) {
106 case GL_SAMPLER_1D:
107 case GL_SAMPLER_2D:
108 case GL_SAMPLER_3D:
109 case GL_SAMPLER_CUBE:
110 case GL_SAMPLER_1D_SHADOW:
111 case GL_SAMPLER_2D_SHADOW:
112 case GL_SAMPLER_CUBE_SHADOW:
113 case GL_SAMPLER_2D_RECT_ARB:
114 case GL_SAMPLER_2D_RECT_SHADOW_ARB:
115 case GL_SAMPLER_1D_ARRAY_EXT:
116 case GL_SAMPLER_2D_ARRAY_EXT:
117 case GL_SAMPLER_1D_ARRAY_SHADOW_EXT:
118 case GL_SAMPLER_2D_ARRAY_SHADOW_EXT:
119 case GL_SAMPLER_CUBE_MAP_ARRAY:
120 case GL_SAMPLER_CUBE_MAP_ARRAY_SHADOW:
121 case GL_SAMPLER_BUFFER:
122 return GL_TRUE;
123 default:
124 return GL_FALSE;
125 }
126 }
127
128
129 /**
130 * Given a uniform index, return the vertex/geometry/fragment program
131 * that has that parameter, plus the position of the parameter in the
132 * parameter/constant buffer.
133 * \param shProg the shader program
134 * \param index the uniform index in [0, NumUniforms-1]
135 * \param progOut returns containing program
136 * \param posOut returns position of the uniform in the param/const buffer
137 * \return GL_TRUE for success, GL_FALSE for invalid index
138 */
139 static GLboolean
140 find_uniform_parameter_pos(struct gl_shader_program *shProg, GLint index,
141 struct gl_program **progOut, GLint *posOut)
142 {
143 struct gl_program *prog = NULL;
144 GLint pos;
145
146 if (!shProg->Uniforms ||
147 index < 0 ||
148 index >= (GLint) shProg->Uniforms->NumUniforms) {
149 return GL_FALSE;
150 }
151
152 pos = shProg->Uniforms->Uniforms[index].VertPos;
153 if (pos >= 0) {
154 prog = &shProg->VertexProgram->Base;
155 }
156 else {
157 pos = shProg->Uniforms->Uniforms[index].FragPos;
158 if (pos >= 0) {
159 prog = &shProg->FragmentProgram->Base;
160 }
161 else {
162 pos = shProg->Uniforms->Uniforms[index].GeomPos;
163 if (pos >= 0) {
164 prog = &shProg->GeometryProgram->Base;
165 }
166 }
167 }
168
169 if (!prog || pos < 0)
170 return GL_FALSE; /* should really never happen */
171
172 *progOut = prog;
173 *posOut = pos;
174
175 return GL_TRUE;
176 }
177
178
179 /**
180 * Return pointer to a gl_program_parameter which corresponds to a uniform.
181 * \param shProg the shader program
182 * \param index the uniform index in [0, NumUniforms-1]
183 * \return gl_program_parameter point or NULL if index is invalid
184 */
185 static const struct gl_program_parameter *
186 get_uniform_parameter(struct gl_shader_program *shProg, GLint index)
187 {
188 struct gl_program *prog;
189 GLint progPos;
190
191 if (find_uniform_parameter_pos(shProg, index, &prog, &progPos))
192 return &prog->Parameters->Parameters[progPos];
193 else
194 return NULL;
195 }
196
197
198 /**
199 * Called by glGetActiveUniform().
200 */
201 static void
202 _mesa_get_active_uniform(struct gl_context *ctx, GLuint program, GLuint index,
203 GLsizei maxLength, GLsizei *length, GLint *size,
204 GLenum *type, GLchar *nameOut)
205 {
206 struct gl_shader_program *shProg =
207 _mesa_lookup_shader_program_err(ctx, program, "glGetActiveUniform");
208 const struct gl_program_parameter *param;
209
210 if (!shProg)
211 return;
212
213 if (!shProg->Uniforms || index >= shProg->Uniforms->NumUniforms) {
214 _mesa_error(ctx, GL_INVALID_VALUE, "glGetActiveUniform(index)");
215 return;
216 }
217
218 param = get_uniform_parameter(shProg, index);
219 if (!param)
220 return;
221
222 if (nameOut) {
223 _mesa_copy_string(nameOut, maxLength, length, param->Name);
224 }
225
226 if (size) {
227 GLint typeSize = _mesa_sizeof_glsl_type(param->DataType);
228 if ((GLint) param->Size > typeSize) {
229 /* This is an array.
230 * Array elements are placed on vector[4] boundaries so they're
231 * a multiple of four floats. We round typeSize up to next multiple
232 * of four to get the right size below.
233 */
234 typeSize = (typeSize + 3) & ~3;
235 }
236 /* Note that the returned size is in units of the <type>, not bytes */
237 *size = param->Size / typeSize;
238 }
239
240 if (type) {
241 *type = param->DataType;
242 }
243 }
244
245
246 static unsigned
247 get_vector_elements(GLenum type)
248 {
249 switch (type) {
250 case GL_FLOAT:
251 case GL_INT:
252 case GL_BOOL:
253 case GL_UNSIGNED_INT:
254 default: /* Catch all the various sampler types. */
255 return 1;
256
257 case GL_FLOAT_VEC2:
258 case GL_INT_VEC2:
259 case GL_BOOL_VEC2:
260 case GL_UNSIGNED_INT_VEC2:
261 return 2;
262
263 case GL_FLOAT_VEC3:
264 case GL_INT_VEC3:
265 case GL_BOOL_VEC3:
266 case GL_UNSIGNED_INT_VEC3:
267 return 3;
268
269 case GL_FLOAT_VEC4:
270 case GL_INT_VEC4:
271 case GL_BOOL_VEC4:
272 case GL_UNSIGNED_INT_VEC4:
273 return 4;
274 }
275 }
276
277 static void
278 get_matrix_dims(GLenum type, GLint *rows, GLint *cols)
279 {
280 switch (type) {
281 case GL_FLOAT_MAT2:
282 *rows = *cols = 2;
283 break;
284 case GL_FLOAT_MAT2x3:
285 *rows = 3;
286 *cols = 2;
287 break;
288 case GL_FLOAT_MAT2x4:
289 *rows = 4;
290 *cols = 2;
291 break;
292 case GL_FLOAT_MAT3:
293 *rows = 3;
294 *cols = 3;
295 break;
296 case GL_FLOAT_MAT3x2:
297 *rows = 2;
298 *cols = 3;
299 break;
300 case GL_FLOAT_MAT3x4:
301 *rows = 4;
302 *cols = 3;
303 break;
304 case GL_FLOAT_MAT4:
305 *rows = 4;
306 *cols = 4;
307 break;
308 case GL_FLOAT_MAT4x2:
309 *rows = 2;
310 *cols = 4;
311 break;
312 case GL_FLOAT_MAT4x3:
313 *rows = 3;
314 *cols = 4;
315 break;
316 default:
317 *rows = *cols = 0;
318 }
319 }
320
321
322 /**
323 * Determine the number of rows and columns occupied by a uniform
324 * according to its datatype. For non-matrix types (such as GL_FLOAT_VEC4),
325 * the number of rows = 1 and cols = number of elements in the vector.
326 */
327 static void
328 get_uniform_rows_cols(const struct gl_program_parameter *p,
329 GLint *rows, GLint *cols)
330 {
331 get_matrix_dims(p->DataType, rows, cols);
332 if (*rows == 0 && *cols == 0) {
333 /* not a matrix type, probably a float or vector */
334 *rows = 1;
335 *cols = get_vector_elements(p->DataType);
336 }
337 }
338
339
340 /**
341 * GLSL uniform arrays and structs require special handling.
342 *
343 * The GL_ARB_shader_objects spec says that if you use
344 * glGetUniformLocation to get the location of an array, you CANNOT
345 * access other elements of the array by adding an offset to the
346 * returned location. For example, you must call
347 * glGetUniformLocation("foo[16]") if you want to set the 16th element
348 * of the array with glUniform().
349 *
350 * HOWEVER, some other OpenGL drivers allow accessing array elements
351 * by adding an offset to the returned array location. And some apps
352 * seem to depend on that behaviour.
353 *
354 * Mesa's gl_uniform_list doesn't directly support this since each
355 * entry in the list describes one uniform variable, not one uniform
356 * element. We could insert dummy entries in the list for each array
357 * element after [0] but that causes complications elsewhere.
358 *
359 * We solve this problem by encoding two values in the location that's
360 * returned by glGetUniformLocation():
361 * a) index into gl_uniform_list::Uniforms[] for the uniform
362 * b) an array/field offset (0 for simple types)
363 *
364 * These two values are encoded in the high and low halves of a GLint.
365 * By putting the uniform number in the high part and the offset in the
366 * low part, we can support the unofficial ability to index into arrays
367 * by adding offsets to the location value.
368 */
369 static void
370 merge_location_offset(GLint *location, GLint offset)
371 {
372 *location = (*location << 16) | offset;
373 }
374
375
376 /**
377 * Separate the uniform location and parameter offset. See above.
378 */
379 static void
380 split_location_offset(GLint *location, GLint *offset)
381 {
382 *offset = *location & 0xffff;
383 *location = *location >> 16;
384 }
385
386
387
388 /**
389 * Called via glGetUniform[fiui]v() to get the current value of a uniform.
390 */
391 static void
392 get_uniform(struct gl_context *ctx, GLuint program, GLint location,
393 GLsizei bufSize, GLenum returnType, GLvoid *paramsOut)
394 {
395 struct gl_shader_program *shProg =
396 _mesa_lookup_shader_program_err(ctx, program, "glGetUniformfv");
397 struct gl_program *prog;
398 GLint paramPos, offset;
399
400 if (!shProg)
401 return;
402
403 split_location_offset(&location, &offset);
404
405 if (!find_uniform_parameter_pos(shProg, location, &prog, &paramPos)) {
406 _mesa_error(ctx, GL_INVALID_OPERATION, "glGetUniformfv(location)");
407 }
408 else {
409 const struct gl_program_parameter *p =
410 &prog->Parameters->Parameters[paramPos];
411 GLint rows, cols, i, j, k;
412 GLsizei numBytes;
413
414 get_uniform_rows_cols(p, &rows, &cols);
415
416 numBytes = rows * cols * _mesa_sizeof_type(returnType);
417 if (bufSize < numBytes) {
418 _mesa_error( ctx, GL_INVALID_OPERATION,
419 "glGetnUniformfvARB(out of bounds: bufSize is %d,"
420 " but %d bytes are required)", bufSize, numBytes );
421 return;
422 }
423
424 switch (returnType) {
425 case GL_FLOAT:
426 {
427 GLfloat *params = (GLfloat *) paramsOut;
428 k = 0;
429 for (i = 0; i < rows; i++) {
430 const int base = paramPos + offset + i;
431 for (j = 0; j < cols; j++ ) {
432 params[k++] = prog->Parameters->ParameterValues[base][j];
433 }
434 }
435 }
436 break;
437 case GL_DOUBLE:
438 {
439 GLfloat *params = (GLfloat *) paramsOut;
440 k = 0;
441 for (i = 0; i < rows; i++) {
442 const int base = paramPos + offset + i;
443 for (j = 0; j < cols; j++ ) {
444 params[k++] = (GLdouble)
445 prog->Parameters->ParameterValues[base][j];
446 }
447 }
448 }
449 break;
450 case GL_INT:
451 {
452 GLint *params = (GLint *) paramsOut;
453 k = 0;
454 for (i = 0; i < rows; i++) {
455 const int base = paramPos + offset + i;
456 for (j = 0; j < cols; j++ ) {
457 params[k++] = (GLint)
458 prog->Parameters->ParameterValues[base][j];
459 }
460 }
461 }
462 break;
463 case GL_UNSIGNED_INT:
464 {
465 GLuint *params = (GLuint *) paramsOut;
466 k = 0;
467 for (i = 0; i < rows; i++) {
468 const int base = paramPos + offset + i;
469 for (j = 0; j < cols; j++ ) {
470 params[k++] = (GLuint)
471 prog->Parameters->ParameterValues[base][j];
472 }
473 }
474 }
475 break;
476 default:
477 _mesa_problem(ctx, "bad returnType in get_uniform()");
478 }
479 }
480 }
481
482
483 /**
484 * Called via glGetUniformLocation().
485 *
486 * The return value will encode two values, the uniform location and an
487 * offset (used for arrays, structs).
488 */
489 GLint
490 _mesa_get_uniform_location(struct gl_context *ctx,
491 struct gl_shader_program *shProg,
492 const GLchar *name)
493 {
494 GLint offset = 0, location = -1;
495
496 if (shProg->LinkStatus == GL_FALSE) {
497 _mesa_error(ctx, GL_INVALID_OPERATION, "glGetUniformfv(program)");
498 return -1;
499 }
500
501 /* XXX we should return -1 if the uniform was declared, but not
502 * actually used.
503 */
504
505 /* XXX we need to be able to parse uniform names for structs and arrays
506 * such as:
507 * mymatrix[1]
508 * mystruct.field1
509 */
510
511 {
512 /* handle 1-dimension arrays here... */
513 char *c = strchr(name, '[');
514 if (c) {
515 /* truncate name at [ */
516 const GLint len = c - name;
517 GLchar *newName = malloc(len + 1);
518 if (!newName)
519 return -1; /* out of mem */
520 memcpy(newName, name, len);
521 newName[len] = 0;
522
523 location = _mesa_lookup_uniform(shProg->Uniforms, newName);
524 if (location >= 0) {
525 const GLint element = atoi(c + 1);
526 if (element > 0) {
527 /* get type of the uniform array element */
528 const struct gl_program_parameter *p =
529 get_uniform_parameter(shProg, location);
530 if (p) {
531 GLint rows, cols;
532 get_matrix_dims(p->DataType, &rows, &cols);
533 if (rows < 1)
534 rows = 1;
535 offset = element * rows;
536 }
537 }
538 }
539
540 free(newName);
541 }
542 }
543
544 if (location < 0) {
545 location = _mesa_lookup_uniform(shProg->Uniforms, name);
546 }
547
548 if (location >= 0) {
549 merge_location_offset(&location, offset);
550 }
551
552 return location;
553 }
554
555
556
557 /**
558 * Update the vertex/fragment program's TexturesUsed array.
559 *
560 * This needs to be called after glUniform(set sampler var) is called.
561 * A call to glUniform(samplerVar, value) causes a sampler to point to a
562 * particular texture unit. We know the sampler's texture target
563 * (1D/2D/3D/etc) from compile time but the sampler's texture unit is
564 * set by glUniform() calls.
565 *
566 * So, scan the program->SamplerUnits[] and program->SamplerTargets[]
567 * information to update the prog->TexturesUsed[] values.
568 * Each value of TexturesUsed[unit] is one of zero, TEXTURE_1D_INDEX,
569 * TEXTURE_2D_INDEX, TEXTURE_3D_INDEX, etc.
570 * We'll use that info for state validation before rendering.
571 */
572 void
573 _mesa_update_shader_textures_used(struct gl_program *prog)
574 {
575 GLuint s;
576
577 memset(prog->TexturesUsed, 0, sizeof(prog->TexturesUsed));
578
579 for (s = 0; s < MAX_SAMPLERS; s++) {
580 if (prog->SamplersUsed & (1 << s)) {
581 GLuint unit = prog->SamplerUnits[s];
582 GLuint tgt = prog->SamplerTargets[s];
583 assert(unit < Elements(prog->TexturesUsed));
584 assert(tgt < NUM_TEXTURE_TARGETS);
585 prog->TexturesUsed[unit] |= (1 << tgt);
586 }
587 }
588 }
589
590
591 /**
592 * Check if the type given by userType is allowed to set a uniform of the
593 * target type. Generally, equivalence is required, but setting Boolean
594 * uniforms can be done with glUniformiv or glUniformfv.
595 */
596 static GLboolean
597 compatible_types(GLenum userType, GLenum targetType)
598 {
599 if (userType == targetType)
600 return GL_TRUE;
601
602 if (targetType == GL_BOOL && (userType == GL_FLOAT ||
603 userType == GL_UNSIGNED_INT ||
604 userType == GL_INT))
605 return GL_TRUE;
606
607 if (targetType == GL_BOOL_VEC2 && (userType == GL_FLOAT_VEC2 ||
608 userType == GL_UNSIGNED_INT_VEC2 ||
609 userType == GL_INT_VEC2))
610 return GL_TRUE;
611
612 if (targetType == GL_BOOL_VEC3 && (userType == GL_FLOAT_VEC3 ||
613 userType == GL_UNSIGNED_INT_VEC3 ||
614 userType == GL_INT_VEC3))
615 return GL_TRUE;
616
617 if (targetType == GL_BOOL_VEC4 && (userType == GL_FLOAT_VEC4 ||
618 userType == GL_UNSIGNED_INT_VEC4 ||
619 userType == GL_INT_VEC4))
620 return GL_TRUE;
621
622 if (is_sampler_type(targetType) && userType == GL_INT)
623 return GL_TRUE;
624
625 return GL_FALSE;
626 }
627
628
629 /**
630 * Set the value of a program's uniform variable.
631 * \param program the program whose uniform to update
632 * \param index the index of the program parameter for the uniform
633 * \param offset additional parameter slot offset (for arrays)
634 * \param type the incoming datatype of 'values'
635 * \param count the number of uniforms to set
636 * \param elems number of elements per uniform (1, 2, 3 or 4)
637 * \param values the new values, of datatype 'type'
638 */
639 static void
640 set_program_uniform(struct gl_context *ctx, struct gl_program *program,
641 GLint index, GLint offset,
642 GLenum type, GLsizei count, GLint elems,
643 const void *values)
644 {
645 const struct gl_program_parameter *param =
646 &program->Parameters->Parameters[index];
647
648 assert(offset >= 0);
649 assert(elems >= 1);
650 assert(elems <= 4);
651
652 if (!compatible_types(type, param->DataType)) {
653 _mesa_error(ctx, GL_INVALID_OPERATION, "glUniform(type mismatch)");
654 return;
655 }
656
657 if (index + offset > (GLint) program->Parameters->Size) {
658 /* out of bounds! */
659 return;
660 }
661
662 if (param->Type == PROGRAM_SAMPLER) {
663 /* This controls which texture unit which is used by a sampler */
664 GLboolean changed = GL_FALSE;
665 GLint i;
666
667 /* this should have been caught by the compatible_types() check */
668 ASSERT(type == GL_INT);
669
670 /* loop over number of samplers to change */
671 for (i = 0; i < count; i++) {
672 GLuint sampler = (GLuint)
673 program->Parameters->ParameterValues[index + offset + i][0];
674 GLuint texUnit = ((GLuint *) values)[i];
675
676 /* check that the sampler (tex unit index) is legal */
677 if (texUnit >= ctx->Const.MaxCombinedTextureImageUnits) {
678 _mesa_error(ctx, GL_INVALID_VALUE,
679 "glUniform1(invalid sampler/tex unit index for '%s')",
680 param->Name);
681 return;
682 }
683
684 /* This maps a sampler to a texture unit: */
685 if (sampler < MAX_SAMPLERS) {
686 #if 0
687 printf("Set program %p sampler %d '%s' to unit %u\n",
688 program, sampler, param->Name, texUnit);
689 #endif
690 if (program->SamplerUnits[sampler] != texUnit) {
691 program->SamplerUnits[sampler] = texUnit;
692 changed = GL_TRUE;
693 }
694 }
695 }
696
697 if (changed) {
698 /* When a sampler's value changes it usually requires rewriting
699 * a GPU program's TEX instructions since there may not be a
700 * sampler->texture lookup table. We signal this with the
701 * ProgramStringNotify() callback.
702 */
703 FLUSH_VERTICES(ctx, _NEW_TEXTURE | _NEW_PROGRAM);
704 _mesa_update_shader_textures_used(program);
705 /* Do we need to care about the return value here?
706 * This should not be the first time the driver was notified of
707 * this program.
708 */
709 (void) ctx->Driver.ProgramStringNotify(ctx, program->Target, program);
710 }
711 }
712 else {
713 /* ordinary uniform variable */
714 const GLboolean isUniformBool = is_boolean_type(param->DataType);
715 const GLenum basicType = base_uniform_type(type);
716 const GLint slots = (param->Size + 3) / 4;
717 const GLint typeSize = _mesa_sizeof_glsl_type(param->DataType);
718 GLsizei k, i;
719
720 if ((GLint) param->Size > typeSize) {
721 /* an array */
722 /* we'll ignore extra data below */
723 }
724 else {
725 /* non-array: count must be at most one; count == 0 is handled
726 * by the loop below
727 */
728 if (count > 1) {
729 _mesa_error(ctx, GL_INVALID_OPERATION,
730 "glUniform(uniform '%s' is not an array)",
731 param->Name);
732 return;
733 }
734 }
735
736 /* loop over number of array elements */
737 for (k = 0; k < count; k++) {
738 GLfloat *uniformVal;
739
740 if (offset + k >= slots) {
741 /* Extra array data is ignored */
742 break;
743 }
744
745 /* uniformVal (the destination) is always float[4] */
746 uniformVal = program->Parameters->ParameterValues[index + offset + k];
747
748 if (basicType == GL_INT) {
749 /* convert user's ints to floats */
750 const GLint *iValues = ((const GLint *) values) + k * elems;
751 for (i = 0; i < elems; i++) {
752 uniformVal[i] = (GLfloat) iValues[i];
753 }
754 }
755 else if (basicType == GL_UNSIGNED_INT) {
756 /* convert user's uints to floats */
757 const GLuint *iValues = ((const GLuint *) values) + k * elems;
758 for (i = 0; i < elems; i++) {
759 uniformVal[i] = (GLfloat) iValues[i];
760 }
761 }
762 else {
763 const GLfloat *fValues = ((const GLfloat *) values) + k * elems;
764 assert(basicType == GL_FLOAT);
765 for (i = 0; i < elems; i++) {
766 uniformVal[i] = fValues[i];
767 }
768 }
769
770 /* if the uniform is bool-valued, convert to 1.0 or 0.0 */
771 if (isUniformBool) {
772 for (i = 0; i < elems; i++) {
773 uniformVal[i] = uniformVal[i] ? 1.0f : 0.0f;
774 }
775 }
776 }
777 }
778 }
779
780
781 /**
782 * Called via glUniform*() functions.
783 */
784 void
785 _mesa_uniform(struct gl_context *ctx, struct gl_shader_program *shProg,
786 GLint location, GLsizei count,
787 const GLvoid *values, GLenum type)
788 {
789 struct gl_uniform *uniform;
790 GLint elems, offset;
791
792 ASSERT_OUTSIDE_BEGIN_END(ctx);
793
794 if (!shProg || !shProg->LinkStatus) {
795 _mesa_error(ctx, GL_INVALID_OPERATION, "glUniform(program not linked)");
796 return;
797 }
798
799 if (location == -1)
800 return; /* The standard specifies this as a no-op */
801
802 if (location < -1) {
803 _mesa_error(ctx, GL_INVALID_OPERATION, "glUniform(location=%d)",
804 location);
805 return;
806 }
807
808 split_location_offset(&location, &offset);
809
810 if (location < 0 || location >= (GLint) shProg->Uniforms->NumUniforms) {
811 _mesa_error(ctx, GL_INVALID_VALUE, "glUniform(location=%d)", location);
812 return;
813 }
814
815 if (count < 0) {
816 _mesa_error(ctx, GL_INVALID_VALUE, "glUniform(count < 0)");
817 return;
818 }
819
820 elems = _mesa_sizeof_glsl_type(type);
821
822 FLUSH_VERTICES(ctx, _NEW_PROGRAM_CONSTANTS);
823
824 uniform = &shProg->Uniforms->Uniforms[location];
825
826 if (ctx->Shader.Flags & GLSL_UNIFORMS) {
827 const GLenum basicType = base_uniform_type(type);
828 GLint i;
829 printf("Mesa: set program %u uniform %s (loc %d) to: ",
830 shProg->Name, uniform->Name, location);
831 if (basicType == GL_INT) {
832 const GLint *v = (const GLint *) values;
833 for (i = 0; i < count * elems; i++) {
834 printf("%d ", v[i]);
835 }
836 }
837 else if (basicType == GL_UNSIGNED_INT) {
838 const GLuint *v = (const GLuint *) values;
839 for (i = 0; i < count * elems; i++) {
840 printf("%u ", v[i]);
841 }
842 }
843 else {
844 const GLfloat *v = (const GLfloat *) values;
845 assert(basicType == GL_FLOAT);
846 for (i = 0; i < count * elems; i++) {
847 printf("%g ", v[i]);
848 }
849 }
850 printf("\n");
851 }
852
853 /* A uniform var may be used by both a vertex shader and a fragment
854 * shader. We may need to update one or both shader's uniform here:
855 */
856 if (shProg->VertexProgram) {
857 /* convert uniform location to program parameter index */
858 GLint index = uniform->VertPos;
859 if (index >= 0) {
860 set_program_uniform(ctx, &shProg->VertexProgram->Base,
861 index, offset, type, count, elems, values);
862 }
863 }
864
865 if (shProg->FragmentProgram) {
866 /* convert uniform location to program parameter index */
867 GLint index = uniform->FragPos;
868 if (index >= 0) {
869 set_program_uniform(ctx, &shProg->FragmentProgram->Base,
870 index, offset, type, count, elems, values);
871 }
872 }
873
874 if (shProg->GeometryProgram) {
875 /* convert uniform location to program parameter index */
876 GLint index = uniform->GeomPos;
877 if (index >= 0) {
878 set_program_uniform(ctx, &shProg->GeometryProgram->Base,
879 index, offset, type, count, elems, values);
880 }
881 }
882
883 uniform->Initialized = GL_TRUE;
884 }
885
886
887 /**
888 * Set a matrix-valued program parameter.
889 */
890 static void
891 set_program_uniform_matrix(struct gl_context *ctx, struct gl_program *program,
892 GLuint index, GLuint offset,
893 GLuint count, GLuint rows, GLuint cols,
894 GLboolean transpose, const GLfloat *values)
895 {
896 GLuint mat, row, col;
897 GLuint src = 0;
898 const struct gl_program_parameter *param =
899 &program->Parameters->Parameters[index];
900 const GLuint slots = (param->Size + 3) / 4;
901 const GLint typeSize = _mesa_sizeof_glsl_type(param->DataType);
902 GLint nr, nc;
903
904 /* check that the number of rows, columns is correct */
905 get_matrix_dims(param->DataType, &nr, &nc);
906 if (rows != nr || cols != nc) {
907 _mesa_error(ctx, GL_INVALID_OPERATION,
908 "glUniformMatrix(matrix size mismatch)");
909 return;
910 }
911
912 if ((GLint) param->Size <= typeSize) {
913 /* non-array: count must be at most one; count == 0 is handled
914 * by the loop below
915 */
916 if (count > 1) {
917 _mesa_error(ctx, GL_INVALID_OPERATION,
918 "glUniformMatrix(uniform is not an array)");
919 return;
920 }
921 }
922
923 /*
924 * Note: the _columns_ of a matrix are stored in program registers, not
925 * the rows. So, the loops below look a little funny.
926 * XXX could optimize this a bit...
927 */
928
929 /* loop over matrices */
930 for (mat = 0; mat < count; mat++) {
931
932 /* each matrix: */
933 for (col = 0; col < cols; col++) {
934 GLfloat *v;
935 if (offset >= slots) {
936 /* Ignore writes beyond the end of (the used part of) an array */
937 return;
938 }
939 v = program->Parameters->ParameterValues[index + offset];
940 for (row = 0; row < rows; row++) {
941 if (transpose) {
942 v[row] = values[src + row * cols + col];
943 }
944 else {
945 v[row] = values[src + col * rows + row];
946 }
947 }
948
949 offset++;
950 }
951
952 src += rows * cols; /* next matrix */
953 }
954 }
955
956
957 /**
958 * Called by glUniformMatrix*() functions.
959 * Note: cols=2, rows=4 ==> array[2] of vec4
960 */
961 void
962 _mesa_uniform_matrix(struct gl_context *ctx, struct gl_shader_program *shProg,
963 GLint cols, GLint rows,
964 GLint location, GLsizei count,
965 GLboolean transpose, const GLfloat *values)
966 {
967 struct gl_uniform *uniform;
968 GLint offset;
969
970 ASSERT_OUTSIDE_BEGIN_END(ctx);
971
972 if (!shProg || !shProg->LinkStatus) {
973 _mesa_error(ctx, GL_INVALID_OPERATION,
974 "glUniformMatrix(program not linked)");
975 return;
976 }
977
978 if (location == -1)
979 return; /* The standard specifies this as a no-op */
980
981 if (location < -1) {
982 _mesa_error(ctx, GL_INVALID_OPERATION, "glUniformMatrix(location)");
983 return;
984 }
985
986 split_location_offset(&location, &offset);
987
988 if (location < 0 || location >= (GLint) shProg->Uniforms->NumUniforms) {
989 _mesa_error(ctx, GL_INVALID_VALUE, "glUniformMatrix(location)");
990 return;
991 }
992 if (values == NULL) {
993 _mesa_error(ctx, GL_INVALID_VALUE, "glUniformMatrix");
994 return;
995 }
996
997 FLUSH_VERTICES(ctx, _NEW_PROGRAM_CONSTANTS);
998
999 uniform = &shProg->Uniforms->Uniforms[location];
1000
1001 if (shProg->VertexProgram) {
1002 /* convert uniform location to program parameter index */
1003 GLint index = uniform->VertPos;
1004 if (index >= 0) {
1005 set_program_uniform_matrix(ctx, &shProg->VertexProgram->Base,
1006 index, offset,
1007 count, rows, cols, transpose, values);
1008 }
1009 }
1010
1011 if (shProg->FragmentProgram) {
1012 /* convert uniform location to program parameter index */
1013 GLint index = uniform->FragPos;
1014 if (index >= 0) {
1015 set_program_uniform_matrix(ctx, &shProg->FragmentProgram->Base,
1016 index, offset,
1017 count, rows, cols, transpose, values);
1018 }
1019 }
1020
1021 if (shProg->GeometryProgram) {
1022 /* convert uniform location to program parameter index */
1023 GLint index = uniform->GeomPos;
1024 if (index >= 0) {
1025 set_program_uniform_matrix(ctx, &shProg->GeometryProgram->Base,
1026 index, offset,
1027 count, rows, cols, transpose, values);
1028 }
1029 }
1030
1031 uniform->Initialized = GL_TRUE;
1032 }
1033
1034
1035 void GLAPIENTRY
1036 _mesa_Uniform1fARB(GLint location, GLfloat v0)
1037 {
1038 GET_CURRENT_CONTEXT(ctx);
1039 _mesa_uniform(ctx, ctx->Shader.ActiveProgram, location, 1, &v0, GL_FLOAT);
1040 }
1041
1042 void GLAPIENTRY
1043 _mesa_Uniform2fARB(GLint location, GLfloat v0, GLfloat v1)
1044 {
1045 GET_CURRENT_CONTEXT(ctx);
1046 GLfloat v[2];
1047 v[0] = v0;
1048 v[1] = v1;
1049 _mesa_uniform(ctx, ctx->Shader.ActiveProgram, location, 1, v, GL_FLOAT_VEC2);
1050 }
1051
1052 void GLAPIENTRY
1053 _mesa_Uniform3fARB(GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
1054 {
1055 GET_CURRENT_CONTEXT(ctx);
1056 GLfloat v[3];
1057 v[0] = v0;
1058 v[1] = v1;
1059 v[2] = v2;
1060 _mesa_uniform(ctx, ctx->Shader.ActiveProgram, location, 1, v, GL_FLOAT_VEC3);
1061 }
1062
1063 void GLAPIENTRY
1064 _mesa_Uniform4fARB(GLint location, GLfloat v0, GLfloat v1, GLfloat v2,
1065 GLfloat v3)
1066 {
1067 GET_CURRENT_CONTEXT(ctx);
1068 GLfloat v[4];
1069 v[0] = v0;
1070 v[1] = v1;
1071 v[2] = v2;
1072 v[3] = v3;
1073 _mesa_uniform(ctx, ctx->Shader.ActiveProgram, location, 1, v, GL_FLOAT_VEC4);
1074 }
1075
1076 void GLAPIENTRY
1077 _mesa_Uniform1iARB(GLint location, GLint v0)
1078 {
1079 GET_CURRENT_CONTEXT(ctx);
1080 _mesa_uniform(ctx, ctx->Shader.ActiveProgram, location, 1, &v0, GL_INT);
1081 }
1082
1083 void GLAPIENTRY
1084 _mesa_Uniform2iARB(GLint location, GLint v0, GLint v1)
1085 {
1086 GET_CURRENT_CONTEXT(ctx);
1087 GLint v[2];
1088 v[0] = v0;
1089 v[1] = v1;
1090 _mesa_uniform(ctx, ctx->Shader.ActiveProgram, location, 1, v, GL_INT_VEC2);
1091 }
1092
1093 void GLAPIENTRY
1094 _mesa_Uniform3iARB(GLint location, GLint v0, GLint v1, GLint v2)
1095 {
1096 GET_CURRENT_CONTEXT(ctx);
1097 GLint v[3];
1098 v[0] = v0;
1099 v[1] = v1;
1100 v[2] = v2;
1101 _mesa_uniform(ctx, ctx->Shader.ActiveProgram, location, 1, v, GL_INT_VEC3);
1102 }
1103
1104 void GLAPIENTRY
1105 _mesa_Uniform4iARB(GLint location, GLint v0, GLint v1, GLint v2, GLint v3)
1106 {
1107 GET_CURRENT_CONTEXT(ctx);
1108 GLint v[4];
1109 v[0] = v0;
1110 v[1] = v1;
1111 v[2] = v2;
1112 v[3] = v3;
1113 _mesa_uniform(ctx, ctx->Shader.ActiveProgram, location, 1, v, GL_INT_VEC4);
1114 }
1115
1116 void GLAPIENTRY
1117 _mesa_Uniform1fvARB(GLint location, GLsizei count, const GLfloat * value)
1118 {
1119 GET_CURRENT_CONTEXT(ctx);
1120 _mesa_uniform(ctx, ctx->Shader.ActiveProgram, location, count, value, GL_FLOAT);
1121 }
1122
1123 void GLAPIENTRY
1124 _mesa_Uniform2fvARB(GLint location, GLsizei count, const GLfloat * value)
1125 {
1126 GET_CURRENT_CONTEXT(ctx);
1127 _mesa_uniform(ctx, ctx->Shader.ActiveProgram, location, count, value, GL_FLOAT_VEC2);
1128 }
1129
1130 void GLAPIENTRY
1131 _mesa_Uniform3fvARB(GLint location, GLsizei count, const GLfloat * value)
1132 {
1133 GET_CURRENT_CONTEXT(ctx);
1134 _mesa_uniform(ctx, ctx->Shader.ActiveProgram, location, count, value, GL_FLOAT_VEC3);
1135 }
1136
1137 void GLAPIENTRY
1138 _mesa_Uniform4fvARB(GLint location, GLsizei count, const GLfloat * value)
1139 {
1140 GET_CURRENT_CONTEXT(ctx);
1141 _mesa_uniform(ctx, ctx->Shader.ActiveProgram, location, count, value, GL_FLOAT_VEC4);
1142 }
1143
1144 void GLAPIENTRY
1145 _mesa_Uniform1ivARB(GLint location, GLsizei count, const GLint * value)
1146 {
1147 GET_CURRENT_CONTEXT(ctx);
1148 _mesa_uniform(ctx, ctx->Shader.ActiveProgram, location, count, value, GL_INT);
1149 }
1150
1151 void GLAPIENTRY
1152 _mesa_Uniform2ivARB(GLint location, GLsizei count, const GLint * value)
1153 {
1154 GET_CURRENT_CONTEXT(ctx);
1155 _mesa_uniform(ctx, ctx->Shader.ActiveProgram, location, count, value, GL_INT_VEC2);
1156 }
1157
1158 void GLAPIENTRY
1159 _mesa_Uniform3ivARB(GLint location, GLsizei count, const GLint * value)
1160 {
1161 GET_CURRENT_CONTEXT(ctx);
1162 _mesa_uniform(ctx, ctx->Shader.ActiveProgram, location, count, value, GL_INT_VEC3);
1163 }
1164
1165 void GLAPIENTRY
1166 _mesa_Uniform4ivARB(GLint location, GLsizei count, const GLint * value)
1167 {
1168 GET_CURRENT_CONTEXT(ctx);
1169 _mesa_uniform(ctx, ctx->Shader.ActiveProgram, location, count, value, GL_INT_VEC4);
1170 }
1171
1172
1173 /** OpenGL 3.0 GLuint-valued functions **/
1174 void GLAPIENTRY
1175 _mesa_Uniform1ui(GLint location, GLuint v0)
1176 {
1177 GET_CURRENT_CONTEXT(ctx);
1178 _mesa_uniform(ctx, ctx->Shader.ActiveProgram, location, 1, &v0, GL_UNSIGNED_INT);
1179 }
1180
1181 void GLAPIENTRY
1182 _mesa_Uniform2ui(GLint location, GLuint v0, GLuint v1)
1183 {
1184 GET_CURRENT_CONTEXT(ctx);
1185 GLuint v[2];
1186 v[0] = v0;
1187 v[1] = v1;
1188 _mesa_uniform(ctx, ctx->Shader.ActiveProgram, location, 1, v, GL_UNSIGNED_INT_VEC2);
1189 }
1190
1191 void GLAPIENTRY
1192 _mesa_Uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
1193 {
1194 GET_CURRENT_CONTEXT(ctx);
1195 GLuint v[3];
1196 v[0] = v0;
1197 v[1] = v1;
1198 v[2] = v2;
1199 _mesa_uniform(ctx, ctx->Shader.ActiveProgram, location, 1, v, GL_UNSIGNED_INT_VEC3);
1200 }
1201
1202 void GLAPIENTRY
1203 _mesa_Uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
1204 {
1205 GET_CURRENT_CONTEXT(ctx);
1206 GLuint v[4];
1207 v[0] = v0;
1208 v[1] = v1;
1209 v[2] = v2;
1210 v[3] = v3;
1211 _mesa_uniform(ctx, ctx->Shader.ActiveProgram, location, 1, v, GL_UNSIGNED_INT_VEC4);
1212 }
1213
1214 void GLAPIENTRY
1215 _mesa_Uniform1uiv(GLint location, GLsizei count, const GLuint *value)
1216 {
1217 GET_CURRENT_CONTEXT(ctx);
1218 _mesa_uniform(ctx, ctx->Shader.ActiveProgram, location, count, value, GL_UNSIGNED_INT);
1219 }
1220
1221 void GLAPIENTRY
1222 _mesa_Uniform2uiv(GLint location, GLsizei count, const GLuint *value)
1223 {
1224 GET_CURRENT_CONTEXT(ctx);
1225 _mesa_uniform(ctx, ctx->Shader.ActiveProgram, location, count, value, GL_UNSIGNED_INT_VEC2);
1226 }
1227
1228 void GLAPIENTRY
1229 _mesa_Uniform3uiv(GLint location, GLsizei count, const GLuint *value)
1230 {
1231 GET_CURRENT_CONTEXT(ctx);
1232 _mesa_uniform(ctx, ctx->Shader.ActiveProgram, location, count, value, GL_UNSIGNED_INT_VEC3);
1233 }
1234
1235 void GLAPIENTRY
1236 _mesa_Uniform4uiv(GLint location, GLsizei count, const GLuint *value)
1237 {
1238 GET_CURRENT_CONTEXT(ctx);
1239 _mesa_uniform(ctx, ctx->Shader.ActiveProgram, location, count, value, GL_UNSIGNED_INT_VEC4);
1240 }
1241
1242
1243
1244 void GLAPIENTRY
1245 _mesa_UniformMatrix2fvARB(GLint location, GLsizei count, GLboolean transpose,
1246 const GLfloat * value)
1247 {
1248 GET_CURRENT_CONTEXT(ctx);
1249 _mesa_uniform_matrix(ctx, ctx->Shader.ActiveProgram,
1250 2, 2, location, count, transpose, value);
1251 }
1252
1253 void GLAPIENTRY
1254 _mesa_UniformMatrix3fvARB(GLint location, GLsizei count, GLboolean transpose,
1255 const GLfloat * value)
1256 {
1257 GET_CURRENT_CONTEXT(ctx);
1258 _mesa_uniform_matrix(ctx, ctx->Shader.ActiveProgram,
1259 3, 3, location, count, transpose, value);
1260 }
1261
1262 void GLAPIENTRY
1263 _mesa_UniformMatrix4fvARB(GLint location, GLsizei count, GLboolean transpose,
1264 const GLfloat * value)
1265 {
1266 GET_CURRENT_CONTEXT(ctx);
1267 _mesa_uniform_matrix(ctx, ctx->Shader.ActiveProgram,
1268 4, 4, location, count, transpose, value);
1269 }
1270
1271
1272 /**
1273 * Non-square UniformMatrix are OpenGL 2.1
1274 */
1275 void GLAPIENTRY
1276 _mesa_UniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose,
1277 const GLfloat *value)
1278 {
1279 GET_CURRENT_CONTEXT(ctx);
1280 _mesa_uniform_matrix(ctx, ctx->Shader.ActiveProgram,
1281 2, 3, location, count, transpose, value);
1282 }
1283
1284 void GLAPIENTRY
1285 _mesa_UniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose,
1286 const GLfloat *value)
1287 {
1288 GET_CURRENT_CONTEXT(ctx);
1289 _mesa_uniform_matrix(ctx, ctx->Shader.ActiveProgram,
1290 3, 2, location, count, transpose, value);
1291 }
1292
1293 void GLAPIENTRY
1294 _mesa_UniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose,
1295 const GLfloat *value)
1296 {
1297 GET_CURRENT_CONTEXT(ctx);
1298 _mesa_uniform_matrix(ctx, ctx->Shader.ActiveProgram,
1299 2, 4, location, count, transpose, value);
1300 }
1301
1302 void GLAPIENTRY
1303 _mesa_UniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose,
1304 const GLfloat *value)
1305 {
1306 GET_CURRENT_CONTEXT(ctx);
1307 _mesa_uniform_matrix(ctx, ctx->Shader.ActiveProgram,
1308 4, 2, location, count, transpose, value);
1309 }
1310
1311 void GLAPIENTRY
1312 _mesa_UniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose,
1313 const GLfloat *value)
1314 {
1315 GET_CURRENT_CONTEXT(ctx);
1316 _mesa_uniform_matrix(ctx, ctx->Shader.ActiveProgram,
1317 3, 4, location, count, transpose, value);
1318 }
1319
1320 void GLAPIENTRY
1321 _mesa_UniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose,
1322 const GLfloat *value)
1323 {
1324 GET_CURRENT_CONTEXT(ctx);
1325 _mesa_uniform_matrix(ctx, ctx->Shader.ActiveProgram,
1326 4, 3, location, count, transpose, value);
1327 }
1328
1329
1330 void GLAPIENTRY
1331 _mesa_GetnUniformfvARB(GLhandleARB program, GLint location,
1332 GLsizei bufSize, GLfloat *params)
1333 {
1334 GET_CURRENT_CONTEXT(ctx);
1335 get_uniform(ctx, program, location, bufSize, GL_FLOAT, params);
1336 }
1337
1338 void GLAPIENTRY
1339 _mesa_GetUniformfvARB(GLhandleARB program, GLint location, GLfloat *params)
1340 {
1341 _mesa_GetnUniformfvARB(program, location, INT_MAX, params);
1342 }
1343
1344
1345 void GLAPIENTRY
1346 _mesa_GetnUniformivARB(GLhandleARB program, GLint location,
1347 GLsizei bufSize, GLint *params)
1348 {
1349 GET_CURRENT_CONTEXT(ctx);
1350 get_uniform(ctx, program, location, bufSize, GL_INT, params);
1351 }
1352
1353 void GLAPIENTRY
1354 _mesa_GetUniformivARB(GLhandleARB program, GLint location, GLint *params)
1355 {
1356 _mesa_GetnUniformivARB(program, location, INT_MAX, params);
1357 }
1358
1359
1360 /* GL3 */
1361 void GLAPIENTRY
1362 _mesa_GetnUniformuivARB(GLhandleARB program, GLint location,
1363 GLsizei bufSize, GLuint *params)
1364 {
1365 GET_CURRENT_CONTEXT(ctx);
1366 get_uniform(ctx, program, location, bufSize, GL_UNSIGNED_INT, params);
1367 }
1368
1369 void GLAPIENTRY
1370 _mesa_GetUniformuiv(GLhandleARB program, GLint location, GLuint *params)
1371 {
1372 _mesa_GetnUniformuivARB(program, location, INT_MAX, params);
1373 }
1374
1375
1376 /* GL4 */
1377 void GLAPIENTRY
1378 _mesa_GetnUniformdvARB(GLhandleARB program, GLint location,
1379 GLsizei bufSize, GLdouble *params)
1380 {
1381 GET_CURRENT_CONTEXT(ctx);
1382 /*
1383 get_uniform(ctx, program, location, bufSize, GL_DOUBLE, params);
1384 */
1385 _mesa_error(ctx, GL_INVALID_OPERATION, "glGetUniformdvARB"
1386 "(GL_ARB_gpu_shader_fp64 not implemented)");
1387 }
1388
1389 void GLAPIENTRY
1390 _mesa_GetUniformdv(GLhandleARB program, GLint location, GLdouble *params)
1391 {
1392 _mesa_GetnUniformdvARB(program, location, INT_MAX, params);
1393 }
1394
1395
1396 GLint GLAPIENTRY
1397 _mesa_GetUniformLocationARB(GLhandleARB programObj, const GLcharARB *name)
1398 {
1399 struct gl_shader_program *shProg;
1400
1401 GET_CURRENT_CONTEXT(ctx);
1402
1403 shProg = _mesa_lookup_shader_program_err(ctx, programObj,
1404 "glGetUniformLocation");
1405 if (!shProg)
1406 return -1;
1407
1408 return _mesa_get_uniform_location(ctx, shProg, name);
1409 }
1410
1411
1412 void GLAPIENTRY
1413 _mesa_GetActiveUniformARB(GLhandleARB program, GLuint index,
1414 GLsizei maxLength, GLsizei * length, GLint * size,
1415 GLenum * type, GLcharARB * name)
1416 {
1417 GET_CURRENT_CONTEXT(ctx);
1418 _mesa_get_active_uniform(ctx, program, index, maxLength, length, size,
1419 type, name);
1420 }
1421
1422
1423 /**
1424 * Plug in shader uniform-related functions into API dispatch table.
1425 */
1426 void
1427 _mesa_init_shader_uniform_dispatch(struct _glapi_table *exec)
1428 {
1429 #if FEATURE_GL
1430 SET_Uniform1fARB(exec, _mesa_Uniform1fARB);
1431 SET_Uniform2fARB(exec, _mesa_Uniform2fARB);
1432 SET_Uniform3fARB(exec, _mesa_Uniform3fARB);
1433 SET_Uniform4fARB(exec, _mesa_Uniform4fARB);
1434 SET_Uniform1iARB(exec, _mesa_Uniform1iARB);
1435 SET_Uniform2iARB(exec, _mesa_Uniform2iARB);
1436 SET_Uniform3iARB(exec, _mesa_Uniform3iARB);
1437 SET_Uniform4iARB(exec, _mesa_Uniform4iARB);
1438 SET_Uniform1fvARB(exec, _mesa_Uniform1fvARB);
1439 SET_Uniform2fvARB(exec, _mesa_Uniform2fvARB);
1440 SET_Uniform3fvARB(exec, _mesa_Uniform3fvARB);
1441 SET_Uniform4fvARB(exec, _mesa_Uniform4fvARB);
1442 SET_Uniform1ivARB(exec, _mesa_Uniform1ivARB);
1443 SET_Uniform2ivARB(exec, _mesa_Uniform2ivARB);
1444 SET_Uniform3ivARB(exec, _mesa_Uniform3ivARB);
1445 SET_Uniform4ivARB(exec, _mesa_Uniform4ivARB);
1446 SET_UniformMatrix2fvARB(exec, _mesa_UniformMatrix2fvARB);
1447 SET_UniformMatrix3fvARB(exec, _mesa_UniformMatrix3fvARB);
1448 SET_UniformMatrix4fvARB(exec, _mesa_UniformMatrix4fvARB);
1449
1450 SET_GetActiveUniformARB(exec, _mesa_GetActiveUniformARB);
1451 SET_GetUniformLocationARB(exec, _mesa_GetUniformLocationARB);
1452 SET_GetUniformfvARB(exec, _mesa_GetUniformfvARB);
1453 SET_GetUniformivARB(exec, _mesa_GetUniformivARB);
1454
1455 /* OpenGL 2.1 */
1456 SET_UniformMatrix2x3fv(exec, _mesa_UniformMatrix2x3fv);
1457 SET_UniformMatrix3x2fv(exec, _mesa_UniformMatrix3x2fv);
1458 SET_UniformMatrix2x4fv(exec, _mesa_UniformMatrix2x4fv);
1459 SET_UniformMatrix4x2fv(exec, _mesa_UniformMatrix4x2fv);
1460 SET_UniformMatrix3x4fv(exec, _mesa_UniformMatrix3x4fv);
1461 SET_UniformMatrix4x3fv(exec, _mesa_UniformMatrix4x3fv);
1462
1463 /* OpenGL 3.0 */
1464 SET_Uniform1uiEXT(exec, _mesa_Uniform1ui);
1465 SET_Uniform2uiEXT(exec, _mesa_Uniform2ui);
1466 SET_Uniform3uiEXT(exec, _mesa_Uniform3ui);
1467 SET_Uniform4uiEXT(exec, _mesa_Uniform4ui);
1468 SET_Uniform1uivEXT(exec, _mesa_Uniform1uiv);
1469 SET_Uniform2uivEXT(exec, _mesa_Uniform2uiv);
1470 SET_Uniform3uivEXT(exec, _mesa_Uniform3uiv);
1471 SET_Uniform4uivEXT(exec, _mesa_Uniform4uiv);
1472 SET_GetUniformuivEXT(exec, _mesa_GetUniformuiv);
1473
1474 /* GL_ARB_robustness */
1475 SET_GetnUniformfvARB(exec, _mesa_GetnUniformfvARB);
1476 SET_GetnUniformivARB(exec, _mesa_GetnUniformivARB);
1477 SET_GetnUniformuivARB(exec, _mesa_GetnUniformuivARB);
1478 SET_GetnUniformdvARB(exec, _mesa_GetnUniformdvARB); /* GL 4.0 */
1479
1480 #endif /* FEATURE_GL */
1481 }