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 KIL instruction.
28 #include "piglit-util.h"
30 int piglit_width
= 200, piglit_height
= 200;
31 int piglit_window_mode
= GLUT_RGBA
| GLUT_DOUBLE
| GLUT_DEPTH
;
33 #define NUM_PROGRAMS 2
35 static GLuint FragProg
[NUM_PROGRAMS
];
37 static const char* const ProgramText
[NUM_PROGRAMS
] = {
40 "MOV result.color, fragment.color;\n"
41 "KIL fragment.texcoord[0];\n"
46 "TEX r0, fragment.texcoord[0], texture[0], 2D;\n"
48 "MOV result.color, fragment.color;\n"
52 static void DoFrame(void)
54 glClearColor(0.0, 0.0, 0.0, 1.0);
55 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
57 glEnable(GL_FRAGMENT_PROGRAM_ARB
);
59 glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB
, FragProg
[0]);
61 glColor3f(0.0, 1.0, 0.0);
73 glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB
, FragProg
[1]);
98 { 0.0, 0.0, 0.0, 1.0 }
103 { 0.0, 0.0, 0.0, 1.0 }
108 { 0.0, 1.0, 0.0, 1.0 }
113 { 0.0, 0.0, 0.0, 1.0 }
120 { 0.0, 1.0, 0.0, 1.0 }
125 { 0.0, 0.0, 0.0, 1.0 }
130 { 0.0, 0.0, 0.0, 1.0 }
135 { 0.0, 0.0, 0.0, 1.0 }
140 { 0.0, 0.0, 0.0, 1.0 }
145 { 0.0, 0.0, 0.0, 1.0 }
150 { 0.0, 0.0, 0.0, 1.0 }
155 { 0.0, 0.0, 0.0, 1.0 }
160 { 0.0, 0.0, 0.0, 1.0 }
165 { 0.0, 0.0, 0.0, 1.0 }
170 { 0.0, 0.0, 0.0, 1.0 }
175 { 0.0, 0.0, 0.0, 1.0 }
180 { 0.0, 0.0, 0.0, 1.0 }
185 { 0.0, 0.0, 0.0, 1.0 }
190 { 0.0, 0.0, 0.0, 1.0 }
195 { 0.0, 0.0, 0.0, 1.0 }
206 static int DoTest( void )
211 glReadBuffer( GL_FRONT
);
215 while(Probes
[idx
].name
) {
220 glReadPixels((int)(Probes
[idx
].x
*piglit_width
/2),
221 (int)(Probes
[idx
].y
*piglit_height
/2),
223 GL_RGBA
, GL_FLOAT
, probe
);
225 printf("%20s (%3.1f,%3.1f): %f,%f,%f,%f",
227 Probes
[idx
].x
, Probes
[idx
].y
,
228 probe
[0], probe
[1], probe
[2], probe
[3]);
230 for(i
= 0; i
< 4; ++i
) {
231 delta
[i
] = probe
[i
] - Probes
[idx
].expected
[i
];
233 if (delta
[i
] > dmax
) dmax
= delta
[i
];
234 else if (-delta
[i
] > dmax
) dmax
= -delta
[i
];
237 printf(" Delta: %f,%f,%f,%f\n", delta
[0], delta
[1], delta
[2], delta
[3]);
242 printf("Max delta: %f\n", dmax
);
258 return pass
? PIGLIT_SUCCESS
: PIGLIT_FAILURE
;
262 static void Reshape(int width
, int height
)
264 piglit_width
= width
;
265 piglit_height
= height
;
266 glViewport(0, 0, width
, height
);
267 glMatrixMode(GL_PROJECTION
);
269 glOrtho(0.0, 2.0, 0.0, 2.0, -2.0, 6.0);
270 glScalef(1.0, 1.0, -1.0); // flip z-axis
271 glMatrixMode(GL_MODELVIEW
);
276 piglit_init(int argc
, char **argv
)
279 GLubyte tex
[4][4][4];
281 glutReshapeFunc(Reshape
);
283 if (!GLEW_VERSION_1_3
) {
284 printf("Requires OpenGL 1.3\n");
285 piglit_report_result(PIGLIT_SKIP
);
288 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER
));
290 piglit_require_fragment_program();
295 for(i
= 0; i
< NUM_PROGRAMS
; ++i
)
296 FragProg
[i
] = piglit_compile_program(GL_FRAGMENT_PROGRAM_ARB
, ProgramText
[i
]);
301 for(y
= 0; y
< 4; ++y
) {
302 for(x
= 0; x
< 4; ++x
) {
303 tex
[y
][x
][0] = (x
& 1) ? 255 : 0;
304 tex
[y
][x
][1] = (x
& 2) ? 255 : 0;
305 tex
[y
][x
][2] = (y
& 1) ? 255 : 0;
306 tex
[y
][x
][3] = (y
& 2) ? 255 : 0;
310 glActiveTexture(GL_TEXTURE0
);
311 glEnable(GL_TEXTURE_2D
);
312 glBindTexture(GL_TEXTURE_2D
, 1);
313 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, 4, 4, 0,
314 GL_RGBA
, GL_UNSIGNED_BYTE
, tex
);
316 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
317 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
319 Reshape(piglit_width
, piglit_height
);