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 FBO depthbuffer tests. 223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/ 233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "es3fFboDepthbufferTests.hpp" 253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "es3fFboTestCase.hpp" 263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "es3fFboTestUtil.hpp" 273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluTextureUtil.hpp" 283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuTextureUtil.hpp" 293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "sglrContextUtil.hpp" 303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glwEnums.hpp" 313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 323c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace deqp 333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 343c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace gles3 353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 363c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace Functional 373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 393c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing std::string; 403c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::Vec2; 413c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::Vec3; 423c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::Vec4; 433c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::IVec2; 443c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::IVec3; 453c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::IVec4; 463c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing tcu::UVec4; 473c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing namespace FboTestUtil; 483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 493c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass BasicFboDepthCase : public FboTestCase 503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 513c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry BasicFboDepthCase (Context& context, const char* name, const char* desc, deUint32 format, int width, int height) 533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : FboTestCase (context, name, desc) 543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_format (format) 553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_width (width) 563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_height (height) 573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 603c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprotected: 613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void preCheck (void) 623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry checkFormatSupport(m_format); 643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void render (tcu::Surface& dst) 673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const deUint32 colorFormat = GL_RGBA8; 693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 fbo = 0; 703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 colorRbo = 0; 713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 depthRbo = 0; 723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GradientShader gradShader (glu::TYPE_FLOAT_VEC4); 733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Texture2DShader texShader (DataTypes() << glu::TYPE_SAMPLER_2D, glu::TYPE_FLOAT_VEC4); 743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 gradShaderID = getCurrentContext()->createProgram(&gradShader); 753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 texShaderID = getCurrentContext()->createProgram(&texShader); 763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry float clearDepth = 1.0f; 773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Setup shaders 793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry gradShader.setGradient(*getCurrentContext(), gradShaderID, tcu::Vec4(0.0f), tcu::Vec4(1.0f)); 803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry texShader.setUniforms (*getCurrentContext(), texShaderID); 813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Setup FBO 833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glGenFramebuffers(1, &fbo); 853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glGenRenderbuffers(1, &colorRbo); 863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glGenRenderbuffers(1, &depthRbo); 873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glBindRenderbuffer(GL_RENDERBUFFER, colorRbo); 893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glRenderbufferStorage(GL_RENDERBUFFER, colorFormat, m_width, m_height); 903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glBindRenderbuffer(GL_RENDERBUFFER, depthRbo); 923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glRenderbufferStorage(GL_RENDERBUFFER, m_format, m_width, m_height); 933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glBindFramebuffer(GL_FRAMEBUFFER, fbo); 953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, colorRbo); 963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthRbo); 973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry checkError(); 983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry checkFramebufferStatus(GL_FRAMEBUFFER); 993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glViewport(0, 0, m_width, m_height); 1013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Clear depth to 1 1033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glClearBufferfv(GL_DEPTH, 0, &clearDepth); 1043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Render gradient with depth = [-1..1] 1063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glEnable(GL_DEPTH_TEST); 1073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry sglr::drawQuad(*getCurrentContext(), gradShaderID, Vec3(-1.0f, -1.0f, -1.0f), Vec3(1.0f, 1.0f, 1.0f)); 1083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Render grid pattern with depth = 0 1103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const deUint32 format = GL_RGBA; 1123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const deUint32 dataType = GL_UNSIGNED_BYTE; 1133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int texW = 128; 1143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int texH = 128; 1153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 gridTex = 0; 1163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::TextureLevel data (glu::mapGLTransferFormat(format, dataType), texW, texH, 1); 1173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::fillWithGrid(data.getAccess(), 8, Vec4(0.2f, 0.7f, 0.1f, 1.0f), Vec4(0.7f, 0.1f, 0.5f, 0.8f)); 1193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glGenTextures(1, &gridTex); 1213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glBindTexture(GL_TEXTURE_2D, gridTex); 1223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 1233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 1243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 1253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 1263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glTexImage2D(GL_TEXTURE_2D, 0, format, texW, texH, 0, format, dataType, data.getAccess().getDataPtr()); 1273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry sglr::drawQuad(*getCurrentContext(), texShaderID, Vec3(-1.0f, -1.0f, 0.0f), Vec3(1.0f, 1.0f, 0.0f)); 1293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Read results. 1323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry readPixels(dst, 0, 0, m_width, m_height, glu::mapGLInternalFormat(colorFormat), Vec4(1.0f), Vec4(0.0f)); 1333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1353c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate: 1363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 m_format; 1373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int m_width; 1383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int m_height; 1393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 1403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1413c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass DepthWriteClampCase : public FboTestCase 1423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1433c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 1443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DepthWriteClampCase (Context& context, const char* name, const char* desc, deUint32 format, int width, int height) 1453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : FboTestCase (context, name, desc) 1463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_format (format) 1473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_width (width) 1483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_height (height) 1493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1523c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprotected: 1533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void preCheck (void) 1543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry checkFormatSupport(m_format); 1563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void render (tcu::Surface& dst) 1593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const deUint32 colorFormat = GL_RGBA8; 1613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 fbo = 0; 1623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 colorRbo = 0; 1633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 depthTexture = 0; 1643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::TransferFormat transferFmt = glu::getTransferFormat(glu::mapGLInternalFormat(m_format)); 1653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DepthGradientShader depthGradShader (glu::TYPE_FLOAT_VEC4); 1673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const deUint32 depthGradShaderID = getCurrentContext()->createProgram(&depthGradShader); 1683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const float clearDepth = 1.0f; 1693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::Vec4 red (1.0, 0.0, 0.0, 1.0); 1703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::Vec4 green (0.0, 1.0, 0.0, 1.0); 1713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Setup FBO 1733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glGenFramebuffers(1, &fbo); 1753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glGenRenderbuffers(1, &colorRbo); 1763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glGenTextures(1, &depthTexture); 1773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glBindRenderbuffer(GL_RENDERBUFFER, colorRbo); 1793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glRenderbufferStorage(GL_RENDERBUFFER, colorFormat, m_width, m_height); 1803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glBindTexture(GL_TEXTURE_2D, depthTexture); 1823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glTexImage2D(GL_TEXTURE_2D, 0, m_format, m_width, m_height, 0, transferFmt.format, transferFmt.dataType, DE_NULL); 1833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 1843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 1853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glBindFramebuffer(GL_FRAMEBUFFER, fbo); 1873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, colorRbo); 1883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depthTexture, 0); 1893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry checkError(); 1903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry checkFramebufferStatus(GL_FRAMEBUFFER); 1913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glViewport(0, 0, m_width, m_height); 1933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Clear depth to 1 1953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glClearBufferfv(GL_DEPTH, 0, &clearDepth); 1963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Test that invalid values are not written to the depth buffer 1983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Render green quad, depth gradient = [-1..2] 2003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glEnable(GL_DEPTH_TEST); 2013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glDepthFunc(GL_ALWAYS); 2023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry depthGradShader.setUniforms(*getCurrentContext(), depthGradShaderID, -1.0f, 2.0f, green); 2043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry sglr::drawQuad(*getCurrentContext(), depthGradShaderID, Vec3(-1.0f, -1.0f, -1.0f), Vec3(1.0f, 1.0f, 1.0f)); 2053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glDepthMask(GL_FALSE); 2063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Test if any fragment has greater depth than 1; there should be none 2083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glDepthFunc(GL_LESS); // (1 < depth) ? 2093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry depthGradShader.setUniforms(*getCurrentContext(), depthGradShaderID, 1.0f, 1.0f, red); 2103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry sglr::drawQuad(*getCurrentContext(), depthGradShaderID, Vec3(-1.0f, -1.0f, -1.0f), Vec3(1.0f, 1.0f, 1.0f)); 2113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Test if any fragment has smaller depth than 0; there should be none 2133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glDepthFunc(GL_GREATER); // (0 > depth) ? 2143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry depthGradShader.setUniforms(*getCurrentContext(), depthGradShaderID, 0.0f, 0.0f, red); 2153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry sglr::drawQuad(*getCurrentContext(), depthGradShaderID, Vec3(-1.0f, -1.0f, -1.0f), Vec3(1.0f, 1.0f, 1.0f)); 2163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Read results. 2183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry readPixels(dst, 0, 0, m_width, m_height, glu::mapGLInternalFormat(colorFormat), Vec4(1.0f), Vec4(0.0f)); 2193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2213c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate: 2223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const deUint32 m_format; 2233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int m_width; 2243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int m_height; 2253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 2263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2273c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass DepthTestClampCase : public FboTestCase 2283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2293c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 2303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DepthTestClampCase (Context& context, const char* name, const char* desc, deUint32 format, int width, int height) 2313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : FboTestCase (context, name, desc) 2323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_format (format) 2333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_width (width) 2343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_height (height) 2353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2383c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprotected: 2393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void preCheck (void) 2403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry checkFormatSupport(m_format); 2423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void render (tcu::Surface& dst) 2453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const deUint32 colorFormat = GL_RGBA8; 2473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 fbo = 0; 2483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 colorRbo = 0; 2493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry deUint32 depthTexture = 0; 2503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glu::TransferFormat transferFmt = glu::getTransferFormat(glu::mapGLInternalFormat(m_format)); 2513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DepthGradientShader depthGradShader (glu::TYPE_FLOAT_VEC4); 2533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const deUint32 depthGradShaderID = getCurrentContext()->createProgram(&depthGradShader); 2543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const float clearDepth = 1.0f; 2553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::Vec4 yellow (1.0, 1.0, 0.0, 1.0); 2563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const tcu::Vec4 green (0.0, 1.0, 0.0, 1.0); 2573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Setup FBO 2593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glGenFramebuffers(1, &fbo); 2613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glGenRenderbuffers(1, &colorRbo); 2623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glGenTextures(1, &depthTexture); 2633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glBindRenderbuffer(GL_RENDERBUFFER, colorRbo); 2653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glRenderbufferStorage(GL_RENDERBUFFER, colorFormat, m_width, m_height); 2663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glBindTexture(GL_TEXTURE_2D, depthTexture); 2683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glTexImage2D(GL_TEXTURE_2D, 0, m_format, m_width, m_height, 0, transferFmt.format, transferFmt.dataType, DE_NULL); 2693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 2703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 2713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glBindFramebuffer(GL_FRAMEBUFFER, fbo); 2733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, colorRbo); 2743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depthTexture, 0); 2753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry checkError(); 2763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry checkFramebufferStatus(GL_FRAMEBUFFER); 2773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glViewport(0, 0, m_width, m_height); 2793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Clear depth to 1 2813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glClearBufferfv(GL_DEPTH, 0, &clearDepth); 2823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Test values used in depth test are clamped 2843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Render green quad, depth gradient = [-1..2] 2863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glEnable(GL_DEPTH_TEST); 2873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glDepthFunc(GL_ALWAYS); 2883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry depthGradShader.setUniforms(*getCurrentContext(), depthGradShaderID, -1.0f, 2.0f, green); 2903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry sglr::drawQuad(*getCurrentContext(), depthGradShaderID, Vec3(-1.0f, -1.0f, -1.0f), Vec3(1.0f, 1.0f, 1.0f)); 2913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Render yellow quad, depth gradient = [-0.5..3]. Gradients have equal values only outside [0, 1] range due to clamping 2933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry glDepthFunc(GL_EQUAL); 2943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry depthGradShader.setUniforms(*getCurrentContext(), depthGradShaderID, -0.5f, 3.0f, yellow); 2953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry sglr::drawQuad(*getCurrentContext(), depthGradShaderID, Vec3(-1.0f, -1.0f, -1.0f), Vec3(1.0f, 1.0f, 1.0f)); 2963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Read results. 2983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry readPixels(dst, 0, 0, m_width, m_height, glu::mapGLInternalFormat(colorFormat), Vec4(1.0f), Vec4(0.0f)); 2993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 3003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3013c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate: 3023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const deUint32 m_format; 3033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int m_width; 3043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const int m_height; 3053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 3063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3073c827367444ee418f129b2c238299f49d3264554Jarkko PoyryFboDepthTests::FboDepthTests (Context& context) 3083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : TestCaseGroup(context, "depth", "Depth tests") 3093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 3103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 3113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3123c827367444ee418f129b2c238299f49d3264554Jarkko PoyryFboDepthTests::~FboDepthTests (void) 3133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 3143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 3153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3163c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid FboDepthTests::init (void) 3173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 3183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry static const deUint32 depthFormats[] = 3193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 3203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GL_DEPTH_COMPONENT32F, 3213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GL_DEPTH_COMPONENT24, 3223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GL_DEPTH_COMPONENT16, 3233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GL_DEPTH32F_STENCIL8, 3243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry GL_DEPTH24_STENCIL8 3253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 3263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // .basic 3283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 3293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::TestCaseGroup* basicGroup = new tcu::TestCaseGroup(m_testCtx, "basic", "Basic depth tests"); 3303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addChild(basicGroup); 3313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int fmtNdx = 0; fmtNdx < DE_LENGTH_OF_ARRAY(depthFormats); fmtNdx++) 3333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry basicGroup->addChild(new BasicFboDepthCase(m_context, getFormatName(depthFormats[fmtNdx]), "", depthFormats[fmtNdx], 119, 127)); 3343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 3353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // .depth_write_clamp 3373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 3383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::TestCaseGroup* depthClampGroup = new tcu::TestCaseGroup(m_testCtx, "depth_write_clamp", "Depth write clamping tests"); 3393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addChild(depthClampGroup); 3403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int fmtNdx = 0; fmtNdx < DE_LENGTH_OF_ARRAY(depthFormats); fmtNdx++) 3423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry depthClampGroup->addChild(new DepthWriteClampCase(m_context, getFormatName(depthFormats[fmtNdx]), "", depthFormats[fmtNdx], 119, 127)); 3433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 3443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // .depth_test_clamp 3463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 3473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry tcu::TestCaseGroup* depthClampGroup = new tcu::TestCaseGroup(m_testCtx, "depth_test_clamp", "Depth test value clamping tests"); 3483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addChild(depthClampGroup); 3493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (int fmtNdx = 0; fmtNdx < DE_LENGTH_OF_ARRAY(depthFormats); fmtNdx++) 3513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry depthClampGroup->addChild(new DepthTestClampCase(m_context, getFormatName(depthFormats[fmtNdx]), "", depthFormats[fmtNdx], 119, 127)); 3523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 3533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 3543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // Functional 3563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // gles3 3573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // deqp 358