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"
38 _is_renderable(struct gl_context
*ctx
, GLenum internalformat
)
40 /* Section 4.4.4 on page 212 of the GLES 3.0.4 spec says:
42 * "An internal format is color-renderable if it is one of the
43 * formats from table 3.13 noted as color-renderable or if it
44 * is unsized format RGBA or RGB."
46 * Therefore, we must accept GL_RGB and GL_RGBA here.
48 if (internalformat
!= GL_RGB
&& internalformat
!= GL_RGBA
&&
49 _mesa_base_fbo_format(ctx
, internalformat
) == 0)
55 /* Handles the cases where either ARB_internalformat_query or
56 * ARB_internalformat_query2 have to return an error.
59 _legal_parameters(struct gl_context
*ctx
, GLenum target
, GLenum internalformat
,
60 GLenum pname
, GLsizei bufSize
, GLint
*params
)
63 bool query2
= _mesa_has_ARB_internalformat_query2(ctx
);
65 /* The ARB_internalformat_query2 spec says:
67 * "The INVALID_ENUM error is generated if the <target> parameter to
68 * GetInternalformati*v is not one of the targets listed in Table 6.xx.
72 case GL_TEXTURE_1D_ARRAY
:
74 case GL_TEXTURE_2D_ARRAY
:
76 case GL_TEXTURE_CUBE_MAP
:
77 case GL_TEXTURE_CUBE_MAP_ARRAY
:
78 case GL_TEXTURE_RECTANGLE
:
79 case GL_TEXTURE_BUFFER
:
81 /* The ARB_internalformat_query spec says:
83 * "If the <target> parameter to GetInternalformativ is not one of
84 * TEXTURE_2D_MULTISAMPLE, TEXTURE_2D_MULTISAMPLE_ARRAY
85 * or RENDERBUFFER then an INVALID_ENUM error is generated.
87 _mesa_error(ctx
, GL_INVALID_ENUM
,
88 "glGetInternalformativ(target=%s)",
89 _mesa_enum_to_string(target
));
98 case GL_TEXTURE_2D_MULTISAMPLE
:
99 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
100 /* The non-existence of ARB_texture_multisample is treated in
101 * ARB_internalformat_query implementation like an error.
104 !(_mesa_has_ARB_texture_multisample(ctx
) || _mesa_is_gles31(ctx
))) {
105 _mesa_error(ctx
, GL_INVALID_ENUM
,
106 "glGetInternalformativ(target=%s)",
107 _mesa_enum_to_string(target
));
114 _mesa_error(ctx
, GL_INVALID_ENUM
,
115 "glGetInternalformativ(target=%s)",
116 _mesa_enum_to_string(target
));
121 /* The ARB_internalformat_query2 spec says:
123 * "The INVALID_ENUM error is generated if the <pname> parameter is
124 * not one of the listed possibilities.
128 case GL_NUM_SAMPLE_COUNTS
:
131 case GL_SRGB_DECODE_ARB
:
132 /* The ARB_internalformat_query2 spec says:
134 * "If ARB_texture_sRGB_decode or EXT_texture_sRGB_decode or
135 * equivalent functionality is not supported, queries for the
136 * SRGB_DECODE_ARB <pname> set the INVALID_ENUM error.
138 if (!_mesa_has_EXT_texture_sRGB_decode(ctx
)) {
139 _mesa_error(ctx
, GL_INVALID_ENUM
,
140 "glGetInternalformativ(pname=%s)",
141 _mesa_enum_to_string(pname
));
145 case GL_INTERNALFORMAT_SUPPORTED
:
146 case GL_INTERNALFORMAT_PREFERRED
:
147 case GL_INTERNALFORMAT_RED_SIZE
:
148 case GL_INTERNALFORMAT_GREEN_SIZE
:
149 case GL_INTERNALFORMAT_BLUE_SIZE
:
150 case GL_INTERNALFORMAT_ALPHA_SIZE
:
151 case GL_INTERNALFORMAT_DEPTH_SIZE
:
152 case GL_INTERNALFORMAT_STENCIL_SIZE
:
153 case GL_INTERNALFORMAT_SHARED_SIZE
:
154 case GL_INTERNALFORMAT_RED_TYPE
:
155 case GL_INTERNALFORMAT_GREEN_TYPE
:
156 case GL_INTERNALFORMAT_BLUE_TYPE
:
157 case GL_INTERNALFORMAT_ALPHA_TYPE
:
158 case GL_INTERNALFORMAT_DEPTH_TYPE
:
159 case GL_INTERNALFORMAT_STENCIL_TYPE
:
164 case GL_MAX_COMBINED_DIMENSIONS
:
165 case GL_COLOR_COMPONENTS
:
166 case GL_DEPTH_COMPONENTS
:
167 case GL_STENCIL_COMPONENTS
:
168 case GL_COLOR_RENDERABLE
:
169 case GL_DEPTH_RENDERABLE
:
170 case GL_STENCIL_RENDERABLE
:
171 case GL_FRAMEBUFFER_RENDERABLE
:
172 case GL_FRAMEBUFFER_RENDERABLE_LAYERED
:
173 case GL_FRAMEBUFFER_BLEND
:
175 case GL_READ_PIXELS_FORMAT
:
176 case GL_READ_PIXELS_TYPE
:
177 case GL_TEXTURE_IMAGE_FORMAT
:
178 case GL_TEXTURE_IMAGE_TYPE
:
179 case GL_GET_TEXTURE_IMAGE_FORMAT
:
180 case GL_GET_TEXTURE_IMAGE_TYPE
:
182 case GL_MANUAL_GENERATE_MIPMAP
:
183 case GL_AUTO_GENERATE_MIPMAP
:
184 case GL_COLOR_ENCODING
:
188 case GL_VERTEX_TEXTURE
:
189 case GL_TESS_CONTROL_TEXTURE
:
190 case GL_TESS_EVALUATION_TEXTURE
:
191 case GL_GEOMETRY_TEXTURE
:
192 case GL_FRAGMENT_TEXTURE
:
193 case GL_COMPUTE_TEXTURE
:
194 case GL_TEXTURE_SHADOW
:
195 case GL_TEXTURE_GATHER
:
196 case GL_TEXTURE_GATHER_SHADOW
:
197 case GL_SHADER_IMAGE_LOAD
:
198 case GL_SHADER_IMAGE_STORE
:
199 case GL_SHADER_IMAGE_ATOMIC
:
200 case GL_IMAGE_TEXEL_SIZE
:
201 case GL_IMAGE_COMPATIBILITY_CLASS
:
202 case GL_IMAGE_PIXEL_FORMAT
:
203 case GL_IMAGE_PIXEL_TYPE
:
204 case GL_IMAGE_FORMAT_COMPATIBILITY_TYPE
:
205 case GL_SIMULTANEOUS_TEXTURE_AND_DEPTH_TEST
:
206 case GL_SIMULTANEOUS_TEXTURE_AND_STENCIL_TEST
:
207 case GL_SIMULTANEOUS_TEXTURE_AND_DEPTH_WRITE
:
208 case GL_SIMULTANEOUS_TEXTURE_AND_STENCIL_WRITE
:
209 case GL_TEXTURE_COMPRESSED
:
210 case GL_TEXTURE_COMPRESSED_BLOCK_WIDTH
:
211 case GL_TEXTURE_COMPRESSED_BLOCK_HEIGHT
:
212 case GL_TEXTURE_COMPRESSED_BLOCK_SIZE
:
213 case GL_CLEAR_BUFFER
:
214 case GL_TEXTURE_VIEW
:
215 case GL_VIEW_COMPATIBILITY_CLASS
:
216 /* The ARB_internalformat_query spec says:
218 * "If the <pname> parameter to GetInternalformativ is not SAMPLES
219 * or NUM_SAMPLE_COUNTS, then an INVALID_ENUM error is generated."
222 _mesa_error(ctx
, GL_INVALID_ENUM
,
223 "glGetInternalformativ(pname=%s)",
224 _mesa_enum_to_string(pname
));
231 _mesa_error(ctx
, GL_INVALID_ENUM
,
232 "glGetInternalformativ(pname=%s)",
233 _mesa_enum_to_string(pname
));
237 /* The ARB_internalformat_query spec says:
239 * "If the <bufSize> parameter to GetInternalformativ is negative, then
240 * an INVALID_VALUE error is generated."
242 * Nothing is said in ARB_internalformat_query2 but we assume the same.
245 _mesa_error(ctx
, GL_INVALID_VALUE
,
246 "glGetInternalformativ(target=%s)",
247 _mesa_enum_to_string(target
));
251 /* The ARB_internalformat_query spec says:
253 * "If the <internalformat> parameter to GetInternalformativ is not
254 * color-, depth- or stencil-renderable, then an INVALID_ENUM error is
257 if (!query2
&& !_is_renderable(ctx
, internalformat
)) {
258 _mesa_error(ctx
, GL_INVALID_ENUM
,
259 "glGetInternalformativ(internalformat=%s)",
260 _mesa_enum_to_string(internalformat
));
267 /* Sets the appropriate "unsupported" response as defined by the
268 * ARB_internalformat_query2 spec for each each <pname>.
271 _set_default_response(GLenum pname
, GLint buffer
[16])
273 /* The ARB_internalformat_query2 defines which is the reponse best
274 * representing "not supported" or "not applicable" for each <pname>.
277 * - size- or count-based queries will return zero,
278 * - support-, format- or type-based queries will return NONE,
279 * - boolean-based queries will return FALSE, and
280 * - list-based queries return no entries."
286 case GL_MAX_COMBINED_DIMENSIONS
:
287 /* This value can be a 64-bit value. As the default is the 32-bit query,
288 * we pack 2 32-bit integers. So we need to clean both */
293 case GL_NUM_SAMPLE_COUNTS
:
294 case GL_INTERNALFORMAT_RED_SIZE
:
295 case GL_INTERNALFORMAT_GREEN_SIZE
:
296 case GL_INTERNALFORMAT_BLUE_SIZE
:
297 case GL_INTERNALFORMAT_ALPHA_SIZE
:
298 case GL_INTERNALFORMAT_DEPTH_SIZE
:
299 case GL_INTERNALFORMAT_STENCIL_SIZE
:
300 case GL_INTERNALFORMAT_SHARED_SIZE
:
305 case GL_IMAGE_TEXEL_SIZE
:
306 case GL_TEXTURE_COMPRESSED_BLOCK_WIDTH
:
307 case GL_TEXTURE_COMPRESSED_BLOCK_HEIGHT
:
308 case GL_TEXTURE_COMPRESSED_BLOCK_SIZE
:
312 case GL_INTERNALFORMAT_PREFERRED
:
313 case GL_INTERNALFORMAT_RED_TYPE
:
314 case GL_INTERNALFORMAT_GREEN_TYPE
:
315 case GL_INTERNALFORMAT_BLUE_TYPE
:
316 case GL_INTERNALFORMAT_ALPHA_TYPE
:
317 case GL_INTERNALFORMAT_DEPTH_TYPE
:
318 case GL_INTERNALFORMAT_STENCIL_TYPE
:
319 case GL_FRAMEBUFFER_RENDERABLE
:
320 case GL_FRAMEBUFFER_RENDERABLE_LAYERED
:
321 case GL_FRAMEBUFFER_BLEND
:
323 case GL_READ_PIXELS_FORMAT
:
324 case GL_READ_PIXELS_TYPE
:
325 case GL_TEXTURE_IMAGE_FORMAT
:
326 case GL_TEXTURE_IMAGE_TYPE
:
327 case GL_GET_TEXTURE_IMAGE_FORMAT
:
328 case GL_GET_TEXTURE_IMAGE_TYPE
:
329 case GL_MANUAL_GENERATE_MIPMAP
:
330 case GL_AUTO_GENERATE_MIPMAP
:
331 case GL_COLOR_ENCODING
:
334 case GL_SRGB_DECODE_ARB
:
336 case GL_VERTEX_TEXTURE
:
337 case GL_TESS_CONTROL_TEXTURE
:
338 case GL_TESS_EVALUATION_TEXTURE
:
339 case GL_GEOMETRY_TEXTURE
:
340 case GL_FRAGMENT_TEXTURE
:
341 case GL_COMPUTE_TEXTURE
:
342 case GL_TEXTURE_SHADOW
:
343 case GL_TEXTURE_GATHER
:
344 case GL_TEXTURE_GATHER_SHADOW
:
345 case GL_SHADER_IMAGE_LOAD
:
346 case GL_SHADER_IMAGE_STORE
:
347 case GL_SHADER_IMAGE_ATOMIC
:
348 case GL_IMAGE_COMPATIBILITY_CLASS
:
349 case GL_IMAGE_PIXEL_FORMAT
:
350 case GL_IMAGE_PIXEL_TYPE
:
351 case GL_IMAGE_FORMAT_COMPATIBILITY_TYPE
:
352 case GL_SIMULTANEOUS_TEXTURE_AND_DEPTH_TEST
:
353 case GL_SIMULTANEOUS_TEXTURE_AND_STENCIL_TEST
:
354 case GL_SIMULTANEOUS_TEXTURE_AND_DEPTH_WRITE
:
355 case GL_SIMULTANEOUS_TEXTURE_AND_STENCIL_WRITE
:
356 case GL_CLEAR_BUFFER
:
357 case GL_TEXTURE_VIEW
:
358 case GL_VIEW_COMPATIBILITY_CLASS
:
362 case GL_INTERNALFORMAT_SUPPORTED
:
363 case GL_COLOR_COMPONENTS
:
364 case GL_DEPTH_COMPONENTS
:
365 case GL_STENCIL_COMPONENTS
:
366 case GL_COLOR_RENDERABLE
:
367 case GL_DEPTH_RENDERABLE
:
368 case GL_STENCIL_RENDERABLE
:
370 case GL_TEXTURE_COMPRESSED
:
371 buffer
[0] = GL_FALSE
;
375 unreachable("invalid 'pname'");
380 _is_target_supported(struct gl_context
*ctx
, GLenum target
)
382 /* The ARB_internalformat_query2 spec says:
384 * "if a particular type of <target> is not supported by the
385 * implementation the "unsupported" answer should be given.
386 * This is not an error."
394 if (!_mesa_is_desktop_gl(ctx
))
398 case GL_TEXTURE_1D_ARRAY
:
399 if (!_mesa_has_EXT_texture_array(ctx
))
403 case GL_TEXTURE_2D_ARRAY
:
404 if (!(_mesa_has_EXT_texture_array(ctx
) || _mesa_is_gles3(ctx
)))
408 case GL_TEXTURE_CUBE_MAP
:
409 if (!_mesa_has_ARB_texture_cube_map(ctx
))
413 case GL_TEXTURE_CUBE_MAP_ARRAY
:
414 if (!_mesa_has_ARB_texture_cube_map_array(ctx
))
418 case GL_TEXTURE_RECTANGLE
:
419 if (!_mesa_has_NV_texture_rectangle(ctx
))
423 case GL_TEXTURE_BUFFER
:
424 if (!_mesa_has_ARB_texture_buffer_object(ctx
))
428 case GL_RENDERBUFFER
:
429 if (!(_mesa_has_ARB_framebuffer_object(ctx
) ||
430 _mesa_is_gles3(ctx
)))
434 case GL_TEXTURE_2D_MULTISAMPLE
:
435 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
436 if (!(_mesa_has_ARB_texture_multisample(ctx
) ||
437 _mesa_is_gles31(ctx
)))
442 unreachable("invalid target");
449 _is_resource_supported(struct gl_context
*ctx
, GLenum target
,
450 GLenum internalformat
, GLenum pname
)
452 /* From the ARB_internalformat_query2 spec:
454 * In the following descriptions, the term /resource/ is used to generically
455 * refer to an object of the appropriate type that has been created with
456 * <internalformat> and <target>. If the particular <target> and
457 * <internalformat> combination do not make sense, ... the "unsupported"
458 * answer should be given. This is not an error.
461 /* In the ARB_internalformat_query2 spec wording, some <pnames> do not care
462 * about the /resource/ being supported or not, we return 'true' for those.
465 case GL_INTERNALFORMAT_SUPPORTED
:
466 case GL_INTERNALFORMAT_PREFERRED
:
467 case GL_COLOR_COMPONENTS
:
468 case GL_DEPTH_COMPONENTS
:
469 case GL_STENCIL_COMPONENTS
:
470 case GL_COLOR_RENDERABLE
:
471 case GL_DEPTH_RENDERABLE
:
472 case GL_STENCIL_RENDERABLE
:
480 case GL_TEXTURE_1D_ARRAY
:
482 case GL_TEXTURE_2D_ARRAY
:
484 case GL_TEXTURE_CUBE_MAP
:
485 case GL_TEXTURE_CUBE_MAP_ARRAY
:
486 case GL_TEXTURE_RECTANGLE
:
487 /* Based on what Mesa does for glTexImage1D/2D/3D and
488 * glCompressedTexImage1D/2D/3D functions.
490 if (_mesa_base_tex_format(ctx
, internalformat
) < 0)
493 /* additional checks for depth textures */
494 if (!_mesa_legal_texture_base_format_for_target(ctx
, target
, internalformat
))
497 /* additional checks for compressed textures */
498 if (_mesa_is_compressed_format(ctx
, internalformat
) &&
499 (!_mesa_target_can_be_compressed(ctx
, target
, internalformat
, NULL
) ||
500 _mesa_format_no_online_compression(ctx
, internalformat
)))
504 case GL_TEXTURE_2D_MULTISAMPLE
:
505 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
506 /* Based on what Mesa does for glTexImage2D/3DMultisample,
507 * glTexStorage2D/3DMultisample and
508 * glTextureStorage2D/3DMultisample functions.
510 if (!_mesa_is_renderable_texture_format(ctx
, internalformat
))
514 case GL_TEXTURE_BUFFER
:
515 /* Based on what Mesa does for the glTexBuffer function. */
516 if (_mesa_validate_texbuffer_format(ctx
, internalformat
) ==
521 case GL_RENDERBUFFER
:
522 /* Based on what Mesa does for glRenderbufferStorage(Multisample) and
523 * glNamedRenderbufferStorage functions.
525 if (!_mesa_base_fbo_format(ctx
, internalformat
))
530 unreachable("bad target");
537 _is_internalformat_supported(struct gl_context
*ctx
, GLenum target
,
538 GLenum internalformat
)
540 /* From the ARB_internalformat_query2 specification:
542 * "- INTERNALFORMAT_SUPPORTED: If <internalformat> is an internal format
543 * that is supported by the implementation in at least some subset of
544 * possible operations, TRUE is written to <params>. If <internalformat>
545 * if not a valid token for any internal format usage, FALSE is returned.
547 * <internalformats> that must be supported (in GL 4.2 or later) include
549 * - "sized internal formats" from Table 3.12, 3.13, and 3.15,
550 * - any specific "compressed internal format" from Table 3.14,
551 * - any "image unit format" from Table 3.21.
552 * - any generic "compressed internal format" from Table 3.14, if the
553 * implementation accepts it for any texture specification commands, and
554 * - unsized or base internal format, if the implementation accepts
555 * it for texture or image specification.
559 /* At this point a internalformat is valid if it is valid as a texture or
560 * as a renderbuffer format. The checks are different because those methods
561 * return different values when passing non supported internalformats */
562 if (_mesa_base_tex_format(ctx
, internalformat
) < 0 &&
563 _mesa_base_fbo_format(ctx
, internalformat
) == 0)
566 /* Let the driver have the final word */
567 ctx
->Driver
.QueryInternalFormat(ctx
, target
, internalformat
,
568 GL_INTERNALFORMAT_SUPPORTED
, buffer
);
570 return (buffer
[0] == GL_TRUE
);
573 /* default implementation of QueryInternalFormat driverfunc, for
574 * drivers not implementing ARB_internalformat_query2.
577 _mesa_query_internal_format_default(struct gl_context
*ctx
, GLenum target
,
578 GLenum internalFormat
, GLenum pname
,
583 (void) internalFormat
;
587 case GL_NUM_SAMPLE_COUNTS
:
591 case GL_INTERNALFORMAT_SUPPORTED
:
595 case GL_INTERNALFORMAT_PREFERRED
:
596 params
[0] = internalFormat
;
599 case GL_MANUAL_GENERATE_MIPMAP
:
600 case GL_AUTO_GENERATE_MIPMAP
:
601 params
[0] = GL_FULL_SUPPORT
;
605 _set_default_response(pname
, params
);
611 * For MAX_WIDTH/MAX_HEIGHT/MAX_DEPTH it returns the equivalent GetInteger
612 * pname for a Getinternalformat pname/target combination. target/pname
613 * combinations that would return 0 due dimension number or unsupported status
614 * should be already filtered out
616 * Note that this means that the returned value would be independent of the
617 * internalformat. This possibility is already mentioned at the Issue 7 of the
618 * arb_internalformat_query2 spec.
621 equivalentSizePname(GLenum target
,
627 case GL_TEXTURE_2D_MULTISAMPLE
:
628 return GL_MAX_TEXTURE_SIZE
;
630 return GL_MAX_3D_TEXTURE_SIZE
;
631 case GL_TEXTURE_CUBE_MAP
:
632 return GL_MAX_CUBE_MAP_TEXTURE_SIZE
;
633 case GL_TEXTURE_RECTANGLE
:
634 return GL_MAX_RECTANGLE_TEXTURE_SIZE
;
635 case GL_RENDERBUFFER
:
636 return GL_MAX_RENDERBUFFER_SIZE
;
637 case GL_TEXTURE_1D_ARRAY
:
638 if (pname
== GL_MAX_HEIGHT
)
639 return GL_MAX_ARRAY_TEXTURE_LAYERS
;
641 return GL_MAX_TEXTURE_SIZE
;
642 case GL_TEXTURE_2D_ARRAY
:
643 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
644 if (pname
== GL_MAX_DEPTH
)
645 return GL_MAX_ARRAY_TEXTURE_LAYERS
;
647 return GL_MAX_TEXTURE_SIZE
;
648 case GL_TEXTURE_CUBE_MAP_ARRAY
:
649 if (pname
== GL_MAX_DEPTH
)
650 return GL_MAX_ARRAY_TEXTURE_LAYERS
;
652 return GL_MAX_CUBE_MAP_TEXTURE_SIZE
;
653 case GL_TEXTURE_BUFFER
:
654 return GL_MAX_TEXTURE_BUFFER_SIZE
;
661 * Returns the dimensions associated to a target. GL_TEXTURE_BUFFER and
662 * GL_RENDERBUFFER have associated a dimension, but they are not textures
663 * per-se, so we can't just call _mesa_get_texture_dimension directly.
666 get_target_dimensions(GLenum target
)
669 case GL_TEXTURE_BUFFER
:
671 case GL_RENDERBUFFER
:
674 return _mesa_get_texture_dimensions(target
);
679 * Returns the minimum amount of dimensions associated to a pname. So for
680 * example, if querying GL_MAX_HEIGHT, it is assumed that your target would
681 * have as minimum 2 dimensions.
683 * Useful to handle sentences like this from query2 spec:
687 * If the resource does not have at least two dimensions
691 get_min_dimensions(GLenum pname
)
706 * Similar to teximage.c:check_multisample_target, but independent of the
710 is_multisample_target(GLenum target
)
713 case GL_TEXTURE_2D_MULTISAMPLE
:
714 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
723 _mesa_GetInternalformativ(GLenum target
, GLenum internalformat
, GLenum pname
,
724 GLsizei bufSize
, GLint
*params
)
727 GET_CURRENT_CONTEXT(ctx
);
729 ASSERT_OUTSIDE_BEGIN_END(ctx
);
731 /* ARB_internalformat_query is also mandatory for ARB_internalformat_query2 */
732 if (!(_mesa_has_ARB_internalformat_query(ctx
) ||
733 _mesa_is_gles3(ctx
))) {
734 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetInternalformativ");
738 assert(ctx
->Driver
.QueryInternalFormat
!= NULL
);
740 if (!_legal_parameters(ctx
, target
, internalformat
, pname
, bufSize
, params
))
743 /* initialize the contents of the temporary buffer */
744 memcpy(buffer
, params
, MIN2(bufSize
, 16) * sizeof(GLint
));
746 /* Use the 'unsupported' response defined by the spec for every pname
747 * as the default answer.
749 _set_default_response(pname
, buffer
);
751 if (!_is_target_supported(ctx
, target
) ||
752 !_is_internalformat_supported(ctx
, target
, internalformat
) ||
753 !_is_resource_supported(ctx
, target
, internalformat
, pname
))
759 case GL_NUM_SAMPLE_COUNTS
:
760 /* The ARB_internalformat_query2 sets the response as 'unsupported' for
761 * SAMPLES and NUM_SAMPLE_COUNTS:
763 * "If <internalformat> is not color-renderable, depth-renderable, or
764 * stencil-renderable (as defined in section 4.4.4), or if <target>
765 * does not support multiple samples (ie other than
766 * TEXTURE_2D_MULTISAMPLE, TEXTURE_2D_MULTISAMPLE_ARRAY,
769 if ((target
!= GL_RENDERBUFFER
&&
770 target
!= GL_TEXTURE_2D_MULTISAMPLE
&&
771 target
!= GL_TEXTURE_2D_MULTISAMPLE_ARRAY
) ||
772 !_is_renderable(ctx
, internalformat
))
775 /* The GL ES 3.0 specification, section 6.1.15 page 236 says:
777 * "Since multisampling is not supported for signed and unsigned
778 * integer internal formats, the value of NUM_SAMPLE_COUNTS will be
779 * zero for such formats.
781 if (pname
== GL_NUM_SAMPLE_COUNTS
&& ctx
->API
== API_OPENGLES2
&&
782 ctx
->Version
== 30 && _mesa_is_enum_format_integer(internalformat
)) {
786 ctx
->Driver
.QueryInternalFormat(ctx
, target
, internalformat
, pname
,
790 case GL_INTERNALFORMAT_SUPPORTED
:
791 /* Having a supported <internalformat> is implemented as a prerequisite
792 * for all the <pnames>. Thus, if we reach this point, the internalformat is
798 case GL_INTERNALFORMAT_PREFERRED
:
799 /* The ARB_internalformat_query2 spec says:
801 * "- INTERNALFORMAT_PREFERRED: The implementation-preferred internal
802 * format for representing resources of the specified <internalformat> is
803 * returned in <params>.
805 * Therefore, we let the driver answer.
807 ctx
->Driver
.QueryInternalFormat(ctx
, target
, internalformat
, pname
,
811 case GL_INTERNALFORMAT_RED_SIZE
:
812 case GL_INTERNALFORMAT_GREEN_SIZE
:
813 case GL_INTERNALFORMAT_BLUE_SIZE
:
814 case GL_INTERNALFORMAT_ALPHA_SIZE
:
815 case GL_INTERNALFORMAT_DEPTH_SIZE
:
816 case GL_INTERNALFORMAT_STENCIL_SIZE
:
817 case GL_INTERNALFORMAT_SHARED_SIZE
:
818 case GL_INTERNALFORMAT_RED_TYPE
:
819 case GL_INTERNALFORMAT_GREEN_TYPE
:
820 case GL_INTERNALFORMAT_BLUE_TYPE
:
821 case GL_INTERNALFORMAT_ALPHA_TYPE
:
822 case GL_INTERNALFORMAT_DEPTH_TYPE
:
823 case GL_INTERNALFORMAT_STENCIL_TYPE
: {
825 mesa_format texformat
;
827 if (target
!= GL_RENDERBUFFER
) {
828 if (!_mesa_legal_get_tex_level_parameter_target(ctx
, target
, true))
831 baseformat
= _mesa_base_tex_format(ctx
, internalformat
);
833 baseformat
= _mesa_base_fbo_format(ctx
, internalformat
);
836 /* Let the driver choose the texture format.
838 * Disclaimer: I am considering that drivers use for renderbuffers the
839 * same format-choice logic as for textures.
841 texformat
= ctx
->Driver
.ChooseTextureFormat(ctx
, target
, internalformat
,
842 GL_NONE
/*format */, GL_NONE
/* type */);
844 if (texformat
== MESA_FORMAT_NONE
|| baseformat
<= 0)
847 /* Implementation based on what Mesa does for glGetTexLevelParameteriv
848 * and glGetRenderbufferParameteriv functions.
850 if (pname
== GL_INTERNALFORMAT_SHARED_SIZE
) {
851 if (_mesa_has_EXT_texture_shared_exponent(ctx
) &&
852 target
!= GL_TEXTURE_BUFFER
&&
853 target
!= GL_RENDERBUFFER
&&
854 texformat
== MESA_FORMAT_R9G9B9E5_FLOAT
) {
860 if (!_mesa_base_format_has_channel(baseformat
, pname
))
864 case GL_INTERNALFORMAT_DEPTH_SIZE
:
865 if (!_mesa_has_ARB_depth_texture(ctx
) &&
866 target
!= GL_RENDERBUFFER
&&
867 target
!= GL_TEXTURE_BUFFER
)
870 case GL_INTERNALFORMAT_RED_SIZE
:
871 case GL_INTERNALFORMAT_GREEN_SIZE
:
872 case GL_INTERNALFORMAT_BLUE_SIZE
:
873 case GL_INTERNALFORMAT_ALPHA_SIZE
:
874 case GL_INTERNALFORMAT_STENCIL_SIZE
:
875 buffer
[0] = _mesa_get_format_bits(texformat
, pname
);
878 case GL_INTERNALFORMAT_DEPTH_TYPE
:
879 if (!_mesa_has_ARB_texture_float(ctx
))
882 case GL_INTERNALFORMAT_RED_TYPE
:
883 case GL_INTERNALFORMAT_GREEN_TYPE
:
884 case GL_INTERNALFORMAT_BLUE_TYPE
:
885 case GL_INTERNALFORMAT_ALPHA_TYPE
:
886 case GL_INTERNALFORMAT_STENCIL_TYPE
:
887 buffer
[0] = _mesa_get_format_datatype(texformat
);
897 /* For WIDTH/HEIGHT/DEPTH/LAYERS there is no reason to think that the
898 * returned values should be different to the values returned by
899 * GetInteger with MAX_TEXTURE_SIZE, MAX_3D_TEXTURE_SIZE, etc.*/
905 GLint min_dimensions
;
907 /* From query2:MAX_HEIGHT spec (as example):
909 * "If the resource does not have at least two dimensions, or if the
910 * resource is unsupported, zero is returned."
912 dimensions
= get_target_dimensions(target
);
913 min_dimensions
= get_min_dimensions(pname
);
914 if (dimensions
< min_dimensions
)
917 get_pname
= equivalentSizePname(target
, pname
);
921 _mesa_GetIntegerv(get_pname
, buffer
);
926 if (!_mesa_has_EXT_texture_array(ctx
))
929 if (!_mesa_is_array_texture(target
))
932 _mesa_GetIntegerv(GL_MAX_ARRAY_TEXTURE_LAYERS
, buffer
);
935 case GL_MAX_COMBINED_DIMENSIONS
:{
936 GLint64 combined_value
= 1;
937 GLenum max_dimensions_pnames
[] = {
946 /* Combining the dimensions. Note that for array targets, this would
947 * automatically include the value of MAX_LAYERS, as that value is
948 * returned as MAX_HEIGHT or MAX_DEPTH */
949 for (i
= 0; i
< 4; i
++) {
950 if (max_dimensions_pnames
[i
] == GL_SAMPLES
&&
951 !is_multisample_target(target
))
954 _mesa_GetInternalformativ(target
, internalformat
,
955 max_dimensions_pnames
[i
],
958 if (current_value
!= 0)
959 combined_value
*= current_value
;
962 if (_mesa_is_cube_map_texture(target
))
965 /* We pack the 64-bit value on two 32-bit values. Calling the 32-bit
966 * query, this would work as far as the value can be hold on a 32-bit
967 * signed integer. For the 64-bit query, the wrapper around the 32-bit
968 * query will unpack the value */
969 memcpy(buffer
, &combined_value
, sizeof(GLint64
));
973 case GL_COLOR_COMPONENTS
:
974 /* The ARB_internalformat_query2 spec says:
976 * "- COLOR_COMPONENTS: If the internal format contains any color
977 * components (R, G, B, or A), TRUE is returned in <params>.
978 * If the internal format is unsupported or contains no color
979 * components, FALSE is returned."
981 if (_mesa_is_color_format(internalformat
))
985 case GL_DEPTH_COMPONENTS
:
986 /* The ARB_internalformat_query2 spec says:
988 * "- DEPTH_COMPONENTS: If the internal format contains a depth
989 * component (D), TRUE is returned in <params>. If the internal format
990 * is unsupported or contains no depth component, FALSE is returned."
992 if (_mesa_is_depth_format(internalformat
) ||
993 _mesa_is_depthstencil_format(internalformat
))
997 case GL_STENCIL_COMPONENTS
:
998 /* The ARB_internalformat_query2 spec says:
1000 * "- STENCIL_COMPONENTS: If the internal format contains a stencil
1001 * component (S), TRUE is returned in <params>. If the internal format
1002 * is unsupported or contains no stencil component, FALSE is returned.
1004 if (_mesa_is_stencil_format(internalformat
) ||
1005 _mesa_is_depthstencil_format(internalformat
))
1006 buffer
[0] = GL_TRUE
;
1009 case GL_COLOR_RENDERABLE
:
1010 case GL_DEPTH_RENDERABLE
:
1011 case GL_STENCIL_RENDERABLE
:
1012 if (!_is_renderable(ctx
, internalformat
))
1015 if (pname
== GL_COLOR_RENDERABLE
) {
1016 if (!_mesa_is_color_format(internalformat
))
1019 GLenum baseFormat
= _mesa_base_fbo_format(ctx
, internalformat
);
1020 if (baseFormat
!= GL_DEPTH_STENCIL
&&
1021 ((pname
== GL_DEPTH_RENDERABLE
&& baseFormat
!= GL_DEPTH_COMPONENT
) ||
1022 (pname
== GL_STENCIL_RENDERABLE
&& baseFormat
!= GL_STENCIL_INDEX
)))
1026 buffer
[0] = GL_TRUE
;
1029 case GL_FRAMEBUFFER_RENDERABLE
:
1033 case GL_FRAMEBUFFER_RENDERABLE_LAYERED
:
1037 case GL_FRAMEBUFFER_BLEND
:
1041 case GL_READ_PIXELS
:
1045 case GL_READ_PIXELS_FORMAT
:
1049 case GL_READ_PIXELS_TYPE
:
1053 case GL_TEXTURE_IMAGE_FORMAT
:
1057 case GL_TEXTURE_IMAGE_TYPE
:
1061 case GL_GET_TEXTURE_IMAGE_FORMAT
:
1065 case GL_GET_TEXTURE_IMAGE_TYPE
:
1070 case GL_MANUAL_GENERATE_MIPMAP
:
1071 case GL_AUTO_GENERATE_MIPMAP
:
1072 if (!_mesa_is_valid_generate_texture_mipmap_target(ctx
, target
) ||
1073 !_mesa_is_valid_generate_texture_mipmap_internalformat(ctx
,
1078 if (pname
== GL_MIPMAP
) {
1079 buffer
[0] = GL_TRUE
;
1082 else if (pname
== GL_MANUAL_GENERATE_MIPMAP
) {
1083 if (!_mesa_has_ARB_framebuffer_object(ctx
))
1087 /* From ARB_internalformat_query2:
1088 * "Dependencies on OpenGL 3.2 (Core Profile)
1089 * In core profiles for OpenGL 3.2 and later versions, queries
1090 * for the AUTO_GENERATE_MIPMAP <pname> return the appropriate
1091 * unsupported response."
1093 if (_mesa_is_desktop_gl(ctx
) && ctx
->Version
>= 32)
1097 ctx
->Driver
.QueryInternalFormat(ctx
, target
, internalformat
, pname
,
1101 case GL_COLOR_ENCODING
:
1102 if (!_mesa_is_color_format(internalformat
))
1105 if (_mesa_is_srgb_format(internalformat
))
1106 buffer
[0] = GL_SRGB
;
1108 buffer
[0] = GL_LINEAR
;
1119 case GL_SRGB_DECODE_ARB
:
1127 case GL_VERTEX_TEXTURE
:
1131 case GL_TESS_CONTROL_TEXTURE
:
1135 case GL_TESS_EVALUATION_TEXTURE
:
1139 case GL_GEOMETRY_TEXTURE
:
1143 case GL_FRAGMENT_TEXTURE
:
1147 case GL_COMPUTE_TEXTURE
:
1151 case GL_TEXTURE_SHADOW
:
1155 case GL_TEXTURE_GATHER
:
1159 case GL_TEXTURE_GATHER_SHADOW
:
1163 case GL_SHADER_IMAGE_LOAD
:
1167 case GL_SHADER_IMAGE_STORE
:
1171 case GL_SHADER_IMAGE_ATOMIC
:
1175 case GL_IMAGE_TEXEL_SIZE
:
1179 case GL_IMAGE_COMPATIBILITY_CLASS
:
1183 case GL_IMAGE_PIXEL_FORMAT
:
1187 case GL_IMAGE_PIXEL_TYPE
:
1191 case GL_IMAGE_FORMAT_COMPATIBILITY_TYPE
: {
1192 if (!_mesa_has_ARB_shader_image_load_store(ctx
))
1195 if (!_mesa_legal_get_tex_level_parameter_target(ctx
, target
, true))
1198 /* From spec: "Equivalent to calling GetTexParameter with <value> set
1199 * to IMAGE_FORMAT_COMPATIBILITY_TYPE."
1201 * GetTexParameter just returns
1202 * tex_obj->ImageFormatCompatibilityType. We create a fake tex_obj
1203 * just with the purpose of getting the value.
1205 struct gl_texture_object
*tex_obj
= _mesa_new_texture_object(ctx
, 0, target
);
1206 buffer
[0] = tex_obj
->ImageFormatCompatibilityType
;
1207 _mesa_delete_texture_object(ctx
, tex_obj
);
1212 case GL_SIMULTANEOUS_TEXTURE_AND_DEPTH_TEST
:
1216 case GL_SIMULTANEOUS_TEXTURE_AND_STENCIL_TEST
:
1220 case GL_SIMULTANEOUS_TEXTURE_AND_DEPTH_WRITE
:
1224 case GL_SIMULTANEOUS_TEXTURE_AND_STENCIL_WRITE
:
1228 case GL_TEXTURE_COMPRESSED
:
1232 case GL_TEXTURE_COMPRESSED_BLOCK_WIDTH
:
1236 case GL_TEXTURE_COMPRESSED_BLOCK_HEIGHT
:
1240 case GL_TEXTURE_COMPRESSED_BLOCK_SIZE
:
1244 case GL_CLEAR_BUFFER
:
1248 case GL_TEXTURE_VIEW
:
1252 case GL_VIEW_COMPATIBILITY_CLASS
:
1257 unreachable("bad param");
1261 if (bufSize
!= 0 && params
== NULL
) {
1262 /* Emit a warning to aid application debugging, but go ahead and do the
1263 * memcpy (and probably crash) anyway.
1266 "glGetInternalformativ(bufSize = %d, but params = NULL)",
1270 /* Copy the data from the temporary buffer to the buffer supplied by the
1271 * application. Clamp the size of the copy to the size supplied by the
1274 memcpy(params
, buffer
, MIN2(bufSize
, 16) * sizeof(GLint
));
1280 _mesa_GetInternalformati64v(GLenum target
, GLenum internalformat
,
1281 GLenum pname
, GLsizei bufSize
, GLint64
*params
)
1285 GLsizei realSize
= MIN2(bufSize
, 16);
1288 GET_CURRENT_CONTEXT(ctx
);
1290 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1292 if (!_mesa_has_ARB_internalformat_query2(ctx
)) {
1293 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetInternalformati64v");
1297 /* For SAMPLES there are cases where params needs to remain unmodified. As
1298 * no pname can return a negative value, we fill params32 with negative
1299 * values as reference values, that can be used to know what copy-back to
1301 memset(params32
, -1, 16);
1303 /* For GL_MAX_COMBINED_DIMENSIONS we need to get back 2 32-bit integers,
1304 * and at the same time we only need 2. So for that pname, we call the
1305 * 32-bit query with bufSize 2, except on the case of bufSize 0, that is
1306 * basically like asking to not get the value, but that is a caller
1308 if (pname
== GL_MAX_COMBINED_DIMENSIONS
&& bufSize
> 0)
1313 _mesa_GetInternalformativ(target
, internalformat
, pname
, callSize
, params32
);
1315 if (pname
== GL_MAX_COMBINED_DIMENSIONS
) {
1316 memcpy(params
, params32
, sizeof(GLint64
));
1318 for (i
= 0; i
< realSize
; i
++) {
1319 /* We only copy back the values that changed */
1320 if (params32
[i
] < 0)
1322 params
[i
] = (GLint64
) params32
[i
];