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"
39 _is_renderable(struct gl_context
*ctx
, GLenum internalformat
)
41 /* Section 4.4.4 on page 212 of the GLES 3.0.4 spec says:
43 * "An internal format is color-renderable if it is one of the
44 * formats from table 3.13 noted as color-renderable or if it
45 * is unsized format RGBA or RGB."
47 * Therefore, we must accept GL_RGB and GL_RGBA here.
49 if (internalformat
!= GL_RGB
&& internalformat
!= GL_RGBA
&&
50 _mesa_base_fbo_format(ctx
, internalformat
) == 0)
56 /* Handles the cases where either ARB_internalformat_query or
57 * ARB_internalformat_query2 have to return an error.
60 _legal_parameters(struct gl_context
*ctx
, GLenum target
, GLenum internalformat
,
61 GLenum pname
, GLsizei bufSize
, GLint
*params
)
64 bool query2
= _mesa_has_ARB_internalformat_query2(ctx
);
66 /* The ARB_internalformat_query2 spec says:
68 * "The INVALID_ENUM error is generated if the <target> parameter to
69 * GetInternalformati*v is not one of the targets listed in Table 6.xx.
73 case GL_TEXTURE_1D_ARRAY
:
75 case GL_TEXTURE_2D_ARRAY
:
77 case GL_TEXTURE_CUBE_MAP
:
78 case GL_TEXTURE_CUBE_MAP_ARRAY
:
79 case GL_TEXTURE_RECTANGLE
:
80 case GL_TEXTURE_BUFFER
:
82 /* The ARB_internalformat_query spec says:
84 * "If the <target> parameter to GetInternalformativ is not one of
85 * TEXTURE_2D_MULTISAMPLE, TEXTURE_2D_MULTISAMPLE_ARRAY
86 * or RENDERBUFFER then an INVALID_ENUM error is generated.
88 _mesa_error(ctx
, GL_INVALID_ENUM
,
89 "glGetInternalformativ(target=%s)",
90 _mesa_enum_to_string(target
));
99 case GL_TEXTURE_2D_MULTISAMPLE
:
100 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
101 /* The non-existence of ARB_texture_multisample is treated in
102 * ARB_internalformat_query implementation like an error.
105 !(_mesa_has_ARB_texture_multisample(ctx
) || _mesa_is_gles31(ctx
))) {
106 _mesa_error(ctx
, GL_INVALID_ENUM
,
107 "glGetInternalformativ(target=%s)",
108 _mesa_enum_to_string(target
));
115 _mesa_error(ctx
, GL_INVALID_ENUM
,
116 "glGetInternalformativ(target=%s)",
117 _mesa_enum_to_string(target
));
122 /* The ARB_internalformat_query2 spec says:
124 * "The INVALID_ENUM error is generated if the <pname> parameter is
125 * not one of the listed possibilities.
129 case GL_NUM_SAMPLE_COUNTS
:
132 case GL_SRGB_DECODE_ARB
:
133 /* The ARB_internalformat_query2 spec says:
135 * "If ARB_texture_sRGB_decode or EXT_texture_sRGB_decode or
136 * equivalent functionality is not supported, queries for the
137 * SRGB_DECODE_ARB <pname> set the INVALID_ENUM error.
139 if (!_mesa_has_EXT_texture_sRGB_decode(ctx
)) {
140 _mesa_error(ctx
, GL_INVALID_ENUM
,
141 "glGetInternalformativ(pname=%s)",
142 _mesa_enum_to_string(pname
));
146 case GL_INTERNALFORMAT_SUPPORTED
:
147 case GL_INTERNALFORMAT_PREFERRED
:
148 case GL_INTERNALFORMAT_RED_SIZE
:
149 case GL_INTERNALFORMAT_GREEN_SIZE
:
150 case GL_INTERNALFORMAT_BLUE_SIZE
:
151 case GL_INTERNALFORMAT_ALPHA_SIZE
:
152 case GL_INTERNALFORMAT_DEPTH_SIZE
:
153 case GL_INTERNALFORMAT_STENCIL_SIZE
:
154 case GL_INTERNALFORMAT_SHARED_SIZE
:
155 case GL_INTERNALFORMAT_RED_TYPE
:
156 case GL_INTERNALFORMAT_GREEN_TYPE
:
157 case GL_INTERNALFORMAT_BLUE_TYPE
:
158 case GL_INTERNALFORMAT_ALPHA_TYPE
:
159 case GL_INTERNALFORMAT_DEPTH_TYPE
:
160 case GL_INTERNALFORMAT_STENCIL_TYPE
:
165 case GL_MAX_COMBINED_DIMENSIONS
:
166 case GL_COLOR_COMPONENTS
:
167 case GL_DEPTH_COMPONENTS
:
168 case GL_STENCIL_COMPONENTS
:
169 case GL_COLOR_RENDERABLE
:
170 case GL_DEPTH_RENDERABLE
:
171 case GL_STENCIL_RENDERABLE
:
172 case GL_FRAMEBUFFER_RENDERABLE
:
173 case GL_FRAMEBUFFER_RENDERABLE_LAYERED
:
174 case GL_FRAMEBUFFER_BLEND
:
176 case GL_READ_PIXELS_FORMAT
:
177 case GL_READ_PIXELS_TYPE
:
178 case GL_TEXTURE_IMAGE_FORMAT
:
179 case GL_TEXTURE_IMAGE_TYPE
:
180 case GL_GET_TEXTURE_IMAGE_FORMAT
:
181 case GL_GET_TEXTURE_IMAGE_TYPE
:
183 case GL_MANUAL_GENERATE_MIPMAP
:
184 case GL_AUTO_GENERATE_MIPMAP
:
185 case GL_COLOR_ENCODING
:
189 case GL_VERTEX_TEXTURE
:
190 case GL_TESS_CONTROL_TEXTURE
:
191 case GL_TESS_EVALUATION_TEXTURE
:
192 case GL_GEOMETRY_TEXTURE
:
193 case GL_FRAGMENT_TEXTURE
:
194 case GL_COMPUTE_TEXTURE
:
195 case GL_TEXTURE_SHADOW
:
196 case GL_TEXTURE_GATHER
:
197 case GL_TEXTURE_GATHER_SHADOW
:
198 case GL_SHADER_IMAGE_LOAD
:
199 case GL_SHADER_IMAGE_STORE
:
200 case GL_SHADER_IMAGE_ATOMIC
:
201 case GL_IMAGE_TEXEL_SIZE
:
202 case GL_IMAGE_COMPATIBILITY_CLASS
:
203 case GL_IMAGE_PIXEL_FORMAT
:
204 case GL_IMAGE_PIXEL_TYPE
:
205 case GL_IMAGE_FORMAT_COMPATIBILITY_TYPE
:
206 case GL_SIMULTANEOUS_TEXTURE_AND_DEPTH_TEST
:
207 case GL_SIMULTANEOUS_TEXTURE_AND_STENCIL_TEST
:
208 case GL_SIMULTANEOUS_TEXTURE_AND_DEPTH_WRITE
:
209 case GL_SIMULTANEOUS_TEXTURE_AND_STENCIL_WRITE
:
210 case GL_TEXTURE_COMPRESSED
:
211 case GL_TEXTURE_COMPRESSED_BLOCK_WIDTH
:
212 case GL_TEXTURE_COMPRESSED_BLOCK_HEIGHT
:
213 case GL_TEXTURE_COMPRESSED_BLOCK_SIZE
:
214 case GL_CLEAR_BUFFER
:
215 case GL_TEXTURE_VIEW
:
216 case GL_VIEW_COMPATIBILITY_CLASS
:
217 /* The ARB_internalformat_query spec says:
219 * "If the <pname> parameter to GetInternalformativ is not SAMPLES
220 * or NUM_SAMPLE_COUNTS, then an INVALID_ENUM error is generated."
223 _mesa_error(ctx
, GL_INVALID_ENUM
,
224 "glGetInternalformativ(pname=%s)",
225 _mesa_enum_to_string(pname
));
232 _mesa_error(ctx
, GL_INVALID_ENUM
,
233 "glGetInternalformativ(pname=%s)",
234 _mesa_enum_to_string(pname
));
238 /* The ARB_internalformat_query spec says:
240 * "If the <bufSize> parameter to GetInternalformativ is negative, then
241 * an INVALID_VALUE error is generated."
243 * Nothing is said in ARB_internalformat_query2 but we assume the same.
246 _mesa_error(ctx
, GL_INVALID_VALUE
,
247 "glGetInternalformativ(target=%s)",
248 _mesa_enum_to_string(target
));
252 /* The ARB_internalformat_query spec says:
254 * "If the <internalformat> parameter to GetInternalformativ is not
255 * color-, depth- or stencil-renderable, then an INVALID_ENUM error is
258 if (!query2
&& !_is_renderable(ctx
, internalformat
)) {
259 _mesa_error(ctx
, GL_INVALID_ENUM
,
260 "glGetInternalformativ(internalformat=%s)",
261 _mesa_enum_to_string(internalformat
));
268 /* Sets the appropriate "unsupported" response as defined by the
269 * ARB_internalformat_query2 spec for each each <pname>.
272 _set_default_response(GLenum pname
, GLint buffer
[16])
274 /* The ARB_internalformat_query2 defines which is the reponse best
275 * representing "not supported" or "not applicable" for each <pname>.
278 * - size- or count-based queries will return zero,
279 * - support-, format- or type-based queries will return NONE,
280 * - boolean-based queries will return FALSE, and
281 * - list-based queries return no entries."
287 case GL_MAX_COMBINED_DIMENSIONS
:
288 /* This value can be a 64-bit value. As the default is the 32-bit query,
289 * we pack 2 32-bit integers. So we need to clean both */
294 case GL_NUM_SAMPLE_COUNTS
:
295 case GL_INTERNALFORMAT_RED_SIZE
:
296 case GL_INTERNALFORMAT_GREEN_SIZE
:
297 case GL_INTERNALFORMAT_BLUE_SIZE
:
298 case GL_INTERNALFORMAT_ALPHA_SIZE
:
299 case GL_INTERNALFORMAT_DEPTH_SIZE
:
300 case GL_INTERNALFORMAT_STENCIL_SIZE
:
301 case GL_INTERNALFORMAT_SHARED_SIZE
:
306 case GL_IMAGE_TEXEL_SIZE
:
307 case GL_TEXTURE_COMPRESSED_BLOCK_WIDTH
:
308 case GL_TEXTURE_COMPRESSED_BLOCK_HEIGHT
:
309 case GL_TEXTURE_COMPRESSED_BLOCK_SIZE
:
313 case GL_INTERNALFORMAT_PREFERRED
:
314 case GL_INTERNALFORMAT_RED_TYPE
:
315 case GL_INTERNALFORMAT_GREEN_TYPE
:
316 case GL_INTERNALFORMAT_BLUE_TYPE
:
317 case GL_INTERNALFORMAT_ALPHA_TYPE
:
318 case GL_INTERNALFORMAT_DEPTH_TYPE
:
319 case GL_INTERNALFORMAT_STENCIL_TYPE
:
320 case GL_FRAMEBUFFER_RENDERABLE
:
321 case GL_FRAMEBUFFER_RENDERABLE_LAYERED
:
322 case GL_FRAMEBUFFER_BLEND
:
324 case GL_READ_PIXELS_FORMAT
:
325 case GL_READ_PIXELS_TYPE
:
326 case GL_TEXTURE_IMAGE_FORMAT
:
327 case GL_TEXTURE_IMAGE_TYPE
:
328 case GL_GET_TEXTURE_IMAGE_FORMAT
:
329 case GL_GET_TEXTURE_IMAGE_TYPE
:
330 case GL_MANUAL_GENERATE_MIPMAP
:
331 case GL_AUTO_GENERATE_MIPMAP
:
332 case GL_COLOR_ENCODING
:
335 case GL_SRGB_DECODE_ARB
:
337 case GL_VERTEX_TEXTURE
:
338 case GL_TESS_CONTROL_TEXTURE
:
339 case GL_TESS_EVALUATION_TEXTURE
:
340 case GL_GEOMETRY_TEXTURE
:
341 case GL_FRAGMENT_TEXTURE
:
342 case GL_COMPUTE_TEXTURE
:
343 case GL_TEXTURE_SHADOW
:
344 case GL_TEXTURE_GATHER
:
345 case GL_TEXTURE_GATHER_SHADOW
:
346 case GL_SHADER_IMAGE_LOAD
:
347 case GL_SHADER_IMAGE_STORE
:
348 case GL_SHADER_IMAGE_ATOMIC
:
349 case GL_IMAGE_COMPATIBILITY_CLASS
:
350 case GL_IMAGE_PIXEL_FORMAT
:
351 case GL_IMAGE_PIXEL_TYPE
:
352 case GL_IMAGE_FORMAT_COMPATIBILITY_TYPE
:
353 case GL_SIMULTANEOUS_TEXTURE_AND_DEPTH_TEST
:
354 case GL_SIMULTANEOUS_TEXTURE_AND_STENCIL_TEST
:
355 case GL_SIMULTANEOUS_TEXTURE_AND_DEPTH_WRITE
:
356 case GL_SIMULTANEOUS_TEXTURE_AND_STENCIL_WRITE
:
357 case GL_CLEAR_BUFFER
:
358 case GL_TEXTURE_VIEW
:
359 case GL_VIEW_COMPATIBILITY_CLASS
:
363 case GL_INTERNALFORMAT_SUPPORTED
:
364 case GL_COLOR_COMPONENTS
:
365 case GL_DEPTH_COMPONENTS
:
366 case GL_STENCIL_COMPONENTS
:
367 case GL_COLOR_RENDERABLE
:
368 case GL_DEPTH_RENDERABLE
:
369 case GL_STENCIL_RENDERABLE
:
371 case GL_TEXTURE_COMPRESSED
:
372 buffer
[0] = GL_FALSE
;
376 unreachable("invalid 'pname'");
381 _is_target_supported(struct gl_context
*ctx
, GLenum target
)
383 /* The ARB_internalformat_query2 spec says:
385 * "if a particular type of <target> is not supported by the
386 * implementation the "unsupported" answer should be given.
387 * This is not an error."
395 if (!_mesa_is_desktop_gl(ctx
))
399 case GL_TEXTURE_1D_ARRAY
:
400 if (!_mesa_has_EXT_texture_array(ctx
))
404 case GL_TEXTURE_2D_ARRAY
:
405 if (!(_mesa_has_EXT_texture_array(ctx
) || _mesa_is_gles3(ctx
)))
409 case GL_TEXTURE_CUBE_MAP
:
410 if (!_mesa_has_ARB_texture_cube_map(ctx
))
414 case GL_TEXTURE_CUBE_MAP_ARRAY
:
415 if (!_mesa_has_ARB_texture_cube_map_array(ctx
))
419 case GL_TEXTURE_RECTANGLE
:
420 if (!_mesa_has_NV_texture_rectangle(ctx
))
424 case GL_TEXTURE_BUFFER
:
425 if (!_mesa_has_ARB_texture_buffer_object(ctx
))
429 case GL_RENDERBUFFER
:
430 if (!(_mesa_has_ARB_framebuffer_object(ctx
) ||
431 _mesa_is_gles3(ctx
)))
435 case GL_TEXTURE_2D_MULTISAMPLE
:
436 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
437 if (!(_mesa_has_ARB_texture_multisample(ctx
) ||
438 _mesa_is_gles31(ctx
)))
443 unreachable("invalid target");
450 _is_resource_supported(struct gl_context
*ctx
, GLenum target
,
451 GLenum internalformat
, GLenum pname
)
453 /* From the ARB_internalformat_query2 spec:
455 * In the following descriptions, the term /resource/ is used to generically
456 * refer to an object of the appropriate type that has been created with
457 * <internalformat> and <target>. If the particular <target> and
458 * <internalformat> combination do not make sense, ... the "unsupported"
459 * answer should be given. This is not an error.
462 /* In the ARB_internalformat_query2 spec wording, some <pnames> do not care
463 * about the /resource/ being supported or not, we return 'true' for those.
466 case GL_INTERNALFORMAT_SUPPORTED
:
467 case GL_INTERNALFORMAT_PREFERRED
:
468 case GL_COLOR_COMPONENTS
:
469 case GL_DEPTH_COMPONENTS
:
470 case GL_STENCIL_COMPONENTS
:
471 case GL_COLOR_RENDERABLE
:
472 case GL_DEPTH_RENDERABLE
:
473 case GL_STENCIL_RENDERABLE
:
481 case GL_TEXTURE_1D_ARRAY
:
483 case GL_TEXTURE_2D_ARRAY
:
485 case GL_TEXTURE_CUBE_MAP
:
486 case GL_TEXTURE_CUBE_MAP_ARRAY
:
487 case GL_TEXTURE_RECTANGLE
:
488 /* Based on what Mesa does for glTexImage1D/2D/3D and
489 * glCompressedTexImage1D/2D/3D functions.
491 if (_mesa_base_tex_format(ctx
, internalformat
) < 0)
494 /* additional checks for depth textures */
495 if (!_mesa_legal_texture_base_format_for_target(ctx
, target
, internalformat
))
498 /* additional checks for compressed textures */
499 if (_mesa_is_compressed_format(ctx
, internalformat
) &&
500 (!_mesa_target_can_be_compressed(ctx
, target
, internalformat
, NULL
) ||
501 _mesa_format_no_online_compression(ctx
, internalformat
)))
505 case GL_TEXTURE_2D_MULTISAMPLE
:
506 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
507 /* Based on what Mesa does for glTexImage2D/3DMultisample,
508 * glTexStorage2D/3DMultisample and
509 * glTextureStorage2D/3DMultisample functions.
511 if (!_mesa_is_renderable_texture_format(ctx
, internalformat
))
515 case GL_TEXTURE_BUFFER
:
516 /* Based on what Mesa does for the glTexBuffer function. */
517 if (_mesa_validate_texbuffer_format(ctx
, internalformat
) ==
522 case GL_RENDERBUFFER
:
523 /* Based on what Mesa does for glRenderbufferStorage(Multisample) and
524 * glNamedRenderbufferStorage functions.
526 if (!_mesa_base_fbo_format(ctx
, internalformat
))
531 unreachable("bad target");
538 _is_internalformat_supported(struct gl_context
*ctx
, GLenum target
,
539 GLenum internalformat
)
541 /* From the ARB_internalformat_query2 specification:
543 * "- INTERNALFORMAT_SUPPORTED: If <internalformat> is an internal format
544 * that is supported by the implementation in at least some subset of
545 * possible operations, TRUE is written to <params>. If <internalformat>
546 * if not a valid token for any internal format usage, FALSE is returned.
548 * <internalformats> that must be supported (in GL 4.2 or later) include
550 * - "sized internal formats" from Table 3.12, 3.13, and 3.15,
551 * - any specific "compressed internal format" from Table 3.14,
552 * - any "image unit format" from Table 3.21.
553 * - any generic "compressed internal format" from Table 3.14, if the
554 * implementation accepts it for any texture specification commands, and
555 * - unsized or base internal format, if the implementation accepts
556 * it for texture or image specification.
560 /* At this point a internalformat is valid if it is valid as a texture or
561 * as a renderbuffer format. The checks are different because those methods
562 * return different values when passing non supported internalformats */
563 if (_mesa_base_tex_format(ctx
, internalformat
) < 0 &&
564 _mesa_base_fbo_format(ctx
, internalformat
) == 0)
567 /* Let the driver have the final word */
568 ctx
->Driver
.QueryInternalFormat(ctx
, target
, internalformat
,
569 GL_INTERNALFORMAT_SUPPORTED
, buffer
);
571 return (buffer
[0] == GL_TRUE
);
574 /* default implementation of QueryInternalFormat driverfunc, for
575 * drivers not implementing ARB_internalformat_query2.
578 _mesa_query_internal_format_default(struct gl_context
*ctx
, GLenum target
,
579 GLenum internalFormat
, GLenum pname
,
584 (void) internalFormat
;
588 case GL_NUM_SAMPLE_COUNTS
:
592 case GL_INTERNALFORMAT_SUPPORTED
:
596 case GL_INTERNALFORMAT_PREFERRED
:
597 params
[0] = internalFormat
;
600 case GL_MANUAL_GENERATE_MIPMAP
:
601 case GL_AUTO_GENERATE_MIPMAP
:
604 case GL_SRGB_DECODE_ARB
:
605 case GL_VERTEX_TEXTURE
:
606 case GL_TESS_CONTROL_TEXTURE
:
607 case GL_TESS_EVALUATION_TEXTURE
:
608 case GL_GEOMETRY_TEXTURE
:
609 case GL_FRAGMENT_TEXTURE
:
610 case GL_COMPUTE_TEXTURE
:
611 case GL_SHADER_IMAGE_LOAD
:
612 case GL_SHADER_IMAGE_STORE
:
613 case GL_SHADER_IMAGE_ATOMIC
:
614 params
[0] = GL_FULL_SUPPORT
;
618 _set_default_response(pname
, params
);
624 * For MAX_WIDTH/MAX_HEIGHT/MAX_DEPTH it returns the equivalent GetInteger
625 * pname for a Getinternalformat pname/target combination. target/pname
626 * combinations that would return 0 due dimension number or unsupported status
627 * should be already filtered out
629 * Note that this means that the returned value would be independent of the
630 * internalformat. This possibility is already mentioned at the Issue 7 of the
631 * arb_internalformat_query2 spec.
634 equivalentSizePname(GLenum target
,
640 case GL_TEXTURE_2D_MULTISAMPLE
:
641 return GL_MAX_TEXTURE_SIZE
;
643 return GL_MAX_3D_TEXTURE_SIZE
;
644 case GL_TEXTURE_CUBE_MAP
:
645 return GL_MAX_CUBE_MAP_TEXTURE_SIZE
;
646 case GL_TEXTURE_RECTANGLE
:
647 return GL_MAX_RECTANGLE_TEXTURE_SIZE
;
648 case GL_RENDERBUFFER
:
649 return GL_MAX_RENDERBUFFER_SIZE
;
650 case GL_TEXTURE_1D_ARRAY
:
651 if (pname
== GL_MAX_HEIGHT
)
652 return GL_MAX_ARRAY_TEXTURE_LAYERS
;
654 return GL_MAX_TEXTURE_SIZE
;
655 case GL_TEXTURE_2D_ARRAY
:
656 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
657 if (pname
== GL_MAX_DEPTH
)
658 return GL_MAX_ARRAY_TEXTURE_LAYERS
;
660 return GL_MAX_TEXTURE_SIZE
;
661 case GL_TEXTURE_CUBE_MAP_ARRAY
:
662 if (pname
== GL_MAX_DEPTH
)
663 return GL_MAX_ARRAY_TEXTURE_LAYERS
;
665 return GL_MAX_CUBE_MAP_TEXTURE_SIZE
;
666 case GL_TEXTURE_BUFFER
:
667 return GL_MAX_TEXTURE_BUFFER_SIZE
;
674 * Returns the dimensions associated to a target. GL_TEXTURE_BUFFER and
675 * GL_RENDERBUFFER have associated a dimension, but they are not textures
676 * per-se, so we can't just call _mesa_get_texture_dimension directly.
679 get_target_dimensions(GLenum target
)
682 case GL_TEXTURE_BUFFER
:
684 case GL_RENDERBUFFER
:
687 return _mesa_get_texture_dimensions(target
);
692 * Returns the minimum amount of dimensions associated to a pname. So for
693 * example, if querying GL_MAX_HEIGHT, it is assumed that your target would
694 * have as minimum 2 dimensions.
696 * Useful to handle sentences like this from query2 spec:
700 * If the resource does not have at least two dimensions
704 get_min_dimensions(GLenum pname
)
719 * Similar to teximage.c:check_multisample_target, but independent of the
723 is_multisample_target(GLenum target
)
726 case GL_TEXTURE_2D_MULTISAMPLE
:
727 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
736 _mesa_GetInternalformativ(GLenum target
, GLenum internalformat
, GLenum pname
,
737 GLsizei bufSize
, GLint
*params
)
740 GET_CURRENT_CONTEXT(ctx
);
742 ASSERT_OUTSIDE_BEGIN_END(ctx
);
744 /* ARB_internalformat_query is also mandatory for ARB_internalformat_query2 */
745 if (!(_mesa_has_ARB_internalformat_query(ctx
) ||
746 _mesa_is_gles3(ctx
))) {
747 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetInternalformativ");
751 assert(ctx
->Driver
.QueryInternalFormat
!= NULL
);
753 if (!_legal_parameters(ctx
, target
, internalformat
, pname
, bufSize
, params
))
756 /* initialize the contents of the temporary buffer */
757 memcpy(buffer
, params
, MIN2(bufSize
, 16) * sizeof(GLint
));
759 /* Use the 'unsupported' response defined by the spec for every pname
760 * as the default answer.
762 _set_default_response(pname
, buffer
);
764 if (!_is_target_supported(ctx
, target
) ||
765 !_is_internalformat_supported(ctx
, target
, internalformat
) ||
766 !_is_resource_supported(ctx
, target
, internalformat
, pname
))
772 case GL_NUM_SAMPLE_COUNTS
:
773 /* The ARB_internalformat_query2 sets the response as 'unsupported' for
774 * SAMPLES and NUM_SAMPLE_COUNTS:
776 * "If <internalformat> is not color-renderable, depth-renderable, or
777 * stencil-renderable (as defined in section 4.4.4), or if <target>
778 * does not support multiple samples (ie other than
779 * TEXTURE_2D_MULTISAMPLE, TEXTURE_2D_MULTISAMPLE_ARRAY,
782 if ((target
!= GL_RENDERBUFFER
&&
783 target
!= GL_TEXTURE_2D_MULTISAMPLE
&&
784 target
!= GL_TEXTURE_2D_MULTISAMPLE_ARRAY
) ||
785 !_is_renderable(ctx
, internalformat
))
788 /* The GL ES 3.0 specification, section 6.1.15 page 236 says:
790 * "Since multisampling is not supported for signed and unsigned
791 * integer internal formats, the value of NUM_SAMPLE_COUNTS will be
792 * zero for such formats.
794 if (pname
== GL_NUM_SAMPLE_COUNTS
&& ctx
->API
== API_OPENGLES2
&&
795 ctx
->Version
== 30 && _mesa_is_enum_format_integer(internalformat
)) {
799 ctx
->Driver
.QueryInternalFormat(ctx
, target
, internalformat
, pname
,
803 case GL_INTERNALFORMAT_SUPPORTED
:
804 /* Having a supported <internalformat> is implemented as a prerequisite
805 * for all the <pnames>. Thus, if we reach this point, the internalformat is
811 case GL_INTERNALFORMAT_PREFERRED
:
812 /* The ARB_internalformat_query2 spec says:
814 * "- INTERNALFORMAT_PREFERRED: The implementation-preferred internal
815 * format for representing resources of the specified <internalformat> is
816 * returned in <params>.
818 * Therefore, we let the driver answer.
820 ctx
->Driver
.QueryInternalFormat(ctx
, target
, internalformat
, pname
,
824 case GL_INTERNALFORMAT_RED_SIZE
:
825 case GL_INTERNALFORMAT_GREEN_SIZE
:
826 case GL_INTERNALFORMAT_BLUE_SIZE
:
827 case GL_INTERNALFORMAT_ALPHA_SIZE
:
828 case GL_INTERNALFORMAT_DEPTH_SIZE
:
829 case GL_INTERNALFORMAT_STENCIL_SIZE
:
830 case GL_INTERNALFORMAT_SHARED_SIZE
:
831 case GL_INTERNALFORMAT_RED_TYPE
:
832 case GL_INTERNALFORMAT_GREEN_TYPE
:
833 case GL_INTERNALFORMAT_BLUE_TYPE
:
834 case GL_INTERNALFORMAT_ALPHA_TYPE
:
835 case GL_INTERNALFORMAT_DEPTH_TYPE
:
836 case GL_INTERNALFORMAT_STENCIL_TYPE
: {
838 mesa_format texformat
;
840 if (target
!= GL_RENDERBUFFER
) {
841 if (!_mesa_legal_get_tex_level_parameter_target(ctx
, target
, true))
844 baseformat
= _mesa_base_tex_format(ctx
, internalformat
);
846 baseformat
= _mesa_base_fbo_format(ctx
, internalformat
);
849 /* Let the driver choose the texture format.
851 * Disclaimer: I am considering that drivers use for renderbuffers the
852 * same format-choice logic as for textures.
854 texformat
= ctx
->Driver
.ChooseTextureFormat(ctx
, target
, internalformat
,
855 GL_NONE
/*format */, GL_NONE
/* type */);
857 if (texformat
== MESA_FORMAT_NONE
|| baseformat
<= 0)
860 /* Implementation based on what Mesa does for glGetTexLevelParameteriv
861 * and glGetRenderbufferParameteriv functions.
863 if (pname
== GL_INTERNALFORMAT_SHARED_SIZE
) {
864 if (_mesa_has_EXT_texture_shared_exponent(ctx
) &&
865 target
!= GL_TEXTURE_BUFFER
&&
866 target
!= GL_RENDERBUFFER
&&
867 texformat
== MESA_FORMAT_R9G9B9E5_FLOAT
) {
873 if (!_mesa_base_format_has_channel(baseformat
, pname
))
877 case GL_INTERNALFORMAT_DEPTH_SIZE
:
878 if (!_mesa_has_ARB_depth_texture(ctx
) &&
879 target
!= GL_RENDERBUFFER
&&
880 target
!= GL_TEXTURE_BUFFER
)
883 case GL_INTERNALFORMAT_RED_SIZE
:
884 case GL_INTERNALFORMAT_GREEN_SIZE
:
885 case GL_INTERNALFORMAT_BLUE_SIZE
:
886 case GL_INTERNALFORMAT_ALPHA_SIZE
:
887 case GL_INTERNALFORMAT_STENCIL_SIZE
:
888 buffer
[0] = _mesa_get_format_bits(texformat
, pname
);
891 case GL_INTERNALFORMAT_DEPTH_TYPE
:
892 if (!_mesa_has_ARB_texture_float(ctx
))
895 case GL_INTERNALFORMAT_RED_TYPE
:
896 case GL_INTERNALFORMAT_GREEN_TYPE
:
897 case GL_INTERNALFORMAT_BLUE_TYPE
:
898 case GL_INTERNALFORMAT_ALPHA_TYPE
:
899 case GL_INTERNALFORMAT_STENCIL_TYPE
:
900 buffer
[0] = _mesa_get_format_datatype(texformat
);
910 /* For WIDTH/HEIGHT/DEPTH/LAYERS there is no reason to think that the
911 * returned values should be different to the values returned by
912 * GetInteger with MAX_TEXTURE_SIZE, MAX_3D_TEXTURE_SIZE, etc.*/
918 GLint min_dimensions
;
920 /* From query2:MAX_HEIGHT spec (as example):
922 * "If the resource does not have at least two dimensions, or if the
923 * resource is unsupported, zero is returned."
925 dimensions
= get_target_dimensions(target
);
926 min_dimensions
= get_min_dimensions(pname
);
927 if (dimensions
< min_dimensions
)
930 get_pname
= equivalentSizePname(target
, pname
);
934 _mesa_GetIntegerv(get_pname
, buffer
);
939 if (!_mesa_has_EXT_texture_array(ctx
))
942 if (!_mesa_is_array_texture(target
))
945 _mesa_GetIntegerv(GL_MAX_ARRAY_TEXTURE_LAYERS
, buffer
);
948 case GL_MAX_COMBINED_DIMENSIONS
:{
949 GLint64 combined_value
= 1;
950 GLenum max_dimensions_pnames
[] = {
959 /* Combining the dimensions. Note that for array targets, this would
960 * automatically include the value of MAX_LAYERS, as that value is
961 * returned as MAX_HEIGHT or MAX_DEPTH */
962 for (i
= 0; i
< 4; i
++) {
963 if (max_dimensions_pnames
[i
] == GL_SAMPLES
&&
964 !is_multisample_target(target
))
967 _mesa_GetInternalformativ(target
, internalformat
,
968 max_dimensions_pnames
[i
],
971 if (current_value
!= 0)
972 combined_value
*= current_value
;
975 if (_mesa_is_cube_map_texture(target
))
978 /* We pack the 64-bit value on two 32-bit values. Calling the 32-bit
979 * query, this would work as far as the value can be hold on a 32-bit
980 * signed integer. For the 64-bit query, the wrapper around the 32-bit
981 * query will unpack the value */
982 memcpy(buffer
, &combined_value
, sizeof(GLint64
));
986 case GL_COLOR_COMPONENTS
:
987 /* The ARB_internalformat_query2 spec says:
989 * "- COLOR_COMPONENTS: If the internal format contains any color
990 * components (R, G, B, or A), TRUE is returned in <params>.
991 * If the internal format is unsupported or contains no color
992 * components, FALSE is returned."
994 if (_mesa_is_color_format(internalformat
))
998 case GL_DEPTH_COMPONENTS
:
999 /* The ARB_internalformat_query2 spec says:
1001 * "- DEPTH_COMPONENTS: If the internal format contains a depth
1002 * component (D), TRUE is returned in <params>. If the internal format
1003 * is unsupported or contains no depth component, FALSE is returned."
1005 if (_mesa_is_depth_format(internalformat
) ||
1006 _mesa_is_depthstencil_format(internalformat
))
1007 buffer
[0] = GL_TRUE
;
1010 case GL_STENCIL_COMPONENTS
:
1011 /* The ARB_internalformat_query2 spec says:
1013 * "- STENCIL_COMPONENTS: If the internal format contains a stencil
1014 * component (S), TRUE is returned in <params>. If the internal format
1015 * is unsupported or contains no stencil component, FALSE is returned.
1017 if (_mesa_is_stencil_format(internalformat
) ||
1018 _mesa_is_depthstencil_format(internalformat
))
1019 buffer
[0] = GL_TRUE
;
1022 case GL_COLOR_RENDERABLE
:
1023 case GL_DEPTH_RENDERABLE
:
1024 case GL_STENCIL_RENDERABLE
:
1025 if (!_is_renderable(ctx
, internalformat
))
1028 if (pname
== GL_COLOR_RENDERABLE
) {
1029 if (!_mesa_is_color_format(internalformat
))
1032 GLenum baseFormat
= _mesa_base_fbo_format(ctx
, internalformat
);
1033 if (baseFormat
!= GL_DEPTH_STENCIL
&&
1034 ((pname
== GL_DEPTH_RENDERABLE
&& baseFormat
!= GL_DEPTH_COMPONENT
) ||
1035 (pname
== GL_STENCIL_RENDERABLE
&& baseFormat
!= GL_STENCIL_INDEX
)))
1039 buffer
[0] = GL_TRUE
;
1042 case GL_FRAMEBUFFER_RENDERABLE
:
1046 case GL_FRAMEBUFFER_RENDERABLE_LAYERED
:
1050 case GL_FRAMEBUFFER_BLEND
:
1054 case GL_READ_PIXELS
:
1058 case GL_READ_PIXELS_FORMAT
:
1062 case GL_READ_PIXELS_TYPE
:
1066 case GL_TEXTURE_IMAGE_FORMAT
:
1070 case GL_TEXTURE_IMAGE_TYPE
:
1074 case GL_GET_TEXTURE_IMAGE_FORMAT
:
1078 case GL_GET_TEXTURE_IMAGE_TYPE
:
1083 case GL_MANUAL_GENERATE_MIPMAP
:
1084 case GL_AUTO_GENERATE_MIPMAP
:
1085 if (!_mesa_is_valid_generate_texture_mipmap_target(ctx
, target
) ||
1086 !_mesa_is_valid_generate_texture_mipmap_internalformat(ctx
,
1091 if (pname
== GL_MIPMAP
) {
1092 buffer
[0] = GL_TRUE
;
1095 else if (pname
== GL_MANUAL_GENERATE_MIPMAP
) {
1096 if (!_mesa_has_ARB_framebuffer_object(ctx
))
1100 /* From ARB_internalformat_query2:
1101 * "Dependencies on OpenGL 3.2 (Core Profile)
1102 * In core profiles for OpenGL 3.2 and later versions, queries
1103 * for the AUTO_GENERATE_MIPMAP <pname> return the appropriate
1104 * unsupported response."
1106 if (_mesa_is_desktop_gl(ctx
) && ctx
->Version
>= 32)
1110 ctx
->Driver
.QueryInternalFormat(ctx
, target
, internalformat
, pname
,
1114 case GL_COLOR_ENCODING
:
1115 if (!_mesa_is_color_format(internalformat
))
1118 if (_mesa_is_srgb_format(internalformat
))
1119 buffer
[0] = GL_SRGB
;
1121 buffer
[0] = GL_LINEAR
;
1125 if (!_mesa_has_EXT_texture_sRGB(ctx
) ||
1126 !_mesa_is_srgb_format(internalformat
)) {
1130 ctx
->Driver
.QueryInternalFormat(ctx
, target
, internalformat
, pname
,
1135 if (!_mesa_has_EXT_framebuffer_sRGB(ctx
) ||
1136 !_mesa_is_color_format(internalformat
)) {
1140 ctx
->Driver
.QueryInternalFormat(ctx
, target
, internalformat
, pname
,
1144 case GL_SRGB_DECODE_ARB
:
1145 /* Presence of EXT_texture_sRGB_decode was already verified */
1146 if (!_mesa_has_EXT_texture_sRGB(ctx
) ||
1147 target
== GL_RENDERBUFFER
||
1148 !_mesa_is_srgb_format(internalformat
)) {
1152 ctx
->Driver
.QueryInternalFormat(ctx
, target
, internalformat
, pname
,
1160 case GL_VERTEX_TEXTURE
:
1161 case GL_TESS_CONTROL_TEXTURE
:
1162 case GL_TESS_EVALUATION_TEXTURE
:
1163 case GL_GEOMETRY_TEXTURE
:
1164 case GL_FRAGMENT_TEXTURE
:
1165 case GL_COMPUTE_TEXTURE
:
1166 if (target
== GL_RENDERBUFFER
)
1169 if ((pname
== GL_TESS_CONTROL_TEXTURE
||
1170 pname
== GL_TESS_EVALUATION_TEXTURE
) &&
1171 !_mesa_has_tessellation(ctx
))
1174 if (pname
== GL_GEOMETRY_TEXTURE
&& !_mesa_has_geometry_shaders(ctx
))
1177 if (pname
== GL_COMPUTE_TEXTURE
&& !_mesa_has_compute_shaders(ctx
))
1180 ctx
->Driver
.QueryInternalFormat(ctx
, target
, internalformat
, pname
,
1184 case GL_TEXTURE_SHADOW
:
1188 case GL_TEXTURE_GATHER
:
1192 case GL_TEXTURE_GATHER_SHADOW
:
1196 case GL_SHADER_IMAGE_LOAD
:
1197 case GL_SHADER_IMAGE_STORE
:
1198 if (!_mesa_has_ARB_shader_image_load_store(ctx
))
1201 /* We call to _mesa_is_shader_image_format_supported
1202 * using "internalformat" as parameter, because the
1203 * the ARB_internalformat_query2 spec says:
1204 * "In this case the <internalformat> is the value of the <format>
1205 * parameter that is passed to BindImageTexture."
1207 if (target
== GL_RENDERBUFFER
||
1208 !_mesa_is_shader_image_format_supported(ctx
, internalformat
))
1211 ctx
->Driver
.QueryInternalFormat(ctx
, target
, internalformat
, pname
,
1215 case GL_SHADER_IMAGE_ATOMIC
:
1216 if (!_mesa_has_ARB_shader_image_load_store(ctx
))
1219 ctx
->Driver
.QueryInternalFormat(ctx
, target
, internalformat
, pname
,
1223 case GL_IMAGE_TEXEL_SIZE
:
1227 case GL_IMAGE_COMPATIBILITY_CLASS
:
1231 case GL_IMAGE_PIXEL_FORMAT
:
1235 case GL_IMAGE_PIXEL_TYPE
:
1239 case GL_IMAGE_FORMAT_COMPATIBILITY_TYPE
: {
1240 if (!_mesa_has_ARB_shader_image_load_store(ctx
))
1243 if (!_mesa_legal_get_tex_level_parameter_target(ctx
, target
, true))
1246 /* From spec: "Equivalent to calling GetTexParameter with <value> set
1247 * to IMAGE_FORMAT_COMPATIBILITY_TYPE."
1249 * GetTexParameter just returns
1250 * tex_obj->ImageFormatCompatibilityType. We create a fake tex_obj
1251 * just with the purpose of getting the value.
1253 struct gl_texture_object
*tex_obj
= _mesa_new_texture_object(ctx
, 0, target
);
1254 buffer
[0] = tex_obj
->ImageFormatCompatibilityType
;
1255 _mesa_delete_texture_object(ctx
, tex_obj
);
1260 case GL_SIMULTANEOUS_TEXTURE_AND_DEPTH_TEST
:
1264 case GL_SIMULTANEOUS_TEXTURE_AND_STENCIL_TEST
:
1268 case GL_SIMULTANEOUS_TEXTURE_AND_DEPTH_WRITE
:
1272 case GL_SIMULTANEOUS_TEXTURE_AND_STENCIL_WRITE
:
1276 case GL_TEXTURE_COMPRESSED
:
1280 case GL_TEXTURE_COMPRESSED_BLOCK_WIDTH
:
1284 case GL_TEXTURE_COMPRESSED_BLOCK_HEIGHT
:
1288 case GL_TEXTURE_COMPRESSED_BLOCK_SIZE
:
1292 case GL_CLEAR_BUFFER
:
1296 case GL_TEXTURE_VIEW
:
1300 case GL_VIEW_COMPATIBILITY_CLASS
:
1305 unreachable("bad param");
1309 if (bufSize
!= 0 && params
== NULL
) {
1310 /* Emit a warning to aid application debugging, but go ahead and do the
1311 * memcpy (and probably crash) anyway.
1314 "glGetInternalformativ(bufSize = %d, but params = NULL)",
1318 /* Copy the data from the temporary buffer to the buffer supplied by the
1319 * application. Clamp the size of the copy to the size supplied by the
1322 memcpy(params
, buffer
, MIN2(bufSize
, 16) * sizeof(GLint
));
1328 _mesa_GetInternalformati64v(GLenum target
, GLenum internalformat
,
1329 GLenum pname
, GLsizei bufSize
, GLint64
*params
)
1333 GLsizei realSize
= MIN2(bufSize
, 16);
1336 GET_CURRENT_CONTEXT(ctx
);
1338 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1340 if (!_mesa_has_ARB_internalformat_query2(ctx
)) {
1341 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetInternalformati64v");
1345 /* For SAMPLES there are cases where params needs to remain unmodified. As
1346 * no pname can return a negative value, we fill params32 with negative
1347 * values as reference values, that can be used to know what copy-back to
1349 memset(params32
, -1, 16);
1351 /* For GL_MAX_COMBINED_DIMENSIONS we need to get back 2 32-bit integers,
1352 * and at the same time we only need 2. So for that pname, we call the
1353 * 32-bit query with bufSize 2, except on the case of bufSize 0, that is
1354 * basically like asking to not get the value, but that is a caller
1356 if (pname
== GL_MAX_COMBINED_DIMENSIONS
&& bufSize
> 0)
1361 _mesa_GetInternalformativ(target
, internalformat
, pname
, callSize
, params32
);
1363 if (pname
== GL_MAX_COMBINED_DIMENSIONS
) {
1364 memcpy(params
, params32
, sizeof(GLint64
));
1366 for (i
= 0; i
< realSize
; i
++) {
1367 /* We only copy back the values that changed */
1368 if (params32
[i
] < 0)
1370 params
[i
] = (GLint64
) params32
[i
];