i965/gen6/blorp: Remove redundant HiZ workaround
[mesa.git] / src / mesa / main / get.c
1 /*
2 * Copyright (C) 2010 Brian Paul All Rights Reserved.
3 * Copyright (C) 2010 Intel Corporation
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included
13 * in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
19 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21 * OTHER DEALINGS IN THE SOFTWARE.
22 *
23 * Author: Kristian Høgsberg <krh@bitplanet.net>
24 */
25
26 #include "glheader.h"
27 #include "context.h"
28 #include "blend.h"
29 #include "enable.h"
30 #include "enums.h"
31 #include "extensions.h"
32 #include "get.h"
33 #include "macros.h"
34 #include "mtypes.h"
35 #include "state.h"
36 #include "texcompress.h"
37 #include "framebuffer.h"
38 #include "samplerobj.h"
39 #include "stencil.h"
40
41 /* This is a table driven implemetation of the glGet*v() functions.
42 * The basic idea is that most getters just look up an int somewhere
43 * in struct gl_context and then convert it to a bool or float according to
44 * which of glGetIntegerv() glGetBooleanv() etc is being called.
45 * Instead of generating code to do this, we can just record the enum
46 * value and the offset into struct gl_context in an array of structs. Then
47 * in glGet*(), we lookup the struct for the enum in question, and use
48 * the offset to get the int we need.
49 *
50 * Sometimes we need to look up a float, a boolean, a bit in a
51 * bitfield, a matrix or other types instead, so we need to track the
52 * type of the value in struct gl_context. And sometimes the value isn't in
53 * struct gl_context but in the drawbuffer, the array object, current texture
54 * unit, or maybe it's a computed value. So we need to also track
55 * where or how to find the value. Finally, we sometimes need to
56 * check that one of a number of extensions are enabled, the GL
57 * version or flush or call _mesa_update_state(). This is done by
58 * attaching optional extra information to the value description
59 * struct, it's sort of like an array of opcodes that describe extra
60 * checks or actions.
61 *
62 * Putting all this together we end up with struct value_desc below,
63 * and with a couple of macros to help, the table of struct value_desc
64 * is about as concise as the specification in the old python script.
65 */
66
67 #define FLOAT_TO_BOOLEAN(X) ( (X) ? GL_TRUE : GL_FALSE )
68 #define FLOAT_TO_FIXED(F) ( ((F) * 65536.0f > INT_MAX) ? INT_MAX : \
69 ((F) * 65536.0f < INT_MIN) ? INT_MIN : \
70 (GLint) ((F) * 65536.0f) )
71
72 #define INT_TO_BOOLEAN(I) ( (I) ? GL_TRUE : GL_FALSE )
73 #define INT_TO_FIXED(I) ( ((I) > SHRT_MAX) ? INT_MAX : \
74 ((I) < SHRT_MIN) ? INT_MIN : \
75 (GLint) ((I) * 65536) )
76
77 #define INT64_TO_BOOLEAN(I) ( (I) ? GL_TRUE : GL_FALSE )
78 #define INT64_TO_INT(I) ( (GLint)((I > INT_MAX) ? INT_MAX : ((I < INT_MIN) ? INT_MIN : (I))) )
79
80 #define BOOLEAN_TO_INT(B) ( (GLint) (B) )
81 #define BOOLEAN_TO_INT64(B) ( (GLint64) (B) )
82 #define BOOLEAN_TO_FLOAT(B) ( (B) ? 1.0F : 0.0F )
83 #define BOOLEAN_TO_FIXED(B) ( (GLint) ((B) ? 1 : 0) << 16 )
84
85 #define ENUM_TO_INT64(E) ( (GLint64) (E) )
86 #define ENUM_TO_FIXED(E) (E)
87
88 enum value_type {
89 TYPE_INVALID,
90 TYPE_INT,
91 TYPE_INT_2,
92 TYPE_INT_3,
93 TYPE_INT_4,
94 TYPE_INT_N,
95 TYPE_INT64,
96 TYPE_ENUM,
97 TYPE_ENUM_2,
98 TYPE_BOOLEAN,
99 TYPE_BIT_0,
100 TYPE_BIT_1,
101 TYPE_BIT_2,
102 TYPE_BIT_3,
103 TYPE_BIT_4,
104 TYPE_BIT_5,
105 TYPE_BIT_6,
106 TYPE_BIT_7,
107 TYPE_FLOAT,
108 TYPE_FLOAT_2,
109 TYPE_FLOAT_3,
110 TYPE_FLOAT_4,
111 TYPE_FLOATN,
112 TYPE_FLOATN_2,
113 TYPE_FLOATN_3,
114 TYPE_FLOATN_4,
115 TYPE_DOUBLEN,
116 TYPE_MATRIX,
117 TYPE_MATRIX_T,
118 TYPE_CONST
119 };
120
121 enum value_location {
122 LOC_BUFFER,
123 LOC_CONTEXT,
124 LOC_ARRAY,
125 LOC_TEXUNIT,
126 LOC_CUSTOM
127 };
128
129 enum value_extra {
130 EXTRA_END = 0x8000,
131 EXTRA_VERSION_30,
132 EXTRA_VERSION_31,
133 EXTRA_VERSION_32,
134 EXTRA_VERSION_40,
135 EXTRA_API_GL,
136 EXTRA_API_GL_CORE,
137 EXTRA_API_ES2,
138 EXTRA_API_ES3,
139 EXTRA_NEW_BUFFERS,
140 EXTRA_NEW_FRAG_CLAMP,
141 EXTRA_VALID_DRAW_BUFFER,
142 EXTRA_VALID_TEXTURE_UNIT,
143 EXTRA_VALID_CLIP_DISTANCE,
144 EXTRA_FLUSH_CURRENT,
145 EXTRA_GLSL_130,
146 EXTRA_EXT_UBO_GS4,
147 EXTRA_EXT_ATOMICS_GS4,
148 };
149
150 #define NO_EXTRA NULL
151 #define NO_OFFSET 0
152
153 struct value_desc {
154 GLenum pname;
155 GLubyte location; /**< enum value_location */
156 GLubyte type; /**< enum value_type */
157 int offset;
158 const int *extra;
159 };
160
161 union value {
162 GLfloat value_float;
163 GLfloat value_float_4[4];
164 GLmatrix *value_matrix;
165 GLint value_int;
166 GLint value_int_4[4];
167 GLint64 value_int64;
168 GLenum value_enum;
169
170 /* Sigh, see GL_COMPRESSED_TEXTURE_FORMATS_ARB handling */
171 struct {
172 GLint n, ints[100];
173 } value_int_n;
174 GLboolean value_bool;
175 };
176
177 #define BUFFER_FIELD(field, type) \
178 LOC_BUFFER, type, offsetof(struct gl_framebuffer, field)
179 #define CONTEXT_FIELD(field, type) \
180 LOC_CONTEXT, type, offsetof(struct gl_context, field)
181 #define ARRAY_FIELD(field, type) \
182 LOC_ARRAY, type, offsetof(struct gl_array_object, field)
183 #undef CONST /* already defined through windows.h */
184 #define CONST(value) \
185 LOC_CONTEXT, TYPE_CONST, value
186
187 #define BUFFER_INT(field) BUFFER_FIELD(field, TYPE_INT)
188 #define BUFFER_ENUM(field) BUFFER_FIELD(field, TYPE_ENUM)
189 #define BUFFER_BOOL(field) BUFFER_FIELD(field, TYPE_BOOLEAN)
190
191 #define CONTEXT_INT(field) CONTEXT_FIELD(field, TYPE_INT)
192 #define CONTEXT_INT2(field) CONTEXT_FIELD(field, TYPE_INT_2)
193 #define CONTEXT_INT64(field) CONTEXT_FIELD(field, TYPE_INT64)
194 #define CONTEXT_ENUM(field) CONTEXT_FIELD(field, TYPE_ENUM)
195 #define CONTEXT_ENUM2(field) CONTEXT_FIELD(field, TYPE_ENUM_2)
196 #define CONTEXT_BOOL(field) CONTEXT_FIELD(field, TYPE_BOOLEAN)
197 #define CONTEXT_BIT0(field) CONTEXT_FIELD(field, TYPE_BIT_0)
198 #define CONTEXT_BIT1(field) CONTEXT_FIELD(field, TYPE_BIT_1)
199 #define CONTEXT_BIT2(field) CONTEXT_FIELD(field, TYPE_BIT_2)
200 #define CONTEXT_BIT3(field) CONTEXT_FIELD(field, TYPE_BIT_3)
201 #define CONTEXT_BIT4(field) CONTEXT_FIELD(field, TYPE_BIT_4)
202 #define CONTEXT_BIT5(field) CONTEXT_FIELD(field, TYPE_BIT_5)
203 #define CONTEXT_BIT6(field) CONTEXT_FIELD(field, TYPE_BIT_6)
204 #define CONTEXT_BIT7(field) CONTEXT_FIELD(field, TYPE_BIT_7)
205 #define CONTEXT_FLOAT(field) CONTEXT_FIELD(field, TYPE_FLOAT)
206 #define CONTEXT_FLOAT2(field) CONTEXT_FIELD(field, TYPE_FLOAT_2)
207 #define CONTEXT_FLOAT3(field) CONTEXT_FIELD(field, TYPE_FLOAT_3)
208 #define CONTEXT_FLOAT4(field) CONTEXT_FIELD(field, TYPE_FLOAT_4)
209 #define CONTEXT_MATRIX(field) CONTEXT_FIELD(field, TYPE_MATRIX)
210 #define CONTEXT_MATRIX_T(field) CONTEXT_FIELD(field, TYPE_MATRIX_T)
211
212 #define ARRAY_INT(field) ARRAY_FIELD(field, TYPE_INT)
213 #define ARRAY_ENUM(field) ARRAY_FIELD(field, TYPE_ENUM)
214 #define ARRAY_BOOL(field) ARRAY_FIELD(field, TYPE_BOOLEAN)
215
216 #define EXT(f) \
217 offsetof(struct gl_extensions, f)
218
219 #define EXTRA_EXT(e) \
220 static const int extra_##e[] = { \
221 EXT(e), EXTRA_END \
222 }
223
224 #define EXTRA_EXT2(e1, e2) \
225 static const int extra_##e1##_##e2[] = { \
226 EXT(e1), EXT(e2), EXTRA_END \
227 }
228
229 /* The 'extra' mechanism is a way to specify extra checks (such as
230 * extensions or specific gl versions) or actions (flush current, new
231 * buffers) that we need to do before looking up an enum. We need to
232 * declare them all up front so we can refer to them in the value_desc
233 * structs below.
234 *
235 * Each EXTRA_ will be executed. For EXTRA_* enums of extensions and API
236 * versions, listing multiple ones in an array means an error will be thrown
237 * only if none of them are available. If you need to check for "AND"
238 * behavior, you would need to make a custom EXTRA_ enum.
239 */
240
241 static const int extra_new_buffers[] = {
242 EXTRA_NEW_BUFFERS,
243 EXTRA_END
244 };
245
246 static const int extra_new_frag_clamp[] = {
247 EXTRA_NEW_FRAG_CLAMP,
248 EXTRA_END
249 };
250
251 static const int extra_valid_draw_buffer[] = {
252 EXTRA_VALID_DRAW_BUFFER,
253 EXTRA_END
254 };
255
256 static const int extra_valid_texture_unit[] = {
257 EXTRA_VALID_TEXTURE_UNIT,
258 EXTRA_END
259 };
260
261 static const int extra_valid_clip_distance[] = {
262 EXTRA_VALID_CLIP_DISTANCE,
263 EXTRA_END
264 };
265
266 static const int extra_flush_current_valid_texture_unit[] = {
267 EXTRA_FLUSH_CURRENT,
268 EXTRA_VALID_TEXTURE_UNIT,
269 EXTRA_END
270 };
271
272 static const int extra_flush_current[] = {
273 EXTRA_FLUSH_CURRENT,
274 EXTRA_END
275 };
276
277 static const int extra_EXT_texture_integer[] = {
278 EXT(EXT_texture_integer),
279 EXTRA_END
280 };
281
282 static const int extra_EXT_texture_integer_and_new_buffers[] = {
283 EXT(EXT_texture_integer),
284 EXTRA_NEW_BUFFERS,
285 EXTRA_END
286 };
287
288 static const int extra_GLSL_130_es3[] = {
289 EXTRA_GLSL_130,
290 EXTRA_API_ES3,
291 EXTRA_END
292 };
293
294 static const int extra_texture_buffer_object[] = {
295 EXTRA_API_GL_CORE,
296 EXTRA_VERSION_31,
297 EXT(ARB_texture_buffer_object),
298 EXTRA_END
299 };
300
301 static const int extra_ARB_transform_feedback2_api_es3[] = {
302 EXT(ARB_transform_feedback2),
303 EXTRA_API_ES3,
304 EXTRA_END
305 };
306
307 static const int extra_ARB_uniform_buffer_object_and_geometry_shader[] = {
308 EXTRA_EXT_UBO_GS4,
309 EXTRA_END
310 };
311
312 static const int extra_ARB_ES2_compatibility_api_es2[] = {
313 EXT(ARB_ES2_compatibility),
314 EXTRA_API_ES2,
315 EXTRA_END
316 };
317
318 static const int extra_ARB_ES3_compatibility_api_es3[] = {
319 EXT(ARB_ES3_compatibility),
320 EXTRA_API_ES3,
321 EXTRA_END
322 };
323
324 static const int extra_EXT_framebuffer_sRGB_and_new_buffers[] = {
325 EXT(EXT_framebuffer_sRGB),
326 EXTRA_NEW_BUFFERS,
327 EXTRA_END
328 };
329
330 static const int extra_EXT_packed_float[] = {
331 EXT(EXT_packed_float),
332 EXTRA_NEW_BUFFERS,
333 EXTRA_END
334 };
335
336 static const int extra_EXT_texture_array_es3[] = {
337 EXT(EXT_texture_array),
338 EXTRA_API_ES3,
339 EXTRA_END
340 };
341
342 static const int extra_ARB_shader_atomic_counters_and_geometry_shader[] = {
343 EXTRA_EXT_ATOMICS_GS4,
344 EXTRA_END
345 };
346
347 EXTRA_EXT(ARB_texture_cube_map);
348 EXTRA_EXT(EXT_texture_array);
349 EXTRA_EXT(NV_fog_distance);
350 EXTRA_EXT(EXT_texture_filter_anisotropic);
351 EXTRA_EXT(NV_point_sprite);
352 EXTRA_EXT(NV_texture_rectangle);
353 EXTRA_EXT(EXT_stencil_two_side);
354 EXTRA_EXT(EXT_depth_bounds_test);
355 EXTRA_EXT(ARB_depth_clamp);
356 EXTRA_EXT(ATI_fragment_shader);
357 EXTRA_EXT(EXT_framebuffer_blit);
358 EXTRA_EXT(EXT_provoking_vertex);
359 EXTRA_EXT(ARB_fragment_shader);
360 EXTRA_EXT(ARB_fragment_program);
361 EXTRA_EXT2(ARB_framebuffer_object, EXT_framebuffer_multisample);
362 EXTRA_EXT(ARB_seamless_cube_map);
363 EXTRA_EXT(ARB_sync);
364 EXTRA_EXT(ARB_vertex_shader);
365 EXTRA_EXT(EXT_transform_feedback);
366 EXTRA_EXT(ARB_transform_feedback3);
367 EXTRA_EXT(EXT_pixel_buffer_object);
368 EXTRA_EXT(ARB_vertex_program);
369 EXTRA_EXT2(NV_point_sprite, ARB_point_sprite);
370 EXTRA_EXT2(ARB_vertex_program, ARB_fragment_program);
371 EXTRA_EXT(ARB_geometry_shader4);
372 EXTRA_EXT(ARB_color_buffer_float);
373 EXTRA_EXT(EXT_framebuffer_sRGB);
374 EXTRA_EXT(OES_EGL_image_external);
375 EXTRA_EXT(ARB_blend_func_extended);
376 EXTRA_EXT(ARB_uniform_buffer_object);
377 EXTRA_EXT(ARB_timer_query);
378 EXTRA_EXT(ARB_map_buffer_alignment);
379 EXTRA_EXT(ARB_texture_cube_map_array);
380 EXTRA_EXT(ARB_texture_buffer_range);
381 EXTRA_EXT(ARB_texture_multisample);
382 EXTRA_EXT(ARB_texture_gather);
383 EXTRA_EXT(ARB_shader_atomic_counters);
384 EXTRA_EXT(ARB_draw_indirect);
385
386 static const int
387 extra_ARB_color_buffer_float_or_glcore[] = {
388 EXT(ARB_color_buffer_float),
389 EXTRA_API_GL_CORE,
390 EXTRA_END
391 };
392
393 static const int
394 extra_NV_primitive_restart[] = {
395 EXT(NV_primitive_restart),
396 EXTRA_END
397 };
398
399 static const int extra_version_30[] = { EXTRA_VERSION_30, EXTRA_END };
400 static const int extra_version_31[] = { EXTRA_VERSION_31, EXTRA_END };
401 static const int extra_version_32[] = { EXTRA_VERSION_32, EXTRA_END };
402 static const int extra_version_40[] = { EXTRA_VERSION_40, EXTRA_END };
403
404 static const int extra_gl30_es3[] = {
405 EXTRA_VERSION_30,
406 EXTRA_API_ES3,
407 EXTRA_END,
408 };
409
410 static const int extra_gl32_es3[] = {
411 EXTRA_VERSION_32,
412 EXTRA_API_ES3,
413 EXTRA_END,
414 };
415
416 static const int extra_gl32_ARB_geometry_shader4[] = {
417 EXTRA_VERSION_32,
418 EXT(ARB_geometry_shader4),
419 EXTRA_END
420 };
421
422 static const int extra_gl40_ARB_sample_shading[] = {
423 EXTRA_VERSION_40,
424 EXT(ARB_sample_shading),
425 EXTRA_END
426 };
427
428 static const int
429 extra_ARB_vertex_program_api_es2[] = {
430 EXT(ARB_vertex_program),
431 EXTRA_API_ES2,
432 EXTRA_END
433 };
434
435 /* The ReadBuffer get token is valid under either full GL or under
436 * GLES2 if the NV_read_buffer extension is available. */
437 static const int
438 extra_NV_read_buffer_api_gl[] = {
439 EXTRA_API_ES2,
440 EXTRA_API_GL,
441 EXTRA_END
442 };
443
444 static const int extra_core_ARB_color_buffer_float_and_new_buffers[] = {
445 EXTRA_API_GL_CORE,
446 EXT(ARB_color_buffer_float),
447 EXTRA_NEW_BUFFERS,
448 EXTRA_END
449 };
450
451 /* This is the big table describing all the enums we accept in
452 * glGet*v(). The table is partitioned into six parts: enums
453 * understood by all GL APIs (OpenGL, GLES and GLES2), enums shared
454 * between OpenGL and GLES, enums exclusive to GLES, etc for the
455 * remaining combinations. To look up the enums valid in a given API
456 * we will use a hash table specific to that API. These tables are in
457 * turn generated at build time and included through get_hash.h.
458 */
459
460 #include "get_hash.h"
461
462 /* All we need now is a way to look up the value struct from the enum.
463 * The code generated by gcc for the old generated big switch
464 * statement is a big, balanced, open coded if/else tree, essentially
465 * an unrolled binary search. It would be natural to sort the new
466 * enum table and use bsearch(), but we will use a read-only hash
467 * table instead. bsearch() has a nice guaranteed worst case
468 * performance, but we're also guaranteed to hit that worst case
469 * (log2(n) iterations) for about half the enums. Instead, using an
470 * open addressing hash table, we can find the enum on the first try
471 * for 80% of the enums, 1 collision for 10% and never more than 5
472 * collisions for any enum (typical numbers). And the code is very
473 * simple, even though it feels a little magic. */
474
475 #ifdef GET_DEBUG
476 static void
477 print_table_stats(int api)
478 {
479 int i, j, collisions[11], count, hash, mask;
480 const struct value_desc *d;
481 const char *api_names[] = {
482 [API_OPENGL_COMPAT] = "GL",
483 [API_OPENGL_CORE] = "GL_CORE",
484 [API_OPENGLES] = "GLES",
485 [API_OPENGLES2] = "GLES2",
486 };
487 const char *api_name;
488
489 api_name = api < Elements(api_names) ? api_names[api] : "N/A";
490 count = 0;
491 mask = Elements(table(api)) - 1;
492 memset(collisions, 0, sizeof collisions);
493
494 for (i = 0; i < Elements(table(api)); i++) {
495 if (!table(api)[i])
496 continue;
497 count++;
498 d = &values[table(api)[i]];
499 hash = (d->pname * prime_factor);
500 j = 0;
501 while (1) {
502 if (values[table(api)[hash & mask]].pname == d->pname)
503 break;
504 hash += prime_step;
505 j++;
506 }
507
508 if (j < 10)
509 collisions[j]++;
510 else
511 collisions[10]++;
512 }
513
514 printf("number of enums for %s: %d (total %ld)\n",
515 api_name, count, Elements(values));
516 for (i = 0; i < Elements(collisions) - 1; i++)
517 if (collisions[i] > 0)
518 printf(" %d enums with %d %scollisions\n",
519 collisions[i], i, i == 10 ? "or more " : "");
520 }
521 #endif
522
523 /**
524 * Initialize the enum hash for a given API
525 *
526 * This is called from one_time_init() to insert the enum values that
527 * are valid for the API in question into the enum hash table.
528 *
529 * \param the current context, for determining the API in question
530 */
531 void _mesa_init_get_hash(struct gl_context *ctx)
532 {
533 #ifdef GET_DEBUG
534 print_table_stats(ctx->API);
535 #else
536 (void) ctx;
537 #endif
538 }
539
540 /**
541 * Handle irregular enums
542 *
543 * Some values don't conform to the "well-known type at context
544 * pointer + offset" pattern, so we have this function to catch all
545 * the corner cases. Typically, it's a computed value or a one-off
546 * pointer to a custom struct or something.
547 *
548 * In this case we can't return a pointer to the value, so we'll have
549 * to use the temporary variable 'v' declared back in the calling
550 * glGet*v() function to store the result.
551 *
552 * \param ctx the current context
553 * \param d the struct value_desc that describes the enum
554 * \param v pointer to the tmp declared in the calling glGet*v() function
555 */
556 static void
557 find_custom_value(struct gl_context *ctx, const struct value_desc *d, union value *v)
558 {
559 struct gl_buffer_object **buffer_obj;
560 struct gl_vertex_attrib_array *array;
561 GLuint unit, *p;
562
563 switch (d->pname) {
564 case GL_MAJOR_VERSION:
565 v->value_int = ctx->Version / 10;
566 break;
567 case GL_MINOR_VERSION:
568 v->value_int = ctx->Version % 10;
569 break;
570
571 case GL_TEXTURE_1D:
572 case GL_TEXTURE_2D:
573 case GL_TEXTURE_3D:
574 case GL_TEXTURE_CUBE_MAP_ARB:
575 case GL_TEXTURE_RECTANGLE_NV:
576 case GL_TEXTURE_EXTERNAL_OES:
577 v->value_bool = _mesa_IsEnabled(d->pname);
578 break;
579
580 case GL_LINE_STIPPLE_PATTERN:
581 /* This is the only GLushort, special case it here by promoting
582 * to an int rather than introducing a new type. */
583 v->value_int = ctx->Line.StipplePattern;
584 break;
585
586 case GL_CURRENT_RASTER_TEXTURE_COORDS:
587 unit = ctx->Texture.CurrentUnit;
588 v->value_float_4[0] = ctx->Current.RasterTexCoords[unit][0];
589 v->value_float_4[1] = ctx->Current.RasterTexCoords[unit][1];
590 v->value_float_4[2] = ctx->Current.RasterTexCoords[unit][2];
591 v->value_float_4[3] = ctx->Current.RasterTexCoords[unit][3];
592 break;
593
594 case GL_CURRENT_TEXTURE_COORDS:
595 unit = ctx->Texture.CurrentUnit;
596 v->value_float_4[0] = ctx->Current.Attrib[VERT_ATTRIB_TEX0 + unit][0];
597 v->value_float_4[1] = ctx->Current.Attrib[VERT_ATTRIB_TEX0 + unit][1];
598 v->value_float_4[2] = ctx->Current.Attrib[VERT_ATTRIB_TEX0 + unit][2];
599 v->value_float_4[3] = ctx->Current.Attrib[VERT_ATTRIB_TEX0 + unit][3];
600 break;
601
602 case GL_COLOR_WRITEMASK:
603 v->value_int_4[0] = ctx->Color.ColorMask[0][RCOMP] ? 1 : 0;
604 v->value_int_4[1] = ctx->Color.ColorMask[0][GCOMP] ? 1 : 0;
605 v->value_int_4[2] = ctx->Color.ColorMask[0][BCOMP] ? 1 : 0;
606 v->value_int_4[3] = ctx->Color.ColorMask[0][ACOMP] ? 1 : 0;
607 break;
608
609 case GL_EDGE_FLAG:
610 v->value_bool = ctx->Current.Attrib[VERT_ATTRIB_EDGEFLAG][0] == 1.0;
611 break;
612
613 case GL_READ_BUFFER:
614 v->value_enum = ctx->ReadBuffer->ColorReadBuffer;
615 break;
616
617 case GL_MAP2_GRID_DOMAIN:
618 v->value_float_4[0] = ctx->Eval.MapGrid2u1;
619 v->value_float_4[1] = ctx->Eval.MapGrid2u2;
620 v->value_float_4[2] = ctx->Eval.MapGrid2v1;
621 v->value_float_4[3] = ctx->Eval.MapGrid2v2;
622 break;
623
624 case GL_TEXTURE_STACK_DEPTH:
625 unit = ctx->Texture.CurrentUnit;
626 v->value_int = ctx->TextureMatrixStack[unit].Depth + 1;
627 break;
628 case GL_TEXTURE_MATRIX:
629 unit = ctx->Texture.CurrentUnit;
630 v->value_matrix = ctx->TextureMatrixStack[unit].Top;
631 break;
632
633 case GL_TEXTURE_COORD_ARRAY:
634 case GL_TEXTURE_COORD_ARRAY_SIZE:
635 case GL_TEXTURE_COORD_ARRAY_TYPE:
636 case GL_TEXTURE_COORD_ARRAY_STRIDE:
637 array = &ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_TEX(ctx->Array.ActiveTexture)];
638 v->value_int = *(GLuint *) ((char *) array + d->offset);
639 break;
640
641 case GL_ACTIVE_TEXTURE_ARB:
642 v->value_int = GL_TEXTURE0_ARB + ctx->Texture.CurrentUnit;
643 break;
644 case GL_CLIENT_ACTIVE_TEXTURE_ARB:
645 v->value_int = GL_TEXTURE0_ARB + ctx->Array.ActiveTexture;
646 break;
647
648 case GL_MODELVIEW_STACK_DEPTH:
649 case GL_PROJECTION_STACK_DEPTH:
650 v->value_int = *(GLint *) ((char *) ctx + d->offset) + 1;
651 break;
652
653 case GL_MAX_TEXTURE_SIZE:
654 case GL_MAX_3D_TEXTURE_SIZE:
655 case GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB:
656 p = (GLuint *) ((char *) ctx + d->offset);
657 v->value_int = 1 << (*p - 1);
658 break;
659
660 case GL_SCISSOR_BOX:
661 v->value_int_4[0] = ctx->Scissor.X;
662 v->value_int_4[1] = ctx->Scissor.Y;
663 v->value_int_4[2] = ctx->Scissor.Width;
664 v->value_int_4[3] = ctx->Scissor.Height;
665 break;
666
667 case GL_LIST_INDEX:
668 v->value_int =
669 ctx->ListState.CurrentList ? ctx->ListState.CurrentList->Name : 0;
670 break;
671 case GL_LIST_MODE:
672 if (!ctx->CompileFlag)
673 v->value_enum = 0;
674 else if (ctx->ExecuteFlag)
675 v->value_enum = GL_COMPILE_AND_EXECUTE;
676 else
677 v->value_enum = GL_COMPILE;
678 break;
679
680 case GL_VIEWPORT:
681 v->value_int_4[0] = ctx->Viewport.X;
682 v->value_int_4[1] = ctx->Viewport.Y;
683 v->value_int_4[2] = ctx->Viewport.Width;
684 v->value_int_4[3] = ctx->Viewport.Height;
685 break;
686
687 case GL_ACTIVE_STENCIL_FACE_EXT:
688 v->value_enum = ctx->Stencil.ActiveFace ? GL_BACK : GL_FRONT;
689 break;
690
691 case GL_STENCIL_FAIL:
692 v->value_enum = ctx->Stencil.FailFunc[ctx->Stencil.ActiveFace];
693 break;
694 case GL_STENCIL_FUNC:
695 v->value_enum = ctx->Stencil.Function[ctx->Stencil.ActiveFace];
696 break;
697 case GL_STENCIL_PASS_DEPTH_FAIL:
698 v->value_enum = ctx->Stencil.ZFailFunc[ctx->Stencil.ActiveFace];
699 break;
700 case GL_STENCIL_PASS_DEPTH_PASS:
701 v->value_enum = ctx->Stencil.ZPassFunc[ctx->Stencil.ActiveFace];
702 break;
703 case GL_STENCIL_REF:
704 v->value_int = _mesa_get_stencil_ref(ctx, ctx->Stencil.ActiveFace);
705 break;
706 case GL_STENCIL_BACK_REF:
707 v->value_int = _mesa_get_stencil_ref(ctx, 1);
708 break;
709 case GL_STENCIL_VALUE_MASK:
710 v->value_int = ctx->Stencil.ValueMask[ctx->Stencil.ActiveFace];
711 break;
712 case GL_STENCIL_WRITEMASK:
713 v->value_int = ctx->Stencil.WriteMask[ctx->Stencil.ActiveFace];
714 break;
715
716 case GL_NUM_EXTENSIONS:
717 v->value_int = _mesa_get_extension_count(ctx);
718 break;
719
720 case GL_IMPLEMENTATION_COLOR_READ_TYPE_OES:
721 v->value_int = _mesa_get_color_read_type(ctx);
722 break;
723 case GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES:
724 v->value_int = _mesa_get_color_read_format(ctx);
725 break;
726
727 case GL_CURRENT_MATRIX_STACK_DEPTH_ARB:
728 v->value_int = ctx->CurrentStack->Depth + 1;
729 break;
730 case GL_CURRENT_MATRIX_ARB:
731 case GL_TRANSPOSE_CURRENT_MATRIX_ARB:
732 v->value_matrix = ctx->CurrentStack->Top;
733 break;
734
735 case GL_NUM_COMPRESSED_TEXTURE_FORMATS_ARB:
736 v->value_int = _mesa_get_compressed_formats(ctx, NULL);
737 break;
738 case GL_COMPRESSED_TEXTURE_FORMATS_ARB:
739 v->value_int_n.n =
740 _mesa_get_compressed_formats(ctx, v->value_int_n.ints);
741 ASSERT(v->value_int_n.n <= (int) ARRAY_SIZE(v->value_int_n.ints));
742 break;
743
744 case GL_MAX_VARYING_FLOATS_ARB:
745 v->value_int = ctx->Const.MaxVarying * 4;
746 break;
747
748 /* Various object names */
749
750 case GL_TEXTURE_BINDING_1D:
751 case GL_TEXTURE_BINDING_2D:
752 case GL_TEXTURE_BINDING_3D:
753 case GL_TEXTURE_BINDING_1D_ARRAY_EXT:
754 case GL_TEXTURE_BINDING_2D_ARRAY_EXT:
755 case GL_TEXTURE_BINDING_CUBE_MAP_ARB:
756 case GL_TEXTURE_BINDING_RECTANGLE_NV:
757 case GL_TEXTURE_BINDING_EXTERNAL_OES:
758 case GL_TEXTURE_BINDING_CUBE_MAP_ARRAY:
759 case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
760 case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY:
761 unit = ctx->Texture.CurrentUnit;
762 v->value_int =
763 ctx->Texture.Unit[unit].CurrentTex[d->offset]->Name;
764 break;
765
766 /* GL_EXT_packed_float */
767 case GL_RGBA_SIGNED_COMPONENTS_EXT:
768 {
769 /* Note: we only check the 0th color attachment. */
770 const struct gl_renderbuffer *rb =
771 ctx->DrawBuffer->_ColorDrawBuffers[0];
772 if (rb && _mesa_is_format_signed(rb->Format)) {
773 /* Issue 17 of GL_EXT_packed_float: If a component (such as
774 * alpha) has zero bits, the component should not be considered
775 * signed and so the bit for the respective component should be
776 * zeroed.
777 */
778 GLint r_bits =
779 _mesa_get_format_bits(rb->Format, GL_RED_BITS);
780 GLint g_bits =
781 _mesa_get_format_bits(rb->Format, GL_GREEN_BITS);
782 GLint b_bits =
783 _mesa_get_format_bits(rb->Format, GL_BLUE_BITS);
784 GLint a_bits =
785 _mesa_get_format_bits(rb->Format, GL_ALPHA_BITS);
786 GLint l_bits =
787 _mesa_get_format_bits(rb->Format, GL_TEXTURE_LUMINANCE_SIZE);
788 GLint i_bits =
789 _mesa_get_format_bits(rb->Format, GL_TEXTURE_INTENSITY_SIZE);
790
791 v->value_int_4[0] = r_bits + l_bits + i_bits > 0;
792 v->value_int_4[1] = g_bits + l_bits + i_bits > 0;
793 v->value_int_4[2] = b_bits + l_bits + i_bits > 0;
794 v->value_int_4[3] = a_bits + i_bits > 0;
795 }
796 else {
797 v->value_int_4[0] =
798 v->value_int_4[1] =
799 v->value_int_4[2] =
800 v->value_int_4[3] = 0;
801 }
802 }
803 break;
804
805 /* GL_ARB_vertex_buffer_object */
806 case GL_VERTEX_ARRAY_BUFFER_BINDING_ARB:
807 case GL_NORMAL_ARRAY_BUFFER_BINDING_ARB:
808 case GL_COLOR_ARRAY_BUFFER_BINDING_ARB:
809 case GL_INDEX_ARRAY_BUFFER_BINDING_ARB:
810 case GL_EDGE_FLAG_ARRAY_BUFFER_BINDING_ARB:
811 case GL_SECONDARY_COLOR_ARRAY_BUFFER_BINDING_ARB:
812 case GL_FOG_COORDINATE_ARRAY_BUFFER_BINDING_ARB:
813 buffer_obj = (struct gl_buffer_object **)
814 ((char *) ctx->Array.ArrayObj + d->offset);
815 v->value_int = (*buffer_obj)->Name;
816 break;
817 case GL_ARRAY_BUFFER_BINDING_ARB:
818 v->value_int = ctx->Array.ArrayBufferObj->Name;
819 break;
820 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING_ARB:
821 v->value_int =
822 ctx->Array.ArrayObj->VertexBinding[VERT_ATTRIB_TEX(ctx->Array.ActiveTexture)].BufferObj->Name;
823 break;
824 case GL_ELEMENT_ARRAY_BUFFER_BINDING_ARB:
825 v->value_int = ctx->Array.ArrayObj->ElementArrayBufferObj->Name;
826 break;
827
828 /* ARB_copy_buffer */
829 case GL_COPY_READ_BUFFER:
830 v->value_int = ctx->CopyReadBuffer->Name;
831 break;
832 case GL_COPY_WRITE_BUFFER:
833 v->value_int = ctx->CopyWriteBuffer->Name;
834 break;
835
836 case GL_PIXEL_PACK_BUFFER_BINDING_EXT:
837 v->value_int = ctx->Pack.BufferObj->Name;
838 break;
839 case GL_PIXEL_UNPACK_BUFFER_BINDING_EXT:
840 v->value_int = ctx->Unpack.BufferObj->Name;
841 break;
842 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
843 v->value_int = ctx->TransformFeedback.CurrentBuffer->Name;
844 break;
845 case GL_TRANSFORM_FEEDBACK_BUFFER_PAUSED:
846 v->value_int = ctx->TransformFeedback.CurrentObject->Paused;
847 break;
848 case GL_TRANSFORM_FEEDBACK_BUFFER_ACTIVE:
849 v->value_int = ctx->TransformFeedback.CurrentObject->Active;
850 break;
851 case GL_TRANSFORM_FEEDBACK_BINDING:
852 v->value_int = ctx->TransformFeedback.CurrentObject->Name;
853 break;
854 case GL_CURRENT_PROGRAM:
855 v->value_int =
856 ctx->Shader.ActiveProgram ? ctx->Shader.ActiveProgram->Name : 0;
857 break;
858 case GL_READ_FRAMEBUFFER_BINDING_EXT:
859 v->value_int = ctx->ReadBuffer->Name;
860 break;
861 case GL_RENDERBUFFER_BINDING_EXT:
862 v->value_int =
863 ctx->CurrentRenderbuffer ? ctx->CurrentRenderbuffer->Name : 0;
864 break;
865 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
866 v->value_int = ctx->Array.ArrayObj->VertexBinding[VERT_ATTRIB_POINT_SIZE].BufferObj->Name;
867 break;
868
869 case GL_FOG_COLOR:
870 if (_mesa_get_clamp_fragment_color(ctx))
871 COPY_4FV(v->value_float_4, ctx->Fog.Color);
872 else
873 COPY_4FV(v->value_float_4, ctx->Fog.ColorUnclamped);
874 break;
875 case GL_COLOR_CLEAR_VALUE:
876 if (_mesa_get_clamp_fragment_color(ctx)) {
877 v->value_float_4[0] = CLAMP(ctx->Color.ClearColor.f[0], 0.0F, 1.0F);
878 v->value_float_4[1] = CLAMP(ctx->Color.ClearColor.f[1], 0.0F, 1.0F);
879 v->value_float_4[2] = CLAMP(ctx->Color.ClearColor.f[2], 0.0F, 1.0F);
880 v->value_float_4[3] = CLAMP(ctx->Color.ClearColor.f[3], 0.0F, 1.0F);
881 } else
882 COPY_4FV(v->value_float_4, ctx->Color.ClearColor.f);
883 break;
884 case GL_BLEND_COLOR_EXT:
885 if (_mesa_get_clamp_fragment_color(ctx))
886 COPY_4FV(v->value_float_4, ctx->Color.BlendColor);
887 else
888 COPY_4FV(v->value_float_4, ctx->Color.BlendColorUnclamped);
889 break;
890 case GL_ALPHA_TEST_REF:
891 if (_mesa_get_clamp_fragment_color(ctx))
892 v->value_float = ctx->Color.AlphaRef;
893 else
894 v->value_float = ctx->Color.AlphaRefUnclamped;
895 break;
896 case GL_MAX_VERTEX_UNIFORM_VECTORS:
897 v->value_int = ctx->Const.Program[MESA_SHADER_VERTEX].MaxUniformComponents / 4;
898 break;
899
900 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
901 v->value_int = ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxUniformComponents / 4;
902 break;
903
904 /* GL_ARB_texture_buffer_object */
905 case GL_TEXTURE_BUFFER_ARB:
906 v->value_int = ctx->Texture.BufferObject->Name;
907 break;
908 case GL_TEXTURE_BINDING_BUFFER_ARB:
909 unit = ctx->Texture.CurrentUnit;
910 v->value_int =
911 ctx->Texture.Unit[unit].CurrentTex[TEXTURE_BUFFER_INDEX]->Name;
912 break;
913 case GL_TEXTURE_BUFFER_DATA_STORE_BINDING_ARB:
914 {
915 struct gl_buffer_object *buf =
916 ctx->Texture.Unit[ctx->Texture.CurrentUnit]
917 .CurrentTex[TEXTURE_BUFFER_INDEX]->BufferObject;
918 v->value_int = buf ? buf->Name : 0;
919 }
920 break;
921 case GL_TEXTURE_BUFFER_FORMAT_ARB:
922 v->value_int = ctx->Texture.Unit[ctx->Texture.CurrentUnit]
923 .CurrentTex[TEXTURE_BUFFER_INDEX]->BufferObjectFormat;
924 break;
925
926 /* GL_ARB_sampler_objects */
927 case GL_SAMPLER_BINDING:
928 {
929 struct gl_sampler_object *samp =
930 ctx->Texture.Unit[ctx->Texture.CurrentUnit].Sampler;
931
932 /*
933 * The sampler object may have been deleted on another context,
934 * so we try to lookup the sampler object before returning its Name.
935 */
936 if (samp && _mesa_lookup_samplerobj(ctx, samp->Name)) {
937 v->value_int = samp->Name;
938 } else {
939 v->value_int = 0;
940 }
941 }
942 break;
943 /* GL_ARB_uniform_buffer_object */
944 case GL_UNIFORM_BUFFER_BINDING:
945 v->value_int = ctx->UniformBuffer->Name;
946 break;
947 /* GL_ARB_timer_query */
948 case GL_TIMESTAMP:
949 if (ctx->Driver.GetTimestamp) {
950 v->value_int64 = ctx->Driver.GetTimestamp(ctx);
951 }
952 else {
953 _mesa_problem(ctx, "driver doesn't implement GetTimestamp");
954 }
955 break;
956 /* GL_ARB_shader_atomic_counters */
957 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
958 v->value_int = ctx->AtomicBuffer->Name;
959 break;
960 /* GL_ARB_draw_indirect */
961 case GL_DRAW_INDIRECT_BUFFER_BINDING:
962 v->value_int = ctx->DrawIndirectBuffer->Name;
963 break;
964 }
965 }
966
967 /**
968 * Check extra constraints on a struct value_desc descriptor
969 *
970 * If a struct value_desc has a non-NULL extra pointer, it means that
971 * there are a number of extra constraints to check or actions to
972 * perform. The extras is just an integer array where each integer
973 * encode different constraints or actions.
974 *
975 * \param ctx current context
976 * \param func name of calling glGet*v() function for error reporting
977 * \param d the struct value_desc that has the extra constraints
978 *
979 * \return GL_FALSE if all of the constraints were not satisfied,
980 * otherwise GL_TRUE.
981 */
982 static GLboolean
983 check_extra(struct gl_context *ctx, const char *func, const struct value_desc *d)
984 {
985 const GLuint version = ctx->Version;
986 GLboolean api_check = GL_FALSE;
987 GLboolean api_found = GL_FALSE;
988 const int *e;
989
990 for (e = d->extra; *e != EXTRA_END; e++) {
991 switch (*e) {
992 case EXTRA_VERSION_30:
993 api_check = GL_TRUE;
994 if (version >= 30)
995 api_found = GL_TRUE;
996 break;
997 case EXTRA_VERSION_31:
998 api_check = GL_TRUE;
999 if (version >= 31)
1000 api_found = GL_TRUE;
1001 break;
1002 case EXTRA_VERSION_32:
1003 api_check = GL_TRUE;
1004 if (version >= 32)
1005 api_found = GL_TRUE;
1006 break;
1007 case EXTRA_NEW_FRAG_CLAMP:
1008 if (ctx->NewState & (_NEW_BUFFERS | _NEW_FRAG_CLAMP))
1009 _mesa_update_state(ctx);
1010 break;
1011 case EXTRA_API_ES2:
1012 api_check = GL_TRUE;
1013 if (ctx->API == API_OPENGLES2)
1014 api_found = GL_TRUE;
1015 break;
1016 case EXTRA_API_ES3:
1017 api_check = GL_TRUE;
1018 if (_mesa_is_gles3(ctx))
1019 api_found = GL_TRUE;
1020 break;
1021 case EXTRA_API_GL:
1022 api_check = GL_TRUE;
1023 if (_mesa_is_desktop_gl(ctx))
1024 api_found = GL_TRUE;
1025 break;
1026 case EXTRA_API_GL_CORE:
1027 api_check = GL_TRUE;
1028 if (ctx->API == API_OPENGL_CORE)
1029 api_found = GL_TRUE;
1030 break;
1031 case EXTRA_NEW_BUFFERS:
1032 if (ctx->NewState & _NEW_BUFFERS)
1033 _mesa_update_state(ctx);
1034 break;
1035 case EXTRA_FLUSH_CURRENT:
1036 FLUSH_CURRENT(ctx, 0);
1037 break;
1038 case EXTRA_VALID_DRAW_BUFFER:
1039 if (d->pname - GL_DRAW_BUFFER0_ARB >= ctx->Const.MaxDrawBuffers) {
1040 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(draw buffer %u)",
1041 func, d->pname - GL_DRAW_BUFFER0_ARB);
1042 return GL_FALSE;
1043 }
1044 break;
1045 case EXTRA_VALID_TEXTURE_UNIT:
1046 if (ctx->Texture.CurrentUnit >= ctx->Const.MaxTextureCoordUnits) {
1047 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(texture %u)",
1048 func, ctx->Texture.CurrentUnit);
1049 return GL_FALSE;
1050 }
1051 break;
1052 case EXTRA_VALID_CLIP_DISTANCE:
1053 if (d->pname - GL_CLIP_DISTANCE0 >= ctx->Const.MaxClipPlanes) {
1054 _mesa_error(ctx, GL_INVALID_ENUM, "%s(clip distance %u)",
1055 func, d->pname - GL_CLIP_DISTANCE0);
1056 return GL_FALSE;
1057 }
1058 break;
1059 case EXTRA_GLSL_130:
1060 api_check = GL_TRUE;
1061 if (ctx->Const.GLSLVersion >= 130)
1062 api_found = GL_TRUE;
1063 break;
1064 case EXTRA_EXT_UBO_GS4:
1065 api_check = GL_TRUE;
1066 api_found = (ctx->Extensions.ARB_uniform_buffer_object &&
1067 _mesa_has_geometry_shaders(ctx));
1068 break;
1069 case EXTRA_EXT_ATOMICS_GS4:
1070 api_check = GL_TRUE;
1071 api_found = (ctx->Extensions.ARB_shader_atomic_counters &&
1072 _mesa_has_geometry_shaders(ctx));
1073 break;
1074 case EXTRA_END:
1075 break;
1076 default: /* *e is a offset into the extension struct */
1077 api_check = GL_TRUE;
1078 if (*(GLboolean *) ((char *) &ctx->Extensions + *e))
1079 api_found = GL_TRUE;
1080 break;
1081 }
1082 }
1083
1084 if (api_check && !api_found) {
1085 _mesa_error(ctx, GL_INVALID_ENUM, "%s(pname=%s)", func,
1086 _mesa_lookup_enum_by_nr(d->pname));
1087 return GL_FALSE;
1088 }
1089
1090 return GL_TRUE;
1091 }
1092
1093 static const struct value_desc error_value =
1094 { 0, 0, TYPE_INVALID, NO_OFFSET, NO_EXTRA };
1095
1096 /**
1097 * Find the struct value_desc corresponding to the enum 'pname'.
1098 *
1099 * We hash the enum value to get an index into the 'table' array,
1100 * which holds the index in the 'values' array of struct value_desc.
1101 * Once we've found the entry, we do the extra checks, if any, then
1102 * look up the value and return a pointer to it.
1103 *
1104 * If the value has to be computed (for example, it's the result of a
1105 * function call or we need to add 1 to it), we use the tmp 'v' to
1106 * store the result.
1107 *
1108 * \param func name of glGet*v() func for error reporting
1109 * \param pname the enum value we're looking up
1110 * \param p is were we return the pointer to the value
1111 * \param v a tmp union value variable in the calling glGet*v() function
1112 *
1113 * \return the struct value_desc corresponding to the enum or a struct
1114 * value_desc of TYPE_INVALID if not found. This lets the calling
1115 * glGet*v() function jump right into a switch statement and
1116 * handle errors there instead of having to check for NULL.
1117 */
1118 static const struct value_desc *
1119 find_value(const char *func, GLenum pname, void **p, union value *v)
1120 {
1121 GET_CURRENT_CONTEXT(ctx);
1122 struct gl_texture_unit *unit;
1123 int mask, hash;
1124 const struct value_desc *d;
1125 int api;
1126
1127 api = ctx->API;
1128 /* We index into the table_set[] list of per-API hash tables using the API's
1129 * value in the gl_api enum. Since GLES 3 doesn't have an API_OPENGL* enum
1130 * value since it's compatible with GLES2 its entry in table_set[] is at the
1131 * end.
1132 */
1133 STATIC_ASSERT(Elements(table_set) == API_OPENGL_LAST + 2);
1134 if (_mesa_is_gles3(ctx)) {
1135 api = API_OPENGL_LAST + 1;
1136 }
1137 mask = Elements(table(api)) - 1;
1138 hash = (pname * prime_factor);
1139 while (1) {
1140 int idx = table(api)[hash & mask];
1141
1142 /* If the enum isn't valid, the hash walk ends with index 0,
1143 * pointing to the first entry of values[] which doesn't hold
1144 * any valid enum. */
1145 if (unlikely(idx == 0)) {
1146 _mesa_error(ctx, GL_INVALID_ENUM, "%s(pname=%s)", func,
1147 _mesa_lookup_enum_by_nr(pname));
1148 return &error_value;
1149 }
1150
1151 d = &values[idx];
1152 if (likely(d->pname == pname))
1153 break;
1154
1155 hash += prime_step;
1156 }
1157
1158 if (unlikely(d->extra && !check_extra(ctx, func, d)))
1159 return &error_value;
1160
1161 switch (d->location) {
1162 case LOC_BUFFER:
1163 *p = ((char *) ctx->DrawBuffer + d->offset);
1164 return d;
1165 case LOC_CONTEXT:
1166 *p = ((char *) ctx + d->offset);
1167 return d;
1168 case LOC_ARRAY:
1169 *p = ((char *) ctx->Array.ArrayObj + d->offset);
1170 return d;
1171 case LOC_TEXUNIT:
1172 unit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
1173 *p = ((char *) unit + d->offset);
1174 return d;
1175 case LOC_CUSTOM:
1176 find_custom_value(ctx, d, v);
1177 *p = v;
1178 return d;
1179 default:
1180 assert(0);
1181 break;
1182 }
1183
1184 /* silence warning */
1185 return &error_value;
1186 }
1187
1188 static const int transpose[] = {
1189 0, 4, 8, 12,
1190 1, 5, 9, 13,
1191 2, 6, 10, 14,
1192 3, 7, 11, 15
1193 };
1194
1195 void GLAPIENTRY
1196 _mesa_GetBooleanv(GLenum pname, GLboolean *params)
1197 {
1198 const struct value_desc *d;
1199 union value v;
1200 GLmatrix *m;
1201 int shift, i;
1202 void *p;
1203
1204 d = find_value("glGetBooleanv", pname, &p, &v);
1205 switch (d->type) {
1206 case TYPE_INVALID:
1207 break;
1208 case TYPE_CONST:
1209 params[0] = INT_TO_BOOLEAN(d->offset);
1210 break;
1211
1212 case TYPE_FLOAT_4:
1213 case TYPE_FLOATN_4:
1214 params[3] = FLOAT_TO_BOOLEAN(((GLfloat *) p)[3]);
1215 case TYPE_FLOAT_3:
1216 case TYPE_FLOATN_3:
1217 params[2] = FLOAT_TO_BOOLEAN(((GLfloat *) p)[2]);
1218 case TYPE_FLOAT_2:
1219 case TYPE_FLOATN_2:
1220 params[1] = FLOAT_TO_BOOLEAN(((GLfloat *) p)[1]);
1221 case TYPE_FLOAT:
1222 case TYPE_FLOATN:
1223 params[0] = FLOAT_TO_BOOLEAN(((GLfloat *) p)[0]);
1224 break;
1225
1226 case TYPE_DOUBLEN:
1227 params[0] = FLOAT_TO_BOOLEAN(((GLdouble *) p)[0]);
1228 break;
1229
1230 case TYPE_INT_4:
1231 params[3] = INT_TO_BOOLEAN(((GLint *) p)[3]);
1232 case TYPE_INT_3:
1233 params[2] = INT_TO_BOOLEAN(((GLint *) p)[2]);
1234 case TYPE_INT_2:
1235 case TYPE_ENUM_2:
1236 params[1] = INT_TO_BOOLEAN(((GLint *) p)[1]);
1237 case TYPE_INT:
1238 case TYPE_ENUM:
1239 params[0] = INT_TO_BOOLEAN(((GLint *) p)[0]);
1240 break;
1241
1242 case TYPE_INT_N:
1243 for (i = 0; i < v.value_int_n.n; i++)
1244 params[i] = INT_TO_BOOLEAN(v.value_int_n.ints[i]);
1245 break;
1246
1247 case TYPE_INT64:
1248 params[0] = INT64_TO_BOOLEAN(((GLint64 *) p)[0]);
1249 break;
1250
1251 case TYPE_BOOLEAN:
1252 params[0] = ((GLboolean*) p)[0];
1253 break;
1254
1255 case TYPE_MATRIX:
1256 m = *(GLmatrix **) p;
1257 for (i = 0; i < 16; i++)
1258 params[i] = FLOAT_TO_BOOLEAN(m->m[i]);
1259 break;
1260
1261 case TYPE_MATRIX_T:
1262 m = *(GLmatrix **) p;
1263 for (i = 0; i < 16; i++)
1264 params[i] = FLOAT_TO_BOOLEAN(m->m[transpose[i]]);
1265 break;
1266
1267 case TYPE_BIT_0:
1268 case TYPE_BIT_1:
1269 case TYPE_BIT_2:
1270 case TYPE_BIT_3:
1271 case TYPE_BIT_4:
1272 case TYPE_BIT_5:
1273 case TYPE_BIT_6:
1274 case TYPE_BIT_7:
1275 shift = d->type - TYPE_BIT_0;
1276 params[0] = (*(GLbitfield *) p >> shift) & 1;
1277 break;
1278 }
1279 }
1280
1281 void GLAPIENTRY
1282 _mesa_GetFloatv(GLenum pname, GLfloat *params)
1283 {
1284 const struct value_desc *d;
1285 union value v;
1286 GLmatrix *m;
1287 int shift, i;
1288 void *p;
1289
1290 d = find_value("glGetFloatv", pname, &p, &v);
1291 switch (d->type) {
1292 case TYPE_INVALID:
1293 break;
1294 case TYPE_CONST:
1295 params[0] = (GLfloat) d->offset;
1296 break;
1297
1298 case TYPE_FLOAT_4:
1299 case TYPE_FLOATN_4:
1300 params[3] = ((GLfloat *) p)[3];
1301 case TYPE_FLOAT_3:
1302 case TYPE_FLOATN_3:
1303 params[2] = ((GLfloat *) p)[2];
1304 case TYPE_FLOAT_2:
1305 case TYPE_FLOATN_2:
1306 params[1] = ((GLfloat *) p)[1];
1307 case TYPE_FLOAT:
1308 case TYPE_FLOATN:
1309 params[0] = ((GLfloat *) p)[0];
1310 break;
1311
1312 case TYPE_DOUBLEN:
1313 params[0] = (GLfloat) (((GLdouble *) p)[0]);
1314 break;
1315
1316 case TYPE_INT_4:
1317 params[3] = (GLfloat) (((GLint *) p)[3]);
1318 case TYPE_INT_3:
1319 params[2] = (GLfloat) (((GLint *) p)[2]);
1320 case TYPE_INT_2:
1321 case TYPE_ENUM_2:
1322 params[1] = (GLfloat) (((GLint *) p)[1]);
1323 case TYPE_INT:
1324 case TYPE_ENUM:
1325 params[0] = (GLfloat) (((GLint *) p)[0]);
1326 break;
1327
1328 case TYPE_INT_N:
1329 for (i = 0; i < v.value_int_n.n; i++)
1330 params[i] = INT_TO_FLOAT(v.value_int_n.ints[i]);
1331 break;
1332
1333 case TYPE_INT64:
1334 params[0] = (GLfloat) (((GLint64 *) p)[0]);
1335 break;
1336
1337 case TYPE_BOOLEAN:
1338 params[0] = BOOLEAN_TO_FLOAT(*(GLboolean*) p);
1339 break;
1340
1341 case TYPE_MATRIX:
1342 m = *(GLmatrix **) p;
1343 for (i = 0; i < 16; i++)
1344 params[i] = m->m[i];
1345 break;
1346
1347 case TYPE_MATRIX_T:
1348 m = *(GLmatrix **) p;
1349 for (i = 0; i < 16; i++)
1350 params[i] = m->m[transpose[i]];
1351 break;
1352
1353 case TYPE_BIT_0:
1354 case TYPE_BIT_1:
1355 case TYPE_BIT_2:
1356 case TYPE_BIT_3:
1357 case TYPE_BIT_4:
1358 case TYPE_BIT_5:
1359 case TYPE_BIT_6:
1360 case TYPE_BIT_7:
1361 shift = d->type - TYPE_BIT_0;
1362 params[0] = BOOLEAN_TO_FLOAT((*(GLbitfield *) p >> shift) & 1);
1363 break;
1364 }
1365 }
1366
1367 void GLAPIENTRY
1368 _mesa_GetIntegerv(GLenum pname, GLint *params)
1369 {
1370 const struct value_desc *d;
1371 union value v;
1372 GLmatrix *m;
1373 int shift, i;
1374 void *p;
1375
1376 d = find_value("glGetIntegerv", pname, &p, &v);
1377 switch (d->type) {
1378 case TYPE_INVALID:
1379 break;
1380 case TYPE_CONST:
1381 params[0] = d->offset;
1382 break;
1383
1384 case TYPE_FLOAT_4:
1385 params[3] = IROUND(((GLfloat *) p)[3]);
1386 case TYPE_FLOAT_3:
1387 params[2] = IROUND(((GLfloat *) p)[2]);
1388 case TYPE_FLOAT_2:
1389 params[1] = IROUND(((GLfloat *) p)[1]);
1390 case TYPE_FLOAT:
1391 params[0] = IROUND(((GLfloat *) p)[0]);
1392 break;
1393
1394 case TYPE_FLOATN_4:
1395 params[3] = FLOAT_TO_INT(((GLfloat *) p)[3]);
1396 case TYPE_FLOATN_3:
1397 params[2] = FLOAT_TO_INT(((GLfloat *) p)[2]);
1398 case TYPE_FLOATN_2:
1399 params[1] = FLOAT_TO_INT(((GLfloat *) p)[1]);
1400 case TYPE_FLOATN:
1401 params[0] = FLOAT_TO_INT(((GLfloat *) p)[0]);
1402 break;
1403
1404 case TYPE_DOUBLEN:
1405 params[0] = FLOAT_TO_INT(((GLdouble *) p)[0]);
1406 break;
1407
1408 case TYPE_INT_4:
1409 params[3] = ((GLint *) p)[3];
1410 case TYPE_INT_3:
1411 params[2] = ((GLint *) p)[2];
1412 case TYPE_INT_2:
1413 case TYPE_ENUM_2:
1414 params[1] = ((GLint *) p)[1];
1415 case TYPE_INT:
1416 case TYPE_ENUM:
1417 params[0] = ((GLint *) p)[0];
1418 break;
1419
1420 case TYPE_INT_N:
1421 for (i = 0; i < v.value_int_n.n; i++)
1422 params[i] = v.value_int_n.ints[i];
1423 break;
1424
1425 case TYPE_INT64:
1426 params[0] = INT64_TO_INT(((GLint64 *) p)[0]);
1427 break;
1428
1429 case TYPE_BOOLEAN:
1430 params[0] = BOOLEAN_TO_INT(*(GLboolean*) p);
1431 break;
1432
1433 case TYPE_MATRIX:
1434 m = *(GLmatrix **) p;
1435 for (i = 0; i < 16; i++)
1436 params[i] = FLOAT_TO_INT(m->m[i]);
1437 break;
1438
1439 case TYPE_MATRIX_T:
1440 m = *(GLmatrix **) p;
1441 for (i = 0; i < 16; i++)
1442 params[i] = FLOAT_TO_INT(m->m[transpose[i]]);
1443 break;
1444
1445 case TYPE_BIT_0:
1446 case TYPE_BIT_1:
1447 case TYPE_BIT_2:
1448 case TYPE_BIT_3:
1449 case TYPE_BIT_4:
1450 case TYPE_BIT_5:
1451 case TYPE_BIT_6:
1452 case TYPE_BIT_7:
1453 shift = d->type - TYPE_BIT_0;
1454 params[0] = (*(GLbitfield *) p >> shift) & 1;
1455 break;
1456 }
1457 }
1458
1459 void GLAPIENTRY
1460 _mesa_GetInteger64v(GLenum pname, GLint64 *params)
1461 {
1462 const struct value_desc *d;
1463 union value v;
1464 GLmatrix *m;
1465 int shift, i;
1466 void *p;
1467
1468 d = find_value("glGetInteger64v", pname, &p, &v);
1469 switch (d->type) {
1470 case TYPE_INVALID:
1471 break;
1472 case TYPE_CONST:
1473 params[0] = d->offset;
1474 break;
1475
1476 case TYPE_FLOAT_4:
1477 params[3] = IROUND64(((GLfloat *) p)[3]);
1478 case TYPE_FLOAT_3:
1479 params[2] = IROUND64(((GLfloat *) p)[2]);
1480 case TYPE_FLOAT_2:
1481 params[1] = IROUND64(((GLfloat *) p)[1]);
1482 case TYPE_FLOAT:
1483 params[0] = IROUND64(((GLfloat *) p)[0]);
1484 break;
1485
1486 case TYPE_FLOATN_4:
1487 params[3] = FLOAT_TO_INT64(((GLfloat *) p)[3]);
1488 case TYPE_FLOATN_3:
1489 params[2] = FLOAT_TO_INT64(((GLfloat *) p)[2]);
1490 case TYPE_FLOATN_2:
1491 params[1] = FLOAT_TO_INT64(((GLfloat *) p)[1]);
1492 case TYPE_FLOATN:
1493 params[0] = FLOAT_TO_INT64(((GLfloat *) p)[0]);
1494 break;
1495
1496 case TYPE_DOUBLEN:
1497 params[0] = FLOAT_TO_INT64(((GLdouble *) p)[0]);
1498 break;
1499
1500 case TYPE_INT_4:
1501 params[3] = ((GLint *) p)[3];
1502 case TYPE_INT_3:
1503 params[2] = ((GLint *) p)[2];
1504 case TYPE_INT_2:
1505 case TYPE_ENUM_2:
1506 params[1] = ((GLint *) p)[1];
1507 case TYPE_INT:
1508 case TYPE_ENUM:
1509 params[0] = ((GLint *) p)[0];
1510 break;
1511
1512 case TYPE_INT_N:
1513 for (i = 0; i < v.value_int_n.n; i++)
1514 params[i] = INT_TO_BOOLEAN(v.value_int_n.ints[i]);
1515 break;
1516
1517 case TYPE_INT64:
1518 params[0] = ((GLint64 *) p)[0];
1519 break;
1520
1521 case TYPE_BOOLEAN:
1522 params[0] = ((GLboolean*) p)[0];
1523 break;
1524
1525 case TYPE_MATRIX:
1526 m = *(GLmatrix **) p;
1527 for (i = 0; i < 16; i++)
1528 params[i] = FLOAT_TO_INT64(m->m[i]);
1529 break;
1530
1531 case TYPE_MATRIX_T:
1532 m = *(GLmatrix **) p;
1533 for (i = 0; i < 16; i++)
1534 params[i] = FLOAT_TO_INT64(m->m[transpose[i]]);
1535 break;
1536
1537 case TYPE_BIT_0:
1538 case TYPE_BIT_1:
1539 case TYPE_BIT_2:
1540 case TYPE_BIT_3:
1541 case TYPE_BIT_4:
1542 case TYPE_BIT_5:
1543 case TYPE_BIT_6:
1544 case TYPE_BIT_7:
1545 shift = d->type - TYPE_BIT_0;
1546 params[0] = (*(GLbitfield *) p >> shift) & 1;
1547 break;
1548 }
1549 }
1550
1551 void GLAPIENTRY
1552 _mesa_GetDoublev(GLenum pname, GLdouble *params)
1553 {
1554 const struct value_desc *d;
1555 union value v;
1556 GLmatrix *m;
1557 int shift, i;
1558 void *p;
1559
1560 d = find_value("glGetDoublev", pname, &p, &v);
1561 switch (d->type) {
1562 case TYPE_INVALID:
1563 break;
1564 case TYPE_CONST:
1565 params[0] = d->offset;
1566 break;
1567
1568 case TYPE_FLOAT_4:
1569 case TYPE_FLOATN_4:
1570 params[3] = ((GLfloat *) p)[3];
1571 case TYPE_FLOAT_3:
1572 case TYPE_FLOATN_3:
1573 params[2] = ((GLfloat *) p)[2];
1574 case TYPE_FLOAT_2:
1575 case TYPE_FLOATN_2:
1576 params[1] = ((GLfloat *) p)[1];
1577 case TYPE_FLOAT:
1578 case TYPE_FLOATN:
1579 params[0] = ((GLfloat *) p)[0];
1580 break;
1581
1582 case TYPE_DOUBLEN:
1583 params[0] = ((GLdouble *) p)[0];
1584 break;
1585
1586 case TYPE_INT_4:
1587 params[3] = ((GLint *) p)[3];
1588 case TYPE_INT_3:
1589 params[2] = ((GLint *) p)[2];
1590 case TYPE_INT_2:
1591 case TYPE_ENUM_2:
1592 params[1] = ((GLint *) p)[1];
1593 case TYPE_INT:
1594 case TYPE_ENUM:
1595 params[0] = ((GLint *) p)[0];
1596 break;
1597
1598 case TYPE_INT_N:
1599 for (i = 0; i < v.value_int_n.n; i++)
1600 params[i] = v.value_int_n.ints[i];
1601 break;
1602
1603 case TYPE_INT64:
1604 params[0] = (GLdouble) (((GLint64 *) p)[0]);
1605 break;
1606
1607 case TYPE_BOOLEAN:
1608 params[0] = *(GLboolean*) p;
1609 break;
1610
1611 case TYPE_MATRIX:
1612 m = *(GLmatrix **) p;
1613 for (i = 0; i < 16; i++)
1614 params[i] = m->m[i];
1615 break;
1616
1617 case TYPE_MATRIX_T:
1618 m = *(GLmatrix **) p;
1619 for (i = 0; i < 16; i++)
1620 params[i] = m->m[transpose[i]];
1621 break;
1622
1623 case TYPE_BIT_0:
1624 case TYPE_BIT_1:
1625 case TYPE_BIT_2:
1626 case TYPE_BIT_3:
1627 case TYPE_BIT_4:
1628 case TYPE_BIT_5:
1629 case TYPE_BIT_6:
1630 case TYPE_BIT_7:
1631 shift = d->type - TYPE_BIT_0;
1632 params[0] = (*(GLbitfield *) p >> shift) & 1;
1633 break;
1634 }
1635 }
1636
1637 static enum value_type
1638 find_value_indexed(const char *func, GLenum pname, GLuint index, union value *v)
1639 {
1640 GET_CURRENT_CONTEXT(ctx);
1641
1642 switch (pname) {
1643
1644 case GL_BLEND:
1645 if (index >= ctx->Const.MaxDrawBuffers)
1646 goto invalid_value;
1647 if (!ctx->Extensions.EXT_draw_buffers2)
1648 goto invalid_enum;
1649 v->value_int = (ctx->Color.BlendEnabled >> index) & 1;
1650 return TYPE_INT;
1651
1652 case GL_BLEND_SRC:
1653 /* fall-through */
1654 case GL_BLEND_SRC_RGB:
1655 if (index >= ctx->Const.MaxDrawBuffers)
1656 goto invalid_value;
1657 if (!ctx->Extensions.ARB_draw_buffers_blend)
1658 goto invalid_enum;
1659 v->value_int = ctx->Color.Blend[index].SrcRGB;
1660 return TYPE_INT;
1661 case GL_BLEND_SRC_ALPHA:
1662 if (index >= ctx->Const.MaxDrawBuffers)
1663 goto invalid_value;
1664 if (!ctx->Extensions.ARB_draw_buffers_blend)
1665 goto invalid_enum;
1666 v->value_int = ctx->Color.Blend[index].SrcA;
1667 return TYPE_INT;
1668 case GL_BLEND_DST:
1669 /* fall-through */
1670 case GL_BLEND_DST_RGB:
1671 if (index >= ctx->Const.MaxDrawBuffers)
1672 goto invalid_value;
1673 if (!ctx->Extensions.ARB_draw_buffers_blend)
1674 goto invalid_enum;
1675 v->value_int = ctx->Color.Blend[index].DstRGB;
1676 return TYPE_INT;
1677 case GL_BLEND_DST_ALPHA:
1678 if (index >= ctx->Const.MaxDrawBuffers)
1679 goto invalid_value;
1680 if (!ctx->Extensions.ARB_draw_buffers_blend)
1681 goto invalid_enum;
1682 v->value_int = ctx->Color.Blend[index].DstA;
1683 return TYPE_INT;
1684 case GL_BLEND_EQUATION_RGB:
1685 if (index >= ctx->Const.MaxDrawBuffers)
1686 goto invalid_value;
1687 if (!ctx->Extensions.ARB_draw_buffers_blend)
1688 goto invalid_enum;
1689 v->value_int = ctx->Color.Blend[index].EquationRGB;
1690 return TYPE_INT;
1691 case GL_BLEND_EQUATION_ALPHA:
1692 if (index >= ctx->Const.MaxDrawBuffers)
1693 goto invalid_value;
1694 if (!ctx->Extensions.ARB_draw_buffers_blend)
1695 goto invalid_enum;
1696 v->value_int = ctx->Color.Blend[index].EquationA;
1697 return TYPE_INT;
1698
1699 case GL_COLOR_WRITEMASK:
1700 if (index >= ctx->Const.MaxDrawBuffers)
1701 goto invalid_value;
1702 if (!ctx->Extensions.EXT_draw_buffers2)
1703 goto invalid_enum;
1704 v->value_int_4[0] = ctx->Color.ColorMask[index][RCOMP] ? 1 : 0;
1705 v->value_int_4[1] = ctx->Color.ColorMask[index][GCOMP] ? 1 : 0;
1706 v->value_int_4[2] = ctx->Color.ColorMask[index][BCOMP] ? 1 : 0;
1707 v->value_int_4[3] = ctx->Color.ColorMask[index][ACOMP] ? 1 : 0;
1708 return TYPE_INT_4;
1709
1710 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
1711 if (index >= ctx->Const.MaxTransformFeedbackBuffers)
1712 goto invalid_value;
1713 if (!ctx->Extensions.EXT_transform_feedback)
1714 goto invalid_enum;
1715 v->value_int64 = ctx->TransformFeedback.CurrentObject->Offset[index];
1716 return TYPE_INT64;
1717
1718 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
1719 if (index >= ctx->Const.MaxTransformFeedbackBuffers)
1720 goto invalid_value;
1721 if (!ctx->Extensions.EXT_transform_feedback)
1722 goto invalid_enum;
1723 v->value_int64
1724 = ctx->TransformFeedback.CurrentObject->RequestedSize[index];
1725 return TYPE_INT64;
1726
1727 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
1728 if (index >= ctx->Const.MaxTransformFeedbackBuffers)
1729 goto invalid_value;
1730 if (!ctx->Extensions.EXT_transform_feedback)
1731 goto invalid_enum;
1732 v->value_int = ctx->TransformFeedback.CurrentObject->BufferNames[index];
1733 return TYPE_INT;
1734
1735 case GL_UNIFORM_BUFFER_BINDING:
1736 if (index >= ctx->Const.MaxUniformBufferBindings)
1737 goto invalid_value;
1738 if (!ctx->Extensions.ARB_uniform_buffer_object)
1739 goto invalid_enum;
1740 v->value_int = ctx->UniformBufferBindings[index].BufferObject->Name;
1741 return TYPE_INT;
1742
1743 case GL_UNIFORM_BUFFER_START:
1744 if (index >= ctx->Const.MaxUniformBufferBindings)
1745 goto invalid_value;
1746 if (!ctx->Extensions.ARB_uniform_buffer_object)
1747 goto invalid_enum;
1748 v->value_int = ctx->UniformBufferBindings[index].Offset;
1749 return TYPE_INT;
1750
1751 case GL_UNIFORM_BUFFER_SIZE:
1752 if (index >= ctx->Const.MaxUniformBufferBindings)
1753 goto invalid_value;
1754 if (!ctx->Extensions.ARB_uniform_buffer_object)
1755 goto invalid_enum;
1756 v->value_int = ctx->UniformBufferBindings[index].Size;
1757 return TYPE_INT;
1758
1759 /* ARB_texture_multisample / GL3.2 */
1760 case GL_SAMPLE_MASK_VALUE:
1761 if (index != 0)
1762 goto invalid_value;
1763 if (!ctx->Extensions.ARB_texture_multisample)
1764 goto invalid_enum;
1765 v->value_int = ctx->Multisample.SampleMaskValue;
1766 return TYPE_INT;
1767
1768 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
1769 if (!ctx->Extensions.ARB_shader_atomic_counters)
1770 goto invalid_enum;
1771 if (index >= ctx->Const.MaxAtomicBufferBindings)
1772 goto invalid_value;
1773 v->value_int = ctx->AtomicBufferBindings[index].BufferObject->Name;
1774 return TYPE_INT;
1775
1776 case GL_ATOMIC_COUNTER_BUFFER_START:
1777 if (!ctx->Extensions.ARB_shader_atomic_counters)
1778 goto invalid_enum;
1779 if (index >= ctx->Const.MaxAtomicBufferBindings)
1780 goto invalid_value;
1781 v->value_int64 = ctx->AtomicBufferBindings[index].Offset;
1782 return TYPE_INT64;
1783
1784 case GL_ATOMIC_COUNTER_BUFFER_SIZE:
1785 if (!ctx->Extensions.ARB_shader_atomic_counters)
1786 goto invalid_enum;
1787 if (index >= ctx->Const.MaxAtomicBufferBindings)
1788 goto invalid_value;
1789 v->value_int64 = ctx->AtomicBufferBindings[index].Size;
1790 return TYPE_INT64;
1791
1792 case GL_VERTEX_BINDING_DIVISOR:
1793 if (!_mesa_is_desktop_gl(ctx) || !ctx->Extensions.ARB_instanced_arrays)
1794 goto invalid_enum;
1795 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs)
1796 goto invalid_value;
1797 v->value_int = ctx->Array.ArrayObj->VertexBinding[VERT_ATTRIB_GENERIC(index)].InstanceDivisor;
1798 return TYPE_INT;
1799
1800 case GL_VERTEX_BINDING_OFFSET:
1801 if (!_mesa_is_desktop_gl(ctx))
1802 goto invalid_enum;
1803 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs)
1804 goto invalid_value;
1805 v->value_int = ctx->Array.ArrayObj->VertexBinding[VERT_ATTRIB_GENERIC(index)].Offset;
1806 return TYPE_INT;
1807
1808 case GL_VERTEX_BINDING_STRIDE:
1809 if (!_mesa_is_desktop_gl(ctx))
1810 goto invalid_enum;
1811 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs)
1812 goto invalid_value;
1813 v->value_int = ctx->Array.ArrayObj->VertexBinding[VERT_ATTRIB_GENERIC(index)].Stride;
1814 return TYPE_INT;
1815 }
1816
1817 invalid_enum:
1818 _mesa_error(ctx, GL_INVALID_ENUM, "%s(pname=%s)", func,
1819 _mesa_lookup_enum_by_nr(pname));
1820 return TYPE_INVALID;
1821 invalid_value:
1822 _mesa_error(ctx, GL_INVALID_VALUE, "%s(pname=%s)", func,
1823 _mesa_lookup_enum_by_nr(pname));
1824 return TYPE_INVALID;
1825 }
1826
1827 void GLAPIENTRY
1828 _mesa_GetBooleani_v( GLenum pname, GLuint index, GLboolean *params )
1829 {
1830 union value v;
1831 enum value_type type =
1832 find_value_indexed("glGetBooleani_v", pname, index, &v);
1833
1834 switch (type) {
1835 case TYPE_INT:
1836 params[0] = INT_TO_BOOLEAN(v.value_int);
1837 break;
1838 case TYPE_INT_4:
1839 params[0] = INT_TO_BOOLEAN(v.value_int_4[0]);
1840 params[1] = INT_TO_BOOLEAN(v.value_int_4[1]);
1841 params[2] = INT_TO_BOOLEAN(v.value_int_4[2]);
1842 params[3] = INT_TO_BOOLEAN(v.value_int_4[3]);
1843 break;
1844 case TYPE_INT64:
1845 params[0] = INT64_TO_BOOLEAN(v.value_int);
1846 break;
1847 default:
1848 ; /* nothing - GL error was recorded */
1849 }
1850 }
1851
1852 void GLAPIENTRY
1853 _mesa_GetIntegeri_v( GLenum pname, GLuint index, GLint *params )
1854 {
1855 union value v;
1856 enum value_type type =
1857 find_value_indexed("glGetIntegeri_v", pname, index, &v);
1858
1859 switch (type) {
1860 case TYPE_INT:
1861 params[0] = v.value_int;
1862 break;
1863 case TYPE_INT_4:
1864 params[0] = v.value_int_4[0];
1865 params[1] = v.value_int_4[1];
1866 params[2] = v.value_int_4[2];
1867 params[3] = v.value_int_4[3];
1868 break;
1869 case TYPE_INT64:
1870 params[0] = INT64_TO_INT(v.value_int);
1871 break;
1872 default:
1873 ; /* nothing - GL error was recorded */
1874 }
1875 }
1876
1877 void GLAPIENTRY
1878 _mesa_GetInteger64i_v( GLenum pname, GLuint index, GLint64 *params )
1879 {
1880 union value v;
1881 enum value_type type =
1882 find_value_indexed("glGetInteger64i_v", pname, index, &v);
1883
1884 switch (type) {
1885 case TYPE_INT:
1886 params[0] = v.value_int;
1887 break;
1888 case TYPE_INT_4:
1889 params[0] = v.value_int_4[0];
1890 params[1] = v.value_int_4[1];
1891 params[2] = v.value_int_4[2];
1892 params[3] = v.value_int_4[3];
1893 break;
1894 case TYPE_INT64:
1895 params[0] = v.value_int;
1896 break;
1897 default:
1898 ; /* nothing - GL error was recorded */
1899 }
1900 }
1901
1902 void GLAPIENTRY
1903 _mesa_GetFixedv(GLenum pname, GLfixed *params)
1904 {
1905 const struct value_desc *d;
1906 union value v;
1907 GLmatrix *m;
1908 int shift, i;
1909 void *p;
1910
1911 d = find_value("glGetDoublev", pname, &p, &v);
1912 switch (d->type) {
1913 case TYPE_INVALID:
1914 break;
1915 case TYPE_CONST:
1916 params[0] = INT_TO_FIXED(d->offset);
1917 break;
1918
1919 case TYPE_FLOAT_4:
1920 case TYPE_FLOATN_4:
1921 params[3] = FLOAT_TO_FIXED(((GLfloat *) p)[3]);
1922 case TYPE_FLOAT_3:
1923 case TYPE_FLOATN_3:
1924 params[2] = FLOAT_TO_FIXED(((GLfloat *) p)[2]);
1925 case TYPE_FLOAT_2:
1926 case TYPE_FLOATN_2:
1927 params[1] = FLOAT_TO_FIXED(((GLfloat *) p)[1]);
1928 case TYPE_FLOAT:
1929 case TYPE_FLOATN:
1930 params[0] = FLOAT_TO_FIXED(((GLfloat *) p)[0]);
1931 break;
1932
1933 case TYPE_DOUBLEN:
1934 params[0] = FLOAT_TO_FIXED(((GLdouble *) p)[0]);
1935 break;
1936
1937 case TYPE_INT_4:
1938 params[3] = INT_TO_FIXED(((GLint *) p)[3]);
1939 case TYPE_INT_3:
1940 params[2] = INT_TO_FIXED(((GLint *) p)[2]);
1941 case TYPE_INT_2:
1942 case TYPE_ENUM_2:
1943 params[1] = INT_TO_FIXED(((GLint *) p)[1]);
1944 case TYPE_INT:
1945 case TYPE_ENUM:
1946 params[0] = INT_TO_FIXED(((GLint *) p)[0]);
1947 break;
1948
1949 case TYPE_INT_N:
1950 for (i = 0; i < v.value_int_n.n; i++)
1951 params[i] = INT_TO_FIXED(v.value_int_n.ints[i]);
1952 break;
1953
1954 case TYPE_INT64:
1955 params[0] = ((GLint64 *) p)[0];
1956 break;
1957
1958 case TYPE_BOOLEAN:
1959 params[0] = BOOLEAN_TO_FIXED(((GLboolean*) p)[0]);
1960 break;
1961
1962 case TYPE_MATRIX:
1963 m = *(GLmatrix **) p;
1964 for (i = 0; i < 16; i++)
1965 params[i] = FLOAT_TO_FIXED(m->m[i]);
1966 break;
1967
1968 case TYPE_MATRIX_T:
1969 m = *(GLmatrix **) p;
1970 for (i = 0; i < 16; i++)
1971 params[i] = FLOAT_TO_FIXED(m->m[transpose[i]]);
1972 break;
1973
1974 case TYPE_BIT_0:
1975 case TYPE_BIT_1:
1976 case TYPE_BIT_2:
1977 case TYPE_BIT_3:
1978 case TYPE_BIT_4:
1979 case TYPE_BIT_5:
1980 case TYPE_BIT_6:
1981 case TYPE_BIT_7:
1982 shift = d->type - TYPE_BIT_0;
1983 params[0] = BOOLEAN_TO_FIXED((*(GLbitfield *) p >> shift) & 1);
1984 break;
1985 }
1986 }