2 * Copyright (c) 2023 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include <dali-toolkit-test-suite-utils.h>
19 #include <dali-toolkit/dali-toolkit.h>
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>
28 using namespace Dali::Toolkit;
30 void scene_view_startup(void)
32 test_return_value = TET_UNDEF;
35 void scene_view_cleanup(void)
37 test_return_value = TET_PASS;
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
47 const char* TEST_GLTF_FILE_NAME = TEST_RESOURCE_DIR "/AnimatedCube.gltf";
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
54 * Copyright (c) 2023 Wave Coorporation
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:
63 * The above copyright notice and this permission notice shall be included in
64 * all copies or substantial portions of the Software.
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
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";
80 Dali::Texture GetDiffuseTexture(Dali::Scene3D::Model model)
82 Dali::Texture texture;
84 Actor meshActor = model.FindChildByName("AnimatedCube");
87 Renderer renderer = meshActor.GetRendererAt(0u);
90 TextureSet textureSet = renderer.GetTextures();
91 if(textureSet.GetTextureCount() == 10u)
93 texture = textureSet.GetTexture(8u);
101 Dali::Texture GetSpecularTexture(Dali::Scene3D::Model model)
103 Dali::Texture texture;
105 Actor meshActor = model.FindChildByName("AnimatedCube");
108 Renderer renderer = meshActor.GetRendererAt(0u);
111 TextureSet textureSet = renderer.GetTextures();
112 if(textureSet.GetTextureCount() == 10u)
114 texture = textureSet.GetTexture(9u);
123 static bool gOnRelayoutCallBackCalled = false;
124 void OnRelayoutCallback(Actor actor)
126 gOnRelayoutCallBackCalled = true;
129 static bool gResourceReadyCalled = false;
130 void OnResourceReady(Control control)
132 gResourceReadyCalled = true;
136 // Negative test case for a method
137 int UtcDaliSceneViewUninitialized(void)
139 ToolkitTestApplication application;
140 tet_infoline("UtcDaliSceneViewUninitialized");
142 Scene3D::SceneView view;
146 // New() must be called to create a Model or it wont be valid.
147 Actor a = Actor::New();
149 DALI_TEST_CHECK(false);
151 catch(Dali::DaliException& e)
153 // Tests that a negative test of an assertion succeeds
154 DALI_TEST_PRINT_ASSERT(e);
155 DALI_TEST_CHECK(!view);
160 // Positive test case for a method
161 int UtcDaliSceneViewNew(void)
163 ToolkitTestApplication application;
164 tet_infoline("UtcDaliSceneViewNew");
166 Scene3D::SceneView view = Scene3D::SceneView::New();
167 DALI_TEST_CHECK(view);
171 // Positive test case for a method
172 int UtcDaliSceneViewDownCast(void)
174 ToolkitTestApplication application;
175 tet_infoline("UtcDaliSceneViewDownCast");
177 Scene3D::SceneView view = Scene3D::SceneView::New();
178 BaseHandle handle(view);
180 Scene3D::SceneView sceneView = Scene3D::SceneView::DownCast(handle);
181 DALI_TEST_CHECK(view);
182 DALI_TEST_CHECK(sceneView);
183 DALI_TEST_CHECK(sceneView == view);
187 int UtcDaliSceneViewTypeRegistry(void)
189 ToolkitTestApplication application;
190 tet_infoline("UtcDaliSceneViewTypeRegistry");
192 TypeRegistry typeRegistry = TypeRegistry::Get();
193 DALI_TEST_CHECK(typeRegistry);
195 TypeInfo typeInfo = typeRegistry.GetTypeInfo("SceneView");
196 DALI_TEST_CHECK(typeInfo);
198 BaseHandle handle = typeInfo.CreateInstance();
199 DALI_TEST_CHECK(handle);
201 Scene3D::SceneView model = Scene3D::SceneView::DownCast(handle);
202 DALI_TEST_CHECK(model);
207 // Positive test case for a method
208 int UtcDaliSceneViewAddRemove(void)
210 ToolkitTestApplication application;
211 tet_infoline("UtcDaliSceneViewAddRemove");
213 Scene3D::SceneView view = Scene3D::SceneView::New();
214 DALI_TEST_CHECK(view);
215 DALI_TEST_EQUALS(1u, view.GetChildCount(), TEST_LOCATION);
217 Actor actor = Actor::New();
219 view.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
220 view.SetProperty(Actor::Property::SIZE, application.GetScene().GetSize());
223 DALI_TEST_EQUALS(1u, view.GetChildCount(), TEST_LOCATION);
224 Actor layer = view.GetChildAt(0u);
226 DALI_TEST_EQUALS(2u, layer.GetChildCount(), TEST_LOCATION);
227 DALI_TEST_EQUALS(actor, layer.GetChildAt(1u), TEST_LOCATION); // index 0u is default camera
230 DALI_TEST_EQUALS(1u, layer.GetChildCount(), TEST_LOCATION);
234 int UtcDaliSceneViewCopyAndAssignment(void)
236 ToolkitTestApplication application;
238 Scene3D::SceneView view = Scene3D::SceneView::New();
239 DALI_TEST_CHECK(view);
241 Scene3D::SceneView copy(view);
242 DALI_TEST_CHECK(view == copy);
244 Scene3D::SceneView assign;
245 DALI_TEST_CHECK(!assign);
248 DALI_TEST_CHECK(assign == view);
253 int UtcDaliSceneViewMoveConstructor(void)
255 ToolkitTestApplication application;
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));
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);
271 int UtcDaliSceneViewMoveAssignment(void)
273 ToolkitTestApplication application;
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));
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);
290 int UtcDaliSceneViewOnScene01(void)
292 ToolkitTestApplication application;
294 Scene3D::SceneView view = Scene3D::SceneView::New();
296 DALI_TEST_EQUALS(1u, view.GetChildCount(), TEST_LOCATION);
297 Actor layer = view.GetChildAt(0u);
299 DALI_TEST_EQUALS(1u, layer.GetChildCount(), TEST_LOCATION);
301 application.GetScene().Add(view);
303 application.SendNotification();
304 application.Render();
306 // CameraActor is added on layer when on scene
307 DALI_TEST_EQUALS(1u, layer.GetChildCount(), TEST_LOCATION);
312 int UtcDaliSceneViewOnScene02(void)
314 ToolkitTestApplication application;
316 uint32_t renderTaskCount = application.GetScene().GetRenderTaskList().GetTaskCount();
317 DALI_TEST_EQUALS(1u, renderTaskCount, TEST_LOCATION);
319 Scene3D::SceneView view = Scene3D::SceneView::New();
321 renderTaskCount = application.GetScene().GetRenderTaskList().GetTaskCount();
322 DALI_TEST_EQUALS(1u, renderTaskCount, TEST_LOCATION);
324 application.GetScene().Add(view);
326 application.SendNotification();
327 application.Render();
329 renderTaskCount = application.GetScene().GetRenderTaskList().GetTaskCount();
330 DALI_TEST_EQUALS(3u, renderTaskCount, TEST_LOCATION);
332 RenderTask renderTask = application.GetScene().GetRenderTaskList().GetTask(2u);
333 CameraActor camera = renderTask.GetCameraActor();
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);
343 int UtcDaliSceneViewUserCamera(void)
345 ToolkitTestApplication application;
347 Scene3D::SceneView view = Scene3D::SceneView::New();
348 view.SetProperty(Dali::Actor::Property::SIZE, Vector2(100, 100));
350 application.GetScene().Add(view);
352 application.SendNotification();
353 application.Render();
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");
361 DALI_TEST_NOT_EQUALS(defaultCamera, view.GetSelectedCamera(), 0.0f, TEST_LOCATION);
362 DALI_TEST_EQUALS(camera, view.GetSelectedCamera(), TEST_LOCATION);
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));
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];
376 view.SetProperty(Dali::Actor::Property::SIZE, Vector2(400, 300));
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);
386 int UtcDaliSceneViewAddRemoveCamera(void)
388 ToolkitTestApplication application;
390 Scene3D::SceneView view = Scene3D::SceneView::New();
391 view.SetProperty(Dali::Actor::Property::SIZE, Vector2(100, 100));
393 application.GetScene().Add(view);
395 application.SendNotification();
396 application.Render();
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");
403 DALI_TEST_EQUALS(1u, view.GetCameraCount(), TEST_LOCATION);
404 view.AddCamera(camera1);
405 DALI_TEST_EQUALS(2u, view.GetCameraCount(), TEST_LOCATION);
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);
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);
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);
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);
436 int UtcDaliSceneViewImageBasedLight01(void)
438 ToolkitTestApplication application;
440 Scene3D::SceneView view = Scene3D::SceneView::New();
441 view.ResourceReadySignal().Connect(OnResourceReady);
442 view.SetProperty(Dali::Actor::Property::SIZE, Vector2(100, 100));
444 application.GetScene().Add(view);
446 application.SendNotification();
447 application.Render();
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);
455 application.SendNotification();
456 application.Render();
457 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
458 application.SendNotification();
459 application.Render();
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);
466 gResourceReadyCalled = false;
467 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
468 view.SetImageBasedLightSource(TEST_DIFFUSE_TEXTURE, TEST_SPECULAR_TEXTURE);
470 application.SendNotification();
471 application.Render();
473 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
474 application.SendNotification();
475 application.Render();
477 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
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);
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();
491 DALI_TEST_EQUALS(GetDiffuseTexture(modelView1), GetDiffuseTexture(modelView3), TEST_LOCATION);
492 DALI_TEST_EQUALS(GetSpecularTexture(modelView1), GetSpecularTexture(modelView3), TEST_LOCATION);
494 view.Remove(modelView1);
496 gResourceReadyCalled = false;
497 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
498 view.SetImageBasedLightSource(TEST_DIFFUSE_TEXTURE2, TEST_SPECULAR_TEXTURE2);
500 application.SendNotification();
501 application.Render();
503 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
504 application.SendNotification();
505 application.Render();
507 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
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);
519 int UtcDaliSceneViewImageBasedLight02(void)
521 ToolkitTestApplication application;
523 Scene3D::SceneView view = Scene3D::SceneView::New();
524 view.ResourceReadySignal().Connect(OnResourceReady);
525 view.SetProperty(Dali::Actor::Property::SIZE, Vector2(100, 100));
527 application.GetScene().Add(view);
529 application.SendNotification();
530 application.Render();
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();
541 gResourceReadyCalled = false;
542 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
543 view.SetImageBasedLightSource(TEST_DIFFUSE_TEXTURE, TEST_SPECULAR_TEXTURE);
545 application.SendNotification();
546 application.Render();
548 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
549 application.SendNotification();
550 application.Render();
552 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
554 Dali::Texture diffuseTexture = GetDiffuseTexture(modelView1);
555 Dali::Texture specularTexture = GetSpecularTexture(modelView1);
557 gResourceReadyCalled = false;
558 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
559 modelView1.SetImageBasedLightSource(TEST_DIFFUSE_TEXTURE2, TEST_SPECULAR_TEXTURE2);
561 application.SendNotification();
562 application.Render();
564 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
565 application.SendNotification();
566 application.Render();
568 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
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);
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);
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);
587 int UtcDaliSceneViewImageBasedLight03(void)
589 ToolkitTestApplication application;
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);
596 application.SendNotification();
597 application.Render();
599 Scene3D::Model modelView1 = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
600 view.Add(modelView1);
601 modelView1.SetImageBasedLightSource(TEST_SPECULAR_TEXTURE, TEST_DIFFUSE_TEXTURE);
603 application.SendNotification();
604 application.Render();
605 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
606 application.SendNotification();
607 application.Render();
609 Dali::Texture diffuseTexture = GetDiffuseTexture(modelView1);
610 Dali::Texture specularTexture = GetSpecularTexture(modelView1);
612 gResourceReadyCalled = false;
613 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
614 view.SetImageBasedLightSource(TEST_DIFFUSE_TEXTURE2, TEST_SPECULAR_TEXTURE2);
616 application.SendNotification();
617 application.Render();
618 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
619 application.SendNotification();
620 application.Render();
622 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
624 DALI_TEST_EQUALS(GetDiffuseTexture(modelView1), diffuseTexture, TEST_LOCATION);
625 DALI_TEST_EQUALS(GetSpecularTexture(modelView1), specularTexture, TEST_LOCATION);
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);
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);
641 int UtcDaliSceneViewImageBasedFactor(void)
643 ToolkitTestApplication application;
645 Scene3D::SceneView view = Scene3D::SceneView::New();
646 view.SetProperty(Dali::Actor::Property::SIZE, Vector2(100, 100));
648 application.GetScene().Add(view);
650 application.SendNotification();
651 application.Render();
653 Scene3D::Model modelView1 = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
654 view.Add(modelView1);
656 DALI_TEST_EQUALS(view.GetImageBasedLightScaleFactor(), 1.0f, TEST_LOCATION);
657 DALI_TEST_EQUALS(modelView1.GetImageBasedLightScaleFactor(), 1.0f, TEST_LOCATION);
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);
665 int UtcDaliSceneViewUseFramebuffer01(void)
667 ToolkitTestApplication application;
669 Scene3D::SceneView view = Scene3D::SceneView::New();
670 view.SetProperty(Dali::Actor::Property::SIZE, Vector2(100, 100));
672 application.GetScene().Add(view);
674 application.SendNotification();
675 application.Render();
677 bool useFramebuffer = view.IsUsingFramebuffer();
678 view.UseFramebuffer(true);
679 DALI_TEST_NOT_EQUALS(useFramebuffer, view.IsUsingFramebuffer(), 0.0f, TEST_LOCATION);
684 int UtcDaliSceneViewUseFramebuffer02(void)
686 ToolkitTestApplication application;
688 Scene3D::SceneView view = Scene3D::SceneView::New();
689 view.SetProperty(Dali::Actor::Property::SIZE, Vector2(100, 100));
691 application.GetScene().Add(view);
693 application.SendNotification();
694 application.Render();
696 RenderTask renderTask = application.GetScene().GetRenderTaskList().GetTask(2u);
697 DALI_TEST_CHECK(!renderTask.GetFrameBuffer());
699 view.UseFramebuffer(true);
700 DALI_TEST_CHECK(renderTask.GetFrameBuffer());
702 view.UseFramebuffer(false);
703 DALI_TEST_CHECK(!renderTask.GetFrameBuffer());
705 view.UseFramebuffer(true);
706 DALI_TEST_CHECK(renderTask.GetFrameBuffer());
711 int UtcDaliSceneViewFramebufferMultiSamplingLevel(void)
713 ToolkitTestApplication application;
715 Scene3D::SceneView view = Scene3D::SceneView::New();
716 view.SetProperty(Dali::Actor::Property::SIZE, Vector2(100, 100));
718 application.GetScene().Add(view);
720 application.SendNotification();
721 application.Render();
723 uint8_t expectValue = 0u; // Default MultiSamplingLevel is 0.
724 uint8_t multiSamplingLevel = view.GetFramebufferMultiSamplingLevel();
725 DALI_TEST_EQUALS(multiSamplingLevel, expectValue, TEST_LOCATION);
727 expectValue = 4u; // Change value.
728 view.UseFramebuffer(true);
729 view.SetFramebufferMultiSamplingLevel(expectValue);
731 multiSamplingLevel = view.GetFramebufferMultiSamplingLevel();
732 DALI_TEST_EQUALS(multiSamplingLevel, expectValue, TEST_LOCATION);
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);
739 application.SendNotification();
740 application.Render();
742 multiSamplingLevel = view.GetFramebufferMultiSamplingLevel();
743 DALI_TEST_EQUALS(multiSamplingLevel, expectValue, TEST_LOCATION);
748 int UtcDaliSceneViewResourceReady(void)
750 ToolkitTestApplication application;
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);
762 DALI_TEST_CHECK(!gOnRelayoutCallBackCalled);
763 DALI_TEST_CHECK(!gResourceReadyCalled);
765 application.GetScene().Add(view);
767 application.SendNotification();
768 application.Render();
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);
774 gOnRelayoutCallBackCalled = false;
775 gResourceReadyCalled = false;
777 view.SetImageBasedLightSource(TEST_DIFFUSE_TEXTURE, TEST_SPECULAR_TEXTURE);
779 application.SendNotification();
780 application.Render();
781 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
782 application.SendNotification();
783 application.Render();
785 DALI_TEST_EQUALS(gOnRelayoutCallBackCalled, false, TEST_LOCATION);
786 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
791 int UtcDaliSceneViewSetSkybox(void)
793 ToolkitTestApplication application;
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);
801 application.SendNotification();
802 application.Render();
804 uint32_t childCount = view.GetChildAt(0u).GetChildCount();
805 view.SetSkybox(TEST_SPECULAR_TEXTURE);
807 gResourceReadyCalled = false;
808 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
810 application.SendNotification();
811 application.Render();
812 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
813 application.SendNotification();
814 application.Render();
816 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
818 DALI_TEST_EQUALS(view.GetChildAt(0u).GetChildCount(), childCount + 1, TEST_LOCATION);
826 int UtcDaliSceneViewSetSkyboxEquirectangular(void)
828 ToolkitTestApplication application;
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);
836 application.SendNotification();
837 application.Render();
839 uint32_t childCount = view.GetChildAt(0u).GetChildCount();
840 view.SetSkyboxEnvironmentMapType(Scene3D::EnvironmentMapType::EQUIRECTANGULAR);
841 view.SetSkybox(TEST_EQUIRECTANGULAR_TEXTURE);
843 gResourceReadyCalled = false;
844 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
846 application.SendNotification();
847 application.Render();
848 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
849 application.SendNotification();
850 application.Render();
852 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
854 DALI_TEST_EQUALS(view.GetChildAt(0u).GetChildCount(), childCount + 1, TEST_LOCATION);
862 int UtcDaliSceneViewSetSkyboxEmpty(void)
864 ToolkitTestApplication application;
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);
872 application.SendNotification();
873 application.Render();
875 uint32_t childCount = view.GetChildAt(0u).GetChildCount();
877 DALI_TEST_EQUALS(view.GetChildAt(0u).GetChildCount(), childCount, TEST_LOCATION);
885 int UtcDaliSceneViewSetSkyboxEmpty2(void)
887 ToolkitTestApplication application;
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);
895 application.SendNotification();
896 application.Render();
898 view.SetSkybox(TEST_EQUIRECTANGULAR_TEXTURE);
900 application.SendNotification();
901 application.Render();
902 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
903 application.SendNotification();
904 application.Render();
906 uint32_t childCount = view.GetChildAt(0u).GetChildCount();
909 DALI_TEST_EQUALS(view.GetChildAt(0u).GetChildCount(), childCount - 1, TEST_LOCATION);
917 int UtcDaliSceneViewSetSkyboxEquirectangularEmpty(void)
919 ToolkitTestApplication application;
921 gResourceReadyCalled = false;
922 Scene3D::SceneView view = Scene3D::SceneView::New();
923 view.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
924 view.ResourceReadySignal().Connect(OnResourceReady);
925 application.GetScene().Add(view);
927 application.SendNotification();
928 application.Render();
930 uint32_t childCount = view.GetChildAt(0u).GetChildCount();
932 DALI_TEST_EQUALS(view.GetChildAt(0u).GetChildCount(), childCount, TEST_LOCATION);
940 int UtcDaliSceneViewSetSkyboxIntensity(void)
942 ToolkitTestApplication application;
944 Scene3D::SceneView view = Scene3D::SceneView::New();
945 view.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
947 float intensity = 0.5f;
948 DALI_TEST_EQUALS(view.GetSkyboxIntensity(), 1.0f, TEST_LOCATION);
950 view.SetSkyboxIntensity(intensity);
951 DALI_TEST_EQUALS(view.GetSkyboxIntensity(), intensity, TEST_LOCATION);
956 int UtcDaliSceneViewSetSkyboxOrientation(void)
958 ToolkitTestApplication application;
960 Scene3D::SceneView view = Scene3D::SceneView::New();
961 view.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
963 Dali::Quaternion orientation = Dali::Quaternion(Radian(0.5f), Vector3::YAXIS);
964 view.SetSkyboxOrientation(orientation);
965 DALI_TEST_EQUALS(view.GetSkyboxOrientation(), orientation, TEST_LOCATION);
970 int UtcDaliSceneViewSetImageBasedLightAndSkybox(void)
972 ToolkitTestApplication application;
974 Scene3D::SceneView view = Scene3D::SceneView::New();
975 view.ResourceReadySignal().Connect(OnResourceReady);
976 view.SetProperty(Dali::Actor::Property::SIZE, Vector2(100, 100));
977 view.SetImageBasedLightSource(TEST_DIFFUSE_TEXTURE, TEST_SPECULAR_TEXTURE);
978 view.SetSkybox(TEST_SPECULAR_TEXTURE);
979 application.GetScene().Add(view);
981 // Check SceneView needs 3 trigger to load both of image based light and skybox.
982 gResourceReadyCalled = false;
983 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
984 application.SendNotification();
985 application.Render();
986 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
987 application.SendNotification();
988 application.Render();
989 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
994 int UtcDaliSceneViewCreateAndRemoveRenderTask(void)
996 ToolkitTestApplication application;
997 RenderTaskList taskList = application.GetScene().GetRenderTaskList();
999 uint32_t renderTaskCount = taskList.GetTaskCount();
1001 Scene3D::SceneView view = Scene3D::SceneView::New();
1002 view.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1004 DALI_TEST_EQUALS(renderTaskCount, application.GetScene().GetRenderTaskList().GetTaskCount(), TEST_LOCATION);
1006 application.GetScene().Add(view);
1008 DALI_TEST_EQUALS(renderTaskCount + 2, application.GetScene().GetRenderTaskList().GetTaskCount(), TEST_LOCATION);
1012 DALI_TEST_EQUALS(renderTaskCount, application.GetScene().GetRenderTaskList().GetTaskCount(), TEST_LOCATION);
1017 int UtcDaliSceneViewColorMode(void)
1019 ToolkitTestApplication application;
1021 Scene3D::SceneView view = Scene3D::SceneView::New();
1022 application.GetScene().Add(view);
1024 DALI_TEST_EQUALS(view.GetChildAt(0u).GetProperty<int>(Dali::Actor::Property::COLOR_MODE), static_cast<int>(ColorMode::USE_OWN_MULTIPLY_PARENT_ALPHA), TEST_LOCATION);
1026 view.UseFramebuffer(true);
1028 DALI_TEST_EQUALS(view.GetChildAt(0u).GetProperty<int>(Dali::Actor::Property::COLOR_MODE), static_cast<int>(ColorMode::USE_OWN_COLOR), TEST_LOCATION);
1030 view.UseFramebuffer(false);
1032 DALI_TEST_EQUALS(view.GetChildAt(0u).GetProperty<int>(Dali::Actor::Property::COLOR_MODE), static_cast<int>(ColorMode::USE_OWN_MULTIPLY_PARENT_ALPHA), TEST_LOCATION);
1037 int UtcDaliSceneViewSetResolution(void)
1039 ToolkitTestApplication application;
1041 Scene3D::SceneView view = Scene3D::SceneView::New();
1042 application.GetScene().Add(view);
1043 view.SetProperty(Dali::Actor::Property::SIZE, Vector2(100, 100));
1045 DALI_TEST_EQUALS(view.GetResolutionWidth(), 100u, TEST_LOCATION);
1046 DALI_TEST_EQUALS(view.GetResolutionHeight(), 100u, TEST_LOCATION);
1048 view.SetResolution(200u, 200u);
1050 DALI_TEST_EQUALS(view.GetResolutionWidth(), 100u, TEST_LOCATION);
1051 DALI_TEST_EQUALS(view.GetResolutionHeight(), 100u, TEST_LOCATION);
1053 view.UseFramebuffer(true);
1055 DALI_TEST_EQUALS(view.GetResolutionWidth(), 200u, TEST_LOCATION);
1056 DALI_TEST_EQUALS(view.GetResolutionHeight(), 200u, TEST_LOCATION);
1058 view.SetResolution(300u, 0u);
1060 DALI_TEST_EQUALS(view.GetResolutionWidth(), 100u, TEST_LOCATION);
1061 DALI_TEST_EQUALS(view.GetResolutionHeight(), 100u, TEST_LOCATION);
1063 view.SetResolution(300u, 400u);
1065 DALI_TEST_EQUALS(view.GetResolutionWidth(), 300u, TEST_LOCATION);
1066 DALI_TEST_EQUALS(view.GetResolutionHeight(), 400u, TEST_LOCATION);
1068 view.ResetResolution();
1070 DALI_TEST_EQUALS(view.GetResolutionWidth(), 100u, TEST_LOCATION);
1071 DALI_TEST_EQUALS(view.GetResolutionHeight(), 100u, TEST_LOCATION);
1073 view.SetProperty(Dali::Actor::Property::SIZE, Vector2(400, 400));
1075 DALI_TEST_EQUALS(view.GetResolutionWidth(), 400u, TEST_LOCATION);
1076 DALI_TEST_EQUALS(view.GetResolutionHeight(), 400u, TEST_LOCATION);
1083 const char* TEST_MASK_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/mask.png";
1085 static constexpr std::string_view Y_FLIP_MASK_TEXTURE = "uYFlipMaskTexture";
1088 int UtcDaliSceneViewMasking(void)
1090 ToolkitTestApplication application;
1092 Scene3D::SceneView view = Scene3D::SceneView::New();
1093 application.GetScene().Add(view);
1095 DALI_TEST_EQUALS(view.GetProperty<std::string>(Dali::Scene3D::SceneView::Property::ALPHA_MASK_URL), "", TEST_LOCATION);
1096 DALI_TEST_EQUALS(view.GetProperty<bool>(Dali::Scene3D::SceneView::Property::CROP_TO_MASK), true, TEST_LOCATION);
1097 DALI_TEST_EQUALS(view.GetProperty<float>(Dali::Scene3D::SceneView::Property::MASK_CONTENT_SCALE), 1.0f, TEST_LOCATION);
1099 auto yFlipMaskTextureIndex = view.GetPropertyIndex(Y_FLIP_MASK_TEXTURE.data());
1100 DALI_TEST_EQUALS(yFlipMaskTextureIndex, Property::INVALID_INDEX, TEST_LOCATION);
1102 view.UseFramebuffer(true);
1103 view.SetProperty(Dali::Scene3D::SceneView::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME);
1104 view.SetProperty(Dali::Scene3D::SceneView::Property::CROP_TO_MASK, false);
1105 view.SetProperty(Dali::Scene3D::SceneView::Property::MASK_CONTENT_SCALE, 0.5f);
1107 DALI_TEST_EQUALS(view.GetProperty<std::string>(Dali::Scene3D::SceneView::Property::ALPHA_MASK_URL), TEST_MASK_IMAGE_FILE_NAME, TEST_LOCATION);
1108 DALI_TEST_EQUALS(view.GetProperty<bool>(Dali::Scene3D::SceneView::Property::CROP_TO_MASK), false, TEST_LOCATION);
1109 DALI_TEST_EQUALS(view.GetProperty<float>(Dali::Scene3D::SceneView::Property::MASK_CONTENT_SCALE), 0.5f, TEST_LOCATION);
1111 yFlipMaskTextureIndex = view.GetPropertyIndex(std::string(Y_FLIP_MASK_TEXTURE));
1112 DALI_TEST_EQUALS(view.GetProperty<float>(yFlipMaskTextureIndex), 1.0f, TEST_LOCATION);