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
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
25 * Verify that commands added in ARB_viewport_array are compiled into display
29 #include "piglit-util-gl.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
55 #define GEN_BUFFERS(type, n, c, div) \
59 for (jjj = 0; jjj < (n * c); jjj++) { \
60 outbuf[jjj] = (type) value++; \
64 #define SET_SCALAR_INDICES2(type, func, n, c) \
66 /* depth values are clamped between 0 and 1.0 \
67 * so we divide by 100. \
69 GEN_BUFFERS(type, n, c, 100.0); \
76 #define SET_SCALAR_INDICES4(type, func, n, c) \
78 GEN_BUFFERS(type, n, c, 1); \
87 #define SET_VECTOR_INDICES(type, func, n, c) \
89 GEN_BUFFERS(type, n, c, 1); \
94 #define SET_ARRAY_INDICES(type, func, n, c, div) \
96 GEN_BUFFERS(type, n, c, div); \
101 #define GET_AND_COMPARE_INDICES(type, func, getmode, n, c, div) \
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]; \
119 if (memcmp(inbuf, outbuf, \
120 sizeof(type) * n * c) != 0) { \
121 printf(" index %d data " \
122 "does not match.\n", \
129 process_indices(unsigned base_value
, enum mode m
, enum function_type f_type
)
133 unsigned value
= base_value
;
134 unsigned count
= m
== set_array_of_vectors
? 1 : MIN_VP
;
136 for (unsigned i
= 0; i
< count
; i
++) {
142 SET_SCALAR_INDICES4(GLfloat
, ViewportIndexedf
, 4, 1);
145 SET_SCALAR_INDICES4(GLint
, ScissorIndexed
, 4, 1);
148 SET_SCALAR_INDICES2(GLclampd
, DepthRangeIndexed
, 2, 1);
156 SET_VECTOR_INDICES(GLfloat
, ViewportIndexedfv
, 4, 1);
159 SET_VECTOR_INDICES(GLint
, ScissorIndexedv
, 4, 1);
162 printf("Error: Depth has no vector setter");
167 case set_array_of_vectors
:
170 SET_ARRAY_INDICES(GLfloat
, ViewportArrayv
, 4, MIN_VP
, 1);
173 SET_ARRAY_INDICES(GLint
, ScissorArrayv
, 4, MIN_VP
, 1);
176 SET_ARRAY_INDICES(GLclampd
, DepthRangeArrayv
, 2, MIN_VP
, 100.0);
181 case get_and_compare
:
184 GET_AND_COMPARE_INDICES(GLfloat
, Floati_v
, GL_VIEWPORT
, 4, 1, 1);
187 GET_AND_COMPARE_INDICES(GLint
, Integeri_v
, GL_SCISSOR_BOX
, 4, 1, 1);
190 GET_AND_COMPARE_INDICES(GLclampd
, Doublei_v
, GL_DEPTH_RANGE
, 2, 1, 100.0);
201 piglit_init(int argc
, char **argv
)
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 {
214 enum mode setter_mode
;
215 const char *setter_mode_name
;
216 enum function_type f_type
;
221 set_scalar
, "viewport scalar", viewport
,
226 set_vector
, "viewport vector", viewport
,
231 set_array_of_vectors
, "viewport array of vectors",
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",
253 set_scalar
, "scissor scalar", scissor
,
258 set_vector
, "scissor vector", scissor
,
263 set_array_of_vectors
, "scissor array of vectors",
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",
285 set_scalar
, "depth scalar", depth
,
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
;
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");
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
);