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