fix the spelling in whole piglit
[piglit.git] / tests / shaders / fp-set-01.c
blob76045590731896d30a21f0991baae2663cdd610c
1 /*
2 * Copyright © 2009 Intel Corporation
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 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * 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 NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
24 /**
25 * \file fp-set-01.c
26 * Validate the two set-on instructions in GL_ARB_fragment_program
28 * \author Ian Romanick <ian.d.romanick@intel.com>
31 #include "piglit-util-gl.h"
33 /* One column for each possible combination of set-on results
35 #define TEST_COLS 16
37 /* One for the reference square and each of the 2 set-on instructions
39 #define TEST_ROWS 3
41 #define BOX_SIZE 16
43 PIGLIT_GL_TEST_CONFIG_BEGIN
45 config.supports_gl_compat_version = 10;
47 config.window_width = (((BOX_SIZE+1)*TEST_COLS)+1);
48 config.window_height = (((BOX_SIZE+1)*TEST_ROWS)+1);
49 config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
51 PIGLIT_GL_TEST_CONFIG_END
53 /**
54 * Source for the fragment program to render the reference box.
56 static const char reference_shader_source[] =
57 "!!ARBfp1.0\n"
58 "MOV result.color, program.env[0];\n"
59 "END"
62 static const char slt_shader_source[] =
63 "!!ARBfp1.0\n"
64 "SLT result.color, program.env[1], fragment.color;\n"
65 "END"
68 static const char sge_shader_source[] =
69 "!!ARBfp1.0\n"
70 "SGE result.color, fragment.color, program.env[1];\n"
71 "END"
74 /**
75 * \name Handles to fragment programs.
77 /*@{*/
78 static GLint reference_prog;
79 static GLint progs[2];
80 /*@}*/
83 enum piglit_result
84 piglit_display(void)
86 const GLfloat comparator[4] = { 0.5, 0.5, 0.5, 0.5 };
87 unsigned i;
88 unsigned j;
89 enum piglit_result result = PIGLIT_PASS;
92 glClear(GL_COLOR_BUFFER_BIT);
93 glEnable(GL_FRAGMENT_PROGRAM_ARB);
95 for (i = 0; i < TEST_COLS; i++) {
96 const int x = (i * (BOX_SIZE + 1)) + 1;
97 GLfloat color[4];
99 color[0] = (i & 0x01) ? 1.0 : 0.0;
100 color[1] = (i & 0x02) ? 1.0 : 0.0;
101 color[2] = (i & 0x04) ? 1.0 : 0.0;
102 color[3] = (i & 0x08) ? 1.0 : 0.0;
104 glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, reference_prog);
106 glProgramEnvParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, 0,
107 color);
108 glProgramEnvParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, 1,
109 comparator);
111 piglit_draw_rect(x, 1, BOX_SIZE, BOX_SIZE);
113 glColor4fv(color);
115 for (j = 0; j < ARRAY_SIZE(progs); j++) {
116 const int y = ((j + 1) * (BOX_SIZE + 1)) + 1;
118 glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, progs[j]);
119 piglit_draw_rect(x, y, BOX_SIZE, BOX_SIZE);
121 if (!piglit_probe_pixel_rgb(x + (BOX_SIZE / 2),
122 y + (BOX_SIZE / 2),
123 color)) {
124 if (!piglit_automatic)
125 printf("shader %u failed on index %u\n",
126 j, i);
128 result = PIGLIT_FAIL;
133 piglit_present_results();
134 return result;
138 void
139 piglit_init(int argc, char **argv)
141 (void) argc;
142 (void) argv;
144 piglit_require_fragment_program();
145 piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
147 reference_prog = piglit_compile_program(GL_FRAGMENT_PROGRAM_ARB,
148 reference_shader_source);
150 progs[0] = piglit_compile_program(GL_FRAGMENT_PROGRAM_ARB,
151 slt_shader_source);
152 progs[1] = piglit_compile_program(GL_FRAGMENT_PROGRAM_ARB,
153 sge_shader_source);
155 glClearColor(1.0, 1.0, 1.0, 1.0);