2 * Copyright © 2012 Intel Corporation
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:
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
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.
26 #include "glformats.h"
30 #include "formatquery.h"
35 #include "genmipmap.h"
36 #include "shaderimage.h"
37 #include "texcompress.h"
40 _is_renderable(struct gl_context
*ctx
, GLenum internalformat
)
42 /* Section 4.4.4 on page 212 of the GLES 3.0.4 spec says:
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."
48 * Therefore, we must accept GL_RGB and GL_RGBA here.
50 if (internalformat
!= GL_RGB
&& internalformat
!= GL_RGBA
&&
51 _mesa_base_fbo_format(ctx
, internalformat
) == 0)
57 /* Handles the cases where either ARB_internalformat_query or
58 * ARB_internalformat_query2 have to return an error.
61 _legal_parameters(struct gl_context
*ctx
, GLenum target
, GLenum internalformat
,
62 GLenum pname
, GLsizei bufSize
, GLint
*params
)
65 bool query2
= _mesa_has_ARB_internalformat_query2(ctx
);
67 /* The ARB_internalformat_query2 spec says:
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.
74 case GL_TEXTURE_1D_ARRAY
:
76 case GL_TEXTURE_2D_ARRAY
:
78 case GL_TEXTURE_CUBE_MAP
:
79 case GL_TEXTURE_CUBE_MAP_ARRAY
:
80 case GL_TEXTURE_RECTANGLE
:
81 case GL_TEXTURE_BUFFER
:
83 /* The ARB_internalformat_query spec says:
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.
89 _mesa_error(ctx
, GL_INVALID_ENUM
,
90 "glGetInternalformativ(target=%s)",
91 _mesa_enum_to_string(target
));
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.
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
));
116 _mesa_error(ctx
, GL_INVALID_ENUM
,
117 "glGetInternalformativ(target=%s)",
118 _mesa_enum_to_string(target
));
123 /* The ARB_internalformat_query2 spec says:
125 * "The INVALID_ENUM error is generated if the <pname> parameter is
126 * not one of the listed possibilities.
130 case GL_NUM_SAMPLE_COUNTS
:
133 case GL_SRGB_DECODE_ARB
:
134 /* The ARB_internalformat_query2 spec says:
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.
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
));
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
:
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
:
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
:
184 case GL_MANUAL_GENERATE_MIPMAP
:
185 case GL_AUTO_GENERATE_MIPMAP
:
186 case GL_COLOR_ENCODING
:
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:
220 * "If the <pname> parameter to GetInternalformativ is not SAMPLES
221 * or NUM_SAMPLE_COUNTS, then an INVALID_ENUM error is generated."
224 _mesa_error(ctx
, GL_INVALID_ENUM
,
225 "glGetInternalformativ(pname=%s)",
226 _mesa_enum_to_string(pname
));
233 _mesa_error(ctx
, GL_INVALID_ENUM
,
234 "glGetInternalformativ(pname=%s)",
235 _mesa_enum_to_string(pname
));
239 /* The ARB_internalformat_query spec says:
241 * "If the <bufSize> parameter to GetInternalformativ is negative, then
242 * an INVALID_VALUE error is generated."
244 * Nothing is said in ARB_internalformat_query2 but we assume the same.
247 _mesa_error(ctx
, GL_INVALID_VALUE
,
248 "glGetInternalformativ(target=%s)",
249 _mesa_enum_to_string(target
));
253 /* The ARB_internalformat_query spec says:
255 * "If the <internalformat> parameter to GetInternalformativ is not
256 * color-, depth- or stencil-renderable, then an INVALID_ENUM error is
259 if (!query2
&& !_is_renderable(ctx
, internalformat
)) {
260 _mesa_error(ctx
, GL_INVALID_ENUM
,
261 "glGetInternalformativ(internalformat=%s)",
262 _mesa_enum_to_string(internalformat
));
269 /* Sets the appropriate "unsupported" response as defined by the
270 * ARB_internalformat_query2 spec for each each <pname>.
273 _set_default_response(GLenum pname
, GLint buffer
[16])
275 /* The ARB_internalformat_query2 defines which is the reponse best
276 * representing "not supported" or "not applicable" for each <pname>.
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."
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 */
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
:
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
:
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
:
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
:
336 case GL_SRGB_DECODE_ARB
:
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
:
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
:
372 case GL_TEXTURE_COMPRESSED
:
373 buffer
[0] = GL_FALSE
;
377 unreachable("invalid 'pname'");
382 _is_target_supported(struct gl_context
*ctx
, GLenum target
)
384 /* The ARB_internalformat_query2 spec says:
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."
396 if (!_mesa_is_desktop_gl(ctx
))
400 case GL_TEXTURE_1D_ARRAY
:
401 if (!_mesa_has_EXT_texture_array(ctx
))
405 case GL_TEXTURE_2D_ARRAY
:
406 if (!(_mesa_has_EXT_texture_array(ctx
) || _mesa_is_gles3(ctx
)))
410 case GL_TEXTURE_CUBE_MAP
:
411 if (!_mesa_has_ARB_texture_cube_map(ctx
))
415 case GL_TEXTURE_CUBE_MAP_ARRAY
:
416 if (!_mesa_has_ARB_texture_cube_map_array(ctx
))
420 case GL_TEXTURE_RECTANGLE
:
421 if (!_mesa_has_NV_texture_rectangle(ctx
))
425 case GL_TEXTURE_BUFFER
:
426 if (!_mesa_has_ARB_texture_buffer_object(ctx
))
430 case GL_RENDERBUFFER
:
431 if (!(_mesa_has_ARB_framebuffer_object(ctx
) ||
432 _mesa_is_gles3(ctx
)))
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
)))
444 unreachable("invalid target");
451 _is_resource_supported(struct gl_context
*ctx
, GLenum target
,
452 GLenum internalformat
, GLenum pname
)
454 /* From the ARB_internalformat_query2 spec:
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.
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.
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
:
482 case GL_TEXTURE_1D_ARRAY
:
484 case GL_TEXTURE_2D_ARRAY
:
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.
492 if (_mesa_base_tex_format(ctx
, internalformat
) < 0)
495 /* additional checks for depth textures */
496 if (!_mesa_legal_texture_base_format_for_target(ctx
, target
, internalformat
))
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
)))
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.
512 if (!_mesa_is_renderable_texture_format(ctx
, internalformat
))
516 case GL_TEXTURE_BUFFER
:
517 /* Based on what Mesa does for the glTexBuffer function. */
518 if (_mesa_validate_texbuffer_format(ctx
, internalformat
) ==
523 case GL_RENDERBUFFER
:
524 /* Based on what Mesa does for glRenderbufferStorage(Multisample) and
525 * glNamedRenderbufferStorage functions.
527 if (!_mesa_base_fbo_format(ctx
, internalformat
))
532 unreachable("bad target");
539 _is_internalformat_supported(struct gl_context
*ctx
, GLenum target
,
540 GLenum internalformat
)
542 /* From the ARB_internalformat_query2 specification:
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.
549 * <internalformats> that must be supported (in GL 4.2 or later) include
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.
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)
568 /* Let the driver have the final word */
569 ctx
->Driver
.QueryInternalFormat(ctx
, target
, internalformat
,
570 GL_INTERNALFORMAT_SUPPORTED
, buffer
);
572 return (buffer
[0] == GL_TRUE
);
575 /* default implementation of QueryInternalFormat driverfunc, for
576 * drivers not implementing ARB_internalformat_query2.
579 _mesa_query_internal_format_default(struct gl_context
*ctx
, GLenum target
,
580 GLenum internalFormat
, GLenum pname
,
585 (void) internalFormat
;
589 case GL_NUM_SAMPLE_COUNTS
:
593 case GL_INTERNALFORMAT_SUPPORTED
:
597 case GL_INTERNALFORMAT_PREFERRED
:
598 params
[0] = internalFormat
;
601 case GL_MANUAL_GENERATE_MIPMAP
:
602 case GL_AUTO_GENERATE_MIPMAP
:
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
;
624 _set_default_response(pname
, params
);
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
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.
640 equivalentSizePname(GLenum target
,
646 case GL_TEXTURE_2D_MULTISAMPLE
:
647 return GL_MAX_TEXTURE_SIZE
;
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
;
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
;
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
;
671 return GL_MAX_CUBE_MAP_TEXTURE_SIZE
;
672 case GL_TEXTURE_BUFFER
:
673 return GL_MAX_TEXTURE_BUFFER_SIZE
;
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.
685 get_target_dimensions(GLenum target
)
688 case GL_TEXTURE_BUFFER
:
690 case GL_RENDERBUFFER
:
693 return _mesa_get_texture_dimensions(target
);
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.
702 * Useful to handle sentences like this from query2 spec:
706 * If the resource does not have at least two dimensions
710 get_min_dimensions(GLenum pname
)
725 * Similar to teximage.c:check_multisample_target, but independent of the
729 is_multisample_target(GLenum target
)
732 case GL_TEXTURE_2D_MULTISAMPLE
:
733 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
742 _mesa_GetInternalformativ(GLenum target
, GLenum internalformat
, GLenum pname
,
743 GLsizei bufSize
, GLint
*params
)
746 GET_CURRENT_CONTEXT(ctx
);
748 ASSERT_OUTSIDE_BEGIN_END(ctx
);
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");
757 assert(ctx
->Driver
.QueryInternalFormat
!= NULL
);
759 if (!_legal_parameters(ctx
, target
, internalformat
, pname
, bufSize
, params
))
762 /* initialize the contents of the temporary buffer */
763 memcpy(buffer
, params
, MIN2(bufSize
, 16) * sizeof(GLint
));
765 /* Use the 'unsupported' response defined by the spec for every pname
766 * as the default answer.
768 _set_default_response(pname
, buffer
);
770 if (!_is_target_supported(ctx
, target
) ||
771 !_is_internalformat_supported(ctx
, target
, internalformat
) ||
772 !_is_resource_supported(ctx
, target
, internalformat
, pname
))
778 case GL_NUM_SAMPLE_COUNTS
:
779 /* The ARB_internalformat_query2 sets the response as 'unsupported' for
780 * SAMPLES and NUM_SAMPLE_COUNTS:
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,
788 if ((target
!= GL_RENDERBUFFER
&&
789 target
!= GL_TEXTURE_2D_MULTISAMPLE
&&
790 target
!= GL_TEXTURE_2D_MULTISAMPLE_ARRAY
) ||
791 !_is_renderable(ctx
, internalformat
))
794 /* The GL ES 3.0 specification, section 6.1.15 page 236 says:
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.
800 if (pname
== GL_NUM_SAMPLE_COUNTS
&& ctx
->API
== API_OPENGLES2
&&
801 ctx
->Version
== 30 && _mesa_is_enum_format_integer(internalformat
)) {
805 ctx
->Driver
.QueryInternalFormat(ctx
, target
, internalformat
, pname
,
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
817 case GL_INTERNALFORMAT_PREFERRED
:
818 /* The ARB_internalformat_query2 spec says:
820 * "- INTERNALFORMAT_PREFERRED: The implementation-preferred internal
821 * format for representing resources of the specified <internalformat> is
822 * returned in <params>.
824 * Therefore, we let the driver answer.
826 ctx
->Driver
.QueryInternalFormat(ctx
, target
, internalformat
, pname
,
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
: {
844 mesa_format texformat
;
846 if (target
!= GL_RENDERBUFFER
) {
847 if (!_mesa_legal_get_tex_level_parameter_target(ctx
, target
, true))
850 baseformat
= _mesa_base_tex_format(ctx
, internalformat
);
852 baseformat
= _mesa_base_fbo_format(ctx
, internalformat
);
855 /* Let the driver choose the texture format.
857 * Disclaimer: I am considering that drivers use for renderbuffers the
858 * same format-choice logic as for textures.
860 texformat
= ctx
->Driver
.ChooseTextureFormat(ctx
, target
, internalformat
,
861 GL_NONE
/*format */, GL_NONE
/* type */);
863 if (texformat
== MESA_FORMAT_NONE
|| baseformat
<= 0)
866 /* Implementation based on what Mesa does for glGetTexLevelParameteriv
867 * and glGetRenderbufferParameteriv functions.
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
) {
879 if (!_mesa_base_format_has_channel(baseformat
, pname
))
883 case GL_INTERNALFORMAT_DEPTH_SIZE
:
884 if (!_mesa_has_ARB_depth_texture(ctx
) &&
885 target
!= GL_RENDERBUFFER
&&
886 target
!= GL_TEXTURE_BUFFER
)
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
);
897 case GL_INTERNALFORMAT_DEPTH_TYPE
:
898 if (!_mesa_has_ARB_texture_float(ctx
))
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
);
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.*/
924 GLint min_dimensions
;
926 /* From query2:MAX_HEIGHT spec (as example):
928 * "If the resource does not have at least two dimensions, or if the
929 * resource is unsupported, zero is returned."
931 dimensions
= get_target_dimensions(target
);
932 min_dimensions
= get_min_dimensions(pname
);
933 if (dimensions
< min_dimensions
)
936 get_pname
= equivalentSizePname(target
, pname
);
940 _mesa_GetIntegerv(get_pname
, buffer
);
945 if (!_mesa_has_EXT_texture_array(ctx
))
948 if (!_mesa_is_array_texture(target
))
951 _mesa_GetIntegerv(GL_MAX_ARRAY_TEXTURE_LAYERS
, buffer
);
954 case GL_MAX_COMBINED_DIMENSIONS
:{
955 GLint64 combined_value
= 1;
956 GLenum max_dimensions_pnames
[] = {
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
))
973 _mesa_GetInternalformativ(target
, internalformat
,
974 max_dimensions_pnames
[i
],
977 if (current_value
!= 0)
978 combined_value
*= current_value
;
981 if (_mesa_is_cube_map_texture(target
))
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
));
992 case GL_COLOR_COMPONENTS
:
993 /* The ARB_internalformat_query2 spec says:
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."
1000 if (_mesa_is_color_format(internalformat
))
1001 buffer
[0] = GL_TRUE
;
1004 case GL_DEPTH_COMPONENTS
:
1005 /* The ARB_internalformat_query2 spec says:
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."
1011 if (_mesa_is_depth_format(internalformat
) ||
1012 _mesa_is_depthstencil_format(internalformat
))
1013 buffer
[0] = GL_TRUE
;
1016 case GL_STENCIL_COMPONENTS
:
1017 /* The ARB_internalformat_query2 spec says:
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.
1023 if (_mesa_is_stencil_format(internalformat
) ||
1024 _mesa_is_depthstencil_format(internalformat
))
1025 buffer
[0] = GL_TRUE
;
1028 case GL_COLOR_RENDERABLE
:
1029 case GL_DEPTH_RENDERABLE
:
1030 case GL_STENCIL_RENDERABLE
:
1031 if (!_is_renderable(ctx
, internalformat
))
1034 if (pname
== GL_COLOR_RENDERABLE
) {
1035 if (!_mesa_is_color_format(internalformat
))
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
)))
1045 buffer
[0] = GL_TRUE
;
1048 case GL_FRAMEBUFFER_RENDERABLE
:
1052 case GL_FRAMEBUFFER_RENDERABLE_LAYERED
:
1056 case GL_FRAMEBUFFER_BLEND
:
1060 case GL_READ_PIXELS
:
1064 case GL_READ_PIXELS_FORMAT
:
1068 case GL_READ_PIXELS_TYPE
:
1072 case GL_TEXTURE_IMAGE_FORMAT
:
1076 case GL_TEXTURE_IMAGE_TYPE
:
1080 case GL_GET_TEXTURE_IMAGE_FORMAT
:
1084 case GL_GET_TEXTURE_IMAGE_TYPE
:
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
,
1097 if (pname
== GL_MIPMAP
) {
1098 buffer
[0] = GL_TRUE
;
1101 else if (pname
== GL_MANUAL_GENERATE_MIPMAP
) {
1102 if (!_mesa_has_ARB_framebuffer_object(ctx
))
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."
1112 if (_mesa_is_desktop_gl(ctx
) && ctx
->Version
>= 32)
1116 ctx
->Driver
.QueryInternalFormat(ctx
, target
, internalformat
, pname
,
1120 case GL_COLOR_ENCODING
:
1121 if (!_mesa_is_color_format(internalformat
))
1124 if (_mesa_is_srgb_format(internalformat
))
1125 buffer
[0] = GL_SRGB
;
1127 buffer
[0] = GL_LINEAR
;
1131 if (!_mesa_has_EXT_texture_sRGB(ctx
) ||
1132 !_mesa_is_srgb_format(internalformat
)) {
1136 ctx
->Driver
.QueryInternalFormat(ctx
, target
, internalformat
, pname
,
1141 if (!_mesa_has_EXT_framebuffer_sRGB(ctx
) ||
1142 !_mesa_is_color_format(internalformat
)) {
1146 ctx
->Driver
.QueryInternalFormat(ctx
, target
, internalformat
, pname
,
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
)) {
1158 ctx
->Driver
.QueryInternalFormat(ctx
, target
, internalformat
, pname
,
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
)
1175 if ((pname
== GL_TESS_CONTROL_TEXTURE
||
1176 pname
== GL_TESS_EVALUATION_TEXTURE
) &&
1177 !_mesa_has_tessellation(ctx
))
1180 if (pname
== GL_GEOMETRY_TEXTURE
&& !_mesa_has_geometry_shaders(ctx
))
1183 if (pname
== GL_COMPUTE_TEXTURE
&& !_mesa_has_compute_shaders(ctx
))
1186 ctx
->Driver
.QueryInternalFormat(ctx
, target
, internalformat
, pname
,
1190 case GL_TEXTURE_SHADOW
:
1194 case GL_TEXTURE_GATHER
:
1198 case GL_TEXTURE_GATHER_SHADOW
:
1202 case GL_SHADER_IMAGE_LOAD
:
1203 case GL_SHADER_IMAGE_STORE
:
1204 if (!_mesa_has_ARB_shader_image_load_store(ctx
))
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."
1213 if (target
== GL_RENDERBUFFER
||
1214 !_mesa_is_shader_image_format_supported(ctx
, internalformat
))
1217 ctx
->Driver
.QueryInternalFormat(ctx
, target
, internalformat
, pname
,
1221 case GL_SHADER_IMAGE_ATOMIC
:
1222 if (!_mesa_has_ARB_shader_image_load_store(ctx
))
1225 ctx
->Driver
.QueryInternalFormat(ctx
, target
, internalformat
, pname
,
1229 case GL_IMAGE_TEXEL_SIZE
: {
1230 mesa_format image_format
;
1232 if (!_mesa_has_ARB_shader_image_load_store(ctx
) ||
1233 target
== GL_RENDERBUFFER
)
1236 image_format
= _mesa_get_shader_image_format(internalformat
);
1237 if (image_format
== MESA_FORMAT_NONE
)
1240 /* We return bits */
1241 buffer
[0] = (_mesa_get_format_bytes(image_format
) * 8);
1245 case GL_IMAGE_COMPATIBILITY_CLASS
:
1246 if (!_mesa_has_ARB_shader_image_load_store(ctx
) ||
1247 target
== GL_RENDERBUFFER
)
1250 buffer
[0] = _mesa_get_image_format_class(internalformat
);
1253 case GL_IMAGE_PIXEL_FORMAT
: {
1256 if (!_mesa_has_ARB_shader_image_load_store(ctx
) ||
1257 target
== GL_RENDERBUFFER
||
1258 !_mesa_is_shader_image_format_supported(ctx
, internalformat
))
1261 base_format
= _mesa_base_tex_format(ctx
, internalformat
);
1262 if (base_format
== -1)
1265 if (_mesa_is_enum_format_integer(internalformat
))
1266 buffer
[0] = _mesa_base_format_to_integer_format(base_format
);
1268 buffer
[0] = base_format
;
1272 case GL_IMAGE_PIXEL_TYPE
: {
1273 mesa_format image_format
;
1277 if (!_mesa_has_ARB_shader_image_load_store(ctx
) ||
1278 target
== GL_RENDERBUFFER
)
1281 image_format
= _mesa_get_shader_image_format(internalformat
);
1282 if (image_format
== MESA_FORMAT_NONE
)
1285 _mesa_uncompressed_format_to_type_and_comps(image_format
, &datatype
,
1290 buffer
[0] = datatype
;
1294 case GL_IMAGE_FORMAT_COMPATIBILITY_TYPE
: {
1295 if (!_mesa_has_ARB_shader_image_load_store(ctx
))
1298 if (!_mesa_legal_get_tex_level_parameter_target(ctx
, target
, true))
1301 /* From spec: "Equivalent to calling GetTexParameter with <value> set
1302 * to IMAGE_FORMAT_COMPATIBILITY_TYPE."
1304 * GetTexParameter just returns
1305 * tex_obj->ImageFormatCompatibilityType. We create a fake tex_obj
1306 * just with the purpose of getting the value.
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
);
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
)
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
)))
1332 ctx
->Driver
.QueryInternalFormat(ctx
, target
, internalformat
, pname
,
1336 case GL_TEXTURE_COMPRESSED
:
1337 buffer
[0] = _mesa_is_compressed_format(ctx
, internalformat
);
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
;
1346 mesaformat
= _mesa_glenum_to_compressed_format(internalformat
);
1347 if (mesaformat
== MESA_FORMAT_NONE
)
1350 block_size
= _mesa_get_format_bytes(mesaformat
);
1351 assert(block_size
> 0);
1353 if (pname
== GL_TEXTURE_COMPRESSED_BLOCK_SIZE
) {
1354 buffer
[0] = block_size
;
1356 GLuint bwidth
, bheight
;
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);
1362 if (pname
== GL_TEXTURE_COMPRESSED_BLOCK_WIDTH
)
1363 buffer
[0] = block_size
/ bheight
;
1365 buffer
[0] = block_size
/ bwidth
;
1370 case GL_CLEAR_BUFFER
:
1371 if (target
!= GL_TEXTURE_BUFFER
)
1374 ctx
->Driver
.QueryInternalFormat(ctx
, target
, internalformat
, pname
,
1378 case GL_TEXTURE_VIEW
:
1382 case GL_VIEW_COMPATIBILITY_CLASS
:
1387 unreachable("bad param");
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.
1396 "glGetInternalformativ(bufSize = %d, but params = NULL)",
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
1404 memcpy(params
, buffer
, MIN2(bufSize
, 16) * sizeof(GLint
));
1410 _mesa_GetInternalformati64v(GLenum target
, GLenum internalformat
,
1411 GLenum pname
, GLsizei bufSize
, GLint64
*params
)
1415 GLsizei realSize
= MIN2(bufSize
, 16);
1418 GET_CURRENT_CONTEXT(ctx
);
1420 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1422 if (!_mesa_has_ARB_internalformat_query2(ctx
)) {
1423 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetInternalformati64v");
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
1431 memset(params32
, -1, 16);
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
1438 if (pname
== GL_MAX_COMBINED_DIMENSIONS
&& bufSize
> 0)
1443 _mesa_GetInternalformativ(target
, internalformat
, pname
, callSize
, params32
);
1445 if (pname
== GL_MAX_COMBINED_DIMENSIONS
) {
1446 memcpy(params
, params32
, sizeof(GLint64
));
1448 for (i
= 0; i
< realSize
; i
++) {
1449 /* We only copy back the values that changed */
1450 if (params32
[i
] < 0)
1452 params
[i
] = (GLint64
) params32
[i
];