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 case GL_SIMULTANEOUS_TEXTURE_AND_DEPTH_TEST
:
615 case GL_SIMULTANEOUS_TEXTURE_AND_STENCIL_TEST
:
616 case GL_SIMULTANEOUS_TEXTURE_AND_DEPTH_WRITE
:
617 case GL_SIMULTANEOUS_TEXTURE_AND_STENCIL_WRITE
:
618 params
[0] = GL_FULL_SUPPORT
;
622 _set_default_response(pname
, params
);
628 * For MAX_WIDTH/MAX_HEIGHT/MAX_DEPTH it returns the equivalent GetInteger
629 * pname for a Getinternalformat pname/target combination. target/pname
630 * combinations that would return 0 due dimension number or unsupported status
631 * should be already filtered out
633 * Note that this means that the returned value would be independent of the
634 * internalformat. This possibility is already mentioned at the Issue 7 of the
635 * arb_internalformat_query2 spec.
638 equivalentSizePname(GLenum target
,
644 case GL_TEXTURE_2D_MULTISAMPLE
:
645 return GL_MAX_TEXTURE_SIZE
;
647 return GL_MAX_3D_TEXTURE_SIZE
;
648 case GL_TEXTURE_CUBE_MAP
:
649 return GL_MAX_CUBE_MAP_TEXTURE_SIZE
;
650 case GL_TEXTURE_RECTANGLE
:
651 return GL_MAX_RECTANGLE_TEXTURE_SIZE
;
652 case GL_RENDERBUFFER
:
653 return GL_MAX_RENDERBUFFER_SIZE
;
654 case GL_TEXTURE_1D_ARRAY
:
655 if (pname
== GL_MAX_HEIGHT
)
656 return GL_MAX_ARRAY_TEXTURE_LAYERS
;
658 return GL_MAX_TEXTURE_SIZE
;
659 case GL_TEXTURE_2D_ARRAY
:
660 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
661 if (pname
== GL_MAX_DEPTH
)
662 return GL_MAX_ARRAY_TEXTURE_LAYERS
;
664 return GL_MAX_TEXTURE_SIZE
;
665 case GL_TEXTURE_CUBE_MAP_ARRAY
:
666 if (pname
== GL_MAX_DEPTH
)
667 return GL_MAX_ARRAY_TEXTURE_LAYERS
;
669 return GL_MAX_CUBE_MAP_TEXTURE_SIZE
;
670 case GL_TEXTURE_BUFFER
:
671 return GL_MAX_TEXTURE_BUFFER_SIZE
;
678 * Returns the dimensions associated to a target. GL_TEXTURE_BUFFER and
679 * GL_RENDERBUFFER have associated a dimension, but they are not textures
680 * per-se, so we can't just call _mesa_get_texture_dimension directly.
683 get_target_dimensions(GLenum target
)
686 case GL_TEXTURE_BUFFER
:
688 case GL_RENDERBUFFER
:
691 return _mesa_get_texture_dimensions(target
);
696 * Returns the minimum amount of dimensions associated to a pname. So for
697 * example, if querying GL_MAX_HEIGHT, it is assumed that your target would
698 * have as minimum 2 dimensions.
700 * Useful to handle sentences like this from query2 spec:
704 * If the resource does not have at least two dimensions
708 get_min_dimensions(GLenum pname
)
723 * Similar to teximage.c:check_multisample_target, but independent of the
727 is_multisample_target(GLenum target
)
730 case GL_TEXTURE_2D_MULTISAMPLE
:
731 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
740 _mesa_GetInternalformativ(GLenum target
, GLenum internalformat
, GLenum pname
,
741 GLsizei bufSize
, GLint
*params
)
744 GET_CURRENT_CONTEXT(ctx
);
746 ASSERT_OUTSIDE_BEGIN_END(ctx
);
748 /* ARB_internalformat_query is also mandatory for ARB_internalformat_query2 */
749 if (!(_mesa_has_ARB_internalformat_query(ctx
) ||
750 _mesa_is_gles3(ctx
))) {
751 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetInternalformativ");
755 assert(ctx
->Driver
.QueryInternalFormat
!= NULL
);
757 if (!_legal_parameters(ctx
, target
, internalformat
, pname
, bufSize
, params
))
760 /* initialize the contents of the temporary buffer */
761 memcpy(buffer
, params
, MIN2(bufSize
, 16) * sizeof(GLint
));
763 /* Use the 'unsupported' response defined by the spec for every pname
764 * as the default answer.
766 _set_default_response(pname
, buffer
);
768 if (!_is_target_supported(ctx
, target
) ||
769 !_is_internalformat_supported(ctx
, target
, internalformat
) ||
770 !_is_resource_supported(ctx
, target
, internalformat
, pname
))
776 case GL_NUM_SAMPLE_COUNTS
:
777 /* The ARB_internalformat_query2 sets the response as 'unsupported' for
778 * SAMPLES and NUM_SAMPLE_COUNTS:
780 * "If <internalformat> is not color-renderable, depth-renderable, or
781 * stencil-renderable (as defined in section 4.4.4), or if <target>
782 * does not support multiple samples (ie other than
783 * TEXTURE_2D_MULTISAMPLE, TEXTURE_2D_MULTISAMPLE_ARRAY,
786 if ((target
!= GL_RENDERBUFFER
&&
787 target
!= GL_TEXTURE_2D_MULTISAMPLE
&&
788 target
!= GL_TEXTURE_2D_MULTISAMPLE_ARRAY
) ||
789 !_is_renderable(ctx
, internalformat
))
792 /* The GL ES 3.0 specification, section 6.1.15 page 236 says:
794 * "Since multisampling is not supported for signed and unsigned
795 * integer internal formats, the value of NUM_SAMPLE_COUNTS will be
796 * zero for such formats.
798 if (pname
== GL_NUM_SAMPLE_COUNTS
&& ctx
->API
== API_OPENGLES2
&&
799 ctx
->Version
== 30 && _mesa_is_enum_format_integer(internalformat
)) {
803 ctx
->Driver
.QueryInternalFormat(ctx
, target
, internalformat
, pname
,
807 case GL_INTERNALFORMAT_SUPPORTED
:
808 /* Having a supported <internalformat> is implemented as a prerequisite
809 * for all the <pnames>. Thus, if we reach this point, the internalformat is
815 case GL_INTERNALFORMAT_PREFERRED
:
816 /* The ARB_internalformat_query2 spec says:
818 * "- INTERNALFORMAT_PREFERRED: The implementation-preferred internal
819 * format for representing resources of the specified <internalformat> is
820 * returned in <params>.
822 * Therefore, we let the driver answer.
824 ctx
->Driver
.QueryInternalFormat(ctx
, target
, internalformat
, pname
,
828 case GL_INTERNALFORMAT_RED_SIZE
:
829 case GL_INTERNALFORMAT_GREEN_SIZE
:
830 case GL_INTERNALFORMAT_BLUE_SIZE
:
831 case GL_INTERNALFORMAT_ALPHA_SIZE
:
832 case GL_INTERNALFORMAT_DEPTH_SIZE
:
833 case GL_INTERNALFORMAT_STENCIL_SIZE
:
834 case GL_INTERNALFORMAT_SHARED_SIZE
:
835 case GL_INTERNALFORMAT_RED_TYPE
:
836 case GL_INTERNALFORMAT_GREEN_TYPE
:
837 case GL_INTERNALFORMAT_BLUE_TYPE
:
838 case GL_INTERNALFORMAT_ALPHA_TYPE
:
839 case GL_INTERNALFORMAT_DEPTH_TYPE
:
840 case GL_INTERNALFORMAT_STENCIL_TYPE
: {
842 mesa_format texformat
;
844 if (target
!= GL_RENDERBUFFER
) {
845 if (!_mesa_legal_get_tex_level_parameter_target(ctx
, target
, true))
848 baseformat
= _mesa_base_tex_format(ctx
, internalformat
);
850 baseformat
= _mesa_base_fbo_format(ctx
, internalformat
);
853 /* Let the driver choose the texture format.
855 * Disclaimer: I am considering that drivers use for renderbuffers the
856 * same format-choice logic as for textures.
858 texformat
= ctx
->Driver
.ChooseTextureFormat(ctx
, target
, internalformat
,
859 GL_NONE
/*format */, GL_NONE
/* type */);
861 if (texformat
== MESA_FORMAT_NONE
|| baseformat
<= 0)
864 /* Implementation based on what Mesa does for glGetTexLevelParameteriv
865 * and glGetRenderbufferParameteriv functions.
867 if (pname
== GL_INTERNALFORMAT_SHARED_SIZE
) {
868 if (_mesa_has_EXT_texture_shared_exponent(ctx
) &&
869 target
!= GL_TEXTURE_BUFFER
&&
870 target
!= GL_RENDERBUFFER
&&
871 texformat
== MESA_FORMAT_R9G9B9E5_FLOAT
) {
877 if (!_mesa_base_format_has_channel(baseformat
, pname
))
881 case GL_INTERNALFORMAT_DEPTH_SIZE
:
882 if (!_mesa_has_ARB_depth_texture(ctx
) &&
883 target
!= GL_RENDERBUFFER
&&
884 target
!= GL_TEXTURE_BUFFER
)
887 case GL_INTERNALFORMAT_RED_SIZE
:
888 case GL_INTERNALFORMAT_GREEN_SIZE
:
889 case GL_INTERNALFORMAT_BLUE_SIZE
:
890 case GL_INTERNALFORMAT_ALPHA_SIZE
:
891 case GL_INTERNALFORMAT_STENCIL_SIZE
:
892 buffer
[0] = _mesa_get_format_bits(texformat
, pname
);
895 case GL_INTERNALFORMAT_DEPTH_TYPE
:
896 if (!_mesa_has_ARB_texture_float(ctx
))
899 case GL_INTERNALFORMAT_RED_TYPE
:
900 case GL_INTERNALFORMAT_GREEN_TYPE
:
901 case GL_INTERNALFORMAT_BLUE_TYPE
:
902 case GL_INTERNALFORMAT_ALPHA_TYPE
:
903 case GL_INTERNALFORMAT_STENCIL_TYPE
:
904 buffer
[0] = _mesa_get_format_datatype(texformat
);
914 /* For WIDTH/HEIGHT/DEPTH/LAYERS there is no reason to think that the
915 * returned values should be different to the values returned by
916 * GetInteger with MAX_TEXTURE_SIZE, MAX_3D_TEXTURE_SIZE, etc.*/
922 GLint min_dimensions
;
924 /* From query2:MAX_HEIGHT spec (as example):
926 * "If the resource does not have at least two dimensions, or if the
927 * resource is unsupported, zero is returned."
929 dimensions
= get_target_dimensions(target
);
930 min_dimensions
= get_min_dimensions(pname
);
931 if (dimensions
< min_dimensions
)
934 get_pname
= equivalentSizePname(target
, pname
);
938 _mesa_GetIntegerv(get_pname
, buffer
);
943 if (!_mesa_has_EXT_texture_array(ctx
))
946 if (!_mesa_is_array_texture(target
))
949 _mesa_GetIntegerv(GL_MAX_ARRAY_TEXTURE_LAYERS
, buffer
);
952 case GL_MAX_COMBINED_DIMENSIONS
:{
953 GLint64 combined_value
= 1;
954 GLenum max_dimensions_pnames
[] = {
963 /* Combining the dimensions. Note that for array targets, this would
964 * automatically include the value of MAX_LAYERS, as that value is
965 * returned as MAX_HEIGHT or MAX_DEPTH */
966 for (i
= 0; i
< 4; i
++) {
967 if (max_dimensions_pnames
[i
] == GL_SAMPLES
&&
968 !is_multisample_target(target
))
971 _mesa_GetInternalformativ(target
, internalformat
,
972 max_dimensions_pnames
[i
],
975 if (current_value
!= 0)
976 combined_value
*= current_value
;
979 if (_mesa_is_cube_map_texture(target
))
982 /* We pack the 64-bit value on two 32-bit values. Calling the 32-bit
983 * query, this would work as far as the value can be hold on a 32-bit
984 * signed integer. For the 64-bit query, the wrapper around the 32-bit
985 * query will unpack the value */
986 memcpy(buffer
, &combined_value
, sizeof(GLint64
));
990 case GL_COLOR_COMPONENTS
:
991 /* The ARB_internalformat_query2 spec says:
993 * "- COLOR_COMPONENTS: If the internal format contains any color
994 * components (R, G, B, or A), TRUE is returned in <params>.
995 * If the internal format is unsupported or contains no color
996 * components, FALSE is returned."
998 if (_mesa_is_color_format(internalformat
))
1002 case GL_DEPTH_COMPONENTS
:
1003 /* The ARB_internalformat_query2 spec says:
1005 * "- DEPTH_COMPONENTS: If the internal format contains a depth
1006 * component (D), TRUE is returned in <params>. If the internal format
1007 * is unsupported or contains no depth component, FALSE is returned."
1009 if (_mesa_is_depth_format(internalformat
) ||
1010 _mesa_is_depthstencil_format(internalformat
))
1011 buffer
[0] = GL_TRUE
;
1014 case GL_STENCIL_COMPONENTS
:
1015 /* The ARB_internalformat_query2 spec says:
1017 * "- STENCIL_COMPONENTS: If the internal format contains a stencil
1018 * component (S), TRUE is returned in <params>. If the internal format
1019 * is unsupported or contains no stencil component, FALSE is returned.
1021 if (_mesa_is_stencil_format(internalformat
) ||
1022 _mesa_is_depthstencil_format(internalformat
))
1023 buffer
[0] = GL_TRUE
;
1026 case GL_COLOR_RENDERABLE
:
1027 case GL_DEPTH_RENDERABLE
:
1028 case GL_STENCIL_RENDERABLE
:
1029 if (!_is_renderable(ctx
, internalformat
))
1032 if (pname
== GL_COLOR_RENDERABLE
) {
1033 if (!_mesa_is_color_format(internalformat
))
1036 GLenum baseFormat
= _mesa_base_fbo_format(ctx
, internalformat
);
1037 if (baseFormat
!= GL_DEPTH_STENCIL
&&
1038 ((pname
== GL_DEPTH_RENDERABLE
&& baseFormat
!= GL_DEPTH_COMPONENT
) ||
1039 (pname
== GL_STENCIL_RENDERABLE
&& baseFormat
!= GL_STENCIL_INDEX
)))
1043 buffer
[0] = GL_TRUE
;
1046 case GL_FRAMEBUFFER_RENDERABLE
:
1050 case GL_FRAMEBUFFER_RENDERABLE_LAYERED
:
1054 case GL_FRAMEBUFFER_BLEND
:
1058 case GL_READ_PIXELS
:
1062 case GL_READ_PIXELS_FORMAT
:
1066 case GL_READ_PIXELS_TYPE
:
1070 case GL_TEXTURE_IMAGE_FORMAT
:
1074 case GL_TEXTURE_IMAGE_TYPE
:
1078 case GL_GET_TEXTURE_IMAGE_FORMAT
:
1082 case GL_GET_TEXTURE_IMAGE_TYPE
:
1087 case GL_MANUAL_GENERATE_MIPMAP
:
1088 case GL_AUTO_GENERATE_MIPMAP
:
1089 if (!_mesa_is_valid_generate_texture_mipmap_target(ctx
, target
) ||
1090 !_mesa_is_valid_generate_texture_mipmap_internalformat(ctx
,
1095 if (pname
== GL_MIPMAP
) {
1096 buffer
[0] = GL_TRUE
;
1099 else if (pname
== GL_MANUAL_GENERATE_MIPMAP
) {
1100 if (!_mesa_has_ARB_framebuffer_object(ctx
))
1104 /* From ARB_internalformat_query2:
1105 * "Dependencies on OpenGL 3.2 (Core Profile)
1106 * In core profiles for OpenGL 3.2 and later versions, queries
1107 * for the AUTO_GENERATE_MIPMAP <pname> return the appropriate
1108 * unsupported response."
1110 if (_mesa_is_desktop_gl(ctx
) && ctx
->Version
>= 32)
1114 ctx
->Driver
.QueryInternalFormat(ctx
, target
, internalformat
, pname
,
1118 case GL_COLOR_ENCODING
:
1119 if (!_mesa_is_color_format(internalformat
))
1122 if (_mesa_is_srgb_format(internalformat
))
1123 buffer
[0] = GL_SRGB
;
1125 buffer
[0] = GL_LINEAR
;
1129 if (!_mesa_has_EXT_texture_sRGB(ctx
) ||
1130 !_mesa_is_srgb_format(internalformat
)) {
1134 ctx
->Driver
.QueryInternalFormat(ctx
, target
, internalformat
, pname
,
1139 if (!_mesa_has_EXT_framebuffer_sRGB(ctx
) ||
1140 !_mesa_is_color_format(internalformat
)) {
1144 ctx
->Driver
.QueryInternalFormat(ctx
, target
, internalformat
, pname
,
1148 case GL_SRGB_DECODE_ARB
:
1149 /* Presence of EXT_texture_sRGB_decode was already verified */
1150 if (!_mesa_has_EXT_texture_sRGB(ctx
) ||
1151 target
== GL_RENDERBUFFER
||
1152 !_mesa_is_srgb_format(internalformat
)) {
1156 ctx
->Driver
.QueryInternalFormat(ctx
, target
, internalformat
, pname
,
1164 case GL_VERTEX_TEXTURE
:
1165 case GL_TESS_CONTROL_TEXTURE
:
1166 case GL_TESS_EVALUATION_TEXTURE
:
1167 case GL_GEOMETRY_TEXTURE
:
1168 case GL_FRAGMENT_TEXTURE
:
1169 case GL_COMPUTE_TEXTURE
:
1170 if (target
== GL_RENDERBUFFER
)
1173 if ((pname
== GL_TESS_CONTROL_TEXTURE
||
1174 pname
== GL_TESS_EVALUATION_TEXTURE
) &&
1175 !_mesa_has_tessellation(ctx
))
1178 if (pname
== GL_GEOMETRY_TEXTURE
&& !_mesa_has_geometry_shaders(ctx
))
1181 if (pname
== GL_COMPUTE_TEXTURE
&& !_mesa_has_compute_shaders(ctx
))
1184 ctx
->Driver
.QueryInternalFormat(ctx
, target
, internalformat
, pname
,
1188 case GL_TEXTURE_SHADOW
:
1192 case GL_TEXTURE_GATHER
:
1196 case GL_TEXTURE_GATHER_SHADOW
:
1200 case GL_SHADER_IMAGE_LOAD
:
1201 case GL_SHADER_IMAGE_STORE
:
1202 if (!_mesa_has_ARB_shader_image_load_store(ctx
))
1205 /* We call to _mesa_is_shader_image_format_supported
1206 * using "internalformat" as parameter, because the
1207 * the ARB_internalformat_query2 spec says:
1208 * "In this case the <internalformat> is the value of the <format>
1209 * parameter that is passed to BindImageTexture."
1211 if (target
== GL_RENDERBUFFER
||
1212 !_mesa_is_shader_image_format_supported(ctx
, internalformat
))
1215 ctx
->Driver
.QueryInternalFormat(ctx
, target
, internalformat
, pname
,
1219 case GL_SHADER_IMAGE_ATOMIC
:
1220 if (!_mesa_has_ARB_shader_image_load_store(ctx
))
1223 ctx
->Driver
.QueryInternalFormat(ctx
, target
, internalformat
, pname
,
1227 case GL_IMAGE_TEXEL_SIZE
: {
1228 mesa_format image_format
;
1230 if (!_mesa_has_ARB_shader_image_load_store(ctx
) ||
1231 target
== GL_RENDERBUFFER
)
1234 image_format
= _mesa_get_shader_image_format(internalformat
);
1235 if (image_format
== MESA_FORMAT_NONE
)
1238 /* We return bits */
1239 buffer
[0] = (_mesa_get_format_bytes(image_format
) * 8);
1243 case GL_IMAGE_COMPATIBILITY_CLASS
:
1244 if (!_mesa_has_ARB_shader_image_load_store(ctx
) ||
1245 target
== GL_RENDERBUFFER
)
1248 buffer
[0] = _mesa_get_image_format_class(internalformat
);
1251 case GL_IMAGE_PIXEL_FORMAT
: {
1254 if (!_mesa_has_ARB_shader_image_load_store(ctx
) ||
1255 target
== GL_RENDERBUFFER
||
1256 !_mesa_is_shader_image_format_supported(ctx
, internalformat
))
1259 base_format
= _mesa_base_tex_format(ctx
, internalformat
);
1260 if (base_format
== -1)
1263 if (_mesa_is_enum_format_integer(internalformat
))
1264 buffer
[0] = _mesa_base_format_to_integer_format(base_format
);
1266 buffer
[0] = base_format
;
1270 case GL_IMAGE_PIXEL_TYPE
: {
1271 mesa_format image_format
;
1275 if (!_mesa_has_ARB_shader_image_load_store(ctx
) ||
1276 target
== GL_RENDERBUFFER
)
1279 image_format
= _mesa_get_shader_image_format(internalformat
);
1280 if (image_format
== MESA_FORMAT_NONE
)
1283 _mesa_uncompressed_format_to_type_and_comps(image_format
, &datatype
,
1288 buffer
[0] = datatype
;
1292 case GL_IMAGE_FORMAT_COMPATIBILITY_TYPE
: {
1293 if (!_mesa_has_ARB_shader_image_load_store(ctx
))
1296 if (!_mesa_legal_get_tex_level_parameter_target(ctx
, target
, true))
1299 /* From spec: "Equivalent to calling GetTexParameter with <value> set
1300 * to IMAGE_FORMAT_COMPATIBILITY_TYPE."
1302 * GetTexParameter just returns
1303 * tex_obj->ImageFormatCompatibilityType. We create a fake tex_obj
1304 * just with the purpose of getting the value.
1306 struct gl_texture_object
*tex_obj
= _mesa_new_texture_object(ctx
, 0, target
);
1307 buffer
[0] = tex_obj
->ImageFormatCompatibilityType
;
1308 _mesa_delete_texture_object(ctx
, tex_obj
);
1313 case GL_SIMULTANEOUS_TEXTURE_AND_DEPTH_TEST
:
1314 case GL_SIMULTANEOUS_TEXTURE_AND_STENCIL_TEST
:
1315 case GL_SIMULTANEOUS_TEXTURE_AND_DEPTH_WRITE
:
1316 case GL_SIMULTANEOUS_TEXTURE_AND_STENCIL_WRITE
:
1317 if (target
== GL_RENDERBUFFER
)
1320 if (!_mesa_is_depthstencil_format(internalformat
)) {
1321 if (((pname
== GL_SIMULTANEOUS_TEXTURE_AND_DEPTH_TEST
||
1322 pname
== GL_SIMULTANEOUS_TEXTURE_AND_DEPTH_WRITE
) &&
1323 !_mesa_is_depth_format(internalformat
)) ||
1324 ((pname
== GL_SIMULTANEOUS_TEXTURE_AND_STENCIL_TEST
||
1325 pname
== GL_SIMULTANEOUS_TEXTURE_AND_STENCIL_WRITE
) &&
1326 !_mesa_is_stencil_format(internalformat
)))
1330 ctx
->Driver
.QueryInternalFormat(ctx
, target
, internalformat
, pname
,
1334 case GL_TEXTURE_COMPRESSED
:
1338 case GL_TEXTURE_COMPRESSED_BLOCK_WIDTH
:
1342 case GL_TEXTURE_COMPRESSED_BLOCK_HEIGHT
:
1346 case GL_TEXTURE_COMPRESSED_BLOCK_SIZE
:
1350 case GL_CLEAR_BUFFER
:
1354 case GL_TEXTURE_VIEW
:
1358 case GL_VIEW_COMPATIBILITY_CLASS
:
1363 unreachable("bad param");
1367 if (bufSize
!= 0 && params
== NULL
) {
1368 /* Emit a warning to aid application debugging, but go ahead and do the
1369 * memcpy (and probably crash) anyway.
1372 "glGetInternalformativ(bufSize = %d, but params = NULL)",
1376 /* Copy the data from the temporary buffer to the buffer supplied by the
1377 * application. Clamp the size of the copy to the size supplied by the
1380 memcpy(params
, buffer
, MIN2(bufSize
, 16) * sizeof(GLint
));
1386 _mesa_GetInternalformati64v(GLenum target
, GLenum internalformat
,
1387 GLenum pname
, GLsizei bufSize
, GLint64
*params
)
1391 GLsizei realSize
= MIN2(bufSize
, 16);
1394 GET_CURRENT_CONTEXT(ctx
);
1396 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1398 if (!_mesa_has_ARB_internalformat_query2(ctx
)) {
1399 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetInternalformati64v");
1403 /* For SAMPLES there are cases where params needs to remain unmodified. As
1404 * no pname can return a negative value, we fill params32 with negative
1405 * values as reference values, that can be used to know what copy-back to
1407 memset(params32
, -1, 16);
1409 /* For GL_MAX_COMBINED_DIMENSIONS we need to get back 2 32-bit integers,
1410 * and at the same time we only need 2. So for that pname, we call the
1411 * 32-bit query with bufSize 2, except on the case of bufSize 0, that is
1412 * basically like asking to not get the value, but that is a caller
1414 if (pname
== GL_MAX_COMBINED_DIMENSIONS
&& bufSize
> 0)
1419 _mesa_GetInternalformativ(target
, internalformat
, pname
, callSize
, params32
);
1421 if (pname
== GL_MAX_COMBINED_DIMENSIONS
) {
1422 memcpy(params
, params32
, sizeof(GLint64
));
1424 for (i
= 0; i
< realSize
; i
++) {
1425 /* We only copy back the values that changed */
1426 if (params32
[i
] < 0)
1428 params
[i
] = (GLint64
) params32
[i
];