Merge "VCPKG - CMakeLists.txt updated to build for vcpkg." into devel/master
[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 UtcDaliFrameBufferNewWithColor01(void)
144 {
145   TestApplication application;
146   uint32_t width = 64;
147   uint32_t height = 64;
148   FrameBuffer frameBuffer = FrameBuffer::New( width, height );
149   application.SendNotification();
150   application.Render();
151   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
152   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
153   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
154   // check that texture is not empty handle
155   DALI_TEST_CHECK( frameBuffer.GetColorTexture() );
156   END_TEST;
157 }
158
159 int UtcDaliFrameBufferNewWithColor02(void)
160 {
161   TestApplication application;
162   uint32_t width = 64;
163   uint32_t height = 64;
164   FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::COLOR );
165   application.SendNotification();
166   application.Render();
167   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
168   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
169   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
170   // check that texture is not empty handle
171   DALI_TEST_CHECK( frameBuffer.GetColorTexture() );
172   END_TEST;
173 }
174
175 int UtcDaliFrameBufferNewWithColor03(void)
176 {
177   TestApplication application;
178   uint32_t width = 64;
179   uint32_t height = 64;
180   FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::COLOR_DEPTH );
181   application.SendNotification();
182   application.Render();
183   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
184   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
185   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
186   // check that texture is not empty handle
187   DALI_TEST_CHECK( frameBuffer.GetColorTexture() );
188   END_TEST;
189 }
190
191 int UtcDaliFrameBufferNewWithColor04(void)
192 {
193   TestApplication application;
194   uint32_t width = 64;
195   uint32_t height = 64;
196   FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::COLOR_STENCIL );
197   application.SendNotification();
198   application.Render();
199   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
200   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
201   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
202   // check that texture is not empty handle
203   DALI_TEST_CHECK( frameBuffer.GetColorTexture() );
204   END_TEST;
205 }
206
207 int UtcDaliFrameBufferNewWithColor05(void)
208 {
209   TestApplication application;
210   uint32_t width = 64;
211   uint32_t height = 64;
212   FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::COLOR_DEPTH_STENCIL );
213   application.SendNotification();
214   application.Render();
215   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
216   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
217   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
218   // check that texture is not empty handle
219   DALI_TEST_CHECK( frameBuffer.GetColorTexture() );
220   END_TEST;
221 }
222
223 int UtcDaliFrameBufferCopyConstructor(void)
224 {
225   TestApplication application;
226
227   unsigned int width(64);
228   unsigned int height(64);
229   FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::NONE );
230
231   FrameBuffer frameBufferCopy( frameBuffer );
232
233   DALI_TEST_CHECK( frameBufferCopy );
234
235   END_TEST;
236 }
237
238 int UtcDaliFrameBufferAssignmentOperator(void)
239 {
240   TestApplication application;
241
242   unsigned int width(64);
243   unsigned int height(64);
244   FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::NONE );
245
246   FrameBuffer frameBuffer2;
247   DALI_TEST_CHECK( !frameBuffer2 );
248
249   frameBuffer2 = frameBuffer;
250   DALI_TEST_CHECK( frameBuffer2 );
251
252   END_TEST;
253 }
254
255 int UtcDaliFrameBufferDownCast01(void)
256 {
257   TestApplication application;
258   unsigned int width(64);
259   unsigned int height(64);
260   FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::NONE );
261
262   BaseHandle handle(frameBuffer);
263   FrameBuffer frameBuffer2 = FrameBuffer::DownCast(handle);
264   DALI_TEST_CHECK( frameBuffer2 );
265
266   END_TEST;
267 }
268
269 int UtcDaliFrameBufferDownCast02(void)
270 {
271   TestApplication application;
272
273   Handle handle = Handle::New(); // Create a custom object
274   FrameBuffer frameBuffer = FrameBuffer::DownCast(handle);
275   DALI_TEST_CHECK( !frameBuffer );
276   END_TEST;
277 }
278
279 int UtcDaliFrameBufferAttachColorTexture01(void)
280 {
281   TestApplication application;
282
283   unsigned int width(64);
284   unsigned int height(64);
285   FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::DEPTH_STENCIL );
286   Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
287   frameBuffer.AttachColorTexture( texture );
288
289   application.SendNotification();
290   application.Render();
291
292   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
293   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
294   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
295
296   END_TEST;
297 }
298
299 int UtcDaliFrameBufferAttachColorTexture02(void)
300 {
301   TestApplication application;
302
303   unsigned int width(64);
304   unsigned int height(64);
305   FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::NONE );
306   Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
307   texture.GenerateMipmaps();
308
309   //Attach mipmap 1
310   frameBuffer.AttachColorTexture( texture, 0u, 1u );
311
312   application.SendNotification();
313   application.Render();
314
315   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
316   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
317   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
318
319   END_TEST;
320 }
321
322 int UtcDaliFrameBufferAttachColorTexture03(void)
323 {
324   TestApplication application;
325
326   unsigned int width(64);
327   unsigned int height(64);
328   FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::NONE );
329   Texture texture = Texture::New( TextureType::TEXTURE_CUBE, Pixel::RGBA8888, width, height );
330   texture.GenerateMipmaps();
331
332   //Attach NEGATIVE_Y face of the cubemap
333   frameBuffer.AttachColorTexture( texture, 0u, CubeMapLayer::NEGATIVE_Y );
334
335   application.SendNotification();
336   application.Render();
337
338   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
339   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
340   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
341
342   END_TEST;
343 }
344
345 int UtcDaliFrameBufferAttachColorTexture04(void)
346 {
347   TestApplication application;
348
349   unsigned int width(64);
350   unsigned int height(64);
351   FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::DEPTH | FrameBuffer::Attachment::STENCIL );
352   Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
353   frameBuffer.AttachColorTexture( texture );
354
355   application.SendNotification();
356   application.Render();
357
358   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
359   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
360   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
361
362   END_TEST;
363 }
364
365 int UtcDaliFrameBufferGetColorTexture01(void)
366 {
367   TestApplication application;
368
369   unsigned int width(64);
370   unsigned int height(64);
371   FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::NONE );
372   Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
373   frameBuffer.AttachColorTexture( texture );
374
375   DALI_TEST_EQUALS(frameBuffer.GetColorTexture(), texture, TEST_LOCATION);
376
377   END_TEST;
378 }
379
380 int UtcDaliFrameBufferGetColorTexture02(void)
381 {
382   TestApplication application;
383
384   unsigned int width(64);
385   unsigned int height(64);
386   FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::NONE );
387   Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
388   frameBuffer.AttachColorTexture( texture, 0u, 1u );
389
390   DALI_TEST_EQUALS(frameBuffer.GetColorTexture(), texture, TEST_LOCATION);
391
392   END_TEST;
393 }
394
395 int UtcDaliFramebufferContextLoss(void)
396 {
397   tet_infoline("UtcDaliFramebufferContextLoss\n");
398   TestApplication application; // Default config: DALI_DISCARDS_ALL_DATA
399
400   //Create the texture
401   unsigned int width(64);
402   unsigned int height(64);
403   Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
404   DALI_TEST_CHECK( texture );
405   FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::NONE );
406   DALI_TEST_CHECK( frameBuffer );
407   frameBuffer.AttachColorTexture( texture, 0u, 1u );
408
409   Geometry geometry = CreateQuadGeometry();
410   Shader shader = CreateShader();
411   Renderer renderer = Renderer::New(geometry, shader);
412
413   application.SendNotification();
414   application.Render(16);
415
416   // Lose & regain context (in render 'thread')
417   application.ResetContext();
418   DALI_TEST_CHECK( frameBuffer );
419
420   END_TEST;
421 }