Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / angle / tests / angle_tests / ClearTest.cpp
1 #include "ANGLETest.h"
2
3 // Use this to select which configurations (e.g. which renderer, which GLES major version) these tests should be run against.
4 typedef ::testing::Types<TFT<Gles::Three, Rend::D3D11>, TFT<Gles::Two, Rend::D3D11>, TFT<Gles::Two, Rend::D3D9>> TestFixtureTypes;
5 TYPED_TEST_CASE(ClearTest, TestFixtureTypes);
6
7 typedef ::testing::Types<TFT<Gles::Three, Rend::D3D11>> TestFixtureTypesES3;
8 TYPED_TEST_CASE(ClearTestES3, TestFixtureTypesES3);
9
10 template<typename T>
11 class ClearTestBase : public ANGLETest
12 {
13   protected:
14     ClearTestBase() : ANGLETest(T::GetGlesMajorVersion(), T::GetRequestedRenderer())
15     {
16         setWindowWidth(128);
17         setWindowHeight(128);
18         setConfigRedBits(8);
19         setConfigGreenBits(8);
20         setConfigBlueBits(8);
21         setConfigAlphaBits(8);
22         setConfigDepthBits(24);
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
50         mProgram = CompileProgram(vertexShaderSource, fragmentShaderSource);
51         if (mProgram == 0)
52         {
53             FAIL() << "shader compilation failed.";
54         }
55
56         glGenFramebuffers(1, &mFBO);
57
58         ASSERT_GL_NO_ERROR();
59     }
60
61     virtual void TearDown()
62     {
63         glDeleteProgram(mProgram);
64         glDeleteFramebuffers(1, &mFBO);
65
66         ANGLETest::TearDown();
67     }
68
69     GLuint mProgram;
70     GLuint mFBO;
71 };
72
73 template <typename T>
74 class ClearTest : public ClearTestBase<T>
75 {};
76
77 template <typename T>
78 class ClearTestES3 : public ClearTestBase<T>
79 {};
80
81 TYPED_TEST(ClearTest, ClearIssue)
82 {
83     glEnable(GL_DEPTH_TEST);
84     glDepthFunc(GL_LEQUAL);
85
86     glClearColor(0.0, 1.0, 0.0, 1.0);
87     glClearDepthf(0.0);
88     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
89
90     EXPECT_GL_NO_ERROR();
91
92     glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
93
94     GLuint rbo;
95     glGenRenderbuffers(1, &rbo);
96     glBindRenderbuffer(GL_RENDERBUFFER, rbo);
97     glRenderbufferStorage(GL_RENDERBUFFER, GL_RGB565, 16, 16);
98
99     EXPECT_GL_NO_ERROR();
100
101     glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rbo);
102
103     EXPECT_GL_NO_ERROR();
104
105     glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
106     glClearDepthf(1.0f);
107     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
108
109     EXPECT_GL_NO_ERROR();
110
111     glBindFramebuffer(GL_FRAMEBUFFER, 0);
112     glBindBuffer(GL_ARRAY_BUFFER, 0);
113
114     drawQuad(mProgram, "position", 0.5f);
115
116     EXPECT_PIXEL_EQ(0, 0, 0, 255, 0, 255);
117 }
118
119 // Requires ES3
120 // This tests a bug where in a masked clear when calling "ClearBuffer", we would
121 // mistakenly clear every channel (including the masked-out ones)
122 TYPED_TEST(ClearTestES3, MaskedClearBufferBug)
123 {
124     unsigned char pixelData[] = { 255, 255, 255, 255 };
125
126     glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
127
128     GLuint textures[2];
129     glGenTextures(2, &textures[0]);
130
131     glBindTexture(GL_TEXTURE_2D, textures[0]);
132     glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixelData);
133     glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0], 0);
134
135     glBindTexture(GL_TEXTURE_2D, textures[1]);
136     glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixelData);
137     glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, textures[1], 0);
138
139     ASSERT_GL_NO_ERROR();
140     EXPECT_PIXEL_EQ(0, 0, 255, 255, 255, 255);
141
142     float clearValue[] = { 0, 0.5f, 0.5f, 1.0f };
143     GLenum drawBuffers[] = { GL_NONE, GL_COLOR_ATTACHMENT1 };
144     glDrawBuffers(2, drawBuffers);
145     glColorMask(GL_TRUE, GL_TRUE, GL_FALSE, GL_TRUE);
146     glClearBufferfv(GL_COLOR, 1, clearValue);
147
148     ASSERT_GL_NO_ERROR();
149     EXPECT_PIXEL_EQ(0, 0, 255, 255, 255, 255);
150
151     // TODO: glReadBuffer support
152     glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, 0, 0);
153     glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[1], 0);
154     EXPECT_PIXEL_EQ(0, 0, 0, 127, 255, 255);
155
156     glDeleteTextures(2, textures);
157 }
158
159 TYPED_TEST(ClearTestES3, BadFBOSerialBug)
160 {
161     // First make a simple framebuffer, and clear it to green
162     glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
163
164     GLuint textures[2];
165     glGenTextures(2, &textures[0]);
166
167     glBindTexture(GL_TEXTURE_2D, textures[0]);
168     glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, getWindowWidth(), getWindowHeight());
169     glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0], 0);
170
171     GLenum drawBuffers[] = { GL_COLOR_ATTACHMENT0 };
172     glDrawBuffers(1, drawBuffers);
173
174     float clearValues1[] = { 0.0f, 1.0f, 0.0f, 1.0f };
175     glClearBufferfv(GL_COLOR, 0, clearValues1);
176
177     ASSERT_GL_NO_ERROR();
178     EXPECT_PIXEL_EQ(0, 0, 0, 255, 0, 255);
179
180     // Next make a second framebuffer, and draw it to red
181     // (Triggers bad applied render target serial)
182     GLuint fbo2;
183     glGenFramebuffers(1, &fbo2);
184     ASSERT_GL_NO_ERROR();
185
186     glBindFramebuffer(GL_FRAMEBUFFER, fbo2);
187
188     glBindTexture(GL_TEXTURE_2D, textures[1]);
189     glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, getWindowWidth(), getWindowHeight());
190     glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[1], 0);
191
192     glDrawBuffers(1, drawBuffers);
193
194     drawQuad(mProgram, "position", 0.5f);
195
196     ASSERT_GL_NO_ERROR();
197     EXPECT_PIXEL_EQ(0, 0, 255, 0, 0, 255);
198
199     // Check that the first framebuffer is still green.
200     glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
201     EXPECT_PIXEL_EQ(0, 0, 0, 255, 0, 255);
202
203     glDeleteTextures(2, textures);
204     glDeleteFramebuffers(1, &fbo2);
205 }