2 * Copyright (C) 2010 Brian Paul All Rights Reserved.
3 * Copyright (C) 2010 Intel Corporation
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:
12 * The above copyright notice and this permission notice shall be included
13 * in all copies or substantial portions of the Software.
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.
23 * Author: Kristian Høgsberg <krh@bitplanet.net>
29 #include "debug_output.h"
33 #include "extensions.h"
38 #include "texcompress.h"
40 #include "framebuffer.h"
41 #include "samplerobj.h"
44 /* This is a table driven implemetation of the glGet*v() functions.
45 * The basic idea is that most getters just look up an int somewhere
46 * in struct gl_context and then convert it to a bool or float according to
47 * which of glGetIntegerv() glGetBooleanv() etc is being called.
48 * Instead of generating code to do this, we can just record the enum
49 * value and the offset into struct gl_context in an array of structs. Then
50 * in glGet*(), we lookup the struct for the enum in question, and use
51 * the offset to get the int we need.
53 * Sometimes we need to look up a float, a boolean, a bit in a
54 * bitfield, a matrix or other types instead, so we need to track the
55 * type of the value in struct gl_context. And sometimes the value isn't in
56 * struct gl_context but in the drawbuffer, the array object, current texture
57 * unit, or maybe it's a computed value. So we need to also track
58 * where or how to find the value. Finally, we sometimes need to
59 * check that one of a number of extensions are enabled, the GL
60 * version or flush or call _mesa_update_state(). This is done by
61 * attaching optional extra information to the value description
62 * struct, it's sort of like an array of opcodes that describe extra
65 * Putting all this together we end up with struct value_desc below,
66 * and with a couple of macros to help, the table of struct value_desc
67 * is about as concise as the specification in the old python script.
70 #define FLOAT_TO_BOOLEAN(X) ( (X) ? GL_TRUE : GL_FALSE )
71 #define FLOAT_TO_FIXED(F) ( ((F) * 65536.0f > INT_MAX) ? INT_MAX : \
72 ((F) * 65536.0f < INT_MIN) ? INT_MIN : \
73 (GLint) ((F) * 65536.0f) )
75 #define INT_TO_BOOLEAN(I) ( (I) ? GL_TRUE : GL_FALSE )
76 #define INT_TO_FIXED(I) ( ((I) > SHRT_MAX) ? INT_MAX : \
77 ((I) < SHRT_MIN) ? INT_MIN : \
78 (GLint) ((I) * 65536) )
80 #define INT64_TO_BOOLEAN(I) ( (I) ? GL_TRUE : GL_FALSE )
81 #define INT64_TO_INT(I) ( (GLint)((I > INT_MAX) ? INT_MAX : ((I < INT_MIN) ? INT_MIN : (I))) )
83 #define BOOLEAN_TO_INT(B) ( (GLint) (B) )
84 #define BOOLEAN_TO_INT64(B) ( (GLint64) (B) )
85 #define BOOLEAN_TO_FLOAT(B) ( (B) ? 1.0F : 0.0F )
86 #define BOOLEAN_TO_FIXED(B) ( (GLint) ((B) ? 1 : 0) << 16 )
88 #define ENUM_TO_INT64(E) ( (GLint64) (E) )
89 #define ENUM_TO_FIXED(E) (E)
125 enum value_location
{
145 EXTRA_NEW_FRAG_CLAMP
,
146 EXTRA_VALID_DRAW_BUFFER
,
147 EXTRA_VALID_TEXTURE_UNIT
,
148 EXTRA_VALID_CLIP_DISTANCE
,
152 EXTRA_EXT_ATOMICS_GS
,
153 EXTRA_EXT_SHADER_IMAGE_GS
,
154 EXTRA_EXT_ATOMICS_TESS
,
155 EXTRA_EXT_SHADER_IMAGE_TESS
,
157 EXTRA_EXT_FB_NO_ATTACH_GS
,
161 #define NO_EXTRA NULL
166 GLubyte location
; /**< enum value_location */
167 GLubyte type
; /**< enum value_type */
174 GLfloat value_float_4
[4];
175 GLdouble value_double_2
[2];
176 GLmatrix
*value_matrix
;
178 GLint value_int_4
[4];
182 /* Sigh, see GL_COMPRESSED_TEXTURE_FORMATS_ARB handling */
186 GLboolean value_bool
;
189 #define BUFFER_FIELD(field, type) \
190 LOC_BUFFER, type, offsetof(struct gl_framebuffer, field)
191 #define CONTEXT_FIELD(field, type) \
192 LOC_CONTEXT, type, offsetof(struct gl_context, field)
193 #define ARRAY_FIELD(field, type) \
194 LOC_ARRAY, type, offsetof(struct gl_vertex_array_object, field)
195 #undef CONST /* already defined through windows.h */
196 #define CONST(value) \
197 LOC_CONTEXT, TYPE_CONST, value
199 #define BUFFER_INT(field) BUFFER_FIELD(field, TYPE_INT)
200 #define BUFFER_ENUM(field) BUFFER_FIELD(field, TYPE_ENUM)
201 #define BUFFER_BOOL(field) BUFFER_FIELD(field, TYPE_BOOLEAN)
203 #define CONTEXT_INT(field) CONTEXT_FIELD(field, TYPE_INT)
204 #define CONTEXT_INT2(field) CONTEXT_FIELD(field, TYPE_INT_2)
205 #define CONTEXT_INT64(field) CONTEXT_FIELD(field, TYPE_INT64)
206 #define CONTEXT_ENUM(field) CONTEXT_FIELD(field, TYPE_ENUM)
207 #define CONTEXT_ENUM2(field) CONTEXT_FIELD(field, TYPE_ENUM_2)
208 #define CONTEXT_BOOL(field) CONTEXT_FIELD(field, TYPE_BOOLEAN)
209 #define CONTEXT_BIT0(field) CONTEXT_FIELD(field, TYPE_BIT_0)
210 #define CONTEXT_BIT1(field) CONTEXT_FIELD(field, TYPE_BIT_1)
211 #define CONTEXT_BIT2(field) CONTEXT_FIELD(field, TYPE_BIT_2)
212 #define CONTEXT_BIT3(field) CONTEXT_FIELD(field, TYPE_BIT_3)
213 #define CONTEXT_BIT4(field) CONTEXT_FIELD(field, TYPE_BIT_4)
214 #define CONTEXT_BIT5(field) CONTEXT_FIELD(field, TYPE_BIT_5)
215 #define CONTEXT_BIT6(field) CONTEXT_FIELD(field, TYPE_BIT_6)
216 #define CONTEXT_BIT7(field) CONTEXT_FIELD(field, TYPE_BIT_7)
217 #define CONTEXT_FLOAT(field) CONTEXT_FIELD(field, TYPE_FLOAT)
218 #define CONTEXT_FLOAT2(field) CONTEXT_FIELD(field, TYPE_FLOAT_2)
219 #define CONTEXT_FLOAT3(field) CONTEXT_FIELD(field, TYPE_FLOAT_3)
220 #define CONTEXT_FLOAT4(field) CONTEXT_FIELD(field, TYPE_FLOAT_4)
221 #define CONTEXT_MATRIX(field) CONTEXT_FIELD(field, TYPE_MATRIX)
222 #define CONTEXT_MATRIX_T(field) CONTEXT_FIELD(field, TYPE_MATRIX_T)
224 #define ARRAY_INT(field) ARRAY_FIELD(field, TYPE_INT)
225 #define ARRAY_ENUM(field) ARRAY_FIELD(field, TYPE_ENUM)
226 #define ARRAY_BOOL(field) ARRAY_FIELD(field, TYPE_BOOLEAN)
229 offsetof(struct gl_extensions, f)
231 #define EXTRA_EXT(e) \
232 static const int extra_##e[] = { \
236 #define EXTRA_EXT2(e1, e2) \
237 static const int extra_##e1##_##e2[] = { \
238 EXT(e1), EXT(e2), EXTRA_END \
241 /* The 'extra' mechanism is a way to specify extra checks (such as
242 * extensions or specific gl versions) or actions (flush current, new
243 * buffers) that we need to do before looking up an enum. We need to
244 * declare them all up front so we can refer to them in the value_desc
247 * Each EXTRA_ will be executed. For EXTRA_* enums of extensions and API
248 * versions, listing multiple ones in an array means an error will be thrown
249 * only if none of them are available. If you need to check for "AND"
250 * behavior, you would need to make a custom EXTRA_ enum.
253 static const int extra_new_buffers
[] = {
258 static const int extra_new_frag_clamp
[] = {
259 EXTRA_NEW_FRAG_CLAMP
,
263 static const int extra_valid_draw_buffer
[] = {
264 EXTRA_VALID_DRAW_BUFFER
,
268 static const int extra_valid_texture_unit
[] = {
269 EXTRA_VALID_TEXTURE_UNIT
,
273 static const int extra_valid_clip_distance
[] = {
274 EXTRA_VALID_CLIP_DISTANCE
,
278 static const int extra_flush_current_valid_texture_unit
[] = {
280 EXTRA_VALID_TEXTURE_UNIT
,
284 static const int extra_flush_current
[] = {
289 static const int extra_EXT_texture_integer_and_new_buffers
[] = {
290 EXT(EXT_texture_integer
),
295 static const int extra_GLSL_130_es3
[] = {
301 static const int extra_texture_buffer_object
[] = {
304 EXT(ARB_texture_buffer_object
),
308 static const int extra_ARB_transform_feedback2_api_es3
[] = {
309 EXT(ARB_transform_feedback2
),
314 static const int extra_ARB_uniform_buffer_object_and_geometry_shader
[] = {
319 static const int extra_ARB_ES2_compatibility_api_es2
[] = {
320 EXT(ARB_ES2_compatibility
),
325 static const int extra_ARB_ES3_compatibility_api_es3
[] = {
326 EXT(ARB_ES3_compatibility
),
331 static const int extra_EXT_framebuffer_sRGB_and_new_buffers
[] = {
332 EXT(EXT_framebuffer_sRGB
),
337 static const int extra_EXT_packed_float
[] = {
338 EXT(EXT_packed_float
),
343 static const int extra_EXT_texture_array_es3
[] = {
344 EXT(EXT_texture_array
),
349 static const int extra_ARB_shader_atomic_counters_and_geometry_shader
[] = {
350 EXTRA_EXT_ATOMICS_GS
,
354 static const int extra_ARB_shader_image_load_store_and_geometry_shader
[] = {
355 EXTRA_EXT_SHADER_IMAGE_GS
,
359 static const int extra_ARB_shader_atomic_counters_and_tessellation
[] = {
360 EXTRA_EXT_ATOMICS_TESS
,
364 static const int extra_ARB_shader_image_load_store_and_tessellation
[] = {
365 EXTRA_EXT_SHADER_IMAGE_TESS
,
369 /* HACK: remove when ARB_compute_shader is actually supported */
370 static const int extra_ARB_compute_shader_es31
[] = {
371 EXT(ARB_compute_shader
),
376 static const int extra_ARB_shader_storage_buffer_object_es31
[] = {
377 EXT(ARB_shader_storage_buffer_object
),
382 static const int extra_ARB_shader_storage_buffer_object_and_geometry_shader
[] = {
387 static const int extra_ARB_framebuffer_no_attachments_and_geometry_shader
[] = {
388 EXTRA_EXT_FB_NO_ATTACH_GS
,
392 static const int extra_ARB_viewport_array_or_oes_geometry_shader
[] = {
393 EXT(ARB_viewport_array
),
398 static const int extra_ARB_gpu_shader5_or_oes_geometry_shader
[] = {
399 EXT(ARB_gpu_shader5
),
404 EXTRA_EXT(ARB_texture_cube_map
);
405 EXTRA_EXT(EXT_texture_array
);
406 EXTRA_EXT(NV_fog_distance
);
407 EXTRA_EXT(EXT_texture_filter_anisotropic
);
408 EXTRA_EXT(NV_point_sprite
);
409 EXTRA_EXT(NV_texture_rectangle
);
410 EXTRA_EXT(EXT_stencil_two_side
);
411 EXTRA_EXT(EXT_depth_bounds_test
);
412 EXTRA_EXT(ARB_depth_clamp
);
413 EXTRA_EXT(ATI_fragment_shader
);
414 EXTRA_EXT(EXT_provoking_vertex
);
415 EXTRA_EXT(ARB_fragment_shader
);
416 EXTRA_EXT(ARB_fragment_program
);
417 EXTRA_EXT2(ARB_framebuffer_object
, EXT_framebuffer_multisample
);
418 EXTRA_EXT(ARB_seamless_cube_map
);
420 EXTRA_EXT(ARB_vertex_shader
);
421 EXTRA_EXT(EXT_transform_feedback
);
422 EXTRA_EXT(ARB_transform_feedback3
);
423 EXTRA_EXT(EXT_pixel_buffer_object
);
424 EXTRA_EXT(ARB_vertex_program
);
425 EXTRA_EXT2(NV_point_sprite
, ARB_point_sprite
);
426 EXTRA_EXT2(ARB_vertex_program
, ARB_fragment_program
);
427 EXTRA_EXT(ARB_color_buffer_float
);
428 EXTRA_EXT(EXT_framebuffer_sRGB
);
429 EXTRA_EXT(OES_EGL_image_external
);
430 EXTRA_EXT(ARB_blend_func_extended
);
431 EXTRA_EXT(ARB_uniform_buffer_object
);
432 EXTRA_EXT(ARB_timer_query
);
433 EXTRA_EXT(ARB_texture_cube_map_array
);
434 EXTRA_EXT(ARB_texture_buffer_range
);
435 EXTRA_EXT(ARB_texture_multisample
);
436 EXTRA_EXT(ARB_texture_gather
);
437 EXTRA_EXT(ARB_shader_atomic_counters
);
438 EXTRA_EXT(ARB_draw_indirect
);
439 EXTRA_EXT(ARB_shader_image_load_store
);
440 EXTRA_EXT(ARB_viewport_array
);
441 EXTRA_EXT(ARB_compute_shader
);
442 EXTRA_EXT(ARB_gpu_shader5
);
443 EXTRA_EXT(ARB_query_buffer_object
);
444 EXTRA_EXT2(ARB_transform_feedback3
, ARB_gpu_shader5
);
445 EXTRA_EXT(INTEL_performance_query
);
446 EXTRA_EXT(ARB_explicit_uniform_location
);
447 EXTRA_EXT(ARB_clip_control
);
448 EXTRA_EXT(EXT_polygon_offset_clamp
);
449 EXTRA_EXT(ARB_framebuffer_no_attachments
);
450 EXTRA_EXT(ARB_tessellation_shader
);
451 EXTRA_EXT(ARB_shader_subroutine
);
452 EXTRA_EXT(ARB_shader_storage_buffer_object
);
453 EXTRA_EXT(ARB_indirect_parameters
);
454 EXTRA_EXT(ATI_meminfo
);
455 EXTRA_EXT(NVX_gpu_memory_info
);
458 extra_ARB_color_buffer_float_or_glcore
[] = {
459 EXT(ARB_color_buffer_float
),
465 extra_NV_primitive_restart
[] = {
466 EXT(NV_primitive_restart
),
470 static const int extra_version_30
[] = { EXTRA_VERSION_30
, EXTRA_END
};
471 static const int extra_version_31
[] = { EXTRA_VERSION_31
, EXTRA_END
};
472 static const int extra_version_32
[] = { EXTRA_VERSION_32
, EXTRA_END
};
473 static const int extra_version_40
[] = { EXTRA_VERSION_40
, EXTRA_END
};
475 static const int extra_gl30_es3
[] = {
481 static const int extra_gl32_es3
[] = {
487 static const int extra_version_32_OES_geometry_shader
[] = {
493 static const int extra_gl40_ARB_sample_shading
[] = {
495 EXT(ARB_sample_shading
),
500 extra_ARB_vertex_program_api_es2
[] = {
501 EXT(ARB_vertex_program
),
506 /* The ReadBuffer get token is valid under either full GL or under
507 * GLES2 if the NV_read_buffer extension is available. */
509 extra_NV_read_buffer_api_gl
[] = {
515 static const int extra_core_ARB_color_buffer_float_and_new_buffers
[] = {
517 EXT(ARB_color_buffer_float
),
522 /* This is the big table describing all the enums we accept in
523 * glGet*v(). The table is partitioned into six parts: enums
524 * understood by all GL APIs (OpenGL, GLES and GLES2), enums shared
525 * between OpenGL and GLES, enums exclusive to GLES, etc for the
526 * remaining combinations. To look up the enums valid in a given API
527 * we will use a hash table specific to that API. These tables are in
528 * turn generated at build time and included through get_hash.h.
531 #include "get_hash.h"
533 /* All we need now is a way to look up the value struct from the enum.
534 * The code generated by gcc for the old generated big switch
535 * statement is a big, balanced, open coded if/else tree, essentially
536 * an unrolled binary search. It would be natural to sort the new
537 * enum table and use bsearch(), but we will use a read-only hash
538 * table instead. bsearch() has a nice guaranteed worst case
539 * performance, but we're also guaranteed to hit that worst case
540 * (log2(n) iterations) for about half the enums. Instead, using an
541 * open addressing hash table, we can find the enum on the first try
542 * for 80% of the enums, 1 collision for 10% and never more than 5
543 * collisions for any enum (typical numbers). And the code is very
544 * simple, even though it feels a little magic. */
548 print_table_stats(int api
)
550 int i
, j
, collisions
[11], count
, hash
, mask
;
551 const struct value_desc
*d
;
552 const char *api_names
[] = {
553 [API_OPENGL_COMPAT
] = "GL",
554 [API_OPENGL_CORE
] = "GL_CORE",
555 [API_OPENGLES
] = "GLES",
556 [API_OPENGLES2
] = "GLES2",
558 const char *api_name
;
560 api_name
= api
< ARRAY_SIZE(api_names
) ? api_names
[api
] : "N/A";
562 mask
= ARRAY_SIZE(table(api
)) - 1;
563 memset(collisions
, 0, sizeof collisions
);
565 for (i
= 0; i
< ARRAY_SIZE(table(api
)); i
++) {
569 d
= &values
[table(api
)[i
]];
570 hash
= (d
->pname
* prime_factor
);
573 if (values
[table(api
)[hash
& mask
]].pname
== d
->pname
)
585 printf("number of enums for %s: %d (total %ld)\n",
586 api_name
, count
, ARRAY_SIZE(values
));
587 for (i
= 0; i
< ARRAY_SIZE(collisions
) - 1; i
++)
588 if (collisions
[i
] > 0)
589 printf(" %d enums with %d %scollisions\n",
590 collisions
[i
], i
, i
== 10 ? "or more " : "");
595 * Initialize the enum hash for a given API
597 * This is called from one_time_init() to insert the enum values that
598 * are valid for the API in question into the enum hash table.
600 * \param the current context, for determining the API in question
602 void _mesa_init_get_hash(struct gl_context
*ctx
)
605 print_table_stats(ctx
->API
);
612 * Handle irregular enums
614 * Some values don't conform to the "well-known type at context
615 * pointer + offset" pattern, so we have this function to catch all
616 * the corner cases. Typically, it's a computed value or a one-off
617 * pointer to a custom struct or something.
619 * In this case we can't return a pointer to the value, so we'll have
620 * to use the temporary variable 'v' declared back in the calling
621 * glGet*v() function to store the result.
623 * \param ctx the current context
624 * \param d the struct value_desc that describes the enum
625 * \param v pointer to the tmp declared in the calling glGet*v() function
628 find_custom_value(struct gl_context
*ctx
, const struct value_desc
*d
, union value
*v
)
630 struct gl_buffer_object
**buffer_obj
;
631 struct gl_vertex_attrib_array
*array
;
635 case GL_MAJOR_VERSION
:
636 v
->value_int
= ctx
->Version
/ 10;
638 case GL_MINOR_VERSION
:
639 v
->value_int
= ctx
->Version
% 10;
645 case GL_TEXTURE_CUBE_MAP_ARB
:
646 case GL_TEXTURE_RECTANGLE_NV
:
647 case GL_TEXTURE_EXTERNAL_OES
:
648 v
->value_bool
= _mesa_IsEnabled(d
->pname
);
651 case GL_LINE_STIPPLE_PATTERN
:
652 /* This is the only GLushort, special case it here by promoting
653 * to an int rather than introducing a new type. */
654 v
->value_int
= ctx
->Line
.StipplePattern
;
657 case GL_CURRENT_RASTER_TEXTURE_COORDS
:
658 unit
= ctx
->Texture
.CurrentUnit
;
659 v
->value_float_4
[0] = ctx
->Current
.RasterTexCoords
[unit
][0];
660 v
->value_float_4
[1] = ctx
->Current
.RasterTexCoords
[unit
][1];
661 v
->value_float_4
[2] = ctx
->Current
.RasterTexCoords
[unit
][2];
662 v
->value_float_4
[3] = ctx
->Current
.RasterTexCoords
[unit
][3];
665 case GL_CURRENT_TEXTURE_COORDS
:
666 unit
= ctx
->Texture
.CurrentUnit
;
667 v
->value_float_4
[0] = ctx
->Current
.Attrib
[VERT_ATTRIB_TEX0
+ unit
][0];
668 v
->value_float_4
[1] = ctx
->Current
.Attrib
[VERT_ATTRIB_TEX0
+ unit
][1];
669 v
->value_float_4
[2] = ctx
->Current
.Attrib
[VERT_ATTRIB_TEX0
+ unit
][2];
670 v
->value_float_4
[3] = ctx
->Current
.Attrib
[VERT_ATTRIB_TEX0
+ unit
][3];
673 case GL_COLOR_WRITEMASK
:
674 v
->value_int_4
[0] = ctx
->Color
.ColorMask
[0][RCOMP
] ? 1 : 0;
675 v
->value_int_4
[1] = ctx
->Color
.ColorMask
[0][GCOMP
] ? 1 : 0;
676 v
->value_int_4
[2] = ctx
->Color
.ColorMask
[0][BCOMP
] ? 1 : 0;
677 v
->value_int_4
[3] = ctx
->Color
.ColorMask
[0][ACOMP
] ? 1 : 0;
681 v
->value_bool
= ctx
->Current
.Attrib
[VERT_ATTRIB_EDGEFLAG
][0] == 1.0F
;
685 v
->value_enum
= ctx
->ReadBuffer
->ColorReadBuffer
;
688 case GL_MAP2_GRID_DOMAIN
:
689 v
->value_float_4
[0] = ctx
->Eval
.MapGrid2u1
;
690 v
->value_float_4
[1] = ctx
->Eval
.MapGrid2u2
;
691 v
->value_float_4
[2] = ctx
->Eval
.MapGrid2v1
;
692 v
->value_float_4
[3] = ctx
->Eval
.MapGrid2v2
;
695 case GL_TEXTURE_STACK_DEPTH
:
696 unit
= ctx
->Texture
.CurrentUnit
;
697 v
->value_int
= ctx
->TextureMatrixStack
[unit
].Depth
+ 1;
699 case GL_TEXTURE_MATRIX
:
700 unit
= ctx
->Texture
.CurrentUnit
;
701 v
->value_matrix
= ctx
->TextureMatrixStack
[unit
].Top
;
704 case GL_TEXTURE_COORD_ARRAY
:
705 case GL_TEXTURE_COORD_ARRAY_SIZE
:
706 case GL_TEXTURE_COORD_ARRAY_TYPE
:
707 case GL_TEXTURE_COORD_ARRAY_STRIDE
:
708 array
= &ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_TEX(ctx
->Array
.ActiveTexture
)];
709 v
->value_int
= *(GLuint
*) ((char *) array
+ d
->offset
);
712 case GL_ACTIVE_TEXTURE_ARB
:
713 v
->value_int
= GL_TEXTURE0_ARB
+ ctx
->Texture
.CurrentUnit
;
715 case GL_CLIENT_ACTIVE_TEXTURE_ARB
:
716 v
->value_int
= GL_TEXTURE0_ARB
+ ctx
->Array
.ActiveTexture
;
719 case GL_MODELVIEW_STACK_DEPTH
:
720 case GL_PROJECTION_STACK_DEPTH
:
721 v
->value_int
= *(GLint
*) ((char *) ctx
+ d
->offset
) + 1;
724 case GL_MAX_TEXTURE_SIZE
:
725 case GL_MAX_3D_TEXTURE_SIZE
:
726 case GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB
:
727 p
= (GLuint
*) ((char *) ctx
+ d
->offset
);
728 v
->value_int
= 1 << (*p
- 1);
732 v
->value_int_4
[0] = ctx
->Scissor
.ScissorArray
[0].X
;
733 v
->value_int_4
[1] = ctx
->Scissor
.ScissorArray
[0].Y
;
734 v
->value_int_4
[2] = ctx
->Scissor
.ScissorArray
[0].Width
;
735 v
->value_int_4
[3] = ctx
->Scissor
.ScissorArray
[0].Height
;
738 case GL_SCISSOR_TEST
:
739 v
->value_bool
= ctx
->Scissor
.EnableFlags
& 1;
744 ctx
->ListState
.CurrentList
? ctx
->ListState
.CurrentList
->Name
: 0;
747 if (!ctx
->CompileFlag
)
749 else if (ctx
->ExecuteFlag
)
750 v
->value_enum
= GL_COMPILE_AND_EXECUTE
;
752 v
->value_enum
= GL_COMPILE
;
756 v
->value_float_4
[0] = ctx
->ViewportArray
[0].X
;
757 v
->value_float_4
[1] = ctx
->ViewportArray
[0].Y
;
758 v
->value_float_4
[2] = ctx
->ViewportArray
[0].Width
;
759 v
->value_float_4
[3] = ctx
->ViewportArray
[0].Height
;
763 v
->value_double_2
[0] = ctx
->ViewportArray
[0].Near
;
764 v
->value_double_2
[1] = ctx
->ViewportArray
[0].Far
;
767 case GL_ACTIVE_STENCIL_FACE_EXT
:
768 v
->value_enum
= ctx
->Stencil
.ActiveFace
? GL_BACK
: GL_FRONT
;
771 case GL_STENCIL_FAIL
:
772 v
->value_enum
= ctx
->Stencil
.FailFunc
[ctx
->Stencil
.ActiveFace
];
774 case GL_STENCIL_FUNC
:
775 v
->value_enum
= ctx
->Stencil
.Function
[ctx
->Stencil
.ActiveFace
];
777 case GL_STENCIL_PASS_DEPTH_FAIL
:
778 v
->value_enum
= ctx
->Stencil
.ZFailFunc
[ctx
->Stencil
.ActiveFace
];
780 case GL_STENCIL_PASS_DEPTH_PASS
:
781 v
->value_enum
= ctx
->Stencil
.ZPassFunc
[ctx
->Stencil
.ActiveFace
];
784 v
->value_int
= _mesa_get_stencil_ref(ctx
, ctx
->Stencil
.ActiveFace
);
786 case GL_STENCIL_BACK_REF
:
787 v
->value_int
= _mesa_get_stencil_ref(ctx
, 1);
789 case GL_STENCIL_VALUE_MASK
:
790 v
->value_int
= ctx
->Stencil
.ValueMask
[ctx
->Stencil
.ActiveFace
];
792 case GL_STENCIL_WRITEMASK
:
793 v
->value_int
= ctx
->Stencil
.WriteMask
[ctx
->Stencil
.ActiveFace
];
796 case GL_NUM_EXTENSIONS
:
797 v
->value_int
= _mesa_get_extension_count(ctx
);
800 case GL_IMPLEMENTATION_COLOR_READ_TYPE_OES
:
801 v
->value_int
= _mesa_get_color_read_type(ctx
);
803 case GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES
:
804 v
->value_int
= _mesa_get_color_read_format(ctx
);
807 case GL_CURRENT_MATRIX_STACK_DEPTH_ARB
:
808 v
->value_int
= ctx
->CurrentStack
->Depth
+ 1;
810 case GL_CURRENT_MATRIX_ARB
:
811 case GL_TRANSPOSE_CURRENT_MATRIX_ARB
:
812 v
->value_matrix
= ctx
->CurrentStack
->Top
;
815 case GL_NUM_COMPRESSED_TEXTURE_FORMATS_ARB
:
816 v
->value_int
= _mesa_get_compressed_formats(ctx
, NULL
);
818 case GL_COMPRESSED_TEXTURE_FORMATS_ARB
:
820 _mesa_get_compressed_formats(ctx
, v
->value_int_n
.ints
);
821 assert(v
->value_int_n
.n
<= (int) ARRAY_SIZE(v
->value_int_n
.ints
));
824 case GL_MAX_VARYING_FLOATS_ARB
:
825 v
->value_int
= ctx
->Const
.MaxVarying
* 4;
828 /* Various object names */
830 case GL_TEXTURE_BINDING_1D
:
831 case GL_TEXTURE_BINDING_2D
:
832 case GL_TEXTURE_BINDING_3D
:
833 case GL_TEXTURE_BINDING_1D_ARRAY_EXT
:
834 case GL_TEXTURE_BINDING_2D_ARRAY_EXT
:
835 case GL_TEXTURE_BINDING_CUBE_MAP_ARB
:
836 case GL_TEXTURE_BINDING_RECTANGLE_NV
:
837 case GL_TEXTURE_BINDING_EXTERNAL_OES
:
838 case GL_TEXTURE_BINDING_CUBE_MAP_ARRAY
:
839 case GL_TEXTURE_BINDING_2D_MULTISAMPLE
:
840 case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY
:
841 unit
= ctx
->Texture
.CurrentUnit
;
843 ctx
->Texture
.Unit
[unit
].CurrentTex
[d
->offset
]->Name
;
846 /* GL_EXT_packed_float */
847 case GL_RGBA_SIGNED_COMPONENTS_EXT
:
849 /* Note: we only check the 0th color attachment. */
850 const struct gl_renderbuffer
*rb
=
851 ctx
->DrawBuffer
->_ColorDrawBuffers
[0];
852 if (rb
&& _mesa_is_format_signed(rb
->Format
)) {
853 /* Issue 17 of GL_EXT_packed_float: If a component (such as
854 * alpha) has zero bits, the component should not be considered
855 * signed and so the bit for the respective component should be
859 _mesa_get_format_bits(rb
->Format
, GL_RED_BITS
);
861 _mesa_get_format_bits(rb
->Format
, GL_GREEN_BITS
);
863 _mesa_get_format_bits(rb
->Format
, GL_BLUE_BITS
);
865 _mesa_get_format_bits(rb
->Format
, GL_ALPHA_BITS
);
867 _mesa_get_format_bits(rb
->Format
, GL_TEXTURE_LUMINANCE_SIZE
);
869 _mesa_get_format_bits(rb
->Format
, GL_TEXTURE_INTENSITY_SIZE
);
871 v
->value_int_4
[0] = r_bits
+ l_bits
+ i_bits
> 0;
872 v
->value_int_4
[1] = g_bits
+ l_bits
+ i_bits
> 0;
873 v
->value_int_4
[2] = b_bits
+ l_bits
+ i_bits
> 0;
874 v
->value_int_4
[3] = a_bits
+ i_bits
> 0;
880 v
->value_int_4
[3] = 0;
885 /* GL_ARB_vertex_buffer_object */
886 case GL_VERTEX_ARRAY_BUFFER_BINDING_ARB
:
887 case GL_NORMAL_ARRAY_BUFFER_BINDING_ARB
:
888 case GL_COLOR_ARRAY_BUFFER_BINDING_ARB
:
889 case GL_INDEX_ARRAY_BUFFER_BINDING_ARB
:
890 case GL_EDGE_FLAG_ARRAY_BUFFER_BINDING_ARB
:
891 case GL_SECONDARY_COLOR_ARRAY_BUFFER_BINDING_ARB
:
892 case GL_FOG_COORDINATE_ARRAY_BUFFER_BINDING_ARB
:
893 buffer_obj
= (struct gl_buffer_object
**)
894 ((char *) ctx
->Array
.VAO
+ d
->offset
);
895 v
->value_int
= (*buffer_obj
)->Name
;
897 case GL_ARRAY_BUFFER_BINDING_ARB
:
898 v
->value_int
= ctx
->Array
.ArrayBufferObj
->Name
;
900 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING_ARB
:
902 ctx
->Array
.VAO
->VertexBinding
[VERT_ATTRIB_TEX(ctx
->Array
.ActiveTexture
)].BufferObj
->Name
;
904 case GL_ELEMENT_ARRAY_BUFFER_BINDING_ARB
:
905 v
->value_int
= ctx
->Array
.VAO
->IndexBufferObj
->Name
;
908 /* ARB_vertex_array_bgra */
909 case GL_COLOR_ARRAY_SIZE
:
910 array
= &ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_COLOR0
];
911 v
->value_int
= array
->Format
== GL_BGRA
? GL_BGRA
: array
->Size
;
913 case GL_SECONDARY_COLOR_ARRAY_SIZE
:
914 array
= &ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_COLOR1
];
915 v
->value_int
= array
->Format
== GL_BGRA
? GL_BGRA
: array
->Size
;
918 /* ARB_copy_buffer */
919 case GL_COPY_READ_BUFFER
:
920 v
->value_int
= ctx
->CopyReadBuffer
->Name
;
922 case GL_COPY_WRITE_BUFFER
:
923 v
->value_int
= ctx
->CopyWriteBuffer
->Name
;
926 case GL_PIXEL_PACK_BUFFER_BINDING_EXT
:
927 v
->value_int
= ctx
->Pack
.BufferObj
->Name
;
929 case GL_PIXEL_UNPACK_BUFFER_BINDING_EXT
:
930 v
->value_int
= ctx
->Unpack
.BufferObj
->Name
;
932 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING
:
933 v
->value_int
= ctx
->TransformFeedback
.CurrentBuffer
->Name
;
935 case GL_TRANSFORM_FEEDBACK_BUFFER_PAUSED
:
936 v
->value_int
= ctx
->TransformFeedback
.CurrentObject
->Paused
;
938 case GL_TRANSFORM_FEEDBACK_BUFFER_ACTIVE
:
939 v
->value_int
= ctx
->TransformFeedback
.CurrentObject
->Active
;
941 case GL_TRANSFORM_FEEDBACK_BINDING
:
942 v
->value_int
= ctx
->TransformFeedback
.CurrentObject
->Name
;
944 case GL_CURRENT_PROGRAM
:
945 /* The Changelog of the ARB_separate_shader_objects spec says:
947 * 24 25 Jul 2011 pbrown Remove the language erroneously deleting
948 * CURRENT_PROGRAM. In the EXT extension, this
949 * token was aliased to ACTIVE_PROGRAM_EXT, and
950 * was used to indicate the last program set by
951 * either ActiveProgramEXT or UseProgram. In
952 * the ARB extension, the SSO active programs
953 * are now program pipeline object state and
954 * CURRENT_PROGRAM should still be used to query
955 * the last program set by UseProgram (bug 7822).
958 ctx
->Shader
.ActiveProgram
? ctx
->Shader
.ActiveProgram
->Name
: 0;
960 case GL_READ_FRAMEBUFFER_BINDING_EXT
:
961 v
->value_int
= ctx
->ReadBuffer
->Name
;
963 case GL_RENDERBUFFER_BINDING_EXT
:
965 ctx
->CurrentRenderbuffer
? ctx
->CurrentRenderbuffer
->Name
: 0;
967 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES
:
968 v
->value_int
= ctx
->Array
.VAO
->VertexBinding
[VERT_ATTRIB_POINT_SIZE
].BufferObj
->Name
;
972 if (_mesa_get_clamp_fragment_color(ctx
, ctx
->DrawBuffer
))
973 COPY_4FV(v
->value_float_4
, ctx
->Fog
.Color
);
975 COPY_4FV(v
->value_float_4
, ctx
->Fog
.ColorUnclamped
);
977 case GL_COLOR_CLEAR_VALUE
:
978 if (_mesa_get_clamp_fragment_color(ctx
, ctx
->DrawBuffer
)) {
979 v
->value_float_4
[0] = CLAMP(ctx
->Color
.ClearColor
.f
[0], 0.0F
, 1.0F
);
980 v
->value_float_4
[1] = CLAMP(ctx
->Color
.ClearColor
.f
[1], 0.0F
, 1.0F
);
981 v
->value_float_4
[2] = CLAMP(ctx
->Color
.ClearColor
.f
[2], 0.0F
, 1.0F
);
982 v
->value_float_4
[3] = CLAMP(ctx
->Color
.ClearColor
.f
[3], 0.0F
, 1.0F
);
984 COPY_4FV(v
->value_float_4
, ctx
->Color
.ClearColor
.f
);
986 case GL_BLEND_COLOR_EXT
:
987 if (_mesa_get_clamp_fragment_color(ctx
, ctx
->DrawBuffer
))
988 COPY_4FV(v
->value_float_4
, ctx
->Color
.BlendColor
);
990 COPY_4FV(v
->value_float_4
, ctx
->Color
.BlendColorUnclamped
);
992 case GL_ALPHA_TEST_REF
:
993 if (_mesa_get_clamp_fragment_color(ctx
, ctx
->DrawBuffer
))
994 v
->value_float
= ctx
->Color
.AlphaRef
;
996 v
->value_float
= ctx
->Color
.AlphaRefUnclamped
;
998 case GL_MAX_VERTEX_UNIFORM_VECTORS
:
999 v
->value_int
= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxUniformComponents
/ 4;
1002 case GL_MAX_FRAGMENT_UNIFORM_VECTORS
:
1003 v
->value_int
= ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxUniformComponents
/ 4;
1006 /* GL_ARB_texture_buffer_object */
1007 case GL_TEXTURE_BUFFER_ARB
:
1008 v
->value_int
= ctx
->Texture
.BufferObject
->Name
;
1010 case GL_TEXTURE_BINDING_BUFFER_ARB
:
1011 unit
= ctx
->Texture
.CurrentUnit
;
1013 ctx
->Texture
.Unit
[unit
].CurrentTex
[TEXTURE_BUFFER_INDEX
]->Name
;
1015 case GL_TEXTURE_BUFFER_DATA_STORE_BINDING_ARB
:
1017 struct gl_buffer_object
*buf
=
1018 ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
]
1019 .CurrentTex
[TEXTURE_BUFFER_INDEX
]->BufferObject
;
1020 v
->value_int
= buf
? buf
->Name
: 0;
1023 case GL_TEXTURE_BUFFER_FORMAT_ARB
:
1024 v
->value_int
= ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
]
1025 .CurrentTex
[TEXTURE_BUFFER_INDEX
]->BufferObjectFormat
;
1028 /* GL_ARB_sampler_objects */
1029 case GL_SAMPLER_BINDING
:
1031 struct gl_sampler_object
*samp
=
1032 ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
].Sampler
;
1033 v
->value_int
= samp
? samp
->Name
: 0;
1036 /* GL_ARB_uniform_buffer_object */
1037 case GL_UNIFORM_BUFFER_BINDING
:
1038 v
->value_int
= ctx
->UniformBuffer
->Name
;
1040 /* GL_ARB_shader_storage_buffer_object */
1041 case GL_SHADER_STORAGE_BUFFER_BINDING
:
1042 v
->value_int
= ctx
->ShaderStorageBuffer
->Name
;
1044 /* GL_ARB_query_buffer_object */
1045 case GL_QUERY_BUFFER_BINDING
:
1046 v
->value_int
= ctx
->QueryBuffer
->Name
;
1048 /* GL_ARB_timer_query */
1050 if (ctx
->Driver
.GetTimestamp
) {
1051 v
->value_int64
= ctx
->Driver
.GetTimestamp(ctx
);
1054 _mesa_problem(ctx
, "driver doesn't implement GetTimestamp");
1058 case GL_DEBUG_LOGGED_MESSAGES
:
1059 case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH
:
1060 case GL_DEBUG_GROUP_STACK_DEPTH
:
1061 v
->value_int
= _mesa_get_debug_state_int(ctx
, d
->pname
);
1063 /* GL_ARB_shader_atomic_counters */
1064 case GL_ATOMIC_COUNTER_BUFFER_BINDING
:
1065 if (ctx
->AtomicBuffer
) {
1066 v
->value_int
= ctx
->AtomicBuffer
->Name
;
1071 /* GL_ARB_draw_indirect */
1072 case GL_DRAW_INDIRECT_BUFFER_BINDING
:
1073 v
->value_int
= ctx
->DrawIndirectBuffer
->Name
;
1075 /* GL_ARB_indirect_parameters */
1076 case GL_PARAMETER_BUFFER_BINDING_ARB
:
1077 v
->value_int
= ctx
->ParameterBuffer
->Name
;
1079 /* GL_ARB_separate_shader_objects */
1080 case GL_PROGRAM_PIPELINE_BINDING
:
1081 if (ctx
->Pipeline
.Current
) {
1082 v
->value_int
= ctx
->Pipeline
.Current
->Name
;
1087 /* GL_ARB_compute_shader */
1088 case GL_DISPATCH_INDIRECT_BUFFER_BINDING
:
1089 v
->value_int
= ctx
->DispatchIndirectBuffer
->Name
;
1091 /* GL_ARB_multisample */
1093 v
->value_int
= _mesa_geometric_samples(ctx
->DrawBuffer
);
1095 case GL_SAMPLE_BUFFERS
:
1096 v
->value_int
= _mesa_geometric_samples(ctx
->DrawBuffer
) > 0;
1098 /* GL_ATI_meminfo & GL_NVX_gpu_memory_info */
1099 case GL_VBO_FREE_MEMORY_ATI
:
1100 case GL_TEXTURE_FREE_MEMORY_ATI
:
1101 case GL_RENDERBUFFER_FREE_MEMORY_ATI
:
1102 case GL_GPU_MEMORY_INFO_DEDICATED_VIDMEM_NVX
:
1103 case GL_GPU_MEMORY_INFO_TOTAL_AVAILABLE_MEMORY_NVX
:
1104 case GL_GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX
:
1105 case GL_GPU_MEMORY_INFO_EVICTION_COUNT_NVX
:
1106 case GL_GPU_MEMORY_INFO_EVICTED_MEMORY_NVX
:
1108 struct gl_memory_info info
;
1110 ctx
->Driver
.QueryMemoryInfo(ctx
, &info
);
1112 if (d
->pname
== GL_GPU_MEMORY_INFO_DEDICATED_VIDMEM_NVX
)
1113 v
->value_int
= info
.total_device_memory
;
1114 else if (d
->pname
== GL_GPU_MEMORY_INFO_TOTAL_AVAILABLE_MEMORY_NVX
)
1115 v
->value_int
= info
.total_device_memory
+
1116 info
.total_staging_memory
;
1117 else if (d
->pname
== GL_GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX
)
1118 v
->value_int
= info
.avail_device_memory
;
1119 else if (d
->pname
== GL_GPU_MEMORY_INFO_EVICTION_COUNT_NVX
)
1120 v
->value_int
= info
.nr_device_memory_evictions
;
1121 else if (d
->pname
== GL_GPU_MEMORY_INFO_EVICTED_MEMORY_NVX
)
1122 v
->value_int
= info
.device_memory_evicted
;
1124 /* ATI free memory enums.
1126 * Since the GPU memory is (usually) page-table based, every two
1127 * consecutive elements are equal. From the GL_ATI_meminfo
1130 * "param[0] - total memory free in the pool
1131 * param[1] - largest available free block in the pool
1132 * param[2] - total auxiliary memory free
1133 * param[3] - largest auxiliary free block"
1135 * All three (VBO, TEXTURE, RENDERBUFFER) queries return
1136 * the same numbers here.
1138 v
->value_int_4
[0] = info
.avail_device_memory
;
1139 v
->value_int_4
[1] = info
.avail_device_memory
;
1140 v
->value_int_4
[2] = info
.avail_staging_memory
;
1141 v
->value_int_4
[3] = info
.avail_staging_memory
;
1149 * Check extra constraints on a struct value_desc descriptor
1151 * If a struct value_desc has a non-NULL extra pointer, it means that
1152 * there are a number of extra constraints to check or actions to
1153 * perform. The extras is just an integer array where each integer
1154 * encode different constraints or actions.
1156 * \param ctx current context
1157 * \param func name of calling glGet*v() function for error reporting
1158 * \param d the struct value_desc that has the extra constraints
1160 * \return GL_FALSE if all of the constraints were not satisfied,
1161 * otherwise GL_TRUE.
1164 check_extra(struct gl_context
*ctx
, const char *func
, const struct value_desc
*d
)
1166 const GLuint version
= ctx
->Version
;
1167 GLboolean api_check
= GL_FALSE
;
1168 GLboolean api_found
= GL_FALSE
;
1171 for (e
= d
->extra
; *e
!= EXTRA_END
; e
++) {
1173 case EXTRA_VERSION_30
:
1174 api_check
= GL_TRUE
;
1176 api_found
= GL_TRUE
;
1178 case EXTRA_VERSION_31
:
1179 api_check
= GL_TRUE
;
1181 api_found
= GL_TRUE
;
1183 case EXTRA_VERSION_32
:
1184 api_check
= GL_TRUE
;
1186 api_found
= GL_TRUE
;
1188 case EXTRA_NEW_FRAG_CLAMP
:
1189 if (ctx
->NewState
& (_NEW_BUFFERS
| _NEW_FRAG_CLAMP
))
1190 _mesa_update_state(ctx
);
1193 api_check
= GL_TRUE
;
1194 if (ctx
->API
== API_OPENGLES2
)
1195 api_found
= GL_TRUE
;
1198 api_check
= GL_TRUE
;
1199 if (_mesa_is_gles3(ctx
))
1200 api_found
= GL_TRUE
;
1202 case EXTRA_API_ES31
:
1203 api_check
= GL_TRUE
;
1204 if (_mesa_is_gles31(ctx
))
1205 api_found
= GL_TRUE
;
1208 api_check
= GL_TRUE
;
1209 if (_mesa_is_desktop_gl(ctx
))
1210 api_found
= GL_TRUE
;
1212 case EXTRA_API_GL_CORE
:
1213 api_check
= GL_TRUE
;
1214 if (ctx
->API
== API_OPENGL_CORE
)
1215 api_found
= GL_TRUE
;
1217 case EXTRA_NEW_BUFFERS
:
1218 if (ctx
->NewState
& _NEW_BUFFERS
)
1219 _mesa_update_state(ctx
);
1221 case EXTRA_FLUSH_CURRENT
:
1222 FLUSH_CURRENT(ctx
, 0);
1224 case EXTRA_VALID_DRAW_BUFFER
:
1225 if (d
->pname
- GL_DRAW_BUFFER0_ARB
>= ctx
->Const
.MaxDrawBuffers
) {
1226 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(draw buffer %u)",
1227 func
, d
->pname
- GL_DRAW_BUFFER0_ARB
);
1231 case EXTRA_VALID_TEXTURE_UNIT
:
1232 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureCoordUnits
) {
1233 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(texture %u)",
1234 func
, ctx
->Texture
.CurrentUnit
);
1238 case EXTRA_VALID_CLIP_DISTANCE
:
1239 if (d
->pname
- GL_CLIP_DISTANCE0
>= ctx
->Const
.MaxClipPlanes
) {
1240 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(clip distance %u)",
1241 func
, d
->pname
- GL_CLIP_DISTANCE0
);
1245 case EXTRA_GLSL_130
:
1246 api_check
= GL_TRUE
;
1247 if (ctx
->Const
.GLSLVersion
>= 130)
1248 api_found
= GL_TRUE
;
1250 case EXTRA_EXT_UBO_GS
:
1251 api_check
= GL_TRUE
;
1252 if (ctx
->Extensions
.ARB_uniform_buffer_object
&&
1253 _mesa_has_geometry_shaders(ctx
))
1254 api_found
= GL_TRUE
;
1256 case EXTRA_EXT_ATOMICS_GS
:
1257 api_check
= GL_TRUE
;
1258 if (ctx
->Extensions
.ARB_shader_atomic_counters
&&
1259 _mesa_has_geometry_shaders(ctx
))
1260 api_found
= GL_TRUE
;
1262 case EXTRA_EXT_SHADER_IMAGE_GS
:
1263 api_check
= GL_TRUE
;
1264 if (ctx
->Extensions
.ARB_shader_image_load_store
&&
1265 _mesa_has_geometry_shaders(ctx
))
1266 api_found
= GL_TRUE
;
1268 case EXTRA_EXT_ATOMICS_TESS
:
1269 api_check
= GL_TRUE
;
1270 api_found
= ctx
->Extensions
.ARB_shader_atomic_counters
&&
1271 _mesa_has_tessellation(ctx
);
1273 case EXTRA_EXT_SHADER_IMAGE_TESS
:
1274 api_check
= GL_TRUE
;
1275 api_found
= ctx
->Extensions
.ARB_shader_image_load_store
&&
1276 _mesa_has_tessellation(ctx
);
1278 case EXTRA_EXT_SSBO_GS
:
1279 api_check
= GL_TRUE
;
1280 if (ctx
->Extensions
.ARB_shader_storage_buffer_object
&&
1281 _mesa_has_geometry_shaders(ctx
))
1282 api_found
= GL_TRUE
;
1284 case EXTRA_EXT_FB_NO_ATTACH_GS
:
1285 api_check
= GL_TRUE
;
1286 if (ctx
->Extensions
.ARB_framebuffer_no_attachments
&&
1287 (_mesa_is_desktop_gl(ctx
) ||
1288 _mesa_has_OES_geometry_shader(ctx
)))
1289 api_found
= GL_TRUE
;
1291 case EXTRA_EXT_ES_GS
:
1292 api_check
= GL_TRUE
;
1293 if (_mesa_has_OES_geometry_shader(ctx
))
1294 api_found
= GL_TRUE
;
1298 default: /* *e is a offset into the extension struct */
1299 api_check
= GL_TRUE
;
1300 if (*(GLboolean
*) ((char *) &ctx
->Extensions
+ *e
))
1301 api_found
= GL_TRUE
;
1306 if (api_check
&& !api_found
) {
1307 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=%s)", func
,
1308 _mesa_enum_to_string(d
->pname
));
1315 static const struct value_desc error_value
=
1316 { 0, 0, TYPE_INVALID
, NO_OFFSET
, NO_EXTRA
};
1319 * Find the struct value_desc corresponding to the enum 'pname'.
1321 * We hash the enum value to get an index into the 'table' array,
1322 * which holds the index in the 'values' array of struct value_desc.
1323 * Once we've found the entry, we do the extra checks, if any, then
1324 * look up the value and return a pointer to it.
1326 * If the value has to be computed (for example, it's the result of a
1327 * function call or we need to add 1 to it), we use the tmp 'v' to
1330 * \param func name of glGet*v() func for error reporting
1331 * \param pname the enum value we're looking up
1332 * \param p is were we return the pointer to the value
1333 * \param v a tmp union value variable in the calling glGet*v() function
1335 * \return the struct value_desc corresponding to the enum or a struct
1336 * value_desc of TYPE_INVALID if not found. This lets the calling
1337 * glGet*v() function jump right into a switch statement and
1338 * handle errors there instead of having to check for NULL.
1340 static const struct value_desc
*
1341 find_value(const char *func
, GLenum pname
, void **p
, union value
*v
)
1343 GET_CURRENT_CONTEXT(ctx
);
1344 struct gl_texture_unit
*unit
;
1346 const struct value_desc
*d
;
1350 /* We index into the table_set[] list of per-API hash tables using the API's
1351 * value in the gl_api enum. Since GLES 3 doesn't have an API_OPENGL* enum
1352 * value since it's compatible with GLES2 its entry in table_set[] is at the
1355 STATIC_ASSERT(ARRAY_SIZE(table_set
) == API_OPENGL_LAST
+ 3);
1356 if (_mesa_is_gles3(ctx
)) {
1357 api
= API_OPENGL_LAST
+ 1;
1359 if (_mesa_is_gles31(ctx
)) {
1360 api
= API_OPENGL_LAST
+ 2;
1362 mask
= ARRAY_SIZE(table(api
)) - 1;
1363 hash
= (pname
* prime_factor
);
1365 int idx
= table(api
)[hash
& mask
];
1367 /* If the enum isn't valid, the hash walk ends with index 0,
1368 * pointing to the first entry of values[] which doesn't hold
1369 * any valid enum. */
1370 if (unlikely(idx
== 0)) {
1371 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=%s)", func
,
1372 _mesa_enum_to_string(pname
));
1373 return &error_value
;
1377 if (likely(d
->pname
== pname
))
1383 if (unlikely(d
->extra
&& !check_extra(ctx
, func
, d
)))
1384 return &error_value
;
1386 switch (d
->location
) {
1388 *p
= ((char *) ctx
->DrawBuffer
+ d
->offset
);
1391 *p
= ((char *) ctx
+ d
->offset
);
1394 *p
= ((char *) ctx
->Array
.VAO
+ d
->offset
);
1397 unit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1398 *p
= ((char *) unit
+ d
->offset
);
1401 find_custom_value(ctx
, d
, v
);
1409 /* silence warning */
1410 return &error_value
;
1413 static const int transpose
[] = {
1421 _mesa_GetBooleanv(GLenum pname
, GLboolean
*params
)
1423 const struct value_desc
*d
;
1429 d
= find_value("glGetBooleanv", pname
, &p
, &v
);
1434 params
[0] = INT_TO_BOOLEAN(d
->offset
);
1439 params
[3] = FLOAT_TO_BOOLEAN(((GLfloat
*) p
)[3]);
1442 params
[2] = FLOAT_TO_BOOLEAN(((GLfloat
*) p
)[2]);
1445 params
[1] = FLOAT_TO_BOOLEAN(((GLfloat
*) p
)[1]);
1448 params
[0] = FLOAT_TO_BOOLEAN(((GLfloat
*) p
)[0]);
1451 case TYPE_DOUBLEN_2
:
1452 params
[1] = FLOAT_TO_BOOLEAN(((GLdouble
*) p
)[1]);
1454 params
[0] = FLOAT_TO_BOOLEAN(((GLdouble
*) p
)[0]);
1458 params
[3] = INT_TO_BOOLEAN(((GLint
*) p
)[3]);
1460 params
[2] = INT_TO_BOOLEAN(((GLint
*) p
)[2]);
1463 params
[1] = INT_TO_BOOLEAN(((GLint
*) p
)[1]);
1466 params
[0] = INT_TO_BOOLEAN(((GLint
*) p
)[0]);
1470 for (i
= 0; i
< v
.value_int_n
.n
; i
++)
1471 params
[i
] = INT_TO_BOOLEAN(v
.value_int_n
.ints
[i
]);
1475 params
[0] = INT64_TO_BOOLEAN(((GLint64
*) p
)[0]);
1479 params
[0] = ((GLboolean
*) p
)[0];
1483 m
= *(GLmatrix
**) p
;
1484 for (i
= 0; i
< 16; i
++)
1485 params
[i
] = FLOAT_TO_BOOLEAN(m
->m
[i
]);
1489 m
= *(GLmatrix
**) p
;
1490 for (i
= 0; i
< 16; i
++)
1491 params
[i
] = FLOAT_TO_BOOLEAN(m
->m
[transpose
[i
]]);
1502 shift
= d
->type
- TYPE_BIT_0
;
1503 params
[0] = (*(GLbitfield
*) p
>> shift
) & 1;
1509 _mesa_GetFloatv(GLenum pname
, GLfloat
*params
)
1511 const struct value_desc
*d
;
1517 d
= find_value("glGetFloatv", pname
, &p
, &v
);
1522 params
[0] = (GLfloat
) d
->offset
;
1527 params
[3] = ((GLfloat
*) p
)[3];
1530 params
[2] = ((GLfloat
*) p
)[2];
1533 params
[1] = ((GLfloat
*) p
)[1];
1536 params
[0] = ((GLfloat
*) p
)[0];
1539 case TYPE_DOUBLEN_2
:
1540 params
[1] = (GLfloat
) (((GLdouble
*) p
)[1]);
1542 params
[0] = (GLfloat
) (((GLdouble
*) p
)[0]);
1546 params
[3] = (GLfloat
) (((GLint
*) p
)[3]);
1548 params
[2] = (GLfloat
) (((GLint
*) p
)[2]);
1551 params
[1] = (GLfloat
) (((GLint
*) p
)[1]);
1554 params
[0] = (GLfloat
) (((GLint
*) p
)[0]);
1558 for (i
= 0; i
< v
.value_int_n
.n
; i
++)
1559 params
[i
] = INT_TO_FLOAT(v
.value_int_n
.ints
[i
]);
1563 params
[0] = (GLfloat
) (((GLint64
*) p
)[0]);
1567 params
[0] = BOOLEAN_TO_FLOAT(*(GLboolean
*) p
);
1571 m
= *(GLmatrix
**) p
;
1572 for (i
= 0; i
< 16; i
++)
1573 params
[i
] = m
->m
[i
];
1577 m
= *(GLmatrix
**) p
;
1578 for (i
= 0; i
< 16; i
++)
1579 params
[i
] = m
->m
[transpose
[i
]];
1590 shift
= d
->type
- TYPE_BIT_0
;
1591 params
[0] = BOOLEAN_TO_FLOAT((*(GLbitfield
*) p
>> shift
) & 1);
1597 _mesa_GetIntegerv(GLenum pname
, GLint
*params
)
1599 const struct value_desc
*d
;
1605 d
= find_value("glGetIntegerv", pname
, &p
, &v
);
1610 params
[0] = d
->offset
;
1614 params
[3] = IROUND(((GLfloat
*) p
)[3]);
1616 params
[2] = IROUND(((GLfloat
*) p
)[2]);
1618 params
[1] = IROUND(((GLfloat
*) p
)[1]);
1620 params
[0] = IROUND(((GLfloat
*) p
)[0]);
1624 params
[3] = FLOAT_TO_INT(((GLfloat
*) p
)[3]);
1626 params
[2] = FLOAT_TO_INT(((GLfloat
*) p
)[2]);
1628 params
[1] = FLOAT_TO_INT(((GLfloat
*) p
)[1]);
1630 params
[0] = FLOAT_TO_INT(((GLfloat
*) p
)[0]);
1633 case TYPE_DOUBLEN_2
:
1634 params
[1] = FLOAT_TO_INT(((GLdouble
*) p
)[1]);
1636 params
[0] = FLOAT_TO_INT(((GLdouble
*) p
)[0]);
1640 params
[3] = ((GLint
*) p
)[3];
1642 params
[2] = ((GLint
*) p
)[2];
1645 params
[1] = ((GLint
*) p
)[1];
1648 params
[0] = ((GLint
*) p
)[0];
1652 for (i
= 0; i
< v
.value_int_n
.n
; i
++)
1653 params
[i
] = v
.value_int_n
.ints
[i
];
1657 params
[0] = INT64_TO_INT(((GLint64
*) p
)[0]);
1661 params
[0] = BOOLEAN_TO_INT(*(GLboolean
*) p
);
1665 m
= *(GLmatrix
**) p
;
1666 for (i
= 0; i
< 16; i
++)
1667 params
[i
] = FLOAT_TO_INT(m
->m
[i
]);
1671 m
= *(GLmatrix
**) p
;
1672 for (i
= 0; i
< 16; i
++)
1673 params
[i
] = FLOAT_TO_INT(m
->m
[transpose
[i
]]);
1684 shift
= d
->type
- TYPE_BIT_0
;
1685 params
[0] = (*(GLbitfield
*) p
>> shift
) & 1;
1691 _mesa_GetInteger64v(GLenum pname
, GLint64
*params
)
1693 const struct value_desc
*d
;
1699 d
= find_value("glGetInteger64v", pname
, &p
, &v
);
1704 params
[0] = d
->offset
;
1708 params
[3] = IROUND64(((GLfloat
*) p
)[3]);
1710 params
[2] = IROUND64(((GLfloat
*) p
)[2]);
1712 params
[1] = IROUND64(((GLfloat
*) p
)[1]);
1714 params
[0] = IROUND64(((GLfloat
*) p
)[0]);
1718 params
[3] = FLOAT_TO_INT64(((GLfloat
*) p
)[3]);
1720 params
[2] = FLOAT_TO_INT64(((GLfloat
*) p
)[2]);
1722 params
[1] = FLOAT_TO_INT64(((GLfloat
*) p
)[1]);
1724 params
[0] = FLOAT_TO_INT64(((GLfloat
*) p
)[0]);
1727 case TYPE_DOUBLEN_2
:
1728 params
[1] = FLOAT_TO_INT64(((GLdouble
*) p
)[1]);
1730 params
[0] = FLOAT_TO_INT64(((GLdouble
*) p
)[0]);
1734 params
[3] = ((GLint
*) p
)[3];
1736 params
[2] = ((GLint
*) p
)[2];
1739 params
[1] = ((GLint
*) p
)[1];
1742 params
[0] = ((GLint
*) p
)[0];
1746 for (i
= 0; i
< v
.value_int_n
.n
; i
++)
1747 params
[i
] = INT_TO_BOOLEAN(v
.value_int_n
.ints
[i
]);
1751 params
[0] = ((GLint64
*) p
)[0];
1755 params
[0] = ((GLboolean
*) p
)[0];
1759 m
= *(GLmatrix
**) p
;
1760 for (i
= 0; i
< 16; i
++)
1761 params
[i
] = FLOAT_TO_INT64(m
->m
[i
]);
1765 m
= *(GLmatrix
**) p
;
1766 for (i
= 0; i
< 16; i
++)
1767 params
[i
] = FLOAT_TO_INT64(m
->m
[transpose
[i
]]);
1778 shift
= d
->type
- TYPE_BIT_0
;
1779 params
[0] = (*(GLbitfield
*) p
>> shift
) & 1;
1785 _mesa_GetDoublev(GLenum pname
, GLdouble
*params
)
1787 const struct value_desc
*d
;
1793 d
= find_value("glGetDoublev", pname
, &p
, &v
);
1798 params
[0] = d
->offset
;
1803 params
[3] = ((GLfloat
*) p
)[3];
1806 params
[2] = ((GLfloat
*) p
)[2];
1809 params
[1] = ((GLfloat
*) p
)[1];
1812 params
[0] = ((GLfloat
*) p
)[0];
1815 case TYPE_DOUBLEN_2
:
1816 params
[1] = ((GLdouble
*) p
)[1];
1818 params
[0] = ((GLdouble
*) p
)[0];
1822 params
[3] = ((GLint
*) p
)[3];
1824 params
[2] = ((GLint
*) p
)[2];
1827 params
[1] = ((GLint
*) p
)[1];
1830 params
[0] = ((GLint
*) p
)[0];
1834 for (i
= 0; i
< v
.value_int_n
.n
; i
++)
1835 params
[i
] = v
.value_int_n
.ints
[i
];
1839 params
[0] = (GLdouble
) (((GLint64
*) p
)[0]);
1843 params
[0] = *(GLboolean
*) p
;
1847 m
= *(GLmatrix
**) p
;
1848 for (i
= 0; i
< 16; i
++)
1849 params
[i
] = m
->m
[i
];
1853 m
= *(GLmatrix
**) p
;
1854 for (i
= 0; i
< 16; i
++)
1855 params
[i
] = m
->m
[transpose
[i
]];
1866 shift
= d
->type
- TYPE_BIT_0
;
1867 params
[0] = (*(GLbitfield
*) p
>> shift
) & 1;
1873 * Convert a GL texture binding enum such as GL_TEXTURE_BINDING_2D
1874 * into the corresponding Mesa texture target index.
1875 * \return TEXTURE_x_INDEX or -1 if binding is invalid
1878 tex_binding_to_index(const struct gl_context
*ctx
, GLenum binding
)
1881 case GL_TEXTURE_BINDING_1D
:
1882 return _mesa_is_desktop_gl(ctx
) ? TEXTURE_1D_INDEX
: -1;
1883 case GL_TEXTURE_BINDING_2D
:
1884 return TEXTURE_2D_INDEX
;
1885 case GL_TEXTURE_BINDING_3D
:
1886 return ctx
->API
!= API_OPENGLES
? TEXTURE_3D_INDEX
: -1;
1887 case GL_TEXTURE_BINDING_CUBE_MAP
:
1888 return ctx
->Extensions
.ARB_texture_cube_map
1889 ? TEXTURE_CUBE_INDEX
: -1;
1890 case GL_TEXTURE_BINDING_RECTANGLE
:
1891 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.NV_texture_rectangle
1892 ? TEXTURE_RECT_INDEX
: -1;
1893 case GL_TEXTURE_BINDING_1D_ARRAY
:
1894 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
1895 ? TEXTURE_1D_ARRAY_INDEX
: -1;
1896 case GL_TEXTURE_BINDING_2D_ARRAY
:
1897 return (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
)
1898 || _mesa_is_gles3(ctx
)
1899 ? TEXTURE_2D_ARRAY_INDEX
: -1;
1900 case GL_TEXTURE_BINDING_BUFFER
:
1901 return ctx
->API
== API_OPENGL_CORE
&&
1902 ctx
->Extensions
.ARB_texture_buffer_object
?
1903 TEXTURE_BUFFER_INDEX
: -1;
1904 case GL_TEXTURE_BINDING_CUBE_MAP_ARRAY
:
1905 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_cube_map_array
1906 ? TEXTURE_CUBE_ARRAY_INDEX
: -1;
1907 case GL_TEXTURE_BINDING_2D_MULTISAMPLE
:
1908 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_multisample
1909 ? TEXTURE_2D_MULTISAMPLE_INDEX
: -1;
1910 case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY
:
1911 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_multisample
1912 ? TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX
: -1;
1918 static enum value_type
1919 find_value_indexed(const char *func
, GLenum pname
, GLuint index
, union value
*v
)
1921 GET_CURRENT_CONTEXT(ctx
);
1926 if (index
>= ctx
->Const
.MaxDrawBuffers
)
1928 if (!ctx
->Extensions
.EXT_draw_buffers2
)
1930 v
->value_int
= (ctx
->Color
.BlendEnabled
>> index
) & 1;
1935 case GL_BLEND_SRC_RGB
:
1936 if (index
>= ctx
->Const
.MaxDrawBuffers
)
1938 if (!ctx
->Extensions
.ARB_draw_buffers_blend
)
1940 v
->value_int
= ctx
->Color
.Blend
[index
].SrcRGB
;
1942 case GL_BLEND_SRC_ALPHA
:
1943 if (index
>= ctx
->Const
.MaxDrawBuffers
)
1945 if (!ctx
->Extensions
.ARB_draw_buffers_blend
)
1947 v
->value_int
= ctx
->Color
.Blend
[index
].SrcA
;
1951 case GL_BLEND_DST_RGB
:
1952 if (index
>= ctx
->Const
.MaxDrawBuffers
)
1954 if (!ctx
->Extensions
.ARB_draw_buffers_blend
)
1956 v
->value_int
= ctx
->Color
.Blend
[index
].DstRGB
;
1958 case GL_BLEND_DST_ALPHA
:
1959 if (index
>= ctx
->Const
.MaxDrawBuffers
)
1961 if (!ctx
->Extensions
.ARB_draw_buffers_blend
)
1963 v
->value_int
= ctx
->Color
.Blend
[index
].DstA
;
1965 case GL_BLEND_EQUATION_RGB
:
1966 if (index
>= ctx
->Const
.MaxDrawBuffers
)
1968 if (!ctx
->Extensions
.ARB_draw_buffers_blend
)
1970 v
->value_int
= ctx
->Color
.Blend
[index
].EquationRGB
;
1972 case GL_BLEND_EQUATION_ALPHA
:
1973 if (index
>= ctx
->Const
.MaxDrawBuffers
)
1975 if (!ctx
->Extensions
.ARB_draw_buffers_blend
)
1977 v
->value_int
= ctx
->Color
.Blend
[index
].EquationA
;
1980 case GL_COLOR_WRITEMASK
:
1981 if (index
>= ctx
->Const
.MaxDrawBuffers
)
1983 if (!ctx
->Extensions
.EXT_draw_buffers2
)
1985 v
->value_int_4
[0] = ctx
->Color
.ColorMask
[index
][RCOMP
] ? 1 : 0;
1986 v
->value_int_4
[1] = ctx
->Color
.ColorMask
[index
][GCOMP
] ? 1 : 0;
1987 v
->value_int_4
[2] = ctx
->Color
.ColorMask
[index
][BCOMP
] ? 1 : 0;
1988 v
->value_int_4
[3] = ctx
->Color
.ColorMask
[index
][ACOMP
] ? 1 : 0;
1991 case GL_SCISSOR_BOX
:
1992 if (index
>= ctx
->Const
.MaxViewports
)
1994 v
->value_int_4
[0] = ctx
->Scissor
.ScissorArray
[index
].X
;
1995 v
->value_int_4
[1] = ctx
->Scissor
.ScissorArray
[index
].Y
;
1996 v
->value_int_4
[2] = ctx
->Scissor
.ScissorArray
[index
].Width
;
1997 v
->value_int_4
[3] = ctx
->Scissor
.ScissorArray
[index
].Height
;
2001 if (index
>= ctx
->Const
.MaxViewports
)
2003 v
->value_float_4
[0] = ctx
->ViewportArray
[index
].X
;
2004 v
->value_float_4
[1] = ctx
->ViewportArray
[index
].Y
;
2005 v
->value_float_4
[2] = ctx
->ViewportArray
[index
].Width
;
2006 v
->value_float_4
[3] = ctx
->ViewportArray
[index
].Height
;
2007 return TYPE_FLOAT_4
;
2009 case GL_DEPTH_RANGE
:
2010 if (index
>= ctx
->Const
.MaxViewports
)
2012 v
->value_double_2
[0] = ctx
->ViewportArray
[index
].Near
;
2013 v
->value_double_2
[1] = ctx
->ViewportArray
[index
].Far
;
2014 return TYPE_DOUBLEN_2
;
2016 case GL_TRANSFORM_FEEDBACK_BUFFER_START
:
2017 if (index
>= ctx
->Const
.MaxTransformFeedbackBuffers
)
2019 if (!ctx
->Extensions
.EXT_transform_feedback
)
2021 v
->value_int64
= ctx
->TransformFeedback
.CurrentObject
->Offset
[index
];
2024 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE
:
2025 if (index
>= ctx
->Const
.MaxTransformFeedbackBuffers
)
2027 if (!ctx
->Extensions
.EXT_transform_feedback
)
2030 = ctx
->TransformFeedback
.CurrentObject
->RequestedSize
[index
];
2033 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING
:
2034 if (index
>= ctx
->Const
.MaxTransformFeedbackBuffers
)
2036 if (!ctx
->Extensions
.EXT_transform_feedback
)
2038 v
->value_int
= ctx
->TransformFeedback
.CurrentObject
->BufferNames
[index
];
2041 case GL_UNIFORM_BUFFER_BINDING
:
2042 if (index
>= ctx
->Const
.MaxUniformBufferBindings
)
2044 if (!ctx
->Extensions
.ARB_uniform_buffer_object
)
2046 v
->value_int
= ctx
->UniformBufferBindings
[index
].BufferObject
->Name
;
2049 case GL_UNIFORM_BUFFER_START
:
2050 if (index
>= ctx
->Const
.MaxUniformBufferBindings
)
2052 if (!ctx
->Extensions
.ARB_uniform_buffer_object
)
2054 v
->value_int
= ctx
->UniformBufferBindings
[index
].Offset
< 0 ? 0 :
2055 ctx
->UniformBufferBindings
[index
].Offset
;
2058 case GL_UNIFORM_BUFFER_SIZE
:
2059 if (index
>= ctx
->Const
.MaxUniformBufferBindings
)
2061 if (!ctx
->Extensions
.ARB_uniform_buffer_object
)
2063 v
->value_int
= ctx
->UniformBufferBindings
[index
].Size
< 0 ? 0 :
2064 ctx
->UniformBufferBindings
[index
].Size
;
2067 /* ARB_shader_storage_buffer_object */
2068 case GL_SHADER_STORAGE_BUFFER_BINDING
:
2069 if (!ctx
->Extensions
.ARB_shader_storage_buffer_object
)
2071 if (index
>= ctx
->Const
.MaxShaderStorageBufferBindings
)
2073 v
->value_int
= ctx
->ShaderStorageBufferBindings
[index
].BufferObject
->Name
;
2076 case GL_SHADER_STORAGE_BUFFER_START
:
2077 if (!ctx
->Extensions
.ARB_shader_storage_buffer_object
)
2079 if (index
>= ctx
->Const
.MaxShaderStorageBufferBindings
)
2081 v
->value_int
= ctx
->ShaderStorageBufferBindings
[index
].Offset
< 0 ? 0 :
2082 ctx
->ShaderStorageBufferBindings
[index
].Offset
;
2085 case GL_SHADER_STORAGE_BUFFER_SIZE
:
2086 if (!ctx
->Extensions
.ARB_shader_storage_buffer_object
)
2088 if (index
>= ctx
->Const
.MaxShaderStorageBufferBindings
)
2090 v
->value_int
= ctx
->ShaderStorageBufferBindings
[index
].Size
< 0 ? 0 :
2091 ctx
->ShaderStorageBufferBindings
[index
].Size
;
2094 /* ARB_texture_multisample / GL3.2 */
2095 case GL_SAMPLE_MASK_VALUE
:
2098 if (!ctx
->Extensions
.ARB_texture_multisample
)
2100 v
->value_int
= ctx
->Multisample
.SampleMaskValue
;
2103 case GL_ATOMIC_COUNTER_BUFFER_BINDING
:
2104 if (!ctx
->Extensions
.ARB_shader_atomic_counters
)
2106 if (index
>= ctx
->Const
.MaxAtomicBufferBindings
)
2108 v
->value_int
= ctx
->AtomicBufferBindings
[index
].BufferObject
->Name
;
2111 case GL_ATOMIC_COUNTER_BUFFER_START
:
2112 if (!ctx
->Extensions
.ARB_shader_atomic_counters
)
2114 if (index
>= ctx
->Const
.MaxAtomicBufferBindings
)
2116 v
->value_int64
= ctx
->AtomicBufferBindings
[index
].Offset
;
2119 case GL_ATOMIC_COUNTER_BUFFER_SIZE
:
2120 if (!ctx
->Extensions
.ARB_shader_atomic_counters
)
2122 if (index
>= ctx
->Const
.MaxAtomicBufferBindings
)
2124 v
->value_int64
= ctx
->AtomicBufferBindings
[index
].Size
;
2127 case GL_VERTEX_BINDING_DIVISOR
:
2128 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_instanced_arrays
) &&
2129 !_mesa_is_gles31(ctx
))
2131 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
)
2133 v
->value_int
= ctx
->Array
.VAO
->VertexBinding
[VERT_ATTRIB_GENERIC(index
)].InstanceDivisor
;
2136 case GL_VERTEX_BINDING_OFFSET
:
2137 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles31(ctx
))
2139 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
)
2141 v
->value_int
= ctx
->Array
.VAO
->VertexBinding
[VERT_ATTRIB_GENERIC(index
)].Offset
;
2144 case GL_VERTEX_BINDING_STRIDE
:
2145 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles31(ctx
))
2147 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
)
2149 v
->value_int
= ctx
->Array
.VAO
->VertexBinding
[VERT_ATTRIB_GENERIC(index
)].Stride
;
2152 case GL_VERTEX_BINDING_BUFFER
:
2153 if (ctx
->API
== API_OPENGLES2
&& ctx
->Version
< 31)
2155 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
)
2157 v
->value_int
= ctx
->Array
.VAO
->VertexBinding
[VERT_ATTRIB_GENERIC(index
)].BufferObj
->Name
;
2160 /* ARB_shader_image_load_store */
2161 case GL_IMAGE_BINDING_NAME
: {
2162 struct gl_texture_object
*t
;
2164 if (!ctx
->Extensions
.ARB_shader_image_load_store
)
2166 if (index
>= ctx
->Const
.MaxImageUnits
)
2169 t
= ctx
->ImageUnits
[index
].TexObj
;
2170 v
->value_int
= (t
? t
->Name
: 0);
2174 case GL_IMAGE_BINDING_LEVEL
:
2175 if (!ctx
->Extensions
.ARB_shader_image_load_store
)
2177 if (index
>= ctx
->Const
.MaxImageUnits
)
2180 v
->value_int
= ctx
->ImageUnits
[index
].Level
;
2183 case GL_IMAGE_BINDING_LAYERED
:
2184 if (!ctx
->Extensions
.ARB_shader_image_load_store
)
2186 if (index
>= ctx
->Const
.MaxImageUnits
)
2189 v
->value_int
= ctx
->ImageUnits
[index
].Layered
;
2192 case GL_IMAGE_BINDING_LAYER
:
2193 if (!ctx
->Extensions
.ARB_shader_image_load_store
)
2195 if (index
>= ctx
->Const
.MaxImageUnits
)
2198 v
->value_int
= ctx
->ImageUnits
[index
].Layer
;
2201 case GL_IMAGE_BINDING_ACCESS
:
2202 if (!ctx
->Extensions
.ARB_shader_image_load_store
)
2204 if (index
>= ctx
->Const
.MaxImageUnits
)
2207 v
->value_int
= ctx
->ImageUnits
[index
].Access
;
2210 case GL_IMAGE_BINDING_FORMAT
:
2211 if (!ctx
->Extensions
.ARB_shader_image_load_store
)
2213 if (index
>= ctx
->Const
.MaxImageUnits
)
2216 v
->value_int
= ctx
->ImageUnits
[index
].Format
;
2219 /* ARB_direct_state_access */
2220 case GL_TEXTURE_BINDING_1D
:
2221 case GL_TEXTURE_BINDING_1D_ARRAY
:
2222 case GL_TEXTURE_BINDING_2D
:
2223 case GL_TEXTURE_BINDING_2D_ARRAY
:
2224 case GL_TEXTURE_BINDING_2D_MULTISAMPLE
:
2225 case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY
:
2226 case GL_TEXTURE_BINDING_3D
:
2227 case GL_TEXTURE_BINDING_BUFFER
:
2228 case GL_TEXTURE_BINDING_CUBE_MAP
:
2229 case GL_TEXTURE_BINDING_CUBE_MAP_ARRAY
:
2230 case GL_TEXTURE_BINDING_RECTANGLE
: {
2233 if (ctx
->API
!= API_OPENGL_CORE
)
2235 target
= tex_binding_to_index(ctx
, pname
);
2238 if (index
>= _mesa_max_tex_unit(ctx
))
2241 v
->value_int
= ctx
->Texture
.Unit
[index
].CurrentTex
[target
]->Name
;
2245 case GL_SAMPLER_BINDING
: {
2246 struct gl_sampler_object
*samp
;
2248 if (ctx
->API
!= API_OPENGL_CORE
)
2250 if (index
>= _mesa_max_tex_unit(ctx
))
2253 samp
= ctx
->Texture
.Unit
[index
].Sampler
;
2254 v
->value_int
= samp
? samp
->Name
: 0;
2258 case GL_MAX_COMPUTE_WORK_GROUP_COUNT
:
2259 if (!_mesa_has_compute_shaders(ctx
))
2263 v
->value_int
= ctx
->Const
.MaxComputeWorkGroupCount
[index
];
2266 case GL_MAX_COMPUTE_WORK_GROUP_SIZE
:
2267 if (!_mesa_has_compute_shaders(ctx
))
2271 v
->value_int
= ctx
->Const
.MaxComputeWorkGroupSize
[index
];
2276 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=%s)", func
,
2277 _mesa_enum_to_string(pname
));
2278 return TYPE_INVALID
;
2280 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(pname=%s)", func
,
2281 _mesa_enum_to_string(pname
));
2282 return TYPE_INVALID
;
2286 _mesa_GetBooleani_v( GLenum pname
, GLuint index
, GLboolean
*params
)
2289 enum value_type type
=
2290 find_value_indexed("glGetBooleani_v", pname
, index
, &v
);
2294 params
[0] = INT_TO_BOOLEAN(v
.value_int
);
2297 params
[0] = INT_TO_BOOLEAN(v
.value_int_4
[0]);
2298 params
[1] = INT_TO_BOOLEAN(v
.value_int_4
[1]);
2299 params
[2] = INT_TO_BOOLEAN(v
.value_int_4
[2]);
2300 params
[3] = INT_TO_BOOLEAN(v
.value_int_4
[3]);
2303 params
[0] = INT64_TO_BOOLEAN(v
.value_int64
);
2306 ; /* nothing - GL error was recorded */
2311 _mesa_GetIntegeri_v( GLenum pname
, GLuint index
, GLint
*params
)
2314 enum value_type type
=
2315 find_value_indexed("glGetIntegeri_v", pname
, index
, &v
);
2320 params
[3] = IROUND(v
.value_float_4
[3]);
2323 params
[2] = IROUND(v
.value_float_4
[2]);
2326 params
[1] = IROUND(v
.value_float_4
[1]);
2329 params
[0] = IROUND(v
.value_float_4
[0]);
2332 case TYPE_DOUBLEN_2
:
2333 params
[1] = IROUND(v
.value_double_2
[1]);
2335 params
[0] = IROUND(v
.value_double_2
[0]);
2339 params
[0] = v
.value_int
;
2342 params
[0] = v
.value_int_4
[0];
2343 params
[1] = v
.value_int_4
[1];
2344 params
[2] = v
.value_int_4
[2];
2345 params
[3] = v
.value_int_4
[3];
2348 params
[0] = INT64_TO_INT(v
.value_int64
);
2351 ; /* nothing - GL error was recorded */
2356 _mesa_GetInteger64i_v( GLenum pname
, GLuint index
, GLint64
*params
)
2359 enum value_type type
=
2360 find_value_indexed("glGetInteger64i_v", pname
, index
, &v
);
2364 params
[0] = v
.value_int
;
2367 params
[0] = v
.value_int_4
[0];
2368 params
[1] = v
.value_int_4
[1];
2369 params
[2] = v
.value_int_4
[2];
2370 params
[3] = v
.value_int_4
[3];
2373 params
[0] = v
.value_int64
;
2376 ; /* nothing - GL error was recorded */
2381 _mesa_GetFloati_v(GLenum pname
, GLuint index
, GLfloat
*params
)
2386 enum value_type type
=
2387 find_value_indexed("glGetFloati_v", pname
, index
, &v
);
2392 params
[3] = v
.value_float_4
[3];
2395 params
[2] = v
.value_float_4
[2];
2398 params
[1] = v
.value_float_4
[1];
2401 params
[0] = v
.value_float_4
[0];
2404 case TYPE_DOUBLEN_2
:
2405 params
[1] = (GLfloat
) v
.value_double_2
[1];
2407 params
[0] = (GLfloat
) v
.value_double_2
[0];
2411 params
[3] = (GLfloat
) v
.value_int_4
[3];
2413 params
[2] = (GLfloat
) v
.value_int_4
[2];
2416 params
[1] = (GLfloat
) v
.value_int_4
[1];
2419 params
[0] = (GLfloat
) v
.value_int_4
[0];
2423 for (i
= 0; i
< v
.value_int_n
.n
; i
++)
2424 params
[i
] = INT_TO_FLOAT(v
.value_int_n
.ints
[i
]);
2428 params
[0] = (GLfloat
) v
.value_int64
;
2432 params
[0] = BOOLEAN_TO_FLOAT(v
.value_bool
);
2436 m
= *(GLmatrix
**) &v
;
2437 for (i
= 0; i
< 16; i
++)
2438 params
[i
] = m
->m
[i
];
2442 m
= *(GLmatrix
**) &v
;
2443 for (i
= 0; i
< 16; i
++)
2444 params
[i
] = m
->m
[transpose
[i
]];
2453 _mesa_GetDoublei_v(GLenum pname
, GLuint index
, GLdouble
*params
)
2458 enum value_type type
=
2459 find_value_indexed("glGetDoublei_v", pname
, index
, &v
);
2464 params
[3] = (GLdouble
) v
.value_float_4
[3];
2467 params
[2] = (GLdouble
) v
.value_float_4
[2];
2470 params
[1] = (GLdouble
) v
.value_float_4
[1];
2473 params
[0] = (GLdouble
) v
.value_float_4
[0];
2476 case TYPE_DOUBLEN_2
:
2477 params
[1] = v
.value_double_2
[1];
2479 params
[0] = v
.value_double_2
[0];
2483 params
[3] = (GLdouble
) v
.value_int_4
[3];
2485 params
[2] = (GLdouble
) v
.value_int_4
[2];
2488 params
[1] = (GLdouble
) v
.value_int_4
[1];
2491 params
[0] = (GLdouble
) v
.value_int_4
[0];
2495 for (i
= 0; i
< v
.value_int_n
.n
; i
++)
2496 params
[i
] = (GLdouble
) INT_TO_FLOAT(v
.value_int_n
.ints
[i
]);
2500 params
[0] = (GLdouble
) v
.value_int64
;
2504 params
[0] = (GLdouble
) BOOLEAN_TO_FLOAT(v
.value_bool
);
2508 m
= *(GLmatrix
**) &v
;
2509 for (i
= 0; i
< 16; i
++)
2510 params
[i
] = (GLdouble
) m
->m
[i
];
2514 m
= *(GLmatrix
**) &v
;
2515 for (i
= 0; i
< 16; i
++)
2516 params
[i
] = (GLdouble
) m
->m
[transpose
[i
]];
2525 _mesa_GetFixedv(GLenum pname
, GLfixed
*params
)
2527 const struct value_desc
*d
;
2533 d
= find_value("glGetDoublev", pname
, &p
, &v
);
2538 params
[0] = INT_TO_FIXED(d
->offset
);
2543 params
[3] = FLOAT_TO_FIXED(((GLfloat
*) p
)[3]);
2546 params
[2] = FLOAT_TO_FIXED(((GLfloat
*) p
)[2]);
2549 params
[1] = FLOAT_TO_FIXED(((GLfloat
*) p
)[1]);
2552 params
[0] = FLOAT_TO_FIXED(((GLfloat
*) p
)[0]);
2555 case TYPE_DOUBLEN_2
:
2556 params
[1] = FLOAT_TO_FIXED(((GLdouble
*) p
)[1]);
2558 params
[0] = FLOAT_TO_FIXED(((GLdouble
*) p
)[0]);
2562 params
[3] = INT_TO_FIXED(((GLint
*) p
)[3]);
2564 params
[2] = INT_TO_FIXED(((GLint
*) p
)[2]);
2567 params
[1] = INT_TO_FIXED(((GLint
*) p
)[1]);
2570 params
[0] = INT_TO_FIXED(((GLint
*) p
)[0]);
2574 for (i
= 0; i
< v
.value_int_n
.n
; i
++)
2575 params
[i
] = INT_TO_FIXED(v
.value_int_n
.ints
[i
]);
2579 params
[0] = ((GLint64
*) p
)[0];
2583 params
[0] = BOOLEAN_TO_FIXED(((GLboolean
*) p
)[0]);
2587 m
= *(GLmatrix
**) p
;
2588 for (i
= 0; i
< 16; i
++)
2589 params
[i
] = FLOAT_TO_FIXED(m
->m
[i
]);
2593 m
= *(GLmatrix
**) p
;
2594 for (i
= 0; i
< 16; i
++)
2595 params
[i
] = FLOAT_TO_FIXED(m
->m
[transpose
[i
]]);
2606 shift
= d
->type
- TYPE_BIT_0
;
2607 params
[0] = BOOLEAN_TO_FIXED((*(GLbitfield
*) p
>> shift
) & 1);