blob: e5cb7bafbe5ed275e4d460ea0218a83a1dd2f1aa [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 Lang0d3683c2014-10-23 11:08:16 -04004ANGLE_TYPED_TEST_CASE(ClearTest, ES2_D3D9, ES2_D3D11, ES3_D3D11);
5ANGLE_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 Langd1913172013-10-18 16:15:10 -040080 glEnable(GL_DEPTH_TEST);
81 glDepthFunc(GL_LEQUAL);
82
83 glClearColor(0.0, 1.0, 0.0, 1.0);
84 glClearDepthf(0.0);
85 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
86
87 EXPECT_GL_NO_ERROR();
88
Jamie Madilla09403c2014-07-21 10:03:36 -040089 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
Geoff Langd1913172013-10-18 16:15:10 -040090
91 GLuint rbo;
92 glGenRenderbuffers(1, &rbo);
93 glBindRenderbuffer(GL_RENDERBUFFER, rbo);
94 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGB565, 16, 16);
95
96 EXPECT_GL_NO_ERROR();
97
98 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rbo);
99
100 EXPECT_GL_NO_ERROR();
101
102 glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
103 glClearDepthf(1.0f);
104 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
105
106 EXPECT_GL_NO_ERROR();
107
108 glBindFramebuffer(GL_FRAMEBUFFER, 0);
109 glBindBuffer(GL_ARRAY_BUFFER, 0);
110
111 drawQuad(mProgram, "position", 0.5f);
112
113 EXPECT_PIXEL_EQ(0, 0, 0, 255, 0, 255);
114}
Jamie Madilla09403c2014-07-21 10:03:36 -0400115
116// Requires ES3
117// This tests a bug where in a masked clear when calling "ClearBuffer", we would
118// mistakenly clear every channel (including the masked-out ones)
Jamie Madill94203b32014-10-02 10:44:16 -0400119TYPED_TEST(ClearTestES3, MaskedClearBufferBug)
Jamie Madilla09403c2014-07-21 10:03:36 -0400120{
121 unsigned char pixelData[] = { 255, 255, 255, 255 };
122
123 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
124
125 GLuint textures[2];
126 glGenTextures(2, &textures[0]);
127
128 glBindTexture(GL_TEXTURE_2D, textures[0]);
129 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixelData);
130 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0], 0);
131
132 glBindTexture(GL_TEXTURE_2D, textures[1]);
133 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixelData);
134 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, textures[1], 0);
135
136 ASSERT_GL_NO_ERROR();
137 EXPECT_PIXEL_EQ(0, 0, 255, 255, 255, 255);
138
139 float clearValue[] = { 0, 0.5f, 0.5f, 1.0f };
140 GLenum drawBuffers[] = { GL_NONE, GL_COLOR_ATTACHMENT1 };
141 glDrawBuffers(2, drawBuffers);
142 glColorMask(GL_TRUE, GL_TRUE, GL_FALSE, GL_TRUE);
143 glClearBufferfv(GL_COLOR, 1, clearValue);
144
145 ASSERT_GL_NO_ERROR();
146 EXPECT_PIXEL_EQ(0, 0, 255, 255, 255, 255);
147
148 // TODO: glReadBuffer support
149 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, 0, 0);
150 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[1], 0);
151 EXPECT_PIXEL_EQ(0, 0, 0, 127, 255, 255);
Jamie Madillc4833262014-09-18 16:18:26 -0400152
153 glDeleteTextures(2, textures);
154}
155
Jamie Madill94203b32014-10-02 10:44:16 -0400156TYPED_TEST(ClearTestES3, BadFBOSerialBug)
Jamie Madillc4833262014-09-18 16:18:26 -0400157{
158 // First make a simple framebuffer, and clear it to green
159 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
160
161 GLuint textures[2];
162 glGenTextures(2, &textures[0]);
163
164 glBindTexture(GL_TEXTURE_2D, textures[0]);
165 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, getWindowWidth(), getWindowHeight());
166 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0], 0);
167
168 GLenum drawBuffers[] = { GL_COLOR_ATTACHMENT0 };
169 glDrawBuffers(1, drawBuffers);
170
171 float clearValues1[] = { 0.0f, 1.0f, 0.0f, 1.0f };
172 glClearBufferfv(GL_COLOR, 0, clearValues1);
173
174 ASSERT_GL_NO_ERROR();
175 EXPECT_PIXEL_EQ(0, 0, 0, 255, 0, 255);
176
177 // Next make a second framebuffer, and draw it to red
178 // (Triggers bad applied render target serial)
179 GLuint fbo2;
180 glGenFramebuffers(1, &fbo2);
181 ASSERT_GL_NO_ERROR();
182
183 glBindFramebuffer(GL_FRAMEBUFFER, fbo2);
184
185 glBindTexture(GL_TEXTURE_2D, textures[1]);
186 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, getWindowWidth(), getWindowHeight());
187 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[1], 0);
188
189 glDrawBuffers(1, drawBuffers);
190
191 drawQuad(mProgram, "position", 0.5f);
192
193 ASSERT_GL_NO_ERROR();
194 EXPECT_PIXEL_EQ(0, 0, 255, 0, 0, 255);
195
196 // Check that the first framebuffer is still green.
197 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
198 EXPECT_PIXEL_EQ(0, 0, 0, 255, 0, 255);
199
200 glDeleteTextures(2, textures);
201 glDeleteFramebuffers(1, &fbo2);
Jamie Madilla09403c2014-07-21 10:03:36 -0400202}