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 Depth and stencil clear tests. 223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/ 233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "es3fDepthStencilClearTests.hpp" 253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluShaderProgram.hpp" 273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluPixelTransfer.hpp" 283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluRenderContext.hpp" 293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuTestLog.hpp" 313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuTexture.hpp" 323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuTextureUtil.hpp" 333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuImageCompare.hpp" 343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuSurface.hpp" 353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuRenderTarget.hpp" 363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deRandom.hpp" 383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deMath.h" 393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deString.h" 403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glwFunctions.hpp" 423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glwEnums.hpp" 433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 443c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace deqp 453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 463c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace gles3 473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 483c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace Functional 493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 513c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::Vec3; 523c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::Vec4; 533c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::TestLog; 543c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing std::string; 553c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing std::vector; 563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 573c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace 583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 603c827367444ee418f129b2c238299f49d3264554Jarkko Poyryenum 613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry STENCIL_STEPS = 32, 633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DEPTH_STEPS = 32 643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 663c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct Clear 673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Clear (void) 693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : clearMask (0) 703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , clearDepth (0.0f) 713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , clearStencil (0) 723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , useScissor (false) 733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , scissor (0, 0, 0, 0) 743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , depthMask (false) 753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , stencilMask (0) 763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 clearMask; 803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry float clearDepth; 813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int clearStencil; 823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool useScissor; 843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::IVec4 scissor; 853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool depthMask; 873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 stencilMask; 883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 903c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytcu::TextureFormat getDepthFormat (int depthBits) 913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry switch (depthBits) 933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case 8: return tcu::TextureFormat(tcu::TextureFormat::D, tcu::TextureFormat::UNORM_INT8); 953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case 16: return tcu::TextureFormat(tcu::TextureFormat::D, tcu::TextureFormat::UNORM_INT16); 96db6ba452c1213fd1c2b03369fdf4c1d23f07cfadJarkko Pöyry case 24: return tcu::TextureFormat(tcu::TextureFormat::D, tcu::TextureFormat::UNORM_INT24); 973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case 32: return tcu::TextureFormat(tcu::TextureFormat::D, tcu::TextureFormat::FLOAT); 983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry default: 993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TCU_FAIL("Can't map depth buffer format"); 1003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1033c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytcu::TextureFormat getStencilFormat (int stencilBits) 1043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry switch (stencilBits) 1063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case 8: return tcu::TextureFormat(tcu::TextureFormat::S, tcu::TextureFormat::UNSIGNED_INT8); 1083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case 16: return tcu::TextureFormat(tcu::TextureFormat::S, tcu::TextureFormat::UNSIGNED_INT16); 109db6ba452c1213fd1c2b03369fdf4c1d23f07cfadJarkko Pöyry case 24: return tcu::TextureFormat(tcu::TextureFormat::S, tcu::TextureFormat::UNSIGNED_INT24); 1103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case 32: return tcu::TextureFormat(tcu::TextureFormat::S, tcu::TextureFormat::UNSIGNED_INT32); 1113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry default: 1123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TCU_FAIL("Can't map depth buffer format"); 1133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // anonymous. 1173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1183c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass DepthStencilClearCase : public TestCase 1193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1203c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 1213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DepthStencilClearCase (Context& context, const char* name, const char* description, int numIters, int numClears, bool depth, bool stencil, bool scissor, bool masked); 1223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ~DepthStencilClearCase (void); 1233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void init (void); 1253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void deinit (void); 1263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry IterateResult iterate (void); 1283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1293c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate: 1303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void generateClears (vector<Clear>& dst, deUint32 seed); 1313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void renderGL (tcu::Surface& dst, const vector<Clear>& clears); 1323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void renderReference (tcu::Surface& dst, const vector<Clear>& clears); 1333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool m_testDepth; 1353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool m_testStencil; 1363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool m_testScissor; 1373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool m_masked; 1383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int m_numIters; 1393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int m_numClears; 1403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int m_curIter; 1413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::ShaderProgram* m_visProgram; 1433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 1443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1453c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDepthStencilClearCase::DepthStencilClearCase (Context& context, const char* name, const char* description, int numIters, int numClears, bool depth, bool stencil, bool scissor, bool masked) 1463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : TestCase (context, name, description) 1473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_testDepth (depth) 1483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_testStencil (stencil) 1493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_testScissor (scissor) 1503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_masked (masked) 1513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_numIters (numIters) 1523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_numClears (numClears) 1533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_curIter (0) 1543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_visProgram (DE_NULL) 1553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1583c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDepthStencilClearCase::~DepthStencilClearCase (void) 1593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DepthStencilClearCase::deinit(); 1613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1633c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid DepthStencilClearCase::init (void) 1643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TestLog& log = m_testCtx.getLog(); 1663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_visProgram = new glu::ShaderProgram(m_context.getRenderContext(), glu::makeVtxFragSources( 1683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Vertex shader. 1693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "#version 300 es\n" 1703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "in highp vec4 a_position;\n" 1713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "void main (void)\n" 1723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "{\n" 1733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry " gl_Position = a_position;\n" 1743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "}\n", 1753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Fragment shader. 1773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "#version 300 es\n" 1783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "uniform mediump vec4 u_color;\n" 1793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "layout(location = 0) out mediump vec4 o_color;\n" 1803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "void main (void)\n" 1813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "{\n" 1823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry " o_color = u_color;\n" 1833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry "}\n")); 1843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (!m_visProgram->isOk()) 1863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry log << *m_visProgram; 1883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry delete m_visProgram; 1893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_visProgram = DE_NULL; 1903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TCU_FAIL("Compile failed"); 1913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass"); 1943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 1953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1963c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid DepthStencilClearCase::deinit (void) 1973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry delete m_visProgram; 1993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_visProgram = DE_NULL; 2003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 2013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2023c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDepthStencilClearCase::IterateResult DepthStencilClearCase::iterate (void) 2033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::RenderTarget& renderTarget = m_context.getRenderTarget(); 2053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int width = renderTarget.getWidth(); 2063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int height = renderTarget.getHeight(); 2073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Surface result (width, height); 2083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::Surface reference (width, height); 2093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::RGBA threshold = renderTarget.getPixelFormat().getColorThreshold() + tcu::RGBA(1,1,1,1); 2103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry vector<Clear> clears; 2113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if ((m_testDepth && renderTarget.getDepthBits() == 0) || 2133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry (m_testStencil && renderTarget.getStencilBits() == 0)) 2143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry throw tcu::NotSupportedError("No depth/stencil buffers", "", __FILE__, __LINE__); 2153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry generateClears(clears, deStringHash(getName())^deInt32Hash(m_curIter)); 2173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry renderGL(result, clears); 2183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry renderReference(reference, clears); 2193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool isLastIter = m_curIter+1 == m_numIters; 2213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool isOk = tcu::pixelThresholdCompare(m_testCtx.getLog(), "Result", "Image comparison result", reference, result, threshold, isLastIter ? tcu::COMPARE_LOG_RESULT : tcu::COMPARE_LOG_ON_ERROR); 2223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (!isOk) 2243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Image comparison failed"); 2253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_curIter += 1; 2273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return isLastIter || !isOk ? STOP : CONTINUE; 2283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 2293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2303c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid DepthStencilClearCase::generateClears (vector<Clear>& clears, deUint32 seed) 2313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::RenderTarget& renderTarget = m_context.getRenderContext().getRenderTarget(); 2333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int width = renderTarget.getWidth(); 2343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int height = renderTarget.getHeight(); 2353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry de::Random rnd (seed); 2363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry clears.resize(m_numClears); 2383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (vector<Clear>::iterator clear = clears.begin(); clear != clears.end(); clear++) 2403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_testScissor) 2423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int w = rnd.getInt(1, width); 2443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int h = rnd.getInt(1, height); 2453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int x = rnd.getInt(0, width-w); 2463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int y = rnd.getInt(0, height-h); 2473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry clear->useScissor = true; // \todo [pyry] Should we randomize? 2493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry clear->scissor = tcu::IVec4(x, y, w, h); 2503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 2523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry clear->useScissor = false; 2533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry clear->clearDepth = rnd.getFloat(-0.2f, 1.2f); 2553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry clear->clearStencil = rnd.getUint32(); 2563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry clear->depthMask = m_masked ? rnd.getBool() : true; 2583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry clear->stencilMask = m_masked ? rnd.getUint32() : 0xffffffffu; 2593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_testDepth && m_testStencil) 2613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry switch (rnd.getInt(0, 2)) 2633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case 0: clear->clearMask = GL_DEPTH_BUFFER_BIT; break; 2653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case 1: clear->clearMask = GL_STENCIL_BUFFER_BIT; break; 2663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case 2: clear->clearMask = GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT; break; 2673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else if (m_testDepth) 2703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry clear->clearMask = GL_DEPTH_BUFFER_BIT; 2713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else 2723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(m_testStencil); 2743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry clear->clearMask = GL_STENCIL_BUFFER_BIT; 2753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 2783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2793c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid DepthStencilClearCase::renderGL (tcu::Surface& dst, const vector<Clear>& clears) 2803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const glw::Functions& gl = m_context.getRenderContext().getFunctions(); 2823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int colorLoc = gl.getUniformLocation(m_visProgram->getProgram(), "u_color"); 2833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int positionLoc = gl.getAttribLocation(m_visProgram->getProgram(), "a_position"); 2843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry static const deUint8 indices[] = { 0, 1, 2, 2, 1, 3 }; 2853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Clear with default values. 2873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.clearDepthf (1.0f); 2883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.clearStencil (0); 2893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.clearColor (1.0f, 0.0f, 0.0f, 1.0f); 2903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.clear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); 2913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(gl.getError(), "Before clears"); 2933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (vector<Clear>::const_iterator clear = clears.begin(); clear != clears.end(); clear++) 2953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (clear->useScissor) 2973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.enable(GL_SCISSOR_TEST); 2993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.scissor(clear->scissor.x(), clear->scissor.y(), clear->scissor.z(), clear->scissor.w()); 3003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 3013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Clear values. 3033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.clearDepthf (clear->clearDepth); 3043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.clearStencil (clear->clearStencil); 3053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Masks. 3073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.depthMask (clear->depthMask ? GL_TRUE : GL_FALSE); 3083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.stencilMask (clear->stencilMask); 3093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Execute clear. 3113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.clear (clear->clearMask); 3123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (clear->useScissor) 3143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.disable(GL_SCISSOR_TEST); 3153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 3163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Restore default masks. 3183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.depthMask (GL_TRUE); 3193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.stencilMask (0xffffffffu); 3203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(gl.getError(), "After clears"); 3223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.useProgram (m_visProgram->getProgram()); 3243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.enableVertexAttribArray (positionLoc); 3253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Visualize depth / stencil buffers. 3273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_testDepth) 3283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 3293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int numSteps = DEPTH_STEPS; 3306ba9faf025982c9eeab3f469a1581a047f20465aJarkko Pöyry float step = 2.0f / (float)numSteps; 3313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.enable (GL_DEPTH_TEST); 3333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.depthFunc(GL_LESS); 3343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.depthMask(GL_FALSE); 3353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.colorMask(GL_FALSE, GL_FALSE, GL_TRUE, GL_FALSE); 3363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int ndx = 0; ndx < numSteps; ndx++) 3383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 3396ba9faf025982c9eeab3f469a1581a047f20465aJarkko Pöyry float d = -1.0f + step*(float)ndx; 3403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry float c = (float)ndx / (float)(numSteps-1); 3413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry float pos[] = 3423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 3433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry -1.0f, -1.0f, d, 3443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry -1.0f, 1.0f, d, 3453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1.0f, -1.0f, d, 3463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1.0f, 1.0f, d 3473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 3483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.uniform4f (colorLoc, 0.0f, 0.0f, c, 1.0f); 3503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.vertexAttribPointer (positionLoc, 3, GL_FLOAT, GL_FALSE, 0, &pos[0]); 3513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.drawElements (GL_TRIANGLES, DE_LENGTH_OF_ARRAY(indices), GL_UNSIGNED_BYTE, &indices[0]); 3523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 3533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.disable (GL_DEPTH_TEST); 3553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.depthMask(GL_TRUE); 3563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(gl.getError(), "After depth visualization"); 3583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 3593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_testStencil) 3613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 3623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int numSteps = STENCIL_STEPS; 3633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int numValues = (1 << TestCase::m_context.getRenderContext().getRenderTarget().getStencilBits()); // 2^bits 3643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int step = numValues / numSteps; 3653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.enable (GL_STENCIL_TEST); 3673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.stencilOp (GL_KEEP, GL_KEEP, GL_KEEP); 3683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.colorMask (GL_FALSE, GL_TRUE, GL_FALSE, GL_FALSE); 3693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry static const float pos[] = 3713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 3723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry -1.0f, -1.0f, 3733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry -1.0f, 1.0f, 3743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1.0f, -1.0f, 3753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1.0f, 1.0f 3763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 3773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.vertexAttribPointer(positionLoc, 2, GL_FLOAT, GL_FALSE, 0, &pos[0]); 3783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int ndx = 0; ndx < numSteps; ndx++) 3803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 3813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int s = step*ndx; 3823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry float c = (float)ndx / (float)(numSteps-1); 3833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.stencilFunc (GL_LEQUAL, s, 0xffu); 3853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.uniform4f (colorLoc, 0.0f, c, 0.0f, 1.0f); 3863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.drawElements (GL_TRIANGLES, DE_LENGTH_OF_ARRAY(indices), GL_UNSIGNED_BYTE, &indices[0]); 3873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 3883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.disable(GL_STENCIL_TEST); 3903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GLU_EXPECT_NO_ERROR(gl.getError(), "After stencil visualization"); 3923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 3933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Restore color mask (changed by visualization). 3953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gl.colorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 3963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::readPixels(m_context.getRenderContext(), 0, 0, dst.getAccess()); 3983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 3993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4003c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid DepthStencilClearCase::renderReference (tcu::Surface& dst, const vector<Clear>& clears) 4013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 4023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::RenderContext& renderCtx = TestCase::m_context.getRenderContext(); 4033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::RenderTarget& renderTarget = renderCtx.getRenderTarget(); 4043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Clear surface to red. 406c215aaa83047ebbaabafef7acd71275a256da6abDejan Mircevski tcu::clear(dst.getAccess(), tcu::RGBA::red().toVec()); 4073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_testDepth) 4093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 4103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Simulated depth buffer span. 4113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::TextureLevel depthBufRow (getDepthFormat(renderTarget.getDepthBits()), dst.getWidth(), 1, 1); 4123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::PixelBufferAccess rowAccess = depthBufRow.getAccess(); 4133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int y = 0; y < dst.getHeight(); y++) 4153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 4163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Clear to default value. 4173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int x = 0; x < rowAccess.getWidth(); x++) 4183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry rowAccess.setPixel(Vec4(1.0f), x, 0); 4193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Execute clears. 4213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (vector<Clear>::const_iterator clear = clears.begin(); clear != clears.end(); clear++) 4223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 4233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Clear / mask test. 4243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if ((clear->clearMask & GL_DEPTH_BUFFER_BIT) == 0 || !clear->depthMask) 4253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry continue; 4263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::IVec4 clearRect = clear->useScissor ? clear->scissor : tcu::IVec4(0, 0, dst.getWidth(), dst.getHeight()); 4283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Intersection test. 4303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (!de::inBounds(y, clearRect.y(), clearRect.y()+clearRect.w())) 4313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry continue; 4323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int x = clearRect.x(); x < clearRect.x()+clearRect.z(); x++) 43409037a4653649d707449463dfe9817a78ccf7d2fJarkko Pöyry rowAccess.setPixDepth(de::clamp(clear->clearDepth, 0.0f, 1.0f), x, 0); 4353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 4363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Map to colors. 4383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int x = 0; x < dst.getWidth(); x++) 4393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 44009037a4653649d707449463dfe9817a78ccf7d2fJarkko Pöyry float depth = rowAccess.getPixDepth(x, 0); 4413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry float step = deFloatFloor(depth * (float)DEPTH_STEPS) / (float)(DEPTH_STEPS-1); 4423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::RGBA oldColor = dst.getPixel(x, y); 4433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::RGBA newColor = tcu::RGBA(oldColor.getRed(), oldColor.getGreen(), deClamp32(deRoundFloatToInt32(step * 255.0f), 0, 255), oldColor.getAlpha()); 4443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry dst.setPixel(x, y, newColor); 4463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 4473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 4483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 4493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (m_testStencil) 4513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 4523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Simulated stencil buffer span. 4533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int stencilBits = renderTarget.getStencilBits(); 4543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::TextureLevel depthBufRow (getStencilFormat(stencilBits), dst.getWidth(), 1, 1); 4553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::PixelBufferAccess rowAccess = depthBufRow.getAccess(); 4563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 bufMask = (1u<<stencilBits)-1; 4573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int y = 0; y < dst.getHeight(); y++) 4593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 4603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Clear to default value. 4613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int x = 0; x < rowAccess.getWidth(); x++) 4623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry rowAccess.setPixel(tcu::UVec4(0), x, 0); 4633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Execute clears. 4653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (vector<Clear>::const_iterator clear = clears.begin(); clear != clears.end(); clear++) 4663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 4673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Clear / mask test. 4683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if ((clear->clearMask & GL_STENCIL_BUFFER_BIT) == 0 || clear->stencilMask == 0) 4693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry continue; 4703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::IVec4 clearRect = clear->useScissor ? clear->scissor : tcu::IVec4(0, 0, dst.getWidth(), dst.getHeight()); 4723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Intersection test. 4743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (!de::inBounds(y, clearRect.y(), clearRect.y()+clearRect.w())) 4753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry continue; 4763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int x = clearRect.x(); x < clearRect.x()+clearRect.z(); x++) 4783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 47909037a4653649d707449463dfe9817a78ccf7d2fJarkko Pöyry deUint32 oldVal = rowAccess.getPixStencil(x, 0); 4803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 newVal = ((oldVal & ~clear->stencilMask) | (clear->clearStencil & clear->stencilMask)) & bufMask; 48109037a4653649d707449463dfe9817a78ccf7d2fJarkko Pöyry rowAccess.setPixStencil(newVal, x, 0); 4823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 4833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 4843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Map to colors. 4863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int x = 0; x < dst.getWidth(); x++) 4873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 48809037a4653649d707449463dfe9817a78ccf7d2fJarkko Pöyry deUint32 stencil = rowAccess.getPixStencil(x, 0); 4893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry float step = (float)(stencil / ((1u<<stencilBits) / (deUint32)STENCIL_STEPS)) / (float)(STENCIL_STEPS-1); 4903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::RGBA oldColor = dst.getPixel(x, y); 4913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::RGBA newColor = tcu::RGBA(oldColor.getRed(), deClamp32(deRoundFloatToInt32(step * 255.0f), 0, 255), oldColor.getBlue(), oldColor.getAlpha()); 4923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry dst.setPixel(x, y, newColor); 4943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 4953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 4963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 4973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 4983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 4993c827367444ee418f129b2c238299f49d3264554Jarkko PoyryDepthStencilClearTests::DepthStencilClearTests (Context& context) 5003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : TestCaseGroup(context, "depth_stencil_clear", "Depth and stencil clear tests") 5013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 5023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 5033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5043c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid DepthStencilClearTests::init (void) 5053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 5063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // iters clears depth stencil scissor masked 5073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addChild(new DepthStencilClearCase(m_context, "depth", "", 4, 2, true, false, false, false)); 5083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addChild(new DepthStencilClearCase(m_context, "depth_scissored", "", 4, 16, true, false, true, false)); 5093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addChild(new DepthStencilClearCase(m_context, "depth_scissored_masked", "", 4, 16, true, false, true, true)); 5103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addChild(new DepthStencilClearCase(m_context, "stencil", "", 4, 2, false, true, false, false)); 5123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addChild(new DepthStencilClearCase(m_context, "stencil_masked", "", 4, 8, false, true, false, true)); 5133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addChild(new DepthStencilClearCase(m_context, "stencil_scissored", "", 4, 16, false, true, true, false)); 5143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addChild(new DepthStencilClearCase(m_context, "stencil_scissored_masked", "", 4, 16, false, true, true, true)); 5153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addChild(new DepthStencilClearCase(m_context, "depth_stencil", "", 4, 2, true, true, false, false)); 5173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addChild(new DepthStencilClearCase(m_context, "depth_stencil_masked", "", 4, 8, true, true, false, true)); 5183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addChild(new DepthStencilClearCase(m_context, "depth_stencil_scissored", "", 4, 16, true, true, true, false)); 5193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addChild(new DepthStencilClearCase(m_context, "depth_stencil_scissored_masked", "", 4, 16, true, true, true, true)); 5203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 5213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 5223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // Functional 5233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // gles3 5243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // deqp 525