#include "ANGLETest.h"
-class ClearTest : public ANGLETest
+// Use this to select which configurations (e.g. which renderer, which GLES major version) these tests should be run against.
+typedef ::testing::Types<TFT<Gles::Three, Rend::D3D11>, TFT<Gles::Two, Rend::D3D11>, TFT<Gles::Two, Rend::D3D9>> TestFixtureTypes;
+TYPED_TEST_CASE(ClearTest, TestFixtureTypes);
+
+typedef ::testing::Types<TFT<Gles::Three, Rend::D3D11>> TestFixtureTypesES3;
+TYPED_TEST_CASE(ClearTestES3, TestFixtureTypesES3);
+
+template<typename T>
+class ClearTestBase : public ANGLETest
{
-protected:
- ClearTest()
+ protected:
+ ClearTestBase() : ANGLETest(T::GetGlesMajorVersion(), T::GetRequestedRenderer())
{
setWindowWidth(128);
setWindowHeight(128);
}
);
- mProgram = compileProgram(vertexShaderSource, fragmentShaderSource);
+ mProgram = CompileProgram(vertexShaderSource, fragmentShaderSource);
if (mProgram == 0)
{
FAIL() << "shader compilation failed.";
}
+
+ glGenFramebuffers(1, &mFBO);
+
+ ASSERT_GL_NO_ERROR();
}
virtual void TearDown()
{
glDeleteProgram(mProgram);
+ glDeleteFramebuffers(1, &mFBO);
ANGLETest::TearDown();
}
GLuint mProgram;
+ GLuint mFBO;
};
-TEST_F(ClearTest, clear_issue)
-{
- EXPECT_GL_NO_ERROR();
+template <typename T>
+class ClearTest : public ClearTestBase<T>
+{};
+
+template <typename T>
+class ClearTestES3 : public ClearTestBase<T>
+{};
+TYPED_TEST(ClearTest, ClearIssue)
+{
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
EXPECT_GL_NO_ERROR();
- GLuint fbo;
- glGenFramebuffers(1, &fbo);
- glBindFramebuffer(GL_FRAMEBUFFER, fbo);
+ glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
GLuint rbo;
glGenRenderbuffers(1, &rbo);
EXPECT_PIXEL_EQ(0, 0, 0, 255, 0, 255);
}
+
+// Requires ES3
+// This tests a bug where in a masked clear when calling "ClearBuffer", we would
+// mistakenly clear every channel (including the masked-out ones)
+TYPED_TEST(ClearTestES3, MaskedClearBufferBug)
+{
+ unsigned char pixelData[] = { 255, 255, 255, 255 };
+
+ glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
+
+ GLuint textures[2];
+ glGenTextures(2, &textures[0]);
+
+ glBindTexture(GL_TEXTURE_2D, textures[0]);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixelData);
+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0], 0);
+
+ glBindTexture(GL_TEXTURE_2D, textures[1]);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixelData);
+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, textures[1], 0);
+
+ ASSERT_GL_NO_ERROR();
+ EXPECT_PIXEL_EQ(0, 0, 255, 255, 255, 255);
+
+ float clearValue[] = { 0, 0.5f, 0.5f, 1.0f };
+ GLenum drawBuffers[] = { GL_NONE, GL_COLOR_ATTACHMENT1 };
+ glDrawBuffers(2, drawBuffers);
+ glColorMask(GL_TRUE, GL_TRUE, GL_FALSE, GL_TRUE);
+ glClearBufferfv(GL_COLOR, 1, clearValue);
+
+ ASSERT_GL_NO_ERROR();
+ EXPECT_PIXEL_EQ(0, 0, 255, 255, 255, 255);
+
+ // TODO: glReadBuffer support
+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, 0, 0);
+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[1], 0);
+ EXPECT_PIXEL_EQ(0, 0, 0, 127, 255, 255);
+
+ glDeleteTextures(2, textures);
+}
+
+TYPED_TEST(ClearTestES3, BadFBOSerialBug)
+{
+ // First make a simple framebuffer, and clear it to green
+ glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
+
+ GLuint textures[2];
+ glGenTextures(2, &textures[0]);
+
+ glBindTexture(GL_TEXTURE_2D, textures[0]);
+ glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, getWindowWidth(), getWindowHeight());
+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0], 0);
+
+ GLenum drawBuffers[] = { GL_COLOR_ATTACHMENT0 };
+ glDrawBuffers(1, drawBuffers);
+
+ float clearValues1[] = { 0.0f, 1.0f, 0.0f, 1.0f };
+ glClearBufferfv(GL_COLOR, 0, clearValues1);
+
+ ASSERT_GL_NO_ERROR();
+ EXPECT_PIXEL_EQ(0, 0, 0, 255, 0, 255);
+
+ // Next make a second framebuffer, and draw it to red
+ // (Triggers bad applied render target serial)
+ GLuint fbo2;
+ glGenFramebuffers(1, &fbo2);
+ ASSERT_GL_NO_ERROR();
+
+ glBindFramebuffer(GL_FRAMEBUFFER, fbo2);
+
+ glBindTexture(GL_TEXTURE_2D, textures[1]);
+ glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, getWindowWidth(), getWindowHeight());
+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[1], 0);
+
+ glDrawBuffers(1, drawBuffers);
+
+ drawQuad(mProgram, "position", 0.5f);
+
+ ASSERT_GL_NO_ERROR();
+ EXPECT_PIXEL_EQ(0, 0, 255, 0, 0, 255);
+
+ // Check that the first framebuffer is still green.
+ glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
+ EXPECT_PIXEL_EQ(0, 0, 0, 255, 0, 255);
+
+ glDeleteTextures(2, textures);
+ glDeleteFramebuffers(1, &fbo2);
+}