[dali_1.3.17] 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   renderer.SetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, true);
995
996   application.SendNotification();
997   application.Render();
998
999   value = renderer.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
1000   DALI_TEST_CHECK( value.Get( preMultipliedAlpha ) );
1001   DALI_TEST_CHECK( preMultipliedAlpha );
1002
1003   value = renderer.GetCurrentProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
1004   DALI_TEST_CHECK( value.Get( preMultipliedAlpha ) );
1005   DALI_TEST_CHECK( preMultipliedAlpha );
1006
1007   srcFactorRgb    = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
1008   destFactorRgb   = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
1009   srcFactorAlpha  = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
1010   destFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
1011
1012   DALI_TEST_EQUALS( (int)BlendFactor::ONE,                 srcFactorRgb,    TEST_LOCATION );
1013   DALI_TEST_EQUALS( (int)BlendFactor::ONE_MINUS_SRC_ALPHA, destFactorRgb,   TEST_LOCATION );
1014   DALI_TEST_EQUALS( (int)BlendFactor::ONE,                 srcFactorAlpha,  TEST_LOCATION );
1015   DALI_TEST_EQUALS( (int)BlendFactor::ONE_MINUS_SRC_ALPHA, destFactorAlpha, TEST_LOCATION );
1016
1017   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uColor", actualValue ) );
1018   DALI_TEST_EQUALS( actualValue, Vector4(0.5f, 0.0f, 0.5f, 0.5f), TEST_LOCATION );
1019
1020   END_TEST;
1021 }
1022
1023 int UtcDaliRendererConstraint01(void)
1024 {
1025   TestApplication application;
1026
1027   tet_infoline("Test that a non-uniform renderer property can be constrained");
1028
1029   Shader shader = Shader::New("VertexSource", "FragmentSource");
1030   Geometry geometry = CreateQuadGeometry();
1031   Renderer renderer = Renderer::New( geometry, shader );
1032
1033   Actor actor = Actor::New();
1034   actor.AddRenderer(renderer);
1035   actor.SetSize(400, 400);
1036   Stage::GetCurrent().Add(actor);
1037
1038   Vector4 initialColor = Color::WHITE;
1039   Property::Index colorIndex = renderer.RegisterProperty( "uFadeColor", initialColor );
1040
1041   application.SendNotification();
1042   application.Render(0);
1043   DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION );
1044
1045   // Apply constraint
1046   Constraint constraint = Constraint::New<Vector4>( renderer, colorIndex, TestConstraintNoBlue );
1047   constraint.Apply();
1048   application.SendNotification();
1049   application.Render(0);
1050
1051   // Expect no blue component in either buffer - yellow
1052   DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector4 >( colorIndex ), Color::YELLOW, TEST_LOCATION );
1053   application.Render(0);
1054   DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector4 >( colorIndex ), Color::YELLOW, TEST_LOCATION );
1055
1056   renderer.RemoveConstraints();
1057   renderer.SetProperty(colorIndex, Color::WHITE );
1058   application.SendNotification();
1059   application.Render(0);
1060   DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector4 >( colorIndex ), Color::WHITE, TEST_LOCATION );
1061
1062   END_TEST;
1063 }
1064
1065 int UtcDaliRendererConstraint02(void)
1066 {
1067   TestApplication application;
1068
1069   tet_infoline("Test that a uniform map renderer property can be constrained");
1070
1071   Shader shader = Shader::New("VertexSource", "FragmentSource");
1072   Geometry geometry = CreateQuadGeometry();
1073   Renderer renderer = Renderer::New( geometry, shader );
1074
1075   Actor actor = Actor::New();
1076   actor.AddRenderer(renderer);
1077   actor.SetSize(400, 400);
1078   Stage::GetCurrent().Add(actor);
1079   application.SendNotification();
1080   application.Render(0);
1081
1082   Vector4 initialColor = Color::WHITE;
1083   Property::Index colorIndex = renderer.RegisterProperty( "uFadeColor", initialColor );
1084
1085   TestGlAbstraction& gl = application.GetGlAbstraction();
1086
1087   application.SendNotification();
1088   application.Render(0);
1089
1090   Vector4 actualValue(Vector4::ZERO);
1091   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1092   DALI_TEST_EQUALS( actualValue, initialColor, TEST_LOCATION );
1093
1094   // Apply constraint
1095   Constraint constraint = Constraint::New<Vector4>( renderer, colorIndex, TestConstraintNoBlue );
1096   constraint.Apply();
1097   application.SendNotification();
1098   application.Render(0);
1099
1100    // Expect no blue component in either buffer - yellow
1101   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1102   DALI_TEST_EQUALS( actualValue, Color::YELLOW, TEST_LOCATION );
1103
1104   application.Render(0);
1105   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1106   DALI_TEST_EQUALS( actualValue, Color::YELLOW, TEST_LOCATION );
1107
1108   renderer.RemoveConstraints();
1109   renderer.SetProperty(colorIndex, Color::WHITE );
1110   application.SendNotification();
1111   application.Render(0);
1112
1113   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1114   DALI_TEST_EQUALS( actualValue, Color::WHITE, TEST_LOCATION );
1115
1116   END_TEST;
1117 }
1118
1119 int UtcDaliRendererAnimatedProperty01(void)
1120 {
1121   TestApplication application;
1122
1123   tet_infoline("Test that a non-uniform renderer property can be animated");
1124
1125   Shader shader = Shader::New("VertexSource", "FragmentSource");
1126   Geometry geometry = CreateQuadGeometry();
1127   Renderer renderer = Renderer::New( geometry, shader );
1128
1129   Actor actor = Actor::New();
1130   actor.AddRenderer(renderer);
1131   actor.SetSize(400, 400);
1132   Stage::GetCurrent().Add(actor);
1133
1134   Vector4 initialColor = Color::WHITE;
1135   Property::Index colorIndex = renderer.RegisterProperty( "uFadeColor", initialColor );
1136
1137   application.SendNotification();
1138   application.Render(0);
1139   DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION );
1140
1141   Animation  animation = Animation::New(1.0f);
1142   KeyFrames keyFrames = KeyFrames::New();
1143   keyFrames.Add(0.0f, initialColor);
1144   keyFrames.Add(1.0f, Color::TRANSPARENT);
1145   animation.AnimateBetween( Property( renderer, colorIndex ), keyFrames );
1146   animation.Play();
1147
1148   application.SendNotification();
1149   application.Render(500);
1150
1151   DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector4 >( colorIndex ), Color::WHITE * 0.5f, TEST_LOCATION );
1152
1153   application.Render(500);
1154
1155   DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector4 >( colorIndex ), Color::TRANSPARENT, TEST_LOCATION );
1156
1157   END_TEST;
1158 }
1159
1160 int UtcDaliRendererAnimatedProperty02(void)
1161 {
1162   TestApplication application;
1163
1164   tet_infoline("Test that a uniform map renderer property can be animated");
1165
1166   Shader shader = Shader::New("VertexSource", "FragmentSource");
1167   Geometry geometry = CreateQuadGeometry();
1168   Renderer renderer = Renderer::New( geometry, shader );
1169
1170   Actor actor = Actor::New();
1171   actor.AddRenderer(renderer);
1172   actor.SetSize(400, 400);
1173   Stage::GetCurrent().Add(actor);
1174   application.SendNotification();
1175   application.Render(0);
1176
1177   Vector4 initialColor = Color::WHITE;
1178   Property::Index colorIndex = renderer.RegisterProperty( "uFadeColor", initialColor );
1179
1180   TestGlAbstraction& gl = application.GetGlAbstraction();
1181
1182   application.SendNotification();
1183   application.Render(0);
1184
1185   Vector4 actualValue(Vector4::ZERO);
1186   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1187   DALI_TEST_EQUALS( actualValue, initialColor, TEST_LOCATION );
1188
1189   Animation  animation = Animation::New(1.0f);
1190   KeyFrames keyFrames = KeyFrames::New();
1191   keyFrames.Add(0.0f, initialColor);
1192   keyFrames.Add(1.0f, Color::TRANSPARENT);
1193   animation.AnimateBetween( Property( renderer, colorIndex ), keyFrames );
1194   animation.Play();
1195
1196   application.SendNotification();
1197   application.Render(500);
1198
1199   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1200   DALI_TEST_EQUALS( actualValue, Color::WHITE * 0.5f, TEST_LOCATION );
1201
1202   application.Render(500);
1203   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1204   DALI_TEST_EQUALS( actualValue, Color::TRANSPARENT, TEST_LOCATION );
1205
1206   END_TEST;
1207 }
1208
1209 int UtcDaliRendererUniformMapPrecendence01(void)
1210 {
1211   TestApplication application;
1212
1213   tet_infoline("Test the uniform map precedence is applied properly");
1214
1215   Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1216
1217   Shader shader = Shader::New("VertexSource", "FragmentSource");
1218   TextureSet textureSet = CreateTextureSet( image );
1219
1220   Geometry geometry = CreateQuadGeometry();
1221   Renderer renderer = Renderer::New( geometry, shader );
1222   renderer.SetTextures( textureSet );
1223
1224   Actor actor = Actor::New();
1225   actor.AddRenderer(renderer);
1226   actor.SetSize(400, 400);
1227   Stage::GetCurrent().Add(actor);
1228   application.SendNotification();
1229   application.Render(0);
1230
1231   renderer.RegisterProperty( "uFadeColor", Color::RED );
1232   actor.RegisterProperty( "uFadeColor", Color::GREEN );
1233   Property::Index shaderFadeColorIndex = shader.RegisterProperty( "uFadeColor", Color::MAGENTA );
1234
1235   TestGlAbstraction& gl = application.GetGlAbstraction();
1236
1237   application.SendNotification();
1238   application.Render(0);
1239
1240   // Expect that the actor's fade color property is accessed
1241   Vector4 actualValue(Vector4::ZERO);
1242   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1243   DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
1244
1245   // Animate shader's fade color property. Should be no change to uniform
1246   Animation  animation = Animation::New(1.0f);
1247   KeyFrames keyFrames = KeyFrames::New();
1248   keyFrames.Add(0.0f, Color::WHITE);
1249   keyFrames.Add(1.0f, Color::TRANSPARENT);
1250   animation.AnimateBetween( Property( shader, shaderFadeColorIndex ), keyFrames );
1251   animation.Play();
1252
1253   application.SendNotification();
1254   application.Render(500);
1255
1256   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1257   DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
1258
1259   application.Render(500);
1260   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1261   DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
1262
1263   END_TEST;
1264 }
1265
1266 int UtcDaliRendererUniformMapPrecendence02(void)
1267 {
1268   TestApplication application;
1269
1270   tet_infoline("Test the uniform map precedence is applied properly");
1271
1272   Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1273
1274   Shader shader = Shader::New("VertexSource", "FragmentSource");
1275   TextureSet textureSet = CreateTextureSet( image );
1276
1277   Geometry geometry = CreateQuadGeometry();
1278   Renderer renderer = Renderer::New( geometry, shader );
1279   renderer.SetTextures( textureSet );
1280
1281   Actor actor = Actor::New();
1282   actor.AddRenderer(renderer);
1283   actor.SetSize(400, 400);
1284   Stage::GetCurrent().Add(actor);
1285   application.SendNotification();
1286   application.Render(0);
1287
1288   // Don't add property / uniform map to renderer
1289   actor.RegisterProperty( "uFadeColor", Color::GREEN );
1290   Property::Index shaderFadeColorIndex = shader.RegisterProperty( "uFadeColor", Color::BLUE );
1291
1292   TestGlAbstraction& gl = application.GetGlAbstraction();
1293
1294   application.SendNotification();
1295   application.Render(0);
1296
1297   // Expect that the actor's fade color property is accessed
1298   Vector4 actualValue(Vector4::ZERO);
1299   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1300   DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
1301
1302   // Animate texture set's fade color property. Should be no change to uniform
1303   Animation  animation = Animation::New(1.0f);
1304   KeyFrames keyFrames = KeyFrames::New();
1305   keyFrames.Add(0.0f, Color::WHITE);
1306   keyFrames.Add(1.0f, Color::TRANSPARENT);
1307   animation.AnimateBetween( Property( shader, shaderFadeColorIndex ), keyFrames );
1308   animation.Play();
1309
1310   application.SendNotification();
1311   application.Render(500);
1312
1313   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1314   DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
1315
1316   application.Render(500);
1317   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1318   DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
1319
1320   END_TEST;
1321 }
1322
1323
1324 int UtcDaliRendererUniformMapPrecendence03(void)
1325 {
1326   TestApplication application;
1327
1328   tet_infoline("Test the uniform map precedence is applied properly");
1329
1330   Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1331
1332   Shader shader = Shader::New("VertexSource", "FragmentSource");
1333   TextureSet textureSet = CreateTextureSet( image );
1334
1335   Geometry geometry = CreateQuadGeometry();
1336   Renderer renderer = Renderer::New( geometry, shader );
1337   renderer.SetTextures( textureSet );
1338
1339   Actor actor = Actor::New();
1340   actor.AddRenderer(renderer);
1341   actor.SetSize(400, 400);
1342   Stage::GetCurrent().Add(actor);
1343   application.SendNotification();
1344   application.Render(0);
1345
1346   // Don't add property / uniform map to renderer or actor
1347   shader.RegisterProperty( "uFadeColor", Color::BLACK );
1348
1349   TestGlAbstraction& gl = application.GetGlAbstraction();
1350
1351   application.SendNotification();
1352   application.Render(0);
1353
1354   // Expect that the shader's fade color property is accessed
1355   Vector4 actualValue(Vector4::ZERO);
1356   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1357   DALI_TEST_EQUALS( actualValue, Color::BLACK, TEST_LOCATION );
1358
1359   END_TEST;
1360 }
1361
1362 int UtcDaliRendererUniformMapMultipleUniforms01(void)
1363 {
1364   TestApplication application;
1365
1366   tet_infoline("Test the uniform maps are collected from all objects (same type)");
1367
1368   Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1369
1370   Shader shader = Shader::New("VertexSource", "FragmentSource");
1371   TextureSet textureSet = CreateTextureSet( image );
1372
1373   Geometry geometry = CreateQuadGeometry();
1374   Renderer renderer = Renderer::New( geometry, shader );
1375   renderer.SetTextures( textureSet );
1376
1377   Actor actor = Actor::New();
1378   actor.AddRenderer(renderer);
1379   actor.SetSize(400, 400);
1380   Stage::GetCurrent().Add(actor);
1381   application.SendNotification();
1382   application.Render(0);
1383
1384   renderer.RegisterProperty( "uUniform1", Color::RED );
1385   actor.RegisterProperty( "uUniform2", Color::GREEN );
1386   shader.RegisterProperty( "uUniform3", Color::MAGENTA );
1387
1388   TestGlAbstraction& gl = application.GetGlAbstraction();
1389
1390   application.SendNotification();
1391   application.Render(0);
1392
1393   // Expect that each of the object's uniforms are set
1394   Vector4 uniform1Value(Vector4::ZERO);
1395   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uUniform1", uniform1Value ) );
1396   DALI_TEST_EQUALS( uniform1Value, Color::RED, TEST_LOCATION );
1397
1398   Vector4 uniform2Value(Vector4::ZERO);
1399   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uUniform2", uniform2Value ) );
1400   DALI_TEST_EQUALS( uniform2Value, Color::GREEN, TEST_LOCATION );
1401
1402   Vector4 uniform3Value(Vector4::ZERO);
1403   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uUniform3", uniform3Value ) );
1404   DALI_TEST_EQUALS( uniform3Value, Color::MAGENTA, TEST_LOCATION );
1405
1406   END_TEST;
1407 }
1408
1409 int UtcDaliRendererUniformMapMultipleUniforms02(void)
1410 {
1411   TestApplication application;
1412
1413   tet_infoline("Test the uniform maps are collected from all objects (different types)");
1414
1415   Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1416
1417   Shader shader = Shader::New("VertexSource", "FragmentSource");
1418   TextureSet textureSet = CreateTextureSet( image );
1419
1420   Geometry geometry = CreateQuadGeometry();
1421   Renderer renderer = Renderer::New( geometry, shader );
1422   renderer.SetTextures( textureSet );
1423
1424   Actor actor = Actor::New();
1425   actor.AddRenderer(renderer);
1426   actor.SetSize(400, 400);
1427   Stage::GetCurrent().Add(actor);
1428   application.SendNotification();
1429   application.Render(0);
1430
1431   Property::Value value1(Color::RED);
1432   renderer.RegisterProperty( "uFadeColor", value1 );
1433
1434   Property::Value value2(1.0f);
1435   actor.RegisterProperty( "uFadeProgress", value2 );
1436
1437   Property::Value value3(Matrix3::IDENTITY);
1438   shader.RegisterProperty( "uANormalMatrix", value3 );
1439
1440   TestGlAbstraction& gl = application.GetGlAbstraction();
1441
1442   application.SendNotification();
1443   application.Render(0);
1444
1445   // Expect that each of the object's uniforms are set
1446   Vector4 uniform1Value(Vector4::ZERO);
1447   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", uniform1Value ) );
1448   DALI_TEST_EQUALS( uniform1Value, value1.Get<Vector4>(), TEST_LOCATION );
1449
1450   float uniform2Value(0.0f);
1451   DALI_TEST_CHECK( gl.GetUniformValue<float>( "uFadeProgress", uniform2Value ) );
1452   DALI_TEST_EQUALS( uniform2Value, value2.Get<float>(), TEST_LOCATION );
1453
1454   Matrix3 uniform3Value;
1455   DALI_TEST_CHECK( gl.GetUniformValue<Matrix3>( "uANormalMatrix", uniform3Value ) );
1456   DALI_TEST_EQUALS( uniform3Value, value3.Get<Matrix3>(), TEST_LOCATION );
1457
1458   END_TEST;
1459 }
1460
1461
1462 Renderer CreateRenderer( Actor actor, Geometry geometry, Shader shader, int depthIndex )
1463 {
1464   Image image0 = BufferImage::New( 64, 64, Pixel::RGB888 );
1465   TextureSet textureSet0 = CreateTextureSet( image0 );
1466   Renderer renderer0 = Renderer::New( geometry, shader );
1467   renderer0.SetTextures( textureSet0 );
1468   renderer0.SetProperty( Renderer::Property::DEPTH_INDEX, depthIndex );
1469   actor.AddRenderer(renderer0);
1470   return renderer0;
1471 }
1472
1473
1474 Actor CreateActor( Actor parent, int siblingOrder, const char* location )
1475 {
1476   Actor actor = Actor::New();
1477   actor.SetAnchorPoint(AnchorPoint::CENTER);
1478   actor.SetParentOrigin(AnchorPoint::CENTER);
1479   actor.SetPosition(0.0f,0.0f);
1480   actor.SetSize(100, 100);
1481   parent.Add(actor);
1482   actor.SetProperty( Dali::DevelActor::Property::SIBLING_ORDER, siblingOrder );
1483   DALI_TEST_EQUALS( actor.GetProperty<int>( Dali::DevelActor::Property::SIBLING_ORDER), siblingOrder, TEST_INNER_LOCATION(location) );
1484
1485   return actor;
1486 }
1487
1488 int UtcDaliRendererRenderOrder2DLayer(void)
1489 {
1490   TestApplication application;
1491   tet_infoline("Test the rendering order in a 2D layer is correct");
1492
1493   Shader shader = Shader::New("VertexSource", "FragmentSource");
1494   Geometry geometry = CreateQuadGeometry();
1495
1496   Actor root = Stage::GetCurrent().GetRootLayer();
1497
1498   Actor actor0 = CreateActor( root, 0, TEST_LOCATION );
1499   Renderer renderer0 = CreateRenderer( actor0, geometry, shader, 0 );
1500
1501   Actor actor1 = CreateActor( root, 0, TEST_LOCATION );
1502   Renderer renderer1 = CreateRenderer( actor1, geometry, shader, 0 );
1503
1504   Actor actor2 = CreateActor( root, 0, TEST_LOCATION );
1505   Renderer renderer2 = CreateRenderer( actor2, geometry, shader, 0 );
1506
1507   Actor actor3 = CreateActor( root, 0, TEST_LOCATION );
1508   Renderer renderer3 = CreateRenderer( actor3, geometry, shader, 0 );
1509
1510   application.SendNotification();
1511   application.Render(0);
1512
1513   /*
1514    * Create the following hierarchy:
1515    *
1516    *            actor2
1517    *              /
1518    *             /
1519    *          actor1
1520    *           /
1521    *          /
1522    *       actor0
1523    *        /
1524    *       /
1525    *    actor3
1526    *
1527    *  Expected rendering order : actor2 - actor1 - actor0 - actor3
1528    */
1529   actor2.Add(actor1);
1530   actor1.Add(actor0);
1531   actor0.Add(actor3);
1532   application.SendNotification();
1533   application.Render(0);
1534
1535   TestGlAbstraction& gl = application.GetGlAbstraction();
1536   gl.EnableTextureCallTrace(true);
1537   application.SendNotification();
1538   application.Render(0);
1539
1540   int textureBindIndex[4];
1541   for( unsigned int i(0); i<4; ++i )
1542   {
1543     std::stringstream params;
1544     params << GL_TEXTURE_2D<<", "<<i+1;
1545     textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str() );
1546   }
1547
1548   //Check that actor1 has been rendered after actor2
1549   DALI_TEST_GREATER( textureBindIndex[1], textureBindIndex[2], TEST_LOCATION );
1550
1551   //Check that actor0 has been rendered after actor1
1552   DALI_TEST_GREATER( textureBindIndex[0], textureBindIndex[1], TEST_LOCATION );
1553
1554   //Check that actor3 has been rendered after actor0
1555   DALI_TEST_GREATER( textureBindIndex[3], textureBindIndex[0], TEST_LOCATION );
1556
1557   END_TEST;
1558 }
1559
1560 int UtcDaliRendererRenderOrder2DLayerMultipleRenderers(void)
1561 {
1562   TestApplication application;
1563   tet_infoline("Test the rendering order in a 2D layer is correct using multiple renderers per actor");
1564
1565   /*
1566    * Creates the following hierarchy:
1567    *
1568    *             actor0------------------------>actor1
1569    *            /   |   \                    /   |   \
1570    *          /     |     \                /     |     \
1571    *        /       |       \            /       |       \
1572    * renderer0 renderer1 renderer2 renderer3 renderer4 renderer5
1573    *
1574    *  renderer0 has depth index 2
1575    *  renderer1 has depth index 0
1576    *  renderer2 has depth index 1
1577    *
1578    *  renderer3 has depth index 1
1579    *  renderer4 has depth index 0
1580    *  renderer5 has depth index -1
1581    *
1582    *  Expected rendering order: renderer1 - renderer2 - renderer0 - renderer5 - renderer4 - renderer3
1583    */
1584
1585   Shader shader = Shader::New("VertexSource", "FragmentSource");
1586   Geometry geometry = CreateQuadGeometry();
1587
1588   Actor root = Stage::GetCurrent().GetRootLayer();
1589
1590   Actor actor0 = CreateActor( root, 0, TEST_LOCATION );
1591   Actor actor1 = CreateActor( actor0, 0, TEST_LOCATION );
1592   Renderer renderer0 = CreateRenderer( actor0, geometry, shader, 2 );
1593   Renderer renderer1 = CreateRenderer( actor0, geometry, shader, 0 );
1594   Renderer renderer2 = CreateRenderer( actor0, geometry, shader, 1 );
1595   Renderer renderer3 = CreateRenderer( actor1, geometry, shader, 1 );
1596   Renderer renderer4 = CreateRenderer( actor1, geometry, shader, 0 );
1597   Renderer renderer5 = CreateRenderer( actor1, geometry, shader, -1 );
1598
1599   application.SendNotification();
1600   application.Render(0);
1601
1602   TestGlAbstraction& gl = application.GetGlAbstraction();
1603   gl.EnableTextureCallTrace(true);
1604   application.SendNotification();
1605   application.Render(0);
1606
1607   int textureBindIndex[6];
1608   for( unsigned int i(0); i<6; ++i )
1609   {
1610     std::stringstream params;
1611     params << GL_TEXTURE_2D<<", "<<i+1;
1612     textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str() );
1613   }
1614
1615   //Check that renderer3 has been rendered after renderer4
1616   DALI_TEST_GREATER( textureBindIndex[3], textureBindIndex[4], TEST_LOCATION );
1617
1618   //Check that renderer0 has been rendered after renderer2
1619   DALI_TEST_GREATER( textureBindIndex[4], textureBindIndex[5], TEST_LOCATION );
1620
1621   //Check that renderer5 has been rendered after renderer2
1622   DALI_TEST_GREATER( textureBindIndex[5], textureBindIndex[0], TEST_LOCATION );
1623
1624   //Check that renderer0 has been rendered after renderer2
1625   DALI_TEST_GREATER( textureBindIndex[0], textureBindIndex[2], TEST_LOCATION );
1626
1627   //Check that renderer2 has been rendered after renderer1
1628   DALI_TEST_GREATER( textureBindIndex[2], textureBindIndex[1], TEST_LOCATION );
1629
1630   END_TEST;
1631 }
1632
1633
1634 int UtcDaliRendererRenderOrder2DLayerSiblingOrder(void)
1635 {
1636   TestApplication application;
1637   tet_infoline("Test the rendering order in a 2D layer is correct using sibling order");
1638
1639   /*
1640    * Creates the following hierarchy:
1641    *
1642    *                            Layer
1643    *                           /    \
1644    *                         /        \
1645    *                       /            \
1646    *                     /                \
1647    *                   /                    \
1648    *             actor0 (SIBLING_ORDER:1)     actor1 (SIBLING_ORDER:0)
1649    *            /   |   \                    /   |   \
1650    *          /     |     \                /     |     \
1651    *        /       |       \            /       |       \
1652    * renderer0 renderer1  actor2     renderer2 renderer3 renderer4
1653    *    DI:2      DI:0      |           DI:0      DI:1      DI:2
1654    *                        |
1655    *                   renderer5
1656    *                      DI:-1
1657    *
1658    *  actor0 has sibling order 1
1659    *  actor1 has sibling order 0
1660    *  actor2 has sibling order 0
1661    *
1662    *  renderer0 has depth index 2
1663    *  renderer1 has depth index 0
1664    *
1665    *  renderer2 has depth index 0
1666    *  renderer3 has depth index 1
1667    *  renderer4 has depth index 2
1668    *
1669    *  renderer5 has depth index -1
1670    *
1671    *  Expected rendering order: renderer2 - renderer3 - renderer4 - renderer1 - renderer0 - renderer5
1672    */
1673
1674   Shader shader = Shader::New("VertexSource", "FragmentSource");
1675   Geometry geometry = CreateQuadGeometry();
1676   Actor root = Stage::GetCurrent().GetRootLayer();
1677   Actor actor0 = CreateActor( root,   1, TEST_LOCATION );
1678   Actor actor1 = CreateActor( root,   0, TEST_LOCATION );
1679   Actor actor2 = CreateActor( actor0, 0, TEST_LOCATION );
1680
1681   Renderer renderer0 = CreateRenderer( actor0, geometry, shader, 2 );
1682   Renderer renderer1 = CreateRenderer( actor0, geometry, shader, 0 );
1683   Renderer renderer2 = CreateRenderer( actor1, geometry, shader, 0 );
1684   Renderer renderer3 = CreateRenderer( actor1, geometry, shader, 1 );
1685   Renderer renderer4 = CreateRenderer( actor1, geometry, shader, 2 );
1686   Renderer renderer5 = CreateRenderer( actor2, geometry, shader, -1 );
1687
1688   application.SendNotification();
1689   application.Render();
1690
1691   TestGlAbstraction& gl = application.GetGlAbstraction();
1692   gl.EnableTextureCallTrace(true);
1693   application.SendNotification();
1694   application.Render(0);
1695
1696   int textureBindIndex[6];
1697   for( unsigned int i(0); i<6; ++i )
1698   {
1699     std::stringstream params;
1700     params << GL_TEXTURE_2D<<", "<<i+1;
1701     textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str() );
1702   }
1703
1704   DALI_TEST_EQUALS( textureBindIndex[2], 0, TEST_LOCATION );
1705   DALI_TEST_EQUALS( textureBindIndex[3], 1, TEST_LOCATION );
1706   DALI_TEST_EQUALS( textureBindIndex[4], 2, TEST_LOCATION );
1707   DALI_TEST_EQUALS( textureBindIndex[1], 3, TEST_LOCATION );
1708   DALI_TEST_EQUALS( textureBindIndex[0], 4, TEST_LOCATION );
1709   DALI_TEST_EQUALS( textureBindIndex[5], 5, TEST_LOCATION );
1710
1711   // Change sibling order of actor1
1712   // New Expected rendering order: renderer1 - renderer0 - renderer 5 - renderer2 - renderer3 - renderer4
1713   actor1.SetProperty( Dali::DevelActor::Property::SIBLING_ORDER, 2 );
1714
1715   gl.GetTextureTrace().Reset();
1716   application.SendNotification();
1717   application.Render(0);
1718
1719   for( unsigned int i(0); i<6; ++i )
1720   {
1721     std::stringstream params;
1722     params << GL_TEXTURE_2D<<", "<<i+1;
1723     textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str() );
1724   }
1725
1726   DALI_TEST_EQUALS( textureBindIndex[1], 0, TEST_LOCATION );
1727   DALI_TEST_EQUALS( textureBindIndex[0], 1, TEST_LOCATION );
1728   DALI_TEST_EQUALS( textureBindIndex[5], 2, TEST_LOCATION );
1729   DALI_TEST_EQUALS( textureBindIndex[2], 3, TEST_LOCATION );
1730   DALI_TEST_EQUALS( textureBindIndex[3], 4, TEST_LOCATION );
1731   DALI_TEST_EQUALS( textureBindIndex[4], 5, TEST_LOCATION );
1732
1733   END_TEST;
1734 }
1735
1736 int UtcDaliRendererRenderOrder2DLayerOverlay(void)
1737 {
1738   TestApplication application;
1739   tet_infoline("Test the rendering order in a 2D layer is correct for overlays");
1740
1741   Shader shader = Shader::New("VertexSource", "FragmentSource");
1742   Geometry geometry = CreateQuadGeometry();
1743   Actor root = Stage::GetCurrent().GetRootLayer();
1744
1745   /*
1746    * Create the following hierarchy:
1747    *
1748    *               actor2
1749    *             (Regular actor)
1750    *              /      \
1751    *             /        \
1752    *         actor1       actor4
1753    *       (Overlay)     (Regular actor)
1754    *          /
1755    *         /
1756    *     actor0
1757    *    (Overlay)
1758    *      /
1759    *     /
1760    *  actor3
1761    * (Overlay)
1762    *
1763    *  Expected rendering order : actor2 - actor4 - actor1 - actor0 - actor3
1764    */
1765
1766   Actor actor0 = CreateActor( root, 0, TEST_LOCATION );
1767   actor0.SetDrawMode( DrawMode::OVERLAY_2D );
1768   Renderer renderer0 = CreateRenderer( actor0, geometry, shader, 0 );
1769
1770   Actor actor1 = CreateActor( root, 0, TEST_LOCATION );
1771   actor1.SetDrawMode( DrawMode::OVERLAY_2D );
1772   Renderer renderer1 = CreateRenderer( actor1, geometry, shader, 0 );
1773
1774   Actor actor2 = CreateActor( root, 0, TEST_LOCATION );
1775   Renderer renderer2 = CreateRenderer( actor2, geometry, shader, 0 );
1776
1777   Actor actor3 = CreateActor( root, 0, TEST_LOCATION );
1778   actor3.SetDrawMode( DrawMode::OVERLAY_2D );
1779   Renderer renderer3 = CreateRenderer( actor3, geometry, shader, 0 );
1780
1781   Actor actor4 = CreateActor( root, 0, TEST_LOCATION );
1782   Renderer renderer4 = CreateRenderer( actor4, geometry, shader, 0 );
1783
1784   application.SendNotification();
1785   application.Render(0);
1786
1787   actor2.Add(actor1);
1788   actor2.Add(actor4);
1789   actor1.Add(actor0);
1790   actor0.Add(actor3);
1791
1792   TestGlAbstraction& gl = application.GetGlAbstraction();
1793   gl.EnableTextureCallTrace(true);
1794   application.SendNotification();
1795   application.Render(0);
1796
1797   int textureBindIndex[5];
1798   for( unsigned int i(0); i<5; ++i )
1799   {
1800     std::stringstream params;
1801     params << GL_TEXTURE_2D<<", "<<i+1;
1802     textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str() );
1803   }
1804
1805   //Check that actor4 has been rendered after actor2
1806   DALI_TEST_GREATER( textureBindIndex[4], textureBindIndex[2], TEST_LOCATION );
1807
1808   //Check that actor1 has been rendered after actor4
1809   DALI_TEST_GREATER( textureBindIndex[1], textureBindIndex[4], TEST_LOCATION );
1810
1811   //Check that actor0 has been rendered after actor1
1812   DALI_TEST_GREATER( textureBindIndex[0], textureBindIndex[1], TEST_LOCATION );
1813
1814   //Check that actor3 has been rendered after actor0
1815   DALI_TEST_GREATER( textureBindIndex[3], textureBindIndex[0], TEST_LOCATION );
1816
1817   END_TEST;
1818 }
1819
1820 int UtcDaliRendererSetIndexRange(void)
1821 {
1822   std::string
1823       vertexShader(
1824         "attribute vec2 aPosition;\n"
1825         "void main()\n"
1826         "{\n"
1827         "  gl_Position = aPosition;\n"
1828         "}"
1829         ),
1830       fragmentShader(
1831         "void main()\n"
1832         "{\n"
1833         "  gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0)\n"
1834         "}\n"
1835         );
1836
1837   TestApplication application;
1838   tet_infoline("Test setting the range of indices to draw");
1839
1840   TestGlAbstraction& gl = application.GetGlAbstraction();
1841   gl.EnableDrawCallTrace( true );
1842
1843   Actor actor = Actor::New();
1844   actor.SetSize( 100, 100 );
1845
1846   // create geometry
1847   Geometry geometry = Geometry::New();
1848   geometry.SetType( Geometry::LINE_LOOP );
1849
1850   // --------------------------------------------------------------------------
1851   // index buffer
1852   unsigned short indices[] = { 0, 2, 4, 6, 8, // offset = 0, count = 5
1853                          0, 1, 2, 3, 4, 5, 6, 7, 8, 9, // offset = 5, count = 10
1854                          1, 3, 5, 7, 9, 1 }; // offset = 15,  count = 6 // line strip
1855
1856   // --------------------------------------------------------------------------
1857   // vertex buffer
1858   struct Vertex
1859   {
1860     Vector2 position;
1861   };
1862   Vertex shapes[] =
1863   {
1864     // pentagon                   // star
1865     { Vector2(  0.0f,   1.00f) }, { Vector2(  0.0f,  -1.00f) },
1866     { Vector2( -0.95f,  0.31f) }, { Vector2(  0.59f,  0.81f) },
1867     { Vector2( -0.59f, -0.81f) }, { Vector2( -0.95f, -0.31f) },
1868     { Vector2(  0.59f, -0.81f) }, { Vector2(  0.95f, -0.31f) },
1869     { Vector2(  0.95f,  0.31f) }, { Vector2( -0.59f,  0.81f) },
1870   };
1871   Property::Map vertexFormat;
1872   vertexFormat["aPosition"] = Property::VECTOR2;
1873   PropertyBuffer vertexBuffer = PropertyBuffer::New( vertexFormat );
1874   vertexBuffer.SetData( shapes, sizeof(shapes)/sizeof(shapes[0]));
1875
1876   // --------------------------------------------------------------------------
1877   geometry.SetIndexBuffer( indices, sizeof(indices)/sizeof(indices[0]) );
1878   geometry.AddVertexBuffer( vertexBuffer );
1879
1880   // create shader
1881   Shader shader = Shader::New( vertexShader,fragmentShader );
1882   Renderer renderer = Renderer::New( geometry, shader );
1883   actor.AddRenderer( renderer );
1884
1885   Stage stage = Stage::GetCurrent();
1886   stage.Add( actor );
1887
1888   char buffer[ 128 ];
1889
1890   // LINE_LOOP, first 0, count 5
1891   {
1892     renderer.SetIndexRange( 0, 5 );
1893     application.SendNotification();
1894     application.Render();
1895
1896     Property::Value value = renderer.GetProperty( Renderer::Property::INDEX_RANGE_FIRST );
1897     int convertedValue;
1898     DALI_TEST_CHECK( value.Get( convertedValue ) );
1899     DALI_TEST_CHECK( convertedValue == 0 );
1900
1901     value = renderer.GetCurrentProperty( Renderer::Property::INDEX_RANGE_FIRST );
1902     DALI_TEST_CHECK( value.Get( convertedValue ) );
1903     DALI_TEST_CHECK( convertedValue == 0 );
1904
1905     value = renderer.GetProperty( Renderer::Property::INDEX_RANGE_COUNT );
1906     DALI_TEST_CHECK( value.Get( convertedValue ) );
1907     DALI_TEST_CHECK( convertedValue == 5 );
1908
1909     value = renderer.GetCurrentProperty( Renderer::Property::INDEX_RANGE_COUNT );
1910     DALI_TEST_CHECK( value.Get( convertedValue ) );
1911     DALI_TEST_CHECK( convertedValue == 5 );
1912
1913     sprintf( buffer, "%u, 5, %u, indices", GL_LINE_LOOP, GL_UNSIGNED_SHORT );
1914     bool result = gl.GetDrawTrace().FindMethodAndParams( "DrawElements" , buffer );
1915     DALI_TEST_CHECK( result );
1916   }
1917
1918   // LINE_LOOP, first 5, count 10
1919   {
1920     renderer.SetIndexRange( 5, 10 );
1921     sprintf( buffer, "%u, 10, %u, indices", GL_LINE_LOOP, GL_UNSIGNED_SHORT );
1922     application.SendNotification();
1923     application.Render();
1924     bool result = gl.GetDrawTrace().FindMethodAndParams( "DrawElements" , buffer );
1925     DALI_TEST_CHECK( result );
1926   }
1927
1928   // LINE_STRIP, first 15, count 6
1929   {
1930     renderer.SetIndexRange( 15, 6 );
1931     geometry.SetType( Geometry::LINE_STRIP );
1932     sprintf( buffer, "%u, 6, %u, indices", GL_LINE_STRIP, GL_UNSIGNED_SHORT );
1933     application.SendNotification();
1934     application.Render();
1935     bool result = gl.GetDrawTrace().FindMethodAndParams( "DrawElements" , buffer );
1936     DALI_TEST_CHECK( result );
1937   }
1938
1939   // Index out of bounds
1940   {
1941     renderer.SetIndexRange( 15, 30 );
1942     geometry.SetType( Geometry::LINE_STRIP );
1943     sprintf( buffer, "%u, 6, %u, indices", GL_LINE_STRIP, GL_UNSIGNED_SHORT );
1944     application.SendNotification();
1945     application.Render();
1946     bool result = gl.GetDrawTrace().FindMethodAndParams( "DrawElements" , buffer );
1947     DALI_TEST_CHECK( result );
1948   }
1949
1950   // drawing whole buffer starting from 15 ( last valid primitive )
1951   {
1952     renderer.SetIndexRange( 15, 0 );
1953     geometry.SetType( Geometry::LINE_STRIP );
1954     sprintf( buffer, "%u, 6, %u, indices", GL_LINE_STRIP, GL_UNSIGNED_SHORT );
1955     application.SendNotification();
1956     application.Render();
1957     bool result = gl.GetDrawTrace().FindMethodAndParams( "DrawElements" , buffer );
1958     DALI_TEST_CHECK( result );
1959   }
1960
1961   END_TEST;
1962 }
1963
1964
1965 int UtcDaliRendererSetDepthFunction(void)
1966 {
1967   TestApplication application;
1968
1969   tet_infoline("Test setting the depth function");
1970
1971   Geometry geometry = CreateQuadGeometry();
1972   Shader shader = CreateShader();
1973   Renderer renderer = Renderer::New( geometry, shader );
1974
1975   Actor actor = Actor::New();
1976   actor.AddRenderer(renderer);
1977   actor.SetSize(400, 400);
1978   Stage stage = Stage::GetCurrent();
1979   stage.GetRootLayer().SetBehavior( Layer::LAYER_3D );
1980   stage.Add(actor);
1981
1982   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1983   glAbstraction.EnableEnableDisableCallTrace(true);
1984   glAbstraction.EnableDepthFunctionCallTrace(true);
1985
1986   TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
1987   TraceCallStack& glDepthFunctionStack = glAbstraction.GetDepthFunctionTrace();
1988
1989   std::ostringstream depthTestStr;
1990   depthTestStr << GL_DEPTH_TEST;
1991
1992   //GL_NEVER
1993   {
1994     renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::NEVER);
1995
1996     glEnableDisableStack.Reset();
1997     glDepthFunctionStack.Reset();
1998     application.SendNotification();
1999     application.Render();
2000
2001     DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Enable", depthTestStr.str().c_str() ) );
2002     std::ostringstream depthFunctionStr;
2003     depthFunctionStr << GL_NEVER;
2004     DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
2005   }
2006
2007   //GL_ALWAYS
2008   {
2009     renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::ALWAYS);
2010
2011     glDepthFunctionStack.Reset();
2012     application.SendNotification();
2013     application.Render();
2014
2015     std::ostringstream depthFunctionStr;
2016     depthFunctionStr << GL_ALWAYS;
2017     DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
2018   }
2019
2020   //GL_LESS
2021   {
2022     renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::LESS);
2023
2024     glDepthFunctionStack.Reset();
2025     application.SendNotification();
2026     application.Render();
2027
2028     std::ostringstream depthFunctionStr;
2029     depthFunctionStr << GL_LESS;
2030     DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
2031   }
2032
2033   //GL_GREATER
2034   {
2035     renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::GREATER);
2036
2037     glDepthFunctionStack.Reset();
2038     application.SendNotification();
2039     application.Render();
2040
2041     std::ostringstream depthFunctionStr;
2042     depthFunctionStr << GL_GREATER;
2043     DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
2044   }
2045
2046   //GL_EQUAL
2047   {
2048     renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::EQUAL);
2049
2050     glDepthFunctionStack.Reset();
2051     application.SendNotification();
2052     application.Render();
2053
2054     std::ostringstream depthFunctionStr;
2055     depthFunctionStr << GL_EQUAL;
2056     DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
2057   }
2058
2059   //GL_NOTEQUAL
2060   {
2061     renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::NOT_EQUAL);
2062
2063     glDepthFunctionStack.Reset();
2064     application.SendNotification();
2065     application.Render();
2066
2067     std::ostringstream depthFunctionStr;
2068     depthFunctionStr << GL_NOTEQUAL;
2069     DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
2070   }
2071
2072   //GL_LEQUAL
2073   {
2074     renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::LESS_EQUAL);
2075
2076     glDepthFunctionStack.Reset();
2077     application.SendNotification();
2078     application.Render();
2079
2080     std::ostringstream depthFunctionStr;
2081     depthFunctionStr << GL_LEQUAL;
2082     DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
2083   }
2084
2085   //GL_GEQUAL
2086   {
2087     renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::GREATER_EQUAL);
2088
2089     glDepthFunctionStack.Reset();
2090     application.SendNotification();
2091     application.Render();
2092
2093     std::ostringstream depthFunctionStr;
2094     depthFunctionStr << GL_GEQUAL;
2095     DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
2096   }
2097
2098   END_TEST;
2099 }
2100
2101 /**
2102  * @brief This templatized function checks an enumeration property is setting and getting correctly.
2103  * The checks performed are as follows:
2104  *  - Check the initial/default value.
2105  *  - Set a different value via enum.
2106  *  - Check it was set.
2107  *  - Set a different value via string.
2108  *  - Check it was set.
2109  */
2110 template< typename T >
2111 void CheckEnumerationProperty( TestApplication& application, Renderer& renderer, Property::Index propertyIndex, T initialValue, T firstCheckEnumeration, T secondCheckEnumeration, std::string secondCheckString )
2112 {
2113   application.SendNotification();
2114   application.Render();
2115
2116   DALI_TEST_CHECK( renderer.GetProperty<int>( propertyIndex ) == static_cast<int>( initialValue ) );
2117   DALI_TEST_CHECK( renderer.GetCurrentProperty< int >( propertyIndex ) == static_cast<int>( initialValue ) );
2118   renderer.SetProperty( propertyIndex, firstCheckEnumeration );
2119   DALI_TEST_CHECK( renderer.GetProperty<int>( propertyIndex ) == static_cast<int>( firstCheckEnumeration ) );
2120   DALI_TEST_CHECK( renderer.GetCurrentProperty< int >( propertyIndex ) != static_cast<int>( firstCheckEnumeration ) );
2121
2122   application.SendNotification();
2123   application.Render();
2124
2125   DALI_TEST_CHECK( renderer.GetProperty<int>( propertyIndex ) == static_cast<int>( firstCheckEnumeration ) );
2126   DALI_TEST_CHECK( renderer.GetCurrentProperty< int >( propertyIndex ) == static_cast<int>( firstCheckEnumeration ) );
2127
2128   renderer.SetProperty( propertyIndex, secondCheckString );
2129   DALI_TEST_CHECK( renderer.GetProperty<int>( propertyIndex ) == static_cast<int>( secondCheckEnumeration ) );
2130   DALI_TEST_CHECK( renderer.GetCurrentProperty< int >( propertyIndex ) != static_cast<int>( secondCheckEnumeration ) );
2131
2132   application.SendNotification();
2133   application.Render();
2134
2135   DALI_TEST_CHECK( renderer.GetProperty<int>( propertyIndex ) == static_cast<int>( secondCheckEnumeration ) );
2136   DALI_TEST_CHECK( renderer.GetCurrentProperty< int >( propertyIndex ) == static_cast<int>( secondCheckEnumeration ) );
2137 }
2138
2139 int UtcDaliRendererEnumProperties(void)
2140 {
2141   TestApplication application;
2142   tet_infoline( "Test Renderer enumeration properties can be set with both integer and string values" );
2143
2144   Geometry geometry = CreateQuadGeometry();
2145   Shader shader = CreateShader();
2146   Renderer renderer = Renderer::New( geometry, shader );
2147
2148   Actor actor = Actor::New();
2149   actor.AddRenderer(renderer);
2150   actor.SetSize(400, 400);
2151   Stage::GetCurrent().Add(actor);
2152
2153   /*
2154    * Here we use a templatized function to perform several checks on each enumeration property.
2155    * @see CheckEnumerationProperty for details of the checks performed.
2156    */
2157
2158   CheckEnumerationProperty< FaceCullingMode::Type >( application, renderer, Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::NONE, FaceCullingMode::FRONT, FaceCullingMode::BACK, "BACK" );
2159   CheckEnumerationProperty< BlendMode::Type >( application, renderer, Renderer::Property::BLEND_MODE, BlendMode::AUTO, BlendMode::OFF, BlendMode::ON, "ON" );
2160   CheckEnumerationProperty< BlendEquation::Type >( application, renderer, Renderer::Property::BLEND_EQUATION_RGB, BlendEquation::ADD, BlendEquation::SUBTRACT, BlendEquation::REVERSE_SUBTRACT, "REVERSE_SUBTRACT" );
2161   CheckEnumerationProperty< BlendEquation::Type >( application, renderer, Renderer::Property::BLEND_EQUATION_ALPHA, BlendEquation::ADD, BlendEquation::SUBTRACT, BlendEquation::REVERSE_SUBTRACT, "REVERSE_SUBTRACT" );
2162   CheckEnumerationProperty< BlendFactor::Type >( application, renderer, Renderer::Property::BLEND_FACTOR_SRC_RGB, BlendFactor::SRC_ALPHA, BlendFactor::ONE, BlendFactor::SRC_COLOR, "SRC_COLOR" );
2163   CheckEnumerationProperty< BlendFactor::Type >( application, renderer, Renderer::Property::BLEND_FACTOR_DEST_RGB, BlendFactor::ONE_MINUS_SRC_ALPHA, BlendFactor::ONE, BlendFactor::SRC_COLOR, "SRC_COLOR" );
2164   CheckEnumerationProperty< BlendFactor::Type >( application, renderer, Renderer::Property::BLEND_FACTOR_SRC_ALPHA, BlendFactor::ONE, BlendFactor::ONE_MINUS_SRC_ALPHA, BlendFactor::SRC_COLOR, "SRC_COLOR" );
2165   CheckEnumerationProperty< BlendFactor::Type >( application, renderer, Renderer::Property::BLEND_FACTOR_DEST_ALPHA, BlendFactor::ONE_MINUS_SRC_ALPHA, BlendFactor::ONE, BlendFactor::SRC_COLOR, "SRC_COLOR" );
2166   CheckEnumerationProperty< DepthWriteMode::Type >( application, renderer, Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::AUTO, DepthWriteMode::OFF, DepthWriteMode::ON, "ON" );
2167   CheckEnumerationProperty< DepthFunction::Type >( application, renderer, Renderer::Property::DEPTH_FUNCTION, DepthFunction::LESS, DepthFunction::ALWAYS, DepthFunction::GREATER, "GREATER" );
2168   CheckEnumerationProperty< DepthTestMode::Type >( application, renderer, Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::AUTO, DepthTestMode::OFF, DepthTestMode::ON, "ON" );
2169   CheckEnumerationProperty< StencilFunction::Type >( application, renderer, Renderer::Property::STENCIL_FUNCTION, StencilFunction::ALWAYS, StencilFunction::LESS, StencilFunction::EQUAL, "EQUAL" );
2170   CheckEnumerationProperty< RenderMode::Type >( application, renderer, Renderer::Property::RENDER_MODE, RenderMode::AUTO, RenderMode::NONE, RenderMode::STENCIL, "STENCIL" );
2171   CheckEnumerationProperty< StencilOperation::Type >( application, renderer, Renderer::Property::STENCIL_OPERATION_ON_FAIL, StencilOperation::KEEP, StencilOperation::REPLACE, StencilOperation::INCREMENT, "INCREMENT" );
2172   CheckEnumerationProperty< StencilOperation::Type >( application, renderer, Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, StencilOperation::KEEP, StencilOperation::REPLACE, StencilOperation::INCREMENT, "INCREMENT" );
2173   CheckEnumerationProperty< StencilOperation::Type >( application, renderer, Renderer::Property::STENCIL_OPERATION_ON_Z_PASS, StencilOperation::KEEP, StencilOperation::REPLACE, StencilOperation::INCREMENT, "INCREMENT" );
2174
2175   END_TEST;
2176 }
2177
2178 Renderer RendererTestFixture( TestApplication& application )
2179 {
2180   Geometry geometry = CreateQuadGeometry();
2181   Shader shader = CreateShader();
2182   Renderer renderer = Renderer::New( geometry, shader );
2183
2184   Actor actor = Actor::New();
2185   actor.AddRenderer( renderer );
2186   actor.SetSize( 400.0f, 400.0f );
2187   Stage stage = Stage::GetCurrent();
2188   stage.GetRootLayer().SetBehavior( Layer::LAYER_3D );
2189   stage.Add( actor );
2190
2191   return renderer;
2192 }
2193
2194 int UtcDaliRendererSetDepthTestMode(void)
2195 {
2196   TestApplication application;
2197   tet_infoline("Test setting the DepthTestMode");
2198
2199   Renderer renderer = RendererTestFixture( application );
2200   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2201   glAbstraction.EnableEnableDisableCallTrace( true );
2202   TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2203
2204   glEnableDisableStack.Reset();
2205   application.SendNotification();
2206   application.Render();
2207
2208   // Check depth-test is enabled by default.
2209   DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Enable", GetDepthTestString() ) );
2210   DALI_TEST_CHECK( !glEnableDisableStack.FindMethodAndParams( "Disable", GetDepthTestString() ) );
2211
2212   // 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.
2213   renderer.SetProperty( Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::OFF );
2214   renderer.SetProperty( Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::OFF );
2215
2216   glEnableDisableStack.Reset();
2217   application.SendNotification();
2218   application.Render();
2219
2220   // Check the depth buffer was disabled.
2221   DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Disable", GetDepthTestString() ) );
2222
2223   // Turn on automatic mode depth-testing.
2224   // Layer behavior is currently set to LAYER_3D so AUTO should enable depth-testing.
2225   renderer.SetProperty( Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::AUTO );
2226
2227   glEnableDisableStack.Reset();
2228   application.SendNotification();
2229   application.Render();
2230
2231   // Check depth-test is now enabled.
2232   DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Enable", GetDepthTestString() ) );
2233   DALI_TEST_CHECK( !glEnableDisableStack.FindMethodAndParams( "Disable", GetDepthTestString() ) );
2234
2235   // Change the layer behavior to LAYER_2D.
2236   // Note this will also disable depth testing for the layer by default, we test this first.
2237   Stage::GetCurrent().GetRootLayer().SetBehavior( Layer::LAYER_2D );
2238
2239   glEnableDisableStack.Reset();
2240   application.SendNotification();
2241   application.Render();
2242
2243   // Check depth-test is disabled.
2244   DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Disable", GetDepthTestString() ) );
2245
2246   // Turn the layer depth-test flag back on, and confirm that depth testing is now on.
2247   Stage::GetCurrent().GetRootLayer().SetDepthTestDisabled( false );
2248
2249   glEnableDisableStack.Reset();
2250   application.SendNotification();
2251   application.Render();
2252
2253   // Check depth-test is *still* disabled.
2254   DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Enable", GetDepthTestString() ) );
2255
2256   END_TEST;
2257 }
2258
2259 int UtcDaliRendererSetDepthWriteMode(void)
2260 {
2261   TestApplication application;
2262   tet_infoline("Test setting the DepthWriteMode");
2263
2264   Renderer renderer = RendererTestFixture( application );
2265   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2266
2267   application.SendNotification();
2268   application.Render();
2269
2270   // Check the default depth-write status first.
2271   DALI_TEST_CHECK( glAbstraction.GetLastDepthMask() );
2272
2273   // Turn off depth-writing.
2274   renderer.SetProperty( Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::OFF );
2275
2276   application.SendNotification();
2277   application.Render();
2278
2279   // Check depth-write is now disabled.
2280   DALI_TEST_CHECK( !glAbstraction.GetLastDepthMask() );
2281
2282   // Test the AUTO mode for depth-writing.
2283   // As our renderer is opaque, depth-testing should be enabled.
2284   renderer.SetProperty( Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::AUTO );
2285
2286   application.SendNotification();
2287   application.Render();
2288
2289   // Check depth-write is now enabled.
2290   DALI_TEST_CHECK( glAbstraction.GetLastDepthMask() );
2291
2292   // Now make the renderer be treated as translucent by enabling blending.
2293   // The AUTO depth-write mode should turn depth-write off in this scenario.
2294   renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::ON );
2295
2296   application.SendNotification();
2297   application.Render();
2298
2299   // Check depth-write is now disabled.
2300   DALI_TEST_CHECK( !glAbstraction.GetLastDepthMask() );
2301
2302   END_TEST;
2303 }
2304
2305 int UtcDaliRendererCheckStencilDefaults(void)
2306 {
2307   TestApplication application;
2308   tet_infoline("Test the stencil defaults");
2309
2310   Renderer renderer = RendererTestFixture( application );
2311   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2312   glAbstraction.EnableEnableDisableCallTrace( true );
2313   glAbstraction.EnableStencilFunctionCallTrace( true );
2314   TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2315   TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2316
2317   ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2318
2319   // Check the defaults:
2320   DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_FUNCTION ).Get<int>() ), static_cast<int>( StencilFunction::ALWAYS ), TEST_LOCATION );
2321   DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_FUNCTION_MASK ).Get<int>() ), 0xFF, TEST_LOCATION );
2322   DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_FUNCTION_REFERENCE ).Get<int>() ), 0x00, TEST_LOCATION );
2323   DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_MASK ).Get<int>() ), 0xFF, TEST_LOCATION );
2324   DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_OPERATION_ON_FAIL ).Get<int>() ), static_cast<int>( StencilOperation::KEEP ), TEST_LOCATION );
2325   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 );
2326   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 );
2327
2328   END_TEST;
2329 }
2330
2331 int UtcDaliRendererSetRenderModeToUseStencilBuffer(void)
2332 {
2333   TestApplication application;
2334   tet_infoline("Test setting the RenderMode to use the stencil buffer");
2335
2336   Renderer renderer = RendererTestFixture( application );
2337   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2338   glAbstraction.EnableEnableDisableCallTrace( true );
2339   glAbstraction.EnableStencilFunctionCallTrace( true );
2340   TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2341   TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2342
2343   // Set the StencilFunction to something other than the default, to confirm it is set as a property,
2344   // but NO GL call has been made while the RenderMode is set to not use the stencil buffer.
2345   renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::NONE );
2346   ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2347
2348   renderer.SetProperty( Renderer::Property::STENCIL_FUNCTION, StencilFunction::NEVER );
2349   DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_FUNCTION ).Get<int>() ), static_cast<int>( StencilFunction::NEVER ), TEST_LOCATION );
2350
2351   ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2352   std::string methodString( "StencilFunc" );
2353   DALI_TEST_CHECK( !glStencilFunctionStack.FindMethod( methodString ) );
2354
2355   // Test the other RenderModes that will not enable the stencil buffer.
2356   renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::AUTO );
2357   ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2358   DALI_TEST_CHECK( !glStencilFunctionStack.FindMethod( methodString ) );
2359
2360   renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::COLOR );
2361   ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2362   DALI_TEST_CHECK( !glStencilFunctionStack.FindMethod( methodString ) );
2363
2364   // Now set the RenderMode to modes that will use the stencil buffer, and check the StencilFunction has changed.
2365   renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::STENCIL );
2366   ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2367
2368   DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Enable", GetStencilTestString() ) );
2369   DALI_TEST_CHECK( glStencilFunctionStack.FindMethod( methodString ) );
2370
2371   // Test the COLOR_STENCIL RenderMode as it also enables the stencil buffer.
2372   // First set a mode to turn off the stencil buffer, so the enable is required.
2373   renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::COLOR );
2374   ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2375   renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::COLOR_STENCIL );
2376   // Set a different stencil function as the last one is cached.
2377   renderer.SetProperty( Renderer::Property::STENCIL_FUNCTION, StencilFunction::ALWAYS );
2378   ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2379
2380   DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Enable", GetStencilTestString() ) );
2381   DALI_TEST_CHECK( glStencilFunctionStack.FindMethod( methodString ) );
2382
2383   END_TEST;
2384 }
2385
2386 // Helper function for the SetRenderModeToUseColorBuffer test.
2387 void CheckRenderModeColorMask( TestApplication& application, Renderer& renderer, RenderMode::Type renderMode, bool expectedValue )
2388 {
2389   // Set the RenderMode property to a value that should not allow color buffer writes.
2390   renderer.SetProperty( Renderer::Property::RENDER_MODE, renderMode );
2391   application.SendNotification();
2392   application.Render();
2393
2394   // Check if ColorMask has been called, and that the values are correct.
2395   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2396   const TestGlAbstraction::ColorMaskParams& colorMaskParams( glAbstraction.GetColorMaskParams() );
2397
2398   DALI_TEST_EQUALS<bool>( colorMaskParams.red,   expectedValue, TEST_LOCATION );
2399   DALI_TEST_EQUALS<bool>( colorMaskParams.green, expectedValue, TEST_LOCATION );
2400   DALI_TEST_EQUALS<bool>( colorMaskParams.blue,  expectedValue, TEST_LOCATION );
2401   DALI_TEST_EQUALS<bool>( colorMaskParams.alpha, expectedValue, TEST_LOCATION );
2402 }
2403
2404 int UtcDaliRendererSetRenderModeToUseColorBuffer(void)
2405 {
2406   TestApplication application;
2407   tet_infoline("Test setting the RenderMode to use the color buffer");
2408
2409   Renderer renderer = RendererTestFixture( application );
2410
2411   // Set the RenderMode property to a value that should not allow color buffer writes.
2412   // Then check if ColorMask has been called, and that the values are correct.
2413   CheckRenderModeColorMask( application, renderer, RenderMode::AUTO, true );
2414   CheckRenderModeColorMask( application, renderer, RenderMode::NONE, false );
2415   CheckRenderModeColorMask( application, renderer, RenderMode::COLOR, true );
2416   CheckRenderModeColorMask( application, renderer, RenderMode::STENCIL, false );
2417   CheckRenderModeColorMask( application, renderer, RenderMode::COLOR_STENCIL, true );
2418
2419   END_TEST;
2420 }
2421
2422 int UtcDaliRendererSetStencilFunction(void)
2423 {
2424   TestApplication application;
2425   tet_infoline("Test setting the StencilFunction");
2426
2427   Renderer renderer = RendererTestFixture( application );
2428   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2429   glAbstraction.EnableEnableDisableCallTrace( true );
2430   glAbstraction.EnableStencilFunctionCallTrace( true );
2431   TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2432   TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2433
2434   // RenderMode must use the stencil for StencilFunction to operate.
2435   renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::STENCIL );
2436   ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2437
2438   /*
2439    * Lookup table for testing StencilFunction.
2440    * Note: This MUST be in the same order as the Dali::StencilFunction enum.
2441    */
2442   const int StencilFunctionLookupTable[] = {
2443       GL_NEVER,
2444       GL_LESS,
2445       GL_EQUAL,
2446       GL_LEQUAL,
2447       GL_GREATER,
2448       GL_NOTEQUAL,
2449       GL_GEQUAL,
2450       GL_ALWAYS
2451   }; const int StencilFunctionLookupTableCount = sizeof( StencilFunctionLookupTable ) / sizeof( StencilFunctionLookupTable[0] );
2452
2453   /*
2454    * Loop through all types of StencilFunction, checking:
2455    *  - The value is cached (set in event thread side)
2456    *  - Causes "glStencilFunc" to be called
2457    *  - Checks the correct parameters to "glStencilFunc" were used
2458    */
2459   std::string nonChangingParameters = "0, 255";
2460   std::string methodString( "StencilFunc" );
2461   for( int i = 0; i < StencilFunctionLookupTableCount; ++i )
2462   {
2463     // Set the property.
2464     renderer.SetProperty( Renderer::Property::STENCIL_FUNCTION, static_cast<Dali::StencilFunction::Type>( i ) );
2465
2466     // Check GetProperty returns the same value.
2467     DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_FUNCTION ).Get<int>() ), i, TEST_LOCATION );
2468
2469     // Reset the trace debug.
2470     ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2471
2472     // Check the function is called and the parameters are correct.
2473     std::stringstream parameterStream;
2474     parameterStream << StencilFunctionLookupTable[ i ] << ", " << nonChangingParameters;
2475
2476     DALI_TEST_CHECK( glStencilFunctionStack.FindMethodAndParams( methodString, parameterStream.str() ) );
2477   }
2478
2479   // Change the Function Reference only and check the behavior is correct:
2480   // 170 is 0xaa in hex / 10101010 in binary (every other bit set).
2481   int testValueReference = 170;
2482   renderer.SetProperty( Renderer::Property::STENCIL_FUNCTION_REFERENCE, testValueReference );
2483
2484   DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_FUNCTION_REFERENCE ).Get<int>() ), testValueReference, TEST_LOCATION );
2485
2486   ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2487
2488   DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetCurrentProperty( Renderer::Property::STENCIL_FUNCTION_REFERENCE ).Get<int>() ), testValueReference, TEST_LOCATION );
2489
2490   std::stringstream parameterStream;
2491   parameterStream << StencilFunctionLookupTable[ StencilOperation::DECREMENT_WRAP ] << ", " << testValueReference << ", 255";
2492
2493   DALI_TEST_CHECK( glStencilFunctionStack.FindMethodAndParams( methodString, parameterStream.str() ) );
2494
2495
2496   // Change the Function Mask only and check the behavior is correct:
2497   // 85 is 0x55 in hex / 01010101 in binary (every other bit set).
2498   int testValueMask = 85;
2499   renderer.SetProperty( Renderer::Property::STENCIL_FUNCTION_MASK, testValueMask );
2500
2501   DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_FUNCTION_MASK ).Get<int>() ), testValueMask, TEST_LOCATION );
2502
2503   ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2504
2505   DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetCurrentProperty( Renderer::Property::STENCIL_FUNCTION_MASK ).Get<int>() ), testValueMask, TEST_LOCATION );
2506
2507   // Clear the stringstream.
2508   parameterStream.str( std::string() );
2509   parameterStream << StencilFunctionLookupTable[ StencilOperation::DECREMENT_WRAP ] << ", " << testValueReference << ", " << testValueMask;
2510
2511   DALI_TEST_CHECK( glStencilFunctionStack.FindMethodAndParams( methodString, parameterStream.str() ) );
2512
2513   END_TEST;
2514 }
2515
2516 int UtcDaliRendererSetStencilOperation(void)
2517 {
2518   TestApplication application;
2519   tet_infoline("Test setting the StencilOperation");
2520
2521   Renderer renderer = RendererTestFixture( application );
2522   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2523   glAbstraction.EnableEnableDisableCallTrace( true );
2524   glAbstraction.EnableStencilFunctionCallTrace( true );
2525   TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2526   TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2527
2528   // RenderMode must use the stencil for StencilOperation to operate.
2529   renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::STENCIL );
2530
2531   /*
2532    * Lookup table for testing StencilOperation.
2533    * Note: This MUST be in the same order as the Dali::StencilOperation enum.
2534    */
2535   const int StencilOperationLookupTable[] = {
2536     GL_ZERO,
2537     GL_KEEP,
2538     GL_REPLACE,
2539     GL_INCR,
2540     GL_DECR,
2541     GL_INVERT,
2542     GL_INCR_WRAP,
2543     GL_DECR_WRAP
2544   }; const int StencilOperationLookupTableCount = sizeof( StencilOperationLookupTable ) / sizeof( StencilOperationLookupTable[0] );
2545
2546   // Set all 3 StencilOperation properties to a default.
2547   renderer.SetProperty( Renderer::Property::STENCIL_OPERATION_ON_FAIL, StencilOperation::KEEP );
2548   renderer.SetProperty( Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, StencilOperation::ZERO );
2549   renderer.SetProperty( Renderer::Property::STENCIL_OPERATION_ON_Z_PASS, StencilOperation::ZERO );
2550
2551   // Set our expected parameter list to the equivalent result.
2552   int parameters[] = { StencilOperationLookupTable[ StencilOperation::ZERO ], StencilOperationLookupTable[ StencilOperation::ZERO ], StencilOperationLookupTable[ StencilOperation::ZERO ] };
2553
2554   ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2555
2556   /*
2557    * Loop through all types of StencilOperation, checking:
2558    *  - The value is cached (set in event thread side)
2559    *  - Causes "glStencilFunc" to be called
2560    *  - Checks the correct parameters to "glStencilFunc" were used
2561    *  - Checks the above for all 3 parameter placements of StencilOperation ( OnFail, OnZFail, OnPass )
2562    */
2563   std::string methodString( "StencilOp" );
2564
2565   for( int i = 0; i < StencilOperationLookupTableCount; ++i )
2566   {
2567     for( int j = 0; j < StencilOperationLookupTableCount; ++j )
2568     {
2569       for( int k = 0; k < StencilOperationLookupTableCount; ++k )
2570       {
2571         // Set the property (outer loop causes all 3 different properties to be set separately).
2572         renderer.SetProperty( Renderer::Property::STENCIL_OPERATION_ON_FAIL, static_cast<Dali::StencilFunction::Type>( i ) );
2573         renderer.SetProperty( Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, static_cast<Dali::StencilFunction::Type>( j ) );
2574         renderer.SetProperty( Renderer::Property::STENCIL_OPERATION_ON_Z_PASS, static_cast<Dali::StencilFunction::Type>( k ) );
2575
2576         // Check GetProperty returns the same value.
2577         DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_OPERATION_ON_FAIL ).Get<int>() ), i, TEST_LOCATION );
2578         DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL ).Get<int>() ), j, TEST_LOCATION );
2579         DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_OPERATION_ON_Z_PASS ).Get<int>() ), k, TEST_LOCATION );
2580
2581         // Reset the trace debug.
2582         ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2583
2584         // Check the function is called and the parameters are correct.
2585         // Set the expected parameter value at its correct index (only)
2586         parameters[ 0u ] = StencilOperationLookupTable[ i ];
2587         parameters[ 1u ] = StencilOperationLookupTable[ j ];
2588         parameters[ 2u ] = StencilOperationLookupTable[ k ];
2589
2590         // Build the parameter list.
2591         std::stringstream parameterStream;
2592         for( int parameterBuild = 0; parameterBuild < 3; ++parameterBuild )
2593         {
2594           parameterStream << parameters[ parameterBuild ];
2595           // Comma-separate the parameters.
2596           if( parameterBuild < 2 )
2597           {
2598             parameterStream << ", ";
2599           }
2600         }
2601
2602         // Check the function was called and the parameters were correct.
2603         DALI_TEST_CHECK( glStencilFunctionStack.FindMethodAndParams( methodString, parameterStream.str() ) );
2604       }
2605     }
2606   }
2607
2608   END_TEST;
2609 }
2610
2611 int UtcDaliRendererSetStencilMask(void)
2612 {
2613   TestApplication application;
2614   tet_infoline("Test setting the StencilMask");
2615
2616   Renderer renderer = RendererTestFixture( application );
2617   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2618   glAbstraction.EnableEnableDisableCallTrace( true );
2619   glAbstraction.EnableStencilFunctionCallTrace( true );
2620   TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2621   TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2622
2623   // RenderMode must use the stencil for StencilMask to operate.
2624   renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::STENCIL );
2625
2626   // Set the StencilMask property to a value.
2627   renderer.SetProperty( Renderer::Property::STENCIL_MASK, 0x00 );
2628
2629   // Check GetProperty returns the same value.
2630   DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_MASK ).Get<int>() ), 0x00, TEST_LOCATION );
2631
2632   ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2633
2634   DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetCurrentProperty( Renderer::Property::STENCIL_MASK ).Get<int>() ), 0x00, TEST_LOCATION );
2635
2636   std::string methodString( "StencilMask" );
2637   std::string parameterString = "0";
2638
2639   // Check the function was called and the parameters were correct.
2640   DALI_TEST_CHECK( glStencilFunctionStack.FindMethodAndParams( methodString, parameterString ) );
2641
2642   // Set the StencilMask property to another value to ensure it has changed.
2643   renderer.SetProperty( Renderer::Property::STENCIL_MASK, 0xFF );
2644
2645   // Check GetProperty returns the same value.
2646   DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_MASK ).Get<int>() ), 0xFF, TEST_LOCATION );
2647
2648   ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2649
2650   DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetCurrentProperty( Renderer::Property::STENCIL_MASK ).Get<int>() ), 0xFF, TEST_LOCATION );
2651
2652   parameterString = "255";
2653
2654   // Check the function was called and the parameters were correct.
2655   DALI_TEST_CHECK( glStencilFunctionStack.FindMethodAndParams( methodString, parameterString ) );
2656
2657   END_TEST;
2658 }
2659
2660 int UtcDaliRendererWrongNumberOfTextures(void)
2661 {
2662   TestApplication application;
2663   tet_infoline("Test renderer does render even if number of textures is different than active samplers in the shader");
2664
2665   //Create a TextureSet with 4 textures (One more texture in the texture set than active samplers)
2666   //@note Shaders in the test suit have 3 active samplers. See TestGlAbstraction::GetActiveUniform()
2667   Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, 64u, 64u );
2668   TextureSet textureSet = CreateTextureSet();
2669   textureSet.SetTexture(0, texture );
2670   textureSet.SetTexture(1, texture );
2671   textureSet.SetTexture(2, texture );
2672   textureSet.SetTexture(3, texture );
2673   Shader shader = Shader::New("VertexSource", "FragmentSource");
2674   Geometry geometry = CreateQuadGeometry();
2675   Renderer renderer = Renderer::New( geometry, shader );
2676   renderer.SetTextures( textureSet );
2677
2678   Actor actor= Actor::New();
2679   actor.AddRenderer(renderer);
2680   actor.SetPosition(0.0f,0.0f);
2681   actor.SetSize(100, 100);
2682   Stage::GetCurrent().Add(actor);
2683
2684   TestGlAbstraction& gl = application.GetGlAbstraction();
2685   TraceCallStack& drawTrace = gl.GetDrawTrace();
2686   drawTrace.Reset();
2687   drawTrace.Enable(true);
2688
2689   application.SendNotification();
2690   application.Render(0);
2691
2692   //Test we do the drawcall when TextureSet has more textures than there are active samplers in the shader
2693   DALI_TEST_EQUALS( drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION );
2694
2695   //Create a TextureSet with 1 texture (two more active samplers than texture in the texture set)
2696   //@note Shaders in the test suit have 3 active samplers. See TestGlAbstraction::GetActiveUniform()
2697   textureSet = CreateTextureSet();
2698   renderer.SetTextures( textureSet );
2699   textureSet.SetTexture(0, texture );
2700   drawTrace.Reset();
2701   application.SendNotification();
2702   application.Render(0);
2703
2704   //Test we do the drawcall when TextureSet has less textures than there are active samplers in the shader.
2705   DALI_TEST_EQUALS( drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION );
2706
2707   END_TEST;
2708 }
2709
2710 int UtcDaliRendererOpacity(void)
2711 {
2712   TestApplication application;
2713
2714   tet_infoline( "Test OPACITY property" );
2715
2716   Geometry geometry = CreateQuadGeometry();
2717   Shader shader = Shader::New( "vertexSrc", "fragmentSrc" );
2718   Renderer renderer = Renderer::New( geometry, shader );
2719
2720   Actor actor = Actor::New();
2721   actor.AddRenderer( renderer );
2722   actor.SetSize( 400, 400 );
2723   actor.SetColor( Vector4( 1.0f, 0.0f, 1.0f, 1.0f ) );
2724   Stage::GetCurrent().Add( actor );
2725
2726   Property::Value value = renderer.GetProperty( DevelRenderer::Property::OPACITY );
2727   float opacity;
2728   DALI_TEST_CHECK( value.Get( opacity ) );
2729   DALI_TEST_EQUALS( opacity, 1.0f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION );
2730
2731   application.SendNotification();
2732   application.Render();
2733
2734   Vector4 actualValue;
2735   TestGlAbstraction& gl = application.GetGlAbstraction();
2736   DALI_TEST_CHECK( gl.GetUniformValue< Vector4 >( "uColor", actualValue ) );
2737   DALI_TEST_EQUALS( actualValue.a, 1.0f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION );
2738
2739   renderer.SetProperty( DevelRenderer::Property::OPACITY, 0.5f );
2740
2741   application.SendNotification();
2742   application.Render();
2743
2744   value = renderer.GetProperty( DevelRenderer::Property::OPACITY );
2745   DALI_TEST_CHECK( value.Get( opacity ) );
2746   DALI_TEST_EQUALS( opacity, 0.5f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION );
2747
2748   value = renderer.GetCurrentProperty( DevelRenderer::Property::OPACITY );
2749   DALI_TEST_CHECK( value.Get( opacity ) );
2750   DALI_TEST_EQUALS( opacity, 0.5f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION );
2751
2752   DALI_TEST_CHECK( gl.GetUniformValue< Vector4 >( "uColor", actualValue ) );
2753   DALI_TEST_EQUALS( actualValue.a, 0.5f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION );
2754
2755   END_TEST;
2756 }
2757
2758 int UtcDaliRendererOpacityAnimation(void)
2759 {
2760   TestApplication application;
2761
2762   tet_infoline( "Test OPACITY property animation" );
2763
2764   Geometry geometry = CreateQuadGeometry();
2765   Shader shader = Shader::New( "vertexSrc", "fragmentSrc" );
2766   Renderer renderer = Renderer::New( geometry, shader );
2767
2768   Actor actor = Actor::New();
2769   actor.AddRenderer( renderer );
2770   actor.SetSize( 400, 400 );
2771   actor.SetColor( Vector4( 1.0f, 0.0f, 1.0f, 1.0f ) );
2772   Stage::GetCurrent().Add( actor );
2773
2774   application.SendNotification();
2775   application.Render(0);
2776
2777   Property::Value value = renderer.GetProperty( DevelRenderer::Property::OPACITY );
2778   float opacity;
2779   DALI_TEST_CHECK( value.Get( opacity ) );
2780   DALI_TEST_EQUALS( opacity, 1.0f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION );
2781
2782   Animation animation = Animation::New( 1.0f );
2783   animation.AnimateTo( Property( renderer, DevelRenderer::Property::OPACITY ), 0.0f );
2784   animation.Play();
2785
2786   application.SendNotification();
2787   application.Render( 1000 );
2788
2789   value = renderer.GetProperty( DevelRenderer::Property::OPACITY );
2790   DALI_TEST_CHECK( value.Get( opacity ) );
2791   DALI_TEST_EQUALS( opacity, 0.0f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION );
2792
2793   renderer.SetProperty( DevelRenderer::Property::OPACITY, 0.1f );
2794
2795   animation.Clear();
2796   animation.AnimateBy( Property( renderer, DevelRenderer::Property::OPACITY ), 0.5f );
2797   animation.Play();
2798
2799   application.SendNotification();
2800   application.Render( 1000 );
2801
2802   value = renderer.GetProperty( DevelRenderer::Property::OPACITY );
2803   DALI_TEST_CHECK( value.Get( opacity ) );
2804   DALI_TEST_EQUALS( opacity, 0.6f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION );
2805
2806   END_TEST;
2807 }
2808
2809 int UtcDaliRendererInvalidProperty(void)
2810 {
2811   TestApplication application;
2812
2813   tet_infoline( "Test invalid property" );
2814
2815   Geometry geometry = CreateQuadGeometry();
2816   Shader shader = Shader::New( "vertexSrc", "fragmentSrc" );
2817   Renderer renderer = Renderer::New( geometry, shader );
2818
2819   Actor actor = Actor::New();
2820   actor.AddRenderer( renderer );
2821   actor.SetSize( 400, 400 );
2822   Stage::GetCurrent().Add( actor );
2823
2824   application.SendNotification();
2825   application.Render(0);
2826
2827   Property::Value value = renderer.GetProperty( Renderer::Property::DEPTH_INDEX + 100 );
2828   DALI_TEST_CHECK( value.GetType() == Property::Type::NONE );
2829
2830   value = renderer.GetCurrentProperty( Renderer::Property::DEPTH_INDEX + 100 );
2831   DALI_TEST_CHECK( value.GetType() == Property::Type::NONE );
2832
2833   END_TEST;
2834 }