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)
126 enum value_location
{
147 EXTRA_NEW_FRAG_CLAMP
,
148 EXTRA_VALID_DRAW_BUFFER
,
149 EXTRA_VALID_TEXTURE_UNIT
,
150 EXTRA_VALID_CLIP_DISTANCE
,
154 EXTRA_EXT_ATOMICS_GS
,
155 EXTRA_EXT_SHADER_IMAGE_GS
,
156 EXTRA_EXT_ATOMICS_TESS
,
157 EXTRA_EXT_SHADER_IMAGE_TESS
,
159 EXTRA_EXT_FB_NO_ATTACH_GS
,
163 #define NO_EXTRA NULL
168 GLubyte location
; /**< enum value_location */
169 GLubyte type
; /**< enum value_type */
176 GLfloat value_float_4
[4];
177 GLdouble value_double_2
[2];
178 GLmatrix
*value_matrix
;
180 GLint value_int_4
[4];
184 /* Sigh, see GL_COMPRESSED_TEXTURE_FORMATS_ARB handling */
188 GLboolean value_bool
;
191 #define BUFFER_FIELD(field, type) \
192 LOC_BUFFER, type, offsetof(struct gl_framebuffer, field)
193 #define CONTEXT_FIELD(field, type) \
194 LOC_CONTEXT, type, offsetof(struct gl_context, field)
195 #define ARRAY_FIELD(field, type) \
196 LOC_ARRAY, type, offsetof(struct gl_vertex_array_object, field)
197 #undef CONST /* already defined through windows.h */
198 #define CONST(value) \
199 LOC_CONTEXT, TYPE_CONST, value
201 #define BUFFER_INT(field) BUFFER_FIELD(field, TYPE_INT)
202 #define BUFFER_ENUM(field) BUFFER_FIELD(field, TYPE_ENUM)
203 #define BUFFER_BOOL(field) BUFFER_FIELD(field, TYPE_BOOLEAN)
205 #define CONTEXT_INT(field) CONTEXT_FIELD(field, TYPE_INT)
206 #define CONTEXT_INT2(field) CONTEXT_FIELD(field, TYPE_INT_2)
207 #define CONTEXT_INT64(field) CONTEXT_FIELD(field, TYPE_INT64)
208 #define CONTEXT_ENUM(field) CONTEXT_FIELD(field, TYPE_ENUM)
209 #define CONTEXT_ENUM2(field) CONTEXT_FIELD(field, TYPE_ENUM_2)
210 #define CONTEXT_BOOL(field) CONTEXT_FIELD(field, TYPE_BOOLEAN)
211 #define CONTEXT_BIT0(field) CONTEXT_FIELD(field, TYPE_BIT_0)
212 #define CONTEXT_BIT1(field) CONTEXT_FIELD(field, TYPE_BIT_1)
213 #define CONTEXT_BIT2(field) CONTEXT_FIELD(field, TYPE_BIT_2)
214 #define CONTEXT_BIT3(field) CONTEXT_FIELD(field, TYPE_BIT_3)
215 #define CONTEXT_BIT4(field) CONTEXT_FIELD(field, TYPE_BIT_4)
216 #define CONTEXT_BIT5(field) CONTEXT_FIELD(field, TYPE_BIT_5)
217 #define CONTEXT_BIT6(field) CONTEXT_FIELD(field, TYPE_BIT_6)
218 #define CONTEXT_BIT7(field) CONTEXT_FIELD(field, TYPE_BIT_7)
219 #define CONTEXT_FLOAT(field) CONTEXT_FIELD(field, TYPE_FLOAT)
220 #define CONTEXT_FLOAT2(field) CONTEXT_FIELD(field, TYPE_FLOAT_2)
221 #define CONTEXT_FLOAT3(field) CONTEXT_FIELD(field, TYPE_FLOAT_3)
222 #define CONTEXT_FLOAT4(field) CONTEXT_FIELD(field, TYPE_FLOAT_4)
223 #define CONTEXT_FLOAT8(field) CONTEXT_FIELD(field, TYPE_FLOAT_8)
224 #define CONTEXT_MATRIX(field) CONTEXT_FIELD(field, TYPE_MATRIX)
225 #define CONTEXT_MATRIX_T(field) CONTEXT_FIELD(field, TYPE_MATRIX_T)
227 #define ARRAY_INT(field) ARRAY_FIELD(field, TYPE_INT)
228 #define ARRAY_ENUM(field) ARRAY_FIELD(field, TYPE_ENUM)
229 #define ARRAY_BOOL(field) ARRAY_FIELD(field, TYPE_BOOLEAN)
232 offsetof(struct gl_extensions, f)
234 #define EXTRA_EXT(e) \
235 static const int extra_##e[] = { \
239 #define EXTRA_EXT2(e1, e2) \
240 static const int extra_##e1##_##e2[] = { \
241 EXT(e1), EXT(e2), EXTRA_END \
244 /* The 'extra' mechanism is a way to specify extra checks (such as
245 * extensions or specific gl versions) or actions (flush current, new
246 * buffers) that we need to do before looking up an enum. We need to
247 * declare them all up front so we can refer to them in the value_desc
250 * Each EXTRA_ will be executed. For EXTRA_* enums of extensions and API
251 * versions, listing multiple ones in an array means an error will be thrown
252 * only if none of them are available. If you need to check for "AND"
253 * behavior, you would need to make a custom EXTRA_ enum.
256 static const int extra_new_buffers
[] = {
261 static const int extra_new_frag_clamp
[] = {
262 EXTRA_NEW_FRAG_CLAMP
,
266 static const int extra_valid_draw_buffer
[] = {
267 EXTRA_VALID_DRAW_BUFFER
,
271 static const int extra_valid_texture_unit
[] = {
272 EXTRA_VALID_TEXTURE_UNIT
,
276 static const int extra_valid_clip_distance
[] = {
277 EXTRA_VALID_CLIP_DISTANCE
,
281 static const int extra_flush_current_valid_texture_unit
[] = {
283 EXTRA_VALID_TEXTURE_UNIT
,
287 static const int extra_flush_current
[] = {
292 static const int extra_EXT_texture_integer_and_new_buffers
[] = {
293 EXT(EXT_texture_integer
),
298 static const int extra_GLSL_130_es3
[] = {
304 static const int extra_texture_buffer_object
[] = {
307 EXT(ARB_texture_buffer_object
),
311 static const int extra_ARB_transform_feedback2_api_es3
[] = {
312 EXT(ARB_transform_feedback2
),
317 static const int extra_ARB_uniform_buffer_object_and_geometry_shader
[] = {
322 static const int extra_ARB_ES2_compatibility_api_es2
[] = {
323 EXT(ARB_ES2_compatibility
),
328 static const int extra_ARB_ES3_compatibility_api_es3
[] = {
329 EXT(ARB_ES3_compatibility
),
334 static const int extra_EXT_framebuffer_sRGB_and_new_buffers
[] = {
335 EXT(EXT_framebuffer_sRGB
),
340 static const int extra_EXT_packed_float
[] = {
341 EXT(EXT_packed_float
),
346 static const int extra_EXT_texture_array_es3
[] = {
347 EXT(EXT_texture_array
),
352 static const int extra_ARB_shader_atomic_counters_and_geometry_shader
[] = {
353 EXTRA_EXT_ATOMICS_GS
,
357 static const int extra_ARB_shader_image_load_store_and_geometry_shader
[] = {
358 EXTRA_EXT_SHADER_IMAGE_GS
,
362 static const int extra_ARB_shader_atomic_counters_and_tessellation
[] = {
363 EXTRA_EXT_ATOMICS_TESS
,
367 static const int extra_ARB_shader_image_load_store_and_tessellation
[] = {
368 EXTRA_EXT_SHADER_IMAGE_TESS
,
372 /* HACK: remove when ARB_compute_shader is actually supported */
373 static const int extra_ARB_compute_shader_es31
[] = {
374 EXT(ARB_compute_shader
),
379 static const int extra_ARB_shader_storage_buffer_object_es31
[] = {
380 EXT(ARB_shader_storage_buffer_object
),
385 static const int extra_ARB_shader_storage_buffer_object_and_geometry_shader
[] = {
390 static const int extra_ARB_shader_image_load_store_shader_storage_buffer_object_es31
[] = {
391 EXT(ARB_shader_image_load_store
),
392 EXT(ARB_shader_storage_buffer_object
),
397 static const int extra_ARB_framebuffer_no_attachments_and_geometry_shader
[] = {
398 EXTRA_EXT_FB_NO_ATTACH_GS
,
402 static const int extra_ARB_viewport_array_or_oes_geometry_shader
[] = {
403 EXT(ARB_viewport_array
),
408 static const int extra_ARB_viewport_array_or_oes_viewport_array
[] = {
409 EXT(ARB_viewport_array
),
410 EXT(OES_viewport_array
),
414 static const int extra_ARB_gpu_shader5_or_oes_geometry_shader
[] = {
415 EXT(ARB_gpu_shader5
),
420 static const int extra_ARB_gpu_shader5_or_OES_sample_variables
[] = {
421 EXT(ARB_gpu_shader5
),
422 EXT(OES_sample_variables
),
426 static const int extra_ES32
[] = {
427 EXT(ARB_ES3_2_compatibility
),
432 static const int extra_KHR_robustness_or_GL
[] = {
439 static const int extra_INTEL_conservative_rasterization
[] = {
440 EXT(INTEL_conservative_rasterization
),
444 EXTRA_EXT(ARB_texture_cube_map
);
445 EXTRA_EXT(EXT_texture_array
);
446 EXTRA_EXT(NV_fog_distance
);
447 EXTRA_EXT(EXT_texture_filter_anisotropic
);
448 EXTRA_EXT(NV_point_sprite
);
449 EXTRA_EXT(NV_texture_rectangle
);
450 EXTRA_EXT(EXT_stencil_two_side
);
451 EXTRA_EXT(EXT_depth_bounds_test
);
452 EXTRA_EXT(ARB_depth_clamp
);
453 EXTRA_EXT(ATI_fragment_shader
);
454 EXTRA_EXT(EXT_provoking_vertex
);
455 EXTRA_EXT(ARB_fragment_shader
);
456 EXTRA_EXT(ARB_fragment_program
);
457 EXTRA_EXT2(ARB_framebuffer_object
, EXT_framebuffer_multisample
);
458 EXTRA_EXT(ARB_seamless_cube_map
);
460 EXTRA_EXT(ARB_vertex_shader
);
461 EXTRA_EXT(EXT_transform_feedback
);
462 EXTRA_EXT(ARB_transform_feedback3
);
463 EXTRA_EXT(EXT_pixel_buffer_object
);
464 EXTRA_EXT(ARB_vertex_program
);
465 EXTRA_EXT2(NV_point_sprite
, ARB_point_sprite
);
466 EXTRA_EXT2(ARB_vertex_program
, ARB_fragment_program
);
467 EXTRA_EXT(ARB_color_buffer_float
);
468 EXTRA_EXT(EXT_framebuffer_sRGB
);
469 EXTRA_EXT(OES_EGL_image_external
);
470 EXTRA_EXT(ARB_blend_func_extended
);
471 EXTRA_EXT(ARB_uniform_buffer_object
);
472 EXTRA_EXT(ARB_timer_query
);
473 EXTRA_EXT2(ARB_texture_cube_map_array
, OES_texture_cube_map_array
);
474 EXTRA_EXT(ARB_texture_buffer_range
);
475 EXTRA_EXT(ARB_texture_multisample
);
476 EXTRA_EXT(ARB_texture_gather
);
477 EXTRA_EXT(ARB_shader_atomic_counters
);
478 EXTRA_EXT(ARB_draw_indirect
);
479 EXTRA_EXT(ARB_shader_image_load_store
);
480 EXTRA_EXT(ARB_viewport_array
);
481 EXTRA_EXT(ARB_query_buffer_object
);
482 EXTRA_EXT2(ARB_transform_feedback3
, ARB_gpu_shader5
);
483 EXTRA_EXT(INTEL_performance_query
);
484 EXTRA_EXT(ARB_explicit_uniform_location
);
485 EXTRA_EXT(ARB_clip_control
);
486 EXTRA_EXT(EXT_polygon_offset_clamp
);
487 EXTRA_EXT(ARB_framebuffer_no_attachments
);
488 EXTRA_EXT(ARB_tessellation_shader
);
489 EXTRA_EXT(ARB_shader_subroutine
);
490 EXTRA_EXT(ARB_shader_storage_buffer_object
);
491 EXTRA_EXT(ARB_indirect_parameters
);
492 EXTRA_EXT(ATI_meminfo
);
493 EXTRA_EXT(NVX_gpu_memory_info
);
494 EXTRA_EXT(ARB_cull_distance
);
495 EXTRA_EXT(EXT_window_rectangles
);
496 EXTRA_EXT(KHR_blend_equation_advanced_coherent
);
497 EXTRA_EXT(OES_primitive_bounding_box
);
498 EXTRA_EXT(ARB_compute_variable_group_size
);
499 EXTRA_EXT(KHR_robustness
);
502 extra_ARB_color_buffer_float_or_glcore
[] = {
503 EXT(ARB_color_buffer_float
),
509 extra_NV_primitive_restart
[] = {
510 EXT(NV_primitive_restart
),
514 static const int extra_version_30
[] = { EXTRA_VERSION_30
, EXTRA_END
};
515 static const int extra_version_31
[] = { EXTRA_VERSION_31
, EXTRA_END
};
516 static const int extra_version_32
[] = { EXTRA_VERSION_32
, EXTRA_END
};
518 static const int extra_gl30_es3
[] = {
524 static const int extra_gl32_es3
[] = {
530 static const int extra_version_32_OES_geometry_shader
[] = {
536 static const int extra_gl40_ARB_sample_shading
[] = {
538 EXT(ARB_sample_shading
),
543 extra_ARB_vertex_program_api_es2
[] = {
544 EXT(ARB_vertex_program
),
549 /* The ReadBuffer get token is valid under either full GL or under
550 * GLES2 if the NV_read_buffer extension is available. */
552 extra_NV_read_buffer_api_gl
[] = {
558 static const int extra_core_ARB_color_buffer_float_and_new_buffers
[] = {
560 EXT(ARB_color_buffer_float
),
565 static const int extra_EXT_shader_framebuffer_fetch
[] = {
568 EXT(MESA_shader_framebuffer_fetch
),
572 /* This is the big table describing all the enums we accept in
573 * glGet*v(). The table is partitioned into six parts: enums
574 * understood by all GL APIs (OpenGL, GLES and GLES2), enums shared
575 * between OpenGL and GLES, enums exclusive to GLES, etc for the
576 * remaining combinations. To look up the enums valid in a given API
577 * we will use a hash table specific to that API. These tables are in
578 * turn generated at build time and included through get_hash.h.
581 #include "get_hash.h"
583 /* All we need now is a way to look up the value struct from the enum.
584 * The code generated by gcc for the old generated big switch
585 * statement is a big, balanced, open coded if/else tree, essentially
586 * an unrolled binary search. It would be natural to sort the new
587 * enum table and use bsearch(), but we will use a read-only hash
588 * table instead. bsearch() has a nice guaranteed worst case
589 * performance, but we're also guaranteed to hit that worst case
590 * (log2(n) iterations) for about half the enums. Instead, using an
591 * open addressing hash table, we can find the enum on the first try
592 * for 80% of the enums, 1 collision for 10% and never more than 5
593 * collisions for any enum (typical numbers). And the code is very
594 * simple, even though it feels a little magic. */
597 * Handle irregular enums
599 * Some values don't conform to the "well-known type at context
600 * pointer + offset" pattern, so we have this function to catch all
601 * the corner cases. Typically, it's a computed value or a one-off
602 * pointer to a custom struct or something.
604 * In this case we can't return a pointer to the value, so we'll have
605 * to use the temporary variable 'v' declared back in the calling
606 * glGet*v() function to store the result.
608 * \param ctx the current context
609 * \param d the struct value_desc that describes the enum
610 * \param v pointer to the tmp declared in the calling glGet*v() function
613 find_custom_value(struct gl_context
*ctx
, const struct value_desc
*d
, union value
*v
)
615 struct gl_buffer_object
**buffer_obj
;
616 struct gl_array_attributes
*array
;
620 case GL_MAJOR_VERSION
:
621 v
->value_int
= ctx
->Version
/ 10;
623 case GL_MINOR_VERSION
:
624 v
->value_int
= ctx
->Version
% 10;
630 case GL_TEXTURE_CUBE_MAP
:
631 case GL_TEXTURE_RECTANGLE_NV
:
632 case GL_TEXTURE_EXTERNAL_OES
:
633 v
->value_bool
= _mesa_IsEnabled(d
->pname
);
636 case GL_LINE_STIPPLE_PATTERN
:
637 /* This is the only GLushort, special case it here by promoting
638 * to an int rather than introducing a new type. */
639 v
->value_int
= ctx
->Line
.StipplePattern
;
642 case GL_CURRENT_RASTER_TEXTURE_COORDS
:
643 unit
= ctx
->Texture
.CurrentUnit
;
644 v
->value_float_4
[0] = ctx
->Current
.RasterTexCoords
[unit
][0];
645 v
->value_float_4
[1] = ctx
->Current
.RasterTexCoords
[unit
][1];
646 v
->value_float_4
[2] = ctx
->Current
.RasterTexCoords
[unit
][2];
647 v
->value_float_4
[3] = ctx
->Current
.RasterTexCoords
[unit
][3];
650 case GL_CURRENT_TEXTURE_COORDS
:
651 unit
= ctx
->Texture
.CurrentUnit
;
652 v
->value_float_4
[0] = ctx
->Current
.Attrib
[VERT_ATTRIB_TEX0
+ unit
][0];
653 v
->value_float_4
[1] = ctx
->Current
.Attrib
[VERT_ATTRIB_TEX0
+ unit
][1];
654 v
->value_float_4
[2] = ctx
->Current
.Attrib
[VERT_ATTRIB_TEX0
+ unit
][2];
655 v
->value_float_4
[3] = ctx
->Current
.Attrib
[VERT_ATTRIB_TEX0
+ unit
][3];
658 case GL_COLOR_WRITEMASK
:
659 v
->value_int_4
[0] = ctx
->Color
.ColorMask
[0][RCOMP
] ? 1 : 0;
660 v
->value_int_4
[1] = ctx
->Color
.ColorMask
[0][GCOMP
] ? 1 : 0;
661 v
->value_int_4
[2] = ctx
->Color
.ColorMask
[0][BCOMP
] ? 1 : 0;
662 v
->value_int_4
[3] = ctx
->Color
.ColorMask
[0][ACOMP
] ? 1 : 0;
666 v
->value_bool
= ctx
->Current
.Attrib
[VERT_ATTRIB_EDGEFLAG
][0] == 1.0F
;
670 v
->value_enum
= ctx
->ReadBuffer
->ColorReadBuffer
;
673 case GL_MAP2_GRID_DOMAIN
:
674 v
->value_float_4
[0] = ctx
->Eval
.MapGrid2u1
;
675 v
->value_float_4
[1] = ctx
->Eval
.MapGrid2u2
;
676 v
->value_float_4
[2] = ctx
->Eval
.MapGrid2v1
;
677 v
->value_float_4
[3] = ctx
->Eval
.MapGrid2v2
;
680 case GL_TEXTURE_STACK_DEPTH
:
681 unit
= ctx
->Texture
.CurrentUnit
;
682 v
->value_int
= ctx
->TextureMatrixStack
[unit
].Depth
+ 1;
684 case GL_TEXTURE_MATRIX
:
685 unit
= ctx
->Texture
.CurrentUnit
;
686 v
->value_matrix
= ctx
->TextureMatrixStack
[unit
].Top
;
689 case GL_TEXTURE_COORD_ARRAY
:
690 case GL_TEXTURE_COORD_ARRAY_SIZE
:
691 case GL_TEXTURE_COORD_ARRAY_TYPE
:
692 case GL_TEXTURE_COORD_ARRAY_STRIDE
:
693 array
= &ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_TEX(ctx
->Array
.ActiveTexture
)];
694 v
->value_int
= *(GLuint
*) ((char *) array
+ d
->offset
);
697 case GL_ACTIVE_TEXTURE_ARB
:
698 v
->value_int
= GL_TEXTURE0_ARB
+ ctx
->Texture
.CurrentUnit
;
700 case GL_CLIENT_ACTIVE_TEXTURE_ARB
:
701 v
->value_int
= GL_TEXTURE0_ARB
+ ctx
->Array
.ActiveTexture
;
704 case GL_MODELVIEW_STACK_DEPTH
:
705 case GL_PROJECTION_STACK_DEPTH
:
706 v
->value_int
= *(GLint
*) ((char *) ctx
+ d
->offset
) + 1;
709 case GL_MAX_TEXTURE_SIZE
:
710 case GL_MAX_3D_TEXTURE_SIZE
:
711 case GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB
:
712 p
= (GLuint
*) ((char *) ctx
+ d
->offset
);
713 v
->value_int
= 1 << (*p
- 1);
717 v
->value_int_4
[0] = ctx
->Scissor
.ScissorArray
[0].X
;
718 v
->value_int_4
[1] = ctx
->Scissor
.ScissorArray
[0].Y
;
719 v
->value_int_4
[2] = ctx
->Scissor
.ScissorArray
[0].Width
;
720 v
->value_int_4
[3] = ctx
->Scissor
.ScissorArray
[0].Height
;
723 case GL_SCISSOR_TEST
:
724 v
->value_bool
= ctx
->Scissor
.EnableFlags
& 1;
729 ctx
->ListState
.CurrentList
? ctx
->ListState
.CurrentList
->Name
: 0;
732 if (!ctx
->CompileFlag
)
734 else if (ctx
->ExecuteFlag
)
735 v
->value_enum
= GL_COMPILE_AND_EXECUTE
;
737 v
->value_enum
= GL_COMPILE
;
741 v
->value_float_4
[0] = ctx
->ViewportArray
[0].X
;
742 v
->value_float_4
[1] = ctx
->ViewportArray
[0].Y
;
743 v
->value_float_4
[2] = ctx
->ViewportArray
[0].Width
;
744 v
->value_float_4
[3] = ctx
->ViewportArray
[0].Height
;
748 v
->value_double_2
[0] = ctx
->ViewportArray
[0].Near
;
749 v
->value_double_2
[1] = ctx
->ViewportArray
[0].Far
;
752 case GL_ACTIVE_STENCIL_FACE_EXT
:
753 v
->value_enum
= ctx
->Stencil
.ActiveFace
? GL_BACK
: GL_FRONT
;
756 case GL_STENCIL_FAIL
:
757 v
->value_enum
= ctx
->Stencil
.FailFunc
[ctx
->Stencil
.ActiveFace
];
759 case GL_STENCIL_FUNC
:
760 v
->value_enum
= ctx
->Stencil
.Function
[ctx
->Stencil
.ActiveFace
];
762 case GL_STENCIL_PASS_DEPTH_FAIL
:
763 v
->value_enum
= ctx
->Stencil
.ZFailFunc
[ctx
->Stencil
.ActiveFace
];
765 case GL_STENCIL_PASS_DEPTH_PASS
:
766 v
->value_enum
= ctx
->Stencil
.ZPassFunc
[ctx
->Stencil
.ActiveFace
];
769 v
->value_int
= _mesa_get_stencil_ref(ctx
, ctx
->Stencil
.ActiveFace
);
771 case GL_STENCIL_BACK_REF
:
772 v
->value_int
= _mesa_get_stencil_ref(ctx
, 1);
774 case GL_STENCIL_VALUE_MASK
:
775 v
->value_int
= ctx
->Stencil
.ValueMask
[ctx
->Stencil
.ActiveFace
];
777 case GL_STENCIL_WRITEMASK
:
778 v
->value_int
= ctx
->Stencil
.WriteMask
[ctx
->Stencil
.ActiveFace
];
781 case GL_NUM_EXTENSIONS
:
782 v
->value_int
= _mesa_get_extension_count(ctx
);
785 case GL_IMPLEMENTATION_COLOR_READ_TYPE_OES
:
786 v
->value_int
= _mesa_get_color_read_type(ctx
);
788 case GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES
:
789 v
->value_int
= _mesa_get_color_read_format(ctx
);
792 case GL_CURRENT_MATRIX_STACK_DEPTH_ARB
:
793 v
->value_int
= ctx
->CurrentStack
->Depth
+ 1;
795 case GL_CURRENT_MATRIX_ARB
:
796 case GL_TRANSPOSE_CURRENT_MATRIX_ARB
:
797 v
->value_matrix
= ctx
->CurrentStack
->Top
;
800 case GL_NUM_COMPRESSED_TEXTURE_FORMATS_ARB
:
801 v
->value_int
= _mesa_get_compressed_formats(ctx
, NULL
);
803 case GL_COMPRESSED_TEXTURE_FORMATS_ARB
:
805 _mesa_get_compressed_formats(ctx
, v
->value_int_n
.ints
);
806 assert(v
->value_int_n
.n
<= (int) ARRAY_SIZE(v
->value_int_n
.ints
));
809 case GL_MAX_VARYING_FLOATS_ARB
:
810 v
->value_int
= ctx
->Const
.MaxVarying
* 4;
813 /* Various object names */
815 case GL_TEXTURE_BINDING_1D
:
816 case GL_TEXTURE_BINDING_2D
:
817 case GL_TEXTURE_BINDING_3D
:
818 case GL_TEXTURE_BINDING_1D_ARRAY_EXT
:
819 case GL_TEXTURE_BINDING_2D_ARRAY_EXT
:
820 case GL_TEXTURE_BINDING_CUBE_MAP_ARB
:
821 case GL_TEXTURE_BINDING_RECTANGLE_NV
:
822 case GL_TEXTURE_BINDING_EXTERNAL_OES
:
823 case GL_TEXTURE_BINDING_CUBE_MAP_ARRAY
:
824 case GL_TEXTURE_BINDING_2D_MULTISAMPLE
:
825 case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY
:
826 unit
= ctx
->Texture
.CurrentUnit
;
828 ctx
->Texture
.Unit
[unit
].CurrentTex
[d
->offset
]->Name
;
831 /* GL_EXT_packed_float */
832 case GL_RGBA_SIGNED_COMPONENTS_EXT
:
834 /* Note: we only check the 0th color attachment. */
835 const struct gl_renderbuffer
*rb
=
836 ctx
->DrawBuffer
->_ColorDrawBuffers
[0];
837 if (rb
&& _mesa_is_format_signed(rb
->Format
)) {
838 /* Issue 17 of GL_EXT_packed_float: If a component (such as
839 * alpha) has zero bits, the component should not be considered
840 * signed and so the bit for the respective component should be
844 _mesa_get_format_bits(rb
->Format
, GL_RED_BITS
);
846 _mesa_get_format_bits(rb
->Format
, GL_GREEN_BITS
);
848 _mesa_get_format_bits(rb
->Format
, GL_BLUE_BITS
);
850 _mesa_get_format_bits(rb
->Format
, GL_ALPHA_BITS
);
852 _mesa_get_format_bits(rb
->Format
, GL_TEXTURE_LUMINANCE_SIZE
);
854 _mesa_get_format_bits(rb
->Format
, GL_TEXTURE_INTENSITY_SIZE
);
856 v
->value_int_4
[0] = r_bits
+ l_bits
+ i_bits
> 0;
857 v
->value_int_4
[1] = g_bits
+ l_bits
+ i_bits
> 0;
858 v
->value_int_4
[2] = b_bits
+ l_bits
+ i_bits
> 0;
859 v
->value_int_4
[3] = a_bits
+ i_bits
> 0;
865 v
->value_int_4
[3] = 0;
870 /* GL_ARB_vertex_buffer_object */
871 case GL_VERTEX_ARRAY_BUFFER_BINDING_ARB
:
872 case GL_NORMAL_ARRAY_BUFFER_BINDING_ARB
:
873 case GL_COLOR_ARRAY_BUFFER_BINDING_ARB
:
874 case GL_INDEX_ARRAY_BUFFER_BINDING_ARB
:
875 case GL_EDGE_FLAG_ARRAY_BUFFER_BINDING_ARB
:
876 case GL_SECONDARY_COLOR_ARRAY_BUFFER_BINDING_ARB
:
877 case GL_FOG_COORDINATE_ARRAY_BUFFER_BINDING_ARB
:
878 buffer_obj
= (struct gl_buffer_object
**)
879 ((char *) ctx
->Array
.VAO
+ d
->offset
);
880 v
->value_int
= (*buffer_obj
)->Name
;
882 case GL_ARRAY_BUFFER_BINDING_ARB
:
883 v
->value_int
= ctx
->Array
.ArrayBufferObj
->Name
;
885 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING_ARB
:
887 ctx
->Array
.VAO
->BufferBinding
[VERT_ATTRIB_TEX(ctx
->Array
.ActiveTexture
)].BufferObj
->Name
;
889 case GL_ELEMENT_ARRAY_BUFFER_BINDING_ARB
:
890 v
->value_int
= ctx
->Array
.VAO
->IndexBufferObj
->Name
;
893 /* ARB_vertex_array_bgra */
894 case GL_COLOR_ARRAY_SIZE
:
895 array
= &ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_COLOR0
];
896 v
->value_int
= array
->Format
== GL_BGRA
? GL_BGRA
: array
->Size
;
898 case GL_SECONDARY_COLOR_ARRAY_SIZE
:
899 array
= &ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_COLOR1
];
900 v
->value_int
= array
->Format
== GL_BGRA
? GL_BGRA
: array
->Size
;
903 /* ARB_copy_buffer */
904 case GL_COPY_READ_BUFFER
:
905 v
->value_int
= ctx
->CopyReadBuffer
->Name
;
907 case GL_COPY_WRITE_BUFFER
:
908 v
->value_int
= ctx
->CopyWriteBuffer
->Name
;
911 case GL_PIXEL_PACK_BUFFER_BINDING_EXT
:
912 v
->value_int
= ctx
->Pack
.BufferObj
->Name
;
914 case GL_PIXEL_UNPACK_BUFFER_BINDING_EXT
:
915 v
->value_int
= ctx
->Unpack
.BufferObj
->Name
;
917 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING
:
918 v
->value_int
= ctx
->TransformFeedback
.CurrentBuffer
->Name
;
920 case GL_TRANSFORM_FEEDBACK_BUFFER_PAUSED
:
921 v
->value_int
= ctx
->TransformFeedback
.CurrentObject
->Paused
;
923 case GL_TRANSFORM_FEEDBACK_BUFFER_ACTIVE
:
924 v
->value_int
= ctx
->TransformFeedback
.CurrentObject
->Active
;
926 case GL_TRANSFORM_FEEDBACK_BINDING
:
927 v
->value_int
= ctx
->TransformFeedback
.CurrentObject
->Name
;
929 case GL_CURRENT_PROGRAM
:
930 /* The Changelog of the ARB_separate_shader_objects spec says:
932 * 24 25 Jul 2011 pbrown Remove the language erroneously deleting
933 * CURRENT_PROGRAM. In the EXT extension, this
934 * token was aliased to ACTIVE_PROGRAM_EXT, and
935 * was used to indicate the last program set by
936 * either ActiveProgramEXT or UseProgram. In
937 * the ARB extension, the SSO active programs
938 * are now program pipeline object state and
939 * CURRENT_PROGRAM should still be used to query
940 * the last program set by UseProgram (bug 7822).
943 ctx
->Shader
.ActiveProgram
? ctx
->Shader
.ActiveProgram
->Name
: 0;
945 case GL_READ_FRAMEBUFFER_BINDING_EXT
:
946 v
->value_int
= ctx
->ReadBuffer
->Name
;
948 case GL_RENDERBUFFER_BINDING_EXT
:
950 ctx
->CurrentRenderbuffer
? ctx
->CurrentRenderbuffer
->Name
: 0;
952 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES
:
953 v
->value_int
= ctx
->Array
.VAO
->BufferBinding
[VERT_ATTRIB_POINT_SIZE
].BufferObj
->Name
;
957 if (_mesa_get_clamp_fragment_color(ctx
, ctx
->DrawBuffer
))
958 COPY_4FV(v
->value_float_4
, ctx
->Fog
.Color
);
960 COPY_4FV(v
->value_float_4
, ctx
->Fog
.ColorUnclamped
);
962 case GL_COLOR_CLEAR_VALUE
:
963 if (_mesa_get_clamp_fragment_color(ctx
, ctx
->DrawBuffer
)) {
964 v
->value_float_4
[0] = CLAMP(ctx
->Color
.ClearColor
.f
[0], 0.0F
, 1.0F
);
965 v
->value_float_4
[1] = CLAMP(ctx
->Color
.ClearColor
.f
[1], 0.0F
, 1.0F
);
966 v
->value_float_4
[2] = CLAMP(ctx
->Color
.ClearColor
.f
[2], 0.0F
, 1.0F
);
967 v
->value_float_4
[3] = CLAMP(ctx
->Color
.ClearColor
.f
[3], 0.0F
, 1.0F
);
969 COPY_4FV(v
->value_float_4
, ctx
->Color
.ClearColor
.f
);
971 case GL_BLEND_COLOR_EXT
:
972 if (_mesa_get_clamp_fragment_color(ctx
, ctx
->DrawBuffer
))
973 COPY_4FV(v
->value_float_4
, ctx
->Color
.BlendColor
);
975 COPY_4FV(v
->value_float_4
, ctx
->Color
.BlendColorUnclamped
);
977 case GL_ALPHA_TEST_REF
:
978 if (_mesa_get_clamp_fragment_color(ctx
, ctx
->DrawBuffer
))
979 v
->value_float
= ctx
->Color
.AlphaRef
;
981 v
->value_float
= ctx
->Color
.AlphaRefUnclamped
;
983 case GL_MAX_VERTEX_UNIFORM_VECTORS
:
984 v
->value_int
= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxUniformComponents
/ 4;
987 case GL_MAX_FRAGMENT_UNIFORM_VECTORS
:
988 v
->value_int
= ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxUniformComponents
/ 4;
991 /* GL_ARB_texture_buffer_object */
992 case GL_TEXTURE_BUFFER_ARB
:
993 v
->value_int
= ctx
->Texture
.BufferObject
->Name
;
995 case GL_TEXTURE_BINDING_BUFFER_ARB
:
996 unit
= ctx
->Texture
.CurrentUnit
;
998 ctx
->Texture
.Unit
[unit
].CurrentTex
[TEXTURE_BUFFER_INDEX
]->Name
;
1000 case GL_TEXTURE_BUFFER_DATA_STORE_BINDING_ARB
:
1002 struct gl_buffer_object
*buf
=
1003 ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
]
1004 .CurrentTex
[TEXTURE_BUFFER_INDEX
]->BufferObject
;
1005 v
->value_int
= buf
? buf
->Name
: 0;
1008 case GL_TEXTURE_BUFFER_FORMAT_ARB
:
1009 v
->value_int
= ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
]
1010 .CurrentTex
[TEXTURE_BUFFER_INDEX
]->BufferObjectFormat
;
1013 /* GL_ARB_sampler_objects */
1014 case GL_SAMPLER_BINDING
:
1016 struct gl_sampler_object
*samp
=
1017 ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
].Sampler
;
1018 v
->value_int
= samp
? samp
->Name
: 0;
1021 /* GL_ARB_uniform_buffer_object */
1022 case GL_UNIFORM_BUFFER_BINDING
:
1023 v
->value_int
= ctx
->UniformBuffer
->Name
;
1025 /* GL_ARB_shader_storage_buffer_object */
1026 case GL_SHADER_STORAGE_BUFFER_BINDING
:
1027 v
->value_int
= ctx
->ShaderStorageBuffer
->Name
;
1029 /* GL_ARB_query_buffer_object */
1030 case GL_QUERY_BUFFER_BINDING
:
1031 v
->value_int
= ctx
->QueryBuffer
->Name
;
1033 /* GL_ARB_timer_query */
1035 if (ctx
->Driver
.GetTimestamp
) {
1036 v
->value_int64
= ctx
->Driver
.GetTimestamp(ctx
);
1039 _mesa_problem(ctx
, "driver doesn't implement GetTimestamp");
1043 case GL_DEBUG_OUTPUT
:
1044 case GL_DEBUG_OUTPUT_SYNCHRONOUS
:
1045 case GL_DEBUG_LOGGED_MESSAGES
:
1046 case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH
:
1047 case GL_DEBUG_GROUP_STACK_DEPTH
:
1048 v
->value_int
= _mesa_get_debug_state_int(ctx
, d
->pname
);
1050 /* GL_ARB_shader_atomic_counters */
1051 case GL_ATOMIC_COUNTER_BUFFER_BINDING
:
1052 if (ctx
->AtomicBuffer
) {
1053 v
->value_int
= ctx
->AtomicBuffer
->Name
;
1058 /* GL_ARB_draw_indirect */
1059 case GL_DRAW_INDIRECT_BUFFER_BINDING
:
1060 v
->value_int
= ctx
->DrawIndirectBuffer
->Name
;
1062 /* GL_ARB_indirect_parameters */
1063 case GL_PARAMETER_BUFFER_BINDING_ARB
:
1064 v
->value_int
= ctx
->ParameterBuffer
->Name
;
1066 /* GL_ARB_separate_shader_objects */
1067 case GL_PROGRAM_PIPELINE_BINDING
:
1068 if (ctx
->Pipeline
.Current
) {
1069 v
->value_int
= ctx
->Pipeline
.Current
->Name
;
1074 /* GL_ARB_compute_shader */
1075 case GL_DISPATCH_INDIRECT_BUFFER_BINDING
:
1076 v
->value_int
= ctx
->DispatchIndirectBuffer
->Name
;
1078 /* GL_ARB_multisample */
1080 v
->value_int
= _mesa_geometric_samples(ctx
->DrawBuffer
);
1082 case GL_SAMPLE_BUFFERS
:
1083 v
->value_int
= _mesa_geometric_samples(ctx
->DrawBuffer
) > 0;
1085 /* GL_EXT_textrue_integer */
1086 case GL_RGBA_INTEGER_MODE_EXT
:
1087 v
->value_int
= (ctx
->DrawBuffer
->_IntegerBuffers
!= 0);
1089 /* GL_ATI_meminfo & GL_NVX_gpu_memory_info */
1090 case GL_VBO_FREE_MEMORY_ATI
:
1091 case GL_TEXTURE_FREE_MEMORY_ATI
:
1092 case GL_RENDERBUFFER_FREE_MEMORY_ATI
:
1093 case GL_GPU_MEMORY_INFO_DEDICATED_VIDMEM_NVX
:
1094 case GL_GPU_MEMORY_INFO_TOTAL_AVAILABLE_MEMORY_NVX
:
1095 case GL_GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX
:
1096 case GL_GPU_MEMORY_INFO_EVICTION_COUNT_NVX
:
1097 case GL_GPU_MEMORY_INFO_EVICTED_MEMORY_NVX
:
1099 struct gl_memory_info info
;
1101 ctx
->Driver
.QueryMemoryInfo(ctx
, &info
);
1103 if (d
->pname
== GL_GPU_MEMORY_INFO_DEDICATED_VIDMEM_NVX
)
1104 v
->value_int
= info
.total_device_memory
;
1105 else if (d
->pname
== GL_GPU_MEMORY_INFO_TOTAL_AVAILABLE_MEMORY_NVX
)
1106 v
->value_int
= info
.total_device_memory
+
1107 info
.total_staging_memory
;
1108 else if (d
->pname
== GL_GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX
)
1109 v
->value_int
= info
.avail_device_memory
;
1110 else if (d
->pname
== GL_GPU_MEMORY_INFO_EVICTION_COUNT_NVX
)
1111 v
->value_int
= info
.nr_device_memory_evictions
;
1112 else if (d
->pname
== GL_GPU_MEMORY_INFO_EVICTED_MEMORY_NVX
)
1113 v
->value_int
= info
.device_memory_evicted
;
1115 /* ATI free memory enums.
1117 * Since the GPU memory is (usually) page-table based, every two
1118 * consecutive elements are equal. From the GL_ATI_meminfo
1121 * "param[0] - total memory free in the pool
1122 * param[1] - largest available free block in the pool
1123 * param[2] - total auxiliary memory free
1124 * param[3] - largest auxiliary free block"
1126 * All three (VBO, TEXTURE, RENDERBUFFER) queries return
1127 * the same numbers here.
1129 v
->value_int_4
[0] = info
.avail_device_memory
;
1130 v
->value_int_4
[1] = info
.avail_device_memory
;
1131 v
->value_int_4
[2] = info
.avail_staging_memory
;
1132 v
->value_int_4
[3] = info
.avail_staging_memory
;
1140 * Check extra constraints on a struct value_desc descriptor
1142 * If a struct value_desc has a non-NULL extra pointer, it means that
1143 * there are a number of extra constraints to check or actions to
1144 * perform. The extras is just an integer array where each integer
1145 * encode different constraints or actions.
1147 * \param ctx current context
1148 * \param func name of calling glGet*v() function for error reporting
1149 * \param d the struct value_desc that has the extra constraints
1151 * \return GL_FALSE if all of the constraints were not satisfied,
1152 * otherwise GL_TRUE.
1155 check_extra(struct gl_context
*ctx
, const char *func
, const struct value_desc
*d
)
1157 const GLuint version
= ctx
->Version
;
1158 GLboolean api_check
= GL_FALSE
;
1159 GLboolean api_found
= GL_FALSE
;
1162 for (e
= d
->extra
; *e
!= EXTRA_END
; e
++) {
1164 case EXTRA_VERSION_30
:
1165 api_check
= GL_TRUE
;
1167 api_found
= GL_TRUE
;
1169 case EXTRA_VERSION_31
:
1170 api_check
= GL_TRUE
;
1172 api_found
= GL_TRUE
;
1174 case EXTRA_VERSION_32
:
1175 api_check
= GL_TRUE
;
1177 api_found
= GL_TRUE
;
1179 case EXTRA_NEW_FRAG_CLAMP
:
1180 if (ctx
->NewState
& (_NEW_BUFFERS
| _NEW_FRAG_CLAMP
))
1181 _mesa_update_state(ctx
);
1184 api_check
= GL_TRUE
;
1185 if (ctx
->API
== API_OPENGLES2
)
1186 api_found
= GL_TRUE
;
1189 api_check
= GL_TRUE
;
1190 if (_mesa_is_gles3(ctx
))
1191 api_found
= GL_TRUE
;
1193 case EXTRA_API_ES31
:
1194 api_check
= GL_TRUE
;
1195 if (_mesa_is_gles31(ctx
))
1196 api_found
= GL_TRUE
;
1198 case EXTRA_API_ES32
:
1199 api_check
= GL_TRUE
;
1200 if (_mesa_is_gles32(ctx
))
1201 api_found
= GL_TRUE
;
1204 api_check
= GL_TRUE
;
1205 if (_mesa_is_desktop_gl(ctx
))
1206 api_found
= GL_TRUE
;
1208 case EXTRA_API_GL_CORE
:
1209 api_check
= GL_TRUE
;
1210 if (ctx
->API
== API_OPENGL_CORE
)
1211 api_found
= GL_TRUE
;
1213 case EXTRA_NEW_BUFFERS
:
1214 if (ctx
->NewState
& _NEW_BUFFERS
)
1215 _mesa_update_state(ctx
);
1217 case EXTRA_FLUSH_CURRENT
:
1218 FLUSH_CURRENT(ctx
, 0);
1220 case EXTRA_VALID_DRAW_BUFFER
:
1221 if (d
->pname
- GL_DRAW_BUFFER0_ARB
>= ctx
->Const
.MaxDrawBuffers
) {
1222 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(draw buffer %u)",
1223 func
, d
->pname
- GL_DRAW_BUFFER0_ARB
);
1227 case EXTRA_VALID_TEXTURE_UNIT
:
1228 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureCoordUnits
) {
1229 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(texture %u)",
1230 func
, ctx
->Texture
.CurrentUnit
);
1234 case EXTRA_VALID_CLIP_DISTANCE
:
1235 if (d
->pname
- GL_CLIP_DISTANCE0
>= ctx
->Const
.MaxClipPlanes
) {
1236 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(clip distance %u)",
1237 func
, d
->pname
- GL_CLIP_DISTANCE0
);
1241 case EXTRA_GLSL_130
:
1242 api_check
= GL_TRUE
;
1243 if (ctx
->Const
.GLSLVersion
>= 130)
1244 api_found
= GL_TRUE
;
1246 case EXTRA_EXT_UBO_GS
:
1247 api_check
= GL_TRUE
;
1248 if (ctx
->Extensions
.ARB_uniform_buffer_object
&&
1249 _mesa_has_geometry_shaders(ctx
))
1250 api_found
= GL_TRUE
;
1252 case EXTRA_EXT_ATOMICS_GS
:
1253 api_check
= GL_TRUE
;
1254 if (ctx
->Extensions
.ARB_shader_atomic_counters
&&
1255 _mesa_has_geometry_shaders(ctx
))
1256 api_found
= GL_TRUE
;
1258 case EXTRA_EXT_SHADER_IMAGE_GS
:
1259 api_check
= GL_TRUE
;
1260 if (ctx
->Extensions
.ARB_shader_image_load_store
&&
1261 _mesa_has_geometry_shaders(ctx
))
1262 api_found
= GL_TRUE
;
1264 case EXTRA_EXT_ATOMICS_TESS
:
1265 api_check
= GL_TRUE
;
1266 api_found
= ctx
->Extensions
.ARB_shader_atomic_counters
&&
1267 _mesa_has_tessellation(ctx
);
1269 case EXTRA_EXT_SHADER_IMAGE_TESS
:
1270 api_check
= GL_TRUE
;
1271 api_found
= ctx
->Extensions
.ARB_shader_image_load_store
&&
1272 _mesa_has_tessellation(ctx
);
1274 case EXTRA_EXT_SSBO_GS
:
1275 api_check
= GL_TRUE
;
1276 if (ctx
->Extensions
.ARB_shader_storage_buffer_object
&&
1277 _mesa_has_geometry_shaders(ctx
))
1278 api_found
= GL_TRUE
;
1280 case EXTRA_EXT_FB_NO_ATTACH_GS
:
1281 api_check
= GL_TRUE
;
1282 if (ctx
->Extensions
.ARB_framebuffer_no_attachments
&&
1283 (_mesa_is_desktop_gl(ctx
) ||
1284 _mesa_has_OES_geometry_shader(ctx
)))
1285 api_found
= GL_TRUE
;
1287 case EXTRA_EXT_ES_GS
:
1288 api_check
= GL_TRUE
;
1289 if (_mesa_has_OES_geometry_shader(ctx
))
1290 api_found
= GL_TRUE
;
1294 default: /* *e is a offset into the extension struct */
1295 api_check
= GL_TRUE
;
1296 if (*(GLboolean
*) ((char *) &ctx
->Extensions
+ *e
))
1297 api_found
= GL_TRUE
;
1302 if (api_check
&& !api_found
) {
1303 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=%s)", func
,
1304 _mesa_enum_to_string(d
->pname
));
1311 static const struct value_desc error_value
=
1312 { 0, 0, TYPE_INVALID
, NO_OFFSET
, NO_EXTRA
};
1315 * Find the struct value_desc corresponding to the enum 'pname'.
1317 * We hash the enum value to get an index into the 'table' array,
1318 * which holds the index in the 'values' array of struct value_desc.
1319 * Once we've found the entry, we do the extra checks, if any, then
1320 * look up the value and return a pointer to it.
1322 * If the value has to be computed (for example, it's the result of a
1323 * function call or we need to add 1 to it), we use the tmp 'v' to
1326 * \param func name of glGet*v() func for error reporting
1327 * \param pname the enum value we're looking up
1328 * \param p is were we return the pointer to the value
1329 * \param v a tmp union value variable in the calling glGet*v() function
1331 * \return the struct value_desc corresponding to the enum or a struct
1332 * value_desc of TYPE_INVALID if not found. This lets the calling
1333 * glGet*v() function jump right into a switch statement and
1334 * handle errors there instead of having to check for NULL.
1336 static const struct value_desc
*
1337 find_value(const char *func
, GLenum pname
, void **p
, union value
*v
)
1339 GET_CURRENT_CONTEXT(ctx
);
1340 struct gl_texture_unit
*unit
;
1342 const struct value_desc
*d
;
1346 /* We index into the table_set[] list of per-API hash tables using the API's
1347 * value in the gl_api enum. Since GLES 3 doesn't have an API_OPENGL* enum
1348 * value since it's compatible with GLES2 its entry in table_set[] is at the
1351 STATIC_ASSERT(ARRAY_SIZE(table_set
) == API_OPENGL_LAST
+ 4);
1352 if (ctx
->API
== API_OPENGLES2
) {
1353 if (ctx
->Version
>= 32)
1354 api
= API_OPENGL_LAST
+ 3;
1355 else if (ctx
->Version
>= 31)
1356 api
= API_OPENGL_LAST
+ 2;
1357 else if (ctx
->Version
>= 30)
1358 api
= API_OPENGL_LAST
+ 1;
1360 mask
= ARRAY_SIZE(table(api
)) - 1;
1361 hash
= (pname
* prime_factor
);
1363 int idx
= table(api
)[hash
& mask
];
1365 /* If the enum isn't valid, the hash walk ends with index 0,
1366 * pointing to the first entry of values[] which doesn't hold
1367 * any valid enum. */
1368 if (unlikely(idx
== 0)) {
1369 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=%s)", func
,
1370 _mesa_enum_to_string(pname
));
1371 return &error_value
;
1375 if (likely(d
->pname
== pname
))
1381 if (unlikely(d
->extra
&& !check_extra(ctx
, func
, d
)))
1382 return &error_value
;
1384 switch (d
->location
) {
1386 *p
= ((char *) ctx
->DrawBuffer
+ d
->offset
);
1389 *p
= ((char *) ctx
+ d
->offset
);
1392 *p
= ((char *) ctx
->Array
.VAO
+ d
->offset
);
1395 unit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1396 *p
= ((char *) unit
+ d
->offset
);
1399 find_custom_value(ctx
, d
, v
);
1407 /* silence warning */
1408 return &error_value
;
1411 static const int transpose
[] = {
1419 _mesa_GetBooleanv(GLenum pname
, GLboolean
*params
)
1421 const struct value_desc
*d
;
1427 d
= find_value("glGetBooleanv", pname
, &p
, &v
);
1432 params
[0] = INT_TO_BOOLEAN(d
->offset
);
1436 params
[7] = FLOAT_TO_BOOLEAN(((GLfloat
*) p
)[7]);
1437 params
[6] = FLOAT_TO_BOOLEAN(((GLfloat
*) p
)[6]);
1438 params
[5] = FLOAT_TO_BOOLEAN(((GLfloat
*) p
)[5]);
1439 params
[4] = FLOAT_TO_BOOLEAN(((GLfloat
*) p
)[4]);
1442 params
[3] = FLOAT_TO_BOOLEAN(((GLfloat
*) p
)[3]);
1445 params
[2] = FLOAT_TO_BOOLEAN(((GLfloat
*) p
)[2]);
1448 params
[1] = FLOAT_TO_BOOLEAN(((GLfloat
*) p
)[1]);
1451 params
[0] = FLOAT_TO_BOOLEAN(((GLfloat
*) p
)[0]);
1454 case TYPE_DOUBLEN_2
:
1455 params
[1] = FLOAT_TO_BOOLEAN(((GLdouble
*) p
)[1]);
1457 params
[0] = FLOAT_TO_BOOLEAN(((GLdouble
*) p
)[0]);
1461 params
[3] = INT_TO_BOOLEAN(((GLint
*) p
)[3]);
1463 params
[2] = INT_TO_BOOLEAN(((GLint
*) p
)[2]);
1466 params
[1] = INT_TO_BOOLEAN(((GLint
*) p
)[1]);
1469 params
[0] = INT_TO_BOOLEAN(((GLint
*) p
)[0]);
1473 for (i
= 0; i
< v
.value_int_n
.n
; i
++)
1474 params
[i
] = INT_TO_BOOLEAN(v
.value_int_n
.ints
[i
]);
1478 params
[0] = INT64_TO_BOOLEAN(((GLint64
*) p
)[0]);
1482 params
[0] = ((GLboolean
*) p
)[0];
1486 m
= *(GLmatrix
**) p
;
1487 for (i
= 0; i
< 16; i
++)
1488 params
[i
] = FLOAT_TO_BOOLEAN(m
->m
[i
]);
1492 m
= *(GLmatrix
**) p
;
1493 for (i
= 0; i
< 16; i
++)
1494 params
[i
] = FLOAT_TO_BOOLEAN(m
->m
[transpose
[i
]]);
1505 shift
= d
->type
- TYPE_BIT_0
;
1506 params
[0] = (*(GLbitfield
*) p
>> shift
) & 1;
1512 _mesa_GetFloatv(GLenum pname
, GLfloat
*params
)
1514 const struct value_desc
*d
;
1520 d
= find_value("glGetFloatv", pname
, &p
, &v
);
1525 params
[0] = (GLfloat
) d
->offset
;
1529 params
[7] = ((GLfloat
*) p
)[7];
1530 params
[6] = ((GLfloat
*) p
)[6];
1531 params
[5] = ((GLfloat
*) p
)[5];
1532 params
[4] = ((GLfloat
*) p
)[4];
1535 params
[3] = ((GLfloat
*) p
)[3];
1538 params
[2] = ((GLfloat
*) p
)[2];
1541 params
[1] = ((GLfloat
*) p
)[1];
1544 params
[0] = ((GLfloat
*) p
)[0];
1547 case TYPE_DOUBLEN_2
:
1548 params
[1] = (GLfloat
) (((GLdouble
*) p
)[1]);
1550 params
[0] = (GLfloat
) (((GLdouble
*) p
)[0]);
1554 params
[3] = (GLfloat
) (((GLint
*) p
)[3]);
1556 params
[2] = (GLfloat
) (((GLint
*) p
)[2]);
1559 params
[1] = (GLfloat
) (((GLint
*) p
)[1]);
1562 params
[0] = (GLfloat
) (((GLint
*) p
)[0]);
1566 for (i
= 0; i
< v
.value_int_n
.n
; i
++)
1567 params
[i
] = INT_TO_FLOAT(v
.value_int_n
.ints
[i
]);
1571 params
[0] = (GLfloat
) (((GLint64
*) p
)[0]);
1575 params
[0] = BOOLEAN_TO_FLOAT(*(GLboolean
*) p
);
1579 m
= *(GLmatrix
**) p
;
1580 for (i
= 0; i
< 16; i
++)
1581 params
[i
] = m
->m
[i
];
1585 m
= *(GLmatrix
**) p
;
1586 for (i
= 0; i
< 16; i
++)
1587 params
[i
] = m
->m
[transpose
[i
]];
1598 shift
= d
->type
- TYPE_BIT_0
;
1599 params
[0] = BOOLEAN_TO_FLOAT((*(GLbitfield
*) p
>> shift
) & 1);
1605 _mesa_GetIntegerv(GLenum pname
, GLint
*params
)
1607 const struct value_desc
*d
;
1613 d
= find_value("glGetIntegerv", pname
, &p
, &v
);
1618 params
[0] = d
->offset
;
1622 params
[7] = IROUND(((GLfloat
*) p
)[7]);
1623 params
[6] = IROUND(((GLfloat
*) p
)[6]);
1624 params
[5] = IROUND(((GLfloat
*) p
)[5]);
1625 params
[4] = IROUND(((GLfloat
*) p
)[4]);
1627 params
[3] = IROUND(((GLfloat
*) p
)[3]);
1629 params
[2] = IROUND(((GLfloat
*) p
)[2]);
1631 params
[1] = IROUND(((GLfloat
*) p
)[1]);
1633 params
[0] = IROUND(((GLfloat
*) p
)[0]);
1637 params
[3] = FLOAT_TO_INT(((GLfloat
*) p
)[3]);
1639 params
[2] = FLOAT_TO_INT(((GLfloat
*) p
)[2]);
1641 params
[1] = FLOAT_TO_INT(((GLfloat
*) p
)[1]);
1643 params
[0] = FLOAT_TO_INT(((GLfloat
*) p
)[0]);
1646 case TYPE_DOUBLEN_2
:
1647 params
[1] = FLOAT_TO_INT(((GLdouble
*) p
)[1]);
1649 params
[0] = FLOAT_TO_INT(((GLdouble
*) p
)[0]);
1653 params
[3] = ((GLint
*) p
)[3];
1655 params
[2] = ((GLint
*) p
)[2];
1658 params
[1] = ((GLint
*) p
)[1];
1661 params
[0] = ((GLint
*) p
)[0];
1665 for (i
= 0; i
< v
.value_int_n
.n
; i
++)
1666 params
[i
] = v
.value_int_n
.ints
[i
];
1670 params
[0] = INT64_TO_INT(((GLint64
*) p
)[0]);
1674 params
[0] = BOOLEAN_TO_INT(*(GLboolean
*) p
);
1678 m
= *(GLmatrix
**) p
;
1679 for (i
= 0; i
< 16; i
++)
1680 params
[i
] = FLOAT_TO_INT(m
->m
[i
]);
1684 m
= *(GLmatrix
**) p
;
1685 for (i
= 0; i
< 16; i
++)
1686 params
[i
] = FLOAT_TO_INT(m
->m
[transpose
[i
]]);
1697 shift
= d
->type
- TYPE_BIT_0
;
1698 params
[0] = (*(GLbitfield
*) p
>> shift
) & 1;
1704 _mesa_GetInteger64v(GLenum pname
, GLint64
*params
)
1706 const struct value_desc
*d
;
1712 d
= find_value("glGetInteger64v", pname
, &p
, &v
);
1717 params
[0] = d
->offset
;
1721 params
[7] = IROUND64(((GLfloat
*) p
)[7]);
1722 params
[6] = IROUND64(((GLfloat
*) p
)[6]);
1723 params
[5] = IROUND64(((GLfloat
*) p
)[5]);
1724 params
[4] = IROUND64(((GLfloat
*) p
)[4]);
1726 params
[3] = IROUND64(((GLfloat
*) p
)[3]);
1728 params
[2] = IROUND64(((GLfloat
*) p
)[2]);
1730 params
[1] = IROUND64(((GLfloat
*) p
)[1]);
1732 params
[0] = IROUND64(((GLfloat
*) p
)[0]);
1736 params
[3] = FLOAT_TO_INT(((GLfloat
*) p
)[3]);
1738 params
[2] = FLOAT_TO_INT(((GLfloat
*) p
)[2]);
1740 params
[1] = FLOAT_TO_INT(((GLfloat
*) p
)[1]);
1742 params
[0] = FLOAT_TO_INT(((GLfloat
*) p
)[0]);
1745 case TYPE_DOUBLEN_2
:
1746 params
[1] = FLOAT_TO_INT(((GLdouble
*) p
)[1]);
1748 params
[0] = FLOAT_TO_INT(((GLdouble
*) p
)[0]);
1752 params
[3] = ((GLint
*) p
)[3];
1754 params
[2] = ((GLint
*) p
)[2];
1757 params
[1] = ((GLint
*) p
)[1];
1760 params
[0] = ((GLint
*) p
)[0];
1764 for (i
= 0; i
< v
.value_int_n
.n
; i
++)
1765 params
[i
] = INT_TO_BOOLEAN(v
.value_int_n
.ints
[i
]);
1769 params
[0] = ((GLint64
*) p
)[0];
1773 params
[0] = ((GLboolean
*) p
)[0];
1777 m
= *(GLmatrix
**) p
;
1778 for (i
= 0; i
< 16; i
++)
1779 params
[i
] = FLOAT_TO_INT64(m
->m
[i
]);
1783 m
= *(GLmatrix
**) p
;
1784 for (i
= 0; i
< 16; i
++)
1785 params
[i
] = FLOAT_TO_INT64(m
->m
[transpose
[i
]]);
1796 shift
= d
->type
- TYPE_BIT_0
;
1797 params
[0] = (*(GLbitfield
*) p
>> shift
) & 1;
1803 _mesa_GetDoublev(GLenum pname
, GLdouble
*params
)
1805 const struct value_desc
*d
;
1811 d
= find_value("glGetDoublev", pname
, &p
, &v
);
1816 params
[0] = d
->offset
;
1820 params
[7] = ((GLfloat
*) p
)[7];
1821 params
[6] = ((GLfloat
*) p
)[6];
1822 params
[5] = ((GLfloat
*) p
)[5];
1823 params
[4] = ((GLfloat
*) p
)[4];
1826 params
[3] = ((GLfloat
*) p
)[3];
1829 params
[2] = ((GLfloat
*) p
)[2];
1832 params
[1] = ((GLfloat
*) p
)[1];
1835 params
[0] = ((GLfloat
*) p
)[0];
1838 case TYPE_DOUBLEN_2
:
1839 params
[1] = ((GLdouble
*) p
)[1];
1841 params
[0] = ((GLdouble
*) p
)[0];
1845 params
[3] = ((GLint
*) p
)[3];
1847 params
[2] = ((GLint
*) p
)[2];
1850 params
[1] = ((GLint
*) p
)[1];
1853 params
[0] = ((GLint
*) p
)[0];
1857 for (i
= 0; i
< v
.value_int_n
.n
; i
++)
1858 params
[i
] = v
.value_int_n
.ints
[i
];
1862 params
[0] = (GLdouble
) (((GLint64
*) p
)[0]);
1866 params
[0] = *(GLboolean
*) p
;
1870 m
= *(GLmatrix
**) p
;
1871 for (i
= 0; i
< 16; i
++)
1872 params
[i
] = m
->m
[i
];
1876 m
= *(GLmatrix
**) p
;
1877 for (i
= 0; i
< 16; i
++)
1878 params
[i
] = m
->m
[transpose
[i
]];
1889 shift
= d
->type
- TYPE_BIT_0
;
1890 params
[0] = (*(GLbitfield
*) p
>> shift
) & 1;
1896 * Convert a GL texture binding enum such as GL_TEXTURE_BINDING_2D
1897 * into the corresponding Mesa texture target index.
1898 * \return TEXTURE_x_INDEX or -1 if binding is invalid
1901 tex_binding_to_index(const struct gl_context
*ctx
, GLenum binding
)
1904 case GL_TEXTURE_BINDING_1D
:
1905 return _mesa_is_desktop_gl(ctx
) ? TEXTURE_1D_INDEX
: -1;
1906 case GL_TEXTURE_BINDING_2D
:
1907 return TEXTURE_2D_INDEX
;
1908 case GL_TEXTURE_BINDING_3D
:
1909 return ctx
->API
!= API_OPENGLES
? TEXTURE_3D_INDEX
: -1;
1910 case GL_TEXTURE_BINDING_CUBE_MAP
:
1911 return ctx
->Extensions
.ARB_texture_cube_map
1912 ? TEXTURE_CUBE_INDEX
: -1;
1913 case GL_TEXTURE_BINDING_RECTANGLE
:
1914 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.NV_texture_rectangle
1915 ? TEXTURE_RECT_INDEX
: -1;
1916 case GL_TEXTURE_BINDING_1D_ARRAY
:
1917 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
1918 ? TEXTURE_1D_ARRAY_INDEX
: -1;
1919 case GL_TEXTURE_BINDING_2D_ARRAY
:
1920 return (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
)
1921 || _mesa_is_gles3(ctx
)
1922 ? TEXTURE_2D_ARRAY_INDEX
: -1;
1923 case GL_TEXTURE_BINDING_BUFFER
:
1924 return (_mesa_has_ARB_texture_buffer_object(ctx
) ||
1925 _mesa_has_OES_texture_buffer(ctx
)) ?
1926 TEXTURE_BUFFER_INDEX
: -1;
1927 case GL_TEXTURE_BINDING_CUBE_MAP_ARRAY
:
1928 return _mesa_has_texture_cube_map_array(ctx
)
1929 ? TEXTURE_CUBE_ARRAY_INDEX
: -1;
1930 case GL_TEXTURE_BINDING_2D_MULTISAMPLE
:
1931 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_multisample
1932 ? TEXTURE_2D_MULTISAMPLE_INDEX
: -1;
1933 case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY
:
1934 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_multisample
1935 ? TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX
: -1;
1941 static enum value_type
1942 find_value_indexed(const char *func
, GLenum pname
, GLuint index
, union value
*v
)
1944 GET_CURRENT_CONTEXT(ctx
);
1949 if (index
>= ctx
->Const
.MaxDrawBuffers
)
1951 if (!ctx
->Extensions
.EXT_draw_buffers2
)
1953 v
->value_int
= (ctx
->Color
.BlendEnabled
>> index
) & 1;
1958 case GL_BLEND_SRC_RGB
:
1959 if (index
>= ctx
->Const
.MaxDrawBuffers
)
1961 if (!ctx
->Extensions
.ARB_draw_buffers_blend
)
1963 v
->value_int
= ctx
->Color
.Blend
[index
].SrcRGB
;
1965 case GL_BLEND_SRC_ALPHA
:
1966 if (index
>= ctx
->Const
.MaxDrawBuffers
)
1968 if (!ctx
->Extensions
.ARB_draw_buffers_blend
)
1970 v
->value_int
= ctx
->Color
.Blend
[index
].SrcA
;
1974 case GL_BLEND_DST_RGB
:
1975 if (index
>= ctx
->Const
.MaxDrawBuffers
)
1977 if (!ctx
->Extensions
.ARB_draw_buffers_blend
)
1979 v
->value_int
= ctx
->Color
.Blend
[index
].DstRGB
;
1981 case GL_BLEND_DST_ALPHA
:
1982 if (index
>= ctx
->Const
.MaxDrawBuffers
)
1984 if (!ctx
->Extensions
.ARB_draw_buffers_blend
)
1986 v
->value_int
= ctx
->Color
.Blend
[index
].DstA
;
1988 case GL_BLEND_EQUATION_RGB
:
1989 if (index
>= ctx
->Const
.MaxDrawBuffers
)
1991 if (!ctx
->Extensions
.ARB_draw_buffers_blend
)
1993 v
->value_int
= ctx
->Color
.Blend
[index
].EquationRGB
;
1995 case GL_BLEND_EQUATION_ALPHA
:
1996 if (index
>= ctx
->Const
.MaxDrawBuffers
)
1998 if (!ctx
->Extensions
.ARB_draw_buffers_blend
)
2000 v
->value_int
= ctx
->Color
.Blend
[index
].EquationA
;
2003 case GL_COLOR_WRITEMASK
:
2004 if (index
>= ctx
->Const
.MaxDrawBuffers
)
2006 if (!ctx
->Extensions
.EXT_draw_buffers2
)
2008 v
->value_int_4
[0] = ctx
->Color
.ColorMask
[index
][RCOMP
] ? 1 : 0;
2009 v
->value_int_4
[1] = ctx
->Color
.ColorMask
[index
][GCOMP
] ? 1 : 0;
2010 v
->value_int_4
[2] = ctx
->Color
.ColorMask
[index
][BCOMP
] ? 1 : 0;
2011 v
->value_int_4
[3] = ctx
->Color
.ColorMask
[index
][ACOMP
] ? 1 : 0;
2014 case GL_SCISSOR_BOX
:
2015 if (index
>= ctx
->Const
.MaxViewports
)
2017 v
->value_int_4
[0] = ctx
->Scissor
.ScissorArray
[index
].X
;
2018 v
->value_int_4
[1] = ctx
->Scissor
.ScissorArray
[index
].Y
;
2019 v
->value_int_4
[2] = ctx
->Scissor
.ScissorArray
[index
].Width
;
2020 v
->value_int_4
[3] = ctx
->Scissor
.ScissorArray
[index
].Height
;
2023 case GL_WINDOW_RECTANGLE_EXT
:
2024 if (!ctx
->Extensions
.EXT_window_rectangles
)
2026 if (index
>= ctx
->Const
.MaxWindowRectangles
)
2028 v
->value_int_4
[0] = ctx
->Scissor
.WindowRects
[index
].X
;
2029 v
->value_int_4
[1] = ctx
->Scissor
.WindowRects
[index
].Y
;
2030 v
->value_int_4
[2] = ctx
->Scissor
.WindowRects
[index
].Width
;
2031 v
->value_int_4
[3] = ctx
->Scissor
.WindowRects
[index
].Height
;
2035 if (index
>= ctx
->Const
.MaxViewports
)
2037 v
->value_float_4
[0] = ctx
->ViewportArray
[index
].X
;
2038 v
->value_float_4
[1] = ctx
->ViewportArray
[index
].Y
;
2039 v
->value_float_4
[2] = ctx
->ViewportArray
[index
].Width
;
2040 v
->value_float_4
[3] = ctx
->ViewportArray
[index
].Height
;
2041 return TYPE_FLOAT_4
;
2043 case GL_DEPTH_RANGE
:
2044 if (index
>= ctx
->Const
.MaxViewports
)
2046 v
->value_double_2
[0] = ctx
->ViewportArray
[index
].Near
;
2047 v
->value_double_2
[1] = ctx
->ViewportArray
[index
].Far
;
2048 return TYPE_DOUBLEN_2
;
2050 case GL_TRANSFORM_FEEDBACK_BUFFER_START
:
2051 if (index
>= ctx
->Const
.MaxTransformFeedbackBuffers
)
2053 if (!ctx
->Extensions
.EXT_transform_feedback
)
2055 v
->value_int64
= ctx
->TransformFeedback
.CurrentObject
->Offset
[index
];
2058 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE
:
2059 if (index
>= ctx
->Const
.MaxTransformFeedbackBuffers
)
2061 if (!ctx
->Extensions
.EXT_transform_feedback
)
2064 = ctx
->TransformFeedback
.CurrentObject
->RequestedSize
[index
];
2067 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING
:
2068 if (index
>= ctx
->Const
.MaxTransformFeedbackBuffers
)
2070 if (!ctx
->Extensions
.EXT_transform_feedback
)
2072 v
->value_int
= ctx
->TransformFeedback
.CurrentObject
->BufferNames
[index
];
2075 case GL_UNIFORM_BUFFER_BINDING
:
2076 if (index
>= ctx
->Const
.MaxUniformBufferBindings
)
2078 if (!ctx
->Extensions
.ARB_uniform_buffer_object
)
2080 v
->value_int
= ctx
->UniformBufferBindings
[index
].BufferObject
->Name
;
2083 case GL_UNIFORM_BUFFER_START
:
2084 if (index
>= ctx
->Const
.MaxUniformBufferBindings
)
2086 if (!ctx
->Extensions
.ARB_uniform_buffer_object
)
2088 v
->value_int
= ctx
->UniformBufferBindings
[index
].Offset
< 0 ? 0 :
2089 ctx
->UniformBufferBindings
[index
].Offset
;
2092 case GL_UNIFORM_BUFFER_SIZE
:
2093 if (index
>= ctx
->Const
.MaxUniformBufferBindings
)
2095 if (!ctx
->Extensions
.ARB_uniform_buffer_object
)
2097 v
->value_int
= ctx
->UniformBufferBindings
[index
].Size
< 0 ? 0 :
2098 ctx
->UniformBufferBindings
[index
].Size
;
2101 /* ARB_shader_storage_buffer_object */
2102 case GL_SHADER_STORAGE_BUFFER_BINDING
:
2103 if (!ctx
->Extensions
.ARB_shader_storage_buffer_object
)
2105 if (index
>= ctx
->Const
.MaxShaderStorageBufferBindings
)
2107 v
->value_int
= ctx
->ShaderStorageBufferBindings
[index
].BufferObject
->Name
;
2110 case GL_SHADER_STORAGE_BUFFER_START
:
2111 if (!ctx
->Extensions
.ARB_shader_storage_buffer_object
)
2113 if (index
>= ctx
->Const
.MaxShaderStorageBufferBindings
)
2115 v
->value_int
= ctx
->ShaderStorageBufferBindings
[index
].Offset
< 0 ? 0 :
2116 ctx
->ShaderStorageBufferBindings
[index
].Offset
;
2119 case GL_SHADER_STORAGE_BUFFER_SIZE
:
2120 if (!ctx
->Extensions
.ARB_shader_storage_buffer_object
)
2122 if (index
>= ctx
->Const
.MaxShaderStorageBufferBindings
)
2124 v
->value_int
= ctx
->ShaderStorageBufferBindings
[index
].Size
< 0 ? 0 :
2125 ctx
->ShaderStorageBufferBindings
[index
].Size
;
2128 /* ARB_texture_multisample / GL3.2 */
2129 case GL_SAMPLE_MASK_VALUE
:
2132 if (!ctx
->Extensions
.ARB_texture_multisample
)
2134 v
->value_int
= ctx
->Multisample
.SampleMaskValue
;
2137 case GL_ATOMIC_COUNTER_BUFFER_BINDING
:
2138 if (!ctx
->Extensions
.ARB_shader_atomic_counters
)
2140 if (index
>= ctx
->Const
.MaxAtomicBufferBindings
)
2142 v
->value_int
= ctx
->AtomicBufferBindings
[index
].BufferObject
->Name
;
2145 case GL_ATOMIC_COUNTER_BUFFER_START
:
2146 if (!ctx
->Extensions
.ARB_shader_atomic_counters
)
2148 if (index
>= ctx
->Const
.MaxAtomicBufferBindings
)
2150 v
->value_int64
= ctx
->AtomicBufferBindings
[index
].Offset
;
2153 case GL_ATOMIC_COUNTER_BUFFER_SIZE
:
2154 if (!ctx
->Extensions
.ARB_shader_atomic_counters
)
2156 if (index
>= ctx
->Const
.MaxAtomicBufferBindings
)
2158 v
->value_int64
= ctx
->AtomicBufferBindings
[index
].Size
;
2161 case GL_VERTEX_BINDING_DIVISOR
:
2162 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_instanced_arrays
) &&
2163 !_mesa_is_gles31(ctx
))
2165 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
)
2167 v
->value_int
= ctx
->Array
.VAO
->BufferBinding
[VERT_ATTRIB_GENERIC(index
)].InstanceDivisor
;
2170 case GL_VERTEX_BINDING_OFFSET
:
2171 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles31(ctx
))
2173 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
)
2175 v
->value_int
= ctx
->Array
.VAO
->BufferBinding
[VERT_ATTRIB_GENERIC(index
)].Offset
;
2178 case GL_VERTEX_BINDING_STRIDE
:
2179 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles31(ctx
))
2181 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
)
2183 v
->value_int
= ctx
->Array
.VAO
->BufferBinding
[VERT_ATTRIB_GENERIC(index
)].Stride
;
2186 case GL_VERTEX_BINDING_BUFFER
:
2187 if (ctx
->API
== API_OPENGLES2
&& ctx
->Version
< 31)
2189 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
)
2191 v
->value_int
= ctx
->Array
.VAO
->BufferBinding
[VERT_ATTRIB_GENERIC(index
)].BufferObj
->Name
;
2194 /* ARB_shader_image_load_store */
2195 case GL_IMAGE_BINDING_NAME
: {
2196 struct gl_texture_object
*t
;
2198 if (!ctx
->Extensions
.ARB_shader_image_load_store
)
2200 if (index
>= ctx
->Const
.MaxImageUnits
)
2203 t
= ctx
->ImageUnits
[index
].TexObj
;
2204 v
->value_int
= (t
? t
->Name
: 0);
2208 case GL_IMAGE_BINDING_LEVEL
:
2209 if (!ctx
->Extensions
.ARB_shader_image_load_store
)
2211 if (index
>= ctx
->Const
.MaxImageUnits
)
2214 v
->value_int
= ctx
->ImageUnits
[index
].Level
;
2217 case GL_IMAGE_BINDING_LAYERED
:
2218 if (!ctx
->Extensions
.ARB_shader_image_load_store
)
2220 if (index
>= ctx
->Const
.MaxImageUnits
)
2223 v
->value_int
= ctx
->ImageUnits
[index
].Layered
;
2226 case GL_IMAGE_BINDING_LAYER
:
2227 if (!ctx
->Extensions
.ARB_shader_image_load_store
)
2229 if (index
>= ctx
->Const
.MaxImageUnits
)
2232 v
->value_int
= ctx
->ImageUnits
[index
].Layer
;
2235 case GL_IMAGE_BINDING_ACCESS
:
2236 if (!ctx
->Extensions
.ARB_shader_image_load_store
)
2238 if (index
>= ctx
->Const
.MaxImageUnits
)
2241 v
->value_int
= ctx
->ImageUnits
[index
].Access
;
2244 case GL_IMAGE_BINDING_FORMAT
:
2245 if (!ctx
->Extensions
.ARB_shader_image_load_store
)
2247 if (index
>= ctx
->Const
.MaxImageUnits
)
2250 v
->value_int
= ctx
->ImageUnits
[index
].Format
;
2253 /* ARB_direct_state_access */
2254 case GL_TEXTURE_BINDING_1D
:
2255 case GL_TEXTURE_BINDING_1D_ARRAY
:
2256 case GL_TEXTURE_BINDING_2D
:
2257 case GL_TEXTURE_BINDING_2D_ARRAY
:
2258 case GL_TEXTURE_BINDING_2D_MULTISAMPLE
:
2259 case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY
:
2260 case GL_TEXTURE_BINDING_3D
:
2261 case GL_TEXTURE_BINDING_BUFFER
:
2262 case GL_TEXTURE_BINDING_CUBE_MAP
:
2263 case GL_TEXTURE_BINDING_CUBE_MAP_ARRAY
:
2264 case GL_TEXTURE_BINDING_RECTANGLE
: {
2267 if (ctx
->API
!= API_OPENGL_CORE
)
2269 target
= tex_binding_to_index(ctx
, pname
);
2272 if (index
>= _mesa_max_tex_unit(ctx
))
2275 v
->value_int
= ctx
->Texture
.Unit
[index
].CurrentTex
[target
]->Name
;
2279 case GL_SAMPLER_BINDING
: {
2280 struct gl_sampler_object
*samp
;
2282 if (ctx
->API
!= API_OPENGL_CORE
)
2284 if (index
>= _mesa_max_tex_unit(ctx
))
2287 samp
= ctx
->Texture
.Unit
[index
].Sampler
;
2288 v
->value_int
= samp
? samp
->Name
: 0;
2292 case GL_MAX_COMPUTE_WORK_GROUP_COUNT
:
2293 if (!_mesa_has_compute_shaders(ctx
))
2297 v
->value_int
= ctx
->Const
.MaxComputeWorkGroupCount
[index
];
2300 case GL_MAX_COMPUTE_WORK_GROUP_SIZE
:
2301 if (!_mesa_has_compute_shaders(ctx
))
2305 v
->value_int
= ctx
->Const
.MaxComputeWorkGroupSize
[index
];
2308 /* ARB_compute_variable_group_size */
2309 case GL_MAX_COMPUTE_VARIABLE_GROUP_SIZE_ARB
:
2310 if (!ctx
->Extensions
.ARB_compute_variable_group_size
)
2314 v
->value_int
= ctx
->Const
.MaxComputeVariableGroupSize
[index
];
2319 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=%s)", func
,
2320 _mesa_enum_to_string(pname
));
2321 return TYPE_INVALID
;
2323 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(pname=%s)", func
,
2324 _mesa_enum_to_string(pname
));
2325 return TYPE_INVALID
;
2329 _mesa_GetBooleani_v( GLenum pname
, GLuint index
, GLboolean
*params
)
2332 enum value_type type
=
2333 find_value_indexed("glGetBooleani_v", pname
, index
, &v
);
2337 params
[0] = INT_TO_BOOLEAN(v
.value_int
);
2340 params
[0] = INT_TO_BOOLEAN(v
.value_int_4
[0]);
2341 params
[1] = INT_TO_BOOLEAN(v
.value_int_4
[1]);
2342 params
[2] = INT_TO_BOOLEAN(v
.value_int_4
[2]);
2343 params
[3] = INT_TO_BOOLEAN(v
.value_int_4
[3]);
2346 params
[0] = INT64_TO_BOOLEAN(v
.value_int64
);
2349 ; /* nothing - GL error was recorded */
2354 _mesa_GetIntegeri_v( GLenum pname
, GLuint index
, GLint
*params
)
2357 enum value_type type
=
2358 find_value_indexed("glGetIntegeri_v", pname
, index
, &v
);
2363 params
[3] = IROUND(v
.value_float_4
[3]);
2366 params
[2] = IROUND(v
.value_float_4
[2]);
2369 params
[1] = IROUND(v
.value_float_4
[1]);
2372 params
[0] = IROUND(v
.value_float_4
[0]);
2375 case TYPE_DOUBLEN_2
:
2376 params
[1] = IROUND(v
.value_double_2
[1]);
2378 params
[0] = IROUND(v
.value_double_2
[0]);
2382 params
[0] = v
.value_int
;
2385 params
[0] = v
.value_int_4
[0];
2386 params
[1] = v
.value_int_4
[1];
2387 params
[2] = v
.value_int_4
[2];
2388 params
[3] = v
.value_int_4
[3];
2391 params
[0] = INT64_TO_INT(v
.value_int64
);
2394 ; /* nothing - GL error was recorded */
2399 _mesa_GetInteger64i_v( GLenum pname
, GLuint index
, GLint64
*params
)
2402 enum value_type type
=
2403 find_value_indexed("glGetInteger64i_v", pname
, index
, &v
);
2407 params
[0] = v
.value_int
;
2410 params
[0] = v
.value_int_4
[0];
2411 params
[1] = v
.value_int_4
[1];
2412 params
[2] = v
.value_int_4
[2];
2413 params
[3] = v
.value_int_4
[3];
2416 params
[0] = v
.value_int64
;
2419 ; /* nothing - GL error was recorded */
2424 _mesa_GetFloati_v(GLenum pname
, GLuint index
, GLfloat
*params
)
2429 enum value_type type
=
2430 find_value_indexed("glGetFloati_v", pname
, index
, &v
);
2435 params
[3] = v
.value_float_4
[3];
2438 params
[2] = v
.value_float_4
[2];
2441 params
[1] = v
.value_float_4
[1];
2444 params
[0] = v
.value_float_4
[0];
2447 case TYPE_DOUBLEN_2
:
2448 params
[1] = (GLfloat
) v
.value_double_2
[1];
2450 params
[0] = (GLfloat
) v
.value_double_2
[0];
2454 params
[3] = (GLfloat
) v
.value_int_4
[3];
2456 params
[2] = (GLfloat
) v
.value_int_4
[2];
2459 params
[1] = (GLfloat
) v
.value_int_4
[1];
2462 params
[0] = (GLfloat
) v
.value_int_4
[0];
2466 for (i
= 0; i
< v
.value_int_n
.n
; i
++)
2467 params
[i
] = INT_TO_FLOAT(v
.value_int_n
.ints
[i
]);
2471 params
[0] = (GLfloat
) v
.value_int64
;
2475 params
[0] = BOOLEAN_TO_FLOAT(v
.value_bool
);
2479 m
= *(GLmatrix
**) &v
;
2480 for (i
= 0; i
< 16; i
++)
2481 params
[i
] = m
->m
[i
];
2485 m
= *(GLmatrix
**) &v
;
2486 for (i
= 0; i
< 16; i
++)
2487 params
[i
] = m
->m
[transpose
[i
]];
2496 _mesa_GetDoublei_v(GLenum pname
, GLuint index
, GLdouble
*params
)
2501 enum value_type type
=
2502 find_value_indexed("glGetDoublei_v", pname
, index
, &v
);
2507 params
[3] = (GLdouble
) v
.value_float_4
[3];
2510 params
[2] = (GLdouble
) v
.value_float_4
[2];
2513 params
[1] = (GLdouble
) v
.value_float_4
[1];
2516 params
[0] = (GLdouble
) v
.value_float_4
[0];
2519 case TYPE_DOUBLEN_2
:
2520 params
[1] = v
.value_double_2
[1];
2522 params
[0] = v
.value_double_2
[0];
2526 params
[3] = (GLdouble
) v
.value_int_4
[3];
2528 params
[2] = (GLdouble
) v
.value_int_4
[2];
2531 params
[1] = (GLdouble
) v
.value_int_4
[1];
2534 params
[0] = (GLdouble
) v
.value_int_4
[0];
2538 for (i
= 0; i
< v
.value_int_n
.n
; i
++)
2539 params
[i
] = (GLdouble
) INT_TO_FLOAT(v
.value_int_n
.ints
[i
]);
2543 params
[0] = (GLdouble
) v
.value_int64
;
2547 params
[0] = (GLdouble
) BOOLEAN_TO_FLOAT(v
.value_bool
);
2551 m
= *(GLmatrix
**) &v
;
2552 for (i
= 0; i
< 16; i
++)
2553 params
[i
] = (GLdouble
) m
->m
[i
];
2557 m
= *(GLmatrix
**) &v
;
2558 for (i
= 0; i
< 16; i
++)
2559 params
[i
] = (GLdouble
) m
->m
[transpose
[i
]];
2568 _mesa_GetFixedv(GLenum pname
, GLfixed
*params
)
2570 const struct value_desc
*d
;
2576 d
= find_value("glGetDoublev", pname
, &p
, &v
);
2581 params
[0] = INT_TO_FIXED(d
->offset
);
2586 params
[3] = FLOAT_TO_FIXED(((GLfloat
*) p
)[3]);
2589 params
[2] = FLOAT_TO_FIXED(((GLfloat
*) p
)[2]);
2592 params
[1] = FLOAT_TO_FIXED(((GLfloat
*) p
)[1]);
2595 params
[0] = FLOAT_TO_FIXED(((GLfloat
*) p
)[0]);
2598 case TYPE_DOUBLEN_2
:
2599 params
[1] = FLOAT_TO_FIXED(((GLdouble
*) p
)[1]);
2601 params
[0] = FLOAT_TO_FIXED(((GLdouble
*) p
)[0]);
2605 params
[3] = INT_TO_FIXED(((GLint
*) p
)[3]);
2607 params
[2] = INT_TO_FIXED(((GLint
*) p
)[2]);
2610 params
[1] = INT_TO_FIXED(((GLint
*) p
)[1]);
2613 params
[0] = INT_TO_FIXED(((GLint
*) p
)[0]);
2617 for (i
= 0; i
< v
.value_int_n
.n
; i
++)
2618 params
[i
] = INT_TO_FIXED(v
.value_int_n
.ints
[i
]);
2622 params
[0] = ((GLint64
*) p
)[0];
2626 params
[0] = BOOLEAN_TO_FIXED(((GLboolean
*) p
)[0]);
2630 m
= *(GLmatrix
**) p
;
2631 for (i
= 0; i
< 16; i
++)
2632 params
[i
] = FLOAT_TO_FIXED(m
->m
[i
]);
2636 m
= *(GLmatrix
**) p
;
2637 for (i
= 0; i
< 16; i
++)
2638 params
[i
] = FLOAT_TO_FIXED(m
->m
[transpose
[i
]]);
2649 shift
= d
->type
- TYPE_BIT_0
;
2650 params
[0] = BOOLEAN_TO_FIXED((*(GLbitfield
*) p
>> shift
) & 1);