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 ABS instruction in GL_ARB_fragment_program
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 "ATTRIB input0 = fragment.texcoord[0];\n"
49 "ATTRIB input1 = fragment.texcoord[1];\n"
52 "MOV R2, {0.0, 0.0, 0.0, 1.0};\n"
54 "# Assume that input1.x is 1.0. COS(PI) is -1. This means\n"
55 "# that R2.y should end up with -1.0.\n"
56 "MUL R0, input1.x, 3.14159265358979323846;\n"
58 "DP4 R2.y, R0, 0.25;\n"
60 "ABS result.color, R2;\n"
64 static const char sge_shader_source
[] =
66 "ATTRIB input0 = fragment.texcoord[0];\n"
67 "ATTRIB input1 = fragment.texcoord[1];\n"
70 "MOV R2, {0.0, 1.0, 0.0, 1.0};\n"
72 "# By convention, all components of input0 are < 0.0, and\n"
73 "# input0 = -input1.\n"
74 "# The dot-product compacts the four components into a single\n"
75 "# component. R2.x should be 0.0.\n"
77 "ADD R0, -input1, R1;\n"
78 "SGE R1, R0, 1e-15;\n"
79 "SLT R0, R0, -1e-15;\n"
84 "# If R2.x is not 0.0 as it should be, set R2.y != 1.0\n"
85 "DP3 R1, R2.xxxx, 1.0;\n"
88 "MOV result.color, R2;\n"
93 static const char vert_shader_source
[] =
95 "ATTRIB iPos = vertex.position;\n"
96 "OUTPUT oPos = result.position;\n"
97 "PARAM mvp[4] = { state.matrix.mvp };\n"
98 "DP4 oPos.x, mvp[0], iPos;\n"
99 "DP4 oPos.y, mvp[1], iPos;\n"
100 "DP4 oPos.z, mvp[2], iPos;\n"
101 "DP4 oPos.w, mvp[3], iPos;\n"
102 "MOV result.texcoord[0], -vertex.color;\n"
103 "MOV result.texcoord[1], vertex.color;\n"
108 * \name Handles to fragment programs.
111 static GLint progs
[TEST_COLS
];
112 static GLint vert_prog
;
119 static const GLfloat color
[4] = { 0.0, 1.0, 0.0, 0.0 };
120 enum piglit_result result
= PIGLIT_SUCCESS
;
123 glClear(GL_COLOR_BUFFER_BIT
);
124 glEnable(GL_FRAGMENT_PROGRAM_ARB
);
125 glEnable(GL_VERTEX_PROGRAM_ARB
);
127 glColor4f(1.0, 0.6, 0.3, 0.1);
129 glBindProgramARB(GL_VERTEX_PROGRAM_ARB
, vert_prog
);
131 for (i
= 0; i
< ELEMENTS(progs
); i
++) {
132 const int x
= 1 + (i
* (BOX_SIZE
+ 1));
134 glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB
, progs
[i
]);
136 piglit_draw_rect(x
, 1, BOX_SIZE
, BOX_SIZE
);
138 if (!piglit_probe_pixel_rgb(x
+ (BOX_SIZE
/ 2),
141 result
= PIGLIT_FAILURE
;
151 piglit_init(int argc
, char **argv
)
156 piglit_require_vertex_program();
157 piglit_require_fragment_program();
158 piglit_ortho_projection(piglit_width
, piglit_height
, GL_FALSE
);
160 progs
[0] = piglit_compile_program(GL_FRAGMENT_PROGRAM_ARB
,
162 progs
[1] = piglit_compile_program(GL_FRAGMENT_PROGRAM_ARB
,
165 vert_prog
= piglit_compile_program(GL_VERTEX_PROGRAM_ARB
,
168 glClearColor(0.5, 0.5, 0.5, 1.0);