f0e295be7cb6aef1beeab94a3089ce355fff7acf
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-FrameBuffer.cpp
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 #include <dali/public-api/dali-core.h>
19 #include <dali-test-suite-utils.h>
20
21 using namespace Dali;
22
23 #include <mesh-builder.h>
24
25 void framebuffer_set_startup(void)
26 {
27   test_return_value = TET_UNDEF;
28 }
29
30 void framebuffer_set_cleanup(void)
31 {
32   test_return_value = TET_PASS;
33 }
34
35 int UtcDaliFrameBufferNew01(void)
36 {
37   TestApplication application;
38
39   unsigned int width(64);
40   unsigned int height(64);
41   FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::NONE );
42
43   DALI_TEST_CHECK( frameBuffer );
44
45   application.SendNotification();
46   application.Render();
47
48   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
49   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
50   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
51
52   END_TEST;
53 }
54
55 int UtcDaliFrameBufferNew02(void)
56 {
57   TestApplication application;
58
59   unsigned int width(64);
60   unsigned int height(64);
61   FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::DEPTH );
62
63   DALI_TEST_CHECK( frameBuffer );
64
65   application.SendNotification();
66   application.Render();
67
68   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
69   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
70   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
71
72   END_TEST;
73 }
74
75 int UtcDaliFrameBufferNew03(void)
76 {
77   TestApplication application;
78
79   unsigned int width(64);
80   unsigned int height(64);
81   FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::STENCIL );
82
83   DALI_TEST_CHECK( frameBuffer );
84
85   application.SendNotification();
86   application.Render();
87
88   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
89   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
90   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
91
92   END_TEST;
93 }
94
95 int UtcDaliFrameBufferNew04(void)
96 {
97   TestApplication application;
98
99   unsigned int width(64);
100   unsigned int height(64);
101   FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::DEPTH_STENCIL );
102
103   DALI_TEST_CHECK( frameBuffer );
104
105   application.SendNotification();
106   application.Render();
107
108   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
109   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
110   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
111
112   END_TEST;
113 }
114
115 int UtcDaliFrameBufferNew05(void)
116 {
117   TestApplication application;
118   FrameBuffer frameBuffer;
119   DALI_TEST_CHECK( !frameBuffer );
120   END_TEST;
121 }
122
123 int UtcDaliFrameBufferNew06(void)
124 {
125   TestApplication application;
126
127   unsigned int width(64);
128   unsigned int height(64);
129   FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::DEPTH | FrameBuffer::Attachment::STENCIL );
130
131   DALI_TEST_CHECK( frameBuffer );
132
133   application.SendNotification();
134   application.Render();
135
136   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
137   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
138   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
139
140   END_TEST;
141 }
142
143 int UtcDaliFrameBufferCopyConstructor(void)
144 {
145   TestApplication application;
146
147   unsigned int width(64);
148   unsigned int height(64);
149   FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::NONE );
150
151   FrameBuffer frameBufferCopy( frameBuffer );
152
153   DALI_TEST_CHECK( frameBufferCopy );
154
155   END_TEST;
156 }
157
158 int UtcDaliFrameBufferAssignmentOperator(void)
159 {
160   TestApplication application;
161
162   unsigned int width(64);
163   unsigned int height(64);
164   FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::NONE );
165
166   FrameBuffer frameBuffer2;
167   DALI_TEST_CHECK( !frameBuffer2 );
168
169   frameBuffer2 = frameBuffer;
170   DALI_TEST_CHECK( frameBuffer2 );
171
172   END_TEST;
173 }
174
175 int UtcDaliFrameBufferDownCast01(void)
176 {
177   TestApplication application;
178   unsigned int width(64);
179   unsigned int height(64);
180   FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::NONE );
181
182   BaseHandle handle(frameBuffer);
183   FrameBuffer frameBuffer2 = FrameBuffer::DownCast(handle);
184   DALI_TEST_CHECK( frameBuffer2 );
185
186   END_TEST;
187 }
188
189 int UtcDaliFrameBufferDownCast02(void)
190 {
191   TestApplication application;
192
193   Handle handle = Handle::New(); // Create a custom object
194   FrameBuffer frameBuffer = FrameBuffer::DownCast(handle);
195   DALI_TEST_CHECK( !frameBuffer );
196   END_TEST;
197 }
198
199 int UtcDaliFrameBufferAttachColorTexture01(void)
200 {
201   TestApplication application;
202
203   unsigned int width(64);
204   unsigned int height(64);
205   FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::DEPTH_STENCIL );
206   Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
207   frameBuffer.AttachColorTexture( texture );
208
209   application.SendNotification();
210   application.Render();
211
212   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
213   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
214   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
215
216   END_TEST;
217 }
218
219 int UtcDaliFrameBufferAttachColorTexture02(void)
220 {
221   TestApplication application;
222
223   unsigned int width(64);
224   unsigned int height(64);
225   FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::NONE );
226   Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
227   texture.GenerateMipmaps();
228
229   //Attach mipmap 1
230   frameBuffer.AttachColorTexture( texture, 0u, 1u );
231
232   application.SendNotification();
233   application.Render();
234
235   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
236   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
237   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
238
239   END_TEST;
240 }
241
242 int UtcDaliFrameBufferAttachColorTexture03(void)
243 {
244   TestApplication application;
245
246   unsigned int width(64);
247   unsigned int height(64);
248   FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::NONE );
249   Texture texture = Texture::New( TextureType::TEXTURE_CUBE, Pixel::RGBA8888, width, height );
250   texture.GenerateMipmaps();
251
252   //Attach NEGATIVE_Y face of the cubemap
253   frameBuffer.AttachColorTexture( texture, 0u, CubeMapLayer::NEGATIVE_Y );
254
255   application.SendNotification();
256   application.Render();
257
258   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
259   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
260   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
261
262   END_TEST;
263 }
264
265 int UtcDaliFrameBufferAttachColorTexture04(void)
266 {
267   TestApplication application;
268
269   unsigned int width(64);
270   unsigned int height(64);
271   FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::DEPTH | FrameBuffer::Attachment::STENCIL );
272   Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
273   frameBuffer.AttachColorTexture( texture );
274
275   application.SendNotification();
276   application.Render();
277
278   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
279   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
280   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
281
282   END_TEST;
283 }
284
285 int UtcDaliFrameBufferGetColorTexture01(void)
286 {
287   TestApplication application;
288
289   unsigned int width(64);
290   unsigned int height(64);
291   FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::NONE );
292   Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
293   frameBuffer.AttachColorTexture( texture );
294
295   DALI_TEST_EQUALS(frameBuffer.GetColorTexture(), texture, TEST_LOCATION);
296
297   END_TEST;
298 }
299
300 int UtcDaliFrameBufferGetColorTexture02(void)
301 {
302   TestApplication application;
303
304   unsigned int width(64);
305   unsigned int height(64);
306   FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::NONE );
307   Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
308   frameBuffer.AttachColorTexture( texture, 0u, 1u );
309
310   DALI_TEST_EQUALS(frameBuffer.GetColorTexture(), texture, TEST_LOCATION);
311
312   END_TEST;
313 }
314