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.h"
32 #include "piglit-framework.h"
38 #define ELEMENTS(x) (sizeof(x) / sizeof(x[0]))
40 int piglit_window_mode
= GLUT_DOUBLE
;
41 int piglit_width
= (((BOX_SIZE
+1)*TEST_COLS
)+1);
42 int piglit_height
= (((BOX_SIZE
+1)*TEST_ROWS
)+1);
46 static const char cos_shader_source
[] =
48 "OPTION NV_fragment_program;\n"
49 "ATTRIB input0 = fragment.texcoord[0];\n"
50 "ATTRIB input1 = fragment.texcoord[1];\n"
53 "MOV R2, {0.0, 0.0, 0.0, 1.0};\n"
55 "# Assume that input1.x is 1.0. COS(PI) is -1. This means\n"
56 "# that R2.y should end up with -1.0.\n"
57 "MUL R0, input1.x, 3.14159265358979323846;\n"
59 "DP4 R2.y, R0, 0.25;\n"
61 "MOV result.color, |R2|;\n"
65 static const char sne_shader_source
[] =
67 "OPTION NV_fragment_program;\n"
68 "ATTRIB input0 = fragment.texcoord[0];\n"
69 "ATTRIB input1 = fragment.texcoord[1];\n"
72 "MOV R2, {0.0, 1.0, 0.0, 1.0};\n"
74 "# By convention, all components of input0 are < 0.0, and\n"
75 "# input0 = -input1.\n"
76 "# The dot-product compacts the four components into a single\n"
77 "# component. R2.x should be 0.0.\n"
78 "ADD R0, -input1, |input0|;\n"
80 "DP4 R2.x, R1, 1.0;\n"
82 "# If R2.x is not 0.0 as it should be, set R2.y != 1.0\n"
83 "DP3 R1, R2.xxxx, 1.0;\n"
86 "MOV result.color, R2;\n"
90 static const char addc_shader_source
[] =
92 "OPTION NV_fragment_program;\n"
93 "ATTRIB input0 = fragment.texcoord[0];\n"
94 "ATTRIB input1 = fragment.texcoord[1];\n"
97 "MOV R2, {0.0, 1.0, 0.0, 1.0};\n"
99 "# By convention, all components of input0 are < 0.0, and\n"
100 "# input0 = -input1.\n"
101 "# The dot-product compacts the four components into a single\n"
102 "# component. R2.x should be 0.0.\n"
103 "ADDC R0, -input1, |input0|;\n"
104 "MOV R1 (NE), 1.0;\n"
105 "DP4 R2.x, R1, 1.0;\n"
107 "# If R2.x is not 0.0 as it should be, set R2.y != 1.0\n"
108 "DP3 R1, R2.xxxx, 1.0;\n"
109 "SUB R2.y, R2, R1;\n"
111 "MOV result.color, R2;\n"
115 static const char vert_shader_source
[] =
117 "ATTRIB iPos = vertex.position;\n"
118 "OUTPUT oPos = result.position;\n"
119 "PARAM mvp[4] = { state.matrix.mvp };\n"
120 "DP4 oPos.x, mvp[0], iPos;\n"
121 "DP4 oPos.y, mvp[1], iPos;\n"
122 "DP4 oPos.z, mvp[2], iPos;\n"
123 "DP4 oPos.w, mvp[3], iPos;\n"
124 "MOV result.texcoord[0], -vertex.color;\n"
125 "MOV result.texcoord[1], vertex.color;\n"
130 * \name Handles to fragment programs.
133 static GLint progs
[TEST_COLS
];
134 static GLint vert_prog
;
141 static const GLfloat color
[4] = { 0.0, 1.0, 0.0, 0.0 };
142 enum piglit_result result
= PIGLIT_SUCCESS
;
145 glClear(GL_COLOR_BUFFER_BIT
);
146 glEnable(GL_FRAGMENT_PROGRAM_ARB
);
147 glEnable(GL_VERTEX_PROGRAM_ARB
);
149 glColor4f(1.0, 0.6, 0.3, 0.1);
151 glBindProgramARB(GL_VERTEX_PROGRAM_ARB
, vert_prog
);
153 for (i
= 0; i
< ELEMENTS(progs
); i
++) {
154 const int x
= 1 + (i
* (BOX_SIZE
+ 1));
156 glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB
, progs
[i
]);
158 piglit_draw_rect(x
, 1, BOX_SIZE
, BOX_SIZE
);
160 if (!piglit_probe_pixel_rgb(x
+ (BOX_SIZE
/ 2),
163 result
= PIGLIT_FAILURE
;
173 piglit_init(int argc
, char **argv
)
178 piglit_require_vertex_program();
179 piglit_require_fragment_program();
180 piglit_require_extension("GL_NV_fragment_program_option");
181 piglit_ortho_projection(piglit_width
, piglit_height
, GL_FALSE
);
183 progs
[0] = piglit_compile_program(GL_FRAGMENT_PROGRAM_ARB
,
185 progs
[1] = piglit_compile_program(GL_FRAGMENT_PROGRAM_ARB
,
187 progs
[2] = piglit_compile_program(GL_FRAGMENT_PROGRAM_ARB
,
190 vert_prog
= piglit_compile_program(GL_VERTEX_PROGRAM_ARB
,
193 glClearColor(0.5, 0.5, 0.5, 1.0);