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 "debug_output.h"
30 #include "enable.h"
31 #include "enums.h"
32 #include "errors.h"
33 #include "extensions.h"
34 #include "get.h"
35 #include "macros.h"
36 #include "mtypes.h"
37 #include "spirv_extensions.h"
38 #include "state.h"
39 #include "texcompress.h"
40 #include "texstate.h"
41 #include "framebuffer.h"
42 #include "samplerobj.h"
43 #include "stencil.h"
44 #include "version.h"
45
46 /* This is a table driven implemetation of the glGet*v() functions.
47 * The basic idea is that most getters just look up an int somewhere
48 * in struct gl_context and then convert it to a bool or float according to
49 * which of glGetIntegerv() glGetBooleanv() etc is being called.
50 * Instead of generating code to do this, we can just record the enum
51 * value and the offset into struct gl_context in an array of structs. Then
52 * in glGet*(), we lookup the struct for the enum in question, and use
53 * the offset to get the int we need.
54 *
55 * Sometimes we need to look up a float, a boolean, a bit in a
56 * bitfield, a matrix or other types instead, so we need to track the
57 * type of the value in struct gl_context. And sometimes the value isn't in
58 * struct gl_context but in the drawbuffer, the array object, current texture
59 * unit, or maybe it's a computed value. So we need to also track
60 * where or how to find the value. Finally, we sometimes need to
61 * check that one of a number of extensions are enabled, the GL
62 * version or flush or call _mesa_update_state(). This is done by
63 * attaching optional extra information to the value description
64 * struct, it's sort of like an array of opcodes that describe extra
65 * checks or actions.
66 *
67 * Putting all this together we end up with struct value_desc below,
68 * and with a couple of macros to help, the table of struct value_desc
69 * is about as concise as the specification in the old python script.
70 */
71
72 static inline GLboolean
FLOAT_TO_BOOLEAN(GLfloat X)73 FLOAT_TO_BOOLEAN(GLfloat X)
74 {
75 return ( (X) ? GL_TRUE : GL_FALSE );
76 }
77
78 static inline GLint
FLOAT_TO_FIXED(GLfloat F)79 FLOAT_TO_FIXED(GLfloat F)
80 {
81 return ( ((F) * 65536.0f > INT_MAX) ? INT_MAX :
82 ((F) * 65536.0f < INT_MIN) ? INT_MIN :
83 (GLint) ((F) * 65536.0f) );
84 }
85
86 static inline GLboolean
INT_TO_BOOLEAN(GLint I)87 INT_TO_BOOLEAN(GLint I)
88 {
89 return ( (I) ? GL_TRUE : GL_FALSE );
90 }
91
92 static inline GLfixed
INT_TO_FIXED(GLint I)93 INT_TO_FIXED(GLint I)
94 {
95 return (((I) > SHRT_MAX) ? INT_MAX :
96 ((I) < SHRT_MIN) ? INT_MIN :
97 (GLint) ((I) * 65536) );
98 }
99
100
101 static inline GLboolean
INT64_TO_BOOLEAN(GLint64 I)102 INT64_TO_BOOLEAN(GLint64 I)
103 {
104 return ( (I) ? GL_TRUE : GL_FALSE );
105 }
106
107 static inline GLint
INT64_TO_INT(GLint64 I)108 INT64_TO_INT(GLint64 I)
109 {
110 return ( (GLint)((I > INT_MAX) ? INT_MAX : ((I < INT_MIN) ? INT_MIN : (I))) );
111 }
112
113 static inline GLint
BOOLEAN_TO_INT(GLboolean B)114 BOOLEAN_TO_INT(GLboolean B)
115 {
116 return ( (GLint) (B) );
117 }
118
119 static inline GLfloat
BOOLEAN_TO_FLOAT(GLboolean B)120 BOOLEAN_TO_FLOAT(GLboolean B)
121 {
122 return ( (B) ? 1.0F : 0.0F );
123 }
124
125 static inline GLfixed
BOOLEAN_TO_FIXED(GLboolean B)126 BOOLEAN_TO_FIXED(GLboolean B)
127 {
128 return ( (GLint) ((B) ? 1 : 0) << 16 );
129 }
130
131 enum value_type {
132 TYPE_INVALID,
133 TYPE_INT,
134 TYPE_INT_2,
135 TYPE_INT_3,
136 TYPE_INT_4,
137 TYPE_INT_N,
138 TYPE_UINT,
139 TYPE_UINT_2,
140 TYPE_UINT_3,
141 TYPE_UINT_4,
142 TYPE_INT64,
143 TYPE_ENUM16,
144 TYPE_ENUM,
145 TYPE_ENUM_2,
146 TYPE_BOOLEAN,
147 TYPE_UBYTE,
148 TYPE_SHORT,
149 TYPE_BIT_0,
150 TYPE_BIT_1,
151 TYPE_BIT_2,
152 TYPE_BIT_3,
153 TYPE_BIT_4,
154 TYPE_BIT_5,
155 TYPE_BIT_6,
156 TYPE_BIT_7,
157 TYPE_FLOAT,
158 TYPE_FLOAT_2,
159 TYPE_FLOAT_3,
160 TYPE_FLOAT_4,
161 TYPE_FLOAT_8,
162 TYPE_FLOATN,
163 TYPE_FLOATN_2,
164 TYPE_FLOATN_3,
165 TYPE_FLOATN_4,
166 TYPE_DOUBLEN,
167 TYPE_DOUBLEN_2,
168 TYPE_MATRIX,
169 TYPE_MATRIX_T,
170 TYPE_CONST
171 };
172
173 enum value_location {
174 LOC_BUFFER,
175 LOC_CONTEXT,
176 LOC_ARRAY,
177 LOC_TEXUNIT,
178 LOC_CUSTOM
179 };
180
181 enum value_extra {
182 EXTRA_END = 0x8000,
183 EXTRA_VERSION_30,
184 EXTRA_VERSION_31,
185 EXTRA_VERSION_32,
186 EXTRA_VERSION_40,
187 EXTRA_VERSION_43,
188 EXTRA_API_GL,
189 EXTRA_API_GL_CORE,
190 EXTRA_API_ES2,
191 EXTRA_API_ES3,
192 EXTRA_API_ES31,
193 EXTRA_API_ES32,
194 EXTRA_NEW_BUFFERS,
195 EXTRA_VALID_DRAW_BUFFER,
196 EXTRA_VALID_TEXTURE_UNIT,
197 EXTRA_VALID_CLIP_DISTANCE,
198 EXTRA_FLUSH_CURRENT,
199 EXTRA_GLSL_130,
200 EXTRA_EXT_UBO_GS,
201 EXTRA_EXT_ATOMICS_GS,
202 EXTRA_EXT_SHADER_IMAGE_GS,
203 EXTRA_EXT_ATOMICS_TESS,
204 EXTRA_EXT_SHADER_IMAGE_TESS,
205 EXTRA_EXT_SSBO_GS,
206 EXTRA_EXT_FB_NO_ATTACH_GS,
207 EXTRA_EXT_ES_GS,
208 EXTRA_EXT_PROVOKING_VERTEX_32,
209 };
210
211 #define NO_EXTRA NULL
212 #define NO_OFFSET 0
213
214 struct value_desc {
215 GLenum pname;
216 GLubyte location; /**< enum value_location */
217 GLubyte type; /**< enum value_type */
218 int offset;
219 const int *extra;
220 };
221
222 union value {
223 GLfloat value_float;
224 GLfloat value_float_4[4];
225 GLdouble value_double_2[2];
226 GLmatrix *value_matrix;
227 GLint value_int;
228 GLint value_int_4[4];
229 GLint64 value_int64;
230 GLenum value_enum;
231 GLenum16 value_enum16;
232 GLubyte value_ubyte;
233 GLshort value_short;
234 GLuint value_uint;
235
236 /* Sigh, see GL_COMPRESSED_TEXTURE_FORMATS_ARB handling */
237 struct {
238 GLint n, ints[100];
239 } value_int_n;
240 GLboolean value_bool;
241 };
242
243 #define BUFFER_FIELD(field, type) \
244 LOC_BUFFER, type, offsetof(struct gl_framebuffer, field)
245 #define CONTEXT_FIELD(field, type) \
246 LOC_CONTEXT, type, offsetof(struct gl_context, field)
247 #define ARRAY_FIELD(field, type) \
248 LOC_ARRAY, type, offsetof(struct gl_vertex_array_object, field)
249 #undef CONST /* already defined through windows.h */
250 #define CONST(value) \
251 LOC_CONTEXT, TYPE_CONST, value
252
253 #define BUFFER_INT(field) BUFFER_FIELD(field, TYPE_INT)
254 #define BUFFER_ENUM(field) BUFFER_FIELD(field, TYPE_ENUM)
255 #define BUFFER_ENUM16(field) BUFFER_FIELD(field, TYPE_ENUM16)
256 #define BUFFER_BOOL(field) BUFFER_FIELD(field, TYPE_BOOLEAN)
257
258 #define CONTEXT_INT(field) CONTEXT_FIELD(field, TYPE_INT)
259 #define CONTEXT_INT2(field) CONTEXT_FIELD(field, TYPE_INT_2)
260 #define CONTEXT_INT64(field) CONTEXT_FIELD(field, TYPE_INT64)
261 #define CONTEXT_UINT(field) CONTEXT_FIELD(field, TYPE_UINT)
262 #define CONTEXT_ENUM16(field) CONTEXT_FIELD(field, TYPE_ENUM16)
263 #define CONTEXT_ENUM(field) CONTEXT_FIELD(field, TYPE_ENUM)
264 #define CONTEXT_ENUM2(field) CONTEXT_FIELD(field, TYPE_ENUM_2)
265 #define CONTEXT_BOOL(field) CONTEXT_FIELD(field, TYPE_BOOLEAN)
266 #define CONTEXT_BIT0(field) CONTEXT_FIELD(field, TYPE_BIT_0)
267 #define CONTEXT_BIT1(field) CONTEXT_FIELD(field, TYPE_BIT_1)
268 #define CONTEXT_BIT2(field) CONTEXT_FIELD(field, TYPE_BIT_2)
269 #define CONTEXT_BIT3(field) CONTEXT_FIELD(field, TYPE_BIT_3)
270 #define CONTEXT_BIT4(field) CONTEXT_FIELD(field, TYPE_BIT_4)
271 #define CONTEXT_BIT5(field) CONTEXT_FIELD(field, TYPE_BIT_5)
272 #define CONTEXT_BIT6(field) CONTEXT_FIELD(field, TYPE_BIT_6)
273 #define CONTEXT_BIT7(field) CONTEXT_FIELD(field, TYPE_BIT_7)
274 #define CONTEXT_FLOAT(field) CONTEXT_FIELD(field, TYPE_FLOAT)
275 #define CONTEXT_FLOAT2(field) CONTEXT_FIELD(field, TYPE_FLOAT_2)
276 #define CONTEXT_FLOAT3(field) CONTEXT_FIELD(field, TYPE_FLOAT_3)
277 #define CONTEXT_FLOAT4(field) CONTEXT_FIELD(field, TYPE_FLOAT_4)
278 #define CONTEXT_FLOAT8(field) CONTEXT_FIELD(field, TYPE_FLOAT_8)
279 #define CONTEXT_MATRIX(field) CONTEXT_FIELD(field, TYPE_MATRIX)
280 #define CONTEXT_MATRIX_T(field) CONTEXT_FIELD(field, TYPE_MATRIX_T)
281
282 /* Vertex array fields */
283 #define ARRAY_INT(field) ARRAY_FIELD(field, TYPE_INT)
284 #define ARRAY_ENUM(field) ARRAY_FIELD(field, TYPE_ENUM)
285 #define ARRAY_ENUM16(field) ARRAY_FIELD(field, TYPE_ENUM16)
286 #define ARRAY_BOOL(field) ARRAY_FIELD(field, TYPE_BOOLEAN)
287 #define ARRAY_UBYTE(field) ARRAY_FIELD(field, TYPE_UBYTE)
288 #define ARRAY_SHORT(field) ARRAY_FIELD(field, TYPE_SHORT)
289
290 #define EXT(f) \
291 offsetof(struct gl_extensions, f)
292
293 #define EXTRA_EXT(e) \
294 static const int extra_##e[] = { \
295 EXT(e), EXTRA_END \
296 }
297
298 #define EXTRA_EXT2(e1, e2) \
299 static const int extra_##e1##_##e2[] = { \
300 EXT(e1), EXT(e2), EXTRA_END \
301 }
302
303 /* The 'extra' mechanism is a way to specify extra checks (such as
304 * extensions or specific gl versions) or actions (flush current, new
305 * buffers) that we need to do before looking up an enum. We need to
306 * declare them all up front so we can refer to them in the value_desc
307 * structs below.
308 *
309 * Each EXTRA_ will be executed. For EXTRA_* enums of extensions and API
310 * versions, listing multiple ones in an array means an error will be thrown
311 * only if none of them are available. If you need to check for "AND"
312 * behavior, you would need to make a custom EXTRA_ enum.
313 */
314
315 static const int extra_new_buffers[] = {
316 EXTRA_NEW_BUFFERS,
317 EXTRA_END
318 };
319
320 static const int extra_valid_draw_buffer[] = {
321 EXTRA_VALID_DRAW_BUFFER,
322 EXTRA_END
323 };
324
325 static const int extra_valid_texture_unit[] = {
326 EXTRA_VALID_TEXTURE_UNIT,
327 EXTRA_END
328 };
329
330 static const int extra_valid_clip_distance[] = {
331 EXTRA_VALID_CLIP_DISTANCE,
332 EXTRA_END
333 };
334
335 static const int extra_flush_current_valid_texture_unit[] = {
336 EXTRA_FLUSH_CURRENT,
337 EXTRA_VALID_TEXTURE_UNIT,
338 EXTRA_END
339 };
340
341 static const int extra_flush_current[] = {
342 EXTRA_FLUSH_CURRENT,
343 EXTRA_END
344 };
345
346 static const int extra_EXT_texture_integer_and_new_buffers[] = {
347 EXT(EXT_texture_integer),
348 EXTRA_NEW_BUFFERS,
349 EXTRA_END
350 };
351
352 static const int extra_GLSL_130_es3_gpushader4[] = {
353 EXTRA_GLSL_130,
354 EXTRA_API_ES3,
355 EXT(EXT_gpu_shader4),
356 EXTRA_END
357 };
358
359 static const int extra_texture_buffer_object[] = {
360 EXT(ARB_texture_buffer_object),
361 EXTRA_END
362 };
363
364 static const int extra_ARB_transform_feedback2_api_es3[] = {
365 EXT(ARB_transform_feedback2),
366 EXTRA_API_ES3,
367 EXTRA_END
368 };
369
370 static const int extra_ARB_uniform_buffer_object_and_geometry_shader[] = {
371 EXTRA_EXT_UBO_GS,
372 EXTRA_END
373 };
374
375 static const int extra_ARB_ES2_compatibility_api_es2[] = {
376 EXT(ARB_ES2_compatibility),
377 EXTRA_API_ES2,
378 EXTRA_END
379 };
380
381 static const int extra_ARB_ES3_compatibility_api_es3[] = {
382 EXT(ARB_ES3_compatibility),
383 EXTRA_API_ES3,
384 EXTRA_END
385 };
386
387 static const int extra_EXT_framebuffer_sRGB_and_new_buffers[] = {
388 EXT(EXT_framebuffer_sRGB),
389 EXTRA_NEW_BUFFERS,
390 EXTRA_END
391 };
392
393 static const int extra_EXT_packed_float[] = {
394 EXT(EXT_packed_float),
395 EXTRA_NEW_BUFFERS,
396 EXTRA_END
397 };
398
399 static const int extra_EXT_texture_array_es3[] = {
400 EXT(EXT_texture_array),
401 EXTRA_API_ES3,
402 EXTRA_END
403 };
404
405 static const int extra_ARB_shader_atomic_counters_and_geometry_shader[] = {
406 EXTRA_EXT_ATOMICS_GS,
407 EXTRA_END
408 };
409
410 static const int extra_ARB_shader_image_load_store_and_geometry_shader[] = {
411 EXTRA_EXT_SHADER_IMAGE_GS,
412 EXTRA_END
413 };
414
415 static const int extra_ARB_shader_atomic_counters_and_tessellation[] = {
416 EXTRA_EXT_ATOMICS_TESS,
417 EXTRA_END
418 };
419
420 static const int extra_ARB_shader_image_load_store_and_tessellation[] = {
421 EXTRA_EXT_SHADER_IMAGE_TESS,
422 EXTRA_END
423 };
424
425 /* HACK: remove when ARB_compute_shader is actually supported */
426 static const int extra_ARB_compute_shader_es31[] = {
427 EXT(ARB_compute_shader),
428 EXTRA_API_ES31,
429 EXTRA_END
430 };
431
432 static const int extra_ARB_shader_storage_buffer_object_es31[] = {
433 EXT(ARB_shader_storage_buffer_object),
434 EXTRA_API_ES31,
435 EXTRA_END
436 };
437
438 static const int extra_ARB_shader_storage_buffer_object_and_geometry_shader[] = {
439 EXTRA_EXT_SSBO_GS,
440 EXTRA_END
441 };
442
443 static const int extra_ARB_shader_image_load_store_shader_storage_buffer_object_es31[] = {
444 EXT(ARB_shader_image_load_store),
445 EXT(ARB_shader_storage_buffer_object),
446 EXTRA_API_ES31,
447 EXTRA_END
448 };
449
450 static const int extra_ARB_framebuffer_no_attachments_and_geometry_shader[] = {
451 EXTRA_EXT_FB_NO_ATTACH_GS,
452 EXTRA_END
453 };
454
455 static const int extra_ARB_viewport_array_or_oes_geometry_shader[] = {
456 EXT(ARB_viewport_array),
457 EXTRA_EXT_ES_GS,
458 EXTRA_END
459 };
460
461 static const int extra_ARB_viewport_array_or_oes_viewport_array[] = {
462 EXT(ARB_viewport_array),
463 EXT(OES_viewport_array),
464 EXTRA_END
465 };
466
467 static const int extra_ARB_gpu_shader5_or_oes_geometry_shader[] = {
468 EXT(ARB_gpu_shader5),
469 EXTRA_EXT_ES_GS,
470 EXTRA_END
471 };
472
473 static const int extra_ARB_gpu_shader5_or_OES_sample_variables[] = {
474 EXT(ARB_gpu_shader5),
475 EXT(OES_sample_variables),
476 EXTRA_END
477 };
478
479 static const int extra_ES32[] = {
480 EXT(ARB_ES3_2_compatibility),
481 EXTRA_API_ES32,
482 EXTRA_END
483 };
484
485 static const int extra_KHR_robustness_or_GL[] = {
486 EXT(KHR_robustness),
487 EXTRA_API_GL,
488 EXTRA_API_GL_CORE,
489 EXTRA_END
490 };
491
492 static const int extra_INTEL_conservative_rasterization[] = {
493 EXT(INTEL_conservative_rasterization),
494 EXTRA_END
495 };
496
497 EXTRA_EXT(ARB_texture_cube_map);
498 EXTRA_EXT(EXT_texture_array);
499 EXTRA_EXT(NV_fog_distance);
500 EXTRA_EXT(EXT_texture_filter_anisotropic);
501 EXTRA_EXT(NV_point_sprite);
502 EXTRA_EXT(NV_texture_rectangle);
503 EXTRA_EXT(EXT_stencil_two_side);
504 EXTRA_EXT(EXT_depth_bounds_test);
505 EXTRA_EXT(ARB_depth_clamp);
506 EXTRA_EXT(AMD_depth_clamp_separate);
507 EXTRA_EXT(ATI_fragment_shader);
508 EXTRA_EXT(EXT_provoking_vertex);
509 EXTRA_EXT(ARB_fragment_shader);
510 EXTRA_EXT(ARB_fragment_program);
511 EXTRA_EXT2(ARB_framebuffer_object, EXT_framebuffer_multisample);
512 EXTRA_EXT(ARB_seamless_cube_map);
513 EXTRA_EXT(ARB_sync);
514 EXTRA_EXT(ARB_vertex_shader);
515 EXTRA_EXT(EXT_transform_feedback);
516 EXTRA_EXT(ARB_transform_feedback3);
517 EXTRA_EXT(EXT_pixel_buffer_object);
518 EXTRA_EXT(ARB_vertex_program);
519 EXTRA_EXT2(NV_point_sprite, ARB_point_sprite);
520 EXTRA_EXT2(ARB_vertex_program, ARB_fragment_program);
521 EXTRA_EXT(ARB_color_buffer_float);
522 EXTRA_EXT(EXT_framebuffer_sRGB);
523 EXTRA_EXT(OES_EGL_image_external);
524 EXTRA_EXT(ARB_blend_func_extended);
525 EXTRA_EXT(ARB_uniform_buffer_object);
526 EXTRA_EXT(ARB_timer_query);
527 EXTRA_EXT2(ARB_texture_cube_map_array, OES_texture_cube_map_array);
528 EXTRA_EXT(ARB_texture_buffer_range);
529 EXTRA_EXT(ARB_texture_multisample);
530 EXTRA_EXT(ARB_texture_gather);
531 EXTRA_EXT(ARB_shader_atomic_counters);
532 EXTRA_EXT(ARB_draw_indirect);
533 EXTRA_EXT(ARB_shader_image_load_store);
534 EXTRA_EXT(ARB_query_buffer_object);
535 EXTRA_EXT2(ARB_transform_feedback3, ARB_gpu_shader5);
536 EXTRA_EXT(INTEL_performance_query);
537 EXTRA_EXT(ARB_explicit_uniform_location);
538 EXTRA_EXT(ARB_clip_control);
539 EXTRA_EXT(ARB_polygon_offset_clamp);
540 EXTRA_EXT(ARB_framebuffer_no_attachments);
541 EXTRA_EXT(ARB_tessellation_shader);
542 EXTRA_EXT(ARB_shader_storage_buffer_object);
543 EXTRA_EXT(ARB_indirect_parameters);
544 EXTRA_EXT(ATI_meminfo);
545 EXTRA_EXT(NVX_gpu_memory_info);
546 EXTRA_EXT(ARB_cull_distance);
547 EXTRA_EXT(EXT_window_rectangles);
548 EXTRA_EXT(KHR_blend_equation_advanced_coherent);
549 EXTRA_EXT(OES_primitive_bounding_box);
550 EXTRA_EXT(ARB_compute_variable_group_size);
551 EXTRA_EXT(KHR_robustness);
552 EXTRA_EXT(ARB_sparse_buffer);
553 EXTRA_EXT(NV_conservative_raster);
554 EXTRA_EXT(NV_conservative_raster_dilate);
555 EXTRA_EXT(NV_conservative_raster_pre_snap_triangles);
556 EXTRA_EXT(ARB_sample_locations);
557 EXTRA_EXT(AMD_framebuffer_multisample_advanced);
558 EXTRA_EXT(ARB_spirv_extensions);
559 EXTRA_EXT(NV_viewport_swizzle);
560
561 static const int
562 extra_ARB_color_buffer_float_or_glcore[] = {
563 EXT(ARB_color_buffer_float),
564 EXTRA_API_GL_CORE,
565 EXTRA_END
566 };
567
568 static const int
569 extra_NV_primitive_restart[] = {
570 EXT(NV_primitive_restart),
571 EXTRA_END
572 };
573
574 static const int extra_version_30[] = { EXTRA_VERSION_30, EXTRA_END };
575 static const int extra_version_31[] = { EXTRA_VERSION_31, EXTRA_END };
576 static const int extra_version_32[] = { EXTRA_VERSION_32, EXTRA_END };
577 static const int extra_version_43[] = { EXTRA_VERSION_43, EXTRA_END };
578
579 static const int extra_gl30_es3[] = {
580 EXTRA_VERSION_30,
581 EXTRA_API_ES3,
582 EXTRA_END,
583 };
584
585 static const int extra_gl32_es3[] = {
586 EXTRA_VERSION_32,
587 EXTRA_API_ES3,
588 EXTRA_END,
589 };
590
591 static const int extra_version_32_OES_geometry_shader[] = {
592 EXTRA_VERSION_32,
593 EXTRA_EXT_ES_GS,
594 EXTRA_END
595 };
596
597 static const int extra_gl40_ARB_sample_shading[] = {
598 EXTRA_VERSION_40,
599 EXT(ARB_sample_shading),
600 EXTRA_END
601 };
602
603 static const int
604 extra_ARB_vertex_program_api_es2[] = {
605 EXT(ARB_vertex_program),
606 EXTRA_API_ES2,
607 EXTRA_END
608 };
609
610 /* The ReadBuffer get token is valid under either full GL or under
611 * GLES2 if the NV_read_buffer extension is available. */
612 static const int
613 extra_NV_read_buffer_api_gl[] = {
614 EXTRA_API_ES2,
615 EXTRA_API_GL,
616 EXTRA_END
617 };
618
619 static const int extra_core_ARB_color_buffer_float_and_new_buffers[] = {
620 EXTRA_API_GL_CORE,
621 EXT(ARB_color_buffer_float),
622 EXTRA_NEW_BUFFERS,
623 EXTRA_END
624 };
625
626 static const int extra_EXT_shader_framebuffer_fetch[] = {
627 EXTRA_API_ES2,
628 EXTRA_API_ES3,
629 EXT(EXT_shader_framebuffer_fetch),
630 EXTRA_END
631 };
632
633 static const int extra_EXT_provoking_vertex_32[] = {
634 EXTRA_EXT_PROVOKING_VERTEX_32,
635 EXTRA_END
636 };
637
638 static const int extra_EXT_disjoint_timer_query[] = {
639 EXTRA_API_ES2,
640 EXTRA_API_ES3,
641 EXT(EXT_disjoint_timer_query),
642 EXTRA_END
643 };
644
645
646 /* This is the big table describing all the enums we accept in
647 * glGet*v(). The table is partitioned into six parts: enums
648 * understood by all GL APIs (OpenGL, GLES and GLES2), enums shared
649 * between OpenGL and GLES, enums exclusive to GLES, etc for the
650 * remaining combinations. To look up the enums valid in a given API
651 * we will use a hash table specific to that API. These tables are in
652 * turn generated at build time and included through get_hash.h.
653 */
654
655 #include "get_hash.h"
656
657 /* All we need now is a way to look up the value struct from the enum.
658 * The code generated by gcc for the old generated big switch
659 * statement is a big, balanced, open coded if/else tree, essentially
660 * an unrolled binary search. It would be natural to sort the new
661 * enum table and use bsearch(), but we will use a read-only hash
662 * table instead. bsearch() has a nice guaranteed worst case
663 * performance, but we're also guaranteed to hit that worst case
664 * (log2(n) iterations) for about half the enums. Instead, using an
665 * open addressing hash table, we can find the enum on the first try
666 * for 80% of the enums, 1 collision for 10% and never more than 5
667 * collisions for any enum (typical numbers). And the code is very
668 * simple, even though it feels a little magic. */
669
670 /**
671 * Handle irregular enums
672 *
673 * Some values don't conform to the "well-known type at context
674 * pointer + offset" pattern, so we have this function to catch all
675 * the corner cases. Typically, it's a computed value or a one-off
676 * pointer to a custom struct or something.
677 *
678 * In this case we can't return a pointer to the value, so we'll have
679 * to use the temporary variable 'v' declared back in the calling
680 * glGet*v() function to store the result.
681 *
682 * \param ctx the current context
683 * \param d the struct value_desc that describes the enum
684 * \param v pointer to the tmp declared in the calling glGet*v() function
685 */
686 static void
find_custom_value(struct gl_context * ctx,const struct value_desc * d,union value * v)687 find_custom_value(struct gl_context *ctx, const struct value_desc *d, union value *v)
688 {
689 struct gl_buffer_object **buffer_obj, *buf;
690 struct gl_array_attributes *array;
691 GLuint unit, *p;
692
693 switch (d->pname) {
694 case GL_MAJOR_VERSION:
695 v->value_int = ctx->Version / 10;
696 break;
697 case GL_MINOR_VERSION:
698 v->value_int = ctx->Version % 10;
699 break;
700
701 case GL_TEXTURE_1D:
702 case GL_TEXTURE_2D:
703 case GL_TEXTURE_3D:
704 case GL_TEXTURE_CUBE_MAP:
705 case GL_TEXTURE_RECTANGLE_NV:
706 case GL_TEXTURE_EXTERNAL_OES:
707 v->value_bool = _mesa_IsEnabled(d->pname);
708 break;
709
710 case GL_LINE_STIPPLE_PATTERN:
711 /* This is the only GLushort, special case it here by promoting
712 * to an int rather than introducing a new type. */
713 v->value_int = ctx->Line.StipplePattern;
714 break;
715
716 case GL_CURRENT_RASTER_TEXTURE_COORDS:
717 unit = ctx->Texture.CurrentUnit;
718 v->value_float_4[0] = ctx->Current.RasterTexCoords[unit][0];
719 v->value_float_4[1] = ctx->Current.RasterTexCoords[unit][1];
720 v->value_float_4[2] = ctx->Current.RasterTexCoords[unit][2];
721 v->value_float_4[3] = ctx->Current.RasterTexCoords[unit][3];
722 break;
723
724 case GL_CURRENT_TEXTURE_COORDS:
725 unit = ctx->Texture.CurrentUnit;
726 v->value_float_4[0] = ctx->Current.Attrib[VERT_ATTRIB_TEX0 + unit][0];
727 v->value_float_4[1] = ctx->Current.Attrib[VERT_ATTRIB_TEX0 + unit][1];
728 v->value_float_4[2] = ctx->Current.Attrib[VERT_ATTRIB_TEX0 + unit][2];
729 v->value_float_4[3] = ctx->Current.Attrib[VERT_ATTRIB_TEX0 + unit][3];
730 break;
731
732 case GL_COLOR_WRITEMASK:
733 v->value_int_4[0] = GET_COLORMASK_BIT(ctx->Color.ColorMask, 0, 0);
734 v->value_int_4[1] = GET_COLORMASK_BIT(ctx->Color.ColorMask, 0, 1);
735 v->value_int_4[2] = GET_COLORMASK_BIT(ctx->Color.ColorMask, 0, 2);
736 v->value_int_4[3] = GET_COLORMASK_BIT(ctx->Color.ColorMask, 0, 3);
737 break;
738
739 case GL_DEPTH_CLAMP:
740 v->value_bool = ctx->Transform.DepthClampNear || ctx->Transform.DepthClampFar;
741 break;
742
743 case GL_EDGE_FLAG:
744 v->value_bool = ctx->Current.Attrib[VERT_ATTRIB_EDGEFLAG][0] == 1.0F;
745 break;
746
747 case GL_READ_BUFFER:
748 v->value_enum16 = ctx->ReadBuffer->ColorReadBuffer;
749 break;
750
751 case GL_MAP2_GRID_DOMAIN:
752 v->value_float_4[0] = ctx->Eval.MapGrid2u1;
753 v->value_float_4[1] = ctx->Eval.MapGrid2u2;
754 v->value_float_4[2] = ctx->Eval.MapGrid2v1;
755 v->value_float_4[3] = ctx->Eval.MapGrid2v2;
756 break;
757
758 case GL_TEXTURE_STACK_DEPTH:
759 unit = ctx->Texture.CurrentUnit;
760 v->value_int = ctx->TextureMatrixStack[unit].Depth + 1;
761 break;
762 case GL_TEXTURE_MATRIX:
763 unit = ctx->Texture.CurrentUnit;
764 v->value_matrix = ctx->TextureMatrixStack[unit].Top;
765 break;
766
767 case GL_VERTEX_ARRAY:
768 v->value_bool = !!(ctx->Array.VAO->Enabled & VERT_BIT_POS);
769 break;
770 case GL_NORMAL_ARRAY:
771 v->value_bool = !!(ctx->Array.VAO->Enabled & VERT_BIT_NORMAL);
772 break;
773 case GL_COLOR_ARRAY:
774 v->value_bool = !!(ctx->Array.VAO->Enabled & VERT_BIT_COLOR0);
775 break;
776 case GL_TEXTURE_COORD_ARRAY:
777 v->value_bool = !!(ctx->Array.VAO->Enabled & VERT_BIT_TEX(ctx->Array.ActiveTexture));
778 break;
779 case GL_INDEX_ARRAY:
780 v->value_bool = !!(ctx->Array.VAO->Enabled & VERT_BIT_COLOR_INDEX);
781 break;
782 case GL_EDGE_FLAG_ARRAY:
783 v->value_bool = !!(ctx->Array.VAO->Enabled & VERT_BIT_EDGEFLAG);
784 break;
785 case GL_SECONDARY_COLOR_ARRAY:
786 v->value_bool = !!(ctx->Array.VAO->Enabled & VERT_BIT_COLOR1);
787 break;
788 case GL_FOG_COORDINATE_ARRAY:
789 v->value_bool = !!(ctx->Array.VAO->Enabled & VERT_BIT_FOG);
790 break;
791 case GL_POINT_SIZE_ARRAY_OES:
792 v->value_bool = !!(ctx->Array.VAO->Enabled & VERT_BIT_POINT_SIZE);
793 break;
794
795 case GL_TEXTURE_COORD_ARRAY_TYPE:
796 case GL_TEXTURE_COORD_ARRAY_STRIDE:
797 array = &ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_TEX(ctx->Array.ActiveTexture)];
798 v->value_int = *(GLuint *) ((char *) array + d->offset);
799 break;
800
801 case GL_TEXTURE_COORD_ARRAY_SIZE:
802 array = &ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_TEX(ctx->Array.ActiveTexture)];
803 v->value_int = array->Format.Size;
804 break;
805
806 case GL_VERTEX_ARRAY_SIZE:
807 array = &ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_POS];
808 v->value_int = array->Format.Size;
809 break;
810
811 case GL_ACTIVE_TEXTURE_ARB:
812 v->value_int = GL_TEXTURE0_ARB + ctx->Texture.CurrentUnit;
813 break;
814 case GL_CLIENT_ACTIVE_TEXTURE_ARB:
815 v->value_int = GL_TEXTURE0_ARB + ctx->Array.ActiveTexture;
816 break;
817
818 case GL_MODELVIEW_STACK_DEPTH:
819 case GL_PROJECTION_STACK_DEPTH:
820 v->value_int = *(GLint *) ((char *) ctx + d->offset) + 1;
821 break;
822
823 case GL_MAX_TEXTURE_SIZE:
824 case GL_MAX_3D_TEXTURE_SIZE:
825 case GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB:
826 p = (GLuint *) ((char *) ctx + d->offset);
827 v->value_int = 1 << (*p - 1);
828 break;
829
830 case GL_SCISSOR_BOX:
831 v->value_int_4[0] = ctx->Scissor.ScissorArray[0].X;
832 v->value_int_4[1] = ctx->Scissor.ScissorArray[0].Y;
833 v->value_int_4[2] = ctx->Scissor.ScissorArray[0].Width;
834 v->value_int_4[3] = ctx->Scissor.ScissorArray[0].Height;
835 break;
836
837 case GL_SCISSOR_TEST:
838 v->value_bool = ctx->Scissor.EnableFlags & 1;
839 break;
840
841 case GL_LIST_INDEX:
842 v->value_int =
843 ctx->ListState.CurrentList ? ctx->ListState.CurrentList->Name : 0;
844 break;
845 case GL_LIST_MODE:
846 if (!ctx->CompileFlag)
847 v->value_enum16 = 0;
848 else if (ctx->ExecuteFlag)
849 v->value_enum16 = GL_COMPILE_AND_EXECUTE;
850 else
851 v->value_enum16 = GL_COMPILE;
852 break;
853
854 case GL_VIEWPORT:
855 v->value_float_4[0] = ctx->ViewportArray[0].X;
856 v->value_float_4[1] = ctx->ViewportArray[0].Y;
857 v->value_float_4[2] = ctx->ViewportArray[0].Width;
858 v->value_float_4[3] = ctx->ViewportArray[0].Height;
859 break;
860
861 case GL_DEPTH_RANGE:
862 v->value_double_2[0] = ctx->ViewportArray[0].Near;
863 v->value_double_2[1] = ctx->ViewportArray[0].Far;
864 break;
865
866 case GL_ACTIVE_STENCIL_FACE_EXT:
867 v->value_enum16 = ctx->Stencil.ActiveFace ? GL_BACK : GL_FRONT;
868 break;
869
870 case GL_STENCIL_FAIL:
871 v->value_enum16 = ctx->Stencil.FailFunc[ctx->Stencil.ActiveFace];
872 break;
873 case GL_STENCIL_FUNC:
874 v->value_enum16 = ctx->Stencil.Function[ctx->Stencil.ActiveFace];
875 break;
876 case GL_STENCIL_PASS_DEPTH_FAIL:
877 v->value_enum16 = ctx->Stencil.ZFailFunc[ctx->Stencil.ActiveFace];
878 break;
879 case GL_STENCIL_PASS_DEPTH_PASS:
880 v->value_enum16 = ctx->Stencil.ZPassFunc[ctx->Stencil.ActiveFace];
881 break;
882 case GL_STENCIL_REF:
883 v->value_int = _mesa_get_stencil_ref(ctx, ctx->Stencil.ActiveFace);
884 break;
885 case GL_STENCIL_BACK_REF:
886 v->value_int = _mesa_get_stencil_ref(ctx, 1);
887 break;
888 case GL_STENCIL_VALUE_MASK:
889 v->value_int = ctx->Stencil.ValueMask[ctx->Stencil.ActiveFace];
890 break;
891 case GL_STENCIL_WRITEMASK:
892 v->value_int = ctx->Stencil.WriteMask[ctx->Stencil.ActiveFace];
893 break;
894
895 case GL_NUM_EXTENSIONS:
896 v->value_int = _mesa_get_extension_count(ctx);
897 break;
898
899 case GL_IMPLEMENTATION_COLOR_READ_TYPE_OES:
900 v->value_int = _mesa_get_color_read_type(ctx, NULL, "glGetIntegerv");
901 break;
902 case GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES:
903 v->value_int = _mesa_get_color_read_format(ctx, NULL, "glGetIntegerv");
904 break;
905
906 case GL_CURRENT_MATRIX_STACK_DEPTH_ARB:
907 v->value_int = ctx->CurrentStack->Depth + 1;
908 break;
909 case GL_CURRENT_MATRIX_ARB:
910 case GL_TRANSPOSE_CURRENT_MATRIX_ARB:
911 v->value_matrix = ctx->CurrentStack->Top;
912 break;
913
914 case GL_NUM_COMPRESSED_TEXTURE_FORMATS_ARB:
915 v->value_int = _mesa_get_compressed_formats(ctx, NULL);
916 break;
917 case GL_COMPRESSED_TEXTURE_FORMATS_ARB:
918 v->value_int_n.n =
919 _mesa_get_compressed_formats(ctx, v->value_int_n.ints);
920 assert(v->value_int_n.n <= (int) ARRAY_SIZE(v->value_int_n.ints));
921 break;
922
923 case GL_MAX_VARYING_FLOATS_ARB:
924 v->value_int = ctx->Const.MaxVarying * 4;
925 break;
926
927 /* Various object names */
928
929 case GL_TEXTURE_BINDING_1D:
930 case GL_TEXTURE_BINDING_2D:
931 case GL_TEXTURE_BINDING_3D:
932 case GL_TEXTURE_BINDING_1D_ARRAY_EXT:
933 case GL_TEXTURE_BINDING_2D_ARRAY_EXT:
934 case GL_TEXTURE_BINDING_CUBE_MAP_ARB:
935 case GL_TEXTURE_BINDING_RECTANGLE_NV:
936 case GL_TEXTURE_BINDING_EXTERNAL_OES:
937 case GL_TEXTURE_BINDING_CUBE_MAP_ARRAY:
938 case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
939 case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY:
940 unit = ctx->Texture.CurrentUnit;
941 v->value_int =
942 ctx->Texture.Unit[unit].CurrentTex[d->offset]->Name;
943 break;
944
945 /* GL_EXT_external_objects */
946 case GL_NUM_DEVICE_UUIDS_EXT:
947 v->value_int = 1;
948 break;
949 case GL_DRIVER_UUID_EXT:
950 _mesa_get_driver_uuid(ctx, v->value_int_4);
951 break;
952 case GL_DEVICE_UUID_EXT:
953 _mesa_get_device_uuid(ctx, v->value_int_4);
954 break;
955
956 /* GL_EXT_packed_float */
957 case GL_RGBA_SIGNED_COMPONENTS_EXT:
958 {
959 /* Note: we only check the 0th color attachment. */
960 const struct gl_renderbuffer *rb =
961 ctx->DrawBuffer->_ColorDrawBuffers[0];
962 if (rb && _mesa_is_format_signed(rb->Format)) {
963 /* Issue 17 of GL_EXT_packed_float: If a component (such as
964 * alpha) has zero bits, the component should not be considered
965 * signed and so the bit for the respective component should be
966 * zeroed.
967 */
968 GLint r_bits =
969 _mesa_get_format_bits(rb->Format, GL_RED_BITS);
970 GLint g_bits =
971 _mesa_get_format_bits(rb->Format, GL_GREEN_BITS);
972 GLint b_bits =
973 _mesa_get_format_bits(rb->Format, GL_BLUE_BITS);
974 GLint a_bits =
975 _mesa_get_format_bits(rb->Format, GL_ALPHA_BITS);
976 GLint l_bits =
977 _mesa_get_format_bits(rb->Format, GL_TEXTURE_LUMINANCE_SIZE);
978 GLint i_bits =
979 _mesa_get_format_bits(rb->Format, GL_TEXTURE_INTENSITY_SIZE);
980
981 v->value_int_4[0] = r_bits + l_bits + i_bits > 0;
982 v->value_int_4[1] = g_bits + l_bits + i_bits > 0;
983 v->value_int_4[2] = b_bits + l_bits + i_bits > 0;
984 v->value_int_4[3] = a_bits + i_bits > 0;
985 }
986 else {
987 v->value_int_4[0] =
988 v->value_int_4[1] =
989 v->value_int_4[2] =
990 v->value_int_4[3] = 0;
991 }
992 }
993 break;
994
995 /* GL_ARB_vertex_buffer_object */
996 case GL_VERTEX_ARRAY_BUFFER_BINDING_ARB:
997 case GL_NORMAL_ARRAY_BUFFER_BINDING_ARB:
998 case GL_COLOR_ARRAY_BUFFER_BINDING_ARB:
999 case GL_INDEX_ARRAY_BUFFER_BINDING_ARB:
1000 case GL_EDGE_FLAG_ARRAY_BUFFER_BINDING_ARB:
1001 case GL_SECONDARY_COLOR_ARRAY_BUFFER_BINDING_ARB:
1002 case GL_FOG_COORDINATE_ARRAY_BUFFER_BINDING_ARB:
1003 buffer_obj = (struct gl_buffer_object **)
1004 ((char *) ctx->Array.VAO + d->offset);
1005 v->value_int = (*buffer_obj) ? (*buffer_obj)->Name : 0;
1006 break;
1007 case GL_ARRAY_BUFFER_BINDING_ARB:
1008 buf = ctx->Array.ArrayBufferObj;
1009 v->value_int = buf ? buf->Name : 0;
1010 break;
1011 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING_ARB:
1012 buf = ctx->Array.VAO->BufferBinding[VERT_ATTRIB_TEX(ctx->Array.ActiveTexture)].BufferObj;
1013 v->value_int = buf ? buf->Name : 0;
1014 break;
1015 case GL_ELEMENT_ARRAY_BUFFER_BINDING_ARB:
1016 buf = ctx->Array.VAO->IndexBufferObj;
1017 v->value_int = buf ? buf->Name : 0;
1018 break;
1019
1020 /* ARB_vertex_array_bgra */
1021 case GL_COLOR_ARRAY_SIZE:
1022 array = &ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_COLOR0];
1023 v->value_int = array->Format.Format == GL_BGRA ? GL_BGRA : array->Format.Size;
1024 break;
1025 case GL_SECONDARY_COLOR_ARRAY_SIZE:
1026 array = &ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_COLOR1];
1027 v->value_int = array->Format.Format == GL_BGRA ? GL_BGRA : array->Format.Size;
1028 break;
1029
1030 /* ARB_copy_buffer */
1031 case GL_COPY_READ_BUFFER:
1032 v->value_int = ctx->CopyReadBuffer ? ctx->CopyReadBuffer->Name : 0;
1033 break;
1034 case GL_COPY_WRITE_BUFFER:
1035 v->value_int = ctx->CopyWriteBuffer ? ctx->CopyWriteBuffer->Name : 0;
1036 break;
1037
1038 case GL_PIXEL_PACK_BUFFER_BINDING_EXT:
1039 v->value_int = ctx->Pack.BufferObj ? ctx->Pack.BufferObj->Name : 0;
1040 break;
1041 case GL_PIXEL_UNPACK_BUFFER_BINDING_EXT:
1042 v->value_int = ctx->Unpack.BufferObj ? ctx->Unpack.BufferObj->Name : 0;
1043 break;
1044 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
1045 v->value_int = ctx->TransformFeedback.CurrentBuffer ?
1046 ctx->TransformFeedback.CurrentBuffer->Name : 0;
1047 break;
1048 case GL_TRANSFORM_FEEDBACK_BUFFER_PAUSED:
1049 v->value_int = ctx->TransformFeedback.CurrentObject->Paused;
1050 break;
1051 case GL_TRANSFORM_FEEDBACK_BUFFER_ACTIVE:
1052 v->value_int = ctx->TransformFeedback.CurrentObject->Active;
1053 break;
1054 case GL_TRANSFORM_FEEDBACK_BINDING:
1055 v->value_int = ctx->TransformFeedback.CurrentObject->Name;
1056 break;
1057 case GL_CURRENT_PROGRAM:
1058 /* The Changelog of the ARB_separate_shader_objects spec says:
1059 *
1060 * 24 25 Jul 2011 pbrown Remove the language erroneously deleting
1061 * CURRENT_PROGRAM. In the EXT extension, this
1062 * token was aliased to ACTIVE_PROGRAM_EXT, and
1063 * was used to indicate the last program set by
1064 * either ActiveProgramEXT or UseProgram. In
1065 * the ARB extension, the SSO active programs
1066 * are now program pipeline object state and
1067 * CURRENT_PROGRAM should still be used to query
1068 * the last program set by UseProgram (bug 7822).
1069 */
1070 v->value_int =
1071 ctx->Shader.ActiveProgram ? ctx->Shader.ActiveProgram->Name : 0;
1072 break;
1073 case GL_READ_FRAMEBUFFER_BINDING_EXT:
1074 v->value_int = ctx->ReadBuffer->Name;
1075 break;
1076 case GL_RENDERBUFFER_BINDING_EXT:
1077 v->value_int =
1078 ctx->CurrentRenderbuffer ? ctx->CurrentRenderbuffer->Name : 0;
1079 break;
1080 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
1081 buf = ctx->Array.VAO->BufferBinding[VERT_ATTRIB_POINT_SIZE].BufferObj;
1082 v->value_int = buf ? buf->Name : 0;
1083 break;
1084
1085 case GL_FOG_COLOR:
1086 if (_mesa_get_clamp_fragment_color(ctx, ctx->DrawBuffer))
1087 COPY_4FV(v->value_float_4, ctx->Fog.Color);
1088 else
1089 COPY_4FV(v->value_float_4, ctx->Fog.ColorUnclamped);
1090 break;
1091 case GL_COLOR_CLEAR_VALUE:
1092 if (_mesa_get_clamp_fragment_color(ctx, ctx->DrawBuffer)) {
1093 v->value_float_4[0] = CLAMP(ctx->Color.ClearColor.f[0], 0.0F, 1.0F);
1094 v->value_float_4[1] = CLAMP(ctx->Color.ClearColor.f[1], 0.0F, 1.0F);
1095 v->value_float_4[2] = CLAMP(ctx->Color.ClearColor.f[2], 0.0F, 1.0F);
1096 v->value_float_4[3] = CLAMP(ctx->Color.ClearColor.f[3], 0.0F, 1.0F);
1097 } else
1098 COPY_4FV(v->value_float_4, ctx->Color.ClearColor.f);
1099 break;
1100 case GL_BLEND_COLOR_EXT:
1101 if (_mesa_get_clamp_fragment_color(ctx, ctx->DrawBuffer))
1102 COPY_4FV(v->value_float_4, ctx->Color.BlendColor);
1103 else
1104 COPY_4FV(v->value_float_4, ctx->Color.BlendColorUnclamped);
1105 break;
1106 case GL_ALPHA_TEST_REF:
1107 if (_mesa_get_clamp_fragment_color(ctx, ctx->DrawBuffer))
1108 v->value_float = ctx->Color.AlphaRef;
1109 else
1110 v->value_float = ctx->Color.AlphaRefUnclamped;
1111 break;
1112 case GL_MAX_VERTEX_UNIFORM_VECTORS:
1113 v->value_int = ctx->Const.Program[MESA_SHADER_VERTEX].MaxUniformComponents / 4;
1114 break;
1115
1116 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
1117 v->value_int = ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxUniformComponents / 4;
1118 break;
1119
1120 /* GL_ARB_texture_buffer_object */
1121 case GL_TEXTURE_BUFFER_ARB:
1122 v->value_int = ctx->Texture.BufferObject ? ctx->Texture.BufferObject->Name : 0;
1123 break;
1124 case GL_TEXTURE_BINDING_BUFFER_ARB:
1125 unit = ctx->Texture.CurrentUnit;
1126 v->value_int =
1127 ctx->Texture.Unit[unit].CurrentTex[TEXTURE_BUFFER_INDEX]->Name;
1128 break;
1129 case GL_TEXTURE_BUFFER_DATA_STORE_BINDING_ARB:
1130 {
1131 struct gl_buffer_object *buf =
1132 ctx->Texture.Unit[ctx->Texture.CurrentUnit]
1133 .CurrentTex[TEXTURE_BUFFER_INDEX]->BufferObject;
1134 v->value_int = buf ? buf->Name : 0;
1135 }
1136 break;
1137 case GL_TEXTURE_BUFFER_FORMAT_ARB:
1138 v->value_int = ctx->Texture.Unit[ctx->Texture.CurrentUnit]
1139 .CurrentTex[TEXTURE_BUFFER_INDEX]->BufferObjectFormat;
1140 break;
1141
1142 /* GL_ARB_sampler_objects */
1143 case GL_SAMPLER_BINDING:
1144 {
1145 struct gl_sampler_object *samp =
1146 ctx->Texture.Unit[ctx->Texture.CurrentUnit].Sampler;
1147 v->value_int = samp ? samp->Name : 0;
1148 }
1149 break;
1150 /* GL_ARB_uniform_buffer_object */
1151 case GL_UNIFORM_BUFFER_BINDING:
1152 v->value_int = ctx->UniformBuffer ? ctx->UniformBuffer->Name : 0;
1153 break;
1154 /* GL_ARB_shader_storage_buffer_object */
1155 case GL_SHADER_STORAGE_BUFFER_BINDING:
1156 v->value_int = ctx->ShaderStorageBuffer ? ctx->ShaderStorageBuffer->Name : 0;
1157 break;
1158 /* GL_ARB_query_buffer_object */
1159 case GL_QUERY_BUFFER_BINDING:
1160 v->value_int = ctx->QueryBuffer ? ctx->QueryBuffer->Name : 0;
1161 break;
1162 /* GL_ARB_timer_query */
1163 case GL_TIMESTAMP:
1164 if (ctx->Driver.GetTimestamp) {
1165 v->value_int64 = ctx->Driver.GetTimestamp(ctx);
1166 }
1167 else {
1168 _mesa_problem(ctx, "driver doesn't implement GetTimestamp");
1169 }
1170 break;
1171 /* GL_KHR_DEBUG */
1172 case GL_DEBUG_OUTPUT:
1173 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
1174 case GL_DEBUG_LOGGED_MESSAGES:
1175 case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH:
1176 case GL_DEBUG_GROUP_STACK_DEPTH:
1177 v->value_int = _mesa_get_debug_state_int(ctx, d->pname);
1178 break;
1179 /* GL_ARB_shader_atomic_counters */
1180 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
1181 v->value_int = ctx->AtomicBuffer ? ctx->AtomicBuffer->Name : 0;
1182 break;
1183 /* GL 4.3 */
1184 case GL_NUM_SHADING_LANGUAGE_VERSIONS:
1185 v->value_int = _mesa_get_shading_language_version(ctx, -1, NULL);
1186 break;
1187 /* GL_ARB_draw_indirect */
1188 case GL_DRAW_INDIRECT_BUFFER_BINDING:
1189 v->value_int = ctx->DrawIndirectBuffer ? ctx->DrawIndirectBuffer->Name: 0;
1190 break;
1191 /* GL_ARB_indirect_parameters */
1192 case GL_PARAMETER_BUFFER_BINDING_ARB:
1193 v->value_int = ctx->ParameterBuffer ? ctx->ParameterBuffer->Name : 0;
1194 break;
1195 /* GL_ARB_separate_shader_objects */
1196 case GL_PROGRAM_PIPELINE_BINDING:
1197 if (ctx->Pipeline.Current) {
1198 v->value_int = ctx->Pipeline.Current->Name;
1199 } else {
1200 v->value_int = 0;
1201 }
1202 break;
1203 /* GL_ARB_compute_shader */
1204 case GL_DISPATCH_INDIRECT_BUFFER_BINDING:
1205 v->value_int = ctx->DispatchIndirectBuffer ?
1206 ctx->DispatchIndirectBuffer->Name : 0;
1207 break;
1208 /* GL_ARB_multisample */
1209 case GL_SAMPLES:
1210 v->value_int = _mesa_geometric_samples(ctx->DrawBuffer);
1211 break;
1212 case GL_SAMPLE_BUFFERS:
1213 v->value_int = _mesa_geometric_samples(ctx->DrawBuffer) > 0;
1214 break;
1215 /* GL_EXT_textrue_integer */
1216 case GL_RGBA_INTEGER_MODE_EXT:
1217 v->value_int = (ctx->DrawBuffer->_IntegerBuffers != 0);
1218 break;
1219 /* GL_ATI_meminfo & GL_NVX_gpu_memory_info */
1220 case GL_VBO_FREE_MEMORY_ATI:
1221 case GL_TEXTURE_FREE_MEMORY_ATI:
1222 case GL_RENDERBUFFER_FREE_MEMORY_ATI:
1223 case GL_GPU_MEMORY_INFO_DEDICATED_VIDMEM_NVX:
1224 case GL_GPU_MEMORY_INFO_TOTAL_AVAILABLE_MEMORY_NVX:
1225 case GL_GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX:
1226 case GL_GPU_MEMORY_INFO_EVICTION_COUNT_NVX:
1227 case GL_GPU_MEMORY_INFO_EVICTED_MEMORY_NVX:
1228 {
1229 struct gl_memory_info info;
1230
1231 ctx->Driver.QueryMemoryInfo(ctx, &info);
1232
1233 if (d->pname == GL_GPU_MEMORY_INFO_DEDICATED_VIDMEM_NVX)
1234 v->value_int = info.total_device_memory;
1235 else if (d->pname == GL_GPU_MEMORY_INFO_TOTAL_AVAILABLE_MEMORY_NVX)
1236 v->value_int = info.total_device_memory +
1237 info.total_staging_memory;
1238 else if (d->pname == GL_GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX)
1239 v->value_int = info.avail_device_memory;
1240 else if (d->pname == GL_GPU_MEMORY_INFO_EVICTION_COUNT_NVX)
1241 v->value_int = info.nr_device_memory_evictions;
1242 else if (d->pname == GL_GPU_MEMORY_INFO_EVICTED_MEMORY_NVX)
1243 v->value_int = info.device_memory_evicted;
1244 else {
1245 /* ATI free memory enums.
1246 *
1247 * Since the GPU memory is (usually) page-table based, every two
1248 * consecutive elements are equal. From the GL_ATI_meminfo
1249 * specification:
1250 *
1251 * "param[0] - total memory free in the pool
1252 * param[1] - largest available free block in the pool
1253 * param[2] - total auxiliary memory free
1254 * param[3] - largest auxiliary free block"
1255 *
1256 * All three (VBO, TEXTURE, RENDERBUFFER) queries return
1257 * the same numbers here.
1258 */
1259 v->value_int_4[0] = info.avail_device_memory;
1260 v->value_int_4[1] = info.avail_device_memory;
1261 v->value_int_4[2] = info.avail_staging_memory;
1262 v->value_int_4[3] = info.avail_staging_memory;
1263 }
1264 }
1265 break;
1266
1267 /* GL_ARB_get_program_binary */
1268 case GL_PROGRAM_BINARY_FORMATS:
1269 assert(ctx->Const.NumProgramBinaryFormats <= 1);
1270 v->value_int_n.n = MIN2(ctx->Const.NumProgramBinaryFormats, 1);
1271 if (ctx->Const.NumProgramBinaryFormats > 0) {
1272 v->value_int_n.ints[0] = GL_PROGRAM_BINARY_FORMAT_MESA;
1273 }
1274 break;
1275 /* ARB_spirv_extensions */
1276 case GL_NUM_SPIR_V_EXTENSIONS:
1277 v->value_int = _mesa_get_spirv_extension_count(ctx);
1278 break;
1279 /* GL_EXT_disjoint_timer_query */
1280 case GL_GPU_DISJOINT_EXT:
1281 {
1282 simple_mtx_lock(&ctx->Shared->Mutex);
1283 v->value_int = ctx->Shared->DisjointOperation;
1284 /* Reset state as expected by the spec. */
1285 ctx->Shared->DisjointOperation = false;
1286 simple_mtx_unlock(&ctx->Shared->Mutex);
1287 }
1288 break;
1289 /* GL_ARB_sample_locations */
1290 case GL_SAMPLE_LOCATION_SUBPIXEL_BITS_ARB:
1291 case GL_SAMPLE_LOCATION_PIXEL_GRID_WIDTH_ARB:
1292 case GL_SAMPLE_LOCATION_PIXEL_GRID_HEIGHT_ARB:
1293 {
1294 GLuint bits, width, height;
1295
1296 if (ctx->NewState & _NEW_BUFFERS)
1297 _mesa_update_state(ctx);
1298
1299 if (ctx->DrawBuffer->_Status != GL_FRAMEBUFFER_COMPLETE) {
1300 v->value_uint = 0;
1301 break;
1302 }
1303
1304 ctx->Driver.GetProgrammableSampleCaps(ctx, ctx->DrawBuffer,
1305 &bits, &width, &height);
1306
1307 if (d->pname == GL_SAMPLE_LOCATION_PIXEL_GRID_WIDTH_ARB)
1308 v->value_uint = width;
1309 else if (d->pname == GL_SAMPLE_LOCATION_PIXEL_GRID_HEIGHT_ARB)
1310 v->value_uint = height;
1311 else
1312 v->value_uint = bits;
1313 }
1314 break;
1315 case GL_PROGRAMMABLE_SAMPLE_LOCATION_TABLE_SIZE_ARB:
1316 v->value_uint = MAX_SAMPLE_LOCATION_TABLE_SIZE;
1317 break;
1318
1319 /* GL_AMD_framebuffer_multisample_advanced */
1320 case GL_SUPPORTED_MULTISAMPLE_MODES_AMD:
1321 v->value_int_n.n = ctx->Const.NumSupportedMultisampleModes * 3;
1322 memcpy(v->value_int_n.ints, ctx->Const.SupportedMultisampleModes,
1323 v->value_int_n.n * sizeof(GLint));
1324 break;
1325
1326 /* GL_NV_viewport_swizzle */
1327 case GL_VIEWPORT_SWIZZLE_X_NV:
1328 v->value_enum = ctx->ViewportArray[0].SwizzleX;
1329 break;
1330 case GL_VIEWPORT_SWIZZLE_Y_NV:
1331 v->value_enum = ctx->ViewportArray[0].SwizzleY;
1332 break;
1333 case GL_VIEWPORT_SWIZZLE_Z_NV:
1334 v->value_enum = ctx->ViewportArray[0].SwizzleZ;
1335 break;
1336 case GL_VIEWPORT_SWIZZLE_W_NV:
1337 v->value_enum = ctx->ViewportArray[0].SwizzleW;
1338 break;
1339 }
1340 }
1341
1342 /**
1343 * Check extra constraints on a struct value_desc descriptor
1344 *
1345 * If a struct value_desc has a non-NULL extra pointer, it means that
1346 * there are a number of extra constraints to check or actions to
1347 * perform. The extras is just an integer array where each integer
1348 * encode different constraints or actions.
1349 *
1350 * \param ctx current context
1351 * \param func name of calling glGet*v() function for error reporting
1352 * \param d the struct value_desc that has the extra constraints
1353 *
1354 * \return GL_FALSE if all of the constraints were not satisfied,
1355 * otherwise GL_TRUE.
1356 */
1357 static GLboolean
check_extra(struct gl_context * ctx,const char * func,const struct value_desc * d)1358 check_extra(struct gl_context *ctx, const char *func, const struct value_desc *d)
1359 {
1360 const GLuint version = ctx->Version;
1361 GLboolean api_check = GL_FALSE;
1362 GLboolean api_found = GL_FALSE;
1363 const int *e;
1364
1365 for (e = d->extra; *e != EXTRA_END; e++) {
1366 switch (*e) {
1367 case EXTRA_VERSION_30:
1368 api_check = GL_TRUE;
1369 if (version >= 30)
1370 api_found = GL_TRUE;
1371 break;
1372 case EXTRA_VERSION_31:
1373 api_check = GL_TRUE;
1374 if (version >= 31)
1375 api_found = GL_TRUE;
1376 break;
1377 case EXTRA_VERSION_32:
1378 api_check = GL_TRUE;
1379 if (version >= 32)
1380 api_found = GL_TRUE;
1381 break;
1382 case EXTRA_VERSION_40:
1383 api_check = GL_TRUE;
1384 if (version >= 40)
1385 api_found = GL_TRUE;
1386 break;
1387 case EXTRA_VERSION_43:
1388 api_check = GL_TRUE;
1389 if (_mesa_is_desktop_gl(ctx) && version >= 43)
1390 api_found = GL_TRUE;
1391 break;
1392 case EXTRA_API_ES2:
1393 api_check = GL_TRUE;
1394 if (ctx->API == API_OPENGLES2)
1395 api_found = GL_TRUE;
1396 break;
1397 case EXTRA_API_ES3:
1398 api_check = GL_TRUE;
1399 if (_mesa_is_gles3(ctx))
1400 api_found = GL_TRUE;
1401 break;
1402 case EXTRA_API_ES31:
1403 api_check = GL_TRUE;
1404 if (_mesa_is_gles31(ctx))
1405 api_found = GL_TRUE;
1406 break;
1407 case EXTRA_API_ES32:
1408 api_check = GL_TRUE;
1409 if (_mesa_is_gles32(ctx))
1410 api_found = GL_TRUE;
1411 break;
1412 case EXTRA_API_GL:
1413 api_check = GL_TRUE;
1414 if (_mesa_is_desktop_gl(ctx))
1415 api_found = GL_TRUE;
1416 break;
1417 case EXTRA_API_GL_CORE:
1418 api_check = GL_TRUE;
1419 if (ctx->API == API_OPENGL_CORE)
1420 api_found = GL_TRUE;
1421 break;
1422 case EXTRA_NEW_BUFFERS:
1423 if (ctx->NewState & _NEW_BUFFERS)
1424 _mesa_update_state(ctx);
1425 break;
1426 case EXTRA_FLUSH_CURRENT:
1427 FLUSH_CURRENT(ctx, 0);
1428 break;
1429 case EXTRA_VALID_DRAW_BUFFER:
1430 if (d->pname - GL_DRAW_BUFFER0_ARB >= ctx->Const.MaxDrawBuffers) {
1431 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(draw buffer %u)",
1432 func, d->pname - GL_DRAW_BUFFER0_ARB);
1433 return GL_FALSE;
1434 }
1435 break;
1436 case EXTRA_VALID_TEXTURE_UNIT:
1437 if (ctx->Texture.CurrentUnit >= ctx->Const.MaxTextureCoordUnits) {
1438 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(texture %u)",
1439 func, ctx->Texture.CurrentUnit);
1440 return GL_FALSE;
1441 }
1442 break;
1443 case EXTRA_VALID_CLIP_DISTANCE:
1444 if (d->pname - GL_CLIP_DISTANCE0 >= ctx->Const.MaxClipPlanes) {
1445 _mesa_error(ctx, GL_INVALID_ENUM, "%s(clip distance %u)",
1446 func, d->pname - GL_CLIP_DISTANCE0);
1447 return GL_FALSE;
1448 }
1449 break;
1450 case EXTRA_GLSL_130:
1451 api_check = GL_TRUE;
1452 if (ctx->Const.GLSLVersion >= 130)
1453 api_found = GL_TRUE;
1454 break;
1455 case EXTRA_EXT_UBO_GS:
1456 api_check = GL_TRUE;
1457 if (ctx->Extensions.ARB_uniform_buffer_object &&
1458 _mesa_has_geometry_shaders(ctx))
1459 api_found = GL_TRUE;
1460 break;
1461 case EXTRA_EXT_ATOMICS_GS:
1462 api_check = GL_TRUE;
1463 if (ctx->Extensions.ARB_shader_atomic_counters &&
1464 _mesa_has_geometry_shaders(ctx))
1465 api_found = GL_TRUE;
1466 break;
1467 case EXTRA_EXT_SHADER_IMAGE_GS:
1468 api_check = GL_TRUE;
1469 if (ctx->Extensions.ARB_shader_image_load_store &&
1470 _mesa_has_geometry_shaders(ctx))
1471 api_found = GL_TRUE;
1472 break;
1473 case EXTRA_EXT_ATOMICS_TESS:
1474 api_check = GL_TRUE;
1475 api_found = ctx->Extensions.ARB_shader_atomic_counters &&
1476 _mesa_has_tessellation(ctx);
1477 break;
1478 case EXTRA_EXT_SHADER_IMAGE_TESS:
1479 api_check = GL_TRUE;
1480 api_found = ctx->Extensions.ARB_shader_image_load_store &&
1481 _mesa_has_tessellation(ctx);
1482 break;
1483 case EXTRA_EXT_SSBO_GS:
1484 api_check = GL_TRUE;
1485 if (ctx->Extensions.ARB_shader_storage_buffer_object &&
1486 _mesa_has_geometry_shaders(ctx))
1487 api_found = GL_TRUE;
1488 break;
1489 case EXTRA_EXT_FB_NO_ATTACH_GS:
1490 api_check = GL_TRUE;
1491 if (ctx->Extensions.ARB_framebuffer_no_attachments &&
1492 (_mesa_is_desktop_gl(ctx) ||
1493 _mesa_has_OES_geometry_shader(ctx)))
1494 api_found = GL_TRUE;
1495 break;
1496 case EXTRA_EXT_ES_GS:
1497 api_check = GL_TRUE;
1498 if (_mesa_has_OES_geometry_shader(ctx))
1499 api_found = GL_TRUE;
1500 break;
1501 case EXTRA_EXT_PROVOKING_VERTEX_32:
1502 api_check = GL_TRUE;
1503 if (ctx->API == API_OPENGL_COMPAT || version == 32)
1504 api_found = ctx->Extensions.EXT_provoking_vertex;
1505 break;
1506 case EXTRA_END:
1507 break;
1508 default: /* *e is a offset into the extension struct */
1509 api_check = GL_TRUE;
1510 if (*(GLboolean *) ((char *) &ctx->Extensions + *e))
1511 api_found = GL_TRUE;
1512 break;
1513 }
1514 }
1515
1516 if (api_check && !api_found) {
1517 _mesa_error(ctx, GL_INVALID_ENUM, "%s(pname=%s)", func,
1518 _mesa_enum_to_string(d->pname));
1519 return GL_FALSE;
1520 }
1521
1522 return GL_TRUE;
1523 }
1524
1525 static const struct value_desc error_value =
1526 { 0, 0, TYPE_INVALID, NO_OFFSET, NO_EXTRA };
1527
1528 /**
1529 * Find the struct value_desc corresponding to the enum 'pname'.
1530 *
1531 * We hash the enum value to get an index into the 'table' array,
1532 * which holds the index in the 'values' array of struct value_desc.
1533 * Once we've found the entry, we do the extra checks, if any, then
1534 * look up the value and return a pointer to it.
1535 *
1536 * If the value has to be computed (for example, it's the result of a
1537 * function call or we need to add 1 to it), we use the tmp 'v' to
1538 * store the result.
1539 *
1540 * \param func name of glGet*v() func for error reporting
1541 * \param pname the enum value we're looking up
1542 * \param p is were we return the pointer to the value
1543 * \param v a tmp union value variable in the calling glGet*v() function
1544 *
1545 * \return the struct value_desc corresponding to the enum or a struct
1546 * value_desc of TYPE_INVALID if not found. This lets the calling
1547 * glGet*v() function jump right into a switch statement and
1548 * handle errors there instead of having to check for NULL.
1549 */
1550 static const struct value_desc *
find_value(const char * func,GLenum pname,void ** p,union value * v)1551 find_value(const char *func, GLenum pname, void **p, union value *v)
1552 {
1553 GET_CURRENT_CONTEXT(ctx);
1554 int mask, hash;
1555 const struct value_desc *d;
1556 int api;
1557
1558 *p = NULL;
1559
1560 api = ctx->API;
1561 /* We index into the table_set[] list of per-API hash tables using the API's
1562 * value in the gl_api enum. Since GLES 3 doesn't have an API_OPENGL* enum
1563 * value since it's compatible with GLES2 its entry in table_set[] is at the
1564 * end.
1565 */
1566 STATIC_ASSERT(ARRAY_SIZE(table_set) == API_OPENGL_LAST + 4);
1567 if (ctx->API == API_OPENGLES2) {
1568 if (ctx->Version >= 32)
1569 api = API_OPENGL_LAST + 3;
1570 else if (ctx->Version >= 31)
1571 api = API_OPENGL_LAST + 2;
1572 else if (ctx->Version >= 30)
1573 api = API_OPENGL_LAST + 1;
1574 }
1575 mask = ARRAY_SIZE(table(api)) - 1;
1576 hash = (pname * prime_factor);
1577 while (1) {
1578 int idx = table(api)[hash & mask];
1579
1580 /* If the enum isn't valid, the hash walk ends with index 0,
1581 * pointing to the first entry of values[] which doesn't hold
1582 * any valid enum. */
1583 if (unlikely(idx == 0)) {
1584 _mesa_error(ctx, GL_INVALID_ENUM, "%s(pname=%s)", func,
1585 _mesa_enum_to_string(pname));
1586 return &error_value;
1587 }
1588
1589 d = &values[idx];
1590 if (likely(d->pname == pname))
1591 break;
1592
1593 hash += prime_step;
1594 }
1595
1596 if (unlikely(d->extra && !check_extra(ctx, func, d)))
1597 return &error_value;
1598
1599 switch (d->location) {
1600 case LOC_BUFFER:
1601 *p = ((char *) ctx->DrawBuffer + d->offset);
1602 return d;
1603 case LOC_CONTEXT:
1604 *p = ((char *) ctx + d->offset);
1605 return d;
1606 case LOC_ARRAY:
1607 *p = ((char *) ctx->Array.VAO + d->offset);
1608 return d;
1609 case LOC_TEXUNIT:
1610 if (ctx->Texture.CurrentUnit < ARRAY_SIZE(ctx->Texture.FixedFuncUnit)) {
1611 unsigned index = ctx->Texture.CurrentUnit;
1612 *p = ((char *)&ctx->Texture.FixedFuncUnit[index] + d->offset);
1613 return d;
1614 }
1615 _mesa_error(ctx, GL_INVALID_VALUE, "%s(pname=%s,unit=%d)", func,
1616 _mesa_enum_to_string(pname),
1617 ctx->Texture.CurrentUnit);
1618 return &error_value;
1619 case LOC_CUSTOM:
1620 find_custom_value(ctx, d, v);
1621 *p = v;
1622 return d;
1623 default:
1624 assert(0);
1625 break;
1626 }
1627
1628 /* silence warning */
1629 return &error_value;
1630 }
1631
1632 static const int transpose[] = {
1633 0, 4, 8, 12,
1634 1, 5, 9, 13,
1635 2, 6, 10, 14,
1636 3, 7, 11, 15
1637 };
1638
1639 static GLsizei
get_value_size(enum value_type type,const union value * v)1640 get_value_size(enum value_type type, const union value *v)
1641 {
1642 switch (type) {
1643 case TYPE_INVALID:
1644 return 0;
1645 case TYPE_CONST:
1646 case TYPE_UINT:
1647 case TYPE_INT:
1648 return sizeof(GLint);
1649 case TYPE_INT_2:
1650 case TYPE_UINT_2:
1651 return sizeof(GLint) * 2;
1652 case TYPE_INT_3:
1653 case TYPE_UINT_3:
1654 return sizeof(GLint) * 3;
1655 case TYPE_INT_4:
1656 case TYPE_UINT_4:
1657 return sizeof(GLint) * 4;
1658 case TYPE_INT_N:
1659 return sizeof(GLint) * v->value_int_n.n;
1660 case TYPE_INT64:
1661 return sizeof(GLint64);
1662 break;
1663 case TYPE_ENUM16:
1664 return sizeof(GLenum16);
1665 case TYPE_ENUM:
1666 return sizeof(GLenum);
1667 case TYPE_ENUM_2:
1668 return sizeof(GLenum) * 2;
1669 case TYPE_BOOLEAN:
1670 return sizeof(GLboolean);
1671 case TYPE_UBYTE:
1672 return sizeof(GLubyte);
1673 case TYPE_SHORT:
1674 return sizeof(GLshort);
1675 case TYPE_BIT_0:
1676 case TYPE_BIT_1:
1677 case TYPE_BIT_2:
1678 case TYPE_BIT_3:
1679 case TYPE_BIT_4:
1680 case TYPE_BIT_5:
1681 case TYPE_BIT_6:
1682 case TYPE_BIT_7:
1683 return 1;
1684 case TYPE_FLOAT:
1685 case TYPE_FLOATN:
1686 return sizeof(GLfloat);
1687 case TYPE_FLOAT_2:
1688 case TYPE_FLOATN_2:
1689 return sizeof(GLfloat) * 2;
1690 case TYPE_FLOAT_3:
1691 case TYPE_FLOATN_3:
1692 return sizeof(GLfloat) * 3;
1693 case TYPE_FLOAT_4:
1694 case TYPE_FLOATN_4:
1695 return sizeof(GLfloat) * 4;
1696 case TYPE_FLOAT_8:
1697 return sizeof(GLfloat) * 8;
1698 case TYPE_DOUBLEN:
1699 return sizeof(GLdouble);
1700 case TYPE_DOUBLEN_2:
1701 return sizeof(GLdouble) * 2;
1702 case TYPE_MATRIX:
1703 return sizeof (GLfloat) * 16;
1704 case TYPE_MATRIX_T:
1705 return sizeof (GLfloat) * 16;
1706 default:
1707 assert(!"invalid value_type given for get_value_size()");
1708 return -1;
1709 }
1710 }
1711
1712 void GLAPIENTRY
_mesa_GetBooleanv(GLenum pname,GLboolean * params)1713 _mesa_GetBooleanv(GLenum pname, GLboolean *params)
1714 {
1715 const struct value_desc *d;
1716 union value v;
1717 GLmatrix *m;
1718 int shift, i;
1719 void *p;
1720
1721 d = find_value("glGetBooleanv", pname, &p, &v);
1722 switch (d->type) {
1723 case TYPE_INVALID:
1724 break;
1725 case TYPE_CONST:
1726 params[0] = INT_TO_BOOLEAN(d->offset);
1727 break;
1728
1729 case TYPE_FLOAT_8:
1730 params[7] = FLOAT_TO_BOOLEAN(((GLfloat *) p)[7]);
1731 params[6] = FLOAT_TO_BOOLEAN(((GLfloat *) p)[6]);
1732 params[5] = FLOAT_TO_BOOLEAN(((GLfloat *) p)[5]);
1733 params[4] = FLOAT_TO_BOOLEAN(((GLfloat *) p)[4]);
1734 /* fallthrough */
1735 case TYPE_FLOAT_4:
1736 case TYPE_FLOATN_4:
1737 params[3] = FLOAT_TO_BOOLEAN(((GLfloat *) p)[3]);
1738 /* fallthrough */
1739 case TYPE_FLOAT_3:
1740 case TYPE_FLOATN_3:
1741 params[2] = FLOAT_TO_BOOLEAN(((GLfloat *) p)[2]);
1742 /* fallthrough */
1743 case TYPE_FLOAT_2:
1744 case TYPE_FLOATN_2:
1745 params[1] = FLOAT_TO_BOOLEAN(((GLfloat *) p)[1]);
1746 /* fallthrough */
1747 case TYPE_FLOAT:
1748 case TYPE_FLOATN:
1749 params[0] = FLOAT_TO_BOOLEAN(((GLfloat *) p)[0]);
1750 break;
1751
1752 case TYPE_DOUBLEN_2:
1753 params[1] = FLOAT_TO_BOOLEAN(((GLdouble *) p)[1]);
1754 /* fallthrough */
1755 case TYPE_DOUBLEN:
1756 params[0] = FLOAT_TO_BOOLEAN(((GLdouble *) p)[0]);
1757 break;
1758
1759 case TYPE_INT_4:
1760 case TYPE_UINT_4:
1761 params[3] = INT_TO_BOOLEAN(((GLint *) p)[3]);
1762 /* fallthrough */
1763 case TYPE_INT_3:
1764 case TYPE_UINT_3:
1765 params[2] = INT_TO_BOOLEAN(((GLint *) p)[2]);
1766 /* fallthrough */
1767 case TYPE_INT_2:
1768 case TYPE_UINT_2:
1769 case TYPE_ENUM_2:
1770 params[1] = INT_TO_BOOLEAN(((GLint *) p)[1]);
1771 /* fallthrough */
1772 case TYPE_INT:
1773 case TYPE_UINT:
1774 case TYPE_ENUM:
1775 params[0] = INT_TO_BOOLEAN(((GLint *) p)[0]);
1776 break;
1777
1778 case TYPE_ENUM16:
1779 params[0] = INT_TO_BOOLEAN(((GLenum16 *) p)[0]);
1780 break;
1781
1782 case TYPE_INT_N:
1783 for (i = 0; i < v.value_int_n.n; i++)
1784 params[i] = INT_TO_BOOLEAN(v.value_int_n.ints[i]);
1785 break;
1786
1787 case TYPE_INT64:
1788 params[0] = INT64_TO_BOOLEAN(((GLint64 *) p)[0]);
1789 break;
1790
1791 case TYPE_BOOLEAN:
1792 params[0] = ((GLboolean*) p)[0];
1793 break;
1794
1795 case TYPE_UBYTE:
1796 params[0] = INT_TO_BOOLEAN(((GLubyte *) p)[0]);
1797 break;
1798
1799 case TYPE_SHORT:
1800 params[0] = INT_TO_BOOLEAN(((GLshort *) p)[0]);
1801 break;
1802
1803 case TYPE_MATRIX:
1804 m = *(GLmatrix **) p;
1805 for (i = 0; i < 16; i++)
1806 params[i] = FLOAT_TO_BOOLEAN(m->m[i]);
1807 break;
1808
1809 case TYPE_MATRIX_T:
1810 m = *(GLmatrix **) p;
1811 for (i = 0; i < 16; i++)
1812 params[i] = FLOAT_TO_BOOLEAN(m->m[transpose[i]]);
1813 break;
1814
1815 case TYPE_BIT_0:
1816 case TYPE_BIT_1:
1817 case TYPE_BIT_2:
1818 case TYPE_BIT_3:
1819 case TYPE_BIT_4:
1820 case TYPE_BIT_5:
1821 case TYPE_BIT_6:
1822 case TYPE_BIT_7:
1823 shift = d->type - TYPE_BIT_0;
1824 params[0] = (*(GLbitfield *) p >> shift) & 1;
1825 break;
1826 }
1827 }
1828
1829 void GLAPIENTRY
_mesa_GetFloatv(GLenum pname,GLfloat * params)1830 _mesa_GetFloatv(GLenum pname, GLfloat *params)
1831 {
1832 const struct value_desc *d;
1833 union value v;
1834 GLmatrix *m;
1835 int shift, i;
1836 void *p;
1837
1838 d = find_value("glGetFloatv", pname, &p, &v);
1839 switch (d->type) {
1840 case TYPE_INVALID:
1841 break;
1842 case TYPE_CONST:
1843 params[0] = (GLfloat) d->offset;
1844 break;
1845
1846 case TYPE_FLOAT_8:
1847 params[7] = ((GLfloat *) p)[7];
1848 params[6] = ((GLfloat *) p)[6];
1849 params[5] = ((GLfloat *) p)[5];
1850 params[4] = ((GLfloat *) p)[4];
1851 /* fallthrough */
1852 case TYPE_FLOAT_4:
1853 case TYPE_FLOATN_4:
1854 params[3] = ((GLfloat *) p)[3];
1855 /* fallthrough */
1856 case TYPE_FLOAT_3:
1857 case TYPE_FLOATN_3:
1858 params[2] = ((GLfloat *) p)[2];
1859 /* fallthrough */
1860 case TYPE_FLOAT_2:
1861 case TYPE_FLOATN_2:
1862 params[1] = ((GLfloat *) p)[1];
1863 /* fallthrough */
1864 case TYPE_FLOAT:
1865 case TYPE_FLOATN:
1866 params[0] = ((GLfloat *) p)[0];
1867 break;
1868
1869 case TYPE_DOUBLEN_2:
1870 params[1] = (GLfloat) (((GLdouble *) p)[1]);
1871 /* fallthrough */
1872 case TYPE_DOUBLEN:
1873 params[0] = (GLfloat) (((GLdouble *) p)[0]);
1874 break;
1875
1876 case TYPE_INT_4:
1877 params[3] = (GLfloat) (((GLint *) p)[3]);
1878 /* fallthrough */
1879 case TYPE_INT_3:
1880 params[2] = (GLfloat) (((GLint *) p)[2]);
1881 /* fallthrough */
1882 case TYPE_INT_2:
1883 case TYPE_ENUM_2:
1884 params[1] = (GLfloat) (((GLint *) p)[1]);
1885 /* fallthrough */
1886 case TYPE_INT:
1887 case TYPE_ENUM:
1888 params[0] = (GLfloat) (((GLint *) p)[0]);
1889 break;
1890
1891 case TYPE_ENUM16:
1892 params[0] = (GLfloat) (((GLenum16 *) p)[0]);
1893 break;
1894
1895 case TYPE_INT_N:
1896 for (i = 0; i < v.value_int_n.n; i++)
1897 params[i] = (GLfloat) v.value_int_n.ints[i];
1898 break;
1899
1900 case TYPE_UINT_4:
1901 params[3] = (GLfloat) (((GLuint *) p)[3]);
1902 /* fallthrough */
1903 case TYPE_UINT_3:
1904 params[2] = (GLfloat) (((GLuint *) p)[2]);
1905 /* fallthrough */
1906 case TYPE_UINT_2:
1907 params[1] = (GLfloat) (((GLuint *) p)[1]);
1908 /* fallthrough */
1909 case TYPE_UINT:
1910 params[0] = (GLfloat) (((GLuint *) p)[0]);
1911 break;
1912
1913 case TYPE_INT64:
1914 params[0] = (GLfloat) (((GLint64 *) p)[0]);
1915 break;
1916
1917 case TYPE_BOOLEAN:
1918 params[0] = BOOLEAN_TO_FLOAT(*(GLboolean*) p);
1919 break;
1920
1921 case TYPE_UBYTE:
1922 params[0] = (GLfloat) ((GLubyte *) p)[0];
1923 break;
1924
1925 case TYPE_SHORT:
1926 params[0] = (GLfloat) ((GLshort *) p)[0];
1927 break;
1928
1929 case TYPE_MATRIX:
1930 m = *(GLmatrix **) p;
1931 for (i = 0; i < 16; i++)
1932 params[i] = m->m[i];
1933 break;
1934
1935 case TYPE_MATRIX_T:
1936 m = *(GLmatrix **) p;
1937 for (i = 0; i < 16; i++)
1938 params[i] = m->m[transpose[i]];
1939 break;
1940
1941 case TYPE_BIT_0:
1942 case TYPE_BIT_1:
1943 case TYPE_BIT_2:
1944 case TYPE_BIT_3:
1945 case TYPE_BIT_4:
1946 case TYPE_BIT_5:
1947 case TYPE_BIT_6:
1948 case TYPE_BIT_7:
1949 shift = d->type - TYPE_BIT_0;
1950 params[0] = BOOLEAN_TO_FLOAT((*(GLbitfield *) p >> shift) & 1);
1951 break;
1952 }
1953 }
1954
1955 void GLAPIENTRY
_mesa_GetIntegerv(GLenum pname,GLint * params)1956 _mesa_GetIntegerv(GLenum pname, GLint *params)
1957 {
1958 const struct value_desc *d;
1959 union value v;
1960 GLmatrix *m;
1961 int shift, i;
1962 void *p;
1963
1964 d = find_value("glGetIntegerv", pname, &p, &v);
1965 switch (d->type) {
1966 case TYPE_INVALID:
1967 break;
1968 case TYPE_CONST:
1969 params[0] = d->offset;
1970 break;
1971
1972 case TYPE_FLOAT_8:
1973 params[7] = lroundf(((GLfloat *) p)[7]);
1974 params[6] = lroundf(((GLfloat *) p)[6]);
1975 params[5] = lroundf(((GLfloat *) p)[5]);
1976 params[4] = lroundf(((GLfloat *) p)[4]);
1977 /* fallthrough */
1978 case TYPE_FLOAT_4:
1979 params[3] = lroundf(((GLfloat *) p)[3]);
1980 /* fallthrough */
1981 case TYPE_FLOAT_3:
1982 params[2] = lroundf(((GLfloat *) p)[2]);
1983 /* fallthrough */
1984 case TYPE_FLOAT_2:
1985 params[1] = lroundf(((GLfloat *) p)[1]);
1986 /* fallthrough */
1987 case TYPE_FLOAT:
1988 params[0] = lroundf(((GLfloat *) p)[0]);
1989 break;
1990
1991 case TYPE_FLOATN_4:
1992 params[3] = FLOAT_TO_INT(((GLfloat *) p)[3]);
1993 /* fallthrough */
1994 case TYPE_FLOATN_3:
1995 params[2] = FLOAT_TO_INT(((GLfloat *) p)[2]);
1996 /* fallthrough */
1997 case TYPE_FLOATN_2:
1998 params[1] = FLOAT_TO_INT(((GLfloat *) p)[1]);
1999 /* fallthrough */
2000 case TYPE_FLOATN:
2001 params[0] = FLOAT_TO_INT(((GLfloat *) p)[0]);
2002 break;
2003
2004 case TYPE_DOUBLEN_2:
2005 params[1] = FLOAT_TO_INT(((GLdouble *) p)[1]);
2006 /* fallthrough */
2007 case TYPE_DOUBLEN:
2008 params[0] = FLOAT_TO_INT(((GLdouble *) p)[0]);
2009 break;
2010
2011 case TYPE_INT_4:
2012 case TYPE_UINT_4:
2013 params[3] = ((GLint *) p)[3];
2014 /* fallthrough */
2015 case TYPE_INT_3:
2016 case TYPE_UINT_3:
2017 params[2] = ((GLint *) p)[2];
2018 /* fallthrough */
2019 case TYPE_INT_2:
2020 case TYPE_UINT_2:
2021 case TYPE_ENUM_2:
2022 params[1] = ((GLint *) p)[1];
2023 /* fallthrough */
2024 case TYPE_INT:
2025 case TYPE_UINT:
2026 case TYPE_ENUM:
2027 params[0] = ((GLint *) p)[0];
2028 break;
2029
2030 case TYPE_ENUM16:
2031 params[0] = ((GLenum16 *) p)[0];
2032 break;
2033
2034 case TYPE_INT_N:
2035 for (i = 0; i < v.value_int_n.n; i++)
2036 params[i] = v.value_int_n.ints[i];
2037 break;
2038
2039 case TYPE_INT64:
2040 params[0] = INT64_TO_INT(((GLint64 *) p)[0]);
2041 break;
2042
2043 case TYPE_BOOLEAN:
2044 params[0] = BOOLEAN_TO_INT(*(GLboolean*) p);
2045 break;
2046
2047 case TYPE_UBYTE:
2048 params[0] = ((GLubyte *) p)[0];
2049 break;
2050
2051 case TYPE_SHORT:
2052 params[0] = ((GLshort *) p)[0];
2053 break;
2054
2055 case TYPE_MATRIX:
2056 m = *(GLmatrix **) p;
2057 for (i = 0; i < 16; i++)
2058 params[i] = FLOAT_TO_INT(m->m[i]);
2059 break;
2060
2061 case TYPE_MATRIX_T:
2062 m = *(GLmatrix **) p;
2063 for (i = 0; i < 16; i++)
2064 params[i] = FLOAT_TO_INT(m->m[transpose[i]]);
2065 break;
2066
2067 case TYPE_BIT_0:
2068 case TYPE_BIT_1:
2069 case TYPE_BIT_2:
2070 case TYPE_BIT_3:
2071 case TYPE_BIT_4:
2072 case TYPE_BIT_5:
2073 case TYPE_BIT_6:
2074 case TYPE_BIT_7:
2075 shift = d->type - TYPE_BIT_0;
2076 params[0] = (*(GLbitfield *) p >> shift) & 1;
2077 break;
2078 }
2079 }
2080
2081 void GLAPIENTRY
_mesa_GetInteger64v(GLenum pname,GLint64 * params)2082 _mesa_GetInteger64v(GLenum pname, GLint64 *params)
2083 {
2084 const struct value_desc *d;
2085 union value v;
2086 GLmatrix *m;
2087 int shift, i;
2088 void *p;
2089
2090 d = find_value("glGetInteger64v", pname, &p, &v);
2091 switch (d->type) {
2092 case TYPE_INVALID:
2093 break;
2094 case TYPE_CONST:
2095 params[0] = d->offset;
2096 break;
2097
2098 case TYPE_FLOAT_8:
2099 params[7] = llround(((GLfloat *) p)[7]);
2100 params[6] = llround(((GLfloat *) p)[6]);
2101 params[5] = llround(((GLfloat *) p)[5]);
2102 params[4] = llround(((GLfloat *) p)[4]);
2103 /* fallthrough */
2104 case TYPE_FLOAT_4:
2105 params[3] = llround(((GLfloat *) p)[3]);
2106 /* fallthrough */
2107 case TYPE_FLOAT_3:
2108 params[2] = llround(((GLfloat *) p)[2]);
2109 /* fallthrough */
2110 case TYPE_FLOAT_2:
2111 params[1] = llround(((GLfloat *) p)[1]);
2112 /* fallthrough */
2113 case TYPE_FLOAT:
2114 params[0] = llround(((GLfloat *) p)[0]);
2115 break;
2116
2117 case TYPE_FLOATN_4:
2118 params[3] = FLOAT_TO_INT(((GLfloat *) p)[3]);
2119 /* fallthrough */
2120 case TYPE_FLOATN_3:
2121 params[2] = FLOAT_TO_INT(((GLfloat *) p)[2]);
2122 /* fallthrough */
2123 case TYPE_FLOATN_2:
2124 params[1] = FLOAT_TO_INT(((GLfloat *) p)[1]);
2125 /* fallthrough */
2126 case TYPE_FLOATN:
2127 params[0] = FLOAT_TO_INT(((GLfloat *) p)[0]);
2128 break;
2129
2130 case TYPE_DOUBLEN_2:
2131 params[1] = FLOAT_TO_INT(((GLdouble *) p)[1]);
2132 /* fallthrough */
2133 case TYPE_DOUBLEN:
2134 params[0] = FLOAT_TO_INT(((GLdouble *) p)[0]);
2135 break;
2136
2137 case TYPE_INT_4:
2138 params[3] = ((GLint *) p)[3];
2139 /* fallthrough */
2140 case TYPE_INT_3:
2141 params[2] = ((GLint *) p)[2];
2142 /* fallthrough */
2143 case TYPE_INT_2:
2144 case TYPE_ENUM_2:
2145 params[1] = ((GLint *) p)[1];
2146 /* fallthrough */
2147 case TYPE_INT:
2148 case TYPE_ENUM:
2149 params[0] = ((GLint *) p)[0];
2150 break;
2151
2152 case TYPE_ENUM16:
2153 params[0] = ((GLenum16 *) p)[0];
2154 break;
2155
2156 case TYPE_INT_N:
2157 for (i = 0; i < v.value_int_n.n; i++)
2158 params[i] = v.value_int_n.ints[i];
2159 break;
2160
2161 case TYPE_UINT_4:
2162 params[3] = ((GLuint *) p)[3];
2163 /* fallthrough */
2164 case TYPE_UINT_3:
2165 params[2] = ((GLuint *) p)[2];
2166 /* fallthrough */
2167 case TYPE_UINT_2:
2168 params[1] = ((GLuint *) p)[1];
2169 /* fallthrough */
2170 case TYPE_UINT:
2171 params[0] = ((GLuint *) p)[0];
2172 break;
2173
2174 case TYPE_INT64:
2175 params[0] = ((GLint64 *) p)[0];
2176 break;
2177
2178 case TYPE_BOOLEAN:
2179 params[0] = ((GLboolean*) p)[0];
2180 break;
2181
2182 case TYPE_MATRIX:
2183 m = *(GLmatrix **) p;
2184 for (i = 0; i < 16; i++)
2185 params[i] = FLOAT_TO_INT64(m->m[i]);
2186 break;
2187
2188 case TYPE_MATRIX_T:
2189 m = *(GLmatrix **) p;
2190 for (i = 0; i < 16; i++)
2191 params[i] = FLOAT_TO_INT64(m->m[transpose[i]]);
2192 break;
2193
2194 case TYPE_BIT_0:
2195 case TYPE_BIT_1:
2196 case TYPE_BIT_2:
2197 case TYPE_BIT_3:
2198 case TYPE_BIT_4:
2199 case TYPE_BIT_5:
2200 case TYPE_BIT_6:
2201 case TYPE_BIT_7:
2202 shift = d->type - TYPE_BIT_0;
2203 params[0] = (*(GLbitfield *) p >> shift) & 1;
2204 break;
2205 }
2206 }
2207
2208 void GLAPIENTRY
_mesa_GetDoublev(GLenum pname,GLdouble * params)2209 _mesa_GetDoublev(GLenum pname, GLdouble *params)
2210 {
2211 const struct value_desc *d;
2212 union value v;
2213 GLmatrix *m;
2214 int shift, i;
2215 void *p;
2216
2217 d = find_value("glGetDoublev", pname, &p, &v);
2218 switch (d->type) {
2219 case TYPE_INVALID:
2220 break;
2221 case TYPE_CONST:
2222 params[0] = d->offset;
2223 break;
2224
2225 case TYPE_FLOAT_8:
2226 params[7] = ((GLfloat *) p)[7];
2227 params[6] = ((GLfloat *) p)[6];
2228 params[5] = ((GLfloat *) p)[5];
2229 params[4] = ((GLfloat *) p)[4];
2230 /* fallthrough */
2231 case TYPE_FLOAT_4:
2232 case TYPE_FLOATN_4:
2233 params[3] = ((GLfloat *) p)[3];
2234 /* fallthrough */
2235 case TYPE_FLOAT_3:
2236 case TYPE_FLOATN_3:
2237 params[2] = ((GLfloat *) p)[2];
2238 /* fallthrough */
2239 case TYPE_FLOAT_2:
2240 case TYPE_FLOATN_2:
2241 params[1] = ((GLfloat *) p)[1];
2242 /* fallthrough */
2243 case TYPE_FLOAT:
2244 case TYPE_FLOATN:
2245 params[0] = ((GLfloat *) p)[0];
2246 break;
2247
2248 case TYPE_DOUBLEN_2:
2249 params[1] = ((GLdouble *) p)[1];
2250 /* fallthrough */
2251 case TYPE_DOUBLEN:
2252 params[0] = ((GLdouble *) p)[0];
2253 break;
2254
2255 case TYPE_INT_4:
2256 params[3] = ((GLint *) p)[3];
2257 /* fallthrough */
2258 case TYPE_INT_3:
2259 params[2] = ((GLint *) p)[2];
2260 /* fallthrough */
2261 case TYPE_INT_2:
2262 case TYPE_ENUM_2:
2263 params[1] = ((GLint *) p)[1];
2264 /* fallthrough */
2265 case TYPE_INT:
2266 case TYPE_ENUM:
2267 params[0] = ((GLint *) p)[0];
2268 break;
2269
2270 case TYPE_ENUM16:
2271 params[0] = ((GLenum16 *) p)[0];
2272 break;
2273
2274 case TYPE_INT_N:
2275 for (i = 0; i < v.value_int_n.n; i++)
2276 params[i] = v.value_int_n.ints[i];
2277 break;
2278
2279 case TYPE_UINT_4:
2280 params[3] = ((GLuint *) p)[3];
2281 /* fallthrough */
2282 case TYPE_UINT_3:
2283 params[2] = ((GLuint *) p)[2];
2284 /* fallthrough */
2285 case TYPE_UINT_2:
2286 params[1] = ((GLuint *) p)[1];
2287 /* fallthrough */
2288 case TYPE_UINT:
2289 params[0] = ((GLuint *) p)[0];
2290 break;
2291
2292 case TYPE_INT64:
2293 params[0] = (GLdouble) (((GLint64 *) p)[0]);
2294 break;
2295
2296 case TYPE_BOOLEAN:
2297 params[0] = *(GLboolean*) p;
2298 break;
2299
2300 case TYPE_UBYTE:
2301 params[0] = ((GLubyte *) p)[0];
2302 break;
2303
2304 case TYPE_SHORT:
2305 params[0] = ((GLshort *) p)[0];
2306 break;
2307
2308 case TYPE_MATRIX:
2309 m = *(GLmatrix **) p;
2310 for (i = 0; i < 16; i++)
2311 params[i] = m->m[i];
2312 break;
2313
2314 case TYPE_MATRIX_T:
2315 m = *(GLmatrix **) p;
2316 for (i = 0; i < 16; i++)
2317 params[i] = m->m[transpose[i]];
2318 break;
2319
2320 case TYPE_BIT_0:
2321 case TYPE_BIT_1:
2322 case TYPE_BIT_2:
2323 case TYPE_BIT_3:
2324 case TYPE_BIT_4:
2325 case TYPE_BIT_5:
2326 case TYPE_BIT_6:
2327 case TYPE_BIT_7:
2328 shift = d->type - TYPE_BIT_0;
2329 params[0] = (*(GLbitfield *) p >> shift) & 1;
2330 break;
2331 }
2332 }
2333
2334 void GLAPIENTRY
_mesa_GetUnsignedBytevEXT(GLenum pname,GLubyte * data)2335 _mesa_GetUnsignedBytevEXT(GLenum pname, GLubyte *data)
2336 {
2337 const struct value_desc *d;
2338 union value v;
2339 int shift;
2340 void *p = NULL;
2341 GLsizei size;
2342 const char *func = "glGetUnsignedBytevEXT";
2343
2344 GET_CURRENT_CONTEXT(ctx);
2345
2346 if (!ctx->Extensions.EXT_memory_object) {
2347 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(unsupported)", func);
2348 return;
2349 }
2350
2351 d = find_value(func, pname, &p, &v);
2352 size = get_value_size(d->type, &v);
2353
2354 switch (d->type) {
2355 case TYPE_BIT_0:
2356 case TYPE_BIT_1:
2357 case TYPE_BIT_2:
2358 case TYPE_BIT_3:
2359 case TYPE_BIT_4:
2360 case TYPE_BIT_5:
2361 case TYPE_BIT_6:
2362 case TYPE_BIT_7:
2363 shift = d->type - TYPE_BIT_0;
2364 data[0] = (*(GLbitfield *) p >> shift) & 1;
2365 break;
2366 case TYPE_CONST:
2367 memcpy(data, &d->offset, size);
2368 break;
2369 case TYPE_INT_N:
2370 memcpy(data, &v.value_int_n.ints, size);
2371 break;
2372 case TYPE_UINT:
2373 case TYPE_INT:
2374 case TYPE_INT_2:
2375 case TYPE_UINT_2:
2376 case TYPE_INT_3:
2377 case TYPE_UINT_3:
2378 case TYPE_INT_4:
2379 case TYPE_UINT_4:
2380 case TYPE_INT64:
2381 case TYPE_ENUM:
2382 case TYPE_ENUM_2:
2383 case TYPE_BOOLEAN:
2384 case TYPE_UBYTE:
2385 case TYPE_SHORT:
2386 case TYPE_FLOAT:
2387 case TYPE_FLOATN:
2388 case TYPE_FLOAT_2:
2389 case TYPE_FLOATN_2:
2390 case TYPE_FLOAT_3:
2391 case TYPE_FLOATN_3:
2392 case TYPE_FLOAT_4:
2393 case TYPE_FLOATN_4:
2394 case TYPE_FLOAT_8:
2395 case TYPE_DOUBLEN:
2396 case TYPE_DOUBLEN_2:
2397 case TYPE_MATRIX:
2398 case TYPE_MATRIX_T:
2399 memcpy(data, p, size);
2400 break;
2401 case TYPE_ENUM16: {
2402 GLenum e = *(GLenum16 *)p;
2403 memcpy(data, &e, sizeof(e));
2404 break;
2405 }
2406 default:
2407 break; /* nothing - GL error was recorded */
2408 }
2409 }
2410
2411 /**
2412 * Convert a GL texture binding enum such as GL_TEXTURE_BINDING_2D
2413 * into the corresponding Mesa texture target index.
2414 * \return TEXTURE_x_INDEX or -1 if binding is invalid
2415 */
2416 static int
tex_binding_to_index(const struct gl_context * ctx,GLenum binding)2417 tex_binding_to_index(const struct gl_context *ctx, GLenum binding)
2418 {
2419 switch (binding) {
2420 case GL_TEXTURE_BINDING_1D:
2421 return _mesa_is_desktop_gl(ctx) ? TEXTURE_1D_INDEX : -1;
2422 case GL_TEXTURE_BINDING_2D:
2423 return TEXTURE_2D_INDEX;
2424 case GL_TEXTURE_BINDING_3D:
2425 return ctx->API != API_OPENGLES ? TEXTURE_3D_INDEX : -1;
2426 case GL_TEXTURE_BINDING_CUBE_MAP:
2427 return ctx->Extensions.ARB_texture_cube_map
2428 ? TEXTURE_CUBE_INDEX : -1;
2429 case GL_TEXTURE_BINDING_RECTANGLE:
2430 return _mesa_is_desktop_gl(ctx) && ctx->Extensions.NV_texture_rectangle
2431 ? TEXTURE_RECT_INDEX : -1;
2432 case GL_TEXTURE_BINDING_1D_ARRAY:
2433 return _mesa_is_desktop_gl(ctx) && ctx->Extensions.EXT_texture_array
2434 ? TEXTURE_1D_ARRAY_INDEX : -1;
2435 case GL_TEXTURE_BINDING_2D_ARRAY:
2436 return (_mesa_is_desktop_gl(ctx) && ctx->Extensions.EXT_texture_array)
2437 || _mesa_is_gles3(ctx)
2438 ? TEXTURE_2D_ARRAY_INDEX : -1;
2439 case GL_TEXTURE_BINDING_BUFFER:
2440 return (_mesa_has_ARB_texture_buffer_object(ctx) ||
2441 _mesa_has_OES_texture_buffer(ctx)) ?
2442 TEXTURE_BUFFER_INDEX : -1;
2443 case GL_TEXTURE_BINDING_CUBE_MAP_ARRAY:
2444 return _mesa_has_texture_cube_map_array(ctx)
2445 ? TEXTURE_CUBE_ARRAY_INDEX : -1;
2446 case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
2447 return _mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_texture_multisample
2448 ? TEXTURE_2D_MULTISAMPLE_INDEX : -1;
2449 case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY:
2450 return _mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_texture_multisample
2451 ? TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX : -1;
2452 default:
2453 return -1;
2454 }
2455 }
2456
2457 static enum value_type
find_value_indexed(const char * func,GLenum pname,GLuint index,union value * v)2458 find_value_indexed(const char *func, GLenum pname, GLuint index, union value *v)
2459 {
2460 GET_CURRENT_CONTEXT(ctx);
2461 struct gl_buffer_object *buf;
2462
2463 switch (pname) {
2464
2465 case GL_BLEND:
2466 if (index >= ctx->Const.MaxDrawBuffers)
2467 goto invalid_value;
2468 if (!ctx->Extensions.EXT_draw_buffers2)
2469 goto invalid_enum;
2470 v->value_int = (ctx->Color.BlendEnabled >> index) & 1;
2471 return TYPE_INT;
2472
2473 case GL_BLEND_SRC:
2474 /* fall-through */
2475 case GL_BLEND_SRC_RGB:
2476 if (index >= ctx->Const.MaxDrawBuffers)
2477 goto invalid_value;
2478 if (!ctx->Extensions.ARB_draw_buffers_blend)
2479 goto invalid_enum;
2480 v->value_int = ctx->Color.Blend[index].SrcRGB;
2481 return TYPE_INT;
2482 case GL_BLEND_SRC_ALPHA:
2483 if (index >= ctx->Const.MaxDrawBuffers)
2484 goto invalid_value;
2485 if (!ctx->Extensions.ARB_draw_buffers_blend)
2486 goto invalid_enum;
2487 v->value_int = ctx->Color.Blend[index].SrcA;
2488 return TYPE_INT;
2489 case GL_BLEND_DST:
2490 /* fall-through */
2491 case GL_BLEND_DST_RGB:
2492 if (index >= ctx->Const.MaxDrawBuffers)
2493 goto invalid_value;
2494 if (!ctx->Extensions.ARB_draw_buffers_blend)
2495 goto invalid_enum;
2496 v->value_int = ctx->Color.Blend[index].DstRGB;
2497 return TYPE_INT;
2498 case GL_BLEND_DST_ALPHA:
2499 if (index >= ctx->Const.MaxDrawBuffers)
2500 goto invalid_value;
2501 if (!ctx->Extensions.ARB_draw_buffers_blend)
2502 goto invalid_enum;
2503 v->value_int = ctx->Color.Blend[index].DstA;
2504 return TYPE_INT;
2505 case GL_BLEND_EQUATION_RGB:
2506 if (index >= ctx->Const.MaxDrawBuffers)
2507 goto invalid_value;
2508 if (!ctx->Extensions.ARB_draw_buffers_blend)
2509 goto invalid_enum;
2510 v->value_int = ctx->Color.Blend[index].EquationRGB;
2511 return TYPE_INT;
2512 case GL_BLEND_EQUATION_ALPHA:
2513 if (index >= ctx->Const.MaxDrawBuffers)
2514 goto invalid_value;
2515 if (!ctx->Extensions.ARB_draw_buffers_blend)
2516 goto invalid_enum;
2517 v->value_int = ctx->Color.Blend[index].EquationA;
2518 return TYPE_INT;
2519
2520 case GL_COLOR_WRITEMASK:
2521 if (index >= ctx->Const.MaxDrawBuffers)
2522 goto invalid_value;
2523 if (!ctx->Extensions.EXT_draw_buffers2)
2524 goto invalid_enum;
2525 v->value_int_4[0] = GET_COLORMASK_BIT(ctx->Color.ColorMask, index, 0);
2526 v->value_int_4[1] = GET_COLORMASK_BIT(ctx->Color.ColorMask, index, 1);
2527 v->value_int_4[2] = GET_COLORMASK_BIT(ctx->Color.ColorMask, index, 2);
2528 v->value_int_4[3] = GET_COLORMASK_BIT(ctx->Color.ColorMask, index, 3);
2529 return TYPE_INT_4;
2530
2531 case GL_SCISSOR_BOX:
2532 if (index >= ctx->Const.MaxViewports)
2533 goto invalid_value;
2534 v->value_int_4[0] = ctx->Scissor.ScissorArray[index].X;
2535 v->value_int_4[1] = ctx->Scissor.ScissorArray[index].Y;
2536 v->value_int_4[2] = ctx->Scissor.ScissorArray[index].Width;
2537 v->value_int_4[3] = ctx->Scissor.ScissorArray[index].Height;
2538 return TYPE_INT_4;
2539
2540 case GL_WINDOW_RECTANGLE_EXT:
2541 if (!ctx->Extensions.EXT_window_rectangles)
2542 goto invalid_enum;
2543 if (index >= ctx->Const.MaxWindowRectangles)
2544 goto invalid_value;
2545 v->value_int_4[0] = ctx->Scissor.WindowRects[index].X;
2546 v->value_int_4[1] = ctx->Scissor.WindowRects[index].Y;
2547 v->value_int_4[2] = ctx->Scissor.WindowRects[index].Width;
2548 v->value_int_4[3] = ctx->Scissor.WindowRects[index].Height;
2549 return TYPE_INT_4;
2550
2551 case GL_VIEWPORT:
2552 if (index >= ctx->Const.MaxViewports)
2553 goto invalid_value;
2554 v->value_float_4[0] = ctx->ViewportArray[index].X;
2555 v->value_float_4[1] = ctx->ViewportArray[index].Y;
2556 v->value_float_4[2] = ctx->ViewportArray[index].Width;
2557 v->value_float_4[3] = ctx->ViewportArray[index].Height;
2558 return TYPE_FLOAT_4;
2559
2560 case GL_DEPTH_RANGE:
2561 if (index >= ctx->Const.MaxViewports)
2562 goto invalid_value;
2563 v->value_double_2[0] = ctx->ViewportArray[index].Near;
2564 v->value_double_2[1] = ctx->ViewportArray[index].Far;
2565 return TYPE_DOUBLEN_2;
2566
2567 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
2568 if (index >= ctx->Const.MaxTransformFeedbackBuffers)
2569 goto invalid_value;
2570 if (!ctx->Extensions.EXT_transform_feedback)
2571 goto invalid_enum;
2572 v->value_int64 = ctx->TransformFeedback.CurrentObject->Offset[index];
2573 return TYPE_INT64;
2574
2575 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
2576 if (index >= ctx->Const.MaxTransformFeedbackBuffers)
2577 goto invalid_value;
2578 if (!ctx->Extensions.EXT_transform_feedback)
2579 goto invalid_enum;
2580 v->value_int64
2581 = ctx->TransformFeedback.CurrentObject->RequestedSize[index];
2582 return TYPE_INT64;
2583
2584 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
2585 if (index >= ctx->Const.MaxTransformFeedbackBuffers)
2586 goto invalid_value;
2587 if (!ctx->Extensions.EXT_transform_feedback)
2588 goto invalid_enum;
2589 v->value_int = ctx->TransformFeedback.CurrentObject->BufferNames[index];
2590 return TYPE_INT;
2591
2592 case GL_UNIFORM_BUFFER_BINDING:
2593 if (index >= ctx->Const.MaxUniformBufferBindings)
2594 goto invalid_value;
2595 if (!ctx->Extensions.ARB_uniform_buffer_object)
2596 goto invalid_enum;
2597 buf = ctx->UniformBufferBindings[index].BufferObject;
2598 v->value_int = buf ? buf->Name : 0;
2599 return TYPE_INT;
2600
2601 case GL_UNIFORM_BUFFER_START:
2602 if (index >= ctx->Const.MaxUniformBufferBindings)
2603 goto invalid_value;
2604 if (!ctx->Extensions.ARB_uniform_buffer_object)
2605 goto invalid_enum;
2606 v->value_int = ctx->UniformBufferBindings[index].Offset < 0 ? 0 :
2607 ctx->UniformBufferBindings[index].Offset;
2608 return TYPE_INT;
2609
2610 case GL_UNIFORM_BUFFER_SIZE:
2611 if (index >= ctx->Const.MaxUniformBufferBindings)
2612 goto invalid_value;
2613 if (!ctx->Extensions.ARB_uniform_buffer_object)
2614 goto invalid_enum;
2615 v->value_int = ctx->UniformBufferBindings[index].Size < 0 ? 0 :
2616 ctx->UniformBufferBindings[index].Size;
2617 return TYPE_INT;
2618
2619 /* ARB_shader_storage_buffer_object */
2620 case GL_SHADER_STORAGE_BUFFER_BINDING:
2621 if (!ctx->Extensions.ARB_shader_storage_buffer_object)
2622 goto invalid_enum;
2623 if (index >= ctx->Const.MaxShaderStorageBufferBindings)
2624 goto invalid_value;
2625 buf = ctx->ShaderStorageBufferBindings[index].BufferObject;
2626 v->value_int = buf ? buf->Name : 0;
2627 return TYPE_INT;
2628
2629 case GL_SHADER_STORAGE_BUFFER_START:
2630 if (!ctx->Extensions.ARB_shader_storage_buffer_object)
2631 goto invalid_enum;
2632 if (index >= ctx->Const.MaxShaderStorageBufferBindings)
2633 goto invalid_value;
2634 v->value_int = ctx->ShaderStorageBufferBindings[index].Offset < 0 ? 0 :
2635 ctx->ShaderStorageBufferBindings[index].Offset;
2636 return TYPE_INT;
2637
2638 case GL_SHADER_STORAGE_BUFFER_SIZE:
2639 if (!ctx->Extensions.ARB_shader_storage_buffer_object)
2640 goto invalid_enum;
2641 if (index >= ctx->Const.MaxShaderStorageBufferBindings)
2642 goto invalid_value;
2643 v->value_int = ctx->ShaderStorageBufferBindings[index].Size < 0 ? 0 :
2644 ctx->ShaderStorageBufferBindings[index].Size;
2645 return TYPE_INT;
2646
2647 /* ARB_texture_multisample / GL3.2 */
2648 case GL_SAMPLE_MASK_VALUE:
2649 if (index != 0)
2650 goto invalid_value;
2651 if (!ctx->Extensions.ARB_texture_multisample)
2652 goto invalid_enum;
2653 v->value_int = ctx->Multisample.SampleMaskValue;
2654 return TYPE_INT;
2655
2656 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
2657 if (!ctx->Extensions.ARB_shader_atomic_counters)
2658 goto invalid_enum;
2659 if (index >= ctx->Const.MaxAtomicBufferBindings)
2660 goto invalid_value;
2661 buf = ctx->AtomicBufferBindings[index].BufferObject;
2662 v->value_int = buf ? buf->Name : 0;
2663 return TYPE_INT;
2664
2665 case GL_ATOMIC_COUNTER_BUFFER_START:
2666 if (!ctx->Extensions.ARB_shader_atomic_counters)
2667 goto invalid_enum;
2668 if (index >= ctx->Const.MaxAtomicBufferBindings)
2669 goto invalid_value;
2670 v->value_int64 = ctx->AtomicBufferBindings[index].Offset < 0 ? 0 :
2671 ctx->AtomicBufferBindings[index].Offset;
2672 return TYPE_INT64;
2673
2674 case GL_ATOMIC_COUNTER_BUFFER_SIZE:
2675 if (!ctx->Extensions.ARB_shader_atomic_counters)
2676 goto invalid_enum;
2677 if (index >= ctx->Const.MaxAtomicBufferBindings)
2678 goto invalid_value;
2679 v->value_int64 = ctx->AtomicBufferBindings[index].Size < 0 ? 0 :
2680 ctx->AtomicBufferBindings[index].Size;
2681 return TYPE_INT64;
2682
2683 case GL_VERTEX_BINDING_DIVISOR:
2684 if ((!_mesa_is_desktop_gl(ctx) || !ctx->Extensions.ARB_instanced_arrays) &&
2685 !_mesa_is_gles31(ctx))
2686 goto invalid_enum;
2687 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs)
2688 goto invalid_value;
2689 v->value_int = ctx->Array.VAO->BufferBinding[VERT_ATTRIB_GENERIC(index)].InstanceDivisor;
2690 return TYPE_INT;
2691
2692 case GL_VERTEX_BINDING_OFFSET:
2693 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles31(ctx))
2694 goto invalid_enum;
2695 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs)
2696 goto invalid_value;
2697 v->value_int = ctx->Array.VAO->BufferBinding[VERT_ATTRIB_GENERIC(index)].Offset;
2698 return TYPE_INT;
2699
2700 case GL_VERTEX_BINDING_STRIDE:
2701 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles31(ctx))
2702 goto invalid_enum;
2703 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs)
2704 goto invalid_value;
2705 v->value_int = ctx->Array.VAO->BufferBinding[VERT_ATTRIB_GENERIC(index)].Stride;
2706 return TYPE_INT;
2707
2708 case GL_VERTEX_BINDING_BUFFER:
2709 if (ctx->API == API_OPENGLES2 && ctx->Version < 31)
2710 goto invalid_enum;
2711 if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs)
2712 goto invalid_value;
2713 buf = ctx->Array.VAO->BufferBinding[VERT_ATTRIB_GENERIC(index)].BufferObj;
2714 v->value_int = buf ? buf->Name : 0;
2715 return TYPE_INT;
2716
2717 /* ARB_shader_image_load_store */
2718 case GL_IMAGE_BINDING_NAME: {
2719 struct gl_texture_object *t;
2720
2721 if (!ctx->Extensions.ARB_shader_image_load_store)
2722 goto invalid_enum;
2723 if (index >= ctx->Const.MaxImageUnits)
2724 goto invalid_value;
2725
2726 t = ctx->ImageUnits[index].TexObj;
2727 v->value_int = (t ? t->Name : 0);
2728 return TYPE_INT;
2729 }
2730
2731 case GL_IMAGE_BINDING_LEVEL:
2732 if (!ctx->Extensions.ARB_shader_image_load_store)
2733 goto invalid_enum;
2734 if (index >= ctx->Const.MaxImageUnits)
2735 goto invalid_value;
2736
2737 v->value_int = ctx->ImageUnits[index].Level;
2738 return TYPE_INT;
2739
2740 case GL_IMAGE_BINDING_LAYERED:
2741 if (!ctx->Extensions.ARB_shader_image_load_store)
2742 goto invalid_enum;
2743 if (index >= ctx->Const.MaxImageUnits)
2744 goto invalid_value;
2745
2746 v->value_int = ctx->ImageUnits[index].Layered;
2747 return TYPE_INT;
2748
2749 case GL_IMAGE_BINDING_LAYER:
2750 if (!ctx->Extensions.ARB_shader_image_load_store)
2751 goto invalid_enum;
2752 if (index >= ctx->Const.MaxImageUnits)
2753 goto invalid_value;
2754
2755 v->value_int = ctx->ImageUnits[index].Layer;
2756 return TYPE_INT;
2757
2758 case GL_IMAGE_BINDING_ACCESS:
2759 if (!ctx->Extensions.ARB_shader_image_load_store)
2760 goto invalid_enum;
2761 if (index >= ctx->Const.MaxImageUnits)
2762 goto invalid_value;
2763
2764 v->value_int = ctx->ImageUnits[index].Access;
2765 return TYPE_INT;
2766
2767 case GL_IMAGE_BINDING_FORMAT:
2768 if (!ctx->Extensions.ARB_shader_image_load_store)
2769 goto invalid_enum;
2770 if (index >= ctx->Const.MaxImageUnits)
2771 goto invalid_value;
2772
2773 v->value_int = ctx->ImageUnits[index].Format;
2774 return TYPE_INT;
2775
2776 /* ARB_direct_state_access */
2777 case GL_TEXTURE_BINDING_1D:
2778 case GL_TEXTURE_BINDING_1D_ARRAY:
2779 case GL_TEXTURE_BINDING_2D:
2780 case GL_TEXTURE_BINDING_2D_ARRAY:
2781 case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
2782 case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY:
2783 case GL_TEXTURE_BINDING_3D:
2784 case GL_TEXTURE_BINDING_BUFFER:
2785 case GL_TEXTURE_BINDING_CUBE_MAP:
2786 case GL_TEXTURE_BINDING_CUBE_MAP_ARRAY:
2787 case GL_TEXTURE_BINDING_RECTANGLE: {
2788 int target;
2789
2790 target = tex_binding_to_index(ctx, pname);
2791 if (target < 0)
2792 goto invalid_enum;
2793 if (index >= _mesa_max_tex_unit(ctx))
2794 goto invalid_value;
2795
2796 v->value_int = ctx->Texture.Unit[index].CurrentTex[target]->Name;
2797 return TYPE_INT;
2798 }
2799
2800 case GL_SAMPLER_BINDING: {
2801 struct gl_sampler_object *samp;
2802
2803 if (!_mesa_is_desktop_gl(ctx) || ctx->Version < 33)
2804 goto invalid_enum;
2805 if (index >= _mesa_max_tex_unit(ctx))
2806 goto invalid_value;
2807
2808 samp = ctx->Texture.Unit[index].Sampler;
2809 v->value_int = samp ? samp->Name : 0;
2810 return TYPE_INT;
2811 }
2812
2813 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
2814 if (!_mesa_has_compute_shaders(ctx))
2815 goto invalid_enum;
2816 if (index >= 3)
2817 goto invalid_value;
2818 v->value_int = ctx->Const.MaxComputeWorkGroupCount[index];
2819 return TYPE_INT;
2820
2821 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
2822 if (!_mesa_has_compute_shaders(ctx))
2823 goto invalid_enum;
2824 if (index >= 3)
2825 goto invalid_value;
2826 v->value_int = ctx->Const.MaxComputeWorkGroupSize[index];
2827 return TYPE_INT;
2828
2829 /* ARB_compute_variable_group_size */
2830 case GL_MAX_COMPUTE_VARIABLE_GROUP_SIZE_ARB:
2831 if (!ctx->Extensions.ARB_compute_variable_group_size)
2832 goto invalid_enum;
2833 if (index >= 3)
2834 goto invalid_value;
2835 v->value_int = ctx->Const.MaxComputeVariableGroupSize[index];
2836 return TYPE_INT;
2837
2838 /* GL_EXT_external_objects */
2839 case GL_NUM_DEVICE_UUIDS_EXT:
2840 v->value_int = 1;
2841 return TYPE_INT;
2842 case GL_DRIVER_UUID_EXT:
2843 if (index >= 1)
2844 goto invalid_value;
2845 _mesa_get_driver_uuid(ctx, v->value_int_4);
2846 return TYPE_INT_4;
2847 case GL_DEVICE_UUID_EXT:
2848 if (index >= 1)
2849 goto invalid_value;
2850 _mesa_get_device_uuid(ctx, v->value_int_4);
2851 return TYPE_INT_4;
2852 /* GL_EXT_direct_state_access */
2853 case GL_TEXTURE_1D:
2854 case GL_TEXTURE_2D:
2855 case GL_TEXTURE_3D:
2856 case GL_TEXTURE_CUBE_MAP:
2857 case GL_TEXTURE_GEN_S:
2858 case GL_TEXTURE_GEN_T:
2859 case GL_TEXTURE_GEN_R:
2860 case GL_TEXTURE_GEN_Q:
2861 case GL_TEXTURE_RECTANGLE_ARB: {
2862 GLuint curTexUnitSave;
2863 if (index >= _mesa_max_tex_unit(ctx))
2864 goto invalid_enum;
2865 curTexUnitSave = ctx->Texture.CurrentUnit;
2866 _mesa_ActiveTexture_no_error(GL_TEXTURE0 + index);
2867 v->value_int = _mesa_IsEnabled(pname);
2868 _mesa_ActiveTexture_no_error(GL_TEXTURE0 + curTexUnitSave);
2869 return TYPE_INT;
2870 }
2871 case GL_TEXTURE_COORD_ARRAY: {
2872 GLuint curTexUnitSave;
2873 if (index >= ctx->Const.MaxTextureCoordUnits)
2874 goto invalid_enum;
2875 curTexUnitSave = ctx->Array.ActiveTexture;
2876 _mesa_ClientActiveTexture(GL_TEXTURE0 + index);
2877 v->value_int = _mesa_IsEnabled(pname);
2878 _mesa_ClientActiveTexture(GL_TEXTURE0 + curTexUnitSave);
2879 return TYPE_INT;
2880 }
2881 case GL_TEXTURE_MATRIX:
2882 if (index >= ARRAY_SIZE(ctx->TextureMatrixStack))
2883 goto invalid_enum;
2884 v->value_matrix = ctx->TextureMatrixStack[index].Top;
2885 return TYPE_MATRIX;
2886 case GL_TRANSPOSE_TEXTURE_MATRIX:
2887 if (index >= ARRAY_SIZE(ctx->TextureMatrixStack))
2888 goto invalid_enum;
2889 v->value_matrix = ctx->TextureMatrixStack[index].Top;
2890 return TYPE_MATRIX_T;
2891 /* GL_NV_viewport_swizzle */
2892 case GL_VIEWPORT_SWIZZLE_X_NV:
2893 if (!ctx->Extensions.NV_viewport_swizzle)
2894 goto invalid_enum;
2895 if (index >= ctx->Const.MaxViewports)
2896 goto invalid_value;
2897 v->value_int = ctx->ViewportArray[index].SwizzleX;
2898 return TYPE_INT;
2899 case GL_VIEWPORT_SWIZZLE_Y_NV:
2900 if (!ctx->Extensions.NV_viewport_swizzle)
2901 goto invalid_enum;
2902 if (index >= ctx->Const.MaxViewports)
2903 goto invalid_value;
2904 v->value_int = ctx->ViewportArray[index].SwizzleY;
2905 return TYPE_INT;
2906 case GL_VIEWPORT_SWIZZLE_Z_NV:
2907 if (!ctx->Extensions.NV_viewport_swizzle)
2908 goto invalid_enum;
2909 if (index >= ctx->Const.MaxViewports)
2910 goto invalid_value;
2911 v->value_int = ctx->ViewportArray[index].SwizzleZ;
2912 return TYPE_INT;
2913 case GL_VIEWPORT_SWIZZLE_W_NV:
2914 if (!ctx->Extensions.NV_viewport_swizzle)
2915 goto invalid_enum;
2916 if (index >= ctx->Const.MaxViewports)
2917 goto invalid_value;
2918 v->value_int = ctx->ViewportArray[index].SwizzleW;
2919 return TYPE_INT;
2920 }
2921
2922 invalid_enum:
2923 _mesa_error(ctx, GL_INVALID_ENUM, "%s(pname=%s)", func,
2924 _mesa_enum_to_string(pname));
2925 return TYPE_INVALID;
2926 invalid_value:
2927 _mesa_error(ctx, GL_INVALID_VALUE, "%s(pname=%s)", func,
2928 _mesa_enum_to_string(pname));
2929 return TYPE_INVALID;
2930 }
2931
2932 void GLAPIENTRY
_mesa_GetBooleani_v(GLenum pname,GLuint index,GLboolean * params)2933 _mesa_GetBooleani_v( GLenum pname, GLuint index, GLboolean *params )
2934 {
2935 union value v;
2936 enum value_type type =
2937 find_value_indexed("glGetBooleani_v", pname, index, &v);
2938
2939 switch (type) {
2940 case TYPE_INT:
2941 case TYPE_UINT:
2942 params[0] = INT_TO_BOOLEAN(v.value_int);
2943 break;
2944 case TYPE_INT_4:
2945 case TYPE_UINT_4:
2946 params[0] = INT_TO_BOOLEAN(v.value_int_4[0]);
2947 params[1] = INT_TO_BOOLEAN(v.value_int_4[1]);
2948 params[2] = INT_TO_BOOLEAN(v.value_int_4[2]);
2949 params[3] = INT_TO_BOOLEAN(v.value_int_4[3]);
2950 break;
2951 case TYPE_INT64:
2952 params[0] = INT64_TO_BOOLEAN(v.value_int64);
2953 break;
2954 default:
2955 ; /* nothing - GL error was recorded */
2956 }
2957 }
2958
2959 void GLAPIENTRY
_mesa_GetIntegeri_v(GLenum pname,GLuint index,GLint * params)2960 _mesa_GetIntegeri_v( GLenum pname, GLuint index, GLint *params )
2961 {
2962 union value v;
2963 enum value_type type =
2964 find_value_indexed("glGetIntegeri_v", pname, index, &v);
2965
2966 switch (type) {
2967 case TYPE_FLOAT_4:
2968 case TYPE_FLOATN_4:
2969 params[3] = lroundf(v.value_float_4[3]);
2970 /* fallthrough */
2971 case TYPE_FLOAT_3:
2972 case TYPE_FLOATN_3:
2973 params[2] = lroundf(v.value_float_4[2]);
2974 /* fallthrough */
2975 case TYPE_FLOAT_2:
2976 case TYPE_FLOATN_2:
2977 params[1] = lroundf(v.value_float_4[1]);
2978 /* fallthrough */
2979 case TYPE_FLOAT:
2980 case TYPE_FLOATN:
2981 params[0] = lroundf(v.value_float_4[0]);
2982 break;
2983
2984 case TYPE_DOUBLEN_2:
2985 params[1] = lroundf(v.value_double_2[1]);
2986 /* fallthrough */
2987 case TYPE_DOUBLEN:
2988 params[0] = lroundf(v.value_double_2[0]);
2989 break;
2990
2991 case TYPE_INT:
2992 case TYPE_UINT:
2993 params[0] = v.value_int;
2994 break;
2995 case TYPE_INT_4:
2996 case TYPE_UINT_4:
2997 params[0] = v.value_int_4[0];
2998 params[1] = v.value_int_4[1];
2999 params[2] = v.value_int_4[2];
3000 params[3] = v.value_int_4[3];
3001 break;
3002 case TYPE_INT64:
3003 params[0] = INT64_TO_INT(v.value_int64);
3004 break;
3005 default:
3006 ; /* nothing - GL error was recorded */
3007 }
3008 }
3009
3010 void GLAPIENTRY
_mesa_GetInteger64i_v(GLenum pname,GLuint index,GLint64 * params)3011 _mesa_GetInteger64i_v( GLenum pname, GLuint index, GLint64 *params )
3012 {
3013 union value v;
3014 enum value_type type =
3015 find_value_indexed("glGetInteger64i_v", pname, index, &v);
3016
3017 switch (type) {
3018 case TYPE_INT:
3019 params[0] = v.value_int;
3020 break;
3021 case TYPE_INT_4:
3022 params[0] = v.value_int_4[0];
3023 params[1] = v.value_int_4[1];
3024 params[2] = v.value_int_4[2];
3025 params[3] = v.value_int_4[3];
3026 break;
3027 case TYPE_UINT:
3028 params[0] = (GLuint) v.value_int;
3029 break;
3030 case TYPE_UINT_4:
3031 params[0] = (GLuint) v.value_int_4[0];
3032 params[1] = (GLuint) v.value_int_4[1];
3033 params[2] = (GLuint) v.value_int_4[2];
3034 params[3] = (GLuint) v.value_int_4[3];
3035 break;
3036 case TYPE_INT64:
3037 params[0] = v.value_int64;
3038 break;
3039 default:
3040 ; /* nothing - GL error was recorded */
3041 }
3042 }
3043
3044 void GLAPIENTRY
_mesa_GetFloati_v(GLenum pname,GLuint index,GLfloat * params)3045 _mesa_GetFloati_v(GLenum pname, GLuint index, GLfloat *params)
3046 {
3047 int i;
3048 GLmatrix *m;
3049 union value v;
3050 enum value_type type =
3051 find_value_indexed("glGetFloati_v", pname, index, &v);
3052
3053 switch (type) {
3054 case TYPE_FLOAT_4:
3055 case TYPE_FLOATN_4:
3056 params[3] = v.value_float_4[3];
3057 /* fallthrough */
3058 case TYPE_FLOAT_3:
3059 case TYPE_FLOATN_3:
3060 params[2] = v.value_float_4[2];
3061 /* fallthrough */
3062 case TYPE_FLOAT_2:
3063 case TYPE_FLOATN_2:
3064 params[1] = v.value_float_4[1];
3065 /* fallthrough */
3066 case TYPE_FLOAT:
3067 case TYPE_FLOATN:
3068 params[0] = v.value_float_4[0];
3069 break;
3070
3071 case TYPE_DOUBLEN_2:
3072 params[1] = (GLfloat) v.value_double_2[1];
3073 /* fallthrough */
3074 case TYPE_DOUBLEN:
3075 params[0] = (GLfloat) v.value_double_2[0];
3076 break;
3077
3078 case TYPE_INT_4:
3079 params[3] = (GLfloat) v.value_int_4[3];
3080 /* fallthrough */
3081 case TYPE_INT_3:
3082 params[2] = (GLfloat) v.value_int_4[2];
3083 /* fallthrough */
3084 case TYPE_INT_2:
3085 case TYPE_ENUM_2:
3086 params[1] = (GLfloat) v.value_int_4[1];
3087 /* fallthrough */
3088 case TYPE_INT:
3089 case TYPE_ENUM:
3090 case TYPE_ENUM16:
3091 params[0] = (GLfloat) v.value_int_4[0];
3092 break;
3093
3094 case TYPE_INT_N:
3095 for (i = 0; i < v.value_int_n.n; i++)
3096 params[i] = (GLfloat) v.value_int_n.ints[i];
3097 break;
3098
3099 case TYPE_UINT_4:
3100 params[3] = (GLfloat) ((GLuint) v.value_int_4[3]);
3101 /* fallthrough */
3102 case TYPE_UINT_3:
3103 params[2] = (GLfloat) ((GLuint) v.value_int_4[2]);
3104 /* fallthrough */
3105 case TYPE_UINT_2:
3106 params[1] = (GLfloat) ((GLuint) v.value_int_4[1]);
3107 /* fallthrough */
3108 case TYPE_UINT:
3109 params[0] = (GLfloat) ((GLuint) v.value_int_4[0]);
3110 break;
3111
3112 case TYPE_INT64:
3113 params[0] = (GLfloat) v.value_int64;
3114 break;
3115
3116 case TYPE_BOOLEAN:
3117 params[0] = BOOLEAN_TO_FLOAT(v.value_bool);
3118 break;
3119
3120 case TYPE_UBYTE:
3121 params[0] = (GLfloat) v.value_ubyte;
3122 break;
3123
3124 case TYPE_SHORT:
3125 params[0] = (GLfloat) v.value_short;
3126 break;
3127
3128 case TYPE_MATRIX:
3129 m = *(GLmatrix **) &v;
3130 for (i = 0; i < 16; i++)
3131 params[i] = m->m[i];
3132 break;
3133
3134 case TYPE_MATRIX_T:
3135 m = *(GLmatrix **) &v;
3136 for (i = 0; i < 16; i++)
3137 params[i] = m->m[transpose[i]];
3138 break;
3139
3140 default:
3141 ;
3142 }
3143 }
3144
3145 void GLAPIENTRY
_mesa_GetDoublei_v(GLenum pname,GLuint index,GLdouble * params)3146 _mesa_GetDoublei_v(GLenum pname, GLuint index, GLdouble *params)
3147 {
3148 int i;
3149 GLmatrix *m;
3150 union value v;
3151 enum value_type type =
3152 find_value_indexed("glGetDoublei_v", pname, index, &v);
3153
3154 switch (type) {
3155 case TYPE_FLOAT_4:
3156 case TYPE_FLOATN_4:
3157 params[3] = (GLdouble) v.value_float_4[3];
3158 /* fallthrough */
3159 case TYPE_FLOAT_3:
3160 case TYPE_FLOATN_3:
3161 params[2] = (GLdouble) v.value_float_4[2];
3162 /* fallthrough */
3163 case TYPE_FLOAT_2:
3164 case TYPE_FLOATN_2:
3165 params[1] = (GLdouble) v.value_float_4[1];
3166 /* fallthrough */
3167 case TYPE_FLOAT:
3168 case TYPE_FLOATN:
3169 params[0] = (GLdouble) v.value_float_4[0];
3170 break;
3171
3172 case TYPE_DOUBLEN_2:
3173 params[1] = v.value_double_2[1];
3174 /* fallthrough */
3175 case TYPE_DOUBLEN:
3176 params[0] = v.value_double_2[0];
3177 break;
3178
3179 case TYPE_INT_4:
3180 params[3] = (GLdouble) v.value_int_4[3];
3181 /* fallthrough */
3182 case TYPE_INT_3:
3183 params[2] = (GLdouble) v.value_int_4[2];
3184 /* fallthrough */
3185 case TYPE_INT_2:
3186 case TYPE_ENUM_2:
3187 params[1] = (GLdouble) v.value_int_4[1];
3188 /* fallthrough */
3189 case TYPE_INT:
3190 case TYPE_ENUM:
3191 case TYPE_ENUM16:
3192 params[0] = (GLdouble) v.value_int_4[0];
3193 break;
3194
3195 case TYPE_INT_N:
3196 for (i = 0; i < v.value_int_n.n; i++)
3197 params[i] = (GLdouble) v.value_int_n.ints[i];
3198 break;
3199
3200 case TYPE_UINT_4:
3201 params[3] = (GLdouble) ((GLuint) v.value_int_4[3]);
3202 /* fallthrough */
3203 case TYPE_UINT_3:
3204 params[2] = (GLdouble) ((GLuint) v.value_int_4[2]);
3205 /* fallthrough */
3206 case TYPE_UINT_2:
3207 params[1] = (GLdouble) ((GLuint) v.value_int_4[1]);
3208 /* fallthrough */
3209 case TYPE_UINT:
3210 params[0] = (GLdouble) ((GLuint) v.value_int_4[0]);
3211 break;
3212
3213 case TYPE_INT64:
3214 params[0] = (GLdouble) v.value_int64;
3215 break;
3216
3217 case TYPE_BOOLEAN:
3218 params[0] = (GLdouble) BOOLEAN_TO_FLOAT(v.value_bool);
3219 break;
3220
3221 case TYPE_UBYTE:
3222 params[0] = (GLdouble) v.value_ubyte;
3223 break;
3224
3225 case TYPE_SHORT:
3226 params[0] = (GLdouble) v.value_short;
3227 break;
3228
3229 case TYPE_MATRIX:
3230 m = *(GLmatrix **) &v;
3231 for (i = 0; i < 16; i++)
3232 params[i] = (GLdouble) m->m[i];
3233 break;
3234
3235 case TYPE_MATRIX_T:
3236 m = *(GLmatrix **) &v;
3237 for (i = 0; i < 16; i++)
3238 params[i] = (GLdouble) m->m[transpose[i]];
3239 break;
3240
3241 default:
3242 ;
3243 }
3244 }
3245
3246 void GLAPIENTRY
_mesa_GetUnsignedBytei_vEXT(GLenum target,GLuint index,GLubyte * data)3247 _mesa_GetUnsignedBytei_vEXT(GLenum target, GLuint index, GLubyte *data)
3248 {
3249 GLsizei size;
3250 union value v;
3251 enum value_type type;
3252 const char *func = "glGetUnsignedBytei_vEXT";
3253
3254 GET_CURRENT_CONTEXT(ctx);
3255
3256 if (!ctx->Extensions.EXT_memory_object) {
3257 _mesa_error(ctx, GL_INVALID_OPERATION, "%s(unsupported)", func);
3258 return;
3259 }
3260
3261 type = find_value_indexed(func, target, index, &v);
3262 size = get_value_size(type, &v);
3263
3264 switch (type) {
3265 case TYPE_UINT:
3266 case TYPE_INT:
3267 case TYPE_INT_2:
3268 case TYPE_UINT_2:
3269 case TYPE_INT_3:
3270 case TYPE_UINT_3:
3271 case TYPE_INT_4:
3272 case TYPE_UINT_4:
3273 case TYPE_INT64:
3274 case TYPE_ENUM16:
3275 case TYPE_ENUM:
3276 case TYPE_ENUM_2:
3277 case TYPE_BOOLEAN:
3278 case TYPE_UBYTE:
3279 case TYPE_SHORT:
3280 case TYPE_FLOAT:
3281 case TYPE_FLOATN:
3282 case TYPE_FLOAT_2:
3283 case TYPE_FLOATN_2:
3284 case TYPE_FLOAT_3:
3285 case TYPE_FLOATN_3:
3286 case TYPE_FLOAT_4:
3287 case TYPE_FLOATN_4:
3288 case TYPE_FLOAT_8:
3289 case TYPE_DOUBLEN:
3290 case TYPE_DOUBLEN_2:
3291 case TYPE_MATRIX:
3292 case TYPE_MATRIX_T:
3293 memcpy(data, &v.value_int, size);
3294 break;
3295 case TYPE_INT_N:
3296 memcpy(data, &v.value_int_n.ints, size);
3297 break;
3298 default:
3299 break; /* nothing - GL error was recorded */
3300 }
3301 }
3302
3303 void GLAPIENTRY
_mesa_GetFixedv(GLenum pname,GLfixed * params)3304 _mesa_GetFixedv(GLenum pname, GLfixed *params)
3305 {
3306 const struct value_desc *d;
3307 union value v;
3308 GLmatrix *m;
3309 int shift, i;
3310 void *p;
3311
3312 d = find_value("glGetDoublev", pname, &p, &v);
3313 switch (d->type) {
3314 case TYPE_INVALID:
3315 break;
3316 case TYPE_CONST:
3317 params[0] = INT_TO_FIXED(d->offset);
3318 break;
3319
3320 case TYPE_FLOAT_4:
3321 case TYPE_FLOATN_4:
3322 params[3] = FLOAT_TO_FIXED(((GLfloat *) p)[3]);
3323 /* fallthrough */
3324 case TYPE_FLOAT_3:
3325 case TYPE_FLOATN_3:
3326 params[2] = FLOAT_TO_FIXED(((GLfloat *) p)[2]);
3327 /* fallthrough */
3328 case TYPE_FLOAT_2:
3329 case TYPE_FLOATN_2:
3330 params[1] = FLOAT_TO_FIXED(((GLfloat *) p)[1]);
3331 /* fallthrough */
3332 case TYPE_FLOAT:
3333 case TYPE_FLOATN:
3334 params[0] = FLOAT_TO_FIXED(((GLfloat *) p)[0]);
3335 break;
3336
3337 case TYPE_DOUBLEN_2:
3338 params[1] = FLOAT_TO_FIXED(((GLdouble *) p)[1]);
3339 /* fallthrough */
3340 case TYPE_DOUBLEN:
3341 params[0] = FLOAT_TO_FIXED(((GLdouble *) p)[0]);
3342 break;
3343
3344 case TYPE_INT_4:
3345 case TYPE_UINT_4:
3346 params[3] = INT_TO_FIXED(((GLint *) p)[3]);
3347 /* fallthrough */
3348 case TYPE_INT_3:
3349 case TYPE_UINT_3:
3350 params[2] = INT_TO_FIXED(((GLint *) p)[2]);
3351 /* fallthrough */
3352 case TYPE_INT_2:
3353 case TYPE_UINT_2:
3354 case TYPE_ENUM_2:
3355 params[1] = INT_TO_FIXED(((GLint *) p)[1]);
3356 /* fallthrough */
3357 case TYPE_INT:
3358 case TYPE_UINT:
3359 case TYPE_ENUM:
3360 params[0] = INT_TO_FIXED(((GLint *) p)[0]);
3361 break;
3362
3363 case TYPE_ENUM16:
3364 params[0] = INT_TO_FIXED((GLint)(((GLenum16 *) p)[0]));
3365 break;
3366
3367 case TYPE_INT_N:
3368 for (i = 0; i < v.value_int_n.n; i++)
3369 params[i] = INT_TO_FIXED(v.value_int_n.ints[i]);
3370 break;
3371
3372 case TYPE_INT64:
3373 params[0] = ((GLint64 *) p)[0];
3374 break;
3375
3376 case TYPE_BOOLEAN:
3377 params[0] = BOOLEAN_TO_FIXED(((GLboolean*) p)[0]);
3378 break;
3379
3380 case TYPE_UBYTE:
3381 params[0] = INT_TO_FIXED(((GLubyte *) p)[0]);
3382 break;
3383
3384 case TYPE_SHORT:
3385 params[0] = INT_TO_FIXED(((GLshort *) p)[0]);
3386 break;
3387
3388 case TYPE_MATRIX:
3389 m = *(GLmatrix **) p;
3390 for (i = 0; i < 16; i++)
3391 params[i] = FLOAT_TO_FIXED(m->m[i]);
3392 break;
3393
3394 case TYPE_MATRIX_T:
3395 m = *(GLmatrix **) p;
3396 for (i = 0; i < 16; i++)
3397 params[i] = FLOAT_TO_FIXED(m->m[transpose[i]]);
3398 break;
3399
3400 case TYPE_BIT_0:
3401 case TYPE_BIT_1:
3402 case TYPE_BIT_2:
3403 case TYPE_BIT_3:
3404 case TYPE_BIT_4:
3405 case TYPE_BIT_5:
3406 case TYPE_BIT_6:
3407 case TYPE_BIT_7:
3408 shift = d->type - TYPE_BIT_0;
3409 params[0] = BOOLEAN_TO_FIXED((*(GLbitfield *) p >> shift) & 1);
3410 break;
3411 }
3412 }
3413