Add more structure constructor tests.
[piglit/hramrach.git] / tests / shaders / fp-kil.c
blob7ce1a29ee09149bdca08036c381bdf9659db7e77
1 /*
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
13 * Software.
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.
24 /**
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] = {
38 "!!ARBfp1.0\n"
39 "TEMP r0;\n"
40 "MOV result.color, fragment.color;\n"
41 "KIL fragment.texcoord[0];\n"
42 "END",
44 "!!ARBfp1.0\n"
45 "TEMP r0;\n"
46 "TEX r0, fragment.texcoord[0], texture[0], 2D;\n"
47 "KIL -r0;\n"
48 "MOV result.color, fragment.color;\n"
49 "END"
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);
62 glBegin(GL_QUADS);
63 glTexCoord2f(-1, -1);
64 glVertex2f(0, 0);
65 glTexCoord2f(1, -1);
66 glVertex2f(1, 0);
67 glTexCoord2f(1, 1);
68 glVertex2f(1, 1);
69 glTexCoord2f(-1, 1);
70 glVertex2f(0, 1);
71 glEnd();
73 glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, FragProg[1]);
75 glBegin(GL_QUADS);
76 glTexCoord2f(0, 0);
77 glVertex2f(0, 1);
78 glTexCoord2f(1, 0);
79 glVertex2f(1, 1);
80 glTexCoord2f(1, 1);
81 glVertex2f(1, 2);
82 glTexCoord2f(0, 1);
83 glVertex2f(0, 2);
84 glEnd();
86 glutSwapBuffers();
89 static const struct {
90 const char* name;
91 float x, y;
92 float expected[4];
93 } Probes[] = {
94 // Program 0
96 "basic #1",
97 0.2, 0.2,
98 { 0.0, 0.0, 0.0, 1.0 }
101 "basic #2",
102 0.8, 0.2,
103 { 0.0, 0.0, 0.0, 1.0 }
106 "basic #3",
107 0.8, 0.8,
108 { 0.0, 1.0, 0.0, 1.0 }
111 "basic #4",
112 0.2, 0.8,
113 { 0.0, 0.0, 0.0, 1.0 }
116 // Program 0
118 "texture #1",
119 0.125, 1.125,
120 { 0.0, 1.0, 0.0, 1.0 }
123 "texture #2",
124 0.375, 1.125,
125 { 0.0, 0.0, 0.0, 1.0 }
128 "texture #3",
129 0.625, 1.125,
130 { 0.0, 0.0, 0.0, 1.0 }
133 "texture #4",
134 0.875, 1.125,
135 { 0.0, 0.0, 0.0, 1.0 }
138 "texture #5",
139 0.125, 1.375,
140 { 0.0, 0.0, 0.0, 1.0 }
143 "texture #6",
144 0.375, 1.375,
145 { 0.0, 0.0, 0.0, 1.0 }
148 "texture #7",
149 0.625, 1.375,
150 { 0.0, 0.0, 0.0, 1.0 }
153 "texture #8",
154 0.875, 1.375,
155 { 0.0, 0.0, 0.0, 1.0 }
158 "texture #9",
159 0.125, 1.625,
160 { 0.0, 0.0, 0.0, 1.0 }
163 "texture #10",
164 0.375, 1.625,
165 { 0.0, 0.0, 0.0, 1.0 }
168 "texture #11",
169 0.625, 1.625,
170 { 0.0, 0.0, 0.0, 1.0 }
173 "texture #12",
174 0.875, 1.625,
175 { 0.0, 0.0, 0.0, 1.0 }
178 "texture #13",
179 0.125, 1.875,
180 { 0.0, 0.0, 0.0, 1.0 }
183 "texture #14",
184 0.375, 1.875,
185 { 0.0, 0.0, 0.0, 1.0 }
188 "texture #15",
189 0.625, 1.875,
190 { 0.0, 0.0, 0.0, 1.0 }
193 "texture #16",
194 0.875, 1.875,
195 { 0.0, 0.0, 0.0, 1.0 }
198 // Sentinel!
201 0, 0,
202 { 0, 0, 0, 0 }
206 static int DoTest( void )
208 int idx;
209 GLfloat dmax;
211 glReadBuffer( GL_FRONT );
212 dmax = 0;
214 idx = 0;
215 while(Probes[idx].name) {
216 GLfloat probe[4];
217 GLfloat delta[4];
218 int i;
220 glReadPixels((int)(Probes[idx].x*piglit_width/2),
221 (int)(Probes[idx].y*piglit_height/2),
222 1, 1,
223 GL_RGBA, GL_FLOAT, probe);
225 printf("%20s (%3.1f,%3.1f): %f,%f,%f,%f",
226 Probes[idx].name,
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]);
239 idx++;
242 printf("Max delta: %f\n", dmax);
244 if (dmax >= 0.02)
245 return 0;
246 else
247 return 1;
250 enum piglit_result
251 piglit_display(void)
253 int pass;
255 DoFrame();
256 pass = DoTest();
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);
268 glLoadIdentity();
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);
272 glLoadIdentity();
275 void
276 piglit_init(int argc, char **argv)
278 int i, x, y;
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();
293 * Fragment programs
295 for(i = 0; i < NUM_PROGRAMS; ++i)
296 FragProg[i] = piglit_compile_program(GL_FRAGMENT_PROGRAM_ARB, ProgramText[i]);
299 * Textures
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);