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