aboutsummaryrefslogtreecommitdiff
path: root/tests/spec/ext_transform_feedback/tessellation.c
blob: c1c42dc41e501ed892f2689fa155e0b0d5e8ce57 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
/*
 * Copyright © 2011 Intel Corporation
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the next
 * paragraph) shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 */

/**
 * \file tessellation.c
 *
 * Verify that transform feedback properly converts primitives of
 * types GL_LINE_LOOP, GL_LINE_STRIP, GL_TRIANGLE_STRIP,
 * GL_TRIANGLE_FAN, GL_QUADS, GL_QUAD_STRIP, and GL_POLYGON into
 * primitives of type GL_LINES or GL_TRIANGLES, as appropriate.
 *
 * According to the OpenGL 3.0 spec (section 2.15: Transform Feedback):
 *
 *     "When quads and polygons are provided to transform feedback
 *     with a primitive mode of TRIANGLES, they will be tessellated
 *     and recorded as triangles (the order of tessellation within a
 *     primitive is undefined). Individual lines or triangles of a
 *     strip or fan primitive will be extracted and recorded
 *     separately."
 *
 * Although it is not stated explicitly, it is clear from context that
 * individual lines of a LINE_LOOP primitive are also expected to be
 * extracted and recorded separately.  Also, the spec does not place
 * any requirement on the order in which vertices are output when
 * extracting individual lines or triangles of a strip, fan, or
 * LINE_LOOP primitive.
 *
 * Because the spec allows variability in how these primitives are
 * tessellated and extracted, we can't verify correct operation by
 * examining the vertices themselves.  However, we can check that if
 * the transform feedback output is fed back into the GL pipeline
 * (using GL_TRIANGLES or GL_LINES, as appropriate), the same image
 * will be rendered.
 *
 * This test operates by first rendering an image without transform
 * feedback, then rendering the same image with transform feedback,
 * then rendering the transform feedback output.  Then it checks that
 * the 3 generated images match exactly.
 *
 * In addition, the test verifies that the expected number of vertices
 * was output by transform feedback.
 *
 * The images are rendered using a fragment shader that attenuates the
 * color of back-facing primitives, so that the test will verify that
 * tesellation preserves winding order properly.
 *
 * The test can be run in four different coloring modes:
 *
 * - "monochrome", meaning that all vertices are assigned the same
 *   color.  A failure in this mode means that the tessellated image
 *   did not have the correct shape.
 *
 * - "wireframe", meaning that all vertices are assigned the same
 *   color, but the image is drawn using
 *   glPolygonMode(GL_FRONT_AND_BACK, GL_LINE).  This test only makes
 *   sense for shapes that would normally be filled (e.g. polygons).
 *   Since we don't expect a tessellated polygon to have the same
 *   appearance as the original image (since additional edges are
 *   added), in this mode we merely check that the correct number of
 *   vertices are output and that the image renders the same with
 *   transform feedback active as with transform feedback inactive.
 *
 * - "smooth", meaning that all vertices are assigned different
 *   colors, and the primitives are drawn with smooth interpolation.
 *   A failure in this mode means that the tessellation performed by
 *   transform feedback failed to match the tessellation performed by
 *   the GL pipeline under normal operation.
 *
 * - "flat_last" or "flat_first", meaning that all vertices are
 *   assigned different colors, and the primitives are flatshaded.  In
 *   the "flat_last" case, they are flatshaded using the GL standard
 *   "last vertex" convention to select the provoking vertex.  In the
 *   "flat_first" case, they are flatshaded using the alternative
 *   "first vertex" convention provided by GL_EXT_provoking_vertex or
 *   GL_ARB_provoking_vertex.  A failure in one of these modes means
 *   that within at least one of the tessellated primitives, transform
 *   feedback failed to output the vertices in the correct order for
 *   proper flatshading.
 *
 * Note: the test can also be run on primitive types "points",
 * "lines", and "triangles".  Although these primitive types are not
 * subject to tessellation, the test is still useful for verifying
 * that correct transform feedback output is generated.
 *
 * Note: some OpenGL implementations do not pass the "flat_first" and
 * "flat_last" tests when rendering quads or polygons.  That is, they
 * produce a tessellation which contains the correct vertices, but not
 * in the order required to preserve flat shaded colors.  This is
 * unlikely to cause problems for client programs, since client
 * programs that use new features like transform feedback are unlikely
 * to also use deprecated features like quads and polygons.  Also, it
 * is a matter of interpretation whether these tests are expected to
 * pass at all--after all, the spec does say that "the order of
 * tessellation within a primitive is undefined".  Accordingly, these
 * failures, should they occur, are flagged as warnings rather than
 * failures.
 */

