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 QuerySamplesForFormat driverfunc, for
33 * non-multisample-capable drivers. */
35 _mesa_query_samples_for_format(struct gl_context
*ctx
, GLenum target
,
36 GLenum internalFormat
, int samples
[16])
39 (void) internalFormat
;
48 _mesa_GetInternalformativ(GLenum target
, GLenum internalformat
, GLenum pname
,
49 GLsizei bufSize
, GLint
*params
)
53 GET_CURRENT_CONTEXT(ctx
);
55 ASSERT_OUTSIDE_BEGIN_END(ctx
);
57 if (!ctx
->Extensions
.ARB_internalformat_query
) {
58 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetInternalformativ");
62 assert(ctx
->Driver
.QuerySamplesForFormat
!= NULL
);
64 /* The ARB_internalformat_query spec says:
66 * "If the <target> parameter to GetInternalformativ is not one of
67 * TEXTURE_2D_MULTISAMPLE, TEXTURE_2D_MULTISAMPLE_ARRAY or RENDERBUFFER
68 * then an INVALID_ENUM error is generated."
74 case GL_TEXTURE_2D_MULTISAMPLE
:
75 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
76 /* These enums are only valid if ARB_texture_multisample is supported */
77 if (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_multisample
)
81 _mesa_error(ctx
, GL_INVALID_ENUM
,
82 "glGetInternalformativ(target=%s)",
83 _mesa_lookup_enum_by_nr(target
));
87 /* The ARB_internalformat_query spec says:
89 * "If the <internalformat> parameter to GetInternalformativ is not
90 * color-, depth- or stencil-renderable, then an INVALID_ENUM error is
93 * Page 243 of the GLES 3.0.4 spec says this for GetInternalformativ:
95 * "internalformat must be color-renderable, depth-renderable or
96 * stencilrenderable (as defined in section 4.4.4)."
98 * Section 4.4.4 on page 212 of the same spec says:
100 * "An internal format is color-renderable if it is one of the
101 * formats from table 3.13 noted as color-renderable or if it
102 * is unsized format RGBA or RGB."
104 * Therefore, we must accept GL_RGB and GL_RGBA here.
106 if (internalformat
!= GL_RGB
&& internalformat
!= GL_RGBA
&&
107 _mesa_base_fbo_format(ctx
, internalformat
) == 0) {
108 _mesa_error(ctx
, GL_INVALID_ENUM
,
109 "glGetInternalformativ(internalformat=%s)",
110 _mesa_lookup_enum_by_nr(internalformat
));
114 /* The ARB_internalformat_query spec says:
116 * "If the <bufSize> parameter to GetInternalformativ is negative, then
117 * an INVALID_VALUE error is generated."
120 _mesa_error(ctx
, GL_INVALID_VALUE
,
121 "glGetInternalformativ(target=%s)",
122 _mesa_lookup_enum_by_nr(target
));
128 count
= ctx
->Driver
.QuerySamplesForFormat(ctx
, target
,
129 internalformat
, buffer
);
131 case GL_NUM_SAMPLE_COUNTS
: {
132 if (_mesa_is_gles3(ctx
) && _mesa_is_enum_format_integer(internalformat
)) {
133 /* From GL ES 3.0 specification, section 6.1.15 page 236: "Since
134 * multisampling is not supported for signed and unsigned integer
135 * internal formats, the value of NUM_SAMPLE_COUNTS will be zero
143 /* The driver can return 0, and we should pass that along to the
144 * application. The ARB decided that ARB_internalformat_query should
145 * behave as ARB_internalformat_query2 in this situation.
147 * The ARB_internalformat_query2 spec says:
149 * "- NUM_SAMPLE_COUNTS: The number of sample counts that would be
150 * returned by querying SAMPLES is returned in <params>.
151 * * If <internalformat> is not color-renderable,
152 * depth-renderable, or stencil-renderable (as defined in
153 * section 4.4.4), or if <target> does not support multiple
154 * samples (ie other than TEXTURE_2D_MULTISAMPLE,
155 * TEXTURE_2D_MULTISAMPLE_ARRAY, or RENDERBUFFER), 0 is
158 num_samples
= ctx
->Driver
.QuerySamplesForFormat(ctx
, target
, internalformat
, buffer
);
160 /* QuerySamplesForFormat writes some stuff to buffer, so we have to
161 * separately over-write it with the requested value.
163 buffer
[0] = (GLint
) num_samples
;
169 _mesa_error(ctx
, GL_INVALID_ENUM
,
170 "glGetInternalformativ(pname=%s)",
171 _mesa_lookup_enum_by_nr(pname
));
175 if (bufSize
!= 0 && params
== NULL
) {
176 /* Emit a warning to aid application debugging, but go ahead and do the
177 * memcpy (and probably crash) anyway.
180 "glGetInternalformativ(bufSize = %d, but params = NULL)",
184 /* Copy the data from the temporary buffer to the buffer supplied by the
185 * application. Clamp the size of the copy to the size supplied by the
188 memcpy(params
, buffer
, MIN2(count
, bufSize
) * sizeof(GLint
));