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