#include "piglit-util-gl-common.h"

#define BUFFER_SIZE 20

PIGLIT_GL_TEST_CONFIG_BEGIN

	config.window_width = 256;
	config.window_height = 256;
	config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_ALPHA;

PIGLIT_GL_TEST_CONFIG_END

/* Test parameters */
static GLenum draw_mode;
static GLenum xfb_mode;
static unsigned num_input_vertices;
static unsigned expected_num_output_vertices;
static unsigned expected_num_output_primitives;
static float (*vertex_positions)[2];
static GLboolean monochrome;
static GLboolean use_flat_color;
static GLboolean wireframe;
static GLboolean is_deprecated_draw_mode;

/* Other globals */
static GLuint normal_prog;
static GLuint xfb_prog;
static GLuint xfb_buf;
static GLuint xfb_generated_query;
static GLuint xfb_written_query;
static float vertex_colors[][4] = {
	{ 0.00, 0.00, 0.00, 0.00 },
	{ 1.00, 0.25, 0.25, 1.00 },
	{ 0.15, 0.37, 0.98, 1.00 },
	{ 0.50, 0.93, 0.07, 1.00 },
	{ 0.85, 0.02, 0.63, 1.00 },
	{ 0.0,  0.75, 0.75, 1.00 },
	{ 0.85, 0.63, 0.02, 1.00 },
	{ 0.5,  0.07, 0.93, 1.00 },
	{ 0.15, 0.98, 0.37, 1.00 }
};

static struct vertex_data {
	float vertex[2];
	float smooth_color[4];
	float flat_color[4];
} verts[BUFFER_SIZE];

/* Note: vertices are chosen to be on pixel centers to minimize the
 * risk that rounding errors change the image.
 */
static float points_vertices[][2] = {
	{  2.5, 62.5 },
	{ 62.5, 62.5 },
	{  2.5,  2.5 },
	{ 62.5,  2.5 }
};

/* Note: vertices are chosen to be on pixel centers to minimize the
 * risk that rounding errors change the image.
 */
static float lines_vertices[][2] = {
	{  2.5, 62.5 },
	{ 62.5, 62.5 },
	{  2.5,  2.5 },
	{ 62.5,  2.5 }
};

/* Note: vertices are chosen to be on pixel centers to minimize the
 * risk that rounding errors change the image.
 */
static float line_loop_vertices[][2] = {
	{  2.5,  2.5 },
	{  2.5, 62.5 },
	{ 62.5, 62.5 },
	{ 62.5,  2.5 }
};

/* Note: vertices are chosen to be on pixel centers to minimize the
 * risk that rounding errors change the image.
 */
static float line_strip_vertices[][2] = {
	{  2.5,  2.5 },
	{  2.5, 32.5 },
	{ 32.5, 32.5 },
	{ 32.5, 62.5 }
};

static float triangles_vertices[][2] = {
	{   2,  2 },
	{   2, 62 },
	{  42,  2 },
	{  62,  2 },
	{  62, 62 },
	{ 102,  2 }
};

static float triangle_strip_vertices[][2] = {
	{  2,  2 },
	{  2, 62 },
	{ 42,  2 },
	{ 42, 62 },
	{ 82,  2 }
};

static float triangle_fan_vertices[][2] = {
	{  2,  2 },
	{  2, 62 },
	{ 32, 47 },
	{ 52, 27 },
	{ 57, 12 }
};

static float quads_vertices[][2] = {
	{   2,  2 },
	{   2, 62 },
	{  62, 62 },
	{  62,  2 },
	{ 102,  2 },
	{ 102, 62 },
	{ 162, 62 },
	{ 162,  2 }
};

