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"
37 _is_renderable(struct gl_context
*ctx
, GLenum internalformat
)
39 /* Section 4.4.4 on page 212 of the GLES 3.0.4 spec says:
41 * "An internal format is color-renderable if it is one of the
42 * formats from table 3.13 noted as color-renderable or if it
43 * is unsized format RGBA or RGB."
45 * Therefore, we must accept GL_RGB and GL_RGBA here.
47 if (internalformat
!= GL_RGB
&& internalformat
!= GL_RGBA
&&
48 _mesa_base_fbo_format(ctx
, internalformat
) == 0)
54 /* Handles the cases where either ARB_internalformat_query or
55 * ARB_internalformat_query2 have to return an error.
58 _legal_parameters(struct gl_context
*ctx
, GLenum target
, GLenum internalformat
,
59 GLenum pname
, GLsizei bufSize
, GLint
*params
)
62 bool query2
= _mesa_has_ARB_internalformat_query2(ctx
);
64 /* The ARB_internalformat_query2 spec says:
66 * "The INVALID_ENUM error is generated if the <target> parameter to
67 * GetInternalformati*v is not one of the targets listed in Table 6.xx.
71 case GL_TEXTURE_1D_ARRAY
:
73 case GL_TEXTURE_2D_ARRAY
:
75 case GL_TEXTURE_CUBE_MAP
:
76 case GL_TEXTURE_CUBE_MAP_ARRAY
:
77 case GL_TEXTURE_RECTANGLE
:
78 case GL_TEXTURE_BUFFER
:
80 /* The ARB_internalformat_query spec says:
82 * "If the <target> parameter to GetInternalformativ is not one of
83 * TEXTURE_2D_MULTISAMPLE, TEXTURE_2D_MULTISAMPLE_ARRAY
84 * or RENDERBUFFER then an INVALID_ENUM error is generated.
86 _mesa_error(ctx
, GL_INVALID_ENUM
,
87 "glGetInternalformativ(target=%s)",
88 _mesa_enum_to_string(target
));
97 case GL_TEXTURE_2D_MULTISAMPLE
:
98 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
99 /* The non-existence of ARB_texture_multisample is treated in
100 * ARB_internalformat_query implementation like an error.
103 !(_mesa_has_ARB_texture_multisample(ctx
) || _mesa_is_gles31(ctx
))) {
104 _mesa_error(ctx
, GL_INVALID_ENUM
,
105 "glGetInternalformativ(target=%s)",
106 _mesa_enum_to_string(target
));
113 _mesa_error(ctx
, GL_INVALID_ENUM
,
114 "glGetInternalformativ(target=%s)",
115 _mesa_enum_to_string(target
));
120 /* The ARB_internalformat_query2 spec says:
122 * "The INVALID_ENUM error is generated if the <pname> parameter is
123 * not one of the listed possibilities.
127 case GL_NUM_SAMPLE_COUNTS
:
130 case GL_SRGB_DECODE_ARB
:
131 /* The ARB_internalformat_query2 spec says:
133 * "If ARB_texture_sRGB_decode or EXT_texture_sRGB_decode or
134 * equivalent functionality is not supported, queries for the
135 * SRGB_DECODE_ARB <pname> set the INVALID_ENUM error.
137 if (!_mesa_has_EXT_texture_sRGB_decode(ctx
)) {
138 _mesa_error(ctx
, GL_INVALID_ENUM
,
139 "glGetInternalformativ(pname=%s)",
140 _mesa_enum_to_string(pname
));
144 case GL_INTERNALFORMAT_SUPPORTED
:
145 case GL_INTERNALFORMAT_PREFERRED
:
146 case GL_INTERNALFORMAT_RED_SIZE
:
147 case GL_INTERNALFORMAT_GREEN_SIZE
:
148 case GL_INTERNALFORMAT_BLUE_SIZE
:
149 case GL_INTERNALFORMAT_ALPHA_SIZE
:
150 case GL_INTERNALFORMAT_DEPTH_SIZE
:
151 case GL_INTERNALFORMAT_STENCIL_SIZE
:
152 case GL_INTERNALFORMAT_SHARED_SIZE
:
153 case GL_INTERNALFORMAT_RED_TYPE
:
154 case GL_INTERNALFORMAT_GREEN_TYPE
:
155 case GL_INTERNALFORMAT_BLUE_TYPE
:
156 case GL_INTERNALFORMAT_ALPHA_TYPE
:
157 case GL_INTERNALFORMAT_DEPTH_TYPE
:
158 case GL_INTERNALFORMAT_STENCIL_TYPE
:
163 case GL_MAX_COMBINED_DIMENSIONS
:
164 case GL_COLOR_COMPONENTS
:
165 case GL_DEPTH_COMPONENTS
:
166 case GL_STENCIL_COMPONENTS
:
167 case GL_COLOR_RENDERABLE
:
168 case GL_DEPTH_RENDERABLE
:
169 case GL_STENCIL_RENDERABLE
:
170 case GL_FRAMEBUFFER_RENDERABLE
:
171 case GL_FRAMEBUFFER_RENDERABLE_LAYERED
:
172 case GL_FRAMEBUFFER_BLEND
:
174 case GL_READ_PIXELS_FORMAT
:
175 case GL_READ_PIXELS_TYPE
:
176 case GL_TEXTURE_IMAGE_FORMAT
:
177 case GL_TEXTURE_IMAGE_TYPE
:
178 case GL_GET_TEXTURE_IMAGE_FORMAT
:
179 case GL_GET_TEXTURE_IMAGE_TYPE
:
181 case GL_MANUAL_GENERATE_MIPMAP
:
182 case GL_AUTO_GENERATE_MIPMAP
:
183 case GL_COLOR_ENCODING
:
187 case GL_VERTEX_TEXTURE
:
188 case GL_TESS_CONTROL_TEXTURE
:
189 case GL_TESS_EVALUATION_TEXTURE
:
190 case GL_GEOMETRY_TEXTURE
:
191 case GL_FRAGMENT_TEXTURE
:
192 case GL_COMPUTE_TEXTURE
:
193 case GL_TEXTURE_SHADOW
:
194 case GL_TEXTURE_GATHER
:
195 case GL_TEXTURE_GATHER_SHADOW
:
196 case GL_SHADER_IMAGE_LOAD
:
197 case GL_SHADER_IMAGE_STORE
:
198 case GL_SHADER_IMAGE_ATOMIC
:
199 case GL_IMAGE_TEXEL_SIZE
:
200 case GL_IMAGE_COMPATIBILITY_CLASS
:
201 case GL_IMAGE_PIXEL_FORMAT
:
202 case GL_IMAGE_PIXEL_TYPE
:
203 case GL_IMAGE_FORMAT_COMPATIBILITY_TYPE
:
204 case GL_SIMULTANEOUS_TEXTURE_AND_DEPTH_TEST
:
205 case GL_SIMULTANEOUS_TEXTURE_AND_STENCIL_TEST
:
206 case GL_SIMULTANEOUS_TEXTURE_AND_DEPTH_WRITE
:
207 case GL_SIMULTANEOUS_TEXTURE_AND_STENCIL_WRITE
:
208 case GL_TEXTURE_COMPRESSED
:
209 case GL_TEXTURE_COMPRESSED_BLOCK_WIDTH
:
210 case GL_TEXTURE_COMPRESSED_BLOCK_HEIGHT
:
211 case GL_TEXTURE_COMPRESSED_BLOCK_SIZE
:
212 case GL_CLEAR_BUFFER
:
213 case GL_TEXTURE_VIEW
:
214 case GL_VIEW_COMPATIBILITY_CLASS
:
215 /* The ARB_internalformat_query spec says:
217 * "If the <pname> parameter to GetInternalformativ is not SAMPLES
218 * or NUM_SAMPLE_COUNTS, then an INVALID_ENUM error is generated."
221 _mesa_error(ctx
, GL_INVALID_ENUM
,
222 "glGetInternalformativ(pname=%s)",
223 _mesa_enum_to_string(pname
));
230 _mesa_error(ctx
, GL_INVALID_ENUM
,
231 "glGetInternalformativ(pname=%s)",
232 _mesa_enum_to_string(pname
));
236 /* The ARB_internalformat_query spec says:
238 * "If the <bufSize> parameter to GetInternalformativ is negative, then
239 * an INVALID_VALUE error is generated."
241 * Nothing is said in ARB_internalformat_query2 but we assume the same.
244 _mesa_error(ctx
, GL_INVALID_VALUE
,
245 "glGetInternalformativ(target=%s)",
246 _mesa_enum_to_string(target
));
250 /* The ARB_internalformat_query spec says:
252 * "If the <internalformat> parameter to GetInternalformativ is not
253 * color-, depth- or stencil-renderable, then an INVALID_ENUM error is
256 if (!query2
&& !_is_renderable(ctx
, internalformat
)) {
257 _mesa_error(ctx
, GL_INVALID_ENUM
,
258 "glGetInternalformativ(internalformat=%s)",
259 _mesa_enum_to_string(internalformat
));
266 /* Sets the appropriate "unsupported" response as defined by the
267 * ARB_internalformat_query2 spec for each each <pname>.
270 _set_default_response(GLenum pname
, GLint buffer
[16])
272 /* The ARB_internalformat_query2 defines which is the reponse best
273 * representing "not supported" or "not applicable" for each <pname>.
276 * - size- or count-based queries will return zero,
277 * - support-, format- or type-based queries will return NONE,
278 * - boolean-based queries will return FALSE, and
279 * - list-based queries return no entries."
285 case GL_MAX_COMBINED_DIMENSIONS
:
286 /* This value can be a 64-bit value. As the default is the 32-bit query,
287 * we pack 2 32-bit integers. So we need to clean both */
292 case GL_NUM_SAMPLE_COUNTS
:
293 case GL_INTERNALFORMAT_RED_SIZE
:
294 case GL_INTERNALFORMAT_GREEN_SIZE
:
295 case GL_INTERNALFORMAT_BLUE_SIZE
:
296 case GL_INTERNALFORMAT_ALPHA_SIZE
:
297 case GL_INTERNALFORMAT_DEPTH_SIZE
:
298 case GL_INTERNALFORMAT_STENCIL_SIZE
:
299 case GL_INTERNALFORMAT_SHARED_SIZE
:
304 case GL_IMAGE_TEXEL_SIZE
:
305 case GL_TEXTURE_COMPRESSED_BLOCK_WIDTH
:
306 case GL_TEXTURE_COMPRESSED_BLOCK_HEIGHT
:
307 case GL_TEXTURE_COMPRESSED_BLOCK_SIZE
:
311 case GL_INTERNALFORMAT_PREFERRED
:
312 case GL_INTERNALFORMAT_RED_TYPE
:
313 case GL_INTERNALFORMAT_GREEN_TYPE
:
314 case GL_INTERNALFORMAT_BLUE_TYPE
:
315 case GL_INTERNALFORMAT_ALPHA_TYPE
:
316 case GL_INTERNALFORMAT_DEPTH_TYPE
:
317 case GL_INTERNALFORMAT_STENCIL_TYPE
:
318 case GL_FRAMEBUFFER_RENDERABLE
:
319 case GL_FRAMEBUFFER_RENDERABLE_LAYERED
:
320 case GL_FRAMEBUFFER_BLEND
:
322 case GL_READ_PIXELS_FORMAT
:
323 case GL_READ_PIXELS_TYPE
:
324 case GL_TEXTURE_IMAGE_FORMAT
:
325 case GL_TEXTURE_IMAGE_TYPE
:
326 case GL_GET_TEXTURE_IMAGE_FORMAT
:
327 case GL_GET_TEXTURE_IMAGE_TYPE
:
328 case GL_MANUAL_GENERATE_MIPMAP
:
329 case GL_AUTO_GENERATE_MIPMAP
:
330 case GL_COLOR_ENCODING
:
333 case GL_SRGB_DECODE_ARB
:
335 case GL_VERTEX_TEXTURE
:
336 case GL_TESS_CONTROL_TEXTURE
:
337 case GL_TESS_EVALUATION_TEXTURE
:
338 case GL_GEOMETRY_TEXTURE
:
339 case GL_FRAGMENT_TEXTURE
:
340 case GL_COMPUTE_TEXTURE
:
341 case GL_TEXTURE_SHADOW
:
342 case GL_TEXTURE_GATHER
:
343 case GL_TEXTURE_GATHER_SHADOW
:
344 case GL_SHADER_IMAGE_LOAD
:
345 case GL_SHADER_IMAGE_STORE
:
346 case GL_SHADER_IMAGE_ATOMIC
:
347 case GL_IMAGE_COMPATIBILITY_CLASS
:
348 case GL_IMAGE_PIXEL_FORMAT
:
349 case GL_IMAGE_PIXEL_TYPE
:
350 case GL_IMAGE_FORMAT_COMPATIBILITY_TYPE
:
351 case GL_SIMULTANEOUS_TEXTURE_AND_DEPTH_TEST
:
352 case GL_SIMULTANEOUS_TEXTURE_AND_STENCIL_TEST
:
353 case GL_SIMULTANEOUS_TEXTURE_AND_DEPTH_WRITE
:
354 case GL_SIMULTANEOUS_TEXTURE_AND_STENCIL_WRITE
:
355 case GL_CLEAR_BUFFER
:
356 case GL_TEXTURE_VIEW
:
357 case GL_VIEW_COMPATIBILITY_CLASS
:
361 case GL_INTERNALFORMAT_SUPPORTED
:
362 case GL_COLOR_COMPONENTS
:
363 case GL_DEPTH_COMPONENTS
:
364 case GL_STENCIL_COMPONENTS
:
365 case GL_COLOR_RENDERABLE
:
366 case GL_DEPTH_RENDERABLE
:
367 case GL_STENCIL_RENDERABLE
:
369 case GL_TEXTURE_COMPRESSED
:
370 buffer
[0] = GL_FALSE
;
374 unreachable("invalid 'pname'");
379 _is_target_supported(struct gl_context
*ctx
, GLenum target
)
381 /* The ARB_internalformat_query2 spec says:
383 * "if a particular type of <target> is not supported by the
384 * implementation the "unsupported" answer should be given.
385 * This is not an error."
393 if (!_mesa_is_desktop_gl(ctx
))
397 case GL_TEXTURE_1D_ARRAY
:
398 if (!_mesa_has_EXT_texture_array(ctx
))
402 case GL_TEXTURE_2D_ARRAY
:
403 if (!(_mesa_has_EXT_texture_array(ctx
) || _mesa_is_gles3(ctx
)))
407 case GL_TEXTURE_CUBE_MAP
:
408 if (!_mesa_has_ARB_texture_cube_map(ctx
))
412 case GL_TEXTURE_CUBE_MAP_ARRAY
:
413 if (!_mesa_has_ARB_texture_cube_map_array(ctx
))
417 case GL_TEXTURE_RECTANGLE
:
418 if (!_mesa_has_NV_texture_rectangle(ctx
))
422 case GL_TEXTURE_BUFFER
:
423 if (!_mesa_has_ARB_texture_buffer_object(ctx
))
427 case GL_RENDERBUFFER
:
428 if (!(_mesa_has_ARB_framebuffer_object(ctx
) ||
429 _mesa_is_gles3(ctx
)))
433 case GL_TEXTURE_2D_MULTISAMPLE
:
434 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
435 if (!(_mesa_has_ARB_texture_multisample(ctx
) ||
436 _mesa_is_gles31(ctx
)))
441 unreachable("invalid target");
448 _is_resource_supported(struct gl_context
*ctx
, GLenum target
,
449 GLenum internalformat
, GLenum pname
)
451 /* From the ARB_internalformat_query2 spec:
453 * In the following descriptions, the term /resource/ is used to generically
454 * refer to an object of the appropriate type that has been created with
455 * <internalformat> and <target>. If the particular <target> and
456 * <internalformat> combination do not make sense, ... the "unsupported"
457 * answer should be given. This is not an error.
460 /* In the ARB_internalformat_query2 spec wording, some <pnames> do not care
461 * about the /resource/ being supported or not, we return 'true' for those.
464 case GL_INTERNALFORMAT_SUPPORTED
:
465 case GL_INTERNALFORMAT_PREFERRED
:
466 case GL_COLOR_COMPONENTS
:
467 case GL_DEPTH_COMPONENTS
:
468 case GL_STENCIL_COMPONENTS
:
469 case GL_COLOR_RENDERABLE
:
470 case GL_DEPTH_RENDERABLE
:
471 case GL_STENCIL_RENDERABLE
:
479 case GL_TEXTURE_1D_ARRAY
:
481 case GL_TEXTURE_2D_ARRAY
:
483 case GL_TEXTURE_CUBE_MAP
:
484 case GL_TEXTURE_CUBE_MAP_ARRAY
:
485 case GL_TEXTURE_RECTANGLE
:
486 /* Based on what Mesa does for glTexImage1D/2D/3D and
487 * glCompressedTexImage1D/2D/3D functions.
489 if (_mesa_base_tex_format(ctx
, internalformat
) < 0)
492 /* additional checks for depth textures */
493 if (!_mesa_legal_texture_base_format_for_target(ctx
, target
, internalformat
))
496 /* additional checks for compressed textures */
497 if (_mesa_is_compressed_format(ctx
, internalformat
) &&
498 (!_mesa_target_can_be_compressed(ctx
, target
, internalformat
, NULL
) ||
499 _mesa_format_no_online_compression(ctx
, internalformat
)))
503 case GL_TEXTURE_2D_MULTISAMPLE
:
504 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
505 /* Based on what Mesa does for glTexImage2D/3DMultisample,
506 * glTexStorage2D/3DMultisample and
507 * glTextureStorage2D/3DMultisample functions.
509 if (!_mesa_is_renderable_texture_format(ctx
, internalformat
))
513 case GL_TEXTURE_BUFFER
:
514 /* Based on what Mesa does for the glTexBuffer function. */
515 if (_mesa_validate_texbuffer_format(ctx
, internalformat
) ==
520 case GL_RENDERBUFFER
:
521 /* Based on what Mesa does for glRenderbufferStorage(Multisample) and
522 * glNamedRenderbufferStorage functions.
524 if (!_mesa_base_fbo_format(ctx
, internalformat
))
529 unreachable("bad target");
536 _is_internalformat_supported(struct gl_context
*ctx
, GLenum target
,
537 GLenum internalformat
)
539 /* From the ARB_internalformat_query2 specification:
541 * "- INTERNALFORMAT_SUPPORTED: If <internalformat> is an internal format
542 * that is supported by the implementation in at least some subset of
543 * possible operations, TRUE is written to <params>. If <internalformat>
544 * if not a valid token for any internal format usage, FALSE is returned.
546 * <internalformats> that must be supported (in GL 4.2 or later) include
548 * - "sized internal formats" from Table 3.12, 3.13, and 3.15,
549 * - any specific "compressed internal format" from Table 3.14,
550 * - any "image unit format" from Table 3.21.
551 * - any generic "compressed internal format" from Table 3.14, if the
552 * implementation accepts it for any texture specification commands, and
553 * - unsized or base internal format, if the implementation accepts
554 * it for texture or image specification.
558 /* At this point a internalformat is valid if it is valid as a texture or
559 * as a renderbuffer format. The checks are different because those methods
560 * return different values when passing non supported internalformats */
561 if (_mesa_base_tex_format(ctx
, internalformat
) < 0 &&
562 _mesa_base_fbo_format(ctx
, internalformat
) == 0)
565 /* Let the driver have the final word */
566 ctx
->Driver
.QueryInternalFormat(ctx
, target
, internalformat
,
567 GL_INTERNALFORMAT_SUPPORTED
, buffer
);
569 return (buffer
[0] == GL_TRUE
);
572 /* default implementation of QueryInternalFormat driverfunc, for
573 * drivers not implementing ARB_internalformat_query2.
576 _mesa_query_internal_format_default(struct gl_context
*ctx
, GLenum target
,
577 GLenum internalFormat
, GLenum pname
,
582 (void) internalFormat
;
586 case GL_NUM_SAMPLE_COUNTS
:
590 case GL_INTERNALFORMAT_SUPPORTED
:
594 case GL_INTERNALFORMAT_PREFERRED
:
595 params
[0] = internalFormat
;
599 _set_default_response(pname
, params
);
605 * For MAX_WIDTH/MAX_HEIGHT/MAX_DEPTH it returns the equivalent GetInteger
606 * pname for a Getinternalformat pname/target combination. target/pname
607 * combinations that would return 0 due dimension number or unsupported status
608 * should be already filtered out
610 * Note that this means that the returned value would be independent of the
611 * internalformat. This possibility is already mentioned at the Issue 7 of the
612 * arb_internalformat_query2 spec.
615 equivalentSizePname(GLenum target
,
621 case GL_TEXTURE_2D_MULTISAMPLE
:
622 return GL_MAX_TEXTURE_SIZE
;
624 return GL_MAX_3D_TEXTURE_SIZE
;
625 case GL_TEXTURE_CUBE_MAP
:
626 return GL_MAX_CUBE_MAP_TEXTURE_SIZE
;
627 case GL_TEXTURE_RECTANGLE
:
628 return GL_MAX_RECTANGLE_TEXTURE_SIZE
;
629 case GL_RENDERBUFFER
:
630 return GL_MAX_RENDERBUFFER_SIZE
;
631 case GL_TEXTURE_1D_ARRAY
:
632 if (pname
== GL_MAX_HEIGHT
)
633 return GL_MAX_ARRAY_TEXTURE_LAYERS
;
635 return GL_MAX_TEXTURE_SIZE
;
636 case GL_TEXTURE_2D_ARRAY
:
637 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
638 if (pname
== GL_MAX_DEPTH
)
639 return GL_MAX_ARRAY_TEXTURE_LAYERS
;
641 return GL_MAX_TEXTURE_SIZE
;
642 case GL_TEXTURE_CUBE_MAP_ARRAY
:
643 if (pname
== GL_MAX_DEPTH
)
644 return GL_MAX_ARRAY_TEXTURE_LAYERS
;
646 return GL_MAX_CUBE_MAP_TEXTURE_SIZE
;
647 case GL_TEXTURE_BUFFER
:
648 return GL_MAX_TEXTURE_BUFFER_SIZE
;
655 * Returns the dimensions associated to a target. GL_TEXTURE_BUFFER and
656 * GL_RENDERBUFFER have associated a dimension, but they are not textures
657 * per-se, so we can't just call _mesa_get_texture_dimension directly.
660 get_target_dimensions(GLenum target
)
663 case GL_TEXTURE_BUFFER
:
665 case GL_RENDERBUFFER
:
668 return _mesa_get_texture_dimensions(target
);
673 * Returns the minimum amount of dimensions associated to a pname. So for
674 * example, if querying GL_MAX_HEIGHT, it is assumed that your target would
675 * have as minimum 2 dimensions.
677 * Useful to handle sentences like this from query2 spec:
681 * If the resource does not have at least two dimensions
685 get_min_dimensions(GLenum pname
)
700 * Similar to teximage.c:check_multisample_target, but independent of the
704 is_multisample_target(GLenum target
)
707 case GL_TEXTURE_2D_MULTISAMPLE
:
708 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
717 _mesa_GetInternalformativ(GLenum target
, GLenum internalformat
, GLenum pname
,
718 GLsizei bufSize
, GLint
*params
)
721 GET_CURRENT_CONTEXT(ctx
);
723 ASSERT_OUTSIDE_BEGIN_END(ctx
);
725 /* ARB_internalformat_query is also mandatory for ARB_internalformat_query2 */
726 if (!(_mesa_has_ARB_internalformat_query(ctx
) ||
727 _mesa_is_gles3(ctx
))) {
728 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetInternalformativ");
732 assert(ctx
->Driver
.QueryInternalFormat
!= NULL
);
734 if (!_legal_parameters(ctx
, target
, internalformat
, pname
, bufSize
, params
))
737 /* initialize the contents of the temporary buffer */
738 memcpy(buffer
, params
, MIN2(bufSize
, 16) * sizeof(GLint
));
740 /* Use the 'unsupported' response defined by the spec for every pname
741 * as the default answer.
743 _set_default_response(pname
, buffer
);
745 if (!_is_target_supported(ctx
, target
) ||
746 !_is_internalformat_supported(ctx
, target
, internalformat
) ||
747 !_is_resource_supported(ctx
, target
, internalformat
, pname
))
753 case GL_NUM_SAMPLE_COUNTS
:
754 /* The ARB_internalformat_query2 sets the response as 'unsupported' for
755 * SAMPLES and NUM_SAMPLE_COUNTS:
757 * "If <internalformat> is not color-renderable, depth-renderable, or
758 * stencil-renderable (as defined in section 4.4.4), or if <target>
759 * does not support multiple samples (ie other than
760 * TEXTURE_2D_MULTISAMPLE, TEXTURE_2D_MULTISAMPLE_ARRAY,
763 if ((target
!= GL_RENDERBUFFER
&&
764 target
!= GL_TEXTURE_2D_MULTISAMPLE
&&
765 target
!= GL_TEXTURE_2D_MULTISAMPLE_ARRAY
) ||
766 !_is_renderable(ctx
, internalformat
))
769 /* The GL ES 3.0 specification, section 6.1.15 page 236 says:
771 * "Since multisampling is not supported for signed and unsigned
772 * integer internal formats, the value of NUM_SAMPLE_COUNTS will be
773 * zero for such formats.
775 if (pname
== GL_NUM_SAMPLE_COUNTS
&& ctx
->API
== API_OPENGLES2
&&
776 ctx
->Version
== 30 && _mesa_is_enum_format_integer(internalformat
)) {
780 ctx
->Driver
.QueryInternalFormat(ctx
, target
, internalformat
, pname
,
784 case GL_INTERNALFORMAT_SUPPORTED
:
785 /* Having a supported <internalformat> is implemented as a prerequisite
786 * for all the <pnames>. Thus, if we reach this point, the internalformat is
792 case GL_INTERNALFORMAT_PREFERRED
:
793 /* The ARB_internalformat_query2 spec says:
795 * "- INTERNALFORMAT_PREFERRED: The implementation-preferred internal
796 * format for representing resources of the specified <internalformat> is
797 * returned in <params>.
799 * Therefore, we let the driver answer.
801 ctx
->Driver
.QueryInternalFormat(ctx
, target
, internalformat
, pname
,
805 case GL_INTERNALFORMAT_RED_SIZE
:
806 case GL_INTERNALFORMAT_GREEN_SIZE
:
807 case GL_INTERNALFORMAT_BLUE_SIZE
:
808 case GL_INTERNALFORMAT_ALPHA_SIZE
:
809 case GL_INTERNALFORMAT_DEPTH_SIZE
:
810 case GL_INTERNALFORMAT_STENCIL_SIZE
:
811 case GL_INTERNALFORMAT_SHARED_SIZE
:
812 case GL_INTERNALFORMAT_RED_TYPE
:
813 case GL_INTERNALFORMAT_GREEN_TYPE
:
814 case GL_INTERNALFORMAT_BLUE_TYPE
:
815 case GL_INTERNALFORMAT_ALPHA_TYPE
:
816 case GL_INTERNALFORMAT_DEPTH_TYPE
:
817 case GL_INTERNALFORMAT_STENCIL_TYPE
: {
819 mesa_format texformat
;
821 if (target
!= GL_RENDERBUFFER
) {
822 if (!_mesa_legal_get_tex_level_parameter_target(ctx
, target
, true))
825 baseformat
= _mesa_base_tex_format(ctx
, internalformat
);
827 baseformat
= _mesa_base_fbo_format(ctx
, internalformat
);
830 /* Let the driver choose the texture format.
832 * Disclaimer: I am considering that drivers use for renderbuffers the
833 * same format-choice logic as for textures.
835 texformat
= ctx
->Driver
.ChooseTextureFormat(ctx
, target
, internalformat
,
836 GL_NONE
/*format */, GL_NONE
/* type */);
838 if (texformat
== MESA_FORMAT_NONE
|| baseformat
<= 0)
841 /* Implementation based on what Mesa does for glGetTexLevelParameteriv
842 * and glGetRenderbufferParameteriv functions.
844 if (pname
== GL_INTERNALFORMAT_SHARED_SIZE
) {
845 if (_mesa_has_EXT_texture_shared_exponent(ctx
) &&
846 target
!= GL_TEXTURE_BUFFER
&&
847 target
!= GL_RENDERBUFFER
&&
848 texformat
== MESA_FORMAT_R9G9B9E5_FLOAT
) {
854 if (!_mesa_base_format_has_channel(baseformat
, pname
))
858 case GL_INTERNALFORMAT_DEPTH_SIZE
:
859 if (!_mesa_has_ARB_depth_texture(ctx
) &&
860 target
!= GL_RENDERBUFFER
&&
861 target
!= GL_TEXTURE_BUFFER
)
864 case GL_INTERNALFORMAT_RED_SIZE
:
865 case GL_INTERNALFORMAT_GREEN_SIZE
:
866 case GL_INTERNALFORMAT_BLUE_SIZE
:
867 case GL_INTERNALFORMAT_ALPHA_SIZE
:
868 case GL_INTERNALFORMAT_STENCIL_SIZE
:
869 buffer
[0] = _mesa_get_format_bits(texformat
, pname
);
872 case GL_INTERNALFORMAT_DEPTH_TYPE
:
873 if (!_mesa_has_ARB_texture_float(ctx
))
876 case GL_INTERNALFORMAT_RED_TYPE
:
877 case GL_INTERNALFORMAT_GREEN_TYPE
:
878 case GL_INTERNALFORMAT_BLUE_TYPE
:
879 case GL_INTERNALFORMAT_ALPHA_TYPE
:
880 case GL_INTERNALFORMAT_STENCIL_TYPE
:
881 buffer
[0] = _mesa_get_format_datatype(texformat
);
891 /* For WIDTH/HEIGHT/DEPTH/LAYERS there is no reason to think that the
892 * returned values should be different to the values returned by
893 * GetInteger with MAX_TEXTURE_SIZE, MAX_3D_TEXTURE_SIZE, etc.*/
899 GLint min_dimensions
;
901 /* From query2:MAX_HEIGHT spec (as example):
903 * "If the resource does not have at least two dimensions, or if the
904 * resource is unsupported, zero is returned."
906 dimensions
= get_target_dimensions(target
);
907 min_dimensions
= get_min_dimensions(pname
);
908 if (dimensions
< min_dimensions
)
911 get_pname
= equivalentSizePname(target
, pname
);
915 _mesa_GetIntegerv(get_pname
, buffer
);
920 if (!_mesa_has_EXT_texture_array(ctx
))
923 if (!_mesa_is_array_texture(target
))
926 _mesa_GetIntegerv(GL_MAX_ARRAY_TEXTURE_LAYERS
, buffer
);
929 case GL_MAX_COMBINED_DIMENSIONS
:{
930 GLint64 combined_value
= 1;
931 GLenum max_dimensions_pnames
[] = {
940 /* Combining the dimensions. Note that for array targets, this would
941 * automatically include the value of MAX_LAYERS, as that value is
942 * returned as MAX_HEIGHT or MAX_DEPTH */
943 for (i
= 0; i
< 4; i
++) {
944 if (max_dimensions_pnames
[i
] == GL_SAMPLES
&&
945 !is_multisample_target(target
))
948 _mesa_GetInternalformativ(target
, internalformat
,
949 max_dimensions_pnames
[i
],
952 if (current_value
!= 0)
953 combined_value
*= current_value
;
956 if (_mesa_is_cube_map_texture(target
))
959 /* We pack the 64-bit value on two 32-bit values. Calling the 32-bit
960 * query, this would work as far as the value can be hold on a 32-bit
961 * signed integer. For the 64-bit query, the wrapper around the 32-bit
962 * query will unpack the value */
963 memcpy(buffer
, &combined_value
, sizeof(GLint64
));
967 case GL_COLOR_COMPONENTS
:
968 /* The ARB_internalformat_query2 spec says:
970 * "- COLOR_COMPONENTS: If the internal format contains any color
971 * components (R, G, B, or A), TRUE is returned in <params>.
972 * If the internal format is unsupported or contains no color
973 * components, FALSE is returned."
975 if (_mesa_is_color_format(internalformat
))
979 case GL_DEPTH_COMPONENTS
:
980 /* The ARB_internalformat_query2 spec says:
982 * "- DEPTH_COMPONENTS: If the internal format contains a depth
983 * component (D), TRUE is returned in <params>. If the internal format
984 * is unsupported or contains no depth component, FALSE is returned."
986 if (_mesa_is_depth_format(internalformat
) ||
987 _mesa_is_depthstencil_format(internalformat
))
991 case GL_STENCIL_COMPONENTS
:
992 /* The ARB_internalformat_query2 spec says:
994 * "- STENCIL_COMPONENTS: If the internal format contains a stencil
995 * component (S), TRUE is returned in <params>. If the internal format
996 * is unsupported or contains no stencil component, FALSE is returned.
998 if (_mesa_is_stencil_format(internalformat
) ||
999 _mesa_is_depthstencil_format(internalformat
))
1000 buffer
[0] = GL_TRUE
;
1003 case GL_COLOR_RENDERABLE
:
1004 case GL_DEPTH_RENDERABLE
:
1005 case GL_STENCIL_RENDERABLE
:
1006 if (!_is_renderable(ctx
, internalformat
))
1009 if (pname
== GL_COLOR_RENDERABLE
) {
1010 if (!_mesa_is_color_format(internalformat
))
1013 GLenum baseFormat
= _mesa_base_fbo_format(ctx
, internalformat
);
1014 if (baseFormat
!= GL_DEPTH_STENCIL
&&
1015 ((pname
== GL_DEPTH_RENDERABLE
&& baseFormat
!= GL_DEPTH_COMPONENT
) ||
1016 (pname
== GL_STENCIL_RENDERABLE
&& baseFormat
!= GL_STENCIL_INDEX
)))
1020 buffer
[0] = GL_TRUE
;
1023 case GL_FRAMEBUFFER_RENDERABLE
:
1027 case GL_FRAMEBUFFER_RENDERABLE_LAYERED
:
1031 case GL_FRAMEBUFFER_BLEND
:
1035 case GL_READ_PIXELS
:
1039 case GL_READ_PIXELS_FORMAT
:
1043 case GL_READ_PIXELS_TYPE
:
1047 case GL_TEXTURE_IMAGE_FORMAT
:
1051 case GL_TEXTURE_IMAGE_TYPE
:
1055 case GL_GET_TEXTURE_IMAGE_FORMAT
:
1059 case GL_GET_TEXTURE_IMAGE_TYPE
:
1067 case GL_MANUAL_GENERATE_MIPMAP
:
1071 case GL_AUTO_GENERATE_MIPMAP
:
1075 case GL_COLOR_ENCODING
:
1087 case GL_SRGB_DECODE_ARB
:
1095 case GL_VERTEX_TEXTURE
:
1099 case GL_TESS_CONTROL_TEXTURE
:
1103 case GL_TESS_EVALUATION_TEXTURE
:
1107 case GL_GEOMETRY_TEXTURE
:
1111 case GL_FRAGMENT_TEXTURE
:
1115 case GL_COMPUTE_TEXTURE
:
1119 case GL_TEXTURE_SHADOW
:
1123 case GL_TEXTURE_GATHER
:
1127 case GL_TEXTURE_GATHER_SHADOW
:
1131 case GL_SHADER_IMAGE_LOAD
:
1135 case GL_SHADER_IMAGE_STORE
:
1139 case GL_SHADER_IMAGE_ATOMIC
:
1143 case GL_IMAGE_TEXEL_SIZE
:
1147 case GL_IMAGE_COMPATIBILITY_CLASS
:
1151 case GL_IMAGE_PIXEL_FORMAT
:
1155 case GL_IMAGE_PIXEL_TYPE
:
1159 case GL_IMAGE_FORMAT_COMPATIBILITY_TYPE
: {
1160 if (!_mesa_has_ARB_shader_image_load_store(ctx
))
1163 if (!_mesa_legal_get_tex_level_parameter_target(ctx
, target
, true))
1166 /* From spec: "Equivalent to calling GetTexParameter with <value> set
1167 * to IMAGE_FORMAT_COMPATIBILITY_TYPE."
1169 * GetTexParameter just returns
1170 * tex_obj->ImageFormatCompatibilityType. We create a fake tex_obj
1171 * just with the purpose of getting the value.
1173 struct gl_texture_object
*tex_obj
= _mesa_new_texture_object(ctx
, 0, target
);
1174 buffer
[0] = tex_obj
->ImageFormatCompatibilityType
;
1175 _mesa_delete_texture_object(ctx
, tex_obj
);
1180 case GL_SIMULTANEOUS_TEXTURE_AND_DEPTH_TEST
:
1184 case GL_SIMULTANEOUS_TEXTURE_AND_STENCIL_TEST
:
1188 case GL_SIMULTANEOUS_TEXTURE_AND_DEPTH_WRITE
:
1192 case GL_SIMULTANEOUS_TEXTURE_AND_STENCIL_WRITE
:
1196 case GL_TEXTURE_COMPRESSED
:
1200 case GL_TEXTURE_COMPRESSED_BLOCK_WIDTH
:
1204 case GL_TEXTURE_COMPRESSED_BLOCK_HEIGHT
:
1208 case GL_TEXTURE_COMPRESSED_BLOCK_SIZE
:
1212 case GL_CLEAR_BUFFER
:
1216 case GL_TEXTURE_VIEW
:
1220 case GL_VIEW_COMPATIBILITY_CLASS
:
1225 unreachable("bad param");
1229 if (bufSize
!= 0 && params
== NULL
) {
1230 /* Emit a warning to aid application debugging, but go ahead and do the
1231 * memcpy (and probably crash) anyway.
1234 "glGetInternalformativ(bufSize = %d, but params = NULL)",
1238 /* Copy the data from the temporary buffer to the buffer supplied by the
1239 * application. Clamp the size of the copy to the size supplied by the
1242 memcpy(params
, buffer
, MIN2(bufSize
, 16) * sizeof(GLint
));
1248 _mesa_GetInternalformati64v(GLenum target
, GLenum internalformat
,
1249 GLenum pname
, GLsizei bufSize
, GLint64
*params
)
1253 GLsizei realSize
= MIN2(bufSize
, 16);
1256 GET_CURRENT_CONTEXT(ctx
);
1258 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1260 if (!_mesa_has_ARB_internalformat_query2(ctx
)) {
1261 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetInternalformati64v");
1265 /* For SAMPLES there are cases where params needs to remain unmodified. As
1266 * no pname can return a negative value, we fill params32 with negative
1267 * values as reference values, that can be used to know what copy-back to
1269 memset(params32
, -1, 16);
1271 /* For GL_MAX_COMBINED_DIMENSIONS we need to get back 2 32-bit integers,
1272 * and at the same time we only need 2. So for that pname, we call the
1273 * 32-bit query with bufSize 2, except on the case of bufSize 0, that is
1274 * basically like asking to not get the value, but that is a caller
1276 if (pname
== GL_MAX_COMBINED_DIMENSIONS
&& bufSize
> 0)
1281 _mesa_GetInternalformativ(target
, internalformat
, pname
, callSize
, params32
);
1283 if (pname
== GL_MAX_COMBINED_DIMENSIONS
) {
1284 memcpy(params
, params32
, sizeof(GLint64
));
1286 for (i
= 0; i
< realSize
; i
++) {
1287 /* We only copy back the values that changed */
1288 if (params32
[i
] < 0)
1290 params
[i
] = (GLint64
) params32
[i
];