framework/replay: disable AA accounting when comparing with no tolerance
[piglit.git] / tests / spec / gl-3.0 / required-sized-texture-formats.c
blobe60b7f11b26d7dc6bd5ff142764dfbdeeac14a88
1 /* Copyright © 2011 Intel Corporation
3 * Permission is hereby granted, free of charge, to any person obtaining a
4 * copy of this software and associated documentation files (the "Software"),
5 * to deal in the Software without restriction, including without limitation
6 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
7 * and/or sell copies of the Software, and to permit persons to whom the
8 * Software is furnished to do so, subject to the following conditions:
10 * The above copyright notice and this permission notice (including the next
11 * paragraph) shall be included in all copies or substantial portions of the
12 * Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20 * IN THE SOFTWARE.
23 #include "piglit-util-gl.h"
24 #include "sized-internalformats.h"
26 /**
27 * @file required-sized-formats.c
29 * Tests that the required sized internal formats for GL 3.0 are
30 * exposed. See page 180 of the GL 3.0 pdf (20080923), "Required
31 * Texture Formats". Notably:
33 * "In addition, implementations are required to support the
34 * following sized internal formats. Requesting one of these
35 * internal formats for any texture type will allocate exactly
36 * the internal component sizes and types shown for that format
37 * in tables 3.16- 3.17:"
39 * Note that table 3.18, sized internal depth and stencil formats, is
40 * excluded.
42 * In GL 3.1 this is changed to allow increased precision for the
43 * required sized formats. From page 118 of the GL 3.1 core spec PDF
44 * (20090528):
46 * "In addition, implementations are required to support the
47 * following sized and compressed internal formats. Requesting
48 * one of these sized internal formats for any texture type will
49 * allocate at least the internal component sizes, and exactly
50 * the component types shown for that format in tables 3.12-
51 * 3.13: "
54 GLenum type_queries[CHANNELS] = {
55 GL_TEXTURE_RED_TYPE,
56 GL_TEXTURE_GREEN_TYPE,
57 GL_TEXTURE_BLUE_TYPE,
58 GL_TEXTURE_ALPHA_TYPE,
59 GL_TEXTURE_LUMINANCE_TYPE,
60 GL_TEXTURE_INTENSITY_TYPE,
61 GL_TEXTURE_DEPTH_TYPE,
62 GL_NONE,
65 GLenum size_queries[CHANNELS] = {
66 GL_TEXTURE_RED_SIZE,
67 GL_TEXTURE_GREEN_SIZE,
68 GL_TEXTURE_BLUE_SIZE,
69 GL_TEXTURE_ALPHA_SIZE,
70 GL_TEXTURE_LUMINANCE_SIZE,
71 GL_TEXTURE_INTENSITY_SIZE,
72 GL_TEXTURE_DEPTH_SIZE,
73 GL_TEXTURE_STENCIL_SIZE,
76 static int target_version;
78 enum piglit_result
79 piglit_display(void)
81 /* UNREACHED */
82 return PIGLIT_FAIL;
85 static void
86 GetTexLevelParameteriv(GLenum target, GLuint level, GLenum pname, GLint *value)
88 const bool compat_profile = !piglit_is_gles() &&
89 !piglit_is_core_profile;
91 if (!compat_profile) {
92 switch (pname) {
93 case GL_TEXTURE_LUMINANCE_SIZE:
94 case GL_TEXTURE_INTENSITY_SIZE:
95 case GL_TEXTURE_LUMINANCE_TYPE:
96 case GL_TEXTURE_INTENSITY_TYPE:
97 *value = 0;
98 return;
99 default:
100 break;
104 glGetTexLevelParameteriv(target, level, pname, value);
107 void
108 piglit_init(int argc, char **argv)
110 bool pass = true;
111 GLuint tex;
112 int i, c;
114 piglit_require_gl_version(target_version);
116 glGenTextures(1, &tex);
117 glBindTexture(GL_TEXTURE_2D, tex);
119 for (i = 0; required_formats[i].token != GL_NONE; i++) {
120 GLint sizes[CHANNELS];
121 GLint types[CHANNELS];
122 bool format_pass = true;
123 GLenum format, type;
124 const struct sized_internalformat *f;
126 if (!valid_for_gl_version(&required_formats[i], target_version))
127 continue;
129 f = get_sized_internalformat(required_formats[i].token);
130 if (!f) {
131 printf("Failed to get sized format for %s\n",
132 piglit_get_gl_enum_name(required_formats[i].token));
133 pass = false;
134 continue;
137 if (f->token == GL_DEPTH24_STENCIL8 ||
138 f->token == GL_DEPTH32F_STENCIL8) {
139 format = GL_DEPTH_STENCIL;
140 type = GL_UNSIGNED_INT_24_8;
141 } else if (get_channel_size(f, D)) {
142 format = GL_DEPTH_COMPONENT;
143 type = GL_FLOAT;
144 } else {
145 format = GL_RGBA;
146 type = GL_FLOAT;
148 /* Have to specify integer data for integer textures. */
149 for (c = R; c <= I; c++) {
150 if (get_channel_type(f, c) == GL_UNSIGNED_INT ||
151 get_channel_type(f, c) == GL_INT) {
152 format = GL_RGBA_INTEGER;
153 type = GL_UNSIGNED_INT;
154 break;
159 glTexImage2D(GL_TEXTURE_2D, 0, f->token,
160 1, 1, 0,
161 format, type, NULL);
163 if (glGetError() != 0) {
164 printf("Unexpected error creating %s texture\n",
165 piglit_get_gl_enum_name(f->token));
166 pass = false;
167 continue;
170 for (c = 0; c < CHANNELS; c++) {
171 GetTexLevelParameteriv(GL_TEXTURE_2D, 0,
172 size_queries[c], &sizes[c]);
174 if (c != S) {
175 GetTexLevelParameteriv(GL_TEXTURE_2D, 0,
176 type_queries[c],
177 &types[c]);
178 } else {
179 /* For stencil, there's no query for
180 * the type, so our table above
181 * records a type/size of unorm 8, and
182 * we'll just set the query result
183 * here to unorm so that we only look
184 * at the size.
186 if (sizes[c] != 0)
187 types[c] = GL_UNSIGNED_NORMALIZED;
188 else
189 types[c] = GL_NONE;
192 /* We use ~0 as the signal for the compressed
193 * texture formats. While the colors being
194 * interpolated across the 4x4 blocks have 8
195 * bits in them, the spec suggests reporting
196 * some approximate value less than that.
197 * From page 319 of the GL 3.0 spec:
199 * "Queries of value of TEXTURE RED SIZE,
200 * TEXTURE GREEN SIZE, [...] return the
201 * actual resolutions of the stored image
202 * array components, not the resolutions
203 * specified when the image array was
204 * defined. For texture images with a
205 * compressed internal format, the
206 * resolutions returned specify the
207 * component resolution of an
208 * uncompressed internal format that
209 * produces an image of roughly the same
210 * quality as the compressed image in
211 * question. Since the quality of the
212 * implementation’s compression algorithm
213 * is likely data-dependent, the returned
214 * component sizes should be treated only
215 * as rough approximations.
217 if (f->bits[c] == SCMP ||
218 f->bits[c] == UCMP) {
219 if (sizes[c] <= 0 || sizes[c] > 8)
220 format_pass = false;
221 } else if (target_version == 30) {
222 if (sizes[c] != get_channel_size(f, c)) {
223 if ((c == D || c == S) &&
224 get_channel_size(f, c) > 0) {
225 /* any non-zero size will do */
226 if (sizes[c] <= 0)
227 format_pass = false;
228 } else {
229 format_pass = false;
232 } else {
233 if (sizes[c] < get_channel_size(f, c)) {
234 format_pass = false;
238 if (types[c] != get_channel_type(f, c))
239 format_pass = false;
242 if (!format_pass) {
243 printf("format %s:\n",
244 piglit_get_gl_enum_name(f->token));
246 printf(" expected: ");
247 for (c = 0; c < CHANNELS; c++) {
248 print_bits(get_channel_size(f, c),
249 get_channel_type(f, c));
250 printf(" ");
252 printf("\n");
254 printf(" observed: ");
255 for (c = 0; c < CHANNELS; c++) {
256 print_bits(sizes[c], types[c]);
257 printf(" ");
259 printf("\n");
261 pass = false;
265 glDeleteTextures(1, &tex);
267 piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
270 PIGLIT_GL_TEST_CONFIG_BEGIN
271 setup_required_size_test(argc, argv, &config);
272 target_version = MAX2(config.supports_gl_compat_version,
273 config.supports_gl_core_version);
274 config.khr_no_error_support = PIGLIT_NO_ERRORS;
275 PIGLIT_GL_TEST_CONFIG_END