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>
32 #include "extensions.h"
37 #include "texcompress.h"
39 #include "framebuffer.h"
40 #include "samplerobj.h"
43 /* This is a table driven implemetation of the glGet*v() functions.
44 * The basic idea is that most getters just look up an int somewhere
45 * in struct gl_context and then convert it to a bool or float according to
46 * which of glGetIntegerv() glGetBooleanv() etc is being called.
47 * Instead of generating code to do this, we can just record the enum
48 * value and the offset into struct gl_context in an array of structs. Then
49 * in glGet*(), we lookup the struct for the enum in question, and use
50 * the offset to get the int we need.
52 * Sometimes we need to look up a float, a boolean, a bit in a
53 * bitfield, a matrix or other types instead, so we need to track the
54 * type of the value in struct gl_context. And sometimes the value isn't in
55 * struct gl_context but in the drawbuffer, the array object, current texture
56 * unit, or maybe it's a computed value. So we need to also track
57 * where or how to find the value. Finally, we sometimes need to
58 * check that one of a number of extensions are enabled, the GL
59 * version or flush or call _mesa_update_state(). This is done by
60 * attaching optional extra information to the value description
61 * struct, it's sort of like an array of opcodes that describe extra
64 * Putting all this together we end up with struct value_desc below,
65 * and with a couple of macros to help, the table of struct value_desc
66 * is about as concise as the specification in the old python script.
69 #define FLOAT_TO_BOOLEAN(X) ( (X) ? GL_TRUE : GL_FALSE )
70 #define FLOAT_TO_FIXED(F) ( ((F) * 65536.0f > INT_MAX) ? INT_MAX : \
71 ((F) * 65536.0f < INT_MIN) ? INT_MIN : \
72 (GLint) ((F) * 65536.0f) )
74 #define INT_TO_BOOLEAN(I) ( (I) ? GL_TRUE : GL_FALSE )
75 #define INT_TO_FIXED(I) ( ((I) > SHRT_MAX) ? INT_MAX : \
76 ((I) < SHRT_MIN) ? INT_MIN : \
77 (GLint) ((I) * 65536) )
79 #define INT64_TO_BOOLEAN(I) ( (I) ? GL_TRUE : GL_FALSE )
80 #define INT64_TO_INT(I) ( (GLint)((I > INT_MAX) ? INT_MAX : ((I < INT_MIN) ? INT_MIN : (I))) )
82 #define BOOLEAN_TO_INT(B) ( (GLint) (B) )
83 #define BOOLEAN_TO_INT64(B) ( (GLint64) (B) )
84 #define BOOLEAN_TO_FLOAT(B) ( (B) ? 1.0F : 0.0F )
85 #define BOOLEAN_TO_FIXED(B) ( (GLint) ((B) ? 1 : 0) << 16 )
87 #define ENUM_TO_INT64(E) ( (GLint64) (E) )
88 #define ENUM_TO_FIXED(E) (E)
124 enum value_location
{
144 EXTRA_NEW_FRAG_CLAMP
,
145 EXTRA_VALID_DRAW_BUFFER
,
146 EXTRA_VALID_TEXTURE_UNIT
,
147 EXTRA_VALID_CLIP_DISTANCE
,
151 EXTRA_EXT_ATOMICS_GS
,
152 EXTRA_EXT_SHADER_IMAGE_GS
,
153 EXTRA_EXT_ATOMICS_TESS
,
154 EXTRA_EXT_SHADER_IMAGE_TESS
,
156 EXTRA_EXT_FB_NO_ATTACH_GS
,
160 #define NO_EXTRA NULL
165 GLubyte location
; /**< enum value_location */
166 GLubyte type
; /**< enum value_type */
173 GLfloat value_float_4
[4];
174 GLdouble value_double_2
[2];
175 GLmatrix
*value_matrix
;
177 GLint value_int_4
[4];
181 /* Sigh, see GL_COMPRESSED_TEXTURE_FORMATS_ARB handling */
185 GLboolean value_bool
;
188 #define BUFFER_FIELD(field, type) \
189 LOC_BUFFER, type, offsetof(struct gl_framebuffer, field)
190 #define CONTEXT_FIELD(field, type) \
191 LOC_CONTEXT, type, offsetof(struct gl_context, field)
192 #define ARRAY_FIELD(field, type) \
193 LOC_ARRAY, type, offsetof(struct gl_vertex_array_object, field)
194 #undef CONST /* already defined through windows.h */
195 #define CONST(value) \
196 LOC_CONTEXT, TYPE_CONST, value
198 #define BUFFER_INT(field) BUFFER_FIELD(field, TYPE_INT)
199 #define BUFFER_ENUM(field) BUFFER_FIELD(field, TYPE_ENUM)
200 #define BUFFER_BOOL(field) BUFFER_FIELD(field, TYPE_BOOLEAN)
202 #define CONTEXT_INT(field) CONTEXT_FIELD(field, TYPE_INT)
203 #define CONTEXT_INT2(field) CONTEXT_FIELD(field, TYPE_INT_2)
204 #define CONTEXT_INT64(field) CONTEXT_FIELD(field, TYPE_INT64)
205 #define CONTEXT_ENUM(field) CONTEXT_FIELD(field, TYPE_ENUM)
206 #define CONTEXT_ENUM2(field) CONTEXT_FIELD(field, TYPE_ENUM_2)
207 #define CONTEXT_BOOL(field) CONTEXT_FIELD(field, TYPE_BOOLEAN)
208 #define CONTEXT_BIT0(field) CONTEXT_FIELD(field, TYPE_BIT_0)
209 #define CONTEXT_BIT1(field) CONTEXT_FIELD(field, TYPE_BIT_1)
210 #define CONTEXT_BIT2(field) CONTEXT_FIELD(field, TYPE_BIT_2)
211 #define CONTEXT_BIT3(field) CONTEXT_FIELD(field, TYPE_BIT_3)
212 #define CONTEXT_BIT4(field) CONTEXT_FIELD(field, TYPE_BIT_4)
213 #define CONTEXT_BIT5(field) CONTEXT_FIELD(field, TYPE_BIT_5)
214 #define CONTEXT_BIT6(field) CONTEXT_FIELD(field, TYPE_BIT_6)
215 #define CONTEXT_BIT7(field) CONTEXT_FIELD(field, TYPE_BIT_7)
216 #define CONTEXT_FLOAT(field) CONTEXT_FIELD(field, TYPE_FLOAT)
217 #define CONTEXT_FLOAT2(field) CONTEXT_FIELD(field, TYPE_FLOAT_2)
218 #define CONTEXT_FLOAT3(field) CONTEXT_FIELD(field, TYPE_FLOAT_3)
219 #define CONTEXT_FLOAT4(field) CONTEXT_FIELD(field, TYPE_FLOAT_4)
220 #define CONTEXT_MATRIX(field) CONTEXT_FIELD(field, TYPE_MATRIX)
221 #define CONTEXT_MATRIX_T(field) CONTEXT_FIELD(field, TYPE_MATRIX_T)
223 #define ARRAY_INT(field) ARRAY_FIELD(field, TYPE_INT)
224 #define ARRAY_ENUM(field) ARRAY_FIELD(field, TYPE_ENUM)
225 #define ARRAY_BOOL(field) ARRAY_FIELD(field, TYPE_BOOLEAN)
228 offsetof(struct gl_extensions, f)
230 #define EXTRA_EXT(e) \
231 static const int extra_##e[] = { \
235 #define EXTRA_EXT2(e1, e2) \
236 static const int extra_##e1##_##e2[] = { \
237 EXT(e1), EXT(e2), EXTRA_END \
240 /* The 'extra' mechanism is a way to specify extra checks (such as
241 * extensions or specific gl versions) or actions (flush current, new
242 * buffers) that we need to do before looking up an enum. We need to
243 * declare them all up front so we can refer to them in the value_desc
246 * Each EXTRA_ will be executed. For EXTRA_* enums of extensions and API
247 * versions, listing multiple ones in an array means an error will be thrown
248 * only if none of them are available. If you need to check for "AND"
249 * behavior, you would need to make a custom EXTRA_ enum.
252 static const int extra_new_buffers
[] = {
257 static const int extra_new_frag_clamp
[] = {
258 EXTRA_NEW_FRAG_CLAMP
,
262 static const int extra_valid_draw_buffer
[] = {
263 EXTRA_VALID_DRAW_BUFFER
,
267 static const int extra_valid_texture_unit
[] = {
268 EXTRA_VALID_TEXTURE_UNIT
,
272 static const int extra_valid_clip_distance
[] = {
273 EXTRA_VALID_CLIP_DISTANCE
,
277 static const int extra_flush_current_valid_texture_unit
[] = {
279 EXTRA_VALID_TEXTURE_UNIT
,
283 static const int extra_flush_current
[] = {
288 static const int extra_EXT_texture_integer_and_new_buffers
[] = {
289 EXT(EXT_texture_integer
),
294 static const int extra_GLSL_130_es3
[] = {
300 static const int extra_texture_buffer_object
[] = {
303 EXT(ARB_texture_buffer_object
),
307 static const int extra_ARB_transform_feedback2_api_es3
[] = {
308 EXT(ARB_transform_feedback2
),
313 static const int extra_ARB_uniform_buffer_object_and_geometry_shader
[] = {
318 static const int extra_ARB_ES2_compatibility_api_es2
[] = {
319 EXT(ARB_ES2_compatibility
),
324 static const int extra_ARB_ES3_compatibility_api_es3
[] = {
325 EXT(ARB_ES3_compatibility
),
330 static const int extra_EXT_framebuffer_sRGB_and_new_buffers
[] = {
331 EXT(EXT_framebuffer_sRGB
),
336 static const int extra_EXT_packed_float
[] = {
337 EXT(EXT_packed_float
),
342 static const int extra_EXT_texture_array_es3
[] = {
343 EXT(EXT_texture_array
),
348 static const int extra_ARB_shader_atomic_counters_and_geometry_shader
[] = {
349 EXTRA_EXT_ATOMICS_GS
,
353 static const int extra_ARB_shader_image_load_store_and_geometry_shader
[] = {
354 EXTRA_EXT_SHADER_IMAGE_GS
,
358 static const int extra_ARB_shader_atomic_counters_and_tessellation
[] = {
359 EXTRA_EXT_ATOMICS_TESS
,
363 static const int extra_ARB_shader_image_load_store_and_tessellation
[] = {
364 EXTRA_EXT_SHADER_IMAGE_TESS
,
368 /* HACK: remove when ARB_compute_shader is actually supported */
369 static const int extra_ARB_compute_shader_es31
[] = {
370 EXT(ARB_compute_shader
),
375 static const int extra_ARB_shader_storage_buffer_object_es31
[] = {
376 EXT(ARB_shader_storage_buffer_object
),
381 static const int extra_ARB_shader_storage_buffer_object_and_geometry_shader
[] = {
386 static const int extra_ARB_framebuffer_no_attachments_and_geometry_shader
[] = {
387 EXTRA_EXT_FB_NO_ATTACH_GS
,
391 static const int extra_ARB_viewport_array_or_oes_geometry_shader
[] = {
392 EXT(ARB_viewport_array
),
397 static const int extra_ARB_gpu_shader5_or_oes_geometry_shader
[] = {
398 EXT(ARB_gpu_shader5
),
403 EXTRA_EXT(ARB_texture_cube_map
);
404 EXTRA_EXT(EXT_texture_array
);
405 EXTRA_EXT(NV_fog_distance
);
406 EXTRA_EXT(EXT_texture_filter_anisotropic
);
407 EXTRA_EXT(NV_point_sprite
);
408 EXTRA_EXT(NV_texture_rectangle
);
409 EXTRA_EXT(EXT_stencil_two_side
);
410 EXTRA_EXT(EXT_depth_bounds_test
);
411 EXTRA_EXT(ARB_depth_clamp
);
412 EXTRA_EXT(ATI_fragment_shader
);
413 EXTRA_EXT(EXT_provoking_vertex
);
414 EXTRA_EXT(ARB_fragment_shader
);
415 EXTRA_EXT(ARB_fragment_program
);
416 EXTRA_EXT2(ARB_framebuffer_object
, EXT_framebuffer_multisample
);
417 EXTRA_EXT(ARB_seamless_cube_map
);
419 EXTRA_EXT(ARB_vertex_shader
);
420 EXTRA_EXT(EXT_transform_feedback
);
421 EXTRA_EXT(ARB_transform_feedback3
);
422 EXTRA_EXT(EXT_pixel_buffer_object
);
423 EXTRA_EXT(ARB_vertex_program
);
424 EXTRA_EXT2(NV_point_sprite
, ARB_point_sprite
);
425 EXTRA_EXT2(ARB_vertex_program
, ARB_fragment_program
);
426 EXTRA_EXT(ARB_color_buffer_float
);
427 EXTRA_EXT(EXT_framebuffer_sRGB
);
428 EXTRA_EXT(OES_EGL_image_external
);
429 EXTRA_EXT(ARB_blend_func_extended
);
430 EXTRA_EXT(ARB_uniform_buffer_object
);
431 EXTRA_EXT(ARB_timer_query
);
432 EXTRA_EXT(ARB_texture_cube_map_array
);
433 EXTRA_EXT(ARB_texture_buffer_range
);
434 EXTRA_EXT(ARB_texture_multisample
);
435 EXTRA_EXT(ARB_texture_gather
);
436 EXTRA_EXT(ARB_shader_atomic_counters
);
437 EXTRA_EXT(ARB_draw_indirect
);
438 EXTRA_EXT(ARB_shader_image_load_store
);
439 EXTRA_EXT(ARB_viewport_array
);
440 EXTRA_EXT(ARB_compute_shader
);
441 EXTRA_EXT(ARB_gpu_shader5
);
442 EXTRA_EXT(ARB_query_buffer_object
);
443 EXTRA_EXT2(ARB_transform_feedback3
, ARB_gpu_shader5
);
444 EXTRA_EXT(INTEL_performance_query
);
445 EXTRA_EXT(ARB_explicit_uniform_location
);
446 EXTRA_EXT(ARB_clip_control
);
447 EXTRA_EXT(EXT_polygon_offset_clamp
);
448 EXTRA_EXT(ARB_framebuffer_no_attachments
);
449 EXTRA_EXT(ARB_tessellation_shader
);
450 EXTRA_EXT(ARB_shader_subroutine
);
451 EXTRA_EXT(ARB_shader_storage_buffer_object
);
452 EXTRA_EXT(ARB_indirect_parameters
);
455 extra_ARB_color_buffer_float_or_glcore
[] = {
456 EXT(ARB_color_buffer_float
),
462 extra_NV_primitive_restart
[] = {
463 EXT(NV_primitive_restart
),
467 static const int extra_version_30
[] = { EXTRA_VERSION_30
, EXTRA_END
};
468 static const int extra_version_31
[] = { EXTRA_VERSION_31
, EXTRA_END
};
469 static const int extra_version_32
[] = { EXTRA_VERSION_32
, EXTRA_END
};
470 static const int extra_version_40
[] = { EXTRA_VERSION_40
, EXTRA_END
};
472 static const int extra_gl30_es3
[] = {
478 static const int extra_gl32_es3
[] = {
484 static const int extra_version_32_OES_geometry_shader
[] = {
490 static const int extra_gl40_ARB_sample_shading
[] = {
492 EXT(ARB_sample_shading
),
497 extra_ARB_vertex_program_api_es2
[] = {
498 EXT(ARB_vertex_program
),
503 /* The ReadBuffer get token is valid under either full GL or under
504 * GLES2 if the NV_read_buffer extension is available. */
506 extra_NV_read_buffer_api_gl
[] = {
512 static const int extra_core_ARB_color_buffer_float_and_new_buffers
[] = {
514 EXT(ARB_color_buffer_float
),
519 /* This is the big table describing all the enums we accept in
520 * glGet*v(). The table is partitioned into six parts: enums
521 * understood by all GL APIs (OpenGL, GLES and GLES2), enums shared
522 * between OpenGL and GLES, enums exclusive to GLES, etc for the
523 * remaining combinations. To look up the enums valid in a given API
524 * we will use a hash table specific to that API. These tables are in
525 * turn generated at build time and included through get_hash.h.
528 #include "get_hash.h"
530 /* All we need now is a way to look up the value struct from the enum.
531 * The code generated by gcc for the old generated big switch
532 * statement is a big, balanced, open coded if/else tree, essentially
533 * an unrolled binary search. It would be natural to sort the new
534 * enum table and use bsearch(), but we will use a read-only hash
535 * table instead. bsearch() has a nice guaranteed worst case
536 * performance, but we're also guaranteed to hit that worst case
537 * (log2(n) iterations) for about half the enums. Instead, using an
538 * open addressing hash table, we can find the enum on the first try
539 * for 80% of the enums, 1 collision for 10% and never more than 5
540 * collisions for any enum (typical numbers). And the code is very
541 * simple, even though it feels a little magic. */
545 print_table_stats(int api
)
547 int i
, j
, collisions
[11], count
, hash
, mask
;
548 const struct value_desc
*d
;
549 const char *api_names
[] = {
550 [API_OPENGL_COMPAT
] = "GL",
551 [API_OPENGL_CORE
] = "GL_CORE",
552 [API_OPENGLES
] = "GLES",
553 [API_OPENGLES2
] = "GLES2",
555 const char *api_name
;
557 api_name
= api
< ARRAY_SIZE(api_names
) ? api_names
[api
] : "N/A";
559 mask
= ARRAY_SIZE(table(api
)) - 1;
560 memset(collisions
, 0, sizeof collisions
);
562 for (i
= 0; i
< ARRAY_SIZE(table(api
)); i
++) {
566 d
= &values
[table(api
)[i
]];
567 hash
= (d
->pname
* prime_factor
);
570 if (values
[table(api
)[hash
& mask
]].pname
== d
->pname
)
582 printf("number of enums for %s: %d (total %ld)\n",
583 api_name
, count
, ARRAY_SIZE(values
));
584 for (i
= 0; i
< ARRAY_SIZE(collisions
) - 1; i
++)
585 if (collisions
[i
] > 0)
586 printf(" %d enums with %d %scollisions\n",
587 collisions
[i
], i
, i
== 10 ? "or more " : "");
592 * Initialize the enum hash for a given API
594 * This is called from one_time_init() to insert the enum values that
595 * are valid for the API in question into the enum hash table.
597 * \param the current context, for determining the API in question
599 void _mesa_init_get_hash(struct gl_context
*ctx
)
602 print_table_stats(ctx
->API
);
609 * Handle irregular enums
611 * Some values don't conform to the "well-known type at context
612 * pointer + offset" pattern, so we have this function to catch all
613 * the corner cases. Typically, it's a computed value or a one-off
614 * pointer to a custom struct or something.
616 * In this case we can't return a pointer to the value, so we'll have
617 * to use the temporary variable 'v' declared back in the calling
618 * glGet*v() function to store the result.
620 * \param ctx the current context
621 * \param d the struct value_desc that describes the enum
622 * \param v pointer to the tmp declared in the calling glGet*v() function
625 find_custom_value(struct gl_context
*ctx
, const struct value_desc
*d
, union value
*v
)
627 struct gl_buffer_object
**buffer_obj
;
628 struct gl_vertex_attrib_array
*array
;
632 case GL_MAJOR_VERSION
:
633 v
->value_int
= ctx
->Version
/ 10;
635 case GL_MINOR_VERSION
:
636 v
->value_int
= ctx
->Version
% 10;
642 case GL_TEXTURE_CUBE_MAP_ARB
:
643 case GL_TEXTURE_RECTANGLE_NV
:
644 case GL_TEXTURE_EXTERNAL_OES
:
645 v
->value_bool
= _mesa_IsEnabled(d
->pname
);
648 case GL_LINE_STIPPLE_PATTERN
:
649 /* This is the only GLushort, special case it here by promoting
650 * to an int rather than introducing a new type. */
651 v
->value_int
= ctx
->Line
.StipplePattern
;
654 case GL_CURRENT_RASTER_TEXTURE_COORDS
:
655 unit
= ctx
->Texture
.CurrentUnit
;
656 v
->value_float_4
[0] = ctx
->Current
.RasterTexCoords
[unit
][0];
657 v
->value_float_4
[1] = ctx
->Current
.RasterTexCoords
[unit
][1];
658 v
->value_float_4
[2] = ctx
->Current
.RasterTexCoords
[unit
][2];
659 v
->value_float_4
[3] = ctx
->Current
.RasterTexCoords
[unit
][3];
662 case GL_CURRENT_TEXTURE_COORDS
:
663 unit
= ctx
->Texture
.CurrentUnit
;
664 v
->value_float_4
[0] = ctx
->Current
.Attrib
[VERT_ATTRIB_TEX0
+ unit
][0];
665 v
->value_float_4
[1] = ctx
->Current
.Attrib
[VERT_ATTRIB_TEX0
+ unit
][1];
666 v
->value_float_4
[2] = ctx
->Current
.Attrib
[VERT_ATTRIB_TEX0
+ unit
][2];
667 v
->value_float_4
[3] = ctx
->Current
.Attrib
[VERT_ATTRIB_TEX0
+ unit
][3];
670 case GL_COLOR_WRITEMASK
:
671 v
->value_int_4
[0] = ctx
->Color
.ColorMask
[0][RCOMP
] ? 1 : 0;
672 v
->value_int_4
[1] = ctx
->Color
.ColorMask
[0][GCOMP
] ? 1 : 0;
673 v
->value_int_4
[2] = ctx
->Color
.ColorMask
[0][BCOMP
] ? 1 : 0;
674 v
->value_int_4
[3] = ctx
->Color
.ColorMask
[0][ACOMP
] ? 1 : 0;
678 v
->value_bool
= ctx
->Current
.Attrib
[VERT_ATTRIB_EDGEFLAG
][0] == 1.0F
;
682 v
->value_enum
= ctx
->ReadBuffer
->ColorReadBuffer
;
685 case GL_MAP2_GRID_DOMAIN
:
686 v
->value_float_4
[0] = ctx
->Eval
.MapGrid2u1
;
687 v
->value_float_4
[1] = ctx
->Eval
.MapGrid2u2
;
688 v
->value_float_4
[2] = ctx
->Eval
.MapGrid2v1
;
689 v
->value_float_4
[3] = ctx
->Eval
.MapGrid2v2
;
692 case GL_TEXTURE_STACK_DEPTH
:
693 unit
= ctx
->Texture
.CurrentUnit
;
694 v
->value_int
= ctx
->TextureMatrixStack
[unit
].Depth
+ 1;
696 case GL_TEXTURE_MATRIX
:
697 unit
= ctx
->Texture
.CurrentUnit
;
698 v
->value_matrix
= ctx
->TextureMatrixStack
[unit
].Top
;
701 case GL_TEXTURE_COORD_ARRAY
:
702 case GL_TEXTURE_COORD_ARRAY_SIZE
:
703 case GL_TEXTURE_COORD_ARRAY_TYPE
:
704 case GL_TEXTURE_COORD_ARRAY_STRIDE
:
705 array
= &ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_TEX(ctx
->Array
.ActiveTexture
)];
706 v
->value_int
= *(GLuint
*) ((char *) array
+ d
->offset
);
709 case GL_ACTIVE_TEXTURE_ARB
:
710 v
->value_int
= GL_TEXTURE0_ARB
+ ctx
->Texture
.CurrentUnit
;
712 case GL_CLIENT_ACTIVE_TEXTURE_ARB
:
713 v
->value_int
= GL_TEXTURE0_ARB
+ ctx
->Array
.ActiveTexture
;
716 case GL_MODELVIEW_STACK_DEPTH
:
717 case GL_PROJECTION_STACK_DEPTH
:
718 v
->value_int
= *(GLint
*) ((char *) ctx
+ d
->offset
) + 1;
721 case GL_MAX_TEXTURE_SIZE
:
722 case GL_MAX_3D_TEXTURE_SIZE
:
723 case GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB
:
724 p
= (GLuint
*) ((char *) ctx
+ d
->offset
);
725 v
->value_int
= 1 << (*p
- 1);
729 v
->value_int_4
[0] = ctx
->Scissor
.ScissorArray
[0].X
;
730 v
->value_int_4
[1] = ctx
->Scissor
.ScissorArray
[0].Y
;
731 v
->value_int_4
[2] = ctx
->Scissor
.ScissorArray
[0].Width
;
732 v
->value_int_4
[3] = ctx
->Scissor
.ScissorArray
[0].Height
;
735 case GL_SCISSOR_TEST
:
736 v
->value_bool
= ctx
->Scissor
.EnableFlags
& 1;
741 ctx
->ListState
.CurrentList
? ctx
->ListState
.CurrentList
->Name
: 0;
744 if (!ctx
->CompileFlag
)
746 else if (ctx
->ExecuteFlag
)
747 v
->value_enum
= GL_COMPILE_AND_EXECUTE
;
749 v
->value_enum
= GL_COMPILE
;
753 v
->value_float_4
[0] = ctx
->ViewportArray
[0].X
;
754 v
->value_float_4
[1] = ctx
->ViewportArray
[0].Y
;
755 v
->value_float_4
[2] = ctx
->ViewportArray
[0].Width
;
756 v
->value_float_4
[3] = ctx
->ViewportArray
[0].Height
;
760 v
->value_double_2
[0] = ctx
->ViewportArray
[0].Near
;
761 v
->value_double_2
[1] = ctx
->ViewportArray
[0].Far
;
764 case GL_ACTIVE_STENCIL_FACE_EXT
:
765 v
->value_enum
= ctx
->Stencil
.ActiveFace
? GL_BACK
: GL_FRONT
;
768 case GL_STENCIL_FAIL
:
769 v
->value_enum
= ctx
->Stencil
.FailFunc
[ctx
->Stencil
.ActiveFace
];
771 case GL_STENCIL_FUNC
:
772 v
->value_enum
= ctx
->Stencil
.Function
[ctx
->Stencil
.ActiveFace
];
774 case GL_STENCIL_PASS_DEPTH_FAIL
:
775 v
->value_enum
= ctx
->Stencil
.ZFailFunc
[ctx
->Stencil
.ActiveFace
];
777 case GL_STENCIL_PASS_DEPTH_PASS
:
778 v
->value_enum
= ctx
->Stencil
.ZPassFunc
[ctx
->Stencil
.ActiveFace
];
781 v
->value_int
= _mesa_get_stencil_ref(ctx
, ctx
->Stencil
.ActiveFace
);
783 case GL_STENCIL_BACK_REF
:
784 v
->value_int
= _mesa_get_stencil_ref(ctx
, 1);
786 case GL_STENCIL_VALUE_MASK
:
787 v
->value_int
= ctx
->Stencil
.ValueMask
[ctx
->Stencil
.ActiveFace
];
789 case GL_STENCIL_WRITEMASK
:
790 v
->value_int
= ctx
->Stencil
.WriteMask
[ctx
->Stencil
.ActiveFace
];
793 case GL_NUM_EXTENSIONS
:
794 v
->value_int
= _mesa_get_extension_count(ctx
);
797 case GL_IMPLEMENTATION_COLOR_READ_TYPE_OES
:
798 v
->value_int
= _mesa_get_color_read_type(ctx
);
800 case GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES
:
801 v
->value_int
= _mesa_get_color_read_format(ctx
);
804 case GL_CURRENT_MATRIX_STACK_DEPTH_ARB
:
805 v
->value_int
= ctx
->CurrentStack
->Depth
+ 1;
807 case GL_CURRENT_MATRIX_ARB
:
808 case GL_TRANSPOSE_CURRENT_MATRIX_ARB
:
809 v
->value_matrix
= ctx
->CurrentStack
->Top
;
812 case GL_NUM_COMPRESSED_TEXTURE_FORMATS_ARB
:
813 v
->value_int
= _mesa_get_compressed_formats(ctx
, NULL
);
815 case GL_COMPRESSED_TEXTURE_FORMATS_ARB
:
817 _mesa_get_compressed_formats(ctx
, v
->value_int_n
.ints
);
818 assert(v
->value_int_n
.n
<= (int) ARRAY_SIZE(v
->value_int_n
.ints
));
821 case GL_MAX_VARYING_FLOATS_ARB
:
822 v
->value_int
= ctx
->Const
.MaxVarying
* 4;
825 /* Various object names */
827 case GL_TEXTURE_BINDING_1D
:
828 case GL_TEXTURE_BINDING_2D
:
829 case GL_TEXTURE_BINDING_3D
:
830 case GL_TEXTURE_BINDING_1D_ARRAY_EXT
:
831 case GL_TEXTURE_BINDING_2D_ARRAY_EXT
:
832 case GL_TEXTURE_BINDING_CUBE_MAP_ARB
:
833 case GL_TEXTURE_BINDING_RECTANGLE_NV
:
834 case GL_TEXTURE_BINDING_EXTERNAL_OES
:
835 case GL_TEXTURE_BINDING_CUBE_MAP_ARRAY
:
836 case GL_TEXTURE_BINDING_2D_MULTISAMPLE
:
837 case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY
:
838 unit
= ctx
->Texture
.CurrentUnit
;
840 ctx
->Texture
.Unit
[unit
].CurrentTex
[d
->offset
]->Name
;
843 /* GL_EXT_packed_float */
844 case GL_RGBA_SIGNED_COMPONENTS_EXT
:
846 /* Note: we only check the 0th color attachment. */
847 const struct gl_renderbuffer
*rb
=
848 ctx
->DrawBuffer
->_ColorDrawBuffers
[0];
849 if (rb
&& _mesa_is_format_signed(rb
->Format
)) {
850 /* Issue 17 of GL_EXT_packed_float: If a component (such as
851 * alpha) has zero bits, the component should not be considered
852 * signed and so the bit for the respective component should be
856 _mesa_get_format_bits(rb
->Format
, GL_RED_BITS
);
858 _mesa_get_format_bits(rb
->Format
, GL_GREEN_BITS
);
860 _mesa_get_format_bits(rb
->Format
, GL_BLUE_BITS
);
862 _mesa_get_format_bits(rb
->Format
, GL_ALPHA_BITS
);
864 _mesa_get_format_bits(rb
->Format
, GL_TEXTURE_LUMINANCE_SIZE
);
866 _mesa_get_format_bits(rb
->Format
, GL_TEXTURE_INTENSITY_SIZE
);
868 v
->value_int_4
[0] = r_bits
+ l_bits
+ i_bits
> 0;
869 v
->value_int_4
[1] = g_bits
+ l_bits
+ i_bits
> 0;
870 v
->value_int_4
[2] = b_bits
+ l_bits
+ i_bits
> 0;
871 v
->value_int_4
[3] = a_bits
+ i_bits
> 0;
877 v
->value_int_4
[3] = 0;
882 /* GL_ARB_vertex_buffer_object */
883 case GL_VERTEX_ARRAY_BUFFER_BINDING_ARB
:
884 case GL_NORMAL_ARRAY_BUFFER_BINDING_ARB
:
885 case GL_COLOR_ARRAY_BUFFER_BINDING_ARB
:
886 case GL_INDEX_ARRAY_BUFFER_BINDING_ARB
:
887 case GL_EDGE_FLAG_ARRAY_BUFFER_BINDING_ARB
:
888 case GL_SECONDARY_COLOR_ARRAY_BUFFER_BINDING_ARB
:
889 case GL_FOG_COORDINATE_ARRAY_BUFFER_BINDING_ARB
:
890 buffer_obj
= (struct gl_buffer_object
**)
891 ((char *) ctx
->Array
.VAO
+ d
->offset
);
892 v
->value_int
= (*buffer_obj
)->Name
;
894 case GL_ARRAY_BUFFER_BINDING_ARB
:
895 v
->value_int
= ctx
->Array
.ArrayBufferObj
->Name
;
897 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING_ARB
:
899 ctx
->Array
.VAO
->VertexBinding
[VERT_ATTRIB_TEX(ctx
->Array
.ActiveTexture
)].BufferObj
->Name
;
901 case GL_ELEMENT_ARRAY_BUFFER_BINDING_ARB
:
902 v
->value_int
= ctx
->Array
.VAO
->IndexBufferObj
->Name
;
905 /* ARB_vertex_array_bgra */
906 case GL_COLOR_ARRAY_SIZE
:
907 array
= &ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_COLOR0
];
908 v
->value_int
= array
->Format
== GL_BGRA
? GL_BGRA
: array
->Size
;
910 case GL_SECONDARY_COLOR_ARRAY_SIZE
:
911 array
= &ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_COLOR1
];
912 v
->value_int
= array
->Format
== GL_BGRA
? GL_BGRA
: array
->Size
;
915 /* ARB_copy_buffer */
916 case GL_COPY_READ_BUFFER
:
917 v
->value_int
= ctx
->CopyReadBuffer
->Name
;
919 case GL_COPY_WRITE_BUFFER
:
920 v
->value_int
= ctx
->CopyWriteBuffer
->Name
;
923 case GL_PIXEL_PACK_BUFFER_BINDING_EXT
:
924 v
->value_int
= ctx
->Pack
.BufferObj
->Name
;
926 case GL_PIXEL_UNPACK_BUFFER_BINDING_EXT
:
927 v
->value_int
= ctx
->Unpack
.BufferObj
->Name
;
929 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING
:
930 v
->value_int
= ctx
->TransformFeedback
.CurrentBuffer
->Name
;
932 case GL_TRANSFORM_FEEDBACK_BUFFER_PAUSED
:
933 v
->value_int
= ctx
->TransformFeedback
.CurrentObject
->Paused
;
935 case GL_TRANSFORM_FEEDBACK_BUFFER_ACTIVE
:
936 v
->value_int
= ctx
->TransformFeedback
.CurrentObject
->Active
;
938 case GL_TRANSFORM_FEEDBACK_BINDING
:
939 v
->value_int
= ctx
->TransformFeedback
.CurrentObject
->Name
;
941 case GL_CURRENT_PROGRAM
:
942 /* The Changelog of the ARB_separate_shader_objects spec says:
944 * 24 25 Jul 2011 pbrown Remove the language erroneously deleting
945 * CURRENT_PROGRAM. In the EXT extension, this
946 * token was aliased to ACTIVE_PROGRAM_EXT, and
947 * was used to indicate the last program set by
948 * either ActiveProgramEXT or UseProgram. In
949 * the ARB extension, the SSO active programs
950 * are now program pipeline object state and
951 * CURRENT_PROGRAM should still be used to query
952 * the last program set by UseProgram (bug 7822).
955 ctx
->Shader
.ActiveProgram
? ctx
->Shader
.ActiveProgram
->Name
: 0;
957 case GL_READ_FRAMEBUFFER_BINDING_EXT
:
958 v
->value_int
= ctx
->ReadBuffer
->Name
;
960 case GL_RENDERBUFFER_BINDING_EXT
:
962 ctx
->CurrentRenderbuffer
? ctx
->CurrentRenderbuffer
->Name
: 0;
964 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES
:
965 v
->value_int
= ctx
->Array
.VAO
->VertexBinding
[VERT_ATTRIB_POINT_SIZE
].BufferObj
->Name
;
969 if (_mesa_get_clamp_fragment_color(ctx
, ctx
->DrawBuffer
))
970 COPY_4FV(v
->value_float_4
, ctx
->Fog
.Color
);
972 COPY_4FV(v
->value_float_4
, ctx
->Fog
.ColorUnclamped
);
974 case GL_COLOR_CLEAR_VALUE
:
975 if (_mesa_get_clamp_fragment_color(ctx
, ctx
->DrawBuffer
)) {
976 v
->value_float_4
[0] = CLAMP(ctx
->Color
.ClearColor
.f
[0], 0.0F
, 1.0F
);
977 v
->value_float_4
[1] = CLAMP(ctx
->Color
.ClearColor
.f
[1], 0.0F
, 1.0F
);
978 v
->value_float_4
[2] = CLAMP(ctx
->Color
.ClearColor
.f
[2], 0.0F
, 1.0F
);
979 v
->value_float_4
[3] = CLAMP(ctx
->Color
.ClearColor
.f
[3], 0.0F
, 1.0F
);
981 COPY_4FV(v
->value_float_4
, ctx
->Color
.ClearColor
.f
);
983 case GL_BLEND_COLOR_EXT
:
984 if (_mesa_get_clamp_fragment_color(ctx
, ctx
->DrawBuffer
))
985 COPY_4FV(v
->value_float_4
, ctx
->Color
.BlendColor
);
987 COPY_4FV(v
->value_float_4
, ctx
->Color
.BlendColorUnclamped
);
989 case GL_ALPHA_TEST_REF
:
990 if (_mesa_get_clamp_fragment_color(ctx
, ctx
->DrawBuffer
))
991 v
->value_float
= ctx
->Color
.AlphaRef
;
993 v
->value_float
= ctx
->Color
.AlphaRefUnclamped
;
995 case GL_MAX_VERTEX_UNIFORM_VECTORS
:
996 v
->value_int
= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxUniformComponents
/ 4;
999 case GL_MAX_FRAGMENT_UNIFORM_VECTORS
:
1000 v
->value_int
= ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxUniformComponents
/ 4;
1003 /* GL_ARB_texture_buffer_object */
1004 case GL_TEXTURE_BUFFER_ARB
:
1005 v
->value_int
= ctx
->Texture
.BufferObject
->Name
;
1007 case GL_TEXTURE_BINDING_BUFFER_ARB
:
1008 unit
= ctx
->Texture
.CurrentUnit
;
1010 ctx
->Texture
.Unit
[unit
].CurrentTex
[TEXTURE_BUFFER_INDEX
]->Name
;
1012 case GL_TEXTURE_BUFFER_DATA_STORE_BINDING_ARB
:
1014 struct gl_buffer_object
*buf
=
1015 ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
]
1016 .CurrentTex
[TEXTURE_BUFFER_INDEX
]->BufferObject
;
1017 v
->value_int
= buf
? buf
->Name
: 0;
1020 case GL_TEXTURE_BUFFER_FORMAT_ARB
:
1021 v
->value_int
= ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
]
1022 .CurrentTex
[TEXTURE_BUFFER_INDEX
]->BufferObjectFormat
;
1025 /* GL_ARB_sampler_objects */
1026 case GL_SAMPLER_BINDING
:
1028 struct gl_sampler_object
*samp
=
1029 ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
].Sampler
;
1030 v
->value_int
= samp
? samp
->Name
: 0;
1033 /* GL_ARB_uniform_buffer_object */
1034 case GL_UNIFORM_BUFFER_BINDING
:
1035 v
->value_int
= ctx
->UniformBuffer
->Name
;
1037 /* GL_ARB_shader_storage_buffer_object */
1038 case GL_SHADER_STORAGE_BUFFER_BINDING
:
1039 v
->value_int
= ctx
->ShaderStorageBuffer
->Name
;
1041 /* GL_ARB_query_buffer_object */
1042 case GL_QUERY_BUFFER_BINDING
:
1043 v
->value_int
= ctx
->QueryBuffer
->Name
;
1045 /* GL_ARB_timer_query */
1047 if (ctx
->Driver
.GetTimestamp
) {
1048 v
->value_int64
= ctx
->Driver
.GetTimestamp(ctx
);
1051 _mesa_problem(ctx
, "driver doesn't implement GetTimestamp");
1055 case GL_DEBUG_LOGGED_MESSAGES
:
1056 case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH
:
1057 case GL_DEBUG_GROUP_STACK_DEPTH
:
1058 v
->value_int
= _mesa_get_debug_state_int(ctx
, d
->pname
);
1060 /* GL_ARB_shader_atomic_counters */
1061 case GL_ATOMIC_COUNTER_BUFFER_BINDING
:
1062 if (ctx
->AtomicBuffer
) {
1063 v
->value_int
= ctx
->AtomicBuffer
->Name
;
1068 /* GL_ARB_draw_indirect */
1069 case GL_DRAW_INDIRECT_BUFFER_BINDING
:
1070 v
->value_int
= ctx
->DrawIndirectBuffer
->Name
;
1072 /* GL_ARB_indirect_parameters */
1073 case GL_PARAMETER_BUFFER_BINDING_ARB
:
1074 v
->value_int
= ctx
->ParameterBuffer
->Name
;
1076 /* GL_ARB_separate_shader_objects */
1077 case GL_PROGRAM_PIPELINE_BINDING
:
1078 if (ctx
->Pipeline
.Current
) {
1079 v
->value_int
= ctx
->Pipeline
.Current
->Name
;
1084 /* GL_ARB_compute_shader */
1085 case GL_DISPATCH_INDIRECT_BUFFER_BINDING
:
1086 v
->value_int
= ctx
->DispatchIndirectBuffer
->Name
;
1092 * Check extra constraints on a struct value_desc descriptor
1094 * If a struct value_desc has a non-NULL extra pointer, it means that
1095 * there are a number of extra constraints to check or actions to
1096 * perform. The extras is just an integer array where each integer
1097 * encode different constraints or actions.
1099 * \param ctx current context
1100 * \param func name of calling glGet*v() function for error reporting
1101 * \param d the struct value_desc that has the extra constraints
1103 * \return GL_FALSE if all of the constraints were not satisfied,
1104 * otherwise GL_TRUE.
1107 check_extra(struct gl_context
*ctx
, const char *func
, const struct value_desc
*d
)
1109 const GLuint version
= ctx
->Version
;
1110 GLboolean api_check
= GL_FALSE
;
1111 GLboolean api_found
= GL_FALSE
;
1114 for (e
= d
->extra
; *e
!= EXTRA_END
; e
++) {
1116 case EXTRA_VERSION_30
:
1117 api_check
= GL_TRUE
;
1119 api_found
= GL_TRUE
;
1121 case EXTRA_VERSION_31
:
1122 api_check
= GL_TRUE
;
1124 api_found
= GL_TRUE
;
1126 case EXTRA_VERSION_32
:
1127 api_check
= GL_TRUE
;
1129 api_found
= GL_TRUE
;
1131 case EXTRA_NEW_FRAG_CLAMP
:
1132 if (ctx
->NewState
& (_NEW_BUFFERS
| _NEW_FRAG_CLAMP
))
1133 _mesa_update_state(ctx
);
1136 api_check
= GL_TRUE
;
1137 if (ctx
->API
== API_OPENGLES2
)
1138 api_found
= GL_TRUE
;
1141 api_check
= GL_TRUE
;
1142 if (_mesa_is_gles3(ctx
))
1143 api_found
= GL_TRUE
;
1145 case EXTRA_API_ES31
:
1146 api_check
= GL_TRUE
;
1147 if (_mesa_is_gles31(ctx
))
1148 api_found
= GL_TRUE
;
1151 api_check
= GL_TRUE
;
1152 if (_mesa_is_desktop_gl(ctx
))
1153 api_found
= GL_TRUE
;
1155 case EXTRA_API_GL_CORE
:
1156 api_check
= GL_TRUE
;
1157 if (ctx
->API
== API_OPENGL_CORE
)
1158 api_found
= GL_TRUE
;
1160 case EXTRA_NEW_BUFFERS
:
1161 if (ctx
->NewState
& _NEW_BUFFERS
)
1162 _mesa_update_state(ctx
);
1164 case EXTRA_FLUSH_CURRENT
:
1165 FLUSH_CURRENT(ctx
, 0);
1167 case EXTRA_VALID_DRAW_BUFFER
:
1168 if (d
->pname
- GL_DRAW_BUFFER0_ARB
>= ctx
->Const
.MaxDrawBuffers
) {
1169 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(draw buffer %u)",
1170 func
, d
->pname
- GL_DRAW_BUFFER0_ARB
);
1174 case EXTRA_VALID_TEXTURE_UNIT
:
1175 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureCoordUnits
) {
1176 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(texture %u)",
1177 func
, ctx
->Texture
.CurrentUnit
);
1181 case EXTRA_VALID_CLIP_DISTANCE
:
1182 if (d
->pname
- GL_CLIP_DISTANCE0
>= ctx
->Const
.MaxClipPlanes
) {
1183 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(clip distance %u)",
1184 func
, d
->pname
- GL_CLIP_DISTANCE0
);
1188 case EXTRA_GLSL_130
:
1189 api_check
= GL_TRUE
;
1190 if (ctx
->Const
.GLSLVersion
>= 130)
1191 api_found
= GL_TRUE
;
1193 case EXTRA_EXT_UBO_GS
:
1194 api_check
= GL_TRUE
;
1195 if (ctx
->Extensions
.ARB_uniform_buffer_object
&&
1196 _mesa_has_geometry_shaders(ctx
))
1197 api_found
= GL_TRUE
;
1199 case EXTRA_EXT_ATOMICS_GS
:
1200 api_check
= GL_TRUE
;
1201 if (ctx
->Extensions
.ARB_shader_atomic_counters
&&
1202 _mesa_has_geometry_shaders(ctx
))
1203 api_found
= GL_TRUE
;
1205 case EXTRA_EXT_SHADER_IMAGE_GS
:
1206 api_check
= GL_TRUE
;
1207 if (ctx
->Extensions
.ARB_shader_image_load_store
&&
1208 _mesa_has_geometry_shaders(ctx
))
1209 api_found
= GL_TRUE
;
1211 case EXTRA_EXT_ATOMICS_TESS
:
1212 api_check
= GL_TRUE
;
1213 api_found
= ctx
->Extensions
.ARB_shader_atomic_counters
&&
1214 _mesa_has_tessellation(ctx
);
1216 case EXTRA_EXT_SHADER_IMAGE_TESS
:
1217 api_check
= GL_TRUE
;
1218 api_found
= ctx
->Extensions
.ARB_shader_image_load_store
&&
1219 _mesa_has_tessellation(ctx
);
1221 case EXTRA_EXT_SSBO_GS
:
1222 api_check
= GL_TRUE
;
1223 if (ctx
->Extensions
.ARB_shader_storage_buffer_object
&&
1224 _mesa_has_geometry_shaders(ctx
))
1225 api_found
= GL_TRUE
;
1227 case EXTRA_EXT_FB_NO_ATTACH_GS
:
1228 api_check
= GL_TRUE
;
1229 if (ctx
->Extensions
.ARB_framebuffer_no_attachments
&&
1230 (_mesa_is_desktop_gl(ctx
) ||
1231 _mesa_has_OES_geometry_shader(ctx
)))
1232 api_found
= GL_TRUE
;
1234 case EXTRA_EXT_ES_GS
:
1235 api_check
= GL_TRUE
;
1236 if (_mesa_has_OES_geometry_shader(ctx
))
1237 api_found
= GL_TRUE
;
1241 default: /* *e is a offset into the extension struct */
1242 api_check
= GL_TRUE
;
1243 if (*(GLboolean
*) ((char *) &ctx
->Extensions
+ *e
))
1244 api_found
= GL_TRUE
;
1249 if (api_check
&& !api_found
) {
1250 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=%s)", func
,
1251 _mesa_enum_to_string(d
->pname
));
1258 static const struct value_desc error_value
=
1259 { 0, 0, TYPE_INVALID
, NO_OFFSET
, NO_EXTRA
};
1262 * Find the struct value_desc corresponding to the enum 'pname'.
1264 * We hash the enum value to get an index into the 'table' array,
1265 * which holds the index in the 'values' array of struct value_desc.
1266 * Once we've found the entry, we do the extra checks, if any, then
1267 * look up the value and return a pointer to it.
1269 * If the value has to be computed (for example, it's the result of a
1270 * function call or we need to add 1 to it), we use the tmp 'v' to
1273 * \param func name of glGet*v() func for error reporting
1274 * \param pname the enum value we're looking up
1275 * \param p is were we return the pointer to the value
1276 * \param v a tmp union value variable in the calling glGet*v() function
1278 * \return the struct value_desc corresponding to the enum or a struct
1279 * value_desc of TYPE_INVALID if not found. This lets the calling
1280 * glGet*v() function jump right into a switch statement and
1281 * handle errors there instead of having to check for NULL.
1283 static const struct value_desc
*
1284 find_value(const char *func
, GLenum pname
, void **p
, union value
*v
)
1286 GET_CURRENT_CONTEXT(ctx
);
1287 struct gl_texture_unit
*unit
;
1289 const struct value_desc
*d
;
1293 /* We index into the table_set[] list of per-API hash tables using the API's
1294 * value in the gl_api enum. Since GLES 3 doesn't have an API_OPENGL* enum
1295 * value since it's compatible with GLES2 its entry in table_set[] is at the
1298 STATIC_ASSERT(ARRAY_SIZE(table_set
) == API_OPENGL_LAST
+ 3);
1299 if (_mesa_is_gles3(ctx
)) {
1300 api
= API_OPENGL_LAST
+ 1;
1302 if (_mesa_is_gles31(ctx
)) {
1303 api
= API_OPENGL_LAST
+ 2;
1305 mask
= ARRAY_SIZE(table(api
)) - 1;
1306 hash
= (pname
* prime_factor
);
1308 int idx
= table(api
)[hash
& mask
];
1310 /* If the enum isn't valid, the hash walk ends with index 0,
1311 * pointing to the first entry of values[] which doesn't hold
1312 * any valid enum. */
1313 if (unlikely(idx
== 0)) {
1314 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=%s)", func
,
1315 _mesa_enum_to_string(pname
));
1316 return &error_value
;
1320 if (likely(d
->pname
== pname
))
1326 if (unlikely(d
->extra
&& !check_extra(ctx
, func
, d
)))
1327 return &error_value
;
1329 switch (d
->location
) {
1331 *p
= ((char *) ctx
->DrawBuffer
+ d
->offset
);
1334 *p
= ((char *) ctx
+ d
->offset
);
1337 *p
= ((char *) ctx
->Array
.VAO
+ d
->offset
);
1340 unit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1341 *p
= ((char *) unit
+ d
->offset
);
1344 find_custom_value(ctx
, d
, v
);
1352 /* silence warning */
1353 return &error_value
;
1356 static const int transpose
[] = {
1364 _mesa_GetBooleanv(GLenum pname
, GLboolean
*params
)
1366 const struct value_desc
*d
;
1372 d
= find_value("glGetBooleanv", pname
, &p
, &v
);
1377 params
[0] = INT_TO_BOOLEAN(d
->offset
);
1382 params
[3] = FLOAT_TO_BOOLEAN(((GLfloat
*) p
)[3]);
1385 params
[2] = FLOAT_TO_BOOLEAN(((GLfloat
*) p
)[2]);
1388 params
[1] = FLOAT_TO_BOOLEAN(((GLfloat
*) p
)[1]);
1391 params
[0] = FLOAT_TO_BOOLEAN(((GLfloat
*) p
)[0]);
1394 case TYPE_DOUBLEN_2
:
1395 params
[1] = FLOAT_TO_BOOLEAN(((GLdouble
*) p
)[1]);
1397 params
[0] = FLOAT_TO_BOOLEAN(((GLdouble
*) p
)[0]);
1401 params
[3] = INT_TO_BOOLEAN(((GLint
*) p
)[3]);
1403 params
[2] = INT_TO_BOOLEAN(((GLint
*) p
)[2]);
1406 params
[1] = INT_TO_BOOLEAN(((GLint
*) p
)[1]);
1409 params
[0] = INT_TO_BOOLEAN(((GLint
*) p
)[0]);
1413 for (i
= 0; i
< v
.value_int_n
.n
; i
++)
1414 params
[i
] = INT_TO_BOOLEAN(v
.value_int_n
.ints
[i
]);
1418 params
[0] = INT64_TO_BOOLEAN(((GLint64
*) p
)[0]);
1422 params
[0] = ((GLboolean
*) p
)[0];
1426 m
= *(GLmatrix
**) p
;
1427 for (i
= 0; i
< 16; i
++)
1428 params
[i
] = FLOAT_TO_BOOLEAN(m
->m
[i
]);
1432 m
= *(GLmatrix
**) p
;
1433 for (i
= 0; i
< 16; i
++)
1434 params
[i
] = FLOAT_TO_BOOLEAN(m
->m
[transpose
[i
]]);
1445 shift
= d
->type
- TYPE_BIT_0
;
1446 params
[0] = (*(GLbitfield
*) p
>> shift
) & 1;
1452 _mesa_GetFloatv(GLenum pname
, GLfloat
*params
)
1454 const struct value_desc
*d
;
1460 d
= find_value("glGetFloatv", pname
, &p
, &v
);
1465 params
[0] = (GLfloat
) d
->offset
;
1470 params
[3] = ((GLfloat
*) p
)[3];
1473 params
[2] = ((GLfloat
*) p
)[2];
1476 params
[1] = ((GLfloat
*) p
)[1];
1479 params
[0] = ((GLfloat
*) p
)[0];
1482 case TYPE_DOUBLEN_2
:
1483 params
[1] = (GLfloat
) (((GLdouble
*) p
)[1]);
1485 params
[0] = (GLfloat
) (((GLdouble
*) p
)[0]);
1489 params
[3] = (GLfloat
) (((GLint
*) p
)[3]);
1491 params
[2] = (GLfloat
) (((GLint
*) p
)[2]);
1494 params
[1] = (GLfloat
) (((GLint
*) p
)[1]);
1497 params
[0] = (GLfloat
) (((GLint
*) p
)[0]);
1501 for (i
= 0; i
< v
.value_int_n
.n
; i
++)
1502 params
[i
] = INT_TO_FLOAT(v
.value_int_n
.ints
[i
]);
1506 params
[0] = (GLfloat
) (((GLint64
*) p
)[0]);
1510 params
[0] = BOOLEAN_TO_FLOAT(*(GLboolean
*) p
);
1514 m
= *(GLmatrix
**) p
;
1515 for (i
= 0; i
< 16; i
++)
1516 params
[i
] = m
->m
[i
];
1520 m
= *(GLmatrix
**) p
;
1521 for (i
= 0; i
< 16; i
++)
1522 params
[i
] = m
->m
[transpose
[i
]];
1533 shift
= d
->type
- TYPE_BIT_0
;
1534 params
[0] = BOOLEAN_TO_FLOAT((*(GLbitfield
*) p
>> shift
) & 1);
1540 _mesa_GetIntegerv(GLenum pname
, GLint
*params
)
1542 const struct value_desc
*d
;
1548 d
= find_value("glGetIntegerv", pname
, &p
, &v
);
1553 params
[0] = d
->offset
;
1557 params
[3] = IROUND(((GLfloat
*) p
)[3]);
1559 params
[2] = IROUND(((GLfloat
*) p
)[2]);
1561 params
[1] = IROUND(((GLfloat
*) p
)[1]);
1563 params
[0] = IROUND(((GLfloat
*) p
)[0]);
1567 params
[3] = FLOAT_TO_INT(((GLfloat
*) p
)[3]);
1569 params
[2] = FLOAT_TO_INT(((GLfloat
*) p
)[2]);
1571 params
[1] = FLOAT_TO_INT(((GLfloat
*) p
)[1]);
1573 params
[0] = FLOAT_TO_INT(((GLfloat
*) p
)[0]);
1576 case TYPE_DOUBLEN_2
:
1577 params
[1] = FLOAT_TO_INT(((GLdouble
*) p
)[1]);
1579 params
[0] = FLOAT_TO_INT(((GLdouble
*) p
)[0]);
1583 params
[3] = ((GLint
*) p
)[3];
1585 params
[2] = ((GLint
*) p
)[2];
1588 params
[1] = ((GLint
*) p
)[1];
1591 params
[0] = ((GLint
*) p
)[0];
1595 for (i
= 0; i
< v
.value_int_n
.n
; i
++)
1596 params
[i
] = v
.value_int_n
.ints
[i
];
1600 params
[0] = INT64_TO_INT(((GLint64
*) p
)[0]);
1604 params
[0] = BOOLEAN_TO_INT(*(GLboolean
*) p
);
1608 m
= *(GLmatrix
**) p
;
1609 for (i
= 0; i
< 16; i
++)
1610 params
[i
] = FLOAT_TO_INT(m
->m
[i
]);
1614 m
= *(GLmatrix
**) p
;
1615 for (i
= 0; i
< 16; i
++)
1616 params
[i
] = FLOAT_TO_INT(m
->m
[transpose
[i
]]);
1627 shift
= d
->type
- TYPE_BIT_0
;
1628 params
[0] = (*(GLbitfield
*) p
>> shift
) & 1;
1634 _mesa_GetInteger64v(GLenum pname
, GLint64
*params
)
1636 const struct value_desc
*d
;
1642 d
= find_value("glGetInteger64v", pname
, &p
, &v
);
1647 params
[0] = d
->offset
;
1651 params
[3] = IROUND64(((GLfloat
*) p
)[3]);
1653 params
[2] = IROUND64(((GLfloat
*) p
)[2]);
1655 params
[1] = IROUND64(((GLfloat
*) p
)[1]);
1657 params
[0] = IROUND64(((GLfloat
*) p
)[0]);
1661 params
[3] = FLOAT_TO_INT64(((GLfloat
*) p
)[3]);
1663 params
[2] = FLOAT_TO_INT64(((GLfloat
*) p
)[2]);
1665 params
[1] = FLOAT_TO_INT64(((GLfloat
*) p
)[1]);
1667 params
[0] = FLOAT_TO_INT64(((GLfloat
*) p
)[0]);
1670 case TYPE_DOUBLEN_2
:
1671 params
[1] = FLOAT_TO_INT64(((GLdouble
*) p
)[1]);
1673 params
[0] = FLOAT_TO_INT64(((GLdouble
*) p
)[0]);
1677 params
[3] = ((GLint
*) p
)[3];
1679 params
[2] = ((GLint
*) p
)[2];
1682 params
[1] = ((GLint
*) p
)[1];
1685 params
[0] = ((GLint
*) p
)[0];
1689 for (i
= 0; i
< v
.value_int_n
.n
; i
++)
1690 params
[i
] = INT_TO_BOOLEAN(v
.value_int_n
.ints
[i
]);
1694 params
[0] = ((GLint64
*) p
)[0];
1698 params
[0] = ((GLboolean
*) p
)[0];
1702 m
= *(GLmatrix
**) p
;
1703 for (i
= 0; i
< 16; i
++)
1704 params
[i
] = FLOAT_TO_INT64(m
->m
[i
]);
1708 m
= *(GLmatrix
**) p
;
1709 for (i
= 0; i
< 16; i
++)
1710 params
[i
] = FLOAT_TO_INT64(m
->m
[transpose
[i
]]);
1721 shift
= d
->type
- TYPE_BIT_0
;
1722 params
[0] = (*(GLbitfield
*) p
>> shift
) & 1;
1728 _mesa_GetDoublev(GLenum pname
, GLdouble
*params
)
1730 const struct value_desc
*d
;
1736 d
= find_value("glGetDoublev", pname
, &p
, &v
);
1741 params
[0] = d
->offset
;
1746 params
[3] = ((GLfloat
*) p
)[3];
1749 params
[2] = ((GLfloat
*) p
)[2];
1752 params
[1] = ((GLfloat
*) p
)[1];
1755 params
[0] = ((GLfloat
*) p
)[0];
1758 case TYPE_DOUBLEN_2
:
1759 params
[1] = ((GLdouble
*) p
)[1];
1761 params
[0] = ((GLdouble
*) p
)[0];
1765 params
[3] = ((GLint
*) p
)[3];
1767 params
[2] = ((GLint
*) p
)[2];
1770 params
[1] = ((GLint
*) p
)[1];
1773 params
[0] = ((GLint
*) p
)[0];
1777 for (i
= 0; i
< v
.value_int_n
.n
; i
++)
1778 params
[i
] = v
.value_int_n
.ints
[i
];
1782 params
[0] = (GLdouble
) (((GLint64
*) p
)[0]);
1786 params
[0] = *(GLboolean
*) p
;
1790 m
= *(GLmatrix
**) p
;
1791 for (i
= 0; i
< 16; i
++)
1792 params
[i
] = m
->m
[i
];
1796 m
= *(GLmatrix
**) p
;
1797 for (i
= 0; i
< 16; i
++)
1798 params
[i
] = m
->m
[transpose
[i
]];
1809 shift
= d
->type
- TYPE_BIT_0
;
1810 params
[0] = (*(GLbitfield
*) p
>> shift
) & 1;
1816 * Convert a GL texture binding enum such as GL_TEXTURE_BINDING_2D
1817 * into the corresponding Mesa texture target index.
1818 * \return TEXTURE_x_INDEX or -1 if binding is invalid
1821 tex_binding_to_index(const struct gl_context
*ctx
, GLenum binding
)
1824 case GL_TEXTURE_BINDING_1D
:
1825 return _mesa_is_desktop_gl(ctx
) ? TEXTURE_1D_INDEX
: -1;
1826 case GL_TEXTURE_BINDING_2D
:
1827 return TEXTURE_2D_INDEX
;
1828 case GL_TEXTURE_BINDING_3D
:
1829 return ctx
->API
!= API_OPENGLES
? TEXTURE_3D_INDEX
: -1;
1830 case GL_TEXTURE_BINDING_CUBE_MAP
:
1831 return ctx
->Extensions
.ARB_texture_cube_map
1832 ? TEXTURE_CUBE_INDEX
: -1;
1833 case GL_TEXTURE_BINDING_RECTANGLE
:
1834 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.NV_texture_rectangle
1835 ? TEXTURE_RECT_INDEX
: -1;
1836 case GL_TEXTURE_BINDING_1D_ARRAY
:
1837 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
1838 ? TEXTURE_1D_ARRAY_INDEX
: -1;
1839 case GL_TEXTURE_BINDING_2D_ARRAY
:
1840 return (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
)
1841 || _mesa_is_gles3(ctx
)
1842 ? TEXTURE_2D_ARRAY_INDEX
: -1;
1843 case GL_TEXTURE_BINDING_BUFFER
:
1844 return ctx
->API
== API_OPENGL_CORE
&&
1845 ctx
->Extensions
.ARB_texture_buffer_object
?
1846 TEXTURE_BUFFER_INDEX
: -1;
1847 case GL_TEXTURE_BINDING_CUBE_MAP_ARRAY
:
1848 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_cube_map_array
1849 ? TEXTURE_CUBE_ARRAY_INDEX
: -1;
1850 case GL_TEXTURE_BINDING_2D_MULTISAMPLE
:
1851 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_multisample
1852 ? TEXTURE_2D_MULTISAMPLE_INDEX
: -1;
1853 case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY
:
1854 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_multisample
1855 ? TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX
: -1;
1861 static enum value_type
1862 find_value_indexed(const char *func
, GLenum pname
, GLuint index
, union value
*v
)
1864 GET_CURRENT_CONTEXT(ctx
);
1869 if (index
>= ctx
->Const
.MaxDrawBuffers
)
1871 if (!ctx
->Extensions
.EXT_draw_buffers2
)
1873 v
->value_int
= (ctx
->Color
.BlendEnabled
>> index
) & 1;
1878 case GL_BLEND_SRC_RGB
:
1879 if (index
>= ctx
->Const
.MaxDrawBuffers
)
1881 if (!ctx
->Extensions
.ARB_draw_buffers_blend
)
1883 v
->value_int
= ctx
->Color
.Blend
[index
].SrcRGB
;
1885 case GL_BLEND_SRC_ALPHA
:
1886 if (index
>= ctx
->Const
.MaxDrawBuffers
)
1888 if (!ctx
->Extensions
.ARB_draw_buffers_blend
)
1890 v
->value_int
= ctx
->Color
.Blend
[index
].SrcA
;
1894 case GL_BLEND_DST_RGB
:
1895 if (index
>= ctx
->Const
.MaxDrawBuffers
)
1897 if (!ctx
->Extensions
.ARB_draw_buffers_blend
)
1899 v
->value_int
= ctx
->Color
.Blend
[index
].DstRGB
;
1901 case GL_BLEND_DST_ALPHA
:
1902 if (index
>= ctx
->Const
.MaxDrawBuffers
)
1904 if (!ctx
->Extensions
.ARB_draw_buffers_blend
)
1906 v
->value_int
= ctx
->Color
.Blend
[index
].DstA
;
1908 case GL_BLEND_EQUATION_RGB
:
1909 if (index
>= ctx
->Const
.MaxDrawBuffers
)
1911 if (!ctx
->Extensions
.ARB_draw_buffers_blend
)
1913 v
->value_int
= ctx
->Color
.Blend
[index
].EquationRGB
;
1915 case GL_BLEND_EQUATION_ALPHA
:
1916 if (index
>= ctx
->Const
.MaxDrawBuffers
)
1918 if (!ctx
->Extensions
.ARB_draw_buffers_blend
)
1920 v
->value_int
= ctx
->Color
.Blend
[index
].EquationA
;
1923 case GL_COLOR_WRITEMASK
:
1924 if (index
>= ctx
->Const
.MaxDrawBuffers
)
1926 if (!ctx
->Extensions
.EXT_draw_buffers2
)
1928 v
->value_int_4
[0] = ctx
->Color
.ColorMask
[index
][RCOMP
] ? 1 : 0;
1929 v
->value_int_4
[1] = ctx
->Color
.ColorMask
[index
][GCOMP
] ? 1 : 0;
1930 v
->value_int_4
[2] = ctx
->Color
.ColorMask
[index
][BCOMP
] ? 1 : 0;
1931 v
->value_int_4
[3] = ctx
->Color
.ColorMask
[index
][ACOMP
] ? 1 : 0;
1934 case GL_SCISSOR_BOX
:
1935 if (index
>= ctx
->Const
.MaxViewports
)
1937 v
->value_int_4
[0] = ctx
->Scissor
.ScissorArray
[index
].X
;
1938 v
->value_int_4
[1] = ctx
->Scissor
.ScissorArray
[index
].Y
;
1939 v
->value_int_4
[2] = ctx
->Scissor
.ScissorArray
[index
].Width
;
1940 v
->value_int_4
[3] = ctx
->Scissor
.ScissorArray
[index
].Height
;
1944 if (index
>= ctx
->Const
.MaxViewports
)
1946 v
->value_float_4
[0] = ctx
->ViewportArray
[index
].X
;
1947 v
->value_float_4
[1] = ctx
->ViewportArray
[index
].Y
;
1948 v
->value_float_4
[2] = ctx
->ViewportArray
[index
].Width
;
1949 v
->value_float_4
[3] = ctx
->ViewportArray
[index
].Height
;
1950 return TYPE_FLOAT_4
;
1952 case GL_DEPTH_RANGE
:
1953 if (index
>= ctx
->Const
.MaxViewports
)
1955 v
->value_double_2
[0] = ctx
->ViewportArray
[index
].Near
;
1956 v
->value_double_2
[1] = ctx
->ViewportArray
[index
].Far
;
1957 return TYPE_DOUBLEN_2
;
1959 case GL_TRANSFORM_FEEDBACK_BUFFER_START
:
1960 if (index
>= ctx
->Const
.MaxTransformFeedbackBuffers
)
1962 if (!ctx
->Extensions
.EXT_transform_feedback
)
1964 v
->value_int64
= ctx
->TransformFeedback
.CurrentObject
->Offset
[index
];
1967 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE
:
1968 if (index
>= ctx
->Const
.MaxTransformFeedbackBuffers
)
1970 if (!ctx
->Extensions
.EXT_transform_feedback
)
1973 = ctx
->TransformFeedback
.CurrentObject
->RequestedSize
[index
];
1976 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING
:
1977 if (index
>= ctx
->Const
.MaxTransformFeedbackBuffers
)
1979 if (!ctx
->Extensions
.EXT_transform_feedback
)
1981 v
->value_int
= ctx
->TransformFeedback
.CurrentObject
->BufferNames
[index
];
1984 case GL_UNIFORM_BUFFER_BINDING
:
1985 if (index
>= ctx
->Const
.MaxUniformBufferBindings
)
1987 if (!ctx
->Extensions
.ARB_uniform_buffer_object
)
1989 v
->value_int
= ctx
->UniformBufferBindings
[index
].BufferObject
->Name
;
1992 case GL_UNIFORM_BUFFER_START
:
1993 if (index
>= ctx
->Const
.MaxUniformBufferBindings
)
1995 if (!ctx
->Extensions
.ARB_uniform_buffer_object
)
1997 v
->value_int
= ctx
->UniformBufferBindings
[index
].Offset
< 0 ? 0 :
1998 ctx
->UniformBufferBindings
[index
].Offset
;
2001 case GL_UNIFORM_BUFFER_SIZE
:
2002 if (index
>= ctx
->Const
.MaxUniformBufferBindings
)
2004 if (!ctx
->Extensions
.ARB_uniform_buffer_object
)
2006 v
->value_int
= ctx
->UniformBufferBindings
[index
].Size
< 0 ? 0 :
2007 ctx
->UniformBufferBindings
[index
].Size
;
2010 /* ARB_shader_storage_buffer_object */
2011 case GL_SHADER_STORAGE_BUFFER_BINDING
:
2012 if (!ctx
->Extensions
.ARB_shader_storage_buffer_object
)
2014 if (index
>= ctx
->Const
.MaxShaderStorageBufferBindings
)
2016 v
->value_int
= ctx
->ShaderStorageBufferBindings
[index
].BufferObject
->Name
;
2019 case GL_SHADER_STORAGE_BUFFER_START
:
2020 if (!ctx
->Extensions
.ARB_shader_storage_buffer_object
)
2022 if (index
>= ctx
->Const
.MaxShaderStorageBufferBindings
)
2024 v
->value_int
= ctx
->ShaderStorageBufferBindings
[index
].Offset
< 0 ? 0 :
2025 ctx
->ShaderStorageBufferBindings
[index
].Offset
;
2028 case GL_SHADER_STORAGE_BUFFER_SIZE
:
2029 if (!ctx
->Extensions
.ARB_shader_storage_buffer_object
)
2031 if (index
>= ctx
->Const
.MaxShaderStorageBufferBindings
)
2033 v
->value_int
= ctx
->ShaderStorageBufferBindings
[index
].Size
< 0 ? 0 :
2034 ctx
->ShaderStorageBufferBindings
[index
].Size
;
2037 /* ARB_texture_multisample / GL3.2 */
2038 case GL_SAMPLE_MASK_VALUE
:
2041 if (!ctx
->Extensions
.ARB_texture_multisample
)
2043 v
->value_int
= ctx
->Multisample
.SampleMaskValue
;
2046 case GL_ATOMIC_COUNTER_BUFFER_BINDING
:
2047 if (!ctx
->Extensions
.ARB_shader_atomic_counters
)
2049 if (index
>= ctx
->Const
.MaxAtomicBufferBindings
)
2051 v
->value_int
= ctx
->AtomicBufferBindings
[index
].BufferObject
->Name
;
2054 case GL_ATOMIC_COUNTER_BUFFER_START
:
2055 if (!ctx
->Extensions
.ARB_shader_atomic_counters
)
2057 if (index
>= ctx
->Const
.MaxAtomicBufferBindings
)
2059 v
->value_int64
= ctx
->AtomicBufferBindings
[index
].Offset
;
2062 case GL_ATOMIC_COUNTER_BUFFER_SIZE
:
2063 if (!ctx
->Extensions
.ARB_shader_atomic_counters
)
2065 if (index
>= ctx
->Const
.MaxAtomicBufferBindings
)
2067 v
->value_int64
= ctx
->AtomicBufferBindings
[index
].Size
;
2070 case GL_VERTEX_BINDING_DIVISOR
:
2071 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_instanced_arrays
) &&
2072 !_mesa_is_gles31(ctx
))
2074 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
)
2076 v
->value_int
= ctx
->Array
.VAO
->VertexBinding
[VERT_ATTRIB_GENERIC(index
)].InstanceDivisor
;
2079 case GL_VERTEX_BINDING_OFFSET
:
2080 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles31(ctx
))
2082 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
)
2084 v
->value_int
= ctx
->Array
.VAO
->VertexBinding
[VERT_ATTRIB_GENERIC(index
)].Offset
;
2087 case GL_VERTEX_BINDING_STRIDE
:
2088 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles31(ctx
))
2090 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
)
2092 v
->value_int
= ctx
->Array
.VAO
->VertexBinding
[VERT_ATTRIB_GENERIC(index
)].Stride
;
2095 case GL_VERTEX_BINDING_BUFFER
:
2096 if (ctx
->API
== API_OPENGLES2
&& ctx
->Version
< 31)
2098 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
)
2100 v
->value_int
= ctx
->Array
.VAO
->VertexBinding
[VERT_ATTRIB_GENERIC(index
)].BufferObj
->Name
;
2103 /* ARB_shader_image_load_store */
2104 case GL_IMAGE_BINDING_NAME
: {
2105 struct gl_texture_object
*t
;
2107 if (!ctx
->Extensions
.ARB_shader_image_load_store
)
2109 if (index
>= ctx
->Const
.MaxImageUnits
)
2112 t
= ctx
->ImageUnits
[index
].TexObj
;
2113 v
->value_int
= (t
? t
->Name
: 0);
2117 case GL_IMAGE_BINDING_LEVEL
:
2118 if (!ctx
->Extensions
.ARB_shader_image_load_store
)
2120 if (index
>= ctx
->Const
.MaxImageUnits
)
2123 v
->value_int
= ctx
->ImageUnits
[index
].Level
;
2126 case GL_IMAGE_BINDING_LAYERED
:
2127 if (!ctx
->Extensions
.ARB_shader_image_load_store
)
2129 if (index
>= ctx
->Const
.MaxImageUnits
)
2132 v
->value_int
= ctx
->ImageUnits
[index
].Layered
;
2135 case GL_IMAGE_BINDING_LAYER
:
2136 if (!ctx
->Extensions
.ARB_shader_image_load_store
)
2138 if (index
>= ctx
->Const
.MaxImageUnits
)
2141 v
->value_int
= ctx
->ImageUnits
[index
].Layer
;
2144 case GL_IMAGE_BINDING_ACCESS
:
2145 if (!ctx
->Extensions
.ARB_shader_image_load_store
)
2147 if (index
>= ctx
->Const
.MaxImageUnits
)
2150 v
->value_int
= ctx
->ImageUnits
[index
].Access
;
2153 case GL_IMAGE_BINDING_FORMAT
:
2154 if (!ctx
->Extensions
.ARB_shader_image_load_store
)
2156 if (index
>= ctx
->Const
.MaxImageUnits
)
2159 v
->value_int
= ctx
->ImageUnits
[index
].Format
;
2162 /* ARB_direct_state_access */
2163 case GL_TEXTURE_BINDING_1D
:
2164 case GL_TEXTURE_BINDING_1D_ARRAY
:
2165 case GL_TEXTURE_BINDING_2D
:
2166 case GL_TEXTURE_BINDING_2D_ARRAY
:
2167 case GL_TEXTURE_BINDING_2D_MULTISAMPLE
:
2168 case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY
:
2169 case GL_TEXTURE_BINDING_3D
:
2170 case GL_TEXTURE_BINDING_BUFFER
:
2171 case GL_TEXTURE_BINDING_CUBE_MAP
:
2172 case GL_TEXTURE_BINDING_CUBE_MAP_ARRAY
:
2173 case GL_TEXTURE_BINDING_RECTANGLE
: {
2176 if (ctx
->API
!= API_OPENGL_CORE
)
2178 target
= tex_binding_to_index(ctx
, pname
);
2181 if (index
>= _mesa_max_tex_unit(ctx
))
2184 v
->value_int
= ctx
->Texture
.Unit
[index
].CurrentTex
[target
]->Name
;
2188 case GL_SAMPLER_BINDING
: {
2189 struct gl_sampler_object
*samp
;
2191 if (ctx
->API
!= API_OPENGL_CORE
)
2193 if (index
>= _mesa_max_tex_unit(ctx
))
2196 samp
= ctx
->Texture
.Unit
[index
].Sampler
;
2197 v
->value_int
= samp
? samp
->Name
: 0;
2201 case GL_MAX_COMPUTE_WORK_GROUP_COUNT
:
2202 if (!_mesa_has_compute_shaders(ctx
))
2206 v
->value_int
= ctx
->Const
.MaxComputeWorkGroupCount
[index
];
2209 case GL_MAX_COMPUTE_WORK_GROUP_SIZE
:
2210 if (!_mesa_has_compute_shaders(ctx
))
2214 v
->value_int
= ctx
->Const
.MaxComputeWorkGroupSize
[index
];
2219 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=%s)", func
,
2220 _mesa_enum_to_string(pname
));
2221 return TYPE_INVALID
;
2223 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(pname=%s)", func
,
2224 _mesa_enum_to_string(pname
));
2225 return TYPE_INVALID
;
2229 _mesa_GetBooleani_v( GLenum pname
, GLuint index
, GLboolean
*params
)
2232 enum value_type type
=
2233 find_value_indexed("glGetBooleani_v", pname
, index
, &v
);
2237 params
[0] = INT_TO_BOOLEAN(v
.value_int
);
2240 params
[0] = INT_TO_BOOLEAN(v
.value_int_4
[0]);
2241 params
[1] = INT_TO_BOOLEAN(v
.value_int_4
[1]);
2242 params
[2] = INT_TO_BOOLEAN(v
.value_int_4
[2]);
2243 params
[3] = INT_TO_BOOLEAN(v
.value_int_4
[3]);
2246 params
[0] = INT64_TO_BOOLEAN(v
.value_int64
);
2249 ; /* nothing - GL error was recorded */
2254 _mesa_GetIntegeri_v( GLenum pname
, GLuint index
, GLint
*params
)
2257 enum value_type type
=
2258 find_value_indexed("glGetIntegeri_v", pname
, index
, &v
);
2263 params
[3] = IROUND(v
.value_float_4
[3]);
2266 params
[2] = IROUND(v
.value_float_4
[2]);
2269 params
[1] = IROUND(v
.value_float_4
[1]);
2272 params
[0] = IROUND(v
.value_float_4
[0]);
2275 case TYPE_DOUBLEN_2
:
2276 params
[1] = IROUND(v
.value_double_2
[1]);
2278 params
[0] = IROUND(v
.value_double_2
[0]);
2282 params
[0] = v
.value_int
;
2285 params
[0] = v
.value_int_4
[0];
2286 params
[1] = v
.value_int_4
[1];
2287 params
[2] = v
.value_int_4
[2];
2288 params
[3] = v
.value_int_4
[3];
2291 params
[0] = INT64_TO_INT(v
.value_int64
);
2294 ; /* nothing - GL error was recorded */
2299 _mesa_GetInteger64i_v( GLenum pname
, GLuint index
, GLint64
*params
)
2302 enum value_type type
=
2303 find_value_indexed("glGetInteger64i_v", pname
, index
, &v
);
2307 params
[0] = v
.value_int
;
2310 params
[0] = v
.value_int_4
[0];
2311 params
[1] = v
.value_int_4
[1];
2312 params
[2] = v
.value_int_4
[2];
2313 params
[3] = v
.value_int_4
[3];
2316 params
[0] = v
.value_int64
;
2319 ; /* nothing - GL error was recorded */
2324 _mesa_GetFloati_v(GLenum pname
, GLuint index
, GLfloat
*params
)
2329 enum value_type type
=
2330 find_value_indexed("glGetFloati_v", pname
, index
, &v
);
2335 params
[3] = v
.value_float_4
[3];
2338 params
[2] = v
.value_float_4
[2];
2341 params
[1] = v
.value_float_4
[1];
2344 params
[0] = v
.value_float_4
[0];
2347 case TYPE_DOUBLEN_2
:
2348 params
[1] = (GLfloat
) v
.value_double_2
[1];
2350 params
[0] = (GLfloat
) v
.value_double_2
[0];
2354 params
[3] = (GLfloat
) v
.value_int_4
[3];
2356 params
[2] = (GLfloat
) v
.value_int_4
[2];
2359 params
[1] = (GLfloat
) v
.value_int_4
[1];
2362 params
[0] = (GLfloat
) v
.value_int_4
[0];
2366 for (i
= 0; i
< v
.value_int_n
.n
; i
++)
2367 params
[i
] = INT_TO_FLOAT(v
.value_int_n
.ints
[i
]);
2371 params
[0] = (GLfloat
) v
.value_int64
;
2375 params
[0] = BOOLEAN_TO_FLOAT(v
.value_bool
);
2379 m
= *(GLmatrix
**) &v
;
2380 for (i
= 0; i
< 16; i
++)
2381 params
[i
] = m
->m
[i
];
2385 m
= *(GLmatrix
**) &v
;
2386 for (i
= 0; i
< 16; i
++)
2387 params
[i
] = m
->m
[transpose
[i
]];
2396 _mesa_GetDoublei_v(GLenum pname
, GLuint index
, GLdouble
*params
)
2401 enum value_type type
=
2402 find_value_indexed("glGetDoublei_v", pname
, index
, &v
);
2407 params
[3] = (GLdouble
) v
.value_float_4
[3];
2410 params
[2] = (GLdouble
) v
.value_float_4
[2];
2413 params
[1] = (GLdouble
) v
.value_float_4
[1];
2416 params
[0] = (GLdouble
) v
.value_float_4
[0];
2419 case TYPE_DOUBLEN_2
:
2420 params
[1] = v
.value_double_2
[1];
2422 params
[0] = v
.value_double_2
[0];
2426 params
[3] = (GLdouble
) v
.value_int_4
[3];
2428 params
[2] = (GLdouble
) v
.value_int_4
[2];
2431 params
[1] = (GLdouble
) v
.value_int_4
[1];
2434 params
[0] = (GLdouble
) v
.value_int_4
[0];
2438 for (i
= 0; i
< v
.value_int_n
.n
; i
++)
2439 params
[i
] = (GLdouble
) INT_TO_FLOAT(v
.value_int_n
.ints
[i
]);
2443 params
[0] = (GLdouble
) v
.value_int64
;
2447 params
[0] = (GLdouble
) BOOLEAN_TO_FLOAT(v
.value_bool
);
2451 m
= *(GLmatrix
**) &v
;
2452 for (i
= 0; i
< 16; i
++)
2453 params
[i
] = (GLdouble
) m
->m
[i
];
2457 m
= *(GLmatrix
**) &v
;
2458 for (i
= 0; i
< 16; i
++)
2459 params
[i
] = (GLdouble
) m
->m
[transpose
[i
]];
2468 _mesa_GetFixedv(GLenum pname
, GLfixed
*params
)
2470 const struct value_desc
*d
;
2476 d
= find_value("glGetDoublev", pname
, &p
, &v
);
2481 params
[0] = INT_TO_FIXED(d
->offset
);
2486 params
[3] = FLOAT_TO_FIXED(((GLfloat
*) p
)[3]);
2489 params
[2] = FLOAT_TO_FIXED(((GLfloat
*) p
)[2]);
2492 params
[1] = FLOAT_TO_FIXED(((GLfloat
*) p
)[1]);
2495 params
[0] = FLOAT_TO_FIXED(((GLfloat
*) p
)[0]);
2498 case TYPE_DOUBLEN_2
:
2499 params
[1] = FLOAT_TO_FIXED(((GLdouble
*) p
)[1]);
2501 params
[0] = FLOAT_TO_FIXED(((GLdouble
*) p
)[0]);
2505 params
[3] = INT_TO_FIXED(((GLint
*) p
)[3]);
2507 params
[2] = INT_TO_FIXED(((GLint
*) p
)[2]);
2510 params
[1] = INT_TO_FIXED(((GLint
*) p
)[1]);
2513 params
[0] = INT_TO_FIXED(((GLint
*) p
)[0]);
2517 for (i
= 0; i
< v
.value_int_n
.n
; i
++)
2518 params
[i
] = INT_TO_FIXED(v
.value_int_n
.ints
[i
]);
2522 params
[0] = ((GLint64
*) p
)[0];
2526 params
[0] = BOOLEAN_TO_FIXED(((GLboolean
*) p
)[0]);
2530 m
= *(GLmatrix
**) p
;
2531 for (i
= 0; i
< 16; i
++)
2532 params
[i
] = FLOAT_TO_FIXED(m
->m
[i
]);
2536 m
= *(GLmatrix
**) p
;
2537 for (i
= 0; i
< 16; i
++)
2538 params
[i
] = FLOAT_TO_FIXED(m
->m
[transpose
[i
]]);
2549 shift
= d
->type
- TYPE_BIT_0
;
2550 params
[0] = BOOLEAN_TO_FIXED((*(GLbitfield
*) p
>> shift
) & 1);