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"
34 _is_renderable(struct gl_context
*ctx
, GLenum internalformat
)
36 /* Section 4.4.4 on page 212 of the GLES 3.0.4 spec says:
38 * "An internal format is color-renderable if it is one of the
39 * formats from table 3.13 noted as color-renderable or if it
40 * is unsized format RGBA or RGB."
42 * Therefore, we must accept GL_RGB and GL_RGBA here.
44 if (internalformat
!= GL_RGB
&& internalformat
!= GL_RGBA
&&
45 _mesa_base_fbo_format(ctx
, internalformat
) == 0)
51 /* Handles the cases where either ARB_internalformat_query or
52 * ARB_internalformat_query2 have to return an error.
55 _legal_parameters(struct gl_context
*ctx
, GLenum target
, GLenum internalformat
,
56 GLenum pname
, GLsizei bufSize
, GLint
*params
)
59 bool query2
= _mesa_has_ARB_internalformat_query2(ctx
);
61 /* The ARB_internalformat_query2 spec says:
63 * "The INVALID_ENUM error is generated if the <target> parameter to
64 * GetInternalformati*v is not one of the targets listed in Table 6.xx.
68 case GL_TEXTURE_1D_ARRAY
:
70 case GL_TEXTURE_2D_ARRAY
:
72 case GL_TEXTURE_CUBE_MAP
:
73 case GL_TEXTURE_CUBE_MAP_ARRAY
:
74 case GL_TEXTURE_RECTANGLE
:
75 case GL_TEXTURE_BUFFER
:
77 /* The ARB_internalformat_query spec says:
79 * "If the <target> parameter to GetInternalformativ is not one of
80 * TEXTURE_2D_MULTISAMPLE, TEXTURE_2D_MULTISAMPLE_ARRAY
81 * or RENDERBUFFER then an INVALID_ENUM error is generated.
83 _mesa_error(ctx
, GL_INVALID_ENUM
,
84 "glGetInternalformativ(target=%s)",
85 _mesa_enum_to_string(target
));
94 case GL_TEXTURE_2D_MULTISAMPLE
:
95 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
96 /* The non-existence of ARB_texture_multisample is treated in
97 * ARB_internalformat_query implementation like an error.
100 !(_mesa_has_ARB_texture_multisample(ctx
) || _mesa_is_gles31(ctx
))) {
101 _mesa_error(ctx
, GL_INVALID_ENUM
,
102 "glGetInternalformativ(target=%s)",
103 _mesa_enum_to_string(target
));
110 _mesa_error(ctx
, GL_INVALID_ENUM
,
111 "glGetInternalformativ(target=%s)",
112 _mesa_enum_to_string(target
));
117 /* The ARB_internalformat_query2 spec says:
119 * "The INVALID_ENUM error is generated if the <pname> parameter is
120 * not one of the listed possibilities.
124 case GL_NUM_SAMPLE_COUNTS
:
127 case GL_SRGB_DECODE_ARB
:
128 /* The ARB_internalformat_query2 spec says:
130 * "If ARB_texture_sRGB_decode or EXT_texture_sRGB_decode or
131 * equivalent functionality is not supported, queries for the
132 * SRGB_DECODE_ARB <pname> set the INVALID_ENUM error.
134 if (!_mesa_has_EXT_texture_sRGB_decode(ctx
)) {
135 _mesa_error(ctx
, GL_INVALID_ENUM
,
136 "glGetInternalformativ(pname=%s)",
137 _mesa_enum_to_string(pname
));
141 case GL_INTERNALFORMAT_SUPPORTED
:
142 case GL_INTERNALFORMAT_PREFERRED
:
143 case GL_INTERNALFORMAT_RED_SIZE
:
144 case GL_INTERNALFORMAT_GREEN_SIZE
:
145 case GL_INTERNALFORMAT_BLUE_SIZE
:
146 case GL_INTERNALFORMAT_ALPHA_SIZE
:
147 case GL_INTERNALFORMAT_DEPTH_SIZE
:
148 case GL_INTERNALFORMAT_STENCIL_SIZE
:
149 case GL_INTERNALFORMAT_SHARED_SIZE
:
150 case GL_INTERNALFORMAT_RED_TYPE
:
151 case GL_INTERNALFORMAT_GREEN_TYPE
:
152 case GL_INTERNALFORMAT_BLUE_TYPE
:
153 case GL_INTERNALFORMAT_ALPHA_TYPE
:
154 case GL_INTERNALFORMAT_DEPTH_TYPE
:
155 case GL_INTERNALFORMAT_STENCIL_TYPE
:
160 case GL_MAX_COMBINED_DIMENSIONS
:
161 case GL_COLOR_COMPONENTS
:
162 case GL_DEPTH_COMPONENTS
:
163 case GL_STENCIL_COMPONENTS
:
164 case GL_COLOR_RENDERABLE
:
165 case GL_DEPTH_RENDERABLE
:
166 case GL_STENCIL_RENDERABLE
:
167 case GL_FRAMEBUFFER_RENDERABLE
:
168 case GL_FRAMEBUFFER_RENDERABLE_LAYERED
:
169 case GL_FRAMEBUFFER_BLEND
:
171 case GL_READ_PIXELS_FORMAT
:
172 case GL_READ_PIXELS_TYPE
:
173 case GL_TEXTURE_IMAGE_FORMAT
:
174 case GL_TEXTURE_IMAGE_TYPE
:
175 case GL_GET_TEXTURE_IMAGE_FORMAT
:
176 case GL_GET_TEXTURE_IMAGE_TYPE
:
178 case GL_MANUAL_GENERATE_MIPMAP
:
179 case GL_AUTO_GENERATE_MIPMAP
:
180 case GL_COLOR_ENCODING
:
184 case GL_VERTEX_TEXTURE
:
185 case GL_TESS_CONTROL_TEXTURE
:
186 case GL_TESS_EVALUATION_TEXTURE
:
187 case GL_GEOMETRY_TEXTURE
:
188 case GL_FRAGMENT_TEXTURE
:
189 case GL_COMPUTE_TEXTURE
:
190 case GL_TEXTURE_SHADOW
:
191 case GL_TEXTURE_GATHER
:
192 case GL_TEXTURE_GATHER_SHADOW
:
193 case GL_SHADER_IMAGE_LOAD
:
194 case GL_SHADER_IMAGE_STORE
:
195 case GL_SHADER_IMAGE_ATOMIC
:
196 case GL_IMAGE_TEXEL_SIZE
:
197 case GL_IMAGE_COMPATIBILITY_CLASS
:
198 case GL_IMAGE_PIXEL_FORMAT
:
199 case GL_IMAGE_PIXEL_TYPE
:
200 case GL_IMAGE_FORMAT_COMPATIBILITY_TYPE
:
201 case GL_SIMULTANEOUS_TEXTURE_AND_DEPTH_TEST
:
202 case GL_SIMULTANEOUS_TEXTURE_AND_STENCIL_TEST
:
203 case GL_SIMULTANEOUS_TEXTURE_AND_DEPTH_WRITE
:
204 case GL_SIMULTANEOUS_TEXTURE_AND_STENCIL_WRITE
:
205 case GL_TEXTURE_COMPRESSED
:
206 case GL_TEXTURE_COMPRESSED_BLOCK_WIDTH
:
207 case GL_TEXTURE_COMPRESSED_BLOCK_HEIGHT
:
208 case GL_TEXTURE_COMPRESSED_BLOCK_SIZE
:
209 case GL_CLEAR_BUFFER
:
210 case GL_TEXTURE_VIEW
:
211 case GL_VIEW_COMPATIBILITY_CLASS
:
212 /* The ARB_internalformat_query spec says:
214 * "If the <pname> parameter to GetInternalformativ is not SAMPLES
215 * or NUM_SAMPLE_COUNTS, then an INVALID_ENUM error is generated."
218 _mesa_error(ctx
, GL_INVALID_ENUM
,
219 "glGetInternalformativ(pname=%s)",
220 _mesa_enum_to_string(pname
));
227 _mesa_error(ctx
, GL_INVALID_ENUM
,
228 "glGetInternalformativ(pname=%s)",
229 _mesa_enum_to_string(pname
));
233 /* The ARB_internalformat_query spec says:
235 * "If the <bufSize> parameter to GetInternalformativ is negative, then
236 * an INVALID_VALUE error is generated."
238 * Nothing is said in ARB_internalformat_query2 but we assume the same.
241 _mesa_error(ctx
, GL_INVALID_VALUE
,
242 "glGetInternalformativ(target=%s)",
243 _mesa_enum_to_string(target
));
247 /* The ARB_internalformat_query spec says:
249 * "If the <internalformat> parameter to GetInternalformativ is not
250 * color-, depth- or stencil-renderable, then an INVALID_ENUM error is
253 if (!query2
&& !_is_renderable(ctx
, internalformat
)) {
254 _mesa_error(ctx
, GL_INVALID_ENUM
,
255 "glGetInternalformativ(internalformat=%s)",
256 _mesa_enum_to_string(internalformat
));
263 /* Sets the appropriate "unsupported" response as defined by the
264 * ARB_internalformat_query2 spec for each each <pname>.
267 _set_default_response(GLenum pname
, GLint buffer
[16])
269 /* The ARB_internalformat_query2 defines which is the reponse best
270 * representing "not supported" or "not applicable" for each <pname>.
273 * - size- or count-based queries will return zero,
274 * - support-, format- or type-based queries will return NONE,
275 * - boolean-based queries will return FALSE, and
276 * - list-based queries return no entries."
282 case GL_MAX_COMBINED_DIMENSIONS
:
283 case GL_NUM_SAMPLE_COUNTS
:
284 case GL_INTERNALFORMAT_RED_SIZE
:
285 case GL_INTERNALFORMAT_GREEN_SIZE
:
286 case GL_INTERNALFORMAT_BLUE_SIZE
:
287 case GL_INTERNALFORMAT_ALPHA_SIZE
:
288 case GL_INTERNALFORMAT_DEPTH_SIZE
:
289 case GL_INTERNALFORMAT_STENCIL_SIZE
:
290 case GL_INTERNALFORMAT_SHARED_SIZE
:
295 case GL_IMAGE_TEXEL_SIZE
:
296 case GL_TEXTURE_COMPRESSED_BLOCK_WIDTH
:
297 case GL_TEXTURE_COMPRESSED_BLOCK_HEIGHT
:
298 case GL_TEXTURE_COMPRESSED_BLOCK_SIZE
:
302 case GL_INTERNALFORMAT_PREFERRED
:
303 case GL_INTERNALFORMAT_RED_TYPE
:
304 case GL_INTERNALFORMAT_GREEN_TYPE
:
305 case GL_INTERNALFORMAT_BLUE_TYPE
:
306 case GL_INTERNALFORMAT_ALPHA_TYPE
:
307 case GL_INTERNALFORMAT_DEPTH_TYPE
:
308 case GL_INTERNALFORMAT_STENCIL_TYPE
:
309 case GL_FRAMEBUFFER_RENDERABLE
:
310 case GL_FRAMEBUFFER_RENDERABLE_LAYERED
:
311 case GL_FRAMEBUFFER_BLEND
:
313 case GL_READ_PIXELS_FORMAT
:
314 case GL_READ_PIXELS_TYPE
:
315 case GL_TEXTURE_IMAGE_FORMAT
:
316 case GL_TEXTURE_IMAGE_TYPE
:
317 case GL_GET_TEXTURE_IMAGE_FORMAT
:
318 case GL_GET_TEXTURE_IMAGE_TYPE
:
319 case GL_MANUAL_GENERATE_MIPMAP
:
320 case GL_AUTO_GENERATE_MIPMAP
:
321 case GL_COLOR_ENCODING
:
324 case GL_SRGB_DECODE_ARB
:
326 case GL_VERTEX_TEXTURE
:
327 case GL_TESS_CONTROL_TEXTURE
:
328 case GL_TESS_EVALUATION_TEXTURE
:
329 case GL_GEOMETRY_TEXTURE
:
330 case GL_FRAGMENT_TEXTURE
:
331 case GL_COMPUTE_TEXTURE
:
332 case GL_TEXTURE_SHADOW
:
333 case GL_TEXTURE_GATHER
:
334 case GL_TEXTURE_GATHER_SHADOW
:
335 case GL_SHADER_IMAGE_LOAD
:
336 case GL_SHADER_IMAGE_STORE
:
337 case GL_SHADER_IMAGE_ATOMIC
:
338 case GL_IMAGE_COMPATIBILITY_CLASS
:
339 case GL_IMAGE_PIXEL_FORMAT
:
340 case GL_IMAGE_PIXEL_TYPE
:
341 case GL_IMAGE_FORMAT_COMPATIBILITY_TYPE
:
342 case GL_SIMULTANEOUS_TEXTURE_AND_DEPTH_TEST
:
343 case GL_SIMULTANEOUS_TEXTURE_AND_STENCIL_TEST
:
344 case GL_SIMULTANEOUS_TEXTURE_AND_DEPTH_WRITE
:
345 case GL_SIMULTANEOUS_TEXTURE_AND_STENCIL_WRITE
:
346 case GL_CLEAR_BUFFER
:
347 case GL_TEXTURE_VIEW
:
348 case GL_VIEW_COMPATIBILITY_CLASS
:
352 case GL_INTERNALFORMAT_SUPPORTED
:
353 case GL_COLOR_COMPONENTS
:
354 case GL_DEPTH_COMPONENTS
:
355 case GL_STENCIL_COMPONENTS
:
356 case GL_COLOR_RENDERABLE
:
357 case GL_DEPTH_RENDERABLE
:
358 case GL_STENCIL_RENDERABLE
:
360 case GL_TEXTURE_COMPRESSED
:
361 buffer
[0] = GL_FALSE
;
365 unreachable("invalid 'pname'");
370 _is_target_supported(struct gl_context
*ctx
, GLenum target
)
372 /* The ARB_internalformat_query2 spec says:
374 * "if a particular type of <target> is not supported by the
375 * implementation the "unsupported" answer should be given.
376 * This is not an error."
384 if (!_mesa_is_desktop_gl(ctx
))
388 case GL_TEXTURE_1D_ARRAY
:
389 if (!_mesa_has_EXT_texture_array(ctx
))
393 case GL_TEXTURE_2D_ARRAY
:
394 if (!(_mesa_has_EXT_texture_array(ctx
) || _mesa_is_gles3(ctx
)))
398 case GL_TEXTURE_CUBE_MAP
:
399 if (!_mesa_has_ARB_texture_cube_map(ctx
))
403 case GL_TEXTURE_CUBE_MAP_ARRAY
:
404 if (!_mesa_has_ARB_texture_cube_map_array(ctx
))
408 case GL_TEXTURE_RECTANGLE
:
409 if (!_mesa_has_NV_texture_rectangle(ctx
))
413 case GL_TEXTURE_BUFFER
:
414 if (!_mesa_has_ARB_texture_buffer_object(ctx
))
418 case GL_RENDERBUFFER
:
419 if (!(_mesa_has_ARB_framebuffer_object(ctx
) ||
420 _mesa_is_gles3(ctx
)))
424 case GL_TEXTURE_2D_MULTISAMPLE
:
425 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
426 if (!(_mesa_has_ARB_texture_multisample(ctx
) ||
427 _mesa_is_gles31(ctx
)))
432 unreachable("invalid target");
438 /* default implementation of QueryInternalFormat driverfunc, for
439 * drivers not implementing ARB_internalformat_query2.
442 _mesa_query_internal_format_default(struct gl_context
*ctx
, GLenum target
,
443 GLenum internalFormat
, GLenum pname
,
448 (void) internalFormat
;
452 case GL_NUM_SAMPLE_COUNTS
:
456 _set_default_response(pname
, params
);
462 _mesa_GetInternalformativ(GLenum target
, GLenum internalformat
, GLenum pname
,
463 GLsizei bufSize
, GLint
*params
)
466 GET_CURRENT_CONTEXT(ctx
);
468 ASSERT_OUTSIDE_BEGIN_END(ctx
);
470 /* ARB_internalformat_query is also mandatory for ARB_internalformat_query2 */
471 if (!(_mesa_has_ARB_internalformat_query(ctx
) ||
472 _mesa_is_gles3(ctx
))) {
473 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetInternalformativ");
477 assert(ctx
->Driver
.QueryInternalFormat
!= NULL
);
479 if (!_legal_parameters(ctx
, target
, internalformat
, pname
, bufSize
, params
))
482 /* initialize the contents of the temporary buffer */
483 memcpy(buffer
, params
, MIN2(bufSize
, 16) * sizeof(GLint
));
485 /* Use the 'unsupported' response defined by the spec for every pname
486 * as the default answer.
488 _set_default_response(pname
, buffer
);
490 if (!_is_target_supported(ctx
, target
))
496 case GL_NUM_SAMPLE_COUNTS
:
497 /* The ARB_internalformat_query2 sets the response as 'unsupported' for
498 * SAMPLES and NUM_SAMPLE_COUNTS:
500 * "If <internalformat> is not color-renderable, depth-renderable, or
501 * stencil-renderable (as defined in section 4.4.4), or if <target>
502 * does not support multiple samples (ie other than
503 * TEXTURE_2D_MULTISAMPLE, TEXTURE_2D_MULTISAMPLE_ARRAY,
506 if ((target
!= GL_RENDERBUFFER
&&
507 target
!= GL_TEXTURE_2D_MULTISAMPLE
&&
508 target
!= GL_TEXTURE_2D_MULTISAMPLE_ARRAY
) ||
509 !_is_renderable(ctx
, internalformat
))
512 /* The GL ES 3.0 specification, section 6.1.15 page 236 says:
514 * "Since multisampling is not supported for signed and unsigned
515 * integer internal formats, the value of NUM_SAMPLE_COUNTS will be
516 * zero for such formats.
518 if (pname
== GL_NUM_SAMPLE_COUNTS
&& ctx
->API
== API_OPENGLES2
&&
519 ctx
->Version
== 30 && _mesa_is_enum_format_integer(internalformat
)) {
523 ctx
->Driver
.QueryInternalFormat(ctx
, target
, internalformat
, pname
,
527 case GL_INTERNALFORMAT_SUPPORTED
:
531 case GL_INTERNALFORMAT_PREFERRED
:
535 case GL_INTERNALFORMAT_RED_SIZE
:
539 case GL_INTERNALFORMAT_GREEN_SIZE
:
543 case GL_INTERNALFORMAT_BLUE_SIZE
:
547 case GL_INTERNALFORMAT_ALPHA_SIZE
:
551 case GL_INTERNALFORMAT_DEPTH_SIZE
:
555 case GL_INTERNALFORMAT_STENCIL_SIZE
:
559 case GL_INTERNALFORMAT_SHARED_SIZE
:
563 case GL_INTERNALFORMAT_RED_TYPE
:
567 case GL_INTERNALFORMAT_GREEN_TYPE
:
571 case GL_INTERNALFORMAT_BLUE_TYPE
:
575 case GL_INTERNALFORMAT_ALPHA_TYPE
:
579 case GL_INTERNALFORMAT_DEPTH_TYPE
:
583 case GL_INTERNALFORMAT_STENCIL_TYPE
:
603 case GL_MAX_COMBINED_DIMENSIONS
:
607 case GL_COLOR_COMPONENTS
:
611 case GL_DEPTH_COMPONENTS
:
615 case GL_STENCIL_COMPONENTS
:
619 case GL_COLOR_RENDERABLE
:
623 case GL_DEPTH_RENDERABLE
:
627 case GL_STENCIL_RENDERABLE
:
631 case GL_FRAMEBUFFER_RENDERABLE
:
635 case GL_FRAMEBUFFER_RENDERABLE_LAYERED
:
639 case GL_FRAMEBUFFER_BLEND
:
647 case GL_READ_PIXELS_FORMAT
:
651 case GL_READ_PIXELS_TYPE
:
655 case GL_TEXTURE_IMAGE_FORMAT
:
659 case GL_TEXTURE_IMAGE_TYPE
:
663 case GL_GET_TEXTURE_IMAGE_FORMAT
:
667 case GL_GET_TEXTURE_IMAGE_TYPE
:
675 case GL_MANUAL_GENERATE_MIPMAP
:
679 case GL_AUTO_GENERATE_MIPMAP
:
683 case GL_COLOR_ENCODING
:
695 case GL_SRGB_DECODE_ARB
:
703 case GL_VERTEX_TEXTURE
:
707 case GL_TESS_CONTROL_TEXTURE
:
711 case GL_TESS_EVALUATION_TEXTURE
:
715 case GL_GEOMETRY_TEXTURE
:
719 case GL_FRAGMENT_TEXTURE
:
723 case GL_COMPUTE_TEXTURE
:
727 case GL_TEXTURE_SHADOW
:
731 case GL_TEXTURE_GATHER
:
735 case GL_TEXTURE_GATHER_SHADOW
:
739 case GL_SHADER_IMAGE_LOAD
:
743 case GL_SHADER_IMAGE_STORE
:
747 case GL_SHADER_IMAGE_ATOMIC
:
751 case GL_IMAGE_TEXEL_SIZE
:
755 case GL_IMAGE_COMPATIBILITY_CLASS
:
759 case GL_IMAGE_PIXEL_FORMAT
:
763 case GL_IMAGE_PIXEL_TYPE
:
767 case GL_IMAGE_FORMAT_COMPATIBILITY_TYPE
:
771 case GL_SIMULTANEOUS_TEXTURE_AND_DEPTH_TEST
:
775 case GL_SIMULTANEOUS_TEXTURE_AND_STENCIL_TEST
:
779 case GL_SIMULTANEOUS_TEXTURE_AND_DEPTH_WRITE
:
783 case GL_SIMULTANEOUS_TEXTURE_AND_STENCIL_WRITE
:
787 case GL_TEXTURE_COMPRESSED
:
791 case GL_TEXTURE_COMPRESSED_BLOCK_WIDTH
:
795 case GL_TEXTURE_COMPRESSED_BLOCK_HEIGHT
:
799 case GL_TEXTURE_COMPRESSED_BLOCK_SIZE
:
803 case GL_CLEAR_BUFFER
:
807 case GL_TEXTURE_VIEW
:
811 case GL_VIEW_COMPATIBILITY_CLASS
:
816 unreachable("bad param");
820 if (bufSize
!= 0 && params
== NULL
) {
821 /* Emit a warning to aid application debugging, but go ahead and do the
822 * memcpy (and probably crash) anyway.
825 "glGetInternalformativ(bufSize = %d, but params = NULL)",
829 /* Copy the data from the temporary buffer to the buffer supplied by the
830 * application. Clamp the size of the copy to the size supplied by the
833 memcpy(params
, buffer
, MIN2(bufSize
, 16) * sizeof(GLint
));
839 _mesa_GetInternalformati64v(GLenum target
, GLenum internalformat
,
840 GLenum pname
, GLsizei bufSize
, GLint64
*params
)
842 GET_CURRENT_CONTEXT(ctx
);
844 ASSERT_OUTSIDE_BEGIN_END(ctx
);
846 if (!_mesa_has_ARB_internalformat_query2(ctx
)) {
847 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetInternalformati64v");
851 _mesa_debug(ctx
, "glGetInternalformati64v() not implemented");