Dali 3D User Interface Engine
utc-Dali-Geometry.cpp
Go to the documentation of this file.
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 
19 #include <dali-test-suite-utils.h>
22 
23 using namespace Dali;
24 
25 #include <mesh-builder.h>
26 
28 {
30 }
31 
33 {
35 }
36 
37 namespace
38 {
39 
40 void TestConstraintNoBlue( Vector4& current, const PropertyInputContainer& inputs )
41 {
42  current.b = 0.0f;
43 }
44 
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 
67 {
68  const unsigned short indexData[6] = { 0, 3, 1, 0, 2, 3 };
69  const unsigned int numberElements = sizeof(indexData)/sizeof(indexData[0]) ;
70 
71  Property::Map indexFormat;
72  indexFormat["indices"] = Property::INTEGER;
73  PropertyBuffer indices = PropertyBuffer::New( indexFormat, numberElements );
74  indices.SetData(indexData);
75 
76  return indices;
77 }
78 
79 }
80 
81 
83 {
84  TestApplication application;
85 
86  Geometry geometry = Geometry::New();
87 
88  DALI_TEST_EQUALS( (bool)geometry, true, TEST_LOCATION );
89  END_TEST;
90 }
91 
93 {
94  TestApplication application;
95  Geometry geometry;
96  DALI_TEST_EQUALS( (bool)geometry, false, TEST_LOCATION );
97  END_TEST;
98 }
99 
101 {
102  TestApplication application;
103 
104  Geometry geometry = Geometry::New();
105 
106  Geometry geometryCopy(geometry);
107 
108  DALI_TEST_EQUALS( (bool)geometryCopy, true, TEST_LOCATION );
109  END_TEST;
110 }
111 
113 {
114  TestApplication application;
115 
116  Geometry geometry = Geometry::New();
117 
118  Geometry geometry2;
119  DALI_TEST_EQUALS( (bool)geometry2, false, TEST_LOCATION );
120 
121  geometry2 = geometry;
122  DALI_TEST_EQUALS( (bool)geometry2, true, TEST_LOCATION );
123 
124  END_TEST;
125 }
126 
128 {
129  TestApplication application;
130 
131  Geometry geometry = Geometry::New();
132 
133  BaseHandle handle(geometry);
134  Geometry geometry2 = Geometry::DownCast(handle);
135  DALI_TEST_EQUALS( (bool)geometry2, true, TEST_LOCATION );
136  END_TEST;
137 }
138 
140 {
141  TestApplication application;
142 
143  Handle handle = Handle::New(); // Create a custom object
144  Geometry geometry = Geometry::DownCast(handle);
145  DALI_TEST_EQUALS( (bool)geometry, false, TEST_LOCATION );
146  END_TEST;
147 }
148 
150 {
151  TestApplication application;
152 
153  tet_infoline("Test AddVertexBuffer");
154 
155  PropertyBuffer vertexBuffer1 = CreateVertexBuffer("aPosition1", "aTexCoord1" );
156  Geometry geometry = Geometry::New();
157  geometry.AddVertexBuffer( vertexBuffer1 );
158 
159  Material material = CreateMaterial();
160  Renderer renderer = Renderer::New(geometry, material);
161  Actor actor = Actor::New();
162  actor.SetSize(Vector3::ONE * 100.f);
163  actor.AddRenderer(renderer);
164  Stage::GetCurrent().Add(actor);
165 
166  application.SendNotification();
167  application.Render(0);
168  application.Render();
169  application.SendNotification();
170 
171  {
172  const TestGlAbstraction::BufferDataCalls& bufferDataCalls =
173  application.GetGlAbstraction().GetBufferDataCalls();
174 
175  DALI_TEST_EQUALS( bufferDataCalls.size(), 1u, TEST_LOCATION );
176 
177  DALI_TEST_EQUALS( bufferDataCalls[0], 4*sizeof( TexturedQuadVertex ), TEST_LOCATION );
178  }
179 
180  // add the second vertex buffer
181  application.GetGlAbstraction().ResetBufferDataCalls();
182 
183  PropertyBuffer vertexBuffer2 = CreateVertexBuffer( "aPosition2", "aTexCoord2" );
184  geometry.AddVertexBuffer( vertexBuffer2 );
185  application.SendNotification();
186  application.Render(0);
187  application.Render();
188  application.SendNotification();
189 
190  {
191  const TestGlAbstraction::BufferDataCalls& bufferDataCalls =
192  application.GetGlAbstraction().GetBufferDataCalls();
193 
194  //Check that only the new buffer gets uploaded
195  DALI_TEST_EQUALS( bufferDataCalls.size(), 1u, TEST_LOCATION );
196  DALI_TEST_EQUALS( bufferDataCalls[0], 4*sizeof( TexturedQuadVertex ), TEST_LOCATION );
197  }
198 
199  END_TEST;
200 }
201 
203 {
204  TestApplication application;
205 
206  tet_infoline("Test GetNumberOfVertexBuffers");
207  PropertyBuffer vertexBuffer1 = CreateVertexBuffer("aPosition1", "aTexCoord1" );
208  PropertyBuffer vertexBuffer2 = CreateVertexBuffer("aPosition2", "aTexCoord2" );
209  PropertyBuffer vertexBuffer3 = CreateVertexBuffer("aPosition3", "aTexCoord3" );
210 
211  Geometry geometry = Geometry::New();
212  geometry.AddVertexBuffer( vertexBuffer1 );
214 
215  geometry.AddVertexBuffer( vertexBuffer2 );
216  geometry.AddVertexBuffer( vertexBuffer3 );
218 
219  geometry.RemoveVertexBuffer( 2u );
221 
222  END_TEST;
223 }
224 
226 {
227  TestApplication application;
228 
229  tet_infoline("Test RemoveVertexBuffer");
230 
231  PropertyBuffer vertexBuffer1 = CreateVertexBuffer("aPosition1", "aTexCoord1" );
232  PropertyBuffer vertexBuffer2 = CreateVertexBuffer("aPosition2", "aTexCoord2" );
233 
234  Geometry geometry = Geometry::New();
235  geometry.AddVertexBuffer( vertexBuffer1 );
236 
237  Material material = CreateMaterial();
238  Renderer renderer = Renderer::New(geometry, material);
239  Actor actor = Actor::New();
240  actor.SetSize(Vector3::ONE * 100.f);
241  actor.AddRenderer(renderer);
242  Stage::GetCurrent().Add(actor);
243 
245 
246  geometry.RemoveVertexBuffer( 0 );
247  geometry.AddVertexBuffer( vertexBuffer2 );
249 
250  geometry.RemoveVertexBuffer( 0 );
252 
253  //Todo: test by checking the BufferDataCalls
254  // make sure the vertex buffer in actually removed from gl
255 
256  END_TEST;
257 }
258 
260 {
261  TestApplication application;
262 
263  tet_infoline("Test SetIndexBuffer");
264 
265  PropertyBuffer vertexBuffer = CreateVertexBuffer("aPosition", "aTexCoord" );
266  PropertyBuffer indexBuffer = CreateIndexBuffer( );
267 
268  Geometry geometry = Geometry::New();
269  geometry.AddVertexBuffer( vertexBuffer );
270 
271  Material material = CreateMaterial();
272  Renderer renderer = Renderer::New(geometry, material);
273  Actor actor = Actor::New();
274  actor.SetSize(Vector3::ONE * 100.f);
275  actor.AddRenderer(renderer);
276  Stage::GetCurrent().Add(actor);
277 
278  application.SendNotification();
279  application.Render(0);
280  application.Render();
281  application.SendNotification();
282 
283  {
284  const TestGlAbstraction::BufferDataCalls& bufferDataCalls =
285  application.GetGlAbstraction().GetBufferDataCalls();
286 
287  DALI_TEST_EQUALS( bufferDataCalls.size(), 1u, TEST_LOCATION );
288 
289  DALI_TEST_EQUALS( bufferDataCalls[0], 4*sizeof( TexturedQuadVertex ), TEST_LOCATION );
290  }
291 
292  // Set index buffer
293  application.GetGlAbstraction().ResetBufferDataCalls();
294 
295  geometry.SetIndexBuffer( indexBuffer );
296  application.SendNotification();
297  application.Render(0);
298  application.Render();
299  application.SendNotification();
300 
301  {
302  const TestGlAbstraction::BufferDataCalls& bufferDataCalls =
303  application.GetGlAbstraction().GetBufferDataCalls();
304 
305  //Only the index buffer should be uploaded
306  DALI_TEST_EQUALS( bufferDataCalls.size(), 1u, TEST_LOCATION );
307 
308  // should be unsigned short instead of unsigned int
309  DALI_TEST_EQUALS( bufferDataCalls[0], 6*sizeof( unsigned short ), TEST_LOCATION );
310  }
311 
312 
313  END_TEST;
314 }
315 
317 {
318  TestApplication application;
319 
320  tet_infoline("Test SetGeometryType and GetGeometryType: without index buffer");
321 
322  unsigned int numVertex = 4u;
323  PropertyBuffer vertexBuffer = CreateVertexBuffer("aPosition", "aTexCoord" );
324 
325  Geometry geometry = Geometry::New();
326  geometry.AddVertexBuffer( vertexBuffer );
327 
328  Material material = CreateMaterial();
329  Renderer renderer = Renderer::New(geometry, material);
330  Actor actor = Actor::New();
331  actor.SetSize(Vector3::ONE * 100.f);
332  actor.AddRenderer(renderer);
333  Stage::GetCurrent().Add(actor);
334 
335  TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
336  TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
337 
338  /****************************************************/
339  // Default (TRIANGLES), no index buffer
340  drawTrace.Reset();
341  drawTrace.Enable(true);
342  application.SendNotification();
343  application.Render(0);
344  application.Render();
345  application.SendNotification();
346  drawTrace.Enable( false );
347 
348  // Test the default geometry type is GL_TRIANGLE
349  // no index buffer, call glDrawArrays,
350  DALI_TEST_EQUALS( drawTrace.CountMethod( "DrawArrays" ), 2, TEST_LOCATION);
351  std::stringstream out;
352  out << GL_TRIANGLES << ", " << 0 << ", " << numVertex;
353  DALI_TEST_EQUALS( drawTrace.TestMethodAndParams(1, "DrawArrays", out.str()), true, TEST_LOCATION);
354 
356 
357  /*********************************************************/
358  // LINES, no index buffer
359  geometry.SetGeometryType( Geometry::LINES );
360 
361  drawTrace.Reset();
362  drawTrace.Enable(true);
363  application.SendNotification();
364  application.Render(0);
365  application.Render();
366  application.SendNotification();
367  drawTrace.Enable( false );
368 
369  // geometry type is set as GL_LINES
370  // no index buffer, call glDrawArrays,
371  DALI_TEST_EQUALS( drawTrace.CountMethod( "DrawArrays" ), 2, TEST_LOCATION);
372  out.str("");
373  out << GL_LINES << ", " << 0 << ", " << numVertex;
374  DALI_TEST_EQUALS( drawTrace.TestMethodAndParams(1, "DrawArrays", out.str()), true, TEST_LOCATION);
375 
377 
378  /*****************************************************/
379  //POINTS
380  geometry.SetGeometryType( Geometry::POINTS );
381 
382  drawTrace.Reset();
383  drawTrace.Enable(true);
384  application.SendNotification();
385  application.Render(0);
386  application.Render();
387  application.SendNotification();
388  drawTrace.Enable( false );
389 
390  // geometry type is set as GL_POINTS
391  // no index buffer, call glDrawArrays,
392  DALI_TEST_EQUALS( drawTrace.CountMethod( "DrawArrays" ), 2, TEST_LOCATION);
393  out.str("");
394  out << GL_POINTS << ", " << 0 << ", " << numVertex;
395  DALI_TEST_EQUALS( drawTrace.TestMethodAndParams(1, "DrawArrays", out.str()), true, TEST_LOCATION);
396 
398 
399  /*****************************************************/
400  //TRIANGLE_STRIP, no index buffer
402 
403  drawTrace.Reset();
404  drawTrace.Enable(true);
405  application.SendNotification();
406  application.Render(0);
407  application.Render();
408  application.SendNotification();
409  drawTrace.Enable( false );
410 
411  // geometry type is set as GL_POINTS
412  // no index buffer, call glDrawArrays,
413  DALI_TEST_EQUALS( drawTrace.CountMethod( "DrawArrays" ), 2, TEST_LOCATION);
414  out.str("");
415  out << GL_TRIANGLE_STRIP << ", " << 0 << ", " << numVertex;
416  DALI_TEST_EQUALS( drawTrace.TestMethodAndParams(1, "DrawArrays", out.str()), true, TEST_LOCATION);
417 
419 
420  /*****************************************************/
421  //TRIANGLE_FAN, no index buffer
423 
424  drawTrace.Reset();
425  drawTrace.Enable(true);
426  application.SendNotification();
427  application.Render(0);
428  application.Render();
429  application.SendNotification();
430  drawTrace.Enable( false );
431 
432  // geometry type is set as GL_POINTS
433  // no index buffer, call glDrawArrays,
434  DALI_TEST_EQUALS( drawTrace.CountMethod( "DrawArrays" ), 2, TEST_LOCATION);
435  out.str("");
436  out << GL_TRIANGLE_FAN << ", " << 0 << ", " << numVertex;
437  DALI_TEST_EQUALS( drawTrace.TestMethodAndParams(1, "DrawArrays", out.str()), true, TEST_LOCATION);
438 
440 
441  END_TEST;
442 }
443 
445 {
446  TestApplication application;
447 
448  tet_infoline("Test SetGeometryType and GetGeometryType: with index buffer");
449 
450  unsigned int numVertex = 4u;
451  unsigned int numIndex = 6u; // 6 unsigned short
452  PropertyBuffer vertexBuffer = CreateVertexBuffer("aPosition", "aTexCoord" );
453  PropertyBuffer indexBuffer = CreateIndexBuffer( );
454 
455  Geometry geometry = Geometry::New();
456  geometry.AddVertexBuffer( vertexBuffer );
457  geometry.SetIndexBuffer( indexBuffer );
458 
459  Material material = CreateMaterial();
460  Renderer renderer = Renderer::New(geometry, material);
461  Actor actor = Actor::New();
462  actor.SetSize(Vector3::ONE * 100.f);
463  actor.AddRenderer(renderer);
464  Stage::GetCurrent().Add(actor);
465 
466  TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
467  TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
468 
469  /****************************************************/
470  // Default (TRIANGLES), no index buffer
471  drawTrace.Reset();
472  drawTrace.Enable(true);
473  application.SendNotification();
474  application.Render(0);
475  application.Render();
476  application.SendNotification();
477  drawTrace.Enable( false );
478 
479  // Test the default geometry type is GL_TRIANGLE
480  DALI_TEST_EQUALS( drawTrace.CountMethod( "DrawElements" ), 2, TEST_LOCATION);
481  std::stringstream out;
482  out << GL_TRIANGLES << ", " << numIndex << ", " << GL_UNSIGNED_SHORT<<", "<<"indices";
483  DALI_TEST_EQUALS( drawTrace.TestMethodAndParams(1, "DrawElements", out.str()), true, TEST_LOCATION);
484 
486 
487  /*********************************************************/
488  // LINES, no index buffer
489  geometry.SetGeometryType( Geometry::LINES );
490 
491  drawTrace.Reset();
492  drawTrace.Enable(true);
493  application.SendNotification();
494  application.Render(0);
495  application.Render();
496  application.SendNotification();
497  drawTrace.Enable( false );
498 
499  // geometry type is set as GL_LINES
500  DALI_TEST_EQUALS( drawTrace.CountMethod( "DrawElements" ), 2, TEST_LOCATION);
501  out.str("");
502  out << GL_LINES << ", " << numIndex << ", " << GL_UNSIGNED_SHORT<<", "<<"indices";
503  DALI_TEST_EQUALS( drawTrace.TestMethodAndParams(1, "DrawElements", out.str()), true, TEST_LOCATION);
504 
506 
507  /*****************************************************/
508  //POINTS
509  geometry.SetGeometryType( Geometry::POINTS );
510 
511  drawTrace.Reset();
512  drawTrace.Enable(true);
513  application.SendNotification();
514  application.Render(0);
515  application.Render();
516  application.SendNotification();
517  drawTrace.Enable( false );
518 
519  // geometry type is set as GL_POINTS
520  // As Points does not use the index buffer, call glDrawArrays,
521  DALI_TEST_EQUALS( drawTrace.CountMethod( "DrawArrays" ), 2, TEST_LOCATION);
522  out.str("");
523  out << GL_POINTS << ", " << 0 << ", " << numVertex;
524  DALI_TEST_EQUALS( drawTrace.TestMethodAndParams(1, "DrawArrays", out.str()), true, TEST_LOCATION);
525 
527 
528  /*****************************************************/
529  //TRIANGLE_STRIP
531 
532  drawTrace.Reset();
533  drawTrace.Enable(true);
534  application.SendNotification();
535  application.Render(0);
536  application.Render();
537  application.SendNotification();
538  drawTrace.Enable( false );
539 
540  // geometry type is set as GL_POINTS
541  DALI_TEST_EQUALS( drawTrace.CountMethod( "DrawElements" ), 2, TEST_LOCATION);
542  out.str("");
543  out << GL_TRIANGLE_STRIP << ", " << numIndex << ", " << GL_UNSIGNED_SHORT<<", "<<"indices";
544  DALI_TEST_EQUALS( drawTrace.TestMethodAndParams(1, "DrawElements", out.str()), true, TEST_LOCATION);
545 
547 
548  /*****************************************************/
549  //TRIANGLE_FAN
551 
552  drawTrace.Reset();
553  drawTrace.Enable(true);
554  application.SendNotification();
555  application.Render(0);
556  application.Render();
557  application.SendNotification();
558  drawTrace.Enable( false );
559 
560  // geometry type is set as GL_POINTS
561  DALI_TEST_EQUALS( drawTrace.CountMethod( "DrawElements" ), 2, TEST_LOCATION);
562  out.str("");
563  out << GL_TRIANGLE_FAN << ", " << numIndex << ", " << GL_UNSIGNED_SHORT<<", "<<"indices";
564  DALI_TEST_EQUALS( drawTrace.TestMethodAndParams(1, "DrawElements", out.str()), true, TEST_LOCATION);
565 
567 
568  END_TEST;
569 }
570 
572 {
573  TestApplication application;
574 
575  tet_infoline("Test SetRequiresDepthTesting, GetRequiresDepthTesting");
576 
577  Shader shader = Shader::New("VertexSource", "FragmentSource");
578  Material material = Material::New( shader );
579 
580  Geometry geometry = CreateQuadGeometry();
581  Renderer renderer = Renderer::New( geometry, material );
582 
583  Actor actor = Actor::New();
584  actor.AddRenderer(renderer);
585  actor.SetSize(400, 400);
586  Stage::GetCurrent().Add(actor);
587 
589 
590  geometry.SetRequiresDepthTesting(true);
591 
592  TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
593  glAbstraction.EnableEnableDisableCallTrace(true);
594  application.SendNotification();
595  application.Render();
596 // TODO: Not supported yes
597 // TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
598 // std::ostringstream out;
599 // out << GL_DEPTH_TEST;
600 // DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", out.str().c_str() ) );
601 
603 
604  END_TEST;
605 }
606 
608 {
609  TestApplication application;
610 
611  tet_infoline("Test SetRequiresDepthTesting, GetRequiresDepthTesting");
612 
613  Shader shader = Shader::New("VertexSource", "FragmentSource");
614  Material material = Material::New( shader );
615 
616  Geometry geometry = CreateQuadGeometry();
617  Renderer renderer = Renderer::New( geometry, material );
618 
619  Actor actor = Actor::New();
620  actor.AddRenderer(renderer);
621  actor.SetSize(400, 400);
622  Stage::GetCurrent().Add(actor);
623 
625 
627 
628  TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
629  glAbstraction.EnableEnableDisableCallTrace(true);
630  application.SendNotification();
631  application.Render();
632 // TODO: Not supported yet
633 // TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
634 // std::ostringstream out;
635 // out << GL_DEPTH_TEST;
636 // DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", out.str().c_str() ) );
637 
639 
640  END_TEST;
641 }
642 
644 {
645  TestApplication application;
646 
647  tet_infoline("Test that a custom geometry property can be constrained");
648 
649  Shader shader = Shader::New("VertexSource", "FragmentSource");
650  Material material = Material::New( shader );
651 
652  Geometry geometry = CreateQuadGeometry();
653  Renderer renderer = Renderer::New( geometry, material );
654 
655  Actor actor = Actor::New();
656  actor.AddRenderer(renderer);
657  actor.SetSize(400, 400);
658  Stage::GetCurrent().Add(actor);
659 
660  Vector4 initialColor = Color::WHITE;
661  Property::Index colorIndex = geometry.RegisterProperty( "uFadeColor", initialColor );
662 
663  application.SendNotification();
664  application.Render(0);
665  DALI_TEST_EQUALS( geometry.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION );
666 
667  // Apply constraint
668  Constraint constraint = Constraint::New<Vector4>( geometry, colorIndex, TestConstraintNoBlue );
669  constraint.Apply();
670  application.SendNotification();
671  application.Render(0);
672 
673  // Expect no blue component in either buffer - yellow
674  DALI_TEST_EQUALS( geometry.GetProperty<Vector4>(colorIndex), Color::YELLOW, TEST_LOCATION );
675  application.Render(0);
676  DALI_TEST_EQUALS( geometry.GetProperty<Vector4>(colorIndex), Color::YELLOW, TEST_LOCATION );
677 
678  geometry.RemoveConstraints();
679  geometry.SetProperty(colorIndex, Color::WHITE );
680  application.SendNotification();
681  application.Render(0);
682  DALI_TEST_EQUALS( geometry.GetProperty<Vector4>(colorIndex), Color::WHITE, TEST_LOCATION );
683 
684  END_TEST;
685 }
686 
688 {
689  TestApplication application;
690 
691  tet_infoline("Test that a uniform map geometry property can be constrained");
692 
693  Shader shader = Shader::New("VertexSource", "FragmentSource");
694  Material material = Material::New( shader );
695 
696  Geometry geometry = CreateQuadGeometry();
697  Renderer renderer = Renderer::New( geometry, material );
698 
699  Actor actor = Actor::New();
700  actor.AddRenderer(renderer);
701  actor.SetSize(400, 400);
702  Stage::GetCurrent().Add(actor);
703  application.SendNotification();
704  application.Render(0);
705 
706  Vector4 initialColor = Color::WHITE;
707  Property::Index colorIndex = geometry.RegisterProperty( "uFadeColor", initialColor );
708 
709  TestGlAbstraction& gl = application.GetGlAbstraction();
710 
711  application.SendNotification();
712  application.Render(0);
713 
714  Vector4 actualValue(Vector4::ZERO);
715  DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
716  DALI_TEST_EQUALS( actualValue, initialColor, TEST_LOCATION );
717 
718  // Apply constraint
719  Constraint constraint = Constraint::New<Vector4>( geometry, colorIndex, TestConstraintNoBlue );
720  constraint.Apply();
721  application.SendNotification();
722  application.Render(0);
723 
724  // Expect no blue component in either buffer - yellow
725  DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
727 
728  application.Render(0);
729  DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
731 
732  geometry.RemoveConstraints();
733  geometry.SetProperty(colorIndex, Color::WHITE );
734  application.SendNotification();
735  application.Render(0);
736 
737  DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
739 
740  END_TEST;
741 }
742 
743 
744 
746 {
747  TestApplication application;
748 
749  tet_infoline("Test that a custom geometry property can be animated");
750 
751  Shader shader = Shader::New("VertexSource", "FragmentSource");
752  Material material = Material::New( shader );
753 
754  Geometry geometry = CreateQuadGeometry();
755  Renderer renderer = Renderer::New( geometry, material );
756 
757  Actor actor = Actor::New();
758  actor.AddRenderer(renderer);
759  actor.SetSize(400, 400);
760  Stage::GetCurrent().Add(actor);
761 
762  Vector4 initialColor = Color::WHITE;
763  Property::Index colorIndex = geometry.RegisterProperty( "uFadeColor", initialColor );
764 
765  application.SendNotification();
766  application.Render(0);
767  DALI_TEST_EQUALS( geometry.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION );
768 
769  Animation animation = Animation::New(1.0f);
770  KeyFrames keyFrames = KeyFrames::New();
771  keyFrames.Add(0.0f, initialColor);
772  keyFrames.Add(1.0f, Color::TRANSPARENT);
773  animation.AnimateBetween( Property( geometry, colorIndex ), keyFrames );
774  animation.Play();
775 
776  application.SendNotification();
777  application.Render(500);
778 
779  DALI_TEST_EQUALS( geometry.GetProperty<Vector4>(colorIndex), Color::WHITE * 0.5f, TEST_LOCATION );
780 
781  application.Render(500);
782 
784 
785  END_TEST;
786 }
787 
789 {
790  TestApplication application;
791 
792  tet_infoline("Test that a uniform map geometry property can be animated");
793 
794  Shader shader = Shader::New("VertexSource", "FragmentSource");
795  Material material = Material::New( shader );
796 
797  Geometry geometry = CreateQuadGeometry();
798  Renderer renderer = Renderer::New( geometry, material );
799 
800  Actor actor = Actor::New();
801  actor.AddRenderer(renderer);
802  actor.SetSize(400, 400);
803  Stage::GetCurrent().Add(actor);
804  application.SendNotification();
805  application.Render(0);
806 
807  Vector4 initialColor = Color::WHITE;
808  Property::Index colorIndex = geometry.RegisterProperty( "uFadeColor", initialColor );
809 
810  TestGlAbstraction& gl = application.GetGlAbstraction();
811 
812  application.SendNotification();
813  application.Render(0);
814 
815  Vector4 actualValue(Vector4::ZERO);
816  DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
817  DALI_TEST_EQUALS( actualValue, initialColor, TEST_LOCATION );
818 
819  Animation animation = Animation::New(1.0f);
820  KeyFrames keyFrames = KeyFrames::New();
821  keyFrames.Add(0.0f, initialColor);
822  keyFrames.Add(1.0f, Color::TRANSPARENT);
823  animation.AnimateBetween( Property( geometry, colorIndex ), keyFrames );
824  animation.Play();
825 
826  application.SendNotification();
827  application.Render(500);
828 
829  DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
830  DALI_TEST_EQUALS( actualValue, Color::WHITE * 0.5f, TEST_LOCATION );
831 
832  application.Render(500);
833  DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
835 
836  END_TEST;
837 }
Dali Docs Home
Read more about Dali