ext_gpu_shader4: add compiler tests for everything
[piglit.git] / tests / spec / arb_provoking_vertex / render.c
blob45c7583108ca874b74e6d88f027f3468c6ed6816
1 /**
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
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 DEALINGS
21 * IN THE SOFTWARE.
24 /**
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},
38 green[3] = {0, 1, 0},
39 blue[3] = {0, 0, 1},
40 yellow[3] = {1, 1, 0},
41 black[3] = {0, 0, 0};
44 /* Do GL_QUADS, GL_QUAD_STRIP obey the provoking vertex control? */
45 static GLboolean quads_pv;
48 void
49 piglit_init(int argc, char **argv)
51 piglit_require_extension("GL_ARB_provoking_vertex");
55 static bool
56 test_mode(GLenum prim, GLenum pv_mode)
58 bool pass = true;
59 const float *expected1, *expected2;
60 int x1 = piglit_width / 4;
61 int x2 = piglit_width * 3 / 4;
62 int y = piglit_height / 2;
63 int dy;
64 int num_black = 0;
65 float dummy[4];
67 glClear(GL_COLOR_BUFFER_BIT);
69 glProvokingVertex(pv_mode);
71 switch (prim) {
72 case GL_LINES:
73 glBegin(GL_LINES);
74 /* first line */
75 glColor3fv(red);
76 glVertex2f(-1, 0);
77 glColor3fv(green);
78 glVertex2f( -0.1, 0);
79 /* second line */
80 glColor3fv(blue);
81 glVertex2f(0.1, 0);
82 glColor3fv(yellow);
83 glVertex2f(1, 0);
84 glEnd();
85 if (pv_mode == GL_FIRST_VERTEX_CONVENTION) {
86 expected1 = red;
87 expected2 = blue;
89 else {
90 expected1 = green;
91 expected2 = yellow;
93 break;
95 case GL_LINE_STRIP:
96 glBegin(GL_LINE_STRIP);
97 glColor3fv(red);
98 glVertex2f(-1, 0);
99 glColor3fv(green);
100 glVertex2f(0, 0);
101 glColor3fv(blue);
102 glVertex2f(1, 0);
103 glEnd();
104 if (pv_mode == GL_FIRST_VERTEX_CONVENTION) {
105 expected1 = red;
106 expected2 = green;
108 else {
109 expected1 = green;
110 expected2 = blue;
112 break;
114 case GL_LINE_LOOP:
115 glBegin(GL_LINE_STRIP);
116 glColor3fv(red);
117 glVertex2f(-1, 0);
118 glColor3fv(green);
119 glVertex2f(0, 0);
120 glColor3fv(blue);
121 glVertex2f(1, 0);
122 glColor3fv(yellow);
123 glVertex2f(0, 1);
124 glEnd();
125 if (pv_mode == GL_FIRST_VERTEX_CONVENTION) {
126 expected1 = red;
127 expected2 = green;
129 else {
130 expected1 = green;
131 expected2 = blue;
133 break;
135 case GL_TRIANGLES:
136 glBegin(GL_TRIANGLES);
137 /* first tri */
138 glColor3fv(red);
139 glVertex2f(-1, -1);
140 glColor3fv(green);
141 glVertex2f( 0, -1);
142 glColor3fv(blue);
143 glVertex2f(-0.5, 1);
144 /* second tri */
145 glColor3fv(green);
146 glVertex2f(0, -1);
147 glColor3fv(blue);
148 glVertex2f( 1, -1);
149 glColor3fv(red);
150 glVertex2f(0.5, 1);
151 glEnd();
152 if (pv_mode == GL_FIRST_VERTEX_CONVENTION) {
153 expected1 = red;
154 expected2 = green;
156 else {
157 expected1 = blue;
158 expected2 = red;
160 break;
162 case GL_TRIANGLE_STRIP:
163 glBegin(GL_TRIANGLE_STRIP);
164 /* first tri */
165 glColor3fv(red);
166 glVertex2f(-1, -1);
167 glColor3fv(green);
168 glVertex2f(-0.5, 1);
169 glColor3fv(blue);
170 glVertex2f(0.5, -1);
171 glColor3fv(yellow);
172 glVertex2f(1, 1);
173 glEnd();
174 if (pv_mode == GL_FIRST_VERTEX_CONVENTION) {
175 expected1 = red;
176 expected2 = green;
178 else {
179 expected1 = blue;
180 expected2 = yellow;
182 break;
184 case GL_TRIANGLE_FAN:
185 glBegin(GL_TRIANGLE_FAN);
186 glColor3fv(red);
187 glVertex2f(1, -1);
188 glColor3fv(green);
189 glVertex2f(-1, -1);
190 glColor3fv(blue);
191 glVertex2f(-1, 1);
192 glColor3fv(yellow);
193 glVertex2f(1, 1);
194 glEnd();
195 if (pv_mode == GL_FIRST_VERTEX_CONVENTION) {
196 expected1 = green;
197 expected2 = blue;
199 else {
200 expected1 = blue;
201 expected2 = yellow;
203 break;
205 case GL_QUADS:
206 glBegin(GL_QUADS);
207 /* first quad */
208 glColor3fv(red);
209 glVertex2f(-1, -1);
210 glColor3fv(green);
211 glVertex2f(-1, 1);
212 glColor3fv(blue);
213 glVertex2f(-0.1, 1);
214 glColor3fv(yellow);
215 glVertex2f(-0.1, -1);
216 /* second quad */
217 glColor3fv(green);
218 glVertex2f(0.1, -1);
219 glColor3fv(blue);
220 glVertex2f(0.1, 1);
221 glColor3fv(yellow);
222 glVertex2f(1, 1);
223 glColor3fv(red);
224 glVertex2f(1, -1);
225 glEnd();
226 if (quads_pv && pv_mode == GL_FIRST_VERTEX_CONVENTION) {
227 expected1 = red;
228 expected2 = green;
230 else {
231 expected1 = yellow;
232 expected2 = red;
234 break;
236 case GL_QUAD_STRIP:
237 glBegin(GL_QUAD_STRIP);
238 glColor3fv(red);
239 glVertex2f(-1, -1);
240 glColor3fv(green);
241 glVertex2f(-1, 1);
242 glColor3fv(blue);
243 glVertex2f(0, -1);
244 glColor3fv(yellow);
245 glVertex2f(0, 1);
246 glColor3fv(green);
247 glVertex2f(1, -1);
248 glColor3fv(red);
249 glVertex2f(1, 1);
250 glEnd();
251 if (quads_pv && pv_mode == GL_FIRST_VERTEX_CONVENTION) {
252 expected1 = red;
253 expected2 = blue;
255 else {
256 expected1 = yellow;
257 expected2 = red;
259 break;
261 case GL_POLYGON:
262 glBegin(GL_POLYGON);
263 glColor3fv(red);
264 glVertex2f(1, -1);
265 glColor3fv(green);
266 glVertex2f(-1, -1);
267 glColor3fv(blue);
268 glVertex2f(-1, 1);
269 glColor3fv(yellow);
270 glVertex2f(1, 1);
271 glEnd();
272 expected1 = red;
273 expected2 = red;
274 break;
276 default:
277 assert(!"Bad prim mode");
278 return false;
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)) {
284 /* try next Y pos */
285 num_black++;
286 continue;
288 if (!piglit_probe_pixel_rgb(x1, y+dy, expected1)) {
289 pass = false;
291 if (!piglit_probe_pixel_rgb(x2, y+dy, expected2)) {
292 pass = false;
296 if (num_black == 3) {
297 /* nothing drawn */
298 pass = false;
301 if (!pass) {
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();
309 return pass;
313 enum piglit_result
314 piglit_display(void)
316 static const GLenum modes[] = {
317 GL_LINES,
318 GL_LINE_STRIP,
319 GL_LINE_LOOP,
320 GL_TRIANGLES,
321 GL_TRIANGLE_STRIP,
322 GL_TRIANGLE_FAN,
323 GL_QUADS,
324 GL_QUAD_STRIP,
325 GL_POLYGON
328 int i;
329 bool pass = true;
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);
346 return PIGLIT_FAIL;