static float quad_strip_vertices[][2] = {
	{   2,  2 },
	{   2, 62 },
	{  62,  2 },
	{  62, 62 },
	{ 122,  2 },
	{ 122, 62 }
};

static float polygon_vertices[][2] = {
	{ 12,  2 },
	{  2, 42 },
	{ 32, 62 },
	{ 62, 42 },
	{ 52,  2 }
};

static const char *vstext =
	"#version 130\n"
	"uniform vec2 vertex_offset;\n"
	"in vec2 vertex;\n"
	"in vec4 smooth_color;\n"
	"in vec4 flat_color;\n"
	"out vec2 vertex_varying;\n"
	"out vec4 smooth_color_varying;\n"
	"flat out vec4 flat_color_varying;\n"
	"\n"
	"void main()\n"
	"{\n"
	"  gl_Position = vec4(vertex + vertex_offset, 0, 128.0);\n"
	"  vertex_varying = vertex;\n"
	"  smooth_color_varying = smooth_color;\n"
	"  flat_color_varying = flat_color;\n"
	"}\n";

static const char *fstext =
	"#version 130\n"
	"uniform bool use_flat_color;\n"
	"in vec4 smooth_color_varying;\n"
	"flat in vec4 flat_color_varying;\n"
	"\n"
	"void main()\n"
	"{\n"
	"  vec4 color = use_flat_color ? flat_color_varying\n"
	"                              : smooth_color_varying;\n"
	"  if (!gl_FrontFacing)\n"
	"    color *= 0.5;\n"
	"  gl_FragColor = color;\n"
	"}\n";

static const char *varyings[] = {
	"vertex_varying", "smooth_color_varying", "flat_color_varying"
};

static void
initialize_shader_and_xfb()
{
	GLuint vs, fs;

	piglit_require_GLSL_version(130);
	piglit_require_transform_feedback();
	vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vstext);
	fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, fstext);
	normal_prog = piglit_CreateProgram();
	piglit_AttachShader(normal_prog, vs);
	piglit_AttachShader(normal_prog, fs);
	piglit_LinkProgram(normal_prog);
	if (!piglit_link_check_status(normal_prog)) {
		piglit_report_result(PIGLIT_FAIL);
	}
	xfb_prog = piglit_CreateProgram();
	piglit_AttachShader(xfb_prog, vs);
	piglit_AttachShader(xfb_prog, fs);
	glTransformFeedbackVaryings(xfb_prog, 3, varyings,
				    GL_INTERLEAVED_ATTRIBS);
	piglit_LinkProgram(xfb_prog);
	if (!piglit_link_check_status(xfb_prog)) {
		piglit_report_result(PIGLIT_FAIL);
	}
	glGenBuffers(1, &xfb_buf);
	glGenQueries(1, &xfb_generated_query);
	glGenQueries(1, &xfb_written_query);
	glFrontFace(GL_CW);
	if (!piglit_check_gl_error(0))
		piglit_report_result(PIGLIT_FAIL);
}

static void
setup_vertex_shader_inputs(GLuint prog)
{
	GLint vertex_index = glGetAttribLocation(prog, "vertex");
	GLint smooth_color_index = glGetAttribLocation(prog, "smooth_color");
	GLint flat_color_index = glGetAttribLocation(prog, "flat_color");

	glVertexAttribPointer(vertex_index, 2, GL_FLOAT, GL_FALSE,
			      sizeof(verts[0]), &verts[0].vertex);
	glVertexAttribPointer(smooth_color_index, 4, GL_FLOAT, GL_FALSE,
			      sizeof(verts[0]), &verts[0].smooth_color);
	glVertexAttribPointer(flat_color_index, 4, GL_FLOAT, GL_FALSE,
			      sizeof(verts[0]), &verts[0].flat_color);
	glEnableVertexAttribArray(vertex_index);
	glEnableVertexAttribArray(smooth_color_index);
	glEnableVertexAttribArray(flat_color_index);
	if (!piglit_check_gl_error(0))
		piglit_report_result(PIGLIT_FAIL);
}

