mesa: fix and simplify resource query for arrays
[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 * 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.
25 */
26
27 /**
28 * \file uniforms.c
29 * Functions related to GLSL uniform variables.
30 * \author Brian Paul
31 */
32
33 /**
34 * XXX things to do:
35 * 1. Check that the right error code is generated for all _mesa_error() calls.
36 * 2. Insert FLUSH_VERTICES calls in various places
37 */
38
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"
49
50 /**
51 * Update the vertex/fragment program's TexturesUsed array.
52 *
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.
58 *
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.
64 */
65 void
66 _mesa_update_shader_textures_used(struct gl_shader_program *shProg,
67 struct gl_program *prog)
68 {
69 GLuint s;
70 struct gl_shader *shader =
71 shProg->_LinkedShaders[_mesa_program_enum_to_shader_stage(prog->Target)];
72
73 assert(shader);
74
75 memcpy(prog->SamplerUnits, shader->SamplerUnits, sizeof(prog->SamplerUnits));
76 memset(prog->TexturesUsed, 0, sizeof(prog->TexturesUsed));
77
78 shProg->SamplersValidated = GL_TRUE;
79
80 for (s = 0; s < MAX_SAMPLERS; s++) {
81 if (prog->SamplersUsed & (1 << s)) {
82 GLuint unit = shader->SamplerUnits[s];
83 GLuint tgt = shader->SamplerTargets[s];
84 assert(unit < ARRAY_SIZE(prog->TexturesUsed));
85 assert(tgt < NUM_TEXTURE_TARGETS);
86
87 /* The types of the samplers associated with a particular texture
88 * unit must be an exact match. Page 74 (page 89 of the PDF) of the
89 * OpenGL 3.3 core spec says:
90 *
91 * "It is not allowed to have variables of different sampler
92 * types pointing to the same texture image unit within a program
93 * object."
94 */
95 if (prog->TexturesUsed[unit] & ~(1 << tgt))
96 shProg->SamplersValidated = GL_FALSE;
97
98 prog->TexturesUsed[unit] |= (1 << tgt);
99 }
100 }
101 }
102
103 /**
104 * Connect a piece of driver storage with a part of a uniform
105 *
106 * \param uni The uniform with which the storage will be associated
107 * \param element_stride Byte-stride between array elements.
108 * \sa gl_uniform_driver_storage::element_stride.
109 * \param vector_stride Byte-stride between vectors (in a matrix).
110 * \sa gl_uniform_driver_storage::vector_stride.
111 * \param format Conversion from native format to driver format
112 * required by the driver.
113 * \param data Location to dump the data.
114 */
115 void
116 _mesa_uniform_attach_driver_storage(struct gl_uniform_storage *uni,
117 unsigned element_stride,
118 unsigned vector_stride,
119 enum gl_uniform_driver_format format,
120 void *data)
121 {
122 uni->driver_storage =
123 realloc(uni->driver_storage,
124 sizeof(struct gl_uniform_driver_storage)
125 * (uni->num_driver_storage + 1));
126
127 uni->driver_storage[uni->num_driver_storage].element_stride = element_stride;
128 uni->driver_storage[uni->num_driver_storage].vector_stride = vector_stride;
129 uni->driver_storage[uni->num_driver_storage].format = format;
130 uni->driver_storage[uni->num_driver_storage].data = data;
131
132 uni->num_driver_storage++;
133 }
134
135 /**
136 * Sever all connections with all pieces of driver storage for all uniforms
137 *
138 * \warning
139 * This function does \b not release any of the \c data pointers
140 * previously passed in to \c _mesa_uniform_attach_driver_stoarge.
141 */
142 void
143 _mesa_uniform_detach_all_driver_storage(struct gl_uniform_storage *uni)
144 {
145 free(uni->driver_storage);
146 uni->driver_storage = NULL;
147 uni->num_driver_storage = 0;
148 }
149
150 void GLAPIENTRY
151 _mesa_Uniform1f(GLint location, GLfloat v0)
152 {
153 GET_CURRENT_CONTEXT(ctx);
154 _mesa_uniform(ctx, ctx->_Shader->ActiveProgram, location, 1, &v0, GLSL_TYPE_FLOAT, 1);
155 }
156
157 void GLAPIENTRY
158 _mesa_Uniform2f(GLint location, GLfloat v0, GLfloat v1)
159 {
160 GET_CURRENT_CONTEXT(ctx);
161 GLfloat v[2];
162 v[0] = v0;
163 v[1] = v1;
164 _mesa_uniform(ctx, ctx->_Shader->ActiveProgram, location, 1, v, GLSL_TYPE_FLOAT, 2);
165 }
166
167 void GLAPIENTRY
168 _mesa_Uniform3f(GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
169 {
170 GET_CURRENT_CONTEXT(ctx);
171 GLfloat v[3];
172 v[0] = v0;
173 v[1] = v1;
174 v[2] = v2;
175 _mesa_uniform(ctx, ctx->_Shader->ActiveProgram, location, 1, v, GLSL_TYPE_FLOAT, 3);
176 }
177
178 void GLAPIENTRY
179 _mesa_Uniform4f(GLint location, GLfloat v0, GLfloat v1, GLfloat v2,
180 GLfloat v3)
181 {
182 GET_CURRENT_CONTEXT(ctx);
183 GLfloat v[4];
184 v[0] = v0;
185 v[1] = v1;
186 v[2] = v2;
187 v[3] = v3;
188 _mesa_uniform(ctx, ctx->_Shader->ActiveProgram, location, 1, v, GLSL_TYPE_FLOAT, 4);
189 }
190
191 void GLAPIENTRY
192 _mesa_Uniform1i(GLint location, GLint v0)
193 {
194 GET_CURRENT_CONTEXT(ctx);
195 _mesa_uniform(ctx, ctx->_Shader->ActiveProgram, location, 1, &v0, GLSL_TYPE_INT, 1);
196 }
197
198 void GLAPIENTRY
199 _mesa_Uniform2i(GLint location, GLint v0, GLint v1)
200 {
201 GET_CURRENT_CONTEXT(ctx);
202 GLint v[2];
203 v[0] = v0;
204 v[1] = v1;
205 _mesa_uniform(ctx, ctx->_Shader->ActiveProgram, location, 1, v, GLSL_TYPE_INT, 2);
206 }
207
208 void GLAPIENTRY
209 _mesa_Uniform3i(GLint location, GLint v0, GLint v1, GLint v2)
210 {
211 GET_CURRENT_CONTEXT(ctx);
212 GLint v[3];
213 v[0] = v0;
214 v[1] = v1;
215 v[2] = v2;
216 _mesa_uniform(ctx, ctx->_Shader->ActiveProgram, location, 1, v, GLSL_TYPE_INT, 3);
217 }
218
219 void GLAPIENTRY
220 _mesa_Uniform4i(GLint location, GLint v0, GLint v1, GLint v2, GLint v3)
221 {
222 GET_CURRENT_CONTEXT(ctx);
223 GLint v[4];
224 v[0] = v0;
225 v[1] = v1;
226 v[2] = v2;
227 v[3] = v3;
228 _mesa_uniform(ctx, ctx->_Shader->ActiveProgram, location, 1, v, GLSL_TYPE_INT, 4);
229 }
230
231 void GLAPIENTRY
232 _mesa_Uniform1fv(GLint location, GLsizei count, const GLfloat * value)
233 {
234 GET_CURRENT_CONTEXT(ctx);
235 _mesa_uniform(ctx, ctx->_Shader->ActiveProgram, location, count, value, GLSL_TYPE_FLOAT, 1);
236 }
237
238 void GLAPIENTRY
239 _mesa_Uniform2fv(GLint location, GLsizei count, const GLfloat * value)
240 {
241 GET_CURRENT_CONTEXT(ctx);
242 _mesa_uniform(ctx, ctx->_Shader->ActiveProgram, location, count, value, GLSL_TYPE_FLOAT, 2);
243 }
244
245 void GLAPIENTRY
246 _mesa_Uniform3fv(GLint location, GLsizei count, const GLfloat * value)
247 {
248 GET_CURRENT_CONTEXT(ctx);
249 _mesa_uniform(ctx, ctx->_Shader->ActiveProgram, location, count, value, GLSL_TYPE_FLOAT, 3);
250 }
251
252 void GLAPIENTRY
253 _mesa_Uniform4fv(GLint location, GLsizei count, const GLfloat * value)
254 {
255 GET_CURRENT_CONTEXT(ctx);
256 _mesa_uniform(ctx, ctx->_Shader->ActiveProgram, location, count, value, GLSL_TYPE_FLOAT, 4);
257 }
258
259 void GLAPIENTRY
260 _mesa_Uniform1iv(GLint location, GLsizei count, const GLint * value)
261 {
262 GET_CURRENT_CONTEXT(ctx);
263 _mesa_uniform(ctx, ctx->_Shader->ActiveProgram, location, count, value, GLSL_TYPE_INT, 1);
264 }
265
266 void GLAPIENTRY
267 _mesa_Uniform2iv(GLint location, GLsizei count, const GLint * value)
268 {
269 GET_CURRENT_CONTEXT(ctx);
270 _mesa_uniform(ctx, ctx->_Shader->ActiveProgram, location, count, value, GLSL_TYPE_INT, 2);
271 }
272
273 void GLAPIENTRY
274 _mesa_Uniform3iv(GLint location, GLsizei count, const GLint * value)
275 {
276 GET_CURRENT_CONTEXT(ctx);
277 _mesa_uniform(ctx, ctx->_Shader->ActiveProgram, location, count, value, GLSL_TYPE_INT, 3);
278 }
279
280 void GLAPIENTRY
281 _mesa_Uniform4iv(GLint location, GLsizei count, const GLint * value)
282 {
283 GET_CURRENT_CONTEXT(ctx);
284 _mesa_uniform(ctx, ctx->_Shader->ActiveProgram, location, count, value, GLSL_TYPE_INT, 4);
285 }
286
287 /** Same as above with direct state access **/
288 void GLAPIENTRY
289 _mesa_ProgramUniform1f(GLuint program, GLint location, GLfloat v0)
290 {
291 GET_CURRENT_CONTEXT(ctx);
292 struct gl_shader_program *shProg =
293 _mesa_lookup_shader_program_err(ctx, program,
294 "glProgramUniform1f");
295 _mesa_uniform(ctx, shProg, location, 1, &v0, GLSL_TYPE_FLOAT, 1);
296 }
297
298 void GLAPIENTRY
299 _mesa_ProgramUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1)
300 {
301 GET_CURRENT_CONTEXT(ctx);
302 GLfloat v[2];
303 struct gl_shader_program *shProg;
304 v[0] = v0;
305 v[1] = v1;
306 shProg = _mesa_lookup_shader_program_err(ctx, program, "glProgramUniform2f");
307 _mesa_uniform(ctx, shProg, location, 1, v, GLSL_TYPE_FLOAT, 2);
308 }
309
310 void GLAPIENTRY
311 _mesa_ProgramUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1,
312 GLfloat v2)
313 {
314 GET_CURRENT_CONTEXT(ctx);
315 GLfloat v[3];
316 struct gl_shader_program *shProg;
317 v[0] = v0;
318 v[1] = v1;
319 v[2] = v2;
320 shProg = _mesa_lookup_shader_program_err(ctx, program, "glProgramUniform3f");
321 _mesa_uniform(ctx, shProg, location, 1, v, GLSL_TYPE_FLOAT, 3);
322 }
323
324 void GLAPIENTRY
325 _mesa_ProgramUniform4f(GLuint program, GLint location, GLfloat v0, GLfloat v1,
326 GLfloat v2, GLfloat v3)
327 {
328 GET_CURRENT_CONTEXT(ctx);
329 GLfloat v[4];
330 struct gl_shader_program *shProg;
331 v[0] = v0;
332 v[1] = v1;
333 v[2] = v2;
334 v[3] = v3;
335 shProg = _mesa_lookup_shader_program_err(ctx, program, "glProgramUniform4f");
336 _mesa_uniform(ctx, shProg, location, 1, v, GLSL_TYPE_FLOAT, 4);
337 }
338
339 void GLAPIENTRY
340 _mesa_ProgramUniform1i(GLuint program, GLint location, GLint v0)
341 {
342 GET_CURRENT_CONTEXT(ctx);
343 struct gl_shader_program *shProg =
344 _mesa_lookup_shader_program_err(ctx, program,
345 "glProgramUniform1i");
346 _mesa_uniform(ctx, shProg, location, 1, &v0, GLSL_TYPE_INT, 1);
347 }
348
349 void GLAPIENTRY
350 _mesa_ProgramUniform2i(GLuint program, GLint location, GLint v0, GLint v1)
351 {
352 GET_CURRENT_CONTEXT(ctx);
353 GLint v[2];
354 struct gl_shader_program *shProg;
355 v[0] = v0;
356 v[1] = v1;
357 shProg = _mesa_lookup_shader_program_err(ctx, program, "glProgramUniform2i");
358 _mesa_uniform(ctx, shProg, location, 1, v, GLSL_TYPE_INT, 2);
359 }
360
361 void GLAPIENTRY
362 _mesa_ProgramUniform3i(GLuint program, GLint location, GLint v0, GLint v1,
363 GLint v2)
364 {
365 GET_CURRENT_CONTEXT(ctx);
366 GLint v[3];
367 struct gl_shader_program *shProg;
368 v[0] = v0;
369 v[1] = v1;
370 v[2] = v2;
371 shProg = _mesa_lookup_shader_program_err(ctx, program, "glProgramUniform3i");
372 _mesa_uniform(ctx, shProg, location, 1, v, GLSL_TYPE_INT, 3);
373 }
374
375 void GLAPIENTRY
376 _mesa_ProgramUniform4i(GLuint program, GLint location, GLint v0, GLint v1,
377 GLint v2, GLint v3)
378 {
379 GET_CURRENT_CONTEXT(ctx);
380 GLint v[4];
381 struct gl_shader_program *shProg;
382 v[0] = v0;
383 v[1] = v1;
384 v[2] = v2;
385 v[3] = v3;
386 shProg = _mesa_lookup_shader_program_err(ctx, program, "glProgramUniform4i");
387 _mesa_uniform(ctx, shProg, location, 1, v, GLSL_TYPE_INT, 4);
388 }
389
390 void GLAPIENTRY
391 _mesa_ProgramUniform1fv(GLuint program, GLint location, GLsizei count,
392 const GLfloat * value)
393 {
394 GET_CURRENT_CONTEXT(ctx);
395 struct gl_shader_program *shProg =
396 _mesa_lookup_shader_program_err(ctx, program,
397 "glProgramUniform1fv");
398 _mesa_uniform(ctx, shProg, location, count, value, GLSL_TYPE_FLOAT, 1);
399 }
400
401 void GLAPIENTRY
402 _mesa_ProgramUniform2fv(GLuint program, GLint location, GLsizei count,
403 const GLfloat * value)
404 {
405 GET_CURRENT_CONTEXT(ctx);
406 struct gl_shader_program *shProg =
407 _mesa_lookup_shader_program_err(ctx, program,
408 "glProgramUniform2fv");
409 _mesa_uniform(ctx, shProg, location, count, value, GLSL_TYPE_FLOAT, 2);
410 }
411
412 void GLAPIENTRY
413 _mesa_ProgramUniform3fv(GLuint program, GLint location, GLsizei count,
414 const GLfloat * value)
415 {
416 GET_CURRENT_CONTEXT(ctx);
417 struct gl_shader_program *shProg =
418 _mesa_lookup_shader_program_err(ctx, program,
419 "glProgramUniform3fv");
420 _mesa_uniform(ctx, shProg, location, count, value, GLSL_TYPE_FLOAT, 3);
421 }
422
423 void GLAPIENTRY
424 _mesa_ProgramUniform4fv(GLuint program, GLint location, GLsizei count,
425 const GLfloat * value)
426 {
427 GET_CURRENT_CONTEXT(ctx);
428 struct gl_shader_program *shProg =
429 _mesa_lookup_shader_program_err(ctx, program,
430 "glProgramUniform4fv");
431 _mesa_uniform(ctx, shProg, location, count, value, GLSL_TYPE_FLOAT, 4);
432 }
433
434 void GLAPIENTRY
435 _mesa_ProgramUniform1iv(GLuint program, GLint location, GLsizei count,
436 const GLint * value)
437 {
438 GET_CURRENT_CONTEXT(ctx);
439 struct gl_shader_program *shProg =
440 _mesa_lookup_shader_program_err(ctx, program,
441 "glProgramUniform1iv");
442 _mesa_uniform(ctx, shProg, location, count, value, GLSL_TYPE_INT, 1);
443 }
444
445 void GLAPIENTRY
446 _mesa_ProgramUniform2iv(GLuint program, GLint location, GLsizei count,
447 const GLint * value)
448 {
449 GET_CURRENT_CONTEXT(ctx);
450 struct gl_shader_program *shProg =
451 _mesa_lookup_shader_program_err(ctx, program,
452 "glProgramUniform2iv");
453 _mesa_uniform(ctx, shProg, location, count, value, GLSL_TYPE_INT, 2);
454 }
455
456 void GLAPIENTRY
457 _mesa_ProgramUniform3iv(GLuint program, GLint location, GLsizei count,
458 const GLint * value)
459 {
460 GET_CURRENT_CONTEXT(ctx);
461 struct gl_shader_program *shProg =
462 _mesa_lookup_shader_program_err(ctx, program,
463 "glProgramUniform3iv");
464 _mesa_uniform(ctx, shProg, location, count, value, GLSL_TYPE_INT, 3);
465 }
466
467 void GLAPIENTRY
468 _mesa_ProgramUniform4iv(GLuint program, GLint location, GLsizei count,
469 const GLint * value)
470 {
471 GET_CURRENT_CONTEXT(ctx);
472 struct gl_shader_program *shProg =
473 _mesa_lookup_shader_program_err(ctx, program,
474 "glProgramUniform4iv");
475 _mesa_uniform(ctx, shProg, location, count, value, GLSL_TYPE_INT, 4);
476 }
477
478
479 /** OpenGL 3.0 GLuint-valued functions **/
480 void GLAPIENTRY
481 _mesa_Uniform1ui(GLint location, GLuint v0)
482 {
483 GET_CURRENT_CONTEXT(ctx);
484 _mesa_uniform(ctx, ctx->_Shader->ActiveProgram, location, 1, &v0, GLSL_TYPE_UINT, 1);
485 }
486
487 void GLAPIENTRY
488 _mesa_Uniform2ui(GLint location, GLuint v0, GLuint v1)
489 {
490 GET_CURRENT_CONTEXT(ctx);
491 GLuint v[2];
492 v[0] = v0;
493 v[1] = v1;
494 _mesa_uniform(ctx, ctx->_Shader->ActiveProgram, location, 1, v, GLSL_TYPE_UINT, 2);
495 }
496
497 void GLAPIENTRY
498 _mesa_Uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
499 {
500 GET_CURRENT_CONTEXT(ctx);
501 GLuint v[3];
502 v[0] = v0;
503 v[1] = v1;
504 v[2] = v2;
505 _mesa_uniform(ctx, ctx->_Shader->ActiveProgram, location, 1, v, GLSL_TYPE_UINT, 3);
506 }
507
508 void GLAPIENTRY
509 _mesa_Uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
510 {
511 GET_CURRENT_CONTEXT(ctx);
512 GLuint v[4];
513 v[0] = v0;
514 v[1] = v1;
515 v[2] = v2;
516 v[3] = v3;
517 _mesa_uniform(ctx, ctx->_Shader->ActiveProgram, location, 1, v, GLSL_TYPE_UINT, 4);
518 }
519
520 void GLAPIENTRY
521 _mesa_Uniform1uiv(GLint location, GLsizei count, const GLuint *value)
522 {
523 GET_CURRENT_CONTEXT(ctx);
524 _mesa_uniform(ctx, ctx->_Shader->ActiveProgram, location, count, value, GLSL_TYPE_UINT, 1);
525 }
526
527 void GLAPIENTRY
528 _mesa_Uniform2uiv(GLint location, GLsizei count, const GLuint *value)
529 {
530 GET_CURRENT_CONTEXT(ctx);
531 _mesa_uniform(ctx, ctx->_Shader->ActiveProgram, location, count, value, GLSL_TYPE_UINT, 2);
532 }
533
534 void GLAPIENTRY
535 _mesa_Uniform3uiv(GLint location, GLsizei count, const GLuint *value)
536 {
537 GET_CURRENT_CONTEXT(ctx);
538 _mesa_uniform(ctx, ctx->_Shader->ActiveProgram, location, count, value, GLSL_TYPE_UINT, 3);
539 }
540
541 void GLAPIENTRY
542 _mesa_Uniform4uiv(GLint location, GLsizei count, const GLuint *value)
543 {
544 GET_CURRENT_CONTEXT(ctx);
545 _mesa_uniform(ctx, ctx->_Shader->ActiveProgram, location, count, value, GLSL_TYPE_UINT, 4);
546 }
547
548
549
550 void GLAPIENTRY
551 _mesa_UniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose,
552 const GLfloat * value)
553 {
554 GET_CURRENT_CONTEXT(ctx);
555 _mesa_uniform_matrix(ctx, ctx->_Shader->ActiveProgram,
556 2, 2, location, count, transpose, value, GL_FLOAT);
557 }
558
559 void GLAPIENTRY
560 _mesa_UniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose,
561 const GLfloat * value)
562 {
563 GET_CURRENT_CONTEXT(ctx);
564 _mesa_uniform_matrix(ctx, ctx->_Shader->ActiveProgram,
565 3, 3, location, count, transpose, value, GL_FLOAT);
566 }
567
568 void GLAPIENTRY
569 _mesa_UniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose,
570 const GLfloat * value)
571 {
572 GET_CURRENT_CONTEXT(ctx);
573 _mesa_uniform_matrix(ctx, ctx->_Shader->ActiveProgram,
574 4, 4, location, count, transpose, value, GL_FLOAT);
575 }
576
577 /** Same as above with direct state access **/
578
579 void GLAPIENTRY
580 _mesa_ProgramUniform1ui(GLuint program, GLint location, GLuint v0)
581 {
582 GET_CURRENT_CONTEXT(ctx);
583 struct gl_shader_program *shProg =
584 _mesa_lookup_shader_program_err(ctx, program,
585 "glProgramUniform1ui");
586 _mesa_uniform(ctx, shProg, location, 1, &v0, GLSL_TYPE_UINT, 1);
587 }
588
589 void GLAPIENTRY
590 _mesa_ProgramUniform2ui(GLuint program, GLint location, GLuint v0, GLuint v1)
591 {
592 GET_CURRENT_CONTEXT(ctx);
593 GLuint v[2];
594 struct gl_shader_program *shProg;
595 v[0] = v0;
596 v[1] = v1;
597 shProg = _mesa_lookup_shader_program_err(ctx, program,
598 "glProgramUniform2ui");
599 _mesa_uniform(ctx, shProg, location, 1, v, GLSL_TYPE_UINT, 2);
600 }
601
602 void GLAPIENTRY
603 _mesa_ProgramUniform3ui(GLuint program, GLint location, GLuint v0, GLuint v1,
604 GLuint v2)
605 {
606 GET_CURRENT_CONTEXT(ctx);
607 GLuint v[3];
608 struct gl_shader_program *shProg;
609 v[0] = v0;
610 v[1] = v1;
611 v[2] = v2;
612 shProg = _mesa_lookup_shader_program_err(ctx, program,
613 "glProgramUniform3ui");
614 _mesa_uniform(ctx, shProg, location, 1, v, GLSL_TYPE_UINT, 3);
615 }
616
617 void GLAPIENTRY
618 _mesa_ProgramUniform4ui(GLuint program, GLint location, GLuint v0, GLuint v1,
619 GLuint v2, GLuint v3)
620 {
621 GET_CURRENT_CONTEXT(ctx);
622 GLuint v[4];
623 struct gl_shader_program *shProg;
624 v[0] = v0;
625 v[1] = v1;
626 v[2] = v2;
627 v[3] = v3;
628 shProg = _mesa_lookup_shader_program_err(ctx, program, "glProgramUniform4ui");
629 _mesa_uniform(ctx, shProg, location, 1, v, GLSL_TYPE_UINT, 4);
630 }
631
632 void GLAPIENTRY
633 _mesa_ProgramUniform1uiv(GLuint program, GLint location, GLsizei count,
634 const GLuint *value)
635 {
636 GET_CURRENT_CONTEXT(ctx);
637 struct gl_shader_program *shProg =
638 _mesa_lookup_shader_program_err(ctx, program,
639 "glProgramUniform1uiv");
640 _mesa_uniform(ctx, shProg, location, count, value, GLSL_TYPE_UINT, 1);
641 }
642
643 void GLAPIENTRY
644 _mesa_ProgramUniform2uiv(GLuint program, GLint location, GLsizei count,
645 const GLuint *value)
646 {
647 GET_CURRENT_CONTEXT(ctx);
648 struct gl_shader_program *shProg =
649 _mesa_lookup_shader_program_err(ctx, program,
650 "glProgramUniform2uiv");
651 _mesa_uniform(ctx, shProg, location, count, value, GLSL_TYPE_UINT, 2);
652 }
653
654 void GLAPIENTRY
655 _mesa_ProgramUniform3uiv(GLuint program, GLint location, GLsizei count,
656 const GLuint *value)
657 {
658 GET_CURRENT_CONTEXT(ctx);
659 struct gl_shader_program *shProg =
660 _mesa_lookup_shader_program_err(ctx, program,
661 "glProgramUniform3uiv");
662 _mesa_uniform(ctx, shProg, location, count, value, GLSL_TYPE_UINT, 3);
663 }
664
665 void GLAPIENTRY
666 _mesa_ProgramUniform4uiv(GLuint program, GLint location, GLsizei count,
667 const GLuint *value)
668 {
669 GET_CURRENT_CONTEXT(ctx);
670 struct gl_shader_program *shProg =
671 _mesa_lookup_shader_program_err(ctx, program,
672 "glProgramUniform4uiv");
673 _mesa_uniform(ctx, shProg, location, count, value, GLSL_TYPE_UINT, 4);
674 }
675
676
677
678 void GLAPIENTRY
679 _mesa_ProgramUniformMatrix2fv(GLuint program, GLint location, GLsizei count,
680 GLboolean transpose, const GLfloat * value)
681 {
682 GET_CURRENT_CONTEXT(ctx);
683 struct gl_shader_program *shProg =
684 _mesa_lookup_shader_program_err(ctx, program,
685 "glProgramUniformMatrix2fv");
686 _mesa_uniform_matrix(ctx, shProg, 2, 2, location, count, transpose, value, GL_FLOAT);
687 }
688
689 void GLAPIENTRY
690 _mesa_ProgramUniformMatrix3fv(GLuint program, GLint location, GLsizei count,
691 GLboolean transpose, const GLfloat * value)
692 {
693 GET_CURRENT_CONTEXT(ctx);
694 struct gl_shader_program *shProg =
695 _mesa_lookup_shader_program_err(ctx, program,
696 "glProgramUniformMatrix3fv");
697 _mesa_uniform_matrix(ctx, shProg, 3, 3, location, count, transpose, value, GL_FLOAT);
698 }
699
700 void GLAPIENTRY
701 _mesa_ProgramUniformMatrix4fv(GLuint program, GLint location, GLsizei count,
702 GLboolean transpose, const GLfloat * value)
703 {
704 GET_CURRENT_CONTEXT(ctx);
705 struct gl_shader_program *shProg =
706 _mesa_lookup_shader_program_err(ctx, program,
707 "glProgramUniformMatrix4fv");
708 _mesa_uniform_matrix(ctx, shProg, 4, 4, location, count, transpose, value, GL_FLOAT);
709 }
710
711
712 /**
713 * Non-square UniformMatrix are OpenGL 2.1
714 */
715 void GLAPIENTRY
716 _mesa_UniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose,
717 const GLfloat *value)
718 {
719 GET_CURRENT_CONTEXT(ctx);
720 _mesa_uniform_matrix(ctx, ctx->_Shader->ActiveProgram,
721 2, 3, location, count, transpose, value, GL_FLOAT);
722 }
723
724 void GLAPIENTRY
725 _mesa_UniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose,
726 const GLfloat *value)
727 {
728 GET_CURRENT_CONTEXT(ctx);
729 _mesa_uniform_matrix(ctx, ctx->_Shader->ActiveProgram,
730 3, 2, location, count, transpose, value, GL_FLOAT);
731 }
732
733 void GLAPIENTRY
734 _mesa_UniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose,
735 const GLfloat *value)
736 {
737 GET_CURRENT_CONTEXT(ctx);
738 _mesa_uniform_matrix(ctx, ctx->_Shader->ActiveProgram,
739 2, 4, location, count, transpose, value, GL_FLOAT);
740 }
741
742 void GLAPIENTRY
743 _mesa_UniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose,
744 const GLfloat *value)
745 {
746 GET_CURRENT_CONTEXT(ctx);
747 _mesa_uniform_matrix(ctx, ctx->_Shader->ActiveProgram,
748 4, 2, location, count, transpose, value, GL_FLOAT);
749 }
750
751 void GLAPIENTRY
752 _mesa_UniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose,
753 const GLfloat *value)
754 {
755 GET_CURRENT_CONTEXT(ctx);
756 _mesa_uniform_matrix(ctx, ctx->_Shader->ActiveProgram,
757 3, 4, location, count, transpose, value, GL_FLOAT);
758 }
759
760 void GLAPIENTRY
761 _mesa_UniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose,
762 const GLfloat *value)
763 {
764 GET_CURRENT_CONTEXT(ctx);
765 _mesa_uniform_matrix(ctx, ctx->_Shader->ActiveProgram,
766 4, 3, location, count, transpose, value, GL_FLOAT);
767 }
768
769 /** Same as above with direct state access **/
770
771 void GLAPIENTRY
772 _mesa_ProgramUniformMatrix2x3fv(GLuint program, GLint location, GLsizei count,
773 GLboolean transpose, const GLfloat * value)
774 {
775 GET_CURRENT_CONTEXT(ctx);
776 struct gl_shader_program *shProg =
777 _mesa_lookup_shader_program_err(ctx, program,
778 "glProgramUniformMatrix2x3fv");
779 _mesa_uniform_matrix(ctx, shProg, 2, 3, location, count, transpose, value, GL_FLOAT);
780 }
781
782 void GLAPIENTRY
783 _mesa_ProgramUniformMatrix3x2fv(GLuint program, GLint location, GLsizei count,
784 GLboolean transpose, const GLfloat * value)
785 {
786 GET_CURRENT_CONTEXT(ctx);
787 struct gl_shader_program *shProg =
788 _mesa_lookup_shader_program_err(ctx, program,
789 "glProgramUniformMatrix3x2fv");
790 _mesa_uniform_matrix(ctx, shProg, 3, 2, location, count, transpose, value, GL_FLOAT);
791 }
792
793 void GLAPIENTRY
794 _mesa_ProgramUniformMatrix2x4fv(GLuint program, GLint location, GLsizei count,
795 GLboolean transpose, const GLfloat * value)
796 {
797 GET_CURRENT_CONTEXT(ctx);
798 struct gl_shader_program *shProg =
799 _mesa_lookup_shader_program_err(ctx, program,
800 "glProgramUniformMatrix2x4fv");
801 _mesa_uniform_matrix(ctx, shProg, 2, 4, location, count, transpose, value, GL_FLOAT);
802 }
803
804 void GLAPIENTRY
805 _mesa_ProgramUniformMatrix4x2fv(GLuint program, GLint location, GLsizei count,
806 GLboolean transpose, const GLfloat * value)
807 {
808 GET_CURRENT_CONTEXT(ctx);
809 struct gl_shader_program *shProg =
810 _mesa_lookup_shader_program_err(ctx, program,
811 "glProgramUniformMatrix4x2fv");
812 _mesa_uniform_matrix(ctx, shProg, 4, 2, location, count, transpose, value, GL_FLOAT);
813 }
814
815 void GLAPIENTRY
816 _mesa_ProgramUniformMatrix3x4fv(GLuint program, GLint location, GLsizei count,
817 GLboolean transpose, const GLfloat * value)
818 {
819 GET_CURRENT_CONTEXT(ctx);
820 struct gl_shader_program *shProg =
821 _mesa_lookup_shader_program_err(ctx, program,
822 "glProgramUniformMatrix3x4fv");
823 _mesa_uniform_matrix(ctx, shProg, 3, 4, location, count, transpose, value, GL_FLOAT);
824 }
825
826 void GLAPIENTRY
827 _mesa_ProgramUniformMatrix4x3fv(GLuint program, GLint location, GLsizei count,
828 GLboolean transpose, const GLfloat * value)
829 {
830 GET_CURRENT_CONTEXT(ctx);
831 struct gl_shader_program *shProg =
832 _mesa_lookup_shader_program_err(ctx, program,
833 "glProgramUniformMatrix4x3fv");
834 _mesa_uniform_matrix(ctx, shProg, 4, 3, location, count, transpose, value, GL_FLOAT);
835 }
836
837
838 void GLAPIENTRY
839 _mesa_GetnUniformfvARB(GLuint program, GLint location,
840 GLsizei bufSize, GLfloat *params)
841 {
842 GET_CURRENT_CONTEXT(ctx);
843 _mesa_get_uniform(ctx, program, location, bufSize, GLSL_TYPE_FLOAT, params);
844 }
845
846 void GLAPIENTRY
847 _mesa_GetUniformfv(GLuint program, GLint location, GLfloat *params)
848 {
849 _mesa_GetnUniformfvARB(program, location, INT_MAX, params);
850 }
851
852
853 void GLAPIENTRY
854 _mesa_GetnUniformivARB(GLuint program, GLint location,
855 GLsizei bufSize, GLint *params)
856 {
857 GET_CURRENT_CONTEXT(ctx);
858 _mesa_get_uniform(ctx, program, location, bufSize, GLSL_TYPE_INT, params);
859 }
860
861 void GLAPIENTRY
862 _mesa_GetUniformiv(GLuint program, GLint location, GLint *params)
863 {
864 _mesa_GetnUniformivARB(program, location, INT_MAX, params);
865 }
866
867
868 /* GL3 */
869 void GLAPIENTRY
870 _mesa_GetnUniformuivARB(GLuint program, GLint location,
871 GLsizei bufSize, GLuint *params)
872 {
873 GET_CURRENT_CONTEXT(ctx);
874 _mesa_get_uniform(ctx, program, location, bufSize, GLSL_TYPE_UINT, params);
875 }
876
877 void GLAPIENTRY
878 _mesa_GetUniformuiv(GLuint program, GLint location, GLuint *params)
879 {
880 _mesa_GetnUniformuivARB(program, location, INT_MAX, params);
881 }
882
883
884 /* GL4 */
885 void GLAPIENTRY
886 _mesa_GetnUniformdvARB(GLuint program, GLint location,
887 GLsizei bufSize, GLdouble *params)
888 {
889 GET_CURRENT_CONTEXT(ctx);
890
891 (void) program;
892 (void) location;
893 (void) bufSize;
894 (void) params;
895
896 /*
897 _mesa_get_uniform(ctx, program, location, bufSize, GLSL_TYPE_DOUBLE, params);
898 */
899 _mesa_error(ctx, GL_INVALID_OPERATION, "glGetUniformdvARB"
900 "(GL_ARB_gpu_shader_fp64 not implemented)");
901 }
902
903 void GLAPIENTRY
904 _mesa_GetUniformdv(GLuint program, GLint location, GLdouble *params)
905 {
906 _mesa_GetnUniformdvARB(program, location, INT_MAX, params);
907 }
908
909
910 GLint GLAPIENTRY
911 _mesa_GetUniformLocation(GLuint programObj, const GLcharARB *name)
912 {
913 struct gl_shader_program *shProg;
914
915 GET_CURRENT_CONTEXT(ctx);
916
917 shProg = _mesa_lookup_shader_program_err(ctx, programObj,
918 "glGetUniformLocation");
919 if (!shProg)
920 return -1;
921
922 /* Page 80 (page 94 of the PDF) of the OpenGL 2.1 spec says:
923 *
924 * "If program has not been successfully linked, the error
925 * INVALID_OPERATION is generated."
926 */
927 if (shProg->LinkStatus == GL_FALSE) {
928 _mesa_error(ctx, GL_INVALID_OPERATION,
929 "glGetUniformLocation(program not linked)");
930 return -1;
931 }
932
933 return _mesa_program_resource_location(shProg, GL_UNIFORM, name);
934 }
935
936 GLuint GLAPIENTRY
937 _mesa_GetUniformBlockIndex(GLuint program,
938 const GLchar *uniformBlockName)
939 {
940 GET_CURRENT_CONTEXT(ctx);
941 struct gl_shader_program *shProg;
942
943 if (!ctx->Extensions.ARB_uniform_buffer_object) {
944 _mesa_error(ctx, GL_INVALID_OPERATION, "glGetUniformBlockIndex");
945 return GL_INVALID_INDEX;
946 }
947
948 shProg = _mesa_lookup_shader_program_err(ctx, program,
949 "glGetUniformBlockIndex");
950 if (!shProg)
951 return GL_INVALID_INDEX;
952
953 struct gl_program_resource *res =
954 _mesa_program_resource_find_name(shProg, GL_UNIFORM_BLOCK,
955 uniformBlockName, NULL);
956 if (!res)
957 return GL_INVALID_INDEX;
958
959 return _mesa_program_resource_index(shProg, res);
960 }
961
962 void GLAPIENTRY
963 _mesa_GetUniformIndices(GLuint program,
964 GLsizei uniformCount,
965 const GLchar * const *uniformNames,
966 GLuint *uniformIndices)
967 {
968 GET_CURRENT_CONTEXT(ctx);
969 GLsizei i;
970 struct gl_shader_program *shProg;
971
972 if (!ctx->Extensions.ARB_uniform_buffer_object) {
973 _mesa_error(ctx, GL_INVALID_OPERATION, "glGetUniformIndices");
974 return;
975 }
976
977 shProg = _mesa_lookup_shader_program_err(ctx, program,
978 "glGetUniformIndices");
979 if (!shProg)
980 return;
981
982 if (uniformCount < 0) {
983 _mesa_error(ctx, GL_INVALID_VALUE,
984 "glGetUniformIndices(uniformCount < 0)");
985 return;
986 }
987
988 for (i = 0; i < uniformCount; i++) {
989 struct gl_program_resource *res =
990 _mesa_program_resource_find_name(shProg, GL_UNIFORM, uniformNames[i],
991 NULL);
992 uniformIndices[i] = _mesa_program_resource_index(shProg, res);
993 }
994 }
995
996 void GLAPIENTRY
997 _mesa_UniformBlockBinding(GLuint program,
998 GLuint uniformBlockIndex,
999 GLuint uniformBlockBinding)
1000 {
1001 GET_CURRENT_CONTEXT(ctx);
1002 struct gl_shader_program *shProg;
1003
1004 if (!ctx->Extensions.ARB_uniform_buffer_object) {
1005 _mesa_error(ctx, GL_INVALID_OPERATION, "glUniformBlockBinding");
1006 return;
1007 }
1008
1009 shProg = _mesa_lookup_shader_program_err(ctx, program,
1010 "glUniformBlockBinding");
1011 if (!shProg)
1012 return;
1013
1014 if (uniformBlockIndex >= shProg->NumUniformBlocks) {
1015 _mesa_error(ctx, GL_INVALID_VALUE,
1016 "glUniformBlockBinding(block index %u >= %u)",
1017 uniformBlockIndex, shProg->NumUniformBlocks);
1018 return;
1019 }
1020
1021 if (uniformBlockBinding >= ctx->Const.MaxUniformBufferBindings) {
1022 _mesa_error(ctx, GL_INVALID_VALUE,
1023 "glUniformBlockBinding(block binding %u >= %u)",
1024 uniformBlockBinding, ctx->Const.MaxUniformBufferBindings);
1025 return;
1026 }
1027
1028 if (shProg->UniformBlocks[uniformBlockIndex].Binding !=
1029 uniformBlockBinding) {
1030 int i;
1031
1032 FLUSH_VERTICES(ctx, 0);
1033 ctx->NewDriverState |= ctx->DriverFlags.NewUniformBuffer;
1034
1035 shProg->UniformBlocks[uniformBlockIndex].Binding = uniformBlockBinding;
1036
1037 for (i = 0; i < MESA_SHADER_STAGES; i++) {
1038 int stage_index = shProg->UniformBlockStageIndex[i][uniformBlockIndex];
1039
1040 if (stage_index != -1) {
1041 struct gl_shader *sh = shProg->_LinkedShaders[i];
1042 sh->UniformBlocks[stage_index].Binding = uniformBlockBinding;
1043 }
1044 }
1045 }
1046 }
1047
1048
1049 /**
1050 * Generic program resource property query.
1051 */
1052 static void
1053 mesa_bufferiv(struct gl_shader_program *shProg, GLenum type,
1054 GLuint index, GLenum pname, GLint *params, const char *caller)
1055 {
1056 GET_CURRENT_CONTEXT(ctx);
1057 struct gl_program_resource *res =
1058 _mesa_program_resource_find_index(shProg, type, index);
1059
1060 if (!res) {
1061 _mesa_error(ctx, GL_INVALID_VALUE, "%s(bufferindex %d)", caller, index);
1062 return;
1063 }
1064
1065 switch (pname) {
1066 case GL_UNIFORM_BLOCK_BINDING:
1067 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
1068 _mesa_program_resource_prop(shProg, res, index, GL_BUFFER_BINDING,
1069 params, caller);
1070 return;
1071 case GL_UNIFORM_BLOCK_DATA_SIZE:
1072 case GL_ATOMIC_COUNTER_BUFFER_DATA_SIZE:
1073 _mesa_program_resource_prop(shProg, res, index, GL_BUFFER_DATA_SIZE,
1074 params, caller);
1075 return;
1076 case GL_UNIFORM_BLOCK_NAME_LENGTH:
1077 _mesa_program_resource_prop(shProg, res, index, GL_NAME_LENGTH,
1078 params, caller);
1079 return;
1080 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS:
1081 case GL_ATOMIC_COUNTER_BUFFER_ACTIVE_ATOMIC_COUNTERS:
1082 _mesa_program_resource_prop(shProg, res, index, GL_NUM_ACTIVE_VARIABLES,
1083 params, caller);
1084 return;
1085 case GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES:
1086 case GL_ATOMIC_COUNTER_BUFFER_ACTIVE_ATOMIC_COUNTER_INDICES:
1087 _mesa_program_resource_prop(shProg, res, index, GL_ACTIVE_VARIABLES,
1088 params, caller);
1089 return;
1090 case GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER:
1091 case GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_VERTEX_SHADER:
1092 _mesa_program_resource_prop(shProg, res, index,
1093 GL_REFERENCED_BY_VERTEX_SHADER, params,
1094 caller);
1095 return;
1096
1097 case GL_UNIFORM_BLOCK_REFERENCED_BY_TESS_CONTROL_SHADER:
1098 case GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_TESS_CONTROL_SHADER:
1099 _mesa_program_resource_prop(shProg, res, index,
1100 GL_REFERENCED_BY_TESS_CONTROL_SHADER, params,
1101 caller);
1102 return;
1103
1104 case GL_UNIFORM_BLOCK_REFERENCED_BY_TESS_EVALUATION_SHADER:
1105 case GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_TESS_EVALUATION_SHADER:
1106 _mesa_program_resource_prop(shProg, res, index,
1107 GL_REFERENCED_BY_TESS_EVALUATION_SHADER, params,
1108 caller);
1109 return;
1110
1111 case GL_UNIFORM_BLOCK_REFERENCED_BY_GEOMETRY_SHADER:
1112 case GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_GEOMETRY_SHADER:
1113 _mesa_program_resource_prop(shProg, res, index,
1114 GL_REFERENCED_BY_GEOMETRY_SHADER, params,
1115 caller);
1116 return;
1117 case GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER:
1118 case GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_FRAGMENT_SHADER:
1119 _mesa_program_resource_prop(shProg, res, index,
1120 GL_REFERENCED_BY_FRAGMENT_SHADER, params,
1121 caller);
1122 return;
1123 default:
1124 _mesa_error(ctx, GL_INVALID_ENUM,
1125 "%s(pname 0x%x (%s))", caller, pname,
1126 _mesa_enum_to_string(pname));
1127 return;
1128 }
1129 }
1130
1131
1132 void GLAPIENTRY
1133 _mesa_GetActiveUniformBlockiv(GLuint program,
1134 GLuint uniformBlockIndex,
1135 GLenum pname,
1136 GLint *params)
1137 {
1138 GET_CURRENT_CONTEXT(ctx);
1139 struct gl_shader_program *shProg;
1140
1141 if (!ctx->Extensions.ARB_uniform_buffer_object) {
1142 _mesa_error(ctx, GL_INVALID_OPERATION, "glGetActiveUniformBlockiv");
1143 return;
1144 }
1145
1146 shProg = _mesa_lookup_shader_program_err(ctx, program,
1147 "glGetActiveUniformBlockiv");
1148 if (!shProg)
1149 return;
1150
1151 mesa_bufferiv(shProg, GL_UNIFORM_BLOCK, uniformBlockIndex, pname, params,
1152 "glGetActiveUniformBlockiv");
1153 }
1154
1155 void GLAPIENTRY
1156 _mesa_GetActiveUniformBlockName(GLuint program,
1157 GLuint uniformBlockIndex,
1158 GLsizei bufSize,
1159 GLsizei *length,
1160 GLchar *uniformBlockName)
1161 {
1162 GET_CURRENT_CONTEXT(ctx);
1163 struct gl_shader_program *shProg;
1164
1165 if (!ctx->Extensions.ARB_uniform_buffer_object) {
1166 _mesa_error(ctx, GL_INVALID_OPERATION, "glGetActiveUniformBlockiv");
1167 return;
1168 }
1169
1170 if (bufSize < 0) {
1171 _mesa_error(ctx, GL_INVALID_VALUE,
1172 "glGetActiveUniformBlockName(bufSize %d < 0)",
1173 bufSize);
1174 return;
1175 }
1176
1177 shProg = _mesa_lookup_shader_program_err(ctx, program,
1178 "glGetActiveUniformBlockiv");
1179 if (!shProg)
1180 return;
1181
1182 if (uniformBlockName)
1183 _mesa_get_program_resource_name(shProg, GL_UNIFORM_BLOCK,
1184 uniformBlockIndex, bufSize, length,
1185 uniformBlockName,
1186 "glGetActiveUniformBlockName");
1187 }
1188
1189 void GLAPIENTRY
1190 _mesa_GetActiveUniformName(GLuint program, GLuint uniformIndex,
1191 GLsizei bufSize, GLsizei *length,
1192 GLchar *uniformName)
1193 {
1194 GET_CURRENT_CONTEXT(ctx);
1195 struct gl_shader_program *shProg;
1196
1197 if (!ctx->Extensions.ARB_uniform_buffer_object) {
1198 _mesa_error(ctx, GL_INVALID_OPERATION, "glGetActiveUniformName");
1199 return;
1200 }
1201
1202 if (bufSize < 0) {
1203 _mesa_error(ctx, GL_INVALID_VALUE,
1204 "glGetActiveUniformName(bufSize %d < 0)",
1205 bufSize);
1206 return;
1207 }
1208
1209 shProg = _mesa_lookup_shader_program_err(ctx, program, "glGetActiveUniformName");
1210
1211 if (!shProg)
1212 return;
1213
1214 _mesa_get_program_resource_name(shProg, GL_UNIFORM, uniformIndex, bufSize,
1215 length, uniformName, "glGetActiveUniformName");
1216 }
1217
1218 void GLAPIENTRY
1219 _mesa_GetActiveAtomicCounterBufferiv(GLuint program, GLuint bufferIndex,
1220 GLenum pname, GLint *params)
1221 {
1222 GET_CURRENT_CONTEXT(ctx);
1223 struct gl_shader_program *shProg;
1224
1225 if (!ctx->Extensions.ARB_shader_atomic_counters) {
1226 _mesa_error(ctx, GL_INVALID_OPERATION,
1227 "glGetActiveAtomicCounterBufferiv");
1228 return;
1229 }
1230
1231 shProg = _mesa_lookup_shader_program_err(ctx, program,
1232 "glGetActiveAtomicCounterBufferiv");
1233 if (!shProg)
1234 return;
1235
1236 mesa_bufferiv(shProg, GL_ATOMIC_COUNTER_BUFFER, bufferIndex, pname, params,
1237 "glGetActiveAtomicCounterBufferiv");
1238 }
1239
1240 void GLAPIENTRY
1241 _mesa_Uniform1d(GLint location, GLdouble v0)
1242 {
1243 GET_CURRENT_CONTEXT(ctx);
1244 _mesa_uniform(ctx, ctx->_Shader->ActiveProgram, location, 1, &v0, GLSL_TYPE_DOUBLE, 1);
1245 }
1246
1247 void GLAPIENTRY
1248 _mesa_Uniform2d(GLint location, GLdouble v0, GLdouble v1)
1249 {
1250 GET_CURRENT_CONTEXT(ctx);
1251 GLdouble v[2];
1252 v[0] = v0;
1253 v[1] = v1;
1254 _mesa_uniform(ctx, ctx->_Shader->ActiveProgram, location, 1, v, GLSL_TYPE_DOUBLE, 2);
1255 }
1256
1257 void GLAPIENTRY
1258 _mesa_Uniform3d(GLint location, GLdouble v0, GLdouble v1, GLdouble v2)
1259 {
1260 GET_CURRENT_CONTEXT(ctx);
1261 GLdouble v[3];
1262 v[0] = v0;
1263 v[1] = v1;
1264 v[2] = v2;
1265 _mesa_uniform(ctx, ctx->_Shader->ActiveProgram, location, 1, v, GLSL_TYPE_DOUBLE, 3);
1266 }
1267
1268 void GLAPIENTRY
1269 _mesa_Uniform4d(GLint location, GLdouble v0, GLdouble v1, GLdouble v2,
1270 GLdouble v3)
1271 {
1272 GET_CURRENT_CONTEXT(ctx);
1273 GLdouble v[4];
1274 v[0] = v0;
1275 v[1] = v1;
1276 v[2] = v2;
1277 v[3] = v3;
1278 _mesa_uniform(ctx, ctx->_Shader->ActiveProgram, location, 1, v, GLSL_TYPE_DOUBLE, 4);
1279 }
1280
1281 void GLAPIENTRY
1282 _mesa_Uniform1dv(GLint location, GLsizei count, const GLdouble * value)
1283 {
1284 GET_CURRENT_CONTEXT(ctx);
1285 _mesa_uniform(ctx, ctx->_Shader->ActiveProgram, location, count, value, GLSL_TYPE_DOUBLE, 1);
1286 }
1287
1288 void GLAPIENTRY
1289 _mesa_Uniform2dv(GLint location, GLsizei count, const GLdouble * value)
1290 {
1291 GET_CURRENT_CONTEXT(ctx);
1292 _mesa_uniform(ctx, ctx->_Shader->ActiveProgram, location, count, value, GLSL_TYPE_DOUBLE, 2);
1293 }
1294
1295 void GLAPIENTRY
1296 _mesa_Uniform3dv(GLint location, GLsizei count, const GLdouble * value)
1297 {
1298 GET_CURRENT_CONTEXT(ctx);
1299 _mesa_uniform(ctx, ctx->_Shader->ActiveProgram, location, count, value, GLSL_TYPE_DOUBLE, 3);
1300 }
1301
1302 void GLAPIENTRY
1303 _mesa_Uniform4dv(GLint location, GLsizei count, const GLdouble * value)
1304 {
1305 GET_CURRENT_CONTEXT(ctx);
1306 _mesa_uniform(ctx, ctx->_Shader->ActiveProgram, location, count, value, GLSL_TYPE_DOUBLE, 4);
1307 }
1308
1309 void GLAPIENTRY
1310 _mesa_UniformMatrix2dv(GLint location, GLsizei count, GLboolean transpose,
1311 const GLdouble * value)
1312 {
1313 GET_CURRENT_CONTEXT(ctx);
1314 _mesa_uniform_matrix(ctx, ctx->_Shader->ActiveProgram,
1315 2, 2, location, count, transpose, value, GL_DOUBLE);
1316 }
1317
1318 void GLAPIENTRY
1319 _mesa_UniformMatrix3dv(GLint location, GLsizei count, GLboolean transpose,
1320 const GLdouble * value)
1321 {
1322 GET_CURRENT_CONTEXT(ctx);
1323 _mesa_uniform_matrix(ctx, ctx->_Shader->ActiveProgram,
1324 3, 3, location, count, transpose, value, GL_DOUBLE);
1325 }
1326
1327 void GLAPIENTRY
1328 _mesa_UniformMatrix4dv(GLint location, GLsizei count, GLboolean transpose,
1329 const GLdouble * value)
1330 {
1331 GET_CURRENT_CONTEXT(ctx);
1332 _mesa_uniform_matrix(ctx, ctx->_Shader->ActiveProgram,
1333 4, 4, location, count, transpose, value, GL_DOUBLE);
1334 }
1335
1336 void GLAPIENTRY
1337 _mesa_UniformMatrix2x3dv(GLint location, GLsizei count, GLboolean transpose,
1338 const GLdouble *value)
1339 {
1340 GET_CURRENT_CONTEXT(ctx);
1341 _mesa_uniform_matrix(ctx, ctx->_Shader->ActiveProgram,
1342 2, 3, location, count, transpose, value, GL_DOUBLE);
1343 }
1344
1345 void GLAPIENTRY
1346 _mesa_UniformMatrix3x2dv(GLint location, GLsizei count, GLboolean transpose,
1347 const GLdouble *value)
1348 {
1349 GET_CURRENT_CONTEXT(ctx);
1350 _mesa_uniform_matrix(ctx, ctx->_Shader->ActiveProgram,
1351 3, 2, location, count, transpose, value, GL_DOUBLE);
1352 }
1353
1354 void GLAPIENTRY
1355 _mesa_UniformMatrix2x4dv(GLint location, GLsizei count, GLboolean transpose,
1356 const GLdouble *value)
1357 {
1358 GET_CURRENT_CONTEXT(ctx);
1359 _mesa_uniform_matrix(ctx, ctx->_Shader->ActiveProgram,
1360 2, 4, location, count, transpose, value, GL_DOUBLE);
1361 }
1362
1363 void GLAPIENTRY
1364 _mesa_UniformMatrix4x2dv(GLint location, GLsizei count, GLboolean transpose,
1365 const GLdouble *value)
1366 {
1367 GET_CURRENT_CONTEXT(ctx);
1368 _mesa_uniform_matrix(ctx, ctx->_Shader->ActiveProgram,
1369 4, 2, location, count, transpose, value, GL_DOUBLE);
1370 }
1371
1372 void GLAPIENTRY
1373 _mesa_UniformMatrix3x4dv(GLint location, GLsizei count, GLboolean transpose,
1374 const GLdouble *value)
1375 {
1376 GET_CURRENT_CONTEXT(ctx);
1377 _mesa_uniform_matrix(ctx, ctx->_Shader->ActiveProgram,
1378 3, 4, location, count, transpose, value, GL_DOUBLE);
1379 }
1380
1381 void GLAPIENTRY
1382 _mesa_UniformMatrix4x3dv(GLint location, GLsizei count, GLboolean transpose,
1383 const GLdouble *value)
1384 {
1385 GET_CURRENT_CONTEXT(ctx);
1386 _mesa_uniform_matrix(ctx, ctx->_Shader->ActiveProgram,
1387 4, 3, location, count, transpose, value, GL_DOUBLE);
1388 }
1389
1390 void GLAPIENTRY
1391 _mesa_ProgramUniform1d(GLuint program, GLint location, GLdouble v0)
1392 {
1393 GET_CURRENT_CONTEXT(ctx);
1394 struct gl_shader_program *shProg =
1395 _mesa_lookup_shader_program_err(ctx, program,
1396 "glProgramUniform1d");
1397 _mesa_uniform(ctx, shProg, location, 1, &v0, GLSL_TYPE_DOUBLE, 1);
1398 }
1399
1400 void GLAPIENTRY
1401 _mesa_ProgramUniform2d(GLuint program, GLint location, GLdouble v0, GLdouble v1)
1402 {
1403 GET_CURRENT_CONTEXT(ctx);
1404 GLdouble v[2];
1405 struct gl_shader_program *shProg;
1406 v[0] = v0;
1407 v[1] = v1;
1408 shProg = _mesa_lookup_shader_program_err(ctx, program, "glProgramUniform2d");
1409 _mesa_uniform(ctx, shProg, location, 1, v, GLSL_TYPE_DOUBLE, 2);
1410 }
1411
1412 void GLAPIENTRY
1413 _mesa_ProgramUniform3d(GLuint program, GLint location, GLdouble v0, GLdouble v1,
1414 GLdouble v2)
1415 {
1416 GET_CURRENT_CONTEXT(ctx);
1417 GLdouble v[3];
1418 struct gl_shader_program *shProg;
1419 v[0] = v0;
1420 v[1] = v1;
1421 v[2] = v2;
1422 shProg = _mesa_lookup_shader_program_err(ctx, program, "glProgramUniform3d");
1423 _mesa_uniform(ctx, shProg, location, 1, v, GLSL_TYPE_DOUBLE, 3);
1424 }
1425
1426 void GLAPIENTRY
1427 _mesa_ProgramUniform4d(GLuint program, GLint location, GLdouble v0, GLdouble v1,
1428 GLdouble v2, GLdouble v3)
1429 {
1430 GET_CURRENT_CONTEXT(ctx);
1431 GLdouble v[4];
1432 struct gl_shader_program *shProg;
1433 v[0] = v0;
1434 v[1] = v1;
1435 v[2] = v2;
1436 v[3] = v3;
1437 shProg = _mesa_lookup_shader_program_err(ctx, program, "glProgramUniform4d");
1438 _mesa_uniform(ctx, shProg, location, 1, v, GLSL_TYPE_DOUBLE, 4);
1439 }
1440
1441 void GLAPIENTRY
1442 _mesa_ProgramUniform1dv(GLuint program, GLint location, GLsizei count,
1443 const GLdouble * value)
1444 {
1445 GET_CURRENT_CONTEXT(ctx);
1446 struct gl_shader_program *shProg =
1447 _mesa_lookup_shader_program_err(ctx, program,
1448 "glProgramUniform1dv");
1449 _mesa_uniform(ctx, shProg, location, count, value, GLSL_TYPE_DOUBLE, 1);
1450 }
1451
1452 void GLAPIENTRY
1453 _mesa_ProgramUniform2dv(GLuint program, GLint location, GLsizei count,
1454 const GLdouble * value)
1455 {
1456 GET_CURRENT_CONTEXT(ctx);
1457 struct gl_shader_program *shProg =
1458 _mesa_lookup_shader_program_err(ctx, program,
1459 "glProgramUniform2dv");
1460 _mesa_uniform(ctx, shProg, location, count, value, GLSL_TYPE_DOUBLE, 2);
1461 }
1462
1463 void GLAPIENTRY
1464 _mesa_ProgramUniform3dv(GLuint program, GLint location, GLsizei count,
1465 const GLdouble * value)
1466 {
1467 GET_CURRENT_CONTEXT(ctx);
1468 struct gl_shader_program *shProg =
1469 _mesa_lookup_shader_program_err(ctx, program,
1470 "glProgramUniform3dv");
1471 _mesa_uniform(ctx, shProg, location, count, value, GLSL_TYPE_DOUBLE, 3);
1472 }
1473
1474 void GLAPIENTRY
1475 _mesa_ProgramUniform4dv(GLuint program, GLint location, GLsizei count,
1476 const GLdouble * value)
1477 {
1478 GET_CURRENT_CONTEXT(ctx);
1479 struct gl_shader_program *shProg =
1480 _mesa_lookup_shader_program_err(ctx, program,
1481 "glProgramUniform4dv");
1482 _mesa_uniform(ctx, shProg, location, count, value, GLSL_TYPE_DOUBLE, 4);
1483 }
1484
1485 void GLAPIENTRY
1486 _mesa_ProgramUniformMatrix2dv(GLuint program, GLint location, GLsizei count,
1487 GLboolean transpose, const GLdouble * value)
1488 {
1489 GET_CURRENT_CONTEXT(ctx);
1490 struct gl_shader_program *shProg =
1491 _mesa_lookup_shader_program_err(ctx, program,
1492 "glProgramUniformMatrix2dv");
1493 _mesa_uniform_matrix(ctx, shProg, 2, 2, location, count, transpose, value, GL_DOUBLE);
1494 }
1495
1496 void GLAPIENTRY
1497 _mesa_ProgramUniformMatrix3dv(GLuint program, GLint location, GLsizei count,
1498 GLboolean transpose, const GLdouble * value)
1499 {
1500 GET_CURRENT_CONTEXT(ctx);
1501 struct gl_shader_program *shProg =
1502 _mesa_lookup_shader_program_err(ctx, program,
1503 "glProgramUniformMatrix3dv");
1504 _mesa_uniform_matrix(ctx, shProg, 3, 3, location, count, transpose, value, GL_DOUBLE);
1505 }
1506
1507 void GLAPIENTRY
1508 _mesa_ProgramUniformMatrix4dv(GLuint program, GLint location, GLsizei count,
1509 GLboolean transpose, const GLdouble * value)
1510 {
1511 GET_CURRENT_CONTEXT(ctx);
1512 struct gl_shader_program *shProg =
1513 _mesa_lookup_shader_program_err(ctx, program,
1514 "glProgramUniformMatrix4dv");
1515 _mesa_uniform_matrix(ctx, shProg, 4, 4, location, count, transpose, value, GL_DOUBLE);
1516 }
1517
1518 void GLAPIENTRY
1519 _mesa_ProgramUniformMatrix2x3dv(GLuint program, GLint location, GLsizei count,
1520 GLboolean transpose, const GLdouble * value)
1521 {
1522 GET_CURRENT_CONTEXT(ctx);
1523 struct gl_shader_program *shProg =
1524 _mesa_lookup_shader_program_err(ctx, program,
1525 "glProgramUniformMatrix2x3dv");
1526 _mesa_uniform_matrix(ctx, shProg, 2, 3, location, count, transpose, value, GL_DOUBLE);
1527 }
1528
1529 void GLAPIENTRY
1530 _mesa_ProgramUniformMatrix3x2dv(GLuint program, GLint location, GLsizei count,
1531 GLboolean transpose, const GLdouble * value)
1532 {
1533 GET_CURRENT_CONTEXT(ctx);
1534 struct gl_shader_program *shProg =
1535 _mesa_lookup_shader_program_err(ctx, program,
1536 "glProgramUniformMatrix3x2dv");
1537 _mesa_uniform_matrix(ctx, shProg, 3, 2, location, count, transpose, value, GL_DOUBLE);
1538 }
1539
1540 void GLAPIENTRY
1541 _mesa_ProgramUniformMatrix2x4dv(GLuint program, GLint location, GLsizei count,
1542 GLboolean transpose, const GLdouble * value)
1543 {
1544 GET_CURRENT_CONTEXT(ctx);
1545 struct gl_shader_program *shProg =
1546 _mesa_lookup_shader_program_err(ctx, program,
1547 "glProgramUniformMatrix2x4dv");
1548 _mesa_uniform_matrix(ctx, shProg, 2, 4, location, count, transpose, value, GL_DOUBLE);
1549 }
1550
1551 void GLAPIENTRY
1552 _mesa_ProgramUniformMatrix4x2dv(GLuint program, GLint location, GLsizei count,
1553 GLboolean transpose, const GLdouble * value)
1554 {
1555 GET_CURRENT_CONTEXT(ctx);
1556 struct gl_shader_program *shProg =
1557 _mesa_lookup_shader_program_err(ctx, program,
1558 "glProgramUniformMatrix4x2dv");
1559 _mesa_uniform_matrix(ctx, shProg, 4, 2, location, count, transpose, value, GL_DOUBLE);
1560 }
1561
1562 void GLAPIENTRY
1563 _mesa_ProgramUniformMatrix3x4dv(GLuint program, GLint location, GLsizei count,
1564 GLboolean transpose, const GLdouble * value)
1565 {
1566 GET_CURRENT_CONTEXT(ctx);
1567 struct gl_shader_program *shProg =
1568 _mesa_lookup_shader_program_err(ctx, program,
1569 "glProgramUniformMatrix3x4dv");
1570 _mesa_uniform_matrix(ctx, shProg, 3, 4, location, count, transpose, value, GL_DOUBLE);
1571 }
1572
1573 void GLAPIENTRY
1574 _mesa_ProgramUniformMatrix4x3dv(GLuint program, GLint location, GLsizei count,
1575 GLboolean transpose, const GLdouble * value)
1576 {
1577 GET_CURRENT_CONTEXT(ctx);
1578 struct gl_shader_program *shProg =
1579 _mesa_lookup_shader_program_err(ctx, program,
1580 "glProgramUniformMatrix4x3dv");
1581 _mesa_uniform_matrix(ctx, shProg, 4, 3, location, count, transpose, value, GL_DOUBLE);
1582 }