mesa: Completely remove QuerySamplesForFormat from driver func table
[mesa.git] / src / mesa / main / formatquery.c
1 /*
2 * Copyright © 2012 Intel Corporation
3 *
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:
10 *
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
13 * Software.
14 *
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.
22 */
23
24 #include "mtypes.h"
25 #include "context.h"
26 #include "glformats.h"
27 #include "macros.h"
28 #include "enums.h"
29 #include "fbobject.h"
30 #include "formatquery.h"
31
32 /* default implementation of QueryInternalFormat driverfunc, for
33 * drivers not implementing ARB_internalformat_query2.
34 */
35 void
36 _mesa_query_internal_format_default(struct gl_context *ctx, GLenum target,
37 GLenum internalFormat, GLenum pname,
38 GLint *params)
39 {
40 (void) ctx;
41 (void) target;
42 (void) internalFormat;
43
44 switch (pname) {
45 case GL_SAMPLES:
46 case GL_NUM_SAMPLE_COUNTS:
47 params[0] = 1;
48 break;
49 default:
50 /* @TODO: handle default values for all the different pnames. */
51 break;
52 }
53 }
54
55 void GLAPIENTRY
56 _mesa_GetInternalformativ(GLenum target, GLenum internalformat, GLenum pname,
57 GLsizei bufSize, GLint *params)
58 {
59 GLint buffer[16];
60 GET_CURRENT_CONTEXT(ctx);
61
62 ASSERT_OUTSIDE_BEGIN_END(ctx);
63
64 if (!ctx->Extensions.ARB_internalformat_query) {
65 _mesa_error(ctx, GL_INVALID_OPERATION, "glGetInternalformativ");
66 return;
67 }
68
69 assert(ctx->Driver.QueryInternalFormat != NULL);
70
71 /* The ARB_internalformat_query spec says:
72 *
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."
76 */
77 switch (target) {
78 case GL_RENDERBUFFER:
79 break;
80
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) ||
86 _mesa_is_gles31(ctx))
87 break;
88
89 default:
90 _mesa_error(ctx, GL_INVALID_ENUM,
91 "glGetInternalformativ(target=%s)",
92 _mesa_enum_to_string(target));
93 return;
94 }
95
96 /* The ARB_internalformat_query spec says:
97 *
98 * "If the <internalformat> parameter to GetInternalformativ is not
99 * color-, depth- or stencil-renderable, then an INVALID_ENUM error is
100 * generated."
101 *
102 * Page 243 of the GLES 3.0.4 spec says this for GetInternalformativ:
103 *
104 * "internalformat must be color-renderable, depth-renderable or
105 * stencilrenderable (as defined in section 4.4.4)."
106 *
107 * Section 4.4.4 on page 212 of the same spec says:
108 *
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."
112 *
113 * Therefore, we must accept GL_RGB and GL_RGBA here.
114 */
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));
120 return;
121 }
122
123 /* The ARB_internalformat_query spec says:
124 *
125 * "If the <bufSize> parameter to GetInternalformativ is negative, then
126 * an INVALID_VALUE error is generated."
127 */
128 if (bufSize < 0) {
129 _mesa_error(ctx, GL_INVALID_VALUE,
130 "glGetInternalformativ(target=%s)",
131 _mesa_enum_to_string(target));
132 return;
133 }
134
135 /* initialize the contents of the temporary buffer */
136 memcpy(buffer, params, MIN2(bufSize, 16) * sizeof(GLint));
137
138 switch (pname) {
139 case GL_SAMPLES:
140 ctx->Driver.QueryInternalFormat(ctx, target, internalformat, pname,
141 buffer);
142 break;
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
149 * for such formats.
150 *
151 * Such a restriction no longer exists in GL ES 3.1.
152 */
153 buffer[0] = 0;
154 } else {
155 ctx->Driver.QueryInternalFormat(ctx, target, internalformat, pname,
156 buffer);
157 }
158 break;
159 }
160 default:
161 _mesa_error(ctx, GL_INVALID_ENUM,
162 "glGetInternalformativ(pname=%s)",
163 _mesa_enum_to_string(pname));
164 return;
165 }
166
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.
170 */
171 _mesa_warning(ctx,
172 "glGetInternalformativ(bufSize = %d, but params = NULL)",
173 bufSize);
174 }
175
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
178 * application.
179 */
180 memcpy(params, buffer, MIN2(bufSize, 16) * sizeof(GLint));
181
182 return;
183 }