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 | { |
Olli Etuaho | a20af6d | 2017-09-18 13:32:29 +0300 | [diff] [blame^] | 78 | const std::string vertexShaderSource = |
| 79 | R"(precision highp float; |
Geoff Lang | d191317 | 2013-10-18 16:15:10 -0400 | [diff] [blame] | 80 | attribute vec4 position; |
| 81 | |
| 82 | void main() |
| 83 | { |
| 84 | gl_Position = position; |
Olli Etuaho | a20af6d | 2017-09-18 13:32:29 +0300 | [diff] [blame^] | 85 | })"; |
Geoff Lang | d191317 | 2013-10-18 16:15:10 -0400 | [diff] [blame] | 86 | |
Olli Etuaho | a20af6d | 2017-09-18 13:32:29 +0300 | [diff] [blame^] | 87 | const std::string fragmentShaderSource = |
| 88 | R"(precision highp float; |
Geoff Lang | d191317 | 2013-10-18 16:15:10 -0400 | [diff] [blame] | 89 | |
| 90 | void main() |
| 91 | { |
| 92 | gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); |
Olli Etuaho | a20af6d | 2017-09-18 13:32:29 +0300 | [diff] [blame^] | 93 | })"; |
Geoff Lang | d191317 | 2013-10-18 16:15:10 -0400 | [diff] [blame] | 94 | |
Jamie Madill | 5599c8f | 2014-08-26 13:16:39 -0400 | [diff] [blame] | 95 | mProgram = CompileProgram(vertexShaderSource, fragmentShaderSource); |
Jamie Madill | cfd6b2b | 2016-02-08 12:50:38 -0500 | [diff] [blame] | 96 | ASSERT_NE(0u, mProgram); |
Geoff Lang | d191317 | 2013-10-18 16:15:10 -0400 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | GLuint mProgram; |
Jamie Madill | cfd6b2b | 2016-02-08 12:50:38 -0500 | [diff] [blame] | 100 | std::vector<GLuint> mFBOs; |
| 101 | std::vector<GLuint> mTextures; |
Geoff Lang | d191317 | 2013-10-18 16:15:10 -0400 | [diff] [blame] | 102 | }; |
| 103 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 104 | class ClearTest : public ClearTestBase {}; |
| 105 | class ClearTestES3 : public ClearTestBase {}; |
Jamie Madill | 94203b3 | 2014-10-02 10:44:16 -0400 | [diff] [blame] | 106 | |
Geoff Lang | afd7f0a | 2015-09-09 15:33:31 -0400 | [diff] [blame] | 107 | // Test clearing the default framebuffer |
| 108 | TEST_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 |
| 116 | TEST_P(ClearTest, RGBA8Framebuffer) |
| 117 | { |
Jamie Madill | cfd6b2b | 2016-02-08 12:50:38 -0500 | [diff] [blame] | 118 | glBindFramebuffer(GL_FRAMEBUFFER, mFBOs[0]); |
Geoff Lang | afd7f0a | 2015-09-09 15:33:31 -0400 | [diff] [blame] | 119 | |
| 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 Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 134 | TEST_P(ClearTest, ClearIssue) |
Geoff Lang | d191317 | 2013-10-18 16:15:10 -0400 | [diff] [blame] | 135 | { |
Geoff Lang | 463cdea | 2015-04-28 13:22:31 -0400 | [diff] [blame] | 136 | // TODO(geofflang): Figure out why this is broken on Intel OpenGL |
Jamie Madill | 518b9fa | 2016-03-02 11:26:02 -0500 | [diff] [blame] | 137 | if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE) |
Geoff Lang | 463cdea | 2015-04-28 13:22:31 -0400 | [diff] [blame] | 138 | { |
| 139 | std::cout << "Test skipped on Intel OpenGL." << std::endl; |
| 140 | return; |
| 141 | } |
| 142 | |
Geoff Lang | d191317 | 2013-10-18 16:15:10 -0400 | [diff] [blame] | 143 | 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 Madill | cfd6b2b | 2016-02-08 12:50:38 -0500 | [diff] [blame] | 152 | glBindFramebuffer(GL_FRAMEBUFFER, mFBOs[0]); |
Geoff Lang | d191317 | 2013-10-18 16:15:10 -0400 | [diff] [blame] | 153 | |
| 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 Madill | cfd6b2b | 2016-02-08 12:50:38 -0500 | [diff] [blame] | 174 | setupDefaultProgram(); |
Geoff Lang | d191317 | 2013-10-18 16:15:10 -0400 | [diff] [blame] | 175 | drawQuad(mProgram, "position", 0.5f); |
| 176 | |
| 177 | EXPECT_PIXEL_EQ(0, 0, 0, 255, 0, 255); |
| 178 | } |
Jamie Madill | a09403c | 2014-07-21 10:03:36 -0400 | [diff] [blame] | 179 | |
| 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 Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 183 | TEST_P(ClearTestES3, MaskedClearBufferBug) |
Jamie Madill | a09403c | 2014-07-21 10:03:36 -0400 | [diff] [blame] | 184 | { |
| 185 | unsigned char pixelData[] = { 255, 255, 255, 255 }; |
| 186 | |
Jamie Madill | cfd6b2b | 2016-02-08 12:50:38 -0500 | [diff] [blame] | 187 | glBindFramebuffer(GL_FRAMEBUFFER, mFBOs[0]); |
Jamie Madill | a09403c | 2014-07-21 10:03:36 -0400 | [diff] [blame] | 188 | |
| 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 Madill | cb34ea5 | 2015-12-11 16:01:18 -0500 | [diff] [blame] | 212 | glReadBuffer(GL_COLOR_ATTACHMENT1); |
| 213 | ASSERT_GL_NO_ERROR(); |
Jamie Madill | 9abdc2d | 2014-11-05 16:13:22 -0500 | [diff] [blame] | 214 | |
Jamie Madill | 9abdc2d | 2014-11-05 16:13:22 -0500 | [diff] [blame] | 215 | EXPECT_PIXEL_NEAR(0, 0, 0, 127, 255, 255, 1); |
Jamie Madill | c483326 | 2014-09-18 16:18:26 -0400 | [diff] [blame] | 216 | |
| 217 | glDeleteTextures(2, textures); |
| 218 | } |
| 219 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 220 | TEST_P(ClearTestES3, BadFBOSerialBug) |
Jamie Madill | c483326 | 2014-09-18 16:18:26 -0400 | [diff] [blame] | 221 | { |
| 222 | // First make a simple framebuffer, and clear it to green |
Jamie Madill | cfd6b2b | 2016-02-08 12:50:38 -0500 | [diff] [blame] | 223 | glBindFramebuffer(GL_FRAMEBUFFER, mFBOs[0]); |
Jamie Madill | c483326 | 2014-09-18 16:18:26 -0400 | [diff] [blame] | 224 | |
| 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 Madill | cfd6b2b | 2016-02-08 12:50:38 -0500 | [diff] [blame] | 255 | setupDefaultProgram(); |
Jamie Madill | c483326 | 2014-09-18 16:18:26 -0400 | [diff] [blame] | 256 | 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 Madill | cfd6b2b | 2016-02-08 12:50:38 -0500 | [diff] [blame] | 262 | glBindFramebuffer(GL_FRAMEBUFFER, mFBOs[0]); |
Jamie Madill | c483326 | 2014-09-18 16:18:26 -0400 | [diff] [blame] | 263 | EXPECT_PIXEL_EQ(0, 0, 0, 255, 0, 255); |
| 264 | |
| 265 | glDeleteTextures(2, textures); |
| 266 | glDeleteFramebuffers(1, &fbo2); |
Jamie Madill | a09403c | 2014-07-21 10:03:36 -0400 | [diff] [blame] | 267 | } |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 268 | |
Geoff Lang | afd7f0a | 2015-09-09 15:33:31 -0400 | [diff] [blame] | 269 | // Test that SRGB framebuffers clear to the linearized clear color |
| 270 | TEST_P(ClearTestES3, SRGBClear) |
| 271 | { |
Jamie Madill | 1ea9aaa | 2015-10-07 11:13:55 -0400 | [diff] [blame] | 272 | // TODO(jmadill): figure out why this fails |
Jamie Madill | 518b9fa | 2016-03-02 11:26:02 -0500 | [diff] [blame] | 273 | if (IsIntel() && GetParam() == ES3_OPENGL()) |
Jamie Madill | 1ea9aaa | 2015-10-07 11:13:55 -0400 | [diff] [blame] | 274 | { |
| 275 | std::cout << "Test skipped on Intel due to failures." << std::endl; |
| 276 | return; |
| 277 | } |
| 278 | |
Geoff Lang | afd7f0a | 2015-09-09 15:33:31 -0400 | [diff] [blame] | 279 | // First make a simple framebuffer, and clear it |
Jamie Madill | cfd6b2b | 2016-02-08 12:50:38 -0500 | [diff] [blame] | 280 | glBindFramebuffer(GL_FRAMEBUFFER, mFBOs[0]); |
Geoff Lang | afd7f0a | 2015-09-09 15:33:31 -0400 | [diff] [blame] | 281 | |
| 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 |
| 297 | TEST_P(ClearTestES3, MixedSRGBClear) |
| 298 | { |
Corentin Wallez | 7b43c9b | 2015-09-30 10:47:30 -0700 | [diff] [blame] | 299 | // TODO(cwallez) figure out why it is broken on Intel on Mac |
Olli Etuaho | 36b7390 | 2015-10-05 11:58:50 +0300 | [diff] [blame] | 300 | #if defined(ANGLE_PLATFORM_APPLE) |
Jamie Madill | 518b9fa | 2016-03-02 11:26:02 -0500 | [diff] [blame] | 301 | if (IsIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE) |
Corentin Wallez | 7b43c9b | 2015-09-30 10:47:30 -0700 | [diff] [blame] | 302 | { |
| 303 | std::cout << "Test skipped on Intel on Mac." << std::endl; |
| 304 | return; |
| 305 | } |
| 306 | #endif |
| 307 | |
Jamie Madill | 1ea9aaa | 2015-10-07 11:13:55 -0400 | [diff] [blame] | 308 | // TODO(jmadill): figure out why this fails |
Jamie Madill | 518b9fa | 2016-03-02 11:26:02 -0500 | [diff] [blame] | 309 | if (IsIntel() && GetParam() == ES3_OPENGL()) |
Jamie Madill | 1ea9aaa | 2015-10-07 11:13:55 -0400 | [diff] [blame] | 310 | { |
| 311 | std::cout << "Test skipped on Intel due to failures." << std::endl; |
| 312 | return; |
| 313 | } |
| 314 | |
Jamie Madill | cfd6b2b | 2016-02-08 12:50:38 -0500 | [diff] [blame] | 315 | glBindFramebuffer(GL_FRAMEBUFFER, mFBOs[0]); |
Geoff Lang | afd7f0a | 2015-09-09 15:33:31 -0400 | [diff] [blame] | 316 | |
| 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 Madill | cfd6b2b | 2016-02-08 12:50:38 -0500 | [diff] [blame] | 347 | // 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. |
| 352 | TEST_P(ClearTestES3, RepeatedClear) |
| 353 | { |
Olli Etuaho | df7d13e | 2017-05-30 13:53:45 +0300 | [diff] [blame] | 354 | if (IsD3D11() && IsIntel()) |
Jamie Madill | cfd6b2b | 2016-02-08 12:50:38 -0500 | [diff] [blame] | 355 | { |
Olli Etuaho | df7d13e | 2017-05-30 13:53:45 +0300 | [diff] [blame] | 356 | // 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 Madill | cfd6b2b | 2016-02-08 12:50:38 -0500 | [diff] [blame] | 359 | 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 Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 467 | // 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] | 468 | ANGLE_INSTANTIATE_TEST(ClearTest, |
| 469 | ES2_D3D9(), |
| 470 | ES2_D3D11(), |
| 471 | ES3_D3D11(), |
| 472 | ES2_OPENGL(), |
| 473 | ES3_OPENGL(), |
| 474 | ES2_OPENGLES(), |
| 475 | ES3_OPENGLES()); |
| 476 | ANGLE_INSTANTIATE_TEST(ClearTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES()); |
Jamie Madill | cfd6b2b | 2016-02-08 12:50:38 -0500 | [diff] [blame] | 477 | |
| 478 | } // anonymous namespace |