cmake: move defaults into the per-platform section
[piglit.git] / tests / shaders / fp-kil.c
bloba29221ca1f85e8e02e2391cf642016d642f928b6
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-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_RGB | PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_DEPTH;
38 PIGLIT_GL_TEST_CONFIG_END
40 #define NUM_PROGRAMS 2
42 static GLuint FragProg[NUM_PROGRAMS];
44 static const char* const ProgramText[NUM_PROGRAMS] = {
45 "!!ARBfp1.0\n"
46 "TEMP r0;\n"
47 "MOV result.color, fragment.color;\n"
48 "KIL fragment.texcoord[0];\n"
49 "END",
51 "!!ARBfp1.0\n"
52 "TEMP r0;\n"
53 "TEX r0, fragment.texcoord[0], texture[0], 2D;\n"
54 "KIL -r0;\n"
55 "MOV result.color, fragment.color;\n"
56 "END"
59 static void DoFrame(void)
61 glClearColor(0.0, 0.0, 0.0, 1.0);
62 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
64 glEnable(GL_FRAGMENT_PROGRAM_ARB);
66 glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, FragProg[0]);
68 glColor3f(0.0, 1.0, 0.0);
69 glBegin(GL_QUADS);
70 glTexCoord2f(-1, -1);
71 glVertex2f(0, 0);
72 glTexCoord2f(1, -1);
73 glVertex2f(1, 0);
74 glTexCoord2f(1, 1);
75 glVertex2f(1, 1);
76 glTexCoord2f(-1, 1);
77 glVertex2f(0, 1);
78 glEnd();
80 glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, FragProg[1]);
82 glBegin(GL_QUADS);
83 glTexCoord2f(0, 0);
84 glVertex2f(0, 1);
85 glTexCoord2f(1, 0);
86 glVertex2f(1, 1);
87 glTexCoord2f(1, 1);
88 glVertex2f(1, 2);
89 glTexCoord2f(0, 1);
90 glVertex2f(0, 2);
91 glEnd();
94 static const struct {
95 const char* name;
96 float x, y;
97 float expected[4];
98 } Probes[] = {
99 // Program 0
101 "basic #1",
102 0.2, 0.2,
103 { 0.0, 0.0, 0.0, 1.0 }
106 "basic #2",
107 0.8, 0.2,
108 { 0.0, 0.0, 0.0, 1.0 }
111 "basic #3",
112 0.8, 0.8,
113 { 0.0, 1.0, 0.0, 1.0 }
116 "basic #4",
117 0.2, 0.8,
118 { 0.0, 0.0, 0.0, 1.0 }
121 // Program 1
123 "texture #1",
124 0.125, 1.125,
125 { 0.0, 1.0, 0.0, 1.0 }
128 "texture #2",
129 0.375, 1.125,
130 { 0.0, 0.0, 0.0, 1.0 }
133 "texture #3",
134 0.625, 1.125,
135 { 0.0, 0.0, 0.0, 1.0 }
138 "texture #4",
139 0.875, 1.125,
140 { 0.0, 0.0, 0.0, 1.0 }
143 "texture #5",
144 0.125, 1.375,
145 { 0.0, 0.0, 0.0, 1.0 }
148 "texture #6",
149 0.375, 1.375,
150 { 0.0, 0.0, 0.0, 1.0 }
153 "texture #7",
154 0.625, 1.375,
155 { 0.0, 0.0, 0.0, 1.0 }
158 "texture #8",
159 0.875, 1.375,
160 { 0.0, 0.0, 0.0, 1.0 }
163 "texture #9",
164 0.125, 1.625,
165 { 0.0, 0.0, 0.0, 1.0 }
168 "texture #10",
169 0.375, 1.625,
170 { 0.0, 0.0, 0.0, 1.0 }
173 "texture #11",
174 0.625, 1.625,
175 { 0.0, 0.0, 0.0, 1.0 }
178 "texture #12",
179 0.875, 1.625,
180 { 0.0, 0.0, 0.0, 1.0 }
183 "texture #13",
184 0.125, 1.875,
185 { 0.0, 0.0, 0.0, 1.0 }
188 "texture #14",
189 0.375, 1.875,
190 { 0.0, 0.0, 0.0, 1.0 }
193 "texture #15",
194 0.625, 1.875,
195 { 0.0, 0.0, 0.0, 1.0 }
198 "texture #16",
199 0.875, 1.875,
200 { 0.0, 0.0, 0.0, 1.0 }
203 // Sentinel!
206 0, 0,
207 { 0, 0, 0, 0 }
211 static bool DoTest( void )
213 int idx = 0;
214 bool pass = true;
216 while(Probes[idx].name) {
217 pass = piglit_probe_pixel_rgba(
218 (int)(Probes[idx].x*piglit_width/2),
219 (int)(Probes[idx].y*piglit_height/2),
220 Probes[idx].expected) && pass;
221 idx++;
224 return pass;
227 enum piglit_result
228 piglit_display(void)
230 bool pass;
232 piglit_gen_ortho_projection(0.0, 2.0, 0.0, 2.0, -2.0, 6.0, GL_FALSE);
234 DoFrame();
235 pass = DoTest();
236 piglit_present_results();
238 return pass ? PIGLIT_PASS : PIGLIT_FAIL;
241 void
242 piglit_init(int argc, char **argv)
244 int i, x, y;
245 GLuint texname;
246 GLubyte tex[4][4][4];
248 piglit_require_gl_version(13);
250 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
252 piglit_require_fragment_program();
255 * Fragment programs
257 for(i = 0; i < NUM_PROGRAMS; ++i)
258 FragProg[i] = piglit_compile_program(GL_FRAGMENT_PROGRAM_ARB, ProgramText[i]);
261 * Textures
263 for(y = 0; y < 4; ++y) {
264 for(x = 0; x < 4; ++x) {
265 tex[y][x][0] = (x & 1) ? 255 : 0;
266 tex[y][x][1] = (x & 2) ? 255 : 0;
267 tex[y][x][2] = (y & 1) ? 255 : 0;
268 tex[y][x][3] = (y & 2) ? 255 : 0;
272 glGenTextures(1, &texname);
273 glActiveTexture(GL_TEXTURE0);
274 glEnable(GL_TEXTURE_2D);
275 glBindTexture(GL_TEXTURE_2D, texname);
276 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 4, 4, 0,
277 GL_RGBA, GL_UNSIGNED_BYTE, tex);
279 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
280 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);