1 // BEGIN_COPYRIGHT -*- glean -*-
3 // Copyright (C) 1999 Allen Akin All Rights Reserved.
5 // Permission is hereby granted, free of charge, to any person
6 // obtaining a copy of this software and associated documentation
7 // files (the "Software"), to deal in the Software without
8 // restriction, including without limitation the rights to use,
9 // copy, modify, merge, publish, distribute, sublicense, and/or
10 // sell copies of the Software, and to permit persons to whom the
11 // Software is furnished to do so, subject to the following
14 // The above copyright notice and this permission notice shall be
15 // included in all copies or substantial portions of the
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
19 // KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
20 // WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
21 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ALLEN AKIN BE
22 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 // AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
24 // OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 // DEALINGS IN THE SOFTWARE.
29 // tmaskedclear.cpp: Test color/index masking with glClear.
31 #include "tmaskedclear.h"
38 MaskedClearTest::failRGB(BasicResult
&r
, GLint chan
, GLfloat expected
,
39 GLfloat actual
, GLint buffer
)
41 static const char *chanNames
[] = { "Red", "Green", "Blue", "Alpha" };
42 static const char *bufferNames
[] = { "GL_FRONT", "GL_BACK" };
44 glGetBooleanv(GL_COLOR_WRITEMASK
, mask
);
45 env
->log
<< name
<< ": FAIL "
46 << r
.config
->conciseDescription() << '\n'
47 << "\t" << chanNames
[chan
] << " is " << actual
48 << ", expected " << expected
49 << " in " << bufferNames
[buffer
] << " buffer\n";
50 env
->log
<< "\tGL_COLOR_WRITEMASK = ("
51 << (mask
[0] ? "GL_TRUE" : "GL_FALSE") << ", "
52 << (mask
[1] ? "GL_TRUE" : "GL_FALSE") << ", "
53 << (mask
[2] ? "GL_TRUE" : "GL_FALSE") << ", "
54 << (mask
[3] ? "GL_TRUE" : "GL_FALSE") << ")\n";
58 MaskedClearTest::failCI(BasicResult
& r
, GLuint expected
, GLuint actual
,
61 static const char *bufferNames
[] = { "GL_FRONT", "GL_BACK" };
63 glGetIntegerv(GL_INDEX_WRITEMASK
, &mask
);
64 env
->log
<< name
<< ": FAIL "
65 << r
.config
->conciseDescription() << '\n'
66 << "\tcolor index is " << actual
67 << ", expected " << expected
68 << " in " << bufferNames
[buffer
] << " buffer\n";
69 env
->log
<< "\tGL_INDEX_WRITEMASK = " << mask
<< "\n";
73 MaskedClearTest::failZ(BasicResult
& r
, GLfloat expected
, GLfloat actual
)
76 glGetBooleanv(GL_DEPTH_WRITEMASK
, &mask
);
77 env
->log
<< name
<< ": FAIL "
78 << r
.config
->conciseDescription() << '\n'
79 << "\tdepth buffer value is " << actual
80 << ", expected " << expected
<< "\n";
81 env
->log
<< "\tGL_DEPTH_WRITEMASK = "
82 << (mask
? "GL_TRUE" : "GL_FALSE") << "\n";
86 MaskedClearTest::failStencil(BasicResult
& r
, GLuint expected
, GLuint actual
)
89 glGetIntegerv(GL_STENCIL_WRITEMASK
, &mask
);
90 env
->log
<< name
<< ": FAIL "
91 << r
.config
->conciseDescription() << '\n'
92 << "\tstencil buffer value is " << actual
93 << ", expected " << expected
<< "\n";
94 env
->log
<< "\tGL_STENCIL_WRITEMASK = " << mask
<< "\n";
97 ///////////////////////////////////////////////////////////////////////////////
98 // runOne: Run a single test case
99 ///////////////////////////////////////////////////////////////////////////////
101 MaskedClearTest::runOne(BasicResult
& r
, Window
&) {
105 // GL init, just to be safe
106 glDisable(GL_SCISSOR_TEST
);
108 // only test front/back-left buffers, quad-buffer stereo in the future
109 const GLint numBuffers
= r
.config
->db
? 2 : 1;
110 for (GLint buffer
= 0; buffer
< numBuffers
&& passed
; buffer
++) {
113 glReadBuffer(GL_FRONT
);
114 glDrawBuffer(GL_FRONT
);
116 glReadBuffer(GL_BACK
);
117 glDrawBuffer(GL_BACK
);
120 if (r
.config
->canRGBA
) {
121 const GLint numChannels
= (r
.config
->a
> 0) ? 4 : 3;
123 chan
< numChannels
&& passed
; chan
++) {
125 glColorMask(GL_TRUE
, GL_TRUE
, GL_TRUE
, GL_TRUE
);
126 glClearColor(0.0, 0.0, 0.0, 0.0);
127 glClear(GL_COLOR_BUFFER_BIT
);
129 // select one channel to "clear" to 1.0
130 glColorMask(chan
== 0, chan
== 1,
131 chan
== 2, chan
== 3);
133 // try to clear surface to white
134 glClearColor(1.0, 1.0, 1.0, 1.0);
135 glClear(GL_COLOR_BUFFER_BIT
);
137 // read 1x1 image at (x,y)=(4,4)
139 glReadPixels(4, 4, 1, 1,
140 GL_RGBA
, GL_FLOAT
, pixel
);
144 comp
< numChannels
&& passed
; comp
++) {
146 // component should be 1.0
147 if (pixel
[comp
] < 0.5) {
149 failRGB(r
, comp
, 1.0,
150 pixel
[comp
], buffer
);
153 // component should be 0.0
154 if (pixel
[comp
] > 0.5) {
156 failRGB(r
, comp
, 0.0,
157 pixel
[comp
], buffer
);
164 const GLint indexBits
= r
.config
->bufSize
;
165 // We just run <indexBits> tests rather than 2^indexBits
166 for (GLint bit
= 0; bit
< indexBits
&& passed
; bit
++) {
170 glClear(GL_COLOR_BUFFER_BIT
);
172 // select one bit to "clear" to 1
173 glIndexMask(1 << bit
);
175 // try to clear surface to ~0
177 glClear(GL_COLOR_BUFFER_BIT
);
179 // read 1x1 image at (x,y)=(4,4)
181 glReadPixels(4, 4, 1, 1,
182 GL_COLOR_INDEX
, GL_UNSIGNED_INT
, &pixel
);
185 if (pixel
!= (1U << bit
)) {
187 failCI(r
, 1 << bit
, pixel
, buffer
);
193 if (passed
&& r
.config
->z
> 0) {
194 // clear depth buffer to zero
195 glDepthMask(GL_TRUE
);
197 glClear(GL_DEPTH_BUFFER_BIT
);
199 // disable Z writes, try to clear to one
200 glDepthMask(GL_FALSE
);
202 glClear(GL_DEPTH_BUFFER_BIT
);
204 // read 1x1 image at (x,y)=(4,4);
206 glReadPixels(4, 4, 1, 1, GL_DEPTH_COMPONENT
, GL_FLOAT
, &depth
);
211 failZ(r
, 0.0, depth
);
215 if (passed
&& r
.config
->s
> 0) {
216 const GLint stencilBits
= r
.config
->s
;
217 // We just run <stencilBits> tests rather than 2^stencilBits
218 for (GLint bit
= 0; bit
< stencilBits
&& passed
; bit
++) {
222 glClear(GL_STENCIL_BUFFER_BIT
);
224 // select one bit to "clear" to 1
225 glStencilMask(1 << bit
);
227 // try to clear stencil buffer to ~0
229 glClear(GL_STENCIL_BUFFER_BIT
);
231 // read 1x1 image at (x,y)=(4,4)
233 glReadPixels(4, 4, 1, 1,
234 GL_STENCIL_INDEX
, GL_UNSIGNED_INT
, &stencil
);
237 if (stencil
!= (1U << bit
)) {
239 failStencil(r
, 1 << bit
, stencil
);
244 } // MaskedClearTest::runOne
247 ///////////////////////////////////////////////////////////////////////////////
248 // logOne: Log a single test case
249 ///////////////////////////////////////////////////////////////////////////////
251 MaskedClearTest::logOne(BasicResult
& r
) {
256 } // MaskedClearTest::logOne
258 ///////////////////////////////////////////////////////////////////////////////
259 // The test object itself:
260 ///////////////////////////////////////////////////////////////////////////////
261 MaskedClearTest
maskedClearTest("maskedClear", "window",
262 "This test checks that glClear works correctly with glColorMask,\n"
263 "glIndexMask, glDepthMask and glStencilMask.\n");