cl: Don't use device_infos if num_device_infos == 0
[piglit.git] / tests / general / provoking-vertex.c
blob523b6b4692a79d45685a53cba1d8c81501f32b00
1 /*
2 * Copyright © 2009 Intel Corporation
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 * Ben Holmes <shranzel@hotmail.com>
28 * draws two triangles using different colors for each vert(1st-red, 2nd-green,
29 * 3rd-blue). first tri drawn using glProvokingVertexEXT set to
30 * GL_FIRST_VERTEX_CONVENTION_EXT.
31 * Second tri using GL_LAST_VERTEX_CONVENTION_EXT.
34 #include "piglit-util-gl.h"
36 PIGLIT_GL_TEST_CONFIG_BEGIN
38 config.supports_gl_compat_version = 10;
40 config.window_width = 400;
41 config.window_height = 300;
42 config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
44 PIGLIT_GL_TEST_CONFIG_END
46 void
47 piglit_init(int argc, char **argv)
50 piglit_require_extension("GL_EXT_provoking_vertex");
51 piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
53 glShadeModel(GL_FLAT);
54 glClearColor(0.2, 0.2, 0.2, 1.0);
58 enum piglit_result
59 piglit_display(void)
61 static const float red[3] = {0.9, 0.0, 0.0};
62 static const float blue[3] = {0.0, 0.0, 0.9};
63 static const float green[3] = {0.0, 1.0, 0.0};
64 GLboolean pass = GL_TRUE;
66 glClear(GL_COLOR_BUFFER_BIT);
67 glProvokingVertexEXT(GL_FIRST_VERTEX_CONVENTION_EXT);
68 /* lower triangle: counter-clockwise */
69 glBegin(GL_TRIANGLES);
70 glColor3fv(red);
71 glVertex3i(125, 85, 0);
72 glColor3fv(green);
73 glVertex3i(175, 85, 0);
74 glColor3fv(blue);
75 glVertex3i(150, 110, 0);
76 glEnd();
78 /* upper triangle: clockwise */
79 glBegin(GL_TRIANGLES);
80 glColor3fv(red);
81 glVertex3i(125, 165, 0);
82 glColor3fv(blue);
83 glVertex3i(150, 190, 0);
84 glColor3fv(green);
85 glVertex3i(175, 165, 0);
86 glEnd();
88 glProvokingVertexEXT(GL_LAST_VERTEX_CONVENTION_EXT);
89 /* lower triangle: counter-clockwise */
90 glBegin(GL_TRIANGLES);
91 glColor3fv(red);
92 glVertex3i(200, 85, 0);
93 glColor3fv(green);
94 glVertex3i(250, 85, 0);
95 glColor3fv(blue);
96 glVertex3i(225, 110, 0);
97 glEnd();
99 /* upper triangle: clockwise */
100 glBegin(GL_TRIANGLES);
101 glColor3fv(green);
102 glVertex3i(250, 165, 0);
103 glColor3fv(red);
104 glVertex3i(200, 165, 0);
105 glColor3fv(blue);
106 glVertex3i(225, 190, 0);
107 glEnd();
109 pass = pass && piglit_probe_pixel_rgb(150, 90, red);
110 pass = pass && piglit_probe_pixel_rgb(150, 170, red);
112 pass = pass && piglit_probe_pixel_rgb(225, 90, blue);
113 pass = pass && piglit_probe_pixel_rgb(225, 170, blue);
115 glFinish();
116 piglit_present_results();
118 return pass ? PIGLIT_PASS : PIGLIT_FAIL;