cmake: move defaults into the per-platform section
[piglit.git] / tests / shaders / fp-lit-mask.c
blob0daa5eea42447ceb5687c69f4900ccb246c46cb9
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 whether LIT honours the output mask.
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 static GLuint FragProg[15];
42 static const char fragProgramTemplate[] =
43 "!!ARBfp1.0\n"
44 "PARAM values = { 0.65, 0.9, 0.0, 8.0 }; \n"
45 "PARAM bogus = { 0.8, 0.8, 0.8, 0.8 }; \n"
46 "MOV result.color, bogus; \n"
47 "LIT result.color.%s, values; \n"
48 "END\n";
49 static float LitExpected[4] = { 1.0, 0.65, 0.433, 1.0 };
51 static void DoFrame(void)
53 int mask;
55 glClearColor(0.0, 0.0, 0.0, 0.0);
56 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
58 glEnable(GL_FRAGMENT_PROGRAM_ARB);
60 for(mask = 1; mask < 16; ++mask) {
61 glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, FragProg[mask-1]);
62 glPushMatrix();
63 glTranslatef((mask % 4), (mask / 4), 0.0);
65 glBegin(GL_QUADS);
66 glVertex2f(0, 0);
67 glVertex2f(1, 0);
68 glVertex2f(1, 1);
69 glVertex2f(0, 1);
70 glEnd();
72 glPopMatrix();
76 static int DoTest( void )
78 int mask;
79 GLfloat dmax;
81 dmax = 0;
83 for(mask = 1; mask < 16; ++mask) {
84 GLfloat probe[4];
85 GLfloat delta[4];
86 int i;
88 glReadPixels(piglit_width * (2*(mask%4)+1)/8,
89 piglit_height * (2*(mask/4)+1)/8, 1, 1,
90 GL_RGBA, GL_FLOAT, probe);
92 printf("Probe %i: %f,%f,%f,%f\n", mask, probe[0], probe[1], probe[2], probe[3]);
94 for(i = 0; i < 4; ++i) {
95 if (mask & (1 << i))
96 delta[i] = probe[i] - LitExpected[i];
97 else
98 delta[i] = probe[i] - 0.8;
100 if (delta[i] > dmax) dmax = delta[i];
101 else if (-delta[i] > dmax) dmax = -delta[i];
104 printf(" Delta: %f,%f,%f,%f\n", delta[0], delta[1], delta[2], delta[3]);
107 printf("Max delta: %f\n", dmax);
109 if (dmax >= 0.02)
110 return 0;
111 else
112 return 1;
115 enum piglit_result
116 piglit_display(void)
118 int pass;
120 DoFrame();
121 pass = DoTest();
122 piglit_present_results();
124 return pass ? PIGLIT_PASS : PIGLIT_FAIL;
127 void piglit_init(int argc, char **argv)
129 int mask;
131 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
133 piglit_require_fragment_program();
136 * Fragment programs
138 for(mask = 1; mask < 16; ++mask) {
139 char programText[1024];
140 char maskstring[5];
142 maskstring[0] = 0;
143 if (mask & 1) strcat(maskstring, "x");
144 if (mask & 2) strcat(maskstring, "y");
145 if (mask & 4) strcat(maskstring, "z");
146 if (mask & 8) strcat(maskstring, "w");
147 sprintf(programText, fragProgramTemplate, maskstring);
149 FragProg[mask-1] = piglit_compile_program(GL_FRAGMENT_PROGRAM_ARB, programText);
152 piglit_ortho_projection(4.0, 4.0, GL_FALSE);