Dali 3D User Interface Engine
utc-Dali-Renderer.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>
20 
21 using namespace Dali;
22 
23 #include <mesh-builder.h>
24 
25 namespace
26 {
27 void TestConstraintNoBlue( Vector4& current, const PropertyInputContainer& inputs )
28 {
29  current.b = 0.0f;
30 }
31 }
32 
34 {
36 }
37 
39 {
41 }
42 
43 
45 {
46  TestApplication application;
47 
48  Geometry geometry = CreateQuadGeometry();
49  Material material = CreateMaterial();
50  Renderer renderer = Renderer::New(geometry, material);
51 
52  DALI_TEST_EQUALS( (bool)renderer, true, TEST_LOCATION );
53  END_TEST;
54 }
55 
57 {
58  TestApplication application;
59  Renderer renderer;
60  DALI_TEST_EQUALS( (bool)renderer, false, TEST_LOCATION );
61  END_TEST;
62 }
63 
65 {
66  TestApplication application;
67 
68  Geometry geometry = CreateQuadGeometry();
69  Material material = CreateMaterial();
70  Renderer renderer = Renderer::New(geometry, material);
71 
72  Renderer rendererCopy( renderer );
73  DALI_TEST_EQUALS( (bool)rendererCopy, true, TEST_LOCATION );
74 
75  END_TEST;
76 }
77 
79 {
80  TestApplication application;
81 
82  Geometry geometry = CreateQuadGeometry();
83  Material material = CreateMaterial();
84  Renderer renderer = Renderer::New(geometry, material);
85 
86  Renderer renderer2;
87  DALI_TEST_EQUALS( (bool)renderer2, false, TEST_LOCATION );
88 
89  renderer2 = renderer;
90  DALI_TEST_EQUALS( (bool)renderer2, true, TEST_LOCATION );
91  END_TEST;
92 }
93 
95 {
96  TestApplication application;
97 
98  Geometry geometry = CreateQuadGeometry();
99  Material material = CreateMaterial();
100  Renderer renderer = Renderer::New(geometry, material);
101 
102  BaseHandle handle(renderer);
103  Renderer renderer2 = Renderer::DownCast(handle);
104  DALI_TEST_EQUALS( (bool)renderer2, true, TEST_LOCATION );
105  END_TEST;
106 }
107 
109 {
110  TestApplication application;
111 
112  Handle handle = Handle::New(); // Create a custom object
113  Renderer renderer = Renderer::DownCast(handle);
114  DALI_TEST_EQUALS( (bool)renderer, false, TEST_LOCATION );
115  END_TEST;
116 }
117 
119 {
120  TestApplication application;
121  tet_infoline( "Test SetGeometry, GetGeometry" );
122 
123  Geometry geometry1 = CreateQuadGeometry();
124  geometry1.RegisterProperty( "uFadeColor", Color::RED );
125 
126  Geometry geometry2 = CreateQuadGeometry();
127  geometry2.RegisterProperty( "uFadeColor", Color::GREEN );
128 
129  Material material = CreateMaterial();
130  Renderer renderer = Renderer::New(geometry1, material);
131  Actor actor = Actor::New();
132  actor.AddRenderer(renderer);
133  actor.SetSize(400, 400);
134  Stage::GetCurrent().Add(actor);
135 
136  TestGlAbstraction& gl = application.GetGlAbstraction();
137  application.SendNotification();
138  application.Render(0);
139 
140  // Expect that the first geometry's fade color property is accessed
141  Vector4 actualValue(Vector4::ZERO);
142  DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
143  DALI_TEST_EQUALS( actualValue, Color::RED, TEST_LOCATION );
144 
145  DALI_TEST_EQUALS( renderer.GetGeometry(), geometry1, TEST_LOCATION );
146 
147  // Set geometry2 to the renderer
148  renderer.SetGeometry( geometry2 );
149 
150  application.SendNotification();
151  application.Render(0);
152 
153  // Expect that the second geometry's fade color property is accessed
154  DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
156 
157  DALI_TEST_EQUALS( renderer.GetGeometry(), geometry2, TEST_LOCATION );
158 
159  END_TEST;
160 }
161 
163 {
164  TestApplication application;
165  tet_infoline( "Test SetMaterial, GetMaterial" );
166 
167  TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
168  glAbstraction.EnableCullFaceCallTrace(true);
169 
170  Material material1 = CreateMaterial();
171  material1.RegisterProperty( "uFadeColor", Color::RED );
172 
173  Material material2 = CreateMaterial();
174  material2.RegisterProperty( "uFadeColor", Color::GREEN );
175 
176  Geometry geometry = CreateQuadGeometry();
177  Renderer renderer = Renderer::New(geometry, material1);
178  Actor actor = Actor::New();
179  actor.AddRenderer(renderer);
180  actor.SetSize(400, 400);
181  Stage::GetCurrent().Add(actor);
182 
183  TestGlAbstraction& gl = application.GetGlAbstraction();
184  application.SendNotification();
185  application.Render(0);
186 
187  // Expect that the first material's fade color property is accessed
188  Vector4 actualValue(Vector4::ZERO);
189  DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
190  DALI_TEST_EQUALS( actualValue, Color::RED, TEST_LOCATION );
191 
192  DALI_TEST_EQUALS( renderer.GetMaterial(), material1, TEST_LOCATION );
193 
194  // set the second material to the renderer
195  renderer.SetMaterial( material2 );
196 
197  application.SendNotification();
198  application.Render(0);
199 
200  // Expect that the second material's fade color property is accessed
201  DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
203 
204  DALI_TEST_EQUALS( renderer.GetMaterial(), material2, TEST_LOCATION );
205 
206  END_TEST;
207 }
208 
210 {
211  TestApplication application;
212 
213  tet_infoline("Test SetDepthIndex, GetDepthIndex");
214 
215  Material material = CreateMaterial();
216  Geometry geometry = CreateQuadGeometry();
217  Renderer renderer = Renderer::New(geometry, material);
218  Actor actor = Actor::New();
219  actor.AddRenderer(renderer);
220  actor.SetSize(400, 400);
221  Stage::GetCurrent().Add(actor);
222 
223  application.SendNotification();
224  application.Render(0);
226 
228 
229  application.SendNotification();
230  application.Render(0);
232 
234 
235  application.SendNotification();
236  application.Render(0);
238 
239  END_TEST;
240 }
241 
243 {
244  TestApplication application;
245 
246  tet_infoline("Test SetFaceCullingMode(cullingMode)");
247  Geometry geometry = CreateQuadGeometry();
248  Material material = CreateMaterial();
249  Renderer renderer = Renderer::New( geometry, material );
250 
251  Actor actor = Actor::New();
252  actor.AddRenderer(renderer);
253  actor.SetSize(400, 400);
254  Stage::GetCurrent().Add(actor);
255 
256  // By default, none of the faces should be culled
257  unsigned int cullFace = renderer.GetProperty<int>( Renderer::Property::FACE_CULLING_MODE );
258  DALI_TEST_CHECK( static_cast< Dali::Renderer::FaceCullingMode >( cullFace ) == Renderer::NONE );
259 
260  TestGlAbstraction& gl = application.GetGlAbstraction();
261  TraceCallStack& cullFaceStack = gl.GetCullFaceTrace();
262  gl.EnableCullFaceCallTrace(true);
263 
264  {
265  cullFaceStack.Reset();
267  application.SendNotification();
268  application.Render();
269 
270  DALI_TEST_EQUALS( cullFaceStack.CountMethod( "CullFace" ), 1, TEST_LOCATION );
271 
272  std::ostringstream cullModeString;
273  cullModeString << GL_FRONT_AND_BACK;
274 
275  DALI_TEST_CHECK( cullFaceStack.FindMethodAndParams( "CullFace", cullModeString.str() ) );
276  cullFace = renderer.GetProperty<int>( Renderer::Property::FACE_CULLING_MODE );
277  DALI_TEST_CHECK( static_cast< Dali::Renderer::FaceCullingMode >( cullFace ) == Renderer::CULL_BACK_AND_FRONT);
278  }
279 
280  {
281  cullFaceStack.Reset();
283  application.SendNotification();
284  application.Render();
285 
286  DALI_TEST_EQUALS( cullFaceStack.CountMethod( "CullFace" ), 1, TEST_LOCATION );
287 
288  std::ostringstream cullModeString;
289  cullModeString << GL_BACK;
290 
291  DALI_TEST_CHECK( cullFaceStack.FindMethodAndParams( "CullFace", cullModeString.str() ) );
292  cullFace = renderer.GetProperty<int>( Renderer::Property::FACE_CULLING_MODE );
293  DALI_TEST_CHECK( static_cast< Dali::Renderer::FaceCullingMode >( cullFace ) == Renderer::CULL_BACK );
294  }
295 
296  {
297  cullFaceStack.Reset();
299  application.SendNotification();
300  application.Render();
301 
302  DALI_TEST_EQUALS( cullFaceStack.CountMethod( "CullFace" ), 1, TEST_LOCATION );
303 
304  std::ostringstream cullModeString;
305  cullModeString << GL_FRONT;
306 
307  DALI_TEST_CHECK( cullFaceStack.FindMethodAndParams( "CullFace", cullModeString.str() ) );
308  cullFace = renderer.GetProperty<int>( Renderer::Property::FACE_CULLING_MODE );
309  DALI_TEST_CHECK( static_cast< Dali::Renderer::FaceCullingMode >( cullFace ) == Renderer::CULL_FRONT );
310  }
311 
312  {
313  cullFaceStack.Reset();
315  application.SendNotification();
316  application.Render();
317 
318  DALI_TEST_EQUALS( cullFaceStack.CountMethod( "CullFace" ), 0, TEST_LOCATION );
319  cullFace = renderer.GetProperty<int>( Renderer::Property::FACE_CULLING_MODE );
320  DALI_TEST_CHECK( static_cast< Dali::Renderer::FaceCullingMode >( cullFace ) == Renderer::NONE );
321  }
322 
323  END_TEST;
324 }
325 
327 {
328  TestApplication application;
329 
330  tet_infoline("Test SetBlendFunc(src, dest) ");
331 
332  Geometry geometry = CreateQuadGeometry();
333  Material material = CreateMaterial();
334  Renderer renderer = Renderer::New( geometry, material );
335 
336  Actor actor = Actor::New();
337  // set a transparent actor color so that blending is enabled
338  actor.SetOpacity( 0.5f );
339  actor.AddRenderer(renderer);
340  actor.SetSize(400, 400);
341  Stage::GetCurrent().Add(actor);
342 
344 
345  // Test that Set was successful:
348  BlendingFactor::Type srcFactorAlpha( BlendingFactor::ZERO );
349  BlendingFactor::Type destFactorAlpha( BlendingFactor::ZERO );
350  renderer.GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
351 
356 
357  application.SendNotification();
358  application.Render();
359 
360  TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
361 
364  DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_SRC_COLOR, glAbstraction.GetLastBlendFuncSrcAlpha(), TEST_LOCATION );
365  DALI_TEST_EQUALS( (GLenum)GL_SRC_ALPHA_SATURATE, glAbstraction.GetLastBlendFuncDstAlpha(), TEST_LOCATION );
366 
367  END_TEST;
368 }
369 
371 {
372  TestApplication application;
373 
374  tet_infoline("Test SetBlendFunc(srcRgb, destRgb, srcAlpha, destAlpha) ");
375 
376  Geometry geometry = CreateQuadGeometry();
377  Material material = CreateMaterial();
378  Renderer renderer = Renderer::New( geometry, material );
379 
380  Actor actor = Actor::New();
381  actor.SetOpacity( 0.5f ); // enable blending
382  actor.AddRenderer(renderer);
383  actor.SetSize(400, 400);
384  Stage::GetCurrent().Add(actor);
385 
388 
389  // Test that Set was successful:
390  {
393  BlendingFactor::Type srcFactorAlpha( BlendingFactor::ZERO );
394  BlendingFactor::Type destFactorAlpha( BlendingFactor::ZERO );
395  renderer.GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
396 
401  }
402 
403  application.SendNotification();
404  application.Render();
405 
406  TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
411 
412  END_TEST;
413 }
414 
416 {
417  TestApplication application;
418 
419  tet_infoline("Test GetBlendEquation() defaults ");
420 
421  Geometry geometry = CreateQuadGeometry();
422  Material material = CreateMaterial();
423  Renderer renderer = Renderer::New( geometry, material );
424 
425  Actor actor = Actor::New();
426  actor.AddRenderer(renderer);
427  actor.SetSize(400, 400);
428  Stage::GetCurrent().Add(actor);
429 
430  // Test the defaults as documented in blending.h
433  renderer.GetBlendEquation( equationRgb, equationAlpha );
436 
437  END_TEST;
438 }
439 
441 {
442  TestApplication application;
443 
444  tet_infoline("Test SetBlendEquation() ");
445 
446  Geometry geometry = CreateQuadGeometry();
447  Material material = CreateMaterial();
448  Renderer renderer = Renderer::New( geometry, material );
449 
450  Actor actor = Actor::New();
451  actor.SetOpacity( 0.1f );
452  actor.AddRenderer(renderer);
453  actor.SetSize(400, 400);
454  Stage::GetCurrent().Add(actor);
455 
456  // Test the single blending equation setting
457  {
460  renderer.GetBlendEquation( equationRgba, equationRgba );
462  }
463 
465 
466  // Test that Set was successful
467  {
470  renderer.GetBlendEquation( equationRgb, equationAlpha );
473  }
474 
475  // Render & check GL commands
476  application.SendNotification();
477  application.Render();
478 
479  TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
481  DALI_TEST_EQUALS( (GLenum)GL_FUNC_REVERSE_SUBTRACT, glAbstraction.GetLastBlendEquationAlpha(), TEST_LOCATION );
482 
483  END_TEST;
484 }
485 
487 {
488  TestApplication application;
489 
490  tet_infoline("Test setting the blend mode to on with an opaque color renders with blending enabled");
491 
492  Geometry geometry = CreateQuadGeometry();
493  Material material = CreateMaterial();
494  Renderer renderer = Renderer::New( geometry, material );
495 
496  Actor actor = Actor::New();
497  actor.SetOpacity( 0.98f );
498  actor.AddRenderer(renderer);
499  actor.SetSize(400, 400);
500  Stage::GetCurrent().Add(actor);
501 
503 
504  TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
505  glAbstraction.EnableEnableDisableCallTrace(true);
506 
507  application.SendNotification();
508  application.Render();
509 
510  TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
511  std::ostringstream blendStr;
512  blendStr << GL_BLEND;
513  DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
514 
515  END_TEST;
516 }
517 
519 {
520  TestApplication application;
521 
522  tet_infoline("Test setting the blend mode to off with a transparent color renders with blending disabled (and not enabled)");
523 
524  Geometry geometry = CreateQuadGeometry();
525  Material material = CreateMaterial();
526  Renderer renderer = Renderer::New( geometry, material );
527 
528  Actor actor = Actor::New();
529  actor.SetOpacity( 0.15f );
530  actor.AddRenderer(renderer);
531  actor.SetSize(400, 400);
532  Stage::GetCurrent().Add(actor);
533 
535 
536  TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
537  glAbstraction.EnableEnableDisableCallTrace(true);
538 
539  application.SendNotification();
540  application.Render();
541 
542  TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
543  std::ostringstream blendStr;
544  blendStr << GL_BLEND;
545  DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
546 
547  END_TEST;
548 }
549 
551 {
552  TestApplication application;
553 
554  tet_infoline("Test setting the blend mode to auto with a transparent material color renders with blending enabled");
555 
556  Geometry geometry = CreateQuadGeometry();
557  Material material = CreateMaterial();
558  Renderer renderer = Renderer::New( geometry, material );
559 
560  Actor actor = Actor::New();
561  actor.SetOpacity( 0.75f );
562  actor.AddRenderer(renderer);
563  actor.SetSize(400, 400);
564  Stage::GetCurrent().Add(actor);
565 
567 
568  TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
569  glAbstraction.EnableEnableDisableCallTrace(true);
570 
571  application.SendNotification();
572  application.Render();
573 
574  TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
575  std::ostringstream blendStr;
576  blendStr << GL_BLEND;
577  DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
578 
579  END_TEST;
580 }
581 
583 {
584  TestApplication application;
585 
586  tet_infoline("Test setting the blend mode to auto with an opaque color renders with blending disabled");
587 
588  Geometry geometry = CreateQuadGeometry();
589  Material material = CreateMaterial();
590  Renderer renderer = Renderer::New( geometry, material );
591 
592  Actor actor = Actor::New();
593  actor.AddRenderer(renderer);
594  actor.SetSize(400, 400);
595  Stage::GetCurrent().Add(actor);
596 
598 
599  TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
600  glAbstraction.EnableEnableDisableCallTrace(true);
601 
602  application.SendNotification();
603  application.Render();
604 
605  TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
606  std::ostringstream blendStr;
607  blendStr << GL_BLEND;
608  DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
609 
610  END_TEST;
611 }
612 
614 {
615  TestApplication application;
616 
617  tet_infoline("Test setting the blend mode to auto with an opaque material color and a transparent actor color renders with blending enabled");
618 
619  Geometry geometry = CreateQuadGeometry();
620  Material material = CreateMaterial();
621  Renderer renderer = Renderer::New( geometry, material );
622 
623  Actor actor = Actor::New();
624  actor.AddRenderer(renderer);
625  actor.SetSize(400, 400);
626  actor.SetColor( Vector4(1.0f, 0.0f, 1.0f, 0.5f) );
627  Stage::GetCurrent().Add(actor);
628 
630 
631  TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
632  glAbstraction.EnableEnableDisableCallTrace(true);
633 
634  application.SendNotification();
635  application.Render();
636 
637  TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
638  std::ostringstream blendStr;
639  blendStr << GL_BLEND;
640  DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
641 
642  END_TEST;
643 }
644 
646 {
647  TestApplication application;
648 
649  tet_infoline("Test setting the blend mode to auto with an opaque material color and an opaque actor color renders with blending disabled");
650 
651  Geometry geometry = CreateQuadGeometry();
652  Material material = CreateMaterial();
653  Renderer renderer = Renderer::New( geometry, material );
654 
655  Actor actor = Actor::New();
656  actor.AddRenderer(renderer);
657  actor.SetSize(400, 400);
658  actor.SetColor( Color::MAGENTA );
659  Stage::GetCurrent().Add(actor);
660 
662 
663  TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
664  glAbstraction.EnableEnableDisableCallTrace(true);
665 
666  application.SendNotification();
667  application.Render();
668 
669  TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
670  std::ostringstream blendStr;
671  blendStr << GL_BLEND;
672  DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
673 
674  END_TEST;
675 }
676 
678 {
679  TestApplication application;
680 
681  tet_infoline("Test setting the blend mode to auto with an opaque color and an image with an alpha channel renders with blending enabled");
682 
683  Geometry geometry = CreateQuadGeometry();
684  BufferImage image = BufferImage::New( 40, 40, Pixel::RGBA8888 );
685  Material material = CreateMaterial( image );
686  Renderer renderer = Renderer::New( geometry, material );
687 
688  Actor actor = Actor::New();
689  actor.AddRenderer(renderer);
690  actor.SetSize(400, 400);
691  Stage::GetCurrent().Add(actor);
692 
694 
695  TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
696  glAbstraction.EnableEnableDisableCallTrace(true);
697 
698  application.SendNotification();
699  application.Render();
700 
701  TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
702  std::ostringstream blendStr;
703  blendStr << GL_BLEND;
704  DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
705 
706  END_TEST;
707 }
708 
710 {
711  TestApplication application;
712  tet_infoline("Test setting the blend mode to auto with an opaque color and an image without an alpha channel and a shader with the hint OUTPUT_IS_TRANSPARENT renders with blending enabled");
713 
714  Geometry geometry = CreateQuadGeometry();
715  Shader shader = Shader::New( "vertexSrc", "fragmentSrc", Shader::HINT_OUTPUT_IS_TRANSPARENT );
716  Material material = Material::New(shader);
717 
718  Renderer renderer = Renderer::New( geometry, material );
719 
720  Actor actor = Actor::New();
721  actor.AddRenderer(renderer);
722  actor.SetSize(400, 400);
723  Stage::GetCurrent().Add(actor);
724 
726 
727  TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
728  glAbstraction.EnableEnableDisableCallTrace(true);
729 
730  application.SendNotification();
731  application.Render();
732 
733  TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
734  std::ostringstream blendStr;
735  blendStr << GL_BLEND;
736  DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
737 
738  END_TEST;
739 }
740 
742 {
743  TestApplication application;
744  tet_infoline("Test setting the blend mode to auto with an opaque color and an image without an alpha channel and a shader with the hint OUTPUT_IS_OPAQUE renders with blending disabled");
745 
746  Geometry geometry = CreateQuadGeometry();
747  Shader shader = Shader::New( "vertexSrc", "fragmentSrc", Shader::HINT_OUTPUT_IS_OPAQUE );
748  Material material = Material::New(shader);
749  BufferImage image = BufferImage::New( 50, 50, Pixel::RGB888 );
750  material.AddTexture( image, "sTexture" );
751  Renderer renderer = Renderer::New( geometry, material );
752 
753  Actor actor = Actor::New();
754  actor.AddRenderer(renderer);
755  actor.SetSize(400, 400);
756  Stage::GetCurrent().Add(actor);
757 
759 
760  TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
761  glAbstraction.EnableEnableDisableCallTrace(true);
762 
763  application.SendNotification();
764  application.Render();
765 
766  TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
767  DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", "GL_BLEND" ) );
768 
769  END_TEST;
770 }
771 
773 {
774  TestApplication application;
775 
776  tet_infoline("Test GetBlendMode()");
777 
778  Geometry geometry = CreateQuadGeometry();
779  Shader shader = Shader::New( "vertexSrc", "fragmentSrc", Shader::HINT_OUTPUT_IS_OPAQUE );
780  Material material = Material::New(shader);
781  Renderer renderer = Renderer::New( geometry, material );
782 
783  // default value
784  unsigned int mode = renderer.GetProperty<int>( Renderer::Property::BLENDING_MODE );
785  DALI_TEST_EQUALS( static_cast< BlendingMode::Type >( mode ), BlendingMode::AUTO, TEST_LOCATION );
786 
787  // ON
789  mode = renderer.GetProperty<int>( Renderer::Property::BLENDING_MODE );
790  DALI_TEST_EQUALS( static_cast< BlendingMode::Type >( mode ), BlendingMode::ON, TEST_LOCATION );
791 
792  // OFF
794  mode = renderer.GetProperty<int>( Renderer::Property::BLENDING_MODE );
795  DALI_TEST_EQUALS( static_cast< BlendingMode::Type >( mode ), BlendingMode::OFF, TEST_LOCATION );
796 
797  END_TEST;
798 }
799 
801 {
802  TestApplication application;
803 
804  tet_infoline("Test SetBlendColor(color)");
805 
806  Geometry geometry = CreateQuadGeometry();
807  Shader shader = Shader::New( "vertexSrc", "fragmentSrc", Shader::HINT_OUTPUT_IS_OPAQUE );
808  Material material = Material::New(shader);
809  BufferImage image = BufferImage::New( 50, 50, Pixel::RGBA8888 );
810  material.AddTexture( image, "sTexture" );
811  Renderer renderer = Renderer::New( geometry, material );
812 
813  Actor actor = Actor::New();
814  actor.AddRenderer(renderer);
815  actor.SetSize(400, 400);
816  Stage::GetCurrent().Add(actor);
817 
818  TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
819 
821  application.SendNotification();
822  application.Render();
824 
826  application.SendNotification();
827  application.Render();
829 
830  Vector4 color( 0.1f, 0.2f, 0.3f, 0.4f );
832  application.SendNotification();
833  application.Render();
834  DALI_TEST_EQUALS( glAbstraction.GetLastBlendColor(), color, TEST_LOCATION );
835 
836  END_TEST;
837 }
838 
840 {
841  TestApplication application;
842 
843  tet_infoline("Test GetBlendColor()");
844 
845  Geometry geometry = CreateQuadGeometry();
846  Shader shader = Shader::New( "vertexSrc", "fragmentSrc", Shader::HINT_OUTPUT_IS_OPAQUE );
847  Material material = Material::New(shader);
848  Renderer renderer = Renderer::New( geometry, material );
849 
851 
853  application.SendNotification();
854  application.Render();
856 
857  Vector4 color( 0.1f, 0.2f, 0.3f, 0.4f );
859  application.SendNotification();
860  application.Render();
862 
863  END_TEST;
864 }
865 
867 {
868  TestApplication application;
869 
870  tet_infoline("Test BLEND_PRE_MULTIPLIED_ALPHA property");
871 
872  Geometry geometry = CreateQuadGeometry();
873  Shader shader = Shader::New( "vertexSrc", "fragmentSrc", Shader::HINT_OUTPUT_IS_OPAQUE );
874  Material material = Material::New(shader);
875 
876  Renderer renderer = Renderer::New( geometry, material );
877 
878  Actor actor = Actor::New();
879  actor.AddRenderer(renderer);
880  actor.SetSize(400, 400);
881  actor.SetColor( Vector4(1.0f, 0.0f, 1.0f, 0.5f) );
882  Stage::GetCurrent().Add(actor);
883 
885  bool preMultipliedAlpha;
886  DALI_TEST_CHECK( value.Get( preMultipliedAlpha ) );
887  DALI_TEST_CHECK( !preMultipliedAlpha );
888 
891  BlendingFactor::Type srcFactorAlpha( BlendingFactor::ZERO );
892  BlendingFactor::Type destFactorAlpha( BlendingFactor::ZERO );
893  renderer.GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
898 
899  application.SendNotification();
900  application.Render();
901 
902  Vector4 actualValue(Vector4::ZERO);
903  TestGlAbstraction& gl = application.GetGlAbstraction();
904  DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uColor", actualValue ) );
905  DALI_TEST_EQUALS( actualValue, Vector4(1.0f, 0.0f, 1.0f, 0.5f), TEST_LOCATION );
906 
908 
909  application.SendNotification();
910  application.Render();
911 
913  DALI_TEST_CHECK( value.Get( preMultipliedAlpha ) );
914  DALI_TEST_CHECK( preMultipliedAlpha );
915 
916  renderer.GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
921 
922  DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uColor", actualValue ) );
923  DALI_TEST_EQUALS( actualValue, Vector4(0.5f, 0.0f, 0.5f, 0.5f), TEST_LOCATION );
924 
925  END_TEST;
926 }
927 
929 {
930  TestApplication application;
931 
932  tet_infoline("Test that a non-uniform renderer property can be constrained");
933 
934  Shader shader = Shader::New("VertexSource", "FragmentSource");
935  Material material = Material::New( shader );
936 
937  Geometry geometry = CreateQuadGeometry();
938  Renderer renderer = Renderer::New( geometry, material );
939 
940  Actor actor = Actor::New();
941  actor.AddRenderer(renderer);
942  actor.SetSize(400, 400);
943  Stage::GetCurrent().Add(actor);
944 
945  Vector4 initialColor = Color::WHITE;
946  Property::Index colorIndex = renderer.RegisterProperty( "uFadeColor", initialColor );
947 
948  application.SendNotification();
949  application.Render(0);
950  DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION );
951 
952  // Apply constraint
953  Constraint constraint = Constraint::New<Vector4>( renderer, colorIndex, TestConstraintNoBlue );
954  constraint.Apply();
955  application.SendNotification();
956  application.Render(0);
957 
958  // Expect no blue component in either buffer - yellow
959  DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(colorIndex), Color::YELLOW, TEST_LOCATION );
960  application.Render(0);
961  DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(colorIndex), Color::YELLOW, TEST_LOCATION );
962 
963  renderer.RemoveConstraints();
964  renderer.SetProperty(colorIndex, Color::WHITE );
965  application.SendNotification();
966  application.Render(0);
967  DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(colorIndex), Color::WHITE, TEST_LOCATION );
968 
969  END_TEST;
970 }
971 
973 {
974  TestApplication application;
975 
976  tet_infoline("Test that a uniform map renderer property can be constrained");
977 
978  Shader shader = Shader::New("VertexSource", "FragmentSource");
979  Material material = Material::New( shader );
980 
981  Geometry geometry = CreateQuadGeometry();
982  Renderer renderer = Renderer::New( geometry, material );
983 
984  Actor actor = Actor::New();
985  actor.AddRenderer(renderer);
986  actor.SetSize(400, 400);
987  Stage::GetCurrent().Add(actor);
988  application.SendNotification();
989  application.Render(0);
990 
991  Vector4 initialColor = Color::WHITE;
992  Property::Index colorIndex = renderer.RegisterProperty( "uFadeColor", initialColor );
993 
994  TestGlAbstraction& gl = application.GetGlAbstraction();
995 
996  application.SendNotification();
997  application.Render(0);
998 
999  Vector4 actualValue(Vector4::ZERO);
1000  DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1001  DALI_TEST_EQUALS( actualValue, initialColor, TEST_LOCATION );
1002 
1003  // Apply constraint
1004  Constraint constraint = Constraint::New<Vector4>( renderer, colorIndex, TestConstraintNoBlue );
1005  constraint.Apply();
1006  application.SendNotification();
1007  application.Render(0);
1008 
1009  // Expect no blue component in either buffer - yellow
1010  DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1011  DALI_TEST_EQUALS( actualValue, Color::YELLOW, TEST_LOCATION );
1012 
1013  application.Render(0);
1014  DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1015  DALI_TEST_EQUALS( actualValue, Color::YELLOW, TEST_LOCATION );
1016 
1017  renderer.RemoveConstraints();
1018  renderer.SetProperty(colorIndex, Color::WHITE );
1019  application.SendNotification();
1020  application.Render(0);
1021 
1022  DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1023  DALI_TEST_EQUALS( actualValue, Color::WHITE, TEST_LOCATION );
1024 
1025  END_TEST;
1026 }
1027 
1028 
1029 
1031 {
1032  TestApplication application;
1033 
1034  tet_infoline("Test that a non-uniform renderer property can be animated");
1035 
1036  Shader shader = Shader::New("VertexSource", "FragmentSource");
1037  Material material = Material::New( shader );
1038 
1039  Geometry geometry = CreateQuadGeometry();
1040  Renderer renderer = Renderer::New( geometry, material );
1041 
1042  Actor actor = Actor::New();
1043  actor.AddRenderer(renderer);
1044  actor.SetSize(400, 400);
1045  Stage::GetCurrent().Add(actor);
1046 
1047  Vector4 initialColor = Color::WHITE;
1048  Property::Index colorIndex = renderer.RegisterProperty( "uFadeColor", initialColor );
1049 
1050  application.SendNotification();
1051  application.Render(0);
1052  DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION );
1053 
1054  Animation animation = Animation::New(1.0f);
1055  KeyFrames keyFrames = KeyFrames::New();
1056  keyFrames.Add(0.0f, initialColor);
1057  keyFrames.Add(1.0f, Color::TRANSPARENT);
1058  animation.AnimateBetween( Property( renderer, colorIndex ), keyFrames );
1059  animation.Play();
1060 
1061  application.SendNotification();
1062  application.Render(500);
1063 
1064  DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(colorIndex), Color::WHITE * 0.5f, TEST_LOCATION );
1065 
1066  application.Render(500);
1067 
1069 
1070  END_TEST;
1071 }
1072 
1074 {
1075  TestApplication application;
1076 
1077  tet_infoline("Test that a uniform map renderer property can be animated");
1078 
1079  Shader shader = Shader::New("VertexSource", "FragmentSource");
1080  Material material = Material::New( shader );
1081 
1082  Geometry geometry = CreateQuadGeometry();
1083  Renderer renderer = Renderer::New( geometry, material );
1084 
1085  Actor actor = Actor::New();
1086  actor.AddRenderer(renderer);
1087  actor.SetSize(400, 400);
1088  Stage::GetCurrent().Add(actor);
1089  application.SendNotification();
1090  application.Render(0);
1091 
1092  Vector4 initialColor = Color::WHITE;
1093  Property::Index colorIndex = renderer.RegisterProperty( "uFadeColor", initialColor );
1094 
1095  TestGlAbstraction& gl = application.GetGlAbstraction();
1096 
1097  application.SendNotification();
1098  application.Render(0);
1099 
1100  Vector4 actualValue(Vector4::ZERO);
1101  DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1102  DALI_TEST_EQUALS( actualValue, initialColor, TEST_LOCATION );
1103 
1104  Animation animation = Animation::New(1.0f);
1105  KeyFrames keyFrames = KeyFrames::New();
1106  keyFrames.Add(0.0f, initialColor);
1107  keyFrames.Add(1.0f, Color::TRANSPARENT);
1108  animation.AnimateBetween( Property( renderer, colorIndex ), keyFrames );
1109  animation.Play();
1110 
1111  application.SendNotification();
1112  application.Render(500);
1113 
1114  DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1115  DALI_TEST_EQUALS( actualValue, Color::WHITE * 0.5f, TEST_LOCATION );
1116 
1117  application.Render(500);
1118  DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1120 
1121  END_TEST;
1122 }
1123 
1124 
1125 
1126 
1128 {
1129  TestApplication application;
1130 
1131  tet_infoline("Test the uniform map precedence is applied properly");
1132 
1133  Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1134 
1135  Shader shader = Shader::New("VertexSource", "FragmentSource");
1136  Material material = Material::New( shader );
1137  material.AddTexture( image, "sTexture" );
1138 
1139  PropertyBuffer vertexBuffer = CreatePropertyBuffer();
1140  Geometry geometry = CreateQuadGeometryFromBuffer(vertexBuffer);
1141  Renderer renderer = Renderer::New( geometry, material );
1142 
1143  Actor actor = Actor::New();
1144  actor.AddRenderer(renderer);
1145  actor.SetSize(400, 400);
1146  Stage::GetCurrent().Add(actor);
1147  application.SendNotification();
1148  application.Render(0);
1149 
1150  renderer.RegisterProperty( "uFadeColor", Color::RED );
1151 
1152  actor.RegisterProperty( "uFadeColor", Color::GREEN );
1153 
1154  Property::Index materialFadeColorIndex = material.RegisterProperty( "uFadeColor", Color::BLUE );
1155 
1156  shader.RegisterProperty( "uFadeColor", Color::MAGENTA );
1157 
1158  geometry.RegisterProperty( "uFadeColor", Color::YELLOW );
1159 
1160  TestGlAbstraction& gl = application.GetGlAbstraction();
1161 
1162  application.SendNotification();
1163  application.Render(0);
1164 
1165  // Expect that the actor's fade color property is accessed
1166  Vector4 actualValue(Vector4::ZERO);
1167  DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1168  DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
1169 
1170  // Animate material's fade color property. Should be no change to uniform
1171  Animation animation = Animation::New(1.0f);
1172  KeyFrames keyFrames = KeyFrames::New();
1173  keyFrames.Add(0.0f, Color::WHITE);
1174  keyFrames.Add(1.0f, Color::TRANSPARENT);
1175  animation.AnimateBetween( Property( material, materialFadeColorIndex ), keyFrames );
1176  animation.Play();
1177 
1178  application.SendNotification();
1179  application.Render(500);
1180 
1181  DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1182  DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
1183 
1184  application.Render(500);
1185  DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1186  DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
1187 
1188  END_TEST;
1189 }
1190 
1192 {
1193  TestApplication application;
1194 
1195  tet_infoline("Test the uniform map precedence is applied properly");
1196 
1197  Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1198 
1199  Shader shader = Shader::New("VertexSource", "FragmentSource");
1200  Material material = Material::New( shader );
1201  material.AddTexture( image, "sTexture" );
1202 
1203  PropertyBuffer vertexBuffer = CreatePropertyBuffer();
1204  Geometry geometry = CreateQuadGeometryFromBuffer(vertexBuffer);
1205  Renderer renderer = Renderer::New( geometry, material );
1206 
1207  Actor actor = Actor::New();
1208  actor.AddRenderer(renderer);
1209  actor.SetSize(400, 400);
1210  Stage::GetCurrent().Add(actor);
1211  application.SendNotification();
1212  application.Render(0);
1213 
1214  // Don't add property / uniform map to renderer
1215 
1216  actor.RegisterProperty( "uFadeColor", Color::GREEN );
1217 
1218  Property::Index materialFadeColorIndex = material.RegisterProperty( "uFadeColor", Color::BLUE );
1219 
1220  shader.RegisterProperty( "uFadeColor", Color::MAGENTA );
1221 
1222  geometry.RegisterProperty( "uFadeColor", Color::YELLOW );
1223 
1224 
1225  TestGlAbstraction& gl = application.GetGlAbstraction();
1226 
1227  application.SendNotification();
1228  application.Render(0);
1229 
1230  // Expect that the actor's fade color property is accessed
1231  Vector4 actualValue(Vector4::ZERO);
1232  DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1233  DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
1234 
1235  // Animate material's fade color property. Should be no change to uniform
1236  Animation animation = Animation::New(1.0f);
1237  KeyFrames keyFrames = KeyFrames::New();
1238  keyFrames.Add(0.0f, Color::WHITE);
1239  keyFrames.Add(1.0f, Color::TRANSPARENT);
1240  animation.AnimateBetween( Property( material, materialFadeColorIndex ), keyFrames );
1241  animation.Play();
1242 
1243  application.SendNotification();
1244  application.Render(500);
1245 
1246  DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1247  DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
1248 
1249  application.Render(500);
1250  DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1251  DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
1252 
1253  END_TEST;
1254 }
1255 
1256 
1258 {
1259  TestApplication application;
1260 
1261  tet_infoline("Test the uniform map precedence is applied properly");
1262 
1263  Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1264 
1265  Shader shader = Shader::New("VertexSource", "FragmentSource");
1266  Material material = Material::New( shader );
1267  material.AddTexture( image, "sTexture" );
1268 
1269  PropertyBuffer vertexBuffer = CreatePropertyBuffer();
1270  Geometry geometry = CreateQuadGeometryFromBuffer(vertexBuffer);
1271  Renderer renderer = Renderer::New( geometry, material );
1272 
1273  Actor actor = Actor::New();
1274  actor.AddRenderer(renderer);
1275  actor.SetSize(400, 400);
1276  Stage::GetCurrent().Add(actor);
1277  application.SendNotification();
1278  application.Render(0);
1279 
1280  // Don't add property / uniform map to renderer or actor
1281 
1282  material.RegisterProperty( "uFadeColor", Color::BLUE );
1283 
1284  shader.RegisterProperty( "uFadeColor", Color::MAGENTA );
1285 
1286  Property::Index geometryFadeColorIndex = geometry.RegisterProperty( "uFadeColor", Color::YELLOW );
1287 
1288  geometry.RegisterProperty( "uFadeColor", Color::BLACK );
1289 
1290 
1291  TestGlAbstraction& gl = application.GetGlAbstraction();
1292 
1293  application.SendNotification();
1294  application.Render(0);
1295 
1296  // Expect that the material's fade color property is accessed
1297  Vector4 actualValue(Vector4::ZERO);
1298  DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1299  DALI_TEST_EQUALS( actualValue, Color::BLUE, TEST_LOCATION );
1300 
1301  // Animate geometry's fade color property. Should be no change to uniform
1302  Animation animation = Animation::New(1.0f);
1303  KeyFrames keyFrames = KeyFrames::New();
1304  keyFrames.Add(0.0f, Color::WHITE);
1305  keyFrames.Add(1.0f, Color::TRANSPARENT);
1306  animation.AnimateBetween( Property( geometry, geometryFadeColorIndex ), keyFrames );
1307  animation.Play();
1308 
1309  application.SendNotification();
1310  application.Render(500);
1311 
1312  DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1313  DALI_TEST_EQUALS( actualValue, Color::BLUE, TEST_LOCATION );
1314 
1315  application.Render(500);
1316  DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1317  DALI_TEST_EQUALS( actualValue, Color::BLUE, TEST_LOCATION );
1318 
1319  END_TEST;
1320 }
1321 
1322 
1324 {
1325  TestApplication application;
1326 
1327  tet_infoline("Test the uniform map precedence is applied properly");
1328 
1329  Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1330 
1331  Shader shader = Shader::New("VertexSource", "FragmentSource");
1332  Material material = Material::New( shader );
1333  material.AddTexture( image, "sTexture" );
1334 
1335  PropertyBuffer vertexBuffer = CreatePropertyBuffer();
1336  Geometry geometry = CreateQuadGeometryFromBuffer(vertexBuffer);
1337  Renderer renderer = Renderer::New( geometry, material );
1338 
1339  Actor actor = Actor::New();
1340  actor.AddRenderer(renderer);
1341  actor.SetSize(400, 400);
1342  Stage::GetCurrent().Add(actor);
1343  application.SendNotification();
1344  application.Render(0);
1345 
1346  // Don't add property / uniform map to renderer/actor/material
1347  shader.RegisterProperty( "uFadeColor", Color::MAGENTA );
1348 
1349  Property::Index geometryFadeColorIndex = geometry.RegisterProperty( "uFadeColor", Color::YELLOW );
1350 
1351  geometry.RegisterProperty( "uFadeColor", Color::BLACK );
1352 
1353 
1354  TestGlAbstraction& gl = application.GetGlAbstraction();
1355 
1356  application.SendNotification();
1357  application.Render(0);
1358 
1359  // Expect that the sampler's fade color property is accessed
1360  Vector4 actualValue(Vector4::ZERO);
1361  DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1363 
1364  // Animate geometry's fade color property. Should be no change to uniform
1365  Animation animation = Animation::New(1.0f);
1366  KeyFrames keyFrames = KeyFrames::New();
1367  keyFrames.Add(0.0f, Color::WHITE);
1368  keyFrames.Add(1.0f, Color::TRANSPARENT);
1369  animation.AnimateBetween( Property( geometry, geometryFadeColorIndex ), keyFrames );
1370  animation.Play();
1371 
1372  application.SendNotification();
1373  application.Render(500);
1374 
1375  DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1377 
1378  application.Render(500);
1379  DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1381 
1382  END_TEST;
1383 }
1384 
1386 {
1387  TestApplication application;
1388 
1389  tet_infoline("Test the uniform map precedence is applied properly");
1390 
1391  Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1392 
1393  Shader shader = Shader::New("VertexSource", "FragmentSource");
1394  Material material = Material::New( shader );
1395 
1396  PropertyBuffer vertexBuffer = CreatePropertyBuffer();
1397  Geometry geometry = CreateQuadGeometryFromBuffer(vertexBuffer);
1398  Renderer renderer = Renderer::New( geometry, material );
1399 
1400  Actor actor = Actor::New();
1401  actor.AddRenderer(renderer);
1402  actor.SetSize(400, 400);
1403  Stage::GetCurrent().Add(actor);
1404  application.SendNotification();
1405  application.Render(0);
1406 
1407  // Don't add property / uniform map to renderer/actor/material/sampler
1408 
1409  shader.RegisterProperty( "uFadeColor", Color::MAGENTA );
1410 
1411  Property::Index geometryFadeColorIndex = geometry.RegisterProperty( "uFadeColor", Color::YELLOW );
1412 
1413  geometry.RegisterProperty( "uFadeColor", Color::BLACK );
1414 
1415 
1416  TestGlAbstraction& gl = application.GetGlAbstraction();
1417 
1418  application.SendNotification();
1419  application.Render(0);
1420 
1421  // Expect that the shader's fade color property is accessed
1422  Vector4 actualValue(Vector4::ZERO);
1423  DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1425 
1426  // Animate geometry's fade color property. Should be no change to uniform
1427  Animation animation = Animation::New(1.0f);
1428  KeyFrames keyFrames = KeyFrames::New();
1429  keyFrames.Add(0.0f, Color::WHITE);
1430  keyFrames.Add(1.0f, Color::TRANSPARENT);
1431  animation.AnimateBetween( Property( geometry, geometryFadeColorIndex ), keyFrames );
1432  animation.Play();
1433 
1434  application.SendNotification();
1435  application.Render(500);
1436 
1437  DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1439 
1440  application.Render(500);
1441  DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1443 
1444  END_TEST;
1445 }
1446 
1448 {
1449  TestApplication application;
1450 
1451  tet_infoline("Test the uniform maps are collected from all objects (same type)");
1452 
1453  Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1454 
1455  Shader shader = Shader::New("VertexSource", "FragmentSource");
1456  Material material = Material::New( shader );
1457 
1458  PropertyBuffer vertexBuffer = CreatePropertyBuffer();
1459  Geometry geometry = CreateQuadGeometryFromBuffer(vertexBuffer);
1460  Renderer renderer = Renderer::New( geometry, material );
1461 
1462  Actor actor = Actor::New();
1463  actor.AddRenderer(renderer);
1464  actor.SetSize(400, 400);
1465  Stage::GetCurrent().Add(actor);
1466  application.SendNotification();
1467  application.Render(0);
1468 
1469  renderer.RegisterProperty( "uUniform1", Color::RED );
1470  actor.RegisterProperty( "uUniform2", Color::GREEN );
1471  material.RegisterProperty( "uUniform3", Color::BLUE );
1472  shader.RegisterProperty( "uUniform4", Color::MAGENTA );
1473  geometry.RegisterProperty( "uUniform5", Color::YELLOW );
1474 
1475  TestGlAbstraction& gl = application.GetGlAbstraction();
1476 
1477  application.SendNotification();
1478  application.Render(0);
1479 
1480  // Expect that each of the object's uniforms are set
1481  Vector4 uniform1Value(Vector4::ZERO);
1482  DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uUniform1", uniform1Value ) );
1483  DALI_TEST_EQUALS( uniform1Value, Color::RED, TEST_LOCATION );
1484 
1485  Vector4 uniform2Value(Vector4::ZERO);
1486  DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uUniform2", uniform2Value ) );
1487  DALI_TEST_EQUALS( uniform2Value, Color::GREEN, TEST_LOCATION );
1488 
1489  Vector4 uniform3Value(Vector4::ZERO);
1490  DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uUniform3", uniform3Value ) );
1491  DALI_TEST_EQUALS( uniform3Value, Color::BLUE, TEST_LOCATION );
1492 
1493  Vector4 uniform5Value(Vector4::ZERO);
1494  DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uUniform4", uniform5Value ) );
1495  DALI_TEST_EQUALS( uniform5Value, Color::MAGENTA, TEST_LOCATION );
1496 
1497  Vector4 uniform6Value(Vector4::ZERO);
1498  DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uUniform5", uniform6Value ) );
1499  DALI_TEST_EQUALS( uniform6Value, Color::YELLOW, TEST_LOCATION );
1500 
1501  END_TEST;
1502 }
1503 
1504 
1506 {
1507  TestApplication application;
1508 
1509  tet_infoline("Test the uniform maps are collected from all objects (different types)");
1510 
1511  Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1512 
1513  Shader shader = Shader::New("VertexSource", "FragmentSource");
1514  Material material = Material::New( shader );
1515 
1516  PropertyBuffer vertexBuffer = CreatePropertyBuffer();
1517  Geometry geometry = CreateQuadGeometryFromBuffer(vertexBuffer);
1518  Renderer renderer = Renderer::New( geometry, material );
1519 
1520  Actor actor = Actor::New();
1521  actor.AddRenderer(renderer);
1522  actor.SetSize(400, 400);
1523  Stage::GetCurrent().Add(actor);
1524  application.SendNotification();
1525  application.Render(0);
1526 
1528  renderer.RegisterProperty( "uFadeColor", value1 );
1529 
1530  Property::Value value2(1.0f);
1531  actor.RegisterProperty( "uFadeProgress", value2 );
1532 
1533  Property::Value value3(Vector3(0.5f, 0.5f, 1.0f));
1534  material.RegisterProperty( "uFadePosition", value3);
1535 
1537  shader.RegisterProperty( "uANormalMatrix", value5 );
1538 
1540  geometry.RegisterProperty( "uAWorldMatrix", value6 );
1541 
1542  TestGlAbstraction& gl = application.GetGlAbstraction();
1543 
1544  application.SendNotification();
1545  application.Render(0);
1546 
1547  // Expect that each of the object's uniforms are set
1548  Vector4 uniform1Value(Vector4::ZERO);
1549  DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", uniform1Value ) );
1550  DALI_TEST_EQUALS( uniform1Value, value1.Get<Vector4>(), TEST_LOCATION );
1551 
1552  float uniform2Value(0.0f);
1553  DALI_TEST_CHECK( gl.GetUniformValue<float>( "uFadeProgress", uniform2Value ) );
1554  DALI_TEST_EQUALS( uniform2Value, value2.Get<float>(), TEST_LOCATION );
1555 
1556  Vector3 uniform3Value(Vector3::ZERO);
1557  DALI_TEST_CHECK( gl.GetUniformValue<Vector3>( "uFadePosition", uniform3Value ) );
1558  DALI_TEST_EQUALS( uniform3Value, value3.Get<Vector3>(), TEST_LOCATION );
1559 
1560  Matrix3 uniform5Value;
1561  DALI_TEST_CHECK( gl.GetUniformValue<Matrix3>( "uANormalMatrix", uniform5Value ) );
1562  DALI_TEST_EQUALS( uniform5Value, value5.Get<Matrix3>(), TEST_LOCATION );
1563 
1564  Matrix uniform6Value;
1565  DALI_TEST_CHECK( gl.GetUniformValue<Matrix>( "uAWorldMatrix", uniform6Value ) );
1566  DALI_TEST_EQUALS( uniform6Value, value6.Get<Matrix>(), TEST_LOCATION );
1567 
1568  END_TEST;
1569 }
1570 
1571 
1573 {
1574  TestApplication application;
1575  tet_infoline("Test the rendering order in a 2D layer is correct");
1576 
1577  Shader shader = Shader::New("VertexSource", "FragmentSource");
1578  PropertyBuffer vertexBuffer = CreatePropertyBuffer();
1579  Geometry geometry = CreateQuadGeometryFromBuffer(vertexBuffer);
1580 
1581  Actor actor0 = Actor::New();
1584  actor0.SetPosition(0.0f,0.0f);
1585  Image image0 = BufferImage::New( 64, 64, Pixel::RGB888 );
1586  Material material0 = Material::New( shader );
1587  material0.AddTexture( image0, "sTexture0" );
1588  Renderer renderer0 = Renderer::New( geometry, material0 );
1589  actor0.AddRenderer(renderer0);
1590  actor0.SetSize(1, 1);
1591  Stage::GetCurrent().Add(actor0);
1592  application.SendNotification();
1593  application.Render(0);
1594 
1595  Actor actor1 = Actor::New();
1598  actor1.SetPosition(0.0f,0.0f);
1599  Image image1= BufferImage::New( 64, 64, Pixel::RGB888 );
1600  Material material1 = Material::New( shader );
1601  material1.AddTexture( image1, "sTexture1" );
1602  Renderer renderer1 = Renderer::New( geometry, material1 );
1603  actor1.AddRenderer(renderer1);
1604  actor1.SetSize(1, 1);
1605  Stage::GetCurrent().Add(actor1);
1606  application.SendNotification();
1607  application.Render(0);
1608 
1609  Actor actor2 = Actor::New();
1612  actor2.SetPosition(0.0f,0.0f);
1613  Image image2= BufferImage::New( 64, 64, Pixel::RGB888 );
1614  Material material2 = Material::New( shader );
1615  material2.AddTexture( image2, "sTexture2" );
1616  Renderer renderer2 = Renderer::New( geometry, material2 );
1617  actor2.AddRenderer(renderer2);
1618  actor2.SetSize(1, 1);
1619  Stage::GetCurrent().Add(actor2);
1620  application.SendNotification();
1621  application.Render(0);
1622 
1623  Actor actor3 = Actor::New();
1626  actor3.SetPosition(0.0f,0.0f);
1627  Image image3 = BufferImage::New( 64, 64, Pixel::RGB888 );
1628  Material material3 = Material::New( shader );
1629  material3.AddTexture( image3, "sTexture3" );
1630  Renderer renderer3 = Renderer::New( geometry, material3 );
1631  actor3.AddRenderer(renderer3);
1632  actor3.SetSize(1, 1);
1633  Stage::GetCurrent().Add(actor3);
1634  application.SendNotification();
1635  application.Render(0);
1636 
1637  /*
1638  * Create the following hierarchy:
1639  *
1640  * actor2
1641  * /
1642  * /
1643  * actor1
1644  * /
1645  * /
1646  * actor0
1647  * /
1648  * /
1649  * actor3
1650  *
1651  * Expected rendering order : actor2 - actor1 - actor0 - actor3
1652  */
1653  actor2.Add(actor1);
1654  actor1.Add(actor0);
1655  actor0.Add(actor3);
1656  application.SendNotification();
1657  application.Render(0);
1658 
1659  TestGlAbstraction& gl = application.GetGlAbstraction();
1660  gl.EnableTextureCallTrace(true);
1661  application.SendNotification();
1662  application.Render(0);
1663 
1664  int textureBindIndex[4];
1665  for( unsigned int i(0); i<4; ++i )
1666  {
1667  std::stringstream params;
1668  params << GL_TEXTURE_2D<<", "<<i+1;
1669  textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str() );
1670  }
1671 
1672  //Check that actor1 has been rendered after actor2
1673  DALI_TEST_GREATER( textureBindIndex[1], textureBindIndex[2], TEST_LOCATION );
1674 
1675  //Check that actor0 has been rendered after actor1
1676  DALI_TEST_GREATER( textureBindIndex[0], textureBindIndex[1], TEST_LOCATION );
1677 
1678  //Check that actor3 has been rendered after actor0
1679  DALI_TEST_GREATER( textureBindIndex[3], textureBindIndex[0], TEST_LOCATION );
1680 
1681  END_TEST;
1682 }
1683 
1685 {
1686  TestApplication application;
1687  tet_infoline("Test the rendering order in a 2D layer is correct using multiple renderers per actor");
1688 
1689  /*
1690  * Creates the following hierarchy:
1691  *
1692  * actor0------------------------>actor1
1693  * / | \ / | \
1694  * / | \ / | \
1695  * / | \ / | \
1696  * renderer0 renderer1 renderer2 renderer3 renderer4 renderer5
1697  *
1698  * renderer0 has depth index 2
1699  * renderer1 has depth index 0
1700  * renderer2 has depth index 1
1701  *
1702  * renderer3 has depth index 1
1703  * renderer4 has depth index 0
1704  * renderer5 has depth index -1
1705  *
1706  * Expected rendering order: renderer1 - renderer2 - renderer0 - renderer5 - renderer4 - renderer3
1707  */
1708 
1709  Shader shader = Shader::New("VertexSource", "FragmentSource");
1710  PropertyBuffer vertexBuffer = CreatePropertyBuffer();
1711  Geometry geometry = CreateQuadGeometryFromBuffer(vertexBuffer);
1712 
1713  Actor actor0 = Actor::New();
1716  actor0.SetPosition(0.0f,0.0f);
1717  actor0.SetSize(1, 1);
1718  Stage::GetCurrent().Add(actor0);
1719 
1720  Actor actor1 = Actor::New();
1723  actor1.SetPosition(0.0f,0.0f);
1724  actor1.SetSize(1, 1);
1725  actor0.Add(actor1);
1726 
1727  //Renderer0
1728  Image image0 = BufferImage::New( 64, 64, Pixel::RGB888 );
1729  Material material0 = Material::New( shader );
1730  material0.AddTexture( image0, "sTexture0" );
1731  Renderer renderer0 = Renderer::New( geometry, material0 );
1733  actor0.AddRenderer(renderer0);
1734  application.SendNotification();
1735  application.Render(0);
1736 
1737  //Renderer1
1738  Image image1= BufferImage::New( 64, 64, Pixel::RGB888 );
1739  Material material1 = Material::New( shader );
1740  material1.AddTexture( image1, "sTexture1" );
1741  Renderer renderer1 = Renderer::New( geometry, material1 );
1743  actor0.AddRenderer(renderer1);
1744  application.SendNotification();
1745  application.Render(0);
1746 
1747  //Renderer2
1748  Image image2= BufferImage::New( 64, 64, Pixel::RGB888 );
1749  Material material2 = Material::New( shader );
1750  material2.AddTexture( image2, "sTexture2" );
1751  Renderer renderer2 = Renderer::New( geometry, material2 );
1753  actor0.AddRenderer(renderer2);
1754  application.SendNotification();
1755  application.Render(0);
1756 
1757  //Renderer3
1758  Image image3 = BufferImage::New( 64, 64, Pixel::RGB888 );
1759  Material material3 = Material::New( shader );
1760  material3.AddTexture( image3, "sTexture3" );
1761  Renderer renderer3 = Renderer::New( geometry, material3 );
1763  actor1.AddRenderer(renderer3);
1764  application.SendNotification();
1765  application.Render(0);
1766 
1767  //Renderer4
1768  Image image4= BufferImage::New( 64, 64, Pixel::RGB888 );
1769  Material material4 = Material::New( shader );
1770  material4.AddTexture( image4, "sTexture4" );
1771  Renderer renderer4 = Renderer::New( geometry, material4 );
1773  actor1.AddRenderer(renderer4);
1774  application.SendNotification();
1775  application.Render(0);
1776 
1777  //Renderer5
1778  Image image5= BufferImage::New( 64, 64, Pixel::RGB888 );
1779  Material material5 = Material::New( shader );
1780  material5.AddTexture( image5, "sTexture5" );
1781  Renderer renderer5 = Renderer::New( geometry, material5 );
1783  actor1.AddRenderer(renderer5);
1784  application.SendNotification();
1785  application.Render(0);
1786 
1787 
1788  TestGlAbstraction& gl = application.GetGlAbstraction();
1789  gl.EnableTextureCallTrace(true);
1790  application.SendNotification();
1791  application.Render(0);
1792 
1793  int textureBindIndex[6];
1794  for( unsigned int i(0); i<6; ++i )
1795  {
1796  std::stringstream params;
1797  params << GL_TEXTURE_2D<<", "<<i+1;
1798  textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str() );
1799  }
1800 
1801  //Check that renderer3 has been rendered after renderer4
1802  DALI_TEST_GREATER( textureBindIndex[3], textureBindIndex[4], TEST_LOCATION );
1803 
1804  //Check that renderer0 has been rendered after renderer2
1805  DALI_TEST_GREATER( textureBindIndex[4], textureBindIndex[5], TEST_LOCATION );
1806 
1807  //Check that renderer0 has been rendered after renderer2
1808  DALI_TEST_GREATER( textureBindIndex[5], textureBindIndex[0], TEST_LOCATION );
1809 
1810  //Check that renderer0 has been rendered after renderer2
1811  DALI_TEST_GREATER( textureBindIndex[0], textureBindIndex[2], TEST_LOCATION );
1812 
1813  //Check that renderer2 has been rendered after renderer1
1814  DALI_TEST_GREATER( textureBindIndex[2], textureBindIndex[1], TEST_LOCATION );
1815 
1816  END_TEST;
1817 }
1818 
1820 {
1821  TestApplication application;
1822  tet_infoline("Test the rendering order in a 2D layer is correct for overlays");
1823 
1824  Shader shader = Shader::New("VertexSource", "FragmentSource");
1825  PropertyBuffer vertexBuffer = CreatePropertyBuffer();
1826  Geometry geometry = CreateQuadGeometryFromBuffer(vertexBuffer);
1827 
1828  Actor actor0 = Actor::New();
1831  Image image0 = BufferImage::New( 64, 64, Pixel::RGB888 );
1832  Material material0 = Material::New( shader );
1833  material0.AddTexture( image0, "sTexture0" );
1834  Renderer renderer0 = Renderer::New( geometry, material0 );
1835  actor0.AddRenderer(renderer0);
1836  actor0.SetPosition(0.0f,0.0f);
1837  actor0.SetSize(100, 100);
1838  Stage::GetCurrent().Add(actor0);
1840  application.SendNotification();
1841  application.Render(0);
1842 
1843  Actor actor1 = Actor::New();
1846  Image image1= BufferImage::New( 64, 64, Pixel::RGB888 );
1847  Material material1 = Material::New( shader );
1848  material1.AddTexture( image1, "sTexture1" );
1849  Renderer renderer1 = Renderer::New( geometry, material1 );
1850  actor1.SetPosition(0.0f,0.0f);
1851  actor1.AddRenderer(renderer1);
1852  actor1.SetSize(100, 100);
1853  Stage::GetCurrent().Add(actor1);
1855  application.SendNotification();
1856  application.Render(0);
1857 
1858  Actor actor2 = Actor::New();
1861  Image image2= BufferImage::New( 64, 64, Pixel::RGB888 );
1862  Material material2 = Material::New( shader );
1863  material2.AddTexture( image2, "sTexture2" );
1864  Renderer renderer2 = Renderer::New( geometry, material2 );
1865  actor2.AddRenderer(renderer2);
1866  actor2.SetPosition(0.0f,0.0f);
1867  actor2.SetSize(100, 100);
1868  Stage::GetCurrent().Add(actor2);
1869  application.SendNotification();
1870  application.Render(0);
1871 
1872  Actor actor3 = Actor::New();
1875  Image image3 = BufferImage::New( 64, 64, Pixel::RGB888 );
1876  Material material3 = Material::New( shader );
1877  material3.AddTexture( image3, "sTexture3" );
1878  Renderer renderer3 = Renderer::New( geometry, material3 );
1879  actor3.SetPosition(0.0f,0.0f);
1880  actor3.AddRenderer(renderer3);
1881  actor3.SetSize(100, 100);
1882  Stage::GetCurrent().Add(actor3);
1884  application.SendNotification();
1885  application.Render(0);
1886 
1887  Actor actor4 = Actor::New();
1890  Image image4 = BufferImage::New( 64, 64, Pixel::RGB888 );
1891  Material material4 = Material::New( shader );
1892  material4.AddTexture( image4, "sTexture4" );
1893  Renderer renderer4 = Renderer::New( geometry, material4 );
1894  actor4.AddRenderer(renderer4);
1895  actor4.SetPosition(0.0f,0.0f);
1896  actor4.SetSize(100, 100);
1897  Stage::GetCurrent().Add(actor4);
1898  application.SendNotification();
1899  application.Render(0);
1900 
1901  /*
1902  * Create the following hierarchy:
1903  *
1904  * actor2
1905  * (Regular actor)
1906  * / \
1907  * / \
1908  * actor1 actor4
1909  * (Overlay) (Regular actor)
1910  * /
1911  * /
1912  * actor0
1913  * (Overlay)
1914  * /
1915  * /
1916  * actor3
1917  * (Overlay)
1918  *
1919  * Expected rendering order : actor2 - actor4 - actor1 - actor0 - actor3
1920  */
1921  Stage::GetCurrent().Add( actor2 );
1922  actor2.Add(actor1);
1923  actor2.Add(actor4);
1924  actor1.Add(actor0);
1925  actor0.Add(actor3);
1926  application.SendNotification();
1927  application.Render(0);
1928 
1929  TestGlAbstraction& gl = application.GetGlAbstraction();
1930  gl.EnableTextureCallTrace(true);
1931  application.SendNotification();
1932  application.Render(0);
1933 
1934  int textureBindIndex[5];
1935  for( unsigned int i(0); i<5; ++i )
1936  {
1937  std::stringstream params;
1938  params << GL_TEXTURE_2D<<", "<<i+1;
1939  textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str() );
1940  }
1941 
1942  //Check that actor4 has been rendered after actor2
1943  DALI_TEST_GREATER( textureBindIndex[4], textureBindIndex[2], TEST_LOCATION );
1944 
1945  //Check that actor1 has been rendered after actor4
1946  DALI_TEST_GREATER( textureBindIndex[1], textureBindIndex[4], TEST_LOCATION );
1947 
1948  //Check that actor0 has been rendered after actor1
1949  DALI_TEST_GREATER( textureBindIndex[0], textureBindIndex[1], TEST_LOCATION );
1950 
1951  //Check that actor3 has been rendered after actor0
1952  DALI_TEST_GREATER( textureBindIndex[3], textureBindIndex[0], TEST_LOCATION );
1953 
1954  END_TEST;
1955 }
Dali Docs Home
Read more about Dali