2 * Copyright (C) 2010 Brian Paul All Rights Reserved.
3 * Copyright (C) 2010 Intel Corporation
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included
13 * in all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
19 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21 * OTHER DEALINGS IN THE SOFTWARE.
23 * Author: Kristian Høgsberg <krh@bitplanet.net>
29 #include "debug_output.h"
33 #include "extensions.h"
38 #include "texcompress.h"
40 #include "framebuffer.h"
41 #include "samplerobj.h"
44 /* This is a table driven implemetation of the glGet*v() functions.
45 * The basic idea is that most getters just look up an int somewhere
46 * in struct gl_context and then convert it to a bool or float according to
47 * which of glGetIntegerv() glGetBooleanv() etc is being called.
48 * Instead of generating code to do this, we can just record the enum
49 * value and the offset into struct gl_context in an array of structs. Then
50 * in glGet*(), we lookup the struct for the enum in question, and use
51 * the offset to get the int we need.
53 * Sometimes we need to look up a float, a boolean, a bit in a
54 * bitfield, a matrix or other types instead, so we need to track the
55 * type of the value in struct gl_context. And sometimes the value isn't in
56 * struct gl_context but in the drawbuffer, the array object, current texture
57 * unit, or maybe it's a computed value. So we need to also track
58 * where or how to find the value. Finally, we sometimes need to
59 * check that one of a number of extensions are enabled, the GL
60 * version or flush or call _mesa_update_state(). This is done by
61 * attaching optional extra information to the value description
62 * struct, it's sort of like an array of opcodes that describe extra
65 * Putting all this together we end up with struct value_desc below,
66 * and with a couple of macros to help, the table of struct value_desc
67 * is about as concise as the specification in the old python script.
70 #define FLOAT_TO_BOOLEAN(X) ( (X) ? GL_TRUE : GL_FALSE )
71 #define FLOAT_TO_FIXED(F) ( ((F) * 65536.0f > INT_MAX) ? INT_MAX : \
72 ((F) * 65536.0f < INT_MIN) ? INT_MIN : \
73 (GLint) ((F) * 65536.0f) )
75 #define INT_TO_BOOLEAN(I) ( (I) ? GL_TRUE : GL_FALSE )
76 #define INT_TO_FIXED(I) ( ((I) > SHRT_MAX) ? INT_MAX : \
77 ((I) < SHRT_MIN) ? INT_MIN : \
78 (GLint) ((I) * 65536) )
80 #define INT64_TO_BOOLEAN(I) ( (I) ? GL_TRUE : GL_FALSE )
81 #define INT64_TO_INT(I) ( (GLint)((I > INT_MAX) ? INT_MAX : ((I < INT_MIN) ? INT_MIN : (I))) )
83 #define BOOLEAN_TO_INT(B) ( (GLint) (B) )
84 #define BOOLEAN_TO_INT64(B) ( (GLint64) (B) )
85 #define BOOLEAN_TO_FLOAT(B) ( (B) ? 1.0F : 0.0F )
86 #define BOOLEAN_TO_FIXED(B) ( (GLint) ((B) ? 1 : 0) << 16 )
88 #define ENUM_TO_INT64(E) ( (GLint64) (E) )
89 #define ENUM_TO_FIXED(E) (E)
125 enum value_location
{
145 EXTRA_NEW_FRAG_CLAMP
,
146 EXTRA_VALID_DRAW_BUFFER
,
147 EXTRA_VALID_TEXTURE_UNIT
,
148 EXTRA_VALID_CLIP_DISTANCE
,
152 EXTRA_EXT_ATOMICS_GS
,
153 EXTRA_EXT_SHADER_IMAGE_GS
,
154 EXTRA_EXT_ATOMICS_TESS
,
155 EXTRA_EXT_SHADER_IMAGE_TESS
,
157 EXTRA_EXT_FB_NO_ATTACH_GS
,
161 #define NO_EXTRA NULL
166 GLubyte location
; /**< enum value_location */
167 GLubyte type
; /**< enum value_type */
174 GLfloat value_float_4
[4];
175 GLdouble value_double_2
[2];
176 GLmatrix
*value_matrix
;
178 GLint value_int_4
[4];
182 /* Sigh, see GL_COMPRESSED_TEXTURE_FORMATS_ARB handling */
186 GLboolean value_bool
;
189 #define BUFFER_FIELD(field, type) \
190 LOC_BUFFER, type, offsetof(struct gl_framebuffer, field)
191 #define CONTEXT_FIELD(field, type) \
192 LOC_CONTEXT, type, offsetof(struct gl_context, field)
193 #define ARRAY_FIELD(field, type) \
194 LOC_ARRAY, type, offsetof(struct gl_vertex_array_object, field)
195 #undef CONST /* already defined through windows.h */
196 #define CONST(value) \
197 LOC_CONTEXT, TYPE_CONST, value
199 #define BUFFER_INT(field) BUFFER_FIELD(field, TYPE_INT)
200 #define BUFFER_ENUM(field) BUFFER_FIELD(field, TYPE_ENUM)
201 #define BUFFER_BOOL(field) BUFFER_FIELD(field, TYPE_BOOLEAN)
203 #define CONTEXT_INT(field) CONTEXT_FIELD(field, TYPE_INT)
204 #define CONTEXT_INT2(field) CONTEXT_FIELD(field, TYPE_INT_2)
205 #define CONTEXT_INT64(field) CONTEXT_FIELD(field, TYPE_INT64)
206 #define CONTEXT_ENUM(field) CONTEXT_FIELD(field, TYPE_ENUM)
207 #define CONTEXT_ENUM2(field) CONTEXT_FIELD(field, TYPE_ENUM_2)
208 #define CONTEXT_BOOL(field) CONTEXT_FIELD(field, TYPE_BOOLEAN)
209 #define CONTEXT_BIT0(field) CONTEXT_FIELD(field, TYPE_BIT_0)
210 #define CONTEXT_BIT1(field) CONTEXT_FIELD(field, TYPE_BIT_1)
211 #define CONTEXT_BIT2(field) CONTEXT_FIELD(field, TYPE_BIT_2)
212 #define CONTEXT_BIT3(field) CONTEXT_FIELD(field, TYPE_BIT_3)
213 #define CONTEXT_BIT4(field) CONTEXT_FIELD(field, TYPE_BIT_4)
214 #define CONTEXT_BIT5(field) CONTEXT_FIELD(field, TYPE_BIT_5)
215 #define CONTEXT_BIT6(field) CONTEXT_FIELD(field, TYPE_BIT_6)
216 #define CONTEXT_BIT7(field) CONTEXT_FIELD(field, TYPE_BIT_7)
217 #define CONTEXT_FLOAT(field) CONTEXT_FIELD(field, TYPE_FLOAT)
218 #define CONTEXT_FLOAT2(field) CONTEXT_FIELD(field, TYPE_FLOAT_2)
219 #define CONTEXT_FLOAT3(field) CONTEXT_FIELD(field, TYPE_FLOAT_3)
220 #define CONTEXT_FLOAT4(field) CONTEXT_FIELD(field, TYPE_FLOAT_4)
221 #define CONTEXT_MATRIX(field) CONTEXT_FIELD(field, TYPE_MATRIX)
222 #define CONTEXT_MATRIX_T(field) CONTEXT_FIELD(field, TYPE_MATRIX_T)
224 #define ARRAY_INT(field) ARRAY_FIELD(field, TYPE_INT)
225 #define ARRAY_ENUM(field) ARRAY_FIELD(field, TYPE_ENUM)
226 #define ARRAY_BOOL(field) ARRAY_FIELD(field, TYPE_BOOLEAN)
229 offsetof(struct gl_extensions, f)
231 #define EXTRA_EXT(e) \
232 static const int extra_##e[] = { \
236 #define EXTRA_EXT2(e1, e2) \
237 static const int extra_##e1##_##e2[] = { \
238 EXT(e1), EXT(e2), EXTRA_END \
241 /* The 'extra' mechanism is a way to specify extra checks (such as
242 * extensions or specific gl versions) or actions (flush current, new
243 * buffers) that we need to do before looking up an enum. We need to
244 * declare them all up front so we can refer to them in the value_desc
247 * Each EXTRA_ will be executed. For EXTRA_* enums of extensions and API
248 * versions, listing multiple ones in an array means an error will be thrown
249 * only if none of them are available. If you need to check for "AND"
250 * behavior, you would need to make a custom EXTRA_ enum.
253 static const int extra_new_buffers
[] = {
258 static const int extra_new_frag_clamp
[] = {
259 EXTRA_NEW_FRAG_CLAMP
,
263 static const int extra_valid_draw_buffer
[] = {
264 EXTRA_VALID_DRAW_BUFFER
,
268 static const int extra_valid_texture_unit
[] = {
269 EXTRA_VALID_TEXTURE_UNIT
,
273 static const int extra_valid_clip_distance
[] = {
274 EXTRA_VALID_CLIP_DISTANCE
,
278 static const int extra_flush_current_valid_texture_unit
[] = {
280 EXTRA_VALID_TEXTURE_UNIT
,
284 static const int extra_flush_current
[] = {
289 static const int extra_EXT_texture_integer_and_new_buffers
[] = {
290 EXT(EXT_texture_integer
),
295 static const int extra_GLSL_130_es3
[] = {
301 static const int extra_texture_buffer_object
[] = {
304 EXT(ARB_texture_buffer_object
),
308 static const int extra_ARB_transform_feedback2_api_es3
[] = {
309 EXT(ARB_transform_feedback2
),
314 static const int extra_ARB_uniform_buffer_object_and_geometry_shader
[] = {
319 static const int extra_ARB_ES2_compatibility_api_es2
[] = {
320 EXT(ARB_ES2_compatibility
),
325 static const int extra_ARB_ES3_compatibility_api_es3
[] = {
326 EXT(ARB_ES3_compatibility
),
331 static const int extra_EXT_framebuffer_sRGB_and_new_buffers
[] = {
332 EXT(EXT_framebuffer_sRGB
),
337 static const int extra_EXT_packed_float
[] = {
338 EXT(EXT_packed_float
),
343 static const int extra_EXT_texture_array_es3
[] = {
344 EXT(EXT_texture_array
),
349 static const int extra_ARB_shader_atomic_counters_and_geometry_shader
[] = {
350 EXTRA_EXT_ATOMICS_GS
,
354 static const int extra_ARB_shader_image_load_store_and_geometry_shader
[] = {
355 EXTRA_EXT_SHADER_IMAGE_GS
,
359 static const int extra_ARB_shader_atomic_counters_and_tessellation
[] = {
360 EXTRA_EXT_ATOMICS_TESS
,
364 static const int extra_ARB_shader_image_load_store_and_tessellation
[] = {
365 EXTRA_EXT_SHADER_IMAGE_TESS
,
369 /* HACK: remove when ARB_compute_shader is actually supported */
370 static const int extra_ARB_compute_shader_es31
[] = {
371 EXT(ARB_compute_shader
),
376 static const int extra_ARB_shader_storage_buffer_object_es31
[] = {
377 EXT(ARB_shader_storage_buffer_object
),
382 static const int extra_ARB_shader_storage_buffer_object_and_geometry_shader
[] = {
387 static const int extra_ARB_shader_image_load_store_shader_storage_buffer_object_es31
[] = {
388 EXT(ARB_shader_image_load_store
),
389 EXT(ARB_shader_storage_buffer_object
),
394 static const int extra_ARB_framebuffer_no_attachments_and_geometry_shader
[] = {
395 EXTRA_EXT_FB_NO_ATTACH_GS
,
399 static const int extra_ARB_viewport_array_or_oes_geometry_shader
[] = {
400 EXT(ARB_viewport_array
),
405 static const int extra_ARB_gpu_shader5_or_oes_geometry_shader
[] = {
406 EXT(ARB_gpu_shader5
),
411 EXTRA_EXT(ARB_texture_cube_map
);
412 EXTRA_EXT(EXT_texture_array
);
413 EXTRA_EXT(NV_fog_distance
);
414 EXTRA_EXT(EXT_texture_filter_anisotropic
);
415 EXTRA_EXT(NV_point_sprite
);
416 EXTRA_EXT(NV_texture_rectangle
);
417 EXTRA_EXT(EXT_stencil_two_side
);
418 EXTRA_EXT(EXT_depth_bounds_test
);
419 EXTRA_EXT(ARB_depth_clamp
);
420 EXTRA_EXT(ATI_fragment_shader
);
421 EXTRA_EXT(EXT_provoking_vertex
);
422 EXTRA_EXT(ARB_fragment_shader
);
423 EXTRA_EXT(ARB_fragment_program
);
424 EXTRA_EXT2(ARB_framebuffer_object
, EXT_framebuffer_multisample
);
425 EXTRA_EXT(ARB_seamless_cube_map
);
427 EXTRA_EXT(ARB_vertex_shader
);
428 EXTRA_EXT(EXT_transform_feedback
);
429 EXTRA_EXT(ARB_transform_feedback3
);
430 EXTRA_EXT(EXT_pixel_buffer_object
);
431 EXTRA_EXT(ARB_vertex_program
);
432 EXTRA_EXT2(NV_point_sprite
, ARB_point_sprite
);
433 EXTRA_EXT2(ARB_vertex_program
, ARB_fragment_program
);
434 EXTRA_EXT(ARB_color_buffer_float
);
435 EXTRA_EXT(EXT_framebuffer_sRGB
);
436 EXTRA_EXT(OES_EGL_image_external
);
437 EXTRA_EXT(ARB_blend_func_extended
);
438 EXTRA_EXT(ARB_uniform_buffer_object
);
439 EXTRA_EXT(ARB_timer_query
);
440 EXTRA_EXT(ARB_texture_cube_map_array
);
441 EXTRA_EXT(ARB_texture_buffer_range
);
442 EXTRA_EXT(ARB_texture_multisample
);
443 EXTRA_EXT(ARB_texture_gather
);
444 EXTRA_EXT(ARB_shader_atomic_counters
);
445 EXTRA_EXT(ARB_draw_indirect
);
446 EXTRA_EXT(ARB_shader_image_load_store
);
447 EXTRA_EXT(ARB_viewport_array
);
448 EXTRA_EXT(ARB_compute_shader
);
449 EXTRA_EXT(ARB_gpu_shader5
);
450 EXTRA_EXT(ARB_query_buffer_object
);
451 EXTRA_EXT2(ARB_transform_feedback3
, ARB_gpu_shader5
);
452 EXTRA_EXT(INTEL_performance_query
);
453 EXTRA_EXT(ARB_explicit_uniform_location
);
454 EXTRA_EXT(ARB_clip_control
);
455 EXTRA_EXT(EXT_polygon_offset_clamp
);
456 EXTRA_EXT(ARB_framebuffer_no_attachments
);
457 EXTRA_EXT(ARB_tessellation_shader
);
458 EXTRA_EXT(ARB_shader_subroutine
);
459 EXTRA_EXT(ARB_shader_storage_buffer_object
);
460 EXTRA_EXT(ARB_indirect_parameters
);
461 EXTRA_EXT(ATI_meminfo
);
462 EXTRA_EXT(NVX_gpu_memory_info
);
465 extra_ARB_color_buffer_float_or_glcore
[] = {
466 EXT(ARB_color_buffer_float
),
472 extra_NV_primitive_restart
[] = {
473 EXT(NV_primitive_restart
),
477 static const int extra_version_30
[] = { EXTRA_VERSION_30
, EXTRA_END
};
478 static const int extra_version_31
[] = { EXTRA_VERSION_31
, EXTRA_END
};
479 static const int extra_version_32
[] = { EXTRA_VERSION_32
, EXTRA_END
};
480 static const int extra_version_40
[] = { EXTRA_VERSION_40
, EXTRA_END
};
482 static const int extra_gl30_es3
[] = {
488 static const int extra_gl32_es3
[] = {
494 static const int extra_version_32_OES_geometry_shader
[] = {
500 static const int extra_gl40_ARB_sample_shading
[] = {
502 EXT(ARB_sample_shading
),
507 extra_ARB_vertex_program_api_es2
[] = {
508 EXT(ARB_vertex_program
),
513 /* The ReadBuffer get token is valid under either full GL or under
514 * GLES2 if the NV_read_buffer extension is available. */
516 extra_NV_read_buffer_api_gl
[] = {
522 static const int extra_core_ARB_color_buffer_float_and_new_buffers
[] = {
524 EXT(ARB_color_buffer_float
),
529 /* This is the big table describing all the enums we accept in
530 * glGet*v(). The table is partitioned into six parts: enums
531 * understood by all GL APIs (OpenGL, GLES and GLES2), enums shared
532 * between OpenGL and GLES, enums exclusive to GLES, etc for the
533 * remaining combinations. To look up the enums valid in a given API
534 * we will use a hash table specific to that API. These tables are in
535 * turn generated at build time and included through get_hash.h.
538 #include "get_hash.h"
540 /* All we need now is a way to look up the value struct from the enum.
541 * The code generated by gcc for the old generated big switch
542 * statement is a big, balanced, open coded if/else tree, essentially
543 * an unrolled binary search. It would be natural to sort the new
544 * enum table and use bsearch(), but we will use a read-only hash
545 * table instead. bsearch() has a nice guaranteed worst case
546 * performance, but we're also guaranteed to hit that worst case
547 * (log2(n) iterations) for about half the enums. Instead, using an
548 * open addressing hash table, we can find the enum on the first try
549 * for 80% of the enums, 1 collision for 10% and never more than 5
550 * collisions for any enum (typical numbers). And the code is very
551 * simple, even though it feels a little magic. */
555 print_table_stats(int api
)
557 int i
, j
, collisions
[11], count
, hash
, mask
;
558 const struct value_desc
*d
;
559 const char *api_names
[] = {
560 [API_OPENGL_COMPAT
] = "GL",
561 [API_OPENGL_CORE
] = "GL_CORE",
562 [API_OPENGLES
] = "GLES",
563 [API_OPENGLES2
] = "GLES2",
565 const char *api_name
;
567 api_name
= api
< ARRAY_SIZE(api_names
) ? api_names
[api
] : "N/A";
569 mask
= ARRAY_SIZE(table(api
)) - 1;
570 memset(collisions
, 0, sizeof collisions
);
572 for (i
= 0; i
< ARRAY_SIZE(table(api
)); i
++) {
576 d
= &values
[table(api
)[i
]];
577 hash
= (d
->pname
* prime_factor
);
580 if (values
[table(api
)[hash
& mask
]].pname
== d
->pname
)
592 printf("number of enums for %s: %d (total %ld)\n",
593 api_name
, count
, ARRAY_SIZE(values
));
594 for (i
= 0; i
< ARRAY_SIZE(collisions
) - 1; i
++)
595 if (collisions
[i
] > 0)
596 printf(" %d enums with %d %scollisions\n",
597 collisions
[i
], i
, i
== 10 ? "or more " : "");
602 * Initialize the enum hash for a given API
604 * This is called from one_time_init() to insert the enum values that
605 * are valid for the API in question into the enum hash table.
607 * \param the current context, for determining the API in question
609 void _mesa_init_get_hash(struct gl_context
*ctx
)
612 print_table_stats(ctx
->API
);
619 * Handle irregular enums
621 * Some values don't conform to the "well-known type at context
622 * pointer + offset" pattern, so we have this function to catch all
623 * the corner cases. Typically, it's a computed value or a one-off
624 * pointer to a custom struct or something.
626 * In this case we can't return a pointer to the value, so we'll have
627 * to use the temporary variable 'v' declared back in the calling
628 * glGet*v() function to store the result.
630 * \param ctx the current context
631 * \param d the struct value_desc that describes the enum
632 * \param v pointer to the tmp declared in the calling glGet*v() function
635 find_custom_value(struct gl_context
*ctx
, const struct value_desc
*d
, union value
*v
)
637 struct gl_buffer_object
**buffer_obj
;
638 struct gl_vertex_attrib_array
*array
;
642 case GL_MAJOR_VERSION
:
643 v
->value_int
= ctx
->Version
/ 10;
645 case GL_MINOR_VERSION
:
646 v
->value_int
= ctx
->Version
% 10;
652 case GL_TEXTURE_CUBE_MAP
:
653 case GL_TEXTURE_RECTANGLE_NV
:
654 case GL_TEXTURE_EXTERNAL_OES
:
655 v
->value_bool
= _mesa_IsEnabled(d
->pname
);
658 case GL_LINE_STIPPLE_PATTERN
:
659 /* This is the only GLushort, special case it here by promoting
660 * to an int rather than introducing a new type. */
661 v
->value_int
= ctx
->Line
.StipplePattern
;
664 case GL_CURRENT_RASTER_TEXTURE_COORDS
:
665 unit
= ctx
->Texture
.CurrentUnit
;
666 v
->value_float_4
[0] = ctx
->Current
.RasterTexCoords
[unit
][0];
667 v
->value_float_4
[1] = ctx
->Current
.RasterTexCoords
[unit
][1];
668 v
->value_float_4
[2] = ctx
->Current
.RasterTexCoords
[unit
][2];
669 v
->value_float_4
[3] = ctx
->Current
.RasterTexCoords
[unit
][3];
672 case GL_CURRENT_TEXTURE_COORDS
:
673 unit
= ctx
->Texture
.CurrentUnit
;
674 v
->value_float_4
[0] = ctx
->Current
.Attrib
[VERT_ATTRIB_TEX0
+ unit
][0];
675 v
->value_float_4
[1] = ctx
->Current
.Attrib
[VERT_ATTRIB_TEX0
+ unit
][1];
676 v
->value_float_4
[2] = ctx
->Current
.Attrib
[VERT_ATTRIB_TEX0
+ unit
][2];
677 v
->value_float_4
[3] = ctx
->Current
.Attrib
[VERT_ATTRIB_TEX0
+ unit
][3];
680 case GL_COLOR_WRITEMASK
:
681 v
->value_int_4
[0] = ctx
->Color
.ColorMask
[0][RCOMP
] ? 1 : 0;
682 v
->value_int_4
[1] = ctx
->Color
.ColorMask
[0][GCOMP
] ? 1 : 0;
683 v
->value_int_4
[2] = ctx
->Color
.ColorMask
[0][BCOMP
] ? 1 : 0;
684 v
->value_int_4
[3] = ctx
->Color
.ColorMask
[0][ACOMP
] ? 1 : 0;
688 v
->value_bool
= ctx
->Current
.Attrib
[VERT_ATTRIB_EDGEFLAG
][0] == 1.0F
;
692 v
->value_enum
= ctx
->ReadBuffer
->ColorReadBuffer
;
695 case GL_MAP2_GRID_DOMAIN
:
696 v
->value_float_4
[0] = ctx
->Eval
.MapGrid2u1
;
697 v
->value_float_4
[1] = ctx
->Eval
.MapGrid2u2
;
698 v
->value_float_4
[2] = ctx
->Eval
.MapGrid2v1
;
699 v
->value_float_4
[3] = ctx
->Eval
.MapGrid2v2
;
702 case GL_TEXTURE_STACK_DEPTH
:
703 unit
= ctx
->Texture
.CurrentUnit
;
704 v
->value_int
= ctx
->TextureMatrixStack
[unit
].Depth
+ 1;
706 case GL_TEXTURE_MATRIX
:
707 unit
= ctx
->Texture
.CurrentUnit
;
708 v
->value_matrix
= ctx
->TextureMatrixStack
[unit
].Top
;
711 case GL_TEXTURE_COORD_ARRAY
:
712 case GL_TEXTURE_COORD_ARRAY_SIZE
:
713 case GL_TEXTURE_COORD_ARRAY_TYPE
:
714 case GL_TEXTURE_COORD_ARRAY_STRIDE
:
715 array
= &ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_TEX(ctx
->Array
.ActiveTexture
)];
716 v
->value_int
= *(GLuint
*) ((char *) array
+ d
->offset
);
719 case GL_ACTIVE_TEXTURE_ARB
:
720 v
->value_int
= GL_TEXTURE0_ARB
+ ctx
->Texture
.CurrentUnit
;
722 case GL_CLIENT_ACTIVE_TEXTURE_ARB
:
723 v
->value_int
= GL_TEXTURE0_ARB
+ ctx
->Array
.ActiveTexture
;
726 case GL_MODELVIEW_STACK_DEPTH
:
727 case GL_PROJECTION_STACK_DEPTH
:
728 v
->value_int
= *(GLint
*) ((char *) ctx
+ d
->offset
) + 1;
731 case GL_MAX_TEXTURE_SIZE
:
732 case GL_MAX_3D_TEXTURE_SIZE
:
733 case GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB
:
734 p
= (GLuint
*) ((char *) ctx
+ d
->offset
);
735 v
->value_int
= 1 << (*p
- 1);
739 v
->value_int_4
[0] = ctx
->Scissor
.ScissorArray
[0].X
;
740 v
->value_int_4
[1] = ctx
->Scissor
.ScissorArray
[0].Y
;
741 v
->value_int_4
[2] = ctx
->Scissor
.ScissorArray
[0].Width
;
742 v
->value_int_4
[3] = ctx
->Scissor
.ScissorArray
[0].Height
;
745 case GL_SCISSOR_TEST
:
746 v
->value_bool
= ctx
->Scissor
.EnableFlags
& 1;
751 ctx
->ListState
.CurrentList
? ctx
->ListState
.CurrentList
->Name
: 0;
754 if (!ctx
->CompileFlag
)
756 else if (ctx
->ExecuteFlag
)
757 v
->value_enum
= GL_COMPILE_AND_EXECUTE
;
759 v
->value_enum
= GL_COMPILE
;
763 v
->value_float_4
[0] = ctx
->ViewportArray
[0].X
;
764 v
->value_float_4
[1] = ctx
->ViewportArray
[0].Y
;
765 v
->value_float_4
[2] = ctx
->ViewportArray
[0].Width
;
766 v
->value_float_4
[3] = ctx
->ViewportArray
[0].Height
;
770 v
->value_double_2
[0] = ctx
->ViewportArray
[0].Near
;
771 v
->value_double_2
[1] = ctx
->ViewportArray
[0].Far
;
774 case GL_ACTIVE_STENCIL_FACE_EXT
:
775 v
->value_enum
= ctx
->Stencil
.ActiveFace
? GL_BACK
: GL_FRONT
;
778 case GL_STENCIL_FAIL
:
779 v
->value_enum
= ctx
->Stencil
.FailFunc
[ctx
->Stencil
.ActiveFace
];
781 case GL_STENCIL_FUNC
:
782 v
->value_enum
= ctx
->Stencil
.Function
[ctx
->Stencil
.ActiveFace
];
784 case GL_STENCIL_PASS_DEPTH_FAIL
:
785 v
->value_enum
= ctx
->Stencil
.ZFailFunc
[ctx
->Stencil
.ActiveFace
];
787 case GL_STENCIL_PASS_DEPTH_PASS
:
788 v
->value_enum
= ctx
->Stencil
.ZPassFunc
[ctx
->Stencil
.ActiveFace
];
791 v
->value_int
= _mesa_get_stencil_ref(ctx
, ctx
->Stencil
.ActiveFace
);
793 case GL_STENCIL_BACK_REF
:
794 v
->value_int
= _mesa_get_stencil_ref(ctx
, 1);
796 case GL_STENCIL_VALUE_MASK
:
797 v
->value_int
= ctx
->Stencil
.ValueMask
[ctx
->Stencil
.ActiveFace
];
799 case GL_STENCIL_WRITEMASK
:
800 v
->value_int
= ctx
->Stencil
.WriteMask
[ctx
->Stencil
.ActiveFace
];
803 case GL_NUM_EXTENSIONS
:
804 v
->value_int
= _mesa_get_extension_count(ctx
);
807 case GL_IMPLEMENTATION_COLOR_READ_TYPE_OES
:
808 v
->value_int
= _mesa_get_color_read_type(ctx
);
810 case GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES
:
811 v
->value_int
= _mesa_get_color_read_format(ctx
);
814 case GL_CURRENT_MATRIX_STACK_DEPTH_ARB
:
815 v
->value_int
= ctx
->CurrentStack
->Depth
+ 1;
817 case GL_CURRENT_MATRIX_ARB
:
818 case GL_TRANSPOSE_CURRENT_MATRIX_ARB
:
819 v
->value_matrix
= ctx
->CurrentStack
->Top
;
822 case GL_NUM_COMPRESSED_TEXTURE_FORMATS_ARB
:
823 v
->value_int
= _mesa_get_compressed_formats(ctx
, NULL
);
825 case GL_COMPRESSED_TEXTURE_FORMATS_ARB
:
827 _mesa_get_compressed_formats(ctx
, v
->value_int_n
.ints
);
828 assert(v
->value_int_n
.n
<= (int) ARRAY_SIZE(v
->value_int_n
.ints
));
831 case GL_MAX_VARYING_FLOATS_ARB
:
832 v
->value_int
= ctx
->Const
.MaxVarying
* 4;
835 /* Various object names */
837 case GL_TEXTURE_BINDING_1D
:
838 case GL_TEXTURE_BINDING_2D
:
839 case GL_TEXTURE_BINDING_3D
:
840 case GL_TEXTURE_BINDING_1D_ARRAY_EXT
:
841 case GL_TEXTURE_BINDING_2D_ARRAY_EXT
:
842 case GL_TEXTURE_BINDING_CUBE_MAP_ARB
:
843 case GL_TEXTURE_BINDING_RECTANGLE_NV
:
844 case GL_TEXTURE_BINDING_EXTERNAL_OES
:
845 case GL_TEXTURE_BINDING_CUBE_MAP_ARRAY
:
846 case GL_TEXTURE_BINDING_2D_MULTISAMPLE
:
847 case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY
:
848 unit
= ctx
->Texture
.CurrentUnit
;
850 ctx
->Texture
.Unit
[unit
].CurrentTex
[d
->offset
]->Name
;
853 /* GL_EXT_packed_float */
854 case GL_RGBA_SIGNED_COMPONENTS_EXT
:
856 /* Note: we only check the 0th color attachment. */
857 const struct gl_renderbuffer
*rb
=
858 ctx
->DrawBuffer
->_ColorDrawBuffers
[0];
859 if (rb
&& _mesa_is_format_signed(rb
->Format
)) {
860 /* Issue 17 of GL_EXT_packed_float: If a component (such as
861 * alpha) has zero bits, the component should not be considered
862 * signed and so the bit for the respective component should be
866 _mesa_get_format_bits(rb
->Format
, GL_RED_BITS
);
868 _mesa_get_format_bits(rb
->Format
, GL_GREEN_BITS
);
870 _mesa_get_format_bits(rb
->Format
, GL_BLUE_BITS
);
872 _mesa_get_format_bits(rb
->Format
, GL_ALPHA_BITS
);
874 _mesa_get_format_bits(rb
->Format
, GL_TEXTURE_LUMINANCE_SIZE
);
876 _mesa_get_format_bits(rb
->Format
, GL_TEXTURE_INTENSITY_SIZE
);
878 v
->value_int_4
[0] = r_bits
+ l_bits
+ i_bits
> 0;
879 v
->value_int_4
[1] = g_bits
+ l_bits
+ i_bits
> 0;
880 v
->value_int_4
[2] = b_bits
+ l_bits
+ i_bits
> 0;
881 v
->value_int_4
[3] = a_bits
+ i_bits
> 0;
887 v
->value_int_4
[3] = 0;
892 /* GL_ARB_vertex_buffer_object */
893 case GL_VERTEX_ARRAY_BUFFER_BINDING_ARB
:
894 case GL_NORMAL_ARRAY_BUFFER_BINDING_ARB
:
895 case GL_COLOR_ARRAY_BUFFER_BINDING_ARB
:
896 case GL_INDEX_ARRAY_BUFFER_BINDING_ARB
:
897 case GL_EDGE_FLAG_ARRAY_BUFFER_BINDING_ARB
:
898 case GL_SECONDARY_COLOR_ARRAY_BUFFER_BINDING_ARB
:
899 case GL_FOG_COORDINATE_ARRAY_BUFFER_BINDING_ARB
:
900 buffer_obj
= (struct gl_buffer_object
**)
901 ((char *) ctx
->Array
.VAO
+ d
->offset
);
902 v
->value_int
= (*buffer_obj
)->Name
;
904 case GL_ARRAY_BUFFER_BINDING_ARB
:
905 v
->value_int
= ctx
->Array
.ArrayBufferObj
->Name
;
907 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING_ARB
:
909 ctx
->Array
.VAO
->VertexBinding
[VERT_ATTRIB_TEX(ctx
->Array
.ActiveTexture
)].BufferObj
->Name
;
911 case GL_ELEMENT_ARRAY_BUFFER_BINDING_ARB
:
912 v
->value_int
= ctx
->Array
.VAO
->IndexBufferObj
->Name
;
915 /* ARB_vertex_array_bgra */
916 case GL_COLOR_ARRAY_SIZE
:
917 array
= &ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_COLOR0
];
918 v
->value_int
= array
->Format
== GL_BGRA
? GL_BGRA
: array
->Size
;
920 case GL_SECONDARY_COLOR_ARRAY_SIZE
:
921 array
= &ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_COLOR1
];
922 v
->value_int
= array
->Format
== GL_BGRA
? GL_BGRA
: array
->Size
;
925 /* ARB_copy_buffer */
926 case GL_COPY_READ_BUFFER
:
927 v
->value_int
= ctx
->CopyReadBuffer
->Name
;
929 case GL_COPY_WRITE_BUFFER
:
930 v
->value_int
= ctx
->CopyWriteBuffer
->Name
;
933 case GL_PIXEL_PACK_BUFFER_BINDING_EXT
:
934 v
->value_int
= ctx
->Pack
.BufferObj
->Name
;
936 case GL_PIXEL_UNPACK_BUFFER_BINDING_EXT
:
937 v
->value_int
= ctx
->Unpack
.BufferObj
->Name
;
939 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING
:
940 v
->value_int
= ctx
->TransformFeedback
.CurrentBuffer
->Name
;
942 case GL_TRANSFORM_FEEDBACK_BUFFER_PAUSED
:
943 v
->value_int
= ctx
->TransformFeedback
.CurrentObject
->Paused
;
945 case GL_TRANSFORM_FEEDBACK_BUFFER_ACTIVE
:
946 v
->value_int
= ctx
->TransformFeedback
.CurrentObject
->Active
;
948 case GL_TRANSFORM_FEEDBACK_BINDING
:
949 v
->value_int
= ctx
->TransformFeedback
.CurrentObject
->Name
;
951 case GL_CURRENT_PROGRAM
:
952 /* The Changelog of the ARB_separate_shader_objects spec says:
954 * 24 25 Jul 2011 pbrown Remove the language erroneously deleting
955 * CURRENT_PROGRAM. In the EXT extension, this
956 * token was aliased to ACTIVE_PROGRAM_EXT, and
957 * was used to indicate the last program set by
958 * either ActiveProgramEXT or UseProgram. In
959 * the ARB extension, the SSO active programs
960 * are now program pipeline object state and
961 * CURRENT_PROGRAM should still be used to query
962 * the last program set by UseProgram (bug 7822).
965 ctx
->Shader
.ActiveProgram
? ctx
->Shader
.ActiveProgram
->Name
: 0;
967 case GL_READ_FRAMEBUFFER_BINDING_EXT
:
968 v
->value_int
= ctx
->ReadBuffer
->Name
;
970 case GL_RENDERBUFFER_BINDING_EXT
:
972 ctx
->CurrentRenderbuffer
? ctx
->CurrentRenderbuffer
->Name
: 0;
974 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES
:
975 v
->value_int
= ctx
->Array
.VAO
->VertexBinding
[VERT_ATTRIB_POINT_SIZE
].BufferObj
->Name
;
979 if (_mesa_get_clamp_fragment_color(ctx
, ctx
->DrawBuffer
))
980 COPY_4FV(v
->value_float_4
, ctx
->Fog
.Color
);
982 COPY_4FV(v
->value_float_4
, ctx
->Fog
.ColorUnclamped
);
984 case GL_COLOR_CLEAR_VALUE
:
985 if (_mesa_get_clamp_fragment_color(ctx
, ctx
->DrawBuffer
)) {
986 v
->value_float_4
[0] = CLAMP(ctx
->Color
.ClearColor
.f
[0], 0.0F
, 1.0F
);
987 v
->value_float_4
[1] = CLAMP(ctx
->Color
.ClearColor
.f
[1], 0.0F
, 1.0F
);
988 v
->value_float_4
[2] = CLAMP(ctx
->Color
.ClearColor
.f
[2], 0.0F
, 1.0F
);
989 v
->value_float_4
[3] = CLAMP(ctx
->Color
.ClearColor
.f
[3], 0.0F
, 1.0F
);
991 COPY_4FV(v
->value_float_4
, ctx
->Color
.ClearColor
.f
);
993 case GL_BLEND_COLOR_EXT
:
994 if (_mesa_get_clamp_fragment_color(ctx
, ctx
->DrawBuffer
))
995 COPY_4FV(v
->value_float_4
, ctx
->Color
.BlendColor
);
997 COPY_4FV(v
->value_float_4
, ctx
->Color
.BlendColorUnclamped
);
999 case GL_ALPHA_TEST_REF
:
1000 if (_mesa_get_clamp_fragment_color(ctx
, ctx
->DrawBuffer
))
1001 v
->value_float
= ctx
->Color
.AlphaRef
;
1003 v
->value_float
= ctx
->Color
.AlphaRefUnclamped
;
1005 case GL_MAX_VERTEX_UNIFORM_VECTORS
:
1006 v
->value_int
= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxUniformComponents
/ 4;
1009 case GL_MAX_FRAGMENT_UNIFORM_VECTORS
:
1010 v
->value_int
= ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxUniformComponents
/ 4;
1013 /* GL_ARB_texture_buffer_object */
1014 case GL_TEXTURE_BUFFER_ARB
:
1015 v
->value_int
= ctx
->Texture
.BufferObject
->Name
;
1017 case GL_TEXTURE_BINDING_BUFFER_ARB
:
1018 unit
= ctx
->Texture
.CurrentUnit
;
1020 ctx
->Texture
.Unit
[unit
].CurrentTex
[TEXTURE_BUFFER_INDEX
]->Name
;
1022 case GL_TEXTURE_BUFFER_DATA_STORE_BINDING_ARB
:
1024 struct gl_buffer_object
*buf
=
1025 ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
]
1026 .CurrentTex
[TEXTURE_BUFFER_INDEX
]->BufferObject
;
1027 v
->value_int
= buf
? buf
->Name
: 0;
1030 case GL_TEXTURE_BUFFER_FORMAT_ARB
:
1031 v
->value_int
= ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
]
1032 .CurrentTex
[TEXTURE_BUFFER_INDEX
]->BufferObjectFormat
;
1035 /* GL_ARB_sampler_objects */
1036 case GL_SAMPLER_BINDING
:
1038 struct gl_sampler_object
*samp
=
1039 ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
].Sampler
;
1040 v
->value_int
= samp
? samp
->Name
: 0;
1043 /* GL_ARB_uniform_buffer_object */
1044 case GL_UNIFORM_BUFFER_BINDING
:
1045 v
->value_int
= ctx
->UniformBuffer
->Name
;
1047 /* GL_ARB_shader_storage_buffer_object */
1048 case GL_SHADER_STORAGE_BUFFER_BINDING
:
1049 v
->value_int
= ctx
->ShaderStorageBuffer
->Name
;
1051 /* GL_ARB_query_buffer_object */
1052 case GL_QUERY_BUFFER_BINDING
:
1053 v
->value_int
= ctx
->QueryBuffer
->Name
;
1055 /* GL_ARB_timer_query */
1057 if (ctx
->Driver
.GetTimestamp
) {
1058 v
->value_int64
= ctx
->Driver
.GetTimestamp(ctx
);
1061 _mesa_problem(ctx
, "driver doesn't implement GetTimestamp");
1065 case GL_DEBUG_OUTPUT
:
1066 case GL_DEBUG_OUTPUT_SYNCHRONOUS
:
1067 case GL_DEBUG_LOGGED_MESSAGES
:
1068 case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH
:
1069 case GL_DEBUG_GROUP_STACK_DEPTH
:
1070 v
->value_int
= _mesa_get_debug_state_int(ctx
, d
->pname
);
1072 /* GL_ARB_shader_atomic_counters */
1073 case GL_ATOMIC_COUNTER_BUFFER_BINDING
:
1074 if (ctx
->AtomicBuffer
) {
1075 v
->value_int
= ctx
->AtomicBuffer
->Name
;
1080 /* GL_ARB_draw_indirect */
1081 case GL_DRAW_INDIRECT_BUFFER_BINDING
:
1082 v
->value_int
= ctx
->DrawIndirectBuffer
->Name
;
1084 /* GL_ARB_indirect_parameters */
1085 case GL_PARAMETER_BUFFER_BINDING_ARB
:
1086 v
->value_int
= ctx
->ParameterBuffer
->Name
;
1088 /* GL_ARB_separate_shader_objects */
1089 case GL_PROGRAM_PIPELINE_BINDING
:
1090 if (ctx
->Pipeline
.Current
) {
1091 v
->value_int
= ctx
->Pipeline
.Current
->Name
;
1096 /* GL_ARB_compute_shader */
1097 case GL_DISPATCH_INDIRECT_BUFFER_BINDING
:
1098 v
->value_int
= ctx
->DispatchIndirectBuffer
->Name
;
1100 /* GL_ARB_multisample */
1102 v
->value_int
= _mesa_geometric_samples(ctx
->DrawBuffer
);
1104 case GL_SAMPLE_BUFFERS
:
1105 v
->value_int
= _mesa_geometric_samples(ctx
->DrawBuffer
) > 0;
1107 /* GL_ATI_meminfo & GL_NVX_gpu_memory_info */
1108 case GL_VBO_FREE_MEMORY_ATI
:
1109 case GL_TEXTURE_FREE_MEMORY_ATI
:
1110 case GL_RENDERBUFFER_FREE_MEMORY_ATI
:
1111 case GL_GPU_MEMORY_INFO_DEDICATED_VIDMEM_NVX
:
1112 case GL_GPU_MEMORY_INFO_TOTAL_AVAILABLE_MEMORY_NVX
:
1113 case GL_GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX
:
1114 case GL_GPU_MEMORY_INFO_EVICTION_COUNT_NVX
:
1115 case GL_GPU_MEMORY_INFO_EVICTED_MEMORY_NVX
:
1117 struct gl_memory_info info
;
1119 ctx
->Driver
.QueryMemoryInfo(ctx
, &info
);
1121 if (d
->pname
== GL_GPU_MEMORY_INFO_DEDICATED_VIDMEM_NVX
)
1122 v
->value_int
= info
.total_device_memory
;
1123 else if (d
->pname
== GL_GPU_MEMORY_INFO_TOTAL_AVAILABLE_MEMORY_NVX
)
1124 v
->value_int
= info
.total_device_memory
+
1125 info
.total_staging_memory
;
1126 else if (d
->pname
== GL_GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX
)
1127 v
->value_int
= info
.avail_device_memory
;
1128 else if (d
->pname
== GL_GPU_MEMORY_INFO_EVICTION_COUNT_NVX
)
1129 v
->value_int
= info
.nr_device_memory_evictions
;
1130 else if (d
->pname
== GL_GPU_MEMORY_INFO_EVICTED_MEMORY_NVX
)
1131 v
->value_int
= info
.device_memory_evicted
;
1133 /* ATI free memory enums.
1135 * Since the GPU memory is (usually) page-table based, every two
1136 * consecutive elements are equal. From the GL_ATI_meminfo
1139 * "param[0] - total memory free in the pool
1140 * param[1] - largest available free block in the pool
1141 * param[2] - total auxiliary memory free
1142 * param[3] - largest auxiliary free block"
1144 * All three (VBO, TEXTURE, RENDERBUFFER) queries return
1145 * the same numbers here.
1147 v
->value_int_4
[0] = info
.avail_device_memory
;
1148 v
->value_int_4
[1] = info
.avail_device_memory
;
1149 v
->value_int_4
[2] = info
.avail_staging_memory
;
1150 v
->value_int_4
[3] = info
.avail_staging_memory
;
1158 * Check extra constraints on a struct value_desc descriptor
1160 * If a struct value_desc has a non-NULL extra pointer, it means that
1161 * there are a number of extra constraints to check or actions to
1162 * perform. The extras is just an integer array where each integer
1163 * encode different constraints or actions.
1165 * \param ctx current context
1166 * \param func name of calling glGet*v() function for error reporting
1167 * \param d the struct value_desc that has the extra constraints
1169 * \return GL_FALSE if all of the constraints were not satisfied,
1170 * otherwise GL_TRUE.
1173 check_extra(struct gl_context
*ctx
, const char *func
, const struct value_desc
*d
)
1175 const GLuint version
= ctx
->Version
;
1176 GLboolean api_check
= GL_FALSE
;
1177 GLboolean api_found
= GL_FALSE
;
1180 for (e
= d
->extra
; *e
!= EXTRA_END
; e
++) {
1182 case EXTRA_VERSION_30
:
1183 api_check
= GL_TRUE
;
1185 api_found
= GL_TRUE
;
1187 case EXTRA_VERSION_31
:
1188 api_check
= GL_TRUE
;
1190 api_found
= GL_TRUE
;
1192 case EXTRA_VERSION_32
:
1193 api_check
= GL_TRUE
;
1195 api_found
= GL_TRUE
;
1197 case EXTRA_NEW_FRAG_CLAMP
:
1198 if (ctx
->NewState
& (_NEW_BUFFERS
| _NEW_FRAG_CLAMP
))
1199 _mesa_update_state(ctx
);
1202 api_check
= GL_TRUE
;
1203 if (ctx
->API
== API_OPENGLES2
)
1204 api_found
= GL_TRUE
;
1207 api_check
= GL_TRUE
;
1208 if (_mesa_is_gles3(ctx
))
1209 api_found
= GL_TRUE
;
1211 case EXTRA_API_ES31
:
1212 api_check
= GL_TRUE
;
1213 if (_mesa_is_gles31(ctx
))
1214 api_found
= GL_TRUE
;
1217 api_check
= GL_TRUE
;
1218 if (_mesa_is_desktop_gl(ctx
))
1219 api_found
= GL_TRUE
;
1221 case EXTRA_API_GL_CORE
:
1222 api_check
= GL_TRUE
;
1223 if (ctx
->API
== API_OPENGL_CORE
)
1224 api_found
= GL_TRUE
;
1226 case EXTRA_NEW_BUFFERS
:
1227 if (ctx
->NewState
& _NEW_BUFFERS
)
1228 _mesa_update_state(ctx
);
1230 case EXTRA_FLUSH_CURRENT
:
1231 FLUSH_CURRENT(ctx
, 0);
1233 case EXTRA_VALID_DRAW_BUFFER
:
1234 if (d
->pname
- GL_DRAW_BUFFER0_ARB
>= ctx
->Const
.MaxDrawBuffers
) {
1235 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(draw buffer %u)",
1236 func
, d
->pname
- GL_DRAW_BUFFER0_ARB
);
1240 case EXTRA_VALID_TEXTURE_UNIT
:
1241 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureCoordUnits
) {
1242 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(texture %u)",
1243 func
, ctx
->Texture
.CurrentUnit
);
1247 case EXTRA_VALID_CLIP_DISTANCE
:
1248 if (d
->pname
- GL_CLIP_DISTANCE0
>= ctx
->Const
.MaxClipPlanes
) {
1249 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(clip distance %u)",
1250 func
, d
->pname
- GL_CLIP_DISTANCE0
);
1254 case EXTRA_GLSL_130
:
1255 api_check
= GL_TRUE
;
1256 if (ctx
->Const
.GLSLVersion
>= 130)
1257 api_found
= GL_TRUE
;
1259 case EXTRA_EXT_UBO_GS
:
1260 api_check
= GL_TRUE
;
1261 if (ctx
->Extensions
.ARB_uniform_buffer_object
&&
1262 _mesa_has_geometry_shaders(ctx
))
1263 api_found
= GL_TRUE
;
1265 case EXTRA_EXT_ATOMICS_GS
:
1266 api_check
= GL_TRUE
;
1267 if (ctx
->Extensions
.ARB_shader_atomic_counters
&&
1268 _mesa_has_geometry_shaders(ctx
))
1269 api_found
= GL_TRUE
;
1271 case EXTRA_EXT_SHADER_IMAGE_GS
:
1272 api_check
= GL_TRUE
;
1273 if (ctx
->Extensions
.ARB_shader_image_load_store
&&
1274 _mesa_has_geometry_shaders(ctx
))
1275 api_found
= GL_TRUE
;
1277 case EXTRA_EXT_ATOMICS_TESS
:
1278 api_check
= GL_TRUE
;
1279 api_found
= ctx
->Extensions
.ARB_shader_atomic_counters
&&
1280 _mesa_has_tessellation(ctx
);
1282 case EXTRA_EXT_SHADER_IMAGE_TESS
:
1283 api_check
= GL_TRUE
;
1284 api_found
= ctx
->Extensions
.ARB_shader_image_load_store
&&
1285 _mesa_has_tessellation(ctx
);
1287 case EXTRA_EXT_SSBO_GS
:
1288 api_check
= GL_TRUE
;
1289 if (ctx
->Extensions
.ARB_shader_storage_buffer_object
&&
1290 _mesa_has_geometry_shaders(ctx
))
1291 api_found
= GL_TRUE
;
1293 case EXTRA_EXT_FB_NO_ATTACH_GS
:
1294 api_check
= GL_TRUE
;
1295 if (ctx
->Extensions
.ARB_framebuffer_no_attachments
&&
1296 (_mesa_is_desktop_gl(ctx
) ||
1297 _mesa_has_OES_geometry_shader(ctx
)))
1298 api_found
= GL_TRUE
;
1300 case EXTRA_EXT_ES_GS
:
1301 api_check
= GL_TRUE
;
1302 if (_mesa_has_OES_geometry_shader(ctx
))
1303 api_found
= GL_TRUE
;
1307 default: /* *e is a offset into the extension struct */
1308 api_check
= GL_TRUE
;
1309 if (*(GLboolean
*) ((char *) &ctx
->Extensions
+ *e
))
1310 api_found
= GL_TRUE
;
1315 if (api_check
&& !api_found
) {
1316 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=%s)", func
,
1317 _mesa_enum_to_string(d
->pname
));
1324 static const struct value_desc error_value
=
1325 { 0, 0, TYPE_INVALID
, NO_OFFSET
, NO_EXTRA
};
1328 * Find the struct value_desc corresponding to the enum 'pname'.
1330 * We hash the enum value to get an index into the 'table' array,
1331 * which holds the index in the 'values' array of struct value_desc.
1332 * Once we've found the entry, we do the extra checks, if any, then
1333 * look up the value and return a pointer to it.
1335 * If the value has to be computed (for example, it's the result of a
1336 * function call or we need to add 1 to it), we use the tmp 'v' to
1339 * \param func name of glGet*v() func for error reporting
1340 * \param pname the enum value we're looking up
1341 * \param p is were we return the pointer to the value
1342 * \param v a tmp union value variable in the calling glGet*v() function
1344 * \return the struct value_desc corresponding to the enum or a struct
1345 * value_desc of TYPE_INVALID if not found. This lets the calling
1346 * glGet*v() function jump right into a switch statement and
1347 * handle errors there instead of having to check for NULL.
1349 static const struct value_desc
*
1350 find_value(const char *func
, GLenum pname
, void **p
, union value
*v
)
1352 GET_CURRENT_CONTEXT(ctx
);
1353 struct gl_texture_unit
*unit
;
1355 const struct value_desc
*d
;
1359 /* We index into the table_set[] list of per-API hash tables using the API's
1360 * value in the gl_api enum. Since GLES 3 doesn't have an API_OPENGL* enum
1361 * value since it's compatible with GLES2 its entry in table_set[] is at the
1364 STATIC_ASSERT(ARRAY_SIZE(table_set
) == API_OPENGL_LAST
+ 3);
1365 if (_mesa_is_gles3(ctx
)) {
1366 api
= API_OPENGL_LAST
+ 1;
1368 if (_mesa_is_gles31(ctx
)) {
1369 api
= API_OPENGL_LAST
+ 2;
1371 mask
= ARRAY_SIZE(table(api
)) - 1;
1372 hash
= (pname
* prime_factor
);
1374 int idx
= table(api
)[hash
& mask
];
1376 /* If the enum isn't valid, the hash walk ends with index 0,
1377 * pointing to the first entry of values[] which doesn't hold
1378 * any valid enum. */
1379 if (unlikely(idx
== 0)) {
1380 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=%s)", func
,
1381 _mesa_enum_to_string(pname
));
1382 return &error_value
;
1386 if (likely(d
->pname
== pname
))
1392 if (unlikely(d
->extra
&& !check_extra(ctx
, func
, d
)))
1393 return &error_value
;
1395 switch (d
->location
) {
1397 *p
= ((char *) ctx
->DrawBuffer
+ d
->offset
);
1400 *p
= ((char *) ctx
+ d
->offset
);
1403 *p
= ((char *) ctx
->Array
.VAO
+ d
->offset
);
1406 unit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1407 *p
= ((char *) unit
+ d
->offset
);
1410 find_custom_value(ctx
, d
, v
);
1418 /* silence warning */
1419 return &error_value
;
1422 static const int transpose
[] = {
1430 _mesa_GetBooleanv(GLenum pname
, GLboolean
*params
)
1432 const struct value_desc
*d
;
1438 d
= find_value("glGetBooleanv", pname
, &p
, &v
);
1443 params
[0] = INT_TO_BOOLEAN(d
->offset
);
1448 params
[3] = FLOAT_TO_BOOLEAN(((GLfloat
*) p
)[3]);
1451 params
[2] = FLOAT_TO_BOOLEAN(((GLfloat
*) p
)[2]);
1454 params
[1] = FLOAT_TO_BOOLEAN(((GLfloat
*) p
)[1]);
1457 params
[0] = FLOAT_TO_BOOLEAN(((GLfloat
*) p
)[0]);
1460 case TYPE_DOUBLEN_2
:
1461 params
[1] = FLOAT_TO_BOOLEAN(((GLdouble
*) p
)[1]);
1463 params
[0] = FLOAT_TO_BOOLEAN(((GLdouble
*) p
)[0]);
1467 params
[3] = INT_TO_BOOLEAN(((GLint
*) p
)[3]);
1469 params
[2] = INT_TO_BOOLEAN(((GLint
*) p
)[2]);
1472 params
[1] = INT_TO_BOOLEAN(((GLint
*) p
)[1]);
1475 params
[0] = INT_TO_BOOLEAN(((GLint
*) p
)[0]);
1479 for (i
= 0; i
< v
.value_int_n
.n
; i
++)
1480 params
[i
] = INT_TO_BOOLEAN(v
.value_int_n
.ints
[i
]);
1484 params
[0] = INT64_TO_BOOLEAN(((GLint64
*) p
)[0]);
1488 params
[0] = ((GLboolean
*) p
)[0];
1492 m
= *(GLmatrix
**) p
;
1493 for (i
= 0; i
< 16; i
++)
1494 params
[i
] = FLOAT_TO_BOOLEAN(m
->m
[i
]);
1498 m
= *(GLmatrix
**) p
;
1499 for (i
= 0; i
< 16; i
++)
1500 params
[i
] = FLOAT_TO_BOOLEAN(m
->m
[transpose
[i
]]);
1511 shift
= d
->type
- TYPE_BIT_0
;
1512 params
[0] = (*(GLbitfield
*) p
>> shift
) & 1;
1518 _mesa_GetFloatv(GLenum pname
, GLfloat
*params
)
1520 const struct value_desc
*d
;
1526 d
= find_value("glGetFloatv", pname
, &p
, &v
);
1531 params
[0] = (GLfloat
) d
->offset
;
1536 params
[3] = ((GLfloat
*) p
)[3];
1539 params
[2] = ((GLfloat
*) p
)[2];
1542 params
[1] = ((GLfloat
*) p
)[1];
1545 params
[0] = ((GLfloat
*) p
)[0];
1548 case TYPE_DOUBLEN_2
:
1549 params
[1] = (GLfloat
) (((GLdouble
*) p
)[1]);
1551 params
[0] = (GLfloat
) (((GLdouble
*) p
)[0]);
1555 params
[3] = (GLfloat
) (((GLint
*) p
)[3]);
1557 params
[2] = (GLfloat
) (((GLint
*) p
)[2]);
1560 params
[1] = (GLfloat
) (((GLint
*) p
)[1]);
1563 params
[0] = (GLfloat
) (((GLint
*) p
)[0]);
1567 for (i
= 0; i
< v
.value_int_n
.n
; i
++)
1568 params
[i
] = INT_TO_FLOAT(v
.value_int_n
.ints
[i
]);
1572 params
[0] = (GLfloat
) (((GLint64
*) p
)[0]);
1576 params
[0] = BOOLEAN_TO_FLOAT(*(GLboolean
*) p
);
1580 m
= *(GLmatrix
**) p
;
1581 for (i
= 0; i
< 16; i
++)
1582 params
[i
] = m
->m
[i
];
1586 m
= *(GLmatrix
**) p
;
1587 for (i
= 0; i
< 16; i
++)
1588 params
[i
] = m
->m
[transpose
[i
]];
1599 shift
= d
->type
- TYPE_BIT_0
;
1600 params
[0] = BOOLEAN_TO_FLOAT((*(GLbitfield
*) p
>> shift
) & 1);
1606 _mesa_GetIntegerv(GLenum pname
, GLint
*params
)
1608 const struct value_desc
*d
;
1614 d
= find_value("glGetIntegerv", pname
, &p
, &v
);
1619 params
[0] = d
->offset
;
1623 params
[3] = IROUND(((GLfloat
*) p
)[3]);
1625 params
[2] = IROUND(((GLfloat
*) p
)[2]);
1627 params
[1] = IROUND(((GLfloat
*) p
)[1]);
1629 params
[0] = IROUND(((GLfloat
*) p
)[0]);
1633 params
[3] = FLOAT_TO_INT(((GLfloat
*) p
)[3]);
1635 params
[2] = FLOAT_TO_INT(((GLfloat
*) p
)[2]);
1637 params
[1] = FLOAT_TO_INT(((GLfloat
*) p
)[1]);
1639 params
[0] = FLOAT_TO_INT(((GLfloat
*) p
)[0]);
1642 case TYPE_DOUBLEN_2
:
1643 params
[1] = FLOAT_TO_INT(((GLdouble
*) p
)[1]);
1645 params
[0] = FLOAT_TO_INT(((GLdouble
*) p
)[0]);
1649 params
[3] = ((GLint
*) p
)[3];
1651 params
[2] = ((GLint
*) p
)[2];
1654 params
[1] = ((GLint
*) p
)[1];
1657 params
[0] = ((GLint
*) p
)[0];
1661 for (i
= 0; i
< v
.value_int_n
.n
; i
++)
1662 params
[i
] = v
.value_int_n
.ints
[i
];
1666 params
[0] = INT64_TO_INT(((GLint64
*) p
)[0]);
1670 params
[0] = BOOLEAN_TO_INT(*(GLboolean
*) p
);
1674 m
= *(GLmatrix
**) p
;
1675 for (i
= 0; i
< 16; i
++)
1676 params
[i
] = FLOAT_TO_INT(m
->m
[i
]);
1680 m
= *(GLmatrix
**) p
;
1681 for (i
= 0; i
< 16; i
++)
1682 params
[i
] = FLOAT_TO_INT(m
->m
[transpose
[i
]]);
1693 shift
= d
->type
- TYPE_BIT_0
;
1694 params
[0] = (*(GLbitfield
*) p
>> shift
) & 1;
1700 _mesa_GetInteger64v(GLenum pname
, GLint64
*params
)
1702 const struct value_desc
*d
;
1708 d
= find_value("glGetInteger64v", pname
, &p
, &v
);
1713 params
[0] = d
->offset
;
1717 params
[3] = IROUND64(((GLfloat
*) p
)[3]);
1719 params
[2] = IROUND64(((GLfloat
*) p
)[2]);
1721 params
[1] = IROUND64(((GLfloat
*) p
)[1]);
1723 params
[0] = IROUND64(((GLfloat
*) p
)[0]);
1727 params
[3] = FLOAT_TO_INT(((GLfloat
*) p
)[3]);
1729 params
[2] = FLOAT_TO_INT(((GLfloat
*) p
)[2]);
1731 params
[1] = FLOAT_TO_INT(((GLfloat
*) p
)[1]);
1733 params
[0] = FLOAT_TO_INT(((GLfloat
*) p
)[0]);
1736 case TYPE_DOUBLEN_2
:
1737 params
[1] = FLOAT_TO_INT(((GLdouble
*) p
)[1]);
1739 params
[0] = FLOAT_TO_INT(((GLdouble
*) p
)[0]);
1743 params
[3] = ((GLint
*) p
)[3];
1745 params
[2] = ((GLint
*) p
)[2];
1748 params
[1] = ((GLint
*) p
)[1];
1751 params
[0] = ((GLint
*) p
)[0];
1755 for (i
= 0; i
< v
.value_int_n
.n
; i
++)
1756 params
[i
] = INT_TO_BOOLEAN(v
.value_int_n
.ints
[i
]);
1760 params
[0] = ((GLint64
*) p
)[0];
1764 params
[0] = ((GLboolean
*) p
)[0];
1768 m
= *(GLmatrix
**) p
;
1769 for (i
= 0; i
< 16; i
++)
1770 params
[i
] = FLOAT_TO_INT64(m
->m
[i
]);
1774 m
= *(GLmatrix
**) p
;
1775 for (i
= 0; i
< 16; i
++)
1776 params
[i
] = FLOAT_TO_INT64(m
->m
[transpose
[i
]]);
1787 shift
= d
->type
- TYPE_BIT_0
;
1788 params
[0] = (*(GLbitfield
*) p
>> shift
) & 1;
1794 _mesa_GetDoublev(GLenum pname
, GLdouble
*params
)
1796 const struct value_desc
*d
;
1802 d
= find_value("glGetDoublev", pname
, &p
, &v
);
1807 params
[0] = d
->offset
;
1812 params
[3] = ((GLfloat
*) p
)[3];
1815 params
[2] = ((GLfloat
*) p
)[2];
1818 params
[1] = ((GLfloat
*) p
)[1];
1821 params
[0] = ((GLfloat
*) p
)[0];
1824 case TYPE_DOUBLEN_2
:
1825 params
[1] = ((GLdouble
*) p
)[1];
1827 params
[0] = ((GLdouble
*) p
)[0];
1831 params
[3] = ((GLint
*) p
)[3];
1833 params
[2] = ((GLint
*) p
)[2];
1836 params
[1] = ((GLint
*) p
)[1];
1839 params
[0] = ((GLint
*) p
)[0];
1843 for (i
= 0; i
< v
.value_int_n
.n
; i
++)
1844 params
[i
] = v
.value_int_n
.ints
[i
];
1848 params
[0] = (GLdouble
) (((GLint64
*) p
)[0]);
1852 params
[0] = *(GLboolean
*) p
;
1856 m
= *(GLmatrix
**) p
;
1857 for (i
= 0; i
< 16; i
++)
1858 params
[i
] = m
->m
[i
];
1862 m
= *(GLmatrix
**) p
;
1863 for (i
= 0; i
< 16; i
++)
1864 params
[i
] = m
->m
[transpose
[i
]];
1875 shift
= d
->type
- TYPE_BIT_0
;
1876 params
[0] = (*(GLbitfield
*) p
>> shift
) & 1;
1882 * Convert a GL texture binding enum such as GL_TEXTURE_BINDING_2D
1883 * into the corresponding Mesa texture target index.
1884 * \return TEXTURE_x_INDEX or -1 if binding is invalid
1887 tex_binding_to_index(const struct gl_context
*ctx
, GLenum binding
)
1890 case GL_TEXTURE_BINDING_1D
:
1891 return _mesa_is_desktop_gl(ctx
) ? TEXTURE_1D_INDEX
: -1;
1892 case GL_TEXTURE_BINDING_2D
:
1893 return TEXTURE_2D_INDEX
;
1894 case GL_TEXTURE_BINDING_3D
:
1895 return ctx
->API
!= API_OPENGLES
? TEXTURE_3D_INDEX
: -1;
1896 case GL_TEXTURE_BINDING_CUBE_MAP
:
1897 return ctx
->Extensions
.ARB_texture_cube_map
1898 ? TEXTURE_CUBE_INDEX
: -1;
1899 case GL_TEXTURE_BINDING_RECTANGLE
:
1900 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.NV_texture_rectangle
1901 ? TEXTURE_RECT_INDEX
: -1;
1902 case GL_TEXTURE_BINDING_1D_ARRAY
:
1903 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
1904 ? TEXTURE_1D_ARRAY_INDEX
: -1;
1905 case GL_TEXTURE_BINDING_2D_ARRAY
:
1906 return (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
)
1907 || _mesa_is_gles3(ctx
)
1908 ? TEXTURE_2D_ARRAY_INDEX
: -1;
1909 case GL_TEXTURE_BINDING_BUFFER
:
1910 return ctx
->API
== API_OPENGL_CORE
&&
1911 ctx
->Extensions
.ARB_texture_buffer_object
?
1912 TEXTURE_BUFFER_INDEX
: -1;
1913 case GL_TEXTURE_BINDING_CUBE_MAP_ARRAY
:
1914 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_cube_map_array
1915 ? TEXTURE_CUBE_ARRAY_INDEX
: -1;
1916 case GL_TEXTURE_BINDING_2D_MULTISAMPLE
:
1917 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_multisample
1918 ? TEXTURE_2D_MULTISAMPLE_INDEX
: -1;
1919 case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY
:
1920 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_multisample
1921 ? TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX
: -1;
1927 static enum value_type
1928 find_value_indexed(const char *func
, GLenum pname
, GLuint index
, union value
*v
)
1930 GET_CURRENT_CONTEXT(ctx
);
1935 if (index
>= ctx
->Const
.MaxDrawBuffers
)
1937 if (!ctx
->Extensions
.EXT_draw_buffers2
)
1939 v
->value_int
= (ctx
->Color
.BlendEnabled
>> index
) & 1;
1944 case GL_BLEND_SRC_RGB
:
1945 if (index
>= ctx
->Const
.MaxDrawBuffers
)
1947 if (!ctx
->Extensions
.ARB_draw_buffers_blend
)
1949 v
->value_int
= ctx
->Color
.Blend
[index
].SrcRGB
;
1951 case GL_BLEND_SRC_ALPHA
:
1952 if (index
>= ctx
->Const
.MaxDrawBuffers
)
1954 if (!ctx
->Extensions
.ARB_draw_buffers_blend
)
1956 v
->value_int
= ctx
->Color
.Blend
[index
].SrcA
;
1960 case GL_BLEND_DST_RGB
:
1961 if (index
>= ctx
->Const
.MaxDrawBuffers
)
1963 if (!ctx
->Extensions
.ARB_draw_buffers_blend
)
1965 v
->value_int
= ctx
->Color
.Blend
[index
].DstRGB
;
1967 case GL_BLEND_DST_ALPHA
:
1968 if (index
>= ctx
->Const
.MaxDrawBuffers
)
1970 if (!ctx
->Extensions
.ARB_draw_buffers_blend
)
1972 v
->value_int
= ctx
->Color
.Blend
[index
].DstA
;
1974 case GL_BLEND_EQUATION_RGB
:
1975 if (index
>= ctx
->Const
.MaxDrawBuffers
)
1977 if (!ctx
->Extensions
.ARB_draw_buffers_blend
)
1979 v
->value_int
= ctx
->Color
.Blend
[index
].EquationRGB
;
1981 case GL_BLEND_EQUATION_ALPHA
:
1982 if (index
>= ctx
->Const
.MaxDrawBuffers
)
1984 if (!ctx
->Extensions
.ARB_draw_buffers_blend
)
1986 v
->value_int
= ctx
->Color
.Blend
[index
].EquationA
;
1989 case GL_COLOR_WRITEMASK
:
1990 if (index
>= ctx
->Const
.MaxDrawBuffers
)
1992 if (!ctx
->Extensions
.EXT_draw_buffers2
)
1994 v
->value_int_4
[0] = ctx
->Color
.ColorMask
[index
][RCOMP
] ? 1 : 0;
1995 v
->value_int_4
[1] = ctx
->Color
.ColorMask
[index
][GCOMP
] ? 1 : 0;
1996 v
->value_int_4
[2] = ctx
->Color
.ColorMask
[index
][BCOMP
] ? 1 : 0;
1997 v
->value_int_4
[3] = ctx
->Color
.ColorMask
[index
][ACOMP
] ? 1 : 0;
2000 case GL_SCISSOR_BOX
:
2001 if (index
>= ctx
->Const
.MaxViewports
)
2003 v
->value_int_4
[0] = ctx
->Scissor
.ScissorArray
[index
].X
;
2004 v
->value_int_4
[1] = ctx
->Scissor
.ScissorArray
[index
].Y
;
2005 v
->value_int_4
[2] = ctx
->Scissor
.ScissorArray
[index
].Width
;
2006 v
->value_int_4
[3] = ctx
->Scissor
.ScissorArray
[index
].Height
;
2010 if (index
>= ctx
->Const
.MaxViewports
)
2012 v
->value_float_4
[0] = ctx
->ViewportArray
[index
].X
;
2013 v
->value_float_4
[1] = ctx
->ViewportArray
[index
].Y
;
2014 v
->value_float_4
[2] = ctx
->ViewportArray
[index
].Width
;
2015 v
->value_float_4
[3] = ctx
->ViewportArray
[index
].Height
;
2016 return TYPE_FLOAT_4
;
2018 case GL_DEPTH_RANGE
:
2019 if (index
>= ctx
->Const
.MaxViewports
)
2021 v
->value_double_2
[0] = ctx
->ViewportArray
[index
].Near
;
2022 v
->value_double_2
[1] = ctx
->ViewportArray
[index
].Far
;
2023 return TYPE_DOUBLEN_2
;
2025 case GL_TRANSFORM_FEEDBACK_BUFFER_START
:
2026 if (index
>= ctx
->Const
.MaxTransformFeedbackBuffers
)
2028 if (!ctx
->Extensions
.EXT_transform_feedback
)
2030 v
->value_int64
= ctx
->TransformFeedback
.CurrentObject
->Offset
[index
];
2033 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE
:
2034 if (index
>= ctx
->Const
.MaxTransformFeedbackBuffers
)
2036 if (!ctx
->Extensions
.EXT_transform_feedback
)
2039 = ctx
->TransformFeedback
.CurrentObject
->RequestedSize
[index
];
2042 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING
:
2043 if (index
>= ctx
->Const
.MaxTransformFeedbackBuffers
)
2045 if (!ctx
->Extensions
.EXT_transform_feedback
)
2047 v
->value_int
= ctx
->TransformFeedback
.CurrentObject
->BufferNames
[index
];
2050 case GL_UNIFORM_BUFFER_BINDING
:
2051 if (index
>= ctx
->Const
.MaxUniformBufferBindings
)
2053 if (!ctx
->Extensions
.ARB_uniform_buffer_object
)
2055 v
->value_int
= ctx
->UniformBufferBindings
[index
].BufferObject
->Name
;
2058 case GL_UNIFORM_BUFFER_START
:
2059 if (index
>= ctx
->Const
.MaxUniformBufferBindings
)
2061 if (!ctx
->Extensions
.ARB_uniform_buffer_object
)
2063 v
->value_int
= ctx
->UniformBufferBindings
[index
].Offset
< 0 ? 0 :
2064 ctx
->UniformBufferBindings
[index
].Offset
;
2067 case GL_UNIFORM_BUFFER_SIZE
:
2068 if (index
>= ctx
->Const
.MaxUniformBufferBindings
)
2070 if (!ctx
->Extensions
.ARB_uniform_buffer_object
)
2072 v
->value_int
= ctx
->UniformBufferBindings
[index
].Size
< 0 ? 0 :
2073 ctx
->UniformBufferBindings
[index
].Size
;
2076 /* ARB_shader_storage_buffer_object */
2077 case GL_SHADER_STORAGE_BUFFER_BINDING
:
2078 if (!ctx
->Extensions
.ARB_shader_storage_buffer_object
)
2080 if (index
>= ctx
->Const
.MaxShaderStorageBufferBindings
)
2082 v
->value_int
= ctx
->ShaderStorageBufferBindings
[index
].BufferObject
->Name
;
2085 case GL_SHADER_STORAGE_BUFFER_START
:
2086 if (!ctx
->Extensions
.ARB_shader_storage_buffer_object
)
2088 if (index
>= ctx
->Const
.MaxShaderStorageBufferBindings
)
2090 v
->value_int
= ctx
->ShaderStorageBufferBindings
[index
].Offset
< 0 ? 0 :
2091 ctx
->ShaderStorageBufferBindings
[index
].Offset
;
2094 case GL_SHADER_STORAGE_BUFFER_SIZE
:
2095 if (!ctx
->Extensions
.ARB_shader_storage_buffer_object
)
2097 if (index
>= ctx
->Const
.MaxShaderStorageBufferBindings
)
2099 v
->value_int
= ctx
->ShaderStorageBufferBindings
[index
].Size
< 0 ? 0 :
2100 ctx
->ShaderStorageBufferBindings
[index
].Size
;
2103 /* ARB_texture_multisample / GL3.2 */
2104 case GL_SAMPLE_MASK_VALUE
:
2107 if (!ctx
->Extensions
.ARB_texture_multisample
)
2109 v
->value_int
= ctx
->Multisample
.SampleMaskValue
;
2112 case GL_ATOMIC_COUNTER_BUFFER_BINDING
:
2113 if (!ctx
->Extensions
.ARB_shader_atomic_counters
)
2115 if (index
>= ctx
->Const
.MaxAtomicBufferBindings
)
2117 v
->value_int
= ctx
->AtomicBufferBindings
[index
].BufferObject
->Name
;
2120 case GL_ATOMIC_COUNTER_BUFFER_START
:
2121 if (!ctx
->Extensions
.ARB_shader_atomic_counters
)
2123 if (index
>= ctx
->Const
.MaxAtomicBufferBindings
)
2125 v
->value_int64
= ctx
->AtomicBufferBindings
[index
].Offset
;
2128 case GL_ATOMIC_COUNTER_BUFFER_SIZE
:
2129 if (!ctx
->Extensions
.ARB_shader_atomic_counters
)
2131 if (index
>= ctx
->Const
.MaxAtomicBufferBindings
)
2133 v
->value_int64
= ctx
->AtomicBufferBindings
[index
].Size
;
2136 case GL_VERTEX_BINDING_DIVISOR
:
2137 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_instanced_arrays
) &&
2138 !_mesa_is_gles31(ctx
))
2140 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
)
2142 v
->value_int
= ctx
->Array
.VAO
->VertexBinding
[VERT_ATTRIB_GENERIC(index
)].InstanceDivisor
;
2145 case GL_VERTEX_BINDING_OFFSET
:
2146 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles31(ctx
))
2148 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
)
2150 v
->value_int
= ctx
->Array
.VAO
->VertexBinding
[VERT_ATTRIB_GENERIC(index
)].Offset
;
2153 case GL_VERTEX_BINDING_STRIDE
:
2154 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles31(ctx
))
2156 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
)
2158 v
->value_int
= ctx
->Array
.VAO
->VertexBinding
[VERT_ATTRIB_GENERIC(index
)].Stride
;
2161 case GL_VERTEX_BINDING_BUFFER
:
2162 if (ctx
->API
== API_OPENGLES2
&& ctx
->Version
< 31)
2164 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
)
2166 v
->value_int
= ctx
->Array
.VAO
->VertexBinding
[VERT_ATTRIB_GENERIC(index
)].BufferObj
->Name
;
2169 /* ARB_shader_image_load_store */
2170 case GL_IMAGE_BINDING_NAME
: {
2171 struct gl_texture_object
*t
;
2173 if (!ctx
->Extensions
.ARB_shader_image_load_store
)
2175 if (index
>= ctx
->Const
.MaxImageUnits
)
2178 t
= ctx
->ImageUnits
[index
].TexObj
;
2179 v
->value_int
= (t
? t
->Name
: 0);
2183 case GL_IMAGE_BINDING_LEVEL
:
2184 if (!ctx
->Extensions
.ARB_shader_image_load_store
)
2186 if (index
>= ctx
->Const
.MaxImageUnits
)
2189 v
->value_int
= ctx
->ImageUnits
[index
].Level
;
2192 case GL_IMAGE_BINDING_LAYERED
:
2193 if (!ctx
->Extensions
.ARB_shader_image_load_store
)
2195 if (index
>= ctx
->Const
.MaxImageUnits
)
2198 v
->value_int
= ctx
->ImageUnits
[index
].Layered
;
2201 case GL_IMAGE_BINDING_LAYER
:
2202 if (!ctx
->Extensions
.ARB_shader_image_load_store
)
2204 if (index
>= ctx
->Const
.MaxImageUnits
)
2207 v
->value_int
= ctx
->ImageUnits
[index
].Layer
;
2210 case GL_IMAGE_BINDING_ACCESS
:
2211 if (!ctx
->Extensions
.ARB_shader_image_load_store
)
2213 if (index
>= ctx
->Const
.MaxImageUnits
)
2216 v
->value_int
= ctx
->ImageUnits
[index
].Access
;
2219 case GL_IMAGE_BINDING_FORMAT
:
2220 if (!ctx
->Extensions
.ARB_shader_image_load_store
)
2222 if (index
>= ctx
->Const
.MaxImageUnits
)
2225 v
->value_int
= ctx
->ImageUnits
[index
].Format
;
2228 /* ARB_direct_state_access */
2229 case GL_TEXTURE_BINDING_1D
:
2230 case GL_TEXTURE_BINDING_1D_ARRAY
:
2231 case GL_TEXTURE_BINDING_2D
:
2232 case GL_TEXTURE_BINDING_2D_ARRAY
:
2233 case GL_TEXTURE_BINDING_2D_MULTISAMPLE
:
2234 case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY
:
2235 case GL_TEXTURE_BINDING_3D
:
2236 case GL_TEXTURE_BINDING_BUFFER
:
2237 case GL_TEXTURE_BINDING_CUBE_MAP
:
2238 case GL_TEXTURE_BINDING_CUBE_MAP_ARRAY
:
2239 case GL_TEXTURE_BINDING_RECTANGLE
: {
2242 if (ctx
->API
!= API_OPENGL_CORE
)
2244 target
= tex_binding_to_index(ctx
, pname
);
2247 if (index
>= _mesa_max_tex_unit(ctx
))
2250 v
->value_int
= ctx
->Texture
.Unit
[index
].CurrentTex
[target
]->Name
;
2254 case GL_SAMPLER_BINDING
: {
2255 struct gl_sampler_object
*samp
;
2257 if (ctx
->API
!= API_OPENGL_CORE
)
2259 if (index
>= _mesa_max_tex_unit(ctx
))
2262 samp
= ctx
->Texture
.Unit
[index
].Sampler
;
2263 v
->value_int
= samp
? samp
->Name
: 0;
2267 case GL_MAX_COMPUTE_WORK_GROUP_COUNT
:
2268 if (!_mesa_has_compute_shaders(ctx
))
2272 v
->value_int
= ctx
->Const
.MaxComputeWorkGroupCount
[index
];
2275 case GL_MAX_COMPUTE_WORK_GROUP_SIZE
:
2276 if (!_mesa_has_compute_shaders(ctx
))
2280 v
->value_int
= ctx
->Const
.MaxComputeWorkGroupSize
[index
];
2285 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=%s)", func
,
2286 _mesa_enum_to_string(pname
));
2287 return TYPE_INVALID
;
2289 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(pname=%s)", func
,
2290 _mesa_enum_to_string(pname
));
2291 return TYPE_INVALID
;
2295 _mesa_GetBooleani_v( GLenum pname
, GLuint index
, GLboolean
*params
)
2298 enum value_type type
=
2299 find_value_indexed("glGetBooleani_v", pname
, index
, &v
);
2303 params
[0] = INT_TO_BOOLEAN(v
.value_int
);
2306 params
[0] = INT_TO_BOOLEAN(v
.value_int_4
[0]);
2307 params
[1] = INT_TO_BOOLEAN(v
.value_int_4
[1]);
2308 params
[2] = INT_TO_BOOLEAN(v
.value_int_4
[2]);
2309 params
[3] = INT_TO_BOOLEAN(v
.value_int_4
[3]);
2312 params
[0] = INT64_TO_BOOLEAN(v
.value_int64
);
2315 ; /* nothing - GL error was recorded */
2320 _mesa_GetIntegeri_v( GLenum pname
, GLuint index
, GLint
*params
)
2323 enum value_type type
=
2324 find_value_indexed("glGetIntegeri_v", pname
, index
, &v
);
2329 params
[3] = IROUND(v
.value_float_4
[3]);
2332 params
[2] = IROUND(v
.value_float_4
[2]);
2335 params
[1] = IROUND(v
.value_float_4
[1]);
2338 params
[0] = IROUND(v
.value_float_4
[0]);
2341 case TYPE_DOUBLEN_2
:
2342 params
[1] = IROUND(v
.value_double_2
[1]);
2344 params
[0] = IROUND(v
.value_double_2
[0]);
2348 params
[0] = v
.value_int
;
2351 params
[0] = v
.value_int_4
[0];
2352 params
[1] = v
.value_int_4
[1];
2353 params
[2] = v
.value_int_4
[2];
2354 params
[3] = v
.value_int_4
[3];
2357 params
[0] = INT64_TO_INT(v
.value_int64
);
2360 ; /* nothing - GL error was recorded */
2365 _mesa_GetInteger64i_v( GLenum pname
, GLuint index
, GLint64
*params
)
2368 enum value_type type
=
2369 find_value_indexed("glGetInteger64i_v", pname
, index
, &v
);
2373 params
[0] = v
.value_int
;
2376 params
[0] = v
.value_int_4
[0];
2377 params
[1] = v
.value_int_4
[1];
2378 params
[2] = v
.value_int_4
[2];
2379 params
[3] = v
.value_int_4
[3];
2382 params
[0] = v
.value_int64
;
2385 ; /* nothing - GL error was recorded */
2390 _mesa_GetFloati_v(GLenum pname
, GLuint index
, GLfloat
*params
)
2395 enum value_type type
=
2396 find_value_indexed("glGetFloati_v", pname
, index
, &v
);
2401 params
[3] = v
.value_float_4
[3];
2404 params
[2] = v
.value_float_4
[2];
2407 params
[1] = v
.value_float_4
[1];
2410 params
[0] = v
.value_float_4
[0];
2413 case TYPE_DOUBLEN_2
:
2414 params
[1] = (GLfloat
) v
.value_double_2
[1];
2416 params
[0] = (GLfloat
) v
.value_double_2
[0];
2420 params
[3] = (GLfloat
) v
.value_int_4
[3];
2422 params
[2] = (GLfloat
) v
.value_int_4
[2];
2425 params
[1] = (GLfloat
) v
.value_int_4
[1];
2428 params
[0] = (GLfloat
) v
.value_int_4
[0];
2432 for (i
= 0; i
< v
.value_int_n
.n
; i
++)
2433 params
[i
] = INT_TO_FLOAT(v
.value_int_n
.ints
[i
]);
2437 params
[0] = (GLfloat
) v
.value_int64
;
2441 params
[0] = BOOLEAN_TO_FLOAT(v
.value_bool
);
2445 m
= *(GLmatrix
**) &v
;
2446 for (i
= 0; i
< 16; i
++)
2447 params
[i
] = m
->m
[i
];
2451 m
= *(GLmatrix
**) &v
;
2452 for (i
= 0; i
< 16; i
++)
2453 params
[i
] = m
->m
[transpose
[i
]];
2462 _mesa_GetDoublei_v(GLenum pname
, GLuint index
, GLdouble
*params
)
2467 enum value_type type
=
2468 find_value_indexed("glGetDoublei_v", pname
, index
, &v
);
2473 params
[3] = (GLdouble
) v
.value_float_4
[3];
2476 params
[2] = (GLdouble
) v
.value_float_4
[2];
2479 params
[1] = (GLdouble
) v
.value_float_4
[1];
2482 params
[0] = (GLdouble
) v
.value_float_4
[0];
2485 case TYPE_DOUBLEN_2
:
2486 params
[1] = v
.value_double_2
[1];
2488 params
[0] = v
.value_double_2
[0];
2492 params
[3] = (GLdouble
) v
.value_int_4
[3];
2494 params
[2] = (GLdouble
) v
.value_int_4
[2];
2497 params
[1] = (GLdouble
) v
.value_int_4
[1];
2500 params
[0] = (GLdouble
) v
.value_int_4
[0];
2504 for (i
= 0; i
< v
.value_int_n
.n
; i
++)
2505 params
[i
] = (GLdouble
) INT_TO_FLOAT(v
.value_int_n
.ints
[i
]);
2509 params
[0] = (GLdouble
) v
.value_int64
;
2513 params
[0] = (GLdouble
) BOOLEAN_TO_FLOAT(v
.value_bool
);
2517 m
= *(GLmatrix
**) &v
;
2518 for (i
= 0; i
< 16; i
++)
2519 params
[i
] = (GLdouble
) m
->m
[i
];
2523 m
= *(GLmatrix
**) &v
;
2524 for (i
= 0; i
< 16; i
++)
2525 params
[i
] = (GLdouble
) m
->m
[transpose
[i
]];
2534 _mesa_GetFixedv(GLenum pname
, GLfixed
*params
)
2536 const struct value_desc
*d
;
2542 d
= find_value("glGetDoublev", pname
, &p
, &v
);
2547 params
[0] = INT_TO_FIXED(d
->offset
);
2552 params
[3] = FLOAT_TO_FIXED(((GLfloat
*) p
)[3]);
2555 params
[2] = FLOAT_TO_FIXED(((GLfloat
*) p
)[2]);
2558 params
[1] = FLOAT_TO_FIXED(((GLfloat
*) p
)[1]);
2561 params
[0] = FLOAT_TO_FIXED(((GLfloat
*) p
)[0]);
2564 case TYPE_DOUBLEN_2
:
2565 params
[1] = FLOAT_TO_FIXED(((GLdouble
*) p
)[1]);
2567 params
[0] = FLOAT_TO_FIXED(((GLdouble
*) p
)[0]);
2571 params
[3] = INT_TO_FIXED(((GLint
*) p
)[3]);
2573 params
[2] = INT_TO_FIXED(((GLint
*) p
)[2]);
2576 params
[1] = INT_TO_FIXED(((GLint
*) p
)[1]);
2579 params
[0] = INT_TO_FIXED(((GLint
*) p
)[0]);
2583 for (i
= 0; i
< v
.value_int_n
.n
; i
++)
2584 params
[i
] = INT_TO_FIXED(v
.value_int_n
.ints
[i
]);
2588 params
[0] = ((GLint64
*) p
)[0];
2592 params
[0] = BOOLEAN_TO_FIXED(((GLboolean
*) p
)[0]);
2596 m
= *(GLmatrix
**) p
;
2597 for (i
= 0; i
< 16; i
++)
2598 params
[i
] = FLOAT_TO_FIXED(m
->m
[i
]);
2602 m
= *(GLmatrix
**) p
;
2603 for (i
= 0; i
< 16; i
++)
2604 params
[i
] = FLOAT_TO_FIXED(m
->m
[transpose
[i
]]);
2615 shift
= d
->type
- TYPE_BIT_0
;
2616 params
[0] = BOOLEAN_TO_FIXED((*(GLbitfield
*) p
>> shift
) & 1);