Simplified actor depth traversal algorithms
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-Renderer.cpp
1 /*
2  * Copyright (c) 2017 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 // EXTERNAL INCLUDES
19 #include <dali/devel-api/actors/actor-devel.h>
20
21 #include <dali/public-api/dali-core.h>
22 #include <dali/devel-api/images/texture-set-image.h>
23 #include <cstdio>
24 #include <string>
25
26 // INTERNAL INCLUDES
27 #include <dali-test-suite-utils.h>
28 #include <test-trace-call-stack.h>
29 #include <mesh-builder.h>
30
31 using namespace Dali;
32
33 namespace // unnamed namespace
34 {
35
36 const BlendFactor::Type   DEFAULT_BLEND_FACTOR_SRC_RGB(    BlendFactor::SRC_ALPHA );
37 const BlendFactor::Type   DEFAULT_BLEND_FACTOR_DEST_RGB(   BlendFactor::ONE_MINUS_SRC_ALPHA );
38 const BlendFactor::Type   DEFAULT_BLEND_FACTOR_SRC_ALPHA(  BlendFactor::ONE );
39 const BlendFactor::Type   DEFAULT_BLEND_FACTOR_DEST_ALPHA( BlendFactor::ONE_MINUS_SRC_ALPHA );
40
41 const BlendEquation::Type DEFAULT_BLEND_EQUATION_RGB(      BlendEquation::ADD );
42 const BlendEquation::Type DEFAULT_BLEND_EQUATION_ALPHA(    BlendEquation::ADD );
43
44 /**
45  * @brief Get GL stencil test enumeration value as a string.
46  * @return The string representation of the value of GL_STENCIL_TEST
47  */
48 std::string GetStencilTestString(void)
49 {
50   std::stringstream stream;
51   stream << GL_STENCIL_TEST;
52   return stream.str();
53 }
54
55 /**
56  * @brief Get GL depth test enumeration value as a string.
57  * @return The string representation of the value of GL_DEPTH_TEST
58  */
59 std::string GetDepthTestString(void)
60 {
61   std::stringstream stream;
62   stream << GL_DEPTH_TEST;
63   return stream.str();
64 }
65
66 void ResetDebugAndFlush( TestApplication& application, TraceCallStack& glEnableDisableStack, TraceCallStack& glStencilFunctionStack )
67 {
68   glEnableDisableStack.Reset();
69   glStencilFunctionStack.Reset();
70   application.SendNotification();
71   application.Render();
72 }
73
74 void TestConstraintNoBlue( Vector4& current, const PropertyInputContainer& inputs )
75 {
76   current.b = 0.0f;
77 }
78
79 } // unnamed namespace
80
81 void renderer_test_startup(void)
82 {
83   test_return_value = TET_UNDEF;
84 }
85
86 void renderer_test_cleanup(void)
87 {
88   test_return_value = TET_PASS;
89 }
90
91
92 int UtcDaliRendererNew01(void)
93 {
94   TestApplication application;
95
96   Geometry geometry = CreateQuadGeometry();
97   Shader shader = CreateShader();
98   Renderer renderer = Renderer::New(geometry, shader);
99
100   DALI_TEST_EQUALS( (bool)renderer, true, TEST_LOCATION );
101   END_TEST;
102 }
103
104 int UtcDaliRendererNew02(void)
105 {
106   TestApplication application;
107   Renderer renderer;
108   DALI_TEST_EQUALS( (bool)renderer, false, TEST_LOCATION );
109   END_TEST;
110 }
111
112 int UtcDaliRendererCopyConstructor(void)
113 {
114   TestApplication application;
115
116   Geometry geometry = CreateQuadGeometry();
117   Shader shader = CreateShader();
118   Renderer renderer = Renderer::New(geometry, shader);
119
120   Renderer rendererCopy( renderer );
121   DALI_TEST_EQUALS( (bool)rendererCopy, true, TEST_LOCATION );
122
123   END_TEST;
124 }
125
126 int UtcDaliRendererAssignmentOperator(void)
127 {
128   TestApplication application;
129
130   Geometry geometry = CreateQuadGeometry();
131   Shader shader = CreateShader();
132   Renderer renderer = Renderer::New(geometry, shader);
133
134   Renderer renderer2;
135   DALI_TEST_EQUALS( (bool)renderer2, false, TEST_LOCATION );
136
137   renderer2 = renderer;
138   DALI_TEST_EQUALS( (bool)renderer2, true, TEST_LOCATION );
139   END_TEST;
140 }
141
142 int UtcDaliRendererDownCast01(void)
143 {
144   TestApplication application;
145
146   Geometry geometry = CreateQuadGeometry();
147   Shader shader = CreateShader();
148   Renderer renderer = Renderer::New(geometry, shader);
149
150   BaseHandle handle(renderer);
151   Renderer renderer2 = Renderer::DownCast(handle);
152   DALI_TEST_EQUALS( (bool)renderer2, true, TEST_LOCATION );
153   END_TEST;
154 }
155
156 int UtcDaliRendererDownCast02(void)
157 {
158   TestApplication application;
159
160   Handle handle = Handle::New(); // Create a custom object
161   Renderer renderer = Renderer::DownCast(handle);
162   DALI_TEST_EQUALS( (bool)renderer, false, TEST_LOCATION );
163   END_TEST;
164 }
165
166 int UtcDaliRendererSetGetGeometry(void)
167 {
168   TestApplication application;
169   tet_infoline( "Test SetGeometry, GetGeometry" );
170
171   Geometry geometry1 = CreateQuadGeometry();
172   Geometry geometry2 = CreateQuadGeometry();
173
174   Shader shader = CreateShader();
175   Renderer renderer = Renderer::New(geometry1, shader);
176   Actor actor = Actor::New();
177   actor.AddRenderer(renderer);
178   actor.SetSize(400, 400);
179   Stage::GetCurrent().Add(actor);
180
181   application.SendNotification();
182   application.Render(0);
183   DALI_TEST_EQUALS( renderer.GetGeometry(), geometry1, TEST_LOCATION );
184
185   // Set geometry2 to the renderer
186   renderer.SetGeometry( geometry2 );
187
188   application.SendNotification();
189   application.Render(0);
190   DALI_TEST_EQUALS( renderer.GetGeometry(), geometry2, TEST_LOCATION );
191
192   END_TEST;
193 }
194
195 int UtcDaliRendererSetGetShader(void)
196 {
197   TestApplication application;
198   tet_infoline( "Test SetShader, GetShader" );
199
200   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
201   glAbstraction.EnableCullFaceCallTrace(true);
202
203   Shader shader1 = CreateShader();
204   shader1.RegisterProperty( "uFadeColor", Color::RED );
205
206   Shader shader2 = CreateShader();
207   shader2.RegisterProperty( "uFadeColor", Color::GREEN );
208
209   Geometry geometry = CreateQuadGeometry();
210   Renderer renderer = Renderer::New(geometry, shader1);
211   Actor actor = Actor::New();
212   actor.AddRenderer(renderer);
213   actor.SetSize(400, 400);
214   Stage::GetCurrent().Add(actor);
215
216   TestGlAbstraction& gl = application.GetGlAbstraction();
217   application.SendNotification();
218   application.Render(0);
219
220   // Expect that the first shaders's fade color property is accessed
221   Vector4 actualValue(Vector4::ZERO);
222   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
223   DALI_TEST_EQUALS( actualValue, Color::RED, TEST_LOCATION );
224
225   DALI_TEST_EQUALS( renderer.GetShader(), shader1, TEST_LOCATION );
226
227   // set the second shader to the renderer
228   renderer.SetShader( shader2 );
229
230   application.SendNotification();
231   application.Render(0);
232
233   // Expect that the second shader's fade color property is accessed
234   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
235   DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
236
237   DALI_TEST_EQUALS( renderer.GetShader(), shader2, TEST_LOCATION );
238
239   END_TEST;
240 }
241
242 int UtcDaliRendererSetGetDepthIndex(void)
243 {
244   TestApplication application;
245
246   tet_infoline("Test SetDepthIndex, GetDepthIndex");
247
248   Shader shader = CreateShader();
249   Geometry geometry = CreateQuadGeometry();
250   Renderer renderer = Renderer::New(geometry, shader);
251   Actor actor = Actor::New();
252   actor.AddRenderer(renderer);
253   actor.SetSize(400, 400);
254   Stage::GetCurrent().Add(actor);
255
256   application.SendNotification();
257   application.Render(0);
258   DALI_TEST_EQUALS( renderer.GetProperty<int>(Renderer::Property::DEPTH_INDEX), 0, TEST_LOCATION );
259
260   renderer.SetProperty( Renderer::Property::DEPTH_INDEX, 1 );
261
262   application.SendNotification();
263   application.Render(0);
264   DALI_TEST_EQUALS( renderer.GetProperty<int>(Renderer::Property::DEPTH_INDEX), 1, TEST_LOCATION );
265
266   renderer.SetProperty( Renderer::Property::DEPTH_INDEX, 10 );
267
268   application.SendNotification();
269   application.Render(0);
270   DALI_TEST_EQUALS( renderer.GetProperty<int>(Renderer::Property::DEPTH_INDEX), 10, TEST_LOCATION );
271
272   END_TEST;
273 }
274
275 int UtcDaliRendererSetGetFaceCullingMode(void)
276 {
277   TestApplication application;
278
279   tet_infoline("Test SetFaceCullingMode(cullingMode)");
280   Geometry geometry = CreateQuadGeometry();
281   Shader shader = CreateShader();
282   Renderer renderer = Renderer::New( geometry, shader );
283
284   Actor actor = Actor::New();
285   actor.AddRenderer(renderer);
286   actor.SetSize(400, 400);
287   Stage::GetCurrent().Add(actor);
288
289   // By default, none of the faces should be culled
290   unsigned int cullFace = renderer.GetProperty<int>( Renderer::Property::FACE_CULLING_MODE );
291   DALI_TEST_CHECK( static_cast< FaceCullingMode::Type >( cullFace ) == FaceCullingMode::NONE );
292
293   TestGlAbstraction& gl = application.GetGlAbstraction();
294   TraceCallStack& cullFaceStack = gl.GetCullFaceTrace();
295   gl.EnableCullFaceCallTrace(true);
296
297   {
298     cullFaceStack.Reset();
299     renderer.SetProperty( Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::FRONT_AND_BACK );
300     application.SendNotification();
301     application.Render();
302
303     DALI_TEST_EQUALS( cullFaceStack.CountMethod( "CullFace" ), 1, TEST_LOCATION );
304
305     std::ostringstream cullModeString;
306     cullModeString << GL_FRONT_AND_BACK;
307
308     DALI_TEST_CHECK( cullFaceStack.FindMethodAndParams( "CullFace", cullModeString.str() ) );
309     cullFace = renderer.GetProperty<int>( Renderer::Property::FACE_CULLING_MODE );
310     DALI_TEST_CHECK( static_cast< FaceCullingMode::Type >( cullFace ) == FaceCullingMode::FRONT_AND_BACK );
311   }
312
313   {
314     cullFaceStack.Reset();
315     renderer.SetProperty( Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::BACK );
316     application.SendNotification();
317     application.Render();
318
319     DALI_TEST_EQUALS( cullFaceStack.CountMethod( "CullFace" ), 1, TEST_LOCATION );
320
321     std::ostringstream cullModeString;
322     cullModeString << GL_BACK;
323
324     DALI_TEST_CHECK( cullFaceStack.FindMethodAndParams( "CullFace", cullModeString.str() ) );
325     cullFace = renderer.GetProperty<int>( Renderer::Property::FACE_CULLING_MODE );
326     DALI_TEST_CHECK( static_cast< FaceCullingMode::Type >( cullFace ) == FaceCullingMode::BACK );
327   }
328
329   {
330     cullFaceStack.Reset();
331     renderer.SetProperty( Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::FRONT );
332     application.SendNotification();
333     application.Render();
334
335     DALI_TEST_EQUALS( cullFaceStack.CountMethod( "CullFace" ), 1, TEST_LOCATION );
336
337     std::ostringstream cullModeString;
338     cullModeString << GL_FRONT;
339
340     DALI_TEST_CHECK( cullFaceStack.FindMethodAndParams( "CullFace", cullModeString.str() ) );
341     cullFace = renderer.GetProperty<int>( Renderer::Property::FACE_CULLING_MODE );
342     DALI_TEST_CHECK( static_cast< FaceCullingMode::Type >( cullFace ) == FaceCullingMode::FRONT );
343   }
344
345   {
346     cullFaceStack.Reset();
347     renderer.SetProperty( Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::NONE );
348     application.SendNotification();
349     application.Render();
350
351     DALI_TEST_EQUALS( cullFaceStack.CountMethod( "CullFace" ), 0, TEST_LOCATION );
352     cullFace = renderer.GetProperty<int>( Renderer::Property::FACE_CULLING_MODE );
353     DALI_TEST_CHECK( static_cast< FaceCullingMode::Type >( cullFace ) == FaceCullingMode::NONE );
354   }
355
356   END_TEST;
357 }
358
359 int UtcDaliRendererBlendOptions01(void)
360 {
361   TestApplication application;
362
363   tet_infoline("Test BLEND_FACTOR properties ");
364
365   Geometry geometry = CreateQuadGeometry();
366   Shader shader = CreateShader();
367   Renderer renderer = Renderer::New( geometry, shader );
368
369   Actor actor = Actor::New();
370   // set a transparent actor color so that blending is enabled
371   actor.SetOpacity( 0.5f );
372   actor.AddRenderer(renderer);
373   actor.SetSize(400, 400);
374   Stage::GetCurrent().Add(actor);
375
376   renderer.SetProperty( Renderer::Property::BLEND_FACTOR_SRC_RGB,    BlendFactor::ONE_MINUS_SRC_COLOR );
377   renderer.SetProperty( Renderer::Property::BLEND_FACTOR_DEST_RGB,   BlendFactor::SRC_ALPHA_SATURATE  );
378   renderer.SetProperty( Renderer::Property::BLEND_FACTOR_SRC_ALPHA,  BlendFactor::ONE_MINUS_SRC_COLOR );
379   renderer.SetProperty( Renderer::Property::BLEND_FACTOR_DEST_ALPHA, BlendFactor::SRC_ALPHA_SATURATE  );
380
381   // Test that Set was successful:
382   int srcFactorRgb    = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
383   int destFactorRgb   = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
384   int srcFactorAlpha  = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
385   int destFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
386
387   DALI_TEST_EQUALS( (int)BlendFactor::ONE_MINUS_SRC_COLOR, srcFactorRgb,    TEST_LOCATION );
388   DALI_TEST_EQUALS( (int)BlendFactor::SRC_ALPHA_SATURATE,  destFactorRgb,   TEST_LOCATION );
389   DALI_TEST_EQUALS( (int)BlendFactor::ONE_MINUS_SRC_COLOR, srcFactorAlpha,  TEST_LOCATION );
390   DALI_TEST_EQUALS( (int)BlendFactor::SRC_ALPHA_SATURATE,  destFactorAlpha, TEST_LOCATION );
391
392   application.SendNotification();
393   application.Render();
394
395   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
396
397   DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_SRC_COLOR, glAbstraction.GetLastBlendFuncSrcRgb(),   TEST_LOCATION );
398   DALI_TEST_EQUALS( (GLenum)GL_SRC_ALPHA_SATURATE,  glAbstraction.GetLastBlendFuncDstRgb(),   TEST_LOCATION );
399   DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_SRC_COLOR, glAbstraction.GetLastBlendFuncSrcAlpha(), TEST_LOCATION );
400   DALI_TEST_EQUALS( (GLenum)GL_SRC_ALPHA_SATURATE,  glAbstraction.GetLastBlendFuncDstAlpha(), TEST_LOCATION );
401
402   END_TEST;
403 }
404
405 int UtcDaliRendererBlendOptions02(void)
406 {
407   TestApplication application;
408
409   tet_infoline("Test BLEND_FACTOR properties ");
410
411   Geometry geometry = CreateQuadGeometry();
412   Shader shader = CreateShader();
413   Renderer renderer = Renderer::New( geometry, shader );
414
415   Actor actor = Actor::New();
416   actor.SetOpacity( 0.5f ); // enable blending
417   actor.AddRenderer(renderer);
418   actor.SetSize(400, 400);
419   Stage::GetCurrent().Add(actor);
420
421   renderer.SetProperty( Renderer::Property::BLEND_FACTOR_SRC_RGB,    BlendFactor::CONSTANT_COLOR );
422   renderer.SetProperty( Renderer::Property::BLEND_FACTOR_DEST_RGB,   BlendFactor::ONE_MINUS_CONSTANT_COLOR );
423   renderer.SetProperty( Renderer::Property::BLEND_FACTOR_SRC_ALPHA,  BlendFactor::CONSTANT_ALPHA );
424   renderer.SetProperty( Renderer::Property::BLEND_FACTOR_DEST_ALPHA, BlendFactor::ONE_MINUS_CONSTANT_ALPHA  );
425
426   // Test that Set was successful:
427   {
428     int srcFactorRgb    = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
429     int destFactorRgb   = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
430     int srcFactorAlpha  = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
431     int destFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
432
433     DALI_TEST_EQUALS( (int)BlendFactor::CONSTANT_COLOR,            srcFactorRgb,    TEST_LOCATION );
434     DALI_TEST_EQUALS( (int)BlendFactor::ONE_MINUS_CONSTANT_COLOR,  destFactorRgb,   TEST_LOCATION );
435     DALI_TEST_EQUALS( (int)BlendFactor::CONSTANT_ALPHA,            srcFactorAlpha,  TEST_LOCATION );
436     DALI_TEST_EQUALS( (int)BlendFactor::ONE_MINUS_CONSTANT_ALPHA,  destFactorAlpha, TEST_LOCATION );
437   }
438
439   application.SendNotification();
440   application.Render();
441
442   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
443   DALI_TEST_EQUALS( (GLenum)GL_CONSTANT_COLOR,           glAbstraction.GetLastBlendFuncSrcRgb(),   TEST_LOCATION );
444   DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_CONSTANT_COLOR, glAbstraction.GetLastBlendFuncDstRgb(),   TEST_LOCATION );
445   DALI_TEST_EQUALS( (GLenum)GL_CONSTANT_ALPHA,           glAbstraction.GetLastBlendFuncSrcAlpha(), TEST_LOCATION );
446   DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_CONSTANT_ALPHA, glAbstraction.GetLastBlendFuncDstAlpha(), TEST_LOCATION );
447
448   END_TEST;
449 }
450
451 int UtcDaliRendererBlendOptions03(void)
452 {
453   TestApplication application;
454
455   tet_infoline("Test GetBlendEquation() defaults ");
456
457   Geometry geometry = CreateQuadGeometry();
458   Shader shader = CreateShader();
459   Renderer renderer = Renderer::New( geometry, shader );
460
461   Actor actor = Actor::New();
462   actor.AddRenderer(renderer);
463   actor.SetSize(400, 400);
464   Stage::GetCurrent().Add(actor);
465
466   // Test the defaults as documented in blending.h
467   int equationRgb   = renderer.GetProperty<int>( Renderer::Property::BLEND_EQUATION_RGB );
468   int equationAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_EQUATION_ALPHA );
469
470   DALI_TEST_EQUALS( (int)BlendEquation::ADD, equationRgb,   TEST_LOCATION );
471   DALI_TEST_EQUALS( (int)BlendEquation::ADD, equationAlpha, TEST_LOCATION );
472
473   END_TEST;
474 }
475
476 int UtcDaliRendererBlendOptions04(void)
477 {
478   TestApplication application;
479
480   tet_infoline("Test SetBlendEquation() ");
481
482   Geometry geometry = CreateQuadGeometry();
483   Shader shader = CreateShader();
484   Renderer renderer = Renderer::New( geometry, shader );
485
486   Actor actor = Actor::New();
487   actor.SetOpacity( 0.1f );
488   actor.AddRenderer(renderer);
489   actor.SetSize(400, 400);
490   Stage::GetCurrent().Add(actor);
491
492   // Test the single blending equation setting
493   {
494     renderer.SetProperty( Renderer::Property::BLEND_EQUATION_RGB, BlendEquation::REVERSE_SUBTRACT );
495     int equationRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_EQUATION_RGB );
496     DALI_TEST_EQUALS( (int)BlendEquation::REVERSE_SUBTRACT, equationRgb, TEST_LOCATION );
497   }
498
499   renderer.SetProperty( Renderer::Property::BLEND_EQUATION_RGB,   BlendEquation::REVERSE_SUBTRACT );
500   renderer.SetProperty( Renderer::Property::BLEND_EQUATION_ALPHA, BlendEquation::REVERSE_SUBTRACT );
501
502   // Test that Set was successful
503   {
504     int equationRgb   = renderer.GetProperty<int>( Renderer::Property::BLEND_EQUATION_RGB );
505     int equationAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_EQUATION_ALPHA );
506     DALI_TEST_EQUALS( (int)BlendEquation::REVERSE_SUBTRACT, equationRgb, TEST_LOCATION );
507     DALI_TEST_EQUALS( (int)BlendEquation::REVERSE_SUBTRACT, equationAlpha, TEST_LOCATION );
508   }
509
510   // Render & check GL commands
511   application.SendNotification();
512   application.Render();
513
514   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
515   DALI_TEST_EQUALS( (GLenum)GL_FUNC_REVERSE_SUBTRACT, glAbstraction.GetLastBlendEquationRgb(),   TEST_LOCATION );
516   DALI_TEST_EQUALS( (GLenum)GL_FUNC_REVERSE_SUBTRACT, glAbstraction.GetLastBlendEquationAlpha(), TEST_LOCATION );
517
518   END_TEST;
519 }
520
521 int UtcDaliRendererSetBlendMode01(void)
522 {
523   TestApplication application;
524
525   tet_infoline("Test setting the blend mode to on with an opaque color renders with blending enabled");
526
527   Geometry geometry = CreateQuadGeometry();
528   Shader shader = CreateShader();
529   Renderer renderer = Renderer::New( geometry, shader );
530
531   Actor actor = Actor::New();
532   actor.SetOpacity( 0.98f );
533   actor.AddRenderer(renderer);
534   actor.SetSize(400, 400);
535   Stage::GetCurrent().Add(actor);
536
537   renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::ON);
538
539   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
540   glAbstraction.EnableEnableDisableCallTrace(true);
541
542   application.SendNotification();
543   application.Render();
544
545   TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
546   std::ostringstream blendStr;
547   blendStr << GL_BLEND;
548   DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
549
550   END_TEST;
551 }
552
553 int UtcDaliRendererSetBlendMode02(void)
554 {
555   TestApplication application;
556
557   tet_infoline("Test setting the blend mode to off with a transparent color renders with blending disabled (and not enabled)");
558
559   Geometry geometry = CreateQuadGeometry();
560   Shader shader = CreateShader();
561   Renderer renderer = Renderer::New( geometry, shader );
562
563   Actor actor = Actor::New();
564   actor.SetOpacity( 0.15f );
565   actor.AddRenderer(renderer);
566   actor.SetSize(400, 400);
567   Stage::GetCurrent().Add(actor);
568
569   renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::OFF);
570
571   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
572   glAbstraction.EnableEnableDisableCallTrace(true);
573
574   application.SendNotification();
575   application.Render();
576
577   TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
578   std::ostringstream blendStr;
579   blendStr << GL_BLEND;
580   DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
581
582   END_TEST;
583 }
584
585 int UtcDaliRendererSetBlendMode03(void)
586 {
587   TestApplication application;
588
589   tet_infoline("Test setting the blend mode to auto with a transparent color renders with blending enabled");
590
591   Geometry geometry = CreateQuadGeometry();
592   Shader shader = CreateShader();
593   Renderer renderer = Renderer::New( geometry, shader );
594
595   Actor actor = Actor::New();
596   actor.SetOpacity( 0.75f );
597   actor.AddRenderer(renderer);
598   actor.SetSize(400, 400);
599   Stage::GetCurrent().Add(actor);
600
601   renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::AUTO);
602
603   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
604   glAbstraction.EnableEnableDisableCallTrace(true);
605
606   application.SendNotification();
607   application.Render();
608
609   TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
610   std::ostringstream blendStr;
611   blendStr << GL_BLEND;
612   DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
613
614   END_TEST;
615 }
616
617 int UtcDaliRendererSetBlendMode04(void)
618 {
619   TestApplication application;
620
621   tet_infoline("Test setting the blend mode to auto with an opaque color renders with blending disabled");
622
623   Geometry geometry = CreateQuadGeometry();
624   Shader shader = CreateShader();
625   Renderer renderer = Renderer::New( geometry, shader );
626
627   Actor actor = Actor::New();
628   actor.AddRenderer(renderer);
629   actor.SetSize(400, 400);
630   Stage::GetCurrent().Add(actor);
631
632   renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::AUTO);
633
634   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
635   glAbstraction.EnableEnableDisableCallTrace(true);
636
637   application.SendNotification();
638   application.Render();
639
640   TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
641   std::ostringstream blendStr;
642   blendStr << GL_BLEND;
643   DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
644
645   END_TEST;
646 }
647
648 int UtcDaliRendererSetBlendMode04b(void)
649 {
650   TestApplication application;
651
652   tet_infoline("Test setting the blend mode to auto with a transparent actor color renders with blending enabled");
653
654   Geometry geometry = CreateQuadGeometry();
655   Shader shader = CreateShader();
656   Renderer renderer = Renderer::New( geometry, shader );
657
658   Actor actor = Actor::New();
659   actor.AddRenderer(renderer);
660   actor.SetSize(400, 400);
661   actor.SetColor( Vector4(1.0f, 0.0f, 1.0f, 0.5f) );
662   Stage::GetCurrent().Add(actor);
663
664   renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::AUTO);
665
666   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
667   glAbstraction.EnableEnableDisableCallTrace(true);
668
669   application.SendNotification();
670   application.Render();
671
672   TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
673   std::ostringstream blendStr;
674   blendStr << GL_BLEND;
675   DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
676
677   END_TEST;
678 }
679
680 int UtcDaliRendererSetBlendMode04c(void)
681 {
682   TestApplication application;
683
684   tet_infoline("Test setting the blend mode to auto with an opaque opaque actor color renders with blending disabled");
685
686   Geometry geometry = CreateQuadGeometry();
687   Shader shader = CreateShader();
688   Renderer renderer = Renderer::New( geometry, shader );
689
690   Actor actor = Actor::New();
691   actor.AddRenderer(renderer);
692   actor.SetSize(400, 400);
693   actor.SetColor( Color::MAGENTA );
694   Stage::GetCurrent().Add(actor);
695
696   renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::AUTO);
697
698   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
699   glAbstraction.EnableEnableDisableCallTrace(true);
700
701   application.SendNotification();
702   application.Render();
703
704   TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
705   std::ostringstream blendStr;
706   blendStr << GL_BLEND;
707   DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
708
709   END_TEST;
710 }
711
712 int UtcDaliRendererSetBlendMode05(void)
713 {
714   TestApplication application;
715
716   tet_infoline("Test setting the blend mode to auto with an opaque color and an image with an alpha channel renders with blending enabled");
717
718   Geometry geometry = CreateQuadGeometry();
719   BufferImage image = BufferImage::New( 40, 40, Pixel::RGBA8888 );
720
721   Shader shader = CreateShader();
722   TextureSet textureSet = CreateTextureSet( image );
723   Renderer renderer = Renderer::New( geometry, shader );
724   renderer.SetTextures( textureSet );
725
726   Actor actor = Actor::New();
727   actor.AddRenderer(renderer);
728   actor.SetSize(400, 400);
729   Stage::GetCurrent().Add(actor);
730
731   renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::AUTO);
732
733   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
734   glAbstraction.EnableEnableDisableCallTrace(true);
735
736   application.SendNotification();
737   application.Render();
738
739   TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
740   std::ostringstream blendStr;
741   blendStr << GL_BLEND;
742   DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
743
744   END_TEST;
745 }
746
747 int UtcDaliRendererSetBlendMode06(void)
748 {
749   TestApplication application;
750   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");
751
752   Geometry geometry = CreateQuadGeometry();
753   Shader shader = Shader::New( "vertexSrc", "fragmentSrc", Shader::Hint::OUTPUT_IS_TRANSPARENT );
754
755   Renderer renderer = Renderer::New( geometry, shader );
756
757   Actor actor = Actor::New();
758   actor.AddRenderer(renderer);
759   actor.SetSize(400, 400);
760   Stage::GetCurrent().Add(actor);
761
762   renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::AUTO);
763
764   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
765   glAbstraction.EnableEnableDisableCallTrace(true);
766
767   application.SendNotification();
768   application.Render();
769
770   TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
771   std::ostringstream blendStr;
772   blendStr << GL_BLEND;
773   DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
774
775   END_TEST;
776 }
777
778 int UtcDaliRendererSetBlendMode07(void)
779 {
780   TestApplication application;
781   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");
782
783   Geometry geometry = CreateQuadGeometry();
784   Shader shader = Shader::New( "vertexSrc", "fragmentSrc" );
785
786   BufferImage image = BufferImage::New( 50, 50, Pixel::RGB888 );
787   TextureSet textureSet = CreateTextureSet( image );
788   Renderer renderer = Renderer::New( geometry, shader );
789   renderer.SetTextures( textureSet );
790
791   Actor actor = Actor::New();
792   actor.AddRenderer(renderer);
793   actor.SetSize(400, 400);
794   Stage::GetCurrent().Add(actor);
795
796   renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::AUTO);
797
798   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
799   glAbstraction.EnableEnableDisableCallTrace(true);
800
801   application.SendNotification();
802   application.Render();
803
804   TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
805   DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", "GL_BLEND" ) );
806
807   END_TEST;
808 }
809
810 int UtcDaliRendererGetBlendMode(void)
811 {
812   TestApplication application;
813
814   tet_infoline("Test GetBlendMode()");
815
816   Geometry geometry = CreateQuadGeometry();
817   Shader shader = Shader::New( "vertexSrc", "fragmentSrc" );
818   Renderer renderer = Renderer::New( geometry, shader );
819
820   // default value
821   unsigned int mode = renderer.GetProperty<int>( Renderer::Property::BLEND_MODE );
822   DALI_TEST_EQUALS( static_cast< BlendMode::Type >( mode ), BlendMode::AUTO, TEST_LOCATION );
823
824   // ON
825   renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::ON );
826   mode = renderer.GetProperty<int>( Renderer::Property::BLEND_MODE );
827   DALI_TEST_EQUALS( static_cast< BlendMode::Type >( mode ), BlendMode::ON, TEST_LOCATION );
828
829   // OFF
830   renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::OFF );
831   mode = renderer.GetProperty<int>( Renderer::Property::BLEND_MODE );
832   DALI_TEST_EQUALS( static_cast< BlendMode::Type >( mode ), BlendMode::OFF, TEST_LOCATION );
833
834   END_TEST;
835 }
836
837 int UtcDaliRendererSetBlendColor(void)
838 {
839   TestApplication application;
840
841   tet_infoline("Test SetBlendColor(color)");
842
843   Geometry geometry = CreateQuadGeometry();
844   Shader shader = Shader::New( "vertexSrc", "fragmentSrc" );
845   TextureSet textureSet = TextureSet::New();
846   BufferImage image = BufferImage::New( 50, 50, Pixel::RGBA8888 );
847   TextureSetImage( textureSet, 0u, image );
848   Renderer renderer = Renderer::New( geometry, shader );
849   renderer.SetTextures( textureSet );
850
851   Actor actor = Actor::New();
852   actor.AddRenderer(renderer);
853   actor.SetSize(400, 400);
854   Stage::GetCurrent().Add(actor);
855
856   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
857
858   renderer.SetProperty( Renderer::Property::BLEND_COLOR, Color::TRANSPARENT );
859   application.SendNotification();
860   application.Render();
861   DALI_TEST_EQUALS( glAbstraction.GetLastBlendColor(), Color::TRANSPARENT, TEST_LOCATION );
862
863   renderer.SetProperty( Renderer::Property::BLEND_COLOR, Color::MAGENTA );
864   application.SendNotification();
865   application.Render();
866   DALI_TEST_EQUALS( glAbstraction.GetLastBlendColor(), Color::MAGENTA, TEST_LOCATION );
867
868   Vector4 color( 0.1f, 0.2f, 0.3f, 0.4f );
869   renderer.SetProperty( Renderer::Property::BLEND_COLOR, color );
870   application.SendNotification();
871   application.Render();
872   DALI_TEST_EQUALS( glAbstraction.GetLastBlendColor(), color, TEST_LOCATION );
873
874   END_TEST;
875 }
876
877 int UtcDaliRendererGetBlendColor(void)
878 {
879   TestApplication application;
880
881   tet_infoline("Test GetBlendColor()");
882
883   Geometry geometry = CreateQuadGeometry();
884   Shader shader = Shader::New( "vertexSrc", "fragmentSrc" );
885   Renderer renderer = Renderer::New( geometry, shader );
886
887   DALI_TEST_EQUALS( renderer.GetProperty<Vector4>( Renderer::Property::BLEND_COLOR ), Color::TRANSPARENT, TEST_LOCATION );
888
889   renderer.SetProperty( Renderer::Property::BLEND_COLOR, Color::MAGENTA );
890   application.SendNotification();
891   application.Render();
892   DALI_TEST_EQUALS( renderer.GetProperty<Vector4>( Renderer::Property::BLEND_COLOR ), Color::MAGENTA, TEST_LOCATION );
893
894   Vector4 color( 0.1f, 0.2f, 0.3f, 0.4f );
895   renderer.SetProperty( Renderer::Property::BLEND_COLOR, color );
896   application.SendNotification();
897   application.Render();
898   DALI_TEST_EQUALS( renderer.GetProperty<Vector4>( Renderer::Property::BLEND_COLOR ), color, TEST_LOCATION );
899
900   END_TEST;
901 }
902
903 int UtcDaliRendererPreMultipledAlpha(void)
904 {
905   TestApplication application;
906
907   tet_infoline("Test BLEND_PRE_MULTIPLIED_ALPHA property");
908
909   Geometry geometry = CreateQuadGeometry();
910   Shader shader = Shader::New( "vertexSrc", "fragmentSrc" );
911   Renderer renderer = Renderer::New( geometry, shader );
912
913   Actor actor = Actor::New();
914   actor.AddRenderer(renderer);
915   actor.SetSize(400, 400);
916   actor.SetColor( Vector4(1.0f, 0.0f, 1.0f, 0.5f) );
917   Stage::GetCurrent().Add(actor);
918
919   Property::Value value = renderer.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
920   bool preMultipliedAlpha;
921   DALI_TEST_CHECK( value.Get( preMultipliedAlpha ) );
922   DALI_TEST_CHECK( !preMultipliedAlpha );
923
924   int srcFactorRgb    = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
925   int destFactorRgb   = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
926   int srcFactorAlpha  = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
927   int destFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
928
929   DALI_TEST_EQUALS( (int)DEFAULT_BLEND_FACTOR_SRC_RGB,    srcFactorRgb,    TEST_LOCATION );
930   DALI_TEST_EQUALS( (int)DEFAULT_BLEND_FACTOR_DEST_RGB,   destFactorRgb,   TEST_LOCATION );
931   DALI_TEST_EQUALS( (int)DEFAULT_BLEND_FACTOR_SRC_ALPHA,  srcFactorAlpha,  TEST_LOCATION );
932   DALI_TEST_EQUALS( (int)DEFAULT_BLEND_FACTOR_DEST_ALPHA, destFactorAlpha, TEST_LOCATION );
933
934   application.SendNotification();
935   application.Render();
936
937   Vector4 actualValue(Vector4::ZERO);
938   TestGlAbstraction& gl = application.GetGlAbstraction();
939   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uColor", actualValue ) );
940   DALI_TEST_EQUALS( actualValue, Vector4(1.0f, 0.0f, 1.0f, 0.5f), TEST_LOCATION );
941
942   renderer.SetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, true);
943
944   application.SendNotification();
945   application.Render();
946
947   value = renderer.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
948   DALI_TEST_CHECK( value.Get( preMultipliedAlpha ) );
949   DALI_TEST_CHECK( preMultipliedAlpha );
950
951   srcFactorRgb    = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
952   destFactorRgb   = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
953   srcFactorAlpha  = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
954   destFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
955
956   DALI_TEST_EQUALS( (int)BlendFactor::ONE,                 srcFactorRgb,    TEST_LOCATION );
957   DALI_TEST_EQUALS( (int)BlendFactor::ONE_MINUS_SRC_ALPHA, destFactorRgb,   TEST_LOCATION );
958   DALI_TEST_EQUALS( (int)BlendFactor::ONE,                 srcFactorAlpha,  TEST_LOCATION );
959   DALI_TEST_EQUALS( (int)BlendFactor::ONE,                 destFactorAlpha, TEST_LOCATION );
960
961   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uColor", actualValue ) );
962   DALI_TEST_EQUALS( actualValue, Vector4(0.5f, 0.0f, 0.5f, 0.5f), TEST_LOCATION );
963
964   END_TEST;
965 }
966
967 int UtcDaliRendererConstraint01(void)
968 {
969   TestApplication application;
970
971   tet_infoline("Test that a non-uniform renderer property can be constrained");
972
973   Shader shader = Shader::New("VertexSource", "FragmentSource");
974   Geometry geometry = CreateQuadGeometry();
975   Renderer renderer = Renderer::New( geometry, shader );
976
977   Actor actor = Actor::New();
978   actor.AddRenderer(renderer);
979   actor.SetSize(400, 400);
980   Stage::GetCurrent().Add(actor);
981
982   Vector4 initialColor = Color::WHITE;
983   Property::Index colorIndex = renderer.RegisterProperty( "uFadeColor", initialColor );
984
985   application.SendNotification();
986   application.Render(0);
987   DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION );
988
989   // Apply constraint
990   Constraint constraint = Constraint::New<Vector4>( renderer, colorIndex, TestConstraintNoBlue );
991   constraint.Apply();
992   application.SendNotification();
993   application.Render(0);
994
995   // Expect no blue component in either buffer - yellow
996   DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector4 >( colorIndex ), Color::YELLOW, TEST_LOCATION );
997   application.Render(0);
998   DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector4 >( colorIndex ), Color::YELLOW, TEST_LOCATION );
999
1000   renderer.RemoveConstraints();
1001   renderer.SetProperty(colorIndex, Color::WHITE );
1002   application.SendNotification();
1003   application.Render(0);
1004   DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector4 >( colorIndex ), Color::WHITE, TEST_LOCATION );
1005
1006   END_TEST;
1007 }
1008
1009 int UtcDaliRendererConstraint02(void)
1010 {
1011   TestApplication application;
1012
1013   tet_infoline("Test that a uniform map renderer property can be constrained");
1014
1015   Shader shader = Shader::New("VertexSource", "FragmentSource");
1016   Geometry geometry = CreateQuadGeometry();
1017   Renderer renderer = Renderer::New( geometry, shader );
1018
1019   Actor actor = Actor::New();
1020   actor.AddRenderer(renderer);
1021   actor.SetSize(400, 400);
1022   Stage::GetCurrent().Add(actor);
1023   application.SendNotification();
1024   application.Render(0);
1025
1026   Vector4 initialColor = Color::WHITE;
1027   Property::Index colorIndex = renderer.RegisterProperty( "uFadeColor", initialColor );
1028
1029   TestGlAbstraction& gl = application.GetGlAbstraction();
1030
1031   application.SendNotification();
1032   application.Render(0);
1033
1034   Vector4 actualValue(Vector4::ZERO);
1035   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1036   DALI_TEST_EQUALS( actualValue, initialColor, TEST_LOCATION );
1037
1038   // Apply constraint
1039   Constraint constraint = Constraint::New<Vector4>( renderer, colorIndex, TestConstraintNoBlue );
1040   constraint.Apply();
1041   application.SendNotification();
1042   application.Render(0);
1043
1044    // Expect no blue component in either buffer - yellow
1045   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1046   DALI_TEST_EQUALS( actualValue, Color::YELLOW, TEST_LOCATION );
1047
1048   application.Render(0);
1049   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1050   DALI_TEST_EQUALS( actualValue, Color::YELLOW, TEST_LOCATION );
1051
1052   renderer.RemoveConstraints();
1053   renderer.SetProperty(colorIndex, Color::WHITE );
1054   application.SendNotification();
1055   application.Render(0);
1056
1057   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1058   DALI_TEST_EQUALS( actualValue, Color::WHITE, TEST_LOCATION );
1059
1060   END_TEST;
1061 }
1062
1063 int UtcDaliRendererAnimatedProperty01(void)
1064 {
1065   TestApplication application;
1066
1067   tet_infoline("Test that a non-uniform renderer property can be animated");
1068
1069   Shader shader = Shader::New("VertexSource", "FragmentSource");
1070   Geometry geometry = CreateQuadGeometry();
1071   Renderer renderer = Renderer::New( geometry, shader );
1072
1073   Actor actor = Actor::New();
1074   actor.AddRenderer(renderer);
1075   actor.SetSize(400, 400);
1076   Stage::GetCurrent().Add(actor);
1077
1078   Vector4 initialColor = Color::WHITE;
1079   Property::Index colorIndex = renderer.RegisterProperty( "uFadeColor", initialColor );
1080
1081   application.SendNotification();
1082   application.Render(0);
1083   DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION );
1084
1085   Animation  animation = Animation::New(1.0f);
1086   KeyFrames keyFrames = KeyFrames::New();
1087   keyFrames.Add(0.0f, initialColor);
1088   keyFrames.Add(1.0f, Color::TRANSPARENT);
1089   animation.AnimateBetween( Property( renderer, colorIndex ), keyFrames );
1090   animation.Play();
1091
1092   application.SendNotification();
1093   application.Render(500);
1094
1095   DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector4 >( colorIndex ), Color::WHITE * 0.5f, TEST_LOCATION );
1096
1097   application.Render(500);
1098
1099   DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector4 >( colorIndex ), Color::TRANSPARENT, TEST_LOCATION );
1100
1101   END_TEST;
1102 }
1103
1104 int UtcDaliRendererAnimatedProperty02(void)
1105 {
1106   TestApplication application;
1107
1108   tet_infoline("Test that a uniform map renderer property can be animated");
1109
1110   Shader shader = Shader::New("VertexSource", "FragmentSource");
1111   Geometry geometry = CreateQuadGeometry();
1112   Renderer renderer = Renderer::New( geometry, shader );
1113
1114   Actor actor = Actor::New();
1115   actor.AddRenderer(renderer);
1116   actor.SetSize(400, 400);
1117   Stage::GetCurrent().Add(actor);
1118   application.SendNotification();
1119   application.Render(0);
1120
1121   Vector4 initialColor = Color::WHITE;
1122   Property::Index colorIndex = renderer.RegisterProperty( "uFadeColor", initialColor );
1123
1124   TestGlAbstraction& gl = application.GetGlAbstraction();
1125
1126   application.SendNotification();
1127   application.Render(0);
1128
1129   Vector4 actualValue(Vector4::ZERO);
1130   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1131   DALI_TEST_EQUALS( actualValue, initialColor, TEST_LOCATION );
1132
1133   Animation  animation = Animation::New(1.0f);
1134   KeyFrames keyFrames = KeyFrames::New();
1135   keyFrames.Add(0.0f, initialColor);
1136   keyFrames.Add(1.0f, Color::TRANSPARENT);
1137   animation.AnimateBetween( Property( renderer, colorIndex ), keyFrames );
1138   animation.Play();
1139
1140   application.SendNotification();
1141   application.Render(500);
1142
1143   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1144   DALI_TEST_EQUALS( actualValue, Color::WHITE * 0.5f, TEST_LOCATION );
1145
1146   application.Render(500);
1147   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1148   DALI_TEST_EQUALS( actualValue, Color::TRANSPARENT, TEST_LOCATION );
1149
1150   END_TEST;
1151 }
1152
1153 int UtcDaliRendererUniformMapPrecendence01(void)
1154 {
1155   TestApplication application;
1156
1157   tet_infoline("Test the uniform map precedence is applied properly");
1158
1159   Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1160
1161   Shader shader = Shader::New("VertexSource", "FragmentSource");
1162   TextureSet textureSet = CreateTextureSet( image );
1163
1164   Geometry geometry = CreateQuadGeometry();
1165   Renderer renderer = Renderer::New( geometry, shader );
1166   renderer.SetTextures( textureSet );
1167
1168   Actor actor = Actor::New();
1169   actor.AddRenderer(renderer);
1170   actor.SetSize(400, 400);
1171   Stage::GetCurrent().Add(actor);
1172   application.SendNotification();
1173   application.Render(0);
1174
1175   renderer.RegisterProperty( "uFadeColor", Color::RED );
1176   actor.RegisterProperty( "uFadeColor", Color::GREEN );
1177   Property::Index shaderFadeColorIndex = shader.RegisterProperty( "uFadeColor", Color::MAGENTA );
1178
1179   TestGlAbstraction& gl = application.GetGlAbstraction();
1180
1181   application.SendNotification();
1182   application.Render(0);
1183
1184   // Expect that the actor's fade color property is accessed
1185   Vector4 actualValue(Vector4::ZERO);
1186   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1187   DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
1188
1189   // Animate shader's fade color property. Should be no change to uniform
1190   Animation  animation = Animation::New(1.0f);
1191   KeyFrames keyFrames = KeyFrames::New();
1192   keyFrames.Add(0.0f, Color::WHITE);
1193   keyFrames.Add(1.0f, Color::TRANSPARENT);
1194   animation.AnimateBetween( Property( shader, shaderFadeColorIndex ), keyFrames );
1195   animation.Play();
1196
1197   application.SendNotification();
1198   application.Render(500);
1199
1200   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1201   DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
1202
1203   application.Render(500);
1204   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1205   DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
1206
1207   END_TEST;
1208 }
1209
1210 int UtcDaliRendererUniformMapPrecendence02(void)
1211 {
1212   TestApplication application;
1213
1214   tet_infoline("Test the uniform map precedence is applied properly");
1215
1216   Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1217
1218   Shader shader = Shader::New("VertexSource", "FragmentSource");
1219   TextureSet textureSet = CreateTextureSet( image );
1220
1221   Geometry geometry = CreateQuadGeometry();
1222   Renderer renderer = Renderer::New( geometry, shader );
1223   renderer.SetTextures( textureSet );
1224
1225   Actor actor = Actor::New();
1226   actor.AddRenderer(renderer);
1227   actor.SetSize(400, 400);
1228   Stage::GetCurrent().Add(actor);
1229   application.SendNotification();
1230   application.Render(0);
1231
1232   // Don't add property / uniform map to renderer
1233   actor.RegisterProperty( "uFadeColor", Color::GREEN );
1234   Property::Index shaderFadeColorIndex = shader.RegisterProperty( "uFadeColor", Color::BLUE );
1235
1236   TestGlAbstraction& gl = application.GetGlAbstraction();
1237
1238   application.SendNotification();
1239   application.Render(0);
1240
1241   // Expect that the actor's fade color property is accessed
1242   Vector4 actualValue(Vector4::ZERO);
1243   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1244   DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
1245
1246   // Animate texture set's fade color property. Should be no change to uniform
1247   Animation  animation = Animation::New(1.0f);
1248   KeyFrames keyFrames = KeyFrames::New();
1249   keyFrames.Add(0.0f, Color::WHITE);
1250   keyFrames.Add(1.0f, Color::TRANSPARENT);
1251   animation.AnimateBetween( Property( shader, shaderFadeColorIndex ), keyFrames );
1252   animation.Play();
1253
1254   application.SendNotification();
1255   application.Render(500);
1256
1257   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1258   DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
1259
1260   application.Render(500);
1261   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1262   DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
1263
1264   END_TEST;
1265 }
1266
1267
1268 int UtcDaliRendererUniformMapPrecendence03(void)
1269 {
1270   TestApplication application;
1271
1272   tet_infoline("Test the uniform map precedence is applied properly");
1273
1274   Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1275
1276   Shader shader = Shader::New("VertexSource", "FragmentSource");
1277   TextureSet textureSet = CreateTextureSet( image );
1278
1279   Geometry geometry = CreateQuadGeometry();
1280   Renderer renderer = Renderer::New( geometry, shader );
1281   renderer.SetTextures( textureSet );
1282
1283   Actor actor = Actor::New();
1284   actor.AddRenderer(renderer);
1285   actor.SetSize(400, 400);
1286   Stage::GetCurrent().Add(actor);
1287   application.SendNotification();
1288   application.Render(0);
1289
1290   // Don't add property / uniform map to renderer or actor
1291   shader.RegisterProperty( "uFadeColor", Color::BLACK );
1292
1293   TestGlAbstraction& gl = application.GetGlAbstraction();
1294
1295   application.SendNotification();
1296   application.Render(0);
1297
1298   // Expect that the shader's fade color property is accessed
1299   Vector4 actualValue(Vector4::ZERO);
1300   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1301   DALI_TEST_EQUALS( actualValue, Color::BLACK, TEST_LOCATION );
1302
1303   END_TEST;
1304 }
1305
1306 int UtcDaliRendererUniformMapMultipleUniforms01(void)
1307 {
1308   TestApplication application;
1309
1310   tet_infoline("Test the uniform maps are collected from all objects (same type)");
1311
1312   Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1313
1314   Shader shader = Shader::New("VertexSource", "FragmentSource");
1315   TextureSet textureSet = CreateTextureSet( image );
1316
1317   Geometry geometry = CreateQuadGeometry();
1318   Renderer renderer = Renderer::New( geometry, shader );
1319   renderer.SetTextures( textureSet );
1320
1321   Actor actor = Actor::New();
1322   actor.AddRenderer(renderer);
1323   actor.SetSize(400, 400);
1324   Stage::GetCurrent().Add(actor);
1325   application.SendNotification();
1326   application.Render(0);
1327
1328   renderer.RegisterProperty( "uUniform1", Color::RED );
1329   actor.RegisterProperty( "uUniform2", Color::GREEN );
1330   shader.RegisterProperty( "uUniform3", Color::MAGENTA );
1331
1332   TestGlAbstraction& gl = application.GetGlAbstraction();
1333
1334   application.SendNotification();
1335   application.Render(0);
1336
1337   // Expect that each of the object's uniforms are set
1338   Vector4 uniform1Value(Vector4::ZERO);
1339   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uUniform1", uniform1Value ) );
1340   DALI_TEST_EQUALS( uniform1Value, Color::RED, TEST_LOCATION );
1341
1342   Vector4 uniform2Value(Vector4::ZERO);
1343   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uUniform2", uniform2Value ) );
1344   DALI_TEST_EQUALS( uniform2Value, Color::GREEN, TEST_LOCATION );
1345
1346   Vector4 uniform3Value(Vector4::ZERO);
1347   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uUniform3", uniform3Value ) );
1348   DALI_TEST_EQUALS( uniform3Value, Color::MAGENTA, TEST_LOCATION );
1349
1350   END_TEST;
1351 }
1352
1353 int UtcDaliRendererUniformMapMultipleUniforms02(void)
1354 {
1355   TestApplication application;
1356
1357   tet_infoline("Test the uniform maps are collected from all objects (different types)");
1358
1359   Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1360
1361   Shader shader = Shader::New("VertexSource", "FragmentSource");
1362   TextureSet textureSet = CreateTextureSet( image );
1363
1364   Geometry geometry = CreateQuadGeometry();
1365   Renderer renderer = Renderer::New( geometry, shader );
1366   renderer.SetTextures( textureSet );
1367
1368   Actor actor = Actor::New();
1369   actor.AddRenderer(renderer);
1370   actor.SetSize(400, 400);
1371   Stage::GetCurrent().Add(actor);
1372   application.SendNotification();
1373   application.Render(0);
1374
1375   Property::Value value1(Color::RED);
1376   renderer.RegisterProperty( "uFadeColor", value1 );
1377
1378   Property::Value value2(1.0f);
1379   actor.RegisterProperty( "uFadeProgress", value2 );
1380
1381   Property::Value value3(Matrix3::IDENTITY);
1382   shader.RegisterProperty( "uANormalMatrix", value3 );
1383
1384   TestGlAbstraction& gl = application.GetGlAbstraction();
1385
1386   application.SendNotification();
1387   application.Render(0);
1388
1389   // Expect that each of the object's uniforms are set
1390   Vector4 uniform1Value(Vector4::ZERO);
1391   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", uniform1Value ) );
1392   DALI_TEST_EQUALS( uniform1Value, value1.Get<Vector4>(), TEST_LOCATION );
1393
1394   float uniform2Value(0.0f);
1395   DALI_TEST_CHECK( gl.GetUniformValue<float>( "uFadeProgress", uniform2Value ) );
1396   DALI_TEST_EQUALS( uniform2Value, value2.Get<float>(), TEST_LOCATION );
1397
1398   Matrix3 uniform3Value;
1399   DALI_TEST_CHECK( gl.GetUniformValue<Matrix3>( "uANormalMatrix", uniform3Value ) );
1400   DALI_TEST_EQUALS( uniform3Value, value3.Get<Matrix3>(), TEST_LOCATION );
1401
1402   END_TEST;
1403 }
1404
1405
1406 Renderer CreateRenderer( Actor actor, Geometry geometry, Shader shader, int depthIndex )
1407 {
1408   Image image0 = BufferImage::New( 64, 64, Pixel::RGB888 );
1409   TextureSet textureSet0 = CreateTextureSet( image0 );
1410   Renderer renderer0 = Renderer::New( geometry, shader );
1411   renderer0.SetTextures( textureSet0 );
1412   renderer0.SetProperty( Renderer::Property::DEPTH_INDEX, depthIndex );
1413   actor.AddRenderer(renderer0);
1414   return renderer0;
1415 }
1416
1417
1418 Actor CreateActor( Actor parent, int siblingOrder, const char* location )
1419 {
1420   Actor actor = Actor::New();
1421   actor.SetAnchorPoint(AnchorPoint::CENTER);
1422   actor.SetParentOrigin(AnchorPoint::CENTER);
1423   actor.SetPosition(0.0f,0.0f);
1424   actor.SetSize(100, 100);
1425   parent.Add(actor);
1426   actor.SetProperty( Dali::DevelActor::Property::SIBLING_ORDER, siblingOrder );
1427   DALI_TEST_EQUALS( actor.GetProperty<int>( Dali::DevelActor::Property::SIBLING_ORDER), siblingOrder, TEST_INNER_LOCATION(location) );
1428
1429   return actor;
1430 }
1431
1432 int UtcDaliRendererRenderOrder2DLayer(void)
1433 {
1434   TestApplication application;
1435   tet_infoline("Test the rendering order in a 2D layer is correct");
1436
1437   Shader shader = Shader::New("VertexSource", "FragmentSource");
1438   Geometry geometry = CreateQuadGeometry();
1439
1440   Actor root = Stage::GetCurrent().GetRootLayer();
1441
1442   Actor actor0 = CreateActor( root, 0, TEST_LOCATION );
1443   Renderer renderer0 = CreateRenderer( actor0, geometry, shader, 0 );
1444
1445   Actor actor1 = CreateActor( root, 0, TEST_LOCATION );
1446   Renderer renderer1 = CreateRenderer( actor1, geometry, shader, 0 );
1447
1448   Actor actor2 = CreateActor( root, 0, TEST_LOCATION );
1449   Renderer renderer2 = CreateRenderer( actor2, geometry, shader, 0 );
1450
1451   Actor actor3 = CreateActor( root, 0, TEST_LOCATION );
1452   Renderer renderer3 = CreateRenderer( actor3, geometry, shader, 0 );
1453
1454   application.SendNotification();
1455   application.Render(0);
1456
1457   /*
1458    * Create the following hierarchy:
1459    *
1460    *            actor2
1461    *              /
1462    *             /
1463    *          actor1
1464    *           /
1465    *          /
1466    *       actor0
1467    *        /
1468    *       /
1469    *    actor3
1470    *
1471    *  Expected rendering order : actor2 - actor1 - actor0 - actor3
1472    */
1473   actor2.Add(actor1);
1474   actor1.Add(actor0);
1475   actor0.Add(actor3);
1476   application.SendNotification();
1477   application.Render(0);
1478
1479   TestGlAbstraction& gl = application.GetGlAbstraction();
1480   gl.EnableTextureCallTrace(true);
1481   application.SendNotification();
1482   application.Render(0);
1483
1484   int textureBindIndex[4];
1485   for( unsigned int i(0); i<4; ++i )
1486   {
1487     std::stringstream params;
1488     params << GL_TEXTURE_2D<<", "<<i+1;
1489     textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str() );
1490   }
1491
1492   //Check that actor1 has been rendered after actor2
1493   DALI_TEST_GREATER( textureBindIndex[1], textureBindIndex[2], TEST_LOCATION );
1494
1495   //Check that actor0 has been rendered after actor1
1496   DALI_TEST_GREATER( textureBindIndex[0], textureBindIndex[1], TEST_LOCATION );
1497
1498   //Check that actor3 has been rendered after actor0
1499   DALI_TEST_GREATER( textureBindIndex[3], textureBindIndex[0], TEST_LOCATION );
1500
1501   END_TEST;
1502 }
1503
1504 int UtcDaliRendererRenderOrder2DLayerMultipleRenderers(void)
1505 {
1506   TestApplication application;
1507   tet_infoline("Test the rendering order in a 2D layer is correct using multiple renderers per actor");
1508
1509   /*
1510    * Creates the following hierarchy:
1511    *
1512    *             actor0------------------------>actor1
1513    *            /   |   \                    /   |   \
1514    *          /     |     \                /     |     \
1515    *        /       |       \            /       |       \
1516    * renderer0 renderer1 renderer2 renderer3 renderer4 renderer5
1517    *
1518    *  renderer0 has depth index 2
1519    *  renderer1 has depth index 0
1520    *  renderer2 has depth index 1
1521    *
1522    *  renderer3 has depth index 1
1523    *  renderer4 has depth index 0
1524    *  renderer5 has depth index -1
1525    *
1526    *  Expected rendering order: renderer1 - renderer2 - renderer0 - renderer5 - renderer4 - renderer3
1527    */
1528
1529   Shader shader = Shader::New("VertexSource", "FragmentSource");
1530   Geometry geometry = CreateQuadGeometry();
1531
1532   Actor root = Stage::GetCurrent().GetRootLayer();
1533
1534   Actor actor0 = CreateActor( root, 0, TEST_LOCATION );
1535   Actor actor1 = CreateActor( actor0, 0, TEST_LOCATION );
1536   Renderer renderer0 = CreateRenderer( actor0, geometry, shader, 2 );
1537   Renderer renderer1 = CreateRenderer( actor0, geometry, shader, 0 );
1538   Renderer renderer2 = CreateRenderer( actor0, geometry, shader, 1 );
1539   Renderer renderer3 = CreateRenderer( actor1, geometry, shader, 1 );
1540   Renderer renderer4 = CreateRenderer( actor1, geometry, shader, 0 );
1541   Renderer renderer5 = CreateRenderer( actor1, geometry, shader, -1 );
1542
1543   application.SendNotification();
1544   application.Render(0);
1545
1546   TestGlAbstraction& gl = application.GetGlAbstraction();
1547   gl.EnableTextureCallTrace(true);
1548   application.SendNotification();
1549   application.Render(0);
1550
1551   int textureBindIndex[6];
1552   for( unsigned int i(0); i<6; ++i )
1553   {
1554     std::stringstream params;
1555     params << GL_TEXTURE_2D<<", "<<i+1;
1556     textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str() );
1557   }
1558
1559   //Check that renderer3 has been rendered after renderer4
1560   DALI_TEST_GREATER( textureBindIndex[3], textureBindIndex[4], TEST_LOCATION );
1561
1562   //Check that renderer0 has been rendered after renderer2
1563   DALI_TEST_GREATER( textureBindIndex[4], textureBindIndex[5], TEST_LOCATION );
1564
1565   //Check that renderer5 has been rendered after renderer2
1566   DALI_TEST_GREATER( textureBindIndex[5], textureBindIndex[0], TEST_LOCATION );
1567
1568   //Check that renderer0 has been rendered after renderer2
1569   DALI_TEST_GREATER( textureBindIndex[0], textureBindIndex[2], TEST_LOCATION );
1570
1571   //Check that renderer2 has been rendered after renderer1
1572   DALI_TEST_GREATER( textureBindIndex[2], textureBindIndex[1], TEST_LOCATION );
1573
1574   END_TEST;
1575 }
1576
1577
1578 int UtcDaliRendererRenderOrder2DLayerSiblingOrder(void)
1579 {
1580   TestApplication application;
1581   tet_infoline("Test the rendering order in a 2D layer is correct using sibling order");
1582
1583   /*
1584    * Creates the following hierarchy:
1585    *
1586    *                            Layer
1587    *                           /    \
1588    *                         /        \
1589    *                       /            \
1590    *                     /                \
1591    *                   /                    \
1592    *             actor0 (SIBLING_ORDER:1)     actor1 (SIBLING_ORDER:0)
1593    *            /   |   \                    /   |   \
1594    *          /     |     \                /     |     \
1595    *        /       |       \            /       |       \
1596    * renderer0 renderer1  actor2     renderer2 renderer3 renderer4
1597    *    DI:2      DI:0      |           DI:0      DI:1      DI:2
1598    *                        |
1599    *                   renderer5
1600    *                      DI:-1
1601    *
1602    *  actor0 has sibling order 1
1603    *  actor1 has sibling order 0
1604    *  actor2 has sibling order 0
1605    *
1606    *  renderer0 has depth index 2
1607    *  renderer1 has depth index 0
1608    *
1609    *  renderer2 has depth index 0
1610    *  renderer3 has depth index 1
1611    *  renderer4 has depth index 2
1612    *
1613    *  renderer5 has depth index -1
1614    *
1615    *  Expected rendering order: renderer2 - renderer3 - renderer4 - renderer1 - renderer0 - renderer5
1616    */
1617
1618   Shader shader = Shader::New("VertexSource", "FragmentSource");
1619   Geometry geometry = CreateQuadGeometry();
1620   Actor root = Stage::GetCurrent().GetRootLayer();
1621   Actor actor0 = CreateActor( root,   1, TEST_LOCATION );
1622   Actor actor1 = CreateActor( root,   0, TEST_LOCATION );
1623   Actor actor2 = CreateActor( actor0, 0, TEST_LOCATION );
1624
1625   Renderer renderer0 = CreateRenderer( actor0, geometry, shader, 2 );
1626   Renderer renderer1 = CreateRenderer( actor0, geometry, shader, 0 );
1627   Renderer renderer2 = CreateRenderer( actor1, geometry, shader, 0 );
1628   Renderer renderer3 = CreateRenderer( actor1, geometry, shader, 1 );
1629   Renderer renderer4 = CreateRenderer( actor1, geometry, shader, 2 );
1630   Renderer renderer5 = CreateRenderer( actor2, geometry, shader, -1 );
1631
1632   application.SendNotification();
1633   application.Render();
1634
1635   TestGlAbstraction& gl = application.GetGlAbstraction();
1636   gl.EnableTextureCallTrace(true);
1637   application.SendNotification();
1638   application.Render(0);
1639
1640   int textureBindIndex[6];
1641   for( unsigned int i(0); i<6; ++i )
1642   {
1643     std::stringstream params;
1644     params << GL_TEXTURE_2D<<", "<<i+1;
1645     textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str() );
1646   }
1647
1648   DALI_TEST_EQUALS( textureBindIndex[2], 0, TEST_LOCATION );
1649   DALI_TEST_EQUALS( textureBindIndex[3], 1, TEST_LOCATION );
1650   DALI_TEST_EQUALS( textureBindIndex[4], 2, TEST_LOCATION );
1651   DALI_TEST_EQUALS( textureBindIndex[1], 3, TEST_LOCATION );
1652   DALI_TEST_EQUALS( textureBindIndex[0], 4, TEST_LOCATION );
1653   DALI_TEST_EQUALS( textureBindIndex[5], 5, TEST_LOCATION );
1654
1655   // Change sibling order of actor1
1656   // New Expected rendering order: renderer1 - renderer0 - renderer 5 - renderer2 - renderer3 - renderer4
1657   actor1.SetProperty( Dali::DevelActor::Property::SIBLING_ORDER, 2 );
1658
1659   gl.GetTextureTrace().Reset();
1660   application.SendNotification();
1661   application.Render(0);
1662
1663   for( unsigned int i(0); i<6; ++i )
1664   {
1665     std::stringstream params;
1666     params << GL_TEXTURE_2D<<", "<<i+1;
1667     textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str() );
1668   }
1669
1670   DALI_TEST_EQUALS( textureBindIndex[1], 0, TEST_LOCATION );
1671   DALI_TEST_EQUALS( textureBindIndex[0], 1, TEST_LOCATION );
1672   DALI_TEST_EQUALS( textureBindIndex[5], 2, TEST_LOCATION );
1673   DALI_TEST_EQUALS( textureBindIndex[2], 3, TEST_LOCATION );
1674   DALI_TEST_EQUALS( textureBindIndex[3], 4, TEST_LOCATION );
1675   DALI_TEST_EQUALS( textureBindIndex[4], 5, TEST_LOCATION );
1676
1677   END_TEST;
1678 }
1679
1680 int UtcDaliRendererRenderOrder2DLayerOverlay(void)
1681 {
1682   TestApplication application;
1683   tet_infoline("Test the rendering order in a 2D layer is correct for overlays");
1684
1685   Shader shader = Shader::New("VertexSource", "FragmentSource");
1686   Geometry geometry = CreateQuadGeometry();
1687   Actor root = Stage::GetCurrent().GetRootLayer();
1688
1689   /*
1690    * Create the following hierarchy:
1691    *
1692    *               actor2
1693    *             (Regular actor)
1694    *              /      \
1695    *             /        \
1696    *         actor1       actor4
1697    *       (Overlay)     (Regular actor)
1698    *          /
1699    *         /
1700    *     actor0
1701    *    (Overlay)
1702    *      /
1703    *     /
1704    *  actor3
1705    * (Overlay)
1706    *
1707    *  Expected rendering order : actor2 - actor4 - actor1 - actor0 - actor3
1708    */
1709
1710   Actor actor0 = CreateActor( root, 0, TEST_LOCATION );
1711   actor0.SetDrawMode( DrawMode::OVERLAY_2D );
1712   Renderer renderer0 = CreateRenderer( actor0, geometry, shader, 0 );
1713
1714   Actor actor1 = CreateActor( root, 0, TEST_LOCATION );
1715   actor1.SetDrawMode( DrawMode::OVERLAY_2D );
1716   Renderer renderer1 = CreateRenderer( actor1, geometry, shader, 0 );
1717
1718   Actor actor2 = CreateActor( root, 0, TEST_LOCATION );
1719   Renderer renderer2 = CreateRenderer( actor2, geometry, shader, 0 );
1720
1721   Actor actor3 = CreateActor( root, 0, TEST_LOCATION );
1722   actor3.SetDrawMode( DrawMode::OVERLAY_2D );
1723   Renderer renderer3 = CreateRenderer( actor3, geometry, shader, 0 );
1724
1725   Actor actor4 = CreateActor( root, 0, TEST_LOCATION );
1726   Renderer renderer4 = CreateRenderer( actor4, geometry, shader, 0 );
1727
1728   application.SendNotification();
1729   application.Render(0);
1730
1731   actor2.Add(actor1);
1732   actor2.Add(actor4);
1733   actor1.Add(actor0);
1734   actor0.Add(actor3);
1735
1736   TestGlAbstraction& gl = application.GetGlAbstraction();
1737   gl.EnableTextureCallTrace(true);
1738   application.SendNotification();
1739   application.Render(0);
1740
1741   int textureBindIndex[5];
1742   for( unsigned int i(0); i<5; ++i )
1743   {
1744     std::stringstream params;
1745     params << GL_TEXTURE_2D<<", "<<i+1;
1746     textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str() );
1747   }
1748
1749   //Check that actor4 has been rendered after actor2
1750   DALI_TEST_GREATER( textureBindIndex[4], textureBindIndex[2], TEST_LOCATION );
1751
1752   //Check that actor1 has been rendered after actor4
1753   DALI_TEST_GREATER( textureBindIndex[1], textureBindIndex[4], TEST_LOCATION );
1754
1755   //Check that actor0 has been rendered after actor1
1756   DALI_TEST_GREATER( textureBindIndex[0], textureBindIndex[1], TEST_LOCATION );
1757
1758   //Check that actor3 has been rendered after actor0
1759   DALI_TEST_GREATER( textureBindIndex[3], textureBindIndex[0], TEST_LOCATION );
1760
1761   END_TEST;
1762 }
1763
1764 int UtcDaliRendererSetIndexRange(void)
1765 {
1766   std::string
1767       vertexShader(
1768         "attribute vec2 aPosition;\n"
1769         "void main()\n"
1770         "{\n"
1771         "  gl_Position = aPosition;\n"
1772         "}"
1773         ),
1774       fragmentShader(
1775         "void main()\n"
1776         "{\n"
1777         "  gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0)\n"
1778         "}\n"
1779         );
1780
1781   TestApplication application;
1782   tet_infoline("Test setting the range of indices to draw");
1783
1784   TestGlAbstraction& gl = application.GetGlAbstraction();
1785   gl.EnableDrawCallTrace( true );
1786
1787   Actor actor = Actor::New();
1788   actor.SetSize( 100, 100 );
1789
1790   // create geometry
1791   Geometry geometry = Geometry::New();
1792   geometry.SetType( Geometry::LINE_LOOP );
1793
1794   // --------------------------------------------------------------------------
1795   // index buffer
1796   unsigned short indices[] = { 0, 2, 4, 6, 8, // offset = 0, count = 5
1797                          0, 1, 2, 3, 4, 5, 6, 7, 8, 9, // offset = 5, count = 10
1798                          1, 3, 5, 7, 9, 1 }; // offset = 15,  count = 6 // line strip
1799
1800   // --------------------------------------------------------------------------
1801   // vertex buffer
1802   struct Vertex
1803   {
1804     Vector2 position;
1805   };
1806   Vertex shapes[] =
1807   {
1808     // pentagon                   // star
1809     { Vector2(  0.0f,   1.00f) }, { Vector2(  0.0f,  -1.00f) },
1810     { Vector2( -0.95f,  0.31f) }, { Vector2(  0.59f,  0.81f) },
1811     { Vector2( -0.59f, -0.81f) }, { Vector2( -0.95f, -0.31f) },
1812     { Vector2(  0.59f, -0.81f) }, { Vector2(  0.95f, -0.31f) },
1813     { Vector2(  0.95f,  0.31f) }, { Vector2( -0.59f,  0.81f) },
1814   };
1815   Property::Map vertexFormat;
1816   vertexFormat["aPosition"] = Property::VECTOR2;
1817   PropertyBuffer vertexBuffer = PropertyBuffer::New( vertexFormat );
1818   vertexBuffer.SetData( shapes, sizeof(shapes)/sizeof(shapes[0]));
1819
1820   // --------------------------------------------------------------------------
1821   geometry.SetIndexBuffer( indices, sizeof(indices)/sizeof(indices[0]) );
1822   geometry.AddVertexBuffer( vertexBuffer );
1823
1824   // create shader
1825   Shader shader = Shader::New( vertexShader,fragmentShader );
1826   Renderer renderer = Renderer::New( geometry, shader );
1827   actor.AddRenderer( renderer );
1828
1829   Stage stage = Stage::GetCurrent();
1830   stage.Add( actor );
1831
1832   char buffer[ 128 ];
1833
1834   // LINE_LOOP, first 0, count 5
1835   {
1836     renderer.SetIndexRange( 0, 5 );
1837     application.SendNotification();
1838     application.Render();
1839     sprintf( buffer, "%u, 5, %u, indices", GL_LINE_LOOP, GL_UNSIGNED_SHORT );
1840     bool result = gl.GetDrawTrace().FindMethodAndParams( "DrawElements" , buffer );
1841     DALI_TEST_CHECK( result );
1842   }
1843
1844   // LINE_LOOP, first 5, count 10
1845   {
1846     renderer.SetIndexRange( 5, 10 );
1847     sprintf( buffer, "%u, 10, %u, indices", GL_LINE_LOOP, GL_UNSIGNED_SHORT );
1848     application.SendNotification();
1849     application.Render();
1850     bool result = gl.GetDrawTrace().FindMethodAndParams( "DrawElements" , buffer );
1851     DALI_TEST_CHECK( result );
1852   }
1853
1854   // LINE_STRIP, first 15, count 6
1855   {
1856     renderer.SetIndexRange( 15, 6 );
1857     geometry.SetType( Geometry::LINE_STRIP );
1858     sprintf( buffer, "%u, 6, %u, indices", GL_LINE_STRIP, GL_UNSIGNED_SHORT );
1859     application.SendNotification();
1860     application.Render();
1861     bool result = gl.GetDrawTrace().FindMethodAndParams( "DrawElements" , buffer );
1862     DALI_TEST_CHECK( result );
1863   }
1864
1865   // Index out of bounds
1866   {
1867     renderer.SetIndexRange( 15, 30 );
1868     geometry.SetType( Geometry::LINE_STRIP );
1869     sprintf( buffer, "%u, 6, %u, indices", GL_LINE_STRIP, GL_UNSIGNED_SHORT );
1870     application.SendNotification();
1871     application.Render();
1872     bool result = gl.GetDrawTrace().FindMethodAndParams( "DrawElements" , buffer );
1873     DALI_TEST_CHECK( result );
1874   }
1875
1876   // drawing whole buffer starting from 15 ( last valid primitive )
1877   {
1878     renderer.SetIndexRange( 15, 0 );
1879     geometry.SetType( Geometry::LINE_STRIP );
1880     sprintf( buffer, "%u, 6, %u, indices", GL_LINE_STRIP, GL_UNSIGNED_SHORT );
1881     application.SendNotification();
1882     application.Render();
1883     bool result = gl.GetDrawTrace().FindMethodAndParams( "DrawElements" , buffer );
1884     DALI_TEST_CHECK( result );
1885   }
1886
1887   END_TEST;
1888 }
1889
1890
1891 int UtcDaliRendererSetDepthFunction(void)
1892 {
1893   TestApplication application;
1894
1895   tet_infoline("Test setting the depth function");
1896
1897   Geometry geometry = CreateQuadGeometry();
1898   Shader shader = CreateShader();
1899   Renderer renderer = Renderer::New( geometry, shader );
1900
1901   Actor actor = Actor::New();
1902   actor.AddRenderer(renderer);
1903   actor.SetSize(400, 400);
1904   Stage stage = Stage::GetCurrent();
1905   stage.GetRootLayer().SetBehavior( Layer::LAYER_3D );
1906   stage.Add(actor);
1907
1908   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1909   glAbstraction.EnableEnableDisableCallTrace(true);
1910   glAbstraction.EnableDepthFunctionCallTrace(true);
1911
1912   TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
1913   TraceCallStack& glDepthFunctionStack = glAbstraction.GetDepthFunctionTrace();
1914
1915   std::ostringstream depthTestStr;
1916   depthTestStr << GL_DEPTH_TEST;
1917
1918   //GL_NEVER
1919   {
1920     renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::NEVER);
1921
1922     glEnableDisableStack.Reset();
1923     glDepthFunctionStack.Reset();
1924     application.SendNotification();
1925     application.Render();
1926
1927     DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Enable", depthTestStr.str().c_str() ) );
1928     std::ostringstream depthFunctionStr;
1929     depthFunctionStr << GL_NEVER;
1930     DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
1931   }
1932
1933   //GL_ALWAYS
1934   {
1935     renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::ALWAYS);
1936
1937     glDepthFunctionStack.Reset();
1938     application.SendNotification();
1939     application.Render();
1940
1941     std::ostringstream depthFunctionStr;
1942     depthFunctionStr << GL_ALWAYS;
1943     DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
1944   }
1945
1946   //GL_LESS
1947   {
1948     renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::LESS);
1949
1950     glDepthFunctionStack.Reset();
1951     application.SendNotification();
1952     application.Render();
1953
1954     std::ostringstream depthFunctionStr;
1955     depthFunctionStr << GL_LESS;
1956     DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
1957   }
1958
1959   //GL_GREATER
1960   {
1961     renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::GREATER);
1962
1963     glDepthFunctionStack.Reset();
1964     application.SendNotification();
1965     application.Render();
1966
1967     std::ostringstream depthFunctionStr;
1968     depthFunctionStr << GL_GREATER;
1969     DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
1970   }
1971
1972   //GL_EQUAL
1973   {
1974     renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::EQUAL);
1975
1976     glDepthFunctionStack.Reset();
1977     application.SendNotification();
1978     application.Render();
1979
1980     std::ostringstream depthFunctionStr;
1981     depthFunctionStr << GL_EQUAL;
1982     DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
1983   }
1984
1985   //GL_NOTEQUAL
1986   {
1987     renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::NOT_EQUAL);
1988
1989     glDepthFunctionStack.Reset();
1990     application.SendNotification();
1991     application.Render();
1992
1993     std::ostringstream depthFunctionStr;
1994     depthFunctionStr << GL_NOTEQUAL;
1995     DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
1996   }
1997
1998   //GL_LEQUAL
1999   {
2000     renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::LESS_EQUAL);
2001
2002     glDepthFunctionStack.Reset();
2003     application.SendNotification();
2004     application.Render();
2005
2006     std::ostringstream depthFunctionStr;
2007     depthFunctionStr << GL_LEQUAL;
2008     DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
2009   }
2010
2011   //GL_GEQUAL
2012   {
2013     renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::GREATER_EQUAL);
2014
2015     glDepthFunctionStack.Reset();
2016     application.SendNotification();
2017     application.Render();
2018
2019     std::ostringstream depthFunctionStr;
2020     depthFunctionStr << GL_GEQUAL;
2021     DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
2022   }
2023
2024   END_TEST;
2025 }
2026
2027 /**
2028  * @brief This templatized function checks an enumeration property is setting and getting correctly.
2029  * The checks performed are as follows:
2030  *  - Check the initial/default value.
2031  *  - Set a different value via enum.
2032  *  - Check it was set.
2033  *  - Set a different value via string.
2034  *  - Check it was set.
2035  */
2036 template< typename T >
2037 void CheckEnumerationProperty( Renderer& renderer, Property::Index propertyIndex, T initialValue, T firstCheckEnumeration, T secondCheckEnumeration, std::string secondCheckString )
2038 {
2039   DALI_TEST_CHECK( renderer.GetProperty<int>( propertyIndex ) == static_cast<int>( initialValue ) );
2040   DALI_TEST_CHECK( renderer.GetCurrentProperty< int >( propertyIndex ) == static_cast<int>( initialValue ) );
2041   renderer.SetProperty( propertyIndex, firstCheckEnumeration );
2042   DALI_TEST_CHECK( renderer.GetProperty<int>( propertyIndex ) == static_cast<int>( firstCheckEnumeration ) );
2043   DALI_TEST_CHECK( renderer.GetCurrentProperty< int >( propertyIndex ) == static_cast<int>( firstCheckEnumeration ) );
2044   renderer.SetProperty( propertyIndex, secondCheckString );
2045   DALI_TEST_CHECK( renderer.GetProperty<int>( propertyIndex ) == static_cast<int>( secondCheckEnumeration ) );
2046   DALI_TEST_CHECK( renderer.GetCurrentProperty< int >( propertyIndex ) == static_cast<int>( secondCheckEnumeration ) );
2047 }
2048
2049 int UtcDaliRendererEnumProperties(void)
2050 {
2051   TestApplication application;
2052   tet_infoline( "Test Renderer enumeration properties can be set with both integer and string values" );
2053
2054   Geometry geometry = CreateQuadGeometry();
2055   Shader shader = CreateShader();
2056   Renderer renderer = Renderer::New( geometry, shader );
2057
2058   /*
2059    * Here we use a templatized function to perform several checks on each enumeration property.
2060    * @see CheckEnumerationProperty for details of the checks performed.
2061    */
2062
2063   CheckEnumerationProperty< FaceCullingMode::Type >( renderer, Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::NONE, FaceCullingMode::FRONT, FaceCullingMode::BACK, "BACK" );
2064   CheckEnumerationProperty< BlendMode::Type >( renderer, Renderer::Property::BLEND_MODE, BlendMode::AUTO, BlendMode::OFF, BlendMode::ON, "ON" );
2065   CheckEnumerationProperty< BlendEquation::Type >( renderer, Renderer::Property::BLEND_EQUATION_RGB, BlendEquation::ADD, BlendEquation::SUBTRACT, BlendEquation::REVERSE_SUBTRACT, "REVERSE_SUBTRACT" );
2066   CheckEnumerationProperty< BlendEquation::Type >( renderer, Renderer::Property::BLEND_EQUATION_ALPHA, BlendEquation::ADD, BlendEquation::SUBTRACT, BlendEquation::REVERSE_SUBTRACT, "REVERSE_SUBTRACT" );
2067   CheckEnumerationProperty< BlendFactor::Type >( renderer, Renderer::Property::BLEND_FACTOR_SRC_RGB, BlendFactor::SRC_ALPHA, BlendFactor::ONE, BlendFactor::SRC_COLOR, "SRC_COLOR" );
2068   CheckEnumerationProperty< BlendFactor::Type >( renderer, Renderer::Property::BLEND_FACTOR_DEST_RGB, BlendFactor::ONE_MINUS_SRC_ALPHA, BlendFactor::ONE, BlendFactor::SRC_COLOR, "SRC_COLOR" );
2069   CheckEnumerationProperty< BlendFactor::Type >( renderer, Renderer::Property::BLEND_FACTOR_SRC_ALPHA, BlendFactor::ONE, BlendFactor::ONE_MINUS_SRC_ALPHA, BlendFactor::SRC_COLOR, "SRC_COLOR" );
2070   CheckEnumerationProperty< BlendFactor::Type >( renderer, Renderer::Property::BLEND_FACTOR_DEST_ALPHA, BlendFactor::ONE_MINUS_SRC_ALPHA, BlendFactor::ONE, BlendFactor::SRC_COLOR, "SRC_COLOR" );
2071   CheckEnumerationProperty< DepthWriteMode::Type >( renderer, Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::AUTO, DepthWriteMode::OFF, DepthWriteMode::ON, "ON" );
2072   CheckEnumerationProperty< DepthFunction::Type >( renderer, Renderer::Property::DEPTH_FUNCTION, DepthFunction::LESS, DepthFunction::ALWAYS, DepthFunction::GREATER, "GREATER" );
2073   CheckEnumerationProperty< DepthTestMode::Type >( renderer, Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::AUTO, DepthTestMode::OFF, DepthTestMode::ON, "ON" );
2074   CheckEnumerationProperty< StencilFunction::Type >( renderer, Renderer::Property::STENCIL_FUNCTION, StencilFunction::ALWAYS, StencilFunction::LESS, StencilFunction::EQUAL, "EQUAL" );
2075   CheckEnumerationProperty< RenderMode::Type >( renderer, Renderer::Property::RENDER_MODE, RenderMode::AUTO, RenderMode::NONE, RenderMode::STENCIL, "STENCIL" );
2076   CheckEnumerationProperty< StencilOperation::Type >( renderer, Renderer::Property::STENCIL_OPERATION_ON_FAIL, StencilOperation::KEEP, StencilOperation::REPLACE, StencilOperation::INCREMENT, "INCREMENT" );
2077   CheckEnumerationProperty< StencilOperation::Type >( renderer, Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, StencilOperation::KEEP, StencilOperation::REPLACE, StencilOperation::INCREMENT, "INCREMENT" );
2078   CheckEnumerationProperty< StencilOperation::Type >( renderer, Renderer::Property::STENCIL_OPERATION_ON_Z_PASS, StencilOperation::KEEP, StencilOperation::REPLACE, StencilOperation::INCREMENT, "INCREMENT" );
2079
2080   END_TEST;
2081 }
2082
2083 Renderer RendererTestFixture( TestApplication& application )
2084 {
2085   Geometry geometry = CreateQuadGeometry();
2086   Shader shader = CreateShader();
2087   Renderer renderer = Renderer::New( geometry, shader );
2088
2089   Actor actor = Actor::New();
2090   actor.AddRenderer( renderer );
2091   actor.SetSize( 400.0f, 400.0f );
2092   Stage stage = Stage::GetCurrent();
2093   stage.GetRootLayer().SetBehavior( Layer::LAYER_3D );
2094   stage.Add( actor );
2095
2096   return renderer;
2097 }
2098
2099 int UtcDaliRendererSetDepthTestMode(void)
2100 {
2101   TestApplication application;
2102   tet_infoline("Test setting the DepthTestMode");
2103
2104   Renderer renderer = RendererTestFixture( application );
2105   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2106   glAbstraction.EnableEnableDisableCallTrace( true );
2107   TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2108
2109   glEnableDisableStack.Reset();
2110   application.SendNotification();
2111   application.Render();
2112
2113   // Check depth-test is enabled by default.
2114   DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Enable", GetDepthTestString() ) );
2115   DALI_TEST_CHECK( !glEnableDisableStack.FindMethodAndParams( "Disable", GetDepthTestString() ) );
2116
2117   // Turn off depth-testing. We want to check if the depth buffer has been disabled, so we need to turn off depth-write as well for this case.
2118   renderer.SetProperty( Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::OFF );
2119   renderer.SetProperty( Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::OFF );
2120
2121   glEnableDisableStack.Reset();
2122   application.SendNotification();
2123   application.Render();
2124
2125   // Check the depth buffer was disabled.
2126   DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Disable", GetDepthTestString() ) );
2127
2128   // Turn on automatic mode depth-testing.
2129   // Layer behavior is currently set to LAYER_3D so AUTO should enable depth-testing.
2130   renderer.SetProperty( Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::AUTO );
2131
2132   glEnableDisableStack.Reset();
2133   application.SendNotification();
2134   application.Render();
2135
2136   // Check depth-test is now enabled.
2137   DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Enable", GetDepthTestString() ) );
2138   DALI_TEST_CHECK( !glEnableDisableStack.FindMethodAndParams( "Disable", GetDepthTestString() ) );
2139
2140   // Change the layer behavior to LAYER_2D.
2141   // Note this will also disable depth testing for the layer by default, we test this first.
2142   Stage::GetCurrent().GetRootLayer().SetBehavior( Layer::LAYER_2D );
2143
2144   glEnableDisableStack.Reset();
2145   application.SendNotification();
2146   application.Render();
2147
2148   // Check depth-test is disabled.
2149   DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Disable", GetDepthTestString() ) );
2150
2151   // Turn the layer depth-test flag back on, and confirm that depth testing is now on.
2152   Stage::GetCurrent().GetRootLayer().SetDepthTestDisabled( false );
2153
2154   glEnableDisableStack.Reset();
2155   application.SendNotification();
2156   application.Render();
2157
2158   // Check depth-test is *still* disabled.
2159   DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Enable", GetDepthTestString() ) );
2160
2161   END_TEST;
2162 }
2163
2164 int UtcDaliRendererSetDepthWriteMode(void)
2165 {
2166   TestApplication application;
2167   tet_infoline("Test setting the DepthWriteMode");
2168
2169   Renderer renderer = RendererTestFixture( application );
2170   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2171
2172   application.SendNotification();
2173   application.Render();
2174
2175   // Check the default depth-write status first.
2176   DALI_TEST_CHECK( glAbstraction.GetLastDepthMask() );
2177
2178   // Turn off depth-writing.
2179   renderer.SetProperty( Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::OFF );
2180
2181   application.SendNotification();
2182   application.Render();
2183
2184   // Check depth-write is now disabled.
2185   DALI_TEST_CHECK( !glAbstraction.GetLastDepthMask() );
2186
2187   // Test the AUTO mode for depth-writing.
2188   // As our renderer is opaque, depth-testing should be enabled.
2189   renderer.SetProperty( Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::AUTO );
2190
2191   application.SendNotification();
2192   application.Render();
2193
2194   // Check depth-write is now enabled.
2195   DALI_TEST_CHECK( glAbstraction.GetLastDepthMask() );
2196
2197   // Now make the renderer be treated as translucent by enabling blending.
2198   // The AUTO depth-write mode should turn depth-write off in this scenario.
2199   renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::ON );
2200
2201   application.SendNotification();
2202   application.Render();
2203
2204   // Check depth-write is now disabled.
2205   DALI_TEST_CHECK( !glAbstraction.GetLastDepthMask() );
2206
2207   END_TEST;
2208 }
2209
2210 int UtcDaliRendererCheckStencilDefaults(void)
2211 {
2212   TestApplication application;
2213   tet_infoline("Test the stencil defaults");
2214
2215   Renderer renderer = RendererTestFixture( application );
2216   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2217   glAbstraction.EnableEnableDisableCallTrace( true );
2218   glAbstraction.EnableStencilFunctionCallTrace( true );
2219   TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2220   TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2221
2222   ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2223
2224   // Check the defaults:
2225   DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_FUNCTION ).Get<int>() ), static_cast<int>( StencilFunction::ALWAYS ), TEST_LOCATION );
2226   DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_FUNCTION_MASK ).Get<int>() ), 0xFF, TEST_LOCATION );
2227   DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_FUNCTION_REFERENCE ).Get<int>() ), 0x00, TEST_LOCATION );
2228   DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_MASK ).Get<int>() ), 0xFF, TEST_LOCATION );
2229   DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_OPERATION_ON_FAIL ).Get<int>() ), static_cast<int>( StencilOperation::KEEP ), TEST_LOCATION );
2230   DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL ).Get<int>() ), static_cast<int>( StencilOperation::KEEP ), TEST_LOCATION );
2231   DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_OPERATION_ON_Z_PASS ).Get<int>() ), static_cast<int>( StencilOperation::KEEP ), TEST_LOCATION );
2232
2233   END_TEST;
2234 }
2235
2236 int UtcDaliRendererSetRenderModeToUseStencilBuffer(void)
2237 {
2238   TestApplication application;
2239   tet_infoline("Test setting the RenderMode to use the stencil buffer");
2240
2241   Renderer renderer = RendererTestFixture( application );
2242   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2243   glAbstraction.EnableEnableDisableCallTrace( true );
2244   glAbstraction.EnableStencilFunctionCallTrace( true );
2245   TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2246   TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2247
2248   // Set the StencilFunction to something other than the default, to confirm it is set as a property,
2249   // but NO GL call has been made while the RenderMode is set to not use the stencil buffer.
2250   renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::NONE );
2251   ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2252
2253   renderer.SetProperty( Renderer::Property::STENCIL_FUNCTION, StencilFunction::NEVER );
2254   DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_FUNCTION ).Get<int>() ), static_cast<int>( StencilFunction::NEVER ), TEST_LOCATION );
2255
2256   ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2257   std::string methodString( "StencilFunc" );
2258   DALI_TEST_CHECK( !glStencilFunctionStack.FindMethod( methodString ) );
2259
2260   // Test the other RenderModes that will not enable the stencil buffer.
2261   renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::AUTO );
2262   ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2263   DALI_TEST_CHECK( !glStencilFunctionStack.FindMethod( methodString ) );
2264
2265   renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::COLOR );
2266   ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2267   DALI_TEST_CHECK( !glStencilFunctionStack.FindMethod( methodString ) );
2268
2269   // Now set the RenderMode to modes that will use the stencil buffer, and check the StencilFunction has changed.
2270   renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::STENCIL );
2271   ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2272
2273   DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Enable", GetStencilTestString() ) );
2274   DALI_TEST_CHECK( glStencilFunctionStack.FindMethod( methodString ) );
2275
2276   // Test the COLOR_STENCIL RenderMode as it also enables the stencil buffer.
2277   // First set a mode to turn off the stencil buffer, so the enable is required.
2278   renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::COLOR );
2279   ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2280   renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::COLOR_STENCIL );
2281   ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2282
2283   DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Enable", GetStencilTestString() ) );
2284   DALI_TEST_CHECK( glStencilFunctionStack.FindMethod( methodString ) );
2285
2286   END_TEST;
2287 }
2288
2289 // Helper function for the SetRenderModeToUseColorBuffer test.
2290 void CheckRenderModeColorMask( TestApplication& application, Renderer& renderer, RenderMode::Type renderMode, bool expectedValue )
2291 {
2292   // Set the RenderMode property to a value that should not allow color buffer writes.
2293   renderer.SetProperty( Renderer::Property::RENDER_MODE, renderMode );
2294   application.SendNotification();
2295   application.Render();
2296
2297   // Check if ColorMask has been called, and that the values are correct.
2298   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2299   const TestGlAbstraction::ColorMaskParams& colorMaskParams( glAbstraction.GetColorMaskParams() );
2300
2301   DALI_TEST_EQUALS<bool>( colorMaskParams.red,   expectedValue, TEST_LOCATION );
2302   DALI_TEST_EQUALS<bool>( colorMaskParams.green, expectedValue, TEST_LOCATION );
2303   DALI_TEST_EQUALS<bool>( colorMaskParams.blue,  expectedValue, TEST_LOCATION );
2304   DALI_TEST_EQUALS<bool>( colorMaskParams.alpha, expectedValue, TEST_LOCATION );
2305 }
2306
2307 int UtcDaliRendererSetRenderModeToUseColorBuffer(void)
2308 {
2309   TestApplication application;
2310   tet_infoline("Test setting the RenderMode to use the color buffer");
2311
2312   Renderer renderer = RendererTestFixture( application );
2313
2314   // Set the RenderMode property to a value that should not allow color buffer writes.
2315   // Then check if ColorMask has been called, and that the values are correct.
2316   CheckRenderModeColorMask( application, renderer, RenderMode::AUTO, true );
2317   CheckRenderModeColorMask( application, renderer, RenderMode::NONE, false );
2318   CheckRenderModeColorMask( application, renderer, RenderMode::COLOR, true );
2319   CheckRenderModeColorMask( application, renderer, RenderMode::STENCIL, false );
2320   CheckRenderModeColorMask( application, renderer, RenderMode::COLOR_STENCIL, true );
2321
2322   END_TEST;
2323 }
2324
2325 int UtcDaliRendererSetStencilFunction(void)
2326 {
2327   TestApplication application;
2328   tet_infoline("Test setting the StencilFunction");
2329
2330   Renderer renderer = RendererTestFixture( application );
2331   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2332   glAbstraction.EnableEnableDisableCallTrace( true );
2333   glAbstraction.EnableStencilFunctionCallTrace( true );
2334   TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2335   TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2336
2337   // RenderMode must use the stencil for StencilFunction to operate.
2338   renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::STENCIL );
2339   ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2340
2341   /*
2342    * Lookup table for testing StencilFunction.
2343    * Note: This MUST be in the same order as the Dali::StencilFunction enum.
2344    */
2345   const int StencilFunctionLookupTable[] = {
2346       GL_NEVER,
2347       GL_LESS,
2348       GL_EQUAL,
2349       GL_LEQUAL,
2350       GL_GREATER,
2351       GL_NOTEQUAL,
2352       GL_GEQUAL,
2353       GL_ALWAYS
2354   }; const int StencilFunctionLookupTableCount = sizeof( StencilFunctionLookupTable ) / sizeof( StencilFunctionLookupTable[0] );
2355
2356   /*
2357    * Loop through all types of StencilFunction, checking:
2358    *  - The value is cached (set in event thread side)
2359    *  - Causes "glStencilFunc" to be called
2360    *  - Checks the correct parameters to "glStencilFunc" were used
2361    */
2362   std::string nonChangingParameters = "0, 255";
2363   std::string methodString( "StencilFunc" );
2364   for( int i = 0; i < StencilFunctionLookupTableCount; ++i )
2365   {
2366     // Set the property.
2367     renderer.SetProperty( Renderer::Property::STENCIL_FUNCTION, static_cast<Dali::StencilFunction::Type>( i ) );
2368
2369     // Check GetProperty returns the same value.
2370     DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_FUNCTION ).Get<int>() ), i, TEST_LOCATION );
2371
2372     // Reset the trace debug.
2373     ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2374
2375     // Check the function is called and the parameters are correct.
2376     std::stringstream parameterStream;
2377     parameterStream << StencilFunctionLookupTable[ i ] << ", " << nonChangingParameters;
2378
2379     DALI_TEST_CHECK( glStencilFunctionStack.FindMethodAndParams( methodString, parameterStream.str() ) );
2380   }
2381
2382   // Change the Function Reference only and check the behavior is correct:
2383   // 170 is 0xaa in hex / 10101010 in binary (every other bit set).
2384   int testValueReference = 170;
2385   renderer.SetProperty( Renderer::Property::STENCIL_FUNCTION_REFERENCE, testValueReference );
2386
2387   DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_FUNCTION_REFERENCE ).Get<int>() ), testValueReference, TEST_LOCATION );
2388
2389   ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2390
2391   std::stringstream parameterStream;
2392   parameterStream << StencilFunctionLookupTable[ StencilOperation::DECREMENT_WRAP ] << ", " << testValueReference << ", 255";
2393
2394   DALI_TEST_CHECK( glStencilFunctionStack.FindMethodAndParams( methodString, parameterStream.str() ) );
2395
2396
2397   // Change the Function Mask only and check the behavior is correct:
2398   // 85 is 0x55 in hex / 01010101 in binary (every other bit set).
2399   int testValueMask = 85;
2400   renderer.SetProperty( Renderer::Property::STENCIL_FUNCTION_MASK, testValueMask );
2401
2402   DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_FUNCTION_MASK ).Get<int>() ), testValueMask, TEST_LOCATION );
2403
2404   ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2405
2406   // Clear the stringstream.
2407   parameterStream.str( std::string() );
2408   parameterStream << StencilFunctionLookupTable[ StencilOperation::DECREMENT_WRAP ] << ", " << testValueReference << ", " << testValueMask;
2409
2410   DALI_TEST_CHECK( glStencilFunctionStack.FindMethodAndParams( methodString, parameterStream.str() ) );
2411
2412   END_TEST;
2413 }
2414
2415 int UtcDaliRendererSetStencilOperation(void)
2416 {
2417   TestApplication application;
2418   tet_infoline("Test setting the StencilOperation");
2419
2420   Renderer renderer = RendererTestFixture( application );
2421   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2422   glAbstraction.EnableEnableDisableCallTrace( true );
2423   glAbstraction.EnableStencilFunctionCallTrace( true );
2424   TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2425   TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2426
2427   // RenderMode must use the stencil for StencilOperation to operate.
2428   renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::STENCIL );
2429
2430   /*
2431    * Lookup table for testing StencilOperation.
2432    * Note: This MUST be in the same order as the Dali::StencilOperation enum.
2433    */
2434   const int StencilOperationLookupTable[] = {
2435     GL_ZERO,
2436     GL_KEEP,
2437     GL_REPLACE,
2438     GL_INCR,
2439     GL_DECR,
2440     GL_INVERT,
2441     GL_INCR_WRAP,
2442     GL_DECR_WRAP
2443   }; const int StencilOperationLookupTableCount = sizeof( StencilOperationLookupTable ) / sizeof( StencilOperationLookupTable[0] );
2444
2445   // Set all 3 StencilOperation properties to a default.
2446   renderer.SetProperty( Renderer::Property::STENCIL_OPERATION_ON_FAIL, StencilOperation::ZERO );
2447   renderer.SetProperty( Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, StencilOperation::ZERO );
2448   renderer.SetProperty( Renderer::Property::STENCIL_OPERATION_ON_Z_PASS, StencilOperation::ZERO );
2449
2450   // Set our expected parameter list to the equivalent result.
2451   int parameters[] = { StencilOperationLookupTable[ StencilOperation::ZERO ], StencilOperationLookupTable[ StencilOperation::ZERO ], StencilOperationLookupTable[ StencilOperation::ZERO ] };
2452
2453   ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2454
2455   /*
2456    * Loop through all types of StencilOperation, checking:
2457    *  - The value is cached (set in event thread side)
2458    *  - Causes "glStencilFunc" to be called
2459    *  - Checks the correct parameters to "glStencilFunc" were used
2460    *  - Checks the above for all 3 parameter placements of StencilOperation ( OnFail, OnZFail, OnPass )
2461    */
2462   int stencilOperationPropertyKeys[] = { Renderer::Property::STENCIL_OPERATION_ON_FAIL, Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, Renderer::Property::STENCIL_OPERATION_ON_Z_PASS };
2463   std::string methodString( "StencilOp" );
2464
2465   for( int parameterIndex = 0; parameterIndex < 3; ++parameterIndex )
2466   {
2467     for( int i = 0; i < StencilOperationLookupTableCount; ++i )
2468     {
2469       // Set the property (outer loop causes all 3 different properties to be set separately).
2470       renderer.SetProperty( stencilOperationPropertyKeys[ parameterIndex ], static_cast<Dali::StencilFunction::Type>( i ) );
2471
2472       // Check GetProperty returns the same value.
2473       DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( stencilOperationPropertyKeys[ parameterIndex ] ).Get<int>() ), i, TEST_LOCATION );
2474
2475       // Reset the trace debug.
2476       ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2477
2478       // Check the function is called and the parameters are correct.
2479       // Set the expected parameter value at its correct index (only)
2480       parameters[ parameterIndex ] = StencilOperationLookupTable[ i ];
2481
2482       // Build the parameter list.
2483       std::stringstream parameterStream;
2484       for( int parameterBuild = 0; parameterBuild < 3; ++parameterBuild )
2485       {
2486         parameterStream << parameters[ parameterBuild ];
2487         // Comma-separate the parameters.
2488         if( parameterBuild < 2 )
2489         {
2490           parameterStream << ", ";
2491         }
2492       }
2493
2494       // Check the function was called and the parameters were correct.
2495       DALI_TEST_CHECK( glStencilFunctionStack.FindMethodAndParams( methodString, parameterStream.str() ) );
2496     }
2497   }
2498
2499   END_TEST;
2500 }
2501
2502 int UtcDaliRendererSetStencilMask(void)
2503 {
2504   TestApplication application;
2505   tet_infoline("Test setting the StencilMask");
2506
2507   Renderer renderer = RendererTestFixture( application );
2508   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2509   glAbstraction.EnableEnableDisableCallTrace( true );
2510   glAbstraction.EnableStencilFunctionCallTrace( true );
2511   TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2512   TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2513
2514   // RenderMode must use the stencil for StencilMask to operate.
2515   renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::STENCIL );
2516
2517   // Set the StencilMask property to a value.
2518   renderer.SetProperty( Renderer::Property::STENCIL_MASK, 0x00 );
2519
2520   // Check GetProperty returns the same value.
2521   DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_MASK ).Get<int>() ), 0x00, TEST_LOCATION );
2522
2523   ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2524
2525   std::string methodString( "StencilMask" );
2526   std::string parameterString = "0";
2527
2528   // Check the function was called and the parameters were correct.
2529   DALI_TEST_CHECK( glStencilFunctionStack.FindMethodAndParams( methodString, parameterString ) );
2530
2531   // Set the StencilMask property to another value to ensure it has changed.
2532   renderer.SetProperty( Renderer::Property::STENCIL_MASK, 0xFF );
2533
2534   // Check GetProperty returns the same value.
2535   DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_MASK ).Get<int>() ), 0xFF, TEST_LOCATION );
2536
2537   ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2538
2539   parameterString = "255";
2540
2541   // Check the function was called and the parameters were correct.
2542   DALI_TEST_CHECK( glStencilFunctionStack.FindMethodAndParams( methodString, parameterString ) );
2543
2544   END_TEST;
2545 }
2546
2547 int UtcDaliRendererWrongNumberOfTextures(void)
2548 {
2549   TestApplication application;
2550   tet_infoline("Test renderer does render even if number of textures is different than active samplers in the shader");
2551
2552   //Create a TextureSet with 4 textures (One more texture in the texture set than active samplers)
2553   //@note Shaders in the test suit have 3 active samplers. See TestGlAbstraction::GetActiveUniform()
2554   Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, 64u, 64u );
2555   TextureSet textureSet = CreateTextureSet();
2556   textureSet.SetTexture(0, texture );
2557   textureSet.SetTexture(1, texture );
2558   textureSet.SetTexture(2, texture );
2559   textureSet.SetTexture(3, texture );
2560   Shader shader = Shader::New("VertexSource", "FragmentSource");
2561   Geometry geometry = CreateQuadGeometry();
2562   Renderer renderer = Renderer::New( geometry, shader );
2563   renderer.SetTextures( textureSet );
2564
2565   Actor actor= Actor::New();
2566   actor.AddRenderer(renderer);
2567   actor.SetPosition(0.0f,0.0f);
2568   actor.SetSize(100, 100);
2569   Stage::GetCurrent().Add(actor);
2570
2571   TestGlAbstraction& gl = application.GetGlAbstraction();
2572   TraceCallStack& drawTrace = gl.GetDrawTrace();
2573   drawTrace.Reset();
2574   drawTrace.Enable(true);
2575
2576   application.SendNotification();
2577   application.Render(0);
2578
2579   //Test we do the drawcall when TextureSet has more textures than there are active samplers in the shader
2580   DALI_TEST_EQUALS( drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION );
2581
2582   //Create a TextureSet with 1 texture (two more active samplers than texture in the texture set)
2583   //@note Shaders in the test suit have 3 active samplers. See TestGlAbstraction::GetActiveUniform()
2584   textureSet = CreateTextureSet();
2585   renderer.SetTextures( textureSet );
2586   textureSet.SetTexture(0, texture );
2587   drawTrace.Reset();
2588   application.SendNotification();
2589   application.Render(0);
2590
2591   //Test we do the drawcall when TextureSet has less textures than there are active samplers in the shader.
2592   DALI_TEST_EQUALS( drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION );
2593
2594   END_TEST;
2595 }