[Tizen] Fixed actor relayout dimension dependencies
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-FrameBuffer.cpp
1 /*
2  * Copyright (c) 2021 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-test-suite-utils.h>
19 #include <dali/devel-api/rendering/frame-buffer-devel.h>
20 #include <dali/public-api/dali-core.h>
21 using namespace Dali;
22
23 #include <mesh-builder.h>
24 #include <test-actor-utils.h>
25
26 void framebuffer_set_startup(void)
27 {
28   test_return_value = TET_UNDEF;
29 }
30
31 void framebuffer_set_cleanup(void)
32 {
33   test_return_value = TET_PASS;
34 }
35
36 RenderTask CreateRenderTask(TestApplication& application,
37                             FrameBuffer      framebuffer)
38 {
39   Actor rootActor = Actor::New();
40   application.GetScene().Add(rootActor);
41   Texture img         = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, 1, 1);
42   Actor   sourceActor = CreateRenderableActor(img);
43   application.GetScene().Add(sourceActor);
44
45   CameraActor offscreenCameraActor = CameraActor::New(Size(TestApplication::DEFAULT_SURFACE_WIDTH,
46                                                            TestApplication::DEFAULT_SURFACE_HEIGHT));
47   application.GetScene().Add(offscreenCameraActor);
48
49   // Change main render task to use a different root
50   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
51   taskList.GetTask(0u).SetSourceActor(rootActor);
52
53   RenderTask newTask = taskList.CreateTask();
54   newTask.SetCameraActor(offscreenCameraActor);
55   newTask.SetSourceActor(sourceActor);
56   newTask.SetInputEnabled(false);
57   newTask.SetClearColor(Vector4(0.f, 0.f, 0.f, 0.f));
58   newTask.SetClearEnabled(true);
59   newTask.SetExclusive(true);
60   newTask.SetFrameBuffer(framebuffer);
61
62   return newTask;
63 }
64
65 int UtcDaliFrameBufferNew01(void)
66 {
67   TestApplication application;
68
69   unsigned int width(64);
70   unsigned int height(64);
71   FrameBuffer  framebuffer = FrameBuffer::New(width, height, FrameBuffer::Attachment::NONE);
72
73   DALI_TEST_CHECK(framebuffer);
74
75   CreateRenderTask(application, framebuffer);
76
77   application.SendNotification();
78   application.Render();
79
80   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachmentCount(), 0u, TEST_LOCATION);
81   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
82   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
83
84   END_TEST;
85 }
86
87 int UtcDaliFrameBufferNew02(void)
88 {
89   TestApplication application;
90
91   unsigned int width(64);
92   unsigned int height(64);
93   FrameBuffer  frameBuffer = FrameBuffer::New(width, height, FrameBuffer::Attachment::DEPTH);
94   DALI_TEST_CHECK(frameBuffer);
95   Texture depthTexture = CreateTexture(TextureType::TEXTURE_2D, Pixel::DEPTH_FLOAT, width, height);
96   DevelFrameBuffer::AttachDepthTexture(frameBuffer, depthTexture);
97
98   CreateRenderTask(application, frameBuffer);
99
100   application.SendNotification();
101   application.Render();
102
103   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachmentCount(), 0u, TEST_LOCATION);
104   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
105   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
106
107   END_TEST;
108 }
109
110 int UtcDaliFrameBufferNew03(void)
111 {
112   TestApplication application;
113
114   unsigned int width(64);
115   unsigned int height(64);
116   FrameBuffer  frameBuffer = FrameBuffer::New(width, height, FrameBuffer::Attachment::STENCIL);
117   DALI_TEST_CHECK(frameBuffer);
118   Texture stencilTexture = CreateTexture(TextureType::TEXTURE_2D, Pixel::DEPTH_STENCIL, width, height);
119   DevelFrameBuffer::AttachDepthStencilTexture(frameBuffer, stencilTexture);
120   CreateRenderTask(application, frameBuffer);
121
122   application.SendNotification();
123   application.Render();
124
125   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachmentCount(), 0u, TEST_LOCATION);
126   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
127   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
128
129   END_TEST;
130 }
131
132 int UtcDaliFrameBufferNew04(void)
133 {
134   TestApplication application;
135
136   unsigned int width(64);
137   unsigned int height(64);
138   FrameBuffer  frameBuffer = FrameBuffer::New(width, height, FrameBuffer::Attachment::DEPTH_STENCIL);
139   DALI_TEST_CHECK(frameBuffer);
140
141   Texture stencilTexture = CreateTexture(TextureType::TEXTURE_2D, Pixel::DEPTH_STENCIL, width, height);
142   DevelFrameBuffer::AttachDepthStencilTexture(frameBuffer, stencilTexture);
143   CreateRenderTask(application, frameBuffer);
144
145   application.SendNotification();
146   application.Render();
147
148   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachmentCount(), 0u, TEST_LOCATION);
149   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
150   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
151
152   END_TEST;
153 }
154
155 int UtcDaliFrameBufferNew05(void)
156 {
157   TestApplication application;
158   FrameBuffer     frameBuffer;
159   DALI_TEST_CHECK(!frameBuffer);
160   END_TEST;
161 }
162
163 int UtcDaliFrameBufferNew06(void)
164 {
165   TestApplication application;
166
167   unsigned int width(64);
168   unsigned int height(64);
169   FrameBuffer  frameBuffer = FrameBuffer::New(width, height, static_cast<FrameBuffer::Attachment::Mask>(FrameBuffer::Attachment::DEPTH | FrameBuffer::Attachment::STENCIL));
170   DALI_TEST_CHECK(frameBuffer);
171
172   Texture stencilTexture = CreateTexture(TextureType::TEXTURE_2D, Pixel::DEPTH_STENCIL, width, height);
173   DevelFrameBuffer::AttachDepthStencilTexture(frameBuffer, stencilTexture);
174   CreateRenderTask(application, frameBuffer);
175
176   application.SendNotification();
177   application.Render();
178
179   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachmentCount(), 0u, TEST_LOCATION);
180   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
181   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
182
183   END_TEST;
184 }
185
186 int UtcDaliFrameBufferNewWithColor01(void)
187 {
188   TestApplication application;
189   uint32_t        width       = 64;
190   uint32_t        height      = 64;
191   FrameBuffer     frameBuffer = FrameBuffer::New(width, height);
192
193   CreateRenderTask(application, frameBuffer);
194   application.SendNotification();
195   application.Render();
196   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachmentCount(), 1u, TEST_LOCATION);
197   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
198   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
199   // check that texture is not empty handle
200   DALI_TEST_CHECK(frameBuffer.GetColorTexture());
201   END_TEST;
202 }
203
204 int UtcDaliFrameBufferNewWithColor02(void)
205 {
206   TestApplication application;
207   uint32_t        width       = 64;
208   uint32_t        height      = 64;
209   FrameBuffer     frameBuffer = FrameBuffer::New(width, height, FrameBuffer::Attachment::COLOR);
210   CreateRenderTask(application, frameBuffer);
211   application.SendNotification();
212   application.Render();
213   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachmentCount(), 1u, TEST_LOCATION);
214   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
215   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
216   // check that texture is not empty handle
217   DALI_TEST_CHECK(frameBuffer.GetColorTexture());
218   END_TEST;
219 }
220
221 int UtcDaliFrameBufferNewWithColor03(void)
222 {
223   TestApplication application;
224   uint32_t        width       = 64;
225   uint32_t        height      = 64;
226   FrameBuffer     frameBuffer = FrameBuffer::New(width, height, FrameBuffer::Attachment::COLOR_DEPTH);
227
228   Texture depthTexture = CreateTexture(TextureType::TEXTURE_2D, Pixel::DEPTH_UNSIGNED_INT, width, height);
229   DevelFrameBuffer::AttachDepthTexture(frameBuffer, depthTexture);
230   CreateRenderTask(application, frameBuffer);
231
232   application.SendNotification();
233   application.Render();
234   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachmentCount(), 1u, TEST_LOCATION);
235   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
236   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
237   // check that texture is not empty handle
238   DALI_TEST_CHECK(frameBuffer.GetColorTexture());
239   END_TEST;
240 }
241
242 int UtcDaliFrameBufferNewWithColor04(void)
243 {
244   TestApplication application;
245   uint32_t        width        = 64;
246   uint32_t        height       = 64;
247   FrameBuffer     frameBuffer  = FrameBuffer::New(width, height, FrameBuffer::Attachment::COLOR_STENCIL);
248   Texture         depthTexture = CreateTexture(TextureType::TEXTURE_2D, Pixel::DEPTH_STENCIL, width, height);
249   DevelFrameBuffer::AttachDepthStencilTexture(frameBuffer, depthTexture);
250   CreateRenderTask(application, frameBuffer);
251   application.SendNotification();
252   application.Render();
253   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachmentCount(), 1u, TEST_LOCATION);
254   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
255   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
256   // check that texture is not empty handle
257   DALI_TEST_CHECK(frameBuffer.GetColorTexture());
258   END_TEST;
259 }
260
261 int UtcDaliFrameBufferNewWithColor05(void)
262 {
263   TestApplication application;
264   uint32_t        width  = 64;
265   uint32_t        height = 64;
266
267   FrameBuffer frameBuffer  = FrameBuffer::New(width, height, FrameBuffer::Attachment::COLOR_DEPTH_STENCIL);
268   Texture     depthTexture = CreateTexture(TextureType::TEXTURE_2D, Pixel::DEPTH_STENCIL, width, height);
269   DevelFrameBuffer::AttachDepthStencilTexture(frameBuffer, depthTexture);
270   CreateRenderTask(application, frameBuffer);
271
272   application.SendNotification();
273   application.Render();
274   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachmentCount(), 1u, TEST_LOCATION);
275   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
276   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
277   // check that texture is not empty handle
278   DALI_TEST_CHECK(frameBuffer.GetColorTexture());
279   END_TEST;
280 }
281
282 int UtcDaliFrameBufferCopyConstructor(void)
283 {
284   TestApplication application;
285
286   unsigned int width(64);
287   unsigned int height(64);
288   FrameBuffer  frameBuffer = FrameBuffer::New(width, height, FrameBuffer::Attachment::NONE);
289
290   FrameBuffer frameBufferCopy(frameBuffer);
291
292   DALI_TEST_CHECK(frameBufferCopy);
293
294   END_TEST;
295 }
296
297 int UtcDaliFrameBufferAssignmentOperator(void)
298 {
299   TestApplication application;
300
301   unsigned int width(64);
302   unsigned int height(64);
303   FrameBuffer  frameBuffer = FrameBuffer::New(width, height, FrameBuffer::Attachment::NONE);
304
305   FrameBuffer frameBuffer2;
306   DALI_TEST_CHECK(!frameBuffer2);
307
308   frameBuffer2 = frameBuffer;
309   DALI_TEST_CHECK(frameBuffer2);
310
311   END_TEST;
312 }
313
314 int UtcDaliFrameBufferMoveConstructor(void)
315 {
316   TestApplication application;
317
318   uint32_t    width       = 64;
319   uint32_t    height      = 64;
320   FrameBuffer frameBuffer = FrameBuffer::New(width, height, FrameBuffer::Attachment::DEPTH_STENCIL);
321   DALI_TEST_CHECK(frameBuffer);
322   DALI_TEST_EQUALS(1, frameBuffer.GetBaseObject().ReferenceCount(), TEST_LOCATION);
323
324   Texture texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
325   frameBuffer.AttachColorTexture(texture);
326   DALI_TEST_EQUALS(frameBuffer.GetColorTexture(), texture, TEST_LOCATION);
327
328   FrameBuffer move = std::move(frameBuffer);
329   DALI_TEST_CHECK(move);
330   DALI_TEST_EQUALS(1, move.GetBaseObject().ReferenceCount(), TEST_LOCATION);
331   DALI_TEST_EQUALS(move.GetColorTexture(), texture, TEST_LOCATION);
332   DALI_TEST_CHECK(!frameBuffer);
333
334   END_TEST;
335 }
336
337 int UtcDaliFrameBufferMoveAssignment(void)
338 {
339   TestApplication application;
340
341   uint32_t    width       = 64;
342   uint32_t    height      = 64;
343   FrameBuffer frameBuffer = FrameBuffer::New(width, height, FrameBuffer::Attachment::DEPTH_STENCIL);
344   DALI_TEST_CHECK(frameBuffer);
345   DALI_TEST_EQUALS(1, frameBuffer.GetBaseObject().ReferenceCount(), TEST_LOCATION);
346
347   Texture texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
348   frameBuffer.AttachColorTexture(texture);
349   DALI_TEST_EQUALS(frameBuffer.GetColorTexture(), texture, TEST_LOCATION);
350
351   FrameBuffer move;
352   move = std::move(frameBuffer);
353   DALI_TEST_CHECK(move);
354   DALI_TEST_EQUALS(1, move.GetBaseObject().ReferenceCount(), TEST_LOCATION);
355   DALI_TEST_EQUALS(move.GetColorTexture(), texture, TEST_LOCATION);
356   DALI_TEST_CHECK(!frameBuffer);
357
358   END_TEST;
359 }
360
361 int UtcDaliFrameBufferDownCast01(void)
362 {
363   TestApplication application;
364   unsigned int    width(64);
365   unsigned int    height(64);
366   FrameBuffer     frameBuffer = FrameBuffer::New(width, height, FrameBuffer::Attachment::NONE);
367
368   BaseHandle  handle(frameBuffer);
369   FrameBuffer frameBuffer2 = FrameBuffer::DownCast(handle);
370   DALI_TEST_CHECK(frameBuffer2);
371
372   END_TEST;
373 }
374
375 int UtcDaliFrameBufferDownCast02(void)
376 {
377   TestApplication application;
378
379   Handle      handle      = Handle::New(); // Create a custom object
380   FrameBuffer frameBuffer = FrameBuffer::DownCast(handle);
381   DALI_TEST_CHECK(!frameBuffer);
382   END_TEST;
383 }
384
385 int UtcDaliFrameBufferAttachColorTexture01(void)
386 {
387   TestApplication application;
388
389   unsigned int width(64);
390   unsigned int height(64);
391   FrameBuffer  frameBuffer = FrameBuffer::New(width, height, FrameBuffer::Attachment::DEPTH_STENCIL);
392   Texture      texture     = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
393   CreateRenderTask(application, frameBuffer);
394   frameBuffer.AttachColorTexture(texture);
395
396   Texture depthTexture = CreateTexture(TextureType::TEXTURE_2D, Pixel::DEPTH_STENCIL, width, height);
397   DevelFrameBuffer::AttachDepthStencilTexture(frameBuffer, depthTexture);
398   CreateRenderTask(application, frameBuffer);
399
400   application.SendNotification();
401   application.Render();
402
403   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachmentCount(), 1u, TEST_LOCATION);
404   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
405   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
406
407   END_TEST;
408 }
409
410 int UtcDaliFrameBufferAttachColorTexture02(void)
411 {
412   TestApplication application;
413
414   unsigned int width(64);
415   unsigned int height(64);
416   FrameBuffer  frameBuffer = FrameBuffer::New(width, height, FrameBuffer::Attachment::NONE);
417   Texture      texture     = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
418   texture.GenerateMipmaps();
419
420   //Attach mipmap 1
421   frameBuffer.AttachColorTexture(texture, 0u, 1u);
422   CreateRenderTask(application, frameBuffer);
423
424   application.SendNotification();
425   application.Render();
426
427   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachmentCount(), 1u, TEST_LOCATION);
428   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
429   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
430
431   END_TEST;
432 }
433
434 int UtcDaliFrameBufferAttachColorTexture03(void)
435 {
436   TestApplication application;
437
438   unsigned int width(64);
439   unsigned int height(64);
440   FrameBuffer  frameBuffer = FrameBuffer::New(width, height, FrameBuffer::Attachment::NONE);
441   Texture      texture     = Texture::New(TextureType::TEXTURE_CUBE, Pixel::RGBA8888, width, height);
442   texture.GenerateMipmaps();
443
444   //Attach NEGATIVE_Y face of the cubemap
445   frameBuffer.AttachColorTexture(texture, 0u, CubeMapLayer::NEGATIVE_Y);
446   CreateRenderTask(application, frameBuffer);
447
448   application.SendNotification();
449   application.Render();
450
451   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachmentCount(), 1u, TEST_LOCATION);
452   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
453   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
454
455   END_TEST;
456 }
457
458 int UtcDaliFrameBufferAttachColorTexture04(void)
459 {
460   TestApplication application;
461
462   unsigned int width(64);
463   unsigned int height(64);
464   FrameBuffer  frameBuffer = FrameBuffer::New(width, height, static_cast<FrameBuffer::Attachment::Mask>(FrameBuffer::Attachment::DEPTH | FrameBuffer::Attachment::STENCIL));
465   Texture      texture     = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
466   frameBuffer.AttachColorTexture(texture);
467
468   Texture depthTexture = CreateTexture(TextureType::TEXTURE_2D, Pixel::DEPTH_STENCIL, width, height);
469   DevelFrameBuffer::AttachDepthStencilTexture(frameBuffer, depthTexture);
470   CreateRenderTask(application, frameBuffer);
471
472   application.SendNotification();
473   application.Render();
474
475   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachmentCount(), 1u, TEST_LOCATION);
476   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
477   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
478
479   END_TEST;
480 }
481
482 int UtcDaliFrameBufferAttachColorTexture05(void)
483 {
484   TestApplication application;
485
486   unsigned int width(64);
487   unsigned int height(64);
488   FrameBuffer  frameBuffer = FrameBuffer::New(width, height, FrameBuffer::Attachment::NONE);
489   Texture      texture     = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
490
491   // N.B. it doesn't make sense per se, however the OGL standard doesn't seem to forbid attaching the same texture to different slots.
492   for(int i = 0; i < Dali::DevelFrameBuffer::MAX_COLOR_ATTACHMENTS + 1; ++i)
493   {
494     frameBuffer.AttachColorTexture(texture);
495   }
496   CreateRenderTask(application, frameBuffer);
497   application.SendNotification();
498   application.Render();
499
500   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachmentCount(), Dali::DevelFrameBuffer::MAX_COLOR_ATTACHMENTS, TEST_LOCATION);
501   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
502   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
503
504   END_TEST;
505 }
506
507 int UtcDaliFrameBufferAttachDepthTexture01(void)
508 {
509   TestApplication application;
510
511   unsigned int width(64);
512   unsigned int height(64);
513   FrameBuffer  frameBuffer = FrameBuffer::New(width, height, FrameBuffer::Attachment::DEPTH);
514   Texture      texture     = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
515   frameBuffer.AttachColorTexture(texture);
516
517   Texture textureDepth = Texture::New(TextureType::TEXTURE_2D, Pixel::DEPTH_UNSIGNED_INT, width, height);
518   DevelFrameBuffer::AttachDepthTexture(frameBuffer, textureDepth);
519   CreateRenderTask(application, frameBuffer);
520   application.SendNotification();
521   application.Render();
522
523   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachmentCount(), 1u, TEST_LOCATION);
524   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
525   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
526
527   END_TEST;
528 }
529
530 int UtcDaliFrameBufferAttachDepthStencilTexture01(void)
531 {
532   TestApplication application;
533
534   unsigned int width(64);
535   unsigned int height(64);
536   FrameBuffer  frameBuffer = FrameBuffer::New(width, height, FrameBuffer::Attachment::DEPTH_STENCIL);
537   Texture      texture     = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
538   frameBuffer.AttachColorTexture(texture);
539
540   Texture textureStencil = Texture::New(TextureType::TEXTURE_2D, Pixel::DEPTH_STENCIL, width, height);
541   DevelFrameBuffer::AttachDepthStencilTexture(frameBuffer, textureStencil);
542
543   CreateRenderTask(application, frameBuffer);
544   application.SendNotification();
545   application.Render();
546
547   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachmentCount(), 1u, TEST_LOCATION);
548   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
549   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
550
551   END_TEST;
552 }
553
554 int UtcDaliFrameBufferGetColorTexture01(void)
555 {
556   TestApplication application;
557
558   unsigned int width(64);
559   unsigned int height(64);
560   FrameBuffer  frameBuffer = FrameBuffer::New(width, height, FrameBuffer::Attachment::NONE);
561   Texture      texture     = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
562   frameBuffer.AttachColorTexture(texture);
563
564   DALI_TEST_EQUALS(frameBuffer.GetColorTexture(), texture, TEST_LOCATION);
565
566   END_TEST;
567 }
568
569 int UtcDaliFrameBufferGetColorTexture02(void)
570 {
571   TestApplication application;
572
573   unsigned int width(64);
574   unsigned int height(64);
575   FrameBuffer  frameBuffer = FrameBuffer::New(width, height, FrameBuffer::Attachment::NONE);
576   Texture      texture     = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
577   frameBuffer.AttachColorTexture(texture, 0u, 1u);
578
579   DALI_TEST_EQUALS(frameBuffer.GetColorTexture(), texture, TEST_LOCATION);
580
581   END_TEST;
582 }
583
584 int UtcDaliFrameBufferGetColorTexture03(void)
585 { // FrameBuffer::GetColorTexture() and GetColorTexture(0) are equivalent
586   TestApplication application;
587
588   unsigned int width(64);
589   unsigned int height(64);
590   FrameBuffer  frameBuffer = FrameBuffer::New(width, height, FrameBuffer::Attachment::NONE);
591   Texture      texture     = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
592   frameBuffer.AttachColorTexture(texture, 0u, 1u);
593
594   DALI_TEST_EQUALS(frameBuffer.GetColorTexture(), texture, TEST_LOCATION);
595   DALI_TEST_EQUALS(DevelFrameBuffer::GetColorTexture(frameBuffer, 0), texture, TEST_LOCATION);
596
597   END_TEST;
598 }
599
600 int UtcDaliFrameBufferGetColorTexture04(void)
601 {
602   TestApplication application;
603
604   unsigned int width(64);
605   unsigned int height(64);
606   FrameBuffer  frameBuffer = FrameBuffer::New(width, height, FrameBuffer::Attachment::NONE);
607   Texture      textures[]  = {
608     Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height),
609     Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height),
610     Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height),
611     Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height),
612     Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height),
613     Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height),
614     Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height),
615     Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height),
616   };
617
618   for(auto& t : textures)
619   {
620     frameBuffer.AttachColorTexture(t, 0u, 1u);
621   }
622
623   for(unsigned int i = 0; i < std::extent<decltype(textures)>::value; ++i)
624   {
625     DALI_TEST_EQUALS(DevelFrameBuffer::GetColorTexture(frameBuffer, i), textures[i], TEST_LOCATION);
626   }
627
628   END_TEST;
629 }
630
631 int UtcDaliFrameBufferGetDepthTexture01(void)
632 {
633   TestApplication application;
634
635   unsigned int width(64);
636   unsigned int height(64);
637   FrameBuffer  frameBuffer = FrameBuffer::New(width, height, FrameBuffer::Attachment::NONE);
638   Texture      texture     = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
639   frameBuffer.AttachColorTexture(texture);
640
641   Texture textureDepth = Texture::New(TextureType::TEXTURE_2D, Pixel::DEPTH_FLOAT, width, height);
642   DevelFrameBuffer::AttachDepthTexture(frameBuffer, textureDepth);
643
644   DALI_TEST_EQUALS(DevelFrameBuffer::GetDepthTexture(frameBuffer), textureDepth, TEST_LOCATION);
645
646   END_TEST;
647 }
648
649 int UtcDaliFrameBufferGetDepthStencilTexture01(void)
650 {
651   TestApplication application;
652
653   unsigned int width(64);
654   unsigned int height(64);
655   FrameBuffer  frameBuffer = FrameBuffer::New(width, height, FrameBuffer::Attachment::NONE);
656   Texture      texture     = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
657   frameBuffer.AttachColorTexture(texture);
658
659   Texture textureStencil = Texture::New(TextureType::TEXTURE_2D, Pixel::DEPTH_STENCIL, width, height);
660   DevelFrameBuffer::AttachDepthStencilTexture(frameBuffer, textureStencil);
661
662   DALI_TEST_EQUALS(DevelFrameBuffer::GetDepthStencilTexture(frameBuffer), textureStencil, TEST_LOCATION);
663
664   END_TEST;
665 }
666
667 int UtcDaliFramebufferContextLoss(void)
668 {
669   tet_infoline("UtcDaliFramebufferContextLoss\n");
670   TestApplication application;
671
672   //Create the texture
673   unsigned int width(64);
674   unsigned int height(64);
675   Texture      texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
676   DALI_TEST_CHECK(texture);
677   FrameBuffer frameBuffer = FrameBuffer::New(width, height, FrameBuffer::Attachment::NONE);
678   DALI_TEST_CHECK(frameBuffer);
679   frameBuffer.AttachColorTexture(texture, 0u, 1u);
680
681   Geometry geometry = CreateQuadGeometry();
682   Shader   shader   = CreateShader();
683   Renderer renderer = Renderer::New(geometry, shader);
684
685   application.SendNotification();
686   application.Render(16);
687
688   // Lose & regain context (in render 'thread')
689   application.ResetContext();
690   DALI_TEST_CHECK(frameBuffer);
691
692   END_TEST;
693 }
694
695 int UtcDaliFrameBufferGetColorTextureNegative(void)
696 {
697   TestApplication   application;
698   Dali::FrameBuffer instance;
699   try
700   {
701     instance.GetColorTexture();
702     DALI_TEST_CHECK(false); // Should not get here
703   }
704   catch(...)
705   {
706     DALI_TEST_CHECK(true); // We expect an assert
707   }
708   END_TEST;
709 }
710
711 int UtcDaliFrameBufferAttachColorTextureNegative01(void)
712 {
713   TestApplication   application;
714   Dali::FrameBuffer instance;
715   try
716   {
717     Dali::Texture arg1 = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 400u, 400u);
718     instance.AttachColorTexture(arg1);
719     DALI_TEST_CHECK(false); // Should not get here
720   }
721   catch(...)
722   {
723     DALI_TEST_CHECK(true); // We expect an assert
724   }
725   END_TEST;
726 }
727
728 int UtcDaliFrameBufferAttachColorTextureNegative02(void)
729 {
730   TestApplication   application;
731   Dali::FrameBuffer instance;
732   try
733   {
734     Dali::Texture arg1 = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 400u, 400u);
735     unsigned int  arg2(0u);
736     unsigned int  arg3(0u);
737     instance.AttachColorTexture(arg1, arg2, arg3);
738     DALI_TEST_CHECK(false); // Should not get here
739   }
740   catch(...)
741   {
742     DALI_TEST_CHECK(true); // We expect an assert
743   }
744   END_TEST;
745 }