1 /* BEGIN_COPYRIGHT -*- glean -*-
3 * Copyright (C) 1999 Allen Akin All Rights Reserved.
4 * Copyright (C) 2015 Intel Corporation.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 * DEALINGS IN THE SOFTWARE.
29 * Test basic GL rendering paths.
32 * Based on the original Glean tpaths.cpp test, this test verifies
33 * that basic, trival OpenGL paths work as expected. For example,
34 * glAlphaFunc(GL_GEQUAL, 0.0) should always pass and
35 * glAlphaFunc(GL_LESS, 0.0) should always fail. We setup trivial
36 * pass and fail conditions for each of alpha test, blending, color mask,
37 * depth test, logic ops, scissor, stencil, stipple, and texture and
38 * make sure they work as expected. We also setup trival-pass for all
39 * these paths simultaneously and test that as well.
41 * To test for pass/fail we examine the color buffer for white or black,
45 * Brian Paul <brianp@valinux.com>
46 * Adapted to Piglit by Juliet Fru <julietfru@gmail.com>, August 2015.
49 #include "piglit-util-gl.h"
51 PIGLIT_GL_TEST_CONFIG_BEGIN
53 config
.supports_gl_compat_version
= 10;
55 config
.window_visual
= PIGLIT_GL_VISUAL_RGBA
|
56 PIGLIT_GL_VISUAL_DOUBLE
| PIGLIT_GL_VISUAL_DEPTH
|
57 PIGLIT_GL_VISUAL_STENCIL
;
58 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
60 PIGLIT_GL_TEST_CONFIG_END
73 NUM_PATHS
/* end-of-list token */
84 path_name(enum path paths
)
98 return "Scissor Test";
100 return "Stencil Test";
102 return "Polygon Stipple";
104 return "Modulated Texture";
108 return "BAD PATH VALUE!";
113 set_path_state(enum path paths
, enum state states
)
118 if (states
== ALWAYS_PASS
) {
119 glAlphaFunc(GL_GEQUAL
, 0.0);
120 glEnable(GL_ALPHA_TEST
);
121 } else if (states
== ALWAYS_FAIL
) {
122 glAlphaFunc(GL_GREATER
, 1.0);
123 glEnable(GL_ALPHA_TEST
);
125 glDisable(GL_ALPHA_TEST
);
129 if (states
== ALWAYS_PASS
) {
130 glBlendFunc(GL_ONE
, GL_ZERO
);
132 } else if (states
== ALWAYS_FAIL
) {
133 glBlendFunc(GL_ZERO
, GL_ONE
);
140 if (states
== ALWAYS_PASS
) {
141 glColorMask(GL_TRUE
, GL_TRUE
, GL_TRUE
, GL_TRUE
);
142 } else if (states
== ALWAYS_FAIL
) {
143 glColorMask(GL_FALSE
, GL_FALSE
, GL_FALSE
, GL_FALSE
);
145 glColorMask(GL_TRUE
, GL_TRUE
, GL_TRUE
, GL_TRUE
);
149 if (states
== ALWAYS_PASS
) {
150 glDepthFunc(GL_ALWAYS
);
151 glEnable(GL_DEPTH_TEST
);
152 } else if (states
== ALWAYS_FAIL
) {
153 glDepthFunc(GL_NEVER
);
154 glEnable(GL_DEPTH_TEST
);
156 glDisable(GL_DEPTH_TEST
);
160 if (states
== ALWAYS_PASS
) {
162 glEnable(GL_COLOR_LOGIC_OP
);
163 } else if (states
== ALWAYS_FAIL
) {
165 glEnable(GL_COLOR_LOGIC_OP
);
167 glDisable(GL_COLOR_LOGIC_OP
);
171 if (states
== ALWAYS_PASS
) {
172 glScissor(0, 0, piglit_width
, piglit_height
);
173 glEnable(GL_SCISSOR_TEST
);
174 } else if (states
== ALWAYS_FAIL
) {
175 glScissor(0, 0, 0, 0);
176 glEnable(GL_SCISSOR_TEST
);
178 glDisable(GL_SCISSOR_TEST
);
182 if (states
== ALWAYS_PASS
) {
183 /* pass if reference <= stencil value (ref = 0) */
184 glStencilFunc(GL_LEQUAL
, 0, ~0);
185 glEnable(GL_STENCIL_TEST
);
186 } else if (states
== ALWAYS_FAIL
) {
187 /* pass if reference > stencil value (ref = 0) */
188 glStencilFunc(GL_GREATER
, 0, ~0);
189 glEnable(GL_STENCIL_TEST
);
191 glDisable(GL_STENCIL_TEST
);
195 if (states
== ALWAYS_PASS
) {
196 GLubyte stipple
[4 * 32];
197 for (i
= 0; i
< 4 * 32; i
++)
199 glPolygonStipple(stipple
);
200 glEnable(GL_POLYGON_STIPPLE
);
201 } else if (states
== ALWAYS_FAIL
) {
202 GLubyte stipple
[4 * 32];
203 for (i
= 0; i
< 4 * 32; i
++)
205 glPolygonStipple(stipple
);
206 glEnable(GL_POLYGON_STIPPLE
);
208 glDisable(GL_POLYGON_STIPPLE
);
212 if (states
== DISABLE
) {
213 glDisable(GL_TEXTURE_2D
);
215 GLubyte val
= (states
== ALWAYS_PASS
) ? 0xff : 0x00;
216 GLubyte texImage
[4 * 4 * 4];
217 for (i
= 0; i
< 4 * 4 * 4; i
++)
219 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, 4, 4, 0,
220 GL_RGBA
, GL_UNSIGNED_BYTE
, texImage
);
221 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
,
223 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
,
225 glTexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
,
227 glEnable(GL_TEXTURE_2D
);
236 piglit_init(int argc
, char **argv
)
247 static const float white
[3] = { 1.0, 1.0, 1.0 };
248 static const float black
[3] = { 0.0, 0.0, 0.0 };
250 piglit_ortho_projection(piglit_width
, piglit_height
, GL_FALSE
);
252 glDisable(GL_DITHER
);
254 /* test always-pass paths */
255 for (i
= 0; i
< NUM_PATHS
; i
++) {
256 glClear(GL_COLOR_BUFFER_BIT
);
257 set_path_state(i
, ALWAYS_PASS
);
260 piglit_draw_rect(i
* 10, 0, 10, 10);
262 set_path_state(i
, DISABLE
);
265 if (!piglit_probe_pixel_rgb(i
* 10 + 4, 4, white
)) {
266 printf("Failure with path %s set to always pass.\n",
273 /* enable all always-pass paths */
275 glClear(GL_COLOR_BUFFER_BIT
);
276 for (i
= 0; i
< NUM_PATHS
; i
++) {
277 set_path_state(i
, ALWAYS_PASS
);
281 piglit_draw_rect(0, 10, 10, 10);
283 for (i
= 0; i
< NUM_PATHS
; i
++) {
284 set_path_state(i
, DISABLE
);
288 if (!piglit_probe_pixel_rgb(4, 14, white
)) {
289 printf("Failure with always-pass paths enabled.\n");
294 /* test never-pass paths */
295 for (i
= 0; i
< NUM_PATHS
; i
++) {
296 glClear(GL_COLOR_BUFFER_BIT
);
297 set_path_state(i
, ALWAYS_FAIL
);
300 piglit_draw_rect(10 * i
, 20, 10, 10);
302 set_path_state(i
, DISABLE
);
305 if (!piglit_probe_pixel_rgb(10 * i
+ 4, 24, black
)) {
306 printf("Failure with %s set to fail mode.\n",
312 piglit_present_results();
313 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;