src/third_party/angle/src/tests/gl_tests/BlitFramebufferANGLETest.cpp
// Test resolving a multisampled stencil buffer with scissor.
Test resolving a multisampled stencil buffer with scissor.
Test resolving a multisampled stencil buffer with scissor .
TEST_P(BlitFramebufferTest, ScissoredMultisampleStencil)
{
    ANGLE_SKIP_TEST_IF(IsAMD() && IsOpenGL() && IsWindows());
    ANGLE_SKIP_TEST_IF((IsIntel() || IsAMD()) && IsOSX());
    constexpr GLuint kSize = 256;
    GLTexture destColorbuf;
    glBindTexture(GL_TEXTURE_2D, destColorbuf.get());
    glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, kSize, kSize);
    GLRenderbuffer destRenderbuf;
    glBindRenderbuffer(GL_RENDERBUFFER, destRenderbuf.get());
    glRenderbufferStorage(GL_RENDERBUFFER, GL_STENCIL_INDEX8, kSize, kSize);
    GLFramebuffer resolved;
    glBindFramebuffer(GL_FRAMEBUFFER, resolved.get());
    glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
                           destColorbuf.get(), 0);
    glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
                              destRenderbuf.get());
    GLColor gray(127, 127, 127, 255);
    glClearStencil(0x10);
    glClearColor(0.499f, 0.499f, 0.499f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
    EXPECT_PIXEL_COLOR_EQ(0, 0, gray);
    EXPECT_PIXEL_COLOR_EQ(kSize / 2, kSize / 2, gray);
    GLRenderbuffer renderbuf;
    glBindRenderbuffer(GL_RENDERBUFFER, renderbuf.get());
    glRenderbufferStorageMultisample(GL_RENDERBUFFER, 2, GL_STENCIL_INDEX8, kSize, kSize);
    ANGLE_GL_PROGRAM(drawRed, essl3_shaders::vs::Simple(), essl3_shaders::fs::Red());
    ANGLE_GL_PROGRAM(drawGreen, essl3_shaders::vs::Simple(), essl3_shaders::fs::Green());
    ANGLE_GL_PROGRAM(drawBlue, essl3_shaders::vs::Simple(), essl3_shaders::fs::Blue());
    GLFramebuffer framebuffer;
    glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
    glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
                              renderbuf.get());
    ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
    glClearStencil(0x1);
    glClear(GL_STENCIL_BUFFER_BIT);
    glEnable(GL_SCISSOR_TEST);
    glEnable(GL_STENCIL_TEST);
    glScissor(kSize / 4, kSize / 4, kSize / 2, kSize / 2);
    glStencilFunc(GL_ALWAYS, 0x2, 0xFF);
    glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
    drawQuad(drawRed.get(), essl3_shaders::PositionAttrib(), 0.5f);
    glBindFramebuffer(GL_DRAW_FRAMEBUFFER, resolved.get());
    glBlitFramebuffer(0, 0, kSize, kSize, 0, 0, kSize, kSize, GL_STENCIL_BUFFER_BIT, GL_NEAREST);
    glBindFramebuffer(GL_FRAMEBUFFER, resolved.get());
    ASSERT_GL_NO_ERROR();
    glDisable(GL_SCISSOR_TEST);
    glStencilMask(0);
    glStencilFunc(GL_EQUAL, 0x1, 0xFF);
    drawQuad(drawBlue.get(), essl3_shaders::PositionAttrib(), 0.5f);
    EXPECT_PIXEL_COLOR_EQ(0, 0, gray);
    EXPECT_PIXEL_COLOR_EQ(kSize - 1, 0, gray);
    EXPECT_PIXEL_COLOR_EQ(0, kSize - 1, gray);
    EXPECT_PIXEL_COLOR_EQ(kSize - 1, kSize - 1, gray);
    EXPECT_PIXEL_COLOR_EQ(kSize / 2, kSize / 2, gray);
    glStencilFunc(GL_EQUAL, 0x2, 0xFF);
    drawQuad(drawRed.get(), essl3_shaders::PositionAttrib(), 0.5f);
    EXPECT_PIXEL_COLOR_EQ(0, 0, gray);
    EXPECT_PIXEL_COLOR_EQ(kSize - 1, 0, gray);
    EXPECT_PIXEL_COLOR_EQ(0, kSize - 1, gray);
    EXPECT_PIXEL_COLOR_EQ(kSize - 1, kSize - 1, gray);
    EXPECT_PIXEL_COLOR_EQ(kSize / 2, kSize / 2, GLColor::red);
    glStencilFunc(GL_EQUAL, 0x10, 0xFF);
    drawQuad(drawGreen.get(), essl3_shaders::PositionAttrib(), 0.5f);
    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 / 2, kSize / 2, GLColor::red);
    ASSERT_GL_NO_ERROR();
}
TEST_P ( BlitFramebufferTest , ScissoredMultisampleStencil ) { ANGLE_SKIP_TEST_IF ( IsAMD ( ) && IsOpenGL ( ) && IsWindows ( ) ) ; ANGLE_SKIP_TEST_IF ( ( IsIntel ( ) || IsAMD ( ) ) && IsOSX ( ) ) ; constexpr GLuint kSize = 256 ; GLTexture destColorbuf ; glBindTexture ( GL_TEXTURE_2D , destColorbuf . get ( ) ) ; glTexStorage2D ( GL_TEXTURE_2D , 1 , GL_RGBA8 , kSize , kSize ) ; GLRenderbuffer destRenderbuf ; glBindRenderbuffer ( GL_RENDERBUFFER , destRenderbuf . get ( ) ) ; glRenderbufferStorage ( GL_RENDERBUFFER , GL_STENCIL_INDEX8 , kSize , kSize ) ; GLFramebuffer resolved ; glBindFramebuffer ( GL_FRAMEBUFFER , resolved . get ( ) ) ; glFramebufferTexture2D ( GL_DRAW_FRAMEBUFFER , GL_COLOR_ATTACHMENT0 , GL_TEXTURE_2D , destColorbuf . get ( ) , 0 ) ; glFramebufferRenderbuffer ( GL_DRAW_FRAMEBUFFER , GL_STENCIL_ATTACHMENT , GL_RENDERBUFFER , destRenderbuf . get ( ) ) ; GLColor gray ( 127 , 127 , 127 , 255 ) ; glClearStencil ( 0x10 ) ; glClearColor ( 0.499f , 0.499f , 0.499f , 1.0f ) ; glClear ( GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT ) ; EXPECT_PIXEL_COLOR_EQ ( 0 , 0 , gray ) ; EXPECT_PIXEL_COLOR_EQ ( kSize / 2 , kSize / 2 , gray ) ; GLRenderbuffer renderbuf ; glBindRenderbuffer ( GL_RENDERBUFFER , renderbuf . get ( ) ) ; glRenderbufferStorageMultisample ( GL_RENDERBUFFER , 2 , GL_STENCIL_INDEX8 , kSize , kSize ) ; ANGLE_GL_PROGRAM ( drawRed , essl3_shaders :: vs :: Simple ( ) , essl3_shaders :: fs :: Red ( ) ) ; ANGLE_GL_PROGRAM ( drawGreen , essl3_shaders :: vs :: Simple ( ) , essl3_shaders :: fs :: Green ( ) ) ; ANGLE_GL_PROGRAM ( drawBlue , essl3_shaders :: vs :: Simple ( ) , essl3_shaders :: fs :: Blue ( ) ) ; GLFramebuffer framebuffer ; glBindFramebuffer ( GL_FRAMEBUFFER , framebuffer . get ( ) ) ; glFramebufferRenderbuffer ( GL_FRAMEBUFFER , GL_STENCIL_ATTACHMENT , GL_RENDERBUFFER , renderbuf . get ( ) ) ; ASSERT_GLENUM_EQ ( GL_FRAMEBUFFER_COMPLETE , glCheckFramebufferStatus ( GL_FRAMEBUFFER ) ) ; glClearStencil ( 0x1 ) ; glClear ( GL_STENCIL_BUFFER_BIT ) ; glEnable ( GL_SCISSOR_TEST ) ; glEnable ( GL_STENCIL_TEST ) ; glScissor ( kSize / 4 , kSize / 4 , kSize / 2 , kSize / 2 ) ; glStencilFunc ( GL_ALWAYS , 0x2 , 0xFF ) ; glStencilOp ( GL_REPLACE , GL_REPLACE , GL_REPLACE ) ; drawQuad ( drawRed . get ( ) , essl3_shaders :: PositionAttrib ( ) , 0.5f ) ; glBindFramebuffer ( GL_DRAW_FRAMEBUFFER , resolved . get ( ) ) ; glBlitFramebuffer ( 0 , 0 , kSize , kSize , 0 , 0 , kSize , kSize , GL_STENCIL_BUFFER_BIT , GL_NEAREST ) ; glBindFramebuffer ( GL_FRAMEBUFFER , resolved . get ( ) ) ; ASSERT_GL_NO_ERROR ( ) ; glDisable ( GL_SCISSOR_TEST ) ; glStencilMask ( 0 ) ; glStencilFunc ( GL_EQUAL , 0x1 , 0xFF ) ; drawQuad ( drawBlue . get ( ) , essl3_shaders :: PositionAttrib ( ) , 0.5f ) ; EXPECT_PIXEL_COLOR_EQ ( 0 , 0 , gray ) ; EXPECT_PIXEL_COLOR_EQ ( kSize - 1 , 0 , gray ) ; EXPECT_PIXEL_COLOR_EQ ( 0 , kSize - 1 , gray ) ; EXPECT_PIXEL_COLOR_EQ ( kSize - 1 , kSize - 1 , gray ) ; EXPECT_PIXEL_COLOR_EQ ( kSize / 2 , kSize / 2 , gray ) ; glStencilFunc ( GL_EQUAL , 0x2 , 0xFF ) ; drawQuad ( drawRed . get ( ) , essl3_shaders :: PositionAttrib ( ) , 0.5f ) ; EXPECT_PIXEL_COLOR_EQ ( 0 , 0 , gray ) ; EXPECT_PIXEL_COLOR_EQ ( kSize - 1 , 0 , gray ) ; EXPECT_PIXEL_COLOR_EQ ( 0 , kSize - 1 , gray ) ; EXPECT_PIXEL_COLOR_EQ ( kSize - 1 , kSize - 1 , gray ) ; EXPECT_PIXEL_COLOR_EQ ( kSize / 2 , kSize / 2 , GLColor :: red ) ; glStencilFunc ( GL_EQUAL , 0x10 , 0xFF ) ; drawQuad ( drawGreen . get ( ) , essl3_shaders :: PositionAttrib ( ) , 0.5f ) ; 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 / 2 , kSize / 2 , GLColor :: red ) ; ASSERT_GL_NO_ERROR ( ) ; }
Test resolving a multisampled stencil buffer with scissor.
Test resolving a multisampled stencil buffer with scissor .
// Incorrect rendering results seen on AMD Windows OpenGL. http://anglebug.com/2486 // Fails verifying that the middle pixel is red. http://anglebug.com/3496 // Create the resolve framebuffer. // Clear the resolved buffer with gray and 0x10 stencil. // Create the multisampled framebuffer. // Fill the stencil buffer with 0x1. // Fill a smaller region of the buffer with 0x2. // Blit into the resolved framebuffer (with scissor still enabled). // Draw blue if the stencil is 0x1, which should never be true. // Draw red if the stencil is 0x2, which should be true in the middle after the blit/resolve. // Draw green if the stencil is 0x10, which should be left untouched in the outer regions.