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
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
26 * Validate all of the set-on instructions in GL_NV_fragment_program_option
28 * Each set-on instruction is validated by comparing the value 0.5 with all
29 * combinations 0.0, 0.5, and 1.0 on the four channels. Reference squares are
30 * even rows, and testing squares are on odd rows.
32 * \author Ian Romanick <ian.d.romanick@intel.com>
35 #include "piglit-util-gl.h"
37 typedef int (cmp_func
)(float a
, float b
);
39 static int eq_func(float a
, float b
);
40 static int fl_func(float a
, float b
);
41 static int ge_func(float a
, float b
);
42 static int gt_func(float a
, float b
);
43 static int le_func(float a
, float b
);
44 static int lt_func(float a
, float b
);
45 static int ne_func(float a
, float b
);
46 static int tr_func(float a
, float b
);
62 /* One column for each possible combination of set-on results
64 #define TEST_COLS (3 * 3 * 3 * 3)
66 /* One for each set-on opcode and its reference square.
68 #define TEST_ROWS (ARRAY_SIZE(tests) * 2)
72 PIGLIT_GL_TEST_CONFIG_BEGIN
74 config
.supports_gl_compat_version
= 10;
76 config
.window_width
= (((BOX_SIZE
+1)*TEST_COLS
)+1);
77 config
.window_height
= (((BOX_SIZE
+1)*TEST_ROWS
)+1);
78 config
.window_visual
= PIGLIT_GL_VISUAL_RGB
| PIGLIT_GL_VISUAL_DOUBLE
;
80 PIGLIT_GL_TEST_CONFIG_END
83 * Source for the fragment program to render the reference box.
85 static const char reference_shader_source
[] =
87 "MOV result.color, program.env[0];\n"
91 static const char shader_template
[] =
93 "OPTION NV_fragment_program;\n"
94 "%s result.color, program.env[1], fragment.color;\n"
100 * \name Handles to fragment programs.
103 static GLint reference_prog
;
104 static GLint progs
[ARRAY_SIZE(tests
)];
108 eq_func(float a
, float b
)
114 fl_func(float a
, float b
)
120 ge_func(float a
, float b
)
126 gt_func(float a
, float b
)
132 le_func(float a
, float b
)
139 lt_func(float a
, float b
)
145 ne_func(float a
, float b
)
151 tr_func(float a
, float b
)
160 const GLfloat comparator
[4] = { 0.5, 0.5, 0.5, 0.5 };
161 static const float values
[3] = { 0.0, 0.5, 1.0 };
164 enum piglit_result result
= PIGLIT_PASS
;
168 glClear(GL_COLOR_BUFFER_BIT
);
169 glEnable(GL_FRAGMENT_PROGRAM_ARB
);
171 glProgramEnvParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB
, 1, comparator
);
173 for (i
= 0; i
< (2 * ARRAY_SIZE(progs
)); i
++) {
174 const int y
= (i
* (BOX_SIZE
+ 1)) + 1;
175 const unsigned idx
= i
>> 1;
178 glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB
,
181 glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB
,
185 for (j
= 0; j
< (3 * 3 * 3 * 3); j
++) {
186 const int x
= (j
* (BOX_SIZE
+ 1)) + 1;
188 /* Determine the color of the reference square.
189 * This depends on both the set-on function and
192 ref
[0] = values
[j
% 3];
193 ref
[1] = values
[(j
/ 3) % 3];
194 ref
[2] = values
[(j
/ 9) % 3];
195 ref
[3] = values
[(j
/ 27) % 3];
197 color
[0] = tests
[idx
].func(comparator
[0], ref
[0])
199 color
[1] = tests
[idx
].func(comparator
[1], ref
[1])
201 color
[2] = tests
[idx
].func(comparator
[2], ref
[2])
203 color
[3] = tests
[idx
].func(comparator
[3], ref
[3])
206 glProgramEnvParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB
,
210 piglit_draw_rect(x
, y
, BOX_SIZE
, BOX_SIZE
);
214 if (!piglit_probe_pixel_rgb(x
+ (BOX_SIZE
/ 2),
217 if (!piglit_automatic
)
218 printf("%s failed on ref = "
219 "{ %.01f %.01f %.01f %.01f }\n",
221 ref
[0], ref
[1], ref
[2], ref
[2]);
223 result
= PIGLIT_FAIL
;
229 piglit_present_results();
235 piglit_init(int argc
, char **argv
)
242 piglit_require_fragment_program();
243 piglit_require_extension("GL_NV_fragment_program_option");
244 piglit_ortho_projection(piglit_width
, piglit_height
, GL_FALSE
);
246 reference_prog
= piglit_compile_program(GL_FRAGMENT_PROGRAM_ARB
,
247 reference_shader_source
);
249 for (i
= 0; i
< ARRAY_SIZE(tests
); i
++) {
250 char shader_source
[512];
252 sprintf(shader_source
, shader_template
, tests
[i
].opcode
);
253 progs
[i
] = piglit_compile_program(GL_FRAGMENT_PROGRAM_ARB
,
258 glClearColor(0.5, 0.5, 0.5, 1.0);