static void
initialize_vertex_shader_inputs()
{
	unsigned i;

	if (monochrome) {
		for (i = 1; i < ARRAY_SIZE(vertex_colors); ++i) {
			vertex_colors[i][0] = 1.0;
			vertex_colors[i][1] = 1.0;
			vertex_colors[i][2] = 1.0;
			vertex_colors[i][3] = 1.0;
		}
	}

	for (i = 0; i < num_input_vertices; ++i) {
		memcpy(verts[i].vertex, vertex_positions[i],
		       sizeof(verts[i].vertex));
		memcpy(verts[i].smooth_color, vertex_colors[i+1],
		       sizeof(verts[i].smooth_color));
		memcpy(verts[i].flat_color, vertex_colors[i+1],
		       sizeof(verts[i].flat_color));
	}
}

/**
 * Determine how many vertices were output by transform feedback by
 * seeing which elements of the transform feedback buffer have been
 * changed from their zero-initialized value.
 */
static unsigned
count_output_vertices(struct vertex_data *vertices)
{
	struct vertex_data zero_initialized;
	unsigned i;

	memset(&zero_initialized, 0, sizeof(zero_initialized));

	for (i = 0; i < BUFFER_SIZE; ++i) {
		if (memcmp(&vertices[i], &zero_initialized,
			   sizeof(zero_initialized)) == 0)
			break;
	}
	return i;
}

/**
 * Check that two strips of the window match.  Strips are numbered
 * from the top from 0 to 3.
 */
static GLboolean
match_strips(int reference, int compare)
{
	GLfloat *reference_image =
		malloc(piglit_width * (piglit_height / 4) * 4 * sizeof(float));
	int reference_offset = (3 - reference) * (piglit_height / 4);
	int compare_offset = (3 - compare) * (piglit_height / 4);
	GLboolean result;
	glReadPixels(0, reference_offset, piglit_width, piglit_height / 4,
		     GL_RGBA, GL_FLOAT, reference_image);
	result = piglit_probe_image_rgba(0, compare_offset, piglit_width,
					 piglit_height / 4, reference_image);
	free(reference_image);
	return result;
}

static void
draw(GLuint prog, bool use_xfb, float y_offset, GLenum mode,
     unsigned num_vertices)
{
	float vertex_offset[2] = { -82.0, y_offset };
	struct vertex_data buffer[BUFFER_SIZE];

	piglit_UseProgram(prog);
	setup_vertex_shader_inputs(prog);
	piglit_Uniform2fv(piglit_GetUniformLocation(prog, "vertex_offset"),
			  1, vertex_offset);
	piglit_Uniform1i(piglit_GetUniformLocation(prog, "use_flat_color"),
			 use_flat_color);
	glBindBuffer(GL_ARRAY_BUFFER, 0);
	if (use_xfb) {
		glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, xfb_buf);
		/* Initialize the buffer with 0 so that we will be
		 * able to identify membory that was not overwitten by
		 * the transform feedback.
		 */
		memset(buffer, 0, sizeof(buffer));
		glBufferData(GL_TRANSFORM_FEEDBACK_BUFFER, sizeof(buffer),
			     buffer, GL_STREAM_READ);
		glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, xfb_buf);
		glBeginTransformFeedback(xfb_mode);
		glBeginQuery(GL_PRIMITIVES_GENERATED, xfb_generated_query);
		glBeginQuery(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN,
			     xfb_written_query);
	}
	glDrawArrays(mode, 0, num_vertices);
	if (use_xfb) {
		glEndTransformFeedback();
		glEndQuery(GL_PRIMITIVES_GENERATED);
		glEndQuery(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN);
	}
	if (!piglit_check_gl_error(0))
		piglit_report_result(PIGLIT_FAIL);
}

