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