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