2 * Copyright © 2014 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.
25 * Test flat-shaded clipped line color.
26 * Exercises provoking vertex, line smooth, line width, etc.
32 #include "piglit-util-gl.h"
34 PIGLIT_GL_TEST_CONFIG_BEGIN
35 config
.supports_gl_compat_version
= 10;
36 config
.window_visual
= PIGLIT_GL_VISUAL_RGB
| PIGLIT_GL_VISUAL_DOUBLE
;
37 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
38 PIGLIT_GL_TEST_CONFIG_END
41 /* far left, far right verts */
42 static const float verts
[2][2] = {
43 { -10.0, 0.0 }, { 10.0, 0.0 }
46 static const float colors
[2][3] = {
47 { 1.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }
50 static const GLuint forward_order
[2] = { 0, 1 };
51 static const GLuint backward_order
[2] = { 1, 0 };
53 static bool have_pv
= false;
57 test_one(int order
, const float expected
[3])
60 int dy
, y
= piglit_height
/ 2;
62 glClear(GL_COLOR_BUFFER_BIT
);
64 /* draw horizontal line across middle of window */
66 glDrawElements(GL_LINES
, 2, GL_UNSIGNED_INT
, forward_order
);
68 glDrawElements(GL_LINES
, 2, GL_UNSIGNED_INT
, backward_order
);
70 /* To be resilient in the face of different line rasterization,
71 * try several Y values to find where the line was drawn.
73 for (dy
= -1; dy
<= 1; dy
++) {
75 glReadPixels(0, y
+ dy
, 1, 1, GL_RGB
, GL_FLOAT
, color
);
76 if (color
[0] || color
[1] || color
[2]) {
77 /* found non-black pixel */
78 /* test all pixels across middle of window */
79 pass
= piglit_probe_rect_rgb(0, y
+ dy
, /* x, y */
80 piglit_width
, 1, /* w, h */
86 piglit_present_results();
93 piglit_init(int argc
, char **argv
)
95 glMatrixMode(GL_PROJECTION
);
97 glMatrixMode(GL_MODELVIEW
);
100 glEnable(GL_VERTEX_ARRAY
);
101 glEnable(GL_COLOR_ARRAY
);
102 glVertexPointer(2, GL_FLOAT
, 0, verts
);
103 glColorPointer(3, GL_FLOAT
, 0, colors
);
105 glShadeModel(GL_FLAT
);
107 if (piglit_is_extension_supported("GL_ARB_provoking_vertex")) {
110 else if (piglit_is_extension_supported("GL_EXT_provoking_vertex")) {
115 printf("Have provoking vertex.\n");
122 int direction
, smooth
, pv
, width
;
125 for (pv
= 0; pv
<= (int) have_pv
; pv
++) {
127 glProvokingVertex(GL_FIRST_VERTEX_CONVENTION_EXT
);
129 for (width
= 1; width
<= 5; width
+= 4) {
130 glLineWidth((float) width
);
132 for (smooth
= 0; smooth
<= 1; smooth
++) {
134 glEnable(GL_LINE_SMOOTH
);
136 glDisable(GL_LINE_SMOOTH
);
138 for (direction
= 0; direction
<= 1; direction
++) {
139 /* Determine which vertex color should
140 * have been used for the line.
142 int c
= !(direction
^ pv
);
144 p
= test_one(direction
, colors
[c
]);
146 printf("failure (pv = %d, dir = %d,"
147 " smooth = %d, width = %d)\n",
148 pv
, direction
, smooth
, width
);
156 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;