src/third_party/angle/src/tests/gl_tests/MultisampledRenderToTextureTest.cpp
// Similar to RenderbufferClearDrawCopyThenBlendSameProgram, but with the depth/stencil attachment
// being unresolved only.
Similar to RenderbufferClearDrawCopyThenBlendSameProgram, but with the depth/stencil attachment
being unresolved only.
Similar to RenderbufferClearDrawCopyThenBlendSameProgram but with the depth / stencil attachment being unresolved only .
TEST_P(MultisampledRenderToTextureES3Test,
       RenderbufferClearDrawCopyThenBlendWithDepthStencilSameProgram)
{
    ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_EXT_multisampled_render_to_texture"));
    constexpr GLsizei kSize = 64;
    setupCopyTexProgram();
    GLFramebuffer fboMS;
    glBindFramebuffer(GL_FRAMEBUFFER, fboMS);
    GLTexture color;
    glBindTexture(GL_TEXTURE_2D, color);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
    glFramebufferTexture2DMultisampleEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, color,
                                         0, 4);
    GLRenderbuffer depthStencil;
    glBindRenderbuffer(GL_RENDERBUFFER, depthStencil);
    glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER, 4, GL_DEPTH24_STENCIL8, kSize, kSize);
    glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
                              depthStencil);
    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);
    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);
    glClearColor(0.1f, 0.9f, 0.2f, 0.8f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
    glUniform4f(colorUniformLocation, 1.0f, 0.0f, 0.0f, 1.0f);
    drawQuad(drawColor, essl1_shaders::PositionAttrib(), 1.0f);
    ASSERT_GL_NO_ERROR();
    glDepthFunc(GL_LESS);
    glStencilFunc(GL_EQUAL, 0x55, 0xFF);
    glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
    glEnable(GL_BLEND);
    glBlendFunc(GL_ONE, GL_ONE);
    glUniform4f(colorUniformLocation, 0.0f, 1.0f, 0.0f, 1.0f);
    drawQuad(drawColor, essl1_shaders::PositionAttrib(), 0.95f);
    ASSERT_GL_NO_ERROR();
    GLTexture texture;
    glBindTexture(GL_TEXTURE_2D, texture);
    glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, kSize, kSize, 0);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT);
    glUniform4f(colorUniformLocation, 0.0f, 1.0f, 0.0f, 1.0f);
    drawQuad(drawColor, essl1_shaders::PositionAttrib(), 0.9f);
    ASSERT_GL_NO_ERROR();
    EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::cyan);
    EXPECT_PIXEL_COLOR_EQ(kSize - 1, 0, GLColor::cyan);
    EXPECT_PIXEL_COLOR_EQ(0, kSize - 1, GLColor::cyan);
    EXPECT_PIXEL_COLOR_EQ(kSize - 1, kSize - 1, GLColor::cyan);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
    glDisable(GL_BLEND);
    glDepthFunc(GL_ALWAYS);
    glStencilFunc(GL_ALWAYS, 0x55, 0xFF);
    glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
    glUniform4f(colorUniformLocation, 0.0f, 0.0f, 1.0f, 1.0f);
    drawQuad(drawColor, essl1_shaders::PositionAttrib(), 0.5f);
    EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue);
    EXPECT_PIXEL_COLOR_EQ(kSize - 1, 0, GLColor::blue);
    EXPECT_PIXEL_COLOR_EQ(0, kSize - 1, GLColor::blue);
    EXPECT_PIXEL_COLOR_EQ(kSize - 1, kSize - 1, GLColor::blue);
    ASSERT_GL_NO_ERROR();
    verifyResults(texture, GLColor::yellow, kSize, 0, 0, kSize, kSize);
    ASSERT_GL_NO_ERROR();
}
TEST_P ( MultisampledRenderToTextureES3Test , RenderbufferClearDrawCopyThenBlendWithDepthStencilSameProgram ) { ANGLE_SKIP_TEST_IF ( ! EnsureGLExtensionEnabled ( " " ) ) ; constexpr GLsizei kSize = 64 ; setupCopyTexProgram ( ) ; GLFramebuffer fboMS ; glBindFramebuffer ( GL_FRAMEBUFFER , fboMS ) ; GLTexture color ; glBindTexture ( GL_TEXTURE_2D , color ) ; glTexImage2D ( GL_TEXTURE_2D , 0 , GL_RGBA , kSize , kSize , 0 , GL_RGBA , GL_UNSIGNED_BYTE , nullptr ) ; glFramebufferTexture2DMultisampleEXT ( GL_FRAMEBUFFER , GL_COLOR_ATTACHMENT0 , GL_TEXTURE_2D , color , 0 , 4 ) ; GLRenderbuffer depthStencil ; glBindRenderbuffer ( GL_RENDERBUFFER , depthStencil ) ; glRenderbufferStorageMultisampleEXT ( GL_RENDERBUFFER , 4 , GL_DEPTH24_STENCIL8 , kSize , kSize ) ; glFramebufferRenderbuffer ( GL_FRAMEBUFFER , GL_DEPTH_STENCIL_ATTACHMENT , GL_RENDERBUFFER , depthStencil ) ; 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 ) ; 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 ) ; glClearColor ( 0.1f , 0.9f , 0.2f , 0.8f ) ; glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT ) ; glUniform4f ( colorUniformLocation , 1.0f , 0.0f , 0.0f , 1.0f ) ; drawQuad ( drawColor , essl1_shaders :: PositionAttrib ( ) , 1.0f ) ; ASSERT_GL_NO_ERROR ( ) ; glDepthFunc ( GL_LESS ) ; glStencilFunc ( GL_EQUAL , 0x55 , 0xFF ) ; glStencilOp ( GL_KEEP , GL_KEEP , GL_KEEP ) ; glEnable ( GL_BLEND ) ; glBlendFunc ( GL_ONE , GL_ONE ) ; glUniform4f ( colorUniformLocation , 0.0f , 1.0f , 0.0f , 1.0f ) ; drawQuad ( drawColor , essl1_shaders :: PositionAttrib ( ) , 0.95f ) ; ASSERT_GL_NO_ERROR ( ) ; GLTexture texture ; glBindTexture ( GL_TEXTURE_2D , texture ) ; glCopyTexImage2D ( GL_TEXTURE_2D , 0 , GL_RGBA , 0 , 0 , kSize , kSize , 0 ) ; glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_MIN_FILTER , GL_NEAREST ) ; glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_MAG_FILTER , GL_NEAREST ) ; glClearColor ( 0.0f , 0.0f , 1.0f , 1.0f ) ; glClear ( GL_COLOR_BUFFER_BIT ) ; glUniform4f ( colorUniformLocation , 0.0f , 1.0f , 0.0f , 1.0f ) ; drawQuad ( drawColor , essl1_shaders :: PositionAttrib ( ) , 0.9f ) ; ASSERT_GL_NO_ERROR ( ) ; EXPECT_PIXEL_COLOR_EQ ( 0 , 0 , GLColor :: cyan ) ; EXPECT_PIXEL_COLOR_EQ ( kSize - 1 , 0 , GLColor :: cyan ) ; EXPECT_PIXEL_COLOR_EQ ( 0 , kSize - 1 , GLColor :: cyan ) ; EXPECT_PIXEL_COLOR_EQ ( kSize - 1 , kSize - 1 , GLColor :: cyan ) ; glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT ) ; glDisable ( GL_BLEND ) ; glDepthFunc ( GL_ALWAYS ) ; glStencilFunc ( GL_ALWAYS , 0x55 , 0xFF ) ; glStencilOp ( GL_REPLACE , GL_REPLACE , GL_REPLACE ) ; glUniform4f ( colorUniformLocation , 0.0f , 0.0f , 1.0f , 1.0f ) ; drawQuad ( drawColor , essl1_shaders :: PositionAttrib ( ) , 0.5f ) ; EXPECT_PIXEL_COLOR_EQ ( 0 , 0 , GLColor :: blue ) ; EXPECT_PIXEL_COLOR_EQ ( kSize - 1 , 0 , GLColor :: blue ) ; EXPECT_PIXEL_COLOR_EQ ( 0 , kSize - 1 , GLColor :: blue ) ; EXPECT_PIXEL_COLOR_EQ ( kSize - 1 , kSize - 1 , GLColor :: blue ) ; ASSERT_GL_NO_ERROR ( ) ; verifyResults ( texture , GLColor :: yellow , kSize , 0 , 0 , kSize , kSize ) ; ASSERT_GL_NO_ERROR ( ) ; }
Similar to RenderbufferClearDrawCopyThenBlendSameProgram, but with the depth/stencil attachment
being unresolved only.
Similar to RenderbufferClearDrawCopyThenBlendSameProgram but with the depth / stencil attachment being unresolved only .
// Create multisampled framebuffer to draw into // Draw red into the multisampled color buffer. // Enable write to depth/stencil so the attachment has valid contents, but always pass the test. // Clear the framebuffer. // Then draw into it. // Blend green into it.  This makes sure that the blend after the resolve doesn't have different // state from the one used here.  Additionally, test that the previous draw output the correct // depth/stencil data.  Again, this makes sure that the draw call after the resolve doesn't have // different has depth/stencil test state. // If depth is not set to 1, rendering would fail. // If stencil is not set to 0x55, rendering would fail. // Create a texture and copy into it. // Clear color (but not depth/stencil), and draw again into the framebuffer, this time blending. // Additionally, make sure the depth/stencil data are retained. // Clear color (to blue), but not depth/stencil. // Blend green into the multisampled color buffer. // Verify that the texture is now cyan // Once again, clear and draw so the program is used again in the way it was first used. // For completeness, verify that the texture used as copy target is yellow.