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