2 * Copyright (c) The Piglit project 2007
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 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the 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 NON-INFRINGEMENT. IN NO EVENT SHALL
18 * VA LINUX SYSTEM, IBM AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE.
25 * Test fragment.position.
28 #include "piglit-util-gl.h"
30 PIGLIT_GL_TEST_CONFIG_BEGIN
32 config
.supports_gl_compat_version
= 10;
34 config
.window_width
= 200;
35 config
.window_height
= 200;
36 config
.window_visual
= PIGLIT_GL_VISUAL_RGBA
| PIGLIT_GL_VISUAL_DOUBLE
| PIGLIT_GL_VISUAL_DEPTH
;
38 PIGLIT_GL_TEST_CONFIG_END
40 extern float piglit_tolerance
[4];
42 #define NUM_PROGRAMS 4
44 static GLuint FragProg
[NUM_PROGRAMS
];
46 static const char* const ProgramText
[NUM_PROGRAMS
] = {
47 /* Color = fragment pos * scale factor */
49 "PARAM factor = { 0.01, 0.01, 1.0, 0.2 };\n"
50 "MUL result.color, fragment.position, factor;\n"
53 /* Color = dependent 2D texture read */
56 "ALIAS scaled = r0;\n"
57 "MUL r0.xy, fragment.position, 0.01;\n"
58 "TEX result.color, scaled, texture[1], 2D;\n"
61 /* Color = RECT texture color at fragment pos */
63 "TEX result.color, fragment.position, texture[0], RECT;\n"
66 /* Color = 2D texture color at fragment pos */
68 "PARAM scale = { 0.01, 0.01, 1.0, 1.0 };\n"
70 "MUL tc, fragment.position, scale;\n"
71 "TEX result.color, tc, texture[1], 2D;\n"
72 "MOV result.color.w, 0.5;\n"
77 * Draw four quadrilaterals, one for each fragment program:
87 * Each quad is about 100x100 pixels in size.
89 static void DoFrame(void)
91 glClearColor(0.3, 0.3, 0.3, 0.3);
92 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
94 glEnable(GL_FRAGMENT_PROGRAM_ARB
);
96 glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB
, FragProg
[0]);
105 glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB
, FragProg
[1]);
114 glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB
, FragProg
[2]);
123 glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB
, FragProg
[3]);
134 static const struct {
143 { 0.2, 0.2, (0.4+2)/8, 0.2 }
148 { 0.8, 0.2, (1.0+2)/8, 0.2 }
153 { 0.8, 0.8, (1.6+2)/8, 0.2 }
158 { 0.2, 0.8, (1.0+2)/8, 0.2 }
165 { 0.8, 0.2, 0.2, 0.2 }
170 { 0.2, 0.2, 0.8, 0.5 }
175 { 0.2, 0.8, 0.8, 0.8 }
180 { 0.8, 0.8, 0.2, 0.5 }
187 { 0.53, 0.47, 0.08, 0.27 }
192 { 0.29, 0.70, 0.08, 0.40 }
197 { 0.29, 0.70, 0.31, 0.51 }
202 { 0.53, 0.47, 0.31, 0.39 }
209 { 0.8, 0.2, 0.2, 0.5 }
214 { 0.2, 0.2, 0.8, 0.5 }
219 { 0.2, 0.8, 0.8, 0.5 }
224 { 0.8, 0.8, 0.2, 0.5 }
234 for (i
= 0; i
< ARRAY_SIZE(Probes
); i
++) {
235 printf("Testing: %s\n", Probes
[i
].name
);
236 pass
= piglit_probe_pixel_rgba(Probes
[i
].x
* piglit_width
/ 2,
237 Probes
[i
].y
* piglit_height
/ 2,
238 Probes
[i
].expected
) && pass
;
253 if (!piglit_automatic
)
254 piglit_present_results();
255 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;
259 static void Reshape(int width
, int height
)
261 piglit_width
= width
;
262 piglit_height
= height
;
263 glViewport(0, 0, width
, height
);
264 glMatrixMode(GL_PROJECTION
);
266 glOrtho(0.0, 2.0, 0.0, 2.0, -2.0, 6.0);
267 glScalef(1.0, 1.0, -1.0); // flip z-axis
268 glMatrixMode(GL_MODELVIEW
);
273 piglit_init(int argc
, char **argv
)
276 GLubyte rectangle
[200][200][4];
277 GLubyte tex
[256*256][4];
280 /* Need GL 1.4 for GL_GENERATE_MIPMAP tex param */
281 piglit_require_gl_version(14);
283 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER
));
285 piglit_require_fragment_program();
287 piglit_tolerance
[0] = 0.02;
288 piglit_tolerance
[1] = 0.02;
289 piglit_tolerance
[2] = 0.02;
290 piglit_tolerance
[3] = 0.02;
292 for(i
= 0; i
< NUM_PROGRAMS
; ++i
)
293 FragProg
[i
] = piglit_compile_program(GL_FRAGMENT_PROGRAM_ARB
, ProgramText
[i
]);
296 * Texture unit 0: 200x200 RECTANGLE texture
298 for(y
= 0; y
< 200; ++y
) {
299 for(x
= 0; x
< 200; ++x
) {
300 rectangle
[y
][x
][0] = 255-x
;
301 rectangle
[y
][x
][1] = x
;
302 rectangle
[y
][x
][2] = y
;
303 rectangle
[y
][x
][3] = (x
+y
)/2;
307 glActiveTexture(GL_TEXTURE0
);
308 glGenTextures(2, texobj
);
309 glBindTexture(GL_TEXTURE_RECTANGLE_ARB
, texobj
[0]);
310 glTexImage2D(GL_TEXTURE_RECTANGLE_ARB
, 0, GL_RGBA
, 200, 200, 0,
311 GL_RGBA
, GL_UNSIGNED_BYTE
, rectangle
);
314 * Texture unit 1: 256x256 2D texture
316 for(y
= 0; y
< 256; ++y
) {
317 for(x
= 0; x
< 256; ++x
) {
318 tex
[256*y
+x
][0] = 255-x
;
321 tex
[256*y
+x
][3] = (x
+y
)/2;
325 glActiveTexture(GL_TEXTURE1
);
326 glBindTexture(GL_TEXTURE_2D
, texobj
[1]);
327 glTexParameteri(GL_TEXTURE_2D
, GL_GENERATE_MIPMAP
, GL_TRUE
);
328 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, 256, 256, 0,
329 GL_RGBA
, GL_UNSIGNED_BYTE
, tex
);
331 // Overwrite higher mipmap levels
332 for(x
= 0; x
< 4; ++x
) {
339 glTexImage2D(GL_TEXTURE_2D
, 7, GL_RGBA
, 2, 2, 0,
340 GL_RGBA
, GL_UNSIGNED_BYTE
, tex
);
341 glTexImage2D(GL_TEXTURE_2D
, 8, GL_RGBA
, 1, 1, 0,
342 GL_RGBA
, GL_UNSIGNED_BYTE
, tex
);
344 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST_MIPMAP_NEAREST
);
345 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
347 Reshape(piglit_width
, piglit_height
);