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