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
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.
26 * Test that points and lines are not effected by polygon culling,
27 * polygon stippling or "unfilled" mode.
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.
48 black_pixel(float x
, float y
)
52 glReadPixels((int) x
, (int) (y
-0.5), 1, 2, GL_RGB
, GL_FLOAT
, pixel
);
54 if (pixel
[0][0] == 0.0 &&
66 /** test that lines aren't effected by polygon culling */
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
;
76 glEnable(GL_CULL_FACE
);
85 if (black_pixel(xmid
, y0
)) {
86 fprintf(stderr
, "Error: Line culled by GL_CULL_FACE = GL_FRONT\n");
95 if (black_pixel(xmid
, y1
)) {
96 fprintf(stderr
, "Error: Line culled by GL_CULL_FACE = GL_BACK\n");
100 glCullFace(GL_FRONT_AND_BACK
);
105 if (black_pixel(xmid
, y2
)) {
106 fprintf(stderr
, "Error: Line culled by GL_CULL_FACE = GL_FRONT_AND_BACK\n");
112 glEnable(GL_LINE_SMOOTH
);
113 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
116 glCullFace(GL_FRONT
);
121 if (black_pixel(xmid_aa
, y0
)) {
122 fprintf(stderr
, "Error: AA Line culled by GL_CULL_FACE = GL_FRONT\n");
131 if (black_pixel(xmid_aa
, y1
)) {
132 fprintf(stderr
, "Error: AA Line culled by GL_CULL_FACE = GL_BACK\n");
136 glCullFace(GL_FRONT_AND_BACK
);
141 if (black_pixel(xmid_aa
, y2
)) {
142 fprintf(stderr
, "Error: AA Line culled by GL_CULL_FACE = GL_FRONT_AND_BACK\n");
147 glDisable(GL_LINE_SMOOTH
);
148 glDisable(GL_CULL_FACE
);
155 /** test that points aren't effected by polygon culling */
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
;
164 glEnable(GL_CULL_FACE
);
168 glCullFace(GL_FRONT
);
172 if (black_pixel(x0
, y0
)) {
173 fprintf(stderr
, "Error: Point culled by GL_CULL_FACE = GL_FRONT\n");
181 if (black_pixel(x0
, y1
)) {
182 fprintf(stderr
, "Error: Point culled by GL_CULL_FACE = GL_BACK\n");
186 glCullFace(GL_FRONT_AND_BACK
);
190 if (black_pixel(x0
, y2
)) {
191 fprintf(stderr
, "Error: Point culled by GL_CULL_FACE = GL_FRONT_AND_BACK\n");
196 glEnable(GL_POINT_SMOOTH
);
197 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
200 glCullFace(GL_FRONT
);
204 if (black_pixel(x1
, y0
)) {
205 fprintf(stderr
, "Error: AA Point culled by GL_CULL_FACE = GL_FRONT\n");
213 if (black_pixel(x1
, y1
)) {
214 fprintf(stderr
, "Error: AA Point culled by GL_CULL_FACE = GL_BACK\n");
218 glCullFace(GL_FRONT_AND_BACK
);
222 if (black_pixel(x1
, y2
)) {
223 fprintf(stderr
, "Error: AA Point culled by GL_CULL_FACE = GL_FRONT_AND_BACK\n");
228 glDisable(GL_POINT_SMOOTH
);
229 glDisable(GL_CULL_FACE
);
236 /** test that lines aren't effected by polygon stipple */
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
);
257 if (black_pixel(xmid
, y0
)) {
258 fprintf(stderr
, "Error: Line not drawn because of polygon stipple.\n");
263 glEnable(GL_LINE_SMOOTH
);
264 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
271 if (black_pixel(xmid_aa
, y0
)) {
272 fprintf(stderr
, "Error: AA Line not drawn because of polygon stipple.\n");
277 glDisable(GL_LINE_SMOOTH
);
278 glDisable(GL_POLYGON_STIPPLE
);
285 /** test that points aren't effected by polygon stipple */
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
);
304 if (black_pixel(x0
, y0
)) {
305 fprintf(stderr
, "Error: Point not drawn because of polygon stipple.\n");
310 glEnable(GL_POINT_SMOOTH
);
311 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
317 if (black_pixel(x1
, y0
)) {
318 fprintf(stderr
, "Error: AA Point not drawn because of polygon stipple.\n");
323 glDisable(GL_POINT_SMOOTH
);
324 glDisable(GL_POLYGON_STIPPLE
);
331 /** test that lines aren't effected by glPolygonMode */
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
);
348 if (black_pixel(xmid
, y0
)) {
349 fprintf(stderr
, "Error: Line not drawn because of polygon mode.\n");
354 glEnable(GL_LINE_SMOOTH
);
355 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
362 if (black_pixel(xmid_aa
, y0
)) {
363 fprintf(stderr
, "Error: Line not drawn because of polygon mode.\n");
368 glDisable(GL_LINE_SMOOTH
);
369 glPolygonMode(GL_FRONT_AND_BACK
, GL_FILL
);
376 /** test that points aren't effected by glPolygonMode */
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
);
391 if (black_pixel(x0
, y0
)) {
392 fprintf(stderr
, "Error: Line not drawn because of polygon mode.\n");
397 glEnable(GL_POINT_SMOOTH
);
398 glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
404 if (black_pixel(x1
, y0
)) {
405 fprintf(stderr
, "Error: AA Line not drawn because of polygon mode.\n");
410 glDisable(GL_POINT_SMOOTH
);
411 glPolygonMode(GL_FRONT_AND_BACK
, GL_FILL
);
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
;
440 piglit_init(int argc
, char **argv
)