Merge "DALi Version 2.2.18" into devel/master
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-FrameBuffer.cpp
1 /*
2  * Copyright (c) 2022 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 UtcDaliFrameBufferSetMultiSampingLevel(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::DEPTH_STENCIL);
561   Texture      texture     = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
562   frameBuffer.AttachColorTexture(texture);
563
564   DevelFrameBuffer::SetMultiSamplingLevel(frameBuffer, 4u);
565
566   CreateRenderTask(application, frameBuffer);
567   application.SendNotification();
568   application.Render();
569
570   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachmentCount(), 1u, TEST_LOCATION);
571   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
572   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
573
574   // We don't have getter API for multisampling level. No testing.
575
576   END_TEST;
577 }
578
579 int UtcDaliFrameBufferGetColorTexture01(void)
580 {
581   TestApplication application;
582
583   unsigned int width(64);
584   unsigned int height(64);
585   FrameBuffer  frameBuffer = FrameBuffer::New(width, height, FrameBuffer::Attachment::NONE);
586   Texture      texture     = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
587   frameBuffer.AttachColorTexture(texture);
588
589   DALI_TEST_EQUALS(frameBuffer.GetColorTexture(), texture, TEST_LOCATION);
590
591   END_TEST;
592 }
593
594 int UtcDaliFrameBufferGetColorTexture02(void)
595 {
596   TestApplication application;
597
598   unsigned int width(64);
599   unsigned int height(64);
600   FrameBuffer  frameBuffer = FrameBuffer::New(width, height, FrameBuffer::Attachment::NONE);
601   Texture      texture     = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
602   frameBuffer.AttachColorTexture(texture, 0u, 1u);
603
604   DALI_TEST_EQUALS(frameBuffer.GetColorTexture(), texture, TEST_LOCATION);
605
606   END_TEST;
607 }
608
609 int UtcDaliFrameBufferGetColorTexture03(void)
610 { // FrameBuffer::GetColorTexture() and GetColorTexture(0) are equivalent
611   TestApplication application;
612
613   unsigned int width(64);
614   unsigned int height(64);
615   FrameBuffer  frameBuffer = FrameBuffer::New(width, height, FrameBuffer::Attachment::NONE);
616   Texture      texture     = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
617   frameBuffer.AttachColorTexture(texture, 0u, 1u);
618
619   DALI_TEST_EQUALS(frameBuffer.GetColorTexture(), texture, TEST_LOCATION);
620   DALI_TEST_EQUALS(DevelFrameBuffer::GetColorTexture(frameBuffer, 0), texture, TEST_LOCATION);
621
622   END_TEST;
623 }
624
625 int UtcDaliFrameBufferGetColorTexture04(void)
626 {
627   TestApplication application;
628
629   unsigned int width(64);
630   unsigned int height(64);
631   FrameBuffer  frameBuffer = FrameBuffer::New(width, height, FrameBuffer::Attachment::NONE);
632   Texture      textures[]  = {
633     Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height),
634     Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height),
635     Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height),
636     Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height),
637     Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height),
638     Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height),
639     Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height),
640     Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height),
641   };
642
643   for(auto& t : textures)
644   {
645     frameBuffer.AttachColorTexture(t, 0u, 1u);
646   }
647
648   for(unsigned int i = 0; i < std::extent<decltype(textures)>::value; ++i)
649   {
650     DALI_TEST_EQUALS(DevelFrameBuffer::GetColorTexture(frameBuffer, i), textures[i], TEST_LOCATION);
651   }
652
653   END_TEST;
654 }
655
656 int UtcDaliFrameBufferGetDepthTexture01(void)
657 {
658   TestApplication application;
659
660   unsigned int width(64);
661   unsigned int height(64);
662   FrameBuffer  frameBuffer = FrameBuffer::New(width, height, FrameBuffer::Attachment::NONE);
663   Texture      texture     = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
664   frameBuffer.AttachColorTexture(texture);
665
666   Texture textureDepth = Texture::New(TextureType::TEXTURE_2D, Pixel::DEPTH_FLOAT, width, height);
667   DevelFrameBuffer::AttachDepthTexture(frameBuffer, textureDepth);
668
669   DALI_TEST_EQUALS(DevelFrameBuffer::GetDepthTexture(frameBuffer), textureDepth, TEST_LOCATION);
670
671   END_TEST;
672 }
673
674 int UtcDaliFrameBufferGetDepthStencilTexture01(void)
675 {
676   TestApplication application;
677
678   unsigned int width(64);
679   unsigned int height(64);
680   FrameBuffer  frameBuffer = FrameBuffer::New(width, height, FrameBuffer::Attachment::NONE);
681   Texture      texture     = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
682   frameBuffer.AttachColorTexture(texture);
683
684   Texture textureStencil = Texture::New(TextureType::TEXTURE_2D, Pixel::DEPTH_STENCIL, width, height);
685   DevelFrameBuffer::AttachDepthStencilTexture(frameBuffer, textureStencil);
686
687   DALI_TEST_EQUALS(DevelFrameBuffer::GetDepthStencilTexture(frameBuffer), textureStencil, TEST_LOCATION);
688
689   END_TEST;
690 }
691
692 int UtcDaliFramebufferContextLoss(void)
693 {
694   tet_infoline("UtcDaliFramebufferContextLoss\n");
695   TestApplication application;
696
697   //Create the texture
698   unsigned int width(64);
699   unsigned int height(64);
700   Texture      texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
701   DALI_TEST_CHECK(texture);
702   FrameBuffer frameBuffer = FrameBuffer::New(width, height, FrameBuffer::Attachment::NONE);
703   DALI_TEST_CHECK(frameBuffer);
704   frameBuffer.AttachColorTexture(texture, 0u, 1u);
705
706   Geometry geometry = CreateQuadGeometry();
707   Shader   shader   = CreateShader();
708   Renderer renderer = Renderer::New(geometry, shader);
709
710   application.SendNotification();
711   application.Render(16);
712
713   // Lose & regain context (in render 'thread')
714   application.ResetContext();
715   DALI_TEST_CHECK(frameBuffer);
716
717   END_TEST;
718 }
719
720 int UtcDaliFrameBufferGetColorTextureNegative(void)
721 {
722   TestApplication   application;
723   Dali::FrameBuffer instance;
724   try
725   {
726     instance.GetColorTexture();
727     DALI_TEST_CHECK(false); // Should not get here
728   }
729   catch(...)
730   {
731     DALI_TEST_CHECK(true); // We expect an assert
732   }
733   END_TEST;
734 }
735
736 int UtcDaliFrameBufferAttachColorTextureNegative01(void)
737 {
738   TestApplication   application;
739   Dali::FrameBuffer instance;
740   try
741   {
742     Dali::Texture arg1 = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 400u, 400u);
743     instance.AttachColorTexture(arg1);
744     DALI_TEST_CHECK(false); // Should not get here
745   }
746   catch(...)
747   {
748     DALI_TEST_CHECK(true); // We expect an assert
749   }
750   END_TEST;
751 }
752
753 int UtcDaliFrameBufferAttachColorTextureNegative02(void)
754 {
755   TestApplication   application;
756   Dali::FrameBuffer instance;
757   try
758   {
759     Dali::Texture arg1 = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 400u, 400u);
760     unsigned int  arg2(0u);
761     unsigned int  arg3(0u);
762     instance.AttachColorTexture(arg1, arg2, arg3);
763     DALI_TEST_CHECK(false); // Should not get here
764   }
765   catch(...)
766   {
767     DALI_TEST_CHECK(true); // We expect an assert
768   }
769   END_TEST;
770 }