3 class ClearTest : public ANGLETest
11 setConfigGreenBits(8);
13 setConfigAlphaBits(8);
14 setConfigDepthBits(24);
22 const std::string vertexShaderSource = SHADER_SOURCE
24 precision highp float;
25 attribute vec4 position;
29 gl_Position = position;
33 const std::string fragmentShaderSource = SHADER_SOURCE
35 precision highp float;
39 gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
43 mProgram = CompileProgram(vertexShaderSource, fragmentShaderSource);
46 FAIL() << "shader compilation failed.";
49 glGenFramebuffers(1, &mFBO);
54 virtual void TearDown()
56 glDeleteProgram(mProgram);
57 glDeleteFramebuffers(1, &mFBO);
59 ANGLETest::TearDown();
66 TEST_F(ClearTest, ClearIssue)
68 glEnable(GL_DEPTH_TEST);
69 glDepthFunc(GL_LEQUAL);
71 glClearColor(0.0, 1.0, 0.0, 1.0);
73 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
77 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
80 glGenRenderbuffers(1, &rbo);
81 glBindRenderbuffer(GL_RENDERBUFFER, rbo);
82 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGB565, 16, 16);
86 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rbo);
90 glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
92 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
96 glBindFramebuffer(GL_FRAMEBUFFER, 0);
97 glBindBuffer(GL_ARRAY_BUFFER, 0);
99 drawQuad(mProgram, "position", 0.5f);
101 EXPECT_PIXEL_EQ(0, 0, 0, 255, 0, 255);
105 // This tests a bug where in a masked clear when calling "ClearBuffer", we would
106 // mistakenly clear every channel (including the masked-out ones)
107 TEST_F(ClearTest, MaskedClearBufferBug)
109 unsigned char pixelData[] = { 255, 255, 255, 255 };
111 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
114 glGenTextures(2, &textures[0]);
116 glBindTexture(GL_TEXTURE_2D, textures[0]);
117 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixelData);
118 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0], 0);
120 glBindTexture(GL_TEXTURE_2D, textures[1]);
121 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixelData);
122 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, textures[1], 0);
124 ASSERT_GL_NO_ERROR();
125 EXPECT_PIXEL_EQ(0, 0, 255, 255, 255, 255);
127 float clearValue[] = { 0, 0.5f, 0.5f, 1.0f };
128 GLenum drawBuffers[] = { GL_NONE, GL_COLOR_ATTACHMENT1 };
129 glDrawBuffers(2, drawBuffers);
130 glColorMask(GL_TRUE, GL_TRUE, GL_FALSE, GL_TRUE);
131 glClearBufferfv(GL_COLOR, 1, clearValue);
133 ASSERT_GL_NO_ERROR();
134 EXPECT_PIXEL_EQ(0, 0, 255, 255, 255, 255);
136 // TODO: glReadBuffer support
137 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, 0, 0);
138 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[1], 0);
139 EXPECT_PIXEL_EQ(0, 0, 0, 127, 255, 255);
141 glDeleteTextures(2, textures);
144 TEST_F(ClearTest, BadFBOSerialBug)
146 // First make a simple framebuffer, and clear it to green
147 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
150 glGenTextures(2, &textures[0]);
152 glBindTexture(GL_TEXTURE_2D, textures[0]);
153 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, getWindowWidth(), getWindowHeight());
154 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0], 0);
156 GLenum drawBuffers[] = { GL_COLOR_ATTACHMENT0 };
157 glDrawBuffers(1, drawBuffers);
159 float clearValues1[] = { 0.0f, 1.0f, 0.0f, 1.0f };
160 glClearBufferfv(GL_COLOR, 0, clearValues1);
162 ASSERT_GL_NO_ERROR();
163 EXPECT_PIXEL_EQ(0, 0, 0, 255, 0, 255);
165 // Next make a second framebuffer, and draw it to red
166 // (Triggers bad applied render target serial)
168 glGenFramebuffers(1, &fbo2);
169 ASSERT_GL_NO_ERROR();
171 glBindFramebuffer(GL_FRAMEBUFFER, fbo2);
173 glBindTexture(GL_TEXTURE_2D, textures[1]);
174 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, getWindowWidth(), getWindowHeight());
175 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[1], 0);
177 glDrawBuffers(1, drawBuffers);
179 drawQuad(mProgram, "position", 0.5f);
181 ASSERT_GL_NO_ERROR();
182 EXPECT_PIXEL_EQ(0, 0, 255, 0, 0, 255);
184 // Check that the first framebuffer is still green.
185 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
186 EXPECT_PIXEL_EQ(0, 0, 0, 255, 0, 255);
188 glDeleteTextures(2, textures);
189 glDeleteFramebuffers(1, &fbo2);