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