Home | History | Annotate | Download | only in main
      1 /*
      2  * Copyright (C) 2010  Brian Paul   All Rights Reserved.
      3  * Copyright (C) 2010  Intel Corporation
      4  *
      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:
     11  *
     12  * The above copyright notice and this permission notice shall be included
     13  * in all copies or substantial portions of the Software.
     14  *
     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.
     22  *
     23  * Author: Kristian Hgsberg <krh (at) bitplanet.net>
     24  */
     25 
     26 #include "glheader.h"
     27 #include "context.h"
     28 #include "blend.h"
     29 #include "debug_output.h"
     30 #include "enable.h"
     31 #include "enums.h"
     32 #include "errors.h"
     33 #include "extensions.h"
     34 #include "get.h"
     35 #include "macros.h"
     36 #include "mtypes.h"
     37 #include "state.h"
     38 #include "texcompress.h"
     39 #include "texstate.h"
     40 #include "framebuffer.h"
     41 #include "samplerobj.h"
     42 #include "stencil.h"
     43 #include "version.h"
     44 
     45 /* This is a table driven implemetation of the glGet*v() functions.
     46  * The basic idea is that most getters just look up an int somewhere
     47  * in struct gl_context and then convert it to a bool or float according to
     48  * which of glGetIntegerv() glGetBooleanv() etc is being called.
     49  * Instead of generating code to do this, we can just record the enum
     50  * value and the offset into struct gl_context in an array of structs.  Then
     51  * in glGet*(), we lookup the struct for the enum in question, and use
     52  * the offset to get the int we need.
     53  *
     54  * Sometimes we need to look up a float, a boolean, a bit in a
     55  * bitfield, a matrix or other types instead, so we need to track the
     56  * type of the value in struct gl_context.  And sometimes the value isn't in
     57  * struct gl_context but in the drawbuffer, the array object, current texture
     58  * unit, or maybe it's a computed value.  So we need to also track
     59  * where or how to find the value.  Finally, we sometimes need to
     60  * check that one of a number of extensions are enabled, the GL
     61  * version or flush or call _mesa_update_state().  This is done by
     62  * attaching optional extra information to the value description
     63  * struct, it's sort of like an array of opcodes that describe extra
     64  * checks or actions.
     65  *
     66  * Putting all this together we end up with struct value_desc below,
     67  * and with a couple of macros to help, the table of struct value_desc
     68  * is about as concise as the specification in the old python script.
     69  */
     70 
     71 #define FLOAT_TO_BOOLEAN(X)   ( (X) ? GL_TRUE : GL_FALSE )
     72 #define FLOAT_TO_FIXED(F)     ( ((F) * 65536.0f > INT_MAX) ? INT_MAX : \
     73                                 ((F) * 65536.0f < INT_MIN) ? INT_MIN : \
     74                                 (GLint) ((F) * 65536.0f) )
     75 
     76 #define INT_TO_BOOLEAN(I)     ( (I) ? GL_TRUE : GL_FALSE )
     77 #define INT_TO_FIXED(I)       ( ((I) > SHRT_MAX) ? INT_MAX : \
     78                                 ((I) < SHRT_MIN) ? INT_MIN : \
     79                                 (GLint) ((I) * 65536) )
     80 
     81 #define INT64_TO_BOOLEAN(I)   ( (I) ? GL_TRUE : GL_FALSE )
     82 #define INT64_TO_INT(I)       ( (GLint)((I > INT_MAX) ? INT_MAX : ((I < INT_MIN) ? INT_MIN : (I))) )
     83 
     84 #define BOOLEAN_TO_INT(B)     ( (GLint) (B) )
     85 #define BOOLEAN_TO_INT64(B)   ( (GLint64) (B) )
     86 #define BOOLEAN_TO_FLOAT(B)   ( (B) ? 1.0F : 0.0F )
     87 #define BOOLEAN_TO_FIXED(B)   ( (GLint) ((B) ? 1 : 0) << 16 )
     88 
     89 #define ENUM_TO_INT64(E)      ( (GLint64) (E) )
     90 #define ENUM_TO_FIXED(E)      (E)
     91 
     92 enum value_type {
     93    TYPE_INVALID,
     94    TYPE_INT,
     95    TYPE_INT_2,
     96    TYPE_INT_3,
     97    TYPE_INT_4,
     98    TYPE_INT_N,
     99    TYPE_UINT,
    100    TYPE_UINT_2,
    101    TYPE_UINT_3,
    102    TYPE_UINT_4,
    103    TYPE_INT64,
    104    TYPE_ENUM,
    105    TYPE_ENUM_2,
    106    TYPE_BOOLEAN,
    107    TYPE_BIT_0,
    108    TYPE_BIT_1,
    109    TYPE_BIT_2,
    110    TYPE_BIT_3,
    111    TYPE_BIT_4,
    112    TYPE_BIT_5,
    113    TYPE_BIT_6,
    114    TYPE_BIT_7,
    115    TYPE_FLOAT,
    116    TYPE_FLOAT_2,
    117    TYPE_FLOAT_3,
    118    TYPE_FLOAT_4,
    119    TYPE_FLOAT_8,
    120    TYPE_FLOATN,
    121    TYPE_FLOATN_2,
    122    TYPE_FLOATN_3,
    123    TYPE_FLOATN_4,
    124    TYPE_DOUBLEN,
    125    TYPE_DOUBLEN_2,
    126    TYPE_MATRIX,
    127    TYPE_MATRIX_T,
    128    TYPE_CONST
    129 };
    130 
    131 enum value_location {
    132    LOC_BUFFER,
    133    LOC_CONTEXT,
    134    LOC_ARRAY,
    135    LOC_TEXUNIT,
    136    LOC_CUSTOM
    137 };
    138 
    139 enum value_extra {
    140    EXTRA_END = 0x8000,
    141    EXTRA_VERSION_30,
    142    EXTRA_VERSION_31,
    143    EXTRA_VERSION_32,
    144    EXTRA_VERSION_40,
    145    EXTRA_VERSION_43,
    146    EXTRA_API_GL,
    147    EXTRA_API_GL_CORE,
    148    EXTRA_API_ES2,
    149    EXTRA_API_ES3,
    150    EXTRA_API_ES31,
    151    EXTRA_API_ES32,
    152    EXTRA_NEW_BUFFERS,
    153    EXTRA_NEW_FRAG_CLAMP,
    154    EXTRA_VALID_DRAW_BUFFER,
    155    EXTRA_VALID_TEXTURE_UNIT,
    156    EXTRA_VALID_CLIP_DISTANCE,
    157    EXTRA_FLUSH_CURRENT,
    158    EXTRA_GLSL_130,
    159    EXTRA_EXT_UBO_GS,
    160    EXTRA_EXT_ATOMICS_GS,
    161    EXTRA_EXT_SHADER_IMAGE_GS,
    162    EXTRA_EXT_ATOMICS_TESS,
    163    EXTRA_EXT_SHADER_IMAGE_TESS,
    164    EXTRA_EXT_SSBO_GS,
    165    EXTRA_EXT_FB_NO_ATTACH_GS,
    166    EXTRA_EXT_ES_GS,
    167    EXTRA_EXT_PROVOKING_VERTEX_32,
    168 };
    169 
    170 #define NO_EXTRA NULL
    171 #define NO_OFFSET 0
    172 
    173 struct value_desc {
    174    GLenum pname;
    175    GLubyte location;  /**< enum value_location */
    176    GLubyte type;      /**< enum value_type */
    177    int offset;
    178    const int *extra;
    179 };
    180 
    181 union value {
    182    GLfloat value_float;
    183    GLfloat value_float_4[4];
    184    GLdouble value_double_2[2];
    185    GLmatrix *value_matrix;
    186    GLint value_int;
    187    GLint value_int_4[4];
    188    GLint64 value_int64;
    189    GLenum value_enum;
    190 
    191    /* Sigh, see GL_COMPRESSED_TEXTURE_FORMATS_ARB handling */
    192    struct {
    193       GLint n, ints[100];
    194    } value_int_n;
    195    GLboolean value_bool;
    196 };
    197 
    198 #define BUFFER_FIELD(field, type) \
    199    LOC_BUFFER, type, offsetof(struct gl_framebuffer, field)
    200 #define CONTEXT_FIELD(field, type) \
    201    LOC_CONTEXT, type, offsetof(struct gl_context, field)
    202 #define ARRAY_FIELD(field, type) \
    203    LOC_ARRAY, type, offsetof(struct gl_vertex_array_object, field)
    204 #undef CONST /* already defined through windows.h */
    205 #define CONST(value) \
    206    LOC_CONTEXT, TYPE_CONST, value
    207 
    208 #define BUFFER_INT(field) BUFFER_FIELD(field, TYPE_INT)
    209 #define BUFFER_ENUM(field) BUFFER_FIELD(field, TYPE_ENUM)
    210 #define BUFFER_BOOL(field) BUFFER_FIELD(field, TYPE_BOOLEAN)
    211 
    212 #define CONTEXT_INT(field) CONTEXT_FIELD(field, TYPE_INT)
    213 #define CONTEXT_INT2(field) CONTEXT_FIELD(field, TYPE_INT_2)
    214 #define CONTEXT_INT64(field) CONTEXT_FIELD(field, TYPE_INT64)
    215 #define CONTEXT_UINT(field) CONTEXT_FIELD(field, TYPE_UINT)
    216 #define CONTEXT_ENUM(field) CONTEXT_FIELD(field, TYPE_ENUM)
    217 #define CONTEXT_ENUM2(field) CONTEXT_FIELD(field, TYPE_ENUM_2)
    218 #define CONTEXT_BOOL(field) CONTEXT_FIELD(field, TYPE_BOOLEAN)
    219 #define CONTEXT_BIT0(field) CONTEXT_FIELD(field, TYPE_BIT_0)
    220 #define CONTEXT_BIT1(field) CONTEXT_FIELD(field, TYPE_BIT_1)
    221 #define CONTEXT_BIT2(field) CONTEXT_FIELD(field, TYPE_BIT_2)
    222 #define CONTEXT_BIT3(field) CONTEXT_FIELD(field, TYPE_BIT_3)
    223 #define CONTEXT_BIT4(field) CONTEXT_FIELD(field, TYPE_BIT_4)
    224 #define CONTEXT_BIT5(field) CONTEXT_FIELD(field, TYPE_BIT_5)
    225 #define CONTEXT_BIT6(field) CONTEXT_FIELD(field, TYPE_BIT_6)
    226 #define CONTEXT_BIT7(field) CONTEXT_FIELD(field, TYPE_BIT_7)
    227 #define CONTEXT_FLOAT(field) CONTEXT_FIELD(field, TYPE_FLOAT)
    228 #define CONTEXT_FLOAT2(field) CONTEXT_FIELD(field, TYPE_FLOAT_2)
    229 #define CONTEXT_FLOAT3(field) CONTEXT_FIELD(field, TYPE_FLOAT_3)
    230 #define CONTEXT_FLOAT4(field) CONTEXT_FIELD(field, TYPE_FLOAT_4)
    231 #define CONTEXT_FLOAT8(field) CONTEXT_FIELD(field, TYPE_FLOAT_8)
    232 #define CONTEXT_MATRIX(field) CONTEXT_FIELD(field, TYPE_MATRIX)
    233 #define CONTEXT_MATRIX_T(field) CONTEXT_FIELD(field, TYPE_MATRIX_T)
    234 
    235 #define ARRAY_INT(field) ARRAY_FIELD(field, TYPE_INT)
    236 #define ARRAY_ENUM(field) ARRAY_FIELD(field, TYPE_ENUM)
    237 #define ARRAY_BOOL(field) ARRAY_FIELD(field, TYPE_BOOLEAN)
    238 
    239 #define EXT(f)					\
    240    offsetof(struct gl_extensions, f)
    241 
    242 #define EXTRA_EXT(e)				\
    243    static const int extra_##e[] = {		\
    244       EXT(e), EXTRA_END				\
    245    }
    246 
    247 #define EXTRA_EXT2(e1, e2)			\
    248    static const int extra_##e1##_##e2[] = {	\
    249       EXT(e1), EXT(e2), EXTRA_END		\
    250    }
    251 
    252 /* The 'extra' mechanism is a way to specify extra checks (such as
    253  * extensions or specific gl versions) or actions (flush current, new
    254  * buffers) that we need to do before looking up an enum.  We need to
    255  * declare them all up front so we can refer to them in the value_desc
    256  * structs below.
    257  *
    258  * Each EXTRA_ will be executed.  For EXTRA_* enums of extensions and API
    259  * versions, listing multiple ones in an array means an error will be thrown
    260  * only if none of them are available.  If you need to check for "AND"
    261  * behavior, you would need to make a custom EXTRA_ enum.
    262  */
    263 
    264 static const int extra_new_buffers[] = {
    265    EXTRA_NEW_BUFFERS,
    266    EXTRA_END
    267 };
    268 
    269 static const int extra_new_frag_clamp[] = {
    270    EXTRA_NEW_FRAG_CLAMP,
    271    EXTRA_END
    272 };
    273 
    274 static const int extra_valid_draw_buffer[] = {
    275    EXTRA_VALID_DRAW_BUFFER,
    276    EXTRA_END
    277 };
    278 
    279 static const int extra_valid_texture_unit[] = {
    280    EXTRA_VALID_TEXTURE_UNIT,
    281    EXTRA_END
    282 };
    283 
    284 static const int extra_valid_clip_distance[] = {
    285    EXTRA_VALID_CLIP_DISTANCE,
    286    EXTRA_END
    287 };
    288 
    289 static const int extra_flush_current_valid_texture_unit[] = {
    290    EXTRA_FLUSH_CURRENT,
    291    EXTRA_VALID_TEXTURE_UNIT,
    292    EXTRA_END
    293 };
    294 
    295 static const int extra_flush_current[] = {
    296    EXTRA_FLUSH_CURRENT,
    297    EXTRA_END
    298 };
    299 
    300 static const int extra_EXT_texture_integer_and_new_buffers[] = {
    301    EXT(EXT_texture_integer),
    302    EXTRA_NEW_BUFFERS,
    303    EXTRA_END
    304 };
    305 
    306 static const int extra_GLSL_130_es3[] = {
    307    EXTRA_GLSL_130,
    308    EXTRA_API_ES3,
    309    EXTRA_END
    310 };
    311 
    312 static const int extra_texture_buffer_object[] = {
    313    EXT(ARB_texture_buffer_object),
    314    EXTRA_END
    315 };
    316 
    317 static const int extra_ARB_transform_feedback2_api_es3[] = {
    318    EXT(ARB_transform_feedback2),
    319    EXTRA_API_ES3,
    320    EXTRA_END
    321 };
    322 
    323 static const int extra_ARB_uniform_buffer_object_and_geometry_shader[] = {
    324    EXTRA_EXT_UBO_GS,
    325    EXTRA_END
    326 };
    327 
    328 static const int extra_ARB_ES2_compatibility_api_es2[] = {
    329    EXT(ARB_ES2_compatibility),
    330    EXTRA_API_ES2,
    331    EXTRA_END
    332 };
    333 
    334 static const int extra_ARB_ES3_compatibility_api_es3[] = {
    335    EXT(ARB_ES3_compatibility),
    336    EXTRA_API_ES3,
    337    EXTRA_END
    338 };
    339 
    340 static const int extra_EXT_framebuffer_sRGB_and_new_buffers[] = {
    341    EXT(EXT_framebuffer_sRGB),
    342    EXTRA_NEW_BUFFERS,
    343    EXTRA_END
    344 };
    345 
    346 static const int extra_EXT_packed_float[] = {
    347    EXT(EXT_packed_float),
    348    EXTRA_NEW_BUFFERS,
    349    EXTRA_END
    350 };
    351 
    352 static const int extra_EXT_texture_array_es3[] = {
    353    EXT(EXT_texture_array),
    354    EXTRA_API_ES3,
    355    EXTRA_END
    356 };
    357 
    358 static const int extra_ARB_shader_atomic_counters_and_geometry_shader[] = {
    359    EXTRA_EXT_ATOMICS_GS,
    360    EXTRA_END
    361 };
    362 
    363 static const int extra_ARB_shader_image_load_store_and_geometry_shader[] = {
    364    EXTRA_EXT_SHADER_IMAGE_GS,
    365    EXTRA_END
    366 };
    367 
    368 static const int extra_ARB_shader_atomic_counters_and_tessellation[] = {
    369    EXTRA_EXT_ATOMICS_TESS,
    370    EXTRA_END
    371 };
    372 
    373 static const int extra_ARB_shader_image_load_store_and_tessellation[] = {
    374    EXTRA_EXT_SHADER_IMAGE_TESS,
    375    EXTRA_END
    376 };
    377 
    378 /* HACK: remove when ARB_compute_shader is actually supported */
    379 static const int extra_ARB_compute_shader_es31[] = {
    380    EXT(ARB_compute_shader),
    381    EXTRA_API_ES31,
    382    EXTRA_END
    383 };
    384 
    385 static const int extra_ARB_shader_storage_buffer_object_es31[] = {
    386    EXT(ARB_shader_storage_buffer_object),
    387    EXTRA_API_ES31,
    388    EXTRA_END
    389 };
    390 
    391 static const int extra_ARB_shader_storage_buffer_object_and_geometry_shader[] = {
    392    EXTRA_EXT_SSBO_GS,
    393    EXTRA_END
    394 };
    395 
    396 static const int extra_ARB_shader_image_load_store_shader_storage_buffer_object_es31[] = {
    397    EXT(ARB_shader_image_load_store),
    398    EXT(ARB_shader_storage_buffer_object),
    399    EXTRA_API_ES31,
    400    EXTRA_END
    401 };
    402 
    403 static const int extra_ARB_framebuffer_no_attachments_and_geometry_shader[] = {
    404    EXTRA_EXT_FB_NO_ATTACH_GS,
    405    EXTRA_END
    406 };
    407 
    408 static const int extra_ARB_viewport_array_or_oes_geometry_shader[] = {
    409    EXT(ARB_viewport_array),
    410    EXTRA_EXT_ES_GS,
    411    EXTRA_END
    412 };
    413 
    414 static const int extra_ARB_viewport_array_or_oes_viewport_array[] = {
    415    EXT(ARB_viewport_array),
    416    EXT(OES_viewport_array),
    417    EXTRA_END
    418 };
    419 
    420 static const int extra_ARB_gpu_shader5_or_oes_geometry_shader[] = {
    421    EXT(ARB_gpu_shader5),
    422    EXTRA_EXT_ES_GS,
    423    EXTRA_END
    424 };
    425 
    426 static const int extra_ARB_gpu_shader5_or_OES_sample_variables[] = {
    427    EXT(ARB_gpu_shader5),
    428    EXT(OES_sample_variables),
    429    EXTRA_END
    430 };
    431 
    432 static const int extra_ES32[] = {
    433    EXT(ARB_ES3_2_compatibility),
    434    EXTRA_API_ES32,
    435    EXTRA_END
    436 };
    437 
    438 static const int extra_KHR_robustness_or_GL[] = {
    439    EXT(KHR_robustness),
    440    EXTRA_API_GL,
    441    EXTRA_API_GL_CORE,
    442    EXTRA_END
    443 };
    444 
    445 static const int extra_INTEL_conservative_rasterization[] = {
    446    EXT(INTEL_conservative_rasterization),
    447    EXTRA_END
    448 };
    449 
    450 EXTRA_EXT(ARB_texture_cube_map);
    451 EXTRA_EXT(EXT_texture_array);
    452 EXTRA_EXT(NV_fog_distance);
    453 EXTRA_EXT(EXT_texture_filter_anisotropic);
    454 EXTRA_EXT(NV_point_sprite);
    455 EXTRA_EXT(NV_texture_rectangle);
    456 EXTRA_EXT(EXT_stencil_two_side);
    457 EXTRA_EXT(EXT_depth_bounds_test);
    458 EXTRA_EXT(ARB_depth_clamp);
    459 EXTRA_EXT(ATI_fragment_shader);
    460 EXTRA_EXT(EXT_provoking_vertex);
    461 EXTRA_EXT(ARB_fragment_shader);
    462 EXTRA_EXT(ARB_fragment_program);
    463 EXTRA_EXT2(ARB_framebuffer_object, EXT_framebuffer_multisample);
    464 EXTRA_EXT(ARB_seamless_cube_map);
    465 EXTRA_EXT(ARB_sync);
    466 EXTRA_EXT(ARB_vertex_shader);
    467 EXTRA_EXT(EXT_transform_feedback);
    468 EXTRA_EXT(ARB_transform_feedback3);
    469 EXTRA_EXT(EXT_pixel_buffer_object);
    470 EXTRA_EXT(ARB_vertex_program);
    471 EXTRA_EXT2(NV_point_sprite, ARB_point_sprite);
    472 EXTRA_EXT2(ARB_vertex_program, ARB_fragment_program);
    473 EXTRA_EXT(ARB_color_buffer_float);
    474 EXTRA_EXT(EXT_framebuffer_sRGB);
    475 EXTRA_EXT(OES_EGL_image_external);
    476 EXTRA_EXT(ARB_blend_func_extended);
    477 EXTRA_EXT(ARB_uniform_buffer_object);
    478 EXTRA_EXT(ARB_timer_query);
    479 EXTRA_EXT2(ARB_texture_cube_map_array, OES_texture_cube_map_array);
    480 EXTRA_EXT(ARB_texture_buffer_range);
    481 EXTRA_EXT(ARB_texture_multisample);
    482 EXTRA_EXT(ARB_texture_gather);
    483 EXTRA_EXT(ARB_shader_atomic_counters);
    484 EXTRA_EXT(ARB_draw_indirect);
    485 EXTRA_EXT(ARB_shader_image_load_store);
    486 EXTRA_EXT(ARB_query_buffer_object);
    487 EXTRA_EXT2(ARB_transform_feedback3, ARB_gpu_shader5);
    488 EXTRA_EXT(INTEL_performance_query);
    489 EXTRA_EXT(ARB_explicit_uniform_location);
    490 EXTRA_EXT(ARB_clip_control);
    491 EXTRA_EXT(ARB_polygon_offset_clamp);
    492 EXTRA_EXT(ARB_framebuffer_no_attachments);
    493 EXTRA_EXT(ARB_tessellation_shader);
    494 EXTRA_EXT(ARB_shader_storage_buffer_object);
    495 EXTRA_EXT(ARB_indirect_parameters);
    496 EXTRA_EXT(ATI_meminfo);
    497 EXTRA_EXT(NVX_gpu_memory_info);
    498 EXTRA_EXT(ARB_cull_distance);
    499 EXTRA_EXT(EXT_window_rectangles);
    500 EXTRA_EXT(KHR_blend_equation_advanced_coherent);
    501 EXTRA_EXT(OES_primitive_bounding_box);
    502 EXTRA_EXT(ARB_compute_variable_group_size);
    503 EXTRA_EXT(KHR_robustness);
    504 EXTRA_EXT(ARB_sparse_buffer);
    505 
    506 static const int
    507 extra_ARB_color_buffer_float_or_glcore[] = {
    508    EXT(ARB_color_buffer_float),
    509    EXTRA_API_GL_CORE,
    510    EXTRA_END
    511 };
    512 
    513 static const int
    514 extra_NV_primitive_restart[] = {
    515    EXT(NV_primitive_restart),
    516    EXTRA_END
    517 };
    518 
    519 static const int extra_version_30[] = { EXTRA_VERSION_30, EXTRA_END };
    520 static const int extra_version_31[] = { EXTRA_VERSION_31, EXTRA_END };
    521 static const int extra_version_32[] = { EXTRA_VERSION_32, EXTRA_END };
    522 static const int extra_version_43[] = { EXTRA_VERSION_43, EXTRA_END };
    523 
    524 static const int extra_gl30_es3[] = {
    525     EXTRA_VERSION_30,
    526     EXTRA_API_ES3,
    527     EXTRA_END,
    528 };
    529 
    530 static const int extra_gl32_es3[] = {
    531     EXTRA_VERSION_32,
    532     EXTRA_API_ES3,
    533     EXTRA_END,
    534 };
    535 
    536 static const int extra_version_32_OES_geometry_shader[] = {
    537     EXTRA_VERSION_32,
    538     EXTRA_EXT_ES_GS,
    539     EXTRA_END
    540 };
    541 
    542 static const int extra_gl40_ARB_sample_shading[] = {
    543    EXTRA_VERSION_40,
    544    EXT(ARB_sample_shading),
    545    EXTRA_END
    546 };
    547 
    548 static const int
    549 extra_ARB_vertex_program_api_es2[] = {
    550    EXT(ARB_vertex_program),
    551    EXTRA_API_ES2,
    552    EXTRA_END
    553 };
    554 
    555 /* The ReadBuffer get token is valid under either full GL or under
    556  * GLES2 if the NV_read_buffer extension is available. */
    557 static const int
    558 extra_NV_read_buffer_api_gl[] = {
    559    EXTRA_API_ES2,
    560    EXTRA_API_GL,
    561    EXTRA_END
    562 };
    563 
    564 static const int extra_core_ARB_color_buffer_float_and_new_buffers[] = {
    565    EXTRA_API_GL_CORE,
    566    EXT(ARB_color_buffer_float),
    567    EXTRA_NEW_BUFFERS,
    568    EXTRA_END
    569 };
    570 
    571 static const int extra_EXT_shader_framebuffer_fetch[] = {
    572    EXTRA_API_ES2,
    573    EXTRA_API_ES3,
    574    EXT(MESA_shader_framebuffer_fetch),
    575    EXTRA_END
    576 };
    577 
    578 static const int extra_EXT_provoking_vertex_32[] = {
    579    EXTRA_EXT_PROVOKING_VERTEX_32,
    580    EXTRA_END
    581 };
    582 
    583 static const int extra_EXT_disjoint_timer_query[] = {
    584    EXTRA_API_ES2,
    585    EXTRA_API_ES3,
    586    EXT(EXT_disjoint_timer_query),
    587    EXTRA_END
    588 };
    589 
    590 
    591 /* This is the big table describing all the enums we accept in
    592  * glGet*v().  The table is partitioned into six parts: enums
    593  * understood by all GL APIs (OpenGL, GLES and GLES2), enums shared
    594  * between OpenGL and GLES, enums exclusive to GLES, etc for the
    595  * remaining combinations. To look up the enums valid in a given API
    596  * we will use a hash table specific to that API. These tables are in
    597  * turn generated at build time and included through get_hash.h.
    598  */
    599 
    600 #include "get_hash.h"
    601 
    602 /* All we need now is a way to look up the value struct from the enum.
    603  * The code generated by gcc for the old generated big switch
    604  * statement is a big, balanced, open coded if/else tree, essentially
    605  * an unrolled binary search.  It would be natural to sort the new
    606  * enum table and use bsearch(), but we will use a read-only hash
    607  * table instead.  bsearch() has a nice guaranteed worst case
    608  * performance, but we're also guaranteed to hit that worst case
    609  * (log2(n) iterations) for about half the enums.  Instead, using an
    610  * open addressing hash table, we can find the enum on the first try
    611  * for 80% of the enums, 1 collision for 10% and never more than 5
    612  * collisions for any enum (typical numbers).  And the code is very
    613  * simple, even though it feels a little magic. */
    614 
    615 /**
    616  * Handle irregular enums
    617  *
    618  * Some values don't conform to the "well-known type at context
    619  * pointer + offset" pattern, so we have this function to catch all
    620  * the corner cases.  Typically, it's a computed value or a one-off
    621  * pointer to a custom struct or something.
    622  *
    623  * In this case we can't return a pointer to the value, so we'll have
    624  * to use the temporary variable 'v' declared back in the calling
    625  * glGet*v() function to store the result.
    626  *
    627  * \param ctx the current context
    628  * \param d the struct value_desc that describes the enum
    629  * \param v pointer to the tmp declared in the calling glGet*v() function
    630  */
    631 static void
    632 find_custom_value(struct gl_context *ctx, const struct value_desc *d, union value *v)
    633 {
    634    struct gl_buffer_object **buffer_obj;
    635    struct gl_array_attributes *array;
    636    GLuint unit, *p;
    637 
    638    switch (d->pname) {
    639    case GL_MAJOR_VERSION:
    640       v->value_int = ctx->Version / 10;
    641       break;
    642    case GL_MINOR_VERSION:
    643       v->value_int = ctx->Version % 10;
    644       break;
    645 
    646    case GL_TEXTURE_1D:
    647    case GL_TEXTURE_2D:
    648    case GL_TEXTURE_3D:
    649    case GL_TEXTURE_CUBE_MAP:
    650    case GL_TEXTURE_RECTANGLE_NV:
    651    case GL_TEXTURE_EXTERNAL_OES:
    652       v->value_bool = _mesa_IsEnabled(d->pname);
    653       break;
    654 
    655    case GL_LINE_STIPPLE_PATTERN:
    656       /* This is the only GLushort, special case it here by promoting
    657        * to an int rather than introducing a new type. */
    658       v->value_int = ctx->Line.StipplePattern;
    659       break;
    660 
    661    case GL_CURRENT_RASTER_TEXTURE_COORDS:
    662       unit = ctx->Texture.CurrentUnit;
    663       v->value_float_4[0] = ctx->Current.RasterTexCoords[unit][0];
    664       v->value_float_4[1] = ctx->Current.RasterTexCoords[unit][1];
    665       v->value_float_4[2] = ctx->Current.RasterTexCoords[unit][2];
    666       v->value_float_4[3] = ctx->Current.RasterTexCoords[unit][3];
    667       break;
    668 
    669    case GL_CURRENT_TEXTURE_COORDS:
    670       unit = ctx->Texture.CurrentUnit;
    671       v->value_float_4[0] = ctx->Current.Attrib[VERT_ATTRIB_TEX0 + unit][0];
    672       v->value_float_4[1] = ctx->Current.Attrib[VERT_ATTRIB_TEX0 + unit][1];
    673       v->value_float_4[2] = ctx->Current.Attrib[VERT_ATTRIB_TEX0 + unit][2];
    674       v->value_float_4[3] = ctx->Current.Attrib[VERT_ATTRIB_TEX0 + unit][3];
    675       break;
    676 
    677    case GL_COLOR_WRITEMASK:
    678       v->value_int_4[0] = ctx->Color.ColorMask[0][RCOMP] ? 1 : 0;
    679       v->value_int_4[1] = ctx->Color.ColorMask[0][GCOMP] ? 1 : 0;
    680       v->value_int_4[2] = ctx->Color.ColorMask[0][BCOMP] ? 1 : 0;
    681       v->value_int_4[3] = ctx->Color.ColorMask[0][ACOMP] ? 1 : 0;
    682       break;
    683 
    684    case GL_EDGE_FLAG:
    685       v->value_bool = ctx->Current.Attrib[VERT_ATTRIB_EDGEFLAG][0] == 1.0F;
    686       break;
    687 
    688    case GL_READ_BUFFER:
    689       v->value_enum = ctx->ReadBuffer->ColorReadBuffer;
    690       break;
    691 
    692    case GL_MAP2_GRID_DOMAIN:
    693       v->value_float_4[0] = ctx->Eval.MapGrid2u1;
    694       v->value_float_4[1] = ctx->Eval.MapGrid2u2;
    695       v->value_float_4[2] = ctx->Eval.MapGrid2v1;
    696       v->value_float_4[3] = ctx->Eval.MapGrid2v2;
    697       break;
    698 
    699    case GL_TEXTURE_STACK_DEPTH:
    700       unit = ctx->Texture.CurrentUnit;
    701       v->value_int = ctx->TextureMatrixStack[unit].Depth + 1;
    702       break;
    703    case GL_TEXTURE_MATRIX:
    704       unit = ctx->Texture.CurrentUnit;
    705       v->value_matrix = ctx->TextureMatrixStack[unit].Top;
    706       break;
    707 
    708    case GL_TEXTURE_COORD_ARRAY:
    709    case GL_TEXTURE_COORD_ARRAY_SIZE:
    710    case GL_TEXTURE_COORD_ARRAY_TYPE:
    711    case GL_TEXTURE_COORD_ARRAY_STRIDE:
    712       array = &ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_TEX(ctx->Array.ActiveTexture)];
    713       v->value_int = *(GLuint *) ((char *) array + d->offset);
    714       break;
    715 
    716    case GL_ACTIVE_TEXTURE_ARB:
    717       v->value_int = GL_TEXTURE0_ARB + ctx->Texture.CurrentUnit;
    718       break;
    719    case GL_CLIENT_ACTIVE_TEXTURE_ARB:
    720       v->value_int = GL_TEXTURE0_ARB + ctx->Array.ActiveTexture;
    721       break;
    722 
    723    case GL_MODELVIEW_STACK_DEPTH:
    724    case GL_PROJECTION_STACK_DEPTH:
    725       v->value_int = *(GLint *) ((char *) ctx + d->offset) + 1;
    726       break;
    727 
    728    case GL_MAX_TEXTURE_SIZE:
    729    case GL_MAX_3D_TEXTURE_SIZE:
    730    case GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB:
    731       p = (GLuint *) ((char *) ctx + d->offset);
    732       v->value_int = 1 << (*p - 1);
    733       break;
    734 
    735    case GL_SCISSOR_BOX:
    736       v->value_int_4[0] = ctx->Scissor.ScissorArray[0].X;
    737       v->value_int_4[1] = ctx->Scissor.ScissorArray[0].Y;
    738       v->value_int_4[2] = ctx->Scissor.ScissorArray[0].Width;
    739       v->value_int_4[3] = ctx->Scissor.ScissorArray[0].Height;
    740       break;
    741 
    742    case GL_SCISSOR_TEST:
    743       v->value_bool = ctx->Scissor.EnableFlags & 1;
    744       break;
    745 
    746    case GL_LIST_INDEX:
    747       v->value_int =
    748          ctx->ListState.CurrentList ? ctx->ListState.CurrentList->Name : 0;
    749       break;
    750    case GL_LIST_MODE:
    751       if (!ctx->CompileFlag)
    752          v->value_enum = 0;
    753       else if (ctx->ExecuteFlag)
    754          v->value_enum = GL_COMPILE_AND_EXECUTE;
    755       else
    756          v->value_enum = GL_COMPILE;
    757       break;
    758 
    759    case GL_VIEWPORT:
    760       v->value_float_4[0] = ctx->ViewportArray[0].X;
    761       v->value_float_4[1] = ctx->ViewportArray[0].Y;
    762       v->value_float_4[2] = ctx->ViewportArray[0].Width;
    763       v->value_float_4[3] = ctx->ViewportArray[0].Height;
    764       break;
    765 
    766    case GL_DEPTH_RANGE:
    767       v->value_double_2[0] = ctx->ViewportArray[0].Near;
    768       v->value_double_2[1] = ctx->ViewportArray[0].Far;
    769       break;
    770 
    771    case GL_ACTIVE_STENCIL_FACE_EXT:
    772       v->value_enum = ctx->Stencil.ActiveFace ? GL_BACK : GL_FRONT;
    773       break;
    774 
    775    case GL_STENCIL_FAIL:
    776       v->value_enum = ctx->Stencil.FailFunc[ctx->Stencil.ActiveFace];
    777       break;
    778    case GL_STENCIL_FUNC:
    779       v->value_enum = ctx->Stencil.Function[ctx->Stencil.ActiveFace];
    780       break;
    781    case GL_STENCIL_PASS_DEPTH_FAIL:
    782       v->value_enum = ctx->Stencil.ZFailFunc[ctx->Stencil.ActiveFace];
    783       break;
    784    case GL_STENCIL_PASS_DEPTH_PASS:
    785       v->value_enum = ctx->Stencil.ZPassFunc[ctx->Stencil.ActiveFace];
    786       break;
    787    case GL_STENCIL_REF:
    788       v->value_int = _mesa_get_stencil_ref(ctx, ctx->Stencil.ActiveFace);
    789       break;
    790    case GL_STENCIL_BACK_REF:
    791       v->value_int = _mesa_get_stencil_ref(ctx, 1);
    792       break;
    793    case GL_STENCIL_VALUE_MASK:
    794       v->value_int = ctx->Stencil.ValueMask[ctx->Stencil.ActiveFace];
    795       break;
    796    case GL_STENCIL_WRITEMASK:
    797       v->value_int = ctx->Stencil.WriteMask[ctx->Stencil.ActiveFace];
    798       break;
    799 
    800    case GL_NUM_EXTENSIONS:
    801       v->value_int = _mesa_get_extension_count(ctx);
    802       break;
    803 
    804    case GL_IMPLEMENTATION_COLOR_READ_TYPE_OES:
    805       v->value_int = _mesa_get_color_read_type(ctx, NULL, "glGetIntegerv");
    806       break;
    807    case GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES:
    808       v->value_int = _mesa_get_color_read_format(ctx, NULL, "glGetIntegerv");
    809       break;
    810 
    811    case GL_CURRENT_MATRIX_STACK_DEPTH_ARB:
    812       v->value_int = ctx->CurrentStack->Depth + 1;
    813       break;
    814    case GL_CURRENT_MATRIX_ARB:
    815    case GL_TRANSPOSE_CURRENT_MATRIX_ARB:
    816       v->value_matrix = ctx->CurrentStack->Top;
    817       break;
    818 
    819    case GL_NUM_COMPRESSED_TEXTURE_FORMATS_ARB:
    820       v->value_int = _mesa_get_compressed_formats(ctx, NULL);
    821       break;
    822    case GL_COMPRESSED_TEXTURE_FORMATS_ARB:
    823       v->value_int_n.n =
    824          _mesa_get_compressed_formats(ctx, v->value_int_n.ints);
    825       assert(v->value_int_n.n <= (int) ARRAY_SIZE(v->value_int_n.ints));
    826       break;
    827 
    828    case GL_MAX_VARYING_FLOATS_ARB:
    829       v->value_int = ctx->Const.MaxVarying * 4;
    830       break;
    831 
    832    /* Various object names */
    833 
    834    case GL_TEXTURE_BINDING_1D:
    835    case GL_TEXTURE_BINDING_2D:
    836    case GL_TEXTURE_BINDING_3D:
    837    case GL_TEXTURE_BINDING_1D_ARRAY_EXT:
    838    case GL_TEXTURE_BINDING_2D_ARRAY_EXT:
    839    case GL_TEXTURE_BINDING_CUBE_MAP_ARB:
    840    case GL_TEXTURE_BINDING_RECTANGLE_NV:
    841    case GL_TEXTURE_BINDING_EXTERNAL_OES:
    842    case GL_TEXTURE_BINDING_CUBE_MAP_ARRAY:
    843    case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
    844    case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY:
    845       unit = ctx->Texture.CurrentUnit;
    846       v->value_int =
    847          ctx->Texture.Unit[unit].CurrentTex[d->offset]->Name;
    848       break;
    849 
    850    /* GL_EXT_external_objects */
    851    case GL_DRIVER_UUID_EXT:
    852       _mesa_get_driver_uuid(ctx, v->value_int_4);
    853       break;
    854    case GL_DEVICE_UUID_EXT:
    855       _mesa_get_device_uuid(ctx, v->value_int_4);
    856       break;
    857 
    858    /* GL_EXT_packed_float */
    859    case GL_RGBA_SIGNED_COMPONENTS_EXT:
    860       {
    861          /* Note: we only check the 0th color attachment. */
    862          const struct gl_renderbuffer *rb =
    863             ctx->DrawBuffer->_ColorDrawBuffers[0];
    864          if (rb && _mesa_is_format_signed(rb->Format)) {
    865             /* Issue 17 of GL_EXT_packed_float:  If a component (such as
    866              * alpha) has zero bits, the component should not be considered
    867              * signed and so the bit for the respective component should be
    868              * zeroed.
    869              */
    870             GLint r_bits =
    871                _mesa_get_format_bits(rb->Format, GL_RED_BITS);
    872             GLint g_bits =
    873                _mesa_get_format_bits(rb->Format, GL_GREEN_BITS);
    874             GLint b_bits =
    875                _mesa_get_format_bits(rb->Format, GL_BLUE_BITS);
    876             GLint a_bits =
    877                _mesa_get_format_bits(rb->Format, GL_ALPHA_BITS);
    878             GLint l_bits =
    879                _mesa_get_format_bits(rb->Format, GL_TEXTURE_LUMINANCE_SIZE);
    880             GLint i_bits =
    881                _mesa_get_format_bits(rb->Format, GL_TEXTURE_INTENSITY_SIZE);
    882 
    883             v->value_int_4[0] = r_bits + l_bits + i_bits > 0;
    884             v->value_int_4[1] = g_bits + l_bits + i_bits > 0;
    885             v->value_int_4[2] = b_bits + l_bits + i_bits > 0;
    886             v->value_int_4[3] = a_bits + i_bits > 0;
    887          }
    888          else {
    889             v->value_int_4[0] =
    890             v->value_int_4[1] =
    891             v->value_int_4[2] =
    892             v->value_int_4[3] = 0;
    893          }
    894       }
    895       break;
    896 
    897    /* GL_ARB_vertex_buffer_object */
    898    case GL_VERTEX_ARRAY_BUFFER_BINDING_ARB:
    899    case GL_NORMAL_ARRAY_BUFFER_BINDING_ARB:
    900    case GL_COLOR_ARRAY_BUFFER_BINDING_ARB:
    901    case GL_INDEX_ARRAY_BUFFER_BINDING_ARB:
    902    case GL_EDGE_FLAG_ARRAY_BUFFER_BINDING_ARB:
    903    case GL_SECONDARY_COLOR_ARRAY_BUFFER_BINDING_ARB:
    904    case GL_FOG_COORDINATE_ARRAY_BUFFER_BINDING_ARB:
    905       buffer_obj = (struct gl_buffer_object **)
    906          ((char *) ctx->Array.VAO + d->offset);
    907       v->value_int = (*buffer_obj)->Name;
    908       break;
    909    case GL_ARRAY_BUFFER_BINDING_ARB:
    910       v->value_int = ctx->Array.ArrayBufferObj->Name;
    911       break;
    912    case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING_ARB:
    913       v->value_int =
    914          ctx->Array.VAO->BufferBinding[VERT_ATTRIB_TEX(ctx->Array.ActiveTexture)].BufferObj->Name;
    915       break;
    916    case GL_ELEMENT_ARRAY_BUFFER_BINDING_ARB:
    917       v->value_int = ctx->Array.VAO->IndexBufferObj->Name;
    918       break;
    919 
    920    /* ARB_vertex_array_bgra */
    921    case GL_COLOR_ARRAY_SIZE:
    922       array = &ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_COLOR0];
    923       v->value_int = array->Format == GL_BGRA ? GL_BGRA : array->Size;
    924       break;
    925    case GL_SECONDARY_COLOR_ARRAY_SIZE:
    926       array = &ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_COLOR1];
    927       v->value_int = array->Format == GL_BGRA ? GL_BGRA : array->Size;
    928       break;
    929 
    930    /* ARB_copy_buffer */
    931    case GL_COPY_READ_BUFFER:
    932       v->value_int = ctx->CopyReadBuffer->Name;
    933       break;
    934    case GL_COPY_WRITE_BUFFER:
    935       v->value_int = ctx->CopyWriteBuffer->Name;
    936       break;
    937 
    938    case GL_PIXEL_PACK_BUFFER_BINDING_EXT:
    939       v->value_int = ctx->Pack.BufferObj->Name;
    940       break;
    941    case GL_PIXEL_UNPACK_BUFFER_BINDING_EXT:
    942       v->value_int = ctx->Unpack.BufferObj->Name;
    943       break;
    944    case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
    945       v->value_int = ctx->TransformFeedback.CurrentBuffer->Name;
    946       break;
    947    case GL_TRANSFORM_FEEDBACK_BUFFER_PAUSED:
    948       v->value_int = ctx->TransformFeedback.CurrentObject->Paused;
    949       break;
    950    case GL_TRANSFORM_FEEDBACK_BUFFER_ACTIVE:
    951       v->value_int = ctx->TransformFeedback.CurrentObject->Active;
    952       break;
    953    case GL_TRANSFORM_FEEDBACK_BINDING:
    954       v->value_int = ctx->TransformFeedback.CurrentObject->Name;
    955       break;
    956    case GL_CURRENT_PROGRAM:
    957       /* The Changelog of the ARB_separate_shader_objects spec says:
    958        *
    959        * 24 25 Jul 2011  pbrown  Remove the language erroneously deleting
    960        *                         CURRENT_PROGRAM.  In the EXT extension, this
    961        *                         token was aliased to ACTIVE_PROGRAM_EXT, and
    962        *                         was used to indicate the last program set by
    963        *                         either ActiveProgramEXT or UseProgram.  In
    964        *                         the ARB extension, the SSO active programs
    965        *                         are now program pipeline object state and
    966        *                         CURRENT_PROGRAM should still be used to query
    967        *                         the last program set by UseProgram (bug 7822).
    968        */
    969       v->value_int =
    970          ctx->Shader.ActiveProgram ? ctx->Shader.ActiveProgram->Name : 0;
    971       break;
    972    case GL_READ_FRAMEBUFFER_BINDING_EXT:
    973       v->value_int = ctx->ReadBuffer->Name;
    974       break;
    975    case GL_RENDERBUFFER_BINDING_EXT:
    976       v->value_int =
    977          ctx->CurrentRenderbuffer ? ctx->CurrentRenderbuffer->Name : 0;
    978       break;
    979    case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
    980       v->value_int = ctx->Array.VAO->BufferBinding[VERT_ATTRIB_POINT_SIZE].BufferObj->Name;
    981       break;
    982 
    983    case GL_FOG_COLOR:
    984       if (_mesa_get_clamp_fragment_color(ctx, ctx->DrawBuffer))
    985          COPY_4FV(v->value_float_4, ctx->Fog.Color);
    986       else
    987          COPY_4FV(v->value_float_4, ctx->Fog.ColorUnclamped);
    988       break;
    989    case GL_COLOR_CLEAR_VALUE:
    990       if (_mesa_get_clamp_fragment_color(ctx, ctx->DrawBuffer)) {
    991          v->value_float_4[0] = CLAMP(ctx->Color.ClearColor.f[0], 0.0F, 1.0F);
    992          v->value_float_4[1] = CLAMP(ctx->Color.ClearColor.f[1], 0.0F, 1.0F);
    993          v->value_float_4[2] = CLAMP(ctx->Color.ClearColor.f[2], 0.0F, 1.0F);
    994          v->value_float_4[3] = CLAMP(ctx->Color.ClearColor.f[3], 0.0F, 1.0F);
    995       } else
    996          COPY_4FV(v->value_float_4, ctx->Color.ClearColor.f);
    997       break;
    998    case GL_BLEND_COLOR_EXT:
    999       if (_mesa_get_clamp_fragment_color(ctx, ctx->DrawBuffer))
   1000          COPY_4FV(v->value_float_4, ctx->Color.BlendColor);
   1001       else
   1002          COPY_4FV(v->value_float_4, ctx->Color.BlendColorUnclamped);
   1003       break;
   1004    case GL_ALPHA_TEST_REF:
   1005       if (_mesa_get_clamp_fragment_color(ctx, ctx->DrawBuffer))
   1006          v->value_float = ctx->Color.AlphaRef;
   1007       else
   1008          v->value_float = ctx->Color.AlphaRefUnclamped;
   1009       break;
   1010    case GL_MAX_VERTEX_UNIFORM_VECTORS:
   1011       v->value_int = ctx->Const.Program[MESA_SHADER_VERTEX].MaxUniformComponents / 4;
   1012       break;
   1013 
   1014    case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
   1015       v->value_int = ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxUniformComponents / 4;
   1016       break;
   1017 
   1018    /* GL_ARB_texture_buffer_object */
   1019    case GL_TEXTURE_BUFFER_ARB:
   1020       v->value_int = ctx->Texture.BufferObject->Name;
   1021       break;
   1022    case GL_TEXTURE_BINDING_BUFFER_ARB:
   1023       unit = ctx->Texture.CurrentUnit;
   1024       v->value_int =
   1025          ctx->Texture.Unit[unit].CurrentTex[TEXTURE_BUFFER_INDEX]->Name;
   1026       break;
   1027    case GL_TEXTURE_BUFFER_DATA_STORE_BINDING_ARB:
   1028       {
   1029          struct gl_buffer_object *buf =
   1030             ctx->Texture.Unit[ctx->Texture.CurrentUnit]
   1031             .CurrentTex[TEXTURE_BUFFER_INDEX]->BufferObject;
   1032          v->value_int = buf ? buf->Name : 0;
   1033       }
   1034       break;
   1035    case GL_TEXTURE_BUFFER_FORMAT_ARB:
   1036       v->value_int = ctx->Texture.Unit[ctx->Texture.CurrentUnit]
   1037          .CurrentTex[TEXTURE_BUFFER_INDEX]->BufferObjectFormat;
   1038       break;
   1039 
   1040    /* GL_ARB_sampler_objects */
   1041    case GL_SAMPLER_BINDING:
   1042       {
   1043          struct gl_sampler_object *samp =
   1044             ctx->Texture.Unit[ctx->Texture.CurrentUnit].Sampler;
   1045          v->value_int = samp ? samp->Name : 0;
   1046       }
   1047       break;
   1048    /* GL_ARB_uniform_buffer_object */
   1049    case GL_UNIFORM_BUFFER_BINDING:
   1050       v->value_int = ctx->UniformBuffer->Name;
   1051       break;
   1052    /* GL_ARB_shader_storage_buffer_object */
   1053    case GL_SHADER_STORAGE_BUFFER_BINDING:
   1054       v->value_int = ctx->ShaderStorageBuffer->Name;
   1055       break;
   1056    /* GL_ARB_query_buffer_object */
   1057    case GL_QUERY_BUFFER_BINDING:
   1058       v->value_int = ctx->QueryBuffer->Name;
   1059       break;
   1060    /* GL_ARB_timer_query */
   1061    case GL_TIMESTAMP:
   1062       if (ctx->Driver.GetTimestamp) {
   1063          v->value_int64 = ctx->Driver.GetTimestamp(ctx);
   1064       }
   1065       else {
   1066          _mesa_problem(ctx, "driver doesn't implement GetTimestamp");
   1067       }
   1068       break;
   1069    /* GL_KHR_DEBUG */
   1070    case GL_DEBUG_OUTPUT:
   1071    case GL_DEBUG_OUTPUT_SYNCHRONOUS:
   1072    case GL_DEBUG_LOGGED_MESSAGES:
   1073    case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH:
   1074    case GL_DEBUG_GROUP_STACK_DEPTH:
   1075       v->value_int = _mesa_get_debug_state_int(ctx, d->pname);
   1076       break;
   1077    /* GL_ARB_shader_atomic_counters */
   1078    case GL_ATOMIC_COUNTER_BUFFER_BINDING:
   1079       if (ctx->AtomicBuffer) {
   1080          v->value_int = ctx->AtomicBuffer->Name;
   1081       } else {
   1082          v->value_int = 0;
   1083       }
   1084       break;
   1085    /* GL 4.3 */
   1086    case GL_NUM_SHADING_LANGUAGE_VERSIONS:
   1087       v->value_int = _mesa_get_shading_language_version(ctx, -1, NULL);
   1088       break;
   1089    /* GL_ARB_draw_indirect */
   1090    case GL_DRAW_INDIRECT_BUFFER_BINDING:
   1091       v->value_int = ctx->DrawIndirectBuffer->Name;
   1092       break;
   1093    /* GL_ARB_indirect_parameters */
   1094    case GL_PARAMETER_BUFFER_BINDING_ARB:
   1095       v->value_int = ctx->ParameterBuffer->Name;
   1096       break;
   1097    /* GL_ARB_separate_shader_objects */
   1098    case GL_PROGRAM_PIPELINE_BINDING:
   1099       if (ctx->Pipeline.Current) {
   1100          v->value_int = ctx->Pipeline.Current->Name;
   1101       } else {
   1102          v->value_int = 0;
   1103       }
   1104       break;
   1105    /* GL_ARB_compute_shader */
   1106    case GL_DISPATCH_INDIRECT_BUFFER_BINDING:
   1107       v->value_int = ctx->DispatchIndirectBuffer->Name;
   1108       break;
   1109    /* GL_ARB_multisample */
   1110    case GL_SAMPLES:
   1111       v->value_int = _mesa_geometric_samples(ctx->DrawBuffer);
   1112       break;
   1113    case GL_SAMPLE_BUFFERS:
   1114       v->value_int = _mesa_geometric_samples(ctx->DrawBuffer) > 0;
   1115       break;
   1116    /* GL_EXT_textrue_integer */
   1117    case GL_RGBA_INTEGER_MODE_EXT:
   1118       v->value_int = (ctx->DrawBuffer->_IntegerBuffers != 0);
   1119       break;
   1120    /* GL_ATI_meminfo & GL_NVX_gpu_memory_info */
   1121    case GL_VBO_FREE_MEMORY_ATI:
   1122    case GL_TEXTURE_FREE_MEMORY_ATI:
   1123    case GL_RENDERBUFFER_FREE_MEMORY_ATI:
   1124    case GL_GPU_MEMORY_INFO_DEDICATED_VIDMEM_NVX:
   1125    case GL_GPU_MEMORY_INFO_TOTAL_AVAILABLE_MEMORY_NVX:
   1126    case GL_GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX:
   1127    case GL_GPU_MEMORY_INFO_EVICTION_COUNT_NVX:
   1128    case GL_GPU_MEMORY_INFO_EVICTED_MEMORY_NVX:
   1129       {
   1130          struct gl_memory_info info;
   1131 
   1132          ctx->Driver.QueryMemoryInfo(ctx, &info);
   1133 
   1134          if (d->pname == GL_GPU_MEMORY_INFO_DEDICATED_VIDMEM_NVX)
   1135             v->value_int = info.total_device_memory;
   1136          else if (d->pname == GL_GPU_MEMORY_INFO_TOTAL_AVAILABLE_MEMORY_NVX)
   1137             v->value_int = info.total_device_memory +
   1138                            info.total_staging_memory;
   1139          else if (d->pname == GL_GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX)
   1140             v->value_int = info.avail_device_memory;
   1141          else if (d->pname == GL_GPU_MEMORY_INFO_EVICTION_COUNT_NVX)
   1142             v->value_int = info.nr_device_memory_evictions;
   1143          else if (d->pname == GL_GPU_MEMORY_INFO_EVICTED_MEMORY_NVX)
   1144             v->value_int = info.device_memory_evicted;
   1145          else {
   1146             /* ATI free memory enums.
   1147              *
   1148              * Since the GPU memory is (usually) page-table based, every two
   1149              * consecutive elements are equal. From the GL_ATI_meminfo
   1150              * specification:
   1151              *
   1152              *    "param[0] - total memory free in the pool
   1153              *     param[1] - largest available free block in the pool
   1154              *     param[2] - total auxiliary memory free
   1155              *     param[3] - largest auxiliary free block"
   1156              *
   1157              * All three (VBO, TEXTURE, RENDERBUFFER) queries return
   1158              * the same numbers here.
   1159              */
   1160             v->value_int_4[0] = info.avail_device_memory;
   1161             v->value_int_4[1] = info.avail_device_memory;
   1162             v->value_int_4[2] = info.avail_staging_memory;
   1163             v->value_int_4[3] = info.avail_staging_memory;
   1164          }
   1165       }
   1166       break;
   1167 
   1168    /* GL_ARB_get_program_binary */
   1169    case GL_PROGRAM_BINARY_FORMATS:
   1170       assert(ctx->Const.NumProgramBinaryFormats <= 1);
   1171       v->value_int_n.n = MIN2(ctx->Const.NumProgramBinaryFormats, 1);
   1172       if (ctx->Const.NumProgramBinaryFormats > 0) {
   1173          v->value_int_n.ints[0] = GL_PROGRAM_BINARY_FORMAT_MESA;
   1174       }
   1175       break;
   1176    /* GL_EXT_disjoint_timer_query */
   1177    case GL_GPU_DISJOINT_EXT:
   1178       {
   1179          simple_mtx_lock(&ctx->Shared->Mutex);
   1180          v->value_int = ctx->Shared->DisjointOperation;
   1181          /* Reset state as expected by the spec. */
   1182          ctx->Shared->DisjointOperation = false;
   1183          simple_mtx_unlock(&ctx->Shared->Mutex);
   1184       }
   1185       break;
   1186    }
   1187 }
   1188 
   1189 /**
   1190  * Check extra constraints on a struct value_desc descriptor
   1191  *
   1192  * If a struct value_desc has a non-NULL extra pointer, it means that
   1193  * there are a number of extra constraints to check or actions to
   1194  * perform.  The extras is just an integer array where each integer
   1195  * encode different constraints or actions.
   1196  *
   1197  * \param ctx current context
   1198  * \param func name of calling glGet*v() function for error reporting
   1199  * \param d the struct value_desc that has the extra constraints
   1200  *
   1201  * \return GL_FALSE if all of the constraints were not satisfied,
   1202  *     otherwise GL_TRUE.
   1203  */
   1204 static GLboolean
   1205 check_extra(struct gl_context *ctx, const char *func, const struct value_desc *d)
   1206 {
   1207    const GLuint version = ctx->Version;
   1208    GLboolean api_check = GL_FALSE;
   1209    GLboolean api_found = GL_FALSE;
   1210    const int *e;
   1211 
   1212    for (e = d->extra; *e != EXTRA_END; e++) {
   1213       switch (*e) {
   1214       case EXTRA_VERSION_30:
   1215          api_check = GL_TRUE;
   1216          if (version >= 30)
   1217             api_found = GL_TRUE;
   1218          break;
   1219       case EXTRA_VERSION_31:
   1220          api_check = GL_TRUE;
   1221          if (version >= 31)
   1222             api_found = GL_TRUE;
   1223          break;
   1224       case EXTRA_VERSION_32:
   1225          api_check = GL_TRUE;
   1226          if (version >= 32)
   1227             api_found = GL_TRUE;
   1228          break;
   1229       case EXTRA_VERSION_40:
   1230          api_check = GL_TRUE;
   1231          if (version >= 40)
   1232             api_found = GL_TRUE;
   1233          break;
   1234       case EXTRA_VERSION_43:
   1235          api_check = TRUE;
   1236          if (_mesa_is_desktop_gl(ctx) && version >= 43)
   1237             api_found = GL_TRUE;
   1238          break;
   1239       case EXTRA_NEW_FRAG_CLAMP:
   1240          if (ctx->NewState & (_NEW_BUFFERS | _NEW_FRAG_CLAMP))
   1241             _mesa_update_state(ctx);
   1242          break;
   1243       case EXTRA_API_ES2:
   1244          api_check = GL_TRUE;
   1245          if (ctx->API == API_OPENGLES2)
   1246             api_found = GL_TRUE;
   1247          break;
   1248       case EXTRA_API_ES3:
   1249          api_check = GL_TRUE;
   1250          if (_mesa_is_gles3(ctx))
   1251             api_found = GL_TRUE;
   1252          break;
   1253       case EXTRA_API_ES31:
   1254          api_check = GL_TRUE;
   1255          if (_mesa_is_gles31(ctx))
   1256             api_found = GL_TRUE;
   1257          break;
   1258       case EXTRA_API_ES32:
   1259          api_check = GL_TRUE;
   1260          if (_mesa_is_gles32(ctx))
   1261             api_found = GL_TRUE;
   1262          break;
   1263       case EXTRA_API_GL:
   1264          api_check = GL_TRUE;
   1265          if (_mesa_is_desktop_gl(ctx))
   1266             api_found = GL_TRUE;
   1267          break;
   1268       case EXTRA_API_GL_CORE:
   1269          api_check = GL_TRUE;
   1270          if (ctx->API == API_OPENGL_CORE)
   1271             api_found = GL_TRUE;
   1272          break;
   1273       case EXTRA_NEW_BUFFERS:
   1274          if (ctx->NewState & _NEW_BUFFERS)
   1275             _mesa_update_state(ctx);
   1276          break;
   1277       case EXTRA_FLUSH_CURRENT:
   1278          FLUSH_CURRENT(ctx, 0);
   1279          break;
   1280       case EXTRA_VALID_DRAW_BUFFER:
   1281          if (d->pname - GL_DRAW_BUFFER0_ARB >= ctx->Const.MaxDrawBuffers) {
   1282             _mesa_error(ctx, GL_INVALID_OPERATION, "%s(draw buffer %u)",
   1283                         func, d->pname - GL_DRAW_BUFFER0_ARB);
   1284             return GL_FALSE;
   1285          }
   1286          break;
   1287       case EXTRA_VALID_TEXTURE_UNIT:
   1288          if (ctx->Texture.CurrentUnit >= ctx->Const.MaxTextureCoordUnits) {
   1289             _mesa_error(ctx, GL_INVALID_OPERATION, "%s(texture %u)",
   1290                         func, ctx->Texture.CurrentUnit);
   1291             return GL_FALSE;
   1292          }
   1293          break;
   1294       case EXTRA_VALID_CLIP_DISTANCE:
   1295          if (d->pname - GL_CLIP_DISTANCE0 >= ctx->Const.MaxClipPlanes) {
   1296             _mesa_error(ctx, GL_INVALID_ENUM, "%s(clip distance %u)",
   1297                         func, d->pname - GL_CLIP_DISTANCE0);
   1298             return GL_FALSE;
   1299          }
   1300          break;
   1301       case EXTRA_GLSL_130:
   1302          api_check = GL_TRUE;
   1303          if (ctx->Const.GLSLVersion >= 130)
   1304             api_found = GL_TRUE;
   1305          break;
   1306       case EXTRA_EXT_UBO_GS:
   1307          api_check = GL_TRUE;
   1308          if (ctx->Extensions.ARB_uniform_buffer_object &&
   1309             _mesa_has_geometry_shaders(ctx))
   1310             api_found = GL_TRUE;
   1311          break;
   1312       case EXTRA_EXT_ATOMICS_GS:
   1313          api_check = GL_TRUE;
   1314          if (ctx->Extensions.ARB_shader_atomic_counters &&
   1315             _mesa_has_geometry_shaders(ctx))
   1316             api_found = GL_TRUE;
   1317          break;
   1318       case EXTRA_EXT_SHADER_IMAGE_GS:
   1319          api_check = GL_TRUE;
   1320          if (ctx->Extensions.ARB_shader_image_load_store &&
   1321             _mesa_has_geometry_shaders(ctx))
   1322             api_found = GL_TRUE;
   1323          break;
   1324       case EXTRA_EXT_ATOMICS_TESS:
   1325          api_check = GL_TRUE;
   1326          api_found = ctx->Extensions.ARB_shader_atomic_counters &&
   1327                      _mesa_has_tessellation(ctx);
   1328          break;
   1329       case EXTRA_EXT_SHADER_IMAGE_TESS:
   1330          api_check = GL_TRUE;
   1331          api_found = ctx->Extensions.ARB_shader_image_load_store &&
   1332                      _mesa_has_tessellation(ctx);
   1333          break;
   1334       case EXTRA_EXT_SSBO_GS:
   1335          api_check = GL_TRUE;
   1336          if (ctx->Extensions.ARB_shader_storage_buffer_object &&
   1337             _mesa_has_geometry_shaders(ctx))
   1338             api_found = GL_TRUE;
   1339          break;
   1340       case EXTRA_EXT_FB_NO_ATTACH_GS:
   1341          api_check = GL_TRUE;
   1342          if (ctx->Extensions.ARB_framebuffer_no_attachments &&
   1343             (_mesa_is_desktop_gl(ctx) ||
   1344             _mesa_has_OES_geometry_shader(ctx)))
   1345             api_found = GL_TRUE;
   1346          break;
   1347       case EXTRA_EXT_ES_GS:
   1348          api_check = GL_TRUE;
   1349          if (_mesa_has_OES_geometry_shader(ctx))
   1350             api_found = GL_TRUE;
   1351          break;
   1352       case EXTRA_EXT_PROVOKING_VERTEX_32:
   1353          api_check = TRUE;
   1354          if (ctx->API == API_OPENGL_COMPAT || version == 32)
   1355             api_found = ctx->Extensions.EXT_provoking_vertex;
   1356          break;
   1357       case EXTRA_END:
   1358          break;
   1359       default: /* *e is a offset into the extension struct */
   1360          api_check = GL_TRUE;
   1361          if (*(GLboolean *) ((char *) &ctx->Extensions + *e))
   1362             api_found = GL_TRUE;
   1363          break;
   1364       }
   1365    }
   1366 
   1367    if (api_check && !api_found) {
   1368       _mesa_error(ctx, GL_INVALID_ENUM, "%s(pname=%s)", func,
   1369                   _mesa_enum_to_string(d->pname));
   1370       return GL_FALSE;
   1371    }
   1372 
   1373    return GL_TRUE;
   1374 }
   1375 
   1376 static const struct value_desc error_value =
   1377    { 0, 0, TYPE_INVALID, NO_OFFSET, NO_EXTRA };
   1378 
   1379 /**
   1380  * Find the struct value_desc corresponding to the enum 'pname'.
   1381  *
   1382  * We hash the enum value to get an index into the 'table' array,
   1383  * which holds the index in the 'values' array of struct value_desc.
   1384  * Once we've found the entry, we do the extra checks, if any, then
   1385  * look up the value and return a pointer to it.
   1386  *
   1387  * If the value has to be computed (for example, it's the result of a
   1388  * function call or we need to add 1 to it), we use the tmp 'v' to
   1389  * store the result.
   1390  *
   1391  * \param func name of glGet*v() func for error reporting
   1392  * \param pname the enum value we're looking up
   1393  * \param p is were we return the pointer to the value
   1394  * \param v a tmp union value variable in the calling glGet*v() function
   1395  *
   1396  * \return the struct value_desc corresponding to the enum or a struct
   1397  *     value_desc of TYPE_INVALID if not found.  This lets the calling
   1398  *     glGet*v() function jump right into a switch statement and
   1399  *     handle errors there instead of having to check for NULL.
   1400  */
   1401 static const struct value_desc *
   1402 find_value(const char *func, GLenum pname, void **p, union value *v)
   1403 {
   1404    GET_CURRENT_CONTEXT(ctx);
   1405    struct gl_texture_unit *unit;
   1406    int mask, hash;
   1407    const struct value_desc *d;
   1408    int api;
   1409 
   1410    api = ctx->API;
   1411    /* We index into the table_set[] list of per-API hash tables using the API's
   1412     * value in the gl_api enum. Since GLES 3 doesn't have an API_OPENGL* enum
   1413     * value since it's compatible with GLES2 its entry in table_set[] is at the
   1414     * end.
   1415     */
   1416    STATIC_ASSERT(ARRAY_SIZE(table_set) == API_OPENGL_LAST + 4);
   1417    if (ctx->API == API_OPENGLES2) {
   1418       if (ctx->Version >= 32)
   1419          api = API_OPENGL_LAST + 3;
   1420       else if (ctx->Version >= 31)
   1421          api = API_OPENGL_LAST + 2;
   1422       else if (ctx->Version >= 30)
   1423          api = API_OPENGL_LAST + 1;
   1424    }
   1425    mask = ARRAY_SIZE(table(api)) - 1;
   1426    hash = (pname * prime_factor);
   1427    while (1) {
   1428       int idx = table(api)[hash & mask];
   1429 
   1430       /* If the enum isn't valid, the hash walk ends with index 0,
   1431        * pointing to the first entry of values[] which doesn't hold
   1432        * any valid enum. */
   1433       if (unlikely(idx == 0)) {
   1434          _mesa_error(ctx, GL_INVALID_ENUM, "%s(pname=%s)", func,
   1435                _mesa_enum_to_string(pname));
   1436          return &error_value;
   1437       }
   1438 
   1439       d = &values[idx];
   1440       if (likely(d->pname == pname))
   1441          break;
   1442 
   1443       hash += prime_step;
   1444    }
   1445 
   1446    if (unlikely(d->extra && !check_extra(ctx, func, d)))
   1447       return &error_value;
   1448 
   1449    switch (d->location) {
   1450    case LOC_BUFFER:
   1451       *p = ((char *) ctx->DrawBuffer + d->offset);
   1452       return d;
   1453    case LOC_CONTEXT:
   1454       *p = ((char *) ctx + d->offset);
   1455       return d;
   1456    case LOC_ARRAY:
   1457       *p = ((char *) ctx->Array.VAO + d->offset);
   1458       return d;
   1459    case LOC_TEXUNIT:
   1460       unit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
   1461       *p = ((char *) unit + d->offset);
   1462       return d;
   1463    case LOC_CUSTOM:
   1464       find_custom_value(ctx, d, v);
   1465       *p = v;
   1466       return d;
   1467    default:
   1468       assert(0);
   1469       break;
   1470    }
   1471 
   1472    /* silence warning */
   1473    return &error_value;
   1474 }
   1475 
   1476 static const int transpose[] = {
   1477    0, 4,  8, 12,
   1478    1, 5,  9, 13,
   1479    2, 6, 10, 14,
   1480    3, 7, 11, 15
   1481 };
   1482 
   1483 static GLsizei
   1484 get_value_size(enum value_type type, const union value *v)
   1485 {
   1486    switch (type) {
   1487    case TYPE_INVALID:
   1488       return 0;
   1489    case TYPE_CONST:
   1490    case TYPE_UINT:
   1491    case TYPE_INT:
   1492       return sizeof(GLint);
   1493    case TYPE_INT_2:
   1494    case TYPE_UINT_2:
   1495       return sizeof(GLint) * 2;
   1496    case TYPE_INT_3:
   1497    case TYPE_UINT_3:
   1498       return sizeof(GLint) * 3;
   1499    case TYPE_INT_4:
   1500    case TYPE_UINT_4:
   1501       return sizeof(GLint) * 4;
   1502    case TYPE_INT_N:
   1503       return sizeof(GLint) * v->value_int_n.n;
   1504    case TYPE_INT64:
   1505       return sizeof(GLint64);
   1506       break;
   1507    case TYPE_ENUM:
   1508       return sizeof(GLenum);
   1509    case TYPE_ENUM_2:
   1510       return sizeof(GLenum) * 2;
   1511    case TYPE_BOOLEAN:
   1512       return sizeof(GLboolean);
   1513    case TYPE_BIT_0:
   1514    case TYPE_BIT_1:
   1515    case TYPE_BIT_2:
   1516    case TYPE_BIT_3:
   1517    case TYPE_BIT_4:
   1518    case TYPE_BIT_5:
   1519    case TYPE_BIT_6:
   1520    case TYPE_BIT_7:
   1521       return 1;
   1522    case TYPE_FLOAT:
   1523    case TYPE_FLOATN:
   1524       return sizeof(GLfloat);
   1525    case TYPE_FLOAT_2:
   1526    case TYPE_FLOATN_2:
   1527       return sizeof(GLfloat) * 2;
   1528    case TYPE_FLOAT_3:
   1529    case TYPE_FLOATN_3:
   1530       return sizeof(GLfloat) * 3;
   1531    case TYPE_FLOAT_4:
   1532    case TYPE_FLOATN_4:
   1533       return sizeof(GLfloat) * 4;
   1534    case TYPE_FLOAT_8:
   1535       return sizeof(GLfloat) * 8;
   1536    case TYPE_DOUBLEN:
   1537       return sizeof(GLdouble);
   1538    case TYPE_DOUBLEN_2:
   1539       return sizeof(GLdouble) * 2;
   1540    case TYPE_MATRIX:
   1541       return sizeof (GLfloat) * 16;
   1542    case TYPE_MATRIX_T:
   1543       return sizeof (GLfloat) * 16;
   1544    default:
   1545       return -1;
   1546    }
   1547 }
   1548 
   1549 void GLAPIENTRY
   1550 _mesa_GetBooleanv(GLenum pname, GLboolean *params)
   1551 {
   1552    const struct value_desc *d;
   1553    union value v;
   1554    GLmatrix *m;
   1555    int shift, i;
   1556    void *p;
   1557 
   1558    d = find_value("glGetBooleanv", pname, &p, &v);
   1559    switch (d->type) {
   1560    case TYPE_INVALID:
   1561       break;
   1562    case TYPE_CONST:
   1563       params[0] = INT_TO_BOOLEAN(d->offset);
   1564       break;
   1565 
   1566    case TYPE_FLOAT_8:
   1567       params[7] = FLOAT_TO_BOOLEAN(((GLfloat *) p)[7]);
   1568       params[6] = FLOAT_TO_BOOLEAN(((GLfloat *) p)[6]);
   1569       params[5] = FLOAT_TO_BOOLEAN(((GLfloat *) p)[5]);
   1570       params[4] = FLOAT_TO_BOOLEAN(((GLfloat *) p)[4]);
   1571    case TYPE_FLOAT_4:
   1572    case TYPE_FLOATN_4:
   1573       params[3] = FLOAT_TO_BOOLEAN(((GLfloat *) p)[3]);
   1574    case TYPE_FLOAT_3:
   1575    case TYPE_FLOATN_3:
   1576       params[2] = FLOAT_TO_BOOLEAN(((GLfloat *) p)[2]);
   1577    case TYPE_FLOAT_2:
   1578    case TYPE_FLOATN_2:
   1579       params[1] = FLOAT_TO_BOOLEAN(((GLfloat *) p)[1]);
   1580    case TYPE_FLOAT:
   1581    case TYPE_FLOATN:
   1582       params[0] = FLOAT_TO_BOOLEAN(((GLfloat *) p)[0]);
   1583       break;
   1584 
   1585    case TYPE_DOUBLEN_2:
   1586       params[1] = FLOAT_TO_BOOLEAN(((GLdouble *) p)[1]);
   1587    case TYPE_DOUBLEN:
   1588       params[0] = FLOAT_TO_BOOLEAN(((GLdouble *) p)[0]);
   1589       break;
   1590 
   1591    case TYPE_INT_4:
   1592    case TYPE_UINT_4:
   1593       params[3] = INT_TO_BOOLEAN(((GLint *) p)[3]);
   1594    case TYPE_INT_3:
   1595    case TYPE_UINT_3:
   1596       params[2] = INT_TO_BOOLEAN(((GLint *) p)[2]);
   1597    case TYPE_INT_2:
   1598    case TYPE_UINT_2:
   1599    case TYPE_ENUM_2:
   1600       params[1] = INT_TO_BOOLEAN(((GLint *) p)[1]);
   1601    case TYPE_INT:
   1602    case TYPE_UINT:
   1603    case TYPE_ENUM:
   1604       params[0] = INT_TO_BOOLEAN(((GLint *) p)[0]);
   1605       break;
   1606 
   1607    case TYPE_INT_N:
   1608       for (i = 0; i < v.value_int_n.n; i++)
   1609          params[i] = INT_TO_BOOLEAN(v.value_int_n.ints[i]);
   1610       break;
   1611 
   1612    case TYPE_INT64:
   1613       params[0] = INT64_TO_BOOLEAN(((GLint64 *) p)[0]);
   1614       break;
   1615 
   1616    case TYPE_BOOLEAN:
   1617       params[0] = ((GLboolean*) p)[0];
   1618       break;
   1619 
   1620    case TYPE_MATRIX:
   1621       m = *(GLmatrix **) p;
   1622       for (i = 0; i < 16; i++)
   1623          params[i] = FLOAT_TO_BOOLEAN(m->m[i]);
   1624       break;
   1625 
   1626    case TYPE_MATRIX_T:
   1627       m = *(GLmatrix **) p;
   1628       for (i = 0; i < 16; i++)
   1629          params[i] = FLOAT_TO_BOOLEAN(m->m[transpose[i]]);
   1630       break;
   1631 
   1632    case TYPE_BIT_0:
   1633    case TYPE_BIT_1:
   1634    case TYPE_BIT_2:
   1635    case TYPE_BIT_3:
   1636    case TYPE_BIT_4:
   1637    case TYPE_BIT_5:
   1638    case TYPE_BIT_6:
   1639    case TYPE_BIT_7:
   1640       shift = d->type - TYPE_BIT_0;
   1641       params[0] = (*(GLbitfield *) p >> shift) & 1;
   1642       break;
   1643    }
   1644 }
   1645 
   1646 void GLAPIENTRY
   1647 _mesa_GetFloatv(GLenum pname, GLfloat *params)
   1648 {
   1649    const struct value_desc *d;
   1650    union value v;
   1651    GLmatrix *m;
   1652    int shift, i;
   1653    void *p;
   1654 
   1655    d = find_value("glGetFloatv", pname, &p, &v);
   1656    switch (d->type) {
   1657    case TYPE_INVALID:
   1658       break;
   1659    case TYPE_CONST:
   1660       params[0] = (GLfloat) d->offset;
   1661       break;
   1662 
   1663    case TYPE_FLOAT_8:
   1664       params[7] = ((GLfloat *) p)[7];
   1665       params[6] = ((GLfloat *) p)[6];
   1666       params[5] = ((GLfloat *) p)[5];
   1667       params[4] = ((GLfloat *) p)[4];
   1668    case TYPE_FLOAT_4:
   1669    case TYPE_FLOATN_4:
   1670       params[3] = ((GLfloat *) p)[3];
   1671    case TYPE_FLOAT_3:
   1672    case TYPE_FLOATN_3:
   1673       params[2] = ((GLfloat *) p)[2];
   1674    case TYPE_FLOAT_2:
   1675    case TYPE_FLOATN_2:
   1676       params[1] = ((GLfloat *) p)[1];
   1677    case TYPE_FLOAT:
   1678    case TYPE_FLOATN:
   1679       params[0] = ((GLfloat *) p)[0];
   1680       break;
   1681 
   1682    case TYPE_DOUBLEN_2:
   1683       params[1] = (GLfloat) (((GLdouble *) p)[1]);
   1684    case TYPE_DOUBLEN:
   1685       params[0] = (GLfloat) (((GLdouble *) p)[0]);
   1686       break;
   1687 
   1688    case TYPE_INT_4:
   1689       params[3] = (GLfloat) (((GLint *) p)[3]);
   1690    case TYPE_INT_3:
   1691       params[2] = (GLfloat) (((GLint *) p)[2]);
   1692    case TYPE_INT_2:
   1693    case TYPE_ENUM_2:
   1694       params[1] = (GLfloat) (((GLint *) p)[1]);
   1695    case TYPE_INT:
   1696    case TYPE_ENUM:
   1697       params[0] = (GLfloat) (((GLint *) p)[0]);
   1698       break;
   1699 
   1700    case TYPE_INT_N:
   1701       for (i = 0; i < v.value_int_n.n; i++)
   1702          params[i] = (GLfloat) v.value_int_n.ints[i];
   1703       break;
   1704 
   1705    case TYPE_UINT_4:
   1706       params[3] = (GLfloat) (((GLuint *) p)[3]);
   1707    case TYPE_UINT_3:
   1708       params[2] = (GLfloat) (((GLuint *) p)[2]);
   1709    case TYPE_UINT_2:
   1710       params[1] = (GLfloat) (((GLuint *) p)[1]);
   1711    case TYPE_UINT:
   1712       params[0] = (GLfloat) (((GLuint *) p)[0]);
   1713       break;
   1714 
   1715    case TYPE_INT64:
   1716       params[0] = (GLfloat) (((GLint64 *) p)[0]);
   1717       break;
   1718 
   1719    case TYPE_BOOLEAN:
   1720       params[0] = BOOLEAN_TO_FLOAT(*(GLboolean*) p);
   1721       break;
   1722 
   1723    case TYPE_MATRIX:
   1724       m = *(GLmatrix **) p;
   1725       for (i = 0; i < 16; i++)
   1726          params[i] = m->m[i];
   1727       break;
   1728 
   1729    case TYPE_MATRIX_T:
   1730       m = *(GLmatrix **) p;
   1731       for (i = 0; i < 16; i++)
   1732          params[i] = m->m[transpose[i]];
   1733       break;
   1734 
   1735    case TYPE_BIT_0:
   1736    case TYPE_BIT_1:
   1737    case TYPE_BIT_2:
   1738    case TYPE_BIT_3:
   1739    case TYPE_BIT_4:
   1740    case TYPE_BIT_5:
   1741    case TYPE_BIT_6:
   1742    case TYPE_BIT_7:
   1743       shift = d->type - TYPE_BIT_0;
   1744       params[0] = BOOLEAN_TO_FLOAT((*(GLbitfield *) p >> shift) & 1);
   1745       break;
   1746    }
   1747 }
   1748 
   1749 void GLAPIENTRY
   1750 _mesa_GetIntegerv(GLenum pname, GLint *params)
   1751 {
   1752    const struct value_desc *d;
   1753    union value v;
   1754    GLmatrix *m;
   1755    int shift, i;
   1756    void *p;
   1757 
   1758    d = find_value("glGetIntegerv", pname, &p, &v);
   1759    switch (d->type) {
   1760    case TYPE_INVALID:
   1761       break;
   1762    case TYPE_CONST:
   1763       params[0] = d->offset;
   1764       break;
   1765 
   1766    case TYPE_FLOAT_8:
   1767       params[7] = IROUND(((GLfloat *) p)[7]);
   1768       params[6] = IROUND(((GLfloat *) p)[6]);
   1769       params[5] = IROUND(((GLfloat *) p)[5]);
   1770       params[4] = IROUND(((GLfloat *) p)[4]);
   1771    case TYPE_FLOAT_4:
   1772       params[3] = IROUND(((GLfloat *) p)[3]);
   1773    case TYPE_FLOAT_3:
   1774       params[2] = IROUND(((GLfloat *) p)[2]);
   1775    case TYPE_FLOAT_2:
   1776       params[1] = IROUND(((GLfloat *) p)[1]);
   1777    case TYPE_FLOAT:
   1778       params[0] = IROUND(((GLfloat *) p)[0]);
   1779       break;
   1780 
   1781    case TYPE_FLOATN_4:
   1782       params[3] = FLOAT_TO_INT(((GLfloat *) p)[3]);
   1783    case TYPE_FLOATN_3:
   1784       params[2] = FLOAT_TO_INT(((GLfloat *) p)[2]);
   1785    case TYPE_FLOATN_2:
   1786       params[1] = FLOAT_TO_INT(((GLfloat *) p)[1]);
   1787    case TYPE_FLOATN:
   1788       params[0] = FLOAT_TO_INT(((GLfloat *) p)[0]);
   1789       break;
   1790 
   1791    case TYPE_DOUBLEN_2:
   1792       params[1] = FLOAT_TO_INT(((GLdouble *) p)[1]);
   1793    case TYPE_DOUBLEN:
   1794       params[0] = FLOAT_TO_INT(((GLdouble *) p)[0]);
   1795       break;
   1796 
   1797    case TYPE_INT_4:
   1798    case TYPE_UINT_4:
   1799       params[3] = ((GLint *) p)[3];
   1800    case TYPE_INT_3:
   1801    case TYPE_UINT_3:
   1802       params[2] = ((GLint *) p)[2];
   1803    case TYPE_INT_2:
   1804    case TYPE_UINT_2:
   1805    case TYPE_ENUM_2:
   1806       params[1] = ((GLint *) p)[1];
   1807    case TYPE_INT:
   1808    case TYPE_UINT:
   1809    case TYPE_ENUM:
   1810       params[0] = ((GLint *) p)[0];
   1811       break;
   1812 
   1813    case TYPE_INT_N:
   1814       for (i = 0; i < v.value_int_n.n; i++)
   1815          params[i] = v.value_int_n.ints[i];
   1816       break;
   1817 
   1818    case TYPE_INT64:
   1819       params[0] = INT64_TO_INT(((GLint64 *) p)[0]);
   1820       break;
   1821 
   1822    case TYPE_BOOLEAN:
   1823       params[0] = BOOLEAN_TO_INT(*(GLboolean*) p);
   1824       break;
   1825 
   1826    case TYPE_MATRIX:
   1827       m = *(GLmatrix **) p;
   1828       for (i = 0; i < 16; i++)
   1829          params[i] = FLOAT_TO_INT(m->m[i]);
   1830       break;
   1831 
   1832    case TYPE_MATRIX_T:
   1833       m = *(GLmatrix **) p;
   1834       for (i = 0; i < 16; i++)
   1835          params[i] = FLOAT_TO_INT(m->m[transpose[i]]);
   1836       break;
   1837 
   1838    case TYPE_BIT_0:
   1839    case TYPE_BIT_1:
   1840    case TYPE_BIT_2:
   1841    case TYPE_BIT_3:
   1842    case TYPE_BIT_4:
   1843    case TYPE_BIT_5:
   1844    case TYPE_BIT_6:
   1845    case TYPE_BIT_7:
   1846       shift = d->type - TYPE_BIT_0;
   1847       params[0] = (*(GLbitfield *) p >> shift) & 1;
   1848       break;
   1849    }
   1850 }
   1851 
   1852 void GLAPIENTRY
   1853 _mesa_GetInteger64v(GLenum pname, GLint64 *params)
   1854 {
   1855    const struct value_desc *d;
   1856    union value v;
   1857    GLmatrix *m;
   1858    int shift, i;
   1859    void *p;
   1860 
   1861    d = find_value("glGetInteger64v", pname, &p, &v);
   1862    switch (d->type) {
   1863    case TYPE_INVALID:
   1864       break;
   1865    case TYPE_CONST:
   1866       params[0] = d->offset;
   1867       break;
   1868 
   1869    case TYPE_FLOAT_8:
   1870       params[7] = IROUND64(((GLfloat *) p)[7]);
   1871       params[6] = IROUND64(((GLfloat *) p)[6]);
   1872       params[5] = IROUND64(((GLfloat *) p)[5]);
   1873       params[4] = IROUND64(((GLfloat *) p)[4]);
   1874    case TYPE_FLOAT_4:
   1875       params[3] = IROUND64(((GLfloat *) p)[3]);
   1876    case TYPE_FLOAT_3:
   1877       params[2] = IROUND64(((GLfloat *) p)[2]);
   1878    case TYPE_FLOAT_2:
   1879       params[1] = IROUND64(((GLfloat *) p)[1]);
   1880    case TYPE_FLOAT:
   1881       params[0] = IROUND64(((GLfloat *) p)[0]);
   1882       break;
   1883 
   1884    case TYPE_FLOATN_4:
   1885       params[3] = FLOAT_TO_INT(((GLfloat *) p)[3]);
   1886    case TYPE_FLOATN_3:
   1887       params[2] = FLOAT_TO_INT(((GLfloat *) p)[2]);
   1888    case TYPE_FLOATN_2:
   1889       params[1] = FLOAT_TO_INT(((GLfloat *) p)[1]);
   1890    case TYPE_FLOATN:
   1891       params[0] = FLOAT_TO_INT(((GLfloat *) p)[0]);
   1892       break;
   1893 
   1894    case TYPE_DOUBLEN_2:
   1895       params[1] = FLOAT_TO_INT(((GLdouble *) p)[1]);
   1896    case TYPE_DOUBLEN:
   1897       params[0] = FLOAT_TO_INT(((GLdouble *) p)[0]);
   1898       break;
   1899 
   1900    case TYPE_INT_4:
   1901       params[3] = ((GLint *) p)[3];
   1902    case TYPE_INT_3:
   1903       params[2] = ((GLint *) p)[2];
   1904    case TYPE_INT_2:
   1905    case TYPE_ENUM_2:
   1906       params[1] = ((GLint *) p)[1];
   1907    case TYPE_INT:
   1908    case TYPE_ENUM:
   1909       params[0] = ((GLint *) p)[0];
   1910       break;
   1911 
   1912    case TYPE_INT_N:
   1913       for (i = 0; i < v.value_int_n.n; i++)
   1914          params[i] = INT_TO_BOOLEAN(v.value_int_n.ints[i]);
   1915       break;
   1916 
   1917    case TYPE_UINT_4:
   1918       params[3] = ((GLuint *) p)[3];
   1919    case TYPE_UINT_3:
   1920       params[2] = ((GLuint *) p)[2];
   1921    case TYPE_UINT_2:
   1922       params[1] = ((GLuint *) p)[1];
   1923    case TYPE_UINT:
   1924       params[0] = ((GLuint *) p)[0];
   1925       break;
   1926 
   1927    case TYPE_INT64:
   1928       params[0] = ((GLint64 *) p)[0];
   1929       break;
   1930 
   1931    case TYPE_BOOLEAN:
   1932       params[0] = ((GLboolean*) p)[0];
   1933       break;
   1934 
   1935    case TYPE_MATRIX:
   1936       m = *(GLmatrix **) p;
   1937       for (i = 0; i < 16; i++)
   1938          params[i] = FLOAT_TO_INT64(m->m[i]);
   1939       break;
   1940 
   1941    case TYPE_MATRIX_T:
   1942       m = *(GLmatrix **) p;
   1943       for (i = 0; i < 16; i++)
   1944          params[i] = FLOAT_TO_INT64(m->m[transpose[i]]);
   1945       break;
   1946 
   1947    case TYPE_BIT_0:
   1948    case TYPE_BIT_1:
   1949    case TYPE_BIT_2:
   1950    case TYPE_BIT_3:
   1951    case TYPE_BIT_4:
   1952    case TYPE_BIT_5:
   1953    case TYPE_BIT_6:
   1954    case TYPE_BIT_7:
   1955       shift = d->type - TYPE_BIT_0;
   1956       params[0] = (*(GLbitfield *) p >> shift) & 1;
   1957       break;
   1958    }
   1959 }
   1960 
   1961 void GLAPIENTRY
   1962 _mesa_GetDoublev(GLenum pname, GLdouble *params)
   1963 {
   1964    const struct value_desc *d;
   1965    union value v;
   1966    GLmatrix *m;
   1967    int shift, i;
   1968    void *p;
   1969 
   1970    d = find_value("glGetDoublev", pname, &p, &v);
   1971    switch (d->type) {
   1972    case TYPE_INVALID:
   1973       break;
   1974    case TYPE_CONST:
   1975       params[0] = d->offset;
   1976       break;
   1977 
   1978    case TYPE_FLOAT_8:
   1979       params[7] = ((GLfloat *) p)[7];
   1980       params[6] = ((GLfloat *) p)[6];
   1981       params[5] = ((GLfloat *) p)[5];
   1982       params[4] = ((GLfloat *) p)[4];
   1983    case TYPE_FLOAT_4:
   1984    case TYPE_FLOATN_4:
   1985       params[3] = ((GLfloat *) p)[3];
   1986    case TYPE_FLOAT_3:
   1987    case TYPE_FLOATN_3:
   1988       params[2] = ((GLfloat *) p)[2];
   1989    case TYPE_FLOAT_2:
   1990    case TYPE_FLOATN_2:
   1991       params[1] = ((GLfloat *) p)[1];
   1992    case TYPE_FLOAT:
   1993    case TYPE_FLOATN:
   1994       params[0] = ((GLfloat *) p)[0];
   1995       break;
   1996 
   1997    case TYPE_DOUBLEN_2:
   1998       params[1] = ((GLdouble *) p)[1];
   1999    case TYPE_DOUBLEN:
   2000       params[0] = ((GLdouble *) p)[0];
   2001       break;
   2002 
   2003    case TYPE_INT_4:
   2004       params[3] = ((GLint *) p)[3];
   2005    case TYPE_INT_3:
   2006       params[2] = ((GLint *) p)[2];
   2007    case TYPE_INT_2:
   2008    case TYPE_ENUM_2:
   2009       params[1] = ((GLint *) p)[1];
   2010    case TYPE_INT:
   2011    case TYPE_ENUM:
   2012       params[0] = ((GLint *) p)[0];
   2013       break;
   2014 
   2015    case TYPE_INT_N:
   2016       for (i = 0; i < v.value_int_n.n; i++)
   2017          params[i] = v.value_int_n.ints[i];
   2018       break;
   2019 
   2020    case TYPE_UINT_4:
   2021       params[3] = ((GLuint *) p)[3];
   2022    case TYPE_UINT_3:
   2023       params[2] = ((GLuint *) p)[2];
   2024    case TYPE_UINT_2:
   2025       params[1] = ((GLuint *) p)[1];
   2026    case TYPE_UINT:
   2027       params[0] = ((GLuint *) p)[0];
   2028       break;
   2029 
   2030    case TYPE_INT64:
   2031       params[0] = (GLdouble) (((GLint64 *) p)[0]);
   2032       break;
   2033 
   2034    case TYPE_BOOLEAN:
   2035       params[0] = *(GLboolean*) p;
   2036       break;
   2037 
   2038    case TYPE_MATRIX:
   2039       m = *(GLmatrix **) p;
   2040       for (i = 0; i < 16; i++)
   2041          params[i] = m->m[i];
   2042       break;
   2043 
   2044    case TYPE_MATRIX_T:
   2045       m = *(GLmatrix **) p;
   2046       for (i = 0; i < 16; i++)
   2047          params[i] = m->m[transpose[i]];
   2048       break;
   2049 
   2050    case TYPE_BIT_0:
   2051    case TYPE_BIT_1:
   2052    case TYPE_BIT_2:
   2053    case TYPE_BIT_3:
   2054    case TYPE_BIT_4:
   2055    case TYPE_BIT_5:
   2056    case TYPE_BIT_6:
   2057    case TYPE_BIT_7:
   2058       shift = d->type - TYPE_BIT_0;
   2059       params[0] = (*(GLbitfield *) p >> shift) & 1;
   2060       break;
   2061    }
   2062 }
   2063 
   2064 void GLAPIENTRY
   2065 _mesa_GetUnsignedBytevEXT(GLenum pname, GLubyte *data)
   2066 {
   2067    const struct value_desc *d;
   2068    union value v;
   2069    int shift;
   2070    void *p;
   2071    GLsizei size;
   2072    const char *func = "glGetUnsignedBytevEXT";
   2073 
   2074    GET_CURRENT_CONTEXT(ctx);
   2075 
   2076    if (!ctx->Extensions.EXT_memory_object) {
   2077       _mesa_error(ctx, GL_INVALID_OPERATION, "%s(unsupported)", func);
   2078       return;
   2079    }
   2080 
   2081    d = find_value(func, pname, &p, &v);
   2082    size = get_value_size(d->type, &v);
   2083    if (size >= 0) {
   2084       _mesa_problem(ctx, "invalid value type in GetUnsignedBytevEXT()");
   2085    }
   2086 
   2087    switch (d->type) {
   2088    case TYPE_BIT_0:
   2089    case TYPE_BIT_1:
   2090    case TYPE_BIT_2:
   2091    case TYPE_BIT_3:
   2092    case TYPE_BIT_4:
   2093    case TYPE_BIT_5:
   2094    case TYPE_BIT_6:
   2095    case TYPE_BIT_7:
   2096       shift = d->type - TYPE_BIT_0;
   2097       data[0] = (*(GLbitfield *) p >> shift) & 1;
   2098       break;
   2099    case TYPE_CONST:
   2100       memcpy(data, &d->offset, size);
   2101       break;
   2102    case TYPE_INT_N:
   2103       memcpy(data, &v.value_int_n.ints, size);
   2104       break;
   2105    case TYPE_UINT:
   2106    case TYPE_INT:
   2107    case TYPE_INT_2:
   2108    case TYPE_UINT_2:
   2109    case TYPE_INT_3:
   2110    case TYPE_UINT_3:
   2111    case TYPE_INT_4:
   2112    case TYPE_UINT_4:
   2113    case TYPE_INT64:
   2114    case TYPE_ENUM:
   2115    case TYPE_ENUM_2:
   2116    case TYPE_BOOLEAN:
   2117    case TYPE_FLOAT:
   2118    case TYPE_FLOATN:
   2119    case TYPE_FLOAT_2:
   2120    case TYPE_FLOATN_2:
   2121    case TYPE_FLOAT_3:
   2122    case TYPE_FLOATN_3:
   2123    case TYPE_FLOAT_4:
   2124    case TYPE_FLOATN_4:
   2125    case TYPE_FLOAT_8:
   2126    case TYPE_DOUBLEN:
   2127    case TYPE_DOUBLEN_2:
   2128    case TYPE_MATRIX:
   2129    case TYPE_MATRIX_T:
   2130       memcpy(data, p, size);
   2131       break;
   2132    default:
   2133       break; /* nothing - GL error was recorded */
   2134    }
   2135 }
   2136 
   2137 /**
   2138  * Convert a GL texture binding enum such as GL_TEXTURE_BINDING_2D
   2139  * into the corresponding Mesa texture target index.
   2140  * \return TEXTURE_x_INDEX or -1 if binding is invalid
   2141  */
   2142 static int
   2143 tex_binding_to_index(const struct gl_context *ctx, GLenum binding)
   2144 {
   2145    switch (binding) {
   2146    case GL_TEXTURE_BINDING_1D:
   2147       return _mesa_is_desktop_gl(ctx) ? TEXTURE_1D_INDEX : -1;
   2148    case GL_TEXTURE_BINDING_2D:
   2149       return TEXTURE_2D_INDEX;
   2150    case GL_TEXTURE_BINDING_3D:
   2151       return ctx->API != API_OPENGLES ? TEXTURE_3D_INDEX : -1;
   2152    case GL_TEXTURE_BINDING_CUBE_MAP:
   2153       return ctx->Extensions.ARB_texture_cube_map
   2154          ? TEXTURE_CUBE_INDEX : -1;
   2155    case GL_TEXTURE_BINDING_RECTANGLE:
   2156       return _mesa_is_desktop_gl(ctx) && ctx->Extensions.NV_texture_rectangle
   2157          ? TEXTURE_RECT_INDEX : -1;
   2158    case GL_TEXTURE_BINDING_1D_ARRAY:
   2159       return _mesa_is_desktop_gl(ctx) && ctx->Extensions.EXT_texture_array
   2160          ? TEXTURE_1D_ARRAY_INDEX : -1;
   2161    case GL_TEXTURE_BINDING_2D_ARRAY:
   2162       return (_mesa_is_desktop_gl(ctx) && ctx->Extensions.EXT_texture_array)
   2163          || _mesa_is_gles3(ctx)
   2164          ? TEXTURE_2D_ARRAY_INDEX : -1;
   2165    case GL_TEXTURE_BINDING_BUFFER:
   2166       return (_mesa_has_ARB_texture_buffer_object(ctx) ||
   2167               _mesa_has_OES_texture_buffer(ctx)) ?
   2168              TEXTURE_BUFFER_INDEX : -1;
   2169    case GL_TEXTURE_BINDING_CUBE_MAP_ARRAY:
   2170       return _mesa_has_texture_cube_map_array(ctx)
   2171          ? TEXTURE_CUBE_ARRAY_INDEX : -1;
   2172    case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
   2173       return _mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_texture_multisample
   2174          ? TEXTURE_2D_MULTISAMPLE_INDEX : -1;
   2175    case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY:
   2176       return _mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_texture_multisample
   2177          ? TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX : -1;
   2178    default:
   2179       return -1;
   2180    }
   2181 }
   2182 
   2183 static enum value_type
   2184 find_value_indexed(const char *func, GLenum pname, GLuint index, union value *v)
   2185 {
   2186    GET_CURRENT_CONTEXT(ctx);
   2187 
   2188    switch (pname) {
   2189 
   2190    case GL_BLEND:
   2191       if (index >= ctx->Const.MaxDrawBuffers)
   2192          goto invalid_value;
   2193       if (!ctx->Extensions.EXT_draw_buffers2)
   2194          goto invalid_enum;
   2195       v->value_int = (ctx->Color.BlendEnabled >> index) & 1;
   2196       return TYPE_INT;
   2197 
   2198    case GL_BLEND_SRC:
   2199       /* fall-through */
   2200    case GL_BLEND_SRC_RGB:
   2201       if (index >= ctx->Const.MaxDrawBuffers)
   2202          goto invalid_value;
   2203       if (!ctx->Extensions.ARB_draw_buffers_blend)
   2204          goto invalid_enum;
   2205       v->value_int = ctx->Color.Blend[index].SrcRGB;
   2206       return TYPE_INT;
   2207    case GL_BLEND_SRC_ALPHA:
   2208       if (index >= ctx->Const.MaxDrawBuffers)
   2209          goto invalid_value;
   2210       if (!ctx->Extensions.ARB_draw_buffers_blend)
   2211          goto invalid_enum;
   2212       v->value_int = ctx->Color.Blend[index].SrcA;
   2213       return TYPE_INT;
   2214    case GL_BLEND_DST:
   2215       /* fall-through */
   2216    case GL_BLEND_DST_RGB:
   2217       if (index >= ctx->Const.MaxDrawBuffers)
   2218          goto invalid_value;
   2219       if (!ctx->Extensions.ARB_draw_buffers_blend)
   2220          goto invalid_enum;
   2221       v->value_int = ctx->Color.Blend[index].DstRGB;
   2222       return TYPE_INT;
   2223    case GL_BLEND_DST_ALPHA:
   2224       if (index >= ctx->Const.MaxDrawBuffers)
   2225          goto invalid_value;
   2226       if (!ctx->Extensions.ARB_draw_buffers_blend)
   2227          goto invalid_enum;
   2228       v->value_int = ctx->Color.Blend[index].DstA;
   2229       return TYPE_INT;
   2230    case GL_BLEND_EQUATION_RGB:
   2231       if (index >= ctx->Const.MaxDrawBuffers)
   2232          goto invalid_value;
   2233       if (!ctx->Extensions.ARB_draw_buffers_blend)
   2234          goto invalid_enum;
   2235       v->value_int = ctx->Color.Blend[index].EquationRGB;
   2236       return TYPE_INT;
   2237    case GL_BLEND_EQUATION_ALPHA:
   2238       if (index >= ctx->Const.MaxDrawBuffers)
   2239          goto invalid_value;
   2240       if (!ctx->Extensions.ARB_draw_buffers_blend)
   2241          goto invalid_enum;
   2242       v->value_int = ctx->Color.Blend[index].EquationA;
   2243       return TYPE_INT;
   2244 
   2245    case GL_COLOR_WRITEMASK:
   2246       if (index >= ctx->Const.MaxDrawBuffers)
   2247          goto invalid_value;
   2248       if (!ctx->Extensions.EXT_draw_buffers2)
   2249          goto invalid_enum;
   2250       v->value_int_4[0] = ctx->Color.ColorMask[index][RCOMP] ? 1 : 0;
   2251       v->value_int_4[1] = ctx->Color.ColorMask[index][GCOMP] ? 1 : 0;
   2252       v->value_int_4[2] = ctx->Color.ColorMask[index][BCOMP] ? 1 : 0;
   2253       v->value_int_4[3] = ctx->Color.ColorMask[index][ACOMP] ? 1 : 0;
   2254       return TYPE_INT_4;
   2255 
   2256    case GL_SCISSOR_BOX:
   2257       if (index >= ctx->Const.MaxViewports)
   2258          goto invalid_value;
   2259       v->value_int_4[0] = ctx->Scissor.ScissorArray[index].X;
   2260       v->value_int_4[1] = ctx->Scissor.ScissorArray[index].Y;
   2261       v->value_int_4[2] = ctx->Scissor.ScissorArray[index].Width;
   2262       v->value_int_4[3] = ctx->Scissor.ScissorArray[index].Height;
   2263       return TYPE_INT_4;
   2264 
   2265    case GL_WINDOW_RECTANGLE_EXT:
   2266       if (!ctx->Extensions.EXT_window_rectangles)
   2267          goto invalid_enum;
   2268       if (index >= ctx->Const.MaxWindowRectangles)
   2269          goto invalid_value;
   2270       v->value_int_4[0] = ctx->Scissor.WindowRects[index].X;
   2271       v->value_int_4[1] = ctx->Scissor.WindowRects[index].Y;
   2272       v->value_int_4[2] = ctx->Scissor.WindowRects[index].Width;
   2273       v->value_int_4[3] = ctx->Scissor.WindowRects[index].Height;
   2274       return TYPE_INT_4;
   2275 
   2276    case GL_VIEWPORT:
   2277       if (index >= ctx->Const.MaxViewports)
   2278          goto invalid_value;
   2279       v->value_float_4[0] = ctx->ViewportArray[index].X;
   2280       v->value_float_4[1] = ctx->ViewportArray[index].Y;
   2281       v->value_float_4[2] = ctx->ViewportArray[index].Width;
   2282       v->value_float_4[3] = ctx->ViewportArray[index].Height;
   2283       return TYPE_FLOAT_4;
   2284 
   2285    case GL_DEPTH_RANGE:
   2286       if (index >= ctx->Const.MaxViewports)
   2287          goto invalid_value;
   2288       v->value_double_2[0] = ctx->ViewportArray[index].Near;
   2289       v->value_double_2[1] = ctx->ViewportArray[index].Far;
   2290       return TYPE_DOUBLEN_2;
   2291 
   2292    case GL_TRANSFORM_FEEDBACK_BUFFER_START:
   2293       if (index >= ctx->Const.MaxTransformFeedbackBuffers)
   2294          goto invalid_value;
   2295       if (!ctx->Extensions.EXT_transform_feedback)
   2296          goto invalid_enum;
   2297       v->value_int64 = ctx->TransformFeedback.CurrentObject->Offset[index];
   2298       return TYPE_INT64;
   2299 
   2300    case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
   2301       if (index >= ctx->Const.MaxTransformFeedbackBuffers)
   2302          goto invalid_value;
   2303       if (!ctx->Extensions.EXT_transform_feedback)
   2304          goto invalid_enum;
   2305       v->value_int64
   2306          = ctx->TransformFeedback.CurrentObject->RequestedSize[index];
   2307       return TYPE_INT64;
   2308 
   2309    case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
   2310       if (index >= ctx->Const.MaxTransformFeedbackBuffers)
   2311          goto invalid_value;
   2312       if (!ctx->Extensions.EXT_transform_feedback)
   2313          goto invalid_enum;
   2314       v->value_int = ctx->TransformFeedback.CurrentObject->BufferNames[index];
   2315       return TYPE_INT;
   2316 
   2317    case GL_UNIFORM_BUFFER_BINDING:
   2318       if (index >= ctx->Const.MaxUniformBufferBindings)
   2319          goto invalid_value;
   2320       if (!ctx->Extensions.ARB_uniform_buffer_object)
   2321          goto invalid_enum;
   2322       v->value_int = ctx->UniformBufferBindings[index].BufferObject->Name;
   2323       return TYPE_INT;
   2324 
   2325    case GL_UNIFORM_BUFFER_START:
   2326       if (index >= ctx->Const.MaxUniformBufferBindings)
   2327          goto invalid_value;
   2328       if (!ctx->Extensions.ARB_uniform_buffer_object)
   2329          goto invalid_enum;
   2330       v->value_int = ctx->UniformBufferBindings[index].Offset < 0 ? 0 :
   2331                      ctx->UniformBufferBindings[index].Offset;
   2332       return TYPE_INT;
   2333 
   2334    case GL_UNIFORM_BUFFER_SIZE:
   2335       if (index >= ctx->Const.MaxUniformBufferBindings)
   2336          goto invalid_value;
   2337       if (!ctx->Extensions.ARB_uniform_buffer_object)
   2338          goto invalid_enum;
   2339       v->value_int = ctx->UniformBufferBindings[index].Size < 0 ? 0 :
   2340                      ctx->UniformBufferBindings[index].Size;
   2341       return TYPE_INT;
   2342 
   2343    /* ARB_shader_storage_buffer_object */
   2344    case GL_SHADER_STORAGE_BUFFER_BINDING:
   2345       if (!ctx->Extensions.ARB_shader_storage_buffer_object)
   2346          goto invalid_enum;
   2347       if (index >= ctx->Const.MaxShaderStorageBufferBindings)
   2348          goto invalid_value;
   2349       v->value_int = ctx->ShaderStorageBufferBindings[index].BufferObject->Name;
   2350       return TYPE_INT;
   2351 
   2352    case GL_SHADER_STORAGE_BUFFER_START:
   2353       if (!ctx->Extensions.ARB_shader_storage_buffer_object)
   2354          goto invalid_enum;
   2355       if (index >= ctx->Const.MaxShaderStorageBufferBindings)
   2356          goto invalid_value;
   2357       v->value_int = ctx->ShaderStorageBufferBindings[index].Offset < 0 ? 0 :
   2358                      ctx->ShaderStorageBufferBindings[index].Offset;
   2359       return TYPE_INT;
   2360 
   2361    case GL_SHADER_STORAGE_BUFFER_SIZE:
   2362       if (!ctx->Extensions.ARB_shader_storage_buffer_object)
   2363          goto invalid_enum;
   2364       if (index >= ctx->Const.MaxShaderStorageBufferBindings)
   2365          goto invalid_value;
   2366       v->value_int = ctx->ShaderStorageBufferBindings[index].Size < 0 ? 0 :
   2367                      ctx->ShaderStorageBufferBindings[index].Size;
   2368       return TYPE_INT;
   2369 
   2370    /* ARB_texture_multisample / GL3.2 */
   2371    case GL_SAMPLE_MASK_VALUE:
   2372       if (index != 0)
   2373          goto invalid_value;
   2374       if (!ctx->Extensions.ARB_texture_multisample)
   2375          goto invalid_enum;
   2376       v->value_int = ctx->Multisample.SampleMaskValue;
   2377       return TYPE_INT;
   2378 
   2379    case GL_ATOMIC_COUNTER_BUFFER_BINDING:
   2380       if (!ctx->Extensions.ARB_shader_atomic_counters)
   2381          goto invalid_enum;
   2382       if (index >= ctx->Const.MaxAtomicBufferBindings)
   2383          goto invalid_value;
   2384       v->value_int = ctx->AtomicBufferBindings[index].BufferObject->Name;
   2385       return TYPE_INT;
   2386 
   2387    case GL_ATOMIC_COUNTER_BUFFER_START:
   2388       if (!ctx->Extensions.ARB_shader_atomic_counters)
   2389          goto invalid_enum;
   2390       if (index >= ctx->Const.MaxAtomicBufferBindings)
   2391          goto invalid_value;
   2392       v->value_int64 = ctx->AtomicBufferBindings[index].Offset < 0 ? 0 :
   2393                        ctx->AtomicBufferBindings[index].Offset;
   2394       return TYPE_INT64;
   2395 
   2396    case GL_ATOMIC_COUNTER_BUFFER_SIZE:
   2397       if (!ctx->Extensions.ARB_shader_atomic_counters)
   2398          goto invalid_enum;
   2399       if (index >= ctx->Const.MaxAtomicBufferBindings)
   2400          goto invalid_value;
   2401       v->value_int64 = ctx->AtomicBufferBindings[index].Size < 0 ? 0 :
   2402                        ctx->AtomicBufferBindings[index].Size;
   2403       return TYPE_INT64;
   2404 
   2405    case GL_VERTEX_BINDING_DIVISOR:
   2406       if ((!_mesa_is_desktop_gl(ctx) || !ctx->Extensions.ARB_instanced_arrays) &&
   2407           !_mesa_is_gles31(ctx))
   2408           goto invalid_enum;
   2409       if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs)
   2410           goto invalid_value;
   2411       v->value_int = ctx->Array.VAO->BufferBinding[VERT_ATTRIB_GENERIC(index)].InstanceDivisor;
   2412       return TYPE_INT;
   2413 
   2414    case GL_VERTEX_BINDING_OFFSET:
   2415       if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles31(ctx))
   2416           goto invalid_enum;
   2417       if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs)
   2418           goto invalid_value;
   2419       v->value_int = ctx->Array.VAO->BufferBinding[VERT_ATTRIB_GENERIC(index)].Offset;
   2420       return TYPE_INT;
   2421 
   2422    case GL_VERTEX_BINDING_STRIDE:
   2423       if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles31(ctx))
   2424           goto invalid_enum;
   2425       if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs)
   2426           goto invalid_value;
   2427       v->value_int = ctx->Array.VAO->BufferBinding[VERT_ATTRIB_GENERIC(index)].Stride;
   2428       return TYPE_INT;
   2429 
   2430    case GL_VERTEX_BINDING_BUFFER:
   2431       if (ctx->API == API_OPENGLES2 && ctx->Version < 31)
   2432          goto invalid_enum;
   2433       if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs)
   2434          goto invalid_value;
   2435       v->value_int = ctx->Array.VAO->BufferBinding[VERT_ATTRIB_GENERIC(index)].BufferObj->Name;
   2436       return TYPE_INT;
   2437 
   2438    /* ARB_shader_image_load_store */
   2439    case GL_IMAGE_BINDING_NAME: {
   2440       struct gl_texture_object *t;
   2441 
   2442       if (!ctx->Extensions.ARB_shader_image_load_store)
   2443          goto invalid_enum;
   2444       if (index >= ctx->Const.MaxImageUnits)
   2445          goto invalid_value;
   2446 
   2447       t = ctx->ImageUnits[index].TexObj;
   2448       v->value_int = (t ? t->Name : 0);
   2449       return TYPE_INT;
   2450    }
   2451 
   2452    case GL_IMAGE_BINDING_LEVEL:
   2453       if (!ctx->Extensions.ARB_shader_image_load_store)
   2454          goto invalid_enum;
   2455       if (index >= ctx->Const.MaxImageUnits)
   2456          goto invalid_value;
   2457 
   2458       v->value_int = ctx->ImageUnits[index].Level;
   2459       return TYPE_INT;
   2460 
   2461    case GL_IMAGE_BINDING_LAYERED:
   2462       if (!ctx->Extensions.ARB_shader_image_load_store)
   2463          goto invalid_enum;
   2464       if (index >= ctx->Const.MaxImageUnits)
   2465          goto invalid_value;
   2466 
   2467       v->value_int = ctx->ImageUnits[index].Layered;
   2468       return TYPE_INT;
   2469 
   2470    case GL_IMAGE_BINDING_LAYER:
   2471       if (!ctx->Extensions.ARB_shader_image_load_store)
   2472          goto invalid_enum;
   2473       if (index >= ctx->Const.MaxImageUnits)
   2474          goto invalid_value;
   2475 
   2476       v->value_int = ctx->ImageUnits[index].Layer;
   2477       return TYPE_INT;
   2478 
   2479    case GL_IMAGE_BINDING_ACCESS:
   2480       if (!ctx->Extensions.ARB_shader_image_load_store)
   2481          goto invalid_enum;
   2482       if (index >= ctx->Const.MaxImageUnits)
   2483          goto invalid_value;
   2484 
   2485       v->value_int = ctx->ImageUnits[index].Access;
   2486       return TYPE_INT;
   2487 
   2488    case GL_IMAGE_BINDING_FORMAT:
   2489       if (!ctx->Extensions.ARB_shader_image_load_store)
   2490          goto invalid_enum;
   2491       if (index >= ctx->Const.MaxImageUnits)
   2492          goto invalid_value;
   2493 
   2494       v->value_int = ctx->ImageUnits[index].Format;
   2495       return TYPE_INT;
   2496 
   2497    /* ARB_direct_state_access */
   2498    case GL_TEXTURE_BINDING_1D:
   2499    case GL_TEXTURE_BINDING_1D_ARRAY:
   2500    case GL_TEXTURE_BINDING_2D:
   2501    case GL_TEXTURE_BINDING_2D_ARRAY:
   2502    case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
   2503    case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY:
   2504    case GL_TEXTURE_BINDING_3D:
   2505    case GL_TEXTURE_BINDING_BUFFER:
   2506    case GL_TEXTURE_BINDING_CUBE_MAP:
   2507    case GL_TEXTURE_BINDING_CUBE_MAP_ARRAY:
   2508    case GL_TEXTURE_BINDING_RECTANGLE: {
   2509       int target;
   2510 
   2511       if (ctx->API != API_OPENGL_CORE)
   2512          goto invalid_enum;
   2513       target = tex_binding_to_index(ctx, pname);
   2514       if (target < 0)
   2515          goto invalid_enum;
   2516       if (index >= _mesa_max_tex_unit(ctx))
   2517          goto invalid_value;
   2518 
   2519       v->value_int = ctx->Texture.Unit[index].CurrentTex[target]->Name;
   2520       return TYPE_INT;
   2521    }
   2522 
   2523    case GL_SAMPLER_BINDING: {
   2524       struct gl_sampler_object *samp;
   2525 
   2526       if (ctx->API != API_OPENGL_CORE)
   2527          goto invalid_enum;
   2528       if (index >= _mesa_max_tex_unit(ctx))
   2529          goto invalid_value;
   2530 
   2531       samp = ctx->Texture.Unit[index].Sampler;
   2532       v->value_int = samp ? samp->Name : 0;
   2533       return TYPE_INT;
   2534    }
   2535 
   2536    case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
   2537       if (!_mesa_has_compute_shaders(ctx))
   2538          goto invalid_enum;
   2539       if (index >= 3)
   2540          goto invalid_value;
   2541       v->value_int = ctx->Const.MaxComputeWorkGroupCount[index];
   2542       return TYPE_INT;
   2543 
   2544    case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
   2545       if (!_mesa_has_compute_shaders(ctx))
   2546          goto invalid_enum;
   2547       if (index >= 3)
   2548          goto invalid_value;
   2549       v->value_int = ctx->Const.MaxComputeWorkGroupSize[index];
   2550       return TYPE_INT;
   2551 
   2552    /* ARB_compute_variable_group_size */
   2553    case GL_MAX_COMPUTE_VARIABLE_GROUP_SIZE_ARB:
   2554       if (!ctx->Extensions.ARB_compute_variable_group_size)
   2555          goto invalid_enum;
   2556       if (index >= 3)
   2557          goto invalid_value;
   2558       v->value_int = ctx->Const.MaxComputeVariableGroupSize[index];
   2559       return TYPE_INT;
   2560 
   2561    /* GL_EXT_external_objects */
   2562    case GL_DRIVER_UUID_EXT:
   2563       _mesa_get_driver_uuid(ctx, v->value_int_4);
   2564       return TYPE_INT_4;
   2565    case GL_DEVICE_UUID_EXT:
   2566       _mesa_get_device_uuid(ctx, v->value_int_4);
   2567       return TYPE_INT_4;
   2568    }
   2569 
   2570  invalid_enum:
   2571    _mesa_error(ctx, GL_INVALID_ENUM, "%s(pname=%s)", func,
   2572                _mesa_enum_to_string(pname));
   2573    return TYPE_INVALID;
   2574  invalid_value:
   2575    _mesa_error(ctx, GL_INVALID_VALUE, "%s(pname=%s)", func,
   2576                _mesa_enum_to_string(pname));
   2577    return TYPE_INVALID;
   2578 }
   2579 
   2580 void GLAPIENTRY
   2581 _mesa_GetBooleani_v( GLenum pname, GLuint index, GLboolean *params )
   2582 {
   2583    union value v;
   2584    enum value_type type =
   2585       find_value_indexed("glGetBooleani_v", pname, index, &v);
   2586 
   2587    switch (type) {
   2588    case TYPE_INT:
   2589    case TYPE_UINT:
   2590       params[0] = INT_TO_BOOLEAN(v.value_int);
   2591       break;
   2592    case TYPE_INT_4:
   2593    case TYPE_UINT_4:
   2594       params[0] = INT_TO_BOOLEAN(v.value_int_4[0]);
   2595       params[1] = INT_TO_BOOLEAN(v.value_int_4[1]);
   2596       params[2] = INT_TO_BOOLEAN(v.value_int_4[2]);
   2597       params[3] = INT_TO_BOOLEAN(v.value_int_4[3]);
   2598       break;
   2599    case TYPE_INT64:
   2600       params[0] = INT64_TO_BOOLEAN(v.value_int64);
   2601       break;
   2602    default:
   2603       ; /* nothing - GL error was recorded */
   2604    }
   2605 }
   2606 
   2607 void GLAPIENTRY
   2608 _mesa_GetIntegeri_v( GLenum pname, GLuint index, GLint *params )
   2609 {
   2610    union value v;
   2611    enum value_type type =
   2612       find_value_indexed("glGetIntegeri_v", pname, index, &v);
   2613 
   2614    switch (type) {
   2615    case TYPE_FLOAT_4:
   2616    case TYPE_FLOATN_4:
   2617       params[3] = IROUND(v.value_float_4[3]);
   2618    case TYPE_FLOAT_3:
   2619    case TYPE_FLOATN_3:
   2620       params[2] = IROUND(v.value_float_4[2]);
   2621    case TYPE_FLOAT_2:
   2622    case TYPE_FLOATN_2:
   2623       params[1] = IROUND(v.value_float_4[1]);
   2624    case TYPE_FLOAT:
   2625    case TYPE_FLOATN:
   2626       params[0] = IROUND(v.value_float_4[0]);
   2627       break;
   2628 
   2629    case TYPE_DOUBLEN_2:
   2630       params[1] = IROUND(v.value_double_2[1]);
   2631    case TYPE_DOUBLEN:
   2632       params[0] = IROUND(v.value_double_2[0]);
   2633       break;
   2634 
   2635    case TYPE_INT:
   2636    case TYPE_UINT:
   2637       params[0] = v.value_int;
   2638       break;
   2639    case TYPE_INT_4:
   2640    case TYPE_UINT_4:
   2641       params[0] = v.value_int_4[0];
   2642       params[1] = v.value_int_4[1];
   2643       params[2] = v.value_int_4[2];
   2644       params[3] = v.value_int_4[3];
   2645       break;
   2646    case TYPE_INT64:
   2647       params[0] = INT64_TO_INT(v.value_int64);
   2648       break;
   2649    default:
   2650       ; /* nothing - GL error was recorded */
   2651    }
   2652 }
   2653 
   2654 void GLAPIENTRY
   2655 _mesa_GetInteger64i_v( GLenum pname, GLuint index, GLint64 *params )
   2656 {
   2657    union value v;
   2658    enum value_type type =
   2659       find_value_indexed("glGetInteger64i_v", pname, index, &v);
   2660 
   2661    switch (type) {
   2662    case TYPE_INT:
   2663       params[0] = v.value_int;
   2664       break;
   2665    case TYPE_INT_4:
   2666       params[0] = v.value_int_4[0];
   2667       params[1] = v.value_int_4[1];
   2668       params[2] = v.value_int_4[2];
   2669       params[3] = v.value_int_4[3];
   2670       break;
   2671    case TYPE_UINT:
   2672       params[0] = (GLuint) v.value_int;
   2673       break;
   2674    case TYPE_UINT_4:
   2675       params[0] = (GLuint) v.value_int_4[0];
   2676       params[1] = (GLuint) v.value_int_4[1];
   2677       params[2] = (GLuint) v.value_int_4[2];
   2678       params[3] = (GLuint) v.value_int_4[3];
   2679       break;
   2680    case TYPE_INT64:
   2681       params[0] = v.value_int64;
   2682       break;
   2683    default:
   2684       ; /* nothing - GL error was recorded */
   2685    }
   2686 }
   2687 
   2688 void GLAPIENTRY
   2689 _mesa_GetFloati_v(GLenum pname, GLuint index, GLfloat *params)
   2690 {
   2691    int i;
   2692    GLmatrix *m;
   2693    union value v;
   2694    enum value_type type =
   2695       find_value_indexed("glGetFloati_v", pname, index, &v);
   2696 
   2697    switch (type) {
   2698    case TYPE_FLOAT_4:
   2699    case TYPE_FLOATN_4:
   2700       params[3] = v.value_float_4[3];
   2701    case TYPE_FLOAT_3:
   2702    case TYPE_FLOATN_3:
   2703       params[2] = v.value_float_4[2];
   2704    case TYPE_FLOAT_2:
   2705    case TYPE_FLOATN_2:
   2706       params[1] = v.value_float_4[1];
   2707    case TYPE_FLOAT:
   2708    case TYPE_FLOATN:
   2709       params[0] = v.value_float_4[0];
   2710       break;
   2711 
   2712    case TYPE_DOUBLEN_2:
   2713       params[1] = (GLfloat) v.value_double_2[1];
   2714    case TYPE_DOUBLEN:
   2715       params[0] = (GLfloat) v.value_double_2[0];
   2716       break;
   2717 
   2718    case TYPE_INT_4:
   2719       params[3] = (GLfloat) v.value_int_4[3];
   2720    case TYPE_INT_3:
   2721       params[2] = (GLfloat) v.value_int_4[2];
   2722    case TYPE_INT_2:
   2723    case TYPE_ENUM_2:
   2724       params[1] = (GLfloat) v.value_int_4[1];
   2725    case TYPE_INT:
   2726    case TYPE_ENUM:
   2727       params[0] = (GLfloat) v.value_int_4[0];
   2728       break;
   2729 
   2730    case TYPE_INT_N:
   2731       for (i = 0; i < v.value_int_n.n; i++)
   2732          params[i] = (GLfloat) v.value_int_n.ints[i];
   2733       break;
   2734 
   2735    case TYPE_UINT_4:
   2736       params[3] = (GLfloat) ((GLuint) v.value_int_4[3]);
   2737    case TYPE_UINT_3:
   2738       params[2] = (GLfloat) ((GLuint) v.value_int_4[2]);
   2739    case TYPE_UINT_2:
   2740       params[1] = (GLfloat) ((GLuint) v.value_int_4[1]);
   2741    case TYPE_UINT:
   2742       params[0] = (GLfloat) ((GLuint) v.value_int_4[0]);
   2743       break;
   2744 
   2745    case TYPE_INT64:
   2746       params[0] = (GLfloat) v.value_int64;
   2747       break;
   2748 
   2749    case TYPE_BOOLEAN:
   2750       params[0] = BOOLEAN_TO_FLOAT(v.value_bool);
   2751       break;
   2752 
   2753    case TYPE_MATRIX:
   2754       m = *(GLmatrix **) &v;
   2755       for (i = 0; i < 16; i++)
   2756          params[i] = m->m[i];
   2757       break;
   2758 
   2759    case TYPE_MATRIX_T:
   2760       m = *(GLmatrix **) &v;
   2761       for (i = 0; i < 16; i++)
   2762          params[i] = m->m[transpose[i]];
   2763       break;
   2764 
   2765    default:
   2766       ;
   2767    }
   2768 }
   2769 
   2770 void GLAPIENTRY
   2771 _mesa_GetDoublei_v(GLenum pname, GLuint index, GLdouble *params)
   2772 {
   2773    int i;
   2774    GLmatrix *m;
   2775    union value v;
   2776    enum value_type type =
   2777       find_value_indexed("glGetDoublei_v", pname, index, &v);
   2778 
   2779    switch (type) {
   2780    case TYPE_FLOAT_4:
   2781    case TYPE_FLOATN_4:
   2782       params[3] = (GLdouble) v.value_float_4[3];
   2783    case TYPE_FLOAT_3:
   2784    case TYPE_FLOATN_3:
   2785       params[2] = (GLdouble) v.value_float_4[2];
   2786    case TYPE_FLOAT_2:
   2787    case TYPE_FLOATN_2:
   2788       params[1] = (GLdouble) v.value_float_4[1];
   2789    case TYPE_FLOAT:
   2790    case TYPE_FLOATN:
   2791       params[0] = (GLdouble) v.value_float_4[0];
   2792       break;
   2793 
   2794    case TYPE_DOUBLEN_2:
   2795       params[1] = v.value_double_2[1];
   2796    case TYPE_DOUBLEN:
   2797       params[0] = v.value_double_2[0];
   2798       break;
   2799 
   2800    case TYPE_INT_4:
   2801       params[3] = (GLdouble) v.value_int_4[3];
   2802    case TYPE_INT_3:
   2803       params[2] = (GLdouble) v.value_int_4[2];
   2804    case TYPE_INT_2:
   2805    case TYPE_ENUM_2:
   2806       params[1] = (GLdouble) v.value_int_4[1];
   2807    case TYPE_INT:
   2808    case TYPE_ENUM:
   2809       params[0] = (GLdouble) v.value_int_4[0];
   2810       break;
   2811 
   2812    case TYPE_INT_N:
   2813       for (i = 0; i < v.value_int_n.n; i++)
   2814          params[i] = (GLdouble) v.value_int_n.ints[i];
   2815       break;
   2816 
   2817    case TYPE_UINT_4:
   2818       params[3] = (GLdouble) ((GLuint) v.value_int_4[3]);
   2819    case TYPE_UINT_3:
   2820       params[2] = (GLdouble) ((GLuint) v.value_int_4[2]);
   2821    case TYPE_UINT_2:
   2822       params[1] = (GLdouble) ((GLuint) v.value_int_4[1]);
   2823    case TYPE_UINT:
   2824       params[0] = (GLdouble) ((GLuint) v.value_int_4[0]);
   2825       break;
   2826 
   2827    case TYPE_INT64:
   2828       params[0] = (GLdouble) v.value_int64;
   2829       break;
   2830 
   2831    case TYPE_BOOLEAN:
   2832       params[0] = (GLdouble) BOOLEAN_TO_FLOAT(v.value_bool);
   2833       break;
   2834 
   2835    case TYPE_MATRIX:
   2836       m = *(GLmatrix **) &v;
   2837       for (i = 0; i < 16; i++)
   2838          params[i] = (GLdouble) m->m[i];
   2839       break;
   2840 
   2841    case TYPE_MATRIX_T:
   2842       m = *(GLmatrix **) &v;
   2843       for (i = 0; i < 16; i++)
   2844          params[i] = (GLdouble) m->m[transpose[i]];
   2845       break;
   2846 
   2847    default:
   2848       ;
   2849    }
   2850 }
   2851 
   2852 void GLAPIENTRY
   2853 _mesa_GetUnsignedBytei_vEXT(GLenum target, GLuint index, GLubyte *data)
   2854 {
   2855    GLsizei size;
   2856    union value v;
   2857    enum value_type type;
   2858    const char *func = "glGetUnsignedBytei_vEXT";
   2859 
   2860    GET_CURRENT_CONTEXT(ctx);
   2861 
   2862    if (!ctx->Extensions.EXT_memory_object) {
   2863       _mesa_error(ctx, GL_INVALID_OPERATION, "%s(unsupported)", func);
   2864       return;
   2865    }
   2866 
   2867    type = find_value_indexed(func, target, index, &v);
   2868    size = get_value_size(type, &v);
   2869    if (size <= 0) {
   2870       _mesa_problem(ctx, "invalid value type in GetUnsignedBytei_vEXT()");
   2871    }
   2872 
   2873    switch (type) {
   2874    case TYPE_UINT:
   2875    case TYPE_INT:
   2876    case TYPE_INT_2:
   2877    case TYPE_UINT_2:
   2878    case TYPE_INT_3:
   2879    case TYPE_UINT_3:
   2880    case TYPE_INT_4:
   2881    case TYPE_UINT_4:
   2882    case TYPE_INT64:
   2883    case TYPE_ENUM:
   2884    case TYPE_ENUM_2:
   2885    case TYPE_BOOLEAN:
   2886    case TYPE_FLOAT:
   2887    case TYPE_FLOATN:
   2888    case TYPE_FLOAT_2:
   2889    case TYPE_FLOATN_2:
   2890    case TYPE_FLOAT_3:
   2891    case TYPE_FLOATN_3:
   2892    case TYPE_FLOAT_4:
   2893    case TYPE_FLOATN_4:
   2894    case TYPE_FLOAT_8:
   2895    case TYPE_DOUBLEN:
   2896    case TYPE_DOUBLEN_2:
   2897    case TYPE_MATRIX:
   2898    case TYPE_MATRIX_T:
   2899       memcpy(data, &v.value_int, size);
   2900       break;
   2901    case TYPE_INT_N:
   2902       memcpy(data, &v.value_int_n.ints, size);
   2903       break;
   2904    default:
   2905       break; /* nothing - GL error was recorded */
   2906    }
   2907 }
   2908 
   2909 void GLAPIENTRY
   2910 _mesa_GetFixedv(GLenum pname, GLfixed *params)
   2911 {
   2912    const struct value_desc *d;
   2913    union value v;
   2914    GLmatrix *m;
   2915    int shift, i;
   2916    void *p;
   2917 
   2918    d = find_value("glGetDoublev", pname, &p, &v);
   2919    switch (d->type) {
   2920    case TYPE_INVALID:
   2921       break;
   2922    case TYPE_CONST:
   2923       params[0] = INT_TO_FIXED(d->offset);
   2924       break;
   2925 
   2926    case TYPE_FLOAT_4:
   2927    case TYPE_FLOATN_4:
   2928       params[3] = FLOAT_TO_FIXED(((GLfloat *) p)[3]);
   2929    case TYPE_FLOAT_3:
   2930    case TYPE_FLOATN_3:
   2931       params[2] = FLOAT_TO_FIXED(((GLfloat *) p)[2]);
   2932    case TYPE_FLOAT_2:
   2933    case TYPE_FLOATN_2:
   2934       params[1] = FLOAT_TO_FIXED(((GLfloat *) p)[1]);
   2935    case TYPE_FLOAT:
   2936    case TYPE_FLOATN:
   2937       params[0] = FLOAT_TO_FIXED(((GLfloat *) p)[0]);
   2938       break;
   2939 
   2940    case TYPE_DOUBLEN_2:
   2941       params[1] = FLOAT_TO_FIXED(((GLdouble *) p)[1]);
   2942    case TYPE_DOUBLEN:
   2943       params[0] = FLOAT_TO_FIXED(((GLdouble *) p)[0]);
   2944       break;
   2945 
   2946    case TYPE_INT_4:
   2947    case TYPE_UINT_4:
   2948       params[3] = INT_TO_FIXED(((GLint *) p)[3]);
   2949    case TYPE_INT_3:
   2950    case TYPE_UINT_3:
   2951       params[2] = INT_TO_FIXED(((GLint *) p)[2]);
   2952    case TYPE_INT_2:
   2953    case TYPE_UINT_2:
   2954    case TYPE_ENUM_2:
   2955       params[1] = INT_TO_FIXED(((GLint *) p)[1]);
   2956    case TYPE_INT:
   2957    case TYPE_UINT:
   2958    case TYPE_ENUM:
   2959       params[0] = INT_TO_FIXED(((GLint *) p)[0]);
   2960       break;
   2961 
   2962    case TYPE_INT_N:
   2963       for (i = 0; i < v.value_int_n.n; i++)
   2964          params[i] = INT_TO_FIXED(v.value_int_n.ints[i]);
   2965       break;
   2966 
   2967    case TYPE_INT64:
   2968       params[0] = ((GLint64 *) p)[0];
   2969       break;
   2970 
   2971    case TYPE_BOOLEAN:
   2972       params[0] = BOOLEAN_TO_FIXED(((GLboolean*) p)[0]);
   2973       break;
   2974 
   2975    case TYPE_MATRIX:
   2976       m = *(GLmatrix **) p;
   2977       for (i = 0; i < 16; i++)
   2978          params[i] = FLOAT_TO_FIXED(m->m[i]);
   2979       break;
   2980 
   2981    case TYPE_MATRIX_T:
   2982       m = *(GLmatrix **) p;
   2983       for (i = 0; i < 16; i++)
   2984          params[i] = FLOAT_TO_FIXED(m->m[transpose[i]]);
   2985       break;
   2986 
   2987    case TYPE_BIT_0:
   2988    case TYPE_BIT_1:
   2989    case TYPE_BIT_2:
   2990    case TYPE_BIT_3:
   2991    case TYPE_BIT_4:
   2992    case TYPE_BIT_5:
   2993    case TYPE_BIT_6:
   2994    case TYPE_BIT_7:
   2995       shift = d->type - TYPE_BIT_0;
   2996       params[0] = BOOLEAN_TO_FIXED((*(GLbitfield *) p >> shift) & 1);
   2997       break;
   2998    }
   2999 }
   3000