mesa: remove NV_light_max_exponent extension enable flag
[mesa.git] / src / 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 "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 #define FLOAT_TO_BOOLEAN(X) ( (X) ? GL_TRUE : GL_FALSE )
65 #define FLOAT_TO_FIXED(F) ( ((F) * 65536.0f > INT_MAX) ? INT_MAX : \
66 ((F) * 65536.0f < INT_MIN) ? INT_MIN : \
67 (GLint) ((F) * 65536.0f) )
68
69 #define INT_TO_BOOLEAN(I) ( (I) ? GL_TRUE : GL_FALSE )
70 #define INT_TO_FIXED(I) ( ((I) > SHRT_MAX) ? INT_MAX : \
71 ((I) < SHRT_MIN) ? INT_MIN : \
72 (GLint) ((I) * 65536) )
73
74 #define INT64_TO_BOOLEAN(I) ( (I) ? GL_TRUE : GL_FALSE )
75 #define INT64_TO_INT(I) ( (GLint)((I > INT_MAX) ? INT_MAX : ((I < INT_MIN) ? INT_MIN : (I))) )
76
77 #define BOOLEAN_TO_INT(B) ( (GLint) (B) )
78 #define BOOLEAN_TO_INT64(B) ( (GLint64) (B) )
79 #define BOOLEAN_TO_FLOAT(B) ( (B) ? 1.0F : 0.0F )
80 #define BOOLEAN_TO_FIXED(B) ( (GLint) ((B) ? 1 : 0) << 16 )
81
82 #define ENUM_TO_INT64(E) ( (GLint64) (E) )
83 #define ENUM_TO_FIXED(E) (E)
84
85 enum value_type {
86 TYPE_INVALID,
87 TYPE_INT,
88 TYPE_INT_2,
89 TYPE_INT_3,
90 TYPE_INT_4,
91 TYPE_INT_N,
92 TYPE_INT64,
93 TYPE_ENUM,
94 TYPE_ENUM_2,
95 TYPE_BOOLEAN,
96 TYPE_BIT_0,
97 TYPE_BIT_1,
98 TYPE_BIT_2,
99 TYPE_BIT_3,
100 TYPE_BIT_4,
101 TYPE_BIT_5,
102 TYPE_BIT_6,
103 TYPE_BIT_7,
104 TYPE_FLOAT,
105 TYPE_FLOAT_2,
106 TYPE_FLOAT_3,
107 TYPE_FLOAT_4,
108 TYPE_FLOATN,
109 TYPE_FLOATN_2,
110 TYPE_FLOATN_3,
111 TYPE_FLOATN_4,
112 TYPE_DOUBLEN,
113 TYPE_MATRIX,
114 TYPE_MATRIX_T,
115 TYPE_CONST
116 };
117
118 enum value_location {
119 LOC_BUFFER,
120 LOC_CONTEXT,
121 LOC_ARRAY,
122 LOC_TEXUNIT,
123 LOC_CUSTOM
124 };
125
126 enum value_extra {
127 EXTRA_END = 0x8000,
128 EXTRA_VERSION_30,
129 EXTRA_VERSION_31,
130 EXTRA_VERSION_32,
131 EXTRA_API_GL,
132 EXTRA_API_ES2,
133 EXTRA_NEW_BUFFERS,
134 EXTRA_NEW_FRAG_CLAMP,
135 EXTRA_VALID_DRAW_BUFFER,
136 EXTRA_VALID_TEXTURE_UNIT,
137 EXTRA_VALID_CLIP_DISTANCE,
138 EXTRA_FLUSH_CURRENT,
139 EXTRA_GLSL_130,
140 };
141
142 #define NO_EXTRA NULL
143 #define NO_OFFSET 0
144
145 struct value_desc {
146 GLenum pname;
147 GLubyte location; /**< enum value_location */
148 GLubyte type; /**< enum value_type */
149 int offset;
150 const int *extra;
151 };
152
153 union value {
154 GLfloat value_float;
155 GLfloat value_float_4[4];
156 GLmatrix *value_matrix;
157 GLint value_int;
158 GLint value_int_4[4];
159 GLint64 value_int64;
160 GLenum value_enum;
161
162 /* Sigh, see GL_COMPRESSED_TEXTURE_FORMATS_ARB handling */
163 struct {
164 GLint n, ints[100];
165 } value_int_n;
166 GLboolean value_bool;
167 };
168
169 #define BUFFER_FIELD(field, type) \
170 LOC_BUFFER, type, offsetof(struct gl_framebuffer, field)
171 #define CONTEXT_FIELD(field, type) \
172 LOC_CONTEXT, type, offsetof(struct gl_context, field)
173 #define ARRAY_FIELD(field, type) \
174 LOC_ARRAY, type, offsetof(struct gl_array_object, field)
175 #undef CONST /* already defined through windows.h */
176 #define CONST(value) \
177 LOC_CONTEXT, TYPE_CONST, value
178
179 #define BUFFER_INT(field) BUFFER_FIELD(field, TYPE_INT)
180 #define BUFFER_ENUM(field) BUFFER_FIELD(field, TYPE_ENUM)
181 #define BUFFER_BOOL(field) BUFFER_FIELD(field, TYPE_BOOLEAN)
182
183 #define CONTEXT_INT(field) CONTEXT_FIELD(field, TYPE_INT)
184 #define CONTEXT_INT2(field) CONTEXT_FIELD(field, TYPE_INT_2)
185 #define CONTEXT_INT64(field) CONTEXT_FIELD(field, TYPE_INT64)
186 #define CONTEXT_ENUM(field) CONTEXT_FIELD(field, TYPE_ENUM)
187 #define CONTEXT_ENUM2(field) CONTEXT_FIELD(field, TYPE_ENUM_2)
188 #define CONTEXT_BOOL(field) CONTEXT_FIELD(field, TYPE_BOOLEAN)
189 #define CONTEXT_BIT0(field) CONTEXT_FIELD(field, TYPE_BIT_0)
190 #define CONTEXT_BIT1(field) CONTEXT_FIELD(field, TYPE_BIT_1)
191 #define CONTEXT_BIT2(field) CONTEXT_FIELD(field, TYPE_BIT_2)
192 #define CONTEXT_BIT3(field) CONTEXT_FIELD(field, TYPE_BIT_3)
193 #define CONTEXT_BIT4(field) CONTEXT_FIELD(field, TYPE_BIT_4)
194 #define CONTEXT_BIT5(field) CONTEXT_FIELD(field, TYPE_BIT_5)
195 #define CONTEXT_BIT6(field) CONTEXT_FIELD(field, TYPE_BIT_6)
196 #define CONTEXT_BIT7(field) CONTEXT_FIELD(field, TYPE_BIT_7)
197 #define CONTEXT_FLOAT(field) CONTEXT_FIELD(field, TYPE_FLOAT)
198 #define CONTEXT_FLOAT2(field) CONTEXT_FIELD(field, TYPE_FLOAT_2)
199 #define CONTEXT_FLOAT3(field) CONTEXT_FIELD(field, TYPE_FLOAT_3)
200 #define CONTEXT_FLOAT4(field) CONTEXT_FIELD(field, TYPE_FLOAT_4)
201 #define CONTEXT_MATRIX(field) CONTEXT_FIELD(field, TYPE_MATRIX)
202 #define CONTEXT_MATRIX_T(field) CONTEXT_FIELD(field, TYPE_MATRIX_T)
203
204 #define ARRAY_INT(field) ARRAY_FIELD(field, TYPE_INT)
205 #define ARRAY_ENUM(field) ARRAY_FIELD(field, TYPE_ENUM)
206 #define ARRAY_BOOL(field) ARRAY_FIELD(field, TYPE_BOOLEAN)
207
208 #define EXT(f) \
209 offsetof(struct gl_extensions, f)
210
211 #define EXTRA_EXT(e) \
212 static const int extra_##e[] = { \
213 EXT(e), EXTRA_END \
214 }
215
216 #define EXTRA_EXT2(e1, e2) \
217 static const int extra_##e1##_##e2[] = { \
218 EXT(e1), EXT(e2), EXTRA_END \
219 }
220
221 /* The 'extra' mechanism is a way to specify extra checks (such as
222 * extensions or specific gl versions) or actions (flush current, new
223 * buffers) that we need to do before looking up an enum. We need to
224 * declare them all up front so we can refer to them in the value_desc
225 * structs below. */
226
227 static const int extra_new_buffers[] = {
228 EXTRA_NEW_BUFFERS,
229 EXTRA_END
230 };
231
232 static const int extra_new_frag_clamp[] = {
233 EXTRA_NEW_FRAG_CLAMP,
234 EXTRA_END
235 };
236
237 static const int extra_valid_draw_buffer[] = {
238 EXTRA_VALID_DRAW_BUFFER,
239 EXTRA_END
240 };
241
242 static const int extra_valid_texture_unit[] = {
243 EXTRA_VALID_TEXTURE_UNIT,
244 EXTRA_END
245 };
246
247 static const int extra_valid_clip_distance[] = {
248 EXTRA_VALID_CLIP_DISTANCE,
249 EXTRA_END
250 };
251
252 static const int extra_flush_current_valid_texture_unit[] = {
253 EXTRA_FLUSH_CURRENT,
254 EXTRA_VALID_TEXTURE_UNIT,
255 EXTRA_END
256 };
257
258 static const int extra_flush_current[] = {
259 EXTRA_FLUSH_CURRENT,
260 EXTRA_END
261 };
262
263 static const int extra_EXT_secondary_color_flush_current[] = {
264 EXT(EXT_secondary_color),
265 EXTRA_FLUSH_CURRENT,
266 EXTRA_END
267 };
268
269 static const int extra_EXT_fog_coord_flush_current[] = {
270 EXT(EXT_fog_coord),
271 EXTRA_FLUSH_CURRENT,
272 EXTRA_END
273 };
274
275 static const int extra_EXT_texture_integer[] = {
276 EXT(EXT_texture_integer),
277 EXTRA_END
278 };
279
280 static const int extra_GLSL_130[] = {
281 EXTRA_GLSL_130,
282 EXTRA_END
283 };
284
285 static const int extra_texture_buffer_object[] = {
286 EXTRA_VERSION_31,
287 EXT(ARB_texture_buffer_object),
288 EXTRA_END
289 };
290
291 static const int extra_ARB_uniform_buffer_object_and_geometry_shader[] = {
292 EXT(ARB_uniform_buffer_object),
293 EXT(ARB_geometry_shader4),
294 EXTRA_END
295 };
296
297
298 EXTRA_EXT(ARB_ES2_compatibility);
299 EXTRA_EXT(ARB_texture_cube_map);
300 EXTRA_EXT(MESA_texture_array);
301 EXTRA_EXT2(EXT_secondary_color, ARB_vertex_program);
302 EXTRA_EXT(EXT_secondary_color);
303 EXTRA_EXT(EXT_fog_coord);
304 EXTRA_EXT(NV_fog_distance);
305 EXTRA_EXT(EXT_texture_filter_anisotropic);
306 EXTRA_EXT(NV_point_sprite);
307 EXTRA_EXT(NV_texture_rectangle);
308 EXTRA_EXT(EXT_stencil_two_side);
309 EXTRA_EXT(EXT_depth_bounds_test);
310 EXTRA_EXT(ARB_depth_clamp);
311 EXTRA_EXT(ATI_fragment_shader);
312 EXTRA_EXT(EXT_framebuffer_blit);
313 EXTRA_EXT(ARB_shader_objects);
314 EXTRA_EXT(EXT_provoking_vertex);
315 EXTRA_EXT(ARB_fragment_shader);
316 EXTRA_EXT(ARB_fragment_program);
317 EXTRA_EXT2(ARB_framebuffer_object, EXT_framebuffer_multisample);
318 EXTRA_EXT(EXT_framebuffer_object);
319 EXTRA_EXT(ARB_seamless_cube_map);
320 EXTRA_EXT(ARB_sync);
321 EXTRA_EXT(ARB_vertex_shader);
322 EXTRA_EXT(EXT_transform_feedback);
323 EXTRA_EXT(ARB_transform_feedback2);
324 EXTRA_EXT(ARB_transform_feedback3);
325 EXTRA_EXT(EXT_pixel_buffer_object);
326 EXTRA_EXT(ARB_vertex_program);
327 EXTRA_EXT2(NV_point_sprite, ARB_point_sprite);
328 EXTRA_EXT2(ARB_vertex_program, ARB_fragment_program);
329 EXTRA_EXT(ARB_geometry_shader4);
330 EXTRA_EXT(ARB_color_buffer_float);
331 EXTRA_EXT(EXT_framebuffer_sRGB);
332 EXTRA_EXT(ARB_texture_buffer_object);
333 EXTRA_EXT(OES_EGL_image_external);
334 EXTRA_EXT(ARB_blend_func_extended);
335 EXTRA_EXT(ARB_uniform_buffer_object);
336 EXTRA_EXT(ARB_timer_query);
337 EXTRA_EXT(ARB_map_buffer_alignment);
338
339 static const int
340 extra_NV_primitive_restart[] = {
341 EXT(NV_primitive_restart),
342 EXTRA_END
343 };
344
345 static const int extra_version_30[] = { EXTRA_VERSION_30, EXTRA_END };
346 static const int extra_version_31[] = { EXTRA_VERSION_31, EXTRA_END };
347 static const int extra_version_32[] = { EXTRA_VERSION_32, EXTRA_END };
348
349 static const int
350 extra_ARB_vertex_program_api_es2[] = {
351 EXT(ARB_vertex_program),
352 EXTRA_API_ES2,
353 EXTRA_END
354 };
355
356 /* The ReadBuffer get token is valid under either full GL or under
357 * GLES2 if the NV_read_buffer extension is available. */
358 static const int
359 extra_NV_read_buffer_api_gl[] = {
360 EXT(NV_read_buffer),
361 EXTRA_API_GL,
362 EXTRA_END
363 };
364
365 /* This is the big table describing all the enums we accept in
366 * glGet*v(). The table is partitioned into six parts: enums
367 * understood by all GL APIs (OpenGL, GLES and GLES2), enums shared
368 * between OpenGL and GLES, enums exclusive to GLES, etc for the
369 * remaining combinations. To look up the enums valid in a given API
370 * we will use a hash table specific to that API. These tables are in
371 * turn generated at build time and included through get_hash.h.
372 * The different sections are guarded by #if FEATURE_GL etc to make
373 * sure we only compile in the enums we may need. */
374
375 #include "get_hash.h"
376
377 /* All we need now is a way to look up the value struct from the enum.
378 * The code generated by gcc for the old generated big switch
379 * statement is a big, balanced, open coded if/else tree, essentially
380 * an unrolled binary search. It would be natural to sort the new
381 * enum table and use bsearch(), but we will use a read-only hash
382 * table instead. bsearch() has a nice guaranteed worst case
383 * performance, but we're also guaranteed to hit that worst case
384 * (log2(n) iterations) for about half the enums. Instead, using an
385 * open addressing hash table, we can find the enum on the first try
386 * for 80% of the enums, 1 collision for 10% and never more than 5
387 * collisions for any enum (typical numbers). And the code is very
388 * simple, even though it feels a little magic. */
389
390 #ifdef GET_DEBUG
391 static void
392 print_table_stats(int api)
393 {
394 int i, j, collisions[11], count, hash, mask;
395 const struct value_desc *d;
396 const char *api_names[] = {
397 [API_OPENGL] = "GL",
398 [API_OPENGL_CORE] = "GL_CORE",
399 [API_OPENGLES] = "GLES",
400 [API_OPENGLES2] = "GLES2",
401 };
402 const char *api_name;
403
404 api_name = api < Elements(api_names) ? api_names[api] : "N/A";
405 count = 0;
406 mask = Elements(table(api)) - 1;
407 memset(collisions, 0, sizeof collisions);
408
409 for (i = 0; i < Elements(table(api)); i++) {
410 if (!table(api)[i])
411 continue;
412 count++;
413 d = &values[table(api)[i]];
414 hash = (d->pname * prime_factor);
415 j = 0;
416 while (1) {
417 if (values[table(api)[hash & mask]].pname == d->pname)
418 break;
419 hash += prime_step;
420 j++;
421 }
422
423 if (j < 10)
424 collisions[j]++;
425 else
426 collisions[10]++;
427 }
428
429 printf("number of enums for %s: %d (total %ld)\n",
430 api_name, count, Elements(values));
431 for (i = 0; i < Elements(collisions) - 1; i++)
432 if (collisions[i] > 0)
433 printf(" %d enums with %d %scollisions\n",
434 collisions[i], i, i == 10 ? "or more " : "");
435 }
436 #endif
437
438 /**
439 * Initialize the enum hash for a given API
440 *
441 * This is called from one_time_init() to insert the enum values that
442 * are valid for the API in question into the enum hash table.
443 *
444 * \param the current context, for determining the API in question
445 */
446 void _mesa_init_get_hash(struct gl_context *ctx)
447 {
448 #ifdef GET_DEBUG
449 print_table_stats();
450 #endif
451 }
452
453 /**
454 * Handle irregular enums
455 *
456 * Some values don't conform to the "well-known type at context
457 * pointer + offset" pattern, so we have this function to catch all
458 * the corner cases. Typically, it's a computed value or a one-off
459 * pointer to a custom struct or something.
460 *
461 * In this case we can't return a pointer to the value, so we'll have
462 * to use the temporary variable 'v' declared back in the calling
463 * glGet*v() function to store the result.
464 *
465 * \param ctx the current context
466 * \param d the struct value_desc that describes the enum
467 * \param v pointer to the tmp declared in the calling glGet*v() function
468 */
469 static void
470 find_custom_value(struct gl_context *ctx, const struct value_desc *d, union value *v)
471 {
472 struct gl_buffer_object **buffer_obj;
473 struct gl_client_array *array;
474 GLuint unit, *p;
475
476 switch (d->pname) {
477 case GL_MAJOR_VERSION:
478 v->value_int = ctx->Version / 10;
479 break;
480 case GL_MINOR_VERSION:
481 v->value_int = ctx->Version % 10;
482 break;
483
484 case GL_TEXTURE_1D:
485 case GL_TEXTURE_2D:
486 case GL_TEXTURE_3D:
487 case GL_TEXTURE_1D_ARRAY_EXT:
488 case GL_TEXTURE_2D_ARRAY_EXT:
489 case GL_TEXTURE_CUBE_MAP_ARB:
490 case GL_TEXTURE_RECTANGLE_NV:
491 case GL_TEXTURE_EXTERNAL_OES:
492 v->value_bool = _mesa_IsEnabled(d->pname);
493 break;
494
495 case GL_LINE_STIPPLE_PATTERN:
496 /* This is the only GLushort, special case it here by promoting
497 * to an int rather than introducing a new type. */
498 v->value_int = ctx->Line.StipplePattern;
499 break;
500
501 case GL_CURRENT_RASTER_TEXTURE_COORDS:
502 unit = ctx->Texture.CurrentUnit;
503 v->value_float_4[0] = ctx->Current.RasterTexCoords[unit][0];
504 v->value_float_4[1] = ctx->Current.RasterTexCoords[unit][1];
505 v->value_float_4[2] = ctx->Current.RasterTexCoords[unit][2];
506 v->value_float_4[3] = ctx->Current.RasterTexCoords[unit][3];
507 break;
508
509 case GL_CURRENT_TEXTURE_COORDS:
510 unit = ctx->Texture.CurrentUnit;
511 v->value_float_4[0] = ctx->Current.Attrib[VERT_ATTRIB_TEX0 + unit][0];
512 v->value_float_4[1] = ctx->Current.Attrib[VERT_ATTRIB_TEX0 + unit][1];
513 v->value_float_4[2] = ctx->Current.Attrib[VERT_ATTRIB_TEX0 + unit][2];
514 v->value_float_4[3] = ctx->Current.Attrib[VERT_ATTRIB_TEX0 + unit][3];
515 break;
516
517 case GL_COLOR_WRITEMASK:
518 v->value_int_4[0] = ctx->Color.ColorMask[0][RCOMP] ? 1 : 0;
519 v->value_int_4[1] = ctx->Color.ColorMask[0][GCOMP] ? 1 : 0;
520 v->value_int_4[2] = ctx->Color.ColorMask[0][BCOMP] ? 1 : 0;
521 v->value_int_4[3] = ctx->Color.ColorMask[0][ACOMP] ? 1 : 0;
522 break;
523
524 case GL_EDGE_FLAG:
525 v->value_bool = ctx->Current.Attrib[VERT_ATTRIB_EDGEFLAG][0] == 1.0;
526 break;
527
528 case GL_READ_BUFFER:
529 v->value_enum = ctx->ReadBuffer->ColorReadBuffer;
530 break;
531
532 case GL_MAP2_GRID_DOMAIN:
533 v->value_float_4[0] = ctx->Eval.MapGrid2u1;
534 v->value_float_4[1] = ctx->Eval.MapGrid2u2;
535 v->value_float_4[2] = ctx->Eval.MapGrid2v1;
536 v->value_float_4[3] = ctx->Eval.MapGrid2v2;
537 break;
538
539 case GL_TEXTURE_STACK_DEPTH:
540 unit = ctx->Texture.CurrentUnit;
541 v->value_int = ctx->TextureMatrixStack[unit].Depth + 1;
542 break;
543 case GL_TEXTURE_MATRIX:
544 unit = ctx->Texture.CurrentUnit;
545 v->value_matrix = ctx->TextureMatrixStack[unit].Top;
546 break;
547
548 case GL_TEXTURE_COORD_ARRAY:
549 case GL_TEXTURE_COORD_ARRAY_SIZE:
550 case GL_TEXTURE_COORD_ARRAY_TYPE:
551 case GL_TEXTURE_COORD_ARRAY_STRIDE:
552 array = &ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_TEX(ctx->Array.ActiveTexture)];
553 v->value_int = *(GLuint *) ((char *) array + d->offset);
554 break;
555
556 case GL_ACTIVE_TEXTURE_ARB:
557 v->value_int = GL_TEXTURE0_ARB + ctx->Texture.CurrentUnit;
558 break;
559 case GL_CLIENT_ACTIVE_TEXTURE_ARB:
560 v->value_int = GL_TEXTURE0_ARB + ctx->Array.ActiveTexture;
561 break;
562
563 case GL_MODELVIEW_STACK_DEPTH:
564 case GL_PROJECTION_STACK_DEPTH:
565 v->value_int = *(GLint *) ((char *) ctx + d->offset) + 1;
566 break;
567
568 case GL_MAX_TEXTURE_SIZE:
569 case GL_MAX_3D_TEXTURE_SIZE:
570 case GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB:
571 p = (GLuint *) ((char *) ctx + d->offset);
572 v->value_int = 1 << (*p - 1);
573 break;
574
575 case GL_SCISSOR_BOX:
576 v->value_int_4[0] = ctx->Scissor.X;
577 v->value_int_4[1] = ctx->Scissor.Y;
578 v->value_int_4[2] = ctx->Scissor.Width;
579 v->value_int_4[3] = ctx->Scissor.Height;
580 break;
581
582 case GL_LIST_INDEX:
583 v->value_int =
584 ctx->ListState.CurrentList ? ctx->ListState.CurrentList->Name : 0;
585 break;
586 case GL_LIST_MODE:
587 if (!ctx->CompileFlag)
588 v->value_enum = 0;
589 else if (ctx->ExecuteFlag)
590 v->value_enum = GL_COMPILE_AND_EXECUTE;
591 else
592 v->value_enum = GL_COMPILE;
593 break;
594
595 case GL_VIEWPORT:
596 v->value_int_4[0] = ctx->Viewport.X;
597 v->value_int_4[1] = ctx->Viewport.Y;
598 v->value_int_4[2] = ctx->Viewport.Width;
599 v->value_int_4[3] = ctx->Viewport.Height;
600 break;
601
602 case GL_ACTIVE_STENCIL_FACE_EXT:
603 v->value_enum = ctx->Stencil.ActiveFace ? GL_BACK : GL_FRONT;
604 break;
605
606 case GL_STENCIL_FAIL:
607 v->value_enum = ctx->Stencil.FailFunc[ctx->Stencil.ActiveFace];
608 break;
609 case GL_STENCIL_FUNC:
610 v->value_enum = ctx->Stencil.Function[ctx->Stencil.ActiveFace];
611 break;
612 case GL_STENCIL_PASS_DEPTH_FAIL:
613 v->value_enum = ctx->Stencil.ZFailFunc[ctx->Stencil.ActiveFace];
614 break;
615 case GL_STENCIL_PASS_DEPTH_PASS:
616 v->value_enum = ctx->Stencil.ZPassFunc[ctx->Stencil.ActiveFace];
617 break;
618 case GL_STENCIL_REF:
619 v->value_int = ctx->Stencil.Ref[ctx->Stencil.ActiveFace];
620 break;
621 case GL_STENCIL_VALUE_MASK:
622 v->value_int = ctx->Stencil.ValueMask[ctx->Stencil.ActiveFace];
623 break;
624 case GL_STENCIL_WRITEMASK:
625 v->value_int = ctx->Stencil.WriteMask[ctx->Stencil.ActiveFace];
626 break;
627
628 case GL_NUM_EXTENSIONS:
629 v->value_int = _mesa_get_extension_count(ctx);
630 break;
631
632 case GL_IMPLEMENTATION_COLOR_READ_TYPE_OES:
633 v->value_int = _mesa_get_color_read_type(ctx);
634 break;
635 case GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES:
636 v->value_int = _mesa_get_color_read_format(ctx);
637 break;
638
639 case GL_CURRENT_MATRIX_STACK_DEPTH_ARB:
640 v->value_int = ctx->CurrentStack->Depth + 1;
641 break;
642 case GL_CURRENT_MATRIX_ARB:
643 case GL_TRANSPOSE_CURRENT_MATRIX_ARB:
644 v->value_matrix = ctx->CurrentStack->Top;
645 break;
646
647 case GL_NUM_COMPRESSED_TEXTURE_FORMATS_ARB:
648 v->value_int = _mesa_get_compressed_formats(ctx, NULL);
649 break;
650 case GL_COMPRESSED_TEXTURE_FORMATS_ARB:
651 v->value_int_n.n =
652 _mesa_get_compressed_formats(ctx, v->value_int_n.ints);
653 ASSERT(v->value_int_n.n <= 100);
654 break;
655
656 case GL_MAX_VARYING_FLOATS_ARB:
657 v->value_int = ctx->Const.MaxVarying * 4;
658 break;
659
660 /* Various object names */
661
662 case GL_TEXTURE_BINDING_1D:
663 case GL_TEXTURE_BINDING_2D:
664 case GL_TEXTURE_BINDING_3D:
665 case GL_TEXTURE_BINDING_1D_ARRAY_EXT:
666 case GL_TEXTURE_BINDING_2D_ARRAY_EXT:
667 case GL_TEXTURE_BINDING_CUBE_MAP_ARB:
668 case GL_TEXTURE_BINDING_RECTANGLE_NV:
669 case GL_TEXTURE_BINDING_EXTERNAL_OES:
670 unit = ctx->Texture.CurrentUnit;
671 v->value_int =
672 ctx->Texture.Unit[unit].CurrentTex[d->offset]->Name;
673 break;
674
675 /* GL_ARB_vertex_buffer_object */
676 case GL_VERTEX_ARRAY_BUFFER_BINDING_ARB:
677 case GL_NORMAL_ARRAY_BUFFER_BINDING_ARB:
678 case GL_COLOR_ARRAY_BUFFER_BINDING_ARB:
679 case GL_INDEX_ARRAY_BUFFER_BINDING_ARB:
680 case GL_EDGE_FLAG_ARRAY_BUFFER_BINDING_ARB:
681 case GL_SECONDARY_COLOR_ARRAY_BUFFER_BINDING_ARB:
682 case GL_FOG_COORDINATE_ARRAY_BUFFER_BINDING_ARB:
683 buffer_obj = (struct gl_buffer_object **)
684 ((char *) ctx->Array.ArrayObj + d->offset);
685 v->value_int = (*buffer_obj)->Name;
686 break;
687 case GL_ARRAY_BUFFER_BINDING_ARB:
688 v->value_int = ctx->Array.ArrayBufferObj->Name;
689 break;
690 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING_ARB:
691 v->value_int =
692 ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_TEX(ctx->Array.ActiveTexture)].BufferObj->Name;
693 break;
694 case GL_ELEMENT_ARRAY_BUFFER_BINDING_ARB:
695 v->value_int = ctx->Array.ArrayObj->ElementArrayBufferObj->Name;
696 break;
697
698 /* ARB_copy_buffer */
699 case GL_COPY_READ_BUFFER:
700 v->value_int = ctx->CopyReadBuffer->Name;
701 break;
702 case GL_COPY_WRITE_BUFFER:
703 v->value_int = ctx->CopyWriteBuffer->Name;
704 break;
705
706 case GL_PIXEL_PACK_BUFFER_BINDING_EXT:
707 v->value_int = ctx->Pack.BufferObj->Name;
708 break;
709 case GL_PIXEL_UNPACK_BUFFER_BINDING_EXT:
710 v->value_int = ctx->Unpack.BufferObj->Name;
711 break;
712 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
713 v->value_int = ctx->TransformFeedback.CurrentBuffer->Name;
714 break;
715 case GL_TRANSFORM_FEEDBACK_BUFFER_PAUSED:
716 v->value_int = ctx->TransformFeedback.CurrentObject->Paused;
717 break;
718 case GL_TRANSFORM_FEEDBACK_BUFFER_ACTIVE:
719 v->value_int = ctx->TransformFeedback.CurrentObject->Active;
720 break;
721 case GL_TRANSFORM_FEEDBACK_BINDING:
722 v->value_int = ctx->TransformFeedback.CurrentObject->Name;
723 break;
724 case GL_CURRENT_PROGRAM:
725 v->value_int =
726 ctx->Shader.ActiveProgram ? ctx->Shader.ActiveProgram->Name : 0;
727 break;
728 case GL_READ_FRAMEBUFFER_BINDING_EXT:
729 v->value_int = ctx->ReadBuffer->Name;
730 break;
731 case GL_RENDERBUFFER_BINDING_EXT:
732 v->value_int =
733 ctx->CurrentRenderbuffer ? ctx->CurrentRenderbuffer->Name : 0;
734 break;
735 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
736 v->value_int = ctx->Array.ArrayObj->VertexAttrib[VERT_ATTRIB_POINT_SIZE].BufferObj->Name;
737 break;
738
739 case GL_FOG_COLOR:
740 if(ctx->Color._ClampFragmentColor)
741 COPY_4FV(v->value_float_4, ctx->Fog.Color);
742 else
743 COPY_4FV(v->value_float_4, ctx->Fog.ColorUnclamped);
744 break;
745 case GL_COLOR_CLEAR_VALUE:
746 if(ctx->Color._ClampFragmentColor) {
747 v->value_float_4[0] = CLAMP(ctx->Color.ClearColor.f[0], 0.0F, 1.0F);
748 v->value_float_4[1] = CLAMP(ctx->Color.ClearColor.f[1], 0.0F, 1.0F);
749 v->value_float_4[2] = CLAMP(ctx->Color.ClearColor.f[2], 0.0F, 1.0F);
750 v->value_float_4[3] = CLAMP(ctx->Color.ClearColor.f[3], 0.0F, 1.0F);
751 } else
752 COPY_4FV(v->value_float_4, ctx->Color.ClearColor.f);
753 break;
754 case GL_BLEND_COLOR_EXT:
755 if(ctx->Color._ClampFragmentColor)
756 COPY_4FV(v->value_float_4, ctx->Color.BlendColor);
757 else
758 COPY_4FV(v->value_float_4, ctx->Color.BlendColorUnclamped);
759 break;
760 case GL_ALPHA_TEST_REF:
761 if(ctx->Color._ClampFragmentColor)
762 v->value_float = ctx->Color.AlphaRef;
763 else
764 v->value_float = ctx->Color.AlphaRefUnclamped;
765 break;
766 case GL_MAX_VERTEX_UNIFORM_VECTORS:
767 v->value_int = ctx->Const.VertexProgram.MaxUniformComponents / 4;
768 break;
769
770 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
771 v->value_int = ctx->Const.FragmentProgram.MaxUniformComponents / 4;
772 break;
773
774 /* GL_ARB_texture_buffer_object */
775 case GL_TEXTURE_BUFFER_ARB:
776 v->value_int = ctx->Texture.BufferObject->Name;
777 break;
778 case GL_TEXTURE_BINDING_BUFFER_ARB:
779 unit = ctx->Texture.CurrentUnit;
780 v->value_int =
781 ctx->Texture.Unit[unit].CurrentTex[TEXTURE_BUFFER_INDEX]->Name;
782 break;
783 case GL_TEXTURE_BUFFER_DATA_STORE_BINDING_ARB:
784 {
785 struct gl_buffer_object *buf =
786 ctx->Texture.Unit[ctx->Texture.CurrentUnit]
787 .CurrentTex[TEXTURE_BUFFER_INDEX]->BufferObject;
788 v->value_int = buf ? buf->Name : 0;
789 }
790 break;
791 case GL_TEXTURE_BUFFER_FORMAT_ARB:
792 v->value_int = ctx->Texture.Unit[ctx->Texture.CurrentUnit]
793 .CurrentTex[TEXTURE_BUFFER_INDEX]->BufferObjectFormat;
794 break;
795
796 /* GL_ARB_sampler_objects */
797 case GL_SAMPLER_BINDING:
798 {
799 struct gl_sampler_object *samp =
800 ctx->Texture.Unit[ctx->Texture.CurrentUnit].Sampler;
801 v->value_int = samp ? samp->Name : 0;
802 }
803 break;
804 /* GL_ARB_uniform_buffer_object */
805 case GL_UNIFORM_BUFFER_BINDING:
806 v->value_int = ctx->UniformBuffer->Name;
807 break;
808 /* GL_ARB_timer_query */
809 case GL_TIMESTAMP:
810 if (ctx->Driver.GetTimestamp) {
811 v->value_int64 = ctx->Driver.GetTimestamp(ctx);
812 }
813 else {
814 _mesa_problem(ctx, "driver doesn't implement GetTimestamp");
815 }
816 break;
817 }
818 }
819
820 /**
821 * Check extra constraints on a struct value_desc descriptor
822 *
823 * If a struct value_desc has a non-NULL extra pointer, it means that
824 * there are a number of extra constraints to check or actions to
825 * perform. The extras is just an integer array where each integer
826 * encode different constraints or actions.
827 *
828 * \param ctx current context
829 * \param func name of calling glGet*v() function for error reporting
830 * \param d the struct value_desc that has the extra constraints
831 *
832 * \return GL_FALSE if one of the constraints was not satisfied,
833 * otherwise GL_TRUE.
834 */
835 static GLboolean
836 check_extra(struct gl_context *ctx, const char *func, const struct value_desc *d)
837 {
838 const GLuint version = ctx->Version;
839 int total, enabled;
840 const int *e;
841
842 total = 0;
843 enabled = 0;
844 for (e = d->extra; *e != EXTRA_END; e++)
845 switch (*e) {
846 case EXTRA_VERSION_30:
847 if (version >= 30) {
848 total++;
849 enabled++;
850 }
851 break;
852 case EXTRA_VERSION_31:
853 if (version >= 31) {
854 total++;
855 enabled++;
856 }
857 break;
858 case EXTRA_VERSION_32:
859 if (version >= 32) {
860 total++;
861 enabled++;
862 }
863 break;
864 case EXTRA_NEW_FRAG_CLAMP:
865 if (ctx->NewState & (_NEW_BUFFERS | _NEW_FRAG_CLAMP))
866 _mesa_update_state(ctx);
867 break;
868 case EXTRA_API_ES2:
869 if (ctx->API == API_OPENGLES2) {
870 total++;
871 enabled++;
872 }
873 break;
874 case EXTRA_API_GL:
875 if (_mesa_is_desktop_gl(ctx)) {
876 total++;
877 enabled++;
878 }
879 break;
880 case EXTRA_NEW_BUFFERS:
881 if (ctx->NewState & _NEW_BUFFERS)
882 _mesa_update_state(ctx);
883 break;
884 case EXTRA_FLUSH_CURRENT:
885 FLUSH_CURRENT(ctx, 0);
886 break;
887 case EXTRA_VALID_DRAW_BUFFER:
888 if (d->pname - GL_DRAW_BUFFER0_ARB >= ctx->Const.MaxDrawBuffers) {
889 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(draw buffer %u)",
890 func, d->pname - GL_DRAW_BUFFER0_ARB);
891 return GL_FALSE;
892 }
893 break;
894 case EXTRA_VALID_TEXTURE_UNIT:
895 if (ctx->Texture.CurrentUnit >= ctx->Const.MaxTextureCoordUnits) {
896 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(texture %u)",
897 func, ctx->Texture.CurrentUnit);
898 return GL_FALSE;
899 }
900 break;
901 case EXTRA_VALID_CLIP_DISTANCE:
902 if (d->pname - GL_CLIP_DISTANCE0 >= ctx->Const.MaxClipPlanes) {
903 _mesa_error(ctx, GL_INVALID_ENUM, "%s(clip distance %u)",
904 func, d->pname - GL_CLIP_DISTANCE0);
905 return GL_FALSE;
906 }
907 break;
908 case EXTRA_GLSL_130:
909 if (ctx->Const.GLSLVersion >= 130) {
910 total++;
911 enabled++;
912 }
913 break;
914 case EXTRA_END:
915 break;
916 default: /* *e is a offset into the extension struct */
917 total++;
918 if (*(GLboolean *) ((char *) &ctx->Extensions + *e))
919 enabled++;
920 break;
921 }
922
923 if (total > 0 && enabled == 0) {
924 _mesa_error(ctx, GL_INVALID_ENUM, "%s(pname=%s)", func,
925 _mesa_lookup_enum_by_nr(d->pname));
926 return GL_FALSE;
927 }
928
929 return GL_TRUE;
930 }
931
932 static const struct value_desc error_value =
933 { 0, 0, TYPE_INVALID, NO_OFFSET, NO_EXTRA };
934
935 /**
936 * Find the struct value_desc corresponding to the enum 'pname'.
937 *
938 * We hash the enum value to get an index into the 'table' array,
939 * which holds the index in the 'values' array of struct value_desc.
940 * Once we've found the entry, we do the extra checks, if any, then
941 * look up the value and return a pointer to it.
942 *
943 * If the value has to be computed (for example, it's the result of a
944 * function call or we need to add 1 to it), we use the tmp 'v' to
945 * store the result.
946 *
947 * \param func name of glGet*v() func for error reporting
948 * \param pname the enum value we're looking up
949 * \param p is were we return the pointer to the value
950 * \param v a tmp union value variable in the calling glGet*v() function
951 *
952 * \return the struct value_desc corresponding to the enum or a struct
953 * value_desc of TYPE_INVALID if not found. This lets the calling
954 * glGet*v() function jump right into a switch statement and
955 * handle errors there instead of having to check for NULL.
956 */
957 static const struct value_desc *
958 find_value(const char *func, GLenum pname, void **p, union value *v)
959 {
960 GET_CURRENT_CONTEXT(ctx);
961 struct gl_texture_unit *unit;
962 int mask, hash;
963 const struct value_desc *d;
964 int api;
965
966 api = ctx->API;
967 mask = Elements(table(api)) - 1;
968 hash = (pname * prime_factor);
969 while (1) {
970 int idx = table(api)[hash & mask];
971
972 /* If the enum isn't valid, the hash walk ends with index 0,
973 * pointing to the first entry of values[] which doesn't hold
974 * any valid enum. */
975 if (unlikely(idx == 0)) {
976 _mesa_error(ctx, GL_INVALID_ENUM, "%s(pname=%s)", func,
977 _mesa_lookup_enum_by_nr(pname));
978 return &error_value;
979 }
980
981 d = &values[idx];
982 if (likely(d->pname == pname))
983 break;
984
985 hash += prime_step;
986 }
987
988 if (unlikely(d->extra && !check_extra(ctx, func, d)))
989 return &error_value;
990
991 switch (d->location) {
992 case LOC_BUFFER:
993 *p = ((char *) ctx->DrawBuffer + d->offset);
994 return d;
995 case LOC_CONTEXT:
996 *p = ((char *) ctx + d->offset);
997 return d;
998 case LOC_ARRAY:
999 *p = ((char *) ctx->Array.ArrayObj + d->offset);
1000 return d;
1001 case LOC_TEXUNIT:
1002 unit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
1003 *p = ((char *) unit + d->offset);
1004 return d;
1005 case LOC_CUSTOM:
1006 find_custom_value(ctx, d, v);
1007 *p = v;
1008 return d;
1009 default:
1010 assert(0);
1011 break;
1012 }
1013
1014 /* silence warning */
1015 return &error_value;
1016 }
1017
1018 static const int transpose[] = {
1019 0, 4, 8, 12,
1020 1, 5, 9, 13,
1021 2, 6, 10, 14,
1022 3, 7, 11, 15
1023 };
1024
1025 void GLAPIENTRY
1026 _mesa_GetBooleanv(GLenum pname, GLboolean *params)
1027 {
1028 const struct value_desc *d;
1029 union value v;
1030 GLmatrix *m;
1031 int shift, i;
1032 void *p;
1033 GET_CURRENT_CONTEXT(ctx);
1034
1035 ASSERT_OUTSIDE_BEGIN_END(ctx);
1036
1037 d = find_value("glGetBooleanv", pname, &p, &v);
1038 switch (d->type) {
1039 case TYPE_INVALID:
1040 break;
1041 case TYPE_CONST:
1042 params[0] = INT_TO_BOOLEAN(d->offset);
1043 break;
1044
1045 case TYPE_FLOAT_4:
1046 case TYPE_FLOATN_4:
1047 params[3] = FLOAT_TO_BOOLEAN(((GLfloat *) p)[3]);
1048 case TYPE_FLOAT_3:
1049 case TYPE_FLOATN_3:
1050 params[2] = FLOAT_TO_BOOLEAN(((GLfloat *) p)[2]);
1051 case TYPE_FLOAT_2:
1052 case TYPE_FLOATN_2:
1053 params[1] = FLOAT_TO_BOOLEAN(((GLfloat *) p)[1]);
1054 case TYPE_FLOAT:
1055 case TYPE_FLOATN:
1056 params[0] = FLOAT_TO_BOOLEAN(((GLfloat *) p)[0]);
1057 break;
1058
1059 case TYPE_DOUBLEN:
1060 params[0] = FLOAT_TO_BOOLEAN(((GLdouble *) p)[0]);
1061 break;
1062
1063 case TYPE_INT_4:
1064 params[3] = INT_TO_BOOLEAN(((GLint *) p)[3]);
1065 case TYPE_INT_3:
1066 params[2] = INT_TO_BOOLEAN(((GLint *) p)[2]);
1067 case TYPE_INT_2:
1068 case TYPE_ENUM_2:
1069 params[1] = INT_TO_BOOLEAN(((GLint *) p)[1]);
1070 case TYPE_INT:
1071 case TYPE_ENUM:
1072 params[0] = INT_TO_BOOLEAN(((GLint *) p)[0]);
1073 break;
1074
1075 case TYPE_INT_N:
1076 for (i = 0; i < v.value_int_n.n; i++)
1077 params[i] = INT_TO_BOOLEAN(v.value_int_n.ints[i]);
1078 break;
1079
1080 case TYPE_INT64:
1081 params[0] = INT64_TO_BOOLEAN(((GLint64 *) p)[0]);
1082 break;
1083
1084 case TYPE_BOOLEAN:
1085 params[0] = ((GLboolean*) p)[0];
1086 break;
1087
1088 case TYPE_MATRIX:
1089 m = *(GLmatrix **) p;
1090 for (i = 0; i < 16; i++)
1091 params[i] = FLOAT_TO_BOOLEAN(m->m[i]);
1092 break;
1093
1094 case TYPE_MATRIX_T:
1095 m = *(GLmatrix **) p;
1096 for (i = 0; i < 16; i++)
1097 params[i] = FLOAT_TO_BOOLEAN(m->m[transpose[i]]);
1098 break;
1099
1100 case TYPE_BIT_0:
1101 case TYPE_BIT_1:
1102 case TYPE_BIT_2:
1103 case TYPE_BIT_3:
1104 case TYPE_BIT_4:
1105 case TYPE_BIT_5:
1106 case TYPE_BIT_6:
1107 case TYPE_BIT_7:
1108 shift = d->type - TYPE_BIT_0;
1109 params[0] = (*(GLbitfield *) p >> shift) & 1;
1110 break;
1111 }
1112 }
1113
1114 void GLAPIENTRY
1115 _mesa_GetFloatv(GLenum pname, GLfloat *params)
1116 {
1117 const struct value_desc *d;
1118 union value v;
1119 GLmatrix *m;
1120 int shift, i;
1121 void *p;
1122 GET_CURRENT_CONTEXT(ctx);
1123
1124 ASSERT_OUTSIDE_BEGIN_END(ctx);
1125
1126 d = find_value("glGetFloatv", pname, &p, &v);
1127 switch (d->type) {
1128 case TYPE_INVALID:
1129 break;
1130 case TYPE_CONST:
1131 params[0] = (GLfloat) d->offset;
1132 break;
1133
1134 case TYPE_FLOAT_4:
1135 case TYPE_FLOATN_4:
1136 params[3] = ((GLfloat *) p)[3];
1137 case TYPE_FLOAT_3:
1138 case TYPE_FLOATN_3:
1139 params[2] = ((GLfloat *) p)[2];
1140 case TYPE_FLOAT_2:
1141 case TYPE_FLOATN_2:
1142 params[1] = ((GLfloat *) p)[1];
1143 case TYPE_FLOAT:
1144 case TYPE_FLOATN:
1145 params[0] = ((GLfloat *) p)[0];
1146 break;
1147
1148 case TYPE_DOUBLEN:
1149 params[0] = (GLfloat) (((GLdouble *) p)[0]);
1150 break;
1151
1152 case TYPE_INT_4:
1153 params[3] = (GLfloat) (((GLint *) p)[3]);
1154 case TYPE_INT_3:
1155 params[2] = (GLfloat) (((GLint *) p)[2]);
1156 case TYPE_INT_2:
1157 case TYPE_ENUM_2:
1158 params[1] = (GLfloat) (((GLint *) p)[1]);
1159 case TYPE_INT:
1160 case TYPE_ENUM:
1161 params[0] = (GLfloat) (((GLint *) p)[0]);
1162 break;
1163
1164 case TYPE_INT_N:
1165 for (i = 0; i < v.value_int_n.n; i++)
1166 params[i] = INT_TO_FLOAT(v.value_int_n.ints[i]);
1167 break;
1168
1169 case TYPE_INT64:
1170 params[0] = (GLfloat) (((GLint64 *) p)[0]);
1171 break;
1172
1173 case TYPE_BOOLEAN:
1174 params[0] = BOOLEAN_TO_FLOAT(*(GLboolean*) p);
1175 break;
1176
1177 case TYPE_MATRIX:
1178 m = *(GLmatrix **) p;
1179 for (i = 0; i < 16; i++)
1180 params[i] = m->m[i];
1181 break;
1182
1183 case TYPE_MATRIX_T:
1184 m = *(GLmatrix **) p;
1185 for (i = 0; i < 16; i++)
1186 params[i] = m->m[transpose[i]];
1187 break;
1188
1189 case TYPE_BIT_0:
1190 case TYPE_BIT_1:
1191 case TYPE_BIT_2:
1192 case TYPE_BIT_3:
1193 case TYPE_BIT_4:
1194 case TYPE_BIT_5:
1195 case TYPE_BIT_6:
1196 case TYPE_BIT_7:
1197 shift = d->type - TYPE_BIT_0;
1198 params[0] = BOOLEAN_TO_FLOAT((*(GLbitfield *) p >> shift) & 1);
1199 break;
1200 }
1201 }
1202
1203 void GLAPIENTRY
1204 _mesa_GetIntegerv(GLenum pname, GLint *params)
1205 {
1206 const struct value_desc *d;
1207 union value v;
1208 GLmatrix *m;
1209 int shift, i;
1210 void *p;
1211 GET_CURRENT_CONTEXT(ctx);
1212
1213 ASSERT_OUTSIDE_BEGIN_END(ctx);
1214
1215 d = find_value("glGetIntegerv", pname, &p, &v);
1216 switch (d->type) {
1217 case TYPE_INVALID:
1218 break;
1219 case TYPE_CONST:
1220 params[0] = d->offset;
1221 break;
1222
1223 case TYPE_FLOAT_4:
1224 params[3] = IROUND(((GLfloat *) p)[3]);
1225 case TYPE_FLOAT_3:
1226 params[2] = IROUND(((GLfloat *) p)[2]);
1227 case TYPE_FLOAT_2:
1228 params[1] = IROUND(((GLfloat *) p)[1]);
1229 case TYPE_FLOAT:
1230 params[0] = IROUND(((GLfloat *) p)[0]);
1231 break;
1232
1233 case TYPE_FLOATN_4:
1234 params[3] = FLOAT_TO_INT(((GLfloat *) p)[3]);
1235 case TYPE_FLOATN_3:
1236 params[2] = FLOAT_TO_INT(((GLfloat *) p)[2]);
1237 case TYPE_FLOATN_2:
1238 params[1] = FLOAT_TO_INT(((GLfloat *) p)[1]);
1239 case TYPE_FLOATN:
1240 params[0] = FLOAT_TO_INT(((GLfloat *) p)[0]);
1241 break;
1242
1243 case TYPE_DOUBLEN:
1244 params[0] = FLOAT_TO_INT(((GLdouble *) p)[0]);
1245 break;
1246
1247 case TYPE_INT_4:
1248 params[3] = ((GLint *) p)[3];
1249 case TYPE_INT_3:
1250 params[2] = ((GLint *) p)[2];
1251 case TYPE_INT_2:
1252 case TYPE_ENUM_2:
1253 params[1] = ((GLint *) p)[1];
1254 case TYPE_INT:
1255 case TYPE_ENUM:
1256 params[0] = ((GLint *) p)[0];
1257 break;
1258
1259 case TYPE_INT_N:
1260 for (i = 0; i < v.value_int_n.n; i++)
1261 params[i] = v.value_int_n.ints[i];
1262 break;
1263
1264 case TYPE_INT64:
1265 params[0] = INT64_TO_INT(((GLint64 *) p)[0]);
1266 break;
1267
1268 case TYPE_BOOLEAN:
1269 params[0] = BOOLEAN_TO_INT(*(GLboolean*) p);
1270 break;
1271
1272 case TYPE_MATRIX:
1273 m = *(GLmatrix **) p;
1274 for (i = 0; i < 16; i++)
1275 params[i] = FLOAT_TO_INT(m->m[i]);
1276 break;
1277
1278 case TYPE_MATRIX_T:
1279 m = *(GLmatrix **) p;
1280 for (i = 0; i < 16; i++)
1281 params[i] = FLOAT_TO_INT(m->m[transpose[i]]);
1282 break;
1283
1284 case TYPE_BIT_0:
1285 case TYPE_BIT_1:
1286 case TYPE_BIT_2:
1287 case TYPE_BIT_3:
1288 case TYPE_BIT_4:
1289 case TYPE_BIT_5:
1290 case TYPE_BIT_6:
1291 case TYPE_BIT_7:
1292 shift = d->type - TYPE_BIT_0;
1293 params[0] = (*(GLbitfield *) p >> shift) & 1;
1294 break;
1295 }
1296 }
1297
1298 void GLAPIENTRY
1299 _mesa_GetInteger64v(GLenum pname, GLint64 *params)
1300 {
1301 const struct value_desc *d;
1302 union value v;
1303 GLmatrix *m;
1304 int shift, i;
1305 void *p;
1306 GET_CURRENT_CONTEXT(ctx);
1307
1308 ASSERT_OUTSIDE_BEGIN_END(ctx);
1309
1310 d = find_value("glGetInteger64v", pname, &p, &v);
1311 switch (d->type) {
1312 case TYPE_INVALID:
1313 break;
1314 case TYPE_CONST:
1315 params[0] = d->offset;
1316 break;
1317
1318 case TYPE_FLOAT_4:
1319 params[3] = IROUND64(((GLfloat *) p)[3]);
1320 case TYPE_FLOAT_3:
1321 params[2] = IROUND64(((GLfloat *) p)[2]);
1322 case TYPE_FLOAT_2:
1323 params[1] = IROUND64(((GLfloat *) p)[1]);
1324 case TYPE_FLOAT:
1325 params[0] = IROUND64(((GLfloat *) p)[0]);
1326 break;
1327
1328 case TYPE_FLOATN_4:
1329 params[3] = FLOAT_TO_INT64(((GLfloat *) p)[3]);
1330 case TYPE_FLOATN_3:
1331 params[2] = FLOAT_TO_INT64(((GLfloat *) p)[2]);
1332 case TYPE_FLOATN_2:
1333 params[1] = FLOAT_TO_INT64(((GLfloat *) p)[1]);
1334 case TYPE_FLOATN:
1335 params[0] = FLOAT_TO_INT64(((GLfloat *) p)[0]);
1336 break;
1337
1338 case TYPE_DOUBLEN:
1339 params[0] = FLOAT_TO_INT64(((GLdouble *) p)[0]);
1340 break;
1341
1342 case TYPE_INT_4:
1343 params[3] = ((GLint *) p)[3];
1344 case TYPE_INT_3:
1345 params[2] = ((GLint *) p)[2];
1346 case TYPE_INT_2:
1347 case TYPE_ENUM_2:
1348 params[1] = ((GLint *) p)[1];
1349 case TYPE_INT:
1350 case TYPE_ENUM:
1351 params[0] = ((GLint *) p)[0];
1352 break;
1353
1354 case TYPE_INT_N:
1355 for (i = 0; i < v.value_int_n.n; i++)
1356 params[i] = INT_TO_BOOLEAN(v.value_int_n.ints[i]);
1357 break;
1358
1359 case TYPE_INT64:
1360 params[0] = ((GLint64 *) p)[0];
1361 break;
1362
1363 case TYPE_BOOLEAN:
1364 params[0] = ((GLboolean*) p)[0];
1365 break;
1366
1367 case TYPE_MATRIX:
1368 m = *(GLmatrix **) p;
1369 for (i = 0; i < 16; i++)
1370 params[i] = FLOAT_TO_INT64(m->m[i]);
1371 break;
1372
1373 case TYPE_MATRIX_T:
1374 m = *(GLmatrix **) p;
1375 for (i = 0; i < 16; i++)
1376 params[i] = FLOAT_TO_INT64(m->m[transpose[i]]);
1377 break;
1378
1379 case TYPE_BIT_0:
1380 case TYPE_BIT_1:
1381 case TYPE_BIT_2:
1382 case TYPE_BIT_3:
1383 case TYPE_BIT_4:
1384 case TYPE_BIT_5:
1385 case TYPE_BIT_6:
1386 case TYPE_BIT_7:
1387 shift = d->type - TYPE_BIT_0;
1388 params[0] = (*(GLbitfield *) p >> shift) & 1;
1389 break;
1390 }
1391 }
1392
1393 void GLAPIENTRY
1394 _mesa_GetDoublev(GLenum pname, GLdouble *params)
1395 {
1396 const struct value_desc *d;
1397 union value v;
1398 GLmatrix *m;
1399 int shift, i;
1400 void *p;
1401 GET_CURRENT_CONTEXT(ctx);
1402
1403 ASSERT_OUTSIDE_BEGIN_END(ctx);
1404
1405 d = find_value("glGetDoublev", pname, &p, &v);
1406 switch (d->type) {
1407 case TYPE_INVALID:
1408 break;
1409 case TYPE_CONST:
1410 params[0] = d->offset;
1411 break;
1412
1413 case TYPE_FLOAT_4:
1414 case TYPE_FLOATN_4:
1415 params[3] = ((GLfloat *) p)[3];
1416 case TYPE_FLOAT_3:
1417 case TYPE_FLOATN_3:
1418 params[2] = ((GLfloat *) p)[2];
1419 case TYPE_FLOAT_2:
1420 case TYPE_FLOATN_2:
1421 params[1] = ((GLfloat *) p)[1];
1422 case TYPE_FLOAT:
1423 case TYPE_FLOATN:
1424 params[0] = ((GLfloat *) p)[0];
1425 break;
1426
1427 case TYPE_DOUBLEN:
1428 params[0] = ((GLdouble *) p)[0];
1429 break;
1430
1431 case TYPE_INT_4:
1432 params[3] = ((GLint *) p)[3];
1433 case TYPE_INT_3:
1434 params[2] = ((GLint *) p)[2];
1435 case TYPE_INT_2:
1436 case TYPE_ENUM_2:
1437 params[1] = ((GLint *) p)[1];
1438 case TYPE_INT:
1439 case TYPE_ENUM:
1440 params[0] = ((GLint *) p)[0];
1441 break;
1442
1443 case TYPE_INT_N:
1444 for (i = 0; i < v.value_int_n.n; i++)
1445 params[i] = v.value_int_n.ints[i];
1446 break;
1447
1448 case TYPE_INT64:
1449 params[0] = (GLdouble) (((GLint64 *) p)[0]);
1450 break;
1451
1452 case TYPE_BOOLEAN:
1453 params[0] = *(GLboolean*) p;
1454 break;
1455
1456 case TYPE_MATRIX:
1457 m = *(GLmatrix **) p;
1458 for (i = 0; i < 16; i++)
1459 params[i] = m->m[i];
1460 break;
1461
1462 case TYPE_MATRIX_T:
1463 m = *(GLmatrix **) p;
1464 for (i = 0; i < 16; i++)
1465 params[i] = m->m[transpose[i]];
1466 break;
1467
1468 case TYPE_BIT_0:
1469 case TYPE_BIT_1:
1470 case TYPE_BIT_2:
1471 case TYPE_BIT_3:
1472 case TYPE_BIT_4:
1473 case TYPE_BIT_5:
1474 case TYPE_BIT_6:
1475 case TYPE_BIT_7:
1476 shift = d->type - TYPE_BIT_0;
1477 params[0] = (*(GLbitfield *) p >> shift) & 1;
1478 break;
1479 }
1480 }
1481
1482 static enum value_type
1483 find_value_indexed(const char *func, GLenum pname, int index, union value *v)
1484 {
1485 GET_CURRENT_CONTEXT(ctx);
1486
1487 switch (pname) {
1488
1489 case GL_BLEND:
1490 if (index >= ctx->Const.MaxDrawBuffers)
1491 goto invalid_value;
1492 if (!ctx->Extensions.EXT_draw_buffers2)
1493 goto invalid_enum;
1494 v->value_int = (ctx->Color.BlendEnabled >> index) & 1;
1495 return TYPE_INT;
1496
1497 case GL_BLEND_SRC:
1498 /* fall-through */
1499 case GL_BLEND_SRC_RGB:
1500 if (index >= ctx->Const.MaxDrawBuffers)
1501 goto invalid_value;
1502 if (!ctx->Extensions.ARB_draw_buffers_blend)
1503 goto invalid_enum;
1504 v->value_int = ctx->Color.Blend[index].SrcRGB;
1505 return TYPE_INT;
1506 case GL_BLEND_SRC_ALPHA:
1507 if (index >= ctx->Const.MaxDrawBuffers)
1508 goto invalid_value;
1509 if (!ctx->Extensions.ARB_draw_buffers_blend)
1510 goto invalid_enum;
1511 v->value_int = ctx->Color.Blend[index].SrcA;
1512 return TYPE_INT;
1513 case GL_BLEND_DST:
1514 /* fall-through */
1515 case GL_BLEND_DST_RGB:
1516 if (index >= ctx->Const.MaxDrawBuffers)
1517 goto invalid_value;
1518 if (!ctx->Extensions.ARB_draw_buffers_blend)
1519 goto invalid_enum;
1520 v->value_int = ctx->Color.Blend[index].DstRGB;
1521 return TYPE_INT;
1522 case GL_BLEND_DST_ALPHA:
1523 if (index >= ctx->Const.MaxDrawBuffers)
1524 goto invalid_value;
1525 if (!ctx->Extensions.ARB_draw_buffers_blend)
1526 goto invalid_enum;
1527 v->value_int = ctx->Color.Blend[index].DstA;
1528 return TYPE_INT;
1529 case GL_BLEND_EQUATION_RGB:
1530 if (index >= ctx->Const.MaxDrawBuffers)
1531 goto invalid_value;
1532 if (!ctx->Extensions.ARB_draw_buffers_blend)
1533 goto invalid_enum;
1534 v->value_int = ctx->Color.Blend[index].EquationRGB;
1535 return TYPE_INT;
1536 case GL_BLEND_EQUATION_ALPHA:
1537 if (index >= ctx->Const.MaxDrawBuffers)
1538 goto invalid_value;
1539 if (!ctx->Extensions.ARB_draw_buffers_blend)
1540 goto invalid_enum;
1541 v->value_int = ctx->Color.Blend[index].EquationA;
1542 return TYPE_INT;
1543
1544 case GL_COLOR_WRITEMASK:
1545 if (index >= ctx->Const.MaxDrawBuffers)
1546 goto invalid_value;
1547 if (!ctx->Extensions.EXT_draw_buffers2)
1548 goto invalid_enum;
1549 v->value_int_4[0] = ctx->Color.ColorMask[index][RCOMP] ? 1 : 0;
1550 v->value_int_4[1] = ctx->Color.ColorMask[index][GCOMP] ? 1 : 0;
1551 v->value_int_4[2] = ctx->Color.ColorMask[index][BCOMP] ? 1 : 0;
1552 v->value_int_4[3] = ctx->Color.ColorMask[index][ACOMP] ? 1 : 0;
1553 return TYPE_INT_4;
1554
1555 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
1556 if (index >= ctx->Const.MaxTransformFeedbackBuffers)
1557 goto invalid_value;
1558 if (!ctx->Extensions.EXT_transform_feedback)
1559 goto invalid_enum;
1560 v->value_int64 = ctx->TransformFeedback.CurrentObject->Offset[index];
1561 return TYPE_INT64;
1562
1563 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
1564 if (index >= ctx->Const.MaxTransformFeedbackBuffers)
1565 goto invalid_value;
1566 if (!ctx->Extensions.EXT_transform_feedback)
1567 goto invalid_enum;
1568 v->value_int64 = ctx->TransformFeedback.CurrentObject->Size[index];
1569 return TYPE_INT64;
1570
1571 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
1572 if (index >= ctx->Const.MaxTransformFeedbackBuffers)
1573 goto invalid_value;
1574 if (!ctx->Extensions.EXT_transform_feedback)
1575 goto invalid_enum;
1576 v->value_int = ctx->TransformFeedback.CurrentObject->BufferNames[index];
1577 return TYPE_INT;
1578
1579 case GL_UNIFORM_BUFFER_BINDING:
1580 if (index >= ctx->Const.MaxUniformBufferBindings)
1581 goto invalid_value;
1582 if (!ctx->Extensions.ARB_uniform_buffer_object)
1583 goto invalid_enum;
1584 v->value_int = ctx->UniformBufferBindings[index].BufferObject->Name;
1585 return TYPE_INT;
1586
1587 case GL_UNIFORM_BUFFER_START:
1588 if (index >= ctx->Const.MaxUniformBufferBindings)
1589 goto invalid_value;
1590 if (!ctx->Extensions.ARB_uniform_buffer_object)
1591 goto invalid_enum;
1592 v->value_int = ctx->UniformBufferBindings[index].Offset;
1593 return TYPE_INT;
1594
1595 case GL_UNIFORM_BUFFER_SIZE:
1596 if (index >= ctx->Const.MaxUniformBufferBindings)
1597 goto invalid_value;
1598 if (!ctx->Extensions.ARB_uniform_buffer_object)
1599 goto invalid_enum;
1600 v->value_int = ctx->UniformBufferBindings[index].Size;
1601 return TYPE_INT;
1602 }
1603
1604 invalid_enum:
1605 _mesa_error(ctx, GL_INVALID_ENUM, "%s(pname=%s)", func,
1606 _mesa_lookup_enum_by_nr(pname));
1607 return TYPE_INVALID;
1608 invalid_value:
1609 _mesa_error(ctx, GL_INVALID_VALUE, "%s(pname=%s)", func,
1610 _mesa_lookup_enum_by_nr(pname));
1611 return TYPE_INVALID;
1612 }
1613
1614 void GLAPIENTRY
1615 _mesa_GetBooleanIndexedv( GLenum pname, GLuint index, GLboolean *params )
1616 {
1617 union value v;
1618 enum value_type type =
1619 find_value_indexed("glGetBooleanIndexedv", pname, index, &v);
1620
1621 switch (type) {
1622 case TYPE_INT:
1623 params[0] = INT_TO_BOOLEAN(v.value_int);
1624 break;
1625 case TYPE_INT_4:
1626 params[0] = INT_TO_BOOLEAN(v.value_int_4[0]);
1627 params[1] = INT_TO_BOOLEAN(v.value_int_4[1]);
1628 params[2] = INT_TO_BOOLEAN(v.value_int_4[2]);
1629 params[3] = INT_TO_BOOLEAN(v.value_int_4[3]);
1630 break;
1631 case TYPE_INT64:
1632 params[0] = INT64_TO_BOOLEAN(v.value_int);
1633 break;
1634 default:
1635 ; /* nothing - GL error was recorded */
1636 }
1637 }
1638
1639 void GLAPIENTRY
1640 _mesa_GetIntegerIndexedv( GLenum pname, GLuint index, GLint *params )
1641 {
1642 union value v;
1643 enum value_type type =
1644 find_value_indexed("glGetIntegerIndexedv", pname, index, &v);
1645
1646 switch (type) {
1647 case TYPE_INT:
1648 params[0] = v.value_int;
1649 break;
1650 case TYPE_INT_4:
1651 params[0] = v.value_int_4[0];
1652 params[1] = v.value_int_4[1];
1653 params[2] = v.value_int_4[2];
1654 params[3] = v.value_int_4[3];
1655 break;
1656 case TYPE_INT64:
1657 params[0] = INT64_TO_INT(v.value_int);
1658 break;
1659 default:
1660 ; /* nothing - GL error was recorded */
1661 }
1662 }
1663
1664 void GLAPIENTRY
1665 _mesa_GetInteger64Indexedv( GLenum pname, GLuint index, GLint64 *params )
1666 {
1667 union value v;
1668 enum value_type type =
1669 find_value_indexed("glGetIntegerIndexedv", pname, index, &v);
1670
1671 switch (type) {
1672 case TYPE_INT:
1673 params[0] = v.value_int;
1674 break;
1675 case TYPE_INT_4:
1676 params[0] = v.value_int_4[0];
1677 params[1] = v.value_int_4[1];
1678 params[2] = v.value_int_4[2];
1679 params[3] = v.value_int_4[3];
1680 break;
1681 case TYPE_INT64:
1682 params[0] = v.value_int;
1683 break;
1684 default:
1685 ; /* nothing - GL error was recorded */
1686 }
1687 }
1688
1689 #if FEATURE_ES1
1690 void GLAPIENTRY
1691 _mesa_GetFixedv(GLenum pname, GLfixed *params)
1692 {
1693 const struct value_desc *d;
1694 union value v;
1695 GLmatrix *m;
1696 int shift, i;
1697 void *p;
1698
1699 d = find_value("glGetDoublev", pname, &p, &v);
1700 switch (d->type) {
1701 case TYPE_INVALID:
1702 break;
1703 case TYPE_CONST:
1704 params[0] = INT_TO_FIXED(d->offset);
1705 break;
1706
1707 case TYPE_FLOAT_4:
1708 case TYPE_FLOATN_4:
1709 params[3] = FLOAT_TO_FIXED(((GLfloat *) p)[3]);
1710 case TYPE_FLOAT_3:
1711 case TYPE_FLOATN_3:
1712 params[2] = FLOAT_TO_FIXED(((GLfloat *) p)[2]);
1713 case TYPE_FLOAT_2:
1714 case TYPE_FLOATN_2:
1715 params[1] = FLOAT_TO_FIXED(((GLfloat *) p)[1]);
1716 case TYPE_FLOAT:
1717 case TYPE_FLOATN:
1718 params[0] = FLOAT_TO_FIXED(((GLfloat *) p)[0]);
1719 break;
1720
1721 case TYPE_DOUBLEN:
1722 params[0] = FLOAT_TO_FIXED(((GLdouble *) p)[0]);
1723 break;
1724
1725 case TYPE_INT_4:
1726 params[3] = INT_TO_FIXED(((GLint *) p)[3]);
1727 case TYPE_INT_3:
1728 params[2] = INT_TO_FIXED(((GLint *) p)[2]);
1729 case TYPE_INT_2:
1730 case TYPE_ENUM_2:
1731 params[1] = INT_TO_FIXED(((GLint *) p)[1]);
1732 case TYPE_INT:
1733 case TYPE_ENUM:
1734 params[0] = INT_TO_FIXED(((GLint *) p)[0]);
1735 break;
1736
1737 case TYPE_INT_N:
1738 for (i = 0; i < v.value_int_n.n; i++)
1739 params[i] = INT_TO_FIXED(v.value_int_n.ints[i]);
1740 break;
1741
1742 case TYPE_INT64:
1743 params[0] = ((GLint64 *) p)[0];
1744 break;
1745
1746 case TYPE_BOOLEAN:
1747 params[0] = BOOLEAN_TO_FIXED(((GLboolean*) p)[0]);
1748 break;
1749
1750 case TYPE_MATRIX:
1751 m = *(GLmatrix **) p;
1752 for (i = 0; i < 16; i++)
1753 params[i] = FLOAT_TO_FIXED(m->m[i]);
1754 break;
1755
1756 case TYPE_MATRIX_T:
1757 m = *(GLmatrix **) p;
1758 for (i = 0; i < 16; i++)
1759 params[i] = FLOAT_TO_FIXED(m->m[transpose[i]]);
1760 break;
1761
1762 case TYPE_BIT_0:
1763 case TYPE_BIT_1:
1764 case TYPE_BIT_2:
1765 case TYPE_BIT_3:
1766 case TYPE_BIT_4:
1767 case TYPE_BIT_5:
1768 case TYPE_BIT_6:
1769 case TYPE_BIT_7:
1770 shift = d->type - TYPE_BIT_0;
1771 params[0] = BOOLEAN_TO_FIXED((*(GLbitfield *) p >> shift) & 1);
1772 break;
1773 }
1774 }
1775 #endif