2 * Copyright (C) 2010 Brian Paul All Rights Reserved.
3 * Copyright (C) 2010 Intel Corporation
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included
13 * in all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
19 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21 * OTHER DEALINGS IN THE SOFTWARE.
23 * Author: Kristian Høgsberg <krh@bitplanet.net>
32 #include "extensions.h"
37 #include "texcompress.h"
39 #include "framebuffer.h"
40 #include "samplerobj.h"
43 /* This is a table driven implemetation of the glGet*v() functions.
44 * The basic idea is that most getters just look up an int somewhere
45 * in struct gl_context and then convert it to a bool or float according to
46 * which of glGetIntegerv() glGetBooleanv() etc is being called.
47 * Instead of generating code to do this, we can just record the enum
48 * value and the offset into struct gl_context in an array of structs. Then
49 * in glGet*(), we lookup the struct for the enum in question, and use
50 * the offset to get the int we need.
52 * Sometimes we need to look up a float, a boolean, a bit in a
53 * bitfield, a matrix or other types instead, so we need to track the
54 * type of the value in struct gl_context. And sometimes the value isn't in
55 * struct gl_context but in the drawbuffer, the array object, current texture
56 * unit, or maybe it's a computed value. So we need to also track
57 * where or how to find the value. Finally, we sometimes need to
58 * check that one of a number of extensions are enabled, the GL
59 * version or flush or call _mesa_update_state(). This is done by
60 * attaching optional extra information to the value description
61 * struct, it's sort of like an array of opcodes that describe extra
64 * Putting all this together we end up with struct value_desc below,
65 * and with a couple of macros to help, the table of struct value_desc
66 * is about as concise as the specification in the old python script.
69 #define FLOAT_TO_BOOLEAN(X) ( (X) ? GL_TRUE : GL_FALSE )
70 #define FLOAT_TO_FIXED(F) ( ((F) * 65536.0f > INT_MAX) ? INT_MAX : \
71 ((F) * 65536.0f < INT_MIN) ? INT_MIN : \
72 (GLint) ((F) * 65536.0f) )
74 #define INT_TO_BOOLEAN(I) ( (I) ? GL_TRUE : GL_FALSE )
75 #define INT_TO_FIXED(I) ( ((I) > SHRT_MAX) ? INT_MAX : \
76 ((I) < SHRT_MIN) ? INT_MIN : \
77 (GLint) ((I) * 65536) )
79 #define INT64_TO_BOOLEAN(I) ( (I) ? GL_TRUE : GL_FALSE )
80 #define INT64_TO_INT(I) ( (GLint)((I > INT_MAX) ? INT_MAX : ((I < INT_MIN) ? INT_MIN : (I))) )
82 #define BOOLEAN_TO_INT(B) ( (GLint) (B) )
83 #define BOOLEAN_TO_INT64(B) ( (GLint64) (B) )
84 #define BOOLEAN_TO_FLOAT(B) ( (B) ? 1.0F : 0.0F )
85 #define BOOLEAN_TO_FIXED(B) ( (GLint) ((B) ? 1 : 0) << 16 )
87 #define ENUM_TO_INT64(E) ( (GLint64) (E) )
88 #define ENUM_TO_FIXED(E) (E)
124 enum value_location
{
144 EXTRA_NEW_FRAG_CLAMP
,
145 EXTRA_VALID_DRAW_BUFFER
,
146 EXTRA_VALID_TEXTURE_UNIT
,
147 EXTRA_VALID_CLIP_DISTANCE
,
151 EXTRA_EXT_ATOMICS_GS4
,
152 EXTRA_EXT_SHADER_IMAGE_GS4
,
153 EXTRA_EXT_ATOMICS_TESS
,
154 EXTRA_EXT_SHADER_IMAGE_TESS
,
157 #define NO_EXTRA NULL
162 GLubyte location
; /**< enum value_location */
163 GLubyte type
; /**< enum value_type */
170 GLfloat value_float_4
[4];
171 GLdouble value_double_2
[2];
172 GLmatrix
*value_matrix
;
174 GLint value_int_4
[4];
178 /* Sigh, see GL_COMPRESSED_TEXTURE_FORMATS_ARB handling */
182 GLboolean value_bool
;
185 #define BUFFER_FIELD(field, type) \
186 LOC_BUFFER, type, offsetof(struct gl_framebuffer, field)
187 #define CONTEXT_FIELD(field, type) \
188 LOC_CONTEXT, type, offsetof(struct gl_context, field)
189 #define ARRAY_FIELD(field, type) \
190 LOC_ARRAY, type, offsetof(struct gl_vertex_array_object, field)
191 #undef CONST /* already defined through windows.h */
192 #define CONST(value) \
193 LOC_CONTEXT, TYPE_CONST, value
195 #define BUFFER_INT(field) BUFFER_FIELD(field, TYPE_INT)
196 #define BUFFER_ENUM(field) BUFFER_FIELD(field, TYPE_ENUM)
197 #define BUFFER_BOOL(field) BUFFER_FIELD(field, TYPE_BOOLEAN)
199 #define CONTEXT_INT(field) CONTEXT_FIELD(field, TYPE_INT)
200 #define CONTEXT_INT2(field) CONTEXT_FIELD(field, TYPE_INT_2)
201 #define CONTEXT_INT64(field) CONTEXT_FIELD(field, TYPE_INT64)
202 #define CONTEXT_ENUM(field) CONTEXT_FIELD(field, TYPE_ENUM)
203 #define CONTEXT_ENUM2(field) CONTEXT_FIELD(field, TYPE_ENUM_2)
204 #define CONTEXT_BOOL(field) CONTEXT_FIELD(field, TYPE_BOOLEAN)
205 #define CONTEXT_BIT0(field) CONTEXT_FIELD(field, TYPE_BIT_0)
206 #define CONTEXT_BIT1(field) CONTEXT_FIELD(field, TYPE_BIT_1)
207 #define CONTEXT_BIT2(field) CONTEXT_FIELD(field, TYPE_BIT_2)
208 #define CONTEXT_BIT3(field) CONTEXT_FIELD(field, TYPE_BIT_3)
209 #define CONTEXT_BIT4(field) CONTEXT_FIELD(field, TYPE_BIT_4)
210 #define CONTEXT_BIT5(field) CONTEXT_FIELD(field, TYPE_BIT_5)
211 #define CONTEXT_BIT6(field) CONTEXT_FIELD(field, TYPE_BIT_6)
212 #define CONTEXT_BIT7(field) CONTEXT_FIELD(field, TYPE_BIT_7)
213 #define CONTEXT_FLOAT(field) CONTEXT_FIELD(field, TYPE_FLOAT)
214 #define CONTEXT_FLOAT2(field) CONTEXT_FIELD(field, TYPE_FLOAT_2)
215 #define CONTEXT_FLOAT3(field) CONTEXT_FIELD(field, TYPE_FLOAT_3)
216 #define CONTEXT_FLOAT4(field) CONTEXT_FIELD(field, TYPE_FLOAT_4)
217 #define CONTEXT_MATRIX(field) CONTEXT_FIELD(field, TYPE_MATRIX)
218 #define CONTEXT_MATRIX_T(field) CONTEXT_FIELD(field, TYPE_MATRIX_T)
220 #define ARRAY_INT(field) ARRAY_FIELD(field, TYPE_INT)
221 #define ARRAY_ENUM(field) ARRAY_FIELD(field, TYPE_ENUM)
222 #define ARRAY_BOOL(field) ARRAY_FIELD(field, TYPE_BOOLEAN)
225 offsetof(struct gl_extensions, f)
227 #define EXTRA_EXT(e) \
228 static const int extra_##e[] = { \
232 #define EXTRA_EXT2(e1, e2) \
233 static const int extra_##e1##_##e2[] = { \
234 EXT(e1), EXT(e2), EXTRA_END \
237 /* The 'extra' mechanism is a way to specify extra checks (such as
238 * extensions or specific gl versions) or actions (flush current, new
239 * buffers) that we need to do before looking up an enum. We need to
240 * declare them all up front so we can refer to them in the value_desc
243 * Each EXTRA_ will be executed. For EXTRA_* enums of extensions and API
244 * versions, listing multiple ones in an array means an error will be thrown
245 * only if none of them are available. If you need to check for "AND"
246 * behavior, you would need to make a custom EXTRA_ enum.
249 static const int extra_new_buffers
[] = {
254 static const int extra_new_frag_clamp
[] = {
255 EXTRA_NEW_FRAG_CLAMP
,
259 static const int extra_valid_draw_buffer
[] = {
260 EXTRA_VALID_DRAW_BUFFER
,
264 static const int extra_valid_texture_unit
[] = {
265 EXTRA_VALID_TEXTURE_UNIT
,
269 static const int extra_valid_clip_distance
[] = {
270 EXTRA_VALID_CLIP_DISTANCE
,
274 static const int extra_flush_current_valid_texture_unit
[] = {
276 EXTRA_VALID_TEXTURE_UNIT
,
280 static const int extra_flush_current
[] = {
285 static const int extra_EXT_texture_integer_and_new_buffers
[] = {
286 EXT(EXT_texture_integer
),
291 static const int extra_GLSL_130_es3
[] = {
297 static const int extra_texture_buffer_object
[] = {
300 EXT(ARB_texture_buffer_object
),
304 static const int extra_ARB_transform_feedback2_api_es3
[] = {
305 EXT(ARB_transform_feedback2
),
310 static const int extra_ARB_uniform_buffer_object_and_geometry_shader
[] = {
315 static const int extra_ARB_ES2_compatibility_api_es2
[] = {
316 EXT(ARB_ES2_compatibility
),
321 static const int extra_ARB_ES3_compatibility_api_es3
[] = {
322 EXT(ARB_ES3_compatibility
),
327 static const int extra_EXT_framebuffer_sRGB_and_new_buffers
[] = {
328 EXT(EXT_framebuffer_sRGB
),
333 static const int extra_EXT_packed_float
[] = {
334 EXT(EXT_packed_float
),
339 static const int extra_EXT_texture_array_es3
[] = {
340 EXT(EXT_texture_array
),
345 static const int extra_ARB_shader_atomic_counters_and_geometry_shader
[] = {
346 EXTRA_EXT_ATOMICS_GS4
,
350 static const int extra_ARB_shader_image_load_store_and_geometry_shader
[] = {
351 EXTRA_EXT_SHADER_IMAGE_GS4
,
355 static const int extra_ARB_shader_atomic_counters_and_tessellation
[] = {
356 EXTRA_EXT_ATOMICS_TESS
,
360 static const int extra_ARB_shader_image_load_store_and_tessellation
[] = {
361 EXTRA_EXT_SHADER_IMAGE_TESS
,
365 /* HACK: remove when ARB_compute_shader is actually supported */
366 static const int extra_ARB_compute_shader_es31
[] = {
367 EXT(ARB_compute_shader
),
372 static const int extra_ARB_shader_storage_buffer_object_es31
[] = {
373 EXT(ARB_shader_storage_buffer_object
),
378 EXTRA_EXT(ARB_texture_cube_map
);
379 EXTRA_EXT(EXT_texture_array
);
380 EXTRA_EXT(NV_fog_distance
);
381 EXTRA_EXT(EXT_texture_filter_anisotropic
);
382 EXTRA_EXT(NV_point_sprite
);
383 EXTRA_EXT(NV_texture_rectangle
);
384 EXTRA_EXT(EXT_stencil_two_side
);
385 EXTRA_EXT(EXT_depth_bounds_test
);
386 EXTRA_EXT(ARB_depth_clamp
);
387 EXTRA_EXT(ATI_fragment_shader
);
388 EXTRA_EXT(EXT_provoking_vertex
);
389 EXTRA_EXT(ARB_fragment_shader
);
390 EXTRA_EXT(ARB_fragment_program
);
391 EXTRA_EXT2(ARB_framebuffer_object
, EXT_framebuffer_multisample
);
392 EXTRA_EXT(ARB_seamless_cube_map
);
394 EXTRA_EXT(ARB_vertex_shader
);
395 EXTRA_EXT(EXT_transform_feedback
);
396 EXTRA_EXT(ARB_transform_feedback3
);
397 EXTRA_EXT(EXT_pixel_buffer_object
);
398 EXTRA_EXT(ARB_vertex_program
);
399 EXTRA_EXT2(NV_point_sprite
, ARB_point_sprite
);
400 EXTRA_EXT2(ARB_vertex_program
, ARB_fragment_program
);
401 EXTRA_EXT(ARB_geometry_shader4
);
402 EXTRA_EXT(ARB_color_buffer_float
);
403 EXTRA_EXT(EXT_framebuffer_sRGB
);
404 EXTRA_EXT(OES_EGL_image_external
);
405 EXTRA_EXT(ARB_blend_func_extended
);
406 EXTRA_EXT(ARB_uniform_buffer_object
);
407 EXTRA_EXT(ARB_timer_query
);
408 EXTRA_EXT(ARB_texture_cube_map_array
);
409 EXTRA_EXT(ARB_texture_buffer_range
);
410 EXTRA_EXT(ARB_texture_multisample
);
411 EXTRA_EXT(ARB_texture_gather
);
412 EXTRA_EXT(ARB_shader_atomic_counters
);
413 EXTRA_EXT(ARB_draw_indirect
);
414 EXTRA_EXT(ARB_shader_image_load_store
);
415 EXTRA_EXT(ARB_viewport_array
);
416 EXTRA_EXT(ARB_compute_shader
);
417 EXTRA_EXT(ARB_gpu_shader5
);
418 EXTRA_EXT2(ARB_transform_feedback3
, ARB_gpu_shader5
);
419 EXTRA_EXT(INTEL_performance_query
);
420 EXTRA_EXT(ARB_explicit_uniform_location
);
421 EXTRA_EXT(ARB_clip_control
);
422 EXTRA_EXT(EXT_polygon_offset_clamp
);
423 EXTRA_EXT(ARB_framebuffer_no_attachments
);
424 EXTRA_EXT(ARB_tessellation_shader
);
425 EXTRA_EXT(ARB_shader_subroutine
);
426 EXTRA_EXT(ARB_shader_storage_buffer_object
);
429 extra_ARB_color_buffer_float_or_glcore
[] = {
430 EXT(ARB_color_buffer_float
),
436 extra_NV_primitive_restart
[] = {
437 EXT(NV_primitive_restart
),
441 static const int extra_version_30
[] = { EXTRA_VERSION_30
, EXTRA_END
};
442 static const int extra_version_31
[] = { EXTRA_VERSION_31
, EXTRA_END
};
443 static const int extra_version_32
[] = { EXTRA_VERSION_32
, EXTRA_END
};
444 static const int extra_version_40
[] = { EXTRA_VERSION_40
, EXTRA_END
};
446 static const int extra_gl30_es3
[] = {
452 static const int extra_gl32_es3
[] = {
458 static const int extra_gl32_ARB_geometry_shader4
[] = {
460 EXT(ARB_geometry_shader4
),
464 static const int extra_gl40_ARB_sample_shading
[] = {
466 EXT(ARB_sample_shading
),
471 extra_ARB_vertex_program_api_es2
[] = {
472 EXT(ARB_vertex_program
),
477 /* The ReadBuffer get token is valid under either full GL or under
478 * GLES2 if the NV_read_buffer extension is available. */
480 extra_NV_read_buffer_api_gl
[] = {
486 static const int extra_core_ARB_color_buffer_float_and_new_buffers
[] = {
488 EXT(ARB_color_buffer_float
),
493 /* This is the big table describing all the enums we accept in
494 * glGet*v(). The table is partitioned into six parts: enums
495 * understood by all GL APIs (OpenGL, GLES and GLES2), enums shared
496 * between OpenGL and GLES, enums exclusive to GLES, etc for the
497 * remaining combinations. To look up the enums valid in a given API
498 * we will use a hash table specific to that API. These tables are in
499 * turn generated at build time and included through get_hash.h.
502 #include "get_hash.h"
504 /* All we need now is a way to look up the value struct from the enum.
505 * The code generated by gcc for the old generated big switch
506 * statement is a big, balanced, open coded if/else tree, essentially
507 * an unrolled binary search. It would be natural to sort the new
508 * enum table and use bsearch(), but we will use a read-only hash
509 * table instead. bsearch() has a nice guaranteed worst case
510 * performance, but we're also guaranteed to hit that worst case
511 * (log2(n) iterations) for about half the enums. Instead, using an
512 * open addressing hash table, we can find the enum on the first try
513 * for 80% of the enums, 1 collision for 10% and never more than 5
514 * collisions for any enum (typical numbers). And the code is very
515 * simple, even though it feels a little magic. */
519 print_table_stats(int api
)
521 int i
, j
, collisions
[11], count
, hash
, mask
;
522 const struct value_desc
*d
;
523 const char *api_names
[] = {
524 [API_OPENGL_COMPAT
] = "GL",
525 [API_OPENGL_CORE
] = "GL_CORE",
526 [API_OPENGLES
] = "GLES",
527 [API_OPENGLES2
] = "GLES2",
529 const char *api_name
;
531 api_name
= api
< ARRAY_SIZE(api_names
) ? api_names
[api
] : "N/A";
533 mask
= ARRAY_SIZE(table(api
)) - 1;
534 memset(collisions
, 0, sizeof collisions
);
536 for (i
= 0; i
< ARRAY_SIZE(table(api
)); i
++) {
540 d
= &values
[table(api
)[i
]];
541 hash
= (d
->pname
* prime_factor
);
544 if (values
[table(api
)[hash
& mask
]].pname
== d
->pname
)
556 printf("number of enums for %s: %d (total %ld)\n",
557 api_name
, count
, ARRAY_SIZE(values
));
558 for (i
= 0; i
< ARRAY_SIZE(collisions
) - 1; i
++)
559 if (collisions
[i
] > 0)
560 printf(" %d enums with %d %scollisions\n",
561 collisions
[i
], i
, i
== 10 ? "or more " : "");
566 * Initialize the enum hash for a given API
568 * This is called from one_time_init() to insert the enum values that
569 * are valid for the API in question into the enum hash table.
571 * \param the current context, for determining the API in question
573 void _mesa_init_get_hash(struct gl_context
*ctx
)
576 print_table_stats(ctx
->API
);
583 * Handle irregular enums
585 * Some values don't conform to the "well-known type at context
586 * pointer + offset" pattern, so we have this function to catch all
587 * the corner cases. Typically, it's a computed value or a one-off
588 * pointer to a custom struct or something.
590 * In this case we can't return a pointer to the value, so we'll have
591 * to use the temporary variable 'v' declared back in the calling
592 * glGet*v() function to store the result.
594 * \param ctx the current context
595 * \param d the struct value_desc that describes the enum
596 * \param v pointer to the tmp declared in the calling glGet*v() function
599 find_custom_value(struct gl_context
*ctx
, const struct value_desc
*d
, union value
*v
)
601 struct gl_buffer_object
**buffer_obj
;
602 struct gl_vertex_attrib_array
*array
;
606 case GL_MAJOR_VERSION
:
607 v
->value_int
= ctx
->Version
/ 10;
609 case GL_MINOR_VERSION
:
610 v
->value_int
= ctx
->Version
% 10;
616 case GL_TEXTURE_CUBE_MAP_ARB
:
617 case GL_TEXTURE_RECTANGLE_NV
:
618 case GL_TEXTURE_EXTERNAL_OES
:
619 v
->value_bool
= _mesa_IsEnabled(d
->pname
);
622 case GL_LINE_STIPPLE_PATTERN
:
623 /* This is the only GLushort, special case it here by promoting
624 * to an int rather than introducing a new type. */
625 v
->value_int
= ctx
->Line
.StipplePattern
;
628 case GL_CURRENT_RASTER_TEXTURE_COORDS
:
629 unit
= ctx
->Texture
.CurrentUnit
;
630 v
->value_float_4
[0] = ctx
->Current
.RasterTexCoords
[unit
][0];
631 v
->value_float_4
[1] = ctx
->Current
.RasterTexCoords
[unit
][1];
632 v
->value_float_4
[2] = ctx
->Current
.RasterTexCoords
[unit
][2];
633 v
->value_float_4
[3] = ctx
->Current
.RasterTexCoords
[unit
][3];
636 case GL_CURRENT_TEXTURE_COORDS
:
637 unit
= ctx
->Texture
.CurrentUnit
;
638 v
->value_float_4
[0] = ctx
->Current
.Attrib
[VERT_ATTRIB_TEX0
+ unit
][0];
639 v
->value_float_4
[1] = ctx
->Current
.Attrib
[VERT_ATTRIB_TEX0
+ unit
][1];
640 v
->value_float_4
[2] = ctx
->Current
.Attrib
[VERT_ATTRIB_TEX0
+ unit
][2];
641 v
->value_float_4
[3] = ctx
->Current
.Attrib
[VERT_ATTRIB_TEX0
+ unit
][3];
644 case GL_COLOR_WRITEMASK
:
645 v
->value_int_4
[0] = ctx
->Color
.ColorMask
[0][RCOMP
] ? 1 : 0;
646 v
->value_int_4
[1] = ctx
->Color
.ColorMask
[0][GCOMP
] ? 1 : 0;
647 v
->value_int_4
[2] = ctx
->Color
.ColorMask
[0][BCOMP
] ? 1 : 0;
648 v
->value_int_4
[3] = ctx
->Color
.ColorMask
[0][ACOMP
] ? 1 : 0;
652 v
->value_bool
= ctx
->Current
.Attrib
[VERT_ATTRIB_EDGEFLAG
][0] == 1.0F
;
656 v
->value_enum
= ctx
->ReadBuffer
->ColorReadBuffer
;
659 case GL_MAP2_GRID_DOMAIN
:
660 v
->value_float_4
[0] = ctx
->Eval
.MapGrid2u1
;
661 v
->value_float_4
[1] = ctx
->Eval
.MapGrid2u2
;
662 v
->value_float_4
[2] = ctx
->Eval
.MapGrid2v1
;
663 v
->value_float_4
[3] = ctx
->Eval
.MapGrid2v2
;
666 case GL_TEXTURE_STACK_DEPTH
:
667 unit
= ctx
->Texture
.CurrentUnit
;
668 v
->value_int
= ctx
->TextureMatrixStack
[unit
].Depth
+ 1;
670 case GL_TEXTURE_MATRIX
:
671 unit
= ctx
->Texture
.CurrentUnit
;
672 v
->value_matrix
= ctx
->TextureMatrixStack
[unit
].Top
;
675 case GL_TEXTURE_COORD_ARRAY
:
676 case GL_TEXTURE_COORD_ARRAY_SIZE
:
677 case GL_TEXTURE_COORD_ARRAY_TYPE
:
678 case GL_TEXTURE_COORD_ARRAY_STRIDE
:
679 array
= &ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_TEX(ctx
->Array
.ActiveTexture
)];
680 v
->value_int
= *(GLuint
*) ((char *) array
+ d
->offset
);
683 case GL_ACTIVE_TEXTURE_ARB
:
684 v
->value_int
= GL_TEXTURE0_ARB
+ ctx
->Texture
.CurrentUnit
;
686 case GL_CLIENT_ACTIVE_TEXTURE_ARB
:
687 v
->value_int
= GL_TEXTURE0_ARB
+ ctx
->Array
.ActiveTexture
;
690 case GL_MODELVIEW_STACK_DEPTH
:
691 case GL_PROJECTION_STACK_DEPTH
:
692 v
->value_int
= *(GLint
*) ((char *) ctx
+ d
->offset
) + 1;
695 case GL_MAX_TEXTURE_SIZE
:
696 case GL_MAX_3D_TEXTURE_SIZE
:
697 case GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB
:
698 p
= (GLuint
*) ((char *) ctx
+ d
->offset
);
699 v
->value_int
= 1 << (*p
- 1);
703 v
->value_int_4
[0] = ctx
->Scissor
.ScissorArray
[0].X
;
704 v
->value_int_4
[1] = ctx
->Scissor
.ScissorArray
[0].Y
;
705 v
->value_int_4
[2] = ctx
->Scissor
.ScissorArray
[0].Width
;
706 v
->value_int_4
[3] = ctx
->Scissor
.ScissorArray
[0].Height
;
709 case GL_SCISSOR_TEST
:
710 v
->value_bool
= ctx
->Scissor
.EnableFlags
& 1;
715 ctx
->ListState
.CurrentList
? ctx
->ListState
.CurrentList
->Name
: 0;
718 if (!ctx
->CompileFlag
)
720 else if (ctx
->ExecuteFlag
)
721 v
->value_enum
= GL_COMPILE_AND_EXECUTE
;
723 v
->value_enum
= GL_COMPILE
;
727 v
->value_float_4
[0] = ctx
->ViewportArray
[0].X
;
728 v
->value_float_4
[1] = ctx
->ViewportArray
[0].Y
;
729 v
->value_float_4
[2] = ctx
->ViewportArray
[0].Width
;
730 v
->value_float_4
[3] = ctx
->ViewportArray
[0].Height
;
734 v
->value_double_2
[0] = ctx
->ViewportArray
[0].Near
;
735 v
->value_double_2
[1] = ctx
->ViewportArray
[0].Far
;
738 case GL_ACTIVE_STENCIL_FACE_EXT
:
739 v
->value_enum
= ctx
->Stencil
.ActiveFace
? GL_BACK
: GL_FRONT
;
742 case GL_STENCIL_FAIL
:
743 v
->value_enum
= ctx
->Stencil
.FailFunc
[ctx
->Stencil
.ActiveFace
];
745 case GL_STENCIL_FUNC
:
746 v
->value_enum
= ctx
->Stencil
.Function
[ctx
->Stencil
.ActiveFace
];
748 case GL_STENCIL_PASS_DEPTH_FAIL
:
749 v
->value_enum
= ctx
->Stencil
.ZFailFunc
[ctx
->Stencil
.ActiveFace
];
751 case GL_STENCIL_PASS_DEPTH_PASS
:
752 v
->value_enum
= ctx
->Stencil
.ZPassFunc
[ctx
->Stencil
.ActiveFace
];
755 v
->value_int
= _mesa_get_stencil_ref(ctx
, ctx
->Stencil
.ActiveFace
);
757 case GL_STENCIL_BACK_REF
:
758 v
->value_int
= _mesa_get_stencil_ref(ctx
, 1);
760 case GL_STENCIL_VALUE_MASK
:
761 v
->value_int
= ctx
->Stencil
.ValueMask
[ctx
->Stencil
.ActiveFace
];
763 case GL_STENCIL_WRITEMASK
:
764 v
->value_int
= ctx
->Stencil
.WriteMask
[ctx
->Stencil
.ActiveFace
];
767 case GL_NUM_EXTENSIONS
:
768 v
->value_int
= _mesa_get_extension_count(ctx
);
771 case GL_IMPLEMENTATION_COLOR_READ_TYPE_OES
:
772 v
->value_int
= _mesa_get_color_read_type(ctx
);
774 case GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES
:
775 v
->value_int
= _mesa_get_color_read_format(ctx
);
778 case GL_CURRENT_MATRIX_STACK_DEPTH_ARB
:
779 v
->value_int
= ctx
->CurrentStack
->Depth
+ 1;
781 case GL_CURRENT_MATRIX_ARB
:
782 case GL_TRANSPOSE_CURRENT_MATRIX_ARB
:
783 v
->value_matrix
= ctx
->CurrentStack
->Top
;
786 case GL_NUM_COMPRESSED_TEXTURE_FORMATS_ARB
:
787 v
->value_int
= _mesa_get_compressed_formats(ctx
, NULL
);
789 case GL_COMPRESSED_TEXTURE_FORMATS_ARB
:
791 _mesa_get_compressed_formats(ctx
, v
->value_int_n
.ints
);
792 assert(v
->value_int_n
.n
<= (int) ARRAY_SIZE(v
->value_int_n
.ints
));
795 case GL_MAX_VARYING_FLOATS_ARB
:
796 v
->value_int
= ctx
->Const
.MaxVarying
* 4;
799 /* Various object names */
801 case GL_TEXTURE_BINDING_1D
:
802 case GL_TEXTURE_BINDING_2D
:
803 case GL_TEXTURE_BINDING_3D
:
804 case GL_TEXTURE_BINDING_1D_ARRAY_EXT
:
805 case GL_TEXTURE_BINDING_2D_ARRAY_EXT
:
806 case GL_TEXTURE_BINDING_CUBE_MAP_ARB
:
807 case GL_TEXTURE_BINDING_RECTANGLE_NV
:
808 case GL_TEXTURE_BINDING_EXTERNAL_OES
:
809 case GL_TEXTURE_BINDING_CUBE_MAP_ARRAY
:
810 case GL_TEXTURE_BINDING_2D_MULTISAMPLE
:
811 case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY
:
812 unit
= ctx
->Texture
.CurrentUnit
;
814 ctx
->Texture
.Unit
[unit
].CurrentTex
[d
->offset
]->Name
;
817 /* GL_EXT_packed_float */
818 case GL_RGBA_SIGNED_COMPONENTS_EXT
:
820 /* Note: we only check the 0th color attachment. */
821 const struct gl_renderbuffer
*rb
=
822 ctx
->DrawBuffer
->_ColorDrawBuffers
[0];
823 if (rb
&& _mesa_is_format_signed(rb
->Format
)) {
824 /* Issue 17 of GL_EXT_packed_float: If a component (such as
825 * alpha) has zero bits, the component should not be considered
826 * signed and so the bit for the respective component should be
830 _mesa_get_format_bits(rb
->Format
, GL_RED_BITS
);
832 _mesa_get_format_bits(rb
->Format
, GL_GREEN_BITS
);
834 _mesa_get_format_bits(rb
->Format
, GL_BLUE_BITS
);
836 _mesa_get_format_bits(rb
->Format
, GL_ALPHA_BITS
);
838 _mesa_get_format_bits(rb
->Format
, GL_TEXTURE_LUMINANCE_SIZE
);
840 _mesa_get_format_bits(rb
->Format
, GL_TEXTURE_INTENSITY_SIZE
);
842 v
->value_int_4
[0] = r_bits
+ l_bits
+ i_bits
> 0;
843 v
->value_int_4
[1] = g_bits
+ l_bits
+ i_bits
> 0;
844 v
->value_int_4
[2] = b_bits
+ l_bits
+ i_bits
> 0;
845 v
->value_int_4
[3] = a_bits
+ i_bits
> 0;
851 v
->value_int_4
[3] = 0;
856 /* GL_ARB_vertex_buffer_object */
857 case GL_VERTEX_ARRAY_BUFFER_BINDING_ARB
:
858 case GL_NORMAL_ARRAY_BUFFER_BINDING_ARB
:
859 case GL_COLOR_ARRAY_BUFFER_BINDING_ARB
:
860 case GL_INDEX_ARRAY_BUFFER_BINDING_ARB
:
861 case GL_EDGE_FLAG_ARRAY_BUFFER_BINDING_ARB
:
862 case GL_SECONDARY_COLOR_ARRAY_BUFFER_BINDING_ARB
:
863 case GL_FOG_COORDINATE_ARRAY_BUFFER_BINDING_ARB
:
864 buffer_obj
= (struct gl_buffer_object
**)
865 ((char *) ctx
->Array
.VAO
+ d
->offset
);
866 v
->value_int
= (*buffer_obj
)->Name
;
868 case GL_ARRAY_BUFFER_BINDING_ARB
:
869 v
->value_int
= ctx
->Array
.ArrayBufferObj
->Name
;
871 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING_ARB
:
873 ctx
->Array
.VAO
->VertexBinding
[VERT_ATTRIB_TEX(ctx
->Array
.ActiveTexture
)].BufferObj
->Name
;
875 case GL_ELEMENT_ARRAY_BUFFER_BINDING_ARB
:
876 v
->value_int
= ctx
->Array
.VAO
->IndexBufferObj
->Name
;
879 /* ARB_vertex_array_bgra */
880 case GL_COLOR_ARRAY_SIZE
:
881 array
= &ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_COLOR0
];
882 v
->value_int
= array
->Format
== GL_BGRA
? GL_BGRA
: array
->Size
;
884 case GL_SECONDARY_COLOR_ARRAY_SIZE
:
885 array
= &ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_COLOR1
];
886 v
->value_int
= array
->Format
== GL_BGRA
? GL_BGRA
: array
->Size
;
889 /* ARB_copy_buffer */
890 case GL_COPY_READ_BUFFER
:
891 v
->value_int
= ctx
->CopyReadBuffer
->Name
;
893 case GL_COPY_WRITE_BUFFER
:
894 v
->value_int
= ctx
->CopyWriteBuffer
->Name
;
897 case GL_PIXEL_PACK_BUFFER_BINDING_EXT
:
898 v
->value_int
= ctx
->Pack
.BufferObj
->Name
;
900 case GL_PIXEL_UNPACK_BUFFER_BINDING_EXT
:
901 v
->value_int
= ctx
->Unpack
.BufferObj
->Name
;
903 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING
:
904 v
->value_int
= ctx
->TransformFeedback
.CurrentBuffer
->Name
;
906 case GL_TRANSFORM_FEEDBACK_BUFFER_PAUSED
:
907 v
->value_int
= ctx
->TransformFeedback
.CurrentObject
->Paused
;
909 case GL_TRANSFORM_FEEDBACK_BUFFER_ACTIVE
:
910 v
->value_int
= ctx
->TransformFeedback
.CurrentObject
->Active
;
912 case GL_TRANSFORM_FEEDBACK_BINDING
:
913 v
->value_int
= ctx
->TransformFeedback
.CurrentObject
->Name
;
915 case GL_CURRENT_PROGRAM
:
916 /* The Changelog of the ARB_separate_shader_objects spec says:
918 * 24 25 Jul 2011 pbrown Remove the language erroneously deleting
919 * CURRENT_PROGRAM. In the EXT extension, this
920 * token was aliased to ACTIVE_PROGRAM_EXT, and
921 * was used to indicate the last program set by
922 * either ActiveProgramEXT or UseProgram. In
923 * the ARB extension, the SSO active programs
924 * are now program pipeline object state and
925 * CURRENT_PROGRAM should still be used to query
926 * the last program set by UseProgram (bug 7822).
929 ctx
->Shader
.ActiveProgram
? ctx
->Shader
.ActiveProgram
->Name
: 0;
931 case GL_READ_FRAMEBUFFER_BINDING_EXT
:
932 v
->value_int
= ctx
->ReadBuffer
->Name
;
934 case GL_RENDERBUFFER_BINDING_EXT
:
936 ctx
->CurrentRenderbuffer
? ctx
->CurrentRenderbuffer
->Name
: 0;
938 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES
:
939 v
->value_int
= ctx
->Array
.VAO
->VertexBinding
[VERT_ATTRIB_POINT_SIZE
].BufferObj
->Name
;
943 if (_mesa_get_clamp_fragment_color(ctx
, ctx
->DrawBuffer
))
944 COPY_4FV(v
->value_float_4
, ctx
->Fog
.Color
);
946 COPY_4FV(v
->value_float_4
, ctx
->Fog
.ColorUnclamped
);
948 case GL_COLOR_CLEAR_VALUE
:
949 if (_mesa_get_clamp_fragment_color(ctx
, ctx
->DrawBuffer
)) {
950 v
->value_float_4
[0] = CLAMP(ctx
->Color
.ClearColor
.f
[0], 0.0F
, 1.0F
);
951 v
->value_float_4
[1] = CLAMP(ctx
->Color
.ClearColor
.f
[1], 0.0F
, 1.0F
);
952 v
->value_float_4
[2] = CLAMP(ctx
->Color
.ClearColor
.f
[2], 0.0F
, 1.0F
);
953 v
->value_float_4
[3] = CLAMP(ctx
->Color
.ClearColor
.f
[3], 0.0F
, 1.0F
);
955 COPY_4FV(v
->value_float_4
, ctx
->Color
.ClearColor
.f
);
957 case GL_BLEND_COLOR_EXT
:
958 if (_mesa_get_clamp_fragment_color(ctx
, ctx
->DrawBuffer
))
959 COPY_4FV(v
->value_float_4
, ctx
->Color
.BlendColor
);
961 COPY_4FV(v
->value_float_4
, ctx
->Color
.BlendColorUnclamped
);
963 case GL_ALPHA_TEST_REF
:
964 if (_mesa_get_clamp_fragment_color(ctx
, ctx
->DrawBuffer
))
965 v
->value_float
= ctx
->Color
.AlphaRef
;
967 v
->value_float
= ctx
->Color
.AlphaRefUnclamped
;
969 case GL_MAX_VERTEX_UNIFORM_VECTORS
:
970 v
->value_int
= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxUniformComponents
/ 4;
973 case GL_MAX_FRAGMENT_UNIFORM_VECTORS
:
974 v
->value_int
= ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxUniformComponents
/ 4;
977 /* GL_ARB_texture_buffer_object */
978 case GL_TEXTURE_BUFFER_ARB
:
979 v
->value_int
= ctx
->Texture
.BufferObject
->Name
;
981 case GL_TEXTURE_BINDING_BUFFER_ARB
:
982 unit
= ctx
->Texture
.CurrentUnit
;
984 ctx
->Texture
.Unit
[unit
].CurrentTex
[TEXTURE_BUFFER_INDEX
]->Name
;
986 case GL_TEXTURE_BUFFER_DATA_STORE_BINDING_ARB
:
988 struct gl_buffer_object
*buf
=
989 ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
]
990 .CurrentTex
[TEXTURE_BUFFER_INDEX
]->BufferObject
;
991 v
->value_int
= buf
? buf
->Name
: 0;
994 case GL_TEXTURE_BUFFER_FORMAT_ARB
:
995 v
->value_int
= ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
]
996 .CurrentTex
[TEXTURE_BUFFER_INDEX
]->BufferObjectFormat
;
999 /* GL_ARB_sampler_objects */
1000 case GL_SAMPLER_BINDING
:
1002 struct gl_sampler_object
*samp
=
1003 ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
].Sampler
;
1004 v
->value_int
= samp
? samp
->Name
: 0;
1007 /* GL_ARB_uniform_buffer_object */
1008 case GL_UNIFORM_BUFFER_BINDING
:
1009 v
->value_int
= ctx
->UniformBuffer
->Name
;
1011 /* GL_ARB_shader_storage_buffer_object */
1012 case GL_SHADER_STORAGE_BUFFER_BINDING
:
1013 v
->value_int
= ctx
->ShaderStorageBuffer
->Name
;
1015 /* GL_ARB_timer_query */
1017 if (ctx
->Driver
.GetTimestamp
) {
1018 v
->value_int64
= ctx
->Driver
.GetTimestamp(ctx
);
1021 _mesa_problem(ctx
, "driver doesn't implement GetTimestamp");
1025 case GL_DEBUG_LOGGED_MESSAGES
:
1026 case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH
:
1027 case GL_DEBUG_GROUP_STACK_DEPTH
:
1028 v
->value_int
= _mesa_get_debug_state_int(ctx
, d
->pname
);
1030 /* GL_ARB_shader_atomic_counters */
1031 case GL_ATOMIC_COUNTER_BUFFER_BINDING
:
1032 if (ctx
->AtomicBuffer
) {
1033 v
->value_int
= ctx
->AtomicBuffer
->Name
;
1038 /* GL_ARB_draw_indirect */
1039 case GL_DRAW_INDIRECT_BUFFER_BINDING
:
1040 v
->value_int
= ctx
->DrawIndirectBuffer
->Name
;
1042 /* GL_ARB_separate_shader_objects */
1043 case GL_PROGRAM_PIPELINE_BINDING
:
1044 if (ctx
->Pipeline
.Current
) {
1045 v
->value_int
= ctx
->Pipeline
.Current
->Name
;
1050 /* GL_ARB_compute_shader */
1051 case GL_DISPATCH_INDIRECT_BUFFER_BINDING
:
1052 v
->value_int
= ctx
->DispatchIndirectBuffer
->Name
;
1058 * Check extra constraints on a struct value_desc descriptor
1060 * If a struct value_desc has a non-NULL extra pointer, it means that
1061 * there are a number of extra constraints to check or actions to
1062 * perform. The extras is just an integer array where each integer
1063 * encode different constraints or actions.
1065 * \param ctx current context
1066 * \param func name of calling glGet*v() function for error reporting
1067 * \param d the struct value_desc that has the extra constraints
1069 * \return GL_FALSE if all of the constraints were not satisfied,
1070 * otherwise GL_TRUE.
1073 check_extra(struct gl_context
*ctx
, const char *func
, const struct value_desc
*d
)
1075 const GLuint version
= ctx
->Version
;
1076 GLboolean api_check
= GL_FALSE
;
1077 GLboolean api_found
= GL_FALSE
;
1080 for (e
= d
->extra
; *e
!= EXTRA_END
; e
++) {
1082 case EXTRA_VERSION_30
:
1083 api_check
= GL_TRUE
;
1085 api_found
= GL_TRUE
;
1087 case EXTRA_VERSION_31
:
1088 api_check
= GL_TRUE
;
1090 api_found
= GL_TRUE
;
1092 case EXTRA_VERSION_32
:
1093 api_check
= GL_TRUE
;
1095 api_found
= GL_TRUE
;
1097 case EXTRA_NEW_FRAG_CLAMP
:
1098 if (ctx
->NewState
& (_NEW_BUFFERS
| _NEW_FRAG_CLAMP
))
1099 _mesa_update_state(ctx
);
1102 api_check
= GL_TRUE
;
1103 if (ctx
->API
== API_OPENGLES2
)
1104 api_found
= GL_TRUE
;
1107 api_check
= GL_TRUE
;
1108 if (_mesa_is_gles3(ctx
))
1109 api_found
= GL_TRUE
;
1111 case EXTRA_API_ES31
:
1112 api_check
= GL_TRUE
;
1113 if (_mesa_is_gles31(ctx
))
1114 api_found
= GL_TRUE
;
1117 api_check
= GL_TRUE
;
1118 if (_mesa_is_desktop_gl(ctx
))
1119 api_found
= GL_TRUE
;
1121 case EXTRA_API_GL_CORE
:
1122 api_check
= GL_TRUE
;
1123 if (ctx
->API
== API_OPENGL_CORE
)
1124 api_found
= GL_TRUE
;
1126 case EXTRA_NEW_BUFFERS
:
1127 if (ctx
->NewState
& _NEW_BUFFERS
)
1128 _mesa_update_state(ctx
);
1130 case EXTRA_FLUSH_CURRENT
:
1131 FLUSH_CURRENT(ctx
, 0);
1133 case EXTRA_VALID_DRAW_BUFFER
:
1134 if (d
->pname
- GL_DRAW_BUFFER0_ARB
>= ctx
->Const
.MaxDrawBuffers
) {
1135 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(draw buffer %u)",
1136 func
, d
->pname
- GL_DRAW_BUFFER0_ARB
);
1140 case EXTRA_VALID_TEXTURE_UNIT
:
1141 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureCoordUnits
) {
1142 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(texture %u)",
1143 func
, ctx
->Texture
.CurrentUnit
);
1147 case EXTRA_VALID_CLIP_DISTANCE
:
1148 if (d
->pname
- GL_CLIP_DISTANCE0
>= ctx
->Const
.MaxClipPlanes
) {
1149 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(clip distance %u)",
1150 func
, d
->pname
- GL_CLIP_DISTANCE0
);
1154 case EXTRA_GLSL_130
:
1155 api_check
= GL_TRUE
;
1156 if (ctx
->Const
.GLSLVersion
>= 130)
1157 api_found
= GL_TRUE
;
1159 case EXTRA_EXT_UBO_GS4
:
1160 api_check
= GL_TRUE
;
1161 api_found
= (ctx
->Extensions
.ARB_uniform_buffer_object
&&
1162 _mesa_has_geometry_shaders(ctx
));
1164 case EXTRA_EXT_ATOMICS_GS4
:
1165 api_check
= GL_TRUE
;
1166 api_found
= (ctx
->Extensions
.ARB_shader_atomic_counters
&&
1167 _mesa_has_geometry_shaders(ctx
));
1169 case EXTRA_EXT_SHADER_IMAGE_GS4
:
1170 api_check
= GL_TRUE
;
1171 api_found
= (ctx
->Extensions
.ARB_shader_image_load_store
&&
1172 _mesa_has_geometry_shaders(ctx
));
1174 case EXTRA_EXT_ATOMICS_TESS
:
1175 api_check
= GL_TRUE
;
1176 api_found
= ctx
->Extensions
.ARB_shader_atomic_counters
&&
1177 _mesa_has_tessellation(ctx
);
1179 case EXTRA_EXT_SHADER_IMAGE_TESS
:
1180 api_check
= GL_TRUE
;
1181 api_found
= ctx
->Extensions
.ARB_shader_image_load_store
&&
1182 _mesa_has_tessellation(ctx
);
1186 default: /* *e is a offset into the extension struct */
1187 api_check
= GL_TRUE
;
1188 if (*(GLboolean
*) ((char *) &ctx
->Extensions
+ *e
))
1189 api_found
= GL_TRUE
;
1194 if (api_check
&& !api_found
) {
1195 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=%s)", func
,
1196 _mesa_enum_to_string(d
->pname
));
1203 static const struct value_desc error_value
=
1204 { 0, 0, TYPE_INVALID
, NO_OFFSET
, NO_EXTRA
};
1207 * Find the struct value_desc corresponding to the enum 'pname'.
1209 * We hash the enum value to get an index into the 'table' array,
1210 * which holds the index in the 'values' array of struct value_desc.
1211 * Once we've found the entry, we do the extra checks, if any, then
1212 * look up the value and return a pointer to it.
1214 * If the value has to be computed (for example, it's the result of a
1215 * function call or we need to add 1 to it), we use the tmp 'v' to
1218 * \param func name of glGet*v() func for error reporting
1219 * \param pname the enum value we're looking up
1220 * \param p is were we return the pointer to the value
1221 * \param v a tmp union value variable in the calling glGet*v() function
1223 * \return the struct value_desc corresponding to the enum or a struct
1224 * value_desc of TYPE_INVALID if not found. This lets the calling
1225 * glGet*v() function jump right into a switch statement and
1226 * handle errors there instead of having to check for NULL.
1228 static const struct value_desc
*
1229 find_value(const char *func
, GLenum pname
, void **p
, union value
*v
)
1231 GET_CURRENT_CONTEXT(ctx
);
1232 struct gl_texture_unit
*unit
;
1234 const struct value_desc
*d
;
1238 /* We index into the table_set[] list of per-API hash tables using the API's
1239 * value in the gl_api enum. Since GLES 3 doesn't have an API_OPENGL* enum
1240 * value since it's compatible with GLES2 its entry in table_set[] is at the
1243 STATIC_ASSERT(ARRAY_SIZE(table_set
) == API_OPENGL_LAST
+ 3);
1244 if (_mesa_is_gles3(ctx
)) {
1245 api
= API_OPENGL_LAST
+ 1;
1247 if (_mesa_is_gles31(ctx
)) {
1248 api
= API_OPENGL_LAST
+ 2;
1250 mask
= ARRAY_SIZE(table(api
)) - 1;
1251 hash
= (pname
* prime_factor
);
1253 int idx
= table(api
)[hash
& mask
];
1255 /* If the enum isn't valid, the hash walk ends with index 0,
1256 * pointing to the first entry of values[] which doesn't hold
1257 * any valid enum. */
1258 if (unlikely(idx
== 0)) {
1259 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=%s)", func
,
1260 _mesa_enum_to_string(pname
));
1261 return &error_value
;
1265 if (likely(d
->pname
== pname
))
1271 if (unlikely(d
->extra
&& !check_extra(ctx
, func
, d
)))
1272 return &error_value
;
1274 switch (d
->location
) {
1276 *p
= ((char *) ctx
->DrawBuffer
+ d
->offset
);
1279 *p
= ((char *) ctx
+ d
->offset
);
1282 *p
= ((char *) ctx
->Array
.VAO
+ d
->offset
);
1285 unit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1286 *p
= ((char *) unit
+ d
->offset
);
1289 find_custom_value(ctx
, d
, v
);
1297 /* silence warning */
1298 return &error_value
;
1301 static const int transpose
[] = {
1309 _mesa_GetBooleanv(GLenum pname
, GLboolean
*params
)
1311 const struct value_desc
*d
;
1317 d
= find_value("glGetBooleanv", pname
, &p
, &v
);
1322 params
[0] = INT_TO_BOOLEAN(d
->offset
);
1327 params
[3] = FLOAT_TO_BOOLEAN(((GLfloat
*) p
)[3]);
1330 params
[2] = FLOAT_TO_BOOLEAN(((GLfloat
*) p
)[2]);
1333 params
[1] = FLOAT_TO_BOOLEAN(((GLfloat
*) p
)[1]);
1336 params
[0] = FLOAT_TO_BOOLEAN(((GLfloat
*) p
)[0]);
1339 case TYPE_DOUBLEN_2
:
1340 params
[1] = FLOAT_TO_BOOLEAN(((GLdouble
*) p
)[1]);
1342 params
[0] = FLOAT_TO_BOOLEAN(((GLdouble
*) p
)[0]);
1346 params
[3] = INT_TO_BOOLEAN(((GLint
*) p
)[3]);
1348 params
[2] = INT_TO_BOOLEAN(((GLint
*) p
)[2]);
1351 params
[1] = INT_TO_BOOLEAN(((GLint
*) p
)[1]);
1354 params
[0] = INT_TO_BOOLEAN(((GLint
*) p
)[0]);
1358 for (i
= 0; i
< v
.value_int_n
.n
; i
++)
1359 params
[i
] = INT_TO_BOOLEAN(v
.value_int_n
.ints
[i
]);
1363 params
[0] = INT64_TO_BOOLEAN(((GLint64
*) p
)[0]);
1367 params
[0] = ((GLboolean
*) p
)[0];
1371 m
= *(GLmatrix
**) p
;
1372 for (i
= 0; i
< 16; i
++)
1373 params
[i
] = FLOAT_TO_BOOLEAN(m
->m
[i
]);
1377 m
= *(GLmatrix
**) p
;
1378 for (i
= 0; i
< 16; i
++)
1379 params
[i
] = FLOAT_TO_BOOLEAN(m
->m
[transpose
[i
]]);
1390 shift
= d
->type
- TYPE_BIT_0
;
1391 params
[0] = (*(GLbitfield
*) p
>> shift
) & 1;
1397 _mesa_GetFloatv(GLenum pname
, GLfloat
*params
)
1399 const struct value_desc
*d
;
1405 d
= find_value("glGetFloatv", pname
, &p
, &v
);
1410 params
[0] = (GLfloat
) d
->offset
;
1415 params
[3] = ((GLfloat
*) p
)[3];
1418 params
[2] = ((GLfloat
*) p
)[2];
1421 params
[1] = ((GLfloat
*) p
)[1];
1424 params
[0] = ((GLfloat
*) p
)[0];
1427 case TYPE_DOUBLEN_2
:
1428 params
[1] = (GLfloat
) (((GLdouble
*) p
)[1]);
1430 params
[0] = (GLfloat
) (((GLdouble
*) p
)[0]);
1434 params
[3] = (GLfloat
) (((GLint
*) p
)[3]);
1436 params
[2] = (GLfloat
) (((GLint
*) p
)[2]);
1439 params
[1] = (GLfloat
) (((GLint
*) p
)[1]);
1442 params
[0] = (GLfloat
) (((GLint
*) p
)[0]);
1446 for (i
= 0; i
< v
.value_int_n
.n
; i
++)
1447 params
[i
] = INT_TO_FLOAT(v
.value_int_n
.ints
[i
]);
1451 params
[0] = (GLfloat
) (((GLint64
*) p
)[0]);
1455 params
[0] = BOOLEAN_TO_FLOAT(*(GLboolean
*) p
);
1459 m
= *(GLmatrix
**) p
;
1460 for (i
= 0; i
< 16; i
++)
1461 params
[i
] = m
->m
[i
];
1465 m
= *(GLmatrix
**) p
;
1466 for (i
= 0; i
< 16; i
++)
1467 params
[i
] = m
->m
[transpose
[i
]];
1478 shift
= d
->type
- TYPE_BIT_0
;
1479 params
[0] = BOOLEAN_TO_FLOAT((*(GLbitfield
*) p
>> shift
) & 1);
1485 _mesa_GetIntegerv(GLenum pname
, GLint
*params
)
1487 const struct value_desc
*d
;
1493 d
= find_value("glGetIntegerv", pname
, &p
, &v
);
1498 params
[0] = d
->offset
;
1502 params
[3] = IROUND(((GLfloat
*) p
)[3]);
1504 params
[2] = IROUND(((GLfloat
*) p
)[2]);
1506 params
[1] = IROUND(((GLfloat
*) p
)[1]);
1508 params
[0] = IROUND(((GLfloat
*) p
)[0]);
1512 params
[3] = FLOAT_TO_INT(((GLfloat
*) p
)[3]);
1514 params
[2] = FLOAT_TO_INT(((GLfloat
*) p
)[2]);
1516 params
[1] = FLOAT_TO_INT(((GLfloat
*) p
)[1]);
1518 params
[0] = FLOAT_TO_INT(((GLfloat
*) p
)[0]);
1521 case TYPE_DOUBLEN_2
:
1522 params
[1] = FLOAT_TO_INT(((GLdouble
*) p
)[1]);
1524 params
[0] = FLOAT_TO_INT(((GLdouble
*) p
)[0]);
1528 params
[3] = ((GLint
*) p
)[3];
1530 params
[2] = ((GLint
*) p
)[2];
1533 params
[1] = ((GLint
*) p
)[1];
1536 params
[0] = ((GLint
*) p
)[0];
1540 for (i
= 0; i
< v
.value_int_n
.n
; i
++)
1541 params
[i
] = v
.value_int_n
.ints
[i
];
1545 params
[0] = INT64_TO_INT(((GLint64
*) p
)[0]);
1549 params
[0] = BOOLEAN_TO_INT(*(GLboolean
*) p
);
1553 m
= *(GLmatrix
**) p
;
1554 for (i
= 0; i
< 16; i
++)
1555 params
[i
] = FLOAT_TO_INT(m
->m
[i
]);
1559 m
= *(GLmatrix
**) p
;
1560 for (i
= 0; i
< 16; i
++)
1561 params
[i
] = FLOAT_TO_INT(m
->m
[transpose
[i
]]);
1572 shift
= d
->type
- TYPE_BIT_0
;
1573 params
[0] = (*(GLbitfield
*) p
>> shift
) & 1;
1579 _mesa_GetInteger64v(GLenum pname
, GLint64
*params
)
1581 const struct value_desc
*d
;
1587 d
= find_value("glGetInteger64v", pname
, &p
, &v
);
1592 params
[0] = d
->offset
;
1596 params
[3] = IROUND64(((GLfloat
*) p
)[3]);
1598 params
[2] = IROUND64(((GLfloat
*) p
)[2]);
1600 params
[1] = IROUND64(((GLfloat
*) p
)[1]);
1602 params
[0] = IROUND64(((GLfloat
*) p
)[0]);
1606 params
[3] = FLOAT_TO_INT64(((GLfloat
*) p
)[3]);
1608 params
[2] = FLOAT_TO_INT64(((GLfloat
*) p
)[2]);
1610 params
[1] = FLOAT_TO_INT64(((GLfloat
*) p
)[1]);
1612 params
[0] = FLOAT_TO_INT64(((GLfloat
*) p
)[0]);
1615 case TYPE_DOUBLEN_2
:
1616 params
[1] = FLOAT_TO_INT64(((GLdouble
*) p
)[1]);
1618 params
[0] = FLOAT_TO_INT64(((GLdouble
*) p
)[0]);
1622 params
[3] = ((GLint
*) p
)[3];
1624 params
[2] = ((GLint
*) p
)[2];
1627 params
[1] = ((GLint
*) p
)[1];
1630 params
[0] = ((GLint
*) p
)[0];
1634 for (i
= 0; i
< v
.value_int_n
.n
; i
++)
1635 params
[i
] = INT_TO_BOOLEAN(v
.value_int_n
.ints
[i
]);
1639 params
[0] = ((GLint64
*) p
)[0];
1643 params
[0] = ((GLboolean
*) p
)[0];
1647 m
= *(GLmatrix
**) p
;
1648 for (i
= 0; i
< 16; i
++)
1649 params
[i
] = FLOAT_TO_INT64(m
->m
[i
]);
1653 m
= *(GLmatrix
**) p
;
1654 for (i
= 0; i
< 16; i
++)
1655 params
[i
] = FLOAT_TO_INT64(m
->m
[transpose
[i
]]);
1666 shift
= d
->type
- TYPE_BIT_0
;
1667 params
[0] = (*(GLbitfield
*) p
>> shift
) & 1;
1673 _mesa_GetDoublev(GLenum pname
, GLdouble
*params
)
1675 const struct value_desc
*d
;
1681 d
= find_value("glGetDoublev", pname
, &p
, &v
);
1686 params
[0] = d
->offset
;
1691 params
[3] = ((GLfloat
*) p
)[3];
1694 params
[2] = ((GLfloat
*) p
)[2];
1697 params
[1] = ((GLfloat
*) p
)[1];
1700 params
[0] = ((GLfloat
*) p
)[0];
1703 case TYPE_DOUBLEN_2
:
1704 params
[1] = ((GLdouble
*) p
)[1];
1706 params
[0] = ((GLdouble
*) p
)[0];
1710 params
[3] = ((GLint
*) p
)[3];
1712 params
[2] = ((GLint
*) p
)[2];
1715 params
[1] = ((GLint
*) p
)[1];
1718 params
[0] = ((GLint
*) p
)[0];
1722 for (i
= 0; i
< v
.value_int_n
.n
; i
++)
1723 params
[i
] = v
.value_int_n
.ints
[i
];
1727 params
[0] = (GLdouble
) (((GLint64
*) p
)[0]);
1731 params
[0] = *(GLboolean
*) p
;
1735 m
= *(GLmatrix
**) p
;
1736 for (i
= 0; i
< 16; i
++)
1737 params
[i
] = m
->m
[i
];
1741 m
= *(GLmatrix
**) p
;
1742 for (i
= 0; i
< 16; i
++)
1743 params
[i
] = m
->m
[transpose
[i
]];
1754 shift
= d
->type
- TYPE_BIT_0
;
1755 params
[0] = (*(GLbitfield
*) p
>> shift
) & 1;
1761 * Convert a GL texture binding enum such as GL_TEXTURE_BINDING_2D
1762 * into the corresponding Mesa texture target index.
1763 * \return TEXTURE_x_INDEX or -1 if binding is invalid
1766 tex_binding_to_index(const struct gl_context
*ctx
, GLenum binding
)
1769 case GL_TEXTURE_BINDING_1D
:
1770 return _mesa_is_desktop_gl(ctx
) ? TEXTURE_1D_INDEX
: -1;
1771 case GL_TEXTURE_BINDING_2D
:
1772 return TEXTURE_2D_INDEX
;
1773 case GL_TEXTURE_BINDING_3D
:
1774 return ctx
->API
!= API_OPENGLES
? TEXTURE_3D_INDEX
: -1;
1775 case GL_TEXTURE_BINDING_CUBE_MAP
:
1776 return ctx
->Extensions
.ARB_texture_cube_map
1777 ? TEXTURE_CUBE_INDEX
: -1;
1778 case GL_TEXTURE_BINDING_RECTANGLE
:
1779 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.NV_texture_rectangle
1780 ? TEXTURE_RECT_INDEX
: -1;
1781 case GL_TEXTURE_BINDING_1D_ARRAY
:
1782 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
1783 ? TEXTURE_1D_ARRAY_INDEX
: -1;
1784 case GL_TEXTURE_BINDING_2D_ARRAY
:
1785 return (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
)
1786 || _mesa_is_gles3(ctx
)
1787 ? TEXTURE_2D_ARRAY_INDEX
: -1;
1788 case GL_TEXTURE_BINDING_BUFFER
:
1789 return ctx
->API
== API_OPENGL_CORE
&&
1790 ctx
->Extensions
.ARB_texture_buffer_object
?
1791 TEXTURE_BUFFER_INDEX
: -1;
1792 case GL_TEXTURE_BINDING_CUBE_MAP_ARRAY
:
1793 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_cube_map_array
1794 ? TEXTURE_CUBE_ARRAY_INDEX
: -1;
1795 case GL_TEXTURE_BINDING_2D_MULTISAMPLE
:
1796 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_multisample
1797 ? TEXTURE_2D_MULTISAMPLE_INDEX
: -1;
1798 case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY
:
1799 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_multisample
1800 ? TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX
: -1;
1806 static enum value_type
1807 find_value_indexed(const char *func
, GLenum pname
, GLuint index
, union value
*v
)
1809 GET_CURRENT_CONTEXT(ctx
);
1814 if (index
>= ctx
->Const
.MaxDrawBuffers
)
1816 if (!ctx
->Extensions
.EXT_draw_buffers2
)
1818 v
->value_int
= (ctx
->Color
.BlendEnabled
>> index
) & 1;
1823 case GL_BLEND_SRC_RGB
:
1824 if (index
>= ctx
->Const
.MaxDrawBuffers
)
1826 if (!ctx
->Extensions
.ARB_draw_buffers_blend
)
1828 v
->value_int
= ctx
->Color
.Blend
[index
].SrcRGB
;
1830 case GL_BLEND_SRC_ALPHA
:
1831 if (index
>= ctx
->Const
.MaxDrawBuffers
)
1833 if (!ctx
->Extensions
.ARB_draw_buffers_blend
)
1835 v
->value_int
= ctx
->Color
.Blend
[index
].SrcA
;
1839 case GL_BLEND_DST_RGB
:
1840 if (index
>= ctx
->Const
.MaxDrawBuffers
)
1842 if (!ctx
->Extensions
.ARB_draw_buffers_blend
)
1844 v
->value_int
= ctx
->Color
.Blend
[index
].DstRGB
;
1846 case GL_BLEND_DST_ALPHA
:
1847 if (index
>= ctx
->Const
.MaxDrawBuffers
)
1849 if (!ctx
->Extensions
.ARB_draw_buffers_blend
)
1851 v
->value_int
= ctx
->Color
.Blend
[index
].DstA
;
1853 case GL_BLEND_EQUATION_RGB
:
1854 if (index
>= ctx
->Const
.MaxDrawBuffers
)
1856 if (!ctx
->Extensions
.ARB_draw_buffers_blend
)
1858 v
->value_int
= ctx
->Color
.Blend
[index
].EquationRGB
;
1860 case GL_BLEND_EQUATION_ALPHA
:
1861 if (index
>= ctx
->Const
.MaxDrawBuffers
)
1863 if (!ctx
->Extensions
.ARB_draw_buffers_blend
)
1865 v
->value_int
= ctx
->Color
.Blend
[index
].EquationA
;
1868 case GL_COLOR_WRITEMASK
:
1869 if (index
>= ctx
->Const
.MaxDrawBuffers
)
1871 if (!ctx
->Extensions
.EXT_draw_buffers2
)
1873 v
->value_int_4
[0] = ctx
->Color
.ColorMask
[index
][RCOMP
] ? 1 : 0;
1874 v
->value_int_4
[1] = ctx
->Color
.ColorMask
[index
][GCOMP
] ? 1 : 0;
1875 v
->value_int_4
[2] = ctx
->Color
.ColorMask
[index
][BCOMP
] ? 1 : 0;
1876 v
->value_int_4
[3] = ctx
->Color
.ColorMask
[index
][ACOMP
] ? 1 : 0;
1879 case GL_SCISSOR_BOX
:
1880 if (index
>= ctx
->Const
.MaxViewports
)
1882 v
->value_int_4
[0] = ctx
->Scissor
.ScissorArray
[index
].X
;
1883 v
->value_int_4
[1] = ctx
->Scissor
.ScissorArray
[index
].Y
;
1884 v
->value_int_4
[2] = ctx
->Scissor
.ScissorArray
[index
].Width
;
1885 v
->value_int_4
[3] = ctx
->Scissor
.ScissorArray
[index
].Height
;
1889 if (index
>= ctx
->Const
.MaxViewports
)
1891 v
->value_float_4
[0] = ctx
->ViewportArray
[index
].X
;
1892 v
->value_float_4
[1] = ctx
->ViewportArray
[index
].Y
;
1893 v
->value_float_4
[2] = ctx
->ViewportArray
[index
].Width
;
1894 v
->value_float_4
[3] = ctx
->ViewportArray
[index
].Height
;
1895 return TYPE_FLOAT_4
;
1897 case GL_DEPTH_RANGE
:
1898 if (index
>= ctx
->Const
.MaxViewports
)
1900 v
->value_double_2
[0] = ctx
->ViewportArray
[index
].Near
;
1901 v
->value_double_2
[1] = ctx
->ViewportArray
[index
].Far
;
1902 return TYPE_DOUBLEN_2
;
1904 case GL_TRANSFORM_FEEDBACK_BUFFER_START
:
1905 if (index
>= ctx
->Const
.MaxTransformFeedbackBuffers
)
1907 if (!ctx
->Extensions
.EXT_transform_feedback
)
1909 v
->value_int64
= ctx
->TransformFeedback
.CurrentObject
->Offset
[index
];
1912 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE
:
1913 if (index
>= ctx
->Const
.MaxTransformFeedbackBuffers
)
1915 if (!ctx
->Extensions
.EXT_transform_feedback
)
1918 = ctx
->TransformFeedback
.CurrentObject
->RequestedSize
[index
];
1921 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING
:
1922 if (index
>= ctx
->Const
.MaxTransformFeedbackBuffers
)
1924 if (!ctx
->Extensions
.EXT_transform_feedback
)
1926 v
->value_int
= ctx
->TransformFeedback
.CurrentObject
->BufferNames
[index
];
1929 case GL_UNIFORM_BUFFER_BINDING
:
1930 if (index
>= ctx
->Const
.MaxUniformBufferBindings
)
1932 if (!ctx
->Extensions
.ARB_uniform_buffer_object
)
1934 v
->value_int
= ctx
->UniformBufferBindings
[index
].BufferObject
->Name
;
1937 case GL_UNIFORM_BUFFER_START
:
1938 if (index
>= ctx
->Const
.MaxUniformBufferBindings
)
1940 if (!ctx
->Extensions
.ARB_uniform_buffer_object
)
1942 v
->value_int
= ctx
->UniformBufferBindings
[index
].Offset
< 0 ? 0 :
1943 ctx
->UniformBufferBindings
[index
].Offset
;
1946 case GL_UNIFORM_BUFFER_SIZE
:
1947 if (index
>= ctx
->Const
.MaxUniformBufferBindings
)
1949 if (!ctx
->Extensions
.ARB_uniform_buffer_object
)
1951 v
->value_int
= ctx
->UniformBufferBindings
[index
].Size
< 0 ? 0 :
1952 ctx
->UniformBufferBindings
[index
].Size
;
1955 /* ARB_shader_storage_buffer_object */
1956 case GL_SHADER_STORAGE_BUFFER_BINDING
:
1957 if (!ctx
->Extensions
.ARB_shader_storage_buffer_object
)
1959 if (index
>= ctx
->Const
.MaxShaderStorageBufferBindings
)
1961 v
->value_int
= ctx
->ShaderStorageBufferBindings
[index
].BufferObject
->Name
;
1964 case GL_SHADER_STORAGE_BUFFER_START
:
1965 if (!ctx
->Extensions
.ARB_shader_storage_buffer_object
)
1967 if (index
>= ctx
->Const
.MaxShaderStorageBufferBindings
)
1969 v
->value_int
= ctx
->ShaderStorageBufferBindings
[index
].Offset
< 0 ? 0 :
1970 ctx
->ShaderStorageBufferBindings
[index
].Offset
;
1973 case GL_SHADER_STORAGE_BUFFER_SIZE
:
1974 if (!ctx
->Extensions
.ARB_shader_storage_buffer_object
)
1976 if (index
>= ctx
->Const
.MaxShaderStorageBufferBindings
)
1978 v
->value_int
= ctx
->ShaderStorageBufferBindings
[index
].Size
< 0 ? 0 :
1979 ctx
->ShaderStorageBufferBindings
[index
].Size
;
1982 /* ARB_texture_multisample / GL3.2 */
1983 case GL_SAMPLE_MASK_VALUE
:
1986 if (!ctx
->Extensions
.ARB_texture_multisample
)
1988 v
->value_int
= ctx
->Multisample
.SampleMaskValue
;
1991 case GL_ATOMIC_COUNTER_BUFFER_BINDING
:
1992 if (!ctx
->Extensions
.ARB_shader_atomic_counters
)
1994 if (index
>= ctx
->Const
.MaxAtomicBufferBindings
)
1996 v
->value_int
= ctx
->AtomicBufferBindings
[index
].BufferObject
->Name
;
1999 case GL_ATOMIC_COUNTER_BUFFER_START
:
2000 if (!ctx
->Extensions
.ARB_shader_atomic_counters
)
2002 if (index
>= ctx
->Const
.MaxAtomicBufferBindings
)
2004 v
->value_int64
= ctx
->AtomicBufferBindings
[index
].Offset
;
2007 case GL_ATOMIC_COUNTER_BUFFER_SIZE
:
2008 if (!ctx
->Extensions
.ARB_shader_atomic_counters
)
2010 if (index
>= ctx
->Const
.MaxAtomicBufferBindings
)
2012 v
->value_int64
= ctx
->AtomicBufferBindings
[index
].Size
;
2015 case GL_VERTEX_BINDING_DIVISOR
:
2016 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_instanced_arrays
) &&
2017 !_mesa_is_gles31(ctx
))
2019 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
)
2021 v
->value_int
= ctx
->Array
.VAO
->VertexBinding
[VERT_ATTRIB_GENERIC(index
)].InstanceDivisor
;
2024 case GL_VERTEX_BINDING_OFFSET
:
2025 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles31(ctx
))
2027 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
)
2029 v
->value_int
= ctx
->Array
.VAO
->VertexBinding
[VERT_ATTRIB_GENERIC(index
)].Offset
;
2032 case GL_VERTEX_BINDING_STRIDE
:
2033 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles31(ctx
))
2035 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
)
2037 v
->value_int
= ctx
->Array
.VAO
->VertexBinding
[VERT_ATTRIB_GENERIC(index
)].Stride
;
2040 case GL_VERTEX_BINDING_BUFFER
:
2041 if (ctx
->API
== API_OPENGLES2
&& ctx
->Version
< 31)
2043 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
)
2045 v
->value_int
= ctx
->Array
.VAO
->VertexBinding
[VERT_ATTRIB_GENERIC(index
)].BufferObj
->Name
;
2048 /* ARB_shader_image_load_store */
2049 case GL_IMAGE_BINDING_NAME
: {
2050 struct gl_texture_object
*t
;
2052 if (!ctx
->Extensions
.ARB_shader_image_load_store
)
2054 if (index
>= ctx
->Const
.MaxImageUnits
)
2057 t
= ctx
->ImageUnits
[index
].TexObj
;
2058 v
->value_int
= (t
? t
->Name
: 0);
2062 case GL_IMAGE_BINDING_LEVEL
:
2063 if (!ctx
->Extensions
.ARB_shader_image_load_store
)
2065 if (index
>= ctx
->Const
.MaxImageUnits
)
2068 v
->value_int
= ctx
->ImageUnits
[index
].Level
;
2071 case GL_IMAGE_BINDING_LAYERED
:
2072 if (!ctx
->Extensions
.ARB_shader_image_load_store
)
2074 if (index
>= ctx
->Const
.MaxImageUnits
)
2077 v
->value_int
= ctx
->ImageUnits
[index
].Layered
;
2080 case GL_IMAGE_BINDING_LAYER
:
2081 if (!ctx
->Extensions
.ARB_shader_image_load_store
)
2083 if (index
>= ctx
->Const
.MaxImageUnits
)
2086 v
->value_int
= ctx
->ImageUnits
[index
].Layer
;
2089 case GL_IMAGE_BINDING_ACCESS
:
2090 if (!ctx
->Extensions
.ARB_shader_image_load_store
)
2092 if (index
>= ctx
->Const
.MaxImageUnits
)
2095 v
->value_int
= ctx
->ImageUnits
[index
].Access
;
2098 case GL_IMAGE_BINDING_FORMAT
:
2099 if (!ctx
->Extensions
.ARB_shader_image_load_store
)
2101 if (index
>= ctx
->Const
.MaxImageUnits
)
2104 v
->value_int
= ctx
->ImageUnits
[index
].Format
;
2107 /* ARB_direct_state_access */
2108 case GL_TEXTURE_BINDING_1D
:
2109 case GL_TEXTURE_BINDING_1D_ARRAY
:
2110 case GL_TEXTURE_BINDING_2D
:
2111 case GL_TEXTURE_BINDING_2D_ARRAY
:
2112 case GL_TEXTURE_BINDING_2D_MULTISAMPLE
:
2113 case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY
:
2114 case GL_TEXTURE_BINDING_3D
:
2115 case GL_TEXTURE_BINDING_BUFFER
:
2116 case GL_TEXTURE_BINDING_CUBE_MAP
:
2117 case GL_TEXTURE_BINDING_CUBE_MAP_ARRAY
:
2118 case GL_TEXTURE_BINDING_RECTANGLE
: {
2121 if (ctx
->API
!= API_OPENGL_CORE
)
2123 target
= tex_binding_to_index(ctx
, pname
);
2126 if (index
>= _mesa_max_tex_unit(ctx
))
2129 v
->value_int
= ctx
->Texture
.Unit
[index
].CurrentTex
[target
]->Name
;
2133 case GL_SAMPLER_BINDING
: {
2134 struct gl_sampler_object
*samp
;
2136 if (ctx
->API
!= API_OPENGL_CORE
)
2138 if (index
>= _mesa_max_tex_unit(ctx
))
2141 samp
= ctx
->Texture
.Unit
[index
].Sampler
;
2142 v
->value_int
= samp
? samp
->Name
: 0;
2146 case GL_MAX_COMPUTE_WORK_GROUP_COUNT
:
2147 if (!_mesa_has_compute_shaders(ctx
))
2151 v
->value_int
= ctx
->Const
.MaxComputeWorkGroupCount
[index
];
2154 case GL_MAX_COMPUTE_WORK_GROUP_SIZE
:
2155 if (!_mesa_has_compute_shaders(ctx
))
2159 v
->value_int
= ctx
->Const
.MaxComputeWorkGroupSize
[index
];
2164 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=%s)", func
,
2165 _mesa_enum_to_string(pname
));
2166 return TYPE_INVALID
;
2168 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(pname=%s)", func
,
2169 _mesa_enum_to_string(pname
));
2170 return TYPE_INVALID
;
2174 _mesa_GetBooleani_v( GLenum pname
, GLuint index
, GLboolean
*params
)
2177 enum value_type type
=
2178 find_value_indexed("glGetBooleani_v", pname
, index
, &v
);
2182 params
[0] = INT_TO_BOOLEAN(v
.value_int
);
2185 params
[0] = INT_TO_BOOLEAN(v
.value_int_4
[0]);
2186 params
[1] = INT_TO_BOOLEAN(v
.value_int_4
[1]);
2187 params
[2] = INT_TO_BOOLEAN(v
.value_int_4
[2]);
2188 params
[3] = INT_TO_BOOLEAN(v
.value_int_4
[3]);
2191 params
[0] = INT64_TO_BOOLEAN(v
.value_int64
);
2194 ; /* nothing - GL error was recorded */
2199 _mesa_GetIntegeri_v( GLenum pname
, GLuint index
, GLint
*params
)
2202 enum value_type type
=
2203 find_value_indexed("glGetIntegeri_v", pname
, index
, &v
);
2208 params
[3] = IROUND(v
.value_float_4
[3]);
2211 params
[2] = IROUND(v
.value_float_4
[2]);
2214 params
[1] = IROUND(v
.value_float_4
[1]);
2217 params
[0] = IROUND(v
.value_float_4
[0]);
2220 case TYPE_DOUBLEN_2
:
2221 params
[1] = IROUND(v
.value_double_2
[1]);
2223 params
[0] = IROUND(v
.value_double_2
[0]);
2227 params
[0] = v
.value_int
;
2230 params
[0] = v
.value_int_4
[0];
2231 params
[1] = v
.value_int_4
[1];
2232 params
[2] = v
.value_int_4
[2];
2233 params
[3] = v
.value_int_4
[3];
2236 params
[0] = INT64_TO_INT(v
.value_int64
);
2239 ; /* nothing - GL error was recorded */
2244 _mesa_GetInteger64i_v( GLenum pname
, GLuint index
, GLint64
*params
)
2247 enum value_type type
=
2248 find_value_indexed("glGetInteger64i_v", pname
, index
, &v
);
2252 params
[0] = v
.value_int
;
2255 params
[0] = v
.value_int_4
[0];
2256 params
[1] = v
.value_int_4
[1];
2257 params
[2] = v
.value_int_4
[2];
2258 params
[3] = v
.value_int_4
[3];
2261 params
[0] = v
.value_int64
;
2264 ; /* nothing - GL error was recorded */
2269 _mesa_GetFloati_v(GLenum pname
, GLuint index
, GLfloat
*params
)
2274 enum value_type type
=
2275 find_value_indexed("glGetFloati_v", pname
, index
, &v
);
2280 params
[3] = v
.value_float_4
[3];
2283 params
[2] = v
.value_float_4
[2];
2286 params
[1] = v
.value_float_4
[1];
2289 params
[0] = v
.value_float_4
[0];
2292 case TYPE_DOUBLEN_2
:
2293 params
[1] = (GLfloat
) v
.value_double_2
[1];
2295 params
[0] = (GLfloat
) v
.value_double_2
[0];
2299 params
[3] = (GLfloat
) v
.value_int_4
[3];
2301 params
[2] = (GLfloat
) v
.value_int_4
[2];
2304 params
[1] = (GLfloat
) v
.value_int_4
[1];
2307 params
[0] = (GLfloat
) v
.value_int_4
[0];
2311 for (i
= 0; i
< v
.value_int_n
.n
; i
++)
2312 params
[i
] = INT_TO_FLOAT(v
.value_int_n
.ints
[i
]);
2316 params
[0] = (GLfloat
) v
.value_int64
;
2320 params
[0] = BOOLEAN_TO_FLOAT(v
.value_bool
);
2324 m
= *(GLmatrix
**) &v
;
2325 for (i
= 0; i
< 16; i
++)
2326 params
[i
] = m
->m
[i
];
2330 m
= *(GLmatrix
**) &v
;
2331 for (i
= 0; i
< 16; i
++)
2332 params
[i
] = m
->m
[transpose
[i
]];
2341 _mesa_GetDoublei_v(GLenum pname
, GLuint index
, GLdouble
*params
)
2346 enum value_type type
=
2347 find_value_indexed("glGetDoublei_v", pname
, index
, &v
);
2352 params
[3] = (GLdouble
) v
.value_float_4
[3];
2355 params
[2] = (GLdouble
) v
.value_float_4
[2];
2358 params
[1] = (GLdouble
) v
.value_float_4
[1];
2361 params
[0] = (GLdouble
) v
.value_float_4
[0];
2364 case TYPE_DOUBLEN_2
:
2365 params
[1] = v
.value_double_2
[1];
2367 params
[0] = v
.value_double_2
[0];
2371 params
[3] = (GLdouble
) v
.value_int_4
[3];
2373 params
[2] = (GLdouble
) v
.value_int_4
[2];
2376 params
[1] = (GLdouble
) v
.value_int_4
[1];
2379 params
[0] = (GLdouble
) v
.value_int_4
[0];
2383 for (i
= 0; i
< v
.value_int_n
.n
; i
++)
2384 params
[i
] = (GLdouble
) INT_TO_FLOAT(v
.value_int_n
.ints
[i
]);
2388 params
[0] = (GLdouble
) v
.value_int64
;
2392 params
[0] = (GLdouble
) BOOLEAN_TO_FLOAT(v
.value_bool
);
2396 m
= *(GLmatrix
**) &v
;
2397 for (i
= 0; i
< 16; i
++)
2398 params
[i
] = (GLdouble
) m
->m
[i
];
2402 m
= *(GLmatrix
**) &v
;
2403 for (i
= 0; i
< 16; i
++)
2404 params
[i
] = (GLdouble
) m
->m
[transpose
[i
]];
2413 _mesa_GetFixedv(GLenum pname
, GLfixed
*params
)
2415 const struct value_desc
*d
;
2421 d
= find_value("glGetDoublev", pname
, &p
, &v
);
2426 params
[0] = INT_TO_FIXED(d
->offset
);
2431 params
[3] = FLOAT_TO_FIXED(((GLfloat
*) p
)[3]);
2434 params
[2] = FLOAT_TO_FIXED(((GLfloat
*) p
)[2]);
2437 params
[1] = FLOAT_TO_FIXED(((GLfloat
*) p
)[1]);
2440 params
[0] = FLOAT_TO_FIXED(((GLfloat
*) p
)[0]);
2443 case TYPE_DOUBLEN_2
:
2444 params
[1] = FLOAT_TO_FIXED(((GLdouble
*) p
)[1]);
2446 params
[0] = FLOAT_TO_FIXED(((GLdouble
*) p
)[0]);
2450 params
[3] = INT_TO_FIXED(((GLint
*) p
)[3]);
2452 params
[2] = INT_TO_FIXED(((GLint
*) p
)[2]);
2455 params
[1] = INT_TO_FIXED(((GLint
*) p
)[1]);
2458 params
[0] = INT_TO_FIXED(((GLint
*) p
)[0]);
2462 for (i
= 0; i
< v
.value_int_n
.n
; i
++)
2463 params
[i
] = INT_TO_FIXED(v
.value_int_n
.ints
[i
]);
2467 params
[0] = ((GLint64
*) p
)[0];
2471 params
[0] = BOOLEAN_TO_FIXED(((GLboolean
*) p
)[0]);
2475 m
= *(GLmatrix
**) p
;
2476 for (i
= 0; i
< 16; i
++)
2477 params
[i
] = FLOAT_TO_FIXED(m
->m
[i
]);
2481 m
= *(GLmatrix
**) p
;
2482 for (i
= 0; i
< 16; i
++)
2483 params
[i
] = FLOAT_TO_FIXED(m
->m
[transpose
[i
]]);
2494 shift
= d
->type
- TYPE_BIT_0
;
2495 params
[0] = BOOLEAN_TO_FIXED((*(GLbitfield
*) p
>> shift
) & 1);