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 for the validity of Viewport bounds, Depth Range bounds and
28 * Scissor Box bounds with viewport arrays (0 to GL_MAX_VIEWPORTS-1).
29 * "Bounds" are the rectangle or range (eg x, y, width, height).
31 #include "piglit-util-gl.h"
33 PIGLIT_GL_TEST_CONFIG_BEGIN
35 config
.supports_gl_compat_version
= 32;
36 config
.supports_gl_core_version
= 32;
37 config
.supports_gl_es_version
= 31;
39 config
.window_visual
= PIGLIT_GL_VISUAL_RGBA
| PIGLIT_GL_VISUAL_DOUBLE
;
40 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
42 PIGLIT_GL_TEST_CONFIG_END
45 * Test clamping for viewport x,y, width, height. They should be clamped
46 * to VIEWPORT_BOUNDS_RANGE and MAX_VIEWPORT_DIMS. INVALID_VALUE for
47 * negative w,h. Test default values of x,y,w,h.
48 * OpenGL 4.3 Core section 13.6.1 ref:
49 * "The location of the viewport’s bottom-left corner, given by (x, y),
50 * are clamped to be within the implementation-dependent viewport bounds
51 * range. The viewport bounds range [min, max] tuple may be determined by
52 * calling GetFloatv with the symbolic constant VIEWPORT_BOUNDS_RANGE (see
55 * "Viewport width and height are clamped to implementation-dependent
56 * maximums when specified. The maximum width and height may be found by
57 * calling GetFloatv with the symbolic constant MAX_VIEWPORT_DIMS."
59 * "An INVALID_VALUE error is generated if either w or h is negative."
61 * "In the initial state, w and h for each viewport are set to the width
62 * and height, respectively, of the window into which the GL is to do its
63 * rendering. If the default framebuffer is bound but no default framebuffer
64 * is associated with the GL context (see chapter 9), then w and h are
65 * initially set to zero. ox, oy , n, and f are set to w/2 , h/2, 0.0, and
69 viewport_bounds(GLint maxVP
)
73 GLfloat vp
[4], vpGet
[4];
77 /* initial values for x,y,w,h */
78 for (i
= 0; i
< maxVP
; i
++) {
79 glGetFloati_v(GL_VIEWPORT
, i
, vp
);
80 if (vp
[0] != 0.0 || vp
[1] != 0.0 ||
81 vp
[2] != (GLfloat
) piglit_width
||
82 vp
[3] != (GLfloat
) piglit_height
) {
83 printf("viewport default value wrong for idx %d\n", i
);
87 pass
= piglit_check_gl_error(GL_NO_ERROR
) && pass
;
89 /* test clamping of viewport values */
90 glGetFloatv(GL_MAX_VIEWPORT_DIMS
, maxDims
);
91 glGetFloatv(GL_VIEWPORT_BOUNDS_RANGE
, range
);
92 vp
[0] = range
[0] - 2.0;
93 vp
[1] = range
[1] + 2.0;
94 vp
[2] = maxDims
[0] + 1.0;
95 vp
[3] = maxDims
[1] + 1.0;
96 glViewportArrayv(0, 1, vp
);
97 glGetFloati_v(GL_VIEWPORT
, 0, vpGet
);
98 if (vpGet
[0] != range
[0] || vpGet
[1] != range
[1] ||
99 vpGet
[2] != maxDims
[0] || vpGet
[3] != maxDims
[1]) {
100 printf("viewport clamping failed glViewportArrayv\n");
103 glViewportIndexedf(1, vp
[0], vp
[1], vp
[2], vp
[3]);
104 glGetFloati_v(GL_VIEWPORT
, 1, vpGet
);
105 if (vpGet
[0] != range
[0] || vpGet
[1] != range
[1] ||
106 vpGet
[2] != maxDims
[0] || vpGet
[3] != maxDims
[1]) {
107 printf("viewport clamping failed glViewportIndexedf\n");
110 glViewportIndexedfv(2, vp
);
111 glGetFloati_v(GL_VIEWPORT
, 2, vpGet
);
112 if (vpGet
[0] != range
[0] || vpGet
[1] != range
[1] ||
113 vpGet
[2] != maxDims
[0] || vpGet
[3] != maxDims
[1]) {
114 printf("viewport clamping failed glViewportIndexedfv\n");
118 pass
= piglit_check_gl_error(GL_NO_ERROR
) && pass
;
120 if (!piglit_khr_no_error
) {
121 /* negative width, height gives gl error */
124 for (i
= 0; i
< 2; i
++) {
125 glViewportArrayv(0, 1, vp
);
126 pass
= piglit_check_gl_error(GL_INVALID_VALUE
) && pass
;
127 glViewportIndexedf(1, vp
[0], vp
[1], vp
[2], vp
[3]);
128 pass
= piglit_check_gl_error(GL_INVALID_VALUE
) && pass
;
129 glViewportIndexedfv(2, vp
);
130 pass
= piglit_check_gl_error(GL_INVALID_VALUE
) && pass
;
140 * Test clamping for depth range near and far. Make sure clamped
141 * to [0, 1]. Test default values for near and far.
142 * OpenGL 4.3 Core section 13.6.1 ref:
143 * "Values in v are each clamped to the range [0, 1] when specified."
147 depth_range_bounds(GLint maxVP
)
150 #ifdef PIGLIT_USE_OPENGL
151 GLdouble dr
[2], drGet
[2];
153 GLfloat dr
[2], drGet
[2];
157 /* initial values for near, far are 0.0, 1.0 respectively */
158 for (i
= 0; i
< maxVP
; i
++) {
159 #ifdef PIGLIT_USE_OPENGL
160 glGetDoublei_v(GL_DEPTH_RANGE
, i
, dr
);
162 glGetFloati_v(GL_DEPTH_RANGE
, i
, dr
);
164 if (dr
[0] != 0.0 || dr
[1] != 1.0) {
165 printf("depth_range default value wrong for idx %d\n",
170 pass
= piglit_check_gl_error(GL_NO_ERROR
) && pass
;
172 /* test clamping of depth_range values */
175 #ifdef PIGLIT_USE_OPENGL
176 glDepthRangeArrayv(0, 1, dr
);
177 glGetDoublei_v(GL_DEPTH_RANGE
, 0, drGet
);
179 glDepthRangeArrayfvOES(0, 1, dr
);
180 glGetFloati_vOES(GL_DEPTH_RANGE
, 0, drGet
);
182 if (drGet
[0] != 0.0 || drGet
[1] != 1.0) {
183 printf("depth_range clamping failed glDepthRangeArrayv\n");
186 #ifdef PIGLIT_USE_OPENGL
187 glDepthRangeIndexed(1, dr
[0], dr
[1]);
188 glGetDoublei_v(GL_DEPTH_RANGE
, 1, drGet
);
190 glDepthRangeIndexedfOES(1, dr
[0], dr
[1]);
191 glGetFloati_vOES(GL_DEPTH_RANGE
, 1, drGet
);
193 if (drGet
[0] != 0.0 || drGet
[1] != 1.0) {
194 printf("depth_range clamping failed glDepthRangeIndexed\n");
202 * Test invalid values for scissor left, bottom, width, height
203 * INVALID_VALUE for negative w,h. Test default values for left, bottom,
205 * OpenGL 4.3 Core section 13.6.1 ref:
206 * "In the initial state, left = bottom = 0, and width and
207 * height are determined by the size of the window into which the GL is
208 * to do its rendering for all viewports. If the default framebuffer is
209 * bound but no default framebuffer is associated with the GL context
210 * (see chapter 4), then width and height are initially set to zero."
212 * "If either width or height is less than zero for any scissor rectangle,
213 * then an INVALID_VALUE error is generated."
216 scissor_bounds(GLint maxVP
)
222 /* initial values for left, bottom, width, height */
223 for (i
= 0; i
< maxVP
; i
++) {
224 glGetIntegeri_v(GL_SCISSOR_BOX
, i
, sc
);
225 if (sc
[0] != 0 || sc
[1] != 0 || sc
[2] != piglit_width
||
226 sc
[3] != piglit_height
) {
227 printf("scissor box default value wrong for idx %d\n",
232 pass
= piglit_check_gl_error(GL_NO_ERROR
) && pass
;
234 /* make sure large values don't cause gl errors */
235 glScissorIndexed(0, 0x8000, 0x80000000, 0x7ffff, 0x7fffffff);
236 pass
= piglit_check_gl_error(GL_NO_ERROR
) && pass
;
238 if (!piglit_khr_no_error
) {
239 /* negative width, height gives gl error */
242 for (i
= 0; i
< 2; i
++) {
243 glScissorArrayv(0, 1, sc
);
244 pass
= piglit_check_gl_error(GL_INVALID_VALUE
) && pass
;
245 glScissorIndexed(1, sc
[0], sc
[1], sc
[2], sc
[3]);
246 pass
= piglit_check_gl_error(GL_INVALID_VALUE
) && pass
;
247 glScissorIndexedv(2, sc
);
248 pass
= piglit_check_gl_error(GL_INVALID_VALUE
) && pass
;
265 const bool subtest_pass = (f); \
266 piglit_report_subtest_result(subtest_pass \
267 ? PIGLIT_PASS : PIGLIT_FAIL, \
269 pass = pass && subtest_pass; \
273 piglit_init(int argc
, char **argv
)
278 #ifdef PIGLIT_USE_OPENGL
279 piglit_require_extension("GL_ARB_viewport_array");
281 piglit_require_extension("GL_OES_viewport_array");
284 glGetIntegerv(GL_MAX_VIEWPORTS
, &maxVP
);
285 if (!piglit_check_gl_error(GL_NO_ERROR
)) {
286 printf("GL error prior to viewport bounds testing\n");
287 piglit_report_result(PIGLIT_FAIL
);
291 X(viewport_bounds(maxVP
), "Viewport x, y, width, height validity");
292 X(depth_range_bounds(maxVP
), "DepthRange near, far validity");
293 X(scissor_bounds(maxVP
),
294 "Scissor left, bottom, width, height validity");
296 pass
= piglit_check_gl_error(GL_NO_ERROR
) && pass
;
297 piglit_report_result(pass
? PIGLIT_PASS
: PIGLIT_FAIL
);