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
21 * DEALINGS IN THE SOFTWARE.
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"
39 int piglit_window_mode
= GLUT_DOUBLE
| GLUT_RGB
;
40 int piglit_width
= 400;
41 int piglit_height
= 300;
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"
55 piglit_init(int argc
, char **argv
)
61 GLfloat texDepthData
[width
][height
];
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
);
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
) {
79 texDepthData
[i
][j
] = 1.0;
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
);
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 {
118 const GLfloat
*probes
[9];
137 GL_GREATER
, 2.0, 0.0,
169 GL_NOTEQUAL
, 0.5, 0.5,
186 static const GLenum modes
[3] = {
187 GL_ALPHA
, GL_LUMINANCE
, GL_INTENSITY
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);
206 glTexParameteri(GL_TEXTURE_2D
,
207 GL_TEXTURE_COMPARE_FUNC
,
209 glTexParameteri(GL_TEXTURE_2D
,
210 GL_DEPTH_TEXTURE_MODE
,
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
);
220 glTexCoord3f(0.0, 1.0, tests
[row
].r1
);
221 glVertex2f(x
, y
+ BOX_SIZE
);
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),
231 if (!piglit_automatic
) {
232 printf("compare = %s, mode = %s\n",
233 compare_names
[compare
- GL_NEVER
],
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
;