220b529d76ddb9fefc4601e9e3b1f6f48348c853
[reactos.git] / reactos / dll / opengl / mesa / main / get.c
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 <precomp.h>
26
27 /* This is a table driven implemetation of the glGet*v() functions.
28 * The basic idea is that most getters just look up an int somewhere
29 * in struct gl_context and then convert it to a bool or float according to
30 * which of glGetIntegerv() glGetBooleanv() etc is being called.
31 * Instead of generating code to do this, we can just record the enum
32 * value and the offset into struct gl_context in an array of structs. Then
33 * in glGet*(), we lookup the struct for the enum in question, and use
34 * the offset to get the int we need.
35 *
36 * Sometimes we need to look up a float, a boolean, a bit in a
37 * bitfield, a matrix or other types instead, so we need to track the
38 * type of the value in struct gl_context. And sometimes the value isn't in
39 * struct gl_context but in the drawbuffer, the array object, current texture
40 * unit, or maybe it's a computed value. So we need to also track
41 * where or how to find the value. Finally, we sometimes need to
42 * check that one of a number of extensions are enabled, the GL
43 * version or flush or call _mesa_update_state(). This is done by
44 * attaching optional extra information to the value description
45 * struct, it's sort of like an array of opcodes that describe extra
46 * checks or actions.
47 *
48 * Putting all this together we end up with struct value_desc below,
49 * and with a couple of macros to help, the table of struct value_desc
50 * is about as concise as the specification in the old python script.
51 */
52
53 #undef CONST
54
55 #define FLOAT_TO_BOOLEAN(X) ( (X) ? GL_TRUE : GL_FALSE )
56 #define FLOAT_TO_FIXED(F) ( ((F) * 65536.0f > INT_MAX) ? INT_MAX : \
57 ((F) * 65536.0f < INT_MIN) ? INT_MIN : \
58 (GLint) ((F) * 65536.0f) )
59
60 #define INT_TO_BOOLEAN(I) ( (I) ? GL_TRUE : GL_FALSE )
61 #define INT_TO_FIXED(I) ( ((I) > SHRT_MAX) ? INT_MAX : \
62 ((I) < SHRT_MIN) ? INT_MIN : \
63 (GLint) ((I) * 65536) )
64
65 #define INT64_TO_BOOLEAN(I) ( (I) ? GL_TRUE : GL_FALSE )
66 #define INT64_TO_INT(I) ( (GLint)((I > INT_MAX) ? INT_MAX : ((I < INT_MIN) ? INT_MIN : (I))) )
67
68 #define BOOLEAN_TO_INT(B) ( (GLint) (B) )
69 #define BOOLEAN_TO_INT64(B) ( (GLint64) (B) )
70 #define BOOLEAN_TO_FLOAT(B) ( (B) ? 1.0F : 0.0F )
71 #define BOOLEAN_TO_FIXED(B) ( (GLint) ((B) ? 1 : 0) << 16 )
72
73 #define ENUM_TO_INT64(E) ( (GLint64) (E) )
74 #define ENUM_TO_FIXED(E) (E)
75
76 enum value_type {
77 TYPE_INVALID,
78 TYPE_INT,
79 TYPE_INT_2,
80 TYPE_INT_3,
81 TYPE_INT_4,
82 TYPE_INT_N,
83 TYPE_INT64,
84 TYPE_ENUM,
85 TYPE_ENUM_2,
86 TYPE_BOOLEAN,
87 TYPE_BIT_0,
88 TYPE_BIT_1,
89 TYPE_BIT_2,
90 TYPE_BIT_3,
91 TYPE_BIT_4,
92 TYPE_BIT_5,
93 TYPE_BIT_6,
94 TYPE_BIT_7,
95 TYPE_FLOAT,
96 TYPE_FLOAT_2,
97 TYPE_FLOAT_3,
98 TYPE_FLOAT_4,
99 TYPE_FLOATN,
100 TYPE_FLOATN_2,
101 TYPE_FLOATN_3,
102 TYPE_FLOATN_4,
103 TYPE_DOUBLEN,
104 TYPE_MATRIX,
105 TYPE_MATRIX_T,
106 TYPE_CONST
107 };
108
109 enum value_location {
110 LOC_BUFFER,
111 LOC_CONTEXT,
112 LOC_ARRAY,
113 LOC_TEXUNIT,
114 LOC_CUSTOM
115 };
116
117 enum value_extra {
118 EXTRA_END = 0x8000,
119 EXTRA_VERSION_30,
120 EXTRA_VERSION_31,
121 EXTRA_VERSION_32,
122 EXTRA_NEW_BUFFERS,
123 EXTRA_VALID_TEXTURE_UNIT,
124 EXTRA_VALID_CLIP_DISTANCE,
125 EXTRA_FLUSH_CURRENT,
126 };
127
128 #define NO_EXTRA NULL
129 #define NO_OFFSET 0
130
131 struct value_desc {
132 GLenum pname;
133 GLubyte location; /**< enum value_location */
134 GLubyte type; /**< enum value_type */
135 int offset;
136 const int *extra;
137 };
138
139 union value {
140 GLfloat value_float;
141 GLfloat value_float_4[4];
142 GLmatrix *value_matrix;
143 GLint value_int;
144 GLint value_int_4[4];
145 GLint64 value_int64;
146 GLenum value_enum;
147
148 /* Sigh, see GL_COMPRESSED_TEXTURE_FORMATS_ARB handling */
149 struct {
150 GLint n, ints[100];
151 } value_int_n;
152 GLboolean value_bool;
153 };
154
155 #define BUFFER_FIELD(field, type) \
156 LOC_BUFFER, type, offsetof(struct gl_framebuffer, field)
157 #define CONTEXT_FIELD(field, type) \
158 LOC_CONTEXT, type, offsetof(struct gl_context, field)
159 #define ARRAY_FIELD(field, type) \
160 LOC_ARRAY, type, offsetof(struct gl_array_attrib, field)
161 #define CONST(value) \
162 LOC_CONTEXT, TYPE_CONST, value
163
164 #define BUFFER_INT(field) BUFFER_FIELD(field, TYPE_INT)
165 #define BUFFER_ENUM(field) BUFFER_FIELD(field, TYPE_ENUM)
166 #define BUFFER_BOOL(field) BUFFER_FIELD(field, TYPE_BOOLEAN)
167
168 #define CONTEXT_INT(field) CONTEXT_FIELD(field, TYPE_INT)
169 #define CONTEXT_INT2(field) CONTEXT_FIELD(field, TYPE_INT_2)
170 #define CONTEXT_INT64(field) CONTEXT_FIELD(field, TYPE_INT64)
171 #define CONTEXT_ENUM(field) CONTEXT_FIELD(field, TYPE_ENUM)
172 #define CONTEXT_ENUM2(field) CONTEXT_FIELD(field, TYPE_ENUM_2)
173 #define CONTEXT_BOOL(field) CONTEXT_FIELD(field, TYPE_BOOLEAN)
174 #define CONTEXT_BIT0(field) CONTEXT_FIELD(field, TYPE_BIT_0)
175 #define CONTEXT_BIT1(field) CONTEXT_FIELD(field, TYPE_BIT_1)
176 #define CONTEXT_BIT2(field) CONTEXT_FIELD(field, TYPE_BIT_2)
177 #define CONTEXT_BIT3(field) CONTEXT_FIELD(field, TYPE_BIT_3)
178 #define CONTEXT_BIT4(field) CONTEXT_FIELD(field, TYPE_BIT_4)
179 #define CONTEXT_BIT5(field) CONTEXT_FIELD(field, TYPE_BIT_5)
180 #define CONTEXT_BIT6(field) CONTEXT_FIELD(field, TYPE_BIT_6)
181 #define CONTEXT_BIT7(field) CONTEXT_FIELD(field, TYPE_BIT_7)
182 #define CONTEXT_FLOAT(field) CONTEXT_FIELD(field, TYPE_FLOAT)
183 #define CONTEXT_FLOAT2(field) CONTEXT_FIELD(field, TYPE_FLOAT_2)
184 #define CONTEXT_FLOAT3(field) CONTEXT_FIELD(field, TYPE_FLOAT_3)
185 #define CONTEXT_FLOAT4(field) CONTEXT_FIELD(field, TYPE_FLOAT_4)
186 #define CONTEXT_MATRIX(field) CONTEXT_FIELD(field, TYPE_MATRIX)
187 #define CONTEXT_MATRIX_T(field) CONTEXT_FIELD(field, TYPE_MATRIX_T)
188
189 #define ARRAY_INT(field) ARRAY_FIELD(field, TYPE_INT)
190 #define ARRAY_ENUM(field) ARRAY_FIELD(field, TYPE_ENUM)
191 #define ARRAY_BOOL(field) ARRAY_FIELD(field, TYPE_BOOLEAN)
192
193 #define EXT(f) \
194 offsetof(struct gl_extensions, f)
195
196 #define EXTRA_EXT(e) \
197 static const int extra_##e[] = { \
198 EXT(e), EXTRA_END \
199 }
200
201 #define EXTRA_EXT2(e1, e2) \
202 static const int extra_##e1##_##e2[] = { \
203 EXT(e1), EXT(e2), EXTRA_END \
204 }
205
206 /* The 'extra' mechanism is a way to specify extra checks (such as
207 * extensions or specific gl versions) or actions (flush current, new
208 * buffers) that we need to do before looking up an enum. We need to
209 * declare them all up front so we can refer to them in the value_desc
210 * structs below. */
211
212 static const int extra_new_buffers[] = {
213 EXTRA_NEW_BUFFERS,
214 EXTRA_END
215 };
216
217 static const int extra_valid_texture_unit[] = {
218 EXTRA_VALID_TEXTURE_UNIT,
219 EXTRA_END
220 };
221
222 static const int extra_valid_clip_distance[] = {
223 EXTRA_VALID_CLIP_DISTANCE,
224 EXTRA_END
225 };
226
227 static const int extra_flush_current_valid_texture_unit[] = {
228 EXTRA_FLUSH_CURRENT,
229 EXTRA_VALID_TEXTURE_UNIT,
230 EXTRA_END
231 };
232
233 static const int extra_flush_current[] = {
234 EXTRA_FLUSH_CURRENT,
235 EXTRA_END
236 };
237
238 static const int extra_EXT_fog_coord_flush_current[] = {
239 EXT(EXT_fog_coord),
240 EXTRA_FLUSH_CURRENT,
241 EXTRA_END
242 };
243
244 static const int extra_EXT_texture_integer[] = {
245 EXT(EXT_texture_integer),
246 EXTRA_END
247 };
248
249
250 EXTRA_EXT(ARB_texture_cube_map);
251 EXTRA_EXT(EXT_fog_coord);
252 EXTRA_EXT(NV_fog_distance);
253 EXTRA_EXT(EXT_texture_filter_anisotropic);
254 EXTRA_EXT(IBM_rasterpos_clip);
255 EXTRA_EXT(NV_point_sprite);
256 EXTRA_EXT(NV_light_max_exponent);
257 EXTRA_EXT(EXT_depth_bounds_test);
258 EXTRA_EXT(EXT_compiled_vertex_array);
259 EXTRA_EXT2(NV_point_sprite, ARB_point_sprite);
260
261 static const int extra_version_30[] = { EXTRA_VERSION_30, EXTRA_END };
262 static const int extra_version_32[] = { EXTRA_VERSION_32, EXTRA_END };
263
264 #define API_OPENGL_BIT (1 << API_OPENGL)
265
266 /* This is the big table describing all the enums we accept in
267 * glGet*v(). The table is partitioned into six parts: enums
268 * understood by all GL APIs (OpenGL, GLES and GLES2), enums shared
269 * between OpenGL and GLES, enums exclusive to GLES, etc for the
270 * remaining combinations. When we add the enums to the hash table in
271 * _mesa_init_get_hash(), we only add the enums for the API we're
272 * instantiating and the different sections are guarded by #if
273 * FEATURE_GL etc to make sure we only compile in the enums we may
274 * need. */
275
276 static const struct value_desc values[] = {
277 { GL_ALPHA_BITS, BUFFER_INT(Visual.alphaBits), extra_new_buffers },
278 { GL_BLEND, CONTEXT_BIT0(Color.BlendEnabled), NO_EXTRA },
279 { GL_BLEND_SRC, CONTEXT_ENUM(Color.SrcFactor), NO_EXTRA },
280 { GL_BLUE_BITS, BUFFER_INT(Visual.blueBits), extra_new_buffers },
281 { GL_COLOR_CLEAR_VALUE, LOC_CUSTOM, TYPE_FLOATN_4, 0, NO_EXTRA },
282 { GL_COLOR_WRITEMASK, LOC_CUSTOM, TYPE_INT_4, 0, NO_EXTRA },
283 { GL_CULL_FACE, CONTEXT_BOOL(Polygon.CullFlag), NO_EXTRA },
284 { GL_CULL_FACE_MODE, CONTEXT_ENUM(Polygon.CullFaceMode), NO_EXTRA },
285 { GL_DEPTH_BITS, BUFFER_INT(Visual.depthBits), NO_EXTRA },
286 { GL_DEPTH_CLEAR_VALUE, CONTEXT_FIELD(Depth.Clear, TYPE_DOUBLEN), NO_EXTRA },
287 { GL_DEPTH_FUNC, CONTEXT_ENUM(Depth.Func), NO_EXTRA },
288 { GL_DEPTH_RANGE, CONTEXT_FIELD(Viewport.Near, TYPE_FLOATN_2), NO_EXTRA },
289 { GL_DEPTH_TEST, CONTEXT_BOOL(Depth.Test), NO_EXTRA },
290 { GL_DEPTH_WRITEMASK, CONTEXT_BOOL(Depth.Mask), NO_EXTRA },
291 { GL_DITHER, CONTEXT_BOOL(Color.DitherFlag), NO_EXTRA },
292 { GL_FRONT_FACE, CONTEXT_ENUM(Polygon.FrontFace), NO_EXTRA },
293 { GL_GREEN_BITS, BUFFER_INT(Visual.greenBits), extra_new_buffers },
294 { GL_LINE_WIDTH, CONTEXT_FLOAT(Line.Width), NO_EXTRA },
295 { GL_ALIASED_LINE_WIDTH_RANGE, CONTEXT_FLOAT2(Const.MinLineWidth), NO_EXTRA },
296 { GL_MAX_ELEMENTS_VERTICES, CONTEXT_INT(Const.MaxArrayLockSize), NO_EXTRA },
297 { GL_MAX_ELEMENTS_INDICES, CONTEXT_INT(Const.MaxArrayLockSize), NO_EXTRA },
298 { GL_MAX_TEXTURE_SIZE, LOC_CUSTOM, TYPE_INT,
299 offsetof(struct gl_context, Const.MaxTextureLevels), NO_EXTRA },
300 { GL_MAX_VIEWPORT_DIMS, CONTEXT_INT2(Const.MaxViewportWidth), NO_EXTRA },
301 { GL_PACK_ALIGNMENT, CONTEXT_INT(Pack.Alignment), NO_EXTRA },
302 { GL_ALIASED_POINT_SIZE_RANGE, CONTEXT_FLOAT2(Const.MinPointSize), NO_EXTRA },
303 { GL_POLYGON_OFFSET_FACTOR, CONTEXT_FLOAT(Polygon.OffsetFactor ), NO_EXTRA },
304 { GL_POLYGON_OFFSET_UNITS, CONTEXT_FLOAT(Polygon.OffsetUnits ), NO_EXTRA },
305 { GL_POLYGON_OFFSET_FILL, CONTEXT_BOOL(Polygon.OffsetFill), NO_EXTRA },
306 { GL_RED_BITS, BUFFER_INT(Visual.redBits), extra_new_buffers },
307 { GL_SCISSOR_BOX, LOC_CUSTOM, TYPE_INT_4, 0, NO_EXTRA },
308 { GL_SCISSOR_TEST, CONTEXT_BOOL(Scissor.Enabled), NO_EXTRA },
309 { GL_STENCIL_BITS, BUFFER_INT(Visual.stencilBits), NO_EXTRA },
310 { GL_STENCIL_CLEAR_VALUE, CONTEXT_INT(Stencil.Clear), NO_EXTRA },
311 { GL_STENCIL_FAIL, LOC_CUSTOM, TYPE_ENUM, NO_OFFSET, NO_EXTRA },
312 { GL_STENCIL_FUNC, LOC_CUSTOM, TYPE_ENUM, NO_OFFSET, NO_EXTRA },
313 { GL_STENCIL_PASS_DEPTH_FAIL, LOC_CUSTOM, TYPE_ENUM, NO_OFFSET, NO_EXTRA },
314 { GL_STENCIL_PASS_DEPTH_PASS, LOC_CUSTOM, TYPE_ENUM, NO_OFFSET, NO_EXTRA },
315 { GL_STENCIL_REF, LOC_CUSTOM, TYPE_INT, NO_OFFSET, NO_EXTRA },
316 { GL_STENCIL_TEST, CONTEXT_BOOL(Stencil.Enabled), NO_EXTRA },
317 { GL_STENCIL_VALUE_MASK, LOC_CUSTOM, TYPE_INT, NO_OFFSET, NO_EXTRA },
318 { GL_STENCIL_WRITEMASK, LOC_CUSTOM, TYPE_INT, NO_OFFSET, NO_EXTRA },
319 { GL_SUBPIXEL_BITS, CONTEXT_INT(Const.SubPixelBits), NO_EXTRA },
320 { GL_TEXTURE_BINDING_2D, LOC_CUSTOM, TYPE_INT, TEXTURE_2D_INDEX, NO_EXTRA },
321 { GL_UNPACK_ALIGNMENT, CONTEXT_INT(Unpack.Alignment), NO_EXTRA },
322 { GL_VIEWPORT, LOC_CUSTOM, TYPE_INT_4, 0, NO_EXTRA },
323
324 /* GL_ARB_multitexture */
325 { GL_ACTIVE_TEXTURE, LOC_CUSTOM, TYPE_INT, 0, NO_EXTRA },
326
327 /* Note that all the OES_* extensions require that the Mesa "struct
328 * gl_extensions" include a member with the name of the extension.
329 * That structure does not yet include OES extensions (and we're
330 * not sure whether it will). If it does, all the OES_*
331 * extensions below should mark the dependency. */
332
333 /* GL_ARB_texture_cube_map */
334 { GL_TEXTURE_BINDING_CUBE_MAP_ARB, LOC_CUSTOM, TYPE_INT,
335 TEXTURE_CUBE_INDEX, extra_ARB_texture_cube_map },
336 { GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB, LOC_CUSTOM, TYPE_INT,
337 offsetof(struct gl_context, Const.MaxCubeTextureLevels),
338 extra_ARB_texture_cube_map }, /* XXX: OES_texture_cube_map */
339
340 /* XXX: OES_blend_subtract */
341 { GL_BLEND_SRC_RGB_EXT, CONTEXT_ENUM(Color.SrcFactor), NO_EXTRA },
342 { GL_BLEND_DST_RGB_EXT, CONTEXT_ENUM(Color.DstFactor), NO_EXTRA },
343
344 /* GL_ARB_multisample */
345 { GL_SAMPLE_ALPHA_TO_COVERAGE_ARB,
346 CONTEXT_BOOL(Multisample.SampleAlphaToCoverage), NO_EXTRA },
347 { GL_SAMPLE_COVERAGE_ARB, CONTEXT_BOOL(Multisample.SampleCoverage), NO_EXTRA },
348 { GL_SAMPLE_COVERAGE_VALUE_ARB,
349 CONTEXT_FLOAT(Multisample.SampleCoverageValue), NO_EXTRA },
350 { GL_SAMPLE_COVERAGE_INVERT_ARB,
351 CONTEXT_BOOL(Multisample.SampleCoverageInvert), NO_EXTRA },
352
353 /* GL_ARB_vertex_buffer_object */
354 { GL_ARRAY_BUFFER_BINDING_ARB, LOC_CUSTOM, TYPE_INT, 0, NO_EXTRA },
355
356 /* GL_ARB_vertex_buffer_object */
357 /* GL_WEIGHT_ARRAY_BUFFER_BINDING_ARB - not supported */
358 { GL_ELEMENT_ARRAY_BUFFER_BINDING_ARB, LOC_CUSTOM, TYPE_INT, 0, NO_EXTRA },
359
360 /* GL_OES_read_format */
361 { GL_IMPLEMENTATION_COLOR_READ_TYPE_OES, LOC_CUSTOM, TYPE_INT, 0,
362 extra_new_buffers },
363 { GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES, LOC_CUSTOM, TYPE_INT, 0,
364 extra_new_buffers },
365
366 /* This entry isn't spec'ed for GLES 2, but is needed for Mesa's
367 * GLSL: */
368 { GL_MAX_CLIP_PLANES, CONTEXT_INT(Const.MaxClipPlanes), NO_EXTRA },
369
370 { GL_MAX_LIGHTS, CONTEXT_INT(Const.MaxLights), NO_EXTRA },
371 { GL_LIGHT0, CONTEXT_BOOL(Light.Light[0].Enabled), NO_EXTRA },
372 { GL_LIGHT1, CONTEXT_BOOL(Light.Light[1].Enabled), NO_EXTRA },
373 { GL_LIGHT2, CONTEXT_BOOL(Light.Light[2].Enabled), NO_EXTRA },
374 { GL_LIGHT3, CONTEXT_BOOL(Light.Light[3].Enabled), NO_EXTRA },
375 { GL_LIGHT4, CONTEXT_BOOL(Light.Light[4].Enabled), NO_EXTRA },
376 { GL_LIGHT5, CONTEXT_BOOL(Light.Light[5].Enabled), NO_EXTRA },
377 { GL_LIGHT6, CONTEXT_BOOL(Light.Light[6].Enabled), NO_EXTRA },
378 { GL_LIGHT7, CONTEXT_BOOL(Light.Light[7].Enabled), NO_EXTRA },
379 { GL_LIGHTING, CONTEXT_BOOL(Light.Enabled), NO_EXTRA },
380 { GL_LIGHT_MODEL_AMBIENT,
381 CONTEXT_FIELD(Light.Model.Ambient[0], TYPE_FLOATN_4), NO_EXTRA },
382 { GL_LIGHT_MODEL_TWO_SIDE, CONTEXT_BOOL(Light.Model.TwoSide), NO_EXTRA },
383 { GL_ALPHA_TEST, CONTEXT_BOOL(Color.AlphaEnabled), NO_EXTRA },
384 { GL_ALPHA_TEST_FUNC, CONTEXT_ENUM(Color.AlphaFunc), NO_EXTRA },
385 { GL_ALPHA_TEST_REF, LOC_CUSTOM, TYPE_FLOATN, 0, NO_EXTRA },
386 { GL_BLEND_DST, CONTEXT_ENUM(Color.DstFactor), NO_EXTRA },
387 { GL_CLIP_DISTANCE0, CONTEXT_BIT0(Transform.ClipPlanesEnabled), extra_valid_clip_distance },
388 { GL_CLIP_DISTANCE1, CONTEXT_BIT1(Transform.ClipPlanesEnabled), extra_valid_clip_distance },
389 { GL_CLIP_DISTANCE2, CONTEXT_BIT2(Transform.ClipPlanesEnabled), extra_valid_clip_distance },
390 { GL_CLIP_DISTANCE3, CONTEXT_BIT3(Transform.ClipPlanesEnabled), extra_valid_clip_distance },
391 { GL_CLIP_DISTANCE4, CONTEXT_BIT4(Transform.ClipPlanesEnabled), extra_valid_clip_distance },
392 { GL_CLIP_DISTANCE5, CONTEXT_BIT5(Transform.ClipPlanesEnabled), extra_valid_clip_distance },
393 { GL_CLIP_DISTANCE6, CONTEXT_BIT6(Transform.ClipPlanesEnabled), extra_valid_clip_distance },
394 { GL_CLIP_DISTANCE7, CONTEXT_BIT7(Transform.ClipPlanesEnabled), extra_valid_clip_distance },
395 { GL_COLOR_MATERIAL, CONTEXT_BOOL(Light.ColorMaterialEnabled), NO_EXTRA },
396 { GL_CURRENT_COLOR,
397 CONTEXT_FIELD(Current.Attrib[VERT_ATTRIB_COLOR][0], TYPE_FLOATN_4),
398 extra_flush_current },
399 { GL_CURRENT_NORMAL,
400 CONTEXT_FIELD(Current.Attrib[VERT_ATTRIB_NORMAL][0], TYPE_FLOATN_3),
401 extra_flush_current },
402 { GL_CURRENT_TEXTURE_COORDS, LOC_CUSTOM, TYPE_FLOAT_4, 0,
403 extra_flush_current_valid_texture_unit },
404 { GL_DISTANCE_ATTENUATION_EXT, CONTEXT_FLOAT3(Point.Params[0]), NO_EXTRA },
405 { GL_FOG, CONTEXT_BOOL(Fog.Enabled), NO_EXTRA },
406 { GL_FOG_COLOR, LOC_CUSTOM, TYPE_FLOATN_4, 0, NO_EXTRA },
407 { GL_FOG_DENSITY, CONTEXT_FLOAT(Fog.Density), NO_EXTRA },
408 { GL_FOG_END, CONTEXT_FLOAT(Fog.End), NO_EXTRA },
409 { GL_FOG_HINT, CONTEXT_ENUM(Hint.Fog), NO_EXTRA },
410 { GL_FOG_MODE, CONTEXT_ENUM(Fog.Mode), NO_EXTRA },
411 { GL_FOG_START, CONTEXT_FLOAT(Fog.Start), NO_EXTRA },
412 { GL_LINE_SMOOTH, CONTEXT_BOOL(Line.SmoothFlag), NO_EXTRA },
413 { GL_LINE_SMOOTH_HINT, CONTEXT_ENUM(Hint.LineSmooth), NO_EXTRA },
414 { GL_LINE_WIDTH_RANGE, CONTEXT_FLOAT2(Const.MinLineWidthAA), NO_EXTRA },
415 { GL_COLOR_LOGIC_OP, CONTEXT_BOOL(Color.ColorLogicOpEnabled), NO_EXTRA },
416 { GL_LOGIC_OP_MODE, CONTEXT_ENUM(Color.LogicOp), NO_EXTRA },
417 { GL_MATRIX_MODE, CONTEXT_ENUM(Transform.MatrixMode), NO_EXTRA },
418 { GL_MAX_MODELVIEW_STACK_DEPTH, CONST(MAX_MODELVIEW_STACK_DEPTH), NO_EXTRA },
419 { GL_MAX_PROJECTION_STACK_DEPTH, CONST(MAX_PROJECTION_STACK_DEPTH), NO_EXTRA },
420 { GL_MAX_TEXTURE_STACK_DEPTH, CONST(MAX_TEXTURE_STACK_DEPTH), NO_EXTRA },
421 { GL_MODELVIEW_MATRIX, CONTEXT_MATRIX(ModelviewMatrixStack.Top), NO_EXTRA },
422 { GL_MODELVIEW_STACK_DEPTH, LOC_CUSTOM, TYPE_INT,
423 offsetof(struct gl_context, ModelviewMatrixStack.Depth), NO_EXTRA },
424 { GL_NORMALIZE, CONTEXT_BOOL(Transform.Normalize), NO_EXTRA },
425 { GL_PACK_SKIP_IMAGES_EXT, CONTEXT_INT(Pack.SkipImages), NO_EXTRA },
426 { GL_PERSPECTIVE_CORRECTION_HINT, CONTEXT_ENUM(Hint.PerspectiveCorrection), NO_EXTRA },
427 { GL_POINT_SIZE, CONTEXT_FLOAT(Point.Size), NO_EXTRA },
428 { GL_POINT_SIZE_RANGE, CONTEXT_FLOAT2(Const.MinPointSizeAA), NO_EXTRA },
429 { GL_POINT_SMOOTH, CONTEXT_BOOL(Point.SmoothFlag), NO_EXTRA },
430 { GL_POINT_SMOOTH_HINT, CONTEXT_ENUM(Hint.PointSmooth), NO_EXTRA },
431 { GL_POINT_SIZE_MIN_EXT, CONTEXT_FLOAT(Point.MinSize), NO_EXTRA },
432 { GL_POINT_SIZE_MAX_EXT, CONTEXT_FLOAT(Point.MaxSize), NO_EXTRA },
433 { GL_POINT_FADE_THRESHOLD_SIZE_EXT, CONTEXT_FLOAT(Point.Threshold), NO_EXTRA },
434 { GL_PROJECTION_MATRIX, CONTEXT_MATRIX(ProjectionMatrixStack.Top), NO_EXTRA },
435 { GL_PROJECTION_STACK_DEPTH, LOC_CUSTOM, TYPE_INT,
436 offsetof(struct gl_context, ProjectionMatrixStack.Depth), NO_EXTRA },
437 { GL_RESCALE_NORMAL, CONTEXT_BOOL(Transform.RescaleNormals), NO_EXTRA },
438 { GL_SHADE_MODEL, CONTEXT_ENUM(Light.ShadeModel), NO_EXTRA },
439 { GL_TEXTURE_2D, LOC_CUSTOM, TYPE_BOOLEAN, 0, NO_EXTRA },
440 { GL_TEXTURE_MATRIX, LOC_CUSTOM, TYPE_MATRIX, 0, extra_valid_texture_unit },
441 { GL_TEXTURE_STACK_DEPTH, LOC_CUSTOM, TYPE_INT, 0,
442 extra_valid_texture_unit },
443
444 { GL_VERTEX_ARRAY, ARRAY_BOOL(VertexAttrib[VERT_ATTRIB_POS].Enabled), NO_EXTRA },
445 { GL_VERTEX_ARRAY_SIZE, ARRAY_INT(VertexAttrib[VERT_ATTRIB_POS].Size), NO_EXTRA },
446 { GL_VERTEX_ARRAY_TYPE, ARRAY_ENUM(VertexAttrib[VERT_ATTRIB_POS].Type), NO_EXTRA },
447 { GL_VERTEX_ARRAY_STRIDE, ARRAY_INT(VertexAttrib[VERT_ATTRIB_POS].Stride), NO_EXTRA },
448 { GL_NORMAL_ARRAY, ARRAY_BOOL(VertexAttrib[VERT_ATTRIB_NORMAL].Enabled), NO_EXTRA },
449 { GL_NORMAL_ARRAY_TYPE, ARRAY_ENUM(VertexAttrib[VERT_ATTRIB_NORMAL].Type), NO_EXTRA },
450 { GL_NORMAL_ARRAY_STRIDE, ARRAY_INT(VertexAttrib[VERT_ATTRIB_NORMAL].Stride), NO_EXTRA },
451 { GL_COLOR_ARRAY, ARRAY_BOOL(VertexAttrib[VERT_ATTRIB_COLOR].Enabled), NO_EXTRA },
452 { GL_COLOR_ARRAY_SIZE, ARRAY_INT(VertexAttrib[VERT_ATTRIB_COLOR].Size), NO_EXTRA },
453 { GL_COLOR_ARRAY_TYPE, ARRAY_ENUM(VertexAttrib[VERT_ATTRIB_COLOR].Type), NO_EXTRA },
454 { GL_COLOR_ARRAY_STRIDE, ARRAY_INT(VertexAttrib[VERT_ATTRIB_COLOR].Stride), NO_EXTRA },
455 { GL_TEXTURE_COORD_ARRAY,
456 LOC_CUSTOM, TYPE_BOOLEAN, offsetof(struct gl_client_array, Enabled), NO_EXTRA },
457 { GL_TEXTURE_COORD_ARRAY_SIZE,
458 LOC_CUSTOM, TYPE_INT, offsetof(struct gl_client_array, Size), NO_EXTRA },
459 { GL_TEXTURE_COORD_ARRAY_TYPE,
460 LOC_CUSTOM, TYPE_ENUM, offsetof(struct gl_client_array, Type), NO_EXTRA },
461 { GL_TEXTURE_COORD_ARRAY_STRIDE,
462 LOC_CUSTOM, TYPE_INT, offsetof(struct gl_client_array, Stride), NO_EXTRA },
463
464 /* GL_ARB_texture_cube_map */
465 { GL_TEXTURE_CUBE_MAP_ARB, LOC_CUSTOM, TYPE_BOOLEAN, 0, NO_EXTRA },
466 /* S, T, and R are always set at the same time */
467 { GL_TEXTURE_GEN_STR_OES, LOC_TEXUNIT, TYPE_BIT_0,
468 offsetof(struct gl_texture_unit, TexGenEnabled), NO_EXTRA },
469
470 /* GL_ARB_multisample */
471 { GL_MULTISAMPLE_ARB, CONTEXT_BOOL(Multisample.Enabled), NO_EXTRA },
472 { GL_SAMPLE_ALPHA_TO_ONE_ARB, CONTEXT_BOOL(Multisample.SampleAlphaToOne), NO_EXTRA },
473
474 /* GL_ARB_vertex_buffer_object */
475 { GL_VERTEX_ARRAY_BUFFER_BINDING_ARB, LOC_CUSTOM, TYPE_INT,
476 offsetof(struct gl_array_attrib, VertexAttrib[VERT_ATTRIB_POS].BufferObj), NO_EXTRA },
477 { GL_NORMAL_ARRAY_BUFFER_BINDING_ARB, LOC_CUSTOM, TYPE_INT,
478 offsetof(struct gl_array_attrib, VertexAttrib[VERT_ATTRIB_NORMAL].BufferObj), NO_EXTRA },
479 { GL_COLOR_ARRAY_BUFFER_BINDING_ARB, LOC_CUSTOM, TYPE_INT,
480 offsetof(struct gl_array_attrib, VertexAttrib[VERT_ATTRIB_COLOR].BufferObj), NO_EXTRA },
481 { GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING_ARB, LOC_CUSTOM, TYPE_INT, NO_OFFSET, NO_EXTRA },
482
483 /* GL_OES_point_sprite */
484 { GL_POINT_SPRITE_NV,
485 CONTEXT_BOOL(Point.PointSprite),
486 extra_NV_point_sprite_ARB_point_sprite },
487
488 /* GL_EXT_texture_filter_anisotropic */
489 { GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT,
490 CONTEXT_FLOAT(Const.MaxTextureMaxAnisotropy),
491 extra_EXT_texture_filter_anisotropic },
492
493 { GL_BLEND_COLOR_EXT, LOC_CUSTOM, TYPE_FLOATN_4, 0, NO_EXTRA },
494
495 { GL_ACCUM_RED_BITS, BUFFER_INT(Visual.accumRedBits), NO_EXTRA },
496 { GL_ACCUM_GREEN_BITS, BUFFER_INT(Visual.accumGreenBits), NO_EXTRA },
497 { GL_ACCUM_BLUE_BITS, BUFFER_INT(Visual.accumBlueBits), NO_EXTRA },
498 { GL_ACCUM_ALPHA_BITS, BUFFER_INT(Visual.accumAlphaBits), NO_EXTRA },
499 { GL_ACCUM_CLEAR_VALUE, CONTEXT_FIELD(Accum.ClearColor[0], TYPE_FLOATN_4), NO_EXTRA },
500 { GL_ALPHA_BIAS, CONTEXT_FLOAT(Pixel.AlphaBias), NO_EXTRA },
501 { GL_ALPHA_SCALE, CONTEXT_FLOAT(Pixel.AlphaScale), NO_EXTRA },
502 { GL_ATTRIB_STACK_DEPTH, CONTEXT_INT(AttribStackDepth), NO_EXTRA },
503 { GL_AUTO_NORMAL, CONTEXT_BOOL(Eval.AutoNormal), NO_EXTRA },
504 { GL_AUX_BUFFERS, BUFFER_INT(Visual.numAuxBuffers), NO_EXTRA },
505 { GL_BLUE_BIAS, CONTEXT_FLOAT(Pixel.BlueBias), NO_EXTRA },
506 { GL_BLUE_SCALE, CONTEXT_FLOAT(Pixel.BlueScale), NO_EXTRA },
507 { GL_CLIENT_ATTRIB_STACK_DEPTH, CONTEXT_INT(ClientAttribStackDepth), NO_EXTRA },
508 { GL_COLOR_MATERIAL_FACE, CONTEXT_ENUM(Light.ColorMaterialFace), NO_EXTRA },
509 { GL_COLOR_MATERIAL_PARAMETER, CONTEXT_ENUM(Light.ColorMaterialMode), NO_EXTRA },
510 { GL_CURRENT_INDEX,
511 CONTEXT_FLOAT(Current.Attrib[VERT_ATTRIB_COLOR_INDEX][0]),
512 extra_flush_current },
513 { GL_CURRENT_RASTER_COLOR,
514 CONTEXT_FIELD(Current.RasterColor[0], TYPE_FLOATN_4), NO_EXTRA },
515 { GL_CURRENT_RASTER_DISTANCE, CONTEXT_FLOAT(Current.RasterDistance), NO_EXTRA },
516 { GL_CURRENT_RASTER_INDEX, CONST(1), NO_EXTRA },
517 { GL_CURRENT_RASTER_POSITION, CONTEXT_FLOAT4(Current.RasterPos[0]), NO_EXTRA },
518 { GL_CURRENT_RASTER_TEXTURE_COORDS, LOC_CUSTOM, TYPE_FLOAT_4, 0,
519 extra_valid_texture_unit },
520 { GL_CURRENT_RASTER_POSITION_VALID, CONTEXT_BOOL(Current.RasterPosValid), NO_EXTRA },
521 { GL_DEPTH_BIAS, CONTEXT_FLOAT(Pixel.DepthBias), NO_EXTRA },
522 { GL_DEPTH_SCALE, CONTEXT_FLOAT(Pixel.DepthScale), NO_EXTRA },
523 { GL_DOUBLEBUFFER, BUFFER_INT(Visual.doubleBufferMode), NO_EXTRA },
524 { GL_DRAW_BUFFER, BUFFER_ENUM(ColorDrawBuffer), NO_EXTRA },
525 { GL_EDGE_FLAG, LOC_CUSTOM, TYPE_BOOLEAN, 0, NO_EXTRA },
526 { GL_FEEDBACK_BUFFER_SIZE, CONTEXT_INT(Feedback.BufferSize), NO_EXTRA },
527 { GL_FEEDBACK_BUFFER_TYPE, CONTEXT_ENUM(Feedback.Type), NO_EXTRA },
528 { GL_FOG_INDEX, CONTEXT_FLOAT(Fog.Index), NO_EXTRA },
529 { GL_GREEN_BIAS, CONTEXT_FLOAT(Pixel.GreenBias), NO_EXTRA },
530 { GL_GREEN_SCALE, CONTEXT_FLOAT(Pixel.GreenScale), NO_EXTRA },
531 { GL_INDEX_BITS, BUFFER_INT(Visual.indexBits), extra_new_buffers },
532 { GL_INDEX_CLEAR_VALUE, CONTEXT_INT(Color.ClearIndex), NO_EXTRA },
533 { GL_INDEX_MODE, CONST(0) , NO_EXTRA},
534 { GL_INDEX_OFFSET, CONTEXT_INT(Pixel.IndexOffset), NO_EXTRA },
535 { GL_INDEX_SHIFT, CONTEXT_INT(Pixel.IndexShift), NO_EXTRA },
536 { GL_INDEX_WRITEMASK, CONTEXT_INT(Color.IndexMask), NO_EXTRA },
537 { GL_LIGHT_MODEL_LOCAL_VIEWER, CONTEXT_BOOL(Light.Model.LocalViewer), NO_EXTRA },
538 { GL_LINE_STIPPLE, CONTEXT_BOOL(Line.StippleFlag), NO_EXTRA },
539 { GL_LINE_STIPPLE_PATTERN, LOC_CUSTOM, TYPE_INT, 0, NO_EXTRA },
540 { GL_LINE_STIPPLE_REPEAT, CONTEXT_INT(Line.StippleFactor), NO_EXTRA },
541 { GL_LINE_WIDTH_GRANULARITY, CONTEXT_FLOAT(Const.LineWidthGranularity), NO_EXTRA },
542 { GL_LIST_BASE, CONTEXT_INT(List.ListBase), NO_EXTRA },
543 { GL_LIST_INDEX, LOC_CUSTOM, TYPE_INT, 0, NO_EXTRA },
544 { GL_LIST_MODE, LOC_CUSTOM, TYPE_ENUM, 0, NO_EXTRA },
545 { GL_INDEX_LOGIC_OP, CONTEXT_BOOL(Color.IndexLogicOpEnabled), NO_EXTRA },
546 { GL_MAP1_COLOR_4, CONTEXT_BOOL(Eval.Map1Color4), NO_EXTRA },
547 { GL_MAP1_GRID_DOMAIN, CONTEXT_FLOAT2(Eval.MapGrid1u1), NO_EXTRA },
548 { GL_MAP1_GRID_SEGMENTS, CONTEXT_INT(Eval.MapGrid1un), NO_EXTRA },
549 { GL_MAP1_INDEX, CONTEXT_BOOL(Eval.Map1Index), NO_EXTRA },
550 { GL_MAP1_NORMAL, CONTEXT_BOOL(Eval.Map1Normal), NO_EXTRA },
551 { GL_MAP1_TEXTURE_COORD_1, CONTEXT_BOOL(Eval.Map1TextureCoord1), NO_EXTRA },
552 { GL_MAP1_TEXTURE_COORD_2, CONTEXT_BOOL(Eval.Map1TextureCoord2), NO_EXTRA },
553 { GL_MAP1_TEXTURE_COORD_3, CONTEXT_BOOL(Eval.Map1TextureCoord3), NO_EXTRA },
554 { GL_MAP1_TEXTURE_COORD_4, CONTEXT_BOOL(Eval.Map1TextureCoord4), NO_EXTRA },
555 { GL_MAP1_VERTEX_3, CONTEXT_BOOL(Eval.Map1Vertex3), NO_EXTRA },
556 { GL_MAP1_VERTEX_4, CONTEXT_BOOL(Eval.Map1Vertex4), NO_EXTRA },
557 { GL_MAP2_COLOR_4, CONTEXT_BOOL(Eval.Map2Color4), NO_EXTRA },
558 { GL_MAP2_GRID_DOMAIN, LOC_CUSTOM, TYPE_FLOAT_4, 0, NO_EXTRA },
559 { GL_MAP2_GRID_SEGMENTS, CONTEXT_INT2(Eval.MapGrid2un), NO_EXTRA },
560 { GL_MAP2_INDEX, CONTEXT_BOOL(Eval.Map2Index), NO_EXTRA },
561 { GL_MAP2_NORMAL, CONTEXT_BOOL(Eval.Map2Normal), NO_EXTRA },
562 { GL_MAP2_TEXTURE_COORD_1, CONTEXT_BOOL(Eval.Map2TextureCoord1), NO_EXTRA },
563 { GL_MAP2_TEXTURE_COORD_2, CONTEXT_BOOL(Eval.Map2TextureCoord2), NO_EXTRA },
564 { GL_MAP2_TEXTURE_COORD_3, CONTEXT_BOOL(Eval.Map2TextureCoord3), NO_EXTRA },
565 { GL_MAP2_TEXTURE_COORD_4, CONTEXT_BOOL(Eval.Map2TextureCoord4), NO_EXTRA },
566 { GL_MAP2_VERTEX_3, CONTEXT_BOOL(Eval.Map2Vertex3), NO_EXTRA },
567 { GL_MAP2_VERTEX_4, CONTEXT_BOOL(Eval.Map2Vertex4), NO_EXTRA },
568 { GL_MAP_COLOR, CONTEXT_BOOL(Pixel.MapColorFlag), NO_EXTRA },
569 { GL_MAP_STENCIL, CONTEXT_BOOL(Pixel.MapStencilFlag), NO_EXTRA },
570 { GL_MAX_ATTRIB_STACK_DEPTH, CONST(MAX_ATTRIB_STACK_DEPTH), NO_EXTRA },
571 { GL_MAX_CLIENT_ATTRIB_STACK_DEPTH, CONST(MAX_CLIENT_ATTRIB_STACK_DEPTH), NO_EXTRA },
572
573 { GL_MAX_EVAL_ORDER, CONST(MAX_EVAL_ORDER), NO_EXTRA },
574 { GL_MAX_LIST_NESTING, CONST(MAX_LIST_NESTING), NO_EXTRA },
575 { GL_MAX_NAME_STACK_DEPTH, CONST(MAX_NAME_STACK_DEPTH), NO_EXTRA },
576 { GL_MAX_PIXEL_MAP_TABLE, CONST(MAX_PIXEL_MAP_TABLE), NO_EXTRA },
577 { GL_NAME_STACK_DEPTH, CONTEXT_INT(Select.NameStackDepth), NO_EXTRA },
578 { GL_PACK_LSB_FIRST, CONTEXT_BOOL(Pack.LsbFirst), NO_EXTRA },
579 { GL_PACK_ROW_LENGTH, CONTEXT_INT(Pack.RowLength), NO_EXTRA },
580 { GL_PACK_SKIP_PIXELS, CONTEXT_INT(Pack.SkipPixels), NO_EXTRA },
581 { GL_PACK_SKIP_ROWS, CONTEXT_INT(Pack.SkipRows), NO_EXTRA },
582 { GL_PACK_SWAP_BYTES, CONTEXT_BOOL(Pack.SwapBytes), NO_EXTRA },
583 { GL_PACK_IMAGE_HEIGHT_EXT, CONTEXT_INT(Pack.ImageHeight), NO_EXTRA },
584 { GL_PACK_INVERT_MESA, CONTEXT_BOOL(Pack.Invert), NO_EXTRA },
585 { GL_PIXEL_MAP_A_TO_A_SIZE, CONTEXT_INT(PixelMaps.AtoA.Size), NO_EXTRA },
586 { GL_PIXEL_MAP_B_TO_B_SIZE, CONTEXT_INT(PixelMaps.BtoB.Size), NO_EXTRA },
587 { GL_PIXEL_MAP_G_TO_G_SIZE, CONTEXT_INT(PixelMaps.GtoG.Size), NO_EXTRA },
588 { GL_PIXEL_MAP_I_TO_A_SIZE, CONTEXT_INT(PixelMaps.ItoA.Size), NO_EXTRA },
589 { GL_PIXEL_MAP_I_TO_B_SIZE, CONTEXT_INT(PixelMaps.ItoB.Size), NO_EXTRA },
590 { GL_PIXEL_MAP_I_TO_G_SIZE, CONTEXT_INT(PixelMaps.ItoG.Size), NO_EXTRA },
591 { GL_PIXEL_MAP_I_TO_I_SIZE, CONTEXT_INT(PixelMaps.ItoI.Size), NO_EXTRA },
592 { GL_PIXEL_MAP_I_TO_R_SIZE, CONTEXT_INT(PixelMaps.ItoR.Size), NO_EXTRA },
593 { GL_PIXEL_MAP_R_TO_R_SIZE, CONTEXT_INT(PixelMaps.RtoR.Size), NO_EXTRA },
594 { GL_PIXEL_MAP_S_TO_S_SIZE, CONTEXT_INT(PixelMaps.StoS.Size), NO_EXTRA },
595 { GL_POINT_SIZE_GRANULARITY, CONTEXT_FLOAT(Const.PointSizeGranularity), NO_EXTRA },
596 { GL_POLYGON_MODE, CONTEXT_ENUM2(Polygon.FrontMode), NO_EXTRA },
597 { GL_POLYGON_OFFSET_BIAS_EXT, CONTEXT_FLOAT(Polygon.OffsetUnits), NO_EXTRA },
598 { GL_POLYGON_OFFSET_POINT, CONTEXT_BOOL(Polygon.OffsetPoint), NO_EXTRA },
599 { GL_POLYGON_OFFSET_LINE, CONTEXT_BOOL(Polygon.OffsetLine), NO_EXTRA },
600 { GL_POLYGON_SMOOTH, CONTEXT_BOOL(Polygon.SmoothFlag), NO_EXTRA },
601 { GL_POLYGON_SMOOTH_HINT, CONTEXT_ENUM(Hint.PolygonSmooth), NO_EXTRA },
602 { GL_POLYGON_STIPPLE, CONTEXT_BOOL(Polygon.StippleFlag), NO_EXTRA },
603 { GL_READ_BUFFER, LOC_CUSTOM, TYPE_ENUM, NO_OFFSET, NO_EXTRA },
604 { GL_RED_BIAS, CONTEXT_FLOAT(Pixel.RedBias), NO_EXTRA },
605 { GL_RED_SCALE, CONTEXT_FLOAT(Pixel.RedScale), NO_EXTRA },
606 { GL_RENDER_MODE, CONTEXT_ENUM(RenderMode), NO_EXTRA },
607 { GL_RGBA_MODE, CONST(1), NO_EXTRA },
608 { GL_SELECTION_BUFFER_SIZE, CONTEXT_INT(Select.BufferSize), NO_EXTRA },
609
610 { GL_STEREO, BUFFER_INT(Visual.stereoMode), NO_EXTRA },
611
612 { GL_TEXTURE_1D, LOC_CUSTOM, TYPE_BOOLEAN, NO_OFFSET, NO_EXTRA },
613
614 { GL_TEXTURE_BINDING_1D, LOC_CUSTOM, TYPE_INT, TEXTURE_1D_INDEX, NO_EXTRA },
615
616 { GL_TEXTURE_GEN_S, LOC_TEXUNIT, TYPE_BIT_0,
617 offsetof(struct gl_texture_unit, TexGenEnabled), NO_EXTRA },
618 { GL_TEXTURE_GEN_T, LOC_TEXUNIT, TYPE_BIT_1,
619 offsetof(struct gl_texture_unit, TexGenEnabled), NO_EXTRA },
620 { GL_TEXTURE_GEN_R, LOC_TEXUNIT, TYPE_BIT_2,
621 offsetof(struct gl_texture_unit, TexGenEnabled), NO_EXTRA },
622 { GL_TEXTURE_GEN_Q, LOC_TEXUNIT, TYPE_BIT_3,
623 offsetof(struct gl_texture_unit, TexGenEnabled), NO_EXTRA },
624 { GL_UNPACK_LSB_FIRST, CONTEXT_BOOL(Unpack.LsbFirst), NO_EXTRA },
625 { GL_UNPACK_ROW_LENGTH, CONTEXT_INT(Unpack.RowLength), NO_EXTRA },
626 { GL_UNPACK_SKIP_PIXELS, CONTEXT_INT(Unpack.SkipPixels), NO_EXTRA },
627 { GL_UNPACK_SKIP_ROWS, CONTEXT_INT(Unpack.SkipRows), NO_EXTRA },
628 { GL_UNPACK_SWAP_BYTES, CONTEXT_BOOL(Unpack.SwapBytes), NO_EXTRA },
629 { GL_UNPACK_SKIP_IMAGES_EXT, CONTEXT_INT(Unpack.SkipImages), NO_EXTRA },
630 { GL_UNPACK_IMAGE_HEIGHT_EXT, CONTEXT_INT(Unpack.ImageHeight), NO_EXTRA },
631 { GL_ZOOM_X, CONTEXT_FLOAT(Pixel.ZoomX), NO_EXTRA },
632 { GL_ZOOM_Y, CONTEXT_FLOAT(Pixel.ZoomY), NO_EXTRA },
633
634 /* Vertex arrays */
635 { GL_VERTEX_ARRAY_COUNT_EXT, CONST(0), NO_EXTRA },
636 { GL_NORMAL_ARRAY_COUNT_EXT, CONST(0), NO_EXTRA },
637 { GL_COLOR_ARRAY_COUNT_EXT, CONST(0), NO_EXTRA },
638 { GL_INDEX_ARRAY, ARRAY_BOOL(VertexAttrib[VERT_ATTRIB_COLOR_INDEX].Enabled), NO_EXTRA },
639 { GL_INDEX_ARRAY_TYPE, ARRAY_ENUM(VertexAttrib[VERT_ATTRIB_COLOR_INDEX].Type), NO_EXTRA },
640 { GL_INDEX_ARRAY_STRIDE, ARRAY_INT(VertexAttrib[VERT_ATTRIB_COLOR_INDEX].Stride), NO_EXTRA },
641 { GL_INDEX_ARRAY_COUNT_EXT, CONST(0), NO_EXTRA },
642 { GL_TEXTURE_COORD_ARRAY_COUNT_EXT, CONST(0), NO_EXTRA },
643 { GL_EDGE_FLAG_ARRAY, ARRAY_BOOL(VertexAttrib[VERT_ATTRIB_EDGEFLAG].Enabled), NO_EXTRA },
644 { GL_EDGE_FLAG_ARRAY_STRIDE, ARRAY_INT(VertexAttrib[VERT_ATTRIB_EDGEFLAG].Stride), NO_EXTRA },
645 { GL_EDGE_FLAG_ARRAY_COUNT_EXT, CONST(0), NO_EXTRA },
646
647 /* GL_EXT_compiled_vertex_array */
648 { GL_ARRAY_ELEMENT_LOCK_FIRST_EXT, CONTEXT_INT(Array.LockFirst),
649 extra_EXT_compiled_vertex_array },
650 { GL_ARRAY_ELEMENT_LOCK_COUNT_EXT, CONTEXT_INT(Array.LockCount),
651 extra_EXT_compiled_vertex_array },
652
653 /* GL_ARB_transpose_matrix */
654 { GL_TRANSPOSE_MODELVIEW_MATRIX_ARB,
655 CONTEXT_MATRIX_T(ModelviewMatrixStack), NO_EXTRA },
656 { GL_TRANSPOSE_PROJECTION_MATRIX_ARB,
657 CONTEXT_MATRIX_T(ProjectionMatrixStack.Top), NO_EXTRA },
658 { GL_TRANSPOSE_TEXTURE_MATRIX_ARB, CONTEXT_MATRIX_T(TextureMatrixStack), NO_EXTRA },
659
660 /* GL_EXT_fog_coord */
661 { GL_CURRENT_FOG_COORDINATE_EXT,
662 CONTEXT_FLOAT(Current.Attrib[VERT_ATTRIB_FOG][0]),
663 extra_EXT_fog_coord_flush_current },
664 { GL_FOG_COORDINATE_ARRAY_EXT, ARRAY_BOOL(VertexAttrib[VERT_ATTRIB_FOG].Enabled),
665 extra_EXT_fog_coord },
666 { GL_FOG_COORDINATE_ARRAY_TYPE_EXT, ARRAY_ENUM(VertexAttrib[VERT_ATTRIB_FOG].Type),
667 extra_EXT_fog_coord },
668 { GL_FOG_COORDINATE_ARRAY_STRIDE_EXT, ARRAY_INT(VertexAttrib[VERT_ATTRIB_FOG].Stride),
669 extra_EXT_fog_coord },
670 { GL_FOG_COORDINATE_SOURCE_EXT, CONTEXT_ENUM(Fog.FogCoordinateSource),
671 extra_EXT_fog_coord },
672
673 /* GL_NV_fog_distance */
674 { GL_FOG_DISTANCE_MODE_NV, CONTEXT_ENUM(Fog.FogDistanceMode),
675 extra_NV_fog_distance },
676
677 /* GL_IBM_rasterpos_clip */
678 { GL_RASTER_POSITION_UNCLIPPED_IBM,
679 CONTEXT_BOOL(Transform.RasterPositionUnclipped),
680 extra_IBM_rasterpos_clip },
681
682 /* GL_NV_point_sprite */
683 { GL_POINT_SPRITE_R_MODE_NV,
684 CONTEXT_ENUM(Point.SpriteRMode), extra_NV_point_sprite },
685 { GL_POINT_SPRITE_COORD_ORIGIN, CONTEXT_ENUM(Point.SpriteOrigin),
686 extra_NV_point_sprite_ARB_point_sprite },
687
688 /* GL_NV_light_max_exponent */
689 { GL_MAX_SHININESS_NV, CONTEXT_FLOAT(Const.MaxShininess),
690 extra_NV_light_max_exponent },
691 { GL_MAX_SPOT_EXPONENT_NV, CONTEXT_FLOAT(Const.MaxSpotExponent),
692 extra_NV_light_max_exponent },
693
694 /* GL_ARB_vertex_buffer_object */
695 { GL_INDEX_ARRAY_BUFFER_BINDING_ARB, LOC_CUSTOM, TYPE_INT,
696 offsetof(struct gl_array_attrib, VertexAttrib[VERT_ATTRIB_COLOR_INDEX].BufferObj), NO_EXTRA },
697 { GL_EDGE_FLAG_ARRAY_BUFFER_BINDING_ARB, LOC_CUSTOM, TYPE_INT,
698 offsetof(struct gl_array_attrib, VertexAttrib[VERT_ATTRIB_EDGEFLAG].BufferObj), NO_EXTRA },
699 { GL_FOG_COORDINATE_ARRAY_BUFFER_BINDING_ARB, LOC_CUSTOM, TYPE_INT,
700 offsetof(struct gl_array_attrib, VertexAttrib[VERT_ATTRIB_FOG].BufferObj), NO_EXTRA },
701
702 /* GL_EXT_depth_bounds_test */
703 { GL_DEPTH_BOUNDS_TEST_EXT, CONTEXT_BOOL(Depth.BoundsTest),
704 extra_EXT_depth_bounds_test },
705 { GL_DEPTH_BOUNDS_EXT, CONTEXT_FLOAT2(Depth.BoundsMin),
706 extra_EXT_depth_bounds_test },
707
708 /* GL_EXT_texture_integer */
709 { GL_RGBA_INTEGER_MODE_EXT, BUFFER_BOOL(_IntegerColor),
710 extra_EXT_texture_integer },
711
712 /* GL 3.0 */
713 { GL_NUM_EXTENSIONS, LOC_CUSTOM, TYPE_INT, 0, extra_version_30 },
714 { GL_MAJOR_VERSION, CONTEXT_INT(VersionMajor), extra_version_30 },
715 { GL_MINOR_VERSION, CONTEXT_INT(VersionMinor), extra_version_30 },
716 { GL_CONTEXT_FLAGS, CONTEXT_INT(Const.ContextFlags), extra_version_30 },
717
718
719 /* GL 3.2 */
720 { GL_CONTEXT_PROFILE_MASK, CONTEXT_INT(Const.ProfileMask),
721 extra_version_32 },
722 };
723
724 /* All we need now is a way to look up the value struct from the enum.
725 * The code generated by gcc for the old generated big switch
726 * statement is a big, balanced, open coded if/else tree, essentially
727 * an unrolled binary search. It would be natural to sort the new
728 * enum table and use bsearch(), but we will use a read-only hash
729 * table instead. bsearch() has a nice guaranteed worst case
730 * performance, but we're also guaranteed to hit that worst case
731 * (log2(n) iterations) for about half the enums. Instead, using an
732 * open addressing hash table, we can find the enum on the first try
733 * for 80% of the enums, 1 collision for 10% and never more than 5
734 * collisions for any enum (typical numbers). And the code is very
735 * simple, even though it feels a little magic. */
736
737 static unsigned short table[1024];
738 static const int prime_factor = 89, prime_step = 281;
739
740 #ifdef GET_DEBUG
741 static void
742 print_table_stats(void)
743 {
744 int i, j, collisions[11], count, hash, mask;
745 const struct value_desc *d;
746
747 count = 0;
748 mask = Elements(table) - 1;
749 memset(collisions, 0, sizeof collisions);
750
751 for (i = 0; i < Elements(table); i++) {
752 if (!table[i])
753 continue;
754 count++;
755 d = &values[table[i]];
756 hash = (d->pname * prime_factor);
757 j = 0;
758 while (1) {
759 if (values[table[hash & mask]].pname == d->pname)
760 break;
761 hash += prime_step;
762 j++;
763 }
764
765 if (j < 10)
766 collisions[j]++;
767 else
768 collisions[10]++;
769 }
770
771 printf("number of enums: %d (total %d)\n", count, Elements(values));
772 for (i = 0; i < Elements(collisions) - 1; i++)
773 if (collisions[i] > 0)
774 printf(" %d enums with %d %scollisions\n",
775 collisions[i], i, i == 10 ? "or more " : "");
776 }
777 #endif
778
779 /**
780 * Initialize the enum hash for a given API
781 *
782 * This is called from one_time_init() to insert the enum values that
783 * are valid for the API in question into the enum hash table.
784 *
785 * \param the current context, for determining the API in question
786 */
787 void _mesa_init_get_hash(struct gl_context *ctx)
788 {
789 int i, hash, index, mask;
790
791 mask = Elements(table) - 1;
792
793 for (i = 0; i < Elements(values); i++) {
794
795 hash = (values[i].pname * prime_factor) & mask;
796 while (1) {
797 index = hash & mask;
798 if (!table[index]) {
799 table[index] = i;
800 break;
801 }
802 hash += prime_step;
803 }
804 }
805
806 #ifdef GET_DEBUG
807 print_table_stats();
808 #endif
809 }
810
811 /**
812 * Handle irregular enums
813 *
814 * Some values don't conform to the "well-known type at context
815 * pointer + offset" pattern, so we have this function to catch all
816 * the corner cases. Typically, it's a computed value or a one-off
817 * pointer to a custom struct or something.
818 *
819 * In this case we can't return a pointer to the value, so we'll have
820 * to use the temporary variable 'v' declared back in the calling
821 * glGet*v() function to store the result.
822 *
823 * \param ctx the current context
824 * \param d the struct value_desc that describes the enum
825 * \param v pointer to the tmp declared in the calling glGet*v() function
826 */
827 static void
828 find_custom_value(struct gl_context *ctx, const struct value_desc *d, union value *v)
829 {
830 struct gl_buffer_object **buffer_obj;
831 struct gl_client_array *array;
832 GLuint *p;
833
834 switch (d->pname) {
835 case GL_TEXTURE_1D:
836 case GL_TEXTURE_2D:
837 case GL_TEXTURE_CUBE_MAP_ARB:
838 v->value_bool = _mesa_IsEnabled(d->pname);
839 break;
840
841 case GL_LINE_STIPPLE_PATTERN:
842 /* This is the only GLushort, special case it here by promoting
843 * to an int rather than introducing a new type. */
844 v->value_int = ctx->Line.StipplePattern;
845 break;
846
847 case GL_CURRENT_RASTER_TEXTURE_COORDS:
848 v->value_float_4[0] = ctx->Current.RasterTexCoords[0];
849 v->value_float_4[1] = ctx->Current.RasterTexCoords[1];
850 v->value_float_4[2] = ctx->Current.RasterTexCoords[2];
851 v->value_float_4[3] = ctx->Current.RasterTexCoords[3];
852 break;
853
854 case GL_CURRENT_TEXTURE_COORDS:
855 v->value_float_4[0] = ctx->Current.Attrib[VERT_ATTRIB_TEX][0];
856 v->value_float_4[1] = ctx->Current.Attrib[VERT_ATTRIB_TEX][1];
857 v->value_float_4[2] = ctx->Current.Attrib[VERT_ATTRIB_TEX][2];
858 v->value_float_4[3] = ctx->Current.Attrib[VERT_ATTRIB_TEX][3];
859 break;
860
861 case GL_COLOR_WRITEMASK:
862 v->value_int_4[0] = ctx->Color.ColorMask[RCOMP] ? 1 : 0;
863 v->value_int_4[1] = ctx->Color.ColorMask[GCOMP] ? 1 : 0;
864 v->value_int_4[2] = ctx->Color.ColorMask[BCOMP] ? 1 : 0;
865 v->value_int_4[3] = ctx->Color.ColorMask[ACOMP] ? 1 : 0;
866 break;
867
868 case GL_EDGE_FLAG:
869 v->value_bool = ctx->Current.Attrib[VERT_ATTRIB_EDGEFLAG][0] == 1.0;
870 break;
871
872 case GL_READ_BUFFER:
873 v->value_enum = ctx->ReadBuffer->ColorReadBuffer;
874 break;
875
876 case GL_MAP2_GRID_DOMAIN:
877 v->value_float_4[0] = ctx->Eval.MapGrid2u1;
878 v->value_float_4[1] = ctx->Eval.MapGrid2u2;
879 v->value_float_4[2] = ctx->Eval.MapGrid2v1;
880 v->value_float_4[3] = ctx->Eval.MapGrid2v2;
881 break;
882
883 case GL_TEXTURE_STACK_DEPTH:
884 v->value_int = ctx->TextureMatrixStack.Depth + 1;
885 break;
886 case GL_TEXTURE_MATRIX:
887 v->value_matrix = ctx->TextureMatrixStack.Top;
888 break;
889
890 case GL_TEXTURE_COORD_ARRAY:
891 case GL_TEXTURE_COORD_ARRAY_SIZE:
892 case GL_TEXTURE_COORD_ARRAY_TYPE:
893 case GL_TEXTURE_COORD_ARRAY_STRIDE:
894 array = &ctx->Array.VertexAttrib[VERT_ATTRIB_TEX];
895 v->value_int = *(GLuint *) ((char *) array + d->offset);
896 break;
897
898 case GL_MODELVIEW_STACK_DEPTH:
899 case GL_PROJECTION_STACK_DEPTH:
900 v->value_int = *(GLint *) ((char *) ctx + d->offset) + 1;
901 break;
902
903 case GL_MAX_TEXTURE_SIZE:
904 case GL_MAX_3D_TEXTURE_SIZE:
905 case GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB:
906 p = (GLuint *) ((char *) ctx + d->offset);
907 v->value_int = 1 << (*p - 1);
908 break;
909
910 case GL_SCISSOR_BOX:
911 v->value_int_4[0] = ctx->Scissor.X;
912 v->value_int_4[1] = ctx->Scissor.Y;
913 v->value_int_4[2] = ctx->Scissor.Width;
914 v->value_int_4[3] = ctx->Scissor.Height;
915 break;
916
917 case GL_LIST_INDEX:
918 v->value_int =
919 ctx->ListState.CurrentList ? ctx->ListState.CurrentList->Name : 0;
920 break;
921 case GL_LIST_MODE:
922 if (!ctx->CompileFlag)
923 v->value_enum = 0;
924 else if (ctx->ExecuteFlag)
925 v->value_enum = GL_COMPILE_AND_EXECUTE;
926 else
927 v->value_enum = GL_COMPILE;
928 break;
929
930 case GL_VIEWPORT:
931 v->value_int_4[0] = ctx->Viewport.X;
932 v->value_int_4[1] = ctx->Viewport.Y;
933 v->value_int_4[2] = ctx->Viewport.Width;
934 v->value_int_4[3] = ctx->Viewport.Height;
935 break;
936
937 case GL_STENCIL_FAIL:
938 v->value_enum = ctx->Stencil.FailFunc;
939 break;
940 case GL_STENCIL_FUNC:
941 v->value_enum = ctx->Stencil.Function;
942 break;
943 case GL_STENCIL_PASS_DEPTH_FAIL:
944 v->value_enum = ctx->Stencil.ZFailFunc;
945 break;
946 case GL_STENCIL_PASS_DEPTH_PASS:
947 v->value_enum = ctx->Stencil.ZPassFunc;
948 break;
949 case GL_STENCIL_REF:
950 v->value_int = ctx->Stencil.Ref;
951 break;
952 case GL_STENCIL_VALUE_MASK:
953 v->value_int = ctx->Stencil.ValueMask;
954 break;
955 case GL_STENCIL_WRITEMASK:
956 v->value_int = ctx->Stencil.WriteMask;
957 break;
958
959 case GL_NUM_EXTENSIONS:
960 v->value_int = _mesa_get_extension_count(ctx);
961 break;
962
963 case GL_IMPLEMENTATION_COLOR_READ_TYPE_OES:
964 v->value_int = _mesa_get_color_read_type(ctx);
965 break;
966 case GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES:
967 v->value_int = _mesa_get_color_read_format(ctx);
968 break;
969
970 case GL_CURRENT_MATRIX_STACK_DEPTH_ARB:
971 v->value_int = ctx->CurrentStack->Depth + 1;
972 break;
973 case GL_CURRENT_MATRIX_ARB:
974 case GL_TRANSPOSE_CURRENT_MATRIX_ARB:
975 v->value_matrix = ctx->CurrentStack->Top;
976 break;
977
978 /* Various object names */
979
980 case GL_TEXTURE_BINDING_1D:
981 case GL_TEXTURE_BINDING_2D:
982 case GL_TEXTURE_BINDING_3D:
983 case GL_TEXTURE_BINDING_CUBE_MAP_ARB:
984 v->value_int =
985 ctx->Texture.Unit.CurrentTex[d->offset]->Name;
986 break;
987
988 /* GL_ARB_vertex_buffer_object */
989 case GL_VERTEX_ARRAY_BUFFER_BINDING_ARB:
990 case GL_NORMAL_ARRAY_BUFFER_BINDING_ARB:
991 case GL_COLOR_ARRAY_BUFFER_BINDING_ARB:
992 case GL_INDEX_ARRAY_BUFFER_BINDING_ARB:
993 case GL_EDGE_FLAG_ARRAY_BUFFER_BINDING_ARB:
994 case GL_SECONDARY_COLOR_ARRAY_BUFFER_BINDING_ARB:
995 case GL_FOG_COORDINATE_ARRAY_BUFFER_BINDING_ARB:
996 buffer_obj = (struct gl_buffer_object **)
997 ((char *) &ctx->Array + d->offset);
998 v->value_int = (*buffer_obj)->Name;
999 break;
1000 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING_ARB:
1001 v->value_int =
1002 ctx->Array.VertexAttrib[VERT_ATTRIB_TEX].BufferObj->Name;
1003 break;
1004 case GL_ELEMENT_ARRAY_BUFFER_BINDING_ARB:
1005 v->value_int = ctx->Array.ElementArrayBufferObj->Name;
1006 break;
1007
1008 case GL_FOG_COLOR:
1009 COPY_4FV(v->value_float_4, ctx->Fog.Color);
1010 break;
1011 case GL_COLOR_CLEAR_VALUE:
1012 v->value_float_4[0] = ctx->Color.ClearColor.f[0], 0.0F, 1.0F;
1013 v->value_float_4[1] = ctx->Color.ClearColor.f[1], 0.0F, 1.0F;
1014 v->value_float_4[2] = ctx->Color.ClearColor.f[2], 0.0F, 1.0F;
1015 v->value_float_4[3] = ctx->Color.ClearColor.f[3], 0.0F, 1.0F;
1016 break;
1017 case GL_ALPHA_TEST_REF:
1018 v->value_float = ctx->Color.AlphaRef;
1019 break;
1020 }
1021 }
1022
1023 /**
1024 * Check extra constraints on a struct value_desc descriptor
1025 *
1026 * If a struct value_desc has a non-NULL extra pointer, it means that
1027 * there are a number of extra constraints to check or actions to
1028 * perform. The extras is just an integer array where each integer
1029 * encode different constraints or actions.
1030 *
1031 * \param ctx current context
1032 * \param func name of calling glGet*v() function for error reporting
1033 * \param d the struct value_desc that has the extra constraints
1034 *
1035 * \return GL_FALSE if one of the constraints was not satisfied,
1036 * otherwise GL_TRUE.
1037 */
1038 static GLboolean
1039 check_extra(struct gl_context *ctx, const char *func, const struct value_desc *d)
1040 {
1041 const GLuint version = ctx->VersionMajor * 10 + ctx->VersionMinor;
1042 int total, enabled;
1043 const int *e;
1044
1045 total = 0;
1046 enabled = 0;
1047 for (e = d->extra; *e != EXTRA_END; e++)
1048 switch (*e) {
1049 case EXTRA_VERSION_30:
1050 if (version >= 30) {
1051 total++;
1052 enabled++;
1053 }
1054 break;
1055 case EXTRA_VERSION_31:
1056 if (version >= 31) {
1057 total++;
1058 enabled++;
1059 }
1060 break;
1061 case EXTRA_VERSION_32:
1062 if (version >= 32) {
1063 total++;
1064 enabled++;
1065 }
1066 break;
1067 case EXTRA_NEW_BUFFERS:
1068 if (ctx->NewState & _NEW_BUFFERS)
1069 _mesa_update_state(ctx);
1070 break;
1071 case EXTRA_FLUSH_CURRENT:
1072 FLUSH_CURRENT(ctx, 0);
1073 break;
1074 case EXTRA_VALID_CLIP_DISTANCE:
1075 if (d->pname - GL_CLIP_DISTANCE0 >= ctx->Const.MaxClipPlanes) {
1076 _mesa_error(ctx, GL_INVALID_ENUM, "%s(clip distance %u)",
1077 func, d->pname - GL_CLIP_DISTANCE0);
1078 return GL_FALSE;
1079 }
1080 break;
1081 case EXTRA_END:
1082 break;
1083 default: /* *e is a offset into the extension struct */
1084 total++;
1085 if (*(GLboolean *) ((char *) &ctx->Extensions + *e))
1086 enabled++;
1087 break;
1088 }
1089
1090 if (total > 0 && enabled == 0) {
1091 _mesa_error(ctx, GL_INVALID_ENUM, "%s(pname=%s)", func,
1092 _mesa_lookup_enum_by_nr(d->pname));
1093 return GL_FALSE;
1094 }
1095
1096 return GL_TRUE;
1097 }
1098
1099 static const struct value_desc error_value =
1100 { 0, 0, TYPE_INVALID, NO_OFFSET, NO_EXTRA };
1101
1102 /**
1103 * Find the struct value_desc corresponding to the enum 'pname'.
1104 *
1105 * We hash the enum value to get an index into the 'table' array,
1106 * which holds the index in the 'values' array of struct value_desc.
1107 * Once we've found the entry, we do the extra checks, if any, then
1108 * look up the value and return a pointer to it.
1109 *
1110 * If the value has to be computed (for example, it's the result of a
1111 * function call or we need to add 1 to it), we use the tmp 'v' to
1112 * store the result.
1113 *
1114 * \param func name of glGet*v() func for error reporting
1115 * \param pname the enum value we're looking up
1116 * \param p is were we return the pointer to the value
1117 * \param v a tmp union value variable in the calling glGet*v() function
1118 *
1119 * \return the struct value_desc corresponding to the enum or a struct
1120 * value_desc of TYPE_INVALID if not found. This lets the calling
1121 * glGet*v() function jump right into a switch statement and
1122 * handle errors there instead of having to check for NULL.
1123 */
1124 static const struct value_desc *
1125 find_value(const char *func, GLenum pname, void **p, union value *v)
1126 {
1127 GET_CURRENT_CONTEXT(ctx);
1128 struct gl_texture_unit *unit;
1129 int mask, hash;
1130 const struct value_desc *d;
1131
1132 mask = Elements(table) - 1;
1133 hash = (pname * prime_factor);
1134 while (1) {
1135 int idx = table[hash & mask];
1136
1137 /* If the enum isn't valid, the hash walk ends with index 0,
1138 * pointing to the first entry of values[] which doesn't hold
1139 * any valid enum. */
1140 if (unlikely(idx == 0)) {
1141 _mesa_error(ctx, GL_INVALID_ENUM, "%s(pname=%s)", func,
1142 _mesa_lookup_enum_by_nr(pname));
1143 return &error_value;
1144 }
1145
1146 d = &values[idx];
1147 if (likely(d->pname == pname))
1148 break;
1149
1150 hash += prime_step;
1151 }
1152
1153 if (unlikely(d->extra && !check_extra(ctx, func, d)))
1154 return &error_value;
1155
1156 switch (d->location) {
1157 case LOC_BUFFER:
1158 *p = ((char *) ctx->DrawBuffer + d->offset);
1159 return d;
1160 case LOC_CONTEXT:
1161 *p = ((char *) ctx + d->offset);
1162 return d;
1163 case LOC_ARRAY:
1164 *p = ((char *)&ctx->Array + d->offset);
1165 return d;
1166 case LOC_TEXUNIT:
1167 unit = &ctx->Texture.Unit;
1168 *p = ((char *) unit + d->offset);
1169 return d;
1170 case LOC_CUSTOM:
1171 find_custom_value(ctx, d, v);
1172 *p = v;
1173 return d;
1174 default:
1175 assert(0);
1176 break;
1177 }
1178
1179 /* silence warning */
1180 return &error_value;
1181 }
1182
1183 static const int transpose[] = {
1184 0, 4, 8, 12,
1185 1, 5, 9, 13,
1186 2, 6, 10, 14,
1187 3, 7, 11, 15
1188 };
1189
1190 void GLAPIENTRY
1191 _mesa_GetBooleanv(GLenum pname, GLboolean *params)
1192 {
1193 const struct value_desc *d;
1194 union value v;
1195 GLmatrix *m;
1196 int shift, i;
1197 void *p;
1198 GET_CURRENT_CONTEXT(ctx);
1199
1200 ASSERT_OUTSIDE_BEGIN_END(ctx);
1201
1202 d = find_value("glGetBooleanv", pname, &p, &v);
1203 switch (d->type) {
1204 case TYPE_INVALID:
1205 break;
1206 case TYPE_CONST:
1207 params[0] = INT_TO_BOOLEAN(d->offset);
1208 break;
1209
1210 case TYPE_FLOAT_4:
1211 case TYPE_FLOATN_4:
1212 params[3] = FLOAT_TO_BOOLEAN(((GLfloat *) p)[3]);
1213 case TYPE_FLOAT_3:
1214 case TYPE_FLOATN_3:
1215 params[2] = FLOAT_TO_BOOLEAN(((GLfloat *) p)[2]);
1216 case TYPE_FLOAT_2:
1217 case TYPE_FLOATN_2:
1218 params[1] = FLOAT_TO_BOOLEAN(((GLfloat *) p)[1]);
1219 case TYPE_FLOAT:
1220 case TYPE_FLOATN:
1221 params[0] = FLOAT_TO_BOOLEAN(((GLfloat *) p)[0]);
1222 break;
1223
1224 case TYPE_DOUBLEN:
1225 params[0] = FLOAT_TO_BOOLEAN(((GLdouble *) p)[0]);
1226 break;
1227
1228 case TYPE_INT_4:
1229 params[3] = INT_TO_BOOLEAN(((GLint *) p)[3]);
1230 case TYPE_INT_3:
1231 params[2] = INT_TO_BOOLEAN(((GLint *) p)[2]);
1232 case TYPE_INT_2:
1233 case TYPE_ENUM_2:
1234 params[1] = INT_TO_BOOLEAN(((GLint *) p)[1]);
1235 case TYPE_INT:
1236 case TYPE_ENUM:
1237 params[0] = INT_TO_BOOLEAN(((GLint *) p)[0]);
1238 break;
1239
1240 case TYPE_INT_N:
1241 for (i = 0; i < v.value_int_n.n; i++)
1242 params[i] = INT_TO_BOOLEAN(v.value_int_n.ints[i]);
1243 break;
1244
1245 case TYPE_INT64:
1246 params[0] = INT64_TO_BOOLEAN(((GLint64 *) p)[0]);
1247 break;
1248
1249 case TYPE_BOOLEAN:
1250 params[0] = ((GLboolean*) p)[0];
1251 break;
1252
1253 case TYPE_MATRIX:
1254 m = *(GLmatrix **) p;
1255 for (i = 0; i < 16; i++)
1256 params[i] = FLOAT_TO_BOOLEAN(m->m[i]);
1257 break;
1258
1259 case TYPE_MATRIX_T:
1260 m = *(GLmatrix **) p;
1261 for (i = 0; i < 16; i++)
1262 params[i] = FLOAT_TO_BOOLEAN(m->m[transpose[i]]);
1263 break;
1264
1265 case TYPE_BIT_0:
1266 case TYPE_BIT_1:
1267 case TYPE_BIT_2:
1268 case TYPE_BIT_3:
1269 case TYPE_BIT_4:
1270 case TYPE_BIT_5:
1271 case TYPE_BIT_6:
1272 case TYPE_BIT_7:
1273 shift = d->type - TYPE_BIT_0;
1274 params[0] = (*(GLbitfield *) p >> shift) & 1;
1275 break;
1276 }
1277 }
1278
1279 void GLAPIENTRY
1280 _mesa_GetFloatv(GLenum pname, GLfloat *params)
1281 {
1282 const struct value_desc *d;
1283 union value v;
1284 GLmatrix *m;
1285 int shift, i;
1286 void *p;
1287 GET_CURRENT_CONTEXT(ctx);
1288
1289 ASSERT_OUTSIDE_BEGIN_END(ctx);
1290
1291 d = find_value("glGetFloatv", pname, &p, &v);
1292 switch (d->type) {
1293 case TYPE_INVALID:
1294 break;
1295 case TYPE_CONST:
1296 params[0] = (GLfloat) d->offset;
1297 break;
1298
1299 case TYPE_FLOAT_4:
1300 case TYPE_FLOATN_4:
1301 params[3] = ((GLfloat *) p)[3];
1302 case TYPE_FLOAT_3:
1303 case TYPE_FLOATN_3:
1304 params[2] = ((GLfloat *) p)[2];
1305 case TYPE_FLOAT_2:
1306 case TYPE_FLOATN_2:
1307 params[1] = ((GLfloat *) p)[1];
1308 case TYPE_FLOAT:
1309 case TYPE_FLOATN:
1310 params[0] = ((GLfloat *) p)[0];
1311 break;
1312
1313 case TYPE_DOUBLEN:
1314 params[0] = ((GLdouble *) p)[0];
1315 break;
1316
1317 case TYPE_INT_4:
1318 params[3] = (GLfloat) (((GLint *) p)[3]);
1319 case TYPE_INT_3:
1320 params[2] = (GLfloat) (((GLint *) p)[2]);
1321 case TYPE_INT_2:
1322 case TYPE_ENUM_2:
1323 params[1] = (GLfloat) (((GLint *) p)[1]);
1324 case TYPE_INT:
1325 case TYPE_ENUM:
1326 params[0] = (GLfloat) (((GLint *) p)[0]);
1327 break;
1328
1329 case TYPE_INT_N:
1330 for (i = 0; i < v.value_int_n.n; i++)
1331 params[i] = INT_TO_FLOAT(v.value_int_n.ints[i]);
1332 break;
1333
1334 case TYPE_INT64:
1335 params[0] = ((GLint64 *) p)[0];
1336 break;
1337
1338 case TYPE_BOOLEAN:
1339 params[0] = BOOLEAN_TO_FLOAT(*(GLboolean*) p);
1340 break;
1341
1342 case TYPE_MATRIX:
1343 m = *(GLmatrix **) p;
1344 for (i = 0; i < 16; i++)
1345 params[i] = m->m[i];
1346 break;
1347
1348 case TYPE_MATRIX_T:
1349 m = *(GLmatrix **) p;
1350 for (i = 0; i < 16; i++)
1351 params[i] = m->m[transpose[i]];
1352 break;
1353
1354 case TYPE_BIT_0:
1355 case TYPE_BIT_1:
1356 case TYPE_BIT_2:
1357 case TYPE_BIT_3:
1358 case TYPE_BIT_4:
1359 case TYPE_BIT_5:
1360 case TYPE_BIT_6:
1361 case TYPE_BIT_7:
1362 shift = d->type - TYPE_BIT_0;
1363 params[0] = BOOLEAN_TO_FLOAT((*(GLbitfield *) p >> shift) & 1);
1364 break;
1365 }
1366 }
1367
1368 void GLAPIENTRY
1369 _mesa_GetIntegerv(GLenum pname, GLint *params)
1370 {
1371 const struct value_desc *d;
1372 union value v;
1373 GLmatrix *m;
1374 int shift, i;
1375 void *p;
1376 GET_CURRENT_CONTEXT(ctx);
1377
1378 ASSERT_OUTSIDE_BEGIN_END(ctx);
1379
1380 d = find_value("glGetIntegerv", pname, &p, &v);
1381 switch (d->type) {
1382 case TYPE_INVALID:
1383 break;
1384 case TYPE_CONST:
1385 params[0] = d->offset;
1386 break;
1387
1388 case TYPE_FLOAT_4:
1389 params[3] = IROUND(((GLfloat *) p)[3]);
1390 case TYPE_FLOAT_3:
1391 params[2] = IROUND(((GLfloat *) p)[2]);
1392 case TYPE_FLOAT_2:
1393 params[1] = IROUND(((GLfloat *) p)[1]);
1394 case TYPE_FLOAT:
1395 params[0] = IROUND(((GLfloat *) p)[0]);
1396 break;
1397
1398 case TYPE_FLOATN_4:
1399 params[3] = FLOAT_TO_INT(((GLfloat *) p)[3]);
1400 case TYPE_FLOATN_3:
1401 params[2] = FLOAT_TO_INT(((GLfloat *) p)[2]);
1402 case TYPE_FLOATN_2:
1403 params[1] = FLOAT_TO_INT(((GLfloat *) p)[1]);
1404 case TYPE_FLOATN:
1405 params[0] = FLOAT_TO_INT(((GLfloat *) p)[0]);
1406 break;
1407
1408 case TYPE_DOUBLEN:
1409 params[0] = FLOAT_TO_INT(((GLdouble *) p)[0]);
1410 break;
1411
1412 case TYPE_INT_4:
1413 params[3] = ((GLint *) p)[3];
1414 case TYPE_INT_3:
1415 params[2] = ((GLint *) p)[2];
1416 case TYPE_INT_2:
1417 case TYPE_ENUM_2:
1418 params[1] = ((GLint *) p)[1];
1419 case TYPE_INT:
1420 case TYPE_ENUM:
1421 params[0] = ((GLint *) p)[0];
1422 break;
1423
1424 case TYPE_INT_N:
1425 for (i = 0; i < v.value_int_n.n; i++)
1426 params[i] = v.value_int_n.ints[i];
1427 break;
1428
1429 case TYPE_INT64:
1430 params[0] = INT64_TO_INT(((GLint64 *) p)[0]);
1431 break;
1432
1433 case TYPE_BOOLEAN:
1434 params[0] = BOOLEAN_TO_INT(*(GLboolean*) p);
1435 break;
1436
1437 case TYPE_MATRIX:
1438 m = *(GLmatrix **) p;
1439 for (i = 0; i < 16; i++)
1440 params[i] = FLOAT_TO_INT(m->m[i]);
1441 break;
1442
1443 case TYPE_MATRIX_T:
1444 m = *(GLmatrix **) p;
1445 for (i = 0; i < 16; i++)
1446 params[i] = FLOAT_TO_INT(m->m[transpose[i]]);
1447 break;
1448
1449 case TYPE_BIT_0:
1450 case TYPE_BIT_1:
1451 case TYPE_BIT_2:
1452 case TYPE_BIT_3:
1453 case TYPE_BIT_4:
1454 case TYPE_BIT_5:
1455 case TYPE_BIT_6:
1456 case TYPE_BIT_7:
1457 shift = d->type - TYPE_BIT_0;
1458 params[0] = (*(GLbitfield *) p >> shift) & 1;
1459 break;
1460 }
1461 }
1462
1463
1464 void GLAPIENTRY
1465 _mesa_GetDoublev(GLenum pname, GLdouble *params)
1466 {
1467 const struct value_desc *d;
1468 union value v;
1469 GLmatrix *m;
1470 int shift, i;
1471 void *p;
1472 GET_CURRENT_CONTEXT(ctx);
1473
1474 ASSERT_OUTSIDE_BEGIN_END(ctx);
1475
1476 d = find_value("glGetDoublev", pname, &p, &v);
1477 switch (d->type) {
1478 case TYPE_INVALID:
1479 break;
1480 case TYPE_CONST:
1481 params[0] = d->offset;
1482 break;
1483
1484 case TYPE_FLOAT_4:
1485 case TYPE_FLOATN_4:
1486 params[3] = ((GLfloat *) p)[3];
1487 case TYPE_FLOAT_3:
1488 case TYPE_FLOATN_3:
1489 params[2] = ((GLfloat *) p)[2];
1490 case TYPE_FLOAT_2:
1491 case TYPE_FLOATN_2:
1492 params[1] = ((GLfloat *) p)[1];
1493 case TYPE_FLOAT:
1494 case TYPE_FLOATN:
1495 params[0] = ((GLfloat *) p)[0];
1496 break;
1497
1498 case TYPE_DOUBLEN:
1499 params[0] = ((GLdouble *) p)[0];
1500 break;
1501
1502 case TYPE_INT_4:
1503 params[3] = ((GLint *) p)[3];
1504 case TYPE_INT_3:
1505 params[2] = ((GLint *) p)[2];
1506 case TYPE_INT_2:
1507 case TYPE_ENUM_2:
1508 params[1] = ((GLint *) p)[1];
1509 case TYPE_INT:
1510 case TYPE_ENUM:
1511 params[0] = ((GLint *) p)[0];
1512 break;
1513
1514 case TYPE_INT_N:
1515 for (i = 0; i < v.value_int_n.n; i++)
1516 params[i] = v.value_int_n.ints[i];
1517 break;
1518
1519 case TYPE_INT64:
1520 params[0] = ((GLint64 *) p)[0];
1521 break;
1522
1523 case TYPE_BOOLEAN:
1524 params[0] = *(GLboolean*) p;
1525 break;
1526
1527 case TYPE_MATRIX:
1528 m = *(GLmatrix **) p;
1529 for (i = 0; i < 16; i++)
1530 params[i] = m->m[i];
1531 break;
1532
1533 case TYPE_MATRIX_T:
1534 m = *(GLmatrix **) p;
1535 for (i = 0; i < 16; i++)
1536 params[i] = m->m[transpose[i]];
1537 break;
1538
1539 case TYPE_BIT_0:
1540 case TYPE_BIT_1:
1541 case TYPE_BIT_2:
1542 case TYPE_BIT_3:
1543 case TYPE_BIT_4:
1544 case TYPE_BIT_5:
1545 case TYPE_BIT_6:
1546 case TYPE_BIT_7:
1547 shift = d->type - TYPE_BIT_0;
1548 params[0] = (*(GLbitfield *) p >> shift) & 1;
1549 break;
1550 }
1551 }
1552
1553 #if FEATURE_ES1
1554 void GLAPIENTRY
1555 _mesa_GetFixedv(GLenum pname, GLfixed *params)
1556 {
1557 const struct value_desc *d;
1558 union value v;
1559 GLmatrix *m;
1560 int shift, i;
1561 void *p;
1562
1563 d = find_value("glGetDoublev", pname, &p, &v);
1564 switch (d->type) {
1565 case TYPE_INVALID:
1566 break;
1567 case TYPE_CONST:
1568 params[0] = INT_TO_FIXED(d->offset);
1569 break;
1570
1571 case TYPE_FLOAT_4:
1572 case TYPE_FLOATN_4:
1573 params[3] = FLOAT_TO_FIXED(((GLfloat *) p)[3]);
1574 case TYPE_FLOAT_3:
1575 case TYPE_FLOATN_3:
1576 params[2] = FLOAT_TO_FIXED(((GLfloat *) p)[2]);
1577 case TYPE_FLOAT_2:
1578 case TYPE_FLOATN_2:
1579 params[1] = FLOAT_TO_FIXED(((GLfloat *) p)[1]);
1580 case TYPE_FLOAT:
1581 case TYPE_FLOATN:
1582 params[0] = FLOAT_TO_FIXED(((GLfloat *) p)[0]);
1583 break;
1584
1585 case TYPE_DOUBLEN:
1586 params[0] = FLOAT_TO_FIXED(((GLdouble *) p)[0]);
1587 break;
1588
1589 case TYPE_INT_4:
1590 params[3] = INT_TO_FIXED(((GLint *) p)[3]);
1591 case TYPE_INT_3:
1592 params[2] = INT_TO_FIXED(((GLint *) p)[2]);
1593 case TYPE_INT_2:
1594 case TYPE_ENUM_2:
1595 params[1] = INT_TO_FIXED(((GLint *) p)[1]);
1596 case TYPE_INT:
1597 case TYPE_ENUM:
1598 params[0] = INT_TO_FIXED(((GLint *) p)[0]);
1599 break;
1600
1601 case TYPE_INT_N:
1602 for (i = 0; i < v.value_int_n.n; i++)
1603 params[i] = INT_TO_FIXED(v.value_int_n.ints[i]);
1604 break;
1605
1606 case TYPE_INT64:
1607 params[0] = ((GLint64 *) p)[0];
1608 break;
1609
1610 case TYPE_BOOLEAN:
1611 params[0] = BOOLEAN_TO_FIXED(((GLboolean*) p)[0]);
1612 break;
1613
1614 case TYPE_MATRIX:
1615 m = *(GLmatrix **) p;
1616 for (i = 0; i < 16; i++)
1617 params[i] = FLOAT_TO_FIXED(m->m[i]);
1618 break;
1619
1620 case TYPE_MATRIX_T:
1621 m = *(GLmatrix **) p;
1622 for (i = 0; i < 16; i++)
1623 params[i] = FLOAT_TO_FIXED(m->m[transpose[i]]);
1624 break;
1625
1626 case TYPE_BIT_0:
1627 case TYPE_BIT_1:
1628 case TYPE_BIT_2:
1629 case TYPE_BIT_3:
1630 case TYPE_BIT_4:
1631 case TYPE_BIT_5:
1632 case TYPE_BIT_6:
1633 case TYPE_BIT_7:
1634 shift = d->type - TYPE_BIT_0;
1635 params[0] = BOOLEAN_TO_FIXED((*(GLbitfield *) p >> shift) & 1);
1636 break;
1637 }
1638 }
1639 #endif