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 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
37 /* One for the reference square and each of the 2 set-on instructions
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
54 * Source for the fragment program to render the reference box.
56 static const char reference_shader_source
[] =
58 "MOV result.color, program.env[0];\n"
62 static const char slt_shader_source
[] =
64 "SLT result.color, program.env[1], fragment.color;\n"
68 static const char sge_shader_source
[] =
70 "SGE result.color, fragment.color, program.env[1];\n"
75 * \name Handles to fragment programs.
78 static GLint reference_prog
;
79 static GLint progs
[2];
86 const GLfloat comparator
[4] = { 0.5, 0.5, 0.5, 0.5 };
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;
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,
108 glProgramEnvParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB
, 1,
111 piglit_draw_rect(x
, 1, BOX_SIZE
, BOX_SIZE
);
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),
124 if (!piglit_automatic
)
125 printf("shader %u failed on index %u\n",
128 result
= PIGLIT_FAIL
;
133 piglit_present_results();
139 piglit_init(int argc
, char **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
,
152 progs
[1] = piglit_compile_program(GL_FRAGMENT_PROGRAM_ARB
,
155 glClearColor(1.0, 1.0, 1.0, 1.0);