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