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
|
/*
* Copyright (c) 2011 VMware, Inc.
*
* 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
* on the rights to use, copy, modify, merge, publish, distribute, sub
* license, 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
* NON-INFRINGEMENT. IN NO EVENT SHALL VMWARE AND/OR THEIR SUPPLIERS
* 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.
*/
/**
* Tests glPolygonMode.
* Brian Paul
* April 2011
*/
#include "piglit-util.h"
int piglit_width = 500, piglit_height = 100;
int piglit_window_mode = GLUT_RGB | GLUT_ALPHA | GLUT_DOUBLE;
static const char *TestName = "polygon-mode";
#define VERTS 16
static const GLfloat Positions[VERTS][2] = {
/* clockwise */
{ 0, -1 },
{ 1, -1 },
{ 1, 1 },
{ 0, 1 },
/* counter-clockwise */
{ 2, -1 },
{ 2, 1 },
{ 3, 1 },
{ 3, -1 },
/* clockwise */
{ 4, -1 },
{ 5, -1 },
{ 5, 1 },
{ 4, 1 },
/* counter-clockwise */
{ 6, -1 },
{ 6, 1 },
{ 7, 1 },
{ 7, -1 }
};
static const GLfloat Colors[VERTS][4] = {
{1, 0, 0, 1},
{1, 0, 0, 1},
{1, 0, 0, 1},
{1, 0, 0, 1},
{0, 1, 0, 1},
{0, 1, 0, 1},
{0, 1, 0, 1},
{0, 1, 0, 1},
{0, 0, 1, 1},
{0, 0, 1, 1},
{0, 0, 1, 1},
{0, 0, 1, 1},
{1, 1, 1, 1},
{1, 1, 1, 1},
{1, 1, 1, 1},
{1, 1, 1, 1}
};
static const char *
get_mode_str(GLenum mode)
{
switch (mode) {
case GL_POINT:
return "GL_POINT";
case GL_LINE:
return "GL_LINE";
case GL_FILL:
return "GL_FILL";
default:
return NULL;
}
}
static GLenum
get_prim_mode(GLenum mode)
{
switch (mode) {
case GL_POINT:
return GL_POINTS;
case GL_LINE:
return GL_LINE_LOOP;
case GL_FILL:
return GL_QUADS;
default:
return 0;
}
}
static GLboolean
test_combo(GLenum frontMode, GLenum backMode)
{
GLenum frontPrim = get_prim_mode(frontMode);
GLenum backPrim = get_prim_mode(backMode);
GLubyte *ref, *test;
GLboolean pass = GL_TRUE;
ref = malloc(piglit_width * piglit_height * 4);
test = malloc(piglit_width * piglit_height * 4);
/* Draw reference image */
glClear(GL_COLOR_BUFFER_BIT);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glDrawArrays(frontPrim, 0, 4);
glDrawArrays(backPrim, 4, 4);
glDrawArrays(frontPrim, 8, 4);
glDrawArrays(backPrim, 12, 4);
glReadPixels(0, 0, piglit_width, piglit_height,
GL_RGBA, GL_UNSIGNED_BYTE, ref);
/* Draw test image */
glClear(GL_COLOR_BUFFER_BIT);
glPolygonMode(GL_FRONT, frontMode);
glPolygonMode(GL_BACK, backMode);
glDrawArrays(GL_QUADS, 0, 16);
glReadPixels(0, 0, piglit_width, piglit_height,
GL_RGBA, GL_UNSIGNED_BYTE, test);
/*
* This assumes that there are generally no rasterization differences
* between the normal rendering paths vs. when glPolygonMode is in effect.
* If that's not true, we'll need a different comparision method.
*/
if (memcmp(ref, test, piglit_width * piglit_height * 4)) {
fprintf(stderr, "%s: glPolygonMode(front=%s, back=%s) failed\n",
TestName, get_mode_str(frontMode), get_mode_str(backMode));
pass = GL_FALSE;
}
glutSwapBuffers();
free(ref);
free(test);
return pass;
}
static GLboolean
test_polygonmode(void)
{
GLenum pass = GL_TRUE;
glVertexPointer(2, GL_FLOAT, 0, Positions);
glColorPointer(4, GL_FLOAT, 0, Colors);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
if (!test_combo(GL_FILL, GL_LINE))
pass = GL_FALSE;
if (!test_combo(GL_FILL, GL_POINT))
pass = GL_FALSE;
if (!test_combo(GL_POINT, GL_LINE))
pass = GL_FALSE;
if (!test_combo(GL_POINT, GL_FILL))
pass = GL_FALSE;
if (!test_combo(GL_LINE, GL_FILL))
pass = GL_FALSE;
if (!test_combo(GL_LINE, GL_POINT))
pass = GL_FALSE;
if (!test_combo(GL_LINE, GL_LINE))
pass = GL_FALSE;
if (!test_combo(GL_POINT, GL_POINT))
pass = GL_FALSE;
return pass;
}
enum piglit_result
piglit_display(void)
{
if (!test_polygonmode())
return PIGLIT_FAILURE;
return PIGLIT_SUCCESS;
}
void
piglit_init(int argc, char **argv)
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-1, 8, -2, 2, -1, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
|