src/third_party/angle/src/tests/gl_tests/MultisampledRenderToTextureTest.cpp
// Draw, then blit depth/stencil with renderbuffers, without a color attachment. Note that this test
// doesn't apply to depth/stencil textures as they are explicitly autoinvalidated between render
// passes.
//
// This test first uses a draw call to fill in the depth/stencil buffer, then blits it to force a
// resolve.  Then it uses a no-op draw call to start a "fullscreen" render pass followed by a
// scissored draw to modify parts of the depth buffer:
//
// +--------------------+
// |     D=1, S=0x55    |
// |                    |
// |     +--------+     |
// |     |  D=0   |     |
// |     | S=0xAA |     |
// |     +--------+     |
// |                    |
// |                    |
// +--------------------+
//
// Blit is used again to copy the depth/stencil attachment data, and the result is verified.
Draw, then blit depth/stencil with renderbuffers, without a color attachment. Note that this test
doesn't apply to depth/stencil textures as they are explicitly autoinvalidated between render
passes.

This test first uses a draw call to fill in the depth/stencil buffer, then blits it to force a
resolve.  Then it uses a no-op draw call to start a "fullscreen" render pass followed by a
scissored draw to modify parts of the depth buffer.



Blit is used again to copy the depth/stencil attachment data, and the result is verified.
Draw then blit depth / stencil with renderbuffers without a color attachment . Note that this test doesn ' t apply to depth / stencil textures as they are explicitly autoinvalidated between render passes . This test first uses a draw call to fill in the depth / stencil buffer then blits it to force a resolve . Then it uses a no - op draw call to start a " fullscreen " render pass followed by a scissored draw to modify parts of the depth buffer . Blit is used again to copy the depth / stencil attachment data and the result is verified .
TEST_P(MultisampledRenderToTextureES3Test, RenderbufferDrawThenBlitDepthStencilOnly)
{
    ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_EXT_multisampled_render_to_texture"));
    ANGLE_SKIP_TEST_IF(IsVulkan() &&
                       (isSwiftshader() || IsAndroid() || IsAMD() || (IsWindows7() && IsNVIDIA())));
    ANGLE_SKIP_TEST_IF(IsLinux() && IsIntel() && IsVulkan());
    ANGLE_SKIP_TEST_IF(IsD3D());
    constexpr GLsizei kSize = 64;
    GLFramebuffer fboMS;
    glBindFramebuffer(GL_FRAMEBUFFER, fboMS);
    GLRenderbuffer depthStencilMS;
    glBindRenderbuffer(GL_RENDERBUFFER, depthStencilMS);
    glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER, 4, GL_DEPTH24_STENCIL8, kSize, kSize);
    glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
                              depthStencilMS);
    ASSERT_GL_NO_ERROR();
    EXPECT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER);
    ANGLE_GL_PROGRAM(drawColor, essl1_shaders::vs::Simple(), essl1_shaders::fs::UniformColor());
    glUseProgram(drawColor);
    GLint colorUniformLocation =
        glGetUniformLocation(drawColor, angle::essl1_shaders::ColorUniform());
    ASSERT_NE(colorUniformLocation, -1);
    glUniform4f(colorUniformLocation, 1.0f, 0.0f, 0.0f, 1.0f);
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_ALWAYS);
    glEnable(GL_STENCIL_TEST);
    glStencilFunc(GL_ALWAYS, 0x55, 0xFF);
    glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
    glStencilMask(0xFF);
     +--------------------+
     |     D=1, S=0x55    |
     |                    |
     |                    |
     |                    |
     |                    |
     |                    |
     |                    |
     |                    |
     +--------------------+
    drawQuad(drawColor, essl1_shaders::PositionAttrib(), 1.0f);
    ASSERT_GL_NO_ERROR();
     Create framebuffer as blit target.
    GLFramebuffer fbo;
    glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo);
    GLRenderbuffer depthStencil;
    glBindRenderbuffer(GL_RENDERBUFFER, depthStencil);
    glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, kSize, kSize);
    glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
                              depthStencil);
    ASSERT_GL_NO_ERROR();
    EXPECT_GL_FRAMEBUFFER_COMPLETE(GL_DRAW_FRAMEBUFFER);
     Blit depth/stencil
    glBlitFramebuffer(0, 0, kSize, kSize, 0, 0, kSize, kSize,
                      GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT, GL_NEAREST);
     Disable depth/stencil and draw again.  Depth/stencil is not modified.
    glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fboMS);
    glDisable(GL_DEPTH_TEST);
    glDisable(GL_STENCIL_TEST);
    drawQuad(drawColor, essl1_shaders::PositionAttrib(), 0.0f);
    ASSERT_GL_NO_ERROR();
     Enable depth/stencil and do a scissored draw.  Depth/stencil is now:
     +--------------------+
     |     D=1, S=0x55    |
     |                    |
     |     +--------+     |
     |     |  D=0   |     |
     |     | S=0xAA |     |
     |     +--------+     |
     |                    |
     |                    |
     +--------------------+
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_STENCIL_TEST);
    glStencilFunc(GL_ALWAYS, 0xAA, 0xFF);
    glEnable(GL_SCISSOR_TEST);
    glScissor(kSize / 4, kSize / 4, kSize / 2, kSize / 2);
    drawQuad(drawColor, essl1_shaders::PositionAttrib(), -1.0f);
    glDisable(GL_SCISSOR_TEST);
    ASSERT_GL_NO_ERROR();
     Blit depth/stencil again.
    glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo);
    glBlitFramebuffer(0, 0, kSize, kSize, 0, 0, kSize, kSize,
                      GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT, GL_NEAREST);
    ASSERT_GL_NO_ERROR();
     Draw into the framebuffer that was the destination of blit, verifying that depth and stencil
     values are correct.
    GLTexture color;
    glBindTexture(GL_TEXTURE_2D, color);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
    glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, color, 0);
    ASSERT_GL_NO_ERROR();
    EXPECT_GL_FRAMEBUFFER_COMPLETE(GL_DRAW_FRAMEBUFFER);
     First, verify the outside border, where D=1 and S=0x55
    glDepthFunc(GL_LESS);
    glStencilFunc(GL_EQUAL, 0x55, 0xFF);
    glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
    glStencilMask(0xFF);
    ASSERT_GL_NO_ERROR();
     Draw green
    glUniform4f(colorUniformLocation, 0.0f, 1.0f, 0.0f, 1.0f);
    drawQuad(drawColor, essl1_shaders::PositionAttrib(), 0.95f);
    ASSERT_GL_NO_ERROR();
     Then, verify the center, where D=0 and S=0xAA
    glDepthFunc(GL_GREATER);
    glStencilFunc(GL_EQUAL, 0xAA, 0xFF);
    glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
    glStencilMask(0xFF);
     Draw blue
    glUniform4f(colorUniformLocation, 0.0f, 0.0f, 1.0f, 1.0f);
    drawQuad(drawColor, essl1_shaders::PositionAttrib(), -0.95f);
    ASSERT_GL_NO_ERROR();
     Verify that the border is now green
    glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo);
    EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
    EXPECT_PIXEL_COLOR_EQ(kSize - 1, 0, GLColor::green);
    EXPECT_PIXEL_COLOR_EQ(0, kSize - 1, GLColor::green);
    EXPECT_PIXEL_COLOR_EQ(kSize - 1, kSize - 1, GLColor::green);
     Verify that the center is now blue
    EXPECT_PIXEL_COLOR_EQ(kSize / 4, kSize / 4, GLColor::blue);
    EXPECT_PIXEL_COLOR_EQ(3 * kSize / 4 - 1, kSize / 4, GLColor::blue);
    EXPECT_PIXEL_COLOR_EQ(kSize / 4, 3 * kSize / 4 - 1, GLColor::blue);
    EXPECT_PIXEL_COLOR_EQ(3 * kSize / 4 - 1, 3 * kSize / 4 - 1, GLColor::blue);
    EXPECT_PIXEL_COLOR_EQ(kSize / 2, kSize / 2, GLColor::blue);
}
TEST_P ( MultisampledRenderToTextureES3Test , RenderbufferDrawThenBlitDepthStencilOnly ) { ANGLE_SKIP_TEST_IF ( ! EnsureGLExtensionEnabled ( " " ) ) ; ANGLE_SKIP_TEST_IF ( IsVulkan ( ) && ( isSwiftshader ( ) || IsAndroid ( ) || IsAMD ( ) || ( IsWindows7 ( ) && IsNVIDIA ( ) ) ) ) ; ANGLE_SKIP_TEST_IF ( IsLinux ( ) && IsIntel ( ) && IsVulkan ( ) ) ; ANGLE_SKIP_TEST_IF ( IsD3D ( ) ) ; constexpr GLsizei kSize = 64 ; GLFramebuffer fboMS ; glBindFramebuffer ( GL_FRAMEBUFFER , fboMS ) ; GLRenderbuffer depthStencilMS ; glBindRenderbuffer ( GL_RENDERBUFFER , depthStencilMS ) ; glRenderbufferStorageMultisampleEXT ( GL_RENDERBUFFER , 4 , GL_DEPTH24_STENCIL8 , kSize , kSize ) ; glFramebufferRenderbuffer ( GL_FRAMEBUFFER , GL_DEPTH_STENCIL_ATTACHMENT , GL_RENDERBUFFER , depthStencilMS ) ; ASSERT_GL_NO_ERROR ( ) ; EXPECT_GL_FRAMEBUFFER_COMPLETE ( GL_FRAMEBUFFER ) ; ANGLE_GL_PROGRAM ( drawColor , essl1_shaders :: vs :: Simple ( ) , essl1_shaders :: fs :: UniformColor ( ) ) ; glUseProgram ( drawColor ) ; GLint colorUniformLocation = glGetUniformLocation ( drawColor , angle :: essl1_shaders :: ColorUniform ( ) ) ; ASSERT_NE ( colorUniformLocation , -1 ) ; glUniform4f ( colorUniformLocation , 1.0f , 0.0f , 0.0f , 1.0f ) ; glEnable ( GL_DEPTH_TEST ) ; glDepthFunc ( GL_ALWAYS ) ; glEnable ( GL_STENCIL_TEST ) ; glStencilFunc ( GL_ALWAYS , 0x55 , 0xFF ) ; glStencilOp ( GL_REPLACE , GL_REPLACE , GL_REPLACE ) ; glStencilMask ( 0xFF ) ; drawQuad ( drawColor , essl1_shaders :: PositionAttrib ( ) , 1.0f ) ; ASSERT_GL_NO_ERROR ( ) ; GLFramebuffer fbo ; glBindFramebuffer ( GL_DRAW_FRAMEBUFFER , fbo ) ; GLRenderbuffer depthStencil ; glBindRenderbuffer ( GL_RENDERBUFFER , depthStencil ) ; glRenderbufferStorage ( GL_RENDERBUFFER , GL_DEPTH24_STENCIL8 , kSize , kSize ) ; glFramebufferRenderbuffer ( GL_DRAW_FRAMEBUFFER , GL_DEPTH_STENCIL_ATTACHMENT , GL_RENDERBUFFER , depthStencil ) ; ASSERT_GL_NO_ERROR ( ) ; EXPECT_GL_FRAMEBUFFER_COMPLETE ( GL_DRAW_FRAMEBUFFER ) ; glBlitFramebuffer ( 0 , 0 , kSize , kSize , 0 , 0 , kSize , kSize , GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT , GL_NEAREST ) ; glBindFramebuffer ( GL_DRAW_FRAMEBUFFER , fboMS ) ; glDisable ( GL_DEPTH_TEST ) ; glDisable ( GL_STENCIL_TEST ) ; drawQuad ( drawColor , essl1_shaders :: PositionAttrib ( ) , 0.0f ) ; ASSERT_GL_NO_ERROR ( ) ; glEnable ( GL_DEPTH_TEST ) ; glEnable ( GL_STENCIL_TEST ) ; glStencilFunc ( GL_ALWAYS , 0xAA , 0xFF ) ; glEnable ( GL_SCISSOR_TEST ) ; glScissor ( kSize / 4 , kSize / 4 , kSize / 2 , kSize / 2 ) ; drawQuad ( drawColor , essl1_shaders :: PositionAttrib ( ) , -1.0f ) ; glDisable ( GL_SCISSOR_TEST ) ; ASSERT_GL_NO_ERROR ( ) ; glBindFramebuffer ( GL_DRAW_FRAMEBUFFER , fbo ) ; glBlitFramebuffer ( 0 , 0 , kSize , kSize , 0 , 0 , kSize , kSize , GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT , GL_NEAREST ) ; ASSERT_GL_NO_ERROR ( ) ; GLTexture color ; glBindTexture ( GL_TEXTURE_2D , color ) ; glTexImage2D ( GL_TEXTURE_2D , 0 , GL_RGBA , kSize , kSize , 0 , GL_RGBA , GL_UNSIGNED_BYTE , nullptr ) ; glFramebufferTexture2D ( GL_DRAW_FRAMEBUFFER , GL_COLOR_ATTACHMENT0 , GL_TEXTURE_2D , color , 0 ) ; ASSERT_GL_NO_ERROR ( ) ; EXPECT_GL_FRAMEBUFFER_COMPLETE ( GL_DRAW_FRAMEBUFFER ) ; glDepthFunc ( GL_LESS ) ; glStencilFunc ( GL_EQUAL , 0x55 , 0xFF ) ; glStencilOp ( GL_KEEP , GL_KEEP , GL_KEEP ) ; glStencilMask ( 0xFF ) ; ASSERT_GL_NO_ERROR ( ) ; glUniform4f ( colorUniformLocation , 0.0f , 1.0f , 0.0f , 1.0f ) ; drawQuad ( drawColor , essl1_shaders :: PositionAttrib ( ) , 0.95f ) ; ASSERT_GL_NO_ERROR ( ) ; glDepthFunc ( GL_GREATER ) ; glStencilFunc ( GL_EQUAL , 0xAA , 0xFF ) ; glStencilOp ( GL_KEEP , GL_KEEP , GL_KEEP ) ; glStencilMask ( 0xFF ) ; glUniform4f ( colorUniformLocation , 0.0f , 0.0f , 1.0f , 1.0f ) ; drawQuad ( drawColor , essl1_shaders :: PositionAttrib ( ) , -0.95f ) ; ASSERT_GL_NO_ERROR ( ) ; glBindFramebuffer ( GL_READ_FRAMEBUFFER , fbo ) ; EXPECT_PIXEL_COLOR_EQ ( 0 , 0 , GLColor :: green ) ; EXPECT_PIXEL_COLOR_EQ ( kSize - 1 , 0 , GLColor :: green ) ; EXPECT_PIXEL_COLOR_EQ ( 0 , kSize - 1 , GLColor :: green ) ; EXPECT_PIXEL_COLOR_EQ ( kSize - 1 , kSize - 1 , GLColor :: green ) ; EXPECT_PIXEL_COLOR_EQ ( kSize / 4 , kSize / 4 , GLColor :: blue ) ; EXPECT_PIXEL_COLOR_EQ ( 3 * kSize / 4 - 1 , kSize / 4 , GLColor :: blue ) ; EXPECT_PIXEL_COLOR_EQ ( kSize / 4 , 3 * kSize / 4 - 1 , GLColor :: blue ) ; EXPECT_PIXEL_COLOR_EQ ( 3 * kSize / 4 - 1 , 3 * kSize / 4 - 1 , GLColor :: blue ) ; EXPECT_PIXEL_COLOR_EQ ( kSize / 2 , kSize / 2 , GLColor :: blue ) ; }
Draw, then blit depth/stencil with renderbuffers, without a color attachment.
Draw then blit depth / stencil with renderbuffers without a color attachment .
// Skip on configurations that don't support VK_KHR_depth_stencil_resolve.  See comment // in RenderbufferClearThenBlitDepthStencil. // http://anglebug.com/5096 // http://anglebug.com/5110 // Create framebuffer to draw into, with depth/stencil attachment only. // Set up program // Output depth/stencil through draw // Draw.  Depth/stencil is now: // // +--------------------+ // |     D=1, S=0x55    | // |                    | // |                    | // |                    | // |                    | // |                    | // |                    | // |                    | // +--------------------+ // Create framebuffer as blit target. // Blit depth/stencil // Disable depth/stencil and draw again.  Depth/stencil is not modified. // Enable depth/stencil and do a scissored draw.  Depth/stencil is now: // // +--------------------+ // |     D=1, S=0x55    | // |                    | // |     +--------+     | // |     |  D=0   |     | // |     | S=0xAA |     | // |     +--------+     | // |                    | // |                    | // +--------------------+ // Blit depth/stencil again. // Draw into the framebuffer that was the destination of blit, verifying that depth and stencil // values are correct. // First, verify the outside border, where D=1 and S=0x55 // Draw green // Then, verify the center, where D=0 and S=0xAA // Draw blue // Verify that the border is now green // Verify that the center is now blue