[dali_2.3.25] Merge branch 'devel/master'
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-Renderer.cpp
1 /*
2  * Copyright (c) 2024 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 #define DEBUG_ENABLED 1
19
20 // EXTERNAL INCLUDES
21 #include <dali/devel-api/actors/actor-devel.h>
22 #include <dali/devel-api/common/capabilities.h>
23 #include <dali/devel-api/common/stage.h>
24 #include <dali/devel-api/rendering/renderer-devel.h>
25 #include <dali/integration-api/debug.h>
26 #include <dali/integration-api/render-task-list-integ.h>
27 #include <dali/public-api/dali-core.h>
28 #include <cstdio>
29 #include <string>
30
31 // INTERNAL INCLUDES
32 #include <dali-test-suite-utils.h>
33 #include <mesh-builder.h>
34 #include <test-trace-call-stack.h>
35 #include "test-actor-utils.h"
36 #include "test-graphics-command-buffer.h"
37
38 using namespace Dali;
39
40 namespace // unnamed namespace
41 {
42 const BlendFactor::Type DEFAULT_BLEND_FACTOR_SRC_RGB(BlendFactor::SRC_ALPHA);
43 const BlendFactor::Type DEFAULT_BLEND_FACTOR_DEST_RGB(BlendFactor::ONE_MINUS_SRC_ALPHA);
44 const BlendFactor::Type DEFAULT_BLEND_FACTOR_SRC_ALPHA(BlendFactor::ONE);
45 const BlendFactor::Type DEFAULT_BLEND_FACTOR_DEST_ALPHA(BlendFactor::ONE_MINUS_SRC_ALPHA);
46
47 const BlendEquation::Type DEFAULT_BLEND_EQUATION_RGB(BlendEquation::ADD);
48 const BlendEquation::Type DEFAULT_BLEND_EQUATION_ALPHA(BlendEquation::ADD);
49
50 /**
51  * @brief Get GL stencil test enumeration value as a string.
52  * @return The string representation of the value of GL_STENCIL_TEST
53  */
54 std::string GetStencilTestString(void)
55 {
56   std::stringstream stream;
57   stream << std::hex << GL_STENCIL_TEST;
58   return stream.str();
59 }
60
61 /**
62  * @brief Get GL depth test enumeration value as a string.
63  * @return The string representation of the value of GL_DEPTH_TEST
64  */
65 std::string GetDepthTestString(void)
66 {
67   std::stringstream stream;
68   stream << std::hex << GL_DEPTH_TEST;
69   return stream.str();
70 }
71
72 void ResetDebugAndFlush(TestApplication& application, TraceCallStack& glEnableDisableStack, TraceCallStack& glStencilFunctionStack)
73 {
74   glEnableDisableStack.Reset();
75   glStencilFunctionStack.Reset();
76   application.SendNotification();
77   application.Render();
78 }
79
80 void TestConstraintNoBlue(Vector4& current, const PropertyInputContainer& inputs)
81 {
82   current.b = 0.0f;
83 }
84
85 Renderer CreateRenderer(Actor actor, Geometry geometry, Shader shader, int depthIndex)
86 {
87   Texture    image0      = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGB888, 64, 64);
88   TextureSet textureSet0 = CreateTextureSet(image0);
89   Renderer   renderer0   = Renderer::New(geometry, shader);
90   renderer0.SetTextures(textureSet0);
91   renderer0.SetProperty(Renderer::Property::DEPTH_INDEX, depthIndex);
92   actor.AddRenderer(renderer0);
93   return renderer0;
94 }
95
96 Actor CreateActor(Actor parent, int siblingOrder, const char* location)
97 {
98   Actor actor = Actor::New();
99   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
100   actor.SetProperty(Actor::Property::PARENT_ORIGIN, AnchorPoint::CENTER);
101   actor.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 0.0f));
102   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
103   parent.Add(actor);
104   actor.SetProperty(Dali::DevelActor::Property::SIBLING_ORDER, siblingOrder);
105   DALI_TEST_EQUALS(actor.GetProperty<int>(Dali::DevelActor::Property::SIBLING_ORDER), siblingOrder, TEST_INNER_LOCATION(location));
106
107   return actor;
108 }
109
110 } // unnamed namespace
111
112 void renderer_test_startup(void)
113 {
114   test_return_value = TET_UNDEF;
115 }
116
117 void renderer_test_cleanup(void)
118 {
119   test_return_value = TET_PASS;
120 }
121
122 int UtcDaliRendererNew01(void)
123 {
124   TestApplication application;
125
126   Geometry geometry = CreateQuadGeometry();
127   Shader   shader   = CreateShader();
128   Renderer renderer = Renderer::New(geometry, shader);
129
130   DALI_TEST_EQUALS((bool)renderer, true, TEST_LOCATION);
131   END_TEST;
132 }
133
134 int UtcDaliRendererNew02(void)
135 {
136   TestApplication application;
137   Renderer        renderer;
138   DALI_TEST_EQUALS((bool)renderer, false, TEST_LOCATION);
139   END_TEST;
140 }
141
142 int UtcDaliRendererCopyConstructor(void)
143 {
144   TestApplication application;
145
146   Geometry geometry = CreateQuadGeometry();
147   Shader   shader   = CreateShader();
148   Renderer renderer = Renderer::New(geometry, shader);
149
150   Renderer rendererCopy(renderer);
151   DALI_TEST_EQUALS((bool)rendererCopy, true, TEST_LOCATION);
152
153   END_TEST;
154 }
155
156 int UtcDaliRendererAssignmentOperator(void)
157 {
158   TestApplication application;
159
160   Geometry geometry = CreateQuadGeometry();
161   Shader   shader   = CreateShader();
162   Renderer renderer = Renderer::New(geometry, shader);
163
164   Renderer renderer2;
165   DALI_TEST_EQUALS((bool)renderer2, false, TEST_LOCATION);
166
167   renderer2 = renderer;
168   DALI_TEST_EQUALS((bool)renderer2, true, TEST_LOCATION);
169   END_TEST;
170 }
171
172 int UtcDaliRendererMoveConstructor(void)
173 {
174   TestApplication application;
175
176   Geometry geometry = CreateQuadGeometry();
177   Shader   shader   = Shader::New("vertexSrc", "fragmentSrc");
178   Renderer renderer = Renderer::New(geometry, shader);
179   DALI_TEST_CHECK(renderer);
180   DALI_TEST_EQUALS(1, renderer.GetBaseObject().ReferenceCount(), TEST_LOCATION);
181   DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::TRANSPARENT, TEST_LOCATION);
182
183   renderer.SetProperty(Renderer::Property::BLEND_COLOR, Color::MAGENTA);
184   application.SendNotification();
185   application.Render();
186   DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::MAGENTA, TEST_LOCATION);
187
188   Renderer move = std::move(renderer);
189   DALI_TEST_CHECK(move);
190   DALI_TEST_EQUALS(1, move.GetBaseObject().ReferenceCount(), TEST_LOCATION);
191   DALI_TEST_EQUALS(move.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::MAGENTA, TEST_LOCATION);
192   DALI_TEST_CHECK(!renderer);
193
194   END_TEST;
195 }
196
197 int UtcDaliRendererMoveAssignment(void)
198 {
199   TestApplication application;
200
201   Geometry geometry = CreateQuadGeometry();
202   Shader   shader   = Shader::New("vertexSrc", "fragmentSrc");
203   Renderer renderer = Renderer::New(geometry, shader);
204   DALI_TEST_CHECK(renderer);
205   DALI_TEST_EQUALS(1, renderer.GetBaseObject().ReferenceCount(), TEST_LOCATION);
206   DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::TRANSPARENT, TEST_LOCATION);
207
208   renderer.SetProperty(Renderer::Property::BLEND_COLOR, Color::MAGENTA);
209   application.SendNotification();
210   application.Render();
211   DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::MAGENTA, TEST_LOCATION);
212
213   Renderer move;
214   move = std::move(renderer);
215   DALI_TEST_CHECK(move);
216   DALI_TEST_EQUALS(1, move.GetBaseObject().ReferenceCount(), TEST_LOCATION);
217   DALI_TEST_EQUALS(move.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::MAGENTA, TEST_LOCATION);
218   DALI_TEST_CHECK(!renderer);
219
220   END_TEST;
221 }
222
223 int UtcDaliRendererDownCast01(void)
224 {
225   TestApplication application;
226
227   Geometry geometry = CreateQuadGeometry();
228   Shader   shader   = CreateShader();
229   Renderer renderer = Renderer::New(geometry, shader);
230
231   BaseHandle handle(renderer);
232   Renderer   renderer2 = Renderer::DownCast(handle);
233   DALI_TEST_EQUALS((bool)renderer2, true, TEST_LOCATION);
234   END_TEST;
235 }
236
237 int UtcDaliRendererDownCast02(void)
238 {
239   TestApplication application;
240
241   Handle   handle   = Handle::New(); // Create a custom object
242   Renderer renderer = Renderer::DownCast(handle);
243   DALI_TEST_EQUALS((bool)renderer, false, TEST_LOCATION);
244   END_TEST;
245 }
246
247 // using a template to auto deduce the parameter types
248 template<typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8>
249 void TEST_RENDERER_PROPERTY(P1 renderer, P2 stringName, P3 type, P4 isWriteable, P5 isAnimateable, P6 isConstraintInput, P7 enumName, P8 LOCATION)
250 {
251   DALI_TEST_EQUALS(renderer.GetPropertyName(enumName), stringName, LOCATION);
252   DALI_TEST_EQUALS(renderer.GetPropertyIndex(stringName), static_cast<Property::Index>(enumName), LOCATION);
253   DALI_TEST_EQUALS(renderer.GetPropertyType(enumName), type, LOCATION);
254   DALI_TEST_EQUALS(renderer.IsPropertyWritable(enumName), isWriteable, LOCATION);
255   DALI_TEST_EQUALS(renderer.IsPropertyAnimatable(enumName), isAnimateable, LOCATION);
256   DALI_TEST_EQUALS(renderer.IsPropertyAConstraintInput(enumName), isConstraintInput, LOCATION);
257 }
258
259 int UtcDaliRendererDefaultProperties(void)
260 {
261   TestApplication application;
262   /* from renderer-impl.cpp
263   DALI_PROPERTY( "depthIndex",                      INTEGER,   true, false,  false, Dali::Renderer::Property::DEPTH_INDEX )
264   DALI_PROPERTY( "faceCullingMode",                 INTEGER,   true, false,  false, Dali::Renderer::Property::FACE_CULLING_MODE )
265   DALI_PROPERTY( "blendMode",                       INTEGER,   true, false,  false, Dali::Renderer::Property::BLEND_MODE )
266   DALI_PROPERTY( "blendEquationRgb",                INTEGER,   true, false,  false, Dali::Renderer::Property::BLEND_EQUATION_RGB )
267   DALI_PROPERTY( "blendEquationAlpha",              INTEGER,   true, false,  false, Dali::Renderer::Property::BLEND_EQUATION_ALPHA )
268   DALI_PROPERTY( "blendFactorSrcRgb",               INTEGER,   true, false,  false, Dali::Renderer::Property::BLEND_FACTOR_SRC_RGB )
269   DALI_PROPERTY( "blendFactorDestRgb",              INTEGER,   true, false,  false, Dali::Renderer::Property::BLEND_FACTOR_DEST_RGB )
270   DALI_PROPERTY( "blendFactorSrcAlpha",             INTEGER,   true, false,  false, Dali::Renderer::Property::BLEND_FACTOR_SRC_ALPHA )
271   DALI_PROPERTY( "blendFactorDestAlpha",            INTEGER,   true, false,  false, Dali::Renderer::Property::BLEND_FACTOR_DEST_ALPHA )
272   DALI_PROPERTY( "blendColor",                      VECTOR4,   true, false,  false, Dali::Renderer::Property::BLEND_COLOR )
273   DALI_PROPERTY( "blendPreMultipliedAlpha",         BOOLEAN,   true, false,  false, Dali::Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA )
274   DALI_PROPERTY( "indexRangeFirst",                 INTEGER,   true, false,  false, Dali::Renderer::Property::INDEX_RANGE_FIRST )
275   DALI_PROPERTY( "indexRangeCount",                 INTEGER,   true, false,  false, Dali::Renderer::Property::INDEX_RANGE_COUNT )
276   DALI_PROPERTY( "depthWriteMode",                  INTEGER,   true, false,  false, Dali::Renderer::Property::DEPTH_WRITE_MODE )
277   DALI_PROPERTY( "depthFunction",                   INTEGER,   true, false,  false, Dali::Renderer::Property::DEPTH_FUNCTION )
278   DALI_PROPERTY( "depthTestMode",                   INTEGER,   true, false,  false, Dali::Renderer::Property::DEPTH_TEST_MODE )
279   DALI_PROPERTY( "renderMode",                      INTEGER,   true, false,  false, Dali::Renderer::Property::RENDER_MODE )
280   DALI_PROPERTY( "stencilFunction",                 INTEGER,   true, false,  false, Dali::Renderer::Property::STENCIL_FUNCTION )
281   DALI_PROPERTY( "stencilFunctionMask",             INTEGER,   true, false,  false, Dali::Renderer::Property::STENCIL_FUNCTION_MASK )
282   DALI_PROPERTY( "stencilFunctionReference",        INTEGER,   true, false,  false, Dali::Renderer::Property::STENCIL_FUNCTION_REFERENCE )
283   DALI_PROPERTY( "stencilMask",                     INTEGER,   true, false,  false, Dali::Renderer::Property::STENCIL_MASK )
284   DALI_PROPERTY( "stencilOperationOnFail",          INTEGER,   true, false,  false, Dali::Renderer::Property::STENCIL_OPERATION_ON_FAIL )
285   DALI_PROPERTY( "stencilOperationOnZFail",         INTEGER,   true, false,  false, Dali::Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL )
286   DALI_PROPERTY( "stencilOperationOnZPass",         INTEGER,   true, false,  false, Dali::Renderer::Property::STENCIL_OPERATION_ON_Z_PASS )
287   DALI_PROPERTY( "opacity",                         FLOAT,     true, true,   true,  Dali::DevelRenderer::Property::OPACITY )
288   DALI_PROPERTY( "renderingBehavior",               INTEGER,   true, false,  false, Dali::DevelRenderer::Property::RENDERING_BEHAVIOR )
289   DALI_PROPERTY( "blendEquation",                   INTEGER,   true, false,  false, Dali::DevelRenderer::Property::BLEND_EQUATION )
290 */
291
292   Geometry geometry = CreateQuadGeometry();
293   Shader   shader   = CreateShader();
294   Renderer renderer = Renderer::New(geometry, shader);
295   DALI_TEST_EQUALS(renderer.GetPropertyCount(), 28, TEST_LOCATION);
296
297   TEST_RENDERER_PROPERTY(renderer, "depthIndex", Property::INTEGER, true, false, false, Renderer::Property::DEPTH_INDEX, TEST_LOCATION);
298   TEST_RENDERER_PROPERTY(renderer, "faceCullingMode", Property::INTEGER, true, false, false, Renderer::Property::FACE_CULLING_MODE, TEST_LOCATION);
299   TEST_RENDERER_PROPERTY(renderer, "blendMode", Property::INTEGER, true, false, false, Renderer::Property::BLEND_MODE, TEST_LOCATION);
300   TEST_RENDERER_PROPERTY(renderer, "blendEquationRgb", Property::INTEGER, true, false, false, Renderer::Property::BLEND_EQUATION_RGB, TEST_LOCATION);
301   TEST_RENDERER_PROPERTY(renderer, "blendEquationAlpha", Property::INTEGER, true, false, false, Renderer::Property::BLEND_EQUATION_ALPHA, TEST_LOCATION);
302   TEST_RENDERER_PROPERTY(renderer, "blendFactorSrcRgb", Property::INTEGER, true, false, false, Renderer::Property::BLEND_FACTOR_SRC_RGB, TEST_LOCATION);
303   TEST_RENDERER_PROPERTY(renderer, "blendFactorDestRgb", Property::INTEGER, true, false, false, Renderer::Property::BLEND_FACTOR_DEST_RGB, TEST_LOCATION);
304   TEST_RENDERER_PROPERTY(renderer, "blendFactorSrcAlpha", Property::INTEGER, true, false, false, Renderer::Property::BLEND_FACTOR_SRC_ALPHA, TEST_LOCATION);
305   TEST_RENDERER_PROPERTY(renderer, "blendFactorDestAlpha", Property::INTEGER, true, false, false, Renderer::Property::BLEND_FACTOR_DEST_ALPHA, TEST_LOCATION);
306   TEST_RENDERER_PROPERTY(renderer, "blendColor", Property::VECTOR4, true, false, false, Renderer::Property::BLEND_COLOR, TEST_LOCATION);
307   TEST_RENDERER_PROPERTY(renderer, "blendPreMultipliedAlpha", Property::BOOLEAN, true, false, false, Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, TEST_LOCATION);
308   TEST_RENDERER_PROPERTY(renderer, "indexRangeFirst", Property::INTEGER, true, false, false, Renderer::Property::INDEX_RANGE_FIRST, TEST_LOCATION);
309   TEST_RENDERER_PROPERTY(renderer, "indexRangeCount", Property::INTEGER, true, false, false, Renderer::Property::INDEX_RANGE_COUNT, TEST_LOCATION);
310   TEST_RENDERER_PROPERTY(renderer, "depthWriteMode", Property::INTEGER, true, false, false, Renderer::Property::DEPTH_WRITE_MODE, TEST_LOCATION);
311   TEST_RENDERER_PROPERTY(renderer, "depthFunction", Property::INTEGER, true, false, false, Renderer::Property::DEPTH_FUNCTION, TEST_LOCATION);
312   TEST_RENDERER_PROPERTY(renderer, "depthTestMode", Property::INTEGER, true, false, false, Renderer::Property::DEPTH_TEST_MODE, TEST_LOCATION);
313   TEST_RENDERER_PROPERTY(renderer, "renderMode", Property::INTEGER, true, false, false, Renderer::Property::RENDER_MODE, TEST_LOCATION);
314   TEST_RENDERER_PROPERTY(renderer, "stencilFunction", Property::INTEGER, true, false, false, Renderer::Property::STENCIL_FUNCTION, TEST_LOCATION);
315   TEST_RENDERER_PROPERTY(renderer, "stencilFunctionMask", Property::INTEGER, true, false, false, Renderer::Property::STENCIL_FUNCTION_MASK, TEST_LOCATION);
316   TEST_RENDERER_PROPERTY(renderer, "stencilFunctionReference", Property::INTEGER, true, false, false, Renderer::Property::STENCIL_FUNCTION_REFERENCE, TEST_LOCATION);
317   TEST_RENDERER_PROPERTY(renderer, "stencilMask", Property::INTEGER, true, false, false, Renderer::Property::STENCIL_MASK, TEST_LOCATION);
318   TEST_RENDERER_PROPERTY(renderer, "stencilOperationOnFail", Property::INTEGER, true, false, false, Renderer::Property::STENCIL_OPERATION_ON_FAIL, TEST_LOCATION);
319   TEST_RENDERER_PROPERTY(renderer, "stencilOperationOnZFail", Property::INTEGER, true, false, false, Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, TEST_LOCATION);
320   TEST_RENDERER_PROPERTY(renderer, "stencilOperationOnZPass", Property::INTEGER, true, false, false, Renderer::Property::STENCIL_OPERATION_ON_Z_PASS, TEST_LOCATION);
321   TEST_RENDERER_PROPERTY(renderer, "opacity", Property::FLOAT, true, true, true, DevelRenderer::Property::OPACITY, TEST_LOCATION);
322   TEST_RENDERER_PROPERTY(renderer, "renderingBehavior", Property::INTEGER, true, false, false, DevelRenderer::Property::RENDERING_BEHAVIOR, TEST_LOCATION);
323   TEST_RENDERER_PROPERTY(renderer, "blendEquation", Property::INTEGER, true, false, false, DevelRenderer::Property::BLEND_EQUATION, TEST_LOCATION);
324   TEST_RENDERER_PROPERTY(renderer, "instanceCount", Property::INTEGER, true, false, false, Dali::DevelRenderer::Property::INSTANCE_COUNT, TEST_LOCATION);
325
326   END_TEST;
327 }
328
329 int UtcDaliRendererSetGetGeometry(void)
330 {
331   TestApplication application;
332   tet_infoline("Test SetGeometry, GetGeometry");
333
334   Geometry geometry1 = CreateQuadGeometry();
335   Geometry geometry2 = CreateQuadGeometry();
336
337   Shader   shader   = CreateShader();
338   Renderer renderer = Renderer::New(geometry1, shader);
339   Actor    actor    = Actor::New();
340   actor.AddRenderer(renderer);
341   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
342   application.GetScene().Add(actor);
343
344   application.SendNotification();
345   application.Render(0);
346   DALI_TEST_EQUALS(renderer.GetGeometry(), geometry1, TEST_LOCATION);
347
348   // Set geometry2 to the renderer
349   renderer.SetGeometry(geometry2);
350
351   application.SendNotification();
352   application.Render(0);
353   DALI_TEST_EQUALS(renderer.GetGeometry(), geometry2, TEST_LOCATION);
354
355   END_TEST;
356 }
357
358 int UtcDaliRendererSetGetShader(void)
359 {
360   TestApplication application;
361   tet_infoline("Test SetShader, GetShader");
362
363   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
364   glAbstraction.EnableCullFaceCallTrace(true);
365
366   Shader shader1 = CreateShader();
367   shader1.RegisterProperty("uFadeColor", Color::RED);
368
369   Shader shader2 = CreateShader();
370   shader2.RegisterProperty("uFadeColor", Color::GREEN);
371
372   Geometry geometry = CreateQuadGeometry();
373   Renderer renderer = Renderer::New(geometry, shader1);
374   Actor    actor    = Actor::New();
375   actor.AddRenderer(renderer);
376   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
377   application.GetScene().Add(actor);
378
379   TestGlAbstraction& gl = application.GetGlAbstraction();
380   application.SendNotification();
381   application.Render(0);
382
383   // Expect that the first shaders's fade color property is accessed
384   Vector4 actualValue(Vector4::ZERO);
385   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
386   DALI_TEST_EQUALS(actualValue, Color::RED, TEST_LOCATION);
387
388   DALI_TEST_EQUALS(renderer.GetShader(), shader1, TEST_LOCATION);
389
390   // set the second shader to the renderer
391   renderer.SetShader(shader2);
392
393   application.SendNotification();
394   application.Render(0);
395
396   // Expect that the second shader's fade color property is accessed
397   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
398   DALI_TEST_EQUALS(actualValue, Color::GREEN, TEST_LOCATION);
399
400   DALI_TEST_EQUALS(renderer.GetShader(), shader2, TEST_LOCATION);
401
402   END_TEST;
403 }
404
405 int UtcDaliRendererSetGetDepthIndex(void)
406 {
407   TestApplication application;
408
409   tet_infoline("Test SetDepthIndex, GetDepthIndex");
410
411   Shader   shader   = CreateShader();
412   Geometry geometry = CreateQuadGeometry();
413   Renderer renderer = Renderer::New(geometry, shader);
414   Actor    actor    = Actor::New();
415   actor.AddRenderer(renderer);
416   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
417   application.GetScene().Add(actor);
418
419   application.SendNotification();
420   application.Render(0);
421   DALI_TEST_EQUALS(renderer.GetProperty<int>(Renderer::Property::DEPTH_INDEX), 0, TEST_LOCATION);
422
423   renderer.SetProperty(Renderer::Property::DEPTH_INDEX, 1);
424
425   DALI_TEST_EQUALS(renderer.GetProperty<int>(Renderer::Property::DEPTH_INDEX), 1, TEST_LOCATION);
426   DALI_TEST_EQUALS(renderer.GetCurrentProperty<int>(Renderer::Property::DEPTH_INDEX), 0, TEST_LOCATION);
427
428   application.SendNotification();
429   application.Render(0);
430   DALI_TEST_EQUALS(renderer.GetCurrentProperty<int>(Renderer::Property::DEPTH_INDEX), 1, TEST_LOCATION);
431
432   renderer.SetProperty(Renderer::Property::DEPTH_INDEX, 10);
433
434   DALI_TEST_EQUALS(renderer.GetProperty<int>(Renderer::Property::DEPTH_INDEX), 10, TEST_LOCATION);
435   DALI_TEST_EQUALS(renderer.GetCurrentProperty<int>(Renderer::Property::DEPTH_INDEX), 1, TEST_LOCATION);
436
437   application.SendNotification();
438   application.Render(0);
439   DALI_TEST_EQUALS(renderer.GetCurrentProperty<int>(Renderer::Property::DEPTH_INDEX), 10, TEST_LOCATION);
440
441   END_TEST;
442 }
443
444 int UtcDaliRendererSetGetFaceCullingMode(void)
445 {
446   TestApplication application;
447
448   tet_infoline("Test SetFaceCullingMode(cullingMode)");
449   Geometry geometry = CreateQuadGeometry();
450   Shader   shader   = CreateShader();
451   Renderer renderer = Renderer::New(geometry, shader);
452
453   Actor actor = Actor::New();
454   actor.AddRenderer(renderer);
455   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
456   application.GetScene().Add(actor);
457
458   // By default, none of the faces should be culled
459   unsigned int cullFace = renderer.GetProperty<int>(Renderer::Property::FACE_CULLING_MODE);
460   DALI_TEST_CHECK(static_cast<FaceCullingMode::Type>(cullFace) == FaceCullingMode::NONE);
461
462   TestGlAbstraction& gl            = application.GetGlAbstraction();
463   TraceCallStack&    cullFaceStack = gl.GetCullFaceTrace();
464   gl.EnableCullFaceCallTrace(true);
465
466   {
467     cullFaceStack.Reset();
468     renderer.SetProperty(Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::FRONT_AND_BACK);
469     application.SendNotification();
470     application.Render();
471
472     DALI_TEST_EQUALS(cullFaceStack.CountMethod("CullFace"), 1, TEST_LOCATION);
473
474     std::ostringstream cullModeString;
475     cullModeString << std::hex << GL_FRONT_AND_BACK;
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_AND_BACK);
480   }
481
482   {
483     cullFaceStack.Reset();
484     renderer.SetProperty(Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::BACK);
485     application.SendNotification();
486     application.Render();
487
488     DALI_TEST_EQUALS(cullFaceStack.CountMethod("CullFace"), 1, TEST_LOCATION);
489
490     std::ostringstream cullModeString;
491     cullModeString << std::hex << GL_BACK;
492
493     DALI_TEST_CHECK(cullFaceStack.FindMethodAndParams("CullFace", cullModeString.str()));
494     cullFace = renderer.GetProperty<int>(Renderer::Property::FACE_CULLING_MODE);
495     DALI_TEST_CHECK(static_cast<FaceCullingMode::Type>(cullFace) == FaceCullingMode::BACK);
496   }
497
498   {
499     cullFaceStack.Reset();
500     renderer.SetProperty(Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::FRONT);
501     application.SendNotification();
502     application.Render();
503
504     DALI_TEST_EQUALS(cullFaceStack.CountMethod("CullFace"), 1, TEST_LOCATION);
505
506     std::ostringstream cullModeString;
507     cullModeString << std::hex << GL_FRONT;
508
509     DALI_TEST_CHECK(cullFaceStack.FindMethodAndParams("CullFace", cullModeString.str()));
510     cullFace = renderer.GetProperty<int>(Renderer::Property::FACE_CULLING_MODE);
511     DALI_TEST_CHECK(static_cast<FaceCullingMode::Type>(cullFace) == FaceCullingMode::FRONT);
512   }
513
514   {
515     cullFaceStack.Reset();
516     renderer.SetProperty(Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::NONE);
517     application.SendNotification();
518     application.Render();
519
520     DALI_TEST_EQUALS(cullFaceStack.CountMethod("CullFace"), 0, TEST_LOCATION);
521     cullFace = renderer.GetProperty<int>(Renderer::Property::FACE_CULLING_MODE);
522     DALI_TEST_CHECK(static_cast<FaceCullingMode::Type>(cullFace) == FaceCullingMode::NONE);
523   }
524
525   END_TEST;
526 }
527
528 int UtcDaliRendererBlendOptions01(void)
529 {
530   TestApplication application;
531
532   tet_infoline("Test BLEND_FACTOR properties ");
533
534   Geometry geometry = CreateQuadGeometry();
535   Shader   shader   = CreateShader();
536   Renderer renderer = Renderer::New(geometry, shader);
537
538   Actor actor = Actor::New();
539   // set a transparent actor color so that blending is enabled
540   actor.SetProperty(Actor::Property::OPACITY, 0.5f);
541   actor.AddRenderer(renderer);
542   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
543   application.GetScene().Add(actor);
544
545   renderer.SetProperty(Renderer::Property::BLEND_FACTOR_SRC_RGB, BlendFactor::ONE_MINUS_SRC_COLOR);
546   renderer.SetProperty(Renderer::Property::BLEND_FACTOR_DEST_RGB, BlendFactor::SRC_ALPHA_SATURATE);
547   renderer.SetProperty(Renderer::Property::BLEND_FACTOR_SRC_ALPHA, BlendFactor::ONE_MINUS_SRC_COLOR);
548   renderer.SetProperty(Renderer::Property::BLEND_FACTOR_DEST_ALPHA, BlendFactor::SRC_ALPHA_SATURATE);
549
550   // Test that Set was successful:
551   int srcFactorRgb    = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
552   int destFactorRgb   = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
553   int srcFactorAlpha  = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
554   int destFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
555
556   DALI_TEST_EQUALS((int)BlendFactor::ONE_MINUS_SRC_COLOR, srcFactorRgb, TEST_LOCATION);
557   DALI_TEST_EQUALS((int)BlendFactor::SRC_ALPHA_SATURATE, destFactorRgb, TEST_LOCATION);
558   DALI_TEST_EQUALS((int)BlendFactor::ONE_MINUS_SRC_COLOR, srcFactorAlpha, TEST_LOCATION);
559   DALI_TEST_EQUALS((int)BlendFactor::SRC_ALPHA_SATURATE, destFactorAlpha, TEST_LOCATION);
560
561   application.SendNotification();
562   application.Render();
563
564   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
565
566   DALI_TEST_EQUALS((GLenum)GL_ONE_MINUS_SRC_COLOR, glAbstraction.GetLastBlendFuncSrcRgb(), TEST_LOCATION);
567   DALI_TEST_EQUALS((GLenum)GL_SRC_ALPHA_SATURATE, glAbstraction.GetLastBlendFuncDstRgb(), TEST_LOCATION);
568   DALI_TEST_EQUALS((GLenum)GL_ONE_MINUS_SRC_COLOR, glAbstraction.GetLastBlendFuncSrcAlpha(), TEST_LOCATION);
569   DALI_TEST_EQUALS((GLenum)GL_SRC_ALPHA_SATURATE, glAbstraction.GetLastBlendFuncDstAlpha(), TEST_LOCATION);
570
571   END_TEST;
572 }
573
574 int UtcDaliRendererBlendOptions02(void)
575 {
576   TestApplication application;
577
578   tet_infoline("Test BLEND_FACTOR properties ");
579
580   Geometry geometry = CreateQuadGeometry();
581   Shader   shader   = CreateShader();
582   Renderer renderer = Renderer::New(geometry, shader);
583
584   Actor actor = Actor::New();
585   actor.SetProperty(Actor::Property::OPACITY, 0.5f); // enable blending
586   actor.AddRenderer(renderer);
587   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
588   application.GetScene().Add(actor);
589
590   renderer.SetProperty(Renderer::Property::BLEND_FACTOR_SRC_RGB, BlendFactor::CONSTANT_COLOR);
591   renderer.SetProperty(Renderer::Property::BLEND_FACTOR_DEST_RGB, BlendFactor::ONE_MINUS_CONSTANT_COLOR);
592   renderer.SetProperty(Renderer::Property::BLEND_FACTOR_SRC_ALPHA, BlendFactor::CONSTANT_ALPHA);
593   renderer.SetProperty(Renderer::Property::BLEND_FACTOR_DEST_ALPHA, BlendFactor::ONE_MINUS_CONSTANT_ALPHA);
594
595   // Test that Set was successful:
596   {
597     int srcFactorRgb    = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
598     int destFactorRgb   = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
599     int srcFactorAlpha  = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
600     int destFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
601
602     DALI_TEST_EQUALS((int)BlendFactor::CONSTANT_COLOR, srcFactorRgb, TEST_LOCATION);
603     DALI_TEST_EQUALS((int)BlendFactor::ONE_MINUS_CONSTANT_COLOR, destFactorRgb, TEST_LOCATION);
604     DALI_TEST_EQUALS((int)BlendFactor::CONSTANT_ALPHA, srcFactorAlpha, TEST_LOCATION);
605     DALI_TEST_EQUALS((int)BlendFactor::ONE_MINUS_CONSTANT_ALPHA, destFactorAlpha, TEST_LOCATION);
606   }
607
608   application.SendNotification();
609   application.Render();
610
611   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
612   DALI_TEST_EQUALS((GLenum)GL_CONSTANT_COLOR, glAbstraction.GetLastBlendFuncSrcRgb(), TEST_LOCATION);
613   DALI_TEST_EQUALS((GLenum)GL_ONE_MINUS_CONSTANT_COLOR, glAbstraction.GetLastBlendFuncDstRgb(), TEST_LOCATION);
614   DALI_TEST_EQUALS((GLenum)GL_CONSTANT_ALPHA, glAbstraction.GetLastBlendFuncSrcAlpha(), TEST_LOCATION);
615   DALI_TEST_EQUALS((GLenum)GL_ONE_MINUS_CONSTANT_ALPHA, glAbstraction.GetLastBlendFuncDstAlpha(), TEST_LOCATION);
616
617   END_TEST;
618 }
619
620 int UtcDaliRendererBlendOptions03(void)
621 {
622   TestApplication application;
623
624   tet_infoline("Test GetBlendEquation() defaults ");
625
626   Geometry geometry = CreateQuadGeometry();
627   Shader   shader   = CreateShader();
628   Renderer renderer = Renderer::New(geometry, shader);
629
630   Actor actor = Actor::New();
631   actor.AddRenderer(renderer);
632   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
633   application.GetScene().Add(actor);
634
635   // Test the defaults as documented in blending.h
636   int equationRgb   = renderer.GetProperty<int>(Renderer::Property::BLEND_EQUATION_RGB);
637   int equationAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_EQUATION_ALPHA);
638
639   DALI_TEST_EQUALS((int)BlendEquation::ADD, equationRgb, TEST_LOCATION);
640   DALI_TEST_EQUALS((int)BlendEquation::ADD, equationAlpha, TEST_LOCATION);
641
642   END_TEST;
643 }
644
645 int UtcDaliRendererBlendOptions04(void)
646 {
647   TestApplication application;
648
649   tet_infoline("Test SetBlendEquation() ");
650
651   Geometry geometry = CreateQuadGeometry();
652   Shader   shader   = CreateShader();
653   Renderer renderer = Renderer::New(geometry, shader);
654
655   Actor actor = Actor::New();
656   actor.SetProperty(Actor::Property::OPACITY, 0.1f);
657   actor.AddRenderer(renderer);
658   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
659   application.GetScene().Add(actor);
660
661   // Test the single blending equation setting
662   {
663     renderer.SetProperty(Renderer::Property::BLEND_EQUATION_RGB, BlendEquation::REVERSE_SUBTRACT);
664     int equationRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_EQUATION_RGB);
665     DALI_TEST_EQUALS((int)BlendEquation::REVERSE_SUBTRACT, equationRgb, TEST_LOCATION);
666   }
667
668   renderer.SetProperty(Renderer::Property::BLEND_EQUATION_RGB, BlendEquation::REVERSE_SUBTRACT);
669   renderer.SetProperty(Renderer::Property::BLEND_EQUATION_ALPHA, BlendEquation::REVERSE_SUBTRACT);
670
671   // Test that Set was successful
672   {
673     int equationRgb   = renderer.GetProperty<int>(Renderer::Property::BLEND_EQUATION_RGB);
674     int equationAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_EQUATION_ALPHA);
675     DALI_TEST_EQUALS((int)BlendEquation::REVERSE_SUBTRACT, equationRgb, TEST_LOCATION);
676     DALI_TEST_EQUALS((int)BlendEquation::REVERSE_SUBTRACT, equationAlpha, TEST_LOCATION);
677   }
678
679   // Render & check GL commands
680   application.SendNotification();
681   application.Render();
682
683   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
684   DALI_TEST_EQUALS((GLenum)GL_FUNC_REVERSE_SUBTRACT, glAbstraction.GetLastBlendEquationRgb(), TEST_LOCATION);
685   DALI_TEST_EQUALS((GLenum)GL_FUNC_REVERSE_SUBTRACT, glAbstraction.GetLastBlendEquationAlpha(), TEST_LOCATION);
686
687   END_TEST;
688 }
689
690 int UtcDaliRendererBlendOptions05(void)
691 {
692   TestApplication application;
693
694   tet_infoline("Test SetAdvancedBlendEquation ");
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.1f);
702
703   actor.AddRenderer(renderer);
704   actor.SetProperty(Actor::Property::SIZE, Vector2(400, 400));
705   application.GetScene().Add(actor);
706   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
707   glAbstraction.EnableEnableDisableCallTrace(true);
708
709   if(Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::MAX))
710   {
711     renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::MAX);
712     int equationRgb = renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION);
713     DALI_TEST_EQUALS((int)DevelBlendEquation::MAX, equationRgb, TEST_LOCATION);
714   }
715
716   if(Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::SCREEN))
717   {
718     renderer.SetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, true);
719     renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::SCREEN);
720     int equation = renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION);
721
722     DALI_TEST_EQUALS((int)DevelBlendEquation::SCREEN, equation, TEST_LOCATION);
723     DALI_TEST_EQUALS(DevelRenderer::IsAdvancedBlendEquationApplied(renderer), true, TEST_LOCATION);
724
725     application.SendNotification();
726     application.Render();
727   }
728
729   if(Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::SCREEN) &&
730      Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::MULTIPLY))
731   {
732     renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::ADD);
733     renderer.SetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, true);
734     renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION_RGB, DevelBlendEquation::SCREEN);
735     renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION_ALPHA, DevelBlendEquation::MULTIPLY);
736     int equationRgb   = renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION_RGB);
737     int equationAlpha = renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION_ALPHA);
738
739     DALI_TEST_EQUALS((int)DevelBlendEquation::ADD, equationRgb, TEST_LOCATION);
740     DALI_TEST_EQUALS((int)DevelBlendEquation::ADD, equationAlpha, TEST_LOCATION);
741     DALI_TEST_EQUALS(DevelRenderer::IsAdvancedBlendEquationApplied(renderer), false, TEST_LOCATION);
742
743     application.SendNotification();
744     application.Render();
745   }
746
747   tet_infoline("Error Checking\n");
748   if(Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::MULTIPLY) &&
749      Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::SCREEN) &&
750      Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::OVERLAY) &&
751      Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::DARKEN) &&
752      Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::LIGHTEN) &&
753      Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::COLOR_DODGE) &&
754      Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::COLOR_BURN) &&
755      Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::HARD_LIGHT) &&
756      Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::SOFT_LIGHT) &&
757      Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::DIFFERENCE) &&
758      Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::EXCLUSION) &&
759      Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::HUE) &&
760      Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::SATURATION) &&
761      Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::COLOR) &&
762      Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::LUMINOSITY))
763   {
764     renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::MULTIPLY);
765     DALI_TEST_EQUALS((int)DevelBlendEquation::MULTIPLY, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
766     application.SendNotification();
767     application.Render();
768     DALI_TEST_EQUALS(glAbstraction.GetLastBlendEquationRgb(), GL_MULTIPLY, TEST_LOCATION);
769
770     renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::SCREEN);
771     DALI_TEST_EQUALS((int)DevelBlendEquation::SCREEN, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
772     application.SendNotification();
773     application.Render();
774     DALI_TEST_EQUALS(glAbstraction.GetLastBlendEquationRgb(), GL_SCREEN, TEST_LOCATION);
775
776     renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::OVERLAY);
777     DALI_TEST_EQUALS((int)DevelBlendEquation::OVERLAY, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
778     application.SendNotification();
779     application.Render();
780     DALI_TEST_EQUALS(glAbstraction.GetLastBlendEquationRgb(), GL_OVERLAY, TEST_LOCATION);
781
782     renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::DARKEN);
783     DALI_TEST_EQUALS((int)DevelBlendEquation::DARKEN, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
784     application.SendNotification();
785     application.Render();
786     DALI_TEST_EQUALS(glAbstraction.GetLastBlendEquationRgb(), GL_DARKEN, TEST_LOCATION);
787
788     renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::LIGHTEN);
789     DALI_TEST_EQUALS((int)DevelBlendEquation::LIGHTEN, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
790     application.SendNotification();
791     application.Render();
792     DALI_TEST_EQUALS(glAbstraction.GetLastBlendEquationRgb(), GL_LIGHTEN, TEST_LOCATION);
793
794     renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::COLOR_DODGE);
795     DALI_TEST_EQUALS((int)DevelBlendEquation::COLOR_DODGE, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
796     application.SendNotification();
797     application.Render();
798     DALI_TEST_EQUALS(glAbstraction.GetLastBlendEquationRgb(), GL_COLORDODGE, TEST_LOCATION);
799
800     renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::COLOR_BURN);
801     DALI_TEST_EQUALS((int)DevelBlendEquation::COLOR_BURN, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
802     application.SendNotification();
803     application.Render();
804     DALI_TEST_EQUALS(glAbstraction.GetLastBlendEquationRgb(), GL_COLORBURN, TEST_LOCATION);
805
806     renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::HARD_LIGHT);
807     DALI_TEST_EQUALS((int)DevelBlendEquation::HARD_LIGHT, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
808     application.SendNotification();
809     application.Render();
810     DALI_TEST_EQUALS(glAbstraction.GetLastBlendEquationRgb(), GL_HARDLIGHT, TEST_LOCATION);
811
812     renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::SOFT_LIGHT);
813     DALI_TEST_EQUALS((int)DevelBlendEquation::SOFT_LIGHT, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
814     application.SendNotification();
815     application.Render();
816     DALI_TEST_EQUALS(glAbstraction.GetLastBlendEquationRgb(), GL_SOFTLIGHT, TEST_LOCATION);
817
818     renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::DIFFERENCE);
819     DALI_TEST_EQUALS((int)DevelBlendEquation::DIFFERENCE, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
820     application.SendNotification();
821     application.Render();
822     DALI_TEST_EQUALS(glAbstraction.GetLastBlendEquationRgb(), GL_DIFFERENCE, TEST_LOCATION);
823
824     renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::EXCLUSION);
825     DALI_TEST_EQUALS((int)DevelBlendEquation::EXCLUSION, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
826     application.SendNotification();
827     application.Render();
828     DALI_TEST_EQUALS(glAbstraction.GetLastBlendEquationRgb(), GL_EXCLUSION, TEST_LOCATION);
829
830     renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::HUE);
831     DALI_TEST_EQUALS((int)DevelBlendEquation::HUE, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
832     application.SendNotification();
833     application.Render();
834     DALI_TEST_EQUALS(glAbstraction.GetLastBlendEquationRgb(), GL_HSL_HUE, TEST_LOCATION);
835
836     renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::SATURATION);
837     DALI_TEST_EQUALS((int)DevelBlendEquation::SATURATION, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
838     application.SendNotification();
839     application.Render();
840     DALI_TEST_EQUALS(glAbstraction.GetLastBlendEquationRgb(), GL_HSL_SATURATION, TEST_LOCATION);
841
842     renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::COLOR);
843     DALI_TEST_EQUALS((int)DevelBlendEquation::COLOR, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
844     application.SendNotification();
845     application.Render();
846     DALI_TEST_EQUALS(glAbstraction.GetLastBlendEquationRgb(), GL_HSL_COLOR, TEST_LOCATION);
847
848     renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::LUMINOSITY);
849     DALI_TEST_EQUALS((int)DevelBlendEquation::LUMINOSITY, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
850     application.SendNotification();
851     application.Render();
852     DALI_TEST_EQUALS(glAbstraction.GetLastBlendEquationRgb(), GL_HSL_LUMINOSITY, TEST_LOCATION);
853   }
854
855   END_TEST;
856 }
857
858 int UtcDaliRendererSetBlendMode01(void)
859 {
860   TestApplication application;
861
862   tet_infoline("Test setting the blend mode to on with an opaque color renders with blending enabled");
863
864   Geometry geometry = CreateQuadGeometry();
865   Shader   shader   = CreateShader();
866   Renderer renderer = Renderer::New(geometry, shader);
867
868   Actor actor = Actor::New();
869   actor.SetProperty(Actor::Property::OPACITY, 1.0f);
870   actor.AddRenderer(renderer);
871   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
872   application.GetScene().Add(actor);
873
874   renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON);
875
876   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
877   glAbstraction.EnableEnableDisableCallTrace(true);
878
879   application.SendNotification();
880   application.Render();
881
882   TraceCallStack&             glEnableStack = glAbstraction.GetEnableDisableTrace();
883   TraceCallStack::NamedParams params;
884   params["cap"] << std::hex << GL_BLEND;
885   DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", params));
886
887   END_TEST;
888 }
889
890 int UtcDaliRendererSetBlendMode01b(void)
891 {
892   TestApplication application;
893
894   tet_infoline("Test setting the blend mode to on with an transparent color renders with blending enabled");
895
896   Geometry geometry = CreateQuadGeometry();
897   Shader   shader   = CreateShader();
898   Renderer renderer = Renderer::New(geometry, shader);
899
900   Actor actor = Actor::New();
901   actor.SetProperty(Actor::Property::OPACITY, 0.0f);
902   actor.AddRenderer(renderer);
903   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
904   application.GetScene().Add(actor);
905
906   renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON);
907
908   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
909   glAbstraction.EnableEnableDisableCallTrace(true);
910   glAbstraction.EnableDrawCallTrace(true);
911
912   application.SendNotification();
913   application.Render();
914
915   TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
916   DALI_TEST_CHECK(!glEnableStack.FindMethod("Enable"));
917
918   DALI_TEST_CHECK(!glAbstraction.GetDrawTrace().FindMethod("DrawElements"));
919
920   END_TEST;
921 }
922
923 int UtcDaliRendererSetBlendMode02(void)
924 {
925   TestApplication application;
926
927   tet_infoline("Test setting the blend mode to off with a transparent color renders with blending disabled (and not enabled)");
928
929   Geometry geometry = CreateQuadGeometry();
930   Shader   shader   = CreateShader();
931   Renderer renderer = Renderer::New(geometry, shader);
932
933   Actor actor = Actor::New();
934   actor.SetProperty(Actor::Property::OPACITY, 0.15f);
935   actor.AddRenderer(renderer);
936   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
937   application.GetScene().Add(actor);
938
939   renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::OFF);
940
941   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
942   glAbstraction.EnableEnableDisableCallTrace(true);
943
944   application.SendNotification();
945   application.Render();
946
947   TraceCallStack&             glEnableStack = glAbstraction.GetEnableDisableTrace();
948   TraceCallStack::NamedParams params;
949   params["cap"] << std::hex << GL_BLEND;
950   DALI_TEST_CHECK(!glEnableStack.FindMethodAndParams("Enable", params));
951
952   END_TEST;
953 }
954
955 int UtcDaliRendererSetBlendMode03(void)
956 {
957   TestApplication application;
958
959   tet_infoline("Test setting the blend mode to auto with a transparent color renders with blending enabled");
960
961   Geometry geometry = CreateQuadGeometry();
962   Shader   shader   = CreateShader();
963   Renderer renderer = Renderer::New(geometry, shader);
964
965   Actor actor = Actor::New();
966   actor.SetProperty(Actor::Property::OPACITY, 0.75f);
967   actor.AddRenderer(renderer);
968   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
969   application.GetScene().Add(actor);
970
971   renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::AUTO);
972
973   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
974   glAbstraction.EnableEnableDisableCallTrace(true);
975
976   application.SendNotification();
977   application.Render();
978
979   TraceCallStack&             glEnableStack = glAbstraction.GetEnableDisableTrace();
980   TraceCallStack::NamedParams params;
981   params["cap"] << std::hex << GL_BLEND;
982   DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", params));
983
984   END_TEST;
985 }
986
987 int UtcDaliRendererSetBlendMode04(void)
988 {
989   TestApplication application;
990
991   tet_infoline("Test setting the blend mode to auto with an opaque color renders with blending disabled");
992
993   Geometry geometry = CreateQuadGeometry();
994   Shader   shader   = CreateShader();
995   Renderer renderer = Renderer::New(geometry, shader);
996
997   Actor actor = Actor::New();
998   actor.AddRenderer(renderer);
999   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1000   application.GetScene().Add(actor);
1001
1002   renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::AUTO);
1003
1004   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1005   glAbstraction.EnableEnableDisableCallTrace(true);
1006
1007   application.SendNotification();
1008   application.Render();
1009
1010   TraceCallStack&             glEnableStack = glAbstraction.GetEnableDisableTrace();
1011   TraceCallStack::NamedParams params;
1012   params["cap"] << std::hex << GL_BLEND;
1013   DALI_TEST_CHECK(!glEnableStack.FindMethodAndParams("Enable", params));
1014   DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Disable", params));
1015
1016   END_TEST;
1017 }
1018
1019 int UtcDaliRendererSetBlendMode04b(void)
1020 {
1021   TestApplication application;
1022
1023   tet_infoline("Test setting the blend mode to auto with a transparent actor color renders with blending enabled");
1024
1025   Geometry geometry = CreateQuadGeometry();
1026   Shader   shader   = CreateShader();
1027   Renderer renderer = Renderer::New(geometry, shader);
1028
1029   Actor actor = Actor::New();
1030   actor.AddRenderer(renderer);
1031   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1032   actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 0.5f));
1033   application.GetScene().Add(actor);
1034
1035   renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::AUTO);
1036
1037   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1038   glAbstraction.EnableEnableDisableCallTrace(true);
1039
1040   application.SendNotification();
1041   application.Render();
1042
1043   TraceCallStack&             glEnableStack = glAbstraction.GetEnableDisableTrace();
1044   TraceCallStack::NamedParams params;
1045   params["cap"] << std::hex << GL_BLEND;
1046   DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", params));
1047
1048   END_TEST;
1049 }
1050
1051 int UtcDaliRendererSetBlendMode04c(void)
1052 {
1053   TestApplication application;
1054
1055   tet_infoline("Test setting the blend mode to auto with an opaque opaque actor color renders with blending disabled");
1056
1057   Geometry geometry = CreateQuadGeometry();
1058   Shader   shader   = CreateShader();
1059   Renderer renderer = Renderer::New(geometry, shader);
1060
1061   Actor actor = Actor::New();
1062   actor.AddRenderer(renderer);
1063   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1064   actor.SetProperty(Actor::Property::COLOR, Color::MAGENTA);
1065   application.GetScene().Add(actor);
1066
1067   renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::AUTO);
1068
1069   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1070   glAbstraction.EnableEnableDisableCallTrace(true);
1071
1072   application.SendNotification();
1073   application.Render();
1074
1075   TraceCallStack&             glEnableStack = glAbstraction.GetEnableDisableTrace();
1076   TraceCallStack::NamedParams params;
1077   params["cap"] << std::hex << GL_BLEND;
1078   DALI_TEST_CHECK(!glEnableStack.FindMethodAndParams("Enable", params));
1079   DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Disable", params));
1080
1081   END_TEST;
1082 }
1083
1084 int UtcDaliRendererSetBlendMode05(void)
1085 {
1086   TestApplication application;
1087
1088   tet_infoline("Test setting the blend mode to auto with an opaque color and an image with an alpha channel renders with blending enabled");
1089
1090   Geometry geometry = CreateQuadGeometry();
1091   Texture  image    = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, 40, 40);
1092
1093   Shader     shader     = CreateShader();
1094   TextureSet textureSet = CreateTextureSet(image);
1095   Renderer   renderer   = Renderer::New(geometry, shader);
1096   renderer.SetTextures(textureSet);
1097
1098   Actor actor = Actor::New();
1099   actor.AddRenderer(renderer);
1100   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1101   application.GetScene().Add(actor);
1102
1103   renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::AUTO);
1104
1105   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1106   glAbstraction.EnableEnableDisableCallTrace(true);
1107
1108   application.SendNotification();
1109   application.Render();
1110
1111   TraceCallStack&             glEnableStack = glAbstraction.GetEnableDisableTrace();
1112   TraceCallStack::NamedParams params;
1113   params["cap"] << std::hex << GL_BLEND;
1114   DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", params));
1115
1116   END_TEST;
1117 }
1118
1119 int UtcDaliRendererSetBlendMode06(void)
1120 {
1121   TestApplication application;
1122   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");
1123
1124   Geometry geometry = CreateQuadGeometry();
1125   Shader   shader   = Shader::New("vertexSrc", "fragmentSrc", Shader::Hint::OUTPUT_IS_TRANSPARENT);
1126
1127   Renderer renderer = Renderer::New(geometry, shader);
1128
1129   Actor actor = Actor::New();
1130   actor.AddRenderer(renderer);
1131   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1132   application.GetScene().Add(actor);
1133
1134   renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::AUTO);
1135
1136   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1137   glAbstraction.EnableEnableDisableCallTrace(true);
1138
1139   application.SendNotification();
1140   application.Render();
1141
1142   TraceCallStack&             glEnableStack = glAbstraction.GetEnableDisableTrace();
1143   TraceCallStack::NamedParams params;
1144   params["cap"] << std::hex << GL_BLEND;
1145   DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", params));
1146
1147   END_TEST;
1148 }
1149
1150 int UtcDaliRendererSetBlendMode07(void)
1151 {
1152   TestApplication application;
1153   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");
1154
1155   Geometry geometry = CreateQuadGeometry();
1156   Shader   shader   = Shader::New("vertexSrc", "fragmentSrc");
1157
1158   Texture    image      = Texture::New(TextureType::TEXTURE_2D, Pixel::RGB888, 50, 50);
1159   TextureSet textureSet = CreateTextureSet(image);
1160   Renderer   renderer   = Renderer::New(geometry, shader);
1161   renderer.SetTextures(textureSet);
1162
1163   Actor actor = Actor::New();
1164   actor.AddRenderer(renderer);
1165   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1166   application.GetScene().Add(actor);
1167
1168   renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::AUTO);
1169
1170   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1171   glAbstraction.EnableEnableDisableCallTrace(true);
1172
1173   application.SendNotification();
1174   application.Render();
1175
1176   TraceCallStack&             glEnableStack = glAbstraction.GetEnableDisableTrace();
1177   TraceCallStack::NamedParams params;
1178   params["cap"] << std::hex << GL_BLEND;
1179   DALI_TEST_CHECK(!glEnableStack.FindMethodAndParams("Enable", params));
1180
1181   END_TEST;
1182 }
1183
1184 int UtcDaliRendererSetBlendMode08(void)
1185 {
1186   TestApplication application;
1187
1188   tet_infoline("Test setting the blend mode to auto with opaque color and Advanced Blend Equation.");
1189
1190   if(Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::SCREEN))
1191   {
1192     Geometry geometry = CreateQuadGeometry();
1193     Shader   shader   = CreateShader();
1194     Renderer renderer = Renderer::New(geometry, shader);
1195
1196     Actor actor = Actor::New();
1197     actor.SetProperty(Actor::Property::OPACITY, 1.0f);
1198     actor.AddRenderer(renderer);
1199     actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1200     application.GetScene().Add(actor);
1201
1202     renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::AUTO);
1203     renderer.SetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, true);
1204     renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::SCREEN);
1205
1206     TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1207     glAbstraction.EnableEnableDisableCallTrace(true);
1208
1209     application.SendNotification();
1210     application.Render();
1211
1212     TraceCallStack&             glEnableStack = glAbstraction.GetEnableDisableTrace();
1213     TraceCallStack::NamedParams params;
1214     params["cap"] << std::hex << GL_BLEND;
1215     DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", params));
1216   }
1217
1218   END_TEST;
1219 }
1220
1221 int UtcDaliRendererSetBlendMode08b(void)
1222 {
1223   TestApplication application;
1224
1225   tet_infoline("Test setting the blend mode to off with opaque color and Advanced Blend Equation.");
1226
1227   if(Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::SCREEN))
1228   {
1229     Geometry geometry = CreateQuadGeometry();
1230     Shader   shader   = CreateShader();
1231     Renderer renderer = Renderer::New(geometry, shader);
1232
1233     Actor actor = Actor::New();
1234     actor.SetProperty(Actor::Property::OPACITY, 1.0f);
1235     actor.AddRenderer(renderer);
1236     actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1237     application.GetScene().Add(actor);
1238
1239     renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::OFF);
1240     renderer.SetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, true);
1241     renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::SCREEN);
1242
1243     TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1244     glAbstraction.EnableEnableDisableCallTrace(true);
1245
1246     application.SendNotification();
1247     application.Render();
1248
1249     TraceCallStack&             glEnableStack = glAbstraction.GetEnableDisableTrace();
1250     TraceCallStack::NamedParams params;
1251     params["cap"] << std::hex << GL_BLEND;
1252     DALI_TEST_CHECK(!glEnableStack.FindMethodAndParams("Enable", params));
1253   }
1254
1255   END_TEST;
1256 }
1257
1258 int UtcDaliRendererSetBlendMode09(void)
1259 {
1260   TestApplication application;
1261
1262   tet_infoline("Test setting the blend mode to on_without_cull with an opaque color renders with blending enabled");
1263
1264   Geometry geometry = CreateQuadGeometry();
1265   Shader   shader   = CreateShader();
1266   Renderer renderer = Renderer::New(geometry, shader);
1267
1268   Actor actor = Actor::New();
1269   actor.SetProperty(Actor::Property::OPACITY, 1.0f);
1270   actor.AddRenderer(renderer);
1271   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1272   application.GetScene().Add(actor);
1273
1274   renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON_WITHOUT_CULL);
1275
1276   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1277   glAbstraction.EnableEnableDisableCallTrace(true);
1278
1279   application.SendNotification();
1280   application.Render();
1281
1282   TraceCallStack&             glEnableStack = glAbstraction.GetEnableDisableTrace();
1283   TraceCallStack::NamedParams params;
1284   params["cap"] << std::hex << GL_BLEND;
1285   DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", params));
1286
1287   END_TEST;
1288 }
1289
1290 int UtcDaliRendererSetBlendMode09b(void)
1291 {
1292   TestApplication application;
1293
1294   tet_infoline("Test setting the blend mode to on_without_cull with an transparent color renders with blending enabled");
1295
1296   Geometry geometry = CreateQuadGeometry();
1297   Shader   shader   = CreateShader();
1298   Renderer renderer = Renderer::New(geometry, shader);
1299
1300   Actor actor = Actor::New();
1301   actor.SetProperty(Actor::Property::OPACITY, 0.0f);
1302   actor.AddRenderer(renderer);
1303   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1304   application.GetScene().Add(actor);
1305
1306   renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON_WITHOUT_CULL);
1307
1308   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1309   glAbstraction.EnableEnableDisableCallTrace(true);
1310   glAbstraction.EnableDrawCallTrace(true);
1311
1312   application.SendNotification();
1313   application.Render();
1314
1315   TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
1316   DALI_TEST_CHECK(glEnableStack.FindMethod("Enable"));
1317
1318   DALI_TEST_CHECK(glAbstraction.GetDrawTrace().FindMethod("DrawElements"));
1319
1320   END_TEST;
1321 }
1322
1323 int UtcDaliRendererGetBlendMode(void)
1324 {
1325   TestApplication application;
1326
1327   tet_infoline("Test GetBlendMode()");
1328
1329   Geometry geometry = CreateQuadGeometry();
1330   Shader   shader   = Shader::New("vertexSrc", "fragmentSrc");
1331   Renderer renderer = Renderer::New(geometry, shader);
1332
1333   // default value
1334   unsigned int mode = renderer.GetProperty<int>(Renderer::Property::BLEND_MODE);
1335   DALI_TEST_EQUALS(static_cast<BlendMode::Type>(mode), BlendMode::AUTO, TEST_LOCATION);
1336
1337   // ON
1338   renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON);
1339   mode = renderer.GetProperty<int>(Renderer::Property::BLEND_MODE);
1340   DALI_TEST_EQUALS(static_cast<BlendMode::Type>(mode), BlendMode::ON, TEST_LOCATION);
1341
1342   // OFF
1343   renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::OFF);
1344   mode = renderer.GetProperty<int>(Renderer::Property::BLEND_MODE);
1345   DALI_TEST_EQUALS(static_cast<BlendMode::Type>(mode), BlendMode::OFF, TEST_LOCATION);
1346
1347   // ON_WITHOUT_CULL
1348   renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON_WITHOUT_CULL);
1349   mode = renderer.GetProperty<int>(Renderer::Property::BLEND_MODE);
1350   DALI_TEST_EQUALS(static_cast<BlendMode::Type>(mode), BlendMode::ON_WITHOUT_CULL, TEST_LOCATION);
1351
1352   END_TEST;
1353 }
1354
1355 int UtcDaliRendererSetBlendColor(void)
1356 {
1357   TestApplication application;
1358
1359   tet_infoline("Test SetBlendColor(color)");
1360
1361   Geometry   geometry   = CreateQuadGeometry();
1362   Shader     shader     = Shader::New("vertexSrc", "fragmentSrc");
1363   TextureSet textureSet = TextureSet::New();
1364   Texture    image      = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, 50, 50);
1365   textureSet.SetTexture(0u, image);
1366   Renderer renderer = Renderer::New(geometry, shader);
1367   renderer.SetTextures(textureSet);
1368
1369   Actor actor = Actor::New();
1370   actor.AddRenderer(renderer);
1371   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1372   application.GetScene().Add(actor);
1373
1374   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1375
1376   renderer.SetProperty(Renderer::Property::BLEND_COLOR, Color::TRANSPARENT);
1377
1378   application.SendNotification();
1379   application.Render();
1380
1381   DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::TRANSPARENT, TEST_LOCATION);
1382   DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::TRANSPARENT, TEST_LOCATION);
1383   DALI_TEST_EQUALS(glAbstraction.GetLastBlendColor(), Color::TRANSPARENT, TEST_LOCATION);
1384
1385   renderer.SetProperty(Renderer::Property::BLEND_COLOR, Color::MAGENTA);
1386
1387   DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::MAGENTA, TEST_LOCATION);
1388   DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::TRANSPARENT, TEST_LOCATION);
1389
1390   application.SendNotification();
1391   application.Render();
1392
1393   DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::MAGENTA, TEST_LOCATION);
1394   DALI_TEST_EQUALS(glAbstraction.GetLastBlendColor(), Color::MAGENTA, TEST_LOCATION);
1395
1396   Vector4 color(0.1f, 0.2f, 0.3f, 0.4f);
1397   renderer.SetProperty(Renderer::Property::BLEND_COLOR, color);
1398   application.SendNotification();
1399   application.Render();
1400   DALI_TEST_EQUALS(glAbstraction.GetLastBlendColor(), color, TEST_LOCATION);
1401
1402   END_TEST;
1403 }
1404
1405 int UtcDaliRendererGetBlendColor(void)
1406 {
1407   TestApplication application;
1408
1409   tet_infoline("Test GetBlendColor()");
1410
1411   Geometry geometry = CreateQuadGeometry();
1412   Shader   shader   = Shader::New("vertexSrc", "fragmentSrc");
1413   Renderer renderer = Renderer::New(geometry, shader);
1414
1415   DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::TRANSPARENT, TEST_LOCATION);
1416
1417   renderer.SetProperty(Renderer::Property::BLEND_COLOR, Color::MAGENTA);
1418   application.SendNotification();
1419   application.Render();
1420   DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::MAGENTA, TEST_LOCATION);
1421
1422   Vector4 color(0.1f, 0.2f, 0.3f, 0.4f);
1423   renderer.SetProperty(Renderer::Property::BLEND_COLOR, color);
1424   application.SendNotification();
1425   application.Render();
1426   DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), color, TEST_LOCATION);
1427
1428   END_TEST;
1429 }
1430
1431 int UtcDaliRendererPreMultipledAlpha(void)
1432 {
1433   TestApplication application;
1434
1435   tet_infoline("Test BLEND_PRE_MULTIPLIED_ALPHA property");
1436
1437   Geometry geometry = CreateQuadGeometry();
1438   Shader   shader   = Shader::New("vertexSrc", "fragmentSrc");
1439   Renderer renderer = Renderer::New(geometry, shader);
1440
1441   Actor actor = Actor::New();
1442   actor.AddRenderer(renderer);
1443   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1444   actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 0.5f));
1445   application.GetScene().Add(actor);
1446
1447   Property::Value value = renderer.GetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
1448   bool            preMultipliedAlpha;
1449   DALI_TEST_CHECK(value.Get(preMultipliedAlpha));
1450   DALI_TEST_CHECK(!preMultipliedAlpha);
1451
1452   int srcFactorRgb    = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
1453   int destFactorRgb   = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
1454   int srcFactorAlpha  = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
1455   int destFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
1456
1457   DALI_TEST_EQUALS((int)DEFAULT_BLEND_FACTOR_SRC_RGB, srcFactorRgb, TEST_LOCATION);
1458   DALI_TEST_EQUALS((int)DEFAULT_BLEND_FACTOR_DEST_RGB, destFactorRgb, TEST_LOCATION);
1459   DALI_TEST_EQUALS((int)DEFAULT_BLEND_FACTOR_SRC_ALPHA, srcFactorAlpha, TEST_LOCATION);
1460   DALI_TEST_EQUALS((int)DEFAULT_BLEND_FACTOR_DEST_ALPHA, destFactorAlpha, TEST_LOCATION);
1461
1462   application.SendNotification();
1463   application.Render();
1464
1465   Vector4            actualValue(Vector4::ZERO);
1466   Vector4            actualActorColor(Vector4::ZERO);
1467   TestGlAbstraction& gl = application.GetGlAbstraction();
1468   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uColor", actualValue));
1469   DALI_TEST_EQUALS(actualValue, Vector4(1.0f, 0.0f, 1.0f, 0.5f), TEST_LOCATION);
1470   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uActorColor", actualActorColor));
1471   DALI_TEST_EQUALS(actualActorColor, Vector4(1.0f, 0.0f, 1.0f, 0.5f), TEST_LOCATION);
1472
1473   // Enable pre-multiplied alpha
1474   renderer.SetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, true);
1475
1476   application.SendNotification();
1477   application.Render();
1478
1479   value = renderer.GetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
1480   DALI_TEST_CHECK(value.Get(preMultipliedAlpha));
1481   DALI_TEST_CHECK(preMultipliedAlpha);
1482
1483   value = renderer.GetCurrentProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
1484   DALI_TEST_CHECK(value.Get(preMultipliedAlpha));
1485   DALI_TEST_CHECK(preMultipliedAlpha);
1486
1487   srcFactorRgb    = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
1488   destFactorRgb   = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
1489   srcFactorAlpha  = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
1490   destFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
1491
1492   DALI_TEST_EQUALS((int)BlendFactor::ONE, srcFactorRgb, TEST_LOCATION);
1493   DALI_TEST_EQUALS((int)BlendFactor::ONE_MINUS_SRC_ALPHA, destFactorRgb, TEST_LOCATION);
1494   DALI_TEST_EQUALS((int)BlendFactor::ONE, srcFactorAlpha, TEST_LOCATION);
1495   DALI_TEST_EQUALS((int)BlendFactor::ONE_MINUS_SRC_ALPHA, destFactorAlpha, TEST_LOCATION);
1496
1497   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uColor", actualValue));
1498   DALI_TEST_EQUALS(actualValue, Vector4(0.5f, 0.0f, 0.5f, 0.5f), TEST_LOCATION);
1499   // Note : uActorColor doesn't premultiplied.
1500   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uActorColor", actualActorColor));
1501   DALI_TEST_EQUALS(actualActorColor, Vector4(1.0f, 0.0f, 1.0f, 0.5f), TEST_LOCATION);
1502
1503   // Disable pre-multiplied alpha again
1504   renderer.SetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, false);
1505
1506   application.SendNotification();
1507   application.Render();
1508
1509   value = renderer.GetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
1510   DALI_TEST_CHECK(value.Get(preMultipliedAlpha));
1511   DALI_TEST_CHECK(!preMultipliedAlpha);
1512
1513   value = renderer.GetCurrentProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
1514   DALI_TEST_CHECK(value.Get(preMultipliedAlpha));
1515   DALI_TEST_CHECK(!preMultipliedAlpha);
1516
1517   srcFactorRgb    = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
1518   destFactorRgb   = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
1519   srcFactorAlpha  = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
1520   destFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
1521
1522   DALI_TEST_EQUALS((int)BlendFactor::SRC_ALPHA, srcFactorRgb, TEST_LOCATION);
1523   DALI_TEST_EQUALS((int)BlendFactor::ONE_MINUS_SRC_ALPHA, destFactorRgb, TEST_LOCATION);
1524   DALI_TEST_EQUALS((int)BlendFactor::ONE, srcFactorAlpha, TEST_LOCATION);
1525   DALI_TEST_EQUALS((int)BlendFactor::ONE_MINUS_SRC_ALPHA, destFactorAlpha, TEST_LOCATION);
1526
1527   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uColor", actualValue));
1528   DALI_TEST_EQUALS(actualValue, Vector4(1.0f, 0.0f, 1.0f, 0.5f), TEST_LOCATION);
1529   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uActorColor", actualActorColor));
1530   DALI_TEST_EQUALS(actualActorColor, Vector4(1.0f, 0.0f, 1.0f, 0.5f), TEST_LOCATION);
1531
1532   END_TEST;
1533 }
1534
1535 int UtcDaliRendererConstraint01(void)
1536 {
1537   TestApplication application;
1538
1539   tet_infoline("Test that a non-uniform renderer property can be constrained");
1540
1541   Shader   shader   = Shader::New("VertexSource", "FragmentSource");
1542   Geometry geometry = CreateQuadGeometry();
1543   Renderer renderer = Renderer::New(geometry, shader);
1544
1545   Actor actor = Actor::New();
1546   actor.AddRenderer(renderer);
1547   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1548   application.GetScene().Add(actor);
1549
1550   Vector4         initialColor = Color::WHITE;
1551   Property::Index colorIndex   = renderer.RegisterProperty("uFadeColor", initialColor);
1552
1553   application.SendNotification();
1554   application.Render(0);
1555   DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION);
1556
1557   // Apply constraint
1558   Constraint constraint = Constraint::New<Vector4>(renderer, colorIndex, TestConstraintNoBlue);
1559   constraint.Apply();
1560   application.SendNotification();
1561   application.Render(0);
1562
1563   // Expect no blue component in either buffer - yellow
1564   DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(colorIndex), Color::YELLOW, TEST_LOCATION);
1565   application.Render(0);
1566   DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(colorIndex), Color::YELLOW, TEST_LOCATION);
1567
1568   renderer.RemoveConstraints();
1569   renderer.SetProperty(colorIndex, Color::WHITE);
1570   application.SendNotification();
1571   application.Render(0);
1572   DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(colorIndex), Color::WHITE, TEST_LOCATION);
1573
1574   END_TEST;
1575 }
1576
1577 int UtcDaliRendererConstraint02(void)
1578 {
1579   TestApplication application;
1580
1581   tet_infoline("Test that a uniform map renderer property can be constrained");
1582
1583   Shader   shader   = Shader::New("VertexSource", "FragmentSource");
1584   Geometry geometry = CreateQuadGeometry();
1585   Renderer renderer = Renderer::New(geometry, shader);
1586
1587   Actor actor = Actor::New();
1588   actor.AddRenderer(renderer);
1589   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1590   application.GetScene().Add(actor);
1591   application.SendNotification();
1592   application.Render(0);
1593
1594   Vector4         initialColor = Color::WHITE;
1595   Property::Index colorIndex   = renderer.RegisterProperty("uFadeColor", initialColor);
1596
1597   TestGlAbstraction& gl = application.GetGlAbstraction();
1598
1599   application.SendNotification();
1600   application.Render(0);
1601
1602   Vector4 actualValue(Vector4::ZERO);
1603   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1604   DALI_TEST_EQUALS(actualValue, initialColor, TEST_LOCATION);
1605
1606   // Apply constraint
1607   Constraint constraint = Constraint::New<Vector4>(renderer, colorIndex, TestConstraintNoBlue);
1608   constraint.Apply();
1609   application.SendNotification();
1610   application.Render(0);
1611
1612   // Expect no blue component in either buffer - yellow
1613   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1614   DALI_TEST_EQUALS(actualValue, Color::YELLOW, TEST_LOCATION);
1615
1616   application.Render(0);
1617   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1618   DALI_TEST_EQUALS(actualValue, Color::YELLOW, TEST_LOCATION);
1619
1620   renderer.RemoveConstraints();
1621   renderer.SetProperty(colorIndex, Color::WHITE);
1622   application.SendNotification();
1623   application.Render(0);
1624
1625   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1626   DALI_TEST_EQUALS(actualValue, Color::WHITE, TEST_LOCATION);
1627
1628   END_TEST;
1629 }
1630
1631 int UtcDaliRendererAnimatedProperty01(void)
1632 {
1633   TestApplication application;
1634
1635   tet_infoline("Test that a non-uniform renderer property can be animated");
1636
1637   Shader   shader   = Shader::New("VertexSource", "FragmentSource");
1638   Geometry geometry = CreateQuadGeometry();
1639   Renderer renderer = Renderer::New(geometry, shader);
1640
1641   Actor actor = Actor::New();
1642   actor.AddRenderer(renderer);
1643   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1644   application.GetScene().Add(actor);
1645
1646   Vector4         initialColor = Color::WHITE;
1647   Property::Index colorIndex   = renderer.RegisterProperty("uFadeColor", initialColor);
1648
1649   application.SendNotification();
1650   application.Render(0);
1651   DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION);
1652
1653   Animation animation = Animation::New(1.0f);
1654   KeyFrames keyFrames = KeyFrames::New();
1655   keyFrames.Add(0.0f, initialColor);
1656   keyFrames.Add(1.0f, Color::TRANSPARENT);
1657   animation.AnimateBetween(Property(renderer, colorIndex), keyFrames);
1658   animation.Play();
1659
1660   application.SendNotification();
1661   application.Render(500);
1662
1663   DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(colorIndex), Color::WHITE * 0.5f, TEST_LOCATION);
1664
1665   application.Render(500);
1666
1667   DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(colorIndex), Color::TRANSPARENT, TEST_LOCATION);
1668
1669   END_TEST;
1670 }
1671
1672 int UtcDaliRendererAnimatedProperty02(void)
1673 {
1674   TestApplication application;
1675
1676   tet_infoline("Test that a uniform map renderer property can be animated");
1677
1678   Shader   shader   = Shader::New("VertexSource", "FragmentSource");
1679   Geometry geometry = CreateQuadGeometry();
1680   Renderer renderer = Renderer::New(geometry, shader);
1681
1682   Actor actor = Actor::New();
1683   actor.AddRenderer(renderer);
1684   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1685   application.GetScene().Add(actor);
1686   application.SendNotification();
1687   application.Render(0);
1688
1689   Vector4         initialColor = Color::WHITE;
1690   Property::Index colorIndex   = renderer.RegisterProperty("uFadeColor", initialColor);
1691
1692   TestGlAbstraction& gl = application.GetGlAbstraction();
1693
1694   application.SendNotification();
1695   application.Render(0);
1696
1697   Vector4 actualValue(Vector4::ZERO);
1698   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1699   DALI_TEST_EQUALS(actualValue, initialColor, TEST_LOCATION);
1700
1701   Animation animation = Animation::New(1.0f);
1702   KeyFrames keyFrames = KeyFrames::New();
1703   keyFrames.Add(0.0f, initialColor);
1704   keyFrames.Add(1.0f, Color::TRANSPARENT);
1705   animation.AnimateBetween(Property(renderer, colorIndex), keyFrames);
1706   animation.Play();
1707
1708   application.SendNotification();
1709   application.Render(500);
1710
1711   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1712   DALI_TEST_EQUALS(actualValue, Color::WHITE * 0.5f, TEST_LOCATION);
1713
1714   application.Render(500);
1715   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1716   DALI_TEST_EQUALS(actualValue, Color::TRANSPARENT, TEST_LOCATION);
1717
1718   END_TEST;
1719 }
1720
1721 int UtcDaliRendererUniformMapPrecendence01(void)
1722 {
1723   TestApplication application;
1724
1725   tet_infoline("Test the uniform map precedence is applied properly");
1726
1727   Texture image = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64);
1728
1729   Shader     shader     = Shader::New("VertexSource", "FragmentSource");
1730   TextureSet textureSet = CreateTextureSet(image);
1731
1732   Geometry geometry = CreateQuadGeometry();
1733   Renderer renderer = Renderer::New(geometry, shader);
1734   renderer.SetTextures(textureSet);
1735
1736   Actor actor = Actor::New();
1737   actor.AddRenderer(renderer);
1738   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1739   application.GetScene().Add(actor);
1740   application.SendNotification();
1741   application.Render(0);
1742
1743   renderer.RegisterProperty("uFadeColor", Color::RED);
1744   actor.RegisterProperty("uFadeColor", Color::GREEN);
1745   Property::Index shaderFadeColorIndex = shader.RegisterProperty("uFadeColor", Color::MAGENTA);
1746
1747   TestGlAbstraction& gl = application.GetGlAbstraction();
1748
1749   application.SendNotification();
1750   application.Render(0);
1751
1752   // Expect that the actor's fade color property is accessed
1753   Vector4 actualValue(Vector4::ZERO);
1754   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1755   DALI_TEST_EQUALS(actualValue, Color::GREEN, TEST_LOCATION);
1756
1757   // Animate shader's fade color property. Should be no change to uniform
1758   Animation animation = Animation::New(1.0f);
1759   KeyFrames keyFrames = KeyFrames::New();
1760   keyFrames.Add(0.0f, Color::WHITE);
1761   keyFrames.Add(1.0f, Color::TRANSPARENT);
1762   animation.AnimateBetween(Property(shader, shaderFadeColorIndex), keyFrames);
1763   animation.Play();
1764
1765   application.SendNotification();
1766   application.Render(500);
1767
1768   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1769   DALI_TEST_EQUALS(actualValue, Color::GREEN, TEST_LOCATION);
1770
1771   application.Render(500);
1772   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1773   DALI_TEST_EQUALS(actualValue, Color::GREEN, TEST_LOCATION);
1774
1775   END_TEST;
1776 }
1777
1778 int UtcDaliRendererUniformMapPrecendence02(void)
1779 {
1780   TestApplication application;
1781
1782   tet_infoline("Test the uniform map precedence is applied properly");
1783
1784   Texture image = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64);
1785
1786   Shader     shader     = Shader::New("VertexSource", "FragmentSource");
1787   TextureSet textureSet = CreateTextureSet(image);
1788
1789   Geometry geometry = CreateQuadGeometry();
1790   Renderer renderer = Renderer::New(geometry, shader);
1791   renderer.SetTextures(textureSet);
1792
1793   Actor actor = Actor::New();
1794   actor.AddRenderer(renderer);
1795   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1796   application.GetScene().Add(actor);
1797   application.SendNotification();
1798   application.Render(0);
1799
1800   // Don't add property / uniform map to renderer
1801   actor.RegisterProperty("uFadeColor", Color::GREEN);
1802   Property::Index shaderFadeColorIndex = shader.RegisterProperty("uFadeColor", Color::BLUE);
1803
1804   TestGlAbstraction& gl = application.GetGlAbstraction();
1805
1806   application.SendNotification();
1807   application.Render(0);
1808
1809   // Expect that the actor's fade color property is accessed
1810   Vector4 actualValue(Vector4::ZERO);
1811   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1812   DALI_TEST_EQUALS(actualValue, Color::GREEN, TEST_LOCATION);
1813
1814   // Animate texture set's fade color property. Should be no change to uniform
1815   Animation animation = Animation::New(1.0f);
1816   KeyFrames keyFrames = KeyFrames::New();
1817   keyFrames.Add(0.0f, Color::WHITE);
1818   keyFrames.Add(1.0f, Color::TRANSPARENT);
1819   animation.AnimateBetween(Property(shader, shaderFadeColorIndex), keyFrames);
1820   animation.Play();
1821
1822   application.SendNotification();
1823   application.Render(500);
1824
1825   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1826   DALI_TEST_EQUALS(actualValue, Color::GREEN, TEST_LOCATION);
1827
1828   application.Render(500);
1829   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1830   DALI_TEST_EQUALS(actualValue, Color::GREEN, TEST_LOCATION);
1831
1832   END_TEST;
1833 }
1834
1835 int UtcDaliRendererUniformMapPrecendence03(void)
1836 {
1837   TestApplication application;
1838
1839   tet_infoline("Test the uniform map precedence is applied properly");
1840
1841   Texture image = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64);
1842
1843   Shader     shader     = Shader::New("VertexSource", "FragmentSource");
1844   TextureSet textureSet = CreateTextureSet(image);
1845
1846   Geometry geometry = CreateQuadGeometry();
1847   Renderer renderer = Renderer::New(geometry, shader);
1848   renderer.SetTextures(textureSet);
1849
1850   Actor actor = Actor::New();
1851   actor.AddRenderer(renderer);
1852   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1853   application.GetScene().Add(actor);
1854   application.SendNotification();
1855   application.Render(0);
1856
1857   // Don't add property / uniform map to renderer or actor
1858   shader.RegisterProperty("uFadeColor", Color::BLACK);
1859
1860   TestGlAbstraction& gl = application.GetGlAbstraction();
1861
1862   application.SendNotification();
1863   application.Render(0);
1864
1865   // Expect that the shader's fade color property is accessed
1866   Vector4 actualValue(Vector4::ZERO);
1867   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1868   DALI_TEST_EQUALS(actualValue, Color::BLACK, TEST_LOCATION);
1869
1870   END_TEST;
1871 }
1872
1873 int UtcDaliRendererUniformMapMultipleUniforms01(void)
1874 {
1875   TestApplication application;
1876
1877   tet_infoline("Test the uniform maps are collected from all objects (same type)");
1878
1879   Texture image = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64);
1880
1881   Shader     shader     = Shader::New("VertexSource", "FragmentSource");
1882   TextureSet textureSet = CreateTextureSet(image);
1883
1884   Geometry geometry = CreateQuadGeometry();
1885   Renderer renderer = Renderer::New(geometry, shader);
1886   renderer.SetTextures(textureSet);
1887
1888   Actor actor = Actor::New();
1889   actor.AddRenderer(renderer);
1890   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1891   application.GetScene().Add(actor);
1892   application.SendNotification();
1893   application.Render(0);
1894
1895   renderer.RegisterProperty("uUniform1", Color::RED);
1896   actor.RegisterProperty("uUniform2", Color::GREEN);
1897   shader.RegisterProperty("uUniform3", Color::MAGENTA);
1898
1899   TestGlAbstraction& gl = application.GetGlAbstraction();
1900
1901   application.SendNotification();
1902   application.Render(0);
1903
1904   // Expect that each of the object's uniforms are set
1905   Vector4 uniform1Value(Vector4::ZERO);
1906   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uUniform1", uniform1Value));
1907   DALI_TEST_EQUALS(uniform1Value, Color::RED, TEST_LOCATION);
1908
1909   Vector4 uniform2Value(Vector4::ZERO);
1910   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uUniform2", uniform2Value));
1911   DALI_TEST_EQUALS(uniform2Value, Color::GREEN, TEST_LOCATION);
1912
1913   Vector4 uniform3Value(Vector4::ZERO);
1914   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uUniform3", uniform3Value));
1915   DALI_TEST_EQUALS(uniform3Value, Color::MAGENTA, TEST_LOCATION);
1916
1917   END_TEST;
1918 }
1919
1920 int UtcDaliRendererUniformMapMultipleUniforms02(void)
1921 {
1922   TestApplication application;
1923
1924   tet_infoline("Test the uniform maps are collected from all objects (different types)");
1925
1926   Texture image = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64);
1927
1928   Shader     shader     = Shader::New("VertexSource", "FragmentSource");
1929   TextureSet textureSet = CreateTextureSet(image);
1930
1931   Geometry geometry = CreateQuadGeometry();
1932   Renderer renderer = Renderer::New(geometry, shader);
1933   renderer.SetTextures(textureSet);
1934
1935   Actor actor = Actor::New();
1936   actor.AddRenderer(renderer);
1937   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1938   application.GetScene().Add(actor);
1939   application.SendNotification();
1940   application.Render(0);
1941
1942   Property::Value value1(Color::RED);
1943   renderer.RegisterProperty("uFadeColor", value1);
1944
1945   Property::Value value2(1.0f);
1946   actor.RegisterProperty("uFadeProgress", value2);
1947
1948   Property::Value value3(Matrix3::IDENTITY);
1949   shader.RegisterProperty("uANormalMatrix", value3);
1950
1951   TestGlAbstraction& gl = application.GetGlAbstraction();
1952
1953   application.SendNotification();
1954   application.Render(0);
1955
1956   // Expect that each of the object's uniforms are set
1957   Vector4 uniform1Value(Vector4::ZERO);
1958   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", uniform1Value));
1959   DALI_TEST_EQUALS(uniform1Value, value1.Get<Vector4>(), TEST_LOCATION);
1960
1961   float uniform2Value(0.0f);
1962   DALI_TEST_CHECK(gl.GetUniformValue<float>("uFadeProgress", uniform2Value));
1963   DALI_TEST_EQUALS(uniform2Value, value2.Get<float>(), TEST_LOCATION);
1964
1965   Matrix3 uniform3Value;
1966   DALI_TEST_CHECK(gl.GetUniformValue<Matrix3>("uANormalMatrix", uniform3Value));
1967   DALI_TEST_EQUALS(uniform3Value, value3.Get<Matrix3>(), TEST_LOCATION);
1968
1969   END_TEST;
1970 }
1971
1972 int UtcDaliRendererRenderOrder2DLayer(void)
1973 {
1974   TestApplication application;
1975   tet_infoline("Test the rendering order in a 2D layer is correct");
1976
1977   Shader   shader   = Shader::New("VertexSource", "FragmentSource");
1978   Geometry geometry = CreateQuadGeometry();
1979
1980   Actor root = application.GetScene().GetRootLayer();
1981
1982   Actor    actor0    = CreateActor(root, 0, TEST_LOCATION);
1983   Renderer renderer0 = CreateRenderer(actor0, geometry, shader, 0);
1984
1985   Actor    actor1    = CreateActor(root, 0, TEST_LOCATION);
1986   Renderer renderer1 = CreateRenderer(actor1, geometry, shader, 0);
1987
1988   Actor    actor2    = CreateActor(root, 0, TEST_LOCATION);
1989   Renderer renderer2 = CreateRenderer(actor2, geometry, shader, 0);
1990
1991   Actor    actor3    = CreateActor(root, 0, TEST_LOCATION);
1992   Renderer renderer3 = CreateRenderer(actor3, geometry, shader, 0);
1993
1994   application.SendNotification();
1995   application.Render(0);
1996
1997   /*
1998    * Create the following hierarchy:
1999    *
2000    *            actor2
2001    *              /
2002    *             /
2003    *          actor1
2004    *           /
2005    *          /
2006    *       actor0
2007    *        /
2008    *       /
2009    *    actor3
2010    *
2011    *  Expected rendering order : actor2 - actor1 - actor0 - actor3
2012    */
2013   actor2.Add(actor1);
2014   actor1.Add(actor0);
2015   actor0.Add(actor3);
2016   application.SendNotification();
2017   application.Render(0);
2018
2019   TestGlAbstraction& gl = application.GetGlAbstraction();
2020   gl.GetTextureTrace().Reset();
2021   gl.EnableTextureCallTrace(true);
2022   application.SendNotification();
2023   application.Render(0);
2024
2025   int textureBindIndex[4];
2026   for(unsigned int i(0); i < 4; ++i)
2027   {
2028     std::stringstream params;
2029     params << std::hex << GL_TEXTURE_2D << std::dec << ", " << i + 1;
2030     textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str());
2031   }
2032
2033   //Check that actor1 has been rendered after actor2
2034   DALI_TEST_GREATER(textureBindIndex[1], textureBindIndex[2], TEST_LOCATION);
2035
2036   //Check that actor0 has been rendered after actor1
2037   DALI_TEST_GREATER(textureBindIndex[0], textureBindIndex[1], TEST_LOCATION);
2038
2039   //Check that actor3 has been rendered after actor0
2040   DALI_TEST_GREATER(textureBindIndex[3], textureBindIndex[0], TEST_LOCATION);
2041
2042   END_TEST;
2043 }
2044
2045 int UtcDaliRendererRenderOrder2DLayerMultipleRenderers(void)
2046 {
2047   TestApplication application;
2048   tet_infoline("Test the rendering order in a 2D layer is correct using multiple renderers per actor");
2049
2050   /*
2051    * Creates the following hierarchy:
2052    *
2053    *             actor0------------------------>actor1
2054    *            /   |   \                    /   |   \
2055    *          /     |     \                /     |     \
2056    *        /       |       \            /       |       \
2057    * renderer0 renderer1 renderer2 renderer3 renderer4 renderer5
2058    *
2059    *  renderer0 has depth index 2
2060    *  renderer1 has depth index 0
2061    *  renderer2 has depth index 1
2062    *
2063    *  renderer3 has depth index 1
2064    *  renderer4 has depth index 0
2065    *  renderer5 has depth index -1
2066    *
2067    *  Expected rendering order: renderer1 - renderer2 - renderer0 - renderer5 - renderer4 - renderer3
2068    */
2069
2070   Shader   shader   = Shader::New("VertexSource", "FragmentSource");
2071   Geometry geometry = CreateQuadGeometry();
2072
2073   Actor root = application.GetScene().GetRootLayer();
2074
2075   Actor    actor0    = CreateActor(root, 0, TEST_LOCATION);
2076   Actor    actor1    = CreateActor(actor0, 0, TEST_LOCATION);
2077   Renderer renderer0 = CreateRenderer(actor0, geometry, shader, 2);
2078   Renderer renderer1 = CreateRenderer(actor0, geometry, shader, 0);
2079   Renderer renderer2 = CreateRenderer(actor0, geometry, shader, 1);
2080   Renderer renderer3 = CreateRenderer(actor1, geometry, shader, 1);
2081   Renderer renderer4 = CreateRenderer(actor1, geometry, shader, 0);
2082   Renderer renderer5 = CreateRenderer(actor1, geometry, shader, -1);
2083
2084   application.SendNotification();
2085   application.Render(0);
2086
2087   TestGlAbstraction& gl = application.GetGlAbstraction();
2088   gl.GetTextureTrace().Reset();
2089   gl.EnableTextureCallTrace(true);
2090   application.SendNotification();
2091   application.Render(0);
2092
2093   int textureBindIndex[6];
2094   for(unsigned int i(0); i < 6; ++i)
2095   {
2096     std::stringstream params;
2097     params << std::hex << GL_TEXTURE_2D << std::dec << ", " << i + 1;
2098     textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str());
2099   }
2100
2101   //Check that renderer3 has been rendered after renderer4
2102   DALI_TEST_GREATER(textureBindIndex[3], textureBindIndex[4], TEST_LOCATION);
2103
2104   //Check that renderer0 has been rendered after renderer2
2105   DALI_TEST_GREATER(textureBindIndex[4], textureBindIndex[5], TEST_LOCATION);
2106
2107   //Check that renderer5 has been rendered after renderer2
2108   DALI_TEST_GREATER(textureBindIndex[5], textureBindIndex[0], TEST_LOCATION);
2109
2110   //Check that renderer0 has been rendered after renderer2
2111   DALI_TEST_GREATER(textureBindIndex[0], textureBindIndex[2], TEST_LOCATION);
2112
2113   //Check that renderer2 has been rendered after renderer1
2114   DALI_TEST_GREATER(textureBindIndex[2], textureBindIndex[1], TEST_LOCATION);
2115
2116   END_TEST;
2117 }
2118
2119 int UtcDaliRendererRenderOrder2DLayerSiblingOrder(void)
2120 {
2121   TestApplication application;
2122   tet_infoline("Test the rendering order in a 2D layer is correct using sibling order");
2123
2124   /*
2125    * Creates the following hierarchy:
2126    *
2127    *                            Layer
2128    *                           /    \
2129    *                         /        \
2130    *                       /            \
2131    *                     /                \
2132    *                   /                    \
2133    *             actor0 (SIBLING_ORDER:1)     actor1 (SIBLING_ORDER:0)
2134    *            /   |   \                    /   |   \
2135    *          /     |     \                /     |     \
2136    *        /       |       \            /       |       \
2137    * renderer0 renderer1  actor2     renderer2 renderer3 renderer4
2138    *    DI:2      DI:0      |           DI:0      DI:1      DI:2
2139    *                        |
2140    *                   renderer5
2141    *                      DI:-1
2142    *
2143    *  actor0 has sibling order 1
2144    *  actor1 has sibling order 0
2145    *  actor2 has sibling order 0
2146    *
2147    *  renderer0 has depth index 2
2148    *  renderer1 has depth index 0
2149    *
2150    *  renderer2 has depth index 0
2151    *  renderer3 has depth index 1
2152    *  renderer4 has depth index 2
2153    *
2154    *  renderer5 has depth index -1
2155    *
2156    *  Expected rendering order: renderer2 - renderer3 - renderer4 - renderer1 - renderer0 - renderer5
2157    */
2158
2159   Shader   shader   = Shader::New("VertexSource", "FragmentSource");
2160   Geometry geometry = CreateQuadGeometry();
2161   Actor    root     = application.GetScene().GetRootLayer();
2162   Actor    actor0   = CreateActor(root, 1, TEST_LOCATION);
2163   Actor    actor1   = CreateActor(root, 0, TEST_LOCATION);
2164   Actor    actor2   = CreateActor(actor0, 0, TEST_LOCATION);
2165
2166   Renderer renderer0 = CreateRenderer(actor0, geometry, shader, 2);
2167   Renderer renderer1 = CreateRenderer(actor0, geometry, shader, 0);
2168   Renderer renderer2 = CreateRenderer(actor1, geometry, shader, 0);
2169   Renderer renderer3 = CreateRenderer(actor1, geometry, shader, 1);
2170   Renderer renderer4 = CreateRenderer(actor1, geometry, shader, 2);
2171   Renderer renderer5 = CreateRenderer(actor2, geometry, shader, -1);
2172
2173   application.SendNotification();
2174   application.Render();
2175
2176   TestGlAbstraction& gl = application.GetGlAbstraction();
2177   gl.GetTextureTrace().Reset();
2178   gl.EnableTextureCallTrace(true);
2179   application.SendNotification();
2180   application.Render(0);
2181
2182   int textureBindIndex[6];
2183   for(unsigned int i(0); i < 6; ++i)
2184   {
2185     std::stringstream params;
2186     params << std::hex << GL_TEXTURE_2D << std::dec << ", " << i + 1;
2187     textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str());
2188   }
2189
2190   DALI_TEST_EQUALS(textureBindIndex[2], 0, TEST_LOCATION);
2191   DALI_TEST_EQUALS(textureBindIndex[3], 1, TEST_LOCATION);
2192   DALI_TEST_EQUALS(textureBindIndex[4], 2, TEST_LOCATION);
2193   DALI_TEST_EQUALS(textureBindIndex[1], 3, TEST_LOCATION);
2194   DALI_TEST_EQUALS(textureBindIndex[0], 4, TEST_LOCATION);
2195   DALI_TEST_EQUALS(textureBindIndex[5], 5, TEST_LOCATION);
2196
2197   // Change sibling order of actor1
2198   // New Expected rendering order: renderer1 - renderer0 - renderer 5 - renderer2 - renderer3 - renderer4
2199   actor1.SetProperty(Dali::DevelActor::Property::SIBLING_ORDER, 2);
2200
2201   gl.GetTextureTrace().Reset();
2202   application.SendNotification();
2203   application.Render(0);
2204
2205   for(unsigned int i(0); i < 6; ++i)
2206   {
2207     std::stringstream params;
2208     params << std::hex << GL_TEXTURE_2D << std::dec << ", " << i + 1;
2209     textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str());
2210   }
2211
2212   DALI_TEST_EQUALS(textureBindIndex[1], 0, TEST_LOCATION);
2213   DALI_TEST_EQUALS(textureBindIndex[0], 1, TEST_LOCATION);
2214   DALI_TEST_EQUALS(textureBindIndex[5], 2, TEST_LOCATION);
2215   DALI_TEST_EQUALS(textureBindIndex[2], 3, TEST_LOCATION);
2216   DALI_TEST_EQUALS(textureBindIndex[3], 4, TEST_LOCATION);
2217   DALI_TEST_EQUALS(textureBindIndex[4], 5, TEST_LOCATION);
2218
2219   END_TEST;
2220 }
2221
2222 int UtcDaliRendererRenderOrder2DLayerOverlay(void)
2223 {
2224   TestApplication application;
2225   tet_infoline("Test the rendering order in a 2D layer is correct for overlays");
2226
2227   Shader   shader   = Shader::New("VertexSource", "FragmentSource");
2228   Geometry geometry = CreateQuadGeometry();
2229   Actor    root     = application.GetScene().GetRootLayer();
2230
2231   /*
2232    * Create the following hierarchy:
2233    *
2234    *               actor2
2235    *             (Regular actor)
2236    *              /      \
2237    *             /        \
2238    *         actor1       actor4
2239    *       (Overlay)     (Regular actor)
2240    *          /
2241    *         /
2242    *     actor0
2243    *    (Overlay)
2244    *      /
2245    *     /
2246    *  actor3
2247    * (Overlay)
2248    *
2249    *  Expected rendering order : actor2 - actor4 - actor1 - actor0 - actor3
2250    */
2251
2252   Actor actor0 = CreateActor(root, 0, TEST_LOCATION);
2253   actor0.SetProperty(Actor::Property::DRAW_MODE, DrawMode::OVERLAY_2D);
2254   Renderer renderer0 = CreateRenderer(actor0, geometry, shader, 0);
2255
2256   Actor actor1 = CreateActor(root, 0, TEST_LOCATION);
2257   actor1.SetProperty(Actor::Property::DRAW_MODE, DrawMode::OVERLAY_2D);
2258   Renderer renderer1 = CreateRenderer(actor1, geometry, shader, 0);
2259
2260   Actor    actor2    = CreateActor(root, 0, TEST_LOCATION);
2261   Renderer renderer2 = CreateRenderer(actor2, geometry, shader, 0);
2262
2263   Actor actor3 = CreateActor(root, 0, TEST_LOCATION);
2264   actor3.SetProperty(Actor::Property::DRAW_MODE, DrawMode::OVERLAY_2D);
2265   Renderer renderer3 = CreateRenderer(actor3, geometry, shader, 0);
2266
2267   Actor    actor4    = CreateActor(root, 0, TEST_LOCATION);
2268   Renderer renderer4 = CreateRenderer(actor4, geometry, shader, 0);
2269
2270   application.SendNotification();
2271   application.Render(0);
2272
2273   actor2.Add(actor1);
2274   actor2.Add(actor4);
2275   actor1.Add(actor0);
2276   actor0.Add(actor3);
2277
2278   TestGlAbstraction& gl = application.GetGlAbstraction();
2279   gl.GetTextureTrace().Reset();
2280   gl.EnableTextureCallTrace(true);
2281   application.SendNotification();
2282   application.Render(0);
2283
2284   int textureBindIndex[5];
2285   for(unsigned int i(0); i < 5; ++i)
2286   {
2287     std::stringstream params;
2288     params << std::hex << GL_TEXTURE_2D << std::dec << ", " << i + 1;
2289     textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str());
2290   }
2291
2292   //Check that actor4 has been rendered after actor2
2293   DALI_TEST_GREATER(textureBindIndex[4], textureBindIndex[2], TEST_LOCATION);
2294
2295   //Check that actor1 has been rendered after actor4
2296   DALI_TEST_GREATER(textureBindIndex[1], textureBindIndex[4], TEST_LOCATION);
2297
2298   //Check that actor0 has been rendered after actor1
2299   DALI_TEST_GREATER(textureBindIndex[0], textureBindIndex[1], TEST_LOCATION);
2300
2301   //Check that actor3 has been rendered after actor0
2302   DALI_TEST_GREATER(textureBindIndex[3], textureBindIndex[0], TEST_LOCATION);
2303
2304   END_TEST;
2305 }
2306
2307 int UtcDaliRendererRenderOrder3DLayer(void)
2308 {
2309   TestApplication application;
2310   tet_infoline("Test the rendering order in a 3D layer is correct");
2311
2312   Shader   shader   = Shader::New("VertexSource", "FragmentSource");
2313   Geometry geometry = CreateQuadGeometry();
2314
2315   application.GetScene().GetRootLayer().SetProperty(Layer::Property::BEHAVIOR, Layer::Behavior::LAYER_3D);
2316   Actor root = application.GetScene().GetRootLayer();
2317
2318   Actor    actor0    = CreateActor(root, 0, TEST_LOCATION);
2319   Renderer renderer0 = CreateRenderer(actor0, geometry, shader, 300);
2320   actor0.SetProperty(Dali::Actor::Property::COLOR_MODE, USE_OWN_COLOR);
2321
2322   Actor    actor1    = CreateActor(root, 0, TEST_LOCATION);
2323   Renderer renderer1 = CreateRenderer(actor1, geometry, shader, 200);
2324   actor1.SetProperty(Dali::Actor::Property::OPACITY, 0.5f);
2325   actor1.SetProperty(Dali::Actor::Property::COLOR_MODE, USE_OWN_COLOR);
2326
2327   Actor    actor2    = CreateActor(root, 0, TEST_LOCATION);
2328   Renderer renderer2 = CreateRenderer(actor2, geometry, shader, 100);
2329   actor2.SetProperty(Dali::Actor::Property::OPACITY, 0.5f);
2330   actor2.SetProperty(Dali::Actor::Property::COLOR_MODE, USE_OWN_COLOR);
2331
2332   Actor    actor3    = CreateActor(root, 0, TEST_LOCATION);
2333   Renderer renderer3 = CreateRenderer(actor3, geometry, shader, 0);
2334   actor3.SetProperty(Dali::Actor::Property::OPACITY, 0.5f);
2335   actor3.SetProperty(Dali::Actor::Property::COLOR_MODE, USE_OWN_COLOR);
2336
2337   application.SendNotification();
2338   application.Render(0);
2339
2340   /*
2341    * Create the following hierarchy:
2342    *
2343    *            actor2
2344    *              /
2345    *             /
2346    *          actor1
2347    *           /
2348    *          /
2349    *       actor0
2350    *        /
2351    *       /
2352    *    actor3
2353    *
2354    *  Expected rendering order : actor0 - actor3 - actor2 - actor1
2355    */
2356   actor2.Add(actor1);
2357   actor1.Add(actor0);
2358   actor0.Add(actor3);
2359   application.SendNotification();
2360   application.Render(0);
2361
2362   TestGlAbstraction& gl = application.GetGlAbstraction();
2363   gl.GetTextureTrace().Reset();
2364   gl.EnableTextureCallTrace(true);
2365   application.SendNotification();
2366   application.Render(0);
2367
2368   int textureBindIndex[4];
2369   for(unsigned int i(0); i < 4; ++i)
2370   {
2371     std::stringstream params;
2372     params << std::hex << GL_TEXTURE_2D << std::dec << ", " << i + 1;
2373     textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str());
2374   }
2375
2376   //Check that actor3 has been rendered after actor0
2377   DALI_TEST_GREATER(textureBindIndex[3], textureBindIndex[0], TEST_LOCATION);
2378
2379   //Check that actor2 has been rendered after actor3
2380   DALI_TEST_GREATER(textureBindIndex[2], textureBindIndex[3], TEST_LOCATION);
2381
2382   //Check that actor1 has been rendered after actor2
2383   DALI_TEST_GREATER(textureBindIndex[1], textureBindIndex[2], TEST_LOCATION);
2384
2385   END_TEST;
2386 }
2387
2388 int UtcDaliRendererSetIndexRange(void)
2389 {
2390   std::string
2391     vertexShader(
2392       "attribute vec2 aPosition;\n"
2393       "void main()\n"
2394       "{\n"
2395       "  gl_Position = aPosition;\n"
2396       "}"),
2397     fragmentShader(
2398       "void main()\n"
2399       "{\n"
2400       "  gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0)\n"
2401       "}\n");
2402
2403   TestApplication application;
2404   tet_infoline("Test setting the range of indices to draw");
2405
2406   TestGlAbstraction& gl = application.GetGlAbstraction();
2407   gl.EnableDrawCallTrace(true);
2408
2409   Actor actor = Actor::New();
2410   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2411
2412   // create geometry
2413   Geometry geometry = Geometry::New();
2414   geometry.SetType(Geometry::LINE_LOOP);
2415
2416   // --------------------------------------------------------------------------
2417   // index buffer
2418   unsigned short indices[] = {0, 2, 4, 6, 8, // offset = 0, count = 5
2419                               0,
2420                               1,
2421                               2,
2422                               3,
2423                               4,
2424                               5,
2425                               6,
2426                               7,
2427                               8,
2428                               9, // offset = 5, count = 10
2429                               1,
2430                               3,
2431                               5,
2432                               7,
2433                               9,
2434                               1}; // offset = 15,  count = 6 // line strip
2435
2436   // --------------------------------------------------------------------------
2437   // vertex buffer
2438   struct Vertex
2439   {
2440     Vector2 position;
2441   };
2442   Vertex shapes[] =
2443     {
2444       // pentagon                   // star
2445       {Vector2(0.0f, 1.00f)},
2446       {Vector2(0.0f, -1.00f)},
2447       {Vector2(-0.95f, 0.31f)},
2448       {Vector2(0.59f, 0.81f)},
2449       {Vector2(-0.59f, -0.81f)},
2450       {Vector2(-0.95f, -0.31f)},
2451       {Vector2(0.59f, -0.81f)},
2452       {Vector2(0.95f, -0.31f)},
2453       {Vector2(0.95f, 0.31f)},
2454       {Vector2(-0.59f, 0.81f)},
2455     };
2456   Property::Map vertexFormat;
2457   vertexFormat["aPosition"] = Property::VECTOR2;
2458   VertexBuffer vertexBuffer = VertexBuffer::New(vertexFormat);
2459   vertexBuffer.SetData(shapes, sizeof(shapes) / sizeof(shapes[0]));
2460
2461   // --------------------------------------------------------------------------
2462   geometry.SetIndexBuffer(indices, sizeof(indices) / sizeof(indices[0]));
2463   geometry.AddVertexBuffer(vertexBuffer);
2464
2465   // create shader
2466   Shader   shader   = Shader::New(vertexShader, fragmentShader);
2467   Renderer renderer = Renderer::New(geometry, shader);
2468   actor.AddRenderer(renderer);
2469
2470   Integration::Scene scene = application.GetScene();
2471   scene.Add(actor);
2472
2473   char buffer[128];
2474
2475   // LINE_LOOP, first 0, count 5
2476   {
2477     renderer.SetIndexRange(0, 5);
2478     application.SendNotification();
2479     application.Render();
2480
2481     Property::Value value = renderer.GetProperty(Renderer::Property::INDEX_RANGE_FIRST);
2482     int             convertedValue;
2483     DALI_TEST_CHECK(value.Get(convertedValue));
2484     DALI_TEST_CHECK(convertedValue == 0);
2485
2486     value = renderer.GetCurrentProperty(Renderer::Property::INDEX_RANGE_FIRST);
2487     DALI_TEST_CHECK(value.Get(convertedValue));
2488     DALI_TEST_CHECK(convertedValue == 0);
2489
2490     value = renderer.GetProperty(Renderer::Property::INDEX_RANGE_COUNT);
2491     DALI_TEST_CHECK(value.Get(convertedValue));
2492     DALI_TEST_CHECK(convertedValue == 5);
2493
2494     value = renderer.GetCurrentProperty(Renderer::Property::INDEX_RANGE_COUNT);
2495     DALI_TEST_CHECK(value.Get(convertedValue));
2496     DALI_TEST_CHECK(convertedValue == 5);
2497
2498     sprintf(buffer, "%u, 5, %u, indices", GL_LINE_LOOP, GL_UNSIGNED_SHORT);
2499     bool result = gl.GetDrawTrace().FindMethodAndParams("DrawElements", buffer);
2500     DALI_TEST_CHECK(result);
2501   }
2502
2503   // LINE_LOOP, first 5, count 10
2504   {
2505     renderer.SetIndexRange(5, 10);
2506     sprintf(buffer, "%u, 10, %u, indices", GL_LINE_LOOP, GL_UNSIGNED_SHORT);
2507     application.SendNotification();
2508     application.Render();
2509     bool result = gl.GetDrawTrace().FindMethodAndParams("DrawElements", buffer);
2510     DALI_TEST_CHECK(result);
2511   }
2512
2513   // LINE_STRIP, first 15, count 6
2514   {
2515     renderer.SetIndexRange(15, 6);
2516     geometry.SetType(Geometry::LINE_STRIP);
2517     sprintf(buffer, "%u, 6, %u, indices", GL_LINE_STRIP, GL_UNSIGNED_SHORT);
2518     application.SendNotification();
2519     application.Render();
2520     bool result = gl.GetDrawTrace().FindMethodAndParams("DrawElements", buffer);
2521     DALI_TEST_CHECK(result);
2522   }
2523
2524   // Index out of bounds
2525   {
2526     renderer.SetIndexRange(15, 30);
2527     geometry.SetType(Geometry::LINE_STRIP);
2528     sprintf(buffer, "%u, 6, %u, indices", GL_LINE_STRIP, GL_UNSIGNED_SHORT);
2529     application.SendNotification();
2530     application.Render();
2531     bool result = gl.GetDrawTrace().FindMethodAndParams("DrawElements", buffer);
2532     DALI_TEST_CHECK(result);
2533   }
2534
2535   // drawing whole buffer starting from 15 ( last valid primitive )
2536   {
2537     renderer.SetIndexRange(15, 0);
2538     geometry.SetType(Geometry::LINE_STRIP);
2539     sprintf(buffer, "%u, 6, %u, indices", GL_LINE_STRIP, GL_UNSIGNED_SHORT);
2540     application.SendNotification();
2541     application.Render();
2542     bool result = gl.GetDrawTrace().FindMethodAndParams("DrawElements", buffer);
2543     DALI_TEST_CHECK(result);
2544   }
2545
2546   END_TEST;
2547 }
2548
2549 int UtcDaliRendererSetDepthFunction(void)
2550 {
2551   TestApplication application;
2552
2553   tet_infoline("Test setting the depth function");
2554
2555   Geometry geometry = CreateQuadGeometry();
2556   Shader   shader   = CreateShader();
2557   Renderer renderer = Renderer::New(geometry, shader);
2558
2559   Actor actor = Actor::New();
2560   actor.AddRenderer(renderer);
2561   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
2562   Integration::Scene scene = application.GetScene();
2563   scene.GetRootLayer().SetProperty(Layer::Property::BEHAVIOR, Layer::LAYER_3D);
2564   scene.Add(actor);
2565
2566   TestGlAbstraction& glAbstraction        = application.GetGlAbstraction();
2567   TraceCallStack&    glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2568   TraceCallStack&    glDepthFunctionStack = glAbstraction.GetDepthFunctionTrace();
2569
2570   glEnableDisableStack.Enable(true);
2571   glDepthFunctionStack.Enable(true);
2572   glEnableDisableStack.EnableLogging(true);
2573   glDepthFunctionStack.EnableLogging(true);
2574
2575   std::ostringstream depthTestStr;
2576   depthTestStr << std::hex << GL_DEPTH_TEST;
2577
2578   //GL_NEVER
2579   {
2580     renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::NEVER);
2581
2582     glEnableDisableStack.Reset();
2583     glDepthFunctionStack.Reset();
2584     application.SendNotification();
2585     application.Render();
2586
2587     DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Enable", depthTestStr.str().c_str()));
2588     std::ostringstream depthFunctionStr;
2589     depthFunctionStr << std::hex << GL_NEVER;
2590     DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2591   }
2592
2593   //GL_ALWAYS
2594   {
2595     renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::ALWAYS);
2596
2597     glDepthFunctionStack.Reset();
2598     application.SendNotification();
2599     application.Render();
2600
2601     std::ostringstream depthFunctionStr;
2602     depthFunctionStr << std::hex << GL_ALWAYS;
2603     DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2604   }
2605
2606   //GL_LESS
2607   {
2608     renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::LESS);
2609
2610     glDepthFunctionStack.Reset();
2611     application.SendNotification();
2612     application.Render();
2613
2614     std::ostringstream depthFunctionStr;
2615     depthFunctionStr << std::hex << GL_LESS;
2616     DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2617   }
2618
2619   //GL_GREATER
2620   {
2621     renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::GREATER);
2622
2623     glDepthFunctionStack.Reset();
2624     application.SendNotification();
2625     application.Render();
2626
2627     std::ostringstream depthFunctionStr;
2628     depthFunctionStr << std::hex << GL_GREATER;
2629     DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2630   }
2631
2632   //GL_EQUAL
2633   {
2634     renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::EQUAL);
2635
2636     glDepthFunctionStack.Reset();
2637     application.SendNotification();
2638     application.Render();
2639
2640     std::ostringstream depthFunctionStr;
2641     depthFunctionStr << std::hex << GL_EQUAL;
2642     DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2643   }
2644
2645   //GL_NOTEQUAL
2646   {
2647     renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::NOT_EQUAL);
2648
2649     glDepthFunctionStack.Reset();
2650     application.SendNotification();
2651     application.Render();
2652
2653     std::ostringstream depthFunctionStr;
2654     depthFunctionStr << std::hex << GL_NOTEQUAL;
2655     DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2656   }
2657
2658   //GL_LEQUAL
2659   {
2660     renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::LESS_EQUAL);
2661
2662     glDepthFunctionStack.Reset();
2663     application.SendNotification();
2664     application.Render();
2665
2666     std::ostringstream depthFunctionStr;
2667     depthFunctionStr << std::hex << GL_LEQUAL;
2668     DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2669   }
2670
2671   //GL_GEQUAL
2672   {
2673     renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::GREATER_EQUAL);
2674
2675     glDepthFunctionStack.Reset();
2676     application.SendNotification();
2677     application.Render();
2678
2679     std::ostringstream depthFunctionStr;
2680     depthFunctionStr << std::hex << GL_GEQUAL;
2681     DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2682   }
2683
2684   END_TEST;
2685 }
2686
2687 /**
2688  * @brief This templatized function checks an enumeration property is setting and getting correctly.
2689  * The checks performed are as follows:
2690  *  - Check the initial/default value.
2691  *  - Set a different value via enum.
2692  *  - Check it was set.
2693  *  - Set a different value via string.
2694  *  - Check it was set.
2695  */
2696 template<typename T>
2697 void CheckEnumerationProperty(TestApplication& application, Renderer& renderer, Property::Index propertyIndex, T initialValue, T firstCheckEnumeration, T secondCheckEnumeration, std::string secondCheckString)
2698 {
2699   application.SendNotification();
2700   application.Render();
2701
2702   DALI_TEST_CHECK(renderer.GetProperty<int>(propertyIndex) == static_cast<int>(initialValue));
2703   DALI_TEST_CHECK(renderer.GetCurrentProperty<int>(propertyIndex) == static_cast<int>(initialValue));
2704   renderer.SetProperty(propertyIndex, firstCheckEnumeration);
2705   DALI_TEST_CHECK(renderer.GetProperty<int>(propertyIndex) == static_cast<int>(firstCheckEnumeration));
2706   DALI_TEST_CHECK(renderer.GetCurrentProperty<int>(propertyIndex) != static_cast<int>(firstCheckEnumeration));
2707
2708   application.SendNotification();
2709   application.Render();
2710
2711   DALI_TEST_CHECK(renderer.GetProperty<int>(propertyIndex) == static_cast<int>(firstCheckEnumeration));
2712   DALI_TEST_CHECK(renderer.GetCurrentProperty<int>(propertyIndex) == static_cast<int>(firstCheckEnumeration));
2713
2714   renderer.SetProperty(propertyIndex, secondCheckString);
2715   DALI_TEST_CHECK(renderer.GetProperty<int>(propertyIndex) == static_cast<int>(secondCheckEnumeration));
2716   DALI_TEST_CHECK(renderer.GetCurrentProperty<int>(propertyIndex) != static_cast<int>(secondCheckEnumeration));
2717
2718   application.SendNotification();
2719   application.Render();
2720
2721   DALI_TEST_CHECK(renderer.GetProperty<int>(propertyIndex) == static_cast<int>(secondCheckEnumeration));
2722   DALI_TEST_CHECK(renderer.GetCurrentProperty<int>(propertyIndex) == static_cast<int>(secondCheckEnumeration));
2723 }
2724
2725 int UtcDaliRendererEnumProperties(void)
2726 {
2727   TestApplication application;
2728   tet_infoline("Test Renderer enumeration properties can be set with both integer and string values");
2729
2730   Geometry geometry = CreateQuadGeometry();
2731   Shader   shader   = CreateShader();
2732   Renderer renderer = Renderer::New(geometry, shader);
2733
2734   Actor actor = Actor::New();
2735   actor.AddRenderer(renderer);
2736   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
2737   application.GetScene().Add(actor);
2738
2739   /*
2740    * Here we use a templatized function to perform several checks on each enumeration property.
2741    * @see CheckEnumerationProperty for details of the checks performed.
2742    */
2743
2744   CheckEnumerationProperty<FaceCullingMode::Type>(application, renderer, Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::NONE, FaceCullingMode::FRONT, FaceCullingMode::BACK, "BACK");
2745   CheckEnumerationProperty<BlendMode::Type>(application, renderer, Renderer::Property::BLEND_MODE, BlendMode::AUTO, BlendMode::OFF, BlendMode::ON, "ON");
2746   CheckEnumerationProperty<BlendEquation::Type>(application, renderer, Renderer::Property::BLEND_EQUATION_RGB, BlendEquation::ADD, BlendEquation::SUBTRACT, BlendEquation::REVERSE_SUBTRACT, "REVERSE_SUBTRACT");
2747   CheckEnumerationProperty<BlendEquation::Type>(application, renderer, Renderer::Property::BLEND_EQUATION_ALPHA, BlendEquation::ADD, BlendEquation::SUBTRACT, BlendEquation::REVERSE_SUBTRACT, "REVERSE_SUBTRACT");
2748   CheckEnumerationProperty<BlendFactor::Type>(application, renderer, Renderer::Property::BLEND_FACTOR_SRC_RGB, BlendFactor::SRC_ALPHA, BlendFactor::ONE, BlendFactor::SRC_COLOR, "SRC_COLOR");
2749   CheckEnumerationProperty<BlendFactor::Type>(application, renderer, Renderer::Property::BLEND_FACTOR_DEST_RGB, BlendFactor::ONE_MINUS_SRC_ALPHA, BlendFactor::ONE, BlendFactor::SRC_COLOR, "SRC_COLOR");
2750   CheckEnumerationProperty<BlendFactor::Type>(application, renderer, Renderer::Property::BLEND_FACTOR_SRC_ALPHA, BlendFactor::ONE, BlendFactor::ONE_MINUS_SRC_ALPHA, BlendFactor::SRC_COLOR, "SRC_COLOR");
2751   CheckEnumerationProperty<BlendFactor::Type>(application, renderer, Renderer::Property::BLEND_FACTOR_DEST_ALPHA, BlendFactor::ONE_MINUS_SRC_ALPHA, BlendFactor::ONE, BlendFactor::SRC_COLOR, "SRC_COLOR");
2752   CheckEnumerationProperty<DepthWriteMode::Type>(application, renderer, Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::AUTO, DepthWriteMode::OFF, DepthWriteMode::ON, "ON");
2753   CheckEnumerationProperty<DepthFunction::Type>(application, renderer, Renderer::Property::DEPTH_FUNCTION, DepthFunction::LESS, DepthFunction::ALWAYS, DepthFunction::GREATER, "GREATER");
2754   CheckEnumerationProperty<DepthTestMode::Type>(application, renderer, Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::AUTO, DepthTestMode::OFF, DepthTestMode::ON, "ON");
2755   CheckEnumerationProperty<StencilFunction::Type>(application, renderer, Renderer::Property::STENCIL_FUNCTION, StencilFunction::ALWAYS, StencilFunction::LESS, StencilFunction::EQUAL, "EQUAL");
2756   CheckEnumerationProperty<RenderMode::Type>(application, renderer, Renderer::Property::RENDER_MODE, RenderMode::AUTO, RenderMode::NONE, RenderMode::STENCIL, "STENCIL");
2757   CheckEnumerationProperty<StencilOperation::Type>(application, renderer, Renderer::Property::STENCIL_OPERATION_ON_FAIL, StencilOperation::KEEP, StencilOperation::REPLACE, StencilOperation::INCREMENT, "INCREMENT");
2758   CheckEnumerationProperty<StencilOperation::Type>(application, renderer, Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, StencilOperation::KEEP, StencilOperation::REPLACE, StencilOperation::INCREMENT, "INCREMENT");
2759   CheckEnumerationProperty<StencilOperation::Type>(application, renderer, Renderer::Property::STENCIL_OPERATION_ON_Z_PASS, StencilOperation::KEEP, StencilOperation::REPLACE, StencilOperation::INCREMENT, "INCREMENT");
2760
2761   if(Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::MAX) &&
2762      Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::MIN))
2763   {
2764     application.SendNotification();
2765     application.Render();
2766     CheckEnumerationProperty<DevelBlendEquation::Type>(application, renderer, DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::REVERSE_SUBTRACT, DevelBlendEquation::MAX, DevelBlendEquation::MIN, "MIN");
2767   }
2768
2769   if(Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::SCREEN))
2770   {
2771     application.SendNotification();
2772     application.Render();
2773     CheckEnumerationProperty<DevelBlendEquation::Type>(application, renderer, DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::MIN, DevelBlendEquation::MULTIPLY, DevelBlendEquation::SCREEN, "SCREEN");
2774   }
2775
2776   END_TEST;
2777 }
2778
2779 Renderer RendererTestFixture(TestApplication& application)
2780 {
2781   Geometry geometry = CreateQuadGeometry();
2782   Shader   shader   = CreateShader();
2783   Renderer renderer = Renderer::New(geometry, shader);
2784
2785   Actor actor = Actor::New();
2786   actor.AddRenderer(renderer);
2787   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
2788   Integration::Scene scene = application.GetScene();
2789   scene.GetRootLayer().SetProperty(Layer::Property::BEHAVIOR, Layer::LAYER_3D);
2790   scene.Add(actor);
2791
2792   return renderer;
2793 }
2794
2795 int UtcDaliRendererSetDepthTestMode(void)
2796 {
2797   TestApplication application;
2798   tet_infoline("Test setting the DepthTestMode");
2799
2800   Renderer           renderer             = RendererTestFixture(application);
2801   TestGlAbstraction& glAbstraction        = application.GetGlAbstraction();
2802   TraceCallStack&    glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2803   glEnableDisableStack.Enable(true);
2804   glEnableDisableStack.EnableLogging(true);
2805
2806   glEnableDisableStack.Reset();
2807   application.SendNotification();
2808   application.Render();
2809
2810   // Check depth-test is enabled by default.
2811   DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Enable", GetDepthTestString()));
2812   DALI_TEST_CHECK(!glEnableDisableStack.FindMethodAndParams("Disable", GetDepthTestString()));
2813
2814   // 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.
2815   renderer.SetProperty(Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::OFF);
2816   renderer.SetProperty(Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::OFF);
2817
2818   glEnableDisableStack.Reset();
2819   application.SendNotification();
2820   application.Render();
2821
2822   // Check the depth buffer was disabled.
2823   DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Disable", GetDepthTestString()));
2824
2825   // Turn on automatic mode depth-testing.
2826   // Layer behavior is currently set to LAYER_3D so AUTO should enable depth-testing.
2827   renderer.SetProperty(Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::AUTO);
2828
2829   glEnableDisableStack.Reset();
2830   application.SendNotification();
2831   application.Render();
2832
2833   // Check depth-test is now enabled.
2834   DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Enable", GetDepthTestString()));
2835   DALI_TEST_CHECK(!glEnableDisableStack.FindMethodAndParams("Disable", GetDepthTestString()));
2836
2837   // Change the layer behavior to LAYER_UI.
2838   // Note this will also disable depth testing for the layer by default, we test this first.
2839   application.GetScene().GetRootLayer().SetProperty(Layer::Property::BEHAVIOR, Layer::LAYER_UI);
2840
2841   glEnableDisableStack.Reset();
2842   application.SendNotification();
2843   application.Render();
2844
2845   // Check depth-test is disabled.
2846   DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Disable", GetDepthTestString()));
2847
2848   // Turn the layer depth-test flag back on, and confirm that depth testing is now on.
2849   application.GetScene().GetRootLayer().SetProperty(Layer::Property::DEPTH_TEST, true);
2850
2851   glEnableDisableStack.Reset();
2852   application.SendNotification();
2853   application.Render();
2854
2855   // Check depth-test is *still* disabled.
2856   DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Enable", GetDepthTestString()));
2857
2858   END_TEST;
2859 }
2860
2861 int UtcDaliRendererSetDepthWriteMode(void)
2862 {
2863   TestApplication application;
2864   tet_infoline("Test setting the DepthWriteMode");
2865
2866   Renderer           renderer      = RendererTestFixture(application);
2867   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2868
2869   application.SendNotification();
2870   application.Render();
2871
2872   // Check the default depth-write status first.
2873   DALI_TEST_CHECK(glAbstraction.GetLastDepthMask());
2874
2875   // Turn off depth-writing.
2876   renderer.SetProperty(Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::OFF);
2877
2878   application.SendNotification();
2879   application.Render();
2880
2881   // Check depth-write is now disabled.
2882   DALI_TEST_CHECK(!glAbstraction.GetLastDepthMask());
2883
2884   // Test the AUTO mode for depth-writing.
2885   // As our renderer is opaque, depth-testing should be enabled.
2886   renderer.SetProperty(Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::AUTO);
2887
2888   application.SendNotification();
2889   application.Render();
2890
2891   // Check depth-write is now enabled.
2892   DALI_TEST_CHECK(glAbstraction.GetLastDepthMask());
2893
2894   // Now make the renderer be treated as translucent by enabling blending.
2895   // The AUTO depth-write mode should turn depth-write off in this scenario.
2896   renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON);
2897
2898   application.SendNotification();
2899   application.Render();
2900
2901   // Check depth-write is now disabled.
2902   DALI_TEST_CHECK(!glAbstraction.GetLastDepthMask());
2903
2904   END_TEST;
2905 }
2906
2907 int UtcDaliRendererBlendModeUseActorOpacity(void)
2908 {
2909   TestApplication application;
2910   tet_infoline("Test setting the UseActorOpacity");
2911
2912   Geometry geometry = CreateQuadGeometry();
2913   Shader   shader   = CreateShader();
2914   Renderer renderer = Renderer::New(geometry, shader);
2915
2916   Actor actor = Actor::New();
2917   actor.AddRenderer(renderer);
2918   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
2919   Integration::Scene scene = application.GetScene();
2920   scene.GetRootLayer().SetProperty(Layer::Property::BEHAVIOR, Layer::LAYER_3D);
2921   scene.Add(actor);
2922
2923   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2924   renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::USE_ACTOR_OPACITY);
2925   actor.AddRenderer(renderer);
2926   application.GetScene().Add(actor);
2927
2928   application.SendNotification();
2929   application.Render();
2930
2931   // Check the default depth-write status first.
2932   DALI_TEST_CHECK(glAbstraction.GetLastDepthMask());
2933
2934   // Turn off depth-writing.
2935   actor.SetProperty(Dali::Actor::Property::COLOR, Vector4(1, 1, 1, 0.5));
2936
2937   application.SendNotification();
2938   application.Render();
2939
2940   // Check depth-write is now disabled.
2941   DALI_TEST_CHECK(!glAbstraction.GetLastDepthMask());
2942
2943   // Turn on depth-writing.
2944   actor.SetProperty(Dali::Actor::Property::COLOR, Vector4(1, 1, 1, 1));
2945
2946   application.SendNotification();
2947   application.Render();
2948
2949   // Check depth-write is now enabled.
2950   DALI_TEST_CHECK(glAbstraction.GetLastDepthMask());
2951
2952   // Turn off depth-writing.
2953   actor.SetProperty(Dali::Actor::Property::COLOR, Vector4(1, 1, 1, 0.0));
2954
2955   application.SendNotification();
2956   application.Render();
2957
2958   // if actor alpha is 0, SetDepthWriteEnable is not called so GetLastDepthMask returns default value true;
2959   DALI_TEST_CHECK(glAbstraction.GetLastDepthMask());
2960
2961   END_TEST;
2962 }
2963
2964 int UtcDaliRendererCheckStencilDefaults(void)
2965 {
2966   TestApplication application;
2967   tet_infoline("Test the stencil defaults");
2968
2969   Renderer           renderer               = RendererTestFixture(application);
2970   TestGlAbstraction& glAbstraction          = application.GetGlAbstraction();
2971   TraceCallStack&    glEnableDisableStack   = glAbstraction.GetEnableDisableTrace();
2972   TraceCallStack&    glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2973   glEnableDisableStack.Enable(true);
2974   glEnableDisableStack.EnableLogging(true);
2975   glStencilFunctionStack.Enable(true);
2976   glStencilFunctionStack.EnableLogging(true);
2977
2978   ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2979
2980   // Check the defaults:
2981   DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_FUNCTION).Get<int>()), static_cast<int>(StencilFunction::ALWAYS), TEST_LOCATION);
2982   DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_FUNCTION_MASK).Get<int>()), 0xFF, TEST_LOCATION);
2983   DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_FUNCTION_REFERENCE).Get<int>()), 0x00, TEST_LOCATION);
2984   DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_MASK).Get<int>()), 0xFF, TEST_LOCATION);
2985   DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_OPERATION_ON_FAIL).Get<int>()), static_cast<int>(StencilOperation::KEEP), TEST_LOCATION);
2986   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);
2987   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);
2988
2989   END_TEST;
2990 }
2991
2992 int UtcDaliRendererSetRenderModeToUseStencilBuffer(void)
2993 {
2994   TestApplication application;
2995   tet_infoline("Test setting the RenderMode to use the stencil buffer");
2996
2997   Renderer           renderer               = RendererTestFixture(application);
2998   TestGlAbstraction& glAbstraction          = application.GetGlAbstraction();
2999   TraceCallStack&    glEnableDisableStack   = glAbstraction.GetEnableDisableTrace();
3000   TraceCallStack&    glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
3001   glEnableDisableStack.Enable(true);
3002   glEnableDisableStack.EnableLogging(true);
3003   glStencilFunctionStack.Enable(true);
3004   glStencilFunctionStack.EnableLogging(true);
3005
3006   // Set the StencilFunction to something other than the default, to confirm it is set as a property,
3007   // but NO GL call has been made while the RenderMode is set to not use the stencil buffer.
3008   renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::NONE);
3009   ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
3010
3011   renderer.SetProperty(Renderer::Property::STENCIL_FUNCTION, StencilFunction::NEVER);
3012   DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_FUNCTION).Get<int>()), static_cast<int>(StencilFunction::NEVER), TEST_LOCATION);
3013
3014   ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
3015   std::string methodString("StencilFunc");
3016   DALI_TEST_CHECK(!glStencilFunctionStack.FindMethod(methodString));
3017
3018   // Test the other RenderModes that will not enable the stencil buffer.
3019   renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::AUTO);
3020   ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
3021   DALI_TEST_CHECK(!glStencilFunctionStack.FindMethod(methodString));
3022
3023   renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::COLOR);
3024   ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
3025   DALI_TEST_CHECK(!glStencilFunctionStack.FindMethod(methodString));
3026
3027   // Now set the RenderMode to modes that will use the stencil buffer, and check the StencilFunction has changed.
3028   renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::STENCIL);
3029   ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
3030
3031   DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Enable", GetStencilTestString()));
3032   DALI_TEST_CHECK(glStencilFunctionStack.FindMethod(methodString));
3033
3034   // Test the COLOR_STENCIL RenderMode as it also enables the stencil buffer.
3035   // First set a mode to turn off the stencil buffer, so the enable is required.
3036   renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::COLOR);
3037   ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
3038   renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::COLOR_STENCIL);
3039   // Set a different stencil function as the last one is cached.
3040   renderer.SetProperty(Renderer::Property::STENCIL_FUNCTION, StencilFunction::ALWAYS);
3041   ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
3042
3043   DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Enable", GetStencilTestString()));
3044   DALI_TEST_CHECK(glStencilFunctionStack.FindMethod(methodString));
3045
3046   END_TEST;
3047 }
3048
3049 // Helper function for the SetRenderModeToUseColorBuffer test.
3050 void CheckRenderModeColorMask(TestApplication& application, Renderer& renderer, RenderMode::Type renderMode, bool expectedValue)
3051 {
3052   // Set the RenderMode property to a value that should not allow color buffer writes.
3053   renderer.SetProperty(Renderer::Property::RENDER_MODE, renderMode);
3054   application.SendNotification();
3055   application.Render();
3056
3057   // Check if ColorMask has been called, and that the values are correct.
3058   TestGlAbstraction&                        glAbstraction = application.GetGlAbstraction();
3059   const TestGlAbstraction::ColorMaskParams& colorMaskParams(glAbstraction.GetColorMaskParams());
3060
3061   DALI_TEST_EQUALS<bool>(colorMaskParams.red, expectedValue, TEST_LOCATION);
3062   DALI_TEST_EQUALS<bool>(colorMaskParams.green, expectedValue, TEST_LOCATION);
3063   DALI_TEST_EQUALS<bool>(colorMaskParams.blue, expectedValue, TEST_LOCATION);
3064   // @todo Only check alpha if framebuffer supports it.
3065   //DALI_TEST_EQUALS<bool>(colorMaskParams.alpha, expectedValue, TEST_LOCATION);
3066 }
3067
3068 int UtcDaliRendererSetRenderModeToUseColorBuffer(void)
3069 {
3070   TestApplication application;
3071   tet_infoline("Test setting the RenderMode to use the color buffer");
3072
3073   Renderer renderer = RendererTestFixture(application);
3074
3075   // Set the RenderMode property to a value that should not allow color buffer writes.
3076   // Then check if ColorMask has been called, and that the values are correct.
3077   CheckRenderModeColorMask(application, renderer, RenderMode::AUTO, true);
3078   CheckRenderModeColorMask(application, renderer, RenderMode::NONE, false);
3079   CheckRenderModeColorMask(application, renderer, RenderMode::COLOR, true);
3080   CheckRenderModeColorMask(application, renderer, RenderMode::STENCIL, false);
3081   CheckRenderModeColorMask(application, renderer, RenderMode::COLOR_STENCIL, true);
3082
3083   END_TEST;
3084 }
3085
3086 int UtcDaliRendererSetStencilFunction(void)
3087 {
3088   TestApplication application;
3089   tet_infoline("Test setting the StencilFunction");
3090
3091   Renderer           renderer               = RendererTestFixture(application);
3092   TestGlAbstraction& glAbstraction          = application.GetGlAbstraction();
3093   TraceCallStack&    glEnableDisableStack   = glAbstraction.GetEnableDisableTrace();
3094   TraceCallStack&    glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
3095   glEnableDisableStack.Enable(true);
3096   glEnableDisableStack.EnableLogging(true);
3097   glStencilFunctionStack.Enable(true);
3098   glStencilFunctionStack.EnableLogging(true);
3099
3100   // RenderMode must use the stencil for StencilFunction to operate.
3101   renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::STENCIL);
3102   ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
3103
3104   /*
3105    * Lookup table for testing StencilFunction.
3106    * Note: This MUST be in the same order as the Dali::StencilFunction enum.
3107    */
3108   const int StencilFunctionLookupTable[] = {
3109     GL_NEVER,
3110     GL_LESS,
3111     GL_EQUAL,
3112     GL_LEQUAL,
3113     GL_GREATER,
3114     GL_NOTEQUAL,
3115     GL_GEQUAL,
3116     GL_ALWAYS};
3117   const int StencilFunctionLookupTableCount = sizeof(StencilFunctionLookupTable) / sizeof(StencilFunctionLookupTable[0]);
3118
3119   /*
3120    * Loop through all types of StencilFunction, checking:
3121    *  - The value is cached (set in event thread side)
3122    *  - Causes "glStencilFunc" to be called
3123    *  - Checks the correct parameters to "glStencilFunc" were used
3124    */
3125   std::string nonChangingParameters = "0, 255";
3126   std::string methodString("StencilFunc");
3127   for(int i = 0; i < StencilFunctionLookupTableCount; ++i)
3128   {
3129     // Set the property.
3130     renderer.SetProperty(Renderer::Property::STENCIL_FUNCTION, static_cast<Dali::StencilFunction::Type>(i));
3131
3132     // Check GetProperty returns the same value.
3133     DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_FUNCTION).Get<int>()), i, TEST_LOCATION);
3134
3135     // Reset the trace debug.
3136     ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
3137
3138     // Check the function is called and the parameters are correct.
3139     std::stringstream parameterStream;
3140     parameterStream << StencilFunctionLookupTable[i] << ", " << nonChangingParameters;
3141
3142     DALI_TEST_CHECK(glStencilFunctionStack.FindMethodAndParams(methodString, parameterStream.str()));
3143   }
3144
3145   // Change the Function Reference only and check the behavior is correct:
3146   // 170 is 0xaa in hex / 10101010 in binary (every other bit set).
3147   int testValueReference = 170;
3148   renderer.SetProperty(Renderer::Property::STENCIL_FUNCTION_REFERENCE, testValueReference);
3149
3150   DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_FUNCTION_REFERENCE).Get<int>()), testValueReference, TEST_LOCATION);
3151
3152   ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
3153
3154   DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetCurrentProperty(Renderer::Property::STENCIL_FUNCTION_REFERENCE).Get<int>()), testValueReference, TEST_LOCATION);
3155
3156   std::stringstream parameterStream;
3157   parameterStream << StencilFunctionLookupTable[StencilOperation::DECREMENT_WRAP] << ", " << testValueReference << ", 255";
3158
3159   DALI_TEST_CHECK(glStencilFunctionStack.FindMethodAndParams(methodString, parameterStream.str()));
3160
3161   // Change the Function Mask only and check the behavior is correct:
3162   // 85 is 0x55 in hex / 01010101 in binary (every other bit set).
3163   int testValueMask = 85;
3164   renderer.SetProperty(Renderer::Property::STENCIL_FUNCTION_MASK, testValueMask);
3165
3166   DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_FUNCTION_MASK).Get<int>()), testValueMask, TEST_LOCATION);
3167
3168   ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
3169
3170   DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetCurrentProperty(Renderer::Property::STENCIL_FUNCTION_MASK).Get<int>()), testValueMask, TEST_LOCATION);
3171
3172   // Clear the stringstream.
3173   parameterStream.str(std::string());
3174   parameterStream << StencilFunctionLookupTable[StencilOperation::DECREMENT_WRAP] << ", " << testValueReference << ", " << testValueMask;
3175
3176   DALI_TEST_CHECK(glStencilFunctionStack.FindMethodAndParams(methodString, parameterStream.str()));
3177
3178   END_TEST;
3179 }
3180
3181 int UtcDaliRendererSetStencilOperation(void)
3182 {
3183   TestApplication application;
3184   tet_infoline("Test setting the StencilOperation");
3185
3186   Renderer           renderer               = RendererTestFixture(application);
3187   TestGlAbstraction& glAbstraction          = application.GetGlAbstraction();
3188   TraceCallStack&    glEnableDisableStack   = glAbstraction.GetEnableDisableTrace();
3189   TraceCallStack&    glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
3190   glEnableDisableStack.Enable(true);
3191   glEnableDisableStack.EnableLogging(true);
3192   glStencilFunctionStack.Enable(true);
3193   glStencilFunctionStack.EnableLogging(true);
3194
3195   // RenderMode must use the stencil for StencilOperation to operate.
3196   renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::STENCIL);
3197
3198   /*
3199    * Lookup table for testing StencilOperation.
3200    * Note: This MUST be in the same order as the Dali::StencilOperation enum.
3201    */
3202   const int StencilOperationLookupTable[] = {
3203     GL_ZERO,
3204     GL_KEEP,
3205     GL_REPLACE,
3206     GL_INCR,
3207     GL_DECR,
3208     GL_INVERT,
3209     GL_INCR_WRAP,
3210     GL_DECR_WRAP};
3211   const int StencilOperationLookupTableCount = sizeof(StencilOperationLookupTable) / sizeof(StencilOperationLookupTable[0]);
3212
3213   // Set all 3 StencilOperation properties to a default.
3214   renderer.SetProperty(Renderer::Property::STENCIL_OPERATION_ON_FAIL, StencilOperation::KEEP);
3215   renderer.SetProperty(Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, StencilOperation::ZERO);
3216   renderer.SetProperty(Renderer::Property::STENCIL_OPERATION_ON_Z_PASS, StencilOperation::ZERO);
3217
3218   // Set our expected parameter list to the equivalent result.
3219   int parameters[] = {StencilOperationLookupTable[StencilOperation::ZERO], StencilOperationLookupTable[StencilOperation::ZERO], StencilOperationLookupTable[StencilOperation::ZERO]};
3220
3221   ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
3222
3223   /*
3224    * Loop through all types of StencilOperation, checking:
3225    *  - The value is cached (set in event thread side)
3226    *  - Causes "glStencilFunc" to be called
3227    *  - Checks the correct parameters to "glStencilFunc" were used
3228    *  - Checks the above for all 3 parameter placements of StencilOperation ( OnFail, OnZFail, OnPass )
3229    */
3230   std::string methodString("StencilOp");
3231
3232   for(int i = 0; i < StencilOperationLookupTableCount; ++i)
3233   {
3234     for(int j = 0; j < StencilOperationLookupTableCount; ++j)
3235     {
3236       for(int k = 0; k < StencilOperationLookupTableCount; ++k)
3237       {
3238         // Set the property (outer loop causes all 3 different properties to be set separately).
3239         renderer.SetProperty(Renderer::Property::STENCIL_OPERATION_ON_FAIL, static_cast<Dali::StencilFunction::Type>(i));
3240         renderer.SetProperty(Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, static_cast<Dali::StencilFunction::Type>(j));
3241         renderer.SetProperty(Renderer::Property::STENCIL_OPERATION_ON_Z_PASS, static_cast<Dali::StencilFunction::Type>(k));
3242
3243         // Check GetProperty returns the same value.
3244         DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_OPERATION_ON_FAIL).Get<int>()), i, TEST_LOCATION);
3245         DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL).Get<int>()), j, TEST_LOCATION);
3246         DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_OPERATION_ON_Z_PASS).Get<int>()), k, TEST_LOCATION);
3247
3248         // Reset the trace debug.
3249         ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
3250
3251         // Check the function is called and the parameters are correct.
3252         // Set the expected parameter value at its correct index (only)
3253         parameters[0u] = StencilOperationLookupTable[i];
3254         parameters[1u] = StencilOperationLookupTable[j];
3255         parameters[2u] = StencilOperationLookupTable[k];
3256
3257         // Build the parameter list.
3258         std::stringstream parameterStream;
3259         for(int parameterBuild = 0; parameterBuild < 3; ++parameterBuild)
3260         {
3261           parameterStream << parameters[parameterBuild];
3262           // Comma-separate the parameters.
3263           if(parameterBuild < 2)
3264           {
3265             parameterStream << ", ";
3266           }
3267         }
3268
3269         // Check the function was called and the parameters were correct.
3270         DALI_TEST_CHECK(glStencilFunctionStack.FindMethodAndParams(methodString, parameterStream.str()));
3271       }
3272     }
3273   }
3274
3275   END_TEST;
3276 }
3277
3278 int UtcDaliRendererSetStencilMask(void)
3279 {
3280   TestApplication application;
3281   tet_infoline("Test setting the StencilMask");
3282
3283   Renderer           renderer               = RendererTestFixture(application);
3284   TestGlAbstraction& glAbstraction          = application.GetGlAbstraction();
3285   TraceCallStack&    glEnableDisableStack   = glAbstraction.GetEnableDisableTrace();
3286   TraceCallStack&    glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
3287   glEnableDisableStack.Enable(true);
3288   glEnableDisableStack.EnableLogging(true);
3289   glStencilFunctionStack.Enable(true);
3290   glStencilFunctionStack.EnableLogging(true);
3291
3292   // RenderMode must use the stencil for StencilMask to operate.
3293   renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::STENCIL);
3294
3295   // Set the StencilMask property to a value.
3296   renderer.SetProperty(Renderer::Property::STENCIL_MASK, 0x00);
3297
3298   // Check GetProperty returns the same value.
3299   DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_MASK).Get<int>()), 0x00, TEST_LOCATION);
3300
3301   ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
3302
3303   DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetCurrentProperty(Renderer::Property::STENCIL_MASK).Get<int>()), 0x00, TEST_LOCATION);
3304
3305   std::string methodString("StencilMask");
3306   std::string parameterString = "0";
3307
3308   // Check the function was called and the parameters were correct.
3309   DALI_TEST_CHECK(glStencilFunctionStack.FindMethodAndParams(methodString, parameterString));
3310
3311   // Set the StencilMask property to another value to ensure it has changed.
3312   renderer.SetProperty(Renderer::Property::STENCIL_MASK, 0xFF);
3313
3314   // Check GetProperty returns the same value.
3315   DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_MASK).Get<int>()), 0xFF, TEST_LOCATION);
3316
3317   ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
3318
3319   DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetCurrentProperty(Renderer::Property::STENCIL_MASK).Get<int>()), 0xFF, TEST_LOCATION);
3320
3321   parameterString = "255";
3322
3323   // Check the function was called and the parameters were correct.
3324   DALI_TEST_CHECK(glStencilFunctionStack.FindMethodAndParams(methodString, parameterString));
3325
3326   END_TEST;
3327 }
3328
3329 int UtcDaliRendererWrongNumberOfTextures(void)
3330 {
3331   TestApplication application;
3332   tet_infoline("Test renderer does render even if number of textures is different than active samplers in the shader");
3333
3334   //Create a TextureSet with 4 textures (One more texture in the texture set than active samplers)
3335   //@note Shaders in the test suit have 3 active samplers. See TestGlAbstraction::GetActiveUniform()
3336   Texture    texture    = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64u, 64u);
3337   TextureSet textureSet = CreateTextureSet();
3338   textureSet.SetTexture(0, texture);
3339   textureSet.SetTexture(1, texture);
3340   textureSet.SetTexture(2, texture);
3341   textureSet.SetTexture(3, texture);
3342   Shader   shader   = Shader::New("VertexSource", "FragmentSource");
3343   Geometry geometry = CreateQuadGeometry();
3344   Renderer renderer = Renderer::New(geometry, shader);
3345   renderer.SetTextures(textureSet);
3346
3347   Actor actor = Actor::New();
3348   actor.AddRenderer(renderer);
3349   actor.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 0.0f));
3350   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
3351   application.GetScene().Add(actor);
3352
3353   TestGlAbstraction& gl        = application.GetGlAbstraction();
3354   TraceCallStack&    drawTrace = gl.GetDrawTrace();
3355   drawTrace.Reset();
3356   drawTrace.Enable(true);
3357   drawTrace.EnableLogging(true);
3358
3359   application.SendNotification();
3360   application.Render(0);
3361
3362   //Test we do the drawcall when TextureSet has more textures than there are active samplers in the shader
3363   DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION);
3364
3365   //Create a TextureSet with 1 texture (two more active samplers than texture in the texture set)
3366   //@note Shaders in the test suit have 3 active samplers. See TestGlAbstraction::GetActiveUniform()
3367   textureSet = CreateTextureSet();
3368   renderer.SetTextures(textureSet);
3369   textureSet.SetTexture(0, texture);
3370   drawTrace.Reset();
3371   application.SendNotification();
3372   application.Render(0);
3373
3374   //Test we do the drawcall when TextureSet has less textures than there are active samplers in the shader.
3375   DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION);
3376
3377   END_TEST;
3378 }
3379
3380 int UtcDaliRendererOpacity(void)
3381 {
3382   TestApplication application;
3383
3384   tet_infoline("Test OPACITY property");
3385
3386   Geometry geometry = CreateQuadGeometry();
3387   Shader   shader   = Shader::New("vertexSrc", "fragmentSrc");
3388   Renderer renderer = Renderer::New(geometry, shader);
3389
3390   Actor actor = Actor::New();
3391   actor.AddRenderer(renderer);
3392   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3393   actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 1.0f));
3394   application.GetScene().Add(actor);
3395
3396   Property::Value value = renderer.GetProperty(DevelRenderer::Property::OPACITY);
3397   float           opacity;
3398   DALI_TEST_CHECK(value.Get(opacity));
3399   DALI_TEST_EQUALS(opacity, 1.0f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3400
3401   application.SendNotification();
3402   application.Render();
3403
3404   Vector4            actualValue;
3405   Vector4            actualActorColor;
3406   TestGlAbstraction& gl = application.GetGlAbstraction();
3407   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uColor", actualValue));
3408   DALI_TEST_EQUALS(actualValue.a, 1.0f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3409   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uActorColor", actualActorColor));
3410   DALI_TEST_EQUALS(actualActorColor.a, 1.0f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3411
3412   renderer.SetProperty(DevelRenderer::Property::OPACITY, 0.5f);
3413
3414   application.SendNotification();
3415   application.Render();
3416
3417   value = renderer.GetProperty(DevelRenderer::Property::OPACITY);
3418   DALI_TEST_CHECK(value.Get(opacity));
3419   DALI_TEST_EQUALS(opacity, 0.5f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3420
3421   value = renderer.GetCurrentProperty(DevelRenderer::Property::OPACITY);
3422   DALI_TEST_CHECK(value.Get(opacity));
3423   DALI_TEST_EQUALS(opacity, 0.5f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3424
3425   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uColor", actualValue));
3426   DALI_TEST_EQUALS(actualValue.a, 0.5f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3427
3428   // Note : Renderer opacity doesn't apply to uActorColor.
3429   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uActorColor", actualActorColor));
3430   DALI_TEST_EQUALS(actualActorColor.a, 1.0f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3431
3432   END_TEST;
3433 }
3434
3435 int UtcDaliRendererOpacityAnimation(void)
3436 {
3437   TestApplication application;
3438
3439   tet_infoline("Test OPACITY property animation");
3440
3441   Geometry geometry = CreateQuadGeometry();
3442   Shader   shader   = Shader::New("vertexSrc", "fragmentSrc");
3443   Renderer renderer = Renderer::New(geometry, shader);
3444
3445   Actor actor = Actor::New();
3446   actor.AddRenderer(renderer);
3447   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3448   actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 1.0f));
3449   application.GetScene().Add(actor);
3450
3451   application.SendNotification();
3452   application.Render(0);
3453
3454   Property::Value value = renderer.GetProperty(DevelRenderer::Property::OPACITY);
3455   float           opacity;
3456   DALI_TEST_CHECK(value.Get(opacity));
3457   DALI_TEST_EQUALS(opacity, 1.0f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3458
3459   Animation animation = Animation::New(1.0f);
3460   animation.AnimateTo(Property(renderer, DevelRenderer::Property::OPACITY), 0.0f);
3461   animation.Play();
3462
3463   application.SendNotification();
3464   application.Render(1000);
3465
3466   value = renderer.GetProperty(DevelRenderer::Property::OPACITY);
3467   DALI_TEST_CHECK(value.Get(opacity));
3468   DALI_TEST_EQUALS(opacity, 0.0f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3469
3470   // Need to clear the animation before setting the property as the animation value is baked and will override any previous setters
3471   animation.Clear();
3472   renderer.SetProperty(DevelRenderer::Property::OPACITY, 0.1f);
3473
3474   animation.AnimateBy(Property(renderer, DevelRenderer::Property::OPACITY), 0.5f);
3475   animation.Play();
3476
3477   application.SendNotification();
3478   application.Render(1000);
3479
3480   value = renderer.GetProperty(DevelRenderer::Property::OPACITY);
3481   DALI_TEST_CHECK(value.Get(opacity));
3482   DALI_TEST_EQUALS(opacity, 0.6f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3483   DALI_TEST_EQUALS(opacity, renderer.GetCurrentProperty(DevelRenderer::Property::OPACITY).Get<float>(), Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3484
3485   END_TEST;
3486 }
3487
3488 int UtcDaliRendererInvalidProperty(void)
3489 {
3490   TestApplication application;
3491
3492   tet_infoline("Test invalid property");
3493
3494   Geometry geometry = CreateQuadGeometry();
3495   Shader   shader   = Shader::New("vertexSrc", "fragmentSrc");
3496   Renderer renderer = Renderer::New(geometry, shader);
3497
3498   Actor actor = Actor::New();
3499   actor.AddRenderer(renderer);
3500   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3501   application.GetScene().Add(actor);
3502
3503   application.SendNotification();
3504   application.Render(0);
3505
3506   Property::Value value = renderer.GetProperty(Renderer::Property::DEPTH_INDEX + 100);
3507   DALI_TEST_CHECK(value.GetType() == Property::Type::NONE);
3508
3509   value = renderer.GetCurrentProperty(Renderer::Property::DEPTH_INDEX + 100);
3510   DALI_TEST_CHECK(value.GetType() == Property::Type::NONE);
3511
3512   END_TEST;
3513 }
3514
3515 int UtcDaliRendererRenderingBehavior(void)
3516 {
3517   TestApplication application;
3518
3519   tet_infoline("Test RENDERING_BEHAVIOR property");
3520
3521   Geometry geometry = CreateQuadGeometry();
3522   Shader   shader   = Shader::New("vertexSrc", "fragmentSrc");
3523   Renderer renderer = Renderer::New(geometry, shader);
3524
3525   Actor actor = Actor::New();
3526   actor.AddRenderer(renderer);
3527   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3528   actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 1.0f));
3529   application.GetScene().Add(actor);
3530
3531   Property::Value value = renderer.GetProperty(DevelRenderer::Property::RENDERING_BEHAVIOR);
3532   int             renderingBehavior;
3533   DALI_TEST_CHECK(value.Get(renderingBehavior));
3534   DALI_TEST_EQUALS(static_cast<DevelRenderer::Rendering::Type>(renderingBehavior), DevelRenderer::Rendering::IF_REQUIRED, TEST_LOCATION);
3535
3536   application.SendNotification();
3537   application.Render();
3538
3539   uint32_t updateStatus = application.GetUpdateStatus();
3540
3541   DALI_TEST_CHECK(!(updateStatus & (Integration::KeepUpdating::STAGE_KEEP_RENDERING | Integration::KeepUpdating::RENDERER_CONTINUOUSLY)));
3542
3543   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
3544   TraceCallStack&    drawTrace     = glAbstraction.GetDrawTrace();
3545   drawTrace.Enable(true);
3546   drawTrace.Reset();
3547
3548   renderer.SetProperty(DevelRenderer::Property::RENDERING_BEHAVIOR, DevelRenderer::Rendering::CONTINUOUSLY);
3549
3550   value = renderer.GetProperty(DevelRenderer::Property::RENDERING_BEHAVIOR);
3551   DALI_TEST_CHECK(value.Get(renderingBehavior));
3552   DALI_TEST_EQUALS(static_cast<DevelRenderer::Rendering::Type>(renderingBehavior), DevelRenderer::Rendering::CONTINUOUSLY, TEST_LOCATION);
3553
3554   // Render and check the update status
3555   application.SendNotification();
3556   application.Render();
3557
3558   updateStatus = application.GetUpdateStatus();
3559
3560   DALI_TEST_CHECK(updateStatus & Integration::KeepUpdating::RENDERER_CONTINUOUSLY);
3561
3562   value = renderer.GetCurrentProperty(DevelRenderer::Property::RENDERING_BEHAVIOR);
3563   DALI_TEST_CHECK(value.Get(renderingBehavior));
3564   DALI_TEST_EQUALS(static_cast<DevelRenderer::Rendering::Type>(renderingBehavior), DevelRenderer::Rendering::CONTINUOUSLY, TEST_LOCATION);
3565
3566   DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION);
3567
3568   drawTrace.Reset();
3569
3570   // Render again and check the update status
3571   application.SendNotification();
3572   application.Render();
3573
3574   updateStatus = application.GetUpdateStatus();
3575
3576   DALI_TEST_CHECK(updateStatus & Integration::KeepUpdating::RENDERER_CONTINUOUSLY);
3577
3578   DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION);
3579
3580   {
3581     // Render again and check the update status
3582     Animation animation = Animation::New(1.0f);
3583     animation.AnimateTo(Property(renderer, DevelRenderer::Property::OPACITY), 0.0f, TimePeriod(0.5f, 0.5f));
3584     animation.Play();
3585
3586     drawTrace.Reset();
3587
3588     application.SendNotification();
3589     application.Render(0);
3590
3591     DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION);
3592
3593     drawTrace.Reset();
3594
3595     application.SendNotification();
3596     application.Render(100);
3597
3598     updateStatus = application.GetUpdateStatus();
3599
3600     DALI_TEST_CHECK(updateStatus & Integration::KeepUpdating::RENDERER_CONTINUOUSLY);
3601
3602     DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION);
3603   }
3604
3605   // Change rendering behavior
3606   renderer.SetProperty(DevelRenderer::Property::RENDERING_BEHAVIOR, DevelRenderer::Rendering::IF_REQUIRED);
3607
3608   // Render and check the update status
3609   application.SendNotification();
3610   application.Render();
3611
3612   updateStatus = application.GetUpdateStatus();
3613
3614   DALI_TEST_CHECK(!(updateStatus & (Integration::KeepUpdating::STAGE_KEEP_RENDERING | Integration::KeepUpdating::RENDERER_CONTINUOUSLY)));
3615
3616   END_TEST;
3617 }
3618
3619 int UtcDaliRendererRegenerateUniformMap(void)
3620 {
3621   TestApplication application;
3622
3623   tet_infoline("Test regenerating uniform map when attaching renderer to the node");
3624
3625   Geometry geometry = CreateQuadGeometry();
3626   Shader   shader   = Shader::New("vertexSrc", "fragmentSrc");
3627   Renderer renderer = Renderer::New(geometry, shader);
3628
3629   Actor actor = Actor::New();
3630   actor.AddRenderer(renderer);
3631   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3632   actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 1.0f));
3633   application.GetScene().Add(actor);
3634
3635   application.SendNotification();
3636   application.Render();
3637
3638   actor.RemoveRenderer(renderer);
3639   shader = Shader::New("vertexSrc", "fragmentSrc");
3640   shader.RegisterProperty("opacity", 0.5f);
3641   renderer.SetShader(shader);
3642
3643   Stage::GetCurrent().KeepRendering(1.0f);
3644
3645   // Update for several frames
3646   application.SendNotification();
3647   application.Render();
3648   application.SendNotification();
3649   application.Render();
3650   application.SendNotification();
3651   application.Render();
3652   application.SendNotification();
3653   application.Render();
3654
3655   // Add Renderer
3656   actor.AddRenderer(renderer);
3657   application.SendNotification();
3658   application.Render();
3659
3660   // Nothing to test here, the test must not crash
3661   auto updateStatus = application.GetUpdateStatus();
3662   DALI_TEST_CHECK(updateStatus & Integration::KeepUpdating::STAGE_KEEP_RENDERING);
3663
3664   END_TEST;
3665 }
3666
3667 int UtcDaliRendererRenderAfterAddShader(void)
3668 {
3669   TestApplication    application;
3670   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
3671
3672   tet_infoline("Test regenerating uniform map when shader changed");
3673
3674   Geometry geometry = CreateQuadGeometry();
3675   Shader   shader1  = Shader::New("vertexSrc1", "fragmentSrc1");
3676   Shader   shader2  = Shader::New("vertexSrc2", "fragmentSrc2");
3677   Renderer renderer = Renderer::New(geometry, shader1);
3678
3679   // Register each shader1 and shader2 only had
3680   shader1.RegisterProperty("uUniform1", Color::CRIMSON);
3681   shader2.RegisterProperty("uShader2Only", Color::AQUA_MARINE);
3682
3683   Actor actor = Actor::New();
3684   actor.AddRenderer(renderer);
3685   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3686   actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 1.0f));
3687   application.GetScene().Add(actor);
3688
3689   Property::Value value = renderer.GetProperty(DevelRenderer::Property::RENDERING_BEHAVIOR);
3690   int             renderingBehavior;
3691   DALI_TEST_CHECK(value.Get(renderingBehavior));
3692   DALI_TEST_EQUALS(static_cast<DevelRenderer::Rendering::Type>(renderingBehavior), DevelRenderer::Rendering::IF_REQUIRED, TEST_LOCATION);
3693
3694   application.SendNotification();
3695   application.Render(0);
3696
3697   // Check uUniform1 rendered and uUniform2 not rendered before
3698   Vector4 actualValue(Vector4::ZERO);
3699   DALI_TEST_CHECK(glAbstraction.GetUniformValue<Vector4>("uUniform1", actualValue));
3700   DALI_TEST_EQUALS(actualValue, Color::CRIMSON, TEST_LOCATION);
3701
3702   uint32_t updateStatus = application.GetUpdateStatus();
3703
3704   DALI_TEST_CHECK(!(updateStatus & (Integration::KeepUpdating::STAGE_KEEP_RENDERING | Integration::KeepUpdating::RENDERER_CONTINUOUSLY)));
3705
3706   // Update for several frames
3707   application.SendNotification();
3708   application.Render();
3709   application.SendNotification();
3710   application.Render();
3711   application.SendNotification();
3712   application.Render();
3713   application.SendNotification();
3714   application.Render();
3715   application.SendNotification();
3716   application.Render();
3717
3718   TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
3719   drawTrace.Enable(true);
3720   drawTrace.Reset();
3721
3722   std::vector<UniformData> customUniforms{{"uShader2Only", Property::VECTOR4}};
3723
3724   application.GetGraphicsController().AddCustomUniforms(customUniforms);
3725
3726   // Change shader.
3727   renderer.SetShader(shader2);
3728
3729   // Render and check the update status
3730   application.SendNotification();
3731   application.Render(0);
3732
3733   updateStatus = application.GetUpdateStatus();
3734
3735   DALI_TEST_CHECK(!(updateStatus & (Integration::KeepUpdating::STAGE_KEEP_RENDERING | Integration::KeepUpdating::RENDERER_CONTINUOUSLY)));
3736
3737   DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION);
3738
3739   // Check uUniform2 rendered now
3740   DALI_TEST_CHECK(glAbstraction.GetUniformValue<Vector4>("uShader2Only", actualValue));
3741   DALI_TEST_EQUALS(actualValue, Color::AQUA_MARINE, TEST_LOCATION);
3742
3743   END_TEST;
3744 }
3745
3746 int UtcDaliRendererAddDrawCommands(void)
3747 {
3748   TestApplication application;
3749
3750   tet_infoline("Test adding draw commands to the renderer");
3751
3752   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
3753   glAbstraction.EnableEnableDisableCallTrace(true);
3754
3755   Geometry geometry = CreateQuadGeometry();
3756   Shader   shader   = Shader::New("vertexSrc", "fragmentSrc");
3757   Renderer renderer = Renderer::New(geometry, shader);
3758
3759   renderer.SetProperty(Renderer::Property::BLEND_MODE, Dali::BlendMode::ON);
3760   Actor actor = Actor::New();
3761   actor.AddRenderer(renderer);
3762   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3763   actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 1.0f));
3764   application.GetScene().Add(actor);
3765
3766   // Expect delivering a single draw call
3767   auto& drawTrace = glAbstraction.GetDrawTrace();
3768   drawTrace.Reset();
3769   drawTrace.Enable(true);
3770   application.SendNotification();
3771   application.Render();
3772
3773   DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION);
3774
3775   tet_infoline("\n\nTesting extension draw commands\n");
3776   auto drawCommand1         = DevelRenderer::DrawCommand{};
3777   drawCommand1.drawType     = DevelRenderer::DrawType::INDEXED;
3778   drawCommand1.firstIndex   = 0;
3779   drawCommand1.elementCount = 2;
3780   drawCommand1.queue        = DevelRenderer::RENDER_QUEUE_OPAQUE;
3781
3782   auto drawCommand2         = DevelRenderer::DrawCommand{};
3783   drawCommand2.drawType     = DevelRenderer::DrawType::INDEXED;
3784   drawCommand2.firstIndex   = 2;
3785   drawCommand2.elementCount = 2;
3786   drawCommand2.queue        = DevelRenderer::RENDER_QUEUE_TRANSPARENT;
3787
3788   auto drawCommand3         = DevelRenderer::DrawCommand{};
3789   drawCommand3.drawType     = DevelRenderer::DrawType::ARRAY;
3790   drawCommand3.firstIndex   = 2;
3791   drawCommand3.elementCount = 2;
3792   drawCommand3.queue        = DevelRenderer::RENDER_QUEUE_OPAQUE;
3793
3794   DevelRenderer::AddDrawCommand(renderer, drawCommand1);
3795   DevelRenderer::AddDrawCommand(renderer, drawCommand2);
3796   DevelRenderer::AddDrawCommand(renderer, drawCommand3);
3797
3798   drawTrace.Reset();
3799   drawTrace.Enable(true);
3800   application.SendNotification();
3801   application.Render();
3802
3803   DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 3, TEST_LOCATION);
3804   END_TEST;
3805 }
3806 int UtcDaliRendererSetGeometryNegative(void)
3807 {
3808   TestApplication application;
3809   Dali::Renderer  instance;
3810   try
3811   {
3812     Dali::Geometry arg1;
3813     instance.SetGeometry(arg1);
3814     DALI_TEST_CHECK(false); // Should not get here
3815   }
3816   catch(...)
3817   {
3818     DALI_TEST_CHECK(true); // We expect an assert
3819   }
3820   END_TEST;
3821 }
3822
3823 int UtcDaliRendererSetTexturesNegative(void)
3824 {
3825   TestApplication application;
3826   Dali::Renderer  instance;
3827   try
3828   {
3829     Dali::TextureSet arg1;
3830     instance.SetTextures(arg1);
3831     DALI_TEST_CHECK(false); // Should not get here
3832   }
3833   catch(...)
3834   {
3835     DALI_TEST_CHECK(true); // We expect an assert
3836   }
3837   END_TEST;
3838 }
3839
3840 int UtcDaliRendererSetShaderNegative(void)
3841 {
3842   TestApplication application;
3843   Dali::Renderer  instance;
3844   try
3845   {
3846     Dali::Shader arg1;
3847     instance.SetShader(arg1);
3848     DALI_TEST_CHECK(false); // Should not get here
3849   }
3850   catch(...)
3851   {
3852     DALI_TEST_CHECK(true); // We expect an assert
3853   }
3854   END_TEST;
3855 }
3856
3857 int UtcDaliRendererGetGeometryNegative(void)
3858 {
3859   TestApplication application;
3860   Dali::Renderer  instance;
3861   try
3862   {
3863     instance.GetGeometry();
3864     DALI_TEST_CHECK(false); // Should not get here
3865   }
3866   catch(...)
3867   {
3868     DALI_TEST_CHECK(true); // We expect an assert
3869   }
3870   END_TEST;
3871 }
3872
3873 int UtcDaliRendererGetTexturesNegative(void)
3874 {
3875   TestApplication application;
3876   Dali::Renderer  instance;
3877   try
3878   {
3879     instance.GetTextures();
3880     DALI_TEST_CHECK(false); // Should not get here
3881   }
3882   catch(...)
3883   {
3884     DALI_TEST_CHECK(true); // We expect an assert
3885   }
3886   END_TEST;
3887 }
3888
3889 int UtcDaliRendererGetShaderNegative(void)
3890 {
3891   TestApplication application;
3892   Dali::Renderer  instance;
3893   try
3894   {
3895     instance.GetShader();
3896     DALI_TEST_CHECK(false); // Should not get here
3897   }
3898   catch(...)
3899   {
3900     DALI_TEST_CHECK(true); // We expect an assert
3901   }
3902   END_TEST;
3903 }
3904
3905 int UtcDaliRendererCheckTextureBindingP(void)
3906 {
3907   TestApplication application;
3908
3909   tet_infoline("Test adding draw commands to the renderer");
3910
3911   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
3912   glAbstraction.EnableEnableDisableCallTrace(true);
3913
3914   Geometry geometry = CreateQuadGeometry();
3915   Shader   shader   = Shader::New("vertexSrc", "fragmentSrc");
3916   Renderer renderer = Renderer::New(geometry, shader);
3917
3918   renderer.SetProperty(Renderer::Property::BLEND_MODE, Dali::BlendMode::ON);
3919   Actor actor = Actor::New();
3920   actor.AddRenderer(renderer);
3921   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3922   actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 1.0f));
3923   application.GetScene().Add(actor);
3924
3925   TestGraphicsController& graphics        = application.GetGraphicsController();
3926   TraceCallStack&         cmdBufCallstack = graphics.mCommandBufferCallStack;
3927   cmdBufCallstack.Enable(true);
3928
3929   application.SendNotification();
3930   application.Render();
3931
3932   DALI_TEST_CHECK(!cmdBufCallstack.FindMethod("BindTextures"));
3933
3934   Texture    image0      = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGB888, 64, 64);
3935   TextureSet textureSet0 = CreateTextureSet(image0);
3936   renderer.SetTextures(textureSet0);
3937
3938   application.SendNotification();
3939   application.Render();
3940
3941   DALI_TEST_CHECK(cmdBufCallstack.FindMethod("BindTextures"));
3942   END_TEST;
3943 }
3944
3945 int UtcDaliRendererPreparePipeline(void)
3946 {
3947   TestApplication application;
3948
3949   tet_infoline("Test that rendering an actor binds the attributes locs from the reflection");
3950
3951   Property::Map vf            = CreateModelVertexFormat();
3952   Geometry      modelGeometry = CreateModelGeometry(vf);
3953   Shader        shader        = Shader::New("vertexSrc", "fragmentSrc");
3954   Renderer      renderer      = Renderer::New(modelGeometry, shader);
3955   Actor         actor         = Actor::New();
3956
3957   // Change the order up to get a fair test
3958   Property::Map modelVF;
3959   modelVF["aBoneIndex[0]"]   = Property::INTEGER;
3960   modelVF["aBoneIndex[1]"]   = Property::INTEGER;
3961   modelVF["aBoneIndex[2]"]   = Property::INTEGER;
3962   modelVF["aBoneIndex[3]"]   = Property::INTEGER;
3963   modelVF["aBoneWeights[0]"] = Property::FLOAT;
3964   modelVF["aBoneWeights[1]"] = Property::FLOAT;
3965   modelVF["aBoneWeights[2]"] = Property::FLOAT;
3966   modelVF["aBoneWeights[3]"] = Property::FLOAT;
3967   modelVF["aPosition"]       = Property::VECTOR3;
3968   modelVF["aNormal"]         = Property::VECTOR3;
3969   modelVF["aTexCoord1"]      = Property::VECTOR3;
3970   modelVF["aTexCoord2"]      = Property::VECTOR3;
3971
3972   Property::Array vfs;
3973   vfs.PushBack(modelVF);
3974   TestGraphicsController& graphics = application.GetGraphicsController();
3975   graphics.SetVertexFormats(vfs);
3976
3977   actor.AddRenderer(renderer);
3978   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3979   actor.SetProperty(Actor::Property::COLOR, Color::WHITE);
3980   application.GetScene().Add(actor);
3981
3982   TraceCallStack& cmdBufCallstack   = graphics.mCommandBufferCallStack;
3983   TraceCallStack& graphicsCallstack = graphics.mCallStack;
3984   cmdBufCallstack.Enable(true);
3985   graphicsCallstack.Enable(true);
3986
3987   application.SendNotification();
3988   application.Render();
3989
3990   DALI_TEST_CHECK(graphicsCallstack.FindMethod("SubmitCommandBuffers"));
3991   std::vector<Graphics::SubmitInfo>& submissions = graphics.mSubmitStack;
3992   DALI_TEST_CHECK(submissions.size() > 0);
3993
3994   TestGraphicsCommandBuffer* cmdBuf = static_cast<TestGraphicsCommandBuffer*>((submissions.back().cmdBuffer[0]));
3995
3996   auto result   = cmdBuf->GetChildCommandsByType(0 | CommandType::BIND_PIPELINE);
3997   auto pipeline = result[0]->data.bindPipeline.pipeline;
3998
3999   if(pipeline)
4000   {
4001     DALI_TEST_EQUALS(pipeline->vertexInputState.attributes.size(), 12, TEST_LOCATION);
4002     DALI_TEST_EQUALS(pipeline->vertexInputState.attributes[3].location, // 4th requested attr: aTexCoord2
4003                      11,
4004                      TEST_LOCATION);
4005     DALI_TEST_EQUALS(pipeline->vertexInputState.attributes[3].format, // 4th requested attr: aTexCoord2
4006                      Graphics::VertexInputFormat::FVECTOR3,
4007                      TEST_LOCATION);
4008   }
4009
4010   END_TEST;
4011 }
4012
4013 int UtcDaliRendererPreparePipelineMissingAttrs(void)
4014 {
4015   TestApplication application;
4016
4017   tet_infoline("Test that rendering an actor tries to bind the attributes locs from the reflection, but fails");
4018   Debug::Filter::SetGlobalLogLevel(Debug::Verbose);
4019
4020   Property::Map modelVF;
4021   modelVF["aPosition"] = Property::VECTOR3;
4022   modelVF["aNormal"]   = Property::VECTOR3;
4023   Property::Array vfs;
4024   vfs.PushBack(modelVF);
4025
4026   TestGraphicsController& graphics = application.GetGraphicsController();
4027   graphics.SetAutoAttrCreation(false);
4028   graphics.SetVertexFormats(vfs);
4029
4030   Property::Map vf            = CreateModelVertexFormat();
4031   Geometry      modelGeometry = CreateModelGeometry(vf);
4032   Shader        shader        = Shader::New("vertexSrc", "fragmentSrc");
4033   Renderer      renderer      = Renderer::New(modelGeometry, shader);
4034   Actor         actor         = Actor::New();
4035
4036   actor.AddRenderer(renderer);
4037   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
4038   actor.SetProperty(Actor::Property::COLOR, Color::WHITE);
4039   application.GetScene().Add(actor);
4040
4041   TraceCallStack& cmdBufCallstack   = graphics.mCommandBufferCallStack;
4042   TraceCallStack& graphicsCallstack = graphics.mCallStack;
4043   cmdBufCallstack.Enable(true);
4044   graphicsCallstack.Enable(true);
4045
4046   application.SendNotification();
4047   application.Render();
4048
4049   DALI_TEST_CHECK(graphicsCallstack.FindMethod("SubmitCommandBuffers"));
4050   std::vector<Graphics::SubmitInfo>& submissions = graphics.mSubmitStack;
4051   DALI_TEST_CHECK(submissions.size() > 0);
4052
4053   TestGraphicsCommandBuffer* cmdBuf = static_cast<TestGraphicsCommandBuffer*>((submissions.back().cmdBuffer[0]));
4054
4055   auto result   = cmdBuf->GetChildCommandsByType(0 | CommandType::BIND_PIPELINE);
4056   auto pipeline = result[0]->data.bindPipeline.pipeline;
4057
4058   if(pipeline)
4059   {
4060     DALI_TEST_EQUALS(pipeline->vertexInputState.attributes.size(), 2, TEST_LOCATION);
4061   }
4062
4063   END_TEST;
4064 }
4065
4066 int UtcDaliRendererUniformArrayOfStruct(void)
4067 {
4068   TestApplication application;
4069   tet_infoline("Test that uniforms that are elements of arrays of structs can be accessed");
4070
4071   std::vector<UniformData> customUniforms{{"arrayof[10].color", Property::VECTOR4},
4072                                           {"arrayof[10].position", Property::VECTOR2},
4073                                           {"arrayof[10].normal", Property::VECTOR3}};
4074
4075   application.GetGraphicsController().AddCustomUniforms(customUniforms);
4076
4077   Geometry geometry = CreateQuadGeometry();
4078   Shader   shader   = Shader::New("vertexSrc", "fragmentSrc");
4079   Renderer renderer = Renderer::New(geometry, shader);
4080   Actor    actor    = Actor::New();
4081   actor.AddRenderer(renderer);
4082   actor[Actor::Property::SIZE] = Vector2(120, 120);
4083   application.GetScene().Add(actor);
4084
4085   // Define some properties to match the custom uniforms.
4086   // Ensure they can be written & read back from the abstraction.
4087
4088   struct UniformIndexPair
4089   {
4090     Property::Index index;
4091     std::string     name;
4092     UniformIndexPair(Property::Index index, std::string name)
4093     : index(index),
4094       name(name)
4095     {
4096     }
4097   };
4098   std::vector<UniformIndexPair> uniformIndices;
4099
4100   std::ostringstream oss;
4101   for(int i = 0; i < 10; ++i)
4102   {
4103     Property::Index index;
4104     oss << "arrayof[" << i << "].color";
4105     Vector4 color = Color::WHITE;
4106     color.r       = 25.5f * i;
4107     index         = renderer.RegisterProperty(oss.str(), color);
4108     uniformIndices.emplace_back(index, oss.str());
4109
4110     oss.str("");
4111     oss.clear();
4112     oss << "arrayof[" << i << "].position";
4113     Vector2 pos(i, 10 + i * 5);
4114     index = renderer.RegisterProperty(oss.str(), pos);
4115     uniformIndices.emplace_back(index, oss.str());
4116
4117     oss.str("");
4118     oss.clear();
4119     oss << "arrayof[" << i << "].normal";
4120     Vector3 normal(i, i * 10, i * 100);
4121     index = renderer.RegisterProperty(oss.str(), normal);
4122     uniformIndices.emplace_back(index, oss.str());
4123     oss.str("");
4124     oss.clear();
4125   }
4126   auto&           gl        = application.GetGlAbstraction();
4127   TraceCallStack& callStack = gl.GetSetUniformTrace();
4128   gl.EnableSetUniformCallTrace(true);
4129
4130   application.SendNotification();
4131   application.Render();
4132
4133   // Check that the uniforms match.
4134   TraceCallStack::NamedParams params;
4135   for(auto& uniformInfo : uniformIndices)
4136   {
4137     Property::Value value = renderer.GetProperty(uniformInfo.index);
4138     switch(value.GetType())
4139     {
4140       case Property::VECTOR2:
4141       {
4142         DALI_TEST_CHECK(callStack.FindMethodAndGetParameters(uniformInfo.name, params));
4143         Vector2 setValue;
4144         DALI_TEST_CHECK(gl.GetUniformValue<Vector2>(uniformInfo.name.c_str(), setValue));
4145         DALI_TEST_EQUALS(value.Get<Vector2>(), setValue, 0.001f, TEST_LOCATION);
4146         break;
4147       }
4148       case Property::VECTOR3:
4149       {
4150         DALI_TEST_CHECK(callStack.FindMethodAndGetParameters(uniformInfo.name, params));
4151         Vector3 setValue;
4152         DALI_TEST_CHECK(gl.GetUniformValue<Vector3>(uniformInfo.name.c_str(), setValue));
4153         DALI_TEST_EQUALS(value.Get<Vector3>(), setValue, 0.001f, TEST_LOCATION);
4154         break;
4155       }
4156       case Property::VECTOR4:
4157       {
4158         DALI_TEST_CHECK(callStack.FindMethodAndGetParameters(uniformInfo.name, params));
4159         Vector4 setValue;
4160         DALI_TEST_CHECK(gl.GetUniformValue<Vector4>(uniformInfo.name.c_str(), setValue));
4161         DALI_TEST_EQUALS(value.Get<Vector4>(), setValue, 0.001f, TEST_LOCATION);
4162         break;
4163       }
4164       default:
4165         break;
4166     }
4167   }
4168
4169   // There is a hash in the property name's uniform map: check this in debugger
4170   // There is a hash in the reflection. Check this in the debugger.
4171
4172   // Check that the reflection contains individual locs for each array entry's struct element
4173   // and that it hashes the whole string
4174
4175   // Ensure that the property name's hash is also for the whole string.
4176
4177   END_TEST;
4178 }
4179
4180 int utcDaliRendererPartialUpdateChangeUniform(void)
4181 {
4182   TestApplication application(
4183     TestApplication::DEFAULT_SURFACE_WIDTH,
4184     TestApplication::DEFAULT_SURFACE_HEIGHT,
4185     TestApplication::DEFAULT_HORIZONTAL_DPI,
4186     TestApplication::DEFAULT_VERTICAL_DPI,
4187     true,
4188     true);
4189
4190   tet_infoline("Check the damaged rect with changing uniform");
4191
4192   const TestGlAbstraction::ScissorParams& glScissorParams(application.GetGlAbstraction().GetScissorParams());
4193
4194   std::vector<Rect<int>> damagedRects;
4195   Rect<int>              clippingRect;
4196   application.SendNotification();
4197   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
4198
4199   // First render pass, nothing to render, adaptor would just do swap buffer.
4200   DALI_TEST_EQUALS(damagedRects.size(), 0, TEST_LOCATION);
4201   application.RenderWithPartialUpdate(damagedRects, clippingRect);
4202
4203   Shader   shader   = Shader::New("VertexSource", "FragmentSource");
4204   Geometry geometry = CreateQuadGeometry();
4205   Renderer renderer = Renderer::New(geometry, shader);
4206
4207   Property::Index colorIndex = renderer.RegisterProperty("uFadeColor", Color::WHITE);
4208
4209   Actor actor = Actor::New();
4210   actor.AddRenderer(renderer);
4211   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
4212   actor.SetProperty(Actor::Property::POSITION, Vector3(16.0f, 16.0f, 0.0f));
4213   actor.SetProperty(Actor::Property::SIZE, Vector3(16.0f, 16.0f, 0.0f));
4214   actor.SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS);
4215   Stage::GetCurrent().Add(actor);
4216
4217   application.SendNotification();
4218
4219   // 1. Actor added, damaged rect is added size of actor
4220   damagedRects.clear();
4221   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
4222   DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
4223
4224   // Aligned by 16
4225   clippingRect = Rect<int>(16, 768, 32, 32); // in screen coordinates
4226   DALI_TEST_EQUALS<Rect<int>>(clippingRect, damagedRects[0], TEST_LOCATION);
4227   application.RenderWithPartialUpdate(damagedRects, clippingRect);
4228   DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
4229   DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
4230   DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
4231   DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
4232
4233   damagedRects.clear();
4234   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
4235   application.RenderWithPartialUpdate(damagedRects, clippingRect);
4236
4237   // Ensure the damaged rect is empty
4238   DALI_TEST_EQUALS(damagedRects.size(), 0, TEST_LOCATION);
4239
4240   // 2. Change the uniform value
4241   renderer.SetProperty(colorIndex, Color::RED);
4242   application.SendNotification();
4243
4244   damagedRects.clear();
4245   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
4246   DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
4247
4248   // Aligned by 16
4249   clippingRect = Rect<int>(16, 768, 32, 32); // in screen coordinates
4250   DALI_TEST_EQUALS<Rect<int>>(clippingRect, damagedRects[0], TEST_LOCATION);
4251   application.RenderWithPartialUpdate(damagedRects, clippingRect);
4252   DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
4253   DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
4254   DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
4255   DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
4256
4257   damagedRects.clear();
4258   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
4259   application.RenderWithPartialUpdate(damagedRects, clippingRect);
4260
4261   // 3. Change the uniform value and another property together
4262   actor.SetProperty(Actor::Property::COLOR, Color::YELLOW);
4263   renderer.SetProperty(colorIndex, Color::BLUE);
4264   application.SendNotification();
4265
4266   damagedRects.clear();
4267   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
4268   DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
4269
4270   // Aligned by 16
4271   clippingRect = Rect<int>(16, 768, 32, 32); // in screen coordinates
4272   DALI_TEST_EQUALS<Rect<int>>(clippingRect, damagedRects[0], TEST_LOCATION);
4273   application.RenderWithPartialUpdate(damagedRects, clippingRect);
4274   DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
4275   DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
4276   DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
4277   DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
4278
4279   damagedRects.clear();
4280   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
4281   application.RenderWithPartialUpdate(damagedRects, clippingRect);
4282
4283   // 4. Change the uniform value only
4284   renderer.SetProperty(colorIndex, Color::RED); // Set the previous value (#2)
4285   application.SendNotification();
4286
4287   damagedRects.clear();
4288   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
4289   DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
4290
4291   // Aligned by 16
4292   clippingRect = Rect<int>(16, 768, 32, 32); // in screen coordinates
4293   DALI_TEST_EQUALS<Rect<int>>(clippingRect, damagedRects[0], TEST_LOCATION);
4294   application.RenderWithPartialUpdate(damagedRects, clippingRect);
4295   DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
4296   DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
4297   DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
4298   DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
4299
4300   END_TEST;
4301 }
4302
4303 int utcDaliRendererPartialUpdateAddRemoveRenderer(void)
4304 {
4305   TestApplication application(
4306     TestApplication::DEFAULT_SURFACE_WIDTH,
4307     TestApplication::DEFAULT_SURFACE_HEIGHT,
4308     TestApplication::DEFAULT_HORIZONTAL_DPI,
4309     TestApplication::DEFAULT_VERTICAL_DPI,
4310     true,
4311     true);
4312
4313   tet_infoline("Check the damaged rect with adding / removing renderer");
4314
4315   const TestGlAbstraction::ScissorParams& glScissorParams(application.GetGlAbstraction().GetScissorParams());
4316
4317   Shader   shader   = Shader::New("VertexSource", "FragmentSource");
4318   Geometry geometry = CreateQuadGeometry();
4319   Renderer renderer = Renderer::New(geometry, shader);
4320
4321   Actor actor = Actor::New();
4322   actor.AddRenderer(renderer);
4323   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
4324   actor.SetProperty(Actor::Property::POSITION, Vector3(16.0f, 16.0f, 0.0f));
4325   actor.SetProperty(Actor::Property::SIZE, Vector3(16.0f, 16.0f, 0.0f));
4326   actor.SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS);
4327   Stage::GetCurrent().Add(actor);
4328
4329   application.SendNotification();
4330
4331   std::vector<Rect<int>> damagedRects;
4332   Rect<int>              clippingRect;
4333
4334   // 1. Actor added, damaged rect is added size of actor
4335   damagedRects.clear();
4336   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
4337   DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
4338
4339   // Aligned by 16
4340   clippingRect = Rect<int>(16, 768, 32, 32); // in screen coordinates
4341   DALI_TEST_EQUALS<Rect<int>>(clippingRect, damagedRects[0], TEST_LOCATION);
4342   application.RenderWithPartialUpdate(damagedRects, clippingRect);
4343   DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
4344   DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
4345   DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
4346   DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
4347
4348   // 2. Remove renderer
4349   actor.RemoveRenderer(renderer);
4350   application.SendNotification();
4351
4352   damagedRects.clear();
4353   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
4354
4355   DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
4356   DALI_TEST_EQUALS<Rect<int>>(clippingRect, damagedRects[0], TEST_LOCATION);
4357
4358   application.RenderWithPartialUpdate(damagedRects, clippingRect);
4359
4360   // 3. Change a property value of the Renderer
4361   renderer.SetProperty(DevelRenderer::Property::OPACITY, 0.5f);
4362   application.SendNotification();
4363
4364   damagedRects.clear();
4365   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
4366
4367   DALI_TEST_EQUALS(damagedRects.size(), 0, TEST_LOCATION);
4368
4369   application.RenderWithPartialUpdate(damagedRects, clippingRect);
4370
4371   // 4. Add renderer again
4372   actor.AddRenderer(renderer);
4373   application.SendNotification();
4374
4375   damagedRects.clear();
4376   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
4377
4378   DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
4379   DALI_TEST_EQUALS<Rect<int>>(clippingRect, damagedRects[0], TEST_LOCATION);
4380
4381   application.RenderWithPartialUpdate(damagedRects, clippingRect);
4382
4383   // 5. Remove renderer agin
4384   actor.RemoveRenderer(renderer);
4385   application.SendNotification();
4386
4387   damagedRects.clear();
4388   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
4389
4390   DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
4391   DALI_TEST_EQUALS<Rect<int>>(clippingRect, damagedRects[0], TEST_LOCATION);
4392
4393   application.RenderWithPartialUpdate(damagedRects, clippingRect);
4394
4395   END_TEST;
4396 }
4397
4398 int utcDaliRendererPartialUpdateRenderingBehavior(void)
4399 {
4400   TestApplication application(
4401     TestApplication::DEFAULT_SURFACE_WIDTH,
4402     TestApplication::DEFAULT_SURFACE_HEIGHT,
4403     TestApplication::DEFAULT_HORIZONTAL_DPI,
4404     TestApplication::DEFAULT_VERTICAL_DPI,
4405     true,
4406     true);
4407
4408   tet_infoline("Check the damaged rect with changing rendering behavior");
4409
4410   const TestGlAbstraction::ScissorParams& glScissorParams(application.GetGlAbstraction().GetScissorParams());
4411
4412   Shader   shader   = Shader::New("VertexSource", "FragmentSource");
4413   Geometry geometry = CreateQuadGeometry();
4414   Renderer renderer = Renderer::New(geometry, shader);
4415
4416   Actor actor = Actor::New();
4417   actor.AddRenderer(renderer);
4418   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
4419   actor.SetProperty(Actor::Property::POSITION, Vector3(16.0f, 16.0f, 0.0f));
4420   actor.SetProperty(Actor::Property::SIZE, Vector3(16.0f, 16.0f, 0.0f));
4421   actor.SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS);
4422   Stage::GetCurrent().Add(actor);
4423
4424   application.SendNotification();
4425
4426   std::vector<Rect<int>> damagedRects;
4427   Rect<int>              clippingRect;
4428
4429   // Actor added, damaged rect is added size of actor
4430   damagedRects.clear();
4431   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
4432   DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
4433
4434   // Aligned by 16
4435   clippingRect = Rect<int>(16, 768, 32, 32); // in screen coordinates
4436   DALI_TEST_EQUALS<Rect<int>>(clippingRect, damagedRects[0], TEST_LOCATION);
4437   application.RenderWithPartialUpdate(damagedRects, clippingRect);
4438   DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
4439   DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
4440   DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
4441   DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
4442
4443   damagedRects.clear();
4444   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
4445   application.RenderWithPartialUpdate(damagedRects, clippingRect);
4446
4447   // Ensure the damaged rect is empty
4448   DALI_TEST_EQUALS(damagedRects.size(), 0, TEST_LOCATION);
4449
4450   // Change rendering behavior to CONTINUOUSLY
4451   renderer[DevelRenderer::Property::RENDERING_BEHAVIOR] = DevelRenderer::Rendering::CONTINUOUSLY;
4452
4453   application.SendNotification();
4454
4455   damagedRects.clear();
4456   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
4457   application.RenderWithPartialUpdate(damagedRects, clippingRect);
4458
4459   // The damaged rect should not be empty
4460   DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
4461   DALI_TEST_EQUALS<Rect<int>>(clippingRect, damagedRects[0], TEST_LOCATION);
4462
4463   damagedRects.clear();
4464   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
4465   application.RenderWithPartialUpdate(damagedRects, clippingRect);
4466
4467   // The damaged rect should not be empty again!
4468   DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
4469   DALI_TEST_EQUALS<Rect<int>>(clippingRect, damagedRects[0], TEST_LOCATION);
4470
4471   END_TEST;
4472 }
4473
4474 int utcDaliRendererDoNotSkipRenderIfTextureSetChanged(void)
4475 {
4476   TestApplication application;
4477   tet_infoline("Check to not skip rendering in case of the TextureSet Changed");
4478
4479   TraceCallStack& drawTrace = application.GetGlAbstraction().GetDrawTrace();
4480   drawTrace.Enable(true);
4481   drawTrace.Reset();
4482
4483   Actor actor = CreateRenderableActor();
4484   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
4485   actor.SetProperty(Actor::Property::SIZE, Vector3(80.0f, 80.0f, 0.0f));
4486   application.GetScene().Add(actor);
4487
4488   // Make any animation to skip rendering.
4489   // Delay duration must be bigger than 0.0f
4490   Animation animation = Animation::New(2.0f);
4491   animation.AnimateTo(Property(actor, Actor::Property::POSITION_X), 1.0f, TimePeriod(1.0f, 1.0f));
4492   animation.Play();
4493
4494   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
4495
4496   Renderer renderer = actor.GetRendererAt(0u);
4497
4498   Texture    image      = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGB888, 64, 64);
4499   TextureSet textureSet = CreateTextureSet(image);
4500
4501   // Render at least 2 frames
4502   application.SendNotification();
4503   application.Render();
4504   application.SendNotification();
4505   application.Render();
4506
4507   drawTrace.Reset();
4508
4509   application.SendNotification();
4510   application.Render();
4511
4512   // Skip rendering
4513   DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 0, TEST_LOCATION);
4514
4515   // Change TextureSet
4516   renderer.SetTextures(textureSet);
4517
4518   application.SendNotification();
4519   application.Render(16u);
4520
4521   // Should not Skip rendering!
4522   DALI_TEST_GREATER(drawTrace.CountMethod("DrawElements"), 0, TEST_LOCATION);
4523
4524   END_TEST;
4525 }
4526
4527 int UtcDaliRendererSetInstanceCount(void)
4528 {
4529   TestApplication application;
4530
4531   tet_infoline("Test setting the instance count results in instanced draw");
4532
4533   Property::Map vertexFormat{{"aPosition", Property::VECTOR2}, {"aTexCoord", Property::VECTOR2}};
4534   Property::Map instanceFormat{{"aTranslation", Property::VECTOR2}, {"aSize", Property::VECTOR2}};
4535
4536   const float halfQuadSize = .5f;
4537   struct TexturedQuadVertex
4538   {
4539     Vector2 aPosition;
4540     Vector2 aTexCoord;
4541   };
4542   TexturedQuadVertex texturedQuadVertexData[4] = {
4543     {Vector2(-halfQuadSize, -halfQuadSize), Vector2(0.f, 0.f)},
4544     {Vector2(halfQuadSize, -halfQuadSize), Vector2(1.f, 0.f)},
4545     {Vector2(-halfQuadSize, halfQuadSize), Vector2(0.f, 1.f)},
4546     {Vector2(halfQuadSize, halfQuadSize), Vector2(1.f, 1.f)}};
4547
4548   VertexBuffer vertexBuffer = VertexBuffer::New(vertexFormat);
4549   vertexBuffer.SetData(texturedQuadVertexData, 4);
4550
4551   VertexBuffer instanceBuffer = VertexBuffer::New(instanceFormat);
4552   instanceBuffer.SetDivisor(1);
4553
4554   struct Instance
4555   {
4556     Vector2 aTranslation;
4557     Vector2 aSize;
4558   };
4559   std::vector<Instance> instanceData = {{Vector2{111.f, 222.f}, Vector2{32, 32}}, {Vector2{-112.f, 342.f}, Vector2{32, 32}}, {Vector2{124.f, 294.f}, Vector2{32, 32}}, {Vector2{459.f, -392.f}, Vector2{32, 32}}};
4560
4561   Dali::Geometry geometry = Dali::Geometry::New();
4562   geometry.AddVertexBuffer(vertexBuffer);
4563   geometry.AddVertexBuffer(instanceBuffer);
4564   geometry.SetType(Geometry::TRIANGLE_STRIP);
4565
4566   Shader shader = CreateShader();
4567
4568   Actor actor = Actor::New();
4569   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
4570   application.GetScene().Add(actor);
4571
4572   Renderer renderer = Renderer::New(geometry, shader);
4573   actor.AddRenderer(renderer);
4574
4575   auto& graphicsController = application.GetGraphicsController();
4576   graphicsController.mCallStack.EnableLogging(true);
4577   graphicsController.mCommandBufferCallStack.EnableLogging(true);
4578
4579   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
4580   auto&              drawTrace     = glAbstraction.GetDrawTrace();
4581   drawTrace.Enable(true);
4582   drawTrace.EnableLogging(true);
4583
4584   application.SendNotification();
4585   application.Render();
4586
4587   tet_infoline("Without instance buffer loaded, should not draw");
4588   DALI_TEST_CHECK(!drawTrace.FindMethod("DrawArrays"));
4589   DALI_TEST_CHECK(!drawTrace.FindMethod("DrawArraysInstanced"));
4590
4591   instanceBuffer.SetData(&instanceData[0], 4);
4592   application.SendNotification();
4593   application.Render();
4594
4595   tet_infoline("With no instance count set, should not draw instanced.");
4596   DALI_TEST_CHECK(drawTrace.FindMethod("DrawArrays"));
4597   DALI_TEST_CHECK(!drawTrace.FindMethod("DrawArraysInstanced"));
4598
4599   renderer[DevelRenderer::Property::INSTANCE_COUNT] = 4;
4600
4601   Property::Value v = renderer["instanceCount"];
4602   DALI_TEST_EQUALS(v, Property::Value(4), TEST_LOCATION);
4603
4604   drawTrace.Reset();
4605   application.SendNotification();
4606   application.Render();
4607
4608   tet_infoline("With instance count set to 4, should draw 4 instances.");
4609   TraceCallStack::NamedParams params;
4610   params["instanceCount"] << 4;
4611   DALI_TEST_CHECK(!drawTrace.FindMethod("DrawArrays"));
4612   DALI_TEST_CHECK(drawTrace.FindMethodAndParams("DrawArraysInstanced", params));
4613
4614   renderer[DevelRenderer::Property::INSTANCE_COUNT] = 1;
4615   drawTrace.Reset();
4616   application.SendNotification();
4617   application.Render();
4618
4619   tet_infoline("With instance count set to 1, should draw 1 instance.");
4620   TraceCallStack::NamedParams params2;
4621   params["instanceCount"] << 1;
4622   DALI_TEST_CHECK(!drawTrace.FindMethod("DrawArrays"));
4623   DALI_TEST_CHECK(drawTrace.FindMethodAndParams("DrawArraysInstanced", params2));
4624
4625   renderer[DevelRenderer::Property::INSTANCE_COUNT] = 0;
4626   drawTrace.Reset();
4627   application.SendNotification();
4628   application.Render();
4629
4630   tet_infoline("With instance count set to 0, should revert to DrawArrays.");
4631   DALI_TEST_CHECK(drawTrace.FindMethod("DrawArrays"));
4632   DALI_TEST_CHECK(!drawTrace.FindMethod("DrawArraysInstanced"));
4633
4634   END_TEST;
4635 }
4636
4637 int UtcDaliRendererVertexRange(void)
4638 {
4639   TestApplication application;
4640
4641   tet_infoline("Test setting the instance count results in instanced draw");
4642
4643   Property::Map vertexFormat{{"aPosition", Property::VECTOR2}, {"aTexCoord", Property::VECTOR2}};
4644   Property::Map instanceFormat{{"aTranslation", Property::VECTOR2}, {"aSize", Property::VECTOR2}};
4645
4646   const float halfQuadSize = .5f;
4647   struct TexturedQuadVertex
4648   {
4649     Vector2 aPosition;
4650     Vector2 aTexCoord;
4651   };
4652   TexturedQuadVertex texturedQuadVertexData[4] = {
4653     {Vector2(-halfQuadSize, -halfQuadSize), Vector2(0.f, 0.f)},
4654     {Vector2(halfQuadSize, -halfQuadSize), Vector2(1.f, 0.f)},
4655     {Vector2(-halfQuadSize, halfQuadSize), Vector2(0.f, 1.f)},
4656     {Vector2(halfQuadSize, halfQuadSize), Vector2(1.f, 1.f)}};
4657
4658   const int                       VERTEX_SET_COUNT(10);
4659   std::vector<TexturedQuadVertex> vertexData;
4660   vertexData.resize(VERTEX_SET_COUNT * 4);
4661   for(int i = 0; i < VERTEX_SET_COUNT; ++i)
4662   {
4663     for(int j = 0; j < 4; ++j)
4664     {
4665       vertexData.push_back({texturedQuadVertexData[j].aPosition * (20.0f * i), texturedQuadVertexData[j].aTexCoord});
4666     }
4667   }
4668
4669   VertexBuffer vertexBuffer = VertexBuffer::New(vertexFormat);
4670   vertexBuffer.SetData(&vertexData[0], VERTEX_SET_COUNT * 4);
4671
4672   Dali::Geometry geometry = Dali::Geometry::New();
4673   geometry.AddVertexBuffer(vertexBuffer);
4674   geometry.SetType(Geometry::TRIANGLE_STRIP);
4675
4676   Shader shader = CreateShader();
4677
4678   Actor actor = Actor::New();
4679   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
4680   application.GetScene().Add(actor);
4681
4682   for(int i = 0; i < VERTEX_SET_COUNT; ++i)
4683   {
4684     Renderer renderer                                     = Renderer::New(geometry, shader);
4685     renderer[DevelRenderer::Property::VERTEX_RANGE_FIRST] = i * 4;
4686     renderer[DevelRenderer::Property::VERTEX_RANGE_COUNT] = 4;
4687     actor.AddRenderer(renderer);
4688   }
4689
4690   for(uint32_t i = 0; i < actor.GetRendererCount(); ++i)
4691   {
4692     auto renderer = actor.GetRendererAt(i);
4693     DALI_TEST_EQUALS(renderer.GetProperty<int>(DevelRenderer::Property::VERTEX_RANGE_FIRST), i * 4, TEST_LOCATION);
4694     DALI_TEST_EQUALS(renderer.GetProperty<int>(DevelRenderer::Property::VERTEX_RANGE_COUNT), 4, TEST_LOCATION);
4695   }
4696
4697   auto& graphicsController = application.GetGraphicsController();
4698   graphicsController.mCallStack.EnableLogging(true);
4699   graphicsController.mCommandBufferCallStack.EnableLogging(true);
4700
4701   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
4702   auto&              drawTrace     = glAbstraction.GetDrawTrace();
4703   drawTrace.Enable(true);
4704   drawTrace.EnableLogging(true);
4705
4706   application.SendNotification();
4707   application.Render();
4708
4709   TraceCallStack::NamedParams namedParams;
4710   namedParams["first"] << 0;
4711   namedParams["count"] << 4;
4712   DALI_TEST_CHECK(drawTrace.FindMethodAndParams("DrawArrays", namedParams));
4713
4714   namedParams["first"].str("");
4715   namedParams["first"].clear();
4716   namedParams["first"] << 4;
4717   DALI_TEST_CHECK(drawTrace.FindMethodAndParams("DrawArrays", namedParams));
4718
4719   namedParams["first"].str("");
4720   namedParams["first"].clear();
4721   namedParams["first"] << 8;
4722   DALI_TEST_CHECK(drawTrace.FindMethodAndParams("DrawArrays", namedParams));
4723
4724   namedParams["first"].str("");
4725   namedParams["first"].clear();
4726   namedParams["first"] << 12;
4727   DALI_TEST_CHECK(drawTrace.FindMethodAndParams("DrawArrays", namedParams));
4728
4729   namedParams["first"].str("");
4730   namedParams["first"].clear();
4731   namedParams["first"] << 16;
4732   DALI_TEST_CHECK(drawTrace.FindMethodAndParams("DrawArrays", namedParams));
4733
4734   DALI_TEST_EQUALS(drawTrace.CountMethod("DrawArrays"), 10, TEST_LOCATION);
4735   END_TEST;
4736 }
4737
4738 TestGraphicsBuffer* FindUniformBuffer(int bufferIndex, TestGraphicsController& graphics)
4739 {
4740   int counter = 0;
4741   for(auto bufferPtr : graphics.mAllocatedBuffers)
4742   {
4743     if(((bufferPtr->mCreateInfo.usage & (0 | Graphics::BufferUsage::UNIFORM_BUFFER)) > 0) &&
4744        !(bufferPtr->mCpuOnly))
4745     {
4746       if(counter == bufferIndex)
4747       {
4748         return bufferPtr;
4749       }
4750       ++counter;
4751     }
4752   }
4753   return nullptr;
4754 }
4755
4756 void CreateRendererProperties(Renderer renderer, const Matrix& m, const Matrix& n)
4757 {
4758   for(int i = 0; i < 300; ++i)
4759   {
4760     std::ostringstream property;
4761     property << "uBone[" << i << "]";
4762     if(i < 299)
4763       renderer.RegisterProperty(property.str(), m);
4764     else
4765       renderer.RegisterProperty(property.str(), n);
4766   }
4767   renderer.RegisterProperty("uNumberOfBlendShapes", 55.0f);
4768   float weight = 0.5f;
4769   for(int i = 0; i < 128; ++i)
4770   {
4771     std::ostringstream property;
4772     property << "uBlendShapeWeight[" << i << "]";
4773     renderer.RegisterProperty(property.str(), weight);
4774   }
4775   float w1                           = 0.01f;
4776   float w2                           = 0.5f;
4777   float w3                           = 0.79f;
4778   renderer["uBlendShapeWeight[0]"]   = w1;
4779   renderer["uBlendShapeWeight[55]"]  = w2;
4780   renderer["uBlendShapeWeight[127]"] = w3;
4781 }
4782
4783 int UtcDaliRendererUniformBlocks01(void)
4784 {
4785   setenv("LOG_UNIFORM_BUFFER", "5f", 1); // Turns on buffer logging
4786   TestApplication application;
4787
4788   tet_infoline("Test that uniforms in blocks are written to a gpu buffer");
4789   auto& graphics = application.GetGraphicsController();
4790   auto& gl       = application.GetGlAbstraction();
4791   gl.mBufferTrace.EnableLogging(true);
4792
4793   gl.SetUniformBufferOffsetAlignment(1024); // Arbitrarily big to easily see it work in debug
4794
4795   const int MAX_BONE_COUNT{300};
4796   const int skinningBlockSize = MAX_BONE_COUNT * sizeof(Matrix);
4797
4798   graphics.AddCustomUniformBlock(TestGraphicsReflection::TestUniformBlockInfo{"Skinning Block", 0, 0, skinningBlockSize, {{"uBone", Graphics::UniformClass::UNIFORM, 0, 0, {0}, {1}, MAX_BONE_COUNT, Property::Type::MATRIX}}});
4799
4800   const int MAX_MORPH_COUNT{128};
4801   const int morphBlockSize = MAX_MORPH_COUNT * sizeof(float) + sizeof(float);
4802   graphics.AddCustomUniformBlock(
4803     TestGraphicsReflection::TestUniformBlockInfo{"MorphBlock", 0, 1, morphBlockSize, {{"uNumberOfBlendShapes", Graphics::UniformClass::UNIFORM, 0, 2, {0}, {2}, 0, Property::Type::FLOAT}, {"uBlendShapeWeight", Graphics::UniformClass::UNIFORM, 0, 2, {4}, {3}, MAX_MORPH_COUNT, Property::Type::FLOAT}}});
4804
4805   Actor    actor    = CreateActor(application.GetScene().GetRootLayer(), 0, TEST_LOCATION);
4806   Shader   shader   = CreateShader(); // Don't care about src content
4807   Geometry geometry = CreateQuadGeometry();
4808   Renderer renderer = CreateRenderer(actor, geometry, shader, 0);
4809   Matrix   m, n;
4810   m.SetIdentity();
4811   n.SetIdentity();
4812   n.SetTransformComponents(Vector3(2.f, 2.f, 2.f), Quaternion(Radian(0.3f), Vector3::YAXIS), Vector3(200.0f, 1.0f, 20.0f));
4813
4814   CreateRendererProperties(renderer, m, n);
4815
4816   TraceCallStack& graphicsTrace = graphics.mCallStack;
4817   TraceCallStack& cmdTrace      = graphics.mCommandBufferCallStack;
4818   graphicsTrace.EnableLogging(true);
4819   cmdTrace.EnableLogging(true);
4820
4821   application.SendNotification();
4822   application.Render();
4823
4824   // We expect 1 vertex buffer, 1 index buffer and 1 uniform buffer (representing 2 blocks)
4825   DALI_TEST_EQUALS(cmdTrace.CountMethod("BindUniformBuffers"), 1, TEST_LOCATION);
4826
4827   tet_infoline("Test that uBone[299] is written correctly");
4828
4829   bool found = false;
4830   for(auto bufferPtr : graphics.mAllocatedBuffers)
4831   {
4832     if(((bufferPtr->mCreateInfo.usage & (0 | Graphics::BufferUsage::UNIFORM_BUFFER)) > 0) &&
4833        !(bufferPtr->mCpuOnly))
4834     {
4835       // We have a GPU uniform buffer. Probably the right one.
4836       // The custom uniform block above should point us to the right spot...
4837       DALI_TEST_CHECK(bufferPtr->memory.size() >= skinningBlockSize);
4838       found        = true;
4839       Matrix* mPtr = reinterpret_cast<Dali::Matrix*>(&bufferPtr->memory[0] + sizeof(Dali::Matrix) * 299);
4840       DALI_TEST_EQUALS(*mPtr, n, 0.0001, TEST_LOCATION);
4841       break;
4842     }
4843   }
4844   DALI_TEST_CHECK(found);
4845
4846   END_TEST;
4847 }
4848
4849 int UtcDaliRendererUniformBlocks02(void)
4850 {
4851   setenv("LOG_UNIFORM_BUFFER", "5f", 1); // Turns on buffer logging
4852   TestApplication application;
4853
4854   tet_infoline("Test that repeated update/render cycles write into alternative buffers");
4855   auto& graphics = application.GetGraphicsController();
4856   auto& gl       = application.GetGlAbstraction();
4857   gl.mBufferTrace.EnableLogging(true);
4858
4859   const uint32_t UNIFORM_BLOCK_ALIGNMENT(512);
4860   gl.SetUniformBufferOffsetAlignment(UNIFORM_BLOCK_ALIGNMENT);
4861
4862   const int MAX_BONE_COUNT{300};
4863   const int skinningBlockSize = MAX_BONE_COUNT * sizeof(Matrix);
4864
4865   graphics.AddCustomUniformBlock(TestGraphicsReflection::TestUniformBlockInfo{"Skinning Block", 0, 0, skinningBlockSize, {{"uBone", Graphics::UniformClass::UNIFORM, 0, 0, {0}, {1}, MAX_BONE_COUNT, Property::Type::MATRIX}}});
4866
4867   const int MAX_MORPH_COUNT{128};
4868   const int morphBlockSize = MAX_MORPH_COUNT * sizeof(float) + sizeof(float);
4869   graphics.AddCustomUniformBlock(
4870     TestGraphicsReflection::TestUniformBlockInfo{"MorphBlock", 0, 1, morphBlockSize, {{"uNumberOfBlendShapes", Graphics::UniformClass::UNIFORM, 0, 2, {0}, {2}, 0, Property::Type::FLOAT}, {"uBlendShapeWeight", Graphics::UniformClass::UNIFORM, 0, 2, {4}, {3}, MAX_MORPH_COUNT, Property::Type::FLOAT}}});
4871
4872   Actor    actor    = CreateActor(application.GetScene().GetRootLayer(), 0, TEST_LOCATION);
4873   Shader   shader   = CreateShader(); // Don't care about src content
4874   Geometry geometry = CreateQuadGeometry();
4875   Renderer renderer = CreateRenderer(actor, geometry, shader, 0);
4876   Matrix   m, n;
4877   m.SetIdentity();
4878   n.SetIdentity();
4879   n.SetTransformComponents(Vector3(2.f, 2.f, 2.f), Quaternion(Radian(0.3f), Vector3::YAXIS), Vector3(200.0f, 1.0f, 20.0f));
4880
4881   CreateRendererProperties(renderer, m, n);
4882   float w1                           = 0.01f;
4883   float w2                           = 0.5f;
4884   float w3                           = 0.79f;
4885   renderer["uBlendShapeWeight[0]"]   = w1;
4886   renderer["uBlendShapeWeight[55]"]  = w2;
4887   renderer["uBlendShapeWeight[127]"] = w3;
4888
4889   TraceCallStack& graphicsTrace = graphics.mCallStack;
4890   TraceCallStack& cmdTrace      = graphics.mCommandBufferCallStack;
4891   graphicsTrace.EnableLogging(true);
4892   cmdTrace.EnableLogging(true);
4893
4894   application.SendNotification();
4895   application.Render();
4896
4897   // We expect 1 vertex buffer, 1 index buffer and 1 uniform buffer (representing 2 blocks)
4898   DALI_TEST_EQUALS(cmdTrace.CountMethod("BindUniformBuffers"), 1, TEST_LOCATION);
4899
4900   const uint32_t MORPH_BLOCK_OFFSET = (skinningBlockSize % UNIFORM_BLOCK_ALIGNMENT == 0) ? skinningBlockSize : ((skinningBlockSize / UNIFORM_BLOCK_ALIGNMENT) + 1) * UNIFORM_BLOCK_ALIGNMENT;
4901
4902   for(int i = 0; i < 50; ++i)
4903   {
4904     tet_infoline("\nTest that uBone[299] is written correctly");
4905     TestGraphicsBuffer* bufferPtr = FindUniformBuffer(i % 2, graphics);
4906     DALI_TEST_CHECK(graphics.mAllocatedBuffers.size() == (i == 0 ? 4 : 5));
4907     DALI_TEST_CHECK(bufferPtr != nullptr);
4908     Matrix* mPtr = reinterpret_cast<Dali::Matrix*>(&bufferPtr->memory[0] + sizeof(Dali::Matrix) * 299);
4909     DALI_TEST_EQUALS(*mPtr, n, 0.0001, TEST_LOCATION);
4910
4911     float* wPtr1 = reinterpret_cast<float*>(&bufferPtr->memory[MORPH_BLOCK_OFFSET] + sizeof(float) * 1);
4912     float* wPtr2 = reinterpret_cast<float*>(&bufferPtr->memory[MORPH_BLOCK_OFFSET] + sizeof(float) * 56);
4913     float* wPtr3 = reinterpret_cast<float*>(&bufferPtr->memory[MORPH_BLOCK_OFFSET] + sizeof(float) * 128);
4914
4915     tet_printf("Test that uBlendShapeWeight[0] is written correctly as %4.2f\n", w1);
4916     tet_printf("Test that uBlendShapeWeight[55] is written correctly as %4.2f\n", w2);
4917     tet_printf("Test that uBlendShapeWeight[127] is written correctly as %4.2f\n", w3);
4918
4919     DALI_TEST_EQUALS(*wPtr1, w1, 0.0001f, TEST_LOCATION);
4920     DALI_TEST_EQUALS(*wPtr2, w2, 0.0001f, TEST_LOCATION);
4921     DALI_TEST_EQUALS(*wPtr3, w3, 0.0001f, TEST_LOCATION);
4922
4923     n.SetTransformComponents(Vector3(2.f, 2.f, 2.f), Quaternion(Radian(i * 0.3f), Vector3::YAXIS), Vector3(200.0f + i * 10.0f, -i, 20.0f));
4924     renderer["uBone[299]"] = n;
4925
4926     w1 += 0.005f;
4927     w2 += 0.005f;
4928     w3 -= 0.01f;
4929     renderer["uBlendShapeWeight[0]"]   = w1;
4930     renderer["uBlendShapeWeight[55]"]  = w2;
4931     renderer["uBlendShapeWeight[127]"] = w3;
4932
4933     application.SendNotification();
4934     application.Render();
4935   }
4936
4937   END_TEST;
4938 }
4939
4940 int AlignSize(int size, int align)
4941 {
4942   return (size % align == 0) ? size : ((size / align) + 1) * align;
4943 }
4944
4945 int UtcDaliRendererUniformBlocks03(void)
4946 {
4947   setenv("LOG_UNIFORM_BUFFER", "5f", 1); // Turns on buffer logging
4948   TestApplication application;
4949
4950   tet_infoline("Test that adding actors grows the uniform buffer");
4951   auto& graphics = application.GetGraphicsController();
4952   auto& gl       = application.GetGlAbstraction();
4953   gl.mBufferTrace.EnableLogging(true);
4954
4955   const uint32_t UNIFORM_BLOCK_ALIGNMENT(512);
4956   gl.SetUniformBufferOffsetAlignment(UNIFORM_BLOCK_ALIGNMENT);
4957
4958   const int MAX_BONE_COUNT{300};
4959   const int skinningBlockSize = MAX_BONE_COUNT * sizeof(Matrix);
4960
4961   graphics.AddCustomUniformBlock(TestGraphicsReflection::TestUniformBlockInfo{"Skinning Block", 0, 0, skinningBlockSize, {{"uBone", Graphics::UniformClass::UNIFORM, 0, 0, {0}, {1}, MAX_BONE_COUNT, Property::Type::MATRIX}}});
4962
4963   const int MAX_MORPH_COUNT{128};
4964   const int morphBlockSize = MAX_MORPH_COUNT * sizeof(float) + sizeof(float);
4965   graphics.AddCustomUniformBlock(
4966     TestGraphicsReflection::TestUniformBlockInfo{"MorphBlock", 0, 1, morphBlockSize, {{"uNumberOfBlendShapes", Graphics::UniformClass::UNIFORM, 0, 2, {0}, {2}, 0, Property::Type::FLOAT}, {"uBlendShapeWeight", Graphics::UniformClass::UNIFORM, 0, 2, {4}, {3}, MAX_MORPH_COUNT, Property::Type::FLOAT}}});
4967
4968   Actor    actor    = CreateActor(application.GetScene().GetRootLayer(), 0, TEST_LOCATION);
4969   Shader   shader   = CreateShader(); // Don't care about src content
4970   Geometry geometry = CreateQuadGeometry();
4971   Renderer renderer = CreateRenderer(actor, geometry, shader, 0);
4972   Matrix   m, n;
4973   m.SetIdentity();
4974   n.SetIdentity();
4975   n.SetTransformComponents(Vector3(2.f, 2.f, 2.f), Quaternion(Radian(0.3f), Vector3::YAXIS), Vector3(200.0f, 1.0f, 20.0f));
4976
4977   CreateRendererProperties(renderer, m, n);
4978
4979   TraceCallStack& graphicsTrace = graphics.mCallStack;
4980   TraceCallStack& cmdTrace      = graphics.mCommandBufferCallStack;
4981   graphicsTrace.EnableLogging(true);
4982   cmdTrace.EnableLogging(true);
4983
4984   application.SendNotification();
4985   application.Render();
4986
4987   // We expect 1 vertex buffer, 1 index buffer and 1 uniform buffer (representing 2 blocks)
4988   DALI_TEST_EQUALS(cmdTrace.CountMethod("BindUniformBuffers"), 1, TEST_LOCATION);
4989
4990   unsigned int overallSize = 0;
4991
4992   for(int i = 0; i < 10; ++i)
4993   {
4994     overallSize += AlignSize(skinningBlockSize, UNIFORM_BLOCK_ALIGNMENT) + AlignSize(morphBlockSize, UNIFORM_BLOCK_ALIGNMENT);
4995
4996     DALI_TEST_CHECK(graphics.mAllocatedBuffers.size() == (i == 0 ? 4 : 5));
4997
4998     TestGraphicsBuffer* bufferPtr = graphics.mAllocatedBuffers.back();
4999     tet_printf("\nTest that latest buffer is big enough(%d)>%d\n", bufferPtr->memory.size(), overallSize);
5000
5001     DALI_TEST_CHECK(bufferPtr->memory.size() >= overallSize);
5002
5003     Actor actor = CreateActor(application.GetScene().GetRootLayer(), 0, TEST_LOCATION);
5004     actor.AddRenderer(renderer);
5005     application.GetScene().Add(actor);
5006
5007     application.SendNotification();
5008     application.Render();
5009   }
5010
5011   END_TEST;
5012 }
5013
5014 int UtcDaliRendererUniformBlocksUnregisterScene01(void)
5015 {
5016   TestApplication application;
5017
5018   tet_infoline("Test that uniform buffers are unregistered after a scene is destroyed\n");
5019
5020   auto& graphics = application.GetGraphicsController();
5021   auto& gl       = application.GetGlAbstraction();
5022   graphics.mCallStack.EnableLogging(true);
5023   graphics.mCommandBufferCallStack.EnableLogging(true);
5024   gl.mBufferTrace.EnableLogging(true);
5025   gl.mBufferTrace.Enable(true);
5026
5027   Actor dummyActor = CreateRenderableActor(CreateTexture(TextureType::TEXTURE_2D, Pixel::RGB888, 45, 45));
5028   application.GetScene().Add(dummyActor);
5029   application.SendNotification();
5030   application.Render();
5031
5032   Dali::Integration::Scene scene = Dali::Integration::Scene::New(Size(480.0f, 800.0f));
5033   DALI_TEST_CHECK(scene);
5034   application.AddScene(scene);
5035
5036   Actor    actor    = CreateActor(scene.GetRootLayer(), 0, TEST_LOCATION);
5037   Shader   shader   = CreateShader(); // Don't really care...
5038   Geometry geometry = CreateQuadGeometry();
5039   Renderer renderer = CreateRenderer(actor, geometry, shader, 0);
5040
5041   const int MAX_BONE_COUNT{300};
5042   const int skinningBlockSize = MAX_BONE_COUNT * sizeof(Matrix);
5043
5044   graphics.AddCustomUniformBlock(TestGraphicsReflection::TestUniformBlockInfo{"Skinning Block", 0, 0, skinningBlockSize, {{"uBone", Graphics::UniformClass::UNIFORM, 0, 0, {0}, {1}, MAX_BONE_COUNT, Property::Type::MATRIX}}});
5045   Matrix m;
5046   m.SetIdentity();
5047   for(int i = 0; i < MAX_BONE_COUNT; ++i)
5048   {
5049     std::ostringstream property;
5050     property << "uBone[" << i << "]";
5051     renderer.RegisterProperty(property.str(), m);
5052   }
5053   tet_infoline("--Expect new scene's buffers to be created here");
5054   application.SendNotification();
5055   application.Render();
5056
5057   scene.RemoveSceneObject(); // Scene's scene graph lifecycle is NOT managed by scene handle
5058   scene.Discard();
5059   scene.Reset();
5060
5061   gl.mBufferTrace.Reset();
5062
5063   tet_infoline("--Expect UnregisterScene to happen during this render cycle");
5064   dummyActor[Actor::Property::SIZE] = Vector3(100, 100, 0);
5065   application.SendNotification();
5066   application.Render();
5067
5068   TraceCallStack::NamedParams namedParams;
5069   namedParams["id"] << 6;
5070   DALI_TEST_CHECK(gl.mBufferTrace.FindMethodAndParams("DeleteBuffers", namedParams));
5071
5072   END_TEST;
5073 }
5074
5075 int UtcDaliRendererUniformNameCrop(void)
5076 {
5077   TestApplication application;
5078   tet_infoline("Tests against reflection cropping one character too many form array uniform name.\n");
5079
5080   auto& graphics = application.GetGraphicsController();
5081
5082   auto uniforms = std::vector<UniformData>{
5083     {"uSomeColor", Dali::Property::Type::FLOAT},
5084     {"uSomeColors[10]", Dali::Property::Type::FLOAT}};
5085   graphics.AddCustomUniforms(uniforms);
5086
5087   auto& gl = application.GetGlAbstraction();
5088   graphics.mCallStack.EnableLogging(true);
5089   graphics.mCommandBufferCallStack.EnableLogging(true);
5090   gl.mBufferTrace.EnableLogging(true);
5091   gl.mBufferTrace.Enable(true);
5092
5093   gl.mSetUniformTrace.EnableLogging(true);
5094   gl.mSetUniformTrace.Enable(true);
5095
5096   Geometry geometry = CreateQuadGeometry();
5097   Shader   shader   = Shader::New("vertexSrc", "fragmentSrc");
5098   Renderer renderer = Renderer::New(geometry, shader);
5099   Actor    actor    = Actor::New();
5100   actor.AddRenderer(renderer);
5101   actor[Actor::Property::SIZE] = Vector2(120, 120);
5102   application.GetScene().Add(actor);
5103
5104   std::ostringstream oss;
5105   struct UniformIndexPair
5106   {
5107     Property::Index index;
5108     std::string     name;
5109     UniformIndexPair(Property::Index index, std::string name)
5110     : index(index),
5111       name(std::move(name))
5112     {
5113     }
5114   };
5115   std::vector<UniformIndexPair> uniformIndices;
5116   for(int i = 0; i < 10; ++i)
5117   {
5118     Property::Index index;
5119     oss << "uArray[" << i + 1 << "]";
5120     auto value = float(i);
5121     index      = renderer.RegisterProperty(oss.str(), value);
5122     uniformIndices.emplace_back(index, oss.str());
5123     oss.str("");
5124     oss.clear();
5125   }
5126
5127   // Cause overwrite, index 10 and uToOverflow should share same memory
5128   [[maybe_unused]] auto badArrayIndex  = renderer.RegisterProperty("uSomeColor", 100.0f);
5129   [[maybe_unused]] auto badArrayIndex2 = renderer.RegisterProperty("uSomeColors[0]", 200.0f);
5130
5131   application.GetScene().Add(actor);
5132   application.SendNotification();
5133   application.Render(0);
5134
5135   float value = 0.0f;
5136   gl.GetUniformValue("uSomeColor", value);
5137
5138   // Test against the bug when name is one character short and array may be mistaken for
5139   // an individual uniform of the same name minut 1 character.
5140   DALI_TEST_EQUALS(value, 100.0f, std::numeric_limits<float>::epsilon(), TEST_LOCATION);
5141   END_TEST;
5142 }
5143
5144 int UtcDaliRendererUniformArrayOverflow(void)
5145 {
5146   TestApplication application;
5147   tet_infoline("Overflow test whether uColor uniform would be overriden by array with out-of-bound index.\n");
5148
5149   auto& graphics = application.GetGraphicsController();
5150   auto  uniforms = std::vector<UniformData>{{"uArray[10]", Dali::Property::Type::FLOAT}};
5151
5152   graphics.AddCustomUniforms(uniforms);
5153
5154   auto& gl = application.GetGlAbstraction();
5155   graphics.mCallStack.EnableLogging(true);
5156   graphics.mCommandBufferCallStack.EnableLogging(true);
5157   gl.mBufferTrace.EnableLogging(true);
5158   gl.mBufferTrace.Enable(true);
5159
5160   gl.mSetUniformTrace.EnableLogging(true);
5161   gl.mSetUniformTrace.Enable(true);
5162
5163   Geometry geometry = CreateQuadGeometry();
5164   Shader   shader   = Shader::New("vertexSrc", "fragmentSrc");
5165   Renderer renderer = Renderer::New(geometry, shader);
5166   Actor    actor    = Actor::New();
5167   actor.AddRenderer(renderer);
5168   actor[Actor::Property::SIZE] = Vector2(120, 120);
5169   application.GetScene().Add(actor);
5170
5171   std::ostringstream oss;
5172   struct UniformIndexPair
5173   {
5174     Property::Index index;
5175     std::string     name;
5176     UniformIndexPair(Property::Index index, std::string name)
5177     : index(index),
5178       name(std::move(name))
5179     {
5180     }
5181   };
5182   std::vector<UniformIndexPair> uniformIndices;
5183   for(int i = 0; i < 10; ++i)
5184   {
5185     Property::Index index;
5186     oss << "uArray[" << i << "]";
5187     auto value = float(i);
5188     index      = renderer.RegisterProperty(oss.str(), value);
5189     uniformIndices.emplace_back(index, oss.str());
5190     oss.str("");
5191     oss.clear();
5192   }
5193
5194   // Cause overwrite, index 10 and uToOverflow should share same memory
5195   [[maybe_unused]] auto badArrayIndex = renderer.RegisterProperty("uArray[10]", 0.0f);
5196
5197   application.GetScene().Add(actor);
5198   application.SendNotification();
5199   application.Render(0);
5200
5201   Vector4 uniformColor = Vector4::ZERO;
5202   gl.GetUniformValue("uColor", uniformColor);
5203   tet_printf("uColor value %f, %f, %f, %f\n",
5204              uniformColor.r,
5205              uniformColor.g,
5206              uniformColor.b,
5207              uniformColor.a);
5208
5209   // the r component of uColor uniform must not be changed.
5210   // if r is 0.0f then test fails as the array stomped on the uniform's memory.
5211   DALI_TEST_EQUALS((uniformColor.r != 0.0f), true, TEST_LOCATION);
5212   END_TEST;
5213 }