glx: don't fail test if the X server is inconsistent
[piglit.git] / tests / general / texgen.c
blob0fb359aa0792639a31848d1134ffcb65712d7f88
1 /*
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
13 * Software.
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.
24 /**
25 * @file
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;
42 /**
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
45 * in in @ref Init.
47 static GLfloat TextureData[4][4][3];
49 /**
50 * Implement the inner part of the above texture in a fragment program.
52 static const char TextureFP[] =
53 "!!ARBfp1.0\n"
54 "TEMP r0;\n"
55 "MUL r0, fragment.texcoord, 4;\n"
56 "FLR r0, r0;\n"
57 "MUL result.color, r0, 0.25;\n"
58 "END\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);
64 if (piglit_automatic)
65 piglit_report_result(PIGLIT_FAIL);
69 /**
70 * Sanity test whether the texture is rendered correctly at all.
72 static void test_sanity(void)
74 int x, y;
76 glClearColor(0.5, 0.5, 0.5, 1.0);
77 glClear(GL_COLOR_BUFFER_BIT);
79 glBegin(GL_QUADS);
80 glTexCoord2f(0, 0);
81 glVertex2f(0, 0);
82 glTexCoord2f(1, 0);
83 glVertex2f(1, 0);
84 glTexCoord2f(1, 1);
85 glVertex2f(1, 1);
86 glTexCoord2f(0, 1);
87 glVertex2f(0, 1);
88 glEnd();
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 };
103 int x, y;
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
114 glBegin(GL_QUADS);
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);
119 glEnd();
121 // Draw lower right quad
122 glTexGenfv(GL_S, GL_EYE_PLANE, sPlane2);
123 glPushMatrix();
124 glTranslatef(0.5, -0.5, 0.0);
125 glScalef(2.0, 1.0, 1.0);
126 glBegin(GL_QUADS);
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);
131 glEnd();
132 glPopMatrix();
134 // Draw upper left quad
135 glPushMatrix();
136 glTranslatef(1.0, 0.5, 0.0);
137 glScalef(-1.0, 1.0, 1.0);
138 glTexGenfv(GL_S, GL_EYE_PLANE, sPlane3);
139 glBegin(GL_QUADS);
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);
144 glEnd();
145 glPopMatrix();
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);
171 static struct {
172 const char* name;
173 void (*function)(void);
174 } Tests[] = {
175 { "sanity", &test_sanity },
176 { "texgen_eye", &test_texgen_eye },
177 { "texgen_eye_fp", &test_texgen_eye_fp }
179 #define NrTests (ARRAY_SIZE(Tests))
181 enum piglit_result
182 piglit_display(void)
184 if (piglit_automatic) {
185 int i;
186 for(i = 0; i < NrTests; ++i)
187 Tests[i].function();
188 return PIGLIT_PASS;
189 } else {
190 Tests[CurrentTest].function();
191 return PIGLIT_PASS;
195 static void Key(unsigned char key, int x, int y)
197 (void) x;
198 (void) y;
199 switch (key) {
200 case 't':
201 CurrentTest++;
202 if (CurrentTest >= NrTests)
203 CurrentTest = 0;
204 printf("Test: %s\n", Tests[CurrentTest].name);
205 break;
206 case 27:
207 exit(0);
208 break;
210 piglit_post_redisplay();
213 void piglit_init(int argc, char *argv[])
215 int x, y;
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);