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