1 //
2 // Copyright 2015 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6
7 #include "test_utils/ANGLETest.h"
8
9 #include "test_utils/gl_raii.h"
10 #include "util/random_utils.h"
11 #include "util/shader_utils.h"
12 #include "util/test_utils.h"
13
14 using namespace angle;
15
16 namespace
17 {
18 class ClearTestBase : public ANGLETest<>
19 {
20 protected:
ClearTestBase()21 ClearTestBase()
22 {
23 setWindowWidth(128);
24 setWindowHeight(128);
25 setConfigRedBits(8);
26 setConfigGreenBits(8);
27 setConfigBlueBits(8);
28 setConfigAlphaBits(8);
29 setConfigDepthBits(24);
30 setConfigStencilBits(8);
31 }
32
testSetUp()33 void testSetUp() override
34 {
35 mFBOs.resize(2, 0);
36 glGenFramebuffers(2, mFBOs.data());
37
38 ASSERT_GL_NO_ERROR();
39 }
40
testTearDown()41 void testTearDown() override
42 {
43 if (!mFBOs.empty())
44 {
45 glDeleteFramebuffers(static_cast<GLsizei>(mFBOs.size()), mFBOs.data());
46 }
47
48 if (!mTextures.empty())
49 {
50 glDeleteTextures(static_cast<GLsizei>(mTextures.size()), mTextures.data());
51 }
52 }
53
54 std::vector<GLuint> mFBOs;
55 std::vector<GLuint> mTextures;
56 };
57
58 class ClearTest : public ClearTestBase
59 {};
60
61 class ClearTestES3 : public ClearTestBase
62 {
63 protected:
verifyDepth(float depthValue,uint32_t size)64 void verifyDepth(float depthValue, uint32_t size)
65 {
66 // Use a small shader to verify depth.
67 ANGLE_GL_PROGRAM(depthTestProgram, essl1_shaders::vs::Passthrough(),
68 essl1_shaders::fs::Blue());
69 ANGLE_GL_PROGRAM(depthTestProgramFail, essl1_shaders::vs::Passthrough(),
70 essl1_shaders::fs::Red());
71
72 GLboolean hasDepthTest = GL_FALSE;
73 GLboolean hasDepthWrite = GL_TRUE;
74 GLint prevDepthFunc = GL_ALWAYS;
75
76 glGetBooleanv(GL_DEPTH_TEST, &hasDepthTest);
77 glGetBooleanv(GL_DEPTH_WRITEMASK, &hasDepthWrite);
78 glGetIntegerv(GL_DEPTH_FUNC, &prevDepthFunc);
79
80 if (!hasDepthTest)
81 {
82 glEnable(GL_DEPTH_TEST);
83 }
84 if (hasDepthWrite)
85 {
86 glDepthMask(GL_FALSE);
87 }
88 glDepthFunc(GL_LESS);
89 drawQuad(depthTestProgram, essl1_shaders::PositionAttrib(), depthValue * 2 - 1 - 0.01f);
90 drawQuad(depthTestProgramFail, essl1_shaders::PositionAttrib(), depthValue * 2 - 1 + 0.01f);
91 if (!hasDepthTest)
92 {
93 glDisable(GL_DEPTH_TEST);
94 }
95 if (hasDepthWrite)
96 {
97 glDepthMask(GL_TRUE);
98 }
99 glDepthFunc(prevDepthFunc);
100 ASSERT_GL_NO_ERROR();
101
102 EXPECT_PIXEL_COLOR_NEAR(0, 0, GLColor::blue, 1);
103 EXPECT_PIXEL_COLOR_NEAR(size - 1, 0, GLColor::blue, 1);
104 EXPECT_PIXEL_COLOR_NEAR(0, size - 1, GLColor::blue, 1);
105 EXPECT_PIXEL_COLOR_NEAR(size - 1, size - 1, GLColor::blue, 1);
106 }
107
verifyStencil(uint32_t stencilValue,uint32_t size)108 void verifyStencil(uint32_t stencilValue, uint32_t size)
109 {
110 // Use another small shader to verify stencil.
111 ANGLE_GL_PROGRAM(stencilTestProgram, essl1_shaders::vs::Passthrough(),
112 essl1_shaders::fs::Green());
113 GLboolean hasStencilTest = GL_FALSE;
114 GLint prevStencilFunc = GL_ALWAYS;
115 GLint prevStencilValue = 0xFF;
116 GLint prevStencilRef = 0xFF;
117 GLint prevStencilFail = GL_KEEP;
118 GLint prevStencilDepthFail = GL_KEEP;
119 GLint prevStencilDepthPass = GL_KEEP;
120
121 glGetBooleanv(GL_STENCIL_TEST, &hasStencilTest);
122 glGetIntegerv(GL_STENCIL_FUNC, &prevStencilFunc);
123 glGetIntegerv(GL_STENCIL_VALUE_MASK, &prevStencilValue);
124 glGetIntegerv(GL_STENCIL_REF, &prevStencilRef);
125 glGetIntegerv(GL_STENCIL_FAIL, &prevStencilFail);
126 glGetIntegerv(GL_STENCIL_PASS_DEPTH_FAIL, &prevStencilDepthFail);
127 glGetIntegerv(GL_STENCIL_PASS_DEPTH_PASS, &prevStencilDepthPass);
128
129 if (!hasStencilTest)
130 {
131 glEnable(GL_STENCIL_TEST);
132 }
133 glStencilFunc(GL_EQUAL, stencilValue, 0xFF);
134 glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
135 drawQuad(stencilTestProgram, essl1_shaders::PositionAttrib(), 0.0f);
136 if (!hasStencilTest)
137 {
138 glDisable(GL_STENCIL_TEST);
139 }
140 glStencilFunc(prevStencilFunc, prevStencilValue, prevStencilRef);
141 glStencilOp(prevStencilFail, prevStencilDepthFail, prevStencilDepthPass);
142 ASSERT_GL_NO_ERROR();
143
144 EXPECT_PIXEL_COLOR_NEAR(0, 0, GLColor::green, 1);
145 EXPECT_PIXEL_COLOR_NEAR(size - 1, 0, GLColor::green, 1);
146 EXPECT_PIXEL_COLOR_NEAR(0, size - 1, GLColor::green, 1);
147 EXPECT_PIXEL_COLOR_NEAR(size - 1, size - 1, GLColor::green, 1);
148 }
149 };
150
151 class ClearTestES31 : public ClearTestES3
152 {};
153
154 class ClearTestRGB : public ANGLETest<>
155 {
156 protected:
ClearTestRGB()157 ClearTestRGB()
158 {
159 setWindowWidth(128);
160 setWindowHeight(128);
161 setConfigRedBits(8);
162 setConfigGreenBits(8);
163 setConfigBlueBits(8);
164 }
165 };
166
167 class ClearTestRGB_ES3 : public ClearTestRGB
168 {};
169
170 // Each int parameter can have three values: don't clear, clear, or masked clear. The bool
171 // parameter controls scissor.
172 using MaskedScissoredClearVariationsTestParams =
173 std::tuple<angle::PlatformParameters, int, int, int, bool>;
174
ParseMaskedScissoredClearVariationsTestParams(const MaskedScissoredClearVariationsTestParams & params,bool * clearColor,bool * clearDepth,bool * clearStencil,bool * maskColor,bool * maskDepth,bool * maskStencil,bool * scissor)175 void ParseMaskedScissoredClearVariationsTestParams(
176 const MaskedScissoredClearVariationsTestParams ¶ms,
177 bool *clearColor,
178 bool *clearDepth,
179 bool *clearStencil,
180 bool *maskColor,
181 bool *maskDepth,
182 bool *maskStencil,
183 bool *scissor)
184 {
185 int colorClearInfo = std::get<1>(params);
186 int depthClearInfo = std::get<2>(params);
187 int stencilClearInfo = std::get<3>(params);
188
189 *clearColor = colorClearInfo > 0;
190 *clearDepth = depthClearInfo > 0;
191 *clearStencil = stencilClearInfo > 0;
192
193 *maskColor = colorClearInfo > 1;
194 *maskDepth = depthClearInfo > 1;
195 *maskStencil = stencilClearInfo > 1;
196
197 *scissor = std::get<4>(params);
198 }
199
MaskedScissoredClearVariationsTestPrint(const::testing::TestParamInfo<MaskedScissoredClearVariationsTestParams> & paramsInfo)200 std::string MaskedScissoredClearVariationsTestPrint(
201 const ::testing::TestParamInfo<MaskedScissoredClearVariationsTestParams> ¶msInfo)
202 {
203 const MaskedScissoredClearVariationsTestParams ¶ms = paramsInfo.param;
204 std::ostringstream out;
205
206 out << std::get<0>(params);
207
208 bool clearColor, clearDepth, clearStencil;
209 bool maskColor, maskDepth, maskStencil;
210 bool scissor;
211
212 ParseMaskedScissoredClearVariationsTestParams(params, &clearColor, &clearDepth, &clearStencil,
213 &maskColor, &maskDepth, &maskStencil, &scissor);
214
215 if (scissor || clearColor || clearDepth || clearStencil || maskColor || maskDepth ||
216 maskStencil)
217 {
218 out << "_";
219 }
220
221 if (scissor)
222 {
223 out << "_scissored";
224 }
225
226 if (clearColor || clearDepth || clearStencil)
227 {
228 out << "_clear_";
229 if (clearColor)
230 {
231 out << "c";
232 }
233 if (clearDepth)
234 {
235 out << "d";
236 }
237 if (clearStencil)
238 {
239 out << "s";
240 }
241 }
242
243 if (maskColor || maskDepth || maskStencil)
244 {
245 out << "_mask_";
246 if (maskColor)
247 {
248 out << "c";
249 }
250 if (maskDepth)
251 {
252 out << "d";
253 }
254 if (maskStencil)
255 {
256 out << "s";
257 }
258 }
259
260 return out.str();
261 }
262
263 class MaskedScissoredClearTestBase : public ANGLETest<MaskedScissoredClearVariationsTestParams>
264 {
265 protected:
MaskedScissoredClearTestBase()266 MaskedScissoredClearTestBase()
267 {
268 setWindowWidth(128);
269 setWindowHeight(128);
270 setConfigRedBits(8);
271 setConfigGreenBits(8);
272 setConfigBlueBits(8);
273 setConfigAlphaBits(8);
274 setConfigDepthBits(24);
275 setConfigStencilBits(8);
276 }
277
278 void maskedScissoredColorDepthStencilClear(
279 const MaskedScissoredClearVariationsTestParams ¶ms);
280
281 bool mHasDepth = true;
282 bool mHasStencil = true;
283 };
284
285 class MaskedScissoredClearTest : public MaskedScissoredClearTestBase
286 {};
287
288 // Overrides a feature to force emulation of stencil-only and depth-only formats with a packed
289 // depth/stencil format
290 class VulkanClearTest : public MaskedScissoredClearTestBase
291 {
292 protected:
testSetUp()293 void testSetUp() override
294 {
295 glBindTexture(GL_TEXTURE_2D, mColorTexture);
296 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, getWindowWidth(), getWindowHeight(), 0, GL_RGBA,
297 GL_UNSIGNED_BYTE, nullptr);
298
299 // Setup Color/Stencil FBO with a stencil format that's emulated with packed depth/stencil.
300 glBindFramebuffer(GL_FRAMEBUFFER, mColorStencilFBO);
301
302 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mColorTexture,
303 0);
304 glBindRenderbuffer(GL_RENDERBUFFER, mStencilTexture);
305 glRenderbufferStorage(GL_RENDERBUFFER, GL_STENCIL_INDEX8, getWindowWidth(),
306 getWindowHeight());
307 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
308 mStencilTexture);
309
310 ASSERT_GL_NO_ERROR();
311
312 // Note: GL_DEPTH_COMPONENT24 is not allowed in GLES2.
313 if (getClientMajorVersion() >= 3)
314 {
315 // Setup Color/Depth FBO with a depth format that's emulated with packed depth/stencil.
316 glBindFramebuffer(GL_FRAMEBUFFER, mColorDepthFBO);
317
318 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
319 mColorTexture, 0);
320 glBindRenderbuffer(GL_RENDERBUFFER, mDepthTexture);
321 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, getWindowWidth(),
322 getWindowHeight());
323 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER,
324 mDepthTexture);
325 }
326
327 ASSERT_GL_NO_ERROR();
328 }
329
bindColorStencilFBO()330 void bindColorStencilFBO()
331 {
332 glBindFramebuffer(GL_FRAMEBUFFER, mColorStencilFBO);
333 mHasDepth = false;
334 }
335
bindColorDepthFBO()336 void bindColorDepthFBO()
337 {
338 glBindFramebuffer(GL_FRAMEBUFFER, mColorDepthFBO);
339 mHasStencil = false;
340 }
341
342 private:
343 GLFramebuffer mColorStencilFBO;
344 GLFramebuffer mColorDepthFBO;
345 GLTexture mColorTexture;
346 GLRenderbuffer mDepthTexture;
347 GLRenderbuffer mStencilTexture;
348 };
349
350 // Test clearing the default framebuffer
TEST_P(ClearTest,DefaultFramebuffer)351 TEST_P(ClearTest, DefaultFramebuffer)
352 {
353 glClearColor(0.25f, 0.5f, 0.5f, 0.5f);
354 glClear(GL_COLOR_BUFFER_BIT);
355 EXPECT_PIXEL_NEAR(0, 0, 64, 128, 128, 128, 1.0);
356 }
357
358 // Test clearing the default framebuffer with scissor and mask
359 // This forces down path that uses draw to do clear
TEST_P(ClearTest,EmptyScissor)360 TEST_P(ClearTest, EmptyScissor)
361 {
362 // These configs have bug that fails this test.
363 // These configs are unmaintained so skipping.
364 ANGLE_SKIP_TEST_IF(IsIntel() && IsD3D9());
365 ANGLE_SKIP_TEST_IF(IsIntel() && IsMac() && IsOpenGL());
366 glClearColor(0.25f, 0.5f, 0.5f, 1.0f);
367 glClear(GL_COLOR_BUFFER_BIT);
368 glEnable(GL_SCISSOR_TEST);
369 glScissor(-10, 0, 5, 5);
370 glClearColor(0.5f, 0.25f, 0.75f, 0.5f);
371 glColorMask(GL_TRUE, GL_FALSE, GL_TRUE, GL_TRUE);
372 glClear(GL_COLOR_BUFFER_BIT);
373 glDisable(GL_SCISSOR_TEST);
374 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
375 EXPECT_PIXEL_NEAR(0, 0, 64, 128, 128, 255, 1.0);
376 }
377
378 // Test clearing the RGB default framebuffer and verify that the alpha channel is not cleared
TEST_P(ClearTestRGB,DefaultFramebufferRGB)379 TEST_P(ClearTestRGB, DefaultFramebufferRGB)
380 {
381 // Some GPUs don't support RGB format default framebuffer,
382 // so skip if the back buffer has alpha bits.
383 EGLWindow *window = getEGLWindow();
384 EGLDisplay display = window->getDisplay();
385 EGLConfig config = window->getConfig();
386 EGLint backbufferAlphaBits = 0;
387 eglGetConfigAttrib(display, config, EGL_ALPHA_SIZE, &backbufferAlphaBits);
388 ANGLE_SKIP_TEST_IF(backbufferAlphaBits != 0);
389
390 glClearColor(0.25f, 0.5f, 0.5f, 0.5f);
391 glClear(GL_COLOR_BUFFER_BIT);
392 EXPECT_PIXEL_NEAR(0, 0, 64, 128, 128, 255, 1.0);
393 }
394
395 // Invalidate the RGB default framebuffer and verify that the alpha channel is not cleared, and
396 // stays set after drawing.
TEST_P(ClearTestRGB_ES3,InvalidateDefaultFramebufferRGB)397 TEST_P(ClearTestRGB_ES3, InvalidateDefaultFramebufferRGB)
398 {
399 ANGLE_GL_PROGRAM(blueProgram, essl1_shaders::vs::Simple(), essl1_shaders::fs::Blue());
400
401 // Some GPUs don't support RGB format default framebuffer,
402 // so skip if the back buffer has alpha bits.
403 EGLWindow *window = getEGLWindow();
404 EGLDisplay display = window->getDisplay();
405 EGLConfig config = window->getConfig();
406 EGLint backbufferAlphaBits = 0;
407 eglGetConfigAttrib(display, config, EGL_ALPHA_SIZE, &backbufferAlphaBits);
408 ANGLE_SKIP_TEST_IF(backbufferAlphaBits != 0);
409
410 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
411 glClear(GL_COLOR_BUFFER_BIT);
412 // Verify that even though Alpha is cleared to 0.0 for this RGB FBO, it should be read back as
413 // 1.0, since the glReadPixels() is issued with GL_RGBA.
414 // OpenGL ES 3.2 spec:
415 // 16.1.3 Obtaining Pixels from the Framebuffer
416 // If G, B, or A values are not present in the internal format, they are taken to be zero,
417 // zero, and one respectively.
418 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
419
420 const GLenum discards[] = {GL_COLOR};
421 glInvalidateFramebuffer(GL_FRAMEBUFFER, 1, discards);
422
423 // Don't explicitly clear, but draw blue (make sure alpha is not cleared)
424 drawQuad(blueProgram, essl1_shaders::PositionAttrib(), 0.5f);
425 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue);
426 }
427
428 // Draw with a shader that outputs alpha=0.5. Readback and ensure that alpha=1.
TEST_P(ClearTestRGB_ES3,ShaderOutputsAlphaVerifyReadingAlphaIsOne)429 TEST_P(ClearTestRGB_ES3, ShaderOutputsAlphaVerifyReadingAlphaIsOne)
430 {
431 ANGLE_GL_PROGRAM(blueProgram, essl1_shaders::vs::Simple(), essl1_shaders::fs::UniformColor());
432 glUseProgram(blueProgram);
433
434 // Some GPUs don't support RGB format default framebuffer,
435 // so skip if the back buffer has alpha bits.
436 EGLWindow *window = getEGLWindow();
437 EGLDisplay display = window->getDisplay();
438 EGLConfig config = window->getConfig();
439 EGLint backbufferAlphaBits = 0;
440 eglGetConfigAttrib(display, config, EGL_ALPHA_SIZE, &backbufferAlphaBits);
441 ANGLE_SKIP_TEST_IF(backbufferAlphaBits != 0);
442
443 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
444 glClear(GL_COLOR_BUFFER_BIT);
445 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
446
447 GLint colorUniformLocation =
448 glGetUniformLocation(blueProgram, angle::essl1_shaders::ColorUniform());
449 ASSERT_NE(colorUniformLocation, -1);
450 glUniform4f(colorUniformLocation, 0.0f, 0.0f, 1.0f, 0.5f);
451 ASSERT_GL_NO_ERROR();
452
453 // Don't explicitly clear, but draw blue (make sure alpha is not cleared)
454 drawQuad(blueProgram, essl1_shaders::PositionAttrib(), 0.5f);
455 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue);
456 }
457
458 // Test clearing a RGBA8 Framebuffer
TEST_P(ClearTest,RGBA8Framebuffer)459 TEST_P(ClearTest, RGBA8Framebuffer)
460 {
461 glBindFramebuffer(GL_FRAMEBUFFER, mFBOs[0]);
462
463 GLTexture texture;
464
465 glBindTexture(GL_TEXTURE_2D, texture);
466 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, getWindowWidth(), getWindowHeight(), 0, GL_RGBA,
467 GL_UNSIGNED_BYTE, nullptr);
468 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
469
470 glClearColor(0.5f, 0.5f, 0.5f, 0.5f);
471 glClear(GL_COLOR_BUFFER_BIT);
472
473 EXPECT_PIXEL_NEAR(0, 0, 128, 128, 128, 128, 1.0);
474 }
475
476 // Test uploading a texture and then clearing a RGBA8 Framebuffer
TEST_P(ClearTest,TextureUploadAndRGBA8Framebuffer)477 TEST_P(ClearTest, TextureUploadAndRGBA8Framebuffer)
478 {
479 glBindFramebuffer(GL_FRAMEBUFFER, mFBOs[0]);
480
481 GLTexture texture;
482
483 constexpr uint32_t kSize = 16;
484 std::vector<GLColor> pixelData(kSize * kSize, GLColor::blue);
485 glBindTexture(GL_TEXTURE_2D, texture);
486 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
487 pixelData.data());
488 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
489
490 EXPECT_PIXEL_NEAR(0, 0, 0, 0, 255, 255, 1.0);
491
492 glClearColor(0.5f, 0.5f, 0.5f, 0.5f);
493 glClear(GL_COLOR_BUFFER_BIT);
494
495 EXPECT_PIXEL_NEAR(0, 0, 128, 128, 128, 128, 1.0);
496 }
497
498 // Test to validate that we can go from an RGBA framebuffer attachment, to an RGB one and still
499 // have a correct behavior after.
TEST_P(ClearTest,ChangeFramebufferAttachmentFromRGBAtoRGB)500 TEST_P(ClearTest, ChangeFramebufferAttachmentFromRGBAtoRGB)
501 {
502 // http://anglebug.com/2689
503 ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES());
504
505 // http://anglebug.com/5165
506 ANGLE_SKIP_TEST_IF(IsMac() && IsDesktopOpenGL() && IsIntel());
507
508 ANGLE_GL_PROGRAM(program, angle::essl1_shaders::vs::Simple(),
509 angle::essl1_shaders::fs::UniformColor());
510 setupQuadVertexBuffer(0.5f, 1.0f);
511 glUseProgram(program);
512 GLint positionLocation = glGetAttribLocation(program, angle::essl1_shaders::PositionAttrib());
513 ASSERT_NE(positionLocation, -1);
514 glVertexAttribPointer(positionLocation, 3, GL_FLOAT, GL_FALSE, 0, nullptr);
515 glEnableVertexAttribArray(positionLocation);
516
517 GLint colorUniformLocation =
518 glGetUniformLocation(program, angle::essl1_shaders::ColorUniform());
519 ASSERT_NE(colorUniformLocation, -1);
520
521 glUniform4f(colorUniformLocation, 1.0f, 1.0f, 1.0f, 0.5f);
522
523 glBindFramebuffer(GL_FRAMEBUFFER, mFBOs[0]);
524
525 GLTexture texture;
526 glBindTexture(GL_TEXTURE_2D, texture);
527 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, getWindowWidth(), getWindowHeight(), 0, GL_RGBA,
528 GL_UNSIGNED_BYTE, nullptr);
529 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
530
531 // Initially clear to black.
532 glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
533 glClear(GL_COLOR_BUFFER_BIT);
534
535 // Clear with masked color.
536 glColorMask(GL_TRUE, GL_FALSE, GL_TRUE, GL_TRUE);
537 glClearColor(0.5f, 0.5f, 0.5f, 0.75f);
538 glClear(GL_COLOR_BUFFER_BIT);
539 ASSERT_GL_NO_ERROR();
540
541 // So far so good, we have an RGBA framebuffer that we've cleared to 0.5 everywhere.
542 EXPECT_PIXEL_NEAR(0, 0, 128, 0, 128, 192, 1.0);
543
544 // In the Vulkan backend, RGB textures are emulated with an RGBA texture format
545 // underneath and we keep a special mask to know that we shouldn't touch the alpha
546 // channel when we have that emulated texture. This test exists to validate that
547 // this mask gets updated correctly when the framebuffer attachment changes.
548 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, getWindowWidth(), getWindowHeight(), 0, GL_RGB,
549 GL_UNSIGNED_BYTE, nullptr);
550 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
551 ASSERT_GL_NO_ERROR();
552
553 glDrawArrays(GL_TRIANGLES, 0, 6);
554 ASSERT_GL_NO_ERROR();
555
556 EXPECT_PIXEL_RECT_EQ(0, 0, getWindowWidth(), getWindowHeight(), GLColor::magenta);
557 }
558
559 // Test clearing a RGB8 Framebuffer with a color mask.
TEST_P(ClearTest,RGB8WithMaskFramebuffer)560 TEST_P(ClearTest, RGB8WithMaskFramebuffer)
561 {
562 glBindFramebuffer(GL_FRAMEBUFFER, mFBOs[0]);
563
564 GLTexture texture;
565
566 glBindTexture(GL_TEXTURE_2D, texture);
567 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, getWindowWidth(), getWindowHeight(), 0, GL_RGB,
568 GL_UNSIGNED_BYTE, nullptr);
569 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
570
571 glClearColor(0.2f, 0.4f, 0.6f, 0.8f);
572 glClear(GL_COLOR_BUFFER_BIT);
573
574 // Since there's no alpha, we expect to get 255 back instead of the clear value (204).
575 EXPECT_PIXEL_NEAR(0, 0, 51, 102, 153, 255, 1.0);
576
577 glColorMask(GL_TRUE, GL_TRUE, GL_FALSE, GL_TRUE);
578 glClearColor(0.1f, 0.3f, 0.5f, 0.7f);
579 glClear(GL_COLOR_BUFFER_BIT);
580
581 // The blue channel was masked so its value should be unchanged.
582 EXPECT_PIXEL_NEAR(0, 0, 26, 77, 153, 255, 1.0);
583
584 // Restore default.
585 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
586 }
587
TEST_P(ClearTest,ClearIssue)588 TEST_P(ClearTest, ClearIssue)
589 {
590 glEnable(GL_DEPTH_TEST);
591 glDepthFunc(GL_LEQUAL);
592
593 glClearColor(0.0, 1.0, 0.0, 1.0);
594 glClearDepthf(0.0);
595 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
596
597 EXPECT_GL_NO_ERROR();
598
599 glBindFramebuffer(GL_FRAMEBUFFER, mFBOs[0]);
600
601 GLRenderbuffer rbo;
602 glBindRenderbuffer(GL_RENDERBUFFER, rbo);
603 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGB565, 16, 16);
604
605 EXPECT_GL_NO_ERROR();
606
607 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rbo);
608
609 EXPECT_GL_NO_ERROR();
610
611 glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
612 glClearDepthf(1.0f);
613 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
614
615 EXPECT_GL_NO_ERROR();
616
617 glBindFramebuffer(GL_FRAMEBUFFER, 0);
618 glBindBuffer(GL_ARRAY_BUFFER, 0);
619
620 ANGLE_GL_PROGRAM(blueProgram, essl1_shaders::vs::Simple(), essl1_shaders::fs::Blue());
621 drawQuad(blueProgram, essl1_shaders::PositionAttrib(), 0.5f);
622
623 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
624 }
625
626 // Regression test for a bug where "glClearDepthf"'s argument was not clamped
627 // In GLES 2 they where declared as GLclampf and the behaviour is the same in GLES 3.2
TEST_P(ClearTest,ClearIsClamped)628 TEST_P(ClearTest, ClearIsClamped)
629 {
630 glClearDepthf(5.0f);
631
632 GLfloat clear_depth;
633 glGetFloatv(GL_DEPTH_CLEAR_VALUE, &clear_depth);
634 EXPECT_EQ(1.0f, clear_depth);
635 }
636
637 // Regression test for a bug where "glDepthRangef"'s arguments were not clamped
638 // In GLES 2 they where declared as GLclampf and the behaviour is the same in GLES 3.2
TEST_P(ClearTest,DepthRangefIsClamped)639 TEST_P(ClearTest, DepthRangefIsClamped)
640 {
641 glDepthRangef(1.1f, -4.0f);
642
643 GLfloat depth_range[2];
644 glGetFloatv(GL_DEPTH_RANGE, depth_range);
645 EXPECT_EQ(1.0f, depth_range[0]);
646 EXPECT_EQ(0.0f, depth_range[1]);
647 }
648
649 // Test scissored clears on Depth16
TEST_P(ClearTest,Depth16Scissored)650 TEST_P(ClearTest, Depth16Scissored)
651 {
652 GLRenderbuffer renderbuffer;
653 glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer);
654 constexpr int kRenderbufferSize = 64;
655 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, kRenderbufferSize,
656 kRenderbufferSize);
657
658 GLFramebuffer fbo;
659 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
660 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, renderbuffer);
661
662 glClearDepthf(0.0f);
663 glClear(GL_DEPTH_BUFFER_BIT);
664
665 glEnable(GL_SCISSOR_TEST);
666 constexpr int kNumSteps = 13;
667 for (int ndx = 1; ndx < kNumSteps; ndx++)
668 {
669 float perc = static_cast<float>(ndx) / static_cast<float>(kNumSteps);
670 glScissor(0, 0, static_cast<int>(kRenderbufferSize * perc),
671 static_cast<int>(kRenderbufferSize * perc));
672 glClearDepthf(perc);
673 glClear(GL_DEPTH_BUFFER_BIT);
674 }
675 }
676
677 // Test scissored clears on Stencil8
TEST_P(ClearTest,Stencil8Scissored)678 TEST_P(ClearTest, Stencil8Scissored)
679 {
680 GLRenderbuffer renderbuffer;
681 glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer);
682 constexpr int kRenderbufferSize = 64;
683 glRenderbufferStorage(GL_RENDERBUFFER, GL_STENCIL_INDEX8, kRenderbufferSize, kRenderbufferSize);
684
685 GLFramebuffer fbo;
686 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
687 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, renderbuffer);
688
689 glClearStencil(0);
690 glClear(GL_STENCIL_BUFFER_BIT);
691
692 glEnable(GL_SCISSOR_TEST);
693 constexpr int kNumSteps = 13;
694 for (int ndx = 1; ndx < kNumSteps; ndx++)
695 {
696 float perc = static_cast<float>(ndx) / static_cast<float>(kNumSteps);
697 glScissor(0, 0, static_cast<int>(kRenderbufferSize * perc),
698 static_cast<int>(kRenderbufferSize * perc));
699 glClearStencil(static_cast<int>(perc * 255.0f));
700 glClear(GL_STENCIL_BUFFER_BIT);
701 }
702 }
703
704 // Covers a bug in the Vulkan back-end where starting a new command buffer in
705 // the masked clear would not trigger descriptor sets to be re-bound.
TEST_P(ClearTest,MaskedClearThenDrawWithUniform)706 TEST_P(ClearTest, MaskedClearThenDrawWithUniform)
707 {
708 // Initialize a program with a uniform.
709 ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Simple(), essl1_shaders::fs::UniformColor());
710 glUseProgram(program);
711
712 GLint uniLoc = glGetUniformLocation(program, essl1_shaders::ColorUniform());
713 ASSERT_NE(-1, uniLoc);
714 glUniform4f(uniLoc, 0.0f, 1.0f, 0.0f, 1.0f);
715
716 // Initialize position attribute.
717 GLint posLoc = glGetAttribLocation(program, essl1_shaders::PositionAttrib());
718 ASSERT_NE(-1, posLoc);
719 setupQuadVertexBuffer(0.5f, 1.0f);
720 glVertexAttribPointer(posLoc, 3, GL_FLOAT, GL_FALSE, 0, nullptr);
721 glEnableVertexAttribArray(posLoc);
722
723 // Initialize a simple FBO.
724 constexpr GLsizei kSize = 2;
725 GLTexture clearTexture;
726 glBindTexture(GL_TEXTURE_2D, clearTexture);
727 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
728
729 GLFramebuffer fbo;
730 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
731 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, clearTexture, 0);
732
733 glViewport(0, 0, kSize, kSize);
734
735 // Clear and draw to flush out dirty bits.
736 glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
737 glClear(GL_COLOR_BUFFER_BIT);
738
739 glDrawArrays(GL_TRIANGLES, 0, 6);
740
741 // Flush to trigger a new serial.
742 glFlush();
743
744 // Enable color mask and draw again to trigger the bug.
745 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE);
746 glClearColor(1.0f, 0.0f, 0.0f, 0.0f);
747 glClear(GL_COLOR_BUFFER_BIT);
748
749 glDrawArrays(GL_TRIANGLES, 0, 6);
750
751 ASSERT_GL_NO_ERROR();
752 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
753 }
754
755 // Clear with a mask to verify that masked clear is done properly
756 // (can't use inline or RenderOp clear when some color channels are masked)
TEST_P(ClearTestES3,ClearPlusMaskDrawAndClear)757 TEST_P(ClearTestES3, ClearPlusMaskDrawAndClear)
758 {
759 // Initialize a program with a uniform.
760 ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Simple(), essl1_shaders::fs::UniformColor());
761 glUseProgram(program);
762
763 GLint uniLoc = glGetUniformLocation(program, essl1_shaders::ColorUniform());
764 ASSERT_NE(-1, uniLoc);
765 glUniform4f(uniLoc, 0.0f, 1.0f, 0.0f, 1.0f);
766
767 // Initialize position attribute.
768 GLint posLoc = glGetAttribLocation(program, essl1_shaders::PositionAttrib());
769 ASSERT_NE(-1, posLoc);
770 setupQuadVertexBuffer(0.5f, 1.0f);
771 glVertexAttribPointer(posLoc, 3, GL_FLOAT, GL_FALSE, 0, nullptr);
772 glEnableVertexAttribArray(posLoc);
773
774 // Initialize a simple FBO.
775 constexpr GLsizei kSize = 2;
776 GLTexture clearTexture;
777 glBindTexture(GL_TEXTURE_2D, clearTexture);
778 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
779
780 GLFramebuffer fbo;
781 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
782 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, clearTexture, 0);
783
784 GLRenderbuffer depthStencil;
785 glBindRenderbuffer(GL_RENDERBUFFER, depthStencil);
786 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, kSize, kSize);
787 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
788 depthStencil);
789 ASSERT_GL_NO_ERROR();
790
791 glViewport(0, 0, kSize, kSize);
792
793 // Clear and draw to flush out dirty bits.
794 glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
795 glClearDepthf(1.0f);
796 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
797
798 // Draw green rectangle
799 glDrawArrays(GL_TRIANGLES, 0, 6);
800
801 // Enable color mask and draw again to trigger the bug.
802 glColorMask(GL_TRUE, GL_FALSE, GL_TRUE, GL_TRUE);
803 glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
804 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
805
806 // Draw purple-ish rectangle, green should be masked off
807 glUniform4f(uniLoc, 1.0f, 0.25f, 1.0f, 1.0f);
808 glDrawArrays(GL_TRIANGLES, 0, 6);
809
810 ASSERT_GL_NO_ERROR();
811 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::white);
812 }
813
814 // Test that clearing all buffers through glClearColor followed by a clear of a specific buffer
815 // clears to the correct values.
TEST_P(ClearTestES3,ClearMultipleAttachmentsFollowedBySpecificOne)816 TEST_P(ClearTestES3, ClearMultipleAttachmentsFollowedBySpecificOne)
817 {
818 constexpr uint32_t kSize = 16;
819 constexpr uint32_t kAttachmentCount = 4;
820 std::vector<unsigned char> pixelData(kSize * kSize * 4, 255);
821
822 glBindFramebuffer(GL_FRAMEBUFFER, mFBOs[0]);
823
824 GLTexture textures[kAttachmentCount];
825 GLenum drawBuffers[kAttachmentCount];
826 GLColor clearValues[kAttachmentCount];
827
828 for (uint32_t i = 0; i < kAttachmentCount; ++i)
829 {
830 glBindTexture(GL_TEXTURE_2D, textures[i]);
831 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
832 pixelData.data());
833 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, GL_TEXTURE_2D, textures[i],
834 0);
835 drawBuffers[i] = GL_COLOR_ATTACHMENT0 + i;
836
837 clearValues[i].R = static_cast<GLubyte>(1 + i * 20);
838 clearValues[i].G = static_cast<GLubyte>(7 + i * 20);
839 clearValues[i].B = static_cast<GLubyte>(12 + i * 20);
840 clearValues[i].A = static_cast<GLubyte>(16 + i * 20);
841 }
842
843 glDrawBuffers(kAttachmentCount, drawBuffers);
844
845 ASSERT_GL_NO_ERROR();
846 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::white);
847
848 // Clear all targets.
849 angle::Vector4 clearColor = clearValues[0].toNormalizedVector();
850 glClearColor(clearColor[0], clearColor[1], clearColor[2], clearColor[3]);
851 glClear(GL_COLOR_BUFFER_BIT);
852 ASSERT_GL_NO_ERROR();
853
854 // Clear odd targets individually.
855 for (uint32_t i = 1; i < kAttachmentCount; i += 2)
856 {
857 clearColor = clearValues[i].toNormalizedVector();
858 glClearBufferfv(GL_COLOR, i, clearColor.data());
859 }
860
861 // Even attachments should be cleared to color 0, while odd attachments are cleared to their
862 // respective color.
863 for (uint32_t i = 0; i < kAttachmentCount; ++i)
864 {
865 glReadBuffer(GL_COLOR_ATTACHMENT0 + i);
866 ASSERT_GL_NO_ERROR();
867
868 uint32_t clearIndex = i % 2 == 0 ? 0 : i;
869 const GLColor &expect = clearValues[clearIndex];
870
871 EXPECT_PIXEL_COLOR_EQ(0, 0, expect);
872 EXPECT_PIXEL_COLOR_EQ(0, kSize - 1, expect);
873 EXPECT_PIXEL_COLOR_EQ(kSize - 1, 0, expect);
874 EXPECT_PIXEL_COLOR_EQ(kSize - 1, kSize - 1, expect);
875 }
876 }
877
878 // Test that clearing each render target individually works. In the Vulkan backend, this should be
879 // done in a single render pass.
TEST_P(ClearTestES3,ClearMultipleAttachmentsIndividually)880 TEST_P(ClearTestES3, ClearMultipleAttachmentsIndividually)
881 {
882 // http://anglebug.com/4855
883 ANGLE_SKIP_TEST_IF(IsWindows() && IsIntel() && IsVulkan());
884
885 constexpr uint32_t kSize = 16;
886 constexpr uint32_t kAttachmentCount = 2;
887 constexpr float kDepthClearValue = 0.125f;
888 constexpr int32_t kStencilClearValue = 0x67;
889 std::vector<unsigned char> pixelData(kSize * kSize * 4, 255);
890
891 glBindFramebuffer(GL_FRAMEBUFFER, mFBOs[0]);
892
893 GLTexture textures[kAttachmentCount];
894 GLRenderbuffer depthStencil;
895 GLenum drawBuffers[kAttachmentCount];
896 GLColor clearValues[kAttachmentCount];
897
898 for (uint32_t i = 0; i < kAttachmentCount; ++i)
899 {
900 glBindTexture(GL_TEXTURE_2D, textures[i]);
901 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
902 pixelData.data());
903 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, GL_TEXTURE_2D, textures[i],
904 0);
905 drawBuffers[i] = GL_COLOR_ATTACHMENT0 + i;
906
907 clearValues[i].R = static_cast<GLubyte>(1 + i * 20);
908 clearValues[i].G = static_cast<GLubyte>(7 + i * 20);
909 clearValues[i].B = static_cast<GLubyte>(12 + i * 20);
910 clearValues[i].A = static_cast<GLubyte>(16 + i * 20);
911 }
912
913 glBindRenderbuffer(GL_RENDERBUFFER, depthStencil);
914 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, kSize, kSize);
915 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
916 depthStencil);
917
918 glDrawBuffers(kAttachmentCount, drawBuffers);
919
920 ASSERT_GL_NO_ERROR();
921 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::white);
922
923 for (uint32_t i = 0; i < kAttachmentCount; ++i)
924 {
925 glClearBufferfv(GL_COLOR, i, clearValues[i].toNormalizedVector().data());
926 }
927
928 glClearBufferfv(GL_DEPTH, 0, &kDepthClearValue);
929 glClearBufferiv(GL_STENCIL, 0, &kStencilClearValue);
930 ASSERT_GL_NO_ERROR();
931
932 for (uint32_t i = 0; i < kAttachmentCount; ++i)
933 {
934 glReadBuffer(GL_COLOR_ATTACHMENT0 + i);
935 ASSERT_GL_NO_ERROR();
936
937 const GLColor &expect = clearValues[i];
938
939 EXPECT_PIXEL_COLOR_EQ(0, 0, expect);
940 EXPECT_PIXEL_COLOR_EQ(0, kSize - 1, expect);
941 EXPECT_PIXEL_COLOR_EQ(kSize - 1, 0, expect);
942 EXPECT_PIXEL_COLOR_EQ(kSize - 1, kSize - 1, expect);
943 }
944
945 glReadBuffer(GL_COLOR_ATTACHMENT0);
946 for (uint32_t i = 1; i < kAttachmentCount; ++i)
947 drawBuffers[i] = GL_NONE;
948 glDrawBuffers(kAttachmentCount, drawBuffers);
949
950 verifyDepth(kDepthClearValue, kSize);
951 verifyStencil(kStencilClearValue, kSize);
952 }
953
954 // Test that clearing multiple attachments in the presence of a color mask, scissor or both
955 // correctly clears all the attachments.
TEST_P(ClearTestES3,MaskedScissoredClearMultipleAttachments)956 TEST_P(ClearTestES3, MaskedScissoredClearMultipleAttachments)
957 {
958 constexpr uint32_t kSize = 16;
959 constexpr uint32_t kAttachmentCount = 2;
960 std::vector<unsigned char> pixelData(kSize * kSize * 4, 255);
961
962 glBindFramebuffer(GL_FRAMEBUFFER, mFBOs[0]);
963
964 GLTexture textures[kAttachmentCount];
965 GLenum drawBuffers[kAttachmentCount];
966
967 for (uint32_t i = 0; i < kAttachmentCount; ++i)
968 {
969 glBindTexture(GL_TEXTURE_2D, textures[i]);
970 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
971 pixelData.data());
972 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, GL_TEXTURE_2D, textures[i],
973 0);
974 drawBuffers[i] = GL_COLOR_ATTACHMENT0 + i;
975 }
976
977 glDrawBuffers(kAttachmentCount, drawBuffers);
978
979 ASSERT_GL_NO_ERROR();
980 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::white);
981
982 // Masked clear
983 GLColor clearColorMasked(31, 63, 255, 191);
984 angle::Vector4 clearColor = GLColor(31, 63, 127, 191).toNormalizedVector();
985
986 glColorMask(GL_TRUE, GL_TRUE, GL_FALSE, GL_TRUE);
987 glClearColor(clearColor[0], clearColor[1], clearColor[2], clearColor[3]);
988 glClear(GL_COLOR_BUFFER_BIT);
989 ASSERT_GL_NO_ERROR();
990
991 // All attachments should be cleared, with the blue channel untouched
992 for (uint32_t i = 0; i < kAttachmentCount; ++i)
993 {
994 glReadBuffer(GL_COLOR_ATTACHMENT0 + i);
995 ASSERT_GL_NO_ERROR();
996
997 EXPECT_PIXEL_COLOR_EQ(0, 0, clearColorMasked);
998 EXPECT_PIXEL_COLOR_EQ(0, kSize - 1, clearColorMasked);
999 EXPECT_PIXEL_COLOR_EQ(kSize - 1, 0, clearColorMasked);
1000 EXPECT_PIXEL_COLOR_EQ(kSize - 1, kSize - 1, clearColorMasked);
1001 EXPECT_PIXEL_COLOR_EQ(kSize / 2, kSize / 2, clearColorMasked);
1002 }
1003
1004 // Masked scissored clear
1005 GLColor clearColorMaskedScissored(63, 127, 255, 31);
1006 clearColor = GLColor(63, 127, 191, 31).toNormalizedVector();
1007
1008 glClearColor(clearColor[0], clearColor[1], clearColor[2], clearColor[3]);
1009 glEnable(GL_SCISSOR_TEST);
1010 glScissor(kSize / 6, kSize / 6, kSize / 3, kSize / 3);
1011 glClear(GL_COLOR_BUFFER_BIT);
1012 ASSERT_GL_NO_ERROR();
1013
1014 // The corners should keep the previous value while the center is cleared, except its blue
1015 // channel.
1016 for (uint32_t i = 0; i < kAttachmentCount; ++i)
1017 {
1018 glReadBuffer(GL_COLOR_ATTACHMENT0 + i);
1019 ASSERT_GL_NO_ERROR();
1020
1021 EXPECT_PIXEL_COLOR_EQ(0, 0, clearColorMasked);
1022 EXPECT_PIXEL_COLOR_EQ(0, kSize - 1, clearColorMasked);
1023 EXPECT_PIXEL_COLOR_EQ(kSize - 1, 0, clearColorMasked);
1024 EXPECT_PIXEL_COLOR_EQ(kSize - 1, kSize - 1, clearColorMasked);
1025 EXPECT_PIXEL_COLOR_EQ(kSize / 3, 2 * kSize / 3, clearColorMasked);
1026 EXPECT_PIXEL_COLOR_EQ(2 * kSize / 3, kSize / 3, clearColorMasked);
1027 EXPECT_PIXEL_COLOR_EQ(2 * kSize / 3, 2 * kSize / 3, clearColorMasked);
1028
1029 EXPECT_PIXEL_COLOR_EQ(kSize / 3, kSize / 3, clearColorMaskedScissored);
1030 }
1031
1032 // Scissored clear
1033 GLColor clearColorScissored(127, 191, 31, 63);
1034 clearColor = GLColor(127, 191, 31, 63).toNormalizedVector();
1035
1036 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
1037 glClearColor(clearColor[0], clearColor[1], clearColor[2], clearColor[3]);
1038 glClear(GL_COLOR_BUFFER_BIT);
1039 ASSERT_GL_NO_ERROR();
1040
1041 // The corners should keep the old value while all channels of the center are cleared.
1042 for (uint32_t i = 0; i < kAttachmentCount; ++i)
1043 {
1044 glReadBuffer(GL_COLOR_ATTACHMENT0 + i);
1045 ASSERT_GL_NO_ERROR();
1046
1047 EXPECT_PIXEL_COLOR_EQ(0, 0, clearColorMasked);
1048 EXPECT_PIXEL_COLOR_EQ(0, kSize - 1, clearColorMasked);
1049 EXPECT_PIXEL_COLOR_EQ(kSize - 1, 0, clearColorMasked);
1050 EXPECT_PIXEL_COLOR_EQ(kSize - 1, kSize - 1, clearColorMasked);
1051 EXPECT_PIXEL_COLOR_EQ(kSize / 3, 2 * kSize / 3, clearColorMasked);
1052 EXPECT_PIXEL_COLOR_EQ(2 * kSize / 3, kSize / 3, clearColorMasked);
1053 EXPECT_PIXEL_COLOR_EQ(2 * kSize / 3, 2 * kSize / 3, clearColorMasked);
1054
1055 EXPECT_PIXEL_COLOR_EQ(kSize / 3, kSize / 3, clearColorScissored);
1056 }
1057 }
1058
1059 // Test clearing multiple attachments in the presence of an indexed color mask.
TEST_P(ClearTestES3,MaskedIndexedClearMultipleAttachments)1060 TEST_P(ClearTestES3, MaskedIndexedClearMultipleAttachments)
1061 {
1062 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_draw_buffers_indexed"));
1063
1064 constexpr uint32_t kSize = 16;
1065 constexpr uint32_t kAttachmentCount = 4;
1066 std::vector<unsigned char> pixelData(kSize * kSize * 4, 255);
1067
1068 glBindFramebuffer(GL_FRAMEBUFFER, mFBOs[0]);
1069
1070 GLTexture textures[kAttachmentCount];
1071 GLenum drawBuffers[kAttachmentCount];
1072
1073 for (uint32_t i = 0; i < kAttachmentCount; ++i)
1074 {
1075 glBindTexture(GL_TEXTURE_2D, textures[i]);
1076 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1077 pixelData.data());
1078 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, GL_TEXTURE_2D, textures[i],
1079 0);
1080 drawBuffers[i] = GL_COLOR_ATTACHMENT0 + i;
1081 }
1082
1083 glDrawBuffers(kAttachmentCount, drawBuffers);
1084
1085 ASSERT_GL_NO_ERROR();
1086 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::white);
1087
1088 // Masked clear
1089 GLColor clearColorMasked(31, 63, 255, 191);
1090 angle::Vector4 clearColor = GLColor(31, 63, 127, 191).toNormalizedVector();
1091
1092 // Block blue channel for all attachements
1093 glColorMask(GL_TRUE, GL_TRUE, GL_FALSE, GL_TRUE);
1094
1095 // Unblock blue channel for attachments 0 and 1
1096 glColorMaskiOES(0, GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
1097 glColorMaskiOES(1, GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
1098
1099 glClearColor(clearColor[0], clearColor[1], clearColor[2], clearColor[3]);
1100 glClear(GL_COLOR_BUFFER_BIT);
1101 ASSERT_GL_NO_ERROR();
1102
1103 // All attachments should be cleared, with the blue channel untouched for all attachments but 1.
1104 for (uint32_t i = 0; i < kAttachmentCount; ++i)
1105 {
1106 glReadBuffer(GL_COLOR_ATTACHMENT0 + i);
1107 ASSERT_GL_NO_ERROR();
1108
1109 const GLColor attachmentColor = (i > 1) ? clearColorMasked : clearColor;
1110 EXPECT_PIXEL_COLOR_EQ(0, 0, attachmentColor);
1111 EXPECT_PIXEL_COLOR_EQ(0, kSize - 1, attachmentColor);
1112 EXPECT_PIXEL_COLOR_EQ(kSize - 1, 0, attachmentColor);
1113 EXPECT_PIXEL_COLOR_EQ(kSize - 1, kSize - 1, attachmentColor);
1114 EXPECT_PIXEL_COLOR_EQ(kSize / 2, kSize / 2, attachmentColor);
1115 }
1116 }
1117
1118 // Test that clearing multiple attachments of different nature (float, int and uint) in the
1119 // presence of a color mask works correctly. In the Vulkan backend, this exercises clearWithDraw
1120 // and the relevant internal shaders.
TEST_P(ClearTestES3,MaskedClearHeterogeneousAttachments)1121 TEST_P(ClearTestES3, MaskedClearHeterogeneousAttachments)
1122 {
1123 // http://anglebug.com/4855
1124 ANGLE_SKIP_TEST_IF(IsWindows() && IsIntel() && IsVulkan());
1125
1126 // TODO(anglebug.com/5491)
1127 ANGLE_SKIP_TEST_IF(IsIOS() && IsOpenGLES());
1128
1129 constexpr uint32_t kSize = 16;
1130 constexpr uint32_t kAttachmentCount = 3;
1131 constexpr float kDepthClearValue = 0.256f;
1132 constexpr int32_t kStencilClearValue = 0x1D;
1133 constexpr GLenum kAttachmentFormats[kAttachmentCount] = {
1134 GL_RGBA8,
1135 GL_RGBA8I,
1136 GL_RGBA8UI,
1137 };
1138 constexpr GLenum kDataFormats[kAttachmentCount] = {
1139 GL_RGBA,
1140 GL_RGBA_INTEGER,
1141 GL_RGBA_INTEGER,
1142 };
1143 constexpr GLenum kDataTypes[kAttachmentCount] = {
1144 GL_UNSIGNED_BYTE,
1145 GL_BYTE,
1146 GL_UNSIGNED_BYTE,
1147 };
1148
1149 std::vector<unsigned char> pixelData(kSize * kSize * 4, 0);
1150
1151 glBindFramebuffer(GL_FRAMEBUFFER, mFBOs[0]);
1152
1153 GLTexture textures[kAttachmentCount];
1154 GLRenderbuffer depthStencil;
1155 GLenum drawBuffers[kAttachmentCount];
1156
1157 for (uint32_t i = 0; i < kAttachmentCount; ++i)
1158 {
1159 glBindTexture(GL_TEXTURE_2D, textures[i]);
1160 glTexImage2D(GL_TEXTURE_2D, 0, kAttachmentFormats[i], kSize, kSize, 0, kDataFormats[i],
1161 kDataTypes[i], pixelData.data());
1162 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, GL_TEXTURE_2D, textures[i],
1163 0);
1164 drawBuffers[i] = GL_COLOR_ATTACHMENT0 + i;
1165 }
1166
1167 glBindRenderbuffer(GL_RENDERBUFFER, depthStencil);
1168 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, kSize, kSize);
1169 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
1170 depthStencil);
1171
1172 glDrawBuffers(kAttachmentCount, drawBuffers);
1173
1174 ASSERT_GL_NO_ERROR();
1175 EXPECT_PIXEL_EQ(0, 0, 0, 0, 0, 0);
1176
1177 // Mask out red for all clears
1178 glColorMask(GL_FALSE, GL_TRUE, GL_TRUE, GL_TRUE);
1179
1180 glClearBufferfv(GL_DEPTH, 0, &kDepthClearValue);
1181 glClearBufferiv(GL_STENCIL, 0, &kStencilClearValue);
1182
1183 GLColor clearValuef = {25, 50, 75, 100};
1184 glClearBufferfv(GL_COLOR, 0, clearValuef.toNormalizedVector().data());
1185
1186 int clearValuei[4] = {10, -20, 30, -40};
1187 glClearBufferiv(GL_COLOR, 1, clearValuei);
1188
1189 uint32_t clearValueui[4] = {50, 60, 70, 80};
1190 glClearBufferuiv(GL_COLOR, 2, clearValueui);
1191
1192 ASSERT_GL_NO_ERROR();
1193
1194 {
1195 glReadBuffer(GL_COLOR_ATTACHMENT0);
1196 ASSERT_GL_NO_ERROR();
1197
1198 GLColor expect = clearValuef;
1199 expect.R = 0;
1200
1201 EXPECT_PIXEL_COLOR_EQ(0, 0, expect);
1202 EXPECT_PIXEL_COLOR_EQ(0, kSize - 1, expect);
1203 EXPECT_PIXEL_COLOR_EQ(kSize - 1, 0, expect);
1204 EXPECT_PIXEL_COLOR_EQ(kSize - 1, kSize - 1, expect);
1205 }
1206
1207 {
1208 glReadBuffer(GL_COLOR_ATTACHMENT1);
1209 ASSERT_GL_NO_ERROR();
1210
1211 EXPECT_PIXEL_8I(0, 0, 0, clearValuei[1], clearValuei[2], clearValuei[3]);
1212 EXPECT_PIXEL_8I(0, kSize - 1, 0, clearValuei[1], clearValuei[2], clearValuei[3]);
1213 EXPECT_PIXEL_8I(kSize - 1, 0, 0, clearValuei[1], clearValuei[2], clearValuei[3]);
1214 EXPECT_PIXEL_8I(kSize - 1, kSize - 1, 0, clearValuei[1], clearValuei[2], clearValuei[3]);
1215 }
1216
1217 {
1218 glReadBuffer(GL_COLOR_ATTACHMENT2);
1219 ASSERT_GL_NO_ERROR();
1220
1221 EXPECT_PIXEL_8UI(0, 0, 0, clearValueui[1], clearValueui[2], clearValueui[3]);
1222 EXPECT_PIXEL_8UI(0, kSize - 1, 0, clearValueui[1], clearValueui[2], clearValueui[3]);
1223 EXPECT_PIXEL_8UI(kSize - 1, 0, 0, clearValueui[1], clearValueui[2], clearValueui[3]);
1224 EXPECT_PIXEL_8UI(kSize - 1, kSize - 1, 0, clearValueui[1], clearValueui[2],
1225 clearValueui[3]);
1226 }
1227
1228 glReadBuffer(GL_COLOR_ATTACHMENT0);
1229 for (uint32_t i = 1; i < kAttachmentCount; ++i)
1230 drawBuffers[i] = GL_NONE;
1231 glDrawBuffers(kAttachmentCount, drawBuffers);
1232
1233 verifyDepth(kDepthClearValue, kSize);
1234 verifyStencil(kStencilClearValue, kSize);
1235 }
1236
1237 // Test that clearing multiple attachments of different nature (float, int and uint) in the
1238 // presence of a scissor test works correctly. In the Vulkan backend, this exercises clearWithDraw
1239 // and the relevant internal shaders.
TEST_P(ClearTestES3,ScissoredClearHeterogeneousAttachments)1240 TEST_P(ClearTestES3, ScissoredClearHeterogeneousAttachments)
1241 {
1242 // http://anglebug.com/4855
1243 ANGLE_SKIP_TEST_IF(IsWindows() && IsIntel() && IsVulkan());
1244
1245 // http://anglebug.com/5116
1246 ANGLE_SKIP_TEST_IF(IsWindows() && (IsOpenGL() || IsD3D11()) && IsAMD());
1247
1248 // http://anglebug.com/5237
1249 ANGLE_SKIP_TEST_IF(IsWindows7() && IsD3D11() && IsNVIDIA());
1250
1251 // TODO(anglebug.com/5491)
1252 ANGLE_SKIP_TEST_IF(IsIOS() && IsOpenGLES());
1253
1254 constexpr uint32_t kSize = 16;
1255 constexpr uint32_t kHalfSize = kSize / 2;
1256 constexpr uint32_t kAttachmentCount = 3;
1257 constexpr float kDepthClearValue = 0.256f;
1258 constexpr int32_t kStencilClearValue = 0x1D;
1259 constexpr GLenum kAttachmentFormats[kAttachmentCount] = {
1260 GL_RGBA8,
1261 GL_RGBA8I,
1262 GL_RGBA8UI,
1263 };
1264 constexpr GLenum kDataFormats[kAttachmentCount] = {
1265 GL_RGBA,
1266 GL_RGBA_INTEGER,
1267 GL_RGBA_INTEGER,
1268 };
1269 constexpr GLenum kDataTypes[kAttachmentCount] = {
1270 GL_UNSIGNED_BYTE,
1271 GL_BYTE,
1272 GL_UNSIGNED_BYTE,
1273 };
1274
1275 std::vector<unsigned char> pixelData(kSize * kSize * 4, 0);
1276
1277 glBindFramebuffer(GL_FRAMEBUFFER, mFBOs[0]);
1278
1279 GLTexture textures[kAttachmentCount];
1280 GLRenderbuffer depthStencil;
1281 GLenum drawBuffers[kAttachmentCount];
1282
1283 for (uint32_t i = 0; i < kAttachmentCount; ++i)
1284 {
1285 glBindTexture(GL_TEXTURE_2D, textures[i]);
1286 glTexImage2D(GL_TEXTURE_2D, 0, kAttachmentFormats[i], kSize, kSize, 0, kDataFormats[i],
1287 kDataTypes[i], pixelData.data());
1288 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, GL_TEXTURE_2D, textures[i],
1289 0);
1290 drawBuffers[i] = GL_COLOR_ATTACHMENT0 + i;
1291 }
1292
1293 glBindRenderbuffer(GL_RENDERBUFFER, depthStencil);
1294 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, kSize, kSize);
1295 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
1296 depthStencil);
1297
1298 glDrawBuffers(kAttachmentCount, drawBuffers);
1299
1300 ASSERT_GL_NO_ERROR();
1301 EXPECT_PIXEL_EQ(0, 0, 0, 0, 0, 0);
1302
1303 // Enable scissor test
1304 glScissor(0, 0, kHalfSize, kHalfSize);
1305 glEnable(GL_SCISSOR_TEST);
1306
1307 GLColor clearValuef = {25, 50, 75, 100};
1308 angle::Vector4 clearValuefv = clearValuef.toNormalizedVector();
1309
1310 glClearColor(clearValuefv.x(), clearValuefv.y(), clearValuefv.z(), clearValuefv.w());
1311 glClearDepthf(kDepthClearValue);
1312
1313 // clear stencil.
1314 glClearBufferiv(GL_STENCIL, 0, &kStencilClearValue);
1315
1316 // clear float color attachment & depth together
1317 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
1318
1319 // clear integer attachment.
1320 int clearValuei[4] = {10, -20, 30, -40};
1321 glClearBufferiv(GL_COLOR, 1, clearValuei);
1322
1323 // clear unsigned integer attachment
1324 uint32_t clearValueui[4] = {50, 60, 70, 80};
1325 glClearBufferuiv(GL_COLOR, 2, clearValueui);
1326
1327 ASSERT_GL_NO_ERROR();
1328
1329 {
1330 glReadBuffer(GL_COLOR_ATTACHMENT0);
1331 ASSERT_GL_NO_ERROR();
1332
1333 GLColor expect = clearValuef;
1334
1335 EXPECT_PIXEL_COLOR_EQ(0, 0, expect);
1336 EXPECT_PIXEL_COLOR_EQ(0, kHalfSize - 1, expect);
1337 EXPECT_PIXEL_COLOR_EQ(kHalfSize - 1, 0, expect);
1338 EXPECT_PIXEL_COLOR_EQ(kHalfSize - 1, kHalfSize - 1, expect);
1339 EXPECT_PIXEL_EQ(kHalfSize + 1, kHalfSize + 1, 0, 0, 0, 0);
1340 }
1341
1342 {
1343 glReadBuffer(GL_COLOR_ATTACHMENT1);
1344 ASSERT_GL_NO_ERROR();
1345
1346 EXPECT_PIXEL_8I(0, 0, clearValuei[0], clearValuei[1], clearValuei[2], clearValuei[3]);
1347 EXPECT_PIXEL_8I(0, kHalfSize - 1, clearValuei[0], clearValuei[1], clearValuei[2],
1348 clearValuei[3]);
1349 EXPECT_PIXEL_8I(kHalfSize - 1, 0, clearValuei[0], clearValuei[1], clearValuei[2],
1350 clearValuei[3]);
1351 EXPECT_PIXEL_8I(kHalfSize - 1, kHalfSize - 1, clearValuei[0], clearValuei[1],
1352 clearValuei[2], clearValuei[3]);
1353 EXPECT_PIXEL_8I(kHalfSize + 1, kHalfSize + 1, 0, 0, 0, 0);
1354 }
1355
1356 {
1357 glReadBuffer(GL_COLOR_ATTACHMENT2);
1358 ASSERT_GL_NO_ERROR();
1359
1360 EXPECT_PIXEL_8UI(0, 0, clearValueui[0], clearValueui[1], clearValueui[2], clearValueui[3]);
1361 EXPECT_PIXEL_8UI(0, kHalfSize - 1, clearValueui[0], clearValueui[1], clearValueui[2],
1362 clearValueui[3]);
1363 EXPECT_PIXEL_8UI(kHalfSize - 1, 0, clearValueui[0], clearValueui[1], clearValueui[2],
1364 clearValueui[3]);
1365 EXPECT_PIXEL_8UI(kHalfSize - 1, kHalfSize - 1, clearValueui[0], clearValueui[1],
1366 clearValueui[2], clearValueui[3]);
1367 EXPECT_PIXEL_8UI(kHalfSize + 1, kHalfSize + 1, 0, 0, 0, 0);
1368 }
1369
1370 glReadBuffer(GL_COLOR_ATTACHMENT0);
1371 for (uint32_t i = 1; i < kAttachmentCount; ++i)
1372 drawBuffers[i] = GL_NONE;
1373 glDrawBuffers(kAttachmentCount, drawBuffers);
1374
1375 verifyDepth(kDepthClearValue, kHalfSize);
1376 verifyStencil(kStencilClearValue, kHalfSize);
1377 }
1378
1379 // This tests a bug where in a masked clear when calling "ClearBuffer", we would
1380 // mistakenly clear every channel (including the masked-out ones)
TEST_P(ClearTestES3,MaskedClearBufferBug)1381 TEST_P(ClearTestES3, MaskedClearBufferBug)
1382 {
1383 unsigned char pixelData[] = {255, 255, 255, 255};
1384
1385 glBindFramebuffer(GL_FRAMEBUFFER, mFBOs[0]);
1386
1387 GLTexture textures[2];
1388
1389 glBindTexture(GL_TEXTURE_2D, textures[0]);
1390 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixelData);
1391 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0], 0);
1392
1393 glBindTexture(GL_TEXTURE_2D, textures[1]);
1394 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixelData);
1395 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, textures[1], 0);
1396
1397 ASSERT_GL_NO_ERROR();
1398 EXPECT_PIXEL_EQ(0, 0, 255, 255, 255, 255);
1399
1400 float clearValue[] = {0, 0.5f, 0.5f, 1.0f};
1401 GLenum drawBuffers[] = {GL_NONE, GL_COLOR_ATTACHMENT1};
1402 glDrawBuffers(2, drawBuffers);
1403 glColorMask(GL_TRUE, GL_TRUE, GL_FALSE, GL_TRUE);
1404 glClearBufferfv(GL_COLOR, 1, clearValue);
1405
1406 ASSERT_GL_NO_ERROR();
1407 EXPECT_PIXEL_EQ(0, 0, 255, 255, 255, 255);
1408
1409 glReadBuffer(GL_COLOR_ATTACHMENT1);
1410 ASSERT_GL_NO_ERROR();
1411
1412 EXPECT_PIXEL_NEAR(0, 0, 0, 127, 255, 255, 1);
1413 }
1414
TEST_P(ClearTestES3,BadFBOSerialBug)1415 TEST_P(ClearTestES3, BadFBOSerialBug)
1416 {
1417 // First make a simple framebuffer, and clear it to green
1418 glBindFramebuffer(GL_FRAMEBUFFER, mFBOs[0]);
1419
1420 GLTexture textures[2];
1421
1422 glBindTexture(GL_TEXTURE_2D, textures[0]);
1423 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, getWindowWidth(), getWindowHeight());
1424 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0], 0);
1425
1426 GLenum drawBuffers[] = {GL_COLOR_ATTACHMENT0};
1427 glDrawBuffers(1, drawBuffers);
1428
1429 float clearValues1[] = {0.0f, 1.0f, 0.0f, 1.0f};
1430 glClearBufferfv(GL_COLOR, 0, clearValues1);
1431
1432 ASSERT_GL_NO_ERROR();
1433 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1434
1435 // Next make a second framebuffer, and draw it to red
1436 // (Triggers bad applied render target serial)
1437 GLFramebuffer fbo2;
1438 glBindFramebuffer(GL_FRAMEBUFFER, fbo2);
1439 ASSERT_GL_NO_ERROR();
1440
1441 glBindTexture(GL_TEXTURE_2D, textures[1]);
1442 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, getWindowWidth(), getWindowHeight());
1443 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[1], 0);
1444
1445 glDrawBuffers(1, drawBuffers);
1446
1447 ANGLE_GL_PROGRAM(blueProgram, essl1_shaders::vs::Simple(), essl1_shaders::fs::Red());
1448 drawQuad(blueProgram, essl1_shaders::PositionAttrib(), 0.5f);
1449
1450 ASSERT_GL_NO_ERROR();
1451 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
1452
1453 // Check that the first framebuffer is still green.
1454 glBindFramebuffer(GL_FRAMEBUFFER, mFBOs[0]);
1455 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1456 }
1457
1458 // Test that SRGB framebuffers clear to the linearized clear color
TEST_P(ClearTestES3,SRGBClear)1459 TEST_P(ClearTestES3, SRGBClear)
1460 {
1461 // First make a simple framebuffer, and clear it
1462 glBindFramebuffer(GL_FRAMEBUFFER, mFBOs[0]);
1463
1464 GLTexture texture;
1465
1466 glBindTexture(GL_TEXTURE_2D, texture);
1467 glTexStorage2D(GL_TEXTURE_2D, 1, GL_SRGB8_ALPHA8, getWindowWidth(), getWindowHeight());
1468 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
1469
1470 glClearColor(0.5f, 0.5f, 0.5f, 0.5f);
1471 glClear(GL_COLOR_BUFFER_BIT);
1472
1473 EXPECT_PIXEL_NEAR(0, 0, 188, 188, 188, 128, 1.0);
1474 }
1475
1476 // Test that framebuffers with mixed SRGB/Linear attachments clear to the correct color for each
1477 // attachment
TEST_P(ClearTestES3,MixedSRGBClear)1478 TEST_P(ClearTestES3, MixedSRGBClear)
1479 {
1480 glBindFramebuffer(GL_FRAMEBUFFER, mFBOs[0]);
1481
1482 GLTexture textures[2];
1483
1484 glBindTexture(GL_TEXTURE_2D, textures[0]);
1485 glTexStorage2D(GL_TEXTURE_2D, 1, GL_SRGB8_ALPHA8, getWindowWidth(), getWindowHeight());
1486 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0], 0);
1487
1488 glBindTexture(GL_TEXTURE_2D, textures[1]);
1489 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, getWindowWidth(), getWindowHeight());
1490 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, textures[1], 0);
1491
1492 GLenum drawBuffers[] = {GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1};
1493 glDrawBuffers(2, drawBuffers);
1494
1495 // Clear both textures
1496 glClearColor(0.5f, 0.5f, 0.5f, 0.5f);
1497 glClear(GL_COLOR_BUFFER_BIT);
1498
1499 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0);
1500 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, 0, 0);
1501
1502 // Check value of texture0
1503 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0], 0);
1504 EXPECT_PIXEL_NEAR(0, 0, 188, 188, 188, 128, 1.0);
1505
1506 // Check value of texture1
1507 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[1], 0);
1508 EXPECT_PIXEL_NEAR(0, 0, 128, 128, 128, 128, 1.0);
1509 }
1510
1511 // This test covers a D3D11 bug where calling ClearRenderTargetView sometimes wouldn't sync
1512 // before a draw call. The test draws small quads to a larger FBO (the default back buffer).
1513 // Before each blit to the back buffer it clears the quad to a certain color using
1514 // ClearBufferfv to give a solid color. The sync problem goes away if we insert a call to
1515 // flush or finish after ClearBufferfv or each draw.
TEST_P(ClearTestES3,RepeatedClear)1516 TEST_P(ClearTestES3, RepeatedClear)
1517 {
1518 // Fails on 431.02 driver. http://anglebug.com/3748
1519 ANGLE_SKIP_TEST_IF(IsWindows() && IsNVIDIA() && IsVulkan());
1520 ANGLE_SKIP_TEST_IF(IsARM64() && IsWindows() && IsD3D());
1521
1522 constexpr char kVS[] =
1523 "#version 300 es\n"
1524 "in highp vec2 position;\n"
1525 "out highp vec2 v_coord;\n"
1526 "void main(void)\n"
1527 "{\n"
1528 " gl_Position = vec4(position, 0, 1);\n"
1529 " vec2 texCoord = (position * 0.5) + 0.5;\n"
1530 " v_coord = texCoord;\n"
1531 "}\n";
1532
1533 constexpr char kFS[] =
1534 "#version 300 es\n"
1535 "in highp vec2 v_coord;\n"
1536 "out highp vec4 color;\n"
1537 "uniform sampler2D tex;\n"
1538 "void main()\n"
1539 "{\n"
1540 " color = texture(tex, v_coord);\n"
1541 "}\n";
1542
1543 ANGLE_GL_PROGRAM(program, kVS, kFS);
1544
1545 mTextures.resize(1, 0);
1546 glGenTextures(1, mTextures.data());
1547
1548 GLenum format = GL_RGBA8;
1549 const int numRowsCols = 3;
1550 const int cellSize = 32;
1551 const int fboSize = cellSize;
1552 const int backFBOSize = cellSize * numRowsCols;
1553 const float fmtValueMin = 0.0f;
1554 const float fmtValueMax = 1.0f;
1555
1556 glBindTexture(GL_TEXTURE_2D, mTextures[0]);
1557 glTexStorage2D(GL_TEXTURE_2D, 1, format, fboSize, fboSize);
1558 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1559 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1560 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1561 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1562 ASSERT_GL_NO_ERROR();
1563
1564 glBindFramebuffer(GL_FRAMEBUFFER, mFBOs[0]);
1565 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[0], 0);
1566 ASSERT_GL_NO_ERROR();
1567
1568 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
1569
1570 // larger fbo bound -- clear to transparent black
1571 glUseProgram(program);
1572 GLint uniLoc = glGetUniformLocation(program, "tex");
1573 ASSERT_NE(-1, uniLoc);
1574 glUniform1i(uniLoc, 0);
1575 glBindTexture(GL_TEXTURE_2D, mTextures[0]);
1576
1577 GLint positionLocation = glGetAttribLocation(program, "position");
1578 ASSERT_NE(-1, positionLocation);
1579
1580 glUseProgram(program);
1581
1582 for (int cellY = 0; cellY < numRowsCols; cellY++)
1583 {
1584 for (int cellX = 0; cellX < numRowsCols; cellX++)
1585 {
1586 int seed = cellX + cellY * numRowsCols;
1587 const Vector4 color = RandomVec4(seed, fmtValueMin, fmtValueMax);
1588
1589 glBindFramebuffer(GL_FRAMEBUFFER, mFBOs[0]);
1590 glClearBufferfv(GL_COLOR, 0, color.data());
1591
1592 glBindFramebuffer(GL_FRAMEBUFFER, 0);
1593
1594 // Method 1: Set viewport and draw full-viewport quad
1595 glViewport(cellX * cellSize, cellY * cellSize, cellSize, cellSize);
1596 drawQuad(program, "position", 0.5f);
1597
1598 // Uncommenting the glFinish call seems to make the test pass.
1599 // glFinish();
1600 }
1601 }
1602
1603 std::vector<GLColor> pixelData(backFBOSize * backFBOSize);
1604 glReadPixels(0, 0, backFBOSize, backFBOSize, GL_RGBA, GL_UNSIGNED_BYTE, pixelData.data());
1605
1606 for (int cellY = 0; cellY < numRowsCols; cellY++)
1607 {
1608 for (int cellX = 0; cellX < numRowsCols; cellX++)
1609 {
1610 int seed = cellX + cellY * numRowsCols;
1611 const Vector4 color = RandomVec4(seed, fmtValueMin, fmtValueMax);
1612 GLColor expectedColor(color);
1613
1614 int testN = cellX * cellSize + cellY * backFBOSize * cellSize + backFBOSize + 1;
1615 GLColor actualColor = pixelData[testN];
1616 EXPECT_NEAR(expectedColor.R, actualColor.R, 1);
1617 EXPECT_NEAR(expectedColor.G, actualColor.G, 1);
1618 EXPECT_NEAR(expectedColor.B, actualColor.B, 1);
1619 EXPECT_NEAR(expectedColor.A, actualColor.A, 1);
1620 }
1621 }
1622
1623 ASSERT_GL_NO_ERROR();
1624 }
1625
1626 // Test that clearing RGB8 attachments work when verified through sampling.
TEST_P(ClearTestES3,ClearRGB8)1627 TEST_P(ClearTestES3, ClearRGB8)
1628 {
1629 GLFramebuffer fb;
1630 glBindFramebuffer(GL_FRAMEBUFFER, fb);
1631
1632 GLTexture tex;
1633 glBindTexture(GL_TEXTURE_2D, tex);
1634 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGB8, 1, 1);
1635 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1636 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1637
1638 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex, 0);
1639 ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER);
1640
1641 // Clear the texture through framebuffer.
1642 const GLubyte kClearColor[] = {63, 127, 191, 55};
1643 glClearColor(kClearColor[0] / 255.0f, kClearColor[1] / 255.0f, kClearColor[2] / 255.0f,
1644 kClearColor[3] / 255.0f);
1645 glClear(GL_COLOR_BUFFER_BIT);
1646 ASSERT_GL_NO_ERROR();
1647
1648 glBindFramebuffer(GL_FRAMEBUFFER, 0);
1649
1650 // Sample from it and verify clear is done.
1651 ANGLE_GL_PROGRAM(program, essl3_shaders::vs::Texture2DLod(), essl3_shaders::fs::Texture2DLod());
1652 glUseProgram(program);
1653 GLint textureLocation = glGetUniformLocation(program, essl3_shaders::Texture2DUniform());
1654 ASSERT_NE(-1, textureLocation);
1655 GLint lodLocation = glGetUniformLocation(program, essl3_shaders::LodUniform());
1656 ASSERT_NE(-1, lodLocation);
1657
1658 glUniform1i(textureLocation, 0);
1659 glUniform1f(lodLocation, 0);
1660
1661 drawQuad(program, essl3_shaders::PositionAttrib(), 0.5f);
1662
1663 EXPECT_PIXEL_NEAR(0, 0, kClearColor[0], kClearColor[1], kClearColor[2], 255, 1);
1664 ASSERT_GL_NO_ERROR();
1665 }
1666
1667 // Test that clearing RGB8 attachments from a 2D texture array does not cause
1668 // VUID-VkImageMemoryBarrier-oldLayout-01197
TEST_P(ClearTestES3,TextureArrayRGB8)1669 TEST_P(ClearTestES3, TextureArrayRGB8)
1670 {
1671 GLFramebuffer fb;
1672 glBindFramebuffer(GL_FRAMEBUFFER, fb);
1673
1674 GLTexture tex;
1675 glBindTexture(GL_TEXTURE_2D_ARRAY, tex);
1676 glTexStorage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGB8, 1, 1, 2);
1677 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1678 glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1679
1680 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, tex, 0, 0);
1681 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, tex, 0, 1);
1682
1683 ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER);
1684
1685 GLenum bufs[2] = {GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1};
1686 glDrawBuffers(2, &bufs[0]);
1687
1688 glClearColor(1.0, 0.0, 1.0, 1.0);
1689 glClear(GL_COLOR_BUFFER_BIT);
1690 ASSERT_GL_NO_ERROR();
1691
1692 glBindFramebuffer(GL_READ_FRAMEBUFFER, fb);
1693
1694 glReadBuffer(GL_COLOR_ATTACHMENT0);
1695 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::magenta);
1696
1697 glReadBuffer(GL_COLOR_ATTACHMENT1);
1698 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::magenta);
1699
1700 EXPECT_GL_NO_ERROR();
1701 }
1702
maskedScissoredColorDepthStencilClear(const MaskedScissoredClearVariationsTestParams & params)1703 void MaskedScissoredClearTestBase::maskedScissoredColorDepthStencilClear(
1704 const MaskedScissoredClearVariationsTestParams ¶ms)
1705 {
1706 // Flaky on Android Nexus 5x and Pixel 2, possible Qualcomm driver bug.
1707 // TODO(jmadill): Re-enable when possible. http://anglebug.com/2548
1708 ANGLE_SKIP_TEST_IF(IsOpenGLES() && IsAndroid());
1709
1710 const int w = getWindowWidth();
1711 const int h = getWindowHeight();
1712 const int wthird = w / 3;
1713 const int hthird = h / 3;
1714
1715 constexpr float kPreClearDepth = 0.9f;
1716 constexpr float kClearDepth = 0.5f;
1717 constexpr uint8_t kPreClearStencil = 0xFF;
1718 constexpr uint8_t kClearStencil = 0x16;
1719 constexpr uint8_t kStencilMask = 0x59;
1720 constexpr uint8_t kMaskedClearStencil =
1721 (kPreClearStencil & ~kStencilMask) | (kClearStencil & kStencilMask);
1722
1723 bool clearColor, clearDepth, clearStencil;
1724 bool maskColor, maskDepth, maskStencil;
1725 bool scissor;
1726
1727 ParseMaskedScissoredClearVariationsTestParams(params, &clearColor, &clearDepth, &clearStencil,
1728 &maskColor, &maskDepth, &maskStencil, &scissor);
1729
1730 // Clear to a random color, 0.9 depth and 0x00 stencil
1731 Vector4 color1(0.1f, 0.2f, 0.3f, 0.4f);
1732 GLColor color1RGB(color1);
1733
1734 glClearColor(color1[0], color1[1], color1[2], color1[3]);
1735 glClearDepthf(kPreClearDepth);
1736 glClearStencil(kPreClearStencil);
1737
1738 if (!clearColor)
1739 {
1740 // If not asked to clear color, clear it anyway, but individually. The clear value is
1741 // still used to verify that the depth/stencil clear happened correctly. This allows
1742 // testing for depth/stencil-only clear implementations.
1743 glClear(GL_COLOR_BUFFER_BIT);
1744 }
1745
1746 glClear((clearColor ? GL_COLOR_BUFFER_BIT : 0) | (clearDepth ? GL_DEPTH_BUFFER_BIT : 0) |
1747 (clearStencil ? GL_STENCIL_BUFFER_BIT : 0));
1748 ASSERT_GL_NO_ERROR();
1749
1750 // Verify color was cleared correctly.
1751 EXPECT_PIXEL_COLOR_NEAR(0, 0, color1RGB, 1);
1752
1753 if (scissor)
1754 {
1755 glEnable(GL_SCISSOR_TEST);
1756 glScissor(wthird / 2, hthird / 2, wthird, hthird);
1757 }
1758
1759 // Use color and stencil masks to clear to a second color, 0.5 depth and 0x59 stencil.
1760 Vector4 color2(0.2f, 0.4f, 0.6f, 0.8f);
1761 GLColor color2RGB(color2);
1762 glClearColor(color2[0], color2[1], color2[2], color2[3]);
1763 glClearDepthf(kClearDepth);
1764 glClearStencil(kClearStencil);
1765 if (maskColor)
1766 {
1767 glColorMask(GL_TRUE, GL_FALSE, GL_TRUE, GL_FALSE);
1768 }
1769 if (maskDepth)
1770 {
1771 glDepthMask(GL_FALSE);
1772 }
1773 if (maskStencil)
1774 {
1775 glStencilMask(kStencilMask);
1776 }
1777 glClear((clearColor ? GL_COLOR_BUFFER_BIT : 0) | (clearDepth ? GL_DEPTH_BUFFER_BIT : 0) |
1778 (clearStencil ? GL_STENCIL_BUFFER_BIT : 0));
1779 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
1780 glDepthMask(GL_TRUE);
1781 glStencilMask(0xFF);
1782 glDisable(GL_DEPTH_TEST);
1783 glDisable(GL_STENCIL_TEST);
1784 glDisable(GL_SCISSOR_TEST);
1785 ASSERT_GL_NO_ERROR();
1786
1787 GLColor color2MaskedRGB(color2RGB[0], color1RGB[1], color2RGB[2], color1RGB[3]);
1788
1789 // If not clearing color, the original color should be left both in the center and corners. If
1790 // using a scissor, the corners should be left to the original color, while the center is
1791 // possibly changed. If using a mask, the center (and corners if not scissored), changes to
1792 // the masked results.
1793 GLColor expectedCenterColorRGB = !clearColor ? color1RGB
1794 : maskColor ? color2MaskedRGB
1795 : color2RGB;
1796 GLColor expectedCornerColorRGB = scissor ? color1RGB : expectedCenterColorRGB;
1797
1798 // Verify second clear color mask worked as expected.
1799 EXPECT_PIXEL_COLOR_NEAR(wthird, hthird, expectedCenterColorRGB, 1);
1800
1801 EXPECT_PIXEL_COLOR_NEAR(0, 0, expectedCornerColorRGB, 1);
1802 EXPECT_PIXEL_COLOR_NEAR(w - 1, 0, expectedCornerColorRGB, 1);
1803 EXPECT_PIXEL_COLOR_NEAR(0, h - 1, expectedCornerColorRGB, 1);
1804 EXPECT_PIXEL_COLOR_NEAR(w - 1, h - 1, expectedCornerColorRGB, 1);
1805 EXPECT_PIXEL_COLOR_NEAR(wthird, 2 * hthird, expectedCornerColorRGB, 1);
1806 EXPECT_PIXEL_COLOR_NEAR(2 * wthird, hthird, expectedCornerColorRGB, 1);
1807 EXPECT_PIXEL_COLOR_NEAR(2 * wthird, 2 * hthird, expectedCornerColorRGB, 1);
1808
1809 // If there is depth, but depth is not asked to be cleared, the depth buffer contains garbage,
1810 // so no particular behavior can be expected.
1811 if (clearDepth || !mHasDepth)
1812 {
1813 // We use a small shader to verify depth.
1814 ANGLE_GL_PROGRAM(depthTestProgram, essl1_shaders::vs::Passthrough(),
1815 essl1_shaders::fs::Blue());
1816 glEnable(GL_DEPTH_TEST);
1817 glDepthFunc(maskDepth ? GL_GREATER : GL_EQUAL);
1818 // - If depth is cleared, but it's masked, kPreClearDepth should be in the depth buffer.
1819 // - If depth is cleared, but it's not masked, kClearDepth should be in the depth buffer.
1820 // - If depth is not cleared, the if above ensures there is no depth buffer at all,
1821 // which means depth test will always pass.
1822 drawQuad(depthTestProgram, essl1_shaders::PositionAttrib(), maskDepth ? 1.0f : 0.0f);
1823 glDisable(GL_DEPTH_TEST);
1824 ASSERT_GL_NO_ERROR();
1825
1826 // Either way, we expect blue to be written to the center.
1827 expectedCenterColorRGB = GLColor::blue;
1828 // If there is no depth, depth test always passes so the whole image must be blue. Same if
1829 // depth write is masked.
1830 expectedCornerColorRGB =
1831 mHasDepth && scissor && !maskDepth ? expectedCornerColorRGB : GLColor::blue;
1832
1833 EXPECT_PIXEL_COLOR_NEAR(wthird, hthird, expectedCenterColorRGB, 1);
1834
1835 EXPECT_PIXEL_COLOR_NEAR(0, 0, expectedCornerColorRGB, 1);
1836 EXPECT_PIXEL_COLOR_NEAR(w - 1, 0, expectedCornerColorRGB, 1);
1837 EXPECT_PIXEL_COLOR_NEAR(0, h - 1, expectedCornerColorRGB, 1);
1838 EXPECT_PIXEL_COLOR_NEAR(w - 1, h - 1, expectedCornerColorRGB, 1);
1839 EXPECT_PIXEL_COLOR_NEAR(wthird, 2 * hthird, expectedCornerColorRGB, 1);
1840 EXPECT_PIXEL_COLOR_NEAR(2 * wthird, hthird, expectedCornerColorRGB, 1);
1841 EXPECT_PIXEL_COLOR_NEAR(2 * wthird, 2 * hthird, expectedCornerColorRGB, 1);
1842 }
1843
1844 // If there is stencil, but it's not asked to be cleared, there is similarly no expectation.
1845 if (clearStencil || !mHasStencil)
1846 {
1847 // And another small shader to verify stencil.
1848 ANGLE_GL_PROGRAM(stencilTestProgram, essl1_shaders::vs::Passthrough(),
1849 essl1_shaders::fs::Green());
1850 glEnable(GL_STENCIL_TEST);
1851 // - If stencil is cleared, but it's masked, kMaskedClearStencil should be in the stencil
1852 // buffer.
1853 // - If stencil is cleared, but it's not masked, kClearStencil should be in the stencil
1854 // buffer.
1855 // - If stencil is not cleared, the if above ensures there is no stencil buffer at all,
1856 // which means stencil test will always pass.
1857 glStencilFunc(GL_EQUAL, maskStencil ? kMaskedClearStencil : kClearStencil, 0xFF);
1858 drawQuad(stencilTestProgram, essl1_shaders::PositionAttrib(), 0.0f);
1859 glDisable(GL_STENCIL_TEST);
1860 ASSERT_GL_NO_ERROR();
1861
1862 // Either way, we expect green to be written to the center.
1863 expectedCenterColorRGB = GLColor::green;
1864 // If there is no stencil, stencil test always passes so the whole image must be green.
1865 expectedCornerColorRGB = mHasStencil && scissor ? expectedCornerColorRGB : GLColor::green;
1866
1867 EXPECT_PIXEL_COLOR_NEAR(wthird, hthird, expectedCenterColorRGB, 1);
1868
1869 EXPECT_PIXEL_COLOR_NEAR(0, 0, expectedCornerColorRGB, 1);
1870 EXPECT_PIXEL_COLOR_NEAR(w - 1, 0, expectedCornerColorRGB, 1);
1871 EXPECT_PIXEL_COLOR_NEAR(0, h - 1, expectedCornerColorRGB, 1);
1872 EXPECT_PIXEL_COLOR_NEAR(w - 1, h - 1, expectedCornerColorRGB, 1);
1873 EXPECT_PIXEL_COLOR_NEAR(wthird, 2 * hthird, expectedCornerColorRGB, 1);
1874 EXPECT_PIXEL_COLOR_NEAR(2 * wthird, hthird, expectedCornerColorRGB, 1);
1875 EXPECT_PIXEL_COLOR_NEAR(2 * wthird, 2 * hthird, expectedCornerColorRGB, 1);
1876 }
1877 }
1878
1879 // Tests combinations of color, depth, stencil clears with or without masks or scissor.
TEST_P(MaskedScissoredClearTest,Test)1880 TEST_P(MaskedScissoredClearTest, Test)
1881 {
1882 maskedScissoredColorDepthStencilClear(GetParam());
1883 }
1884
1885 // Tests combinations of color, depth, stencil clears with or without masks or scissor.
1886 //
1887 // This uses depth/stencil attachments that are single-channel, but are emulated with a format
1888 // that has both channels.
TEST_P(VulkanClearTest,Test)1889 TEST_P(VulkanClearTest, Test)
1890 {
1891 bool clearColor, clearDepth, clearStencil;
1892 bool maskColor, maskDepth, maskStencil;
1893 bool scissor;
1894
1895 ParseMaskedScissoredClearVariationsTestParams(GetParam(), &clearColor, &clearDepth,
1896 &clearStencil, &maskColor, &maskDepth,
1897 &maskStencil, &scissor);
1898
1899 // We only care about clearing depth xor stencil.
1900 if (clearDepth == clearStencil)
1901 {
1902 return;
1903 }
1904
1905 if (clearDepth)
1906 {
1907 // Creating a depth-only renderbuffer is an ES3 feature.
1908 ANGLE_SKIP_TEST_IF(getClientMajorVersion() < 3);
1909 bindColorDepthFBO();
1910 }
1911 else
1912 {
1913 bindColorStencilFBO();
1914 }
1915
1916 maskedScissoredColorDepthStencilClear(GetParam());
1917 }
1918
1919 // Tests that clearing a non existing attachment works.
TEST_P(ClearTest,ClearColorThenClearNonExistingDepthStencil)1920 TEST_P(ClearTest, ClearColorThenClearNonExistingDepthStencil)
1921 {
1922 constexpr GLsizei kSize = 16;
1923
1924 GLTexture color;
1925 glBindTexture(GL_TEXTURE_2D, color);
1926 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1927
1928 GLFramebuffer fbo;
1929 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
1930 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, color, 0);
1931 ASSERT_GL_NO_ERROR();
1932 ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER);
1933
1934 // Clear color.
1935 glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
1936 glClear(GL_COLOR_BUFFER_BIT);
1937
1938 // Clear depth/stencil.
1939 glClear(GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
1940 ASSERT_GL_NO_ERROR();
1941
1942 // Read back color.
1943 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
1944 }
1945
1946 // Tests that clearing a non existing attachment works.
TEST_P(ClearTestES3,ClearDepthStencilThenClearNonExistingColor)1947 TEST_P(ClearTestES3, ClearDepthStencilThenClearNonExistingColor)
1948 {
1949 constexpr GLsizei kSize = 16;
1950
1951 GLRenderbuffer depth;
1952 glBindRenderbuffer(GL_RENDERBUFFER, depth);
1953 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, kSize, kSize);
1954
1955 GLFramebuffer fbo;
1956 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
1957 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, depth);
1958 ASSERT_GL_NO_ERROR();
1959 ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER);
1960
1961 // Clear depth/stencil.
1962 glClearDepthf(1.0f);
1963 glClearStencil(0xAA);
1964 glClear(GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
1965 ASSERT_GL_NO_ERROR();
1966
1967 // Clear color.
1968 glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
1969 glClear(GL_COLOR_BUFFER_BIT);
1970 ASSERT_GL_NO_ERROR();
1971 }
1972
1973 // Test that just clearing a nonexistent drawbuffer of the default framebuffer doesn't cause an
1974 // assert.
TEST_P(ClearTestES3,ClearBuffer1OnDefaultFramebufferNoAssert)1975 TEST_P(ClearTestES3, ClearBuffer1OnDefaultFramebufferNoAssert)
1976 {
1977 std::vector<GLuint> testUint(4);
1978 glClearBufferuiv(GL_COLOR, 1, testUint.data());
1979 std::vector<GLint> testInt(4);
1980 glClearBufferiv(GL_COLOR, 1, testInt.data());
1981 std::vector<GLfloat> testFloat(4);
1982 glClearBufferfv(GL_COLOR, 1, testFloat.data());
1983 EXPECT_GL_NO_ERROR();
1984 }
1985
1986 // Clears many small concentric rectangles using scissor regions.
TEST_P(ClearTest,InceptionScissorClears)1987 TEST_P(ClearTest, InceptionScissorClears)
1988 {
1989 angle::RNG rng;
1990
1991 constexpr GLuint kSize = 16;
1992
1993 // Create a square user FBO so we have more control over the dimensions.
1994 GLFramebuffer fbo;
1995 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
1996
1997 GLRenderbuffer rbo;
1998 glBindRenderbuffer(GL_RENDERBUFFER, rbo);
1999 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, kSize, kSize);
2000
2001 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rbo);
2002 ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER);
2003
2004 glViewport(0, 0, kSize, kSize);
2005
2006 // Draw small concentric squares using scissor.
2007 std::vector<GLColor> expectedColors;
2008 for (GLuint index = 0; index < (kSize - 1) / 2; index++)
2009 {
2010 // Do the first clear without the scissor.
2011 if (index > 0)
2012 {
2013 glEnable(GL_SCISSOR_TEST);
2014 glScissor(index, index, kSize - (index * 2), kSize - (index * 2));
2015 }
2016
2017 GLColor color = RandomColor(&rng);
2018 expectedColors.push_back(color);
2019 Vector4 floatColor = color.toNormalizedVector();
2020 glClearColor(floatColor[0], floatColor[1], floatColor[2], floatColor[3]);
2021 glClear(GL_COLOR_BUFFER_BIT);
2022 }
2023
2024 ASSERT_GL_NO_ERROR();
2025
2026 std::vector<GLColor> actualColors(expectedColors.size());
2027 glReadPixels(0, kSize / 2, actualColors.size(), 1, GL_RGBA, GL_UNSIGNED_BYTE,
2028 actualColors.data());
2029
2030 EXPECT_EQ(expectedColors, actualColors);
2031 }
2032
2033 // Clears many small concentric rectangles using scissor regions.
TEST_P(ClearTest,DrawThenInceptionScissorClears)2034 TEST_P(ClearTest, DrawThenInceptionScissorClears)
2035 {
2036 angle::RNG rng;
2037
2038 constexpr GLuint kSize = 16;
2039
2040 // Create a square user FBO so we have more control over the dimensions.
2041 GLFramebuffer fbo;
2042 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
2043
2044 GLRenderbuffer rbo;
2045 glBindRenderbuffer(GL_RENDERBUFFER, rbo);
2046 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, kSize, kSize);
2047
2048 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rbo);
2049 ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER);
2050
2051 glViewport(0, 0, kSize, kSize);
2052
2053 ANGLE_GL_PROGRAM(redProgram, essl1_shaders::vs::Simple(), essl1_shaders::fs::Red());
2054 drawQuad(redProgram, essl1_shaders::PositionAttrib(), 0.5f);
2055 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
2056
2057 // Draw small concentric squares using scissor.
2058 std::vector<GLColor> expectedColors;
2059 for (GLuint index = 0; index < (kSize - 1) / 2; index++)
2060 {
2061 // Do the first clear without the scissor.
2062 if (index > 0)
2063 {
2064 glEnable(GL_SCISSOR_TEST);
2065 glScissor(index, index, kSize - (index * 2), kSize - (index * 2));
2066 }
2067
2068 GLColor color = RandomColor(&rng);
2069 expectedColors.push_back(color);
2070 Vector4 floatColor = color.toNormalizedVector();
2071 glClearColor(floatColor[0], floatColor[1], floatColor[2], floatColor[3]);
2072 glClear(GL_COLOR_BUFFER_BIT);
2073 }
2074
2075 ASSERT_GL_NO_ERROR();
2076
2077 std::vector<GLColor> actualColors(expectedColors.size());
2078 glReadPixels(0, kSize / 2, actualColors.size(), 1, GL_RGBA, GL_UNSIGNED_BYTE,
2079 actualColors.data());
2080
2081 EXPECT_EQ(expectedColors, actualColors);
2082 }
2083
2084 // Test that clearBuffer with disabled non-zero drawbuffer or disabled read source doesn't cause an
2085 // assert.
TEST_P(ClearTestES3,ClearDisabledNonZeroAttachmentNoAssert)2086 TEST_P(ClearTestES3, ClearDisabledNonZeroAttachmentNoAssert)
2087 {
2088 // http://anglebug.com/4612
2089 ANGLE_SKIP_TEST_IF(IsMac() && IsDesktopOpenGL());
2090
2091 GLFramebuffer fb;
2092 glBindFramebuffer(GL_FRAMEBUFFER, fb);
2093
2094 GLRenderbuffer rb;
2095 glBindRenderbuffer(GL_RENDERBUFFER, rb);
2096 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, 16, 16);
2097
2098 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_RENDERBUFFER, rb);
2099 glDrawBuffers(0, nullptr);
2100 glReadBuffer(GL_NONE);
2101
2102 ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER);
2103
2104 float clearColorf[4] = {0.5, 0.5, 0.5, 0.5};
2105 glClearBufferfv(GL_COLOR, 1, clearColorf);
2106
2107 GLuint clearColorui[4] = {255, 255, 255, 255};
2108 glClearBufferuiv(GL_COLOR, 1, clearColorui);
2109
2110 GLint clearColori[4] = {-127, -127, -127, -127};
2111 glClearBufferiv(GL_COLOR, 1, clearColori);
2112
2113 EXPECT_GL_NO_ERROR();
2114 }
2115
2116 // Test that having a framebuffer with maximum number of attachments and clearing color, depth and
2117 // stencil works.
TEST_P(ClearTestES3,ClearMaxAttachments)2118 TEST_P(ClearTestES3, ClearMaxAttachments)
2119 {
2120 // http://anglebug.com/4612
2121 ANGLE_SKIP_TEST_IF(IsMac() && IsDesktopOpenGL());
2122 // http://anglebug.com/5397
2123 ANGLE_SKIP_TEST_IF(IsAMD() && IsD3D11());
2124
2125 constexpr GLsizei kSize = 16;
2126
2127 GLint maxDrawBuffers = 0;
2128 glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers);
2129 ASSERT_GE(maxDrawBuffers, 4);
2130
2131 // Setup framebuffer.
2132 GLFramebuffer fb;
2133 glBindFramebuffer(GL_FRAMEBUFFER, fb);
2134
2135 std::vector<GLRenderbuffer> color(maxDrawBuffers);
2136 std::vector<GLenum> drawBuffers(maxDrawBuffers);
2137
2138 for (GLint colorIndex = 0; colorIndex < maxDrawBuffers; ++colorIndex)
2139 {
2140 glBindRenderbuffer(GL_RENDERBUFFER, color[colorIndex]);
2141 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, kSize, kSize);
2142 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + colorIndex,
2143 GL_RENDERBUFFER, color[colorIndex]);
2144
2145 drawBuffers[colorIndex] = GL_COLOR_ATTACHMENT0 + colorIndex;
2146 }
2147
2148 GLRenderbuffer depthStencil;
2149 glBindRenderbuffer(GL_RENDERBUFFER, depthStencil);
2150 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, kSize, kSize);
2151 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
2152 depthStencil);
2153
2154 EXPECT_GL_NO_ERROR();
2155 ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER);
2156
2157 glDrawBuffers(maxDrawBuffers, drawBuffers.data());
2158
2159 glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
2160 glClearDepthf(1.0f);
2161 glClearStencil(0x55);
2162 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
2163 EXPECT_GL_NO_ERROR();
2164
2165 // Verify that every color attachment is cleared correctly.
2166 for (GLint colorIndex = 0; colorIndex < maxDrawBuffers; ++colorIndex)
2167 {
2168 glReadBuffer(GL_COLOR_ATTACHMENT0 + colorIndex);
2169
2170 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
2171 EXPECT_PIXEL_COLOR_EQ(0, kSize - 1, GLColor::red);
2172 EXPECT_PIXEL_COLOR_EQ(kSize - 1, 0, GLColor::red);
2173 EXPECT_PIXEL_COLOR_EQ(kSize - 1, kSize - 1, GLColor::red);
2174 }
2175
2176 // Verify that depth and stencil attachments are cleared correctly.
2177 GLFramebuffer fbVerify;
2178 glBindFramebuffer(GL_FRAMEBUFFER, fbVerify);
2179
2180 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, color[0]);
2181 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
2182 depthStencil);
2183
2184 // If depth is not cleared to 1, rendering would fail.
2185 glEnable(GL_DEPTH_TEST);
2186 glDepthFunc(GL_LESS);
2187
2188 // If stencil is not cleared to 0x55, rendering would fail.
2189 glEnable(GL_STENCIL_TEST);
2190 glStencilFunc(GL_EQUAL, 0x55, 0xFF);
2191 glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
2192 glStencilMask(0xFF);
2193
2194 // Draw green.
2195 ANGLE_GL_PROGRAM(drawGreen, essl1_shaders::vs::Simple(), essl1_shaders::fs::Green());
2196 drawQuad(drawGreen, essl1_shaders::PositionAttrib(), 0.95f);
2197
2198 // Verify that green was drawn.
2199 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2200 EXPECT_PIXEL_COLOR_EQ(0, kSize - 1, GLColor::green);
2201 EXPECT_PIXEL_COLOR_EQ(kSize - 1, 0, GLColor::green);
2202 EXPECT_PIXEL_COLOR_EQ(kSize - 1, kSize - 1, GLColor::green);
2203 }
2204
2205 // Test that having a framebuffer with maximum number of attachments and clearing color, depth and
2206 // stencil after a draw call works.
TEST_P(ClearTestES3,ClearMaxAttachmentsAfterDraw)2207 TEST_P(ClearTestES3, ClearMaxAttachmentsAfterDraw)
2208 {
2209 // http://anglebug.com/4612
2210 ANGLE_SKIP_TEST_IF(IsMac() && IsDesktopOpenGL());
2211
2212 constexpr GLsizei kSize = 16;
2213
2214 GLint maxDrawBuffers = 0;
2215 glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers);
2216 ASSERT_GE(maxDrawBuffers, 4);
2217
2218 // Setup framebuffer.
2219 GLFramebuffer fb;
2220 glBindFramebuffer(GL_FRAMEBUFFER, fb);
2221
2222 std::vector<GLRenderbuffer> color(maxDrawBuffers);
2223 std::vector<GLenum> drawBuffers(maxDrawBuffers);
2224
2225 for (GLint colorIndex = 0; colorIndex < maxDrawBuffers; ++colorIndex)
2226 {
2227 glBindRenderbuffer(GL_RENDERBUFFER, color[colorIndex]);
2228 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, kSize, kSize);
2229 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + colorIndex,
2230 GL_RENDERBUFFER, color[colorIndex]);
2231
2232 drawBuffers[colorIndex] = GL_COLOR_ATTACHMENT0 + colorIndex;
2233 }
2234
2235 GLRenderbuffer depthStencil;
2236 glBindRenderbuffer(GL_RENDERBUFFER, depthStencil);
2237 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, kSize, kSize);
2238 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
2239 depthStencil);
2240
2241 EXPECT_GL_NO_ERROR();
2242 ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER);
2243
2244 glDrawBuffers(maxDrawBuffers, drawBuffers.data());
2245
2246 // Issue a draw call to render blue, depth=0 and stencil 0x3C to the attachments.
2247 glEnable(GL_DEPTH_TEST);
2248 glDepthFunc(GL_ALWAYS);
2249
2250 glEnable(GL_STENCIL_TEST);
2251 glStencilFunc(GL_ALWAYS, 0x3C, 0xFF);
2252 glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
2253 glStencilMask(0xFF);
2254
2255 // Generate shader for this framebuffer.
2256 std::stringstream strstr;
2257 strstr << "#version 300 es\n"
2258 "precision highp float;\n";
2259 for (GLint colorIndex = 0; colorIndex < maxDrawBuffers; ++colorIndex)
2260 {
2261 strstr << "layout(location = " << colorIndex << ") out vec4 value" << colorIndex << ";\n";
2262 }
2263 strstr << "void main()\n"
2264 "{\n";
2265 for (GLint colorIndex = 0; colorIndex < maxDrawBuffers; ++colorIndex)
2266 {
2267 strstr << "value" << colorIndex << " = vec4(0.0f, 0.0f, 1.0f, 1.0f);\n";
2268 }
2269 strstr << "}\n";
2270
2271 ANGLE_GL_PROGRAM(drawMRT, essl3_shaders::vs::Simple(), strstr.str().c_str());
2272 drawQuad(drawMRT, essl3_shaders::PositionAttrib(), 0.0f);
2273 ASSERT_GL_NO_ERROR();
2274
2275 glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
2276 glClearDepthf(1.0f);
2277 glClearStencil(0x55);
2278 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
2279 EXPECT_GL_NO_ERROR();
2280
2281 // Verify that every color attachment is cleared correctly.
2282 for (GLint colorIndex = 0; colorIndex < maxDrawBuffers; ++colorIndex)
2283 {
2284 glReadBuffer(GL_COLOR_ATTACHMENT0 + colorIndex);
2285
2286 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red) << colorIndex;
2287 EXPECT_PIXEL_COLOR_EQ(0, kSize - 1, GLColor::red) << colorIndex;
2288 EXPECT_PIXEL_COLOR_EQ(kSize - 1, 0, GLColor::red) << colorIndex;
2289 EXPECT_PIXEL_COLOR_EQ(kSize - 1, kSize - 1, GLColor::red) << colorIndex;
2290 }
2291
2292 // Verify that depth and stencil attachments are cleared correctly.
2293 GLFramebuffer fbVerify;
2294 glBindFramebuffer(GL_FRAMEBUFFER, fbVerify);
2295
2296 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, color[0]);
2297 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
2298 depthStencil);
2299
2300 // If depth is not cleared to 1, rendering would fail.
2301 glDepthFunc(GL_LESS);
2302
2303 // If stencil is not cleared to 0x55, rendering would fail.
2304 glStencilFunc(GL_EQUAL, 0x55, 0xFF);
2305 glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
2306
2307 // Draw green.
2308 ANGLE_GL_PROGRAM(drawGreen, essl1_shaders::vs::Simple(), essl1_shaders::fs::Green());
2309 drawQuad(drawGreen, essl1_shaders::PositionAttrib(), 0.95f);
2310
2311 // Verify that green was drawn.
2312 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2313 EXPECT_PIXEL_COLOR_EQ(0, kSize - 1, GLColor::green);
2314 EXPECT_PIXEL_COLOR_EQ(kSize - 1, 0, GLColor::green);
2315 EXPECT_PIXEL_COLOR_EQ(kSize - 1, kSize - 1, GLColor::green);
2316 }
2317
2318 // Test that mixed masked clear works after clear.
TEST_P(ClearTestES3,ClearThenMixedMaskedClear)2319 TEST_P(ClearTestES3, ClearThenMixedMaskedClear)
2320 {
2321 constexpr GLsizei kSize = 16;
2322
2323 // Setup framebuffer.
2324 GLRenderbuffer color;
2325 glBindRenderbuffer(GL_RENDERBUFFER, color);
2326 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, kSize, kSize);
2327
2328 GLRenderbuffer depthStencil;
2329 glBindRenderbuffer(GL_RENDERBUFFER, depthStencil);
2330 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, kSize, kSize);
2331
2332 GLFramebuffer fb;
2333 glBindFramebuffer(GL_FRAMEBUFFER, fb);
2334 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, color);
2335 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
2336 depthStencil);
2337 EXPECT_GL_NO_ERROR();
2338 ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER);
2339
2340 // Clear color and depth/stencil
2341 glClearColor(0.1f, 1.0f, 0.0f, 0.7f);
2342 glClearDepthf(0.0f);
2343 glClearStencil(0x55);
2344 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
2345
2346 // Clear again, but with color and stencil masked
2347 glClearColor(1.0f, 0.2f, 0.6f, 1.0f);
2348 glClearDepthf(1.0f);
2349 glClearStencil(0x3C);
2350 glColorMask(GL_TRUE, GL_FALSE, GL_FALSE, GL_TRUE);
2351 glStencilMask(0xF0);
2352 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
2353
2354 // Issue a draw call to verify color, depth and stencil.
2355
2356 // If depth is not cleared to 1, rendering would fail.
2357 glEnable(GL_DEPTH_TEST);
2358 glDepthFunc(GL_LESS);
2359
2360 // If stencil is not cleared to 0x35, rendering would fail.
2361 glEnable(GL_STENCIL_TEST);
2362 glStencilFunc(GL_EQUAL, 0x35, 0xFF);
2363 glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
2364 glStencilMask(0xFF);
2365 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
2366
2367 ANGLE_GL_PROGRAM(drawColor, essl1_shaders::vs::Simple(), essl1_shaders::fs::UniformColor());
2368 glUseProgram(drawColor);
2369 GLint colorUniformLocation =
2370 glGetUniformLocation(drawColor, angle::essl1_shaders::ColorUniform());
2371 ASSERT_NE(colorUniformLocation, -1);
2372
2373 // Blend half-transparent blue into the color buffer.
2374 glUniform4f(colorUniformLocation, 0.0f, 0.0f, 1.0f, 0.5f);
2375 glEnable(GL_BLEND);
2376 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
2377 drawQuad(drawColor, essl1_shaders::PositionAttrib(), 0.95f);
2378 ASSERT_GL_NO_ERROR();
2379
2380 // Verify that the color buffer is now gray
2381 const GLColor kExpected(127, 127, 127, 191);
2382 EXPECT_PIXEL_COLOR_NEAR(0, 0, kExpected, 1);
2383 EXPECT_PIXEL_COLOR_NEAR(0, kSize - 1, kExpected, 1);
2384 EXPECT_PIXEL_COLOR_NEAR(kSize - 1, 0, kExpected, 1);
2385 EXPECT_PIXEL_COLOR_NEAR(kSize - 1, kSize - 1, kExpected, 1);
2386 }
2387
2388 // Test that clearing stencil after a draw call works.
TEST_P(ClearTestES3,ClearStencilAfterDraw)2389 TEST_P(ClearTestES3, ClearStencilAfterDraw)
2390 {
2391 // http://anglebug.com/4612
2392 ANGLE_SKIP_TEST_IF(IsMac() && IsDesktopOpenGL());
2393
2394 constexpr GLsizei kSize = 16;
2395
2396 GLint maxDrawBuffers = 0;
2397 glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers);
2398 ASSERT_GE(maxDrawBuffers, 4);
2399
2400 // Setup framebuffer.
2401 GLFramebuffer fb;
2402 glBindFramebuffer(GL_FRAMEBUFFER, fb);
2403
2404 std::vector<GLRenderbuffer> color(maxDrawBuffers);
2405 std::vector<GLenum> drawBuffers(maxDrawBuffers);
2406
2407 for (GLint colorIndex = 0; colorIndex < maxDrawBuffers; ++colorIndex)
2408 {
2409 glBindRenderbuffer(GL_RENDERBUFFER, color[colorIndex]);
2410 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, kSize, kSize);
2411 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + colorIndex,
2412 GL_RENDERBUFFER, color[colorIndex]);
2413
2414 drawBuffers[colorIndex] = GL_COLOR_ATTACHMENT0 + colorIndex;
2415 }
2416
2417 GLRenderbuffer depthStencil;
2418 glBindRenderbuffer(GL_RENDERBUFFER, depthStencil);
2419 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, kSize, kSize);
2420 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
2421 depthStencil);
2422
2423 EXPECT_GL_NO_ERROR();
2424 ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER);
2425
2426 glDrawBuffers(maxDrawBuffers, drawBuffers.data());
2427
2428 // Issue a draw call to render blue and stencil 0x3C to the attachments.
2429 glEnable(GL_STENCIL_TEST);
2430 glStencilFunc(GL_ALWAYS, 0x3C, 0xFF);
2431 glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
2432 glStencilMask(0xFF);
2433
2434 // Generate shader for this framebuffer.
2435 std::stringstream strstr;
2436 strstr << "#version 300 es\n"
2437 "precision highp float;\n";
2438 for (GLint colorIndex = 0; colorIndex < maxDrawBuffers; ++colorIndex)
2439 {
2440 strstr << "layout(location = " << colorIndex << ") out vec4 value" << colorIndex << ";\n";
2441 }
2442 strstr << "void main()\n"
2443 "{\n";
2444 for (GLint colorIndex = 0; colorIndex < maxDrawBuffers; ++colorIndex)
2445 {
2446 strstr << "value" << colorIndex << " = vec4(0.0f, 0.0f, 1.0f, 1.0f);\n";
2447 }
2448 strstr << "}\n";
2449
2450 ANGLE_GL_PROGRAM(drawMRT, essl3_shaders::vs::Simple(), strstr.str().c_str());
2451 drawQuad(drawMRT, essl3_shaders::PositionAttrib(), 0.0f);
2452 ASSERT_GL_NO_ERROR();
2453
2454 glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
2455 glClearStencil(0x55);
2456 glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
2457 EXPECT_GL_NO_ERROR();
2458
2459 // Verify that every color attachment is cleared correctly.
2460 for (GLint colorIndex = 0; colorIndex < maxDrawBuffers; ++colorIndex)
2461 {
2462 glReadBuffer(GL_COLOR_ATTACHMENT0 + colorIndex);
2463
2464 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
2465 EXPECT_PIXEL_COLOR_EQ(0, kSize - 1, GLColor::red);
2466 EXPECT_PIXEL_COLOR_EQ(kSize - 1, 0, GLColor::red);
2467 EXPECT_PIXEL_COLOR_EQ(kSize - 1, kSize - 1, GLColor::red);
2468 }
2469
2470 // Verify that depth and stencil attachments are cleared correctly.
2471 GLFramebuffer fbVerify;
2472 glBindFramebuffer(GL_FRAMEBUFFER, fbVerify);
2473
2474 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, color[0]);
2475 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
2476 depthStencil);
2477
2478 // If stencil is not cleared to 0x55, rendering would fail.
2479 glStencilFunc(GL_EQUAL, 0x55, 0xFF);
2480 glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
2481
2482 // Draw green.
2483 ANGLE_GL_PROGRAM(drawGreen, essl1_shaders::vs::Simple(), essl1_shaders::fs::Green());
2484 drawQuad(drawGreen, essl1_shaders::PositionAttrib(), 0.95f);
2485
2486 // Verify that green was drawn.
2487 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2488 EXPECT_PIXEL_COLOR_EQ(0, kSize - 1, GLColor::green);
2489 EXPECT_PIXEL_COLOR_EQ(kSize - 1, 0, GLColor::green);
2490 EXPECT_PIXEL_COLOR_EQ(kSize - 1, kSize - 1, GLColor::green);
2491 }
2492
2493 // Test that mid-render pass clearing of mixed used and unused color attachments works.
TEST_P(ClearTestES3,MixedRenderPassClearMixedUsedUnusedAttachments)2494 TEST_P(ClearTestES3, MixedRenderPassClearMixedUsedUnusedAttachments)
2495 {
2496 // http://anglebug.com/4612
2497 ANGLE_SKIP_TEST_IF(IsMac() && IsDesktopOpenGL());
2498
2499 constexpr GLsizei kSize = 16;
2500
2501 // Setup framebuffer.
2502 GLFramebuffer fb;
2503 glBindFramebuffer(GL_FRAMEBUFFER, fb);
2504
2505 GLRenderbuffer color[2];
2506
2507 for (GLint colorIndex = 0; colorIndex < 2; ++colorIndex)
2508 {
2509 glBindRenderbuffer(GL_RENDERBUFFER, color[colorIndex]);
2510 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, kSize, kSize);
2511 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + colorIndex,
2512 GL_RENDERBUFFER, color[colorIndex]);
2513 }
2514 EXPECT_GL_NO_ERROR();
2515 ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER);
2516
2517 // Disable color attachment 0.
2518 GLenum drawBuffers[] = {GL_NONE, GL_COLOR_ATTACHMENT1};
2519 glDrawBuffers(2, drawBuffers);
2520
2521 // Draw into color attachment 1
2522 constexpr char kFS[] = R"(#version 300 es
2523 precision highp float;
2524 layout(location = 0) out vec4 color0;
2525 layout(location = 1) out vec4 color1;
2526 void main()
2527 {
2528 color0 = vec4(0, 0, 1, 1);
2529 color1 = vec4(1, 0, 0, 1);
2530 })";
2531
2532 ANGLE_GL_PROGRAM(drawMRT, essl3_shaders::vs::Simple(), kFS);
2533 drawQuad(drawMRT, essl3_shaders::PositionAttrib(), 0.0f);
2534 ASSERT_GL_NO_ERROR();
2535
2536 // Color attachment 0 is now uninitialized, while color attachment 1 is red.
2537 // Re-enable color attachment 0 and clear both attachments to green.
2538 drawBuffers[0] = GL_COLOR_ATTACHMENT0;
2539 glDrawBuffers(2, drawBuffers);
2540
2541 glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
2542 glClear(GL_COLOR_BUFFER_BIT);
2543 EXPECT_GL_NO_ERROR();
2544
2545 // Verify that both color attachments are now green.
2546 glReadBuffer(GL_COLOR_ATTACHMENT0);
2547 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2548 glReadBuffer(GL_COLOR_ATTACHMENT1);
2549 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2550 EXPECT_GL_NO_ERROR();
2551 }
2552
2553 // Test that draw without state change after masked clear works
TEST_P(ClearTestES3,DrawClearThenDrawWithoutStateChange)2554 TEST_P(ClearTestES3, DrawClearThenDrawWithoutStateChange)
2555 {
2556 swapBuffers();
2557 constexpr GLsizei kSize = 16;
2558
2559 // Setup framebuffer.
2560 GLRenderbuffer color;
2561 glBindRenderbuffer(GL_RENDERBUFFER, color);
2562 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, kSize, kSize);
2563
2564 GLFramebuffer fb;
2565 glBindFramebuffer(GL_FRAMEBUFFER, fb);
2566 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, color);
2567 EXPECT_GL_NO_ERROR();
2568 ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER);
2569
2570 // Clear color initially.
2571 glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
2572 glClear(GL_COLOR_BUFFER_BIT);
2573
2574 // Mask color.
2575 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE);
2576
2577 ANGLE_GL_PROGRAM(drawColor, essl1_shaders::vs::Simple(), essl1_shaders::fs::UniformColor());
2578 glUseProgram(drawColor);
2579 GLint colorUniformLocation =
2580 glGetUniformLocation(drawColor, angle::essl1_shaders::ColorUniform());
2581 ASSERT_NE(colorUniformLocation, -1);
2582
2583 // Initialize position attribute.
2584 GLint posLoc = glGetAttribLocation(drawColor, essl1_shaders::PositionAttrib());
2585 ASSERT_NE(-1, posLoc);
2586 setupQuadVertexBuffer(0.5f, 1.0f);
2587 glVertexAttribPointer(posLoc, 3, GL_FLOAT, GL_FALSE, 0, nullptr);
2588 glEnableVertexAttribArray(posLoc);
2589
2590 // Draw red.
2591 glViewport(0, 0, kSize, kSize);
2592 glClearColor(0.0f, 1.0f, 0.0f, 0.0f);
2593 glUniform4f(colorUniformLocation, 1.0f, 0.0f, 0.0f, 0.5f);
2594 glDrawArrays(GL_TRIANGLES, 0, 6);
2595
2596 // Clear to green without any state change.
2597 glClear(GL_COLOR_BUFFER_BIT);
2598
2599 // Draw red again without any state change.
2600 glDrawArrays(GL_TRIANGLES, 0, 6);
2601
2602 // Verify that the color buffer is now red
2603 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
2604 EXPECT_PIXEL_COLOR_EQ(0, kSize - 1, GLColor::red);
2605 EXPECT_PIXEL_COLOR_EQ(kSize - 1, 0, GLColor::red);
2606 EXPECT_PIXEL_COLOR_EQ(kSize - 1, kSize - 1, GLColor::red);
2607 }
2608
2609 // Test that clear stencil value is correctly masked to 8 bits.
TEST_P(ClearTest,ClearStencilMask)2610 TEST_P(ClearTest, ClearStencilMask)
2611 {
2612 GLint stencilBits = 0;
2613 glGetIntegerv(GL_STENCIL_BITS, &stencilBits);
2614 EXPECT_EQ(stencilBits, 8);
2615
2616 ANGLE_GL_PROGRAM(drawColor, essl1_shaders::vs::Simple(), essl1_shaders::fs::Green());
2617 glUseProgram(drawColor);
2618
2619 glClearColor(0, 0, 0, 1);
2620 glClear(GL_COLOR_BUFFER_BIT);
2621 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2622
2623 // Clear stencil value must be masked to 0x42
2624 glClearStencil(0x142);
2625 glClear(GL_STENCIL_BUFFER_BIT);
2626
2627 // Check that the stencil test works as expected
2628 glEnable(GL_STENCIL_TEST);
2629
2630 // Negative case
2631 glStencilFunc(GL_NOTEQUAL, 0x42, 0xFF);
2632 drawQuad(drawColor, essl1_shaders::PositionAttrib(), 0.5f);
2633 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2634
2635 // Positive case
2636 glStencilFunc(GL_EQUAL, 0x42, 0xFF);
2637 drawQuad(drawColor, essl1_shaders::PositionAttrib(), 0.5f);
2638 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2639
2640 ASSERT_GL_NO_ERROR();
2641 }
2642
2643 // Test that glClearBufferiv correctly masks the clear stencil value.
TEST_P(ClearTestES3,ClearBufferivStencilMask)2644 TEST_P(ClearTestES3, ClearBufferivStencilMask)
2645 {
2646 GLint stencilBits = 0;
2647 glGetIntegerv(GL_STENCIL_BITS, &stencilBits);
2648 EXPECT_EQ(stencilBits, 8);
2649
2650 ANGLE_GL_PROGRAM(drawColor, essl1_shaders::vs::Simple(), essl1_shaders::fs::Green());
2651 glUseProgram(drawColor);
2652
2653 glClearColor(0, 0, 0, 1);
2654 glClear(GL_COLOR_BUFFER_BIT);
2655 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2656
2657 // Clear stencil value must be masked to 0x42
2658 const GLint kStencilClearValue = 0x142;
2659 glClearBufferiv(GL_STENCIL, 0, &kStencilClearValue);
2660
2661 // Check that the stencil test works as expected
2662 glEnable(GL_STENCIL_TEST);
2663
2664 // Negative case
2665 glStencilFunc(GL_NOTEQUAL, 0x42, 0xFF);
2666 drawQuad(drawColor, essl1_shaders::PositionAttrib(), 0.5f);
2667 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2668
2669 // Positive case
2670 glStencilFunc(GL_EQUAL, 0x42, 0xFF);
2671 drawQuad(drawColor, essl1_shaders::PositionAttrib(), 0.5f);
2672 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2673
2674 ASSERT_GL_NO_ERROR();
2675 }
2676
2677 // Test that glClearBufferfi correctly masks the clear stencil value.
TEST_P(ClearTestES3,ClearBufferfiStencilMask)2678 TEST_P(ClearTestES3, ClearBufferfiStencilMask)
2679 {
2680 GLint stencilBits = 0;
2681 glGetIntegerv(GL_STENCIL_BITS, &stencilBits);
2682 EXPECT_EQ(stencilBits, 8);
2683
2684 ANGLE_GL_PROGRAM(drawColor, essl1_shaders::vs::Simple(), essl1_shaders::fs::Green());
2685 glUseProgram(drawColor);
2686
2687 glClearColor(0, 0, 0, 1);
2688 glClear(GL_COLOR_BUFFER_BIT);
2689 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2690
2691 // Clear stencil value must be masked to 0x42
2692 glClearBufferfi(GL_DEPTH_STENCIL, 0, 0.5f, 0x142);
2693
2694 // Check that the stencil test works as expected
2695 glEnable(GL_STENCIL_TEST);
2696
2697 // Negative case
2698 glStencilFunc(GL_NOTEQUAL, 0x42, 0xFF);
2699 drawQuad(drawColor, essl1_shaders::PositionAttrib(), 0.5f);
2700 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2701
2702 // Positive case
2703 glStencilFunc(GL_EQUAL, 0x42, 0xFF);
2704 drawQuad(drawColor, essl1_shaders::PositionAttrib(), 0.5f);
2705 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2706
2707 ASSERT_GL_NO_ERROR();
2708 }
2709
2710 // Test that glClearBufferfi works when stencil attachment is not present.
TEST_P(ClearTestES3,ClearBufferfiNoStencilAttachment)2711 TEST_P(ClearTestES3, ClearBufferfiNoStencilAttachment)
2712 {
2713 constexpr GLsizei kSize = 16;
2714
2715 GLRenderbuffer color;
2716 glBindRenderbuffer(GL_RENDERBUFFER, color);
2717 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, kSize, kSize);
2718
2719 GLRenderbuffer depth;
2720 glBindRenderbuffer(GL_RENDERBUFFER, depth);
2721 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, kSize, kSize);
2722
2723 GLFramebuffer fbo;
2724 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
2725 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, color);
2726 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depth);
2727 EXPECT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER);
2728 EXPECT_GL_NO_ERROR();
2729
2730 // Clear depth/stencil with glClearBufferfi. Note that the stencil attachment doesn't exist.
2731 glClearBufferfi(GL_DEPTH_STENCIL, 0, 0.5f, 0x55);
2732 EXPECT_GL_NO_ERROR();
2733
2734 // Verify depth is cleared correctly.
2735 verifyDepth(0.5f, kSize);
2736 }
2737
2738 // Test that scissored clear followed by non-scissored draw works. Ensures that when scissor size
2739 // is expanded, the clear operation remains limited to the scissor region. Written to catch
2740 // potential future bugs if loadOp=CLEAR is used in the Vulkan backend for a small render pass and
2741 // then the render area is mistakenly enlarged.
TEST_P(ClearTest,ScissoredClearThenNonScissoredDraw)2742 TEST_P(ClearTest, ScissoredClearThenNonScissoredDraw)
2743 {
2744 constexpr GLsizei kSize = 16;
2745 const std::vector<GLColor> kInitialData(kSize * kSize, GLColor::red);
2746
2747 // Setup framebuffer. Initialize color with red.
2748 GLTexture color;
2749 glBindTexture(GL_TEXTURE_2D, color);
2750 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2751 kInitialData.data());
2752
2753 GLFramebuffer fb;
2754 glBindFramebuffer(GL_FRAMEBUFFER, fb);
2755 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, color, 0);
2756 EXPECT_GL_NO_ERROR();
2757 ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER);
2758
2759 // Issue a scissored clear to green.
2760 glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
2761 glScissor(kSize / 2, 0, kSize / 2, kSize);
2762 glEnable(GL_SCISSOR_TEST);
2763 glClear(GL_COLOR_BUFFER_BIT);
2764
2765 // Expand the scissor and blend blue into the framebuffer.
2766 glScissor(0, 0, kSize, kSize);
2767 glEnable(GL_BLEND);
2768 glBlendFunc(GL_ONE, GL_ONE);
2769
2770 ANGLE_GL_PROGRAM(drawBlue, essl1_shaders::vs::Simple(), essl1_shaders::fs::Blue());
2771 drawQuad(drawBlue, essl1_shaders::PositionAttrib(), 0.5f);
2772 ASSERT_GL_NO_ERROR();
2773
2774 // Verify that the left half is magenta, and the right half is cyan.
2775 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::magenta);
2776 EXPECT_PIXEL_COLOR_EQ(kSize / 2 - 1, 0, GLColor::magenta);
2777 EXPECT_PIXEL_COLOR_EQ(0, kSize - 1, GLColor::magenta);
2778 EXPECT_PIXEL_COLOR_EQ(kSize / 2 - 1, kSize - 1, GLColor::magenta);
2779
2780 EXPECT_PIXEL_COLOR_EQ(kSize / 2, 0, GLColor::cyan);
2781 EXPECT_PIXEL_COLOR_EQ(kSize / 2, kSize - 1, GLColor::cyan);
2782 EXPECT_PIXEL_COLOR_EQ(kSize - 1, 0, GLColor::cyan);
2783 EXPECT_PIXEL_COLOR_EQ(kSize - 1, kSize - 1, GLColor::cyan);
2784 }
2785
2786 // Test that clear followed by a scissored masked clear works.
TEST_P(ClearTest,ClearThenScissoredMaskedClear)2787 TEST_P(ClearTest, ClearThenScissoredMaskedClear)
2788 {
2789 constexpr GLsizei kSize = 16;
2790
2791 // Setup framebuffer
2792 GLTexture color;
2793 glBindTexture(GL_TEXTURE_2D, color);
2794 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
2795
2796 GLFramebuffer fb;
2797 glBindFramebuffer(GL_FRAMEBUFFER, fb);
2798 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, color, 0);
2799 EXPECT_GL_NO_ERROR();
2800 ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER);
2801
2802 // Clear to red.
2803 glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
2804 glClear(GL_COLOR_BUFFER_BIT);
2805
2806 // Mask red and clear to green with a scissor
2807 glColorMask(GL_FALSE, GL_TRUE, GL_TRUE, GL_TRUE);
2808 glScissor(0, 0, kSize / 2, kSize);
2809 glEnable(GL_SCISSOR_TEST);
2810 glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
2811 glClear(GL_COLOR_BUFFER_BIT);
2812
2813 // Verify that the left half is yellow, and the right half is red.
2814 EXPECT_PIXEL_RECT_EQ(0, 0, kSize / 2, kSize, GLColor::yellow);
2815 EXPECT_PIXEL_RECT_EQ(kSize / 2, 0, kSize / 2, kSize, GLColor::red);
2816 }
2817
2818 // Test that a scissored stencil clear followed by a full clear works.
TEST_P(ClearTestES3,StencilScissoredClearThenFullClear)2819 TEST_P(ClearTestES3, StencilScissoredClearThenFullClear)
2820 {
2821 constexpr GLsizei kSize = 128;
2822
2823 GLint stencilBits = 0;
2824 glGetIntegerv(GL_STENCIL_BITS, &stencilBits);
2825 EXPECT_EQ(stencilBits, 8);
2826
2827 // Clear stencil value must be masked to 0x42
2828 glClearBufferfi(GL_DEPTH_STENCIL, 0, 0.5f, 0x142);
2829
2830 glClearColor(1, 0, 0, 1);
2831 glClear(GL_COLOR_BUFFER_BIT);
2832 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
2833
2834 // Shrink the render area.
2835 glScissor(kSize / 2, 0, kSize / 2, kSize);
2836 glEnable(GL_SCISSOR_TEST);
2837
2838 // Clear stencil.
2839 glClearBufferfi(GL_DEPTH_STENCIL, 0, 0.5f, 0x64);
2840
2841 // Grow the render area.
2842 glScissor(0, 0, kSize, kSize);
2843 glEnable(GL_SCISSOR_TEST);
2844
2845 // Check that the stencil test works as expected
2846 glEnable(GL_STENCIL_TEST);
2847
2848 // Scissored region is green, outside is red (clear color)
2849 glStencilFunc(GL_EQUAL, 0x64, 0xFF);
2850 ANGLE_GL_PROGRAM(drawGreen, essl3_shaders::vs::Simple(), essl3_shaders::fs::Green());
2851 glUseProgram(drawGreen);
2852 drawQuad(drawGreen, essl3_shaders::PositionAttrib(), 0.5f);
2853 EXPECT_PIXEL_RECT_EQ(0, 0, kSize / 2, kSize, GLColor::red);
2854 EXPECT_PIXEL_RECT_EQ(kSize / 2, 0, kSize / 2, kSize, GLColor::green);
2855
2856 // Outside scissored region is blue.
2857 glStencilFunc(GL_EQUAL, 0x42, 0xFF);
2858 ANGLE_GL_PROGRAM(drawBlue, essl3_shaders::vs::Simple(), essl3_shaders::fs::Blue());
2859 glUseProgram(drawBlue);
2860 drawQuad(drawBlue, essl3_shaders::PositionAttrib(), 0.5f);
2861 EXPECT_PIXEL_RECT_EQ(0, 0, kSize / 2, kSize, GLColor::blue);
2862 EXPECT_PIXEL_RECT_EQ(kSize / 2, 0, kSize / 2, kSize, GLColor::green);
2863
2864 ASSERT_GL_NO_ERROR();
2865 }
2866
2867 // This is a test that must be verified visually.
2868 //
2869 // Tests that clear of the default framebuffer applies to the window.
TEST_P(ClearTest,DISABLED_ClearReachesWindow)2870 TEST_P(ClearTest, DISABLED_ClearReachesWindow)
2871 {
2872 ANGLE_GL_PROGRAM(blueProgram, essl1_shaders::vs::Simple(), essl1_shaders::fs::Blue());
2873
2874 // Draw blue.
2875 drawQuad(blueProgram, essl1_shaders::PositionAttrib(), 0.5f);
2876 swapBuffers();
2877
2878 // Use glClear to clear to red. Regression test for the Vulkan backend where this clear
2879 // remained "deferred" and didn't make it to the window on swap.
2880 glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
2881 glClear(GL_COLOR_BUFFER_BIT);
2882 swapBuffers();
2883
2884 // Wait for visual verification.
2885 angle::Sleep(2000);
2886 }
2887
2888 // Tests that masked clear after a no-op framebuffer binding change with an open render pass works.
TEST_P(ClearTest,DrawThenChangeFBOBindingAndBackThenMaskedClear)2889 TEST_P(ClearTest, DrawThenChangeFBOBindingAndBackThenMaskedClear)
2890 {
2891 ANGLE_GL_PROGRAM(blueProgram, essl1_shaders::vs::Simple(), essl1_shaders::fs::Blue());
2892
2893 // Draw blue.
2894 drawQuad(blueProgram, essl1_shaders::PositionAttrib(), 0.5f);
2895
2896 // Change framebuffer and back
2897 glBindFramebuffer(GL_FRAMEBUFFER, mFBOs[0]);
2898 glBindFramebuffer(GL_FRAMEBUFFER, 0);
2899
2900 // Masked clear
2901 glColorMask(1, 0, 0, 1);
2902 glClearColor(1.0f, 0.5f, 0.5f, 1.0f);
2903 glClear(GL_COLOR_BUFFER_BIT);
2904
2905 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::magenta);
2906 }
2907
2908 // Test that clearing slices of a 3D texture and reading them back works.
TEST_P(ClearTestES3,ClearAndReadPixels3DTexture)2909 TEST_P(ClearTestES3, ClearAndReadPixels3DTexture)
2910 {
2911 constexpr uint32_t kWidth = 128;
2912 constexpr uint32_t kHeight = 128;
2913 constexpr uint32_t kDepth = 7;
2914
2915 GLTexture texture;
2916 glBindTexture(GL_TEXTURE_3D, texture);
2917 glTexStorage3D(GL_TEXTURE_3D, 1, GL_RGBA8, kWidth, kHeight, kDepth);
2918 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 0);
2919
2920 std::array<GLColor, kDepth> clearColors = {
2921 GLColor::red, GLColor::green, GLColor::blue, GLColor::yellow,
2922 GLColor::cyan, GLColor::magenta, GLColor::white,
2923 };
2924
2925 GLFramebuffer framebuffer;
2926 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
2927
2928 for (uint32_t z = 0; z < kDepth; ++z)
2929 {
2930 glFramebufferTextureLayer(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texture, 0, z);
2931 glClearBufferfv(GL_COLOR, 0, clearColors[z].toNormalizedVector().data());
2932 }
2933
2934 for (uint32_t z = 0; z < kDepth; ++z)
2935 {
2936 glFramebufferTextureLayer(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texture, 0, z);
2937 EXPECT_PIXEL_COLOR_EQ(0, 0, clearColors[z]);
2938 }
2939 }
2940
2941 // Test that clearing stencil with zero first byte in mask doesn't crash.
TEST_P(ClearTestES3,ClearStencilZeroFirstByteMask)2942 TEST_P(ClearTestES3, ClearStencilZeroFirstByteMask)
2943 {
2944 glStencilMask(0xe7d6a900);
2945 glClear(GL_STENCIL_BUFFER_BIT);
2946 }
2947
2948 // Test that mid render pass clear after draw sets the render pass size correctly.
TEST_P(ClearTestES3,ScissoredDrawThenFullClear)2949 TEST_P(ClearTestES3, ScissoredDrawThenFullClear)
2950 {
2951 const int w = getWindowWidth();
2952 const int h = getWindowHeight();
2953
2954 // Use viewport to imply scissor on the draw call
2955 glViewport(w / 4, h / 4, w / 2, h / 2);
2956
2957 ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Passthrough(), essl1_shaders::fs::Blue());
2958 drawQuad(program, essl1_shaders::PositionAttrib(), 0);
2959
2960 // Mid-render-pass clear without scissor or viewport change, which covers the whole framebuffer.
2961 glClearColor(1, 1, 0, 1);
2962 glClear(GL_COLOR_BUFFER_BIT);
2963
2964 EXPECT_PIXEL_RECT_EQ(0, 0, w, h, GLColor::yellow);
2965 }
2966
2967 // Test that mid render pass clear after masked clear sets the render pass size correctly.
TEST_P(ClearTestES3,MaskedScissoredClearThenFullClear)2968 TEST_P(ClearTestES3, MaskedScissoredClearThenFullClear)
2969 {
2970 const int w = getWindowWidth();
2971 const int h = getWindowHeight();
2972
2973 // Use viewport to imply a small scissor on (non-existing) draw calls. This is important to
2974 // make sure render area that's derived from scissor+viewport for draw calls doesn't
2975 // accidentally fix render area derived from scissor for clear calls.
2976 glViewport(w / 2, h / 2, 1, 1);
2977
2978 glEnable(GL_SCISSOR_TEST);
2979 glScissor(w / 4, h / 4, w / 2, h / 2);
2980 glColorMask(GL_TRUE, GL_FALSE, GL_TRUE, GL_FALSE);
2981 glClearColor(0.13, 0.38, 0.87, 0.65);
2982 glClear(GL_COLOR_BUFFER_BIT);
2983
2984 // Mid-render-pass clear without scissor, which covers the whole framebuffer.
2985 glDisable(GL_SCISSOR_TEST);
2986 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
2987 glClearColor(1, 1, 0, 1);
2988 glClear(GL_COLOR_BUFFER_BIT);
2989
2990 EXPECT_PIXEL_RECT_EQ(0, 0, w, h, GLColor::yellow);
2991 }
2992
2993 // Test that mid render pass masked clear after masked clear sets the render pass size correctly.
TEST_P(ClearTestES3,MaskedScissoredClearThenFullMaskedClear)2994 TEST_P(ClearTestES3, MaskedScissoredClearThenFullMaskedClear)
2995 {
2996 const int w = getWindowWidth();
2997 const int h = getWindowHeight();
2998
2999 // Make sure the framebuffer is initialized.
3000 glClearColor(0, 0, 0, 1);
3001 glClear(GL_COLOR_BUFFER_BIT);
3002 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
3003
3004 // Use viewport to imply a small scissor on (non-existing) draw calls This is important to
3005 // make sure render area that's derived from scissor+viewport for draw calls doesn't
3006 // accidentally fix render area derived from scissor for clear calls.
3007 glViewport(w / 2, h / 2, 1, 1);
3008
3009 glEnable(GL_SCISSOR_TEST);
3010 glScissor(w / 4, h / 4, w / 2, h / 2);
3011 glColorMask(GL_TRUE, GL_FALSE, GL_TRUE, GL_FALSE);
3012 glClearColor(1, 1, 0, 1);
3013 glClear(GL_COLOR_BUFFER_BIT);
3014
3015 // Mid-render-pass clear without scissor, which covers the whole framebuffer.
3016 glDisable(GL_SCISSOR_TEST);
3017 glColorMask(GL_FALSE, GL_TRUE, GL_FALSE, GL_TRUE);
3018 glClearColor(1, 1, 1, 1);
3019 glClear(GL_COLOR_BUFFER_BIT);
3020
3021 EXPECT_PIXEL_RECT_EQ(0, 0, w / 4, h, GLColor::green);
3022 EXPECT_PIXEL_RECT_EQ(w / 4, 0, w / 2, h / 4, GLColor::green);
3023 EXPECT_PIXEL_RECT_EQ(w / 4, 3 * h / 4, w / 2, h / 4, GLColor::green);
3024 EXPECT_PIXEL_RECT_EQ(3 * w / 4, 0, w / 4, h, GLColor::green);
3025
3026 EXPECT_PIXEL_RECT_EQ(w / 4, h / 4, w / 2, h / 2, GLColor::yellow);
3027 }
3028
3029 // Test that reclearing color to the same value works.
TEST_P(ClearTestES3,RepeatedColorClear)3030 TEST_P(ClearTestES3, RepeatedColorClear)
3031 {
3032 glClearColor(1, 1, 0, 1);
3033 glClear(GL_COLOR_BUFFER_BIT);
3034 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::yellow);
3035
3036 glClear(GL_COLOR_BUFFER_BIT);
3037 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::yellow);
3038
3039 ASSERT_GL_NO_ERROR();
3040 }
3041
3042 // Test that reclearing depth to the same value works.
TEST_P(ClearTestES3,RepeatedDepthClear)3043 TEST_P(ClearTestES3, RepeatedDepthClear)
3044 {
3045 glClearDepthf(0.25f);
3046 glClear(GL_DEPTH_BUFFER_BIT);
3047
3048 verifyDepth(0.25f, 1);
3049
3050 glClear(GL_DEPTH_BUFFER_BIT);
3051
3052 verifyDepth(0.25f, 1);
3053
3054 ASSERT_GL_NO_ERROR();
3055 }
3056
3057 // Test that reclearing stencil to the same value works.
TEST_P(ClearTestES3,RepeatedStencilClear)3058 TEST_P(ClearTestES3, RepeatedStencilClear)
3059 {
3060 glClearStencil(0xE4);
3061 glClear(GL_STENCIL_BUFFER_BIT);
3062 verifyStencil(0xE4, 1);
3063
3064 glClear(GL_STENCIL_BUFFER_BIT);
3065 verifyStencil(0xE4, 1);
3066
3067 ASSERT_GL_NO_ERROR();
3068 }
3069
3070 // Test that reclearing color to the same value works if color was written to in between with a draw
3071 // call.
TEST_P(ClearTestES3,RepeatedColorClearWithDrawInBetween)3072 TEST_P(ClearTestES3, RepeatedColorClearWithDrawInBetween)
3073 {
3074 glClearColor(1, 0, 0, 1);
3075 glClear(GL_COLOR_BUFFER_BIT);
3076 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
3077
3078 glClear(GL_COLOR_BUFFER_BIT);
3079 glEnable(GL_BLEND);
3080 glBlendFunc(GL_ONE, GL_ONE);
3081 ANGLE_GL_PROGRAM(drawGreen, essl1_shaders::vs::Passthrough(), essl1_shaders::fs::Green());
3082 drawQuad(drawGreen, essl1_shaders::PositionAttrib(), 0);
3083 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::yellow);
3084
3085 glClear(GL_COLOR_BUFFER_BIT);
3086 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
3087
3088 ASSERT_GL_NO_ERROR();
3089 }
3090
3091 // Test that reclearing depth to the same value works if depth was written to in between with a draw
3092 // call.
TEST_P(ClearTestES3,RepeatedDepthClearWithDrawInBetween)3093 TEST_P(ClearTestES3, RepeatedDepthClearWithDrawInBetween)
3094 {
3095 glClearDepthf(0.25f);
3096 glClear(GL_DEPTH_BUFFER_BIT);
3097
3098 ANGLE_GL_PROGRAM(drawGreen, essl1_shaders::vs::Passthrough(), essl1_shaders::fs::Green());
3099 glEnable(GL_DEPTH_TEST);
3100 glDepthFunc(GL_ALWAYS);
3101 drawQuad(drawGreen, essl1_shaders::PositionAttrib(), 0.75f);
3102
3103 glClear(GL_DEPTH_BUFFER_BIT);
3104 glDepthMask(GL_FALSE);
3105 verifyDepth(0.25f, 1);
3106
3107 ASSERT_GL_NO_ERROR();
3108 }
3109
3110 // Test that reclearing stencil to the same value works if stencil was written to in between with a
3111 // draw call.
TEST_P(ClearTestES3,RepeatedStencilClearWithDrawInBetween)3112 TEST_P(ClearTestES3, RepeatedStencilClearWithDrawInBetween)
3113 {
3114 glClearStencil(0xE4);
3115 glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
3116 glStencilFunc(GL_ALWAYS, 0x3C, 0xFF);
3117 glEnable(GL_STENCIL_TEST);
3118
3119 glClear(GL_STENCIL_BUFFER_BIT);
3120 ANGLE_GL_PROGRAM(drawGreen, essl1_shaders::vs::Passthrough(), essl1_shaders::fs::Green());
3121 drawQuad(drawGreen, essl1_shaders::PositionAttrib(), 0.75f);
3122
3123 glClear(GL_STENCIL_BUFFER_BIT);
3124 verifyStencil(0xE4, 1);
3125
3126 ASSERT_GL_NO_ERROR();
3127 }
3128
3129 // Test that reclearing color to the same value works if color was written to in between with
3130 // glCopyTexSubImage2D.
TEST_P(ClearTestES3,RepeatedColorClearWithCopyInBetween)3131 TEST_P(ClearTestES3, RepeatedColorClearWithCopyInBetween)
3132 {
3133 GLTexture color;
3134 glBindTexture(GL_TEXTURE_2D, color);
3135 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, getWindowWidth(), getWindowHeight());
3136
3137 GLFramebuffer fbo;
3138 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
3139 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, color, 0);
3140 ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER);
3141
3142 // Clear the texture
3143 glClearColor(1, 0, 0, 1);
3144 glClear(GL_COLOR_BUFFER_BIT);
3145 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
3146
3147 // Replace the framebuffer texture
3148 GLTexture color2;
3149 glBindTexture(GL_TEXTURE_2D, color2);
3150 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, getWindowWidth(), getWindowHeight());
3151 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, color2, 0);
3152 ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER);
3153
3154 // Clear the new texture and copy it to the old texture
3155 glClearColor(0, 1, 0, 1);
3156 glClear(GL_COLOR_BUFFER_BIT);
3157 glBindTexture(GL_TEXTURE_2D, color);
3158 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, getWindowWidth(), getWindowHeight());
3159
3160 // Attach the original texture back to the framebuffer and verify the copy.
3161 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, color, 0);
3162 ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER);
3163 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3164
3165 // Clear to the original value and make sure it's applied.
3166 glClearColor(1, 0, 0, 1);
3167 glClear(GL_COLOR_BUFFER_BIT);
3168 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
3169
3170 ASSERT_GL_NO_ERROR();
3171 }
3172
3173 // Test that reclearing color to the same value works if color was written to in between with a
3174 // blit.
TEST_P(ClearTestES3,RepeatedColorClearWithBlitInBetween)3175 TEST_P(ClearTestES3, RepeatedColorClearWithBlitInBetween)
3176 {
3177 GLTexture color;
3178 glBindTexture(GL_TEXTURE_2D, color);
3179 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, getWindowWidth(), getWindowHeight());
3180
3181 GLFramebuffer fbo;
3182 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
3183 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, color, 0);
3184 ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER);
3185
3186 // Clear the texture
3187 glClearColor(1, 0, 0, 1);
3188 glClear(GL_COLOR_BUFFER_BIT);
3189 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
3190
3191 // Create another framebuffer as blit src
3192 GLTexture color2;
3193 glBindTexture(GL_TEXTURE_2D, color2);
3194 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, getWindowWidth(), getWindowHeight());
3195
3196 GLFramebuffer fbo2;
3197 glBindFramebuffer(GL_FRAMEBUFFER, fbo2);
3198 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, color2, 0);
3199 ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER);
3200
3201 // Clear the new framebuffer and blit it to the old one
3202 glClearColor(0, 1, 0, 1);
3203 glClear(GL_COLOR_BUFFER_BIT);
3204 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo);
3205 glBlitFramebuffer(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(),
3206 getWindowHeight(), GL_COLOR_BUFFER_BIT, GL_NEAREST);
3207
3208 // Verify the copy is done correctly.
3209 glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo);
3210 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3211
3212 // Clear to the original value and make sure it's applied.
3213 glClearColor(1, 0, 0, 1);
3214 glClear(GL_COLOR_BUFFER_BIT);
3215 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
3216
3217 ASSERT_GL_NO_ERROR();
3218 }
3219
3220 // Test that reclearing depth to the same value works if depth was written to in between with a
3221 // blit.
TEST_P(ClearTestES3,RepeatedDepthClearWithBlitInBetween)3222 TEST_P(ClearTestES3, RepeatedDepthClearWithBlitInBetween)
3223 {
3224 GLTexture color;
3225 glBindTexture(GL_TEXTURE_2D, color);
3226 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, getWindowWidth(), getWindowHeight());
3227
3228 GLRenderbuffer depth;
3229 glBindRenderbuffer(GL_RENDERBUFFER, depth);
3230 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, getWindowWidth(),
3231 getWindowHeight());
3232
3233 GLFramebuffer fbo;
3234 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
3235 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, color, 0);
3236 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depth);
3237 ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER);
3238
3239 // Clear depth
3240 glClearDepthf(0.25f);
3241 glClearColor(1, 0, 0, 1);
3242 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
3243 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
3244 verifyDepth(0.25f, 1);
3245
3246 // Create another framebuffer as blit src
3247 GLRenderbuffer depth2;
3248 glBindRenderbuffer(GL_RENDERBUFFER, depth2);
3249 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, getWindowWidth(),
3250 getWindowHeight());
3251
3252 GLFramebuffer fbo2;
3253 glBindFramebuffer(GL_FRAMEBUFFER, fbo2);
3254 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depth2);
3255 ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER);
3256
3257 // Clear the new framebuffer and blit it to the old one
3258 glClearDepthf(0.75f);
3259 glClear(GL_DEPTH_BUFFER_BIT);
3260 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo);
3261 glBlitFramebuffer(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(),
3262 getWindowHeight(), GL_DEPTH_BUFFER_BIT, GL_NEAREST);
3263
3264 // Verify the copy is done correctly.
3265 glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo);
3266 verifyDepth(0.75f, 1);
3267
3268 // Clear to the original value and make sure it's applied.
3269 glClearDepthf(0.25f);
3270 glClear(GL_DEPTH_BUFFER_BIT);
3271 verifyDepth(0.25f, 1);
3272
3273 ASSERT_GL_NO_ERROR();
3274 }
3275
3276 // Test that reclearing stencil to the same value works if stencil was written to in between with a
3277 // blit.
TEST_P(ClearTestES3,RepeatedStencilClearWithBlitInBetween)3278 TEST_P(ClearTestES3, RepeatedStencilClearWithBlitInBetween)
3279 {
3280 GLTexture color;
3281 glBindTexture(GL_TEXTURE_2D, color);
3282 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, getWindowWidth(), getWindowHeight());
3283
3284 GLRenderbuffer stencil;
3285 glBindRenderbuffer(GL_RENDERBUFFER, stencil);
3286 glRenderbufferStorage(GL_RENDERBUFFER, GL_STENCIL_INDEX8, getWindowWidth(), getWindowHeight());
3287
3288 GLFramebuffer fbo;
3289 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
3290 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, color, 0);
3291 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, stencil);
3292 ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER);
3293
3294 // Clear stencil
3295 glClearStencil(0xE4);
3296 glClearColor(1, 0, 0, 1);
3297 glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
3298 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
3299 verifyStencil(0xE4, 1);
3300
3301 // Create another framebuffer as blit src
3302 GLRenderbuffer stencil2;
3303 glBindRenderbuffer(GL_RENDERBUFFER, stencil2);
3304 glRenderbufferStorage(GL_RENDERBUFFER, GL_STENCIL_INDEX8, getWindowWidth(), getWindowHeight());
3305
3306 GLFramebuffer fbo2;
3307 glBindFramebuffer(GL_FRAMEBUFFER, fbo2);
3308 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, stencil2);
3309 ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER);
3310
3311 // Clear the new framebuffer and blit it to the old one
3312 glClearStencil(0x35);
3313 glClear(GL_STENCIL_BUFFER_BIT);
3314 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo);
3315 glBlitFramebuffer(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(),
3316 getWindowHeight(), GL_STENCIL_BUFFER_BIT, GL_NEAREST);
3317
3318 // Verify the copy is done correctly.
3319 glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo);
3320 verifyStencil(0x35, 1);
3321
3322 // Clear to the original value and make sure it's applied.
3323 glClearStencil(0xE4);
3324 glClear(GL_STENCIL_BUFFER_BIT);
3325 verifyStencil(0xE4, 1);
3326
3327 ASSERT_GL_NO_ERROR();
3328 }
3329
3330 // Test that reclearing color to the same value works if color was written to in between with a
3331 // compute shader.
TEST_P(ClearTestES31,RepeatedColorClearWithDispatchInBetween)3332 TEST_P(ClearTestES31, RepeatedColorClearWithDispatchInBetween)
3333 {
3334 GLTexture color;
3335 glBindTexture(GL_TEXTURE_2D, color);
3336 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, getWindowWidth(), getWindowHeight());
3337
3338 GLFramebuffer fbo;
3339 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
3340 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, color, 0);
3341 ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER);
3342
3343 // Clear the texture
3344 glClearColor(1, 0, 0, 1);
3345 glClear(GL_COLOR_BUFFER_BIT);
3346 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
3347
3348 // Write to the texture with a compute shader.
3349 constexpr char kCS[] = R"(#version 310 es
3350 layout(local_size_x=1, local_size_y=1, local_size_z=1) in;
3351 layout(rgba8) uniform highp writeonly image2D imageOut;
3352 void main()
3353 {
3354 imageStore(imageOut, ivec2(gl_GlobalInvocationID.xy), vec4(0, 1, 0, 1));
3355 })";
3356
3357 ANGLE_GL_COMPUTE_PROGRAM(program, kCS);
3358 glUseProgram(program);
3359 glBindImageTexture(0, color, 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_RGBA8);
3360
3361 glDispatchCompute(getWindowWidth(), getWindowHeight(), 1);
3362 EXPECT_GL_NO_ERROR();
3363
3364 glMemoryBarrier(GL_FRAMEBUFFER_BARRIER_BIT);
3365
3366 // Verify the compute shader overwrites the image correctly.
3367 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3368
3369 // Clear to the original value and make sure it's applied.
3370 glClearColor(1, 0, 0, 1);
3371 glClear(GL_COLOR_BUFFER_BIT);
3372 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
3373
3374 ASSERT_GL_NO_ERROR();
3375 }
3376
3377 // Test that reclearing depth to the same value works if depth is blit after clear, and depth is
3378 // modified in between with a draw call.
TEST_P(ClearTestES3,RepeatedDepthClearWithBlitAfterClearAndDrawInBetween)3379 TEST_P(ClearTestES3, RepeatedDepthClearWithBlitAfterClearAndDrawInBetween)
3380 {
3381 glClearDepthf(0.25f);
3382 glClear(GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
3383
3384 // Make sure clear is flushed.
3385 GLRenderbuffer depth;
3386 glBindRenderbuffer(GL_RENDERBUFFER, depth);
3387 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8_OES, getWindowWidth(),
3388 getWindowHeight());
3389
3390 GLFramebuffer fbo;
3391 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo);
3392 glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depth);
3393 ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_DRAW_FRAMEBUFFER);
3394
3395 glBlitFramebuffer(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(),
3396 getWindowHeight(), GL_DEPTH_BUFFER_BIT, GL_NEAREST);
3397
3398 // Draw to depth, and break the render pass.
3399 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
3400 ANGLE_GL_PROGRAM(drawGreen, essl1_shaders::vs::Passthrough(), essl1_shaders::fs::Green());
3401 glEnable(GL_DEPTH_TEST);
3402 glDepthFunc(GL_ALWAYS);
3403 drawQuad(drawGreen, essl1_shaders::PositionAttrib(), 0.75f);
3404 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3405
3406 // Clear back to the original value
3407 glClear(GL_DEPTH_BUFFER_BIT);
3408
3409 // Blit again.
3410 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo);
3411 glBlitFramebuffer(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(),
3412 getWindowHeight(), GL_DEPTH_BUFFER_BIT, GL_NEAREST);
3413
3414 // Make sure the cleared value is in destination, not the modified value.
3415 GLTexture color;
3416 glBindTexture(GL_TEXTURE_2D, color);
3417 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, getWindowWidth(), getWindowHeight());
3418
3419 glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo);
3420 glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, color, 0);
3421 ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_READ_FRAMEBUFFER);
3422 verifyDepth(0.25f, 1);
3423
3424 ASSERT_GL_NO_ERROR();
3425 }
3426
3427 // Test that gaps in framebuffer attachments do not cause race
3428 // conditions when a clear op is followed by a draw call.
TEST_P(ClearTestES3,DrawAfterClearWithGaps)3429 TEST_P(ClearTestES3, DrawAfterClearWithGaps)
3430 {
3431 constexpr char kVS[] = R"(#version 300 es
3432 precision highp float;
3433 void main() {
3434 vec2 offset = vec2((gl_VertexID & 1) == 0 ? -1.0 : 1.0, (gl_VertexID & 2) == 0 ? -1.0 : 1.0);
3435 gl_Position = vec4(offset * 0.125 - 0.5, 0.0, 1.0);
3436 })";
3437
3438 constexpr char kFS[] = R"(#version 300 es
3439 precision mediump float;
3440 layout(location=0) out vec4 color0;
3441 layout(location=2) out vec4 color2;
3442 void main() {
3443 color0 = vec4(1, 0, 1, 1);
3444 color2 = vec4(1, 1, 0, 1);
3445 })";
3446
3447 ANGLE_GL_PROGRAM(program, kVS, kFS);
3448 glUseProgram(program);
3449
3450 constexpr int kSize = 1024;
3451
3452 GLRenderbuffer rb0;
3453 glBindRenderbuffer(GL_RENDERBUFFER, rb0);
3454 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, kSize, kSize);
3455
3456 GLRenderbuffer rb2;
3457 glBindRenderbuffer(GL_RENDERBUFFER, rb2);
3458 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, kSize, kSize);
3459
3460 GLFramebuffer fb;
3461 glBindFramebuffer(GL_FRAMEBUFFER, fb);
3462 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rb0);
3463 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT2, GL_RENDERBUFFER, rb2);
3464
3465 GLenum bufs[3] = {GL_COLOR_ATTACHMENT0, GL_NONE, GL_COLOR_ATTACHMENT2};
3466 glDrawBuffers(3, bufs);
3467 glReadBuffer(GL_COLOR_ATTACHMENT2);
3468
3469 glClearColor(0, 1, 0, 1);
3470 glViewport(0, 0, kSize, kSize);
3471
3472 // Draw immediately after clear
3473 glClear(GL_COLOR_BUFFER_BIT);
3474 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
3475
3476 std::vector<GLColor> pixels(kSize * kSize, GLColor::transparentBlack);
3477 glReadPixels(0, 0, kSize, kSize, GL_RGBA, GL_UNSIGNED_BYTE, pixels.data());
3478 ASSERT_GL_NO_ERROR();
3479
3480 for (int y = 0; y < kSize; ++y)
3481 {
3482 for (int x = 0; x < kSize; ++x)
3483 {
3484 const GLColor color = pixels[y * kSize + x];
3485 if (x > 192 && x < 319 && y > 192 && y < 319)
3486 {
3487 EXPECT_EQ(color, GLColor::yellow) << "at " << x << ", " << y;
3488 }
3489 else if (x < 191 || x > 320 || y < 191 || y > 320)
3490 {
3491 EXPECT_EQ(color, GLColor::green) << "at " << x << ", " << y;
3492 }
3493 }
3494 }
3495 }
3496
3497 // Test that reclearing stencil to the same value works if stencil is blit after clear, and stencil
3498 // is modified in between with a draw call.
TEST_P(ClearTestES3,RepeatedStencilClearWithBlitAfterClearAndDrawInBetween)3499 TEST_P(ClearTestES3, RepeatedStencilClearWithBlitAfterClearAndDrawInBetween)
3500 {
3501 glClearStencil(0xE4);
3502 glClear(GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
3503
3504 // Make sure clear is flushed.
3505 GLRenderbuffer stencil;
3506 glBindRenderbuffer(GL_RENDERBUFFER, stencil);
3507 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8_OES, getWindowWidth(),
3508 getWindowHeight());
3509
3510 GLFramebuffer fbo;
3511 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo);
3512 glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, stencil);
3513 ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_DRAW_FRAMEBUFFER);
3514
3515 glBlitFramebuffer(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(),
3516 getWindowHeight(), GL_STENCIL_BUFFER_BIT, GL_NEAREST);
3517
3518 // Draw to stencil, and break the render pass.
3519 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
3520 ANGLE_GL_PROGRAM(drawGreen, essl1_shaders::vs::Passthrough(), essl1_shaders::fs::Green());
3521 glEnable(GL_STENCIL_TEST);
3522 glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
3523 glStencilFunc(GL_ALWAYS, 0x3C, 0xFF);
3524 drawQuad(drawGreen, essl1_shaders::PositionAttrib(), 0.75f);
3525 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3526
3527 // Clear back to the original value
3528 glClear(GL_STENCIL_BUFFER_BIT);
3529
3530 // Blit again.
3531 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo);
3532 glBlitFramebuffer(0, 0, getWindowWidth(), getWindowHeight(), 0, 0, getWindowWidth(),
3533 getWindowHeight(), GL_STENCIL_BUFFER_BIT, GL_NEAREST);
3534
3535 // Make sure the cleared value is in destination, not the modified value.
3536 GLTexture color;
3537 glBindTexture(GL_TEXTURE_2D, color);
3538 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, getWindowWidth(), getWindowHeight());
3539
3540 glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo);
3541 glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, color, 0);
3542 ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_READ_FRAMEBUFFER);
3543 verifyStencil(0xE4, 1);
3544
3545 ASSERT_GL_NO_ERROR();
3546 }
3547
3548 ANGLE_INSTANTIATE_TEST_ES2_AND_ES3_AND(
3549 ClearTest,
3550 ES3_VULKAN().enable(Feature::ForceFallbackFormat),
3551 ES3_VULKAN().enable(Feature::PreferDrawClearOverVkCmdClearAttachments),
3552 ES2_WEBGPU());
3553
3554 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(ClearTestES3);
3555 ANGLE_INSTANTIATE_TEST_ES3_AND(
3556 ClearTestES3,
3557 ES3_VULKAN().enable(Feature::ForceFallbackFormat),
3558 ES3_VULKAN().enable(Feature::PreferDrawClearOverVkCmdClearAttachments));
3559
3560 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(ClearTestES31);
3561 ANGLE_INSTANTIATE_TEST_ES31_AND(
3562 ClearTestES31,
3563 ES31_VULKAN().enable(Feature::ForceFallbackFormat),
3564 ES31_VULKAN().enable(Feature::PreferDrawClearOverVkCmdClearAttachments));
3565
3566 ANGLE_INSTANTIATE_TEST_COMBINE_4(MaskedScissoredClearTest,
3567 MaskedScissoredClearVariationsTestPrint,
3568 testing::Range(0, 3),
3569 testing::Range(0, 3),
3570 testing::Range(0, 3),
3571 testing::Bool(),
3572 ANGLE_ALL_TEST_PLATFORMS_ES2,
3573 ANGLE_ALL_TEST_PLATFORMS_ES3,
3574 ES3_VULKAN()
3575 .disable(Feature::SupportsExtendedDynamicState)
3576 .disable(Feature::SupportsExtendedDynamicState2),
3577 ES3_VULKAN().disable(Feature::SupportsExtendedDynamicState2));
3578
3579 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(VulkanClearTest);
3580 ANGLE_INSTANTIATE_TEST_COMBINE_4(VulkanClearTest,
3581 MaskedScissoredClearVariationsTestPrint,
3582 testing::Range(0, 3),
3583 testing::Range(0, 3),
3584 testing::Range(0, 3),
3585 testing::Bool(),
3586 ES2_VULKAN().enable(Feature::ForceFallbackFormat),
3587 ES2_VULKAN_SWIFTSHADER().enable(Feature::ForceFallbackFormat),
3588 ES3_VULKAN().enable(Feature::ForceFallbackFormat),
3589 ES3_VULKAN_SWIFTSHADER().enable(Feature::ForceFallbackFormat));
3590
3591 // Not all ANGLE backends support RGB backbuffers
3592 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(ClearTestRGB);
3593 ANGLE_INSTANTIATE_TEST(ClearTestRGB,
3594 ES2_D3D11(),
3595 ES3_D3D11(),
3596 ES2_VULKAN(),
3597 ES3_VULKAN(),
3598 ES2_METAL(),
3599 ES3_METAL());
3600
3601 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(ClearTestRGB_ES3);
3602 ANGLE_INSTANTIATE_TEST(ClearTestRGB_ES3, ES3_D3D11(), ES3_VULKAN(), ES3_METAL());
3603
3604 } // anonymous namespace
3605