2 * Copyright © 2013 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 * 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.
27 * Test glPolygonMode + glPolygonOffset.
34 #include "piglit-util-gl.h"
37 PIGLIT_GL_TEST_CONFIG_BEGIN
38 config
.supports_gl_compat_version
= 10;
39 config
.window_visual
= (PIGLIT_GL_VISUAL_RGB
|
40 PIGLIT_GL_VISUAL_DOUBLE
|
41 PIGLIT_GL_VISUAL_DEPTH
);
42 PIGLIT_GL_TEST_CONFIG_END
47 * Check that we drew a white outline around the blue polygon
50 check_lines_visible(int number
)
52 static const float white
[3] = {1, 1, 1};
53 static const float blue
[3] = {0, 0, 1};
54 const int w
= piglit_width
, h
= piglit_height
;
55 const int mx
= w
/ 2, my
= h
/ 2;
60 if (!piglit_probe_pixel_rgb_silent(mx
, 1, white
, p
)) {
61 piglit_report_subtest_result(PIGLIT_FAIL
,
62 "config %d: Expected white pixel on bottom edge",
68 if (!piglit_probe_pixel_rgb_silent(mx
, h
-2, white
, p
)) {
69 piglit_report_subtest_result(PIGLIT_FAIL
,
70 "config %d: Expected white pixel on top edge",
76 if (!piglit_probe_pixel_rgb_silent(1, my
, white
, p
)) {
77 piglit_report_subtest_result(PIGLIT_FAIL
,
78 "config %d: Expected white pixel on left edge",
84 if (!piglit_probe_pixel_rgb_silent(w
-2, my
, white
, p
)) {
85 piglit_report_subtest_result(PIGLIT_FAIL
,
86 "config %d: Expected white pixel on right edge",
92 if (!piglit_probe_pixel_rgb_silent(mx
, my
, blue
, p
)) {
93 piglit_report_subtest_result(PIGLIT_FAIL
,
94 "config %d: Expected blue pixel in center",
103 /** Draw rect with clockwise vertices */
105 rect_cw(float coords
[2][2])
108 glVertex2f(coords
[0][0], coords
[0][0]);
109 glVertex2f(coords
[0][0], coords
[1][0]);
110 glVertex2f(coords
[1][0], coords
[1][0]);
111 glVertex2f(coords
[1][0], coords
[0][0]);
116 /** Draw rect with counter clockwise vertices */
118 rect_ccw(float coords
[2][2])
121 glVertex2f(coords
[0][0], coords
[0][0]);
122 glVertex2f(coords
[1][0], coords
[0][0]);
123 glVertex2f(coords
[1][0], coords
[1][0]);
124 glVertex2f(coords
[0][0], coords
[1][0]);
129 enum color
{ WHITE
, BLUE
};
133 float offsetFactor
, offsetUnits
;
135 GLenum frontMode1
, backMode1
;
139 GLenum frontMode2
, backMode2
;
146 * For all these test configurations, we should wind up drawing a
147 * blue filled quad with a white outline.
149 static const struct test_config configs
[] = {
151 GL_POLYGON_OFFSET_FILL
, 1.0, 1.0,
153 GL_LINE
, GL_LINE
, WHITE
, GL_CCW
,
155 GL_FILL
, GL_FILL
, BLUE
, GL_CCW
158 GL_POLYGON_OFFSET_FILL
, 1.0, 1.0,
160 GL_FILL
, GL_FILL
, BLUE
, GL_CCW
,
162 GL_LINE
, GL_LINE
, WHITE
, GL_CCW
165 GL_POLYGON_OFFSET_FILL
, 1.0, 1.0,
167 GL_FILL
, GL_LINE
, BLUE
, GL_CCW
,
169 GL_FILL
, GL_LINE
, WHITE
, GL_CW
172 GL_POLYGON_OFFSET_FILL
, 1.0, 1.0,
174 GL_LINE
, GL_FILL
, WHITE
, GL_CCW
,
176 GL_LINE
, GL_FILL
, BLUE
, GL_CW
179 GL_POLYGON_OFFSET_LINE
, 1.0, -1.0,
181 GL_LINE
, GL_FILL
, WHITE
, GL_CCW
,
183 GL_LINE
, GL_FILL
, BLUE
, GL_CW
186 GL_POLYGON_OFFSET_LINE
, 1.0, -1.0,
188 GL_LINE
, GL_FILL
, BLUE
, GL_CW
,
190 GL_LINE
, GL_FILL
, WHITE
, GL_CCW
193 GL_POLYGON_OFFSET_LINE
, 1.0, -1.0,
195 GL_FILL
, GL_LINE
, BLUE
, GL_CCW
,
197 GL_FILL
, GL_LINE
, WHITE
, GL_CW
202 /** Test one configuration */
204 test(int config_number
)
206 const struct test_config
*config
= &configs
[config_number
];
208 float white_coords
[2][2], blue_coords
[2][2], (*coords
)[2];
210 /* for drawing the filled quad (cover the whole window) */
211 blue_coords
[0][0] = 0;
212 blue_coords
[0][1] = 0;
213 blue_coords
[1][0] = piglit_width
;
214 blue_coords
[1][1] = piglit_height
;
216 /* for drawing the outline (2 pixels smaller than the window size) */
217 white_coords
[0][0] = 1;
218 white_coords
[0][1] = 1;
219 white_coords
[1][0] = piglit_width
- 2;
220 white_coords
[1][1] = piglit_height
- 2;
222 assert(config
->offsetEnable
== GL_POLYGON_OFFSET_FILL
||
223 config
->offsetEnable
== GL_POLYGON_OFFSET_LINE
||
224 config
->offsetEnable
== GL_POLYGON_OFFSET_POINT
);
226 assert(config
->frontMode1
== GL_LINE
||
227 config
->frontMode1
== GL_FILL
||
228 config
->frontMode1
== GL_POINT
);
230 assert(config
->backMode1
== GL_LINE
||
231 config
->backMode1
== GL_FILL
||
232 config
->backMode1
== GL_POINT
);
234 assert(config
->winding1
== GL_CW
||
235 config
->winding1
== GL_CCW
);
237 assert(config
->winding2
== GL_CW
||
238 config
->winding2
== GL_CCW
);
240 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
242 glEnable(config
->offsetEnable
);
243 glPolygonOffset(config
->offsetFactor
, config
->offsetUnits
);
245 /* draw first prim */
246 glPolygonMode(GL_FRONT
, config
->frontMode1
);
247 glPolygonMode(GL_BACK
, config
->backMode1
);
248 if (config
->color1
== WHITE
) {
250 coords
= white_coords
;
254 coords
= blue_coords
;
257 if (config
->winding1
== GL_CW
)
262 /* draw second prim */
263 glPolygonMode(GL_FRONT
, config
->frontMode2
);
264 glPolygonMode(GL_BACK
, config
->backMode2
);
265 if (config
->color2
== WHITE
) {
267 coords
= white_coords
;
271 coords
= blue_coords
;
274 if (config
->winding2
== GL_CW
)
280 pass
= check_lines_visible(config_number
);
282 piglit_present_results();
284 glDisable(config
->offsetEnable
);
296 piglit_ortho_projection(piglit_width
, piglit_height
, GL_FALSE
);
298 /* Sub-pixel translation so that lines hit specific pixels */
299 glMatrixMode(GL_MODELVIEW
);
301 glTranslatef(0.375, 0.375, 0.0);
303 for (i
= 0; i
< ARRAY_SIZE(configs
); i
++) {
304 pass
= test(i
) && pass
;
307 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;
312 piglit_init(int argc
, char **argv
)
314 glClearColor(1, 0, 0, 0);
315 glEnable(GL_DEPTH_TEST
);
316 glDepthFunc(GL_LEQUAL
);