bd69ea8f67771ccdeec5ade09e25cc79b9081abd
[mesa.git] / src / mesa / main / formatquery.c
1 /*
2 * Copyright © 2012 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * 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 OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 */
23
24 #include "mtypes.h"
25 #include "context.h"
26 #include "glformats.h"
27 #include "macros.h"
28 #include "enums.h"
29 #include "fbobject.h"
30 #include "formatquery.h"
31 #include "teximage.h"
32 #include "texparam.h"
33 #include "texobj.h"
34 #include "get.h"
35 #include "genmipmap.h"
36
37 static bool
38 _is_renderable(struct gl_context *ctx, GLenum internalformat)
39 {
40 /* Section 4.4.4 on page 212 of the GLES 3.0.4 spec says:
41 *
42 * "An internal format is color-renderable if it is one of the
43 * formats from table 3.13 noted as color-renderable or if it
44 * is unsized format RGBA or RGB."
45 *
46 * Therefore, we must accept GL_RGB and GL_RGBA here.
47 */
48 if (internalformat != GL_RGB && internalformat != GL_RGBA &&
49 _mesa_base_fbo_format(ctx, internalformat) == 0)
50 return false;
51
52 return true;
53 }
54
55 /* Handles the cases where either ARB_internalformat_query or
56 * ARB_internalformat_query2 have to return an error.
57 */
58 static bool
59 _legal_parameters(struct gl_context *ctx, GLenum target, GLenum internalformat,
60 GLenum pname, GLsizei bufSize, GLint *params)
61
62 {
63 bool query2 = _mesa_has_ARB_internalformat_query2(ctx);
64
65 /* The ARB_internalformat_query2 spec says:
66 *
67 * "The INVALID_ENUM error is generated if the <target> parameter to
68 * GetInternalformati*v is not one of the targets listed in Table 6.xx.
69 */
70 switch(target){
71 case GL_TEXTURE_1D:
72 case GL_TEXTURE_1D_ARRAY:
73 case GL_TEXTURE_2D:
74 case GL_TEXTURE_2D_ARRAY:
75 case GL_TEXTURE_3D:
76 case GL_TEXTURE_CUBE_MAP:
77 case GL_TEXTURE_CUBE_MAP_ARRAY:
78 case GL_TEXTURE_RECTANGLE:
79 case GL_TEXTURE_BUFFER:
80 if (!query2) {
81 /* The ARB_internalformat_query spec says:
82 *
83 * "If the <target> parameter to GetInternalformativ is not one of
84 * TEXTURE_2D_MULTISAMPLE, TEXTURE_2D_MULTISAMPLE_ARRAY
85 * or RENDERBUFFER then an INVALID_ENUM error is generated.
86 */
87 _mesa_error(ctx, GL_INVALID_ENUM,
88 "glGetInternalformativ(target=%s)",
89 _mesa_enum_to_string(target));
90
91 return false;
92 }
93 break;
94
95 case GL_RENDERBUFFER:
96 break;
97
98 case GL_TEXTURE_2D_MULTISAMPLE:
99 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY:
100 /* The non-existence of ARB_texture_multisample is treated in
101 * ARB_internalformat_query implementation like an error.
102 */
103 if (!query2 &&
104 !(_mesa_has_ARB_texture_multisample(ctx) || _mesa_is_gles31(ctx))) {
105 _mesa_error(ctx, GL_INVALID_ENUM,
106 "glGetInternalformativ(target=%s)",
107 _mesa_enum_to_string(target));
108
109 return false;
110 }
111 break;
112
113 default:
114 _mesa_error(ctx, GL_INVALID_ENUM,
115 "glGetInternalformativ(target=%s)",
116 _mesa_enum_to_string(target));
117 return false;
118 }
119
120
121 /* The ARB_internalformat_query2 spec says:
122 *
123 * "The INVALID_ENUM error is generated if the <pname> parameter is
124 * not one of the listed possibilities.
125 */
126 switch(pname){
127 case GL_SAMPLES:
128 case GL_NUM_SAMPLE_COUNTS:
129 break;
130
131 case GL_SRGB_DECODE_ARB:
132 /* The ARB_internalformat_query2 spec says:
133 *
134 * "If ARB_texture_sRGB_decode or EXT_texture_sRGB_decode or
135 * equivalent functionality is not supported, queries for the
136 * SRGB_DECODE_ARB <pname> set the INVALID_ENUM error.
137 */
138 if (!_mesa_has_EXT_texture_sRGB_decode(ctx)) {
139 _mesa_error(ctx, GL_INVALID_ENUM,
140 "glGetInternalformativ(pname=%s)",
141 _mesa_enum_to_string(pname));
142 return false;
143 }
144 /* fallthrough */
145 case GL_INTERNALFORMAT_SUPPORTED:
146 case GL_INTERNALFORMAT_PREFERRED:
147 case GL_INTERNALFORMAT_RED_SIZE:
148 case GL_INTERNALFORMAT_GREEN_SIZE:
149 case GL_INTERNALFORMAT_BLUE_SIZE:
150 case GL_INTERNALFORMAT_ALPHA_SIZE:
151 case GL_INTERNALFORMAT_DEPTH_SIZE:
152 case GL_INTERNALFORMAT_STENCIL_SIZE:
153 case GL_INTERNALFORMAT_SHARED_SIZE:
154 case GL_INTERNALFORMAT_RED_TYPE:
155 case GL_INTERNALFORMAT_GREEN_TYPE:
156 case GL_INTERNALFORMAT_BLUE_TYPE:
157 case GL_INTERNALFORMAT_ALPHA_TYPE:
158 case GL_INTERNALFORMAT_DEPTH_TYPE:
159 case GL_INTERNALFORMAT_STENCIL_TYPE:
160 case GL_MAX_WIDTH:
161 case GL_MAX_HEIGHT:
162 case GL_MAX_DEPTH:
163 case GL_MAX_LAYERS:
164 case GL_MAX_COMBINED_DIMENSIONS:
165 case GL_COLOR_COMPONENTS:
166 case GL_DEPTH_COMPONENTS:
167 case GL_STENCIL_COMPONENTS:
168 case GL_COLOR_RENDERABLE:
169 case GL_DEPTH_RENDERABLE:
170 case GL_STENCIL_RENDERABLE:
171 case GL_FRAMEBUFFER_RENDERABLE:
172 case GL_FRAMEBUFFER_RENDERABLE_LAYERED:
173 case GL_FRAMEBUFFER_BLEND:
174 case GL_READ_PIXELS:
175 case GL_READ_PIXELS_FORMAT:
176 case GL_READ_PIXELS_TYPE:
177 case GL_TEXTURE_IMAGE_FORMAT:
178 case GL_TEXTURE_IMAGE_TYPE:
179 case GL_GET_TEXTURE_IMAGE_FORMAT:
180 case GL_GET_TEXTURE_IMAGE_TYPE:
181 case GL_MIPMAP:
182 case GL_MANUAL_GENERATE_MIPMAP:
183 case GL_AUTO_GENERATE_MIPMAP:
184 case GL_COLOR_ENCODING:
185 case GL_SRGB_READ:
186 case GL_SRGB_WRITE:
187 case GL_FILTER:
188 case GL_VERTEX_TEXTURE:
189 case GL_TESS_CONTROL_TEXTURE:
190 case GL_TESS_EVALUATION_TEXTURE:
191 case GL_GEOMETRY_TEXTURE:
192 case GL_FRAGMENT_TEXTURE:
193 case GL_COMPUTE_TEXTURE:
194 case GL_TEXTURE_SHADOW:
195 case GL_TEXTURE_GATHER:
196 case GL_TEXTURE_GATHER_SHADOW:
197 case GL_SHADER_IMAGE_LOAD:
198 case GL_SHADER_IMAGE_STORE:
199 case GL_SHADER_IMAGE_ATOMIC:
200 case GL_IMAGE_TEXEL_SIZE:
201 case GL_IMAGE_COMPATIBILITY_CLASS:
202 case GL_IMAGE_PIXEL_FORMAT:
203 case GL_IMAGE_PIXEL_TYPE:
204 case GL_IMAGE_FORMAT_COMPATIBILITY_TYPE:
205 case GL_SIMULTANEOUS_TEXTURE_AND_DEPTH_TEST:
206 case GL_SIMULTANEOUS_TEXTURE_AND_STENCIL_TEST:
207 case GL_SIMULTANEOUS_TEXTURE_AND_DEPTH_WRITE:
208 case GL_SIMULTANEOUS_TEXTURE_AND_STENCIL_WRITE:
209 case GL_TEXTURE_COMPRESSED:
210 case GL_TEXTURE_COMPRESSED_BLOCK_WIDTH:
211 case GL_TEXTURE_COMPRESSED_BLOCK_HEIGHT:
212 case GL_TEXTURE_COMPRESSED_BLOCK_SIZE:
213 case GL_CLEAR_BUFFER:
214 case GL_TEXTURE_VIEW:
215 case GL_VIEW_COMPATIBILITY_CLASS:
216 /* The ARB_internalformat_query spec says:
217 *
218 * "If the <pname> parameter to GetInternalformativ is not SAMPLES
219 * or NUM_SAMPLE_COUNTS, then an INVALID_ENUM error is generated."
220 */
221 if (!query2) {
222 _mesa_error(ctx, GL_INVALID_ENUM,
223 "glGetInternalformativ(pname=%s)",
224 _mesa_enum_to_string(pname));
225
226 return false;
227 }
228 break;
229
230 default:
231 _mesa_error(ctx, GL_INVALID_ENUM,
232 "glGetInternalformativ(pname=%s)",
233 _mesa_enum_to_string(pname));
234 return false;
235 }
236
237 /* The ARB_internalformat_query spec says:
238 *
239 * "If the <bufSize> parameter to GetInternalformativ is negative, then
240 * an INVALID_VALUE error is generated."
241 *
242 * Nothing is said in ARB_internalformat_query2 but we assume the same.
243 */
244 if (bufSize < 0) {
245 _mesa_error(ctx, GL_INVALID_VALUE,
246 "glGetInternalformativ(target=%s)",
247 _mesa_enum_to_string(target));
248 return false;
249 }
250
251 /* The ARB_internalformat_query spec says:
252 *
253 * "If the <internalformat> parameter to GetInternalformativ is not
254 * color-, depth- or stencil-renderable, then an INVALID_ENUM error is
255 * generated."
256 */
257 if (!query2 && !_is_renderable(ctx, internalformat)) {
258 _mesa_error(ctx, GL_INVALID_ENUM,
259 "glGetInternalformativ(internalformat=%s)",
260 _mesa_enum_to_string(internalformat));
261 return false;
262 }
263
264 return true;
265 }
266
267 /* Sets the appropriate "unsupported" response as defined by the
268 * ARB_internalformat_query2 spec for each each <pname>.
269 */
270 static void
271 _set_default_response(GLenum pname, GLint buffer[16])
272 {
273 /* The ARB_internalformat_query2 defines which is the reponse best
274 * representing "not supported" or "not applicable" for each <pname>.
275 *
276 * " In general:
277 * - size- or count-based queries will return zero,
278 * - support-, format- or type-based queries will return NONE,
279 * - boolean-based queries will return FALSE, and
280 * - list-based queries return no entries."
281 */
282 switch(pname) {
283 case GL_SAMPLES:
284 break;
285
286 case GL_MAX_COMBINED_DIMENSIONS:
287 /* This value can be a 64-bit value. As the default is the 32-bit query,
288 * we pack 2 32-bit integers. So we need to clean both */
289 buffer[0] = 0;
290 buffer[1] = 0;
291 break;
292
293 case GL_NUM_SAMPLE_COUNTS:
294 case GL_INTERNALFORMAT_RED_SIZE:
295 case GL_INTERNALFORMAT_GREEN_SIZE:
296 case GL_INTERNALFORMAT_BLUE_SIZE:
297 case GL_INTERNALFORMAT_ALPHA_SIZE:
298 case GL_INTERNALFORMAT_DEPTH_SIZE:
299 case GL_INTERNALFORMAT_STENCIL_SIZE:
300 case GL_INTERNALFORMAT_SHARED_SIZE:
301 case GL_MAX_WIDTH:
302 case GL_MAX_HEIGHT:
303 case GL_MAX_DEPTH:
304 case GL_MAX_LAYERS:
305 case GL_IMAGE_TEXEL_SIZE:
306 case GL_TEXTURE_COMPRESSED_BLOCK_WIDTH:
307 case GL_TEXTURE_COMPRESSED_BLOCK_HEIGHT:
308 case GL_TEXTURE_COMPRESSED_BLOCK_SIZE:
309 buffer[0] = 0;
310 break;
311
312 case GL_INTERNALFORMAT_PREFERRED:
313 case GL_INTERNALFORMAT_RED_TYPE:
314 case GL_INTERNALFORMAT_GREEN_TYPE:
315 case GL_INTERNALFORMAT_BLUE_TYPE:
316 case GL_INTERNALFORMAT_ALPHA_TYPE:
317 case GL_INTERNALFORMAT_DEPTH_TYPE:
318 case GL_INTERNALFORMAT_STENCIL_TYPE:
319 case GL_FRAMEBUFFER_RENDERABLE:
320 case GL_FRAMEBUFFER_RENDERABLE_LAYERED:
321 case GL_FRAMEBUFFER_BLEND:
322 case GL_READ_PIXELS:
323 case GL_READ_PIXELS_FORMAT:
324 case GL_READ_PIXELS_TYPE:
325 case GL_TEXTURE_IMAGE_FORMAT:
326 case GL_TEXTURE_IMAGE_TYPE:
327 case GL_GET_TEXTURE_IMAGE_FORMAT:
328 case GL_GET_TEXTURE_IMAGE_TYPE:
329 case GL_MANUAL_GENERATE_MIPMAP:
330 case GL_AUTO_GENERATE_MIPMAP:
331 case GL_COLOR_ENCODING:
332 case GL_SRGB_READ:
333 case GL_SRGB_WRITE:
334 case GL_SRGB_DECODE_ARB:
335 case GL_FILTER:
336 case GL_VERTEX_TEXTURE:
337 case GL_TESS_CONTROL_TEXTURE:
338 case GL_TESS_EVALUATION_TEXTURE:
339 case GL_GEOMETRY_TEXTURE:
340 case GL_FRAGMENT_TEXTURE:
341 case GL_COMPUTE_TEXTURE:
342 case GL_TEXTURE_SHADOW:
343 case GL_TEXTURE_GATHER:
344 case GL_TEXTURE_GATHER_SHADOW:
345 case GL_SHADER_IMAGE_LOAD:
346 case GL_SHADER_IMAGE_STORE:
347 case GL_SHADER_IMAGE_ATOMIC:
348 case GL_IMAGE_COMPATIBILITY_CLASS:
349 case GL_IMAGE_PIXEL_FORMAT:
350 case GL_IMAGE_PIXEL_TYPE:
351 case GL_IMAGE_FORMAT_COMPATIBILITY_TYPE:
352 case GL_SIMULTANEOUS_TEXTURE_AND_DEPTH_TEST:
353 case GL_SIMULTANEOUS_TEXTURE_AND_STENCIL_TEST:
354 case GL_SIMULTANEOUS_TEXTURE_AND_DEPTH_WRITE:
355 case GL_SIMULTANEOUS_TEXTURE_AND_STENCIL_WRITE:
356 case GL_CLEAR_BUFFER:
357 case GL_TEXTURE_VIEW:
358 case GL_VIEW_COMPATIBILITY_CLASS:
359 buffer[0] = GL_NONE;
360 break;
361
362 case GL_INTERNALFORMAT_SUPPORTED:
363 case GL_COLOR_COMPONENTS:
364 case GL_DEPTH_COMPONENTS:
365 case GL_STENCIL_COMPONENTS:
366 case GL_COLOR_RENDERABLE:
367 case GL_DEPTH_RENDERABLE:
368 case GL_STENCIL_RENDERABLE:
369 case GL_MIPMAP:
370 case GL_TEXTURE_COMPRESSED:
371 buffer[0] = GL_FALSE;
372 break;
373
374 default:
375 unreachable("invalid 'pname'");
376 }
377 }
378
379 static bool
380 _is_target_supported(struct gl_context *ctx, GLenum target)
381 {
382 /* The ARB_internalformat_query2 spec says:
383 *
384 * "if a particular type of <target> is not supported by the
385 * implementation the "unsupported" answer should be given.
386 * This is not an error."
387 */
388 switch(target){
389 case GL_TEXTURE_2D:
390 case GL_TEXTURE_3D:
391 break;
392
393 case GL_TEXTURE_1D:
394 if (!_mesa_is_desktop_gl(ctx))
395 return false;
396 break;
397
398 case GL_TEXTURE_1D_ARRAY:
399 if (!_mesa_has_EXT_texture_array(ctx))
400 return false;
401 break;
402
403 case GL_TEXTURE_2D_ARRAY:
404 if (!(_mesa_has_EXT_texture_array(ctx) || _mesa_is_gles3(ctx)))
405 return false;
406 break;
407
408 case GL_TEXTURE_CUBE_MAP:
409 if (!_mesa_has_ARB_texture_cube_map(ctx))
410 return false;
411 break;
412
413 case GL_TEXTURE_CUBE_MAP_ARRAY:
414 if (!_mesa_has_ARB_texture_cube_map_array(ctx))
415 return false;
416 break;
417
418 case GL_TEXTURE_RECTANGLE:
419 if (!_mesa_has_NV_texture_rectangle(ctx))
420 return false;
421 break;
422
423 case GL_TEXTURE_BUFFER:
424 if (!_mesa_has_ARB_texture_buffer_object(ctx))
425 return false;
426 break;
427
428 case GL_RENDERBUFFER:
429 if (!(_mesa_has_ARB_framebuffer_object(ctx) ||
430 _mesa_is_gles3(ctx)))
431 return false;
432 break;
433
434 case GL_TEXTURE_2D_MULTISAMPLE:
435 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY:
436 if (!(_mesa_has_ARB_texture_multisample(ctx) ||
437 _mesa_is_gles31(ctx)))
438 return false;
439 break;
440
441 default:
442 unreachable("invalid target");
443 }
444
445 return true;
446 }
447
448 static bool
449 _is_resource_supported(struct gl_context *ctx, GLenum target,
450 GLenum internalformat, GLenum pname)
451 {
452 /* From the ARB_internalformat_query2 spec:
453 *
454 * In the following descriptions, the term /resource/ is used to generically
455 * refer to an object of the appropriate type that has been created with
456 * <internalformat> and <target>. If the particular <target> and
457 * <internalformat> combination do not make sense, ... the "unsupported"
458 * answer should be given. This is not an error.
459 */
460
461 /* In the ARB_internalformat_query2 spec wording, some <pnames> do not care
462 * about the /resource/ being supported or not, we return 'true' for those.
463 */
464 switch (pname) {
465 case GL_INTERNALFORMAT_SUPPORTED:
466 case GL_INTERNALFORMAT_PREFERRED:
467 case GL_COLOR_COMPONENTS:
468 case GL_DEPTH_COMPONENTS:
469 case GL_STENCIL_COMPONENTS:
470 case GL_COLOR_RENDERABLE:
471 case GL_DEPTH_RENDERABLE:
472 case GL_STENCIL_RENDERABLE:
473 return true;
474 default:
475 break;
476 }
477
478 switch(target){
479 case GL_TEXTURE_1D:
480 case GL_TEXTURE_1D_ARRAY:
481 case GL_TEXTURE_2D:
482 case GL_TEXTURE_2D_ARRAY:
483 case GL_TEXTURE_3D:
484 case GL_TEXTURE_CUBE_MAP:
485 case GL_TEXTURE_CUBE_MAP_ARRAY:
486 case GL_TEXTURE_RECTANGLE:
487 /* Based on what Mesa does for glTexImage1D/2D/3D and
488 * glCompressedTexImage1D/2D/3D functions.
489 */
490 if (_mesa_base_tex_format(ctx, internalformat) < 0)
491 return false;
492
493 /* additional checks for depth textures */
494 if (!_mesa_legal_texture_base_format_for_target(ctx, target, internalformat))
495 return false;
496
497 /* additional checks for compressed textures */
498 if (_mesa_is_compressed_format(ctx, internalformat) &&
499 (!_mesa_target_can_be_compressed(ctx, target, internalformat, NULL) ||
500 _mesa_format_no_online_compression(ctx, internalformat)))
501 return false;
502
503 break;
504 case GL_TEXTURE_2D_MULTISAMPLE:
505 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY:
506 /* Based on what Mesa does for glTexImage2D/3DMultisample,
507 * glTexStorage2D/3DMultisample and
508 * glTextureStorage2D/3DMultisample functions.
509 */
510 if (!_mesa_is_renderable_texture_format(ctx, internalformat))
511 return false;
512
513 break;
514 case GL_TEXTURE_BUFFER:
515 /* Based on what Mesa does for the glTexBuffer function. */
516 if (_mesa_validate_texbuffer_format(ctx, internalformat) ==
517 MESA_FORMAT_NONE)
518 return false;
519
520 break;
521 case GL_RENDERBUFFER:
522 /* Based on what Mesa does for glRenderbufferStorage(Multisample) and
523 * glNamedRenderbufferStorage functions.
524 */
525 if (!_mesa_base_fbo_format(ctx, internalformat))
526 return false;
527
528 break;
529 default:
530 unreachable("bad target");
531 }
532
533 return true;
534 }
535
536 static bool
537 _is_internalformat_supported(struct gl_context *ctx, GLenum target,
538 GLenum internalformat)
539 {
540 /* From the ARB_internalformat_query2 specification:
541 *
542 * "- INTERNALFORMAT_SUPPORTED: If <internalformat> is an internal format
543 * that is supported by the implementation in at least some subset of
544 * possible operations, TRUE is written to <params>. If <internalformat>
545 * if not a valid token for any internal format usage, FALSE is returned.
546 *
547 * <internalformats> that must be supported (in GL 4.2 or later) include
548 * the following:
549 * - "sized internal formats" from Table 3.12, 3.13, and 3.15,
550 * - any specific "compressed internal format" from Table 3.14,
551 * - any "image unit format" from Table 3.21.
552 * - any generic "compressed internal format" from Table 3.14, if the
553 * implementation accepts it for any texture specification commands, and
554 * - unsized or base internal format, if the implementation accepts
555 * it for texture or image specification.
556 */
557 GLint buffer[1];
558
559 /* At this point a internalformat is valid if it is valid as a texture or
560 * as a renderbuffer format. The checks are different because those methods
561 * return different values when passing non supported internalformats */
562 if (_mesa_base_tex_format(ctx, internalformat) < 0 &&
563 _mesa_base_fbo_format(ctx, internalformat) == 0)
564 return false;
565
566 /* Let the driver have the final word */
567 ctx->Driver.QueryInternalFormat(ctx, target, internalformat,
568 GL_INTERNALFORMAT_SUPPORTED, buffer);
569
570 return (buffer[0] == GL_TRUE);
571 }
572
573 /* default implementation of QueryInternalFormat driverfunc, for
574 * drivers not implementing ARB_internalformat_query2.
575 */
576 void
577 _mesa_query_internal_format_default(struct gl_context *ctx, GLenum target,
578 GLenum internalFormat, GLenum pname,
579 GLint *params)
580 {
581 (void) ctx;
582 (void) target;
583 (void) internalFormat;
584
585 switch (pname) {
586 case GL_SAMPLES:
587 case GL_NUM_SAMPLE_COUNTS:
588 params[0] = 1;
589 break;
590
591 case GL_INTERNALFORMAT_SUPPORTED:
592 params[0] = GL_TRUE;
593 break;
594
595 case GL_INTERNALFORMAT_PREFERRED:
596 params[0] = internalFormat;
597 break;
598
599 case GL_MANUAL_GENERATE_MIPMAP:
600 case GL_AUTO_GENERATE_MIPMAP:
601 params[0] = GL_FULL_SUPPORT;
602 break;
603
604 default:
605 _set_default_response(pname, params);
606 break;
607 }
608 }
609
610 /*
611 * For MAX_WIDTH/MAX_HEIGHT/MAX_DEPTH it returns the equivalent GetInteger
612 * pname for a Getinternalformat pname/target combination. target/pname
613 * combinations that would return 0 due dimension number or unsupported status
614 * should be already filtered out
615 *
616 * Note that this means that the returned value would be independent of the
617 * internalformat. This possibility is already mentioned at the Issue 7 of the
618 * arb_internalformat_query2 spec.
619 */
620 static GLenum
621 equivalentSizePname(GLenum target,
622 GLenum pname)
623 {
624 switch (target) {
625 case GL_TEXTURE_1D:
626 case GL_TEXTURE_2D:
627 case GL_TEXTURE_2D_MULTISAMPLE:
628 return GL_MAX_TEXTURE_SIZE;
629 case GL_TEXTURE_3D:
630 return GL_MAX_3D_TEXTURE_SIZE;
631 case GL_TEXTURE_CUBE_MAP:
632 return GL_MAX_CUBE_MAP_TEXTURE_SIZE;
633 case GL_TEXTURE_RECTANGLE:
634 return GL_MAX_RECTANGLE_TEXTURE_SIZE;
635 case GL_RENDERBUFFER:
636 return GL_MAX_RENDERBUFFER_SIZE;
637 case GL_TEXTURE_1D_ARRAY:
638 if (pname == GL_MAX_HEIGHT)
639 return GL_MAX_ARRAY_TEXTURE_LAYERS;
640 else
641 return GL_MAX_TEXTURE_SIZE;
642 case GL_TEXTURE_2D_ARRAY:
643 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY:
644 if (pname == GL_MAX_DEPTH)
645 return GL_MAX_ARRAY_TEXTURE_LAYERS;
646 else
647 return GL_MAX_TEXTURE_SIZE;
648 case GL_TEXTURE_CUBE_MAP_ARRAY:
649 if (pname == GL_MAX_DEPTH)
650 return GL_MAX_ARRAY_TEXTURE_LAYERS;
651 else
652 return GL_MAX_CUBE_MAP_TEXTURE_SIZE;
653 case GL_TEXTURE_BUFFER:
654 return GL_MAX_TEXTURE_BUFFER_SIZE;
655 default:
656 return 0;
657 }
658 }
659
660 /*
661 * Returns the dimensions associated to a target. GL_TEXTURE_BUFFER and
662 * GL_RENDERBUFFER have associated a dimension, but they are not textures
663 * per-se, so we can't just call _mesa_get_texture_dimension directly.
664 */
665 static GLint
666 get_target_dimensions(GLenum target)
667 {
668 switch(target) {
669 case GL_TEXTURE_BUFFER:
670 return 1;
671 case GL_RENDERBUFFER:
672 return 2;
673 default:
674 return _mesa_get_texture_dimensions(target);
675 }
676 }
677
678 /*
679 * Returns the minimum amount of dimensions associated to a pname. So for
680 * example, if querying GL_MAX_HEIGHT, it is assumed that your target would
681 * have as minimum 2 dimensions.
682 *
683 * Useful to handle sentences like this from query2 spec:
684 *
685 * "MAX_HEIGHT:
686 * <skip>
687 * If the resource does not have at least two dimensions
688 * <skip>."
689 */
690 static GLint
691 get_min_dimensions(GLenum pname)
692 {
693 switch(pname) {
694 case GL_MAX_WIDTH:
695 return 1;
696 case GL_MAX_HEIGHT:
697 return 2;
698 case GL_MAX_DEPTH:
699 return 3;
700 default:
701 return 0;
702 }
703 }
704
705 /*
706 * Similar to teximage.c:check_multisample_target, but independent of the
707 * dimensions.
708 */
709 static bool
710 is_multisample_target(GLenum target)
711 {
712 switch(target) {
713 case GL_TEXTURE_2D_MULTISAMPLE:
714 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY:
715 return true;
716 default:
717 return false;
718 }
719
720 }
721
722 void GLAPIENTRY
723 _mesa_GetInternalformativ(GLenum target, GLenum internalformat, GLenum pname,
724 GLsizei bufSize, GLint *params)
725 {
726 GLint buffer[16];
727 GET_CURRENT_CONTEXT(ctx);
728
729 ASSERT_OUTSIDE_BEGIN_END(ctx);
730
731 /* ARB_internalformat_query is also mandatory for ARB_internalformat_query2 */
732 if (!(_mesa_has_ARB_internalformat_query(ctx) ||
733 _mesa_is_gles3(ctx))) {
734 _mesa_error(ctx, GL_INVALID_OPERATION, "glGetInternalformativ");
735 return;
736 }
737
738 assert(ctx->Driver.QueryInternalFormat != NULL);
739
740 if (!_legal_parameters(ctx, target, internalformat, pname, bufSize, params))
741 return;
742
743 /* initialize the contents of the temporary buffer */
744 memcpy(buffer, params, MIN2(bufSize, 16) * sizeof(GLint));
745
746 /* Use the 'unsupported' response defined by the spec for every pname
747 * as the default answer.
748 */
749 _set_default_response(pname, buffer);
750
751 if (!_is_target_supported(ctx, target) ||
752 !_is_internalformat_supported(ctx, target, internalformat) ||
753 !_is_resource_supported(ctx, target, internalformat, pname))
754 goto end;
755
756 switch (pname) {
757 case GL_SAMPLES:
758 /* fall-through */
759 case GL_NUM_SAMPLE_COUNTS:
760 /* The ARB_internalformat_query2 sets the response as 'unsupported' for
761 * SAMPLES and NUM_SAMPLE_COUNTS:
762 *
763 * "If <internalformat> is not color-renderable, depth-renderable, or
764 * stencil-renderable (as defined in section 4.4.4), or if <target>
765 * does not support multiple samples (ie other than
766 * TEXTURE_2D_MULTISAMPLE, TEXTURE_2D_MULTISAMPLE_ARRAY,
767 * or RENDERBUFFER)."
768 */
769 if ((target != GL_RENDERBUFFER &&
770 target != GL_TEXTURE_2D_MULTISAMPLE &&
771 target != GL_TEXTURE_2D_MULTISAMPLE_ARRAY) ||
772 !_is_renderable(ctx, internalformat))
773 goto end;
774
775 /* The GL ES 3.0 specification, section 6.1.15 page 236 says:
776 *
777 * "Since multisampling is not supported for signed and unsigned
778 * integer internal formats, the value of NUM_SAMPLE_COUNTS will be
779 * zero for such formats.
780 */
781 if (pname == GL_NUM_SAMPLE_COUNTS && ctx->API == API_OPENGLES2 &&
782 ctx->Version == 30 && _mesa_is_enum_format_integer(internalformat)) {
783 goto end;
784 }
785
786 ctx->Driver.QueryInternalFormat(ctx, target, internalformat, pname,
787 buffer);
788 break;
789
790 case GL_INTERNALFORMAT_SUPPORTED:
791 /* Having a supported <internalformat> is implemented as a prerequisite
792 * for all the <pnames>. Thus, if we reach this point, the internalformat is
793 * supported.
794 */
795 buffer[0] = GL_TRUE;
796 break;
797
798 case GL_INTERNALFORMAT_PREFERRED:
799 /* The ARB_internalformat_query2 spec says:
800 *
801 * "- INTERNALFORMAT_PREFERRED: The implementation-preferred internal
802 * format for representing resources of the specified <internalformat> is
803 * returned in <params>.
804 *
805 * Therefore, we let the driver answer.
806 */
807 ctx->Driver.QueryInternalFormat(ctx, target, internalformat, pname,
808 buffer);
809 break;
810
811 case GL_INTERNALFORMAT_RED_SIZE:
812 case GL_INTERNALFORMAT_GREEN_SIZE:
813 case GL_INTERNALFORMAT_BLUE_SIZE:
814 case GL_INTERNALFORMAT_ALPHA_SIZE:
815 case GL_INTERNALFORMAT_DEPTH_SIZE:
816 case GL_INTERNALFORMAT_STENCIL_SIZE:
817 case GL_INTERNALFORMAT_SHARED_SIZE:
818 case GL_INTERNALFORMAT_RED_TYPE:
819 case GL_INTERNALFORMAT_GREEN_TYPE:
820 case GL_INTERNALFORMAT_BLUE_TYPE:
821 case GL_INTERNALFORMAT_ALPHA_TYPE:
822 case GL_INTERNALFORMAT_DEPTH_TYPE:
823 case GL_INTERNALFORMAT_STENCIL_TYPE: {
824 GLint baseformat;
825 mesa_format texformat;
826
827 if (target != GL_RENDERBUFFER) {
828 if (!_mesa_legal_get_tex_level_parameter_target(ctx, target, true))
829 goto end;
830
831 baseformat = _mesa_base_tex_format(ctx, internalformat);
832 } else {
833 baseformat = _mesa_base_fbo_format(ctx, internalformat);
834 }
835
836 /* Let the driver choose the texture format.
837 *
838 * Disclaimer: I am considering that drivers use for renderbuffers the
839 * same format-choice logic as for textures.
840 */
841 texformat = ctx->Driver.ChooseTextureFormat(ctx, target, internalformat,
842 GL_NONE /*format */, GL_NONE /* type */);
843
844 if (texformat == MESA_FORMAT_NONE || baseformat <= 0)
845 goto end;
846
847 /* Implementation based on what Mesa does for glGetTexLevelParameteriv
848 * and glGetRenderbufferParameteriv functions.
849 */
850 if (pname == GL_INTERNALFORMAT_SHARED_SIZE) {
851 if (_mesa_has_EXT_texture_shared_exponent(ctx) &&
852 target != GL_TEXTURE_BUFFER &&
853 target != GL_RENDERBUFFER &&
854 texformat == MESA_FORMAT_R9G9B9E5_FLOAT) {
855 buffer[0] = 5;
856 }
857 goto end;
858 }
859
860 if (!_mesa_base_format_has_channel(baseformat, pname))
861 goto end;
862
863 switch (pname) {
864 case GL_INTERNALFORMAT_DEPTH_SIZE:
865 if (!_mesa_has_ARB_depth_texture(ctx) &&
866 target != GL_RENDERBUFFER &&
867 target != GL_TEXTURE_BUFFER)
868 goto end;
869 /* fallthrough */
870 case GL_INTERNALFORMAT_RED_SIZE:
871 case GL_INTERNALFORMAT_GREEN_SIZE:
872 case GL_INTERNALFORMAT_BLUE_SIZE:
873 case GL_INTERNALFORMAT_ALPHA_SIZE:
874 case GL_INTERNALFORMAT_STENCIL_SIZE:
875 buffer[0] = _mesa_get_format_bits(texformat, pname);
876 break;
877
878 case GL_INTERNALFORMAT_DEPTH_TYPE:
879 if (!_mesa_has_ARB_texture_float(ctx))
880 goto end;
881 /* fallthrough */
882 case GL_INTERNALFORMAT_RED_TYPE:
883 case GL_INTERNALFORMAT_GREEN_TYPE:
884 case GL_INTERNALFORMAT_BLUE_TYPE:
885 case GL_INTERNALFORMAT_ALPHA_TYPE:
886 case GL_INTERNALFORMAT_STENCIL_TYPE:
887 buffer[0] = _mesa_get_format_datatype(texformat);
888 break;
889
890 default:
891 break;
892
893 }
894 break;
895 }
896
897 /* For WIDTH/HEIGHT/DEPTH/LAYERS there is no reason to think that the
898 * returned values should be different to the values returned by
899 * GetInteger with MAX_TEXTURE_SIZE, MAX_3D_TEXTURE_SIZE, etc.*/
900 case GL_MAX_WIDTH:
901 case GL_MAX_HEIGHT:
902 case GL_MAX_DEPTH: {
903 GLenum get_pname;
904 GLint dimensions;
905 GLint min_dimensions;
906
907 /* From query2:MAX_HEIGHT spec (as example):
908 *
909 * "If the resource does not have at least two dimensions, or if the
910 * resource is unsupported, zero is returned."
911 */
912 dimensions = get_target_dimensions(target);
913 min_dimensions = get_min_dimensions(pname);
914 if (dimensions < min_dimensions)
915 goto end;
916
917 get_pname = equivalentSizePname(target, pname);
918 if (get_pname == 0)
919 goto end;
920
921 _mesa_GetIntegerv(get_pname, buffer);
922 break;
923 }
924
925 case GL_MAX_LAYERS:
926 if (!_mesa_has_EXT_texture_array(ctx))
927 goto end;
928
929 if (!_mesa_is_array_texture(target))
930 goto end;
931
932 _mesa_GetIntegerv(GL_MAX_ARRAY_TEXTURE_LAYERS, buffer);
933 break;
934
935 case GL_MAX_COMBINED_DIMENSIONS:{
936 GLint64 combined_value = 1;
937 GLenum max_dimensions_pnames[] = {
938 GL_MAX_WIDTH,
939 GL_MAX_HEIGHT,
940 GL_MAX_DEPTH,
941 GL_SAMPLES
942 };
943 unsigned i;
944 GLint current_value;
945
946 /* Combining the dimensions. Note that for array targets, this would
947 * automatically include the value of MAX_LAYERS, as that value is
948 * returned as MAX_HEIGHT or MAX_DEPTH */
949 for (i = 0; i < 4; i++) {
950 if (max_dimensions_pnames[i] == GL_SAMPLES &&
951 !is_multisample_target(target))
952 continue;
953
954 _mesa_GetInternalformativ(target, internalformat,
955 max_dimensions_pnames[i],
956 1, &current_value);
957
958 if (current_value != 0)
959 combined_value *= current_value;
960 }
961
962 if (_mesa_is_cube_map_texture(target))
963 combined_value *= 6;
964
965 /* We pack the 64-bit value on two 32-bit values. Calling the 32-bit
966 * query, this would work as far as the value can be hold on a 32-bit
967 * signed integer. For the 64-bit query, the wrapper around the 32-bit
968 * query will unpack the value */
969 memcpy(buffer, &combined_value, sizeof(GLint64));
970 break;
971 }
972
973 case GL_COLOR_COMPONENTS:
974 /* The ARB_internalformat_query2 spec says:
975 *
976 * "- COLOR_COMPONENTS: If the internal format contains any color
977 * components (R, G, B, or A), TRUE is returned in <params>.
978 * If the internal format is unsupported or contains no color
979 * components, FALSE is returned."
980 */
981 if (_mesa_is_color_format(internalformat))
982 buffer[0] = GL_TRUE;
983 break;
984
985 case GL_DEPTH_COMPONENTS:
986 /* The ARB_internalformat_query2 spec says:
987 *
988 * "- DEPTH_COMPONENTS: If the internal format contains a depth
989 * component (D), TRUE is returned in <params>. If the internal format
990 * is unsupported or contains no depth component, FALSE is returned."
991 */
992 if (_mesa_is_depth_format(internalformat) ||
993 _mesa_is_depthstencil_format(internalformat))
994 buffer[0] = GL_TRUE;
995 break;
996
997 case GL_STENCIL_COMPONENTS:
998 /* The ARB_internalformat_query2 spec says:
999 *
1000 * "- STENCIL_COMPONENTS: If the internal format contains a stencil
1001 * component (S), TRUE is returned in <params>. If the internal format
1002 * is unsupported or contains no stencil component, FALSE is returned.
1003 */
1004 if (_mesa_is_stencil_format(internalformat) ||
1005 _mesa_is_depthstencil_format(internalformat))
1006 buffer[0] = GL_TRUE;
1007 break;
1008
1009 case GL_COLOR_RENDERABLE:
1010 case GL_DEPTH_RENDERABLE:
1011 case GL_STENCIL_RENDERABLE:
1012 if (!_is_renderable(ctx, internalformat))
1013 goto end;
1014
1015 if (pname == GL_COLOR_RENDERABLE) {
1016 if (!_mesa_is_color_format(internalformat))
1017 goto end;
1018 } else {
1019 GLenum baseFormat = _mesa_base_fbo_format(ctx, internalformat);
1020 if (baseFormat != GL_DEPTH_STENCIL &&
1021 ((pname == GL_DEPTH_RENDERABLE && baseFormat != GL_DEPTH_COMPONENT) ||
1022 (pname == GL_STENCIL_RENDERABLE && baseFormat != GL_STENCIL_INDEX)))
1023 goto end;
1024 }
1025
1026 buffer[0] = GL_TRUE;
1027 break;
1028
1029 case GL_FRAMEBUFFER_RENDERABLE:
1030 /* @TODO */
1031 break;
1032
1033 case GL_FRAMEBUFFER_RENDERABLE_LAYERED:
1034 /* @TODO */
1035 break;
1036
1037 case GL_FRAMEBUFFER_BLEND:
1038 /* @TODO */
1039 break;
1040
1041 case GL_READ_PIXELS:
1042 /* @TODO */
1043 break;
1044
1045 case GL_READ_PIXELS_FORMAT:
1046 /* @TODO */
1047 break;
1048
1049 case GL_READ_PIXELS_TYPE:
1050 /* @TODO */
1051 break;
1052
1053 case GL_TEXTURE_IMAGE_FORMAT:
1054 /* @TODO */
1055 break;
1056
1057 case GL_TEXTURE_IMAGE_TYPE:
1058 /* @TODO */
1059 break;
1060
1061 case GL_GET_TEXTURE_IMAGE_FORMAT:
1062 /* @TODO */
1063 break;
1064
1065 case GL_GET_TEXTURE_IMAGE_TYPE:
1066 /* @TODO */
1067 break;
1068
1069 case GL_MIPMAP:
1070 case GL_MANUAL_GENERATE_MIPMAP:
1071 case GL_AUTO_GENERATE_MIPMAP:
1072 if (!_mesa_is_valid_generate_texture_mipmap_target(ctx, target) ||
1073 !_mesa_is_valid_generate_texture_mipmap_internalformat(ctx,
1074 internalformat)) {
1075 goto end;
1076 }
1077
1078 if (pname == GL_MIPMAP) {
1079 buffer[0] = GL_TRUE;
1080 goto end;
1081 }
1082 else if (pname == GL_MANUAL_GENERATE_MIPMAP) {
1083 if (!_mesa_has_ARB_framebuffer_object(ctx))
1084 goto end;
1085 }
1086 else {
1087 /* From ARB_internalformat_query2:
1088 * "Dependencies on OpenGL 3.2 (Core Profile)
1089 * In core profiles for OpenGL 3.2 and later versions, queries
1090 * for the AUTO_GENERATE_MIPMAP <pname> return the appropriate
1091 * unsupported response."
1092 */
1093 if (_mesa_is_desktop_gl(ctx) && ctx->Version >= 32)
1094 goto end;
1095 }
1096
1097 ctx->Driver.QueryInternalFormat(ctx, target, internalformat, pname,
1098 buffer);
1099 break;
1100
1101 case GL_COLOR_ENCODING:
1102 if (!_mesa_is_color_format(internalformat))
1103 goto end;
1104
1105 if (_mesa_is_srgb_format(internalformat))
1106 buffer[0] = GL_SRGB;
1107 else
1108 buffer[0] = GL_LINEAR;
1109 break;
1110
1111 case GL_SRGB_READ:
1112 /* @TODO */
1113 break;
1114
1115 case GL_SRGB_WRITE:
1116 /* @TODO */
1117 break;
1118
1119 case GL_SRGB_DECODE_ARB:
1120 /* @TODO */
1121 break;
1122
1123 case GL_FILTER:
1124 /* @TODO */
1125 break;
1126
1127 case GL_VERTEX_TEXTURE:
1128 /* @TODO */
1129 break;
1130
1131 case GL_TESS_CONTROL_TEXTURE:
1132 /* @TODO */
1133 break;
1134
1135 case GL_TESS_EVALUATION_TEXTURE:
1136 /* @TODO */
1137 break;
1138
1139 case GL_GEOMETRY_TEXTURE:
1140 /* @TODO */
1141 break;
1142
1143 case GL_FRAGMENT_TEXTURE:
1144 /* @TODO */
1145 break;
1146
1147 case GL_COMPUTE_TEXTURE:
1148 /* @TODO */
1149 break;
1150
1151 case GL_TEXTURE_SHADOW:
1152 /* @TODO */
1153 break;
1154
1155 case GL_TEXTURE_GATHER:
1156 /* @TODO */
1157 break;
1158
1159 case GL_TEXTURE_GATHER_SHADOW:
1160 /* @TODO */
1161 break;
1162
1163 case GL_SHADER_IMAGE_LOAD:
1164 /* @TODO */
1165 break;
1166
1167 case GL_SHADER_IMAGE_STORE:
1168 /* @TODO */
1169 break;
1170
1171 case GL_SHADER_IMAGE_ATOMIC:
1172 /* @TODO */
1173 break;
1174
1175 case GL_IMAGE_TEXEL_SIZE:
1176 /* @TODO */
1177 break;
1178
1179 case GL_IMAGE_COMPATIBILITY_CLASS:
1180 /* @TODO */
1181 break;
1182
1183 case GL_IMAGE_PIXEL_FORMAT:
1184 /* @TODO */
1185 break;
1186
1187 case GL_IMAGE_PIXEL_TYPE:
1188 /* @TODO */
1189 break;
1190
1191 case GL_IMAGE_FORMAT_COMPATIBILITY_TYPE: {
1192 if (!_mesa_has_ARB_shader_image_load_store(ctx))
1193 goto end;
1194
1195 if (!_mesa_legal_get_tex_level_parameter_target(ctx, target, true))
1196 goto end;
1197
1198 /* From spec: "Equivalent to calling GetTexParameter with <value> set
1199 * to IMAGE_FORMAT_COMPATIBILITY_TYPE."
1200 *
1201 * GetTexParameter just returns
1202 * tex_obj->ImageFormatCompatibilityType. We create a fake tex_obj
1203 * just with the purpose of getting the value.
1204 */
1205 struct gl_texture_object *tex_obj = _mesa_new_texture_object(ctx, 0, target);
1206 buffer[0] = tex_obj->ImageFormatCompatibilityType;
1207 _mesa_delete_texture_object(ctx, tex_obj);
1208
1209 break;
1210 }
1211
1212 case GL_SIMULTANEOUS_TEXTURE_AND_DEPTH_TEST:
1213 /* @TODO */
1214 break;
1215
1216 case GL_SIMULTANEOUS_TEXTURE_AND_STENCIL_TEST:
1217 /* @TODO */
1218 break;
1219
1220 case GL_SIMULTANEOUS_TEXTURE_AND_DEPTH_WRITE:
1221 /* @TODO */
1222 break;
1223
1224 case GL_SIMULTANEOUS_TEXTURE_AND_STENCIL_WRITE:
1225 /* @TODO */
1226 break;
1227
1228 case GL_TEXTURE_COMPRESSED:
1229 /* @TODO */
1230 break;
1231
1232 case GL_TEXTURE_COMPRESSED_BLOCK_WIDTH:
1233 /* @TODO */
1234 break;
1235
1236 case GL_TEXTURE_COMPRESSED_BLOCK_HEIGHT:
1237 /* @TODO */
1238 break;
1239
1240 case GL_TEXTURE_COMPRESSED_BLOCK_SIZE:
1241 /* @TODO */
1242 break;
1243
1244 case GL_CLEAR_BUFFER:
1245 /* @TODO */
1246 break;
1247
1248 case GL_TEXTURE_VIEW:
1249 /* @TODO */
1250 break;
1251
1252 case GL_VIEW_COMPATIBILITY_CLASS:
1253 /* @TODO */
1254 break;
1255
1256 default:
1257 unreachable("bad param");
1258 }
1259
1260 end:
1261 if (bufSize != 0 && params == NULL) {
1262 /* Emit a warning to aid application debugging, but go ahead and do the
1263 * memcpy (and probably crash) anyway.
1264 */
1265 _mesa_warning(ctx,
1266 "glGetInternalformativ(bufSize = %d, but params = NULL)",
1267 bufSize);
1268 }
1269
1270 /* Copy the data from the temporary buffer to the buffer supplied by the
1271 * application. Clamp the size of the copy to the size supplied by the
1272 * application.
1273 */
1274 memcpy(params, buffer, MIN2(bufSize, 16) * sizeof(GLint));
1275
1276 return;
1277 }
1278
1279 void GLAPIENTRY
1280 _mesa_GetInternalformati64v(GLenum target, GLenum internalformat,
1281 GLenum pname, GLsizei bufSize, GLint64 *params)
1282 {
1283 GLint params32[16];
1284 unsigned i;
1285 GLsizei realSize = MIN2(bufSize, 16);
1286 GLsizei callSize;
1287
1288 GET_CURRENT_CONTEXT(ctx);
1289
1290 ASSERT_OUTSIDE_BEGIN_END(ctx);
1291
1292 if (!_mesa_has_ARB_internalformat_query2(ctx)) {
1293 _mesa_error(ctx, GL_INVALID_OPERATION, "glGetInternalformati64v");
1294 return;
1295 }
1296
1297 /* For SAMPLES there are cases where params needs to remain unmodified. As
1298 * no pname can return a negative value, we fill params32 with negative
1299 * values as reference values, that can be used to know what copy-back to
1300 * params */
1301 memset(params32, -1, 16);
1302
1303 /* For GL_MAX_COMBINED_DIMENSIONS we need to get back 2 32-bit integers,
1304 * and at the same time we only need 2. So for that pname, we call the
1305 * 32-bit query with bufSize 2, except on the case of bufSize 0, that is
1306 * basically like asking to not get the value, but that is a caller
1307 * problem. */
1308 if (pname == GL_MAX_COMBINED_DIMENSIONS && bufSize > 0)
1309 callSize = 2;
1310 else
1311 callSize = bufSize;
1312
1313 _mesa_GetInternalformativ(target, internalformat, pname, callSize, params32);
1314
1315 if (pname == GL_MAX_COMBINED_DIMENSIONS) {
1316 memcpy(params, params32, sizeof(GLint64));
1317 } else {
1318 for (i = 0; i < realSize; i++) {
1319 /* We only copy back the values that changed */
1320 if (params32[i] < 0)
1321 break;
1322 params[i] = (GLint64) params32[i];
1323 }
1324 }
1325 }