mesa/formatquery: Added simultaneous texture and depth/stencil 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 case GL_SIMULTANEOUS_TEXTURE_AND_DEPTH_TEST:
615 case GL_SIMULTANEOUS_TEXTURE_AND_STENCIL_TEST:
616 case GL_SIMULTANEOUS_TEXTURE_AND_DEPTH_WRITE:
617 case GL_SIMULTANEOUS_TEXTURE_AND_STENCIL_WRITE:
618 params[0] = GL_FULL_SUPPORT;
619 break;
620
621 default:
622 _set_default_response(pname, params);
623 break;
624 }
625 }
626
627 /*
628 * For MAX_WIDTH/MAX_HEIGHT/MAX_DEPTH it returns the equivalent GetInteger
629 * pname for a Getinternalformat pname/target combination. target/pname
630 * combinations that would return 0 due dimension number or unsupported status
631 * should be already filtered out
632 *
633 * Note that this means that the returned value would be independent of the
634 * internalformat. This possibility is already mentioned at the Issue 7 of the
635 * arb_internalformat_query2 spec.
636 */
637 static GLenum
638 equivalentSizePname(GLenum target,
639 GLenum pname)
640 {
641 switch (target) {
642 case GL_TEXTURE_1D:
643 case GL_TEXTURE_2D:
644 case GL_TEXTURE_2D_MULTISAMPLE:
645 return GL_MAX_TEXTURE_SIZE;
646 case GL_TEXTURE_3D:
647 return GL_MAX_3D_TEXTURE_SIZE;
648 case GL_TEXTURE_CUBE_MAP:
649 return GL_MAX_CUBE_MAP_TEXTURE_SIZE;
650 case GL_TEXTURE_RECTANGLE:
651 return GL_MAX_RECTANGLE_TEXTURE_SIZE;
652 case GL_RENDERBUFFER:
653 return GL_MAX_RENDERBUFFER_SIZE;
654 case GL_TEXTURE_1D_ARRAY:
655 if (pname == GL_MAX_HEIGHT)
656 return GL_MAX_ARRAY_TEXTURE_LAYERS;
657 else
658 return GL_MAX_TEXTURE_SIZE;
659 case GL_TEXTURE_2D_ARRAY:
660 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY:
661 if (pname == GL_MAX_DEPTH)
662 return GL_MAX_ARRAY_TEXTURE_LAYERS;
663 else
664 return GL_MAX_TEXTURE_SIZE;
665 case GL_TEXTURE_CUBE_MAP_ARRAY:
666 if (pname == GL_MAX_DEPTH)
667 return GL_MAX_ARRAY_TEXTURE_LAYERS;
668 else
669 return GL_MAX_CUBE_MAP_TEXTURE_SIZE;
670 case GL_TEXTURE_BUFFER:
671 return GL_MAX_TEXTURE_BUFFER_SIZE;
672 default:
673 return 0;
674 }
675 }
676
677 /*
678 * Returns the dimensions associated to a target. GL_TEXTURE_BUFFER and
679 * GL_RENDERBUFFER have associated a dimension, but they are not textures
680 * per-se, so we can't just call _mesa_get_texture_dimension directly.
681 */
682 static GLint
683 get_target_dimensions(GLenum target)
684 {
685 switch(target) {
686 case GL_TEXTURE_BUFFER:
687 return 1;
688 case GL_RENDERBUFFER:
689 return 2;
690 default:
691 return _mesa_get_texture_dimensions(target);
692 }
693 }
694
695 /*
696 * Returns the minimum amount of dimensions associated to a pname. So for
697 * example, if querying GL_MAX_HEIGHT, it is assumed that your target would
698 * have as minimum 2 dimensions.
699 *
700 * Useful to handle sentences like this from query2 spec:
701 *
702 * "MAX_HEIGHT:
703 * <skip>
704 * If the resource does not have at least two dimensions
705 * <skip>."
706 */
707 static GLint
708 get_min_dimensions(GLenum pname)
709 {
710 switch(pname) {
711 case GL_MAX_WIDTH:
712 return 1;
713 case GL_MAX_HEIGHT:
714 return 2;
715 case GL_MAX_DEPTH:
716 return 3;
717 default:
718 return 0;
719 }
720 }
721
722 /*
723 * Similar to teximage.c:check_multisample_target, but independent of the
724 * dimensions.
725 */
726 static bool
727 is_multisample_target(GLenum target)
728 {
729 switch(target) {
730 case GL_TEXTURE_2D_MULTISAMPLE:
731 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY:
732 return true;
733 default:
734 return false;
735 }
736
737 }
738
739 void GLAPIENTRY
740 _mesa_GetInternalformativ(GLenum target, GLenum internalformat, GLenum pname,
741 GLsizei bufSize, GLint *params)
742 {
743 GLint buffer[16];
744 GET_CURRENT_CONTEXT(ctx);
745
746 ASSERT_OUTSIDE_BEGIN_END(ctx);
747
748 /* ARB_internalformat_query is also mandatory for ARB_internalformat_query2 */
749 if (!(_mesa_has_ARB_internalformat_query(ctx) ||
750 _mesa_is_gles3(ctx))) {
751 _mesa_error(ctx, GL_INVALID_OPERATION, "glGetInternalformativ");
752 return;
753 }
754
755 assert(ctx->Driver.QueryInternalFormat != NULL);
756
757 if (!_legal_parameters(ctx, target, internalformat, pname, bufSize, params))
758 return;
759
760 /* initialize the contents of the temporary buffer */
761 memcpy(buffer, params, MIN2(bufSize, 16) * sizeof(GLint));
762
763 /* Use the 'unsupported' response defined by the spec for every pname
764 * as the default answer.
765 */
766 _set_default_response(pname, buffer);
767
768 if (!_is_target_supported(ctx, target) ||
769 !_is_internalformat_supported(ctx, target, internalformat) ||
770 !_is_resource_supported(ctx, target, internalformat, pname))
771 goto end;
772
773 switch (pname) {
774 case GL_SAMPLES:
775 /* fall-through */
776 case GL_NUM_SAMPLE_COUNTS:
777 /* The ARB_internalformat_query2 sets the response as 'unsupported' for
778 * SAMPLES and NUM_SAMPLE_COUNTS:
779 *
780 * "If <internalformat> is not color-renderable, depth-renderable, or
781 * stencil-renderable (as defined in section 4.4.4), or if <target>
782 * does not support multiple samples (ie other than
783 * TEXTURE_2D_MULTISAMPLE, TEXTURE_2D_MULTISAMPLE_ARRAY,
784 * or RENDERBUFFER)."
785 */
786 if ((target != GL_RENDERBUFFER &&
787 target != GL_TEXTURE_2D_MULTISAMPLE &&
788 target != GL_TEXTURE_2D_MULTISAMPLE_ARRAY) ||
789 !_is_renderable(ctx, internalformat))
790 goto end;
791
792 /* The GL ES 3.0 specification, section 6.1.15 page 236 says:
793 *
794 * "Since multisampling is not supported for signed and unsigned
795 * integer internal formats, the value of NUM_SAMPLE_COUNTS will be
796 * zero for such formats.
797 */
798 if (pname == GL_NUM_SAMPLE_COUNTS && ctx->API == API_OPENGLES2 &&
799 ctx->Version == 30 && _mesa_is_enum_format_integer(internalformat)) {
800 goto end;
801 }
802
803 ctx->Driver.QueryInternalFormat(ctx, target, internalformat, pname,
804 buffer);
805 break;
806
807 case GL_INTERNALFORMAT_SUPPORTED:
808 /* Having a supported <internalformat> is implemented as a prerequisite
809 * for all the <pnames>. Thus, if we reach this point, the internalformat is
810 * supported.
811 */
812 buffer[0] = GL_TRUE;
813 break;
814
815 case GL_INTERNALFORMAT_PREFERRED:
816 /* The ARB_internalformat_query2 spec says:
817 *
818 * "- INTERNALFORMAT_PREFERRED: The implementation-preferred internal
819 * format for representing resources of the specified <internalformat> is
820 * returned in <params>.
821 *
822 * Therefore, we let the driver answer.
823 */
824 ctx->Driver.QueryInternalFormat(ctx, target, internalformat, pname,
825 buffer);
826 break;
827
828 case GL_INTERNALFORMAT_RED_SIZE:
829 case GL_INTERNALFORMAT_GREEN_SIZE:
830 case GL_INTERNALFORMAT_BLUE_SIZE:
831 case GL_INTERNALFORMAT_ALPHA_SIZE:
832 case GL_INTERNALFORMAT_DEPTH_SIZE:
833 case GL_INTERNALFORMAT_STENCIL_SIZE:
834 case GL_INTERNALFORMAT_SHARED_SIZE:
835 case GL_INTERNALFORMAT_RED_TYPE:
836 case GL_INTERNALFORMAT_GREEN_TYPE:
837 case GL_INTERNALFORMAT_BLUE_TYPE:
838 case GL_INTERNALFORMAT_ALPHA_TYPE:
839 case GL_INTERNALFORMAT_DEPTH_TYPE:
840 case GL_INTERNALFORMAT_STENCIL_TYPE: {
841 GLint baseformat;
842 mesa_format texformat;
843
844 if (target != GL_RENDERBUFFER) {
845 if (!_mesa_legal_get_tex_level_parameter_target(ctx, target, true))
846 goto end;
847
848 baseformat = _mesa_base_tex_format(ctx, internalformat);
849 } else {
850 baseformat = _mesa_base_fbo_format(ctx, internalformat);
851 }
852
853 /* Let the driver choose the texture format.
854 *
855 * Disclaimer: I am considering that drivers use for renderbuffers the
856 * same format-choice logic as for textures.
857 */
858 texformat = ctx->Driver.ChooseTextureFormat(ctx, target, internalformat,
859 GL_NONE /*format */, GL_NONE /* type */);
860
861 if (texformat == MESA_FORMAT_NONE || baseformat <= 0)
862 goto end;
863
864 /* Implementation based on what Mesa does for glGetTexLevelParameteriv
865 * and glGetRenderbufferParameteriv functions.
866 */
867 if (pname == GL_INTERNALFORMAT_SHARED_SIZE) {
868 if (_mesa_has_EXT_texture_shared_exponent(ctx) &&
869 target != GL_TEXTURE_BUFFER &&
870 target != GL_RENDERBUFFER &&
871 texformat == MESA_FORMAT_R9G9B9E5_FLOAT) {
872 buffer[0] = 5;
873 }
874 goto end;
875 }
876
877 if (!_mesa_base_format_has_channel(baseformat, pname))
878 goto end;
879
880 switch (pname) {
881 case GL_INTERNALFORMAT_DEPTH_SIZE:
882 if (!_mesa_has_ARB_depth_texture(ctx) &&
883 target != GL_RENDERBUFFER &&
884 target != GL_TEXTURE_BUFFER)
885 goto end;
886 /* fallthrough */
887 case GL_INTERNALFORMAT_RED_SIZE:
888 case GL_INTERNALFORMAT_GREEN_SIZE:
889 case GL_INTERNALFORMAT_BLUE_SIZE:
890 case GL_INTERNALFORMAT_ALPHA_SIZE:
891 case GL_INTERNALFORMAT_STENCIL_SIZE:
892 buffer[0] = _mesa_get_format_bits(texformat, pname);
893 break;
894
895 case GL_INTERNALFORMAT_DEPTH_TYPE:
896 if (!_mesa_has_ARB_texture_float(ctx))
897 goto end;
898 /* fallthrough */
899 case GL_INTERNALFORMAT_RED_TYPE:
900 case GL_INTERNALFORMAT_GREEN_TYPE:
901 case GL_INTERNALFORMAT_BLUE_TYPE:
902 case GL_INTERNALFORMAT_ALPHA_TYPE:
903 case GL_INTERNALFORMAT_STENCIL_TYPE:
904 buffer[0] = _mesa_get_format_datatype(texformat);
905 break;
906
907 default:
908 break;
909
910 }
911 break;
912 }
913
914 /* For WIDTH/HEIGHT/DEPTH/LAYERS there is no reason to think that the
915 * returned values should be different to the values returned by
916 * GetInteger with MAX_TEXTURE_SIZE, MAX_3D_TEXTURE_SIZE, etc.*/
917 case GL_MAX_WIDTH:
918 case GL_MAX_HEIGHT:
919 case GL_MAX_DEPTH: {
920 GLenum get_pname;
921 GLint dimensions;
922 GLint min_dimensions;
923
924 /* From query2:MAX_HEIGHT spec (as example):
925 *
926 * "If the resource does not have at least two dimensions, or if the
927 * resource is unsupported, zero is returned."
928 */
929 dimensions = get_target_dimensions(target);
930 min_dimensions = get_min_dimensions(pname);
931 if (dimensions < min_dimensions)
932 goto end;
933
934 get_pname = equivalentSizePname(target, pname);
935 if (get_pname == 0)
936 goto end;
937
938 _mesa_GetIntegerv(get_pname, buffer);
939 break;
940 }
941
942 case GL_MAX_LAYERS:
943 if (!_mesa_has_EXT_texture_array(ctx))
944 goto end;
945
946 if (!_mesa_is_array_texture(target))
947 goto end;
948
949 _mesa_GetIntegerv(GL_MAX_ARRAY_TEXTURE_LAYERS, buffer);
950 break;
951
952 case GL_MAX_COMBINED_DIMENSIONS:{
953 GLint64 combined_value = 1;
954 GLenum max_dimensions_pnames[] = {
955 GL_MAX_WIDTH,
956 GL_MAX_HEIGHT,
957 GL_MAX_DEPTH,
958 GL_SAMPLES
959 };
960 unsigned i;
961 GLint current_value;
962
963 /* Combining the dimensions. Note that for array targets, this would
964 * automatically include the value of MAX_LAYERS, as that value is
965 * returned as MAX_HEIGHT or MAX_DEPTH */
966 for (i = 0; i < 4; i++) {
967 if (max_dimensions_pnames[i] == GL_SAMPLES &&
968 !is_multisample_target(target))
969 continue;
970
971 _mesa_GetInternalformativ(target, internalformat,
972 max_dimensions_pnames[i],
973 1, &current_value);
974
975 if (current_value != 0)
976 combined_value *= current_value;
977 }
978
979 if (_mesa_is_cube_map_texture(target))
980 combined_value *= 6;
981
982 /* We pack the 64-bit value on two 32-bit values. Calling the 32-bit
983 * query, this would work as far as the value can be hold on a 32-bit
984 * signed integer. For the 64-bit query, the wrapper around the 32-bit
985 * query will unpack the value */
986 memcpy(buffer, &combined_value, sizeof(GLint64));
987 break;
988 }
989
990 case GL_COLOR_COMPONENTS:
991 /* The ARB_internalformat_query2 spec says:
992 *
993 * "- COLOR_COMPONENTS: If the internal format contains any color
994 * components (R, G, B, or A), TRUE is returned in <params>.
995 * If the internal format is unsupported or contains no color
996 * components, FALSE is returned."
997 */
998 if (_mesa_is_color_format(internalformat))
999 buffer[0] = GL_TRUE;
1000 break;
1001
1002 case GL_DEPTH_COMPONENTS:
1003 /* The ARB_internalformat_query2 spec says:
1004 *
1005 * "- DEPTH_COMPONENTS: If the internal format contains a depth
1006 * component (D), TRUE is returned in <params>. If the internal format
1007 * is unsupported or contains no depth component, FALSE is returned."
1008 */
1009 if (_mesa_is_depth_format(internalformat) ||
1010 _mesa_is_depthstencil_format(internalformat))
1011 buffer[0] = GL_TRUE;
1012 break;
1013
1014 case GL_STENCIL_COMPONENTS:
1015 /* The ARB_internalformat_query2 spec says:
1016 *
1017 * "- STENCIL_COMPONENTS: If the internal format contains a stencil
1018 * component (S), TRUE is returned in <params>. If the internal format
1019 * is unsupported or contains no stencil component, FALSE is returned.
1020 */
1021 if (_mesa_is_stencil_format(internalformat) ||
1022 _mesa_is_depthstencil_format(internalformat))
1023 buffer[0] = GL_TRUE;
1024 break;
1025
1026 case GL_COLOR_RENDERABLE:
1027 case GL_DEPTH_RENDERABLE:
1028 case GL_STENCIL_RENDERABLE:
1029 if (!_is_renderable(ctx, internalformat))
1030 goto end;
1031
1032 if (pname == GL_COLOR_RENDERABLE) {
1033 if (!_mesa_is_color_format(internalformat))
1034 goto end;
1035 } else {
1036 GLenum baseFormat = _mesa_base_fbo_format(ctx, internalformat);
1037 if (baseFormat != GL_DEPTH_STENCIL &&
1038 ((pname == GL_DEPTH_RENDERABLE && baseFormat != GL_DEPTH_COMPONENT) ||
1039 (pname == GL_STENCIL_RENDERABLE && baseFormat != GL_STENCIL_INDEX)))
1040 goto end;
1041 }
1042
1043 buffer[0] = GL_TRUE;
1044 break;
1045
1046 case GL_FRAMEBUFFER_RENDERABLE:
1047 /* @TODO */
1048 break;
1049
1050 case GL_FRAMEBUFFER_RENDERABLE_LAYERED:
1051 /* @TODO */
1052 break;
1053
1054 case GL_FRAMEBUFFER_BLEND:
1055 /* @TODO */
1056 break;
1057
1058 case GL_READ_PIXELS:
1059 /* @TODO */
1060 break;
1061
1062 case GL_READ_PIXELS_FORMAT:
1063 /* @TODO */
1064 break;
1065
1066 case GL_READ_PIXELS_TYPE:
1067 /* @TODO */
1068 break;
1069
1070 case GL_TEXTURE_IMAGE_FORMAT:
1071 /* @TODO */
1072 break;
1073
1074 case GL_TEXTURE_IMAGE_TYPE:
1075 /* @TODO */
1076 break;
1077
1078 case GL_GET_TEXTURE_IMAGE_FORMAT:
1079 /* @TODO */
1080 break;
1081
1082 case GL_GET_TEXTURE_IMAGE_TYPE:
1083 /* @TODO */
1084 break;
1085
1086 case GL_MIPMAP:
1087 case GL_MANUAL_GENERATE_MIPMAP:
1088 case GL_AUTO_GENERATE_MIPMAP:
1089 if (!_mesa_is_valid_generate_texture_mipmap_target(ctx, target) ||
1090 !_mesa_is_valid_generate_texture_mipmap_internalformat(ctx,
1091 internalformat)) {
1092 goto end;
1093 }
1094
1095 if (pname == GL_MIPMAP) {
1096 buffer[0] = GL_TRUE;
1097 goto end;
1098 }
1099 else if (pname == GL_MANUAL_GENERATE_MIPMAP) {
1100 if (!_mesa_has_ARB_framebuffer_object(ctx))
1101 goto end;
1102 }
1103 else {
1104 /* From ARB_internalformat_query2:
1105 * "Dependencies on OpenGL 3.2 (Core Profile)
1106 * In core profiles for OpenGL 3.2 and later versions, queries
1107 * for the AUTO_GENERATE_MIPMAP <pname> return the appropriate
1108 * unsupported response."
1109 */
1110 if (_mesa_is_desktop_gl(ctx) && ctx->Version >= 32)
1111 goto end;
1112 }
1113
1114 ctx->Driver.QueryInternalFormat(ctx, target, internalformat, pname,
1115 buffer);
1116 break;
1117
1118 case GL_COLOR_ENCODING:
1119 if (!_mesa_is_color_format(internalformat))
1120 goto end;
1121
1122 if (_mesa_is_srgb_format(internalformat))
1123 buffer[0] = GL_SRGB;
1124 else
1125 buffer[0] = GL_LINEAR;
1126 break;
1127
1128 case GL_SRGB_READ:
1129 if (!_mesa_has_EXT_texture_sRGB(ctx) ||
1130 !_mesa_is_srgb_format(internalformat)) {
1131 goto end;
1132 }
1133
1134 ctx->Driver.QueryInternalFormat(ctx, target, internalformat, pname,
1135 buffer);
1136 break;
1137
1138 case GL_SRGB_WRITE:
1139 if (!_mesa_has_EXT_framebuffer_sRGB(ctx) ||
1140 !_mesa_is_color_format(internalformat)) {
1141 goto end;
1142 }
1143
1144 ctx->Driver.QueryInternalFormat(ctx, target, internalformat, pname,
1145 buffer);
1146 break;
1147
1148 case GL_SRGB_DECODE_ARB:
1149 /* Presence of EXT_texture_sRGB_decode was already verified */
1150 if (!_mesa_has_EXT_texture_sRGB(ctx) ||
1151 target == GL_RENDERBUFFER ||
1152 !_mesa_is_srgb_format(internalformat)) {
1153 goto end;
1154 }
1155
1156 ctx->Driver.QueryInternalFormat(ctx, target, internalformat, pname,
1157 buffer);
1158 break;
1159
1160 case GL_FILTER:
1161 /* @TODO */
1162 break;
1163
1164 case GL_VERTEX_TEXTURE:
1165 case GL_TESS_CONTROL_TEXTURE:
1166 case GL_TESS_EVALUATION_TEXTURE:
1167 case GL_GEOMETRY_TEXTURE:
1168 case GL_FRAGMENT_TEXTURE:
1169 case GL_COMPUTE_TEXTURE:
1170 if (target == GL_RENDERBUFFER)
1171 goto end;
1172
1173 if ((pname == GL_TESS_CONTROL_TEXTURE ||
1174 pname == GL_TESS_EVALUATION_TEXTURE) &&
1175 !_mesa_has_tessellation(ctx))
1176 goto end;
1177
1178 if (pname == GL_GEOMETRY_TEXTURE && !_mesa_has_geometry_shaders(ctx))
1179 goto end;
1180
1181 if (pname == GL_COMPUTE_TEXTURE && !_mesa_has_compute_shaders(ctx))
1182 goto end;
1183
1184 ctx->Driver.QueryInternalFormat(ctx, target, internalformat, pname,
1185 buffer);
1186 break;
1187
1188 case GL_TEXTURE_SHADOW:
1189 /* @TODO */
1190 break;
1191
1192 case GL_TEXTURE_GATHER:
1193 /* @TODO */
1194 break;
1195
1196 case GL_TEXTURE_GATHER_SHADOW:
1197 /* @TODO */
1198 break;
1199
1200 case GL_SHADER_IMAGE_LOAD:
1201 case GL_SHADER_IMAGE_STORE:
1202 if (!_mesa_has_ARB_shader_image_load_store(ctx))
1203 goto end;
1204
1205 /* We call to _mesa_is_shader_image_format_supported
1206 * using "internalformat" as parameter, because the
1207 * the ARB_internalformat_query2 spec says:
1208 * "In this case the <internalformat> is the value of the <format>
1209 * parameter that is passed to BindImageTexture."
1210 */
1211 if (target == GL_RENDERBUFFER ||
1212 !_mesa_is_shader_image_format_supported(ctx, internalformat))
1213 goto end;
1214
1215 ctx->Driver.QueryInternalFormat(ctx, target, internalformat, pname,
1216 buffer);
1217 break;
1218
1219 case GL_SHADER_IMAGE_ATOMIC:
1220 if (!_mesa_has_ARB_shader_image_load_store(ctx))
1221 goto end;
1222
1223 ctx->Driver.QueryInternalFormat(ctx, target, internalformat, pname,
1224 buffer);
1225 break;
1226
1227 case GL_IMAGE_TEXEL_SIZE: {
1228 mesa_format image_format;
1229
1230 if (!_mesa_has_ARB_shader_image_load_store(ctx) ||
1231 target == GL_RENDERBUFFER)
1232 goto end;
1233
1234 image_format = _mesa_get_shader_image_format(internalformat);
1235 if (image_format == MESA_FORMAT_NONE)
1236 goto end;
1237
1238 /* We return bits */
1239 buffer[0] = (_mesa_get_format_bytes(image_format) * 8);
1240 break;
1241 }
1242
1243 case GL_IMAGE_COMPATIBILITY_CLASS:
1244 if (!_mesa_has_ARB_shader_image_load_store(ctx) ||
1245 target == GL_RENDERBUFFER)
1246 goto end;
1247
1248 buffer[0] = _mesa_get_image_format_class(internalformat);
1249 break;
1250
1251 case GL_IMAGE_PIXEL_FORMAT: {
1252 GLint base_format;
1253
1254 if (!_mesa_has_ARB_shader_image_load_store(ctx) ||
1255 target == GL_RENDERBUFFER ||
1256 !_mesa_is_shader_image_format_supported(ctx, internalformat))
1257 goto end;
1258
1259 base_format = _mesa_base_tex_format(ctx, internalformat);
1260 if (base_format == -1)
1261 goto end;
1262
1263 if (_mesa_is_enum_format_integer(internalformat))
1264 buffer[0] = _mesa_base_format_to_integer_format(base_format);
1265 else
1266 buffer[0] = base_format;
1267 break;
1268 }
1269
1270 case GL_IMAGE_PIXEL_TYPE: {
1271 mesa_format image_format;
1272 GLenum datatype;
1273 GLuint comps;
1274
1275 if (!_mesa_has_ARB_shader_image_load_store(ctx) ||
1276 target == GL_RENDERBUFFER)
1277 goto end;
1278
1279 image_format = _mesa_get_shader_image_format(internalformat);
1280 if (image_format == MESA_FORMAT_NONE)
1281 goto end;
1282
1283 _mesa_uncompressed_format_to_type_and_comps(image_format, &datatype,
1284 &comps);
1285 if (!datatype)
1286 goto end;
1287
1288 buffer[0] = datatype;
1289 break;
1290 }
1291
1292 case GL_IMAGE_FORMAT_COMPATIBILITY_TYPE: {
1293 if (!_mesa_has_ARB_shader_image_load_store(ctx))
1294 goto end;
1295
1296 if (!_mesa_legal_get_tex_level_parameter_target(ctx, target, true))
1297 goto end;
1298
1299 /* From spec: "Equivalent to calling GetTexParameter with <value> set
1300 * to IMAGE_FORMAT_COMPATIBILITY_TYPE."
1301 *
1302 * GetTexParameter just returns
1303 * tex_obj->ImageFormatCompatibilityType. We create a fake tex_obj
1304 * just with the purpose of getting the value.
1305 */
1306 struct gl_texture_object *tex_obj = _mesa_new_texture_object(ctx, 0, target);
1307 buffer[0] = tex_obj->ImageFormatCompatibilityType;
1308 _mesa_delete_texture_object(ctx, tex_obj);
1309
1310 break;
1311 }
1312
1313 case GL_SIMULTANEOUS_TEXTURE_AND_DEPTH_TEST:
1314 case GL_SIMULTANEOUS_TEXTURE_AND_STENCIL_TEST:
1315 case GL_SIMULTANEOUS_TEXTURE_AND_DEPTH_WRITE:
1316 case GL_SIMULTANEOUS_TEXTURE_AND_STENCIL_WRITE:
1317 if (target == GL_RENDERBUFFER)
1318 goto end;
1319
1320 if (!_mesa_is_depthstencil_format(internalformat)) {
1321 if (((pname == GL_SIMULTANEOUS_TEXTURE_AND_DEPTH_TEST ||
1322 pname == GL_SIMULTANEOUS_TEXTURE_AND_DEPTH_WRITE) &&
1323 !_mesa_is_depth_format(internalformat)) ||
1324 ((pname == GL_SIMULTANEOUS_TEXTURE_AND_STENCIL_TEST ||
1325 pname == GL_SIMULTANEOUS_TEXTURE_AND_STENCIL_WRITE) &&
1326 !_mesa_is_stencil_format(internalformat)))
1327 goto end;
1328 }
1329
1330 ctx->Driver.QueryInternalFormat(ctx, target, internalformat, pname,
1331 buffer);
1332 break;
1333
1334 case GL_TEXTURE_COMPRESSED:
1335 /* @TODO */
1336 break;
1337
1338 case GL_TEXTURE_COMPRESSED_BLOCK_WIDTH:
1339 /* @TODO */
1340 break;
1341
1342 case GL_TEXTURE_COMPRESSED_BLOCK_HEIGHT:
1343 /* @TODO */
1344 break;
1345
1346 case GL_TEXTURE_COMPRESSED_BLOCK_SIZE:
1347 /* @TODO */
1348 break;
1349
1350 case GL_CLEAR_BUFFER:
1351 /* @TODO */
1352 break;
1353
1354 case GL_TEXTURE_VIEW:
1355 /* @TODO */
1356 break;
1357
1358 case GL_VIEW_COMPATIBILITY_CLASS:
1359 /* @TODO */
1360 break;
1361
1362 default:
1363 unreachable("bad param");
1364 }
1365
1366 end:
1367 if (bufSize != 0 && params == NULL) {
1368 /* Emit a warning to aid application debugging, but go ahead and do the
1369 * memcpy (and probably crash) anyway.
1370 */
1371 _mesa_warning(ctx,
1372 "glGetInternalformativ(bufSize = %d, but params = NULL)",
1373 bufSize);
1374 }
1375
1376 /* Copy the data from the temporary buffer to the buffer supplied by the
1377 * application. Clamp the size of the copy to the size supplied by the
1378 * application.
1379 */
1380 memcpy(params, buffer, MIN2(bufSize, 16) * sizeof(GLint));
1381
1382 return;
1383 }
1384
1385 void GLAPIENTRY
1386 _mesa_GetInternalformati64v(GLenum target, GLenum internalformat,
1387 GLenum pname, GLsizei bufSize, GLint64 *params)
1388 {
1389 GLint params32[16];
1390 unsigned i;
1391 GLsizei realSize = MIN2(bufSize, 16);
1392 GLsizei callSize;
1393
1394 GET_CURRENT_CONTEXT(ctx);
1395
1396 ASSERT_OUTSIDE_BEGIN_END(ctx);
1397
1398 if (!_mesa_has_ARB_internalformat_query2(ctx)) {
1399 _mesa_error(ctx, GL_INVALID_OPERATION, "glGetInternalformati64v");
1400 return;
1401 }
1402
1403 /* For SAMPLES there are cases where params needs to remain unmodified. As
1404 * no pname can return a negative value, we fill params32 with negative
1405 * values as reference values, that can be used to know what copy-back to
1406 * params */
1407 memset(params32, -1, 16);
1408
1409 /* For GL_MAX_COMBINED_DIMENSIONS we need to get back 2 32-bit integers,
1410 * and at the same time we only need 2. So for that pname, we call the
1411 * 32-bit query with bufSize 2, except on the case of bufSize 0, that is
1412 * basically like asking to not get the value, but that is a caller
1413 * problem. */
1414 if (pname == GL_MAX_COMBINED_DIMENSIONS && bufSize > 0)
1415 callSize = 2;
1416 else
1417 callSize = bufSize;
1418
1419 _mesa_GetInternalformativ(target, internalformat, pname, callSize, params32);
1420
1421 if (pname == GL_MAX_COMBINED_DIMENSIONS) {
1422 memcpy(params, params32, sizeof(GLint64));
1423 } else {
1424 for (i = 0; i < realSize; i++) {
1425 /* We only copy back the values that changed */
1426 if (params32[i] < 0)
1427 break;
1428 params[i] = (GLint64) params32[i];
1429 }
1430 }
1431 }