src/third_party/angle/src/tests/gl_tests/DiscardFramebufferEXTTest.cpp
// This test is try to ensure that if depth test has been used, depth clear does not get optimized
// out. It also tests that if the depth buffer has not been used, the rendering is still correct.
This test is try to ensure that if depth test has been used, depth clear does not get optimized
out. It also tests that if the depth buffer has not been used, the rendering is still correct.
This test is try to ensure that if depth test has been used depth clear does not get optimized out . It also tests that if the depth buffer has not been used the rendering is still correct .
TEST_P(DiscardFramebufferEXTTest, ClearDepthThenDrawWithDepthTestThenDiscard)
{
    ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_discard_framebuffer"));
    ANGLE_SKIP_TEST_IF(IsVulkan() && IsIntel() && IsWindows());
    GLTexture texture;
    GLRenderbuffer renderbuffer;
    GLFramebuffer framebuffer;
    GLint colorUniformLocation;
    constexpr GLsizei kTexWidth  = 256;
    constexpr GLsizei kTexHeight = 256;
    glBindTexture(GL_TEXTURE_2D, texture);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, kTexWidth, kTexHeight, 0, GL_RGB, GL_UNSIGNED_BYTE,
                 nullptr);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    ASSERT_GL_NO_ERROR();
    glBindTexture(GL_TEXTURE_2D, 0);
    glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer);
    glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, kTexWidth, kTexWidth);
    glBindRenderbuffer(GL_RENDERBUFFER, 0);
    ASSERT_GL_NO_ERROR();
    glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
    glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, renderbuffer);
    ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
    ASSERT_GL_NO_ERROR();
    ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Passthrough(), essl1_shaders::fs::UniformColor());
    glUseProgram(program);
    colorUniformLocation = glGetUniformLocation(program, angle::essl1_shaders::ColorUniform());
    ASSERT_NE(-1, colorUniformLocation);
    ASSERT_GL_NO_ERROR();
    glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
    glClearColor(0.0f, 1.0f, 0.0f, 1.0f);  
    constexpr GLfloat kDepthClearValue = 0.5f;
    constexpr GLfloat depthDrawValue = kDepthClearValue * 2.0f - 1.0f;
    glClearDepthf(kDepthClearValue);
    glEnable(GL_DEPTH_TEST);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glDepthFunc(GL_LESS);
    glDisable(GL_DEPTH_TEST);
    glViewport(0, 0, kTexWidth / 2, kTexHeight / 2);
    glUniform4fv(colorUniformLocation, 1, GLColor::blue.toNormalizedVector().data());
    drawQuad(program, essl1_shaders::PositionAttrib(), depthDrawValue - 0.1f);
    glEnable(GL_DEPTH_TEST);
    glViewport(kTexWidth / 2, 0, kTexWidth / 2, kTexHeight / 2);
    drawQuad(program, essl1_shaders::PositionAttrib(), depthDrawValue - 0.1f);
    glDisable(GL_DEPTH_TEST);
    glViewport(0, kTexHeight / 2, kTexWidth / 2, kTexHeight / 2);
    drawQuad(program, essl1_shaders::PositionAttrib(), depthDrawValue + 0.1f);
    glEnable(GL_DEPTH_TEST);
    glViewport(kTexWidth / 2, kTexHeight / 2, kTexWidth / 2, kTexHeight / 2);
    drawQuad(program, essl1_shaders::PositionAttrib(), depthDrawValue + 0.1f);
    glEnable(GL_DEPTH_TEST);
    glUniform4fv(colorUniformLocation, 1, GLColor::red.toNormalizedVector().data());
    glViewport(0, 0, kTexWidth, kTexHeight);
    drawQuad(program, essl1_shaders::PositionAttrib(), depthDrawValue - 0.05f);
    GLenum discards = GL_DEPTH_ATTACHMENT;
    glDiscardFramebufferEXT(GL_FRAMEBUFFER, 1, &discards);
    ASSERT_GL_NO_ERROR();
    EXPECT_PIXEL_COLOR_EQ(1, 1, GLColor::red);
    EXPECT_PIXEL_COLOR_EQ(kTexWidth / 2 + 1, 1, GLColor::blue);
    EXPECT_PIXEL_COLOR_EQ(1, kTexHeight / 2 + 1, GLColor::red);
    EXPECT_PIXEL_COLOR_EQ(kTexWidth / 2 + 1, kTexHeight / 2 + 1, GLColor::red);
}
TEST_P ( DiscardFramebufferEXTTest , ClearDepthThenDrawWithDepthTestThenDiscard ) { ANGLE_SKIP_TEST_IF ( ! IsGLExtensionEnabled ( " " ) ) ; ANGLE_SKIP_TEST_IF ( IsVulkan ( ) && IsIntel ( ) && IsWindows ( ) ) ; GLTexture texture ; GLRenderbuffer renderbuffer ; GLFramebuffer framebuffer ; GLint colorUniformLocation ; constexpr GLsizei kTexWidth = 256 ; constexpr GLsizei kTexHeight = 256 ; glBindTexture ( GL_TEXTURE_2D , texture ) ; glTexImage2D ( GL_TEXTURE_2D , 0 , GL_RGB , kTexWidth , kTexHeight , 0 , GL_RGB , GL_UNSIGNED_BYTE , nullptr ) ; glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_MAG_FILTER , GL_LINEAR ) ; glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_MIN_FILTER , GL_LINEAR ) ; ASSERT_GL_NO_ERROR ( ) ; glBindTexture ( GL_TEXTURE_2D , 0 ) ; glBindRenderbuffer ( GL_RENDERBUFFER , renderbuffer ) ; glRenderbufferStorage ( GL_RENDERBUFFER , GL_DEPTH_COMPONENT16 , kTexWidth , kTexWidth ) ; glBindRenderbuffer ( GL_RENDERBUFFER , 0 ) ; ASSERT_GL_NO_ERROR ( ) ; glBindFramebuffer ( GL_FRAMEBUFFER , framebuffer ) ; glFramebufferTexture2D ( GL_FRAMEBUFFER , GL_COLOR_ATTACHMENT0 , GL_TEXTURE_2D , texture , 0 ) ; glFramebufferRenderbuffer ( GL_FRAMEBUFFER , GL_DEPTH_ATTACHMENT , GL_RENDERBUFFER , renderbuffer ) ; ASSERT_GLENUM_EQ ( GL_FRAMEBUFFER_COMPLETE , glCheckFramebufferStatus ( GL_FRAMEBUFFER ) ) ; ASSERT_GL_NO_ERROR ( ) ; ANGLE_GL_PROGRAM ( program , essl1_shaders :: vs :: Passthrough ( ) , essl1_shaders :: fs :: UniformColor ( ) ) ; glUseProgram ( program ) ; colorUniformLocation = glGetUniformLocation ( program , angle :: essl1_shaders :: ColorUniform ( ) ) ; ASSERT_NE ( -1 , colorUniformLocation ) ; ASSERT_GL_NO_ERROR ( ) ; glBindFramebuffer ( GL_FRAMEBUFFER , framebuffer ) ; glClearColor ( 0.0f , 1.0f , 0.0f , 1.0f ) ; constexpr GLfloat kDepthClearValue = 0.5f ; constexpr GLfloat depthDrawValue = kDepthClearValue * 2.0f - 1.0f ; glClearDepthf ( kDepthClearValue ) ; glEnable ( GL_DEPTH_TEST ) ; glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ) ; glDepthFunc ( GL_LESS ) ; glDisable ( GL_DEPTH_TEST ) ; glViewport ( 0 , 0 , kTexWidth / 2 , kTexHeight / 2 ) ; glUniform4fv ( colorUniformLocation , 1 , GLColor :: blue . toNormalizedVector ( ) . data ( ) ) ; drawQuad ( program , essl1_shaders :: PositionAttrib ( ) , depthDrawValue - 0.1f ) ; glEnable ( GL_DEPTH_TEST ) ; glViewport ( kTexWidth / 2 , 0 , kTexWidth / 2 , kTexHeight / 2 ) ; drawQuad ( program , essl1_shaders :: PositionAttrib ( ) , depthDrawValue - 0.1f ) ; glDisable ( GL_DEPTH_TEST ) ; glViewport ( 0 , kTexHeight / 2 , kTexWidth / 2 , kTexHeight / 2 ) ; drawQuad ( program , essl1_shaders :: PositionAttrib ( ) , depthDrawValue + 0.1f ) ; glEnable ( GL_DEPTH_TEST ) ; glViewport ( kTexWidth / 2 , kTexHeight / 2 , kTexWidth / 2 , kTexHeight / 2 ) ; drawQuad ( program , essl1_shaders :: PositionAttrib ( ) , depthDrawValue + 0.1f ) ; glEnable ( GL_DEPTH_TEST ) ; glUniform4fv ( colorUniformLocation , 1 , GLColor :: red . toNormalizedVector ( ) . data ( ) ) ; glViewport ( 0 , 0 , kTexWidth , kTexHeight ) ; drawQuad ( program , essl1_shaders :: PositionAttrib ( ) , depthDrawValue - 0.05f ) ; GLenum discards = GL_DEPTH_ATTACHMENT ; glDiscardFramebufferEXT ( GL_FRAMEBUFFER , 1 , & discards ) ; ASSERT_GL_NO_ERROR ( ) ; EXPECT_PIXEL_COLOR_EQ ( 1 , 1 , GLColor :: red ) ; EXPECT_PIXEL_COLOR_EQ ( kTexWidth / 2 + 1 , 1 , GLColor :: blue ) ; EXPECT_PIXEL_COLOR_EQ ( 1 , kTexHeight / 2 + 1 , GLColor :: red ) ; EXPECT_PIXEL_COLOR_EQ ( kTexWidth / 2 + 1 , kTexHeight / 2 + 1 , GLColor :: red ) ; }
This test is try to ensure that if depth test has been used, depth clear does not get optimized
out.
This test is try to ensure that if depth test has been used depth clear does not get optimized out .
// http://anglebug.com/4914 // Draw into FBO0 // clear to green // This depth value equals to kDepthClearValue after viewport transform // Draw bottom left with depth test disabled. DepthValue should remain 0.5f with blue color. // Draw bottom right with depth test enabled. DepthValue should be 0.45f with blue color. // Draw to top left with depth test disabled. DepthValue should remain 0.5f with blue color // Draw to top right with depth test enabled. DepthValue should remain 0.5f with green color // Now draw the full quad with depth test enabled to verify the depth value is expected. // It should fail depth test in bottom right which will keep it with blue color. All other // quarters will pass depth test and draw a red quad. // Invalidate depth buffer. This will trigger depth value not been written to buffer but the // depth load/clear should not optimize out