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