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