Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 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 | |
Corentin Wallez | d3970de | 2015-05-14 11:07:48 -0400 | [diff] [blame] | 7 | #include "test_utils/ANGLETest.h" |
Geoff Lang | d191317 | 2013-10-18 16:15:10 -0400 | [diff] [blame] | 8 | |
Jamie Madill | cfd6b2b | 2016-02-08 12:50:38 -0500 | [diff] [blame] | 9 | #include "random_utils.h" |
Jamie Madill | cfd6b2b | 2016-02-08 12:50:38 -0500 | [diff] [blame] | 10 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 11 | using namespace angle; |
Jamie Madill | 94203b3 | 2014-10-02 10:44:16 -0400 | [diff] [blame] | 12 | |
Jamie Madill | cfd6b2b | 2016-02-08 12:50:38 -0500 | [diff] [blame] | 13 | namespace |
| 14 | { |
| 15 | |
| 16 | Vector4 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 | |
| 25 | GLColor Vec4ToColor(const Vector4 &vec) |
| 26 | { |
| 27 | GLColor color; |
Corentin Wallez | 922cbfc | 2016-11-25 16:23:18 -0500 | [diff] [blame^] | 28 | 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 Madill | cfd6b2b | 2016-02-08 12:50:38 -0500 | [diff] [blame] | 32 | return color; |
| 33 | }; |
| 34 | |
Jamie Madill | 94203b3 | 2014-10-02 10:44:16 -0400 | [diff] [blame] | 35 | class ClearTestBase : public ANGLETest |
Geoff Lang | d191317 | 2013-10-18 16:15:10 -0400 | [diff] [blame] | 36 | { |
Jamie Madill | 94203b3 | 2014-10-02 10:44:16 -0400 | [diff] [blame] | 37 | protected: |
Jamie Madill | cfd6b2b | 2016-02-08 12:50:38 -0500 | [diff] [blame] | 38 | ClearTestBase() : mProgram(0) |
Geoff Lang | d191317 | 2013-10-18 16:15:10 -0400 | [diff] [blame] | 39 | { |
| 40 | setWindowWidth(128); |
| 41 | setWindowHeight(128); |
Geoff Lang | efc551f | 2013-10-31 10:20:28 -0400 | [diff] [blame] | 42 | setConfigRedBits(8); |
| 43 | setConfigGreenBits(8); |
| 44 | setConfigBlueBits(8); |
| 45 | setConfigAlphaBits(8); |
| 46 | setConfigDepthBits(24); |
Geoff Lang | d191317 | 2013-10-18 16:15:10 -0400 | [diff] [blame] | 47 | } |
| 48 | |
Jamie Madill | cfd6b2b | 2016-02-08 12:50:38 -0500 | [diff] [blame] | 49 | void SetUp() override |
Geoff Lang | d191317 | 2013-10-18 16:15:10 -0400 | [diff] [blame] | 50 | { |
| 51 | ANGLETest::SetUp(); |
| 52 | |
Jamie Madill | cfd6b2b | 2016-02-08 12:50:38 -0500 | [diff] [blame] | 53 | 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 | { |
Geoff Lang | d191317 | 2013-10-18 16:15:10 -0400 | [diff] [blame] | 78 | const std::string vertexShaderSource = SHADER_SOURCE |
| 79 | ( |
| 80 | precision highp float; |
| 81 | attribute vec4 position; |
| 82 | |
| 83 | void main() |
| 84 | { |
| 85 | gl_Position = position; |
| 86 | } |
| 87 | ); |
| 88 | |
| 89 | const std::string fragmentShaderSource = SHADER_SOURCE |
| 90 | ( |
| 91 | precision highp float; |
| 92 | |
| 93 | void main() |
| 94 | { |
| 95 | gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); |
| 96 | } |
| 97 | ); |
| 98 | |
Jamie Madill | 5599c8f | 2014-08-26 13:16:39 -0400 | [diff] [blame] | 99 | mProgram = CompileProgram(vertexShaderSource, fragmentShaderSource); |
Jamie Madill | cfd6b2b | 2016-02-08 12:50:38 -0500 | [diff] [blame] | 100 | ASSERT_NE(0u, mProgram); |
Geoff Lang | d191317 | 2013-10-18 16:15:10 -0400 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | GLuint mProgram; |
Jamie Madill | cfd6b2b | 2016-02-08 12:50:38 -0500 | [diff] [blame] | 104 | std::vector<GLuint> mFBOs; |
| 105 | std::vector<GLuint> mTextures; |
Geoff Lang | d191317 | 2013-10-18 16:15:10 -0400 | [diff] [blame] | 106 | }; |
| 107 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 108 | class ClearTest : public ClearTestBase {}; |
| 109 | class ClearTestES3 : public ClearTestBase {}; |
Jamie Madill | 94203b3 | 2014-10-02 10:44:16 -0400 | [diff] [blame] | 110 | |
Geoff Lang | afd7f0a | 2015-09-09 15:33:31 -0400 | [diff] [blame] | 111 | // Test clearing the default framebuffer |
| 112 | TEST_P(ClearTest, DefaultFramebuffer) |
| 113 | { |
| 114 | glClearColor(0.25f, 0.5f, 0.5f, 0.5f); |
| 115 | glClear(GL_COLOR_BUFFER_BIT); |
| 116 | EXPECT_PIXEL_NEAR(0, 0, 64, 128, 128, 128, 1.0); |
| 117 | } |
| 118 | |
| 119 | // Test clearing a RGBA8 Framebuffer |
| 120 | TEST_P(ClearTest, RGBA8Framebuffer) |
| 121 | { |
Jamie Madill | cfd6b2b | 2016-02-08 12:50:38 -0500 | [diff] [blame] | 122 | glBindFramebuffer(GL_FRAMEBUFFER, mFBOs[0]); |
Geoff Lang | afd7f0a | 2015-09-09 15:33:31 -0400 | [diff] [blame] | 123 | |
| 124 | GLuint texture; |
| 125 | glGenTextures(1, &texture); |
| 126 | |
| 127 | glBindTexture(GL_TEXTURE_2D, texture); |
| 128 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, getWindowWidth(), getWindowHeight(), 0, GL_RGBA, |
| 129 | GL_UNSIGNED_BYTE, nullptr); |
| 130 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0); |
| 131 | |
| 132 | glClearColor(0.5f, 0.5f, 0.5f, 0.5f); |
| 133 | glClear(GL_COLOR_BUFFER_BIT); |
| 134 | |
| 135 | EXPECT_PIXEL_NEAR(0, 0, 128, 128, 128, 128, 1.0); |
| 136 | } |
| 137 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 138 | TEST_P(ClearTest, ClearIssue) |
Geoff Lang | d191317 | 2013-10-18 16:15:10 -0400 | [diff] [blame] | 139 | { |
Geoff Lang | 463cdea | 2015-04-28 13:22:31 -0400 | [diff] [blame] | 140 | // TODO(geofflang): Figure out why this is broken on Intel OpenGL |
Jamie Madill | 518b9fa | 2016-03-02 11:26:02 -0500 | [diff] [blame] | 141 | if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE) |
Geoff Lang | 463cdea | 2015-04-28 13:22:31 -0400 | [diff] [blame] | 142 | { |
| 143 | std::cout << "Test skipped on Intel OpenGL." << std::endl; |
| 144 | return; |
| 145 | } |
| 146 | |
Geoff Lang | d191317 | 2013-10-18 16:15:10 -0400 | [diff] [blame] | 147 | glEnable(GL_DEPTH_TEST); |
| 148 | glDepthFunc(GL_LEQUAL); |
| 149 | |
| 150 | glClearColor(0.0, 1.0, 0.0, 1.0); |
| 151 | glClearDepthf(0.0); |
| 152 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
| 153 | |
| 154 | EXPECT_GL_NO_ERROR(); |
| 155 | |
Jamie Madill | cfd6b2b | 2016-02-08 12:50:38 -0500 | [diff] [blame] | 156 | glBindFramebuffer(GL_FRAMEBUFFER, mFBOs[0]); |
Geoff Lang | d191317 | 2013-10-18 16:15:10 -0400 | [diff] [blame] | 157 | |
| 158 | GLuint rbo; |
| 159 | glGenRenderbuffers(1, &rbo); |
| 160 | glBindRenderbuffer(GL_RENDERBUFFER, rbo); |
| 161 | glRenderbufferStorage(GL_RENDERBUFFER, GL_RGB565, 16, 16); |
| 162 | |
| 163 | EXPECT_GL_NO_ERROR(); |
| 164 | |
| 165 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rbo); |
| 166 | |
| 167 | EXPECT_GL_NO_ERROR(); |
| 168 | |
| 169 | glClearColor(1.0f, 0.0f, 0.0f, 1.0f); |
| 170 | glClearDepthf(1.0f); |
| 171 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
| 172 | |
| 173 | EXPECT_GL_NO_ERROR(); |
| 174 | |
| 175 | glBindFramebuffer(GL_FRAMEBUFFER, 0); |
| 176 | glBindBuffer(GL_ARRAY_BUFFER, 0); |
| 177 | |
Jamie Madill | cfd6b2b | 2016-02-08 12:50:38 -0500 | [diff] [blame] | 178 | setupDefaultProgram(); |
Geoff Lang | d191317 | 2013-10-18 16:15:10 -0400 | [diff] [blame] | 179 | drawQuad(mProgram, "position", 0.5f); |
| 180 | |
| 181 | EXPECT_PIXEL_EQ(0, 0, 0, 255, 0, 255); |
| 182 | } |
Jamie Madill | a09403c | 2014-07-21 10:03:36 -0400 | [diff] [blame] | 183 | |
| 184 | // Requires ES3 |
| 185 | // This tests a bug where in a masked clear when calling "ClearBuffer", we would |
| 186 | // mistakenly clear every channel (including the masked-out ones) |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 187 | TEST_P(ClearTestES3, MaskedClearBufferBug) |
Jamie Madill | a09403c | 2014-07-21 10:03:36 -0400 | [diff] [blame] | 188 | { |
| 189 | unsigned char pixelData[] = { 255, 255, 255, 255 }; |
| 190 | |
Jamie Madill | cfd6b2b | 2016-02-08 12:50:38 -0500 | [diff] [blame] | 191 | glBindFramebuffer(GL_FRAMEBUFFER, mFBOs[0]); |
Jamie Madill | a09403c | 2014-07-21 10:03:36 -0400 | [diff] [blame] | 192 | |
| 193 | GLuint textures[2]; |
| 194 | glGenTextures(2, &textures[0]); |
| 195 | |
| 196 | glBindTexture(GL_TEXTURE_2D, textures[0]); |
| 197 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixelData); |
| 198 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0], 0); |
| 199 | |
| 200 | glBindTexture(GL_TEXTURE_2D, textures[1]); |
| 201 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixelData); |
| 202 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, textures[1], 0); |
| 203 | |
| 204 | ASSERT_GL_NO_ERROR(); |
| 205 | EXPECT_PIXEL_EQ(0, 0, 255, 255, 255, 255); |
| 206 | |
| 207 | float clearValue[] = { 0, 0.5f, 0.5f, 1.0f }; |
| 208 | GLenum drawBuffers[] = { GL_NONE, GL_COLOR_ATTACHMENT1 }; |
| 209 | glDrawBuffers(2, drawBuffers); |
| 210 | glColorMask(GL_TRUE, GL_TRUE, GL_FALSE, GL_TRUE); |
| 211 | glClearBufferfv(GL_COLOR, 1, clearValue); |
| 212 | |
| 213 | ASSERT_GL_NO_ERROR(); |
| 214 | EXPECT_PIXEL_EQ(0, 0, 255, 255, 255, 255); |
| 215 | |
Jamie Madill | cb34ea5 | 2015-12-11 16:01:18 -0500 | [diff] [blame] | 216 | glReadBuffer(GL_COLOR_ATTACHMENT1); |
| 217 | ASSERT_GL_NO_ERROR(); |
Jamie Madill | 9abdc2d | 2014-11-05 16:13:22 -0500 | [diff] [blame] | 218 | |
Jamie Madill | 9abdc2d | 2014-11-05 16:13:22 -0500 | [diff] [blame] | 219 | EXPECT_PIXEL_NEAR(0, 0, 0, 127, 255, 255, 1); |
Jamie Madill | c483326 | 2014-09-18 16:18:26 -0400 | [diff] [blame] | 220 | |
| 221 | glDeleteTextures(2, textures); |
| 222 | } |
| 223 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 224 | TEST_P(ClearTestES3, BadFBOSerialBug) |
Jamie Madill | c483326 | 2014-09-18 16:18:26 -0400 | [diff] [blame] | 225 | { |
| 226 | // First make a simple framebuffer, and clear it to green |
Jamie Madill | cfd6b2b | 2016-02-08 12:50:38 -0500 | [diff] [blame] | 227 | glBindFramebuffer(GL_FRAMEBUFFER, mFBOs[0]); |
Jamie Madill | c483326 | 2014-09-18 16:18:26 -0400 | [diff] [blame] | 228 | |
| 229 | GLuint textures[2]; |
| 230 | glGenTextures(2, &textures[0]); |
| 231 | |
| 232 | glBindTexture(GL_TEXTURE_2D, textures[0]); |
| 233 | glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, getWindowWidth(), getWindowHeight()); |
| 234 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0], 0); |
| 235 | |
| 236 | GLenum drawBuffers[] = { GL_COLOR_ATTACHMENT0 }; |
| 237 | glDrawBuffers(1, drawBuffers); |
| 238 | |
| 239 | float clearValues1[] = { 0.0f, 1.0f, 0.0f, 1.0f }; |
| 240 | glClearBufferfv(GL_COLOR, 0, clearValues1); |
| 241 | |
| 242 | ASSERT_GL_NO_ERROR(); |
| 243 | EXPECT_PIXEL_EQ(0, 0, 0, 255, 0, 255); |
| 244 | |
| 245 | // Next make a second framebuffer, and draw it to red |
| 246 | // (Triggers bad applied render target serial) |
| 247 | GLuint fbo2; |
| 248 | glGenFramebuffers(1, &fbo2); |
| 249 | ASSERT_GL_NO_ERROR(); |
| 250 | |
| 251 | glBindFramebuffer(GL_FRAMEBUFFER, fbo2); |
| 252 | |
| 253 | glBindTexture(GL_TEXTURE_2D, textures[1]); |
| 254 | glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, getWindowWidth(), getWindowHeight()); |
| 255 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[1], 0); |
| 256 | |
| 257 | glDrawBuffers(1, drawBuffers); |
| 258 | |
Jamie Madill | cfd6b2b | 2016-02-08 12:50:38 -0500 | [diff] [blame] | 259 | setupDefaultProgram(); |
Jamie Madill | c483326 | 2014-09-18 16:18:26 -0400 | [diff] [blame] | 260 | drawQuad(mProgram, "position", 0.5f); |
| 261 | |
| 262 | ASSERT_GL_NO_ERROR(); |
| 263 | EXPECT_PIXEL_EQ(0, 0, 255, 0, 0, 255); |
| 264 | |
| 265 | // Check that the first framebuffer is still green. |
Jamie Madill | cfd6b2b | 2016-02-08 12:50:38 -0500 | [diff] [blame] | 266 | glBindFramebuffer(GL_FRAMEBUFFER, mFBOs[0]); |
Jamie Madill | c483326 | 2014-09-18 16:18:26 -0400 | [diff] [blame] | 267 | EXPECT_PIXEL_EQ(0, 0, 0, 255, 0, 255); |
| 268 | |
| 269 | glDeleteTextures(2, textures); |
| 270 | glDeleteFramebuffers(1, &fbo2); |
Jamie Madill | a09403c | 2014-07-21 10:03:36 -0400 | [diff] [blame] | 271 | } |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 272 | |
Geoff Lang | afd7f0a | 2015-09-09 15:33:31 -0400 | [diff] [blame] | 273 | // Test that SRGB framebuffers clear to the linearized clear color |
| 274 | TEST_P(ClearTestES3, SRGBClear) |
| 275 | { |
Jamie Madill | 1ea9aaa | 2015-10-07 11:13:55 -0400 | [diff] [blame] | 276 | // TODO(jmadill): figure out why this fails |
Jamie Madill | 518b9fa | 2016-03-02 11:26:02 -0500 | [diff] [blame] | 277 | if (IsIntel() && GetParam() == ES3_OPENGL()) |
Jamie Madill | 1ea9aaa | 2015-10-07 11:13:55 -0400 | [diff] [blame] | 278 | { |
| 279 | std::cout << "Test skipped on Intel due to failures." << std::endl; |
| 280 | return; |
| 281 | } |
| 282 | |
Geoff Lang | afd7f0a | 2015-09-09 15:33:31 -0400 | [diff] [blame] | 283 | // First make a simple framebuffer, and clear it |
Jamie Madill | cfd6b2b | 2016-02-08 12:50:38 -0500 | [diff] [blame] | 284 | glBindFramebuffer(GL_FRAMEBUFFER, mFBOs[0]); |
Geoff Lang | afd7f0a | 2015-09-09 15:33:31 -0400 | [diff] [blame] | 285 | |
| 286 | GLuint texture; |
| 287 | glGenTextures(1, &texture); |
| 288 | |
| 289 | glBindTexture(GL_TEXTURE_2D, texture); |
| 290 | glTexStorage2D(GL_TEXTURE_2D, 1, GL_SRGB8_ALPHA8, getWindowWidth(), getWindowHeight()); |
| 291 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0); |
| 292 | |
| 293 | glClearColor(0.5f, 0.5f, 0.5f, 0.5f); |
| 294 | glClear(GL_COLOR_BUFFER_BIT); |
| 295 | |
| 296 | EXPECT_PIXEL_NEAR(0, 0, 188, 188, 188, 128, 1.0); |
| 297 | } |
| 298 | |
| 299 | // Test that framebuffers with mixed SRGB/Linear attachments clear to the correct color for each |
| 300 | // attachment |
| 301 | TEST_P(ClearTestES3, MixedSRGBClear) |
| 302 | { |
Corentin Wallez | 7b43c9b | 2015-09-30 10:47:30 -0700 | [diff] [blame] | 303 | // TODO(cwallez) figure out why it is broken on Intel on Mac |
Olli Etuaho | 36b7390 | 2015-10-05 11:58:50 +0300 | [diff] [blame] | 304 | #if defined(ANGLE_PLATFORM_APPLE) |
Jamie Madill | 518b9fa | 2016-03-02 11:26:02 -0500 | [diff] [blame] | 305 | if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE) |
Corentin Wallez | 7b43c9b | 2015-09-30 10:47:30 -0700 | [diff] [blame] | 306 | { |
| 307 | std::cout << "Test skipped on Intel on Mac." << std::endl; |
| 308 | return; |
| 309 | } |
| 310 | #endif |
| 311 | |
Jamie Madill | 1ea9aaa | 2015-10-07 11:13:55 -0400 | [diff] [blame] | 312 | // TODO(jmadill): figure out why this fails |
Jamie Madill | 518b9fa | 2016-03-02 11:26:02 -0500 | [diff] [blame] | 313 | if (IsIntel() && GetParam() == ES3_OPENGL()) |
Jamie Madill | 1ea9aaa | 2015-10-07 11:13:55 -0400 | [diff] [blame] | 314 | { |
| 315 | std::cout << "Test skipped on Intel due to failures." << std::endl; |
| 316 | return; |
| 317 | } |
| 318 | |
Jamie Madill | cfd6b2b | 2016-02-08 12:50:38 -0500 | [diff] [blame] | 319 | glBindFramebuffer(GL_FRAMEBUFFER, mFBOs[0]); |
Geoff Lang | afd7f0a | 2015-09-09 15:33:31 -0400 | [diff] [blame] | 320 | |
| 321 | GLuint textures[2]; |
| 322 | glGenTextures(2, &textures[0]); |
| 323 | |
| 324 | glBindTexture(GL_TEXTURE_2D, textures[0]); |
| 325 | glTexStorage2D(GL_TEXTURE_2D, 1, GL_SRGB8_ALPHA8, getWindowWidth(), getWindowHeight()); |
| 326 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0], 0); |
| 327 | |
| 328 | glBindTexture(GL_TEXTURE_2D, textures[1]); |
| 329 | glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, getWindowWidth(), getWindowHeight()); |
| 330 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, textures[1], 0); |
| 331 | |
| 332 | GLenum drawBuffers[] = {GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1}; |
| 333 | glDrawBuffers(2, drawBuffers); |
| 334 | |
| 335 | // Clear both textures |
| 336 | glClearColor(0.5f, 0.5f, 0.5f, 0.5f); |
| 337 | glClear(GL_COLOR_BUFFER_BIT); |
| 338 | |
| 339 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0); |
| 340 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, 0, 0); |
| 341 | |
| 342 | // Check value of texture0 |
| 343 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0], 0); |
| 344 | EXPECT_PIXEL_NEAR(0, 0, 188, 188, 188, 128, 1.0); |
| 345 | |
| 346 | // Check value of texture1 |
| 347 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[1], 0); |
| 348 | EXPECT_PIXEL_NEAR(0, 0, 128, 128, 128, 128, 1.0); |
| 349 | } |
| 350 | |
Jamie Madill | cfd6b2b | 2016-02-08 12:50:38 -0500 | [diff] [blame] | 351 | // This test covers a D3D11 bug where calling ClearRenderTargetView sometimes wouldn't sync |
| 352 | // before a draw call. The test draws small quads to a larger FBO (the default back buffer). |
| 353 | // Before each blit to the back buffer it clears the quad to a certain color using |
| 354 | // ClearBufferfv to give a solid color. The sync problem goes away if we insert a call to |
| 355 | // flush or finish after ClearBufferfv or each draw. |
| 356 | TEST_P(ClearTestES3, RepeatedClear) |
| 357 | { |
Jamie Madill | 518b9fa | 2016-03-02 11:26:02 -0500 | [diff] [blame] | 358 | if (IsD3D11() && (IsNVIDIA() || IsIntel())) |
Jamie Madill | cfd6b2b | 2016-02-08 12:50:38 -0500 | [diff] [blame] | 359 | { |
| 360 | std::cout << "Test skipped on Nvidia and Intel D3D11." << std::endl; |
| 361 | return; |
| 362 | } |
| 363 | |
| 364 | const std::string &vertexSource = |
| 365 | "#version 300 es\n" |
| 366 | "in highp vec2 position;\n" |
| 367 | "out highp vec2 v_coord;\n" |
| 368 | "void main(void)\n" |
| 369 | "{\n" |
| 370 | " gl_Position = vec4(position, 0, 1);\n" |
| 371 | " vec2 texCoord = (position * 0.5) + 0.5;\n" |
| 372 | " v_coord = texCoord;\n" |
| 373 | "}\n"; |
| 374 | |
| 375 | const std::string &fragmentSource = |
| 376 | "#version 300 es\n" |
| 377 | "in highp vec2 v_coord;\n" |
| 378 | "out highp vec4 color;\n" |
| 379 | "uniform sampler2D tex;\n" |
| 380 | "void main()\n" |
| 381 | "{\n" |
| 382 | " color = texture(tex, v_coord);\n" |
| 383 | "}\n"; |
| 384 | |
| 385 | mProgram = CompileProgram(vertexSource, fragmentSource); |
| 386 | ASSERT_NE(0u, mProgram); |
| 387 | |
| 388 | mTextures.resize(1, 0); |
| 389 | glGenTextures(1, mTextures.data()); |
| 390 | |
| 391 | GLenum format = GL_RGBA8; |
| 392 | const int numRowsCols = 3; |
| 393 | const int cellSize = 32; |
| 394 | const int fboSize = cellSize; |
| 395 | const int backFBOSize = cellSize * numRowsCols; |
| 396 | const float fmtValueMin = 0.0f; |
| 397 | const float fmtValueMax = 1.0f; |
| 398 | |
| 399 | glBindTexture(GL_TEXTURE_2D, mTextures[0]); |
| 400 | glTexStorage2D(GL_TEXTURE_2D, 1, format, fboSize, fboSize); |
| 401 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 402 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 403 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 404 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 405 | ASSERT_GL_NO_ERROR(); |
| 406 | |
| 407 | glBindFramebuffer(GL_FRAMEBUFFER, mFBOs[0]); |
| 408 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextures[0], 0); |
| 409 | ASSERT_GL_NO_ERROR(); |
| 410 | |
| 411 | ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 412 | |
| 413 | // larger fbo bound -- clear to transparent black |
| 414 | glUseProgram(mProgram); |
| 415 | GLint uniLoc = glGetUniformLocation(mProgram, "tex"); |
| 416 | ASSERT_NE(-1, uniLoc); |
| 417 | glUniform1i(uniLoc, 0); |
| 418 | glBindTexture(GL_TEXTURE_2D, mTextures[0]); |
| 419 | |
| 420 | GLint positionLocation = glGetAttribLocation(mProgram, "position"); |
| 421 | ASSERT_NE(-1, positionLocation); |
| 422 | |
| 423 | glUseProgram(mProgram); |
| 424 | |
| 425 | for (int cellY = 0; cellY < numRowsCols; cellY++) |
| 426 | { |
| 427 | for (int cellX = 0; cellX < numRowsCols; cellX++) |
| 428 | { |
| 429 | int seed = cellX + cellY * numRowsCols; |
| 430 | const Vector4 color = RandomVec4(seed, fmtValueMin, fmtValueMax); |
| 431 | |
| 432 | glBindFramebuffer(GL_FRAMEBUFFER, mFBOs[0]); |
| 433 | glClearBufferfv(GL_COLOR, 0, color.data()); |
| 434 | |
| 435 | glBindFramebuffer(GL_FRAMEBUFFER, 0); |
| 436 | |
| 437 | // Method 1: Set viewport and draw full-viewport quad |
| 438 | glViewport(cellX * cellSize, cellY * cellSize, cellSize, cellSize); |
| 439 | drawQuad(mProgram, "position", 0.5f); |
| 440 | |
| 441 | // Uncommenting the glFinish call seems to make the test pass. |
| 442 | // glFinish(); |
| 443 | } |
| 444 | } |
| 445 | |
| 446 | std::vector<GLColor> pixelData(backFBOSize * backFBOSize); |
| 447 | glReadPixels(0, 0, backFBOSize, backFBOSize, GL_RGBA, GL_UNSIGNED_BYTE, pixelData.data()); |
| 448 | |
| 449 | for (int cellY = 0; cellY < numRowsCols; cellY++) |
| 450 | { |
| 451 | for (int cellX = 0; cellX < numRowsCols; cellX++) |
| 452 | { |
| 453 | int seed = cellX + cellY * numRowsCols; |
| 454 | const Vector4 color = RandomVec4(seed, fmtValueMin, fmtValueMax); |
| 455 | GLColor expectedColor = Vec4ToColor(color); |
| 456 | |
| 457 | int testN = cellX * cellSize + cellY * backFBOSize * cellSize + backFBOSize + 1; |
| 458 | GLColor actualColor = pixelData[testN]; |
| 459 | EXPECT_NEAR(expectedColor.R, actualColor.R, 1); |
| 460 | EXPECT_NEAR(expectedColor.G, actualColor.G, 1); |
| 461 | EXPECT_NEAR(expectedColor.B, actualColor.B, 1); |
| 462 | EXPECT_NEAR(expectedColor.A, actualColor.A, 1); |
| 463 | } |
| 464 | } |
| 465 | |
| 466 | ASSERT_GL_NO_ERROR(); |
| 467 | } |
| 468 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 469 | // Use this to select which configurations (e.g. which renderer, which GLES major version) these tests should be run against. |
Geoff Lang | e0cc2a4 | 2016-01-20 10:58:17 -0500 | [diff] [blame] | 470 | ANGLE_INSTANTIATE_TEST(ClearTest, |
| 471 | ES2_D3D9(), |
| 472 | ES2_D3D11(), |
| 473 | ES3_D3D11(), |
| 474 | ES2_OPENGL(), |
| 475 | ES3_OPENGL(), |
| 476 | ES2_OPENGLES(), |
| 477 | ES3_OPENGLES()); |
| 478 | ANGLE_INSTANTIATE_TEST(ClearTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES()); |
Jamie Madill | cfd6b2b | 2016-02-08 12:50:38 -0500 | [diff] [blame] | 479 | |
| 480 | } // anonymous namespace |