framework/replay: disable AA accounting when comparing with no tolerance
[piglit.git] / tests / spec / gl-1.0 / no-op-paths.c
blob7c86b7c309410dfc6a184598cea7312e6814348e
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
15 * Software.
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.
25 * END_COPYRIGHT
27 /** @file paths.c
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,
42 * respectively.
44 * Authors:
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
62 enum path
64 ALPHA,
65 BLEND,
66 COLOR_MASK,
67 DEPTH,
68 LOGIC,
69 SCISSOR,
70 STENCIL,
71 STIPPLE,
72 TEXTURE,
73 NUM_PATHS /* end-of-list token */
76 enum state
78 DISABLE,
79 ALWAYS_PASS,
80 ALWAYS_FAIL
83 const char *
84 path_name(enum path paths)
86 switch (paths) {
87 case ALPHA:
88 return "Alpha Test";
89 case BLEND:
90 return "Blending";
91 case COLOR_MASK:
92 return "Color Mask";
93 case DEPTH:
94 return "Depth Test";
95 case LOGIC:
96 return "LogicOp";
97 case SCISSOR:
98 return "Scissor Test";
99 case STENCIL:
100 return "Stencil Test";
101 case STIPPLE:
102 return "Polygon Stipple";
103 case TEXTURE:
104 return "Modulated Texture";
105 case NUM_PATHS:
106 return "paths";
107 default:
108 return "BAD PATH VALUE!";
112 void
113 set_path_state(enum path paths, enum state states)
115 int i;
116 switch (paths) {
117 case ALPHA:
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);
124 } else {
125 glDisable(GL_ALPHA_TEST);
127 break;
128 case BLEND:
129 if (states == ALWAYS_PASS) {
130 glBlendFunc(GL_ONE, GL_ZERO);
131 glEnable(GL_BLEND);
132 } else if (states == ALWAYS_FAIL) {
133 glBlendFunc(GL_ZERO, GL_ONE);
134 glEnable(GL_BLEND);
135 } else {
136 glDisable(GL_BLEND);
138 break;
139 case COLOR_MASK:
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);
144 } else {
145 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
147 break;
148 case DEPTH:
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);
155 } else {
156 glDisable(GL_DEPTH_TEST);
158 break;
159 case LOGIC:
160 if (states == ALWAYS_PASS) {
161 glLogicOp(GL_OR);
162 glEnable(GL_COLOR_LOGIC_OP);
163 } else if (states == ALWAYS_FAIL) {
164 glLogicOp(GL_AND);
165 glEnable(GL_COLOR_LOGIC_OP);
166 } else {
167 glDisable(GL_COLOR_LOGIC_OP);
169 break;
170 case SCISSOR:
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);
177 } else {
178 glDisable(GL_SCISSOR_TEST);
180 break;
181 case STENCIL:
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);
190 } else {
191 glDisable(GL_STENCIL_TEST);
193 break;
194 case STIPPLE:
195 if (states == ALWAYS_PASS) {
196 GLubyte stipple[4 * 32];
197 for (i = 0; i < 4 * 32; i++)
198 stipple[i] = 0xff;
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++)
204 stipple[i] = 0x0;
205 glPolygonStipple(stipple);
206 glEnable(GL_POLYGON_STIPPLE);
207 } else {
208 glDisable(GL_POLYGON_STIPPLE);
210 break;
211 case TEXTURE:
212 if (states == DISABLE) {
213 glDisable(GL_TEXTURE_2D);
214 } else {
215 GLubyte val = (states == ALWAYS_PASS) ? 0xff : 0x00;
216 GLubyte texImage[4 * 4 * 4];
217 for (i = 0; i < 4 * 4 * 4; i++)
218 texImage[i] = val;
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,
222 GL_NEAREST);
223 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
224 GL_NEAREST);
225 glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE,
226 GL_MODULATE);
227 glEnable(GL_TEXTURE_2D);
229 break;
230 default:
231 break;
235 void
236 piglit_init(int argc, char **argv)
238 /* No init */
241 enum piglit_result
242 piglit_display(void)
244 bool pass = true;
245 int i;
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);
259 /* draw polygon */
260 piglit_draw_rect(i * 10, 0, 10, 10);
262 set_path_state(i, DISABLE);
264 /* test buffer */
265 if (!piglit_probe_pixel_rgb(i * 10 + 4, 4, white)) {
266 printf("Failure with path %s set to always pass.\n",
267 path_name(i));
269 pass = false;
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);
280 /* draw polygon */
281 piglit_draw_rect(0, 10, 10, 10);
283 for (i = 0; i < NUM_PATHS; i++) {
284 set_path_state(i, DISABLE);
287 /* test buffer */
288 if (!piglit_probe_pixel_rgb(4, 14, white)) {
289 printf("Failure with always-pass paths enabled.\n");
290 pass = false;
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);
299 /* draw polygon */
300 piglit_draw_rect(10 * i, 20, 10, 10);
302 set_path_state(i, DISABLE);
304 /* test buffer */
305 if (!piglit_probe_pixel_rgb(10 * i + 4, 24, black)) {
306 printf("Failure with %s set to fail mode.\n",
307 path_name(i));
308 pass = false;
312 piglit_present_results();
313 return pass ? PIGLIT_PASS : PIGLIT_FAIL;