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