2 * Copyright (c) 2014 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.
21 #include <dali/public-api/dali-core.h>
22 #include <dali/devel-api/actors/mesh-actor.h>
23 #include <dali/devel-api/geometry/mesh.h>
24 #include <dali/devel-api/geometry/animatable-mesh.h>
25 #include <dali-test-suite-utils.h>
29 #include <mesh-builder.h>
31 void mesh_actor_test_startup(void)
33 test_return_value = TET_UNDEF;
36 void mesh_actor_test_cleanup(void)
38 test_return_value = TET_PASS;
47 MeshData::VertexContainer vertices;
48 MeshData::FaceIndices faces;
50 ConstructVertices(vertices, 60);
51 ConstructFaces(vertices, faces);
52 Material customMaterial = ConstructMaterial();
53 meshData.SetData(vertices, faces, bones, customMaterial);
54 Mesh mesh = Mesh::New(meshData);
58 static AnimatableMesh NewAnimatableMesh()
60 AnimatableMesh::Faces faces;
65 Material customMaterial = Material::New("CustomMaterial");
66 customMaterial.SetOpacity(.76f);
67 customMaterial.SetDiffuseColor(Vector4(0.8f, 0.0f, 0.4f, 1.0f));
68 customMaterial.SetAmbientColor(Vector4(0.2f, 1.0f, 0.6f, 1.0f));
69 customMaterial.SetSpecularColor(Vector4(0.5f, 0.6f, 0.7f, 1.0f));
71 AnimatableMesh mesh = AnimatableMesh::New( 10u, faces, customMaterial );
74 } // anonymous namespace
76 int UtcDaliMeshActorConstructorVoid(void)
78 TestApplication application;
79 tet_infoline("Testing Dali::MeshActor::MeshActor()");
82 DALI_TEST_CHECK(!actor);
86 int UtcDaliMeshActorNew01(void)
88 TestApplication application;
89 tet_infoline("Testing Dali::MeshActor::New()");
91 AnimatableMesh mesh = NewAnimatableMesh();
92 MeshActor actor = MeshActor::New(mesh);
93 application.SendNotification();
96 application.SendNotification();
98 DALI_TEST_CHECK(actor);
103 int UtcDaliMeshActorNew03(void)
105 TestApplication application;
106 tet_infoline("Testing Dali::Mesh::New() - Create with no mesh");
110 MeshActor actor = MeshActor::New(); // Shouldn't assert
111 tet_result(TET_PASS);
113 catch (Dali::DaliException& e)
115 tet_result(TET_FAIL);
121 int UtcDaliMeshActorCreateNoMeshData(void)
123 TestApplication application;
124 tet_infoline("Testing Dali::Mesh::New() - Create with no mesh data");
129 Mesh mesh = Mesh::New(meshData);
130 MeshActor actor1 = MeshActor::New(mesh);
132 catch(Dali::DaliException& e)
134 DALI_TEST_PRINT_ASSERT( e );
135 DALI_TEST_ASSERT(e, "object", TEST_LOCATION);
141 int UtcDaliMeshActorCreateSetData01(void)
143 TestApplication application;
144 tet_infoline("Testing Dali::MeshData::SetData() - Create with no verts");
148 MeshData::VertexContainer vertices;
149 MeshData::FaceIndices faces;
151 Material customMaterial;
152 meshData.SetData(vertices, faces, bones, customMaterial);
153 Mesh mesh = Mesh::New(meshData);
154 MeshActor actor1 = MeshActor::New(mesh);
156 catch(Dali::DaliException& e)
158 DALI_TEST_PRINT_ASSERT( e );
159 DALI_TEST_ASSERT(e, "!vertices.empty()", TEST_LOCATION );
164 int UtcDaliMeshActorCreateSetData02(void)
166 TestApplication application;
167 tet_infoline("Testing Dali::MeshData::SetData - Create with no faces");
171 MeshData::VertexContainer vertices;
172 MeshData::FaceIndices faces;
174 Material customMaterial;
175 ConstructVertices(vertices, 60);
176 meshData.SetData(vertices, faces, bones, customMaterial);
177 Mesh mesh = Mesh::New(meshData);
178 MeshActor actor1 = MeshActor::New(mesh);
180 catch(Dali::DaliException& e)
182 DALI_TEST_PRINT_ASSERT( e );
183 DALI_TEST_ASSERT(e, "!faceIndices.empty", TEST_LOCATION );
188 int UtcDaliMeshActorCreateSetData03(void)
190 TestApplication application;
191 tet_infoline("Testing Dali::MeshData::SetData - Create with no mats");
195 MeshData::VertexContainer vertices;
196 MeshData::FaceIndices faces;
198 Material customMaterial;
199 ConstructVertices(vertices, 60);
200 ConstructFaces(vertices, faces);
201 meshData.SetData(vertices, faces, bones, customMaterial);
202 Mesh mesh = Mesh::New(meshData);
203 MeshActor actor1 = MeshActor::New(mesh);
205 catch(Dali::DaliException& e)
207 DALI_TEST_PRINT_ASSERT( e );
208 DALI_TEST_ASSERT(e, "material", TEST_LOCATION );
213 int UtcDaliMeshActorCreateSetData04(void)
215 TestApplication application;
216 tet_infoline("Testing Dali::MeshActor::SetData()");
219 MeshData::VertexContainer vertices;
220 MeshData::FaceIndices faces;
222 ConstructVertices(vertices, 60);
223 ConstructFaces(vertices, faces);
224 Material customMaterial = ConstructMaterial();
225 meshData.SetData(vertices, faces, bones, customMaterial);
227 Mesh mesh = Mesh::New(meshData);
228 MeshActor actor1 = MeshActor::New(mesh);
229 DALI_TEST_CHECK(actor1);
234 int UtcDaliMeshActorDownCast(void)
236 TestApplication application;
237 tet_infoline("Testing Dali::MeshActor::DownCast()");
240 MeshData::VertexContainer vertices;
241 MeshData::FaceIndices faces;
243 ConstructVertices(vertices, 60);
244 ConstructFaces(vertices, faces);
245 Material customMaterial = ConstructMaterial();
246 meshData.SetData(vertices, faces, bones, customMaterial);
247 Mesh mesh = Mesh::New(meshData);
249 MeshActor actor1 = MeshActor::New(mesh);
250 Actor anActor = Actor::New();
253 Actor child = anActor.GetChildAt(0);
254 MeshActor meshActor = MeshActor::DownCast(child);
256 DALI_TEST_CHECK(meshActor);
260 int UtcDaliMeshActorDownCast2(void)
262 TestApplication application;
263 tet_infoline("Testing Dali::MeshActor::DownCast()");
265 Actor actor1 = Actor::New();
266 Actor anActor = Actor::New();
269 Actor child = anActor.GetChildAt(0);
270 MeshActor meshActor = MeshActor::DownCast(child);
271 DALI_TEST_CHECK(!meshActor);
273 Actor unInitialzedActor;
274 meshActor = DownCast< MeshActor >( unInitialzedActor );
275 DALI_TEST_CHECK(!meshActor);
279 int UtcDaliMeshActorSetMaterial01(void)
281 TestApplication application;
282 tet_infoline("Testing Dali::MeshActor::SetMaterial()");
284 Mesh mesh = NewMesh();
286 MeshActor actor = MeshActor::New(mesh);
287 std::string name = "AMeshActor";
288 Stage::GetCurrent().Add(actor);
290 application.SendNotification();
291 application.Render();
292 application.Render();
293 application.SendNotification();
295 Material customMaterial = Material::New("CustomMaterial");
296 customMaterial.SetDiffuseColor(Vector4(1.0f, 0.0f, 0.0f, 1.0f));
298 MeshActor::SetMaterial(actor, name, customMaterial);
299 application.SendNotification();
300 application.Render();
301 application.Render();
302 application.SendNotification();
304 DALI_TEST_CHECK( actor.GetMaterial() == customMaterial );
308 int UtcDaliMeshActorSetMaterial01b(void)
310 TestApplication application;
311 tet_infoline("Testing Dali::MeshActor::SetMaterial()");
313 Mesh mesh = NewMesh();
315 Actor rootActor = Actor::New();
316 MeshActor meshActor = MeshActor::New(mesh);
317 rootActor.Add(meshActor);
319 std::string name = "AMeshActor";
320 meshActor.SetName(name);
322 Stage::GetCurrent().Add(rootActor);
323 application.SendNotification();
324 application.Render();
325 application.Render();
326 application.SendNotification();
328 Material customMaterial = Material::New("CustomMaterial");
329 customMaterial.SetDiffuseColor(Vector4(1.0f, 0.0f, 0.0f, 1.0f));
331 MeshActor::SetMaterial(rootActor, name, customMaterial);
332 application.SendNotification();
333 application.Render();
334 application.Render();
335 application.SendNotification();
337 DALI_TEST_CHECK(meshActor.GetMaterial() == customMaterial );
342 int UtcDaliMeshActorSetMaterial02(void)
344 TestApplication application;
345 tet_infoline("Testing Dali::MeshActor::SetMaterial()");
347 Mesh mesh = NewMesh();
348 MeshActor actor = MeshActor::New(mesh);
350 std::string name = "AMeshActor";
352 Stage::GetCurrent().Add(actor);
353 application.SendNotification();
354 application.Render();
355 application.Render();
356 application.SendNotification();
358 Material baseMat = actor.GetMaterial();
359 Material customMaterial = Material::New("CustomMaterial");
360 customMaterial.SetDiffuseColor(Vector4(1.0f, 0.0f, 0.0f, 1.0f));
362 MeshActor::SetMaterial(actor, "NoName", customMaterial);
363 application.SendNotification();
364 application.Render();
365 application.Render();
366 application.SendNotification();
368 DALI_TEST_CHECK( actor.GetMaterial() == baseMat );
369 DALI_TEST_CHECK( actor.GetMaterial() != customMaterial );
373 int UtcDaliMeshActorSetMaterial02b(void)
375 TestApplication application;
376 tet_infoline("Testing Dali::MeshActor::SetMaterial()");
378 Mesh mesh = NewMesh();
380 MeshActor actor = MeshActor::New(mesh);
381 Stage::GetCurrent().Add(actor);
383 std::string name = "AMeshActor";
385 application.SendNotification();
386 application.Render();
387 application.Render();
388 application.SendNotification();
390 Material baseMat = actor.GetMaterial();
391 Material customMaterial = Material::New("CustomMaterial");
392 customMaterial.SetDiffuseColor(Vector4(1.0f, 0.0f, 0.0f, 1.0f));
394 MeshActor::SetMaterial(actor, "NoName", customMaterial);
395 application.SendNotification();
396 application.Render();
397 application.Render();
398 application.SendNotification();
400 DALI_TEST_CHECK( actor.GetMaterial() == baseMat );
401 DALI_TEST_CHECK( actor.GetMaterial() != customMaterial );
406 int UtcDaliMeshActorSetMaterial03(void)
408 TestApplication application;
409 tet_infoline("Testing Dali::MeshActor::SetMaterial()");
411 Mesh mesh = NewMesh();
413 MeshActor actor = MeshActor::New(mesh);
414 std::string name = "AMeshActor";
416 Stage::GetCurrent().Add(actor);
418 Material customMaterial = Material::New("CustomMaterial");
419 customMaterial.SetDiffuseColor(Vector4(1.0f, 0.0f, 0.0f, 1.0f));
421 actor.SetMaterial(customMaterial);
422 application.SendNotification();
423 application.Render(0);
424 application.Render(16);
425 application.SendNotification();
427 DALI_TEST_CHECK(actor.GetMaterial() == customMaterial );
431 int UtcDaliMeshActorSetMaterial03b(void)
433 TestApplication application;
434 tet_infoline("Testing Dali::MeshActor::SetMaterial()");
436 Mesh mesh = NewMesh();
438 MeshActor actor = MeshActor::New(mesh);
439 std::string name = "AMeshActor";
441 Stage::GetCurrent().Add(actor);
443 Material customMaterial = Material::New("CustomMaterial");
444 customMaterial.SetDiffuseColor(Vector4(1.0f, 0.0f, 0.0f, 1.0f));
446 actor.SetMaterial(customMaterial);
447 application.SendNotification();
448 application.Render(0);
449 application.Render(16);
450 application.SendNotification();
451 DALI_TEST_CHECK(actor.GetMaterial() == customMaterial );
457 int UtcDaliMeshActorGetMaterial01(void)
459 TestApplication application;
460 tet_infoline("Testing Dali::MeshActor::SetMaterial()");
463 MeshData::VertexContainer vertices;
464 MeshData::FaceIndices faces;
466 ConstructVertices(vertices, 60);
467 ConstructFaces(vertices, faces);
468 Material material = ConstructMaterial();
469 meshData.SetData(vertices, faces, bones, material);
470 Mesh mesh = Mesh::New(meshData);
472 MeshActor actor = MeshActor::New(mesh);
473 std::string name = "AMeshActor";
475 application.SendNotification();
476 application.Render();
477 application.Render();
478 application.SendNotification();
480 Material gotMaterial = actor.GetMaterial();
482 DALI_TEST_EQUALS( material.GetOpacity(), gotMaterial.GetOpacity(), TEST_LOCATION );
483 DALI_TEST_EQUALS( material.GetAmbientColor(), gotMaterial.GetAmbientColor(), TEST_LOCATION );
484 DALI_TEST_EQUALS( material.GetDiffuseColor(), gotMaterial.GetDiffuseColor(), TEST_LOCATION );
485 DALI_TEST_EQUALS( material.GetSpecularColor(), gotMaterial.GetSpecularColor(), TEST_LOCATION );
490 int UtcDaliMeshActorGetMaterial02(void)
492 TestApplication application;
493 tet_infoline("Testing Dali::MeshActor::SetMaterial()");
496 MeshData::VertexContainer vertices;
497 MeshData::FaceIndices faces;
499 ConstructVertices(vertices, 60);
500 ConstructFaces(vertices, faces);
501 Material material = ConstructMaterial();
502 meshData.SetData(vertices, faces, bones, material);
503 Mesh mesh = Mesh::New(meshData);
505 MeshActor actor = MeshActor::New(mesh);
506 std::string name = "AMeshActor";
508 application.SendNotification();
509 application.Render();
510 application.Render();
511 application.SendNotification();
513 Material gotMaterial = actor.GetMaterial();
515 DALI_TEST_EQUALS( material.GetOpacity(), gotMaterial.GetOpacity(), TEST_LOCATION );
516 DALI_TEST_EQUALS( material.GetAmbientColor(), gotMaterial.GetAmbientColor(), TEST_LOCATION );
517 DALI_TEST_EQUALS( material.GetDiffuseColor(), gotMaterial.GetDiffuseColor(), TEST_LOCATION );
518 DALI_TEST_EQUALS( material.GetSpecularColor(), gotMaterial.GetSpecularColor(), TEST_LOCATION );
526 Material ConstructMaterial(float opacity, float diffuseOpacity)
528 Material customMaterial = Material::New("CustomMaterial");
529 customMaterial.SetOpacity(opacity);
530 customMaterial.SetDiffuseColor(Vector4(0.8f, 0.0f, 0.4f, diffuseOpacity));
531 customMaterial.SetAmbientColor(Vector4(0.2f, 1.0f, 0.6f, 1.0f));
532 customMaterial.SetSpecularColor(Vector4(0.5f, 0.6f, 0.7f, 1.0f));
533 return customMaterial;
536 static void TestBlending( TestApplication& application, Material material, float actorOpacity, BlendingMode::Type blendingMode, bool expectedBlend )
539 MeshData::VertexContainer vertices;
540 MeshData::FaceIndices faces;
542 ConstructVertices(vertices, 60);
543 ConstructFaces(vertices, faces);
544 meshData.SetData(vertices, faces, bones, material);
545 Mesh mesh = Mesh::New(meshData);
547 application.SendNotification();
548 application.Render(0);
549 application.Render();
550 application.SendNotification();
552 MeshActor actor = MeshActor::New(mesh);
553 Stage::GetCurrent().Add(actor);
555 actor.SetBlendMode(blendingMode);
556 actor.SetOpacity(actorOpacity);
558 TraceCallStack& cullFaceTrace = application.GetGlAbstraction().GetCullFaceTrace();
559 cullFaceTrace.Enable(true);
560 application.SendNotification();
561 application.Render();
562 DALI_TEST_EQUALS( BlendEnabled( cullFaceTrace ), expectedBlend, TEST_LOCATION );
564 } //anonymous namespace
567 int UtcDaliMeshActorBlend01(void)
569 // Set Material with translucent color, actor color opaque, Set Use image alpha to true
572 TestApplication application;
573 tet_infoline("Testing Dali::MeshActor::Blend01()");
575 TestBlending( application, ConstructMaterial(0.5f, 0.5f), 1.0f, BlendingMode::AUTO, true );
580 int UtcDaliMeshActorBlend02(void)
582 // Set material to translucent, set use image alpha to false, set actor opacity to 1.0f
583 // Expect no blending
585 TestApplication application;
586 tet_infoline("Testing Dali::MeshActor::Blend02()");
587 TestBlending( application, ConstructMaterial(0.5f, 0.5f), 1.0f, BlendingMode::OFF, false );
591 int UtcDaliMeshActorBlend03(void)
593 // Set material to opaque, set use image alpha to true, set actor opacity to 1.0f
594 // Expect no blending
596 TestApplication application;
597 tet_infoline("Testing Dali::MeshActor::Blend03()");
598 TestBlending( application, ConstructMaterial(1.0f, 1.0f), 1.0f, BlendingMode::AUTO, false );
603 int UtcDaliMeshActorBlend04(void)
605 // Set material to have image with alpha, set use image alpha to true, set actor opacity to 1.0f
607 TestApplication application;
608 tet_infoline("Testing Dali::MeshActor::Blend04()");
610 Material material = ConstructMaterial(1.0f, 1.0f);
611 BufferImage image = BufferImage::New( 100, 50, Pixel::RGBA8888 );
612 material.SetDiffuseTexture( image );
613 application.SendNotification();
614 application.Render(0);
616 TestBlending( application, material, 1.0f, BlendingMode::AUTO, true );
620 int UtcDaliMeshActorBlend05(void)
622 // Set material to have image with alpha, set use image alpha to false, set actor opacity to 1.0f
623 // Expect no blending
625 TestApplication application;
626 tet_infoline("Testing Dali::MeshActor::Blend05()");
628 Material material = ConstructMaterial(1.0f, 1.0f);
629 BufferImage image = BufferImage::New( 100, 50, Pixel::RGBA8888 );
630 material.SetDiffuseTexture( image );
631 application.SendNotification();
632 application.Render(0);
634 TestBlending( application, material, 1.0f, BlendingMode::ON, true );
639 int UtcDaliMeshActorBlend06(void)
641 // Set material to have image without alpha, set use image alpha to true, set actor opacity to 1.0f
642 // Expect no blending
644 TestApplication application;
645 tet_infoline("Testing Dali::MeshActor::Blend()");
647 Material material = ConstructMaterial(1.0f, 1.0f);
648 BufferImage image = BufferImage::New( 100, 50, Pixel::RGB888 );
649 material.SetDiffuseTexture( image );
650 application.SendNotification();
651 application.Render(0);
653 TestBlending( application, material, 1.0f, BlendingMode::AUTO, false );
657 int UtcDaliMeshActorBlend07(void)
659 // Set material to have framebuffer with alpha, set use image alpha to true, set actor opacity to 1.0f
661 TestApplication application;
662 tet_infoline("Testing Dali::MeshActor::Blend07()");
663 application.Render(0);
665 Material material = ConstructMaterial(1.0f, 1.0f);
666 FrameBufferImage image = FrameBufferImage::New( 100, 50, Pixel::RGBA8888 );
667 RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
668 RenderTask task = taskList.GetTask( 0u );
669 task.SetTargetFrameBuffer( image ); // To ensure frame buffer is connected
670 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
671 application.SendNotification();
672 application.Render();
674 material.SetDiffuseTexture( image ); // (to render from)
675 application.SendNotification();
676 application.Render();
677 application.Render();
678 application.SendNotification();
680 TestBlending( application, material, 1.0f, BlendingMode::AUTO, true );
684 int UtcDaliMeshActorBlend08(void)
686 // Set material to have image with alpha, set use image alpha to false, set actor opacity to 0.5f
688 TestApplication application;
689 tet_infoline("Testing Dali::MeshActor::Blend08()");
691 Material material = ConstructMaterial(1.0f, 1.0f);
692 BufferImage image = BufferImage::New( 100, 50, Pixel::RGBA8888 );
693 material.SetDiffuseTexture( image );
694 application.SendNotification();
695 application.Render(0);
697 TestBlending( application, material, 0.5f, BlendingMode::AUTO, true );
701 int UtcDaliMeshActorBlend09(void)
703 // Set material to have image with no alpha, set material opacity to 0.5, set use image alpha to true, set actor opacity to 1.0f
705 TestApplication application;
706 tet_infoline("Testing Dali::MeshActor::Blend08()");
708 Material material = ConstructMaterial(0.5f, 1.0f);
709 BufferImage image = BufferImage::New( 100, 50, Pixel::RGB888 );
710 material.SetDiffuseTexture( image );
711 application.SendNotification();
712 application.Render(0);
714 TestBlending( application, material, 1.0f, BlendingMode::AUTO, true );
718 // Test that bones update the mesh's bone transform uniforms
719 // (Removed old test - wasn't checking the above information, but instead the property
720 // info, which is tested elsewhere)
722 int UtcDaliMeshActorIndices(void)
724 TestApplication application;
725 Actor basicActor = Actor::New();
726 Mesh mesh = NewMesh();
727 MeshActor meshActor = MeshActor::New(mesh);
729 Property::IndexContainer indices;
730 meshActor.GetPropertyIndices( indices );
731 DALI_TEST_CHECK( indices.size() == basicActor.GetPropertyCount() ); // Mesh Actor does not have any properties
732 DALI_TEST_EQUALS( indices.size(), meshActor.GetPropertyCount(), TEST_LOCATION );
736 int UtcDaliAnimatableMeshActorIndices(void)
738 TestApplication application;
739 Actor basicActor = Actor::New();
740 AnimatableMesh mesh = NewAnimatableMesh();
741 MeshActor meshActor = MeshActor::New(mesh);
743 Property::IndexContainer indices;
744 meshActor.GetPropertyIndices( indices );
745 DALI_TEST_CHECK( indices.size() == basicActor.GetPropertyCount() ); // Mesh Actor does not have any properties
746 DALI_TEST_EQUALS( indices.size(), meshActor.GetPropertyCount(), TEST_LOCATION );