Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/angle
Path: blob/main_old/src/tests/gl_tests/ClearTest.cpp
1693 views
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 "platform/FeaturesVk.h"
10
#include "test_utils/gl_raii.h"
11
#include "util/random_utils.h"
12
#include "util/shader_utils.h"
13
#include "util/test_utils.h"
14
15
using namespace angle;
16
17
namespace
18
{
19
class ClearTestBase : public ANGLETest
20
{
21
protected:
22
ClearTestBase()
23
{
24
setWindowWidth(128);
25
setWindowHeight(128);
26
setConfigRedBits(8);
27
setConfigGreenBits(8);
28
setConfigBlueBits(8);
29
setConfigAlphaBits(8);
30
setConfigDepthBits(24);
31
setConfigStencilBits(8);
32
}
33
34
void testSetUp() override
35
{
36
mFBOs.resize(2, 0);
37
glGenFramebuffers(2, mFBOs.data());
38
39
ASSERT_GL_NO_ERROR();
40
}
41
42
void testTearDown() override
43
{
44
if (!mFBOs.empty())
45
{
46
glDeleteFramebuffers(static_cast<GLsizei>(mFBOs.size()), mFBOs.data());
47
}
48
49
if (!mTextures.empty())
50
{
51
glDeleteTextures(static_cast<GLsizei>(mTextures.size()), mTextures.data());
52
}
53
}
54
55
std::vector<GLuint> mFBOs;
56
std::vector<GLuint> mTextures;
57
};
58
59
class ClearTest : public ClearTestBase
60
{};
61
62
class ClearTestES3 : public ClearTestBase
63
{
64
protected:
65
void verifyDepth(float depthValue, uint32_t size)
66
{
67
// Use a small shader to verify depth.
68
ANGLE_GL_PROGRAM(depthTestProgram, essl1_shaders::vs::Passthrough(),
69
essl1_shaders::fs::Blue());
70
ANGLE_GL_PROGRAM(depthTestProgramFail, essl1_shaders::vs::Passthrough(),
71
essl1_shaders::fs::Red());
72
glEnable(GL_DEPTH_TEST);
73
glDepthFunc(GL_LESS);
74
drawQuad(depthTestProgram, essl1_shaders::PositionAttrib(), depthValue * 2 - 1 - 0.01f);
75
drawQuad(depthTestProgramFail, essl1_shaders::PositionAttrib(), depthValue * 2 - 1 + 0.01f);
76
glDisable(GL_DEPTH_TEST);
77
ASSERT_GL_NO_ERROR();
78
79
EXPECT_PIXEL_COLOR_NEAR(0, 0, GLColor::blue, 1);
80
EXPECT_PIXEL_COLOR_NEAR(size - 1, 0, GLColor::blue, 1);
81
EXPECT_PIXEL_COLOR_NEAR(0, size - 1, GLColor::blue, 1);
82
EXPECT_PIXEL_COLOR_NEAR(size - 1, size - 1, GLColor::blue, 1);
83
}
84
85
void verifyStencil(uint32_t stencilValue, uint32_t size)
86
{
87
// Use another small shader to verify stencil.
88
ANGLE_GL_PROGRAM(stencilTestProgram, essl1_shaders::vs::Passthrough(),
89
essl1_shaders::fs::Green());
90
glEnable(GL_STENCIL_TEST);
91
glStencilFunc(GL_EQUAL, stencilValue, 0xFF);
92
drawQuad(stencilTestProgram, essl1_shaders::PositionAttrib(), 0.0f);
93
glDisable(GL_STENCIL_TEST);
94
ASSERT_GL_NO_ERROR();
95
96
EXPECT_PIXEL_COLOR_NEAR(0, 0, GLColor::green, 1);
97
EXPECT_PIXEL_COLOR_NEAR(size - 1, 0, GLColor::green, 1);
98
EXPECT_PIXEL_COLOR_NEAR(0, size - 1, GLColor::green, 1);
99
EXPECT_PIXEL_COLOR_NEAR(size - 1, size - 1, GLColor::green, 1);
100
}
101
};
102
103
class ClearTestRGB : public ANGLETest
104
{
105
protected:
106
ClearTestRGB()
107
{
108
setWindowWidth(128);
109
setWindowHeight(128);
110
setConfigRedBits(8);
111
setConfigGreenBits(8);
112
setConfigBlueBits(8);
113
}
114
};
115
116
// Each int parameter can have three values: don't clear, clear, or masked clear. The bool
117
// parameter controls scissor.
118
using MaskedScissoredClearVariationsTestParams =
119
std::tuple<angle::PlatformParameters, int, int, int, bool>;
120
121
void ParseMaskedScissoredClearVariationsTestParams(
122
const MaskedScissoredClearVariationsTestParams &params,
123
bool *clearColor,
124
bool *clearDepth,
125
bool *clearStencil,
126
bool *maskColor,
127
bool *maskDepth,
128
bool *maskStencil,
129
bool *scissor)
130
{
131
int colorClearInfo = std::get<1>(params);
132
int depthClearInfo = std::get<2>(params);
133
int stencilClearInfo = std::get<3>(params);
134
135
*clearColor = colorClearInfo > 0;
136
*clearDepth = depthClearInfo > 0;
137
*clearStencil = stencilClearInfo > 0;
138
139
*maskColor = colorClearInfo > 1;
140
*maskDepth = depthClearInfo > 1;
141
*maskStencil = stencilClearInfo > 1;
142
143
*scissor = std::get<4>(params);
144
}
145
146
std::string MaskedScissoredClearVariationsTestPrint(
147
const ::testing::TestParamInfo<MaskedScissoredClearVariationsTestParams> &paramsInfo)
148
{
149
const MaskedScissoredClearVariationsTestParams &params = paramsInfo.param;
150
std::ostringstream out;
151
152
out << std::get<0>(params);
153
154
bool clearColor, clearDepth, clearStencil;
155
bool maskColor, maskDepth, maskStencil;
156
bool scissor;
157
158
ParseMaskedScissoredClearVariationsTestParams(params, &clearColor, &clearDepth, &clearStencil,
159
&maskColor, &maskDepth, &maskStencil, &scissor);
160
161
if (scissor || clearColor || clearDepth || clearStencil || maskColor || maskDepth ||
162
maskStencil)
163
{
164
out << "_";
165
}
166
167
if (scissor)
168
{
169
out << "_scissored";
170
}
171
172
if (clearColor || clearDepth || clearStencil)
173
{
174
out << "_clear_";
175
if (clearColor)
176
{
177
out << "c";
178
}
179
if (clearDepth)
180
{
181
out << "d";
182
}
183
if (clearStencil)
184
{
185
out << "s";
186
}
187
}
188
189
if (maskColor || maskDepth || maskStencil)
190
{
191
out << "_mask_";
192
if (maskColor)
193
{
194
out << "c";
195
}
196
if (maskDepth)
197
{
198
out << "d";
199
}
200
if (maskStencil)
201
{
202
out << "s";
203
}
204
}
205
206
return out.str();
207
}
208
209
class MaskedScissoredClearTestBase
210
: public ANGLETestWithParam<MaskedScissoredClearVariationsTestParams>
211
{
212
protected:
213
MaskedScissoredClearTestBase()
214
{
215
setWindowWidth(128);
216
setWindowHeight(128);
217
setConfigRedBits(8);
218
setConfigGreenBits(8);
219
setConfigBlueBits(8);
220
setConfigAlphaBits(8);
221
setConfigDepthBits(24);
222
setConfigStencilBits(8);
223
}
224
225
void maskedScissoredColorDepthStencilClear(
226
const MaskedScissoredClearVariationsTestParams &params);
227
228
bool mHasDepth = true;
229
bool mHasStencil = true;
230
};
231
232
class MaskedScissoredClearTest : public MaskedScissoredClearTestBase
233
{};
234
235
class VulkanClearTest : public MaskedScissoredClearTestBase
236
{
237
protected:
238
void testSetUp() override
239
{
240
glBindTexture(GL_TEXTURE_2D, mColorTexture);
241
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, getWindowWidth(), getWindowHeight(), 0, GL_RGBA,
242
GL_UNSIGNED_BYTE, nullptr);
243
244
// Setup Color/Stencil FBO with a stencil format that's emulated with packed depth/stencil.
245
glBindFramebuffer(GL_FRAMEBUFFER, mColorStencilFBO);
246
247
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mColorTexture,
248
0);
249
glBindRenderbuffer(GL_RENDERBUFFER, mStencilTexture);
250
glRenderbufferStorage(GL_RENDERBUFFER, GL_STENCIL_INDEX8, getWindowWidth(),
251
getWindowHeight());
252
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
253
mStencilTexture);
254
255
ASSERT_GL_NO_ERROR();
256
257
// Note: GL_DEPTH_COMPONENT24 is not allowed in GLES2.
258
if (getClientMajorVersion() >= 3)
259
{
260
// Setup Color/Depth FBO with a depth format that's emulated with packed depth/stencil.
261
glBindFramebuffer(GL_FRAMEBUFFER, mColorDepthFBO);
262
263
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
264
mColorTexture, 0);
265
glBindRenderbuffer(GL_RENDERBUFFER, mDepthTexture);
266
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, getWindowWidth(),
267
getWindowHeight());
268
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER,
269
mDepthTexture);
270
}
271
272
ASSERT_GL_NO_ERROR();
273
}
274
275
void bindColorStencilFBO()
276
{
277
glBindFramebuffer(GL_FRAMEBUFFER, mColorStencilFBO);
278
mHasDepth = false;
279
}
280
281
void bindColorDepthFBO()
282
{
283
glBindFramebuffer(GL_FRAMEBUFFER, mColorDepthFBO);
284
mHasStencil = false;
285
}
286
287
// Override a feature to force emulation of stencil-only and depth-only formats with a packed
288
// depth/stencil format
289
void overrideFeaturesVk(FeaturesVk *featuresVk) override
290
{
291
featuresVk->overrideFeatures({"force_fallback_format"}, true);
292
}
293
294
private:
295
GLFramebuffer mColorStencilFBO;
296
GLFramebuffer mColorDepthFBO;
297
GLTexture mColorTexture;
298
GLRenderbuffer mDepthTexture;
299
GLRenderbuffer mStencilTexture;
300
};
301
302
// Test clearing the default framebuffer
303
TEST_P(ClearTest, DefaultFramebuffer)
304
{
305
glClearColor(0.25f, 0.5f, 0.5f, 0.5f);
306
glClear(GL_COLOR_BUFFER_BIT);
307
EXPECT_PIXEL_NEAR(0, 0, 64, 128, 128, 128, 1.0);
308
}
309
310
// Test clearing the default framebuffer with scissor and mask
311
// This forces down path that uses draw to do clear
312
TEST_P(ClearTest, EmptyScissor)
313
{
314
// These configs have bug that fails this test.
315
// These configs are unmaintained so skipping.
316
ANGLE_SKIP_TEST_IF(IsIntel() && IsD3D9());
317
ANGLE_SKIP_TEST_IF(IsOSX());
318
glClearColor(0.25f, 0.5f, 0.5f, 1.0f);
319
glClear(GL_COLOR_BUFFER_BIT);
320
glEnable(GL_SCISSOR_TEST);
321
glScissor(-10, 0, 5, 5);
322
glClearColor(0.5f, 0.25f, 0.75f, 0.5f);
323
glColorMask(GL_TRUE, GL_FALSE, GL_TRUE, GL_TRUE);
324
glClear(GL_COLOR_BUFFER_BIT);
325
glDisable(GL_SCISSOR_TEST);
326
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
327
EXPECT_PIXEL_NEAR(0, 0, 64, 128, 128, 255, 1.0);
328
}
329
330
// Test clearing the RGB default framebuffer and verify that the alpha channel is not cleared
331
TEST_P(ClearTestRGB, DefaultFramebufferRGB)
332
{
333
// Some GPUs don't support RGB format default framebuffer,
334
// so skip if the back buffer has alpha bits.
335
EGLWindow *window = getEGLWindow();
336
EGLDisplay display = window->getDisplay();
337
EGLConfig config = window->getConfig();
338
EGLint backbufferAlphaBits = 0;
339
eglGetConfigAttrib(display, config, EGL_ALPHA_SIZE, &backbufferAlphaBits);
340
ANGLE_SKIP_TEST_IF(backbufferAlphaBits != 0);
341
342
glClearColor(0.25f, 0.5f, 0.5f, 0.5f);
343
glClear(GL_COLOR_BUFFER_BIT);
344
EXPECT_PIXEL_NEAR(0, 0, 64, 128, 128, 255, 1.0);
345
}
346
347
// Invalidate the RGB default framebuffer and verify that the alpha channel is not cleared, and
348
// stays set after drawing.
349
TEST_P(ClearTestRGB, InvalidateDefaultFramebufferRGB)
350
{
351
ANGLE_GL_PROGRAM(blueProgram, essl1_shaders::vs::Simple(), essl1_shaders::fs::Blue());
352
353
// Some GPUs don't support RGB format default framebuffer,
354
// so skip if the back buffer has alpha bits.
355
EGLWindow *window = getEGLWindow();
356
EGLDisplay display = window->getDisplay();
357
EGLConfig config = window->getConfig();
358
EGLint backbufferAlphaBits = 0;
359
eglGetConfigAttrib(display, config, EGL_ALPHA_SIZE, &backbufferAlphaBits);
360
ANGLE_SKIP_TEST_IF(backbufferAlphaBits != 0);
361
// glInvalidateFramebuffer() isn't supported with GLES 2.0
362
ANGLE_SKIP_TEST_IF(getClientMajorVersion() < 3);
363
ANGLE_SKIP_TEST_IF(IsD3D11());
364
365
const GLenum discards[] = {GL_COLOR};
366
glInvalidateFramebuffer(GL_FRAMEBUFFER, 1, discards);
367
EXPECT_PIXEL_NEAR(0, 0, 0, 0, 0, 255, 1.0);
368
369
// Don't explicitly clear, but draw blue (make sure alpha is not cleared)
370
drawQuad(blueProgram, essl1_shaders::PositionAttrib(), 0.5f);
371
EXPECT_PIXEL_NEAR(0, 0, 0, 0, 255, 255, 1.0);
372
}
373
374
// Test clearing a RGBA8 Framebuffer
375
TEST_P(ClearTest, RGBA8Framebuffer)
376
{
377
glBindFramebuffer(GL_FRAMEBUFFER, mFBOs[0]);
378
379
GLTexture texture;
380
381
glBindTexture(GL_TEXTURE_2D, texture);
382
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, getWindowWidth(), getWindowHeight(), 0, GL_RGBA,
383
GL_UNSIGNED_BYTE, nullptr);
384
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
385
386
glClearColor(0.5f, 0.5f, 0.5f, 0.5f);
387
glClear(GL_COLOR_BUFFER_BIT);
388
389
EXPECT_PIXEL_NEAR(0, 0, 128, 128, 128, 128, 1.0);
390
}
391
392
// Test to validate that we can go from an RGBA framebuffer attachment, to an RGB one and still
393
// have a correct behavior after.
394
TEST_P(ClearTest, ChangeFramebufferAttachmentFromRGBAtoRGB)
395
{
396
// http://anglebug.com/2689
397
ANGLE_SKIP_TEST_IF(IsD3D9() || IsD3D11() || (IsOzone() && IsOpenGLES()));
398
ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES());
399
400
// http://anglebug.com/5165
401
ANGLE_SKIP_TEST_IF(IsOSX() && IsDesktopOpenGL());
402
403
ANGLE_GL_PROGRAM(program, angle::essl1_shaders::vs::Simple(),
404
angle::essl1_shaders::fs::UniformColor());
405
setupQuadVertexBuffer(0.5f, 1.0f);
406
glUseProgram(program);
407
GLint positionLocation = glGetAttribLocation(program, angle::essl1_shaders::PositionAttrib());
408
ASSERT_NE(positionLocation, -1);
409
glVertexAttribPointer(positionLocation, 3, GL_FLOAT, GL_FALSE, 0, nullptr);
410
glEnableVertexAttribArray(positionLocation);
411
412
GLint colorUniformLocation =
413
glGetUniformLocation(program, angle::essl1_shaders::ColorUniform());
414
ASSERT_NE(colorUniformLocation, -1);
415
416
glUniform4f(colorUniformLocation, 1.0f, 1.0f, 1.0f, 0.5f);
417
418
glBindFramebuffer(GL_FRAMEBUFFER, mFBOs[0]);
419
420
GLTexture texture;
421
glBindTexture(GL_TEXTURE_2D, texture);
422
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, getWindowWidth(), getWindowHeight(), 0, GL_RGBA,
423
GL_UNSIGNED_BYTE, nullptr);
424
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
425
426
// Initially clear to black.
427
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
428
glClear(GL_COLOR_BUFFER_BIT);
429
430
// Clear with masked color.
431
glColorMask(GL_TRUE, GL_FALSE, GL_TRUE, GL_TRUE);
432
glClearColor(0.5f, 0.5f, 0.5f, 0.75f);
433
glClear(GL_COLOR_BUFFER_BIT);
434
ASSERT_GL_NO_ERROR();
435
436
// So far so good, we have an RGBA framebuffer that we've cleared to 0.5 everywhere.
437
EXPECT_PIXEL_NEAR(0, 0, 128, 0, 128, 192, 1.0);
438
439
// In the Vulkan backend, RGB textures are emulated with an RGBA texture format
440
// underneath and we keep a special mask to know that we shouldn't touch the alpha
441
// channel when we have that emulated texture. This test exists to validate that
442
// this mask gets updated correctly when the framebuffer attachment changes.
443
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, getWindowWidth(), getWindowHeight(), 0, GL_RGB,
444
GL_UNSIGNED_BYTE, nullptr);
445
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
446
ASSERT_GL_NO_ERROR();
447
448
glDrawArrays(GL_TRIANGLES, 0, 6);
449
ASSERT_GL_NO_ERROR();
450
451
EXPECT_PIXEL_RECT_EQ(0, 0, getWindowWidth(), getWindowHeight(), GLColor::magenta);
452
}
453
454
// Test clearing a RGB8 Framebuffer with a color mask.
455
TEST_P(ClearTest, RGB8WithMaskFramebuffer)
456
{
457
glBindFramebuffer(GL_FRAMEBUFFER, mFBOs[0]);
458
459
GLTexture texture;
460
461
glBindTexture(GL_TEXTURE_2D, texture);
462
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, getWindowWidth(), getWindowHeight(), 0, GL_RGB,
463
GL_UNSIGNED_BYTE, nullptr);
464
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
465
466
glClearColor(0.2f, 0.4f, 0.6f, 0.8f);
467
glClear(GL_COLOR_BUFFER_BIT);
468
469
// Since there's no alpha, we expect to get 255 back instead of the clear value (204).
470
EXPECT_PIXEL_NEAR(0, 0, 51, 102, 153, 255, 1.0);
471
472
glColorMask(GL_TRUE, GL_TRUE, GL_FALSE, GL_TRUE);
473
glClearColor(0.1f, 0.3f, 0.5f, 0.7f);
474
glClear(GL_COLOR_BUFFER_BIT);
475
476
// The blue channel was masked so its value should be unchanged.
477
EXPECT_PIXEL_NEAR(0, 0, 26, 77, 153, 255, 1.0);
478
479
// Restore default.
480
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
481
}
482
483
TEST_P(ClearTest, ClearIssue)
484
{
485
glEnable(GL_DEPTH_TEST);
486
glDepthFunc(GL_LEQUAL);
487
488
glClearColor(0.0, 1.0, 0.0, 1.0);
489
glClearDepthf(0.0);
490
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
491
492
EXPECT_GL_NO_ERROR();
493
494
glBindFramebuffer(GL_FRAMEBUFFER, mFBOs[0]);
495
496
GLRenderbuffer rbo;
497
glBindRenderbuffer(GL_RENDERBUFFER, rbo);
498
glRenderbufferStorage(GL_RENDERBUFFER, GL_RGB565, 16, 16);
499
500
EXPECT_GL_NO_ERROR();
501
502
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rbo);
503
504
EXPECT_GL_NO_ERROR();
505
506
glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
507
glClearDepthf(1.0f);
508
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
509
510
EXPECT_GL_NO_ERROR();
511
512
glBindFramebuffer(GL_FRAMEBUFFER, 0);
513
glBindBuffer(GL_ARRAY_BUFFER, 0);
514
515
ANGLE_GL_PROGRAM(blueProgram, essl1_shaders::vs::Simple(), essl1_shaders::fs::Blue());
516
drawQuad(blueProgram, essl1_shaders::PositionAttrib(), 0.5f);
517
518
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
519
}
520
521
// Regression test for a bug where "glClearDepthf"'s argument was not clamped
522
// In GLES 2 they where declared as GLclampf and the behaviour is the same in GLES 3.2
523
TEST_P(ClearTest, ClearIsClamped)
524
{
525
glClearDepthf(5.0f);
526
527
GLfloat clear_depth;
528
glGetFloatv(GL_DEPTH_CLEAR_VALUE, &clear_depth);
529
EXPECT_EQ(1.0f, clear_depth);
530
}
531
532
// Regression test for a bug where "glDepthRangef"'s arguments were not clamped
533
// In GLES 2 they where declared as GLclampf and the behaviour is the same in GLES 3.2
534
TEST_P(ClearTest, DepthRangefIsClamped)
535
{
536
glDepthRangef(1.1f, -4.0f);
537
538
GLfloat depth_range[2];
539
glGetFloatv(GL_DEPTH_RANGE, depth_range);
540
EXPECT_EQ(1.0f, depth_range[0]);
541
EXPECT_EQ(0.0f, depth_range[1]);
542
}
543
544
// Test scissored clears on Depth16
545
TEST_P(ClearTest, Depth16Scissored)
546
{
547
GLRenderbuffer renderbuffer;
548
glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer);
549
constexpr int kRenderbufferSize = 64;
550
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, kRenderbufferSize,
551
kRenderbufferSize);
552
553
GLFramebuffer fbo;
554
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
555
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, renderbuffer);
556
557
glClearDepthf(0.0f);
558
glClear(GL_DEPTH_BUFFER_BIT);
559
560
glEnable(GL_SCISSOR_TEST);
561
constexpr int kNumSteps = 13;
562
for (int ndx = 1; ndx < kNumSteps; ndx++)
563
{
564
float perc = static_cast<float>(ndx) / static_cast<float>(kNumSteps);
565
glScissor(0, 0, static_cast<int>(kRenderbufferSize * perc),
566
static_cast<int>(kRenderbufferSize * perc));
567
glClearDepthf(perc);
568
glClear(GL_DEPTH_BUFFER_BIT);
569
}
570
}
571
572
// Test scissored clears on Stencil8
573
TEST_P(ClearTest, Stencil8Scissored)
574
{
575
GLRenderbuffer renderbuffer;
576
glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer);
577
constexpr int kRenderbufferSize = 64;
578
glRenderbufferStorage(GL_RENDERBUFFER, GL_STENCIL_INDEX8, kRenderbufferSize, kRenderbufferSize);
579
580
GLFramebuffer fbo;
581
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
582
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, renderbuffer);
583
584
glClearStencil(0);
585
glClear(GL_STENCIL_BUFFER_BIT);
586
587
glEnable(GL_SCISSOR_TEST);
588
constexpr int kNumSteps = 13;
589
for (int ndx = 1; ndx < kNumSteps; ndx++)
590
{
591
float perc = static_cast<float>(ndx) / static_cast<float>(kNumSteps);
592
glScissor(0, 0, static_cast<int>(kRenderbufferSize * perc),
593
static_cast<int>(kRenderbufferSize * perc));
594
glClearStencil(static_cast<int>(perc * 255.0f));
595
glClear(GL_STENCIL_BUFFER_BIT);
596
}
597
}
598
599
// Covers a bug in the Vulkan back-end where starting a new command buffer in
600
// the masked clear would not trigger descriptor sets to be re-bound.
601
TEST_P(ClearTest, MaskedClearThenDrawWithUniform)
602
{
603
// Initialize a program with a uniform.
604
ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Simple(), essl1_shaders::fs::UniformColor());
605
glUseProgram(program);
606
607
GLint uniLoc = glGetUniformLocation(program, essl1_shaders::ColorUniform());
608
ASSERT_NE(-1, uniLoc);
609
glUniform4f(uniLoc, 0.0f, 1.0f, 0.0f, 1.0f);
610
611
// Initialize position attribute.
612
GLint posLoc = glGetAttribLocation(program, essl1_shaders::PositionAttrib());
613
ASSERT_NE(-1, posLoc);
614
setupQuadVertexBuffer(0.5f, 1.0f);
615
glVertexAttribPointer(posLoc, 3, GL_FLOAT, GL_FALSE, 0, nullptr);
616
glEnableVertexAttribArray(posLoc);
617
618
// Initialize a simple FBO.
619
constexpr GLsizei kSize = 2;
620
GLTexture clearTexture;
621
glBindTexture(GL_TEXTURE_2D, clearTexture);
622
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
623
624
GLFramebuffer fbo;
625
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
626
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, clearTexture, 0);
627
628
glViewport(0, 0, kSize, kSize);
629
630
// Clear and draw to flush out dirty bits.
631
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
632
glClear(GL_COLOR_BUFFER_BIT);
633
634
glDrawArrays(GL_TRIANGLES, 0, 6);
635
636
// Flush to trigger a new serial.
637
glFlush();
638
639
// Enable color mask and draw again to trigger the bug.
640
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE);
641
glClearColor(1.0f, 0.0f, 0.0f, 0.0f);
642
glClear(GL_COLOR_BUFFER_BIT);
643
644
glDrawArrays(GL_TRIANGLES, 0, 6);
645
646
ASSERT_GL_NO_ERROR();
647
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
648
}
649
650
// Clear with a mask to verify that masked clear is done properly
651
// (can't use inline or RenderOp clear when some color channels are masked)
652
TEST_P(ClearTestES3, ClearPlusMaskDrawAndClear)
653
{
654
// Initialize a program with a uniform.
655
ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Simple(), essl1_shaders::fs::UniformColor());
656
glUseProgram(program);
657
658
GLint uniLoc = glGetUniformLocation(program, essl1_shaders::ColorUniform());
659
ASSERT_NE(-1, uniLoc);
660
glUniform4f(uniLoc, 0.0f, 1.0f, 0.0f, 1.0f);
661
662
// Initialize position attribute.
663
GLint posLoc = glGetAttribLocation(program, essl1_shaders::PositionAttrib());
664
ASSERT_NE(-1, posLoc);
665
setupQuadVertexBuffer(0.5f, 1.0f);
666
glVertexAttribPointer(posLoc, 3, GL_FLOAT, GL_FALSE, 0, nullptr);
667
glEnableVertexAttribArray(posLoc);
668
669
// Initialize a simple FBO.
670
constexpr GLsizei kSize = 2;
671
GLTexture clearTexture;
672
glBindTexture(GL_TEXTURE_2D, clearTexture);
673
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
674
675
GLFramebuffer fbo;
676
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
677
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, clearTexture, 0);
678
679
GLRenderbuffer depthStencil;
680
glBindRenderbuffer(GL_RENDERBUFFER, depthStencil);
681
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, kSize, kSize);
682
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
683
depthStencil);
684
ASSERT_GL_NO_ERROR();
685
686
glViewport(0, 0, kSize, kSize);
687
688
// Clear and draw to flush out dirty bits.
689
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
690
glClearDepthf(1.0f);
691
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
692
693
// Draw green rectangle
694
glDrawArrays(GL_TRIANGLES, 0, 6);
695
696
// Enable color mask and draw again to trigger the bug.
697
glColorMask(GL_TRUE, GL_FALSE, GL_TRUE, GL_TRUE);
698
glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
699
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
700
701
// Draw purple-ish rectangle, green should be masked off
702
glUniform4f(uniLoc, 1.0f, 0.25f, 1.0f, 1.0f);
703
glDrawArrays(GL_TRIANGLES, 0, 6);
704
705
ASSERT_GL_NO_ERROR();
706
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::white);
707
}
708
709
// Test that clearing all buffers through glClearColor followed by a clear of a specific buffer
710
// clears to the correct values.
711
TEST_P(ClearTestES3, ClearMultipleAttachmentsFollowedBySpecificOne)
712
{
713
// http://anglebug.com/4092
714
ANGLE_SKIP_TEST_IF(isSwiftshader());
715
constexpr uint32_t kSize = 16;
716
constexpr uint32_t kAttachmentCount = 4;
717
std::vector<unsigned char> pixelData(kSize * kSize * 4, 255);
718
719
glBindFramebuffer(GL_FRAMEBUFFER, mFBOs[0]);
720
721
GLTexture textures[kAttachmentCount];
722
GLenum drawBuffers[kAttachmentCount];
723
GLColor clearValues[kAttachmentCount];
724
725
for (uint32_t i = 0; i < kAttachmentCount; ++i)
726
{
727
glBindTexture(GL_TEXTURE_2D, textures[i]);
728
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
729
pixelData.data());
730
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, GL_TEXTURE_2D, textures[i],
731
0);
732
drawBuffers[i] = GL_COLOR_ATTACHMENT0 + i;
733
734
clearValues[i].R = static_cast<GLubyte>(1 + i * 20);
735
clearValues[i].G = static_cast<GLubyte>(7 + i * 20);
736
clearValues[i].B = static_cast<GLubyte>(12 + i * 20);
737
clearValues[i].A = static_cast<GLubyte>(16 + i * 20);
738
}
739
740
glDrawBuffers(kAttachmentCount, drawBuffers);
741
742
ASSERT_GL_NO_ERROR();
743
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::white);
744
745
// Clear all targets.
746
angle::Vector4 clearColor = clearValues[0].toNormalizedVector();
747
glClearColor(clearColor[0], clearColor[1], clearColor[2], clearColor[3]);
748
glClear(GL_COLOR_BUFFER_BIT);
749
ASSERT_GL_NO_ERROR();
750
751
// Clear odd targets individually.
752
for (uint32_t i = 1; i < kAttachmentCount; i += 2)
753
{
754
clearColor = clearValues[i].toNormalizedVector();
755
glClearBufferfv(GL_COLOR, i, clearColor.data());
756
}
757
758
// Even attachments should be cleared to color 0, while odd attachments are cleared to their
759
// respective color.
760
for (uint32_t i = 0; i < kAttachmentCount; ++i)
761
{
762
glReadBuffer(GL_COLOR_ATTACHMENT0 + i);
763
ASSERT_GL_NO_ERROR();
764
765
uint32_t clearIndex = i % 2 == 0 ? 0 : i;
766
const GLColor &expect = clearValues[clearIndex];
767
768
EXPECT_PIXEL_COLOR_EQ(0, 0, expect);
769
EXPECT_PIXEL_COLOR_EQ(0, kSize - 1, expect);
770
EXPECT_PIXEL_COLOR_EQ(kSize - 1, 0, expect);
771
EXPECT_PIXEL_COLOR_EQ(kSize - 1, kSize - 1, expect);
772
}
773
}
774
775
// Test that clearing each render target individually works. In the Vulkan backend, this should be
776
// done in a single render pass.
777
TEST_P(ClearTestES3, ClearMultipleAttachmentsIndividually)
778
{
779
// http://anglebug.com/4855
780
ANGLE_SKIP_TEST_IF(IsWindows() && IsIntel() && IsVulkan());
781
782
constexpr uint32_t kSize = 16;
783
constexpr uint32_t kAttachmentCount = 2;
784
constexpr float kDepthClearValue = 0.125f;
785
constexpr int32_t kStencilClearValue = 0x67;
786
std::vector<unsigned char> pixelData(kSize * kSize * 4, 255);
787
788
glBindFramebuffer(GL_FRAMEBUFFER, mFBOs[0]);
789
790
GLTexture textures[kAttachmentCount];
791
GLRenderbuffer depthStencil;
792
GLenum drawBuffers[kAttachmentCount];
793
GLColor clearValues[kAttachmentCount];
794
795
for (uint32_t i = 0; i < kAttachmentCount; ++i)
796
{
797
glBindTexture(GL_TEXTURE_2D, textures[i]);
798
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
799
pixelData.data());
800
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, GL_TEXTURE_2D, textures[i],
801
0);
802
drawBuffers[i] = GL_COLOR_ATTACHMENT0 + i;
803
804
clearValues[i].R = static_cast<GLubyte>(1 + i * 20);
805
clearValues[i].G = static_cast<GLubyte>(7 + i * 20);
806
clearValues[i].B = static_cast<GLubyte>(12 + i * 20);
807
clearValues[i].A = static_cast<GLubyte>(16 + i * 20);
808
}
809
810
glBindRenderbuffer(GL_RENDERBUFFER, depthStencil);
811
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, kSize, kSize);
812
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
813
depthStencil);
814
815
glDrawBuffers(kAttachmentCount, drawBuffers);
816
817
ASSERT_GL_NO_ERROR();
818
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::white);
819
820
for (uint32_t i = 0; i < kAttachmentCount; ++i)
821
{
822
glClearBufferfv(GL_COLOR, i, clearValues[i].toNormalizedVector().data());
823
}
824
825
glClearBufferfv(GL_DEPTH, 0, &kDepthClearValue);
826
glClearBufferiv(GL_STENCIL, 0, &kStencilClearValue);
827
ASSERT_GL_NO_ERROR();
828
829
for (uint32_t i = 0; i < kAttachmentCount; ++i)
830
{
831
glReadBuffer(GL_COLOR_ATTACHMENT0 + i);
832
ASSERT_GL_NO_ERROR();
833
834
const GLColor &expect = clearValues[i];
835
836
EXPECT_PIXEL_COLOR_EQ(0, 0, expect);
837
EXPECT_PIXEL_COLOR_EQ(0, kSize - 1, expect);
838
EXPECT_PIXEL_COLOR_EQ(kSize - 1, 0, expect);
839
EXPECT_PIXEL_COLOR_EQ(kSize - 1, kSize - 1, expect);
840
}
841
842
glReadBuffer(GL_COLOR_ATTACHMENT0);
843
for (uint32_t i = 1; i < kAttachmentCount; ++i)
844
drawBuffers[i] = GL_NONE;
845
glDrawBuffers(kAttachmentCount, drawBuffers);
846
847
verifyDepth(kDepthClearValue, kSize);
848
verifyStencil(kStencilClearValue, kSize);
849
}
850
851
// Test that clearing multiple attachments in the presence of a color mask, scissor or both
852
// correctly clears all the attachments.
853
TEST_P(ClearTestES3, MaskedScissoredClearMultipleAttachments)
854
{
855
constexpr uint32_t kSize = 16;
856
constexpr uint32_t kAttachmentCount = 2;
857
std::vector<unsigned char> pixelData(kSize * kSize * 4, 255);
858
859
glBindFramebuffer(GL_FRAMEBUFFER, mFBOs[0]);
860
861
GLTexture textures[kAttachmentCount];
862
GLenum drawBuffers[kAttachmentCount];
863
864
for (uint32_t i = 0; i < kAttachmentCount; ++i)
865
{
866
glBindTexture(GL_TEXTURE_2D, textures[i]);
867
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
868
pixelData.data());
869
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, GL_TEXTURE_2D, textures[i],
870
0);
871
drawBuffers[i] = GL_COLOR_ATTACHMENT0 + i;
872
}
873
874
glDrawBuffers(kAttachmentCount, drawBuffers);
875
876
ASSERT_GL_NO_ERROR();
877
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::white);
878
879
// Masked clear
880
GLColor clearColorMasked(31, 63, 255, 191);
881
angle::Vector4 clearColor = GLColor(31, 63, 127, 191).toNormalizedVector();
882
883
glColorMask(GL_TRUE, GL_TRUE, GL_FALSE, GL_TRUE);
884
glClearColor(clearColor[0], clearColor[1], clearColor[2], clearColor[3]);
885
glClear(GL_COLOR_BUFFER_BIT);
886
ASSERT_GL_NO_ERROR();
887
888
// All attachments should be cleared, with the blue channel untouched
889
for (uint32_t i = 0; i < kAttachmentCount; ++i)
890
{
891
glReadBuffer(GL_COLOR_ATTACHMENT0 + i);
892
ASSERT_GL_NO_ERROR();
893
894
EXPECT_PIXEL_COLOR_EQ(0, 0, clearColorMasked);
895
EXPECT_PIXEL_COLOR_EQ(0, kSize - 1, clearColorMasked);
896
EXPECT_PIXEL_COLOR_EQ(kSize - 1, 0, clearColorMasked);
897
EXPECT_PIXEL_COLOR_EQ(kSize - 1, kSize - 1, clearColorMasked);
898
EXPECT_PIXEL_COLOR_EQ(kSize / 2, kSize / 2, clearColorMasked);
899
}
900
901
// Masked scissored clear
902
GLColor clearColorMaskedScissored(63, 127, 255, 31);
903
clearColor = GLColor(63, 127, 191, 31).toNormalizedVector();
904
905
glClearColor(clearColor[0], clearColor[1], clearColor[2], clearColor[3]);
906
glEnable(GL_SCISSOR_TEST);
907
glScissor(kSize / 6, kSize / 6, kSize / 3, kSize / 3);
908
glClear(GL_COLOR_BUFFER_BIT);
909
ASSERT_GL_NO_ERROR();
910
911
// The corners should keep the previous value while the center is cleared, except its blue
912
// channel.
913
for (uint32_t i = 0; i < kAttachmentCount; ++i)
914
{
915
glReadBuffer(GL_COLOR_ATTACHMENT0 + i);
916
ASSERT_GL_NO_ERROR();
917
918
EXPECT_PIXEL_COLOR_EQ(0, 0, clearColorMasked);
919
EXPECT_PIXEL_COLOR_EQ(0, kSize - 1, clearColorMasked);
920
EXPECT_PIXEL_COLOR_EQ(kSize - 1, 0, clearColorMasked);
921
EXPECT_PIXEL_COLOR_EQ(kSize - 1, kSize - 1, clearColorMasked);
922
EXPECT_PIXEL_COLOR_EQ(kSize / 3, 2 * kSize / 3, clearColorMasked);
923
EXPECT_PIXEL_COLOR_EQ(2 * kSize / 3, kSize / 3, clearColorMasked);
924
EXPECT_PIXEL_COLOR_EQ(2 * kSize / 3, 2 * kSize / 3, clearColorMasked);
925
926
EXPECT_PIXEL_COLOR_EQ(kSize / 3, kSize / 3, clearColorMaskedScissored);
927
}
928
929
// Scissored clear
930
GLColor clearColorScissored(127, 191, 31, 63);
931
clearColor = GLColor(127, 191, 31, 63).toNormalizedVector();
932
933
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
934
glClearColor(clearColor[0], clearColor[1], clearColor[2], clearColor[3]);
935
glClear(GL_COLOR_BUFFER_BIT);
936
ASSERT_GL_NO_ERROR();
937
938
// The corners should keep the old value while all channels of the center are cleared.
939
for (uint32_t i = 0; i < kAttachmentCount; ++i)
940
{
941
glReadBuffer(GL_COLOR_ATTACHMENT0 + i);
942
ASSERT_GL_NO_ERROR();
943
944
EXPECT_PIXEL_COLOR_EQ(0, 0, clearColorMasked);
945
EXPECT_PIXEL_COLOR_EQ(0, kSize - 1, clearColorMasked);
946
EXPECT_PIXEL_COLOR_EQ(kSize - 1, 0, clearColorMasked);
947
EXPECT_PIXEL_COLOR_EQ(kSize - 1, kSize - 1, clearColorMasked);
948
EXPECT_PIXEL_COLOR_EQ(kSize / 3, 2 * kSize / 3, clearColorMasked);
949
EXPECT_PIXEL_COLOR_EQ(2 * kSize / 3, kSize / 3, clearColorMasked);
950
EXPECT_PIXEL_COLOR_EQ(2 * kSize / 3, 2 * kSize / 3, clearColorMasked);
951
952
EXPECT_PIXEL_COLOR_EQ(kSize / 3, kSize / 3, clearColorScissored);
953
}
954
}
955
956
// Test clearing multiple attachments in the presence of an indexed color mask.
957
TEST_P(ClearTestES3, MaskedIndexedClearMultipleAttachments)
958
{
959
ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_OES_draw_buffers_indexed"));
960
961
constexpr uint32_t kSize = 16;
962
constexpr uint32_t kAttachmentCount = 4;
963
std::vector<unsigned char> pixelData(kSize * kSize * 4, 255);
964
965
glBindFramebuffer(GL_FRAMEBUFFER, mFBOs[0]);
966
967
GLTexture textures[kAttachmentCount];
968
GLenum drawBuffers[kAttachmentCount];
969
970
for (uint32_t i = 0; i < kAttachmentCount; ++i)
971
{
972
glBindTexture(GL_TEXTURE_2D, textures[i]);
973
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
974
pixelData.data());
975
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, GL_TEXTURE_2D, textures[i],
976
0);
977
drawBuffers[i] = GL_COLOR_ATTACHMENT0 + i;
978
}
979
980
glDrawBuffers(kAttachmentCount, drawBuffers);
981
982
ASSERT_GL_NO_ERROR();
983
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::white);
984
985
// Masked clear
986
GLColor clearColorMasked(31, 63, 255, 191);
987
angle::Vector4 clearColor = GLColor(31, 63, 127, 191).toNormalizedVector();
988
989
// Block blue channel for all attachements
990
glColorMask(GL_TRUE, GL_TRUE, GL_FALSE, GL_TRUE);
991
992
// Unblock blue channel for attachments 0 and 1
993
glColorMaskiOES(0, GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
994
glColorMaskiOES(1, GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
995
996
glClearColor(clearColor[0], clearColor[1], clearColor[2], clearColor[3]);
997
glClear(GL_COLOR_BUFFER_BIT);
998
ASSERT_GL_NO_ERROR();
999
1000
// All attachments should be cleared, with the blue channel untouched for all attachments but 1.
1001
for (uint32_t i = 0; i < kAttachmentCount; ++i)
1002
{
1003
glReadBuffer(GL_COLOR_ATTACHMENT0 + i);
1004
ASSERT_GL_NO_ERROR();
1005
1006
const GLColor attachmentColor = (i > 1) ? clearColorMasked : clearColor;
1007
EXPECT_PIXEL_COLOR_EQ(0, 0, attachmentColor);
1008
EXPECT_PIXEL_COLOR_EQ(0, kSize - 1, attachmentColor);
1009
EXPECT_PIXEL_COLOR_EQ(kSize - 1, 0, attachmentColor);
1010
EXPECT_PIXEL_COLOR_EQ(kSize - 1, kSize - 1, attachmentColor);
1011
EXPECT_PIXEL_COLOR_EQ(kSize / 2, kSize / 2, attachmentColor);
1012
}
1013
}
1014
1015
// Test that clearing multiple attachments of different nature (float, int and uint) in the
1016
// presence of a color mask works correctly. In the Vulkan backend, this exercises clearWithDraw
1017
// and the relevant internal shaders.
1018
TEST_P(ClearTestES3, MaskedClearHeterogeneousAttachments)
1019
{
1020
// http://anglebug.com/4855
1021
ANGLE_SKIP_TEST_IF(IsWindows() && IsIntel() && IsVulkan());
1022
1023
// TODO(anglebug.com/5491)
1024
ANGLE_SKIP_TEST_IF(IsIOS() && IsOpenGLES());
1025
1026
constexpr uint32_t kSize = 16;
1027
constexpr uint32_t kAttachmentCount = 3;
1028
constexpr float kDepthClearValue = 0.256f;
1029
constexpr int32_t kStencilClearValue = 0x1D;
1030
constexpr GLenum kAttachmentFormats[kAttachmentCount] = {
1031
GL_RGBA8,
1032
GL_RGBA8I,
1033
GL_RGBA8UI,
1034
};
1035
constexpr GLenum kDataFormats[kAttachmentCount] = {
1036
GL_RGBA,
1037
GL_RGBA_INTEGER,
1038
GL_RGBA_INTEGER,
1039
};
1040
constexpr GLenum kDataTypes[kAttachmentCount] = {
1041
GL_UNSIGNED_BYTE,
1042
GL_BYTE,
1043
GL_UNSIGNED_BYTE,
1044
};
1045
1046
std::vector<unsigned char> pixelData(kSize * kSize * 4, 0);
1047
1048
glBindFramebuffer(GL_FRAMEBUFFER, mFBOs[0]);
1049
1050
GLTexture textures[kAttachmentCount];
1051
GLRenderbuffer depthStencil;
1052
GLenum drawBuffers[kAttachmentCount];
1053
1054
for (uint32_t i = 0; i < kAttachmentCount; ++i)
1055
{
1056
glBindTexture(GL_TEXTURE_2D, textures[i]);
1057
glTexImage2D(GL_TEXTURE_2D, 0, kAttachmentFormats[i], kSize, kSize, 0, kDataFormats[i],
1058
kDataTypes[i], pixelData.data());
1059
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, GL_TEXTURE_2D, textures[i],
1060
0);
1061
drawBuffers[i] = GL_COLOR_ATTACHMENT0 + i;
1062
}
1063
1064
glBindRenderbuffer(GL_RENDERBUFFER, depthStencil);
1065
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, kSize, kSize);
1066
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
1067
depthStencil);
1068
1069
glDrawBuffers(kAttachmentCount, drawBuffers);
1070
1071
ASSERT_GL_NO_ERROR();
1072
EXPECT_PIXEL_EQ(0, 0, 0, 0, 0, 0);
1073
1074
// Mask out red for all clears
1075
glColorMask(GL_FALSE, GL_TRUE, GL_TRUE, GL_TRUE);
1076
1077
glClearBufferfv(GL_DEPTH, 0, &kDepthClearValue);
1078
glClearBufferiv(GL_STENCIL, 0, &kStencilClearValue);
1079
1080
GLColor clearValuef = {25, 50, 75, 100};
1081
glClearBufferfv(GL_COLOR, 0, clearValuef.toNormalizedVector().data());
1082
1083
int clearValuei[4] = {10, -20, 30, -40};
1084
glClearBufferiv(GL_COLOR, 1, clearValuei);
1085
1086
uint32_t clearValueui[4] = {50, 60, 70, 80};
1087
glClearBufferuiv(GL_COLOR, 2, clearValueui);
1088
1089
ASSERT_GL_NO_ERROR();
1090
1091
{
1092
glReadBuffer(GL_COLOR_ATTACHMENT0);
1093
ASSERT_GL_NO_ERROR();
1094
1095
GLColor expect = clearValuef;
1096
expect.R = 0;
1097
1098
EXPECT_PIXEL_COLOR_EQ(0, 0, expect);
1099
EXPECT_PIXEL_COLOR_EQ(0, kSize - 1, expect);
1100
EXPECT_PIXEL_COLOR_EQ(kSize - 1, 0, expect);
1101
EXPECT_PIXEL_COLOR_EQ(kSize - 1, kSize - 1, expect);
1102
}
1103
1104
{
1105
glReadBuffer(GL_COLOR_ATTACHMENT1);
1106
ASSERT_GL_NO_ERROR();
1107
1108
EXPECT_PIXEL_8I(0, 0, 0, clearValuei[1], clearValuei[2], clearValuei[3]);
1109
EXPECT_PIXEL_8I(0, kSize - 1, 0, clearValuei[1], clearValuei[2], clearValuei[3]);
1110
EXPECT_PIXEL_8I(kSize - 1, 0, 0, clearValuei[1], clearValuei[2], clearValuei[3]);
1111
EXPECT_PIXEL_8I(kSize - 1, kSize - 1, 0, clearValuei[1], clearValuei[2], clearValuei[3]);
1112
}
1113
1114
{
1115
glReadBuffer(GL_COLOR_ATTACHMENT2);
1116
ASSERT_GL_NO_ERROR();
1117
1118
EXPECT_PIXEL_8UI(0, 0, 0, clearValueui[1], clearValueui[2], clearValueui[3]);
1119
EXPECT_PIXEL_8UI(0, kSize - 1, 0, clearValueui[1], clearValueui[2], clearValueui[3]);
1120
EXPECT_PIXEL_8UI(kSize - 1, 0, 0, clearValueui[1], clearValueui[2], clearValueui[3]);
1121
EXPECT_PIXEL_8UI(kSize - 1, kSize - 1, 0, clearValueui[1], clearValueui[2],
1122
clearValueui[3]);
1123
}
1124
1125
glReadBuffer(GL_COLOR_ATTACHMENT0);
1126
for (uint32_t i = 1; i < kAttachmentCount; ++i)
1127
drawBuffers[i] = GL_NONE;
1128
glDrawBuffers(kAttachmentCount, drawBuffers);
1129
1130
verifyDepth(kDepthClearValue, kSize);
1131
verifyStencil(kStencilClearValue, kSize);
1132
}
1133
1134
// Test that clearing multiple attachments of different nature (float, int and uint) in the
1135
// presence of a scissor test works correctly. In the Vulkan backend, this exercises clearWithDraw
1136
// and the relevant internal shaders.
1137
TEST_P(ClearTestES3, ScissoredClearHeterogeneousAttachments)
1138
{
1139
// http://anglebug.com/4855
1140
ANGLE_SKIP_TEST_IF(IsWindows() && IsIntel() && IsVulkan());
1141
1142
// http://anglebug.com/5116
1143
ANGLE_SKIP_TEST_IF(IsWindows() && (IsOpenGL() || IsD3D11()) && IsAMD());
1144
1145
// http://anglebug.com/5237
1146
ANGLE_SKIP_TEST_IF(IsWindows7() && IsD3D11() && IsNVIDIA());
1147
1148
// TODO(anglebug.com/5491)
1149
ANGLE_SKIP_TEST_IF(IsIOS() && IsOpenGLES());
1150
1151
constexpr uint32_t kSize = 16;
1152
constexpr uint32_t kHalfSize = kSize / 2;
1153
constexpr uint32_t kAttachmentCount = 3;
1154
constexpr float kDepthClearValue = 0.256f;
1155
constexpr int32_t kStencilClearValue = 0x1D;
1156
constexpr GLenum kAttachmentFormats[kAttachmentCount] = {
1157
GL_RGBA8,
1158
GL_RGBA8I,
1159
GL_RGBA8UI,
1160
};
1161
constexpr GLenum kDataFormats[kAttachmentCount] = {
1162
GL_RGBA,
1163
GL_RGBA_INTEGER,
1164
GL_RGBA_INTEGER,
1165
};
1166
constexpr GLenum kDataTypes[kAttachmentCount] = {
1167
GL_UNSIGNED_BYTE,
1168
GL_BYTE,
1169
GL_UNSIGNED_BYTE,
1170
};
1171
1172
std::vector<unsigned char> pixelData(kSize * kSize * 4, 0);
1173
1174
glBindFramebuffer(GL_FRAMEBUFFER, mFBOs[0]);
1175
1176
GLTexture textures[kAttachmentCount];
1177
GLRenderbuffer depthStencil;
1178
GLenum drawBuffers[kAttachmentCount];
1179
1180
for (uint32_t i = 0; i < kAttachmentCount; ++i)
1181
{
1182
glBindTexture(GL_TEXTURE_2D, textures[i]);
1183
glTexImage2D(GL_TEXTURE_2D, 0, kAttachmentFormats[i], kSize, kSize, 0, kDataFormats[i],
1184
kDataTypes[i], pixelData.data());
1185
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, GL_TEXTURE_2D, textures[i],
1186
0);
1187
drawBuffers[i] = GL_COLOR_ATTACHMENT0 + i;
1188
}
1189
1190
glBindRenderbuffer(GL_RENDERBUFFER, depthStencil);
1191
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, kSize, kSize);
1192
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
1193
depthStencil);
1194
1195
glDrawBuffers(kAttachmentCount, drawBuffers);
1196
1197
ASSERT_GL_NO_ERROR();
1198
EXPECT_PIXEL_EQ(0, 0, 0, 0, 0, 0);
1199
1200
// Enable scissor test
1201
glScissor(0, 0, kHalfSize, kHalfSize);
1202
glEnable(GL_SCISSOR_TEST);
1203
1204
GLColor clearValuef = {25, 50, 75, 100};
1205
angle::Vector4 clearValuefv = clearValuef.toNormalizedVector();
1206
1207
glClearColor(clearValuefv.x(), clearValuefv.y(), clearValuefv.z(), clearValuefv.w());
1208
glClearDepthf(kDepthClearValue);
1209
1210
// clear stencil.
1211
glClearBufferiv(GL_STENCIL, 0, &kStencilClearValue);
1212
1213
// clear float color attachment & depth together
1214
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
1215
1216
// clear integer attachment.
1217
int clearValuei[4] = {10, -20, 30, -40};
1218
glClearBufferiv(GL_COLOR, 1, clearValuei);
1219
1220
// clear unsigned integer attachment
1221
uint32_t clearValueui[4] = {50, 60, 70, 80};
1222
glClearBufferuiv(GL_COLOR, 2, clearValueui);
1223
1224
ASSERT_GL_NO_ERROR();
1225
1226
{
1227
glReadBuffer(GL_COLOR_ATTACHMENT0);
1228
ASSERT_GL_NO_ERROR();
1229
1230
GLColor expect = clearValuef;
1231
1232
EXPECT_PIXEL_COLOR_EQ(0, 0, expect);
1233
EXPECT_PIXEL_COLOR_EQ(0, kHalfSize - 1, expect);
1234
EXPECT_PIXEL_COLOR_EQ(kHalfSize - 1, 0, expect);
1235
EXPECT_PIXEL_COLOR_EQ(kHalfSize - 1, kHalfSize - 1, expect);
1236
EXPECT_PIXEL_EQ(kHalfSize + 1, kHalfSize + 1, 0, 0, 0, 0);
1237
}
1238
1239
{
1240
glReadBuffer(GL_COLOR_ATTACHMENT1);
1241
ASSERT_GL_NO_ERROR();
1242
1243
EXPECT_PIXEL_8I(0, 0, clearValuei[0], clearValuei[1], clearValuei[2], clearValuei[3]);
1244
EXPECT_PIXEL_8I(0, kHalfSize - 1, clearValuei[0], clearValuei[1], clearValuei[2],
1245
clearValuei[3]);
1246
EXPECT_PIXEL_8I(kHalfSize - 1, 0, clearValuei[0], clearValuei[1], clearValuei[2],
1247
clearValuei[3]);
1248
EXPECT_PIXEL_8I(kHalfSize - 1, kHalfSize - 1, clearValuei[0], clearValuei[1],
1249
clearValuei[2], clearValuei[3]);
1250
EXPECT_PIXEL_8I(kHalfSize + 1, kHalfSize + 1, 0, 0, 0, 0);
1251
}
1252
1253
{
1254
glReadBuffer(GL_COLOR_ATTACHMENT2);
1255
ASSERT_GL_NO_ERROR();
1256
1257
EXPECT_PIXEL_8UI(0, 0, clearValueui[0], clearValueui[1], clearValueui[2], clearValueui[3]);
1258
EXPECT_PIXEL_8UI(0, kHalfSize - 1, clearValueui[0], clearValueui[1], clearValueui[2],
1259
clearValueui[3]);
1260
EXPECT_PIXEL_8UI(kHalfSize - 1, 0, clearValueui[0], clearValueui[1], clearValueui[2],
1261
clearValueui[3]);
1262
EXPECT_PIXEL_8UI(kHalfSize - 1, kHalfSize - 1, clearValueui[0], clearValueui[1],
1263
clearValueui[2], clearValueui[3]);
1264
EXPECT_PIXEL_8UI(kHalfSize + 1, kHalfSize + 1, 0, 0, 0, 0);
1265
}
1266
1267
glReadBuffer(GL_COLOR_ATTACHMENT0);
1268
for (uint32_t i = 1; i < kAttachmentCount; ++i)
1269
drawBuffers[i] = GL_NONE;
1270
glDrawBuffers(kAttachmentCount, drawBuffers);
1271
1272
verifyDepth(kDepthClearValue, kHalfSize);
1273
verifyStencil(kStencilClearValue, kHalfSize);
1274
}
1275
1276
// This tests a bug where in a masked clear when calling "ClearBuffer", we would
1277
// mistakenly clear every channel (including the masked-out ones)
1278
TEST_P(ClearTestES3, MaskedClearBufferBug)
1279
{
1280
// TODO(syoussefi): Qualcomm driver crashes in the presence of VK_ATTACHMENT_UNUSED.
1281
// http://anglebug.com/3423
1282
ANGLE_SKIP_TEST_IF(IsVulkan() && IsAndroid());
1283
1284
unsigned char pixelData[] = {255, 255, 255, 255};
1285
1286
glBindFramebuffer(GL_FRAMEBUFFER, mFBOs[0]);
1287
1288
GLTexture textures[2];
1289
1290
glBindTexture(GL_TEXTURE_2D, textures[0]);
1291
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixelData);
1292
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0], 0);
1293
1294
glBindTexture(GL_TEXTURE_2D, textures[1]);
1295
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixelData);
1296
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, textures[1], 0);
1297
1298
ASSERT_GL_NO_ERROR();
1299
EXPECT_PIXEL_EQ(0, 0, 255, 255, 255, 255);
1300
1301
float clearValue[] = {0, 0.5f, 0.5f, 1.0f};
1302
GLenum drawBuffers[] = {GL_NONE, GL_COLOR_ATTACHMENT1};
1303
glDrawBuffers(2, drawBuffers);
1304
glColorMask(GL_TRUE, GL_TRUE, GL_FALSE, GL_TRUE);
1305
glClearBufferfv(GL_COLOR, 1, clearValue);
1306
1307
ASSERT_GL_NO_ERROR();
1308
EXPECT_PIXEL_EQ(0, 0, 255, 255, 255, 255);
1309
1310
glReadBuffer(GL_COLOR_ATTACHMENT1);
1311
ASSERT_GL_NO_ERROR();
1312
1313
EXPECT_PIXEL_NEAR(0, 0, 0, 127, 255, 255, 1);
1314
}
1315
1316
TEST_P(ClearTestES3, BadFBOSerialBug)
1317
{
1318
// First make a simple framebuffer, and clear it to green
1319
glBindFramebuffer(GL_FRAMEBUFFER, mFBOs[0]);
1320
1321
GLTexture textures[2];
1322
1323
glBindTexture(GL_TEXTURE_2D, textures[0]);
1324
glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, getWindowWidth(), getWindowHeight());
1325
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0], 0);
1326
1327
GLenum drawBuffers[] = {GL_COLOR_ATTACHMENT0};
1328
glDrawBuffers(1, drawBuffers);
1329
1330
float clearValues1[] = {0.0f, 1.0f, 0.0f, 1.0f};
1331
glClearBufferfv(GL_COLOR, 0, clearValues1);
1332
1333
ASSERT_GL_NO_ERROR();
1334
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1335
1336
// Next make a second framebuffer, and draw it to red
1337
// (Triggers bad applied render target serial)
1338
GLFramebuffer fbo2;
1339
glBindFramebuffer(GL_FRAMEBUFFER, fbo2);
1340
ASSERT_GL_NO_ERROR();
1341
1342
glBindTexture(GL_TEXTURE_2D, textures[1]);
1343
glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, getWindowWidth(), getWindowHeight());
1344
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[1], 0);
1345
1346
glDrawBuffers(1, drawBuffers);
1347
1348
ANGLE_GL_PROGRAM(blueProgram, essl1_shaders::vs::Simple(), essl1_shaders::fs::Red());
1349
drawQuad(blueProgram, essl1_shaders::PositionAttrib(), 0.5f);
1350
1351
ASSERT_GL_NO_ERROR();
1352
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
1353
1354
// Check that the first framebuffer is still green.
1355
glBindFramebuffer(GL_FRAMEBUFFER, mFBOs[0]);
1356
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1357
}
1358
1359
// Test that SRGB framebuffers clear to the linearized clear color
1360
TEST_P(ClearTestES3, SRGBClear)
1361
{
1362
// First make a simple framebuffer, and clear it
1363
glBindFramebuffer(GL_FRAMEBUFFER, mFBOs[0]);
1364
1365
GLTexture texture;
1366
1367
glBindTexture(GL_TEXTURE_2D, texture);
1368
glTexStorage2D(GL_TEXTURE_2D, 1, GL_SRGB8_ALPHA8, getWindowWidth(), getWindowHeight());
1369
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
1370
1371
glClearColor(0.5f, 0.5f, 0.5f, 0.5f);
1372
glClear(GL_COLOR_BUFFER_BIT);
1373
1374
EXPECT_PIXEL_NEAR(0, 0, 188, 188, 188, 128, 1.0);
1375
}
1376
1377
// Test that framebuffers with mixed SRGB/Linear attachments clear to the correct color for each
1378
// attachment
1379
TEST_P(ClearTestES3, MixedSRGBClear)
1380
{
1381
glBindFramebuffer(GL_FRAMEBUFFER, mFBOs[0]);
1382
1383
GLTexture textures[2];
1384
1385
glBindTexture(GL_TEXTURE_2D, textures[0]);
1386
glTexStorage2D(GL_TEXTURE_2D, 1, GL_SRGB8_ALPHA8, getWindowWidth(), getWindowHeight());
1387
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0], 0);
1388
1389
glBindTexture(GL_TEXTURE_2D, textures[1]);
1390
glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, getWindowWidth(), getWindowHeight());
1391
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, textures[1], 0);
1392
1393
GLenum drawBuffers[] = {GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1};
1394
glDrawBuffers(2, drawBuffers);
1395
1396
// Clear both textures
1397
glClearColor(0.5f, 0.5f, 0.5f, 0.5f);
1398
glClear(GL_COLOR_BUFFER_BIT);
1399
1400
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0);
1401
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, 0, 0);
1402
1403
// Check value of texture0
1404
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0], 0);
1405
EXPECT_PIXEL_NEAR(0, 0, 188, 188, 188, 128, 1.0);
1406
1407
// Check value of texture1
1408
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[1], 0);
1409
EXPECT_PIXEL_NEAR(0, 0, 128, 128, 128, 128, 1.0);
1410
}
1411
1412
// This test covers a D3D11 bug where calling ClearRenderTargetView sometimes wouldn't sync
1413
// before a draw call. The test draws small quads to a larger FBO (the default back buffer).
1414
// Before each blit to the back buffer it clears the quad to a certain color using
1415
// ClearBufferfv to give a solid color. The sync problem goes away if we insert a call to
1416
// flush or finish after ClearBufferfv or each draw.
1417
TEST_P(ClearTestES3, RepeatedClear)
1418
{
1419
// Fails on 431.02 driver. http://anglebug.com/3748
1420
ANGLE_SKIP_TEST_IF(IsWindows() && IsNVIDIA() && IsVulkan());
1421
ANGLE_SKIP_TEST_IF(IsARM64() && IsWindows() && IsD3D());
1422
1423
constexpr char kVS[] =
1424
"#version 300 es\n"
1425
"in highp vec2 position;\n"
1426
"out highp vec2 v_coord;\n"
1427
"void main(void)\n"
1428
"{\n"
1429
" gl_Position = vec4(position, 0, 1);\n"
1430
" vec2 texCoord = (position * 0.5) + 0.5;\n"
1431
" v_coord = texCoord;\n"
1432
"}\n";
1433
1434
constexpr char kFS[] =
1435
"#version 300 es\n"
1436
"in highp vec2 v_coord;\n"
1437
"out highp vec4 color;\n"
1438
"uniform sampler2D tex;\n"
1439
"void main()\n"
1440
"{\n"
1441
" color = texture(tex, v_coord);\n"
1442
"}\n";
1443
1444
ANGLE_GL_PROGRAM(program, kVS, kFS);
1445
1446
mTextures.resize(1, 0);
1447
glGenTextures(1, mTextures.data());
1448
1449
GLenum format = GL_RGBA8;
1450
const int numRowsCols = 3;
1451
const int cellSize = 32;
1452
const int fboSize = cellSize;
1453
const int backFBOSize = cellSize * numRowsCols;
1454
const float fmtValueMin = 0.0f;
1455
const float fmtValueMax = 1.0f;
1456
1457
glBindTexture(GL_TEXTURE_2D, mTextures[0]);
1458
glTexStorage2D(GL_TEXTURE_2D, 1, format, fboSize, fboSize);
1459
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1460
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1461
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1462
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1463
ASSERT_GL_NO_ERROR();
1464
1465
glBindFramebuffer(GL_FRAMEBUFFER, mFBOs[0]);
1466
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[0], 0);
1467
ASSERT_GL_NO_ERROR();
1468
1469
ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
1470
1471
// larger fbo bound -- clear to transparent black
1472
glUseProgram(program);
1473
GLint uniLoc = glGetUniformLocation(program, "tex");
1474
ASSERT_NE(-1, uniLoc);
1475
glUniform1i(uniLoc, 0);
1476
glBindTexture(GL_TEXTURE_2D, mTextures[0]);
1477
1478
GLint positionLocation = glGetAttribLocation(program, "position");
1479
ASSERT_NE(-1, positionLocation);
1480
1481
glUseProgram(program);
1482
1483
for (int cellY = 0; cellY < numRowsCols; cellY++)
1484
{
1485
for (int cellX = 0; cellX < numRowsCols; cellX++)
1486
{
1487
int seed = cellX + cellY * numRowsCols;
1488
const Vector4 color = RandomVec4(seed, fmtValueMin, fmtValueMax);
1489
1490
glBindFramebuffer(GL_FRAMEBUFFER, mFBOs[0]);
1491
glClearBufferfv(GL_COLOR, 0, color.data());
1492
1493
glBindFramebuffer(GL_FRAMEBUFFER, 0);
1494
1495
// Method 1: Set viewport and draw full-viewport quad
1496
glViewport(cellX * cellSize, cellY * cellSize, cellSize, cellSize);
1497
drawQuad(program, "position", 0.5f);
1498
1499
// Uncommenting the glFinish call seems to make the test pass.
1500
// glFinish();
1501
}
1502
}
1503
1504
std::vector<GLColor> pixelData(backFBOSize * backFBOSize);
1505
glReadPixels(0, 0, backFBOSize, backFBOSize, GL_RGBA, GL_UNSIGNED_BYTE, pixelData.data());
1506
1507
for (int cellY = 0; cellY < numRowsCols; cellY++)
1508
{
1509
for (int cellX = 0; cellX < numRowsCols; cellX++)
1510
{
1511
int seed = cellX + cellY * numRowsCols;
1512
const Vector4 color = RandomVec4(seed, fmtValueMin, fmtValueMax);
1513
GLColor expectedColor(color);
1514
1515
int testN = cellX * cellSize + cellY * backFBOSize * cellSize + backFBOSize + 1;
1516
GLColor actualColor = pixelData[testN];
1517
EXPECT_NEAR(expectedColor.R, actualColor.R, 1);
1518
EXPECT_NEAR(expectedColor.G, actualColor.G, 1);
1519
EXPECT_NEAR(expectedColor.B, actualColor.B, 1);
1520
EXPECT_NEAR(expectedColor.A, actualColor.A, 1);
1521
}
1522
}
1523
1524
ASSERT_GL_NO_ERROR();
1525
}
1526
1527
// Test that clearing RGB8 attachments from a 2D texture array does not cause
1528
// VUID-VkImageMemoryBarrier-oldLayout-01197
1529
TEST_P(ClearTestES3, TextureArrayRGB8)
1530
{
1531
GLFramebuffer fb;
1532
glBindFramebuffer(GL_FRAMEBUFFER, fb);
1533
1534
GLTexture tex;
1535
glBindTexture(GL_TEXTURE_2D_ARRAY, tex);
1536
glTexStorage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGB8, 1, 1, 2);
1537
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1538
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1539
1540
glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, tex, 0, 0);
1541
glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, tex, 0, 1);
1542
1543
ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER);
1544
1545
GLenum bufs[2] = {GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1};
1546
glDrawBuffers(2, &bufs[0]);
1547
1548
glClearColor(1.0, 0.0, 1.0, 1.0);
1549
glClear(GL_COLOR_BUFFER_BIT);
1550
ASSERT_GL_NO_ERROR();
1551
1552
glBindFramebuffer(GL_READ_FRAMEBUFFER, fb);
1553
1554
glReadBuffer(GL_COLOR_ATTACHMENT0);
1555
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::magenta);
1556
1557
glReadBuffer(GL_COLOR_ATTACHMENT1);
1558
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::magenta);
1559
1560
EXPECT_GL_NO_ERROR();
1561
}
1562
1563
void MaskedScissoredClearTestBase::maskedScissoredColorDepthStencilClear(
1564
const MaskedScissoredClearVariationsTestParams &params)
1565
{
1566
// Flaky on Android Nexus 5x and Pixel 2, possible Qualcomm driver bug.
1567
// TODO(jmadill): Re-enable when possible. http://anglebug.com/2548
1568
ANGLE_SKIP_TEST_IF(IsOpenGLES() && IsAndroid());
1569
1570
const int w = getWindowWidth();
1571
const int h = getWindowHeight();
1572
const int wthird = w / 3;
1573
const int hthird = h / 3;
1574
1575
constexpr float kPreClearDepth = 0.9f;
1576
constexpr float kClearDepth = 0.5f;
1577
constexpr uint8_t kPreClearStencil = 0xFF;
1578
constexpr uint8_t kClearStencil = 0x16;
1579
constexpr uint8_t kStencilMask = 0x59;
1580
constexpr uint8_t kMaskedClearStencil =
1581
(kPreClearStencil & ~kStencilMask) | (kClearStencil & kStencilMask);
1582
1583
bool clearColor, clearDepth, clearStencil;
1584
bool maskColor, maskDepth, maskStencil;
1585
bool scissor;
1586
1587
ParseMaskedScissoredClearVariationsTestParams(params, &clearColor, &clearDepth, &clearStencil,
1588
&maskColor, &maskDepth, &maskStencil, &scissor);
1589
1590
// clearDepth && !maskDepth fails on Intel Ubuntu 19.04 Mesa 19.0.2 GL. http://anglebug.com/3614
1591
ANGLE_SKIP_TEST_IF(IsLinux() && IsIntel() && IsDesktopOpenGL() && clearDepth && !maskDepth);
1592
1593
// Clear to a random color, 0.9 depth and 0x00 stencil
1594
Vector4 color1(0.1f, 0.2f, 0.3f, 0.4f);
1595
GLColor color1RGB(color1);
1596
1597
glClearColor(color1[0], color1[1], color1[2], color1[3]);
1598
glClearDepthf(kPreClearDepth);
1599
glClearStencil(kPreClearStencil);
1600
1601
if (!clearColor)
1602
{
1603
// If not asked to clear color, clear it anyway, but individually. The clear value is
1604
// still used to verify that the depth/stencil clear happened correctly. This allows
1605
// testing for depth/stencil-only clear implementations.
1606
glClear(GL_COLOR_BUFFER_BIT);
1607
}
1608
1609
glClear((clearColor ? GL_COLOR_BUFFER_BIT : 0) | (clearDepth ? GL_DEPTH_BUFFER_BIT : 0) |
1610
(clearStencil ? GL_STENCIL_BUFFER_BIT : 0));
1611
ASSERT_GL_NO_ERROR();
1612
1613
// Verify color was cleared correctly.
1614
EXPECT_PIXEL_COLOR_NEAR(0, 0, color1RGB, 1);
1615
1616
if (scissor)
1617
{
1618
glEnable(GL_SCISSOR_TEST);
1619
glScissor(wthird / 2, hthird / 2, wthird, hthird);
1620
}
1621
1622
// Use color and stencil masks to clear to a second color, 0.5 depth and 0x59 stencil.
1623
Vector4 color2(0.2f, 0.4f, 0.6f, 0.8f);
1624
GLColor color2RGB(color2);
1625
glClearColor(color2[0], color2[1], color2[2], color2[3]);
1626
glClearDepthf(kClearDepth);
1627
glClearStencil(kClearStencil);
1628
if (maskColor)
1629
{
1630
glColorMask(GL_TRUE, GL_FALSE, GL_TRUE, GL_FALSE);
1631
}
1632
if (maskDepth)
1633
{
1634
glDepthMask(GL_FALSE);
1635
}
1636
if (maskStencil)
1637
{
1638
glStencilMask(kStencilMask);
1639
}
1640
glClear((clearColor ? GL_COLOR_BUFFER_BIT : 0) | (clearDepth ? GL_DEPTH_BUFFER_BIT : 0) |
1641
(clearStencil ? GL_STENCIL_BUFFER_BIT : 0));
1642
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
1643
glDepthMask(GL_TRUE);
1644
glStencilMask(0xFF);
1645
glDisable(GL_DEPTH_TEST);
1646
glDisable(GL_STENCIL_TEST);
1647
glDisable(GL_SCISSOR_TEST);
1648
ASSERT_GL_NO_ERROR();
1649
1650
GLColor color2MaskedRGB(color2RGB[0], color1RGB[1], color2RGB[2], color1RGB[3]);
1651
1652
// If not clearing color, the original color should be left both in the center and corners. If
1653
// using a scissor, the corners should be left to the original color, while the center is
1654
// possibly changed. If using a mask, the center (and corners if not scissored), changes to
1655
// the masked results.
1656
GLColor expectedCenterColorRGB =
1657
!clearColor ? color1RGB : maskColor ? color2MaskedRGB : color2RGB;
1658
GLColor expectedCornerColorRGB = scissor ? color1RGB : expectedCenterColorRGB;
1659
1660
// Verify second clear color mask worked as expected.
1661
EXPECT_PIXEL_COLOR_NEAR(wthird, hthird, expectedCenterColorRGB, 1);
1662
1663
EXPECT_PIXEL_COLOR_NEAR(0, 0, expectedCornerColorRGB, 1);
1664
EXPECT_PIXEL_COLOR_NEAR(w - 1, 0, expectedCornerColorRGB, 1);
1665
EXPECT_PIXEL_COLOR_NEAR(0, h - 1, expectedCornerColorRGB, 1);
1666
EXPECT_PIXEL_COLOR_NEAR(w - 1, h - 1, expectedCornerColorRGB, 1);
1667
EXPECT_PIXEL_COLOR_NEAR(wthird, 2 * hthird, expectedCornerColorRGB, 1);
1668
EXPECT_PIXEL_COLOR_NEAR(2 * wthird, hthird, expectedCornerColorRGB, 1);
1669
EXPECT_PIXEL_COLOR_NEAR(2 * wthird, 2 * hthird, expectedCornerColorRGB, 1);
1670
1671
// If there is depth, but depth is not asked to be cleared, the depth buffer contains garbage,
1672
// so no particular behavior can be expected.
1673
if (clearDepth || !mHasDepth)
1674
{
1675
// We use a small shader to verify depth.
1676
ANGLE_GL_PROGRAM(depthTestProgram, essl1_shaders::vs::Passthrough(),
1677
essl1_shaders::fs::Blue());
1678
glEnable(GL_DEPTH_TEST);
1679
glDepthFunc(maskDepth ? GL_GREATER : GL_EQUAL);
1680
// - If depth is cleared, but it's masked, kPreClearDepth should be in the depth buffer.
1681
// - If depth is cleared, but it's not masked, kClearDepth should be in the depth buffer.
1682
// - If depth is not cleared, the if above ensures there is no depth buffer at all,
1683
// which means depth test will always pass.
1684
drawQuad(depthTestProgram, essl1_shaders::PositionAttrib(), maskDepth ? 1.0f : 0.0f);
1685
glDisable(GL_DEPTH_TEST);
1686
ASSERT_GL_NO_ERROR();
1687
1688
// Either way, we expect blue to be written to the center.
1689
expectedCenterColorRGB = GLColor::blue;
1690
// If there is no depth, depth test always passes so the whole image must be blue. Same if
1691
// depth write is masked.
1692
expectedCornerColorRGB =
1693
mHasDepth && scissor && !maskDepth ? expectedCornerColorRGB : GLColor::blue;
1694
1695
EXPECT_PIXEL_COLOR_NEAR(wthird, hthird, expectedCenterColorRGB, 1);
1696
1697
EXPECT_PIXEL_COLOR_NEAR(0, 0, expectedCornerColorRGB, 1);
1698
EXPECT_PIXEL_COLOR_NEAR(w - 1, 0, expectedCornerColorRGB, 1);
1699
EXPECT_PIXEL_COLOR_NEAR(0, h - 1, expectedCornerColorRGB, 1);
1700
EXPECT_PIXEL_COLOR_NEAR(w - 1, h - 1, expectedCornerColorRGB, 1);
1701
EXPECT_PIXEL_COLOR_NEAR(wthird, 2 * hthird, expectedCornerColorRGB, 1);
1702
EXPECT_PIXEL_COLOR_NEAR(2 * wthird, hthird, expectedCornerColorRGB, 1);
1703
EXPECT_PIXEL_COLOR_NEAR(2 * wthird, 2 * hthird, expectedCornerColorRGB, 1);
1704
}
1705
1706
// If there is stencil, but it's not asked to be cleared, there is similarly no expectation.
1707
if (clearStencil || !mHasStencil)
1708
{
1709
// And another small shader to verify stencil.
1710
ANGLE_GL_PROGRAM(stencilTestProgram, essl1_shaders::vs::Passthrough(),
1711
essl1_shaders::fs::Green());
1712
glEnable(GL_STENCIL_TEST);
1713
// - If stencil is cleared, but it's masked, kMaskedClearStencil should be in the stencil
1714
// buffer.
1715
// - If stencil is cleared, but it's not masked, kClearStencil should be in the stencil
1716
// buffer.
1717
// - If stencil is not cleared, the if above ensures there is no stencil buffer at all,
1718
// which means stencil test will always pass.
1719
glStencilFunc(GL_EQUAL, maskStencil ? kMaskedClearStencil : kClearStencil, 0xFF);
1720
drawQuad(stencilTestProgram, essl1_shaders::PositionAttrib(), 0.0f);
1721
glDisable(GL_STENCIL_TEST);
1722
ASSERT_GL_NO_ERROR();
1723
1724
// Either way, we expect green to be written to the center.
1725
expectedCenterColorRGB = GLColor::green;
1726
// If there is no stencil, stencil test always passes so the whole image must be green.
1727
expectedCornerColorRGB = mHasStencil && scissor ? expectedCornerColorRGB : GLColor::green;
1728
1729
EXPECT_PIXEL_COLOR_NEAR(wthird, hthird, expectedCenterColorRGB, 1);
1730
1731
EXPECT_PIXEL_COLOR_NEAR(0, 0, expectedCornerColorRGB, 1);
1732
EXPECT_PIXEL_COLOR_NEAR(w - 1, 0, expectedCornerColorRGB, 1);
1733
EXPECT_PIXEL_COLOR_NEAR(0, h - 1, expectedCornerColorRGB, 1);
1734
EXPECT_PIXEL_COLOR_NEAR(w - 1, h - 1, expectedCornerColorRGB, 1);
1735
EXPECT_PIXEL_COLOR_NEAR(wthird, 2 * hthird, expectedCornerColorRGB, 1);
1736
EXPECT_PIXEL_COLOR_NEAR(2 * wthird, hthird, expectedCornerColorRGB, 1);
1737
EXPECT_PIXEL_COLOR_NEAR(2 * wthird, 2 * hthird, expectedCornerColorRGB, 1);
1738
}
1739
}
1740
1741
// Tests combinations of color, depth, stencil clears with or without masks or scissor.
1742
TEST_P(MaskedScissoredClearTest, Test)
1743
{
1744
maskedScissoredColorDepthStencilClear(GetParam());
1745
}
1746
1747
// Tests combinations of color, depth, stencil clears with or without masks or scissor.
1748
//
1749
// This uses depth/stencil attachments that are single-channel, but are emulated with a format
1750
// that has both channels.
1751
TEST_P(VulkanClearTest, Test)
1752
{
1753
bool clearColor, clearDepth, clearStencil;
1754
bool maskColor, maskDepth, maskStencil;
1755
bool scissor;
1756
1757
ParseMaskedScissoredClearVariationsTestParams(GetParam(), &clearColor, &clearDepth,
1758
&clearStencil, &maskColor, &maskDepth,
1759
&maskStencil, &scissor);
1760
1761
// We only care about clearing depth xor stencil.
1762
if (clearDepth == clearStencil)
1763
{
1764
return;
1765
}
1766
1767
if (clearDepth)
1768
{
1769
// Creating a depth-only renderbuffer is an ES3 feature.
1770
ANGLE_SKIP_TEST_IF(getClientMajorVersion() < 3);
1771
bindColorDepthFBO();
1772
}
1773
else
1774
{
1775
bindColorStencilFBO();
1776
}
1777
1778
maskedScissoredColorDepthStencilClear(GetParam());
1779
}
1780
1781
// Tests that clearing a non existing attachment works.
1782
TEST_P(ClearTest, ClearColorThenClearNonExistingDepthStencil)
1783
{
1784
constexpr GLsizei kSize = 16;
1785
1786
GLTexture color;
1787
glBindTexture(GL_TEXTURE_2D, color);
1788
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1789
1790
GLFramebuffer fbo;
1791
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
1792
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, color, 0);
1793
ASSERT_GL_NO_ERROR();
1794
ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER);
1795
1796
// Clear color.
1797
glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
1798
glClear(GL_COLOR_BUFFER_BIT);
1799
1800
// Clear depth/stencil.
1801
glClear(GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
1802
ASSERT_GL_NO_ERROR();
1803
1804
// Read back color.
1805
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
1806
}
1807
1808
// Tests that clearing a non existing attachment works.
1809
TEST_P(ClearTestES3, ClearDepthStencilThenClearNonExistingColor)
1810
{
1811
constexpr GLsizei kSize = 16;
1812
1813
GLRenderbuffer depth;
1814
glBindRenderbuffer(GL_RENDERBUFFER, depth);
1815
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, kSize, kSize);
1816
1817
GLFramebuffer fbo;
1818
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
1819
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, depth);
1820
ASSERT_GL_NO_ERROR();
1821
ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER);
1822
1823
// Clear depth/stencil.
1824
glClearDepthf(1.0f);
1825
glClearStencil(0xAA);
1826
glClear(GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
1827
ASSERT_GL_NO_ERROR();
1828
1829
// Clear color.
1830
glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
1831
glClear(GL_COLOR_BUFFER_BIT);
1832
ASSERT_GL_NO_ERROR();
1833
}
1834
1835
// Test that just clearing a nonexistent drawbuffer of the default framebuffer doesn't cause an
1836
// assert.
1837
TEST_P(ClearTestES3, ClearBuffer1OnDefaultFramebufferNoAssert)
1838
{
1839
std::vector<GLuint> testUint(4);
1840
glClearBufferuiv(GL_COLOR, 1, testUint.data());
1841
std::vector<GLint> testInt(4);
1842
glClearBufferiv(GL_COLOR, 1, testInt.data());
1843
std::vector<GLfloat> testFloat(4);
1844
glClearBufferfv(GL_COLOR, 1, testFloat.data());
1845
EXPECT_GL_NO_ERROR();
1846
}
1847
1848
// Clears many small concentric rectangles using scissor regions.
1849
TEST_P(ClearTest, InceptionScissorClears)
1850
{
1851
angle::RNG rng;
1852
1853
constexpr GLuint kSize = 16;
1854
1855
// Create a square user FBO so we have more control over the dimensions.
1856
GLFramebuffer fbo;
1857
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
1858
1859
GLRenderbuffer rbo;
1860
glBindRenderbuffer(GL_RENDERBUFFER, rbo);
1861
glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, kSize, kSize);
1862
1863
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rbo);
1864
ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER);
1865
1866
glViewport(0, 0, kSize, kSize);
1867
1868
// Draw small concentric squares using scissor.
1869
std::vector<GLColor> expectedColors;
1870
for (GLuint index = 0; index < (kSize - 1) / 2; index++)
1871
{
1872
// Do the first clear without the scissor.
1873
if (index > 0)
1874
{
1875
glEnable(GL_SCISSOR_TEST);
1876
glScissor(index, index, kSize - (index * 2), kSize - (index * 2));
1877
}
1878
1879
GLColor color = RandomColor(&rng);
1880
expectedColors.push_back(color);
1881
Vector4 floatColor = color.toNormalizedVector();
1882
glClearColor(floatColor[0], floatColor[1], floatColor[2], floatColor[3]);
1883
glClear(GL_COLOR_BUFFER_BIT);
1884
}
1885
1886
ASSERT_GL_NO_ERROR();
1887
1888
std::vector<GLColor> actualColors(expectedColors.size());
1889
glReadPixels(0, kSize / 2, actualColors.size(), 1, GL_RGBA, GL_UNSIGNED_BYTE,
1890
actualColors.data());
1891
1892
EXPECT_EQ(expectedColors, actualColors);
1893
}
1894
1895
// Test that clearBuffer with disabled non-zero drawbuffer or disabled read source doesn't cause an
1896
// assert.
1897
TEST_P(ClearTestES3, ClearDisabledNonZeroAttachmentNoAssert)
1898
{
1899
// http://anglebug.com/4612
1900
ANGLE_SKIP_TEST_IF(IsOSX() && IsDesktopOpenGL());
1901
1902
GLFramebuffer fb;
1903
glBindFramebuffer(GL_FRAMEBUFFER, fb);
1904
1905
GLRenderbuffer rb;
1906
glBindRenderbuffer(GL_RENDERBUFFER, rb);
1907
glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, 16, 16);
1908
1909
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_RENDERBUFFER, rb);
1910
glDrawBuffers(0, nullptr);
1911
glReadBuffer(GL_NONE);
1912
1913
ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER);
1914
1915
float clearColorf[4] = {0.5, 0.5, 0.5, 0.5};
1916
glClearBufferfv(GL_COLOR, 1, clearColorf);
1917
1918
GLuint clearColorui[4] = {255, 255, 255, 255};
1919
glClearBufferuiv(GL_COLOR, 1, clearColorui);
1920
1921
GLint clearColori[4] = {-127, -127, -127, -127};
1922
glClearBufferiv(GL_COLOR, 1, clearColori);
1923
1924
EXPECT_GL_NO_ERROR();
1925
}
1926
1927
// Test that having a framebuffer with maximum number of attachments and clearing color, depth and
1928
// stencil works.
1929
TEST_P(ClearTestES3, ClearMaxAttachments)
1930
{
1931
// http://anglebug.com/4612
1932
ANGLE_SKIP_TEST_IF(IsOSX() && IsDesktopOpenGL());
1933
// http://anglebug.com/5397
1934
ANGLE_SKIP_TEST_IF(IsAMD() && IsD3D11());
1935
1936
constexpr GLsizei kSize = 16;
1937
1938
GLint maxDrawBuffers = 0;
1939
glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers);
1940
ASSERT_GE(maxDrawBuffers, 4);
1941
1942
// Setup framebuffer.
1943
GLFramebuffer fb;
1944
glBindFramebuffer(GL_FRAMEBUFFER, fb);
1945
1946
std::vector<GLRenderbuffer> color(maxDrawBuffers);
1947
std::vector<GLenum> drawBuffers(maxDrawBuffers);
1948
1949
for (GLint colorIndex = 0; colorIndex < maxDrawBuffers; ++colorIndex)
1950
{
1951
glBindRenderbuffer(GL_RENDERBUFFER, color[colorIndex]);
1952
glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, kSize, kSize);
1953
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + colorIndex,
1954
GL_RENDERBUFFER, color[colorIndex]);
1955
1956
drawBuffers[colorIndex] = GL_COLOR_ATTACHMENT0 + colorIndex;
1957
}
1958
1959
GLRenderbuffer depthStencil;
1960
glBindRenderbuffer(GL_RENDERBUFFER, depthStencil);
1961
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, kSize, kSize);
1962
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
1963
depthStencil);
1964
1965
EXPECT_GL_NO_ERROR();
1966
ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER);
1967
1968
glDrawBuffers(maxDrawBuffers, drawBuffers.data());
1969
1970
glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
1971
glClearDepthf(1.0f);
1972
glClearStencil(0x55);
1973
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
1974
EXPECT_GL_NO_ERROR();
1975
1976
// Verify that every color attachment is cleared correctly.
1977
for (GLint colorIndex = 0; colorIndex < maxDrawBuffers; ++colorIndex)
1978
{
1979
glReadBuffer(GL_COLOR_ATTACHMENT0 + colorIndex);
1980
1981
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
1982
EXPECT_PIXEL_COLOR_EQ(0, kSize - 1, GLColor::red);
1983
EXPECT_PIXEL_COLOR_EQ(kSize - 1, 0, GLColor::red);
1984
EXPECT_PIXEL_COLOR_EQ(kSize - 1, kSize - 1, GLColor::red);
1985
}
1986
1987
// Verify that depth and stencil attachments are cleared correctly.
1988
GLFramebuffer fbVerify;
1989
glBindFramebuffer(GL_FRAMEBUFFER, fbVerify);
1990
1991
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, color[0]);
1992
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
1993
depthStencil);
1994
1995
// If depth is not cleared to 1, rendering would fail.
1996
glEnable(GL_DEPTH_TEST);
1997
glDepthFunc(GL_LESS);
1998
1999
// If stencil is not cleared to 0x55, rendering would fail.
2000
glEnable(GL_STENCIL_TEST);
2001
glStencilFunc(GL_EQUAL, 0x55, 0xFF);
2002
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
2003
glStencilMask(0xFF);
2004
2005
// Draw green.
2006
ANGLE_GL_PROGRAM(drawGreen, essl1_shaders::vs::Simple(), essl1_shaders::fs::Green());
2007
drawQuad(drawGreen, essl1_shaders::PositionAttrib(), 0.95f);
2008
2009
// Verify that green was drawn.
2010
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2011
EXPECT_PIXEL_COLOR_EQ(0, kSize - 1, GLColor::green);
2012
EXPECT_PIXEL_COLOR_EQ(kSize - 1, 0, GLColor::green);
2013
EXPECT_PIXEL_COLOR_EQ(kSize - 1, kSize - 1, GLColor::green);
2014
}
2015
2016
// Test that having a framebuffer with maximum number of attachments and clearing color, depth and
2017
// stencil after a draw call works.
2018
TEST_P(ClearTestES3, ClearMaxAttachmentsAfterDraw)
2019
{
2020
// http://anglebug.com/4612
2021
ANGLE_SKIP_TEST_IF(IsOSX() && IsDesktopOpenGL());
2022
2023
constexpr GLsizei kSize = 16;
2024
2025
GLint maxDrawBuffers = 0;
2026
glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers);
2027
ASSERT_GE(maxDrawBuffers, 4);
2028
2029
// Setup framebuffer.
2030
GLFramebuffer fb;
2031
glBindFramebuffer(GL_FRAMEBUFFER, fb);
2032
2033
std::vector<GLRenderbuffer> color(maxDrawBuffers);
2034
std::vector<GLenum> drawBuffers(maxDrawBuffers);
2035
2036
for (GLint colorIndex = 0; colorIndex < maxDrawBuffers; ++colorIndex)
2037
{
2038
glBindRenderbuffer(GL_RENDERBUFFER, color[colorIndex]);
2039
glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, kSize, kSize);
2040
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + colorIndex,
2041
GL_RENDERBUFFER, color[colorIndex]);
2042
2043
drawBuffers[colorIndex] = GL_COLOR_ATTACHMENT0 + colorIndex;
2044
}
2045
2046
GLRenderbuffer depthStencil;
2047
glBindRenderbuffer(GL_RENDERBUFFER, depthStencil);
2048
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, kSize, kSize);
2049
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
2050
depthStencil);
2051
2052
EXPECT_GL_NO_ERROR();
2053
ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER);
2054
2055
glDrawBuffers(maxDrawBuffers, drawBuffers.data());
2056
2057
// Issue a draw call to render blue, depth=0 and stencil 0x3C to the attachments.
2058
glEnable(GL_DEPTH_TEST);
2059
glDepthFunc(GL_ALWAYS);
2060
2061
glEnable(GL_STENCIL_TEST);
2062
glStencilFunc(GL_ALWAYS, 0x3C, 0xFF);
2063
glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
2064
glStencilMask(0xFF);
2065
2066
// Generate shader for this framebuffer.
2067
std::stringstream strstr;
2068
strstr << "#version 300 es\n"
2069
"precision highp float;\n";
2070
for (GLint colorIndex = 0; colorIndex < maxDrawBuffers; ++colorIndex)
2071
{
2072
strstr << "layout(location = " << colorIndex << ") out vec4 value" << colorIndex << ";\n";
2073
}
2074
strstr << "void main()\n"
2075
"{\n";
2076
for (GLint colorIndex = 0; colorIndex < maxDrawBuffers; ++colorIndex)
2077
{
2078
strstr << "value" << colorIndex << " = vec4(0.0f, 0.0f, 1.0f, 1.0f);\n";
2079
}
2080
strstr << "}\n";
2081
2082
ANGLE_GL_PROGRAM(drawMRT, essl3_shaders::vs::Simple(), strstr.str().c_str());
2083
drawQuad(drawMRT, essl3_shaders::PositionAttrib(), 0.0f);
2084
ASSERT_GL_NO_ERROR();
2085
2086
glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
2087
glClearDepthf(1.0f);
2088
glClearStencil(0x55);
2089
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
2090
EXPECT_GL_NO_ERROR();
2091
2092
// Verify that every color attachment is cleared correctly.
2093
for (GLint colorIndex = 0; colorIndex < maxDrawBuffers; ++colorIndex)
2094
{
2095
glReadBuffer(GL_COLOR_ATTACHMENT0 + colorIndex);
2096
2097
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
2098
EXPECT_PIXEL_COLOR_EQ(0, kSize - 1, GLColor::red);
2099
EXPECT_PIXEL_COLOR_EQ(kSize - 1, 0, GLColor::red);
2100
EXPECT_PIXEL_COLOR_EQ(kSize - 1, kSize - 1, GLColor::red);
2101
}
2102
2103
// Verify that depth and stencil attachments are cleared correctly.
2104
GLFramebuffer fbVerify;
2105
glBindFramebuffer(GL_FRAMEBUFFER, fbVerify);
2106
2107
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, color[0]);
2108
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
2109
depthStencil);
2110
2111
// If depth is not cleared to 1, rendering would fail.
2112
glDepthFunc(GL_LESS);
2113
2114
// If stencil is not cleared to 0x55, rendering would fail.
2115
glStencilFunc(GL_EQUAL, 0x55, 0xFF);
2116
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
2117
2118
// Draw green.
2119
ANGLE_GL_PROGRAM(drawGreen, essl1_shaders::vs::Simple(), essl1_shaders::fs::Green());
2120
drawQuad(drawGreen, essl1_shaders::PositionAttrib(), 0.95f);
2121
2122
// Verify that green was drawn.
2123
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2124
EXPECT_PIXEL_COLOR_EQ(0, kSize - 1, GLColor::green);
2125
EXPECT_PIXEL_COLOR_EQ(kSize - 1, 0, GLColor::green);
2126
EXPECT_PIXEL_COLOR_EQ(kSize - 1, kSize - 1, GLColor::green);
2127
}
2128
2129
// Test that mixed masked clear works after clear.
2130
TEST_P(ClearTestES3, ClearThenMixedMaskedClear)
2131
{
2132
constexpr GLsizei kSize = 16;
2133
2134
// Setup framebuffer.
2135
GLRenderbuffer color;
2136
glBindRenderbuffer(GL_RENDERBUFFER, color);
2137
glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, kSize, kSize);
2138
2139
GLRenderbuffer depthStencil;
2140
glBindRenderbuffer(GL_RENDERBUFFER, depthStencil);
2141
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, kSize, kSize);
2142
2143
GLFramebuffer fb;
2144
glBindFramebuffer(GL_FRAMEBUFFER, fb);
2145
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, color);
2146
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
2147
depthStencil);
2148
EXPECT_GL_NO_ERROR();
2149
ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER);
2150
2151
// Clear color and depth/stencil
2152
glClearColor(0.1f, 1.0f, 0.0f, 0.7f);
2153
glClearDepthf(0.0f);
2154
glClearStencil(0x55);
2155
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
2156
2157
// Clear again, but with color and stencil masked
2158
glClearColor(1.0f, 0.2f, 0.6f, 1.0f);
2159
glClearDepthf(1.0f);
2160
glClearStencil(0x3C);
2161
glColorMask(GL_TRUE, GL_FALSE, GL_FALSE, GL_TRUE);
2162
glStencilMask(0xF0);
2163
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
2164
2165
// Issue a draw call to verify color, depth and stencil.
2166
2167
// If depth is not cleared to 1, rendering would fail.
2168
glEnable(GL_DEPTH_TEST);
2169
glDepthFunc(GL_LESS);
2170
2171
// If stencil is not cleared to 0x35, rendering would fail.
2172
glEnable(GL_STENCIL_TEST);
2173
glStencilFunc(GL_EQUAL, 0x35, 0xFF);
2174
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
2175
glStencilMask(0xFF);
2176
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
2177
2178
ANGLE_GL_PROGRAM(drawColor, essl1_shaders::vs::Simple(), essl1_shaders::fs::UniformColor());
2179
glUseProgram(drawColor);
2180
GLint colorUniformLocation =
2181
glGetUniformLocation(drawColor, angle::essl1_shaders::ColorUniform());
2182
ASSERT_NE(colorUniformLocation, -1);
2183
2184
// Blend half-transparent blue into the color buffer.
2185
glUniform4f(colorUniformLocation, 0.0f, 0.0f, 1.0f, 0.5f);
2186
glEnable(GL_BLEND);
2187
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
2188
drawQuad(drawColor, essl1_shaders::PositionAttrib(), 0.95f);
2189
ASSERT_GL_NO_ERROR();
2190
2191
// Verify that the color buffer is now gray
2192
const GLColor kExpected(127, 127, 127, 191);
2193
EXPECT_PIXEL_COLOR_NEAR(0, 0, kExpected, 1);
2194
EXPECT_PIXEL_COLOR_NEAR(0, kSize - 1, kExpected, 1);
2195
EXPECT_PIXEL_COLOR_NEAR(kSize - 1, 0, kExpected, 1);
2196
EXPECT_PIXEL_COLOR_NEAR(kSize - 1, kSize - 1, kExpected, 1);
2197
}
2198
2199
// Test that draw without state change after masked clear works
2200
TEST_P(ClearTestES3, DrawClearThenDrawWithoutStateChange)
2201
{
2202
swapBuffers();
2203
constexpr GLsizei kSize = 16;
2204
2205
// Setup framebuffer.
2206
GLRenderbuffer color;
2207
glBindRenderbuffer(GL_RENDERBUFFER, color);
2208
glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, kSize, kSize);
2209
2210
GLFramebuffer fb;
2211
glBindFramebuffer(GL_FRAMEBUFFER, fb);
2212
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, color);
2213
EXPECT_GL_NO_ERROR();
2214
ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER);
2215
2216
// Clear color initially.
2217
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
2218
glClear(GL_COLOR_BUFFER_BIT);
2219
2220
// Mask color.
2221
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE);
2222
2223
ANGLE_GL_PROGRAM(drawColor, essl1_shaders::vs::Simple(), essl1_shaders::fs::UniformColor());
2224
glUseProgram(drawColor);
2225
GLint colorUniformLocation =
2226
glGetUniformLocation(drawColor, angle::essl1_shaders::ColorUniform());
2227
ASSERT_NE(colorUniformLocation, -1);
2228
2229
// Initialize position attribute.
2230
GLint posLoc = glGetAttribLocation(drawColor, essl1_shaders::PositionAttrib());
2231
ASSERT_NE(-1, posLoc);
2232
setupQuadVertexBuffer(0.5f, 1.0f);
2233
glVertexAttribPointer(posLoc, 3, GL_FLOAT, GL_FALSE, 0, nullptr);
2234
glEnableVertexAttribArray(posLoc);
2235
2236
// Draw red.
2237
glViewport(0, 0, kSize, kSize);
2238
glClearColor(0.0f, 1.0f, 0.0f, 0.0f);
2239
glUniform4f(colorUniformLocation, 1.0f, 0.0f, 0.0f, 0.5f);
2240
glDrawArrays(GL_TRIANGLES, 0, 6);
2241
2242
// Clear to green without any state change.
2243
glClear(GL_COLOR_BUFFER_BIT);
2244
2245
// Draw red again without any state change.
2246
glDrawArrays(GL_TRIANGLES, 0, 6);
2247
2248
// Verify that the color buffer is now red
2249
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
2250
EXPECT_PIXEL_COLOR_EQ(0, kSize - 1, GLColor::red);
2251
EXPECT_PIXEL_COLOR_EQ(kSize - 1, 0, GLColor::red);
2252
EXPECT_PIXEL_COLOR_EQ(kSize - 1, kSize - 1, GLColor::red);
2253
}
2254
2255
// Test that clear stencil value is correctly masked to 8 bits.
2256
TEST_P(ClearTest, ClearStencilMask)
2257
{
2258
GLint stencilBits = 0;
2259
glGetIntegerv(GL_STENCIL_BITS, &stencilBits);
2260
EXPECT_EQ(stencilBits, 8);
2261
2262
ANGLE_GL_PROGRAM(drawColor, essl1_shaders::vs::Simple(), essl1_shaders::fs::Green());
2263
glUseProgram(drawColor);
2264
2265
glClearColor(0, 0, 0, 1);
2266
glClear(GL_COLOR_BUFFER_BIT);
2267
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2268
2269
// Clear stencil value must be masked to 0x42
2270
glClearStencil(0x142);
2271
glClear(GL_STENCIL_BUFFER_BIT);
2272
2273
// Check that the stencil test works as expected
2274
glEnable(GL_STENCIL_TEST);
2275
2276
// Negative case
2277
glStencilFunc(GL_NOTEQUAL, 0x42, 0xFF);
2278
drawQuad(drawColor, essl1_shaders::PositionAttrib(), 0.5f);
2279
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2280
2281
// Positive case
2282
glStencilFunc(GL_EQUAL, 0x42, 0xFF);
2283
drawQuad(drawColor, essl1_shaders::PositionAttrib(), 0.5f);
2284
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2285
2286
ASSERT_GL_NO_ERROR();
2287
}
2288
2289
// Test that glClearBufferiv correctly masks the clear stencil value.
2290
TEST_P(ClearTestES3, ClearBufferivStencilMask)
2291
{
2292
GLint stencilBits = 0;
2293
glGetIntegerv(GL_STENCIL_BITS, &stencilBits);
2294
EXPECT_EQ(stencilBits, 8);
2295
2296
ANGLE_GL_PROGRAM(drawColor, essl1_shaders::vs::Simple(), essl1_shaders::fs::Green());
2297
glUseProgram(drawColor);
2298
2299
glClearColor(0, 0, 0, 1);
2300
glClear(GL_COLOR_BUFFER_BIT);
2301
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2302
2303
// Clear stencil value must be masked to 0x42
2304
const GLint kStencilClearValue = 0x142;
2305
glClearBufferiv(GL_STENCIL, 0, &kStencilClearValue);
2306
2307
// Check that the stencil test works as expected
2308
glEnable(GL_STENCIL_TEST);
2309
2310
// Negative case
2311
glStencilFunc(GL_NOTEQUAL, 0x42, 0xFF);
2312
drawQuad(drawColor, essl1_shaders::PositionAttrib(), 0.5f);
2313
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2314
2315
// Positive case
2316
glStencilFunc(GL_EQUAL, 0x42, 0xFF);
2317
drawQuad(drawColor, essl1_shaders::PositionAttrib(), 0.5f);
2318
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2319
2320
ASSERT_GL_NO_ERROR();
2321
}
2322
2323
// Test that glClearBufferfi correctly masks the clear stencil value.
2324
TEST_P(ClearTestES3, ClearBufferfiStencilMask)
2325
{
2326
GLint stencilBits = 0;
2327
glGetIntegerv(GL_STENCIL_BITS, &stencilBits);
2328
EXPECT_EQ(stencilBits, 8);
2329
2330
ANGLE_GL_PROGRAM(drawColor, essl1_shaders::vs::Simple(), essl1_shaders::fs::Green());
2331
glUseProgram(drawColor);
2332
2333
glClearColor(0, 0, 0, 1);
2334
glClear(GL_COLOR_BUFFER_BIT);
2335
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2336
2337
// Clear stencil value must be masked to 0x42
2338
glClearBufferfi(GL_DEPTH_STENCIL, 0, 0.5f, 0x142);
2339
2340
// Check that the stencil test works as expected
2341
glEnable(GL_STENCIL_TEST);
2342
2343
// Negative case
2344
glStencilFunc(GL_NOTEQUAL, 0x42, 0xFF);
2345
drawQuad(drawColor, essl1_shaders::PositionAttrib(), 0.5f);
2346
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
2347
2348
// Positive case
2349
glStencilFunc(GL_EQUAL, 0x42, 0xFF);
2350
drawQuad(drawColor, essl1_shaders::PositionAttrib(), 0.5f);
2351
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2352
2353
ASSERT_GL_NO_ERROR();
2354
}
2355
2356
// Test that glClearBufferfi works when stencil attachment is not present.
2357
TEST_P(ClearTestES3, ClearBufferfiNoStencilAttachment)
2358
{
2359
constexpr GLsizei kSize = 16;
2360
2361
GLRenderbuffer color;
2362
glBindRenderbuffer(GL_RENDERBUFFER, color);
2363
glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, kSize, kSize);
2364
2365
GLRenderbuffer depth;
2366
glBindRenderbuffer(GL_RENDERBUFFER, depth);
2367
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, kSize, kSize);
2368
2369
GLFramebuffer fbo;
2370
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
2371
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, color);
2372
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depth);
2373
EXPECT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER);
2374
EXPECT_GL_NO_ERROR();
2375
2376
// Clear depth/stencil with glClearBufferfi. Note that the stencil attachment doesn't exist.
2377
glClearBufferfi(GL_DEPTH_STENCIL, 0, 0.5f, 0x55);
2378
EXPECT_GL_NO_ERROR();
2379
2380
// Verify depth is cleared correctly.
2381
verifyDepth(0.5f, kSize);
2382
}
2383
2384
// Test that scissored clear followed by non-scissored draw works. Ensures that when scissor size
2385
// is expanded, the clear operation remains limited to the scissor region. Written to catch
2386
// potential future bugs if loadOp=CLEAR is used in the Vulkan backend for a small render pass and
2387
// then the render area is mistakenly enlarged.
2388
TEST_P(ClearTest, ScissoredClearThenNonScissoredDraw)
2389
{
2390
constexpr GLsizei kSize = 16;
2391
const std::vector<GLColor> kInitialData(kSize * kSize, GLColor::red);
2392
2393
// Setup framebuffer. Initialize color with red.
2394
GLTexture color;
2395
glBindTexture(GL_TEXTURE_2D, color);
2396
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
2397
kInitialData.data());
2398
2399
GLFramebuffer fb;
2400
glBindFramebuffer(GL_FRAMEBUFFER, fb);
2401
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, color, 0);
2402
EXPECT_GL_NO_ERROR();
2403
ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER);
2404
2405
// Issue a scissored clear to green.
2406
glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
2407
glScissor(kSize / 2, 0, kSize / 2, kSize);
2408
glEnable(GL_SCISSOR_TEST);
2409
glClear(GL_COLOR_BUFFER_BIT);
2410
2411
// Expand the scissor and blend blue into the framebuffer.
2412
glScissor(0, 0, kSize, kSize);
2413
glEnable(GL_BLEND);
2414
glBlendFunc(GL_ONE, GL_ONE);
2415
2416
ANGLE_GL_PROGRAM(drawBlue, essl1_shaders::vs::Simple(), essl1_shaders::fs::Blue());
2417
drawQuad(drawBlue, essl1_shaders::PositionAttrib(), 0.5f);
2418
ASSERT_GL_NO_ERROR();
2419
2420
// Verify that the left half is magenta, and the right half is cyan.
2421
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::magenta);
2422
EXPECT_PIXEL_COLOR_EQ(kSize / 2 - 1, 0, GLColor::magenta);
2423
EXPECT_PIXEL_COLOR_EQ(0, kSize - 1, GLColor::magenta);
2424
EXPECT_PIXEL_COLOR_EQ(kSize / 2 - 1, kSize - 1, GLColor::magenta);
2425
2426
EXPECT_PIXEL_COLOR_EQ(kSize / 2, 0, GLColor::cyan);
2427
EXPECT_PIXEL_COLOR_EQ(kSize / 2, kSize - 1, GLColor::cyan);
2428
EXPECT_PIXEL_COLOR_EQ(kSize - 1, 0, GLColor::cyan);
2429
EXPECT_PIXEL_COLOR_EQ(kSize - 1, kSize - 1, GLColor::cyan);
2430
}
2431
2432
// Test that clear followed by a scissored masked clear works.
2433
TEST_P(ClearTest, ClearThenScissoredMaskedClear)
2434
{
2435
constexpr GLsizei kSize = 16;
2436
2437
// Setup framebuffer
2438
GLTexture color;
2439
glBindTexture(GL_TEXTURE_2D, color);
2440
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
2441
2442
GLFramebuffer fb;
2443
glBindFramebuffer(GL_FRAMEBUFFER, fb);
2444
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, color, 0);
2445
EXPECT_GL_NO_ERROR();
2446
ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER);
2447
2448
// Clear to red.
2449
glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
2450
glClear(GL_COLOR_BUFFER_BIT);
2451
2452
// Mask red and clear to green with a scissor
2453
glColorMask(GL_FALSE, GL_TRUE, GL_TRUE, GL_TRUE);
2454
glScissor(0, 0, kSize / 2, kSize);
2455
glEnable(GL_SCISSOR_TEST);
2456
glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
2457
glClear(GL_COLOR_BUFFER_BIT);
2458
2459
// Verify that the left half is yellow, and the right half is red.
2460
EXPECT_PIXEL_RECT_EQ(0, 0, kSize / 2, kSize, GLColor::yellow);
2461
EXPECT_PIXEL_RECT_EQ(kSize / 2, 0, kSize / 2, kSize, GLColor::red);
2462
}
2463
2464
// This is a test that must be verified visually.
2465
//
2466
// Tests that clear of the default framebuffer applies to the window.
2467
TEST_P(ClearTest, DISABLED_ClearReachesWindow)
2468
{
2469
ANGLE_GL_PROGRAM(blueProgram, essl1_shaders::vs::Simple(), essl1_shaders::fs::Blue());
2470
2471
// Draw blue.
2472
drawQuad(blueProgram, essl1_shaders::PositionAttrib(), 0.5f);
2473
swapBuffers();
2474
2475
// Use glClear to clear to red. Regression test for the Vulkan backend where this clear
2476
// remained "deferred" and didn't make it to the window on swap.
2477
glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
2478
glClear(GL_COLOR_BUFFER_BIT);
2479
swapBuffers();
2480
2481
// Wait for visual verification.
2482
angle::Sleep(2000);
2483
}
2484
2485
// Test that clearing slices of a 3D texture and reading them back works.
2486
TEST_P(ClearTestES3, ClearAndReadPixels3DTexture)
2487
{
2488
constexpr uint32_t kWidth = 128;
2489
constexpr uint32_t kHeight = 128;
2490
constexpr uint32_t kDepth = 7;
2491
2492
GLTexture texture;
2493
glBindTexture(GL_TEXTURE_3D, texture);
2494
glTexStorage3D(GL_TEXTURE_3D, 1, GL_RGBA8, kWidth, kHeight, kDepth);
2495
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 0);
2496
2497
std::array<GLColor, kDepth> clearColors = {
2498
GLColor::red, GLColor::green, GLColor::blue, GLColor::yellow,
2499
GLColor::cyan, GLColor::magenta, GLColor::white,
2500
};
2501
2502
GLFramebuffer framebuffer;
2503
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
2504
2505
for (uint32_t z = 0; z < kDepth; ++z)
2506
{
2507
glFramebufferTextureLayer(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texture, 0, z);
2508
glClearBufferfv(GL_COLOR, 0, clearColors[z].toNormalizedVector().data());
2509
}
2510
2511
for (uint32_t z = 0; z < kDepth; ++z)
2512
{
2513
glFramebufferTextureLayer(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texture, 0, z);
2514
EXPECT_PIXEL_COLOR_EQ(0, 0, clearColors[z]);
2515
}
2516
}
2517
2518
#ifdef Bool
2519
// X11 craziness.
2520
# undef Bool
2521
#endif
2522
2523
ANGLE_INSTANTIATE_TEST_ES2_AND_ES3(ClearTest);
2524
2525
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(ClearTestES3);
2526
ANGLE_INSTANTIATE_TEST_ES3(ClearTestES3);
2527
2528
ANGLE_INSTANTIATE_TEST_COMBINE_4(MaskedScissoredClearTest,
2529
MaskedScissoredClearVariationsTestPrint,
2530
testing::Range(0, 3),
2531
testing::Range(0, 3),
2532
testing::Range(0, 3),
2533
testing::Bool(),
2534
ES2_D3D9(),
2535
ES2_D3D11(),
2536
ES3_D3D11(),
2537
ES2_OPENGL(),
2538
ES3_OPENGL(),
2539
ES2_OPENGLES(),
2540
ES3_OPENGLES(),
2541
ES2_VULKAN(),
2542
ES3_VULKAN(),
2543
ES2_METAL(),
2544
ES3_METAL());
2545
2546
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(VulkanClearTest);
2547
ANGLE_INSTANTIATE_TEST_COMBINE_4(VulkanClearTest,
2548
MaskedScissoredClearVariationsTestPrint,
2549
testing::Range(0, 3),
2550
testing::Range(0, 3),
2551
testing::Range(0, 3),
2552
testing::Bool(),
2553
ES2_VULKAN(),
2554
ES3_VULKAN());
2555
2556
// Not all ANGLE backends support RGB backbuffers
2557
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(ClearTestRGB);
2558
ANGLE_INSTANTIATE_TEST(ClearTestRGB,
2559
ES2_D3D11(),
2560
ES3_D3D11(),
2561
ES2_VULKAN(),
2562
ES3_VULKAN(),
2563
ES2_METAL(),
2564
ES3_METAL());
2565
2566
} // anonymous namespace
2567
2568