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