2 * Port of Glean maskedClear test to piglit. Original copyright follows.
4 * Copyright (C) 1999 Allen Akin All Rights Reserved.
6 * Permission is hereby granted, free of charge, to any person
7 * obtaining a copy of this software and associated documentation
8 * files (the "Software"), to deal in the Software without
9 * restriction, including without limitation the rights to use,
10 * copy, modify, merge, publish, distribute, sublicense, and/or
11 * sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following
15 * The above copyright notice and this permission notice shall be
16 * included in all copies or substantial portions of the
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
20 * KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
21 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
22 * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ALLEN AKIN BE
23 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
24 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
25 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26 * DEALINGS IN THE SOFTWARE.
30 * Test color/depth/stencil masking with glClear.
34 #include "piglit-util-gl.h"
36 PIGLIT_GL_TEST_CONFIG_BEGIN
37 config
.supports_gl_compat_version
= 10;
38 config
.window_visual
= (PIGLIT_GL_VISUAL_RGB
|
39 PIGLIT_GL_VISUAL_DEPTH
|
40 PIGLIT_GL_VISUAL_STENCIL
|
41 PIGLIT_GL_VISUAL_DOUBLE
);
42 config
.requires_displayed_window
= true;
43 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
44 PIGLIT_GL_TEST_CONFIG_END
48 failRGB(GLint chan
, GLfloat expected
,
49 GLfloat actual
, GLenum buffer
)
51 static const char *chanNames
[] = { "Red", "Green", "Blue", "Alpha" };
53 glGetBooleanv(GL_COLOR_WRITEMASK
, mask
);
54 fprintf(stderr
, "masked-clear: %s is %f, expected %f in %s\n",
55 chanNames
[chan
], actual
, expected
,
56 piglit_get_gl_enum_name(buffer
));
57 fprintf(stderr
, "\tGL_COLOR_WRITEMASK = (%s, %s, %s, %s)\n",
58 (mask
[0] ? "GL_TRUE" : "GL_FALSE"),
59 (mask
[1] ? "GL_TRUE" : "GL_FALSE"),
60 (mask
[2] ? "GL_TRUE" : "GL_FALSE"),
61 (mask
[3] ? "GL_TRUE" : "GL_FALSE"));
66 failZ(GLfloat expected
, GLfloat actual
)
69 glGetBooleanv(GL_DEPTH_WRITEMASK
, &mask
);
70 fprintf(stderr
, "masked-clear: depth buffer value is %f, expected %f\n",
72 fprintf(stderr
, "\tGL_DEPTH_WRITEMASK = %s\n",
73 mask
? "GL_TRUE" : "GL_FALSE");
78 failStencil(GLuint expected
, GLuint actual
)
81 glGetIntegerv(GL_STENCIL_WRITEMASK
, &mask
);
82 fprintf(stderr
, "masked-clear: stencil buffer value is %d, expected %d\n",
84 fprintf(stderr
, "\tGL_STENCIL_WRITEMASK = 0x%x\n", mask
);
89 test_color_masking(GLenum buffer
)
92 int chan
, comp
, numChannels
;
95 assert(buffer
== GL_FRONT
|| buffer
== GL_BACK
);
100 glGetIntegerv(GL_ALPHA_BITS
, &a
);
101 numChannels
= a
? 4 : 3;
103 for (chan
= 0; chan
< numChannels
&& passed
; chan
++) {
107 glColorMask(GL_TRUE
, GL_TRUE
, GL_TRUE
, GL_TRUE
);
108 glClearColor(0.0, 0.0, 0.0, 0.0);
109 glClear(GL_COLOR_BUFFER_BIT
);
111 /* select one channel to "clear" to 1.0 */
112 glColorMask(chan
== 0, chan
== 1, chan
== 2, chan
== 3);
114 /* try to clear surface to white */
115 glClearColor(1.0, 1.0, 1.0, 1.0);
116 glClear(GL_COLOR_BUFFER_BIT
);
118 /* read 1x1 image at (x,y)=(4,4) */
119 glReadPixels(4, 4, 1, 1, GL_RGBA
, GL_FLOAT
, pixel
);
121 if (!piglit_automatic
)
122 piglit_present_results();
125 for (comp
= 0; comp
< numChannels
&& passed
; comp
++) {
127 /* component should be 1.0 */
128 if (pixel
[comp
] < 0.5) {
131 pixel
[comp
], buffer
);
134 /* component should be 0.0 */
135 if (pixel
[comp
] > 0.5) {
138 pixel
[comp
], buffer
);
149 test_depth_masking(void)
154 /* clear depth buffer to zero */
155 glDepthMask(GL_TRUE
);
157 glClear(GL_DEPTH_BUFFER_BIT
);
159 /* disable Z writes, try to clear to one */
160 glDepthMask(GL_FALSE
);
162 glClear(GL_DEPTH_BUFFER_BIT
);
164 /* read 1x1 image at (x,y)=(4,4); */
165 glReadPixels(4, 4, 1, 1, GL_DEPTH_COMPONENT
, GL_FLOAT
, &depth
);
178 test_stencil_masking(void)
184 glGetIntegerv(GL_STENCIL_BITS
, &stencilBits
);
186 /* We just run <stencilBits> tests rather than 2^stencilBits */
187 for (bit
= 0; bit
< stencilBits
; bit
++) {
193 glClear(GL_STENCIL_BUFFER_BIT
);
195 /* select one bit to "clear" to 1 */
196 glStencilMask(1 << bit
);
198 /* try to clear stencil buffer to ~0 */
200 glClear(GL_STENCIL_BUFFER_BIT
);
202 /* read 1x1 image at (x,y)=(4,4) */
203 glReadPixels(4, 4, 1, 1,
204 GL_STENCIL_INDEX
, GL_UNSIGNED_INT
, &stencil
);
207 if (stencil
!= (1U << bit
)) {
209 failStencil(1 << bit
, stencil
);
222 pass
= test_color_masking(GL_FRONT
) && pass
;
224 pass
= test_color_masking(GL_BACK
) && pass
;
226 pass
= test_depth_masking() && pass
;
228 pass
= test_stencil_masking() && pass
;
230 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;
235 piglit_init(int argc
, char **argv
)