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