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 EXTRA_EXT(ARB_texture_cube_map
);
440 EXTRA_EXT(EXT_texture_array
);
441 EXTRA_EXT(NV_fog_distance
);
442 EXTRA_EXT(EXT_texture_filter_anisotropic
);
443 EXTRA_EXT(NV_point_sprite
);
444 EXTRA_EXT(NV_texture_rectangle
);
445 EXTRA_EXT(EXT_stencil_two_side
);
446 EXTRA_EXT(EXT_depth_bounds_test
);
447 EXTRA_EXT(ARB_depth_clamp
);
448 EXTRA_EXT(ATI_fragment_shader
);
449 EXTRA_EXT(EXT_provoking_vertex
);
450 EXTRA_EXT(ARB_fragment_shader
);
451 EXTRA_EXT(ARB_fragment_program
);
452 EXTRA_EXT2(ARB_framebuffer_object
, EXT_framebuffer_multisample
);
453 EXTRA_EXT(ARB_seamless_cube_map
);
455 EXTRA_EXT(ARB_vertex_shader
);
456 EXTRA_EXT(EXT_transform_feedback
);
457 EXTRA_EXT(ARB_transform_feedback3
);
458 EXTRA_EXT(EXT_pixel_buffer_object
);
459 EXTRA_EXT(ARB_vertex_program
);
460 EXTRA_EXT2(NV_point_sprite
, ARB_point_sprite
);
461 EXTRA_EXT2(ARB_vertex_program
, ARB_fragment_program
);
462 EXTRA_EXT(ARB_color_buffer_float
);
463 EXTRA_EXT(EXT_framebuffer_sRGB
);
464 EXTRA_EXT(OES_EGL_image_external
);
465 EXTRA_EXT(ARB_blend_func_extended
);
466 EXTRA_EXT(ARB_uniform_buffer_object
);
467 EXTRA_EXT(ARB_timer_query
);
468 EXTRA_EXT2(ARB_texture_cube_map_array
, OES_texture_cube_map_array
);
469 EXTRA_EXT(ARB_texture_buffer_range
);
470 EXTRA_EXT(ARB_texture_multisample
);
471 EXTRA_EXT(ARB_texture_gather
);
472 EXTRA_EXT(ARB_shader_atomic_counters
);
473 EXTRA_EXT(ARB_draw_indirect
);
474 EXTRA_EXT(ARB_shader_image_load_store
);
475 EXTRA_EXT(ARB_viewport_array
);
476 EXTRA_EXT(ARB_query_buffer_object
);
477 EXTRA_EXT2(ARB_transform_feedback3
, ARB_gpu_shader5
);
478 EXTRA_EXT(INTEL_performance_query
);
479 EXTRA_EXT(ARB_explicit_uniform_location
);
480 EXTRA_EXT(ARB_clip_control
);
481 EXTRA_EXT(EXT_polygon_offset_clamp
);
482 EXTRA_EXT(ARB_framebuffer_no_attachments
);
483 EXTRA_EXT(ARB_tessellation_shader
);
484 EXTRA_EXT(ARB_shader_subroutine
);
485 EXTRA_EXT(ARB_shader_storage_buffer_object
);
486 EXTRA_EXT(ARB_indirect_parameters
);
487 EXTRA_EXT(ATI_meminfo
);
488 EXTRA_EXT(NVX_gpu_memory_info
);
489 EXTRA_EXT(ARB_cull_distance
);
490 EXTRA_EXT(EXT_window_rectangles
);
491 EXTRA_EXT(KHR_blend_equation_advanced_coherent
);
492 EXTRA_EXT(OES_primitive_bounding_box
);
493 EXTRA_EXT(ARB_compute_variable_group_size
);
496 extra_ARB_color_buffer_float_or_glcore
[] = {
497 EXT(ARB_color_buffer_float
),
503 extra_NV_primitive_restart
[] = {
504 EXT(NV_primitive_restart
),
508 static const int extra_version_30
[] = { EXTRA_VERSION_30
, EXTRA_END
};
509 static const int extra_version_31
[] = { EXTRA_VERSION_31
, EXTRA_END
};
510 static const int extra_version_32
[] = { EXTRA_VERSION_32
, EXTRA_END
};
512 static const int extra_gl30_es3
[] = {
518 static const int extra_gl32_es3
[] = {
524 static const int extra_version_32_OES_geometry_shader
[] = {
530 static const int extra_gl40_ARB_sample_shading
[] = {
532 EXT(ARB_sample_shading
),
537 extra_ARB_vertex_program_api_es2
[] = {
538 EXT(ARB_vertex_program
),
543 /* The ReadBuffer get token is valid under either full GL or under
544 * GLES2 if the NV_read_buffer extension is available. */
546 extra_NV_read_buffer_api_gl
[] = {
552 static const int extra_core_ARB_color_buffer_float_and_new_buffers
[] = {
554 EXT(ARB_color_buffer_float
),
559 static const int extra_EXT_shader_framebuffer_fetch
[] = {
562 EXT(MESA_shader_framebuffer_fetch
),
566 /* This is the big table describing all the enums we accept in
567 * glGet*v(). The table is partitioned into six parts: enums
568 * understood by all GL APIs (OpenGL, GLES and GLES2), enums shared
569 * between OpenGL and GLES, enums exclusive to GLES, etc for the
570 * remaining combinations. To look up the enums valid in a given API
571 * we will use a hash table specific to that API. These tables are in
572 * turn generated at build time and included through get_hash.h.
575 #include "get_hash.h"
577 /* All we need now is a way to look up the value struct from the enum.
578 * The code generated by gcc for the old generated big switch
579 * statement is a big, balanced, open coded if/else tree, essentially
580 * an unrolled binary search. It would be natural to sort the new
581 * enum table and use bsearch(), but we will use a read-only hash
582 * table instead. bsearch() has a nice guaranteed worst case
583 * performance, but we're also guaranteed to hit that worst case
584 * (log2(n) iterations) for about half the enums. Instead, using an
585 * open addressing hash table, we can find the enum on the first try
586 * for 80% of the enums, 1 collision for 10% and never more than 5
587 * collisions for any enum (typical numbers). And the code is very
588 * simple, even though it feels a little magic. */
591 * Handle irregular enums
593 * Some values don't conform to the "well-known type at context
594 * pointer + offset" pattern, so we have this function to catch all
595 * the corner cases. Typically, it's a computed value or a one-off
596 * pointer to a custom struct or something.
598 * In this case we can't return a pointer to the value, so we'll have
599 * to use the temporary variable 'v' declared back in the calling
600 * glGet*v() function to store the result.
602 * \param ctx the current context
603 * \param d the struct value_desc that describes the enum
604 * \param v pointer to the tmp declared in the calling glGet*v() function
607 find_custom_value(struct gl_context
*ctx
, const struct value_desc
*d
, union value
*v
)
609 struct gl_buffer_object
**buffer_obj
;
610 struct gl_vertex_attrib_array
*array
;
614 case GL_MAJOR_VERSION
:
615 v
->value_int
= ctx
->Version
/ 10;
617 case GL_MINOR_VERSION
:
618 v
->value_int
= ctx
->Version
% 10;
624 case GL_TEXTURE_CUBE_MAP
:
625 case GL_TEXTURE_RECTANGLE_NV
:
626 case GL_TEXTURE_EXTERNAL_OES
:
627 v
->value_bool
= _mesa_IsEnabled(d
->pname
);
630 case GL_LINE_STIPPLE_PATTERN
:
631 /* This is the only GLushort, special case it here by promoting
632 * to an int rather than introducing a new type. */
633 v
->value_int
= ctx
->Line
.StipplePattern
;
636 case GL_CURRENT_RASTER_TEXTURE_COORDS
:
637 unit
= ctx
->Texture
.CurrentUnit
;
638 v
->value_float_4
[0] = ctx
->Current
.RasterTexCoords
[unit
][0];
639 v
->value_float_4
[1] = ctx
->Current
.RasterTexCoords
[unit
][1];
640 v
->value_float_4
[2] = ctx
->Current
.RasterTexCoords
[unit
][2];
641 v
->value_float_4
[3] = ctx
->Current
.RasterTexCoords
[unit
][3];
644 case GL_CURRENT_TEXTURE_COORDS
:
645 unit
= ctx
->Texture
.CurrentUnit
;
646 v
->value_float_4
[0] = ctx
->Current
.Attrib
[VERT_ATTRIB_TEX0
+ unit
][0];
647 v
->value_float_4
[1] = ctx
->Current
.Attrib
[VERT_ATTRIB_TEX0
+ unit
][1];
648 v
->value_float_4
[2] = ctx
->Current
.Attrib
[VERT_ATTRIB_TEX0
+ unit
][2];
649 v
->value_float_4
[3] = ctx
->Current
.Attrib
[VERT_ATTRIB_TEX0
+ unit
][3];
652 case GL_COLOR_WRITEMASK
:
653 v
->value_int_4
[0] = ctx
->Color
.ColorMask
[0][RCOMP
] ? 1 : 0;
654 v
->value_int_4
[1] = ctx
->Color
.ColorMask
[0][GCOMP
] ? 1 : 0;
655 v
->value_int_4
[2] = ctx
->Color
.ColorMask
[0][BCOMP
] ? 1 : 0;
656 v
->value_int_4
[3] = ctx
->Color
.ColorMask
[0][ACOMP
] ? 1 : 0;
660 v
->value_bool
= ctx
->Current
.Attrib
[VERT_ATTRIB_EDGEFLAG
][0] == 1.0F
;
664 v
->value_enum
= ctx
->ReadBuffer
->ColorReadBuffer
;
667 case GL_MAP2_GRID_DOMAIN
:
668 v
->value_float_4
[0] = ctx
->Eval
.MapGrid2u1
;
669 v
->value_float_4
[1] = ctx
->Eval
.MapGrid2u2
;
670 v
->value_float_4
[2] = ctx
->Eval
.MapGrid2v1
;
671 v
->value_float_4
[3] = ctx
->Eval
.MapGrid2v2
;
674 case GL_TEXTURE_STACK_DEPTH
:
675 unit
= ctx
->Texture
.CurrentUnit
;
676 v
->value_int
= ctx
->TextureMatrixStack
[unit
].Depth
+ 1;
678 case GL_TEXTURE_MATRIX
:
679 unit
= ctx
->Texture
.CurrentUnit
;
680 v
->value_matrix
= ctx
->TextureMatrixStack
[unit
].Top
;
683 case GL_TEXTURE_COORD_ARRAY
:
684 case GL_TEXTURE_COORD_ARRAY_SIZE
:
685 case GL_TEXTURE_COORD_ARRAY_TYPE
:
686 case GL_TEXTURE_COORD_ARRAY_STRIDE
:
687 array
= &ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_TEX(ctx
->Array
.ActiveTexture
)];
688 v
->value_int
= *(GLuint
*) ((char *) array
+ d
->offset
);
691 case GL_ACTIVE_TEXTURE_ARB
:
692 v
->value_int
= GL_TEXTURE0_ARB
+ ctx
->Texture
.CurrentUnit
;
694 case GL_CLIENT_ACTIVE_TEXTURE_ARB
:
695 v
->value_int
= GL_TEXTURE0_ARB
+ ctx
->Array
.ActiveTexture
;
698 case GL_MODELVIEW_STACK_DEPTH
:
699 case GL_PROJECTION_STACK_DEPTH
:
700 v
->value_int
= *(GLint
*) ((char *) ctx
+ d
->offset
) + 1;
703 case GL_MAX_TEXTURE_SIZE
:
704 case GL_MAX_3D_TEXTURE_SIZE
:
705 case GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB
:
706 p
= (GLuint
*) ((char *) ctx
+ d
->offset
);
707 v
->value_int
= 1 << (*p
- 1);
711 v
->value_int_4
[0] = ctx
->Scissor
.ScissorArray
[0].X
;
712 v
->value_int_4
[1] = ctx
->Scissor
.ScissorArray
[0].Y
;
713 v
->value_int_4
[2] = ctx
->Scissor
.ScissorArray
[0].Width
;
714 v
->value_int_4
[3] = ctx
->Scissor
.ScissorArray
[0].Height
;
717 case GL_SCISSOR_TEST
:
718 v
->value_bool
= ctx
->Scissor
.EnableFlags
& 1;
723 ctx
->ListState
.CurrentList
? ctx
->ListState
.CurrentList
->Name
: 0;
726 if (!ctx
->CompileFlag
)
728 else if (ctx
->ExecuteFlag
)
729 v
->value_enum
= GL_COMPILE_AND_EXECUTE
;
731 v
->value_enum
= GL_COMPILE
;
735 v
->value_float_4
[0] = ctx
->ViewportArray
[0].X
;
736 v
->value_float_4
[1] = ctx
->ViewportArray
[0].Y
;
737 v
->value_float_4
[2] = ctx
->ViewportArray
[0].Width
;
738 v
->value_float_4
[3] = ctx
->ViewportArray
[0].Height
;
742 v
->value_double_2
[0] = ctx
->ViewportArray
[0].Near
;
743 v
->value_double_2
[1] = ctx
->ViewportArray
[0].Far
;
746 case GL_ACTIVE_STENCIL_FACE_EXT
:
747 v
->value_enum
= ctx
->Stencil
.ActiveFace
? GL_BACK
: GL_FRONT
;
750 case GL_STENCIL_FAIL
:
751 v
->value_enum
= ctx
->Stencil
.FailFunc
[ctx
->Stencil
.ActiveFace
];
753 case GL_STENCIL_FUNC
:
754 v
->value_enum
= ctx
->Stencil
.Function
[ctx
->Stencil
.ActiveFace
];
756 case GL_STENCIL_PASS_DEPTH_FAIL
:
757 v
->value_enum
= ctx
->Stencil
.ZFailFunc
[ctx
->Stencil
.ActiveFace
];
759 case GL_STENCIL_PASS_DEPTH_PASS
:
760 v
->value_enum
= ctx
->Stencil
.ZPassFunc
[ctx
->Stencil
.ActiveFace
];
763 v
->value_int
= _mesa_get_stencil_ref(ctx
, ctx
->Stencil
.ActiveFace
);
765 case GL_STENCIL_BACK_REF
:
766 v
->value_int
= _mesa_get_stencil_ref(ctx
, 1);
768 case GL_STENCIL_VALUE_MASK
:
769 v
->value_int
= ctx
->Stencil
.ValueMask
[ctx
->Stencil
.ActiveFace
];
771 case GL_STENCIL_WRITEMASK
:
772 v
->value_int
= ctx
->Stencil
.WriteMask
[ctx
->Stencil
.ActiveFace
];
775 case GL_NUM_EXTENSIONS
:
776 v
->value_int
= _mesa_get_extension_count(ctx
);
779 case GL_IMPLEMENTATION_COLOR_READ_TYPE_OES
:
780 v
->value_int
= _mesa_get_color_read_type(ctx
);
782 case GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES
:
783 v
->value_int
= _mesa_get_color_read_format(ctx
);
786 case GL_CURRENT_MATRIX_STACK_DEPTH_ARB
:
787 v
->value_int
= ctx
->CurrentStack
->Depth
+ 1;
789 case GL_CURRENT_MATRIX_ARB
:
790 case GL_TRANSPOSE_CURRENT_MATRIX_ARB
:
791 v
->value_matrix
= ctx
->CurrentStack
->Top
;
794 case GL_NUM_COMPRESSED_TEXTURE_FORMATS_ARB
:
795 v
->value_int
= _mesa_get_compressed_formats(ctx
, NULL
);
797 case GL_COMPRESSED_TEXTURE_FORMATS_ARB
:
799 _mesa_get_compressed_formats(ctx
, v
->value_int_n
.ints
);
800 assert(v
->value_int_n
.n
<= (int) ARRAY_SIZE(v
->value_int_n
.ints
));
803 case GL_MAX_VARYING_FLOATS_ARB
:
804 v
->value_int
= ctx
->Const
.MaxVarying
* 4;
807 /* Various object names */
809 case GL_TEXTURE_BINDING_1D
:
810 case GL_TEXTURE_BINDING_2D
:
811 case GL_TEXTURE_BINDING_3D
:
812 case GL_TEXTURE_BINDING_1D_ARRAY_EXT
:
813 case GL_TEXTURE_BINDING_2D_ARRAY_EXT
:
814 case GL_TEXTURE_BINDING_CUBE_MAP_ARB
:
815 case GL_TEXTURE_BINDING_RECTANGLE_NV
:
816 case GL_TEXTURE_BINDING_EXTERNAL_OES
:
817 case GL_TEXTURE_BINDING_CUBE_MAP_ARRAY
:
818 case GL_TEXTURE_BINDING_2D_MULTISAMPLE
:
819 case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY
:
820 unit
= ctx
->Texture
.CurrentUnit
;
822 ctx
->Texture
.Unit
[unit
].CurrentTex
[d
->offset
]->Name
;
825 /* GL_EXT_packed_float */
826 case GL_RGBA_SIGNED_COMPONENTS_EXT
:
828 /* Note: we only check the 0th color attachment. */
829 const struct gl_renderbuffer
*rb
=
830 ctx
->DrawBuffer
->_ColorDrawBuffers
[0];
831 if (rb
&& _mesa_is_format_signed(rb
->Format
)) {
832 /* Issue 17 of GL_EXT_packed_float: If a component (such as
833 * alpha) has zero bits, the component should not be considered
834 * signed and so the bit for the respective component should be
838 _mesa_get_format_bits(rb
->Format
, GL_RED_BITS
);
840 _mesa_get_format_bits(rb
->Format
, GL_GREEN_BITS
);
842 _mesa_get_format_bits(rb
->Format
, GL_BLUE_BITS
);
844 _mesa_get_format_bits(rb
->Format
, GL_ALPHA_BITS
);
846 _mesa_get_format_bits(rb
->Format
, GL_TEXTURE_LUMINANCE_SIZE
);
848 _mesa_get_format_bits(rb
->Format
, GL_TEXTURE_INTENSITY_SIZE
);
850 v
->value_int_4
[0] = r_bits
+ l_bits
+ i_bits
> 0;
851 v
->value_int_4
[1] = g_bits
+ l_bits
+ i_bits
> 0;
852 v
->value_int_4
[2] = b_bits
+ l_bits
+ i_bits
> 0;
853 v
->value_int_4
[3] = a_bits
+ i_bits
> 0;
859 v
->value_int_4
[3] = 0;
864 /* GL_ARB_vertex_buffer_object */
865 case GL_VERTEX_ARRAY_BUFFER_BINDING_ARB
:
866 case GL_NORMAL_ARRAY_BUFFER_BINDING_ARB
:
867 case GL_COLOR_ARRAY_BUFFER_BINDING_ARB
:
868 case GL_INDEX_ARRAY_BUFFER_BINDING_ARB
:
869 case GL_EDGE_FLAG_ARRAY_BUFFER_BINDING_ARB
:
870 case GL_SECONDARY_COLOR_ARRAY_BUFFER_BINDING_ARB
:
871 case GL_FOG_COORDINATE_ARRAY_BUFFER_BINDING_ARB
:
872 buffer_obj
= (struct gl_buffer_object
**)
873 ((char *) ctx
->Array
.VAO
+ d
->offset
);
874 v
->value_int
= (*buffer_obj
)->Name
;
876 case GL_ARRAY_BUFFER_BINDING_ARB
:
877 v
->value_int
= ctx
->Array
.ArrayBufferObj
->Name
;
879 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING_ARB
:
881 ctx
->Array
.VAO
->VertexBinding
[VERT_ATTRIB_TEX(ctx
->Array
.ActiveTexture
)].BufferObj
->Name
;
883 case GL_ELEMENT_ARRAY_BUFFER_BINDING_ARB
:
884 v
->value_int
= ctx
->Array
.VAO
->IndexBufferObj
->Name
;
887 /* ARB_vertex_array_bgra */
888 case GL_COLOR_ARRAY_SIZE
:
889 array
= &ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_COLOR0
];
890 v
->value_int
= array
->Format
== GL_BGRA
? GL_BGRA
: array
->Size
;
892 case GL_SECONDARY_COLOR_ARRAY_SIZE
:
893 array
= &ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_COLOR1
];
894 v
->value_int
= array
->Format
== GL_BGRA
? GL_BGRA
: array
->Size
;
897 /* ARB_copy_buffer */
898 case GL_COPY_READ_BUFFER
:
899 v
->value_int
= ctx
->CopyReadBuffer
->Name
;
901 case GL_COPY_WRITE_BUFFER
:
902 v
->value_int
= ctx
->CopyWriteBuffer
->Name
;
905 case GL_PIXEL_PACK_BUFFER_BINDING_EXT
:
906 v
->value_int
= ctx
->Pack
.BufferObj
->Name
;
908 case GL_PIXEL_UNPACK_BUFFER_BINDING_EXT
:
909 v
->value_int
= ctx
->Unpack
.BufferObj
->Name
;
911 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING
:
912 v
->value_int
= ctx
->TransformFeedback
.CurrentBuffer
->Name
;
914 case GL_TRANSFORM_FEEDBACK_BUFFER_PAUSED
:
915 v
->value_int
= ctx
->TransformFeedback
.CurrentObject
->Paused
;
917 case GL_TRANSFORM_FEEDBACK_BUFFER_ACTIVE
:
918 v
->value_int
= ctx
->TransformFeedback
.CurrentObject
->Active
;
920 case GL_TRANSFORM_FEEDBACK_BINDING
:
921 v
->value_int
= ctx
->TransformFeedback
.CurrentObject
->Name
;
923 case GL_CURRENT_PROGRAM
:
924 /* The Changelog of the ARB_separate_shader_objects spec says:
926 * 24 25 Jul 2011 pbrown Remove the language erroneously deleting
927 * CURRENT_PROGRAM. In the EXT extension, this
928 * token was aliased to ACTIVE_PROGRAM_EXT, and
929 * was used to indicate the last program set by
930 * either ActiveProgramEXT or UseProgram. In
931 * the ARB extension, the SSO active programs
932 * are now program pipeline object state and
933 * CURRENT_PROGRAM should still be used to query
934 * the last program set by UseProgram (bug 7822).
937 ctx
->Shader
.ActiveProgram
? ctx
->Shader
.ActiveProgram
->Name
: 0;
939 case GL_READ_FRAMEBUFFER_BINDING_EXT
:
940 v
->value_int
= ctx
->ReadBuffer
->Name
;
942 case GL_RENDERBUFFER_BINDING_EXT
:
944 ctx
->CurrentRenderbuffer
? ctx
->CurrentRenderbuffer
->Name
: 0;
946 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES
:
947 v
->value_int
= ctx
->Array
.VAO
->VertexBinding
[VERT_ATTRIB_POINT_SIZE
].BufferObj
->Name
;
951 if (_mesa_get_clamp_fragment_color(ctx
, ctx
->DrawBuffer
))
952 COPY_4FV(v
->value_float_4
, ctx
->Fog
.Color
);
954 COPY_4FV(v
->value_float_4
, ctx
->Fog
.ColorUnclamped
);
956 case GL_COLOR_CLEAR_VALUE
:
957 if (_mesa_get_clamp_fragment_color(ctx
, ctx
->DrawBuffer
)) {
958 v
->value_float_4
[0] = CLAMP(ctx
->Color
.ClearColor
.f
[0], 0.0F
, 1.0F
);
959 v
->value_float_4
[1] = CLAMP(ctx
->Color
.ClearColor
.f
[1], 0.0F
, 1.0F
);
960 v
->value_float_4
[2] = CLAMP(ctx
->Color
.ClearColor
.f
[2], 0.0F
, 1.0F
);
961 v
->value_float_4
[3] = CLAMP(ctx
->Color
.ClearColor
.f
[3], 0.0F
, 1.0F
);
963 COPY_4FV(v
->value_float_4
, ctx
->Color
.ClearColor
.f
);
965 case GL_BLEND_COLOR_EXT
:
966 if (_mesa_get_clamp_fragment_color(ctx
, ctx
->DrawBuffer
))
967 COPY_4FV(v
->value_float_4
, ctx
->Color
.BlendColor
);
969 COPY_4FV(v
->value_float_4
, ctx
->Color
.BlendColorUnclamped
);
971 case GL_ALPHA_TEST_REF
:
972 if (_mesa_get_clamp_fragment_color(ctx
, ctx
->DrawBuffer
))
973 v
->value_float
= ctx
->Color
.AlphaRef
;
975 v
->value_float
= ctx
->Color
.AlphaRefUnclamped
;
977 case GL_MAX_VERTEX_UNIFORM_VECTORS
:
978 v
->value_int
= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxUniformComponents
/ 4;
981 case GL_MAX_FRAGMENT_UNIFORM_VECTORS
:
982 v
->value_int
= ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxUniformComponents
/ 4;
985 /* GL_ARB_texture_buffer_object */
986 case GL_TEXTURE_BUFFER_ARB
:
987 v
->value_int
= ctx
->Texture
.BufferObject
->Name
;
989 case GL_TEXTURE_BINDING_BUFFER_ARB
:
990 unit
= ctx
->Texture
.CurrentUnit
;
992 ctx
->Texture
.Unit
[unit
].CurrentTex
[TEXTURE_BUFFER_INDEX
]->Name
;
994 case GL_TEXTURE_BUFFER_DATA_STORE_BINDING_ARB
:
996 struct gl_buffer_object
*buf
=
997 ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
]
998 .CurrentTex
[TEXTURE_BUFFER_INDEX
]->BufferObject
;
999 v
->value_int
= buf
? buf
->Name
: 0;
1002 case GL_TEXTURE_BUFFER_FORMAT_ARB
:
1003 v
->value_int
= ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
]
1004 .CurrentTex
[TEXTURE_BUFFER_INDEX
]->BufferObjectFormat
;
1007 /* GL_ARB_sampler_objects */
1008 case GL_SAMPLER_BINDING
:
1010 struct gl_sampler_object
*samp
=
1011 ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
].Sampler
;
1012 v
->value_int
= samp
? samp
->Name
: 0;
1015 /* GL_ARB_uniform_buffer_object */
1016 case GL_UNIFORM_BUFFER_BINDING
:
1017 v
->value_int
= ctx
->UniformBuffer
->Name
;
1019 /* GL_ARB_shader_storage_buffer_object */
1020 case GL_SHADER_STORAGE_BUFFER_BINDING
:
1021 v
->value_int
= ctx
->ShaderStorageBuffer
->Name
;
1023 /* GL_ARB_query_buffer_object */
1024 case GL_QUERY_BUFFER_BINDING
:
1025 v
->value_int
= ctx
->QueryBuffer
->Name
;
1027 /* GL_ARB_timer_query */
1029 if (ctx
->Driver
.GetTimestamp
) {
1030 v
->value_int64
= ctx
->Driver
.GetTimestamp(ctx
);
1033 _mesa_problem(ctx
, "driver doesn't implement GetTimestamp");
1037 case GL_DEBUG_OUTPUT
:
1038 case GL_DEBUG_OUTPUT_SYNCHRONOUS
:
1039 case GL_DEBUG_LOGGED_MESSAGES
:
1040 case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH
:
1041 case GL_DEBUG_GROUP_STACK_DEPTH
:
1042 v
->value_int
= _mesa_get_debug_state_int(ctx
, d
->pname
);
1044 /* GL_ARB_shader_atomic_counters */
1045 case GL_ATOMIC_COUNTER_BUFFER_BINDING
:
1046 if (ctx
->AtomicBuffer
) {
1047 v
->value_int
= ctx
->AtomicBuffer
->Name
;
1052 /* GL_ARB_draw_indirect */
1053 case GL_DRAW_INDIRECT_BUFFER_BINDING
:
1054 v
->value_int
= ctx
->DrawIndirectBuffer
->Name
;
1056 /* GL_ARB_indirect_parameters */
1057 case GL_PARAMETER_BUFFER_BINDING_ARB
:
1058 v
->value_int
= ctx
->ParameterBuffer
->Name
;
1060 /* GL_ARB_separate_shader_objects */
1061 case GL_PROGRAM_PIPELINE_BINDING
:
1062 if (ctx
->Pipeline
.Current
) {
1063 v
->value_int
= ctx
->Pipeline
.Current
->Name
;
1068 /* GL_ARB_compute_shader */
1069 case GL_DISPATCH_INDIRECT_BUFFER_BINDING
:
1070 v
->value_int
= ctx
->DispatchIndirectBuffer
->Name
;
1072 /* GL_ARB_multisample */
1074 v
->value_int
= _mesa_geometric_samples(ctx
->DrawBuffer
);
1076 case GL_SAMPLE_BUFFERS
:
1077 v
->value_int
= _mesa_geometric_samples(ctx
->DrawBuffer
) > 0;
1079 /* GL_ATI_meminfo & GL_NVX_gpu_memory_info */
1080 case GL_VBO_FREE_MEMORY_ATI
:
1081 case GL_TEXTURE_FREE_MEMORY_ATI
:
1082 case GL_RENDERBUFFER_FREE_MEMORY_ATI
:
1083 case GL_GPU_MEMORY_INFO_DEDICATED_VIDMEM_NVX
:
1084 case GL_GPU_MEMORY_INFO_TOTAL_AVAILABLE_MEMORY_NVX
:
1085 case GL_GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX
:
1086 case GL_GPU_MEMORY_INFO_EVICTION_COUNT_NVX
:
1087 case GL_GPU_MEMORY_INFO_EVICTED_MEMORY_NVX
:
1089 struct gl_memory_info info
;
1091 ctx
->Driver
.QueryMemoryInfo(ctx
, &info
);
1093 if (d
->pname
== GL_GPU_MEMORY_INFO_DEDICATED_VIDMEM_NVX
)
1094 v
->value_int
= info
.total_device_memory
;
1095 else if (d
->pname
== GL_GPU_MEMORY_INFO_TOTAL_AVAILABLE_MEMORY_NVX
)
1096 v
->value_int
= info
.total_device_memory
+
1097 info
.total_staging_memory
;
1098 else if (d
->pname
== GL_GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX
)
1099 v
->value_int
= info
.avail_device_memory
;
1100 else if (d
->pname
== GL_GPU_MEMORY_INFO_EVICTION_COUNT_NVX
)
1101 v
->value_int
= info
.nr_device_memory_evictions
;
1102 else if (d
->pname
== GL_GPU_MEMORY_INFO_EVICTED_MEMORY_NVX
)
1103 v
->value_int
= info
.device_memory_evicted
;
1105 /* ATI free memory enums.
1107 * Since the GPU memory is (usually) page-table based, every two
1108 * consecutive elements are equal. From the GL_ATI_meminfo
1111 * "param[0] - total memory free in the pool
1112 * param[1] - largest available free block in the pool
1113 * param[2] - total auxiliary memory free
1114 * param[3] - largest auxiliary free block"
1116 * All three (VBO, TEXTURE, RENDERBUFFER) queries return
1117 * the same numbers here.
1119 v
->value_int_4
[0] = info
.avail_device_memory
;
1120 v
->value_int_4
[1] = info
.avail_device_memory
;
1121 v
->value_int_4
[2] = info
.avail_staging_memory
;
1122 v
->value_int_4
[3] = info
.avail_staging_memory
;
1130 * Check extra constraints on a struct value_desc descriptor
1132 * If a struct value_desc has a non-NULL extra pointer, it means that
1133 * there are a number of extra constraints to check or actions to
1134 * perform. The extras is just an integer array where each integer
1135 * encode different constraints or actions.
1137 * \param ctx current context
1138 * \param func name of calling glGet*v() function for error reporting
1139 * \param d the struct value_desc that has the extra constraints
1141 * \return GL_FALSE if all of the constraints were not satisfied,
1142 * otherwise GL_TRUE.
1145 check_extra(struct gl_context
*ctx
, const char *func
, const struct value_desc
*d
)
1147 const GLuint version
= ctx
->Version
;
1148 GLboolean api_check
= GL_FALSE
;
1149 GLboolean api_found
= GL_FALSE
;
1152 for (e
= d
->extra
; *e
!= EXTRA_END
; e
++) {
1154 case EXTRA_VERSION_30
:
1155 api_check
= GL_TRUE
;
1157 api_found
= GL_TRUE
;
1159 case EXTRA_VERSION_31
:
1160 api_check
= GL_TRUE
;
1162 api_found
= GL_TRUE
;
1164 case EXTRA_VERSION_32
:
1165 api_check
= GL_TRUE
;
1167 api_found
= GL_TRUE
;
1169 case EXTRA_NEW_FRAG_CLAMP
:
1170 if (ctx
->NewState
& (_NEW_BUFFERS
| _NEW_FRAG_CLAMP
))
1171 _mesa_update_state(ctx
);
1174 api_check
= GL_TRUE
;
1175 if (ctx
->API
== API_OPENGLES2
)
1176 api_found
= GL_TRUE
;
1179 api_check
= GL_TRUE
;
1180 if (_mesa_is_gles3(ctx
))
1181 api_found
= GL_TRUE
;
1183 case EXTRA_API_ES31
:
1184 api_check
= GL_TRUE
;
1185 if (_mesa_is_gles31(ctx
))
1186 api_found
= GL_TRUE
;
1188 case EXTRA_API_ES32
:
1189 api_check
= GL_TRUE
;
1190 if (_mesa_is_gles32(ctx
))
1191 api_found
= GL_TRUE
;
1194 api_check
= GL_TRUE
;
1195 if (_mesa_is_desktop_gl(ctx
))
1196 api_found
= GL_TRUE
;
1198 case EXTRA_API_GL_CORE
:
1199 api_check
= GL_TRUE
;
1200 if (ctx
->API
== API_OPENGL_CORE
)
1201 api_found
= GL_TRUE
;
1203 case EXTRA_NEW_BUFFERS
:
1204 if (ctx
->NewState
& _NEW_BUFFERS
)
1205 _mesa_update_state(ctx
);
1207 case EXTRA_FLUSH_CURRENT
:
1208 FLUSH_CURRENT(ctx
, 0);
1210 case EXTRA_VALID_DRAW_BUFFER
:
1211 if (d
->pname
- GL_DRAW_BUFFER0_ARB
>= ctx
->Const
.MaxDrawBuffers
) {
1212 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(draw buffer %u)",
1213 func
, d
->pname
- GL_DRAW_BUFFER0_ARB
);
1217 case EXTRA_VALID_TEXTURE_UNIT
:
1218 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureCoordUnits
) {
1219 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(texture %u)",
1220 func
, ctx
->Texture
.CurrentUnit
);
1224 case EXTRA_VALID_CLIP_DISTANCE
:
1225 if (d
->pname
- GL_CLIP_DISTANCE0
>= ctx
->Const
.MaxClipPlanes
) {
1226 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(clip distance %u)",
1227 func
, d
->pname
- GL_CLIP_DISTANCE0
);
1231 case EXTRA_GLSL_130
:
1232 api_check
= GL_TRUE
;
1233 if (ctx
->Const
.GLSLVersion
>= 130)
1234 api_found
= GL_TRUE
;
1236 case EXTRA_EXT_UBO_GS
:
1237 api_check
= GL_TRUE
;
1238 if (ctx
->Extensions
.ARB_uniform_buffer_object
&&
1239 _mesa_has_geometry_shaders(ctx
))
1240 api_found
= GL_TRUE
;
1242 case EXTRA_EXT_ATOMICS_GS
:
1243 api_check
= GL_TRUE
;
1244 if (ctx
->Extensions
.ARB_shader_atomic_counters
&&
1245 _mesa_has_geometry_shaders(ctx
))
1246 api_found
= GL_TRUE
;
1248 case EXTRA_EXT_SHADER_IMAGE_GS
:
1249 api_check
= GL_TRUE
;
1250 if (ctx
->Extensions
.ARB_shader_image_load_store
&&
1251 _mesa_has_geometry_shaders(ctx
))
1252 api_found
= GL_TRUE
;
1254 case EXTRA_EXT_ATOMICS_TESS
:
1255 api_check
= GL_TRUE
;
1256 api_found
= ctx
->Extensions
.ARB_shader_atomic_counters
&&
1257 _mesa_has_tessellation(ctx
);
1259 case EXTRA_EXT_SHADER_IMAGE_TESS
:
1260 api_check
= GL_TRUE
;
1261 api_found
= ctx
->Extensions
.ARB_shader_image_load_store
&&
1262 _mesa_has_tessellation(ctx
);
1264 case EXTRA_EXT_SSBO_GS
:
1265 api_check
= GL_TRUE
;
1266 if (ctx
->Extensions
.ARB_shader_storage_buffer_object
&&
1267 _mesa_has_geometry_shaders(ctx
))
1268 api_found
= GL_TRUE
;
1270 case EXTRA_EXT_FB_NO_ATTACH_GS
:
1271 api_check
= GL_TRUE
;
1272 if (ctx
->Extensions
.ARB_framebuffer_no_attachments
&&
1273 (_mesa_is_desktop_gl(ctx
) ||
1274 _mesa_has_OES_geometry_shader(ctx
)))
1275 api_found
= GL_TRUE
;
1277 case EXTRA_EXT_ES_GS
:
1278 api_check
= GL_TRUE
;
1279 if (_mesa_has_OES_geometry_shader(ctx
))
1280 api_found
= GL_TRUE
;
1284 default: /* *e is a offset into the extension struct */
1285 api_check
= GL_TRUE
;
1286 if (*(GLboolean
*) ((char *) &ctx
->Extensions
+ *e
))
1287 api_found
= GL_TRUE
;
1292 if (api_check
&& !api_found
) {
1293 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=%s)", func
,
1294 _mesa_enum_to_string(d
->pname
));
1301 static const struct value_desc error_value
=
1302 { 0, 0, TYPE_INVALID
, NO_OFFSET
, NO_EXTRA
};
1305 * Find the struct value_desc corresponding to the enum 'pname'.
1307 * We hash the enum value to get an index into the 'table' array,
1308 * which holds the index in the 'values' array of struct value_desc.
1309 * Once we've found the entry, we do the extra checks, if any, then
1310 * look up the value and return a pointer to it.
1312 * If the value has to be computed (for example, it's the result of a
1313 * function call or we need to add 1 to it), we use the tmp 'v' to
1316 * \param func name of glGet*v() func for error reporting
1317 * \param pname the enum value we're looking up
1318 * \param p is were we return the pointer to the value
1319 * \param v a tmp union value variable in the calling glGet*v() function
1321 * \return the struct value_desc corresponding to the enum or a struct
1322 * value_desc of TYPE_INVALID if not found. This lets the calling
1323 * glGet*v() function jump right into a switch statement and
1324 * handle errors there instead of having to check for NULL.
1326 static const struct value_desc
*
1327 find_value(const char *func
, GLenum pname
, void **p
, union value
*v
)
1329 GET_CURRENT_CONTEXT(ctx
);
1330 struct gl_texture_unit
*unit
;
1332 const struct value_desc
*d
;
1336 /* We index into the table_set[] list of per-API hash tables using the API's
1337 * value in the gl_api enum. Since GLES 3 doesn't have an API_OPENGL* enum
1338 * value since it's compatible with GLES2 its entry in table_set[] is at the
1341 STATIC_ASSERT(ARRAY_SIZE(table_set
) == API_OPENGL_LAST
+ 4);
1342 if (ctx
->API
== API_OPENGLES2
) {
1343 if (ctx
->Version
>= 32)
1344 api
= API_OPENGL_LAST
+ 3;
1345 else if (ctx
->Version
>= 31)
1346 api
= API_OPENGL_LAST
+ 2;
1347 else if (ctx
->Version
>= 30)
1348 api
= API_OPENGL_LAST
+ 1;
1350 mask
= ARRAY_SIZE(table(api
)) - 1;
1351 hash
= (pname
* prime_factor
);
1353 int idx
= table(api
)[hash
& mask
];
1355 /* If the enum isn't valid, the hash walk ends with index 0,
1356 * pointing to the first entry of values[] which doesn't hold
1357 * any valid enum. */
1358 if (unlikely(idx
== 0)) {
1359 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=%s)", func
,
1360 _mesa_enum_to_string(pname
));
1361 return &error_value
;
1365 if (likely(d
->pname
== pname
))
1371 if (unlikely(d
->extra
&& !check_extra(ctx
, func
, d
)))
1372 return &error_value
;
1374 switch (d
->location
) {
1376 *p
= ((char *) ctx
->DrawBuffer
+ d
->offset
);
1379 *p
= ((char *) ctx
+ d
->offset
);
1382 *p
= ((char *) ctx
->Array
.VAO
+ d
->offset
);
1385 unit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1386 *p
= ((char *) unit
+ d
->offset
);
1389 find_custom_value(ctx
, d
, v
);
1397 /* silence warning */
1398 return &error_value
;
1401 static const int transpose
[] = {
1409 _mesa_GetBooleanv(GLenum pname
, GLboolean
*params
)
1411 const struct value_desc
*d
;
1417 d
= find_value("glGetBooleanv", pname
, &p
, &v
);
1422 params
[0] = INT_TO_BOOLEAN(d
->offset
);
1426 params
[7] = FLOAT_TO_BOOLEAN(((GLfloat
*) p
)[7]);
1427 params
[6] = FLOAT_TO_BOOLEAN(((GLfloat
*) p
)[6]);
1428 params
[5] = FLOAT_TO_BOOLEAN(((GLfloat
*) p
)[5]);
1429 params
[4] = FLOAT_TO_BOOLEAN(((GLfloat
*) p
)[4]);
1432 params
[3] = FLOAT_TO_BOOLEAN(((GLfloat
*) p
)[3]);
1435 params
[2] = FLOAT_TO_BOOLEAN(((GLfloat
*) p
)[2]);
1438 params
[1] = FLOAT_TO_BOOLEAN(((GLfloat
*) p
)[1]);
1441 params
[0] = FLOAT_TO_BOOLEAN(((GLfloat
*) p
)[0]);
1444 case TYPE_DOUBLEN_2
:
1445 params
[1] = FLOAT_TO_BOOLEAN(((GLdouble
*) p
)[1]);
1447 params
[0] = FLOAT_TO_BOOLEAN(((GLdouble
*) p
)[0]);
1451 params
[3] = INT_TO_BOOLEAN(((GLint
*) p
)[3]);
1453 params
[2] = INT_TO_BOOLEAN(((GLint
*) p
)[2]);
1456 params
[1] = INT_TO_BOOLEAN(((GLint
*) p
)[1]);
1459 params
[0] = INT_TO_BOOLEAN(((GLint
*) p
)[0]);
1463 for (i
= 0; i
< v
.value_int_n
.n
; i
++)
1464 params
[i
] = INT_TO_BOOLEAN(v
.value_int_n
.ints
[i
]);
1468 params
[0] = INT64_TO_BOOLEAN(((GLint64
*) p
)[0]);
1472 params
[0] = ((GLboolean
*) p
)[0];
1476 m
= *(GLmatrix
**) p
;
1477 for (i
= 0; i
< 16; i
++)
1478 params
[i
] = FLOAT_TO_BOOLEAN(m
->m
[i
]);
1482 m
= *(GLmatrix
**) p
;
1483 for (i
= 0; i
< 16; i
++)
1484 params
[i
] = FLOAT_TO_BOOLEAN(m
->m
[transpose
[i
]]);
1495 shift
= d
->type
- TYPE_BIT_0
;
1496 params
[0] = (*(GLbitfield
*) p
>> shift
) & 1;
1502 _mesa_GetFloatv(GLenum pname
, GLfloat
*params
)
1504 const struct value_desc
*d
;
1510 d
= find_value("glGetFloatv", pname
, &p
, &v
);
1515 params
[0] = (GLfloat
) d
->offset
;
1519 params
[7] = ((GLfloat
*) p
)[7];
1520 params
[6] = ((GLfloat
*) p
)[6];
1521 params
[5] = ((GLfloat
*) p
)[5];
1522 params
[4] = ((GLfloat
*) p
)[4];
1525 params
[3] = ((GLfloat
*) p
)[3];
1528 params
[2] = ((GLfloat
*) p
)[2];
1531 params
[1] = ((GLfloat
*) p
)[1];
1534 params
[0] = ((GLfloat
*) p
)[0];
1537 case TYPE_DOUBLEN_2
:
1538 params
[1] = (GLfloat
) (((GLdouble
*) p
)[1]);
1540 params
[0] = (GLfloat
) (((GLdouble
*) p
)[0]);
1544 params
[3] = (GLfloat
) (((GLint
*) p
)[3]);
1546 params
[2] = (GLfloat
) (((GLint
*) p
)[2]);
1549 params
[1] = (GLfloat
) (((GLint
*) p
)[1]);
1552 params
[0] = (GLfloat
) (((GLint
*) p
)[0]);
1556 for (i
= 0; i
< v
.value_int_n
.n
; i
++)
1557 params
[i
] = INT_TO_FLOAT(v
.value_int_n
.ints
[i
]);
1561 params
[0] = (GLfloat
) (((GLint64
*) p
)[0]);
1565 params
[0] = BOOLEAN_TO_FLOAT(*(GLboolean
*) p
);
1569 m
= *(GLmatrix
**) p
;
1570 for (i
= 0; i
< 16; i
++)
1571 params
[i
] = m
->m
[i
];
1575 m
= *(GLmatrix
**) p
;
1576 for (i
= 0; i
< 16; i
++)
1577 params
[i
] = m
->m
[transpose
[i
]];
1588 shift
= d
->type
- TYPE_BIT_0
;
1589 params
[0] = BOOLEAN_TO_FLOAT((*(GLbitfield
*) p
>> shift
) & 1);
1595 _mesa_GetIntegerv(GLenum pname
, GLint
*params
)
1597 const struct value_desc
*d
;
1603 d
= find_value("glGetIntegerv", pname
, &p
, &v
);
1608 params
[0] = d
->offset
;
1612 params
[7] = IROUND(((GLfloat
*) p
)[7]);
1613 params
[6] = IROUND(((GLfloat
*) p
)[6]);
1614 params
[5] = IROUND(((GLfloat
*) p
)[5]);
1615 params
[4] = IROUND(((GLfloat
*) p
)[4]);
1617 params
[3] = IROUND(((GLfloat
*) p
)[3]);
1619 params
[2] = IROUND(((GLfloat
*) p
)[2]);
1621 params
[1] = IROUND(((GLfloat
*) p
)[1]);
1623 params
[0] = IROUND(((GLfloat
*) p
)[0]);
1627 params
[3] = FLOAT_TO_INT(((GLfloat
*) p
)[3]);
1629 params
[2] = FLOAT_TO_INT(((GLfloat
*) p
)[2]);
1631 params
[1] = FLOAT_TO_INT(((GLfloat
*) p
)[1]);
1633 params
[0] = FLOAT_TO_INT(((GLfloat
*) p
)[0]);
1636 case TYPE_DOUBLEN_2
:
1637 params
[1] = FLOAT_TO_INT(((GLdouble
*) p
)[1]);
1639 params
[0] = FLOAT_TO_INT(((GLdouble
*) p
)[0]);
1643 params
[3] = ((GLint
*) p
)[3];
1645 params
[2] = ((GLint
*) p
)[2];
1648 params
[1] = ((GLint
*) p
)[1];
1651 params
[0] = ((GLint
*) p
)[0];
1655 for (i
= 0; i
< v
.value_int_n
.n
; i
++)
1656 params
[i
] = v
.value_int_n
.ints
[i
];
1660 params
[0] = INT64_TO_INT(((GLint64
*) p
)[0]);
1664 params
[0] = BOOLEAN_TO_INT(*(GLboolean
*) p
);
1668 m
= *(GLmatrix
**) p
;
1669 for (i
= 0; i
< 16; i
++)
1670 params
[i
] = FLOAT_TO_INT(m
->m
[i
]);
1674 m
= *(GLmatrix
**) p
;
1675 for (i
= 0; i
< 16; i
++)
1676 params
[i
] = FLOAT_TO_INT(m
->m
[transpose
[i
]]);
1687 shift
= d
->type
- TYPE_BIT_0
;
1688 params
[0] = (*(GLbitfield
*) p
>> shift
) & 1;
1694 _mesa_GetInteger64v(GLenum pname
, GLint64
*params
)
1696 const struct value_desc
*d
;
1702 d
= find_value("glGetInteger64v", pname
, &p
, &v
);
1707 params
[0] = d
->offset
;
1711 params
[7] = IROUND64(((GLfloat
*) p
)[7]);
1712 params
[6] = IROUND64(((GLfloat
*) p
)[6]);
1713 params
[5] = IROUND64(((GLfloat
*) p
)[5]);
1714 params
[4] = IROUND64(((GLfloat
*) p
)[4]);
1716 params
[3] = IROUND64(((GLfloat
*) p
)[3]);
1718 params
[2] = IROUND64(((GLfloat
*) p
)[2]);
1720 params
[1] = IROUND64(((GLfloat
*) p
)[1]);
1722 params
[0] = IROUND64(((GLfloat
*) p
)[0]);
1726 params
[3] = FLOAT_TO_INT(((GLfloat
*) p
)[3]);
1728 params
[2] = FLOAT_TO_INT(((GLfloat
*) p
)[2]);
1730 params
[1] = FLOAT_TO_INT(((GLfloat
*) p
)[1]);
1732 params
[0] = FLOAT_TO_INT(((GLfloat
*) p
)[0]);
1735 case TYPE_DOUBLEN_2
:
1736 params
[1] = FLOAT_TO_INT(((GLdouble
*) p
)[1]);
1738 params
[0] = FLOAT_TO_INT(((GLdouble
*) p
)[0]);
1742 params
[3] = ((GLint
*) p
)[3];
1744 params
[2] = ((GLint
*) p
)[2];
1747 params
[1] = ((GLint
*) p
)[1];
1750 params
[0] = ((GLint
*) p
)[0];
1754 for (i
= 0; i
< v
.value_int_n
.n
; i
++)
1755 params
[i
] = INT_TO_BOOLEAN(v
.value_int_n
.ints
[i
]);
1759 params
[0] = ((GLint64
*) p
)[0];
1763 params
[0] = ((GLboolean
*) p
)[0];
1767 m
= *(GLmatrix
**) p
;
1768 for (i
= 0; i
< 16; i
++)
1769 params
[i
] = FLOAT_TO_INT64(m
->m
[i
]);
1773 m
= *(GLmatrix
**) p
;
1774 for (i
= 0; i
< 16; i
++)
1775 params
[i
] = FLOAT_TO_INT64(m
->m
[transpose
[i
]]);
1786 shift
= d
->type
- TYPE_BIT_0
;
1787 params
[0] = (*(GLbitfield
*) p
>> shift
) & 1;
1793 _mesa_GetDoublev(GLenum pname
, GLdouble
*params
)
1795 const struct value_desc
*d
;
1801 d
= find_value("glGetDoublev", pname
, &p
, &v
);
1806 params
[0] = d
->offset
;
1810 params
[7] = ((GLfloat
*) p
)[7];
1811 params
[6] = ((GLfloat
*) p
)[6];
1812 params
[5] = ((GLfloat
*) p
)[5];
1813 params
[4] = ((GLfloat
*) p
)[4];
1816 params
[3] = ((GLfloat
*) p
)[3];
1819 params
[2] = ((GLfloat
*) p
)[2];
1822 params
[1] = ((GLfloat
*) p
)[1];
1825 params
[0] = ((GLfloat
*) p
)[0];
1828 case TYPE_DOUBLEN_2
:
1829 params
[1] = ((GLdouble
*) p
)[1];
1831 params
[0] = ((GLdouble
*) p
)[0];
1835 params
[3] = ((GLint
*) p
)[3];
1837 params
[2] = ((GLint
*) p
)[2];
1840 params
[1] = ((GLint
*) p
)[1];
1843 params
[0] = ((GLint
*) p
)[0];
1847 for (i
= 0; i
< v
.value_int_n
.n
; i
++)
1848 params
[i
] = v
.value_int_n
.ints
[i
];
1852 params
[0] = (GLdouble
) (((GLint64
*) p
)[0]);
1856 params
[0] = *(GLboolean
*) p
;
1860 m
= *(GLmatrix
**) p
;
1861 for (i
= 0; i
< 16; i
++)
1862 params
[i
] = m
->m
[i
];
1866 m
= *(GLmatrix
**) p
;
1867 for (i
= 0; i
< 16; i
++)
1868 params
[i
] = m
->m
[transpose
[i
]];
1879 shift
= d
->type
- TYPE_BIT_0
;
1880 params
[0] = (*(GLbitfield
*) p
>> shift
) & 1;
1886 * Convert a GL texture binding enum such as GL_TEXTURE_BINDING_2D
1887 * into the corresponding Mesa texture target index.
1888 * \return TEXTURE_x_INDEX or -1 if binding is invalid
1891 tex_binding_to_index(const struct gl_context
*ctx
, GLenum binding
)
1894 case GL_TEXTURE_BINDING_1D
:
1895 return _mesa_is_desktop_gl(ctx
) ? TEXTURE_1D_INDEX
: -1;
1896 case GL_TEXTURE_BINDING_2D
:
1897 return TEXTURE_2D_INDEX
;
1898 case GL_TEXTURE_BINDING_3D
:
1899 return ctx
->API
!= API_OPENGLES
? TEXTURE_3D_INDEX
: -1;
1900 case GL_TEXTURE_BINDING_CUBE_MAP
:
1901 return ctx
->Extensions
.ARB_texture_cube_map
1902 ? TEXTURE_CUBE_INDEX
: -1;
1903 case GL_TEXTURE_BINDING_RECTANGLE
:
1904 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.NV_texture_rectangle
1905 ? TEXTURE_RECT_INDEX
: -1;
1906 case GL_TEXTURE_BINDING_1D_ARRAY
:
1907 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
1908 ? TEXTURE_1D_ARRAY_INDEX
: -1;
1909 case GL_TEXTURE_BINDING_2D_ARRAY
:
1910 return (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
)
1911 || _mesa_is_gles3(ctx
)
1912 ? TEXTURE_2D_ARRAY_INDEX
: -1;
1913 case GL_TEXTURE_BINDING_BUFFER
:
1914 return (_mesa_has_ARB_texture_buffer_object(ctx
) ||
1915 _mesa_has_OES_texture_buffer(ctx
)) ?
1916 TEXTURE_BUFFER_INDEX
: -1;
1917 case GL_TEXTURE_BINDING_CUBE_MAP_ARRAY
:
1918 return _mesa_has_texture_cube_map_array(ctx
)
1919 ? TEXTURE_CUBE_ARRAY_INDEX
: -1;
1920 case GL_TEXTURE_BINDING_2D_MULTISAMPLE
:
1921 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_multisample
1922 ? TEXTURE_2D_MULTISAMPLE_INDEX
: -1;
1923 case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY
:
1924 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_multisample
1925 ? TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX
: -1;
1931 static enum value_type
1932 find_value_indexed(const char *func
, GLenum pname
, GLuint index
, union value
*v
)
1934 GET_CURRENT_CONTEXT(ctx
);
1939 if (index
>= ctx
->Const
.MaxDrawBuffers
)
1941 if (!ctx
->Extensions
.EXT_draw_buffers2
)
1943 v
->value_int
= (ctx
->Color
.BlendEnabled
>> index
) & 1;
1948 case GL_BLEND_SRC_RGB
:
1949 if (index
>= ctx
->Const
.MaxDrawBuffers
)
1951 if (!ctx
->Extensions
.ARB_draw_buffers_blend
)
1953 v
->value_int
= ctx
->Color
.Blend
[index
].SrcRGB
;
1955 case GL_BLEND_SRC_ALPHA
:
1956 if (index
>= ctx
->Const
.MaxDrawBuffers
)
1958 if (!ctx
->Extensions
.ARB_draw_buffers_blend
)
1960 v
->value_int
= ctx
->Color
.Blend
[index
].SrcA
;
1964 case GL_BLEND_DST_RGB
:
1965 if (index
>= ctx
->Const
.MaxDrawBuffers
)
1967 if (!ctx
->Extensions
.ARB_draw_buffers_blend
)
1969 v
->value_int
= ctx
->Color
.Blend
[index
].DstRGB
;
1971 case GL_BLEND_DST_ALPHA
:
1972 if (index
>= ctx
->Const
.MaxDrawBuffers
)
1974 if (!ctx
->Extensions
.ARB_draw_buffers_blend
)
1976 v
->value_int
= ctx
->Color
.Blend
[index
].DstA
;
1978 case GL_BLEND_EQUATION_RGB
:
1979 if (index
>= ctx
->Const
.MaxDrawBuffers
)
1981 if (!ctx
->Extensions
.ARB_draw_buffers_blend
)
1983 v
->value_int
= ctx
->Color
.Blend
[index
].EquationRGB
;
1985 case GL_BLEND_EQUATION_ALPHA
:
1986 if (index
>= ctx
->Const
.MaxDrawBuffers
)
1988 if (!ctx
->Extensions
.ARB_draw_buffers_blend
)
1990 v
->value_int
= ctx
->Color
.Blend
[index
].EquationA
;
1993 case GL_COLOR_WRITEMASK
:
1994 if (index
>= ctx
->Const
.MaxDrawBuffers
)
1996 if (!ctx
->Extensions
.EXT_draw_buffers2
)
1998 v
->value_int_4
[0] = ctx
->Color
.ColorMask
[index
][RCOMP
] ? 1 : 0;
1999 v
->value_int_4
[1] = ctx
->Color
.ColorMask
[index
][GCOMP
] ? 1 : 0;
2000 v
->value_int_4
[2] = ctx
->Color
.ColorMask
[index
][BCOMP
] ? 1 : 0;
2001 v
->value_int_4
[3] = ctx
->Color
.ColorMask
[index
][ACOMP
] ? 1 : 0;
2004 case GL_SCISSOR_BOX
:
2005 if (index
>= ctx
->Const
.MaxViewports
)
2007 v
->value_int_4
[0] = ctx
->Scissor
.ScissorArray
[index
].X
;
2008 v
->value_int_4
[1] = ctx
->Scissor
.ScissorArray
[index
].Y
;
2009 v
->value_int_4
[2] = ctx
->Scissor
.ScissorArray
[index
].Width
;
2010 v
->value_int_4
[3] = ctx
->Scissor
.ScissorArray
[index
].Height
;
2013 case GL_WINDOW_RECTANGLE_EXT
:
2014 if (!ctx
->Extensions
.EXT_window_rectangles
)
2016 if (index
>= ctx
->Const
.MaxWindowRectangles
)
2018 v
->value_int_4
[0] = ctx
->Scissor
.WindowRects
[index
].X
;
2019 v
->value_int_4
[1] = ctx
->Scissor
.WindowRects
[index
].Y
;
2020 v
->value_int_4
[2] = ctx
->Scissor
.WindowRects
[index
].Width
;
2021 v
->value_int_4
[3] = ctx
->Scissor
.WindowRects
[index
].Height
;
2025 if (index
>= ctx
->Const
.MaxViewports
)
2027 v
->value_float_4
[0] = ctx
->ViewportArray
[index
].X
;
2028 v
->value_float_4
[1] = ctx
->ViewportArray
[index
].Y
;
2029 v
->value_float_4
[2] = ctx
->ViewportArray
[index
].Width
;
2030 v
->value_float_4
[3] = ctx
->ViewportArray
[index
].Height
;
2031 return TYPE_FLOAT_4
;
2033 case GL_DEPTH_RANGE
:
2034 if (index
>= ctx
->Const
.MaxViewports
)
2036 v
->value_double_2
[0] = ctx
->ViewportArray
[index
].Near
;
2037 v
->value_double_2
[1] = ctx
->ViewportArray
[index
].Far
;
2038 return TYPE_DOUBLEN_2
;
2040 case GL_TRANSFORM_FEEDBACK_BUFFER_START
:
2041 if (index
>= ctx
->Const
.MaxTransformFeedbackBuffers
)
2043 if (!ctx
->Extensions
.EXT_transform_feedback
)
2045 v
->value_int64
= ctx
->TransformFeedback
.CurrentObject
->Offset
[index
];
2048 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE
:
2049 if (index
>= ctx
->Const
.MaxTransformFeedbackBuffers
)
2051 if (!ctx
->Extensions
.EXT_transform_feedback
)
2054 = ctx
->TransformFeedback
.CurrentObject
->RequestedSize
[index
];
2057 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING
:
2058 if (index
>= ctx
->Const
.MaxTransformFeedbackBuffers
)
2060 if (!ctx
->Extensions
.EXT_transform_feedback
)
2062 v
->value_int
= ctx
->TransformFeedback
.CurrentObject
->BufferNames
[index
];
2065 case GL_UNIFORM_BUFFER_BINDING
:
2066 if (index
>= ctx
->Const
.MaxUniformBufferBindings
)
2068 if (!ctx
->Extensions
.ARB_uniform_buffer_object
)
2070 v
->value_int
= ctx
->UniformBufferBindings
[index
].BufferObject
->Name
;
2073 case GL_UNIFORM_BUFFER_START
:
2074 if (index
>= ctx
->Const
.MaxUniformBufferBindings
)
2076 if (!ctx
->Extensions
.ARB_uniform_buffer_object
)
2078 v
->value_int
= ctx
->UniformBufferBindings
[index
].Offset
< 0 ? 0 :
2079 ctx
->UniformBufferBindings
[index
].Offset
;
2082 case GL_UNIFORM_BUFFER_SIZE
:
2083 if (index
>= ctx
->Const
.MaxUniformBufferBindings
)
2085 if (!ctx
->Extensions
.ARB_uniform_buffer_object
)
2087 v
->value_int
= ctx
->UniformBufferBindings
[index
].Size
< 0 ? 0 :
2088 ctx
->UniformBufferBindings
[index
].Size
;
2091 /* ARB_shader_storage_buffer_object */
2092 case GL_SHADER_STORAGE_BUFFER_BINDING
:
2093 if (!ctx
->Extensions
.ARB_shader_storage_buffer_object
)
2095 if (index
>= ctx
->Const
.MaxShaderStorageBufferBindings
)
2097 v
->value_int
= ctx
->ShaderStorageBufferBindings
[index
].BufferObject
->Name
;
2100 case GL_SHADER_STORAGE_BUFFER_START
:
2101 if (!ctx
->Extensions
.ARB_shader_storage_buffer_object
)
2103 if (index
>= ctx
->Const
.MaxShaderStorageBufferBindings
)
2105 v
->value_int
= ctx
->ShaderStorageBufferBindings
[index
].Offset
< 0 ? 0 :
2106 ctx
->ShaderStorageBufferBindings
[index
].Offset
;
2109 case GL_SHADER_STORAGE_BUFFER_SIZE
:
2110 if (!ctx
->Extensions
.ARB_shader_storage_buffer_object
)
2112 if (index
>= ctx
->Const
.MaxShaderStorageBufferBindings
)
2114 v
->value_int
= ctx
->ShaderStorageBufferBindings
[index
].Size
< 0 ? 0 :
2115 ctx
->ShaderStorageBufferBindings
[index
].Size
;
2118 /* ARB_texture_multisample / GL3.2 */
2119 case GL_SAMPLE_MASK_VALUE
:
2122 if (!ctx
->Extensions
.ARB_texture_multisample
)
2124 v
->value_int
= ctx
->Multisample
.SampleMaskValue
;
2127 case GL_ATOMIC_COUNTER_BUFFER_BINDING
:
2128 if (!ctx
->Extensions
.ARB_shader_atomic_counters
)
2130 if (index
>= ctx
->Const
.MaxAtomicBufferBindings
)
2132 v
->value_int
= ctx
->AtomicBufferBindings
[index
].BufferObject
->Name
;
2135 case GL_ATOMIC_COUNTER_BUFFER_START
:
2136 if (!ctx
->Extensions
.ARB_shader_atomic_counters
)
2138 if (index
>= ctx
->Const
.MaxAtomicBufferBindings
)
2140 v
->value_int64
= ctx
->AtomicBufferBindings
[index
].Offset
;
2143 case GL_ATOMIC_COUNTER_BUFFER_SIZE
:
2144 if (!ctx
->Extensions
.ARB_shader_atomic_counters
)
2146 if (index
>= ctx
->Const
.MaxAtomicBufferBindings
)
2148 v
->value_int64
= ctx
->AtomicBufferBindings
[index
].Size
;
2151 case GL_VERTEX_BINDING_DIVISOR
:
2152 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_instanced_arrays
) &&
2153 !_mesa_is_gles31(ctx
))
2155 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
)
2157 v
->value_int
= ctx
->Array
.VAO
->VertexBinding
[VERT_ATTRIB_GENERIC(index
)].InstanceDivisor
;
2160 case GL_VERTEX_BINDING_OFFSET
:
2161 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles31(ctx
))
2163 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
)
2165 v
->value_int
= ctx
->Array
.VAO
->VertexBinding
[VERT_ATTRIB_GENERIC(index
)].Offset
;
2168 case GL_VERTEX_BINDING_STRIDE
:
2169 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles31(ctx
))
2171 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
)
2173 v
->value_int
= ctx
->Array
.VAO
->VertexBinding
[VERT_ATTRIB_GENERIC(index
)].Stride
;
2176 case GL_VERTEX_BINDING_BUFFER
:
2177 if (ctx
->API
== API_OPENGLES2
&& ctx
->Version
< 31)
2179 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
)
2181 v
->value_int
= ctx
->Array
.VAO
->VertexBinding
[VERT_ATTRIB_GENERIC(index
)].BufferObj
->Name
;
2184 /* ARB_shader_image_load_store */
2185 case GL_IMAGE_BINDING_NAME
: {
2186 struct gl_texture_object
*t
;
2188 if (!ctx
->Extensions
.ARB_shader_image_load_store
)
2190 if (index
>= ctx
->Const
.MaxImageUnits
)
2193 t
= ctx
->ImageUnits
[index
].TexObj
;
2194 v
->value_int
= (t
? t
->Name
: 0);
2198 case GL_IMAGE_BINDING_LEVEL
:
2199 if (!ctx
->Extensions
.ARB_shader_image_load_store
)
2201 if (index
>= ctx
->Const
.MaxImageUnits
)
2204 v
->value_int
= ctx
->ImageUnits
[index
].Level
;
2207 case GL_IMAGE_BINDING_LAYERED
:
2208 if (!ctx
->Extensions
.ARB_shader_image_load_store
)
2210 if (index
>= ctx
->Const
.MaxImageUnits
)
2213 v
->value_int
= ctx
->ImageUnits
[index
].Layered
;
2216 case GL_IMAGE_BINDING_LAYER
:
2217 if (!ctx
->Extensions
.ARB_shader_image_load_store
)
2219 if (index
>= ctx
->Const
.MaxImageUnits
)
2222 v
->value_int
= ctx
->ImageUnits
[index
].Layer
;
2225 case GL_IMAGE_BINDING_ACCESS
:
2226 if (!ctx
->Extensions
.ARB_shader_image_load_store
)
2228 if (index
>= ctx
->Const
.MaxImageUnits
)
2231 v
->value_int
= ctx
->ImageUnits
[index
].Access
;
2234 case GL_IMAGE_BINDING_FORMAT
:
2235 if (!ctx
->Extensions
.ARB_shader_image_load_store
)
2237 if (index
>= ctx
->Const
.MaxImageUnits
)
2240 v
->value_int
= ctx
->ImageUnits
[index
].Format
;
2243 /* ARB_direct_state_access */
2244 case GL_TEXTURE_BINDING_1D
:
2245 case GL_TEXTURE_BINDING_1D_ARRAY
:
2246 case GL_TEXTURE_BINDING_2D
:
2247 case GL_TEXTURE_BINDING_2D_ARRAY
:
2248 case GL_TEXTURE_BINDING_2D_MULTISAMPLE
:
2249 case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY
:
2250 case GL_TEXTURE_BINDING_3D
:
2251 case GL_TEXTURE_BINDING_BUFFER
:
2252 case GL_TEXTURE_BINDING_CUBE_MAP
:
2253 case GL_TEXTURE_BINDING_CUBE_MAP_ARRAY
:
2254 case GL_TEXTURE_BINDING_RECTANGLE
: {
2257 if (ctx
->API
!= API_OPENGL_CORE
)
2259 target
= tex_binding_to_index(ctx
, pname
);
2262 if (index
>= _mesa_max_tex_unit(ctx
))
2265 v
->value_int
= ctx
->Texture
.Unit
[index
].CurrentTex
[target
]->Name
;
2269 case GL_SAMPLER_BINDING
: {
2270 struct gl_sampler_object
*samp
;
2272 if (ctx
->API
!= API_OPENGL_CORE
)
2274 if (index
>= _mesa_max_tex_unit(ctx
))
2277 samp
= ctx
->Texture
.Unit
[index
].Sampler
;
2278 v
->value_int
= samp
? samp
->Name
: 0;
2282 case GL_MAX_COMPUTE_WORK_GROUP_COUNT
:
2283 if (!_mesa_has_compute_shaders(ctx
))
2287 v
->value_int
= ctx
->Const
.MaxComputeWorkGroupCount
[index
];
2290 case GL_MAX_COMPUTE_WORK_GROUP_SIZE
:
2291 if (!_mesa_has_compute_shaders(ctx
))
2295 v
->value_int
= ctx
->Const
.MaxComputeWorkGroupSize
[index
];
2298 /* ARB_compute_variable_group_size */
2299 case GL_MAX_COMPUTE_VARIABLE_GROUP_SIZE_ARB
:
2300 if (!ctx
->Extensions
.ARB_compute_variable_group_size
)
2304 v
->value_int
= ctx
->Const
.MaxComputeVariableGroupSize
[index
];
2309 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=%s)", func
,
2310 _mesa_enum_to_string(pname
));
2311 return TYPE_INVALID
;
2313 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(pname=%s)", func
,
2314 _mesa_enum_to_string(pname
));
2315 return TYPE_INVALID
;
2319 _mesa_GetBooleani_v( GLenum pname
, GLuint index
, GLboolean
*params
)
2322 enum value_type type
=
2323 find_value_indexed("glGetBooleani_v", pname
, index
, &v
);
2327 params
[0] = INT_TO_BOOLEAN(v
.value_int
);
2330 params
[0] = INT_TO_BOOLEAN(v
.value_int_4
[0]);
2331 params
[1] = INT_TO_BOOLEAN(v
.value_int_4
[1]);
2332 params
[2] = INT_TO_BOOLEAN(v
.value_int_4
[2]);
2333 params
[3] = INT_TO_BOOLEAN(v
.value_int_4
[3]);
2336 params
[0] = INT64_TO_BOOLEAN(v
.value_int64
);
2339 ; /* nothing - GL error was recorded */
2344 _mesa_GetIntegeri_v( GLenum pname
, GLuint index
, GLint
*params
)
2347 enum value_type type
=
2348 find_value_indexed("glGetIntegeri_v", pname
, index
, &v
);
2353 params
[3] = IROUND(v
.value_float_4
[3]);
2356 params
[2] = IROUND(v
.value_float_4
[2]);
2359 params
[1] = IROUND(v
.value_float_4
[1]);
2362 params
[0] = IROUND(v
.value_float_4
[0]);
2365 case TYPE_DOUBLEN_2
:
2366 params
[1] = IROUND(v
.value_double_2
[1]);
2368 params
[0] = IROUND(v
.value_double_2
[0]);
2372 params
[0] = v
.value_int
;
2375 params
[0] = v
.value_int_4
[0];
2376 params
[1] = v
.value_int_4
[1];
2377 params
[2] = v
.value_int_4
[2];
2378 params
[3] = v
.value_int_4
[3];
2381 params
[0] = INT64_TO_INT(v
.value_int64
);
2384 ; /* nothing - GL error was recorded */
2389 _mesa_GetInteger64i_v( GLenum pname
, GLuint index
, GLint64
*params
)
2392 enum value_type type
=
2393 find_value_indexed("glGetInteger64i_v", pname
, index
, &v
);
2397 params
[0] = v
.value_int
;
2400 params
[0] = v
.value_int_4
[0];
2401 params
[1] = v
.value_int_4
[1];
2402 params
[2] = v
.value_int_4
[2];
2403 params
[3] = v
.value_int_4
[3];
2406 params
[0] = v
.value_int64
;
2409 ; /* nothing - GL error was recorded */
2414 _mesa_GetFloati_v(GLenum pname
, GLuint index
, GLfloat
*params
)
2419 enum value_type type
=
2420 find_value_indexed("glGetFloati_v", pname
, index
, &v
);
2425 params
[3] = v
.value_float_4
[3];
2428 params
[2] = v
.value_float_4
[2];
2431 params
[1] = v
.value_float_4
[1];
2434 params
[0] = v
.value_float_4
[0];
2437 case TYPE_DOUBLEN_2
:
2438 params
[1] = (GLfloat
) v
.value_double_2
[1];
2440 params
[0] = (GLfloat
) v
.value_double_2
[0];
2444 params
[3] = (GLfloat
) v
.value_int_4
[3];
2446 params
[2] = (GLfloat
) v
.value_int_4
[2];
2449 params
[1] = (GLfloat
) v
.value_int_4
[1];
2452 params
[0] = (GLfloat
) v
.value_int_4
[0];
2456 for (i
= 0; i
< v
.value_int_n
.n
; i
++)
2457 params
[i
] = INT_TO_FLOAT(v
.value_int_n
.ints
[i
]);
2461 params
[0] = (GLfloat
) v
.value_int64
;
2465 params
[0] = BOOLEAN_TO_FLOAT(v
.value_bool
);
2469 m
= *(GLmatrix
**) &v
;
2470 for (i
= 0; i
< 16; i
++)
2471 params
[i
] = m
->m
[i
];
2475 m
= *(GLmatrix
**) &v
;
2476 for (i
= 0; i
< 16; i
++)
2477 params
[i
] = m
->m
[transpose
[i
]];
2486 _mesa_GetDoublei_v(GLenum pname
, GLuint index
, GLdouble
*params
)
2491 enum value_type type
=
2492 find_value_indexed("glGetDoublei_v", pname
, index
, &v
);
2497 params
[3] = (GLdouble
) v
.value_float_4
[3];
2500 params
[2] = (GLdouble
) v
.value_float_4
[2];
2503 params
[1] = (GLdouble
) v
.value_float_4
[1];
2506 params
[0] = (GLdouble
) v
.value_float_4
[0];
2509 case TYPE_DOUBLEN_2
:
2510 params
[1] = v
.value_double_2
[1];
2512 params
[0] = v
.value_double_2
[0];
2516 params
[3] = (GLdouble
) v
.value_int_4
[3];
2518 params
[2] = (GLdouble
) v
.value_int_4
[2];
2521 params
[1] = (GLdouble
) v
.value_int_4
[1];
2524 params
[0] = (GLdouble
) v
.value_int_4
[0];
2528 for (i
= 0; i
< v
.value_int_n
.n
; i
++)
2529 params
[i
] = (GLdouble
) INT_TO_FLOAT(v
.value_int_n
.ints
[i
]);
2533 params
[0] = (GLdouble
) v
.value_int64
;
2537 params
[0] = (GLdouble
) BOOLEAN_TO_FLOAT(v
.value_bool
);
2541 m
= *(GLmatrix
**) &v
;
2542 for (i
= 0; i
< 16; i
++)
2543 params
[i
] = (GLdouble
) m
->m
[i
];
2547 m
= *(GLmatrix
**) &v
;
2548 for (i
= 0; i
< 16; i
++)
2549 params
[i
] = (GLdouble
) m
->m
[transpose
[i
]];
2558 _mesa_GetFixedv(GLenum pname
, GLfixed
*params
)
2560 const struct value_desc
*d
;
2566 d
= find_value("glGetDoublev", pname
, &p
, &v
);
2571 params
[0] = INT_TO_FIXED(d
->offset
);
2576 params
[3] = FLOAT_TO_FIXED(((GLfloat
*) p
)[3]);
2579 params
[2] = FLOAT_TO_FIXED(((GLfloat
*) p
)[2]);
2582 params
[1] = FLOAT_TO_FIXED(((GLfloat
*) p
)[1]);
2585 params
[0] = FLOAT_TO_FIXED(((GLfloat
*) p
)[0]);
2588 case TYPE_DOUBLEN_2
:
2589 params
[1] = FLOAT_TO_FIXED(((GLdouble
*) p
)[1]);
2591 params
[0] = FLOAT_TO_FIXED(((GLdouble
*) p
)[0]);
2595 params
[3] = INT_TO_FIXED(((GLint
*) p
)[3]);
2597 params
[2] = INT_TO_FIXED(((GLint
*) p
)[2]);
2600 params
[1] = INT_TO_FIXED(((GLint
*) p
)[1]);
2603 params
[0] = INT_TO_FIXED(((GLint
*) p
)[0]);
2607 for (i
= 0; i
< v
.value_int_n
.n
; i
++)
2608 params
[i
] = INT_TO_FIXED(v
.value_int_n
.ints
[i
]);
2612 params
[0] = ((GLint64
*) p
)[0];
2616 params
[0] = BOOLEAN_TO_FIXED(((GLboolean
*) p
)[0]);
2620 m
= *(GLmatrix
**) p
;
2621 for (i
= 0; i
< 16; i
++)
2622 params
[i
] = FLOAT_TO_FIXED(m
->m
[i
]);
2626 m
= *(GLmatrix
**) p
;
2627 for (i
= 0; i
< 16; i
++)
2628 params
[i
] = FLOAT_TO_FIXED(m
->m
[transpose
[i
]]);
2639 shift
= d
->type
- TYPE_BIT_0
;
2640 params
[0] = BOOLEAN_TO_FIXED((*(GLbitfield
*) p
>> shift
) & 1);