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
|
/*
* Copyright (c) The Piglit project 2007
*
* 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
* VA LINUX SYSTEM, IBM 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.
*/
/**
* Test fragment.position.
*/
#include "piglit-util-gl-common.h"
PIGLIT_GL_TEST_CONFIG_BEGIN
config.supports_gl_compat_version = 10;
config.window_width = 200;
config.window_height = 200;
config.window_visual = PIGLIT_GL_VISUAL_RGBA | PIGLIT_GL_VISUAL_ALPHA | PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_DEPTH;
PIGLIT_GL_TEST_CONFIG_END
extern float piglit_tolerance[4];
#define NUM_PROGRAMS 4
static GLuint FragProg[NUM_PROGRAMS];
static const char* const ProgramText[NUM_PROGRAMS] = {
/* Color = fragment pos * scale factor */
"!!ARBfp1.0\n"
"PARAM factor = { 0.01, 0.01, 1.0, 0.2 };\n"
"MUL result.color, fragment.position, factor;\n"
"END",
/* Color = dependent 2D texture read */
"!!ARBfp1.0\n"
"TEMP r0;\n"
"ALIAS scaled = r0;\n"
"MUL r0.xy, fragment.position, 0.01;\n"
"TEX result.color, scaled, texture[1], 2D;\n"
"END",
/* Color = RECT texture color at fragment pos */
"!!ARBfp1.0\n"
"TEX result.color, fragment.position, texture[0], RECT;\n"
"END",
/* Color = 2D texture color at fragment pos */
"!!ARBfp1.0\n"
"PARAM scale = { 0.01, 0.01, 1.0, 1.0 };\n"
"TEMP tc;\n"
"MUL tc, fragment.position, scale;\n"
"TEX result.color, tc, texture[1], 2D;\n"
"MOV result.color.w, 0.5;\n"
"END",
};
/**
* Draw four quadrilaterals, one for each fragment program:
* +--------+--------+
* | | |
* | Prog 1 | Prog 3 |
* | | |
* +--------+--------+
* | | |
* | Prog 0 | Prog 2 |
* | | |
* +--------+--------+
* Each quad is about 100x100 pixels in size.
*/
static void DoFrame(void)
{
glClearColor(0.3, 0.3, 0.3, 0.3);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_FRAGMENT_PROGRAM_ARB);
glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, FragProg[0]);
glBegin(GL_QUADS);
glVertex3f(0, 0, 0);
glVertex3f(1, 0, 1);
glVertex3f(1, 1, 2);
glVertex3f(0, 1, 1);
glEnd();
glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, FragProg[1]);
glBegin(GL_QUADS);
glVertex2f(0, 1);
glVertex2f(1, 1);
glVertex2f(1, 2);
glVertex2f(0, 2);
glEnd();
glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, FragProg[2]);
glBegin(GL_QUADS);
glVertex2f(1, 0);
glVertex2f(2, 0);
glVertex2f(2, 1);
glVertex2f(1, 1);
glEnd();
glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, FragProg[3]);
glBegin(GL_QUADS);
glVertex2f(1, 1);
glVertex2f(2, 1);
glVertex2f(2, 2);
glVertex2f(1, 2);
glEnd();
}
static const struct {
const char* name;
float x, y;
float expected[4];
} Probes[] = {
// Program 0
{
"basic #1",
0.2, 0.2,
{ 0.2, 0.2, (0.4+2)/8, 0.2 }
},
{
"basic #2",
0.8, 0.2,
{ 0.8, 0.2, (1.0+2)/8, 0.2 }
},
{
"basic #3",
0.8, 0.8,
{ 0.8, 0.8, (1.6+2)/8, 0.2 }
},
{
"basic #4",
0.2, 0.8,
{ 0.2, 0.8, (1.0+2)/8, 0.2 }
},
// Program 1
{
"tex2d scaled #1",
0.2, 1.2,
{ 0.8, 0.2, 0.2, 0.2 }
},
{
"tex2d scaled #2",
0.8, 1.2,
{ 0.2, 0.2, 0.8, 0.5 }
},
{
"tex2d scaled #3",
0.8, 1.8,
{ 0.2, 0.8, 0.8, 0.8 }
},
{
"tex2d scaled #4",
0.2, 1.8,
{ 0.8, 0.8, 0.2, 0.5 }
},
// Program 2
{
"texrect #1",
1.2, 0.2,
{ 0.53, 0.47, 0.08, 0.27 }
},
{
"texrect #2",
1.8, 0.2,
{ 0.29, 0.70, 0.08, 0.40 }
},
{
"texrect #1",
1.8, 0.8,
{ 0.29, 0.70, 0.31, 0.51 }
},
{
"texrect #1",
1.2, 0.8,
{ 0.53, 0.47, 0.31, 0.39 }
},
// Program 3
{
"tex2d unscaled #1",
1.2, 1.2,
{ 0.8, 0.2, 0.2, 0.5 }
},
{
"tex2d unscaled #2",
1.8, 1.2,
{ 0.2, 0.2, 0.8, 0.5 }
},
{
"tex2d unscaled #3",
1.8, 1.8,
{ 0.2, 0.8, 0.8, 0.5 }
},
{
"tex2d unscaled #4",
1.2, 1.8,
{ 0.8, 0.8, 0.2, 0.5 }
},
};
static bool
DoTest(void)
{
int i;
bool pass = true;
for (i = 0; i < ARRAY_SIZE(Probes); i++) {
printf("Testing: %s\n", Probes[i].name);
pass = piglit_probe_pixel_rgba(Probes[i].x * piglit_width / 2,
Probes[i].y * piglit_height / 2,
Probes[i].expected) && pass;
}
return pass;
}
enum piglit_result
piglit_display(void)
{
int pass;
DoFrame();
pass = DoTest();
if (!piglit_automatic)
piglit_present_results();
return pass ? PIGLIT_PASS : PIGLIT_FAIL;
}
static void Reshape(int width, int height)
{
piglit_width = width;
piglit_height = height;
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, 2.0, 0.0, 2.0, -2.0, 6.0);
glScalef(1.0, 1.0, -1.0); // flip z-axis
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void
piglit_init(int argc, char **argv)
{
int i, x, y;
GLubyte rectangle[200][200][4];
GLubyte tex[256*256][4];
/* Need GL 1.4 for GL_GENERATE_MIPMAP tex param */
piglit_require_gl_version(14);
printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
piglit_require_fragment_program();
piglit_tolerance[0] = 0.02;
piglit_tolerance[1] = 0.02;
piglit_tolerance[2] = 0.02;
piglit_tolerance[3] = 0.02;
for(i = 0; i < NUM_PROGRAMS; ++i)
FragProg[i] = piglit_compile_program(GL_FRAGMENT_PROGRAM_ARB, ProgramText[i]);
/*
* Texture unit 0: 200x200 RECTANGLE texture
*/
for(y = 0; y < 200; ++y) {
for(x = 0; x < 200; ++x) {
rectangle[y][x][0] = 255-x;
rectangle[y][x][1] = x;
rectangle[y][x][2] = y;
rectangle[y][x][3] = (x+y)/2;
}
}
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 1);
glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA, 200, 200, 0,
GL_RGBA, GL_UNSIGNED_BYTE, rectangle);
/*
* Texture unit 1: 256x256 2D texture
*/
for(y = 0; y < 256; ++y) {
for(x = 0; x < 256; ++x) {
tex[256*y+x][0] = 255-x;
tex[256*y+x][1] = y;
tex[256*y+x][2] = x;
tex[256*y+x][3] = (x+y)/2;
}
}
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, 2);
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0,
GL_RGBA, GL_UNSIGNED_BYTE, tex);
// Overwrite higher mipmap levels
for(x = 0; x < 4; ++x) {
tex[x][0] = 255;
tex[x][1] = 128;
tex[x][2] = 128;
tex[x][3] = 255;
}
glTexImage2D(GL_TEXTURE_2D, 7, GL_RGBA, 2, 2, 0,
GL_RGBA, GL_UNSIGNED_BYTE, tex);
glTexImage2D(GL_TEXTURE_2D, 8, GL_RGBA, 1, 1, 0,
GL_RGBA, GL_UNSIGNED_BYTE, tex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
Reshape(piglit_width, piglit_height);
}
|