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