13464ebd5Sriastradh/*
23464ebd5Sriastradh * Copyright (C) 2010  Brian Paul   All Rights Reserved.
33464ebd5Sriastradh * Copyright (C) 2010  Intel Corporation
43464ebd5Sriastradh *
53464ebd5Sriastradh * Permission is hereby granted, free of charge, to any person obtaining a
63464ebd5Sriastradh * copy of this software and associated documentation files (the "Software"),
73464ebd5Sriastradh * to deal in the Software without restriction, including without limitation
83464ebd5Sriastradh * the rights to use, copy, modify, merge, publish, distribute, sublicense,
93464ebd5Sriastradh * and/or sell copies of the Software, and to permit persons to whom the
103464ebd5Sriastradh * Software is furnished to do so, subject to the following conditions:
113464ebd5Sriastradh *
123464ebd5Sriastradh * The above copyright notice and this permission notice shall be included
133464ebd5Sriastradh * in all copies or substantial portions of the Software.
143464ebd5Sriastradh *
153464ebd5Sriastradh * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
163464ebd5Sriastradh * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
173464ebd5Sriastradh * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18af69d88dSmrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
19af69d88dSmrg * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20af69d88dSmrg * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21af69d88dSmrg * OTHER DEALINGS IN THE SOFTWARE.
223464ebd5Sriastradh *
233464ebd5Sriastradh * Author: Kristian Høgsberg <krh@bitplanet.net>
243464ebd5Sriastradh */
257117f1b4Smrg
267117f1b4Smrg#include "glheader.h"
277117f1b4Smrg#include "context.h"
28af69d88dSmrg#include "blend.h"
2901e04c3fSmrg#include "debug_output.h"
307117f1b4Smrg#include "enable.h"
313464ebd5Sriastradh#include "enums.h"
32af69d88dSmrg#include "errors.h"
337117f1b4Smrg#include "extensions.h"
347117f1b4Smrg#include "get.h"
357117f1b4Smrg#include "macros.h"
367117f1b4Smrg#include "mtypes.h"
377ec681f3Smrg#include "spirv_extensions.h"
387117f1b4Smrg#include "state.h"
397117f1b4Smrg#include "texcompress.h"
4001e04c3fSmrg#include "texstate.h"
414a49301eSmrg#include "framebuffer.h"
42af69d88dSmrg#include "samplerobj.h"
43af69d88dSmrg#include "stencil.h"
4401e04c3fSmrg#include "version.h"
457117f1b4Smrg
463464ebd5Sriastradh/* This is a table driven implemetation of the glGet*v() functions.
473464ebd5Sriastradh * The basic idea is that most getters just look up an int somewhere
483464ebd5Sriastradh * in struct gl_context and then convert it to a bool or float according to
493464ebd5Sriastradh * which of glGetIntegerv() glGetBooleanv() etc is being called.
503464ebd5Sriastradh * Instead of generating code to do this, we can just record the enum
513464ebd5Sriastradh * value and the offset into struct gl_context in an array of structs.  Then
523464ebd5Sriastradh * in glGet*(), we lookup the struct for the enum in question, and use
533464ebd5Sriastradh * the offset to get the int we need.
543464ebd5Sriastradh *
553464ebd5Sriastradh * Sometimes we need to look up a float, a boolean, a bit in a
563464ebd5Sriastradh * bitfield, a matrix or other types instead, so we need to track the
573464ebd5Sriastradh * type of the value in struct gl_context.  And sometimes the value isn't in
583464ebd5Sriastradh * struct gl_context but in the drawbuffer, the array object, current texture
593464ebd5Sriastradh * unit, or maybe it's a computed value.  So we need to also track
603464ebd5Sriastradh * where or how to find the value.  Finally, we sometimes need to
613464ebd5Sriastradh * check that one of a number of extensions are enabled, the GL
623464ebd5Sriastradh * version or flush or call _mesa_update_state().  This is done by
633464ebd5Sriastradh * attaching optional extra information to the value description
643464ebd5Sriastradh * struct, it's sort of like an array of opcodes that describe extra
653464ebd5Sriastradh * checks or actions.
663464ebd5Sriastradh *
673464ebd5Sriastradh * Putting all this together we end up with struct value_desc below,
683464ebd5Sriastradh * and with a couple of macros to help, the table of struct value_desc
693464ebd5Sriastradh * is about as concise as the specification in the old python script.
703464ebd5Sriastradh */
713464ebd5Sriastradh
727ec681f3Smrgstatic inline GLboolean
737ec681f3SmrgFLOAT_TO_BOOLEAN(GLfloat X)
747ec681f3Smrg{
757ec681f3Smrg   return ( (X) ? GL_TRUE : GL_FALSE );
767ec681f3Smrg}
777ec681f3Smrg
787ec681f3Smrgstatic inline GLint
797ec681f3SmrgFLOAT_TO_FIXED(GLfloat F)
807ec681f3Smrg{
817ec681f3Smrg   return ( ((F) * 65536.0f > INT_MAX) ? INT_MAX :
827ec681f3Smrg            ((F) * 65536.0f < INT_MIN) ? INT_MIN :
837ec681f3Smrg            (GLint) ((F) * 65536.0f) );
847ec681f3Smrg}
857ec681f3Smrg
867ec681f3Smrgstatic inline GLboolean
877ec681f3SmrgINT_TO_BOOLEAN(GLint I)
887ec681f3Smrg{
897ec681f3Smrg   return ( (I) ? GL_TRUE : GL_FALSE );
907ec681f3Smrg}
917117f1b4Smrg
927ec681f3Smrgstatic inline GLfixed
937ec681f3SmrgINT_TO_FIXED(GLint I)
947ec681f3Smrg{
957ec681f3Smrg   return (((I) > SHRT_MAX) ? INT_MAX :
967ec681f3Smrg           ((I) < SHRT_MIN) ? INT_MIN :
977ec681f3Smrg           (GLint) ((I) * 65536) );
987ec681f3Smrg}
997117f1b4Smrg
1004a49301eSmrg
1017ec681f3Smrgstatic inline GLboolean
1027ec681f3SmrgINT64_TO_BOOLEAN(GLint64 I)
1037ec681f3Smrg{
1047ec681f3Smrg   return ( (I) ? GL_TRUE : GL_FALSE );
1057ec681f3Smrg}
1067117f1b4Smrg
1077ec681f3Smrgstatic inline GLint
1087ec681f3SmrgINT64_TO_INT(GLint64 I)
1097ec681f3Smrg{
1107ec681f3Smrg   return ( (GLint)((I > INT_MAX) ? INT_MAX : ((I < INT_MIN) ? INT_MIN : (I))) );
1117ec681f3Smrg}
1127ec681f3Smrg
1137ec681f3Smrgstatic inline GLint
1147ec681f3SmrgBOOLEAN_TO_INT(GLboolean B)
1157ec681f3Smrg{
1167ec681f3Smrg   return ( (GLint) (B) );
1177ec681f3Smrg}
1187ec681f3Smrg
1197ec681f3Smrgstatic inline GLfloat
1207ec681f3SmrgBOOLEAN_TO_FLOAT(GLboolean B)
1217ec681f3Smrg{
1227ec681f3Smrg   return ( (B) ? 1.0F : 0.0F );
1237ec681f3Smrg}
1247ec681f3Smrg
1257ec681f3Smrgstatic inline GLfixed
1267ec681f3SmrgBOOLEAN_TO_FIXED(GLboolean B)
1277ec681f3Smrg{
1287ec681f3Smrg   return ( (GLint) ((B) ? 1 : 0) << 16 );
1297ec681f3Smrg}
1304a49301eSmrg
1313464ebd5Sriastradhenum value_type {
1323464ebd5Sriastradh   TYPE_INVALID,
1333464ebd5Sriastradh   TYPE_INT,
1343464ebd5Sriastradh   TYPE_INT_2,
1353464ebd5Sriastradh   TYPE_INT_3,
1363464ebd5Sriastradh   TYPE_INT_4,
1373464ebd5Sriastradh   TYPE_INT_N,
13801e04c3fSmrg   TYPE_UINT,
13901e04c3fSmrg   TYPE_UINT_2,
14001e04c3fSmrg   TYPE_UINT_3,
14101e04c3fSmrg   TYPE_UINT_4,
1423464ebd5Sriastradh   TYPE_INT64,
14301e04c3fSmrg   TYPE_ENUM16,
1443464ebd5Sriastradh   TYPE_ENUM,
1453464ebd5Sriastradh   TYPE_ENUM_2,
1463464ebd5Sriastradh   TYPE_BOOLEAN,
14701e04c3fSmrg   TYPE_UBYTE,
14801e04c3fSmrg   TYPE_SHORT,
1493464ebd5Sriastradh   TYPE_BIT_0,
1503464ebd5Sriastradh   TYPE_BIT_1,
1513464ebd5Sriastradh   TYPE_BIT_2,
1523464ebd5Sriastradh   TYPE_BIT_3,
1533464ebd5Sriastradh   TYPE_BIT_4,
1543464ebd5Sriastradh   TYPE_BIT_5,
155af69d88dSmrg   TYPE_BIT_6,
156af69d88dSmrg   TYPE_BIT_7,
1573464ebd5Sriastradh   TYPE_FLOAT,
1583464ebd5Sriastradh   TYPE_FLOAT_2,
1593464ebd5Sriastradh   TYPE_FLOAT_3,
1603464ebd5Sriastradh   TYPE_FLOAT_4,
16101e04c3fSmrg   TYPE_FLOAT_8,
1623464ebd5Sriastradh   TYPE_FLOATN,
1633464ebd5Sriastradh   TYPE_FLOATN_2,
1643464ebd5Sriastradh   TYPE_FLOATN_3,
1653464ebd5Sriastradh   TYPE_FLOATN_4,
1663464ebd5Sriastradh   TYPE_DOUBLEN,
167af69d88dSmrg   TYPE_DOUBLEN_2,
1683464ebd5Sriastradh   TYPE_MATRIX,
1693464ebd5Sriastradh   TYPE_MATRIX_T,
1703464ebd5Sriastradh   TYPE_CONST
1713464ebd5Sriastradh};
1727117f1b4Smrg
1733464ebd5Sriastradhenum value_location {
1743464ebd5Sriastradh   LOC_BUFFER,
1753464ebd5Sriastradh   LOC_CONTEXT,
1763464ebd5Sriastradh   LOC_ARRAY,
1773464ebd5Sriastradh   LOC_TEXUNIT,
1783464ebd5Sriastradh   LOC_CUSTOM
1793464ebd5Sriastradh};
1803464ebd5Sriastradh
1813464ebd5Sriastradhenum value_extra {
1823464ebd5Sriastradh   EXTRA_END = 0x8000,
1833464ebd5Sriastradh   EXTRA_VERSION_30,
1843464ebd5Sriastradh   EXTRA_VERSION_31,
1853464ebd5Sriastradh   EXTRA_VERSION_32,
186af69d88dSmrg   EXTRA_VERSION_40,
18701e04c3fSmrg   EXTRA_VERSION_43,
188af69d88dSmrg   EXTRA_API_GL,
189af69d88dSmrg   EXTRA_API_GL_CORE,
190af69d88dSmrg   EXTRA_API_ES2,
191af69d88dSmrg   EXTRA_API_ES3,
19201e04c3fSmrg   EXTRA_API_ES31,
19301e04c3fSmrg   EXTRA_API_ES32,
19401e04c3fSmrg   EXTRA_NEW_BUFFERS,
1953464ebd5Sriastradh   EXTRA_VALID_DRAW_BUFFER,
1963464ebd5Sriastradh   EXTRA_VALID_TEXTURE_UNIT,
197af69d88dSmrg   EXTRA_VALID_CLIP_DISTANCE,
1983464ebd5Sriastradh   EXTRA_FLUSH_CURRENT,
199af69d88dSmrg   EXTRA_GLSL_130,
20001e04c3fSmrg   EXTRA_EXT_UBO_GS,
20101e04c3fSmrg   EXTRA_EXT_ATOMICS_GS,
20201e04c3fSmrg   EXTRA_EXT_SHADER_IMAGE_GS,
20301e04c3fSmrg   EXTRA_EXT_ATOMICS_TESS,
20401e04c3fSmrg   EXTRA_EXT_SHADER_IMAGE_TESS,
20501e04c3fSmrg   EXTRA_EXT_SSBO_GS,
20601e04c3fSmrg   EXTRA_EXT_FB_NO_ATTACH_GS,
20701e04c3fSmrg   EXTRA_EXT_ES_GS,
20801e04c3fSmrg   EXTRA_EXT_PROVOKING_VERTEX_32,
2093464ebd5Sriastradh};
2103464ebd5Sriastradh
2113464ebd5Sriastradh#define NO_EXTRA NULL
2123464ebd5Sriastradh#define NO_OFFSET 0
2133464ebd5Sriastradh
2143464ebd5Sriastradhstruct value_desc {
2153464ebd5Sriastradh   GLenum pname;
2163464ebd5Sriastradh   GLubyte location;  /**< enum value_location */
2173464ebd5Sriastradh   GLubyte type;      /**< enum value_type */
2183464ebd5Sriastradh   int offset;
2193464ebd5Sriastradh   const int *extra;
2203464ebd5Sriastradh};
2213464ebd5Sriastradh
2223464ebd5Sriastradhunion value {
2233464ebd5Sriastradh   GLfloat value_float;
2243464ebd5Sriastradh   GLfloat value_float_4[4];
225af69d88dSmrg   GLdouble value_double_2[2];
2263464ebd5Sriastradh   GLmatrix *value_matrix;
2273464ebd5Sriastradh   GLint value_int;
2283464ebd5Sriastradh   GLint value_int_4[4];
2293464ebd5Sriastradh   GLint64 value_int64;
2303464ebd5Sriastradh   GLenum value_enum;
2317ec681f3Smrg   GLenum16 value_enum16;
23201e04c3fSmrg   GLubyte value_ubyte;
23301e04c3fSmrg   GLshort value_short;
23401e04c3fSmrg   GLuint value_uint;
2353464ebd5Sriastradh
2363464ebd5Sriastradh   /* Sigh, see GL_COMPRESSED_TEXTURE_FORMATS_ARB handling */
2373464ebd5Sriastradh   struct {
2383464ebd5Sriastradh      GLint n, ints[100];
2393464ebd5Sriastradh   } value_int_n;
2403464ebd5Sriastradh   GLboolean value_bool;
2413464ebd5Sriastradh};
2423464ebd5Sriastradh
2433464ebd5Sriastradh#define BUFFER_FIELD(field, type) \
2443464ebd5Sriastradh   LOC_BUFFER, type, offsetof(struct gl_framebuffer, field)
2453464ebd5Sriastradh#define CONTEXT_FIELD(field, type) \
2463464ebd5Sriastradh   LOC_CONTEXT, type, offsetof(struct gl_context, field)
2473464ebd5Sriastradh#define ARRAY_FIELD(field, type) \
248af69d88dSmrg   LOC_ARRAY, type, offsetof(struct gl_vertex_array_object, field)
249af69d88dSmrg#undef CONST /* already defined through windows.h */
2503464ebd5Sriastradh#define CONST(value) \
2513464ebd5Sriastradh   LOC_CONTEXT, TYPE_CONST, value
2523464ebd5Sriastradh
2533464ebd5Sriastradh#define BUFFER_INT(field) BUFFER_FIELD(field, TYPE_INT)
2543464ebd5Sriastradh#define BUFFER_ENUM(field) BUFFER_FIELD(field, TYPE_ENUM)
25501e04c3fSmrg#define BUFFER_ENUM16(field) BUFFER_FIELD(field, TYPE_ENUM16)
2563464ebd5Sriastradh#define BUFFER_BOOL(field) BUFFER_FIELD(field, TYPE_BOOLEAN)
2573464ebd5Sriastradh
2583464ebd5Sriastradh#define CONTEXT_INT(field) CONTEXT_FIELD(field, TYPE_INT)
2593464ebd5Sriastradh#define CONTEXT_INT2(field) CONTEXT_FIELD(field, TYPE_INT_2)
2603464ebd5Sriastradh#define CONTEXT_INT64(field) CONTEXT_FIELD(field, TYPE_INT64)
26101e04c3fSmrg#define CONTEXT_UINT(field) CONTEXT_FIELD(field, TYPE_UINT)
26201e04c3fSmrg#define CONTEXT_ENUM16(field) CONTEXT_FIELD(field, TYPE_ENUM16)
2633464ebd5Sriastradh#define CONTEXT_ENUM(field) CONTEXT_FIELD(field, TYPE_ENUM)
2643464ebd5Sriastradh#define CONTEXT_ENUM2(field) CONTEXT_FIELD(field, TYPE_ENUM_2)
2653464ebd5Sriastradh#define CONTEXT_BOOL(field) CONTEXT_FIELD(field, TYPE_BOOLEAN)
2663464ebd5Sriastradh#define CONTEXT_BIT0(field) CONTEXT_FIELD(field, TYPE_BIT_0)
2673464ebd5Sriastradh#define CONTEXT_BIT1(field) CONTEXT_FIELD(field, TYPE_BIT_1)
2683464ebd5Sriastradh#define CONTEXT_BIT2(field) CONTEXT_FIELD(field, TYPE_BIT_2)
2693464ebd5Sriastradh#define CONTEXT_BIT3(field) CONTEXT_FIELD(field, TYPE_BIT_3)
2703464ebd5Sriastradh#define CONTEXT_BIT4(field) CONTEXT_FIELD(field, TYPE_BIT_4)
2713464ebd5Sriastradh#define CONTEXT_BIT5(field) CONTEXT_FIELD(field, TYPE_BIT_5)
272af69d88dSmrg#define CONTEXT_BIT6(field) CONTEXT_FIELD(field, TYPE_BIT_6)
273af69d88dSmrg#define CONTEXT_BIT7(field) CONTEXT_FIELD(field, TYPE_BIT_7)
2743464ebd5Sriastradh#define CONTEXT_FLOAT(field) CONTEXT_FIELD(field, TYPE_FLOAT)
2753464ebd5Sriastradh#define CONTEXT_FLOAT2(field) CONTEXT_FIELD(field, TYPE_FLOAT_2)
2763464ebd5Sriastradh#define CONTEXT_FLOAT3(field) CONTEXT_FIELD(field, TYPE_FLOAT_3)
2773464ebd5Sriastradh#define CONTEXT_FLOAT4(field) CONTEXT_FIELD(field, TYPE_FLOAT_4)
27801e04c3fSmrg#define CONTEXT_FLOAT8(field) CONTEXT_FIELD(field, TYPE_FLOAT_8)
2793464ebd5Sriastradh#define CONTEXT_MATRIX(field) CONTEXT_FIELD(field, TYPE_MATRIX)
2803464ebd5Sriastradh#define CONTEXT_MATRIX_T(field) CONTEXT_FIELD(field, TYPE_MATRIX_T)
2813464ebd5Sriastradh
28201e04c3fSmrg/* Vertex array fields */
2833464ebd5Sriastradh#define ARRAY_INT(field) ARRAY_FIELD(field, TYPE_INT)
2843464ebd5Sriastradh#define ARRAY_ENUM(field) ARRAY_FIELD(field, TYPE_ENUM)
28501e04c3fSmrg#define ARRAY_ENUM16(field) ARRAY_FIELD(field, TYPE_ENUM16)
2863464ebd5Sriastradh#define ARRAY_BOOL(field) ARRAY_FIELD(field, TYPE_BOOLEAN)
28701e04c3fSmrg#define ARRAY_UBYTE(field) ARRAY_FIELD(field, TYPE_UBYTE)
28801e04c3fSmrg#define ARRAY_SHORT(field) ARRAY_FIELD(field, TYPE_SHORT)
2893464ebd5Sriastradh
2903464ebd5Sriastradh#define EXT(f)					\
2913464ebd5Sriastradh   offsetof(struct gl_extensions, f)
2923464ebd5Sriastradh
2933464ebd5Sriastradh#define EXTRA_EXT(e)				\
2943464ebd5Sriastradh   static const int extra_##e[] = {		\
2953464ebd5Sriastradh      EXT(e), EXTRA_END				\
2967117f1b4Smrg   }
2977117f1b4Smrg
2983464ebd5Sriastradh#define EXTRA_EXT2(e1, e2)			\
2993464ebd5Sriastradh   static const int extra_##e1##_##e2[] = {	\
3003464ebd5Sriastradh      EXT(e1), EXT(e2), EXTRA_END		\
3013464ebd5Sriastradh   }
3023464ebd5Sriastradh
3033464ebd5Sriastradh/* The 'extra' mechanism is a way to specify extra checks (such as
3043464ebd5Sriastradh * extensions or specific gl versions) or actions (flush current, new
3053464ebd5Sriastradh * buffers) that we need to do before looking up an enum.  We need to
3063464ebd5Sriastradh * declare them all up front so we can refer to them in the value_desc
307af69d88dSmrg * structs below.
308af69d88dSmrg *
309af69d88dSmrg * Each EXTRA_ will be executed.  For EXTRA_* enums of extensions and API
310af69d88dSmrg * versions, listing multiple ones in an array means an error will be thrown
311af69d88dSmrg * only if none of them are available.  If you need to check for "AND"
312af69d88dSmrg * behavior, you would need to make a custom EXTRA_ enum.
313af69d88dSmrg */
3143464ebd5Sriastradh
3153464ebd5Sriastradhstatic const int extra_new_buffers[] = {
3163464ebd5Sriastradh   EXTRA_NEW_BUFFERS,
3173464ebd5Sriastradh   EXTRA_END
3183464ebd5Sriastradh};
3193464ebd5Sriastradh
3203464ebd5Sriastradhstatic const int extra_valid_draw_buffer[] = {
3213464ebd5Sriastradh   EXTRA_VALID_DRAW_BUFFER,
3223464ebd5Sriastradh   EXTRA_END
3233464ebd5Sriastradh};
3243464ebd5Sriastradh
3253464ebd5Sriastradhstatic const int extra_valid_texture_unit[] = {
3263464ebd5Sriastradh   EXTRA_VALID_TEXTURE_UNIT,
3273464ebd5Sriastradh   EXTRA_END
3283464ebd5Sriastradh};
3293464ebd5Sriastradh
330af69d88dSmrgstatic const int extra_valid_clip_distance[] = {
331af69d88dSmrg   EXTRA_VALID_CLIP_DISTANCE,
332af69d88dSmrg   EXTRA_END
333af69d88dSmrg};
334af69d88dSmrg
3353464ebd5Sriastradhstatic const int extra_flush_current_valid_texture_unit[] = {
3363464ebd5Sriastradh   EXTRA_FLUSH_CURRENT,
3373464ebd5Sriastradh   EXTRA_VALID_TEXTURE_UNIT,
3383464ebd5Sriastradh   EXTRA_END
3393464ebd5Sriastradh};
3403464ebd5Sriastradh
3413464ebd5Sriastradhstatic const int extra_flush_current[] = {
3423464ebd5Sriastradh   EXTRA_FLUSH_CURRENT,
3433464ebd5Sriastradh   EXTRA_END
3443464ebd5Sriastradh};
3453464ebd5Sriastradh
346af69d88dSmrgstatic const int extra_EXT_texture_integer_and_new_buffers[] = {
347af69d88dSmrg   EXT(EXT_texture_integer),
3483464ebd5Sriastradh   EXTRA_NEW_BUFFERS,
3493464ebd5Sriastradh   EXTRA_END
3503464ebd5Sriastradh};
3513464ebd5Sriastradh
352b9abf16eSmayastatic const int extra_GLSL_130_es3_gpushader4[] = {
353af69d88dSmrg   EXTRA_GLSL_130,
354af69d88dSmrg   EXTRA_API_ES3,
355b9abf16eSmaya   EXT(EXT_gpu_shader4),
3563464ebd5Sriastradh   EXTRA_END
3573464ebd5Sriastradh};
3583464ebd5Sriastradh
359af69d88dSmrgstatic const int extra_texture_buffer_object[] = {
360af69d88dSmrg   EXT(ARB_texture_buffer_object),
3613464ebd5Sriastradh   EXTRA_END
3623464ebd5Sriastradh};
3633464ebd5Sriastradh
364af69d88dSmrgstatic const int extra_ARB_transform_feedback2_api_es3[] = {
365af69d88dSmrg   EXT(ARB_transform_feedback2),
366af69d88dSmrg   EXTRA_API_ES3,
3673464ebd5Sriastradh   EXTRA_END
3683464ebd5Sriastradh};
3693464ebd5Sriastradh
370af69d88dSmrgstatic const int extra_ARB_uniform_buffer_object_and_geometry_shader[] = {
37101e04c3fSmrg   EXTRA_EXT_UBO_GS,
3723464ebd5Sriastradh   EXTRA_END
3733464ebd5Sriastradh};
3743464ebd5Sriastradh
375af69d88dSmrgstatic const int extra_ARB_ES2_compatibility_api_es2[] = {
376af69d88dSmrg   EXT(ARB_ES2_compatibility),
377af69d88dSmrg   EXTRA_API_ES2,
3783464ebd5Sriastradh   EXTRA_END
3793464ebd5Sriastradh};
3803464ebd5Sriastradh
381af69d88dSmrgstatic const int extra_ARB_ES3_compatibility_api_es3[] = {
382af69d88dSmrg   EXT(ARB_ES3_compatibility),
383af69d88dSmrg   EXTRA_API_ES3,
384af69d88dSmrg   EXTRA_END
385af69d88dSmrg};
386af69d88dSmrg
387af69d88dSmrgstatic const int extra_EXT_framebuffer_sRGB_and_new_buffers[] = {
388af69d88dSmrg   EXT(EXT_framebuffer_sRGB),
389af69d88dSmrg   EXTRA_NEW_BUFFERS,
390af69d88dSmrg   EXTRA_END
391af69d88dSmrg};
392af69d88dSmrg
393af69d88dSmrgstatic const int extra_EXT_packed_float[] = {
394af69d88dSmrg   EXT(EXT_packed_float),
395af69d88dSmrg   EXTRA_NEW_BUFFERS,
396af69d88dSmrg   EXTRA_END
397af69d88dSmrg};
398af69d88dSmrg
399af69d88dSmrgstatic const int extra_EXT_texture_array_es3[] = {
400af69d88dSmrg   EXT(EXT_texture_array),
401af69d88dSmrg   EXTRA_API_ES3,
402af69d88dSmrg   EXTRA_END
403af69d88dSmrg};
404af69d88dSmrg
405af69d88dSmrgstatic const int extra_ARB_shader_atomic_counters_and_geometry_shader[] = {
40601e04c3fSmrg   EXTRA_EXT_ATOMICS_GS,
407af69d88dSmrg   EXTRA_END
408af69d88dSmrg};
409af69d88dSmrg
4107ec681f3Smrgstatic const int extra_ARB_shader_atomic_counters_es31[] = {
4117ec681f3Smrg   EXT(ARB_shader_atomic_counters),
4127ec681f3Smrg   EXTRA_API_ES31,
4137ec681f3Smrg   EXTRA_END
4147ec681f3Smrg};
4157ec681f3Smrg
416af69d88dSmrgstatic const int extra_ARB_shader_image_load_store_and_geometry_shader[] = {
41701e04c3fSmrg   EXTRA_EXT_SHADER_IMAGE_GS,
41801e04c3fSmrg   EXTRA_END
41901e04c3fSmrg};
42001e04c3fSmrg
42101e04c3fSmrgstatic const int extra_ARB_shader_atomic_counters_and_tessellation[] = {
42201e04c3fSmrg   EXTRA_EXT_ATOMICS_TESS,
42301e04c3fSmrg   EXTRA_END
42401e04c3fSmrg};
42501e04c3fSmrg
42601e04c3fSmrgstatic const int extra_ARB_shader_image_load_store_and_tessellation[] = {
42701e04c3fSmrg   EXTRA_EXT_SHADER_IMAGE_TESS,
42801e04c3fSmrg   EXTRA_END
42901e04c3fSmrg};
43001e04c3fSmrg
4317ec681f3Smrgstatic const int extra_ARB_shader_image_load_store_es31[] = {
4327ec681f3Smrg   EXT(ARB_shader_image_load_store),
4337ec681f3Smrg   EXTRA_API_ES31,
4347ec681f3Smrg   EXTRA_END
4357ec681f3Smrg};
4367ec681f3Smrg
43701e04c3fSmrg/* HACK: remove when ARB_compute_shader is actually supported */
43801e04c3fSmrgstatic const int extra_ARB_compute_shader_es31[] = {
43901e04c3fSmrg   EXT(ARB_compute_shader),
44001e04c3fSmrg   EXTRA_API_ES31,
44101e04c3fSmrg   EXTRA_END
44201e04c3fSmrg};
44301e04c3fSmrg
44401e04c3fSmrgstatic const int extra_ARB_shader_storage_buffer_object_es31[] = {
44501e04c3fSmrg   EXT(ARB_shader_storage_buffer_object),
44601e04c3fSmrg   EXTRA_API_ES31,
44701e04c3fSmrg   EXTRA_END
44801e04c3fSmrg};
44901e04c3fSmrg
45001e04c3fSmrgstatic const int extra_ARB_shader_storage_buffer_object_and_geometry_shader[] = {
45101e04c3fSmrg   EXTRA_EXT_SSBO_GS,
45201e04c3fSmrg   EXTRA_END
45301e04c3fSmrg};
45401e04c3fSmrg
45501e04c3fSmrgstatic const int extra_ARB_shader_image_load_store_shader_storage_buffer_object_es31[] = {
45601e04c3fSmrg   EXT(ARB_shader_image_load_store),
45701e04c3fSmrg   EXT(ARB_shader_storage_buffer_object),
45801e04c3fSmrg   EXTRA_API_ES31,
45901e04c3fSmrg   EXTRA_END
46001e04c3fSmrg};
46101e04c3fSmrg
46201e04c3fSmrgstatic const int extra_ARB_framebuffer_no_attachments_and_geometry_shader[] = {
46301e04c3fSmrg   EXTRA_EXT_FB_NO_ATTACH_GS,
46401e04c3fSmrg   EXTRA_END
46501e04c3fSmrg};
46601e04c3fSmrg
46701e04c3fSmrgstatic const int extra_ARB_viewport_array_or_oes_geometry_shader[] = {
46801e04c3fSmrg   EXT(ARB_viewport_array),
46901e04c3fSmrg   EXTRA_EXT_ES_GS,
47001e04c3fSmrg   EXTRA_END
47101e04c3fSmrg};
47201e04c3fSmrg
47301e04c3fSmrgstatic const int extra_ARB_viewport_array_or_oes_viewport_array[] = {
47401e04c3fSmrg   EXT(ARB_viewport_array),
47501e04c3fSmrg   EXT(OES_viewport_array),
47601e04c3fSmrg   EXTRA_END
47701e04c3fSmrg};
47801e04c3fSmrg
47901e04c3fSmrgstatic const int extra_ARB_gpu_shader5_or_oes_geometry_shader[] = {
48001e04c3fSmrg   EXT(ARB_gpu_shader5),
48101e04c3fSmrg   EXTRA_EXT_ES_GS,
48201e04c3fSmrg   EXTRA_END
48301e04c3fSmrg};
48401e04c3fSmrg
48501e04c3fSmrgstatic const int extra_ARB_gpu_shader5_or_OES_sample_variables[] = {
48601e04c3fSmrg   EXT(ARB_gpu_shader5),
48701e04c3fSmrg   EXT(OES_sample_variables),
48801e04c3fSmrg   EXTRA_END
48901e04c3fSmrg};
49001e04c3fSmrg
49101e04c3fSmrgstatic const int extra_ES32[] = {
49201e04c3fSmrg   EXT(ARB_ES3_2_compatibility),
49301e04c3fSmrg   EXTRA_API_ES32,
49401e04c3fSmrg   EXTRA_END
49501e04c3fSmrg};
49601e04c3fSmrg
49701e04c3fSmrgstatic const int extra_KHR_robustness_or_GL[] = {
49801e04c3fSmrg   EXT(KHR_robustness),
49901e04c3fSmrg   EXTRA_API_GL,
50001e04c3fSmrg   EXTRA_API_GL_CORE,
50101e04c3fSmrg   EXTRA_END
50201e04c3fSmrg};
50301e04c3fSmrg
50401e04c3fSmrgstatic const int extra_INTEL_conservative_rasterization[] = {
50501e04c3fSmrg   EXT(INTEL_conservative_rasterization),
506af69d88dSmrg   EXTRA_END
507af69d88dSmrg};
5083464ebd5Sriastradh
5097ec681f3Smrgstatic const int extra_ARB_timer_query_or_EXT_disjoint_timer_query[] = {
5107ec681f3Smrg   EXT(ARB_timer_query),
5117ec681f3Smrg   EXT(EXT_disjoint_timer_query),
5127ec681f3Smrg   EXTRA_END
5137ec681f3Smrg};
5147ec681f3Smrg
5153464ebd5SriastradhEXTRA_EXT(ARB_texture_cube_map);
516af69d88dSmrgEXTRA_EXT(EXT_texture_array);
517af69d88dSmrgEXTRA_EXT(NV_fog_distance);
5183464ebd5SriastradhEXTRA_EXT(EXT_texture_filter_anisotropic);
5193464ebd5SriastradhEXTRA_EXT(NV_texture_rectangle);
5203464ebd5SriastradhEXTRA_EXT(EXT_stencil_two_side);
5213464ebd5SriastradhEXTRA_EXT(EXT_depth_bounds_test);
5223464ebd5SriastradhEXTRA_EXT(ARB_depth_clamp);
52301e04c3fSmrgEXTRA_EXT(AMD_depth_clamp_separate);
5243464ebd5SriastradhEXTRA_EXT(ATI_fragment_shader);
5253464ebd5SriastradhEXTRA_EXT(EXT_provoking_vertex);
5263464ebd5SriastradhEXTRA_EXT(ARB_fragment_shader);
5273464ebd5SriastradhEXTRA_EXT(ARB_fragment_program);
5283464ebd5SriastradhEXTRA_EXT2(ARB_framebuffer_object, EXT_framebuffer_multisample);
5293464ebd5SriastradhEXTRA_EXT(ARB_seamless_cube_map);
5303464ebd5SriastradhEXTRA_EXT(ARB_sync);
5313464ebd5SriastradhEXTRA_EXT(ARB_vertex_shader);
5323464ebd5SriastradhEXTRA_EXT(EXT_transform_feedback);
533af69d88dSmrgEXTRA_EXT(ARB_transform_feedback3);
5343464ebd5SriastradhEXTRA_EXT(EXT_pixel_buffer_object);
5353464ebd5SriastradhEXTRA_EXT(ARB_vertex_program);
5367ec681f3SmrgEXTRA_EXT(ARB_point_sprite);
5373464ebd5SriastradhEXTRA_EXT2(ARB_vertex_program, ARB_fragment_program);
538af69d88dSmrgEXTRA_EXT(ARB_color_buffer_float);
5393464ebd5SriastradhEXTRA_EXT(EXT_framebuffer_sRGB);
540af69d88dSmrgEXTRA_EXT(OES_EGL_image_external);
541af69d88dSmrgEXTRA_EXT(ARB_blend_func_extended);
542af69d88dSmrgEXTRA_EXT(ARB_uniform_buffer_object);
54301e04c3fSmrgEXTRA_EXT2(ARB_texture_cube_map_array, OES_texture_cube_map_array);
544af69d88dSmrgEXTRA_EXT(ARB_texture_buffer_range);
545af69d88dSmrgEXTRA_EXT(ARB_texture_multisample);
546af69d88dSmrgEXTRA_EXT(ARB_texture_gather);
547af69d88dSmrgEXTRA_EXT(ARB_draw_indirect);
548af69d88dSmrgEXTRA_EXT(ARB_shader_image_load_store);
54901e04c3fSmrgEXTRA_EXT(ARB_query_buffer_object);
550af69d88dSmrgEXTRA_EXT2(ARB_transform_feedback3, ARB_gpu_shader5);
551af69d88dSmrgEXTRA_EXT(INTEL_performance_query);
552af69d88dSmrgEXTRA_EXT(ARB_explicit_uniform_location);
55301e04c3fSmrgEXTRA_EXT(ARB_clip_control);
55401e04c3fSmrgEXTRA_EXT(ARB_polygon_offset_clamp);
55501e04c3fSmrgEXTRA_EXT(ARB_framebuffer_no_attachments);
55601e04c3fSmrgEXTRA_EXT(ARB_tessellation_shader);
55701e04c3fSmrgEXTRA_EXT(ARB_shader_storage_buffer_object);
55801e04c3fSmrgEXTRA_EXT(ARB_indirect_parameters);
55901e04c3fSmrgEXTRA_EXT(ATI_meminfo);
56001e04c3fSmrgEXTRA_EXT(NVX_gpu_memory_info);
56101e04c3fSmrgEXTRA_EXT(ARB_cull_distance);
56201e04c3fSmrgEXTRA_EXT(EXT_window_rectangles);
56301e04c3fSmrgEXTRA_EXT(KHR_blend_equation_advanced_coherent);
56401e04c3fSmrgEXTRA_EXT(OES_primitive_bounding_box);
56501e04c3fSmrgEXTRA_EXT(ARB_compute_variable_group_size);
56601e04c3fSmrgEXTRA_EXT(KHR_robustness);
56701e04c3fSmrgEXTRA_EXT(ARB_sparse_buffer);
56801e04c3fSmrgEXTRA_EXT(NV_conservative_raster);
56901e04c3fSmrgEXTRA_EXT(NV_conservative_raster_dilate);
57001e04c3fSmrgEXTRA_EXT(NV_conservative_raster_pre_snap_triangles);
57101e04c3fSmrgEXTRA_EXT(ARB_sample_locations);
57201e04c3fSmrgEXTRA_EXT(AMD_framebuffer_multisample_advanced);
5737ec681f3SmrgEXTRA_EXT(ARB_spirv_extensions);
5747ec681f3SmrgEXTRA_EXT(NV_viewport_swizzle);
5753464ebd5Sriastradh
5763464ebd5Sriastradhstatic const int
577af69d88dSmrgextra_ARB_color_buffer_float_or_glcore[] = {
578af69d88dSmrg   EXT(ARB_color_buffer_float),
579af69d88dSmrg   EXTRA_API_GL_CORE,
5803464ebd5Sriastradh   EXTRA_END
5813464ebd5Sriastradh};
5823464ebd5Sriastradh
5833464ebd5Sriastradhstatic const int
5843464ebd5Sriastradhextra_NV_primitive_restart[] = {
5853464ebd5Sriastradh   EXT(NV_primitive_restart),
5863464ebd5Sriastradh   EXTRA_END
5873464ebd5Sriastradh};
5883464ebd5Sriastradh
5893464ebd5Sriastradhstatic const int extra_version_30[] = { EXTRA_VERSION_30, EXTRA_END };
5903464ebd5Sriastradhstatic const int extra_version_31[] = { EXTRA_VERSION_31, EXTRA_END };
5913464ebd5Sriastradhstatic const int extra_version_32[] = { EXTRA_VERSION_32, EXTRA_END };
59201e04c3fSmrgstatic const int extra_version_43[] = { EXTRA_VERSION_43, EXTRA_END };
593af69d88dSmrg
594af69d88dSmrgstatic const int extra_gl30_es3[] = {
595af69d88dSmrg    EXTRA_VERSION_30,
596af69d88dSmrg    EXTRA_API_ES3,
597af69d88dSmrg    EXTRA_END,
598af69d88dSmrg};
599af69d88dSmrg
600af69d88dSmrgstatic const int extra_gl32_es3[] = {
601af69d88dSmrg    EXTRA_VERSION_32,
602af69d88dSmrg    EXTRA_API_ES3,
603af69d88dSmrg    EXTRA_END,
604af69d88dSmrg};
605af69d88dSmrg
60601e04c3fSmrgstatic const int extra_version_32_OES_geometry_shader[] = {
607af69d88dSmrg    EXTRA_VERSION_32,
60801e04c3fSmrg    EXTRA_EXT_ES_GS,
609af69d88dSmrg    EXTRA_END
610af69d88dSmrg};
611af69d88dSmrg
612af69d88dSmrgstatic const int extra_gl40_ARB_sample_shading[] = {
613af69d88dSmrg   EXTRA_VERSION_40,
614af69d88dSmrg   EXT(ARB_sample_shading),
615af69d88dSmrg   EXTRA_END
616af69d88dSmrg};
6173464ebd5Sriastradh
6183464ebd5Sriastradhstatic const int
619af69d88dSmrgextra_ARB_vertex_program_api_es2[] = {
6203464ebd5Sriastradh   EXT(ARB_vertex_program),
621af69d88dSmrg   EXTRA_API_ES2,
622af69d88dSmrg   EXTRA_END
623af69d88dSmrg};
624af69d88dSmrg
625af69d88dSmrg/* The ReadBuffer get token is valid under either full GL or under
626af69d88dSmrg * GLES2 if the NV_read_buffer extension is available. */
627af69d88dSmrgstatic const int
628af69d88dSmrgextra_NV_read_buffer_api_gl[] = {
629af69d88dSmrg   EXTRA_API_ES2,
630af69d88dSmrg   EXTRA_API_GL,
6313464ebd5Sriastradh   EXTRA_END
6323464ebd5Sriastradh};
6333464ebd5Sriastradh
634af69d88dSmrgstatic const int extra_core_ARB_color_buffer_float_and_new_buffers[] = {
635af69d88dSmrg   EXTRA_API_GL_CORE,
636af69d88dSmrg   EXT(ARB_color_buffer_float),
637af69d88dSmrg   EXTRA_NEW_BUFFERS,
638af69d88dSmrg   EXTRA_END
639af69d88dSmrg};
6403464ebd5Sriastradh
64101e04c3fSmrgstatic const int extra_EXT_shader_framebuffer_fetch[] = {
64201e04c3fSmrg   EXTRA_API_ES2,
64301e04c3fSmrg   EXTRA_API_ES3,
64401e04c3fSmrg   EXT(EXT_shader_framebuffer_fetch),
64501e04c3fSmrg   EXTRA_END
64601e04c3fSmrg};
64701e04c3fSmrg
64801e04c3fSmrgstatic const int extra_EXT_provoking_vertex_32[] = {
64901e04c3fSmrg   EXTRA_EXT_PROVOKING_VERTEX_32,
65001e04c3fSmrg   EXTRA_END
65101e04c3fSmrg};
65201e04c3fSmrg
65301e04c3fSmrgstatic const int extra_EXT_disjoint_timer_query[] = {
65401e04c3fSmrg   EXTRA_API_ES2,
65501e04c3fSmrg   EXTRA_API_ES3,
65601e04c3fSmrg   EXT(EXT_disjoint_timer_query),
65701e04c3fSmrg   EXTRA_END
65801e04c3fSmrg};
65901e04c3fSmrg
66001e04c3fSmrg
6613464ebd5Sriastradh/* This is the big table describing all the enums we accept in
6623464ebd5Sriastradh * glGet*v().  The table is partitioned into six parts: enums
6633464ebd5Sriastradh * understood by all GL APIs (OpenGL, GLES and GLES2), enums shared
6643464ebd5Sriastradh * between OpenGL and GLES, enums exclusive to GLES, etc for the
665af69d88dSmrg * remaining combinations. To look up the enums valid in a given API
666af69d88dSmrg * we will use a hash table specific to that API. These tables are in
667af69d88dSmrg * turn generated at build time and included through get_hash.h.
668af69d88dSmrg */
6693464ebd5Sriastradh
670af69d88dSmrg#include "get_hash.h"
6713464ebd5Sriastradh
6723464ebd5Sriastradh/* All we need now is a way to look up the value struct from the enum.
6733464ebd5Sriastradh * The code generated by gcc for the old generated big switch
6743464ebd5Sriastradh * statement is a big, balanced, open coded if/else tree, essentially
6753464ebd5Sriastradh * an unrolled binary search.  It would be natural to sort the new
6763464ebd5Sriastradh * enum table and use bsearch(), but we will use a read-only hash
6773464ebd5Sriastradh * table instead.  bsearch() has a nice guaranteed worst case
6783464ebd5Sriastradh * performance, but we're also guaranteed to hit that worst case
6793464ebd5Sriastradh * (log2(n) iterations) for about half the enums.  Instead, using an
6803464ebd5Sriastradh * open addressing hash table, we can find the enum on the first try
6813464ebd5Sriastradh * for 80% of the enums, 1 collision for 10% and never more than 5
6823464ebd5Sriastradh * collisions for any enum (typical numbers).  And the code is very
6833464ebd5Sriastradh * simple, even though it feels a little magic. */
6843464ebd5Sriastradh
6853464ebd5Sriastradh/**
6863464ebd5Sriastradh * Handle irregular enums
6873464ebd5Sriastradh *
6883464ebd5Sriastradh * Some values don't conform to the "well-known type at context
6893464ebd5Sriastradh * pointer + offset" pattern, so we have this function to catch all
6903464ebd5Sriastradh * the corner cases.  Typically, it's a computed value or a one-off
6913464ebd5Sriastradh * pointer to a custom struct or something.
6923464ebd5Sriastradh *
6933464ebd5Sriastradh * In this case we can't return a pointer to the value, so we'll have
6943464ebd5Sriastradh * to use the temporary variable 'v' declared back in the calling
6953464ebd5Sriastradh * glGet*v() function to store the result.
6963464ebd5Sriastradh *
6973464ebd5Sriastradh * \param ctx the current context
6983464ebd5Sriastradh * \param d the struct value_desc that describes the enum
6993464ebd5Sriastradh * \param v pointer to the tmp declared in the calling glGet*v() function
7003464ebd5Sriastradh */
7013464ebd5Sriastradhstatic void
7023464ebd5Sriastradhfind_custom_value(struct gl_context *ctx, const struct value_desc *d, union value *v)
7033464ebd5Sriastradh{
7047ec681f3Smrg   struct gl_buffer_object **buffer_obj, *buf;
70501e04c3fSmrg   struct gl_array_attributes *array;
7063464ebd5Sriastradh   GLuint unit, *p;
7073464ebd5Sriastradh
7083464ebd5Sriastradh   switch (d->pname) {
709af69d88dSmrg   case GL_MAJOR_VERSION:
710af69d88dSmrg      v->value_int = ctx->Version / 10;
711af69d88dSmrg      break;
712af69d88dSmrg   case GL_MINOR_VERSION:
713af69d88dSmrg      v->value_int = ctx->Version % 10;
714af69d88dSmrg      break;
715af69d88dSmrg
7163464ebd5Sriastradh   case GL_TEXTURE_1D:
7173464ebd5Sriastradh   case GL_TEXTURE_2D:
7183464ebd5Sriastradh   case GL_TEXTURE_3D:
71901e04c3fSmrg   case GL_TEXTURE_CUBE_MAP:
7203464ebd5Sriastradh   case GL_TEXTURE_RECTANGLE_NV:
721af69d88dSmrg   case GL_TEXTURE_EXTERNAL_OES:
7223464ebd5Sriastradh      v->value_bool = _mesa_IsEnabled(d->pname);
7233464ebd5Sriastradh      break;
7243464ebd5Sriastradh
7253464ebd5Sriastradh   case GL_LINE_STIPPLE_PATTERN:
7263464ebd5Sriastradh      /* This is the only GLushort, special case it here by promoting
7273464ebd5Sriastradh       * to an int rather than introducing a new type. */
7283464ebd5Sriastradh      v->value_int = ctx->Line.StipplePattern;
7293464ebd5Sriastradh      break;
7303464ebd5Sriastradh
7313464ebd5Sriastradh   case GL_CURRENT_RASTER_TEXTURE_COORDS:
7323464ebd5Sriastradh      unit = ctx->Texture.CurrentUnit;
7333464ebd5Sriastradh      v->value_float_4[0] = ctx->Current.RasterTexCoords[unit][0];
7343464ebd5Sriastradh      v->value_float_4[1] = ctx->Current.RasterTexCoords[unit][1];
7353464ebd5Sriastradh      v->value_float_4[2] = ctx->Current.RasterTexCoords[unit][2];
7363464ebd5Sriastradh      v->value_float_4[3] = ctx->Current.RasterTexCoords[unit][3];
7373464ebd5Sriastradh      break;
7383464ebd5Sriastradh
7393464ebd5Sriastradh   case GL_CURRENT_TEXTURE_COORDS:
7403464ebd5Sriastradh      unit = ctx->Texture.CurrentUnit;
7413464ebd5Sriastradh      v->value_float_4[0] = ctx->Current.Attrib[VERT_ATTRIB_TEX0 + unit][0];
7423464ebd5Sriastradh      v->value_float_4[1] = ctx->Current.Attrib[VERT_ATTRIB_TEX0 + unit][1];
7433464ebd5Sriastradh      v->value_float_4[2] = ctx->Current.Attrib[VERT_ATTRIB_TEX0 + unit][2];
7443464ebd5Sriastradh      v->value_float_4[3] = ctx->Current.Attrib[VERT_ATTRIB_TEX0 + unit][3];
7453464ebd5Sriastradh      break;
7463464ebd5Sriastradh
7473464ebd5Sriastradh   case GL_COLOR_WRITEMASK:
74801e04c3fSmrg      v->value_int_4[0] = GET_COLORMASK_BIT(ctx->Color.ColorMask, 0, 0);
74901e04c3fSmrg      v->value_int_4[1] = GET_COLORMASK_BIT(ctx->Color.ColorMask, 0, 1);
75001e04c3fSmrg      v->value_int_4[2] = GET_COLORMASK_BIT(ctx->Color.ColorMask, 0, 2);
75101e04c3fSmrg      v->value_int_4[3] = GET_COLORMASK_BIT(ctx->Color.ColorMask, 0, 3);
75201e04c3fSmrg      break;
75301e04c3fSmrg
75401e04c3fSmrg   case GL_DEPTH_CLAMP:
75501e04c3fSmrg      v->value_bool = ctx->Transform.DepthClampNear || ctx->Transform.DepthClampFar;
7563464ebd5Sriastradh      break;
7573464ebd5Sriastradh
7583464ebd5Sriastradh   case GL_EDGE_FLAG:
75901e04c3fSmrg      v->value_bool = ctx->Current.Attrib[VERT_ATTRIB_EDGEFLAG][0] == 1.0F;
7603464ebd5Sriastradh      break;
7613464ebd5Sriastradh
7623464ebd5Sriastradh   case GL_READ_BUFFER:
7637ec681f3Smrg      v->value_enum16 = ctx->ReadBuffer->ColorReadBuffer;
7643464ebd5Sriastradh      break;
7653464ebd5Sriastradh
7663464ebd5Sriastradh   case GL_MAP2_GRID_DOMAIN:
7673464ebd5Sriastradh      v->value_float_4[0] = ctx->Eval.MapGrid2u1;
7683464ebd5Sriastradh      v->value_float_4[1] = ctx->Eval.MapGrid2u2;
7693464ebd5Sriastradh      v->value_float_4[2] = ctx->Eval.MapGrid2v1;
7703464ebd5Sriastradh      v->value_float_4[3] = ctx->Eval.MapGrid2v2;
7713464ebd5Sriastradh      break;
7723464ebd5Sriastradh
7733464ebd5Sriastradh   case GL_TEXTURE_STACK_DEPTH:
7743464ebd5Sriastradh      unit = ctx->Texture.CurrentUnit;
7753464ebd5Sriastradh      v->value_int = ctx->TextureMatrixStack[unit].Depth + 1;
7763464ebd5Sriastradh      break;
7773464ebd5Sriastradh   case GL_TEXTURE_MATRIX:
7783464ebd5Sriastradh      unit = ctx->Texture.CurrentUnit;
7793464ebd5Sriastradh      v->value_matrix = ctx->TextureMatrixStack[unit].Top;
7803464ebd5Sriastradh      break;
7813464ebd5Sriastradh
782b9abf16eSmaya   case GL_VERTEX_ARRAY:
783b9abf16eSmaya      v->value_bool = !!(ctx->Array.VAO->Enabled & VERT_BIT_POS);
784b9abf16eSmaya      break;
785b9abf16eSmaya   case GL_NORMAL_ARRAY:
786b9abf16eSmaya      v->value_bool = !!(ctx->Array.VAO->Enabled & VERT_BIT_NORMAL);
787b9abf16eSmaya      break;
788b9abf16eSmaya   case GL_COLOR_ARRAY:
789b9abf16eSmaya      v->value_bool = !!(ctx->Array.VAO->Enabled & VERT_BIT_COLOR0);
790b9abf16eSmaya      break;
7913464ebd5Sriastradh   case GL_TEXTURE_COORD_ARRAY:
792b9abf16eSmaya      v->value_bool = !!(ctx->Array.VAO->Enabled & VERT_BIT_TEX(ctx->Array.ActiveTexture));
793b9abf16eSmaya      break;
794b9abf16eSmaya   case GL_INDEX_ARRAY:
795b9abf16eSmaya      v->value_bool = !!(ctx->Array.VAO->Enabled & VERT_BIT_COLOR_INDEX);
796b9abf16eSmaya      break;
797b9abf16eSmaya   case GL_EDGE_FLAG_ARRAY:
798b9abf16eSmaya      v->value_bool = !!(ctx->Array.VAO->Enabled & VERT_BIT_EDGEFLAG);
799b9abf16eSmaya      break;
800b9abf16eSmaya   case GL_SECONDARY_COLOR_ARRAY:
801b9abf16eSmaya      v->value_bool = !!(ctx->Array.VAO->Enabled & VERT_BIT_COLOR1);
802b9abf16eSmaya      break;
803b9abf16eSmaya   case GL_FOG_COORDINATE_ARRAY:
804b9abf16eSmaya      v->value_bool = !!(ctx->Array.VAO->Enabled & VERT_BIT_FOG);
805b9abf16eSmaya      break;
806b9abf16eSmaya   case GL_POINT_SIZE_ARRAY_OES:
807b9abf16eSmaya      v->value_bool = !!(ctx->Array.VAO->Enabled & VERT_BIT_POINT_SIZE);
808b9abf16eSmaya      break;
809b9abf16eSmaya
8103464ebd5Sriastradh   case GL_TEXTURE_COORD_ARRAY_TYPE:
8113464ebd5Sriastradh   case GL_TEXTURE_COORD_ARRAY_STRIDE:
812af69d88dSmrg      array = &ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_TEX(ctx->Array.ActiveTexture)];
8133464ebd5Sriastradh      v->value_int = *(GLuint *) ((char *) array + d->offset);
8143464ebd5Sriastradh      break;
8153464ebd5Sriastradh
816b9abf16eSmaya   case GL_TEXTURE_COORD_ARRAY_SIZE:
817b9abf16eSmaya      array = &ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_TEX(ctx->Array.ActiveTexture)];
818b9abf16eSmaya      v->value_int = array->Format.Size;
819b9abf16eSmaya      break;
820b9abf16eSmaya
821b9abf16eSmaya   case GL_VERTEX_ARRAY_SIZE:
822b9abf16eSmaya      array = &ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_POS];
823b9abf16eSmaya      v->value_int = array->Format.Size;
824b9abf16eSmaya      break;
825b9abf16eSmaya
8263464ebd5Sriastradh   case GL_ACTIVE_TEXTURE_ARB:
8273464ebd5Sriastradh      v->value_int = GL_TEXTURE0_ARB + ctx->Texture.CurrentUnit;
8283464ebd5Sriastradh      break;
8293464ebd5Sriastradh   case GL_CLIENT_ACTIVE_TEXTURE_ARB:
8303464ebd5Sriastradh      v->value_int = GL_TEXTURE0_ARB + ctx->Array.ActiveTexture;
8313464ebd5Sriastradh      break;
8323464ebd5Sriastradh
8333464ebd5Sriastradh   case GL_MODELVIEW_STACK_DEPTH:
8343464ebd5Sriastradh   case GL_PROJECTION_STACK_DEPTH:
8353464ebd5Sriastradh      v->value_int = *(GLint *) ((char *) ctx + d->offset) + 1;
8363464ebd5Sriastradh      break;
8373464ebd5Sriastradh
8383464ebd5Sriastradh   case GL_MAX_TEXTURE_SIZE:
8393464ebd5Sriastradh   case GL_MAX_3D_TEXTURE_SIZE:
8403464ebd5Sriastradh   case GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB:
8413464ebd5Sriastradh      p = (GLuint *) ((char *) ctx + d->offset);
8423464ebd5Sriastradh      v->value_int = 1 << (*p - 1);
8433464ebd5Sriastradh      break;
8443464ebd5Sriastradh
8453464ebd5Sriastradh   case GL_SCISSOR_BOX:
846af69d88dSmrg      v->value_int_4[0] = ctx->Scissor.ScissorArray[0].X;
847af69d88dSmrg      v->value_int_4[1] = ctx->Scissor.ScissorArray[0].Y;
848af69d88dSmrg      v->value_int_4[2] = ctx->Scissor.ScissorArray[0].Width;
849af69d88dSmrg      v->value_int_4[3] = ctx->Scissor.ScissorArray[0].Height;
850af69d88dSmrg      break;
851af69d88dSmrg
852af69d88dSmrg   case GL_SCISSOR_TEST:
853af69d88dSmrg      v->value_bool = ctx->Scissor.EnableFlags & 1;
8543464ebd5Sriastradh      break;
8553464ebd5Sriastradh
8563464ebd5Sriastradh   case GL_LIST_INDEX:
8573464ebd5Sriastradh      v->value_int =
85801e04c3fSmrg         ctx->ListState.CurrentList ? ctx->ListState.CurrentList->Name : 0;
8593464ebd5Sriastradh      break;
8603464ebd5Sriastradh   case GL_LIST_MODE:
8613464ebd5Sriastradh      if (!ctx->CompileFlag)
8627ec681f3Smrg         v->value_enum16 = 0;
8633464ebd5Sriastradh      else if (ctx->ExecuteFlag)
8647ec681f3Smrg         v->value_enum16 = GL_COMPILE_AND_EXECUTE;
8653464ebd5Sriastradh      else
8667ec681f3Smrg         v->value_enum16 = GL_COMPILE;
8673464ebd5Sriastradh      break;
8683464ebd5Sriastradh
8693464ebd5Sriastradh   case GL_VIEWPORT:
870af69d88dSmrg      v->value_float_4[0] = ctx->ViewportArray[0].X;
871af69d88dSmrg      v->value_float_4[1] = ctx->ViewportArray[0].Y;
872af69d88dSmrg      v->value_float_4[2] = ctx->ViewportArray[0].Width;
873af69d88dSmrg      v->value_float_4[3] = ctx->ViewportArray[0].Height;
874af69d88dSmrg      break;
875af69d88dSmrg
876af69d88dSmrg   case GL_DEPTH_RANGE:
877af69d88dSmrg      v->value_double_2[0] = ctx->ViewportArray[0].Near;
878af69d88dSmrg      v->value_double_2[1] = ctx->ViewportArray[0].Far;
8793464ebd5Sriastradh      break;
8803464ebd5Sriastradh
8813464ebd5Sriastradh   case GL_ACTIVE_STENCIL_FACE_EXT:
8827ec681f3Smrg      v->value_enum16 = ctx->Stencil.ActiveFace ? GL_BACK : GL_FRONT;
8833464ebd5Sriastradh      break;
8843464ebd5Sriastradh
8853464ebd5Sriastradh   case GL_STENCIL_FAIL:
8867ec681f3Smrg      v->value_enum16 = ctx->Stencil.FailFunc[ctx->Stencil.ActiveFace];
8873464ebd5Sriastradh      break;
8883464ebd5Sriastradh   case GL_STENCIL_FUNC:
8897ec681f3Smrg      v->value_enum16 = ctx->Stencil.Function[ctx->Stencil.ActiveFace];
8903464ebd5Sriastradh      break;
8913464ebd5Sriastradh   case GL_STENCIL_PASS_DEPTH_FAIL:
8927ec681f3Smrg      v->value_enum16 = ctx->Stencil.ZFailFunc[ctx->Stencil.ActiveFace];
8933464ebd5Sriastradh      break;
8943464ebd5Sriastradh   case GL_STENCIL_PASS_DEPTH_PASS:
8957ec681f3Smrg      v->value_enum16 = ctx->Stencil.ZPassFunc[ctx->Stencil.ActiveFace];
8963464ebd5Sriastradh      break;
8973464ebd5Sriastradh   case GL_STENCIL_REF:
898af69d88dSmrg      v->value_int = _mesa_get_stencil_ref(ctx, ctx->Stencil.ActiveFace);
899af69d88dSmrg      break;
900af69d88dSmrg   case GL_STENCIL_BACK_REF:
901af69d88dSmrg      v->value_int = _mesa_get_stencil_ref(ctx, 1);
9023464ebd5Sriastradh      break;
9033464ebd5Sriastradh   case GL_STENCIL_VALUE_MASK:
9043464ebd5Sriastradh      v->value_int = ctx->Stencil.ValueMask[ctx->Stencil.ActiveFace];
9053464ebd5Sriastradh      break;
9063464ebd5Sriastradh   case GL_STENCIL_WRITEMASK:
9073464ebd5Sriastradh      v->value_int = ctx->Stencil.WriteMask[ctx->Stencil.ActiveFace];
9083464ebd5Sriastradh      break;
9093464ebd5Sriastradh
9103464ebd5Sriastradh   case GL_NUM_EXTENSIONS:
9113464ebd5Sriastradh      v->value_int = _mesa_get_extension_count(ctx);
9123464ebd5Sriastradh      break;
9133464ebd5Sriastradh
9143464ebd5Sriastradh   case GL_IMPLEMENTATION_COLOR_READ_TYPE_OES:
91501e04c3fSmrg      v->value_int = _mesa_get_color_read_type(ctx, NULL, "glGetIntegerv");
9163464ebd5Sriastradh      break;
9173464ebd5Sriastradh   case GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES:
91801e04c3fSmrg      v->value_int = _mesa_get_color_read_format(ctx, NULL, "glGetIntegerv");
9193464ebd5Sriastradh      break;
9203464ebd5Sriastradh
9213464ebd5Sriastradh   case GL_CURRENT_MATRIX_STACK_DEPTH_ARB:
9223464ebd5Sriastradh      v->value_int = ctx->CurrentStack->Depth + 1;
9233464ebd5Sriastradh      break;
9243464ebd5Sriastradh   case GL_CURRENT_MATRIX_ARB:
9253464ebd5Sriastradh   case GL_TRANSPOSE_CURRENT_MATRIX_ARB:
9263464ebd5Sriastradh      v->value_matrix = ctx->CurrentStack->Top;
9273464ebd5Sriastradh      break;
9283464ebd5Sriastradh
9293464ebd5Sriastradh   case GL_NUM_COMPRESSED_TEXTURE_FORMATS_ARB:
9303464ebd5Sriastradh      v->value_int = _mesa_get_compressed_formats(ctx, NULL);
9313464ebd5Sriastradh      break;
9323464ebd5Sriastradh   case GL_COMPRESSED_TEXTURE_FORMATS_ARB:
93301e04c3fSmrg      v->value_int_n.n =
93401e04c3fSmrg         _mesa_get_compressed_formats(ctx, v->value_int_n.ints);
93501e04c3fSmrg      assert(v->value_int_n.n <= (int) ARRAY_SIZE(v->value_int_n.ints));
9363464ebd5Sriastradh      break;
9373464ebd5Sriastradh
9383464ebd5Sriastradh   case GL_MAX_VARYING_FLOATS_ARB:
9393464ebd5Sriastradh      v->value_int = ctx->Const.MaxVarying * 4;
9403464ebd5Sriastradh      break;
9413464ebd5Sriastradh
9423464ebd5Sriastradh   /* Various object names */
9433464ebd5Sriastradh
9443464ebd5Sriastradh   case GL_TEXTURE_BINDING_1D:
9453464ebd5Sriastradh   case GL_TEXTURE_BINDING_2D:
9463464ebd5Sriastradh   case GL_TEXTURE_BINDING_3D:
9473464ebd5Sriastradh   case GL_TEXTURE_BINDING_1D_ARRAY_EXT:
9483464ebd5Sriastradh   case GL_TEXTURE_BINDING_2D_ARRAY_EXT:
9493464ebd5Sriastradh   case GL_TEXTURE_BINDING_CUBE_MAP_ARB:
9503464ebd5Sriastradh   case GL_TEXTURE_BINDING_RECTANGLE_NV:
951af69d88dSmrg   case GL_TEXTURE_BINDING_EXTERNAL_OES:
952af69d88dSmrg   case GL_TEXTURE_BINDING_CUBE_MAP_ARRAY:
953af69d88dSmrg   case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
954af69d88dSmrg   case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY:
9553464ebd5Sriastradh      unit = ctx->Texture.CurrentUnit;
9563464ebd5Sriastradh      v->value_int =
95701e04c3fSmrg         ctx->Texture.Unit[unit].CurrentTex[d->offset]->Name;
95801e04c3fSmrg      break;
95901e04c3fSmrg
96001e04c3fSmrg   /* GL_EXT_external_objects */
961993e1d59Smrg   case GL_NUM_DEVICE_UUIDS_EXT:
962993e1d59Smrg      v->value_int = 1;
963993e1d59Smrg      break;
96401e04c3fSmrg   case GL_DRIVER_UUID_EXT:
96501e04c3fSmrg      _mesa_get_driver_uuid(ctx, v->value_int_4);
96601e04c3fSmrg      break;
96701e04c3fSmrg   case GL_DEVICE_UUID_EXT:
96801e04c3fSmrg      _mesa_get_device_uuid(ctx, v->value_int_4);
9693464ebd5Sriastradh      break;
9703464ebd5Sriastradh
971af69d88dSmrg   /* GL_EXT_packed_float */
972af69d88dSmrg   case GL_RGBA_SIGNED_COMPONENTS_EXT:
973af69d88dSmrg      {
974af69d88dSmrg         /* Note: we only check the 0th color attachment. */
975af69d88dSmrg         const struct gl_renderbuffer *rb =
976af69d88dSmrg            ctx->DrawBuffer->_ColorDrawBuffers[0];
977af69d88dSmrg         if (rb && _mesa_is_format_signed(rb->Format)) {
978af69d88dSmrg            /* Issue 17 of GL_EXT_packed_float:  If a component (such as
979af69d88dSmrg             * alpha) has zero bits, the component should not be considered
980af69d88dSmrg             * signed and so the bit for the respective component should be
981af69d88dSmrg             * zeroed.
982af69d88dSmrg             */
983af69d88dSmrg            GLint r_bits =
984af69d88dSmrg               _mesa_get_format_bits(rb->Format, GL_RED_BITS);
985af69d88dSmrg            GLint g_bits =
986af69d88dSmrg               _mesa_get_format_bits(rb->Format, GL_GREEN_BITS);
987af69d88dSmrg            GLint b_bits =
988af69d88dSmrg               _mesa_get_format_bits(rb->Format, GL_BLUE_BITS);
989af69d88dSmrg            GLint a_bits =
990af69d88dSmrg               _mesa_get_format_bits(rb->Format, GL_ALPHA_BITS);
991af69d88dSmrg            GLint l_bits =
992af69d88dSmrg               _mesa_get_format_bits(rb->Format, GL_TEXTURE_LUMINANCE_SIZE);
993af69d88dSmrg            GLint i_bits =
994af69d88dSmrg               _mesa_get_format_bits(rb->Format, GL_TEXTURE_INTENSITY_SIZE);
995af69d88dSmrg
996af69d88dSmrg            v->value_int_4[0] = r_bits + l_bits + i_bits > 0;
997af69d88dSmrg            v->value_int_4[1] = g_bits + l_bits + i_bits > 0;
998af69d88dSmrg            v->value_int_4[2] = b_bits + l_bits + i_bits > 0;
999af69d88dSmrg            v->value_int_4[3] = a_bits + i_bits > 0;
1000af69d88dSmrg         }
1001af69d88dSmrg         else {
1002af69d88dSmrg            v->value_int_4[0] =
1003af69d88dSmrg            v->value_int_4[1] =
1004af69d88dSmrg            v->value_int_4[2] =
1005af69d88dSmrg            v->value_int_4[3] = 0;
1006af69d88dSmrg         }
1007af69d88dSmrg      }
1008af69d88dSmrg      break;
1009af69d88dSmrg
10103464ebd5Sriastradh   /* GL_ARB_vertex_buffer_object */
10113464ebd5Sriastradh   case GL_VERTEX_ARRAY_BUFFER_BINDING_ARB:
10123464ebd5Sriastradh   case GL_NORMAL_ARRAY_BUFFER_BINDING_ARB:
10133464ebd5Sriastradh   case GL_COLOR_ARRAY_BUFFER_BINDING_ARB:
10143464ebd5Sriastradh   case GL_INDEX_ARRAY_BUFFER_BINDING_ARB:
10153464ebd5Sriastradh   case GL_EDGE_FLAG_ARRAY_BUFFER_BINDING_ARB:
10163464ebd5Sriastradh   case GL_SECONDARY_COLOR_ARRAY_BUFFER_BINDING_ARB:
10173464ebd5Sriastradh   case GL_FOG_COORDINATE_ARRAY_BUFFER_BINDING_ARB:
10183464ebd5Sriastradh      buffer_obj = (struct gl_buffer_object **)
101901e04c3fSmrg         ((char *) ctx->Array.VAO + d->offset);
10207ec681f3Smrg      v->value_int = (*buffer_obj) ? (*buffer_obj)->Name : 0;
10213464ebd5Sriastradh      break;
10223464ebd5Sriastradh   case GL_ARRAY_BUFFER_BINDING_ARB:
10237ec681f3Smrg      buf = ctx->Array.ArrayBufferObj;
10247ec681f3Smrg      v->value_int = buf ? buf->Name : 0;
10253464ebd5Sriastradh      break;
10263464ebd5Sriastradh   case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING_ARB:
10277ec681f3Smrg      buf = ctx->Array.VAO->BufferBinding[VERT_ATTRIB_TEX(ctx->Array.ActiveTexture)].BufferObj;
10287ec681f3Smrg      v->value_int = buf ? buf->Name : 0;
10293464ebd5Sriastradh      break;
10303464ebd5Sriastradh   case GL_ELEMENT_ARRAY_BUFFER_BINDING_ARB:
10317ec681f3Smrg      buf = ctx->Array.VAO->IndexBufferObj;
10327ec681f3Smrg      v->value_int = buf ? buf->Name : 0;
1033af69d88dSmrg      break;
1034af69d88dSmrg
1035af69d88dSmrg   /* ARB_vertex_array_bgra */
1036af69d88dSmrg   case GL_COLOR_ARRAY_SIZE:
1037af69d88dSmrg      array = &ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_COLOR0];
1038b9abf16eSmaya      v->value_int = array->Format.Format == GL_BGRA ? GL_BGRA : array->Format.Size;
1039af69d88dSmrg      break;
1040af69d88dSmrg   case GL_SECONDARY_COLOR_ARRAY_SIZE:
1041af69d88dSmrg      array = &ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_COLOR1];
1042b9abf16eSmaya      v->value_int = array->Format.Format == GL_BGRA ? GL_BGRA : array->Format.Size;
10433464ebd5Sriastradh      break;
10443464ebd5Sriastradh
10453464ebd5Sriastradh   /* ARB_copy_buffer */
10463464ebd5Sriastradh   case GL_COPY_READ_BUFFER:
10477ec681f3Smrg      v->value_int = ctx->CopyReadBuffer ? ctx->CopyReadBuffer->Name : 0;
10483464ebd5Sriastradh      break;
10493464ebd5Sriastradh   case GL_COPY_WRITE_BUFFER:
10507ec681f3Smrg      v->value_int = ctx->CopyWriteBuffer ? ctx->CopyWriteBuffer->Name : 0;
10513464ebd5Sriastradh      break;
10523464ebd5Sriastradh
10533464ebd5Sriastradh   case GL_PIXEL_PACK_BUFFER_BINDING_EXT:
10547ec681f3Smrg      v->value_int = ctx->Pack.BufferObj ? ctx->Pack.BufferObj->Name : 0;
10553464ebd5Sriastradh      break;
10563464ebd5Sriastradh   case GL_PIXEL_UNPACK_BUFFER_BINDING_EXT:
10577ec681f3Smrg      v->value_int = ctx->Unpack.BufferObj ? ctx->Unpack.BufferObj->Name : 0;
10583464ebd5Sriastradh      break;
10593464ebd5Sriastradh   case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
10607ec681f3Smrg      v->value_int = ctx->TransformFeedback.CurrentBuffer ?
10617ec681f3Smrg                        ctx->TransformFeedback.CurrentBuffer->Name : 0;
10623464ebd5Sriastradh      break;
10633464ebd5Sriastradh   case GL_TRANSFORM_FEEDBACK_BUFFER_PAUSED:
10643464ebd5Sriastradh      v->value_int = ctx->TransformFeedback.CurrentObject->Paused;
10653464ebd5Sriastradh      break;
10663464ebd5Sriastradh   case GL_TRANSFORM_FEEDBACK_BUFFER_ACTIVE:
10673464ebd5Sriastradh      v->value_int = ctx->TransformFeedback.CurrentObject->Active;
10683464ebd5Sriastradh      break;
10693464ebd5Sriastradh   case GL_TRANSFORM_FEEDBACK_BINDING:
10703464ebd5Sriastradh      v->value_int = ctx->TransformFeedback.CurrentObject->Name;
10713464ebd5Sriastradh      break;
10723464ebd5Sriastradh   case GL_CURRENT_PROGRAM:
1073af69d88dSmrg      /* The Changelog of the ARB_separate_shader_objects spec says:
1074af69d88dSmrg       *
1075af69d88dSmrg       * 24 25 Jul 2011  pbrown  Remove the language erroneously deleting
1076af69d88dSmrg       *                         CURRENT_PROGRAM.  In the EXT extension, this
1077af69d88dSmrg       *                         token was aliased to ACTIVE_PROGRAM_EXT, and
1078af69d88dSmrg       *                         was used to indicate the last program set by
1079af69d88dSmrg       *                         either ActiveProgramEXT or UseProgram.  In
1080af69d88dSmrg       *                         the ARB extension, the SSO active programs
1081af69d88dSmrg       *                         are now program pipeline object state and
1082af69d88dSmrg       *                         CURRENT_PROGRAM should still be used to query
1083af69d88dSmrg       *                         the last program set by UseProgram (bug 7822).
1084af69d88dSmrg       */
10853464ebd5Sriastradh      v->value_int =
108601e04c3fSmrg         ctx->Shader.ActiveProgram ? ctx->Shader.ActiveProgram->Name : 0;
10873464ebd5Sriastradh      break;
10883464ebd5Sriastradh   case GL_READ_FRAMEBUFFER_BINDING_EXT:
10893464ebd5Sriastradh      v->value_int = ctx->ReadBuffer->Name;
10903464ebd5Sriastradh      break;
10913464ebd5Sriastradh   case GL_RENDERBUFFER_BINDING_EXT:
10923464ebd5Sriastradh      v->value_int =
109301e04c3fSmrg         ctx->CurrentRenderbuffer ? ctx->CurrentRenderbuffer->Name : 0;
10943464ebd5Sriastradh      break;
10953464ebd5Sriastradh   case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
10967ec681f3Smrg      buf = ctx->Array.VAO->BufferBinding[VERT_ATTRIB_POINT_SIZE].BufferObj;
10977ec681f3Smrg      v->value_int = buf ? buf->Name : 0;
10983464ebd5Sriastradh      break;
10993464ebd5Sriastradh
11003464ebd5Sriastradh   case GL_FOG_COLOR:
110101e04c3fSmrg      if (_mesa_get_clamp_fragment_color(ctx, ctx->DrawBuffer))
11023464ebd5Sriastradh         COPY_4FV(v->value_float_4, ctx->Fog.Color);
11033464ebd5Sriastradh      else
11043464ebd5Sriastradh         COPY_4FV(v->value_float_4, ctx->Fog.ColorUnclamped);
11053464ebd5Sriastradh      break;
11063464ebd5Sriastradh   case GL_COLOR_CLEAR_VALUE:
110701e04c3fSmrg      if (_mesa_get_clamp_fragment_color(ctx, ctx->DrawBuffer)) {
1108af69d88dSmrg         v->value_float_4[0] = CLAMP(ctx->Color.ClearColor.f[0], 0.0F, 1.0F);
1109af69d88dSmrg         v->value_float_4[1] = CLAMP(ctx->Color.ClearColor.f[1], 0.0F, 1.0F);
1110af69d88dSmrg         v->value_float_4[2] = CLAMP(ctx->Color.ClearColor.f[2], 0.0F, 1.0F);
1111af69d88dSmrg         v->value_float_4[3] = CLAMP(ctx->Color.ClearColor.f[3], 0.0F, 1.0F);
1112af69d88dSmrg      } else
1113af69d88dSmrg         COPY_4FV(v->value_float_4, ctx->Color.ClearColor.f);
11143464ebd5Sriastradh      break;
11153464ebd5Sriastradh   case GL_BLEND_COLOR_EXT:
111601e04c3fSmrg      if (_mesa_get_clamp_fragment_color(ctx, ctx->DrawBuffer))
11173464ebd5Sriastradh         COPY_4FV(v->value_float_4, ctx->Color.BlendColor);
11183464ebd5Sriastradh      else
11193464ebd5Sriastradh         COPY_4FV(v->value_float_4, ctx->Color.BlendColorUnclamped);
11203464ebd5Sriastradh      break;
11213464ebd5Sriastradh   case GL_ALPHA_TEST_REF:
112201e04c3fSmrg      if (_mesa_get_clamp_fragment_color(ctx, ctx->DrawBuffer))
11233464ebd5Sriastradh         v->value_float = ctx->Color.AlphaRef;
11243464ebd5Sriastradh      else
11253464ebd5Sriastradh         v->value_float = ctx->Color.AlphaRefUnclamped;
11263464ebd5Sriastradh      break;
11273464ebd5Sriastradh   case GL_MAX_VERTEX_UNIFORM_VECTORS:
1128af69d88dSmrg      v->value_int = ctx->Const.Program[MESA_SHADER_VERTEX].MaxUniformComponents / 4;
11293464ebd5Sriastradh      break;
11303464ebd5Sriastradh
11313464ebd5Sriastradh   case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
1132af69d88dSmrg      v->value_int = ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxUniformComponents / 4;
11333464ebd5Sriastradh      break;
11343464ebd5Sriastradh
11353464ebd5Sriastradh   /* GL_ARB_texture_buffer_object */
11363464ebd5Sriastradh   case GL_TEXTURE_BUFFER_ARB:
11377ec681f3Smrg      v->value_int = ctx->Texture.BufferObject ? ctx->Texture.BufferObject->Name : 0;
11383464ebd5Sriastradh      break;
11393464ebd5Sriastradh   case GL_TEXTURE_BINDING_BUFFER_ARB:
11403464ebd5Sriastradh      unit = ctx->Texture.CurrentUnit;
11413464ebd5Sriastradh      v->value_int =
11423464ebd5Sriastradh         ctx->Texture.Unit[unit].CurrentTex[TEXTURE_BUFFER_INDEX]->Name;
11433464ebd5Sriastradh      break;
11443464ebd5Sriastradh   case GL_TEXTURE_BUFFER_DATA_STORE_BINDING_ARB:
11453464ebd5Sriastradh      {
11463464ebd5Sriastradh         struct gl_buffer_object *buf =
11473464ebd5Sriastradh            ctx->Texture.Unit[ctx->Texture.CurrentUnit]
11483464ebd5Sriastradh            .CurrentTex[TEXTURE_BUFFER_INDEX]->BufferObject;
11493464ebd5Sriastradh         v->value_int = buf ? buf->Name : 0;
11503464ebd5Sriastradh      }
11513464ebd5Sriastradh      break;
11523464ebd5Sriastradh   case GL_TEXTURE_BUFFER_FORMAT_ARB:
11533464ebd5Sriastradh      v->value_int = ctx->Texture.Unit[ctx->Texture.CurrentUnit]
11543464ebd5Sriastradh         .CurrentTex[TEXTURE_BUFFER_INDEX]->BufferObjectFormat;
11553464ebd5Sriastradh      break;
11563464ebd5Sriastradh
11573464ebd5Sriastradh   /* GL_ARB_sampler_objects */
11583464ebd5Sriastradh   case GL_SAMPLER_BINDING:
11593464ebd5Sriastradh      {
11603464ebd5Sriastradh         struct gl_sampler_object *samp =
11613464ebd5Sriastradh            ctx->Texture.Unit[ctx->Texture.CurrentUnit].Sampler;
116201e04c3fSmrg         v->value_int = samp ? samp->Name : 0;
1163af69d88dSmrg      }
1164af69d88dSmrg      break;
1165af69d88dSmrg   /* GL_ARB_uniform_buffer_object */
1166af69d88dSmrg   case GL_UNIFORM_BUFFER_BINDING:
11677ec681f3Smrg      v->value_int = ctx->UniformBuffer ? ctx->UniformBuffer->Name : 0;
1168af69d88dSmrg      break;
116901e04c3fSmrg   /* GL_ARB_shader_storage_buffer_object */
117001e04c3fSmrg   case GL_SHADER_STORAGE_BUFFER_BINDING:
11717ec681f3Smrg      v->value_int = ctx->ShaderStorageBuffer ? ctx->ShaderStorageBuffer->Name : 0;
117201e04c3fSmrg      break;
117301e04c3fSmrg   /* GL_ARB_query_buffer_object */
117401e04c3fSmrg   case GL_QUERY_BUFFER_BINDING:
11757ec681f3Smrg      v->value_int = ctx->QueryBuffer ? ctx->QueryBuffer->Name : 0;
117601e04c3fSmrg      break;
1177af69d88dSmrg   /* GL_ARB_timer_query */
1178af69d88dSmrg   case GL_TIMESTAMP:
1179af69d88dSmrg      if (ctx->Driver.GetTimestamp) {
1180af69d88dSmrg         v->value_int64 = ctx->Driver.GetTimestamp(ctx);
1181af69d88dSmrg      }
1182af69d88dSmrg      else {
1183af69d88dSmrg         _mesa_problem(ctx, "driver doesn't implement GetTimestamp");
11843464ebd5Sriastradh      }
11853464ebd5Sriastradh      break;
1186af69d88dSmrg   /* GL_KHR_DEBUG */
118701e04c3fSmrg   case GL_DEBUG_OUTPUT:
118801e04c3fSmrg   case GL_DEBUG_OUTPUT_SYNCHRONOUS:
1189af69d88dSmrg   case GL_DEBUG_LOGGED_MESSAGES:
1190af69d88dSmrg   case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH:
1191af69d88dSmrg   case GL_DEBUG_GROUP_STACK_DEPTH:
1192af69d88dSmrg      v->value_int = _mesa_get_debug_state_int(ctx, d->pname);
1193af69d88dSmrg      break;
1194af69d88dSmrg   /* GL_ARB_shader_atomic_counters */
1195af69d88dSmrg   case GL_ATOMIC_COUNTER_BUFFER_BINDING:
11967ec681f3Smrg      v->value_int = ctx->AtomicBuffer ? ctx->AtomicBuffer->Name : 0;
1197af69d88dSmrg      break;
119801e04c3fSmrg   /* GL 4.3 */
119901e04c3fSmrg   case GL_NUM_SHADING_LANGUAGE_VERSIONS:
120001e04c3fSmrg      v->value_int = _mesa_get_shading_language_version(ctx, -1, NULL);
120101e04c3fSmrg      break;
1202af69d88dSmrg   /* GL_ARB_draw_indirect */
1203af69d88dSmrg   case GL_DRAW_INDIRECT_BUFFER_BINDING:
12047ec681f3Smrg      v->value_int = ctx->DrawIndirectBuffer ? ctx->DrawIndirectBuffer->Name: 0;
1205af69d88dSmrg      break;
120601e04c3fSmrg   /* GL_ARB_indirect_parameters */
120701e04c3fSmrg   case GL_PARAMETER_BUFFER_BINDING_ARB:
12087ec681f3Smrg      v->value_int = ctx->ParameterBuffer ? ctx->ParameterBuffer->Name : 0;
120901e04c3fSmrg      break;
1210af69d88dSmrg   /* GL_ARB_separate_shader_objects */
1211af69d88dSmrg   case GL_PROGRAM_PIPELINE_BINDING:
1212af69d88dSmrg      if (ctx->Pipeline.Current) {
1213af69d88dSmrg         v->value_int = ctx->Pipeline.Current->Name;
1214af69d88dSmrg      } else {
1215af69d88dSmrg         v->value_int = 0;
1216af69d88dSmrg      }
1217af69d88dSmrg      break;
121801e04c3fSmrg   /* GL_ARB_compute_shader */
121901e04c3fSmrg   case GL_DISPATCH_INDIRECT_BUFFER_BINDING:
12207ec681f3Smrg      v->value_int = ctx->DispatchIndirectBuffer ?
12217ec681f3Smrg                        ctx->DispatchIndirectBuffer->Name : 0;
122201e04c3fSmrg      break;
122301e04c3fSmrg   /* GL_ARB_multisample */
122401e04c3fSmrg   case GL_SAMPLES:
122501e04c3fSmrg      v->value_int = _mesa_geometric_samples(ctx->DrawBuffer);
122601e04c3fSmrg      break;
122701e04c3fSmrg   case GL_SAMPLE_BUFFERS:
122801e04c3fSmrg      v->value_int = _mesa_geometric_samples(ctx->DrawBuffer) > 0;
122901e04c3fSmrg      break;
123001e04c3fSmrg   /* GL_EXT_textrue_integer */
123101e04c3fSmrg   case GL_RGBA_INTEGER_MODE_EXT:
123201e04c3fSmrg      v->value_int = (ctx->DrawBuffer->_IntegerBuffers != 0);
123301e04c3fSmrg      break;
123401e04c3fSmrg   /* GL_ATI_meminfo & GL_NVX_gpu_memory_info */
123501e04c3fSmrg   case GL_VBO_FREE_MEMORY_ATI:
123601e04c3fSmrg   case GL_TEXTURE_FREE_MEMORY_ATI:
123701e04c3fSmrg   case GL_RENDERBUFFER_FREE_MEMORY_ATI:
123801e04c3fSmrg   case GL_GPU_MEMORY_INFO_DEDICATED_VIDMEM_NVX:
123901e04c3fSmrg   case GL_GPU_MEMORY_INFO_TOTAL_AVAILABLE_MEMORY_NVX:
124001e04c3fSmrg   case GL_GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX:
124101e04c3fSmrg   case GL_GPU_MEMORY_INFO_EVICTION_COUNT_NVX:
124201e04c3fSmrg   case GL_GPU_MEMORY_INFO_EVICTED_MEMORY_NVX:
124301e04c3fSmrg      {
124401e04c3fSmrg         struct gl_memory_info info;
124501e04c3fSmrg
124601e04c3fSmrg         ctx->Driver.QueryMemoryInfo(ctx, &info);
124701e04c3fSmrg
124801e04c3fSmrg         if (d->pname == GL_GPU_MEMORY_INFO_DEDICATED_VIDMEM_NVX)
124901e04c3fSmrg            v->value_int = info.total_device_memory;
125001e04c3fSmrg         else if (d->pname == GL_GPU_MEMORY_INFO_TOTAL_AVAILABLE_MEMORY_NVX)
125101e04c3fSmrg            v->value_int = info.total_device_memory +
125201e04c3fSmrg                           info.total_staging_memory;
125301e04c3fSmrg         else if (d->pname == GL_GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX)
125401e04c3fSmrg            v->value_int = info.avail_device_memory;
125501e04c3fSmrg         else if (d->pname == GL_GPU_MEMORY_INFO_EVICTION_COUNT_NVX)
125601e04c3fSmrg            v->value_int = info.nr_device_memory_evictions;
125701e04c3fSmrg         else if (d->pname == GL_GPU_MEMORY_INFO_EVICTED_MEMORY_NVX)
125801e04c3fSmrg            v->value_int = info.device_memory_evicted;
125901e04c3fSmrg         else {
126001e04c3fSmrg            /* ATI free memory enums.
126101e04c3fSmrg             *
126201e04c3fSmrg             * Since the GPU memory is (usually) page-table based, every two
126301e04c3fSmrg             * consecutive elements are equal. From the GL_ATI_meminfo
126401e04c3fSmrg             * specification:
126501e04c3fSmrg             *
126601e04c3fSmrg             *    "param[0] - total memory free in the pool
126701e04c3fSmrg             *     param[1] - largest available free block in the pool
126801e04c3fSmrg             *     param[2] - total auxiliary memory free
126901e04c3fSmrg             *     param[3] - largest auxiliary free block"
127001e04c3fSmrg             *
127101e04c3fSmrg             * All three (VBO, TEXTURE, RENDERBUFFER) queries return
127201e04c3fSmrg             * the same numbers here.
127301e04c3fSmrg             */
127401e04c3fSmrg            v->value_int_4[0] = info.avail_device_memory;
127501e04c3fSmrg            v->value_int_4[1] = info.avail_device_memory;
127601e04c3fSmrg            v->value_int_4[2] = info.avail_staging_memory;
127701e04c3fSmrg            v->value_int_4[3] = info.avail_staging_memory;
127801e04c3fSmrg         }
127901e04c3fSmrg      }
128001e04c3fSmrg      break;
128101e04c3fSmrg
128201e04c3fSmrg   /* GL_ARB_get_program_binary */
128301e04c3fSmrg   case GL_PROGRAM_BINARY_FORMATS:
128401e04c3fSmrg      assert(ctx->Const.NumProgramBinaryFormats <= 1);
128501e04c3fSmrg      v->value_int_n.n = MIN2(ctx->Const.NumProgramBinaryFormats, 1);
128601e04c3fSmrg      if (ctx->Const.NumProgramBinaryFormats > 0) {
128701e04c3fSmrg         v->value_int_n.ints[0] = GL_PROGRAM_BINARY_FORMAT_MESA;
128801e04c3fSmrg      }
128901e04c3fSmrg      break;
12907ec681f3Smrg   /* ARB_spirv_extensions */
12917ec681f3Smrg   case GL_NUM_SPIR_V_EXTENSIONS:
12927ec681f3Smrg      v->value_int = _mesa_get_spirv_extension_count(ctx);
12937ec681f3Smrg      break;
129401e04c3fSmrg   /* GL_EXT_disjoint_timer_query */
129501e04c3fSmrg   case GL_GPU_DISJOINT_EXT:
129601e04c3fSmrg      {
129701e04c3fSmrg         simple_mtx_lock(&ctx->Shared->Mutex);
129801e04c3fSmrg         v->value_int = ctx->Shared->DisjointOperation;
129901e04c3fSmrg         /* Reset state as expected by the spec. */
130001e04c3fSmrg         ctx->Shared->DisjointOperation = false;
130101e04c3fSmrg         simple_mtx_unlock(&ctx->Shared->Mutex);
130201e04c3fSmrg      }
130301e04c3fSmrg      break;
130401e04c3fSmrg   /* GL_ARB_sample_locations */
130501e04c3fSmrg   case GL_SAMPLE_LOCATION_SUBPIXEL_BITS_ARB:
130601e04c3fSmrg   case GL_SAMPLE_LOCATION_PIXEL_GRID_WIDTH_ARB:
130701e04c3fSmrg   case GL_SAMPLE_LOCATION_PIXEL_GRID_HEIGHT_ARB:
130801e04c3fSmrg      {
130901e04c3fSmrg         GLuint bits, width, height;
131001e04c3fSmrg
131101e04c3fSmrg         if (ctx->NewState & _NEW_BUFFERS)
131201e04c3fSmrg            _mesa_update_state(ctx);
131301e04c3fSmrg
131401e04c3fSmrg         if (ctx->DrawBuffer->_Status != GL_FRAMEBUFFER_COMPLETE) {
131501e04c3fSmrg            v->value_uint = 0;
131601e04c3fSmrg            break;
131701e04c3fSmrg         }
131801e04c3fSmrg
131901e04c3fSmrg         ctx->Driver.GetProgrammableSampleCaps(ctx, ctx->DrawBuffer,
132001e04c3fSmrg                                               &bits, &width, &height);
132101e04c3fSmrg
132201e04c3fSmrg         if (d->pname == GL_SAMPLE_LOCATION_PIXEL_GRID_WIDTH_ARB)
132301e04c3fSmrg            v->value_uint = width;
132401e04c3fSmrg         else if (d->pname == GL_SAMPLE_LOCATION_PIXEL_GRID_HEIGHT_ARB)
132501e04c3fSmrg            v->value_uint = height;
132601e04c3fSmrg         else
132701e04c3fSmrg            v->value_uint = bits;
132801e04c3fSmrg      }
132901e04c3fSmrg      break;
133001e04c3fSmrg   case GL_PROGRAMMABLE_SAMPLE_LOCATION_TABLE_SIZE_ARB:
133101e04c3fSmrg      v->value_uint = MAX_SAMPLE_LOCATION_TABLE_SIZE;
133201e04c3fSmrg      break;
133301e04c3fSmrg
133401e04c3fSmrg   /* GL_AMD_framebuffer_multisample_advanced */
133501e04c3fSmrg   case GL_SUPPORTED_MULTISAMPLE_MODES_AMD:
133601e04c3fSmrg      v->value_int_n.n = ctx->Const.NumSupportedMultisampleModes * 3;
133701e04c3fSmrg      memcpy(v->value_int_n.ints, ctx->Const.SupportedMultisampleModes,
133801e04c3fSmrg             v->value_int_n.n * sizeof(GLint));
133901e04c3fSmrg      break;
13407ec681f3Smrg
13417ec681f3Smrg   /* GL_NV_viewport_swizzle */
13427ec681f3Smrg   case GL_VIEWPORT_SWIZZLE_X_NV:
13437ec681f3Smrg      v->value_enum = ctx->ViewportArray[0].SwizzleX;
13447ec681f3Smrg      break;
13457ec681f3Smrg   case GL_VIEWPORT_SWIZZLE_Y_NV:
13467ec681f3Smrg      v->value_enum = ctx->ViewportArray[0].SwizzleY;
13477ec681f3Smrg      break;
13487ec681f3Smrg   case GL_VIEWPORT_SWIZZLE_Z_NV:
13497ec681f3Smrg      v->value_enum = ctx->ViewportArray[0].SwizzleZ;
13507ec681f3Smrg      break;
13517ec681f3Smrg   case GL_VIEWPORT_SWIZZLE_W_NV:
13527ec681f3Smrg      v->value_enum = ctx->ViewportArray[0].SwizzleW;
13537ec681f3Smrg      break;
1354af69d88dSmrg   }
13553464ebd5Sriastradh}
13563464ebd5Sriastradh
13573464ebd5Sriastradh/**
13583464ebd5Sriastradh * Check extra constraints on a struct value_desc descriptor
13593464ebd5Sriastradh *
13603464ebd5Sriastradh * If a struct value_desc has a non-NULL extra pointer, it means that
13613464ebd5Sriastradh * there are a number of extra constraints to check or actions to
13623464ebd5Sriastradh * perform.  The extras is just an integer array where each integer
13633464ebd5Sriastradh * encode different constraints or actions.
13643464ebd5Sriastradh *
13653464ebd5Sriastradh * \param ctx current context
13663464ebd5Sriastradh * \param func name of calling glGet*v() function for error reporting
13673464ebd5Sriastradh * \param d the struct value_desc that has the extra constraints
13683464ebd5Sriastradh *
1369af69d88dSmrg * \return GL_FALSE if all of the constraints were not satisfied,
13703464ebd5Sriastradh *     otherwise GL_TRUE.
13717117f1b4Smrg */
13723464ebd5Sriastradhstatic GLboolean
13733464ebd5Sriastradhcheck_extra(struct gl_context *ctx, const char *func, const struct value_desc *d)
13743464ebd5Sriastradh{
1375af69d88dSmrg   const GLuint version = ctx->Version;
1376af69d88dSmrg   GLboolean api_check = GL_FALSE;
1377af69d88dSmrg   GLboolean api_found = GL_FALSE;
13783464ebd5Sriastradh   const int *e;
13793464ebd5Sriastradh
1380af69d88dSmrg   for (e = d->extra; *e != EXTRA_END; e++) {
13813464ebd5Sriastradh      switch (*e) {
13823464ebd5Sriastradh      case EXTRA_VERSION_30:
1383af69d88dSmrg         api_check = GL_TRUE;
1384af69d88dSmrg         if (version >= 30)
1385af69d88dSmrg            api_found = GL_TRUE;
138601e04c3fSmrg         break;
13873464ebd5Sriastradh      case EXTRA_VERSION_31:
1388af69d88dSmrg         api_check = GL_TRUE;
1389af69d88dSmrg         if (version >= 31)
1390af69d88dSmrg            api_found = GL_TRUE;
139101e04c3fSmrg         break;
13923464ebd5Sriastradh      case EXTRA_VERSION_32:
1393af69d88dSmrg         api_check = GL_TRUE;
1394af69d88dSmrg         if (version >= 32)
1395af69d88dSmrg            api_found = GL_TRUE;
139601e04c3fSmrg         break;
139701e04c3fSmrg      case EXTRA_VERSION_40:
139801e04c3fSmrg         api_check = GL_TRUE;
139901e04c3fSmrg         if (version >= 40)
140001e04c3fSmrg            api_found = GL_TRUE;
140101e04c3fSmrg         break;
140201e04c3fSmrg      case EXTRA_VERSION_43:
14037ec681f3Smrg         api_check = GL_TRUE;
140401e04c3fSmrg         if (_mesa_is_desktop_gl(ctx) && version >= 43)
140501e04c3fSmrg            api_found = GL_TRUE;
140601e04c3fSmrg         break;
1407af69d88dSmrg      case EXTRA_API_ES2:
1408af69d88dSmrg         api_check = GL_TRUE;
1409af69d88dSmrg         if (ctx->API == API_OPENGLES2)
1410af69d88dSmrg            api_found = GL_TRUE;
141101e04c3fSmrg         break;
1412af69d88dSmrg      case EXTRA_API_ES3:
1413af69d88dSmrg         api_check = GL_TRUE;
1414af69d88dSmrg         if (_mesa_is_gles3(ctx))
1415af69d88dSmrg            api_found = GL_TRUE;
141601e04c3fSmrg         break;
141701e04c3fSmrg      case EXTRA_API_ES31:
141801e04c3fSmrg         api_check = GL_TRUE;
141901e04c3fSmrg         if (_mesa_is_gles31(ctx))
142001e04c3fSmrg            api_found = GL_TRUE;
142101e04c3fSmrg         break;
142201e04c3fSmrg      case EXTRA_API_ES32:
142301e04c3fSmrg         api_check = GL_TRUE;
142401e04c3fSmrg         if (_mesa_is_gles32(ctx))
142501e04c3fSmrg            api_found = GL_TRUE;
142601e04c3fSmrg         break;
1427af69d88dSmrg      case EXTRA_API_GL:
1428af69d88dSmrg         api_check = GL_TRUE;
1429af69d88dSmrg         if (_mesa_is_desktop_gl(ctx))
1430af69d88dSmrg            api_found = GL_TRUE;
143101e04c3fSmrg         break;
1432af69d88dSmrg      case EXTRA_API_GL_CORE:
1433af69d88dSmrg         api_check = GL_TRUE;
1434af69d88dSmrg         if (ctx->API == API_OPENGL_CORE)
1435af69d88dSmrg            api_found = GL_TRUE;
143601e04c3fSmrg         break;
14373464ebd5Sriastradh      case EXTRA_NEW_BUFFERS:
143801e04c3fSmrg         if (ctx->NewState & _NEW_BUFFERS)
143901e04c3fSmrg            _mesa_update_state(ctx);
144001e04c3fSmrg         break;
14413464ebd5Sriastradh      case EXTRA_FLUSH_CURRENT:
144201e04c3fSmrg         FLUSH_CURRENT(ctx, 0);
144301e04c3fSmrg         break;
14443464ebd5Sriastradh      case EXTRA_VALID_DRAW_BUFFER:
144501e04c3fSmrg         if (d->pname - GL_DRAW_BUFFER0_ARB >= ctx->Const.MaxDrawBuffers) {
144601e04c3fSmrg            _mesa_error(ctx, GL_INVALID_OPERATION, "%s(draw buffer %u)",
144701e04c3fSmrg                        func, d->pname - GL_DRAW_BUFFER0_ARB);
144801e04c3fSmrg            return GL_FALSE;
144901e04c3fSmrg         }
145001e04c3fSmrg         break;
14513464ebd5Sriastradh      case EXTRA_VALID_TEXTURE_UNIT:
145201e04c3fSmrg         if (ctx->Texture.CurrentUnit >= ctx->Const.MaxTextureCoordUnits) {
145301e04c3fSmrg            _mesa_error(ctx, GL_INVALID_OPERATION, "%s(texture %u)",
145401e04c3fSmrg                        func, ctx->Texture.CurrentUnit);
145501e04c3fSmrg            return GL_FALSE;
145601e04c3fSmrg         }
145701e04c3fSmrg         break;
1458af69d88dSmrg      case EXTRA_VALID_CLIP_DISTANCE:
145901e04c3fSmrg         if (d->pname - GL_CLIP_DISTANCE0 >= ctx->Const.MaxClipPlanes) {
146001e04c3fSmrg            _mesa_error(ctx, GL_INVALID_ENUM, "%s(clip distance %u)",
146101e04c3fSmrg                        func, d->pname - GL_CLIP_DISTANCE0);
146201e04c3fSmrg            return GL_FALSE;
146301e04c3fSmrg         }
146401e04c3fSmrg         break;
1465af69d88dSmrg      case EXTRA_GLSL_130:
1466af69d88dSmrg         api_check = GL_TRUE;
1467af69d88dSmrg         if (ctx->Const.GLSLVersion >= 130)
1468af69d88dSmrg            api_found = GL_TRUE;
146901e04c3fSmrg         break;
147001e04c3fSmrg      case EXTRA_EXT_UBO_GS:
1471af69d88dSmrg         api_check = GL_TRUE;
147201e04c3fSmrg         if (ctx->Extensions.ARB_uniform_buffer_object &&
147301e04c3fSmrg            _mesa_has_geometry_shaders(ctx))
147401e04c3fSmrg            api_found = GL_TRUE;
147501e04c3fSmrg         break;
147601e04c3fSmrg      case EXTRA_EXT_ATOMICS_GS:
147701e04c3fSmrg         api_check = GL_TRUE;
147801e04c3fSmrg         if (ctx->Extensions.ARB_shader_atomic_counters &&
147901e04c3fSmrg            _mesa_has_geometry_shaders(ctx))
148001e04c3fSmrg            api_found = GL_TRUE;
148101e04c3fSmrg         break;
148201e04c3fSmrg      case EXTRA_EXT_SHADER_IMAGE_GS:
148301e04c3fSmrg         api_check = GL_TRUE;
148401e04c3fSmrg         if (ctx->Extensions.ARB_shader_image_load_store &&
148501e04c3fSmrg            _mesa_has_geometry_shaders(ctx))
148601e04c3fSmrg            api_found = GL_TRUE;
148701e04c3fSmrg         break;
148801e04c3fSmrg      case EXTRA_EXT_ATOMICS_TESS:
148901e04c3fSmrg         api_check = GL_TRUE;
149001e04c3fSmrg         api_found = ctx->Extensions.ARB_shader_atomic_counters &&
149101e04c3fSmrg                     _mesa_has_tessellation(ctx);
149201e04c3fSmrg         break;
149301e04c3fSmrg      case EXTRA_EXT_SHADER_IMAGE_TESS:
149401e04c3fSmrg         api_check = GL_TRUE;
149501e04c3fSmrg         api_found = ctx->Extensions.ARB_shader_image_load_store &&
149601e04c3fSmrg                     _mesa_has_tessellation(ctx);
149701e04c3fSmrg         break;
149801e04c3fSmrg      case EXTRA_EXT_SSBO_GS:
149901e04c3fSmrg         api_check = GL_TRUE;
150001e04c3fSmrg         if (ctx->Extensions.ARB_shader_storage_buffer_object &&
150101e04c3fSmrg            _mesa_has_geometry_shaders(ctx))
150201e04c3fSmrg            api_found = GL_TRUE;
1503af69d88dSmrg         break;
150401e04c3fSmrg      case EXTRA_EXT_FB_NO_ATTACH_GS:
1505af69d88dSmrg         api_check = GL_TRUE;
150601e04c3fSmrg         if (ctx->Extensions.ARB_framebuffer_no_attachments &&
150701e04c3fSmrg            (_mesa_is_desktop_gl(ctx) ||
150801e04c3fSmrg            _mesa_has_OES_geometry_shader(ctx)))
150901e04c3fSmrg            api_found = GL_TRUE;
1510af69d88dSmrg         break;
151101e04c3fSmrg      case EXTRA_EXT_ES_GS:
1512af69d88dSmrg         api_check = GL_TRUE;
151301e04c3fSmrg         if (_mesa_has_OES_geometry_shader(ctx))
151401e04c3fSmrg            api_found = GL_TRUE;
151501e04c3fSmrg         break;
151601e04c3fSmrg      case EXTRA_EXT_PROVOKING_VERTEX_32:
15177ec681f3Smrg         api_check = GL_TRUE;
151801e04c3fSmrg         if (ctx->API == API_OPENGL_COMPAT || version == 32)
151901e04c3fSmrg            api_found = ctx->Extensions.EXT_provoking_vertex;
1520af69d88dSmrg         break;
15213464ebd5Sriastradh      case EXTRA_END:
152201e04c3fSmrg         break;
15233464ebd5Sriastradh      default: /* *e is a offset into the extension struct */
152401e04c3fSmrg         api_check = GL_TRUE;
152501e04c3fSmrg         if (*(GLboolean *) ((char *) &ctx->Extensions + *e))
152601e04c3fSmrg            api_found = GL_TRUE;
152701e04c3fSmrg         break;
15283464ebd5Sriastradh      }
1529af69d88dSmrg   }
15303464ebd5Sriastradh
1531af69d88dSmrg   if (api_check && !api_found) {
15323464ebd5Sriastradh      _mesa_error(ctx, GL_INVALID_ENUM, "%s(pname=%s)", func,
153301e04c3fSmrg                  _mesa_enum_to_string(d->pname));
15343464ebd5Sriastradh      return GL_FALSE;
15357117f1b4Smrg   }
15367117f1b4Smrg
15373464ebd5Sriastradh   return GL_TRUE;
15383464ebd5Sriastradh}
15393464ebd5Sriastradh
15403464ebd5Sriastradhstatic const struct value_desc error_value =
15413464ebd5Sriastradh   { 0, 0, TYPE_INVALID, NO_OFFSET, NO_EXTRA };
15423464ebd5Sriastradh
15433464ebd5Sriastradh/**
15443464ebd5Sriastradh * Find the struct value_desc corresponding to the enum 'pname'.
154501e04c3fSmrg *
15463464ebd5Sriastradh * We hash the enum value to get an index into the 'table' array,
15473464ebd5Sriastradh * which holds the index in the 'values' array of struct value_desc.
15483464ebd5Sriastradh * Once we've found the entry, we do the extra checks, if any, then
15493464ebd5Sriastradh * look up the value and return a pointer to it.
15503464ebd5Sriastradh *
15513464ebd5Sriastradh * If the value has to be computed (for example, it's the result of a
15523464ebd5Sriastradh * function call or we need to add 1 to it), we use the tmp 'v' to
15533464ebd5Sriastradh * store the result.
155401e04c3fSmrg *
15553464ebd5Sriastradh * \param func name of glGet*v() func for error reporting
15563464ebd5Sriastradh * \param pname the enum value we're looking up
15573464ebd5Sriastradh * \param p is were we return the pointer to the value
15583464ebd5Sriastradh * \param v a tmp union value variable in the calling glGet*v() function
15593464ebd5Sriastradh *
15603464ebd5Sriastradh * \return the struct value_desc corresponding to the enum or a struct
15613464ebd5Sriastradh *     value_desc of TYPE_INVALID if not found.  This lets the calling
15623464ebd5Sriastradh *     glGet*v() function jump right into a switch statement and
15633464ebd5Sriastradh *     handle errors there instead of having to check for NULL.
15647117f1b4Smrg */
15653464ebd5Sriastradhstatic const struct value_desc *
15663464ebd5Sriastradhfind_value(const char *func, GLenum pname, void **p, union value *v)
15673464ebd5Sriastradh{
15683464ebd5Sriastradh   GET_CURRENT_CONTEXT(ctx);
15693464ebd5Sriastradh   int mask, hash;
15703464ebd5Sriastradh   const struct value_desc *d;
1571af69d88dSmrg   int api;
15723464ebd5Sriastradh
15737ec681f3Smrg   *p = NULL;
15747ec681f3Smrg
1575af69d88dSmrg   api = ctx->API;
1576af69d88dSmrg   /* We index into the table_set[] list of per-API hash tables using the API's
1577af69d88dSmrg    * value in the gl_api enum. Since GLES 3 doesn't have an API_OPENGL* enum
1578af69d88dSmrg    * value since it's compatible with GLES2 its entry in table_set[] is at the
1579af69d88dSmrg    * end.
1580af69d88dSmrg    */
158101e04c3fSmrg   STATIC_ASSERT(ARRAY_SIZE(table_set) == API_OPENGL_LAST + 4);
158201e04c3fSmrg   if (ctx->API == API_OPENGLES2) {
158301e04c3fSmrg      if (ctx->Version >= 32)
158401e04c3fSmrg         api = API_OPENGL_LAST + 3;
158501e04c3fSmrg      else if (ctx->Version >= 31)
158601e04c3fSmrg         api = API_OPENGL_LAST + 2;
158701e04c3fSmrg      else if (ctx->Version >= 30)
158801e04c3fSmrg         api = API_OPENGL_LAST + 1;
1589af69d88dSmrg   }
159001e04c3fSmrg   mask = ARRAY_SIZE(table(api)) - 1;
15913464ebd5Sriastradh   hash = (pname * prime_factor);
15923464ebd5Sriastradh   while (1) {
1593af69d88dSmrg      int idx = table(api)[hash & mask];
15943464ebd5Sriastradh
15953464ebd5Sriastradh      /* If the enum isn't valid, the hash walk ends with index 0,
1596af69d88dSmrg       * pointing to the first entry of values[] which doesn't hold
1597af69d88dSmrg       * any valid enum. */
1598af69d88dSmrg      if (unlikely(idx == 0)) {
1599af69d88dSmrg         _mesa_error(ctx, GL_INVALID_ENUM, "%s(pname=%s)", func,
160001e04c3fSmrg               _mesa_enum_to_string(pname));
1601af69d88dSmrg         return &error_value;
16023464ebd5Sriastradh      }
16033464ebd5Sriastradh
1604af69d88dSmrg      d = &values[idx];
16053464ebd5Sriastradh      if (likely(d->pname == pname))
1606af69d88dSmrg         break;
16073464ebd5Sriastradh
16083464ebd5Sriastradh      hash += prime_step;
16097117f1b4Smrg   }
16107117f1b4Smrg
16113464ebd5Sriastradh   if (unlikely(d->extra && !check_extra(ctx, func, d)))
16123464ebd5Sriastradh      return &error_value;
16133464ebd5Sriastradh
16143464ebd5Sriastradh   switch (d->location) {
16153464ebd5Sriastradh   case LOC_BUFFER:
16163464ebd5Sriastradh      *p = ((char *) ctx->DrawBuffer + d->offset);
16173464ebd5Sriastradh      return d;
16183464ebd5Sriastradh   case LOC_CONTEXT:
16193464ebd5Sriastradh      *p = ((char *) ctx + d->offset);
16203464ebd5Sriastradh      return d;
16213464ebd5Sriastradh   case LOC_ARRAY:
1622af69d88dSmrg      *p = ((char *) ctx->Array.VAO + d->offset);
16233464ebd5Sriastradh      return d;
16243464ebd5Sriastradh   case LOC_TEXUNIT:
162501e04c3fSmrg      if (ctx->Texture.CurrentUnit < ARRAY_SIZE(ctx->Texture.FixedFuncUnit)) {
162601e04c3fSmrg         unsigned index = ctx->Texture.CurrentUnit;
162701e04c3fSmrg         *p = ((char *)&ctx->Texture.FixedFuncUnit[index] + d->offset);
16287ec681f3Smrg         return d;
162901e04c3fSmrg      }
16307ec681f3Smrg      _mesa_error(ctx, GL_INVALID_VALUE, "%s(pname=%s,unit=%d)", func,
16317ec681f3Smrg                  _mesa_enum_to_string(pname),
16327ec681f3Smrg                  ctx->Texture.CurrentUnit);
16337ec681f3Smrg      return &error_value;
16343464ebd5Sriastradh   case LOC_CUSTOM:
16353464ebd5Sriastradh      find_custom_value(ctx, d, v);
16363464ebd5Sriastradh      *p = v;
16373464ebd5Sriastradh      return d;
16383464ebd5Sriastradh   default:
16393464ebd5Sriastradh      assert(0);
16403464ebd5Sriastradh      break;
16413464ebd5Sriastradh   }
16423464ebd5Sriastradh
16433464ebd5Sriastradh   /* silence warning */
16443464ebd5Sriastradh   return &error_value;
16453464ebd5Sriastradh}
16463464ebd5Sriastradh
16473464ebd5Sriastradhstatic const int transpose[] = {
16483464ebd5Sriastradh   0, 4,  8, 12,
16493464ebd5Sriastradh   1, 5,  9, 13,
16503464ebd5Sriastradh   2, 6, 10, 14,
16513464ebd5Sriastradh   3, 7, 11, 15
16523464ebd5Sriastradh};
16537117f1b4Smrg
165401e04c3fSmrgstatic GLsizei
165501e04c3fSmrgget_value_size(enum value_type type, const union value *v)
165601e04c3fSmrg{
165701e04c3fSmrg   switch (type) {
165801e04c3fSmrg   case TYPE_INVALID:
165901e04c3fSmrg      return 0;
166001e04c3fSmrg   case TYPE_CONST:
166101e04c3fSmrg   case TYPE_UINT:
166201e04c3fSmrg   case TYPE_INT:
166301e04c3fSmrg      return sizeof(GLint);
166401e04c3fSmrg   case TYPE_INT_2:
166501e04c3fSmrg   case TYPE_UINT_2:
166601e04c3fSmrg      return sizeof(GLint) * 2;
166701e04c3fSmrg   case TYPE_INT_3:
166801e04c3fSmrg   case TYPE_UINT_3:
166901e04c3fSmrg      return sizeof(GLint) * 3;
167001e04c3fSmrg   case TYPE_INT_4:
167101e04c3fSmrg   case TYPE_UINT_4:
167201e04c3fSmrg      return sizeof(GLint) * 4;
167301e04c3fSmrg   case TYPE_INT_N:
167401e04c3fSmrg      return sizeof(GLint) * v->value_int_n.n;
167501e04c3fSmrg   case TYPE_INT64:
167601e04c3fSmrg      return sizeof(GLint64);
167701e04c3fSmrg      break;
167801e04c3fSmrg   case TYPE_ENUM16:
167901e04c3fSmrg      return sizeof(GLenum16);
168001e04c3fSmrg   case TYPE_ENUM:
168101e04c3fSmrg      return sizeof(GLenum);
168201e04c3fSmrg   case TYPE_ENUM_2:
168301e04c3fSmrg      return sizeof(GLenum) * 2;
168401e04c3fSmrg   case TYPE_BOOLEAN:
168501e04c3fSmrg      return sizeof(GLboolean);
168601e04c3fSmrg   case TYPE_UBYTE:
168701e04c3fSmrg      return sizeof(GLubyte);
168801e04c3fSmrg   case TYPE_SHORT:
168901e04c3fSmrg      return sizeof(GLshort);
169001e04c3fSmrg   case TYPE_BIT_0:
169101e04c3fSmrg   case TYPE_BIT_1:
169201e04c3fSmrg   case TYPE_BIT_2:
169301e04c3fSmrg   case TYPE_BIT_3:
169401e04c3fSmrg   case TYPE_BIT_4:
169501e04c3fSmrg   case TYPE_BIT_5:
169601e04c3fSmrg   case TYPE_BIT_6:
169701e04c3fSmrg   case TYPE_BIT_7:
169801e04c3fSmrg      return 1;
169901e04c3fSmrg   case TYPE_FLOAT:
170001e04c3fSmrg   case TYPE_FLOATN:
170101e04c3fSmrg      return sizeof(GLfloat);
170201e04c3fSmrg   case TYPE_FLOAT_2:
170301e04c3fSmrg   case TYPE_FLOATN_2:
170401e04c3fSmrg      return sizeof(GLfloat) * 2;
170501e04c3fSmrg   case TYPE_FLOAT_3:
170601e04c3fSmrg   case TYPE_FLOATN_3:
170701e04c3fSmrg      return sizeof(GLfloat) * 3;
170801e04c3fSmrg   case TYPE_FLOAT_4:
170901e04c3fSmrg   case TYPE_FLOATN_4:
171001e04c3fSmrg      return sizeof(GLfloat) * 4;
171101e04c3fSmrg   case TYPE_FLOAT_8:
171201e04c3fSmrg      return sizeof(GLfloat) * 8;
171301e04c3fSmrg   case TYPE_DOUBLEN:
171401e04c3fSmrg      return sizeof(GLdouble);
171501e04c3fSmrg   case TYPE_DOUBLEN_2:
171601e04c3fSmrg      return sizeof(GLdouble) * 2;
171701e04c3fSmrg   case TYPE_MATRIX:
171801e04c3fSmrg      return sizeof (GLfloat) * 16;
171901e04c3fSmrg   case TYPE_MATRIX_T:
172001e04c3fSmrg      return sizeof (GLfloat) * 16;
172101e04c3fSmrg   default:
17227ec681f3Smrg      assert(!"invalid value_type given for get_value_size()");
172301e04c3fSmrg      return -1;
172401e04c3fSmrg   }
172501e04c3fSmrg}
172601e04c3fSmrg
17277117f1b4Smrgvoid GLAPIENTRY
17283464ebd5Sriastradh_mesa_GetBooleanv(GLenum pname, GLboolean *params)
17297117f1b4Smrg{
17303464ebd5Sriastradh   const struct value_desc *d;
17313464ebd5Sriastradh   union value v;
17323464ebd5Sriastradh   GLmatrix *m;
17333464ebd5Sriastradh   int shift, i;
17343464ebd5Sriastradh   void *p;
17357117f1b4Smrg
17363464ebd5Sriastradh   d = find_value("glGetBooleanv", pname, &p, &v);
17373464ebd5Sriastradh   switch (d->type) {
17383464ebd5Sriastradh   case TYPE_INVALID:
17393464ebd5Sriastradh      break;
17403464ebd5Sriastradh   case TYPE_CONST:
17413464ebd5Sriastradh      params[0] = INT_TO_BOOLEAN(d->offset);
17423464ebd5Sriastradh      break;
17437117f1b4Smrg
174401e04c3fSmrg   case TYPE_FLOAT_8:
174501e04c3fSmrg      params[7] = FLOAT_TO_BOOLEAN(((GLfloat *) p)[7]);
174601e04c3fSmrg      params[6] = FLOAT_TO_BOOLEAN(((GLfloat *) p)[6]);
174701e04c3fSmrg      params[5] = FLOAT_TO_BOOLEAN(((GLfloat *) p)[5]);
174801e04c3fSmrg      params[4] = FLOAT_TO_BOOLEAN(((GLfloat *) p)[4]);
17497ec681f3Smrg      FALLTHROUGH;
17503464ebd5Sriastradh   case TYPE_FLOAT_4:
17513464ebd5Sriastradh   case TYPE_FLOATN_4:
17523464ebd5Sriastradh      params[3] = FLOAT_TO_BOOLEAN(((GLfloat *) p)[3]);
17537ec681f3Smrg      FALLTHROUGH;
17543464ebd5Sriastradh   case TYPE_FLOAT_3:
17553464ebd5Sriastradh   case TYPE_FLOATN_3:
17563464ebd5Sriastradh      params[2] = FLOAT_TO_BOOLEAN(((GLfloat *) p)[2]);
17577ec681f3Smrg      FALLTHROUGH;
17583464ebd5Sriastradh   case TYPE_FLOAT_2:
17593464ebd5Sriastradh   case TYPE_FLOATN_2:
17603464ebd5Sriastradh      params[1] = FLOAT_TO_BOOLEAN(((GLfloat *) p)[1]);
17617ec681f3Smrg      FALLTHROUGH;
17623464ebd5Sriastradh   case TYPE_FLOAT:
17633464ebd5Sriastradh   case TYPE_FLOATN:
17643464ebd5Sriastradh      params[0] = FLOAT_TO_BOOLEAN(((GLfloat *) p)[0]);
17653464ebd5Sriastradh      break;
17667117f1b4Smrg
1767af69d88dSmrg   case TYPE_DOUBLEN_2:
1768af69d88dSmrg      params[1] = FLOAT_TO_BOOLEAN(((GLdouble *) p)[1]);
17697ec681f3Smrg      FALLTHROUGH;
17703464ebd5Sriastradh   case TYPE_DOUBLEN:
17713464ebd5Sriastradh      params[0] = FLOAT_TO_BOOLEAN(((GLdouble *) p)[0]);
17723464ebd5Sriastradh      break;
17737117f1b4Smrg
17743464ebd5Sriastradh   case TYPE_INT_4:
177501e04c3fSmrg   case TYPE_UINT_4:
17763464ebd5Sriastradh      params[3] = INT_TO_BOOLEAN(((GLint *) p)[3]);
17777ec681f3Smrg      FALLTHROUGH;
17783464ebd5Sriastradh   case TYPE_INT_3:
177901e04c3fSmrg   case TYPE_UINT_3:
17803464ebd5Sriastradh      params[2] = INT_TO_BOOLEAN(((GLint *) p)[2]);
17817ec681f3Smrg      FALLTHROUGH;
17823464ebd5Sriastradh   case TYPE_INT_2:
178301e04c3fSmrg   case TYPE_UINT_2:
17843464ebd5Sriastradh   case TYPE_ENUM_2:
17853464ebd5Sriastradh      params[1] = INT_TO_BOOLEAN(((GLint *) p)[1]);
17867ec681f3Smrg      FALLTHROUGH;
17873464ebd5Sriastradh   case TYPE_INT:
178801e04c3fSmrg   case TYPE_UINT:
17893464ebd5Sriastradh   case TYPE_ENUM:
17903464ebd5Sriastradh      params[0] = INT_TO_BOOLEAN(((GLint *) p)[0]);
17913464ebd5Sriastradh      break;
17923464ebd5Sriastradh
179301e04c3fSmrg   case TYPE_ENUM16:
179401e04c3fSmrg      params[0] = INT_TO_BOOLEAN(((GLenum16 *) p)[0]);
179501e04c3fSmrg      break;
179601e04c3fSmrg
17973464ebd5Sriastradh   case TYPE_INT_N:
17983464ebd5Sriastradh      for (i = 0; i < v.value_int_n.n; i++)
179901e04c3fSmrg         params[i] = INT_TO_BOOLEAN(v.value_int_n.ints[i]);
18003464ebd5Sriastradh      break;
18013464ebd5Sriastradh
18023464ebd5Sriastradh   case TYPE_INT64:
18033464ebd5Sriastradh      params[0] = INT64_TO_BOOLEAN(((GLint64 *) p)[0]);
18043464ebd5Sriastradh      break;
18053464ebd5Sriastradh
18063464ebd5Sriastradh   case TYPE_BOOLEAN:
18073464ebd5Sriastradh      params[0] = ((GLboolean*) p)[0];
180801e04c3fSmrg      break;
180901e04c3fSmrg
181001e04c3fSmrg   case TYPE_UBYTE:
181101e04c3fSmrg      params[0] = INT_TO_BOOLEAN(((GLubyte *) p)[0]);
181201e04c3fSmrg      break;
181301e04c3fSmrg
181401e04c3fSmrg   case TYPE_SHORT:
181501e04c3fSmrg      params[0] = INT_TO_BOOLEAN(((GLshort *) p)[0]);
181601e04c3fSmrg      break;
18173464ebd5Sriastradh
18183464ebd5Sriastradh   case TYPE_MATRIX:
18193464ebd5Sriastradh      m = *(GLmatrix **) p;
18203464ebd5Sriastradh      for (i = 0; i < 16; i++)
182101e04c3fSmrg         params[i] = FLOAT_TO_BOOLEAN(m->m[i]);
18223464ebd5Sriastradh      break;
18233464ebd5Sriastradh
18243464ebd5Sriastradh   case TYPE_MATRIX_T:
18253464ebd5Sriastradh      m = *(GLmatrix **) p;
18263464ebd5Sriastradh      for (i = 0; i < 16; i++)
182701e04c3fSmrg         params[i] = FLOAT_TO_BOOLEAN(m->m[transpose[i]]);
18283464ebd5Sriastradh      break;
18293464ebd5Sriastradh
18303464ebd5Sriastradh   case TYPE_BIT_0:
18313464ebd5Sriastradh   case TYPE_BIT_1:
18323464ebd5Sriastradh   case TYPE_BIT_2:
18333464ebd5Sriastradh   case TYPE_BIT_3:
18343464ebd5Sriastradh   case TYPE_BIT_4:
18353464ebd5Sriastradh   case TYPE_BIT_5:
1836af69d88dSmrg   case TYPE_BIT_6:
1837af69d88dSmrg   case TYPE_BIT_7:
18383464ebd5Sriastradh      shift = d->type - TYPE_BIT_0;
18393464ebd5Sriastradh      params[0] = (*(GLbitfield *) p >> shift) & 1;
18403464ebd5Sriastradh      break;
18414a49301eSmrg   }
18424a49301eSmrg}
18437117f1b4Smrg
18447117f1b4Smrgvoid GLAPIENTRY
18453464ebd5Sriastradh_mesa_GetFloatv(GLenum pname, GLfloat *params)
18467117f1b4Smrg{
18473464ebd5Sriastradh   const struct value_desc *d;
18483464ebd5Sriastradh   union value v;
18493464ebd5Sriastradh   GLmatrix *m;
18503464ebd5Sriastradh   int shift, i;
18513464ebd5Sriastradh   void *p;
18527117f1b4Smrg
18533464ebd5Sriastradh   d = find_value("glGetFloatv", pname, &p, &v);
18543464ebd5Sriastradh   switch (d->type) {
18553464ebd5Sriastradh   case TYPE_INVALID:
18563464ebd5Sriastradh      break;
18573464ebd5Sriastradh   case TYPE_CONST:
18583464ebd5Sriastradh      params[0] = (GLfloat) d->offset;
18593464ebd5Sriastradh      break;
18607117f1b4Smrg
186101e04c3fSmrg   case TYPE_FLOAT_8:
186201e04c3fSmrg      params[7] = ((GLfloat *) p)[7];
186301e04c3fSmrg      params[6] = ((GLfloat *) p)[6];
186401e04c3fSmrg      params[5] = ((GLfloat *) p)[5];
186501e04c3fSmrg      params[4] = ((GLfloat *) p)[4];
18667ec681f3Smrg      FALLTHROUGH;
18673464ebd5Sriastradh   case TYPE_FLOAT_4:
18683464ebd5Sriastradh   case TYPE_FLOATN_4:
18693464ebd5Sriastradh      params[3] = ((GLfloat *) p)[3];
18707ec681f3Smrg      FALLTHROUGH;
18713464ebd5Sriastradh   case TYPE_FLOAT_3:
18723464ebd5Sriastradh   case TYPE_FLOATN_3:
18733464ebd5Sriastradh      params[2] = ((GLfloat *) p)[2];
18747ec681f3Smrg      FALLTHROUGH;
18753464ebd5Sriastradh   case TYPE_FLOAT_2:
18763464ebd5Sriastradh   case TYPE_FLOATN_2:
18773464ebd5Sriastradh      params[1] = ((GLfloat *) p)[1];
18787ec681f3Smrg      FALLTHROUGH;
18793464ebd5Sriastradh   case TYPE_FLOAT:
18803464ebd5Sriastradh   case TYPE_FLOATN:
18813464ebd5Sriastradh      params[0] = ((GLfloat *) p)[0];
18823464ebd5Sriastradh      break;
18837117f1b4Smrg
1884af69d88dSmrg   case TYPE_DOUBLEN_2:
1885af69d88dSmrg      params[1] = (GLfloat) (((GLdouble *) p)[1]);
18867ec681f3Smrg      FALLTHROUGH;
18873464ebd5Sriastradh   case TYPE_DOUBLEN:
1888af69d88dSmrg      params[0] = (GLfloat) (((GLdouble *) p)[0]);
18893464ebd5Sriastradh      break;
18903464ebd5Sriastradh
18913464ebd5Sriastradh   case TYPE_INT_4:
18923464ebd5Sriastradh      params[3] = (GLfloat) (((GLint *) p)[3]);
18937ec681f3Smrg      FALLTHROUGH;
18943464ebd5Sriastradh   case TYPE_INT_3:
18953464ebd5Sriastradh      params[2] = (GLfloat) (((GLint *) p)[2]);
18967ec681f3Smrg      FALLTHROUGH;
18973464ebd5Sriastradh   case TYPE_INT_2:
18983464ebd5Sriastradh   case TYPE_ENUM_2:
18993464ebd5Sriastradh      params[1] = (GLfloat) (((GLint *) p)[1]);
19007ec681f3Smrg      FALLTHROUGH;
19013464ebd5Sriastradh   case TYPE_INT:
19023464ebd5Sriastradh   case TYPE_ENUM:
19033464ebd5Sriastradh      params[0] = (GLfloat) (((GLint *) p)[0]);
19043464ebd5Sriastradh      break;
19053464ebd5Sriastradh
190601e04c3fSmrg   case TYPE_ENUM16:
190701e04c3fSmrg      params[0] = (GLfloat) (((GLenum16 *) p)[0]);
190801e04c3fSmrg      break;
190901e04c3fSmrg
19103464ebd5Sriastradh   case TYPE_INT_N:
19113464ebd5Sriastradh      for (i = 0; i < v.value_int_n.n; i++)
191201e04c3fSmrg         params[i] = (GLfloat) v.value_int_n.ints[i];
191301e04c3fSmrg      break;
191401e04c3fSmrg
191501e04c3fSmrg   case TYPE_UINT_4:
191601e04c3fSmrg      params[3] = (GLfloat) (((GLuint *) p)[3]);
19177ec681f3Smrg      FALLTHROUGH;
191801e04c3fSmrg   case TYPE_UINT_3:
191901e04c3fSmrg      params[2] = (GLfloat) (((GLuint *) p)[2]);
19207ec681f3Smrg      FALLTHROUGH;
192101e04c3fSmrg   case TYPE_UINT_2:
192201e04c3fSmrg      params[1] = (GLfloat) (((GLuint *) p)[1]);
19237ec681f3Smrg      FALLTHROUGH;
192401e04c3fSmrg   case TYPE_UINT:
192501e04c3fSmrg      params[0] = (GLfloat) (((GLuint *) p)[0]);
19263464ebd5Sriastradh      break;
19273464ebd5Sriastradh
19283464ebd5Sriastradh   case TYPE_INT64:
1929af69d88dSmrg      params[0] = (GLfloat) (((GLint64 *) p)[0]);
19303464ebd5Sriastradh      break;
19313464ebd5Sriastradh
19323464ebd5Sriastradh   case TYPE_BOOLEAN:
19333464ebd5Sriastradh      params[0] = BOOLEAN_TO_FLOAT(*(GLboolean*) p);
193401e04c3fSmrg      break;
193501e04c3fSmrg
193601e04c3fSmrg   case TYPE_UBYTE:
193701e04c3fSmrg      params[0] = (GLfloat) ((GLubyte *) p)[0];
193801e04c3fSmrg      break;
193901e04c3fSmrg
194001e04c3fSmrg   case TYPE_SHORT:
194101e04c3fSmrg      params[0] = (GLfloat) ((GLshort *) p)[0];
194201e04c3fSmrg      break;
19433464ebd5Sriastradh
19443464ebd5Sriastradh   case TYPE_MATRIX:
19453464ebd5Sriastradh      m = *(GLmatrix **) p;
19463464ebd5Sriastradh      for (i = 0; i < 16; i++)
194701e04c3fSmrg         params[i] = m->m[i];
19483464ebd5Sriastradh      break;
19493464ebd5Sriastradh
19503464ebd5Sriastradh   case TYPE_MATRIX_T:
19513464ebd5Sriastradh      m = *(GLmatrix **) p;
19523464ebd5Sriastradh      for (i = 0; i < 16; i++)
195301e04c3fSmrg         params[i] = m->m[transpose[i]];
19543464ebd5Sriastradh      break;
19553464ebd5Sriastradh
19563464ebd5Sriastradh   case TYPE_BIT_0:
19573464ebd5Sriastradh   case TYPE_BIT_1:
19583464ebd5Sriastradh   case TYPE_BIT_2:
19593464ebd5Sriastradh   case TYPE_BIT_3:
19603464ebd5Sriastradh   case TYPE_BIT_4:
19613464ebd5Sriastradh   case TYPE_BIT_5:
1962af69d88dSmrg   case TYPE_BIT_6:
1963af69d88dSmrg   case TYPE_BIT_7:
19643464ebd5Sriastradh      shift = d->type - TYPE_BIT_0;
19653464ebd5Sriastradh      params[0] = BOOLEAN_TO_FLOAT((*(GLbitfield *) p >> shift) & 1);
19663464ebd5Sriastradh      break;
19673464ebd5Sriastradh   }
19687117f1b4Smrg}
19697117f1b4Smrg
1970cdc920a0Smrgvoid GLAPIENTRY
19713464ebd5Sriastradh_mesa_GetIntegerv(GLenum pname, GLint *params)
1972cdc920a0Smrg{
19733464ebd5Sriastradh   const struct value_desc *d;
19743464ebd5Sriastradh   union value v;
19753464ebd5Sriastradh   GLmatrix *m;
19763464ebd5Sriastradh   int shift, i;
19773464ebd5Sriastradh   void *p;
1978cdc920a0Smrg
19793464ebd5Sriastradh   d = find_value("glGetIntegerv", pname, &p, &v);
19803464ebd5Sriastradh   switch (d->type) {
19813464ebd5Sriastradh   case TYPE_INVALID:
19823464ebd5Sriastradh      break;
19833464ebd5Sriastradh   case TYPE_CONST:
19843464ebd5Sriastradh      params[0] = d->offset;
19853464ebd5Sriastradh      break;
1986cdc920a0Smrg
198701e04c3fSmrg   case TYPE_FLOAT_8:
19887ec681f3Smrg      params[7] = lroundf(((GLfloat *) p)[7]);
19897ec681f3Smrg      params[6] = lroundf(((GLfloat *) p)[6]);
19907ec681f3Smrg      params[5] = lroundf(((GLfloat *) p)[5]);
19917ec681f3Smrg      params[4] = lroundf(((GLfloat *) p)[4]);
19927ec681f3Smrg      FALLTHROUGH;
19933464ebd5Sriastradh   case TYPE_FLOAT_4:
19947ec681f3Smrg      params[3] = lroundf(((GLfloat *) p)[3]);
19957ec681f3Smrg      FALLTHROUGH;
19963464ebd5Sriastradh   case TYPE_FLOAT_3:
19977ec681f3Smrg      params[2] = lroundf(((GLfloat *) p)[2]);
19987ec681f3Smrg      FALLTHROUGH;
19993464ebd5Sriastradh   case TYPE_FLOAT_2:
20007ec681f3Smrg      params[1] = lroundf(((GLfloat *) p)[1]);
20017ec681f3Smrg      FALLTHROUGH;
20023464ebd5Sriastradh   case TYPE_FLOAT:
20037ec681f3Smrg      params[0] = lroundf(((GLfloat *) p)[0]);
20043464ebd5Sriastradh      break;
2005cdc920a0Smrg
20063464ebd5Sriastradh   case TYPE_FLOATN_4:
20073464ebd5Sriastradh      params[3] = FLOAT_TO_INT(((GLfloat *) p)[3]);
20087ec681f3Smrg      FALLTHROUGH;
20093464ebd5Sriastradh   case TYPE_FLOATN_3:
20103464ebd5Sriastradh      params[2] = FLOAT_TO_INT(((GLfloat *) p)[2]);
20117ec681f3Smrg      FALLTHROUGH;
20123464ebd5Sriastradh   case TYPE_FLOATN_2:
20133464ebd5Sriastradh      params[1] = FLOAT_TO_INT(((GLfloat *) p)[1]);
20147ec681f3Smrg      FALLTHROUGH;
20153464ebd5Sriastradh   case TYPE_FLOATN:
20163464ebd5Sriastradh      params[0] = FLOAT_TO_INT(((GLfloat *) p)[0]);
20173464ebd5Sriastradh      break;
20183464ebd5Sriastradh
2019af69d88dSmrg   case TYPE_DOUBLEN_2:
2020af69d88dSmrg      params[1] = FLOAT_TO_INT(((GLdouble *) p)[1]);
20217ec681f3Smrg      FALLTHROUGH;
20223464ebd5Sriastradh   case TYPE_DOUBLEN:
20233464ebd5Sriastradh      params[0] = FLOAT_TO_INT(((GLdouble *) p)[0]);
20243464ebd5Sriastradh      break;
20253464ebd5Sriastradh
20263464ebd5Sriastradh   case TYPE_INT_4:
202701e04c3fSmrg   case TYPE_UINT_4:
20283464ebd5Sriastradh      params[3] = ((GLint *) p)[3];
20297ec681f3Smrg      FALLTHROUGH;
20303464ebd5Sriastradh   case TYPE_INT_3:
203101e04c3fSmrg   case TYPE_UINT_3:
20323464ebd5Sriastradh      params[2] = ((GLint *) p)[2];
20337ec681f3Smrg      FALLTHROUGH;
20343464ebd5Sriastradh   case TYPE_INT_2:
203501e04c3fSmrg   case TYPE_UINT_2:
20363464ebd5Sriastradh   case TYPE_ENUM_2:
20373464ebd5Sriastradh      params[1] = ((GLint *) p)[1];
20387ec681f3Smrg      FALLTHROUGH;
20393464ebd5Sriastradh   case TYPE_INT:
204001e04c3fSmrg   case TYPE_UINT:
20413464ebd5Sriastradh   case TYPE_ENUM:
20423464ebd5Sriastradh      params[0] = ((GLint *) p)[0];
20433464ebd5Sriastradh      break;
20443464ebd5Sriastradh
204501e04c3fSmrg   case TYPE_ENUM16:
204601e04c3fSmrg      params[0] = ((GLenum16 *) p)[0];
204701e04c3fSmrg      break;
204801e04c3fSmrg
20493464ebd5Sriastradh   case TYPE_INT_N:
20503464ebd5Sriastradh      for (i = 0; i < v.value_int_n.n; i++)
205101e04c3fSmrg         params[i] = v.value_int_n.ints[i];
20523464ebd5Sriastradh      break;
20533464ebd5Sriastradh
20543464ebd5Sriastradh   case TYPE_INT64:
20553464ebd5Sriastradh      params[0] = INT64_TO_INT(((GLint64 *) p)[0]);
20563464ebd5Sriastradh      break;
20573464ebd5Sriastradh
20583464ebd5Sriastradh   case TYPE_BOOLEAN:
20593464ebd5Sriastradh      params[0] = BOOLEAN_TO_INT(*(GLboolean*) p);
206001e04c3fSmrg      break;
206101e04c3fSmrg
206201e04c3fSmrg   case TYPE_UBYTE:
206301e04c3fSmrg      params[0] = ((GLubyte *) p)[0];
206401e04c3fSmrg      break;
206501e04c3fSmrg
206601e04c3fSmrg   case TYPE_SHORT:
206701e04c3fSmrg      params[0] = ((GLshort *) p)[0];
206801e04c3fSmrg      break;
20693464ebd5Sriastradh
20703464ebd5Sriastradh   case TYPE_MATRIX:
20713464ebd5Sriastradh      m = *(GLmatrix **) p;
20723464ebd5Sriastradh      for (i = 0; i < 16; i++)
207301e04c3fSmrg         params[i] = FLOAT_TO_INT(m->m[i]);
20743464ebd5Sriastradh      break;
20753464ebd5Sriastradh
20763464ebd5Sriastradh   case TYPE_MATRIX_T:
20773464ebd5Sriastradh      m = *(GLmatrix **) p;
20783464ebd5Sriastradh      for (i = 0; i < 16; i++)
207901e04c3fSmrg         params[i] = FLOAT_TO_INT(m->m[transpose[i]]);
20803464ebd5Sriastradh      break;
20813464ebd5Sriastradh
20823464ebd5Sriastradh   case TYPE_BIT_0:
20833464ebd5Sriastradh   case TYPE_BIT_1:
20843464ebd5Sriastradh   case TYPE_BIT_2:
20853464ebd5Sriastradh   case TYPE_BIT_3:
20863464ebd5Sriastradh   case TYPE_BIT_4:
20873464ebd5Sriastradh   case TYPE_BIT_5:
2088af69d88dSmrg   case TYPE_BIT_6:
2089af69d88dSmrg   case TYPE_BIT_7:
20903464ebd5Sriastradh      shift = d->type - TYPE_BIT_0;
20913464ebd5Sriastradh      params[0] = (*(GLbitfield *) p >> shift) & 1;
20923464ebd5Sriastradh      break;
2093cdc920a0Smrg   }
2094cdc920a0Smrg}
2095cdc920a0Smrg
2096cdc920a0Smrgvoid GLAPIENTRY
20973464ebd5Sriastradh_mesa_GetInteger64v(GLenum pname, GLint64 *params)
2098cdc920a0Smrg{
20993464ebd5Sriastradh   const struct value_desc *d;
21003464ebd5Sriastradh   union value v;
21013464ebd5Sriastradh   GLmatrix *m;
21023464ebd5Sriastradh   int shift, i;
21033464ebd5Sriastradh   void *p;
2104cdc920a0Smrg
21053464ebd5Sriastradh   d = find_value("glGetInteger64v", pname, &p, &v);
21063464ebd5Sriastradh   switch (d->type) {
21073464ebd5Sriastradh   case TYPE_INVALID:
21083464ebd5Sriastradh      break;
21093464ebd5Sriastradh   case TYPE_CONST:
21103464ebd5Sriastradh      params[0] = d->offset;
21113464ebd5Sriastradh      break;
2112cdc920a0Smrg
211301e04c3fSmrg   case TYPE_FLOAT_8:
21147ec681f3Smrg      params[7] = llround(((GLfloat *) p)[7]);
21157ec681f3Smrg      params[6] = llround(((GLfloat *) p)[6]);
21167ec681f3Smrg      params[5] = llround(((GLfloat *) p)[5]);
21177ec681f3Smrg      params[4] = llround(((GLfloat *) p)[4]);
21187ec681f3Smrg      FALLTHROUGH;
21193464ebd5Sriastradh   case TYPE_FLOAT_4:
21207ec681f3Smrg      params[3] = llround(((GLfloat *) p)[3]);
21217ec681f3Smrg      FALLTHROUGH;
21223464ebd5Sriastradh   case TYPE_FLOAT_3:
21237ec681f3Smrg      params[2] = llround(((GLfloat *) p)[2]);
21247ec681f3Smrg      FALLTHROUGH;
21253464ebd5Sriastradh   case TYPE_FLOAT_2:
21267ec681f3Smrg      params[1] = llround(((GLfloat *) p)[1]);
21277ec681f3Smrg      FALLTHROUGH;
21283464ebd5Sriastradh   case TYPE_FLOAT:
21297ec681f3Smrg      params[0] = llround(((GLfloat *) p)[0]);
21303464ebd5Sriastradh      break;
2131cdc920a0Smrg
21323464ebd5Sriastradh   case TYPE_FLOATN_4:
213301e04c3fSmrg      params[3] = FLOAT_TO_INT(((GLfloat *) p)[3]);
21347ec681f3Smrg      FALLTHROUGH;
21353464ebd5Sriastradh   case TYPE_FLOATN_3:
213601e04c3fSmrg      params[2] = FLOAT_TO_INT(((GLfloat *) p)[2]);
21377ec681f3Smrg      FALLTHROUGH;
21383464ebd5Sriastradh   case TYPE_FLOATN_2:
213901e04c3fSmrg      params[1] = FLOAT_TO_INT(((GLfloat *) p)[1]);
21407ec681f3Smrg      FALLTHROUGH;
21413464ebd5Sriastradh   case TYPE_FLOATN:
214201e04c3fSmrg      params[0] = FLOAT_TO_INT(((GLfloat *) p)[0]);
21433464ebd5Sriastradh      break;
21443464ebd5Sriastradh
2145af69d88dSmrg   case TYPE_DOUBLEN_2:
214601e04c3fSmrg      params[1] = FLOAT_TO_INT(((GLdouble *) p)[1]);
21477ec681f3Smrg      FALLTHROUGH;
21483464ebd5Sriastradh   case TYPE_DOUBLEN:
214901e04c3fSmrg      params[0] = FLOAT_TO_INT(((GLdouble *) p)[0]);
21503464ebd5Sriastradh      break;
21513464ebd5Sriastradh
21523464ebd5Sriastradh   case TYPE_INT_4:
21533464ebd5Sriastradh      params[3] = ((GLint *) p)[3];
21547ec681f3Smrg      FALLTHROUGH;
21553464ebd5Sriastradh   case TYPE_INT_3:
21563464ebd5Sriastradh      params[2] = ((GLint *) p)[2];
21577ec681f3Smrg      FALLTHROUGH;
21583464ebd5Sriastradh   case TYPE_INT_2:
21593464ebd5Sriastradh   case TYPE_ENUM_2:
21603464ebd5Sriastradh      params[1] = ((GLint *) p)[1];
21617ec681f3Smrg      FALLTHROUGH;
21623464ebd5Sriastradh   case TYPE_INT:
21633464ebd5Sriastradh   case TYPE_ENUM:
21643464ebd5Sriastradh      params[0] = ((GLint *) p)[0];
21653464ebd5Sriastradh      break;
21663464ebd5Sriastradh
216701e04c3fSmrg   case TYPE_ENUM16:
216801e04c3fSmrg      params[0] = ((GLenum16 *) p)[0];
216901e04c3fSmrg      break;
217001e04c3fSmrg
21713464ebd5Sriastradh   case TYPE_INT_N:
21723464ebd5Sriastradh      for (i = 0; i < v.value_int_n.n; i++)
217301e04c3fSmrg         params[i] = v.value_int_n.ints[i];
217401e04c3fSmrg      break;
217501e04c3fSmrg
217601e04c3fSmrg   case TYPE_UINT_4:
217701e04c3fSmrg      params[3] = ((GLuint *) p)[3];
21787ec681f3Smrg      FALLTHROUGH;
217901e04c3fSmrg   case TYPE_UINT_3:
218001e04c3fSmrg      params[2] = ((GLuint *) p)[2];
21817ec681f3Smrg      FALLTHROUGH;
218201e04c3fSmrg   case TYPE_UINT_2:
218301e04c3fSmrg      params[1] = ((GLuint *) p)[1];
21847ec681f3Smrg      FALLTHROUGH;
218501e04c3fSmrg   case TYPE_UINT:
218601e04c3fSmrg      params[0] = ((GLuint *) p)[0];
21873464ebd5Sriastradh      break;
21883464ebd5Sriastradh
21893464ebd5Sriastradh   case TYPE_INT64:
21903464ebd5Sriastradh      params[0] = ((GLint64 *) p)[0];
21913464ebd5Sriastradh      break;
21923464ebd5Sriastradh
21933464ebd5Sriastradh   case TYPE_BOOLEAN:
21943464ebd5Sriastradh      params[0] = ((GLboolean*) p)[0];
219501e04c3fSmrg      break;
21963464ebd5Sriastradh
21973464ebd5Sriastradh   case TYPE_MATRIX:
21983464ebd5Sriastradh      m = *(GLmatrix **) p;
21993464ebd5Sriastradh      for (i = 0; i < 16; i++)
220001e04c3fSmrg         params[i] = FLOAT_TO_INT64(m->m[i]);
22013464ebd5Sriastradh      break;
22023464ebd5Sriastradh
22033464ebd5Sriastradh   case TYPE_MATRIX_T:
22043464ebd5Sriastradh      m = *(GLmatrix **) p;
22053464ebd5Sriastradh      for (i = 0; i < 16; i++)
220601e04c3fSmrg         params[i] = FLOAT_TO_INT64(m->m[transpose[i]]);
22073464ebd5Sriastradh      break;
22083464ebd5Sriastradh
22093464ebd5Sriastradh   case TYPE_BIT_0:
22103464ebd5Sriastradh   case TYPE_BIT_1:
22113464ebd5Sriastradh   case TYPE_BIT_2:
22123464ebd5Sriastradh   case TYPE_BIT_3:
22133464ebd5Sriastradh   case TYPE_BIT_4:
22143464ebd5Sriastradh   case TYPE_BIT_5:
2215af69d88dSmrg   case TYPE_BIT_6:
2216af69d88dSmrg   case TYPE_BIT_7:
22173464ebd5Sriastradh      shift = d->type - TYPE_BIT_0;
22183464ebd5Sriastradh      params[0] = (*(GLbitfield *) p >> shift) & 1;
22193464ebd5Sriastradh      break;
2220cdc920a0Smrg   }
2221cdc920a0Smrg}
2222cdc920a0Smrg
2223cdc920a0Smrgvoid GLAPIENTRY
22243464ebd5Sriastradh_mesa_GetDoublev(GLenum pname, GLdouble *params)
2225cdc920a0Smrg{
22263464ebd5Sriastradh   const struct value_desc *d;
22273464ebd5Sriastradh   union value v;
22283464ebd5Sriastradh   GLmatrix *m;
22293464ebd5Sriastradh   int shift, i;
22303464ebd5Sriastradh   void *p;
2231cdc920a0Smrg
22323464ebd5Sriastradh   d = find_value("glGetDoublev", pname, &p, &v);
22333464ebd5Sriastradh   switch (d->type) {
22343464ebd5Sriastradh   case TYPE_INVALID:
22353464ebd5Sriastradh      break;
22363464ebd5Sriastradh   case TYPE_CONST:
22373464ebd5Sriastradh      params[0] = d->offset;
22383464ebd5Sriastradh      break;
22393464ebd5Sriastradh
224001e04c3fSmrg   case TYPE_FLOAT_8:
224101e04c3fSmrg      params[7] = ((GLfloat *) p)[7];
224201e04c3fSmrg      params[6] = ((GLfloat *) p)[6];
224301e04c3fSmrg      params[5] = ((GLfloat *) p)[5];
224401e04c3fSmrg      params[4] = ((GLfloat *) p)[4];
22457ec681f3Smrg      FALLTHROUGH;
22463464ebd5Sriastradh   case TYPE_FLOAT_4:
22473464ebd5Sriastradh   case TYPE_FLOATN_4:
22483464ebd5Sriastradh      params[3] = ((GLfloat *) p)[3];
22497ec681f3Smrg      FALLTHROUGH;
22503464ebd5Sriastradh   case TYPE_FLOAT_3:
22513464ebd5Sriastradh   case TYPE_FLOATN_3:
22523464ebd5Sriastradh      params[2] = ((GLfloat *) p)[2];
22537ec681f3Smrg      FALLTHROUGH;
22543464ebd5Sriastradh   case TYPE_FLOAT_2:
22553464ebd5Sriastradh   case TYPE_FLOATN_2:
22563464ebd5Sriastradh      params[1] = ((GLfloat *) p)[1];
22577ec681f3Smrg      FALLTHROUGH;
22583464ebd5Sriastradh   case TYPE_FLOAT:
22593464ebd5Sriastradh   case TYPE_FLOATN:
22603464ebd5Sriastradh      params[0] = ((GLfloat *) p)[0];
22613464ebd5Sriastradh      break;
22623464ebd5Sriastradh
2263af69d88dSmrg   case TYPE_DOUBLEN_2:
2264af69d88dSmrg      params[1] = ((GLdouble *) p)[1];
22657ec681f3Smrg      FALLTHROUGH;
22663464ebd5Sriastradh   case TYPE_DOUBLEN:
22673464ebd5Sriastradh      params[0] = ((GLdouble *) p)[0];
22683464ebd5Sriastradh      break;
22693464ebd5Sriastradh
22703464ebd5Sriastradh   case TYPE_INT_4:
22713464ebd5Sriastradh      params[3] = ((GLint *) p)[3];
22727ec681f3Smrg      FALLTHROUGH;
22733464ebd5Sriastradh   case TYPE_INT_3:
22743464ebd5Sriastradh      params[2] = ((GLint *) p)[2];
22757ec681f3Smrg      FALLTHROUGH;
22763464ebd5Sriastradh   case TYPE_INT_2:
22773464ebd5Sriastradh   case TYPE_ENUM_2:
22783464ebd5Sriastradh      params[1] = ((GLint *) p)[1];
22797ec681f3Smrg      FALLTHROUGH;
22803464ebd5Sriastradh   case TYPE_INT:
22813464ebd5Sriastradh   case TYPE_ENUM:
22823464ebd5Sriastradh      params[0] = ((GLint *) p)[0];
22833464ebd5Sriastradh      break;
22843464ebd5Sriastradh
228501e04c3fSmrg   case TYPE_ENUM16:
228601e04c3fSmrg      params[0] = ((GLenum16 *) p)[0];
228701e04c3fSmrg      break;
228801e04c3fSmrg
22893464ebd5Sriastradh   case TYPE_INT_N:
22903464ebd5Sriastradh      for (i = 0; i < v.value_int_n.n; i++)
229101e04c3fSmrg         params[i] = v.value_int_n.ints[i];
229201e04c3fSmrg      break;
229301e04c3fSmrg
229401e04c3fSmrg   case TYPE_UINT_4:
229501e04c3fSmrg      params[3] = ((GLuint *) p)[3];
22967ec681f3Smrg      FALLTHROUGH;
229701e04c3fSmrg   case TYPE_UINT_3:
229801e04c3fSmrg      params[2] = ((GLuint *) p)[2];
22997ec681f3Smrg      FALLTHROUGH;
230001e04c3fSmrg   case TYPE_UINT_2:
230101e04c3fSmrg      params[1] = ((GLuint *) p)[1];
23027ec681f3Smrg      FALLTHROUGH;
230301e04c3fSmrg   case TYPE_UINT:
230401e04c3fSmrg      params[0] = ((GLuint *) p)[0];
23053464ebd5Sriastradh      break;
23063464ebd5Sriastradh
23073464ebd5Sriastradh   case TYPE_INT64:
2308af69d88dSmrg      params[0] = (GLdouble) (((GLint64 *) p)[0]);
23093464ebd5Sriastradh      break;
23103464ebd5Sriastradh
23113464ebd5Sriastradh   case TYPE_BOOLEAN:
23123464ebd5Sriastradh      params[0] = *(GLboolean*) p;
231301e04c3fSmrg      break;
231401e04c3fSmrg
231501e04c3fSmrg   case TYPE_UBYTE:
231601e04c3fSmrg      params[0] = ((GLubyte *) p)[0];
231701e04c3fSmrg      break;
231801e04c3fSmrg
231901e04c3fSmrg   case TYPE_SHORT:
232001e04c3fSmrg      params[0] = ((GLshort *) p)[0];
232101e04c3fSmrg      break;
23223464ebd5Sriastradh
23233464ebd5Sriastradh   case TYPE_MATRIX:
23243464ebd5Sriastradh      m = *(GLmatrix **) p;
23253464ebd5Sriastradh      for (i = 0; i < 16; i++)
232601e04c3fSmrg         params[i] = m->m[i];
23273464ebd5Sriastradh      break;
23283464ebd5Sriastradh
23293464ebd5Sriastradh   case TYPE_MATRIX_T:
23303464ebd5Sriastradh      m = *(GLmatrix **) p;
23313464ebd5Sriastradh      for (i = 0; i < 16; i++)
233201e04c3fSmrg         params[i] = m->m[transpose[i]];
23333464ebd5Sriastradh      break;
23343464ebd5Sriastradh
23353464ebd5Sriastradh   case TYPE_BIT_0:
23363464ebd5Sriastradh   case TYPE_BIT_1:
23373464ebd5Sriastradh   case TYPE_BIT_2:
23383464ebd5Sriastradh   case TYPE_BIT_3:
23393464ebd5Sriastradh   case TYPE_BIT_4:
23403464ebd5Sriastradh   case TYPE_BIT_5:
2341af69d88dSmrg   case TYPE_BIT_6:
2342af69d88dSmrg   case TYPE_BIT_7:
23433464ebd5Sriastradh      shift = d->type - TYPE_BIT_0;
23443464ebd5Sriastradh      params[0] = (*(GLbitfield *) p >> shift) & 1;
23453464ebd5Sriastradh      break;
23463464ebd5Sriastradh   }
23473464ebd5Sriastradh}
2348cdc920a0Smrg
234901e04c3fSmrgvoid GLAPIENTRY
235001e04c3fSmrg_mesa_GetUnsignedBytevEXT(GLenum pname, GLubyte *data)
235101e04c3fSmrg{
235201e04c3fSmrg   const struct value_desc *d;
235301e04c3fSmrg   union value v;
235401e04c3fSmrg   int shift;
235501e04c3fSmrg   void *p = NULL;
235601e04c3fSmrg   GLsizei size;
235701e04c3fSmrg   const char *func = "glGetUnsignedBytevEXT";
235801e04c3fSmrg
235901e04c3fSmrg   GET_CURRENT_CONTEXT(ctx);
236001e04c3fSmrg
236101e04c3fSmrg   if (!ctx->Extensions.EXT_memory_object) {
236201e04c3fSmrg      _mesa_error(ctx, GL_INVALID_OPERATION, "%s(unsupported)", func);
236301e04c3fSmrg      return;
236401e04c3fSmrg   }
236501e04c3fSmrg
236601e04c3fSmrg   d = find_value(func, pname, &p, &v);
236701e04c3fSmrg   size = get_value_size(d->type, &v);
236801e04c3fSmrg
236901e04c3fSmrg   switch (d->type) {
237001e04c3fSmrg   case TYPE_BIT_0:
237101e04c3fSmrg   case TYPE_BIT_1:
237201e04c3fSmrg   case TYPE_BIT_2:
237301e04c3fSmrg   case TYPE_BIT_3:
237401e04c3fSmrg   case TYPE_BIT_4:
237501e04c3fSmrg   case TYPE_BIT_5:
237601e04c3fSmrg   case TYPE_BIT_6:
237701e04c3fSmrg   case TYPE_BIT_7:
237801e04c3fSmrg      shift = d->type - TYPE_BIT_0;
237901e04c3fSmrg      data[0] = (*(GLbitfield *) p >> shift) & 1;
238001e04c3fSmrg      break;
238101e04c3fSmrg   case TYPE_CONST:
238201e04c3fSmrg      memcpy(data, &d->offset, size);
238301e04c3fSmrg      break;
238401e04c3fSmrg   case TYPE_INT_N:
238501e04c3fSmrg      memcpy(data, &v.value_int_n.ints, size);
238601e04c3fSmrg      break;
238701e04c3fSmrg   case TYPE_UINT:
238801e04c3fSmrg   case TYPE_INT:
238901e04c3fSmrg   case TYPE_INT_2:
239001e04c3fSmrg   case TYPE_UINT_2:
239101e04c3fSmrg   case TYPE_INT_3:
239201e04c3fSmrg   case TYPE_UINT_3:
239301e04c3fSmrg   case TYPE_INT_4:
239401e04c3fSmrg   case TYPE_UINT_4:
239501e04c3fSmrg   case TYPE_INT64:
239601e04c3fSmrg   case TYPE_ENUM:
239701e04c3fSmrg   case TYPE_ENUM_2:
239801e04c3fSmrg   case TYPE_BOOLEAN:
239901e04c3fSmrg   case TYPE_UBYTE:
240001e04c3fSmrg   case TYPE_SHORT:
240101e04c3fSmrg   case TYPE_FLOAT:
240201e04c3fSmrg   case TYPE_FLOATN:
240301e04c3fSmrg   case TYPE_FLOAT_2:
240401e04c3fSmrg   case TYPE_FLOATN_2:
240501e04c3fSmrg   case TYPE_FLOAT_3:
240601e04c3fSmrg   case TYPE_FLOATN_3:
240701e04c3fSmrg   case TYPE_FLOAT_4:
240801e04c3fSmrg   case TYPE_FLOATN_4:
240901e04c3fSmrg   case TYPE_FLOAT_8:
241001e04c3fSmrg   case TYPE_DOUBLEN:
241101e04c3fSmrg   case TYPE_DOUBLEN_2:
241201e04c3fSmrg   case TYPE_MATRIX:
241301e04c3fSmrg   case TYPE_MATRIX_T:
241401e04c3fSmrg      memcpy(data, p, size);
241501e04c3fSmrg      break;
241601e04c3fSmrg   case TYPE_ENUM16: {
241701e04c3fSmrg      GLenum e = *(GLenum16 *)p;
241801e04c3fSmrg      memcpy(data, &e, sizeof(e));
241901e04c3fSmrg      break;
242001e04c3fSmrg   }
242101e04c3fSmrg   default:
242201e04c3fSmrg      break; /* nothing - GL error was recorded */
242301e04c3fSmrg   }
242401e04c3fSmrg}
242501e04c3fSmrg
242601e04c3fSmrg/**
242701e04c3fSmrg * Convert a GL texture binding enum such as GL_TEXTURE_BINDING_2D
242801e04c3fSmrg * into the corresponding Mesa texture target index.
242901e04c3fSmrg * \return TEXTURE_x_INDEX or -1 if binding is invalid
243001e04c3fSmrg */
243101e04c3fSmrgstatic int
243201e04c3fSmrgtex_binding_to_index(const struct gl_context *ctx, GLenum binding)
243301e04c3fSmrg{
243401e04c3fSmrg   switch (binding) {
243501e04c3fSmrg   case GL_TEXTURE_BINDING_1D:
243601e04c3fSmrg      return _mesa_is_desktop_gl(ctx) ? TEXTURE_1D_INDEX : -1;
243701e04c3fSmrg   case GL_TEXTURE_BINDING_2D:
243801e04c3fSmrg      return TEXTURE_2D_INDEX;
243901e04c3fSmrg   case GL_TEXTURE_BINDING_3D:
244001e04c3fSmrg      return ctx->API != API_OPENGLES ? TEXTURE_3D_INDEX : -1;
244101e04c3fSmrg   case GL_TEXTURE_BINDING_CUBE_MAP:
244201e04c3fSmrg      return ctx->Extensions.ARB_texture_cube_map
244301e04c3fSmrg         ? TEXTURE_CUBE_INDEX : -1;
244401e04c3fSmrg   case GL_TEXTURE_BINDING_RECTANGLE:
244501e04c3fSmrg      return _mesa_is_desktop_gl(ctx) && ctx->Extensions.NV_texture_rectangle
244601e04c3fSmrg         ? TEXTURE_RECT_INDEX : -1;
244701e04c3fSmrg   case GL_TEXTURE_BINDING_1D_ARRAY:
244801e04c3fSmrg      return _mesa_is_desktop_gl(ctx) && ctx->Extensions.EXT_texture_array
244901e04c3fSmrg         ? TEXTURE_1D_ARRAY_INDEX : -1;
245001e04c3fSmrg   case GL_TEXTURE_BINDING_2D_ARRAY:
245101e04c3fSmrg      return (_mesa_is_desktop_gl(ctx) && ctx->Extensions.EXT_texture_array)
245201e04c3fSmrg         || _mesa_is_gles3(ctx)
245301e04c3fSmrg         ? TEXTURE_2D_ARRAY_INDEX : -1;
245401e04c3fSmrg   case GL_TEXTURE_BINDING_BUFFER:
245501e04c3fSmrg      return (_mesa_has_ARB_texture_buffer_object(ctx) ||
245601e04c3fSmrg              _mesa_has_OES_texture_buffer(ctx)) ?
245701e04c3fSmrg             TEXTURE_BUFFER_INDEX : -1;
245801e04c3fSmrg   case GL_TEXTURE_BINDING_CUBE_MAP_ARRAY:
245901e04c3fSmrg      return _mesa_has_texture_cube_map_array(ctx)
246001e04c3fSmrg         ? TEXTURE_CUBE_ARRAY_INDEX : -1;
246101e04c3fSmrg   case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
246201e04c3fSmrg      return _mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_texture_multisample
246301e04c3fSmrg         ? TEXTURE_2D_MULTISAMPLE_INDEX : -1;
246401e04c3fSmrg   case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY:
246501e04c3fSmrg      return _mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_texture_multisample
246601e04c3fSmrg         ? TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX : -1;
246701e04c3fSmrg   default:
246801e04c3fSmrg      return -1;
246901e04c3fSmrg   }
247001e04c3fSmrg}
247101e04c3fSmrg
24723464ebd5Sriastradhstatic enum value_type
2473af69d88dSmrgfind_value_indexed(const char *func, GLenum pname, GLuint index, union value *v)
24743464ebd5Sriastradh{
24753464ebd5Sriastradh   GET_CURRENT_CONTEXT(ctx);
24767ec681f3Smrg   struct gl_buffer_object *buf;
2477cdc920a0Smrg
2478cdc920a0Smrg   switch (pname) {
24793464ebd5Sriastradh
24803464ebd5Sriastradh   case GL_BLEND:
24813464ebd5Sriastradh      if (index >= ctx->Const.MaxDrawBuffers)
248201e04c3fSmrg         goto invalid_value;
24833464ebd5Sriastradh      if (!ctx->Extensions.EXT_draw_buffers2)
248401e04c3fSmrg         goto invalid_enum;
24853464ebd5Sriastradh      v->value_int = (ctx->Color.BlendEnabled >> index) & 1;
24863464ebd5Sriastradh      return TYPE_INT;
24873464ebd5Sriastradh
24883464ebd5Sriastradh   case GL_BLEND_SRC:
24897ec681f3Smrg      FALLTHROUGH;
24903464ebd5Sriastradh   case GL_BLEND_SRC_RGB:
24913464ebd5Sriastradh      if (index >= ctx->Const.MaxDrawBuffers)
249201e04c3fSmrg         goto invalid_value;
24933464ebd5Sriastradh      if (!ctx->Extensions.ARB_draw_buffers_blend)
249401e04c3fSmrg         goto invalid_enum;
24953464ebd5Sriastradh      v->value_int = ctx->Color.Blend[index].SrcRGB;
24963464ebd5Sriastradh      return TYPE_INT;
24973464ebd5Sriastradh   case GL_BLEND_SRC_ALPHA:
24983464ebd5Sriastradh      if (index >= ctx->Const.MaxDrawBuffers)
249901e04c3fSmrg         goto invalid_value;
25003464ebd5Sriastradh      if (!ctx->Extensions.ARB_draw_buffers_blend)
250101e04c3fSmrg         goto invalid_enum;
25023464ebd5Sriastradh      v->value_int = ctx->Color.Blend[index].SrcA;
25033464ebd5Sriastradh      return TYPE_INT;
25043464ebd5Sriastradh   case GL_BLEND_DST:
25057ec681f3Smrg      FALLTHROUGH;
25063464ebd5Sriastradh   case GL_BLEND_DST_RGB:
25073464ebd5Sriastradh      if (index >= ctx->Const.MaxDrawBuffers)
250801e04c3fSmrg         goto invalid_value;
25093464ebd5Sriastradh      if (!ctx->Extensions.ARB_draw_buffers_blend)
251001e04c3fSmrg         goto invalid_enum;
25113464ebd5Sriastradh      v->value_int = ctx->Color.Blend[index].DstRGB;
25123464ebd5Sriastradh      return TYPE_INT;
25133464ebd5Sriastradh   case GL_BLEND_DST_ALPHA:
25143464ebd5Sriastradh      if (index >= ctx->Const.MaxDrawBuffers)
251501e04c3fSmrg         goto invalid_value;
25163464ebd5Sriastradh      if (!ctx->Extensions.ARB_draw_buffers_blend)
251701e04c3fSmrg         goto invalid_enum;
25183464ebd5Sriastradh      v->value_int = ctx->Color.Blend[index].DstA;
25193464ebd5Sriastradh      return TYPE_INT;
25203464ebd5Sriastradh   case GL_BLEND_EQUATION_RGB:
25213464ebd5Sriastradh      if (index >= ctx->Const.MaxDrawBuffers)
252201e04c3fSmrg         goto invalid_value;
25233464ebd5Sriastradh      if (!ctx->Extensions.ARB_draw_buffers_blend)
252401e04c3fSmrg         goto invalid_enum;
25253464ebd5Sriastradh      v->value_int = ctx->Color.Blend[index].EquationRGB;
25263464ebd5Sriastradh      return TYPE_INT;
25273464ebd5Sriastradh   case GL_BLEND_EQUATION_ALPHA:
25283464ebd5Sriastradh      if (index >= ctx->Const.MaxDrawBuffers)
252901e04c3fSmrg         goto invalid_value;
25303464ebd5Sriastradh      if (!ctx->Extensions.ARB_draw_buffers_blend)
253101e04c3fSmrg         goto invalid_enum;
25323464ebd5Sriastradh      v->value_int = ctx->Color.Blend[index].EquationA;
25333464ebd5Sriastradh      return TYPE_INT;
25343464ebd5Sriastradh
25353464ebd5Sriastradh   case GL_COLOR_WRITEMASK:
25363464ebd5Sriastradh      if (index >= ctx->Const.MaxDrawBuffers)
253701e04c3fSmrg         goto invalid_value;
25383464ebd5Sriastradh      if (!ctx->Extensions.EXT_draw_buffers2)
253901e04c3fSmrg         goto invalid_enum;
254001e04c3fSmrg      v->value_int_4[0] = GET_COLORMASK_BIT(ctx->Color.ColorMask, index, 0);
254101e04c3fSmrg      v->value_int_4[1] = GET_COLORMASK_BIT(ctx->Color.ColorMask, index, 1);
254201e04c3fSmrg      v->value_int_4[2] = GET_COLORMASK_BIT(ctx->Color.ColorMask, index, 2);
254301e04c3fSmrg      v->value_int_4[3] = GET_COLORMASK_BIT(ctx->Color.ColorMask, index, 3);
25443464ebd5Sriastradh      return TYPE_INT_4;
25453464ebd5Sriastradh
2546af69d88dSmrg   case GL_SCISSOR_BOX:
2547af69d88dSmrg      if (index >= ctx->Const.MaxViewports)
2548af69d88dSmrg         goto invalid_value;
2549af69d88dSmrg      v->value_int_4[0] = ctx->Scissor.ScissorArray[index].X;
2550af69d88dSmrg      v->value_int_4[1] = ctx->Scissor.ScissorArray[index].Y;
2551af69d88dSmrg      v->value_int_4[2] = ctx->Scissor.ScissorArray[index].Width;
2552af69d88dSmrg      v->value_int_4[3] = ctx->Scissor.ScissorArray[index].Height;
2553af69d88dSmrg      return TYPE_INT_4;
2554af69d88dSmrg
255501e04c3fSmrg   case GL_WINDOW_RECTANGLE_EXT:
255601e04c3fSmrg      if (!ctx->Extensions.EXT_window_rectangles)
255701e04c3fSmrg         goto invalid_enum;
255801e04c3fSmrg      if (index >= ctx->Const.MaxWindowRectangles)
255901e04c3fSmrg         goto invalid_value;
256001e04c3fSmrg      v->value_int_4[0] = ctx->Scissor.WindowRects[index].X;
256101e04c3fSmrg      v->value_int_4[1] = ctx->Scissor.WindowRects[index].Y;
256201e04c3fSmrg      v->value_int_4[2] = ctx->Scissor.WindowRects[index].Width;
256301e04c3fSmrg      v->value_int_4[3] = ctx->Scissor.WindowRects[index].Height;
256401e04c3fSmrg      return TYPE_INT_4;
256501e04c3fSmrg
2566af69d88dSmrg   case GL_VIEWPORT:
2567af69d88dSmrg      if (index >= ctx->Const.MaxViewports)
2568af69d88dSmrg         goto invalid_value;
2569af69d88dSmrg      v->value_float_4[0] = ctx->ViewportArray[index].X;
2570af69d88dSmrg      v->value_float_4[1] = ctx->ViewportArray[index].Y;
2571af69d88dSmrg      v->value_float_4[2] = ctx->ViewportArray[index].Width;
2572af69d88dSmrg      v->value_float_4[3] = ctx->ViewportArray[index].Height;
2573af69d88dSmrg      return TYPE_FLOAT_4;
2574af69d88dSmrg
2575af69d88dSmrg   case GL_DEPTH_RANGE:
2576af69d88dSmrg      if (index >= ctx->Const.MaxViewports)
2577af69d88dSmrg         goto invalid_value;
2578af69d88dSmrg      v->value_double_2[0] = ctx->ViewportArray[index].Near;
2579af69d88dSmrg      v->value_double_2[1] = ctx->ViewportArray[index].Far;
2580af69d88dSmrg      return TYPE_DOUBLEN_2;
2581af69d88dSmrg
25823464ebd5Sriastradh   case GL_TRANSFORM_FEEDBACK_BUFFER_START:
2583af69d88dSmrg      if (index >= ctx->Const.MaxTransformFeedbackBuffers)
258401e04c3fSmrg         goto invalid_value;
25853464ebd5Sriastradh      if (!ctx->Extensions.EXT_transform_feedback)
258601e04c3fSmrg         goto invalid_enum;
25873464ebd5Sriastradh      v->value_int64 = ctx->TransformFeedback.CurrentObject->Offset[index];
25883464ebd5Sriastradh      return TYPE_INT64;
25893464ebd5Sriastradh
25903464ebd5Sriastradh   case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
2591af69d88dSmrg      if (index >= ctx->Const.MaxTransformFeedbackBuffers)
259201e04c3fSmrg         goto invalid_value;
25933464ebd5Sriastradh      if (!ctx->Extensions.EXT_transform_feedback)
259401e04c3fSmrg         goto invalid_enum;
2595af69d88dSmrg      v->value_int64
2596af69d88dSmrg         = ctx->TransformFeedback.CurrentObject->RequestedSize[index];
25973464ebd5Sriastradh      return TYPE_INT64;
25983464ebd5Sriastradh
25993464ebd5Sriastradh   case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
2600af69d88dSmrg      if (index >= ctx->Const.MaxTransformFeedbackBuffers)
260101e04c3fSmrg         goto invalid_value;
26023464ebd5Sriastradh      if (!ctx->Extensions.EXT_transform_feedback)
260301e04c3fSmrg         goto invalid_enum;
2604af69d88dSmrg      v->value_int = ctx->TransformFeedback.CurrentObject->BufferNames[index];
2605af69d88dSmrg      return TYPE_INT;
2606af69d88dSmrg
2607af69d88dSmrg   case GL_UNIFORM_BUFFER_BINDING:
2608af69d88dSmrg      if (index >= ctx->Const.MaxUniformBufferBindings)
260901e04c3fSmrg         goto invalid_value;
2610af69d88dSmrg      if (!ctx->Extensions.ARB_uniform_buffer_object)
261101e04c3fSmrg         goto invalid_enum;
26127ec681f3Smrg      buf = ctx->UniformBufferBindings[index].BufferObject;
26137ec681f3Smrg      v->value_int = buf ? buf->Name : 0;
2614af69d88dSmrg      return TYPE_INT;
2615af69d88dSmrg
2616af69d88dSmrg   case GL_UNIFORM_BUFFER_START:
2617af69d88dSmrg      if (index >= ctx->Const.MaxUniformBufferBindings)
261801e04c3fSmrg         goto invalid_value;
2619af69d88dSmrg      if (!ctx->Extensions.ARB_uniform_buffer_object)
262001e04c3fSmrg         goto invalid_enum;
262101e04c3fSmrg      v->value_int = ctx->UniformBufferBindings[index].Offset < 0 ? 0 :
262201e04c3fSmrg                     ctx->UniformBufferBindings[index].Offset;
2623af69d88dSmrg      return TYPE_INT;
2624af69d88dSmrg
2625af69d88dSmrg   case GL_UNIFORM_BUFFER_SIZE:
2626af69d88dSmrg      if (index >= ctx->Const.MaxUniformBufferBindings)
262701e04c3fSmrg         goto invalid_value;
2628af69d88dSmrg      if (!ctx->Extensions.ARB_uniform_buffer_object)
262901e04c3fSmrg         goto invalid_enum;
263001e04c3fSmrg      v->value_int = ctx->UniformBufferBindings[index].Size < 0 ? 0 :
263101e04c3fSmrg                     ctx->UniformBufferBindings[index].Size;
263201e04c3fSmrg      return TYPE_INT;
263301e04c3fSmrg
263401e04c3fSmrg   /* ARB_shader_storage_buffer_object */
263501e04c3fSmrg   case GL_SHADER_STORAGE_BUFFER_BINDING:
26367ec681f3Smrg      if (!ctx->Extensions.ARB_shader_storage_buffer_object && !_mesa_is_gles31(ctx))
263701e04c3fSmrg         goto invalid_enum;
263801e04c3fSmrg      if (index >= ctx->Const.MaxShaderStorageBufferBindings)
263901e04c3fSmrg         goto invalid_value;
26407ec681f3Smrg      buf = ctx->ShaderStorageBufferBindings[index].BufferObject;
26417ec681f3Smrg      v->value_int = buf ? buf->Name : 0;
264201e04c3fSmrg      return TYPE_INT;
264301e04c3fSmrg
264401e04c3fSmrg   case GL_SHADER_STORAGE_BUFFER_START:
26457ec681f3Smrg      if (!ctx->Extensions.ARB_shader_storage_buffer_object && !_mesa_is_gles31(ctx))
264601e04c3fSmrg         goto invalid_enum;
264701e04c3fSmrg      if (index >= ctx->Const.MaxShaderStorageBufferBindings)
264801e04c3fSmrg         goto invalid_value;
264901e04c3fSmrg      v->value_int = ctx->ShaderStorageBufferBindings[index].Offset < 0 ? 0 :
265001e04c3fSmrg                     ctx->ShaderStorageBufferBindings[index].Offset;
265101e04c3fSmrg      return TYPE_INT;
265201e04c3fSmrg
265301e04c3fSmrg   case GL_SHADER_STORAGE_BUFFER_SIZE:
26547ec681f3Smrg      if (!ctx->Extensions.ARB_shader_storage_buffer_object && !_mesa_is_gles31(ctx))
265501e04c3fSmrg         goto invalid_enum;
265601e04c3fSmrg      if (index >= ctx->Const.MaxShaderStorageBufferBindings)
265701e04c3fSmrg         goto invalid_value;
265801e04c3fSmrg      v->value_int = ctx->ShaderStorageBufferBindings[index].Size < 0 ? 0 :
265901e04c3fSmrg                     ctx->ShaderStorageBufferBindings[index].Size;
2660af69d88dSmrg      return TYPE_INT;
2661af69d88dSmrg
2662af69d88dSmrg   /* ARB_texture_multisample / GL3.2 */
2663af69d88dSmrg   case GL_SAMPLE_MASK_VALUE:
2664af69d88dSmrg      if (index != 0)
2665af69d88dSmrg         goto invalid_value;
2666af69d88dSmrg      if (!ctx->Extensions.ARB_texture_multisample)
2667af69d88dSmrg         goto invalid_enum;
2668af69d88dSmrg      v->value_int = ctx->Multisample.SampleMaskValue;
2669af69d88dSmrg      return TYPE_INT;
2670af69d88dSmrg
2671af69d88dSmrg   case GL_ATOMIC_COUNTER_BUFFER_BINDING:
26727ec681f3Smrg      if (!ctx->Extensions.ARB_shader_atomic_counters && !_mesa_is_gles31(ctx))
2673af69d88dSmrg         goto invalid_enum;
2674af69d88dSmrg      if (index >= ctx->Const.MaxAtomicBufferBindings)
2675af69d88dSmrg         goto invalid_value;
26767ec681f3Smrg      buf = ctx->AtomicBufferBindings[index].BufferObject;
26777ec681f3Smrg      v->value_int = buf ? buf->Name : 0;
2678af69d88dSmrg      return TYPE_INT;
2679af69d88dSmrg
2680af69d88dSmrg   case GL_ATOMIC_COUNTER_BUFFER_START:
26817ec681f3Smrg      if (!ctx->Extensions.ARB_shader_atomic_counters && !_mesa_is_gles31(ctx))
2682af69d88dSmrg         goto invalid_enum;
2683af69d88dSmrg      if (index >= ctx->Const.MaxAtomicBufferBindings)
2684af69d88dSmrg         goto invalid_value;
268501e04c3fSmrg      v->value_int64 = ctx->AtomicBufferBindings[index].Offset < 0 ? 0 :
268601e04c3fSmrg                       ctx->AtomicBufferBindings[index].Offset;
2687af69d88dSmrg      return TYPE_INT64;
2688af69d88dSmrg
2689af69d88dSmrg   case GL_ATOMIC_COUNTER_BUFFER_SIZE:
26907ec681f3Smrg      if (!ctx->Extensions.ARB_shader_atomic_counters && !_mesa_is_gles31(ctx))
2691af69d88dSmrg         goto invalid_enum;
2692af69d88dSmrg      if (index >= ctx->Const.MaxAtomicBufferBindings)
2693af69d88dSmrg         goto invalid_value;
269401e04c3fSmrg      v->value_int64 = ctx->AtomicBufferBindings[index].Size < 0 ? 0 :
269501e04c3fSmrg                       ctx->AtomicBufferBindings[index].Size;
2696af69d88dSmrg      return TYPE_INT64;
2697af69d88dSmrg
2698af69d88dSmrg   case GL_VERTEX_BINDING_DIVISOR:
269901e04c3fSmrg      if ((!_mesa_is_desktop_gl(ctx) || !ctx->Extensions.ARB_instanced_arrays) &&
270001e04c3fSmrg          !_mesa_is_gles31(ctx))
2701af69d88dSmrg          goto invalid_enum;
2702af69d88dSmrg      if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs)
2703af69d88dSmrg          goto invalid_value;
270401e04c3fSmrg      v->value_int = ctx->Array.VAO->BufferBinding[VERT_ATTRIB_GENERIC(index)].InstanceDivisor;
2705af69d88dSmrg      return TYPE_INT;
2706af69d88dSmrg
2707af69d88dSmrg   case GL_VERTEX_BINDING_OFFSET:
270801e04c3fSmrg      if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles31(ctx))
2709af69d88dSmrg          goto invalid_enum;
2710af69d88dSmrg      if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs)
2711af69d88dSmrg          goto invalid_value;
271201e04c3fSmrg      v->value_int = ctx->Array.VAO->BufferBinding[VERT_ATTRIB_GENERIC(index)].Offset;
2713af69d88dSmrg      return TYPE_INT;
2714af69d88dSmrg
2715af69d88dSmrg   case GL_VERTEX_BINDING_STRIDE:
271601e04c3fSmrg      if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles31(ctx))
2717af69d88dSmrg          goto invalid_enum;
2718af69d88dSmrg      if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs)
2719af69d88dSmrg          goto invalid_value;
272001e04c3fSmrg      v->value_int = ctx->Array.VAO->BufferBinding[VERT_ATTRIB_GENERIC(index)].Stride;
272101e04c3fSmrg      return TYPE_INT;
272201e04c3fSmrg
272301e04c3fSmrg   case GL_VERTEX_BINDING_BUFFER:
272401e04c3fSmrg      if (ctx->API == API_OPENGLES2 && ctx->Version < 31)
272501e04c3fSmrg         goto invalid_enum;
272601e04c3fSmrg      if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs)
272701e04c3fSmrg         goto invalid_value;
27287ec681f3Smrg      buf = ctx->Array.VAO->BufferBinding[VERT_ATTRIB_GENERIC(index)].BufferObj;
27297ec681f3Smrg      v->value_int = buf ? buf->Name : 0;
273001e04c3fSmrg      return TYPE_INT;
2731af69d88dSmrg
2732af69d88dSmrg   /* ARB_shader_image_load_store */
2733af69d88dSmrg   case GL_IMAGE_BINDING_NAME: {
2734af69d88dSmrg      struct gl_texture_object *t;
2735af69d88dSmrg
27367ec681f3Smrg      if (!ctx->Extensions.ARB_shader_image_load_store && !_mesa_is_gles31(ctx))
2737af69d88dSmrg         goto invalid_enum;
2738af69d88dSmrg      if (index >= ctx->Const.MaxImageUnits)
2739af69d88dSmrg         goto invalid_value;
2740af69d88dSmrg
2741af69d88dSmrg      t = ctx->ImageUnits[index].TexObj;
2742af69d88dSmrg      v->value_int = (t ? t->Name : 0);
2743af69d88dSmrg      return TYPE_INT;
2744af69d88dSmrg   }
2745af69d88dSmrg
2746af69d88dSmrg   case GL_IMAGE_BINDING_LEVEL:
27477ec681f3Smrg      if (!ctx->Extensions.ARB_shader_image_load_store && !_mesa_is_gles31(ctx))
2748af69d88dSmrg         goto invalid_enum;
2749af69d88dSmrg      if (index >= ctx->Const.MaxImageUnits)
2750af69d88dSmrg         goto invalid_value;
2751af69d88dSmrg
2752af69d88dSmrg      v->value_int = ctx->ImageUnits[index].Level;
2753af69d88dSmrg      return TYPE_INT;
2754af69d88dSmrg
2755af69d88dSmrg   case GL_IMAGE_BINDING_LAYERED:
27567ec681f3Smrg      if (!ctx->Extensions.ARB_shader_image_load_store && !_mesa_is_gles31(ctx))
2757af69d88dSmrg         goto invalid_enum;
2758af69d88dSmrg      if (index >= ctx->Const.MaxImageUnits)
2759af69d88dSmrg         goto invalid_value;
2760af69d88dSmrg
2761af69d88dSmrg      v->value_int = ctx->ImageUnits[index].Layered;
2762af69d88dSmrg      return TYPE_INT;
2763af69d88dSmrg
2764af69d88dSmrg   case GL_IMAGE_BINDING_LAYER:
27657ec681f3Smrg      if (!ctx->Extensions.ARB_shader_image_load_store && !_mesa_is_gles31(ctx))
2766af69d88dSmrg         goto invalid_enum;
2767af69d88dSmrg      if (index >= ctx->Const.MaxImageUnits)
2768af69d88dSmrg         goto invalid_value;
2769af69d88dSmrg
2770af69d88dSmrg      v->value_int = ctx->ImageUnits[index].Layer;
2771af69d88dSmrg      return TYPE_INT;
2772af69d88dSmrg
2773af69d88dSmrg   case GL_IMAGE_BINDING_ACCESS:
27747ec681f3Smrg      if (!ctx->Extensions.ARB_shader_image_load_store && !_mesa_is_gles31(ctx))
2775af69d88dSmrg         goto invalid_enum;
2776af69d88dSmrg      if (index >= ctx->Const.MaxImageUnits)
2777af69d88dSmrg         goto invalid_value;
2778af69d88dSmrg
2779af69d88dSmrg      v->value_int = ctx->ImageUnits[index].Access;
2780af69d88dSmrg      return TYPE_INT;
2781af69d88dSmrg
2782af69d88dSmrg   case GL_IMAGE_BINDING_FORMAT:
27837ec681f3Smrg      if (!ctx->Extensions.ARB_shader_image_load_store && !_mesa_is_gles31(ctx))
2784af69d88dSmrg         goto invalid_enum;
2785af69d88dSmrg      if (index >= ctx->Const.MaxImageUnits)
2786af69d88dSmrg         goto invalid_value;
2787af69d88dSmrg
2788af69d88dSmrg      v->value_int = ctx->ImageUnits[index].Format;
2789af69d88dSmrg      return TYPE_INT;
2790af69d88dSmrg
279101e04c3fSmrg   /* ARB_direct_state_access */
279201e04c3fSmrg   case GL_TEXTURE_BINDING_1D:
279301e04c3fSmrg   case GL_TEXTURE_BINDING_1D_ARRAY:
279401e04c3fSmrg   case GL_TEXTURE_BINDING_2D:
279501e04c3fSmrg   case GL_TEXTURE_BINDING_2D_ARRAY:
279601e04c3fSmrg   case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
279701e04c3fSmrg   case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY:
279801e04c3fSmrg   case GL_TEXTURE_BINDING_3D:
279901e04c3fSmrg   case GL_TEXTURE_BINDING_BUFFER:
280001e04c3fSmrg   case GL_TEXTURE_BINDING_CUBE_MAP:
280101e04c3fSmrg   case GL_TEXTURE_BINDING_CUBE_MAP_ARRAY:
280201e04c3fSmrg   case GL_TEXTURE_BINDING_RECTANGLE: {
280301e04c3fSmrg      int target;
280401e04c3fSmrg
280501e04c3fSmrg      target = tex_binding_to_index(ctx, pname);
280601e04c3fSmrg      if (target < 0)
280701e04c3fSmrg         goto invalid_enum;
280801e04c3fSmrg      if (index >= _mesa_max_tex_unit(ctx))
280901e04c3fSmrg         goto invalid_value;
281001e04c3fSmrg
281101e04c3fSmrg      v->value_int = ctx->Texture.Unit[index].CurrentTex[target]->Name;
281201e04c3fSmrg      return TYPE_INT;
281301e04c3fSmrg   }
281401e04c3fSmrg
281501e04c3fSmrg   case GL_SAMPLER_BINDING: {
281601e04c3fSmrg      struct gl_sampler_object *samp;
281701e04c3fSmrg
281801e04c3fSmrg      if (!_mesa_is_desktop_gl(ctx) || ctx->Version < 33)
281901e04c3fSmrg         goto invalid_enum;
282001e04c3fSmrg      if (index >= _mesa_max_tex_unit(ctx))
282101e04c3fSmrg         goto invalid_value;
282201e04c3fSmrg
282301e04c3fSmrg      samp = ctx->Texture.Unit[index].Sampler;
282401e04c3fSmrg      v->value_int = samp ? samp->Name : 0;
282501e04c3fSmrg      return TYPE_INT;
282601e04c3fSmrg   }
282701e04c3fSmrg
2828af69d88dSmrg   case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
282901e04c3fSmrg      if (!_mesa_has_compute_shaders(ctx))
2830af69d88dSmrg         goto invalid_enum;
2831af69d88dSmrg      if (index >= 3)
2832af69d88dSmrg         goto invalid_value;
2833af69d88dSmrg      v->value_int = ctx->Const.MaxComputeWorkGroupCount[index];
2834af69d88dSmrg      return TYPE_INT;
2835af69d88dSmrg
2836af69d88dSmrg   case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
283701e04c3fSmrg      if (!_mesa_has_compute_shaders(ctx))
2838af69d88dSmrg         goto invalid_enum;
2839af69d88dSmrg      if (index >= 3)
2840af69d88dSmrg         goto invalid_value;
2841af69d88dSmrg      v->value_int = ctx->Const.MaxComputeWorkGroupSize[index];
28423464ebd5Sriastradh      return TYPE_INT;
284301e04c3fSmrg
284401e04c3fSmrg   /* ARB_compute_variable_group_size */
284501e04c3fSmrg   case GL_MAX_COMPUTE_VARIABLE_GROUP_SIZE_ARB:
284601e04c3fSmrg      if (!ctx->Extensions.ARB_compute_variable_group_size)
284701e04c3fSmrg         goto invalid_enum;
284801e04c3fSmrg      if (index >= 3)
284901e04c3fSmrg         goto invalid_value;
285001e04c3fSmrg      v->value_int = ctx->Const.MaxComputeVariableGroupSize[index];
285101e04c3fSmrg      return TYPE_INT;
285201e04c3fSmrg
285301e04c3fSmrg   /* GL_EXT_external_objects */
285401e04c3fSmrg   case GL_NUM_DEVICE_UUIDS_EXT:
285501e04c3fSmrg      v->value_int = 1;
285601e04c3fSmrg      return TYPE_INT;
285701e04c3fSmrg   case GL_DRIVER_UUID_EXT:
285801e04c3fSmrg      if (index >= 1)
285901e04c3fSmrg         goto invalid_value;
286001e04c3fSmrg      _mesa_get_driver_uuid(ctx, v->value_int_4);
286101e04c3fSmrg      return TYPE_INT_4;
286201e04c3fSmrg   case GL_DEVICE_UUID_EXT:
286301e04c3fSmrg      if (index >= 1)
286401e04c3fSmrg         goto invalid_value;
286501e04c3fSmrg      _mesa_get_device_uuid(ctx, v->value_int_4);
286601e04c3fSmrg      return TYPE_INT_4;
28677ec681f3Smrg   /* GL_EXT_direct_state_access */
28687ec681f3Smrg   case GL_TEXTURE_1D:
28697ec681f3Smrg   case GL_TEXTURE_2D:
28707ec681f3Smrg   case GL_TEXTURE_3D:
28717ec681f3Smrg   case GL_TEXTURE_CUBE_MAP:
28727ec681f3Smrg   case GL_TEXTURE_GEN_S:
28737ec681f3Smrg   case GL_TEXTURE_GEN_T:
28747ec681f3Smrg   case GL_TEXTURE_GEN_R:
28757ec681f3Smrg   case GL_TEXTURE_GEN_Q:
28767ec681f3Smrg   case GL_TEXTURE_RECTANGLE_ARB: {
28777ec681f3Smrg      GLuint curTexUnitSave;
28787ec681f3Smrg      if (index >= _mesa_max_tex_unit(ctx))
28797ec681f3Smrg         goto invalid_enum;
28807ec681f3Smrg      curTexUnitSave = ctx->Texture.CurrentUnit;
28817ec681f3Smrg      _mesa_ActiveTexture_no_error(GL_TEXTURE0 + index);
28827ec681f3Smrg      v->value_int = _mesa_IsEnabled(pname);
28837ec681f3Smrg      _mesa_ActiveTexture_no_error(GL_TEXTURE0 + curTexUnitSave);
28847ec681f3Smrg      return TYPE_INT;
28857ec681f3Smrg   }
28867ec681f3Smrg   case GL_TEXTURE_COORD_ARRAY: {
28877ec681f3Smrg      GLuint curTexUnitSave;
28887ec681f3Smrg      if (index >= ctx->Const.MaxTextureCoordUnits)
28897ec681f3Smrg         goto invalid_enum;
28907ec681f3Smrg      curTexUnitSave = ctx->Array.ActiveTexture;
28917ec681f3Smrg      _mesa_ClientActiveTexture(GL_TEXTURE0 + index);
28927ec681f3Smrg      v->value_int = _mesa_IsEnabled(pname);
28937ec681f3Smrg      _mesa_ClientActiveTexture(GL_TEXTURE0 + curTexUnitSave);
28947ec681f3Smrg      return TYPE_INT;
28957ec681f3Smrg   }
28967ec681f3Smrg   case GL_TEXTURE_MATRIX:
28977ec681f3Smrg      if (index >= ARRAY_SIZE(ctx->TextureMatrixStack))
28987ec681f3Smrg         goto invalid_enum;
28997ec681f3Smrg      v->value_matrix = ctx->TextureMatrixStack[index].Top;
29007ec681f3Smrg      return TYPE_MATRIX;
29017ec681f3Smrg   case GL_TRANSPOSE_TEXTURE_MATRIX:
29027ec681f3Smrg      if (index >= ARRAY_SIZE(ctx->TextureMatrixStack))
29037ec681f3Smrg         goto invalid_enum;
29047ec681f3Smrg      v->value_matrix = ctx->TextureMatrixStack[index].Top;
29057ec681f3Smrg      return TYPE_MATRIX_T;
29067ec681f3Smrg   /* GL_NV_viewport_swizzle */
29077ec681f3Smrg   case GL_VIEWPORT_SWIZZLE_X_NV:
29087ec681f3Smrg      if (!ctx->Extensions.NV_viewport_swizzle)
29097ec681f3Smrg         goto invalid_enum;
29107ec681f3Smrg      if (index >= ctx->Const.MaxViewports)
29117ec681f3Smrg         goto invalid_value;
29127ec681f3Smrg      v->value_int = ctx->ViewportArray[index].SwizzleX;
29137ec681f3Smrg      return TYPE_INT;
29147ec681f3Smrg   case GL_VIEWPORT_SWIZZLE_Y_NV:
29157ec681f3Smrg      if (!ctx->Extensions.NV_viewport_swizzle)
29167ec681f3Smrg         goto invalid_enum;
29177ec681f3Smrg      if (index >= ctx->Const.MaxViewports)
29187ec681f3Smrg         goto invalid_value;
29197ec681f3Smrg      v->value_int = ctx->ViewportArray[index].SwizzleY;
29207ec681f3Smrg      return TYPE_INT;
29217ec681f3Smrg   case GL_VIEWPORT_SWIZZLE_Z_NV:
29227ec681f3Smrg      if (!ctx->Extensions.NV_viewport_swizzle)
29237ec681f3Smrg         goto invalid_enum;
29247ec681f3Smrg      if (index >= ctx->Const.MaxViewports)
29257ec681f3Smrg         goto invalid_value;
29267ec681f3Smrg      v->value_int = ctx->ViewportArray[index].SwizzleZ;
29277ec681f3Smrg      return TYPE_INT;
29287ec681f3Smrg   case GL_VIEWPORT_SWIZZLE_W_NV:
29297ec681f3Smrg      if (!ctx->Extensions.NV_viewport_swizzle)
29307ec681f3Smrg         goto invalid_enum;
29317ec681f3Smrg      if (index >= ctx->Const.MaxViewports)
29327ec681f3Smrg         goto invalid_value;
29337ec681f3Smrg      v->value_int = ctx->ViewportArray[index].SwizzleW;
29347ec681f3Smrg      return TYPE_INT;
29353464ebd5Sriastradh   }
29363464ebd5Sriastradh
29373464ebd5Sriastradh invalid_enum:
29383464ebd5Sriastradh   _mesa_error(ctx, GL_INVALID_ENUM, "%s(pname=%s)", func,
293901e04c3fSmrg               _mesa_enum_to_string(pname));
29403464ebd5Sriastradh   return TYPE_INVALID;
29413464ebd5Sriastradh invalid_value:
29423464ebd5Sriastradh   _mesa_error(ctx, GL_INVALID_VALUE, "%s(pname=%s)", func,
294301e04c3fSmrg               _mesa_enum_to_string(pname));
29443464ebd5Sriastradh   return TYPE_INVALID;
29453464ebd5Sriastradh}
29463464ebd5Sriastradh
29473464ebd5Sriastradhvoid GLAPIENTRY
2948af69d88dSmrg_mesa_GetBooleani_v( GLenum pname, GLuint index, GLboolean *params )
29493464ebd5Sriastradh{
29503464ebd5Sriastradh   union value v;
29513464ebd5Sriastradh   enum value_type type =
2952af69d88dSmrg      find_value_indexed("glGetBooleani_v", pname, index, &v);
29533464ebd5Sriastradh
29543464ebd5Sriastradh   switch (type) {
29553464ebd5Sriastradh   case TYPE_INT:
295601e04c3fSmrg   case TYPE_UINT:
29573464ebd5Sriastradh      params[0] = INT_TO_BOOLEAN(v.value_int);
29583464ebd5Sriastradh      break;
29593464ebd5Sriastradh   case TYPE_INT_4:
296001e04c3fSmrg   case TYPE_UINT_4:
29613464ebd5Sriastradh      params[0] = INT_TO_BOOLEAN(v.value_int_4[0]);
29623464ebd5Sriastradh      params[1] = INT_TO_BOOLEAN(v.value_int_4[1]);
29633464ebd5Sriastradh      params[2] = INT_TO_BOOLEAN(v.value_int_4[2]);
29643464ebd5Sriastradh      params[3] = INT_TO_BOOLEAN(v.value_int_4[3]);
29653464ebd5Sriastradh      break;
29663464ebd5Sriastradh   case TYPE_INT64:
2967af69d88dSmrg      params[0] = INT64_TO_BOOLEAN(v.value_int64);
29683464ebd5Sriastradh      break;
29693464ebd5Sriastradh   default:
29703464ebd5Sriastradh      ; /* nothing - GL error was recorded */
29713464ebd5Sriastradh   }
29723464ebd5Sriastradh}
29733464ebd5Sriastradh
29743464ebd5Sriastradhvoid GLAPIENTRY
2975af69d88dSmrg_mesa_GetIntegeri_v( GLenum pname, GLuint index, GLint *params )
29763464ebd5Sriastradh{
29773464ebd5Sriastradh   union value v;
29783464ebd5Sriastradh   enum value_type type =
2979af69d88dSmrg      find_value_indexed("glGetIntegeri_v", pname, index, &v);
29803464ebd5Sriastradh
29813464ebd5Sriastradh   switch (type) {
2982af69d88dSmrg   case TYPE_FLOAT_4:
2983af69d88dSmrg   case TYPE_FLOATN_4:
29847ec681f3Smrg      params[3] = lroundf(v.value_float_4[3]);
29857ec681f3Smrg      FALLTHROUGH;
2986af69d88dSmrg   case TYPE_FLOAT_3:
2987af69d88dSmrg   case TYPE_FLOATN_3:
29887ec681f3Smrg      params[2] = lroundf(v.value_float_4[2]);
29897ec681f3Smrg      FALLTHROUGH;
2990af69d88dSmrg   case TYPE_FLOAT_2:
2991af69d88dSmrg   case TYPE_FLOATN_2:
29927ec681f3Smrg      params[1] = lroundf(v.value_float_4[1]);
29937ec681f3Smrg      FALLTHROUGH;
2994af69d88dSmrg   case TYPE_FLOAT:
2995af69d88dSmrg   case TYPE_FLOATN:
29967ec681f3Smrg      params[0] = lroundf(v.value_float_4[0]);
2997af69d88dSmrg      break;
2998af69d88dSmrg
2999af69d88dSmrg   case TYPE_DOUBLEN_2:
30007ec681f3Smrg      params[1] = lroundf(v.value_double_2[1]);
30017ec681f3Smrg      FALLTHROUGH;
3002af69d88dSmrg   case TYPE_DOUBLEN:
30037ec681f3Smrg      params[0] = lroundf(v.value_double_2[0]);
3004af69d88dSmrg      break;
3005af69d88dSmrg
30063464ebd5Sriastradh   case TYPE_INT:
300701e04c3fSmrg   case TYPE_UINT:
30083464ebd5Sriastradh      params[0] = v.value_int;
30093464ebd5Sriastradh      break;
30103464ebd5Sriastradh   case TYPE_INT_4:
301101e04c3fSmrg   case TYPE_UINT_4:
30123464ebd5Sriastradh      params[0] = v.value_int_4[0];
30133464ebd5Sriastradh      params[1] = v.value_int_4[1];
30143464ebd5Sriastradh      params[2] = v.value_int_4[2];
30153464ebd5Sriastradh      params[3] = v.value_int_4[3];
30163464ebd5Sriastradh      break;
30173464ebd5Sriastradh   case TYPE_INT64:
3018af69d88dSmrg      params[0] = INT64_TO_INT(v.value_int64);
30193464ebd5Sriastradh      break;
30203464ebd5Sriastradh   default:
30213464ebd5Sriastradh      ; /* nothing - GL error was recorded */
30223464ebd5Sriastradh   }
30233464ebd5Sriastradh}
30243464ebd5Sriastradh
30253464ebd5Sriastradhvoid GLAPIENTRY
3026af69d88dSmrg_mesa_GetInteger64i_v( GLenum pname, GLuint index, GLint64 *params )
30273464ebd5Sriastradh{
30283464ebd5Sriastradh   union value v;
30293464ebd5Sriastradh   enum value_type type =
3030af69d88dSmrg      find_value_indexed("glGetInteger64i_v", pname, index, &v);
30313464ebd5Sriastradh
30323464ebd5Sriastradh   switch (type) {
30333464ebd5Sriastradh   case TYPE_INT:
30343464ebd5Sriastradh      params[0] = v.value_int;
30353464ebd5Sriastradh      break;
30363464ebd5Sriastradh   case TYPE_INT_4:
30373464ebd5Sriastradh      params[0] = v.value_int_4[0];
30383464ebd5Sriastradh      params[1] = v.value_int_4[1];
30393464ebd5Sriastradh      params[2] = v.value_int_4[2];
30403464ebd5Sriastradh      params[3] = v.value_int_4[3];
30413464ebd5Sriastradh      break;
304201e04c3fSmrg   case TYPE_UINT:
304301e04c3fSmrg      params[0] = (GLuint) v.value_int;
304401e04c3fSmrg      break;
304501e04c3fSmrg   case TYPE_UINT_4:
304601e04c3fSmrg      params[0] = (GLuint) v.value_int_4[0];
304701e04c3fSmrg      params[1] = (GLuint) v.value_int_4[1];
304801e04c3fSmrg      params[2] = (GLuint) v.value_int_4[2];
304901e04c3fSmrg      params[3] = (GLuint) v.value_int_4[3];
305001e04c3fSmrg      break;
30513464ebd5Sriastradh   case TYPE_INT64:
3052af69d88dSmrg      params[0] = v.value_int64;
30533464ebd5Sriastradh      break;
30543464ebd5Sriastradh   default:
30553464ebd5Sriastradh      ; /* nothing - GL error was recorded */
3056cdc920a0Smrg   }
3057cdc920a0Smrg}
3058cdc920a0Smrg
3059af69d88dSmrgvoid GLAPIENTRY
3060af69d88dSmrg_mesa_GetFloati_v(GLenum pname, GLuint index, GLfloat *params)
3061af69d88dSmrg{
3062af69d88dSmrg   int i;
3063af69d88dSmrg   GLmatrix *m;
3064af69d88dSmrg   union value v;
3065af69d88dSmrg   enum value_type type =
3066af69d88dSmrg      find_value_indexed("glGetFloati_v", pname, index, &v);
3067af69d88dSmrg
3068af69d88dSmrg   switch (type) {
3069af69d88dSmrg   case TYPE_FLOAT_4:
3070af69d88dSmrg   case TYPE_FLOATN_4:
3071af69d88dSmrg      params[3] = v.value_float_4[3];
30727ec681f3Smrg      FALLTHROUGH;
3073af69d88dSmrg   case TYPE_FLOAT_3:
3074af69d88dSmrg   case TYPE_FLOATN_3:
3075af69d88dSmrg      params[2] = v.value_float_4[2];
30767ec681f3Smrg      FALLTHROUGH;
3077af69d88dSmrg   case TYPE_FLOAT_2:
3078af69d88dSmrg   case TYPE_FLOATN_2:
3079af69d88dSmrg      params[1] = v.value_float_4[1];
30807ec681f3Smrg      FALLTHROUGH;
3081af69d88dSmrg   case TYPE_FLOAT:
3082af69d88dSmrg   case TYPE_FLOATN:
3083af69d88dSmrg      params[0] = v.value_float_4[0];
3084af69d88dSmrg      break;
3085af69d88dSmrg
3086af69d88dSmrg   case TYPE_DOUBLEN_2:
3087af69d88dSmrg      params[1] = (GLfloat) v.value_double_2[1];
30887ec681f3Smrg      FALLTHROUGH;
3089af69d88dSmrg   case TYPE_DOUBLEN:
3090af69d88dSmrg      params[0] = (GLfloat) v.value_double_2[0];
3091af69d88dSmrg      break;
3092af69d88dSmrg
3093af69d88dSmrg   case TYPE_INT_4:
3094af69d88dSmrg      params[3] = (GLfloat) v.value_int_4[3];
30957ec681f3Smrg      FALLTHROUGH;
3096af69d88dSmrg   case TYPE_INT_3:
3097af69d88dSmrg      params[2] = (GLfloat) v.value_int_4[2];
30987ec681f3Smrg      FALLTHROUGH;
3099af69d88dSmrg   case TYPE_INT_2:
3100af69d88dSmrg   case TYPE_ENUM_2:
3101af69d88dSmrg      params[1] = (GLfloat) v.value_int_4[1];
31027ec681f3Smrg      FALLTHROUGH;
3103af69d88dSmrg   case TYPE_INT:
3104af69d88dSmrg   case TYPE_ENUM:
310501e04c3fSmrg   case TYPE_ENUM16:
3106af69d88dSmrg      params[0] = (GLfloat) v.value_int_4[0];
3107af69d88dSmrg      break;
3108af69d88dSmrg
3109af69d88dSmrg   case TYPE_INT_N:
3110af69d88dSmrg      for (i = 0; i < v.value_int_n.n; i++)
311101e04c3fSmrg         params[i] = (GLfloat) v.value_int_n.ints[i];
311201e04c3fSmrg      break;
311301e04c3fSmrg
311401e04c3fSmrg   case TYPE_UINT_4:
311501e04c3fSmrg      params[3] = (GLfloat) ((GLuint) v.value_int_4[3]);
31167ec681f3Smrg      FALLTHROUGH;
311701e04c3fSmrg   case TYPE_UINT_3:
311801e04c3fSmrg      params[2] = (GLfloat) ((GLuint) v.value_int_4[2]);
31197ec681f3Smrg      FALLTHROUGH;
312001e04c3fSmrg   case TYPE_UINT_2:
312101e04c3fSmrg      params[1] = (GLfloat) ((GLuint) v.value_int_4[1]);
31227ec681f3Smrg      FALLTHROUGH;
312301e04c3fSmrg   case TYPE_UINT:
312401e04c3fSmrg      params[0] = (GLfloat) ((GLuint) v.value_int_4[0]);
3125af69d88dSmrg      break;
3126af69d88dSmrg
3127af69d88dSmrg   case TYPE_INT64:
3128af69d88dSmrg      params[0] = (GLfloat) v.value_int64;
3129af69d88dSmrg      break;
3130af69d88dSmrg
3131af69d88dSmrg   case TYPE_BOOLEAN:
3132af69d88dSmrg      params[0] = BOOLEAN_TO_FLOAT(v.value_bool);
3133af69d88dSmrg      break;
3134af69d88dSmrg
313501e04c3fSmrg   case TYPE_UBYTE:
313601e04c3fSmrg      params[0] = (GLfloat) v.value_ubyte;
313701e04c3fSmrg      break;
313801e04c3fSmrg
313901e04c3fSmrg   case TYPE_SHORT:
314001e04c3fSmrg      params[0] = (GLfloat) v.value_short;
314101e04c3fSmrg      break;
314201e04c3fSmrg
3143af69d88dSmrg   case TYPE_MATRIX:
3144af69d88dSmrg      m = *(GLmatrix **) &v;
3145af69d88dSmrg      for (i = 0; i < 16; i++)
314601e04c3fSmrg         params[i] = m->m[i];
3147af69d88dSmrg      break;
3148af69d88dSmrg
3149af69d88dSmrg   case TYPE_MATRIX_T:
3150af69d88dSmrg      m = *(GLmatrix **) &v;
3151af69d88dSmrg      for (i = 0; i < 16; i++)
315201e04c3fSmrg         params[i] = m->m[transpose[i]];
3153af69d88dSmrg      break;
3154af69d88dSmrg
3155af69d88dSmrg   default:
3156af69d88dSmrg      ;
3157af69d88dSmrg   }
3158af69d88dSmrg}
3159af69d88dSmrg
3160af69d88dSmrgvoid GLAPIENTRY
3161af69d88dSmrg_mesa_GetDoublei_v(GLenum pname, GLuint index, GLdouble *params)
3162af69d88dSmrg{
3163af69d88dSmrg   int i;
3164af69d88dSmrg   GLmatrix *m;
3165af69d88dSmrg   union value v;
3166af69d88dSmrg   enum value_type type =
3167af69d88dSmrg      find_value_indexed("glGetDoublei_v", pname, index, &v);
3168af69d88dSmrg
3169af69d88dSmrg   switch (type) {
3170af69d88dSmrg   case TYPE_FLOAT_4:
3171af69d88dSmrg   case TYPE_FLOATN_4:
3172af69d88dSmrg      params[3] = (GLdouble) v.value_float_4[3];
31737ec681f3Smrg      FALLTHROUGH;
3174af69d88dSmrg   case TYPE_FLOAT_3:
3175af69d88dSmrg   case TYPE_FLOATN_3:
3176af69d88dSmrg      params[2] = (GLdouble) v.value_float_4[2];
31777ec681f3Smrg      FALLTHROUGH;
3178af69d88dSmrg   case TYPE_FLOAT_2:
3179af69d88dSmrg   case TYPE_FLOATN_2:
3180af69d88dSmrg      params[1] = (GLdouble) v.value_float_4[1];
31817ec681f3Smrg      FALLTHROUGH;
3182af69d88dSmrg   case TYPE_FLOAT:
3183af69d88dSmrg   case TYPE_FLOATN:
3184af69d88dSmrg      params[0] = (GLdouble) v.value_float_4[0];
3185af69d88dSmrg      break;
3186af69d88dSmrg
3187af69d88dSmrg   case TYPE_DOUBLEN_2:
3188af69d88dSmrg      params[1] = v.value_double_2[1];
31897ec681f3Smrg      FALLTHROUGH;
3190af69d88dSmrg   case TYPE_DOUBLEN:
3191af69d88dSmrg      params[0] = v.value_double_2[0];
3192af69d88dSmrg      break;
3193af69d88dSmrg
3194af69d88dSmrg   case TYPE_INT_4:
3195af69d88dSmrg      params[3] = (GLdouble) v.value_int_4[3];
31967ec681f3Smrg      FALLTHROUGH;
3197af69d88dSmrg   case TYPE_INT_3:
3198af69d88dSmrg      params[2] = (GLdouble) v.value_int_4[2];
31997ec681f3Smrg      FALLTHROUGH;
3200af69d88dSmrg   case TYPE_INT_2:
3201af69d88dSmrg   case TYPE_ENUM_2:
3202af69d88dSmrg      params[1] = (GLdouble) v.value_int_4[1];
32037ec681f3Smrg      FALLTHROUGH;
3204af69d88dSmrg   case TYPE_INT:
3205af69d88dSmrg   case TYPE_ENUM:
320601e04c3fSmrg   case TYPE_ENUM16:
3207af69d88dSmrg      params[0] = (GLdouble) v.value_int_4[0];
3208af69d88dSmrg      break;
3209af69d88dSmrg
3210af69d88dSmrg   case TYPE_INT_N:
3211af69d88dSmrg      for (i = 0; i < v.value_int_n.n; i++)
321201e04c3fSmrg         params[i] = (GLdouble) v.value_int_n.ints[i];
321301e04c3fSmrg      break;
321401e04c3fSmrg
321501e04c3fSmrg   case TYPE_UINT_4:
321601e04c3fSmrg      params[3] = (GLdouble) ((GLuint) v.value_int_4[3]);
32177ec681f3Smrg      FALLTHROUGH;
321801e04c3fSmrg   case TYPE_UINT_3:
321901e04c3fSmrg      params[2] = (GLdouble) ((GLuint) v.value_int_4[2]);
32207ec681f3Smrg      FALLTHROUGH;
322101e04c3fSmrg   case TYPE_UINT_2:
322201e04c3fSmrg      params[1] = (GLdouble) ((GLuint) v.value_int_4[1]);
32237ec681f3Smrg      FALLTHROUGH;
322401e04c3fSmrg   case TYPE_UINT:
322501e04c3fSmrg      params[0] = (GLdouble) ((GLuint) v.value_int_4[0]);
3226af69d88dSmrg      break;
3227af69d88dSmrg
3228af69d88dSmrg   case TYPE_INT64:
3229af69d88dSmrg      params[0] = (GLdouble) v.value_int64;
3230af69d88dSmrg      break;
3231af69d88dSmrg
3232af69d88dSmrg   case TYPE_BOOLEAN:
3233af69d88dSmrg      params[0] = (GLdouble) BOOLEAN_TO_FLOAT(v.value_bool);
3234af69d88dSmrg      break;
3235af69d88dSmrg
323601e04c3fSmrg   case TYPE_UBYTE:
323701e04c3fSmrg      params[0] = (GLdouble) v.value_ubyte;
323801e04c3fSmrg      break;
323901e04c3fSmrg
324001e04c3fSmrg   case TYPE_SHORT:
324101e04c3fSmrg      params[0] = (GLdouble) v.value_short;
324201e04c3fSmrg      break;
324301e04c3fSmrg
3244af69d88dSmrg   case TYPE_MATRIX:
3245af69d88dSmrg      m = *(GLmatrix **) &v;
3246af69d88dSmrg      for (i = 0; i < 16; i++)
324701e04c3fSmrg         params[i] = (GLdouble) m->m[i];
3248af69d88dSmrg      break;
3249af69d88dSmrg
3250af69d88dSmrg   case TYPE_MATRIX_T:
3251af69d88dSmrg      m = *(GLmatrix **) &v;
3252af69d88dSmrg      for (i = 0; i < 16; i++)
325301e04c3fSmrg         params[i] = (GLdouble) m->m[transpose[i]];
3254af69d88dSmrg      break;
3255af69d88dSmrg
3256af69d88dSmrg   default:
3257af69d88dSmrg      ;
3258af69d88dSmrg   }
3259af69d88dSmrg}
3260af69d88dSmrg
326101e04c3fSmrgvoid GLAPIENTRY
326201e04c3fSmrg_mesa_GetUnsignedBytei_vEXT(GLenum target, GLuint index, GLubyte *data)
326301e04c3fSmrg{
326401e04c3fSmrg   GLsizei size;
326501e04c3fSmrg   union value v;
326601e04c3fSmrg   enum value_type type;
326701e04c3fSmrg   const char *func = "glGetUnsignedBytei_vEXT";
326801e04c3fSmrg
326901e04c3fSmrg   GET_CURRENT_CONTEXT(ctx);
327001e04c3fSmrg
327101e04c3fSmrg   if (!ctx->Extensions.EXT_memory_object) {
327201e04c3fSmrg      _mesa_error(ctx, GL_INVALID_OPERATION, "%s(unsupported)", func);
327301e04c3fSmrg      return;
327401e04c3fSmrg   }
327501e04c3fSmrg
327601e04c3fSmrg   type = find_value_indexed(func, target, index, &v);
327701e04c3fSmrg   size = get_value_size(type, &v);
327801e04c3fSmrg
327901e04c3fSmrg   switch (type) {
328001e04c3fSmrg   case TYPE_UINT:
328101e04c3fSmrg   case TYPE_INT:
328201e04c3fSmrg   case TYPE_INT_2:
328301e04c3fSmrg   case TYPE_UINT_2:
328401e04c3fSmrg   case TYPE_INT_3:
328501e04c3fSmrg   case TYPE_UINT_3:
328601e04c3fSmrg   case TYPE_INT_4:
328701e04c3fSmrg   case TYPE_UINT_4:
328801e04c3fSmrg   case TYPE_INT64:
328901e04c3fSmrg   case TYPE_ENUM16:
329001e04c3fSmrg   case TYPE_ENUM:
329101e04c3fSmrg   case TYPE_ENUM_2:
329201e04c3fSmrg   case TYPE_BOOLEAN:
329301e04c3fSmrg   case TYPE_UBYTE:
329401e04c3fSmrg   case TYPE_SHORT:
329501e04c3fSmrg   case TYPE_FLOAT:
329601e04c3fSmrg   case TYPE_FLOATN:
329701e04c3fSmrg   case TYPE_FLOAT_2:
329801e04c3fSmrg   case TYPE_FLOATN_2:
329901e04c3fSmrg   case TYPE_FLOAT_3:
330001e04c3fSmrg   case TYPE_FLOATN_3:
330101e04c3fSmrg   case TYPE_FLOAT_4:
330201e04c3fSmrg   case TYPE_FLOATN_4:
330301e04c3fSmrg   case TYPE_FLOAT_8:
330401e04c3fSmrg   case TYPE_DOUBLEN:
330501e04c3fSmrg   case TYPE_DOUBLEN_2:
330601e04c3fSmrg   case TYPE_MATRIX:
330701e04c3fSmrg   case TYPE_MATRIX_T:
330801e04c3fSmrg      memcpy(data, &v.value_int, size);
330901e04c3fSmrg      break;
331001e04c3fSmrg   case TYPE_INT_N:
331101e04c3fSmrg      memcpy(data, &v.value_int_n.ints, size);
331201e04c3fSmrg      break;
331301e04c3fSmrg   default:
331401e04c3fSmrg      break; /* nothing - GL error was recorded */
331501e04c3fSmrg   }
331601e04c3fSmrg}
331701e04c3fSmrg
33183464ebd5Sriastradhvoid GLAPIENTRY
33193464ebd5Sriastradh_mesa_GetFixedv(GLenum pname, GLfixed *params)
33203464ebd5Sriastradh{
33213464ebd5Sriastradh   const struct value_desc *d;
33223464ebd5Sriastradh   union value v;
33233464ebd5Sriastradh   GLmatrix *m;
33243464ebd5Sriastradh   int shift, i;
33253464ebd5Sriastradh   void *p;
33263464ebd5Sriastradh
33273464ebd5Sriastradh   d = find_value("glGetDoublev", pname, &p, &v);
33283464ebd5Sriastradh   switch (d->type) {
33293464ebd5Sriastradh   case TYPE_INVALID:
33303464ebd5Sriastradh      break;
33313464ebd5Sriastradh   case TYPE_CONST:
33323464ebd5Sriastradh      params[0] = INT_TO_FIXED(d->offset);
33333464ebd5Sriastradh      break;
33343464ebd5Sriastradh
33353464ebd5Sriastradh   case TYPE_FLOAT_4:
33363464ebd5Sriastradh   case TYPE_FLOATN_4:
33373464ebd5Sriastradh      params[3] = FLOAT_TO_FIXED(((GLfloat *) p)[3]);
33387ec681f3Smrg      FALLTHROUGH;
33393464ebd5Sriastradh   case TYPE_FLOAT_3:
33403464ebd5Sriastradh   case TYPE_FLOATN_3:
33413464ebd5Sriastradh      params[2] = FLOAT_TO_FIXED(((GLfloat *) p)[2]);
33427ec681f3Smrg      FALLTHROUGH;
33433464ebd5Sriastradh   case TYPE_FLOAT_2:
33443464ebd5Sriastradh   case TYPE_FLOATN_2:
33453464ebd5Sriastradh      params[1] = FLOAT_TO_FIXED(((GLfloat *) p)[1]);
33467ec681f3Smrg      FALLTHROUGH;
33473464ebd5Sriastradh   case TYPE_FLOAT:
33483464ebd5Sriastradh   case TYPE_FLOATN:
33493464ebd5Sriastradh      params[0] = FLOAT_TO_FIXED(((GLfloat *) p)[0]);
33503464ebd5Sriastradh      break;
33513464ebd5Sriastradh
3352af69d88dSmrg   case TYPE_DOUBLEN_2:
3353af69d88dSmrg      params[1] = FLOAT_TO_FIXED(((GLdouble *) p)[1]);
33547ec681f3Smrg      FALLTHROUGH;
33553464ebd5Sriastradh   case TYPE_DOUBLEN:
33563464ebd5Sriastradh      params[0] = FLOAT_TO_FIXED(((GLdouble *) p)[0]);
33573464ebd5Sriastradh      break;
33583464ebd5Sriastradh
33593464ebd5Sriastradh   case TYPE_INT_4:
336001e04c3fSmrg   case TYPE_UINT_4:
33613464ebd5Sriastradh      params[3] = INT_TO_FIXED(((GLint *) p)[3]);
33627ec681f3Smrg      FALLTHROUGH;
33633464ebd5Sriastradh   case TYPE_INT_3:
336401e04c3fSmrg   case TYPE_UINT_3:
33653464ebd5Sriastradh      params[2] = INT_TO_FIXED(((GLint *) p)[2]);
33667ec681f3Smrg      FALLTHROUGH;
33673464ebd5Sriastradh   case TYPE_INT_2:
336801e04c3fSmrg   case TYPE_UINT_2:
33693464ebd5Sriastradh   case TYPE_ENUM_2:
33703464ebd5Sriastradh      params[1] = INT_TO_FIXED(((GLint *) p)[1]);
33717ec681f3Smrg      FALLTHROUGH;
33723464ebd5Sriastradh   case TYPE_INT:
337301e04c3fSmrg   case TYPE_UINT:
33743464ebd5Sriastradh   case TYPE_ENUM:
33753464ebd5Sriastradh      params[0] = INT_TO_FIXED(((GLint *) p)[0]);
33763464ebd5Sriastradh      break;
33773464ebd5Sriastradh
337801e04c3fSmrg   case TYPE_ENUM16:
337901e04c3fSmrg      params[0] = INT_TO_FIXED((GLint)(((GLenum16 *) p)[0]));
338001e04c3fSmrg      break;
338101e04c3fSmrg
33823464ebd5Sriastradh   case TYPE_INT_N:
33833464ebd5Sriastradh      for (i = 0; i < v.value_int_n.n; i++)
338401e04c3fSmrg         params[i] = INT_TO_FIXED(v.value_int_n.ints[i]);
33853464ebd5Sriastradh      break;
33863464ebd5Sriastradh
33873464ebd5Sriastradh   case TYPE_INT64:
33883464ebd5Sriastradh      params[0] = ((GLint64 *) p)[0];
33893464ebd5Sriastradh      break;
33903464ebd5Sriastradh
33913464ebd5Sriastradh   case TYPE_BOOLEAN:
33923464ebd5Sriastradh      params[0] = BOOLEAN_TO_FIXED(((GLboolean*) p)[0]);
339301e04c3fSmrg      break;
339401e04c3fSmrg
339501e04c3fSmrg   case TYPE_UBYTE:
339601e04c3fSmrg      params[0] = INT_TO_FIXED(((GLubyte *) p)[0]);
339701e04c3fSmrg      break;
339801e04c3fSmrg
339901e04c3fSmrg   case TYPE_SHORT:
340001e04c3fSmrg      params[0] = INT_TO_FIXED(((GLshort *) p)[0]);
340101e04c3fSmrg      break;
34023464ebd5Sriastradh
34033464ebd5Sriastradh   case TYPE_MATRIX:
34043464ebd5Sriastradh      m = *(GLmatrix **) p;
34053464ebd5Sriastradh      for (i = 0; i < 16; i++)
340601e04c3fSmrg         params[i] = FLOAT_TO_FIXED(m->m[i]);
34073464ebd5Sriastradh      break;
34083464ebd5Sriastradh
34093464ebd5Sriastradh   case TYPE_MATRIX_T:
34103464ebd5Sriastradh      m = *(GLmatrix **) p;
34113464ebd5Sriastradh      for (i = 0; i < 16; i++)
341201e04c3fSmrg         params[i] = FLOAT_TO_FIXED(m->m[transpose[i]]);
34133464ebd5Sriastradh      break;
34143464ebd5Sriastradh
34153464ebd5Sriastradh   case TYPE_BIT_0:
34163464ebd5Sriastradh   case TYPE_BIT_1:
34173464ebd5Sriastradh   case TYPE_BIT_2:
34183464ebd5Sriastradh   case TYPE_BIT_3:
34193464ebd5Sriastradh   case TYPE_BIT_4:
34203464ebd5Sriastradh   case TYPE_BIT_5:
3421af69d88dSmrg   case TYPE_BIT_6:
3422af69d88dSmrg   case TYPE_BIT_7:
34233464ebd5Sriastradh      shift = d->type - TYPE_BIT_0;
34243464ebd5Sriastradh      params[0] = BOOLEAN_TO_FIXED((*(GLbitfield *) p >> shift) & 1);
34253464ebd5Sriastradh      break;
34263464ebd5Sriastradh   }
34273464ebd5Sriastradh}
3428