2 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include <dali/public-api/dali-core.h>
19 #include <dali-test-suite-utils.h>
20 #include <dali/devel-api/rendering/frame-buffer-devel.h>
24 #include <mesh-builder.h>
26 void framebuffer_set_startup(void)
28 test_return_value = TET_UNDEF;
31 void framebuffer_set_cleanup(void)
33 test_return_value = TET_PASS;
36 int UtcDaliFrameBufferNew01(void)
38 TestApplication application;
40 unsigned int width(64);
41 unsigned int height(64);
42 FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::NONE );
44 DALI_TEST_CHECK( frameBuffer );
46 application.SendNotification();
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);
56 int UtcDaliFrameBufferNew02(void)
58 TestApplication application;
60 unsigned int width(64);
61 unsigned int height(64);
62 FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::DEPTH );
64 DALI_TEST_CHECK( frameBuffer );
66 application.SendNotification();
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);
76 int UtcDaliFrameBufferNew03(void)
78 TestApplication application;
80 unsigned int width(64);
81 unsigned int height(64);
82 FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::STENCIL );
84 DALI_TEST_CHECK( frameBuffer );
86 application.SendNotification();
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);
96 int UtcDaliFrameBufferNew04(void)
98 TestApplication application;
100 unsigned int width(64);
101 unsigned int height(64);
102 FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::DEPTH_STENCIL );
104 DALI_TEST_CHECK( frameBuffer );
106 application.SendNotification();
107 application.Render();
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);
116 int UtcDaliFrameBufferNew05(void)
118 TestApplication application;
119 FrameBuffer frameBuffer;
120 DALI_TEST_CHECK( !frameBuffer );
124 int UtcDaliFrameBufferNew06(void)
126 TestApplication application;
128 unsigned int width(64);
129 unsigned int height(64);
130 FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::DEPTH | FrameBuffer::Attachment::STENCIL );
132 DALI_TEST_CHECK( frameBuffer );
134 application.SendNotification();
135 application.Render();
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);
144 int UtcDaliFrameBufferNewWithColor01(void)
146 TestApplication application;
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() );
160 int UtcDaliFrameBufferNewWithColor02(void)
162 TestApplication application;
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() );
176 int UtcDaliFrameBufferNewWithColor03(void)
178 TestApplication application;
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() );
192 int UtcDaliFrameBufferNewWithColor04(void)
194 TestApplication application;
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() );
208 int UtcDaliFrameBufferNewWithColor05(void)
210 TestApplication application;
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() );
224 int UtcDaliFrameBufferCopyConstructor(void)
226 TestApplication application;
228 unsigned int width(64);
229 unsigned int height(64);
230 FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::NONE );
232 FrameBuffer frameBufferCopy( frameBuffer );
234 DALI_TEST_CHECK( frameBufferCopy );
239 int UtcDaliFrameBufferAssignmentOperator(void)
241 TestApplication application;
243 unsigned int width(64);
244 unsigned int height(64);
245 FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::NONE );
247 FrameBuffer frameBuffer2;
248 DALI_TEST_CHECK( !frameBuffer2 );
250 frameBuffer2 = frameBuffer;
251 DALI_TEST_CHECK( frameBuffer2 );
256 int UtcDaliFrameBufferDownCast01(void)
258 TestApplication application;
259 unsigned int width(64);
260 unsigned int height(64);
261 FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::NONE );
263 BaseHandle handle(frameBuffer);
264 FrameBuffer frameBuffer2 = FrameBuffer::DownCast(handle);
265 DALI_TEST_CHECK( frameBuffer2 );
270 int UtcDaliFrameBufferDownCast02(void)
272 TestApplication application;
274 Handle handle = Handle::New(); // Create a custom object
275 FrameBuffer frameBuffer = FrameBuffer::DownCast(handle);
276 DALI_TEST_CHECK( !frameBuffer );
280 int UtcDaliFrameBufferAttachColorTexture01(void)
282 TestApplication application;
284 unsigned int width(64);
285 unsigned int height(64);
286 FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::DEPTH_STENCIL );
287 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
288 frameBuffer.AttachColorTexture( texture );
290 application.SendNotification();
291 application.Render();
293 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachmentCount(), 1u, TEST_LOCATION);
294 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
295 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
300 int UtcDaliFrameBufferAttachColorTexture02(void)
302 TestApplication application;
304 unsigned int width(64);
305 unsigned int height(64);
306 FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::NONE );
307 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
308 texture.GenerateMipmaps();
311 frameBuffer.AttachColorTexture( texture, 0u, 1u );
313 application.SendNotification();
314 application.Render();
316 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachmentCount(), 1u, TEST_LOCATION);
317 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
318 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
323 int UtcDaliFrameBufferAttachColorTexture03(void)
325 TestApplication application;
327 unsigned int width(64);
328 unsigned int height(64);
329 FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::NONE );
330 Texture texture = Texture::New( TextureType::TEXTURE_CUBE, Pixel::RGBA8888, width, height );
331 texture.GenerateMipmaps();
333 //Attach NEGATIVE_Y face of the cubemap
334 frameBuffer.AttachColorTexture( texture, 0u, CubeMapLayer::NEGATIVE_Y );
336 application.SendNotification();
337 application.Render();
339 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachmentCount(), 1u, TEST_LOCATION);
340 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
341 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
346 int UtcDaliFrameBufferAttachColorTexture04(void)
348 TestApplication application;
350 unsigned int width(64);
351 unsigned int height(64);
352 FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::DEPTH | FrameBuffer::Attachment::STENCIL );
353 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
354 frameBuffer.AttachColorTexture( texture );
356 application.SendNotification();
357 application.Render();
359 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachmentCount(), 1u, TEST_LOCATION);
360 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
361 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
366 int UtcDaliFrameBufferAttachColorTexture05(void)
368 TestApplication application;
370 unsigned int width(64);
371 unsigned int height(64);
372 FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::NONE );
373 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
375 // 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.
376 for (int i = 0; i < Dali::DevelFrameBuffer::MAX_COLOR_ATTACHMENTS + 1; ++i)
378 frameBuffer.AttachColorTexture( texture );
381 application.SendNotification();
382 application.Render();
384 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachmentCount(), Dali::DevelFrameBuffer::MAX_COLOR_ATTACHMENTS, TEST_LOCATION);
385 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
386 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
391 int UtcDaliFrameBufferGetColorTexture01(void)
393 TestApplication application;
395 unsigned int width(64);
396 unsigned int height(64);
397 FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::NONE );
398 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
399 frameBuffer.AttachColorTexture( texture );
401 DALI_TEST_EQUALS(frameBuffer.GetColorTexture(), texture, TEST_LOCATION);
406 int UtcDaliFrameBufferGetColorTexture02(void)
408 TestApplication application;
410 unsigned int width(64);
411 unsigned int height(64);
412 FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::NONE );
413 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
414 frameBuffer.AttachColorTexture( texture, 0u, 1u );
416 DALI_TEST_EQUALS(frameBuffer.GetColorTexture(), texture, TEST_LOCATION);
421 int UtcDaliFrameBufferGetColorTexture03(void)
422 { // FrameBuffer::GetColorTexture() and GetColorTexture(0) are equivalent
423 TestApplication application;
425 unsigned int width(64);
426 unsigned int height(64);
427 FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::NONE );
428 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
429 frameBuffer.AttachColorTexture( texture, 0u, 1u );
431 DALI_TEST_EQUALS(frameBuffer.GetColorTexture(), texture, TEST_LOCATION);
432 DALI_TEST_EQUALS(DevelFrameBuffer::GetColorTexture(frameBuffer, 0), texture, TEST_LOCATION);
437 int UtcDaliFrameBufferGetColorTexture04(void)
439 TestApplication application;
441 unsigned int width(64);
442 unsigned int height(64);
443 FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::NONE );
444 Texture textures[] = {
445 Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height ),
446 Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height ),
447 Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height ),
448 Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height ),
449 Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height ),
450 Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height ),
451 Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height ),
452 Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height ),
455 for (auto& t: textures)
457 frameBuffer.AttachColorTexture( t, 0u, 1u );
460 for (unsigned int i = 0; i < std::extent<decltype(textures)>::value; ++i)
462 DALI_TEST_EQUALS(DevelFrameBuffer::GetColorTexture(frameBuffer, i), textures[i], TEST_LOCATION);
468 int UtcDaliFramebufferContextLoss(void)
470 tet_infoline("UtcDaliFramebufferContextLoss\n");
471 TestApplication application; // Default config: DALI_DISCARDS_ALL_DATA
474 unsigned int width(64);
475 unsigned int height(64);
476 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
477 DALI_TEST_CHECK( texture );
478 FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::NONE );
479 DALI_TEST_CHECK( frameBuffer );
480 frameBuffer.AttachColorTexture( texture, 0u, 1u );
482 Geometry geometry = CreateQuadGeometry();
483 Shader shader = CreateShader();
484 Renderer renderer = Renderer::New(geometry, shader);
486 application.SendNotification();
487 application.Render(16);
489 // Lose & regain context (in render 'thread')
490 application.ResetContext();
491 DALI_TEST_CHECK( frameBuffer );