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