xref: /aosp_15_r20/external/deqp/modules/gles2/functional/es2fStencilTests.cpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
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 Stencil tests.
22*35238bceSAndroid Build Coastguard Worker  *//*--------------------------------------------------------------------*/
23*35238bceSAndroid Build Coastguard Worker 
24*35238bceSAndroid Build Coastguard Worker #include "es2fStencilTests.hpp"
25*35238bceSAndroid Build Coastguard Worker 
26*35238bceSAndroid Build Coastguard Worker #include "tcuSurface.hpp"
27*35238bceSAndroid Build Coastguard Worker #include "tcuVector.hpp"
28*35238bceSAndroid Build Coastguard Worker #include "tcuTestLog.hpp"
29*35238bceSAndroid Build Coastguard Worker #include "tcuImageCompare.hpp"
30*35238bceSAndroid Build Coastguard Worker #include "tcuRenderTarget.hpp"
31*35238bceSAndroid Build Coastguard Worker 
32*35238bceSAndroid Build Coastguard Worker #include "sglrContextUtil.hpp"
33*35238bceSAndroid Build Coastguard Worker #include "sglrGLContext.hpp"
34*35238bceSAndroid Build Coastguard Worker #include "sglrReferenceContext.hpp"
35*35238bceSAndroid Build Coastguard Worker 
36*35238bceSAndroid Build Coastguard Worker #include "deRandom.hpp"
37*35238bceSAndroid Build Coastguard Worker #include "deMath.h"
38*35238bceSAndroid Build Coastguard Worker #include "deString.h"
39*35238bceSAndroid Build Coastguard Worker 
40*35238bceSAndroid Build Coastguard Worker #include <vector>
41*35238bceSAndroid Build Coastguard Worker 
42*35238bceSAndroid Build Coastguard Worker #include "glwEnums.hpp"
43*35238bceSAndroid Build Coastguard Worker #include "glwDefs.hpp"
44*35238bceSAndroid Build Coastguard Worker 
45*35238bceSAndroid Build Coastguard Worker using std::vector;
46*35238bceSAndroid Build Coastguard Worker using tcu::IVec2;
47*35238bceSAndroid Build Coastguard Worker using tcu::IVec4;
48*35238bceSAndroid Build Coastguard Worker using tcu::Vec3;
49*35238bceSAndroid Build Coastguard Worker using namespace glw;
50*35238bceSAndroid Build Coastguard Worker 
51*35238bceSAndroid Build Coastguard Worker namespace deqp
52*35238bceSAndroid Build Coastguard Worker {
53*35238bceSAndroid Build Coastguard Worker namespace gles2
54*35238bceSAndroid Build Coastguard Worker {
55*35238bceSAndroid Build Coastguard Worker namespace Functional
56*35238bceSAndroid Build Coastguard Worker {
57*35238bceSAndroid Build Coastguard Worker 
58*35238bceSAndroid Build Coastguard Worker class StencilShader : public sglr::ShaderProgram
59*35238bceSAndroid Build Coastguard Worker {
60*35238bceSAndroid Build Coastguard Worker public:
StencilShader(void)61*35238bceSAndroid Build Coastguard Worker     StencilShader(void)
62*35238bceSAndroid Build Coastguard Worker         : sglr::ShaderProgram(sglr::pdec::ShaderProgramDeclaration()
63*35238bceSAndroid Build Coastguard Worker                               << sglr::pdec::VertexAttribute("a_position", rr::GENERICVECTYPE_FLOAT)
64*35238bceSAndroid Build Coastguard Worker                               << sglr::pdec::VertexToFragmentVarying(rr::GENERICVECTYPE_FLOAT)
65*35238bceSAndroid Build Coastguard Worker                               << sglr::pdec::FragmentOutput(rr::GENERICVECTYPE_FLOAT)
66*35238bceSAndroid Build Coastguard Worker                               << sglr::pdec::Uniform("u_color", glu::TYPE_FLOAT_VEC4)
67*35238bceSAndroid Build Coastguard Worker                               << sglr::pdec::VertexSource("attribute highp vec4 a_position;\n"
68*35238bceSAndroid Build Coastguard Worker                                                           "void main (void)\n"
69*35238bceSAndroid Build Coastguard Worker                                                           "{\n"
70*35238bceSAndroid Build Coastguard Worker                                                           "    gl_Position = a_position;\n"
71*35238bceSAndroid Build Coastguard Worker                                                           "}\n")
72*35238bceSAndroid Build Coastguard Worker                               << sglr::pdec::FragmentSource("uniform mediump vec4 u_color;\n"
73*35238bceSAndroid Build Coastguard Worker                                                             "void main (void)\n"
74*35238bceSAndroid Build Coastguard Worker                                                             "{\n"
75*35238bceSAndroid Build Coastguard Worker                                                             "    gl_FragColor = u_color;\n"
76*35238bceSAndroid Build Coastguard Worker                                                             "}\n"))
77*35238bceSAndroid Build Coastguard Worker         , u_color(getUniformByName("u_color"))
78*35238bceSAndroid Build Coastguard Worker     {
79*35238bceSAndroid Build Coastguard Worker     }
80*35238bceSAndroid Build Coastguard Worker 
setColor(sglr::Context & ctx,uint32_t program,const tcu::Vec4 & color)81*35238bceSAndroid Build Coastguard Worker     void setColor(sglr::Context &ctx, uint32_t program, const tcu::Vec4 &color)
82*35238bceSAndroid Build Coastguard Worker     {
83*35238bceSAndroid Build Coastguard Worker         ctx.useProgram(program);
84*35238bceSAndroid Build Coastguard Worker         ctx.uniform4fv(ctx.getUniformLocation(program, "u_color"), 1, color.getPtr());
85*35238bceSAndroid Build Coastguard Worker     }
86*35238bceSAndroid Build Coastguard Worker 
87*35238bceSAndroid Build Coastguard Worker private:
shadeVertices(const rr::VertexAttrib * inputs,rr::VertexPacket * const * packets,const int numPackets) const88*35238bceSAndroid Build Coastguard Worker     void shadeVertices(const rr::VertexAttrib *inputs, rr::VertexPacket *const *packets, const int numPackets) const
89*35238bceSAndroid Build Coastguard Worker     {
90*35238bceSAndroid Build Coastguard Worker         for (int packetNdx = 0; packetNdx < numPackets; ++packetNdx)
91*35238bceSAndroid Build Coastguard Worker         {
92*35238bceSAndroid Build Coastguard Worker             rr::VertexPacket &packet = *packets[packetNdx];
93*35238bceSAndroid Build Coastguard Worker 
94*35238bceSAndroid Build Coastguard Worker             packet.position = rr::readVertexAttribFloat(inputs[0], packet.instanceNdx, packet.vertexNdx);
95*35238bceSAndroid Build Coastguard Worker         }
96*35238bceSAndroid Build Coastguard Worker     }
97*35238bceSAndroid Build Coastguard Worker 
shadeFragments(rr::FragmentPacket * packets,const int numPackets,const rr::FragmentShadingContext & context) const98*35238bceSAndroid Build Coastguard Worker     void shadeFragments(rr::FragmentPacket *packets, const int numPackets,
99*35238bceSAndroid Build Coastguard Worker                         const rr::FragmentShadingContext &context) const
100*35238bceSAndroid Build Coastguard Worker     {
101*35238bceSAndroid Build Coastguard Worker         const tcu::Vec4 color(u_color.value.f4);
102*35238bceSAndroid Build Coastguard Worker 
103*35238bceSAndroid Build Coastguard Worker         DE_UNREF(packets);
104*35238bceSAndroid Build Coastguard Worker 
105*35238bceSAndroid Build Coastguard Worker         for (int packetNdx = 0; packetNdx < numPackets; ++packetNdx)
106*35238bceSAndroid Build Coastguard Worker             for (int fragNdx = 0; fragNdx < 4; ++fragNdx)
107*35238bceSAndroid Build Coastguard Worker                 rr::writeFragmentOutput(context, packetNdx, fragNdx, 0, color);
108*35238bceSAndroid Build Coastguard Worker     }
109*35238bceSAndroid Build Coastguard Worker 
110*35238bceSAndroid Build Coastguard Worker     const sglr::UniformSlot &u_color;
111*35238bceSAndroid Build Coastguard Worker };
112*35238bceSAndroid Build Coastguard Worker 
113*35238bceSAndroid Build Coastguard Worker class StencilOp
114*35238bceSAndroid Build Coastguard Worker {
115*35238bceSAndroid Build Coastguard Worker public:
116*35238bceSAndroid Build Coastguard Worker     enum Type
117*35238bceSAndroid Build Coastguard Worker     {
118*35238bceSAndroid Build Coastguard Worker         TYPE_CLEAR_STENCIL = 0,
119*35238bceSAndroid Build Coastguard Worker         TYPE_CLEAR_DEPTH,
120*35238bceSAndroid Build Coastguard Worker         TYPE_QUAD,
121*35238bceSAndroid Build Coastguard Worker 
122*35238bceSAndroid Build Coastguard Worker         TYPE_LAST
123*35238bceSAndroid Build Coastguard Worker     };
124*35238bceSAndroid Build Coastguard Worker 
125*35238bceSAndroid Build Coastguard Worker     Type type;
126*35238bceSAndroid Build Coastguard Worker     GLenum stencilTest;
127*35238bceSAndroid Build Coastguard Worker     int stencil; //!< Ref for quad op, clear value for clears
128*35238bceSAndroid Build Coastguard Worker     uint32_t stencilMask;
129*35238bceSAndroid Build Coastguard Worker     GLenum depthTest;
130*35238bceSAndroid Build Coastguard Worker     float depth; //!< Quad depth or clear value
131*35238bceSAndroid Build Coastguard Worker     GLenum sFail;
132*35238bceSAndroid Build Coastguard Worker     GLenum dFail;
133*35238bceSAndroid Build Coastguard Worker     GLenum dPass;
134*35238bceSAndroid Build Coastguard Worker 
StencilOp(Type type_,GLenum stencilTest_=GL_ALWAYS,int stencil_=0,GLenum depthTest_=GL_ALWAYS,float depth_=1.0f,GLenum sFail_=GL_KEEP,GLenum dFail_=GL_KEEP,GLenum dPass_=GL_KEEP)135*35238bceSAndroid Build Coastguard Worker     StencilOp(Type type_, GLenum stencilTest_ = GL_ALWAYS, int stencil_ = 0, GLenum depthTest_ = GL_ALWAYS,
136*35238bceSAndroid Build Coastguard Worker               float depth_ = 1.0f, GLenum sFail_ = GL_KEEP, GLenum dFail_ = GL_KEEP, GLenum dPass_ = GL_KEEP)
137*35238bceSAndroid Build Coastguard Worker         : type(type_)
138*35238bceSAndroid Build Coastguard Worker         , stencilTest(stencilTest_)
139*35238bceSAndroid Build Coastguard Worker         , stencil(stencil_)
140*35238bceSAndroid Build Coastguard Worker         , stencilMask(0xffffffffu)
141*35238bceSAndroid Build Coastguard Worker         , depthTest(depthTest_)
142*35238bceSAndroid Build Coastguard Worker         , depth(depth_)
143*35238bceSAndroid Build Coastguard Worker         , sFail(sFail_)
144*35238bceSAndroid Build Coastguard Worker         , dFail(dFail_)
145*35238bceSAndroid Build Coastguard Worker         , dPass(dPass_)
146*35238bceSAndroid Build Coastguard Worker     {
147*35238bceSAndroid Build Coastguard Worker     }
148*35238bceSAndroid Build Coastguard Worker 
clearStencil(int stencil)149*35238bceSAndroid Build Coastguard Worker     static StencilOp clearStencil(int stencil)
150*35238bceSAndroid Build Coastguard Worker     {
151*35238bceSAndroid Build Coastguard Worker         StencilOp op(TYPE_CLEAR_STENCIL);
152*35238bceSAndroid Build Coastguard Worker         op.stencil = stencil;
153*35238bceSAndroid Build Coastguard Worker         return op;
154*35238bceSAndroid Build Coastguard Worker     }
155*35238bceSAndroid Build Coastguard Worker 
clearDepth(float depth)156*35238bceSAndroid Build Coastguard Worker     static StencilOp clearDepth(float depth)
157*35238bceSAndroid Build Coastguard Worker     {
158*35238bceSAndroid Build Coastguard Worker         StencilOp op(TYPE_CLEAR_DEPTH);
159*35238bceSAndroid Build Coastguard Worker         op.depth = depth;
160*35238bceSAndroid Build Coastguard Worker         return op;
161*35238bceSAndroid Build Coastguard Worker     }
162*35238bceSAndroid Build Coastguard Worker 
quad(GLenum stencilTest,int stencil,GLenum depthTest,float depth,GLenum sFail,GLenum dFail,GLenum dPass)163*35238bceSAndroid Build Coastguard Worker     static StencilOp quad(GLenum stencilTest, int stencil, GLenum depthTest, float depth, GLenum sFail, GLenum dFail,
164*35238bceSAndroid Build Coastguard Worker                           GLenum dPass)
165*35238bceSAndroid Build Coastguard Worker     {
166*35238bceSAndroid Build Coastguard Worker         return StencilOp(TYPE_QUAD, stencilTest, stencil, depthTest, depth, sFail, dFail, dPass);
167*35238bceSAndroid Build Coastguard Worker     }
168*35238bceSAndroid Build Coastguard Worker };
169*35238bceSAndroid Build Coastguard Worker 
170*35238bceSAndroid Build Coastguard Worker class StencilCase : public TestCase
171*35238bceSAndroid Build Coastguard Worker {
172*35238bceSAndroid Build Coastguard Worker public:
173*35238bceSAndroid Build Coastguard Worker     StencilCase(Context &context, const char *name, const char *description);
174*35238bceSAndroid Build Coastguard Worker     virtual ~StencilCase(void);
175*35238bceSAndroid Build Coastguard Worker 
176*35238bceSAndroid Build Coastguard Worker     void init(void);
177*35238bceSAndroid Build Coastguard Worker     void deinit(void);
178*35238bceSAndroid Build Coastguard Worker     IterateResult iterate(void);
179*35238bceSAndroid Build Coastguard Worker 
180*35238bceSAndroid Build Coastguard Worker     virtual void genOps(vector<StencilOp> &dst, int stencilBits, int depthBits, int targetStencil) = DE_NULL;
181*35238bceSAndroid Build Coastguard Worker 
182*35238bceSAndroid Build Coastguard Worker private:
183*35238bceSAndroid Build Coastguard Worker     void executeOps(sglr::Context &context, const IVec4 &cell, const vector<StencilOp> &ops);
184*35238bceSAndroid Build Coastguard Worker     void visualizeStencil(sglr::Context &context, int stencilBits, int stencilStep);
185*35238bceSAndroid Build Coastguard Worker 
186*35238bceSAndroid Build Coastguard Worker     StencilShader m_shader;
187*35238bceSAndroid Build Coastguard Worker     uint32_t m_shaderID;
188*35238bceSAndroid Build Coastguard Worker };
189*35238bceSAndroid Build Coastguard Worker 
StencilCase(Context & context,const char * name,const char * description)190*35238bceSAndroid Build Coastguard Worker StencilCase::StencilCase(Context &context, const char *name, const char *description)
191*35238bceSAndroid Build Coastguard Worker     : TestCase(context, name, description)
192*35238bceSAndroid Build Coastguard Worker     , m_shaderID(0)
193*35238bceSAndroid Build Coastguard Worker {
194*35238bceSAndroid Build Coastguard Worker }
195*35238bceSAndroid Build Coastguard Worker 
~StencilCase(void)196*35238bceSAndroid Build Coastguard Worker StencilCase::~StencilCase(void)
197*35238bceSAndroid Build Coastguard Worker {
198*35238bceSAndroid Build Coastguard Worker }
199*35238bceSAndroid Build Coastguard Worker 
init(void)200*35238bceSAndroid Build Coastguard Worker void StencilCase::init(void)
201*35238bceSAndroid Build Coastguard Worker {
202*35238bceSAndroid Build Coastguard Worker }
203*35238bceSAndroid Build Coastguard Worker 
deinit(void)204*35238bceSAndroid Build Coastguard Worker void StencilCase::deinit(void)
205*35238bceSAndroid Build Coastguard Worker {
206*35238bceSAndroid Build Coastguard Worker }
207*35238bceSAndroid Build Coastguard Worker 
executeOps(sglr::Context & context,const IVec4 & cell,const vector<StencilOp> & ops)208*35238bceSAndroid Build Coastguard Worker void StencilCase::executeOps(sglr::Context &context, const IVec4 &cell, const vector<StencilOp> &ops)
209*35238bceSAndroid Build Coastguard Worker {
210*35238bceSAndroid Build Coastguard Worker     // For quadOps
211*35238bceSAndroid Build Coastguard Worker     float x0 = 2.0f * ((float)cell.x() / (float)context.getWidth()) - 1.0f;
212*35238bceSAndroid Build Coastguard Worker     float y0 = 2.0f * ((float)cell.y() / (float)context.getHeight()) - 1.0f;
213*35238bceSAndroid Build Coastguard Worker     float x1 = x0 + 2.0f * ((float)cell.z() / (float)context.getWidth());
214*35238bceSAndroid Build Coastguard Worker     float y1 = y0 + 2.0f * ((float)cell.w() / (float)context.getHeight());
215*35238bceSAndroid Build Coastguard Worker 
216*35238bceSAndroid Build Coastguard Worker     m_shader.setColor(context, m_shaderID, tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f));
217*35238bceSAndroid Build Coastguard Worker 
218*35238bceSAndroid Build Coastguard Worker     for (vector<StencilOp>::const_iterator i = ops.begin(); i != ops.end(); i++)
219*35238bceSAndroid Build Coastguard Worker     {
220*35238bceSAndroid Build Coastguard Worker         const StencilOp &op = *i;
221*35238bceSAndroid Build Coastguard Worker 
222*35238bceSAndroid Build Coastguard Worker         switch (op.type)
223*35238bceSAndroid Build Coastguard Worker         {
224*35238bceSAndroid Build Coastguard Worker         case StencilOp::TYPE_CLEAR_DEPTH:
225*35238bceSAndroid Build Coastguard Worker             context.enable(GL_SCISSOR_TEST);
226*35238bceSAndroid Build Coastguard Worker             context.scissor(cell.x(), cell.y(), cell.z(), cell.w());
227*35238bceSAndroid Build Coastguard Worker             context.clearDepthf(op.depth);
228*35238bceSAndroid Build Coastguard Worker             context.clear(GL_DEPTH_BUFFER_BIT);
229*35238bceSAndroid Build Coastguard Worker             context.disable(GL_SCISSOR_TEST);
230*35238bceSAndroid Build Coastguard Worker             break;
231*35238bceSAndroid Build Coastguard Worker 
232*35238bceSAndroid Build Coastguard Worker         case StencilOp::TYPE_CLEAR_STENCIL:
233*35238bceSAndroid Build Coastguard Worker             context.enable(GL_SCISSOR_TEST);
234*35238bceSAndroid Build Coastguard Worker             context.scissor(cell.x(), cell.y(), cell.z(), cell.w());
235*35238bceSAndroid Build Coastguard Worker             context.clearStencil(op.stencil);
236*35238bceSAndroid Build Coastguard Worker             context.clear(GL_STENCIL_BUFFER_BIT);
237*35238bceSAndroid Build Coastguard Worker             context.disable(GL_SCISSOR_TEST);
238*35238bceSAndroid Build Coastguard Worker             break;
239*35238bceSAndroid Build Coastguard Worker 
240*35238bceSAndroid Build Coastguard Worker         case StencilOp::TYPE_QUAD:
241*35238bceSAndroid Build Coastguard Worker             context.enable(GL_DEPTH_TEST);
242*35238bceSAndroid Build Coastguard Worker             context.enable(GL_STENCIL_TEST);
243*35238bceSAndroid Build Coastguard Worker             context.depthFunc(op.depthTest);
244*35238bceSAndroid Build Coastguard Worker             context.stencilFunc(op.stencilTest, op.stencil, op.stencilMask);
245*35238bceSAndroid Build Coastguard Worker             context.stencilOp(op.sFail, op.dFail, op.dPass);
246*35238bceSAndroid Build Coastguard Worker             sglr::drawQuad(context, m_shaderID, Vec3(x0, y0, op.depth), Vec3(x1, y1, op.depth));
247*35238bceSAndroid Build Coastguard Worker             context.disable(GL_STENCIL_TEST);
248*35238bceSAndroid Build Coastguard Worker             context.disable(GL_DEPTH_TEST);
249*35238bceSAndroid Build Coastguard Worker             break;
250*35238bceSAndroid Build Coastguard Worker 
251*35238bceSAndroid Build Coastguard Worker         default:
252*35238bceSAndroid Build Coastguard Worker             DE_ASSERT(false);
253*35238bceSAndroid Build Coastguard Worker         }
254*35238bceSAndroid Build Coastguard Worker     }
255*35238bceSAndroid Build Coastguard Worker }
256*35238bceSAndroid Build Coastguard Worker 
visualizeStencil(sglr::Context & context,int stencilBits,int stencilStep)257*35238bceSAndroid Build Coastguard Worker void StencilCase::visualizeStencil(sglr::Context &context, int stencilBits, int stencilStep)
258*35238bceSAndroid Build Coastguard Worker {
259*35238bceSAndroid Build Coastguard Worker     int endVal           = 1 << stencilBits;
260*35238bceSAndroid Build Coastguard Worker     int numStencilValues = endVal / stencilStep + 1;
261*35238bceSAndroid Build Coastguard Worker 
262*35238bceSAndroid Build Coastguard Worker     context.enable(GL_STENCIL_TEST);
263*35238bceSAndroid Build Coastguard Worker     context.stencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
264*35238bceSAndroid Build Coastguard Worker 
265*35238bceSAndroid Build Coastguard Worker     for (int ndx = 0; ndx < numStencilValues; ndx++)
266*35238bceSAndroid Build Coastguard Worker     {
267*35238bceSAndroid Build Coastguard Worker         int value      = deMin32(ndx * stencilStep, endVal - 1);
268*35238bceSAndroid Build Coastguard Worker         float colorMix = (float)value / (float)de::max(1, endVal - 1);
269*35238bceSAndroid Build Coastguard Worker         tcu::Vec4 color(0.0f, 1.0f - colorMix, colorMix, 1.0f);
270*35238bceSAndroid Build Coastguard Worker 
271*35238bceSAndroid Build Coastguard Worker         m_shader.setColor(context, m_shaderID, color);
272*35238bceSAndroid Build Coastguard Worker         context.stencilFunc(GL_EQUAL, value, 0xffffffffu);
273*35238bceSAndroid Build Coastguard Worker         sglr::drawQuad(context, m_shaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(+1.0f, +1.0f, 0.0f));
274*35238bceSAndroid Build Coastguard Worker     }
275*35238bceSAndroid Build Coastguard Worker }
276*35238bceSAndroid Build Coastguard Worker 
iterate(void)277*35238bceSAndroid Build Coastguard Worker TestCase::IterateResult StencilCase::iterate(void)
278*35238bceSAndroid Build Coastguard Worker {
279*35238bceSAndroid Build Coastguard Worker     const tcu::RenderTarget &renderTarget = m_context.getRenderContext().getRenderTarget();
280*35238bceSAndroid Build Coastguard Worker     int depthBits                         = renderTarget.getDepthBits();
281*35238bceSAndroid Build Coastguard Worker     int stencilBits                       = renderTarget.getStencilBits();
282*35238bceSAndroid Build Coastguard Worker 
283*35238bceSAndroid Build Coastguard Worker     int stencilStep      = stencilBits == 8 ? 8 : 1;
284*35238bceSAndroid Build Coastguard Worker     int numStencilValues = (1 << stencilBits) / stencilStep + 1;
285*35238bceSAndroid Build Coastguard Worker 
286*35238bceSAndroid Build Coastguard Worker     int gridSize = (int)deFloatCeil(deFloatSqrt((float)(numStencilValues + 2)));
287*35238bceSAndroid Build Coastguard Worker 
288*35238bceSAndroid Build Coastguard Worker     int width  = deMin32(128, renderTarget.getWidth());
289*35238bceSAndroid Build Coastguard Worker     int height = deMin32(128, renderTarget.getHeight());
290*35238bceSAndroid Build Coastguard Worker 
291*35238bceSAndroid Build Coastguard Worker     tcu::TestLog &log = m_testCtx.getLog();
292*35238bceSAndroid Build Coastguard Worker     de::Random rnd(deStringHash(m_name.c_str()));
293*35238bceSAndroid Build Coastguard Worker     int viewportX  = rnd.getInt(0, renderTarget.getWidth() - width);
294*35238bceSAndroid Build Coastguard Worker     int viewportY  = rnd.getInt(0, renderTarget.getHeight() - height);
295*35238bceSAndroid Build Coastguard Worker     IVec4 viewport = IVec4(viewportX, viewportY, width, height);
296*35238bceSAndroid Build Coastguard Worker 
297*35238bceSAndroid Build Coastguard Worker     tcu::Surface gles2Frame(width, height);
298*35238bceSAndroid Build Coastguard Worker     tcu::Surface refFrame(width, height);
299*35238bceSAndroid Build Coastguard Worker     GLenum gles2Error;
300*35238bceSAndroid Build Coastguard Worker 
301*35238bceSAndroid Build Coastguard Worker     const char *failReason = DE_NULL;
302*35238bceSAndroid Build Coastguard Worker 
303*35238bceSAndroid Build Coastguard Worker     // Get ops for stencil values
304*35238bceSAndroid Build Coastguard Worker     vector<vector<StencilOp>> ops(numStencilValues + 2);
305*35238bceSAndroid Build Coastguard Worker     {
306*35238bceSAndroid Build Coastguard Worker         // Values from 0 to max
307*35238bceSAndroid Build Coastguard Worker         for (int ndx = 0; ndx < numStencilValues; ndx++)
308*35238bceSAndroid Build Coastguard Worker             genOps(ops[ndx], stencilBits, depthBits, deMin32(ndx * stencilStep, (1 << stencilBits) - 1));
309*35238bceSAndroid Build Coastguard Worker 
310*35238bceSAndroid Build Coastguard Worker         // -1 and max+1
311*35238bceSAndroid Build Coastguard Worker         genOps(ops[numStencilValues + 0], stencilBits, depthBits, 1 << stencilBits);
312*35238bceSAndroid Build Coastguard Worker         genOps(ops[numStencilValues + 1], stencilBits, depthBits, -1);
313*35238bceSAndroid Build Coastguard Worker     }
314*35238bceSAndroid Build Coastguard Worker 
315*35238bceSAndroid Build Coastguard Worker     // Compute cells: (x, y, w, h)
316*35238bceSAndroid Build Coastguard Worker     vector<IVec4> cells;
317*35238bceSAndroid Build Coastguard Worker     int cellWidth  = width / gridSize;
318*35238bceSAndroid Build Coastguard Worker     int cellHeight = height / gridSize;
319*35238bceSAndroid Build Coastguard Worker     for (int y = 0; y < gridSize; y++)
320*35238bceSAndroid Build Coastguard Worker         for (int x = 0; x < gridSize; x++)
321*35238bceSAndroid Build Coastguard Worker             cells.push_back(IVec4(x * cellWidth, y * cellHeight, cellWidth, cellHeight));
322*35238bceSAndroid Build Coastguard Worker 
323*35238bceSAndroid Build Coastguard Worker     DE_ASSERT(ops.size() <= cells.size());
324*35238bceSAndroid Build Coastguard Worker 
325*35238bceSAndroid Build Coastguard Worker     // Execute for gles2 context
326*35238bceSAndroid Build Coastguard Worker     {
327*35238bceSAndroid Build Coastguard Worker         sglr::GLContext context(m_context.getRenderContext(), log, 0 /* don't log calls or program */, viewport);
328*35238bceSAndroid Build Coastguard Worker 
329*35238bceSAndroid Build Coastguard Worker         m_shaderID = context.createProgram(&m_shader);
330*35238bceSAndroid Build Coastguard Worker 
331*35238bceSAndroid Build Coastguard Worker         context.clearColor(1.0f, 0.0f, 0.0f, 1.0f);
332*35238bceSAndroid Build Coastguard Worker         context.clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
333*35238bceSAndroid Build Coastguard Worker 
334*35238bceSAndroid Build Coastguard Worker         for (int ndx = 0; ndx < (int)ops.size(); ndx++)
335*35238bceSAndroid Build Coastguard Worker             executeOps(context, cells[ndx], ops[ndx]);
336*35238bceSAndroid Build Coastguard Worker 
337*35238bceSAndroid Build Coastguard Worker         visualizeStencil(context, stencilBits, stencilStep);
338*35238bceSAndroid Build Coastguard Worker 
339*35238bceSAndroid Build Coastguard Worker         gles2Error = context.getError();
340*35238bceSAndroid Build Coastguard Worker         context.readPixels(gles2Frame, 0, 0, width, height);
341*35238bceSAndroid Build Coastguard Worker     }
342*35238bceSAndroid Build Coastguard Worker 
343*35238bceSAndroid Build Coastguard Worker     // Execute for reference context
344*35238bceSAndroid Build Coastguard Worker     {
345*35238bceSAndroid Build Coastguard Worker         sglr::ReferenceContextBuffers buffers(
346*35238bceSAndroid Build Coastguard Worker             tcu::PixelFormat(8, 8, 8, renderTarget.getPixelFormat().alphaBits ? 8 : 0), renderTarget.getDepthBits(),
347*35238bceSAndroid Build Coastguard Worker             renderTarget.getStencilBits(), width, height);
348*35238bceSAndroid Build Coastguard Worker         sglr::ReferenceContext context(sglr::ReferenceContextLimits(m_context.getRenderContext()),
349*35238bceSAndroid Build Coastguard Worker                                        buffers.getColorbuffer(), buffers.getDepthbuffer(), buffers.getStencilbuffer());
350*35238bceSAndroid Build Coastguard Worker 
351*35238bceSAndroid Build Coastguard Worker         m_shaderID = context.createProgram(&m_shader);
352*35238bceSAndroid Build Coastguard Worker 
353*35238bceSAndroid Build Coastguard Worker         context.clearColor(1.0f, 0.0f, 0.0f, 1.0f);
354*35238bceSAndroid Build Coastguard Worker         context.clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
355*35238bceSAndroid Build Coastguard Worker 
356*35238bceSAndroid Build Coastguard Worker         for (int ndx = 0; ndx < (int)ops.size(); ndx++)
357*35238bceSAndroid Build Coastguard Worker             executeOps(context, cells[ndx], ops[ndx]);
358*35238bceSAndroid Build Coastguard Worker 
359*35238bceSAndroid Build Coastguard Worker         visualizeStencil(context, stencilBits, stencilStep);
360*35238bceSAndroid Build Coastguard Worker 
361*35238bceSAndroid Build Coastguard Worker         context.readPixels(refFrame, 0, 0, width, height);
362*35238bceSAndroid Build Coastguard Worker     }
363*35238bceSAndroid Build Coastguard Worker 
364*35238bceSAndroid Build Coastguard Worker     // Check error
365*35238bceSAndroid Build Coastguard Worker     bool errorCodeOk = (gles2Error == GL_NO_ERROR);
366*35238bceSAndroid Build Coastguard Worker     if (!errorCodeOk && !failReason)
367*35238bceSAndroid Build Coastguard Worker         failReason = "Got unexpected error";
368*35238bceSAndroid Build Coastguard Worker 
369*35238bceSAndroid Build Coastguard Worker     // Compare images
370*35238bceSAndroid Build Coastguard Worker     const float threshold = 0.02f;
371*35238bceSAndroid Build Coastguard Worker     bool imagesOk         = tcu::fuzzyCompare(log, "ComparisonResult", "Image comparison result", refFrame, gles2Frame,
372*35238bceSAndroid Build Coastguard Worker                                               threshold, tcu::COMPARE_LOG_RESULT);
373*35238bceSAndroid Build Coastguard Worker 
374*35238bceSAndroid Build Coastguard Worker     if (!imagesOk && !failReason)
375*35238bceSAndroid Build Coastguard Worker         failReason = "Image comparison failed";
376*35238bceSAndroid Build Coastguard Worker 
377*35238bceSAndroid Build Coastguard Worker     // Store test result
378*35238bceSAndroid Build Coastguard Worker     bool isOk = errorCodeOk && imagesOk;
379*35238bceSAndroid Build Coastguard Worker     m_testCtx.setTestResult(isOk ? QP_TEST_RESULT_PASS : QP_TEST_RESULT_FAIL, isOk ? "Pass" : failReason);
380*35238bceSAndroid Build Coastguard Worker 
381*35238bceSAndroid Build Coastguard Worker     return STOP;
382*35238bceSAndroid Build Coastguard Worker }
383*35238bceSAndroid Build Coastguard Worker 
StencilTests(Context & context)384*35238bceSAndroid Build Coastguard Worker StencilTests::StencilTests(Context &context) : TestCaseGroup(context, "stencil", "Stencil Tests")
385*35238bceSAndroid Build Coastguard Worker {
386*35238bceSAndroid Build Coastguard Worker }
387*35238bceSAndroid Build Coastguard Worker 
~StencilTests(void)388*35238bceSAndroid Build Coastguard Worker StencilTests::~StencilTests(void)
389*35238bceSAndroid Build Coastguard Worker {
390*35238bceSAndroid Build Coastguard Worker }
391*35238bceSAndroid Build Coastguard Worker 
392*35238bceSAndroid Build Coastguard Worker typedef void (*GenStencilOpsFunc)(vector<StencilOp> &dst, int stencilBits, int depthBits, int targetStencil);
393*35238bceSAndroid Build Coastguard Worker 
394*35238bceSAndroid Build Coastguard Worker class SimpleStencilCase : public StencilCase
395*35238bceSAndroid Build Coastguard Worker {
396*35238bceSAndroid Build Coastguard Worker public:
SimpleStencilCase(Context & context,const char * name,const char * description,GenStencilOpsFunc genOpsFunc)397*35238bceSAndroid Build Coastguard Worker     SimpleStencilCase(Context &context, const char *name, const char *description, GenStencilOpsFunc genOpsFunc)
398*35238bceSAndroid Build Coastguard Worker         : StencilCase(context, name, description)
399*35238bceSAndroid Build Coastguard Worker         , m_genOps(genOpsFunc)
400*35238bceSAndroid Build Coastguard Worker     {
401*35238bceSAndroid Build Coastguard Worker     }
402*35238bceSAndroid Build Coastguard Worker 
genOps(vector<StencilOp> & dst,int stencilBits,int depthBits,int targetStencil)403*35238bceSAndroid Build Coastguard Worker     void genOps(vector<StencilOp> &dst, int stencilBits, int depthBits, int targetStencil)
404*35238bceSAndroid Build Coastguard Worker     {
405*35238bceSAndroid Build Coastguard Worker         m_genOps(dst, stencilBits, depthBits, targetStencil);
406*35238bceSAndroid Build Coastguard Worker     }
407*35238bceSAndroid Build Coastguard Worker 
408*35238bceSAndroid Build Coastguard Worker private:
409*35238bceSAndroid Build Coastguard Worker     GenStencilOpsFunc m_genOps;
410*35238bceSAndroid Build Coastguard Worker };
411*35238bceSAndroid Build Coastguard Worker 
init(void)412*35238bceSAndroid Build Coastguard Worker void StencilTests::init(void)
413*35238bceSAndroid Build Coastguard Worker {
414*35238bceSAndroid Build Coastguard Worker #define STENCIL_CASE(NAME, DESCRIPTION, GEN_OPS_BODY)                                                     \
415*35238bceSAndroid Build Coastguard Worker     do                                                                                                    \
416*35238bceSAndroid Build Coastguard Worker     {                                                                                                     \
417*35238bceSAndroid Build Coastguard Worker         struct Gen_##NAME                                                                                 \
418*35238bceSAndroid Build Coastguard Worker         {                                                                                                 \
419*35238bceSAndroid Build Coastguard Worker             static void genOps(vector<StencilOp> &dst, int stencilBits, int depthBits, int targetStencil) \
420*35238bceSAndroid Build Coastguard Worker             {                                                                                             \
421*35238bceSAndroid Build Coastguard Worker                 DE_UNREF(stencilBits &&depthBits);                                                        \
422*35238bceSAndroid Build Coastguard Worker                 GEN_OPS_BODY                                                                              \
423*35238bceSAndroid Build Coastguard Worker             }                                                                                             \
424*35238bceSAndroid Build Coastguard Worker         };                                                                                                \
425*35238bceSAndroid Build Coastguard Worker         addChild(new SimpleStencilCase(m_context, #NAME, DESCRIPTION, Gen_##NAME::genOps));               \
426*35238bceSAndroid Build Coastguard Worker     } while (false);
427*35238bceSAndroid Build Coastguard Worker 
428*35238bceSAndroid Build Coastguard Worker     STENCIL_CASE(clear, "Stencil clear", {
429*35238bceSAndroid Build Coastguard Worker         // \note Unused bits are set to 1, clear should mask them out
430*35238bceSAndroid Build Coastguard Worker         int mask = (1 << stencilBits) - 1;
431*35238bceSAndroid Build Coastguard Worker         dst.push_back(StencilOp::clearStencil(targetStencil | ~mask));
432*35238bceSAndroid Build Coastguard Worker     })
433*35238bceSAndroid Build Coastguard Worker 
434*35238bceSAndroid Build Coastguard Worker     // Replace in different points
435*35238bceSAndroid Build Coastguard Worker     STENCIL_CASE(stencil_fail_replace, "Set stencil on stencil fail", {
436*35238bceSAndroid Build Coastguard Worker         dst.push_back(StencilOp::quad(GL_NEVER, targetStencil, GL_ALWAYS, 0.0f, GL_REPLACE, GL_KEEP, GL_KEEP));
437*35238bceSAndroid Build Coastguard Worker     })
438*35238bceSAndroid Build Coastguard Worker     STENCIL_CASE(depth_fail_replace, "Set stencil on depth fail", {
439*35238bceSAndroid Build Coastguard Worker         dst.push_back(StencilOp::clearDepth(0.0f));
440*35238bceSAndroid Build Coastguard Worker         dst.push_back(StencilOp::quad(GL_ALWAYS, targetStencil, GL_LESS, 0.5f, GL_KEEP, GL_REPLACE, GL_KEEP));
441*35238bceSAndroid Build Coastguard Worker     })
442*35238bceSAndroid Build Coastguard Worker     STENCIL_CASE(depth_pass_replace, "Set stencil on depth pass", {
443*35238bceSAndroid Build Coastguard Worker         dst.push_back(StencilOp::quad(GL_ALWAYS, targetStencil, GL_LESS, 0.0f, GL_KEEP, GL_KEEP, GL_REPLACE));
444*35238bceSAndroid Build Coastguard Worker     })
445*35238bceSAndroid Build Coastguard Worker 
446*35238bceSAndroid Build Coastguard Worker     // Increment, decrement
447*35238bceSAndroid Build Coastguard Worker     STENCIL_CASE(incr_stencil_fail, "Increment on stencil fail", {
448*35238bceSAndroid Build Coastguard Worker         if (targetStencil > 0)
449*35238bceSAndroid Build Coastguard Worker         {
450*35238bceSAndroid Build Coastguard Worker             dst.push_back(StencilOp::clearStencil(targetStencil - 1));
451*35238bceSAndroid Build Coastguard Worker             dst.push_back(StencilOp::quad(GL_EQUAL, targetStencil, GL_ALWAYS, 0.0f, GL_INCR, GL_KEEP, GL_KEEP));
452*35238bceSAndroid Build Coastguard Worker         }
453*35238bceSAndroid Build Coastguard Worker         else
454*35238bceSAndroid Build Coastguard Worker             dst.push_back(StencilOp::clearStencil(targetStencil));
455*35238bceSAndroid Build Coastguard Worker     })
456*35238bceSAndroid Build Coastguard Worker     STENCIL_CASE(decr_stencil_fail, "Decrement on stencil fail", {
457*35238bceSAndroid Build Coastguard Worker         int maxStencil = (1 << stencilBits) - 1;
458*35238bceSAndroid Build Coastguard Worker         if (targetStencil < maxStencil)
459*35238bceSAndroid Build Coastguard Worker         {
460*35238bceSAndroid Build Coastguard Worker             dst.push_back(StencilOp::clearStencil(targetStencil + 1));
461*35238bceSAndroid Build Coastguard Worker             dst.push_back(StencilOp::quad(GL_EQUAL, targetStencil, GL_ALWAYS, 0.0f, GL_DECR, GL_KEEP, GL_KEEP));
462*35238bceSAndroid Build Coastguard Worker         }
463*35238bceSAndroid Build Coastguard Worker         else
464*35238bceSAndroid Build Coastguard Worker             dst.push_back(StencilOp::clearStencil(targetStencil));
465*35238bceSAndroid Build Coastguard Worker     })
466*35238bceSAndroid Build Coastguard Worker     STENCIL_CASE(incr_wrap_stencil_fail, "Increment (wrap) on stencil fail", {
467*35238bceSAndroid Build Coastguard Worker         int maxStencil = (1 << stencilBits) - 1;
468*35238bceSAndroid Build Coastguard Worker         dst.push_back(StencilOp::clearStencil((targetStencil - 1) & maxStencil));
469*35238bceSAndroid Build Coastguard Worker         dst.push_back(StencilOp::quad(GL_EQUAL, targetStencil, GL_ALWAYS, 0.0f, GL_INCR_WRAP, GL_KEEP, GL_KEEP));
470*35238bceSAndroid Build Coastguard Worker     })
471*35238bceSAndroid Build Coastguard Worker     STENCIL_CASE(decr_wrap_stencil_fail, "Decrement (wrap) on stencil fail", {
472*35238bceSAndroid Build Coastguard Worker         int maxStencil = (1 << stencilBits) - 1;
473*35238bceSAndroid Build Coastguard Worker         dst.push_back(StencilOp::clearStencil((targetStencil + 1) & maxStencil));
474*35238bceSAndroid Build Coastguard Worker         dst.push_back(StencilOp::quad(GL_EQUAL, targetStencil, GL_ALWAYS, 0.0f, GL_DECR_WRAP, GL_KEEP, GL_KEEP));
475*35238bceSAndroid Build Coastguard Worker     })
476*35238bceSAndroid Build Coastguard Worker 
477*35238bceSAndroid Build Coastguard Worker     // Zero, Invert
478*35238bceSAndroid Build Coastguard Worker     STENCIL_CASE(zero_stencil_fail, "Zero on stencil fail", {
479*35238bceSAndroid Build Coastguard Worker         dst.push_back(StencilOp::clearStencil(targetStencil));
480*35238bceSAndroid Build Coastguard Worker         dst.push_back(StencilOp::quad(GL_NOTEQUAL, targetStencil, GL_ALWAYS, 0.0f, GL_ZERO, GL_KEEP, GL_KEEP));
481*35238bceSAndroid Build Coastguard Worker         dst.push_back(StencilOp::quad(GL_EQUAL, targetStencil, GL_ALWAYS, 0.0f, GL_REPLACE, GL_KEEP, GL_KEEP));
482*35238bceSAndroid Build Coastguard Worker     })
483*35238bceSAndroid Build Coastguard Worker     STENCIL_CASE(invert_stencil_fail, "Invert on stencil fail", {
484*35238bceSAndroid Build Coastguard Worker         int mask = (1 << stencilBits) - 1;
485*35238bceSAndroid Build Coastguard Worker         dst.push_back(StencilOp::clearStencil((~targetStencil) & mask));
486*35238bceSAndroid Build Coastguard Worker         dst.push_back(StencilOp::quad(GL_EQUAL, targetStencil, GL_ALWAYS, 0.0f, GL_INVERT, GL_KEEP, GL_KEEP));
487*35238bceSAndroid Build Coastguard Worker     })
488*35238bceSAndroid Build Coastguard Worker 
489*35238bceSAndroid Build Coastguard Worker     // Comparison modes
490*35238bceSAndroid Build Coastguard Worker     STENCIL_CASE(cmp_equal, "Equality comparison", {
491*35238bceSAndroid Build Coastguard Worker         int mask = (1 << stencilBits) - 1;
492*35238bceSAndroid Build Coastguard Worker         int inv  = (~targetStencil) & mask;
493*35238bceSAndroid Build Coastguard Worker         dst.push_back(StencilOp::clearStencil(inv));
494*35238bceSAndroid Build Coastguard Worker         dst.push_back(StencilOp::quad(GL_EQUAL, inv, GL_ALWAYS, 0.0f, GL_KEEP, GL_KEEP, GL_INVERT));
495*35238bceSAndroid Build Coastguard Worker         dst.push_back(StencilOp::quad(GL_EQUAL, inv, GL_ALWAYS, 0.0f, GL_KEEP, GL_KEEP, GL_INVERT));
496*35238bceSAndroid Build Coastguard Worker     })
497*35238bceSAndroid Build Coastguard Worker     STENCIL_CASE(cmp_not_equal, "Equality comparison", {
498*35238bceSAndroid Build Coastguard Worker         int mask = (1 << stencilBits) - 1;
499*35238bceSAndroid Build Coastguard Worker         int inv  = (~targetStencil) & mask;
500*35238bceSAndroid Build Coastguard Worker         dst.push_back(StencilOp::clearStencil(inv));
501*35238bceSAndroid Build Coastguard Worker         dst.push_back(StencilOp::quad(GL_NOTEQUAL, targetStencil, GL_ALWAYS, 0.0f, GL_KEEP, GL_KEEP, GL_INVERT));
502*35238bceSAndroid Build Coastguard Worker         dst.push_back(StencilOp::quad(GL_NOTEQUAL, targetStencil, GL_ALWAYS, 0.0f, GL_KEEP, GL_KEEP, GL_INVERT));
503*35238bceSAndroid Build Coastguard Worker     })
504*35238bceSAndroid Build Coastguard Worker     STENCIL_CASE(cmp_less_than, "Less than comparison", {
505*35238bceSAndroid Build Coastguard Worker         int maxStencil = (1 << stencilBits) - 1;
506*35238bceSAndroid Build Coastguard Worker         if (targetStencil < maxStencil)
507*35238bceSAndroid Build Coastguard Worker         {
508*35238bceSAndroid Build Coastguard Worker             dst.push_back(StencilOp::clearStencil(targetStencil + 1));
509*35238bceSAndroid Build Coastguard Worker             dst.push_back(StencilOp::quad(GL_LESS, targetStencil, GL_ALWAYS, 0.0f, GL_KEEP, GL_KEEP, GL_DECR));
510*35238bceSAndroid Build Coastguard Worker             dst.push_back(StencilOp::quad(GL_LESS, targetStencil, GL_ALWAYS, 0.0f, GL_KEEP, GL_KEEP, GL_DECR));
511*35238bceSAndroid Build Coastguard Worker         }
512*35238bceSAndroid Build Coastguard Worker         else
513*35238bceSAndroid Build Coastguard Worker             dst.push_back(StencilOp::clearStencil(targetStencil));
514*35238bceSAndroid Build Coastguard Worker     })
515*35238bceSAndroid Build Coastguard Worker     STENCIL_CASE(cmp_less_or_equal, "Less or equal comparison", {
516*35238bceSAndroid Build Coastguard Worker         int maxStencil = (1 << stencilBits) - 1;
517*35238bceSAndroid Build Coastguard Worker         if (targetStencil < maxStencil)
518*35238bceSAndroid Build Coastguard Worker         {
519*35238bceSAndroid Build Coastguard Worker             dst.push_back(StencilOp::clearStencil(targetStencil + 1));
520*35238bceSAndroid Build Coastguard Worker             dst.push_back(StencilOp::quad(GL_LEQUAL, targetStencil + 1, GL_ALWAYS, 0.0f, GL_KEEP, GL_KEEP, GL_DECR));
521*35238bceSAndroid Build Coastguard Worker             dst.push_back(StencilOp::quad(GL_LEQUAL, targetStencil + 1, GL_ALWAYS, 0.0f, GL_KEEP, GL_KEEP, GL_DECR));
522*35238bceSAndroid Build Coastguard Worker         }
523*35238bceSAndroid Build Coastguard Worker         else
524*35238bceSAndroid Build Coastguard Worker             dst.push_back(StencilOp::clearStencil(targetStencil));
525*35238bceSAndroid Build Coastguard Worker     })
526*35238bceSAndroid Build Coastguard Worker     STENCIL_CASE(cmp_greater_than, "Greater than comparison", {
527*35238bceSAndroid Build Coastguard Worker         if (targetStencil > 0)
528*35238bceSAndroid Build Coastguard Worker         {
529*35238bceSAndroid Build Coastguard Worker             dst.push_back(StencilOp::clearStencil(targetStencil - 1));
530*35238bceSAndroid Build Coastguard Worker             dst.push_back(StencilOp::quad(GL_GREATER, targetStencil, GL_ALWAYS, 0.0f, GL_KEEP, GL_KEEP, GL_INCR));
531*35238bceSAndroid Build Coastguard Worker             dst.push_back(StencilOp::quad(GL_GREATER, targetStencil, GL_ALWAYS, 0.0f, GL_KEEP, GL_KEEP, GL_INCR));
532*35238bceSAndroid Build Coastguard Worker         }
533*35238bceSAndroid Build Coastguard Worker         else
534*35238bceSAndroid Build Coastguard Worker             dst.push_back(StencilOp::clearStencil(targetStencil));
535*35238bceSAndroid Build Coastguard Worker     })
536*35238bceSAndroid Build Coastguard Worker     STENCIL_CASE(cmp_greater_or_equal, "Greater or equal comparison", {
537*35238bceSAndroid Build Coastguard Worker         if (targetStencil > 0)
538*35238bceSAndroid Build Coastguard Worker         {
539*35238bceSAndroid Build Coastguard Worker             dst.push_back(StencilOp::clearStencil(targetStencil - 1));
540*35238bceSAndroid Build Coastguard Worker             dst.push_back(StencilOp::quad(GL_GEQUAL, targetStencil - 1, GL_ALWAYS, 0.0f, GL_KEEP, GL_KEEP, GL_INCR));
541*35238bceSAndroid Build Coastguard Worker             dst.push_back(StencilOp::quad(GL_GEQUAL, targetStencil - 1, GL_ALWAYS, 0.0f, GL_KEEP, GL_KEEP, GL_INCR));
542*35238bceSAndroid Build Coastguard Worker         }
543*35238bceSAndroid Build Coastguard Worker         else
544*35238bceSAndroid Build Coastguard Worker             dst.push_back(StencilOp::clearStencil(targetStencil));
545*35238bceSAndroid Build Coastguard Worker     })
546*35238bceSAndroid Build Coastguard Worker     STENCIL_CASE(cmp_mask_equal, "Equality comparison with mask", {
547*35238bceSAndroid Build Coastguard Worker         int valMask = (1 << stencilBits) - 1;
548*35238bceSAndroid Build Coastguard Worker         int mask    = (1 << 7) | (1 << 5) | (1 << 3) | (1 << 1);
549*35238bceSAndroid Build Coastguard Worker         dst.push_back(StencilOp::clearStencil(~targetStencil));
550*35238bceSAndroid Build Coastguard Worker         StencilOp op =
551*35238bceSAndroid Build Coastguard Worker             StencilOp::quad(GL_EQUAL, (~targetStencil | ~mask) & valMask, GL_ALWAYS, 0.0f, GL_KEEP, GL_KEEP, GL_INVERT);
552*35238bceSAndroid Build Coastguard Worker         op.stencilMask = mask;
553*35238bceSAndroid Build Coastguard Worker         dst.push_back(op);
554*35238bceSAndroid Build Coastguard Worker     })
555*35238bceSAndroid Build Coastguard Worker }
556*35238bceSAndroid Build Coastguard Worker 
557*35238bceSAndroid Build Coastguard Worker } // namespace Functional
558*35238bceSAndroid Build Coastguard Worker } // namespace gles2
559*35238bceSAndroid Build Coastguard Worker } // namespace deqp
560