framework/replay: disable AA accounting when comparing with no tolerance
[piglit.git] / tests / spec / arb_viewport_array / dlist.c
blob35f78ec0fa64e2b2abc96fd2e96c6cd6f9a299f8
1 /*
2 * Copyright © 2018 Timothy Arceri
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 * Verify that commands added in ARB_viewport_array are compiled into display
26 * lists.
29 #include "piglit-util-gl.h"
30 #include <stdarg.h>
32 PIGLIT_GL_TEST_CONFIG_BEGIN
34 config.supports_gl_compat_version = 32;
35 config.window_visual = PIGLIT_GL_VISUAL_RGBA | PIGLIT_GL_VISUAL_DOUBLE;
36 config.khr_no_error_support = PIGLIT_NO_ERRORS;
38 PIGLIT_GL_TEST_CONFIG_END
40 #define MIN_VP 16
42 enum mode {
43 set_scalar,
44 set_vector,
45 set_array_of_vectors,
46 get_and_compare
49 enum function_type {
50 viewport,
51 scissor,
52 depth
55 #define GEN_BUFFERS(type, n, c, div) \
56 type outbuf[n * c]; \
57 unsigned jjj; \
59 for (jjj = 0; jjj < (n * c); jjj++) { \
60 outbuf[jjj] = (type) value++; \
61 outbuf[jjj] /= div; \
64 #define SET_SCALAR_INDICES2(type, func, n, c) \
65 do { \
66 /* depth values are clamped between 0 and 1.0 \
67 * so we divide by 100. \
68 */ \
69 GEN_BUFFERS(type, n, c, 100.0); \
70 gl ## func \
71 (i, \
72 outbuf[0], \
73 outbuf[1]); \
74 } while (0)
76 #define SET_SCALAR_INDICES4(type, func, n, c) \
77 do { \
78 GEN_BUFFERS(type, n, c, 1); \
79 gl ## func \
80 (i, \
81 outbuf[0], \
82 outbuf[1], \
83 outbuf[2], \
84 outbuf[3]); \
85 } while (0)
87 #define SET_VECTOR_INDICES(type, func, n, c) \
88 do { \
89 GEN_BUFFERS(type, n, c, 1); \
90 gl ## func \
91 (i, outbuf); \
92 } while (0)
94 #define SET_ARRAY_INDICES(type, func, n, c, div) \
95 do { \
96 GEN_BUFFERS(type, n, c, div); \
97 gl ## func \
98 (0, c, outbuf); \
99 } while (0)
101 #define GET_AND_COMPARE_INDICES(type, func, getmode, n, c, div) \
102 do { \
103 type inbuf[n * c]; \
104 GEN_BUFFERS(type, n, c, div); \
106 /* Mesa converts the depth double to a float */ \
107 if (sizeof(type) == sizeof(GLclampd)) { \
108 for (unsigned j = 0; j < (n * c); j++) {\
109 float tmp = outbuf[j]; \
110 outbuf[j] = tmp; \
114 glGet ## func \
116 getmode \
117 , i, inbuf); \
119 if (memcmp(inbuf, outbuf, \
120 sizeof(type) * n * c) != 0) { \
121 printf(" index %d data " \
122 "does not match.\n", \
123 i); \
124 pass = false; \
126 } while (0)
128 bool
129 process_indices(unsigned base_value, enum mode m, enum function_type f_type)
131 bool pass = true;
133 unsigned value = base_value;
134 unsigned count = m == set_array_of_vectors ? 1 : MIN_VP;
136 for (unsigned i = 0; i < count; i++) {
138 switch (m) {
139 case set_scalar:
140 switch (f_type) {
141 case viewport:
142 SET_SCALAR_INDICES4(GLfloat, ViewportIndexedf, 4, 1);
143 break;
144 case scissor:
145 SET_SCALAR_INDICES4(GLint, ScissorIndexed, 4, 1);
146 break;
147 case depth:
148 SET_SCALAR_INDICES2(GLclampd, DepthRangeIndexed, 2, 1);
149 break;
152 break;
153 case set_vector:
154 switch (f_type) {
155 case viewport:
156 SET_VECTOR_INDICES(GLfloat, ViewportIndexedfv, 4, 1);
157 break;
158 case scissor:
159 SET_VECTOR_INDICES(GLint, ScissorIndexedv, 4, 1);
160 break;
161 case depth:
162 printf("Error: Depth has no vector setter");
163 break;
166 break;
167 case set_array_of_vectors:
168 switch (f_type) {
169 case viewport:
170 SET_ARRAY_INDICES(GLfloat, ViewportArrayv, 4, MIN_VP, 1);
171 break;
172 case scissor:
173 SET_ARRAY_INDICES(GLint, ScissorArrayv, 4, MIN_VP, 1);
174 break;
175 case depth:
176 SET_ARRAY_INDICES(GLclampd, DepthRangeArrayv, 2, MIN_VP, 100.0);
177 break;
180 break;
181 case get_and_compare:
182 switch (f_type) {
183 case viewport:
184 GET_AND_COMPARE_INDICES(GLfloat, Floati_v, GL_VIEWPORT, 4, 1, 1);
185 break;
186 case scissor:
187 GET_AND_COMPARE_INDICES(GLint, Integeri_v, GL_SCISSOR_BOX, 4, 1, 1);
188 break;
189 case depth:
190 GET_AND_COMPARE_INDICES(GLclampd, Doublei_v, GL_DEPTH_RANGE, 2, 1, 100.0);
191 break;
193 break;
197 return pass;
200 void
201 piglit_init(int argc, char **argv)
203 bool pass = true;
204 GLint maxVP;
206 piglit_require_extension("GL_ARB_viewport_array");
208 glGetIntegerv(GL_MAX_VIEWPORTS, &maxVP);
209 if (!piglit_check_gl_error(GL_NO_ERROR) || maxVP < MIN_VP)
210 piglit_report_result(PIGLIT_FAIL);
212 static const struct {
213 GLenum list_mode;
214 enum mode setter_mode;
215 const char *setter_mode_name;
216 enum function_type f_type;
217 unsigned base_value;
218 } tests[] = {
220 GL_COMPILE,
221 set_scalar, "viewport scalar", viewport,
225 GL_COMPILE,
226 set_vector, "viewport vector", viewport,
230 GL_COMPILE,
231 set_array_of_vectors, "viewport array of vectors",
232 viewport,
236 GL_COMPILE_AND_EXECUTE,
237 set_scalar, "viewport scalar", viewport,
241 GL_COMPILE_AND_EXECUTE,
242 set_vector, "viewport vector", viewport,
246 GL_COMPILE_AND_EXECUTE,
247 set_array_of_vectors, "viewport array of vectors",
248 viewport,
252 GL_COMPILE,
253 set_scalar, "scissor scalar", scissor,
257 GL_COMPILE,
258 set_vector, "scissor vector", scissor,
262 GL_COMPILE,
263 set_array_of_vectors, "scissor array of vectors",
264 scissor,
268 GL_COMPILE_AND_EXECUTE,
269 set_scalar, "scissor scalar", scissor,
273 GL_COMPILE_AND_EXECUTE,
274 set_vector, "scissor vector", scissor,
278 GL_COMPILE_AND_EXECUTE,
279 set_array_of_vectors, "scissor array of vectors",
280 scissor,
284 GL_COMPILE,
285 set_scalar, "depth scalar", depth,
289 GL_COMPILE,
290 set_array_of_vectors, "depth array", depth,
294 GL_COMPILE_AND_EXECUTE,
295 set_scalar, "depth scalar", depth,
299 GL_COMPILE_AND_EXECUTE,
300 set_array_of_vectors, "depth array", depth,
305 GLuint list = glGenLists(1);
307 for (unsigned i = 0; i < ARRAY_SIZE(tests); i++) {
308 const unsigned post_compile_base_value =
309 (tests[i].list_mode == GL_COMPILE)
310 ? 0 : tests[i].base_value;
312 printf(" %s: %s mode\n",
313 piglit_get_gl_enum_name(tests[i].list_mode),
314 tests[i].setter_mode_name);
316 printf(" pre-initialize\n");
317 pass = process_indices(0, tests[i].setter_mode, tests[i].f_type) && pass;
318 pass = process_indices(0, get_and_compare, tests[i].f_type) && pass;
320 glNewList(list, tests[i].list_mode);
321 printf(" compiling\n");
322 pass = process_indices(tests[i].base_value,
323 tests[i].setter_mode, tests[i].f_type) && pass;
324 glEndList();
326 printf(" post-compile verify\n");
327 pass = process_indices(post_compile_base_value,
328 get_and_compare, tests[i].f_type) && pass;
330 /* Reset the values back. This is useful if GL_COMPILE
331 * executed the commands and for GL_COMPILE_AND_EXECUTE. We
332 * want to know that glCallList changed things.
334 printf(" restore original values\n");
335 pass = process_indices(0, tests[i].setter_mode, tests[i].f_type) && pass;
336 pass = process_indices(0, get_and_compare, tests[i].f_type) && pass;
338 printf(" post-glCallList verify\n");
339 glCallList(list);
340 pass = process_indices(tests[i].base_value,
341 get_and_compare, tests[i].f_type) && pass;
344 glDeleteLists(list, 1);
346 pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
348 piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
351 enum piglit_result
352 piglit_display(void)
354 return PIGLIT_FAIL;