13c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*------------------------------------------------------------------------- 23c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * drawElements Quality Program OpenGL ES 3.0 Module 33c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * ------------------------------------------------- 43c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 53c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Copyright 2014 The Android Open Source Project 63c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 73c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Licensed under the Apache License, Version 2.0 (the "License"); 83c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * you may not use this file except in compliance with the License. 93c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * You may obtain a copy of the License at 103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * http://www.apache.org/licenses/LICENSE-2.0 123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Unless required by applicable law or agreed to in writing, software 143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * distributed under the License is distributed on an "AS IS" BASIS, 153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * See the License for the specific language governing permissions and 173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * limitations under the License. 183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*! 203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \file 213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief Stencil tests. 223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/ 233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "es3fStencilTests.hpp" 253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuSurface.hpp" 273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuVector.hpp" 283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuTestLog.hpp" 293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuImageCompare.hpp" 303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuRenderTarget.hpp" 313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "sglrContextUtil.hpp" 333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "sglrGLContext.hpp" 343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "sglrReferenceContext.hpp" 353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deRandom.hpp" 373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deMath.h" 383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deString.h" 393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <vector> 413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glwEnums.hpp" 433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glwDefs.hpp" 443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 453c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::Vec3; 463c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::IVec2; 473c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::IVec4; 483c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing std::vector; 493c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing namespace glw; 503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 513c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace deqp 523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 533c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace gles3 543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 553c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace Functional 563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 583c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass StencilShader : public sglr::ShaderProgram 593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 603c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry StencilShader (void) 623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : sglr::ShaderProgram(sglr::pdec::ShaderProgramDeclaration() 633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << sglr::pdec::VertexAttribute("a_position", rr::GENERICVECTYPE_FLOAT) 643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << sglr::pdec::VertexToFragmentVarying(rr::GENERICVECTYPE_FLOAT) 653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << sglr::pdec::FragmentOutput(rr::GENERICVECTYPE_FLOAT) 663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << sglr::pdec::Uniform("u_color", glu::TYPE_FLOAT_VEC4) 673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << sglr::pdec::VertexSource("#version 300 es\n" 683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "in highp vec4 a_position;\n" 693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "void main (void)\n" 703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "{\n" 713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry " gl_Position = a_position;\n" 723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "}\n") 733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry << sglr::pdec::FragmentSource("#version 300 es\n" 743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "uniform highp vec4 u_color;\n" 753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "layout(location = 0) out mediump vec4 o_color;\n" 763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "void main (void)\n" 773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "{\n" 783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry " o_color = u_color;\n" 793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "}\n")) 803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , u_color (getUniformByName("u_color")) 813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void setColor (sglr::Context& ctx, deUint32 program, const tcu::Vec4& color) 853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ctx.useProgram(program); 873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ctx.uniform4fv(ctx.getUniformLocation(program, "u_color"), 1, color.getPtr()); 883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 903c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate: 913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void shadeVertices (const rr::VertexAttrib* inputs, rr::VertexPacket* const* packets, const int numPackets) const 923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int packetNdx = 0; packetNdx < numPackets; ++packetNdx) 943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry rr::VertexPacket& packet = *packets[packetNdx]; 963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry packet.position = rr::readVertexAttribFloat(inputs[0], packet.instanceNdx, packet.vertexNdx); 983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void shadeFragments (rr::FragmentPacket* packets, const int numPackets, const rr::FragmentShadingContext& context) const 1023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::Vec4 color(u_color.value.f4); 1043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_UNREF(packets); 1063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int packetNdx = 0; packetNdx < numPackets; ++packetNdx) 1083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int fragNdx = 0; fragNdx < 4; ++fragNdx) 1093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry rr::writeFragmentOutput(context, packetNdx, fragNdx, 0, color); 1103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const sglr::UniformSlot& u_color; 1133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 1143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1153c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass StencilOp 1163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1173c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 1183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry enum Type 1193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TYPE_CLEAR_STENCIL = 0, 1213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TYPE_CLEAR_DEPTH, 1223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TYPE_QUAD, 1233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TYPE_LAST 1253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 1263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Type type; 1283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLenum stencilTest; 1293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int stencil; //!< Ref for quad op, clear value for clears 1303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 stencilMask; 1313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLenum depthTest; 1323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry float depth; //!< Quad depth or clear value 1333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLenum sFail; 1343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLenum dFail; 1353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLenum dPass; 1363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 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) 1383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : type (type_) 1393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , stencilTest (stencilTest_) 1403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , stencil (stencil_) 1413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , stencilMask (0xffffffffu) 1423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , depthTest (depthTest_) 1433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , depth (depth_) 1443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , sFail (sFail_) 1453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , dFail (dFail_) 1463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , dPass (dPass_) 1473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry static StencilOp clearStencil (int stencil) 1513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry StencilOp op(TYPE_CLEAR_STENCIL); 1533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry op.stencil = stencil; 1543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return op; 1553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry static StencilOp clearDepth (float depth) 1583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry StencilOp op(TYPE_CLEAR_DEPTH); 1603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry op.depth = depth; 1613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return op; 1623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry static StencilOp quad (GLenum stencilTest, int stencil, GLenum depthTest, float depth, GLenum sFail, GLenum dFail, GLenum dPass) 1653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return StencilOp(TYPE_QUAD, stencilTest, stencil, depthTest, depth, sFail, dFail, dPass); 1673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 1693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1703c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass StencilCase : public TestCase 1713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1723c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 1733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry StencilCase (Context& context, const char* name, const char* description); 1743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry virtual ~StencilCase (void); 1753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void init (void); 1773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void deinit (void); 1783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry IterateResult iterate (void); 1793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry virtual void genOps (vector<StencilOp>& dst, int stencilBits, int depthBits, int targetStencil) = DE_NULL; 1813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1823c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate: 1833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void executeOps (sglr::Context& context, const IVec4& cell, const vector<StencilOp>& ops); 1843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void visualizeStencil (sglr::Context& context, int stencilBits, int stencilStep); 1853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry StencilShader m_shader; 1873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 m_shaderID; 1883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 1893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1903c827367444ee418f129b2c238299f49d3264554Jarkko PoyryStencilCase::StencilCase (Context& context, const char* name, const char* description) 1913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : TestCase (context, name, description) 1923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_shaderID (0) 1933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1963c827367444ee418f129b2c238299f49d3264554Jarkko PoyryStencilCase::~StencilCase (void) 1973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2003c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid StencilCase::init (void) 2013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 2033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2043c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid StencilCase::deinit (void) 2053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 2073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2083c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid StencilCase::executeOps (sglr::Context& context, const IVec4& cell, const vector<StencilOp>& ops) 2093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // For quadOps 2113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry float x0 = 2.0f*((float)cell.x() / (float)context.getWidth())-1.0f; 2123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry float y0 = 2.0f*((float)cell.y() / (float)context.getHeight())-1.0f; 2133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry float x1 = x0 + 2.0f*((float)cell.z() / (float)context.getWidth()); 2143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry float y1 = y0 + 2.0f*((float)cell.w() / (float)context.getHeight()); 2153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_shader.setColor(context, m_shaderID, tcu::Vec4(0.0f, 0.0f, 0.0f, 1.0f)); 2173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (vector<StencilOp>::const_iterator i = ops.begin(); i != ops.end(); i++) 2193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const StencilOp& op = *i; 2213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry switch (op.type) 2233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case StencilOp::TYPE_CLEAR_DEPTH: 2253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry context.enable(GL_SCISSOR_TEST); 2263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry context.scissor(cell.x(), cell.y(), cell.z(), cell.w()); 2273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry context.clearDepthf(op.depth); 2283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry context.clear(GL_DEPTH_BUFFER_BIT); 2293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry context.disable(GL_SCISSOR_TEST); 2303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry break; 2313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case StencilOp::TYPE_CLEAR_STENCIL: 2333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry context.enable(GL_SCISSOR_TEST); 2343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry context.scissor(cell.x(), cell.y(), cell.z(), cell.w()); 2353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry context.clearStencil(op.stencil); 2363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry context.clear(GL_STENCIL_BUFFER_BIT); 2373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry context.disable(GL_SCISSOR_TEST); 2383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry break; 2393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case StencilOp::TYPE_QUAD: 2413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry context.enable(GL_DEPTH_TEST); 2423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry context.enable(GL_STENCIL_TEST); 2433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry context.depthFunc(op.depthTest); 2443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry context.stencilFunc(op.stencilTest, op.stencil, op.stencilMask); 2453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry context.stencilOp(op.sFail, op.dFail, op.dPass); 2463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry sglr::drawQuad(context, m_shaderID, Vec3(x0, y0, op.depth), Vec3(x1, y1, op.depth)); 2473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry context.disable(GL_STENCIL_TEST); 2483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry context.disable(GL_DEPTH_TEST); 2493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry break; 2503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry default: 2523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(DE_FALSE); 2533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 2563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2573c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid StencilCase::visualizeStencil (sglr::Context& context, int stencilBits, int stencilStep) 2583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int endVal = 1<<stencilBits; 2603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int numStencilValues = endVal/stencilStep + 1; 2613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry context.enable(GL_STENCIL_TEST); 2633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry context.stencilOp(GL_KEEP, GL_KEEP, GL_KEEP); 2643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int ndx = 0; ndx < numStencilValues; ndx++) 2663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int value = deMin32(ndx*stencilStep, endVal-1); 2683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry float colorMix = (float)value/(float)de::max(1, endVal-1); 2693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Vec4 color (0.0f, 1.0f-colorMix, colorMix, 1.0f); 2703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_shader.setColor(context, m_shaderID, color); 2723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry context.stencilFunc(GL_EQUAL, value, 0xffffffffu); 2733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry sglr::drawQuad(context, m_shaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(+1.0f, +1.0f, 0.0f)); 2743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 2763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2773c827367444ee418f129b2c238299f49d3264554Jarkko PoyryTestCase::IterateResult StencilCase::iterate (void) 2783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::RenderTarget& renderTarget = m_context.getRenderContext().getRenderTarget(); 2803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int depthBits = renderTarget.getDepthBits(); 2813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int stencilBits = renderTarget.getStencilBits(); 2823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int stencilStep = stencilBits == 8 ? 8 : 1; 2843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int numStencilValues = (1<<stencilBits)/stencilStep + 1; 2853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int gridSize = (int)deFloatCeil(deFloatSqrt((float)(numStencilValues+2))); 2873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int width = deMin32(128, renderTarget.getWidth()); 2893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int height = deMin32(128, renderTarget.getHeight()); 2903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::TestLog& log = m_testCtx.getLog(); 2923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry de::Random rnd (deStringHash(m_name.c_str())); 2933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int viewportX = rnd.getInt(0, renderTarget.getWidth()-width); 2943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int viewportY = rnd.getInt(0, renderTarget.getHeight()-height); 2953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry IVec4 viewport = IVec4(viewportX, viewportY, width, height); 2963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Surface gles2Frame (width, height); 2983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Surface refFrame (width, height); 2993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLenum gles2Error; 3003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const char* failReason = DE_NULL; 3023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Get ops for stencil values 3043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry vector<vector<StencilOp> > ops(numStencilValues+2); 3053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 3063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Values from 0 to max 3073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int ndx = 0; ndx < numStencilValues; ndx++) 3083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry genOps(ops[ndx], stencilBits, depthBits, deMin32(ndx*stencilStep, (1<<stencilBits)-1)); 3093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // -1 and max+1 3113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry genOps(ops[numStencilValues+0], stencilBits, depthBits, 1<<stencilBits); 3123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry genOps(ops[numStencilValues+1], stencilBits, depthBits, -1); 3133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 3143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Compute cells: (x, y, w, h) 3163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry vector<IVec4> cells; 3173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int cellWidth = width/gridSize; 3183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int cellHeight = height/gridSize; 3193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int y = 0; y < gridSize; y++) 3203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int x = 0; x < gridSize; x++) 3213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry cells.push_back(IVec4(x*cellWidth, y*cellHeight, cellWidth, cellHeight)); 3223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(ops.size() <= cells.size()); 3243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Execute for gles3 context 3263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 3273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry sglr::GLContext context(m_context.getRenderContext(), log, 0 /* don't log calls or program */, viewport); 3283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_shaderID = context.createProgram(&m_shader); 3303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry context.clearColor(1.0f, 0.0f, 0.0f, 1.0f); 3323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry context.clear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT); 3333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int ndx = 0; ndx < (int)ops.size(); ndx++) 3353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry executeOps(context, cells[ndx], ops[ndx]); 3363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry visualizeStencil(context, stencilBits, stencilStep); 3383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gles2Error = context.getError(); 3403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry context.readPixels(gles2Frame, 0, 0, width, height); 3413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 3423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Execute for reference context 3443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 3453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry sglr::ReferenceContextBuffers buffers (tcu::PixelFormat(8,8,8,renderTarget.getPixelFormat().alphaBits?8:0), renderTarget.getDepthBits(), renderTarget.getStencilBits(), width, height); 3463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry sglr::ReferenceContext context (sglr::ReferenceContextLimits(m_context.getRenderContext()), buffers.getColorbuffer(), buffers.getDepthbuffer(), buffers.getStencilbuffer()); 3473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_shaderID = context.createProgram(&m_shader); 3493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry context.clearColor(1.0f, 0.0f, 0.0f, 1.0f); 3513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry context.clear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT); 3523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int ndx = 0; ndx < (int)ops.size(); ndx++) 3543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry executeOps(context, cells[ndx], ops[ndx]); 3553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry visualizeStencil(context, stencilBits, stencilStep); 3573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry context.readPixels(refFrame, 0, 0, width, height); 3593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 3603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Check error 3623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool errorCodeOk = (gles2Error == GL_NO_ERROR); 3633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (!errorCodeOk && !failReason) 3643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry failReason = "Got unexpected error"; 3653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Compare images 3673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const float threshold = 0.02f; 3683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool imagesOk = tcu::fuzzyCompare(log, "ComparisonResult", "Image comparison result", refFrame, gles2Frame, threshold, tcu::COMPARE_LOG_RESULT); 3693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (!imagesOk && !failReason) 3713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry failReason = "Image comparison failed"; 3723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Store test result 3743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool isOk = errorCodeOk && imagesOk; 3753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.setTestResult(isOk ? QP_TEST_RESULT_PASS : QP_TEST_RESULT_FAIL, 3763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry isOk ? "Pass" : failReason); 3773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return STOP; 3793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 3803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3813c827367444ee418f129b2c238299f49d3264554Jarkko PoyryStencilTests::StencilTests (Context& context) 3823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : TestCaseGroup(context, "stencil", "Stencil Tests") 3833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 3843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 3853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3863c827367444ee418f129b2c238299f49d3264554Jarkko PoyryStencilTests::~StencilTests (void) 3873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 3883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 3893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3903c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytypedef void (*GenStencilOpsFunc) (vector<StencilOp>& dst, int stencilBits, int depthBits, int targetStencil); 3913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3923c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass SimpleStencilCase : public StencilCase 3933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 3943c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 3953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry SimpleStencilCase (Context& context, const char* name, const char* description, GenStencilOpsFunc genOpsFunc) 3963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : StencilCase (context, name, description) 3973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_genOps (genOpsFunc) 3983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 3993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 4003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void genOps (vector<StencilOp>& dst, int stencilBits, int depthBits, int targetStencil) 4023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 4033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_genOps(dst, stencilBits, depthBits, targetStencil); 4043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 4053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4063c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate: 4073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GenStencilOpsFunc m_genOps; 4083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 4093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4103c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid StencilTests::init (void) 4113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 4123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#define STENCIL_CASE(NAME, DESCRIPTION, GEN_OPS_BODY) \ 4133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry do { \ 4143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry struct Gen_##NAME { \ 4153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry static void genOps (vector<StencilOp>& dst, int stencilBits, int depthBits, int targetStencil) \ 4163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { \ 4173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_UNREF(stencilBits && depthBits); \ 4183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GEN_OPS_BODY \ 4193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } \ 4203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; \ 4213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addChild(new SimpleStencilCase(m_context, #NAME, DESCRIPTION, Gen_##NAME::genOps)); \ 4223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } while (deGetFalse()); 4233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry STENCIL_CASE(clear, "Stencil clear", 4253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 4263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // \note Unused bits are set to 1, clear should mask them out 4273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int mask = (1<<stencilBits)-1; 4283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry dst.push_back(StencilOp::clearStencil(targetStencil | ~mask)); 4293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }); 4303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Replace in different points 4323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry STENCIL_CASE(stencil_fail_replace, "Set stencil on stencil fail", 4333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 4343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry dst.push_back(StencilOp::quad(GL_NEVER, targetStencil, GL_ALWAYS, 0.0f, GL_REPLACE, GL_KEEP, GL_KEEP)); 4353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }); 4363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry STENCIL_CASE(depth_fail_replace, "Set stencil on depth fail", 4373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 4383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry dst.push_back(StencilOp::clearDepth(0.0f)); 4393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry dst.push_back(StencilOp::quad(GL_ALWAYS, targetStencil, GL_LESS, 0.5f, GL_KEEP, GL_REPLACE, GL_KEEP)); 4403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }); 4413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry STENCIL_CASE(depth_pass_replace, "Set stencil on depth pass", 4423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 4433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry dst.push_back(StencilOp::quad(GL_ALWAYS, targetStencil, GL_LESS, 0.0f, GL_KEEP, GL_KEEP, GL_REPLACE)); 4443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }); 4453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Increment, decrement 4473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry STENCIL_CASE(incr_stencil_fail, "Increment on stencil fail", 4483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 4493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (targetStencil > 0) 4503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 4513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry dst.push_back(StencilOp::clearStencil(targetStencil-1)); 4523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry dst.push_back(StencilOp::quad(GL_EQUAL, targetStencil, GL_ALWAYS, 0.0f, GL_INCR, GL_KEEP, GL_KEEP)); 4533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 4543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 4553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry dst.push_back(StencilOp::clearStencil(targetStencil)); 4563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }); 4573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry STENCIL_CASE(decr_stencil_fail, "Decrement on stencil fail", 4583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 4593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int maxStencil = (1<<stencilBits)-1; 4603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (targetStencil < maxStencil) 4613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 4623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry dst.push_back(StencilOp::clearStencil(targetStencil+1)); 4633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry dst.push_back(StencilOp::quad(GL_EQUAL, targetStencil, GL_ALWAYS, 0.0f, GL_DECR, GL_KEEP, GL_KEEP)); 4643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 4653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 4663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry dst.push_back(StencilOp::clearStencil(targetStencil)); 4673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }); 4683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry STENCIL_CASE(incr_wrap_stencil_fail, "Increment (wrap) on stencil fail", 4693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 4703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int maxStencil = (1<<stencilBits)-1; 4713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry dst.push_back(StencilOp::clearStencil((targetStencil-1)&maxStencil)); 4723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry dst.push_back(StencilOp::quad(GL_EQUAL, targetStencil, GL_ALWAYS, 0.0f, GL_INCR_WRAP, GL_KEEP, GL_KEEP)); 4733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }); 4743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry STENCIL_CASE(decr_wrap_stencil_fail, "Decrement (wrap) on stencil fail", 4753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 4763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int maxStencil = (1<<stencilBits)-1; 4773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry dst.push_back(StencilOp::clearStencil((targetStencil+1)&maxStencil)); 4783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry dst.push_back(StencilOp::quad(GL_EQUAL, targetStencil, GL_ALWAYS, 0.0f, GL_DECR_WRAP, GL_KEEP, GL_KEEP)); 4793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }); 4803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Zero, Invert 4823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry STENCIL_CASE(zero_stencil_fail, "Zero on stencil fail", 4833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 4843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry dst.push_back(StencilOp::clearStencil(targetStencil)); 4853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry dst.push_back(StencilOp::quad(GL_NOTEQUAL, targetStencil, GL_ALWAYS, 0.0f, GL_ZERO, GL_KEEP, GL_KEEP)); 4863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry dst.push_back(StencilOp::quad(GL_EQUAL, targetStencil, GL_ALWAYS, 0.0f, GL_REPLACE, GL_KEEP, GL_KEEP)); 4873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }); 4883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry STENCIL_CASE(invert_stencil_fail, "Invert on stencil fail", 4893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 4903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int mask = (1<<stencilBits)-1; 4913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry dst.push_back(StencilOp::clearStencil((~targetStencil)&mask)); 4923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry dst.push_back(StencilOp::quad(GL_EQUAL, targetStencil, GL_ALWAYS, 0.0f, GL_INVERT, GL_KEEP, GL_KEEP)); 4933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }); 4943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Comparison modes 4963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry STENCIL_CASE(cmp_equal, "Equality comparison", 4973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 4983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int mask = (1<<stencilBits)-1; 4993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int inv = (~targetStencil)&mask; 5003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry dst.push_back(StencilOp::clearStencil(inv)); 5013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry dst.push_back(StencilOp::quad(GL_EQUAL, inv, GL_ALWAYS, 0.0f, GL_KEEP, GL_KEEP, GL_INVERT)); 5023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry dst.push_back(StencilOp::quad(GL_EQUAL, inv, GL_ALWAYS, 0.0f, GL_KEEP, GL_KEEP, GL_INVERT)); 5033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }); 5043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry STENCIL_CASE(cmp_not_equal, "Equality comparison", 5053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 5063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int mask = (1<<stencilBits)-1; 5073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int inv = (~targetStencil)&mask; 5083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry dst.push_back(StencilOp::clearStencil(inv)); 5093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry dst.push_back(StencilOp::quad(GL_NOTEQUAL, targetStencil, GL_ALWAYS, 0.0f, GL_KEEP, GL_KEEP, GL_INVERT)); 5103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry dst.push_back(StencilOp::quad(GL_NOTEQUAL, targetStencil, GL_ALWAYS, 0.0f, GL_KEEP, GL_KEEP, GL_INVERT)); 5113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }); 5123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry STENCIL_CASE(cmp_less_than, "Less than comparison", 5133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 5143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int maxStencil = (1<<stencilBits)-1; 5153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (targetStencil < maxStencil) 5163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 5173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry dst.push_back(StencilOp::clearStencil(targetStencil+1)); 5183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry dst.push_back(StencilOp::quad(GL_LESS, targetStencil, GL_ALWAYS, 0.0f, GL_KEEP, GL_KEEP, GL_DECR)); 5193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry dst.push_back(StencilOp::quad(GL_LESS, targetStencil, GL_ALWAYS, 0.0f, GL_KEEP, GL_KEEP, GL_DECR)); 5203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 5213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 5223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry dst.push_back(StencilOp::clearStencil(targetStencil)); 5233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }); 5243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry STENCIL_CASE(cmp_less_or_equal, "Less or equal comparison", 5253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 5263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int maxStencil = (1<<stencilBits)-1; 5273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (targetStencil < maxStencil) 5283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 5293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry dst.push_back(StencilOp::clearStencil(targetStencil+1)); 5303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry dst.push_back(StencilOp::quad(GL_LEQUAL, targetStencil+1, GL_ALWAYS, 0.0f, GL_KEEP, GL_KEEP, GL_DECR)); 5313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry dst.push_back(StencilOp::quad(GL_LEQUAL, targetStencil+1, GL_ALWAYS, 0.0f, GL_KEEP, GL_KEEP, GL_DECR)); 5323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 5333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 5343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry dst.push_back(StencilOp::clearStencil(targetStencil)); 5353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }); 5363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry STENCIL_CASE(cmp_greater_than, "Greater than comparison", 5373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 5383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (targetStencil > 0) 5393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 5403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry dst.push_back(StencilOp::clearStencil(targetStencil-1)); 5413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry dst.push_back(StencilOp::quad(GL_GREATER, targetStencil, GL_ALWAYS, 0.0f, GL_KEEP, GL_KEEP, GL_INCR)); 5423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry dst.push_back(StencilOp::quad(GL_GREATER, targetStencil, GL_ALWAYS, 0.0f, GL_KEEP, GL_KEEP, GL_INCR)); 5433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 5443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 5453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry dst.push_back(StencilOp::clearStencil(targetStencil)); 5463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }); 5473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry STENCIL_CASE(cmp_greater_or_equal, "Greater or equal comparison", 5483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 5493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (targetStencil > 0) 5503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 5513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry dst.push_back(StencilOp::clearStencil(targetStencil-1)); 5523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry dst.push_back(StencilOp::quad(GL_GEQUAL, targetStencil-1, GL_ALWAYS, 0.0f, GL_KEEP, GL_KEEP, GL_INCR)); 5533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry dst.push_back(StencilOp::quad(GL_GEQUAL, targetStencil-1, GL_ALWAYS, 0.0f, GL_KEEP, GL_KEEP, GL_INCR)); 5543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 5553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 5563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry dst.push_back(StencilOp::clearStencil(targetStencil)); 5573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }); 5583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry STENCIL_CASE(cmp_mask_equal, "Equality comparison with mask", 5593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 5603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int valMask = (1<<stencilBits)-1; 5613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int mask = (1<<7)|(1<<5)|(1<<3)|(1<<1); 5623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry dst.push_back(StencilOp::clearStencil(~targetStencil)); 5633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry StencilOp op = StencilOp::quad(GL_EQUAL, (~targetStencil | ~mask) & valMask, GL_ALWAYS, 0.0f, GL_KEEP, GL_KEEP, GL_INVERT); 5643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry op.stencilMask = mask; 5653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry dst.push_back(op); 5663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }); 5673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 5683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // Functional 5703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // gles3 5713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // deqp 572