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"
32 /* default implementation of QueryInternalFormat driverfunc, for
33 * drivers not implementing ARB_internalformat_query2.
36 _mesa_query_internal_format_default(struct gl_context
*ctx
, GLenum target
,
37 GLenum internalFormat
, GLenum pname
,
42 (void) internalFormat
;
46 case GL_NUM_SAMPLE_COUNTS
:
50 /* @TODO: handle default values for all the different pnames. */
56 _mesa_GetInternalformativ(GLenum target
, GLenum internalformat
, GLenum pname
,
57 GLsizei bufSize
, GLint
*params
)
60 GET_CURRENT_CONTEXT(ctx
);
62 ASSERT_OUTSIDE_BEGIN_END(ctx
);
64 if (!ctx
->Extensions
.ARB_internalformat_query
) {
65 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetInternalformativ");
69 assert(ctx
->Driver
.QueryInternalFormat
!= NULL
);
71 /* The ARB_internalformat_query spec says:
73 * "If the <target> parameter to GetInternalformativ is not one of
74 * TEXTURE_2D_MULTISAMPLE, TEXTURE_2D_MULTISAMPLE_ARRAY or RENDERBUFFER
75 * then an INVALID_ENUM error is generated."
81 case GL_TEXTURE_2D_MULTISAMPLE
:
82 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
83 /* These enums are only valid if ARB_texture_multisample is supported */
84 if ((_mesa_is_desktop_gl(ctx
) &&
85 ctx
->Extensions
.ARB_texture_multisample
) ||
90 _mesa_error(ctx
, GL_INVALID_ENUM
,
91 "glGetInternalformativ(target=%s)",
92 _mesa_enum_to_string(target
));
96 /* The ARB_internalformat_query spec says:
98 * "If the <internalformat> parameter to GetInternalformativ is not
99 * color-, depth- or stencil-renderable, then an INVALID_ENUM error is
102 * Page 243 of the GLES 3.0.4 spec says this for GetInternalformativ:
104 * "internalformat must be color-renderable, depth-renderable or
105 * stencilrenderable (as defined in section 4.4.4)."
107 * Section 4.4.4 on page 212 of the same spec says:
109 * "An internal format is color-renderable if it is one of the
110 * formats from table 3.13 noted as color-renderable or if it
111 * is unsized format RGBA or RGB."
113 * Therefore, we must accept GL_RGB and GL_RGBA here.
115 if (internalformat
!= GL_RGB
&& internalformat
!= GL_RGBA
&&
116 _mesa_base_fbo_format(ctx
, internalformat
) == 0) {
117 _mesa_error(ctx
, GL_INVALID_ENUM
,
118 "glGetInternalformativ(internalformat=%s)",
119 _mesa_enum_to_string(internalformat
));
123 /* The ARB_internalformat_query spec says:
125 * "If the <bufSize> parameter to GetInternalformativ is negative, then
126 * an INVALID_VALUE error is generated."
129 _mesa_error(ctx
, GL_INVALID_VALUE
,
130 "glGetInternalformativ(target=%s)",
131 _mesa_enum_to_string(target
));
135 /* initialize the contents of the temporary buffer */
136 memcpy(buffer
, params
, MIN2(bufSize
, 16) * sizeof(GLint
));
140 ctx
->Driver
.QueryInternalFormat(ctx
, target
, internalformat
, pname
,
143 case GL_NUM_SAMPLE_COUNTS
: {
144 if ((ctx
->API
== API_OPENGLES2
&& ctx
->Version
== 30) &&
145 _mesa_is_enum_format_integer(internalformat
)) {
146 /* From GL ES 3.0 specification, section 6.1.15 page 236: "Since
147 * multisampling is not supported for signed and unsigned integer
148 * internal formats, the value of NUM_SAMPLE_COUNTS will be zero
151 * Such a restriction no longer exists in GL ES 3.1.
155 ctx
->Driver
.QueryInternalFormat(ctx
, target
, internalformat
, pname
,
161 _mesa_error(ctx
, GL_INVALID_ENUM
,
162 "glGetInternalformativ(pname=%s)",
163 _mesa_enum_to_string(pname
));
167 if (bufSize
!= 0 && params
== NULL
) {
168 /* Emit a warning to aid application debugging, but go ahead and do the
169 * memcpy (and probably crash) anyway.
172 "glGetInternalformativ(bufSize = %d, but params = NULL)",
176 /* Copy the data from the temporary buffer to the buffer supplied by the
177 * application. Clamp the size of the copy to the size supplied by the
180 memcpy(params
, buffer
, MIN2(bufSize
, 16) * sizeof(GLint
));