• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2010  Brian Paul   All Rights Reserved.
3  * Copyright (C) 2010  Intel Corporation
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included
13  * in all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
19  * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21  *
22  * Author: Kristian Høgsberg <krh@bitplanet.net>
23  */
24 
25 #include "glheader.h"
26 #include "context.h"
27 #include "enable.h"
28 #include "enums.h"
29 #include "extensions.h"
30 #include "get.h"
31 #include "macros.h"
32 #include "mfeatures.h"
33 #include "mtypes.h"
34 #include "state.h"
35 #include "texcompress.h"
36 #include "framebuffer.h"
37 
38 /* This is a table driven implemetation of the glGet*v() functions.
39  * The basic idea is that most getters just look up an int somewhere
40  * in struct gl_context and then convert it to a bool or float according to
41  * which of glGetIntegerv() glGetBooleanv() etc is being called.
42  * Instead of generating code to do this, we can just record the enum
43  * value and the offset into struct gl_context in an array of structs.  Then
44  * in glGet*(), we lookup the struct for the enum in question, and use
45  * the offset to get the int we need.
46  *
47  * Sometimes we need to look up a float, a boolean, a bit in a
48  * bitfield, a matrix or other types instead, so we need to track the
49  * type of the value in struct gl_context.  And sometimes the value isn't in
50  * struct gl_context but in the drawbuffer, the array object, current texture
51  * unit, or maybe it's a computed value.  So we need to also track
52  * where or how to find the value.  Finally, we sometimes need to
53  * check that one of a number of extensions are enabled, the GL
54  * version or flush or call _mesa_update_state().  This is done by
55  * attaching optional extra information to the value description
56  * struct, it's sort of like an array of opcodes that describe extra
57  * checks or actions.
58  *
59  * Putting all this together we end up with struct value_desc below,
60  * and with a couple of macros to help, the table of struct value_desc
61  * is about as concise as the specification in the old python script.
62  */
63 
64 #undef CONST
65 
66 #define FLOAT_TO_BOOLEAN(X)   ( (X) ? GL_TRUE : GL_FALSE )
67 #define FLOAT_TO_FIXED(F)     ( ((F) * 65536.0f > INT_MAX) ? INT_MAX : \
68                                 ((F) * 65536.0f < INT_MIN) ? INT_MIN : \
69                                 (GLint) ((F) * 65536.0f) )
70 
71 #define INT_TO_BOOLEAN(I)     ( (I) ? GL_TRUE : GL_FALSE )
72 #define INT_TO_FIXED(I)       ( ((I) > SHRT_MAX) ? INT_MAX : \
73                                 ((I) < SHRT_MIN) ? INT_MIN : \
74                                 (GLint) ((I) * 65536) )
75 
76 #define INT64_TO_BOOLEAN(I)   ( (I) ? GL_TRUE : GL_FALSE )
77 #define INT64_TO_INT(I)       ( (GLint)((I > INT_MAX) ? INT_MAX : ((I < INT_MIN) ? INT_MIN : (I))) )
78 
79 #define BOOLEAN_TO_INT(B)     ( (GLint) (B) )
80 #define BOOLEAN_TO_INT64(B)   ( (GLint64) (B) )
81 #define BOOLEAN_TO_FLOAT(B)   ( (B) ? 1.0F : 0.0F )
82 #define BOOLEAN_TO_FIXED(B)   ( (GLint) ((B) ? 1 : 0) << 16 )
83 
84 #define ENUM_TO_INT64(E)      ( (GLint64) (E) )
85 #define ENUM_TO_FIXED(E)      (E)
86 
87 enum value_type {
88    TYPE_INVALID,
89    TYPE_API_MASK,
90    TYPE_INT,
91    TYPE_INT_2,
92    TYPE_INT_3,
93    TYPE_INT_4,
94    TYPE_INT_N,
95    TYPE_INT64,
96    TYPE_ENUM,
97    TYPE_ENUM_2,
98    TYPE_BOOLEAN,
99    TYPE_BIT_0,
100    TYPE_BIT_1,
101    TYPE_BIT_2,
102    TYPE_BIT_3,
103    TYPE_BIT_4,
104    TYPE_BIT_5,
105    TYPE_BIT_6,
106    TYPE_BIT_7,
107    TYPE_FLOAT,
108    TYPE_FLOAT_2,
109    TYPE_FLOAT_3,
110    TYPE_FLOAT_4,
111    TYPE_FLOATN,
112    TYPE_FLOATN_2,
113    TYPE_FLOATN_3,
114    TYPE_FLOATN_4,
115    TYPE_DOUBLEN,
116    TYPE_MATRIX,
117    TYPE_MATRIX_T,
118    TYPE_CONST
119 };
120 
121 enum value_location {
122    LOC_BUFFER,
123    LOC_CONTEXT,
124    LOC_ARRAY,
125    LOC_TEXUNIT,
126    LOC_CUSTOM
127 };
128 
129 enum value_extra {
130    EXTRA_END = 0x8000,
131    EXTRA_VERSION_30,
132    EXTRA_VERSION_31,
133    EXTRA_VERSION_32,
134    EXTRA_API_GL,
135    EXTRA_API_ES2,
136    EXTRA_NEW_BUFFERS,
137    EXTRA_NEW_FRAG_CLAMP,
138    EXTRA_VALID_DRAW_BUFFER,
139    EXTRA_VALID_TEXTURE_UNIT,
140    EXTRA_VALID_CLIP_DISTANCE,
141    EXTRA_FLUSH_CURRENT,
142    EXTRA_GLSL_130,
143 };
144 
145 #define NO_EXTRA NULL
146 #define NO_OFFSET 0
147 
148 struct value_desc {
149    GLenum pname;
150    GLubyte location;  /**< enum value_location */
151    GLubyte type;      /**< enum value_type */
152    int offset;
153    const int *extra;
154 };
155 
156 union value {
157    GLfloat value_float;
158    GLfloat value_float_4[4];
159    GLmatrix *value_matrix;
160    GLint value_int;
161    GLint value_int_4[4];
162    GLint64 value_int64;
163    GLenum value_enum;
164 
165    /* Sigh, see GL_COMPRESSED_TEXTURE_FORMATS_ARB handling */
166    struct {
167       GLint n, ints[100];
168    } value_int_n;
169    GLboolean value_bool;
170 };
171 
172 #define BUFFER_FIELD(field, type) \
173    LOC_BUFFER, type, offsetof(struct gl_framebuffer, field)
174 #define CONTEXT_FIELD(field, type) \
175    LOC_CONTEXT, type, offsetof(struct gl_context, field)
176 #define ARRAY_FIELD(field, type) \
177    LOC_ARRAY, type, offsetof(struct gl_array_object, field)
178 #define CONST(value) \
179    LOC_CONTEXT, TYPE_CONST, value
180 
181 #define BUFFER_INT(field) BUFFER_FIELD(field, TYPE_INT)
182 #define BUFFER_ENUM(field) BUFFER_FIELD(field, TYPE_ENUM)
183 #define BUFFER_BOOL(field) BUFFER_FIELD(field, TYPE_BOOLEAN)
184 
185 #define CONTEXT_INT(field) CONTEXT_FIELD(field, TYPE_INT)
186 #define CONTEXT_INT2(field) CONTEXT_FIELD(field, TYPE_INT_2)
187 #define CONTEXT_INT64(field) CONTEXT_FIELD(field, TYPE_INT64)
188 #define CONTEXT_ENUM(field) CONTEXT_FIELD(field, TYPE_ENUM)
189 #define CONTEXT_ENUM2(field) CONTEXT_FIELD(field, TYPE_ENUM_2)
190 #define CONTEXT_BOOL(field) CONTEXT_FIELD(field, TYPE_BOOLEAN)
191 #define CONTEXT_BIT0(field) CONTEXT_FIELD(field, TYPE_BIT_0)
192 #define CONTEXT_BIT1(field) CONTEXT_FIELD(field, TYPE_BIT_1)
193 #define CONTEXT_BIT2(field) CONTEXT_FIELD(field, TYPE_BIT_2)
194 #define CONTEXT_BIT3(field) CONTEXT_FIELD(field, TYPE_BIT_3)
195 #define CONTEXT_BIT4(field) CONTEXT_FIELD(field, TYPE_BIT_4)
196 #define CONTEXT_BIT5(field) CONTEXT_FIELD(field, TYPE_BIT_5)
197 #define CONTEXT_BIT6(field) CONTEXT_FIELD(field, TYPE_BIT_6)
198 #define CONTEXT_BIT7(field) CONTEXT_FIELD(field, TYPE_BIT_7)
199 #define CONTEXT_FLOAT(field) CONTEXT_FIELD(field, TYPE_FLOAT)
200 #define CONTEXT_FLOAT2(field) CONTEXT_FIELD(field, TYPE_FLOAT_2)
201 #define CONTEXT_FLOAT3(field) CONTEXT_FIELD(field, TYPE_FLOAT_3)
202 #define CONTEXT_FLOAT4(field) CONTEXT_FIELD(field, TYPE_FLOAT_4)
203 #define CONTEXT_MATRIX(field) CONTEXT_FIELD(field, TYPE_MATRIX)
204 #define CONTEXT_MATRIX_T(field) CONTEXT_FIELD(field, TYPE_MATRIX_T)
205 
206 #define ARRAY_INT(field) ARRAY_FIELD(field, TYPE_INT)
207 #define ARRAY_ENUM(field) ARRAY_FIELD(field, TYPE_ENUM)
208 #define ARRAY_BOOL(field) ARRAY_FIELD(field, TYPE_BOOLEAN)
209 
210 #define EXT(f)					\
211    offsetof(struct gl_extensions, f)
212 
213 #define EXTRA_EXT(e)				\
214    static const int extra_##e[] = {		\
215       EXT(e), EXTRA_END				\
216    }
217 
218 #define EXTRA_EXT2(e1, e2)			\
219    static const int extra_##e1##_##e2[] = {	\
220       EXT(e1), EXT(e2), EXTRA_END		\
221    }
222 
223 /* The 'extra' mechanism is a way to specify extra checks (such as
224  * extensions or specific gl versions) or actions (flush current, new
225  * buffers) that we need to do before looking up an enum.  We need to
226  * declare them all up front so we can refer to them in the value_desc
227  * structs below. */
228 
229 static const int extra_new_buffers[] = {
230    EXTRA_NEW_BUFFERS,
231    EXTRA_END
232 };
233 
234 static const int extra_new_frag_clamp[] = {
235    EXTRA_NEW_FRAG_CLAMP,
236    EXTRA_END
237 };
238 
239 static const int extra_valid_draw_buffer[] = {
240    EXTRA_VALID_DRAW_BUFFER,
241    EXTRA_END
242 };
243 
244 static const int extra_valid_texture_unit[] = {
245    EXTRA_VALID_TEXTURE_UNIT,
246    EXTRA_END
247 };
248 
249 static const int extra_valid_clip_distance[] = {
250    EXTRA_VALID_CLIP_DISTANCE,
251    EXTRA_END
252 };
253 
254 static const int extra_flush_current_valid_texture_unit[] = {
255    EXTRA_FLUSH_CURRENT,
256    EXTRA_VALID_TEXTURE_UNIT,
257    EXTRA_END
258 };
259 
260 static const int extra_flush_current[] = {
261    EXTRA_FLUSH_CURRENT,
262    EXTRA_END
263 };
264 
265 static const int extra_EXT_secondary_color_flush_current[] = {
266    EXT(EXT_secondary_color),
267    EXTRA_FLUSH_CURRENT,
268    EXTRA_END
269 };
270 
271 static const int extra_EXT_fog_coord_flush_current[] = {
272    EXT(EXT_fog_coord),
273    EXTRA_FLUSH_CURRENT,
274    EXTRA_END
275 };
276 
277 static const int extra_EXT_texture_integer[] = {
278    EXT(EXT_texture_integer),
279    EXTRA_END
280 };
281 
282 static const int extra_GLSL_130[] = {
283    EXTRA_GLSL_130,
284    EXTRA_END
285 };
286 
287 static const int extra_texture_buffer_object[] = {
288    EXTRA_VERSION_31,
289    EXT(ARB_texture_buffer_object),
290    EXTRA_END
291 };
292 
293 static const int extra_ARB_uniform_buffer_object_and_geometry_shader[] = {
294    EXT(ARB_uniform_buffer_object),
295    EXT(ARB_geometry_shader4),
296    EXTRA_END
297 };
298 
299 
300 EXTRA_EXT(ARB_ES2_compatibility);
301 EXTRA_EXT(ARB_texture_cube_map);
302 EXTRA_EXT(MESA_texture_array);
303 EXTRA_EXT2(EXT_secondary_color, ARB_vertex_program);
304 EXTRA_EXT(EXT_secondary_color);
305 EXTRA_EXT(EXT_fog_coord);
306 EXTRA_EXT(NV_fog_distance);
307 EXTRA_EXT(EXT_texture_filter_anisotropic);
308 EXTRA_EXT(IBM_rasterpos_clip);
309 EXTRA_EXT(NV_point_sprite);
310 EXTRA_EXT(NV_vertex_program);
311 EXTRA_EXT(NV_fragment_program);
312 EXTRA_EXT(NV_texture_rectangle);
313 EXTRA_EXT(EXT_stencil_two_side);
314 EXTRA_EXT(NV_light_max_exponent);
315 EXTRA_EXT(EXT_depth_bounds_test);
316 EXTRA_EXT(ARB_depth_clamp);
317 EXTRA_EXT(ATI_fragment_shader);
318 EXTRA_EXT(EXT_framebuffer_blit);
319 EXTRA_EXT(ARB_shader_objects);
320 EXTRA_EXT(EXT_provoking_vertex);
321 EXTRA_EXT(ARB_fragment_shader);
322 EXTRA_EXT(ARB_fragment_program);
323 EXTRA_EXT2(ARB_framebuffer_object, EXT_framebuffer_multisample);
324 EXTRA_EXT(EXT_framebuffer_object);
325 EXTRA_EXT(ARB_seamless_cube_map);
326 EXTRA_EXT(EXT_compiled_vertex_array);
327 EXTRA_EXT(ARB_sync);
328 EXTRA_EXT(ARB_vertex_shader);
329 EXTRA_EXT(EXT_transform_feedback);
330 EXTRA_EXT(ARB_transform_feedback2);
331 EXTRA_EXT(ARB_transform_feedback3);
332 EXTRA_EXT(EXT_pixel_buffer_object);
333 EXTRA_EXT(ARB_vertex_program);
334 EXTRA_EXT2(NV_point_sprite, ARB_point_sprite);
335 EXTRA_EXT2(ARB_fragment_program, NV_fragment_program);
336 EXTRA_EXT2(ARB_vertex_program, NV_vertex_program);
337 EXTRA_EXT2(ARB_vertex_program, ARB_fragment_program);
338 EXTRA_EXT(ARB_geometry_shader4);
339 EXTRA_EXT(ARB_color_buffer_float);
340 EXTRA_EXT(ARB_copy_buffer);
341 EXTRA_EXT(EXT_framebuffer_sRGB);
342 EXTRA_EXT(ARB_texture_buffer_object);
343 EXTRA_EXT(OES_EGL_image_external);
344 EXTRA_EXT(ARB_blend_func_extended);
345 EXTRA_EXT(ARB_uniform_buffer_object);
346 EXTRA_EXT(ARB_timer_query);
347 
348 static const int
349 extra_ARB_vertex_program_ARB_fragment_program_NV_vertex_program[] = {
350    EXT(ARB_vertex_program),
351    EXT(ARB_fragment_program),
352    EXT(NV_vertex_program),
353    EXTRA_END
354 };
355 
356 static const int
357 extra_NV_vertex_program_ARB_vertex_program_ARB_fragment_program_NV_vertex_program[] = {
358    EXT(NV_vertex_program),
359    EXT(ARB_vertex_program),
360    EXT(ARB_fragment_program),
361    EXT(NV_vertex_program),
362    EXTRA_END
363 };
364 
365 static const int
366 extra_NV_primitive_restart[] = {
367    EXT(NV_primitive_restart),
368    EXTRA_END
369 };
370 
371 static const int extra_version_30[] = { EXTRA_VERSION_30, EXTRA_END };
372 static const int extra_version_31[] = { EXTRA_VERSION_31, EXTRA_END };
373 static const int extra_version_32[] = { EXTRA_VERSION_32, EXTRA_END };
374 
375 static const int
376 extra_ARB_vertex_program_api_es2[] = {
377    EXT(ARB_vertex_program),
378    EXTRA_API_ES2,
379    EXTRA_END
380 };
381 
382 /* The ReadBuffer get token is valid under either full GL or under
383  * GLES2 if the NV_read_buffer extension is available. */
384 static const int
385 extra_NV_read_buffer_api_gl[] = {
386    EXT(NV_read_buffer),
387    EXTRA_API_GL,
388    EXTRA_END
389 };
390 
391 #define API_OPENGL_BIT (1 << API_OPENGL)
392 #define API_OPENGLES_BIT (1 << API_OPENGLES)
393 #define API_OPENGLES2_BIT (1 << API_OPENGLES2)
394 #define API_OPENGL_CORE_BIT (1 << API_OPENGL_CORE)
395 
396 /* This is the big table describing all the enums we accept in
397  * glGet*v().  The table is partitioned into six parts: enums
398  * understood by all GL APIs (OpenGL, GLES and GLES2), enums shared
399  * between OpenGL and GLES, enums exclusive to GLES, etc for the
400  * remaining combinations.  When we add the enums to the hash table in
401  * _mesa_init_get_hash(), we only add the enums for the API we're
402  * instantiating and the different sections are guarded by #if
403  * FEATURE_GL etc to make sure we only compile in the enums we may
404  * need. */
405 
406 static const struct value_desc values[] = {
407    /* Enums shared between OpenGL, GLES1 and GLES2 */
408    { 0, 0, TYPE_API_MASK,
409      API_OPENGL_BIT | API_OPENGLES_BIT | API_OPENGLES2_BIT |
410        API_OPENGL_CORE_BIT,
411      NO_EXTRA},
412    { GL_ALPHA_BITS, BUFFER_INT(Visual.alphaBits), extra_new_buffers },
413    { GL_BLEND, CONTEXT_BIT0(Color.BlendEnabled), NO_EXTRA },
414    { GL_BLEND_SRC, CONTEXT_ENUM(Color.Blend[0].SrcRGB), NO_EXTRA },
415    { GL_BLUE_BITS, BUFFER_INT(Visual.blueBits), extra_new_buffers },
416    { GL_COLOR_CLEAR_VALUE, LOC_CUSTOM, TYPE_FLOATN_4, 0, extra_new_frag_clamp },
417    { GL_COLOR_WRITEMASK, LOC_CUSTOM, TYPE_INT_4, 0, NO_EXTRA },
418    { GL_CULL_FACE, CONTEXT_BOOL(Polygon.CullFlag), NO_EXTRA },
419    { GL_CULL_FACE_MODE, CONTEXT_ENUM(Polygon.CullFaceMode), NO_EXTRA },
420    { GL_DEPTH_BITS, BUFFER_INT(Visual.depthBits), NO_EXTRA },
421    { GL_DEPTH_CLEAR_VALUE, CONTEXT_FIELD(Depth.Clear, TYPE_DOUBLEN), NO_EXTRA },
422    { GL_DEPTH_FUNC, CONTEXT_ENUM(Depth.Func), NO_EXTRA },
423    { GL_DEPTH_RANGE, CONTEXT_FIELD(Viewport.Near, TYPE_FLOATN_2), NO_EXTRA },
424    { GL_DEPTH_TEST, CONTEXT_BOOL(Depth.Test), NO_EXTRA },
425    { GL_DEPTH_WRITEMASK, CONTEXT_BOOL(Depth.Mask), NO_EXTRA },
426    { GL_DITHER, CONTEXT_BOOL(Color.DitherFlag), NO_EXTRA },
427    { GL_FRONT_FACE, CONTEXT_ENUM(Polygon.FrontFace), NO_EXTRA },
428    { GL_GREEN_BITS, BUFFER_INT(Visual.greenBits), extra_new_buffers },
429    { GL_LINE_WIDTH, CONTEXT_FLOAT(Line.Width), NO_EXTRA },
430    { GL_ALIASED_LINE_WIDTH_RANGE, CONTEXT_FLOAT2(Const.MinLineWidth), NO_EXTRA },
431    { GL_MAX_ELEMENTS_VERTICES, CONTEXT_INT(Const.MaxArrayLockSize), NO_EXTRA },
432    { GL_MAX_ELEMENTS_INDICES, CONTEXT_INT(Const.MaxArrayLockSize), NO_EXTRA },
433    { GL_MAX_TEXTURE_SIZE, LOC_CUSTOM, TYPE_INT,
434      offsetof(struct gl_context, Const.MaxTextureLevels), NO_EXTRA },
435    { GL_MAX_VIEWPORT_DIMS, CONTEXT_INT2(Const.MaxViewportWidth), NO_EXTRA },
436    { GL_PACK_ALIGNMENT, CONTEXT_INT(Pack.Alignment), NO_EXTRA },
437    { GL_ALIASED_POINT_SIZE_RANGE, CONTEXT_FLOAT2(Const.MinPointSize), NO_EXTRA },
438    { GL_POLYGON_OFFSET_FACTOR, CONTEXT_FLOAT(Polygon.OffsetFactor ), NO_EXTRA },
439    { GL_POLYGON_OFFSET_UNITS, CONTEXT_FLOAT(Polygon.OffsetUnits ), NO_EXTRA },
440    { GL_POLYGON_OFFSET_FILL, CONTEXT_BOOL(Polygon.OffsetFill), NO_EXTRA },
441    { GL_RED_BITS, BUFFER_INT(Visual.redBits), extra_new_buffers },
442    { GL_SCISSOR_BOX, LOC_CUSTOM, TYPE_INT_4, 0, NO_EXTRA },
443    { GL_SCISSOR_TEST, CONTEXT_BOOL(Scissor.Enabled), NO_EXTRA },
444    { GL_STENCIL_BITS, BUFFER_INT(Visual.stencilBits), NO_EXTRA },
445    { GL_STENCIL_CLEAR_VALUE, CONTEXT_INT(Stencil.Clear), NO_EXTRA },
446    { GL_STENCIL_FAIL, LOC_CUSTOM, TYPE_ENUM, NO_OFFSET, NO_EXTRA },
447    { GL_STENCIL_FUNC, LOC_CUSTOM, TYPE_ENUM, NO_OFFSET, NO_EXTRA },
448    { GL_STENCIL_PASS_DEPTH_FAIL, LOC_CUSTOM, TYPE_ENUM, NO_OFFSET, NO_EXTRA },
449    { GL_STENCIL_PASS_DEPTH_PASS, LOC_CUSTOM, TYPE_ENUM, NO_OFFSET, NO_EXTRA },
450    { GL_STENCIL_REF, LOC_CUSTOM, TYPE_INT, NO_OFFSET, NO_EXTRA },
451    { GL_STENCIL_TEST, CONTEXT_BOOL(Stencil.Enabled), NO_EXTRA },
452    { GL_STENCIL_VALUE_MASK, LOC_CUSTOM, TYPE_INT, NO_OFFSET, NO_EXTRA },
453    { GL_STENCIL_WRITEMASK, LOC_CUSTOM, TYPE_INT, NO_OFFSET, NO_EXTRA },
454    { GL_SUBPIXEL_BITS, CONTEXT_INT(Const.SubPixelBits), NO_EXTRA },
455    { GL_TEXTURE_BINDING_2D, LOC_CUSTOM, TYPE_INT, TEXTURE_2D_INDEX, NO_EXTRA },
456    { GL_UNPACK_ALIGNMENT, CONTEXT_INT(Unpack.Alignment), NO_EXTRA },
457    { GL_VIEWPORT, LOC_CUSTOM, TYPE_INT_4, 0, NO_EXTRA },
458 
459    /* GL_ARB_multitexture */
460    { GL_ACTIVE_TEXTURE, LOC_CUSTOM, TYPE_INT, 0, NO_EXTRA },
461 
462    /* Note that all the OES_* extensions require that the Mesa "struct
463     * gl_extensions" include a member with the name of the extension.
464     * That structure does not yet include OES extensions (and we're
465     * not sure whether it will).  If it does, all the OES_*
466     * extensions below should mark the dependency. */
467 
468    /* GL_ARB_texture_cube_map */
469    { GL_TEXTURE_BINDING_CUBE_MAP_ARB, LOC_CUSTOM, TYPE_INT,
470      TEXTURE_CUBE_INDEX, extra_ARB_texture_cube_map },
471    { GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB, LOC_CUSTOM, TYPE_INT,
472      offsetof(struct gl_context, Const.MaxCubeTextureLevels),
473      extra_ARB_texture_cube_map }, /* XXX: OES_texture_cube_map */
474 
475    /* XXX: OES_blend_subtract */
476    { GL_BLEND_SRC_RGB_EXT, CONTEXT_ENUM(Color.Blend[0].SrcRGB), NO_EXTRA },
477    { GL_BLEND_DST_RGB_EXT, CONTEXT_ENUM(Color.Blend[0].DstRGB), NO_EXTRA },
478    { GL_BLEND_SRC_ALPHA_EXT, CONTEXT_ENUM(Color.Blend[0].SrcA), NO_EXTRA },
479    { GL_BLEND_DST_ALPHA_EXT, CONTEXT_ENUM(Color.Blend[0].DstA), NO_EXTRA },
480 
481    /* GL_BLEND_EQUATION_RGB, which is what we're really after, is
482     * defined identically to GL_BLEND_EQUATION. */
483    { GL_BLEND_EQUATION, CONTEXT_ENUM(Color.Blend[0].EquationRGB), NO_EXTRA },
484    { GL_BLEND_EQUATION_ALPHA_EXT, CONTEXT_ENUM(Color.Blend[0].EquationA), NO_EXTRA },
485 
486    /* GL_ARB_texture_compression */
487    { GL_NUM_COMPRESSED_TEXTURE_FORMATS_ARB, LOC_CUSTOM, TYPE_INT, 0, NO_EXTRA },
488    { GL_COMPRESSED_TEXTURE_FORMATS_ARB, LOC_CUSTOM, TYPE_INT_N, 0, NO_EXTRA },
489 
490    /* GL_ARB_multisample */
491    { GL_SAMPLE_ALPHA_TO_COVERAGE_ARB,
492      CONTEXT_BOOL(Multisample.SampleAlphaToCoverage), NO_EXTRA },
493    { GL_SAMPLE_COVERAGE_ARB, CONTEXT_BOOL(Multisample.SampleCoverage), NO_EXTRA },
494    { GL_SAMPLE_COVERAGE_VALUE_ARB,
495      CONTEXT_FLOAT(Multisample.SampleCoverageValue), NO_EXTRA },
496    { GL_SAMPLE_COVERAGE_INVERT_ARB,
497      CONTEXT_BOOL(Multisample.SampleCoverageInvert), NO_EXTRA },
498    { GL_SAMPLE_BUFFERS_ARB, BUFFER_INT(Visual.sampleBuffers), NO_EXTRA },
499    { GL_SAMPLES_ARB, BUFFER_INT(Visual.samples), NO_EXTRA },
500 
501    /* GL_SGIS_generate_mipmap */
502    { GL_GENERATE_MIPMAP_HINT_SGIS, CONTEXT_ENUM(Hint.GenerateMipmap), NO_EXTRA },
503 
504    /* GL_ARB_vertex_buffer_object */
505    { GL_ARRAY_BUFFER_BINDING_ARB, LOC_CUSTOM, TYPE_INT, 0, NO_EXTRA },
506 
507    /* GL_ARB_vertex_buffer_object */
508    /* GL_WEIGHT_ARRAY_BUFFER_BINDING_ARB - not supported */
509    { GL_ELEMENT_ARRAY_BUFFER_BINDING_ARB, LOC_CUSTOM, TYPE_INT, 0, NO_EXTRA },
510 
511    /* GL_ARB_color_buffer_float */
512    { GL_CLAMP_VERTEX_COLOR, CONTEXT_ENUM(Light.ClampVertexColor), extra_ARB_color_buffer_float },
513    { GL_CLAMP_FRAGMENT_COLOR, CONTEXT_ENUM(Color.ClampFragmentColor), extra_ARB_color_buffer_float },
514    { GL_CLAMP_READ_COLOR, CONTEXT_ENUM(Color.ClampReadColor), extra_ARB_color_buffer_float },
515 
516    /* GL_ARB_copy_buffer */
517    { GL_COPY_READ_BUFFER, LOC_CUSTOM, TYPE_INT, 0, extra_ARB_copy_buffer },
518    { GL_COPY_WRITE_BUFFER, LOC_CUSTOM, TYPE_INT, 0, extra_ARB_copy_buffer },
519 
520    /* GL_OES_read_format */
521    { GL_IMPLEMENTATION_COLOR_READ_TYPE_OES, LOC_CUSTOM, TYPE_INT, 0,
522      extra_new_buffers },
523    { GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES, LOC_CUSTOM, TYPE_INT, 0,
524      extra_new_buffers },
525 
526    /* GL_EXT_framebuffer_object */
527    { GL_FRAMEBUFFER_BINDING_EXT, BUFFER_INT(Name),
528      extra_EXT_framebuffer_object },
529    { GL_RENDERBUFFER_BINDING_EXT, LOC_CUSTOM, TYPE_INT, 0,
530      extra_EXT_framebuffer_object },
531    { GL_MAX_RENDERBUFFER_SIZE_EXT, CONTEXT_INT(Const.MaxRenderbufferSize),
532      extra_EXT_framebuffer_object },
533 
534    /* This entry isn't spec'ed for GLES 2, but is needed for Mesa's
535     * GLSL: */
536    { GL_MAX_CLIP_PLANES, CONTEXT_INT(Const.MaxClipPlanes), NO_EXTRA },
537 
538    /* GL_{APPLE,ARB,OES}_vertex_array_object */
539    { GL_VERTEX_ARRAY_BINDING_APPLE, ARRAY_INT(Name), NO_EXTRA },
540 
541    /* GL_EXT_texture_filter_anisotropic */
542    { GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT,
543      CONTEXT_FLOAT(Const.MaxTextureMaxAnisotropy),
544      extra_EXT_texture_filter_anisotropic },
545 
546 #if FEATURE_GL || FEATURE_ES1
547    /* Enums in OpenGL and GLES1 */
548    { 0, 0, TYPE_API_MASK, API_OPENGL_BIT | API_OPENGLES_BIT | API_OPENGL_CORE_BIT, NO_EXTRA },
549    { GL_MAX_LIGHTS, CONTEXT_INT(Const.MaxLights), NO_EXTRA },
550    { GL_LIGHT0, CONTEXT_BOOL(Light.Light[0].Enabled), NO_EXTRA },
551    { GL_LIGHT1, CONTEXT_BOOL(Light.Light[1].Enabled), NO_EXTRA },
552    { GL_LIGHT2, CONTEXT_BOOL(Light.Light[2].Enabled), NO_EXTRA },
553    { GL_LIGHT3, CONTEXT_BOOL(Light.Light[3].Enabled), NO_EXTRA },
554    { GL_LIGHT4, CONTEXT_BOOL(Light.Light[4].Enabled), NO_EXTRA },
555    { GL_LIGHT5, CONTEXT_BOOL(Light.Light[5].Enabled), NO_EXTRA },
556    { GL_LIGHT6, CONTEXT_BOOL(Light.Light[6].Enabled), NO_EXTRA },
557    { GL_LIGHT7, CONTEXT_BOOL(Light.Light[7].Enabled), NO_EXTRA },
558    { GL_LIGHTING, CONTEXT_BOOL(Light.Enabled), NO_EXTRA },
559    { GL_LIGHT_MODEL_AMBIENT,
560      CONTEXT_FIELD(Light.Model.Ambient[0], TYPE_FLOATN_4), NO_EXTRA },
561    { GL_LIGHT_MODEL_TWO_SIDE, CONTEXT_BOOL(Light.Model.TwoSide), NO_EXTRA },
562    { GL_ALPHA_TEST, CONTEXT_BOOL(Color.AlphaEnabled), NO_EXTRA },
563    { GL_ALPHA_TEST_FUNC, CONTEXT_ENUM(Color.AlphaFunc), NO_EXTRA },
564    { GL_ALPHA_TEST_REF, LOC_CUSTOM, TYPE_FLOATN, 0, extra_new_frag_clamp },
565    { GL_BLEND_DST, CONTEXT_ENUM(Color.Blend[0].DstRGB), NO_EXTRA },
566    { GL_CLIP_DISTANCE0, CONTEXT_BIT0(Transform.ClipPlanesEnabled), extra_valid_clip_distance },
567    { GL_CLIP_DISTANCE1, CONTEXT_BIT1(Transform.ClipPlanesEnabled), extra_valid_clip_distance },
568    { GL_CLIP_DISTANCE2, CONTEXT_BIT2(Transform.ClipPlanesEnabled), extra_valid_clip_distance },
569    { GL_CLIP_DISTANCE3, CONTEXT_BIT3(Transform.ClipPlanesEnabled), extra_valid_clip_distance },
570    { GL_CLIP_DISTANCE4, CONTEXT_BIT4(Transform.ClipPlanesEnabled), extra_valid_clip_distance },
571    { GL_CLIP_DISTANCE5, CONTEXT_BIT5(Transform.ClipPlanesEnabled), extra_valid_clip_distance },
572    { GL_CLIP_DISTANCE6, CONTEXT_BIT6(Transform.ClipPlanesEnabled), extra_valid_clip_distance },
573    { GL_CLIP_DISTANCE7, CONTEXT_BIT7(Transform.ClipPlanesEnabled), extra_valid_clip_distance },
574    { GL_COLOR_MATERIAL, CONTEXT_BOOL(Light.ColorMaterialEnabled), NO_EXTRA },
575    { GL_CURRENT_COLOR,
576      CONTEXT_FIELD(Current.Attrib[VERT_ATTRIB_COLOR0][0], TYPE_FLOATN_4),
577      extra_flush_current },
578    { GL_CURRENT_NORMAL,
579      CONTEXT_FIELD(Current.Attrib[VERT_ATTRIB_NORMAL][0], TYPE_FLOATN_3),
580      extra_flush_current },
581    { GL_CURRENT_TEXTURE_COORDS, LOC_CUSTOM, TYPE_FLOAT_4, 0,
582      extra_flush_current_valid_texture_unit },
583    { GL_DISTANCE_ATTENUATION_EXT, CONTEXT_FLOAT3(Point.Params[0]), NO_EXTRA },
584    { GL_FOG, CONTEXT_BOOL(Fog.Enabled), NO_EXTRA },
585    { GL_FOG_COLOR, LOC_CUSTOM, TYPE_FLOATN_4, 0, extra_new_frag_clamp },
586    { GL_FOG_DENSITY, CONTEXT_FLOAT(Fog.Density), NO_EXTRA },
587    { GL_FOG_END, CONTEXT_FLOAT(Fog.End), NO_EXTRA },
588    { GL_FOG_HINT, CONTEXT_ENUM(Hint.Fog), NO_EXTRA },
589    { GL_FOG_MODE, CONTEXT_ENUM(Fog.Mode), NO_EXTRA },
590    { GL_FOG_START, CONTEXT_FLOAT(Fog.Start), NO_EXTRA },
591    { GL_LINE_SMOOTH, CONTEXT_BOOL(Line.SmoothFlag), NO_EXTRA },
592    { GL_LINE_SMOOTH_HINT, CONTEXT_ENUM(Hint.LineSmooth), NO_EXTRA },
593    { GL_LINE_WIDTH_RANGE, CONTEXT_FLOAT2(Const.MinLineWidthAA), NO_EXTRA },
594    { GL_COLOR_LOGIC_OP, CONTEXT_BOOL(Color.ColorLogicOpEnabled), NO_EXTRA },
595    { GL_LOGIC_OP_MODE, CONTEXT_ENUM(Color.LogicOp), NO_EXTRA },
596    { GL_MATRIX_MODE, CONTEXT_ENUM(Transform.MatrixMode), NO_EXTRA },
597    { GL_MAX_MODELVIEW_STACK_DEPTH, CONST(MAX_MODELVIEW_STACK_DEPTH), NO_EXTRA },
598    { GL_MAX_PROJECTION_STACK_DEPTH, CONST(MAX_PROJECTION_STACK_DEPTH), NO_EXTRA },
599    { GL_MAX_TEXTURE_STACK_DEPTH, CONST(MAX_TEXTURE_STACK_DEPTH), NO_EXTRA },
600    { GL_MODELVIEW_MATRIX, CONTEXT_MATRIX(ModelviewMatrixStack.Top), NO_EXTRA },
601    { GL_MODELVIEW_STACK_DEPTH, LOC_CUSTOM, TYPE_INT,
602      offsetof(struct gl_context, ModelviewMatrixStack.Depth), NO_EXTRA },
603    { GL_NORMALIZE, CONTEXT_BOOL(Transform.Normalize), NO_EXTRA },
604    { GL_PACK_SKIP_IMAGES_EXT, CONTEXT_INT(Pack.SkipImages), NO_EXTRA },
605    { GL_PERSPECTIVE_CORRECTION_HINT, CONTEXT_ENUM(Hint.PerspectiveCorrection), NO_EXTRA },
606    { GL_POINT_SIZE, CONTEXT_FLOAT(Point.Size), NO_EXTRA },
607    { GL_POINT_SIZE_RANGE, CONTEXT_FLOAT2(Const.MinPointSizeAA), NO_EXTRA },
608    { GL_POINT_SMOOTH, CONTEXT_BOOL(Point.SmoothFlag), NO_EXTRA },
609    { GL_POINT_SMOOTH_HINT, CONTEXT_ENUM(Hint.PointSmooth), NO_EXTRA },
610    { GL_POINT_SIZE_MIN_EXT, CONTEXT_FLOAT(Point.MinSize), NO_EXTRA },
611    { GL_POINT_SIZE_MAX_EXT, CONTEXT_FLOAT(Point.MaxSize), NO_EXTRA },
612    { GL_POINT_FADE_THRESHOLD_SIZE_EXT, CONTEXT_FLOAT(Point.Threshold), NO_EXTRA },
613    { GL_PROJECTION_MATRIX, CONTEXT_MATRIX(ProjectionMatrixStack.Top), NO_EXTRA },
614    { GL_PROJECTION_STACK_DEPTH, LOC_CUSTOM, TYPE_INT,
615      offsetof(struct gl_context, ProjectionMatrixStack.Depth), NO_EXTRA },
616    { GL_RESCALE_NORMAL, CONTEXT_BOOL(Transform.RescaleNormals), NO_EXTRA },
617    { GL_SHADE_MODEL, CONTEXT_ENUM(Light.ShadeModel), NO_EXTRA },
618    { GL_TEXTURE_2D, LOC_CUSTOM, TYPE_BOOLEAN, 0, NO_EXTRA },
619    { GL_TEXTURE_MATRIX, LOC_CUSTOM, TYPE_MATRIX, 0, extra_valid_texture_unit },
620    { GL_TEXTURE_STACK_DEPTH, LOC_CUSTOM, TYPE_INT, 0,
621      extra_valid_texture_unit  },
622 
623    { GL_VERTEX_ARRAY, ARRAY_BOOL(VertexAttrib[VERT_ATTRIB_POS].Enabled), NO_EXTRA },
624    { GL_VERTEX_ARRAY_SIZE, ARRAY_INT(VertexAttrib[VERT_ATTRIB_POS].Size), NO_EXTRA },
625    { GL_VERTEX_ARRAY_TYPE, ARRAY_ENUM(VertexAttrib[VERT_ATTRIB_POS].Type), NO_EXTRA },
626    { GL_VERTEX_ARRAY_STRIDE, ARRAY_INT(VertexAttrib[VERT_ATTRIB_POS].Stride), NO_EXTRA },
627    { GL_NORMAL_ARRAY, ARRAY_BOOL(VertexAttrib[VERT_ATTRIB_NORMAL].Enabled), NO_EXTRA },
628    { GL_NORMAL_ARRAY_TYPE, ARRAY_ENUM(VertexAttrib[VERT_ATTRIB_NORMAL].Type), NO_EXTRA },
629    { GL_NORMAL_ARRAY_STRIDE, ARRAY_INT(VertexAttrib[VERT_ATTRIB_NORMAL].Stride), NO_EXTRA },
630    { GL_COLOR_ARRAY, ARRAY_BOOL(VertexAttrib[VERT_ATTRIB_COLOR0].Enabled), NO_EXTRA },
631    { GL_COLOR_ARRAY_SIZE, ARRAY_INT(VertexAttrib[VERT_ATTRIB_COLOR0].Size), NO_EXTRA },
632    { GL_COLOR_ARRAY_TYPE, ARRAY_ENUM(VertexAttrib[VERT_ATTRIB_COLOR0].Type), NO_EXTRA },
633    { GL_COLOR_ARRAY_STRIDE, ARRAY_INT(VertexAttrib[VERT_ATTRIB_COLOR0].Stride), NO_EXTRA },
634    { GL_TEXTURE_COORD_ARRAY,
635      LOC_CUSTOM, TYPE_BOOLEAN, offsetof(struct gl_client_array, Enabled), NO_EXTRA },
636    { GL_TEXTURE_COORD_ARRAY_SIZE,
637      LOC_CUSTOM, TYPE_INT, offsetof(struct gl_client_array, Size), NO_EXTRA },
638    { GL_TEXTURE_COORD_ARRAY_TYPE,
639      LOC_CUSTOM, TYPE_ENUM, offsetof(struct gl_client_array, Type), NO_EXTRA },
640    { GL_TEXTURE_COORD_ARRAY_STRIDE,
641      LOC_CUSTOM, TYPE_INT, offsetof(struct gl_client_array, Stride), NO_EXTRA },
642 
643    /* GL_ARB_ES2_compatibility */
644    { GL_SHADER_COMPILER, CONST(1), extra_ARB_ES2_compatibility },
645    { GL_MAX_VARYING_VECTORS, CONTEXT_INT(Const.MaxVarying),
646      extra_ARB_ES2_compatibility },
647    { GL_MAX_VERTEX_UNIFORM_VECTORS, LOC_CUSTOM, TYPE_INT, 0,
648      extra_ARB_ES2_compatibility },
649    { GL_MAX_FRAGMENT_UNIFORM_VECTORS, LOC_CUSTOM, TYPE_INT, 0,
650      extra_ARB_ES2_compatibility },
651 
652    /* GL_ARB_multitexture */
653    { GL_MAX_TEXTURE_UNITS, CONTEXT_INT(Const.MaxTextureUnits), NO_EXTRA },
654    { GL_CLIENT_ACTIVE_TEXTURE, LOC_CUSTOM, TYPE_INT, 0, NO_EXTRA },
655 
656    /* GL_ARB_texture_cube_map */
657    { GL_TEXTURE_CUBE_MAP_ARB, LOC_CUSTOM, TYPE_BOOLEAN, 0, NO_EXTRA },
658    /* S, T, and R are always set at the same time */
659    { GL_TEXTURE_GEN_STR_OES, LOC_TEXUNIT, TYPE_BIT_0,
660      offsetof(struct gl_texture_unit, TexGenEnabled), NO_EXTRA },
661 
662    /* GL_ARB_multisample */
663    { GL_MULTISAMPLE_ARB, CONTEXT_BOOL(Multisample.Enabled), NO_EXTRA },
664    { GL_SAMPLE_ALPHA_TO_ONE_ARB, CONTEXT_BOOL(Multisample.SampleAlphaToOne), NO_EXTRA },
665 
666    /* GL_ARB_vertex_buffer_object */
667    { GL_VERTEX_ARRAY_BUFFER_BINDING_ARB, LOC_CUSTOM, TYPE_INT,
668      offsetof(struct gl_array_object, VertexAttrib[VERT_ATTRIB_POS].BufferObj), NO_EXTRA },
669    { GL_NORMAL_ARRAY_BUFFER_BINDING_ARB, LOC_CUSTOM, TYPE_INT,
670      offsetof(struct gl_array_object, VertexAttrib[VERT_ATTRIB_NORMAL].BufferObj), NO_EXTRA },
671    { GL_COLOR_ARRAY_BUFFER_BINDING_ARB, LOC_CUSTOM, TYPE_INT,
672      offsetof(struct gl_array_object, VertexAttrib[VERT_ATTRIB_COLOR0].BufferObj), NO_EXTRA },
673    { GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING_ARB, LOC_CUSTOM, TYPE_INT, NO_OFFSET, NO_EXTRA },
674 
675    /* GL_OES_point_sprite */
676    { GL_POINT_SPRITE_NV,
677      CONTEXT_BOOL(Point.PointSprite),
678      extra_NV_point_sprite_ARB_point_sprite },
679 
680    /* GL_ARB_fragment_shader */
681    { GL_MAX_FRAGMENT_UNIFORM_COMPONENTS_ARB,
682      CONTEXT_INT(Const.FragmentProgram.MaxUniformComponents),
683      extra_ARB_fragment_shader },
684 
685    /* GL_ARB_vertex_shader */
686    { GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB,
687      CONTEXT_INT(Const.VertexProgram.MaxUniformComponents),
688      extra_ARB_vertex_shader },
689    { GL_MAX_VARYING_FLOATS_ARB, LOC_CUSTOM, TYPE_INT, 0,
690      extra_ARB_vertex_shader },
691 
692    /* GL_EXT_texture_lod_bias */
693    { GL_MAX_TEXTURE_LOD_BIAS_EXT, CONTEXT_FLOAT(Const.MaxTextureLodBias),
694      NO_EXTRA },
695 #endif /* FEATURE_GL || FEATURE_ES1 */
696 
697 #if FEATURE_ES1
698    { 0, 0, TYPE_API_MASK, API_OPENGLES_BIT },
699    /* XXX: OES_matrix_get */
700    { GL_MODELVIEW_MATRIX_FLOAT_AS_INT_BITS_OES },
701    { GL_PROJECTION_MATRIX_FLOAT_AS_INT_BITS_OES },
702    { GL_TEXTURE_MATRIX_FLOAT_AS_INT_BITS_OES },
703 
704    /* OES_point_size_array */
705    { GL_POINT_SIZE_ARRAY_OES, ARRAY_FIELD(VertexAttrib[VERT_ATTRIB_POINT_SIZE].Enabled, TYPE_BOOLEAN) },
706    { GL_POINT_SIZE_ARRAY_TYPE_OES, ARRAY_FIELD(VertexAttrib[VERT_ATTRIB_POINT_SIZE].Type, TYPE_ENUM) },
707    { GL_POINT_SIZE_ARRAY_STRIDE_OES, ARRAY_FIELD(VertexAttrib[VERT_ATTRIB_POINT_SIZE].Stride, TYPE_INT) },
708    { GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES, LOC_CUSTOM, TYPE_INT, 0 },
709 #endif /* FEATURE_ES1 */
710 
711 #if FEATURE_GL || FEATURE_ES2
712    { 0, 0, TYPE_API_MASK, API_OPENGL_BIT | API_OPENGL_CORE_BIT | API_OPENGLES2_BIT, NO_EXTRA },
713    { GL_MAX_TEXTURE_COORDS_ARB, /* == GL_MAX_TEXTURE_COORDS_NV */
714      CONTEXT_INT(Const.MaxTextureCoordUnits),
715      extra_ARB_fragment_program_NV_fragment_program },
716    { GL_PACK_IMAGE_HEIGHT_EXT, CONTEXT_INT(Pack.ImageHeight), NO_EXTRA },
717    { GL_PACK_ROW_LENGTH, CONTEXT_INT(Pack.RowLength), NO_EXTRA },
718    { GL_PACK_SKIP_PIXELS, CONTEXT_INT(Pack.SkipPixels), NO_EXTRA },
719    { GL_PACK_SKIP_ROWS, CONTEXT_INT(Pack.SkipRows), NO_EXTRA },
720    { GL_UNPACK_ROW_LENGTH, CONTEXT_INT(Unpack.RowLength), NO_EXTRA },
721    { GL_UNPACK_SKIP_PIXELS, CONTEXT_INT(Unpack.SkipPixels), NO_EXTRA },
722    { GL_UNPACK_SKIP_ROWS, CONTEXT_INT(Unpack.SkipRows), NO_EXTRA },
723    { GL_UNPACK_SKIP_IMAGES_EXT, CONTEXT_INT(Unpack.SkipImages), NO_EXTRA },
724    { GL_UNPACK_IMAGE_HEIGHT_EXT, CONTEXT_INT(Unpack.ImageHeight), NO_EXTRA },
725 
726    /* GL_ARB_draw_buffers */
727    { GL_MAX_DRAW_BUFFERS_ARB, CONTEXT_INT(Const.MaxDrawBuffers), NO_EXTRA },
728 
729    /* GL_EXT_framebuffer_object / GL_NV_fbo_color_attachments */
730    { GL_MAX_COLOR_ATTACHMENTS, CONTEXT_INT(Const.MaxColorAttachments),
731      extra_EXT_framebuffer_object },
732 
733    /* GL_ARB_draw_buffers / GL_NV_draw_buffers (for ES 2.0) */
734    { GL_DRAW_BUFFER0_ARB, BUFFER_ENUM(ColorDrawBuffer[0]), NO_EXTRA },
735    { GL_DRAW_BUFFER1_ARB, BUFFER_ENUM(ColorDrawBuffer[1]),
736      extra_valid_draw_buffer },
737    { GL_DRAW_BUFFER2_ARB, BUFFER_ENUM(ColorDrawBuffer[2]),
738      extra_valid_draw_buffer },
739    { GL_DRAW_BUFFER3_ARB, BUFFER_ENUM(ColorDrawBuffer[3]),
740      extra_valid_draw_buffer },
741    { GL_DRAW_BUFFER4_ARB, BUFFER_ENUM(ColorDrawBuffer[4]),
742      extra_valid_draw_buffer },
743    { GL_DRAW_BUFFER5_ARB, BUFFER_ENUM(ColorDrawBuffer[5]),
744      extra_valid_draw_buffer },
745    { GL_DRAW_BUFFER6_ARB, BUFFER_ENUM(ColorDrawBuffer[6]),
746      extra_valid_draw_buffer },
747    { GL_DRAW_BUFFER7_ARB, BUFFER_ENUM(ColorDrawBuffer[7]),
748      extra_valid_draw_buffer },
749 
750    { GL_BLEND_COLOR_EXT, LOC_CUSTOM, TYPE_FLOATN_4, 0, extra_new_frag_clamp },
751    /* GL_ARB_fragment_program */
752    { GL_MAX_TEXTURE_IMAGE_UNITS_ARB, /* == GL_MAX_TEXTURE_IMAGE_UNITS_NV */
753      CONTEXT_INT(Const.MaxTextureImageUnits),
754      extra_ARB_fragment_program_NV_fragment_program },
755    { GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB,
756      CONTEXT_INT(Const.MaxVertexTextureImageUnits), extra_ARB_vertex_shader },
757    { GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS_ARB,
758      CONTEXT_INT(Const.MaxCombinedTextureImageUnits),
759      extra_ARB_vertex_shader },
760 
761    /* GL_ARB_shader_objects
762     * Actually, this token isn't part of GL_ARB_shader_objects, but is
763     * close enough for now. */
764    { GL_CURRENT_PROGRAM, LOC_CUSTOM, TYPE_INT, 0, extra_ARB_shader_objects },
765 
766    /* OpenGL 2.0 */
767    { GL_STENCIL_BACK_FUNC, CONTEXT_ENUM(Stencil.Function[1]), NO_EXTRA },
768    { GL_STENCIL_BACK_VALUE_MASK, CONTEXT_INT(Stencil.ValueMask[1]), NO_EXTRA },
769    { GL_STENCIL_BACK_WRITEMASK, CONTEXT_INT(Stencil.WriteMask[1]), NO_EXTRA },
770    { GL_STENCIL_BACK_REF, CONTEXT_INT(Stencil.Ref[1]), NO_EXTRA },
771    { GL_STENCIL_BACK_FAIL, CONTEXT_ENUM(Stencil.FailFunc[1]), NO_EXTRA },
772    { GL_STENCIL_BACK_PASS_DEPTH_FAIL, CONTEXT_ENUM(Stencil.ZFailFunc[1]), NO_EXTRA },
773    { GL_STENCIL_BACK_PASS_DEPTH_PASS, CONTEXT_ENUM(Stencil.ZPassFunc[1]), NO_EXTRA },
774 
775    { GL_MAX_VERTEX_ATTRIBS_ARB,
776      CONTEXT_INT(Const.VertexProgram.MaxAttribs),
777      extra_ARB_vertex_program_api_es2 },
778 
779    /* OES_texture_3D */
780    { GL_TEXTURE_BINDING_3D, LOC_CUSTOM, TYPE_INT, TEXTURE_3D_INDEX, NO_EXTRA },
781    { GL_MAX_3D_TEXTURE_SIZE, LOC_CUSTOM, TYPE_INT,
782      offsetof(struct gl_context, Const.Max3DTextureLevels), NO_EXTRA },
783 
784    /* GL_ARB_fragment_program/OES_standard_derivatives */
785    { GL_FRAGMENT_SHADER_DERIVATIVE_HINT_ARB,
786      CONTEXT_ENUM(Hint.FragmentShaderDerivative), extra_ARB_fragment_shader },
787 
788    /* GL_NV_read_buffer */
789    { GL_READ_BUFFER,
790      LOC_CUSTOM, TYPE_ENUM, NO_OFFSET, extra_NV_read_buffer_api_gl },
791 
792 #endif /* FEATURE_GL || FEATURE_ES2 */
793 
794 #if FEATURE_ES1 || FEATURE_ES2
795    { 0, 0, TYPE_API_MASK, API_OPENGLES | API_OPENGLES2_BIT, NO_EXTRA },
796    /* GL_OES_EGL_image_external */
797    { GL_TEXTURE_BINDING_EXTERNAL_OES, LOC_CUSTOM,
798      TYPE_INT, TEXTURE_EXTERNAL_INDEX, extra_OES_EGL_image_external },
799    { GL_TEXTURE_EXTERNAL_OES, LOC_CUSTOM,
800      TYPE_BOOLEAN, 0, extra_OES_EGL_image_external },
801 #endif
802 
803 #if FEATURE_ES2
804    /* Enums unique to OpenGL ES 2.0 */
805    { 0, 0, TYPE_API_MASK, API_OPENGLES2_BIT, NO_EXTRA },
806    { GL_MAX_FRAGMENT_UNIFORM_VECTORS, LOC_CUSTOM, TYPE_INT, 0, NO_EXTRA },
807    { GL_MAX_VARYING_VECTORS, CONTEXT_INT(Const.MaxVarying), NO_EXTRA },
808    { GL_MAX_VERTEX_UNIFORM_VECTORS, LOC_CUSTOM, TYPE_INT, 0, NO_EXTRA },
809    { GL_SHADER_COMPILER, CONST(1), NO_EXTRA },
810    /* OES_get_program_binary */
811    { GL_NUM_SHADER_BINARY_FORMATS, CONST(0), NO_EXTRA },
812    { GL_SHADER_BINARY_FORMATS, CONST(0), NO_EXTRA },
813 #endif /* FEATURE_ES2 */
814 
815 #if FEATURE_GL
816    /* Remaining enums are only in OpenGL */
817    { 0, 0, TYPE_API_MASK, API_OPENGL_BIT | API_OPENGL_CORE_BIT, NO_EXTRA },
818    { GL_ACCUM_RED_BITS, BUFFER_INT(Visual.accumRedBits), NO_EXTRA },
819    { GL_ACCUM_GREEN_BITS, BUFFER_INT(Visual.accumGreenBits), NO_EXTRA },
820    { GL_ACCUM_BLUE_BITS, BUFFER_INT(Visual.accumBlueBits), NO_EXTRA },
821    { GL_ACCUM_ALPHA_BITS, BUFFER_INT(Visual.accumAlphaBits), NO_EXTRA },
822    { GL_ACCUM_CLEAR_VALUE, CONTEXT_FIELD(Accum.ClearColor[0], TYPE_FLOATN_4), NO_EXTRA },
823    { GL_ALPHA_BIAS, CONTEXT_FLOAT(Pixel.AlphaBias), NO_EXTRA },
824    { GL_ALPHA_SCALE, CONTEXT_FLOAT(Pixel.AlphaScale), NO_EXTRA },
825    { GL_ATTRIB_STACK_DEPTH, CONTEXT_INT(AttribStackDepth), NO_EXTRA },
826    { GL_AUTO_NORMAL, CONTEXT_BOOL(Eval.AutoNormal), NO_EXTRA },
827    { GL_AUX_BUFFERS, BUFFER_INT(Visual.numAuxBuffers), NO_EXTRA },
828    { GL_BLUE_BIAS, CONTEXT_FLOAT(Pixel.BlueBias), NO_EXTRA },
829    { GL_BLUE_SCALE, CONTEXT_FLOAT(Pixel.BlueScale), NO_EXTRA },
830    { GL_CLIENT_ATTRIB_STACK_DEPTH, CONTEXT_INT(ClientAttribStackDepth), NO_EXTRA },
831    { GL_COLOR_MATERIAL_FACE, CONTEXT_ENUM(Light.ColorMaterialFace), NO_EXTRA },
832    { GL_COLOR_MATERIAL_PARAMETER, CONTEXT_ENUM(Light.ColorMaterialMode), NO_EXTRA },
833    { GL_CURRENT_INDEX,
834      CONTEXT_FLOAT(Current.Attrib[VERT_ATTRIB_COLOR_INDEX][0]),
835      extra_flush_current },
836    { GL_CURRENT_RASTER_COLOR,
837      CONTEXT_FIELD(Current.RasterColor[0], TYPE_FLOATN_4), NO_EXTRA },
838    { GL_CURRENT_RASTER_DISTANCE, CONTEXT_FLOAT(Current.RasterDistance), NO_EXTRA },
839    { GL_CURRENT_RASTER_INDEX, CONST(1), NO_EXTRA },
840    { GL_CURRENT_RASTER_POSITION, CONTEXT_FLOAT4(Current.RasterPos[0]), NO_EXTRA },
841    { GL_CURRENT_RASTER_SECONDARY_COLOR,
842      CONTEXT_FIELD(Current.RasterSecondaryColor[0], TYPE_FLOATN_4), NO_EXTRA },
843    { GL_CURRENT_RASTER_TEXTURE_COORDS, LOC_CUSTOM, TYPE_FLOAT_4, 0,
844      extra_valid_texture_unit },
845    { GL_CURRENT_RASTER_POSITION_VALID, CONTEXT_BOOL(Current.RasterPosValid), NO_EXTRA },
846    { GL_DEPTH_BIAS, CONTEXT_FLOAT(Pixel.DepthBias), NO_EXTRA },
847    { GL_DEPTH_SCALE, CONTEXT_FLOAT(Pixel.DepthScale), NO_EXTRA },
848    { GL_DOUBLEBUFFER, BUFFER_INT(Visual.doubleBufferMode), NO_EXTRA },
849    { GL_DRAW_BUFFER, BUFFER_ENUM(ColorDrawBuffer[0]), NO_EXTRA },
850    { GL_EDGE_FLAG, LOC_CUSTOM, TYPE_BOOLEAN, 0, NO_EXTRA },
851    { GL_FEEDBACK_BUFFER_SIZE, CONTEXT_INT(Feedback.BufferSize), NO_EXTRA },
852    { GL_FEEDBACK_BUFFER_TYPE, CONTEXT_ENUM(Feedback.Type), NO_EXTRA },
853    { GL_FOG_INDEX, CONTEXT_FLOAT(Fog.Index), NO_EXTRA },
854    { GL_GREEN_BIAS, CONTEXT_FLOAT(Pixel.GreenBias), NO_EXTRA },
855    { GL_GREEN_SCALE, CONTEXT_FLOAT(Pixel.GreenScale), NO_EXTRA },
856    { GL_INDEX_BITS, BUFFER_INT(Visual.indexBits), extra_new_buffers },
857    { GL_INDEX_CLEAR_VALUE, CONTEXT_INT(Color.ClearIndex), NO_EXTRA },
858    { GL_INDEX_MODE, CONST(0) , NO_EXTRA},
859    { GL_INDEX_OFFSET, CONTEXT_INT(Pixel.IndexOffset), NO_EXTRA },
860    { GL_INDEX_SHIFT, CONTEXT_INT(Pixel.IndexShift), NO_EXTRA },
861    { GL_INDEX_WRITEMASK, CONTEXT_INT(Color.IndexMask), NO_EXTRA },
862    { GL_LIGHT_MODEL_COLOR_CONTROL, CONTEXT_ENUM(Light.Model.ColorControl), NO_EXTRA },
863    { GL_LIGHT_MODEL_LOCAL_VIEWER, CONTEXT_BOOL(Light.Model.LocalViewer), NO_EXTRA },
864    { GL_LINE_STIPPLE, CONTEXT_BOOL(Line.StippleFlag), NO_EXTRA },
865    { GL_LINE_STIPPLE_PATTERN, LOC_CUSTOM, TYPE_INT, 0, NO_EXTRA },
866    { GL_LINE_STIPPLE_REPEAT, CONTEXT_INT(Line.StippleFactor), NO_EXTRA },
867    { GL_LINE_WIDTH_GRANULARITY, CONTEXT_FLOAT(Const.LineWidthGranularity), NO_EXTRA },
868    { GL_LIST_BASE, CONTEXT_INT(List.ListBase), NO_EXTRA },
869    { GL_LIST_INDEX, LOC_CUSTOM, TYPE_INT, 0, NO_EXTRA },
870    { GL_LIST_MODE, LOC_CUSTOM, TYPE_ENUM, 0, NO_EXTRA },
871    { GL_INDEX_LOGIC_OP, CONTEXT_BOOL(Color.IndexLogicOpEnabled), NO_EXTRA },
872    { GL_MAP1_COLOR_4, CONTEXT_BOOL(Eval.Map1Color4), NO_EXTRA },
873    { GL_MAP1_GRID_DOMAIN, CONTEXT_FLOAT2(Eval.MapGrid1u1), NO_EXTRA },
874    { GL_MAP1_GRID_SEGMENTS, CONTEXT_INT(Eval.MapGrid1un), NO_EXTRA },
875    { GL_MAP1_INDEX, CONTEXT_BOOL(Eval.Map1Index), NO_EXTRA },
876    { GL_MAP1_NORMAL, CONTEXT_BOOL(Eval.Map1Normal), NO_EXTRA },
877    { GL_MAP1_TEXTURE_COORD_1, CONTEXT_BOOL(Eval.Map1TextureCoord1), NO_EXTRA },
878    { GL_MAP1_TEXTURE_COORD_2, CONTEXT_BOOL(Eval.Map1TextureCoord2), NO_EXTRA },
879    { GL_MAP1_TEXTURE_COORD_3, CONTEXT_BOOL(Eval.Map1TextureCoord3), NO_EXTRA },
880    { GL_MAP1_TEXTURE_COORD_4, CONTEXT_BOOL(Eval.Map1TextureCoord4), NO_EXTRA },
881    { GL_MAP1_VERTEX_3, CONTEXT_BOOL(Eval.Map1Vertex3), NO_EXTRA },
882    { GL_MAP1_VERTEX_4, CONTEXT_BOOL(Eval.Map1Vertex4), NO_EXTRA },
883    { GL_MAP2_COLOR_4, CONTEXT_BOOL(Eval.Map2Color4), NO_EXTRA },
884    { GL_MAP2_GRID_DOMAIN, LOC_CUSTOM, TYPE_FLOAT_4, 0, NO_EXTRA },
885    { GL_MAP2_GRID_SEGMENTS, CONTEXT_INT2(Eval.MapGrid2un), NO_EXTRA },
886    { GL_MAP2_INDEX, CONTEXT_BOOL(Eval.Map2Index), NO_EXTRA },
887    { GL_MAP2_NORMAL, CONTEXT_BOOL(Eval.Map2Normal), NO_EXTRA },
888    { GL_MAP2_TEXTURE_COORD_1, CONTEXT_BOOL(Eval.Map2TextureCoord1), NO_EXTRA },
889    { GL_MAP2_TEXTURE_COORD_2, CONTEXT_BOOL(Eval.Map2TextureCoord2), NO_EXTRA },
890    { GL_MAP2_TEXTURE_COORD_3, CONTEXT_BOOL(Eval.Map2TextureCoord3), NO_EXTRA },
891    { GL_MAP2_TEXTURE_COORD_4, CONTEXT_BOOL(Eval.Map2TextureCoord4), NO_EXTRA },
892    { GL_MAP2_VERTEX_3, CONTEXT_BOOL(Eval.Map2Vertex3), NO_EXTRA },
893    { GL_MAP2_VERTEX_4, CONTEXT_BOOL(Eval.Map2Vertex4), NO_EXTRA },
894    { GL_MAP_COLOR, CONTEXT_BOOL(Pixel.MapColorFlag), NO_EXTRA },
895    { GL_MAP_STENCIL, CONTEXT_BOOL(Pixel.MapStencilFlag), NO_EXTRA },
896    { GL_MAX_ATTRIB_STACK_DEPTH, CONST(MAX_ATTRIB_STACK_DEPTH), NO_EXTRA },
897    { GL_MAX_CLIENT_ATTRIB_STACK_DEPTH, CONST(MAX_CLIENT_ATTRIB_STACK_DEPTH), NO_EXTRA },
898 
899    { GL_MAX_EVAL_ORDER, CONST(MAX_EVAL_ORDER), NO_EXTRA },
900    { GL_MAX_LIST_NESTING, CONST(MAX_LIST_NESTING), NO_EXTRA },
901    { GL_MAX_NAME_STACK_DEPTH, CONST(MAX_NAME_STACK_DEPTH), NO_EXTRA },
902    { GL_MAX_PIXEL_MAP_TABLE, CONST(MAX_PIXEL_MAP_TABLE), NO_EXTRA },
903    { GL_NAME_STACK_DEPTH, CONTEXT_INT(Select.NameStackDepth), NO_EXTRA },
904    { GL_PACK_LSB_FIRST, CONTEXT_BOOL(Pack.LsbFirst), NO_EXTRA },
905    { GL_PACK_SWAP_BYTES, CONTEXT_BOOL(Pack.SwapBytes), NO_EXTRA },
906    { GL_PACK_INVERT_MESA, CONTEXT_BOOL(Pack.Invert), NO_EXTRA },
907    { GL_PIXEL_MAP_A_TO_A_SIZE, CONTEXT_INT(PixelMaps.AtoA.Size), NO_EXTRA },
908    { GL_PIXEL_MAP_B_TO_B_SIZE, CONTEXT_INT(PixelMaps.BtoB.Size), NO_EXTRA },
909    { GL_PIXEL_MAP_G_TO_G_SIZE, CONTEXT_INT(PixelMaps.GtoG.Size), NO_EXTRA },
910    { GL_PIXEL_MAP_I_TO_A_SIZE, CONTEXT_INT(PixelMaps.ItoA.Size), NO_EXTRA },
911    { GL_PIXEL_MAP_I_TO_B_SIZE, CONTEXT_INT(PixelMaps.ItoB.Size), NO_EXTRA },
912    { GL_PIXEL_MAP_I_TO_G_SIZE, CONTEXT_INT(PixelMaps.ItoG.Size), NO_EXTRA },
913    { GL_PIXEL_MAP_I_TO_I_SIZE, CONTEXT_INT(PixelMaps.ItoI.Size), NO_EXTRA },
914    { GL_PIXEL_MAP_I_TO_R_SIZE, CONTEXT_INT(PixelMaps.ItoR.Size), NO_EXTRA },
915    { GL_PIXEL_MAP_R_TO_R_SIZE, CONTEXT_INT(PixelMaps.RtoR.Size), NO_EXTRA },
916    { GL_PIXEL_MAP_S_TO_S_SIZE, CONTEXT_INT(PixelMaps.StoS.Size), NO_EXTRA },
917    { GL_POINT_SIZE_GRANULARITY, CONTEXT_FLOAT(Const.PointSizeGranularity), NO_EXTRA },
918    { GL_POLYGON_MODE, CONTEXT_ENUM2(Polygon.FrontMode), NO_EXTRA },
919    { GL_POLYGON_OFFSET_BIAS_EXT, CONTEXT_FLOAT(Polygon.OffsetUnits), NO_EXTRA },
920    { GL_POLYGON_OFFSET_POINT, CONTEXT_BOOL(Polygon.OffsetPoint), NO_EXTRA },
921    { GL_POLYGON_OFFSET_LINE, CONTEXT_BOOL(Polygon.OffsetLine), NO_EXTRA },
922    { GL_POLYGON_SMOOTH, CONTEXT_BOOL(Polygon.SmoothFlag), NO_EXTRA },
923    { GL_POLYGON_SMOOTH_HINT, CONTEXT_ENUM(Hint.PolygonSmooth), NO_EXTRA },
924    { GL_POLYGON_STIPPLE, CONTEXT_BOOL(Polygon.StippleFlag), NO_EXTRA },
925    { GL_RED_BIAS, CONTEXT_FLOAT(Pixel.RedBias), NO_EXTRA },
926    { GL_RED_SCALE, CONTEXT_FLOAT(Pixel.RedScale), NO_EXTRA },
927    { GL_RENDER_MODE, CONTEXT_ENUM(RenderMode), NO_EXTRA },
928    { GL_RGBA_MODE, CONST(1), NO_EXTRA },
929    { GL_SELECTION_BUFFER_SIZE, CONTEXT_INT(Select.BufferSize), NO_EXTRA },
930 
931    { GL_STEREO, BUFFER_INT(Visual.stereoMode), NO_EXTRA },
932 
933    { GL_TEXTURE_1D, LOC_CUSTOM, TYPE_BOOLEAN, NO_OFFSET, NO_EXTRA },
934    { GL_TEXTURE_3D, LOC_CUSTOM, TYPE_BOOLEAN, NO_OFFSET, NO_EXTRA },
935    { GL_TEXTURE_1D_ARRAY_EXT, LOC_CUSTOM, TYPE_BOOLEAN, NO_OFFSET, NO_EXTRA },
936    { GL_TEXTURE_2D_ARRAY_EXT, LOC_CUSTOM, TYPE_BOOLEAN, NO_OFFSET, NO_EXTRA },
937 
938    { GL_TEXTURE_BINDING_1D, LOC_CUSTOM, TYPE_INT, TEXTURE_1D_INDEX, NO_EXTRA },
939    { GL_TEXTURE_BINDING_1D_ARRAY, LOC_CUSTOM, TYPE_INT,
940      TEXTURE_1D_ARRAY_INDEX, extra_MESA_texture_array },
941    { GL_TEXTURE_BINDING_2D_ARRAY, LOC_CUSTOM, TYPE_INT,
942      TEXTURE_1D_ARRAY_INDEX, extra_MESA_texture_array },
943    { GL_MAX_ARRAY_TEXTURE_LAYERS_EXT,
944      CONTEXT_INT(Const.MaxArrayTextureLayers), extra_MESA_texture_array },
945 
946    { GL_TEXTURE_GEN_S, LOC_TEXUNIT, TYPE_BIT_0,
947      offsetof(struct gl_texture_unit, TexGenEnabled), NO_EXTRA },
948    { GL_TEXTURE_GEN_T, LOC_TEXUNIT, TYPE_BIT_1,
949      offsetof(struct gl_texture_unit, TexGenEnabled), NO_EXTRA },
950    { GL_TEXTURE_GEN_R, LOC_TEXUNIT, TYPE_BIT_2,
951      offsetof(struct gl_texture_unit, TexGenEnabled), NO_EXTRA },
952    { GL_TEXTURE_GEN_Q, LOC_TEXUNIT, TYPE_BIT_3,
953      offsetof(struct gl_texture_unit, TexGenEnabled), NO_EXTRA },
954    { GL_UNPACK_LSB_FIRST, CONTEXT_BOOL(Unpack.LsbFirst), NO_EXTRA },
955    { GL_UNPACK_SWAP_BYTES, CONTEXT_BOOL(Unpack.SwapBytes), NO_EXTRA },
956    { GL_ZOOM_X, CONTEXT_FLOAT(Pixel.ZoomX), NO_EXTRA },
957    { GL_ZOOM_Y, CONTEXT_FLOAT(Pixel.ZoomY), NO_EXTRA },
958 
959    /* Vertex arrays */
960    { GL_VERTEX_ARRAY_COUNT_EXT, CONST(0), NO_EXTRA },
961    { GL_NORMAL_ARRAY_COUNT_EXT, CONST(0), NO_EXTRA },
962    { GL_COLOR_ARRAY_COUNT_EXT, CONST(0), NO_EXTRA },
963    { GL_INDEX_ARRAY, ARRAY_BOOL(VertexAttrib[VERT_ATTRIB_COLOR_INDEX].Enabled), NO_EXTRA },
964    { GL_INDEX_ARRAY_TYPE, ARRAY_ENUM(VertexAttrib[VERT_ATTRIB_COLOR_INDEX].Type), NO_EXTRA },
965    { GL_INDEX_ARRAY_STRIDE, ARRAY_INT(VertexAttrib[VERT_ATTRIB_COLOR_INDEX].Stride), NO_EXTRA },
966    { GL_INDEX_ARRAY_COUNT_EXT, CONST(0), NO_EXTRA },
967    { GL_TEXTURE_COORD_ARRAY_COUNT_EXT, CONST(0), NO_EXTRA },
968    { GL_EDGE_FLAG_ARRAY, ARRAY_BOOL(VertexAttrib[VERT_ATTRIB_EDGEFLAG].Enabled), NO_EXTRA },
969    { GL_EDGE_FLAG_ARRAY_STRIDE, ARRAY_INT(VertexAttrib[VERT_ATTRIB_EDGEFLAG].Stride), NO_EXTRA },
970    { GL_EDGE_FLAG_ARRAY_COUNT_EXT, CONST(0), NO_EXTRA },
971 
972    /* GL_ARB_texture_compression */
973    { GL_TEXTURE_COMPRESSION_HINT_ARB, CONTEXT_INT(Hint.TextureCompression), NO_EXTRA },
974 
975    /* GL_EXT_compiled_vertex_array */
976    { GL_ARRAY_ELEMENT_LOCK_FIRST_EXT, CONTEXT_INT(Array.LockFirst),
977      extra_EXT_compiled_vertex_array },
978    { GL_ARRAY_ELEMENT_LOCK_COUNT_EXT, CONTEXT_INT(Array.LockCount),
979      extra_EXT_compiled_vertex_array },
980 
981    /* GL_ARB_transpose_matrix */
982    { GL_TRANSPOSE_MODELVIEW_MATRIX_ARB,
983      CONTEXT_MATRIX_T(ModelviewMatrixStack), NO_EXTRA },
984    { GL_TRANSPOSE_PROJECTION_MATRIX_ARB,
985      CONTEXT_MATRIX_T(ProjectionMatrixStack.Top), NO_EXTRA },
986    { GL_TRANSPOSE_TEXTURE_MATRIX_ARB, CONTEXT_MATRIX_T(TextureMatrixStack), NO_EXTRA },
987 
988    /* GL_EXT_secondary_color */
989    { GL_COLOR_SUM_EXT, CONTEXT_BOOL(Fog.ColorSumEnabled),
990      extra_EXT_secondary_color_ARB_vertex_program },
991    { GL_CURRENT_SECONDARY_COLOR_EXT,
992      CONTEXT_FIELD(Current.Attrib[VERT_ATTRIB_COLOR1][0], TYPE_FLOATN_4),
993      extra_EXT_secondary_color_flush_current },
994    { GL_SECONDARY_COLOR_ARRAY_EXT, ARRAY_BOOL(VertexAttrib[VERT_ATTRIB_COLOR1].Enabled),
995      extra_EXT_secondary_color },
996    { GL_SECONDARY_COLOR_ARRAY_TYPE_EXT, ARRAY_ENUM(VertexAttrib[VERT_ATTRIB_COLOR1].Type),
997      extra_EXT_secondary_color },
998    { GL_SECONDARY_COLOR_ARRAY_STRIDE_EXT, ARRAY_INT(VertexAttrib[VERT_ATTRIB_COLOR1].Stride),
999      extra_EXT_secondary_color },
1000    { GL_SECONDARY_COLOR_ARRAY_SIZE_EXT, ARRAY_INT(VertexAttrib[VERT_ATTRIB_COLOR1].Size),
1001      extra_EXT_secondary_color },
1002 
1003    /* GL_EXT_fog_coord */
1004    { GL_CURRENT_FOG_COORDINATE_EXT,
1005      CONTEXT_FLOAT(Current.Attrib[VERT_ATTRIB_FOG][0]),
1006      extra_EXT_fog_coord_flush_current },
1007    { GL_FOG_COORDINATE_ARRAY_EXT, ARRAY_BOOL(VertexAttrib[VERT_ATTRIB_FOG].Enabled),
1008      extra_EXT_fog_coord },
1009    { GL_FOG_COORDINATE_ARRAY_TYPE_EXT, ARRAY_ENUM(VertexAttrib[VERT_ATTRIB_FOG].Type),
1010      extra_EXT_fog_coord },
1011    { GL_FOG_COORDINATE_ARRAY_STRIDE_EXT, ARRAY_INT(VertexAttrib[VERT_ATTRIB_FOG].Stride),
1012      extra_EXT_fog_coord },
1013    { GL_FOG_COORDINATE_SOURCE_EXT, CONTEXT_ENUM(Fog.FogCoordinateSource),
1014      extra_EXT_fog_coord },
1015 
1016    /* GL_NV_fog_distance */
1017    { GL_FOG_DISTANCE_MODE_NV, CONTEXT_ENUM(Fog.FogDistanceMode),
1018      extra_NV_fog_distance },
1019 
1020    /* GL_IBM_rasterpos_clip */
1021    { GL_RASTER_POSITION_UNCLIPPED_IBM,
1022      CONTEXT_BOOL(Transform.RasterPositionUnclipped),
1023      extra_IBM_rasterpos_clip },
1024 
1025    /* GL_NV_point_sprite */
1026    { GL_POINT_SPRITE_R_MODE_NV,
1027      CONTEXT_ENUM(Point.SpriteRMode), extra_NV_point_sprite },
1028    { GL_POINT_SPRITE_COORD_ORIGIN, CONTEXT_ENUM(Point.SpriteOrigin),
1029      extra_NV_point_sprite_ARB_point_sprite },
1030 
1031    /* GL_NV_vertex_program */
1032    { GL_VERTEX_PROGRAM_BINDING_NV, LOC_CUSTOM, TYPE_INT, 0,
1033      extra_NV_vertex_program },
1034    { GL_VERTEX_ATTRIB_ARRAY0_NV, ARRAY_BOOL(VertexAttrib[VERT_ATTRIB_GENERIC(0)].Enabled),
1035      extra_NV_vertex_program },
1036    { GL_VERTEX_ATTRIB_ARRAY1_NV, ARRAY_BOOL(VertexAttrib[VERT_ATTRIB_GENERIC(1)].Enabled),
1037      extra_NV_vertex_program },
1038    { GL_VERTEX_ATTRIB_ARRAY2_NV, ARRAY_BOOL(VertexAttrib[VERT_ATTRIB_GENERIC(2)].Enabled),
1039      extra_NV_vertex_program },
1040    { GL_VERTEX_ATTRIB_ARRAY3_NV, ARRAY_BOOL(VertexAttrib[VERT_ATTRIB_GENERIC(3)].Enabled),
1041      extra_NV_vertex_program },
1042    { GL_VERTEX_ATTRIB_ARRAY4_NV, ARRAY_BOOL(VertexAttrib[VERT_ATTRIB_GENERIC(4)].Enabled),
1043      extra_NV_vertex_program },
1044    { GL_VERTEX_ATTRIB_ARRAY5_NV, ARRAY_BOOL(VertexAttrib[VERT_ATTRIB_GENERIC(5)].Enabled),
1045      extra_NV_vertex_program },
1046    { GL_VERTEX_ATTRIB_ARRAY6_NV, ARRAY_BOOL(VertexAttrib[VERT_ATTRIB_GENERIC(6)].Enabled),
1047      extra_NV_vertex_program },
1048    { GL_VERTEX_ATTRIB_ARRAY7_NV, ARRAY_BOOL(VertexAttrib[VERT_ATTRIB_GENERIC(7)].Enabled),
1049      extra_NV_vertex_program },
1050    { GL_VERTEX_ATTRIB_ARRAY8_NV, ARRAY_BOOL(VertexAttrib[VERT_ATTRIB_GENERIC(8)].Enabled),
1051      extra_NV_vertex_program },
1052    { GL_VERTEX_ATTRIB_ARRAY9_NV, ARRAY_BOOL(VertexAttrib[VERT_ATTRIB_GENERIC(9)].Enabled),
1053      extra_NV_vertex_program },
1054    { GL_VERTEX_ATTRIB_ARRAY10_NV, ARRAY_BOOL(VertexAttrib[VERT_ATTRIB_GENERIC(10)].Enabled),
1055      extra_NV_vertex_program },
1056    { GL_VERTEX_ATTRIB_ARRAY11_NV, ARRAY_BOOL(VertexAttrib[VERT_ATTRIB_GENERIC(11)].Enabled),
1057      extra_NV_vertex_program },
1058    { GL_VERTEX_ATTRIB_ARRAY12_NV, ARRAY_BOOL(VertexAttrib[VERT_ATTRIB_GENERIC(12)].Enabled),
1059      extra_NV_vertex_program },
1060    { GL_VERTEX_ATTRIB_ARRAY13_NV, ARRAY_BOOL(VertexAttrib[VERT_ATTRIB_GENERIC(13)].Enabled),
1061      extra_NV_vertex_program },
1062    { GL_VERTEX_ATTRIB_ARRAY14_NV, ARRAY_BOOL(VertexAttrib[VERT_ATTRIB_GENERIC(14)].Enabled),
1063      extra_NV_vertex_program },
1064    { GL_VERTEX_ATTRIB_ARRAY15_NV, ARRAY_BOOL(VertexAttrib[VERT_ATTRIB_GENERIC(15)].Enabled),
1065      extra_NV_vertex_program },
1066    { GL_MAP1_VERTEX_ATTRIB0_4_NV, CONTEXT_BOOL(Eval.Map1Attrib[0]),
1067      extra_NV_vertex_program },
1068    { GL_MAP1_VERTEX_ATTRIB1_4_NV, CONTEXT_BOOL(Eval.Map1Attrib[1]),
1069      extra_NV_vertex_program },
1070    { GL_MAP1_VERTEX_ATTRIB2_4_NV, CONTEXT_BOOL(Eval.Map1Attrib[2]),
1071      extra_NV_vertex_program },
1072    { GL_MAP1_VERTEX_ATTRIB3_4_NV, CONTEXT_BOOL(Eval.Map1Attrib[3]),
1073      extra_NV_vertex_program },
1074    { GL_MAP1_VERTEX_ATTRIB4_4_NV, CONTEXT_BOOL(Eval.Map1Attrib[4]),
1075      extra_NV_vertex_program },
1076    { GL_MAP1_VERTEX_ATTRIB5_4_NV, CONTEXT_BOOL(Eval.Map1Attrib[5]),
1077      extra_NV_vertex_program },
1078    { GL_MAP1_VERTEX_ATTRIB6_4_NV, CONTEXT_BOOL(Eval.Map1Attrib[6]),
1079      extra_NV_vertex_program },
1080    { GL_MAP1_VERTEX_ATTRIB7_4_NV, CONTEXT_BOOL(Eval.Map1Attrib[7]),
1081      extra_NV_vertex_program },
1082    { GL_MAP1_VERTEX_ATTRIB8_4_NV, CONTEXT_BOOL(Eval.Map1Attrib[8]),
1083      extra_NV_vertex_program },
1084    { GL_MAP1_VERTEX_ATTRIB9_4_NV, CONTEXT_BOOL(Eval.Map1Attrib[9]),
1085      extra_NV_vertex_program },
1086    { GL_MAP1_VERTEX_ATTRIB10_4_NV, CONTEXT_BOOL(Eval.Map1Attrib[10]),
1087      extra_NV_vertex_program },
1088    { GL_MAP1_VERTEX_ATTRIB11_4_NV, CONTEXT_BOOL(Eval.Map1Attrib[11]),
1089      extra_NV_vertex_program },
1090    { GL_MAP1_VERTEX_ATTRIB12_4_NV, CONTEXT_BOOL(Eval.Map1Attrib[12]),
1091      extra_NV_vertex_program },
1092    { GL_MAP1_VERTEX_ATTRIB13_4_NV, CONTEXT_BOOL(Eval.Map1Attrib[13]),
1093      extra_NV_vertex_program },
1094    { GL_MAP1_VERTEX_ATTRIB14_4_NV, CONTEXT_BOOL(Eval.Map1Attrib[14]),
1095      extra_NV_vertex_program },
1096    { GL_MAP1_VERTEX_ATTRIB15_4_NV, CONTEXT_BOOL(Eval.Map1Attrib[15]),
1097      extra_NV_vertex_program },
1098 
1099    /* GL_NV_fragment_program */
1100    { GL_FRAGMENT_PROGRAM_NV, CONTEXT_BOOL(FragmentProgram.Enabled),
1101      extra_NV_fragment_program },
1102    { GL_FRAGMENT_PROGRAM_BINDING_NV, LOC_CUSTOM, TYPE_INT, 0,
1103      extra_NV_fragment_program },
1104    { GL_MAX_FRAGMENT_PROGRAM_LOCAL_PARAMETERS_NV,
1105      CONST(MAX_NV_FRAGMENT_PROGRAM_PARAMS),
1106      extra_NV_fragment_program },
1107 
1108    /* GL_NV_texture_rectangle */
1109    { GL_TEXTURE_RECTANGLE_NV,
1110      LOC_CUSTOM, TYPE_BOOLEAN, 0, extra_NV_texture_rectangle },
1111    { GL_TEXTURE_BINDING_RECTANGLE_NV,
1112      LOC_CUSTOM, TYPE_INT, TEXTURE_RECT_INDEX, extra_NV_texture_rectangle },
1113    { GL_MAX_RECTANGLE_TEXTURE_SIZE_NV,
1114      CONTEXT_INT(Const.MaxTextureRectSize), extra_NV_texture_rectangle },
1115 
1116    /* GL_EXT_stencil_two_side */
1117    { GL_STENCIL_TEST_TWO_SIDE_EXT, CONTEXT_BOOL(Stencil.TestTwoSide),
1118 	 extra_EXT_stencil_two_side },
1119    { GL_ACTIVE_STENCIL_FACE_EXT, LOC_CUSTOM, TYPE_ENUM, NO_OFFSET, NO_EXTRA },
1120 
1121    /* GL_NV_light_max_exponent */
1122    { GL_MAX_SHININESS_NV, CONTEXT_FLOAT(Const.MaxShininess),
1123      extra_NV_light_max_exponent },
1124    { GL_MAX_SPOT_EXPONENT_NV, CONTEXT_FLOAT(Const.MaxSpotExponent),
1125      extra_NV_light_max_exponent },
1126 
1127    /* GL_NV_primitive_restart */
1128    { GL_PRIMITIVE_RESTART_NV, CONTEXT_BOOL(Array.PrimitiveRestart),
1129      extra_NV_primitive_restart },
1130    { GL_PRIMITIVE_RESTART_INDEX_NV, CONTEXT_INT(Array.RestartIndex),
1131      extra_NV_primitive_restart },
1132 
1133    /* GL_ARB_vertex_buffer_object */
1134    { GL_INDEX_ARRAY_BUFFER_BINDING_ARB, LOC_CUSTOM, TYPE_INT,
1135      offsetof(struct gl_array_object, VertexAttrib[VERT_ATTRIB_COLOR_INDEX].BufferObj), NO_EXTRA },
1136    { GL_EDGE_FLAG_ARRAY_BUFFER_BINDING_ARB, LOC_CUSTOM, TYPE_INT,
1137      offsetof(struct gl_array_object, VertexAttrib[VERT_ATTRIB_EDGEFLAG].BufferObj), NO_EXTRA },
1138    { GL_SECONDARY_COLOR_ARRAY_BUFFER_BINDING_ARB, LOC_CUSTOM, TYPE_INT,
1139      offsetof(struct gl_array_object, VertexAttrib[VERT_ATTRIB_COLOR1].BufferObj), NO_EXTRA },
1140    { GL_FOG_COORDINATE_ARRAY_BUFFER_BINDING_ARB, LOC_CUSTOM, TYPE_INT,
1141      offsetof(struct gl_array_object, VertexAttrib[VERT_ATTRIB_FOG].BufferObj), NO_EXTRA },
1142 
1143    /* GL_EXT_pixel_buffer_object */
1144    { GL_PIXEL_PACK_BUFFER_BINDING_EXT, LOC_CUSTOM, TYPE_INT, 0,
1145      extra_EXT_pixel_buffer_object },
1146    { GL_PIXEL_UNPACK_BUFFER_BINDING_EXT, LOC_CUSTOM, TYPE_INT, 0,
1147      extra_EXT_pixel_buffer_object },
1148 
1149    /* GL_ARB_vertex_program */
1150    { GL_VERTEX_PROGRAM_ARB, /* == GL_VERTEX_PROGRAM_NV */
1151      CONTEXT_BOOL(VertexProgram.Enabled),
1152      extra_ARB_vertex_program_NV_vertex_program },
1153    { GL_VERTEX_PROGRAM_POINT_SIZE_ARB, /* == GL_VERTEX_PROGRAM_POINT_SIZE_NV*/
1154      CONTEXT_BOOL(VertexProgram.PointSizeEnabled),
1155      extra_ARB_vertex_program_NV_vertex_program },
1156    { GL_VERTEX_PROGRAM_TWO_SIDE_ARB, /* == GL_VERTEX_PROGRAM_TWO_SIDE_NV */
1157      CONTEXT_BOOL(VertexProgram.TwoSideEnabled),
1158      extra_ARB_vertex_program_NV_vertex_program },
1159    { GL_MAX_PROGRAM_MATRIX_STACK_DEPTH_ARB, /* == GL_MAX_TRACK_MATRIX_STACK_DEPTH_NV */
1160      CONTEXT_INT(Const.MaxProgramMatrixStackDepth),
1161      extra_ARB_vertex_program_ARB_fragment_program_NV_vertex_program },
1162    { GL_MAX_PROGRAM_MATRICES_ARB, /* == GL_MAX_TRACK_MATRICES_NV */
1163      CONTEXT_INT(Const.MaxProgramMatrices),
1164      extra_ARB_vertex_program_ARB_fragment_program_NV_vertex_program },
1165    { GL_CURRENT_MATRIX_STACK_DEPTH_ARB, /* == GL_CURRENT_MATRIX_STACK_DEPTH_NV */
1166      LOC_CUSTOM, TYPE_INT, 0,
1167      extra_ARB_vertex_program_ARB_fragment_program_NV_vertex_program },
1168 
1169    { GL_CURRENT_MATRIX_ARB, /* == GL_CURRENT_MATRIX_NV */
1170      LOC_CUSTOM, TYPE_MATRIX, 0,
1171      extra_ARB_vertex_program_ARB_fragment_program_NV_vertex_program },
1172    { GL_TRANSPOSE_CURRENT_MATRIX_ARB, /* == GL_CURRENT_MATRIX_NV */
1173      LOC_CUSTOM, TYPE_MATRIX, 0,
1174      extra_ARB_vertex_program_ARB_fragment_program },
1175 
1176    { GL_PROGRAM_ERROR_POSITION_ARB, /* == GL_PROGRAM_ERROR_POSITION_NV */
1177      CONTEXT_INT(Program.ErrorPos),
1178      extra_NV_vertex_program_ARB_vertex_program_ARB_fragment_program_NV_vertex_program },
1179 
1180    /* GL_ARB_fragment_program */
1181    { GL_FRAGMENT_PROGRAM_ARB, CONTEXT_BOOL(FragmentProgram.Enabled),
1182      extra_ARB_fragment_program },
1183 
1184    /* GL_EXT_depth_bounds_test */
1185    { GL_DEPTH_BOUNDS_TEST_EXT, CONTEXT_BOOL(Depth.BoundsTest),
1186      extra_EXT_depth_bounds_test },
1187    { GL_DEPTH_BOUNDS_EXT, CONTEXT_FLOAT2(Depth.BoundsMin),
1188      extra_EXT_depth_bounds_test },
1189 
1190    /* GL_ARB_depth_clamp*/
1191    { GL_DEPTH_CLAMP, CONTEXT_BOOL(Transform.DepthClamp),
1192      extra_ARB_depth_clamp },
1193 
1194    /* GL_ATI_fragment_shader */
1195    { GL_NUM_FRAGMENT_REGISTERS_ATI, CONST(6), extra_ATI_fragment_shader },
1196    { GL_NUM_FRAGMENT_CONSTANTS_ATI, CONST(8), extra_ATI_fragment_shader },
1197    { GL_NUM_PASSES_ATI, CONST(2), extra_ATI_fragment_shader },
1198    { GL_NUM_INSTRUCTIONS_PER_PASS_ATI, CONST(8), extra_ATI_fragment_shader },
1199    { GL_NUM_INSTRUCTIONS_TOTAL_ATI, CONST(16), extra_ATI_fragment_shader },
1200    { GL_COLOR_ALPHA_PAIRING_ATI, CONST(GL_TRUE), extra_ATI_fragment_shader },
1201    { GL_NUM_LOOPBACK_COMPONENTS_ATI, CONST(3), extra_ATI_fragment_shader },
1202    { GL_NUM_INPUT_INTERPOLATOR_COMPONENTS_ATI,
1203      CONST(3), extra_ATI_fragment_shader },
1204 
1205    /* GL_EXT_framebuffer_blit
1206     * NOTE: GL_DRAW_FRAMEBUFFER_BINDING_EXT == GL_FRAMEBUFFER_BINDING_EXT */
1207    { GL_READ_FRAMEBUFFER_BINDING_EXT, LOC_CUSTOM, TYPE_INT, 0,
1208      extra_EXT_framebuffer_blit },
1209 
1210    /* GL_EXT_provoking_vertex */
1211    { GL_PROVOKING_VERTEX_EXT,
1212      CONTEXT_ENUM(Light.ProvokingVertex), extra_EXT_provoking_vertex },
1213    { GL_QUADS_FOLLOW_PROVOKING_VERTEX_CONVENTION_EXT,
1214      CONTEXT_BOOL(Const.QuadsFollowProvokingVertexConvention),
1215      extra_EXT_provoking_vertex },
1216 
1217    /* GL_ARB_framebuffer_object */
1218    { GL_MAX_SAMPLES, CONTEXT_INT(Const.MaxSamples),
1219      extra_ARB_framebuffer_object_EXT_framebuffer_multisample },
1220 
1221    /* GL_ARB_seamless_cube_map */
1222    { GL_TEXTURE_CUBE_MAP_SEAMLESS,
1223      CONTEXT_BOOL(Texture.CubeMapSeamless), extra_ARB_seamless_cube_map },
1224 
1225    /* GL_ARB_sync */
1226    { GL_MAX_SERVER_WAIT_TIMEOUT,
1227      CONTEXT_INT64(Const.MaxServerWaitTimeout), extra_ARB_sync },
1228 
1229    /* GL_EXT_texture_integer */
1230    { GL_RGBA_INTEGER_MODE_EXT, BUFFER_BOOL(_IntegerColor),
1231      extra_EXT_texture_integer },
1232 
1233    /* GL_EXT_transform_feedback */
1234    { GL_TRANSFORM_FEEDBACK_BUFFER_BINDING, LOC_CUSTOM, TYPE_INT, 0,
1235      extra_EXT_transform_feedback },
1236    { GL_RASTERIZER_DISCARD, CONTEXT_BOOL(RasterDiscard),
1237      extra_EXT_transform_feedback },
1238    { GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS,
1239      CONTEXT_INT(Const.MaxTransformFeedbackInterleavedComponents),
1240      extra_EXT_transform_feedback },
1241    { GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS,
1242      CONTEXT_INT(Const.MaxTransformFeedbackBuffers),
1243      extra_EXT_transform_feedback },
1244    { GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS,
1245      CONTEXT_INT(Const.MaxTransformFeedbackSeparateComponents),
1246      extra_EXT_transform_feedback },
1247 
1248    /* GL_ARB_transform_feedback2 */
1249    { GL_TRANSFORM_FEEDBACK_BUFFER_PAUSED, LOC_CUSTOM, TYPE_BOOLEAN, 0,
1250      extra_ARB_transform_feedback2 },
1251    { GL_TRANSFORM_FEEDBACK_BUFFER_ACTIVE, LOC_CUSTOM, TYPE_BOOLEAN, 0,
1252      extra_ARB_transform_feedback2 },
1253    { GL_TRANSFORM_FEEDBACK_BINDING, LOC_CUSTOM, TYPE_INT, 0,
1254      extra_ARB_transform_feedback2 },
1255 
1256    /* GL_ARB_transform_feedback3 */
1257    { GL_MAX_TRANSFORM_FEEDBACK_BUFFERS,
1258      CONTEXT_INT(Const.MaxTransformFeedbackBuffers),
1259      extra_ARB_transform_feedback3 },
1260    { GL_MAX_VERTEX_STREAMS,
1261      CONTEXT_INT(Const.MaxVertexStreams),
1262      extra_ARB_transform_feedback3 },
1263 
1264    /* GL_ARB_geometry_shader4 */
1265    { GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_ARB,
1266      CONTEXT_INT(Const.MaxGeometryTextureImageUnits),
1267      extra_ARB_geometry_shader4 },
1268    { GL_MAX_GEOMETRY_OUTPUT_VERTICES_ARB,
1269      CONTEXT_INT(Const.MaxGeometryOutputVertices),
1270      extra_ARB_geometry_shader4 },
1271    { GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_ARB,
1272      CONTEXT_INT(Const.MaxGeometryTotalOutputComponents),
1273      extra_ARB_geometry_shader4 },
1274    { GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_ARB,
1275      CONTEXT_INT(Const.GeometryProgram.MaxUniformComponents),
1276      extra_ARB_geometry_shader4 },
1277    { GL_MAX_GEOMETRY_VARYING_COMPONENTS_ARB,
1278      CONTEXT_INT(Const.MaxGeometryVaryingComponents),
1279      extra_ARB_geometry_shader4 },
1280    { GL_MAX_VERTEX_VARYING_COMPONENTS_ARB,
1281      CONTEXT_INT(Const.MaxVertexVaryingComponents),
1282      extra_ARB_geometry_shader4 },
1283 
1284    /* GL_ARB_color_buffer_float */
1285    { GL_RGBA_FLOAT_MODE_ARB, BUFFER_FIELD(Visual.floatMode, TYPE_BOOLEAN), 0 },
1286 
1287    /* GL_EXT_gpu_shader4 / GLSL 1.30 */
1288    { GL_MIN_PROGRAM_TEXEL_OFFSET,
1289      CONTEXT_INT(Const.MinProgramTexelOffset),
1290      extra_GLSL_130 },
1291    { GL_MAX_PROGRAM_TEXEL_OFFSET,
1292      CONTEXT_INT(Const.MaxProgramTexelOffset),
1293      extra_GLSL_130 },
1294 
1295    /* GL_ARB_texture_buffer_object */
1296    { GL_MAX_TEXTURE_BUFFER_SIZE_ARB, CONTEXT_INT(Const.MaxTextureBufferSize),
1297      extra_texture_buffer_object },
1298    { GL_TEXTURE_BINDING_BUFFER_ARB, LOC_CUSTOM, TYPE_INT, 0,
1299      extra_texture_buffer_object },
1300    { GL_TEXTURE_BUFFER_DATA_STORE_BINDING_ARB, LOC_CUSTOM, TYPE_INT,
1301      TEXTURE_BUFFER_INDEX, extra_texture_buffer_object },
1302    { GL_TEXTURE_BUFFER_FORMAT_ARB, LOC_CUSTOM, TYPE_INT, 0,
1303      extra_texture_buffer_object },
1304    { GL_TEXTURE_BUFFER_ARB, LOC_CUSTOM, TYPE_INT, 0,
1305      extra_texture_buffer_object },
1306 
1307    /* GL_ARB_sampler_objects / GL 3.3 */
1308    { GL_SAMPLER_BINDING,
1309      LOC_CUSTOM, TYPE_INT, GL_SAMPLER_BINDING, NO_EXTRA },
1310 
1311    /* GL 3.0 */
1312    { GL_NUM_EXTENSIONS, LOC_CUSTOM, TYPE_INT, 0, extra_version_30 },
1313    { GL_MAJOR_VERSION, LOC_CUSTOM, TYPE_INT, 0, extra_version_30 },
1314    { GL_MINOR_VERSION, LOC_CUSTOM, TYPE_INT, 0, extra_version_30  },
1315    { GL_CONTEXT_FLAGS, CONTEXT_INT(Const.ContextFlags), extra_version_30  },
1316 
1317    /* GL3.0 / GL_EXT_framebuffer_sRGB */
1318    { GL_FRAMEBUFFER_SRGB_EXT, CONTEXT_BOOL(Color.sRGBEnabled), extra_EXT_framebuffer_sRGB },
1319    { GL_FRAMEBUFFER_SRGB_CAPABLE_EXT, BUFFER_INT(Visual.sRGBCapable), extra_EXT_framebuffer_sRGB },
1320 
1321    /* GL 3.1 */
1322    /* NOTE: different enum values for GL_PRIMITIVE_RESTART_NV
1323     * vs. GL_PRIMITIVE_RESTART!
1324     */
1325    { GL_PRIMITIVE_RESTART, CONTEXT_BOOL(Array.PrimitiveRestart),
1326      extra_version_31 },
1327    { GL_PRIMITIVE_RESTART_INDEX, CONTEXT_INT(Array.RestartIndex),
1328      extra_version_31 },
1329 
1330 
1331    /* GL 3.2 */
1332    { GL_CONTEXT_PROFILE_MASK, CONTEXT_INT(Const.ProfileMask),
1333      extra_version_32 },
1334 
1335    /* GL_ARB_robustness */
1336    { GL_RESET_NOTIFICATION_STRATEGY_ARB, CONTEXT_ENUM(Const.ResetStrategy), NO_EXTRA },
1337 
1338    /* GL_ARB_debug_output */
1339    { GL_DEBUG_LOGGED_MESSAGES_ARB, CONTEXT_INT(Debug.NumMessages), NO_EXTRA },
1340    { GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH_ARB, CONTEXT_INT(Debug.NextMsgLength), NO_EXTRA },
1341    { GL_MAX_DEBUG_LOGGED_MESSAGES_ARB, CONST(MAX_DEBUG_LOGGED_MESSAGES), NO_EXTRA },
1342    { GL_MAX_DEBUG_MESSAGE_LENGTH_ARB, CONST(MAX_DEBUG_MESSAGE_LENGTH), NO_EXTRA },
1343 
1344    { GL_MAX_DUAL_SOURCE_DRAW_BUFFERS, CONTEXT_INT(Const.MaxDualSourceDrawBuffers), extra_ARB_blend_func_extended },
1345 
1346    /* GL_ARB_uniform_buffer_object */
1347    { GL_MAX_VERTEX_UNIFORM_BLOCKS, CONTEXT_INT(Const.VertexProgram.MaxUniformBlocks),
1348      extra_ARB_uniform_buffer_object },
1349    { GL_MAX_FRAGMENT_UNIFORM_BLOCKS, CONTEXT_INT(Const.FragmentProgram.MaxUniformBlocks),
1350      extra_ARB_uniform_buffer_object },
1351    { GL_MAX_GEOMETRY_UNIFORM_BLOCKS, CONTEXT_INT(Const.GeometryProgram.MaxUniformBlocks),
1352      extra_ARB_uniform_buffer_object_and_geometry_shader },
1353    { GL_MAX_COMBINED_UNIFORM_BLOCKS, CONTEXT_INT(Const.MaxCombinedUniformBlocks),
1354      extra_ARB_uniform_buffer_object },
1355    { GL_MAX_UNIFORM_BLOCK_SIZE, CONTEXT_INT(Const.MaxUniformBlockSize),
1356      extra_ARB_uniform_buffer_object },
1357    { GL_MAX_UNIFORM_BUFFER_BINDINGS, CONTEXT_INT(Const.MaxUniformBufferBindings),
1358      extra_ARB_uniform_buffer_object },
1359 
1360    { GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS, CONTEXT_INT(Const.VertexProgram.MaxCombinedUniformComponents),
1361      extra_ARB_uniform_buffer_object },
1362    { GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS, CONTEXT_INT(Const.FragmentProgram.MaxCombinedUniformComponents),
1363      extra_ARB_uniform_buffer_object },
1364    { GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS, CONTEXT_INT(Const.GeometryProgram.MaxCombinedUniformComponents),
1365      extra_ARB_uniform_buffer_object_and_geometry_shader },
1366    { GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, CONTEXT_INT(Const.UniformBufferOffsetAlignment),
1367      extra_ARB_uniform_buffer_object },
1368 
1369    { GL_UNIFORM_BUFFER_BINDING, LOC_CUSTOM, TYPE_INT, 0, extra_ARB_uniform_buffer_object },
1370 
1371    /* GL_ARB_timer_query */
1372    { GL_TIMESTAMP, LOC_CUSTOM, TYPE_INT64, 0, extra_ARB_timer_query }
1373 
1374 #endif /* FEATURE_GL */
1375 };
1376 
1377 /* All we need now is a way to look up the value struct from the enum.
1378  * The code generated by gcc for the old generated big switch
1379  * statement is a big, balanced, open coded if/else tree, essentially
1380  * an unrolled binary search.  It would be natural to sort the new
1381  * enum table and use bsearch(), but we will use a read-only hash
1382  * table instead.  bsearch() has a nice guaranteed worst case
1383  * performance, but we're also guaranteed to hit that worst case
1384  * (log2(n) iterations) for about half the enums.  Instead, using an
1385  * open addressing hash table, we can find the enum on the first try
1386  * for 80% of the enums, 1 collision for 10% and never more than 5
1387  * collisions for any enum (typical numbers).  And the code is very
1388  * simple, even though it feels a little magic. */
1389 
1390 static unsigned short table[API_LAST + 1][1024];
1391 static const int prime_factor = 89, prime_step = 281;
1392 
1393 #ifdef GET_DEBUG
1394 static void
print_table_stats(int api)1395 print_table_stats(int api)
1396 {
1397    int i, j, collisions[11], count, hash, mask;
1398    const struct value_desc *d;
1399    const char *api_names[] = {
1400       [API_OPENGL] = "GL",
1401       [API_OPENGL_CORE] = "GL_CORE",
1402       [API_OPENGLES] = "GLES",
1403       [API_OPENGLES2] = "GLES2",
1404    };
1405    const char *api_name;
1406 
1407    api_name = api < Elements(api_names) ? api_names[api] : "N/A";
1408    count = 0;
1409    mask = Elements(table[api]) - 1;
1410    memset(collisions, 0, sizeof collisions);
1411 
1412    for (i = 0; i < Elements(table[api]); i++) {
1413       if (!table[api][i])
1414          continue;
1415       count++;
1416       d = &values[table[api][i]];
1417       hash = (d->pname * prime_factor);
1418       j = 0;
1419       while (1) {
1420          if (values[table[api][hash & mask]].pname == d->pname)
1421             break;
1422          hash += prime_step;
1423          j++;
1424       }
1425 
1426       if (j < 10)
1427          collisions[j]++;
1428       else
1429          collisions[10]++;
1430    }
1431 
1432    printf("number of enums for %s: %d (total %ld)\n",
1433          api_name, count, Elements(values));
1434    for (i = 0; i < Elements(collisions) - 1; i++)
1435       if (collisions[i] > 0)
1436          printf("  %d enums with %d %scollisions\n",
1437                collisions[i], i, i == 10 ? "or more " : "");
1438 }
1439 #endif
1440 
1441 /**
1442  * Initialize the enum hash for a given API
1443  *
1444  * This is called from one_time_init() to insert the enum values that
1445  * are valid for the API in question into the enum hash table.
1446  *
1447  * \param the current context, for determining the API in question
1448  */
_mesa_init_get_hash(struct gl_context * ctx)1449 void _mesa_init_get_hash(struct gl_context *ctx)
1450 {
1451    int i, hash, index, mask;
1452    int api;
1453    int api_mask = 0, api_bit;
1454 
1455    api = ctx->API;
1456 
1457    mask = Elements(table[api]) - 1;
1458    api_bit = 1 << api;
1459 
1460    for (i = 0; i < Elements(values); i++) {
1461       if (values[i].type == TYPE_API_MASK) {
1462          api_mask = values[i].offset;
1463          continue;
1464       }
1465       if (!(api_mask & api_bit))
1466          continue;
1467 
1468       hash = (values[i].pname * prime_factor) & mask;
1469       while (1) {
1470          index = hash & mask;
1471          if (!table[api][index]) {
1472             table[api][index] = i;
1473             break;
1474          }
1475          hash += prime_step;
1476       }
1477    }
1478 
1479 #ifdef GET_DEBUG
1480    print_table_stats();
1481 #endif
1482 }
1483 
1484 /**
1485  * Handle irregular enums
1486  *
1487  * Some values don't conform to the "well-known type at context
1488  * pointer + offset" pattern, so we have this function to catch all
1489  * the corner cases.  Typically, it's a computed value or a one-off
1490  * pointer to a custom struct or something.
1491  *
1492  * In this case we can't return a pointer to the value, so we'll have
1493  * to use the temporary variable 'v' declared back in the calling
1494  * glGet*v() function to store the result.
1495  *
1496  * \param ctx the current context
1497  * \param d the struct value_desc that describes the enum
1498  * \param v pointer to the tmp declared in the calling glGet*v() function
1499  */
1500 static void
find_custom_value(struct gl_context * ctx,const struct value_desc * d,union value * v)1501 find_custom_value(struct gl_context *ctx, const struct value_desc *d, union value *v)
1502 {
1503    struct gl_buffer_object **buffer_obj;
1504    struct gl_client_array *array;
1505    GLuint unit, *p;
1506 
1507    switch (d->pname) {
1508    case GL_MAJOR_VERSION:
1509       v->value_int = ctx->Version / 10;
1510       break;
1511    case GL_MINOR_VERSION:
1512       v->value_int = ctx->Version % 10;
1513       break;
1514 
1515    case GL_TEXTURE_1D:
1516    case GL_TEXTURE_2D:
1517    case GL_TEXTURE_3D:
1518    case GL_TEXTURE_1D_ARRAY_EXT:
1519    case GL_TEXTURE_2D_ARRAY_EXT:
1520    case GL_TEXTURE_CUBE_MAP_ARB:
1521    case GL_TEXTURE_RECTANGLE_NV:
1522    case GL_TEXTURE_EXTERNAL_OES:
1523       v->value_bool = _mesa_IsEnabled(d->pname);
1524       break;
1525 
1526    case GL_LINE_STIPPLE_PATTERN:
1527       /* This is the only GLushort, special case it here by promoting
1528        * to an int rather than introducing a new type. */
1529       v->value_int = ctx->Line.StipplePattern;
1530       break;
1531 
1532    case GL_CURRENT_RASTER_TEXTURE_COORDS:
1533       unit = ctx->Texture.CurrentUnit;
1534       v->value_float_4[0] = ctx->Current.RasterTexCoords[unit][0];
1535       v->value_float_4[1] = ctx->Current.RasterTexCoords[unit][1];
1536       v->value_float_4[2] = ctx->Current.RasterTexCoords[unit][2];
1537       v->value_float_4[3] = ctx->Current.RasterTexCoords[unit][3];
1538       break;
1539 
1540    case GL_CURRENT_TEXTURE_COORDS:
1541       unit = ctx->Texture.CurrentUnit;
1542       v->value_float_4[0] = ctx->Current.Attrib[VERT_ATTRIB_TEX0 + unit][0];
1543       v->value_float_4[1] = ctx->Current.Attrib[VERT_ATTRIB_TEX0 + unit][1];
1544       v->value_float_4[2] = ctx->Current.Attrib[VERT_ATTRIB_TEX0 + unit][2];
1545       v->value_float_4[3] = ctx->Current.Attrib[VERT_ATTRIB_TEX0 + unit][3];
1546       break;
1547 
1548    case GL_COLOR_WRITEMASK:
1549       v->value_int_4[0] = ctx->Color.ColorMask[0][RCOMP] ? 1 : 0;
1550       v->value_int_4[1] = ctx->Color.ColorMask[0][GCOMP] ? 1 : 0;
1551       v->value_int_4[2] = ctx->Color.ColorMask[0][BCOMP] ? 1 : 0;
1552       v->value_int_4[3] = ctx->Color.ColorMask[0][ACOMP] ? 1 : 0;
1553       break;
1554 
1555    case GL_EDGE_FLAG:
1556       v->value_bool = ctx->Current.Attrib[VERT_ATTRIB_EDGEFLAG][0] == 1.0;
1557       break;
1558 
1559    case GL_READ_BUFFER:
1560       v->value_enum = ctx->ReadBuffer->ColorReadBuffer;
1561       break;
1562 
1563    case GL_MAP2_GRID_DOMAIN:
1564       v->value_float_4[0] = ctx->Eval.MapGrid2u1;
1565       v->value_float_4[1] = ctx->Eval.MapGrid2u2;
1566       v->value_float_4[2] = ctx->Eval.MapGrid2v1;
1567       v->value_float_4[3] = ctx->Eval.MapGrid2v2;
1568       break;
1569 
1570    case GL_TEXTURE_STACK_DEPTH:
1571       unit = ctx->Texture.CurrentUnit;
1572       v->value_int = ctx->TextureMatrixStack[unit].Depth + 1;
1573       break;
1574    case GL_TEXTURE_MATRIX:
1575       unit = ctx->Texture.CurrentUnit;
1576       v->value_matrix = ctx->TextureMatrixStack[unit].Top;
1577       break;
1578 
1579    case GL_TEXTURE_COORD_ARRAY:
1580    case GL_TEXTURE_COORD_ARRAY_SIZE:
1581    case GL_TEXTURE_COORD_ARRAY_TYPE:
1582    case GL_TEXTURE_COORD_ARRAY_STRIDE:
1583       array = &ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_TEX(ctx->Array.ActiveTexture)];
1584       v->value_int = *(GLuint *) ((char *) array + d->offset);
1585       break;
1586 
1587    case GL_ACTIVE_TEXTURE_ARB:
1588       v->value_int = GL_TEXTURE0_ARB + ctx->Texture.CurrentUnit;
1589       break;
1590    case GL_CLIENT_ACTIVE_TEXTURE_ARB:
1591       v->value_int = GL_TEXTURE0_ARB + ctx->Array.ActiveTexture;
1592       break;
1593 
1594    case GL_MODELVIEW_STACK_DEPTH:
1595    case GL_PROJECTION_STACK_DEPTH:
1596       v->value_int = *(GLint *) ((char *) ctx + d->offset) + 1;
1597       break;
1598 
1599    case GL_MAX_TEXTURE_SIZE:
1600    case GL_MAX_3D_TEXTURE_SIZE:
1601    case GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB:
1602       p = (GLuint *) ((char *) ctx + d->offset);
1603       v->value_int = 1 << (*p - 1);
1604       break;
1605 
1606    case GL_SCISSOR_BOX:
1607       v->value_int_4[0] = ctx->Scissor.X;
1608       v->value_int_4[1] = ctx->Scissor.Y;
1609       v->value_int_4[2] = ctx->Scissor.Width;
1610       v->value_int_4[3] = ctx->Scissor.Height;
1611       break;
1612 
1613    case GL_LIST_INDEX:
1614       v->value_int =
1615 	 ctx->ListState.CurrentList ? ctx->ListState.CurrentList->Name : 0;
1616       break;
1617    case GL_LIST_MODE:
1618       if (!ctx->CompileFlag)
1619 	 v->value_enum = 0;
1620       else if (ctx->ExecuteFlag)
1621 	 v->value_enum = GL_COMPILE_AND_EXECUTE;
1622       else
1623 	 v->value_enum = GL_COMPILE;
1624       break;
1625 
1626    case GL_VIEWPORT:
1627       v->value_int_4[0] = ctx->Viewport.X;
1628       v->value_int_4[1] = ctx->Viewport.Y;
1629       v->value_int_4[2] = ctx->Viewport.Width;
1630       v->value_int_4[3] = ctx->Viewport.Height;
1631       break;
1632 
1633    case GL_ACTIVE_STENCIL_FACE_EXT:
1634       v->value_enum = ctx->Stencil.ActiveFace ? GL_BACK : GL_FRONT;
1635       break;
1636 
1637    case GL_STENCIL_FAIL:
1638       v->value_enum = ctx->Stencil.FailFunc[ctx->Stencil.ActiveFace];
1639       break;
1640    case GL_STENCIL_FUNC:
1641       v->value_enum = ctx->Stencil.Function[ctx->Stencil.ActiveFace];
1642       break;
1643    case GL_STENCIL_PASS_DEPTH_FAIL:
1644       v->value_enum = ctx->Stencil.ZFailFunc[ctx->Stencil.ActiveFace];
1645       break;
1646    case GL_STENCIL_PASS_DEPTH_PASS:
1647       v->value_enum = ctx->Stencil.ZPassFunc[ctx->Stencil.ActiveFace];
1648       break;
1649    case GL_STENCIL_REF:
1650       v->value_int = ctx->Stencil.Ref[ctx->Stencil.ActiveFace];
1651       break;
1652    case GL_STENCIL_VALUE_MASK:
1653       v->value_int = ctx->Stencil.ValueMask[ctx->Stencil.ActiveFace];
1654       break;
1655    case GL_STENCIL_WRITEMASK:
1656       v->value_int = ctx->Stencil.WriteMask[ctx->Stencil.ActiveFace];
1657       break;
1658 
1659    case GL_NUM_EXTENSIONS:
1660       v->value_int = _mesa_get_extension_count(ctx);
1661       break;
1662 
1663    case GL_IMPLEMENTATION_COLOR_READ_TYPE_OES:
1664       v->value_int = _mesa_get_color_read_type(ctx);
1665       break;
1666    case GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES:
1667       v->value_int = _mesa_get_color_read_format(ctx);
1668       break;
1669 
1670    case GL_CURRENT_MATRIX_STACK_DEPTH_ARB:
1671       v->value_int = ctx->CurrentStack->Depth + 1;
1672       break;
1673    case GL_CURRENT_MATRIX_ARB:
1674    case GL_TRANSPOSE_CURRENT_MATRIX_ARB:
1675       v->value_matrix = ctx->CurrentStack->Top;
1676       break;
1677 
1678    case GL_NUM_COMPRESSED_TEXTURE_FORMATS_ARB:
1679       v->value_int = _mesa_get_compressed_formats(ctx, NULL);
1680       break;
1681    case GL_COMPRESSED_TEXTURE_FORMATS_ARB:
1682       v->value_int_n.n =
1683 	 _mesa_get_compressed_formats(ctx, v->value_int_n.ints);
1684       ASSERT(v->value_int_n.n <= 100);
1685       break;
1686 
1687    case GL_MAX_VARYING_FLOATS_ARB:
1688       v->value_int = ctx->Const.MaxVarying * 4;
1689       break;
1690 
1691    /* Various object names */
1692 
1693    case GL_TEXTURE_BINDING_1D:
1694    case GL_TEXTURE_BINDING_2D:
1695    case GL_TEXTURE_BINDING_3D:
1696    case GL_TEXTURE_BINDING_1D_ARRAY_EXT:
1697    case GL_TEXTURE_BINDING_2D_ARRAY_EXT:
1698    case GL_TEXTURE_BINDING_CUBE_MAP_ARB:
1699    case GL_TEXTURE_BINDING_RECTANGLE_NV:
1700    case GL_TEXTURE_BINDING_EXTERNAL_OES:
1701       unit = ctx->Texture.CurrentUnit;
1702       v->value_int =
1703 	 ctx->Texture.Unit[unit].CurrentTex[d->offset]->Name;
1704       break;
1705 
1706    /* GL_ARB_vertex_buffer_object */
1707    case GL_VERTEX_ARRAY_BUFFER_BINDING_ARB:
1708    case GL_NORMAL_ARRAY_BUFFER_BINDING_ARB:
1709    case GL_COLOR_ARRAY_BUFFER_BINDING_ARB:
1710    case GL_INDEX_ARRAY_BUFFER_BINDING_ARB:
1711    case GL_EDGE_FLAG_ARRAY_BUFFER_BINDING_ARB:
1712    case GL_SECONDARY_COLOR_ARRAY_BUFFER_BINDING_ARB:
1713    case GL_FOG_COORDINATE_ARRAY_BUFFER_BINDING_ARB:
1714       buffer_obj = (struct gl_buffer_object **)
1715 	 ((char *) ctx->Array.ArrayObj + d->offset);
1716       v->value_int = (*buffer_obj)->Name;
1717       break;
1718    case GL_ARRAY_BUFFER_BINDING_ARB:
1719       v->value_int = ctx->Array.ArrayBufferObj->Name;
1720       break;
1721    case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING_ARB:
1722       v->value_int =
1723 	 ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_TEX(ctx->Array.ActiveTexture)].BufferObj->Name;
1724       break;
1725    case GL_ELEMENT_ARRAY_BUFFER_BINDING_ARB:
1726       v->value_int = ctx->Array.ArrayObj->ElementArrayBufferObj->Name;
1727       break;
1728 
1729    /* ARB_copy_buffer */
1730    case GL_COPY_READ_BUFFER:
1731       v->value_int = ctx->CopyReadBuffer->Name;
1732       break;
1733    case GL_COPY_WRITE_BUFFER:
1734       v->value_int = ctx->CopyWriteBuffer->Name;
1735       break;
1736 
1737    case GL_FRAGMENT_PROGRAM_BINDING_NV:
1738       v->value_int =
1739 	 ctx->FragmentProgram.Current ? ctx->FragmentProgram.Current->Base.Id : 0;
1740       break;
1741    case GL_VERTEX_PROGRAM_BINDING_NV:
1742       v->value_int =
1743 	 ctx->VertexProgram.Current ? ctx->VertexProgram.Current->Base.Id : 0;
1744       break;
1745    case GL_PIXEL_PACK_BUFFER_BINDING_EXT:
1746       v->value_int = ctx->Pack.BufferObj->Name;
1747       break;
1748    case GL_PIXEL_UNPACK_BUFFER_BINDING_EXT:
1749       v->value_int = ctx->Unpack.BufferObj->Name;
1750       break;
1751    case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
1752       v->value_int = ctx->TransformFeedback.CurrentBuffer->Name;
1753       break;
1754    case GL_TRANSFORM_FEEDBACK_BUFFER_PAUSED:
1755       v->value_int = ctx->TransformFeedback.CurrentObject->Paused;
1756       break;
1757    case GL_TRANSFORM_FEEDBACK_BUFFER_ACTIVE:
1758       v->value_int = ctx->TransformFeedback.CurrentObject->Active;
1759       break;
1760    case GL_TRANSFORM_FEEDBACK_BINDING:
1761       v->value_int = ctx->TransformFeedback.CurrentObject->Name;
1762       break;
1763    case GL_CURRENT_PROGRAM:
1764       v->value_int =
1765 	 ctx->Shader.ActiveProgram ? ctx->Shader.ActiveProgram->Name : 0;
1766       break;
1767    case GL_READ_FRAMEBUFFER_BINDING_EXT:
1768       v->value_int = ctx->ReadBuffer->Name;
1769       break;
1770    case GL_RENDERBUFFER_BINDING_EXT:
1771       v->value_int =
1772 	 ctx->CurrentRenderbuffer ? ctx->CurrentRenderbuffer->Name : 0;
1773       break;
1774    case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
1775       v->value_int = ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_POINT_SIZE].BufferObj->Name;
1776       break;
1777 
1778    case GL_FOG_COLOR:
1779       if(ctx->Color._ClampFragmentColor)
1780          COPY_4FV(v->value_float_4, ctx->Fog.Color);
1781       else
1782          COPY_4FV(v->value_float_4, ctx->Fog.ColorUnclamped);
1783       break;
1784    case GL_COLOR_CLEAR_VALUE:
1785       if(ctx->Color._ClampFragmentColor) {
1786          v->value_float_4[0] = CLAMP(ctx->Color.ClearColor.f[0], 0.0F, 1.0F);
1787          v->value_float_4[1] = CLAMP(ctx->Color.ClearColor.f[1], 0.0F, 1.0F);
1788          v->value_float_4[2] = CLAMP(ctx->Color.ClearColor.f[2], 0.0F, 1.0F);
1789          v->value_float_4[3] = CLAMP(ctx->Color.ClearColor.f[3], 0.0F, 1.0F);
1790       } else
1791          COPY_4FV(v->value_float_4, ctx->Color.ClearColor.f);
1792       break;
1793    case GL_BLEND_COLOR_EXT:
1794       if(ctx->Color._ClampFragmentColor)
1795          COPY_4FV(v->value_float_4, ctx->Color.BlendColor);
1796       else
1797          COPY_4FV(v->value_float_4, ctx->Color.BlendColorUnclamped);
1798       break;
1799    case GL_ALPHA_TEST_REF:
1800       if(ctx->Color._ClampFragmentColor)
1801          v->value_float = ctx->Color.AlphaRef;
1802       else
1803          v->value_float = ctx->Color.AlphaRefUnclamped;
1804       break;
1805    case GL_MAX_VERTEX_UNIFORM_VECTORS:
1806       v->value_int = ctx->Const.VertexProgram.MaxUniformComponents / 4;
1807       break;
1808 
1809    case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
1810       v->value_int = ctx->Const.FragmentProgram.MaxUniformComponents / 4;
1811       break;
1812 
1813    /* GL_ARB_texture_buffer_object */
1814    case GL_TEXTURE_BUFFER_ARB:
1815       v->value_int = ctx->Texture.BufferObject->Name;
1816       break;
1817    case GL_TEXTURE_BINDING_BUFFER_ARB:
1818       unit = ctx->Texture.CurrentUnit;
1819       v->value_int =
1820          ctx->Texture.Unit[unit].CurrentTex[TEXTURE_BUFFER_INDEX]->Name;
1821       break;
1822    case GL_TEXTURE_BUFFER_DATA_STORE_BINDING_ARB:
1823       {
1824          struct gl_buffer_object *buf =
1825             ctx->Texture.Unit[ctx->Texture.CurrentUnit]
1826             .CurrentTex[TEXTURE_BUFFER_INDEX]->BufferObject;
1827          v->value_int = buf ? buf->Name : 0;
1828       }
1829       break;
1830    case GL_TEXTURE_BUFFER_FORMAT_ARB:
1831       v->value_int = ctx->Texture.Unit[ctx->Texture.CurrentUnit]
1832          .CurrentTex[TEXTURE_BUFFER_INDEX]->BufferObjectFormat;
1833       break;
1834 
1835    /* GL_ARB_sampler_objects */
1836    case GL_SAMPLER_BINDING:
1837       {
1838          struct gl_sampler_object *samp =
1839             ctx->Texture.Unit[ctx->Texture.CurrentUnit].Sampler;
1840          v->value_int = samp ? samp->Name : 0;
1841       }
1842       break;
1843    /* GL_ARB_uniform_buffer_object */
1844    case GL_UNIFORM_BUFFER_BINDING:
1845       v->value_int = ctx->UniformBuffer->Name;
1846       break;
1847    /* GL_ARB_timer_query */
1848    case GL_TIMESTAMP:
1849       if (ctx->Driver.GetTimestamp) {
1850          v->value_int64 = ctx->Driver.GetTimestamp(ctx);
1851       }
1852       else {
1853          _mesa_problem(ctx, "driver doesn't implement GetTimestamp");
1854       }
1855       break;
1856    }
1857 }
1858 
1859 /**
1860  * Check extra constraints on a struct value_desc descriptor
1861  *
1862  * If a struct value_desc has a non-NULL extra pointer, it means that
1863  * there are a number of extra constraints to check or actions to
1864  * perform.  The extras is just an integer array where each integer
1865  * encode different constraints or actions.
1866  *
1867  * \param ctx current context
1868  * \param func name of calling glGet*v() function for error reporting
1869  * \param d the struct value_desc that has the extra constraints
1870  *
1871  * \return GL_FALSE if one of the constraints was not satisfied,
1872  *     otherwise GL_TRUE.
1873  */
1874 static GLboolean
check_extra(struct gl_context * ctx,const char * func,const struct value_desc * d)1875 check_extra(struct gl_context *ctx, const char *func, const struct value_desc *d)
1876 {
1877    const GLuint version = ctx->Version;
1878    int total, enabled;
1879    const int *e;
1880 
1881    total = 0;
1882    enabled = 0;
1883    for (e = d->extra; *e != EXTRA_END; e++)
1884       switch (*e) {
1885       case EXTRA_VERSION_30:
1886 	 if (version >= 30) {
1887 	    total++;
1888 	    enabled++;
1889 	 }
1890 	 break;
1891       case EXTRA_VERSION_31:
1892 	 if (version >= 31) {
1893 	    total++;
1894 	    enabled++;
1895 	 }
1896 	 break;
1897       case EXTRA_VERSION_32:
1898 	 if (version >= 32) {
1899 	    total++;
1900 	    enabled++;
1901 	 }
1902 	 break;
1903       case EXTRA_NEW_FRAG_CLAMP:
1904          if (ctx->NewState & (_NEW_BUFFERS | _NEW_FRAG_CLAMP))
1905             _mesa_update_state(ctx);
1906          break;
1907       case EXTRA_API_ES2:
1908 	 if (ctx->API == API_OPENGLES2) {
1909 	    total++;
1910 	    enabled++;
1911 	 }
1912 	 break;
1913       case EXTRA_API_GL:
1914 	 if (_mesa_is_desktop_gl(ctx)) {
1915 	    total++;
1916 	    enabled++;
1917 	 }
1918 	 break;
1919       case EXTRA_NEW_BUFFERS:
1920 	 if (ctx->NewState & _NEW_BUFFERS)
1921 	    _mesa_update_state(ctx);
1922 	 break;
1923       case EXTRA_FLUSH_CURRENT:
1924 	 FLUSH_CURRENT(ctx, 0);
1925 	 break;
1926       case EXTRA_VALID_DRAW_BUFFER:
1927 	 if (d->pname - GL_DRAW_BUFFER0_ARB >= ctx->Const.MaxDrawBuffers) {
1928 	    _mesa_error(ctx, GL_INVALID_OPERATION, "%s(draw buffer %u)",
1929 			func, d->pname - GL_DRAW_BUFFER0_ARB);
1930 	    return GL_FALSE;
1931 	 }
1932 	 break;
1933       case EXTRA_VALID_TEXTURE_UNIT:
1934 	 if (ctx->Texture.CurrentUnit >= ctx->Const.MaxTextureCoordUnits) {
1935 	    _mesa_error(ctx, GL_INVALID_OPERATION, "%s(texture %u)",
1936 			func, ctx->Texture.CurrentUnit);
1937 	    return GL_FALSE;
1938 	 }
1939 	 break;
1940       case EXTRA_VALID_CLIP_DISTANCE:
1941 	 if (d->pname - GL_CLIP_DISTANCE0 >= ctx->Const.MaxClipPlanes) {
1942 	    _mesa_error(ctx, GL_INVALID_ENUM, "%s(clip distance %u)",
1943 			func, d->pname - GL_CLIP_DISTANCE0);
1944 	    return GL_FALSE;
1945 	 }
1946 	 break;
1947       case EXTRA_GLSL_130:
1948 	 if (ctx->Const.GLSLVersion >= 130) {
1949 	    total++;
1950 	    enabled++;
1951 	 }
1952 	 break;
1953       case EXTRA_END:
1954 	 break;
1955       default: /* *e is a offset into the extension struct */
1956 	 total++;
1957 	 if (*(GLboolean *) ((char *) &ctx->Extensions + *e))
1958 	    enabled++;
1959 	 break;
1960       }
1961 
1962    if (total > 0 && enabled == 0) {
1963       _mesa_error(ctx, GL_INVALID_ENUM, "%s(pname=%s)", func,
1964                   _mesa_lookup_enum_by_nr(d->pname));
1965       return GL_FALSE;
1966    }
1967 
1968    return GL_TRUE;
1969 }
1970 
1971 static const struct value_desc error_value =
1972    { 0, 0, TYPE_INVALID, NO_OFFSET, NO_EXTRA };
1973 
1974 /**
1975  * Find the struct value_desc corresponding to the enum 'pname'.
1976  *
1977  * We hash the enum value to get an index into the 'table' array,
1978  * which holds the index in the 'values' array of struct value_desc.
1979  * Once we've found the entry, we do the extra checks, if any, then
1980  * look up the value and return a pointer to it.
1981  *
1982  * If the value has to be computed (for example, it's the result of a
1983  * function call or we need to add 1 to it), we use the tmp 'v' to
1984  * store the result.
1985  *
1986  * \param func name of glGet*v() func for error reporting
1987  * \param pname the enum value we're looking up
1988  * \param p is were we return the pointer to the value
1989  * \param v a tmp union value variable in the calling glGet*v() function
1990  *
1991  * \return the struct value_desc corresponding to the enum or a struct
1992  *     value_desc of TYPE_INVALID if not found.  This lets the calling
1993  *     glGet*v() function jump right into a switch statement and
1994  *     handle errors there instead of having to check for NULL.
1995  */
1996 static const struct value_desc *
find_value(const char * func,GLenum pname,void ** p,union value * v)1997 find_value(const char *func, GLenum pname, void **p, union value *v)
1998 {
1999    GET_CURRENT_CONTEXT(ctx);
2000    struct gl_texture_unit *unit;
2001    int mask, hash;
2002    const struct value_desc *d;
2003    int api;
2004 
2005    api = ctx->API;
2006    mask = Elements(table[api]) - 1;
2007    hash = (pname * prime_factor);
2008    while (1) {
2009       d = &values[table[api][hash & mask]];
2010 
2011       /* If the enum isn't valid, the hash walk ends with index 0,
2012        * which is the API mask entry at the beginning of values[]. */
2013       if (unlikely(d->type == TYPE_API_MASK)) {
2014          _mesa_error(ctx, GL_INVALID_ENUM, "%s(pname=%s)", func,
2015                _mesa_lookup_enum_by_nr(pname));
2016          return &error_value;
2017       }
2018 
2019       if (likely(d->pname == pname))
2020          break;
2021 
2022       hash += prime_step;
2023    }
2024 
2025    if (unlikely(d->extra && !check_extra(ctx, func, d)))
2026       return &error_value;
2027 
2028    switch (d->location) {
2029    case LOC_BUFFER:
2030       *p = ((char *) ctx->DrawBuffer + d->offset);
2031       return d;
2032    case LOC_CONTEXT:
2033       *p = ((char *) ctx + d->offset);
2034       return d;
2035    case LOC_ARRAY:
2036       *p = ((char *) ctx->Array.ArrayObj + d->offset);
2037       return d;
2038    case LOC_TEXUNIT:
2039       unit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
2040       *p = ((char *) unit + d->offset);
2041       return d;
2042    case LOC_CUSTOM:
2043       find_custom_value(ctx, d, v);
2044       *p = v;
2045       return d;
2046    default:
2047       assert(0);
2048       break;
2049    }
2050 
2051    /* silence warning */
2052    return &error_value;
2053 }
2054 
2055 static const int transpose[] = {
2056    0, 4,  8, 12,
2057    1, 5,  9, 13,
2058    2, 6, 10, 14,
2059    3, 7, 11, 15
2060 };
2061 
2062 void GLAPIENTRY
_mesa_GetBooleanv(GLenum pname,GLboolean * params)2063 _mesa_GetBooleanv(GLenum pname, GLboolean *params)
2064 {
2065    const struct value_desc *d;
2066    union value v;
2067    GLmatrix *m;
2068    int shift, i;
2069    void *p;
2070    GET_CURRENT_CONTEXT(ctx);
2071 
2072    ASSERT_OUTSIDE_BEGIN_END(ctx);
2073 
2074    d = find_value("glGetBooleanv", pname, &p, &v);
2075    switch (d->type) {
2076    case TYPE_INVALID:
2077       break;
2078    case TYPE_CONST:
2079       params[0] = INT_TO_BOOLEAN(d->offset);
2080       break;
2081 
2082    case TYPE_FLOAT_4:
2083    case TYPE_FLOATN_4:
2084       params[3] = FLOAT_TO_BOOLEAN(((GLfloat *) p)[3]);
2085    case TYPE_FLOAT_3:
2086    case TYPE_FLOATN_3:
2087       params[2] = FLOAT_TO_BOOLEAN(((GLfloat *) p)[2]);
2088    case TYPE_FLOAT_2:
2089    case TYPE_FLOATN_2:
2090       params[1] = FLOAT_TO_BOOLEAN(((GLfloat *) p)[1]);
2091    case TYPE_FLOAT:
2092    case TYPE_FLOATN:
2093       params[0] = FLOAT_TO_BOOLEAN(((GLfloat *) p)[0]);
2094       break;
2095 
2096    case TYPE_DOUBLEN:
2097       params[0] = FLOAT_TO_BOOLEAN(((GLdouble *) p)[0]);
2098       break;
2099 
2100    case TYPE_INT_4:
2101       params[3] = INT_TO_BOOLEAN(((GLint *) p)[3]);
2102    case TYPE_INT_3:
2103       params[2] = INT_TO_BOOLEAN(((GLint *) p)[2]);
2104    case TYPE_INT_2:
2105    case TYPE_ENUM_2:
2106       params[1] = INT_TO_BOOLEAN(((GLint *) p)[1]);
2107    case TYPE_INT:
2108    case TYPE_ENUM:
2109       params[0] = INT_TO_BOOLEAN(((GLint *) p)[0]);
2110       break;
2111 
2112    case TYPE_INT_N:
2113       for (i = 0; i < v.value_int_n.n; i++)
2114 	 params[i] = INT_TO_BOOLEAN(v.value_int_n.ints[i]);
2115       break;
2116 
2117    case TYPE_INT64:
2118       params[0] = INT64_TO_BOOLEAN(((GLint64 *) p)[0]);
2119       break;
2120 
2121    case TYPE_BOOLEAN:
2122       params[0] = ((GLboolean*) p)[0];
2123       break;
2124 
2125    case TYPE_MATRIX:
2126       m = *(GLmatrix **) p;
2127       for (i = 0; i < 16; i++)
2128 	 params[i] = FLOAT_TO_BOOLEAN(m->m[i]);
2129       break;
2130 
2131    case TYPE_MATRIX_T:
2132       m = *(GLmatrix **) p;
2133       for (i = 0; i < 16; i++)
2134 	 params[i] = FLOAT_TO_BOOLEAN(m->m[transpose[i]]);
2135       break;
2136 
2137    case TYPE_BIT_0:
2138    case TYPE_BIT_1:
2139    case TYPE_BIT_2:
2140    case TYPE_BIT_3:
2141    case TYPE_BIT_4:
2142    case TYPE_BIT_5:
2143    case TYPE_BIT_6:
2144    case TYPE_BIT_7:
2145       shift = d->type - TYPE_BIT_0;
2146       params[0] = (*(GLbitfield *) p >> shift) & 1;
2147       break;
2148    }
2149 }
2150 
2151 void GLAPIENTRY
_mesa_GetFloatv(GLenum pname,GLfloat * params)2152 _mesa_GetFloatv(GLenum pname, GLfloat *params)
2153 {
2154    const struct value_desc *d;
2155    union value v;
2156    GLmatrix *m;
2157    int shift, i;
2158    void *p;
2159    GET_CURRENT_CONTEXT(ctx);
2160 
2161    ASSERT_OUTSIDE_BEGIN_END(ctx);
2162 
2163    d = find_value("glGetFloatv", pname, &p, &v);
2164    switch (d->type) {
2165    case TYPE_INVALID:
2166       break;
2167    case TYPE_CONST:
2168       params[0] = (GLfloat) d->offset;
2169       break;
2170 
2171    case TYPE_FLOAT_4:
2172    case TYPE_FLOATN_4:
2173       params[3] = ((GLfloat *) p)[3];
2174    case TYPE_FLOAT_3:
2175    case TYPE_FLOATN_3:
2176       params[2] = ((GLfloat *) p)[2];
2177    case TYPE_FLOAT_2:
2178    case TYPE_FLOATN_2:
2179       params[1] = ((GLfloat *) p)[1];
2180    case TYPE_FLOAT:
2181    case TYPE_FLOATN:
2182       params[0] = ((GLfloat *) p)[0];
2183       break;
2184 
2185    case TYPE_DOUBLEN:
2186       params[0] = ((GLdouble *) p)[0];
2187       break;
2188 
2189    case TYPE_INT_4:
2190       params[3] = (GLfloat) (((GLint *) p)[3]);
2191    case TYPE_INT_3:
2192       params[2] = (GLfloat) (((GLint *) p)[2]);
2193    case TYPE_INT_2:
2194    case TYPE_ENUM_2:
2195       params[1] = (GLfloat) (((GLint *) p)[1]);
2196    case TYPE_INT:
2197    case TYPE_ENUM:
2198       params[0] = (GLfloat) (((GLint *) p)[0]);
2199       break;
2200 
2201    case TYPE_INT_N:
2202       for (i = 0; i < v.value_int_n.n; i++)
2203 	 params[i] = INT_TO_FLOAT(v.value_int_n.ints[i]);
2204       break;
2205 
2206    case TYPE_INT64:
2207       params[0] = ((GLint64 *) p)[0];
2208       break;
2209 
2210    case TYPE_BOOLEAN:
2211       params[0] = BOOLEAN_TO_FLOAT(*(GLboolean*) p);
2212       break;
2213 
2214    case TYPE_MATRIX:
2215       m = *(GLmatrix **) p;
2216       for (i = 0; i < 16; i++)
2217 	 params[i] = m->m[i];
2218       break;
2219 
2220    case TYPE_MATRIX_T:
2221       m = *(GLmatrix **) p;
2222       for (i = 0; i < 16; i++)
2223 	 params[i] = m->m[transpose[i]];
2224       break;
2225 
2226    case TYPE_BIT_0:
2227    case TYPE_BIT_1:
2228    case TYPE_BIT_2:
2229    case TYPE_BIT_3:
2230    case TYPE_BIT_4:
2231    case TYPE_BIT_5:
2232    case TYPE_BIT_6:
2233    case TYPE_BIT_7:
2234       shift = d->type - TYPE_BIT_0;
2235       params[0] = BOOLEAN_TO_FLOAT((*(GLbitfield *) p >> shift) & 1);
2236       break;
2237    }
2238 }
2239 
2240 void GLAPIENTRY
_mesa_GetIntegerv(GLenum pname,GLint * params)2241 _mesa_GetIntegerv(GLenum pname, GLint *params)
2242 {
2243    const struct value_desc *d;
2244    union value v;
2245    GLmatrix *m;
2246    int shift, i;
2247    void *p;
2248    GET_CURRENT_CONTEXT(ctx);
2249 
2250    ASSERT_OUTSIDE_BEGIN_END(ctx);
2251 
2252    d = find_value("glGetIntegerv", pname, &p, &v);
2253    switch (d->type) {
2254    case TYPE_INVALID:
2255       break;
2256    case TYPE_CONST:
2257       params[0] = d->offset;
2258       break;
2259 
2260    case TYPE_FLOAT_4:
2261       params[3] = IROUND(((GLfloat *) p)[3]);
2262    case TYPE_FLOAT_3:
2263       params[2] = IROUND(((GLfloat *) p)[2]);
2264    case TYPE_FLOAT_2:
2265       params[1] = IROUND(((GLfloat *) p)[1]);
2266    case TYPE_FLOAT:
2267       params[0] = IROUND(((GLfloat *) p)[0]);
2268       break;
2269 
2270    case TYPE_FLOATN_4:
2271       params[3] = FLOAT_TO_INT(((GLfloat *) p)[3]);
2272    case TYPE_FLOATN_3:
2273       params[2] = FLOAT_TO_INT(((GLfloat *) p)[2]);
2274    case TYPE_FLOATN_2:
2275       params[1] = FLOAT_TO_INT(((GLfloat *) p)[1]);
2276    case TYPE_FLOATN:
2277       params[0] = FLOAT_TO_INT(((GLfloat *) p)[0]);
2278       break;
2279 
2280    case TYPE_DOUBLEN:
2281       params[0] = FLOAT_TO_INT(((GLdouble *) p)[0]);
2282       break;
2283 
2284    case TYPE_INT_4:
2285       params[3] = ((GLint *) p)[3];
2286    case TYPE_INT_3:
2287       params[2] = ((GLint *) p)[2];
2288    case TYPE_INT_2:
2289    case TYPE_ENUM_2:
2290       params[1] = ((GLint *) p)[1];
2291    case TYPE_INT:
2292    case TYPE_ENUM:
2293       params[0] = ((GLint *) p)[0];
2294       break;
2295 
2296    case TYPE_INT_N:
2297       for (i = 0; i < v.value_int_n.n; i++)
2298 	 params[i] = v.value_int_n.ints[i];
2299       break;
2300 
2301    case TYPE_INT64:
2302       params[0] = INT64_TO_INT(((GLint64 *) p)[0]);
2303       break;
2304 
2305    case TYPE_BOOLEAN:
2306       params[0] = BOOLEAN_TO_INT(*(GLboolean*) p);
2307       break;
2308 
2309    case TYPE_MATRIX:
2310       m = *(GLmatrix **) p;
2311       for (i = 0; i < 16; i++)
2312 	 params[i] = FLOAT_TO_INT(m->m[i]);
2313       break;
2314 
2315    case TYPE_MATRIX_T:
2316       m = *(GLmatrix **) p;
2317       for (i = 0; i < 16; i++)
2318 	 params[i] = FLOAT_TO_INT(m->m[transpose[i]]);
2319       break;
2320 
2321    case TYPE_BIT_0:
2322    case TYPE_BIT_1:
2323    case TYPE_BIT_2:
2324    case TYPE_BIT_3:
2325    case TYPE_BIT_4:
2326    case TYPE_BIT_5:
2327    case TYPE_BIT_6:
2328    case TYPE_BIT_7:
2329       shift = d->type - TYPE_BIT_0;
2330       params[0] = (*(GLbitfield *) p >> shift) & 1;
2331       break;
2332    }
2333 }
2334 
2335 #if FEATURE_ARB_sync
2336 void GLAPIENTRY
_mesa_GetInteger64v(GLenum pname,GLint64 * params)2337 _mesa_GetInteger64v(GLenum pname, GLint64 *params)
2338 {
2339    const struct value_desc *d;
2340    union value v;
2341    GLmatrix *m;
2342    int shift, i;
2343    void *p;
2344    GET_CURRENT_CONTEXT(ctx);
2345 
2346    ASSERT_OUTSIDE_BEGIN_END(ctx);
2347 
2348    d = find_value("glGetInteger64v", pname, &p, &v);
2349    switch (d->type) {
2350    case TYPE_INVALID:
2351       break;
2352    case TYPE_CONST:
2353       params[0] = d->offset;
2354       break;
2355 
2356    case TYPE_FLOAT_4:
2357       params[3] = IROUND64(((GLfloat *) p)[3]);
2358    case TYPE_FLOAT_3:
2359       params[2] = IROUND64(((GLfloat *) p)[2]);
2360    case TYPE_FLOAT_2:
2361       params[1] = IROUND64(((GLfloat *) p)[1]);
2362    case TYPE_FLOAT:
2363       params[0] = IROUND64(((GLfloat *) p)[0]);
2364       break;
2365 
2366    case TYPE_FLOATN_4:
2367       params[3] = FLOAT_TO_INT64(((GLfloat *) p)[3]);
2368    case TYPE_FLOATN_3:
2369       params[2] = FLOAT_TO_INT64(((GLfloat *) p)[2]);
2370    case TYPE_FLOATN_2:
2371       params[1] = FLOAT_TO_INT64(((GLfloat *) p)[1]);
2372    case TYPE_FLOATN:
2373       params[0] = FLOAT_TO_INT64(((GLfloat *) p)[0]);
2374       break;
2375 
2376    case TYPE_DOUBLEN:
2377       params[0] = FLOAT_TO_INT64(((GLdouble *) p)[0]);
2378       break;
2379 
2380    case TYPE_INT_4:
2381       params[3] = ((GLint *) p)[3];
2382    case TYPE_INT_3:
2383       params[2] = ((GLint *) p)[2];
2384    case TYPE_INT_2:
2385    case TYPE_ENUM_2:
2386       params[1] = ((GLint *) p)[1];
2387    case TYPE_INT:
2388    case TYPE_ENUM:
2389       params[0] = ((GLint *) p)[0];
2390       break;
2391 
2392    case TYPE_INT_N:
2393       for (i = 0; i < v.value_int_n.n; i++)
2394 	 params[i] = INT_TO_BOOLEAN(v.value_int_n.ints[i]);
2395       break;
2396 
2397    case TYPE_INT64:
2398       params[0] = ((GLint64 *) p)[0];
2399       break;
2400 
2401    case TYPE_BOOLEAN:
2402       params[0] = ((GLboolean*) p)[0];
2403       break;
2404 
2405    case TYPE_MATRIX:
2406       m = *(GLmatrix **) p;
2407       for (i = 0; i < 16; i++)
2408 	 params[i] = FLOAT_TO_INT64(m->m[i]);
2409       break;
2410 
2411    case TYPE_MATRIX_T:
2412       m = *(GLmatrix **) p;
2413       for (i = 0; i < 16; i++)
2414 	 params[i] = FLOAT_TO_INT64(m->m[transpose[i]]);
2415       break;
2416 
2417    case TYPE_BIT_0:
2418    case TYPE_BIT_1:
2419    case TYPE_BIT_2:
2420    case TYPE_BIT_3:
2421    case TYPE_BIT_4:
2422    case TYPE_BIT_5:
2423    case TYPE_BIT_6:
2424    case TYPE_BIT_7:
2425       shift = d->type - TYPE_BIT_0;
2426       params[0] = (*(GLbitfield *) p >> shift) & 1;
2427       break;
2428    }
2429 }
2430 #endif /* FEATURE_ARB_sync */
2431 
2432 void GLAPIENTRY
_mesa_GetDoublev(GLenum pname,GLdouble * params)2433 _mesa_GetDoublev(GLenum pname, GLdouble *params)
2434 {
2435    const struct value_desc *d;
2436    union value v;
2437    GLmatrix *m;
2438    int shift, i;
2439    void *p;
2440    GET_CURRENT_CONTEXT(ctx);
2441 
2442    ASSERT_OUTSIDE_BEGIN_END(ctx);
2443 
2444    d = find_value("glGetDoublev", pname, &p, &v);
2445    switch (d->type) {
2446    case TYPE_INVALID:
2447       break;
2448    case TYPE_CONST:
2449       params[0] = d->offset;
2450       break;
2451 
2452    case TYPE_FLOAT_4:
2453    case TYPE_FLOATN_4:
2454       params[3] = ((GLfloat *) p)[3];
2455    case TYPE_FLOAT_3:
2456    case TYPE_FLOATN_3:
2457       params[2] = ((GLfloat *) p)[2];
2458    case TYPE_FLOAT_2:
2459    case TYPE_FLOATN_2:
2460       params[1] = ((GLfloat *) p)[1];
2461    case TYPE_FLOAT:
2462    case TYPE_FLOATN:
2463       params[0] = ((GLfloat *) p)[0];
2464       break;
2465 
2466    case TYPE_DOUBLEN:
2467       params[0] = ((GLdouble *) p)[0];
2468       break;
2469 
2470    case TYPE_INT_4:
2471       params[3] = ((GLint *) p)[3];
2472    case TYPE_INT_3:
2473       params[2] = ((GLint *) p)[2];
2474    case TYPE_INT_2:
2475    case TYPE_ENUM_2:
2476       params[1] = ((GLint *) p)[1];
2477    case TYPE_INT:
2478    case TYPE_ENUM:
2479       params[0] = ((GLint *) p)[0];
2480       break;
2481 
2482    case TYPE_INT_N:
2483       for (i = 0; i < v.value_int_n.n; i++)
2484 	 params[i] = v.value_int_n.ints[i];
2485       break;
2486 
2487    case TYPE_INT64:
2488       params[0] = ((GLint64 *) p)[0];
2489       break;
2490 
2491    case TYPE_BOOLEAN:
2492       params[0] = *(GLboolean*) p;
2493       break;
2494 
2495    case TYPE_MATRIX:
2496       m = *(GLmatrix **) p;
2497       for (i = 0; i < 16; i++)
2498 	 params[i] = m->m[i];
2499       break;
2500 
2501    case TYPE_MATRIX_T:
2502       m = *(GLmatrix **) p;
2503       for (i = 0; i < 16; i++)
2504 	 params[i] = m->m[transpose[i]];
2505       break;
2506 
2507    case TYPE_BIT_0:
2508    case TYPE_BIT_1:
2509    case TYPE_BIT_2:
2510    case TYPE_BIT_3:
2511    case TYPE_BIT_4:
2512    case TYPE_BIT_5:
2513    case TYPE_BIT_6:
2514    case TYPE_BIT_7:
2515       shift = d->type - TYPE_BIT_0;
2516       params[0] = (*(GLbitfield *) p >> shift) & 1;
2517       break;
2518    }
2519 }
2520 
2521 static enum value_type
find_value_indexed(const char * func,GLenum pname,int index,union value * v)2522 find_value_indexed(const char *func, GLenum pname, int index, union value *v)
2523 {
2524    GET_CURRENT_CONTEXT(ctx);
2525 
2526    switch (pname) {
2527 
2528    case GL_BLEND:
2529       if (index >= ctx->Const.MaxDrawBuffers)
2530 	 goto invalid_value;
2531       if (!ctx->Extensions.EXT_draw_buffers2)
2532 	 goto invalid_enum;
2533       v->value_int = (ctx->Color.BlendEnabled >> index) & 1;
2534       return TYPE_INT;
2535 
2536    case GL_BLEND_SRC:
2537       /* fall-through */
2538    case GL_BLEND_SRC_RGB:
2539       if (index >= ctx->Const.MaxDrawBuffers)
2540 	 goto invalid_value;
2541       if (!ctx->Extensions.ARB_draw_buffers_blend)
2542 	 goto invalid_enum;
2543       v->value_int = ctx->Color.Blend[index].SrcRGB;
2544       return TYPE_INT;
2545    case GL_BLEND_SRC_ALPHA:
2546       if (index >= ctx->Const.MaxDrawBuffers)
2547 	 goto invalid_value;
2548       if (!ctx->Extensions.ARB_draw_buffers_blend)
2549 	 goto invalid_enum;
2550       v->value_int = ctx->Color.Blend[index].SrcA;
2551       return TYPE_INT;
2552    case GL_BLEND_DST:
2553       /* fall-through */
2554    case GL_BLEND_DST_RGB:
2555       if (index >= ctx->Const.MaxDrawBuffers)
2556 	 goto invalid_value;
2557       if (!ctx->Extensions.ARB_draw_buffers_blend)
2558 	 goto invalid_enum;
2559       v->value_int = ctx->Color.Blend[index].DstRGB;
2560       return TYPE_INT;
2561    case GL_BLEND_DST_ALPHA:
2562       if (index >= ctx->Const.MaxDrawBuffers)
2563 	 goto invalid_value;
2564       if (!ctx->Extensions.ARB_draw_buffers_blend)
2565 	 goto invalid_enum;
2566       v->value_int = ctx->Color.Blend[index].DstA;
2567       return TYPE_INT;
2568    case GL_BLEND_EQUATION_RGB:
2569       if (index >= ctx->Const.MaxDrawBuffers)
2570 	 goto invalid_value;
2571       if (!ctx->Extensions.ARB_draw_buffers_blend)
2572 	 goto invalid_enum;
2573       v->value_int = ctx->Color.Blend[index].EquationRGB;
2574       return TYPE_INT;
2575    case GL_BLEND_EQUATION_ALPHA:
2576       if (index >= ctx->Const.MaxDrawBuffers)
2577 	 goto invalid_value;
2578       if (!ctx->Extensions.ARB_draw_buffers_blend)
2579 	 goto invalid_enum;
2580       v->value_int = ctx->Color.Blend[index].EquationA;
2581       return TYPE_INT;
2582 
2583    case GL_COLOR_WRITEMASK:
2584       if (index >= ctx->Const.MaxDrawBuffers)
2585 	 goto invalid_value;
2586       if (!ctx->Extensions.EXT_draw_buffers2)
2587 	 goto invalid_enum;
2588       v->value_int_4[0] = ctx->Color.ColorMask[index][RCOMP] ? 1 : 0;
2589       v->value_int_4[1] = ctx->Color.ColorMask[index][GCOMP] ? 1 : 0;
2590       v->value_int_4[2] = ctx->Color.ColorMask[index][BCOMP] ? 1 : 0;
2591       v->value_int_4[3] = ctx->Color.ColorMask[index][ACOMP] ? 1 : 0;
2592       return TYPE_INT_4;
2593 
2594    case GL_TRANSFORM_FEEDBACK_BUFFER_START:
2595       if (index >= ctx->Const.MaxTransformFeedbackBuffers)
2596 	 goto invalid_value;
2597       if (!ctx->Extensions.EXT_transform_feedback)
2598 	 goto invalid_enum;
2599       v->value_int64 = ctx->TransformFeedback.CurrentObject->Offset[index];
2600       return TYPE_INT64;
2601 
2602    case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
2603       if (index >= ctx->Const.MaxTransformFeedbackBuffers)
2604 	 goto invalid_value;
2605       if (!ctx->Extensions.EXT_transform_feedback)
2606 	 goto invalid_enum;
2607       v->value_int64 = ctx->TransformFeedback.CurrentObject->Size[index];
2608       return TYPE_INT64;
2609 
2610    case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
2611       if (index >= ctx->Const.MaxTransformFeedbackBuffers)
2612 	 goto invalid_value;
2613       if (!ctx->Extensions.EXT_transform_feedback)
2614 	 goto invalid_enum;
2615       v->value_int = ctx->TransformFeedback.CurrentObject->BufferNames[index];
2616       return TYPE_INT;
2617 
2618    case GL_UNIFORM_BUFFER_BINDING:
2619       if (index >= ctx->Const.MaxUniformBufferBindings)
2620 	 goto invalid_value;
2621       if (!ctx->Extensions.ARB_uniform_buffer_object)
2622 	 goto invalid_enum;
2623       v->value_int = ctx->UniformBufferBindings[index].BufferObject->Name;
2624       return TYPE_INT;
2625 
2626    case GL_UNIFORM_BUFFER_START:
2627       if (index >= ctx->Const.MaxUniformBufferBindings)
2628 	 goto invalid_value;
2629       if (!ctx->Extensions.ARB_uniform_buffer_object)
2630 	 goto invalid_enum;
2631       v->value_int = ctx->UniformBufferBindings[index].Offset;
2632       return TYPE_INT;
2633 
2634    case GL_UNIFORM_BUFFER_SIZE:
2635       if (index >= ctx->Const.MaxUniformBufferBindings)
2636 	 goto invalid_value;
2637       if (!ctx->Extensions.ARB_uniform_buffer_object)
2638 	 goto invalid_enum;
2639       v->value_int = ctx->UniformBufferBindings[index].Size;
2640       return TYPE_INT;
2641    }
2642 
2643  invalid_enum:
2644    _mesa_error(ctx, GL_INVALID_ENUM, "%s(pname=%s)", func,
2645                _mesa_lookup_enum_by_nr(pname));
2646    return TYPE_INVALID;
2647  invalid_value:
2648    _mesa_error(ctx, GL_INVALID_VALUE, "%s(pname=%s)", func,
2649                _mesa_lookup_enum_by_nr(pname));
2650    return TYPE_INVALID;
2651 }
2652 
2653 void GLAPIENTRY
_mesa_GetBooleanIndexedv(GLenum pname,GLuint index,GLboolean * params)2654 _mesa_GetBooleanIndexedv( GLenum pname, GLuint index, GLboolean *params )
2655 {
2656    union value v;
2657    enum value_type type =
2658       find_value_indexed("glGetBooleanIndexedv", pname, index, &v);
2659 
2660    switch (type) {
2661    case TYPE_INT:
2662       params[0] = INT_TO_BOOLEAN(v.value_int);
2663       break;
2664    case TYPE_INT_4:
2665       params[0] = INT_TO_BOOLEAN(v.value_int_4[0]);
2666       params[1] = INT_TO_BOOLEAN(v.value_int_4[1]);
2667       params[2] = INT_TO_BOOLEAN(v.value_int_4[2]);
2668       params[3] = INT_TO_BOOLEAN(v.value_int_4[3]);
2669       break;
2670    case TYPE_INT64:
2671       params[0] = INT64_TO_BOOLEAN(v.value_int);
2672       break;
2673    default:
2674       ; /* nothing - GL error was recorded */
2675    }
2676 }
2677 
2678 void GLAPIENTRY
_mesa_GetIntegerIndexedv(GLenum pname,GLuint index,GLint * params)2679 _mesa_GetIntegerIndexedv( GLenum pname, GLuint index, GLint *params )
2680 {
2681    union value v;
2682    enum value_type type =
2683       find_value_indexed("glGetIntegerIndexedv", pname, index, &v);
2684 
2685    switch (type) {
2686    case TYPE_INT:
2687       params[0] = v.value_int;
2688       break;
2689    case TYPE_INT_4:
2690       params[0] = v.value_int_4[0];
2691       params[1] = v.value_int_4[1];
2692       params[2] = v.value_int_4[2];
2693       params[3] = v.value_int_4[3];
2694       break;
2695    case TYPE_INT64:
2696       params[0] = INT64_TO_INT(v.value_int);
2697       break;
2698    default:
2699       ; /* nothing - GL error was recorded */
2700    }
2701 }
2702 
2703 #if FEATURE_ARB_sync
2704 void GLAPIENTRY
_mesa_GetInteger64Indexedv(GLenum pname,GLuint index,GLint64 * params)2705 _mesa_GetInteger64Indexedv( GLenum pname, GLuint index, GLint64 *params )
2706 {
2707    union value v;
2708    enum value_type type =
2709       find_value_indexed("glGetIntegerIndexedv", pname, index, &v);
2710 
2711    switch (type) {
2712    case TYPE_INT:
2713       params[0] = v.value_int;
2714       break;
2715    case TYPE_INT_4:
2716       params[0] = v.value_int_4[0];
2717       params[1] = v.value_int_4[1];
2718       params[2] = v.value_int_4[2];
2719       params[3] = v.value_int_4[3];
2720       break;
2721    case TYPE_INT64:
2722       params[0] = v.value_int;
2723       break;
2724    default:
2725       ; /* nothing - GL error was recorded */
2726    }
2727 }
2728 #endif /* FEATURE_ARB_sync */
2729 
2730 #if FEATURE_ES1
2731 void GLAPIENTRY
_mesa_GetFixedv(GLenum pname,GLfixed * params)2732 _mesa_GetFixedv(GLenum pname, GLfixed *params)
2733 {
2734    const struct value_desc *d;
2735    union value v;
2736    GLmatrix *m;
2737    int shift, i;
2738    void *p;
2739 
2740    d = find_value("glGetDoublev", pname, &p, &v);
2741    switch (d->type) {
2742    case TYPE_INVALID:
2743       break;
2744    case TYPE_CONST:
2745       params[0] = INT_TO_FIXED(d->offset);
2746       break;
2747 
2748    case TYPE_FLOAT_4:
2749    case TYPE_FLOATN_4:
2750       params[3] = FLOAT_TO_FIXED(((GLfloat *) p)[3]);
2751    case TYPE_FLOAT_3:
2752    case TYPE_FLOATN_3:
2753       params[2] = FLOAT_TO_FIXED(((GLfloat *) p)[2]);
2754    case TYPE_FLOAT_2:
2755    case TYPE_FLOATN_2:
2756       params[1] = FLOAT_TO_FIXED(((GLfloat *) p)[1]);
2757    case TYPE_FLOAT:
2758    case TYPE_FLOATN:
2759       params[0] = FLOAT_TO_FIXED(((GLfloat *) p)[0]);
2760       break;
2761 
2762    case TYPE_DOUBLEN:
2763       params[0] = FLOAT_TO_FIXED(((GLdouble *) p)[0]);
2764       break;
2765 
2766    case TYPE_INT_4:
2767       params[3] = INT_TO_FIXED(((GLint *) p)[3]);
2768    case TYPE_INT_3:
2769       params[2] = INT_TO_FIXED(((GLint *) p)[2]);
2770    case TYPE_INT_2:
2771    case TYPE_ENUM_2:
2772       params[1] = INT_TO_FIXED(((GLint *) p)[1]);
2773    case TYPE_INT:
2774    case TYPE_ENUM:
2775       params[0] = INT_TO_FIXED(((GLint *) p)[0]);
2776       break;
2777 
2778    case TYPE_INT_N:
2779       for (i = 0; i < v.value_int_n.n; i++)
2780 	 params[i] = INT_TO_FIXED(v.value_int_n.ints[i]);
2781       break;
2782 
2783    case TYPE_INT64:
2784       params[0] = ((GLint64 *) p)[0];
2785       break;
2786 
2787    case TYPE_BOOLEAN:
2788       params[0] = BOOLEAN_TO_FIXED(((GLboolean*) p)[0]);
2789       break;
2790 
2791    case TYPE_MATRIX:
2792       m = *(GLmatrix **) p;
2793       for (i = 0; i < 16; i++)
2794 	 params[i] = FLOAT_TO_FIXED(m->m[i]);
2795       break;
2796 
2797    case TYPE_MATRIX_T:
2798       m = *(GLmatrix **) p;
2799       for (i = 0; i < 16; i++)
2800 	 params[i] = FLOAT_TO_FIXED(m->m[transpose[i]]);
2801       break;
2802 
2803    case TYPE_BIT_0:
2804    case TYPE_BIT_1:
2805    case TYPE_BIT_2:
2806    case TYPE_BIT_3:
2807    case TYPE_BIT_4:
2808    case TYPE_BIT_5:
2809    case TYPE_BIT_6:
2810    case TYPE_BIT_7:
2811       shift = d->type - TYPE_BIT_0;
2812       params[0] = BOOLEAN_TO_FIXED((*(GLbitfield *) p >> shift) & 1);
2813       break;
2814    }
2815 }
2816 #endif
2817