static void
print_usage_and_exit(char *prog_name)
{
	printf("Usage: %s <draw_mode> <shade_mode>\n"
	       "  where <draw_mode> is one of:\n"
	       "    points\n"
	       "    lines\n"
	       "    line_loop\n"
	       "    line_strip\n"
	       "    triangles\n"
	       "    triangle_strip\n"
	       "    triangle_fan\n"
	       "    quads\n"
	       "    quad_strip\n"
	       "    polygon\n"
	       "  and <shade_mode> is one of:\n"
	       "    monochrome\n"
	       "    smooth\n"
	       "    flat_first\n"
	       "    flat_last\n", prog_name);
	exit(1);
}

void
piglit_init(int argc, char **argv)
{
	/* Interpret command line args */
	if (argc != 3)
		print_usage_and_exit(argv[0]);
	if (strcmp(argv[1], "points") == 0) {
		draw_mode = GL_POINTS;
                is_deprecated_draw_mode = GL_FALSE;
		xfb_mode = GL_POINTS;
		num_input_vertices = 4;
		expected_num_output_vertices = 4;
		expected_num_output_primitives = 4;
		vertex_positions = points_vertices;
	} else if (strcmp(argv[1], "lines") == 0) {
		draw_mode = GL_LINES;
                is_deprecated_draw_mode = GL_FALSE;
		xfb_mode = GL_LINES;
		num_input_vertices = 4;
		expected_num_output_vertices = 4;
		expected_num_output_primitives = 2;
		vertex_positions = lines_vertices;
	} else if (strcmp(argv[1], "line_loop") == 0) {
		draw_mode = GL_LINE_LOOP;
                is_deprecated_draw_mode = GL_FALSE;
		xfb_mode = GL_LINES;
		num_input_vertices = 4;
		expected_num_output_vertices = 8;
		expected_num_output_primitives = 4;
		vertex_positions = line_loop_vertices;
	} else if (strcmp(argv[1], "line_strip") == 0) {
		draw_mode = GL_LINE_STRIP;
                is_deprecated_draw_mode = GL_FALSE;
		xfb_mode = GL_LINES;
		num_input_vertices = 4;
		expected_num_output_vertices = 6;
		expected_num_output_primitives = 3;
		vertex_positions = line_strip_vertices;
	} else if (strcmp(argv[1], "triangles") == 0) {
		draw_mode = GL_TRIANGLES;
                is_deprecated_draw_mode = GL_FALSE;
		xfb_mode = GL_TRIANGLES;
		num_input_vertices = 6;
		expected_num_output_vertices = 6;
		expected_num_output_primitives = 2;
		vertex_positions = triangles_vertices;
	} else if (strcmp(argv[1], "triangle_strip") == 0) {
		draw_mode = GL_TRIANGLE_STRIP;
                is_deprecated_draw_mode = GL_FALSE;
		xfb_mode = GL_TRIANGLES;
		num_input_vertices = 5;
		expected_num_output_vertices = 9;
		expected_num_output_primitives = 3;
		vertex_positions = triangle_strip_vertices;
	} else if (strcmp(argv[1], "triangle_fan") == 0) {
		draw_mode = GL_TRIANGLE_FAN;
                is_deprecated_draw_mode = GL_FALSE;
		xfb_mode = GL_TRIANGLES;
		num_input_vertices = 5;
		expected_num_output_vertices = 9;
		expected_num_output_primitives = 3;
		vertex_positions = triangle_fan_vertices;
	} else if (strcmp(argv[1], "quads") == 0) {
		draw_mode = GL_QUADS;
                is_deprecated_draw_mode = GL_TRUE;
		xfb_mode = GL_TRIANGLES;
		num_input_vertices = 8;
		expected_num_output_vertices = 12;
		expected_num_output_primitives = 4;
		vertex_positions = quads_vertices;
	} else if (strcmp(argv[1], "quad_strip") == 0) {
		draw_mode = GL_QUAD_STRIP;
                is_deprecated_draw_mode = GL_TRUE;
		xfb_mode = GL_TRIANGLES;
		num_input_vertices = 6;
		expected_num_output_vertices = 12;
		expected_num_output_primitives = 4;
		vertex_positions = quad_strip_vertices;
	} else if (strcmp(argv[1], "polygon") == 0) {
		draw_mode = GL_POLYGON;
                is_deprecated_draw_mode = GL_TRUE;
		xfb_mode = GL_TRIANGLES;
		num_input_vertices = 5;
		expected_num_output_vertices = 9;
		expected_num_output_primitives = 3;
		vertex_positions = polygon_vertices;
	} else {
		print_usage_and_exit(argv[0]);
	}
	if (strcmp(argv[2], "monochrome") == 0) {
		monochrome = GL_TRUE;
		use_flat_color = GL_FALSE;
		wireframe = GL_FALSE;
	} else if (strcmp(argv[2], "smooth") == 0) {
		monochrome = GL_FALSE;
		use_flat_color = GL_FALSE;
		wireframe = GL_FALSE;
	} else if (strcmp(argv[2], "flat_last") == 0) {
		monochrome = GL_FALSE;
		use_flat_color = GL_TRUE;
		wireframe = GL_FALSE;
	} else if (strcmp(argv[2], "flat_first") == 0) {
		monochrome = GL_FALSE;
		use_flat_color = GL_TRUE;
		if (piglit_is_extension_supported("GL_EXT_provoking_vertex")) {
			glProvokingVertexEXT(GL_FIRST_VERTEX_CONVENTION);
		} else if (piglit_is_extension_supported("GL_ARB_provoking_vertex")) {
			glProvokingVertex(GL_FIRST_VERTEX_CONVENTION);
		} else {
			printf("Test requires GL_EXT_provoking_vertex "
			       "or GL_ARB_provoking_vertex\n");
			piglit_report_result(PIGLIT_SKIP);
		}
		wireframe = GL_FALSE;
	} else if (strcmp(argv[2], "wireframe") == 0) {
		monochrome = GL_TRUE;
		use_flat_color = GL_FALSE;
		wireframe = GL_TRUE;
	} else {
		print_usage_and_exit(argv[0]);
	}

	initialize_shader_and_xfb();
}

