Add a test for copying from one mip to another

Bug: angleproject:2914
Change-Id: Ib39f8599a613cbb85688c230cf8a72e23d8e1c1c
Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2231618
Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>
Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org>
Reviewed-by: Kenneth Russell <kbr@chromium.org>
This commit is contained in:
Shahbaz Youssefi 2020-06-04 16:14:18 -04:00 коммит произвёл Commit Bot
Родитель 7993f34db4
Коммит 06462adde6
1 изменённых файлов: 115 добавлений и 0 удалений

Просмотреть файл

@ -2778,6 +2778,121 @@ TEST_P(WebGLCompatibilityTest, TextureCopyingFeedbackLoops)
EXPECT_GL_NO_ERROR();
}
// Test that copying from mip 1 of a texture to mip 0 works. When the framebuffer is attached to
// mip 1 of a mip-complete texture, an image with both mips are created. When copying from the
// framebuffer to mip 0, it is being redefined.
TEST_P(WebGL2CompatibilityTest, CopyMip1ToMip0)
{
// http://anglebug.com/4804
ANGLE_SKIP_TEST_IF(IsD3D11());
// http://anglebug.com/4805
ANGLE_SKIP_TEST_IF(IsOpenGL() && IsIntel() && IsWindows());
GLFramebuffer framebuffer;
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
GLTexture texture;
glBindTexture(GL_TEXTURE_2D, texture);
const GLColor mip0[4] = {
GLColor::red,
GLColor::red,
GLColor::red,
GLColor::red,
};
const GLColor mip1[1] = {
GLColor::green,
};
// Create a complete mip chain in mips 0 to 2
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, mip0);
glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, mip1);
// Framebuffer can bind to mip 1, as the texture is mip-complete.
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 1);
EXPECT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER);
// Copy to mip 0. This shouldn't crash.
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, 1, 1, 0);
EXPECT_GL_NO_ERROR();
// The framebuffer is now incomplete.
EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT,
glCheckFramebufferStatus(GL_FRAMEBUFFER));
// http://anglebug.com/4802
ANGLE_SKIP_TEST_IF(IsOpenGL() && IsNVIDIA());
// http://anglebug.com/4803
ANGLE_SKIP_TEST_IF(IsOpenGL() && IsAMD() && IsOSX());
// Bind framebuffer to mip 0 and make sure the copy was done.
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
EXPECT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER);
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
}
// Test that copying from mip 0 of a texture to mip 1 works. When the framebuffer is attached to
// mip 0 of a mip-complete texture, an image with both mips are created. When copying from the
// framebuffer to mip 1, it is being redefined.
TEST_P(WebGL2CompatibilityTest, CopyMip0ToMip1)
{
// http://anglebug.com/4805
ANGLE_SKIP_TEST_IF(IsOpenGL() && IsIntel() && IsWindows());
ANGLE_SKIP_TEST_IF(IsOpenGL() && IsAMD() && IsWindows());
GLFramebuffer framebuffer;
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
GLTexture texture;
glBindTexture(GL_TEXTURE_2D, texture);
const GLColor mip0[4] = {
GLColor::red,
GLColor::red,
GLColor::red,
GLColor::red,
};
const GLColor mip1[1] = {
GLColor::green,
};
// Create a complete mip chain in mips 0 to 2
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, mip0);
glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, mip1);
// Framebuffer can bind to mip 0, as the texture is mip-complete.
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
EXPECT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER);
// Copy to mip 1. This shouldn't crash.
glCopyTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 0, 0, 2, 2, 0);
EXPECT_GL_NO_ERROR();
// The framebuffer is still complete.
EXPECT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER);
// Make sure mip 0 is untouched.
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
EXPECT_PIXEL_COLOR_EQ(1, 1, GLColor::red);
// When reading back the framebuffer, the attached texture is not rebased, so the framebuffer
// still sees the 1x1 mip. The copy is flushed to this mip, which is incorrect.
// http://anglebug.com/4792.
ANGLE_SKIP_TEST_IF(IsVulkan());
// Bind framebuffer to mip 1 and make sure the copy was done.
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 1);
EXPECT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER);
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
EXPECT_PIXEL_COLOR_EQ(1, 1, GLColor::red);
}
void WebGLCompatibilityTest::drawBuffersFeedbackLoop(GLuint program,
const std::array<GLenum, 2> &drawBuffers,
GLenum expectedError)