Fix svace issue (uint32_t to long or std::streamsize)
[platform/core/uifw/dali-adaptor.git] / automated-tests / src / dali-graphics / utc-Dali-GraphicsFramebuffer.cpp
1 /*
2  * Copyright (c) 2022 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 #include <dali-test-suite-utils.h>
18 #include <dali/dali.h>
19
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>
24
25 using namespace Dali;
26
27 namespace
28 {
29 RenderTask CreateRenderTask(TestGraphicsApplication& application,
30                             FrameBuffer              framebuffer)
31 {
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);
37
38   CameraActor offscreenCameraActor = CameraActor::New(Size(TestApplication::DEFAULT_SURFACE_WIDTH,
39                                                            TestApplication::DEFAULT_SURFACE_HEIGHT));
40   application.GetScene().Add(offscreenCameraActor);
41
42   // Change main render task to use a different root
43   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
44   taskList.GetTask(0u).SetSourceActor(rootActor);
45
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);
54
55   return newTask;
56 }
57 } // namespace
58
59 void utc_dali_graphics_framebuffer_startup(void)
60 {
61   test_return_value = TET_UNDEF;
62 }
63 void utc_dali_graphics_framebuffer_cleanup(void)
64 {
65   test_return_value = TET_PASS;
66 }
67
68 int UtcDaliGraphicsFramebufferAttachDepth(void)
69 {
70   TestGraphicsApplication app;
71   tet_infoline("UtcDaliGraphicsFramebufferAttachDepth - Test for GLES specific behavior");
72
73   auto& gl = app.GetGlAbstraction();
74
75   uint32_t width  = 16u;
76   uint32_t height = 24u;
77
78   FrameBuffer framebuffer = FrameBuffer::New(width, height, FrameBuffer::Attachment::DEPTH);
79
80   DALI_TEST_CHECK(framebuffer);
81
82   Texture dummyColorTexture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
83   Actor   dummyActor        = CreateRenderableActor(dummyColorTexture);
84   framebuffer.AttachColorTexture(dummyColorTexture);
85
86   app.GetScene().Add(dummyActor);
87
88   auto renderTask = CreateRenderTask(app, framebuffer);
89
90   DALI_TEST_CHECK(renderTask);
91
92   app.SendNotification();
93   app.Render(16); // The above actor will get rendered and drawn once.
94
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.
102
103   END_TEST;
104 }
105
106 int UtcDaliGraphicsFramebufferAttachStencil(void)
107 {
108   TestGraphicsApplication app;
109   tet_infoline("UtcDaliGraphicsFramebufferAttachStencil - Test for GLES specific behavior");
110
111   auto& gl = app.GetGlAbstraction();
112
113   uint32_t width  = 16u;
114   uint32_t height = 24u;
115
116   FrameBuffer framebuffer = FrameBuffer::New(width, height, FrameBuffer::Attachment::STENCIL);
117
118   DALI_TEST_CHECK(framebuffer);
119
120   Texture dummyColorTexture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
121   Actor   dummyActor        = CreateRenderableActor(dummyColorTexture);
122   framebuffer.AttachColorTexture(dummyColorTexture);
123
124   app.GetScene().Add(dummyActor);
125
126   auto renderTask = CreateRenderTask(app, framebuffer);
127
128   DALI_TEST_CHECK(renderTask);
129
130   app.SendNotification();
131   app.Render(16); // The above actor will get rendered and drawn once.
132
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.
140
141   END_TEST;
142 }
143
144 int UtcDaliGraphicsFramebufferAttachDepthStencil(void)
145 {
146   TestGraphicsApplication app;
147   tet_infoline("UtcDaliGraphicsFramebufferAttachDepthStencil - Test for GLES specific behavior");
148
149   auto& gl = app.GetGlAbstraction();
150
151   uint32_t width  = 16u;
152   uint32_t height = 24u;
153
154   FrameBuffer framebuffer = FrameBuffer::New(width, height, FrameBuffer::Attachment::DEPTH_STENCIL);
155
156   DALI_TEST_CHECK(framebuffer);
157
158   Texture dummyColorTexture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
159   Actor   dummyActor        = CreateRenderableActor(dummyColorTexture);
160   framebuffer.AttachColorTexture(dummyColorTexture);
161
162   app.GetScene().Add(dummyActor);
163
164   auto renderTask = CreateRenderTask(app, framebuffer);
165
166   DALI_TEST_CHECK(renderTask);
167
168   app.SendNotification();
169   app.Render(16); // The above actor will get rendered and drawn once.
170
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.
178
179   END_TEST;
180 }
181
182 int UtcDaliGraphicsFramebufferAttachDepthTexture(void)
183 {
184   TestGraphicsApplication app;
185   tet_infoline("UtcDaliGraphicsFramebufferAttachDepthTexture - Test for GLES specific behavior");
186
187   auto& gl = app.GetGlAbstraction();
188
189   uint32_t width  = 16u;
190   uint32_t height = 24u;
191
192   FrameBuffer framebuffer = FrameBuffer::New(width, height, FrameBuffer::Attachment::NONE);
193
194   DALI_TEST_CHECK(framebuffer);
195
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);
201
202   app.GetScene().Add(dummyActor);
203
204   auto renderTask = CreateRenderTask(app, framebuffer);
205
206   DALI_TEST_CHECK(renderTask);
207
208   app.SendNotification();
209   app.Render(16); // The above actor will get rendered and drawn once.
210
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.
218
219   END_TEST;
220 }
221
222 int UtcDaliGraphicsFramebufferAttachDepthStencilTexture(void)
223 {
224   TestGraphicsApplication app;
225   tet_infoline("UtcDaliGraphicsFramebufferAttachDepthStencilTexture - Test for GLES specific behavior");
226
227   auto& gl = app.GetGlAbstraction();
228
229   uint32_t width  = 16u;
230   uint32_t height = 24u;
231
232   FrameBuffer framebuffer = FrameBuffer::New(width, height, FrameBuffer::Attachment::STENCIL);
233
234   DALI_TEST_CHECK(framebuffer);
235
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);
241
242   app.GetScene().Add(dummyActor);
243
244   auto renderTask = CreateRenderTask(app, framebuffer);
245
246   DALI_TEST_CHECK(renderTask);
247
248   app.SendNotification();
249   app.Render(16); // The above actor will get rendered and drawn once.
250
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.
258
259   END_TEST;
260 }
261
262 int UtcDaliGraphicsFramebufferAttachStencilAndDepthTexture(void)
263 {
264   TestGraphicsApplication app;
265   tet_infoline("UtcDaliGraphicsFramebufferAttachStencilAndDepthTexture - Test for GLES specific behavior");
266
267   auto& gl = app.GetGlAbstraction();
268
269   uint32_t width  = 16u;
270   uint32_t height = 24u;
271
272   FrameBuffer framebuffer = FrameBuffer::New(width, height, FrameBuffer::Attachment::STENCIL);
273
274   DALI_TEST_CHECK(framebuffer);
275
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);
282
283   app.GetScene().Add(dummyActor);
284
285   auto renderTask = CreateRenderTask(app, framebuffer);
286
287   DALI_TEST_CHECK(renderTask);
288
289   app.SendNotification();
290   app.Render(16); // The above actor will get rendered and drawn once.
291
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.
299
300   END_TEST;
301 }