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