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 EXTRA_EXT(ARB_texture_cube_map
);
373 EXTRA_EXT(EXT_texture_array
);
374 EXTRA_EXT(NV_fog_distance
);
375 EXTRA_EXT(EXT_texture_filter_anisotropic
);
376 EXTRA_EXT(NV_point_sprite
);
377 EXTRA_EXT(NV_texture_rectangle
);
378 EXTRA_EXT(EXT_stencil_two_side
);
379 EXTRA_EXT(EXT_depth_bounds_test
);
380 EXTRA_EXT(ARB_depth_clamp
);
381 EXTRA_EXT(ATI_fragment_shader
);
382 EXTRA_EXT(EXT_provoking_vertex
);
383 EXTRA_EXT(ARB_fragment_shader
);
384 EXTRA_EXT(ARB_fragment_program
);
385 EXTRA_EXT2(ARB_framebuffer_object
, EXT_framebuffer_multisample
);
386 EXTRA_EXT(ARB_seamless_cube_map
);
388 EXTRA_EXT(ARB_vertex_shader
);
389 EXTRA_EXT(EXT_transform_feedback
);
390 EXTRA_EXT(ARB_transform_feedback3
);
391 EXTRA_EXT(EXT_pixel_buffer_object
);
392 EXTRA_EXT(ARB_vertex_program
);
393 EXTRA_EXT2(NV_point_sprite
, ARB_point_sprite
);
394 EXTRA_EXT2(ARB_vertex_program
, ARB_fragment_program
);
395 EXTRA_EXT(ARB_geometry_shader4
);
396 EXTRA_EXT(ARB_color_buffer_float
);
397 EXTRA_EXT(EXT_framebuffer_sRGB
);
398 EXTRA_EXT(OES_EGL_image_external
);
399 EXTRA_EXT(ARB_blend_func_extended
);
400 EXTRA_EXT(ARB_uniform_buffer_object
);
401 EXTRA_EXT(ARB_timer_query
);
402 EXTRA_EXT(ARB_texture_cube_map_array
);
403 EXTRA_EXT(ARB_texture_buffer_range
);
404 EXTRA_EXT(ARB_texture_multisample
);
405 EXTRA_EXT(ARB_texture_gather
);
406 EXTRA_EXT(ARB_shader_atomic_counters
);
407 EXTRA_EXT(ARB_draw_indirect
);
408 EXTRA_EXT(ARB_shader_image_load_store
);
409 EXTRA_EXT(ARB_viewport_array
);
410 EXTRA_EXT(ARB_compute_shader
);
411 EXTRA_EXT(ARB_gpu_shader5
);
412 EXTRA_EXT2(ARB_transform_feedback3
, ARB_gpu_shader5
);
413 EXTRA_EXT(INTEL_performance_query
);
414 EXTRA_EXT(ARB_explicit_uniform_location
);
415 EXTRA_EXT(ARB_clip_control
);
416 EXTRA_EXT(EXT_polygon_offset_clamp
);
417 EXTRA_EXT(ARB_framebuffer_no_attachments
);
418 EXTRA_EXT(ARB_tessellation_shader
);
419 EXTRA_EXT(ARB_shader_subroutine
);
422 extra_ARB_color_buffer_float_or_glcore
[] = {
423 EXT(ARB_color_buffer_float
),
429 extra_NV_primitive_restart
[] = {
430 EXT(NV_primitive_restart
),
434 static const int extra_version_30
[] = { EXTRA_VERSION_30
, EXTRA_END
};
435 static const int extra_version_31
[] = { EXTRA_VERSION_31
, EXTRA_END
};
436 static const int extra_version_32
[] = { EXTRA_VERSION_32
, EXTRA_END
};
437 static const int extra_version_40
[] = { EXTRA_VERSION_40
, EXTRA_END
};
439 static const int extra_gl30_es3
[] = {
445 static const int extra_gl32_es3
[] = {
451 static const int extra_gl32_ARB_geometry_shader4
[] = {
453 EXT(ARB_geometry_shader4
),
457 static const int extra_gl40_ARB_sample_shading
[] = {
459 EXT(ARB_sample_shading
),
464 extra_ARB_vertex_program_api_es2
[] = {
465 EXT(ARB_vertex_program
),
470 /* The ReadBuffer get token is valid under either full GL or under
471 * GLES2 if the NV_read_buffer extension is available. */
473 extra_NV_read_buffer_api_gl
[] = {
479 static const int extra_core_ARB_color_buffer_float_and_new_buffers
[] = {
481 EXT(ARB_color_buffer_float
),
486 /* This is the big table describing all the enums we accept in
487 * glGet*v(). The table is partitioned into six parts: enums
488 * understood by all GL APIs (OpenGL, GLES and GLES2), enums shared
489 * between OpenGL and GLES, enums exclusive to GLES, etc for the
490 * remaining combinations. To look up the enums valid in a given API
491 * we will use a hash table specific to that API. These tables are in
492 * turn generated at build time and included through get_hash.h.
495 #include "get_hash.h"
497 /* All we need now is a way to look up the value struct from the enum.
498 * The code generated by gcc for the old generated big switch
499 * statement is a big, balanced, open coded if/else tree, essentially
500 * an unrolled binary search. It would be natural to sort the new
501 * enum table and use bsearch(), but we will use a read-only hash
502 * table instead. bsearch() has a nice guaranteed worst case
503 * performance, but we're also guaranteed to hit that worst case
504 * (log2(n) iterations) for about half the enums. Instead, using an
505 * open addressing hash table, we can find the enum on the first try
506 * for 80% of the enums, 1 collision for 10% and never more than 5
507 * collisions for any enum (typical numbers). And the code is very
508 * simple, even though it feels a little magic. */
512 print_table_stats(int api
)
514 int i
, j
, collisions
[11], count
, hash
, mask
;
515 const struct value_desc
*d
;
516 const char *api_names
[] = {
517 [API_OPENGL_COMPAT
] = "GL",
518 [API_OPENGL_CORE
] = "GL_CORE",
519 [API_OPENGLES
] = "GLES",
520 [API_OPENGLES2
] = "GLES2",
522 const char *api_name
;
524 api_name
= api
< ARRAY_SIZE(api_names
) ? api_names
[api
] : "N/A";
526 mask
= ARRAY_SIZE(table(api
)) - 1;
527 memset(collisions
, 0, sizeof collisions
);
529 for (i
= 0; i
< ARRAY_SIZE(table(api
)); i
++) {
533 d
= &values
[table(api
)[i
]];
534 hash
= (d
->pname
* prime_factor
);
537 if (values
[table(api
)[hash
& mask
]].pname
== d
->pname
)
549 printf("number of enums for %s: %d (total %ld)\n",
550 api_name
, count
, ARRAY_SIZE(values
));
551 for (i
= 0; i
< ARRAY_SIZE(collisions
) - 1; i
++)
552 if (collisions
[i
] > 0)
553 printf(" %d enums with %d %scollisions\n",
554 collisions
[i
], i
, i
== 10 ? "or more " : "");
559 * Initialize the enum hash for a given API
561 * This is called from one_time_init() to insert the enum values that
562 * are valid for the API in question into the enum hash table.
564 * \param the current context, for determining the API in question
566 void _mesa_init_get_hash(struct gl_context
*ctx
)
569 print_table_stats(ctx
->API
);
576 * Handle irregular enums
578 * Some values don't conform to the "well-known type at context
579 * pointer + offset" pattern, so we have this function to catch all
580 * the corner cases. Typically, it's a computed value or a one-off
581 * pointer to a custom struct or something.
583 * In this case we can't return a pointer to the value, so we'll have
584 * to use the temporary variable 'v' declared back in the calling
585 * glGet*v() function to store the result.
587 * \param ctx the current context
588 * \param d the struct value_desc that describes the enum
589 * \param v pointer to the tmp declared in the calling glGet*v() function
592 find_custom_value(struct gl_context
*ctx
, const struct value_desc
*d
, union value
*v
)
594 struct gl_buffer_object
**buffer_obj
;
595 struct gl_vertex_attrib_array
*array
;
599 case GL_MAJOR_VERSION
:
600 v
->value_int
= ctx
->Version
/ 10;
602 case GL_MINOR_VERSION
:
603 v
->value_int
= ctx
->Version
% 10;
609 case GL_TEXTURE_CUBE_MAP_ARB
:
610 case GL_TEXTURE_RECTANGLE_NV
:
611 case GL_TEXTURE_EXTERNAL_OES
:
612 v
->value_bool
= _mesa_IsEnabled(d
->pname
);
615 case GL_LINE_STIPPLE_PATTERN
:
616 /* This is the only GLushort, special case it here by promoting
617 * to an int rather than introducing a new type. */
618 v
->value_int
= ctx
->Line
.StipplePattern
;
621 case GL_CURRENT_RASTER_TEXTURE_COORDS
:
622 unit
= ctx
->Texture
.CurrentUnit
;
623 v
->value_float_4
[0] = ctx
->Current
.RasterTexCoords
[unit
][0];
624 v
->value_float_4
[1] = ctx
->Current
.RasterTexCoords
[unit
][1];
625 v
->value_float_4
[2] = ctx
->Current
.RasterTexCoords
[unit
][2];
626 v
->value_float_4
[3] = ctx
->Current
.RasterTexCoords
[unit
][3];
629 case GL_CURRENT_TEXTURE_COORDS
:
630 unit
= ctx
->Texture
.CurrentUnit
;
631 v
->value_float_4
[0] = ctx
->Current
.Attrib
[VERT_ATTRIB_TEX0
+ unit
][0];
632 v
->value_float_4
[1] = ctx
->Current
.Attrib
[VERT_ATTRIB_TEX0
+ unit
][1];
633 v
->value_float_4
[2] = ctx
->Current
.Attrib
[VERT_ATTRIB_TEX0
+ unit
][2];
634 v
->value_float_4
[3] = ctx
->Current
.Attrib
[VERT_ATTRIB_TEX0
+ unit
][3];
637 case GL_COLOR_WRITEMASK
:
638 v
->value_int_4
[0] = ctx
->Color
.ColorMask
[0][RCOMP
] ? 1 : 0;
639 v
->value_int_4
[1] = ctx
->Color
.ColorMask
[0][GCOMP
] ? 1 : 0;
640 v
->value_int_4
[2] = ctx
->Color
.ColorMask
[0][BCOMP
] ? 1 : 0;
641 v
->value_int_4
[3] = ctx
->Color
.ColorMask
[0][ACOMP
] ? 1 : 0;
645 v
->value_bool
= ctx
->Current
.Attrib
[VERT_ATTRIB_EDGEFLAG
][0] == 1.0F
;
649 v
->value_enum
= ctx
->ReadBuffer
->ColorReadBuffer
;
652 case GL_MAP2_GRID_DOMAIN
:
653 v
->value_float_4
[0] = ctx
->Eval
.MapGrid2u1
;
654 v
->value_float_4
[1] = ctx
->Eval
.MapGrid2u2
;
655 v
->value_float_4
[2] = ctx
->Eval
.MapGrid2v1
;
656 v
->value_float_4
[3] = ctx
->Eval
.MapGrid2v2
;
659 case GL_TEXTURE_STACK_DEPTH
:
660 unit
= ctx
->Texture
.CurrentUnit
;
661 v
->value_int
= ctx
->TextureMatrixStack
[unit
].Depth
+ 1;
663 case GL_TEXTURE_MATRIX
:
664 unit
= ctx
->Texture
.CurrentUnit
;
665 v
->value_matrix
= ctx
->TextureMatrixStack
[unit
].Top
;
668 case GL_TEXTURE_COORD_ARRAY
:
669 case GL_TEXTURE_COORD_ARRAY_SIZE
:
670 case GL_TEXTURE_COORD_ARRAY_TYPE
:
671 case GL_TEXTURE_COORD_ARRAY_STRIDE
:
672 array
= &ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_TEX(ctx
->Array
.ActiveTexture
)];
673 v
->value_int
= *(GLuint
*) ((char *) array
+ d
->offset
);
676 case GL_ACTIVE_TEXTURE_ARB
:
677 v
->value_int
= GL_TEXTURE0_ARB
+ ctx
->Texture
.CurrentUnit
;
679 case GL_CLIENT_ACTIVE_TEXTURE_ARB
:
680 v
->value_int
= GL_TEXTURE0_ARB
+ ctx
->Array
.ActiveTexture
;
683 case GL_MODELVIEW_STACK_DEPTH
:
684 case GL_PROJECTION_STACK_DEPTH
:
685 v
->value_int
= *(GLint
*) ((char *) ctx
+ d
->offset
) + 1;
688 case GL_MAX_TEXTURE_SIZE
:
689 case GL_MAX_3D_TEXTURE_SIZE
:
690 case GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB
:
691 p
= (GLuint
*) ((char *) ctx
+ d
->offset
);
692 v
->value_int
= 1 << (*p
- 1);
696 v
->value_int_4
[0] = ctx
->Scissor
.ScissorArray
[0].X
;
697 v
->value_int_4
[1] = ctx
->Scissor
.ScissorArray
[0].Y
;
698 v
->value_int_4
[2] = ctx
->Scissor
.ScissorArray
[0].Width
;
699 v
->value_int_4
[3] = ctx
->Scissor
.ScissorArray
[0].Height
;
702 case GL_SCISSOR_TEST
:
703 v
->value_bool
= ctx
->Scissor
.EnableFlags
& 1;
708 ctx
->ListState
.CurrentList
? ctx
->ListState
.CurrentList
->Name
: 0;
711 if (!ctx
->CompileFlag
)
713 else if (ctx
->ExecuteFlag
)
714 v
->value_enum
= GL_COMPILE_AND_EXECUTE
;
716 v
->value_enum
= GL_COMPILE
;
720 v
->value_float_4
[0] = ctx
->ViewportArray
[0].X
;
721 v
->value_float_4
[1] = ctx
->ViewportArray
[0].Y
;
722 v
->value_float_4
[2] = ctx
->ViewportArray
[0].Width
;
723 v
->value_float_4
[3] = ctx
->ViewportArray
[0].Height
;
727 v
->value_double_2
[0] = ctx
->ViewportArray
[0].Near
;
728 v
->value_double_2
[1] = ctx
->ViewportArray
[0].Far
;
731 case GL_ACTIVE_STENCIL_FACE_EXT
:
732 v
->value_enum
= ctx
->Stencil
.ActiveFace
? GL_BACK
: GL_FRONT
;
735 case GL_STENCIL_FAIL
:
736 v
->value_enum
= ctx
->Stencil
.FailFunc
[ctx
->Stencil
.ActiveFace
];
738 case GL_STENCIL_FUNC
:
739 v
->value_enum
= ctx
->Stencil
.Function
[ctx
->Stencil
.ActiveFace
];
741 case GL_STENCIL_PASS_DEPTH_FAIL
:
742 v
->value_enum
= ctx
->Stencil
.ZFailFunc
[ctx
->Stencil
.ActiveFace
];
744 case GL_STENCIL_PASS_DEPTH_PASS
:
745 v
->value_enum
= ctx
->Stencil
.ZPassFunc
[ctx
->Stencil
.ActiveFace
];
748 v
->value_int
= _mesa_get_stencil_ref(ctx
, ctx
->Stencil
.ActiveFace
);
750 case GL_STENCIL_BACK_REF
:
751 v
->value_int
= _mesa_get_stencil_ref(ctx
, 1);
753 case GL_STENCIL_VALUE_MASK
:
754 v
->value_int
= ctx
->Stencil
.ValueMask
[ctx
->Stencil
.ActiveFace
];
756 case GL_STENCIL_WRITEMASK
:
757 v
->value_int
= ctx
->Stencil
.WriteMask
[ctx
->Stencil
.ActiveFace
];
760 case GL_NUM_EXTENSIONS
:
761 v
->value_int
= _mesa_get_extension_count(ctx
);
764 case GL_IMPLEMENTATION_COLOR_READ_TYPE_OES
:
765 v
->value_int
= _mesa_get_color_read_type(ctx
);
767 case GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES
:
768 v
->value_int
= _mesa_get_color_read_format(ctx
);
771 case GL_CURRENT_MATRIX_STACK_DEPTH_ARB
:
772 v
->value_int
= ctx
->CurrentStack
->Depth
+ 1;
774 case GL_CURRENT_MATRIX_ARB
:
775 case GL_TRANSPOSE_CURRENT_MATRIX_ARB
:
776 v
->value_matrix
= ctx
->CurrentStack
->Top
;
779 case GL_NUM_COMPRESSED_TEXTURE_FORMATS_ARB
:
780 v
->value_int
= _mesa_get_compressed_formats(ctx
, NULL
);
782 case GL_COMPRESSED_TEXTURE_FORMATS_ARB
:
784 _mesa_get_compressed_formats(ctx
, v
->value_int_n
.ints
);
785 assert(v
->value_int_n
.n
<= (int) ARRAY_SIZE(v
->value_int_n
.ints
));
788 case GL_MAX_VARYING_FLOATS_ARB
:
789 v
->value_int
= ctx
->Const
.MaxVarying
* 4;
792 /* Various object names */
794 case GL_TEXTURE_BINDING_1D
:
795 case GL_TEXTURE_BINDING_2D
:
796 case GL_TEXTURE_BINDING_3D
:
797 case GL_TEXTURE_BINDING_1D_ARRAY_EXT
:
798 case GL_TEXTURE_BINDING_2D_ARRAY_EXT
:
799 case GL_TEXTURE_BINDING_CUBE_MAP_ARB
:
800 case GL_TEXTURE_BINDING_RECTANGLE_NV
:
801 case GL_TEXTURE_BINDING_EXTERNAL_OES
:
802 case GL_TEXTURE_BINDING_CUBE_MAP_ARRAY
:
803 case GL_TEXTURE_BINDING_2D_MULTISAMPLE
:
804 case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY
:
805 unit
= ctx
->Texture
.CurrentUnit
;
807 ctx
->Texture
.Unit
[unit
].CurrentTex
[d
->offset
]->Name
;
810 /* GL_EXT_packed_float */
811 case GL_RGBA_SIGNED_COMPONENTS_EXT
:
813 /* Note: we only check the 0th color attachment. */
814 const struct gl_renderbuffer
*rb
=
815 ctx
->DrawBuffer
->_ColorDrawBuffers
[0];
816 if (rb
&& _mesa_is_format_signed(rb
->Format
)) {
817 /* Issue 17 of GL_EXT_packed_float: If a component (such as
818 * alpha) has zero bits, the component should not be considered
819 * signed and so the bit for the respective component should be
823 _mesa_get_format_bits(rb
->Format
, GL_RED_BITS
);
825 _mesa_get_format_bits(rb
->Format
, GL_GREEN_BITS
);
827 _mesa_get_format_bits(rb
->Format
, GL_BLUE_BITS
);
829 _mesa_get_format_bits(rb
->Format
, GL_ALPHA_BITS
);
831 _mesa_get_format_bits(rb
->Format
, GL_TEXTURE_LUMINANCE_SIZE
);
833 _mesa_get_format_bits(rb
->Format
, GL_TEXTURE_INTENSITY_SIZE
);
835 v
->value_int_4
[0] = r_bits
+ l_bits
+ i_bits
> 0;
836 v
->value_int_4
[1] = g_bits
+ l_bits
+ i_bits
> 0;
837 v
->value_int_4
[2] = b_bits
+ l_bits
+ i_bits
> 0;
838 v
->value_int_4
[3] = a_bits
+ i_bits
> 0;
844 v
->value_int_4
[3] = 0;
849 /* GL_ARB_vertex_buffer_object */
850 case GL_VERTEX_ARRAY_BUFFER_BINDING_ARB
:
851 case GL_NORMAL_ARRAY_BUFFER_BINDING_ARB
:
852 case GL_COLOR_ARRAY_BUFFER_BINDING_ARB
:
853 case GL_INDEX_ARRAY_BUFFER_BINDING_ARB
:
854 case GL_EDGE_FLAG_ARRAY_BUFFER_BINDING_ARB
:
855 case GL_SECONDARY_COLOR_ARRAY_BUFFER_BINDING_ARB
:
856 case GL_FOG_COORDINATE_ARRAY_BUFFER_BINDING_ARB
:
857 buffer_obj
= (struct gl_buffer_object
**)
858 ((char *) ctx
->Array
.VAO
+ d
->offset
);
859 v
->value_int
= (*buffer_obj
)->Name
;
861 case GL_ARRAY_BUFFER_BINDING_ARB
:
862 v
->value_int
= ctx
->Array
.ArrayBufferObj
->Name
;
864 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING_ARB
:
866 ctx
->Array
.VAO
->VertexBinding
[VERT_ATTRIB_TEX(ctx
->Array
.ActiveTexture
)].BufferObj
->Name
;
868 case GL_ELEMENT_ARRAY_BUFFER_BINDING_ARB
:
869 v
->value_int
= ctx
->Array
.VAO
->IndexBufferObj
->Name
;
872 /* ARB_vertex_array_bgra */
873 case GL_COLOR_ARRAY_SIZE
:
874 array
= &ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_COLOR0
];
875 v
->value_int
= array
->Format
== GL_BGRA
? GL_BGRA
: array
->Size
;
877 case GL_SECONDARY_COLOR_ARRAY_SIZE
:
878 array
= &ctx
->Array
.VAO
->VertexAttrib
[VERT_ATTRIB_COLOR1
];
879 v
->value_int
= array
->Format
== GL_BGRA
? GL_BGRA
: array
->Size
;
882 /* ARB_copy_buffer */
883 case GL_COPY_READ_BUFFER
:
884 v
->value_int
= ctx
->CopyReadBuffer
->Name
;
886 case GL_COPY_WRITE_BUFFER
:
887 v
->value_int
= ctx
->CopyWriteBuffer
->Name
;
890 case GL_PIXEL_PACK_BUFFER_BINDING_EXT
:
891 v
->value_int
= ctx
->Pack
.BufferObj
->Name
;
893 case GL_PIXEL_UNPACK_BUFFER_BINDING_EXT
:
894 v
->value_int
= ctx
->Unpack
.BufferObj
->Name
;
896 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING
:
897 v
->value_int
= ctx
->TransformFeedback
.CurrentBuffer
->Name
;
899 case GL_TRANSFORM_FEEDBACK_BUFFER_PAUSED
:
900 v
->value_int
= ctx
->TransformFeedback
.CurrentObject
->Paused
;
902 case GL_TRANSFORM_FEEDBACK_BUFFER_ACTIVE
:
903 v
->value_int
= ctx
->TransformFeedback
.CurrentObject
->Active
;
905 case GL_TRANSFORM_FEEDBACK_BINDING
:
906 v
->value_int
= ctx
->TransformFeedback
.CurrentObject
->Name
;
908 case GL_CURRENT_PROGRAM
:
909 /* The Changelog of the ARB_separate_shader_objects spec says:
911 * 24 25 Jul 2011 pbrown Remove the language erroneously deleting
912 * CURRENT_PROGRAM. In the EXT extension, this
913 * token was aliased to ACTIVE_PROGRAM_EXT, and
914 * was used to indicate the last program set by
915 * either ActiveProgramEXT or UseProgram. In
916 * the ARB extension, the SSO active programs
917 * are now program pipeline object state and
918 * CURRENT_PROGRAM should still be used to query
919 * the last program set by UseProgram (bug 7822).
922 ctx
->Shader
.ActiveProgram
? ctx
->Shader
.ActiveProgram
->Name
: 0;
924 case GL_READ_FRAMEBUFFER_BINDING_EXT
:
925 v
->value_int
= ctx
->ReadBuffer
->Name
;
927 case GL_RENDERBUFFER_BINDING_EXT
:
929 ctx
->CurrentRenderbuffer
? ctx
->CurrentRenderbuffer
->Name
: 0;
931 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES
:
932 v
->value_int
= ctx
->Array
.VAO
->VertexBinding
[VERT_ATTRIB_POINT_SIZE
].BufferObj
->Name
;
936 if (_mesa_get_clamp_fragment_color(ctx
, ctx
->DrawBuffer
))
937 COPY_4FV(v
->value_float_4
, ctx
->Fog
.Color
);
939 COPY_4FV(v
->value_float_4
, ctx
->Fog
.ColorUnclamped
);
941 case GL_COLOR_CLEAR_VALUE
:
942 if (_mesa_get_clamp_fragment_color(ctx
, ctx
->DrawBuffer
)) {
943 v
->value_float_4
[0] = CLAMP(ctx
->Color
.ClearColor
.f
[0], 0.0F
, 1.0F
);
944 v
->value_float_4
[1] = CLAMP(ctx
->Color
.ClearColor
.f
[1], 0.0F
, 1.0F
);
945 v
->value_float_4
[2] = CLAMP(ctx
->Color
.ClearColor
.f
[2], 0.0F
, 1.0F
);
946 v
->value_float_4
[3] = CLAMP(ctx
->Color
.ClearColor
.f
[3], 0.0F
, 1.0F
);
948 COPY_4FV(v
->value_float_4
, ctx
->Color
.ClearColor
.f
);
950 case GL_BLEND_COLOR_EXT
:
951 if (_mesa_get_clamp_fragment_color(ctx
, ctx
->DrawBuffer
))
952 COPY_4FV(v
->value_float_4
, ctx
->Color
.BlendColor
);
954 COPY_4FV(v
->value_float_4
, ctx
->Color
.BlendColorUnclamped
);
956 case GL_ALPHA_TEST_REF
:
957 if (_mesa_get_clamp_fragment_color(ctx
, ctx
->DrawBuffer
))
958 v
->value_float
= ctx
->Color
.AlphaRef
;
960 v
->value_float
= ctx
->Color
.AlphaRefUnclamped
;
962 case GL_MAX_VERTEX_UNIFORM_VECTORS
:
963 v
->value_int
= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxUniformComponents
/ 4;
966 case GL_MAX_FRAGMENT_UNIFORM_VECTORS
:
967 v
->value_int
= ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxUniformComponents
/ 4;
970 /* GL_ARB_texture_buffer_object */
971 case GL_TEXTURE_BUFFER_ARB
:
972 v
->value_int
= ctx
->Texture
.BufferObject
->Name
;
974 case GL_TEXTURE_BINDING_BUFFER_ARB
:
975 unit
= ctx
->Texture
.CurrentUnit
;
977 ctx
->Texture
.Unit
[unit
].CurrentTex
[TEXTURE_BUFFER_INDEX
]->Name
;
979 case GL_TEXTURE_BUFFER_DATA_STORE_BINDING_ARB
:
981 struct gl_buffer_object
*buf
=
982 ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
]
983 .CurrentTex
[TEXTURE_BUFFER_INDEX
]->BufferObject
;
984 v
->value_int
= buf
? buf
->Name
: 0;
987 case GL_TEXTURE_BUFFER_FORMAT_ARB
:
988 v
->value_int
= ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
]
989 .CurrentTex
[TEXTURE_BUFFER_INDEX
]->BufferObjectFormat
;
992 /* GL_ARB_sampler_objects */
993 case GL_SAMPLER_BINDING
:
995 struct gl_sampler_object
*samp
=
996 ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
].Sampler
;
997 v
->value_int
= samp
? samp
->Name
: 0;
1000 /* GL_ARB_uniform_buffer_object */
1001 case GL_UNIFORM_BUFFER_BINDING
:
1002 v
->value_int
= ctx
->UniformBuffer
->Name
;
1004 /* GL_ARB_timer_query */
1006 if (ctx
->Driver
.GetTimestamp
) {
1007 v
->value_int64
= ctx
->Driver
.GetTimestamp(ctx
);
1010 _mesa_problem(ctx
, "driver doesn't implement GetTimestamp");
1014 case GL_DEBUG_LOGGED_MESSAGES
:
1015 case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH
:
1016 case GL_DEBUG_GROUP_STACK_DEPTH
:
1017 v
->value_int
= _mesa_get_debug_state_int(ctx
, d
->pname
);
1019 /* GL_ARB_shader_atomic_counters */
1020 case GL_ATOMIC_COUNTER_BUFFER_BINDING
:
1021 if (ctx
->AtomicBuffer
) {
1022 v
->value_int
= ctx
->AtomicBuffer
->Name
;
1027 /* GL_ARB_draw_indirect */
1028 case GL_DRAW_INDIRECT_BUFFER_BINDING
:
1029 v
->value_int
= ctx
->DrawIndirectBuffer
->Name
;
1031 /* GL_ARB_separate_shader_objects */
1032 case GL_PROGRAM_PIPELINE_BINDING
:
1033 if (ctx
->Pipeline
.Current
) {
1034 v
->value_int
= ctx
->Pipeline
.Current
->Name
;
1039 /* GL_ARB_compute_shader */
1040 case GL_DISPATCH_INDIRECT_BUFFER_BINDING
:
1041 v
->value_int
= ctx
->DispatchIndirectBuffer
->Name
;
1047 * Check extra constraints on a struct value_desc descriptor
1049 * If a struct value_desc has a non-NULL extra pointer, it means that
1050 * there are a number of extra constraints to check or actions to
1051 * perform. The extras is just an integer array where each integer
1052 * encode different constraints or actions.
1054 * \param ctx current context
1055 * \param func name of calling glGet*v() function for error reporting
1056 * \param d the struct value_desc that has the extra constraints
1058 * \return GL_FALSE if all of the constraints were not satisfied,
1059 * otherwise GL_TRUE.
1062 check_extra(struct gl_context
*ctx
, const char *func
, const struct value_desc
*d
)
1064 const GLuint version
= ctx
->Version
;
1065 GLboolean api_check
= GL_FALSE
;
1066 GLboolean api_found
= GL_FALSE
;
1069 for (e
= d
->extra
; *e
!= EXTRA_END
; e
++) {
1071 case EXTRA_VERSION_30
:
1072 api_check
= GL_TRUE
;
1074 api_found
= GL_TRUE
;
1076 case EXTRA_VERSION_31
:
1077 api_check
= GL_TRUE
;
1079 api_found
= GL_TRUE
;
1081 case EXTRA_VERSION_32
:
1082 api_check
= GL_TRUE
;
1084 api_found
= GL_TRUE
;
1086 case EXTRA_NEW_FRAG_CLAMP
:
1087 if (ctx
->NewState
& (_NEW_BUFFERS
| _NEW_FRAG_CLAMP
))
1088 _mesa_update_state(ctx
);
1091 api_check
= GL_TRUE
;
1092 if (ctx
->API
== API_OPENGLES2
)
1093 api_found
= GL_TRUE
;
1096 api_check
= GL_TRUE
;
1097 if (_mesa_is_gles3(ctx
))
1098 api_found
= GL_TRUE
;
1100 case EXTRA_API_ES31
:
1101 api_check
= GL_TRUE
;
1102 if (_mesa_is_gles31(ctx
))
1103 api_found
= GL_TRUE
;
1106 api_check
= GL_TRUE
;
1107 if (_mesa_is_desktop_gl(ctx
))
1108 api_found
= GL_TRUE
;
1110 case EXTRA_API_GL_CORE
:
1111 api_check
= GL_TRUE
;
1112 if (ctx
->API
== API_OPENGL_CORE
)
1113 api_found
= GL_TRUE
;
1115 case EXTRA_NEW_BUFFERS
:
1116 if (ctx
->NewState
& _NEW_BUFFERS
)
1117 _mesa_update_state(ctx
);
1119 case EXTRA_FLUSH_CURRENT
:
1120 FLUSH_CURRENT(ctx
, 0);
1122 case EXTRA_VALID_DRAW_BUFFER
:
1123 if (d
->pname
- GL_DRAW_BUFFER0_ARB
>= ctx
->Const
.MaxDrawBuffers
) {
1124 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(draw buffer %u)",
1125 func
, d
->pname
- GL_DRAW_BUFFER0_ARB
);
1129 case EXTRA_VALID_TEXTURE_UNIT
:
1130 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureCoordUnits
) {
1131 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(texture %u)",
1132 func
, ctx
->Texture
.CurrentUnit
);
1136 case EXTRA_VALID_CLIP_DISTANCE
:
1137 if (d
->pname
- GL_CLIP_DISTANCE0
>= ctx
->Const
.MaxClipPlanes
) {
1138 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(clip distance %u)",
1139 func
, d
->pname
- GL_CLIP_DISTANCE0
);
1143 case EXTRA_GLSL_130
:
1144 api_check
= GL_TRUE
;
1145 if (ctx
->Const
.GLSLVersion
>= 130)
1146 api_found
= GL_TRUE
;
1148 case EXTRA_EXT_UBO_GS4
:
1149 api_check
= GL_TRUE
;
1150 api_found
= (ctx
->Extensions
.ARB_uniform_buffer_object
&&
1151 _mesa_has_geometry_shaders(ctx
));
1153 case EXTRA_EXT_ATOMICS_GS4
:
1154 api_check
= GL_TRUE
;
1155 api_found
= (ctx
->Extensions
.ARB_shader_atomic_counters
&&
1156 _mesa_has_geometry_shaders(ctx
));
1158 case EXTRA_EXT_SHADER_IMAGE_GS4
:
1159 api_check
= GL_TRUE
;
1160 api_found
= (ctx
->Extensions
.ARB_shader_image_load_store
&&
1161 _mesa_has_geometry_shaders(ctx
));
1163 case EXTRA_EXT_ATOMICS_TESS
:
1164 api_check
= GL_TRUE
;
1165 api_found
= ctx
->Extensions
.ARB_shader_atomic_counters
&&
1166 _mesa_has_tessellation(ctx
);
1168 case EXTRA_EXT_SHADER_IMAGE_TESS
:
1169 api_check
= GL_TRUE
;
1170 api_found
= ctx
->Extensions
.ARB_shader_image_load_store
&&
1171 _mesa_has_tessellation(ctx
);
1175 default: /* *e is a offset into the extension struct */
1176 api_check
= GL_TRUE
;
1177 if (*(GLboolean
*) ((char *) &ctx
->Extensions
+ *e
))
1178 api_found
= GL_TRUE
;
1183 if (api_check
&& !api_found
) {
1184 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=%s)", func
,
1185 _mesa_enum_to_string(d
->pname
));
1192 static const struct value_desc error_value
=
1193 { 0, 0, TYPE_INVALID
, NO_OFFSET
, NO_EXTRA
};
1196 * Find the struct value_desc corresponding to the enum 'pname'.
1198 * We hash the enum value to get an index into the 'table' array,
1199 * which holds the index in the 'values' array of struct value_desc.
1200 * Once we've found the entry, we do the extra checks, if any, then
1201 * look up the value and return a pointer to it.
1203 * If the value has to be computed (for example, it's the result of a
1204 * function call or we need to add 1 to it), we use the tmp 'v' to
1207 * \param func name of glGet*v() func for error reporting
1208 * \param pname the enum value we're looking up
1209 * \param p is were we return the pointer to the value
1210 * \param v a tmp union value variable in the calling glGet*v() function
1212 * \return the struct value_desc corresponding to the enum or a struct
1213 * value_desc of TYPE_INVALID if not found. This lets the calling
1214 * glGet*v() function jump right into a switch statement and
1215 * handle errors there instead of having to check for NULL.
1217 static const struct value_desc
*
1218 find_value(const char *func
, GLenum pname
, void **p
, union value
*v
)
1220 GET_CURRENT_CONTEXT(ctx
);
1221 struct gl_texture_unit
*unit
;
1223 const struct value_desc
*d
;
1227 /* We index into the table_set[] list of per-API hash tables using the API's
1228 * value in the gl_api enum. Since GLES 3 doesn't have an API_OPENGL* enum
1229 * value since it's compatible with GLES2 its entry in table_set[] is at the
1232 STATIC_ASSERT(ARRAY_SIZE(table_set
) == API_OPENGL_LAST
+ 3);
1233 if (_mesa_is_gles3(ctx
)) {
1234 api
= API_OPENGL_LAST
+ 1;
1236 if (_mesa_is_gles31(ctx
)) {
1237 api
= API_OPENGL_LAST
+ 2;
1239 mask
= ARRAY_SIZE(table(api
)) - 1;
1240 hash
= (pname
* prime_factor
);
1242 int idx
= table(api
)[hash
& mask
];
1244 /* If the enum isn't valid, the hash walk ends with index 0,
1245 * pointing to the first entry of values[] which doesn't hold
1246 * any valid enum. */
1247 if (unlikely(idx
== 0)) {
1248 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=%s)", func
,
1249 _mesa_enum_to_string(pname
));
1250 return &error_value
;
1254 if (likely(d
->pname
== pname
))
1260 if (unlikely(d
->extra
&& !check_extra(ctx
, func
, d
)))
1261 return &error_value
;
1263 switch (d
->location
) {
1265 *p
= ((char *) ctx
->DrawBuffer
+ d
->offset
);
1268 *p
= ((char *) ctx
+ d
->offset
);
1271 *p
= ((char *) ctx
->Array
.VAO
+ d
->offset
);
1274 unit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1275 *p
= ((char *) unit
+ d
->offset
);
1278 find_custom_value(ctx
, d
, v
);
1286 /* silence warning */
1287 return &error_value
;
1290 static const int transpose
[] = {
1298 _mesa_GetBooleanv(GLenum pname
, GLboolean
*params
)
1300 const struct value_desc
*d
;
1306 d
= find_value("glGetBooleanv", pname
, &p
, &v
);
1311 params
[0] = INT_TO_BOOLEAN(d
->offset
);
1316 params
[3] = FLOAT_TO_BOOLEAN(((GLfloat
*) p
)[3]);
1319 params
[2] = FLOAT_TO_BOOLEAN(((GLfloat
*) p
)[2]);
1322 params
[1] = FLOAT_TO_BOOLEAN(((GLfloat
*) p
)[1]);
1325 params
[0] = FLOAT_TO_BOOLEAN(((GLfloat
*) p
)[0]);
1328 case TYPE_DOUBLEN_2
:
1329 params
[1] = FLOAT_TO_BOOLEAN(((GLdouble
*) p
)[1]);
1331 params
[0] = FLOAT_TO_BOOLEAN(((GLdouble
*) p
)[0]);
1335 params
[3] = INT_TO_BOOLEAN(((GLint
*) p
)[3]);
1337 params
[2] = INT_TO_BOOLEAN(((GLint
*) p
)[2]);
1340 params
[1] = INT_TO_BOOLEAN(((GLint
*) p
)[1]);
1343 params
[0] = INT_TO_BOOLEAN(((GLint
*) p
)[0]);
1347 for (i
= 0; i
< v
.value_int_n
.n
; i
++)
1348 params
[i
] = INT_TO_BOOLEAN(v
.value_int_n
.ints
[i
]);
1352 params
[0] = INT64_TO_BOOLEAN(((GLint64
*) p
)[0]);
1356 params
[0] = ((GLboolean
*) p
)[0];
1360 m
= *(GLmatrix
**) p
;
1361 for (i
= 0; i
< 16; i
++)
1362 params
[i
] = FLOAT_TO_BOOLEAN(m
->m
[i
]);
1366 m
= *(GLmatrix
**) p
;
1367 for (i
= 0; i
< 16; i
++)
1368 params
[i
] = FLOAT_TO_BOOLEAN(m
->m
[transpose
[i
]]);
1379 shift
= d
->type
- TYPE_BIT_0
;
1380 params
[0] = (*(GLbitfield
*) p
>> shift
) & 1;
1386 _mesa_GetFloatv(GLenum pname
, GLfloat
*params
)
1388 const struct value_desc
*d
;
1394 d
= find_value("glGetFloatv", pname
, &p
, &v
);
1399 params
[0] = (GLfloat
) d
->offset
;
1404 params
[3] = ((GLfloat
*) p
)[3];
1407 params
[2] = ((GLfloat
*) p
)[2];
1410 params
[1] = ((GLfloat
*) p
)[1];
1413 params
[0] = ((GLfloat
*) p
)[0];
1416 case TYPE_DOUBLEN_2
:
1417 params
[1] = (GLfloat
) (((GLdouble
*) p
)[1]);
1419 params
[0] = (GLfloat
) (((GLdouble
*) p
)[0]);
1423 params
[3] = (GLfloat
) (((GLint
*) p
)[3]);
1425 params
[2] = (GLfloat
) (((GLint
*) p
)[2]);
1428 params
[1] = (GLfloat
) (((GLint
*) p
)[1]);
1431 params
[0] = (GLfloat
) (((GLint
*) p
)[0]);
1435 for (i
= 0; i
< v
.value_int_n
.n
; i
++)
1436 params
[i
] = INT_TO_FLOAT(v
.value_int_n
.ints
[i
]);
1440 params
[0] = (GLfloat
) (((GLint64
*) p
)[0]);
1444 params
[0] = BOOLEAN_TO_FLOAT(*(GLboolean
*) p
);
1448 m
= *(GLmatrix
**) p
;
1449 for (i
= 0; i
< 16; i
++)
1450 params
[i
] = m
->m
[i
];
1454 m
= *(GLmatrix
**) p
;
1455 for (i
= 0; i
< 16; i
++)
1456 params
[i
] = m
->m
[transpose
[i
]];
1467 shift
= d
->type
- TYPE_BIT_0
;
1468 params
[0] = BOOLEAN_TO_FLOAT((*(GLbitfield
*) p
>> shift
) & 1);
1474 _mesa_GetIntegerv(GLenum pname
, GLint
*params
)
1476 const struct value_desc
*d
;
1482 d
= find_value("glGetIntegerv", pname
, &p
, &v
);
1487 params
[0] = d
->offset
;
1491 params
[3] = IROUND(((GLfloat
*) p
)[3]);
1493 params
[2] = IROUND(((GLfloat
*) p
)[2]);
1495 params
[1] = IROUND(((GLfloat
*) p
)[1]);
1497 params
[0] = IROUND(((GLfloat
*) p
)[0]);
1501 params
[3] = FLOAT_TO_INT(((GLfloat
*) p
)[3]);
1503 params
[2] = FLOAT_TO_INT(((GLfloat
*) p
)[2]);
1505 params
[1] = FLOAT_TO_INT(((GLfloat
*) p
)[1]);
1507 params
[0] = FLOAT_TO_INT(((GLfloat
*) p
)[0]);
1510 case TYPE_DOUBLEN_2
:
1511 params
[1] = FLOAT_TO_INT(((GLdouble
*) p
)[1]);
1513 params
[0] = FLOAT_TO_INT(((GLdouble
*) p
)[0]);
1517 params
[3] = ((GLint
*) p
)[3];
1519 params
[2] = ((GLint
*) p
)[2];
1522 params
[1] = ((GLint
*) p
)[1];
1525 params
[0] = ((GLint
*) p
)[0];
1529 for (i
= 0; i
< v
.value_int_n
.n
; i
++)
1530 params
[i
] = v
.value_int_n
.ints
[i
];
1534 params
[0] = INT64_TO_INT(((GLint64
*) p
)[0]);
1538 params
[0] = BOOLEAN_TO_INT(*(GLboolean
*) p
);
1542 m
= *(GLmatrix
**) p
;
1543 for (i
= 0; i
< 16; i
++)
1544 params
[i
] = FLOAT_TO_INT(m
->m
[i
]);
1548 m
= *(GLmatrix
**) p
;
1549 for (i
= 0; i
< 16; i
++)
1550 params
[i
] = FLOAT_TO_INT(m
->m
[transpose
[i
]]);
1561 shift
= d
->type
- TYPE_BIT_0
;
1562 params
[0] = (*(GLbitfield
*) p
>> shift
) & 1;
1568 _mesa_GetInteger64v(GLenum pname
, GLint64
*params
)
1570 const struct value_desc
*d
;
1576 d
= find_value("glGetInteger64v", pname
, &p
, &v
);
1581 params
[0] = d
->offset
;
1585 params
[3] = IROUND64(((GLfloat
*) p
)[3]);
1587 params
[2] = IROUND64(((GLfloat
*) p
)[2]);
1589 params
[1] = IROUND64(((GLfloat
*) p
)[1]);
1591 params
[0] = IROUND64(((GLfloat
*) p
)[0]);
1595 params
[3] = FLOAT_TO_INT64(((GLfloat
*) p
)[3]);
1597 params
[2] = FLOAT_TO_INT64(((GLfloat
*) p
)[2]);
1599 params
[1] = FLOAT_TO_INT64(((GLfloat
*) p
)[1]);
1601 params
[0] = FLOAT_TO_INT64(((GLfloat
*) p
)[0]);
1604 case TYPE_DOUBLEN_2
:
1605 params
[1] = FLOAT_TO_INT64(((GLdouble
*) p
)[1]);
1607 params
[0] = FLOAT_TO_INT64(((GLdouble
*) p
)[0]);
1611 params
[3] = ((GLint
*) p
)[3];
1613 params
[2] = ((GLint
*) p
)[2];
1616 params
[1] = ((GLint
*) p
)[1];
1619 params
[0] = ((GLint
*) p
)[0];
1623 for (i
= 0; i
< v
.value_int_n
.n
; i
++)
1624 params
[i
] = INT_TO_BOOLEAN(v
.value_int_n
.ints
[i
]);
1628 params
[0] = ((GLint64
*) p
)[0];
1632 params
[0] = ((GLboolean
*) p
)[0];
1636 m
= *(GLmatrix
**) p
;
1637 for (i
= 0; i
< 16; i
++)
1638 params
[i
] = FLOAT_TO_INT64(m
->m
[i
]);
1642 m
= *(GLmatrix
**) p
;
1643 for (i
= 0; i
< 16; i
++)
1644 params
[i
] = FLOAT_TO_INT64(m
->m
[transpose
[i
]]);
1655 shift
= d
->type
- TYPE_BIT_0
;
1656 params
[0] = (*(GLbitfield
*) p
>> shift
) & 1;
1662 _mesa_GetDoublev(GLenum pname
, GLdouble
*params
)
1664 const struct value_desc
*d
;
1670 d
= find_value("glGetDoublev", pname
, &p
, &v
);
1675 params
[0] = d
->offset
;
1680 params
[3] = ((GLfloat
*) p
)[3];
1683 params
[2] = ((GLfloat
*) p
)[2];
1686 params
[1] = ((GLfloat
*) p
)[1];
1689 params
[0] = ((GLfloat
*) p
)[0];
1692 case TYPE_DOUBLEN_2
:
1693 params
[1] = ((GLdouble
*) p
)[1];
1695 params
[0] = ((GLdouble
*) p
)[0];
1699 params
[3] = ((GLint
*) p
)[3];
1701 params
[2] = ((GLint
*) p
)[2];
1704 params
[1] = ((GLint
*) p
)[1];
1707 params
[0] = ((GLint
*) p
)[0];
1711 for (i
= 0; i
< v
.value_int_n
.n
; i
++)
1712 params
[i
] = v
.value_int_n
.ints
[i
];
1716 params
[0] = (GLdouble
) (((GLint64
*) p
)[0]);
1720 params
[0] = *(GLboolean
*) p
;
1724 m
= *(GLmatrix
**) p
;
1725 for (i
= 0; i
< 16; i
++)
1726 params
[i
] = m
->m
[i
];
1730 m
= *(GLmatrix
**) p
;
1731 for (i
= 0; i
< 16; i
++)
1732 params
[i
] = m
->m
[transpose
[i
]];
1743 shift
= d
->type
- TYPE_BIT_0
;
1744 params
[0] = (*(GLbitfield
*) p
>> shift
) & 1;
1750 * Convert a GL texture binding enum such as GL_TEXTURE_BINDING_2D
1751 * into the corresponding Mesa texture target index.
1752 * \return TEXTURE_x_INDEX or -1 if binding is invalid
1755 tex_binding_to_index(const struct gl_context
*ctx
, GLenum binding
)
1758 case GL_TEXTURE_BINDING_1D
:
1759 return _mesa_is_desktop_gl(ctx
) ? TEXTURE_1D_INDEX
: -1;
1760 case GL_TEXTURE_BINDING_2D
:
1761 return TEXTURE_2D_INDEX
;
1762 case GL_TEXTURE_BINDING_3D
:
1763 return ctx
->API
!= API_OPENGLES
? TEXTURE_3D_INDEX
: -1;
1764 case GL_TEXTURE_BINDING_CUBE_MAP
:
1765 return ctx
->Extensions
.ARB_texture_cube_map
1766 ? TEXTURE_CUBE_INDEX
: -1;
1767 case GL_TEXTURE_BINDING_RECTANGLE
:
1768 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.NV_texture_rectangle
1769 ? TEXTURE_RECT_INDEX
: -1;
1770 case GL_TEXTURE_BINDING_1D_ARRAY
:
1771 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
1772 ? TEXTURE_1D_ARRAY_INDEX
: -1;
1773 case GL_TEXTURE_BINDING_2D_ARRAY
:
1774 return (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
)
1775 || _mesa_is_gles3(ctx
)
1776 ? TEXTURE_2D_ARRAY_INDEX
: -1;
1777 case GL_TEXTURE_BINDING_BUFFER
:
1778 return ctx
->API
== API_OPENGL_CORE
&&
1779 ctx
->Extensions
.ARB_texture_buffer_object
?
1780 TEXTURE_BUFFER_INDEX
: -1;
1781 case GL_TEXTURE_BINDING_CUBE_MAP_ARRAY
:
1782 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_cube_map_array
1783 ? TEXTURE_CUBE_ARRAY_INDEX
: -1;
1784 case GL_TEXTURE_BINDING_2D_MULTISAMPLE
:
1785 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_multisample
1786 ? TEXTURE_2D_MULTISAMPLE_INDEX
: -1;
1787 case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY
:
1788 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_multisample
1789 ? TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX
: -1;
1795 static enum value_type
1796 find_value_indexed(const char *func
, GLenum pname
, GLuint index
, union value
*v
)
1798 GET_CURRENT_CONTEXT(ctx
);
1803 if (index
>= ctx
->Const
.MaxDrawBuffers
)
1805 if (!ctx
->Extensions
.EXT_draw_buffers2
)
1807 v
->value_int
= (ctx
->Color
.BlendEnabled
>> index
) & 1;
1812 case GL_BLEND_SRC_RGB
:
1813 if (index
>= ctx
->Const
.MaxDrawBuffers
)
1815 if (!ctx
->Extensions
.ARB_draw_buffers_blend
)
1817 v
->value_int
= ctx
->Color
.Blend
[index
].SrcRGB
;
1819 case GL_BLEND_SRC_ALPHA
:
1820 if (index
>= ctx
->Const
.MaxDrawBuffers
)
1822 if (!ctx
->Extensions
.ARB_draw_buffers_blend
)
1824 v
->value_int
= ctx
->Color
.Blend
[index
].SrcA
;
1828 case GL_BLEND_DST_RGB
:
1829 if (index
>= ctx
->Const
.MaxDrawBuffers
)
1831 if (!ctx
->Extensions
.ARB_draw_buffers_blend
)
1833 v
->value_int
= ctx
->Color
.Blend
[index
].DstRGB
;
1835 case GL_BLEND_DST_ALPHA
:
1836 if (index
>= ctx
->Const
.MaxDrawBuffers
)
1838 if (!ctx
->Extensions
.ARB_draw_buffers_blend
)
1840 v
->value_int
= ctx
->Color
.Blend
[index
].DstA
;
1842 case GL_BLEND_EQUATION_RGB
:
1843 if (index
>= ctx
->Const
.MaxDrawBuffers
)
1845 if (!ctx
->Extensions
.ARB_draw_buffers_blend
)
1847 v
->value_int
= ctx
->Color
.Blend
[index
].EquationRGB
;
1849 case GL_BLEND_EQUATION_ALPHA
:
1850 if (index
>= ctx
->Const
.MaxDrawBuffers
)
1852 if (!ctx
->Extensions
.ARB_draw_buffers_blend
)
1854 v
->value_int
= ctx
->Color
.Blend
[index
].EquationA
;
1857 case GL_COLOR_WRITEMASK
:
1858 if (index
>= ctx
->Const
.MaxDrawBuffers
)
1860 if (!ctx
->Extensions
.EXT_draw_buffers2
)
1862 v
->value_int_4
[0] = ctx
->Color
.ColorMask
[index
][RCOMP
] ? 1 : 0;
1863 v
->value_int_4
[1] = ctx
->Color
.ColorMask
[index
][GCOMP
] ? 1 : 0;
1864 v
->value_int_4
[2] = ctx
->Color
.ColorMask
[index
][BCOMP
] ? 1 : 0;
1865 v
->value_int_4
[3] = ctx
->Color
.ColorMask
[index
][ACOMP
] ? 1 : 0;
1868 case GL_SCISSOR_BOX
:
1869 if (index
>= ctx
->Const
.MaxViewports
)
1871 v
->value_int_4
[0] = ctx
->Scissor
.ScissorArray
[index
].X
;
1872 v
->value_int_4
[1] = ctx
->Scissor
.ScissorArray
[index
].Y
;
1873 v
->value_int_4
[2] = ctx
->Scissor
.ScissorArray
[index
].Width
;
1874 v
->value_int_4
[3] = ctx
->Scissor
.ScissorArray
[index
].Height
;
1878 if (index
>= ctx
->Const
.MaxViewports
)
1880 v
->value_float_4
[0] = ctx
->ViewportArray
[index
].X
;
1881 v
->value_float_4
[1] = ctx
->ViewportArray
[index
].Y
;
1882 v
->value_float_4
[2] = ctx
->ViewportArray
[index
].Width
;
1883 v
->value_float_4
[3] = ctx
->ViewportArray
[index
].Height
;
1884 return TYPE_FLOAT_4
;
1886 case GL_DEPTH_RANGE
:
1887 if (index
>= ctx
->Const
.MaxViewports
)
1889 v
->value_double_2
[0] = ctx
->ViewportArray
[index
].Near
;
1890 v
->value_double_2
[1] = ctx
->ViewportArray
[index
].Far
;
1891 return TYPE_DOUBLEN_2
;
1893 case GL_TRANSFORM_FEEDBACK_BUFFER_START
:
1894 if (index
>= ctx
->Const
.MaxTransformFeedbackBuffers
)
1896 if (!ctx
->Extensions
.EXT_transform_feedback
)
1898 v
->value_int64
= ctx
->TransformFeedback
.CurrentObject
->Offset
[index
];
1901 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE
:
1902 if (index
>= ctx
->Const
.MaxTransformFeedbackBuffers
)
1904 if (!ctx
->Extensions
.EXT_transform_feedback
)
1907 = ctx
->TransformFeedback
.CurrentObject
->RequestedSize
[index
];
1910 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING
:
1911 if (index
>= ctx
->Const
.MaxTransformFeedbackBuffers
)
1913 if (!ctx
->Extensions
.EXT_transform_feedback
)
1915 v
->value_int
= ctx
->TransformFeedback
.CurrentObject
->BufferNames
[index
];
1918 case GL_UNIFORM_BUFFER_BINDING
:
1919 if (index
>= ctx
->Const
.MaxUniformBufferBindings
)
1921 if (!ctx
->Extensions
.ARB_uniform_buffer_object
)
1923 v
->value_int
= ctx
->UniformBufferBindings
[index
].BufferObject
->Name
;
1926 case GL_UNIFORM_BUFFER_START
:
1927 if (index
>= ctx
->Const
.MaxUniformBufferBindings
)
1929 if (!ctx
->Extensions
.ARB_uniform_buffer_object
)
1931 v
->value_int
= ctx
->UniformBufferBindings
[index
].Offset
;
1934 case GL_UNIFORM_BUFFER_SIZE
:
1935 if (index
>= ctx
->Const
.MaxUniformBufferBindings
)
1937 if (!ctx
->Extensions
.ARB_uniform_buffer_object
)
1939 v
->value_int
= ctx
->UniformBufferBindings
[index
].Size
;
1942 /* ARB_texture_multisample / GL3.2 */
1943 case GL_SAMPLE_MASK_VALUE
:
1946 if (!ctx
->Extensions
.ARB_texture_multisample
)
1948 v
->value_int
= ctx
->Multisample
.SampleMaskValue
;
1951 case GL_ATOMIC_COUNTER_BUFFER_BINDING
:
1952 if (!ctx
->Extensions
.ARB_shader_atomic_counters
)
1954 if (index
>= ctx
->Const
.MaxAtomicBufferBindings
)
1956 v
->value_int
= ctx
->AtomicBufferBindings
[index
].BufferObject
->Name
;
1959 case GL_ATOMIC_COUNTER_BUFFER_START
:
1960 if (!ctx
->Extensions
.ARB_shader_atomic_counters
)
1962 if (index
>= ctx
->Const
.MaxAtomicBufferBindings
)
1964 v
->value_int64
= ctx
->AtomicBufferBindings
[index
].Offset
;
1967 case GL_ATOMIC_COUNTER_BUFFER_SIZE
:
1968 if (!ctx
->Extensions
.ARB_shader_atomic_counters
)
1970 if (index
>= ctx
->Const
.MaxAtomicBufferBindings
)
1972 v
->value_int64
= ctx
->AtomicBufferBindings
[index
].Size
;
1975 case GL_VERTEX_BINDING_DIVISOR
:
1976 if ((!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_instanced_arrays
) &&
1977 !_mesa_is_gles31(ctx
))
1979 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
)
1981 v
->value_int
= ctx
->Array
.VAO
->VertexBinding
[VERT_ATTRIB_GENERIC(index
)].InstanceDivisor
;
1984 case GL_VERTEX_BINDING_OFFSET
:
1985 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles31(ctx
))
1987 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
)
1989 v
->value_int
= ctx
->Array
.VAO
->VertexBinding
[VERT_ATTRIB_GENERIC(index
)].Offset
;
1992 case GL_VERTEX_BINDING_STRIDE
:
1993 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles31(ctx
))
1995 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
)
1997 v
->value_int
= ctx
->Array
.VAO
->VertexBinding
[VERT_ATTRIB_GENERIC(index
)].Stride
;
2000 case GL_VERTEX_BINDING_BUFFER
:
2001 if (ctx
->API
== API_OPENGLES2
&& ctx
->Version
< 31)
2003 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
)
2005 v
->value_int
= ctx
->Array
.VAO
->VertexBinding
[VERT_ATTRIB_GENERIC(index
)].BufferObj
->Name
;
2008 /* ARB_shader_image_load_store */
2009 case GL_IMAGE_BINDING_NAME
: {
2010 struct gl_texture_object
*t
;
2012 if (!ctx
->Extensions
.ARB_shader_image_load_store
)
2014 if (index
>= ctx
->Const
.MaxImageUnits
)
2017 t
= ctx
->ImageUnits
[index
].TexObj
;
2018 v
->value_int
= (t
? t
->Name
: 0);
2022 case GL_IMAGE_BINDING_LEVEL
:
2023 if (!ctx
->Extensions
.ARB_shader_image_load_store
)
2025 if (index
>= ctx
->Const
.MaxImageUnits
)
2028 v
->value_int
= ctx
->ImageUnits
[index
].Level
;
2031 case GL_IMAGE_BINDING_LAYERED
:
2032 if (!ctx
->Extensions
.ARB_shader_image_load_store
)
2034 if (index
>= ctx
->Const
.MaxImageUnits
)
2037 v
->value_int
= ctx
->ImageUnits
[index
].Layered
;
2040 case GL_IMAGE_BINDING_LAYER
:
2041 if (!ctx
->Extensions
.ARB_shader_image_load_store
)
2043 if (index
>= ctx
->Const
.MaxImageUnits
)
2046 v
->value_int
= ctx
->ImageUnits
[index
].Layer
;
2049 case GL_IMAGE_BINDING_ACCESS
:
2050 if (!ctx
->Extensions
.ARB_shader_image_load_store
)
2052 if (index
>= ctx
->Const
.MaxImageUnits
)
2055 v
->value_int
= ctx
->ImageUnits
[index
].Access
;
2058 case GL_IMAGE_BINDING_FORMAT
:
2059 if (!ctx
->Extensions
.ARB_shader_image_load_store
)
2061 if (index
>= ctx
->Const
.MaxImageUnits
)
2064 v
->value_int
= ctx
->ImageUnits
[index
].Format
;
2067 /* ARB_direct_state_access */
2068 case GL_TEXTURE_BINDING_1D
:
2069 case GL_TEXTURE_BINDING_1D_ARRAY
:
2070 case GL_TEXTURE_BINDING_2D
:
2071 case GL_TEXTURE_BINDING_2D_ARRAY
:
2072 case GL_TEXTURE_BINDING_2D_MULTISAMPLE
:
2073 case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY
:
2074 case GL_TEXTURE_BINDING_3D
:
2075 case GL_TEXTURE_BINDING_BUFFER
:
2076 case GL_TEXTURE_BINDING_CUBE_MAP
:
2077 case GL_TEXTURE_BINDING_CUBE_MAP_ARRAY
:
2078 case GL_TEXTURE_BINDING_RECTANGLE
: {
2081 if (ctx
->API
!= API_OPENGL_CORE
)
2083 target
= tex_binding_to_index(ctx
, pname
);
2086 if (index
>= _mesa_max_tex_unit(ctx
))
2089 v
->value_int
= ctx
->Texture
.Unit
[index
].CurrentTex
[target
]->Name
;
2093 case GL_SAMPLER_BINDING
: {
2094 struct gl_sampler_object
*samp
;
2096 if (ctx
->API
!= API_OPENGL_CORE
)
2098 if (index
>= _mesa_max_tex_unit(ctx
))
2101 samp
= ctx
->Texture
.Unit
[index
].Sampler
;
2102 v
->value_int
= samp
? samp
->Name
: 0;
2106 case GL_MAX_COMPUTE_WORK_GROUP_COUNT
:
2107 if (!_mesa_has_compute_shaders(ctx
))
2111 v
->value_int
= ctx
->Const
.MaxComputeWorkGroupCount
[index
];
2114 case GL_MAX_COMPUTE_WORK_GROUP_SIZE
:
2115 if (!_mesa_has_compute_shaders(ctx
))
2119 v
->value_int
= ctx
->Const
.MaxComputeWorkGroupSize
[index
];
2124 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=%s)", func
,
2125 _mesa_enum_to_string(pname
));
2126 return TYPE_INVALID
;
2128 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(pname=%s)", func
,
2129 _mesa_enum_to_string(pname
));
2130 return TYPE_INVALID
;
2134 _mesa_GetBooleani_v( GLenum pname
, GLuint index
, GLboolean
*params
)
2137 enum value_type type
=
2138 find_value_indexed("glGetBooleani_v", pname
, index
, &v
);
2142 params
[0] = INT_TO_BOOLEAN(v
.value_int
);
2145 params
[0] = INT_TO_BOOLEAN(v
.value_int_4
[0]);
2146 params
[1] = INT_TO_BOOLEAN(v
.value_int_4
[1]);
2147 params
[2] = INT_TO_BOOLEAN(v
.value_int_4
[2]);
2148 params
[3] = INT_TO_BOOLEAN(v
.value_int_4
[3]);
2151 params
[0] = INT64_TO_BOOLEAN(v
.value_int64
);
2154 ; /* nothing - GL error was recorded */
2159 _mesa_GetIntegeri_v( GLenum pname
, GLuint index
, GLint
*params
)
2162 enum value_type type
=
2163 find_value_indexed("glGetIntegeri_v", pname
, index
, &v
);
2168 params
[3] = IROUND(v
.value_float_4
[3]);
2171 params
[2] = IROUND(v
.value_float_4
[2]);
2174 params
[1] = IROUND(v
.value_float_4
[1]);
2177 params
[0] = IROUND(v
.value_float_4
[0]);
2180 case TYPE_DOUBLEN_2
:
2181 params
[1] = IROUND(v
.value_double_2
[1]);
2183 params
[0] = IROUND(v
.value_double_2
[0]);
2187 params
[0] = v
.value_int
;
2190 params
[0] = v
.value_int_4
[0];
2191 params
[1] = v
.value_int_4
[1];
2192 params
[2] = v
.value_int_4
[2];
2193 params
[3] = v
.value_int_4
[3];
2196 params
[0] = INT64_TO_INT(v
.value_int64
);
2199 ; /* nothing - GL error was recorded */
2204 _mesa_GetInteger64i_v( GLenum pname
, GLuint index
, GLint64
*params
)
2207 enum value_type type
=
2208 find_value_indexed("glGetInteger64i_v", pname
, index
, &v
);
2212 params
[0] = v
.value_int
;
2215 params
[0] = v
.value_int_4
[0];
2216 params
[1] = v
.value_int_4
[1];
2217 params
[2] = v
.value_int_4
[2];
2218 params
[3] = v
.value_int_4
[3];
2221 params
[0] = v
.value_int64
;
2224 ; /* nothing - GL error was recorded */
2229 _mesa_GetFloati_v(GLenum pname
, GLuint index
, GLfloat
*params
)
2234 enum value_type type
=
2235 find_value_indexed("glGetFloati_v", pname
, index
, &v
);
2240 params
[3] = v
.value_float_4
[3];
2243 params
[2] = v
.value_float_4
[2];
2246 params
[1] = v
.value_float_4
[1];
2249 params
[0] = v
.value_float_4
[0];
2252 case TYPE_DOUBLEN_2
:
2253 params
[1] = (GLfloat
) v
.value_double_2
[1];
2255 params
[0] = (GLfloat
) v
.value_double_2
[0];
2259 params
[3] = (GLfloat
) v
.value_int_4
[3];
2261 params
[2] = (GLfloat
) v
.value_int_4
[2];
2264 params
[1] = (GLfloat
) v
.value_int_4
[1];
2267 params
[0] = (GLfloat
) v
.value_int_4
[0];
2271 for (i
= 0; i
< v
.value_int_n
.n
; i
++)
2272 params
[i
] = INT_TO_FLOAT(v
.value_int_n
.ints
[i
]);
2276 params
[0] = (GLfloat
) v
.value_int64
;
2280 params
[0] = BOOLEAN_TO_FLOAT(v
.value_bool
);
2284 m
= *(GLmatrix
**) &v
;
2285 for (i
= 0; i
< 16; i
++)
2286 params
[i
] = m
->m
[i
];
2290 m
= *(GLmatrix
**) &v
;
2291 for (i
= 0; i
< 16; i
++)
2292 params
[i
] = m
->m
[transpose
[i
]];
2301 _mesa_GetDoublei_v(GLenum pname
, GLuint index
, GLdouble
*params
)
2306 enum value_type type
=
2307 find_value_indexed("glGetDoublei_v", pname
, index
, &v
);
2312 params
[3] = (GLdouble
) v
.value_float_4
[3];
2315 params
[2] = (GLdouble
) v
.value_float_4
[2];
2318 params
[1] = (GLdouble
) v
.value_float_4
[1];
2321 params
[0] = (GLdouble
) v
.value_float_4
[0];
2324 case TYPE_DOUBLEN_2
:
2325 params
[1] = v
.value_double_2
[1];
2327 params
[0] = v
.value_double_2
[0];
2331 params
[3] = (GLdouble
) v
.value_int_4
[3];
2333 params
[2] = (GLdouble
) v
.value_int_4
[2];
2336 params
[1] = (GLdouble
) v
.value_int_4
[1];
2339 params
[0] = (GLdouble
) v
.value_int_4
[0];
2343 for (i
= 0; i
< v
.value_int_n
.n
; i
++)
2344 params
[i
] = (GLdouble
) INT_TO_FLOAT(v
.value_int_n
.ints
[i
]);
2348 params
[0] = (GLdouble
) v
.value_int64
;
2352 params
[0] = (GLdouble
) BOOLEAN_TO_FLOAT(v
.value_bool
);
2356 m
= *(GLmatrix
**) &v
;
2357 for (i
= 0; i
< 16; i
++)
2358 params
[i
] = (GLdouble
) m
->m
[i
];
2362 m
= *(GLmatrix
**) &v
;
2363 for (i
= 0; i
< 16; i
++)
2364 params
[i
] = (GLdouble
) m
->m
[transpose
[i
]];
2373 _mesa_GetFixedv(GLenum pname
, GLfixed
*params
)
2375 const struct value_desc
*d
;
2381 d
= find_value("glGetDoublev", pname
, &p
, &v
);
2386 params
[0] = INT_TO_FIXED(d
->offset
);
2391 params
[3] = FLOAT_TO_FIXED(((GLfloat
*) p
)[3]);
2394 params
[2] = FLOAT_TO_FIXED(((GLfloat
*) p
)[2]);
2397 params
[1] = FLOAT_TO_FIXED(((GLfloat
*) p
)[1]);
2400 params
[0] = FLOAT_TO_FIXED(((GLfloat
*) p
)[0]);
2403 case TYPE_DOUBLEN_2
:
2404 params
[1] = FLOAT_TO_FIXED(((GLdouble
*) p
)[1]);
2406 params
[0] = FLOAT_TO_FIXED(((GLdouble
*) p
)[0]);
2410 params
[3] = INT_TO_FIXED(((GLint
*) p
)[3]);
2412 params
[2] = INT_TO_FIXED(((GLint
*) p
)[2]);
2415 params
[1] = INT_TO_FIXED(((GLint
*) p
)[1]);
2418 params
[0] = INT_TO_FIXED(((GLint
*) p
)[0]);
2422 for (i
= 0; i
< v
.value_int_n
.n
; i
++)
2423 params
[i
] = INT_TO_FIXED(v
.value_int_n
.ints
[i
]);
2427 params
[0] = ((GLint64
*) p
)[0];
2431 params
[0] = BOOLEAN_TO_FIXED(((GLboolean
*) p
)[0]);
2435 m
= *(GLmatrix
**) p
;
2436 for (i
= 0; i
< 16; i
++)
2437 params
[i
] = FLOAT_TO_FIXED(m
->m
[i
]);
2441 m
= *(GLmatrix
**) p
;
2442 for (i
= 0; i
< 16; i
++)
2443 params
[i
] = FLOAT_TO_FIXED(m
->m
[transpose
[i
]]);
2454 shift
= d
->type
- TYPE_BIT_0
;
2455 params
[0] = BOOLEAN_TO_FIXED((*(GLbitfield
*) p
>> shift
) & 1);