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 | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 9 | using namespace angle; |
Jamie Madill | 94203b3 | 2014-10-02 10:44:16 -0400 | [diff] [blame] | 10 | |
Jamie Madill | 94203b3 | 2014-10-02 10:44:16 -0400 | [diff] [blame] | 11 | class ClearTestBase : public ANGLETest |
Geoff Lang | d191317 | 2013-10-18 16:15:10 -0400 | [diff] [blame] | 12 | { |
Jamie Madill | 94203b3 | 2014-10-02 10:44:16 -0400 | [diff] [blame] | 13 | protected: |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 14 | ClearTestBase() |
Geoff Lang | d191317 | 2013-10-18 16:15:10 -0400 | [diff] [blame] | 15 | { |
| 16 | setWindowWidth(128); |
| 17 | setWindowHeight(128); |
Geoff Lang | efc551f | 2013-10-31 10:20:28 -0400 | [diff] [blame] | 18 | setConfigRedBits(8); |
| 19 | setConfigGreenBits(8); |
| 20 | setConfigBlueBits(8); |
| 21 | setConfigAlphaBits(8); |
| 22 | setConfigDepthBits(24); |
Geoff Lang | d191317 | 2013-10-18 16:15:10 -0400 | [diff] [blame] | 23 | } |
| 24 | |
| 25 | virtual void SetUp() |
| 26 | { |
| 27 | ANGLETest::SetUp(); |
| 28 | |
| 29 | const std::string vertexShaderSource = SHADER_SOURCE |
| 30 | ( |
| 31 | precision highp float; |
| 32 | attribute vec4 position; |
| 33 | |
| 34 | void main() |
| 35 | { |
| 36 | gl_Position = position; |
| 37 | } |
| 38 | ); |
| 39 | |
| 40 | const std::string fragmentShaderSource = SHADER_SOURCE |
| 41 | ( |
| 42 | precision highp float; |
| 43 | |
| 44 | void main() |
| 45 | { |
| 46 | gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); |
| 47 | } |
| 48 | ); |
| 49 | |
Jamie Madill | 5599c8f | 2014-08-26 13:16:39 -0400 | [diff] [blame] | 50 | mProgram = CompileProgram(vertexShaderSource, fragmentShaderSource); |
Geoff Lang | d191317 | 2013-10-18 16:15:10 -0400 | [diff] [blame] | 51 | if (mProgram == 0) |
| 52 | { |
| 53 | FAIL() << "shader compilation failed."; |
| 54 | } |
Jamie Madill | a09403c | 2014-07-21 10:03:36 -0400 | [diff] [blame] | 55 | |
| 56 | glGenFramebuffers(1, &mFBO); |
| 57 | |
| 58 | ASSERT_GL_NO_ERROR(); |
Geoff Lang | d191317 | 2013-10-18 16:15:10 -0400 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | virtual void TearDown() |
| 62 | { |
| 63 | glDeleteProgram(mProgram); |
Jamie Madill | a09403c | 2014-07-21 10:03:36 -0400 | [diff] [blame] | 64 | glDeleteFramebuffers(1, &mFBO); |
Geoff Lang | d191317 | 2013-10-18 16:15:10 -0400 | [diff] [blame] | 65 | |
| 66 | ANGLETest::TearDown(); |
| 67 | } |
| 68 | |
| 69 | GLuint mProgram; |
Jamie Madill | a09403c | 2014-07-21 10:03:36 -0400 | [diff] [blame] | 70 | GLuint mFBO; |
Geoff Lang | d191317 | 2013-10-18 16:15:10 -0400 | [diff] [blame] | 71 | }; |
| 72 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 73 | class ClearTest : public ClearTestBase {}; |
| 74 | class ClearTestES3 : public ClearTestBase {}; |
Jamie Madill | 94203b3 | 2014-10-02 10:44:16 -0400 | [diff] [blame] | 75 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 76 | TEST_P(ClearTest, ClearIssue) |
Geoff Lang | d191317 | 2013-10-18 16:15:10 -0400 | [diff] [blame] | 77 | { |
Geoff Lang | 463cdea | 2015-04-28 13:22:31 -0400 | [diff] [blame] | 78 | // TODO(geofflang): Figure out why this is broken on Intel OpenGL |
| 79 | if (isIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE) |
| 80 | { |
| 81 | std::cout << "Test skipped on Intel OpenGL." << std::endl; |
| 82 | return; |
| 83 | } |
| 84 | |
Geoff Lang | d191317 | 2013-10-18 16:15:10 -0400 | [diff] [blame] | 85 | glEnable(GL_DEPTH_TEST); |
| 86 | glDepthFunc(GL_LEQUAL); |
| 87 | |
| 88 | glClearColor(0.0, 1.0, 0.0, 1.0); |
| 89 | glClearDepthf(0.0); |
| 90 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
| 91 | |
| 92 | EXPECT_GL_NO_ERROR(); |
| 93 | |
Jamie Madill | a09403c | 2014-07-21 10:03:36 -0400 | [diff] [blame] | 94 | glBindFramebuffer(GL_FRAMEBUFFER, mFBO); |
Geoff Lang | d191317 | 2013-10-18 16:15:10 -0400 | [diff] [blame] | 95 | |
| 96 | GLuint rbo; |
| 97 | glGenRenderbuffers(1, &rbo); |
| 98 | glBindRenderbuffer(GL_RENDERBUFFER, rbo); |
| 99 | glRenderbufferStorage(GL_RENDERBUFFER, GL_RGB565, 16, 16); |
| 100 | |
| 101 | EXPECT_GL_NO_ERROR(); |
| 102 | |
| 103 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rbo); |
| 104 | |
| 105 | EXPECT_GL_NO_ERROR(); |
| 106 | |
| 107 | glClearColor(1.0f, 0.0f, 0.0f, 1.0f); |
| 108 | glClearDepthf(1.0f); |
| 109 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
| 110 | |
| 111 | EXPECT_GL_NO_ERROR(); |
| 112 | |
| 113 | glBindFramebuffer(GL_FRAMEBUFFER, 0); |
| 114 | glBindBuffer(GL_ARRAY_BUFFER, 0); |
| 115 | |
| 116 | drawQuad(mProgram, "position", 0.5f); |
| 117 | |
| 118 | EXPECT_PIXEL_EQ(0, 0, 0, 255, 0, 255); |
| 119 | } |
Jamie Madill | a09403c | 2014-07-21 10:03:36 -0400 | [diff] [blame] | 120 | |
| 121 | // Requires ES3 |
| 122 | // This tests a bug where in a masked clear when calling "ClearBuffer", we would |
| 123 | // mistakenly clear every channel (including the masked-out ones) |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 124 | TEST_P(ClearTestES3, MaskedClearBufferBug) |
Jamie Madill | a09403c | 2014-07-21 10:03:36 -0400 | [diff] [blame] | 125 | { |
| 126 | unsigned char pixelData[] = { 255, 255, 255, 255 }; |
| 127 | |
| 128 | glBindFramebuffer(GL_FRAMEBUFFER, mFBO); |
| 129 | |
| 130 | GLuint textures[2]; |
| 131 | glGenTextures(2, &textures[0]); |
| 132 | |
| 133 | glBindTexture(GL_TEXTURE_2D, textures[0]); |
| 134 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixelData); |
| 135 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0], 0); |
| 136 | |
| 137 | glBindTexture(GL_TEXTURE_2D, textures[1]); |
| 138 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixelData); |
| 139 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, textures[1], 0); |
| 140 | |
| 141 | ASSERT_GL_NO_ERROR(); |
| 142 | EXPECT_PIXEL_EQ(0, 0, 255, 255, 255, 255); |
| 143 | |
| 144 | float clearValue[] = { 0, 0.5f, 0.5f, 1.0f }; |
| 145 | GLenum drawBuffers[] = { GL_NONE, GL_COLOR_ATTACHMENT1 }; |
| 146 | glDrawBuffers(2, drawBuffers); |
| 147 | glColorMask(GL_TRUE, GL_TRUE, GL_FALSE, GL_TRUE); |
| 148 | glClearBufferfv(GL_COLOR, 1, clearValue); |
| 149 | |
| 150 | ASSERT_GL_NO_ERROR(); |
| 151 | EXPECT_PIXEL_EQ(0, 0, 255, 255, 255, 255); |
| 152 | |
| 153 | // TODO: glReadBuffer support |
| 154 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, 0, 0); |
| 155 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[1], 0); |
Jamie Madill | 9abdc2d | 2014-11-05 16:13:22 -0500 | [diff] [blame] | 156 | |
| 157 | //TODO(jmadill): Robust handling of pixel test error ranges |
| 158 | EXPECT_PIXEL_NEAR(0, 0, 0, 127, 255, 255, 1); |
Jamie Madill | c483326 | 2014-09-18 16:18:26 -0400 | [diff] [blame] | 159 | |
| 160 | glDeleteTextures(2, textures); |
| 161 | } |
| 162 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 163 | TEST_P(ClearTestES3, BadFBOSerialBug) |
Jamie Madill | c483326 | 2014-09-18 16:18:26 -0400 | [diff] [blame] | 164 | { |
| 165 | // First make a simple framebuffer, and clear it to green |
| 166 | glBindFramebuffer(GL_FRAMEBUFFER, mFBO); |
| 167 | |
| 168 | GLuint textures[2]; |
| 169 | glGenTextures(2, &textures[0]); |
| 170 | |
| 171 | glBindTexture(GL_TEXTURE_2D, textures[0]); |
| 172 | glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, getWindowWidth(), getWindowHeight()); |
| 173 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0], 0); |
| 174 | |
| 175 | GLenum drawBuffers[] = { GL_COLOR_ATTACHMENT0 }; |
| 176 | glDrawBuffers(1, drawBuffers); |
| 177 | |
| 178 | float clearValues1[] = { 0.0f, 1.0f, 0.0f, 1.0f }; |
| 179 | glClearBufferfv(GL_COLOR, 0, clearValues1); |
| 180 | |
| 181 | ASSERT_GL_NO_ERROR(); |
| 182 | EXPECT_PIXEL_EQ(0, 0, 0, 255, 0, 255); |
| 183 | |
| 184 | // Next make a second framebuffer, and draw it to red |
| 185 | // (Triggers bad applied render target serial) |
| 186 | GLuint fbo2; |
| 187 | glGenFramebuffers(1, &fbo2); |
| 188 | ASSERT_GL_NO_ERROR(); |
| 189 | |
| 190 | glBindFramebuffer(GL_FRAMEBUFFER, fbo2); |
| 191 | |
| 192 | glBindTexture(GL_TEXTURE_2D, textures[1]); |
| 193 | glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, getWindowWidth(), getWindowHeight()); |
| 194 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[1], 0); |
| 195 | |
| 196 | glDrawBuffers(1, drawBuffers); |
| 197 | |
| 198 | drawQuad(mProgram, "position", 0.5f); |
| 199 | |
| 200 | ASSERT_GL_NO_ERROR(); |
| 201 | EXPECT_PIXEL_EQ(0, 0, 255, 0, 0, 255); |
| 202 | |
| 203 | // Check that the first framebuffer is still green. |
| 204 | glBindFramebuffer(GL_FRAMEBUFFER, mFBO); |
| 205 | EXPECT_PIXEL_EQ(0, 0, 0, 255, 0, 255); |
| 206 | |
| 207 | glDeleteTextures(2, textures); |
| 208 | glDeleteFramebuffers(1, &fbo2); |
Jamie Madill | a09403c | 2014-07-21 10:03:36 -0400 | [diff] [blame] | 209 | } |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 210 | |
| 211 | // Use this to select which configurations (e.g. which renderer, which GLES major version) these tests should be run against. |
| 212 | ANGLE_INSTANTIATE_TEST(ClearTest, ES2_D3D9(), ES2_D3D11(), ES3_D3D11(), ES2_OPENGL(), ES3_OPENGL()); |
| 213 | ANGLE_INSTANTIATE_TEST(ClearTestES3, ES3_D3D11()); |