2 * Copyright © 2013 LunarG, Inc.
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
23 * Author: Jon Ashburn <jon@lunarg.com>
27 * Tests GL_ARB_viewport_array regarding the validity for the indices.
28 * Use both valid and invalid parameters (index, first, count)
29 * for these new API entry points:
30 * glViewportArrayv, glViewportIndexedf, glViewportIndexedfv, glGetFloati_v.
32 * Also test that writing to an invalid viewport index for Viewport, DepthRange,
33 * Scissor Box, Scissor Test does not modify any of the state for the valid
38 #include "piglit-util-gl.h"
41 PIGLIT_GL_TEST_CONFIG_BEGIN
43 config
.supports_gl_compat_version
= 32;
44 config
.supports_gl_core_version
= 32;
45 config
.supports_gl_es_version
= 31;
47 config
.window_visual
= PIGLIT_GL_VISUAL_RGBA
| PIGLIT_GL_VISUAL_DOUBLE
;
48 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
50 PIGLIT_GL_TEST_CONFIG_END
53 * Test that ViewportArrayv, ViewportIndexedf(v), GetFloati_v give the
54 * "expected_error" gl error. Given the values for "first" and "count"
55 * or "index" in range [first, first+count).
58 check_vp_index(GLuint first
, GLsizei count
, GLenum expected_error
)
60 static const GLfloat v
[] = {0.2, -2.3, 50.0, 1000.3};
64 const unsigned numIterate
= (expected_error
== GL_NO_ERROR
)
66 /* only iterate multiple indices for no error case */
67 for (i
= count
; i
> count
- numIterate
; i
--) {
68 glViewportIndexedf(first
+ i
- 1, v
[0], v
[1], v
[2], v
[3]);
69 pass
= piglit_check_gl_error(expected_error
) && pass
;
71 glViewportIndexedfv(first
+ i
- 1, v
);
72 pass
= piglit_check_gl_error(expected_error
) && pass
;
74 glGetFloati_v(GL_VIEWPORT
,first
+ i
- 1, vGet
);
75 pass
= piglit_check_gl_error(expected_error
) && pass
;
78 mv
= malloc(sizeof(GLfloat
) * 4 * count
);
81 for (i
=0; i
< count
; i
++) {
87 glViewportArrayv(first
, count
, mv
);
89 pass
= piglit_check_gl_error(expected_error
) && pass
;
95 * Test first + count or index valid invalid values.
96 * Valid range is 0 thru (MAX_VIEWPORTS-1).
97 * Also test the Enable, Disable, IsEnabled with invalid index.
100 test_vp_indices(GLint maxVP
)
105 * valid largest range viewport index
106 * OpenGL Core 4.3 Spec, section 13.6.1 ref:
107 * "Multiple viewports are available and are numbered zero
108 * through the value of MAX_VIEWPORTS minus one."
110 if (!check_vp_index(0, maxVP
, GL_NO_ERROR
)) {
111 printf("Got error for valid viewport range, max range=%u\n",
116 if (!piglit_khr_no_error
) {
118 * invalid count + first index for viewport
119 * OpenGL Spec Core 4.3 Spec, section 13.6.1 ref:
120 * "An INVALID_VALUE error is generated if first + count
121 * is greater than the value of MAX_VIEWPORTS."
123 if (!check_vp_index(maxVP
- 1, 2, GL_INVALID_VALUE
)) {
124 printf("Wrong error for invalid viewport range\n");
128 * invalid count for viewport
129 * OpenGL Spec Core 4.3 Spec, section 13.6.1 ref:
130 * "An INVALID_VALUE error is generated if count is negative."
132 glViewportArrayv(0, -1, NULL
);
133 pass
= piglit_check_gl_error(GL_INVALID_VALUE
) && pass
;
140 * Test values for viewports, depth_range and scissor boxes/test are preserved
141 * with invalid indices.
142 * OpenGL Core 4.3 Spec, section 13.6.1 ref:
143 * "Viewports whose indices lie outside the range [first, first + count)
147 test_preserve_invalid_index(GLint maxVP
)
150 static const GLfloat vp
[4] = {1.5555, 2.433, 3.777, 4.888};
152 static const GLint sc
[4] = {3, 9, 17, 23};
154 #ifdef PIGLIT_USE_OPENGL
155 static const GLdouble dr
[2] = {0.3333, 0.66666};
158 static const GLfloat dr
[2] = {0.3333, 0.66666};
164 /* intialize all indices to know values */
165 for (i
= 0; i
< maxVP
; i
++) {
166 glViewportIndexedfv(i
, vp
);
167 #ifdef PIGLIT_USE_OPENGL
168 glDepthRangeIndexed(i
, dr
[0], dr
[1]);
170 glDepthRangeIndexedfOES(i
, dr
[0], dr
[1]);
172 glScissorIndexedv(i
, sc
);
173 glEnablei(GL_SCISSOR_TEST
, i
);
175 pass
= piglit_check_gl_error(GL_NO_ERROR
) && pass
;
177 if (!piglit_khr_no_error
) {
178 /* set an illegal index and then test that no indices changed*/
179 glViewportIndexedf(maxVP
, 0.0, 0.0, 1.0, 1.0);
180 glScissorIndexed(maxVP
, 0, 0, 1, 1);
181 #ifdef PIGLIT_USE_OPENGL
182 glDepthRangeIndexed(maxVP
, 0.0, 0.0);
184 glDepthRangeIndexedfOES(maxVP
, 0.0, 0.0);
186 glDisablei(GL_SCISSOR_TEST
, maxVP
);
188 pass
= piglit_check_gl_error(GL_INVALID_VALUE
) && pass
;
191 for (i
= 0; i
< maxVP
; i
++) {
192 glGetFloati_v(GL_VIEWPORT
, i
, vpGet
);
193 if (vpGet
[0] != vp
[0] || vpGet
[1] != vp
[1] || vpGet
[2] != vp
[2]
194 || vpGet
[3] != vp
[3]) {
195 printf("Viewport index %d got erroneously changed\n",
199 #ifdef PIGLIT_USE_OPENGL
200 glGetDoublei_v(GL_DEPTH_RANGE
, i
, drGet
);
202 glGetFloati_vOES(GL_DEPTH_RANGE
, i
, drGet
);
204 /* Allow float precisions instead of double for desktop GL. */
205 if ((float)drGet
[0] != (float)dr
[0] ||
206 (float)drGet
[1] != (float)dr
[1]) {
207 printf("DepthRange index %d got erroneously changed\n",
211 glGetIntegeri_v(GL_SCISSOR_BOX
, i
, scGet
);
212 if (scGet
[0] != sc
[0] || scGet
[1] != sc
[1] || scGet
[2] != sc
[2]
213 || scGet
[3] != sc
[3]) {
214 printf("Scissor Box for index %d got erroneously changed\n",
218 scEnabled
= glIsEnabledi(GL_SCISSOR_TEST
, i
);
219 if (scEnabled
== GL_FALSE
) {
220 printf("Scissor Test for index %d got erroneously changed\n",
235 piglit_init(int argc
, char **argv
)
240 #ifdef PIGLIT_USE_OPENGL
241 piglit_require_extension("GL_ARB_viewport_array");
243 piglit_require_extension("GL_OES_viewport_array");
246 glGetIntegerv(GL_MAX_VIEWPORTS
, &maxVP
);
247 if (!piglit_check_gl_error(GL_NO_ERROR
))
248 piglit_report_result(PIGLIT_FAIL
);
250 pass
= test_preserve_invalid_index(maxVP
) && pass
;
251 pass
= piglit_check_gl_error(GL_NO_ERROR
) && pass
;
252 pass
= test_vp_indices(maxVP
) && pass
;
253 pass
= piglit_check_gl_error(GL_NO_ERROR
) && pass
;
254 piglit_report_result(pass
? PIGLIT_PASS
: PIGLIT_FAIL
);