(AutomatedTests) Merged managed & unmanaged tests
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-MeshActor.cpp
1 /*
2  * Copyright (c) 2014 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 <iostream>
19
20 #include <stdlib.h>
21 #include <dali/public-api/dali-core.h>
22 #include <dali-test-suite-utils.h>
23
24 using namespace Dali;
25
26 #include <mesh-builder.h>
27
28 void mesh_actor_test_startup(void)
29 {
30   test_return_value = TET_UNDEF;
31 }
32
33 void mesh_actor_test_cleanup(void)
34 {
35   test_return_value = TET_PASS;
36 }
37
38 namespace
39 {
40
41 static Mesh NewMesh()
42 {
43   MeshData meshData;
44   MeshData::VertexContainer    vertices;
45   MeshData::FaceIndices        faces;
46   BoneContainer                bones;
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);
52   return mesh;
53 }
54
55 static AnimatableMesh NewAnimatableMesh()
56 {
57   AnimatableMesh::Faces faces;
58   faces.push_back(0);
59   faces.push_back(1);
60   faces.push_back(2);
61
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));
67
68   AnimatableMesh mesh = AnimatableMesh::New( 10u, faces, customMaterial );
69   return mesh;
70 }
71 } // anonymous namespace
72
73 int UtcDaliMeshActorConstructorVoid(void)
74 {
75   TestApplication application;
76   tet_infoline("Testing Dali::MeshActor::MeshActor()");
77
78   MeshActor actor;
79   DALI_TEST_CHECK(!actor);
80   END_TEST;
81 }
82
83 int UtcDaliMeshActorNew01(void)
84 {
85   TestApplication application;
86   tet_infoline("Testing Dali::MeshActor::New()");
87
88   AnimatableMesh mesh = NewAnimatableMesh();
89   MeshActor actor = MeshActor::New(mesh);
90   application.SendNotification();
91   application.Render();
92   application.Render();
93   application.SendNotification();
94
95   DALI_TEST_CHECK(actor);
96   END_TEST;
97 }
98
99 int UtcDaliMeshActorNew02(void)
100 {
101   TestApplication application;
102   TestPlatformAbstraction& platform = application.GetPlatform();
103
104   tet_infoline("Testing Dali::MeshActor::New()");
105
106   std::string modelName("AModel");
107   Dali::ModelData modelData = Dali::ModelData::New(modelName);
108   Dali::Entity rootEntity = Dali::Entity::New("root");
109   modelData.SetRootEntity(rootEntity);
110   rootEntity.SetType(Dali::Entity::OBJECT);
111
112   Model model = Model::New("Fake model");
113
114   // Run Core - will query using TestPlatformAbstraction::GetResources().
115   application.SendNotification();
116   application.Render();
117
118   Integration::ResourceRequest* request = platform.GetRequest();
119   if(request)
120   {
121     platform.SetResourceLoaded(request->GetId(), request->GetType()->id, Integration::ResourcePointer(&(modelData.GetBaseObject())));
122   }
123
124   application.Render();
125   application.SendNotification();
126
127   Actor actor = ModelActorFactory::BuildActorTree(model, ""); // model should be loaded
128
129   DALI_TEST_CHECK(model.GetLoadingState() == ResourceLoadingSucceeded);
130   DALI_TEST_CHECK(actor);
131   DALI_TEST_CHECK(actor.GetName().compare("root") == 0);
132   END_TEST;
133 }
134
135 int UtcDaliMeshActorNew03(void)
136 {
137   TestApplication application;
138   tet_infoline("Testing Dali::Mesh::New() - Create with no mesh");
139
140   try
141   {
142     MeshActor actor = MeshActor::New(); // Shouldn't assert
143     tet_result(TET_PASS);
144   }
145   catch (Dali::DaliException& e)
146   {
147     tet_result(TET_FAIL);
148   }
149
150   END_TEST;
151 }
152
153 int UtcDaliMeshActorCreateNoMeshData(void)
154 {
155   TestApplication application;
156   tet_infoline("Testing Dali::Mesh::New() - Create with no mesh data");
157
158   try
159   {
160     MeshData meshData;
161     Mesh mesh = Mesh::New(meshData);
162     MeshActor actor1 = MeshActor::New(mesh);
163   }
164   catch(Dali::DaliException& e)
165   {
166     DALI_TEST_PRINT_ASSERT( e );
167     DALI_TEST_ASSERT(e, "object", TEST_LOCATION);
168   }
169   END_TEST;
170 }
171
172
173 int UtcDaliMeshActorCreateSetData01(void)
174 {
175   TestApplication application;
176   tet_infoline("Testing Dali::MeshData::SetData() - Create with no verts");
177   try
178   {
179     MeshData meshData;
180     MeshData::VertexContainer vertices;
181     MeshData::FaceIndices     faces;
182     BoneContainer             bones;
183     Material                  customMaterial;
184     meshData.SetData(vertices, faces, bones, customMaterial);
185     Mesh mesh = Mesh::New(meshData);
186     MeshActor actor1 = MeshActor::New(mesh);
187   }
188   catch(Dali::DaliException& e)
189   {
190     DALI_TEST_PRINT_ASSERT( e );
191     DALI_TEST_ASSERT(e, "!vertices.empty()", TEST_LOCATION );
192   }
193   END_TEST;
194 }
195
196 int UtcDaliMeshActorCreateSetData02(void)
197 {
198   TestApplication application;
199   tet_infoline("Testing Dali::MeshData::SetData - Create with no faces");
200   try
201   {
202     MeshData meshData;
203     MeshData::VertexContainer    vertices;
204     MeshData::FaceIndices        faces;
205     BoneContainer                bones;
206     Material                     customMaterial;
207     ConstructVertices(vertices, 60);
208     meshData.SetData(vertices, faces, bones, customMaterial);
209     Mesh mesh = Mesh::New(meshData);
210     MeshActor actor1 = MeshActor::New(mesh);
211   }
212   catch(Dali::DaliException& e)
213   {
214     DALI_TEST_PRINT_ASSERT( e );
215     DALI_TEST_ASSERT(e, "!faceIndices.empty", TEST_LOCATION );
216   }
217   END_TEST;
218 }
219
220 int UtcDaliMeshActorCreateSetData03(void)
221 {
222   TestApplication application;
223   tet_infoline("Testing Dali::MeshData::SetData - Create with no mats");
224   try
225   {
226     MeshData meshData;
227     MeshData::VertexContainer    vertices;
228     MeshData::FaceIndices        faces;
229     BoneContainer                bones;
230     Material                     customMaterial;
231     ConstructVertices(vertices, 60);
232     ConstructFaces(vertices, faces);
233     meshData.SetData(vertices, faces, bones, customMaterial);
234     Mesh mesh = Mesh::New(meshData);
235     MeshActor actor1 = MeshActor::New(mesh);
236   }
237   catch(Dali::DaliException& e)
238   {
239     DALI_TEST_PRINT_ASSERT( e );
240     DALI_TEST_ASSERT(e, "material", TEST_LOCATION );
241   }
242   END_TEST;
243 }
244
245 int UtcDaliMeshActorCreateSetData04(void)
246 {
247   TestApplication application;
248   tet_infoline("Testing Dali::MeshActor::SetData()");
249
250   MeshData meshData;
251   MeshData::VertexContainer    vertices;
252   MeshData::FaceIndices        faces;
253   BoneContainer                bones;
254   ConstructVertices(vertices, 60);
255   ConstructFaces(vertices, faces);
256   Material customMaterial = ConstructMaterial();
257   meshData.SetData(vertices, faces, bones, customMaterial);
258
259   Mesh mesh = Mesh::New(meshData);
260   MeshActor actor1 = MeshActor::New(mesh);
261   DALI_TEST_CHECK(actor1);
262   END_TEST;
263 }
264
265
266 int UtcDaliMeshActorDownCast(void)
267 {
268   TestApplication application;
269   tet_infoline("Testing Dali::MeshActor::DownCast()");
270
271   MeshData meshData;
272   MeshData::VertexContainer    vertices;
273   MeshData::FaceIndices        faces;
274   BoneContainer                bones;
275   ConstructVertices(vertices, 60);
276   ConstructFaces(vertices, faces);
277   Material customMaterial = ConstructMaterial();
278   meshData.SetData(vertices, faces, bones, customMaterial);
279   Mesh mesh = Mesh::New(meshData);
280
281   MeshActor actor1 = MeshActor::New(mesh);
282   Actor anActor = Actor::New();
283   anActor.Add(actor1);
284
285   Actor child = anActor.GetChildAt(0);
286   MeshActor meshActor = MeshActor::DownCast(child);
287
288   DALI_TEST_CHECK(meshActor);
289   END_TEST;
290 }
291
292 int UtcDaliMeshActorDownCast2(void)
293 {
294   TestApplication application;
295   tet_infoline("Testing Dali::MeshActor::DownCast()");
296
297   Actor actor1 = Actor::New();
298   Actor anActor = Actor::New();
299   anActor.Add(actor1);
300
301   Actor child = anActor.GetChildAt(0);
302   MeshActor meshActor = MeshActor::DownCast(child);
303   DALI_TEST_CHECK(!meshActor);
304
305   Actor unInitialzedActor;
306   meshActor = DownCast< MeshActor >( unInitialzedActor );
307   DALI_TEST_CHECK(!meshActor);
308   END_TEST;
309 }
310
311 int UtcDaliMeshActorSetMaterial01(void)
312 {
313   TestApplication application;
314   tet_infoline("Testing Dali::MeshActor::SetMaterial()");
315
316   Mesh mesh = NewMesh();
317
318   MeshActor actor = MeshActor::New(mesh);
319   std::string name = "AMeshActor";
320   Stage::GetCurrent().Add(actor);
321   actor.SetName(name);
322   application.SendNotification();
323   application.Render();
324   application.Render();
325   application.SendNotification();
326
327   Material customMaterial = Material::New("CustomMaterial");
328   customMaterial.SetDiffuseColor(Vector4(1.0f, 0.0f, 0.0f, 1.0f));
329
330   MeshActor::SetMaterial(actor, name, customMaterial);
331   application.SendNotification();
332   application.Render();
333   application.Render();
334   application.SendNotification();
335
336   DALI_TEST_CHECK( actor.GetMaterial() == customMaterial );
337   END_TEST;
338 }
339
340 int UtcDaliMeshActorSetMaterial01b(void)
341 {
342   TestApplication application;
343   tet_infoline("Testing Dali::MeshActor::SetMaterial()");
344
345   Mesh mesh = NewMesh();
346
347   Actor rootActor = Actor::New();
348   MeshActor meshActor = MeshActor::New(mesh);
349   rootActor.Add(meshActor);
350
351   std::string name = "AMeshActor";
352   meshActor.SetName(name);
353
354   Stage::GetCurrent().Add(rootActor);
355   application.SendNotification();
356   application.Render();
357   application.Render();
358   application.SendNotification();
359
360   Material customMaterial = Material::New("CustomMaterial");
361   customMaterial.SetDiffuseColor(Vector4(1.0f, 0.0f, 0.0f, 1.0f));
362
363   MeshActor::SetMaterial(rootActor, name, customMaterial);
364   application.SendNotification();
365   application.Render();
366   application.Render();
367   application.SendNotification();
368
369   DALI_TEST_CHECK(meshActor.GetMaterial() == customMaterial );
370   END_TEST;
371 }
372
373
374 int UtcDaliMeshActorSetMaterial02(void)
375 {
376   TestApplication application;
377   tet_infoline("Testing Dali::MeshActor::SetMaterial()");
378
379   Mesh mesh = NewMesh();
380   MeshActor actor = MeshActor::New(mesh);
381
382   std::string name = "AMeshActor";
383   actor.SetName(name);
384   Stage::GetCurrent().Add(actor);
385   application.SendNotification();
386   application.Render();
387   application.Render();
388   application.SendNotification();
389
390   Material baseMat = actor.GetMaterial();
391   Material customMaterial = Material::New("CustomMaterial");
392   customMaterial.SetDiffuseColor(Vector4(1.0f, 0.0f, 0.0f, 1.0f));
393
394   MeshActor::SetMaterial(actor, "NoName", customMaterial);
395   application.SendNotification();
396   application.Render();
397   application.Render();
398   application.SendNotification();
399
400   DALI_TEST_CHECK( actor.GetMaterial() == baseMat );
401   DALI_TEST_CHECK( actor.GetMaterial() != customMaterial );
402   END_TEST;
403 }
404
405 int UtcDaliMeshActorSetMaterial02b(void)
406 {
407   TestApplication application;
408   tet_infoline("Testing Dali::MeshActor::SetMaterial()");
409
410   Mesh mesh = NewMesh();
411
412   MeshActor actor = MeshActor::New(mesh);
413   Stage::GetCurrent().Add(actor);
414
415   std::string name = "AMeshActor";
416   actor.SetName(name);
417   application.SendNotification();
418   application.Render();
419   application.Render();
420   application.SendNotification();
421
422   Material baseMat = actor.GetMaterial();
423   Material customMaterial = Material::New("CustomMaterial");
424   customMaterial.SetDiffuseColor(Vector4(1.0f, 0.0f, 0.0f, 1.0f));
425
426   MeshActor::SetMaterial(actor, "NoName", customMaterial);
427   application.SendNotification();
428   application.Render();
429   application.Render();
430   application.SendNotification();
431
432   DALI_TEST_CHECK( actor.GetMaterial() == baseMat );
433   DALI_TEST_CHECK( actor.GetMaterial() != customMaterial );
434   END_TEST;
435 }
436
437
438 int UtcDaliMeshActorSetMaterial03(void)
439 {
440   TestApplication application;
441   tet_infoline("Testing Dali::MeshActor::SetMaterial()");
442
443   Mesh mesh = NewMesh();
444
445   MeshActor actor = MeshActor::New(mesh);
446   std::string name = "AMeshActor";
447   actor.SetName(name);
448   Stage::GetCurrent().Add(actor);
449
450   Material customMaterial = Material::New("CustomMaterial");
451   customMaterial.SetDiffuseColor(Vector4(1.0f, 0.0f, 0.0f, 1.0f));
452
453   actor.SetMaterial(customMaterial);
454   application.SendNotification();
455   application.Render(0);
456   application.Render(16);
457   application.SendNotification();
458
459   DALI_TEST_CHECK(actor.GetMaterial() == customMaterial );
460   END_TEST;
461 }
462
463 int UtcDaliMeshActorSetMaterial03b(void)
464 {
465   TestApplication application;
466   tet_infoline("Testing Dali::MeshActor::SetMaterial()");
467
468   Mesh mesh = NewMesh();
469
470   MeshActor actor = MeshActor::New(mesh);
471   std::string name = "AMeshActor";
472   actor.SetName(name);
473   Stage::GetCurrent().Add(actor);
474
475   Material customMaterial = Material::New("CustomMaterial");
476   customMaterial.SetDiffuseColor(Vector4(1.0f, 0.0f, 0.0f, 1.0f));
477
478   actor.SetMaterial(customMaterial);
479   application.SendNotification();
480   application.Render(0);
481   application.Render(16);
482   application.SendNotification();
483   DALI_TEST_CHECK(actor.GetMaterial() == customMaterial );
484   END_TEST;
485 }
486
487
488
489 int UtcDaliMeshActorGetMaterial01(void)
490 {
491   TestApplication application;
492   tet_infoline("Testing Dali::MeshActor::SetMaterial()");
493
494   MeshData meshData;
495   MeshData::VertexContainer vertices;
496   MeshData::FaceIndices faces;
497   BoneContainer bones;
498   ConstructVertices(vertices, 60);
499   ConstructFaces(vertices, faces);
500   Material material = ConstructMaterial();
501   meshData.SetData(vertices, faces, bones, material);
502   Mesh mesh = Mesh::New(meshData);
503
504   MeshActor actor = MeshActor::New(mesh);
505   std::string name = "AMeshActor";
506   actor.SetName(name);
507   application.SendNotification();
508   application.Render();
509   application.Render();
510   application.SendNotification();
511
512   Material gotMaterial = actor.GetMaterial();
513
514   DALI_TEST_EQUALS( material.GetOpacity(), gotMaterial.GetOpacity(), TEST_LOCATION );
515   DALI_TEST_EQUALS( material.GetAmbientColor(), gotMaterial.GetAmbientColor(), TEST_LOCATION );
516   DALI_TEST_EQUALS( material.GetDiffuseColor(), gotMaterial.GetDiffuseColor(), TEST_LOCATION );
517   DALI_TEST_EQUALS( material.GetSpecularColor(), gotMaterial.GetSpecularColor(), TEST_LOCATION );
518   END_TEST;
519 }
520
521
522 int UtcDaliMeshActorGetMaterial02(void)
523 {
524   TestApplication application;
525   tet_infoline("Testing Dali::MeshActor::SetMaterial()");
526
527   MeshData meshData;
528   MeshData::VertexContainer vertices;
529   MeshData::FaceIndices faces;
530   BoneContainer bones;
531   ConstructVertices(vertices, 60);
532   ConstructFaces(vertices, faces);
533   Material material = ConstructMaterial();
534   meshData.SetData(vertices, faces, bones, material);
535   Mesh mesh = Mesh::New(meshData);
536
537   MeshActor actor = MeshActor::New(mesh);
538   std::string name = "AMeshActor";
539   actor.SetName(name);
540   application.SendNotification();
541   application.Render();
542   application.Render();
543   application.SendNotification();
544
545   Material gotMaterial = actor.GetMaterial();
546
547   DALI_TEST_EQUALS( material.GetOpacity(), gotMaterial.GetOpacity(), TEST_LOCATION );
548   DALI_TEST_EQUALS( material.GetAmbientColor(), gotMaterial.GetAmbientColor(), TEST_LOCATION );
549   DALI_TEST_EQUALS( material.GetDiffuseColor(), gotMaterial.GetDiffuseColor(), TEST_LOCATION );
550   DALI_TEST_EQUALS( material.GetSpecularColor(), gotMaterial.GetSpecularColor(), TEST_LOCATION );
551   END_TEST;
552 }
553
554 int UtcDaliMeshActorSetLighting01(void)
555 {
556   TestApplication application;
557   tet_infoline("Testing Dali::MeshActor::GetLighting()");
558
559   Mesh mesh = NewMesh();
560
561   MeshActor actor = MeshActor::New(mesh);
562   Stage::GetCurrent().Add(actor);
563
564   // Mesh actors should be lit by default
565   DALI_TEST_EQUALS(actor.IsAffectedByLighting(), true, TEST_LOCATION);
566   END_TEST;
567 }
568
569 int UtcDaliMeshActorSetLighting02(void)
570 {
571   TestApplication application;
572   tet_infoline("Testing Dali::MeshActor::SetLighting()");
573
574   Mesh mesh = NewMesh();
575   MeshActor actor = MeshActor::New(mesh);
576   Stage::GetCurrent().Add(actor);
577
578   application.SendNotification();
579   application.Render();
580   application.Render();
581   application.SendNotification();
582
583   Light light = Light::New("KeyLight");
584   light.SetFallOff(Vector2(10000.0f, 10000.0f));
585   LightActor keyLightActor = LightActor::New();
586   keyLightActor.SetParentOrigin(ParentOrigin::CENTER);
587   keyLightActor.SetPosition(200.0f, 500.0f, 300.0f);
588   keyLightActor.SetName(light.GetName());
589
590   Stage::GetCurrent().Add(keyLightActor);
591   keyLightActor.SetLight(light);
592   keyLightActor.SetActive(true);
593
594   actor.SetAffectedByLighting(true);
595   DALI_TEST_EQUALS(actor.IsAffectedByLighting(), true, TEST_LOCATION);
596
597   // Test rendering to ensure that the correct shader setup is used in renderer
598   // (check in debugger or via coverage)
599   application.Render(1);
600   application.SendNotification();
601   application.Render(1);
602   application.SendNotification();
603   application.Render(1);
604   application.SendNotification();
605   application.Render(1);
606   application.SendNotification();
607   application.Render(1);
608
609   actor.SetAffectedByLighting(false);
610   DALI_TEST_EQUALS(actor.IsAffectedByLighting(), false, TEST_LOCATION);
611
612   // Test rendering to ensure that the correct shader setup is used in renderer
613   // (check in debugger or via coverage)
614   application.Render(1);
615   application.SendNotification();
616   application.Render(1);
617   application.SendNotification();
618   application.Render(1);
619   application.SendNotification();
620   application.Render(1);
621   application.SendNotification();
622   application.Render(1);
623   END_TEST;
624 }
625
626 namespace
627 {
628
629 Material ConstructMaterial(float opacity, float diffuseOpacity)
630 {
631   Material customMaterial = Material::New("CustomMaterial");
632   customMaterial.SetOpacity(opacity);
633   customMaterial.SetDiffuseColor(Vector4(0.8f, 0.0f, 0.4f, diffuseOpacity));
634   customMaterial.SetAmbientColor(Vector4(0.2f, 1.0f, 0.6f, 1.0f));
635   customMaterial.SetSpecularColor(Vector4(0.5f, 0.6f, 0.7f, 1.0f));
636   return customMaterial;
637 }
638
639 static void TestBlending( TestApplication& application, Material material, float actorOpacity, BlendingMode::Type blendingMode, bool expectedBlend )
640 {
641   MeshData meshData;
642   MeshData::VertexContainer vertices;
643   MeshData::FaceIndices faces;
644   BoneContainer bones;
645   ConstructVertices(vertices, 60);
646   ConstructFaces(vertices, faces);
647   meshData.SetData(vertices, faces, bones, material);
648   Mesh mesh = Mesh::New(meshData);
649
650   application.SendNotification();
651   application.Render(0);
652   application.Render();
653   application.SendNotification();
654
655   MeshActor actor = MeshActor::New(mesh);
656   Stage::GetCurrent().Add(actor);
657
658   actor.SetAffectedByLighting(false);
659   actor.SetBlendMode(blendingMode);
660   actor.SetOpacity(actorOpacity);
661
662   TraceCallStack& cullFaceTrace = application.GetGlAbstraction().GetCullFaceTrace();
663   cullFaceTrace.Enable(true);
664   application.SendNotification();
665   application.Render();
666   DALI_TEST_EQUALS( BlendEnabled( cullFaceTrace ), expectedBlend, TEST_LOCATION );
667 }
668 } //anonymous namespace
669
670
671 int UtcDaliMeshActorBlend01(void)
672 {
673   // Set Material with translucent color, actor color opaque, Set Use image alpha to true
674   // Expect blending
675
676   TestApplication application;
677   tet_infoline("Testing Dali::MeshActor::Blend01()");
678
679   TestBlending( application, ConstructMaterial(0.5f, 0.5f), 1.0f, BlendingMode::AUTO, true );
680   END_TEST;
681 }
682
683
684 int UtcDaliMeshActorBlend02(void)
685 {
686   // Set material to translucent, set use image alpha to false, set actor opacity to 1.0f
687   // Expect no blending
688
689   TestApplication application;
690   tet_infoline("Testing Dali::MeshActor::Blend02()");
691   TestBlending( application, ConstructMaterial(0.5f, 0.5f), 1.0f, BlendingMode::OFF, false );
692   END_TEST;
693 }
694
695 int UtcDaliMeshActorBlend03(void)
696 {
697   // Set material to opaque, set use image alpha to true, set actor opacity to 1.0f
698   // Expect no blending
699
700   TestApplication application;
701   tet_infoline("Testing Dali::MeshActor::Blend03()");
702   TestBlending( application, ConstructMaterial(1.0f, 1.0f), 1.0f, BlendingMode::AUTO, false );
703   END_TEST;
704 }
705
706
707 int UtcDaliMeshActorBlend04(void)
708 {
709   // Set material to have image with alpha, set use image alpha to true, set actor opacity to 1.0f
710   // Expect blending
711   TestApplication application;
712   tet_infoline("Testing Dali::MeshActor::Blend04()");
713
714   Material material = ConstructMaterial(1.0f, 1.0f);
715   BitmapImage image = BitmapImage::New( 100, 50, Pixel::RGBA8888 );
716   material.SetDiffuseTexture( image );
717   application.SendNotification();
718   application.Render(0);
719
720   TestBlending( application, material, 1.0f, BlendingMode::AUTO, true );
721   END_TEST;
722 }
723
724 int UtcDaliMeshActorBlend05(void)
725 {
726   // Set material to have image with alpha, set use image alpha to false, set actor opacity to 1.0f
727   // Expect no blending
728
729   TestApplication application;
730   tet_infoline("Testing Dali::MeshActor::Blend05()");
731
732   Material material = ConstructMaterial(1.0f, 1.0f);
733   BitmapImage image = BitmapImage::New( 100, 50, Pixel::RGBA8888 );
734   material.SetDiffuseTexture( image );
735   application.SendNotification();
736   application.Render(0);
737
738   TestBlending( application, material, 1.0f, BlendingMode::ON, true );
739   END_TEST;
740 }
741
742
743 int UtcDaliMeshActorBlend06(void)
744 {
745   // Set material to have image without alpha, set use image alpha to true, set actor opacity to 1.0f
746   // Expect no blending
747
748   TestApplication application;
749   tet_infoline("Testing Dali::MeshActor::Blend()");
750
751   Material material = ConstructMaterial(1.0f, 1.0f);
752   BitmapImage image = BitmapImage::New( 100, 50, Pixel::RGB888 );
753   material.SetDiffuseTexture( image );
754   application.SendNotification();
755   application.Render(0);
756
757   TestBlending( application, material, 1.0f, BlendingMode::AUTO, false );
758   END_TEST;
759 }
760
761 int UtcDaliMeshActorBlend07(void)
762 {
763   // Set material to have framebuffer with alpha, set use image alpha to true, set actor opacity to 1.0f
764   // Expect blending
765   TestApplication application;
766   tet_infoline("Testing Dali::MeshActor::Blend07()");
767   application.Render(0);
768
769   Material material = ConstructMaterial(1.0f, 1.0f);
770   FrameBufferImage image = FrameBufferImage::New( 100, 50, Pixel::RGBA8888 );
771   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
772   RenderTask task = taskList.GetTask( 0u );
773   task.SetTargetFrameBuffer( image ); // To ensure frame buffer is connected
774   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
775   application.SendNotification();
776   application.Render();
777
778   material.SetDiffuseTexture( image ); // (to render from)
779   application.SendNotification();
780   application.Render();
781   application.Render();
782   application.SendNotification();
783
784   TestBlending( application, material, 1.0f, BlendingMode::AUTO, true );
785   END_TEST;
786 }
787
788 int UtcDaliMeshActorBlend08(void)
789 {
790   // Set material to have image with alpha, set use image alpha to false, set actor opacity to 0.5f
791   // Expect blending
792   TestApplication application;
793   tet_infoline("Testing Dali::MeshActor::Blend08()");
794
795   Material material = ConstructMaterial(1.0f, 1.0f);
796   BitmapImage image = BitmapImage::New( 100, 50, Pixel::RGBA8888 );
797   material.SetDiffuseTexture( image );
798   application.SendNotification();
799   application.Render(0);
800
801   TestBlending( application, material, 0.5f, BlendingMode::AUTO, true );
802   END_TEST;
803 }
804
805 int UtcDaliMeshActorBlend09(void)
806 {
807   // 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
808   // Expect blending
809   TestApplication application;
810   tet_infoline("Testing Dali::MeshActor::Blend08()");
811
812   Material material = ConstructMaterial(0.5f, 1.0f);
813   BitmapImage image = BitmapImage::New( 100, 50, Pixel::RGB888 );
814   material.SetDiffuseTexture( image );
815   application.SendNotification();
816   application.Render(0);
817
818   TestBlending( application, material, 1.0f, BlendingMode::AUTO, true );
819   END_TEST;
820 }
821
822 int UtcDaliMeshActorBoneUpdate01(void)
823 {
824   TestApplication application;
825   tet_infoline("Testing Dali::MeshActor::BoneUpdate01()");
826
827   // Set up a mesh with bones.
828   // animate bones
829   // ensure bone actor's world matrix is updated
830
831   Actor trunk = Actor::New();
832   trunk.SetName("trunk");
833   trunk.SetPosition(Vector3(100.0f, 200.0f, 300.0f));
834   trunk.SetRotation(Quaternion(M_PI*0.3f, Vector3::XAXIS));
835   Actor branch = Actor::New();
836   branch.SetName("branch");
837   branch.SetPosition(Vector3(10.0f, 100.0f, 0.0f));
838   branch.SetRotation(Quaternion(M_PI*0.2f, Vector3::YAXIS));
839
840   Actor twig = ImageActor::New(CreateBitmapImage());
841   twig.SetName("twig");
842   branch.SetPosition(Vector3(20.0f, 30.0f, 40.0f));
843
844   Actor bug = Actor::New(); // Not a bone
845   bug.SetName("bug");
846   bug.SetPosition(Vector3(10.0f, 10.0f, 10.0f));
847
848   Stage::GetCurrent().Add(trunk);
849   trunk.Add(branch);
850   branch.Add(twig);
851   twig.Add(bug);
852
853   MeshData meshData;
854   CreateMeshData(meshData); // Created with named bones (as above)
855   Mesh mesh = Mesh::New(meshData);
856   MeshActor meshActor = MeshActor::New(mesh);
857   Stage::GetCurrent().Add(meshActor);
858
859   meshActor.BindBonesToMesh(Stage::GetCurrent().GetRootLayer());
860
861   application.SendNotification();
862   application.Render(0);
863   application.Render();
864   application.SendNotification();
865
866   // How to test?
867   // Need to see what bone actor's node has set as world matrix.
868
869   Animation anim = Animation::New(1.0f);
870   anim.RotateBy(trunk, Radian(M_PI*0.5f), Vector3::ZAXIS);
871   anim.Play();
872   application.SendNotification();
873   application.Render(500);
874   application.SendNotification();
875   application.Render(500);
876   application.SendNotification();
877   application.Render(10);
878
879   // All bones have moved.
880   // Check that their world matrix has been updated: ( Isn't IDENTITY )
881   DALI_TEST_CHECK( ! application.GetGlAbstraction().CheckUniformValue("uModelMatrix", Matrix::IDENTITY ) );
882
883   Matrix worldMatrix;
884   GLuint programId, uniformId;
885   DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformIds("uModelMatrix", programId, uniformId) );
886   DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue( programId, uniformId, worldMatrix) );
887
888   // But also check that property is calculated as needed:
889   Matrix calcWorldMatrix = twig.GetCurrentWorldMatrix();
890   DALI_TEST_CHECK( Matrix::IDENTITY != calcWorldMatrix );
891   DALI_TEST_CHECK( worldMatrix == calcWorldMatrix );
892   END_TEST;
893
894 }
895
896 int UtcDaliMeshActorIndices(void)
897 {
898   TestApplication application;
899   Actor basicActor = Actor::New();
900   Mesh mesh = NewMesh();
901   MeshActor meshActor = MeshActor::New(mesh);
902
903   Property::IndexContainer indices;
904   meshActor.GetPropertyIndices( indices );
905   DALI_TEST_CHECK( indices.size() == basicActor.GetPropertyCount() ); // Mesh Actor does not have any properties
906   DALI_TEST_EQUALS( indices.size(), meshActor.GetPropertyCount(), TEST_LOCATION );
907   END_TEST;
908 }
909
910 int UtcDaliAnimatableMeshActorIndices(void)
911 {
912   TestApplication application;
913   Actor basicActor = Actor::New();
914   AnimatableMesh mesh = NewAnimatableMesh();
915   MeshActor meshActor = MeshActor::New(mesh);
916
917   Property::IndexContainer indices;
918   meshActor.GetPropertyIndices( indices );
919   DALI_TEST_CHECK( indices.size() == basicActor.GetPropertyCount() ); // Mesh Actor does not have any properties
920   DALI_TEST_EQUALS( indices.size(), meshActor.GetPropertyCount(), TEST_LOCATION );
921   END_TEST;
922 }