Add more structure constructor tests.
[piglit/hramrach.git] / tests / texturing / depth-tex-compare.c
blob8117cac850a3d1ff14147b9bc85af43446f7c3f9
1 /*
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
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 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
21 * DEALINGS IN THE SOFTWARE.
24 // author: Ben Holmes
27 * This test draws depth textures as LUMINANCE, INTENSITY, and ALPHA. These
28 * textures are compared to the r component of the texture coordinate and
29 * compared using all eight texture compare functions. The result of the
30 * comparison is modulated with the vertex color (pink) and blended with the
31 * clear color (green) using the alpha value.
34 #include "piglit-util.h"
35 #include "piglit-framework.h"
37 #define BOX_SIZE 25
39 int piglit_window_mode = GLUT_DOUBLE | GLUT_RGB;
40 int piglit_width = 400;
41 int piglit_height = 300;
43 static GLuint tex;
45 static const char *const compare_names[8] = {
46 "GL_NEVER", "GL_LESS", "GL_EQUAL", "GL_LEQUAL",
47 "GL_GREATER", "GL_NOTEQUAL", "GL_GEQUAL", "GL_ALWAYS"
50 static const char *const mode_names[3] = {
51 "GL_ALPHA", "GL_LUMINANCE", "GL_INTENSITY"
54 void
55 piglit_init(int argc, char **argv)
57 #define height 2
58 #define width 2
59 int i, j;
61 GLfloat texDepthData[width][height];
63 (void) argc;
64 (void) argv;
66 piglit_require_extension("GL_ARB_depth_texture");
67 piglit_require_extension("GL_ARB_shadow");
68 piglit_require_extension("GL_EXT_shadow_funcs");
69 piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
71 glEnable(GL_TEXTURE_2D);
72 glEnable(GL_BLEND);
73 glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
74 glClearColor(0.0, 1.0, 0.0, 1.0);
76 for (i=0; i < width; ++i) {
77 for (j=0; j < height; ++j) {
78 if ((i+j) & 1) {
79 texDepthData[i][j] = 1.0;
81 else {
82 texDepthData[i][j] = 0.5;
87 glGenTextures(1, &tex);
88 glBindTexture(GL_TEXTURE_2D, tex);
89 glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_FALSE);
90 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
91 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
92 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
93 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
94 glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_LUMINANCE);
95 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE,
96 GL_COMPARE_R_TO_TEXTURE);
97 glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, width, height, 0,
98 GL_DEPTH_COMPONENT, GL_FLOAT, texDepthData);
99 #undef height
100 #undef width
104 enum piglit_result
105 piglit_display(void)
107 GLboolean pass = GL_TRUE;
109 static const GLfloat pink[3] = {1.0, 0.0, 1.0};
110 static const GLfloat white[3] = {1.0, 1.0, 1.0};
111 static const GLfloat black[3] = {0.0, 0.0, 0.0};
112 static const GLfloat green[3] = {0.0, 1.0, 0.0};
114 static const struct {
115 GLenum compare;
116 float r0;
117 float r1;
118 const GLfloat *probes[9];
119 } tests[] = {
121 GL_LESS, 2.0, 0.0,
123 pink, white, white,
124 pink, black, black,
125 pink, green, green
129 GL_LEQUAL, 2.0, 0.0,
131 pink, white, pink,
132 pink, black, pink,
133 pink, green, pink,
137 GL_GREATER, 2.0, 0.0,
139 white, pink, white,
140 black, pink, black,
141 green, pink, green,
145 GL_GEQUAL, 2.0, 0.0,
147 white, pink, pink,
148 black, pink, pink,
149 green, pink, pink,
153 GL_ALWAYS, 2.0, 0.0,
155 pink, pink, pink,
156 pink, pink, pink,
157 pink, pink, pink,
161 GL_NEVER, 2.0, 0.0,
163 white, white, white,
164 black, black, black,
165 green, green, green,
169 GL_NOTEQUAL, 0.5, 0.5,
171 white, white, pink,
172 black, black, pink,
173 green, green, pink,
177 GL_EQUAL, 0.5, 0.5,
179 pink, pink, white,
180 pink, pink, black,
181 pink, pink, green,
186 static const GLenum modes[3] = {
187 GL_ALPHA, GL_LUMINANCE, GL_INTENSITY
190 unsigned row;
191 unsigned col;
193 glClear(GL_COLOR_BUFFER_BIT);
195 glColor3f(1.0, 0.0, 1.0);
197 glBindTexture(GL_TEXTURE_2D, tex);
198 for (row = 0; row < ARRAY_SIZE(tests); row++) {
199 const int y = 275 - (35 * row);
200 const GLenum compare = tests[row].compare;
202 for (col = 0; col < 3; col++) {
203 const int x = 150 + (col * 50);
204 unsigned i;
206 glTexParameteri(GL_TEXTURE_2D,
207 GL_TEXTURE_COMPARE_FUNC,
208 compare);
209 glTexParameteri(GL_TEXTURE_2D,
210 GL_DEPTH_TEXTURE_MODE,
211 modes[col]);
213 glBegin(GL_TRIANGLE_STRIP);
214 glTexCoord3f(1.0, 0.0, tests[row].r0);
215 glVertex2f(x + BOX_SIZE, y);
216 glTexCoord3f(1.0, 1.0, tests[row].r0);
217 glVertex2f(x + BOX_SIZE, y + BOX_SIZE);
218 glTexCoord3f(0.0, 0.0, tests[row].r1);
219 glVertex2f(x, y);
220 glTexCoord3f(0.0, 1.0, tests[row].r1);
221 glVertex2f(x, y + BOX_SIZE);
222 glEnd();
224 for (i = 0; i < 3; i++) {
225 const GLfloat *const color =
226 tests[row].probes[(3 * col) + i];
228 if (!piglit_probe_pixel_rgb(x + 5 + (i * 5),
229 y + 10,
230 color)) {
231 if (!piglit_automatic) {
232 printf("compare = %s, mode = %s\n",
233 compare_names[compare - GL_NEVER],
234 mode_names[col]);
237 pass = GL_FALSE;
243 glFinish();
244 glutSwapBuffers();
246 printf(" Left to Right: ALPHA, LUMINANCE, INTENSITY\n Top to Bottom: LESS, LEQUAL, GREATER, GEQUAL, ALWAYS, NEVER, NOTEQUAL, EQUAL\n");
248 return pass ? PIGLIT_SUCCESS : PIGLIT_FAILURE;