1*35238bceSAndroid Build Coastguard Worker /*-------------------------------------------------------------------------
2*35238bceSAndroid Build Coastguard Worker * drawElements Quality Program OpenGL ES 2.0 Module
3*35238bceSAndroid Build Coastguard Worker * -------------------------------------------------
4*35238bceSAndroid Build Coastguard Worker *
5*35238bceSAndroid Build Coastguard Worker * Copyright 2014 The Android Open Source Project
6*35238bceSAndroid Build Coastguard Worker *
7*35238bceSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License");
8*35238bceSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License.
9*35238bceSAndroid Build Coastguard Worker * You may obtain a copy of the License at
10*35238bceSAndroid Build Coastguard Worker *
11*35238bceSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0
12*35238bceSAndroid Build Coastguard Worker *
13*35238bceSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software
14*35238bceSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS,
15*35238bceSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16*35238bceSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and
17*35238bceSAndroid Build Coastguard Worker * limitations under the License.
18*35238bceSAndroid Build Coastguard Worker *
19*35238bceSAndroid Build Coastguard Worker *//*!
20*35238bceSAndroid Build Coastguard Worker * \file
21*35238bceSAndroid Build Coastguard Worker * \brief Depth and stencil clear tests.
22*35238bceSAndroid Build Coastguard Worker *//*--------------------------------------------------------------------*/
23*35238bceSAndroid Build Coastguard Worker
24*35238bceSAndroid Build Coastguard Worker #include "es2fDepthStencilClearTests.hpp"
25*35238bceSAndroid Build Coastguard Worker
26*35238bceSAndroid Build Coastguard Worker #include "gluShaderProgram.hpp"
27*35238bceSAndroid Build Coastguard Worker #include "gluPixelTransfer.hpp"
28*35238bceSAndroid Build Coastguard Worker #include "gluRenderContext.hpp"
29*35238bceSAndroid Build Coastguard Worker
30*35238bceSAndroid Build Coastguard Worker #include "tcuTestLog.hpp"
31*35238bceSAndroid Build Coastguard Worker #include "tcuTexture.hpp"
32*35238bceSAndroid Build Coastguard Worker #include "tcuTextureUtil.hpp"
33*35238bceSAndroid Build Coastguard Worker #include "tcuImageCompare.hpp"
34*35238bceSAndroid Build Coastguard Worker #include "tcuSurface.hpp"
35*35238bceSAndroid Build Coastguard Worker #include "tcuRenderTarget.hpp"
36*35238bceSAndroid Build Coastguard Worker
37*35238bceSAndroid Build Coastguard Worker #include "deRandom.hpp"
38*35238bceSAndroid Build Coastguard Worker #include "deMath.h"
39*35238bceSAndroid Build Coastguard Worker #include "deString.h"
40*35238bceSAndroid Build Coastguard Worker
41*35238bceSAndroid Build Coastguard Worker #include "glwFunctions.hpp"
42*35238bceSAndroid Build Coastguard Worker #include "glwEnums.hpp"
43*35238bceSAndroid Build Coastguard Worker
44*35238bceSAndroid Build Coastguard Worker namespace deqp
45*35238bceSAndroid Build Coastguard Worker {
46*35238bceSAndroid Build Coastguard Worker namespace gles2
47*35238bceSAndroid Build Coastguard Worker {
48*35238bceSAndroid Build Coastguard Worker namespace Functional
49*35238bceSAndroid Build Coastguard Worker {
50*35238bceSAndroid Build Coastguard Worker
51*35238bceSAndroid Build Coastguard Worker using std::string;
52*35238bceSAndroid Build Coastguard Worker using std::vector;
53*35238bceSAndroid Build Coastguard Worker using tcu::TestLog;
54*35238bceSAndroid Build Coastguard Worker using tcu::Vec3;
55*35238bceSAndroid Build Coastguard Worker using tcu::Vec4;
56*35238bceSAndroid Build Coastguard Worker
57*35238bceSAndroid Build Coastguard Worker namespace
58*35238bceSAndroid Build Coastguard Worker {
59*35238bceSAndroid Build Coastguard Worker
60*35238bceSAndroid Build Coastguard Worker enum
61*35238bceSAndroid Build Coastguard Worker {
62*35238bceSAndroid Build Coastguard Worker STENCIL_STEPS = 32,
63*35238bceSAndroid Build Coastguard Worker DEPTH_STEPS = 32
64*35238bceSAndroid Build Coastguard Worker };
65*35238bceSAndroid Build Coastguard Worker
66*35238bceSAndroid Build Coastguard Worker struct Clear
67*35238bceSAndroid Build Coastguard Worker {
Cleardeqp::gles2::Functional::__anon997496580111::Clear68*35238bceSAndroid Build Coastguard Worker Clear(void)
69*35238bceSAndroid Build Coastguard Worker : clearMask(0)
70*35238bceSAndroid Build Coastguard Worker , clearDepth(0.0f)
71*35238bceSAndroid Build Coastguard Worker , clearStencil(0)
72*35238bceSAndroid Build Coastguard Worker , useScissor(false)
73*35238bceSAndroid Build Coastguard Worker , scissor(0, 0, 0, 0)
74*35238bceSAndroid Build Coastguard Worker , depthMask(false)
75*35238bceSAndroid Build Coastguard Worker , stencilMask(0)
76*35238bceSAndroid Build Coastguard Worker {
77*35238bceSAndroid Build Coastguard Worker }
78*35238bceSAndroid Build Coastguard Worker
79*35238bceSAndroid Build Coastguard Worker uint32_t clearMask;
80*35238bceSAndroid Build Coastguard Worker float clearDepth;
81*35238bceSAndroid Build Coastguard Worker int clearStencil;
82*35238bceSAndroid Build Coastguard Worker
83*35238bceSAndroid Build Coastguard Worker bool useScissor;
84*35238bceSAndroid Build Coastguard Worker tcu::IVec4 scissor;
85*35238bceSAndroid Build Coastguard Worker
86*35238bceSAndroid Build Coastguard Worker bool depthMask;
87*35238bceSAndroid Build Coastguard Worker uint32_t stencilMask;
88*35238bceSAndroid Build Coastguard Worker };
89*35238bceSAndroid Build Coastguard Worker
getDepthFormat(int depthBits)90*35238bceSAndroid Build Coastguard Worker tcu::TextureFormat getDepthFormat(int depthBits)
91*35238bceSAndroid Build Coastguard Worker {
92*35238bceSAndroid Build Coastguard Worker switch (depthBits)
93*35238bceSAndroid Build Coastguard Worker {
94*35238bceSAndroid Build Coastguard Worker case 8:
95*35238bceSAndroid Build Coastguard Worker return tcu::TextureFormat(tcu::TextureFormat::D, tcu::TextureFormat::UNORM_INT8);
96*35238bceSAndroid Build Coastguard Worker case 16:
97*35238bceSAndroid Build Coastguard Worker return tcu::TextureFormat(tcu::TextureFormat::D, tcu::TextureFormat::UNORM_INT16);
98*35238bceSAndroid Build Coastguard Worker case 24:
99*35238bceSAndroid Build Coastguard Worker return tcu::TextureFormat(tcu::TextureFormat::D, tcu::TextureFormat::UNORM_INT24);
100*35238bceSAndroid Build Coastguard Worker case 32:
101*35238bceSAndroid Build Coastguard Worker return tcu::TextureFormat(tcu::TextureFormat::D, tcu::TextureFormat::FLOAT);
102*35238bceSAndroid Build Coastguard Worker default:
103*35238bceSAndroid Build Coastguard Worker TCU_FAIL("Can't map depth buffer format");
104*35238bceSAndroid Build Coastguard Worker }
105*35238bceSAndroid Build Coastguard Worker }
106*35238bceSAndroid Build Coastguard Worker
getStencilFormat(int stencilBits)107*35238bceSAndroid Build Coastguard Worker tcu::TextureFormat getStencilFormat(int stencilBits)
108*35238bceSAndroid Build Coastguard Worker {
109*35238bceSAndroid Build Coastguard Worker switch (stencilBits)
110*35238bceSAndroid Build Coastguard Worker {
111*35238bceSAndroid Build Coastguard Worker case 8:
112*35238bceSAndroid Build Coastguard Worker return tcu::TextureFormat(tcu::TextureFormat::S, tcu::TextureFormat::UNSIGNED_INT8);
113*35238bceSAndroid Build Coastguard Worker case 16:
114*35238bceSAndroid Build Coastguard Worker return tcu::TextureFormat(tcu::TextureFormat::S, tcu::TextureFormat::UNSIGNED_INT16);
115*35238bceSAndroid Build Coastguard Worker case 24:
116*35238bceSAndroid Build Coastguard Worker return tcu::TextureFormat(tcu::TextureFormat::S, tcu::TextureFormat::UNSIGNED_INT24);
117*35238bceSAndroid Build Coastguard Worker case 32:
118*35238bceSAndroid Build Coastguard Worker return tcu::TextureFormat(tcu::TextureFormat::S, tcu::TextureFormat::UNSIGNED_INT32);
119*35238bceSAndroid Build Coastguard Worker default:
120*35238bceSAndroid Build Coastguard Worker TCU_FAIL("Can't map depth buffer format");
121*35238bceSAndroid Build Coastguard Worker }
122*35238bceSAndroid Build Coastguard Worker }
123*35238bceSAndroid Build Coastguard Worker
124*35238bceSAndroid Build Coastguard Worker } // namespace
125*35238bceSAndroid Build Coastguard Worker
126*35238bceSAndroid Build Coastguard Worker class DepthStencilClearCase : public TestCase
127*35238bceSAndroid Build Coastguard Worker {
128*35238bceSAndroid Build Coastguard Worker public:
129*35238bceSAndroid Build Coastguard Worker DepthStencilClearCase(Context &context, const char *name, const char *description, int numIters, int numClears,
130*35238bceSAndroid Build Coastguard Worker bool depth, bool stencil, bool scissor, bool masked);
131*35238bceSAndroid Build Coastguard Worker ~DepthStencilClearCase(void);
132*35238bceSAndroid Build Coastguard Worker
133*35238bceSAndroid Build Coastguard Worker void init(void);
134*35238bceSAndroid Build Coastguard Worker void deinit(void);
135*35238bceSAndroid Build Coastguard Worker
136*35238bceSAndroid Build Coastguard Worker IterateResult iterate(void);
137*35238bceSAndroid Build Coastguard Worker
138*35238bceSAndroid Build Coastguard Worker private:
139*35238bceSAndroid Build Coastguard Worker void generateClears(vector<Clear> &dst, uint32_t seed);
140*35238bceSAndroid Build Coastguard Worker void renderGL(tcu::Surface &dst, const vector<Clear> &clears);
141*35238bceSAndroid Build Coastguard Worker void renderReference(tcu::Surface &dst, const vector<Clear> &clears);
142*35238bceSAndroid Build Coastguard Worker
143*35238bceSAndroid Build Coastguard Worker bool m_testDepth;
144*35238bceSAndroid Build Coastguard Worker bool m_testStencil;
145*35238bceSAndroid Build Coastguard Worker bool m_testScissor;
146*35238bceSAndroid Build Coastguard Worker bool m_masked;
147*35238bceSAndroid Build Coastguard Worker int m_numIters;
148*35238bceSAndroid Build Coastguard Worker int m_numClears;
149*35238bceSAndroid Build Coastguard Worker int m_curIter;
150*35238bceSAndroid Build Coastguard Worker
151*35238bceSAndroid Build Coastguard Worker glu::ShaderProgram *m_visProgram;
152*35238bceSAndroid Build Coastguard Worker };
153*35238bceSAndroid Build Coastguard Worker
DepthStencilClearCase(Context & context,const char * name,const char * description,int numIters,int numClears,bool depth,bool stencil,bool scissor,bool masked)154*35238bceSAndroid Build Coastguard Worker DepthStencilClearCase::DepthStencilClearCase(Context &context, const char *name, const char *description, int numIters,
155*35238bceSAndroid Build Coastguard Worker int numClears, bool depth, bool stencil, bool scissor, bool masked)
156*35238bceSAndroid Build Coastguard Worker : TestCase(context, name, description)
157*35238bceSAndroid Build Coastguard Worker , m_testDepth(depth)
158*35238bceSAndroid Build Coastguard Worker , m_testStencil(stencil)
159*35238bceSAndroid Build Coastguard Worker , m_testScissor(scissor)
160*35238bceSAndroid Build Coastguard Worker , m_masked(masked)
161*35238bceSAndroid Build Coastguard Worker , m_numIters(numIters)
162*35238bceSAndroid Build Coastguard Worker , m_numClears(numClears)
163*35238bceSAndroid Build Coastguard Worker , m_curIter(0)
164*35238bceSAndroid Build Coastguard Worker , m_visProgram(DE_NULL)
165*35238bceSAndroid Build Coastguard Worker {
166*35238bceSAndroid Build Coastguard Worker }
167*35238bceSAndroid Build Coastguard Worker
~DepthStencilClearCase(void)168*35238bceSAndroid Build Coastguard Worker DepthStencilClearCase::~DepthStencilClearCase(void)
169*35238bceSAndroid Build Coastguard Worker {
170*35238bceSAndroid Build Coastguard Worker DepthStencilClearCase::deinit();
171*35238bceSAndroid Build Coastguard Worker }
172*35238bceSAndroid Build Coastguard Worker
init(void)173*35238bceSAndroid Build Coastguard Worker void DepthStencilClearCase::init(void)
174*35238bceSAndroid Build Coastguard Worker {
175*35238bceSAndroid Build Coastguard Worker TestLog &log = m_testCtx.getLog();
176*35238bceSAndroid Build Coastguard Worker
177*35238bceSAndroid Build Coastguard Worker m_visProgram = new glu::ShaderProgram(m_context.getRenderContext(), glu::makeVtxFragSources(
178*35238bceSAndroid Build Coastguard Worker // Vertex shader.
179*35238bceSAndroid Build Coastguard Worker "attribute highp vec4 a_position;\n"
180*35238bceSAndroid Build Coastguard Worker "void main (void)\n"
181*35238bceSAndroid Build Coastguard Worker "{\n"
182*35238bceSAndroid Build Coastguard Worker " gl_Position = a_position;\n"
183*35238bceSAndroid Build Coastguard Worker "}\n",
184*35238bceSAndroid Build Coastguard Worker
185*35238bceSAndroid Build Coastguard Worker // Fragment shader.
186*35238bceSAndroid Build Coastguard Worker "uniform mediump vec4 u_color;\n"
187*35238bceSAndroid Build Coastguard Worker "void main (void)\n"
188*35238bceSAndroid Build Coastguard Worker "{\n"
189*35238bceSAndroid Build Coastguard Worker " gl_FragColor = u_color;\n"
190*35238bceSAndroid Build Coastguard Worker "}\n"));
191*35238bceSAndroid Build Coastguard Worker
192*35238bceSAndroid Build Coastguard Worker if (!m_visProgram->isOk())
193*35238bceSAndroid Build Coastguard Worker {
194*35238bceSAndroid Build Coastguard Worker log << *m_visProgram;
195*35238bceSAndroid Build Coastguard Worker delete m_visProgram;
196*35238bceSAndroid Build Coastguard Worker m_visProgram = DE_NULL;
197*35238bceSAndroid Build Coastguard Worker TCU_FAIL("Compile failed");
198*35238bceSAndroid Build Coastguard Worker }
199*35238bceSAndroid Build Coastguard Worker
200*35238bceSAndroid Build Coastguard Worker m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
201*35238bceSAndroid Build Coastguard Worker }
202*35238bceSAndroid Build Coastguard Worker
deinit(void)203*35238bceSAndroid Build Coastguard Worker void DepthStencilClearCase::deinit(void)
204*35238bceSAndroid Build Coastguard Worker {
205*35238bceSAndroid Build Coastguard Worker delete m_visProgram;
206*35238bceSAndroid Build Coastguard Worker m_visProgram = DE_NULL;
207*35238bceSAndroid Build Coastguard Worker }
208*35238bceSAndroid Build Coastguard Worker
iterate(void)209*35238bceSAndroid Build Coastguard Worker DepthStencilClearCase::IterateResult DepthStencilClearCase::iterate(void)
210*35238bceSAndroid Build Coastguard Worker {
211*35238bceSAndroid Build Coastguard Worker const tcu::RenderTarget &renderTarget = m_context.getRenderTarget();
212*35238bceSAndroid Build Coastguard Worker int width = renderTarget.getWidth();
213*35238bceSAndroid Build Coastguard Worker int height = renderTarget.getHeight();
214*35238bceSAndroid Build Coastguard Worker tcu::Surface result(width, height);
215*35238bceSAndroid Build Coastguard Worker tcu::Surface reference(width, height);
216*35238bceSAndroid Build Coastguard Worker tcu::RGBA threshold = renderTarget.getPixelFormat().getColorThreshold() + tcu::RGBA(1, 1, 1, 1);
217*35238bceSAndroid Build Coastguard Worker vector<Clear> clears;
218*35238bceSAndroid Build Coastguard Worker
219*35238bceSAndroid Build Coastguard Worker if ((m_testDepth && renderTarget.getDepthBits() == 0) || (m_testStencil && renderTarget.getStencilBits() == 0))
220*35238bceSAndroid Build Coastguard Worker throw tcu::NotSupportedError("No depth/stencil buffers", "", __FILE__, __LINE__);
221*35238bceSAndroid Build Coastguard Worker
222*35238bceSAndroid Build Coastguard Worker generateClears(clears, deStringHash(getName()) ^ deInt32Hash(m_curIter));
223*35238bceSAndroid Build Coastguard Worker renderGL(result, clears);
224*35238bceSAndroid Build Coastguard Worker renderReference(reference, clears);
225*35238bceSAndroid Build Coastguard Worker
226*35238bceSAndroid Build Coastguard Worker bool isLastIter = m_curIter + 1 == m_numIters;
227*35238bceSAndroid Build Coastguard Worker bool isOk = tcu::pixelThresholdCompare(m_testCtx.getLog(), "Result", "Image comparison result", reference, result,
228*35238bceSAndroid Build Coastguard Worker threshold, isLastIter ? tcu::COMPARE_LOG_RESULT : tcu::COMPARE_LOG_ON_ERROR);
229*35238bceSAndroid Build Coastguard Worker
230*35238bceSAndroid Build Coastguard Worker if (!isOk)
231*35238bceSAndroid Build Coastguard Worker m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Image comparison failed");
232*35238bceSAndroid Build Coastguard Worker
233*35238bceSAndroid Build Coastguard Worker m_curIter += 1;
234*35238bceSAndroid Build Coastguard Worker return isLastIter || !isOk ? STOP : CONTINUE;
235*35238bceSAndroid Build Coastguard Worker }
236*35238bceSAndroid Build Coastguard Worker
generateClears(vector<Clear> & clears,uint32_t seed)237*35238bceSAndroid Build Coastguard Worker void DepthStencilClearCase::generateClears(vector<Clear> &clears, uint32_t seed)
238*35238bceSAndroid Build Coastguard Worker {
239*35238bceSAndroid Build Coastguard Worker const tcu::RenderTarget &renderTarget = m_context.getRenderContext().getRenderTarget();
240*35238bceSAndroid Build Coastguard Worker int width = renderTarget.getWidth();
241*35238bceSAndroid Build Coastguard Worker int height = renderTarget.getHeight();
242*35238bceSAndroid Build Coastguard Worker de::Random rnd(seed);
243*35238bceSAndroid Build Coastguard Worker
244*35238bceSAndroid Build Coastguard Worker clears.resize(m_numClears);
245*35238bceSAndroid Build Coastguard Worker
246*35238bceSAndroid Build Coastguard Worker for (vector<Clear>::iterator clear = clears.begin(); clear != clears.end(); clear++)
247*35238bceSAndroid Build Coastguard Worker {
248*35238bceSAndroid Build Coastguard Worker if (m_testScissor)
249*35238bceSAndroid Build Coastguard Worker {
250*35238bceSAndroid Build Coastguard Worker int w = rnd.getInt(1, width);
251*35238bceSAndroid Build Coastguard Worker int h = rnd.getInt(1, height);
252*35238bceSAndroid Build Coastguard Worker int x = rnd.getInt(0, width - w);
253*35238bceSAndroid Build Coastguard Worker int y = rnd.getInt(0, height - h);
254*35238bceSAndroid Build Coastguard Worker
255*35238bceSAndroid Build Coastguard Worker clear->useScissor = true; // \todo [pyry] Should we randomize?
256*35238bceSAndroid Build Coastguard Worker clear->scissor = tcu::IVec4(x, y, w, h);
257*35238bceSAndroid Build Coastguard Worker }
258*35238bceSAndroid Build Coastguard Worker else
259*35238bceSAndroid Build Coastguard Worker clear->useScissor = false;
260*35238bceSAndroid Build Coastguard Worker
261*35238bceSAndroid Build Coastguard Worker clear->clearDepth = rnd.getFloat(-0.2f, 1.2f);
262*35238bceSAndroid Build Coastguard Worker clear->clearStencil = rnd.getUint32();
263*35238bceSAndroid Build Coastguard Worker
264*35238bceSAndroid Build Coastguard Worker clear->depthMask = m_masked ? rnd.getBool() : true;
265*35238bceSAndroid Build Coastguard Worker clear->stencilMask = m_masked ? rnd.getUint32() : 0xffffffffu;
266*35238bceSAndroid Build Coastguard Worker
267*35238bceSAndroid Build Coastguard Worker if (m_testDepth && m_testStencil)
268*35238bceSAndroid Build Coastguard Worker {
269*35238bceSAndroid Build Coastguard Worker switch (rnd.getInt(0, 2))
270*35238bceSAndroid Build Coastguard Worker {
271*35238bceSAndroid Build Coastguard Worker case 0:
272*35238bceSAndroid Build Coastguard Worker clear->clearMask = GL_DEPTH_BUFFER_BIT;
273*35238bceSAndroid Build Coastguard Worker break;
274*35238bceSAndroid Build Coastguard Worker case 1:
275*35238bceSAndroid Build Coastguard Worker clear->clearMask = GL_STENCIL_BUFFER_BIT;
276*35238bceSAndroid Build Coastguard Worker break;
277*35238bceSAndroid Build Coastguard Worker case 2:
278*35238bceSAndroid Build Coastguard Worker clear->clearMask = GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT;
279*35238bceSAndroid Build Coastguard Worker break;
280*35238bceSAndroid Build Coastguard Worker }
281*35238bceSAndroid Build Coastguard Worker }
282*35238bceSAndroid Build Coastguard Worker else if (m_testDepth)
283*35238bceSAndroid Build Coastguard Worker clear->clearMask = GL_DEPTH_BUFFER_BIT;
284*35238bceSAndroid Build Coastguard Worker else
285*35238bceSAndroid Build Coastguard Worker {
286*35238bceSAndroid Build Coastguard Worker DE_ASSERT(m_testStencil);
287*35238bceSAndroid Build Coastguard Worker clear->clearMask = GL_STENCIL_BUFFER_BIT;
288*35238bceSAndroid Build Coastguard Worker }
289*35238bceSAndroid Build Coastguard Worker }
290*35238bceSAndroid Build Coastguard Worker }
291*35238bceSAndroid Build Coastguard Worker
renderGL(tcu::Surface & dst,const vector<Clear> & clears)292*35238bceSAndroid Build Coastguard Worker void DepthStencilClearCase::renderGL(tcu::Surface &dst, const vector<Clear> &clears)
293*35238bceSAndroid Build Coastguard Worker {
294*35238bceSAndroid Build Coastguard Worker const glw::Functions &gl = m_context.getRenderContext().getFunctions();
295*35238bceSAndroid Build Coastguard Worker int colorLoc = gl.getUniformLocation(m_visProgram->getProgram(), "u_color");
296*35238bceSAndroid Build Coastguard Worker int positionLoc = gl.getAttribLocation(m_visProgram->getProgram(), "a_position");
297*35238bceSAndroid Build Coastguard Worker static const uint8_t indices[] = {0, 1, 2, 2, 1, 3};
298*35238bceSAndroid Build Coastguard Worker
299*35238bceSAndroid Build Coastguard Worker // Clear with default values.
300*35238bceSAndroid Build Coastguard Worker gl.clearDepthf(1.0f);
301*35238bceSAndroid Build Coastguard Worker gl.clearStencil(0);
302*35238bceSAndroid Build Coastguard Worker gl.clearColor(1.0f, 0.0f, 0.0f, 1.0f);
303*35238bceSAndroid Build Coastguard Worker gl.clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
304*35238bceSAndroid Build Coastguard Worker
305*35238bceSAndroid Build Coastguard Worker GLU_EXPECT_NO_ERROR(gl.getError(), "Before clears");
306*35238bceSAndroid Build Coastguard Worker
307*35238bceSAndroid Build Coastguard Worker for (vector<Clear>::const_iterator clear = clears.begin(); clear != clears.end(); clear++)
308*35238bceSAndroid Build Coastguard Worker {
309*35238bceSAndroid Build Coastguard Worker if (clear->useScissor)
310*35238bceSAndroid Build Coastguard Worker {
311*35238bceSAndroid Build Coastguard Worker gl.enable(GL_SCISSOR_TEST);
312*35238bceSAndroid Build Coastguard Worker gl.scissor(clear->scissor.x(), clear->scissor.y(), clear->scissor.z(), clear->scissor.w());
313*35238bceSAndroid Build Coastguard Worker }
314*35238bceSAndroid Build Coastguard Worker
315*35238bceSAndroid Build Coastguard Worker // Clear values.
316*35238bceSAndroid Build Coastguard Worker gl.clearDepthf(clear->clearDepth);
317*35238bceSAndroid Build Coastguard Worker gl.clearStencil(clear->clearStencil);
318*35238bceSAndroid Build Coastguard Worker
319*35238bceSAndroid Build Coastguard Worker // Masks.
320*35238bceSAndroid Build Coastguard Worker gl.depthMask(clear->depthMask ? GL_TRUE : GL_FALSE);
321*35238bceSAndroid Build Coastguard Worker gl.stencilMask(clear->stencilMask);
322*35238bceSAndroid Build Coastguard Worker
323*35238bceSAndroid Build Coastguard Worker // Execute clear.
324*35238bceSAndroid Build Coastguard Worker gl.clear(clear->clearMask);
325*35238bceSAndroid Build Coastguard Worker
326*35238bceSAndroid Build Coastguard Worker if (clear->useScissor)
327*35238bceSAndroid Build Coastguard Worker gl.disable(GL_SCISSOR_TEST);
328*35238bceSAndroid Build Coastguard Worker }
329*35238bceSAndroid Build Coastguard Worker
330*35238bceSAndroid Build Coastguard Worker // Restore default masks.
331*35238bceSAndroid Build Coastguard Worker gl.depthMask(GL_TRUE);
332*35238bceSAndroid Build Coastguard Worker gl.stencilMask(0xffffffffu);
333*35238bceSAndroid Build Coastguard Worker
334*35238bceSAndroid Build Coastguard Worker GLU_EXPECT_NO_ERROR(gl.getError(), "After clears");
335*35238bceSAndroid Build Coastguard Worker
336*35238bceSAndroid Build Coastguard Worker gl.useProgram(m_visProgram->getProgram());
337*35238bceSAndroid Build Coastguard Worker gl.enableVertexAttribArray(positionLoc);
338*35238bceSAndroid Build Coastguard Worker
339*35238bceSAndroid Build Coastguard Worker // Visualize depth / stencil buffers.
340*35238bceSAndroid Build Coastguard Worker if (m_testDepth)
341*35238bceSAndroid Build Coastguard Worker {
342*35238bceSAndroid Build Coastguard Worker int numSteps = DEPTH_STEPS;
343*35238bceSAndroid Build Coastguard Worker float step = 2.0f / (float)numSteps;
344*35238bceSAndroid Build Coastguard Worker
345*35238bceSAndroid Build Coastguard Worker gl.enable(GL_DEPTH_TEST);
346*35238bceSAndroid Build Coastguard Worker gl.depthFunc(GL_LESS);
347*35238bceSAndroid Build Coastguard Worker gl.depthMask(GL_FALSE);
348*35238bceSAndroid Build Coastguard Worker gl.colorMask(GL_FALSE, GL_FALSE, GL_TRUE, GL_FALSE);
349*35238bceSAndroid Build Coastguard Worker
350*35238bceSAndroid Build Coastguard Worker for (int ndx = 0; ndx < numSteps; ndx++)
351*35238bceSAndroid Build Coastguard Worker {
352*35238bceSAndroid Build Coastguard Worker float d = -1.0f + step * (float)ndx;
353*35238bceSAndroid Build Coastguard Worker float c = (float)ndx / (float)(numSteps - 1);
354*35238bceSAndroid Build Coastguard Worker float pos[] = {-1.0f, -1.0f, d, -1.0f, 1.0f, d, 1.0f, -1.0f, d, 1.0f, 1.0f, d};
355*35238bceSAndroid Build Coastguard Worker
356*35238bceSAndroid Build Coastguard Worker gl.uniform4f(colorLoc, 0.0f, 0.0f, c, 1.0f);
357*35238bceSAndroid Build Coastguard Worker gl.vertexAttribPointer(positionLoc, 3, GL_FLOAT, GL_FALSE, 0, &pos[0]);
358*35238bceSAndroid Build Coastguard Worker gl.drawElements(GL_TRIANGLES, DE_LENGTH_OF_ARRAY(indices), GL_UNSIGNED_BYTE, &indices[0]);
359*35238bceSAndroid Build Coastguard Worker }
360*35238bceSAndroid Build Coastguard Worker
361*35238bceSAndroid Build Coastguard Worker gl.disable(GL_DEPTH_TEST);
362*35238bceSAndroid Build Coastguard Worker gl.depthMask(GL_TRUE);
363*35238bceSAndroid Build Coastguard Worker
364*35238bceSAndroid Build Coastguard Worker GLU_EXPECT_NO_ERROR(gl.getError(), "After depth visualization");
365*35238bceSAndroid Build Coastguard Worker }
366*35238bceSAndroid Build Coastguard Worker
367*35238bceSAndroid Build Coastguard Worker if (m_testStencil)
368*35238bceSAndroid Build Coastguard Worker {
369*35238bceSAndroid Build Coastguard Worker int numSteps = STENCIL_STEPS;
370*35238bceSAndroid Build Coastguard Worker int numValues = (1 << TestCase::m_context.getRenderContext().getRenderTarget().getStencilBits()); // 2^bits
371*35238bceSAndroid Build Coastguard Worker int step = numValues / numSteps;
372*35238bceSAndroid Build Coastguard Worker
373*35238bceSAndroid Build Coastguard Worker gl.enable(GL_STENCIL_TEST);
374*35238bceSAndroid Build Coastguard Worker gl.stencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
375*35238bceSAndroid Build Coastguard Worker gl.colorMask(GL_FALSE, GL_TRUE, GL_FALSE, GL_FALSE);
376*35238bceSAndroid Build Coastguard Worker
377*35238bceSAndroid Build Coastguard Worker static const float pos[] = {-1.0f, -1.0f, -1.0f, 1.0f, 1.0f, -1.0f, 1.0f, 1.0f};
378*35238bceSAndroid Build Coastguard Worker gl.vertexAttribPointer(positionLoc, 2, GL_FLOAT, GL_FALSE, 0, &pos[0]);
379*35238bceSAndroid Build Coastguard Worker
380*35238bceSAndroid Build Coastguard Worker for (int ndx = 0; ndx < numSteps; ndx++)
381*35238bceSAndroid Build Coastguard Worker {
382*35238bceSAndroid Build Coastguard Worker int s = step * ndx;
383*35238bceSAndroid Build Coastguard Worker float c = (float)ndx / (float)(numSteps - 1);
384*35238bceSAndroid Build Coastguard Worker
385*35238bceSAndroid Build Coastguard Worker gl.stencilFunc(GL_LEQUAL, s, 0xffu);
386*35238bceSAndroid Build Coastguard Worker gl.uniform4f(colorLoc, 0.0f, c, 0.0f, 1.0f);
387*35238bceSAndroid Build Coastguard Worker gl.drawElements(GL_TRIANGLES, DE_LENGTH_OF_ARRAY(indices), GL_UNSIGNED_BYTE, &indices[0]);
388*35238bceSAndroid Build Coastguard Worker }
389*35238bceSAndroid Build Coastguard Worker
390*35238bceSAndroid Build Coastguard Worker gl.disable(GL_STENCIL_TEST);
391*35238bceSAndroid Build Coastguard Worker
392*35238bceSAndroid Build Coastguard Worker GLU_EXPECT_NO_ERROR(gl.getError(), "After stencil visualization");
393*35238bceSAndroid Build Coastguard Worker }
394*35238bceSAndroid Build Coastguard Worker
395*35238bceSAndroid Build Coastguard Worker // Restore color mask (changed by visualization).
396*35238bceSAndroid Build Coastguard Worker gl.colorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
397*35238bceSAndroid Build Coastguard Worker
398*35238bceSAndroid Build Coastguard Worker glu::readPixels(m_context.getRenderContext(), 0, 0, dst.getAccess());
399*35238bceSAndroid Build Coastguard Worker }
400*35238bceSAndroid Build Coastguard Worker
renderReference(tcu::Surface & dst,const vector<Clear> & clears)401*35238bceSAndroid Build Coastguard Worker void DepthStencilClearCase::renderReference(tcu::Surface &dst, const vector<Clear> &clears)
402*35238bceSAndroid Build Coastguard Worker {
403*35238bceSAndroid Build Coastguard Worker glu::RenderContext &renderCtx = TestCase::m_context.getRenderContext();
404*35238bceSAndroid Build Coastguard Worker const tcu::RenderTarget &renderTarget = renderCtx.getRenderTarget();
405*35238bceSAndroid Build Coastguard Worker
406*35238bceSAndroid Build Coastguard Worker // Clear surface to red.
407*35238bceSAndroid Build Coastguard Worker tcu::clear(dst.getAccess(), tcu::RGBA::red().toVec());
408*35238bceSAndroid Build Coastguard Worker
409*35238bceSAndroid Build Coastguard Worker if (m_testDepth)
410*35238bceSAndroid Build Coastguard Worker {
411*35238bceSAndroid Build Coastguard Worker // Simulated depth buffer span.
412*35238bceSAndroid Build Coastguard Worker tcu::TextureLevel depthBufRow(getDepthFormat(renderTarget.getDepthBits()), dst.getWidth(), 1, 1);
413*35238bceSAndroid Build Coastguard Worker tcu::PixelBufferAccess rowAccess = depthBufRow.getAccess();
414*35238bceSAndroid Build Coastguard Worker
415*35238bceSAndroid Build Coastguard Worker for (int y = 0; y < dst.getHeight(); y++)
416*35238bceSAndroid Build Coastguard Worker {
417*35238bceSAndroid Build Coastguard Worker // Clear to default value.
418*35238bceSAndroid Build Coastguard Worker for (int x = 0; x < rowAccess.getWidth(); x++)
419*35238bceSAndroid Build Coastguard Worker rowAccess.setPixel(Vec4(1.0f), x, 0);
420*35238bceSAndroid Build Coastguard Worker
421*35238bceSAndroid Build Coastguard Worker // Execute clears.
422*35238bceSAndroid Build Coastguard Worker for (vector<Clear>::const_iterator clear = clears.begin(); clear != clears.end(); clear++)
423*35238bceSAndroid Build Coastguard Worker {
424*35238bceSAndroid Build Coastguard Worker // Clear / mask test.
425*35238bceSAndroid Build Coastguard Worker if ((clear->clearMask & GL_DEPTH_BUFFER_BIT) == 0 || !clear->depthMask)
426*35238bceSAndroid Build Coastguard Worker continue;
427*35238bceSAndroid Build Coastguard Worker
428*35238bceSAndroid Build Coastguard Worker tcu::IVec4 clearRect =
429*35238bceSAndroid Build Coastguard Worker clear->useScissor ? clear->scissor : tcu::IVec4(0, 0, dst.getWidth(), dst.getHeight());
430*35238bceSAndroid Build Coastguard Worker
431*35238bceSAndroid Build Coastguard Worker // Intersection test.
432*35238bceSAndroid Build Coastguard Worker if (!de::inBounds(y, clearRect.y(), clearRect.y() + clearRect.w()))
433*35238bceSAndroid Build Coastguard Worker continue;
434*35238bceSAndroid Build Coastguard Worker
435*35238bceSAndroid Build Coastguard Worker for (int x = clearRect.x(); x < clearRect.x() + clearRect.z(); x++)
436*35238bceSAndroid Build Coastguard Worker rowAccess.setPixDepth(de::clamp(clear->clearDepth, 0.0f, 1.0f), x, 0);
437*35238bceSAndroid Build Coastguard Worker }
438*35238bceSAndroid Build Coastguard Worker
439*35238bceSAndroid Build Coastguard Worker // Map to colors.
440*35238bceSAndroid Build Coastguard Worker for (int x = 0; x < dst.getWidth(); x++)
441*35238bceSAndroid Build Coastguard Worker {
442*35238bceSAndroid Build Coastguard Worker float depth = rowAccess.getPixDepth(x, 0);
443*35238bceSAndroid Build Coastguard Worker float step = deFloatFloor(depth * (float)DEPTH_STEPS) / (float)(DEPTH_STEPS - 1);
444*35238bceSAndroid Build Coastguard Worker tcu::RGBA oldColor = dst.getPixel(x, y);
445*35238bceSAndroid Build Coastguard Worker tcu::RGBA newColor =
446*35238bceSAndroid Build Coastguard Worker tcu::RGBA(oldColor.getRed(), oldColor.getGreen(),
447*35238bceSAndroid Build Coastguard Worker deClamp32(deRoundFloatToInt32(step * 255.0f), 0, 255), oldColor.getAlpha());
448*35238bceSAndroid Build Coastguard Worker
449*35238bceSAndroid Build Coastguard Worker dst.setPixel(x, y, newColor);
450*35238bceSAndroid Build Coastguard Worker }
451*35238bceSAndroid Build Coastguard Worker }
452*35238bceSAndroid Build Coastguard Worker }
453*35238bceSAndroid Build Coastguard Worker
454*35238bceSAndroid Build Coastguard Worker if (m_testStencil)
455*35238bceSAndroid Build Coastguard Worker {
456*35238bceSAndroid Build Coastguard Worker // Simulated stencil buffer span.
457*35238bceSAndroid Build Coastguard Worker int stencilBits = renderTarget.getStencilBits();
458*35238bceSAndroid Build Coastguard Worker tcu::TextureLevel depthBufRow(getStencilFormat(stencilBits), dst.getWidth(), 1, 1);
459*35238bceSAndroid Build Coastguard Worker tcu::PixelBufferAccess rowAccess = depthBufRow.getAccess();
460*35238bceSAndroid Build Coastguard Worker uint32_t bufMask = (1u << stencilBits) - 1;
461*35238bceSAndroid Build Coastguard Worker
462*35238bceSAndroid Build Coastguard Worker for (int y = 0; y < dst.getHeight(); y++)
463*35238bceSAndroid Build Coastguard Worker {
464*35238bceSAndroid Build Coastguard Worker // Clear to default value.
465*35238bceSAndroid Build Coastguard Worker for (int x = 0; x < rowAccess.getWidth(); x++)
466*35238bceSAndroid Build Coastguard Worker rowAccess.setPixel(tcu::UVec4(0), x, 0);
467*35238bceSAndroid Build Coastguard Worker
468*35238bceSAndroid Build Coastguard Worker // Execute clears.
469*35238bceSAndroid Build Coastguard Worker for (vector<Clear>::const_iterator clear = clears.begin(); clear != clears.end(); clear++)
470*35238bceSAndroid Build Coastguard Worker {
471*35238bceSAndroid Build Coastguard Worker // Clear / mask test.
472*35238bceSAndroid Build Coastguard Worker if ((clear->clearMask & GL_STENCIL_BUFFER_BIT) == 0 || clear->stencilMask == 0)
473*35238bceSAndroid Build Coastguard Worker continue;
474*35238bceSAndroid Build Coastguard Worker
475*35238bceSAndroid Build Coastguard Worker tcu::IVec4 clearRect =
476*35238bceSAndroid Build Coastguard Worker clear->useScissor ? clear->scissor : tcu::IVec4(0, 0, dst.getWidth(), dst.getHeight());
477*35238bceSAndroid Build Coastguard Worker
478*35238bceSAndroid Build Coastguard Worker // Intersection test.
479*35238bceSAndroid Build Coastguard Worker if (!de::inBounds(y, clearRect.y(), clearRect.y() + clearRect.w()))
480*35238bceSAndroid Build Coastguard Worker continue;
481*35238bceSAndroid Build Coastguard Worker
482*35238bceSAndroid Build Coastguard Worker for (int x = clearRect.x(); x < clearRect.x() + clearRect.z(); x++)
483*35238bceSAndroid Build Coastguard Worker {
484*35238bceSAndroid Build Coastguard Worker uint32_t oldVal = rowAccess.getPixStencil(x, 0);
485*35238bceSAndroid Build Coastguard Worker uint32_t newVal =
486*35238bceSAndroid Build Coastguard Worker ((oldVal & ~clear->stencilMask) | (clear->clearStencil & clear->stencilMask)) & bufMask;
487*35238bceSAndroid Build Coastguard Worker rowAccess.setPixStencil(newVal, x, 0);
488*35238bceSAndroid Build Coastguard Worker }
489*35238bceSAndroid Build Coastguard Worker }
490*35238bceSAndroid Build Coastguard Worker
491*35238bceSAndroid Build Coastguard Worker // Map to colors.
492*35238bceSAndroid Build Coastguard Worker for (int x = 0; x < dst.getWidth(); x++)
493*35238bceSAndroid Build Coastguard Worker {
494*35238bceSAndroid Build Coastguard Worker uint32_t stencil = rowAccess.getPixStencil(x, 0);
495*35238bceSAndroid Build Coastguard Worker float step =
496*35238bceSAndroid Build Coastguard Worker (float)(stencil / ((1u << stencilBits) / (uint32_t)STENCIL_STEPS)) / (float)(STENCIL_STEPS - 1);
497*35238bceSAndroid Build Coastguard Worker tcu::RGBA oldColor = dst.getPixel(x, y);
498*35238bceSAndroid Build Coastguard Worker tcu::RGBA newColor = tcu::RGBA(oldColor.getRed(), deClamp32(deRoundFloatToInt32(step * 255.0f), 0, 255),
499*35238bceSAndroid Build Coastguard Worker oldColor.getBlue(), oldColor.getAlpha());
500*35238bceSAndroid Build Coastguard Worker
501*35238bceSAndroid Build Coastguard Worker dst.setPixel(x, y, newColor);
502*35238bceSAndroid Build Coastguard Worker }
503*35238bceSAndroid Build Coastguard Worker }
504*35238bceSAndroid Build Coastguard Worker }
505*35238bceSAndroid Build Coastguard Worker }
506*35238bceSAndroid Build Coastguard Worker
DepthStencilClearTests(Context & context)507*35238bceSAndroid Build Coastguard Worker DepthStencilClearTests::DepthStencilClearTests(Context &context)
508*35238bceSAndroid Build Coastguard Worker : TestCaseGroup(context, "depth_stencil_clear", "Depth and stencil clear tests")
509*35238bceSAndroid Build Coastguard Worker {
510*35238bceSAndroid Build Coastguard Worker }
511*35238bceSAndroid Build Coastguard Worker
init(void)512*35238bceSAndroid Build Coastguard Worker void DepthStencilClearTests::init(void)
513*35238bceSAndroid Build Coastguard Worker {
514*35238bceSAndroid Build Coastguard Worker // iters clears depth stencil scissor masked
515*35238bceSAndroid Build Coastguard Worker addChild(new DepthStencilClearCase(m_context, "depth", "", 4, 2, true, false, false, false));
516*35238bceSAndroid Build Coastguard Worker addChild(new DepthStencilClearCase(m_context, "depth_scissored", "", 4, 16, true, false, true, false));
517*35238bceSAndroid Build Coastguard Worker addChild(new DepthStencilClearCase(m_context, "depth_scissored_masked", "", 4, 16, true, false, true, true));
518*35238bceSAndroid Build Coastguard Worker
519*35238bceSAndroid Build Coastguard Worker addChild(new DepthStencilClearCase(m_context, "stencil", "", 4, 2, false, true, false, false));
520*35238bceSAndroid Build Coastguard Worker addChild(new DepthStencilClearCase(m_context, "stencil_masked", "", 4, 8, false, true, false, true));
521*35238bceSAndroid Build Coastguard Worker addChild(new DepthStencilClearCase(m_context, "stencil_scissored", "", 4, 16, false, true, true, false));
522*35238bceSAndroid Build Coastguard Worker addChild(new DepthStencilClearCase(m_context, "stencil_scissored_masked", "", 4, 16, false, true, true, true));
523*35238bceSAndroid Build Coastguard Worker
524*35238bceSAndroid Build Coastguard Worker addChild(new DepthStencilClearCase(m_context, "depth_stencil", "", 4, 2, true, true, false, false));
525*35238bceSAndroid Build Coastguard Worker addChild(new DepthStencilClearCase(m_context, "depth_stencil_masked", "", 4, 8, true, true, false, true));
526*35238bceSAndroid Build Coastguard Worker addChild(new DepthStencilClearCase(m_context, "depth_stencil_scissored", "", 4, 16, true, true, true, false));
527*35238bceSAndroid Build Coastguard Worker addChild(new DepthStencilClearCase(m_context, "depth_stencil_scissored_masked", "", 4, 16, true, true, true, true));
528*35238bceSAndroid Build Coastguard Worker }
529*35238bceSAndroid Build Coastguard Worker
530*35238bceSAndroid Build Coastguard Worker } // namespace Functional
531*35238bceSAndroid Build Coastguard Worker } // namespace gles2
532*35238bceSAndroid Build Coastguard Worker } // namespace deqp
533