2 * Copyright (c) 2022 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.
17 #include <dali-test-suite-utils.h>
18 #include <dali/dali.h>
20 #include <dali/internal/graphics/gles-impl/egl-graphics-controller.h>
21 #include <test-actor-utils.h>
22 #include <test-graphics-application.h>
23 #include <test-graphics-framebuffer.h>
29 RenderTask CreateRenderTask(TestGraphicsApplication& application,
30 FrameBuffer framebuffer)
32 Actor rootActor = Actor::New();
33 application.GetScene().Add(rootActor);
34 Texture img = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, 1, 1);
35 Actor sourceActor = CreateRenderableActor(img);
36 application.GetScene().Add(sourceActor);
38 CameraActor offscreenCameraActor = CameraActor::New(Size(TestApplication::DEFAULT_SURFACE_WIDTH,
39 TestApplication::DEFAULT_SURFACE_HEIGHT));
40 application.GetScene().Add(offscreenCameraActor);
42 // Change main render task to use a different root
43 RenderTaskList taskList = application.GetScene().GetRenderTaskList();
44 taskList.GetTask(0u).SetSourceActor(rootActor);
46 RenderTask newTask = taskList.CreateTask();
47 newTask.SetCameraActor(offscreenCameraActor);
48 newTask.SetSourceActor(sourceActor);
49 newTask.SetInputEnabled(false);
50 newTask.SetClearColor(Vector4(0.f, 0.f, 0.f, 0.f));
51 newTask.SetClearEnabled(true);
52 newTask.SetExclusive(true);
53 newTask.SetFrameBuffer(framebuffer);
59 void utc_dali_graphics_framebuffer_startup(void)
61 test_return_value = TET_UNDEF;
63 void utc_dali_graphics_framebuffer_cleanup(void)
65 test_return_value = TET_PASS;
68 int UtcDaliGraphicsFramebufferAttachDepth(void)
70 TestGraphicsApplication app;
71 tet_infoline("UtcDaliGraphicsFramebufferAttachDepth - Test for GLES specific behavior");
73 auto& gl = app.GetGlAbstraction();
76 uint32_t height = 24u;
78 FrameBuffer framebuffer = FrameBuffer::New(width, height, FrameBuffer::Attachment::DEPTH);
80 DALI_TEST_CHECK(framebuffer);
82 Texture dummyColorTexture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
83 Actor dummyActor = CreateRenderableActor(dummyColorTexture);
84 framebuffer.AttachColorTexture(dummyColorTexture);
86 app.GetScene().Add(dummyActor);
88 auto renderTask = CreateRenderTask(app, framebuffer);
90 DALI_TEST_CHECK(renderTask);
92 app.SendNotification();
93 app.Render(16); // The above actor will get rendered and drawn once.
95 DALI_TEST_EQUALS(gl.CheckFramebufferColorAttachmentCount(), 1u, TEST_LOCATION);
96 DALI_TEST_EQUALS(gl.CheckFramebufferDepthAttachmentCount(), 0u, TEST_LOCATION);
97 DALI_TEST_EQUALS(gl.CheckFramebufferStencilAttachmentCount(), 0u, TEST_LOCATION);
98 DALI_TEST_EQUALS(gl.CheckFramebufferDepthStencilAttachmentCount(), 0u, TEST_LOCATION);
99 DALI_TEST_EQUALS(gl.CheckFramebufferDepthAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
100 DALI_TEST_EQUALS(gl.CheckFramebufferStencilAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
101 DALI_TEST_EQUALS(gl.CheckFramebufferDepthStencilAttachment(), (GLenum)GL_FALSE, TEST_LOCATION); // Check whether renderbuffer attached by DEPTH_STENCIL.
106 int UtcDaliGraphicsFramebufferAttachStencil(void)
108 TestGraphicsApplication app;
109 tet_infoline("UtcDaliGraphicsFramebufferAttachStencil - Test for GLES specific behavior");
111 auto& gl = app.GetGlAbstraction();
113 uint32_t width = 16u;
114 uint32_t height = 24u;
116 FrameBuffer framebuffer = FrameBuffer::New(width, height, FrameBuffer::Attachment::STENCIL);
118 DALI_TEST_CHECK(framebuffer);
120 Texture dummyColorTexture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
121 Actor dummyActor = CreateRenderableActor(dummyColorTexture);
122 framebuffer.AttachColorTexture(dummyColorTexture);
124 app.GetScene().Add(dummyActor);
126 auto renderTask = CreateRenderTask(app, framebuffer);
128 DALI_TEST_CHECK(renderTask);
130 app.SendNotification();
131 app.Render(16); // The above actor will get rendered and drawn once.
133 DALI_TEST_EQUALS(gl.CheckFramebufferColorAttachmentCount(), 1u, TEST_LOCATION);
134 DALI_TEST_EQUALS(gl.CheckFramebufferDepthAttachmentCount(), 0u, TEST_LOCATION);
135 DALI_TEST_EQUALS(gl.CheckFramebufferStencilAttachmentCount(), 0u, TEST_LOCATION);
136 DALI_TEST_EQUALS(gl.CheckFramebufferDepthStencilAttachmentCount(), 0u, TEST_LOCATION);
137 DALI_TEST_EQUALS(gl.CheckFramebufferDepthAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
138 DALI_TEST_EQUALS(gl.CheckFramebufferStencilAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
139 DALI_TEST_EQUALS(gl.CheckFramebufferDepthStencilAttachment(), (GLenum)GL_FALSE, TEST_LOCATION); // Check whether renderbuffer attached by DEPTH_STENCIL.
144 int UtcDaliGraphicsFramebufferAttachDepthStencil(void)
146 TestGraphicsApplication app;
147 tet_infoline("UtcDaliGraphicsFramebufferAttachDepthStencil - Test for GLES specific behavior");
149 auto& gl = app.GetGlAbstraction();
151 uint32_t width = 16u;
152 uint32_t height = 24u;
154 FrameBuffer framebuffer = FrameBuffer::New(width, height, FrameBuffer::Attachment::DEPTH_STENCIL);
156 DALI_TEST_CHECK(framebuffer);
158 Texture dummyColorTexture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
159 Actor dummyActor = CreateRenderableActor(dummyColorTexture);
160 framebuffer.AttachColorTexture(dummyColorTexture);
162 app.GetScene().Add(dummyActor);
164 auto renderTask = CreateRenderTask(app, framebuffer);
166 DALI_TEST_CHECK(renderTask);
168 app.SendNotification();
169 app.Render(16); // The above actor will get rendered and drawn once.
171 DALI_TEST_EQUALS(gl.CheckFramebufferColorAttachmentCount(), 1u, TEST_LOCATION);
172 DALI_TEST_EQUALS(gl.CheckFramebufferDepthAttachmentCount(), 0u, TEST_LOCATION);
173 DALI_TEST_EQUALS(gl.CheckFramebufferStencilAttachmentCount(), 0u, TEST_LOCATION);
174 DALI_TEST_EQUALS(gl.CheckFramebufferDepthStencilAttachmentCount(), 0u, TEST_LOCATION);
175 DALI_TEST_EQUALS(gl.CheckFramebufferDepthAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
176 DALI_TEST_EQUALS(gl.CheckFramebufferStencilAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
177 DALI_TEST_EQUALS(gl.CheckFramebufferDepthStencilAttachment(), (GLenum)GL_TRUE, TEST_LOCATION); // Check whether renderbuffer attached by DEPTH_STENCIL.
182 int UtcDaliGraphicsFramebufferAttachDepthTexture(void)
184 TestGraphicsApplication app;
185 tet_infoline("UtcDaliGraphicsFramebufferAttachDepthTexture - Test for GLES specific behavior");
187 auto& gl = app.GetGlAbstraction();
189 uint32_t width = 16u;
190 uint32_t height = 24u;
192 FrameBuffer framebuffer = FrameBuffer::New(width, height, FrameBuffer::Attachment::NONE);
194 DALI_TEST_CHECK(framebuffer);
196 Texture dummyColorTexture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
197 Texture dummyDepthTexture = CreateTexture(TextureType::TEXTURE_2D, Pixel::DEPTH_UNSIGNED_INT, width, height);
198 Actor dummyActor = CreateRenderableActor(dummyColorTexture);
199 framebuffer.AttachColorTexture(dummyColorTexture);
200 DevelFrameBuffer::AttachDepthTexture(framebuffer, dummyDepthTexture);
202 app.GetScene().Add(dummyActor);
204 auto renderTask = CreateRenderTask(app, framebuffer);
206 DALI_TEST_CHECK(renderTask);
208 app.SendNotification();
209 app.Render(16); // The above actor will get rendered and drawn once.
211 DALI_TEST_EQUALS(gl.CheckFramebufferColorAttachmentCount(), 1u, TEST_LOCATION);
212 DALI_TEST_EQUALS(gl.CheckFramebufferDepthAttachmentCount(), 1u, TEST_LOCATION);
213 DALI_TEST_EQUALS(gl.CheckFramebufferStencilAttachmentCount(), 0u, TEST_LOCATION);
214 DALI_TEST_EQUALS(gl.CheckFramebufferDepthStencilAttachmentCount(), 0u, TEST_LOCATION);
215 DALI_TEST_EQUALS(gl.CheckFramebufferDepthAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
216 DALI_TEST_EQUALS(gl.CheckFramebufferStencilAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
217 DALI_TEST_EQUALS(gl.CheckFramebufferDepthStencilAttachment(), (GLenum)GL_FALSE, TEST_LOCATION); // Check whether renderbuffer attached by DEPTH_STENCIL.
222 int UtcDaliGraphicsFramebufferAttachDepthStencilTexture(void)
224 TestGraphicsApplication app;
225 tet_infoline("UtcDaliGraphicsFramebufferAttachDepthStencilTexture - Test for GLES specific behavior");
227 auto& gl = app.GetGlAbstraction();
229 uint32_t width = 16u;
230 uint32_t height = 24u;
232 FrameBuffer framebuffer = FrameBuffer::New(width, height, FrameBuffer::Attachment::STENCIL);
234 DALI_TEST_CHECK(framebuffer);
236 Texture dummyColorTexture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
237 Texture dummyDepthStencilTexture = CreateTexture(TextureType::TEXTURE_2D, Pixel::DEPTH_STENCIL, width, height);
238 Actor dummyActor = CreateRenderableActor(dummyColorTexture);
239 framebuffer.AttachColorTexture(dummyColorTexture);
240 DevelFrameBuffer::AttachDepthStencilTexture(framebuffer, dummyDepthStencilTexture);
242 app.GetScene().Add(dummyActor);
244 auto renderTask = CreateRenderTask(app, framebuffer);
246 DALI_TEST_CHECK(renderTask);
248 app.SendNotification();
249 app.Render(16); // The above actor will get rendered and drawn once.
251 DALI_TEST_EQUALS(gl.CheckFramebufferColorAttachmentCount(), 1u, TEST_LOCATION);
252 DALI_TEST_EQUALS(gl.CheckFramebufferDepthAttachmentCount(), 1u, TEST_LOCATION);
253 DALI_TEST_EQUALS(gl.CheckFramebufferStencilAttachmentCount(), 1u, TEST_LOCATION);
254 DALI_TEST_EQUALS(gl.CheckFramebufferDepthStencilAttachmentCount(), 1u, TEST_LOCATION);
255 DALI_TEST_EQUALS(gl.CheckFramebufferDepthAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
256 DALI_TEST_EQUALS(gl.CheckFramebufferStencilAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
257 DALI_TEST_EQUALS(gl.CheckFramebufferDepthStencilAttachment(), (GLenum)GL_FALSE, TEST_LOCATION); // Check whether renderbuffer attached by DEPTH_STENCIL.
262 int UtcDaliGraphicsFramebufferAttachStencilAndDepthTexture(void)
264 TestGraphicsApplication app;
265 tet_infoline("UtcDaliGraphicsFramebufferAttachStencilAndDepthTexture - Test for GLES specific behavior");
267 auto& gl = app.GetGlAbstraction();
269 uint32_t width = 16u;
270 uint32_t height = 24u;
272 FrameBuffer framebuffer = FrameBuffer::New(width, height, FrameBuffer::Attachment::STENCIL);
274 DALI_TEST_CHECK(framebuffer);
276 Texture dummyColorTexture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
277 // Note : Current GLES cannot seperate destination of depth result and stencil result. We need to make the texture as DEPTH_STENCIL
278 Texture dummyDepthTexture = CreateTexture(TextureType::TEXTURE_2D, Pixel::DEPTH_STENCIL, width, height);
279 Actor dummyActor = CreateRenderableActor(dummyColorTexture);
280 framebuffer.AttachColorTexture(dummyColorTexture);
281 DevelFrameBuffer::AttachDepthTexture(framebuffer, dummyDepthTexture);
283 app.GetScene().Add(dummyActor);
285 auto renderTask = CreateRenderTask(app, framebuffer);
287 DALI_TEST_CHECK(renderTask);
289 app.SendNotification();
290 app.Render(16); // The above actor will get rendered and drawn once.
292 DALI_TEST_EQUALS(gl.CheckFramebufferColorAttachmentCount(), 1u, TEST_LOCATION);
293 DALI_TEST_EQUALS(gl.CheckFramebufferDepthAttachmentCount(), 1u, TEST_LOCATION);
294 DALI_TEST_EQUALS(gl.CheckFramebufferStencilAttachmentCount(), 1u, TEST_LOCATION);
295 DALI_TEST_EQUALS(gl.CheckFramebufferDepthStencilAttachmentCount(), 1u, TEST_LOCATION);
296 DALI_TEST_EQUALS(gl.CheckFramebufferDepthAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
297 DALI_TEST_EQUALS(gl.CheckFramebufferStencilAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
298 DALI_TEST_EQUALS(gl.CheckFramebufferDepthStencilAttachment(), (GLenum)GL_FALSE, TEST_LOCATION); // Check whether renderbuffer attached by DEPTH_STENCIL.