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