Merge changes I539c58fc,I6e1141c1 into devel/new_mesh
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-Geometry.cpp
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 #include <dali/public-api/dali-core.h>
19 #include <dali-test-suite-utils.h>
20 #include <dali/devel-api/rendering/geometry.h>
21 #include <dali/devel-api/rendering/renderer.h>
22
23 using namespace Dali;
24
25 #include <mesh-builder.h>
26
27 void geometry_test_startup(void)
28 {
29   test_return_value = TET_UNDEF;
30 }
31
32 void geometry_test_cleanup(void)
33 {
34   test_return_value = TET_PASS;
35 }
36
37 namespace
38 {
39
40 void TestConstraintNoBlue( Vector4& current, const PropertyInputContainer& inputs )
41 {
42   current.b = 0.0f;
43 }
44
45 struct TexturedQuadVertex { Vector2 position; Vector2 textureCoordinates; };
46
47 PropertyBuffer CreateVertexBuffer( const std::string& aPosition, const std::string& aTexCoord )
48 {
49   const float halfQuadSize = .5f;
50   TexturedQuadVertex texturedQuadVertexData[4] = {
51     { Vector2(-halfQuadSize, -halfQuadSize), Vector2(0.f, 0.f) },
52     { Vector2( halfQuadSize, -halfQuadSize), Vector2(1.f, 0.f) },
53     { Vector2(-halfQuadSize,  halfQuadSize), Vector2(0.f, 1.f) },
54     { Vector2( halfQuadSize,  halfQuadSize), Vector2(1.f, 1.f) } };
55
56   Property::Map vertexFormat;
57   vertexFormat[aPosition] = Property::VECTOR2;
58   vertexFormat[aTexCoord] = Property::VECTOR2;
59
60   PropertyBuffer vertexData = PropertyBuffer::New( vertexFormat, 4 );
61   vertexData.SetData(texturedQuadVertexData);
62
63   return vertexData;
64 }
65
66 PropertyBuffer CreateIndexBuffer()
67 {
68   unsigned short indexData[6] = { 0, 3, 1, 0, 2, 3 };
69   Property::Map indexFormat;
70   indexFormat["indices"] = Property::UNSIGNED_INTEGER; // Should be Unsigned Short
71   PropertyBuffer indices = PropertyBuffer::New( indexFormat, 3 );
72   indices.SetData(indexData);
73
74   return indices;
75 }
76
77 }
78
79
80 int UtcDaliGeometryNew01(void)
81 {
82   TestApplication application;
83
84   Geometry geometry = Geometry::New();
85
86   DALI_TEST_EQUALS( (bool)geometry, true, TEST_LOCATION );
87   END_TEST;
88 }
89
90 int UtcDaliGeometryNew02(void)
91 {
92   TestApplication application;
93   Geometry geometry;
94   DALI_TEST_EQUALS( (bool)geometry, false, TEST_LOCATION );
95   END_TEST;
96 }
97
98 int UtcDaliGeometryCopyConstructor(void)
99 {
100   TestApplication application;
101
102   Geometry geometry = Geometry::New();
103
104   Geometry geometryCopy(geometry);
105
106   DALI_TEST_EQUALS( (bool)geometryCopy, true, TEST_LOCATION );
107   END_TEST;
108 }
109
110 int UtcDaliGeometryAssignmentOperator(void)
111 {
112   TestApplication application;
113
114   Geometry geometry = Geometry::New();
115
116   Geometry geometry2;
117   DALI_TEST_EQUALS( (bool)geometry2, false, TEST_LOCATION );
118
119   geometry2 = geometry;
120   DALI_TEST_EQUALS( (bool)geometry2, true, TEST_LOCATION );
121
122   END_TEST;
123 }
124
125 int UtcDaliGeometryDownCast01(void)
126 {
127   TestApplication application;
128
129   Geometry geometry = Geometry::New();
130
131   BaseHandle handle(geometry);
132   Geometry geometry2 = Geometry::DownCast(handle);
133   DALI_TEST_EQUALS( (bool)geometry2, true, TEST_LOCATION );
134   END_TEST;
135 }
136
137 int UtcDaliGeometryDownCast02(void)
138 {
139   TestApplication application;
140
141   Handle handle = Handle::New(); // Create a custom object
142   Geometry geometry = Geometry::DownCast(handle);
143   DALI_TEST_EQUALS( (bool)geometry, false, TEST_LOCATION );
144   END_TEST;
145 }
146
147 int UtcDaliGeometryAddVertexBuffer(void)
148 {
149   TestApplication application;
150
151   tet_infoline("Test AddVertexBuffer");
152
153   PropertyBuffer vertexBuffer1 = CreateVertexBuffer("aPosition1", "aTexCoord1" );
154   Geometry geometry = Geometry::New();
155   geometry.AddVertexBuffer( vertexBuffer1 );
156
157   Material material = CreateMaterial(1.f);
158   Renderer renderer = Renderer::New(geometry, material);
159   Actor actor = Actor::New();
160   actor.SetSize(Vector3::ONE * 100.f);
161   actor.AddRenderer(renderer);
162   Stage::GetCurrent().Add(actor);
163
164   application.SendNotification();
165   application.Render(0);
166   application.Render();
167   application.SendNotification();
168
169   {
170     const TestGlAbstraction::BufferDataCalls& bufferDataCalls =
171         application.GetGlAbstraction().GetBufferDataCalls();
172
173     DALI_TEST_EQUALS( bufferDataCalls.size(), 1u, TEST_LOCATION );
174
175     DALI_TEST_EQUALS( bufferDataCalls[0], 4*sizeof( TexturedQuadVertex ), TEST_LOCATION );
176   }
177
178   // add the second vertex buffer
179   application.GetGlAbstraction().ResetBufferDataCalls();
180
181   PropertyBuffer vertexBuffer2 = CreateVertexBuffer( "aPosition2", "aTexCoord2" );
182   geometry.AddVertexBuffer( vertexBuffer2 );
183   application.SendNotification();
184   application.Render(0);
185   application.Render();
186   application.SendNotification();
187
188   {
189     const TestGlAbstraction::BufferDataCalls& bufferDataCalls =
190         application.GetGlAbstraction().GetBufferDataCalls();
191
192     DALI_TEST_EQUALS( bufferDataCalls.size(), 2u, TEST_LOCATION );
193
194     DALI_TEST_EQUALS( bufferDataCalls[0], 4*sizeof( TexturedQuadVertex ), TEST_LOCATION );
195     DALI_TEST_EQUALS( bufferDataCalls[1], 4*sizeof( TexturedQuadVertex ), TEST_LOCATION );
196   }
197
198   END_TEST;
199 }
200
201 int UtcDaliGeometryGetNumberOfVertexBuffers(void)
202 {
203   TestApplication application;
204
205   tet_infoline("Test GetNumberOfVertexBuffers");
206   PropertyBuffer vertexBuffer1 = CreateVertexBuffer("aPosition1", "aTexCoord1" );
207   PropertyBuffer vertexBuffer2 = CreateVertexBuffer("aPosition2", "aTexCoord2" );
208   PropertyBuffer vertexBuffer3 = CreateVertexBuffer("aPosition3", "aTexCoord3" );
209
210   Geometry geometry = Geometry::New();
211   geometry.AddVertexBuffer( vertexBuffer1 );
212   DALI_TEST_EQUALS( geometry.GetNumberOfVertexBuffers(), 1u, TEST_LOCATION );
213
214   geometry.AddVertexBuffer( vertexBuffer2 );
215   geometry.AddVertexBuffer( vertexBuffer3 );
216   DALI_TEST_EQUALS( geometry.GetNumberOfVertexBuffers(), 3u, TEST_LOCATION );
217
218   geometry.RemoveVertexBuffer( 2u );
219   DALI_TEST_EQUALS( geometry.GetNumberOfVertexBuffers(), 2u, TEST_LOCATION );
220
221   END_TEST;
222 }
223
224 int UtcDaliGeometryRemoveVertexBuffer(void)
225 {
226   TestApplication application;
227
228   tet_infoline("Test RemoveVertexBuffer");
229
230   PropertyBuffer vertexBuffer1 = CreateVertexBuffer("aPosition1", "aTexCoord1" );
231   PropertyBuffer vertexBuffer2 = CreateVertexBuffer("aPosition2", "aTexCoord2" );
232
233   Geometry geometry = Geometry::New();
234   geometry.AddVertexBuffer( vertexBuffer1 );
235
236   Material material = CreateMaterial(1.f);
237   Renderer renderer = Renderer::New(geometry, material);
238   Actor actor = Actor::New();
239   actor.SetSize(Vector3::ONE * 100.f);
240   actor.AddRenderer(renderer);
241   Stage::GetCurrent().Add(actor);
242
243   DALI_TEST_EQUALS( geometry.GetNumberOfVertexBuffers(), 1u, TEST_LOCATION );
244
245   geometry.RemoveVertexBuffer( 0 );
246   geometry.AddVertexBuffer( vertexBuffer2 );
247   DALI_TEST_EQUALS( geometry.GetNumberOfVertexBuffers(), 1u, TEST_LOCATION );
248
249   geometry.RemoveVertexBuffer( 0 );
250   DALI_TEST_EQUALS( geometry.GetNumberOfVertexBuffers(), 0u, TEST_LOCATION );
251
252   //Todo: test by checking the BufferDataCalls
253   // make sure the vertex buffer in actually removed from gl
254
255    END_TEST;
256 }
257
258 int UtcDaliGeometrySetIndexBuffer(void)
259 {
260   TestApplication application;
261
262   tet_infoline("Test SetIndexBuffer");
263
264   PropertyBuffer vertexBuffer = CreateVertexBuffer("aPosition", "aTexCoord" );
265   PropertyBuffer indexBuffer = CreateIndexBuffer( );
266
267   Geometry geometry = Geometry::New();
268   geometry.AddVertexBuffer( vertexBuffer );
269
270   Material material = CreateMaterial(1.f);
271   Renderer renderer = Renderer::New(geometry, material);
272   Actor actor = Actor::New();
273   actor.SetSize(Vector3::ONE * 100.f);
274   actor.AddRenderer(renderer);
275   Stage::GetCurrent().Add(actor);
276
277   application.SendNotification();
278   application.Render(0);
279   application.Render();
280   application.SendNotification();
281
282   {
283     const TestGlAbstraction::BufferDataCalls& bufferDataCalls =
284         application.GetGlAbstraction().GetBufferDataCalls();
285
286     DALI_TEST_EQUALS( bufferDataCalls.size(), 1u, TEST_LOCATION );
287
288     DALI_TEST_EQUALS( bufferDataCalls[0], 4*sizeof( TexturedQuadVertex ), TEST_LOCATION );
289   }
290
291   // Set index buffer
292   application.GetGlAbstraction().ResetBufferDataCalls();
293
294   geometry.SetIndexBuffer( indexBuffer );
295   application.SendNotification();
296   application.Render(0);
297   application.Render();
298   application.SendNotification();
299
300   {
301     const TestGlAbstraction::BufferDataCalls& bufferDataCalls =
302         application.GetGlAbstraction().GetBufferDataCalls();
303
304     DALI_TEST_EQUALS( bufferDataCalls.size(), 2u, TEST_LOCATION );
305
306     DALI_TEST_EQUALS( bufferDataCalls[0], 4*sizeof( TexturedQuadVertex ), TEST_LOCATION );
307     // should be unsigned short instead of unsigned int
308     DALI_TEST_EQUALS( bufferDataCalls[1], 6*sizeof( unsigned short ), TEST_LOCATION );
309   }
310
311
312   END_TEST;
313 }
314
315 int UtcDaliGeometrySetGetGeometryType(void)
316 {
317   TestApplication application;
318
319   tet_infoline("Test SetGeometryType and GetGeometryType");
320
321   unsigned int numVertex = 4u;
322   PropertyBuffer vertexBuffer = CreateVertexBuffer("aPosition", "aTexCoord" );
323
324   Geometry geometry = Geometry::New();
325   geometry.AddVertexBuffer( vertexBuffer );
326
327   Material material = CreateMaterial(1.f);
328   Renderer renderer = Renderer::New(geometry, material);
329   Actor actor = Actor::New();
330   actor.SetSize(Vector3::ONE * 100.f);
331   actor.AddRenderer(renderer);
332   Stage::GetCurrent().Add(actor);
333
334   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
335   TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
336
337   /****************************************************/
338   // Default (TRIANGLES), no index buffer
339   drawTrace.Reset();
340   drawTrace.Enable(true);
341   application.SendNotification();
342   application.Render(0);
343   application.Render();
344   application.SendNotification();
345   drawTrace.Enable( false );
346
347   // Test the default geometry type is GL_TRIANGLE
348   // no index buffer, call glDrawArrays,
349   DALI_TEST_EQUALS( drawTrace.CountMethod( "DrawArrays" ), 2, TEST_LOCATION);
350   std::stringstream out;
351   out << GL_TRIANGLES << ", " << 0 << ", " << numVertex;
352   DALI_TEST_EQUALS( drawTrace.TestMethodAndParams(1, "DrawArrays", out.str()), true, TEST_LOCATION);
353
354   DALI_TEST_EQUALS( geometry.GetGeometryType(), Geometry::TRIANGLES, TEST_LOCATION);
355
356   /*********************************************************/
357   // LINES, no index buffer
358   geometry.SetGeometryType( Geometry::LINES );
359
360   drawTrace.Reset();
361   drawTrace.Enable(true);
362   application.SendNotification();
363   application.Render(0);
364   application.Render();
365   application.SendNotification();
366   drawTrace.Enable( false );
367
368   // geometry type is set as GL_LINES
369   // no index buffer, call glDrawArrays,
370   DALI_TEST_EQUALS( drawTrace.CountMethod( "DrawArrays" ), 2, TEST_LOCATION);
371   out.str("");
372   out << GL_LINES << ", " << 0 << ", " << numVertex;
373   DALI_TEST_EQUALS( drawTrace.TestMethodAndParams(1, "DrawArrays", out.str()), true, TEST_LOCATION);
374
375   DALI_TEST_EQUALS( geometry.GetGeometryType(), Geometry::LINES, TEST_LOCATION);
376
377   /*****************************************************/
378   //POINTS
379   geometry.SetGeometryType( Geometry::POINTS );
380
381   drawTrace.Reset();
382   drawTrace.Enable(true);
383   application.SendNotification();
384   application.Render(0);
385   application.Render();
386   application.SendNotification();
387   drawTrace.Enable( false );
388
389   // geometry type is set as GL_POINTS
390   // no index buffer, call glDrawArrays,
391   DALI_TEST_EQUALS( drawTrace.CountMethod( "DrawArrays" ), 2, TEST_LOCATION);
392   out.str("");
393   out << GL_POINTS << ", " << 0 << ", " << numVertex;
394   DALI_TEST_EQUALS( drawTrace.TestMethodAndParams(1, "DrawArrays", out.str()), true, TEST_LOCATION);
395
396   DALI_TEST_EQUALS( geometry.GetGeometryType(), Geometry::POINTS, TEST_LOCATION);
397
398   END_TEST;
399 }
400
401 int UtcDaliGeometrySetGetRequireDepthTesting(void)
402 {
403   TestApplication application;
404
405   tet_infoline("Test SetRequiresDepthTesting, GetRequiresDepthTesting");
406
407   Shader shader = Shader::New("VertexSource", "FragmentSource");
408   Material material = Material::New( shader );
409
410   Geometry geometry = CreateQuadGeometry();
411   Renderer renderer = Renderer::New( geometry, material );
412
413   Actor actor = Actor::New();
414   actor.AddRenderer(renderer);
415   actor.SetSize(400, 400);
416   Stage::GetCurrent().Add(actor);
417
418   DALI_TEST_EQUALS( geometry.GetRequiresDepthTesting(), false, TEST_LOCATION );
419
420   geometry.SetRequiresDepthTesting(true);
421
422   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
423   glAbstraction.EnableCullFaceCallTrace(true);
424   application.SendNotification();
425   application.Render();
426 //  TODO: Not supported yes
427 //  TraceCallStack& glEnableStack = glAbstraction.GetCullFaceTrace();
428 //  std::ostringstream out;
429 //  out << GL_DEPTH_TEST;
430 //  DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", out.str().c_str() ) );
431
432   DALI_TEST_EQUALS( geometry.GetRequiresDepthTesting(), true, TEST_LOCATION );
433
434   END_TEST;
435 }
436
437 int UtcDaliGeometryPropertyRequiresDepthTest(void)
438 {
439   TestApplication application;
440
441   tet_infoline("Test SetRequiresDepthTesting, GetRequiresDepthTesting");
442
443   Shader shader = Shader::New("VertexSource", "FragmentSource");
444   Material material = Material::New( shader );
445
446   Geometry geometry = CreateQuadGeometry();
447   Renderer renderer = Renderer::New( geometry, material );
448
449   Actor actor = Actor::New();
450   actor.AddRenderer(renderer);
451   actor.SetSize(400, 400);
452   Stage::GetCurrent().Add(actor);
453
454   DALI_TEST_EQUALS( geometry.GetProperty<bool>(Geometry::Property::REQUIRES_DEPTH_TEST), false, TEST_LOCATION );
455
456   geometry.SetProperty(Geometry::Property::REQUIRES_DEPTH_TEST, true );
457
458   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
459   glAbstraction.EnableCullFaceCallTrace(true);
460   application.SendNotification();
461   application.Render();
462 //  TODO: Not supported yes
463 //  TraceCallStack& glEnableStack = glAbstraction.GetCullFaceTrace();
464 //  std::ostringstream out;
465 //  out << GL_DEPTH_TEST;
466 //  DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", out.str().c_str() ) );
467
468   DALI_TEST_EQUALS( geometry.GetProperty<bool>(Geometry::Property::REQUIRES_DEPTH_TEST), true, TEST_LOCATION );
469
470   END_TEST;
471 }
472
473 int UtcDaliGeometryConstraint(void)
474 {
475   TestApplication application;
476
477   tet_infoline("Test that a custom geometry property can be constrained");
478
479   Shader shader = Shader::New("VertexSource", "FragmentSource");
480   Material material = Material::New( shader );
481   material.SetProperty(Material::Property::COLOR, Color::WHITE);
482
483   Geometry geometry = CreateQuadGeometry();
484   Renderer renderer = Renderer::New( geometry, material );
485
486   Actor actor = Actor::New();
487   actor.AddRenderer(renderer);
488   actor.SetSize(400, 400);
489   Stage::GetCurrent().Add(actor);
490
491   Vector4 initialColor = Color::WHITE;
492   Property::Index colorIndex = geometry.RegisterProperty( "uFadeColor", initialColor );
493
494   application.SendNotification();
495   application.Render(0);
496   DALI_TEST_EQUALS( geometry.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION );
497
498   // Apply constraint
499   Constraint constraint = Constraint::New<Vector4>( geometry, colorIndex, TestConstraintNoBlue );
500   constraint.Apply();
501   application.SendNotification();
502   application.Render(0);
503
504   // Expect no blue component in either buffer - yellow
505   DALI_TEST_EQUALS( geometry.GetProperty<Vector4>(colorIndex), Color::YELLOW, TEST_LOCATION );
506   application.Render(0);
507   DALI_TEST_EQUALS( geometry.GetProperty<Vector4>(colorIndex), Color::YELLOW, TEST_LOCATION );
508
509   geometry.RemoveConstraints();
510   geometry.SetProperty(colorIndex, Color::WHITE );
511   application.SendNotification();
512   application.Render(0);
513   DALI_TEST_EQUALS( geometry.GetProperty<Vector4>(colorIndex), Color::WHITE, TEST_LOCATION );
514
515   END_TEST;
516 }
517
518 int UtcDaliGeometryConstraint02(void)
519 {
520   TestApplication application;
521
522   tet_infoline("Test that a uniform map geometry property can be constrained");
523
524   Shader shader = Shader::New("VertexSource", "FragmentSource");
525   Material material = Material::New( shader );
526   material.SetProperty(Material::Property::COLOR, Color::WHITE);
527
528   Geometry geometry = CreateQuadGeometry();
529   Renderer renderer = Renderer::New( geometry, material );
530
531   Actor actor = Actor::New();
532   actor.AddRenderer(renderer);
533   actor.SetSize(400, 400);
534   Stage::GetCurrent().Add(actor);
535   application.SendNotification();
536   application.Render(0);
537
538   Vector4 initialColor = Color::WHITE;
539   Property::Index colorIndex = geometry.RegisterProperty( "uFadeColor", initialColor );
540
541   TestGlAbstraction& gl = application.GetGlAbstraction();
542
543   application.SendNotification();
544   application.Render(0);
545
546   Vector4 actualValue(Vector4::ZERO);
547   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
548   DALI_TEST_EQUALS( actualValue, initialColor, TEST_LOCATION );
549
550   // Apply constraint
551   Constraint constraint = Constraint::New<Vector4>( geometry, colorIndex, TestConstraintNoBlue );
552   constraint.Apply();
553   application.SendNotification();
554   application.Render(0);
555
556    // Expect no blue component in either buffer - yellow
557   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
558   DALI_TEST_EQUALS( actualValue, Color::YELLOW, TEST_LOCATION );
559
560   application.Render(0);
561   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
562   DALI_TEST_EQUALS( actualValue, Color::YELLOW, TEST_LOCATION );
563
564   geometry.RemoveConstraints();
565   geometry.SetProperty(colorIndex, Color::WHITE );
566   application.SendNotification();
567   application.Render(0);
568
569   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
570   DALI_TEST_EQUALS( actualValue, Color::WHITE, TEST_LOCATION );
571
572   END_TEST;
573 }
574
575
576
577 int UtcDaliGeometryAnimatedProperty01(void)
578 {
579   TestApplication application;
580
581   tet_infoline("Test that a custom geometry property can be animated");
582
583   Shader shader = Shader::New("VertexSource", "FragmentSource");
584   Material material = Material::New( shader );
585   material.SetProperty(Material::Property::COLOR, Color::WHITE);
586
587   Geometry geometry = CreateQuadGeometry();
588   Renderer renderer = Renderer::New( geometry, material );
589
590   Actor actor = Actor::New();
591   actor.AddRenderer(renderer);
592   actor.SetSize(400, 400);
593   Stage::GetCurrent().Add(actor);
594
595   Vector4 initialColor = Color::WHITE;
596   Property::Index colorIndex = geometry.RegisterProperty( "uFadeColor", initialColor );
597
598   application.SendNotification();
599   application.Render(0);
600   DALI_TEST_EQUALS( geometry.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION );
601
602   Animation  animation = Animation::New(1.0f);
603   KeyFrames keyFrames = KeyFrames::New();
604   keyFrames.Add(0.0f, initialColor);
605   keyFrames.Add(1.0f, Color::TRANSPARENT);
606   animation.AnimateBetween( Property( geometry, colorIndex ), keyFrames );
607   animation.Play();
608
609   application.SendNotification();
610   application.Render(500);
611
612   DALI_TEST_EQUALS( geometry.GetProperty<Vector4>(colorIndex), Color::WHITE * 0.5f, TEST_LOCATION );
613
614   application.Render(500);
615
616   DALI_TEST_EQUALS( geometry.GetProperty<Vector4>(colorIndex), Color::TRANSPARENT, TEST_LOCATION );
617
618   END_TEST;
619 }
620
621 int UtcDaliGeometryAnimatedProperty02(void)
622 {
623   TestApplication application;
624
625   tet_infoline("Test that a uniform map geometry property can be animated");
626
627   Shader shader = Shader::New("VertexSource", "FragmentSource");
628   Material material = Material::New( shader );
629   material.SetProperty(Material::Property::COLOR, Color::WHITE);
630
631   Geometry geometry = CreateQuadGeometry();
632   Renderer renderer = Renderer::New( geometry, material );
633
634   Actor actor = Actor::New();
635   actor.AddRenderer(renderer);
636   actor.SetSize(400, 400);
637   Stage::GetCurrent().Add(actor);
638   application.SendNotification();
639   application.Render(0);
640
641   Vector4 initialColor = Color::WHITE;
642   Property::Index colorIndex = geometry.RegisterProperty( "uFadeColor", initialColor );
643
644   TestGlAbstraction& gl = application.GetGlAbstraction();
645
646   application.SendNotification();
647   application.Render(0);
648
649   Vector4 actualValue(Vector4::ZERO);
650   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
651   DALI_TEST_EQUALS( actualValue, initialColor, TEST_LOCATION );
652
653   Animation  animation = Animation::New(1.0f);
654   KeyFrames keyFrames = KeyFrames::New();
655   keyFrames.Add(0.0f, initialColor);
656   keyFrames.Add(1.0f, Color::TRANSPARENT);
657   animation.AnimateBetween( Property( geometry, colorIndex ), keyFrames );
658   animation.Play();
659
660   application.SendNotification();
661   application.Render(500);
662
663   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
664   DALI_TEST_EQUALS( actualValue, Color::WHITE * 0.5f, TEST_LOCATION );
665
666   application.Render(500);
667   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
668   DALI_TEST_EQUALS( actualValue, Color::TRANSPARENT, TEST_LOCATION );
669
670   END_TEST;
671 }