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