blob: 3c867887b5c3869d0498284c94e4edac61833dea [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.
4typedef ::testing::Types<TFT<Gles::Three, Rend::D3D11>, TFT<Gles::Two, Rend::D3D11>, TFT<Gles::Two, Rend::D3D9>> TestFixtureTypes;
5TYPED_TEST_CASE(ClearTest, TestFixtureTypes);
6
7template<typename T>
Geoff Langd1913172013-10-18 16:15:10 -04008class ClearTest : public ANGLETest
9{
10protected:
Austin Kinross18b931d2014-09-29 12:58:31 -070011 ClearTest() : ANGLETest(T::GetGlesMajorVersion(), T::GetRequestedRenderer())
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
Austin Kinross18b931d2014-09-29 12:58:31 -070070TYPED_TEST(ClearTest, ClearIssue)
Geoff Langd1913172013-10-18 16:15:10 -040071{
Geoff Langd1913172013-10-18 16:15:10 -040072 glEnable(GL_DEPTH_TEST);
73 glDepthFunc(GL_LEQUAL);
74
75 glClearColor(0.0, 1.0, 0.0, 1.0);
76 glClearDepthf(0.0);
77 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
78
79 EXPECT_GL_NO_ERROR();
80
Jamie Madilla09403c2014-07-21 10:03:36 -040081 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
Geoff Langd1913172013-10-18 16:15:10 -040082
83 GLuint rbo;
84 glGenRenderbuffers(1, &rbo);
85 glBindRenderbuffer(GL_RENDERBUFFER, rbo);
86 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGB565, 16, 16);
87
88 EXPECT_GL_NO_ERROR();
89
90 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rbo);
91
92 EXPECT_GL_NO_ERROR();
93
94 glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
95 glClearDepthf(1.0f);
96 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
97
98 EXPECT_GL_NO_ERROR();
99
100 glBindFramebuffer(GL_FRAMEBUFFER, 0);
101 glBindBuffer(GL_ARRAY_BUFFER, 0);
102
103 drawQuad(mProgram, "position", 0.5f);
104
105 EXPECT_PIXEL_EQ(0, 0, 0, 255, 0, 255);
106}
Jamie Madilla09403c2014-07-21 10:03:36 -0400107
108// Requires ES3
109// This tests a bug where in a masked clear when calling "ClearBuffer", we would
110// mistakenly clear every channel (including the masked-out ones)
Austin Kinross18b931d2014-09-29 12:58:31 -0700111TYPED_TEST(ClearTest, MaskedClearBufferBug)
Jamie Madilla09403c2014-07-21 10:03:36 -0400112{
113 unsigned char pixelData[] = { 255, 255, 255, 255 };
114
115 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
116
117 GLuint textures[2];
118 glGenTextures(2, &textures[0]);
119
120 glBindTexture(GL_TEXTURE_2D, textures[0]);
121 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixelData);
122 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0], 0);
123
124 glBindTexture(GL_TEXTURE_2D, textures[1]);
125 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixelData);
126 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, textures[1], 0);
127
128 ASSERT_GL_NO_ERROR();
129 EXPECT_PIXEL_EQ(0, 0, 255, 255, 255, 255);
130
131 float clearValue[] = { 0, 0.5f, 0.5f, 1.0f };
132 GLenum drawBuffers[] = { GL_NONE, GL_COLOR_ATTACHMENT1 };
133 glDrawBuffers(2, drawBuffers);
134 glColorMask(GL_TRUE, GL_TRUE, GL_FALSE, GL_TRUE);
135 glClearBufferfv(GL_COLOR, 1, clearValue);
136
137 ASSERT_GL_NO_ERROR();
138 EXPECT_PIXEL_EQ(0, 0, 255, 255, 255, 255);
139
140 // TODO: glReadBuffer support
141 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, 0, 0);
142 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[1], 0);
143 EXPECT_PIXEL_EQ(0, 0, 0, 127, 255, 255);
Jamie Madillc4833262014-09-18 16:18:26 -0400144
145 glDeleteTextures(2, textures);
146}
147
Austin Kinross18b931d2014-09-29 12:58:31 -0700148TYPED_TEST(ClearTest, BadFBOSerialBug)
Jamie Madillc4833262014-09-18 16:18:26 -0400149{
150 // First make a simple framebuffer, and clear it to green
151 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
152
153 GLuint textures[2];
154 glGenTextures(2, &textures[0]);
155
156 glBindTexture(GL_TEXTURE_2D, textures[0]);
157 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, getWindowWidth(), getWindowHeight());
158 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0], 0);
159
160 GLenum drawBuffers[] = { GL_COLOR_ATTACHMENT0 };
161 glDrawBuffers(1, drawBuffers);
162
163 float clearValues1[] = { 0.0f, 1.0f, 0.0f, 1.0f };
164 glClearBufferfv(GL_COLOR, 0, clearValues1);
165
166 ASSERT_GL_NO_ERROR();
167 EXPECT_PIXEL_EQ(0, 0, 0, 255, 0, 255);
168
169 // Next make a second framebuffer, and draw it to red
170 // (Triggers bad applied render target serial)
171 GLuint fbo2;
172 glGenFramebuffers(1, &fbo2);
173 ASSERT_GL_NO_ERROR();
174
175 glBindFramebuffer(GL_FRAMEBUFFER, fbo2);
176
177 glBindTexture(GL_TEXTURE_2D, textures[1]);
178 glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, getWindowWidth(), getWindowHeight());
179 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[1], 0);
180
181 glDrawBuffers(1, drawBuffers);
182
183 drawQuad(mProgram, "position", 0.5f);
184
185 ASSERT_GL_NO_ERROR();
186 EXPECT_PIXEL_EQ(0, 0, 255, 0, 0, 255);
187
188 // Check that the first framebuffer is still green.
189 glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
190 EXPECT_PIXEL_EQ(0, 0, 0, 255, 0, 255);
191
192 glDeleteTextures(2, textures);
193 glDeleteFramebuffers(1, &fbo2);
Jamie Madilla09403c2014-07-21 10:03:36 -0400194}