2 * Copyright 2015 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 DEALINGS
25 * Test provoking vertex control with rendering.
29 #include "piglit-util-gl.h"
31 PIGLIT_GL_TEST_CONFIG_BEGIN
32 config
.supports_gl_compat_version
= 10;
33 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
34 PIGLIT_GL_TEST_CONFIG_END
37 static const float red
[3] = {1, 0, 0},
40 yellow
[3] = {1, 1, 0},
44 /* Do GL_QUADS, GL_QUAD_STRIP obey the provoking vertex control? */
45 static GLboolean quads_pv
;
49 piglit_init(int argc
, char **argv
)
51 piglit_require_extension("GL_ARB_provoking_vertex");
56 test_mode(GLenum prim
, GLenum pv_mode
)
59 const float *expected1
, *expected2
;
60 int x1
= piglit_width
/ 4;
61 int x2
= piglit_width
* 3 / 4;
62 int y
= piglit_height
/ 2;
67 glClear(GL_COLOR_BUFFER_BIT
);
69 glProvokingVertex(pv_mode
);
85 if (pv_mode
== GL_FIRST_VERTEX_CONVENTION
) {
96 glBegin(GL_LINE_STRIP
);
104 if (pv_mode
== GL_FIRST_VERTEX_CONVENTION
) {
115 glBegin(GL_LINE_STRIP
);
125 if (pv_mode
== GL_FIRST_VERTEX_CONVENTION
) {
136 glBegin(GL_TRIANGLES
);
152 if (pv_mode
== GL_FIRST_VERTEX_CONVENTION
) {
162 case GL_TRIANGLE_STRIP
:
163 glBegin(GL_TRIANGLE_STRIP
);
174 if (pv_mode
== GL_FIRST_VERTEX_CONVENTION
) {
184 case GL_TRIANGLE_FAN
:
185 glBegin(GL_TRIANGLE_FAN
);
195 if (pv_mode
== GL_FIRST_VERTEX_CONVENTION
) {
215 glVertex2f(-0.1, -1);
226 if (quads_pv
&& pv_mode
== GL_FIRST_VERTEX_CONVENTION
) {
237 glBegin(GL_QUAD_STRIP
);
251 if (quads_pv
&& pv_mode
== GL_FIRST_VERTEX_CONVENTION
) {
277 assert(!"Bad prim mode");
281 /* try probing 3 scan lines to make sure we hit GL_LINES, etc. */
282 for (dy
= -1; dy
<= 1 && pass
; dy
++) {
283 if (piglit_probe_pixel_rgb_silent(x1
, y
+dy
, black
, dummy
)) {
288 if (!piglit_probe_pixel_rgb(x1
, y
+dy
, expected1
)) {
291 if (!piglit_probe_pixel_rgb(x2
, y
+dy
, expected2
)) {
296 if (num_black
== 3) {
302 printf("Failure for %s, %s\n",
303 piglit_get_prim_name(prim
),
304 piglit_get_gl_enum_name(pv_mode
));
307 piglit_present_results();
316 static const GLenum modes
[] = {
331 glViewport(0, 0, piglit_width
, piglit_height
);
332 glShadeModel(GL_FLAT
);
334 glGetBooleanv(GL_QUADS_FOLLOW_PROVOKING_VERTEX_CONVENTION
, &quads_pv
);
335 printf("GL_QUADS_FOLLOW_PROVOKING_VERTEX_CONVENTION = %u\n", quads_pv
);
337 for (i
= 0; i
< ARRAY_SIZE(modes
); i
++) {
338 pass
= test_mode(modes
[i
], GL_FIRST_VERTEX_CONVENTION
) && pass
;
339 pass
= test_mode(modes
[i
], GL_LAST_VERTEX_CONVENTION
) && pass
;
342 pass
= piglit_check_gl_error(GL_NO_ERROR
) && pass
;
344 piglit_report_result(pass
? PIGLIT_PASS
: PIGLIT_FAIL
);