2 * Copyright (c) 2016 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>
23 #include <mesh-builder.h>
25 void framebuffer_set_startup(void)
27 test_return_value = TET_UNDEF;
30 void framebuffer_set_cleanup(void)
32 test_return_value = TET_PASS;
35 int UtcDaliFrameBufferNew01(void)
37 TestApplication application;
39 unsigned int width(64);
40 unsigned int height(64);
41 FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::NONE );
43 DALI_TEST_CHECK( frameBuffer );
45 application.SendNotification();
48 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
49 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
50 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
55 int UtcDaliFrameBufferNew02(void)
57 TestApplication application;
59 unsigned int width(64);
60 unsigned int height(64);
61 FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::DEPTH );
63 DALI_TEST_CHECK( frameBuffer );
65 application.SendNotification();
68 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
69 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
70 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
75 int UtcDaliFrameBufferNew03(void)
77 TestApplication application;
79 unsigned int width(64);
80 unsigned int height(64);
81 FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::STENCIL );
83 DALI_TEST_CHECK( frameBuffer );
85 application.SendNotification();
88 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
89 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
90 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
95 int UtcDaliFrameBufferNew04(void)
97 TestApplication application;
99 unsigned int width(64);
100 unsigned int height(64);
101 FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::DEPTH_STENCIL );
103 DALI_TEST_CHECK( frameBuffer );
105 application.SendNotification();
106 application.Render();
108 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
109 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
110 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
115 int UtcDaliFrameBufferNew05(void)
117 TestApplication application;
118 FrameBuffer frameBuffer;
119 DALI_TEST_CHECK( !frameBuffer );
123 int UtcDaliFrameBufferNew06(void)
125 TestApplication application;
127 unsigned int width(64);
128 unsigned int height(64);
129 FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::DEPTH | FrameBuffer::Attachment::STENCIL );
131 DALI_TEST_CHECK( frameBuffer );
133 application.SendNotification();
134 application.Render();
136 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
137 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
138 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
143 int UtcDaliFrameBufferNewWithColor01(void)
145 TestApplication application;
147 uint32_t height = 64;
148 FrameBuffer frameBuffer = FrameBuffer::New( width, height );
149 application.SendNotification();
150 application.Render();
151 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
152 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
153 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
154 // check that texture is not empty handle
155 DALI_TEST_CHECK( frameBuffer.GetColorTexture() );
159 int UtcDaliFrameBufferNewWithColor02(void)
161 TestApplication application;
163 uint32_t height = 64;
164 FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::COLOR );
165 application.SendNotification();
166 application.Render();
167 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
168 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
169 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
170 // check that texture is not empty handle
171 DALI_TEST_CHECK( frameBuffer.GetColorTexture() );
175 int UtcDaliFrameBufferNewWithColor03(void)
177 TestApplication application;
179 uint32_t height = 64;
180 FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::COLOR_DEPTH );
181 application.SendNotification();
182 application.Render();
183 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
184 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
185 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
186 // check that texture is not empty handle
187 DALI_TEST_CHECK( frameBuffer.GetColorTexture() );
191 int UtcDaliFrameBufferNewWithColor04(void)
193 TestApplication application;
195 uint32_t height = 64;
196 FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::COLOR_STENCIL );
197 application.SendNotification();
198 application.Render();
199 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
200 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
201 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
202 // check that texture is not empty handle
203 DALI_TEST_CHECK( frameBuffer.GetColorTexture() );
207 int UtcDaliFrameBufferNewWithColor05(void)
209 TestApplication application;
211 uint32_t height = 64;
212 FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::COLOR_DEPTH_STENCIL );
213 application.SendNotification();
214 application.Render();
215 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
216 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
217 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
218 // check that texture is not empty handle
219 DALI_TEST_CHECK( frameBuffer.GetColorTexture() );
223 int UtcDaliFrameBufferCopyConstructor(void)
225 TestApplication application;
227 unsigned int width(64);
228 unsigned int height(64);
229 FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::NONE );
231 FrameBuffer frameBufferCopy( frameBuffer );
233 DALI_TEST_CHECK( frameBufferCopy );
238 int UtcDaliFrameBufferAssignmentOperator(void)
240 TestApplication application;
242 unsigned int width(64);
243 unsigned int height(64);
244 FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::NONE );
246 FrameBuffer frameBuffer2;
247 DALI_TEST_CHECK( !frameBuffer2 );
249 frameBuffer2 = frameBuffer;
250 DALI_TEST_CHECK( frameBuffer2 );
255 int UtcDaliFrameBufferDownCast01(void)
257 TestApplication application;
258 unsigned int width(64);
259 unsigned int height(64);
260 FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::NONE );
262 BaseHandle handle(frameBuffer);
263 FrameBuffer frameBuffer2 = FrameBuffer::DownCast(handle);
264 DALI_TEST_CHECK( frameBuffer2 );
269 int UtcDaliFrameBufferDownCast02(void)
271 TestApplication application;
273 Handle handle = Handle::New(); // Create a custom object
274 FrameBuffer frameBuffer = FrameBuffer::DownCast(handle);
275 DALI_TEST_CHECK( !frameBuffer );
279 int UtcDaliFrameBufferAttachColorTexture01(void)
281 TestApplication application;
283 unsigned int width(64);
284 unsigned int height(64);
285 FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::DEPTH_STENCIL );
286 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
287 frameBuffer.AttachColorTexture( texture );
289 application.SendNotification();
290 application.Render();
292 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
293 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
294 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
299 int UtcDaliFrameBufferAttachColorTexture02(void)
301 TestApplication application;
303 unsigned int width(64);
304 unsigned int height(64);
305 FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::NONE );
306 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
307 texture.GenerateMipmaps();
310 frameBuffer.AttachColorTexture( texture, 0u, 1u );
312 application.SendNotification();
313 application.Render();
315 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
316 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
317 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
322 int UtcDaliFrameBufferAttachColorTexture03(void)
324 TestApplication application;
326 unsigned int width(64);
327 unsigned int height(64);
328 FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::NONE );
329 Texture texture = Texture::New( TextureType::TEXTURE_CUBE, Pixel::RGBA8888, width, height );
330 texture.GenerateMipmaps();
332 //Attach NEGATIVE_Y face of the cubemap
333 frameBuffer.AttachColorTexture( texture, 0u, CubeMapLayer::NEGATIVE_Y );
335 application.SendNotification();
336 application.Render();
338 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
339 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
340 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
345 int UtcDaliFrameBufferAttachColorTexture04(void)
347 TestApplication application;
349 unsigned int width(64);
350 unsigned int height(64);
351 FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::DEPTH | FrameBuffer::Attachment::STENCIL );
352 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
353 frameBuffer.AttachColorTexture( texture );
355 application.SendNotification();
356 application.Render();
358 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
359 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
360 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
365 int UtcDaliFrameBufferGetColorTexture01(void)
367 TestApplication application;
369 unsigned int width(64);
370 unsigned int height(64);
371 FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::NONE );
372 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
373 frameBuffer.AttachColorTexture( texture );
375 DALI_TEST_EQUALS(frameBuffer.GetColorTexture(), texture, TEST_LOCATION);
380 int UtcDaliFrameBufferGetColorTexture02(void)
382 TestApplication application;
384 unsigned int width(64);
385 unsigned int height(64);
386 FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::NONE );
387 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
388 frameBuffer.AttachColorTexture( texture, 0u, 1u );
390 DALI_TEST_EQUALS(frameBuffer.GetColorTexture(), texture, TEST_LOCATION);
395 int UtcDaliFramebufferContextLoss(void)
397 tet_infoline("UtcDaliFramebufferContextLoss\n");
398 TestApplication application; // Default config: DALI_DISCARDS_ALL_DATA
401 unsigned int width(64);
402 unsigned int height(64);
403 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
404 DALI_TEST_CHECK( texture );
405 FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::NONE );
406 DALI_TEST_CHECK( frameBuffer );
407 frameBuffer.AttachColorTexture( texture, 0u, 1u );
409 Geometry geometry = CreateQuadGeometry();
410 Shader shader = CreateShader();
411 Renderer renderer = Renderer::New(geometry, shader);
413 application.SendNotification();
414 application.Render(16);
416 // Lose & regain context (in render 'thread')
417 application.ResetContext();
418 DALI_TEST_CHECK( frameBuffer );