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