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 UtcDaliFrameBufferCopyConstructor(void)
145 TestApplication application;
147 unsigned int width(64);
148 unsigned int height(64);
149 FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::NONE );
151 FrameBuffer frameBufferCopy( frameBuffer );
153 DALI_TEST_CHECK( frameBufferCopy );
158 int UtcDaliFrameBufferAssignmentOperator(void)
160 TestApplication application;
162 unsigned int width(64);
163 unsigned int height(64);
164 FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::NONE );
166 FrameBuffer frameBuffer2;
167 DALI_TEST_CHECK( !frameBuffer2 );
169 frameBuffer2 = frameBuffer;
170 DALI_TEST_CHECK( frameBuffer2 );
175 int UtcDaliFrameBufferDownCast01(void)
177 TestApplication application;
178 unsigned int width(64);
179 unsigned int height(64);
180 FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::NONE );
182 BaseHandle handle(frameBuffer);
183 FrameBuffer frameBuffer2 = FrameBuffer::DownCast(handle);
184 DALI_TEST_CHECK( frameBuffer2 );
189 int UtcDaliFrameBufferDownCast02(void)
191 TestApplication application;
193 Handle handle = Handle::New(); // Create a custom object
194 FrameBuffer frameBuffer = FrameBuffer::DownCast(handle);
195 DALI_TEST_CHECK( !frameBuffer );
199 int UtcDaliFrameBufferAttachColorTexture01(void)
201 TestApplication application;
203 unsigned int width(64);
204 unsigned int height(64);
205 FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::DEPTH_STENCIL );
206 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
207 frameBuffer.AttachColorTexture( texture );
209 application.SendNotification();
210 application.Render();
212 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
213 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
214 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
219 int UtcDaliFrameBufferAttachColorTexture02(void)
221 TestApplication application;
223 unsigned int width(64);
224 unsigned int height(64);
225 FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::NONE );
226 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
227 texture.GenerateMipmaps();
230 frameBuffer.AttachColorTexture( texture, 0u, 1u );
232 application.SendNotification();
233 application.Render();
235 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
236 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
237 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
242 int UtcDaliFrameBufferAttachColorTexture03(void)
244 TestApplication application;
246 unsigned int width(64);
247 unsigned int height(64);
248 FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::NONE );
249 Texture texture = Texture::New( TextureType::TEXTURE_CUBE, Pixel::RGBA8888, width, height );
250 texture.GenerateMipmaps();
252 //Attach NEGATIVE_Y face of the cubemap
253 frameBuffer.AttachColorTexture( texture, 0u, CubeMapLayer::NEGATIVE_Y );
255 application.SendNotification();
256 application.Render();
258 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
259 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
260 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
265 int UtcDaliFrameBufferAttachColorTexture04(void)
267 TestApplication application;
269 unsigned int width(64);
270 unsigned int height(64);
271 FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::DEPTH | FrameBuffer::Attachment::STENCIL );
272 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
273 frameBuffer.AttachColorTexture( texture );
275 application.SendNotification();
276 application.Render();
278 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
279 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
280 DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
285 int UtcDaliFrameBufferGetColorTexture01(void)
287 TestApplication application;
289 unsigned int width(64);
290 unsigned int height(64);
291 FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::NONE );
292 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
293 frameBuffer.AttachColorTexture( texture );
295 DALI_TEST_EQUALS(frameBuffer.GetColorTexture(), texture, TEST_LOCATION);
300 int UtcDaliFrameBufferGetColorTexture02(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 frameBuffer.AttachColorTexture( texture, 0u, 1u );
310 DALI_TEST_EQUALS(frameBuffer.GetColorTexture(), texture, TEST_LOCATION);
315 int UtcDaliFramebufferContextLoss(void)
317 tet_infoline("UtcDaliFramebufferContextLoss\n");
318 TestApplication application; // Default config: DALI_DISCARDS_ALL_DATA
321 unsigned int width(64);
322 unsigned int height(64);
323 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
324 DALI_TEST_CHECK( texture );
325 FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::NONE );
326 DALI_TEST_CHECK( frameBuffer );
327 frameBuffer.AttachColorTexture( texture, 0u, 1u );
329 application.SendNotification();
330 application.Render(16);
332 // Lose & regain context (in render 'thread')
333 application.ResetContext();
334 DALI_TEST_CHECK( frameBuffer );