fix the spelling in whole piglit
[piglit.git] / tests / spec / arb_internalformat_query2 / format-components.c
blob70ba7dc2f8cb56d555dfdc7f4424c1284b63053b
1 /*
2 * Copyright © 2015 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
13 * Software.
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 DEALINGS
21 * IN THE SOFTWARE.
24 /**
25 * \file format-components.c
27 * Tests if the values returned by:
29 * * COLOR_COMPONENTS
30 * * STENCIL_COMPONENTS
31 * * DEPTH_COMPONENTS
33 * are correct for all the internalformats.
36 #include "common.h"
38 PIGLIT_GL_TEST_CONFIG_BEGIN
40 config.supports_gl_compat_version = 10;
41 config.window_visual = PIGLIT_GL_VISUAL_RGB;
42 config.khr_no_error_support = PIGLIT_NO_ERRORS;
44 PIGLIT_GL_TEST_CONFIG_END
46 enum piglit_result
47 piglit_display(void)
49 return PIGLIT_FAIL;
52 static const GLenum pnames[] = {
53 GL_COLOR_COMPONENTS,
54 GL_STENCIL_COMPONENTS,
55 GL_DEPTH_COMPONENTS,
58 static GLboolean
59 is_color_format(GLenum internalformat)
61 switch (internalformat) {
62 case GL_RED:
63 case GL_RG:
64 case GL_RGB:
65 case GL_RGBA:
66 case GL_R8:
67 case GL_R8_SNORM:
68 case GL_R16:
69 case GL_R16_SNORM:
70 case GL_RG8:
71 case GL_RG8_SNORM:
72 case GL_RG16:
73 case GL_RG16_SNORM:
74 case GL_R3_G3_B2:
75 case GL_RGB4:
76 case GL_RGB5:
77 case GL_RGB8:
78 case GL_RGB8_SNORM:
79 case GL_RGB10:
80 case GL_RGB12:
81 case GL_RGB16:
82 case GL_RGB16_SNORM:
83 case GL_RGBA2:
84 case GL_RGBA4:
85 case GL_RGB5_A1:
86 case GL_RGBA8:
87 case GL_RGBA8_SNORM:
88 case GL_RGB10_A2:
89 case GL_RGB10_A2UI:
90 case GL_RGBA12:
91 case GL_RGBA16:
92 case GL_RGBA16_SNORM:
93 case GL_SRGB8:
94 case GL_SRGB8_ALPHA8:
95 case GL_R16F:
96 case GL_RG16F:
97 case GL_RGB16F:
98 case GL_RGBA16F:
99 case GL_R32F:
100 case GL_RG32F:
101 case GL_RGB32F:
102 case GL_RGBA32F:
103 case GL_R11F_G11F_B10F:
104 case GL_RGB9_E5:
105 case GL_R8I:
106 case GL_R8UI:
107 case GL_R16I:
108 case GL_R16UI:
109 case GL_R32I:
110 case GL_R32UI:
111 case GL_RG8I:
112 case GL_RG16I:
113 case GL_RG16UI:
114 case GL_RG32I:
115 case GL_RG32UI:
116 case GL_RGB8I:
117 case GL_RGB8UI:
118 case GL_RGB16I:
119 case GL_RGB16UI:
120 case GL_RGB32I:
121 case GL_RGB32UI:
122 case GL_RGBA8I:
123 case GL_RGBA8UI:
124 case GL_RGBA16I:
125 case GL_RGBA16UI:
126 case GL_RGBA32I:
127 case GL_RGBA32UI:
128 case GL_COMPRESSED_RED:
129 case GL_COMPRESSED_RG:
130 case GL_COMPRESSED_RGB:
131 case GL_COMPRESSED_RGBA:
132 case GL_COMPRESSED_SRGB:
133 case GL_COMPRESSED_SRGB_ALPHA:
134 case GL_COMPRESSED_RED_RGTC1:
135 case GL_COMPRESSED_SIGNED_RED_RGTC1:
136 case GL_COMPRESSED_RG_RGTC2:
137 case GL_COMPRESSED_SIGNED_RG_RGTC2:
138 case GL_COMPRESSED_RGBA_BPTC_UNORM:
139 case GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM:
140 case GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT:
141 case GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT:
142 case GL_COMPRESSED_RGB8_ETC2:
143 case GL_COMPRESSED_SRGB8_ETC2:
144 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2:
145 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2:
146 case GL_COMPRESSED_RGBA8_ETC2_EAC:
147 case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:
148 case GL_COMPRESSED_R11_EAC:
149 case GL_COMPRESSED_SIGNED_R11_EAC:
150 case GL_COMPRESSED_RG11_EAC:
151 case GL_COMPRESSED_SIGNED_RG11_EAC:
152 return GL_TRUE;
153 default:
154 return GL_FALSE;
158 static GLboolean
159 is_depth_format(GLenum internalformat)
161 switch (internalformat) {
162 case GL_DEPTH_COMPONENT:
163 case GL_DEPTH_COMPONENT16:
164 case GL_DEPTH_COMPONENT24:
165 case GL_DEPTH_COMPONENT32:
166 case GL_DEPTH_COMPONENT32F:
167 case GL_DEPTH_STENCIL:
168 case GL_DEPTH24_STENCIL8_EXT:
169 case GL_DEPTH32F_STENCIL8:
170 return GL_TRUE;
171 default:
172 return GL_FALSE;
175 static GLboolean
176 is_stencil_format(GLenum internalformat)
178 switch (internalformat) {
179 case GL_STENCIL_INDEX:
180 case GL_DEPTH_STENCIL:
181 case GL_DEPTH24_STENCIL8_EXT:
182 case GL_DEPTH32F_STENCIL8:
183 return GL_TRUE;
184 default:
185 return GL_FALSE;
189 static bool
190 try(const GLenum *targets, unsigned num_targets,
191 const GLenum *internalformats, unsigned num_internalformats,
192 const GLenum pname, test_data *data)
194 bool pass = true;
195 unsigned i;
196 unsigned j;
198 for (i = 0; i < num_targets; i++) {
199 for (j = 0; j < num_internalformats; j++) {
200 bool error_test;
201 bool value_test = true;
202 bool supported;
204 supported = check_query2_dependencies(pname, targets[i])
205 && test_data_check_supported(data, targets[i],
206 internalformats[j]);
208 test_data_execute(data, targets[i], internalformats[j],
209 pname);
211 error_test =
212 piglit_check_gl_error(GL_NO_ERROR);
214 if (!supported) {
215 value_test = test_data_is_unsupported_response(data, pname);
216 } else {
217 GLint returned_value = test_data_value_at_index(data, 0);
218 GLint expected_value = -1;
220 switch(pname) {
221 case GL_COLOR_COMPONENTS:
222 expected_value = is_color_format(internalformats[j]);
223 break;
224 case GL_STENCIL_COMPONENTS:
225 expected_value = is_stencil_format(internalformats[j]);
226 break;
227 case GL_DEPTH_COMPONENTS:
228 expected_value = is_depth_format(internalformats[j]);
229 break;
230 default:
231 assert(!"incorrect pname for test");
232 break;
235 value_test = (returned_value == expected_value);
238 if (error_test && value_test)
239 continue;
241 print_failing_case(targets[i], internalformats[j], pname, data);
243 pass = false;
247 return pass;
250 static bool
251 check_format_components(void)
253 bool check_pass = true;
254 test_data *data = test_data_new(0, 1);
255 unsigned i;
256 int testing64;
258 for (i = 0; i < ARRAY_SIZE(pnames); i++) {
259 bool pass = true;
261 for (testing64 = 0; testing64 <= 1; testing64++) {
262 test_data_set_testing64(data, testing64);
264 pass = try(valid_targets, ARRAY_SIZE(valid_targets),
265 valid_internalformats, num_valid_internalformats,
266 pnames[i], data)
267 && pass;
270 piglit_report_subtest_result(pass ? PIGLIT_PASS : PIGLIT_FAIL,
271 "%s", piglit_get_gl_enum_name(pnames[i]));
273 check_pass = check_pass && pass;
276 test_data_clear(&data);
278 return check_pass;
281 void
282 piglit_init(int argc, char **argv)
284 bool pass = true;
286 piglit_require_extension("GL_ARB_internalformat_query2");
287 initialize_valid_internalformats();
289 pass = check_format_components()
290 && pass;
292 piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);