2 * Mesa 3-D graphics library
4 * Copyright (C) 2004-2008 Brian Paul All Rights Reserved.
5 * Copyright (C) 2009-2010 VMware, Inc. All Rights Reserved.
6 * Copyright © 2010 Intel Corporation
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
22 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
23 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24 * OTHER DEALINGS IN THE SOFTWARE.
29 * Functions related to GLSL uniform variables.
35 * 1. Check that the right error code is generated for all _mesa_error() calls.
36 * 2. Insert FLUSH_VERTICES calls in various places
39 #include "main/glheader.h"
40 #include "main/context.h"
41 #include "main/dispatch.h"
42 #include "main/shaderapi.h"
43 #include "main/shaderobj.h"
44 #include "main/uniforms.h"
45 #include "main/enums.h"
46 #include "ir_uniform.h"
47 #include "glsl_types.h"
48 #include "program/program.h"
51 * Update the vertex/fragment program's TexturesUsed array.
53 * This needs to be called after glUniform(set sampler var) is called.
54 * A call to glUniform(samplerVar, value) causes a sampler to point to a
55 * particular texture unit. We know the sampler's texture target
56 * (1D/2D/3D/etc) from compile time but the sampler's texture unit is
57 * set by glUniform() calls.
59 * So, scan the program->SamplerUnits[] and program->SamplerTargets[]
60 * information to update the prog->TexturesUsed[] values.
61 * Each value of TexturesUsed[unit] is one of zero, TEXTURE_1D_INDEX,
62 * TEXTURE_2D_INDEX, TEXTURE_3D_INDEX, etc.
63 * We'll use that info for state validation before rendering.
66 _mesa_update_shader_textures_used(struct gl_shader_program
*shProg
,
67 struct gl_program
*prog
)
70 struct gl_shader
*shader
=
71 shProg
->_LinkedShaders
[_mesa_program_enum_to_shader_stage(prog
->Target
)];
75 memcpy(prog
->SamplerUnits
, shader
->SamplerUnits
, sizeof(prog
->SamplerUnits
));
76 memset(prog
->TexturesUsed
, 0, sizeof(prog
->TexturesUsed
));
78 for (s
= 0; s
< MAX_SAMPLERS
; s
++) {
79 if (prog
->SamplersUsed
& (1 << s
)) {
80 GLuint unit
= shader
->SamplerUnits
[s
];
81 GLuint tgt
= shader
->SamplerTargets
[s
];
82 assert(unit
< Elements(prog
->TexturesUsed
));
83 assert(tgt
< NUM_TEXTURE_TARGETS
);
84 prog
->TexturesUsed
[unit
] |= (1 << tgt
);
90 * Connect a piece of driver storage with a part of a uniform
92 * \param uni The uniform with which the storage will be associated
93 * \param element_stride Byte-stride between array elements.
94 * \sa gl_uniform_driver_storage::element_stride.
95 * \param vector_stride Byte-stride between vectors (in a matrix).
96 * \sa gl_uniform_driver_storage::vector_stride.
97 * \param format Conversion from native format to driver format
98 * required by the driver.
99 * \param data Location to dump the data.
102 _mesa_uniform_attach_driver_storage(struct gl_uniform_storage
*uni
,
103 unsigned element_stride
,
104 unsigned vector_stride
,
105 enum gl_uniform_driver_format format
,
108 uni
->driver_storage
=
109 realloc(uni
->driver_storage
,
110 sizeof(struct gl_uniform_driver_storage
)
111 * (uni
->num_driver_storage
+ 1));
113 uni
->driver_storage
[uni
->num_driver_storage
].element_stride
= element_stride
;
114 uni
->driver_storage
[uni
->num_driver_storage
].vector_stride
= vector_stride
;
115 uni
->driver_storage
[uni
->num_driver_storage
].format
= format
;
116 uni
->driver_storage
[uni
->num_driver_storage
].data
= data
;
118 uni
->num_driver_storage
++;
122 * Sever all connections with all pieces of driver storage for all uniforms
125 * This function does \b not release any of the \c data pointers
126 * previously passed in to \c _mesa_uniform_attach_driver_stoarge.
129 _mesa_uniform_detach_all_driver_storage(struct gl_uniform_storage
*uni
)
131 free(uni
->driver_storage
);
132 uni
->driver_storage
= NULL
;
133 uni
->num_driver_storage
= 0;
137 _mesa_Uniform1f(GLint location
, GLfloat v0
)
139 GET_CURRENT_CONTEXT(ctx
);
140 _mesa_uniform(ctx
, ctx
->_Shader
->ActiveProgram
, location
, 1, &v0
, GL_FLOAT
);
144 _mesa_Uniform2f(GLint location
, GLfloat v0
, GLfloat v1
)
146 GET_CURRENT_CONTEXT(ctx
);
150 _mesa_uniform(ctx
, ctx
->_Shader
->ActiveProgram
, location
, 1, v
, GL_FLOAT_VEC2
);
154 _mesa_Uniform3f(GLint location
, GLfloat v0
, GLfloat v1
, GLfloat v2
)
156 GET_CURRENT_CONTEXT(ctx
);
161 _mesa_uniform(ctx
, ctx
->_Shader
->ActiveProgram
, location
, 1, v
, GL_FLOAT_VEC3
);
165 _mesa_Uniform4f(GLint location
, GLfloat v0
, GLfloat v1
, GLfloat v2
,
168 GET_CURRENT_CONTEXT(ctx
);
174 _mesa_uniform(ctx
, ctx
->_Shader
->ActiveProgram
, location
, 1, v
, GL_FLOAT_VEC4
);
178 _mesa_Uniform1i(GLint location
, GLint v0
)
180 GET_CURRENT_CONTEXT(ctx
);
181 _mesa_uniform(ctx
, ctx
->_Shader
->ActiveProgram
, location
, 1, &v0
, GL_INT
);
185 _mesa_Uniform2i(GLint location
, GLint v0
, GLint v1
)
187 GET_CURRENT_CONTEXT(ctx
);
191 _mesa_uniform(ctx
, ctx
->_Shader
->ActiveProgram
, location
, 1, v
, GL_INT_VEC2
);
195 _mesa_Uniform3i(GLint location
, GLint v0
, GLint v1
, GLint v2
)
197 GET_CURRENT_CONTEXT(ctx
);
202 _mesa_uniform(ctx
, ctx
->_Shader
->ActiveProgram
, location
, 1, v
, GL_INT_VEC3
);
206 _mesa_Uniform4i(GLint location
, GLint v0
, GLint v1
, GLint v2
, GLint v3
)
208 GET_CURRENT_CONTEXT(ctx
);
214 _mesa_uniform(ctx
, ctx
->_Shader
->ActiveProgram
, location
, 1, v
, GL_INT_VEC4
);
218 _mesa_Uniform1fv(GLint location
, GLsizei count
, const GLfloat
* value
)
220 GET_CURRENT_CONTEXT(ctx
);
221 _mesa_uniform(ctx
, ctx
->_Shader
->ActiveProgram
, location
, count
, value
, GL_FLOAT
);
225 _mesa_Uniform2fv(GLint location
, GLsizei count
, const GLfloat
* value
)
227 GET_CURRENT_CONTEXT(ctx
);
228 _mesa_uniform(ctx
, ctx
->_Shader
->ActiveProgram
, location
, count
, value
, GL_FLOAT_VEC2
);
232 _mesa_Uniform3fv(GLint location
, GLsizei count
, const GLfloat
* value
)
234 GET_CURRENT_CONTEXT(ctx
);
235 _mesa_uniform(ctx
, ctx
->_Shader
->ActiveProgram
, location
, count
, value
, GL_FLOAT_VEC3
);
239 _mesa_Uniform4fv(GLint location
, GLsizei count
, const GLfloat
* value
)
241 GET_CURRENT_CONTEXT(ctx
);
242 _mesa_uniform(ctx
, ctx
->_Shader
->ActiveProgram
, location
, count
, value
, GL_FLOAT_VEC4
);
246 _mesa_Uniform1iv(GLint location
, GLsizei count
, const GLint
* value
)
248 GET_CURRENT_CONTEXT(ctx
);
249 _mesa_uniform(ctx
, ctx
->_Shader
->ActiveProgram
, location
, count
, value
, GL_INT
);
253 _mesa_Uniform2iv(GLint location
, GLsizei count
, const GLint
* value
)
255 GET_CURRENT_CONTEXT(ctx
);
256 _mesa_uniform(ctx
, ctx
->_Shader
->ActiveProgram
, location
, count
, value
, GL_INT_VEC2
);
260 _mesa_Uniform3iv(GLint location
, GLsizei count
, const GLint
* value
)
262 GET_CURRENT_CONTEXT(ctx
);
263 _mesa_uniform(ctx
, ctx
->_Shader
->ActiveProgram
, location
, count
, value
, GL_INT_VEC3
);
267 _mesa_Uniform4iv(GLint location
, GLsizei count
, const GLint
* value
)
269 GET_CURRENT_CONTEXT(ctx
);
270 _mesa_uniform(ctx
, ctx
->_Shader
->ActiveProgram
, location
, count
, value
, GL_INT_VEC4
);
273 /** Same as above with direct state access **/
275 _mesa_ProgramUniform1f(GLuint program
, GLint location
, GLfloat v0
)
277 GET_CURRENT_CONTEXT(ctx
);
278 struct gl_shader_program
*shProg
=
279 _mesa_lookup_shader_program_err(ctx
, program
,
280 "glProgramUniform1f");
281 _mesa_uniform(ctx
, shProg
, location
, 1, &v0
, GL_FLOAT
);
285 _mesa_ProgramUniform2f(GLuint program
, GLint location
, GLfloat v0
, GLfloat v1
)
287 GET_CURRENT_CONTEXT(ctx
);
289 struct gl_shader_program
*shProg
;
292 shProg
= _mesa_lookup_shader_program_err(ctx
, program
, "glProgramUniform2f");
293 _mesa_uniform(ctx
, shProg
, location
, 1, v
, GL_FLOAT_VEC2
);
297 _mesa_ProgramUniform3f(GLuint program
, GLint location
, GLfloat v0
, GLfloat v1
,
300 GET_CURRENT_CONTEXT(ctx
);
302 struct gl_shader_program
*shProg
;
306 shProg
= _mesa_lookup_shader_program_err(ctx
, program
, "glProgramUniform3f");
307 _mesa_uniform(ctx
, shProg
, location
, 1, v
, GL_FLOAT_VEC3
);
311 _mesa_ProgramUniform4f(GLuint program
, GLint location
, GLfloat v0
, GLfloat v1
,
312 GLfloat v2
, GLfloat v3
)
314 GET_CURRENT_CONTEXT(ctx
);
316 struct gl_shader_program
*shProg
;
321 shProg
= _mesa_lookup_shader_program_err(ctx
, program
, "glProgramUniform4f");
322 _mesa_uniform(ctx
, shProg
, location
, 1, v
, GL_FLOAT_VEC4
);
326 _mesa_ProgramUniform1i(GLuint program
, GLint location
, GLint v0
)
328 GET_CURRENT_CONTEXT(ctx
);
329 struct gl_shader_program
*shProg
=
330 _mesa_lookup_shader_program_err(ctx
, program
,
331 "glProgramUniform1i");
332 _mesa_uniform(ctx
, shProg
, location
, 1, &v0
, GL_INT
);
336 _mesa_ProgramUniform2i(GLuint program
, GLint location
, GLint v0
, GLint v1
)
338 GET_CURRENT_CONTEXT(ctx
);
340 struct gl_shader_program
*shProg
;
343 shProg
= _mesa_lookup_shader_program_err(ctx
, program
, "glProgramUniform2i");
344 _mesa_uniform(ctx
, shProg
, location
, 1, v
, GL_INT_VEC2
);
348 _mesa_ProgramUniform3i(GLuint program
, GLint location
, GLint v0
, GLint v1
,
351 GET_CURRENT_CONTEXT(ctx
);
353 struct gl_shader_program
*shProg
;
357 shProg
= _mesa_lookup_shader_program_err(ctx
, program
, "glProgramUniform3i");
358 _mesa_uniform(ctx
, shProg
, location
, 1, v
, GL_INT_VEC3
);
362 _mesa_ProgramUniform4i(GLuint program
, GLint location
, GLint v0
, GLint v1
,
365 GET_CURRENT_CONTEXT(ctx
);
367 struct gl_shader_program
*shProg
;
372 shProg
= _mesa_lookup_shader_program_err(ctx
, program
, "glProgramUniform4i");
373 _mesa_uniform(ctx
, shProg
, location
, 1, v
, GL_INT_VEC4
);
377 _mesa_ProgramUniform1fv(GLuint program
, GLint location
, GLsizei count
,
378 const GLfloat
* value
)
380 GET_CURRENT_CONTEXT(ctx
);
381 struct gl_shader_program
*shProg
=
382 _mesa_lookup_shader_program_err(ctx
, program
,
383 "glProgramUniform1fv");
384 _mesa_uniform(ctx
, shProg
, location
, count
, value
, GL_FLOAT
);
388 _mesa_ProgramUniform2fv(GLuint program
, GLint location
, GLsizei count
,
389 const GLfloat
* value
)
391 GET_CURRENT_CONTEXT(ctx
);
392 struct gl_shader_program
*shProg
=
393 _mesa_lookup_shader_program_err(ctx
, program
,
394 "glProgramUniform2fv");
395 _mesa_uniform(ctx
, shProg
, location
, count
, value
, GL_FLOAT_VEC2
);
399 _mesa_ProgramUniform3fv(GLuint program
, GLint location
, GLsizei count
,
400 const GLfloat
* value
)
402 GET_CURRENT_CONTEXT(ctx
);
403 struct gl_shader_program
*shProg
=
404 _mesa_lookup_shader_program_err(ctx
, program
,
405 "glProgramUniform3fv");
406 _mesa_uniform(ctx
, shProg
, location
, count
, value
, GL_FLOAT_VEC3
);
410 _mesa_ProgramUniform4fv(GLuint program
, GLint location
, GLsizei count
,
411 const GLfloat
* value
)
413 GET_CURRENT_CONTEXT(ctx
);
414 struct gl_shader_program
*shProg
=
415 _mesa_lookup_shader_program_err(ctx
, program
,
416 "glProgramUniform4fv");
417 _mesa_uniform(ctx
, shProg
, location
, count
, value
, GL_FLOAT_VEC4
);
421 _mesa_ProgramUniform1iv(GLuint program
, GLint location
, GLsizei count
,
424 GET_CURRENT_CONTEXT(ctx
);
425 struct gl_shader_program
*shProg
=
426 _mesa_lookup_shader_program_err(ctx
, program
,
427 "glProgramUniform1iv");
428 _mesa_uniform(ctx
, shProg
, location
, count
, value
, GL_INT
);
432 _mesa_ProgramUniform2iv(GLuint program
, GLint location
, GLsizei count
,
435 GET_CURRENT_CONTEXT(ctx
);
436 struct gl_shader_program
*shProg
=
437 _mesa_lookup_shader_program_err(ctx
, program
,
438 "glProgramUniform2iv");
439 _mesa_uniform(ctx
, shProg
, location
, count
, value
, GL_INT_VEC2
);
443 _mesa_ProgramUniform3iv(GLuint program
, GLint location
, GLsizei count
,
446 GET_CURRENT_CONTEXT(ctx
);
447 struct gl_shader_program
*shProg
=
448 _mesa_lookup_shader_program_err(ctx
, program
,
449 "glProgramUniform3iv");
450 _mesa_uniform(ctx
, shProg
, location
, count
, value
, GL_INT_VEC3
);
454 _mesa_ProgramUniform4iv(GLuint program
, GLint location
, GLsizei count
,
457 GET_CURRENT_CONTEXT(ctx
);
458 struct gl_shader_program
*shProg
=
459 _mesa_lookup_shader_program_err(ctx
, program
,
460 "glProgramUniform4iv");
461 _mesa_uniform(ctx
, shProg
, location
, count
, value
, GL_INT_VEC4
);
465 /** OpenGL 3.0 GLuint-valued functions **/
467 _mesa_Uniform1ui(GLint location
, GLuint v0
)
469 GET_CURRENT_CONTEXT(ctx
);
470 _mesa_uniform(ctx
, ctx
->_Shader
->ActiveProgram
, location
, 1, &v0
, GL_UNSIGNED_INT
);
474 _mesa_Uniform2ui(GLint location
, GLuint v0
, GLuint v1
)
476 GET_CURRENT_CONTEXT(ctx
);
480 _mesa_uniform(ctx
, ctx
->_Shader
->ActiveProgram
, location
, 1, v
, GL_UNSIGNED_INT_VEC2
);
484 _mesa_Uniform3ui(GLint location
, GLuint v0
, GLuint v1
, GLuint v2
)
486 GET_CURRENT_CONTEXT(ctx
);
491 _mesa_uniform(ctx
, ctx
->_Shader
->ActiveProgram
, location
, 1, v
, GL_UNSIGNED_INT_VEC3
);
495 _mesa_Uniform4ui(GLint location
, GLuint v0
, GLuint v1
, GLuint v2
, GLuint v3
)
497 GET_CURRENT_CONTEXT(ctx
);
503 _mesa_uniform(ctx
, ctx
->_Shader
->ActiveProgram
, location
, 1, v
, GL_UNSIGNED_INT_VEC4
);
507 _mesa_Uniform1uiv(GLint location
, GLsizei count
, const GLuint
*value
)
509 GET_CURRENT_CONTEXT(ctx
);
510 _mesa_uniform(ctx
, ctx
->_Shader
->ActiveProgram
, location
, count
, value
, GL_UNSIGNED_INT
);
514 _mesa_Uniform2uiv(GLint location
, GLsizei count
, const GLuint
*value
)
516 GET_CURRENT_CONTEXT(ctx
);
517 _mesa_uniform(ctx
, ctx
->_Shader
->ActiveProgram
, location
, count
, value
, GL_UNSIGNED_INT_VEC2
);
521 _mesa_Uniform3uiv(GLint location
, GLsizei count
, const GLuint
*value
)
523 GET_CURRENT_CONTEXT(ctx
);
524 _mesa_uniform(ctx
, ctx
->_Shader
->ActiveProgram
, location
, count
, value
, GL_UNSIGNED_INT_VEC3
);
528 _mesa_Uniform4uiv(GLint location
, GLsizei count
, const GLuint
*value
)
530 GET_CURRENT_CONTEXT(ctx
);
531 _mesa_uniform(ctx
, ctx
->_Shader
->ActiveProgram
, location
, count
, value
, GL_UNSIGNED_INT_VEC4
);
537 _mesa_UniformMatrix2fv(GLint location
, GLsizei count
, GLboolean transpose
,
538 const GLfloat
* value
)
540 GET_CURRENT_CONTEXT(ctx
);
541 _mesa_uniform_matrix(ctx
, ctx
->_Shader
->ActiveProgram
,
542 2, 2, location
, count
, transpose
, value
);
546 _mesa_UniformMatrix3fv(GLint location
, GLsizei count
, GLboolean transpose
,
547 const GLfloat
* value
)
549 GET_CURRENT_CONTEXT(ctx
);
550 _mesa_uniform_matrix(ctx
, ctx
->_Shader
->ActiveProgram
,
551 3, 3, location
, count
, transpose
, value
);
555 _mesa_UniformMatrix4fv(GLint location
, GLsizei count
, GLboolean transpose
,
556 const GLfloat
* value
)
558 GET_CURRENT_CONTEXT(ctx
);
559 _mesa_uniform_matrix(ctx
, ctx
->_Shader
->ActiveProgram
,
560 4, 4, location
, count
, transpose
, value
);
563 /** Same as above with direct state access **/
566 _mesa_ProgramUniform1ui(GLuint program
, GLint location
, GLuint v0
)
568 GET_CURRENT_CONTEXT(ctx
);
569 struct gl_shader_program
*shProg
=
570 _mesa_lookup_shader_program_err(ctx
, program
,
571 "glProgramUniform1ui");
572 _mesa_uniform(ctx
, shProg
, location
, 1, &v0
, GL_UNSIGNED_INT
);
576 _mesa_ProgramUniform2ui(GLuint program
, GLint location
, GLuint v0
, GLuint v1
)
578 GET_CURRENT_CONTEXT(ctx
);
580 struct gl_shader_program
*shProg
;
583 shProg
= _mesa_lookup_shader_program_err(ctx
, program
,
584 "glProgramUniform2ui");
585 _mesa_uniform(ctx
, shProg
, location
, 1, v
, GL_UNSIGNED_INT_VEC2
);
589 _mesa_ProgramUniform3ui(GLuint program
, GLint location
, GLuint v0
, GLuint v1
,
592 GET_CURRENT_CONTEXT(ctx
);
594 struct gl_shader_program
*shProg
;
598 shProg
= _mesa_lookup_shader_program_err(ctx
, program
,
599 "glProgramUniform3ui");
600 _mesa_uniform(ctx
, shProg
, location
, 1, v
, GL_UNSIGNED_INT_VEC3
);
604 _mesa_ProgramUniform4ui(GLuint program
, GLint location
, GLuint v0
, GLuint v1
,
605 GLuint v2
, GLuint v3
)
607 GET_CURRENT_CONTEXT(ctx
);
609 struct gl_shader_program
*shProg
;
614 shProg
= _mesa_lookup_shader_program_err(ctx
, program
, "glProgramUniform4ui");
615 _mesa_uniform(ctx
, shProg
, location
, 1, v
, GL_UNSIGNED_INT_VEC4
);
619 _mesa_ProgramUniform1uiv(GLuint program
, GLint location
, GLsizei count
,
622 GET_CURRENT_CONTEXT(ctx
);
623 struct gl_shader_program
*shProg
=
624 _mesa_lookup_shader_program_err(ctx
, program
,
625 "glProgramUniform1uiv");
626 _mesa_uniform(ctx
, shProg
, location
, count
, value
, GL_UNSIGNED_INT
);
630 _mesa_ProgramUniform2uiv(GLuint program
, GLint location
, GLsizei count
,
633 GET_CURRENT_CONTEXT(ctx
);
634 struct gl_shader_program
*shProg
=
635 _mesa_lookup_shader_program_err(ctx
, program
,
636 "glProgramUniform2uiv");
637 _mesa_uniform(ctx
, shProg
, location
, count
, value
, GL_UNSIGNED_INT_VEC2
);
641 _mesa_ProgramUniform3uiv(GLuint program
, GLint location
, GLsizei count
,
644 GET_CURRENT_CONTEXT(ctx
);
645 struct gl_shader_program
*shProg
=
646 _mesa_lookup_shader_program_err(ctx
, program
,
647 "glProgramUniform3uiv");
648 _mesa_uniform(ctx
, shProg
, location
, count
, value
, GL_UNSIGNED_INT_VEC3
);
652 _mesa_ProgramUniform4uiv(GLuint program
, GLint location
, GLsizei count
,
655 GET_CURRENT_CONTEXT(ctx
);
656 struct gl_shader_program
*shProg
=
657 _mesa_lookup_shader_program_err(ctx
, program
,
658 "glProgramUniform4uiv");
659 _mesa_uniform(ctx
, shProg
, location
, count
, value
, GL_UNSIGNED_INT_VEC4
);
665 _mesa_ProgramUniformMatrix2fv(GLuint program
, GLint location
, GLsizei count
,
666 GLboolean transpose
, const GLfloat
* value
)
668 GET_CURRENT_CONTEXT(ctx
);
669 struct gl_shader_program
*shProg
=
670 _mesa_lookup_shader_program_err(ctx
, program
,
671 "glProgramUniformMatrix2fv");
672 _mesa_uniform_matrix(ctx
, shProg
, 2, 2, location
, count
, transpose
, value
);
676 _mesa_ProgramUniformMatrix3fv(GLuint program
, GLint location
, GLsizei count
,
677 GLboolean transpose
, const GLfloat
* value
)
679 GET_CURRENT_CONTEXT(ctx
);
680 struct gl_shader_program
*shProg
=
681 _mesa_lookup_shader_program_err(ctx
, program
,
682 "glProgramUniformMatrix3fv");
683 _mesa_uniform_matrix(ctx
, shProg
, 3, 3, location
, count
, transpose
, value
);
687 _mesa_ProgramUniformMatrix4fv(GLuint program
, GLint location
, GLsizei count
,
688 GLboolean transpose
, const GLfloat
* value
)
690 GET_CURRENT_CONTEXT(ctx
);
691 struct gl_shader_program
*shProg
=
692 _mesa_lookup_shader_program_err(ctx
, program
,
693 "glProgramUniformMatrix4fv");
694 _mesa_uniform_matrix(ctx
, shProg
, 4, 4, location
, count
, transpose
, value
);
699 * Non-square UniformMatrix are OpenGL 2.1
702 _mesa_UniformMatrix2x3fv(GLint location
, GLsizei count
, GLboolean transpose
,
703 const GLfloat
*value
)
705 GET_CURRENT_CONTEXT(ctx
);
706 _mesa_uniform_matrix(ctx
, ctx
->_Shader
->ActiveProgram
,
707 2, 3, location
, count
, transpose
, value
);
711 _mesa_UniformMatrix3x2fv(GLint location
, GLsizei count
, GLboolean transpose
,
712 const GLfloat
*value
)
714 GET_CURRENT_CONTEXT(ctx
);
715 _mesa_uniform_matrix(ctx
, ctx
->_Shader
->ActiveProgram
,
716 3, 2, location
, count
, transpose
, value
);
720 _mesa_UniformMatrix2x4fv(GLint location
, GLsizei count
, GLboolean transpose
,
721 const GLfloat
*value
)
723 GET_CURRENT_CONTEXT(ctx
);
724 _mesa_uniform_matrix(ctx
, ctx
->_Shader
->ActiveProgram
,
725 2, 4, location
, count
, transpose
, value
);
729 _mesa_UniformMatrix4x2fv(GLint location
, GLsizei count
, GLboolean transpose
,
730 const GLfloat
*value
)
732 GET_CURRENT_CONTEXT(ctx
);
733 _mesa_uniform_matrix(ctx
, ctx
->_Shader
->ActiveProgram
,
734 4, 2, location
, count
, transpose
, value
);
738 _mesa_UniformMatrix3x4fv(GLint location
, GLsizei count
, GLboolean transpose
,
739 const GLfloat
*value
)
741 GET_CURRENT_CONTEXT(ctx
);
742 _mesa_uniform_matrix(ctx
, ctx
->_Shader
->ActiveProgram
,
743 3, 4, location
, count
, transpose
, value
);
747 _mesa_UniformMatrix4x3fv(GLint location
, GLsizei count
, GLboolean transpose
,
748 const GLfloat
*value
)
750 GET_CURRENT_CONTEXT(ctx
);
751 _mesa_uniform_matrix(ctx
, ctx
->_Shader
->ActiveProgram
,
752 4, 3, location
, count
, transpose
, value
);
755 /** Same as above with direct state access **/
758 _mesa_ProgramUniformMatrix2x3fv(GLuint program
, GLint location
, GLsizei count
,
759 GLboolean transpose
, const GLfloat
* value
)
761 GET_CURRENT_CONTEXT(ctx
);
762 struct gl_shader_program
*shProg
=
763 _mesa_lookup_shader_program_err(ctx
, program
,
764 "glProgramUniformMatrix2x3fv");
765 _mesa_uniform_matrix(ctx
, shProg
, 2, 3, location
, count
, transpose
, value
);
769 _mesa_ProgramUniformMatrix3x2fv(GLuint program
, GLint location
, GLsizei count
,
770 GLboolean transpose
, const GLfloat
* value
)
772 GET_CURRENT_CONTEXT(ctx
);
773 struct gl_shader_program
*shProg
=
774 _mesa_lookup_shader_program_err(ctx
, program
,
775 "glProgramUniformMatrix3x2fv");
776 _mesa_uniform_matrix(ctx
, shProg
, 3, 2, location
, count
, transpose
, value
);
780 _mesa_ProgramUniformMatrix2x4fv(GLuint program
, GLint location
, GLsizei count
,
781 GLboolean transpose
, const GLfloat
* value
)
783 GET_CURRENT_CONTEXT(ctx
);
784 struct gl_shader_program
*shProg
=
785 _mesa_lookup_shader_program_err(ctx
, program
,
786 "glProgramUniformMatrix2x4fv");
787 _mesa_uniform_matrix(ctx
, shProg
, 2, 4, location
, count
, transpose
, value
);
791 _mesa_ProgramUniformMatrix4x2fv(GLuint program
, GLint location
, GLsizei count
,
792 GLboolean transpose
, const GLfloat
* value
)
794 GET_CURRENT_CONTEXT(ctx
);
795 struct gl_shader_program
*shProg
=
796 _mesa_lookup_shader_program_err(ctx
, program
,
797 "glProgramUniformMatrix4x2fv");
798 _mesa_uniform_matrix(ctx
, shProg
, 4, 2, location
, count
, transpose
, value
);
802 _mesa_ProgramUniformMatrix3x4fv(GLuint program
, GLint location
, GLsizei count
,
803 GLboolean transpose
, const GLfloat
* value
)
805 GET_CURRENT_CONTEXT(ctx
);
806 struct gl_shader_program
*shProg
=
807 _mesa_lookup_shader_program_err(ctx
, program
,
808 "glProgramUniformMatrix3x4fv");
809 _mesa_uniform_matrix(ctx
, shProg
, 3, 4, location
, count
, transpose
, value
);
813 _mesa_ProgramUniformMatrix4x3fv(GLuint program
, GLint location
, GLsizei count
,
814 GLboolean transpose
, const GLfloat
* value
)
816 GET_CURRENT_CONTEXT(ctx
);
817 struct gl_shader_program
*shProg
=
818 _mesa_lookup_shader_program_err(ctx
, program
,
819 "glProgramUniformMatrix4x3fv");
820 _mesa_uniform_matrix(ctx
, shProg
, 4, 3, location
, count
, transpose
, value
);
825 _mesa_GetnUniformfvARB(GLuint program
, GLint location
,
826 GLsizei bufSize
, GLfloat
*params
)
828 GET_CURRENT_CONTEXT(ctx
);
829 _mesa_get_uniform(ctx
, program
, location
, bufSize
, GLSL_TYPE_FLOAT
, params
);
833 _mesa_GetUniformfv(GLuint program
, GLint location
, GLfloat
*params
)
835 _mesa_GetnUniformfvARB(program
, location
, INT_MAX
, params
);
840 _mesa_GetnUniformivARB(GLuint program
, GLint location
,
841 GLsizei bufSize
, GLint
*params
)
843 GET_CURRENT_CONTEXT(ctx
);
844 _mesa_get_uniform(ctx
, program
, location
, bufSize
, GLSL_TYPE_INT
, params
);
848 _mesa_GetUniformiv(GLuint program
, GLint location
, GLint
*params
)
850 _mesa_GetnUniformivARB(program
, location
, INT_MAX
, params
);
856 _mesa_GetnUniformuivARB(GLuint program
, GLint location
,
857 GLsizei bufSize
, GLuint
*params
)
859 GET_CURRENT_CONTEXT(ctx
);
860 _mesa_get_uniform(ctx
, program
, location
, bufSize
, GLSL_TYPE_UINT
, params
);
864 _mesa_GetUniformuiv(GLuint program
, GLint location
, GLuint
*params
)
866 _mesa_GetnUniformuivARB(program
, location
, INT_MAX
, params
);
872 _mesa_GetnUniformdvARB(GLuint program
, GLint location
,
873 GLsizei bufSize
, GLdouble
*params
)
875 GET_CURRENT_CONTEXT(ctx
);
883 _mesa_get_uniform(ctx, program, location, bufSize, GLSL_TYPE_DOUBLE, params);
885 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetUniformdvARB"
886 "(GL_ARB_gpu_shader_fp64 not implemented)");
890 _mesa_GetUniformdv(GLuint program
, GLint location
, GLdouble
*params
)
892 _mesa_GetnUniformdvARB(program
, location
, INT_MAX
, params
);
897 _mesa_GetUniformLocation(GLuint programObj
, const GLcharARB
*name
)
899 struct gl_shader_program
*shProg
;
900 GLuint index
, offset
;
902 GET_CURRENT_CONTEXT(ctx
);
904 shProg
= _mesa_lookup_shader_program_err(ctx
, programObj
,
905 "glGetUniformLocation");
909 /* Page 80 (page 94 of the PDF) of the OpenGL 2.1 spec says:
911 * "If program has not been successfully linked, the error
912 * INVALID_OPERATION is generated."
914 if (shProg
->LinkStatus
== GL_FALSE
) {
915 _mesa_error(ctx
, GL_INVALID_OPERATION
,
916 "glGetUniformLocation(program not linked)");
920 index
= _mesa_get_uniform_location(ctx
, shProg
, name
, &offset
);
921 if (index
== GL_INVALID_INDEX
)
924 /* From the GL_ARB_uniform_buffer_object spec:
926 * "The value -1 will be returned if <name> does not correspond to an
927 * active uniform variable name in <program>, if <name> is associated
928 * with a named uniform block, or if <name> starts with the reserved
931 if (shProg
->UniformStorage
[index
].block_index
!= -1 ||
932 shProg
->UniformStorage
[index
].atomic_buffer_index
!= -1)
935 /* location in remap table + array element offset */
936 return shProg
->UniformStorage
[index
].remap_location
+ offset
;
940 _mesa_GetUniformBlockIndex(GLuint program
,
941 const GLchar
*uniformBlockName
)
943 GET_CURRENT_CONTEXT(ctx
);
945 struct gl_shader_program
*shProg
;
947 if (!ctx
->Extensions
.ARB_uniform_buffer_object
) {
948 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetUniformBlockIndex");
949 return GL_INVALID_INDEX
;
952 shProg
= _mesa_lookup_shader_program_err(ctx
, program
,
953 "glGetUniformBlockIndex");
955 return GL_INVALID_INDEX
;
957 for (i
= 0; i
< shProg
->NumUniformBlocks
; i
++) {
958 if (!strcmp(shProg
->UniformBlocks
[i
].Name
, uniformBlockName
))
962 return GL_INVALID_INDEX
;
966 _mesa_GetUniformIndices(GLuint program
,
967 GLsizei uniformCount
,
968 const GLchar
* const *uniformNames
,
969 GLuint
*uniformIndices
)
971 GET_CURRENT_CONTEXT(ctx
);
973 struct gl_shader_program
*shProg
;
975 if (!ctx
->Extensions
.ARB_uniform_buffer_object
) {
976 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetUniformIndices");
980 shProg
= _mesa_lookup_shader_program_err(ctx
, program
,
981 "glGetUniformIndices");
985 if (uniformCount
< 0) {
986 _mesa_error(ctx
, GL_INVALID_VALUE
,
987 "glGetUniformIndices(uniformCount < 0)");
991 for (i
= 0; i
< uniformCount
; i
++) {
993 uniformIndices
[i
] = _mesa_get_uniform_location(ctx
, shProg
,
994 uniformNames
[i
], &offset
);
999 _mesa_UniformBlockBinding(GLuint program
,
1000 GLuint uniformBlockIndex
,
1001 GLuint uniformBlockBinding
)
1003 GET_CURRENT_CONTEXT(ctx
);
1004 struct gl_shader_program
*shProg
;
1006 if (!ctx
->Extensions
.ARB_uniform_buffer_object
) {
1007 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glUniformBlockBinding");
1011 shProg
= _mesa_lookup_shader_program_err(ctx
, program
,
1012 "glUniformBlockBinding");
1016 if (uniformBlockIndex
>= shProg
->NumUniformBlocks
) {
1017 _mesa_error(ctx
, GL_INVALID_VALUE
,
1018 "glUniformBlockBinding(block index %u >= %u)",
1019 uniformBlockIndex
, shProg
->NumUniformBlocks
);
1023 if (uniformBlockBinding
>= ctx
->Const
.MaxUniformBufferBindings
) {
1024 _mesa_error(ctx
, GL_INVALID_VALUE
,
1025 "glUniformBlockBinding(block binding %u >= %u)",
1026 uniformBlockBinding
, ctx
->Const
.MaxUniformBufferBindings
);
1030 if (shProg
->UniformBlocks
[uniformBlockIndex
].Binding
!=
1031 uniformBlockBinding
) {
1034 FLUSH_VERTICES(ctx
, 0);
1035 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewUniformBuffer
;
1037 shProg
->UniformBlocks
[uniformBlockIndex
].Binding
= uniformBlockBinding
;
1039 for (i
= 0; i
< MESA_SHADER_STAGES
; i
++) {
1040 int stage_index
= shProg
->UniformBlockStageIndex
[i
][uniformBlockIndex
];
1042 if (stage_index
!= -1) {
1043 struct gl_shader
*sh
= shProg
->_LinkedShaders
[i
];
1044 sh
->UniformBlocks
[stage_index
].Binding
= uniformBlockBinding
;
1051 _mesa_GetActiveUniformBlockiv(GLuint program
,
1052 GLuint uniformBlockIndex
,
1056 GET_CURRENT_CONTEXT(ctx
);
1057 struct gl_shader_program
*shProg
;
1058 struct gl_uniform_block
*block
;
1061 if (!ctx
->Extensions
.ARB_uniform_buffer_object
) {
1062 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetActiveUniformBlockiv");
1066 shProg
= _mesa_lookup_shader_program_err(ctx
, program
,
1067 "glGetActiveUniformBlockiv");
1071 if (uniformBlockIndex
>= shProg
->NumUniformBlocks
) {
1072 _mesa_error(ctx
, GL_INVALID_VALUE
,
1073 "glGetActiveUniformBlockiv(block index %u >= %u)",
1074 uniformBlockIndex
, shProg
->NumUniformBlocks
);
1078 block
= &shProg
->UniformBlocks
[uniformBlockIndex
];
1081 case GL_UNIFORM_BLOCK_BINDING
:
1082 params
[0] = block
->Binding
;
1085 case GL_UNIFORM_BLOCK_DATA_SIZE
:
1086 params
[0] = block
->UniformBufferSize
;
1089 case GL_UNIFORM_BLOCK_NAME_LENGTH
:
1090 params
[0] = strlen(block
->Name
) + 1;
1093 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS
: {
1096 for (i
= 0; i
< block
->NumUniforms
; i
++) {
1099 _mesa_get_uniform_location(ctx
, shProg
,
1100 block
->Uniforms
[i
].IndexName
,
1110 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES
: {
1113 for (i
= 0; i
< block
->NumUniforms
; i
++) {
1116 _mesa_get_uniform_location(ctx
, shProg
,
1117 block
->Uniforms
[i
].IndexName
,
1121 params
[count
++] = idx
;
1126 case GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER
:
1127 params
[0] = shProg
->UniformBlockStageIndex
[MESA_SHADER_VERTEX
][uniformBlockIndex
] != -1;
1130 case GL_UNIFORM_BLOCK_REFERENCED_BY_GEOMETRY_SHADER
:
1131 params
[0] = shProg
->UniformBlockStageIndex
[MESA_SHADER_GEOMETRY
][uniformBlockIndex
] != -1;
1134 case GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER
:
1135 params
[0] = shProg
->UniformBlockStageIndex
[MESA_SHADER_FRAGMENT
][uniformBlockIndex
] != -1;
1139 _mesa_error(ctx
, GL_INVALID_ENUM
,
1140 "glGetActiveUniformBlockiv(pname 0x%x (%s))",
1141 pname
, _mesa_lookup_enum_by_nr(pname
));
1147 _mesa_GetActiveUniformBlockName(GLuint program
,
1148 GLuint uniformBlockIndex
,
1151 GLchar
*uniformBlockName
)
1153 GET_CURRENT_CONTEXT(ctx
);
1154 struct gl_shader_program
*shProg
;
1155 struct gl_uniform_block
*block
;
1157 if (!ctx
->Extensions
.ARB_uniform_buffer_object
) {
1158 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetActiveUniformBlockiv");
1163 _mesa_error(ctx
, GL_INVALID_VALUE
,
1164 "glGetActiveUniformBlockName(bufSize %d < 0)",
1169 shProg
= _mesa_lookup_shader_program_err(ctx
, program
,
1170 "glGetActiveUniformBlockiv");
1174 if (uniformBlockIndex
>= shProg
->NumUniformBlocks
) {
1175 _mesa_error(ctx
, GL_INVALID_VALUE
,
1176 "glGetActiveUniformBlockiv(block index %u >= %u)",
1177 uniformBlockIndex
, shProg
->NumUniformBlocks
);
1181 block
= &shProg
->UniformBlocks
[uniformBlockIndex
];
1183 if (uniformBlockName
) {
1184 _mesa_copy_string(uniformBlockName
, bufSize
, length
, block
->Name
);
1189 _mesa_GetActiveUniformName(GLuint program
, GLuint uniformIndex
,
1190 GLsizei bufSize
, GLsizei
*length
,
1191 GLchar
*uniformName
)
1193 GET_CURRENT_CONTEXT(ctx
);
1194 struct gl_shader_program
*shProg
;
1196 if (!ctx
->Extensions
.ARB_uniform_buffer_object
) {
1197 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetActiveUniformBlockiv");
1202 _mesa_error(ctx
, GL_INVALID_VALUE
,
1203 "glGetActiveUniformName(bufSize %d < 0)",
1208 shProg
= _mesa_lookup_shader_program_err(ctx
, program
, "glGetActiveUniformName");
1213 if (uniformIndex
>= shProg
->NumUserUniformStorage
) {
1214 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetActiveUniform(index)");
1219 _mesa_get_uniform_name(& shProg
->UniformStorage
[uniformIndex
],
1220 bufSize
, length
, uniformName
);
1225 _mesa_get_uniform_name(const struct gl_uniform_storage
*uni
,
1226 GLsizei maxLength
, GLsizei
*length
,
1229 GLsizei localLength
;
1232 length
= &localLength
;
1234 _mesa_copy_string(nameOut
, maxLength
, length
, uni
->name
);
1236 /* Page 61 (page 73 of the PDF) in section 2.11 of the OpenGL ES 3.0
1239 * "If the active uniform is an array, the uniform name returned in
1240 * name will always be the name of the uniform array appended with
1243 * The same text also appears in the OpenGL 4.2 spec. It does not,
1244 * however, appear in any previous spec. Previous specifications are
1245 * ambiguous in this regard. However, either name can later be passed
1246 * to glGetUniformLocation (and related APIs), so there shouldn't be any
1247 * harm in always appending "[0]" to uniform array names.
1249 if (uni
->array_elements
!= 0) {
1252 /* The comparison is strange because *length does *NOT* include the
1253 * terminating NUL, but maxLength does.
1255 for (i
= 0; i
< 3 && (*length
+ i
+ 1) < maxLength
; i
++)
1256 nameOut
[*length
+ i
] = "[0]"[i
];
1258 nameOut
[*length
+ i
] = '\0';
1264 _mesa_GetActiveAtomicCounterBufferiv(GLuint program
, GLuint bufferIndex
,
1265 GLenum pname
, GLint
*params
)
1267 GET_CURRENT_CONTEXT(ctx
);
1268 struct gl_shader_program
*shProg
;
1269 struct gl_active_atomic_buffer
*ab
;
1272 if (!ctx
->Extensions
.ARB_shader_atomic_counters
) {
1273 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1274 "glGetActiveAtomicCounterBufferiv");
1278 shProg
= _mesa_lookup_shader_program_err(ctx
, program
,
1279 "glGetActiveAtomicCounterBufferiv");
1283 if (bufferIndex
>= shProg
->NumAtomicBuffers
) {
1284 _mesa_error(ctx
, GL_INVALID_VALUE
,
1285 "glGetActiveAtomicCounterBufferiv(bufferIndex)");
1289 ab
= &shProg
->AtomicBuffers
[bufferIndex
];
1292 case GL_ATOMIC_COUNTER_BUFFER_BINDING
:
1293 params
[0] = ab
->Binding
;
1295 case GL_ATOMIC_COUNTER_BUFFER_DATA_SIZE
:
1296 params
[0] = ab
->MinimumSize
;
1298 case GL_ATOMIC_COUNTER_BUFFER_ACTIVE_ATOMIC_COUNTERS
:
1299 params
[0] = ab
->NumUniforms
;
1301 case GL_ATOMIC_COUNTER_BUFFER_ACTIVE_ATOMIC_COUNTER_INDICES
:
1302 for (i
= 0; i
< ab
->NumUniforms
; ++i
)
1303 params
[i
] = ab
->Uniforms
[i
];
1305 case GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_VERTEX_SHADER
:
1306 params
[0] = ab
->StageReferences
[MESA_SHADER_VERTEX
];
1308 case GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_GEOMETRY_SHADER
:
1309 params
[0] = ab
->StageReferences
[MESA_SHADER_GEOMETRY
];
1311 case GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_FRAGMENT_SHADER
:
1312 params
[0] = ab
->StageReferences
[MESA_SHADER_FRAGMENT
];
1314 case GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_TESS_CONTROL_SHADER
:
1315 params
[0] = GL_FALSE
;
1317 case GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_TESS_EVALUATION_SHADER
:
1318 params
[0] = GL_FALSE
;
1321 _mesa_error(ctx
, GL_INVALID_ENUM
,
1322 "glGetActiveAtomicCounterBufferiv(pname 0x%x (%s))",
1323 pname
, _mesa_lookup_enum_by_nr(pname
));