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 absolute value operand modifier in GL_NV_fragment_program_option
28 * \author Ian Romanick <ian.d.romanick@intel.com>
31 #include "piglit-util-gl.h"
37 PIGLIT_GL_TEST_CONFIG_BEGIN
39 config
.supports_gl_compat_version
= 10;
41 config
.window_width
= (((BOX_SIZE
+1)*TEST_COLS
)+1);
42 config
.window_height
= (((BOX_SIZE
+1)*TEST_ROWS
)+1);
43 config
.window_visual
= PIGLIT_GL_VISUAL_RGB
| PIGLIT_GL_VISUAL_DOUBLE
;
45 PIGLIT_GL_TEST_CONFIG_END
47 static const char cos_shader_source
[] =
49 "OPTION NV_fragment_program;\n"
50 "ATTRIB input0 = fragment.texcoord[0];\n"
51 "ATTRIB input1 = fragment.texcoord[1];\n"
54 "MOV R2, {0.0, 0.0, 0.0, 1.0};\n"
56 "# Assume that input1.x is 1.0. COS(PI) is -1. This means\n"
57 "# that R2.y should end up with -1.0.\n"
58 "MUL R0, input1.x, 3.14159265358979323846;\n"
60 "DP4 R2.y, R0, 0.25;\n"
62 "MOV result.color, |R2|;\n"
66 static const char sne_shader_source
[] =
68 "OPTION NV_fragment_program;\n"
69 "ATTRIB input0 = fragment.texcoord[0];\n"
70 "ATTRIB input1 = fragment.texcoord[1];\n"
73 "MOV R2, {0.0, 1.0, 0.0, 1.0};\n"
75 "# By convention, all components of input0 are < 0.0, and\n"
76 "# input0 = -input1.\n"
77 "# The dot-product compacts the four components into a single\n"
78 "# component. R2.x should be 0.0.\n"
79 "ADD R0, -input1, |input0|;\n"
81 "DP4 R2.x, R1, 1.0;\n"
83 "# If R2.x is not 0.0 as it should be, set R2.y != 1.0\n"
84 "DP3 R1, R2.xxxx, 1.0;\n"
87 "MOV result.color, R2;\n"
91 static const char addc_shader_source
[] =
93 "OPTION NV_fragment_program;\n"
94 "ATTRIB input0 = fragment.texcoord[0];\n"
95 "ATTRIB input1 = fragment.texcoord[1];\n"
98 "MOV R2, {0.0, 1.0, 0.0, 1.0};\n"
100 "# By convention, all components of input0 are < 0.0, and\n"
101 "# input0 = -input1.\n"
102 "# The dot-product compacts the four components into a single\n"
103 "# component. R2.x should be 0.0.\n"
104 "ADDC R0, -input1, |input0|;\n"
105 "MOV R1 (NE), 1.0;\n"
106 "DP4 R2.x, R1, 1.0;\n"
108 "# If R2.x is not 0.0 as it should be, set R2.y != 1.0\n"
109 "DP3 R1, R2.xxxx, 1.0;\n"
110 "SUB R2.y, R2, R1;\n"
112 "MOV result.color, R2;\n"
116 static const char vert_shader_source
[] =
118 "ATTRIB iPos = vertex.position;\n"
119 "OUTPUT oPos = result.position;\n"
120 "PARAM mvp[4] = { state.matrix.mvp };\n"
121 "DP4 oPos.x, mvp[0], iPos;\n"
122 "DP4 oPos.y, mvp[1], iPos;\n"
123 "DP4 oPos.z, mvp[2], iPos;\n"
124 "DP4 oPos.w, mvp[3], iPos;\n"
125 "MOV result.texcoord[0], -vertex.color;\n"
126 "MOV result.texcoord[1], vertex.color;\n"
131 * \name Handles to fragment programs.
134 static GLint progs
[TEST_COLS
];
135 static GLint vert_prog
;
142 static const GLfloat color
[4] = { 0.0, 1.0, 0.0, 0.0 };
143 enum piglit_result result
= PIGLIT_PASS
;
146 glClear(GL_COLOR_BUFFER_BIT
);
147 glEnable(GL_FRAGMENT_PROGRAM_ARB
);
148 glEnable(GL_VERTEX_PROGRAM_ARB
);
150 glColor4f(1.0, 0.6, 0.3, 0.1);
152 glBindProgramARB(GL_VERTEX_PROGRAM_ARB
, vert_prog
);
154 for (i
= 0; i
< ARRAY_SIZE(progs
); i
++) {
155 const int x
= 1 + (i
* (BOX_SIZE
+ 1));
157 glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB
, progs
[i
]);
159 piglit_draw_rect(x
, 1, BOX_SIZE
, BOX_SIZE
);
161 if (!piglit_probe_pixel_rgb(x
+ (BOX_SIZE
/ 2),
164 result
= PIGLIT_FAIL
;
168 piglit_present_results();
174 piglit_init(int argc
, char **argv
)
179 piglit_require_vertex_program();
180 piglit_require_fragment_program();
181 piglit_require_extension("GL_NV_fragment_program_option");
182 piglit_ortho_projection(piglit_width
, piglit_height
, GL_FALSE
);
184 progs
[0] = piglit_compile_program(GL_FRAGMENT_PROGRAM_ARB
,
186 progs
[1] = piglit_compile_program(GL_FRAGMENT_PROGRAM_ARB
,
188 progs
[2] = piglit_compile_program(GL_FRAGMENT_PROGRAM_ARB
,
191 vert_prog
= piglit_compile_program(GL_VERTEX_PROGRAM_ARB
,
194 glClearColor(0.5, 0.5, 0.5, 1.0);