2 * Copyright (c) The Piglit project 2007
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 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the 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 NON-INFRINGEMENT. IN NO EVENT SHALL
18 * VA LINUX SYSTEM, IBM AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE.
25 * Test a fragment program that
26 * \sa http://www.mail-archive.com/dri-devel%40lists.sourceforge.net/msg30180.html
29 #include "piglit-util-gl.h"
31 PIGLIT_GL_TEST_CONFIG_BEGIN
33 config
.supports_gl_compat_version
= 10;
35 config
.window_width
= 200;
36 config
.window_visual
= PIGLIT_GL_VISUAL_RGB
| PIGLIT_GL_VISUAL_DOUBLE
| PIGLIT_GL_VISUAL_DEPTH
;
38 PIGLIT_GL_TEST_CONFIG_END
40 static GLuint TexDiffuse
;
41 static GLuint TexNormal
;
42 static GLuint TexSpecular
;
43 static GLuint TexLookup
;
45 static GLuint FragProg
;
47 static void DoFrame(void)
49 static float Local
[3][4] = {
50 { 1.0, 0.8, 1.0, 1.0 },
51 { 0.5, 0.5, 0.5, 1.0 },
52 { 1.0, 0.0, 0.0, 1.0 }
54 static float Local2
[3][4] = {
55 { 0.8, 1.0, 1.0, 1.0 },
56 { 0.5, 0.5, 0.5, 1.0 },
57 { 1.0, 0.0, 1.0, 1.0 }
61 glClearColor(0.8, 0.8, 0.8, 0.8);
62 glClear( GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
64 glActiveTexture(GL_TEXTURE0
);
65 glBindTexture(GL_TEXTURE_2D
, TexDiffuse
);
66 glEnable(GL_TEXTURE_2D
);
68 glActiveTexture(GL_TEXTURE1
);
69 glBindTexture(GL_TEXTURE_2D
, TexNormal
);
70 glEnable(GL_TEXTURE_2D
);
72 glActiveTexture(GL_TEXTURE2
);
73 glBindTexture(GL_TEXTURE_2D
, TexSpecular
);
74 glEnable(GL_TEXTURE_2D
);
76 glActiveTexture(GL_TEXTURE3
);
77 glBindTexture(GL_TEXTURE_2D
, TexLookup
);
78 glEnable(GL_TEXTURE_2D
);
80 glActiveTexture(GL_TEXTURE4
);
81 glBindTexture(GL_TEXTURE_2D
, TexLookup
);
82 glEnable(GL_TEXTURE_2D
);
84 glActiveTexture(GL_TEXTURE5
);
85 glBindTexture(GL_TEXTURE_2D
, TexLookup
);
86 glEnable(GL_TEXTURE_2D
);
88 glMultiTexCoord2f(GL_TEXTURE0
, 0.0, 0.0);
89 glMultiTexCoord2f(GL_TEXTURE1
, 0.0, 0.0);
90 glMultiTexCoord2f(GL_TEXTURE2
, 0.0, 0.0);
91 glMultiTexCoord3f(GL_TEXTURE3
, 0.0, 0.05, 0.25);
92 glMultiTexCoord3f(GL_TEXTURE4
, 4, -3, 0);
93 glMultiTexCoord3f(GL_TEXTURE5
, 0, 3, 4);
95 glEnable(GL_FRAGMENT_PROGRAM_ARB
);
96 for(i
= 0; i
< 3; ++i
)
97 glProgramLocalParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB
, i
, Local
[i
]);
100 glVertex2f(0.75, 0.75);
101 glVertex2f(0.25, 0.75);
102 glVertex2f(0.25, 0.25);
103 glVertex2f(0.75, 0.25);
106 glEnable(GL_FRAGMENT_PROGRAM_ARB
);
107 for(i
= 0; i
< 3; ++i
)
108 glProgramLocalParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB
, i
, Local2
[i
]);
111 glVertex2f(1.75, 0.75);
112 glVertex2f(1.25, 0.75);
113 glVertex2f(1.25, 0.25);
114 glVertex2f(1.75, 0.25);
121 static const float expected
[2][3] = {
122 { 0.30, 0.23, 0.40 },
128 for(i
= 0; i
< 2; ++i
) {
129 pass
= pass
&& piglit_probe_pixel_rgb(piglit_width
*(2*i
+1)/4,
145 piglit_present_results();
147 return succ
? PIGLIT_PASS
: PIGLIT_FAIL
;
151 static void Reshape(int width
, int height
)
153 piglit_width
= width
;
154 piglit_height
= height
;
155 glViewport(0, 0, width
, height
);
156 glMatrixMode(GL_PROJECTION
);
158 glOrtho(0.0, 2.0, 0.0, 1.0, -1.0, 1.0);
159 glMatrixMode(GL_MODELVIEW
);
164 piglit_init(int argc
, char **argv
)
166 GLubyte data
[256][256][4];
169 static const char *fragProgramText
=
172 "# Copyright (C) 2006 Oliver McFadden <z3ro.geek@gmail.com>\n"
174 "# This program is free software; you can redistribute it and/or modify\n"
175 "# it under the terms of the GNU General Public License as published by\n"
176 "# the Free Software Foundation; either version 2 of the License, or\n"
177 "# (at your option) any later version.\n"
179 "# This program is distributed in the hope that it will be useful,\n"
180 "# but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
181 "# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
182 "# GNU General Public License for more details.\n"
184 "# You should have received a copy of the GNU General Public License\n"
185 "# along with this program; if not, write to the Free Software\n"
186 "# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n"
188 "TEMP H, L, N, V, attenuationxy, attenuationz, color, diffuse, dot, specular, tmp;\n"
190 "DP3 L.x, fragment.texcoord[4], fragment.texcoord[4];\n"
192 "MUL L.xyz, L.x, fragment.texcoord[4];\n"
194 "DP3 V.x, fragment.texcoord[5], fragment.texcoord[5];\n"
196 "MUL V.xyz, V.x, fragment.texcoord[5];\n"
199 "DP3 H.x, tmp, tmp;\n"
201 "MUL H.xyz, H.x, tmp;\n"
203 "TEX tmp.xyz, fragment.texcoord[1], texture[1], 2D;\n"
204 "MAD tmp.xyz, tmp, 2.0, -1.0;\n"
205 "DP3 N.x, tmp, tmp;\n"
207 "MUL N.xyz, N.x, tmp;\n"
209 "DP3_SAT dot.x, N, L;\n"
210 "MUL dot.xyz, program.local[0], dot.x;\n"
212 "TEX diffuse.xyz, fragment.texcoord[0], texture[0], 2D;\n"
214 "DP3_SAT tmp.x, N, H;\n"
215 "POW tmp.x, tmp.x, program.local[2].x;\n"
216 "TEX specular.xyz, fragment.texcoord[2], texture[2], 2D;\n"
217 "MUL specular.xyz, specular, program.local[0];\n"
218 "MUL specular.xyz, specular, tmp.x;\n"
220 "TEX attenuationxy.xyz, fragment.texcoord[3], texture[3], 2D;\n"
222 "MOV tmp.x, fragment.texcoord[3].z;\n"
224 "TEX attenuationz.xyz, tmp, texture[4], 2D;\n"
226 "MOV color, diffuse;\n"
227 "MUL color.xyz, color, dot;\n"
228 "ADD color.xyz, color, specular;\n"
229 "MUL color.xyz, color, attenuationxy;\n"
230 "MUL color.xyz, color, attenuationz;\n"
231 "MUL color.xyz, color, program.local[1].x;\n"
232 "MOV result.color, color;\n"
236 piglit_require_gl_version(13);
238 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER
));
240 piglit_require_fragment_program();
241 FragProg
= piglit_compile_program(GL_FRAGMENT_PROGRAM_ARB
, fragProgramText
);
243 glGenTextures(1, &TexDiffuse
);
244 glGenTextures(1, &TexNormal
);
245 glGenTextures(1, &TexSpecular
);
246 glGenTextures(1, &TexLookup
);
249 * Initialize textures
252 for(y
= 0; y
< 256; ++y
) {
253 for(x
= 0; x
< 256; ++x
) {
254 data
[y
][x
][0] = 255; // 1.0
255 data
[y
][x
][1] = 192; // 0.75
256 data
[y
][x
][2] = 255; // 1.0
261 glBindTexture(GL_TEXTURE_2D
, TexDiffuse
);
262 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
263 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
264 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, 256, 256, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, data
);
267 for(y
= 0; y
< 256; ++y
) {
268 for(x
= 0; x
< 256; ++x
) {
269 data
[y
][x
][0] = 255; // 1.0
270 data
[y
][x
][1] = 0; // 0.0
271 data
[y
][x
][2] = 0; // 0.0
276 glBindTexture(GL_TEXTURE_2D
, TexNormal
);
277 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
278 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
279 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, 256, 256, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, data
);
282 for(y
= 0; y
< 256; ++y
) {
283 for(x
= 0; x
< 256; ++x
) {
284 data
[y
][x
][0] = 255; // 1.0
285 data
[y
][x
][1] = 255; // 1.0
286 data
[y
][x
][2] = 192; // 0.75
291 glBindTexture(GL_TEXTURE_2D
, TexSpecular
);
292 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
293 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
294 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, 256, 256, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, data
);
297 for(y
= 0; y
< 256; ++y
) {
298 for(x
= 0; x
< 256; ++x
) {
299 data
[y
][x
][0] = 255-x
;
300 data
[y
][x
][1] = 255-y
;
306 glBindTexture(GL_TEXTURE_2D
, TexLookup
);
307 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
308 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
309 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, 256, 256, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, data
);
311 Reshape(piglit_width
, piglit_height
);