cl: Don't use device_infos if num_device_infos == 0
[piglit.git] / tests / general / point-line-no-cull.c
blob511e387673613bc943c39124c8f53a9592eec879
1 /*
2 * Copyright (c) 2010 VMware, 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 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the 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 NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORES OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE.
24 /**
25 * @file
26 * Test that points and lines are not effected by polygon culling,
27 * polygon stippling or "unfilled" mode.
29 * @author Brian Paul
33 #include "piglit-util-gl.h"
35 PIGLIT_GL_TEST_CONFIG_BEGIN
37 config.supports_gl_compat_version = 10;
39 config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
41 PIGLIT_GL_TEST_CONFIG_END
43 /** Test if the pixels at (x,y) and (x,y+1) are black.
44 * We test two pixels to be sure we hit the primitive we drew. We could
45 * be off by one and miss the line if it's only one pixel wide otherwise.
47 static GLboolean
48 black_pixel(float x, float y)
50 GLfloat pixel[2][3];
52 glReadPixels((int) x, (int) (y-0.5), 1, 2, GL_RGB, GL_FLOAT, pixel);
54 if (pixel[0][0] == 0.0 &&
55 pixel[0][1] == 0.0 &&
56 pixel[0][2] == 0.0 &&
57 pixel[1][0] == 0.0 &&
58 pixel[1][1] == 0.0 &&
59 pixel[1][2] == 0.0)
60 return GL_TRUE;
61 else
62 return GL_FALSE;
66 /** test that lines aren't effected by polygon culling */
67 static GLboolean
68 test_lines_no_culling(void)
70 const GLfloat x0 = 5.0, x1 = 40.0, xmid = 0.5 * (x0 + x1);
71 const GLfloat x2 = 45.0, x3 = 85.0, xmid_aa = 0.5 * (x2 + x3);
72 const GLfloat y0 = 5.0, y1 = 15.0, y2 = 25.0;
73 GLboolean pass = GL_TRUE;
75 glLineWidth(3.0);
76 glEnable(GL_CULL_FACE);
78 /* Non-AA */
80 glCullFace(GL_FRONT);
81 glBegin(GL_LINES);
82 glVertex2f(x0, y0);
83 glVertex2f(x1, y0);
84 glEnd();
85 if (black_pixel(xmid, y0)) {
86 fprintf(stderr, "Error: Line culled by GL_CULL_FACE = GL_FRONT\n");
87 pass = GL_FALSE;
90 glCullFace(GL_BACK);
91 glBegin(GL_LINES);
92 glVertex2f(x0, y1);
93 glVertex2f(x1, y1);
94 glEnd();
95 if (black_pixel(xmid, y1)) {
96 fprintf(stderr, "Error: Line culled by GL_CULL_FACE = GL_BACK\n");
97 pass = GL_FALSE;
100 glCullFace(GL_FRONT_AND_BACK);
101 glBegin(GL_LINES);
102 glVertex2f(x0, y2);
103 glVertex2f(x1, y2);
104 glEnd();
105 if (black_pixel(xmid, y2)) {
106 fprintf(stderr, "Error: Line culled by GL_CULL_FACE = GL_FRONT_AND_BACK\n");
107 pass = GL_FALSE;
111 /* AA */
112 glEnable(GL_LINE_SMOOTH);
113 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
114 glEnable(GL_BLEND);
116 glCullFace(GL_FRONT);
117 glBegin(GL_LINES);
118 glVertex2f(x2, y0);
119 glVertex2f(x3, y0);
120 glEnd();
121 if (black_pixel(xmid_aa, y0)) {
122 fprintf(stderr, "Error: AA Line culled by GL_CULL_FACE = GL_FRONT\n");
123 pass = GL_FALSE;
126 glCullFace(GL_BACK);
127 glBegin(GL_LINES);
128 glVertex2f(x2, y1);
129 glVertex2f(x3, y1);
130 glEnd();
131 if (black_pixel(xmid_aa, y1)) {
132 fprintf(stderr, "Error: AA Line culled by GL_CULL_FACE = GL_BACK\n");
133 pass = GL_FALSE;
136 glCullFace(GL_FRONT_AND_BACK);
137 glBegin(GL_LINES);
138 glVertex2f(x2, y2);
139 glVertex2f(x3, y2);
140 glEnd();
141 if (black_pixel(xmid_aa, y2)) {
142 fprintf(stderr, "Error: AA Line culled by GL_CULL_FACE = GL_FRONT_AND_BACK\n");
143 pass = GL_FALSE;
146 glDisable(GL_BLEND);
147 glDisable(GL_LINE_SMOOTH);
148 glDisable(GL_CULL_FACE);
149 glLineWidth(1.0);
151 return pass;
155 /** test that points aren't effected by polygon culling */
156 static GLboolean
157 test_points_no_culling(void)
159 const GLfloat x0 = 100.0, x1 = 110.0;
160 const GLfloat y0 = 5.0, y1 = 15.0, y2 = 25.0;
161 GLboolean pass = GL_TRUE;
163 glPointSize(5.0);
164 glEnable(GL_CULL_FACE);
166 /* Non-AA */
168 glCullFace(GL_FRONT);
169 glBegin(GL_POINTS);
170 glVertex2f(x0, y0);
171 glEnd();
172 if (black_pixel(x0, y0)) {
173 fprintf(stderr, "Error: Point culled by GL_CULL_FACE = GL_FRONT\n");
174 pass = GL_FALSE;
177 glCullFace(GL_BACK);
178 glBegin(GL_POINTS);
179 glVertex2f(x0, y1);
180 glEnd();
181 if (black_pixel(x0, y1)) {
182 fprintf(stderr, "Error: Point culled by GL_CULL_FACE = GL_BACK\n");
183 pass = GL_FALSE;
186 glCullFace(GL_FRONT_AND_BACK);
187 glBegin(GL_POINTS);
188 glVertex2f(x0, y2);
189 glEnd();
190 if (black_pixel(x0, y2)) {
191 fprintf(stderr, "Error: Point culled by GL_CULL_FACE = GL_FRONT_AND_BACK\n");
192 pass = GL_FALSE;
195 /* AA */
196 glEnable(GL_POINT_SMOOTH);
197 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
198 glEnable(GL_BLEND);
200 glCullFace(GL_FRONT);
201 glBegin(GL_POINTS);
202 glVertex2f(x1, y0);
203 glEnd();
204 if (black_pixel(x1, y0)) {
205 fprintf(stderr, "Error: AA Point culled by GL_CULL_FACE = GL_FRONT\n");
206 pass = GL_FALSE;
209 glCullFace(GL_BACK);
210 glBegin(GL_POINTS);
211 glVertex2f(x1, y1);
212 glEnd();
213 if (black_pixel(x1, y1)) {
214 fprintf(stderr, "Error: AA Point culled by GL_CULL_FACE = GL_BACK\n");
215 pass = GL_FALSE;
218 glCullFace(GL_FRONT_AND_BACK);
219 glBegin(GL_POINTS);
220 glVertex2f(x1, y2);
221 glEnd();
222 if (black_pixel(x1, y2)) {
223 fprintf(stderr, "Error: AA Point culled by GL_CULL_FACE = GL_FRONT_AND_BACK\n");
224 pass = GL_FALSE;
227 glDisable(GL_BLEND);
228 glDisable(GL_POINT_SMOOTH);
229 glDisable(GL_CULL_FACE);
230 glPointSize(1.0);
232 return pass;
236 /** test that lines aren't effected by polygon stipple */
237 static GLboolean
238 test_lines_no_stippling(void)
240 const GLfloat x0 = 5.0, x1 = 40.0, xmid = 0.5 * (x0 + x1);
241 const GLfloat x2 = 45.0, x3 = 85.0, xmid_aa = 0.5 * (x2 + x3);
242 const GLfloat y0 = 50.0;
243 GLubyte stipple[4 * 32];
244 GLboolean pass = GL_TRUE;
246 memset(stipple, 0, sizeof(stipple));
247 glPolygonStipple(stipple);
248 glEnable(GL_POLYGON_STIPPLE);
250 glLineWidth(3.0);
252 /* Non-AA */
253 glBegin(GL_LINES);
254 glVertex2f(x0, y0);
255 glVertex2f(x1, y0);
256 glEnd();
257 if (black_pixel(xmid, y0)) {
258 fprintf(stderr, "Error: Line not drawn because of polygon stipple.\n");
259 pass = GL_FALSE;
262 /* AA */
263 glEnable(GL_LINE_SMOOTH);
264 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
265 glEnable(GL_BLEND);
267 glBegin(GL_LINES);
268 glVertex2f(x2, y0);
269 glVertex2f(x3, y0);
270 glEnd();
271 if (black_pixel(xmid_aa, y0)) {
272 fprintf(stderr, "Error: AA Line not drawn because of polygon stipple.\n");
273 pass = GL_FALSE;
276 glDisable(GL_BLEND);
277 glDisable(GL_LINE_SMOOTH);
278 glDisable(GL_POLYGON_STIPPLE);
279 glLineWidth(1.0);
281 return pass;
285 /** test that points aren't effected by polygon stipple */
286 static GLboolean
287 test_points_no_stippling(void)
289 const GLfloat x0 = 100.0, x1 = 110.0;
290 const GLfloat y0 = 50.0;
291 GLubyte stipple[4 * 32];
292 GLboolean pass = GL_TRUE;
294 memset(stipple, 0, sizeof(stipple));
295 glPolygonStipple(stipple);
296 glEnable(GL_POLYGON_STIPPLE);
298 glPointSize(5.0);
300 /* Non-AA */
301 glBegin(GL_POINTS);
302 glVertex2f(x0, y0);
303 glEnd();
304 if (black_pixel(x0, y0)) {
305 fprintf(stderr, "Error: Point not drawn because of polygon stipple.\n");
306 pass = GL_FALSE;
309 /* AA */
310 glEnable(GL_POINT_SMOOTH);
311 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
312 glEnable(GL_BLEND);
314 glBegin(GL_POINTS);
315 glVertex2f(x1, y0);
316 glEnd();
317 if (black_pixel(x1, y0)) {
318 fprintf(stderr, "Error: AA Point not drawn because of polygon stipple.\n");
319 pass = GL_FALSE;
322 glDisable(GL_BLEND);
323 glDisable(GL_POINT_SMOOTH);
324 glDisable(GL_POLYGON_STIPPLE);
325 glPointSize(1.0);
327 return pass;
331 /** test that lines aren't effected by glPolygonMode */
332 static GLboolean
333 test_lines_no_pgonmode(void)
335 const GLfloat x0 = 5.0, x1 = 40.0, xmid = 0.5 * (x0 + x1);
336 const GLfloat x2 = 45.0, x3 = 85.0, xmid_aa = 0.5 * (x2 + x3);
337 const GLfloat y0 = 80.0;
338 GLboolean pass = GL_TRUE;
340 glPolygonMode(GL_FRONT_AND_BACK, GL_POINT);
341 glLineWidth(3.0);
343 /* Non-AA */
344 glBegin(GL_LINES);
345 glVertex2f(x0, y0);
346 glVertex2f(x1, y0);
347 glEnd();
348 if (black_pixel(xmid, y0)) {
349 fprintf(stderr, "Error: Line not drawn because of polygon mode.\n");
350 pass = GL_FALSE;
353 /* AA */
354 glEnable(GL_LINE_SMOOTH);
355 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
356 glEnable(GL_BLEND);
358 glBegin(GL_LINES);
359 glVertex2f(x2, y0);
360 glVertex2f(x3, y0);
361 glEnd();
362 if (black_pixel(xmid_aa, y0)) {
363 fprintf(stderr, "Error: Line not drawn because of polygon mode.\n");
364 pass = GL_FALSE;
367 glDisable(GL_BLEND);
368 glDisable(GL_LINE_SMOOTH);
369 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
370 glLineWidth(1.0);
372 return pass;
376 /** test that points aren't effected by glPolygonMode */
377 static GLboolean
378 test_points_no_pgonmode(void)
380 const GLfloat x0 = 100.0, x1 = 110.0;
381 const GLfloat y0 = 80.0;
382 GLboolean pass = GL_TRUE;
384 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
385 glPointSize(5.0);
387 /* Non-AA */
388 glBegin(GL_POINTS);
389 glVertex2f(x0, y0);
390 glEnd();
391 if (black_pixel(x0, y0)) {
392 fprintf(stderr, "Error: Line not drawn because of polygon mode.\n");
393 pass = GL_FALSE;
396 /* AA */
397 glEnable(GL_POINT_SMOOTH);
398 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
399 glEnable(GL_BLEND);
401 glBegin(GL_POINTS);
402 glVertex2f(x1, y0);
403 glEnd();
404 if (black_pixel(x1, y0)) {
405 fprintf(stderr, "Error: AA Line not drawn because of polygon mode.\n");
406 pass = GL_FALSE;
409 glDisable(GL_BLEND);
410 glDisable(GL_POINT_SMOOTH);
411 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
412 glPointSize(1.0);
414 return pass;
418 enum piglit_result
419 piglit_display(void)
421 GLboolean pass = GL_TRUE;
423 piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
425 glClear(GL_COLOR_BUFFER_BIT);
427 pass = test_lines_no_culling() && pass;
428 pass = test_points_no_culling() && pass;
429 pass = test_lines_no_stippling() && pass;
430 pass = test_points_no_stippling() && pass;
431 pass = test_lines_no_pgonmode() && pass;
432 pass = test_points_no_pgonmode() && pass;
434 piglit_present_results();
436 return pass ? PIGLIT_PASS : PIGLIT_FAIL;
439 void
440 piglit_init(int argc, char **argv)