src/third_party/angle/src/tests/gl_tests/DiscardFramebufferEXTTest.cpp
// ANGLE implements an optimization that if depth stencil buffer has not been used and not stored in
// the renderpass, the depth buffer clear will be dropped.
ANGLE implements an optimization that if depth stencil buffer has not been used and not stored in
the renderpass, the depth buffer clear will be dropped.
ANGLE implements an optimization that if depth stencil buffer has not been used and not stored in the renderpass the depth buffer clear will be dropped .
TEST_P(DiscardFramebufferEXTTest, ClearDepthThenDrawWithoutDepthTestThenDiscard)
{
    ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_discard_framebuffer"));
    ANGLE_SKIP_TEST_IF(IsD3D11());
    ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Passthrough(), essl1_shaders::fs::UniformColor());
    glUseProgram(program);
    GLint colorUniformLocation =
        glGetUniformLocation(program, angle::essl1_shaders::ColorUniform());
    ASSERT_NE(-1, colorUniformLocation);
    ASSERT_GL_NO_ERROR();
    constexpr GLfloat kDepthClearValue = 0.5f;
    constexpr GLfloat depthDrawValue = kDepthClearValue * 2.0f - 1.0f;
    glBindFramebuffer(GL_FRAMEBUFFER, 0);
    glEnable(GL_DEPTH_TEST);
    glClearDepthf(kDepthClearValue);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glDisable(GL_DEPTH_TEST);
    glUniform4fv(colorUniformLocation, 1, GLColor::cyan.toNormalizedVector().data());
    glViewport(0, 0, getWindowWidth(), getWindowHeight());
    drawQuad(program, essl1_shaders::PositionAttrib(), depthDrawValue + 0.05f);
    GLenum discards = GL_DEPTH_EXT;
    glDiscardFramebufferEXT(GL_FRAMEBUFFER, 1, &discards);
    ASSERT_GL_NO_ERROR();
    EXPECT_PIXEL_COLOR_EQ(1, 1, GLColor::cyan);
}
TEST_P ( DiscardFramebufferEXTTest , ClearDepthThenDrawWithoutDepthTestThenDiscard ) { ANGLE_SKIP_TEST_IF ( ! IsGLExtensionEnabled ( " " ) ) ; ANGLE_SKIP_TEST_IF ( IsD3D11 ( ) ) ; ANGLE_GL_PROGRAM ( program , essl1_shaders :: vs :: Passthrough ( ) , essl1_shaders :: fs :: UniformColor ( ) ) ; glUseProgram ( program ) ; GLint colorUniformLocation = glGetUniformLocation ( program , angle :: essl1_shaders :: ColorUniform ( ) ) ; ASSERT_NE ( -1 , colorUniformLocation ) ; ASSERT_GL_NO_ERROR ( ) ; constexpr GLfloat kDepthClearValue = 0.5f ; constexpr GLfloat depthDrawValue = kDepthClearValue * 2.0f - 1.0f ; glBindFramebuffer ( GL_FRAMEBUFFER , 0 ) ; glEnable ( GL_DEPTH_TEST ) ; glClearDepthf ( kDepthClearValue ) ; glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ) ; glDisable ( GL_DEPTH_TEST ) ; glUniform4fv ( colorUniformLocation , 1 , GLColor :: cyan . toNormalizedVector ( ) . data ( ) ) ; glViewport ( 0 , 0 , getWindowWidth ( ) , getWindowHeight ( ) ) ; drawQuad ( program , essl1_shaders :: PositionAttrib ( ) , depthDrawValue + 0.05f ) ; GLenum discards = GL_DEPTH_EXT ; glDiscardFramebufferEXT ( GL_FRAMEBUFFER , 1 , & discards ) ; ASSERT_GL_NO_ERROR ( ) ; EXPECT_PIXEL_COLOR_EQ ( 1 , 1 , GLColor :: cyan ) ; }
ANGLE implements an optimization that if depth stencil buffer has not been used and not stored in
the renderpass, the depth buffer clear will be dropped.
ANGLE implements an optimization that if depth stencil buffer has not been used and not stored in the renderpass the depth buffer clear will be dropped .
// TODO: fix crash issue. http://anglebug.com/4141 // This depth value equals to kDepthClearValue after viewport transform // This depth clear should be optimized out. We do not have a good way to verify that it // actually gets dropped, but at least we will ensure rendering is still correct.