blob: 13989c352eff6e9fcea40e5116cab66c45e2af51 [file] [log] [blame]
Jamie Madillfa05f602015-05-07 13:47:11 -04001//
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
Corentin Wallezd3970de2015-05-14 11:07:48 -04007#include "test_utils/ANGLETest.h"
Geoff Langd1913172013-10-18 16:15:10 -04008
Jamie Madillcfd6b2b2016-02-08 12:50:38 -05009#include "random_utils.h"
Jamie Madillcfd6b2b2016-02-08 12:50:38 -050010
Jamie Madillfa05f602015-05-07 13:47:11 -040011using namespace angle;
Jamie Madill94203b32014-10-02 10:44:16 -040012
Jamie Madillcfd6b2b2016-02-08 12:50:38 -050013namespace
14{
15
16Vector4 RandomVec4(int seed, float minValue, float maxValue)
17{
18 RNG rng(seed);
19 srand(seed);
20 return Vector4(
21 rng.randomFloatBetween(minValue, maxValue), rng.randomFloatBetween(minValue, maxValue),
22 rng.randomFloatBetween(minValue, maxValue), rng.randomFloatBetween(minValue, maxValue));
23}
24
25GLColor Vec4ToColor(const Vector4 &vec)
26{
27 GLColor color;
Corentin Wallez922cbfc2016-11-25 16:23:18 -050028 color.R = static_cast<uint8_t>(vec.x() * 255.0f);
29 color.G = static_cast<uint8_t>(vec.y() * 255.0f);
30 color.B = static_cast<uint8_t>(vec.z() * 255.0f);
31 color.A = static_cast<uint8_t>(vec.w() * 255.0f);
Jamie Madillcfd6b2b2016-02-08 12:50:38 -050032 return color;
33};
34
Jamie Madill94203b32014-10-02 10:44:16 -040035class ClearTestBase : public ANGLETest
Geoff Langd1913172013-10-18 16:15:10 -040036{
Jamie Madill94203b32014-10-02 10:44:16 -040037 protected:
Jamie Madillcfd6b2b2016-02-08 12:50:38 -050038 ClearTestBase() : mProgram(0)
Geoff Langd1913172013-10-18 16:15:10 -040039 {
40 setWindowWidth(128);
41 setWindowHeight(128);
Geoff Langefc551f2013-10-31 10:20:28 -040042 setConfigRedBits(8);
43 setConfigGreenBits(8);
44 setConfigBlueBits(8);
45 setConfigAlphaBits(8);
46 setConfigDepthBits(24);
Geoff Langd1913172013-10-18 16:15:10 -040047 }
48
Jamie Madillcfd6b2b2016-02-08 12:50:38 -050049 void SetUp() override
Geoff Langd1913172013-10-18 16:15:10 -040050 {
51 ANGLETest::SetUp();
52
Jamie Madillcfd6b2b2016-02-08 12:50:38 -050053 mFBOs.resize(2, 0);
54 glGenFramebuffers(2, mFBOs.data());
55
56 ASSERT_GL_NO_ERROR();
57 }
58
59 void TearDown() override
60 {
61 glDeleteProgram(mProgram);
62
63 if (!mFBOs.empty())
64 {
65 glDeleteFramebuffers(static_cast<GLsizei>(mFBOs.size()), mFBOs.data());
66 }
67
68 if (!mTextures.empty())
69 {
70 glDeleteTextures(static_cast<GLsizei>(mTextures.size()), mTextures.data());
71 }
72
73 ANGLETest::TearDown();
74 }
75
76 void setupDefaultProgram()
77 {
Olli Etuahoa20af6d2017-09-18 13:32:29 +030078 const std::string vertexShaderSource =
79 R"(precision highp float;
Geoff Langd1913172013-10-18 16:15:10 -040080 attribute vec4 position;
81
82 void main()
83 {
84 gl_Position = position;
Olli Etuahoa20af6d2017-09-18 13:32:29 +030085 })";
Geoff Langd1913172013-10-18 16:15:10 -040086
Olli Etuahoa20af6d2017-09-18 13:32:29 +030087 const std::string fragmentShaderSource =
88 R"(precision highp float;
Geoff Langd1913172013-10-18 16:15:10 -040089
90 void main()
91 {
92 gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
Olli Etuahoa20af6d2017-09-18 13:32:29 +030093 })";
Geoff Langd1913172013-10-18 16:15:10 -040094
Jamie Madill5599c8f2014-08-26 13:16:39 -040095 mProgram = CompileProgram(vertexShaderSource, fragmentShaderSource);
Jamie Madillcfd6b2b2016-02-08 12:50:38 -050096 ASSERT_NE(0u, mProgram);
Geoff Langd1913172013-10-18 16:15:10 -040097 }
98
99 GLuint mProgram;
Jamie Madillcfd6b2b2016-02-08 12:50:38 -0500100 std::vector<GLuint> mFBOs;
101 std::vector<GLuint> mTextures;
Geoff Langd1913172013-10-18 16:15:10 -0400102};
103
Jamie Madillfa05f602015-05-07 13:47:11 -0400104class ClearTest : public ClearTestBase {};
105class ClearTestES3 : public ClearTestBase {};
Jamie Madill94203b32014-10-02 10:44:16 -0400106
Geoff Langafd7f0a2015-09-09 15:33:31 -0400107// Test clearing the default framebuffer
108TEST_P(ClearTest, DefaultFramebuffer)
109{
110 glClearColor(0.25f, 0.5f, 0.5f, 0.5f);
111 glClear(GL_COLOR_BUFFER_BIT);
112 EXPECT_PIXEL_NEAR(0, 0, 64, 128, 128, 128, 1.0);
113}
114
115// Test clearing a RGBA8 Framebuffer
116TEST_P(ClearTest, RGBA8Framebuffer)
117{
Jamie Madillcfd6b2b2016-02-08 12:50:38 -0500118 glBindFramebuffer(GL_FRAMEBUFFER, mFBOs[0]);
Geoff Langafd7f0a2015-09-09 15:33:31 -0400119
120 GLuint texture;
121 glGenTextures(1, &texture);
122
123 glBindTexture(GL_TEXTURE_2D, texture);
124 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, getWindowWidth(), getWindowHeight(), 0, GL_RGBA,
125 GL_UNSIGNED_BYTE, nullptr);
126 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
127
128 glClearColor(0.5f, 0.5f, 0.5f, 0.5f);
129 glClear(GL_COLOR_BUFFER_BIT);
130
131 EXPECT_PIXEL_NEAR(0, 0, 128, 128, 128, 128, 1.0);
132}
133
Jamie Madillfa05f602015-05-07 13:47:11 -0400134TEST_P(ClearTest, ClearIssue)
Geoff Langd1913172013-10-18 16:15:10 -0400135{
Geoff Lang463cdea2015-04-28 13:22:31 -0400136 // TODO(geofflang): Figure out why this is broken on Intel OpenGL
Jamie Madill518b9fa2016-03-02 11:26:02 -0500137 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
Geoff Lang463cdea2015-04-28 13:22:31 -0400138 {
139 std::cout << "Test skipped on Intel OpenGL." << std::endl;
140 return;
141 }
142
Geoff Langd1913172013-10-18 16:15:10 -0400143 glEnable(GL_DEPTH_TEST);
144 glDepthFunc(GL_LEQUAL);
145
146 glClearColor(0.0, 1.0, 0.0, 1.0);
147 glClearDepthf(0.0);
148 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
149
150 EXPECT_GL_NO_ERROR();
151
Jamie Madillcfd6b2b2016-02-08 12:50:38 -0500152 glBindFramebuffer(GL_FRAMEBUFFER, mFBOs[0]);
Geoff Langd1913172013-10-18 16:15:10 -0400153
154 GLuint rbo;
155 glGenRenderbuffers(1, &rbo);
156 glBindRenderbuffer(GL_RENDERBUFFER, rbo);
157 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGB565, 16, 16);
158
159 EXPECT_GL_NO_ERROR();
160
161 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rbo);
162
163 EXPECT_GL_NO_ERROR();
164
165 glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
166 glClearDepthf(1.0f);
167 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
168
169 EXPECT_GL_NO_ERROR();
170
171 glBindFramebuffer(GL_FRAMEBUFFER, 0);
172 glBindBuffer(GL_ARRAY_BUFFER, 0);
173
Jamie Madillcfd6b2b2016-02-08 12:50:38 -0500174 setupDefaultProgram();
Geoff Langd1913172013-10-18 16:15:10 -0400175 drawQuad(mProgram, "position", 0.5f);
176
177 EXPECT_PIXEL_EQ(0, 0, 0, 255, 0, 255);
178}
Jamie Madilla09403c2014-07-21 10:03:36 -0400179
180// Requires ES3
181// This tests a bug where in a masked clear when calling "ClearBuffer", we would
182// mistakenly clear every channel (including the masked-out ones)
Jamie Madillfa05f602015-05-07 13:47:11 -0400183TEST_P(ClearTestES3, MaskedClearBufferBug)
Jamie Madilla09403c2014-07-21 10:03:36 -0400184{
185 unsigned char pixelData[] = { 255, 255, 255, 255 };
186
Jamie Madillcfd6b2b2016-02-08 12:50:38 -0500187 glBindFramebuffer(GL_FRAMEBUFFER, mFBOs[0]);
Jamie Madilla09403c2014-07-21 10:03:36 -0400188
189 GLuint textures[2];
190 glGenTextures(2, &textures[0]);
191
192 glBindTexture(GL_TEXTURE_2D, textures[0]);
193 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixelData);
194 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0], 0);
195
196 glBindTexture(GL_TEXTURE_2D, textures[1]);
197 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixelData);
198 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, textures[1], 0);
199
200 ASSERT_GL_NO_ERROR();
201 EXPECT_PIXEL_EQ(0, 0, 255, 255, 255, 255);
202
203 float clearValue[] = { 0, 0.5f, 0.5f, 1.0f };
204 GLenum drawBuffers[] = { GL_NONE, GL_COLOR_ATTACHMENT1 };
205 glDrawBuffers(2, drawBuffers);
206 glColorMask(GL_TRUE, GL_TRUE, GL_FALSE, GL_TRUE);
207 glClearBufferfv(GL_COLOR, 1, clearValue);
208
209 ASSERT_GL_NO_ERROR();
210 EXPECT_PIXEL_EQ(0, 0, 255, 255, 255, 255);
211
Jamie Madillcb34ea52015-12-11 16:01:18 -0500212 glReadBuffer(GL_COLOR_ATTACHMENT1);
213 ASSERT_GL_NO_ERROR();
Jamie Madill9abdc2d2014-11-05 16:13:22 -0500214
Jamie Madill9abdc2d2014-11-05 16:13:22 -0500215 EXPECT_PIXEL_NEAR(0, 0, 0, 127, 255, 255, 1);
Jamie Madillc4833262014-09-18 16:18:26 -0400216
217 glDeleteTextures(2, textures);
218}
219
Jamie Madillfa05f602015-05-07 13:47:11 -0400220TEST_P(ClearTestES3, BadFBOSerialBug)
Jamie Madillc4833262014-09-18 16:18:26 -0400221{
222 // First make a simple framebuffer, and clear it to green
Jamie Madillcfd6b2b2016-02-08 12:50:38 -0500223 glBindFramebuffer(GL_FRAMEBUFFER, mFBOs[0]);
Jamie Madillc4833262014-09-18 16:18:26 -0400224
225 GLuint textures[2];
226 glGenTextures(2, &textures[0]);
227
228 glBindTexture(GL_TEXTURE_2D, textures[0]);
229 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, getWindowWidth(), getWindowHeight());
230 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0], 0);
231
232 GLenum drawBuffers[] = { GL_COLOR_ATTACHMENT0 };
233 glDrawBuffers(1, drawBuffers);
234
235 float clearValues1[] = { 0.0f, 1.0f, 0.0f, 1.0f };
236 glClearBufferfv(GL_COLOR, 0, clearValues1);
237
238 ASSERT_GL_NO_ERROR();
239 EXPECT_PIXEL_EQ(0, 0, 0, 255, 0, 255);
240
241 // Next make a second framebuffer, and draw it to red
242 // (Triggers bad applied render target serial)
243 GLuint fbo2;
244 glGenFramebuffers(1, &fbo2);
245 ASSERT_GL_NO_ERROR();
246
247 glBindFramebuffer(GL_FRAMEBUFFER, fbo2);
248
249 glBindTexture(GL_TEXTURE_2D, textures[1]);
250 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, getWindowWidth(), getWindowHeight());
251 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[1], 0);
252
253 glDrawBuffers(1, drawBuffers);
254
Jamie Madillcfd6b2b2016-02-08 12:50:38 -0500255 setupDefaultProgram();
Jamie Madillc4833262014-09-18 16:18:26 -0400256 drawQuad(mProgram, "position", 0.5f);
257
258 ASSERT_GL_NO_ERROR();
259 EXPECT_PIXEL_EQ(0, 0, 255, 0, 0, 255);
260
261 // Check that the first framebuffer is still green.
Jamie Madillcfd6b2b2016-02-08 12:50:38 -0500262 glBindFramebuffer(GL_FRAMEBUFFER, mFBOs[0]);
Jamie Madillc4833262014-09-18 16:18:26 -0400263 EXPECT_PIXEL_EQ(0, 0, 0, 255, 0, 255);
264
265 glDeleteTextures(2, textures);
266 glDeleteFramebuffers(1, &fbo2);
Jamie Madilla09403c2014-07-21 10:03:36 -0400267}
Jamie Madillfa05f602015-05-07 13:47:11 -0400268
Geoff Langafd7f0a2015-09-09 15:33:31 -0400269// Test that SRGB framebuffers clear to the linearized clear color
270TEST_P(ClearTestES3, SRGBClear)
271{
Jamie Madill1ea9aaa2015-10-07 11:13:55 -0400272 // TODO(jmadill): figure out why this fails
Jamie Madill518b9fa2016-03-02 11:26:02 -0500273 if (IsIntel() && GetParam() == ES3_OPENGL())
Jamie Madill1ea9aaa2015-10-07 11:13:55 -0400274 {
275 std::cout << "Test skipped on Intel due to failures." << std::endl;
276 return;
277 }
278
Geoff Langafd7f0a2015-09-09 15:33:31 -0400279 // First make a simple framebuffer, and clear it
Jamie Madillcfd6b2b2016-02-08 12:50:38 -0500280 glBindFramebuffer(GL_FRAMEBUFFER, mFBOs[0]);
Geoff Langafd7f0a2015-09-09 15:33:31 -0400281
282 GLuint texture;
283 glGenTextures(1, &texture);
284
285 glBindTexture(GL_TEXTURE_2D, texture);
286 glTexStorage2D(GL_TEXTURE_2D, 1, GL_SRGB8_ALPHA8, getWindowWidth(), getWindowHeight());
287 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
288
289 glClearColor(0.5f, 0.5f, 0.5f, 0.5f);
290 glClear(GL_COLOR_BUFFER_BIT);
291
292 EXPECT_PIXEL_NEAR(0, 0, 188, 188, 188, 128, 1.0);
293}
294
295// Test that framebuffers with mixed SRGB/Linear attachments clear to the correct color for each
296// attachment
297TEST_P(ClearTestES3, MixedSRGBClear)
298{
Corentin Wallez7b43c9b2015-09-30 10:47:30 -0700299 // TODO(cwallez) figure out why it is broken on Intel on Mac
Olli Etuaho36b73902015-10-05 11:58:50 +0300300#if defined(ANGLE_PLATFORM_APPLE)
Jamie Madill518b9fa2016-03-02 11:26:02 -0500301 if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
Corentin Wallez7b43c9b2015-09-30 10:47:30 -0700302 {
303 std::cout << "Test skipped on Intel on Mac." << std::endl;
304 return;
305 }
306#endif
307
Jamie Madill1ea9aaa2015-10-07 11:13:55 -0400308 // TODO(jmadill): figure out why this fails
Jamie Madill518b9fa2016-03-02 11:26:02 -0500309 if (IsIntel() && GetParam() == ES3_OPENGL())
Jamie Madill1ea9aaa2015-10-07 11:13:55 -0400310 {
311 std::cout << "Test skipped on Intel due to failures." << std::endl;
312 return;
313 }
314
Jamie Madillcfd6b2b2016-02-08 12:50:38 -0500315 glBindFramebuffer(GL_FRAMEBUFFER, mFBOs[0]);
Geoff Langafd7f0a2015-09-09 15:33:31 -0400316
317 GLuint textures[2];
318 glGenTextures(2, &textures[0]);
319
320 glBindTexture(GL_TEXTURE_2D, textures[0]);
321 glTexStorage2D(GL_TEXTURE_2D, 1, GL_SRGB8_ALPHA8, getWindowWidth(), getWindowHeight());
322 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0], 0);
323
324 glBindTexture(GL_TEXTURE_2D, textures[1]);
325 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, getWindowWidth(), getWindowHeight());
326 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, textures[1], 0);
327
328 GLenum drawBuffers[] = {GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1};
329 glDrawBuffers(2, drawBuffers);
330
331 // Clear both textures
332 glClearColor(0.5f, 0.5f, 0.5f, 0.5f);
333 glClear(GL_COLOR_BUFFER_BIT);
334
335 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0);
336 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, 0, 0);
337
338 // Check value of texture0
339 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0], 0);
340 EXPECT_PIXEL_NEAR(0, 0, 188, 188, 188, 128, 1.0);
341
342 // Check value of texture1
343 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[1], 0);
344 EXPECT_PIXEL_NEAR(0, 0, 128, 128, 128, 128, 1.0);
345}
346
Jamie Madillcfd6b2b2016-02-08 12:50:38 -0500347// This test covers a D3D11 bug where calling ClearRenderTargetView sometimes wouldn't sync
348// before a draw call. The test draws small quads to a larger FBO (the default back buffer).
349// Before each blit to the back buffer it clears the quad to a certain color using
350// ClearBufferfv to give a solid color. The sync problem goes away if we insert a call to
351// flush or finish after ClearBufferfv or each draw.
352TEST_P(ClearTestES3, RepeatedClear)
353{
Olli Etuahodf7d13e2017-05-30 13:53:45 +0300354 if (IsD3D11() && IsIntel())
Jamie Madillcfd6b2b2016-02-08 12:50:38 -0500355 {
Olli Etuahodf7d13e2017-05-30 13:53:45 +0300356 // Note that there's been a bug affecting this test on NVIDIA drivers as well, until fall
357 // 2016 driver releases.
358 std::cout << "Test skipped on Intel D3D11." << std::endl;
Jamie Madillcfd6b2b2016-02-08 12:50:38 -0500359 return;
360 }
361
362 const std::string &vertexSource =
363 "#version 300 es\n"
364 "in highp vec2 position;\n"
365 "out highp vec2 v_coord;\n"
366 "void main(void)\n"
367 "{\n"
368 " gl_Position = vec4(position, 0, 1);\n"
369 " vec2 texCoord = (position * 0.5) + 0.5;\n"
370 " v_coord = texCoord;\n"
371 "}\n";
372
373 const std::string &fragmentSource =
374 "#version 300 es\n"
375 "in highp vec2 v_coord;\n"
376 "out highp vec4 color;\n"
377 "uniform sampler2D tex;\n"
378 "void main()\n"
379 "{\n"
380 " color = texture(tex, v_coord);\n"
381 "}\n";
382
383 mProgram = CompileProgram(vertexSource, fragmentSource);
384 ASSERT_NE(0u, mProgram);
385
386 mTextures.resize(1, 0);
387 glGenTextures(1, mTextures.data());
388
389 GLenum format = GL_RGBA8;
390 const int numRowsCols = 3;
391 const int cellSize = 32;
392 const int fboSize = cellSize;
393 const int backFBOSize = cellSize * numRowsCols;
394 const float fmtValueMin = 0.0f;
395 const float fmtValueMax = 1.0f;
396
397 glBindTexture(GL_TEXTURE_2D, mTextures[0]);
398 glTexStorage2D(GL_TEXTURE_2D, 1, format, fboSize, fboSize);
399 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
400 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
401 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
402 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
403 ASSERT_GL_NO_ERROR();
404
405 glBindFramebuffer(GL_FRAMEBUFFER, mFBOs[0]);
406 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[0], 0);
407 ASSERT_GL_NO_ERROR();
408
409 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
410
411 // larger fbo bound -- clear to transparent black
412 glUseProgram(mProgram);
413 GLint uniLoc = glGetUniformLocation(mProgram, "tex");
414 ASSERT_NE(-1, uniLoc);
415 glUniform1i(uniLoc, 0);
416 glBindTexture(GL_TEXTURE_2D, mTextures[0]);
417
418 GLint positionLocation = glGetAttribLocation(mProgram, "position");
419 ASSERT_NE(-1, positionLocation);
420
421 glUseProgram(mProgram);
422
423 for (int cellY = 0; cellY < numRowsCols; cellY++)
424 {
425 for (int cellX = 0; cellX < numRowsCols; cellX++)
426 {
427 int seed = cellX + cellY * numRowsCols;
428 const Vector4 color = RandomVec4(seed, fmtValueMin, fmtValueMax);
429
430 glBindFramebuffer(GL_FRAMEBUFFER, mFBOs[0]);
431 glClearBufferfv(GL_COLOR, 0, color.data());
432
433 glBindFramebuffer(GL_FRAMEBUFFER, 0);
434
435 // Method 1: Set viewport and draw full-viewport quad
436 glViewport(cellX * cellSize, cellY * cellSize, cellSize, cellSize);
437 drawQuad(mProgram, "position", 0.5f);
438
439 // Uncommenting the glFinish call seems to make the test pass.
440 // glFinish();
441 }
442 }
443
444 std::vector<GLColor> pixelData(backFBOSize * backFBOSize);
445 glReadPixels(0, 0, backFBOSize, backFBOSize, GL_RGBA, GL_UNSIGNED_BYTE, pixelData.data());
446
447 for (int cellY = 0; cellY < numRowsCols; cellY++)
448 {
449 for (int cellX = 0; cellX < numRowsCols; cellX++)
450 {
451 int seed = cellX + cellY * numRowsCols;
452 const Vector4 color = RandomVec4(seed, fmtValueMin, fmtValueMax);
453 GLColor expectedColor = Vec4ToColor(color);
454
455 int testN = cellX * cellSize + cellY * backFBOSize * cellSize + backFBOSize + 1;
456 GLColor actualColor = pixelData[testN];
457 EXPECT_NEAR(expectedColor.R, actualColor.R, 1);
458 EXPECT_NEAR(expectedColor.G, actualColor.G, 1);
459 EXPECT_NEAR(expectedColor.B, actualColor.B, 1);
460 EXPECT_NEAR(expectedColor.A, actualColor.A, 1);
461 }
462 }
463
464 ASSERT_GL_NO_ERROR();
465}
466
Jamie Madillfa05f602015-05-07 13:47:11 -0400467// Use this to select which configurations (e.g. which renderer, which GLES major version) these tests should be run against.
Geoff Lange0cc2a42016-01-20 10:58:17 -0500468ANGLE_INSTANTIATE_TEST(ClearTest,
469 ES2_D3D9(),
470 ES2_D3D11(),
471 ES3_D3D11(),
472 ES2_OPENGL(),
473 ES3_OPENGL(),
474 ES2_OPENGLES(),
475 ES3_OPENGLES());
476ANGLE_INSTANTIATE_TEST(ClearTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Jamie Madillcfd6b2b2016-02-08 12:50:38 -0500477
478} // anonymous namespace