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
);
453 EXTRA_EXT(ATI_meminfo
);
454 EXTRA_EXT(NVX_gpu_memory_info
);
457 extra_ARB_color_buffer_float_or_glcore
[] = {
458 EXT(ARB_color_buffer_float
),
464 extra_NV_primitive_restart
[] = {
465 EXT(NV_primitive_restart
),
469 static const int extra_version_30
[] = { EXTRA_VERSION_30
, EXTRA_END
};
470 static const int extra_version_31
[] = { EXTRA_VERSION_31
, EXTRA_END
};
471 static const int extra_version_32
[] = { EXTRA_VERSION_32
, EXTRA_END
};
472 static const int extra_version_40
[] = { EXTRA_VERSION_40
, EXTRA_END
};
474 static const int extra_gl30_es3
[] = {
480 static const int extra_gl32_es3
[] = {
486 static const int extra_version_32_OES_geometry_shader
[] = {
492 static const int extra_gl40_ARB_sample_shading
[] = {
494 EXT(ARB_sample_shading
),
499 extra_ARB_vertex_program_api_es2
[] = {
500 EXT(ARB_vertex_program
),
505 /* The ReadBuffer get token is valid under either full GL or under
506 * GLES2 if the NV_read_buffer extension is available. */
508 extra_NV_read_buffer_api_gl
[] = {
514 static const int extra_core_ARB_color_buffer_float_and_new_buffers
[] = {
516 EXT(ARB_color_buffer_float
),
521 /* This is the big table describing all the enums we accept in
522 * glGet*v(). The table is partitioned into six parts: enums
523 * understood by all GL APIs (OpenGL, GLES and GLES2), enums shared
524 * between OpenGL and GLES, enums exclusive to GLES, etc for the
525 * remaining combinations. To look up the enums valid in a given API
526 * we will use a hash table specific to that API. These tables are in
527 * turn generated at build time and included through get_hash.h.
530 #include "get_hash.h"
532 /* All we need now is a way to look up the value struct from the enum.
533 * The code generated by gcc for the old generated big switch
534 * statement is a big, balanced, open coded if/else tree, essentially
535 * an unrolled binary search. It would be natural to sort the new
536 * enum table and use bsearch(), but we will use a read-only hash
537 * table instead. bsearch() has a nice guaranteed worst case
538 * performance, but we're also guaranteed to hit that worst case
539 * (log2(n) iterations) for about half the enums. Instead, using an
540 * open addressing hash table, we can find the enum on the first try
541 * for 80% of the enums, 1 collision for 10% and never more than 5
542 * collisions for any enum (typical numbers). And the code is very
543 * simple, even though it feels a little magic. */
547 print_table_stats(int api
)
549 int i
, j
, collisions
[11], count
, hash
, mask
;
550 const struct value_desc
*d
;
551 const char *api_names
[] = {
552 [API_OPENGL_COMPAT
] = "GL",
553 [API_OPENGL_CORE
] = "GL_CORE",
554 [API_OPENGLES
] = "GLES",
555 [API_OPENGLES2
] = "GLES2",
557 const char *api_name
;
559 api_name
= api
< ARRAY_SIZE(api_names
) ? api_names
[api
] : "N/A";
561 mask
= ARRAY_SIZE(table(api
)) - 1;
562 memset(collisions
, 0, sizeof collisions
);
564 for (i
= 0; i
< ARRAY_SIZE(table(api
)); i
++) {
568 d
= &values
[table(api
)[i
]];
569 hash
= (d
->pname
* prime_factor
);
572 if (values
[table(api
)[hash
& mask
]].pname
== d
->pname
)
584 printf("number of enums for %s: %d (total %ld)\n",
585 api_name
, count
, ARRAY_SIZE(values
));
586 for (i
= 0; i
< ARRAY_SIZE(collisions
) - 1; i
++)
587 if (collisions
[i
] > 0)
588 printf(" %d enums with %d %scollisions\n",
589 collisions
[i
], i
, i
== 10 ? "or more " : "");
594 * Initialize the enum hash for a given API
596 * This is called from one_time_init() to insert the enum values that
597 * are valid for the API in question into the enum hash table.
599 * \param the current context, for determining the API in question
601 void _mesa_init_get_hash(struct gl_context
*ctx
)
604 print_table_stats(ctx
->API
);
611 * Handle irregular enums
613 * Some values don't conform to the "well-known type at context
614 * pointer + offset" pattern, so we have this function to catch all
615 * the corner cases. Typically, it's a computed value or a one-off
616 * pointer to a custom struct or something.
618 * In this case we can't return a pointer to the value, so we'll have
619 * to use the temporary variable 'v' declared back in the calling
620 * glGet*v() function to store the result.
622 * \param ctx the current context
623 * \param d the struct value_desc that describes the enum
624 * \param v pointer to the tmp declared in the calling glGet*v() function
627 find_custom_value(struct gl_context
*ctx
, const struct value_desc
*d
, union value
*v
)
629 struct gl_buffer_object
**buffer_obj
;
630 struct gl_vertex_attrib_array
*array
;
634 case GL_MAJOR_VERSION
:
635 v
->value_int
= ctx
->Version
/ 10;
637 case GL_MINOR_VERSION
:
638 v
->value_int
= ctx
->Version
% 10;
644 case GL_TEXTURE_CUBE_MAP_ARB
:
645 case GL_TEXTURE_RECTANGLE_NV
:
646 case GL_TEXTURE_EXTERNAL_OES
:
647 v
->value_bool
= _mesa_IsEnabled(d
->pname
);
650 case GL_LINE_STIPPLE_PATTERN
:
651 /* This is the only GLushort, special case it here by promoting
652 * to an int rather than introducing a new type. */
653 v
->value_int
= ctx
->Line
.StipplePattern
;
656 case GL_CURRENT_RASTER_TEXTURE_COORDS
:
657 unit
= ctx
->Texture
.CurrentUnit
;
658 v
->value_float_4
[0] = ctx
->Current
.RasterTexCoords
[unit
][0];
659 v
->value_float_4
[1] = ctx
->Current
.RasterTexCoords
[unit
][1];
660 v
->value_float_4
[2] = ctx
->Current
.RasterTexCoords
[unit
][2];
661 v
->value_float_4
[3] = ctx
->Current
.RasterTexCoords
[unit
][3];
664 case GL_CURRENT_TEXTURE_COORDS
:
665 unit
= ctx
->Texture
.CurrentUnit
;
666 v
->value_float_4
[0] = ctx
->Current
.Attrib
[VERT_ATTRIB_TEX0
+ unit
][0];
667 v
->value_float_4
[1] = ctx
->Current
.Attrib
[VERT_ATTRIB_TEX0
+ unit
][1];
668 v
->value_float_4
[2] = ctx
->Current
.Attrib
[VERT_ATTRIB_TEX0
+ unit
][2];
669 v
->value_float_4
[3] = ctx
->Current
.Attrib
[VERT_ATTRIB_TEX0
+ unit
][3];
672 case GL_COLOR_WRITEMASK
:
673 v
->value_int_4
[0] = ctx
->Color
.ColorMask
[0][RCOMP
] ? 1 : 0;
674 v
->value_int_4
[1] = ctx
->Color
.ColorMask
[0][GCOMP
] ? 1 : 0;
675 v
->value_int_4
[2] = ctx
->Color
.ColorMask
[0][BCOMP
] ? 1 : 0;
676 v
->value_int_4
[3] = ctx
->Color
.ColorMask
[0][ACOMP
] ? 1 : 0;
680 v
->value_bool
= ctx
->Current
.Attrib
[VERT_ATTRIB_EDGEFLAG
][0] == 1.0F
;
684 v
->value_enum
= ctx
->ReadBuffer
->ColorReadBuffer
;
687 case GL_MAP2_GRID_DOMAIN
:
688 v
->value_float_4
[0] = ctx
->Eval
.MapGrid2u1
;
689 v
->value_float_4
[1] = ctx
->Eval
.MapGrid2u2
;
690 v
->value_float_4
[2] = ctx
->Eval
.MapGrid2v1
;
691 v
->value_float_4
[3] = ctx
->Eval
.MapGrid2v2
;
694 case GL_TEXTURE_STACK_DEPTH
:
695 unit
= ctx
->Texture
.CurrentUnit
;
696 v
->value_int
= ctx
->TextureMatrixStack
[unit
].Depth
+ 1;
698 case GL_TEXTURE_MATRIX
:
699 unit
= ctx
->Texture
.CurrentUnit
;
700 v
->value_matrix
= ctx
->TextureMatrixStack
[unit
].Top
;
703 case GL_TEXTURE_COORD_ARRAY
:
704 case GL_TEXTURE_COORD_ARRAY_SIZE
:
705 case GL_TEXTURE_COORD_ARRAY_TYPE
:
706 case GL_TEXTURE_COORD_ARRAY_STRIDE
:
707 array
= &ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_TEX(ctx
->Array
.ActiveTexture
)];
708 v
->value_int
= *(GLuint
*) ((char *) array
+ d
->offset
);
711 case GL_ACTIVE_TEXTURE_ARB
:
712 v
->value_int
= GL_TEXTURE0_ARB
+ ctx
->Texture
.CurrentUnit
;
714 case GL_CLIENT_ACTIVE_TEXTURE_ARB
:
715 v
->value_int
= GL_TEXTURE0_ARB
+ ctx
->Array
.ActiveTexture
;
718 case GL_MODELVIEW_STACK_DEPTH
:
719 case GL_PROJECTION_STACK_DEPTH
:
720 v
->value_int
= *(GLint
*) ((char *) ctx
+ d
->offset
) + 1;
723 case GL_MAX_TEXTURE_SIZE
:
724 case GL_MAX_3D_TEXTURE_SIZE
:
725 case GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB
:
726 p
= (GLuint
*) ((char *) ctx
+ d
->offset
);
727 v
->value_int
= 1 << (*p
- 1);
731 v
->value_int_4
[0] = ctx
->Scissor
.ScissorArray
[0].X
;
732 v
->value_int_4
[1] = ctx
->Scissor
.ScissorArray
[0].Y
;
733 v
->value_int_4
[2] = ctx
->Scissor
.ScissorArray
[0].Width
;
734 v
->value_int_4
[3] = ctx
->Scissor
.ScissorArray
[0].Height
;
737 case GL_SCISSOR_TEST
:
738 v
->value_bool
= ctx
->Scissor
.EnableFlags
& 1;
743 ctx
->ListState
.CurrentList
? ctx
->ListState
.CurrentList
->Name
: 0;
746 if (!ctx
->CompileFlag
)
748 else if (ctx
->ExecuteFlag
)
749 v
->value_enum
= GL_COMPILE_AND_EXECUTE
;
751 v
->value_enum
= GL_COMPILE
;
755 v
->value_float_4
[0] = ctx
->ViewportArray
[0].X
;
756 v
->value_float_4
[1] = ctx
->ViewportArray
[0].Y
;
757 v
->value_float_4
[2] = ctx
->ViewportArray
[0].Width
;
758 v
->value_float_4
[3] = ctx
->ViewportArray
[0].Height
;
762 v
->value_double_2
[0] = ctx
->ViewportArray
[0].Near
;
763 v
->value_double_2
[1] = ctx
->ViewportArray
[0].Far
;
766 case GL_ACTIVE_STENCIL_FACE_EXT
:
767 v
->value_enum
= ctx
->Stencil
.ActiveFace
? GL_BACK
: GL_FRONT
;
770 case GL_STENCIL_FAIL
:
771 v
->value_enum
= ctx
->Stencil
.FailFunc
[ctx
->Stencil
.ActiveFace
];
773 case GL_STENCIL_FUNC
:
774 v
->value_enum
= ctx
->Stencil
.Function
[ctx
->Stencil
.ActiveFace
];
776 case GL_STENCIL_PASS_DEPTH_FAIL
:
777 v
->value_enum
= ctx
->Stencil
.ZFailFunc
[ctx
->Stencil
.ActiveFace
];
779 case GL_STENCIL_PASS_DEPTH_PASS
:
780 v
->value_enum
= ctx
->Stencil
.ZPassFunc
[ctx
->Stencil
.ActiveFace
];
783 v
->value_int
= _mesa_get_stencil_ref(ctx
, ctx
->Stencil
.ActiveFace
);
785 case GL_STENCIL_BACK_REF
:
786 v
->value_int
= _mesa_get_stencil_ref(ctx
, 1);
788 case GL_STENCIL_VALUE_MASK
:
789 v
->value_int
= ctx
->Stencil
.ValueMask
[ctx
->Stencil
.ActiveFace
];
791 case GL_STENCIL_WRITEMASK
:
792 v
->value_int
= ctx
->Stencil
.WriteMask
[ctx
->Stencil
.ActiveFace
];
795 case GL_NUM_EXTENSIONS
:
796 v
->value_int
= _mesa_get_extension_count(ctx
);
799 case GL_IMPLEMENTATION_COLOR_READ_TYPE_OES
:
800 v
->value_int
= _mesa_get_color_read_type(ctx
);
802 case GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES
:
803 v
->value_int
= _mesa_get_color_read_format(ctx
);
806 case GL_CURRENT_MATRIX_STACK_DEPTH_ARB
:
807 v
->value_int
= ctx
->CurrentStack
->Depth
+ 1;
809 case GL_CURRENT_MATRIX_ARB
:
810 case GL_TRANSPOSE_CURRENT_MATRIX_ARB
:
811 v
->value_matrix
= ctx
->CurrentStack
->Top
;
814 case GL_NUM_COMPRESSED_TEXTURE_FORMATS_ARB
:
815 v
->value_int
= _mesa_get_compressed_formats(ctx
, NULL
);
817 case GL_COMPRESSED_TEXTURE_FORMATS_ARB
:
819 _mesa_get_compressed_formats(ctx
, v
->value_int_n
.ints
);
820 assert(v
->value_int_n
.n
<= (int) ARRAY_SIZE(v
->value_int_n
.ints
));
823 case GL_MAX_VARYING_FLOATS_ARB
:
824 v
->value_int
= ctx
->Const
.MaxVarying
* 4;
827 /* Various object names */
829 case GL_TEXTURE_BINDING_1D
:
830 case GL_TEXTURE_BINDING_2D
:
831 case GL_TEXTURE_BINDING_3D
:
832 case GL_TEXTURE_BINDING_1D_ARRAY_EXT
:
833 case GL_TEXTURE_BINDING_2D_ARRAY_EXT
:
834 case GL_TEXTURE_BINDING_CUBE_MAP_ARB
:
835 case GL_TEXTURE_BINDING_RECTANGLE_NV
:
836 case GL_TEXTURE_BINDING_EXTERNAL_OES
:
837 case GL_TEXTURE_BINDING_CUBE_MAP_ARRAY
:
838 case GL_TEXTURE_BINDING_2D_MULTISAMPLE
:
839 case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY
:
840 unit
= ctx
->Texture
.CurrentUnit
;
842 ctx
->Texture
.Unit
[unit
].CurrentTex
[d
->offset
]->Name
;
845 /* GL_EXT_packed_float */
846 case GL_RGBA_SIGNED_COMPONENTS_EXT
:
848 /* Note: we only check the 0th color attachment. */
849 const struct gl_renderbuffer
*rb
=
850 ctx
->DrawBuffer
->_ColorDrawBuffers
[0];
851 if (rb
&& _mesa_is_format_signed(rb
->Format
)) {
852 /* Issue 17 of GL_EXT_packed_float: If a component (such as
853 * alpha) has zero bits, the component should not be considered
854 * signed and so the bit for the respective component should be
858 _mesa_get_format_bits(rb
->Format
, GL_RED_BITS
);
860 _mesa_get_format_bits(rb
->Format
, GL_GREEN_BITS
);
862 _mesa_get_format_bits(rb
->Format
, GL_BLUE_BITS
);
864 _mesa_get_format_bits(rb
->Format
, GL_ALPHA_BITS
);
866 _mesa_get_format_bits(rb
->Format
, GL_TEXTURE_LUMINANCE_SIZE
);
868 _mesa_get_format_bits(rb
->Format
, GL_TEXTURE_INTENSITY_SIZE
);
870 v
->value_int_4
[0] = r_bits
+ l_bits
+ i_bits
> 0;
871 v
->value_int_4
[1] = g_bits
+ l_bits
+ i_bits
> 0;
872 v
->value_int_4
[2] = b_bits
+ l_bits
+ i_bits
> 0;
873 v
->value_int_4
[3] = a_bits
+ i_bits
> 0;
879 v
->value_int_4
[3] = 0;
884 /* GL_ARB_vertex_buffer_object */
885 case GL_VERTEX_ARRAY_BUFFER_BINDING_ARB
:
886 case GL_NORMAL_ARRAY_BUFFER_BINDING_ARB
:
887 case GL_COLOR_ARRAY_BUFFER_BINDING_ARB
:
888 case GL_INDEX_ARRAY_BUFFER_BINDING_ARB
:
889 case GL_EDGE_FLAG_ARRAY_BUFFER_BINDING_ARB
:
890 case GL_SECONDARY_COLOR_ARRAY_BUFFER_BINDING_ARB
:
891 case GL_FOG_COORDINATE_ARRAY_BUFFER_BINDING_ARB
:
892 buffer_obj
= (struct gl_buffer_object
**)
893 ((char *) ctx
->Array
.VAO
+ d
->offset
);
894 v
->value_int
= (*buffer_obj
)->Name
;
896 case GL_ARRAY_BUFFER_BINDING_ARB
:
897 v
->value_int
= ctx
->Array
.ArrayBufferObj
->Name
;
899 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING_ARB
:
901 ctx
->Array
.VAO
->VertexBinding
[VERT_ATTRIB_TEX(ctx
->Array
.ActiveTexture
)].BufferObj
->Name
;
903 case GL_ELEMENT_ARRAY_BUFFER_BINDING_ARB
:
904 v
->value_int
= ctx
->Array
.VAO
->IndexBufferObj
->Name
;
907 /* ARB_vertex_array_bgra */
908 case GL_COLOR_ARRAY_SIZE
:
909 array
= &ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_COLOR0
];
910 v
->value_int
= array
->Format
== GL_BGRA
? GL_BGRA
: array
->Size
;
912 case GL_SECONDARY_COLOR_ARRAY_SIZE
:
913 array
= &ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_COLOR1
];
914 v
->value_int
= array
->Format
== GL_BGRA
? GL_BGRA
: array
->Size
;
917 /* ARB_copy_buffer */
918 case GL_COPY_READ_BUFFER
:
919 v
->value_int
= ctx
->CopyReadBuffer
->Name
;
921 case GL_COPY_WRITE_BUFFER
:
922 v
->value_int
= ctx
->CopyWriteBuffer
->Name
;
925 case GL_PIXEL_PACK_BUFFER_BINDING_EXT
:
926 v
->value_int
= ctx
->Pack
.BufferObj
->Name
;
928 case GL_PIXEL_UNPACK_BUFFER_BINDING_EXT
:
929 v
->value_int
= ctx
->Unpack
.BufferObj
->Name
;
931 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING
:
932 v
->value_int
= ctx
->TransformFeedback
.CurrentBuffer
->Name
;
934 case GL_TRANSFORM_FEEDBACK_BUFFER_PAUSED
:
935 v
->value_int
= ctx
->TransformFeedback
.CurrentObject
->Paused
;
937 case GL_TRANSFORM_FEEDBACK_BUFFER_ACTIVE
:
938 v
->value_int
= ctx
->TransformFeedback
.CurrentObject
->Active
;
940 case GL_TRANSFORM_FEEDBACK_BINDING
:
941 v
->value_int
= ctx
->TransformFeedback
.CurrentObject
->Name
;
943 case GL_CURRENT_PROGRAM
:
944 /* The Changelog of the ARB_separate_shader_objects spec says:
946 * 24 25 Jul 2011 pbrown Remove the language erroneously deleting
947 * CURRENT_PROGRAM. In the EXT extension, this
948 * token was aliased to ACTIVE_PROGRAM_EXT, and
949 * was used to indicate the last program set by
950 * either ActiveProgramEXT or UseProgram. In
951 * the ARB extension, the SSO active programs
952 * are now program pipeline object state and
953 * CURRENT_PROGRAM should still be used to query
954 * the last program set by UseProgram (bug 7822).
957 ctx
->Shader
.ActiveProgram
? ctx
->Shader
.ActiveProgram
->Name
: 0;
959 case GL_READ_FRAMEBUFFER_BINDING_EXT
:
960 v
->value_int
= ctx
->ReadBuffer
->Name
;
962 case GL_RENDERBUFFER_BINDING_EXT
:
964 ctx
->CurrentRenderbuffer
? ctx
->CurrentRenderbuffer
->Name
: 0;
966 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES
:
967 v
->value_int
= ctx
->Array
.VAO
->VertexBinding
[VERT_ATTRIB_POINT_SIZE
].BufferObj
->Name
;
971 if (_mesa_get_clamp_fragment_color(ctx
, ctx
->DrawBuffer
))
972 COPY_4FV(v
->value_float_4
, ctx
->Fog
.Color
);
974 COPY_4FV(v
->value_float_4
, ctx
->Fog
.ColorUnclamped
);
976 case GL_COLOR_CLEAR_VALUE
:
977 if (_mesa_get_clamp_fragment_color(ctx
, ctx
->DrawBuffer
)) {
978 v
->value_float_4
[0] = CLAMP(ctx
->Color
.ClearColor
.f
[0], 0.0F
, 1.0F
);
979 v
->value_float_4
[1] = CLAMP(ctx
->Color
.ClearColor
.f
[1], 0.0F
, 1.0F
);
980 v
->value_float_4
[2] = CLAMP(ctx
->Color
.ClearColor
.f
[2], 0.0F
, 1.0F
);
981 v
->value_float_4
[3] = CLAMP(ctx
->Color
.ClearColor
.f
[3], 0.0F
, 1.0F
);
983 COPY_4FV(v
->value_float_4
, ctx
->Color
.ClearColor
.f
);
985 case GL_BLEND_COLOR_EXT
:
986 if (_mesa_get_clamp_fragment_color(ctx
, ctx
->DrawBuffer
))
987 COPY_4FV(v
->value_float_4
, ctx
->Color
.BlendColor
);
989 COPY_4FV(v
->value_float_4
, ctx
->Color
.BlendColorUnclamped
);
991 case GL_ALPHA_TEST_REF
:
992 if (_mesa_get_clamp_fragment_color(ctx
, ctx
->DrawBuffer
))
993 v
->value_float
= ctx
->Color
.AlphaRef
;
995 v
->value_float
= ctx
->Color
.AlphaRefUnclamped
;
997 case GL_MAX_VERTEX_UNIFORM_VECTORS
:
998 v
->value_int
= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxUniformComponents
/ 4;
1001 case GL_MAX_FRAGMENT_UNIFORM_VECTORS
:
1002 v
->value_int
= ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxUniformComponents
/ 4;
1005 /* GL_ARB_texture_buffer_object */
1006 case GL_TEXTURE_BUFFER_ARB
:
1007 v
->value_int
= ctx
->Texture
.BufferObject
->Name
;
1009 case GL_TEXTURE_BINDING_BUFFER_ARB
:
1010 unit
= ctx
->Texture
.CurrentUnit
;
1012 ctx
->Texture
.Unit
[unit
].CurrentTex
[TEXTURE_BUFFER_INDEX
]->Name
;
1014 case GL_TEXTURE_BUFFER_DATA_STORE_BINDING_ARB
:
1016 struct gl_buffer_object
*buf
=
1017 ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
]
1018 .CurrentTex
[TEXTURE_BUFFER_INDEX
]->BufferObject
;
1019 v
->value_int
= buf
? buf
->Name
: 0;
1022 case GL_TEXTURE_BUFFER_FORMAT_ARB
:
1023 v
->value_int
= ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
]
1024 .CurrentTex
[TEXTURE_BUFFER_INDEX
]->BufferObjectFormat
;
1027 /* GL_ARB_sampler_objects */
1028 case GL_SAMPLER_BINDING
:
1030 struct gl_sampler_object
*samp
=
1031 ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
].Sampler
;
1032 v
->value_int
= samp
? samp
->Name
: 0;
1035 /* GL_ARB_uniform_buffer_object */
1036 case GL_UNIFORM_BUFFER_BINDING
:
1037 v
->value_int
= ctx
->UniformBuffer
->Name
;
1039 /* GL_ARB_shader_storage_buffer_object */
1040 case GL_SHADER_STORAGE_BUFFER_BINDING
:
1041 v
->value_int
= ctx
->ShaderStorageBuffer
->Name
;
1043 /* GL_ARB_query_buffer_object */
1044 case GL_QUERY_BUFFER_BINDING
:
1045 v
->value_int
= ctx
->QueryBuffer
->Name
;
1047 /* GL_ARB_timer_query */
1049 if (ctx
->Driver
.GetTimestamp
) {
1050 v
->value_int64
= ctx
->Driver
.GetTimestamp(ctx
);
1053 _mesa_problem(ctx
, "driver doesn't implement GetTimestamp");
1057 case GL_DEBUG_LOGGED_MESSAGES
:
1058 case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH
:
1059 case GL_DEBUG_GROUP_STACK_DEPTH
:
1060 v
->value_int
= _mesa_get_debug_state_int(ctx
, d
->pname
);
1062 /* GL_ARB_shader_atomic_counters */
1063 case GL_ATOMIC_COUNTER_BUFFER_BINDING
:
1064 if (ctx
->AtomicBuffer
) {
1065 v
->value_int
= ctx
->AtomicBuffer
->Name
;
1070 /* GL_ARB_draw_indirect */
1071 case GL_DRAW_INDIRECT_BUFFER_BINDING
:
1072 v
->value_int
= ctx
->DrawIndirectBuffer
->Name
;
1074 /* GL_ARB_indirect_parameters */
1075 case GL_PARAMETER_BUFFER_BINDING_ARB
:
1076 v
->value_int
= ctx
->ParameterBuffer
->Name
;
1078 /* GL_ARB_separate_shader_objects */
1079 case GL_PROGRAM_PIPELINE_BINDING
:
1080 if (ctx
->Pipeline
.Current
) {
1081 v
->value_int
= ctx
->Pipeline
.Current
->Name
;
1086 /* GL_ARB_compute_shader */
1087 case GL_DISPATCH_INDIRECT_BUFFER_BINDING
:
1088 v
->value_int
= ctx
->DispatchIndirectBuffer
->Name
;
1090 /* GL_ARB_multisample */
1092 v
->value_int
= _mesa_geometric_samples(ctx
->DrawBuffer
);
1094 case GL_SAMPLE_BUFFERS
:
1095 v
->value_int
= _mesa_geometric_samples(ctx
->DrawBuffer
) > 0;
1097 /* GL_ATI_meminfo & GL_NVX_gpu_memory_info */
1098 case GL_VBO_FREE_MEMORY_ATI
:
1099 case GL_TEXTURE_FREE_MEMORY_ATI
:
1100 case GL_RENDERBUFFER_FREE_MEMORY_ATI
:
1101 case GL_GPU_MEMORY_INFO_DEDICATED_VIDMEM_NVX
:
1102 case GL_GPU_MEMORY_INFO_TOTAL_AVAILABLE_MEMORY_NVX
:
1103 case GL_GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX
:
1104 case GL_GPU_MEMORY_INFO_EVICTION_COUNT_NVX
:
1105 case GL_GPU_MEMORY_INFO_EVICTED_MEMORY_NVX
:
1107 struct gl_memory_info info
;
1109 ctx
->Driver
.QueryMemoryInfo(ctx
, &info
);
1111 if (d
->pname
== GL_GPU_MEMORY_INFO_DEDICATED_VIDMEM_NVX
)
1112 v
->value_int
= info
.total_device_memory
;
1113 else if (d
->pname
== GL_GPU_MEMORY_INFO_TOTAL_AVAILABLE_MEMORY_NVX
)
1114 v
->value_int
= info
.total_device_memory
+
1115 info
.total_staging_memory
;
1116 else if (d
->pname
== GL_GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX
)
1117 v
->value_int
= info
.avail_device_memory
;
1118 else if (d
->pname
== GL_GPU_MEMORY_INFO_EVICTION_COUNT_NVX
)
1119 v
->value_int
= info
.nr_device_memory_evictions
;
1120 else if (d
->pname
== GL_GPU_MEMORY_INFO_EVICTED_MEMORY_NVX
)
1121 v
->value_int
= info
.device_memory_evicted
;
1123 /* ATI free memory enums.
1125 * Since the GPU memory is (usually) page-table based, every two
1126 * consecutive elements are equal. From the GL_ATI_meminfo
1129 * "param[0] - total memory free in the pool
1130 * param[1] - largest available free block in the pool
1131 * param[2] - total auxiliary memory free
1132 * param[3] - largest auxiliary free block"
1134 * All three (VBO, TEXTURE, RENDERBUFFER) queries return
1135 * the same numbers here.
1137 v
->value_int_4
[0] = info
.avail_device_memory
;
1138 v
->value_int_4
[1] = info
.avail_device_memory
;
1139 v
->value_int_4
[2] = info
.avail_staging_memory
;
1140 v
->value_int_4
[3] = info
.avail_staging_memory
;
1148 * Check extra constraints on a struct value_desc descriptor
1150 * If a struct value_desc has a non-NULL extra pointer, it means that
1151 * there are a number of extra constraints to check or actions to
1152 * perform. The extras is just an integer array where each integer
1153 * encode different constraints or actions.
1155 * \param ctx current context
1156 * \param func name of calling glGet*v() function for error reporting
1157 * \param d the struct value_desc that has the extra constraints
1159 * \return GL_FALSE if all of the constraints were not satisfied,
1160 * otherwise GL_TRUE.
1163 check_extra(struct gl_context
*ctx
, const char *func
, const struct value_desc
*d
)
1165 const GLuint version
= ctx
->Version
;
1166 GLboolean api_check
= GL_FALSE
;
1167 GLboolean api_found
= GL_FALSE
;
1170 for (e
= d
->extra
; *e
!= EXTRA_END
; e
++) {
1172 case EXTRA_VERSION_30
:
1173 api_check
= GL_TRUE
;
1175 api_found
= GL_TRUE
;
1177 case EXTRA_VERSION_31
:
1178 api_check
= GL_TRUE
;
1180 api_found
= GL_TRUE
;
1182 case EXTRA_VERSION_32
:
1183 api_check
= GL_TRUE
;
1185 api_found
= GL_TRUE
;
1187 case EXTRA_NEW_FRAG_CLAMP
:
1188 if (ctx
->NewState
& (_NEW_BUFFERS
| _NEW_FRAG_CLAMP
))
1189 _mesa_update_state(ctx
);
1192 api_check
= GL_TRUE
;
1193 if (ctx
->API
== API_OPENGLES2
)
1194 api_found
= GL_TRUE
;
1197 api_check
= GL_TRUE
;
1198 if (_mesa_is_gles3(ctx
))
1199 api_found
= GL_TRUE
;
1201 case EXTRA_API_ES31
:
1202 api_check
= GL_TRUE
;
1203 if (_mesa_is_gles31(ctx
))
1204 api_found
= GL_TRUE
;
1207 api_check
= GL_TRUE
;
1208 if (_mesa_is_desktop_gl(ctx
))
1209 api_found
= GL_TRUE
;
1211 case EXTRA_API_GL_CORE
:
1212 api_check
= GL_TRUE
;
1213 if (ctx
->API
== API_OPENGL_CORE
)
1214 api_found
= GL_TRUE
;
1216 case EXTRA_NEW_BUFFERS
:
1217 if (ctx
->NewState
& _NEW_BUFFERS
)
1218 _mesa_update_state(ctx
);
1220 case EXTRA_FLUSH_CURRENT
:
1221 FLUSH_CURRENT(ctx
, 0);
1223 case EXTRA_VALID_DRAW_BUFFER
:
1224 if (d
->pname
- GL_DRAW_BUFFER0_ARB
>= ctx
->Const
.MaxDrawBuffers
) {
1225 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(draw buffer %u)",
1226 func
, d
->pname
- GL_DRAW_BUFFER0_ARB
);
1230 case EXTRA_VALID_TEXTURE_UNIT
:
1231 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureCoordUnits
) {
1232 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(texture %u)",
1233 func
, ctx
->Texture
.CurrentUnit
);
1237 case EXTRA_VALID_CLIP_DISTANCE
:
1238 if (d
->pname
- GL_CLIP_DISTANCE0
>= ctx
->Const
.MaxClipPlanes
) {
1239 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(clip distance %u)",
1240 func
, d
->pname
- GL_CLIP_DISTANCE0
);
1244 case EXTRA_GLSL_130
:
1245 api_check
= GL_TRUE
;
1246 if (ctx
->Const
.GLSLVersion
>= 130)
1247 api_found
= GL_TRUE
;
1249 case EXTRA_EXT_UBO_GS
:
1250 api_check
= GL_TRUE
;
1251 if (ctx
->Extensions
.ARB_uniform_buffer_object
&&
1252 _mesa_has_geometry_shaders(ctx
))
1253 api_found
= GL_TRUE
;
1255 case EXTRA_EXT_ATOMICS_GS
:
1256 api_check
= GL_TRUE
;
1257 if (ctx
->Extensions
.ARB_shader_atomic_counters
&&
1258 _mesa_has_geometry_shaders(ctx
))
1259 api_found
= GL_TRUE
;
1261 case EXTRA_EXT_SHADER_IMAGE_GS
:
1262 api_check
= GL_TRUE
;
1263 if (ctx
->Extensions
.ARB_shader_image_load_store
&&
1264 _mesa_has_geometry_shaders(ctx
))
1265 api_found
= GL_TRUE
;
1267 case EXTRA_EXT_ATOMICS_TESS
:
1268 api_check
= GL_TRUE
;
1269 api_found
= ctx
->Extensions
.ARB_shader_atomic_counters
&&
1270 _mesa_has_tessellation(ctx
);
1272 case EXTRA_EXT_SHADER_IMAGE_TESS
:
1273 api_check
= GL_TRUE
;
1274 api_found
= ctx
->Extensions
.ARB_shader_image_load_store
&&
1275 _mesa_has_tessellation(ctx
);
1277 case EXTRA_EXT_SSBO_GS
:
1278 api_check
= GL_TRUE
;
1279 if (ctx
->Extensions
.ARB_shader_storage_buffer_object
&&
1280 _mesa_has_geometry_shaders(ctx
))
1281 api_found
= GL_TRUE
;
1283 case EXTRA_EXT_FB_NO_ATTACH_GS
:
1284 api_check
= GL_TRUE
;
1285 if (ctx
->Extensions
.ARB_framebuffer_no_attachments
&&
1286 (_mesa_is_desktop_gl(ctx
) ||
1287 _mesa_has_OES_geometry_shader(ctx
)))
1288 api_found
= GL_TRUE
;
1290 case EXTRA_EXT_ES_GS
:
1291 api_check
= GL_TRUE
;
1292 if (_mesa_has_OES_geometry_shader(ctx
))
1293 api_found
= GL_TRUE
;
1297 default: /* *e is a offset into the extension struct */
1298 api_check
= GL_TRUE
;
1299 if (*(GLboolean
*) ((char *) &ctx
->Extensions
+ *e
))
1300 api_found
= GL_TRUE
;
1305 if (api_check
&& !api_found
) {
1306 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=%s)", func
,
1307 _mesa_enum_to_string(d
->pname
));
1314 static const struct value_desc error_value
=
1315 { 0, 0, TYPE_INVALID
, NO_OFFSET
, NO_EXTRA
};
1318 * Find the struct value_desc corresponding to the enum 'pname'.
1320 * We hash the enum value to get an index into the 'table' array,
1321 * which holds the index in the 'values' array of struct value_desc.
1322 * Once we've found the entry, we do the extra checks, if any, then
1323 * look up the value and return a pointer to it.
1325 * If the value has to be computed (for example, it's the result of a
1326 * function call or we need to add 1 to it), we use the tmp 'v' to
1329 * \param func name of glGet*v() func for error reporting
1330 * \param pname the enum value we're looking up
1331 * \param p is were we return the pointer to the value
1332 * \param v a tmp union value variable in the calling glGet*v() function
1334 * \return the struct value_desc corresponding to the enum or a struct
1335 * value_desc of TYPE_INVALID if not found. This lets the calling
1336 * glGet*v() function jump right into a switch statement and
1337 * handle errors there instead of having to check for NULL.
1339 static const struct value_desc
*
1340 find_value(const char *func
, GLenum pname
, void **p
, union value
*v
)
1342 GET_CURRENT_CONTEXT(ctx
);
1343 struct gl_texture_unit
*unit
;
1345 const struct value_desc
*d
;
1349 /* We index into the table_set[] list of per-API hash tables using the API's
1350 * value in the gl_api enum. Since GLES 3 doesn't have an API_OPENGL* enum
1351 * value since it's compatible with GLES2 its entry in table_set[] is at the
1354 STATIC_ASSERT(ARRAY_SIZE(table_set
) == API_OPENGL_LAST
+ 3);
1355 if (_mesa_is_gles3(ctx
)) {
1356 api
= API_OPENGL_LAST
+ 1;
1358 if (_mesa_is_gles31(ctx
)) {
1359 api
= API_OPENGL_LAST
+ 2;
1361 mask
= ARRAY_SIZE(table(api
)) - 1;
1362 hash
= (pname
* prime_factor
);
1364 int idx
= table(api
)[hash
& mask
];
1366 /* If the enum isn't valid, the hash walk ends with index 0,
1367 * pointing to the first entry of values[] which doesn't hold
1368 * any valid enum. */
1369 if (unlikely(idx
== 0)) {
1370 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=%s)", func
,
1371 _mesa_enum_to_string(pname
));
1372 return &error_value
;
1376 if (likely(d
->pname
== pname
))
1382 if (unlikely(d
->extra
&& !check_extra(ctx
, func
, d
)))
1383 return &error_value
;
1385 switch (d
->location
) {
1387 *p
= ((char *) ctx
->DrawBuffer
+ d
->offset
);
1390 *p
= ((char *) ctx
+ d
->offset
);
1393 *p
= ((char *) ctx
->Array
.VAO
+ d
->offset
);
1396 unit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1397 *p
= ((char *) unit
+ d
->offset
);
1400 find_custom_value(ctx
, d
, v
);
1408 /* silence warning */
1409 return &error_value
;
1412 static const int transpose
[] = {
1420 _mesa_GetBooleanv(GLenum pname
, GLboolean
*params
)
1422 const struct value_desc
*d
;
1428 d
= find_value("glGetBooleanv", pname
, &p
, &v
);
1433 params
[0] = INT_TO_BOOLEAN(d
->offset
);
1438 params
[3] = FLOAT_TO_BOOLEAN(((GLfloat
*) p
)[3]);
1441 params
[2] = FLOAT_TO_BOOLEAN(((GLfloat
*) p
)[2]);
1444 params
[1] = FLOAT_TO_BOOLEAN(((GLfloat
*) p
)[1]);
1447 params
[0] = FLOAT_TO_BOOLEAN(((GLfloat
*) p
)[0]);
1450 case TYPE_DOUBLEN_2
:
1451 params
[1] = FLOAT_TO_BOOLEAN(((GLdouble
*) p
)[1]);
1453 params
[0] = FLOAT_TO_BOOLEAN(((GLdouble
*) p
)[0]);
1457 params
[3] = INT_TO_BOOLEAN(((GLint
*) p
)[3]);
1459 params
[2] = INT_TO_BOOLEAN(((GLint
*) p
)[2]);
1462 params
[1] = INT_TO_BOOLEAN(((GLint
*) p
)[1]);
1465 params
[0] = INT_TO_BOOLEAN(((GLint
*) p
)[0]);
1469 for (i
= 0; i
< v
.value_int_n
.n
; i
++)
1470 params
[i
] = INT_TO_BOOLEAN(v
.value_int_n
.ints
[i
]);
1474 params
[0] = INT64_TO_BOOLEAN(((GLint64
*) p
)[0]);
1478 params
[0] = ((GLboolean
*) p
)[0];
1482 m
= *(GLmatrix
**) p
;
1483 for (i
= 0; i
< 16; i
++)
1484 params
[i
] = FLOAT_TO_BOOLEAN(m
->m
[i
]);
1488 m
= *(GLmatrix
**) p
;
1489 for (i
= 0; i
< 16; i
++)
1490 params
[i
] = FLOAT_TO_BOOLEAN(m
->m
[transpose
[i
]]);
1501 shift
= d
->type
- TYPE_BIT_0
;
1502 params
[0] = (*(GLbitfield
*) p
>> shift
) & 1;
1508 _mesa_GetFloatv(GLenum pname
, GLfloat
*params
)
1510 const struct value_desc
*d
;
1516 d
= find_value("glGetFloatv", pname
, &p
, &v
);
1521 params
[0] = (GLfloat
) d
->offset
;
1526 params
[3] = ((GLfloat
*) p
)[3];
1529 params
[2] = ((GLfloat
*) p
)[2];
1532 params
[1] = ((GLfloat
*) p
)[1];
1535 params
[0] = ((GLfloat
*) p
)[0];
1538 case TYPE_DOUBLEN_2
:
1539 params
[1] = (GLfloat
) (((GLdouble
*) p
)[1]);
1541 params
[0] = (GLfloat
) (((GLdouble
*) p
)[0]);
1545 params
[3] = (GLfloat
) (((GLint
*) p
)[3]);
1547 params
[2] = (GLfloat
) (((GLint
*) p
)[2]);
1550 params
[1] = (GLfloat
) (((GLint
*) p
)[1]);
1553 params
[0] = (GLfloat
) (((GLint
*) p
)[0]);
1557 for (i
= 0; i
< v
.value_int_n
.n
; i
++)
1558 params
[i
] = INT_TO_FLOAT(v
.value_int_n
.ints
[i
]);
1562 params
[0] = (GLfloat
) (((GLint64
*) p
)[0]);
1566 params
[0] = BOOLEAN_TO_FLOAT(*(GLboolean
*) p
);
1570 m
= *(GLmatrix
**) p
;
1571 for (i
= 0; i
< 16; i
++)
1572 params
[i
] = m
->m
[i
];
1576 m
= *(GLmatrix
**) p
;
1577 for (i
= 0; i
< 16; i
++)
1578 params
[i
] = m
->m
[transpose
[i
]];
1589 shift
= d
->type
- TYPE_BIT_0
;
1590 params
[0] = BOOLEAN_TO_FLOAT((*(GLbitfield
*) p
>> shift
) & 1);
1596 _mesa_GetIntegerv(GLenum pname
, GLint
*params
)
1598 const struct value_desc
*d
;
1604 d
= find_value("glGetIntegerv", pname
, &p
, &v
);
1609 params
[0] = d
->offset
;
1613 params
[3] = IROUND(((GLfloat
*) p
)[3]);
1615 params
[2] = IROUND(((GLfloat
*) p
)[2]);
1617 params
[1] = IROUND(((GLfloat
*) p
)[1]);
1619 params
[0] = IROUND(((GLfloat
*) p
)[0]);
1623 params
[3] = FLOAT_TO_INT(((GLfloat
*) p
)[3]);
1625 params
[2] = FLOAT_TO_INT(((GLfloat
*) p
)[2]);
1627 params
[1] = FLOAT_TO_INT(((GLfloat
*) p
)[1]);
1629 params
[0] = FLOAT_TO_INT(((GLfloat
*) p
)[0]);
1632 case TYPE_DOUBLEN_2
:
1633 params
[1] = FLOAT_TO_INT(((GLdouble
*) p
)[1]);
1635 params
[0] = FLOAT_TO_INT(((GLdouble
*) p
)[0]);
1639 params
[3] = ((GLint
*) p
)[3];
1641 params
[2] = ((GLint
*) p
)[2];
1644 params
[1] = ((GLint
*) p
)[1];
1647 params
[0] = ((GLint
*) p
)[0];
1651 for (i
= 0; i
< v
.value_int_n
.n
; i
++)
1652 params
[i
] = v
.value_int_n
.ints
[i
];
1656 params
[0] = INT64_TO_INT(((GLint64
*) p
)[0]);
1660 params
[0] = BOOLEAN_TO_INT(*(GLboolean
*) p
);
1664 m
= *(GLmatrix
**) p
;
1665 for (i
= 0; i
< 16; i
++)
1666 params
[i
] = FLOAT_TO_INT(m
->m
[i
]);
1670 m
= *(GLmatrix
**) p
;
1671 for (i
= 0; i
< 16; i
++)
1672 params
[i
] = FLOAT_TO_INT(m
->m
[transpose
[i
]]);
1683 shift
= d
->type
- TYPE_BIT_0
;
1684 params
[0] = (*(GLbitfield
*) p
>> shift
) & 1;
1690 _mesa_GetInteger64v(GLenum pname
, GLint64
*params
)
1692 const struct value_desc
*d
;
1698 d
= find_value("glGetInteger64v", pname
, &p
, &v
);
1703 params
[0] = d
->offset
;
1707 params
[3] = IROUND64(((GLfloat
*) p
)[3]);
1709 params
[2] = IROUND64(((GLfloat
*) p
)[2]);
1711 params
[1] = IROUND64(((GLfloat
*) p
)[1]);
1713 params
[0] = IROUND64(((GLfloat
*) p
)[0]);
1717 params
[3] = FLOAT_TO_INT64(((GLfloat
*) p
)[3]);
1719 params
[2] = FLOAT_TO_INT64(((GLfloat
*) p
)[2]);
1721 params
[1] = FLOAT_TO_INT64(((GLfloat
*) p
)[1]);
1723 params
[0] = FLOAT_TO_INT64(((GLfloat
*) p
)[0]);
1726 case TYPE_DOUBLEN_2
:
1727 params
[1] = FLOAT_TO_INT64(((GLdouble
*) p
)[1]);
1729 params
[0] = FLOAT_TO_INT64(((GLdouble
*) p
)[0]);
1733 params
[3] = ((GLint
*) p
)[3];
1735 params
[2] = ((GLint
*) p
)[2];
1738 params
[1] = ((GLint
*) p
)[1];
1741 params
[0] = ((GLint
*) p
)[0];
1745 for (i
= 0; i
< v
.value_int_n
.n
; i
++)
1746 params
[i
] = INT_TO_BOOLEAN(v
.value_int_n
.ints
[i
]);
1750 params
[0] = ((GLint64
*) p
)[0];
1754 params
[0] = ((GLboolean
*) p
)[0];
1758 m
= *(GLmatrix
**) p
;
1759 for (i
= 0; i
< 16; i
++)
1760 params
[i
] = FLOAT_TO_INT64(m
->m
[i
]);
1764 m
= *(GLmatrix
**) p
;
1765 for (i
= 0; i
< 16; i
++)
1766 params
[i
] = FLOAT_TO_INT64(m
->m
[transpose
[i
]]);
1777 shift
= d
->type
- TYPE_BIT_0
;
1778 params
[0] = (*(GLbitfield
*) p
>> shift
) & 1;
1784 _mesa_GetDoublev(GLenum pname
, GLdouble
*params
)
1786 const struct value_desc
*d
;
1792 d
= find_value("glGetDoublev", pname
, &p
, &v
);
1797 params
[0] = d
->offset
;
1802 params
[3] = ((GLfloat
*) p
)[3];
1805 params
[2] = ((GLfloat
*) p
)[2];
1808 params
[1] = ((GLfloat
*) p
)[1];
1811 params
[0] = ((GLfloat
*) p
)[0];
1814 case TYPE_DOUBLEN_2
:
1815 params
[1] = ((GLdouble
*) p
)[1];
1817 params
[0] = ((GLdouble
*) p
)[0];
1821 params
[3] = ((GLint
*) p
)[3];
1823 params
[2] = ((GLint
*) p
)[2];
1826 params
[1] = ((GLint
*) p
)[1];
1829 params
[0] = ((GLint
*) p
)[0];
1833 for (i
= 0; i
< v
.value_int_n
.n
; i
++)
1834 params
[i
] = v
.value_int_n
.ints
[i
];
1838 params
[0] = (GLdouble
) (((GLint64
*) p
)[0]);
1842 params
[0] = *(GLboolean
*) p
;
1846 m
= *(GLmatrix
**) p
;
1847 for (i
= 0; i
< 16; i
++)
1848 params
[i
] = m
->m
[i
];
1852 m
= *(GLmatrix
**) p
;
1853 for (i
= 0; i
< 16; i
++)
1854 params
[i
] = m
->m
[transpose
[i
]];
1865 shift
= d
->type
- TYPE_BIT_0
;
1866 params
[0] = (*(GLbitfield
*) p
>> shift
) & 1;
1872 * Convert a GL texture binding enum such as GL_TEXTURE_BINDING_2D
1873 * into the corresponding Mesa texture target index.
1874 * \return TEXTURE_x_INDEX or -1 if binding is invalid
1877 tex_binding_to_index(const struct gl_context
*ctx
, GLenum binding
)
1880 case GL_TEXTURE_BINDING_1D
:
1881 return _mesa_is_desktop_gl(ctx
) ? TEXTURE_1D_INDEX
: -1;
1882 case GL_TEXTURE_BINDING_2D
:
1883 return TEXTURE_2D_INDEX
;
1884 case GL_TEXTURE_BINDING_3D
:
1885 return ctx
->API
!= API_OPENGLES
? TEXTURE_3D_INDEX
: -1;
1886 case GL_TEXTURE_BINDING_CUBE_MAP
:
1887 return ctx
->Extensions
.ARB_texture_cube_map
1888 ? TEXTURE_CUBE_INDEX
: -1;
1889 case GL_TEXTURE_BINDING_RECTANGLE
:
1890 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.NV_texture_rectangle
1891 ? TEXTURE_RECT_INDEX
: -1;
1892 case GL_TEXTURE_BINDING_1D_ARRAY
:
1893 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
1894 ? TEXTURE_1D_ARRAY_INDEX
: -1;
1895 case GL_TEXTURE_BINDING_2D_ARRAY
:
1896 return (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
)
1897 || _mesa_is_gles3(ctx
)
1898 ? TEXTURE_2D_ARRAY_INDEX
: -1;
1899 case GL_TEXTURE_BINDING_BUFFER
:
1900 return ctx
->API
== API_OPENGL_CORE
&&
1901 ctx
->Extensions
.ARB_texture_buffer_object
?
1902 TEXTURE_BUFFER_INDEX
: -1;
1903 case GL_TEXTURE_BINDING_CUBE_MAP_ARRAY
:
1904 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_cube_map_array
1905 ? TEXTURE_CUBE_ARRAY_INDEX
: -1;
1906 case GL_TEXTURE_BINDING_2D_MULTISAMPLE
:
1907 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_multisample
1908 ? TEXTURE_2D_MULTISAMPLE_INDEX
: -1;
1909 case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY
:
1910 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_multisample
1911 ? TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX
: -1;
1917 static enum value_type
1918 find_value_indexed(const char *func
, GLenum pname
, GLuint index
, union value
*v
)
1920 GET_CURRENT_CONTEXT(ctx
);
1925 if (index
>= ctx
->Const
.MaxDrawBuffers
)
1927 if (!ctx
->Extensions
.EXT_draw_buffers2
)
1929 v
->value_int
= (ctx
->Color
.BlendEnabled
>> index
) & 1;
1934 case GL_BLEND_SRC_RGB
:
1935 if (index
>= ctx
->Const
.MaxDrawBuffers
)
1937 if (!ctx
->Extensions
.ARB_draw_buffers_blend
)
1939 v
->value_int
= ctx
->Color
.Blend
[index
].SrcRGB
;
1941 case GL_BLEND_SRC_ALPHA
:
1942 if (index
>= ctx
->Const
.MaxDrawBuffers
)
1944 if (!ctx
->Extensions
.ARB_draw_buffers_blend
)
1946 v
->value_int
= ctx
->Color
.Blend
[index
].SrcA
;
1950 case GL_BLEND_DST_RGB
:
1951 if (index
>= ctx
->Const
.MaxDrawBuffers
)
1953 if (!ctx
->Extensions
.ARB_draw_buffers_blend
)
1955 v
->value_int
= ctx
->Color
.Blend
[index
].DstRGB
;
1957 case GL_BLEND_DST_ALPHA
:
1958 if (index
>= ctx
->Const
.MaxDrawBuffers
)
1960 if (!ctx
->Extensions
.ARB_draw_buffers_blend
)
1962 v
->value_int
= ctx
->Color
.Blend
[index
].DstA
;
1964 case GL_BLEND_EQUATION_RGB
:
1965 if (index
>= ctx
->Const
.MaxDrawBuffers
)
1967 if (!ctx
->Extensions
.ARB_draw_buffers_blend
)
1969 v
->value_int
= ctx
->Color
.Blend
[index
].EquationRGB
;
1971 case GL_BLEND_EQUATION_ALPHA
:
1972 if (index
>= ctx
->Const
.MaxDrawBuffers
)
1974 if (!ctx
->Extensions
.ARB_draw_buffers_blend
)
1976 v
->value_int
= ctx
->Color
.Blend
[index
].EquationA
;
1979 case GL_COLOR_WRITEMASK
:
1980 if (index
>= ctx
->Const
.MaxDrawBuffers
)
1982 if (!ctx
->Extensions
.EXT_draw_buffers2
)
1984 v
->value_int_4
[0] = ctx
->Color
.ColorMask
[index
][RCOMP
] ? 1 : 0;
1985 v
->value_int_4
[1] = ctx
->Color
.ColorMask
[index
][GCOMP
] ? 1 : 0;
1986 v
->value_int_4
[2] = ctx
->Color
.ColorMask
[index
][BCOMP
] ? 1 : 0;
1987 v
->value_int_4
[3] = ctx
->Color
.ColorMask
[index
][ACOMP
] ? 1 : 0;
1990 case GL_SCISSOR_BOX
:
1991 if (index
>= ctx
->Const
.MaxViewports
)
1993 v
->value_int_4
[0] = ctx
->Scissor
.ScissorArray
[index
].X
;
1994 v
->value_int_4
[1] = ctx
->Scissor
.ScissorArray
[index
].Y
;
1995 v
->value_int_4
[2] = ctx
->Scissor
.ScissorArray
[index
].Width
;
1996 v
->value_int_4
[3] = ctx
->Scissor
.ScissorArray
[index
].Height
;
2000 if (index
>= ctx
->Const
.MaxViewports
)
2002 v
->value_float_4
[0] = ctx
->ViewportArray
[index
].X
;
2003 v
->value_float_4
[1] = ctx
->ViewportArray
[index
].Y
;
2004 v
->value_float_4
[2] = ctx
->ViewportArray
[index
].Width
;
2005 v
->value_float_4
[3] = ctx
->ViewportArray
[index
].Height
;
2006 return TYPE_FLOAT_4
;
2008 case GL_DEPTH_RANGE
:
2009 if (index
>= ctx
->Const
.MaxViewports
)
2011 v
->value_double_2
[0] = ctx
->ViewportArray
[index
].Near
;
2012 v
->value_double_2
[1] = ctx
->ViewportArray
[index
].Far
;
2013 return TYPE_DOUBLEN_2
;
2015 case GL_TRANSFORM_FEEDBACK_BUFFER_START
:
2016 if (index
>= ctx
->Const
.MaxTransformFeedbackBuffers
)
2018 if (!ctx
->Extensions
.EXT_transform_feedback
)
2020 v
->value_int64
= ctx
->TransformFeedback
.CurrentObject
->Offset
[index
];
2023 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE
:
2024 if (index
>= ctx
->Const
.MaxTransformFeedbackBuffers
)
2026 if (!ctx
->Extensions
.EXT_transform_feedback
)
2029 = ctx
->TransformFeedback
.CurrentObject
->RequestedSize
[index
];
2032 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING
:
2033 if (index
>= ctx
->Const
.MaxTransformFeedbackBuffers
)
2035 if (!ctx
->Extensions
.EXT_transform_feedback
)
2037 v
->value_int
= ctx
->TransformFeedback
.CurrentObject
->BufferNames
[index
];
2040 case GL_UNIFORM_BUFFER_BINDING
:
2041 if (index
>= ctx
->Const
.MaxUniformBufferBindings
)
2043 if (!ctx
->Extensions
.ARB_uniform_buffer_object
)
2045 v
->value_int
= ctx
->UniformBufferBindings
[index
].BufferObject
->Name
;
2048 case GL_UNIFORM_BUFFER_START
:
2049 if (index
>= ctx
->Const
.MaxUniformBufferBindings
)
2051 if (!ctx
->Extensions
.ARB_uniform_buffer_object
)
2053 v
->value_int
= ctx
->UniformBufferBindings
[index
].Offset
< 0 ? 0 :
2054 ctx
->UniformBufferBindings
[index
].Offset
;
2057 case GL_UNIFORM_BUFFER_SIZE
:
2058 if (index
>= ctx
->Const
.MaxUniformBufferBindings
)
2060 if (!ctx
->Extensions
.ARB_uniform_buffer_object
)
2062 v
->value_int
= ctx
->UniformBufferBindings
[index
].Size
< 0 ? 0 :
2063 ctx
->UniformBufferBindings
[index
].Size
;
2066 /* ARB_shader_storage_buffer_object */
2067 case GL_SHADER_STORAGE_BUFFER_BINDING
:
2068 if (!ctx
->Extensions
.ARB_shader_storage_buffer_object
)
2070 if (index
>= ctx
->Const
.MaxShaderStorageBufferBindings
)
2072 v
->value_int
= ctx
->ShaderStorageBufferBindings
[index
].BufferObject
->Name
;
2075 case GL_SHADER_STORAGE_BUFFER_START
:
2076 if (!ctx
->Extensions
.ARB_shader_storage_buffer_object
)
2078 if (index
>= ctx
->Const
.MaxShaderStorageBufferBindings
)
2080 v
->value_int
= ctx
->ShaderStorageBufferBindings
[index
].Offset
< 0 ? 0 :
2081 ctx
->ShaderStorageBufferBindings
[index
].Offset
;
2084 case GL_SHADER_STORAGE_BUFFER_SIZE
:
2085 if (!ctx
->Extensions
.ARB_shader_storage_buffer_object
)
2087 if (index
>= ctx
->Const
.MaxShaderStorageBufferBindings
)
2089 v
->value_int
= ctx
->ShaderStorageBufferBindings
[index
].Size
< 0 ? 0 :
2090 ctx
->ShaderStorageBufferBindings
[index
].Size
;
2093 /* ARB_texture_multisample / GL3.2 */
2094 case GL_SAMPLE_MASK_VALUE
:
2097 if (!ctx
->Extensions
.ARB_texture_multisample
)
2099 v
->value_int
= ctx
->Multisample
.SampleMaskValue
;
2102 case GL_ATOMIC_COUNTER_BUFFER_BINDING
:
2103 if (!ctx
->Extensions
.ARB_shader_atomic_counters
)
2105 if (index
>= ctx
->Const
.MaxAtomicBufferBindings
)
2107 v
->value_int
= ctx
->AtomicBufferBindings
[index
].BufferObject
->Name
;
2110 case GL_ATOMIC_COUNTER_BUFFER_START
:
2111 if (!ctx
->Extensions
.ARB_shader_atomic_counters
)
2113 if (index
>= ctx
->Const
.MaxAtomicBufferBindings
)
2115 v
->value_int64
= ctx
->AtomicBufferBindings
[index
].Offset
;
2118 case GL_ATOMIC_COUNTER_BUFFER_SIZE
:
2119 if (!ctx
->Extensions
.ARB_shader_atomic_counters
)
2121 if (index
>= ctx
->Const
.MaxAtomicBufferBindings
)
2123 v
->value_int64
= ctx
->AtomicBufferBindings
[index
].Size
;
2126 case GL_VERTEX_BINDING_DIVISOR
:
2127 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_instanced_arrays
) &&
2128 !_mesa_is_gles31(ctx
))
2130 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
)
2132 v
->value_int
= ctx
->Array
.VAO
->VertexBinding
[VERT_ATTRIB_GENERIC(index
)].InstanceDivisor
;
2135 case GL_VERTEX_BINDING_OFFSET
:
2136 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles31(ctx
))
2138 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
)
2140 v
->value_int
= ctx
->Array
.VAO
->VertexBinding
[VERT_ATTRIB_GENERIC(index
)].Offset
;
2143 case GL_VERTEX_BINDING_STRIDE
:
2144 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles31(ctx
))
2146 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
)
2148 v
->value_int
= ctx
->Array
.VAO
->VertexBinding
[VERT_ATTRIB_GENERIC(index
)].Stride
;
2151 case GL_VERTEX_BINDING_BUFFER
:
2152 if (ctx
->API
== API_OPENGLES2
&& ctx
->Version
< 31)
2154 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
)
2156 v
->value_int
= ctx
->Array
.VAO
->VertexBinding
[VERT_ATTRIB_GENERIC(index
)].BufferObj
->Name
;
2159 /* ARB_shader_image_load_store */
2160 case GL_IMAGE_BINDING_NAME
: {
2161 struct gl_texture_object
*t
;
2163 if (!ctx
->Extensions
.ARB_shader_image_load_store
)
2165 if (index
>= ctx
->Const
.MaxImageUnits
)
2168 t
= ctx
->ImageUnits
[index
].TexObj
;
2169 v
->value_int
= (t
? t
->Name
: 0);
2173 case GL_IMAGE_BINDING_LEVEL
:
2174 if (!ctx
->Extensions
.ARB_shader_image_load_store
)
2176 if (index
>= ctx
->Const
.MaxImageUnits
)
2179 v
->value_int
= ctx
->ImageUnits
[index
].Level
;
2182 case GL_IMAGE_BINDING_LAYERED
:
2183 if (!ctx
->Extensions
.ARB_shader_image_load_store
)
2185 if (index
>= ctx
->Const
.MaxImageUnits
)
2188 v
->value_int
= ctx
->ImageUnits
[index
].Layered
;
2191 case GL_IMAGE_BINDING_LAYER
:
2192 if (!ctx
->Extensions
.ARB_shader_image_load_store
)
2194 if (index
>= ctx
->Const
.MaxImageUnits
)
2197 v
->value_int
= ctx
->ImageUnits
[index
].Layer
;
2200 case GL_IMAGE_BINDING_ACCESS
:
2201 if (!ctx
->Extensions
.ARB_shader_image_load_store
)
2203 if (index
>= ctx
->Const
.MaxImageUnits
)
2206 v
->value_int
= ctx
->ImageUnits
[index
].Access
;
2209 case GL_IMAGE_BINDING_FORMAT
:
2210 if (!ctx
->Extensions
.ARB_shader_image_load_store
)
2212 if (index
>= ctx
->Const
.MaxImageUnits
)
2215 v
->value_int
= ctx
->ImageUnits
[index
].Format
;
2218 /* ARB_direct_state_access */
2219 case GL_TEXTURE_BINDING_1D
:
2220 case GL_TEXTURE_BINDING_1D_ARRAY
:
2221 case GL_TEXTURE_BINDING_2D
:
2222 case GL_TEXTURE_BINDING_2D_ARRAY
:
2223 case GL_TEXTURE_BINDING_2D_MULTISAMPLE
:
2224 case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY
:
2225 case GL_TEXTURE_BINDING_3D
:
2226 case GL_TEXTURE_BINDING_BUFFER
:
2227 case GL_TEXTURE_BINDING_CUBE_MAP
:
2228 case GL_TEXTURE_BINDING_CUBE_MAP_ARRAY
:
2229 case GL_TEXTURE_BINDING_RECTANGLE
: {
2232 if (ctx
->API
!= API_OPENGL_CORE
)
2234 target
= tex_binding_to_index(ctx
, pname
);
2237 if (index
>= _mesa_max_tex_unit(ctx
))
2240 v
->value_int
= ctx
->Texture
.Unit
[index
].CurrentTex
[target
]->Name
;
2244 case GL_SAMPLER_BINDING
: {
2245 struct gl_sampler_object
*samp
;
2247 if (ctx
->API
!= API_OPENGL_CORE
)
2249 if (index
>= _mesa_max_tex_unit(ctx
))
2252 samp
= ctx
->Texture
.Unit
[index
].Sampler
;
2253 v
->value_int
= samp
? samp
->Name
: 0;
2257 case GL_MAX_COMPUTE_WORK_GROUP_COUNT
:
2258 if (!_mesa_has_compute_shaders(ctx
))
2262 v
->value_int
= ctx
->Const
.MaxComputeWorkGroupCount
[index
];
2265 case GL_MAX_COMPUTE_WORK_GROUP_SIZE
:
2266 if (!_mesa_has_compute_shaders(ctx
))
2270 v
->value_int
= ctx
->Const
.MaxComputeWorkGroupSize
[index
];
2275 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=%s)", func
,
2276 _mesa_enum_to_string(pname
));
2277 return TYPE_INVALID
;
2279 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(pname=%s)", func
,
2280 _mesa_enum_to_string(pname
));
2281 return TYPE_INVALID
;
2285 _mesa_GetBooleani_v( GLenum pname
, GLuint index
, GLboolean
*params
)
2288 enum value_type type
=
2289 find_value_indexed("glGetBooleani_v", pname
, index
, &v
);
2293 params
[0] = INT_TO_BOOLEAN(v
.value_int
);
2296 params
[0] = INT_TO_BOOLEAN(v
.value_int_4
[0]);
2297 params
[1] = INT_TO_BOOLEAN(v
.value_int_4
[1]);
2298 params
[2] = INT_TO_BOOLEAN(v
.value_int_4
[2]);
2299 params
[3] = INT_TO_BOOLEAN(v
.value_int_4
[3]);
2302 params
[0] = INT64_TO_BOOLEAN(v
.value_int64
);
2305 ; /* nothing - GL error was recorded */
2310 _mesa_GetIntegeri_v( GLenum pname
, GLuint index
, GLint
*params
)
2313 enum value_type type
=
2314 find_value_indexed("glGetIntegeri_v", pname
, index
, &v
);
2319 params
[3] = IROUND(v
.value_float_4
[3]);
2322 params
[2] = IROUND(v
.value_float_4
[2]);
2325 params
[1] = IROUND(v
.value_float_4
[1]);
2328 params
[0] = IROUND(v
.value_float_4
[0]);
2331 case TYPE_DOUBLEN_2
:
2332 params
[1] = IROUND(v
.value_double_2
[1]);
2334 params
[0] = IROUND(v
.value_double_2
[0]);
2338 params
[0] = v
.value_int
;
2341 params
[0] = v
.value_int_4
[0];
2342 params
[1] = v
.value_int_4
[1];
2343 params
[2] = v
.value_int_4
[2];
2344 params
[3] = v
.value_int_4
[3];
2347 params
[0] = INT64_TO_INT(v
.value_int64
);
2350 ; /* nothing - GL error was recorded */
2355 _mesa_GetInteger64i_v( GLenum pname
, GLuint index
, GLint64
*params
)
2358 enum value_type type
=
2359 find_value_indexed("glGetInteger64i_v", pname
, index
, &v
);
2363 params
[0] = v
.value_int
;
2366 params
[0] = v
.value_int_4
[0];
2367 params
[1] = v
.value_int_4
[1];
2368 params
[2] = v
.value_int_4
[2];
2369 params
[3] = v
.value_int_4
[3];
2372 params
[0] = v
.value_int64
;
2375 ; /* nothing - GL error was recorded */
2380 _mesa_GetFloati_v(GLenum pname
, GLuint index
, GLfloat
*params
)
2385 enum value_type type
=
2386 find_value_indexed("glGetFloati_v", pname
, index
, &v
);
2391 params
[3] = v
.value_float_4
[3];
2394 params
[2] = v
.value_float_4
[2];
2397 params
[1] = v
.value_float_4
[1];
2400 params
[0] = v
.value_float_4
[0];
2403 case TYPE_DOUBLEN_2
:
2404 params
[1] = (GLfloat
) v
.value_double_2
[1];
2406 params
[0] = (GLfloat
) v
.value_double_2
[0];
2410 params
[3] = (GLfloat
) v
.value_int_4
[3];
2412 params
[2] = (GLfloat
) v
.value_int_4
[2];
2415 params
[1] = (GLfloat
) v
.value_int_4
[1];
2418 params
[0] = (GLfloat
) v
.value_int_4
[0];
2422 for (i
= 0; i
< v
.value_int_n
.n
; i
++)
2423 params
[i
] = INT_TO_FLOAT(v
.value_int_n
.ints
[i
]);
2427 params
[0] = (GLfloat
) v
.value_int64
;
2431 params
[0] = BOOLEAN_TO_FLOAT(v
.value_bool
);
2435 m
= *(GLmatrix
**) &v
;
2436 for (i
= 0; i
< 16; i
++)
2437 params
[i
] = m
->m
[i
];
2441 m
= *(GLmatrix
**) &v
;
2442 for (i
= 0; i
< 16; i
++)
2443 params
[i
] = m
->m
[transpose
[i
]];
2452 _mesa_GetDoublei_v(GLenum pname
, GLuint index
, GLdouble
*params
)
2457 enum value_type type
=
2458 find_value_indexed("glGetDoublei_v", pname
, index
, &v
);
2463 params
[3] = (GLdouble
) v
.value_float_4
[3];
2466 params
[2] = (GLdouble
) v
.value_float_4
[2];
2469 params
[1] = (GLdouble
) v
.value_float_4
[1];
2472 params
[0] = (GLdouble
) v
.value_float_4
[0];
2475 case TYPE_DOUBLEN_2
:
2476 params
[1] = v
.value_double_2
[1];
2478 params
[0] = v
.value_double_2
[0];
2482 params
[3] = (GLdouble
) v
.value_int_4
[3];
2484 params
[2] = (GLdouble
) v
.value_int_4
[2];
2487 params
[1] = (GLdouble
) v
.value_int_4
[1];
2490 params
[0] = (GLdouble
) v
.value_int_4
[0];
2494 for (i
= 0; i
< v
.value_int_n
.n
; i
++)
2495 params
[i
] = (GLdouble
) INT_TO_FLOAT(v
.value_int_n
.ints
[i
]);
2499 params
[0] = (GLdouble
) v
.value_int64
;
2503 params
[0] = (GLdouble
) BOOLEAN_TO_FLOAT(v
.value_bool
);
2507 m
= *(GLmatrix
**) &v
;
2508 for (i
= 0; i
< 16; i
++)
2509 params
[i
] = (GLdouble
) m
->m
[i
];
2513 m
= *(GLmatrix
**) &v
;
2514 for (i
= 0; i
< 16; i
++)
2515 params
[i
] = (GLdouble
) m
->m
[transpose
[i
]];
2524 _mesa_GetFixedv(GLenum pname
, GLfixed
*params
)
2526 const struct value_desc
*d
;
2532 d
= find_value("glGetDoublev", pname
, &p
, &v
);
2537 params
[0] = INT_TO_FIXED(d
->offset
);
2542 params
[3] = FLOAT_TO_FIXED(((GLfloat
*) p
)[3]);
2545 params
[2] = FLOAT_TO_FIXED(((GLfloat
*) p
)[2]);
2548 params
[1] = FLOAT_TO_FIXED(((GLfloat
*) p
)[1]);
2551 params
[0] = FLOAT_TO_FIXED(((GLfloat
*) p
)[0]);
2554 case TYPE_DOUBLEN_2
:
2555 params
[1] = FLOAT_TO_FIXED(((GLdouble
*) p
)[1]);
2557 params
[0] = FLOAT_TO_FIXED(((GLdouble
*) p
)[0]);
2561 params
[3] = INT_TO_FIXED(((GLint
*) p
)[3]);
2563 params
[2] = INT_TO_FIXED(((GLint
*) p
)[2]);
2566 params
[1] = INT_TO_FIXED(((GLint
*) p
)[1]);
2569 params
[0] = INT_TO_FIXED(((GLint
*) p
)[0]);
2573 for (i
= 0; i
< v
.value_int_n
.n
; i
++)
2574 params
[i
] = INT_TO_FIXED(v
.value_int_n
.ints
[i
]);
2578 params
[0] = ((GLint64
*) p
)[0];
2582 params
[0] = BOOLEAN_TO_FIXED(((GLboolean
*) p
)[0]);
2586 m
= *(GLmatrix
**) p
;
2587 for (i
= 0; i
< 16; i
++)
2588 params
[i
] = FLOAT_TO_FIXED(m
->m
[i
]);
2592 m
= *(GLmatrix
**) p
;
2593 for (i
= 0; i
< 16; i
++)
2594 params
[i
] = FLOAT_TO_FIXED(m
->m
[transpose
[i
]]);
2605 shift
= d
->type
- TYPE_BIT_0
;
2606 params
[0] = BOOLEAN_TO_FIXED((*(GLbitfield
*) p
>> shift
) & 1);