Cache manager for 3D models
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-scene3d / utc-Dali-SceneView.cpp
1 /*
2  * Copyright (c) 2023 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
18 #include <dali-toolkit-test-suite-utils.h>
19 #include <dali-toolkit/dali-toolkit.h>
20 #include <stdlib.h>
21 #include <iostream>
22
23 #include <dali-scene3d/public-api/controls/model/model.h>
24 #include <dali-scene3d/public-api/controls/scene-view/scene-view.h>
25 #include <toolkit-event-thread-callback.h>
26
27 using namespace Dali;
28 using namespace Dali::Toolkit;
29
30 void scene_view_startup(void)
31 {
32   test_return_value = TET_UNDEF;
33 }
34
35 void scene_view_cleanup(void)
36 {
37   test_return_value = TET_PASS;
38 }
39
40 namespace
41 {
42 /**
43  * For the AnimatedCube.gltf and its Assets
44  * Donated by Norbert Nopper for glTF testing.
45  * Take from https://github.com/KhronosGroup/glTF-Sample-Models/tree/master/2.0/AnimatedCube
46  */
47 const char* TEST_GLTF_FILE_NAME = TEST_RESOURCE_DIR "/AnimatedCube.gltf";
48
49 /**
50  * For the diffuse and specular cube map texture.
51  * These textures are based off version of Wave engine sample
52  * Take from https://github.com/WaveEngine/Samples
53  *
54  * Copyright (c) 2023 Wave Coorporation
55  *
56  * Permission is hereby granted, free of charge, to any person obtaining a copy
57  * of this software and associated documentation files (the "Software"), to
58  * deal in the Software without restriction, including without limitation the
59  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
60  * sell copies of the Software, and to permit persons to whom the Software is
61  * furnished to do so, subject to the following conditions:
62  *
63  * The above copyright notice and this permission notice shall be included in
64  * all copies or substantial portions of the Software.
65  *
66  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
67  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
68  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
69  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
70  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
71  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
72  * THE SOFTWARE.
73  */
74 const char* TEST_EQUIRECTANGULAR_TEXTURE = TEST_RESOURCE_DIR "/application-icon-20.png";
75 const char* TEST_DIFFUSE_TEXTURE         = TEST_RESOURCE_DIR "/forest_irradiance.ktx";
76 const char* TEST_SPECULAR_TEXTURE        = TEST_RESOURCE_DIR "/forest_radiance.ktx";
77 const char* TEST_DIFFUSE_TEXTURE2        = TEST_RESOURCE_DIR "//forest_irradiance.ktx";
78 const char* TEST_SPECULAR_TEXTURE2       = TEST_RESOURCE_DIR "//forest_radiance.ktx";
79
80 Dali::Texture GetDiffuseTexture(Dali::Scene3D::Model model)
81 {
82   Dali::Texture texture;
83
84   Actor meshActor = model.FindChildByName("AnimatedCube");
85   if(meshActor)
86   {
87     Renderer renderer = meshActor.GetRendererAt(0u);
88     if(renderer)
89     {
90       TextureSet textureSet = renderer.GetTextures();
91       if(textureSet.GetTextureCount() == 9u)
92       {
93         texture = textureSet.GetTexture(7u);
94       }
95     }
96   }
97
98   return texture;
99 }
100
101 Dali::Texture GetSpecularTexture(Dali::Scene3D::Model model)
102 {
103   Dali::Texture texture;
104
105   Actor meshActor = model.FindChildByName("AnimatedCube");
106   if(meshActor)
107   {
108     Renderer renderer = meshActor.GetRendererAt(0u);
109     if(renderer)
110     {
111       TextureSet textureSet = renderer.GetTextures();
112       if(textureSet.GetTextureCount() == 9u)
113       {
114         texture = textureSet.GetTexture(8u);
115       }
116     }
117   }
118
119   return texture;
120 }
121
122 // For ResourceReady
123 static bool gOnRelayoutCallBackCalled = false;
124 void        OnRelayoutCallback(Actor actor)
125 {
126   gOnRelayoutCallBackCalled = true;
127 }
128
129 static bool gResourceReadyCalled = false;
130 void        OnResourceReady(Control control)
131 {
132   gResourceReadyCalled = true;
133 }
134 } // namespace
135
136 // Negative test case for a method
137 int UtcDaliSceneViewUninitialized(void)
138 {
139   ToolkitTestApplication application;
140   tet_infoline("UtcDaliSceneViewUninitialized");
141
142   Scene3D::SceneView view;
143
144   try
145   {
146     // New() must be called to create a Model or it wont be valid.
147     Actor a = Actor::New();
148     view.Add(a);
149     DALI_TEST_CHECK(false);
150   }
151   catch(Dali::DaliException& e)
152   {
153     // Tests that a negative test of an assertion succeeds
154     DALI_TEST_PRINT_ASSERT(e);
155     DALI_TEST_CHECK(!view);
156   }
157   END_TEST;
158 }
159
160 // Positive test case for a method
161 int UtcDaliSceneViewNew(void)
162 {
163   ToolkitTestApplication application;
164   tet_infoline("UtcDaliSceneViewNew");
165
166   Scene3D::SceneView view = Scene3D::SceneView::New();
167   DALI_TEST_CHECK(view);
168   END_TEST;
169 }
170
171 // Positive test case for a method
172 int UtcDaliSceneViewDownCast(void)
173 {
174   ToolkitTestApplication application;
175   tet_infoline("UtcDaliSceneViewDownCast");
176
177   Scene3D::SceneView view = Scene3D::SceneView::New();
178   BaseHandle         handle(view);
179
180   Scene3D::SceneView sceneView = Scene3D::SceneView::DownCast(handle);
181   DALI_TEST_CHECK(view);
182   DALI_TEST_CHECK(sceneView);
183   DALI_TEST_CHECK(sceneView == view);
184   END_TEST;
185 }
186
187 int UtcDaliSceneViewTypeRegistry(void)
188 {
189   ToolkitTestApplication application;
190   tet_infoline("UtcDaliSceneViewTypeRegistry");
191
192   TypeRegistry typeRegistry = TypeRegistry::Get();
193   DALI_TEST_CHECK(typeRegistry);
194
195   TypeInfo typeInfo = typeRegistry.GetTypeInfo("SceneView");
196   DALI_TEST_CHECK(typeInfo);
197
198   BaseHandle handle = typeInfo.CreateInstance();
199   DALI_TEST_CHECK(handle);
200
201   Scene3D::SceneView model = Scene3D::SceneView::DownCast(handle);
202   DALI_TEST_CHECK(model);
203
204   END_TEST;
205 }
206
207 // Positive test case for a method
208 int UtcDaliSceneViewAddRemove(void)
209 {
210   ToolkitTestApplication application;
211   tet_infoline("UtcDaliSceneViewAddRemove");
212
213   Scene3D::SceneView view = Scene3D::SceneView::New();
214   DALI_TEST_CHECK(view);
215   DALI_TEST_EQUALS(1u, view.GetChildCount(), TEST_LOCATION);
216
217   Actor actor = Actor::New();
218
219   view.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
220   view.SetProperty(Actor::Property::SIZE, application.GetScene().GetSize());
221   view.Add(actor);
222
223   DALI_TEST_EQUALS(1u, view.GetChildCount(), TEST_LOCATION);
224   Actor layer = view.GetChildAt(0u);
225
226   DALI_TEST_EQUALS(2u, layer.GetChildCount(), TEST_LOCATION);
227   DALI_TEST_EQUALS(actor, layer.GetChildAt(1u), TEST_LOCATION); // index 0u is default camera
228
229   view.Remove(actor);
230   DALI_TEST_EQUALS(1u, layer.GetChildCount(), TEST_LOCATION);
231   END_TEST;
232 }
233
234 int UtcDaliSceneViewCopyAndAssignment(void)
235 {
236   ToolkitTestApplication application;
237
238   Scene3D::SceneView view = Scene3D::SceneView::New();
239   DALI_TEST_CHECK(view);
240
241   Scene3D::SceneView copy(view);
242   DALI_TEST_CHECK(view == copy);
243
244   Scene3D::SceneView assign;
245   DALI_TEST_CHECK(!assign);
246
247   assign = copy;
248   DALI_TEST_CHECK(assign == view);
249
250   END_TEST;
251 }
252
253 int UtcDaliSceneViewMoveConstructor(void)
254 {
255   ToolkitTestApplication application;
256
257   Scene3D::SceneView view = Scene3D::SceneView::New();
258   DALI_TEST_EQUALS(1, view.GetBaseObject().ReferenceCount(), TEST_LOCATION);
259   view.SetProperty(Actor::Property::SENSITIVE, false);
260   DALI_TEST_CHECK(false == view.GetProperty<bool>(Actor::Property::SENSITIVE));
261
262   Scene3D::SceneView moved = std::move(view);
263   DALI_TEST_CHECK(moved);
264   DALI_TEST_EQUALS(1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION);
265   DALI_TEST_CHECK(false == moved.GetProperty<bool>(Actor::Property::SENSITIVE));
266   DALI_TEST_CHECK(!view);
267
268   END_TEST;
269 }
270
271 int UtcDaliSceneViewMoveAssignment(void)
272 {
273   ToolkitTestApplication application;
274
275   Scene3D::SceneView view = Scene3D::SceneView::New();
276   DALI_TEST_EQUALS(1, view.GetBaseObject().ReferenceCount(), TEST_LOCATION);
277   view.SetProperty(Actor::Property::SENSITIVE, false);
278   DALI_TEST_CHECK(false == view.GetProperty<bool>(Actor::Property::SENSITIVE));
279
280   Scene3D::SceneView moved;
281   moved = std::move(view);
282   DALI_TEST_CHECK(moved);
283   DALI_TEST_EQUALS(1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION);
284   DALI_TEST_CHECK(false == moved.GetProperty<bool>(Actor::Property::SENSITIVE));
285   DALI_TEST_CHECK(!view);
286
287   END_TEST;
288 }
289
290 int UtcDaliSceneViewOnScene01(void)
291 {
292   ToolkitTestApplication application;
293
294   Scene3D::SceneView view = Scene3D::SceneView::New();
295
296   DALI_TEST_EQUALS(1u, view.GetChildCount(), TEST_LOCATION);
297   Actor layer = view.GetChildAt(0u);
298
299   DALI_TEST_EQUALS(1u, layer.GetChildCount(), TEST_LOCATION);
300
301   application.GetScene().Add(view);
302
303   application.SendNotification();
304   application.Render();
305
306   // CameraActor is added on layer when on scene
307   DALI_TEST_EQUALS(1u, layer.GetChildCount(), TEST_LOCATION);
308
309   END_TEST;
310 }
311
312 int UtcDaliSceneViewOnScene02(void)
313 {
314   ToolkitTestApplication application;
315
316   uint32_t renderTaskCount = application.GetScene().GetRenderTaskList().GetTaskCount();
317   DALI_TEST_EQUALS(1u, renderTaskCount, TEST_LOCATION);
318
319   Scene3D::SceneView view = Scene3D::SceneView::New();
320
321   renderTaskCount = application.GetScene().GetRenderTaskList().GetTaskCount();
322   DALI_TEST_EQUALS(1u, renderTaskCount, TEST_LOCATION);
323
324   application.GetScene().Add(view);
325
326   application.SendNotification();
327   application.Render();
328
329   renderTaskCount = application.GetScene().GetRenderTaskList().GetTaskCount();
330   DALI_TEST_EQUALS(2u, renderTaskCount, TEST_LOCATION);
331
332   RenderTask  renderTask = application.GetScene().GetRenderTaskList().GetTask(1u);
333   CameraActor camera     = renderTask.GetCameraActor();
334
335   CameraActor defaultCamera = renderTask.GetCameraActor();
336   DALI_TEST_CHECK(defaultCamera);
337   DALI_TEST_EQUALS(camera, defaultCamera, TEST_LOCATION);
338   DALI_TEST_EQUALS(defaultCamera, view.GetSelectedCamera(), TEST_LOCATION);
339
340   END_TEST;
341 }
342
343 int UtcDaliSceneViewUserCamera(void)
344 {
345   ToolkitTestApplication application;
346
347   Scene3D::SceneView view = Scene3D::SceneView::New();
348   view.SetProperty(Dali::Actor::Property::SIZE, Vector2(100, 100));
349
350   application.GetScene().Add(view);
351
352   application.SendNotification();
353   application.Render();
354
355   CameraActor defaultCamera = view.GetSelectedCamera();
356   CameraActor camera        = Dali::CameraActor::New();
357   camera.SetProperty(Dali::Actor::Property::NAME, "camera");
358   view.AddCamera(camera);
359   view.SelectCamera("camera");
360
361   DALI_TEST_NOT_EQUALS(defaultCamera, view.GetSelectedCamera(), 0.0f, TEST_LOCATION);
362   DALI_TEST_EQUALS(camera, view.GetSelectedCamera(), TEST_LOCATION);
363
364   camera.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
365   camera.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
366   camera.SetFieldOfView(0.5f);
367   camera.SetNearClippingPlane(1.0f);
368   camera.SetFarClippingPlane(5000.0f);
369   camera.SetProperty(Dali::Actor::Property::POSITION, Vector3(20, 30, 40));
370
371   float   fov            = camera[Dali::CameraActor::Property::FIELD_OF_VIEW];
372   float   nearPlain      = camera[Dali::CameraActor::Property::NEAR_PLANE_DISTANCE];
373   float   farPlain       = camera[Dali::CameraActor::Property::FAR_PLANE_DISTANCE];
374   Vector3 cameraPosition = camera[Dali::Actor::Property::POSITION];
375
376   view.SetProperty(Dali::Actor::Property::SIZE, Vector2(400, 300));
377
378   DALI_TEST_EQUALS(fov, camera.GetProperty<float>(Dali::CameraActor::Property::FIELD_OF_VIEW), TEST_LOCATION);
379   DALI_TEST_EQUALS(nearPlain, camera.GetProperty<float>(Dali::CameraActor::Property::NEAR_PLANE_DISTANCE), TEST_LOCATION);
380   DALI_TEST_EQUALS(farPlain, camera.GetProperty<float>(Dali::CameraActor::Property::FAR_PLANE_DISTANCE), TEST_LOCATION);
381   DALI_TEST_EQUALS(cameraPosition, camera.GetProperty<Vector3>(Dali::Actor::Property::POSITION), TEST_LOCATION);
382
383   END_TEST;
384 }
385
386 int UtcDaliSceneViewAddRemoveCamera(void)
387 {
388   ToolkitTestApplication application;
389
390   Scene3D::SceneView view = Scene3D::SceneView::New();
391   view.SetProperty(Dali::Actor::Property::SIZE, Vector2(100, 100));
392
393   application.GetScene().Add(view);
394
395   application.SendNotification();
396   application.Render();
397
398   CameraActor camera0 = view.GetSelectedCamera();
399   camera0.SetProperty(Dali::Actor::Property::NAME, "camera0");
400   CameraActor camera1 = Dali::CameraActor::New();
401   camera1.SetProperty(Dali::Actor::Property::NAME, "camera1");
402
403   DALI_TEST_EQUALS(1u, view.GetCameraCount(), TEST_LOCATION);
404   view.AddCamera(camera1);
405   DALI_TEST_EQUALS(2u, view.GetCameraCount(), TEST_LOCATION);
406
407   DALI_TEST_EQUALS(camera0, view.GetCamera(0), TEST_LOCATION);
408   DALI_TEST_EQUALS(camera0, view.GetCamera("camera0"), TEST_LOCATION);
409   DALI_TEST_EQUALS(camera1, view.GetCamera(1), TEST_LOCATION);
410   DALI_TEST_EQUALS(camera1, view.GetCamera("camera1"), TEST_LOCATION);
411
412   DALI_TEST_EQUALS(camera0, view.GetSelectedCamera(), TEST_LOCATION);
413   view.SelectCamera(1); // 0 -> 1
414   DALI_TEST_EQUALS(camera1, view.GetSelectedCamera(), TEST_LOCATION);
415   view.SelectCamera("camera0"); // 1 -> 0
416   DALI_TEST_EQUALS(camera0, view.GetSelectedCamera(), TEST_LOCATION);
417   view.SelectCamera("camera1"); // 0 -> 1
418   DALI_TEST_EQUALS(camera1, view.GetSelectedCamera(), TEST_LOCATION);
419   view.SelectCamera(0); // 1 -> 0
420   DALI_TEST_EQUALS(camera0, view.GetSelectedCamera(), TEST_LOCATION);
421
422   view.SelectCamera(1); // 0 -> 1
423   DALI_TEST_EQUALS(camera1, view.GetSelectedCamera(), TEST_LOCATION);
424   DALI_TEST_EQUALS(2u, view.GetCameraCount(), TEST_LOCATION);
425   view.RemoveCamera(camera1); // 1 -> 0
426   DALI_TEST_EQUALS(camera0, view.GetSelectedCamera(), TEST_LOCATION);
427   DALI_TEST_EQUALS(1u, view.GetCameraCount(), TEST_LOCATION);
428
429   CameraActor defaultCamera = view.GetSelectedCamera();
430   DALI_TEST_CHECK(defaultCamera);
431   DALI_TEST_EQUALS(camera0, defaultCamera, TEST_LOCATION);
432   DALI_TEST_NOT_EQUALS(camera1, defaultCamera, 0.0f, TEST_LOCATION);
433   END_TEST;
434 }
435
436 int UtcDaliSceneViewImageBasedLight01(void)
437 {
438   ToolkitTestApplication application;
439
440   Scene3D::SceneView view = Scene3D::SceneView::New();
441   view.ResourceReadySignal().Connect(OnResourceReady);
442   view.SetProperty(Dali::Actor::Property::SIZE, Vector2(100, 100));
443
444   application.GetScene().Add(view);
445
446   application.SendNotification();
447   application.Render();
448
449   Scene3D::Model modelView1 = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
450   Scene3D::Model modelView2 = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
451   Scene3D::Model modelView3 = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
452   view.Add(modelView1);
453   view.Add(modelView2);
454
455   application.SendNotification();
456   application.Render();
457   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
458   application.SendNotification();
459   application.Render();
460
461   DALI_TEST_EQUALS(GetDiffuseTexture(modelView1), GetDiffuseTexture(modelView2), TEST_LOCATION);
462   DALI_TEST_EQUALS(GetSpecularTexture(modelView1), GetSpecularTexture(modelView2), TEST_LOCATION);
463   DALI_TEST_NOT_EQUALS(GetDiffuseTexture(modelView1), GetDiffuseTexture(modelView3), 0.0f, TEST_LOCATION);
464   DALI_TEST_NOT_EQUALS(GetSpecularTexture(modelView1), GetSpecularTexture(modelView3), 0.0f, TEST_LOCATION);
465
466   gResourceReadyCalled = false;
467   DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
468   view.SetImageBasedLightSource(TEST_DIFFUSE_TEXTURE, TEST_SPECULAR_TEXTURE);
469
470   application.SendNotification();
471   application.Render();
472
473   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
474   application.SendNotification();
475   application.Render();
476
477   DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
478
479   DALI_TEST_EQUALS(GetDiffuseTexture(modelView1), GetDiffuseTexture(modelView2), TEST_LOCATION);
480   DALI_TEST_EQUALS(GetSpecularTexture(modelView1), GetSpecularTexture(modelView2), TEST_LOCATION);
481   DALI_TEST_NOT_EQUALS(GetDiffuseTexture(modelView1), GetDiffuseTexture(modelView3), 0.0f, TEST_LOCATION);
482   DALI_TEST_NOT_EQUALS(GetSpecularTexture(modelView1), GetSpecularTexture(modelView3), 0.0f, TEST_LOCATION);
483
484   view.Add(modelView3);
485   application.SendNotification();
486   application.Render();
487   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
488   application.SendNotification();
489   application.Render();
490
491   DALI_TEST_EQUALS(GetDiffuseTexture(modelView1), GetDiffuseTexture(modelView3), TEST_LOCATION);
492   DALI_TEST_EQUALS(GetSpecularTexture(modelView1), GetSpecularTexture(modelView3), TEST_LOCATION);
493
494   view.Remove(modelView1);
495
496   gResourceReadyCalled = false;
497   DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
498   view.SetImageBasedLightSource(TEST_DIFFUSE_TEXTURE2, TEST_SPECULAR_TEXTURE2);
499
500   application.SendNotification();
501   application.Render();
502
503   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
504   application.SendNotification();
505   application.Render();
506
507   DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
508
509   DALI_TEST_NOT_EQUALS(GetDiffuseTexture(modelView1), GetDiffuseTexture(modelView2), 0.0f, TEST_LOCATION);
510   DALI_TEST_NOT_EQUALS(GetSpecularTexture(modelView1), GetSpecularTexture(modelView2), 0.0f, TEST_LOCATION);
511   DALI_TEST_NOT_EQUALS(GetDiffuseTexture(modelView1), GetDiffuseTexture(modelView3), 0.0f, TEST_LOCATION);
512   DALI_TEST_NOT_EQUALS(GetSpecularTexture(modelView1), GetSpecularTexture(modelView3), 0.0f, TEST_LOCATION);
513   DALI_TEST_EQUALS(GetDiffuseTexture(modelView2), GetDiffuseTexture(modelView3), TEST_LOCATION);
514   DALI_TEST_EQUALS(GetSpecularTexture(modelView2), GetSpecularTexture(modelView3), TEST_LOCATION);
515
516   END_TEST;
517 }
518
519 int UtcDaliSceneViewImageBasedLight02(void)
520 {
521   ToolkitTestApplication application;
522
523   Scene3D::SceneView view = Scene3D::SceneView::New();
524   view.ResourceReadySignal().Connect(OnResourceReady);
525   view.SetProperty(Dali::Actor::Property::SIZE, Vector2(100, 100));
526
527   application.GetScene().Add(view);
528
529   application.SendNotification();
530   application.Render();
531
532   Scene3D::Model modelView1 = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
533   modelView1.ResourceReadySignal().Connect(OnResourceReady);
534   view.Add(modelView1);
535   application.SendNotification();
536   application.Render();
537   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
538   application.SendNotification();
539   application.Render();
540
541   gResourceReadyCalled = false;
542   DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
543   view.SetImageBasedLightSource(TEST_DIFFUSE_TEXTURE, TEST_SPECULAR_TEXTURE);
544
545   application.SendNotification();
546   application.Render();
547
548   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
549   application.SendNotification();
550   application.Render();
551
552   DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
553
554   Dali::Texture diffuseTexture  = GetDiffuseTexture(modelView1);
555   Dali::Texture specularTexture = GetSpecularTexture(modelView1);
556
557   gResourceReadyCalled = false;
558   DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
559   modelView1.SetImageBasedLightSource(TEST_DIFFUSE_TEXTURE2, TEST_SPECULAR_TEXTURE2);
560
561   application.SendNotification();
562   application.Render();
563
564   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
565   application.SendNotification();
566   application.Render();
567
568   DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
569
570   DALI_TEST_NOT_EQUALS(GetDiffuseTexture(modelView1), diffuseTexture, 0.0f, TEST_LOCATION);
571   DALI_TEST_NOT_EQUALS(GetSpecularTexture(modelView1), specularTexture, 0.0f, TEST_LOCATION);
572   diffuseTexture  = GetDiffuseTexture(modelView1);
573   specularTexture = GetSpecularTexture(modelView1);
574
575   // reset SceneView IBL
576   view.SetImageBasedLightSource("", "");
577   DALI_TEST_EQUALS(GetDiffuseTexture(modelView1), diffuseTexture, TEST_LOCATION);
578   DALI_TEST_EQUALS(GetSpecularTexture(modelView1), specularTexture, TEST_LOCATION);
579
580   modelView1.SetImageBasedLightSource("", "");
581   DALI_TEST_NOT_EQUALS(GetDiffuseTexture(modelView1), diffuseTexture, 0.0f, TEST_LOCATION);
582   DALI_TEST_NOT_EQUALS(GetSpecularTexture(modelView1), specularTexture, 0.0f, TEST_LOCATION);
583
584   END_TEST;
585 }
586
587 int UtcDaliSceneViewImageBasedLight03(void)
588 {
589   ToolkitTestApplication application;
590
591   Scene3D::SceneView view = Scene3D::SceneView::New();
592   view.SetProperty(Dali::Actor::Property::SIZE, Vector2(100, 100));
593   view.ResourceReadySignal().Connect(OnResourceReady);
594   application.GetScene().Add(view);
595
596   application.SendNotification();
597   application.Render();
598
599   Scene3D::Model modelView1 = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
600   view.Add(modelView1);
601   modelView1.SetImageBasedLightSource(TEST_SPECULAR_TEXTURE, TEST_DIFFUSE_TEXTURE);
602
603   application.SendNotification();
604   application.Render();
605   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
606   application.SendNotification();
607   application.Render();
608
609   Dali::Texture diffuseTexture  = GetDiffuseTexture(modelView1);
610   Dali::Texture specularTexture = GetSpecularTexture(modelView1);
611
612   gResourceReadyCalled = false;
613   DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
614   view.SetImageBasedLightSource(TEST_DIFFUSE_TEXTURE2, TEST_SPECULAR_TEXTURE2);
615
616   application.SendNotification();
617   application.Render();
618   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
619   application.SendNotification();
620   application.Render();
621
622   DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
623
624   DALI_TEST_EQUALS(GetDiffuseTexture(modelView1), diffuseTexture, TEST_LOCATION);
625   DALI_TEST_EQUALS(GetSpecularTexture(modelView1), specularTexture, TEST_LOCATION);
626
627   modelView1.SetImageBasedLightSource("", "");
628   DALI_TEST_NOT_EQUALS(GetDiffuseTexture(modelView1), diffuseTexture, 0.0f, TEST_LOCATION);
629   DALI_TEST_NOT_EQUALS(GetSpecularTexture(modelView1), specularTexture, 0.0f, TEST_LOCATION);
630   diffuseTexture  = GetDiffuseTexture(modelView1);
631   specularTexture = GetSpecularTexture(modelView1);
632
633   // reset SceneView IBL
634   view.SetImageBasedLightSource("", "");
635   DALI_TEST_NOT_EQUALS(GetDiffuseTexture(modelView1), diffuseTexture, 0.0f, TEST_LOCATION);
636   DALI_TEST_NOT_EQUALS(GetSpecularTexture(modelView1), specularTexture, 0.0f, TEST_LOCATION);
637
638   END_TEST;
639 }
640
641 int UtcDaliSceneViewImageBasedFactor(void)
642 {
643   ToolkitTestApplication application;
644
645   Scene3D::SceneView view = Scene3D::SceneView::New();
646   view.SetProperty(Dali::Actor::Property::SIZE, Vector2(100, 100));
647
648   application.GetScene().Add(view);
649
650   application.SendNotification();
651   application.Render();
652
653   Scene3D::Model modelView1 = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
654   view.Add(modelView1);
655
656   DALI_TEST_EQUALS(view.GetImageBasedLightScaleFactor(), 1.0f, TEST_LOCATION);
657   DALI_TEST_EQUALS(modelView1.GetImageBasedLightScaleFactor(), 1.0f, TEST_LOCATION);
658
659   view.SetImageBasedLightScaleFactor(0.5f);
660   DALI_TEST_EQUALS(view.GetImageBasedLightScaleFactor(), 0.5f, TEST_LOCATION);
661   DALI_TEST_EQUALS(modelView1.GetImageBasedLightScaleFactor(), 1.0f, TEST_LOCATION);
662   END_TEST;
663 }
664
665 int UtcDaliSceneViewUseFramebuffer01(void)
666 {
667   ToolkitTestApplication application;
668
669   Scene3D::SceneView view = Scene3D::SceneView::New();
670   view.SetProperty(Dali::Actor::Property::SIZE, Vector2(100, 100));
671
672   application.GetScene().Add(view);
673
674   application.SendNotification();
675   application.Render();
676
677   bool useFramebuffer = view.IsUsingFramebuffer();
678   view.UseFramebuffer(true);
679   DALI_TEST_NOT_EQUALS(useFramebuffer, view.IsUsingFramebuffer(), 0.0f, TEST_LOCATION);
680
681   END_TEST;
682 }
683
684 int UtcDaliSceneViewUseFramebuffer02(void)
685 {
686   ToolkitTestApplication application;
687
688   Scene3D::SceneView view = Scene3D::SceneView::New();
689   view.SetProperty(Dali::Actor::Property::SIZE, Vector2(100, 100));
690
691   application.GetScene().Add(view);
692
693   application.SendNotification();
694   application.Render();
695
696   RenderTask renderTask = application.GetScene().GetRenderTaskList().GetTask(1u);
697   DALI_TEST_CHECK(!renderTask.GetFrameBuffer());
698
699   view.UseFramebuffer(true);
700   DALI_TEST_CHECK(renderTask.GetFrameBuffer());
701
702   view.UseFramebuffer(false);
703   DALI_TEST_CHECK(!renderTask.GetFrameBuffer());
704
705   view.UseFramebuffer(true);
706   DALI_TEST_CHECK(renderTask.GetFrameBuffer());
707
708   END_TEST;
709 }
710
711 int UtcDaliSceneViewFramebufferMultiSamplingLevel(void)
712 {
713   ToolkitTestApplication application;
714
715   Scene3D::SceneView view = Scene3D::SceneView::New();
716   view.SetProperty(Dali::Actor::Property::SIZE, Vector2(100, 100));
717
718   application.GetScene().Add(view);
719
720   application.SendNotification();
721   application.Render();
722
723   uint8_t expectValue        = 0u; // Default MultiSamplingLevel is 0.
724   uint8_t multiSamplingLevel = view.GetFramebufferMultiSamplingLevel();
725   DALI_TEST_EQUALS(multiSamplingLevel, expectValue, TEST_LOCATION);
726
727   expectValue = 4u; // Change value.
728   view.UseFramebuffer(true);
729   view.SetFramebufferMultiSamplingLevel(expectValue);
730
731   multiSamplingLevel = view.GetFramebufferMultiSamplingLevel();
732   DALI_TEST_EQUALS(multiSamplingLevel, expectValue, TEST_LOCATION);
733
734   // Note : we don't check multi sampling level is applied to framebuffer, or not.
735   view.UseFramebuffer(false);
736   expectValue = 2u; // Change value.
737   view.SetFramebufferMultiSamplingLevel(expectValue);
738
739   application.SendNotification();
740   application.Render();
741
742   multiSamplingLevel = view.GetFramebufferMultiSamplingLevel();
743   DALI_TEST_EQUALS(multiSamplingLevel, expectValue, TEST_LOCATION);
744
745   END_TEST;
746 }
747
748 int UtcDaliSceneViewResourceReady(void)
749 {
750   ToolkitTestApplication application;
751
752   gOnRelayoutCallBackCalled = false;
753   gResourceReadyCalled      = false;
754   Scene3D::SceneView view   = Scene3D::SceneView::New();
755   view.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
756   view.OnRelayoutSignal().Connect(OnRelayoutCallback);
757   view.ResourceReadySignal().Connect(OnResourceReady);
758   // SceneView::IsResourceReady() returns true by default.
759   DALI_TEST_EQUALS(view.IsResourceReady(), true, TEST_LOCATION);
760
761   // Sanity check
762   DALI_TEST_CHECK(!gOnRelayoutCallBackCalled);
763   DALI_TEST_CHECK(!gResourceReadyCalled);
764
765   application.GetScene().Add(view);
766
767   application.SendNotification();
768   application.Render();
769
770   DALI_TEST_EQUALS(gOnRelayoutCallBackCalled, true, TEST_LOCATION);
771   DALI_TEST_EQUALS(view.IsResourceReady(), true, TEST_LOCATION);
772   DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
773
774   gOnRelayoutCallBackCalled = false;
775   gResourceReadyCalled      = false;
776
777   view.SetImageBasedLightSource(TEST_DIFFUSE_TEXTURE, TEST_SPECULAR_TEXTURE);
778
779   application.SendNotification();
780   application.Render();
781   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
782   application.SendNotification();
783   application.Render();
784
785   DALI_TEST_EQUALS(gOnRelayoutCallBackCalled, false, TEST_LOCATION);
786   DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
787
788   END_TEST;
789 }
790
791 int UtcDaliSceneViewSetSkybox(void)
792 {
793   ToolkitTestApplication application;
794
795   gResourceReadyCalled    = false;
796   Scene3D::SceneView view = Scene3D::SceneView::New();
797   view.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
798   view.ResourceReadySignal().Connect(OnResourceReady);
799   application.GetScene().Add(view);
800
801   application.SendNotification();
802   application.Render();
803
804   uint32_t childCount = view.GetChildAt(0u).GetChildCount();
805   view.SetSkybox(TEST_SPECULAR_TEXTURE);
806
807   gResourceReadyCalled = false;
808   DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
809
810   application.SendNotification();
811   application.Render();
812   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
813   application.SendNotification();
814   application.Render();
815
816   DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
817
818   DALI_TEST_EQUALS(view.GetChildAt(0u).GetChildCount(), childCount + 1, TEST_LOCATION);
819
820   view.Unparent();
821   view.Reset();
822
823   END_TEST;
824 }
825
826 int UtcDaliSceneViewSetSkyboxEquirectangular(void)
827 {
828   ToolkitTestApplication application;
829
830   gResourceReadyCalled    = false;
831   Scene3D::SceneView view = Scene3D::SceneView::New();
832   view.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
833   view.ResourceReadySignal().Connect(OnResourceReady);
834   application.GetScene().Add(view);
835
836   application.SendNotification();
837   application.Render();
838
839   uint32_t childCount = view.GetChildAt(0u).GetChildCount();
840   view.SetSkyboxEnvironmentMapType(Scene3D::EnvironmentMapType::EQUIRECTANGULAR);
841   view.SetSkybox(TEST_EQUIRECTANGULAR_TEXTURE);
842
843   gResourceReadyCalled = false;
844   DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
845
846   application.SendNotification();
847   application.Render();
848   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
849   application.SendNotification();
850   application.Render();
851
852   DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
853
854   DALI_TEST_EQUALS(view.GetChildAt(0u).GetChildCount(), childCount + 1, TEST_LOCATION);
855
856   view.Unparent();
857   view.Reset();
858
859   END_TEST;
860 }
861
862 int UtcDaliSceneViewSetSkyboxEmpty(void)
863 {
864   ToolkitTestApplication application;
865
866   gResourceReadyCalled    = false;
867   Scene3D::SceneView view = Scene3D::SceneView::New();
868   view.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
869   view.ResourceReadySignal().Connect(OnResourceReady);
870   application.GetScene().Add(view);
871
872   application.SendNotification();
873   application.Render();
874
875   uint32_t childCount = view.GetChildAt(0u).GetChildCount();
876   view.SetSkybox("");
877   DALI_TEST_EQUALS(view.GetChildAt(0u).GetChildCount(), childCount, TEST_LOCATION);
878
879   view.Unparent();
880   view.Reset();
881
882   END_TEST;
883 }
884
885 int UtcDaliSceneViewSetSkyboxEquirectangularEmpty(void)
886 {
887   ToolkitTestApplication application;
888
889   gResourceReadyCalled    = false;
890   Scene3D::SceneView view = Scene3D::SceneView::New();
891   view.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
892   view.ResourceReadySignal().Connect(OnResourceReady);
893   application.GetScene().Add(view);
894
895   application.SendNotification();
896   application.Render();
897
898   uint32_t childCount = view.GetChildAt(0u).GetChildCount();
899   view.SetSkybox("");
900   DALI_TEST_EQUALS(view.GetChildAt(0u).GetChildCount(), childCount, TEST_LOCATION);
901
902   view.Unparent();
903   view.Reset();
904
905   END_TEST;
906 }
907
908 int UtcDaliSceneViewSetSkyboxIntensity(void)
909 {
910   ToolkitTestApplication application;
911
912   Scene3D::SceneView view = Scene3D::SceneView::New();
913   view.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
914
915   float intensity = 0.5f;
916   DALI_TEST_EQUALS(view.GetSkyboxIntensity(), 1.0f, TEST_LOCATION);
917
918   view.SetSkyboxIntensity(intensity);
919   DALI_TEST_EQUALS(view.GetSkyboxIntensity(), intensity, TEST_LOCATION);
920
921   END_TEST;
922 }
923
924 int UtcDaliSceneViewSetSkyboxOrientation(void)
925 {
926   ToolkitTestApplication application;
927
928   Scene3D::SceneView view = Scene3D::SceneView::New();
929   view.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
930
931   Dali::Quaternion orientation = Dali::Quaternion(Radian(0.5f), Vector3::YAXIS);
932   view.SetSkyboxOrientation(orientation);
933   DALI_TEST_EQUALS(view.GetSkyboxOrientation(), orientation, TEST_LOCATION);
934
935   END_TEST;
936 }
937
938 int UtcDaliSceneViewSetImageBasedLightAndSkybox(void)
939 {
940   ToolkitTestApplication application;
941
942   Scene3D::SceneView view = Scene3D::SceneView::New();
943   view.ResourceReadySignal().Connect(OnResourceReady);
944   view.SetProperty(Dali::Actor::Property::SIZE, Vector2(100, 100));
945   view.SetImageBasedLightSource(TEST_DIFFUSE_TEXTURE, TEST_SPECULAR_TEXTURE);
946   view.SetSkybox(TEST_SPECULAR_TEXTURE);
947   application.GetScene().Add(view);
948
949   // Check SceneView needs 3 trigger to load both of image based light and skybox.
950   gResourceReadyCalled = false;
951   DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
952   application.SendNotification();
953   application.Render();
954   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
955   application.SendNotification();
956   application.Render();
957   DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
958
959   END_TEST;
960 }
961
962 int UtcDaliSceneViewCreateAndRemoveRenderTask(void)
963 {
964   ToolkitTestApplication application;
965   RenderTaskList         taskList = application.GetScene().GetRenderTaskList();
966
967   uint32_t renderTaskCount = taskList.GetTaskCount();
968
969   Scene3D::SceneView view = Scene3D::SceneView::New();
970   view.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
971
972   DALI_TEST_EQUALS(renderTaskCount, application.GetScene().GetRenderTaskList().GetTaskCount(), TEST_LOCATION);
973
974   application.GetScene().Add(view);
975
976   DALI_TEST_EQUALS(renderTaskCount + 1, application.GetScene().GetRenderTaskList().GetTaskCount(), TEST_LOCATION);
977
978   view.Unparent();
979
980   DALI_TEST_EQUALS(renderTaskCount, application.GetScene().GetRenderTaskList().GetTaskCount(), TEST_LOCATION);
981
982   END_TEST;
983 }
984
985 int UtcDaliSceneViewColorMode(void)
986 {
987   ToolkitTestApplication application;
988
989   Scene3D::SceneView view = Scene3D::SceneView::New();
990   application.GetScene().Add(view);
991
992   DALI_TEST_EQUALS(view.GetChildAt(0u).GetProperty<int>(Dali::Actor::Property::COLOR_MODE), static_cast<int>(ColorMode::USE_OWN_MULTIPLY_PARENT_ALPHA), TEST_LOCATION);
993
994   view.UseFramebuffer(true);
995
996   DALI_TEST_EQUALS(view.GetChildAt(0u).GetProperty<int>(Dali::Actor::Property::COLOR_MODE), static_cast<int>(ColorMode::USE_OWN_COLOR), TEST_LOCATION);
997
998   view.UseFramebuffer(false);
999
1000   DALI_TEST_EQUALS(view.GetChildAt(0u).GetProperty<int>(Dali::Actor::Property::COLOR_MODE), static_cast<int>(ColorMode::USE_OWN_MULTIPLY_PARENT_ALPHA), TEST_LOCATION);
1001
1002   END_TEST;
1003 }