2 * Copyright (c) The Piglit project 2008
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.
26 * Test a number of basic TexGen functions.
29 #include "piglit-util-gl.h"
31 PIGLIT_GL_TEST_CONFIG_BEGIN
33 config
.supports_gl_compat_version
= 10;
35 config
.window_visual
= PIGLIT_GL_VISUAL_RGB
| PIGLIT_GL_VISUAL_DOUBLE
;
37 PIGLIT_GL_TEST_CONFIG_END
39 static int CurrentTest
= 0;
40 static int UseFragmentProgram
= 0;
43 * The test uses a 4x4 clamped, nearest-filtered texture with the following
44 * RGB colors. The pattern matches what @ref TextureFP produces and is filled
47 static GLfloat TextureData
[4][4][3];
50 * Implement the inner part of the above texture in a fragment program.
52 static const char TextureFP
[] =
55 "MUL r0, fragment.texcoord, 4;\n"
57 "MUL result.color, r0, 0.25;\n"
60 static void probe_cell(const char* testname
, int x
, int y
, const float* expected
)
62 if (!piglit_probe_pixel_rgb((2*x
+1)*piglit_width
/8, (2*y
+1)*piglit_height
/8, expected
)) {
63 fprintf(stderr
, "%s: %i,%i failed\n", testname
, x
, y
);
65 piglit_report_result(PIGLIT_FAIL
);
70 * Sanity test whether the texture is rendered correctly at all.
72 static void test_sanity(void)
76 glClearColor(0.5, 0.5, 0.5, 1.0);
77 glClear(GL_COLOR_BUFFER_BIT
);
90 for(y
= 0; y
< 4; ++y
) {
91 for(x
= 0; x
< 4; ++x
)
92 probe_cell("test_sanity", x
, y
, TextureData
[y
][x
]);
95 piglit_present_results();
98 static void do_test_texgen_eye(const char* testname
)
100 static GLfloat sPlane1
[4] = { 1.0, 0.0, 0.0, 0.25 };
101 static GLfloat sPlane2
[4] = { 1.0, 0.0, 0.0, -0.25 };
102 static GLfloat sPlane3
[4] = { -1.0, 0.0, 0.0, 1.25 };
105 glClearColor(0.5, 0.5, 0.5, 1.0);
106 glClear(GL_COLOR_BUFFER_BIT
);
108 // Note: Modelview matrix is identity
109 glTexGeni(GL_S
, GL_TEXTURE_GEN_MODE
, GL_EYE_LINEAR
);
110 glTexGenfv(GL_S
, GL_EYE_PLANE
, sPlane1
);
111 glEnable(GL_TEXTURE_GEN_S
);
113 // Draw lower left quad
115 glTexCoord2f(0, 0.25); glVertex2f(0.0, 0.0);
116 glTexCoord2f(0, 0.25); glVertex2f(0.5, 0.0);
117 glTexCoord2f(0, 0.75); glVertex2f(0.5, 0.5);
118 glTexCoord2f(0, 0.75); glVertex2f(0.0, 0.5);
121 // Draw lower right quad
122 glTexGenfv(GL_S
, GL_EYE_PLANE
, sPlane2
);
124 glTranslatef(0.5, -0.5, 0.0);
125 glScalef(2.0, 1.0, 1.0);
127 glTexCoord2f(0, 0.25); glVertex2f(0.0, 0.5);
128 glTexCoord2f(0, 0.25); glVertex2f(0.25, 0.5);
129 glTexCoord2f(0, 0.75); glVertex2f(0.25, 1.0);
130 glTexCoord2f(0, 0.75); glVertex2f(0.0, 1.0);
134 // Draw upper left quad
136 glTranslatef(1.0, 0.5, 0.0);
137 glScalef(-1.0, 1.0, 1.0);
138 glTexGenfv(GL_S
, GL_EYE_PLANE
, sPlane3
);
140 glTexCoord2f(0, 0.25); glVertex2f(1.0, 0.0);
141 glTexCoord2f(0, 0.25); glVertex2f(0.5, 0.0);
142 glTexCoord2f(0, 0.75); glVertex2f(0.5, 0.5);
143 glTexCoord2f(0, 0.75); glVertex2f(1.0, 0.5);
147 glDisable(GL_TEXTURE_GEN_S
);
149 for(y
= 0; y
< 2; ++y
) {
150 for(x
= 0; x
< 2; ++x
)
151 probe_cell(testname
, x
, y
, TextureData
[y
+1][x
+1]);
154 piglit_present_results();
157 static void test_texgen_eye(void)
159 do_test_texgen_eye("test_texgen_eye");
162 static void test_texgen_eye_fp(void)
164 if (UseFragmentProgram
) {
165 glEnable(GL_FRAGMENT_PROGRAM_ARB
);
166 do_test_texgen_eye("test_texgen_eye_fp");
167 glDisable(GL_FRAGMENT_PROGRAM_ARB
);
173 void (*function
)(void);
175 { "sanity", &test_sanity
},
176 { "texgen_eye", &test_texgen_eye
},
177 { "texgen_eye_fp", &test_texgen_eye_fp
}
179 #define NrTests (ARRAY_SIZE(Tests))
184 if (piglit_automatic
) {
186 for(i
= 0; i
< NrTests
; ++i
)
190 Tests
[CurrentTest
].function();
195 static void Key(unsigned char key
, int x
, int y
)
202 if (CurrentTest
>= NrTests
)
204 printf("Test: %s\n", Tests
[CurrentTest
].name
);
210 piglit_post_redisplay();
213 void piglit_init(int argc
, char *argv
[])
217 if (!piglit_automatic
) {
218 printf("Press 't' to switch tests; Escape to quit\n");
219 piglit_set_keyboard_func(Key
);
222 if (piglit_use_fragment_program()) {
223 UseFragmentProgram
= 1;
224 glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB
,
225 piglit_compile_program(GL_FRAGMENT_PROGRAM_ARB
, TextureFP
));
228 for(y
= 0; y
< 4; ++y
) {
229 for(x
= 0; x
< 4; ++x
) {
230 TextureData
[y
][x
][0] = x
* 0.25;
231 TextureData
[y
][x
][1] = y
* 0.25;
232 TextureData
[y
][x
][2] = 0.0;
236 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
237 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
238 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_CLAMP
);
239 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_CLAMP
);
240 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGB
, 4, 4, 0, GL_RGB
, GL_FLOAT
, TextureData
);
241 glEnable(GL_TEXTURE_2D
);
243 piglit_ortho_projection(1.0, 1.0, GL_FALSE
);