Asynchronous loading of Scene3D resources
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-scene3d / utc-Dali-SceneView.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
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) 2022 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
123 // For ResourceReady
124 static bool gOnRelayoutCallBackCalled = false;
125 void OnRelayoutCallback(Actor actor)
126 {
127   gOnRelayoutCallBackCalled = true;
128 }
129
130 static bool gResourceReadyCalled = false;
131 void OnResourceReady(Control control)
132 {
133   gResourceReadyCalled = true;
134 }
135 } // namespace
136
137 // Negative test case for a method
138 int UtcDaliSceneViewUninitialized(void)
139 {
140   ToolkitTestApplication application;
141   tet_infoline("UtcDaliSceneViewUninitialized");
142
143   Scene3D::SceneView view;
144
145   try
146   {
147     // New() must be called to create a Model or it wont be valid.
148     Actor a = Actor::New();
149     view.Add(a);
150     DALI_TEST_CHECK(false);
151   }
152   catch(Dali::DaliException& e)
153   {
154     // Tests that a negative test of an assertion succeeds
155     DALI_TEST_PRINT_ASSERT(e);
156     DALI_TEST_CHECK(!view);
157   }
158   END_TEST;
159 }
160
161 // Positive test case for a method
162 int UtcDaliSceneViewNew(void)
163 {
164   ToolkitTestApplication application;
165   tet_infoline("UtcDaliSceneViewNew");
166
167   Scene3D::SceneView view = Scene3D::SceneView::New();
168   DALI_TEST_CHECK(view);
169   END_TEST;
170 }
171
172 // Positive test case for a method
173 int UtcDaliSceneViewDownCast(void)
174 {
175   ToolkitTestApplication application;
176   tet_infoline("UtcDaliSceneViewDownCast");
177
178   Scene3D::SceneView view = Scene3D::SceneView::New();
179   BaseHandle         handle(view);
180
181   Scene3D::SceneView sceneView = Scene3D::SceneView::DownCast(handle);
182   DALI_TEST_CHECK(view);
183   DALI_TEST_CHECK(sceneView);
184   DALI_TEST_CHECK(sceneView == view);
185   END_TEST;
186 }
187
188 int UtcDaliSceneViewTypeRegistry(void)
189 {
190   ToolkitTestApplication application;
191   tet_infoline("UtcDaliSceneViewTypeRegistry");
192
193   TypeRegistry typeRegistry = TypeRegistry::Get();
194   DALI_TEST_CHECK(typeRegistry);
195
196   TypeInfo typeInfo = typeRegistry.GetTypeInfo("SceneView");
197   DALI_TEST_CHECK(typeInfo);
198
199   BaseHandle handle = typeInfo.CreateInstance();
200   DALI_TEST_CHECK(handle);
201
202   Scene3D::SceneView model = Scene3D::SceneView::DownCast(handle);
203   DALI_TEST_CHECK(model);
204
205   END_TEST;
206 }
207
208 // Positive test case for a method
209 int UtcDaliSceneViewAddRemove(void)
210 {
211   ToolkitTestApplication application;
212   tet_infoline("UtcDaliSceneViewAddRemove");
213
214   Scene3D::SceneView view = Scene3D::SceneView::New();
215   DALI_TEST_CHECK(view);
216   DALI_TEST_EQUALS(1u, view.GetChildCount(), TEST_LOCATION);
217
218   Actor actor = Actor::New();
219
220   view.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
221   view.SetProperty(Actor::Property::SIZE, application.GetScene().GetSize());
222   view.Add(actor);
223
224   DALI_TEST_EQUALS(1u, view.GetChildCount(), TEST_LOCATION);
225   Actor layer = view.GetChildAt(0u);
226
227   DALI_TEST_EQUALS(2u, layer.GetChildCount(), TEST_LOCATION);
228   DALI_TEST_EQUALS(actor, layer.GetChildAt(1u), TEST_LOCATION); // index 0u is default camera
229
230   view.Remove(actor);
231   DALI_TEST_EQUALS(1u, layer.GetChildCount(), TEST_LOCATION);
232   END_TEST;
233 }
234
235 int UtcDaliSceneViewCopyAndAssignment(void)
236 {
237   ToolkitTestApplication application;
238
239   Scene3D::SceneView view = Scene3D::SceneView::New();
240   DALI_TEST_CHECK(view);
241
242   Scene3D::SceneView copy(view);
243   DALI_TEST_CHECK(view == copy);
244
245   Scene3D::SceneView assign;
246   DALI_TEST_CHECK(!assign);
247
248   assign = copy;
249   DALI_TEST_CHECK(assign == view);
250
251   END_TEST;
252 }
253
254 int UtcDaliSceneViewMoveConstructor(void)
255 {
256   ToolkitTestApplication application;
257
258   Scene3D::SceneView view = Scene3D::SceneView::New();
259   DALI_TEST_EQUALS(1, view.GetBaseObject().ReferenceCount(), TEST_LOCATION);
260   view.SetProperty(Actor::Property::SENSITIVE, false);
261   DALI_TEST_CHECK(false == view.GetProperty<bool>(Actor::Property::SENSITIVE));
262
263   Scene3D::SceneView moved = std::move(view);
264   DALI_TEST_CHECK(moved);
265   DALI_TEST_EQUALS(1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION);
266   DALI_TEST_CHECK(false == moved.GetProperty<bool>(Actor::Property::SENSITIVE));
267   DALI_TEST_CHECK(!view);
268
269   END_TEST;
270 }
271
272 int UtcDaliSceneViewMoveAssignment(void)
273 {
274   ToolkitTestApplication application;
275
276   Scene3D::SceneView view = Scene3D::SceneView::New();
277   DALI_TEST_EQUALS(1, view.GetBaseObject().ReferenceCount(), TEST_LOCATION);
278   view.SetProperty(Actor::Property::SENSITIVE, false);
279   DALI_TEST_CHECK(false == view.GetProperty<bool>(Actor::Property::SENSITIVE));
280
281   Scene3D::SceneView moved;
282   moved = std::move(view);
283   DALI_TEST_CHECK(moved);
284   DALI_TEST_EQUALS(1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION);
285   DALI_TEST_CHECK(false == moved.GetProperty<bool>(Actor::Property::SENSITIVE));
286   DALI_TEST_CHECK(!view);
287
288   END_TEST;
289 }
290
291 int UtcDaliSceneViewOnScene01(void)
292 {
293   ToolkitTestApplication application;
294
295   Scene3D::SceneView view = Scene3D::SceneView::New();
296
297   DALI_TEST_EQUALS(1u, view.GetChildCount(), TEST_LOCATION);
298   Actor layer = view.GetChildAt(0u);
299
300   DALI_TEST_EQUALS(1u, layer.GetChildCount(), TEST_LOCATION);
301
302   application.GetScene().Add(view);
303
304   application.SendNotification();
305   application.Render();
306
307   // CameraActor is added on layer when on scene
308   DALI_TEST_EQUALS(1u, layer.GetChildCount(), TEST_LOCATION);
309
310   END_TEST;
311 }
312
313 int UtcDaliSceneViewOnScene02(void)
314 {
315   ToolkitTestApplication application;
316
317   uint32_t renderTaskCount = application.GetScene().GetRenderTaskList().GetTaskCount();
318   DALI_TEST_EQUALS(1u, renderTaskCount, TEST_LOCATION);
319
320   Scene3D::SceneView view = Scene3D::SceneView::New();
321
322   renderTaskCount = application.GetScene().GetRenderTaskList().GetTaskCount();
323   DALI_TEST_EQUALS(1u, renderTaskCount, TEST_LOCATION);
324
325   application.GetScene().Add(view);
326
327   application.SendNotification();
328   application.Render();
329
330
331   renderTaskCount = application.GetScene().GetRenderTaskList().GetTaskCount();
332   DALI_TEST_EQUALS(2u, renderTaskCount, TEST_LOCATION);
333
334   RenderTask  renderTask = application.GetScene().GetRenderTaskList().GetTask(1u);
335   CameraActor camera     = renderTask.GetCameraActor();
336
337   CameraActor defaultCamera = renderTask.GetCameraActor();
338   DALI_TEST_CHECK(defaultCamera);
339   DALI_TEST_EQUALS(camera, defaultCamera, TEST_LOCATION);
340   DALI_TEST_EQUALS(defaultCamera, view.GetSelectedCamera(), TEST_LOCATION);
341
342   END_TEST;
343 }
344
345 int UtcDaliSceneViewUserCamera(void)
346 {
347   ToolkitTestApplication application;
348
349   Scene3D::SceneView view = Scene3D::SceneView::New();
350   view.SetProperty(Dali::Actor::Property::SIZE, Vector2(100, 100));
351
352   application.GetScene().Add(view);
353
354   application.SendNotification();
355   application.Render();
356
357   CameraActor defaultCamera = view.GetSelectedCamera();
358   CameraActor camera        = Dali::CameraActor::New();
359   camera.SetProperty(Dali::Actor::Property::NAME, "camera");
360   view.AddCamera(camera);
361   view.SelectCamera("camera");
362
363   DALI_TEST_NOT_EQUALS(defaultCamera, view.GetSelectedCamera(), 0.0f, TEST_LOCATION);
364   DALI_TEST_EQUALS(camera, view.GetSelectedCamera(), TEST_LOCATION);
365
366   camera.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
367   camera.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
368   camera.SetFieldOfView(0.5f);
369   camera.SetNearClippingPlane(1.0f);
370   camera.SetFarClippingPlane(5000.0f);
371   camera.SetProperty(Dali::Actor::Property::POSITION, Vector3(20, 30, 40));
372
373   float   fov            = camera[Dali::CameraActor::Property::FIELD_OF_VIEW];
374   float   nearPlain      = camera[Dali::CameraActor::Property::NEAR_PLANE_DISTANCE];
375   float   farPlain       = camera[Dali::CameraActor::Property::FAR_PLANE_DISTANCE];
376   Vector3 cameraPosition = camera[Dali::Actor::Property::POSITION];
377
378   view.SetProperty(Dali::Actor::Property::SIZE, Vector2(400, 300));
379
380   DALI_TEST_EQUALS(fov, camera.GetProperty<float>(Dali::CameraActor::Property::FIELD_OF_VIEW), TEST_LOCATION);
381   DALI_TEST_EQUALS(nearPlain, camera.GetProperty<float>(Dali::CameraActor::Property::NEAR_PLANE_DISTANCE), TEST_LOCATION);
382   DALI_TEST_EQUALS(farPlain, camera.GetProperty<float>(Dali::CameraActor::Property::FAR_PLANE_DISTANCE), TEST_LOCATION);
383   DALI_TEST_EQUALS(cameraPosition, camera.GetProperty<Vector3>(Dali::Actor::Property::POSITION), TEST_LOCATION);
384
385   END_TEST;
386 }
387
388 int UtcDaliSceneViewAddRemoveCamera(void)
389 {
390   ToolkitTestApplication application;
391
392   Scene3D::SceneView view = Scene3D::SceneView::New();
393   view.SetProperty(Dali::Actor::Property::SIZE, Vector2(100, 100));
394
395   application.GetScene().Add(view);
396
397   application.SendNotification();
398   application.Render();
399
400   CameraActor camera0 = view.GetSelectedCamera();
401   camera0.SetProperty(Dali::Actor::Property::NAME, "camera0");
402   CameraActor camera1 = Dali::CameraActor::New();
403   camera1.SetProperty(Dali::Actor::Property::NAME, "camera1");
404
405   DALI_TEST_EQUALS(1u, view.GetCameraCount(), TEST_LOCATION);
406   view.AddCamera(camera1);
407   DALI_TEST_EQUALS(2u, view.GetCameraCount(), TEST_LOCATION);
408
409   DALI_TEST_EQUALS(camera0, view.GetCamera(0), TEST_LOCATION);
410   DALI_TEST_EQUALS(camera0, view.GetCamera("camera0"), TEST_LOCATION);
411   DALI_TEST_EQUALS(camera1, view.GetCamera(1), TEST_LOCATION);
412   DALI_TEST_EQUALS(camera1, view.GetCamera("camera1"), TEST_LOCATION);
413
414   DALI_TEST_EQUALS(camera0, view.GetSelectedCamera(), TEST_LOCATION);
415   view.SelectCamera(1); // 0 -> 1
416   DALI_TEST_EQUALS(camera1, view.GetSelectedCamera(), TEST_LOCATION);
417   view.SelectCamera("camera0"); // 1 -> 0
418   DALI_TEST_EQUALS(camera0, view.GetSelectedCamera(), TEST_LOCATION);
419   view.SelectCamera("camera1"); // 0 -> 1
420   DALI_TEST_EQUALS(camera1, view.GetSelectedCamera(), TEST_LOCATION);
421   view.SelectCamera(0); // 1 -> 0
422   DALI_TEST_EQUALS(camera0, view.GetSelectedCamera(), TEST_LOCATION);
423
424   view.SelectCamera(1); // 0 -> 1
425   DALI_TEST_EQUALS(camera1, view.GetSelectedCamera(), TEST_LOCATION);
426   DALI_TEST_EQUALS(2u, view.GetCameraCount(), TEST_LOCATION);
427   view.RemoveCamera(camera1); // 1 -> 0
428   DALI_TEST_EQUALS(camera0, view.GetSelectedCamera(), TEST_LOCATION);
429   DALI_TEST_EQUALS(1u, view.GetCameraCount(), TEST_LOCATION);
430
431   CameraActor defaultCamera = view.GetSelectedCamera();
432   DALI_TEST_CHECK(defaultCamera);
433   DALI_TEST_EQUALS(camera0, defaultCamera, TEST_LOCATION);
434   DALI_TEST_NOT_EQUALS(camera1, defaultCamera, 0.0f, TEST_LOCATION);
435   END_TEST;
436 }
437
438 int UtcDaliSceneViewImageBasedLight01(void)
439 {
440   ToolkitTestApplication application;
441
442   Scene3D::SceneView view = Scene3D::SceneView::New();
443   view.ResourceReadySignal().Connect(OnResourceReady);
444   view.SetProperty(Dali::Actor::Property::SIZE, Vector2(100, 100));
445
446   application.GetScene().Add(view);
447
448   application.SendNotification();
449   application.Render();
450
451   Scene3D::Model modelView1 = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
452   Scene3D::Model modelView2 = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
453   Scene3D::Model modelView3 = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
454   view.Add(modelView1);
455   view.Add(modelView2);
456
457   application.SendNotification();
458   application.Render();
459   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
460   application.SendNotification();
461   application.Render();
462
463   DALI_TEST_NOT_EQUALS(GetDiffuseTexture(modelView1), GetDiffuseTexture(modelView2), 0.0f, TEST_LOCATION);
464   DALI_TEST_NOT_EQUALS(GetSpecularTexture(modelView1), GetSpecularTexture(modelView2), 0.0f, TEST_LOCATION);
465   DALI_TEST_NOT_EQUALS(GetDiffuseTexture(modelView1), GetDiffuseTexture(modelView3), 0.0f, TEST_LOCATION);
466   DALI_TEST_NOT_EQUALS(GetSpecularTexture(modelView1), GetSpecularTexture(modelView3), 0.0f, TEST_LOCATION);
467
468   gResourceReadyCalled = false;
469   DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
470   view.SetImageBasedLightSource(TEST_DIFFUSE_TEXTURE, TEST_SPECULAR_TEXTURE);
471
472   application.SendNotification();
473   application.Render();
474
475   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
476   application.SendNotification();
477   application.Render();
478
479   DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
480
481   DALI_TEST_EQUALS(GetDiffuseTexture(modelView1), GetDiffuseTexture(modelView2), TEST_LOCATION);
482   DALI_TEST_EQUALS(GetSpecularTexture(modelView1), GetSpecularTexture(modelView2), TEST_LOCATION);
483   DALI_TEST_NOT_EQUALS(GetDiffuseTexture(modelView1), GetDiffuseTexture(modelView3), 0.0f, TEST_LOCATION);
484   DALI_TEST_NOT_EQUALS(GetSpecularTexture(modelView1), GetSpecularTexture(modelView3), 0.0f, TEST_LOCATION);
485
486   view.Add(modelView3);
487   application.SendNotification();
488   application.Render();
489   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
490   application.SendNotification();
491   application.Render();
492
493   DALI_TEST_EQUALS(GetDiffuseTexture(modelView1), GetDiffuseTexture(modelView3), TEST_LOCATION);
494   DALI_TEST_EQUALS(GetSpecularTexture(modelView1), GetSpecularTexture(modelView3), TEST_LOCATION);
495
496   view.Remove(modelView1);
497
498   gResourceReadyCalled = false;
499   DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
500   view.SetImageBasedLightSource(TEST_DIFFUSE_TEXTURE2, TEST_SPECULAR_TEXTURE2);
501
502   application.SendNotification();
503   application.Render();
504
505   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
506   application.SendNotification();
507   application.Render();
508
509   DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
510
511   DALI_TEST_NOT_EQUALS(GetDiffuseTexture(modelView1), GetDiffuseTexture(modelView2), 0.0f, TEST_LOCATION);
512   DALI_TEST_NOT_EQUALS(GetSpecularTexture(modelView1), GetSpecularTexture(modelView2), 0.0f, TEST_LOCATION);
513   DALI_TEST_NOT_EQUALS(GetDiffuseTexture(modelView1), GetDiffuseTexture(modelView3), 0.0f, TEST_LOCATION);
514   DALI_TEST_NOT_EQUALS(GetSpecularTexture(modelView1), GetSpecularTexture(modelView3), 0.0f, TEST_LOCATION);
515   DALI_TEST_EQUALS(GetDiffuseTexture(modelView2), GetDiffuseTexture(modelView3), TEST_LOCATION);
516   DALI_TEST_EQUALS(GetSpecularTexture(modelView2), GetSpecularTexture(modelView3), TEST_LOCATION);
517
518   END_TEST;
519 }
520
521 int UtcDaliSceneViewImageBasedLight02(void)
522 {
523   ToolkitTestApplication application;
524
525   Scene3D::SceneView view = Scene3D::SceneView::New();
526   view.ResourceReadySignal().Connect(OnResourceReady);
527   view.SetProperty(Dali::Actor::Property::SIZE, Vector2(100, 100));
528
529   application.GetScene().Add(view);
530
531   application.SendNotification();
532   application.Render();
533
534   Scene3D::Model modelView1 = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
535   modelView1.ResourceReadySignal().Connect(OnResourceReady);
536   view.Add(modelView1);
537   application.SendNotification();
538   application.Render();
539   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
540   application.SendNotification();
541   application.Render();
542
543   gResourceReadyCalled = false;
544   DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
545   view.SetImageBasedLightSource(TEST_DIFFUSE_TEXTURE, TEST_SPECULAR_TEXTURE);
546
547   application.SendNotification();
548   application.Render();
549
550   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
551   application.SendNotification();
552   application.Render();
553
554   DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
555
556   Dali::Texture diffuseTexture = GetDiffuseTexture(modelView1);
557   Dali::Texture specularTexture = GetSpecularTexture(modelView1);
558
559   gResourceReadyCalled = false;
560   DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
561   modelView1.SetImageBasedLightSource(TEST_DIFFUSE_TEXTURE2, TEST_SPECULAR_TEXTURE2);
562
563   application.SendNotification();
564   application.Render();
565
566   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
567   application.SendNotification();
568   application.Render();
569
570   DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
571
572   DALI_TEST_NOT_EQUALS(GetDiffuseTexture(modelView1), diffuseTexture, 0.0f, TEST_LOCATION);
573   DALI_TEST_NOT_EQUALS(GetSpecularTexture(modelView1), specularTexture, 0.0f, TEST_LOCATION);
574   diffuseTexture = GetDiffuseTexture(modelView1);
575   specularTexture = GetSpecularTexture(modelView1);
576
577   // reset SceneView IBL
578   view.SetImageBasedLightSource("", "");
579   DALI_TEST_EQUALS(GetDiffuseTexture(modelView1), diffuseTexture, TEST_LOCATION);
580   DALI_TEST_EQUALS(GetSpecularTexture(modelView1), specularTexture, TEST_LOCATION);
581
582   modelView1.SetImageBasedLightSource("", "");
583   DALI_TEST_NOT_EQUALS(GetDiffuseTexture(modelView1), diffuseTexture, 0.0f, TEST_LOCATION);
584   DALI_TEST_NOT_EQUALS(GetSpecularTexture(modelView1), specularTexture, 0.0f, TEST_LOCATION);
585
586   END_TEST;
587 }
588
589 int UtcDaliSceneViewImageBasedLight03(void)
590 {
591   ToolkitTestApplication application;
592
593   Scene3D::SceneView view = Scene3D::SceneView::New();
594   view.SetProperty(Dali::Actor::Property::SIZE, Vector2(100, 100));
595   view.ResourceReadySignal().Connect(OnResourceReady);
596   application.GetScene().Add(view);
597
598   application.SendNotification();
599   application.Render();
600
601   Scene3D::Model modelView1 = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
602   view.Add(modelView1);
603   modelView1.SetImageBasedLightSource(TEST_SPECULAR_TEXTURE, TEST_DIFFUSE_TEXTURE);
604
605   application.SendNotification();
606   application.Render();
607   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
608   application.SendNotification();
609   application.Render();
610
611   Dali::Texture diffuseTexture = GetDiffuseTexture(modelView1);
612   Dali::Texture specularTexture = GetSpecularTexture(modelView1);
613
614   gResourceReadyCalled = false;
615   DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
616   view.SetImageBasedLightSource(TEST_DIFFUSE_TEXTURE2, TEST_SPECULAR_TEXTURE2);
617
618   application.SendNotification();
619   application.Render();
620   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
621   application.SendNotification();
622   application.Render();
623
624   DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
625
626   DALI_TEST_EQUALS(GetDiffuseTexture(modelView1), diffuseTexture, TEST_LOCATION);
627   DALI_TEST_EQUALS(GetSpecularTexture(modelView1), specularTexture, TEST_LOCATION);
628
629   modelView1.SetImageBasedLightSource("", "");
630   DALI_TEST_NOT_EQUALS(GetDiffuseTexture(modelView1), diffuseTexture, 0.0f, TEST_LOCATION);
631   DALI_TEST_NOT_EQUALS(GetSpecularTexture(modelView1), specularTexture, 0.0f, TEST_LOCATION);
632   diffuseTexture = GetDiffuseTexture(modelView1);
633   specularTexture = GetSpecularTexture(modelView1);
634
635   // reset SceneView IBL
636   view.SetImageBasedLightSource("", "");
637   DALI_TEST_NOT_EQUALS(GetDiffuseTexture(modelView1), diffuseTexture, 0.0f, TEST_LOCATION);
638   DALI_TEST_NOT_EQUALS(GetSpecularTexture(modelView1), specularTexture, 0.0f, TEST_LOCATION);
639
640   END_TEST;
641 }
642
643 int UtcDaliSceneViewImageBasedFactor(void)
644 {
645   ToolkitTestApplication application;
646
647   Scene3D::SceneView view = Scene3D::SceneView::New();
648   view.SetProperty(Dali::Actor::Property::SIZE, Vector2(100, 100));
649
650   application.GetScene().Add(view);
651
652   application.SendNotification();
653   application.Render();
654
655   Scene3D::Model modelView1 = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
656   view.Add(modelView1);
657
658   DALI_TEST_EQUALS(view.GetImageBasedLightScaleFactor(), 1.0f, TEST_LOCATION);
659   DALI_TEST_EQUALS(modelView1.GetImageBasedLightScaleFactor(), 1.0f, TEST_LOCATION);
660
661   view.SetImageBasedLightScaleFactor(0.5f);
662   DALI_TEST_EQUALS(view.GetImageBasedLightScaleFactor(), 0.5f, TEST_LOCATION);
663   DALI_TEST_EQUALS(modelView1.GetImageBasedLightScaleFactor(), 1.0f, TEST_LOCATION);
664   END_TEST;
665 }
666
667 int UtcDaliSceneViewUseFramebuffer01(void)
668 {
669   ToolkitTestApplication application;
670
671   Scene3D::SceneView view = Scene3D::SceneView::New();
672   view.SetProperty(Dali::Actor::Property::SIZE, Vector2(100, 100));
673
674   application.GetScene().Add(view);
675
676   application.SendNotification();
677   application.Render();
678
679   bool useFramebuffer = view.IsUsingFramebuffer();
680   view.UseFramebuffer(true);
681   DALI_TEST_NOT_EQUALS(useFramebuffer, view.IsUsingFramebuffer(), 0.0f, TEST_LOCATION);
682
683   END_TEST;
684 }
685
686 int UtcDaliSceneViewUseFramebuffer02(void)
687 {
688   ToolkitTestApplication application;
689
690   Scene3D::SceneView view = Scene3D::SceneView::New();
691   view.SetProperty(Dali::Actor::Property::SIZE, Vector2(100, 100));
692
693   application.GetScene().Add(view);
694
695   application.SendNotification();
696   application.Render();
697
698   RenderTask renderTask = application.GetScene().GetRenderTaskList().GetTask(1u);
699   DALI_TEST_CHECK(!renderTask.GetFrameBuffer());
700
701   view.UseFramebuffer(true);
702   DALI_TEST_CHECK(renderTask.GetFrameBuffer());
703
704   view.UseFramebuffer(false);
705   DALI_TEST_CHECK(!renderTask.GetFrameBuffer());
706
707   view.UseFramebuffer(true);
708   DALI_TEST_CHECK(renderTask.GetFrameBuffer());
709
710   END_TEST;
711 }
712
713 int UtcDaliSceneViewResourceReady(void)
714 {
715   ToolkitTestApplication application;
716
717   gOnRelayoutCallBackCalled = false;
718   gResourceReadyCalled = false;
719   Scene3D::SceneView view = Scene3D::SceneView::New();
720   view.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
721   view.OnRelayoutSignal().Connect(OnRelayoutCallback);
722   view.ResourceReadySignal().Connect(OnResourceReady);
723   // SceneView::IsResourceReady() returns true by default.
724   DALI_TEST_EQUALS(view.IsResourceReady(), true, TEST_LOCATION);
725
726   // Sanity check
727   DALI_TEST_CHECK(!gOnRelayoutCallBackCalled);
728   DALI_TEST_CHECK(!gResourceReadyCalled);
729
730   application.GetScene().Add(view);
731
732   application.SendNotification();
733   application.Render();
734
735   DALI_TEST_EQUALS(gOnRelayoutCallBackCalled, true, TEST_LOCATION);
736   DALI_TEST_EQUALS(view.IsResourceReady(), true, TEST_LOCATION);
737   DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
738
739   gOnRelayoutCallBackCalled = false;
740   gResourceReadyCalled = false;
741
742   view.SetImageBasedLightSource(TEST_DIFFUSE_TEXTURE, TEST_SPECULAR_TEXTURE);
743
744   application.SendNotification();
745   application.Render();
746   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
747   application.SendNotification();
748   application.Render();
749
750   DALI_TEST_EQUALS(gOnRelayoutCallBackCalled, false, TEST_LOCATION);
751   DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
752
753   END_TEST;
754 }
755
756 int UtcDaliSceneViewSetSkybox(void)
757 {
758   ToolkitTestApplication application;
759
760   gResourceReadyCalled = false;
761   Scene3D::SceneView view = Scene3D::SceneView::New();
762   view.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
763   view.ResourceReadySignal().Connect(OnResourceReady);
764   application.GetScene().Add(view);
765
766   application.SendNotification();
767   application.Render();
768
769   uint32_t childCount = view.GetChildAt(0u).GetChildCount();
770   view.SetSkybox(TEST_SPECULAR_TEXTURE);
771
772   gResourceReadyCalled = false;
773   DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
774
775   application.SendNotification();
776   application.Render();
777   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
778   application.SendNotification();
779   application.Render();
780
781   DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
782
783   DALI_TEST_EQUALS(view.GetChildAt(0u).GetChildCount(), childCount + 1, TEST_LOCATION);
784
785   view.Unparent();
786   view.Reset();
787
788   END_TEST;
789 }
790
791 int UtcDaliSceneViewSetSkyboxEquirectangular(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_EQUIRECTANGULAR_TEXTURE, Scene3D::SceneView::SkyboxType::EQUIRECTANGULAR);
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 UtcDaliSceneViewSetSkyboxEmpty(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.SetSkybox("");
841   DALI_TEST_EQUALS(view.GetChildAt(0u).GetChildCount(), childCount, TEST_LOCATION);
842
843   view.Unparent();
844   view.Reset();
845
846   END_TEST;
847 }
848
849 int UtcDaliSceneViewSetSkyboxEquirectangularEmpty(void)
850 {
851   ToolkitTestApplication application;
852
853   gResourceReadyCalled = false;
854   Scene3D::SceneView view = Scene3D::SceneView::New();
855   view.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
856   view.ResourceReadySignal().Connect(OnResourceReady);
857   application.GetScene().Add(view);
858
859   application.SendNotification();
860   application.Render();
861
862   uint32_t childCount = view.GetChildAt(0u).GetChildCount();
863   view.SetSkybox("", Scene3D::SceneView::SkyboxType::EQUIRECTANGULAR);
864   DALI_TEST_EQUALS(view.GetChildAt(0u).GetChildCount(), childCount, TEST_LOCATION);
865
866   view.Unparent();
867   view.Reset();
868
869   END_TEST;
870 }
871
872 int UtcDaliSceneViewSetSkyboxIntensity(void)
873 {
874   ToolkitTestApplication application;
875
876   Scene3D::SceneView view = Scene3D::SceneView::New();
877   view.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
878
879   float intensity = 0.5f;
880   DALI_TEST_EQUALS(view.GetSkyboxIntensity(), 1.0f, TEST_LOCATION);
881
882   view.SetSkyboxIntensity(intensity);
883   DALI_TEST_EQUALS(view.GetSkyboxIntensity(), intensity, TEST_LOCATION);
884
885   END_TEST;
886 }
887
888 int UtcDaliSceneViewSetSkyboxOrientation(void)
889 {
890   ToolkitTestApplication application;
891
892   Scene3D::SceneView view = Scene3D::SceneView::New();
893   view.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
894
895   Dali::Quaternion orientation = Dali::Quaternion(Radian(0.5f), Vector3::YAXIS);
896   view.SetSkyboxOrientation(orientation);
897   DALI_TEST_EQUALS(view.GetSkyboxOrientation(), orientation, TEST_LOCATION);
898
899   END_TEST;
900 }
901
902 int UtcDaliSceneViewSetImageBasedLightAndSkybox(void)
903 {
904   ToolkitTestApplication application;
905
906   Scene3D::SceneView view = Scene3D::SceneView::New();
907   view.ResourceReadySignal().Connect(OnResourceReady);
908   view.SetProperty(Dali::Actor::Property::SIZE, Vector2(100, 100));
909   view.SetImageBasedLightSource(TEST_DIFFUSE_TEXTURE, TEST_SPECULAR_TEXTURE);
910   view.SetSkybox(TEST_SPECULAR_TEXTURE);
911   application.GetScene().Add(view);
912
913   // Check SceneView needs 3 trigger to load both of image based light and skybox.
914   gResourceReadyCalled = false;
915   DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
916   application.SendNotification();
917   application.Render();
918   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
919   application.SendNotification();
920   application.Render();
921   DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
922
923   END_TEST;
924 }
925
926 int UtcDaliSceneViewCreateAndRemoveRenderTask(void)
927 {
928   ToolkitTestApplication application;
929   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
930
931   uint32_t renderTaskCount = taskList.GetTaskCount();
932
933   Scene3D::SceneView view = Scene3D::SceneView::New();
934   view.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
935
936   DALI_TEST_EQUALS(renderTaskCount, application.GetScene().GetRenderTaskList().GetTaskCount(), TEST_LOCATION);
937
938   application.GetScene().Add(view);
939
940   DALI_TEST_EQUALS(renderTaskCount + 1, application.GetScene().GetRenderTaskList().GetTaskCount(), TEST_LOCATION);
941
942   view.Unparent();
943
944   DALI_TEST_EQUALS(renderTaskCount, application.GetScene().GetRenderTaskList().GetTaskCount(), TEST_LOCATION);
945
946   END_TEST;
947 }
948
949 int UtcDaliSceneViewColorMode(void)
950 {
951   ToolkitTestApplication application;
952
953   Scene3D::SceneView view = Scene3D::SceneView::New();
954   application.GetScene().Add(view);
955
956   DALI_TEST_EQUALS(view.GetChildAt(0u).GetProperty<int>(Dali::Actor::Property::COLOR_MODE), static_cast<int>(ColorMode::USE_OWN_MULTIPLY_PARENT_ALPHA), TEST_LOCATION);
957
958   view.UseFramebuffer(true);
959
960   DALI_TEST_EQUALS(view.GetChildAt(0u).GetProperty<int>(Dali::Actor::Property::COLOR_MODE), static_cast<int>(ColorMode::USE_OWN_COLOR), TEST_LOCATION);
961
962   view.UseFramebuffer(false);
963
964   DALI_TEST_EQUALS(view.GetChildAt(0u).GetProperty<int>(Dali::Actor::Property::COLOR_MODE), static_cast<int>(ColorMode::USE_OWN_MULTIPLY_PARENT_ALPHA), TEST_LOCATION);
965
966   END_TEST;
967 }