fix the spelling in whole piglit
[piglit.git] / tests / spec / arb_internalformat_query2 / texture-compressed-block.c
blob656816fbeb37018513f5569c5196b096a518f2a0
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 texture-compressed-block.c
27 * Verify conditions defined on the spec for the following pnames:
28 * * TEXTURE_COMPRESSED_BLOCK_WIDTH
29 * * TEXTURE_COMPRESSED_BLOCK_HEIGHT
30 * * TEXTURE_COMPRESSED_BLOCK_SIZE
32 * In all those three the spec says :
34 * "If the internal format is not compressed, or the resource is not
35 * supported, 0 is returned."
37 * One could guess which internalformats are compressed, but
38 * TEXTURE_COMPRESSED is already there to know that.
40 * So this test just verifies that if TEXTURE_COMPRESSED or
41 * INTERNALFORMAT_SUPPORTED are false, all those pnames should return
42 * 0.
44 * In that sense, this test is generic-pname-checks on those pnames,
45 * plus a TEXTURE_COMPRESSED check.
49 #include "common.h"
51 PIGLIT_GL_TEST_CONFIG_BEGIN
53 config.supports_gl_compat_version = 10;
54 config.window_visual = PIGLIT_GL_VISUAL_RGB;
55 config.khr_no_error_support = PIGLIT_NO_ERRORS;
57 PIGLIT_GL_TEST_CONFIG_END
59 enum piglit_result
60 piglit_display(void)
62 return PIGLIT_FAIL;
65 static const GLenum pnames[] = {
66 GL_TEXTURE_COMPRESSED_BLOCK_WIDTH,
67 GL_TEXTURE_COMPRESSED_BLOCK_HEIGHT,
68 GL_TEXTURE_COMPRESSED_BLOCK_SIZE,
71 /* As with test_data_check_supported, @data is only used to know if we
72 * are checking the 32 or the 64-bit query. @data content should not
73 * be modified */
74 static bool
75 test_data_check_compressed(test_data *data,
76 const GLenum target,
77 const GLenum internalformat)
79 bool result;
80 test_data *local_data = test_data_new(test_data_get_testing64(data), 1);
82 test_data_execute(local_data, target, internalformat,
83 GL_TEXTURE_COMPRESSED);
85 if (!piglit_check_gl_error(GL_NO_ERROR))
86 result = false;
87 else
88 result = test_data_value_at_index(local_data, 0) == GL_TRUE;
90 test_data_clear(&local_data);
92 return result;
95 /* try_local could be implemented as try_basic (at common.c) with
96 * @possible_values==NULL, and testing that if TEXTURE_COMPRESSED is
97 * false, it should returns zero. Candidate to be refactored */
98 bool
99 try_local(const GLenum *targets, unsigned num_targets,
100 const GLenum *internalformats, unsigned num_internalformats,
101 const GLenum pname,
102 test_data *data)
104 bool pass = true;
105 unsigned i;
106 unsigned j;
108 for (i = 0; i < num_targets; i++) {
109 for (j = 0; j < num_internalformats; j++) {
110 bool error_test;
111 bool value_test = true;
112 bool supported;
113 bool compressed;
115 supported = check_query2_dependencies(pname, targets[i])
116 && test_data_check_supported(data, targets[i],
117 internalformats[j]);
119 compressed = test_data_check_compressed(data, targets[i],
120 internalformats[j]);
122 test_data_execute(data, targets[i], internalformats[j],
123 pname);
125 /* If it is supported and compressed, we don't
126 * have a way to verify at this point that the
127 * returned value is correct */
128 if (supported && compressed)
129 continue;
131 error_test =
132 piglit_check_gl_error(GL_NO_ERROR);
134 * From spec:
135 * "If the internal format is not compressed,
136 * or the resource is not supported, 0 is
137 * returned."
139 if (!supported || !compressed)
140 value_test = test_data_is_unsupported_response(data, pname);
142 if (error_test && value_test)
143 continue;
145 /* If we are here, the test is failing */
146 print_failing_case(targets[i], internalformats[j],
147 pname, data);
149 if (!supported && !value_test)
150 fprintf(stderr,"\tInternalformat is not supported, but returned value is not zero\n");
152 if (!compressed && !value_test)
153 fprintf(stderr,"\tInternalformat is not compressed, but returned value is not zero\n");
155 pass = false;
159 return pass;
162 static bool
163 check_texture_compressed_block(const GLenum *pnames, unsigned num_pnames)
165 bool check_pass = true;
166 test_data *data = test_data_new(0, 1);
167 unsigned i;
168 int testing64;
170 for (i = 0; i < num_pnames; i++) {
171 bool pass = true;
173 for (testing64 = 0; testing64 <= 1; testing64++) {
174 test_data_set_testing64(data, testing64);
175 pass = try_local(valid_targets, ARRAY_SIZE(valid_targets),
176 valid_internalformats, num_valid_internalformats,
177 pnames[i], data)
178 && pass;
181 piglit_report_subtest_result(pass ? PIGLIT_PASS : PIGLIT_FAIL,
182 "%s", piglit_get_gl_enum_name(pnames[i]));
184 check_pass = check_pass && pass;
187 test_data_clear(&data);
189 return check_pass;
192 void
193 piglit_init(int argc, char **argv)
195 bool pass = true;
197 piglit_require_extension("GL_ARB_internalformat_query2");
198 initialize_valid_internalformats();
200 pass = check_texture_compressed_block(pnames, ARRAY_SIZE(pnames))
201 && pass;
203 piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);