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>
31 #include "extensions.h"
36 #include "texcompress.h"
37 #include "framebuffer.h"
38 #include "samplerobj.h"
41 /* This is a table driven implemetation of the glGet*v() functions.
42 * The basic idea is that most getters just look up an int somewhere
43 * in struct gl_context and then convert it to a bool or float according to
44 * which of glGetIntegerv() glGetBooleanv() etc is being called.
45 * Instead of generating code to do this, we can just record the enum
46 * value and the offset into struct gl_context in an array of structs. Then
47 * in glGet*(), we lookup the struct for the enum in question, and use
48 * the offset to get the int we need.
50 * Sometimes we need to look up a float, a boolean, a bit in a
51 * bitfield, a matrix or other types instead, so we need to track the
52 * type of the value in struct gl_context. And sometimes the value isn't in
53 * struct gl_context but in the drawbuffer, the array object, current texture
54 * unit, or maybe it's a computed value. So we need to also track
55 * where or how to find the value. Finally, we sometimes need to
56 * check that one of a number of extensions are enabled, the GL
57 * version or flush or call _mesa_update_state(). This is done by
58 * attaching optional extra information to the value description
59 * struct, it's sort of like an array of opcodes that describe extra
62 * Putting all this together we end up with struct value_desc below,
63 * and with a couple of macros to help, the table of struct value_desc
64 * is about as concise as the specification in the old python script.
67 #define FLOAT_TO_BOOLEAN(X) ( (X) ? GL_TRUE : GL_FALSE )
68 #define FLOAT_TO_FIXED(F) ( ((F) * 65536.0f > INT_MAX) ? INT_MAX : \
69 ((F) * 65536.0f < INT_MIN) ? INT_MIN : \
70 (GLint) ((F) * 65536.0f) )
72 #define INT_TO_BOOLEAN(I) ( (I) ? GL_TRUE : GL_FALSE )
73 #define INT_TO_FIXED(I) ( ((I) > SHRT_MAX) ? INT_MAX : \
74 ((I) < SHRT_MIN) ? INT_MIN : \
75 (GLint) ((I) * 65536) )
77 #define INT64_TO_BOOLEAN(I) ( (I) ? GL_TRUE : GL_FALSE )
78 #define INT64_TO_INT(I) ( (GLint)((I > INT_MAX) ? INT_MAX : ((I < INT_MIN) ? INT_MIN : (I))) )
80 #define BOOLEAN_TO_INT(B) ( (GLint) (B) )
81 #define BOOLEAN_TO_INT64(B) ( (GLint64) (B) )
82 #define BOOLEAN_TO_FLOAT(B) ( (B) ? 1.0F : 0.0F )
83 #define BOOLEAN_TO_FIXED(B) ( (GLint) ((B) ? 1 : 0) << 16 )
85 #define ENUM_TO_INT64(E) ( (GLint64) (E) )
86 #define ENUM_TO_FIXED(E) (E)
121 enum value_location
{
140 EXTRA_NEW_FRAG_CLAMP
,
141 EXTRA_VALID_DRAW_BUFFER
,
142 EXTRA_VALID_TEXTURE_UNIT
,
143 EXTRA_VALID_CLIP_DISTANCE
,
147 EXTRA_EXT_ATOMICS_GS4
,
150 #define NO_EXTRA NULL
155 GLubyte location
; /**< enum value_location */
156 GLubyte type
; /**< enum value_type */
163 GLfloat value_float_4
[4];
164 GLmatrix
*value_matrix
;
166 GLint value_int_4
[4];
170 /* Sigh, see GL_COMPRESSED_TEXTURE_FORMATS_ARB handling */
174 GLboolean value_bool
;
177 #define BUFFER_FIELD(field, type) \
178 LOC_BUFFER, type, offsetof(struct gl_framebuffer, field)
179 #define CONTEXT_FIELD(field, type) \
180 LOC_CONTEXT, type, offsetof(struct gl_context, field)
181 #define ARRAY_FIELD(field, type) \
182 LOC_ARRAY, type, offsetof(struct gl_array_object, field)
183 #undef CONST /* already defined through windows.h */
184 #define CONST(value) \
185 LOC_CONTEXT, TYPE_CONST, value
187 #define BUFFER_INT(field) BUFFER_FIELD(field, TYPE_INT)
188 #define BUFFER_ENUM(field) BUFFER_FIELD(field, TYPE_ENUM)
189 #define BUFFER_BOOL(field) BUFFER_FIELD(field, TYPE_BOOLEAN)
191 #define CONTEXT_INT(field) CONTEXT_FIELD(field, TYPE_INT)
192 #define CONTEXT_INT2(field) CONTEXT_FIELD(field, TYPE_INT_2)
193 #define CONTEXT_INT64(field) CONTEXT_FIELD(field, TYPE_INT64)
194 #define CONTEXT_ENUM(field) CONTEXT_FIELD(field, TYPE_ENUM)
195 #define CONTEXT_ENUM2(field) CONTEXT_FIELD(field, TYPE_ENUM_2)
196 #define CONTEXT_BOOL(field) CONTEXT_FIELD(field, TYPE_BOOLEAN)
197 #define CONTEXT_BIT0(field) CONTEXT_FIELD(field, TYPE_BIT_0)
198 #define CONTEXT_BIT1(field) CONTEXT_FIELD(field, TYPE_BIT_1)
199 #define CONTEXT_BIT2(field) CONTEXT_FIELD(field, TYPE_BIT_2)
200 #define CONTEXT_BIT3(field) CONTEXT_FIELD(field, TYPE_BIT_3)
201 #define CONTEXT_BIT4(field) CONTEXT_FIELD(field, TYPE_BIT_4)
202 #define CONTEXT_BIT5(field) CONTEXT_FIELD(field, TYPE_BIT_5)
203 #define CONTEXT_BIT6(field) CONTEXT_FIELD(field, TYPE_BIT_6)
204 #define CONTEXT_BIT7(field) CONTEXT_FIELD(field, TYPE_BIT_7)
205 #define CONTEXT_FLOAT(field) CONTEXT_FIELD(field, TYPE_FLOAT)
206 #define CONTEXT_FLOAT2(field) CONTEXT_FIELD(field, TYPE_FLOAT_2)
207 #define CONTEXT_FLOAT3(field) CONTEXT_FIELD(field, TYPE_FLOAT_3)
208 #define CONTEXT_FLOAT4(field) CONTEXT_FIELD(field, TYPE_FLOAT_4)
209 #define CONTEXT_MATRIX(field) CONTEXT_FIELD(field, TYPE_MATRIX)
210 #define CONTEXT_MATRIX_T(field) CONTEXT_FIELD(field, TYPE_MATRIX_T)
212 #define ARRAY_INT(field) ARRAY_FIELD(field, TYPE_INT)
213 #define ARRAY_ENUM(field) ARRAY_FIELD(field, TYPE_ENUM)
214 #define ARRAY_BOOL(field) ARRAY_FIELD(field, TYPE_BOOLEAN)
217 offsetof(struct gl_extensions, f)
219 #define EXTRA_EXT(e) \
220 static const int extra_##e[] = { \
224 #define EXTRA_EXT2(e1, e2) \
225 static const int extra_##e1##_##e2[] = { \
226 EXT(e1), EXT(e2), EXTRA_END \
229 /* The 'extra' mechanism is a way to specify extra checks (such as
230 * extensions or specific gl versions) or actions (flush current, new
231 * buffers) that we need to do before looking up an enum. We need to
232 * declare them all up front so we can refer to them in the value_desc
235 * Each EXTRA_ will be executed. For EXTRA_* enums of extensions and API
236 * versions, listing multiple ones in an array means an error will be thrown
237 * only if none of them are available. If you need to check for "AND"
238 * behavior, you would need to make a custom EXTRA_ enum.
241 static const int extra_new_buffers
[] = {
246 static const int extra_new_frag_clamp
[] = {
247 EXTRA_NEW_FRAG_CLAMP
,
251 static const int extra_valid_draw_buffer
[] = {
252 EXTRA_VALID_DRAW_BUFFER
,
256 static const int extra_valid_texture_unit
[] = {
257 EXTRA_VALID_TEXTURE_UNIT
,
261 static const int extra_valid_clip_distance
[] = {
262 EXTRA_VALID_CLIP_DISTANCE
,
266 static const int extra_flush_current_valid_texture_unit
[] = {
268 EXTRA_VALID_TEXTURE_UNIT
,
272 static const int extra_flush_current
[] = {
277 static const int extra_EXT_texture_integer
[] = {
278 EXT(EXT_texture_integer
),
282 static const int extra_EXT_texture_integer_and_new_buffers
[] = {
283 EXT(EXT_texture_integer
),
288 static const int extra_GLSL_130_es3
[] = {
294 static const int extra_texture_buffer_object
[] = {
297 EXT(ARB_texture_buffer_object
),
301 static const int extra_ARB_transform_feedback2_api_es3
[] = {
302 EXT(ARB_transform_feedback2
),
307 static const int extra_ARB_uniform_buffer_object_and_geometry_shader
[] = {
312 static const int extra_ARB_ES2_compatibility_api_es2
[] = {
313 EXT(ARB_ES2_compatibility
),
318 static const int extra_ARB_ES3_compatibility_api_es3
[] = {
319 EXT(ARB_ES3_compatibility
),
324 static const int extra_EXT_framebuffer_sRGB_and_new_buffers
[] = {
325 EXT(EXT_framebuffer_sRGB
),
330 static const int extra_EXT_packed_float
[] = {
331 EXT(EXT_packed_float
),
336 static const int extra_EXT_texture_array_es3
[] = {
337 EXT(EXT_texture_array
),
342 static const int extra_ARB_shader_atomic_counters_and_geometry_shader
[] = {
343 EXTRA_EXT_ATOMICS_GS4
,
347 EXTRA_EXT(ARB_texture_cube_map
);
348 EXTRA_EXT(EXT_texture_array
);
349 EXTRA_EXT(NV_fog_distance
);
350 EXTRA_EXT(EXT_texture_filter_anisotropic
);
351 EXTRA_EXT(NV_point_sprite
);
352 EXTRA_EXT(NV_texture_rectangle
);
353 EXTRA_EXT(EXT_stencil_two_side
);
354 EXTRA_EXT(EXT_depth_bounds_test
);
355 EXTRA_EXT(ARB_depth_clamp
);
356 EXTRA_EXT(ATI_fragment_shader
);
357 EXTRA_EXT(EXT_framebuffer_blit
);
358 EXTRA_EXT(EXT_provoking_vertex
);
359 EXTRA_EXT(ARB_fragment_shader
);
360 EXTRA_EXT(ARB_fragment_program
);
361 EXTRA_EXT2(ARB_framebuffer_object
, EXT_framebuffer_multisample
);
362 EXTRA_EXT(ARB_seamless_cube_map
);
364 EXTRA_EXT(ARB_vertex_shader
);
365 EXTRA_EXT(EXT_transform_feedback
);
366 EXTRA_EXT(ARB_transform_feedback3
);
367 EXTRA_EXT(EXT_pixel_buffer_object
);
368 EXTRA_EXT(ARB_vertex_program
);
369 EXTRA_EXT2(NV_point_sprite
, ARB_point_sprite
);
370 EXTRA_EXT2(ARB_vertex_program
, ARB_fragment_program
);
371 EXTRA_EXT(ARB_geometry_shader4
);
372 EXTRA_EXT(ARB_color_buffer_float
);
373 EXTRA_EXT(EXT_framebuffer_sRGB
);
374 EXTRA_EXT(OES_EGL_image_external
);
375 EXTRA_EXT(ARB_blend_func_extended
);
376 EXTRA_EXT(ARB_uniform_buffer_object
);
377 EXTRA_EXT(ARB_timer_query
);
378 EXTRA_EXT(ARB_map_buffer_alignment
);
379 EXTRA_EXT(ARB_texture_cube_map_array
);
380 EXTRA_EXT(ARB_texture_buffer_range
);
381 EXTRA_EXT(ARB_texture_multisample
);
382 EXTRA_EXT(ARB_texture_gather
);
383 EXTRA_EXT(ARB_shader_atomic_counters
);
384 EXTRA_EXT(ARB_draw_indirect
);
387 extra_ARB_color_buffer_float_or_glcore
[] = {
388 EXT(ARB_color_buffer_float
),
394 extra_NV_primitive_restart
[] = {
395 EXT(NV_primitive_restart
),
399 static const int extra_version_30
[] = { EXTRA_VERSION_30
, EXTRA_END
};
400 static const int extra_version_31
[] = { EXTRA_VERSION_31
, EXTRA_END
};
401 static const int extra_version_32
[] = { EXTRA_VERSION_32
, EXTRA_END
};
402 static const int extra_version_40
[] = { EXTRA_VERSION_40
, EXTRA_END
};
404 static const int extra_gl30_es3
[] = {
410 static const int extra_gl32_es3
[] = {
416 static const int extra_gl32_ARB_geometry_shader4
[] = {
418 EXT(ARB_geometry_shader4
),
422 static const int extra_gl40_ARB_sample_shading
[] = {
424 EXT(ARB_sample_shading
),
429 extra_ARB_vertex_program_api_es2
[] = {
430 EXT(ARB_vertex_program
),
435 /* The ReadBuffer get token is valid under either full GL or under
436 * GLES2 if the NV_read_buffer extension is available. */
438 extra_NV_read_buffer_api_gl
[] = {
444 static const int extra_core_ARB_color_buffer_float_and_new_buffers
[] = {
446 EXT(ARB_color_buffer_float
),
451 /* This is the big table describing all the enums we accept in
452 * glGet*v(). The table is partitioned into six parts: enums
453 * understood by all GL APIs (OpenGL, GLES and GLES2), enums shared
454 * between OpenGL and GLES, enums exclusive to GLES, etc for the
455 * remaining combinations. To look up the enums valid in a given API
456 * we will use a hash table specific to that API. These tables are in
457 * turn generated at build time and included through get_hash.h.
460 #include "get_hash.h"
462 /* All we need now is a way to look up the value struct from the enum.
463 * The code generated by gcc for the old generated big switch
464 * statement is a big, balanced, open coded if/else tree, essentially
465 * an unrolled binary search. It would be natural to sort the new
466 * enum table and use bsearch(), but we will use a read-only hash
467 * table instead. bsearch() has a nice guaranteed worst case
468 * performance, but we're also guaranteed to hit that worst case
469 * (log2(n) iterations) for about half the enums. Instead, using an
470 * open addressing hash table, we can find the enum on the first try
471 * for 80% of the enums, 1 collision for 10% and never more than 5
472 * collisions for any enum (typical numbers). And the code is very
473 * simple, even though it feels a little magic. */
477 print_table_stats(int api
)
479 int i
, j
, collisions
[11], count
, hash
, mask
;
480 const struct value_desc
*d
;
481 const char *api_names
[] = {
482 [API_OPENGL_COMPAT
] = "GL",
483 [API_OPENGL_CORE
] = "GL_CORE",
484 [API_OPENGLES
] = "GLES",
485 [API_OPENGLES2
] = "GLES2",
487 const char *api_name
;
489 api_name
= api
< Elements(api_names
) ? api_names
[api
] : "N/A";
491 mask
= Elements(table(api
)) - 1;
492 memset(collisions
, 0, sizeof collisions
);
494 for (i
= 0; i
< Elements(table(api
)); i
++) {
498 d
= &values
[table(api
)[i
]];
499 hash
= (d
->pname
* prime_factor
);
502 if (values
[table(api
)[hash
& mask
]].pname
== d
->pname
)
514 printf("number of enums for %s: %d (total %ld)\n",
515 api_name
, count
, Elements(values
));
516 for (i
= 0; i
< Elements(collisions
) - 1; i
++)
517 if (collisions
[i
] > 0)
518 printf(" %d enums with %d %scollisions\n",
519 collisions
[i
], i
, i
== 10 ? "or more " : "");
524 * Initialize the enum hash for a given API
526 * This is called from one_time_init() to insert the enum values that
527 * are valid for the API in question into the enum hash table.
529 * \param the current context, for determining the API in question
531 void _mesa_init_get_hash(struct gl_context
*ctx
)
534 print_table_stats(ctx
->API
);
541 * Handle irregular enums
543 * Some values don't conform to the "well-known type at context
544 * pointer + offset" pattern, so we have this function to catch all
545 * the corner cases. Typically, it's a computed value or a one-off
546 * pointer to a custom struct or something.
548 * In this case we can't return a pointer to the value, so we'll have
549 * to use the temporary variable 'v' declared back in the calling
550 * glGet*v() function to store the result.
552 * \param ctx the current context
553 * \param d the struct value_desc that describes the enum
554 * \param v pointer to the tmp declared in the calling glGet*v() function
557 find_custom_value(struct gl_context
*ctx
, const struct value_desc
*d
, union value
*v
)
559 struct gl_buffer_object
**buffer_obj
;
560 struct gl_vertex_attrib_array
*array
;
564 case GL_MAJOR_VERSION
:
565 v
->value_int
= ctx
->Version
/ 10;
567 case GL_MINOR_VERSION
:
568 v
->value_int
= ctx
->Version
% 10;
574 case GL_TEXTURE_CUBE_MAP_ARB
:
575 case GL_TEXTURE_RECTANGLE_NV
:
576 case GL_TEXTURE_EXTERNAL_OES
:
577 v
->value_bool
= _mesa_IsEnabled(d
->pname
);
580 case GL_LINE_STIPPLE_PATTERN
:
581 /* This is the only GLushort, special case it here by promoting
582 * to an int rather than introducing a new type. */
583 v
->value_int
= ctx
->Line
.StipplePattern
;
586 case GL_CURRENT_RASTER_TEXTURE_COORDS
:
587 unit
= ctx
->Texture
.CurrentUnit
;
588 v
->value_float_4
[0] = ctx
->Current
.RasterTexCoords
[unit
][0];
589 v
->value_float_4
[1] = ctx
->Current
.RasterTexCoords
[unit
][1];
590 v
->value_float_4
[2] = ctx
->Current
.RasterTexCoords
[unit
][2];
591 v
->value_float_4
[3] = ctx
->Current
.RasterTexCoords
[unit
][3];
594 case GL_CURRENT_TEXTURE_COORDS
:
595 unit
= ctx
->Texture
.CurrentUnit
;
596 v
->value_float_4
[0] = ctx
->Current
.Attrib
[VERT_ATTRIB_TEX0
+ unit
][0];
597 v
->value_float_4
[1] = ctx
->Current
.Attrib
[VERT_ATTRIB_TEX0
+ unit
][1];
598 v
->value_float_4
[2] = ctx
->Current
.Attrib
[VERT_ATTRIB_TEX0
+ unit
][2];
599 v
->value_float_4
[3] = ctx
->Current
.Attrib
[VERT_ATTRIB_TEX0
+ unit
][3];
602 case GL_COLOR_WRITEMASK
:
603 v
->value_int_4
[0] = ctx
->Color
.ColorMask
[0][RCOMP
] ? 1 : 0;
604 v
->value_int_4
[1] = ctx
->Color
.ColorMask
[0][GCOMP
] ? 1 : 0;
605 v
->value_int_4
[2] = ctx
->Color
.ColorMask
[0][BCOMP
] ? 1 : 0;
606 v
->value_int_4
[3] = ctx
->Color
.ColorMask
[0][ACOMP
] ? 1 : 0;
610 v
->value_bool
= ctx
->Current
.Attrib
[VERT_ATTRIB_EDGEFLAG
][0] == 1.0;
614 v
->value_enum
= ctx
->ReadBuffer
->ColorReadBuffer
;
617 case GL_MAP2_GRID_DOMAIN
:
618 v
->value_float_4
[0] = ctx
->Eval
.MapGrid2u1
;
619 v
->value_float_4
[1] = ctx
->Eval
.MapGrid2u2
;
620 v
->value_float_4
[2] = ctx
->Eval
.MapGrid2v1
;
621 v
->value_float_4
[3] = ctx
->Eval
.MapGrid2v2
;
624 case GL_TEXTURE_STACK_DEPTH
:
625 unit
= ctx
->Texture
.CurrentUnit
;
626 v
->value_int
= ctx
->TextureMatrixStack
[unit
].Depth
+ 1;
628 case GL_TEXTURE_MATRIX
:
629 unit
= ctx
->Texture
.CurrentUnit
;
630 v
->value_matrix
= ctx
->TextureMatrixStack
[unit
].Top
;
633 case GL_TEXTURE_COORD_ARRAY
:
634 case GL_TEXTURE_COORD_ARRAY_SIZE
:
635 case GL_TEXTURE_COORD_ARRAY_TYPE
:
636 case GL_TEXTURE_COORD_ARRAY_STRIDE
:
637 array
= &ctx
->Array
.ArrayObj
->VertexAttrib
[VERT_ATTRIB_TEX(ctx
->Array
.ActiveTexture
)];
638 v
->value_int
= *(GLuint
*) ((char *) array
+ d
->offset
);
641 case GL_ACTIVE_TEXTURE_ARB
:
642 v
->value_int
= GL_TEXTURE0_ARB
+ ctx
->Texture
.CurrentUnit
;
644 case GL_CLIENT_ACTIVE_TEXTURE_ARB
:
645 v
->value_int
= GL_TEXTURE0_ARB
+ ctx
->Array
.ActiveTexture
;
648 case GL_MODELVIEW_STACK_DEPTH
:
649 case GL_PROJECTION_STACK_DEPTH
:
650 v
->value_int
= *(GLint
*) ((char *) ctx
+ d
->offset
) + 1;
653 case GL_MAX_TEXTURE_SIZE
:
654 case GL_MAX_3D_TEXTURE_SIZE
:
655 case GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB
:
656 p
= (GLuint
*) ((char *) ctx
+ d
->offset
);
657 v
->value_int
= 1 << (*p
- 1);
661 v
->value_int_4
[0] = ctx
->Scissor
.X
;
662 v
->value_int_4
[1] = ctx
->Scissor
.Y
;
663 v
->value_int_4
[2] = ctx
->Scissor
.Width
;
664 v
->value_int_4
[3] = ctx
->Scissor
.Height
;
669 ctx
->ListState
.CurrentList
? ctx
->ListState
.CurrentList
->Name
: 0;
672 if (!ctx
->CompileFlag
)
674 else if (ctx
->ExecuteFlag
)
675 v
->value_enum
= GL_COMPILE_AND_EXECUTE
;
677 v
->value_enum
= GL_COMPILE
;
681 v
->value_int_4
[0] = ctx
->Viewport
.X
;
682 v
->value_int_4
[1] = ctx
->Viewport
.Y
;
683 v
->value_int_4
[2] = ctx
->Viewport
.Width
;
684 v
->value_int_4
[3] = ctx
->Viewport
.Height
;
687 case GL_ACTIVE_STENCIL_FACE_EXT
:
688 v
->value_enum
= ctx
->Stencil
.ActiveFace
? GL_BACK
: GL_FRONT
;
691 case GL_STENCIL_FAIL
:
692 v
->value_enum
= ctx
->Stencil
.FailFunc
[ctx
->Stencil
.ActiveFace
];
694 case GL_STENCIL_FUNC
:
695 v
->value_enum
= ctx
->Stencil
.Function
[ctx
->Stencil
.ActiveFace
];
697 case GL_STENCIL_PASS_DEPTH_FAIL
:
698 v
->value_enum
= ctx
->Stencil
.ZFailFunc
[ctx
->Stencil
.ActiveFace
];
700 case GL_STENCIL_PASS_DEPTH_PASS
:
701 v
->value_enum
= ctx
->Stencil
.ZPassFunc
[ctx
->Stencil
.ActiveFace
];
704 v
->value_int
= _mesa_get_stencil_ref(ctx
, ctx
->Stencil
.ActiveFace
);
706 case GL_STENCIL_BACK_REF
:
707 v
->value_int
= _mesa_get_stencil_ref(ctx
, 1);
709 case GL_STENCIL_VALUE_MASK
:
710 v
->value_int
= ctx
->Stencil
.ValueMask
[ctx
->Stencil
.ActiveFace
];
712 case GL_STENCIL_WRITEMASK
:
713 v
->value_int
= ctx
->Stencil
.WriteMask
[ctx
->Stencil
.ActiveFace
];
716 case GL_NUM_EXTENSIONS
:
717 v
->value_int
= _mesa_get_extension_count(ctx
);
720 case GL_IMPLEMENTATION_COLOR_READ_TYPE_OES
:
721 v
->value_int
= _mesa_get_color_read_type(ctx
);
723 case GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES
:
724 v
->value_int
= _mesa_get_color_read_format(ctx
);
727 case GL_CURRENT_MATRIX_STACK_DEPTH_ARB
:
728 v
->value_int
= ctx
->CurrentStack
->Depth
+ 1;
730 case GL_CURRENT_MATRIX_ARB
:
731 case GL_TRANSPOSE_CURRENT_MATRIX_ARB
:
732 v
->value_matrix
= ctx
->CurrentStack
->Top
;
735 case GL_NUM_COMPRESSED_TEXTURE_FORMATS_ARB
:
736 v
->value_int
= _mesa_get_compressed_formats(ctx
, NULL
);
738 case GL_COMPRESSED_TEXTURE_FORMATS_ARB
:
740 _mesa_get_compressed_formats(ctx
, v
->value_int_n
.ints
);
741 ASSERT(v
->value_int_n
.n
<= (int) ARRAY_SIZE(v
->value_int_n
.ints
));
744 case GL_MAX_VARYING_FLOATS_ARB
:
745 v
->value_int
= ctx
->Const
.MaxVarying
* 4;
748 /* Various object names */
750 case GL_TEXTURE_BINDING_1D
:
751 case GL_TEXTURE_BINDING_2D
:
752 case GL_TEXTURE_BINDING_3D
:
753 case GL_TEXTURE_BINDING_1D_ARRAY_EXT
:
754 case GL_TEXTURE_BINDING_2D_ARRAY_EXT
:
755 case GL_TEXTURE_BINDING_CUBE_MAP_ARB
:
756 case GL_TEXTURE_BINDING_RECTANGLE_NV
:
757 case GL_TEXTURE_BINDING_EXTERNAL_OES
:
758 case GL_TEXTURE_BINDING_CUBE_MAP_ARRAY
:
759 case GL_TEXTURE_BINDING_2D_MULTISAMPLE
:
760 case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY
:
761 unit
= ctx
->Texture
.CurrentUnit
;
763 ctx
->Texture
.Unit
[unit
].CurrentTex
[d
->offset
]->Name
;
766 /* GL_EXT_packed_float */
767 case GL_RGBA_SIGNED_COMPONENTS_EXT
:
769 /* Note: we only check the 0th color attachment. */
770 const struct gl_renderbuffer
*rb
=
771 ctx
->DrawBuffer
->_ColorDrawBuffers
[0];
772 if (rb
&& _mesa_is_format_signed(rb
->Format
)) {
773 /* Issue 17 of GL_EXT_packed_float: If a component (such as
774 * alpha) has zero bits, the component should not be considered
775 * signed and so the bit for the respective component should be
779 _mesa_get_format_bits(rb
->Format
, GL_RED_BITS
);
781 _mesa_get_format_bits(rb
->Format
, GL_GREEN_BITS
);
783 _mesa_get_format_bits(rb
->Format
, GL_BLUE_BITS
);
785 _mesa_get_format_bits(rb
->Format
, GL_ALPHA_BITS
);
787 _mesa_get_format_bits(rb
->Format
, GL_TEXTURE_LUMINANCE_SIZE
);
789 _mesa_get_format_bits(rb
->Format
, GL_TEXTURE_INTENSITY_SIZE
);
791 v
->value_int_4
[0] = r_bits
+ l_bits
+ i_bits
> 0;
792 v
->value_int_4
[1] = g_bits
+ l_bits
+ i_bits
> 0;
793 v
->value_int_4
[2] = b_bits
+ l_bits
+ i_bits
> 0;
794 v
->value_int_4
[3] = a_bits
+ i_bits
> 0;
800 v
->value_int_4
[3] = 0;
805 /* GL_ARB_vertex_buffer_object */
806 case GL_VERTEX_ARRAY_BUFFER_BINDING_ARB
:
807 case GL_NORMAL_ARRAY_BUFFER_BINDING_ARB
:
808 case GL_COLOR_ARRAY_BUFFER_BINDING_ARB
:
809 case GL_INDEX_ARRAY_BUFFER_BINDING_ARB
:
810 case GL_EDGE_FLAG_ARRAY_BUFFER_BINDING_ARB
:
811 case GL_SECONDARY_COLOR_ARRAY_BUFFER_BINDING_ARB
:
812 case GL_FOG_COORDINATE_ARRAY_BUFFER_BINDING_ARB
:
813 buffer_obj
= (struct gl_buffer_object
**)
814 ((char *) ctx
->Array
.ArrayObj
+ d
->offset
);
815 v
->value_int
= (*buffer_obj
)->Name
;
817 case GL_ARRAY_BUFFER_BINDING_ARB
:
818 v
->value_int
= ctx
->Array
.ArrayBufferObj
->Name
;
820 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING_ARB
:
822 ctx
->Array
.ArrayObj
->VertexBinding
[VERT_ATTRIB_TEX(ctx
->Array
.ActiveTexture
)].BufferObj
->Name
;
824 case GL_ELEMENT_ARRAY_BUFFER_BINDING_ARB
:
825 v
->value_int
= ctx
->Array
.ArrayObj
->ElementArrayBufferObj
->Name
;
828 /* ARB_copy_buffer */
829 case GL_COPY_READ_BUFFER
:
830 v
->value_int
= ctx
->CopyReadBuffer
->Name
;
832 case GL_COPY_WRITE_BUFFER
:
833 v
->value_int
= ctx
->CopyWriteBuffer
->Name
;
836 case GL_PIXEL_PACK_BUFFER_BINDING_EXT
:
837 v
->value_int
= ctx
->Pack
.BufferObj
->Name
;
839 case GL_PIXEL_UNPACK_BUFFER_BINDING_EXT
:
840 v
->value_int
= ctx
->Unpack
.BufferObj
->Name
;
842 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING
:
843 v
->value_int
= ctx
->TransformFeedback
.CurrentBuffer
->Name
;
845 case GL_TRANSFORM_FEEDBACK_BUFFER_PAUSED
:
846 v
->value_int
= ctx
->TransformFeedback
.CurrentObject
->Paused
;
848 case GL_TRANSFORM_FEEDBACK_BUFFER_ACTIVE
:
849 v
->value_int
= ctx
->TransformFeedback
.CurrentObject
->Active
;
851 case GL_TRANSFORM_FEEDBACK_BINDING
:
852 v
->value_int
= ctx
->TransformFeedback
.CurrentObject
->Name
;
854 case GL_CURRENT_PROGRAM
:
856 ctx
->Shader
.ActiveProgram
? ctx
->Shader
.ActiveProgram
->Name
: 0;
858 case GL_READ_FRAMEBUFFER_BINDING_EXT
:
859 v
->value_int
= ctx
->ReadBuffer
->Name
;
861 case GL_RENDERBUFFER_BINDING_EXT
:
863 ctx
->CurrentRenderbuffer
? ctx
->CurrentRenderbuffer
->Name
: 0;
865 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES
:
866 v
->value_int
= ctx
->Array
.ArrayObj
->VertexBinding
[VERT_ATTRIB_POINT_SIZE
].BufferObj
->Name
;
870 if (_mesa_get_clamp_fragment_color(ctx
))
871 COPY_4FV(v
->value_float_4
, ctx
->Fog
.Color
);
873 COPY_4FV(v
->value_float_4
, ctx
->Fog
.ColorUnclamped
);
875 case GL_COLOR_CLEAR_VALUE
:
876 if (_mesa_get_clamp_fragment_color(ctx
)) {
877 v
->value_float_4
[0] = CLAMP(ctx
->Color
.ClearColor
.f
[0], 0.0F
, 1.0F
);
878 v
->value_float_4
[1] = CLAMP(ctx
->Color
.ClearColor
.f
[1], 0.0F
, 1.0F
);
879 v
->value_float_4
[2] = CLAMP(ctx
->Color
.ClearColor
.f
[2], 0.0F
, 1.0F
);
880 v
->value_float_4
[3] = CLAMP(ctx
->Color
.ClearColor
.f
[3], 0.0F
, 1.0F
);
882 COPY_4FV(v
->value_float_4
, ctx
->Color
.ClearColor
.f
);
884 case GL_BLEND_COLOR_EXT
:
885 if (_mesa_get_clamp_fragment_color(ctx
))
886 COPY_4FV(v
->value_float_4
, ctx
->Color
.BlendColor
);
888 COPY_4FV(v
->value_float_4
, ctx
->Color
.BlendColorUnclamped
);
890 case GL_ALPHA_TEST_REF
:
891 if (_mesa_get_clamp_fragment_color(ctx
))
892 v
->value_float
= ctx
->Color
.AlphaRef
;
894 v
->value_float
= ctx
->Color
.AlphaRefUnclamped
;
896 case GL_MAX_VERTEX_UNIFORM_VECTORS
:
897 v
->value_int
= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxUniformComponents
/ 4;
900 case GL_MAX_FRAGMENT_UNIFORM_VECTORS
:
901 v
->value_int
= ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxUniformComponents
/ 4;
904 /* GL_ARB_texture_buffer_object */
905 case GL_TEXTURE_BUFFER_ARB
:
906 v
->value_int
= ctx
->Texture
.BufferObject
->Name
;
908 case GL_TEXTURE_BINDING_BUFFER_ARB
:
909 unit
= ctx
->Texture
.CurrentUnit
;
911 ctx
->Texture
.Unit
[unit
].CurrentTex
[TEXTURE_BUFFER_INDEX
]->Name
;
913 case GL_TEXTURE_BUFFER_DATA_STORE_BINDING_ARB
:
915 struct gl_buffer_object
*buf
=
916 ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
]
917 .CurrentTex
[TEXTURE_BUFFER_INDEX
]->BufferObject
;
918 v
->value_int
= buf
? buf
->Name
: 0;
921 case GL_TEXTURE_BUFFER_FORMAT_ARB
:
922 v
->value_int
= ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
]
923 .CurrentTex
[TEXTURE_BUFFER_INDEX
]->BufferObjectFormat
;
926 /* GL_ARB_sampler_objects */
927 case GL_SAMPLER_BINDING
:
929 struct gl_sampler_object
*samp
=
930 ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
].Sampler
;
933 * The sampler object may have been deleted on another context,
934 * so we try to lookup the sampler object before returning its Name.
936 if (samp
&& _mesa_lookup_samplerobj(ctx
, samp
->Name
)) {
937 v
->value_int
= samp
->Name
;
943 /* GL_ARB_uniform_buffer_object */
944 case GL_UNIFORM_BUFFER_BINDING
:
945 v
->value_int
= ctx
->UniformBuffer
->Name
;
947 /* GL_ARB_timer_query */
949 if (ctx
->Driver
.GetTimestamp
) {
950 v
->value_int64
= ctx
->Driver
.GetTimestamp(ctx
);
953 _mesa_problem(ctx
, "driver doesn't implement GetTimestamp");
956 /* GL_ARB_shader_atomic_counters */
957 case GL_ATOMIC_COUNTER_BUFFER_BINDING
:
958 v
->value_int
= ctx
->AtomicBuffer
->Name
;
960 /* GL_ARB_draw_indirect */
961 case GL_DRAW_INDIRECT_BUFFER_BINDING
:
962 v
->value_int
= ctx
->DrawIndirectBuffer
->Name
;
968 * Check extra constraints on a struct value_desc descriptor
970 * If a struct value_desc has a non-NULL extra pointer, it means that
971 * there are a number of extra constraints to check or actions to
972 * perform. The extras is just an integer array where each integer
973 * encode different constraints or actions.
975 * \param ctx current context
976 * \param func name of calling glGet*v() function for error reporting
977 * \param d the struct value_desc that has the extra constraints
979 * \return GL_FALSE if all of the constraints were not satisfied,
983 check_extra(struct gl_context
*ctx
, const char *func
, const struct value_desc
*d
)
985 const GLuint version
= ctx
->Version
;
986 GLboolean api_check
= GL_FALSE
;
987 GLboolean api_found
= GL_FALSE
;
990 for (e
= d
->extra
; *e
!= EXTRA_END
; e
++) {
992 case EXTRA_VERSION_30
:
997 case EXTRA_VERSION_31
:
1000 api_found
= GL_TRUE
;
1002 case EXTRA_VERSION_32
:
1003 api_check
= GL_TRUE
;
1005 api_found
= GL_TRUE
;
1007 case EXTRA_NEW_FRAG_CLAMP
:
1008 if (ctx
->NewState
& (_NEW_BUFFERS
| _NEW_FRAG_CLAMP
))
1009 _mesa_update_state(ctx
);
1012 api_check
= GL_TRUE
;
1013 if (ctx
->API
== API_OPENGLES2
)
1014 api_found
= GL_TRUE
;
1017 api_check
= GL_TRUE
;
1018 if (_mesa_is_gles3(ctx
))
1019 api_found
= GL_TRUE
;
1022 api_check
= GL_TRUE
;
1023 if (_mesa_is_desktop_gl(ctx
))
1024 api_found
= GL_TRUE
;
1026 case EXTRA_API_GL_CORE
:
1027 api_check
= GL_TRUE
;
1028 if (ctx
->API
== API_OPENGL_CORE
)
1029 api_found
= GL_TRUE
;
1031 case EXTRA_NEW_BUFFERS
:
1032 if (ctx
->NewState
& _NEW_BUFFERS
)
1033 _mesa_update_state(ctx
);
1035 case EXTRA_FLUSH_CURRENT
:
1036 FLUSH_CURRENT(ctx
, 0);
1038 case EXTRA_VALID_DRAW_BUFFER
:
1039 if (d
->pname
- GL_DRAW_BUFFER0_ARB
>= ctx
->Const
.MaxDrawBuffers
) {
1040 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(draw buffer %u)",
1041 func
, d
->pname
- GL_DRAW_BUFFER0_ARB
);
1045 case EXTRA_VALID_TEXTURE_UNIT
:
1046 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureCoordUnits
) {
1047 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(texture %u)",
1048 func
, ctx
->Texture
.CurrentUnit
);
1052 case EXTRA_VALID_CLIP_DISTANCE
:
1053 if (d
->pname
- GL_CLIP_DISTANCE0
>= ctx
->Const
.MaxClipPlanes
) {
1054 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(clip distance %u)",
1055 func
, d
->pname
- GL_CLIP_DISTANCE0
);
1059 case EXTRA_GLSL_130
:
1060 api_check
= GL_TRUE
;
1061 if (ctx
->Const
.GLSLVersion
>= 130)
1062 api_found
= GL_TRUE
;
1064 case EXTRA_EXT_UBO_GS4
:
1065 api_check
= GL_TRUE
;
1066 api_found
= (ctx
->Extensions
.ARB_uniform_buffer_object
&&
1067 _mesa_has_geometry_shaders(ctx
));
1069 case EXTRA_EXT_ATOMICS_GS4
:
1070 api_check
= GL_TRUE
;
1071 api_found
= (ctx
->Extensions
.ARB_shader_atomic_counters
&&
1072 _mesa_has_geometry_shaders(ctx
));
1076 default: /* *e is a offset into the extension struct */
1077 api_check
= GL_TRUE
;
1078 if (*(GLboolean
*) ((char *) &ctx
->Extensions
+ *e
))
1079 api_found
= GL_TRUE
;
1084 if (api_check
&& !api_found
) {
1085 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=%s)", func
,
1086 _mesa_lookup_enum_by_nr(d
->pname
));
1093 static const struct value_desc error_value
=
1094 { 0, 0, TYPE_INVALID
, NO_OFFSET
, NO_EXTRA
};
1097 * Find the struct value_desc corresponding to the enum 'pname'.
1099 * We hash the enum value to get an index into the 'table' array,
1100 * which holds the index in the 'values' array of struct value_desc.
1101 * Once we've found the entry, we do the extra checks, if any, then
1102 * look up the value and return a pointer to it.
1104 * If the value has to be computed (for example, it's the result of a
1105 * function call or we need to add 1 to it), we use the tmp 'v' to
1108 * \param func name of glGet*v() func for error reporting
1109 * \param pname the enum value we're looking up
1110 * \param p is were we return the pointer to the value
1111 * \param v a tmp union value variable in the calling glGet*v() function
1113 * \return the struct value_desc corresponding to the enum or a struct
1114 * value_desc of TYPE_INVALID if not found. This lets the calling
1115 * glGet*v() function jump right into a switch statement and
1116 * handle errors there instead of having to check for NULL.
1118 static const struct value_desc
*
1119 find_value(const char *func
, GLenum pname
, void **p
, union value
*v
)
1121 GET_CURRENT_CONTEXT(ctx
);
1122 struct gl_texture_unit
*unit
;
1124 const struct value_desc
*d
;
1128 /* We index into the table_set[] list of per-API hash tables using the API's
1129 * value in the gl_api enum. Since GLES 3 doesn't have an API_OPENGL* enum
1130 * value since it's compatible with GLES2 its entry in table_set[] is at the
1133 STATIC_ASSERT(Elements(table_set
) == API_OPENGL_LAST
+ 2);
1134 if (_mesa_is_gles3(ctx
)) {
1135 api
= API_OPENGL_LAST
+ 1;
1137 mask
= Elements(table(api
)) - 1;
1138 hash
= (pname
* prime_factor
);
1140 int idx
= table(api
)[hash
& mask
];
1142 /* If the enum isn't valid, the hash walk ends with index 0,
1143 * pointing to the first entry of values[] which doesn't hold
1144 * any valid enum. */
1145 if (unlikely(idx
== 0)) {
1146 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=%s)", func
,
1147 _mesa_lookup_enum_by_nr(pname
));
1148 return &error_value
;
1152 if (likely(d
->pname
== pname
))
1158 if (unlikely(d
->extra
&& !check_extra(ctx
, func
, d
)))
1159 return &error_value
;
1161 switch (d
->location
) {
1163 *p
= ((char *) ctx
->DrawBuffer
+ d
->offset
);
1166 *p
= ((char *) ctx
+ d
->offset
);
1169 *p
= ((char *) ctx
->Array
.ArrayObj
+ d
->offset
);
1172 unit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1173 *p
= ((char *) unit
+ d
->offset
);
1176 find_custom_value(ctx
, d
, v
);
1184 /* silence warning */
1185 return &error_value
;
1188 static const int transpose
[] = {
1196 _mesa_GetBooleanv(GLenum pname
, GLboolean
*params
)
1198 const struct value_desc
*d
;
1204 d
= find_value("glGetBooleanv", pname
, &p
, &v
);
1209 params
[0] = INT_TO_BOOLEAN(d
->offset
);
1214 params
[3] = FLOAT_TO_BOOLEAN(((GLfloat
*) p
)[3]);
1217 params
[2] = FLOAT_TO_BOOLEAN(((GLfloat
*) p
)[2]);
1220 params
[1] = FLOAT_TO_BOOLEAN(((GLfloat
*) p
)[1]);
1223 params
[0] = FLOAT_TO_BOOLEAN(((GLfloat
*) p
)[0]);
1227 params
[0] = FLOAT_TO_BOOLEAN(((GLdouble
*) p
)[0]);
1231 params
[3] = INT_TO_BOOLEAN(((GLint
*) p
)[3]);
1233 params
[2] = INT_TO_BOOLEAN(((GLint
*) p
)[2]);
1236 params
[1] = INT_TO_BOOLEAN(((GLint
*) p
)[1]);
1239 params
[0] = INT_TO_BOOLEAN(((GLint
*) p
)[0]);
1243 for (i
= 0; i
< v
.value_int_n
.n
; i
++)
1244 params
[i
] = INT_TO_BOOLEAN(v
.value_int_n
.ints
[i
]);
1248 params
[0] = INT64_TO_BOOLEAN(((GLint64
*) p
)[0]);
1252 params
[0] = ((GLboolean
*) p
)[0];
1256 m
= *(GLmatrix
**) p
;
1257 for (i
= 0; i
< 16; i
++)
1258 params
[i
] = FLOAT_TO_BOOLEAN(m
->m
[i
]);
1262 m
= *(GLmatrix
**) p
;
1263 for (i
= 0; i
< 16; i
++)
1264 params
[i
] = FLOAT_TO_BOOLEAN(m
->m
[transpose
[i
]]);
1275 shift
= d
->type
- TYPE_BIT_0
;
1276 params
[0] = (*(GLbitfield
*) p
>> shift
) & 1;
1282 _mesa_GetFloatv(GLenum pname
, GLfloat
*params
)
1284 const struct value_desc
*d
;
1290 d
= find_value("glGetFloatv", pname
, &p
, &v
);
1295 params
[0] = (GLfloat
) d
->offset
;
1300 params
[3] = ((GLfloat
*) p
)[3];
1303 params
[2] = ((GLfloat
*) p
)[2];
1306 params
[1] = ((GLfloat
*) p
)[1];
1309 params
[0] = ((GLfloat
*) p
)[0];
1313 params
[0] = (GLfloat
) (((GLdouble
*) p
)[0]);
1317 params
[3] = (GLfloat
) (((GLint
*) p
)[3]);
1319 params
[2] = (GLfloat
) (((GLint
*) p
)[2]);
1322 params
[1] = (GLfloat
) (((GLint
*) p
)[1]);
1325 params
[0] = (GLfloat
) (((GLint
*) p
)[0]);
1329 for (i
= 0; i
< v
.value_int_n
.n
; i
++)
1330 params
[i
] = INT_TO_FLOAT(v
.value_int_n
.ints
[i
]);
1334 params
[0] = (GLfloat
) (((GLint64
*) p
)[0]);
1338 params
[0] = BOOLEAN_TO_FLOAT(*(GLboolean
*) p
);
1342 m
= *(GLmatrix
**) p
;
1343 for (i
= 0; i
< 16; i
++)
1344 params
[i
] = m
->m
[i
];
1348 m
= *(GLmatrix
**) p
;
1349 for (i
= 0; i
< 16; i
++)
1350 params
[i
] = m
->m
[transpose
[i
]];
1361 shift
= d
->type
- TYPE_BIT_0
;
1362 params
[0] = BOOLEAN_TO_FLOAT((*(GLbitfield
*) p
>> shift
) & 1);
1368 _mesa_GetIntegerv(GLenum pname
, GLint
*params
)
1370 const struct value_desc
*d
;
1376 d
= find_value("glGetIntegerv", pname
, &p
, &v
);
1381 params
[0] = d
->offset
;
1385 params
[3] = IROUND(((GLfloat
*) p
)[3]);
1387 params
[2] = IROUND(((GLfloat
*) p
)[2]);
1389 params
[1] = IROUND(((GLfloat
*) p
)[1]);
1391 params
[0] = IROUND(((GLfloat
*) p
)[0]);
1395 params
[3] = FLOAT_TO_INT(((GLfloat
*) p
)[3]);
1397 params
[2] = FLOAT_TO_INT(((GLfloat
*) p
)[2]);
1399 params
[1] = FLOAT_TO_INT(((GLfloat
*) p
)[1]);
1401 params
[0] = FLOAT_TO_INT(((GLfloat
*) p
)[0]);
1405 params
[0] = FLOAT_TO_INT(((GLdouble
*) p
)[0]);
1409 params
[3] = ((GLint
*) p
)[3];
1411 params
[2] = ((GLint
*) p
)[2];
1414 params
[1] = ((GLint
*) p
)[1];
1417 params
[0] = ((GLint
*) p
)[0];
1421 for (i
= 0; i
< v
.value_int_n
.n
; i
++)
1422 params
[i
] = v
.value_int_n
.ints
[i
];
1426 params
[0] = INT64_TO_INT(((GLint64
*) p
)[0]);
1430 params
[0] = BOOLEAN_TO_INT(*(GLboolean
*) p
);
1434 m
= *(GLmatrix
**) p
;
1435 for (i
= 0; i
< 16; i
++)
1436 params
[i
] = FLOAT_TO_INT(m
->m
[i
]);
1440 m
= *(GLmatrix
**) p
;
1441 for (i
= 0; i
< 16; i
++)
1442 params
[i
] = FLOAT_TO_INT(m
->m
[transpose
[i
]]);
1453 shift
= d
->type
- TYPE_BIT_0
;
1454 params
[0] = (*(GLbitfield
*) p
>> shift
) & 1;
1460 _mesa_GetInteger64v(GLenum pname
, GLint64
*params
)
1462 const struct value_desc
*d
;
1468 d
= find_value("glGetInteger64v", pname
, &p
, &v
);
1473 params
[0] = d
->offset
;
1477 params
[3] = IROUND64(((GLfloat
*) p
)[3]);
1479 params
[2] = IROUND64(((GLfloat
*) p
)[2]);
1481 params
[1] = IROUND64(((GLfloat
*) p
)[1]);
1483 params
[0] = IROUND64(((GLfloat
*) p
)[0]);
1487 params
[3] = FLOAT_TO_INT64(((GLfloat
*) p
)[3]);
1489 params
[2] = FLOAT_TO_INT64(((GLfloat
*) p
)[2]);
1491 params
[1] = FLOAT_TO_INT64(((GLfloat
*) p
)[1]);
1493 params
[0] = FLOAT_TO_INT64(((GLfloat
*) p
)[0]);
1497 params
[0] = FLOAT_TO_INT64(((GLdouble
*) p
)[0]);
1501 params
[3] = ((GLint
*) p
)[3];
1503 params
[2] = ((GLint
*) p
)[2];
1506 params
[1] = ((GLint
*) p
)[1];
1509 params
[0] = ((GLint
*) p
)[0];
1513 for (i
= 0; i
< v
.value_int_n
.n
; i
++)
1514 params
[i
] = INT_TO_BOOLEAN(v
.value_int_n
.ints
[i
]);
1518 params
[0] = ((GLint64
*) p
)[0];
1522 params
[0] = ((GLboolean
*) p
)[0];
1526 m
= *(GLmatrix
**) p
;
1527 for (i
= 0; i
< 16; i
++)
1528 params
[i
] = FLOAT_TO_INT64(m
->m
[i
]);
1532 m
= *(GLmatrix
**) p
;
1533 for (i
= 0; i
< 16; i
++)
1534 params
[i
] = FLOAT_TO_INT64(m
->m
[transpose
[i
]]);
1545 shift
= d
->type
- TYPE_BIT_0
;
1546 params
[0] = (*(GLbitfield
*) p
>> shift
) & 1;
1552 _mesa_GetDoublev(GLenum pname
, GLdouble
*params
)
1554 const struct value_desc
*d
;
1560 d
= find_value("glGetDoublev", pname
, &p
, &v
);
1565 params
[0] = d
->offset
;
1570 params
[3] = ((GLfloat
*) p
)[3];
1573 params
[2] = ((GLfloat
*) p
)[2];
1576 params
[1] = ((GLfloat
*) p
)[1];
1579 params
[0] = ((GLfloat
*) p
)[0];
1583 params
[0] = ((GLdouble
*) p
)[0];
1587 params
[3] = ((GLint
*) p
)[3];
1589 params
[2] = ((GLint
*) p
)[2];
1592 params
[1] = ((GLint
*) p
)[1];
1595 params
[0] = ((GLint
*) p
)[0];
1599 for (i
= 0; i
< v
.value_int_n
.n
; i
++)
1600 params
[i
] = v
.value_int_n
.ints
[i
];
1604 params
[0] = (GLdouble
) (((GLint64
*) p
)[0]);
1608 params
[0] = *(GLboolean
*) p
;
1612 m
= *(GLmatrix
**) p
;
1613 for (i
= 0; i
< 16; i
++)
1614 params
[i
] = m
->m
[i
];
1618 m
= *(GLmatrix
**) p
;
1619 for (i
= 0; i
< 16; i
++)
1620 params
[i
] = m
->m
[transpose
[i
]];
1631 shift
= d
->type
- TYPE_BIT_0
;
1632 params
[0] = (*(GLbitfield
*) p
>> shift
) & 1;
1637 static enum value_type
1638 find_value_indexed(const char *func
, GLenum pname
, GLuint index
, union value
*v
)
1640 GET_CURRENT_CONTEXT(ctx
);
1645 if (index
>= ctx
->Const
.MaxDrawBuffers
)
1647 if (!ctx
->Extensions
.EXT_draw_buffers2
)
1649 v
->value_int
= (ctx
->Color
.BlendEnabled
>> index
) & 1;
1654 case GL_BLEND_SRC_RGB
:
1655 if (index
>= ctx
->Const
.MaxDrawBuffers
)
1657 if (!ctx
->Extensions
.ARB_draw_buffers_blend
)
1659 v
->value_int
= ctx
->Color
.Blend
[index
].SrcRGB
;
1661 case GL_BLEND_SRC_ALPHA
:
1662 if (index
>= ctx
->Const
.MaxDrawBuffers
)
1664 if (!ctx
->Extensions
.ARB_draw_buffers_blend
)
1666 v
->value_int
= ctx
->Color
.Blend
[index
].SrcA
;
1670 case GL_BLEND_DST_RGB
:
1671 if (index
>= ctx
->Const
.MaxDrawBuffers
)
1673 if (!ctx
->Extensions
.ARB_draw_buffers_blend
)
1675 v
->value_int
= ctx
->Color
.Blend
[index
].DstRGB
;
1677 case GL_BLEND_DST_ALPHA
:
1678 if (index
>= ctx
->Const
.MaxDrawBuffers
)
1680 if (!ctx
->Extensions
.ARB_draw_buffers_blend
)
1682 v
->value_int
= ctx
->Color
.Blend
[index
].DstA
;
1684 case GL_BLEND_EQUATION_RGB
:
1685 if (index
>= ctx
->Const
.MaxDrawBuffers
)
1687 if (!ctx
->Extensions
.ARB_draw_buffers_blend
)
1689 v
->value_int
= ctx
->Color
.Blend
[index
].EquationRGB
;
1691 case GL_BLEND_EQUATION_ALPHA
:
1692 if (index
>= ctx
->Const
.MaxDrawBuffers
)
1694 if (!ctx
->Extensions
.ARB_draw_buffers_blend
)
1696 v
->value_int
= ctx
->Color
.Blend
[index
].EquationA
;
1699 case GL_COLOR_WRITEMASK
:
1700 if (index
>= ctx
->Const
.MaxDrawBuffers
)
1702 if (!ctx
->Extensions
.EXT_draw_buffers2
)
1704 v
->value_int_4
[0] = ctx
->Color
.ColorMask
[index
][RCOMP
] ? 1 : 0;
1705 v
->value_int_4
[1] = ctx
->Color
.ColorMask
[index
][GCOMP
] ? 1 : 0;
1706 v
->value_int_4
[2] = ctx
->Color
.ColorMask
[index
][BCOMP
] ? 1 : 0;
1707 v
->value_int_4
[3] = ctx
->Color
.ColorMask
[index
][ACOMP
] ? 1 : 0;
1710 case GL_TRANSFORM_FEEDBACK_BUFFER_START
:
1711 if (index
>= ctx
->Const
.MaxTransformFeedbackBuffers
)
1713 if (!ctx
->Extensions
.EXT_transform_feedback
)
1715 v
->value_int64
= ctx
->TransformFeedback
.CurrentObject
->Offset
[index
];
1718 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE
:
1719 if (index
>= ctx
->Const
.MaxTransformFeedbackBuffers
)
1721 if (!ctx
->Extensions
.EXT_transform_feedback
)
1724 = ctx
->TransformFeedback
.CurrentObject
->RequestedSize
[index
];
1727 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING
:
1728 if (index
>= ctx
->Const
.MaxTransformFeedbackBuffers
)
1730 if (!ctx
->Extensions
.EXT_transform_feedback
)
1732 v
->value_int
= ctx
->TransformFeedback
.CurrentObject
->BufferNames
[index
];
1735 case GL_UNIFORM_BUFFER_BINDING
:
1736 if (index
>= ctx
->Const
.MaxUniformBufferBindings
)
1738 if (!ctx
->Extensions
.ARB_uniform_buffer_object
)
1740 v
->value_int
= ctx
->UniformBufferBindings
[index
].BufferObject
->Name
;
1743 case GL_UNIFORM_BUFFER_START
:
1744 if (index
>= ctx
->Const
.MaxUniformBufferBindings
)
1746 if (!ctx
->Extensions
.ARB_uniform_buffer_object
)
1748 v
->value_int
= ctx
->UniformBufferBindings
[index
].Offset
;
1751 case GL_UNIFORM_BUFFER_SIZE
:
1752 if (index
>= ctx
->Const
.MaxUniformBufferBindings
)
1754 if (!ctx
->Extensions
.ARB_uniform_buffer_object
)
1756 v
->value_int
= ctx
->UniformBufferBindings
[index
].Size
;
1759 /* ARB_texture_multisample / GL3.2 */
1760 case GL_SAMPLE_MASK_VALUE
:
1763 if (!ctx
->Extensions
.ARB_texture_multisample
)
1765 v
->value_int
= ctx
->Multisample
.SampleMaskValue
;
1768 case GL_ATOMIC_COUNTER_BUFFER_BINDING
:
1769 if (!ctx
->Extensions
.ARB_shader_atomic_counters
)
1771 if (index
>= ctx
->Const
.MaxAtomicBufferBindings
)
1773 v
->value_int
= ctx
->AtomicBufferBindings
[index
].BufferObject
->Name
;
1776 case GL_ATOMIC_COUNTER_BUFFER_START
:
1777 if (!ctx
->Extensions
.ARB_shader_atomic_counters
)
1779 if (index
>= ctx
->Const
.MaxAtomicBufferBindings
)
1781 v
->value_int64
= ctx
->AtomicBufferBindings
[index
].Offset
;
1784 case GL_ATOMIC_COUNTER_BUFFER_SIZE
:
1785 if (!ctx
->Extensions
.ARB_shader_atomic_counters
)
1787 if (index
>= ctx
->Const
.MaxAtomicBufferBindings
)
1789 v
->value_int64
= ctx
->AtomicBufferBindings
[index
].Size
;
1792 case GL_VERTEX_BINDING_DIVISOR
:
1793 if (!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_instanced_arrays
)
1795 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
)
1797 v
->value_int
= ctx
->Array
.ArrayObj
->VertexBinding
[VERT_ATTRIB_GENERIC(index
)].InstanceDivisor
;
1800 case GL_VERTEX_BINDING_OFFSET
:
1801 if (!_mesa_is_desktop_gl(ctx
))
1803 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
)
1805 v
->value_int
= ctx
->Array
.ArrayObj
->VertexBinding
[VERT_ATTRIB_GENERIC(index
)].Offset
;
1808 case GL_VERTEX_BINDING_STRIDE
:
1809 if (!_mesa_is_desktop_gl(ctx
))
1811 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxAttribs
)
1813 v
->value_int
= ctx
->Array
.ArrayObj
->VertexBinding
[VERT_ATTRIB_GENERIC(index
)].Stride
;
1818 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(pname=%s)", func
,
1819 _mesa_lookup_enum_by_nr(pname
));
1820 return TYPE_INVALID
;
1822 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(pname=%s)", func
,
1823 _mesa_lookup_enum_by_nr(pname
));
1824 return TYPE_INVALID
;
1828 _mesa_GetBooleani_v( GLenum pname
, GLuint index
, GLboolean
*params
)
1831 enum value_type type
=
1832 find_value_indexed("glGetBooleani_v", pname
, index
, &v
);
1836 params
[0] = INT_TO_BOOLEAN(v
.value_int
);
1839 params
[0] = INT_TO_BOOLEAN(v
.value_int_4
[0]);
1840 params
[1] = INT_TO_BOOLEAN(v
.value_int_4
[1]);
1841 params
[2] = INT_TO_BOOLEAN(v
.value_int_4
[2]);
1842 params
[3] = INT_TO_BOOLEAN(v
.value_int_4
[3]);
1845 params
[0] = INT64_TO_BOOLEAN(v
.value_int
);
1848 ; /* nothing - GL error was recorded */
1853 _mesa_GetIntegeri_v( GLenum pname
, GLuint index
, GLint
*params
)
1856 enum value_type type
=
1857 find_value_indexed("glGetIntegeri_v", pname
, index
, &v
);
1861 params
[0] = v
.value_int
;
1864 params
[0] = v
.value_int_4
[0];
1865 params
[1] = v
.value_int_4
[1];
1866 params
[2] = v
.value_int_4
[2];
1867 params
[3] = v
.value_int_4
[3];
1870 params
[0] = INT64_TO_INT(v
.value_int
);
1873 ; /* nothing - GL error was recorded */
1878 _mesa_GetInteger64i_v( GLenum pname
, GLuint index
, GLint64
*params
)
1881 enum value_type type
=
1882 find_value_indexed("glGetInteger64i_v", pname
, index
, &v
);
1886 params
[0] = v
.value_int
;
1889 params
[0] = v
.value_int_4
[0];
1890 params
[1] = v
.value_int_4
[1];
1891 params
[2] = v
.value_int_4
[2];
1892 params
[3] = v
.value_int_4
[3];
1895 params
[0] = v
.value_int
;
1898 ; /* nothing - GL error was recorded */
1903 _mesa_GetFixedv(GLenum pname
, GLfixed
*params
)
1905 const struct value_desc
*d
;
1911 d
= find_value("glGetDoublev", pname
, &p
, &v
);
1916 params
[0] = INT_TO_FIXED(d
->offset
);
1921 params
[3] = FLOAT_TO_FIXED(((GLfloat
*) p
)[3]);
1924 params
[2] = FLOAT_TO_FIXED(((GLfloat
*) p
)[2]);
1927 params
[1] = FLOAT_TO_FIXED(((GLfloat
*) p
)[1]);
1930 params
[0] = FLOAT_TO_FIXED(((GLfloat
*) p
)[0]);
1934 params
[0] = FLOAT_TO_FIXED(((GLdouble
*) p
)[0]);
1938 params
[3] = INT_TO_FIXED(((GLint
*) p
)[3]);
1940 params
[2] = INT_TO_FIXED(((GLint
*) p
)[2]);
1943 params
[1] = INT_TO_FIXED(((GLint
*) p
)[1]);
1946 params
[0] = INT_TO_FIXED(((GLint
*) p
)[0]);
1950 for (i
= 0; i
< v
.value_int_n
.n
; i
++)
1951 params
[i
] = INT_TO_FIXED(v
.value_int_n
.ints
[i
]);
1955 params
[0] = ((GLint64
*) p
)[0];
1959 params
[0] = BOOLEAN_TO_FIXED(((GLboolean
*) p
)[0]);
1963 m
= *(GLmatrix
**) p
;
1964 for (i
= 0; i
< 16; i
++)
1965 params
[i
] = FLOAT_TO_FIXED(m
->m
[i
]);
1969 m
= *(GLmatrix
**) p
;
1970 for (i
= 0; i
< 16; i
++)
1971 params
[i
] = FLOAT_TO_FIXED(m
->m
[transpose
[i
]]);
1982 shift
= d
->type
- TYPE_BIT_0
;
1983 params
[0] = BOOLEAN_TO_FIXED((*(GLbitfield
*) p
>> shift
) & 1);