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