2 * Copyright Mathias Fröhlich <Mathias.Froehlich@web.de>
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
21 * DEALINGS IN THE SOFTWARE.
24 * Mathias Fröhlich <Mathias.Froehlich@web.de>
27 /** @file clip-control.c
29 * Basic test for ARB_clip_contol.
32 #include "piglit-util-gl.h"
34 PIGLIT_GL_TEST_CONFIG_BEGIN
36 config
.supports_gl_compat_version
= 20;
38 config
.window_visual
= PIGLIT_GL_VISUAL_RGB
| PIGLIT_GL_VISUAL_DOUBLE
| PIGLIT_GL_VISUAL_DEPTH
;
39 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
41 PIGLIT_GL_TEST_CONFIG_END
44 piglit_init(int argc
, char **argv
)
46 piglit_require_extension("GL_ARB_clip_control");
48 piglit_ortho_projection(piglit_width
, piglit_height
, GL_FALSE
);
52 test_clip_control(GLenum origin
, GLenum mode
)
57 pass
= piglit_check_gl_error(GL_NO_ERROR
);
59 glGetIntegerv(GL_CLIP_ORIGIN
, &value
);
60 if (value
!= origin
) {
61 fprintf(stderr
, "glClipControl origin unexpected!\n");
64 glGetIntegerv(GL_CLIP_DEPTH_MODE
, &value
);
66 fprintf(stderr
, "glClipControl mode unexpected!\n");
76 GLboolean pass
= GL_TRUE
;
78 /* The initial values */
79 pass
= test_clip_control(GL_LOWER_LEFT
, GL_NEGATIVE_ONE_TO_ONE
) && pass
;
81 glClipControl(GL_LOWER_LEFT
, GL_ZERO_TO_ONE
);
82 pass
= test_clip_control(GL_LOWER_LEFT
, GL_ZERO_TO_ONE
) && pass
;
84 glClipControl(GL_UPPER_LEFT
, GL_ZERO_TO_ONE
);
85 pass
= test_clip_control(GL_UPPER_LEFT
, GL_ZERO_TO_ONE
) && pass
;
87 glClipControl(GL_UPPER_LEFT
, GL_NEGATIVE_ONE_TO_ONE
);
88 pass
= test_clip_control(GL_UPPER_LEFT
, GL_NEGATIVE_ONE_TO_ONE
) && pass
;
90 if (!piglit_khr_no_error
) {
91 /* Check bailing out on invalid input */
92 glClipControl(GL_RGB
, GL_NEGATIVE_ONE_TO_ONE
);
93 pass
= piglit_check_gl_error(GL_INVALID_ENUM
) && pass
;
94 piglit_reset_gl_error();
95 pass
= test_clip_control(GL_UPPER_LEFT
, GL_NEGATIVE_ONE_TO_ONE
) && pass
;
97 glClipControl(GL_LOWER_LEFT
, GL_RGB
);
98 pass
= piglit_check_gl_error(GL_INVALID_ENUM
) && pass
;
99 piglit_reset_gl_error();
100 pass
= test_clip_control(GL_UPPER_LEFT
, GL_NEGATIVE_ONE_TO_ONE
) && pass
;
104 glClipControl(GL_LOWER_LEFT
, GL_NEGATIVE_ONE_TO_ONE
);
105 pass
= test_clip_control(GL_LOWER_LEFT
, GL_NEGATIVE_ONE_TO_ONE
) && pass
;
107 glPushAttrib(GL_TRANSFORM_BIT
);
109 glClipControl(GL_UPPER_LEFT
, GL_ZERO_TO_ONE
);
110 pass
= test_clip_control(GL_UPPER_LEFT
, GL_ZERO_TO_ONE
) && pass
;
112 /* Back to default */
114 pass
= test_clip_control(GL_LOWER_LEFT
, GL_NEGATIVE_ONE_TO_ONE
) && pass
;
120 test_patch(GLenum origin
, GLenum depth
,
121 GLclampd near
, GLclampd far
,
122 float x
, float y
, float z
)
124 GLboolean pass
= GL_TRUE
;
130 if (origin
== GL_LOWER_LEFT
)
133 draw_y
= piglit_height
- y
;
135 piglit_draw_rect_z(z
, x
- 2, draw_y
- 2, 4, 4);
138 /* Check the depth and clip behavior */
140 /* The usual orthographic projection flips the z sign */
141 if (depth
== GL_NEGATIVE_ONE_TO_ONE
)
142 depth_z
= -z
*0.5*(far
- near
) + 0.5*(near
+ far
);
144 depth_z
= -z
*(far
- near
) + near
;
146 if ((depth_z
< near
&& depth_z
< far
)
147 || (near
< depth_z
&& far
< depth_z
))
148 /* still the clear value */
149 pass
= piglit_probe_pixel_depth(x
, y
, 1.0) && pass
;
151 /* the written depth value */
152 pass
= piglit_probe_pixel_depth(x
, y
, depth_z
) && pass
;
158 test_patches(GLenum origin
, GLenum depth
,
159 GLclampd near
, GLclampd far
,
162 GLboolean pass
= GL_TRUE
;
164 /* Back to default */
165 glClipControl(origin
, depth
);
166 glDepthRange(near
, far
);
168 if (depth
== GL_NEGATIVE_ONE_TO_ONE
) {
169 /* outside the clip space */
170 pass
= test_patch(origin
, depth
, near
, far
,
172 /* inside the clip space */
173 pass
= test_patch(origin
, depth
, near
, far
,
175 pass
= test_patch(origin
, depth
, near
, far
,
177 pass
= test_patch(origin
, depth
, near
, far
,
179 pass
= test_patch(origin
, depth
, near
, far
,
180 x
, 50, -0.5) && pass
;
181 pass
= test_patch(origin
, depth
, near
, far
,
182 x
, 60, -1.0) && pass
;
183 /* outside the clip space */
184 pass
= test_patch(origin
, depth
, near
, far
,
185 x
, 70, -1.5) && pass
;
187 /* outside the clip space */
188 pass
= test_patch(origin
, depth
, near
, far
,
189 x
, 10, 0.25) && pass
;
190 /* inside the clip space */
191 pass
= test_patch(origin
, depth
, near
, far
,
193 pass
= test_patch(origin
, depth
, near
, far
,
194 x
, 30, -0.25) && pass
;
195 pass
= test_patch(origin
, depth
, near
, far
,
196 x
, 40, -0.5) && pass
;
197 pass
= test_patch(origin
, depth
, near
, far
,
198 x
, 50, -0.75) && pass
;
199 pass
= test_patch(origin
, depth
, near
, far
,
200 x
, 60, -1.0) && pass
;
201 /* outside the clip space */
202 pass
= test_patch(origin
, depth
, near
, far
,
203 x
, 70, -1.25) && pass
;
212 GLboolean pass
= GL_TRUE
;
213 GLclampd near
= 0, far
= 1;
215 /* Now prepare the draw buffer */
216 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
217 glEnable(GL_DEPTH_TEST
);
218 glDepthFunc(GL_ALWAYS
);
220 /* Also test the winding order logic */
221 glEnable(GL_CULL_FACE
);
224 /* The clear value - to be sure */
225 pass
= piglit_probe_pixel_depth(5, 5, 1.0) && pass
;
228 /* Defaut depth rage all clip control combinations */
229 pass
= test_patches(GL_LOWER_LEFT
, GL_NEGATIVE_ONE_TO_ONE
,
230 near
, far
, 10) && pass
;
231 pass
= test_patches(GL_LOWER_LEFT
, GL_ZERO_TO_ONE
,
232 near
, far
, 20) && pass
;
233 pass
= test_patches(GL_UPPER_LEFT
, GL_NEGATIVE_ONE_TO_ONE
,
234 near
, far
, 30) && pass
;
235 pass
= test_patches(GL_UPPER_LEFT
, GL_ZERO_TO_ONE
,
236 near
, far
, 40) && pass
;
239 /* Narrow depth rage all clip control combinations */
242 pass
= test_patches(GL_LOWER_LEFT
, GL_NEGATIVE_ONE_TO_ONE
,
243 near
, far
, 50) && pass
;
244 pass
= test_patches(GL_LOWER_LEFT
, GL_ZERO_TO_ONE
,
245 near
, far
, 60) && pass
;
246 pass
= test_patches(GL_UPPER_LEFT
, GL_NEGATIVE_ONE_TO_ONE
,
247 near
, far
, 70) && pass
;
248 pass
= test_patches(GL_UPPER_LEFT
, GL_ZERO_TO_ONE
,
249 near
, far
, 80) && pass
;
252 /* Reverse narrow depth rage all clip control combinations */
255 pass
= test_patches(GL_LOWER_LEFT
, GL_NEGATIVE_ONE_TO_ONE
,
256 near
, far
, 90) && pass
;
257 pass
= test_patches(GL_LOWER_LEFT
, GL_ZERO_TO_ONE
,
258 near
, far
, 100) && pass
;
259 pass
= test_patches(GL_UPPER_LEFT
, GL_NEGATIVE_ONE_TO_ONE
,
260 near
, far
, 110) && pass
;
261 pass
= test_patches(GL_UPPER_LEFT
, GL_ZERO_TO_ONE
,
262 near
, far
, 120) && pass
;
265 /* Back to default */
266 glClipControl(GL_LOWER_LEFT
, GL_NEGATIVE_ONE_TO_ONE
);
267 glDepthRange(0.0, 1.0);
269 piglit_present_results();
279 /* Check for getting and setting the state. */
282 /* Check for correct draws according to the state. */
283 pass
= draw_test() && pass
;
285 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;