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