blob: 42eb1afca766587330a7b72dd67eadf3ba267d5c [file] [log] [blame]
Geoff Langd1913172013-10-18 16:15:10 -04001#include "ANGLETest.h"
2
Austin Kinross18b931d2014-09-29 12:58:31 -07003// Use this to select which configurations (e.g. which renderer, which GLES major version) these tests should be run against.
Geoff Lang5b028d12015-04-27 10:43:54 -04004ANGLE_TYPED_TEST_CASE(ClearTest, ES2_D3D9, ES2_D3D11, ES3_D3D11, ES2_OPENGL, ES3_OPENGL);
Geoff Lang0d3683c2014-10-23 11:08:16 -04005ANGLE_TYPED_TEST_CASE(ClearTestES3, ES3_D3D11);
Jamie Madill94203b32014-10-02 10:44:16 -04006
Austin Kinross18b931d2014-09-29 12:58:31 -07007template<typename T>
Jamie Madill94203b32014-10-02 10:44:16 -04008class ClearTestBase : public ANGLETest
Geoff Langd1913172013-10-18 16:15:10 -04009{
Jamie Madill94203b32014-10-02 10:44:16 -040010 protected:
Geoff Lang0d3683c2014-10-23 11:08:16 -040011 ClearTestBase() : ANGLETest(T::GetGlesMajorVersion(), T::GetPlatform())
Geoff Langd1913172013-10-18 16:15:10 -040012 {
13 setWindowWidth(128);
14 setWindowHeight(128);
Geoff Langefc551f2013-10-31 10:20:28 -040015 setConfigRedBits(8);
16 setConfigGreenBits(8);
17 setConfigBlueBits(8);
18 setConfigAlphaBits(8);
19 setConfigDepthBits(24);
Geoff Langd1913172013-10-18 16:15:10 -040020 }
21
22 virtual void SetUp()
23 {
24 ANGLETest::SetUp();
25
26 const std::string vertexShaderSource = SHADER_SOURCE
27 (
28 precision highp float;
29 attribute vec4 position;
30
31 void main()
32 {
33 gl_Position = position;
34 }
35 );
36
37 const std::string fragmentShaderSource = SHADER_SOURCE
38 (
39 precision highp float;
40
41 void main()
42 {
43 gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
44 }
45 );
46
Jamie Madill5599c8f2014-08-26 13:16:39 -040047 mProgram = CompileProgram(vertexShaderSource, fragmentShaderSource);
Geoff Langd1913172013-10-18 16:15:10 -040048 if (mProgram == 0)
49 {
50 FAIL() << "shader compilation failed.";
51 }
Jamie Madilla09403c2014-07-21 10:03:36 -040052
53 glGenFramebuffers(1, &mFBO);
54
55 ASSERT_GL_NO_ERROR();
Geoff Langd1913172013-10-18 16:15:10 -040056 }
57
58 virtual void TearDown()
59 {
60 glDeleteProgram(mProgram);
Jamie Madilla09403c2014-07-21 10:03:36 -040061 glDeleteFramebuffers(1, &mFBO);
Geoff Langd1913172013-10-18 16:15:10 -040062
63 ANGLETest::TearDown();
64 }
65
66 GLuint mProgram;
Jamie Madilla09403c2014-07-21 10:03:36 -040067 GLuint mFBO;
Geoff Langd1913172013-10-18 16:15:10 -040068};
69
Jamie Madill94203b32014-10-02 10:44:16 -040070template <typename T>
71class ClearTest : public ClearTestBase<T>
72{};
73
74template <typename T>
75class ClearTestES3 : public ClearTestBase<T>
76{};
77
Austin Kinross18b931d2014-09-29 12:58:31 -070078TYPED_TEST(ClearTest, ClearIssue)
Geoff Langd1913172013-10-18 16:15:10 -040079{
Geoff Lang463cdea2015-04-28 13:22:31 -040080 // TODO(geofflang): Figure out why this is broken on Intel OpenGL
81 if (isIntel() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
82 {
83 std::cout << "Test skipped on Intel OpenGL." << std::endl;
84 return;
85 }
86
Geoff Langd1913172013-10-18 16:15:10 -040087 glEnable(GL_DEPTH_TEST);
88 glDepthFunc(GL_LEQUAL);
89
90 glClearColor(0.0, 1.0, 0.0, 1.0);
91 glClearDepthf(0.0);
92 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
93
94 EXPECT_GL_NO_ERROR();
95
Jamie Madilla09403c2014-07-21 10:03:36 -040096 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
Geoff Langd1913172013-10-18 16:15:10 -040097
98 GLuint rbo;
99 glGenRenderbuffers(1, &rbo);
100 glBindRenderbuffer(GL_RENDERBUFFER, rbo);
101 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGB565, 16, 16);
102
103 EXPECT_GL_NO_ERROR();
104
105 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rbo);
106
107 EXPECT_GL_NO_ERROR();
108
109 glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
110 glClearDepthf(1.0f);
111 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
112
113 EXPECT_GL_NO_ERROR();
114
115 glBindFramebuffer(GL_FRAMEBUFFER, 0);
116 glBindBuffer(GL_ARRAY_BUFFER, 0);
117
118 drawQuad(mProgram, "position", 0.5f);
119
120 EXPECT_PIXEL_EQ(0, 0, 0, 255, 0, 255);
121}
Jamie Madilla09403c2014-07-21 10:03:36 -0400122
123// Requires ES3
124// This tests a bug where in a masked clear when calling "ClearBuffer", we would
125// mistakenly clear every channel (including the masked-out ones)
Jamie Madill94203b32014-10-02 10:44:16 -0400126TYPED_TEST(ClearTestES3, MaskedClearBufferBug)
Jamie Madilla09403c2014-07-21 10:03:36 -0400127{
128 unsigned char pixelData[] = { 255, 255, 255, 255 };
129
130 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
131
132 GLuint textures[2];
133 glGenTextures(2, &textures[0]);
134
135 glBindTexture(GL_TEXTURE_2D, textures[0]);
136 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixelData);
137 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0], 0);
138
139 glBindTexture(GL_TEXTURE_2D, textures[1]);
140 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixelData);
141 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, textures[1], 0);
142
143 ASSERT_GL_NO_ERROR();
144 EXPECT_PIXEL_EQ(0, 0, 255, 255, 255, 255);
145
146 float clearValue[] = { 0, 0.5f, 0.5f, 1.0f };
147 GLenum drawBuffers[] = { GL_NONE, GL_COLOR_ATTACHMENT1 };
148 glDrawBuffers(2, drawBuffers);
149 glColorMask(GL_TRUE, GL_TRUE, GL_FALSE, GL_TRUE);
150 glClearBufferfv(GL_COLOR, 1, clearValue);
151
152 ASSERT_GL_NO_ERROR();
153 EXPECT_PIXEL_EQ(0, 0, 255, 255, 255, 255);
154
155 // TODO: glReadBuffer support
156 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, 0, 0);
157 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[1], 0);
Jamie Madill9abdc2d2014-11-05 16:13:22 -0500158
159 //TODO(jmadill): Robust handling of pixel test error ranges
160 EXPECT_PIXEL_NEAR(0, 0, 0, 127, 255, 255, 1);
Jamie Madillc4833262014-09-18 16:18:26 -0400161
162 glDeleteTextures(2, textures);
163}
164
Jamie Madill94203b32014-10-02 10:44:16 -0400165TYPED_TEST(ClearTestES3, BadFBOSerialBug)
Jamie Madillc4833262014-09-18 16:18:26 -0400166{
167 // First make a simple framebuffer, and clear it to green
168 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
169
170 GLuint textures[2];
171 glGenTextures(2, &textures[0]);
172
173 glBindTexture(GL_TEXTURE_2D, textures[0]);
174 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, getWindowWidth(), getWindowHeight());
175 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0], 0);
176
177 GLenum drawBuffers[] = { GL_COLOR_ATTACHMENT0 };
178 glDrawBuffers(1, drawBuffers);
179
180 float clearValues1[] = { 0.0f, 1.0f, 0.0f, 1.0f };
181 glClearBufferfv(GL_COLOR, 0, clearValues1);
182
183 ASSERT_GL_NO_ERROR();
184 EXPECT_PIXEL_EQ(0, 0, 0, 255, 0, 255);
185
186 // Next make a second framebuffer, and draw it to red
187 // (Triggers bad applied render target serial)
188 GLuint fbo2;
189 glGenFramebuffers(1, &fbo2);
190 ASSERT_GL_NO_ERROR();
191
192 glBindFramebuffer(GL_FRAMEBUFFER, fbo2);
193
194 glBindTexture(GL_TEXTURE_2D, textures[1]);
195 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, getWindowWidth(), getWindowHeight());
196 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[1], 0);
197
198 glDrawBuffers(1, drawBuffers);
199
200 drawQuad(mProgram, "position", 0.5f);
201
202 ASSERT_GL_NO_ERROR();
203 EXPECT_PIXEL_EQ(0, 0, 255, 0, 0, 255);
204
205 // Check that the first framebuffer is still green.
206 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
207 EXPECT_PIXEL_EQ(0, 0, 0, 255, 0, 255);
208
209 glDeleteTextures(2, textures);
210 glDeleteFramebuffers(1, &fbo2);
Jamie Madilla09403c2014-07-21 10:03:36 -0400211}