3 // Use this to select which configurations (e.g. which renderer, which GLES major version) these tests should be run against.
4 typedef ::testing::Types<TFT<Gles::Three, Rend::D3D11>, TFT<Gles::Two, Rend::D3D11>, TFT<Gles::Two, Rend::D3D9>> TestFixtureTypes;
5 TYPED_TEST_CASE(ClearTest, TestFixtureTypes);
7 typedef ::testing::Types<TFT<Gles::Three, Rend::D3D11>> TestFixtureTypesES3;
8 TYPED_TEST_CASE(ClearTestES3, TestFixtureTypesES3);
11 class ClearTestBase : public ANGLETest
14 ClearTestBase() : ANGLETest(T::GetGlesMajorVersion(), T::GetRequestedRenderer())
19 setConfigGreenBits(8);
21 setConfigAlphaBits(8);
22 setConfigDepthBits(24);
29 const std::string vertexShaderSource = SHADER_SOURCE
31 precision highp float;
32 attribute vec4 position;
36 gl_Position = position;
40 const std::string fragmentShaderSource = SHADER_SOURCE
42 precision highp float;
46 gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
50 mProgram = CompileProgram(vertexShaderSource, fragmentShaderSource);
53 FAIL() << "shader compilation failed.";
56 glGenFramebuffers(1, &mFBO);
61 virtual void TearDown()
63 glDeleteProgram(mProgram);
64 glDeleteFramebuffers(1, &mFBO);
66 ANGLETest::TearDown();
74 class ClearTest : public ClearTestBase<T>
78 class ClearTestES3 : public ClearTestBase<T>
81 TYPED_TEST(ClearTest, ClearIssue)
83 glEnable(GL_DEPTH_TEST);
84 glDepthFunc(GL_LEQUAL);
86 glClearColor(0.0, 1.0, 0.0, 1.0);
88 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
92 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
95 glGenRenderbuffers(1, &rbo);
96 glBindRenderbuffer(GL_RENDERBUFFER, rbo);
97 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGB565, 16, 16);
101 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rbo);
103 EXPECT_GL_NO_ERROR();
105 glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
107 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
109 EXPECT_GL_NO_ERROR();
111 glBindFramebuffer(GL_FRAMEBUFFER, 0);
112 glBindBuffer(GL_ARRAY_BUFFER, 0);
114 drawQuad(mProgram, "position", 0.5f);
116 EXPECT_PIXEL_EQ(0, 0, 0, 255, 0, 255);
120 // This tests a bug where in a masked clear when calling "ClearBuffer", we would
121 // mistakenly clear every channel (including the masked-out ones)
122 TYPED_TEST(ClearTestES3, MaskedClearBufferBug)
124 unsigned char pixelData[] = { 255, 255, 255, 255 };
126 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
129 glGenTextures(2, &textures[0]);
131 glBindTexture(GL_TEXTURE_2D, textures[0]);
132 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixelData);
133 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0], 0);
135 glBindTexture(GL_TEXTURE_2D, textures[1]);
136 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixelData);
137 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, textures[1], 0);
139 ASSERT_GL_NO_ERROR();
140 EXPECT_PIXEL_EQ(0, 0, 255, 255, 255, 255);
142 float clearValue[] = { 0, 0.5f, 0.5f, 1.0f };
143 GLenum drawBuffers[] = { GL_NONE, GL_COLOR_ATTACHMENT1 };
144 glDrawBuffers(2, drawBuffers);
145 glColorMask(GL_TRUE, GL_TRUE, GL_FALSE, GL_TRUE);
146 glClearBufferfv(GL_COLOR, 1, clearValue);
148 ASSERT_GL_NO_ERROR();
149 EXPECT_PIXEL_EQ(0, 0, 255, 255, 255, 255);
151 // TODO: glReadBuffer support
152 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, 0, 0);
153 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[1], 0);
154 EXPECT_PIXEL_EQ(0, 0, 0, 127, 255, 255);
156 glDeleteTextures(2, textures);
159 TYPED_TEST(ClearTestES3, BadFBOSerialBug)
161 // First make a simple framebuffer, and clear it to green
162 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
165 glGenTextures(2, &textures[0]);
167 glBindTexture(GL_TEXTURE_2D, textures[0]);
168 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, getWindowWidth(), getWindowHeight());
169 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0], 0);
171 GLenum drawBuffers[] = { GL_COLOR_ATTACHMENT0 };
172 glDrawBuffers(1, drawBuffers);
174 float clearValues1[] = { 0.0f, 1.0f, 0.0f, 1.0f };
175 glClearBufferfv(GL_COLOR, 0, clearValues1);
177 ASSERT_GL_NO_ERROR();
178 EXPECT_PIXEL_EQ(0, 0, 0, 255, 0, 255);
180 // Next make a second framebuffer, and draw it to red
181 // (Triggers bad applied render target serial)
183 glGenFramebuffers(1, &fbo2);
184 ASSERT_GL_NO_ERROR();
186 glBindFramebuffer(GL_FRAMEBUFFER, fbo2);
188 glBindTexture(GL_TEXTURE_2D, textures[1]);
189 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, getWindowWidth(), getWindowHeight());
190 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[1], 0);
192 glDrawBuffers(1, drawBuffers);
194 drawQuad(mProgram, "position", 0.5f);
196 ASSERT_GL_NO_ERROR();
197 EXPECT_PIXEL_EQ(0, 0, 255, 0, 0, 255);
199 // Check that the first framebuffer is still green.
200 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
201 EXPECT_PIXEL_EQ(0, 0, 0, 255, 0, 255);
203 glDeleteTextures(2, textures);
204 glDeleteFramebuffers(1, &fbo2);