get.c revision 01e04c3f
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"
377117f1b4Smrg#include "state.h"
387117f1b4Smrg#include "texcompress.h"
3901e04c3fSmrg#include "texstate.h"
404a49301eSmrg#include "framebuffer.h"
41af69d88dSmrg#include "samplerobj.h"
42af69d88dSmrg#include "stencil.h"
4301e04c3fSmrg#include "version.h"
447117f1b4Smrg
453464ebd5Sriastradh/* This is a table driven implemetation of the glGet*v() functions.
463464ebd5Sriastradh * The basic idea is that most getters just look up an int somewhere
473464ebd5Sriastradh * in struct gl_context and then convert it to a bool or float according to
483464ebd5Sriastradh * which of glGetIntegerv() glGetBooleanv() etc is being called.
493464ebd5Sriastradh * Instead of generating code to do this, we can just record the enum
503464ebd5Sriastradh * value and the offset into struct gl_context in an array of structs.  Then
513464ebd5Sriastradh * in glGet*(), we lookup the struct for the enum in question, and use
523464ebd5Sriastradh * the offset to get the int we need.
533464ebd5Sriastradh *
543464ebd5Sriastradh * Sometimes we need to look up a float, a boolean, a bit in a
553464ebd5Sriastradh * bitfield, a matrix or other types instead, so we need to track the
563464ebd5Sriastradh * type of the value in struct gl_context.  And sometimes the value isn't in
573464ebd5Sriastradh * struct gl_context but in the drawbuffer, the array object, current texture
583464ebd5Sriastradh * unit, or maybe it's a computed value.  So we need to also track
593464ebd5Sriastradh * where or how to find the value.  Finally, we sometimes need to
603464ebd5Sriastradh * check that one of a number of extensions are enabled, the GL
613464ebd5Sriastradh * version or flush or call _mesa_update_state().  This is done by
623464ebd5Sriastradh * attaching optional extra information to the value description
633464ebd5Sriastradh * struct, it's sort of like an array of opcodes that describe extra
643464ebd5Sriastradh * checks or actions.
653464ebd5Sriastradh *
663464ebd5Sriastradh * Putting all this together we end up with struct value_desc below,
673464ebd5Sriastradh * and with a couple of macros to help, the table of struct value_desc
683464ebd5Sriastradh * is about as concise as the specification in the old python script.
693464ebd5Sriastradh */
703464ebd5Sriastradh
717117f1b4Smrg#define FLOAT_TO_BOOLEAN(X)   ( (X) ? GL_TRUE : GL_FALSE )
723464ebd5Sriastradh#define FLOAT_TO_FIXED(F)     ( ((F) * 65536.0f > INT_MAX) ? INT_MAX : \
733464ebd5Sriastradh                                ((F) * 65536.0f < INT_MIN) ? INT_MIN : \
743464ebd5Sriastradh                                (GLint) ((F) * 65536.0f) )
757117f1b4Smrg
767117f1b4Smrg#define INT_TO_BOOLEAN(I)     ( (I) ? GL_TRUE : GL_FALSE )
773464ebd5Sriastradh#define INT_TO_FIXED(I)       ( ((I) > SHRT_MAX) ? INT_MAX : \
783464ebd5Sriastradh                                ((I) < SHRT_MIN) ? INT_MIN : \
793464ebd5Sriastradh                                (GLint) ((I) * 65536) )
807117f1b4Smrg
814a49301eSmrg#define INT64_TO_BOOLEAN(I)   ( (I) ? GL_TRUE : GL_FALSE )
824a49301eSmrg#define INT64_TO_INT(I)       ( (GLint)((I > INT_MAX) ? INT_MAX : ((I < INT_MIN) ? INT_MIN : (I))) )
834a49301eSmrg
847117f1b4Smrg#define BOOLEAN_TO_INT(B)     ( (GLint) (B) )
854a49301eSmrg#define BOOLEAN_TO_INT64(B)   ( (GLint64) (B) )
867117f1b4Smrg#define BOOLEAN_TO_FLOAT(B)   ( (B) ? 1.0F : 0.0F )
873464ebd5Sriastradh#define BOOLEAN_TO_FIXED(B)   ( (GLint) ((B) ? 1 : 0) << 16 )
887117f1b4Smrg
894a49301eSmrg#define ENUM_TO_INT64(E)      ( (GLint64) (E) )
903464ebd5Sriastradh#define ENUM_TO_FIXED(E)      (E)
914a49301eSmrg
923464ebd5Sriastradhenum value_type {
933464ebd5Sriastradh   TYPE_INVALID,
943464ebd5Sriastradh   TYPE_INT,
953464ebd5Sriastradh   TYPE_INT_2,
963464ebd5Sriastradh   TYPE_INT_3,
973464ebd5Sriastradh   TYPE_INT_4,
983464ebd5Sriastradh   TYPE_INT_N,
9901e04c3fSmrg   TYPE_UINT,
10001e04c3fSmrg   TYPE_UINT_2,
10101e04c3fSmrg   TYPE_UINT_3,
10201e04c3fSmrg   TYPE_UINT_4,
1033464ebd5Sriastradh   TYPE_INT64,
10401e04c3fSmrg   TYPE_ENUM16,
1053464ebd5Sriastradh   TYPE_ENUM,
1063464ebd5Sriastradh   TYPE_ENUM_2,
1073464ebd5Sriastradh   TYPE_BOOLEAN,
10801e04c3fSmrg   TYPE_UBYTE,
10901e04c3fSmrg   TYPE_SHORT,
1103464ebd5Sriastradh   TYPE_BIT_0,
1113464ebd5Sriastradh   TYPE_BIT_1,
1123464ebd5Sriastradh   TYPE_BIT_2,
1133464ebd5Sriastradh   TYPE_BIT_3,
1143464ebd5Sriastradh   TYPE_BIT_4,
1153464ebd5Sriastradh   TYPE_BIT_5,
116af69d88dSmrg   TYPE_BIT_6,
117af69d88dSmrg   TYPE_BIT_7,
1183464ebd5Sriastradh   TYPE_FLOAT,
1193464ebd5Sriastradh   TYPE_FLOAT_2,
1203464ebd5Sriastradh   TYPE_FLOAT_3,
1213464ebd5Sriastradh   TYPE_FLOAT_4,
12201e04c3fSmrg   TYPE_FLOAT_8,
1233464ebd5Sriastradh   TYPE_FLOATN,
1243464ebd5Sriastradh   TYPE_FLOATN_2,
1253464ebd5Sriastradh   TYPE_FLOATN_3,
1263464ebd5Sriastradh   TYPE_FLOATN_4,
1273464ebd5Sriastradh   TYPE_DOUBLEN,
128af69d88dSmrg   TYPE_DOUBLEN_2,
1293464ebd5Sriastradh   TYPE_MATRIX,
1303464ebd5Sriastradh   TYPE_MATRIX_T,
1313464ebd5Sriastradh   TYPE_CONST
1323464ebd5Sriastradh};
1337117f1b4Smrg
1343464ebd5Sriastradhenum value_location {
1353464ebd5Sriastradh   LOC_BUFFER,
1363464ebd5Sriastradh   LOC_CONTEXT,
1373464ebd5Sriastradh   LOC_ARRAY,
1383464ebd5Sriastradh   LOC_TEXUNIT,
1393464ebd5Sriastradh   LOC_CUSTOM
1403464ebd5Sriastradh};
1413464ebd5Sriastradh
1423464ebd5Sriastradhenum value_extra {
1433464ebd5Sriastradh   EXTRA_END = 0x8000,
1443464ebd5Sriastradh   EXTRA_VERSION_30,
1453464ebd5Sriastradh   EXTRA_VERSION_31,
1463464ebd5Sriastradh   EXTRA_VERSION_32,
147af69d88dSmrg   EXTRA_VERSION_40,
14801e04c3fSmrg   EXTRA_VERSION_43,
149af69d88dSmrg   EXTRA_API_GL,
150af69d88dSmrg   EXTRA_API_GL_CORE,
151af69d88dSmrg   EXTRA_API_ES2,
152af69d88dSmrg   EXTRA_API_ES3,
15301e04c3fSmrg   EXTRA_API_ES31,
15401e04c3fSmrg   EXTRA_API_ES32,
15501e04c3fSmrg   EXTRA_NEW_BUFFERS,
1563464ebd5Sriastradh   EXTRA_NEW_FRAG_CLAMP,
1573464ebd5Sriastradh   EXTRA_VALID_DRAW_BUFFER,
1583464ebd5Sriastradh   EXTRA_VALID_TEXTURE_UNIT,
159af69d88dSmrg   EXTRA_VALID_CLIP_DISTANCE,
1603464ebd5Sriastradh   EXTRA_FLUSH_CURRENT,
161af69d88dSmrg   EXTRA_GLSL_130,
16201e04c3fSmrg   EXTRA_EXT_UBO_GS,
16301e04c3fSmrg   EXTRA_EXT_ATOMICS_GS,
16401e04c3fSmrg   EXTRA_EXT_SHADER_IMAGE_GS,
16501e04c3fSmrg   EXTRA_EXT_ATOMICS_TESS,
16601e04c3fSmrg   EXTRA_EXT_SHADER_IMAGE_TESS,
16701e04c3fSmrg   EXTRA_EXT_SSBO_GS,
16801e04c3fSmrg   EXTRA_EXT_FB_NO_ATTACH_GS,
16901e04c3fSmrg   EXTRA_EXT_ES_GS,
17001e04c3fSmrg   EXTRA_EXT_PROVOKING_VERTEX_32,
1713464ebd5Sriastradh};
1723464ebd5Sriastradh
1733464ebd5Sriastradh#define NO_EXTRA NULL
1743464ebd5Sriastradh#define NO_OFFSET 0
1753464ebd5Sriastradh
1763464ebd5Sriastradhstruct value_desc {
1773464ebd5Sriastradh   GLenum pname;
1783464ebd5Sriastradh   GLubyte location;  /**< enum value_location */
1793464ebd5Sriastradh   GLubyte type;      /**< enum value_type */
1803464ebd5Sriastradh   int offset;
1813464ebd5Sriastradh   const int *extra;
1823464ebd5Sriastradh};
1833464ebd5Sriastradh
1843464ebd5Sriastradhunion value {
1853464ebd5Sriastradh   GLfloat value_float;
1863464ebd5Sriastradh   GLfloat value_float_4[4];
187af69d88dSmrg   GLdouble value_double_2[2];
1883464ebd5Sriastradh   GLmatrix *value_matrix;
1893464ebd5Sriastradh   GLint value_int;
1903464ebd5Sriastradh   GLint value_int_4[4];
1913464ebd5Sriastradh   GLint64 value_int64;
1923464ebd5Sriastradh   GLenum value_enum;
19301e04c3fSmrg   GLubyte value_ubyte;
19401e04c3fSmrg   GLshort value_short;
19501e04c3fSmrg   GLuint value_uint;
1963464ebd5Sriastradh
1973464ebd5Sriastradh   /* Sigh, see GL_COMPRESSED_TEXTURE_FORMATS_ARB handling */
1983464ebd5Sriastradh   struct {
1993464ebd5Sriastradh      GLint n, ints[100];
2003464ebd5Sriastradh   } value_int_n;
2013464ebd5Sriastradh   GLboolean value_bool;
2023464ebd5Sriastradh};
2033464ebd5Sriastradh
2043464ebd5Sriastradh#define BUFFER_FIELD(field, type) \
2053464ebd5Sriastradh   LOC_BUFFER, type, offsetof(struct gl_framebuffer, field)
2063464ebd5Sriastradh#define CONTEXT_FIELD(field, type) \
2073464ebd5Sriastradh   LOC_CONTEXT, type, offsetof(struct gl_context, field)
2083464ebd5Sriastradh#define ARRAY_FIELD(field, type) \
209af69d88dSmrg   LOC_ARRAY, type, offsetof(struct gl_vertex_array_object, field)
210af69d88dSmrg#undef CONST /* already defined through windows.h */
2113464ebd5Sriastradh#define CONST(value) \
2123464ebd5Sriastradh   LOC_CONTEXT, TYPE_CONST, value
2133464ebd5Sriastradh
2143464ebd5Sriastradh#define BUFFER_INT(field) BUFFER_FIELD(field, TYPE_INT)
2153464ebd5Sriastradh#define BUFFER_ENUM(field) BUFFER_FIELD(field, TYPE_ENUM)
21601e04c3fSmrg#define BUFFER_ENUM16(field) BUFFER_FIELD(field, TYPE_ENUM16)
2173464ebd5Sriastradh#define BUFFER_BOOL(field) BUFFER_FIELD(field, TYPE_BOOLEAN)
2183464ebd5Sriastradh
2193464ebd5Sriastradh#define CONTEXT_INT(field) CONTEXT_FIELD(field, TYPE_INT)
2203464ebd5Sriastradh#define CONTEXT_INT2(field) CONTEXT_FIELD(field, TYPE_INT_2)
2213464ebd5Sriastradh#define CONTEXT_INT64(field) CONTEXT_FIELD(field, TYPE_INT64)
22201e04c3fSmrg#define CONTEXT_UINT(field) CONTEXT_FIELD(field, TYPE_UINT)
22301e04c3fSmrg#define CONTEXT_ENUM16(field) CONTEXT_FIELD(field, TYPE_ENUM16)
2243464ebd5Sriastradh#define CONTEXT_ENUM(field) CONTEXT_FIELD(field, TYPE_ENUM)
2253464ebd5Sriastradh#define CONTEXT_ENUM2(field) CONTEXT_FIELD(field, TYPE_ENUM_2)
2263464ebd5Sriastradh#define CONTEXT_BOOL(field) CONTEXT_FIELD(field, TYPE_BOOLEAN)
2273464ebd5Sriastradh#define CONTEXT_BIT0(field) CONTEXT_FIELD(field, TYPE_BIT_0)
2283464ebd5Sriastradh#define CONTEXT_BIT1(field) CONTEXT_FIELD(field, TYPE_BIT_1)
2293464ebd5Sriastradh#define CONTEXT_BIT2(field) CONTEXT_FIELD(field, TYPE_BIT_2)
2303464ebd5Sriastradh#define CONTEXT_BIT3(field) CONTEXT_FIELD(field, TYPE_BIT_3)
2313464ebd5Sriastradh#define CONTEXT_BIT4(field) CONTEXT_FIELD(field, TYPE_BIT_4)
2323464ebd5Sriastradh#define CONTEXT_BIT5(field) CONTEXT_FIELD(field, TYPE_BIT_5)
233af69d88dSmrg#define CONTEXT_BIT6(field) CONTEXT_FIELD(field, TYPE_BIT_6)
234af69d88dSmrg#define CONTEXT_BIT7(field) CONTEXT_FIELD(field, TYPE_BIT_7)
2353464ebd5Sriastradh#define CONTEXT_FLOAT(field) CONTEXT_FIELD(field, TYPE_FLOAT)
2363464ebd5Sriastradh#define CONTEXT_FLOAT2(field) CONTEXT_FIELD(field, TYPE_FLOAT_2)
2373464ebd5Sriastradh#define CONTEXT_FLOAT3(field) CONTEXT_FIELD(field, TYPE_FLOAT_3)
2383464ebd5Sriastradh#define CONTEXT_FLOAT4(field) CONTEXT_FIELD(field, TYPE_FLOAT_4)
23901e04c3fSmrg#define CONTEXT_FLOAT8(field) CONTEXT_FIELD(field, TYPE_FLOAT_8)
2403464ebd5Sriastradh#define CONTEXT_MATRIX(field) CONTEXT_FIELD(field, TYPE_MATRIX)
2413464ebd5Sriastradh#define CONTEXT_MATRIX_T(field) CONTEXT_FIELD(field, TYPE_MATRIX_T)
2423464ebd5Sriastradh
24301e04c3fSmrg/* Vertex array fields */
2443464ebd5Sriastradh#define ARRAY_INT(field) ARRAY_FIELD(field, TYPE_INT)
2453464ebd5Sriastradh#define ARRAY_ENUM(field) ARRAY_FIELD(field, TYPE_ENUM)
24601e04c3fSmrg#define ARRAY_ENUM16(field) ARRAY_FIELD(field, TYPE_ENUM16)
2473464ebd5Sriastradh#define ARRAY_BOOL(field) ARRAY_FIELD(field, TYPE_BOOLEAN)
24801e04c3fSmrg#define ARRAY_UBYTE(field) ARRAY_FIELD(field, TYPE_UBYTE)
24901e04c3fSmrg#define ARRAY_SHORT(field) ARRAY_FIELD(field, TYPE_SHORT)
2503464ebd5Sriastradh
2513464ebd5Sriastradh#define EXT(f)					\
2523464ebd5Sriastradh   offsetof(struct gl_extensions, f)
2533464ebd5Sriastradh
2543464ebd5Sriastradh#define EXTRA_EXT(e)				\
2553464ebd5Sriastradh   static const int extra_##e[] = {		\
2563464ebd5Sriastradh      EXT(e), EXTRA_END				\
2577117f1b4Smrg   }
2587117f1b4Smrg
2593464ebd5Sriastradh#define EXTRA_EXT2(e1, e2)			\
2603464ebd5Sriastradh   static const int extra_##e1##_##e2[] = {	\
2613464ebd5Sriastradh      EXT(e1), EXT(e2), EXTRA_END		\
2623464ebd5Sriastradh   }
2633464ebd5Sriastradh
2643464ebd5Sriastradh/* The 'extra' mechanism is a way to specify extra checks (such as
2653464ebd5Sriastradh * extensions or specific gl versions) or actions (flush current, new
2663464ebd5Sriastradh * buffers) that we need to do before looking up an enum.  We need to
2673464ebd5Sriastradh * declare them all up front so we can refer to them in the value_desc
268af69d88dSmrg * structs below.
269af69d88dSmrg *
270af69d88dSmrg * Each EXTRA_ will be executed.  For EXTRA_* enums of extensions and API
271af69d88dSmrg * versions, listing multiple ones in an array means an error will be thrown
272af69d88dSmrg * only if none of them are available.  If you need to check for "AND"
273af69d88dSmrg * behavior, you would need to make a custom EXTRA_ enum.
274af69d88dSmrg */
2753464ebd5Sriastradh
2763464ebd5Sriastradhstatic const int extra_new_buffers[] = {
2773464ebd5Sriastradh   EXTRA_NEW_BUFFERS,
2783464ebd5Sriastradh   EXTRA_END
2793464ebd5Sriastradh};
2803464ebd5Sriastradh
2813464ebd5Sriastradhstatic const int extra_new_frag_clamp[] = {
2823464ebd5Sriastradh   EXTRA_NEW_FRAG_CLAMP,
2833464ebd5Sriastradh   EXTRA_END
2843464ebd5Sriastradh};
2853464ebd5Sriastradh
2863464ebd5Sriastradhstatic const int extra_valid_draw_buffer[] = {
2873464ebd5Sriastradh   EXTRA_VALID_DRAW_BUFFER,
2883464ebd5Sriastradh   EXTRA_END
2893464ebd5Sriastradh};
2903464ebd5Sriastradh
2913464ebd5Sriastradhstatic const int extra_valid_texture_unit[] = {
2923464ebd5Sriastradh   EXTRA_VALID_TEXTURE_UNIT,
2933464ebd5Sriastradh   EXTRA_END
2943464ebd5Sriastradh};
2953464ebd5Sriastradh
296af69d88dSmrgstatic const int extra_valid_clip_distance[] = {
297af69d88dSmrg   EXTRA_VALID_CLIP_DISTANCE,
298af69d88dSmrg   EXTRA_END
299af69d88dSmrg};
300af69d88dSmrg
3013464ebd5Sriastradhstatic const int extra_flush_current_valid_texture_unit[] = {
3023464ebd5Sriastradh   EXTRA_FLUSH_CURRENT,
3033464ebd5Sriastradh   EXTRA_VALID_TEXTURE_UNIT,
3043464ebd5Sriastradh   EXTRA_END
3053464ebd5Sriastradh};
3063464ebd5Sriastradh
3073464ebd5Sriastradhstatic const int extra_flush_current[] = {
3083464ebd5Sriastradh   EXTRA_FLUSH_CURRENT,
3093464ebd5Sriastradh   EXTRA_END
3103464ebd5Sriastradh};
3113464ebd5Sriastradh
312af69d88dSmrgstatic const int extra_EXT_texture_integer_and_new_buffers[] = {
313af69d88dSmrg   EXT(EXT_texture_integer),
3143464ebd5Sriastradh   EXTRA_NEW_BUFFERS,
3153464ebd5Sriastradh   EXTRA_END
3163464ebd5Sriastradh};
3173464ebd5Sriastradh
318af69d88dSmrgstatic const int extra_GLSL_130_es3[] = {
319af69d88dSmrg   EXTRA_GLSL_130,
320af69d88dSmrg   EXTRA_API_ES3,
3213464ebd5Sriastradh   EXTRA_END
3223464ebd5Sriastradh};
3233464ebd5Sriastradh
324af69d88dSmrgstatic const int extra_texture_buffer_object[] = {
325af69d88dSmrg   EXT(ARB_texture_buffer_object),
3263464ebd5Sriastradh   EXTRA_END
3273464ebd5Sriastradh};
3283464ebd5Sriastradh
329af69d88dSmrgstatic const int extra_ARB_transform_feedback2_api_es3[] = {
330af69d88dSmrg   EXT(ARB_transform_feedback2),
331af69d88dSmrg   EXTRA_API_ES3,
3323464ebd5Sriastradh   EXTRA_END
3333464ebd5Sriastradh};
3343464ebd5Sriastradh
335af69d88dSmrgstatic const int extra_ARB_uniform_buffer_object_and_geometry_shader[] = {
33601e04c3fSmrg   EXTRA_EXT_UBO_GS,
3373464ebd5Sriastradh   EXTRA_END
3383464ebd5Sriastradh};
3393464ebd5Sriastradh
340af69d88dSmrgstatic const int extra_ARB_ES2_compatibility_api_es2[] = {
341af69d88dSmrg   EXT(ARB_ES2_compatibility),
342af69d88dSmrg   EXTRA_API_ES2,
3433464ebd5Sriastradh   EXTRA_END
3443464ebd5Sriastradh};
3453464ebd5Sriastradh
346af69d88dSmrgstatic const int extra_ARB_ES3_compatibility_api_es3[] = {
347af69d88dSmrg   EXT(ARB_ES3_compatibility),
348af69d88dSmrg   EXTRA_API_ES3,
349af69d88dSmrg   EXTRA_END
350af69d88dSmrg};
351af69d88dSmrg
352af69d88dSmrgstatic const int extra_EXT_framebuffer_sRGB_and_new_buffers[] = {
353af69d88dSmrg   EXT(EXT_framebuffer_sRGB),
354af69d88dSmrg   EXTRA_NEW_BUFFERS,
355af69d88dSmrg   EXTRA_END
356af69d88dSmrg};
357af69d88dSmrg
358af69d88dSmrgstatic const int extra_EXT_packed_float[] = {
359af69d88dSmrg   EXT(EXT_packed_float),
360af69d88dSmrg   EXTRA_NEW_BUFFERS,
361af69d88dSmrg   EXTRA_END
362af69d88dSmrg};
363af69d88dSmrg
364af69d88dSmrgstatic const int extra_EXT_texture_array_es3[] = {
365af69d88dSmrg   EXT(EXT_texture_array),
366af69d88dSmrg   EXTRA_API_ES3,
367af69d88dSmrg   EXTRA_END
368af69d88dSmrg};
369af69d88dSmrg
370af69d88dSmrgstatic const int extra_ARB_shader_atomic_counters_and_geometry_shader[] = {
37101e04c3fSmrg   EXTRA_EXT_ATOMICS_GS,
372af69d88dSmrg   EXTRA_END
373af69d88dSmrg};
374af69d88dSmrg
375af69d88dSmrgstatic const int extra_ARB_shader_image_load_store_and_geometry_shader[] = {
37601e04c3fSmrg   EXTRA_EXT_SHADER_IMAGE_GS,
37701e04c3fSmrg   EXTRA_END
37801e04c3fSmrg};
37901e04c3fSmrg
38001e04c3fSmrgstatic const int extra_ARB_shader_atomic_counters_and_tessellation[] = {
38101e04c3fSmrg   EXTRA_EXT_ATOMICS_TESS,
38201e04c3fSmrg   EXTRA_END
38301e04c3fSmrg};
38401e04c3fSmrg
38501e04c3fSmrgstatic const int extra_ARB_shader_image_load_store_and_tessellation[] = {
38601e04c3fSmrg   EXTRA_EXT_SHADER_IMAGE_TESS,
38701e04c3fSmrg   EXTRA_END
38801e04c3fSmrg};
38901e04c3fSmrg
39001e04c3fSmrg/* HACK: remove when ARB_compute_shader is actually supported */
39101e04c3fSmrgstatic const int extra_ARB_compute_shader_es31[] = {
39201e04c3fSmrg   EXT(ARB_compute_shader),
39301e04c3fSmrg   EXTRA_API_ES31,
39401e04c3fSmrg   EXTRA_END
39501e04c3fSmrg};
39601e04c3fSmrg
39701e04c3fSmrgstatic const int extra_ARB_shader_storage_buffer_object_es31[] = {
39801e04c3fSmrg   EXT(ARB_shader_storage_buffer_object),
39901e04c3fSmrg   EXTRA_API_ES31,
40001e04c3fSmrg   EXTRA_END
40101e04c3fSmrg};
40201e04c3fSmrg
40301e04c3fSmrgstatic const int extra_ARB_shader_storage_buffer_object_and_geometry_shader[] = {
40401e04c3fSmrg   EXTRA_EXT_SSBO_GS,
40501e04c3fSmrg   EXTRA_END
40601e04c3fSmrg};
40701e04c3fSmrg
40801e04c3fSmrgstatic const int extra_ARB_shader_image_load_store_shader_storage_buffer_object_es31[] = {
40901e04c3fSmrg   EXT(ARB_shader_image_load_store),
41001e04c3fSmrg   EXT(ARB_shader_storage_buffer_object),
41101e04c3fSmrg   EXTRA_API_ES31,
41201e04c3fSmrg   EXTRA_END
41301e04c3fSmrg};
41401e04c3fSmrg
41501e04c3fSmrgstatic const int extra_ARB_framebuffer_no_attachments_and_geometry_shader[] = {
41601e04c3fSmrg   EXTRA_EXT_FB_NO_ATTACH_GS,
41701e04c3fSmrg   EXTRA_END
41801e04c3fSmrg};
41901e04c3fSmrg
42001e04c3fSmrgstatic const int extra_ARB_viewport_array_or_oes_geometry_shader[] = {
42101e04c3fSmrg   EXT(ARB_viewport_array),
42201e04c3fSmrg   EXTRA_EXT_ES_GS,
42301e04c3fSmrg   EXTRA_END
42401e04c3fSmrg};
42501e04c3fSmrg
42601e04c3fSmrgstatic const int extra_ARB_viewport_array_or_oes_viewport_array[] = {
42701e04c3fSmrg   EXT(ARB_viewport_array),
42801e04c3fSmrg   EXT(OES_viewport_array),
42901e04c3fSmrg   EXTRA_END
43001e04c3fSmrg};
43101e04c3fSmrg
43201e04c3fSmrgstatic const int extra_ARB_gpu_shader5_or_oes_geometry_shader[] = {
43301e04c3fSmrg   EXT(ARB_gpu_shader5),
43401e04c3fSmrg   EXTRA_EXT_ES_GS,
43501e04c3fSmrg   EXTRA_END
43601e04c3fSmrg};
43701e04c3fSmrg
43801e04c3fSmrgstatic const int extra_ARB_gpu_shader5_or_OES_sample_variables[] = {
43901e04c3fSmrg   EXT(ARB_gpu_shader5),
44001e04c3fSmrg   EXT(OES_sample_variables),
44101e04c3fSmrg   EXTRA_END
44201e04c3fSmrg};
44301e04c3fSmrg
44401e04c3fSmrgstatic const int extra_ES32[] = {
44501e04c3fSmrg   EXT(ARB_ES3_2_compatibility),
44601e04c3fSmrg   EXTRA_API_ES32,
44701e04c3fSmrg   EXTRA_END
44801e04c3fSmrg};
44901e04c3fSmrg
45001e04c3fSmrgstatic const int extra_KHR_robustness_or_GL[] = {
45101e04c3fSmrg   EXT(KHR_robustness),
45201e04c3fSmrg   EXTRA_API_GL,
45301e04c3fSmrg   EXTRA_API_GL_CORE,
45401e04c3fSmrg   EXTRA_END
45501e04c3fSmrg};
45601e04c3fSmrg
45701e04c3fSmrgstatic const int extra_INTEL_conservative_rasterization[] = {
45801e04c3fSmrg   EXT(INTEL_conservative_rasterization),
459af69d88dSmrg   EXTRA_END
460af69d88dSmrg};
4613464ebd5Sriastradh
4623464ebd5SriastradhEXTRA_EXT(ARB_texture_cube_map);
463af69d88dSmrgEXTRA_EXT(EXT_texture_array);
464af69d88dSmrgEXTRA_EXT(NV_fog_distance);
4653464ebd5SriastradhEXTRA_EXT(EXT_texture_filter_anisotropic);
4663464ebd5SriastradhEXTRA_EXT(NV_point_sprite);
4673464ebd5SriastradhEXTRA_EXT(NV_texture_rectangle);
4683464ebd5SriastradhEXTRA_EXT(EXT_stencil_two_side);
4693464ebd5SriastradhEXTRA_EXT(EXT_depth_bounds_test);
4703464ebd5SriastradhEXTRA_EXT(ARB_depth_clamp);
47101e04c3fSmrgEXTRA_EXT(AMD_depth_clamp_separate);
4723464ebd5SriastradhEXTRA_EXT(ATI_fragment_shader);
4733464ebd5SriastradhEXTRA_EXT(EXT_provoking_vertex);
4743464ebd5SriastradhEXTRA_EXT(ARB_fragment_shader);
4753464ebd5SriastradhEXTRA_EXT(ARB_fragment_program);
4763464ebd5SriastradhEXTRA_EXT2(ARB_framebuffer_object, EXT_framebuffer_multisample);
4773464ebd5SriastradhEXTRA_EXT(ARB_seamless_cube_map);
4783464ebd5SriastradhEXTRA_EXT(ARB_sync);
4793464ebd5SriastradhEXTRA_EXT(ARB_vertex_shader);
4803464ebd5SriastradhEXTRA_EXT(EXT_transform_feedback);
481af69d88dSmrgEXTRA_EXT(ARB_transform_feedback3);
4823464ebd5SriastradhEXTRA_EXT(EXT_pixel_buffer_object);
4833464ebd5SriastradhEXTRA_EXT(ARB_vertex_program);
4843464ebd5SriastradhEXTRA_EXT2(NV_point_sprite, ARB_point_sprite);
4853464ebd5SriastradhEXTRA_EXT2(ARB_vertex_program, ARB_fragment_program);
486af69d88dSmrgEXTRA_EXT(ARB_color_buffer_float);
4873464ebd5SriastradhEXTRA_EXT(EXT_framebuffer_sRGB);
488af69d88dSmrgEXTRA_EXT(OES_EGL_image_external);
489af69d88dSmrgEXTRA_EXT(ARB_blend_func_extended);
490af69d88dSmrgEXTRA_EXT(ARB_uniform_buffer_object);
491af69d88dSmrgEXTRA_EXT(ARB_timer_query);
49201e04c3fSmrgEXTRA_EXT2(ARB_texture_cube_map_array, OES_texture_cube_map_array);
493af69d88dSmrgEXTRA_EXT(ARB_texture_buffer_range);
494af69d88dSmrgEXTRA_EXT(ARB_texture_multisample);
495af69d88dSmrgEXTRA_EXT(ARB_texture_gather);
496af69d88dSmrgEXTRA_EXT(ARB_shader_atomic_counters);
497af69d88dSmrgEXTRA_EXT(ARB_draw_indirect);
498af69d88dSmrgEXTRA_EXT(ARB_shader_image_load_store);
49901e04c3fSmrgEXTRA_EXT(ARB_query_buffer_object);
500af69d88dSmrgEXTRA_EXT2(ARB_transform_feedback3, ARB_gpu_shader5);
501af69d88dSmrgEXTRA_EXT(INTEL_performance_query);
502af69d88dSmrgEXTRA_EXT(ARB_explicit_uniform_location);
50301e04c3fSmrgEXTRA_EXT(ARB_clip_control);
50401e04c3fSmrgEXTRA_EXT(ARB_polygon_offset_clamp);
50501e04c3fSmrgEXTRA_EXT(ARB_framebuffer_no_attachments);
50601e04c3fSmrgEXTRA_EXT(ARB_tessellation_shader);
50701e04c3fSmrgEXTRA_EXT(ARB_shader_storage_buffer_object);
50801e04c3fSmrgEXTRA_EXT(ARB_indirect_parameters);
50901e04c3fSmrgEXTRA_EXT(ATI_meminfo);
51001e04c3fSmrgEXTRA_EXT(NVX_gpu_memory_info);
51101e04c3fSmrgEXTRA_EXT(ARB_cull_distance);
51201e04c3fSmrgEXTRA_EXT(EXT_window_rectangles);
51301e04c3fSmrgEXTRA_EXT(KHR_blend_equation_advanced_coherent);
51401e04c3fSmrgEXTRA_EXT(OES_primitive_bounding_box);
51501e04c3fSmrgEXTRA_EXT(ARB_compute_variable_group_size);
51601e04c3fSmrgEXTRA_EXT(KHR_robustness);
51701e04c3fSmrgEXTRA_EXT(ARB_sparse_buffer);
51801e04c3fSmrgEXTRA_EXT(NV_conservative_raster);
51901e04c3fSmrgEXTRA_EXT(NV_conservative_raster_dilate);
52001e04c3fSmrgEXTRA_EXT(NV_conservative_raster_pre_snap_triangles);
52101e04c3fSmrgEXTRA_EXT(ARB_sample_locations);
52201e04c3fSmrgEXTRA_EXT(AMD_framebuffer_multisample_advanced);
5233464ebd5Sriastradh
5243464ebd5Sriastradhstatic const int
525af69d88dSmrgextra_ARB_color_buffer_float_or_glcore[] = {
526af69d88dSmrg   EXT(ARB_color_buffer_float),
527af69d88dSmrg   EXTRA_API_GL_CORE,
5283464ebd5Sriastradh   EXTRA_END
5293464ebd5Sriastradh};
5303464ebd5Sriastradh
5313464ebd5Sriastradhstatic const int
5323464ebd5Sriastradhextra_NV_primitive_restart[] = {
5333464ebd5Sriastradh   EXT(NV_primitive_restart),
5343464ebd5Sriastradh   EXTRA_END
5353464ebd5Sriastradh};
5363464ebd5Sriastradh
5373464ebd5Sriastradhstatic const int extra_version_30[] = { EXTRA_VERSION_30, EXTRA_END };
5383464ebd5Sriastradhstatic const int extra_version_31[] = { EXTRA_VERSION_31, EXTRA_END };
5393464ebd5Sriastradhstatic const int extra_version_32[] = { EXTRA_VERSION_32, EXTRA_END };
54001e04c3fSmrgstatic const int extra_version_43[] = { EXTRA_VERSION_43, EXTRA_END };
541af69d88dSmrg
542af69d88dSmrgstatic const int extra_gl30_es3[] = {
543af69d88dSmrg    EXTRA_VERSION_30,
544af69d88dSmrg    EXTRA_API_ES3,
545af69d88dSmrg    EXTRA_END,
546af69d88dSmrg};
547af69d88dSmrg
548af69d88dSmrgstatic const int extra_gl32_es3[] = {
549af69d88dSmrg    EXTRA_VERSION_32,
550af69d88dSmrg    EXTRA_API_ES3,
551af69d88dSmrg    EXTRA_END,
552af69d88dSmrg};
553af69d88dSmrg
55401e04c3fSmrgstatic const int extra_version_32_OES_geometry_shader[] = {
555af69d88dSmrg    EXTRA_VERSION_32,
55601e04c3fSmrg    EXTRA_EXT_ES_GS,
557af69d88dSmrg    EXTRA_END
558af69d88dSmrg};
559af69d88dSmrg
560af69d88dSmrgstatic const int extra_gl40_ARB_sample_shading[] = {
561af69d88dSmrg   EXTRA_VERSION_40,
562af69d88dSmrg   EXT(ARB_sample_shading),
563af69d88dSmrg   EXTRA_END
564af69d88dSmrg};
5653464ebd5Sriastradh
5663464ebd5Sriastradhstatic const int
567af69d88dSmrgextra_ARB_vertex_program_api_es2[] = {
5683464ebd5Sriastradh   EXT(ARB_vertex_program),
569af69d88dSmrg   EXTRA_API_ES2,
570af69d88dSmrg   EXTRA_END
571af69d88dSmrg};
572af69d88dSmrg
573af69d88dSmrg/* The ReadBuffer get token is valid under either full GL or under
574af69d88dSmrg * GLES2 if the NV_read_buffer extension is available. */
575af69d88dSmrgstatic const int
576af69d88dSmrgextra_NV_read_buffer_api_gl[] = {
577af69d88dSmrg   EXTRA_API_ES2,
578af69d88dSmrg   EXTRA_API_GL,
5793464ebd5Sriastradh   EXTRA_END
5803464ebd5Sriastradh};
5813464ebd5Sriastradh
582af69d88dSmrgstatic const int extra_core_ARB_color_buffer_float_and_new_buffers[] = {
583af69d88dSmrg   EXTRA_API_GL_CORE,
584af69d88dSmrg   EXT(ARB_color_buffer_float),
585af69d88dSmrg   EXTRA_NEW_BUFFERS,
586af69d88dSmrg   EXTRA_END
587af69d88dSmrg};
5883464ebd5Sriastradh
58901e04c3fSmrgstatic const int extra_EXT_shader_framebuffer_fetch[] = {
59001e04c3fSmrg   EXTRA_API_ES2,
59101e04c3fSmrg   EXTRA_API_ES3,
59201e04c3fSmrg   EXT(EXT_shader_framebuffer_fetch),
59301e04c3fSmrg   EXTRA_END
59401e04c3fSmrg};
59501e04c3fSmrg
59601e04c3fSmrgstatic const int extra_EXT_provoking_vertex_32[] = {
59701e04c3fSmrg   EXTRA_EXT_PROVOKING_VERTEX_32,
59801e04c3fSmrg   EXTRA_END
59901e04c3fSmrg};
60001e04c3fSmrg
60101e04c3fSmrgstatic const int extra_EXT_disjoint_timer_query[] = {
60201e04c3fSmrg   EXTRA_API_ES2,
60301e04c3fSmrg   EXTRA_API_ES3,
60401e04c3fSmrg   EXT(EXT_disjoint_timer_query),
60501e04c3fSmrg   EXTRA_END
60601e04c3fSmrg};
60701e04c3fSmrg
60801e04c3fSmrg
6093464ebd5Sriastradh/* This is the big table describing all the enums we accept in
6103464ebd5Sriastradh * glGet*v().  The table is partitioned into six parts: enums
6113464ebd5Sriastradh * understood by all GL APIs (OpenGL, GLES and GLES2), enums shared
6123464ebd5Sriastradh * between OpenGL and GLES, enums exclusive to GLES, etc for the
613af69d88dSmrg * remaining combinations. To look up the enums valid in a given API
614af69d88dSmrg * we will use a hash table specific to that API. These tables are in
615af69d88dSmrg * turn generated at build time and included through get_hash.h.
616af69d88dSmrg */
6173464ebd5Sriastradh
618af69d88dSmrg#include "get_hash.h"
6193464ebd5Sriastradh
6203464ebd5Sriastradh/* All we need now is a way to look up the value struct from the enum.
6213464ebd5Sriastradh * The code generated by gcc for the old generated big switch
6223464ebd5Sriastradh * statement is a big, balanced, open coded if/else tree, essentially
6233464ebd5Sriastradh * an unrolled binary search.  It would be natural to sort the new
6243464ebd5Sriastradh * enum table and use bsearch(), but we will use a read-only hash
6253464ebd5Sriastradh * table instead.  bsearch() has a nice guaranteed worst case
6263464ebd5Sriastradh * performance, but we're also guaranteed to hit that worst case
6273464ebd5Sriastradh * (log2(n) iterations) for about half the enums.  Instead, using an
6283464ebd5Sriastradh * open addressing hash table, we can find the enum on the first try
6293464ebd5Sriastradh * for 80% of the enums, 1 collision for 10% and never more than 5
6303464ebd5Sriastradh * collisions for any enum (typical numbers).  And the code is very
6313464ebd5Sriastradh * simple, even though it feels a little magic. */
6323464ebd5Sriastradh
6333464ebd5Sriastradh/**
6343464ebd5Sriastradh * Handle irregular enums
6353464ebd5Sriastradh *
6363464ebd5Sriastradh * Some values don't conform to the "well-known type at context
6373464ebd5Sriastradh * pointer + offset" pattern, so we have this function to catch all
6383464ebd5Sriastradh * the corner cases.  Typically, it's a computed value or a one-off
6393464ebd5Sriastradh * pointer to a custom struct or something.
6403464ebd5Sriastradh *
6413464ebd5Sriastradh * In this case we can't return a pointer to the value, so we'll have
6423464ebd5Sriastradh * to use the temporary variable 'v' declared back in the calling
6433464ebd5Sriastradh * glGet*v() function to store the result.
6443464ebd5Sriastradh *
6453464ebd5Sriastradh * \param ctx the current context
6463464ebd5Sriastradh * \param d the struct value_desc that describes the enum
6473464ebd5Sriastradh * \param v pointer to the tmp declared in the calling glGet*v() function
6483464ebd5Sriastradh */
6493464ebd5Sriastradhstatic void
6503464ebd5Sriastradhfind_custom_value(struct gl_context *ctx, const struct value_desc *d, union value *v)
6513464ebd5Sriastradh{
6523464ebd5Sriastradh   struct gl_buffer_object **buffer_obj;
65301e04c3fSmrg   struct gl_array_attributes *array;
6543464ebd5Sriastradh   GLuint unit, *p;
6553464ebd5Sriastradh
6563464ebd5Sriastradh   switch (d->pname) {
657af69d88dSmrg   case GL_MAJOR_VERSION:
658af69d88dSmrg      v->value_int = ctx->Version / 10;
659af69d88dSmrg      break;
660af69d88dSmrg   case GL_MINOR_VERSION:
661af69d88dSmrg      v->value_int = ctx->Version % 10;
662af69d88dSmrg      break;
663af69d88dSmrg
6643464ebd5Sriastradh   case GL_TEXTURE_1D:
6653464ebd5Sriastradh   case GL_TEXTURE_2D:
6663464ebd5Sriastradh   case GL_TEXTURE_3D:
66701e04c3fSmrg   case GL_TEXTURE_CUBE_MAP:
6683464ebd5Sriastradh   case GL_TEXTURE_RECTANGLE_NV:
669af69d88dSmrg   case GL_TEXTURE_EXTERNAL_OES:
6703464ebd5Sriastradh      v->value_bool = _mesa_IsEnabled(d->pname);
6713464ebd5Sriastradh      break;
6723464ebd5Sriastradh
6733464ebd5Sriastradh   case GL_LINE_STIPPLE_PATTERN:
6743464ebd5Sriastradh      /* This is the only GLushort, special case it here by promoting
6753464ebd5Sriastradh       * to an int rather than introducing a new type. */
6763464ebd5Sriastradh      v->value_int = ctx->Line.StipplePattern;
6773464ebd5Sriastradh      break;
6783464ebd5Sriastradh
6793464ebd5Sriastradh   case GL_CURRENT_RASTER_TEXTURE_COORDS:
6803464ebd5Sriastradh      unit = ctx->Texture.CurrentUnit;
6813464ebd5Sriastradh      v->value_float_4[0] = ctx->Current.RasterTexCoords[unit][0];
6823464ebd5Sriastradh      v->value_float_4[1] = ctx->Current.RasterTexCoords[unit][1];
6833464ebd5Sriastradh      v->value_float_4[2] = ctx->Current.RasterTexCoords[unit][2];
6843464ebd5Sriastradh      v->value_float_4[3] = ctx->Current.RasterTexCoords[unit][3];
6853464ebd5Sriastradh      break;
6863464ebd5Sriastradh
6873464ebd5Sriastradh   case GL_CURRENT_TEXTURE_COORDS:
6883464ebd5Sriastradh      unit = ctx->Texture.CurrentUnit;
6893464ebd5Sriastradh      v->value_float_4[0] = ctx->Current.Attrib[VERT_ATTRIB_TEX0 + unit][0];
6903464ebd5Sriastradh      v->value_float_4[1] = ctx->Current.Attrib[VERT_ATTRIB_TEX0 + unit][1];
6913464ebd5Sriastradh      v->value_float_4[2] = ctx->Current.Attrib[VERT_ATTRIB_TEX0 + unit][2];
6923464ebd5Sriastradh      v->value_float_4[3] = ctx->Current.Attrib[VERT_ATTRIB_TEX0 + unit][3];
6933464ebd5Sriastradh      break;
6943464ebd5Sriastradh
6953464ebd5Sriastradh   case GL_COLOR_WRITEMASK:
69601e04c3fSmrg      v->value_int_4[0] = GET_COLORMASK_BIT(ctx->Color.ColorMask, 0, 0);
69701e04c3fSmrg      v->value_int_4[1] = GET_COLORMASK_BIT(ctx->Color.ColorMask, 0, 1);
69801e04c3fSmrg      v->value_int_4[2] = GET_COLORMASK_BIT(ctx->Color.ColorMask, 0, 2);
69901e04c3fSmrg      v->value_int_4[3] = GET_COLORMASK_BIT(ctx->Color.ColorMask, 0, 3);
70001e04c3fSmrg      break;
70101e04c3fSmrg
70201e04c3fSmrg   case GL_DEPTH_CLAMP:
70301e04c3fSmrg      v->value_bool = ctx->Transform.DepthClampNear || ctx->Transform.DepthClampFar;
7043464ebd5Sriastradh      break;
7053464ebd5Sriastradh
7063464ebd5Sriastradh   case GL_EDGE_FLAG:
70701e04c3fSmrg      v->value_bool = ctx->Current.Attrib[VERT_ATTRIB_EDGEFLAG][0] == 1.0F;
7083464ebd5Sriastradh      break;
7093464ebd5Sriastradh
7103464ebd5Sriastradh   case GL_READ_BUFFER:
7113464ebd5Sriastradh      v->value_enum = ctx->ReadBuffer->ColorReadBuffer;
7123464ebd5Sriastradh      break;
7133464ebd5Sriastradh
7143464ebd5Sriastradh   case GL_MAP2_GRID_DOMAIN:
7153464ebd5Sriastradh      v->value_float_4[0] = ctx->Eval.MapGrid2u1;
7163464ebd5Sriastradh      v->value_float_4[1] = ctx->Eval.MapGrid2u2;
7173464ebd5Sriastradh      v->value_float_4[2] = ctx->Eval.MapGrid2v1;
7183464ebd5Sriastradh      v->value_float_4[3] = ctx->Eval.MapGrid2v2;
7193464ebd5Sriastradh      break;
7203464ebd5Sriastradh
7213464ebd5Sriastradh   case GL_TEXTURE_STACK_DEPTH:
7223464ebd5Sriastradh      unit = ctx->Texture.CurrentUnit;
7233464ebd5Sriastradh      v->value_int = ctx->TextureMatrixStack[unit].Depth + 1;
7243464ebd5Sriastradh      break;
7253464ebd5Sriastradh   case GL_TEXTURE_MATRIX:
7263464ebd5Sriastradh      unit = ctx->Texture.CurrentUnit;
7273464ebd5Sriastradh      v->value_matrix = ctx->TextureMatrixStack[unit].Top;
7283464ebd5Sriastradh      break;
7293464ebd5Sriastradh
7303464ebd5Sriastradh   case GL_TEXTURE_COORD_ARRAY:
7313464ebd5Sriastradh   case GL_TEXTURE_COORD_ARRAY_SIZE:
7323464ebd5Sriastradh   case GL_TEXTURE_COORD_ARRAY_TYPE:
7333464ebd5Sriastradh   case GL_TEXTURE_COORD_ARRAY_STRIDE:
734af69d88dSmrg      array = &ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_TEX(ctx->Array.ActiveTexture)];
7353464ebd5Sriastradh      v->value_int = *(GLuint *) ((char *) array + d->offset);
7363464ebd5Sriastradh      break;
7373464ebd5Sriastradh
7383464ebd5Sriastradh   case GL_ACTIVE_TEXTURE_ARB:
7393464ebd5Sriastradh      v->value_int = GL_TEXTURE0_ARB + ctx->Texture.CurrentUnit;
7403464ebd5Sriastradh      break;
7413464ebd5Sriastradh   case GL_CLIENT_ACTIVE_TEXTURE_ARB:
7423464ebd5Sriastradh      v->value_int = GL_TEXTURE0_ARB + ctx->Array.ActiveTexture;
7433464ebd5Sriastradh      break;
7443464ebd5Sriastradh
7453464ebd5Sriastradh   case GL_MODELVIEW_STACK_DEPTH:
7463464ebd5Sriastradh   case GL_PROJECTION_STACK_DEPTH:
7473464ebd5Sriastradh      v->value_int = *(GLint *) ((char *) ctx + d->offset) + 1;
7483464ebd5Sriastradh      break;
7493464ebd5Sriastradh
7503464ebd5Sriastradh   case GL_MAX_TEXTURE_SIZE:
7513464ebd5Sriastradh   case GL_MAX_3D_TEXTURE_SIZE:
7523464ebd5Sriastradh   case GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB:
7533464ebd5Sriastradh      p = (GLuint *) ((char *) ctx + d->offset);
7543464ebd5Sriastradh      v->value_int = 1 << (*p - 1);
7553464ebd5Sriastradh      break;
7563464ebd5Sriastradh
7573464ebd5Sriastradh   case GL_SCISSOR_BOX:
758af69d88dSmrg      v->value_int_4[0] = ctx->Scissor.ScissorArray[0].X;
759af69d88dSmrg      v->value_int_4[1] = ctx->Scissor.ScissorArray[0].Y;
760af69d88dSmrg      v->value_int_4[2] = ctx->Scissor.ScissorArray[0].Width;
761af69d88dSmrg      v->value_int_4[3] = ctx->Scissor.ScissorArray[0].Height;
762af69d88dSmrg      break;
763af69d88dSmrg
764af69d88dSmrg   case GL_SCISSOR_TEST:
765af69d88dSmrg      v->value_bool = ctx->Scissor.EnableFlags & 1;
7663464ebd5Sriastradh      break;
7673464ebd5Sriastradh
7683464ebd5Sriastradh   case GL_LIST_INDEX:
7693464ebd5Sriastradh      v->value_int =
77001e04c3fSmrg         ctx->ListState.CurrentList ? ctx->ListState.CurrentList->Name : 0;
7713464ebd5Sriastradh      break;
7723464ebd5Sriastradh   case GL_LIST_MODE:
7733464ebd5Sriastradh      if (!ctx->CompileFlag)
77401e04c3fSmrg         v->value_enum = 0;
7753464ebd5Sriastradh      else if (ctx->ExecuteFlag)
77601e04c3fSmrg         v->value_enum = GL_COMPILE_AND_EXECUTE;
7773464ebd5Sriastradh      else
77801e04c3fSmrg         v->value_enum = GL_COMPILE;
7793464ebd5Sriastradh      break;
7803464ebd5Sriastradh
7813464ebd5Sriastradh   case GL_VIEWPORT:
782af69d88dSmrg      v->value_float_4[0] = ctx->ViewportArray[0].X;
783af69d88dSmrg      v->value_float_4[1] = ctx->ViewportArray[0].Y;
784af69d88dSmrg      v->value_float_4[2] = ctx->ViewportArray[0].Width;
785af69d88dSmrg      v->value_float_4[3] = ctx->ViewportArray[0].Height;
786af69d88dSmrg      break;
787af69d88dSmrg
788af69d88dSmrg   case GL_DEPTH_RANGE:
789af69d88dSmrg      v->value_double_2[0] = ctx->ViewportArray[0].Near;
790af69d88dSmrg      v->value_double_2[1] = ctx->ViewportArray[0].Far;
7913464ebd5Sriastradh      break;
7923464ebd5Sriastradh
7933464ebd5Sriastradh   case GL_ACTIVE_STENCIL_FACE_EXT:
7943464ebd5Sriastradh      v->value_enum = ctx->Stencil.ActiveFace ? GL_BACK : GL_FRONT;
7953464ebd5Sriastradh      break;
7963464ebd5Sriastradh
7973464ebd5Sriastradh   case GL_STENCIL_FAIL:
7983464ebd5Sriastradh      v->value_enum = ctx->Stencil.FailFunc[ctx->Stencil.ActiveFace];
7993464ebd5Sriastradh      break;
8003464ebd5Sriastradh   case GL_STENCIL_FUNC:
8013464ebd5Sriastradh      v->value_enum = ctx->Stencil.Function[ctx->Stencil.ActiveFace];
8023464ebd5Sriastradh      break;
8033464ebd5Sriastradh   case GL_STENCIL_PASS_DEPTH_FAIL:
8043464ebd5Sriastradh      v->value_enum = ctx->Stencil.ZFailFunc[ctx->Stencil.ActiveFace];
8053464ebd5Sriastradh      break;
8063464ebd5Sriastradh   case GL_STENCIL_PASS_DEPTH_PASS:
8073464ebd5Sriastradh      v->value_enum = ctx->Stencil.ZPassFunc[ctx->Stencil.ActiveFace];
8083464ebd5Sriastradh      break;
8093464ebd5Sriastradh   case GL_STENCIL_REF:
810af69d88dSmrg      v->value_int = _mesa_get_stencil_ref(ctx, ctx->Stencil.ActiveFace);
811af69d88dSmrg      break;
812af69d88dSmrg   case GL_STENCIL_BACK_REF:
813af69d88dSmrg      v->value_int = _mesa_get_stencil_ref(ctx, 1);
8143464ebd5Sriastradh      break;
8153464ebd5Sriastradh   case GL_STENCIL_VALUE_MASK:
8163464ebd5Sriastradh      v->value_int = ctx->Stencil.ValueMask[ctx->Stencil.ActiveFace];
8173464ebd5Sriastradh      break;
8183464ebd5Sriastradh   case GL_STENCIL_WRITEMASK:
8193464ebd5Sriastradh      v->value_int = ctx->Stencil.WriteMask[ctx->Stencil.ActiveFace];
8203464ebd5Sriastradh      break;
8213464ebd5Sriastradh
8223464ebd5Sriastradh   case GL_NUM_EXTENSIONS:
8233464ebd5Sriastradh      v->value_int = _mesa_get_extension_count(ctx);
8243464ebd5Sriastradh      break;
8253464ebd5Sriastradh
8263464ebd5Sriastradh   case GL_IMPLEMENTATION_COLOR_READ_TYPE_OES:
82701e04c3fSmrg      v->value_int = _mesa_get_color_read_type(ctx, NULL, "glGetIntegerv");
8283464ebd5Sriastradh      break;
8293464ebd5Sriastradh   case GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES:
83001e04c3fSmrg      v->value_int = _mesa_get_color_read_format(ctx, NULL, "glGetIntegerv");
8313464ebd5Sriastradh      break;
8323464ebd5Sriastradh
8333464ebd5Sriastradh   case GL_CURRENT_MATRIX_STACK_DEPTH_ARB:
8343464ebd5Sriastradh      v->value_int = ctx->CurrentStack->Depth + 1;
8353464ebd5Sriastradh      break;
8363464ebd5Sriastradh   case GL_CURRENT_MATRIX_ARB:
8373464ebd5Sriastradh   case GL_TRANSPOSE_CURRENT_MATRIX_ARB:
8383464ebd5Sriastradh      v->value_matrix = ctx->CurrentStack->Top;
8393464ebd5Sriastradh      break;
8403464ebd5Sriastradh
8413464ebd5Sriastradh   case GL_NUM_COMPRESSED_TEXTURE_FORMATS_ARB:
8423464ebd5Sriastradh      v->value_int = _mesa_get_compressed_formats(ctx, NULL);
8433464ebd5Sriastradh      break;
8443464ebd5Sriastradh   case GL_COMPRESSED_TEXTURE_FORMATS_ARB:
84501e04c3fSmrg      v->value_int_n.n =
84601e04c3fSmrg         _mesa_get_compressed_formats(ctx, v->value_int_n.ints);
84701e04c3fSmrg      assert(v->value_int_n.n <= (int) ARRAY_SIZE(v->value_int_n.ints));
8483464ebd5Sriastradh      break;
8493464ebd5Sriastradh
8503464ebd5Sriastradh   case GL_MAX_VARYING_FLOATS_ARB:
8513464ebd5Sriastradh      v->value_int = ctx->Const.MaxVarying * 4;
8523464ebd5Sriastradh      break;
8533464ebd5Sriastradh
8543464ebd5Sriastradh   /* Various object names */
8553464ebd5Sriastradh
8563464ebd5Sriastradh   case GL_TEXTURE_BINDING_1D:
8573464ebd5Sriastradh   case GL_TEXTURE_BINDING_2D:
8583464ebd5Sriastradh   case GL_TEXTURE_BINDING_3D:
8593464ebd5Sriastradh   case GL_TEXTURE_BINDING_1D_ARRAY_EXT:
8603464ebd5Sriastradh   case GL_TEXTURE_BINDING_2D_ARRAY_EXT:
8613464ebd5Sriastradh   case GL_TEXTURE_BINDING_CUBE_MAP_ARB:
8623464ebd5Sriastradh   case GL_TEXTURE_BINDING_RECTANGLE_NV:
863af69d88dSmrg   case GL_TEXTURE_BINDING_EXTERNAL_OES:
864af69d88dSmrg   case GL_TEXTURE_BINDING_CUBE_MAP_ARRAY:
865af69d88dSmrg   case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
866af69d88dSmrg   case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY:
8673464ebd5Sriastradh      unit = ctx->Texture.CurrentUnit;
8683464ebd5Sriastradh      v->value_int =
86901e04c3fSmrg         ctx->Texture.Unit[unit].CurrentTex[d->offset]->Name;
87001e04c3fSmrg      break;
87101e04c3fSmrg
87201e04c3fSmrg   /* GL_EXT_external_objects */
87301e04c3fSmrg   case GL_DRIVER_UUID_EXT:
87401e04c3fSmrg      _mesa_get_driver_uuid(ctx, v->value_int_4);
87501e04c3fSmrg      break;
87601e04c3fSmrg   case GL_DEVICE_UUID_EXT:
87701e04c3fSmrg      _mesa_get_device_uuid(ctx, v->value_int_4);
8783464ebd5Sriastradh      break;
8793464ebd5Sriastradh
880af69d88dSmrg   /* GL_EXT_packed_float */
881af69d88dSmrg   case GL_RGBA_SIGNED_COMPONENTS_EXT:
882af69d88dSmrg      {
883af69d88dSmrg         /* Note: we only check the 0th color attachment. */
884af69d88dSmrg         const struct gl_renderbuffer *rb =
885af69d88dSmrg            ctx->DrawBuffer->_ColorDrawBuffers[0];
886af69d88dSmrg         if (rb && _mesa_is_format_signed(rb->Format)) {
887af69d88dSmrg            /* Issue 17 of GL_EXT_packed_float:  If a component (such as
888af69d88dSmrg             * alpha) has zero bits, the component should not be considered
889af69d88dSmrg             * signed and so the bit for the respective component should be
890af69d88dSmrg             * zeroed.
891af69d88dSmrg             */
892af69d88dSmrg            GLint r_bits =
893af69d88dSmrg               _mesa_get_format_bits(rb->Format, GL_RED_BITS);
894af69d88dSmrg            GLint g_bits =
895af69d88dSmrg               _mesa_get_format_bits(rb->Format, GL_GREEN_BITS);
896af69d88dSmrg            GLint b_bits =
897af69d88dSmrg               _mesa_get_format_bits(rb->Format, GL_BLUE_BITS);
898af69d88dSmrg            GLint a_bits =
899af69d88dSmrg               _mesa_get_format_bits(rb->Format, GL_ALPHA_BITS);
900af69d88dSmrg            GLint l_bits =
901af69d88dSmrg               _mesa_get_format_bits(rb->Format, GL_TEXTURE_LUMINANCE_SIZE);
902af69d88dSmrg            GLint i_bits =
903af69d88dSmrg               _mesa_get_format_bits(rb->Format, GL_TEXTURE_INTENSITY_SIZE);
904af69d88dSmrg
905af69d88dSmrg            v->value_int_4[0] = r_bits + l_bits + i_bits > 0;
906af69d88dSmrg            v->value_int_4[1] = g_bits + l_bits + i_bits > 0;
907af69d88dSmrg            v->value_int_4[2] = b_bits + l_bits + i_bits > 0;
908af69d88dSmrg            v->value_int_4[3] = a_bits + i_bits > 0;
909af69d88dSmrg         }
910af69d88dSmrg         else {
911af69d88dSmrg            v->value_int_4[0] =
912af69d88dSmrg            v->value_int_4[1] =
913af69d88dSmrg            v->value_int_4[2] =
914af69d88dSmrg            v->value_int_4[3] = 0;
915af69d88dSmrg         }
916af69d88dSmrg      }
917af69d88dSmrg      break;
918af69d88dSmrg
9193464ebd5Sriastradh   /* GL_ARB_vertex_buffer_object */
9203464ebd5Sriastradh   case GL_VERTEX_ARRAY_BUFFER_BINDING_ARB:
9213464ebd5Sriastradh   case GL_NORMAL_ARRAY_BUFFER_BINDING_ARB:
9223464ebd5Sriastradh   case GL_COLOR_ARRAY_BUFFER_BINDING_ARB:
9233464ebd5Sriastradh   case GL_INDEX_ARRAY_BUFFER_BINDING_ARB:
9243464ebd5Sriastradh   case GL_EDGE_FLAG_ARRAY_BUFFER_BINDING_ARB:
9253464ebd5Sriastradh   case GL_SECONDARY_COLOR_ARRAY_BUFFER_BINDING_ARB:
9263464ebd5Sriastradh   case GL_FOG_COORDINATE_ARRAY_BUFFER_BINDING_ARB:
9273464ebd5Sriastradh      buffer_obj = (struct gl_buffer_object **)
92801e04c3fSmrg         ((char *) ctx->Array.VAO + d->offset);
9293464ebd5Sriastradh      v->value_int = (*buffer_obj)->Name;
9303464ebd5Sriastradh      break;
9313464ebd5Sriastradh   case GL_ARRAY_BUFFER_BINDING_ARB:
9323464ebd5Sriastradh      v->value_int = ctx->Array.ArrayBufferObj->Name;
9333464ebd5Sriastradh      break;
9343464ebd5Sriastradh   case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING_ARB:
9353464ebd5Sriastradh      v->value_int =
93601e04c3fSmrg         ctx->Array.VAO->BufferBinding[VERT_ATTRIB_TEX(ctx->Array.ActiveTexture)].BufferObj->Name;
9373464ebd5Sriastradh      break;
9383464ebd5Sriastradh   case GL_ELEMENT_ARRAY_BUFFER_BINDING_ARB:
939af69d88dSmrg      v->value_int = ctx->Array.VAO->IndexBufferObj->Name;
940af69d88dSmrg      break;
941af69d88dSmrg
942af69d88dSmrg   /* ARB_vertex_array_bgra */
943af69d88dSmrg   case GL_COLOR_ARRAY_SIZE:
944af69d88dSmrg      array = &ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_COLOR0];
945af69d88dSmrg      v->value_int = array->Format == GL_BGRA ? GL_BGRA : array->Size;
946af69d88dSmrg      break;
947af69d88dSmrg   case GL_SECONDARY_COLOR_ARRAY_SIZE:
948af69d88dSmrg      array = &ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_COLOR1];
949af69d88dSmrg      v->value_int = array->Format == GL_BGRA ? GL_BGRA : array->Size;
9503464ebd5Sriastradh      break;
9513464ebd5Sriastradh
9523464ebd5Sriastradh   /* ARB_copy_buffer */
9533464ebd5Sriastradh   case GL_COPY_READ_BUFFER:
9543464ebd5Sriastradh      v->value_int = ctx->CopyReadBuffer->Name;
9553464ebd5Sriastradh      break;
9563464ebd5Sriastradh   case GL_COPY_WRITE_BUFFER:
9573464ebd5Sriastradh      v->value_int = ctx->CopyWriteBuffer->Name;
9583464ebd5Sriastradh      break;
9593464ebd5Sriastradh
9603464ebd5Sriastradh   case GL_PIXEL_PACK_BUFFER_BINDING_EXT:
9613464ebd5Sriastradh      v->value_int = ctx->Pack.BufferObj->Name;
9623464ebd5Sriastradh      break;
9633464ebd5Sriastradh   case GL_PIXEL_UNPACK_BUFFER_BINDING_EXT:
9643464ebd5Sriastradh      v->value_int = ctx->Unpack.BufferObj->Name;
9653464ebd5Sriastradh      break;
9663464ebd5Sriastradh   case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
9673464ebd5Sriastradh      v->value_int = ctx->TransformFeedback.CurrentBuffer->Name;
9683464ebd5Sriastradh      break;
9693464ebd5Sriastradh   case GL_TRANSFORM_FEEDBACK_BUFFER_PAUSED:
9703464ebd5Sriastradh      v->value_int = ctx->TransformFeedback.CurrentObject->Paused;
9713464ebd5Sriastradh      break;
9723464ebd5Sriastradh   case GL_TRANSFORM_FEEDBACK_BUFFER_ACTIVE:
9733464ebd5Sriastradh      v->value_int = ctx->TransformFeedback.CurrentObject->Active;
9743464ebd5Sriastradh      break;
9753464ebd5Sriastradh   case GL_TRANSFORM_FEEDBACK_BINDING:
9763464ebd5Sriastradh      v->value_int = ctx->TransformFeedback.CurrentObject->Name;
9773464ebd5Sriastradh      break;
9783464ebd5Sriastradh   case GL_CURRENT_PROGRAM:
979af69d88dSmrg      /* The Changelog of the ARB_separate_shader_objects spec says:
980af69d88dSmrg       *
981af69d88dSmrg       * 24 25 Jul 2011  pbrown  Remove the language erroneously deleting
982af69d88dSmrg       *                         CURRENT_PROGRAM.  In the EXT extension, this
983af69d88dSmrg       *                         token was aliased to ACTIVE_PROGRAM_EXT, and
984af69d88dSmrg       *                         was used to indicate the last program set by
985af69d88dSmrg       *                         either ActiveProgramEXT or UseProgram.  In
986af69d88dSmrg       *                         the ARB extension, the SSO active programs
987af69d88dSmrg       *                         are now program pipeline object state and
988af69d88dSmrg       *                         CURRENT_PROGRAM should still be used to query
989af69d88dSmrg       *                         the last program set by UseProgram (bug 7822).
990af69d88dSmrg       */
9913464ebd5Sriastradh      v->value_int =
99201e04c3fSmrg         ctx->Shader.ActiveProgram ? ctx->Shader.ActiveProgram->Name : 0;
9933464ebd5Sriastradh      break;
9943464ebd5Sriastradh   case GL_READ_FRAMEBUFFER_BINDING_EXT:
9953464ebd5Sriastradh      v->value_int = ctx->ReadBuffer->Name;
9963464ebd5Sriastradh      break;
9973464ebd5Sriastradh   case GL_RENDERBUFFER_BINDING_EXT:
9983464ebd5Sriastradh      v->value_int =
99901e04c3fSmrg         ctx->CurrentRenderbuffer ? ctx->CurrentRenderbuffer->Name : 0;
10003464ebd5Sriastradh      break;
10013464ebd5Sriastradh   case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
100201e04c3fSmrg      v->value_int = ctx->Array.VAO->BufferBinding[VERT_ATTRIB_POINT_SIZE].BufferObj->Name;
10033464ebd5Sriastradh      break;
10043464ebd5Sriastradh
10053464ebd5Sriastradh   case GL_FOG_COLOR:
100601e04c3fSmrg      if (_mesa_get_clamp_fragment_color(ctx, ctx->DrawBuffer))
10073464ebd5Sriastradh         COPY_4FV(v->value_float_4, ctx->Fog.Color);
10083464ebd5Sriastradh      else
10093464ebd5Sriastradh         COPY_4FV(v->value_float_4, ctx->Fog.ColorUnclamped);
10103464ebd5Sriastradh      break;
10113464ebd5Sriastradh   case GL_COLOR_CLEAR_VALUE:
101201e04c3fSmrg      if (_mesa_get_clamp_fragment_color(ctx, ctx->DrawBuffer)) {
1013af69d88dSmrg         v->value_float_4[0] = CLAMP(ctx->Color.ClearColor.f[0], 0.0F, 1.0F);
1014af69d88dSmrg         v->value_float_4[1] = CLAMP(ctx->Color.ClearColor.f[1], 0.0F, 1.0F);
1015af69d88dSmrg         v->value_float_4[2] = CLAMP(ctx->Color.ClearColor.f[2], 0.0F, 1.0F);
1016af69d88dSmrg         v->value_float_4[3] = CLAMP(ctx->Color.ClearColor.f[3], 0.0F, 1.0F);
1017af69d88dSmrg      } else
1018af69d88dSmrg         COPY_4FV(v->value_float_4, ctx->Color.ClearColor.f);
10193464ebd5Sriastradh      break;
10203464ebd5Sriastradh   case GL_BLEND_COLOR_EXT:
102101e04c3fSmrg      if (_mesa_get_clamp_fragment_color(ctx, ctx->DrawBuffer))
10223464ebd5Sriastradh         COPY_4FV(v->value_float_4, ctx->Color.BlendColor);
10233464ebd5Sriastradh      else
10243464ebd5Sriastradh         COPY_4FV(v->value_float_4, ctx->Color.BlendColorUnclamped);
10253464ebd5Sriastradh      break;
10263464ebd5Sriastradh   case GL_ALPHA_TEST_REF:
102701e04c3fSmrg      if (_mesa_get_clamp_fragment_color(ctx, ctx->DrawBuffer))
10283464ebd5Sriastradh         v->value_float = ctx->Color.AlphaRef;
10293464ebd5Sriastradh      else
10303464ebd5Sriastradh         v->value_float = ctx->Color.AlphaRefUnclamped;
10313464ebd5Sriastradh      break;
10323464ebd5Sriastradh   case GL_MAX_VERTEX_UNIFORM_VECTORS:
1033af69d88dSmrg      v->value_int = ctx->Const.Program[MESA_SHADER_VERTEX].MaxUniformComponents / 4;
10343464ebd5Sriastradh      break;
10353464ebd5Sriastradh
10363464ebd5Sriastradh   case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
1037af69d88dSmrg      v->value_int = ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxUniformComponents / 4;
10383464ebd5Sriastradh      break;
10393464ebd5Sriastradh
10403464ebd5Sriastradh   /* GL_ARB_texture_buffer_object */
10413464ebd5Sriastradh   case GL_TEXTURE_BUFFER_ARB:
10423464ebd5Sriastradh      v->value_int = ctx->Texture.BufferObject->Name;
10433464ebd5Sriastradh      break;
10443464ebd5Sriastradh   case GL_TEXTURE_BINDING_BUFFER_ARB:
10453464ebd5Sriastradh      unit = ctx->Texture.CurrentUnit;
10463464ebd5Sriastradh      v->value_int =
10473464ebd5Sriastradh         ctx->Texture.Unit[unit].CurrentTex[TEXTURE_BUFFER_INDEX]->Name;
10483464ebd5Sriastradh      break;
10493464ebd5Sriastradh   case GL_TEXTURE_BUFFER_DATA_STORE_BINDING_ARB:
10503464ebd5Sriastradh      {
10513464ebd5Sriastradh         struct gl_buffer_object *buf =
10523464ebd5Sriastradh            ctx->Texture.Unit[ctx->Texture.CurrentUnit]
10533464ebd5Sriastradh            .CurrentTex[TEXTURE_BUFFER_INDEX]->BufferObject;
10543464ebd5Sriastradh         v->value_int = buf ? buf->Name : 0;
10553464ebd5Sriastradh      }
10563464ebd5Sriastradh      break;
10573464ebd5Sriastradh   case GL_TEXTURE_BUFFER_FORMAT_ARB:
10583464ebd5Sriastradh      v->value_int = ctx->Texture.Unit[ctx->Texture.CurrentUnit]
10593464ebd5Sriastradh         .CurrentTex[TEXTURE_BUFFER_INDEX]->BufferObjectFormat;
10603464ebd5Sriastradh      break;
10613464ebd5Sriastradh
10623464ebd5Sriastradh   /* GL_ARB_sampler_objects */
10633464ebd5Sriastradh   case GL_SAMPLER_BINDING:
10643464ebd5Sriastradh      {
10653464ebd5Sriastradh         struct gl_sampler_object *samp =
10663464ebd5Sriastradh            ctx->Texture.Unit[ctx->Texture.CurrentUnit].Sampler;
106701e04c3fSmrg         v->value_int = samp ? samp->Name : 0;
1068af69d88dSmrg      }
1069af69d88dSmrg      break;
1070af69d88dSmrg   /* GL_ARB_uniform_buffer_object */
1071af69d88dSmrg   case GL_UNIFORM_BUFFER_BINDING:
1072af69d88dSmrg      v->value_int = ctx->UniformBuffer->Name;
1073af69d88dSmrg      break;
107401e04c3fSmrg   /* GL_ARB_shader_storage_buffer_object */
107501e04c3fSmrg   case GL_SHADER_STORAGE_BUFFER_BINDING:
107601e04c3fSmrg      v->value_int = ctx->ShaderStorageBuffer->Name;
107701e04c3fSmrg      break;
107801e04c3fSmrg   /* GL_ARB_query_buffer_object */
107901e04c3fSmrg   case GL_QUERY_BUFFER_BINDING:
108001e04c3fSmrg      v->value_int = ctx->QueryBuffer->Name;
108101e04c3fSmrg      break;
1082af69d88dSmrg   /* GL_ARB_timer_query */
1083af69d88dSmrg   case GL_TIMESTAMP:
1084af69d88dSmrg      if (ctx->Driver.GetTimestamp) {
1085af69d88dSmrg         v->value_int64 = ctx->Driver.GetTimestamp(ctx);
1086af69d88dSmrg      }
1087af69d88dSmrg      else {
1088af69d88dSmrg         _mesa_problem(ctx, "driver doesn't implement GetTimestamp");
10893464ebd5Sriastradh      }
10903464ebd5Sriastradh      break;
1091af69d88dSmrg   /* GL_KHR_DEBUG */
109201e04c3fSmrg   case GL_DEBUG_OUTPUT:
109301e04c3fSmrg   case GL_DEBUG_OUTPUT_SYNCHRONOUS:
1094af69d88dSmrg   case GL_DEBUG_LOGGED_MESSAGES:
1095af69d88dSmrg   case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH:
1096af69d88dSmrg   case GL_DEBUG_GROUP_STACK_DEPTH:
1097af69d88dSmrg      v->value_int = _mesa_get_debug_state_int(ctx, d->pname);
1098af69d88dSmrg      break;
1099af69d88dSmrg   /* GL_ARB_shader_atomic_counters */
1100af69d88dSmrg   case GL_ATOMIC_COUNTER_BUFFER_BINDING:
1101af69d88dSmrg      if (ctx->AtomicBuffer) {
1102af69d88dSmrg         v->value_int = ctx->AtomicBuffer->Name;
1103af69d88dSmrg      } else {
1104af69d88dSmrg         v->value_int = 0;
1105af69d88dSmrg      }
1106af69d88dSmrg      break;
110701e04c3fSmrg   /* GL 4.3 */
110801e04c3fSmrg   case GL_NUM_SHADING_LANGUAGE_VERSIONS:
110901e04c3fSmrg      v->value_int = _mesa_get_shading_language_version(ctx, -1, NULL);
111001e04c3fSmrg      break;
1111af69d88dSmrg   /* GL_ARB_draw_indirect */
1112af69d88dSmrg   case GL_DRAW_INDIRECT_BUFFER_BINDING:
1113af69d88dSmrg      v->value_int = ctx->DrawIndirectBuffer->Name;
1114af69d88dSmrg      break;
111501e04c3fSmrg   /* GL_ARB_indirect_parameters */
111601e04c3fSmrg   case GL_PARAMETER_BUFFER_BINDING_ARB:
111701e04c3fSmrg      v->value_int = ctx->ParameterBuffer->Name;
111801e04c3fSmrg      break;
1119af69d88dSmrg   /* GL_ARB_separate_shader_objects */
1120af69d88dSmrg   case GL_PROGRAM_PIPELINE_BINDING:
1121af69d88dSmrg      if (ctx->Pipeline.Current) {
1122af69d88dSmrg         v->value_int = ctx->Pipeline.Current->Name;
1123af69d88dSmrg      } else {
1124af69d88dSmrg         v->value_int = 0;
1125af69d88dSmrg      }
1126af69d88dSmrg      break;
112701e04c3fSmrg   /* GL_ARB_compute_shader */
112801e04c3fSmrg   case GL_DISPATCH_INDIRECT_BUFFER_BINDING:
112901e04c3fSmrg      v->value_int = ctx->DispatchIndirectBuffer->Name;
113001e04c3fSmrg      break;
113101e04c3fSmrg   /* GL_ARB_multisample */
113201e04c3fSmrg   case GL_SAMPLES:
113301e04c3fSmrg      v->value_int = _mesa_geometric_samples(ctx->DrawBuffer);
113401e04c3fSmrg      break;
113501e04c3fSmrg   case GL_SAMPLE_BUFFERS:
113601e04c3fSmrg      v->value_int = _mesa_geometric_samples(ctx->DrawBuffer) > 0;
113701e04c3fSmrg      break;
113801e04c3fSmrg   /* GL_EXT_textrue_integer */
113901e04c3fSmrg   case GL_RGBA_INTEGER_MODE_EXT:
114001e04c3fSmrg      v->value_int = (ctx->DrawBuffer->_IntegerBuffers != 0);
114101e04c3fSmrg      break;
114201e04c3fSmrg   /* GL_ATI_meminfo & GL_NVX_gpu_memory_info */
114301e04c3fSmrg   case GL_VBO_FREE_MEMORY_ATI:
114401e04c3fSmrg   case GL_TEXTURE_FREE_MEMORY_ATI:
114501e04c3fSmrg   case GL_RENDERBUFFER_FREE_MEMORY_ATI:
114601e04c3fSmrg   case GL_GPU_MEMORY_INFO_DEDICATED_VIDMEM_NVX:
114701e04c3fSmrg   case GL_GPU_MEMORY_INFO_TOTAL_AVAILABLE_MEMORY_NVX:
114801e04c3fSmrg   case GL_GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX:
114901e04c3fSmrg   case GL_GPU_MEMORY_INFO_EVICTION_COUNT_NVX:
115001e04c3fSmrg   case GL_GPU_MEMORY_INFO_EVICTED_MEMORY_NVX:
115101e04c3fSmrg      {
115201e04c3fSmrg         struct gl_memory_info info;
115301e04c3fSmrg
115401e04c3fSmrg         ctx->Driver.QueryMemoryInfo(ctx, &info);
115501e04c3fSmrg
115601e04c3fSmrg         if (d->pname == GL_GPU_MEMORY_INFO_DEDICATED_VIDMEM_NVX)
115701e04c3fSmrg            v->value_int = info.total_device_memory;
115801e04c3fSmrg         else if (d->pname == GL_GPU_MEMORY_INFO_TOTAL_AVAILABLE_MEMORY_NVX)
115901e04c3fSmrg            v->value_int = info.total_device_memory +
116001e04c3fSmrg                           info.total_staging_memory;
116101e04c3fSmrg         else if (d->pname == GL_GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX)
116201e04c3fSmrg            v->value_int = info.avail_device_memory;
116301e04c3fSmrg         else if (d->pname == GL_GPU_MEMORY_INFO_EVICTION_COUNT_NVX)
116401e04c3fSmrg            v->value_int = info.nr_device_memory_evictions;
116501e04c3fSmrg         else if (d->pname == GL_GPU_MEMORY_INFO_EVICTED_MEMORY_NVX)
116601e04c3fSmrg            v->value_int = info.device_memory_evicted;
116701e04c3fSmrg         else {
116801e04c3fSmrg            /* ATI free memory enums.
116901e04c3fSmrg             *
117001e04c3fSmrg             * Since the GPU memory is (usually) page-table based, every two
117101e04c3fSmrg             * consecutive elements are equal. From the GL_ATI_meminfo
117201e04c3fSmrg             * specification:
117301e04c3fSmrg             *
117401e04c3fSmrg             *    "param[0] - total memory free in the pool
117501e04c3fSmrg             *     param[1] - largest available free block in the pool
117601e04c3fSmrg             *     param[2] - total auxiliary memory free
117701e04c3fSmrg             *     param[3] - largest auxiliary free block"
117801e04c3fSmrg             *
117901e04c3fSmrg             * All three (VBO, TEXTURE, RENDERBUFFER) queries return
118001e04c3fSmrg             * the same numbers here.
118101e04c3fSmrg             */
118201e04c3fSmrg            v->value_int_4[0] = info.avail_device_memory;
118301e04c3fSmrg            v->value_int_4[1] = info.avail_device_memory;
118401e04c3fSmrg            v->value_int_4[2] = info.avail_staging_memory;
118501e04c3fSmrg            v->value_int_4[3] = info.avail_staging_memory;
118601e04c3fSmrg         }
118701e04c3fSmrg      }
118801e04c3fSmrg      break;
118901e04c3fSmrg
119001e04c3fSmrg   /* GL_ARB_get_program_binary */
119101e04c3fSmrg   case GL_PROGRAM_BINARY_FORMATS:
119201e04c3fSmrg      assert(ctx->Const.NumProgramBinaryFormats <= 1);
119301e04c3fSmrg      v->value_int_n.n = MIN2(ctx->Const.NumProgramBinaryFormats, 1);
119401e04c3fSmrg      if (ctx->Const.NumProgramBinaryFormats > 0) {
119501e04c3fSmrg         v->value_int_n.ints[0] = GL_PROGRAM_BINARY_FORMAT_MESA;
119601e04c3fSmrg      }
119701e04c3fSmrg      break;
119801e04c3fSmrg   /* GL_EXT_disjoint_timer_query */
119901e04c3fSmrg   case GL_GPU_DISJOINT_EXT:
120001e04c3fSmrg      {
120101e04c3fSmrg         simple_mtx_lock(&ctx->Shared->Mutex);
120201e04c3fSmrg         v->value_int = ctx->Shared->DisjointOperation;
120301e04c3fSmrg         /* Reset state as expected by the spec. */
120401e04c3fSmrg         ctx->Shared->DisjointOperation = false;
120501e04c3fSmrg         simple_mtx_unlock(&ctx->Shared->Mutex);
120601e04c3fSmrg      }
120701e04c3fSmrg      break;
120801e04c3fSmrg   /* GL_ARB_sample_locations */
120901e04c3fSmrg   case GL_SAMPLE_LOCATION_SUBPIXEL_BITS_ARB:
121001e04c3fSmrg   case GL_SAMPLE_LOCATION_PIXEL_GRID_WIDTH_ARB:
121101e04c3fSmrg   case GL_SAMPLE_LOCATION_PIXEL_GRID_HEIGHT_ARB:
121201e04c3fSmrg      {
121301e04c3fSmrg         GLuint bits, width, height;
121401e04c3fSmrg
121501e04c3fSmrg         if (ctx->NewState & _NEW_BUFFERS)
121601e04c3fSmrg            _mesa_update_state(ctx);
121701e04c3fSmrg
121801e04c3fSmrg         if (ctx->DrawBuffer->_Status != GL_FRAMEBUFFER_COMPLETE) {
121901e04c3fSmrg            v->value_uint = 0;
122001e04c3fSmrg            break;
122101e04c3fSmrg         }
122201e04c3fSmrg
122301e04c3fSmrg         ctx->Driver.GetProgrammableSampleCaps(ctx, ctx->DrawBuffer,
122401e04c3fSmrg                                               &bits, &width, &height);
122501e04c3fSmrg
122601e04c3fSmrg         if (d->pname == GL_SAMPLE_LOCATION_PIXEL_GRID_WIDTH_ARB)
122701e04c3fSmrg            v->value_uint = width;
122801e04c3fSmrg         else if (d->pname == GL_SAMPLE_LOCATION_PIXEL_GRID_HEIGHT_ARB)
122901e04c3fSmrg            v->value_uint = height;
123001e04c3fSmrg         else
123101e04c3fSmrg            v->value_uint = bits;
123201e04c3fSmrg      }
123301e04c3fSmrg      break;
123401e04c3fSmrg   case GL_PROGRAMMABLE_SAMPLE_LOCATION_TABLE_SIZE_ARB:
123501e04c3fSmrg      v->value_uint = MAX_SAMPLE_LOCATION_TABLE_SIZE;
123601e04c3fSmrg      break;
123701e04c3fSmrg
123801e04c3fSmrg   /* GL_AMD_framebuffer_multisample_advanced */
123901e04c3fSmrg   case GL_SUPPORTED_MULTISAMPLE_MODES_AMD:
124001e04c3fSmrg      v->value_int_n.n = ctx->Const.NumSupportedMultisampleModes * 3;
124101e04c3fSmrg      memcpy(v->value_int_n.ints, ctx->Const.SupportedMultisampleModes,
124201e04c3fSmrg             v->value_int_n.n * sizeof(GLint));
124301e04c3fSmrg      break;
1244af69d88dSmrg   }
12453464ebd5Sriastradh}
12463464ebd5Sriastradh
12473464ebd5Sriastradh/**
12483464ebd5Sriastradh * Check extra constraints on a struct value_desc descriptor
12493464ebd5Sriastradh *
12503464ebd5Sriastradh * If a struct value_desc has a non-NULL extra pointer, it means that
12513464ebd5Sriastradh * there are a number of extra constraints to check or actions to
12523464ebd5Sriastradh * perform.  The extras is just an integer array where each integer
12533464ebd5Sriastradh * encode different constraints or actions.
12543464ebd5Sriastradh *
12553464ebd5Sriastradh * \param ctx current context
12563464ebd5Sriastradh * \param func name of calling glGet*v() function for error reporting
12573464ebd5Sriastradh * \param d the struct value_desc that has the extra constraints
12583464ebd5Sriastradh *
1259af69d88dSmrg * \return GL_FALSE if all of the constraints were not satisfied,
12603464ebd5Sriastradh *     otherwise GL_TRUE.
12617117f1b4Smrg */
12623464ebd5Sriastradhstatic GLboolean
12633464ebd5Sriastradhcheck_extra(struct gl_context *ctx, const char *func, const struct value_desc *d)
12643464ebd5Sriastradh{
1265af69d88dSmrg   const GLuint version = ctx->Version;
1266af69d88dSmrg   GLboolean api_check = GL_FALSE;
1267af69d88dSmrg   GLboolean api_found = GL_FALSE;
12683464ebd5Sriastradh   const int *e;
12693464ebd5Sriastradh
1270af69d88dSmrg   for (e = d->extra; *e != EXTRA_END; e++) {
12713464ebd5Sriastradh      switch (*e) {
12723464ebd5Sriastradh      case EXTRA_VERSION_30:
1273af69d88dSmrg         api_check = GL_TRUE;
1274af69d88dSmrg         if (version >= 30)
1275af69d88dSmrg            api_found = GL_TRUE;
127601e04c3fSmrg         break;
12773464ebd5Sriastradh      case EXTRA_VERSION_31:
1278af69d88dSmrg         api_check = GL_TRUE;
1279af69d88dSmrg         if (version >= 31)
1280af69d88dSmrg            api_found = GL_TRUE;
128101e04c3fSmrg         break;
12823464ebd5Sriastradh      case EXTRA_VERSION_32:
1283af69d88dSmrg         api_check = GL_TRUE;
1284af69d88dSmrg         if (version >= 32)
1285af69d88dSmrg            api_found = GL_TRUE;
128601e04c3fSmrg         break;
128701e04c3fSmrg      case EXTRA_VERSION_40:
128801e04c3fSmrg         api_check = GL_TRUE;
128901e04c3fSmrg         if (version >= 40)
129001e04c3fSmrg            api_found = GL_TRUE;
129101e04c3fSmrg         break;
129201e04c3fSmrg      case EXTRA_VERSION_43:
129301e04c3fSmrg         api_check = TRUE;
129401e04c3fSmrg         if (_mesa_is_desktop_gl(ctx) && version >= 43)
129501e04c3fSmrg            api_found = GL_TRUE;
129601e04c3fSmrg         break;
12973464ebd5Sriastradh      case EXTRA_NEW_FRAG_CLAMP:
12983464ebd5Sriastradh         if (ctx->NewState & (_NEW_BUFFERS | _NEW_FRAG_CLAMP))
12993464ebd5Sriastradh            _mesa_update_state(ctx);
13003464ebd5Sriastradh         break;
1301af69d88dSmrg      case EXTRA_API_ES2:
1302af69d88dSmrg         api_check = GL_TRUE;
1303af69d88dSmrg         if (ctx->API == API_OPENGLES2)
1304af69d88dSmrg            api_found = GL_TRUE;
130501e04c3fSmrg         break;
1306af69d88dSmrg      case EXTRA_API_ES3:
1307af69d88dSmrg         api_check = GL_TRUE;
1308af69d88dSmrg         if (_mesa_is_gles3(ctx))
1309af69d88dSmrg            api_found = GL_TRUE;
131001e04c3fSmrg         break;
131101e04c3fSmrg      case EXTRA_API_ES31:
131201e04c3fSmrg         api_check = GL_TRUE;
131301e04c3fSmrg         if (_mesa_is_gles31(ctx))
131401e04c3fSmrg            api_found = GL_TRUE;
131501e04c3fSmrg         break;
131601e04c3fSmrg      case EXTRA_API_ES32:
131701e04c3fSmrg         api_check = GL_TRUE;
131801e04c3fSmrg         if (_mesa_is_gles32(ctx))
131901e04c3fSmrg            api_found = GL_TRUE;
132001e04c3fSmrg         break;
1321af69d88dSmrg      case EXTRA_API_GL:
1322af69d88dSmrg         api_check = GL_TRUE;
1323af69d88dSmrg         if (_mesa_is_desktop_gl(ctx))
1324af69d88dSmrg            api_found = GL_TRUE;
132501e04c3fSmrg         break;
1326af69d88dSmrg      case EXTRA_API_GL_CORE:
1327af69d88dSmrg         api_check = GL_TRUE;
1328af69d88dSmrg         if (ctx->API == API_OPENGL_CORE)
1329af69d88dSmrg            api_found = GL_TRUE;
133001e04c3fSmrg         break;
13313464ebd5Sriastradh      case EXTRA_NEW_BUFFERS:
133201e04c3fSmrg         if (ctx->NewState & _NEW_BUFFERS)
133301e04c3fSmrg            _mesa_update_state(ctx);
133401e04c3fSmrg         break;
13353464ebd5Sriastradh      case EXTRA_FLUSH_CURRENT:
133601e04c3fSmrg         FLUSH_CURRENT(ctx, 0);
133701e04c3fSmrg         break;
13383464ebd5Sriastradh      case EXTRA_VALID_DRAW_BUFFER:
133901e04c3fSmrg         if (d->pname - GL_DRAW_BUFFER0_ARB >= ctx->Const.MaxDrawBuffers) {
134001e04c3fSmrg            _mesa_error(ctx, GL_INVALID_OPERATION, "%s(draw buffer %u)",
134101e04c3fSmrg                        func, d->pname - GL_DRAW_BUFFER0_ARB);
134201e04c3fSmrg            return GL_FALSE;
134301e04c3fSmrg         }
134401e04c3fSmrg         break;
13453464ebd5Sriastradh      case EXTRA_VALID_TEXTURE_UNIT:
134601e04c3fSmrg         if (ctx->Texture.CurrentUnit >= ctx->Const.MaxTextureCoordUnits) {
134701e04c3fSmrg            _mesa_error(ctx, GL_INVALID_OPERATION, "%s(texture %u)",
134801e04c3fSmrg                        func, ctx->Texture.CurrentUnit);
134901e04c3fSmrg            return GL_FALSE;
135001e04c3fSmrg         }
135101e04c3fSmrg         break;
1352af69d88dSmrg      case EXTRA_VALID_CLIP_DISTANCE:
135301e04c3fSmrg         if (d->pname - GL_CLIP_DISTANCE0 >= ctx->Const.MaxClipPlanes) {
135401e04c3fSmrg            _mesa_error(ctx, GL_INVALID_ENUM, "%s(clip distance %u)",
135501e04c3fSmrg                        func, d->pname - GL_CLIP_DISTANCE0);
135601e04c3fSmrg            return GL_FALSE;
135701e04c3fSmrg         }
135801e04c3fSmrg         break;
1359af69d88dSmrg      case EXTRA_GLSL_130:
1360af69d88dSmrg         api_check = GL_TRUE;
1361af69d88dSmrg         if (ctx->Const.GLSLVersion >= 130)
1362af69d88dSmrg            api_found = GL_TRUE;
136301e04c3fSmrg         break;
136401e04c3fSmrg      case EXTRA_EXT_UBO_GS:
1365af69d88dSmrg         api_check = GL_TRUE;
136601e04c3fSmrg         if (ctx->Extensions.ARB_uniform_buffer_object &&
136701e04c3fSmrg            _mesa_has_geometry_shaders(ctx))
136801e04c3fSmrg            api_found = GL_TRUE;
136901e04c3fSmrg         break;
137001e04c3fSmrg      case EXTRA_EXT_ATOMICS_GS:
137101e04c3fSmrg         api_check = GL_TRUE;
137201e04c3fSmrg         if (ctx->Extensions.ARB_shader_atomic_counters &&
137301e04c3fSmrg            _mesa_has_geometry_shaders(ctx))
137401e04c3fSmrg            api_found = GL_TRUE;
137501e04c3fSmrg         break;
137601e04c3fSmrg      case EXTRA_EXT_SHADER_IMAGE_GS:
137701e04c3fSmrg         api_check = GL_TRUE;
137801e04c3fSmrg         if (ctx->Extensions.ARB_shader_image_load_store &&
137901e04c3fSmrg            _mesa_has_geometry_shaders(ctx))
138001e04c3fSmrg            api_found = GL_TRUE;
138101e04c3fSmrg         break;
138201e04c3fSmrg      case EXTRA_EXT_ATOMICS_TESS:
138301e04c3fSmrg         api_check = GL_TRUE;
138401e04c3fSmrg         api_found = ctx->Extensions.ARB_shader_atomic_counters &&
138501e04c3fSmrg                     _mesa_has_tessellation(ctx);
138601e04c3fSmrg         break;
138701e04c3fSmrg      case EXTRA_EXT_SHADER_IMAGE_TESS:
138801e04c3fSmrg         api_check = GL_TRUE;
138901e04c3fSmrg         api_found = ctx->Extensions.ARB_shader_image_load_store &&
139001e04c3fSmrg                     _mesa_has_tessellation(ctx);
139101e04c3fSmrg         break;
139201e04c3fSmrg      case EXTRA_EXT_SSBO_GS:
139301e04c3fSmrg         api_check = GL_TRUE;
139401e04c3fSmrg         if (ctx->Extensions.ARB_shader_storage_buffer_object &&
139501e04c3fSmrg            _mesa_has_geometry_shaders(ctx))
139601e04c3fSmrg            api_found = GL_TRUE;
1397af69d88dSmrg         break;
139801e04c3fSmrg      case EXTRA_EXT_FB_NO_ATTACH_GS:
1399af69d88dSmrg         api_check = GL_TRUE;
140001e04c3fSmrg         if (ctx->Extensions.ARB_framebuffer_no_attachments &&
140101e04c3fSmrg            (_mesa_is_desktop_gl(ctx) ||
140201e04c3fSmrg            _mesa_has_OES_geometry_shader(ctx)))
140301e04c3fSmrg            api_found = GL_TRUE;
1404af69d88dSmrg         break;
140501e04c3fSmrg      case EXTRA_EXT_ES_GS:
1406af69d88dSmrg         api_check = GL_TRUE;
140701e04c3fSmrg         if (_mesa_has_OES_geometry_shader(ctx))
140801e04c3fSmrg            api_found = GL_TRUE;
140901e04c3fSmrg         break;
141001e04c3fSmrg      case EXTRA_EXT_PROVOKING_VERTEX_32:
141101e04c3fSmrg         api_check = TRUE;
141201e04c3fSmrg         if (ctx->API == API_OPENGL_COMPAT || version == 32)
141301e04c3fSmrg            api_found = ctx->Extensions.EXT_provoking_vertex;
1414af69d88dSmrg         break;
14153464ebd5Sriastradh      case EXTRA_END:
141601e04c3fSmrg         break;
14173464ebd5Sriastradh      default: /* *e is a offset into the extension struct */
141801e04c3fSmrg         api_check = GL_TRUE;
141901e04c3fSmrg         if (*(GLboolean *) ((char *) &ctx->Extensions + *e))
142001e04c3fSmrg            api_found = GL_TRUE;
142101e04c3fSmrg         break;
14223464ebd5Sriastradh      }
1423af69d88dSmrg   }
14243464ebd5Sriastradh
1425af69d88dSmrg   if (api_check && !api_found) {
14263464ebd5Sriastradh      _mesa_error(ctx, GL_INVALID_ENUM, "%s(pname=%s)", func,
142701e04c3fSmrg                  _mesa_enum_to_string(d->pname));
14283464ebd5Sriastradh      return GL_FALSE;
14297117f1b4Smrg   }
14307117f1b4Smrg
14313464ebd5Sriastradh   return GL_TRUE;
14323464ebd5Sriastradh}
14333464ebd5Sriastradh
14343464ebd5Sriastradhstatic const struct value_desc error_value =
14353464ebd5Sriastradh   { 0, 0, TYPE_INVALID, NO_OFFSET, NO_EXTRA };
14363464ebd5Sriastradh
14373464ebd5Sriastradh/**
14383464ebd5Sriastradh * Find the struct value_desc corresponding to the enum 'pname'.
143901e04c3fSmrg *
14403464ebd5Sriastradh * We hash the enum value to get an index into the 'table' array,
14413464ebd5Sriastradh * which holds the index in the 'values' array of struct value_desc.
14423464ebd5Sriastradh * Once we've found the entry, we do the extra checks, if any, then
14433464ebd5Sriastradh * look up the value and return a pointer to it.
14443464ebd5Sriastradh *
14453464ebd5Sriastradh * If the value has to be computed (for example, it's the result of a
14463464ebd5Sriastradh * function call or we need to add 1 to it), we use the tmp 'v' to
14473464ebd5Sriastradh * store the result.
144801e04c3fSmrg *
14493464ebd5Sriastradh * \param func name of glGet*v() func for error reporting
14503464ebd5Sriastradh * \param pname the enum value we're looking up
14513464ebd5Sriastradh * \param p is were we return the pointer to the value
14523464ebd5Sriastradh * \param v a tmp union value variable in the calling glGet*v() function
14533464ebd5Sriastradh *
14543464ebd5Sriastradh * \return the struct value_desc corresponding to the enum or a struct
14553464ebd5Sriastradh *     value_desc of TYPE_INVALID if not found.  This lets the calling
14563464ebd5Sriastradh *     glGet*v() function jump right into a switch statement and
14573464ebd5Sriastradh *     handle errors there instead of having to check for NULL.
14587117f1b4Smrg */
14593464ebd5Sriastradhstatic const struct value_desc *
14603464ebd5Sriastradhfind_value(const char *func, GLenum pname, void **p, union value *v)
14613464ebd5Sriastradh{
14623464ebd5Sriastradh   GET_CURRENT_CONTEXT(ctx);
14633464ebd5Sriastradh   int mask, hash;
14643464ebd5Sriastradh   const struct value_desc *d;
1465af69d88dSmrg   int api;
14663464ebd5Sriastradh
1467af69d88dSmrg   api = ctx->API;
1468af69d88dSmrg   /* We index into the table_set[] list of per-API hash tables using the API's
1469af69d88dSmrg    * value in the gl_api enum. Since GLES 3 doesn't have an API_OPENGL* enum
1470af69d88dSmrg    * value since it's compatible with GLES2 its entry in table_set[] is at the
1471af69d88dSmrg    * end.
1472af69d88dSmrg    */
147301e04c3fSmrg   STATIC_ASSERT(ARRAY_SIZE(table_set) == API_OPENGL_LAST + 4);
147401e04c3fSmrg   if (ctx->API == API_OPENGLES2) {
147501e04c3fSmrg      if (ctx->Version >= 32)
147601e04c3fSmrg         api = API_OPENGL_LAST + 3;
147701e04c3fSmrg      else if (ctx->Version >= 31)
147801e04c3fSmrg         api = API_OPENGL_LAST + 2;
147901e04c3fSmrg      else if (ctx->Version >= 30)
148001e04c3fSmrg         api = API_OPENGL_LAST + 1;
1481af69d88dSmrg   }
148201e04c3fSmrg   mask = ARRAY_SIZE(table(api)) - 1;
14833464ebd5Sriastradh   hash = (pname * prime_factor);
14843464ebd5Sriastradh   while (1) {
1485af69d88dSmrg      int idx = table(api)[hash & mask];
14863464ebd5Sriastradh
14873464ebd5Sriastradh      /* If the enum isn't valid, the hash walk ends with index 0,
1488af69d88dSmrg       * pointing to the first entry of values[] which doesn't hold
1489af69d88dSmrg       * any valid enum. */
1490af69d88dSmrg      if (unlikely(idx == 0)) {
1491af69d88dSmrg         _mesa_error(ctx, GL_INVALID_ENUM, "%s(pname=%s)", func,
149201e04c3fSmrg               _mesa_enum_to_string(pname));
1493af69d88dSmrg         return &error_value;
14943464ebd5Sriastradh      }
14953464ebd5Sriastradh
1496af69d88dSmrg      d = &values[idx];
14973464ebd5Sriastradh      if (likely(d->pname == pname))
1498af69d88dSmrg         break;
14993464ebd5Sriastradh
15003464ebd5Sriastradh      hash += prime_step;
15017117f1b4Smrg   }
15027117f1b4Smrg
15033464ebd5Sriastradh   if (unlikely(d->extra && !check_extra(ctx, func, d)))
15043464ebd5Sriastradh      return &error_value;
15053464ebd5Sriastradh
15063464ebd5Sriastradh   switch (d->location) {
15073464ebd5Sriastradh   case LOC_BUFFER:
15083464ebd5Sriastradh      *p = ((char *) ctx->DrawBuffer + d->offset);
15093464ebd5Sriastradh      return d;
15103464ebd5Sriastradh   case LOC_CONTEXT:
15113464ebd5Sriastradh      *p = ((char *) ctx + d->offset);
15123464ebd5Sriastradh      return d;
15133464ebd5Sriastradh   case LOC_ARRAY:
1514af69d88dSmrg      *p = ((char *) ctx->Array.VAO + d->offset);
15153464ebd5Sriastradh      return d;
15163464ebd5Sriastradh   case LOC_TEXUNIT:
151701e04c3fSmrg      if (ctx->Texture.CurrentUnit < ARRAY_SIZE(ctx->Texture.FixedFuncUnit)) {
151801e04c3fSmrg         unsigned index = ctx->Texture.CurrentUnit;
151901e04c3fSmrg         *p = ((char *)&ctx->Texture.FixedFuncUnit[index] + d->offset);
152001e04c3fSmrg      }
15213464ebd5Sriastradh      return d;
15223464ebd5Sriastradh   case LOC_CUSTOM:
15233464ebd5Sriastradh      find_custom_value(ctx, d, v);
15243464ebd5Sriastradh      *p = v;
15253464ebd5Sriastradh      return d;
15263464ebd5Sriastradh   default:
15273464ebd5Sriastradh      assert(0);
15283464ebd5Sriastradh      break;
15293464ebd5Sriastradh   }
15303464ebd5Sriastradh
15313464ebd5Sriastradh   /* silence warning */
15323464ebd5Sriastradh   return &error_value;
15333464ebd5Sriastradh}
15343464ebd5Sriastradh
15353464ebd5Sriastradhstatic const int transpose[] = {
15363464ebd5Sriastradh   0, 4,  8, 12,
15373464ebd5Sriastradh   1, 5,  9, 13,
15383464ebd5Sriastradh   2, 6, 10, 14,
15393464ebd5Sriastradh   3, 7, 11, 15
15403464ebd5Sriastradh};
15417117f1b4Smrg
154201e04c3fSmrgstatic GLsizei
154301e04c3fSmrgget_value_size(enum value_type type, const union value *v)
154401e04c3fSmrg{
154501e04c3fSmrg   switch (type) {
154601e04c3fSmrg   case TYPE_INVALID:
154701e04c3fSmrg      return 0;
154801e04c3fSmrg   case TYPE_CONST:
154901e04c3fSmrg   case TYPE_UINT:
155001e04c3fSmrg   case TYPE_INT:
155101e04c3fSmrg      return sizeof(GLint);
155201e04c3fSmrg   case TYPE_INT_2:
155301e04c3fSmrg   case TYPE_UINT_2:
155401e04c3fSmrg      return sizeof(GLint) * 2;
155501e04c3fSmrg   case TYPE_INT_3:
155601e04c3fSmrg   case TYPE_UINT_3:
155701e04c3fSmrg      return sizeof(GLint) * 3;
155801e04c3fSmrg   case TYPE_INT_4:
155901e04c3fSmrg   case TYPE_UINT_4:
156001e04c3fSmrg      return sizeof(GLint) * 4;
156101e04c3fSmrg   case TYPE_INT_N:
156201e04c3fSmrg      return sizeof(GLint) * v->value_int_n.n;
156301e04c3fSmrg   case TYPE_INT64:
156401e04c3fSmrg      return sizeof(GLint64);
156501e04c3fSmrg      break;
156601e04c3fSmrg   case TYPE_ENUM16:
156701e04c3fSmrg      return sizeof(GLenum16);
156801e04c3fSmrg   case TYPE_ENUM:
156901e04c3fSmrg      return sizeof(GLenum);
157001e04c3fSmrg   case TYPE_ENUM_2:
157101e04c3fSmrg      return sizeof(GLenum) * 2;
157201e04c3fSmrg   case TYPE_BOOLEAN:
157301e04c3fSmrg      return sizeof(GLboolean);
157401e04c3fSmrg   case TYPE_UBYTE:
157501e04c3fSmrg      return sizeof(GLubyte);
157601e04c3fSmrg   case TYPE_SHORT:
157701e04c3fSmrg      return sizeof(GLshort);
157801e04c3fSmrg   case TYPE_BIT_0:
157901e04c3fSmrg   case TYPE_BIT_1:
158001e04c3fSmrg   case TYPE_BIT_2:
158101e04c3fSmrg   case TYPE_BIT_3:
158201e04c3fSmrg   case TYPE_BIT_4:
158301e04c3fSmrg   case TYPE_BIT_5:
158401e04c3fSmrg   case TYPE_BIT_6:
158501e04c3fSmrg   case TYPE_BIT_7:
158601e04c3fSmrg      return 1;
158701e04c3fSmrg   case TYPE_FLOAT:
158801e04c3fSmrg   case TYPE_FLOATN:
158901e04c3fSmrg      return sizeof(GLfloat);
159001e04c3fSmrg   case TYPE_FLOAT_2:
159101e04c3fSmrg   case TYPE_FLOATN_2:
159201e04c3fSmrg      return sizeof(GLfloat) * 2;
159301e04c3fSmrg   case TYPE_FLOAT_3:
159401e04c3fSmrg   case TYPE_FLOATN_3:
159501e04c3fSmrg      return sizeof(GLfloat) * 3;
159601e04c3fSmrg   case TYPE_FLOAT_4:
159701e04c3fSmrg   case TYPE_FLOATN_4:
159801e04c3fSmrg      return sizeof(GLfloat) * 4;
159901e04c3fSmrg   case TYPE_FLOAT_8:
160001e04c3fSmrg      return sizeof(GLfloat) * 8;
160101e04c3fSmrg   case TYPE_DOUBLEN:
160201e04c3fSmrg      return sizeof(GLdouble);
160301e04c3fSmrg   case TYPE_DOUBLEN_2:
160401e04c3fSmrg      return sizeof(GLdouble) * 2;
160501e04c3fSmrg   case TYPE_MATRIX:
160601e04c3fSmrg      return sizeof (GLfloat) * 16;
160701e04c3fSmrg   case TYPE_MATRIX_T:
160801e04c3fSmrg      return sizeof (GLfloat) * 16;
160901e04c3fSmrg   default:
161001e04c3fSmrg      return -1;
161101e04c3fSmrg   }
161201e04c3fSmrg}
161301e04c3fSmrg
16147117f1b4Smrgvoid GLAPIENTRY
16153464ebd5Sriastradh_mesa_GetBooleanv(GLenum pname, GLboolean *params)
16167117f1b4Smrg{
16173464ebd5Sriastradh   const struct value_desc *d;
16183464ebd5Sriastradh   union value v;
16193464ebd5Sriastradh   GLmatrix *m;
16203464ebd5Sriastradh   int shift, i;
16213464ebd5Sriastradh   void *p;
16227117f1b4Smrg
16233464ebd5Sriastradh   d = find_value("glGetBooleanv", pname, &p, &v);
16243464ebd5Sriastradh   switch (d->type) {
16253464ebd5Sriastradh   case TYPE_INVALID:
16263464ebd5Sriastradh      break;
16273464ebd5Sriastradh   case TYPE_CONST:
16283464ebd5Sriastradh      params[0] = INT_TO_BOOLEAN(d->offset);
16293464ebd5Sriastradh      break;
16307117f1b4Smrg
163101e04c3fSmrg   case TYPE_FLOAT_8:
163201e04c3fSmrg      params[7] = FLOAT_TO_BOOLEAN(((GLfloat *) p)[7]);
163301e04c3fSmrg      params[6] = FLOAT_TO_BOOLEAN(((GLfloat *) p)[6]);
163401e04c3fSmrg      params[5] = FLOAT_TO_BOOLEAN(((GLfloat *) p)[5]);
163501e04c3fSmrg      params[4] = FLOAT_TO_BOOLEAN(((GLfloat *) p)[4]);
16363464ebd5Sriastradh   case TYPE_FLOAT_4:
16373464ebd5Sriastradh   case TYPE_FLOATN_4:
16383464ebd5Sriastradh      params[3] = FLOAT_TO_BOOLEAN(((GLfloat *) p)[3]);
16393464ebd5Sriastradh   case TYPE_FLOAT_3:
16403464ebd5Sriastradh   case TYPE_FLOATN_3:
16413464ebd5Sriastradh      params[2] = FLOAT_TO_BOOLEAN(((GLfloat *) p)[2]);
16423464ebd5Sriastradh   case TYPE_FLOAT_2:
16433464ebd5Sriastradh   case TYPE_FLOATN_2:
16443464ebd5Sriastradh      params[1] = FLOAT_TO_BOOLEAN(((GLfloat *) p)[1]);
16453464ebd5Sriastradh   case TYPE_FLOAT:
16463464ebd5Sriastradh   case TYPE_FLOATN:
16473464ebd5Sriastradh      params[0] = FLOAT_TO_BOOLEAN(((GLfloat *) p)[0]);
16483464ebd5Sriastradh      break;
16497117f1b4Smrg
1650af69d88dSmrg   case TYPE_DOUBLEN_2:
1651af69d88dSmrg      params[1] = FLOAT_TO_BOOLEAN(((GLdouble *) p)[1]);
16523464ebd5Sriastradh   case TYPE_DOUBLEN:
16533464ebd5Sriastradh      params[0] = FLOAT_TO_BOOLEAN(((GLdouble *) p)[0]);
16543464ebd5Sriastradh      break;
16557117f1b4Smrg
16563464ebd5Sriastradh   case TYPE_INT_4:
165701e04c3fSmrg   case TYPE_UINT_4:
16583464ebd5Sriastradh      params[3] = INT_TO_BOOLEAN(((GLint *) p)[3]);
16593464ebd5Sriastradh   case TYPE_INT_3:
166001e04c3fSmrg   case TYPE_UINT_3:
16613464ebd5Sriastradh      params[2] = INT_TO_BOOLEAN(((GLint *) p)[2]);
16623464ebd5Sriastradh   case TYPE_INT_2:
166301e04c3fSmrg   case TYPE_UINT_2:
16643464ebd5Sriastradh   case TYPE_ENUM_2:
16653464ebd5Sriastradh      params[1] = INT_TO_BOOLEAN(((GLint *) p)[1]);
16663464ebd5Sriastradh   case TYPE_INT:
166701e04c3fSmrg   case TYPE_UINT:
16683464ebd5Sriastradh   case TYPE_ENUM:
16693464ebd5Sriastradh      params[0] = INT_TO_BOOLEAN(((GLint *) p)[0]);
16703464ebd5Sriastradh      break;
16713464ebd5Sriastradh
167201e04c3fSmrg   case TYPE_ENUM16:
167301e04c3fSmrg      params[0] = INT_TO_BOOLEAN(((GLenum16 *) p)[0]);
167401e04c3fSmrg      break;
167501e04c3fSmrg
16763464ebd5Sriastradh   case TYPE_INT_N:
16773464ebd5Sriastradh      for (i = 0; i < v.value_int_n.n; i++)
167801e04c3fSmrg         params[i] = INT_TO_BOOLEAN(v.value_int_n.ints[i]);
16793464ebd5Sriastradh      break;
16803464ebd5Sriastradh
16813464ebd5Sriastradh   case TYPE_INT64:
16823464ebd5Sriastradh      params[0] = INT64_TO_BOOLEAN(((GLint64 *) p)[0]);
16833464ebd5Sriastradh      break;
16843464ebd5Sriastradh
16853464ebd5Sriastradh   case TYPE_BOOLEAN:
16863464ebd5Sriastradh      params[0] = ((GLboolean*) p)[0];
168701e04c3fSmrg      break;
168801e04c3fSmrg
168901e04c3fSmrg   case TYPE_UBYTE:
169001e04c3fSmrg      params[0] = INT_TO_BOOLEAN(((GLubyte *) p)[0]);
169101e04c3fSmrg      break;
169201e04c3fSmrg
169301e04c3fSmrg   case TYPE_SHORT:
169401e04c3fSmrg      params[0] = INT_TO_BOOLEAN(((GLshort *) p)[0]);
169501e04c3fSmrg      break;
16963464ebd5Sriastradh
16973464ebd5Sriastradh   case TYPE_MATRIX:
16983464ebd5Sriastradh      m = *(GLmatrix **) p;
16993464ebd5Sriastradh      for (i = 0; i < 16; i++)
170001e04c3fSmrg         params[i] = FLOAT_TO_BOOLEAN(m->m[i]);
17013464ebd5Sriastradh      break;
17023464ebd5Sriastradh
17033464ebd5Sriastradh   case TYPE_MATRIX_T:
17043464ebd5Sriastradh      m = *(GLmatrix **) p;
17053464ebd5Sriastradh      for (i = 0; i < 16; i++)
170601e04c3fSmrg         params[i] = FLOAT_TO_BOOLEAN(m->m[transpose[i]]);
17073464ebd5Sriastradh      break;
17083464ebd5Sriastradh
17093464ebd5Sriastradh   case TYPE_BIT_0:
17103464ebd5Sriastradh   case TYPE_BIT_1:
17113464ebd5Sriastradh   case TYPE_BIT_2:
17123464ebd5Sriastradh   case TYPE_BIT_3:
17133464ebd5Sriastradh   case TYPE_BIT_4:
17143464ebd5Sriastradh   case TYPE_BIT_5:
1715af69d88dSmrg   case TYPE_BIT_6:
1716af69d88dSmrg   case TYPE_BIT_7:
17173464ebd5Sriastradh      shift = d->type - TYPE_BIT_0;
17183464ebd5Sriastradh      params[0] = (*(GLbitfield *) p >> shift) & 1;
17193464ebd5Sriastradh      break;
17204a49301eSmrg   }
17214a49301eSmrg}
17227117f1b4Smrg
17237117f1b4Smrgvoid GLAPIENTRY
17243464ebd5Sriastradh_mesa_GetFloatv(GLenum pname, GLfloat *params)
17257117f1b4Smrg{
17263464ebd5Sriastradh   const struct value_desc *d;
17273464ebd5Sriastradh   union value v;
17283464ebd5Sriastradh   GLmatrix *m;
17293464ebd5Sriastradh   int shift, i;
17303464ebd5Sriastradh   void *p;
17317117f1b4Smrg
17323464ebd5Sriastradh   d = find_value("glGetFloatv", pname, &p, &v);
17333464ebd5Sriastradh   switch (d->type) {
17343464ebd5Sriastradh   case TYPE_INVALID:
17353464ebd5Sriastradh      break;
17363464ebd5Sriastradh   case TYPE_CONST:
17373464ebd5Sriastradh      params[0] = (GLfloat) d->offset;
17383464ebd5Sriastradh      break;
17397117f1b4Smrg
174001e04c3fSmrg   case TYPE_FLOAT_8:
174101e04c3fSmrg      params[7] = ((GLfloat *) p)[7];
174201e04c3fSmrg      params[6] = ((GLfloat *) p)[6];
174301e04c3fSmrg      params[5] = ((GLfloat *) p)[5];
174401e04c3fSmrg      params[4] = ((GLfloat *) p)[4];
17453464ebd5Sriastradh   case TYPE_FLOAT_4:
17463464ebd5Sriastradh   case TYPE_FLOATN_4:
17473464ebd5Sriastradh      params[3] = ((GLfloat *) p)[3];
17483464ebd5Sriastradh   case TYPE_FLOAT_3:
17493464ebd5Sriastradh   case TYPE_FLOATN_3:
17503464ebd5Sriastradh      params[2] = ((GLfloat *) p)[2];
17513464ebd5Sriastradh   case TYPE_FLOAT_2:
17523464ebd5Sriastradh   case TYPE_FLOATN_2:
17533464ebd5Sriastradh      params[1] = ((GLfloat *) p)[1];
17543464ebd5Sriastradh   case TYPE_FLOAT:
17553464ebd5Sriastradh   case TYPE_FLOATN:
17563464ebd5Sriastradh      params[0] = ((GLfloat *) p)[0];
17573464ebd5Sriastradh      break;
17587117f1b4Smrg
1759af69d88dSmrg   case TYPE_DOUBLEN_2:
1760af69d88dSmrg      params[1] = (GLfloat) (((GLdouble *) p)[1]);
17613464ebd5Sriastradh   case TYPE_DOUBLEN:
1762af69d88dSmrg      params[0] = (GLfloat) (((GLdouble *) p)[0]);
17633464ebd5Sriastradh      break;
17643464ebd5Sriastradh
17653464ebd5Sriastradh   case TYPE_INT_4:
17663464ebd5Sriastradh      params[3] = (GLfloat) (((GLint *) p)[3]);
17673464ebd5Sriastradh   case TYPE_INT_3:
17683464ebd5Sriastradh      params[2] = (GLfloat) (((GLint *) p)[2]);
17693464ebd5Sriastradh   case TYPE_INT_2:
17703464ebd5Sriastradh   case TYPE_ENUM_2:
17713464ebd5Sriastradh      params[1] = (GLfloat) (((GLint *) p)[1]);
17723464ebd5Sriastradh   case TYPE_INT:
17733464ebd5Sriastradh   case TYPE_ENUM:
17743464ebd5Sriastradh      params[0] = (GLfloat) (((GLint *) p)[0]);
17753464ebd5Sriastradh      break;
17763464ebd5Sriastradh
177701e04c3fSmrg   case TYPE_ENUM16:
177801e04c3fSmrg      params[0] = (GLfloat) (((GLenum16 *) p)[0]);
177901e04c3fSmrg      break;
178001e04c3fSmrg
17813464ebd5Sriastradh   case TYPE_INT_N:
17823464ebd5Sriastradh      for (i = 0; i < v.value_int_n.n; i++)
178301e04c3fSmrg         params[i] = (GLfloat) v.value_int_n.ints[i];
178401e04c3fSmrg      break;
178501e04c3fSmrg
178601e04c3fSmrg   case TYPE_UINT_4:
178701e04c3fSmrg      params[3] = (GLfloat) (((GLuint *) p)[3]);
178801e04c3fSmrg   case TYPE_UINT_3:
178901e04c3fSmrg      params[2] = (GLfloat) (((GLuint *) p)[2]);
179001e04c3fSmrg   case TYPE_UINT_2:
179101e04c3fSmrg      params[1] = (GLfloat) (((GLuint *) p)[1]);
179201e04c3fSmrg   case TYPE_UINT:
179301e04c3fSmrg      params[0] = (GLfloat) (((GLuint *) p)[0]);
17943464ebd5Sriastradh      break;
17953464ebd5Sriastradh
17963464ebd5Sriastradh   case TYPE_INT64:
1797af69d88dSmrg      params[0] = (GLfloat) (((GLint64 *) p)[0]);
17983464ebd5Sriastradh      break;
17993464ebd5Sriastradh
18003464ebd5Sriastradh   case TYPE_BOOLEAN:
18013464ebd5Sriastradh      params[0] = BOOLEAN_TO_FLOAT(*(GLboolean*) p);
180201e04c3fSmrg      break;
180301e04c3fSmrg
180401e04c3fSmrg   case TYPE_UBYTE:
180501e04c3fSmrg      params[0] = (GLfloat) ((GLubyte *) p)[0];
180601e04c3fSmrg      break;
180701e04c3fSmrg
180801e04c3fSmrg   case TYPE_SHORT:
180901e04c3fSmrg      params[0] = (GLfloat) ((GLshort *) p)[0];
181001e04c3fSmrg      break;
18113464ebd5Sriastradh
18123464ebd5Sriastradh   case TYPE_MATRIX:
18133464ebd5Sriastradh      m = *(GLmatrix **) p;
18143464ebd5Sriastradh      for (i = 0; i < 16; i++)
181501e04c3fSmrg         params[i] = m->m[i];
18163464ebd5Sriastradh      break;
18173464ebd5Sriastradh
18183464ebd5Sriastradh   case TYPE_MATRIX_T:
18193464ebd5Sriastradh      m = *(GLmatrix **) p;
18203464ebd5Sriastradh      for (i = 0; i < 16; i++)
182101e04c3fSmrg         params[i] = m->m[transpose[i]];
18223464ebd5Sriastradh      break;
18233464ebd5Sriastradh
18243464ebd5Sriastradh   case TYPE_BIT_0:
18253464ebd5Sriastradh   case TYPE_BIT_1:
18263464ebd5Sriastradh   case TYPE_BIT_2:
18273464ebd5Sriastradh   case TYPE_BIT_3:
18283464ebd5Sriastradh   case TYPE_BIT_4:
18293464ebd5Sriastradh   case TYPE_BIT_5:
1830af69d88dSmrg   case TYPE_BIT_6:
1831af69d88dSmrg   case TYPE_BIT_7:
18323464ebd5Sriastradh      shift = d->type - TYPE_BIT_0;
18333464ebd5Sriastradh      params[0] = BOOLEAN_TO_FLOAT((*(GLbitfield *) p >> shift) & 1);
18343464ebd5Sriastradh      break;
18353464ebd5Sriastradh   }
18367117f1b4Smrg}
18377117f1b4Smrg
1838cdc920a0Smrgvoid GLAPIENTRY
18393464ebd5Sriastradh_mesa_GetIntegerv(GLenum pname, GLint *params)
1840cdc920a0Smrg{
18413464ebd5Sriastradh   const struct value_desc *d;
18423464ebd5Sriastradh   union value v;
18433464ebd5Sriastradh   GLmatrix *m;
18443464ebd5Sriastradh   int shift, i;
18453464ebd5Sriastradh   void *p;
1846cdc920a0Smrg
18473464ebd5Sriastradh   d = find_value("glGetIntegerv", pname, &p, &v);
18483464ebd5Sriastradh   switch (d->type) {
18493464ebd5Sriastradh   case TYPE_INVALID:
18503464ebd5Sriastradh      break;
18513464ebd5Sriastradh   case TYPE_CONST:
18523464ebd5Sriastradh      params[0] = d->offset;
18533464ebd5Sriastradh      break;
1854cdc920a0Smrg
185501e04c3fSmrg   case TYPE_FLOAT_8:
185601e04c3fSmrg      params[7] = IROUND(((GLfloat *) p)[7]);
185701e04c3fSmrg      params[6] = IROUND(((GLfloat *) p)[6]);
185801e04c3fSmrg      params[5] = IROUND(((GLfloat *) p)[5]);
185901e04c3fSmrg      params[4] = IROUND(((GLfloat *) p)[4]);
18603464ebd5Sriastradh   case TYPE_FLOAT_4:
18613464ebd5Sriastradh      params[3] = IROUND(((GLfloat *) p)[3]);
18623464ebd5Sriastradh   case TYPE_FLOAT_3:
18633464ebd5Sriastradh      params[2] = IROUND(((GLfloat *) p)[2]);
18643464ebd5Sriastradh   case TYPE_FLOAT_2:
18653464ebd5Sriastradh      params[1] = IROUND(((GLfloat *) p)[1]);
18663464ebd5Sriastradh   case TYPE_FLOAT:
18673464ebd5Sriastradh      params[0] = IROUND(((GLfloat *) p)[0]);
18683464ebd5Sriastradh      break;
1869cdc920a0Smrg
18703464ebd5Sriastradh   case TYPE_FLOATN_4:
18713464ebd5Sriastradh      params[3] = FLOAT_TO_INT(((GLfloat *) p)[3]);
18723464ebd5Sriastradh   case TYPE_FLOATN_3:
18733464ebd5Sriastradh      params[2] = FLOAT_TO_INT(((GLfloat *) p)[2]);
18743464ebd5Sriastradh   case TYPE_FLOATN_2:
18753464ebd5Sriastradh      params[1] = FLOAT_TO_INT(((GLfloat *) p)[1]);
18763464ebd5Sriastradh   case TYPE_FLOATN:
18773464ebd5Sriastradh      params[0] = FLOAT_TO_INT(((GLfloat *) p)[0]);
18783464ebd5Sriastradh      break;
18793464ebd5Sriastradh
1880af69d88dSmrg   case TYPE_DOUBLEN_2:
1881af69d88dSmrg      params[1] = FLOAT_TO_INT(((GLdouble *) p)[1]);
18823464ebd5Sriastradh   case TYPE_DOUBLEN:
18833464ebd5Sriastradh      params[0] = FLOAT_TO_INT(((GLdouble *) p)[0]);
18843464ebd5Sriastradh      break;
18853464ebd5Sriastradh
18863464ebd5Sriastradh   case TYPE_INT_4:
188701e04c3fSmrg   case TYPE_UINT_4:
18883464ebd5Sriastradh      params[3] = ((GLint *) p)[3];
18893464ebd5Sriastradh   case TYPE_INT_3:
189001e04c3fSmrg   case TYPE_UINT_3:
18913464ebd5Sriastradh      params[2] = ((GLint *) p)[2];
18923464ebd5Sriastradh   case TYPE_INT_2:
189301e04c3fSmrg   case TYPE_UINT_2:
18943464ebd5Sriastradh   case TYPE_ENUM_2:
18953464ebd5Sriastradh      params[1] = ((GLint *) p)[1];
18963464ebd5Sriastradh   case TYPE_INT:
189701e04c3fSmrg   case TYPE_UINT:
18983464ebd5Sriastradh   case TYPE_ENUM:
18993464ebd5Sriastradh      params[0] = ((GLint *) p)[0];
19003464ebd5Sriastradh      break;
19013464ebd5Sriastradh
190201e04c3fSmrg   case TYPE_ENUM16:
190301e04c3fSmrg      params[0] = ((GLenum16 *) p)[0];
190401e04c3fSmrg      break;
190501e04c3fSmrg
19063464ebd5Sriastradh   case TYPE_INT_N:
19073464ebd5Sriastradh      for (i = 0; i < v.value_int_n.n; i++)
190801e04c3fSmrg         params[i] = v.value_int_n.ints[i];
19093464ebd5Sriastradh      break;
19103464ebd5Sriastradh
19113464ebd5Sriastradh   case TYPE_INT64:
19123464ebd5Sriastradh      params[0] = INT64_TO_INT(((GLint64 *) p)[0]);
19133464ebd5Sriastradh      break;
19143464ebd5Sriastradh
19153464ebd5Sriastradh   case TYPE_BOOLEAN:
19163464ebd5Sriastradh      params[0] = BOOLEAN_TO_INT(*(GLboolean*) p);
191701e04c3fSmrg      break;
191801e04c3fSmrg
191901e04c3fSmrg   case TYPE_UBYTE:
192001e04c3fSmrg      params[0] = ((GLubyte *) p)[0];
192101e04c3fSmrg      break;
192201e04c3fSmrg
192301e04c3fSmrg   case TYPE_SHORT:
192401e04c3fSmrg      params[0] = ((GLshort *) p)[0];
192501e04c3fSmrg      break;
19263464ebd5Sriastradh
19273464ebd5Sriastradh   case TYPE_MATRIX:
19283464ebd5Sriastradh      m = *(GLmatrix **) p;
19293464ebd5Sriastradh      for (i = 0; i < 16; i++)
193001e04c3fSmrg         params[i] = FLOAT_TO_INT(m->m[i]);
19313464ebd5Sriastradh      break;
19323464ebd5Sriastradh
19333464ebd5Sriastradh   case TYPE_MATRIX_T:
19343464ebd5Sriastradh      m = *(GLmatrix **) p;
19353464ebd5Sriastradh      for (i = 0; i < 16; i++)
193601e04c3fSmrg         params[i] = FLOAT_TO_INT(m->m[transpose[i]]);
19373464ebd5Sriastradh      break;
19383464ebd5Sriastradh
19393464ebd5Sriastradh   case TYPE_BIT_0:
19403464ebd5Sriastradh   case TYPE_BIT_1:
19413464ebd5Sriastradh   case TYPE_BIT_2:
19423464ebd5Sriastradh   case TYPE_BIT_3:
19433464ebd5Sriastradh   case TYPE_BIT_4:
19443464ebd5Sriastradh   case TYPE_BIT_5:
1945af69d88dSmrg   case TYPE_BIT_6:
1946af69d88dSmrg   case TYPE_BIT_7:
19473464ebd5Sriastradh      shift = d->type - TYPE_BIT_0;
19483464ebd5Sriastradh      params[0] = (*(GLbitfield *) p >> shift) & 1;
19493464ebd5Sriastradh      break;
1950cdc920a0Smrg   }
1951cdc920a0Smrg}
1952cdc920a0Smrg
1953cdc920a0Smrgvoid GLAPIENTRY
19543464ebd5Sriastradh_mesa_GetInteger64v(GLenum pname, GLint64 *params)
1955cdc920a0Smrg{
19563464ebd5Sriastradh   const struct value_desc *d;
19573464ebd5Sriastradh   union value v;
19583464ebd5Sriastradh   GLmatrix *m;
19593464ebd5Sriastradh   int shift, i;
19603464ebd5Sriastradh   void *p;
1961cdc920a0Smrg
19623464ebd5Sriastradh   d = find_value("glGetInteger64v", pname, &p, &v);
19633464ebd5Sriastradh   switch (d->type) {
19643464ebd5Sriastradh   case TYPE_INVALID:
19653464ebd5Sriastradh      break;
19663464ebd5Sriastradh   case TYPE_CONST:
19673464ebd5Sriastradh      params[0] = d->offset;
19683464ebd5Sriastradh      break;
1969cdc920a0Smrg
197001e04c3fSmrg   case TYPE_FLOAT_8:
197101e04c3fSmrg      params[7] = IROUND64(((GLfloat *) p)[7]);
197201e04c3fSmrg      params[6] = IROUND64(((GLfloat *) p)[6]);
197301e04c3fSmrg      params[5] = IROUND64(((GLfloat *) p)[5]);
197401e04c3fSmrg      params[4] = IROUND64(((GLfloat *) p)[4]);
19753464ebd5Sriastradh   case TYPE_FLOAT_4:
19763464ebd5Sriastradh      params[3] = IROUND64(((GLfloat *) p)[3]);
19773464ebd5Sriastradh   case TYPE_FLOAT_3:
19783464ebd5Sriastradh      params[2] = IROUND64(((GLfloat *) p)[2]);
19793464ebd5Sriastradh   case TYPE_FLOAT_2:
19803464ebd5Sriastradh      params[1] = IROUND64(((GLfloat *) p)[1]);
19813464ebd5Sriastradh   case TYPE_FLOAT:
19823464ebd5Sriastradh      params[0] = IROUND64(((GLfloat *) p)[0]);
19833464ebd5Sriastradh      break;
1984cdc920a0Smrg
19853464ebd5Sriastradh   case TYPE_FLOATN_4:
198601e04c3fSmrg      params[3] = FLOAT_TO_INT(((GLfloat *) p)[3]);
19873464ebd5Sriastradh   case TYPE_FLOATN_3:
198801e04c3fSmrg      params[2] = FLOAT_TO_INT(((GLfloat *) p)[2]);
19893464ebd5Sriastradh   case TYPE_FLOATN_2:
199001e04c3fSmrg      params[1] = FLOAT_TO_INT(((GLfloat *) p)[1]);
19913464ebd5Sriastradh   case TYPE_FLOATN:
199201e04c3fSmrg      params[0] = FLOAT_TO_INT(((GLfloat *) p)[0]);
19933464ebd5Sriastradh      break;
19943464ebd5Sriastradh
1995af69d88dSmrg   case TYPE_DOUBLEN_2:
199601e04c3fSmrg      params[1] = FLOAT_TO_INT(((GLdouble *) p)[1]);
19973464ebd5Sriastradh   case TYPE_DOUBLEN:
199801e04c3fSmrg      params[0] = FLOAT_TO_INT(((GLdouble *) p)[0]);
19993464ebd5Sriastradh      break;
20003464ebd5Sriastradh
20013464ebd5Sriastradh   case TYPE_INT_4:
20023464ebd5Sriastradh      params[3] = ((GLint *) p)[3];
20033464ebd5Sriastradh   case TYPE_INT_3:
20043464ebd5Sriastradh      params[2] = ((GLint *) p)[2];
20053464ebd5Sriastradh   case TYPE_INT_2:
20063464ebd5Sriastradh   case TYPE_ENUM_2:
20073464ebd5Sriastradh      params[1] = ((GLint *) p)[1];
20083464ebd5Sriastradh   case TYPE_INT:
20093464ebd5Sriastradh   case TYPE_ENUM:
20103464ebd5Sriastradh      params[0] = ((GLint *) p)[0];
20113464ebd5Sriastradh      break;
20123464ebd5Sriastradh
201301e04c3fSmrg   case TYPE_ENUM16:
201401e04c3fSmrg      params[0] = ((GLenum16 *) p)[0];
201501e04c3fSmrg      break;
201601e04c3fSmrg
20173464ebd5Sriastradh   case TYPE_INT_N:
20183464ebd5Sriastradh      for (i = 0; i < v.value_int_n.n; i++)
201901e04c3fSmrg         params[i] = v.value_int_n.ints[i];
202001e04c3fSmrg      break;
202101e04c3fSmrg
202201e04c3fSmrg   case TYPE_UINT_4:
202301e04c3fSmrg      params[3] = ((GLuint *) p)[3];
202401e04c3fSmrg   case TYPE_UINT_3:
202501e04c3fSmrg      params[2] = ((GLuint *) p)[2];
202601e04c3fSmrg   case TYPE_UINT_2:
202701e04c3fSmrg      params[1] = ((GLuint *) p)[1];
202801e04c3fSmrg   case TYPE_UINT:
202901e04c3fSmrg      params[0] = ((GLuint *) p)[0];
20303464ebd5Sriastradh      break;
20313464ebd5Sriastradh
20323464ebd5Sriastradh   case TYPE_INT64:
20333464ebd5Sriastradh      params[0] = ((GLint64 *) p)[0];
20343464ebd5Sriastradh      break;
20353464ebd5Sriastradh
20363464ebd5Sriastradh   case TYPE_BOOLEAN:
20373464ebd5Sriastradh      params[0] = ((GLboolean*) p)[0];
203801e04c3fSmrg      break;
20393464ebd5Sriastradh
20403464ebd5Sriastradh   case TYPE_MATRIX:
20413464ebd5Sriastradh      m = *(GLmatrix **) p;
20423464ebd5Sriastradh      for (i = 0; i < 16; i++)
204301e04c3fSmrg         params[i] = FLOAT_TO_INT64(m->m[i]);
20443464ebd5Sriastradh      break;
20453464ebd5Sriastradh
20463464ebd5Sriastradh   case TYPE_MATRIX_T:
20473464ebd5Sriastradh      m = *(GLmatrix **) p;
20483464ebd5Sriastradh      for (i = 0; i < 16; i++)
204901e04c3fSmrg         params[i] = FLOAT_TO_INT64(m->m[transpose[i]]);
20503464ebd5Sriastradh      break;
20513464ebd5Sriastradh
20523464ebd5Sriastradh   case TYPE_BIT_0:
20533464ebd5Sriastradh   case TYPE_BIT_1:
20543464ebd5Sriastradh   case TYPE_BIT_2:
20553464ebd5Sriastradh   case TYPE_BIT_3:
20563464ebd5Sriastradh   case TYPE_BIT_4:
20573464ebd5Sriastradh   case TYPE_BIT_5:
2058af69d88dSmrg   case TYPE_BIT_6:
2059af69d88dSmrg   case TYPE_BIT_7:
20603464ebd5Sriastradh      shift = d->type - TYPE_BIT_0;
20613464ebd5Sriastradh      params[0] = (*(GLbitfield *) p >> shift) & 1;
20623464ebd5Sriastradh      break;
2063cdc920a0Smrg   }
2064cdc920a0Smrg}
2065cdc920a0Smrg
2066cdc920a0Smrgvoid GLAPIENTRY
20673464ebd5Sriastradh_mesa_GetDoublev(GLenum pname, GLdouble *params)
2068cdc920a0Smrg{
20693464ebd5Sriastradh   const struct value_desc *d;
20703464ebd5Sriastradh   union value v;
20713464ebd5Sriastradh   GLmatrix *m;
20723464ebd5Sriastradh   int shift, i;
20733464ebd5Sriastradh   void *p;
2074cdc920a0Smrg
20753464ebd5Sriastradh   d = find_value("glGetDoublev", pname, &p, &v);
20763464ebd5Sriastradh   switch (d->type) {
20773464ebd5Sriastradh   case TYPE_INVALID:
20783464ebd5Sriastradh      break;
20793464ebd5Sriastradh   case TYPE_CONST:
20803464ebd5Sriastradh      params[0] = d->offset;
20813464ebd5Sriastradh      break;
20823464ebd5Sriastradh
208301e04c3fSmrg   case TYPE_FLOAT_8:
208401e04c3fSmrg      params[7] = ((GLfloat *) p)[7];
208501e04c3fSmrg      params[6] = ((GLfloat *) p)[6];
208601e04c3fSmrg      params[5] = ((GLfloat *) p)[5];
208701e04c3fSmrg      params[4] = ((GLfloat *) p)[4];
20883464ebd5Sriastradh   case TYPE_FLOAT_4:
20893464ebd5Sriastradh   case TYPE_FLOATN_4:
20903464ebd5Sriastradh      params[3] = ((GLfloat *) p)[3];
20913464ebd5Sriastradh   case TYPE_FLOAT_3:
20923464ebd5Sriastradh   case TYPE_FLOATN_3:
20933464ebd5Sriastradh      params[2] = ((GLfloat *) p)[2];
20943464ebd5Sriastradh   case TYPE_FLOAT_2:
20953464ebd5Sriastradh   case TYPE_FLOATN_2:
20963464ebd5Sriastradh      params[1] = ((GLfloat *) p)[1];
20973464ebd5Sriastradh   case TYPE_FLOAT:
20983464ebd5Sriastradh   case TYPE_FLOATN:
20993464ebd5Sriastradh      params[0] = ((GLfloat *) p)[0];
21003464ebd5Sriastradh      break;
21013464ebd5Sriastradh
2102af69d88dSmrg   case TYPE_DOUBLEN_2:
2103af69d88dSmrg      params[1] = ((GLdouble *) p)[1];
21043464ebd5Sriastradh   case TYPE_DOUBLEN:
21053464ebd5Sriastradh      params[0] = ((GLdouble *) p)[0];
21063464ebd5Sriastradh      break;
21073464ebd5Sriastradh
21083464ebd5Sriastradh   case TYPE_INT_4:
21093464ebd5Sriastradh      params[3] = ((GLint *) p)[3];
21103464ebd5Sriastradh   case TYPE_INT_3:
21113464ebd5Sriastradh      params[2] = ((GLint *) p)[2];
21123464ebd5Sriastradh   case TYPE_INT_2:
21133464ebd5Sriastradh   case TYPE_ENUM_2:
21143464ebd5Sriastradh      params[1] = ((GLint *) p)[1];
21153464ebd5Sriastradh   case TYPE_INT:
21163464ebd5Sriastradh   case TYPE_ENUM:
21173464ebd5Sriastradh      params[0] = ((GLint *) p)[0];
21183464ebd5Sriastradh      break;
21193464ebd5Sriastradh
212001e04c3fSmrg   case TYPE_ENUM16:
212101e04c3fSmrg      params[0] = ((GLenum16 *) p)[0];
212201e04c3fSmrg      break;
212301e04c3fSmrg
21243464ebd5Sriastradh   case TYPE_INT_N:
21253464ebd5Sriastradh      for (i = 0; i < v.value_int_n.n; i++)
212601e04c3fSmrg         params[i] = v.value_int_n.ints[i];
212701e04c3fSmrg      break;
212801e04c3fSmrg
212901e04c3fSmrg   case TYPE_UINT_4:
213001e04c3fSmrg      params[3] = ((GLuint *) p)[3];
213101e04c3fSmrg   case TYPE_UINT_3:
213201e04c3fSmrg      params[2] = ((GLuint *) p)[2];
213301e04c3fSmrg   case TYPE_UINT_2:
213401e04c3fSmrg      params[1] = ((GLuint *) p)[1];
213501e04c3fSmrg   case TYPE_UINT:
213601e04c3fSmrg      params[0] = ((GLuint *) p)[0];
21373464ebd5Sriastradh      break;
21383464ebd5Sriastradh
21393464ebd5Sriastradh   case TYPE_INT64:
2140af69d88dSmrg      params[0] = (GLdouble) (((GLint64 *) p)[0]);
21413464ebd5Sriastradh      break;
21423464ebd5Sriastradh
21433464ebd5Sriastradh   case TYPE_BOOLEAN:
21443464ebd5Sriastradh      params[0] = *(GLboolean*) p;
214501e04c3fSmrg      break;
214601e04c3fSmrg
214701e04c3fSmrg   case TYPE_UBYTE:
214801e04c3fSmrg      params[0] = ((GLubyte *) p)[0];
214901e04c3fSmrg      break;
215001e04c3fSmrg
215101e04c3fSmrg   case TYPE_SHORT:
215201e04c3fSmrg      params[0] = ((GLshort *) p)[0];
215301e04c3fSmrg      break;
21543464ebd5Sriastradh
21553464ebd5Sriastradh   case TYPE_MATRIX:
21563464ebd5Sriastradh      m = *(GLmatrix **) p;
21573464ebd5Sriastradh      for (i = 0; i < 16; i++)
215801e04c3fSmrg         params[i] = m->m[i];
21593464ebd5Sriastradh      break;
21603464ebd5Sriastradh
21613464ebd5Sriastradh   case TYPE_MATRIX_T:
21623464ebd5Sriastradh      m = *(GLmatrix **) p;
21633464ebd5Sriastradh      for (i = 0; i < 16; i++)
216401e04c3fSmrg         params[i] = m->m[transpose[i]];
21653464ebd5Sriastradh      break;
21663464ebd5Sriastradh
21673464ebd5Sriastradh   case TYPE_BIT_0:
21683464ebd5Sriastradh   case TYPE_BIT_1:
21693464ebd5Sriastradh   case TYPE_BIT_2:
21703464ebd5Sriastradh   case TYPE_BIT_3:
21713464ebd5Sriastradh   case TYPE_BIT_4:
21723464ebd5Sriastradh   case TYPE_BIT_5:
2173af69d88dSmrg   case TYPE_BIT_6:
2174af69d88dSmrg   case TYPE_BIT_7:
21753464ebd5Sriastradh      shift = d->type - TYPE_BIT_0;
21763464ebd5Sriastradh      params[0] = (*(GLbitfield *) p >> shift) & 1;
21773464ebd5Sriastradh      break;
21783464ebd5Sriastradh   }
21793464ebd5Sriastradh}
2180cdc920a0Smrg
218101e04c3fSmrgvoid GLAPIENTRY
218201e04c3fSmrg_mesa_GetUnsignedBytevEXT(GLenum pname, GLubyte *data)
218301e04c3fSmrg{
218401e04c3fSmrg   const struct value_desc *d;
218501e04c3fSmrg   union value v;
218601e04c3fSmrg   int shift;
218701e04c3fSmrg   void *p = NULL;
218801e04c3fSmrg   GLsizei size;
218901e04c3fSmrg   const char *func = "glGetUnsignedBytevEXT";
219001e04c3fSmrg
219101e04c3fSmrg   GET_CURRENT_CONTEXT(ctx);
219201e04c3fSmrg
219301e04c3fSmrg   if (!ctx->Extensions.EXT_memory_object) {
219401e04c3fSmrg      _mesa_error(ctx, GL_INVALID_OPERATION, "%s(unsupported)", func);
219501e04c3fSmrg      return;
219601e04c3fSmrg   }
219701e04c3fSmrg
219801e04c3fSmrg   d = find_value(func, pname, &p, &v);
219901e04c3fSmrg   size = get_value_size(d->type, &v);
220001e04c3fSmrg   if (size <= 0) {
220101e04c3fSmrg      _mesa_problem(ctx, "invalid value type in GetUnsignedBytevEXT()");
220201e04c3fSmrg   }
220301e04c3fSmrg
220401e04c3fSmrg   switch (d->type) {
220501e04c3fSmrg   case TYPE_BIT_0:
220601e04c3fSmrg   case TYPE_BIT_1:
220701e04c3fSmrg   case TYPE_BIT_2:
220801e04c3fSmrg   case TYPE_BIT_3:
220901e04c3fSmrg   case TYPE_BIT_4:
221001e04c3fSmrg   case TYPE_BIT_5:
221101e04c3fSmrg   case TYPE_BIT_6:
221201e04c3fSmrg   case TYPE_BIT_7:
221301e04c3fSmrg      shift = d->type - TYPE_BIT_0;
221401e04c3fSmrg      data[0] = (*(GLbitfield *) p >> shift) & 1;
221501e04c3fSmrg      break;
221601e04c3fSmrg   case TYPE_CONST:
221701e04c3fSmrg      memcpy(data, &d->offset, size);
221801e04c3fSmrg      break;
221901e04c3fSmrg   case TYPE_INT_N:
222001e04c3fSmrg      memcpy(data, &v.value_int_n.ints, size);
222101e04c3fSmrg      break;
222201e04c3fSmrg   case TYPE_UINT:
222301e04c3fSmrg   case TYPE_INT:
222401e04c3fSmrg   case TYPE_INT_2:
222501e04c3fSmrg   case TYPE_UINT_2:
222601e04c3fSmrg   case TYPE_INT_3:
222701e04c3fSmrg   case TYPE_UINT_3:
222801e04c3fSmrg   case TYPE_INT_4:
222901e04c3fSmrg   case TYPE_UINT_4:
223001e04c3fSmrg   case TYPE_INT64:
223101e04c3fSmrg   case TYPE_ENUM:
223201e04c3fSmrg   case TYPE_ENUM_2:
223301e04c3fSmrg   case TYPE_BOOLEAN:
223401e04c3fSmrg   case TYPE_UBYTE:
223501e04c3fSmrg   case TYPE_SHORT:
223601e04c3fSmrg   case TYPE_FLOAT:
223701e04c3fSmrg   case TYPE_FLOATN:
223801e04c3fSmrg   case TYPE_FLOAT_2:
223901e04c3fSmrg   case TYPE_FLOATN_2:
224001e04c3fSmrg   case TYPE_FLOAT_3:
224101e04c3fSmrg   case TYPE_FLOATN_3:
224201e04c3fSmrg   case TYPE_FLOAT_4:
224301e04c3fSmrg   case TYPE_FLOATN_4:
224401e04c3fSmrg   case TYPE_FLOAT_8:
224501e04c3fSmrg   case TYPE_DOUBLEN:
224601e04c3fSmrg   case TYPE_DOUBLEN_2:
224701e04c3fSmrg   case TYPE_MATRIX:
224801e04c3fSmrg   case TYPE_MATRIX_T:
224901e04c3fSmrg      memcpy(data, p, size);
225001e04c3fSmrg      break;
225101e04c3fSmrg   case TYPE_ENUM16: {
225201e04c3fSmrg      GLenum e = *(GLenum16 *)p;
225301e04c3fSmrg      memcpy(data, &e, sizeof(e));
225401e04c3fSmrg      break;
225501e04c3fSmrg   }
225601e04c3fSmrg   default:
225701e04c3fSmrg      break; /* nothing - GL error was recorded */
225801e04c3fSmrg   }
225901e04c3fSmrg}
226001e04c3fSmrg
226101e04c3fSmrg/**
226201e04c3fSmrg * Convert a GL texture binding enum such as GL_TEXTURE_BINDING_2D
226301e04c3fSmrg * into the corresponding Mesa texture target index.
226401e04c3fSmrg * \return TEXTURE_x_INDEX or -1 if binding is invalid
226501e04c3fSmrg */
226601e04c3fSmrgstatic int
226701e04c3fSmrgtex_binding_to_index(const struct gl_context *ctx, GLenum binding)
226801e04c3fSmrg{
226901e04c3fSmrg   switch (binding) {
227001e04c3fSmrg   case GL_TEXTURE_BINDING_1D:
227101e04c3fSmrg      return _mesa_is_desktop_gl(ctx) ? TEXTURE_1D_INDEX : -1;
227201e04c3fSmrg   case GL_TEXTURE_BINDING_2D:
227301e04c3fSmrg      return TEXTURE_2D_INDEX;
227401e04c3fSmrg   case GL_TEXTURE_BINDING_3D:
227501e04c3fSmrg      return ctx->API != API_OPENGLES ? TEXTURE_3D_INDEX : -1;
227601e04c3fSmrg   case GL_TEXTURE_BINDING_CUBE_MAP:
227701e04c3fSmrg      return ctx->Extensions.ARB_texture_cube_map
227801e04c3fSmrg         ? TEXTURE_CUBE_INDEX : -1;
227901e04c3fSmrg   case GL_TEXTURE_BINDING_RECTANGLE:
228001e04c3fSmrg      return _mesa_is_desktop_gl(ctx) && ctx->Extensions.NV_texture_rectangle
228101e04c3fSmrg         ? TEXTURE_RECT_INDEX : -1;
228201e04c3fSmrg   case GL_TEXTURE_BINDING_1D_ARRAY:
228301e04c3fSmrg      return _mesa_is_desktop_gl(ctx) && ctx->Extensions.EXT_texture_array
228401e04c3fSmrg         ? TEXTURE_1D_ARRAY_INDEX : -1;
228501e04c3fSmrg   case GL_TEXTURE_BINDING_2D_ARRAY:
228601e04c3fSmrg      return (_mesa_is_desktop_gl(ctx) && ctx->Extensions.EXT_texture_array)
228701e04c3fSmrg         || _mesa_is_gles3(ctx)
228801e04c3fSmrg         ? TEXTURE_2D_ARRAY_INDEX : -1;
228901e04c3fSmrg   case GL_TEXTURE_BINDING_BUFFER:
229001e04c3fSmrg      return (_mesa_has_ARB_texture_buffer_object(ctx) ||
229101e04c3fSmrg              _mesa_has_OES_texture_buffer(ctx)) ?
229201e04c3fSmrg             TEXTURE_BUFFER_INDEX : -1;
229301e04c3fSmrg   case GL_TEXTURE_BINDING_CUBE_MAP_ARRAY:
229401e04c3fSmrg      return _mesa_has_texture_cube_map_array(ctx)
229501e04c3fSmrg         ? TEXTURE_CUBE_ARRAY_INDEX : -1;
229601e04c3fSmrg   case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
229701e04c3fSmrg      return _mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_texture_multisample
229801e04c3fSmrg         ? TEXTURE_2D_MULTISAMPLE_INDEX : -1;
229901e04c3fSmrg   case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY:
230001e04c3fSmrg      return _mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_texture_multisample
230101e04c3fSmrg         ? TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX : -1;
230201e04c3fSmrg   default:
230301e04c3fSmrg      return -1;
230401e04c3fSmrg   }
230501e04c3fSmrg}
230601e04c3fSmrg
23073464ebd5Sriastradhstatic enum value_type
2308af69d88dSmrgfind_value_indexed(const char *func, GLenum pname, GLuint index, union value *v)
23093464ebd5Sriastradh{
23103464ebd5Sriastradh   GET_CURRENT_CONTEXT(ctx);
2311cdc920a0Smrg
2312cdc920a0Smrg   switch (pname) {
23133464ebd5Sriastradh
23143464ebd5Sriastradh   case GL_BLEND:
23153464ebd5Sriastradh      if (index >= ctx->Const.MaxDrawBuffers)
231601e04c3fSmrg         goto invalid_value;
23173464ebd5Sriastradh      if (!ctx->Extensions.EXT_draw_buffers2)
231801e04c3fSmrg         goto invalid_enum;
23193464ebd5Sriastradh      v->value_int = (ctx->Color.BlendEnabled >> index) & 1;
23203464ebd5Sriastradh      return TYPE_INT;
23213464ebd5Sriastradh
23223464ebd5Sriastradh   case GL_BLEND_SRC:
23233464ebd5Sriastradh      /* fall-through */
23243464ebd5Sriastradh   case GL_BLEND_SRC_RGB:
23253464ebd5Sriastradh      if (index >= ctx->Const.MaxDrawBuffers)
232601e04c3fSmrg         goto invalid_value;
23273464ebd5Sriastradh      if (!ctx->Extensions.ARB_draw_buffers_blend)
232801e04c3fSmrg         goto invalid_enum;
23293464ebd5Sriastradh      v->value_int = ctx->Color.Blend[index].SrcRGB;
23303464ebd5Sriastradh      return TYPE_INT;
23313464ebd5Sriastradh   case GL_BLEND_SRC_ALPHA:
23323464ebd5Sriastradh      if (index >= ctx->Const.MaxDrawBuffers)
233301e04c3fSmrg         goto invalid_value;
23343464ebd5Sriastradh      if (!ctx->Extensions.ARB_draw_buffers_blend)
233501e04c3fSmrg         goto invalid_enum;
23363464ebd5Sriastradh      v->value_int = ctx->Color.Blend[index].SrcA;
23373464ebd5Sriastradh      return TYPE_INT;
23383464ebd5Sriastradh   case GL_BLEND_DST:
23393464ebd5Sriastradh      /* fall-through */
23403464ebd5Sriastradh   case GL_BLEND_DST_RGB:
23413464ebd5Sriastradh      if (index >= ctx->Const.MaxDrawBuffers)
234201e04c3fSmrg         goto invalid_value;
23433464ebd5Sriastradh      if (!ctx->Extensions.ARB_draw_buffers_blend)
234401e04c3fSmrg         goto invalid_enum;
23453464ebd5Sriastradh      v->value_int = ctx->Color.Blend[index].DstRGB;
23463464ebd5Sriastradh      return TYPE_INT;
23473464ebd5Sriastradh   case GL_BLEND_DST_ALPHA:
23483464ebd5Sriastradh      if (index >= ctx->Const.MaxDrawBuffers)
234901e04c3fSmrg         goto invalid_value;
23503464ebd5Sriastradh      if (!ctx->Extensions.ARB_draw_buffers_blend)
235101e04c3fSmrg         goto invalid_enum;
23523464ebd5Sriastradh      v->value_int = ctx->Color.Blend[index].DstA;
23533464ebd5Sriastradh      return TYPE_INT;
23543464ebd5Sriastradh   case GL_BLEND_EQUATION_RGB:
23553464ebd5Sriastradh      if (index >= ctx->Const.MaxDrawBuffers)
235601e04c3fSmrg         goto invalid_value;
23573464ebd5Sriastradh      if (!ctx->Extensions.ARB_draw_buffers_blend)
235801e04c3fSmrg         goto invalid_enum;
23593464ebd5Sriastradh      v->value_int = ctx->Color.Blend[index].EquationRGB;
23603464ebd5Sriastradh      return TYPE_INT;
23613464ebd5Sriastradh   case GL_BLEND_EQUATION_ALPHA:
23623464ebd5Sriastradh      if (index >= ctx->Const.MaxDrawBuffers)
236301e04c3fSmrg         goto invalid_value;
23643464ebd5Sriastradh      if (!ctx->Extensions.ARB_draw_buffers_blend)
236501e04c3fSmrg         goto invalid_enum;
23663464ebd5Sriastradh      v->value_int = ctx->Color.Blend[index].EquationA;
23673464ebd5Sriastradh      return TYPE_INT;
23683464ebd5Sriastradh
23693464ebd5Sriastradh   case GL_COLOR_WRITEMASK:
23703464ebd5Sriastradh      if (index >= ctx->Const.MaxDrawBuffers)
237101e04c3fSmrg         goto invalid_value;
23723464ebd5Sriastradh      if (!ctx->Extensions.EXT_draw_buffers2)
237301e04c3fSmrg         goto invalid_enum;
237401e04c3fSmrg      v->value_int_4[0] = GET_COLORMASK_BIT(ctx->Color.ColorMask, index, 0);
237501e04c3fSmrg      v->value_int_4[1] = GET_COLORMASK_BIT(ctx->Color.ColorMask, index, 1);
237601e04c3fSmrg      v->value_int_4[2] = GET_COLORMASK_BIT(ctx->Color.ColorMask, index, 2);
237701e04c3fSmrg      v->value_int_4[3] = GET_COLORMASK_BIT(ctx->Color.ColorMask, index, 3);
23783464ebd5Sriastradh      return TYPE_INT_4;
23793464ebd5Sriastradh
2380af69d88dSmrg   case GL_SCISSOR_BOX:
2381af69d88dSmrg      if (index >= ctx->Const.MaxViewports)
2382af69d88dSmrg         goto invalid_value;
2383af69d88dSmrg      v->value_int_4[0] = ctx->Scissor.ScissorArray[index].X;
2384af69d88dSmrg      v->value_int_4[1] = ctx->Scissor.ScissorArray[index].Y;
2385af69d88dSmrg      v->value_int_4[2] = ctx->Scissor.ScissorArray[index].Width;
2386af69d88dSmrg      v->value_int_4[3] = ctx->Scissor.ScissorArray[index].Height;
2387af69d88dSmrg      return TYPE_INT_4;
2388af69d88dSmrg
238901e04c3fSmrg   case GL_WINDOW_RECTANGLE_EXT:
239001e04c3fSmrg      if (!ctx->Extensions.EXT_window_rectangles)
239101e04c3fSmrg         goto invalid_enum;
239201e04c3fSmrg      if (index >= ctx->Const.MaxWindowRectangles)
239301e04c3fSmrg         goto invalid_value;
239401e04c3fSmrg      v->value_int_4[0] = ctx->Scissor.WindowRects[index].X;
239501e04c3fSmrg      v->value_int_4[1] = ctx->Scissor.WindowRects[index].Y;
239601e04c3fSmrg      v->value_int_4[2] = ctx->Scissor.WindowRects[index].Width;
239701e04c3fSmrg      v->value_int_4[3] = ctx->Scissor.WindowRects[index].Height;
239801e04c3fSmrg      return TYPE_INT_4;
239901e04c3fSmrg
2400af69d88dSmrg   case GL_VIEWPORT:
2401af69d88dSmrg      if (index >= ctx->Const.MaxViewports)
2402af69d88dSmrg         goto invalid_value;
2403af69d88dSmrg      v->value_float_4[0] = ctx->ViewportArray[index].X;
2404af69d88dSmrg      v->value_float_4[1] = ctx->ViewportArray[index].Y;
2405af69d88dSmrg      v->value_float_4[2] = ctx->ViewportArray[index].Width;
2406af69d88dSmrg      v->value_float_4[3] = ctx->ViewportArray[index].Height;
2407af69d88dSmrg      return TYPE_FLOAT_4;
2408af69d88dSmrg
2409af69d88dSmrg   case GL_DEPTH_RANGE:
2410af69d88dSmrg      if (index >= ctx->Const.MaxViewports)
2411af69d88dSmrg         goto invalid_value;
2412af69d88dSmrg      v->value_double_2[0] = ctx->ViewportArray[index].Near;
2413af69d88dSmrg      v->value_double_2[1] = ctx->ViewportArray[index].Far;
2414af69d88dSmrg      return TYPE_DOUBLEN_2;
2415af69d88dSmrg
24163464ebd5Sriastradh   case GL_TRANSFORM_FEEDBACK_BUFFER_START:
2417af69d88dSmrg      if (index >= ctx->Const.MaxTransformFeedbackBuffers)
241801e04c3fSmrg         goto invalid_value;
24193464ebd5Sriastradh      if (!ctx->Extensions.EXT_transform_feedback)
242001e04c3fSmrg         goto invalid_enum;
24213464ebd5Sriastradh      v->value_int64 = ctx->TransformFeedback.CurrentObject->Offset[index];
24223464ebd5Sriastradh      return TYPE_INT64;
24233464ebd5Sriastradh
24243464ebd5Sriastradh   case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
2425af69d88dSmrg      if (index >= ctx->Const.MaxTransformFeedbackBuffers)
242601e04c3fSmrg         goto invalid_value;
24273464ebd5Sriastradh      if (!ctx->Extensions.EXT_transform_feedback)
242801e04c3fSmrg         goto invalid_enum;
2429af69d88dSmrg      v->value_int64
2430af69d88dSmrg         = ctx->TransformFeedback.CurrentObject->RequestedSize[index];
24313464ebd5Sriastradh      return TYPE_INT64;
24323464ebd5Sriastradh
24333464ebd5Sriastradh   case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
2434af69d88dSmrg      if (index >= ctx->Const.MaxTransformFeedbackBuffers)
243501e04c3fSmrg         goto invalid_value;
24363464ebd5Sriastradh      if (!ctx->Extensions.EXT_transform_feedback)
243701e04c3fSmrg         goto invalid_enum;
2438af69d88dSmrg      v->value_int = ctx->TransformFeedback.CurrentObject->BufferNames[index];
2439af69d88dSmrg      return TYPE_INT;
2440af69d88dSmrg
2441af69d88dSmrg   case GL_UNIFORM_BUFFER_BINDING:
2442af69d88dSmrg      if (index >= ctx->Const.MaxUniformBufferBindings)
244301e04c3fSmrg         goto invalid_value;
2444af69d88dSmrg      if (!ctx->Extensions.ARB_uniform_buffer_object)
244501e04c3fSmrg         goto invalid_enum;
2446af69d88dSmrg      v->value_int = ctx->UniformBufferBindings[index].BufferObject->Name;
2447af69d88dSmrg      return TYPE_INT;
2448af69d88dSmrg
2449af69d88dSmrg   case GL_UNIFORM_BUFFER_START:
2450af69d88dSmrg      if (index >= ctx->Const.MaxUniformBufferBindings)
245101e04c3fSmrg         goto invalid_value;
2452af69d88dSmrg      if (!ctx->Extensions.ARB_uniform_buffer_object)
245301e04c3fSmrg         goto invalid_enum;
245401e04c3fSmrg      v->value_int = ctx->UniformBufferBindings[index].Offset < 0 ? 0 :
245501e04c3fSmrg                     ctx->UniformBufferBindings[index].Offset;
2456af69d88dSmrg      return TYPE_INT;
2457af69d88dSmrg
2458af69d88dSmrg   case GL_UNIFORM_BUFFER_SIZE:
2459af69d88dSmrg      if (index >= ctx->Const.MaxUniformBufferBindings)
246001e04c3fSmrg         goto invalid_value;
2461af69d88dSmrg      if (!ctx->Extensions.ARB_uniform_buffer_object)
246201e04c3fSmrg         goto invalid_enum;
246301e04c3fSmrg      v->value_int = ctx->UniformBufferBindings[index].Size < 0 ? 0 :
246401e04c3fSmrg                     ctx->UniformBufferBindings[index].Size;
246501e04c3fSmrg      return TYPE_INT;
246601e04c3fSmrg
246701e04c3fSmrg   /* ARB_shader_storage_buffer_object */
246801e04c3fSmrg   case GL_SHADER_STORAGE_BUFFER_BINDING:
246901e04c3fSmrg      if (!ctx->Extensions.ARB_shader_storage_buffer_object)
247001e04c3fSmrg         goto invalid_enum;
247101e04c3fSmrg      if (index >= ctx->Const.MaxShaderStorageBufferBindings)
247201e04c3fSmrg         goto invalid_value;
247301e04c3fSmrg      v->value_int = ctx->ShaderStorageBufferBindings[index].BufferObject->Name;
247401e04c3fSmrg      return TYPE_INT;
247501e04c3fSmrg
247601e04c3fSmrg   case GL_SHADER_STORAGE_BUFFER_START:
247701e04c3fSmrg      if (!ctx->Extensions.ARB_shader_storage_buffer_object)
247801e04c3fSmrg         goto invalid_enum;
247901e04c3fSmrg      if (index >= ctx->Const.MaxShaderStorageBufferBindings)
248001e04c3fSmrg         goto invalid_value;
248101e04c3fSmrg      v->value_int = ctx->ShaderStorageBufferBindings[index].Offset < 0 ? 0 :
248201e04c3fSmrg                     ctx->ShaderStorageBufferBindings[index].Offset;
248301e04c3fSmrg      return TYPE_INT;
248401e04c3fSmrg
248501e04c3fSmrg   case GL_SHADER_STORAGE_BUFFER_SIZE:
248601e04c3fSmrg      if (!ctx->Extensions.ARB_shader_storage_buffer_object)
248701e04c3fSmrg         goto invalid_enum;
248801e04c3fSmrg      if (index >= ctx->Const.MaxShaderStorageBufferBindings)
248901e04c3fSmrg         goto invalid_value;
249001e04c3fSmrg      v->value_int = ctx->ShaderStorageBufferBindings[index].Size < 0 ? 0 :
249101e04c3fSmrg                     ctx->ShaderStorageBufferBindings[index].Size;
2492af69d88dSmrg      return TYPE_INT;
2493af69d88dSmrg
2494af69d88dSmrg   /* ARB_texture_multisample / GL3.2 */
2495af69d88dSmrg   case GL_SAMPLE_MASK_VALUE:
2496af69d88dSmrg      if (index != 0)
2497af69d88dSmrg         goto invalid_value;
2498af69d88dSmrg      if (!ctx->Extensions.ARB_texture_multisample)
2499af69d88dSmrg         goto invalid_enum;
2500af69d88dSmrg      v->value_int = ctx->Multisample.SampleMaskValue;
2501af69d88dSmrg      return TYPE_INT;
2502af69d88dSmrg
2503af69d88dSmrg   case GL_ATOMIC_COUNTER_BUFFER_BINDING:
2504af69d88dSmrg      if (!ctx->Extensions.ARB_shader_atomic_counters)
2505af69d88dSmrg         goto invalid_enum;
2506af69d88dSmrg      if (index >= ctx->Const.MaxAtomicBufferBindings)
2507af69d88dSmrg         goto invalid_value;
2508af69d88dSmrg      v->value_int = ctx->AtomicBufferBindings[index].BufferObject->Name;
2509af69d88dSmrg      return TYPE_INT;
2510af69d88dSmrg
2511af69d88dSmrg   case GL_ATOMIC_COUNTER_BUFFER_START:
2512af69d88dSmrg      if (!ctx->Extensions.ARB_shader_atomic_counters)
2513af69d88dSmrg         goto invalid_enum;
2514af69d88dSmrg      if (index >= ctx->Const.MaxAtomicBufferBindings)
2515af69d88dSmrg         goto invalid_value;
251601e04c3fSmrg      v->value_int64 = ctx->AtomicBufferBindings[index].Offset < 0 ? 0 :
251701e04c3fSmrg                       ctx->AtomicBufferBindings[index].Offset;
2518af69d88dSmrg      return TYPE_INT64;
2519af69d88dSmrg
2520af69d88dSmrg   case GL_ATOMIC_COUNTER_BUFFER_SIZE:
2521af69d88dSmrg      if (!ctx->Extensions.ARB_shader_atomic_counters)
2522af69d88dSmrg         goto invalid_enum;
2523af69d88dSmrg      if (index >= ctx->Const.MaxAtomicBufferBindings)
2524af69d88dSmrg         goto invalid_value;
252501e04c3fSmrg      v->value_int64 = ctx->AtomicBufferBindings[index].Size < 0 ? 0 :
252601e04c3fSmrg                       ctx->AtomicBufferBindings[index].Size;
2527af69d88dSmrg      return TYPE_INT64;
2528af69d88dSmrg
2529af69d88dSmrg   case GL_VERTEX_BINDING_DIVISOR:
253001e04c3fSmrg      if ((!_mesa_is_desktop_gl(ctx) || !ctx->Extensions.ARB_instanced_arrays) &&
253101e04c3fSmrg          !_mesa_is_gles31(ctx))
2532af69d88dSmrg          goto invalid_enum;
2533af69d88dSmrg      if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs)
2534af69d88dSmrg          goto invalid_value;
253501e04c3fSmrg      v->value_int = ctx->Array.VAO->BufferBinding[VERT_ATTRIB_GENERIC(index)].InstanceDivisor;
2536af69d88dSmrg      return TYPE_INT;
2537af69d88dSmrg
2538af69d88dSmrg   case GL_VERTEX_BINDING_OFFSET:
253901e04c3fSmrg      if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles31(ctx))
2540af69d88dSmrg          goto invalid_enum;
2541af69d88dSmrg      if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs)
2542af69d88dSmrg          goto invalid_value;
254301e04c3fSmrg      v->value_int = ctx->Array.VAO->BufferBinding[VERT_ATTRIB_GENERIC(index)].Offset;
2544af69d88dSmrg      return TYPE_INT;
2545af69d88dSmrg
2546af69d88dSmrg   case GL_VERTEX_BINDING_STRIDE:
254701e04c3fSmrg      if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles31(ctx))
2548af69d88dSmrg          goto invalid_enum;
2549af69d88dSmrg      if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs)
2550af69d88dSmrg          goto invalid_value;
255101e04c3fSmrg      v->value_int = ctx->Array.VAO->BufferBinding[VERT_ATTRIB_GENERIC(index)].Stride;
255201e04c3fSmrg      return TYPE_INT;
255301e04c3fSmrg
255401e04c3fSmrg   case GL_VERTEX_BINDING_BUFFER:
255501e04c3fSmrg      if (ctx->API == API_OPENGLES2 && ctx->Version < 31)
255601e04c3fSmrg         goto invalid_enum;
255701e04c3fSmrg      if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs)
255801e04c3fSmrg         goto invalid_value;
255901e04c3fSmrg      v->value_int = ctx->Array.VAO->BufferBinding[VERT_ATTRIB_GENERIC(index)].BufferObj->Name;
256001e04c3fSmrg      return TYPE_INT;
2561af69d88dSmrg
2562af69d88dSmrg   /* ARB_shader_image_load_store */
2563af69d88dSmrg   case GL_IMAGE_BINDING_NAME: {
2564af69d88dSmrg      struct gl_texture_object *t;
2565af69d88dSmrg
2566af69d88dSmrg      if (!ctx->Extensions.ARB_shader_image_load_store)
2567af69d88dSmrg         goto invalid_enum;
2568af69d88dSmrg      if (index >= ctx->Const.MaxImageUnits)
2569af69d88dSmrg         goto invalid_value;
2570af69d88dSmrg
2571af69d88dSmrg      t = ctx->ImageUnits[index].TexObj;
2572af69d88dSmrg      v->value_int = (t ? t->Name : 0);
2573af69d88dSmrg      return TYPE_INT;
2574af69d88dSmrg   }
2575af69d88dSmrg
2576af69d88dSmrg   case GL_IMAGE_BINDING_LEVEL:
2577af69d88dSmrg      if (!ctx->Extensions.ARB_shader_image_load_store)
2578af69d88dSmrg         goto invalid_enum;
2579af69d88dSmrg      if (index >= ctx->Const.MaxImageUnits)
2580af69d88dSmrg         goto invalid_value;
2581af69d88dSmrg
2582af69d88dSmrg      v->value_int = ctx->ImageUnits[index].Level;
2583af69d88dSmrg      return TYPE_INT;
2584af69d88dSmrg
2585af69d88dSmrg   case GL_IMAGE_BINDING_LAYERED:
2586af69d88dSmrg      if (!ctx->Extensions.ARB_shader_image_load_store)
2587af69d88dSmrg         goto invalid_enum;
2588af69d88dSmrg      if (index >= ctx->Const.MaxImageUnits)
2589af69d88dSmrg         goto invalid_value;
2590af69d88dSmrg
2591af69d88dSmrg      v->value_int = ctx->ImageUnits[index].Layered;
2592af69d88dSmrg      return TYPE_INT;
2593af69d88dSmrg
2594af69d88dSmrg   case GL_IMAGE_BINDING_LAYER:
2595af69d88dSmrg      if (!ctx->Extensions.ARB_shader_image_load_store)
2596af69d88dSmrg         goto invalid_enum;
2597af69d88dSmrg      if (index >= ctx->Const.MaxImageUnits)
2598af69d88dSmrg         goto invalid_value;
2599af69d88dSmrg
2600af69d88dSmrg      v->value_int = ctx->ImageUnits[index].Layer;
2601af69d88dSmrg      return TYPE_INT;
2602af69d88dSmrg
2603af69d88dSmrg   case GL_IMAGE_BINDING_ACCESS:
2604af69d88dSmrg      if (!ctx->Extensions.ARB_shader_image_load_store)
2605af69d88dSmrg         goto invalid_enum;
2606af69d88dSmrg      if (index >= ctx->Const.MaxImageUnits)
2607af69d88dSmrg         goto invalid_value;
2608af69d88dSmrg
2609af69d88dSmrg      v->value_int = ctx->ImageUnits[index].Access;
2610af69d88dSmrg      return TYPE_INT;
2611af69d88dSmrg
2612af69d88dSmrg   case GL_IMAGE_BINDING_FORMAT:
2613af69d88dSmrg      if (!ctx->Extensions.ARB_shader_image_load_store)
2614af69d88dSmrg         goto invalid_enum;
2615af69d88dSmrg      if (index >= ctx->Const.MaxImageUnits)
2616af69d88dSmrg         goto invalid_value;
2617af69d88dSmrg
2618af69d88dSmrg      v->value_int = ctx->ImageUnits[index].Format;
2619af69d88dSmrg      return TYPE_INT;
2620af69d88dSmrg
262101e04c3fSmrg   /* ARB_direct_state_access */
262201e04c3fSmrg   case GL_TEXTURE_BINDING_1D:
262301e04c3fSmrg   case GL_TEXTURE_BINDING_1D_ARRAY:
262401e04c3fSmrg   case GL_TEXTURE_BINDING_2D:
262501e04c3fSmrg   case GL_TEXTURE_BINDING_2D_ARRAY:
262601e04c3fSmrg   case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
262701e04c3fSmrg   case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY:
262801e04c3fSmrg   case GL_TEXTURE_BINDING_3D:
262901e04c3fSmrg   case GL_TEXTURE_BINDING_BUFFER:
263001e04c3fSmrg   case GL_TEXTURE_BINDING_CUBE_MAP:
263101e04c3fSmrg   case GL_TEXTURE_BINDING_CUBE_MAP_ARRAY:
263201e04c3fSmrg   case GL_TEXTURE_BINDING_RECTANGLE: {
263301e04c3fSmrg      int target;
263401e04c3fSmrg
263501e04c3fSmrg      if (ctx->API != API_OPENGL_CORE)
263601e04c3fSmrg         goto invalid_enum;
263701e04c3fSmrg      target = tex_binding_to_index(ctx, pname);
263801e04c3fSmrg      if (target < 0)
263901e04c3fSmrg         goto invalid_enum;
264001e04c3fSmrg      if (index >= _mesa_max_tex_unit(ctx))
264101e04c3fSmrg         goto invalid_value;
264201e04c3fSmrg
264301e04c3fSmrg      v->value_int = ctx->Texture.Unit[index].CurrentTex[target]->Name;
264401e04c3fSmrg      return TYPE_INT;
264501e04c3fSmrg   }
264601e04c3fSmrg
264701e04c3fSmrg   case GL_SAMPLER_BINDING: {
264801e04c3fSmrg      struct gl_sampler_object *samp;
264901e04c3fSmrg
265001e04c3fSmrg      if (!_mesa_is_desktop_gl(ctx) || ctx->Version < 33)
265101e04c3fSmrg         goto invalid_enum;
265201e04c3fSmrg      if (index >= _mesa_max_tex_unit(ctx))
265301e04c3fSmrg         goto invalid_value;
265401e04c3fSmrg
265501e04c3fSmrg      samp = ctx->Texture.Unit[index].Sampler;
265601e04c3fSmrg      v->value_int = samp ? samp->Name : 0;
265701e04c3fSmrg      return TYPE_INT;
265801e04c3fSmrg   }
265901e04c3fSmrg
2660af69d88dSmrg   case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
266101e04c3fSmrg      if (!_mesa_has_compute_shaders(ctx))
2662af69d88dSmrg         goto invalid_enum;
2663af69d88dSmrg      if (index >= 3)
2664af69d88dSmrg         goto invalid_value;
2665af69d88dSmrg      v->value_int = ctx->Const.MaxComputeWorkGroupCount[index];
2666af69d88dSmrg      return TYPE_INT;
2667af69d88dSmrg
2668af69d88dSmrg   case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
266901e04c3fSmrg      if (!_mesa_has_compute_shaders(ctx))
2670af69d88dSmrg         goto invalid_enum;
2671af69d88dSmrg      if (index >= 3)
2672af69d88dSmrg         goto invalid_value;
2673af69d88dSmrg      v->value_int = ctx->Const.MaxComputeWorkGroupSize[index];
26743464ebd5Sriastradh      return TYPE_INT;
267501e04c3fSmrg
267601e04c3fSmrg   /* ARB_compute_variable_group_size */
267701e04c3fSmrg   case GL_MAX_COMPUTE_VARIABLE_GROUP_SIZE_ARB:
267801e04c3fSmrg      if (!ctx->Extensions.ARB_compute_variable_group_size)
267901e04c3fSmrg         goto invalid_enum;
268001e04c3fSmrg      if (index >= 3)
268101e04c3fSmrg         goto invalid_value;
268201e04c3fSmrg      v->value_int = ctx->Const.MaxComputeVariableGroupSize[index];
268301e04c3fSmrg      return TYPE_INT;
268401e04c3fSmrg
268501e04c3fSmrg   /* GL_EXT_external_objects */
268601e04c3fSmrg   case GL_NUM_DEVICE_UUIDS_EXT:
268701e04c3fSmrg      v->value_int = 1;
268801e04c3fSmrg      return TYPE_INT;
268901e04c3fSmrg   case GL_DRIVER_UUID_EXT:
269001e04c3fSmrg      if (index >= 1)
269101e04c3fSmrg         goto invalid_value;
269201e04c3fSmrg      _mesa_get_driver_uuid(ctx, v->value_int_4);
269301e04c3fSmrg      return TYPE_INT_4;
269401e04c3fSmrg   case GL_DEVICE_UUID_EXT:
269501e04c3fSmrg      if (index >= 1)
269601e04c3fSmrg         goto invalid_value;
269701e04c3fSmrg      _mesa_get_device_uuid(ctx, v->value_int_4);
269801e04c3fSmrg      return TYPE_INT_4;
26993464ebd5Sriastradh   }
27003464ebd5Sriastradh
27013464ebd5Sriastradh invalid_enum:
27023464ebd5Sriastradh   _mesa_error(ctx, GL_INVALID_ENUM, "%s(pname=%s)", func,
270301e04c3fSmrg               _mesa_enum_to_string(pname));
27043464ebd5Sriastradh   return TYPE_INVALID;
27053464ebd5Sriastradh invalid_value:
27063464ebd5Sriastradh   _mesa_error(ctx, GL_INVALID_VALUE, "%s(pname=%s)", func,
270701e04c3fSmrg               _mesa_enum_to_string(pname));
27083464ebd5Sriastradh   return TYPE_INVALID;
27093464ebd5Sriastradh}
27103464ebd5Sriastradh
27113464ebd5Sriastradhvoid GLAPIENTRY
2712af69d88dSmrg_mesa_GetBooleani_v( GLenum pname, GLuint index, GLboolean *params )
27133464ebd5Sriastradh{
27143464ebd5Sriastradh   union value v;
27153464ebd5Sriastradh   enum value_type type =
2716af69d88dSmrg      find_value_indexed("glGetBooleani_v", pname, index, &v);
27173464ebd5Sriastradh
27183464ebd5Sriastradh   switch (type) {
27193464ebd5Sriastradh   case TYPE_INT:
272001e04c3fSmrg   case TYPE_UINT:
27213464ebd5Sriastradh      params[0] = INT_TO_BOOLEAN(v.value_int);
27223464ebd5Sriastradh      break;
27233464ebd5Sriastradh   case TYPE_INT_4:
272401e04c3fSmrg   case TYPE_UINT_4:
27253464ebd5Sriastradh      params[0] = INT_TO_BOOLEAN(v.value_int_4[0]);
27263464ebd5Sriastradh      params[1] = INT_TO_BOOLEAN(v.value_int_4[1]);
27273464ebd5Sriastradh      params[2] = INT_TO_BOOLEAN(v.value_int_4[2]);
27283464ebd5Sriastradh      params[3] = INT_TO_BOOLEAN(v.value_int_4[3]);
27293464ebd5Sriastradh      break;
27303464ebd5Sriastradh   case TYPE_INT64:
2731af69d88dSmrg      params[0] = INT64_TO_BOOLEAN(v.value_int64);
27323464ebd5Sriastradh      break;
27333464ebd5Sriastradh   default:
27343464ebd5Sriastradh      ; /* nothing - GL error was recorded */
27353464ebd5Sriastradh   }
27363464ebd5Sriastradh}
27373464ebd5Sriastradh
27383464ebd5Sriastradhvoid GLAPIENTRY
2739af69d88dSmrg_mesa_GetIntegeri_v( GLenum pname, GLuint index, GLint *params )
27403464ebd5Sriastradh{
27413464ebd5Sriastradh   union value v;
27423464ebd5Sriastradh   enum value_type type =
2743af69d88dSmrg      find_value_indexed("glGetIntegeri_v", pname, index, &v);
27443464ebd5Sriastradh
27453464ebd5Sriastradh   switch (type) {
2746af69d88dSmrg   case TYPE_FLOAT_4:
2747af69d88dSmrg   case TYPE_FLOATN_4:
2748af69d88dSmrg      params[3] = IROUND(v.value_float_4[3]);
2749af69d88dSmrg   case TYPE_FLOAT_3:
2750af69d88dSmrg   case TYPE_FLOATN_3:
2751af69d88dSmrg      params[2] = IROUND(v.value_float_4[2]);
2752af69d88dSmrg   case TYPE_FLOAT_2:
2753af69d88dSmrg   case TYPE_FLOATN_2:
2754af69d88dSmrg      params[1] = IROUND(v.value_float_4[1]);
2755af69d88dSmrg   case TYPE_FLOAT:
2756af69d88dSmrg   case TYPE_FLOATN:
2757af69d88dSmrg      params[0] = IROUND(v.value_float_4[0]);
2758af69d88dSmrg      break;
2759af69d88dSmrg
2760af69d88dSmrg   case TYPE_DOUBLEN_2:
2761af69d88dSmrg      params[1] = IROUND(v.value_double_2[1]);
2762af69d88dSmrg   case TYPE_DOUBLEN:
2763af69d88dSmrg      params[0] = IROUND(v.value_double_2[0]);
2764af69d88dSmrg      break;
2765af69d88dSmrg
27663464ebd5Sriastradh   case TYPE_INT:
276701e04c3fSmrg   case TYPE_UINT:
27683464ebd5Sriastradh      params[0] = v.value_int;
27693464ebd5Sriastradh      break;
27703464ebd5Sriastradh   case TYPE_INT_4:
277101e04c3fSmrg   case TYPE_UINT_4:
27723464ebd5Sriastradh      params[0] = v.value_int_4[0];
27733464ebd5Sriastradh      params[1] = v.value_int_4[1];
27743464ebd5Sriastradh      params[2] = v.value_int_4[2];
27753464ebd5Sriastradh      params[3] = v.value_int_4[3];
27763464ebd5Sriastradh      break;
27773464ebd5Sriastradh   case TYPE_INT64:
2778af69d88dSmrg      params[0] = INT64_TO_INT(v.value_int64);
27793464ebd5Sriastradh      break;
27803464ebd5Sriastradh   default:
27813464ebd5Sriastradh      ; /* nothing - GL error was recorded */
27823464ebd5Sriastradh   }
27833464ebd5Sriastradh}
27843464ebd5Sriastradh
27853464ebd5Sriastradhvoid GLAPIENTRY
2786af69d88dSmrg_mesa_GetInteger64i_v( GLenum pname, GLuint index, GLint64 *params )
27873464ebd5Sriastradh{
27883464ebd5Sriastradh   union value v;
27893464ebd5Sriastradh   enum value_type type =
2790af69d88dSmrg      find_value_indexed("glGetInteger64i_v", pname, index, &v);
27913464ebd5Sriastradh
27923464ebd5Sriastradh   switch (type) {
27933464ebd5Sriastradh   case TYPE_INT:
27943464ebd5Sriastradh      params[0] = v.value_int;
27953464ebd5Sriastradh      break;
27963464ebd5Sriastradh   case TYPE_INT_4:
27973464ebd5Sriastradh      params[0] = v.value_int_4[0];
27983464ebd5Sriastradh      params[1] = v.value_int_4[1];
27993464ebd5Sriastradh      params[2] = v.value_int_4[2];
28003464ebd5Sriastradh      params[3] = v.value_int_4[3];
28013464ebd5Sriastradh      break;
280201e04c3fSmrg   case TYPE_UINT:
280301e04c3fSmrg      params[0] = (GLuint) v.value_int;
280401e04c3fSmrg      break;
280501e04c3fSmrg   case TYPE_UINT_4:
280601e04c3fSmrg      params[0] = (GLuint) v.value_int_4[0];
280701e04c3fSmrg      params[1] = (GLuint) v.value_int_4[1];
280801e04c3fSmrg      params[2] = (GLuint) v.value_int_4[2];
280901e04c3fSmrg      params[3] = (GLuint) v.value_int_4[3];
281001e04c3fSmrg      break;
28113464ebd5Sriastradh   case TYPE_INT64:
2812af69d88dSmrg      params[0] = v.value_int64;
28133464ebd5Sriastradh      break;
28143464ebd5Sriastradh   default:
28153464ebd5Sriastradh      ; /* nothing - GL error was recorded */
2816cdc920a0Smrg   }
2817cdc920a0Smrg}
2818cdc920a0Smrg
2819af69d88dSmrgvoid GLAPIENTRY
2820af69d88dSmrg_mesa_GetFloati_v(GLenum pname, GLuint index, GLfloat *params)
2821af69d88dSmrg{
2822af69d88dSmrg   int i;
2823af69d88dSmrg   GLmatrix *m;
2824af69d88dSmrg   union value v;
2825af69d88dSmrg   enum value_type type =
2826af69d88dSmrg      find_value_indexed("glGetFloati_v", pname, index, &v);
2827af69d88dSmrg
2828af69d88dSmrg   switch (type) {
2829af69d88dSmrg   case TYPE_FLOAT_4:
2830af69d88dSmrg   case TYPE_FLOATN_4:
2831af69d88dSmrg      params[3] = v.value_float_4[3];
2832af69d88dSmrg   case TYPE_FLOAT_3:
2833af69d88dSmrg   case TYPE_FLOATN_3:
2834af69d88dSmrg      params[2] = v.value_float_4[2];
2835af69d88dSmrg   case TYPE_FLOAT_2:
2836af69d88dSmrg   case TYPE_FLOATN_2:
2837af69d88dSmrg      params[1] = v.value_float_4[1];
2838af69d88dSmrg   case TYPE_FLOAT:
2839af69d88dSmrg   case TYPE_FLOATN:
2840af69d88dSmrg      params[0] = v.value_float_4[0];
2841af69d88dSmrg      break;
2842af69d88dSmrg
2843af69d88dSmrg   case TYPE_DOUBLEN_2:
2844af69d88dSmrg      params[1] = (GLfloat) v.value_double_2[1];
2845af69d88dSmrg   case TYPE_DOUBLEN:
2846af69d88dSmrg      params[0] = (GLfloat) v.value_double_2[0];
2847af69d88dSmrg      break;
2848af69d88dSmrg
2849af69d88dSmrg   case TYPE_INT_4:
2850af69d88dSmrg      params[3] = (GLfloat) v.value_int_4[3];
2851af69d88dSmrg   case TYPE_INT_3:
2852af69d88dSmrg      params[2] = (GLfloat) v.value_int_4[2];
2853af69d88dSmrg   case TYPE_INT_2:
2854af69d88dSmrg   case TYPE_ENUM_2:
2855af69d88dSmrg      params[1] = (GLfloat) v.value_int_4[1];
2856af69d88dSmrg   case TYPE_INT:
2857af69d88dSmrg   case TYPE_ENUM:
285801e04c3fSmrg   case TYPE_ENUM16:
2859af69d88dSmrg      params[0] = (GLfloat) v.value_int_4[0];
2860af69d88dSmrg      break;
2861af69d88dSmrg
2862af69d88dSmrg   case TYPE_INT_N:
2863af69d88dSmrg      for (i = 0; i < v.value_int_n.n; i++)
286401e04c3fSmrg         params[i] = (GLfloat) v.value_int_n.ints[i];
286501e04c3fSmrg      break;
286601e04c3fSmrg
286701e04c3fSmrg   case TYPE_UINT_4:
286801e04c3fSmrg      params[3] = (GLfloat) ((GLuint) v.value_int_4[3]);
286901e04c3fSmrg   case TYPE_UINT_3:
287001e04c3fSmrg      params[2] = (GLfloat) ((GLuint) v.value_int_4[2]);
287101e04c3fSmrg   case TYPE_UINT_2:
287201e04c3fSmrg      params[1] = (GLfloat) ((GLuint) v.value_int_4[1]);
287301e04c3fSmrg   case TYPE_UINT:
287401e04c3fSmrg      params[0] = (GLfloat) ((GLuint) v.value_int_4[0]);
2875af69d88dSmrg      break;
2876af69d88dSmrg
2877af69d88dSmrg   case TYPE_INT64:
2878af69d88dSmrg      params[0] = (GLfloat) v.value_int64;
2879af69d88dSmrg      break;
2880af69d88dSmrg
2881af69d88dSmrg   case TYPE_BOOLEAN:
2882af69d88dSmrg      params[0] = BOOLEAN_TO_FLOAT(v.value_bool);
2883af69d88dSmrg      break;
2884af69d88dSmrg
288501e04c3fSmrg   case TYPE_UBYTE:
288601e04c3fSmrg      params[0] = (GLfloat) v.value_ubyte;
288701e04c3fSmrg      break;
288801e04c3fSmrg
288901e04c3fSmrg   case TYPE_SHORT:
289001e04c3fSmrg      params[0] = (GLfloat) v.value_short;
289101e04c3fSmrg      break;
289201e04c3fSmrg
2893af69d88dSmrg   case TYPE_MATRIX:
2894af69d88dSmrg      m = *(GLmatrix **) &v;
2895af69d88dSmrg      for (i = 0; i < 16; i++)
289601e04c3fSmrg         params[i] = m->m[i];
2897af69d88dSmrg      break;
2898af69d88dSmrg
2899af69d88dSmrg   case TYPE_MATRIX_T:
2900af69d88dSmrg      m = *(GLmatrix **) &v;
2901af69d88dSmrg      for (i = 0; i < 16; i++)
290201e04c3fSmrg         params[i] = m->m[transpose[i]];
2903af69d88dSmrg      break;
2904af69d88dSmrg
2905af69d88dSmrg   default:
2906af69d88dSmrg      ;
2907af69d88dSmrg   }
2908af69d88dSmrg}
2909af69d88dSmrg
2910af69d88dSmrgvoid GLAPIENTRY
2911af69d88dSmrg_mesa_GetDoublei_v(GLenum pname, GLuint index, GLdouble *params)
2912af69d88dSmrg{
2913af69d88dSmrg   int i;
2914af69d88dSmrg   GLmatrix *m;
2915af69d88dSmrg   union value v;
2916af69d88dSmrg   enum value_type type =
2917af69d88dSmrg      find_value_indexed("glGetDoublei_v", pname, index, &v);
2918af69d88dSmrg
2919af69d88dSmrg   switch (type) {
2920af69d88dSmrg   case TYPE_FLOAT_4:
2921af69d88dSmrg   case TYPE_FLOATN_4:
2922af69d88dSmrg      params[3] = (GLdouble) v.value_float_4[3];
2923af69d88dSmrg   case TYPE_FLOAT_3:
2924af69d88dSmrg   case TYPE_FLOATN_3:
2925af69d88dSmrg      params[2] = (GLdouble) v.value_float_4[2];
2926af69d88dSmrg   case TYPE_FLOAT_2:
2927af69d88dSmrg   case TYPE_FLOATN_2:
2928af69d88dSmrg      params[1] = (GLdouble) v.value_float_4[1];
2929af69d88dSmrg   case TYPE_FLOAT:
2930af69d88dSmrg   case TYPE_FLOATN:
2931af69d88dSmrg      params[0] = (GLdouble) v.value_float_4[0];
2932af69d88dSmrg      break;
2933af69d88dSmrg
2934af69d88dSmrg   case TYPE_DOUBLEN_2:
2935af69d88dSmrg      params[1] = v.value_double_2[1];
2936af69d88dSmrg   case TYPE_DOUBLEN:
2937af69d88dSmrg      params[0] = v.value_double_2[0];
2938af69d88dSmrg      break;
2939af69d88dSmrg
2940af69d88dSmrg   case TYPE_INT_4:
2941af69d88dSmrg      params[3] = (GLdouble) v.value_int_4[3];
2942af69d88dSmrg   case TYPE_INT_3:
2943af69d88dSmrg      params[2] = (GLdouble) v.value_int_4[2];
2944af69d88dSmrg   case TYPE_INT_2:
2945af69d88dSmrg   case TYPE_ENUM_2:
2946af69d88dSmrg      params[1] = (GLdouble) v.value_int_4[1];
2947af69d88dSmrg   case TYPE_INT:
2948af69d88dSmrg   case TYPE_ENUM:
294901e04c3fSmrg   case TYPE_ENUM16:
2950af69d88dSmrg      params[0] = (GLdouble) v.value_int_4[0];
2951af69d88dSmrg      break;
2952af69d88dSmrg
2953af69d88dSmrg   case TYPE_INT_N:
2954af69d88dSmrg      for (i = 0; i < v.value_int_n.n; i++)
295501e04c3fSmrg         params[i] = (GLdouble) v.value_int_n.ints[i];
295601e04c3fSmrg      break;
295701e04c3fSmrg
295801e04c3fSmrg   case TYPE_UINT_4:
295901e04c3fSmrg      params[3] = (GLdouble) ((GLuint) v.value_int_4[3]);
296001e04c3fSmrg   case TYPE_UINT_3:
296101e04c3fSmrg      params[2] = (GLdouble) ((GLuint) v.value_int_4[2]);
296201e04c3fSmrg   case TYPE_UINT_2:
296301e04c3fSmrg      params[1] = (GLdouble) ((GLuint) v.value_int_4[1]);
296401e04c3fSmrg   case TYPE_UINT:
296501e04c3fSmrg      params[0] = (GLdouble) ((GLuint) v.value_int_4[0]);
2966af69d88dSmrg      break;
2967af69d88dSmrg
2968af69d88dSmrg   case TYPE_INT64:
2969af69d88dSmrg      params[0] = (GLdouble) v.value_int64;
2970af69d88dSmrg      break;
2971af69d88dSmrg
2972af69d88dSmrg   case TYPE_BOOLEAN:
2973af69d88dSmrg      params[0] = (GLdouble) BOOLEAN_TO_FLOAT(v.value_bool);
2974af69d88dSmrg      break;
2975af69d88dSmrg
297601e04c3fSmrg   case TYPE_UBYTE:
297701e04c3fSmrg      params[0] = (GLdouble) v.value_ubyte;
297801e04c3fSmrg      break;
297901e04c3fSmrg
298001e04c3fSmrg   case TYPE_SHORT:
298101e04c3fSmrg      params[0] = (GLdouble) v.value_short;
298201e04c3fSmrg      break;
298301e04c3fSmrg
2984af69d88dSmrg   case TYPE_MATRIX:
2985af69d88dSmrg      m = *(GLmatrix **) &v;
2986af69d88dSmrg      for (i = 0; i < 16; i++)
298701e04c3fSmrg         params[i] = (GLdouble) m->m[i];
2988af69d88dSmrg      break;
2989af69d88dSmrg
2990af69d88dSmrg   case TYPE_MATRIX_T:
2991af69d88dSmrg      m = *(GLmatrix **) &v;
2992af69d88dSmrg      for (i = 0; i < 16; i++)
299301e04c3fSmrg         params[i] = (GLdouble) m->m[transpose[i]];
2994af69d88dSmrg      break;
2995af69d88dSmrg
2996af69d88dSmrg   default:
2997af69d88dSmrg      ;
2998af69d88dSmrg   }
2999af69d88dSmrg}
3000af69d88dSmrg
300101e04c3fSmrgvoid GLAPIENTRY
300201e04c3fSmrg_mesa_GetUnsignedBytei_vEXT(GLenum target, GLuint index, GLubyte *data)
300301e04c3fSmrg{
300401e04c3fSmrg   GLsizei size;
300501e04c3fSmrg   union value v;
300601e04c3fSmrg   enum value_type type;
300701e04c3fSmrg   const char *func = "glGetUnsignedBytei_vEXT";
300801e04c3fSmrg
300901e04c3fSmrg   GET_CURRENT_CONTEXT(ctx);
301001e04c3fSmrg
301101e04c3fSmrg   if (!ctx->Extensions.EXT_memory_object) {
301201e04c3fSmrg      _mesa_error(ctx, GL_INVALID_OPERATION, "%s(unsupported)", func);
301301e04c3fSmrg      return;
301401e04c3fSmrg   }
301501e04c3fSmrg
301601e04c3fSmrg   type = find_value_indexed(func, target, index, &v);
301701e04c3fSmrg   size = get_value_size(type, &v);
301801e04c3fSmrg   if (size <= 0) {
301901e04c3fSmrg      _mesa_problem(ctx, "invalid value type in GetUnsignedBytei_vEXT()");
302001e04c3fSmrg   }
302101e04c3fSmrg
302201e04c3fSmrg   switch (type) {
302301e04c3fSmrg   case TYPE_UINT:
302401e04c3fSmrg   case TYPE_INT:
302501e04c3fSmrg   case TYPE_INT_2:
302601e04c3fSmrg   case TYPE_UINT_2:
302701e04c3fSmrg   case TYPE_INT_3:
302801e04c3fSmrg   case TYPE_UINT_3:
302901e04c3fSmrg   case TYPE_INT_4:
303001e04c3fSmrg   case TYPE_UINT_4:
303101e04c3fSmrg   case TYPE_INT64:
303201e04c3fSmrg   case TYPE_ENUM16:
303301e04c3fSmrg   case TYPE_ENUM:
303401e04c3fSmrg   case TYPE_ENUM_2:
303501e04c3fSmrg   case TYPE_BOOLEAN:
303601e04c3fSmrg   case TYPE_UBYTE:
303701e04c3fSmrg   case TYPE_SHORT:
303801e04c3fSmrg   case TYPE_FLOAT:
303901e04c3fSmrg   case TYPE_FLOATN:
304001e04c3fSmrg   case TYPE_FLOAT_2:
304101e04c3fSmrg   case TYPE_FLOATN_2:
304201e04c3fSmrg   case TYPE_FLOAT_3:
304301e04c3fSmrg   case TYPE_FLOATN_3:
304401e04c3fSmrg   case TYPE_FLOAT_4:
304501e04c3fSmrg   case TYPE_FLOATN_4:
304601e04c3fSmrg   case TYPE_FLOAT_8:
304701e04c3fSmrg   case TYPE_DOUBLEN:
304801e04c3fSmrg   case TYPE_DOUBLEN_2:
304901e04c3fSmrg   case TYPE_MATRIX:
305001e04c3fSmrg   case TYPE_MATRIX_T:
305101e04c3fSmrg      memcpy(data, &v.value_int, size);
305201e04c3fSmrg      break;
305301e04c3fSmrg   case TYPE_INT_N:
305401e04c3fSmrg      memcpy(data, &v.value_int_n.ints, size);
305501e04c3fSmrg      break;
305601e04c3fSmrg   default:
305701e04c3fSmrg      break; /* nothing - GL error was recorded */
305801e04c3fSmrg   }
305901e04c3fSmrg}
306001e04c3fSmrg
30613464ebd5Sriastradhvoid GLAPIENTRY
30623464ebd5Sriastradh_mesa_GetFixedv(GLenum pname, GLfixed *params)
30633464ebd5Sriastradh{
30643464ebd5Sriastradh   const struct value_desc *d;
30653464ebd5Sriastradh   union value v;
30663464ebd5Sriastradh   GLmatrix *m;
30673464ebd5Sriastradh   int shift, i;
30683464ebd5Sriastradh   void *p;
30693464ebd5Sriastradh
30703464ebd5Sriastradh   d = find_value("glGetDoublev", pname, &p, &v);
30713464ebd5Sriastradh   switch (d->type) {
30723464ebd5Sriastradh   case TYPE_INVALID:
30733464ebd5Sriastradh      break;
30743464ebd5Sriastradh   case TYPE_CONST:
30753464ebd5Sriastradh      params[0] = INT_TO_FIXED(d->offset);
30763464ebd5Sriastradh      break;
30773464ebd5Sriastradh
30783464ebd5Sriastradh   case TYPE_FLOAT_4:
30793464ebd5Sriastradh   case TYPE_FLOATN_4:
30803464ebd5Sriastradh      params[3] = FLOAT_TO_FIXED(((GLfloat *) p)[3]);
30813464ebd5Sriastradh   case TYPE_FLOAT_3:
30823464ebd5Sriastradh   case TYPE_FLOATN_3:
30833464ebd5Sriastradh      params[2] = FLOAT_TO_FIXED(((GLfloat *) p)[2]);
30843464ebd5Sriastradh   case TYPE_FLOAT_2:
30853464ebd5Sriastradh   case TYPE_FLOATN_2:
30863464ebd5Sriastradh      params[1] = FLOAT_TO_FIXED(((GLfloat *) p)[1]);
30873464ebd5Sriastradh   case TYPE_FLOAT:
30883464ebd5Sriastradh   case TYPE_FLOATN:
30893464ebd5Sriastradh      params[0] = FLOAT_TO_FIXED(((GLfloat *) p)[0]);
30903464ebd5Sriastradh      break;
30913464ebd5Sriastradh
3092af69d88dSmrg   case TYPE_DOUBLEN_2:
3093af69d88dSmrg      params[1] = FLOAT_TO_FIXED(((GLdouble *) p)[1]);
30943464ebd5Sriastradh   case TYPE_DOUBLEN:
30953464ebd5Sriastradh      params[0] = FLOAT_TO_FIXED(((GLdouble *) p)[0]);
30963464ebd5Sriastradh      break;
30973464ebd5Sriastradh
30983464ebd5Sriastradh   case TYPE_INT_4:
309901e04c3fSmrg   case TYPE_UINT_4:
31003464ebd5Sriastradh      params[3] = INT_TO_FIXED(((GLint *) p)[3]);
31013464ebd5Sriastradh   case TYPE_INT_3:
310201e04c3fSmrg   case TYPE_UINT_3:
31033464ebd5Sriastradh      params[2] = INT_TO_FIXED(((GLint *) p)[2]);
31043464ebd5Sriastradh   case TYPE_INT_2:
310501e04c3fSmrg   case TYPE_UINT_2:
31063464ebd5Sriastradh   case TYPE_ENUM_2:
31073464ebd5Sriastradh      params[1] = INT_TO_FIXED(((GLint *) p)[1]);
31083464ebd5Sriastradh   case TYPE_INT:
310901e04c3fSmrg   case TYPE_UINT:
31103464ebd5Sriastradh   case TYPE_ENUM:
31113464ebd5Sriastradh      params[0] = INT_TO_FIXED(((GLint *) p)[0]);
31123464ebd5Sriastradh      break;
31133464ebd5Sriastradh
311401e04c3fSmrg   case TYPE_ENUM16:
311501e04c3fSmrg      params[0] = INT_TO_FIXED((GLint)(((GLenum16 *) p)[0]));
311601e04c3fSmrg      break;
311701e04c3fSmrg
31183464ebd5Sriastradh   case TYPE_INT_N:
31193464ebd5Sriastradh      for (i = 0; i < v.value_int_n.n; i++)
312001e04c3fSmrg         params[i] = INT_TO_FIXED(v.value_int_n.ints[i]);
31213464ebd5Sriastradh      break;
31223464ebd5Sriastradh
31233464ebd5Sriastradh   case TYPE_INT64:
31243464ebd5Sriastradh      params[0] = ((GLint64 *) p)[0];
31253464ebd5Sriastradh      break;
31263464ebd5Sriastradh
31273464ebd5Sriastradh   case TYPE_BOOLEAN:
31283464ebd5Sriastradh      params[0] = BOOLEAN_TO_FIXED(((GLboolean*) p)[0]);
312901e04c3fSmrg      break;
313001e04c3fSmrg
313101e04c3fSmrg   case TYPE_UBYTE:
313201e04c3fSmrg      params[0] = INT_TO_FIXED(((GLubyte *) p)[0]);
313301e04c3fSmrg      break;
313401e04c3fSmrg
313501e04c3fSmrg   case TYPE_SHORT:
313601e04c3fSmrg      params[0] = INT_TO_FIXED(((GLshort *) p)[0]);
313701e04c3fSmrg      break;
31383464ebd5Sriastradh
31393464ebd5Sriastradh   case TYPE_MATRIX:
31403464ebd5Sriastradh      m = *(GLmatrix **) p;
31413464ebd5Sriastradh      for (i = 0; i < 16; i++)
314201e04c3fSmrg         params[i] = FLOAT_TO_FIXED(m->m[i]);
31433464ebd5Sriastradh      break;
31443464ebd5Sriastradh
31453464ebd5Sriastradh   case TYPE_MATRIX_T:
31463464ebd5Sriastradh      m = *(GLmatrix **) p;
31473464ebd5Sriastradh      for (i = 0; i < 16; i++)
314801e04c3fSmrg         params[i] = FLOAT_TO_FIXED(m->m[transpose[i]]);
31493464ebd5Sriastradh      break;
31503464ebd5Sriastradh
31513464ebd5Sriastradh   case TYPE_BIT_0:
31523464ebd5Sriastradh   case TYPE_BIT_1:
31533464ebd5Sriastradh   case TYPE_BIT_2:
31543464ebd5Sriastradh   case TYPE_BIT_3:
31553464ebd5Sriastradh   case TYPE_BIT_4:
31563464ebd5Sriastradh   case TYPE_BIT_5:
3157af69d88dSmrg   case TYPE_BIT_6:
3158af69d88dSmrg   case TYPE_BIT_7:
31593464ebd5Sriastradh      shift = d->type - TYPE_BIT_0;
31603464ebd5Sriastradh      params[0] = BOOLEAN_TO_FIXED((*(GLbitfield *) p >> shift) & 1);
31613464ebd5Sriastradh      break;
31623464ebd5Sriastradh   }
31633464ebd5Sriastradh}
3164