enum piglit_result piglit_display(void)
{
	struct vertex_data *readback;
	unsigned num_output_vertices;
	GLboolean pass = GL_TRUE;
	GLboolean warn = GL_FALSE;
	GLuint num_generated_primitives;
	GLuint num_written_primitives;

	initialize_vertex_shader_inputs();

	glClear(GL_COLOR_BUFFER_BIT);
	if (wireframe)
		glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
	draw(normal_prog, false, 64.0, draw_mode, num_input_vertices);
	draw(xfb_prog, true, 0.0, draw_mode, num_input_vertices);

	pass = match_strips(0, 1) && pass;

	readback = glMapBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, GL_READ_ONLY);
	pass = piglit_check_gl_error(0) && pass;

	num_output_vertices = count_output_vertices(readback);
	if (num_output_vertices != expected_num_output_vertices) {
		printf("Expected %u output vertices, but got %u\n",
		       expected_num_output_vertices, num_output_vertices);
		pass = GL_FALSE;
	}
	glGetQueryObjectuiv(xfb_generated_query, GL_QUERY_RESULT,
			    &num_generated_primitives);
	if (num_generated_primitives != expected_num_output_primitives) {
		printf("Expected %u primitives generated, but got %u\n",
		       expected_num_output_primitives,
		       num_generated_primitives);
		pass = GL_FALSE;
	}
	glGetQueryObjectuiv(xfb_written_query, GL_QUERY_RESULT,
			    &num_written_primitives);
	if (num_written_primitives != expected_num_output_primitives) {
		printf("Expected %u primitives written, but got %u\n",
		       expected_num_output_primitives, num_written_primitives);
		pass = GL_FALSE;
	}

	memcpy(verts, readback, sizeof(verts));
	glUnmapBuffer(GL_TRANSFORM_FEEDBACK_BUFFER);

	draw(normal_prog, false, -64.0, xfb_mode, num_output_vertices);

	if (!wireframe) {
		if (use_flat_color && is_deprecated_draw_mode)
			warn = (!match_strips(0, 2)) || warn;
		else
			pass = match_strips(0, 2) && pass;
	}

	piglit_present_results();

	if (!pass)
		return PIGLIT_FAIL;
	else if (warn)
		return PIGLIT_WARN;
	else
		return PIGLIT_PASS;
}