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-test-suite-utils.h>
26 #include <mesh-builder.h>
28 void mesh_actor_test_startup(void)
30 test_return_value = TET_UNDEF;
33 void mesh_actor_test_cleanup(void)
35 test_return_value = TET_PASS;
44 MeshData::VertexContainer vertices;
45 MeshData::FaceIndices faces;
47 ConstructVertices(vertices, 60);
48 ConstructFaces(vertices, faces);
49 Material customMaterial = ConstructMaterial();
50 meshData.SetData(vertices, faces, bones, customMaterial);
51 Mesh mesh = Mesh::New(meshData);
55 static AnimatableMesh NewAnimatableMesh()
57 AnimatableMesh::Faces faces;
62 Material customMaterial = Material::New("CustomMaterial");
63 customMaterial.SetOpacity(.76f);
64 customMaterial.SetDiffuseColor(Vector4(0.8f, 0.0f, 0.4f, 1.0f));
65 customMaterial.SetAmbientColor(Vector4(0.2f, 1.0f, 0.6f, 1.0f));
66 customMaterial.SetSpecularColor(Vector4(0.5f, 0.6f, 0.7f, 1.0f));
68 AnimatableMesh mesh = AnimatableMesh::New( 10u, faces, customMaterial );
71 } // anonymous namespace
73 int UtcDaliMeshActorConstructorVoid(void)
75 TestApplication application;
76 tet_infoline("Testing Dali::MeshActor::MeshActor()");
79 DALI_TEST_CHECK(!actor);
83 int UtcDaliMeshActorNew01(void)
85 TestApplication application;
86 tet_infoline("Testing Dali::MeshActor::New()");
88 AnimatableMesh mesh = NewAnimatableMesh();
89 MeshActor actor = MeshActor::New(mesh);
90 application.SendNotification();
93 application.SendNotification();
95 DALI_TEST_CHECK(actor);
100 int UtcDaliMeshActorNew03(void)
102 TestApplication application;
103 tet_infoline("Testing Dali::Mesh::New() - Create with no mesh");
107 MeshActor actor = MeshActor::New(); // Shouldn't assert
108 tet_result(TET_PASS);
110 catch (Dali::DaliException& e)
112 tet_result(TET_FAIL);
118 int UtcDaliMeshActorCreateNoMeshData(void)
120 TestApplication application;
121 tet_infoline("Testing Dali::Mesh::New() - Create with no mesh data");
126 Mesh mesh = Mesh::New(meshData);
127 MeshActor actor1 = MeshActor::New(mesh);
129 catch(Dali::DaliException& e)
131 DALI_TEST_PRINT_ASSERT( e );
132 DALI_TEST_ASSERT(e, "object", TEST_LOCATION);
138 int UtcDaliMeshActorCreateSetData01(void)
140 TestApplication application;
141 tet_infoline("Testing Dali::MeshData::SetData() - Create with no verts");
145 MeshData::VertexContainer vertices;
146 MeshData::FaceIndices faces;
148 Material customMaterial;
149 meshData.SetData(vertices, faces, bones, customMaterial);
150 Mesh mesh = Mesh::New(meshData);
151 MeshActor actor1 = MeshActor::New(mesh);
153 catch(Dali::DaliException& e)
155 DALI_TEST_PRINT_ASSERT( e );
156 DALI_TEST_ASSERT(e, "!vertices.empty()", TEST_LOCATION );
161 int UtcDaliMeshActorCreateSetData02(void)
163 TestApplication application;
164 tet_infoline("Testing Dali::MeshData::SetData - Create with no faces");
168 MeshData::VertexContainer vertices;
169 MeshData::FaceIndices faces;
171 Material customMaterial;
172 ConstructVertices(vertices, 60);
173 meshData.SetData(vertices, faces, bones, customMaterial);
174 Mesh mesh = Mesh::New(meshData);
175 MeshActor actor1 = MeshActor::New(mesh);
177 catch(Dali::DaliException& e)
179 DALI_TEST_PRINT_ASSERT( e );
180 DALI_TEST_ASSERT(e, "!faceIndices.empty", TEST_LOCATION );
185 int UtcDaliMeshActorCreateSetData03(void)
187 TestApplication application;
188 tet_infoline("Testing Dali::MeshData::SetData - Create with no mats");
192 MeshData::VertexContainer vertices;
193 MeshData::FaceIndices faces;
195 Material customMaterial;
196 ConstructVertices(vertices, 60);
197 ConstructFaces(vertices, faces);
198 meshData.SetData(vertices, faces, bones, customMaterial);
199 Mesh mesh = Mesh::New(meshData);
200 MeshActor actor1 = MeshActor::New(mesh);
202 catch(Dali::DaliException& e)
204 DALI_TEST_PRINT_ASSERT( e );
205 DALI_TEST_ASSERT(e, "material", TEST_LOCATION );
210 int UtcDaliMeshActorCreateSetData04(void)
212 TestApplication application;
213 tet_infoline("Testing Dali::MeshActor::SetData()");
216 MeshData::VertexContainer vertices;
217 MeshData::FaceIndices faces;
219 ConstructVertices(vertices, 60);
220 ConstructFaces(vertices, faces);
221 Material customMaterial = ConstructMaterial();
222 meshData.SetData(vertices, faces, bones, customMaterial);
224 Mesh mesh = Mesh::New(meshData);
225 MeshActor actor1 = MeshActor::New(mesh);
226 DALI_TEST_CHECK(actor1);
231 int UtcDaliMeshActorDownCast(void)
233 TestApplication application;
234 tet_infoline("Testing Dali::MeshActor::DownCast()");
237 MeshData::VertexContainer vertices;
238 MeshData::FaceIndices faces;
240 ConstructVertices(vertices, 60);
241 ConstructFaces(vertices, faces);
242 Material customMaterial = ConstructMaterial();
243 meshData.SetData(vertices, faces, bones, customMaterial);
244 Mesh mesh = Mesh::New(meshData);
246 MeshActor actor1 = MeshActor::New(mesh);
247 Actor anActor = Actor::New();
250 Actor child = anActor.GetChildAt(0);
251 MeshActor meshActor = MeshActor::DownCast(child);
253 DALI_TEST_CHECK(meshActor);
257 int UtcDaliMeshActorDownCast2(void)
259 TestApplication application;
260 tet_infoline("Testing Dali::MeshActor::DownCast()");
262 Actor actor1 = Actor::New();
263 Actor anActor = Actor::New();
266 Actor child = anActor.GetChildAt(0);
267 MeshActor meshActor = MeshActor::DownCast(child);
268 DALI_TEST_CHECK(!meshActor);
270 Actor unInitialzedActor;
271 meshActor = DownCast< MeshActor >( unInitialzedActor );
272 DALI_TEST_CHECK(!meshActor);
276 int UtcDaliMeshActorSetMaterial01(void)
278 TestApplication application;
279 tet_infoline("Testing Dali::MeshActor::SetMaterial()");
281 Mesh mesh = NewMesh();
283 MeshActor actor = MeshActor::New(mesh);
284 std::string name = "AMeshActor";
285 Stage::GetCurrent().Add(actor);
287 application.SendNotification();
288 application.Render();
289 application.Render();
290 application.SendNotification();
292 Material customMaterial = Material::New("CustomMaterial");
293 customMaterial.SetDiffuseColor(Vector4(1.0f, 0.0f, 0.0f, 1.0f));
295 MeshActor::SetMaterial(actor, name, customMaterial);
296 application.SendNotification();
297 application.Render();
298 application.Render();
299 application.SendNotification();
301 DALI_TEST_CHECK( actor.GetMaterial() == customMaterial );
305 int UtcDaliMeshActorSetMaterial01b(void)
307 TestApplication application;
308 tet_infoline("Testing Dali::MeshActor::SetMaterial()");
310 Mesh mesh = NewMesh();
312 Actor rootActor = Actor::New();
313 MeshActor meshActor = MeshActor::New(mesh);
314 rootActor.Add(meshActor);
316 std::string name = "AMeshActor";
317 meshActor.SetName(name);
319 Stage::GetCurrent().Add(rootActor);
320 application.SendNotification();
321 application.Render();
322 application.Render();
323 application.SendNotification();
325 Material customMaterial = Material::New("CustomMaterial");
326 customMaterial.SetDiffuseColor(Vector4(1.0f, 0.0f, 0.0f, 1.0f));
328 MeshActor::SetMaterial(rootActor, name, customMaterial);
329 application.SendNotification();
330 application.Render();
331 application.Render();
332 application.SendNotification();
334 DALI_TEST_CHECK(meshActor.GetMaterial() == customMaterial );
339 int UtcDaliMeshActorSetMaterial02(void)
341 TestApplication application;
342 tet_infoline("Testing Dali::MeshActor::SetMaterial()");
344 Mesh mesh = NewMesh();
345 MeshActor actor = MeshActor::New(mesh);
347 std::string name = "AMeshActor";
349 Stage::GetCurrent().Add(actor);
350 application.SendNotification();
351 application.Render();
352 application.Render();
353 application.SendNotification();
355 Material baseMat = actor.GetMaterial();
356 Material customMaterial = Material::New("CustomMaterial");
357 customMaterial.SetDiffuseColor(Vector4(1.0f, 0.0f, 0.0f, 1.0f));
359 MeshActor::SetMaterial(actor, "NoName", customMaterial);
360 application.SendNotification();
361 application.Render();
362 application.Render();
363 application.SendNotification();
365 DALI_TEST_CHECK( actor.GetMaterial() == baseMat );
366 DALI_TEST_CHECK( actor.GetMaterial() != customMaterial );
370 int UtcDaliMeshActorSetMaterial02b(void)
372 TestApplication application;
373 tet_infoline("Testing Dali::MeshActor::SetMaterial()");
375 Mesh mesh = NewMesh();
377 MeshActor actor = MeshActor::New(mesh);
378 Stage::GetCurrent().Add(actor);
380 std::string name = "AMeshActor";
382 application.SendNotification();
383 application.Render();
384 application.Render();
385 application.SendNotification();
387 Material baseMat = actor.GetMaterial();
388 Material customMaterial = Material::New("CustomMaterial");
389 customMaterial.SetDiffuseColor(Vector4(1.0f, 0.0f, 0.0f, 1.0f));
391 MeshActor::SetMaterial(actor, "NoName", customMaterial);
392 application.SendNotification();
393 application.Render();
394 application.Render();
395 application.SendNotification();
397 DALI_TEST_CHECK( actor.GetMaterial() == baseMat );
398 DALI_TEST_CHECK( actor.GetMaterial() != customMaterial );
403 int UtcDaliMeshActorSetMaterial03(void)
405 TestApplication application;
406 tet_infoline("Testing Dali::MeshActor::SetMaterial()");
408 Mesh mesh = NewMesh();
410 MeshActor actor = MeshActor::New(mesh);
411 std::string name = "AMeshActor";
413 Stage::GetCurrent().Add(actor);
415 Material customMaterial = Material::New("CustomMaterial");
416 customMaterial.SetDiffuseColor(Vector4(1.0f, 0.0f, 0.0f, 1.0f));
418 actor.SetMaterial(customMaterial);
419 application.SendNotification();
420 application.Render(0);
421 application.Render(16);
422 application.SendNotification();
424 DALI_TEST_CHECK(actor.GetMaterial() == customMaterial );
428 int UtcDaliMeshActorSetMaterial03b(void)
430 TestApplication application;
431 tet_infoline("Testing Dali::MeshActor::SetMaterial()");
433 Mesh mesh = NewMesh();
435 MeshActor actor = MeshActor::New(mesh);
436 std::string name = "AMeshActor";
438 Stage::GetCurrent().Add(actor);
440 Material customMaterial = Material::New("CustomMaterial");
441 customMaterial.SetDiffuseColor(Vector4(1.0f, 0.0f, 0.0f, 1.0f));
443 actor.SetMaterial(customMaterial);
444 application.SendNotification();
445 application.Render(0);
446 application.Render(16);
447 application.SendNotification();
448 DALI_TEST_CHECK(actor.GetMaterial() == customMaterial );
454 int UtcDaliMeshActorGetMaterial01(void)
456 TestApplication application;
457 tet_infoline("Testing Dali::MeshActor::SetMaterial()");
460 MeshData::VertexContainer vertices;
461 MeshData::FaceIndices faces;
463 ConstructVertices(vertices, 60);
464 ConstructFaces(vertices, faces);
465 Material material = ConstructMaterial();
466 meshData.SetData(vertices, faces, bones, material);
467 Mesh mesh = Mesh::New(meshData);
469 MeshActor actor = MeshActor::New(mesh);
470 std::string name = "AMeshActor";
472 application.SendNotification();
473 application.Render();
474 application.Render();
475 application.SendNotification();
477 Material gotMaterial = actor.GetMaterial();
479 DALI_TEST_EQUALS( material.GetOpacity(), gotMaterial.GetOpacity(), TEST_LOCATION );
480 DALI_TEST_EQUALS( material.GetAmbientColor(), gotMaterial.GetAmbientColor(), TEST_LOCATION );
481 DALI_TEST_EQUALS( material.GetDiffuseColor(), gotMaterial.GetDiffuseColor(), TEST_LOCATION );
482 DALI_TEST_EQUALS( material.GetSpecularColor(), gotMaterial.GetSpecularColor(), TEST_LOCATION );
487 int UtcDaliMeshActorGetMaterial02(void)
489 TestApplication application;
490 tet_infoline("Testing Dali::MeshActor::SetMaterial()");
493 MeshData::VertexContainer vertices;
494 MeshData::FaceIndices faces;
496 ConstructVertices(vertices, 60);
497 ConstructFaces(vertices, faces);
498 Material material = ConstructMaterial();
499 meshData.SetData(vertices, faces, bones, material);
500 Mesh mesh = Mesh::New(meshData);
502 MeshActor actor = MeshActor::New(mesh);
503 std::string name = "AMeshActor";
505 application.SendNotification();
506 application.Render();
507 application.Render();
508 application.SendNotification();
510 Material gotMaterial = actor.GetMaterial();
512 DALI_TEST_EQUALS( material.GetOpacity(), gotMaterial.GetOpacity(), TEST_LOCATION );
513 DALI_TEST_EQUALS( material.GetAmbientColor(), gotMaterial.GetAmbientColor(), TEST_LOCATION );
514 DALI_TEST_EQUALS( material.GetDiffuseColor(), gotMaterial.GetDiffuseColor(), TEST_LOCATION );
515 DALI_TEST_EQUALS( material.GetSpecularColor(), gotMaterial.GetSpecularColor(), TEST_LOCATION );
523 Material ConstructMaterial(float opacity, float diffuseOpacity)
525 Material customMaterial = Material::New("CustomMaterial");
526 customMaterial.SetOpacity(opacity);
527 customMaterial.SetDiffuseColor(Vector4(0.8f, 0.0f, 0.4f, diffuseOpacity));
528 customMaterial.SetAmbientColor(Vector4(0.2f, 1.0f, 0.6f, 1.0f));
529 customMaterial.SetSpecularColor(Vector4(0.5f, 0.6f, 0.7f, 1.0f));
530 return customMaterial;
533 static void TestBlending( TestApplication& application, Material material, float actorOpacity, BlendingMode::Type blendingMode, bool expectedBlend )
536 MeshData::VertexContainer vertices;
537 MeshData::FaceIndices faces;
539 ConstructVertices(vertices, 60);
540 ConstructFaces(vertices, faces);
541 meshData.SetData(vertices, faces, bones, material);
542 Mesh mesh = Mesh::New(meshData);
544 application.SendNotification();
545 application.Render(0);
546 application.Render();
547 application.SendNotification();
549 MeshActor actor = MeshActor::New(mesh);
550 Stage::GetCurrent().Add(actor);
552 actor.SetBlendMode(blendingMode);
553 actor.SetOpacity(actorOpacity);
555 TraceCallStack& cullFaceTrace = application.GetGlAbstraction().GetCullFaceTrace();
556 cullFaceTrace.Enable(true);
557 application.SendNotification();
558 application.Render();
559 DALI_TEST_EQUALS( BlendEnabled( cullFaceTrace ), expectedBlend, TEST_LOCATION );
561 } //anonymous namespace
564 int UtcDaliMeshActorBlend01(void)
566 // Set Material with translucent color, actor color opaque, Set Use image alpha to true
569 TestApplication application;
570 tet_infoline("Testing Dali::MeshActor::Blend01()");
572 TestBlending( application, ConstructMaterial(0.5f, 0.5f), 1.0f, BlendingMode::AUTO, true );
577 int UtcDaliMeshActorBlend02(void)
579 // Set material to translucent, set use image alpha to false, set actor opacity to 1.0f
580 // Expect no blending
582 TestApplication application;
583 tet_infoline("Testing Dali::MeshActor::Blend02()");
584 TestBlending( application, ConstructMaterial(0.5f, 0.5f), 1.0f, BlendingMode::OFF, false );
588 int UtcDaliMeshActorBlend03(void)
590 // Set material to opaque, set use image alpha to true, set actor opacity to 1.0f
591 // Expect no blending
593 TestApplication application;
594 tet_infoline("Testing Dali::MeshActor::Blend03()");
595 TestBlending( application, ConstructMaterial(1.0f, 1.0f), 1.0f, BlendingMode::AUTO, false );
600 int UtcDaliMeshActorBlend04(void)
602 // Set material to have image with alpha, set use image alpha to true, set actor opacity to 1.0f
604 TestApplication application;
605 tet_infoline("Testing Dali::MeshActor::Blend04()");
607 Material material = ConstructMaterial(1.0f, 1.0f);
608 BufferImage image = BufferImage::New( 100, 50, Pixel::RGBA8888 );
609 material.SetDiffuseTexture( image );
610 application.SendNotification();
611 application.Render(0);
613 TestBlending( application, material, 1.0f, BlendingMode::AUTO, true );
617 int UtcDaliMeshActorBlend05(void)
619 // Set material to have image with alpha, set use image alpha to false, set actor opacity to 1.0f
620 // Expect no blending
622 TestApplication application;
623 tet_infoline("Testing Dali::MeshActor::Blend05()");
625 Material material = ConstructMaterial(1.0f, 1.0f);
626 BufferImage image = BufferImage::New( 100, 50, Pixel::RGBA8888 );
627 material.SetDiffuseTexture( image );
628 application.SendNotification();
629 application.Render(0);
631 TestBlending( application, material, 1.0f, BlendingMode::ON, true );
636 int UtcDaliMeshActorBlend06(void)
638 // Set material to have image without alpha, set use image alpha to true, set actor opacity to 1.0f
639 // Expect no blending
641 TestApplication application;
642 tet_infoline("Testing Dali::MeshActor::Blend()");
644 Material material = ConstructMaterial(1.0f, 1.0f);
645 BufferImage image = BufferImage::New( 100, 50, Pixel::RGB888 );
646 material.SetDiffuseTexture( image );
647 application.SendNotification();
648 application.Render(0);
650 TestBlending( application, material, 1.0f, BlendingMode::AUTO, false );
654 int UtcDaliMeshActorBlend07(void)
656 // Set material to have framebuffer with alpha, set use image alpha to true, set actor opacity to 1.0f
658 TestApplication application;
659 tet_infoline("Testing Dali::MeshActor::Blend07()");
660 application.Render(0);
662 Material material = ConstructMaterial(1.0f, 1.0f);
663 FrameBufferImage image = FrameBufferImage::New( 100, 50, Pixel::RGBA8888 );
664 RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
665 RenderTask task = taskList.GetTask( 0u );
666 task.SetTargetFrameBuffer( image ); // To ensure frame buffer is connected
667 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
668 application.SendNotification();
669 application.Render();
671 material.SetDiffuseTexture( image ); // (to render from)
672 application.SendNotification();
673 application.Render();
674 application.Render();
675 application.SendNotification();
677 TestBlending( application, material, 1.0f, BlendingMode::AUTO, true );
681 int UtcDaliMeshActorBlend08(void)
683 // Set material to have image with alpha, set use image alpha to false, set actor opacity to 0.5f
685 TestApplication application;
686 tet_infoline("Testing Dali::MeshActor::Blend08()");
688 Material material = ConstructMaterial(1.0f, 1.0f);
689 BufferImage image = BufferImage::New( 100, 50, Pixel::RGBA8888 );
690 material.SetDiffuseTexture( image );
691 application.SendNotification();
692 application.Render(0);
694 TestBlending( application, material, 0.5f, BlendingMode::AUTO, true );
698 int UtcDaliMeshActorBlend09(void)
700 // 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
702 TestApplication application;
703 tet_infoline("Testing Dali::MeshActor::Blend08()");
705 Material material = ConstructMaterial(0.5f, 1.0f);
706 BufferImage image = BufferImage::New( 100, 50, Pixel::RGB888 );
707 material.SetDiffuseTexture( image );
708 application.SendNotification();
709 application.Render(0);
711 TestBlending( application, material, 1.0f, BlendingMode::AUTO, true );
715 // Test that bones update the mesh's bone transform uniforms
716 // (Removed old test - wasn't checking the above information, but instead the property
717 // info, which is tested elsewhere)
719 int UtcDaliMeshActorIndices(void)
721 TestApplication application;
722 Actor basicActor = Actor::New();
723 Mesh mesh = NewMesh();
724 MeshActor meshActor = MeshActor::New(mesh);
726 Property::IndexContainer indices;
727 meshActor.GetPropertyIndices( indices );
728 DALI_TEST_CHECK( indices.size() == basicActor.GetPropertyCount() ); // Mesh Actor does not have any properties
729 DALI_TEST_EQUALS( indices.size(), meshActor.GetPropertyCount(), TEST_LOCATION );
733 int UtcDaliAnimatableMeshActorIndices(void)
735 TestApplication application;
736 Actor basicActor = Actor::New();
737 AnimatableMesh mesh = NewAnimatableMesh();
738 MeshActor meshActor = MeshActor::New(mesh);
740 Property::IndexContainer indices;
741 meshActor.GetPropertyIndices( indices );
742 DALI_TEST_CHECK( indices.size() == basicActor.GetPropertyCount() ); // Mesh Actor does not have any properties
743 DALI_TEST_EQUALS( indices.size(), meshActor.GetPropertyCount(), TEST_LOCATION );