blob: af9b9707fa14abe450b3e07ca0661b35747683c7 [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 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);
Jamie Madill9abdc2d2014-11-05 16:13:22 -0500151
152 //TODO(jmadill): Robust handling of pixel test error ranges
153 EXPECT_PIXEL_NEAR(0, 0, 0, 127, 255, 255, 1);
Jamie Madillc4833262014-09-18 16:18:26 -0400154
155 glDeleteTextures(2, textures);
156}
157
Jamie Madill94203b32014-10-02 10:44:16 -0400158TYPED_TEST(ClearTestES3, BadFBOSerialBug)
Jamie Madillc4833262014-09-18 16:18:26 -0400159{
160 // First make a simple framebuffer, and clear it to green
161 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
162
163 GLuint textures[2];
164 glGenTextures(2, &textures[0]);
165
166 glBindTexture(GL_TEXTURE_2D, textures[0]);
167 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, getWindowWidth(), getWindowHeight());
168 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0], 0);
169
170 GLenum drawBuffers[] = { GL_COLOR_ATTACHMENT0 };
171 glDrawBuffers(1, drawBuffers);
172
173 float clearValues1[] = { 0.0f, 1.0f, 0.0f, 1.0f };
174 glClearBufferfv(GL_COLOR, 0, clearValues1);
175
176 ASSERT_GL_NO_ERROR();
177 EXPECT_PIXEL_EQ(0, 0, 0, 255, 0, 255);
178
179 // Next make a second framebuffer, and draw it to red
180 // (Triggers bad applied render target serial)
181 GLuint fbo2;
182 glGenFramebuffers(1, &fbo2);
183 ASSERT_GL_NO_ERROR();
184
185 glBindFramebuffer(GL_FRAMEBUFFER, fbo2);
186
187 glBindTexture(GL_TEXTURE_2D, textures[1]);
188 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, getWindowWidth(), getWindowHeight());
189 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[1], 0);
190
191 glDrawBuffers(1, drawBuffers);
192
193 drawQuad(mProgram, "position", 0.5f);
194
195 ASSERT_GL_NO_ERROR();
196 EXPECT_PIXEL_EQ(0, 0, 255, 0, 0, 255);
197
198 // Check that the first framebuffer is still green.
199 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
200 EXPECT_PIXEL_EQ(0, 0, 0, 255, 0, 255);
201
202 glDeleteTextures(2, textures);
203 glDeleteFramebuffers(1, &fbo2);
Jamie Madilla09403c2014-07-21 10:03:36 -0400204}