ext_gpu_shader4: add compiler tests for everything
[piglit.git] / tests / spec / arb_clip_control / clip-control.c
blob020ea0aa2f8d3d4506f4bfb868c2c2990128257e
1 /*
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
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
21 * DEALINGS IN THE SOFTWARE.
23 * Authors:
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
43 void
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);
51 GLboolean
52 test_clip_control(GLenum origin, GLenum mode)
54 GLboolean pass;
55 GLint value;
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");
62 pass = GL_FALSE;
64 glGetIntegerv(GL_CLIP_DEPTH_MODE, &value);
65 if (value != mode) {
66 fprintf(stderr, "glClipControl mode unexpected!\n");
67 pass = GL_FALSE;
70 return pass;
73 GLboolean
74 state_test(void)
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;
103 /* Check push/pop */
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 */
113 glPopAttrib();
114 pass = test_clip_control(GL_LOWER_LEFT, GL_NEGATIVE_ONE_TO_ONE) && pass;
116 return pass;
119 GLboolean
120 test_patch(GLenum origin, GLenum depth,
121 GLclampd near, GLclampd far,
122 float x, float y, float z)
124 GLboolean pass = GL_TRUE;
125 float draw_y;
126 float depth_z;
128 /* Draw the patch */
130 if (origin == GL_LOWER_LEFT)
131 draw_y = y;
132 else
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);
143 else
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;
150 else
151 /* the written depth value */
152 pass = piglit_probe_pixel_depth(x, y, depth_z) && pass;
154 return pass;
157 GLboolean
158 test_patches(GLenum origin, GLenum depth,
159 GLclampd near, GLclampd far,
160 float x)
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,
171 x, 10, 1.5) && pass;
172 /* inside the clip space */
173 pass = test_patch(origin, depth, near, far,
174 x, 20, 1.0) && pass;
175 pass = test_patch(origin, depth, near, far,
176 x, 30, 0.5) && pass;
177 pass = test_patch(origin, depth, near, far,
178 x, 40, 0.0) && pass;
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;
186 } else {
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,
192 x, 20, 0.0) && pass;
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;
206 return pass;
209 GLboolean
210 draw_test(void)
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);
222 glCullFace(GL_BACK);
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 */
240 near = 0.25;
241 far = 0.75;
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 */
253 near = 0.75;
254 far = 0.25;
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();
271 return pass;
274 enum piglit_result
275 piglit_display(void)
277 GLboolean pass;
279 /* Check for getting and setting the state. */
280 pass = state_test();
282 /* Check for correct draws according to the state. */
283 pass = draw_test() && pass;
285 return pass ? PIGLIT_PASS : PIGLIT_FAIL;