3fd820bc3edf8965960c68517a85ae04234f4fc0
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-Renderer.cpp
1 /*
2  * Copyright (c) 2022 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 UtcDaliRendererCheckStencilDefaults(void)
2822 {
2823   TestApplication application;
2824   tet_infoline("Test the stencil defaults");
2825
2826   Renderer           renderer               = RendererTestFixture(application);
2827   TestGlAbstraction& glAbstraction          = application.GetGlAbstraction();
2828   TraceCallStack&    glEnableDisableStack   = glAbstraction.GetEnableDisableTrace();
2829   TraceCallStack&    glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2830   glEnableDisableStack.Enable(true);
2831   glEnableDisableStack.EnableLogging(true);
2832   glStencilFunctionStack.Enable(true);
2833   glStencilFunctionStack.EnableLogging(true);
2834
2835   ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2836
2837   // Check the defaults:
2838   DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_FUNCTION).Get<int>()), static_cast<int>(StencilFunction::ALWAYS), TEST_LOCATION);
2839   DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_FUNCTION_MASK).Get<int>()), 0xFF, TEST_LOCATION);
2840   DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_FUNCTION_REFERENCE).Get<int>()), 0x00, TEST_LOCATION);
2841   DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_MASK).Get<int>()), 0xFF, TEST_LOCATION);
2842   DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_OPERATION_ON_FAIL).Get<int>()), static_cast<int>(StencilOperation::KEEP), TEST_LOCATION);
2843   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);
2844   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);
2845
2846   END_TEST;
2847 }
2848
2849 int UtcDaliRendererSetRenderModeToUseStencilBuffer(void)
2850 {
2851   TestApplication application;
2852   tet_infoline("Test setting the RenderMode to use the stencil buffer");
2853
2854   Renderer           renderer               = RendererTestFixture(application);
2855   TestGlAbstraction& glAbstraction          = application.GetGlAbstraction();
2856   TraceCallStack&    glEnableDisableStack   = glAbstraction.GetEnableDisableTrace();
2857   TraceCallStack&    glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2858   glEnableDisableStack.Enable(true);
2859   glEnableDisableStack.EnableLogging(true);
2860   glStencilFunctionStack.Enable(true);
2861   glStencilFunctionStack.EnableLogging(true);
2862
2863   // Set the StencilFunction to something other than the default, to confirm it is set as a property,
2864   // but NO GL call has been made while the RenderMode is set to not use the stencil buffer.
2865   renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::NONE);
2866   ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2867
2868   renderer.SetProperty(Renderer::Property::STENCIL_FUNCTION, StencilFunction::NEVER);
2869   DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_FUNCTION).Get<int>()), static_cast<int>(StencilFunction::NEVER), TEST_LOCATION);
2870
2871   ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2872   std::string methodString("StencilFunc");
2873   DALI_TEST_CHECK(!glStencilFunctionStack.FindMethod(methodString));
2874
2875   // Test the other RenderModes that will not enable the stencil buffer.
2876   renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::AUTO);
2877   ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2878   DALI_TEST_CHECK(!glStencilFunctionStack.FindMethod(methodString));
2879
2880   renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::COLOR);
2881   ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2882   DALI_TEST_CHECK(!glStencilFunctionStack.FindMethod(methodString));
2883
2884   // Now set the RenderMode to modes that will use the stencil buffer, and check the StencilFunction has changed.
2885   renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::STENCIL);
2886   ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2887
2888   DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Enable", GetStencilTestString()));
2889   DALI_TEST_CHECK(glStencilFunctionStack.FindMethod(methodString));
2890
2891   // Test the COLOR_STENCIL RenderMode as it also enables the stencil buffer.
2892   // First set a mode to turn off the stencil buffer, so the enable is required.
2893   renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::COLOR);
2894   ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2895   renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::COLOR_STENCIL);
2896   // Set a different stencil function as the last one is cached.
2897   renderer.SetProperty(Renderer::Property::STENCIL_FUNCTION, StencilFunction::ALWAYS);
2898   ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2899
2900   DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Enable", GetStencilTestString()));
2901   DALI_TEST_CHECK(glStencilFunctionStack.FindMethod(methodString));
2902
2903   END_TEST;
2904 }
2905
2906 // Helper function for the SetRenderModeToUseColorBuffer test.
2907 void CheckRenderModeColorMask(TestApplication& application, Renderer& renderer, RenderMode::Type renderMode, bool expectedValue)
2908 {
2909   // Set the RenderMode property to a value that should not allow color buffer writes.
2910   renderer.SetProperty(Renderer::Property::RENDER_MODE, renderMode);
2911   application.SendNotification();
2912   application.Render();
2913
2914   // Check if ColorMask has been called, and that the values are correct.
2915   TestGlAbstraction&                        glAbstraction = application.GetGlAbstraction();
2916   const TestGlAbstraction::ColorMaskParams& colorMaskParams(glAbstraction.GetColorMaskParams());
2917
2918   DALI_TEST_EQUALS<bool>(colorMaskParams.red, expectedValue, TEST_LOCATION);
2919   DALI_TEST_EQUALS<bool>(colorMaskParams.green, expectedValue, TEST_LOCATION);
2920   DALI_TEST_EQUALS<bool>(colorMaskParams.blue, expectedValue, TEST_LOCATION);
2921   // @todo Only check alpha if framebuffer supports it.
2922   //DALI_TEST_EQUALS<bool>(colorMaskParams.alpha, expectedValue, TEST_LOCATION);
2923 }
2924
2925 int UtcDaliRendererSetRenderModeToUseColorBuffer(void)
2926 {
2927   TestApplication application;
2928   tet_infoline("Test setting the RenderMode to use the color buffer");
2929
2930   Renderer renderer = RendererTestFixture(application);
2931
2932   // Set the RenderMode property to a value that should not allow color buffer writes.
2933   // Then check if ColorMask has been called, and that the values are correct.
2934   CheckRenderModeColorMask(application, renderer, RenderMode::AUTO, true);
2935   CheckRenderModeColorMask(application, renderer, RenderMode::NONE, false);
2936   CheckRenderModeColorMask(application, renderer, RenderMode::COLOR, true);
2937   CheckRenderModeColorMask(application, renderer, RenderMode::STENCIL, false);
2938   CheckRenderModeColorMask(application, renderer, RenderMode::COLOR_STENCIL, true);
2939
2940   END_TEST;
2941 }
2942
2943 int UtcDaliRendererSetStencilFunction(void)
2944 {
2945   TestApplication application;
2946   tet_infoline("Test setting the StencilFunction");
2947
2948   Renderer           renderer               = RendererTestFixture(application);
2949   TestGlAbstraction& glAbstraction          = application.GetGlAbstraction();
2950   TraceCallStack&    glEnableDisableStack   = glAbstraction.GetEnableDisableTrace();
2951   TraceCallStack&    glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2952   glEnableDisableStack.Enable(true);
2953   glEnableDisableStack.EnableLogging(true);
2954   glStencilFunctionStack.Enable(true);
2955   glStencilFunctionStack.EnableLogging(true);
2956
2957   // RenderMode must use the stencil for StencilFunction to operate.
2958   renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::STENCIL);
2959   ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2960
2961   /*
2962    * Lookup table for testing StencilFunction.
2963    * Note: This MUST be in the same order as the Dali::StencilFunction enum.
2964    */
2965   const int StencilFunctionLookupTable[] = {
2966     GL_NEVER,
2967     GL_LESS,
2968     GL_EQUAL,
2969     GL_LEQUAL,
2970     GL_GREATER,
2971     GL_NOTEQUAL,
2972     GL_GEQUAL,
2973     GL_ALWAYS};
2974   const int StencilFunctionLookupTableCount = sizeof(StencilFunctionLookupTable) / sizeof(StencilFunctionLookupTable[0]);
2975
2976   /*
2977    * Loop through all types of StencilFunction, checking:
2978    *  - The value is cached (set in event thread side)
2979    *  - Causes "glStencilFunc" to be called
2980    *  - Checks the correct parameters to "glStencilFunc" were used
2981    */
2982   std::string nonChangingParameters = "0, 255";
2983   std::string methodString("StencilFunc");
2984   for(int i = 0; i < StencilFunctionLookupTableCount; ++i)
2985   {
2986     // Set the property.
2987     renderer.SetProperty(Renderer::Property::STENCIL_FUNCTION, static_cast<Dali::StencilFunction::Type>(i));
2988
2989     // Check GetProperty returns the same value.
2990     DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_FUNCTION).Get<int>()), i, TEST_LOCATION);
2991
2992     // Reset the trace debug.
2993     ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2994
2995     // Check the function is called and the parameters are correct.
2996     std::stringstream parameterStream;
2997     parameterStream << StencilFunctionLookupTable[i] << ", " << nonChangingParameters;
2998
2999     DALI_TEST_CHECK(glStencilFunctionStack.FindMethodAndParams(methodString, parameterStream.str()));
3000   }
3001
3002   // Change the Function Reference only and check the behavior is correct:
3003   // 170 is 0xaa in hex / 10101010 in binary (every other bit set).
3004   int testValueReference = 170;
3005   renderer.SetProperty(Renderer::Property::STENCIL_FUNCTION_REFERENCE, testValueReference);
3006
3007   DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_FUNCTION_REFERENCE).Get<int>()), testValueReference, TEST_LOCATION);
3008
3009   ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
3010
3011   DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetCurrentProperty(Renderer::Property::STENCIL_FUNCTION_REFERENCE).Get<int>()), testValueReference, TEST_LOCATION);
3012
3013   std::stringstream parameterStream;
3014   parameterStream << StencilFunctionLookupTable[StencilOperation::DECREMENT_WRAP] << ", " << testValueReference << ", 255";
3015
3016   DALI_TEST_CHECK(glStencilFunctionStack.FindMethodAndParams(methodString, parameterStream.str()));
3017
3018   // Change the Function Mask only and check the behavior is correct:
3019   // 85 is 0x55 in hex / 01010101 in binary (every other bit set).
3020   int testValueMask = 85;
3021   renderer.SetProperty(Renderer::Property::STENCIL_FUNCTION_MASK, testValueMask);
3022
3023   DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_FUNCTION_MASK).Get<int>()), testValueMask, TEST_LOCATION);
3024
3025   ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
3026
3027   DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetCurrentProperty(Renderer::Property::STENCIL_FUNCTION_MASK).Get<int>()), testValueMask, TEST_LOCATION);
3028
3029   // Clear the stringstream.
3030   parameterStream.str(std::string());
3031   parameterStream << StencilFunctionLookupTable[StencilOperation::DECREMENT_WRAP] << ", " << testValueReference << ", " << testValueMask;
3032
3033   DALI_TEST_CHECK(glStencilFunctionStack.FindMethodAndParams(methodString, parameterStream.str()));
3034
3035   END_TEST;
3036 }
3037
3038 int UtcDaliRendererSetStencilOperation(void)
3039 {
3040   TestApplication application;
3041   tet_infoline("Test setting the StencilOperation");
3042
3043   Renderer           renderer               = RendererTestFixture(application);
3044   TestGlAbstraction& glAbstraction          = application.GetGlAbstraction();
3045   TraceCallStack&    glEnableDisableStack   = glAbstraction.GetEnableDisableTrace();
3046   TraceCallStack&    glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
3047   glEnableDisableStack.Enable(true);
3048   glEnableDisableStack.EnableLogging(true);
3049   glStencilFunctionStack.Enable(true);
3050   glStencilFunctionStack.EnableLogging(true);
3051
3052   // RenderMode must use the stencil for StencilOperation to operate.
3053   renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::STENCIL);
3054
3055   /*
3056    * Lookup table for testing StencilOperation.
3057    * Note: This MUST be in the same order as the Dali::StencilOperation enum.
3058    */
3059   const int StencilOperationLookupTable[] = {
3060     GL_ZERO,
3061     GL_KEEP,
3062     GL_REPLACE,
3063     GL_INCR,
3064     GL_DECR,
3065     GL_INVERT,
3066     GL_INCR_WRAP,
3067     GL_DECR_WRAP};
3068   const int StencilOperationLookupTableCount = sizeof(StencilOperationLookupTable) / sizeof(StencilOperationLookupTable[0]);
3069
3070   // Set all 3 StencilOperation properties to a default.
3071   renderer.SetProperty(Renderer::Property::STENCIL_OPERATION_ON_FAIL, StencilOperation::KEEP);
3072   renderer.SetProperty(Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, StencilOperation::ZERO);
3073   renderer.SetProperty(Renderer::Property::STENCIL_OPERATION_ON_Z_PASS, StencilOperation::ZERO);
3074
3075   // Set our expected parameter list to the equivalent result.
3076   int parameters[] = {StencilOperationLookupTable[StencilOperation::ZERO], StencilOperationLookupTable[StencilOperation::ZERO], StencilOperationLookupTable[StencilOperation::ZERO]};
3077
3078   ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
3079
3080   /*
3081    * Loop through all types of StencilOperation, checking:
3082    *  - The value is cached (set in event thread side)
3083    *  - Causes "glStencilFunc" to be called
3084    *  - Checks the correct parameters to "glStencilFunc" were used
3085    *  - Checks the above for all 3 parameter placements of StencilOperation ( OnFail, OnZFail, OnPass )
3086    */
3087   std::string methodString("StencilOp");
3088
3089   for(int i = 0; i < StencilOperationLookupTableCount; ++i)
3090   {
3091     for(int j = 0; j < StencilOperationLookupTableCount; ++j)
3092     {
3093       for(int k = 0; k < StencilOperationLookupTableCount; ++k)
3094       {
3095         // Set the property (outer loop causes all 3 different properties to be set separately).
3096         renderer.SetProperty(Renderer::Property::STENCIL_OPERATION_ON_FAIL, static_cast<Dali::StencilFunction::Type>(i));
3097         renderer.SetProperty(Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, static_cast<Dali::StencilFunction::Type>(j));
3098         renderer.SetProperty(Renderer::Property::STENCIL_OPERATION_ON_Z_PASS, static_cast<Dali::StencilFunction::Type>(k));
3099
3100         // Check GetProperty returns the same value.
3101         DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_OPERATION_ON_FAIL).Get<int>()), i, TEST_LOCATION);
3102         DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL).Get<int>()), j, TEST_LOCATION);
3103         DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_OPERATION_ON_Z_PASS).Get<int>()), k, TEST_LOCATION);
3104
3105         // Reset the trace debug.
3106         ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
3107
3108         // Check the function is called and the parameters are correct.
3109         // Set the expected parameter value at its correct index (only)
3110         parameters[0u] = StencilOperationLookupTable[i];
3111         parameters[1u] = StencilOperationLookupTable[j];
3112         parameters[2u] = StencilOperationLookupTable[k];
3113
3114         // Build the parameter list.
3115         std::stringstream parameterStream;
3116         for(int parameterBuild = 0; parameterBuild < 3; ++parameterBuild)
3117         {
3118           parameterStream << parameters[parameterBuild];
3119           // Comma-separate the parameters.
3120           if(parameterBuild < 2)
3121           {
3122             parameterStream << ", ";
3123           }
3124         }
3125
3126         // Check the function was called and the parameters were correct.
3127         DALI_TEST_CHECK(glStencilFunctionStack.FindMethodAndParams(methodString, parameterStream.str()));
3128       }
3129     }
3130   }
3131
3132   END_TEST;
3133 }
3134
3135 int UtcDaliRendererSetStencilMask(void)
3136 {
3137   TestApplication application;
3138   tet_infoline("Test setting the StencilMask");
3139
3140   Renderer           renderer               = RendererTestFixture(application);
3141   TestGlAbstraction& glAbstraction          = application.GetGlAbstraction();
3142   TraceCallStack&    glEnableDisableStack   = glAbstraction.GetEnableDisableTrace();
3143   TraceCallStack&    glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
3144   glEnableDisableStack.Enable(true);
3145   glEnableDisableStack.EnableLogging(true);
3146   glStencilFunctionStack.Enable(true);
3147   glStencilFunctionStack.EnableLogging(true);
3148
3149   // RenderMode must use the stencil for StencilMask to operate.
3150   renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::STENCIL);
3151
3152   // Set the StencilMask property to a value.
3153   renderer.SetProperty(Renderer::Property::STENCIL_MASK, 0x00);
3154
3155   // Check GetProperty returns the same value.
3156   DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_MASK).Get<int>()), 0x00, TEST_LOCATION);
3157
3158   ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
3159
3160   DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetCurrentProperty(Renderer::Property::STENCIL_MASK).Get<int>()), 0x00, TEST_LOCATION);
3161
3162   std::string methodString("StencilMask");
3163   std::string parameterString = "0";
3164
3165   // Check the function was called and the parameters were correct.
3166   DALI_TEST_CHECK(glStencilFunctionStack.FindMethodAndParams(methodString, parameterString));
3167
3168   // Set the StencilMask property to another value to ensure it has changed.
3169   renderer.SetProperty(Renderer::Property::STENCIL_MASK, 0xFF);
3170
3171   // Check GetProperty returns the same value.
3172   DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_MASK).Get<int>()), 0xFF, TEST_LOCATION);
3173
3174   ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
3175
3176   DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetCurrentProperty(Renderer::Property::STENCIL_MASK).Get<int>()), 0xFF, TEST_LOCATION);
3177
3178   parameterString = "255";
3179
3180   // Check the function was called and the parameters were correct.
3181   DALI_TEST_CHECK(glStencilFunctionStack.FindMethodAndParams(methodString, parameterString));
3182
3183   END_TEST;
3184 }
3185
3186 int UtcDaliRendererWrongNumberOfTextures(void)
3187 {
3188   TestApplication application;
3189   tet_infoline("Test renderer does render even if number of textures is different than active samplers in the shader");
3190
3191   //Create a TextureSet with 4 textures (One more texture in the texture set than active samplers)
3192   //@note Shaders in the test suit have 3 active samplers. See TestGlAbstraction::GetActiveUniform()
3193   Texture    texture    = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64u, 64u);
3194   TextureSet textureSet = CreateTextureSet();
3195   textureSet.SetTexture(0, texture);
3196   textureSet.SetTexture(1, texture);
3197   textureSet.SetTexture(2, texture);
3198   textureSet.SetTexture(3, texture);
3199   Shader   shader   = Shader::New("VertexSource", "FragmentSource");
3200   Geometry geometry = CreateQuadGeometry();
3201   Renderer renderer = Renderer::New(geometry, shader);
3202   renderer.SetTextures(textureSet);
3203
3204   Actor actor = Actor::New();
3205   actor.AddRenderer(renderer);
3206   actor.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 0.0f));
3207   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
3208   application.GetScene().Add(actor);
3209
3210   TestGlAbstraction& gl        = application.GetGlAbstraction();
3211   TraceCallStack&    drawTrace = gl.GetDrawTrace();
3212   drawTrace.Reset();
3213   drawTrace.Enable(true);
3214   drawTrace.EnableLogging(true);
3215
3216   application.SendNotification();
3217   application.Render(0);
3218
3219   //Test we do the drawcall when TextureSet has more textures than there are active samplers in the shader
3220   DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION);
3221
3222   //Create a TextureSet with 1 texture (two more active samplers than texture in the texture set)
3223   //@note Shaders in the test suit have 3 active samplers. See TestGlAbstraction::GetActiveUniform()
3224   textureSet = CreateTextureSet();
3225   renderer.SetTextures(textureSet);
3226   textureSet.SetTexture(0, texture);
3227   drawTrace.Reset();
3228   application.SendNotification();
3229   application.Render(0);
3230
3231   //Test we do the drawcall when TextureSet has less textures than there are active samplers in the shader.
3232   DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION);
3233
3234   END_TEST;
3235 }
3236
3237 int UtcDaliRendererOpacity(void)
3238 {
3239   TestApplication application;
3240
3241   tet_infoline("Test OPACITY property");
3242
3243   Geometry geometry = CreateQuadGeometry();
3244   Shader   shader   = Shader::New("vertexSrc", "fragmentSrc");
3245   Renderer renderer = Renderer::New(geometry, shader);
3246
3247   Actor actor = Actor::New();
3248   actor.AddRenderer(renderer);
3249   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3250   actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 1.0f));
3251   application.GetScene().Add(actor);
3252
3253   Property::Value value = renderer.GetProperty(DevelRenderer::Property::OPACITY);
3254   float           opacity;
3255   DALI_TEST_CHECK(value.Get(opacity));
3256   DALI_TEST_EQUALS(opacity, 1.0f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3257
3258   application.SendNotification();
3259   application.Render();
3260
3261   Vector4            actualValue;
3262   Vector4            actualActorColor;
3263   TestGlAbstraction& gl = application.GetGlAbstraction();
3264   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uColor", actualValue));
3265   DALI_TEST_EQUALS(actualValue.a, 1.0f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3266   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uActorColor", actualActorColor));
3267   DALI_TEST_EQUALS(actualActorColor.a, 1.0f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3268
3269   renderer.SetProperty(DevelRenderer::Property::OPACITY, 0.5f);
3270
3271   application.SendNotification();
3272   application.Render();
3273
3274   value = renderer.GetProperty(DevelRenderer::Property::OPACITY);
3275   DALI_TEST_CHECK(value.Get(opacity));
3276   DALI_TEST_EQUALS(opacity, 0.5f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3277
3278   value = renderer.GetCurrentProperty(DevelRenderer::Property::OPACITY);
3279   DALI_TEST_CHECK(value.Get(opacity));
3280   DALI_TEST_EQUALS(opacity, 0.5f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3281
3282   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uColor", actualValue));
3283   DALI_TEST_EQUALS(actualValue.a, 0.5f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3284
3285   // Note : Renderer opacity doesn't apply to uActorColor.
3286   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uActorColor", actualActorColor));
3287   DALI_TEST_EQUALS(actualActorColor.a, 1.0f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3288
3289   END_TEST;
3290 }
3291
3292 int UtcDaliRendererOpacityAnimation(void)
3293 {
3294   TestApplication application;
3295
3296   tet_infoline("Test OPACITY property animation");
3297
3298   Geometry geometry = CreateQuadGeometry();
3299   Shader   shader   = Shader::New("vertexSrc", "fragmentSrc");
3300   Renderer renderer = Renderer::New(geometry, shader);
3301
3302   Actor actor = Actor::New();
3303   actor.AddRenderer(renderer);
3304   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3305   actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 1.0f));
3306   application.GetScene().Add(actor);
3307
3308   application.SendNotification();
3309   application.Render(0);
3310
3311   Property::Value value = renderer.GetProperty(DevelRenderer::Property::OPACITY);
3312   float           opacity;
3313   DALI_TEST_CHECK(value.Get(opacity));
3314   DALI_TEST_EQUALS(opacity, 1.0f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3315
3316   Animation animation = Animation::New(1.0f);
3317   animation.AnimateTo(Property(renderer, DevelRenderer::Property::OPACITY), 0.0f);
3318   animation.Play();
3319
3320   application.SendNotification();
3321   application.Render(1000);
3322
3323   value = renderer.GetProperty(DevelRenderer::Property::OPACITY);
3324   DALI_TEST_CHECK(value.Get(opacity));
3325   DALI_TEST_EQUALS(opacity, 0.0f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3326
3327   // Need to clear the animation before setting the property as the animation value is baked and will override any previous setters
3328   animation.Clear();
3329   renderer.SetProperty(DevelRenderer::Property::OPACITY, 0.1f);
3330
3331   animation.AnimateBy(Property(renderer, DevelRenderer::Property::OPACITY), 0.5f);
3332   animation.Play();
3333
3334   application.SendNotification();
3335   application.Render(1000);
3336
3337   value = renderer.GetProperty(DevelRenderer::Property::OPACITY);
3338   DALI_TEST_CHECK(value.Get(opacity));
3339   DALI_TEST_EQUALS(opacity, 0.6f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3340   DALI_TEST_EQUALS(opacity, renderer.GetCurrentProperty(DevelRenderer::Property::OPACITY).Get<float>(), Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3341
3342   END_TEST;
3343 }
3344
3345 int UtcDaliRendererInvalidProperty(void)
3346 {
3347   TestApplication application;
3348
3349   tet_infoline("Test invalid property");
3350
3351   Geometry geometry = CreateQuadGeometry();
3352   Shader   shader   = Shader::New("vertexSrc", "fragmentSrc");
3353   Renderer renderer = Renderer::New(geometry, shader);
3354
3355   Actor actor = Actor::New();
3356   actor.AddRenderer(renderer);
3357   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3358   application.GetScene().Add(actor);
3359
3360   application.SendNotification();
3361   application.Render(0);
3362
3363   Property::Value value = renderer.GetProperty(Renderer::Property::DEPTH_INDEX + 100);
3364   DALI_TEST_CHECK(value.GetType() == Property::Type::NONE);
3365
3366   value = renderer.GetCurrentProperty(Renderer::Property::DEPTH_INDEX + 100);
3367   DALI_TEST_CHECK(value.GetType() == Property::Type::NONE);
3368
3369   END_TEST;
3370 }
3371
3372 int UtcDaliRendererRenderingBehavior(void)
3373 {
3374   TestApplication application;
3375
3376   tet_infoline("Test RENDERING_BEHAVIOR property");
3377
3378   Geometry geometry = CreateQuadGeometry();
3379   Shader   shader   = Shader::New("vertexSrc", "fragmentSrc");
3380   Renderer renderer = Renderer::New(geometry, shader);
3381
3382   Actor actor = Actor::New();
3383   actor.AddRenderer(renderer);
3384   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3385   actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 1.0f));
3386   application.GetScene().Add(actor);
3387
3388   Property::Value value = renderer.GetProperty(DevelRenderer::Property::RENDERING_BEHAVIOR);
3389   int             renderingBehavior;
3390   DALI_TEST_CHECK(value.Get(renderingBehavior));
3391   DALI_TEST_EQUALS(static_cast<DevelRenderer::Rendering::Type>(renderingBehavior), DevelRenderer::Rendering::IF_REQUIRED, TEST_LOCATION);
3392
3393   application.SendNotification();
3394   application.Render();
3395
3396   uint32_t updateStatus = application.GetUpdateStatus();
3397
3398   DALI_TEST_CHECK(!(updateStatus & Integration::KeepUpdating::STAGE_KEEP_RENDERING));
3399
3400   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
3401   TraceCallStack&    drawTrace     = glAbstraction.GetDrawTrace();
3402   drawTrace.Enable(true);
3403   drawTrace.Reset();
3404
3405   renderer.SetProperty(DevelRenderer::Property::RENDERING_BEHAVIOR, DevelRenderer::Rendering::CONTINUOUSLY);
3406
3407   value = renderer.GetProperty(DevelRenderer::Property::RENDERING_BEHAVIOR);
3408   DALI_TEST_CHECK(value.Get(renderingBehavior));
3409   DALI_TEST_EQUALS(static_cast<DevelRenderer::Rendering::Type>(renderingBehavior), DevelRenderer::Rendering::CONTINUOUSLY, TEST_LOCATION);
3410
3411   // Render and check the update status
3412   application.SendNotification();
3413   application.Render();
3414
3415   updateStatus = application.GetUpdateStatus();
3416
3417   DALI_TEST_CHECK(updateStatus & Integration::KeepUpdating::STAGE_KEEP_RENDERING);
3418
3419   value = renderer.GetCurrentProperty(DevelRenderer::Property::RENDERING_BEHAVIOR);
3420   DALI_TEST_CHECK(value.Get(renderingBehavior));
3421   DALI_TEST_EQUALS(static_cast<DevelRenderer::Rendering::Type>(renderingBehavior), DevelRenderer::Rendering::CONTINUOUSLY, TEST_LOCATION);
3422
3423   DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION);
3424
3425   drawTrace.Reset();
3426
3427   // Render again and check the update status
3428   application.SendNotification();
3429   application.Render();
3430
3431   updateStatus = application.GetUpdateStatus();
3432
3433   DALI_TEST_CHECK(updateStatus & Integration::KeepUpdating::STAGE_KEEP_RENDERING);
3434
3435   DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION);
3436
3437   {
3438     // Render again and check the update status
3439     Animation animation = Animation::New(1.0f);
3440     animation.AnimateTo(Property(renderer, DevelRenderer::Property::OPACITY), 0.0f, TimePeriod(0.5f, 0.5f));
3441     animation.Play();
3442
3443     drawTrace.Reset();
3444
3445     application.SendNotification();
3446     application.Render(0);
3447
3448     DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION);
3449
3450     drawTrace.Reset();
3451
3452     application.SendNotification();
3453     application.Render(100);
3454
3455     updateStatus = application.GetUpdateStatus();
3456
3457     DALI_TEST_CHECK(updateStatus & Integration::KeepUpdating::STAGE_KEEP_RENDERING);
3458
3459     DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION);
3460   }
3461
3462   // Change rendering behavior
3463   renderer.SetProperty(DevelRenderer::Property::RENDERING_BEHAVIOR, DevelRenderer::Rendering::IF_REQUIRED);
3464
3465   // Render and check the update status
3466   application.SendNotification();
3467   application.Render();
3468
3469   updateStatus = application.GetUpdateStatus();
3470
3471   DALI_TEST_CHECK(!(updateStatus & Integration::KeepUpdating::STAGE_KEEP_RENDERING));
3472
3473   END_TEST;
3474 }
3475
3476 int UtcDaliRendererRegenerateUniformMap(void)
3477 {
3478   TestApplication application;
3479
3480   tet_infoline("Test regenerating uniform map when attaching renderer to the node");
3481
3482   Geometry geometry = CreateQuadGeometry();
3483   Shader   shader   = Shader::New("vertexSrc", "fragmentSrc");
3484   Renderer renderer = Renderer::New(geometry, shader);
3485
3486   Actor actor = Actor::New();
3487   actor.AddRenderer(renderer);
3488   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3489   actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 1.0f));
3490   application.GetScene().Add(actor);
3491
3492   application.SendNotification();
3493   application.Render();
3494
3495   actor.RemoveRenderer(renderer);
3496   shader = Shader::New("vertexSrc", "fragmentSrc");
3497   shader.RegisterProperty("opacity", 0.5f);
3498   renderer.SetShader(shader);
3499
3500   Stage::GetCurrent().KeepRendering(1.0f);
3501
3502   // Update for several frames
3503   application.SendNotification();
3504   application.Render();
3505   application.SendNotification();
3506   application.Render();
3507   application.SendNotification();
3508   application.Render();
3509   application.SendNotification();
3510   application.Render();
3511
3512   // Add Renderer
3513   actor.AddRenderer(renderer);
3514   application.SendNotification();
3515   application.Render();
3516
3517   // Nothing to test here, the test must not crash
3518   auto updateStatus = application.GetUpdateStatus();
3519   DALI_TEST_CHECK(updateStatus & Integration::KeepUpdating::STAGE_KEEP_RENDERING);
3520
3521   END_TEST;
3522 }
3523
3524 int UtcDaliRendererRenderAfterAddShader(void)
3525 {
3526   TestApplication    application;
3527   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
3528
3529   tet_infoline("Test regenerating uniform map when shader changed");
3530
3531   Geometry geometry = CreateQuadGeometry();
3532   Shader   shader1  = Shader::New("vertexSrc1", "fragmentSrc1");
3533   Shader   shader2  = Shader::New("vertexSrc2", "fragmentSrc2");
3534   Renderer renderer = Renderer::New(geometry, shader1);
3535
3536   // Register each shader1 and shader2 only had
3537   shader1.RegisterProperty("uUniform1", Color::CRIMSON);
3538   shader2.RegisterProperty("uShader2Only", Color::AQUA_MARINE);
3539
3540   Actor actor = Actor::New();
3541   actor.AddRenderer(renderer);
3542   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3543   actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 1.0f));
3544   application.GetScene().Add(actor);
3545
3546   Property::Value value = renderer.GetProperty(DevelRenderer::Property::RENDERING_BEHAVIOR);
3547   int             renderingBehavior;
3548   DALI_TEST_CHECK(value.Get(renderingBehavior));
3549   DALI_TEST_EQUALS(static_cast<DevelRenderer::Rendering::Type>(renderingBehavior), DevelRenderer::Rendering::IF_REQUIRED, TEST_LOCATION);
3550
3551   application.SendNotification();
3552   application.Render(0);
3553
3554   // Check uUniform1 rendered and uUniform2 not rendered before
3555   Vector4 actualValue(Vector4::ZERO);
3556   DALI_TEST_CHECK(glAbstraction.GetUniformValue<Vector4>("uUniform1", actualValue));
3557   DALI_TEST_EQUALS(actualValue, Color::CRIMSON, TEST_LOCATION);
3558
3559   uint32_t updateStatus = application.GetUpdateStatus();
3560
3561   DALI_TEST_CHECK(!(updateStatus & Integration::KeepUpdating::STAGE_KEEP_RENDERING));
3562
3563   // Update for several frames
3564   application.SendNotification();
3565   application.Render();
3566   application.SendNotification();
3567   application.Render();
3568   application.SendNotification();
3569   application.Render();
3570   application.SendNotification();
3571   application.Render();
3572   application.SendNotification();
3573   application.Render();
3574
3575   TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
3576   drawTrace.Enable(true);
3577   drawTrace.Reset();
3578
3579   std::vector<UniformData> customUniforms{{"uShader2Only", Property::VECTOR4}};
3580
3581   application.GetGraphicsController().AddCustomUniforms(customUniforms);
3582
3583   // Change shader.
3584   renderer.SetShader(shader2);
3585
3586   // Render and check the update status
3587   application.SendNotification();
3588   application.Render(0);
3589
3590   updateStatus = application.GetUpdateStatus();
3591
3592   DALI_TEST_CHECK(!(updateStatus & Integration::KeepUpdating::STAGE_KEEP_RENDERING));
3593
3594   DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION);
3595
3596   // Check uUniform2 rendered now
3597   DALI_TEST_CHECK(glAbstraction.GetUniformValue<Vector4>("uShader2Only", actualValue));
3598   DALI_TEST_EQUALS(actualValue, Color::AQUA_MARINE, TEST_LOCATION);
3599
3600   END_TEST;
3601 }
3602
3603 int UtcDaliRendererAddDrawCommands(void)
3604 {
3605   TestApplication application;
3606
3607   tet_infoline("Test adding draw commands to the renderer");
3608
3609   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
3610   glAbstraction.EnableEnableDisableCallTrace(true);
3611
3612   Geometry geometry = CreateQuadGeometry();
3613   Shader   shader   = Shader::New("vertexSrc", "fragmentSrc");
3614   Renderer renderer = Renderer::New(geometry, shader);
3615
3616   renderer.SetProperty(Renderer::Property::BLEND_MODE, Dali::BlendMode::ON);
3617   Actor actor = Actor::New();
3618   actor.AddRenderer(renderer);
3619   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3620   actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 1.0f));
3621   application.GetScene().Add(actor);
3622
3623   // Expect delivering a single draw call
3624   auto& drawTrace = glAbstraction.GetDrawTrace();
3625   drawTrace.Reset();
3626   drawTrace.Enable(true);
3627   application.SendNotification();
3628   application.Render();
3629
3630   DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION);
3631
3632   tet_infoline("\n\nTesting extension draw commands\n");
3633   auto drawCommand1         = DevelRenderer::DrawCommand{};
3634   drawCommand1.drawType     = DevelRenderer::DrawType::INDEXED;
3635   drawCommand1.firstIndex   = 0;
3636   drawCommand1.elementCount = 2;
3637   drawCommand1.queue        = DevelRenderer::RENDER_QUEUE_OPAQUE;
3638
3639   auto drawCommand2         = DevelRenderer::DrawCommand{};
3640   drawCommand2.drawType     = DevelRenderer::DrawType::INDEXED;
3641   drawCommand2.firstIndex   = 2;
3642   drawCommand2.elementCount = 2;
3643   drawCommand2.queue        = DevelRenderer::RENDER_QUEUE_TRANSPARENT;
3644
3645   auto drawCommand3         = DevelRenderer::DrawCommand{};
3646   drawCommand3.drawType     = DevelRenderer::DrawType::ARRAY;
3647   drawCommand3.firstIndex   = 2;
3648   drawCommand3.elementCount = 2;
3649   drawCommand3.queue        = DevelRenderer::RENDER_QUEUE_OPAQUE;
3650
3651   DevelRenderer::AddDrawCommand(renderer, drawCommand1);
3652   DevelRenderer::AddDrawCommand(renderer, drawCommand2);
3653   DevelRenderer::AddDrawCommand(renderer, drawCommand3);
3654
3655   drawTrace.Reset();
3656   drawTrace.Enable(true);
3657   application.SendNotification();
3658   application.Render();
3659
3660   DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 3, TEST_LOCATION);
3661   END_TEST;
3662 }
3663 int UtcDaliRendererSetGeometryNegative(void)
3664 {
3665   TestApplication application;
3666   Dali::Renderer  instance;
3667   try
3668   {
3669     Dali::Geometry arg1;
3670     instance.SetGeometry(arg1);
3671     DALI_TEST_CHECK(false); // Should not get here
3672   }
3673   catch(...)
3674   {
3675     DALI_TEST_CHECK(true); // We expect an assert
3676   }
3677   END_TEST;
3678 }
3679
3680 int UtcDaliRendererSetTexturesNegative(void)
3681 {
3682   TestApplication application;
3683   Dali::Renderer  instance;
3684   try
3685   {
3686     Dali::TextureSet arg1;
3687     instance.SetTextures(arg1);
3688     DALI_TEST_CHECK(false); // Should not get here
3689   }
3690   catch(...)
3691   {
3692     DALI_TEST_CHECK(true); // We expect an assert
3693   }
3694   END_TEST;
3695 }
3696
3697 int UtcDaliRendererSetShaderNegative(void)
3698 {
3699   TestApplication application;
3700   Dali::Renderer  instance;
3701   try
3702   {
3703     Dali::Shader arg1;
3704     instance.SetShader(arg1);
3705     DALI_TEST_CHECK(false); // Should not get here
3706   }
3707   catch(...)
3708   {
3709     DALI_TEST_CHECK(true); // We expect an assert
3710   }
3711   END_TEST;
3712 }
3713
3714 int UtcDaliRendererGetGeometryNegative(void)
3715 {
3716   TestApplication application;
3717   Dali::Renderer  instance;
3718   try
3719   {
3720     instance.GetGeometry();
3721     DALI_TEST_CHECK(false); // Should not get here
3722   }
3723   catch(...)
3724   {
3725     DALI_TEST_CHECK(true); // We expect an assert
3726   }
3727   END_TEST;
3728 }
3729
3730 int UtcDaliRendererGetTexturesNegative(void)
3731 {
3732   TestApplication application;
3733   Dali::Renderer  instance;
3734   try
3735   {
3736     instance.GetTextures();
3737     DALI_TEST_CHECK(false); // Should not get here
3738   }
3739   catch(...)
3740   {
3741     DALI_TEST_CHECK(true); // We expect an assert
3742   }
3743   END_TEST;
3744 }
3745
3746 int UtcDaliRendererGetShaderNegative(void)
3747 {
3748   TestApplication application;
3749   Dali::Renderer  instance;
3750   try
3751   {
3752     instance.GetShader();
3753     DALI_TEST_CHECK(false); // Should not get here
3754   }
3755   catch(...)
3756   {
3757     DALI_TEST_CHECK(true); // We expect an assert
3758   }
3759   END_TEST;
3760 }
3761
3762 int UtcDaliRendererCheckTextureBindingP(void)
3763 {
3764   TestApplication application;
3765
3766   tet_infoline("Test adding draw commands to the renderer");
3767
3768   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
3769   glAbstraction.EnableEnableDisableCallTrace(true);
3770
3771   Geometry geometry = CreateQuadGeometry();
3772   Shader   shader   = Shader::New("vertexSrc", "fragmentSrc");
3773   Renderer renderer = Renderer::New(geometry, shader);
3774
3775   renderer.SetProperty(Renderer::Property::BLEND_MODE, Dali::BlendMode::ON);
3776   Actor actor = Actor::New();
3777   actor.AddRenderer(renderer);
3778   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3779   actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 1.0f));
3780   application.GetScene().Add(actor);
3781
3782   TestGraphicsController& graphics        = application.GetGraphicsController();
3783   TraceCallStack&         cmdBufCallstack = graphics.mCommandBufferCallStack;
3784   cmdBufCallstack.Enable(true);
3785
3786   application.SendNotification();
3787   application.Render();
3788
3789   DALI_TEST_CHECK(!cmdBufCallstack.FindMethod("BindTextures"));
3790
3791   Texture    image0      = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGB888, 64, 64);
3792   TextureSet textureSet0 = CreateTextureSet(image0);
3793   renderer.SetTextures(textureSet0);
3794
3795   application.SendNotification();
3796   application.Render();
3797
3798   DALI_TEST_CHECK(cmdBufCallstack.FindMethod("BindTextures"));
3799   END_TEST;
3800 }
3801
3802 int UtcDaliRendererPreparePipeline(void)
3803 {
3804   TestApplication application;
3805
3806   tet_infoline("Test that rendering an actor binds the attributes locs from the reflection");
3807
3808   Property::Map vf            = CreateModelVertexFormat();
3809   Geometry      modelGeometry = CreateModelGeometry(vf);
3810   Shader        shader        = Shader::New("vertexSrc", "fragmentSrc");
3811   Renderer      renderer      = Renderer::New(modelGeometry, shader);
3812   Actor         actor         = Actor::New();
3813
3814   // Change the order up to get a fair test
3815   Property::Map modelVF;
3816   modelVF["aBoneIndex[0]"]   = Property::INTEGER;
3817   modelVF["aBoneIndex[1]"]   = Property::INTEGER;
3818   modelVF["aBoneIndex[2]"]   = Property::INTEGER;
3819   modelVF["aBoneIndex[3]"]   = Property::INTEGER;
3820   modelVF["aBoneWeights[0]"] = Property::FLOAT;
3821   modelVF["aBoneWeights[1]"] = Property::FLOAT;
3822   modelVF["aBoneWeights[2]"] = Property::FLOAT;
3823   modelVF["aBoneWeights[3]"] = Property::FLOAT;
3824   modelVF["aPosition"]       = Property::VECTOR3;
3825   modelVF["aNormal"]         = Property::VECTOR3;
3826   modelVF["aTexCoord1"]      = Property::VECTOR3;
3827   modelVF["aTexCoord2"]      = Property::VECTOR3;
3828
3829   Property::Array vfs;
3830   vfs.PushBack(modelVF);
3831   TestGraphicsController& graphics = application.GetGraphicsController();
3832   graphics.SetVertexFormats(vfs);
3833
3834   actor.AddRenderer(renderer);
3835   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3836   actor.SetProperty(Actor::Property::COLOR, Color::WHITE);
3837   application.GetScene().Add(actor);
3838
3839   TraceCallStack& cmdBufCallstack   = graphics.mCommandBufferCallStack;
3840   TraceCallStack& graphicsCallstack = graphics.mCallStack;
3841   cmdBufCallstack.Enable(true);
3842   graphicsCallstack.Enable(true);
3843
3844   application.SendNotification();
3845   application.Render();
3846
3847   DALI_TEST_CHECK(graphicsCallstack.FindMethod("SubmitCommandBuffers"));
3848   std::vector<Graphics::SubmitInfo>& submissions = graphics.mSubmitStack;
3849   DALI_TEST_CHECK(submissions.size() > 0);
3850
3851   TestGraphicsCommandBuffer* cmdBuf = static_cast<TestGraphicsCommandBuffer*>((submissions.back().cmdBuffer[0]));
3852
3853   auto result   = cmdBuf->GetChildCommandsByType(0 | CommandType::BIND_PIPELINE);
3854   auto pipeline = result[0]->data.bindPipeline.pipeline;
3855
3856   if(pipeline)
3857   {
3858     DALI_TEST_EQUALS(pipeline->vertexInputState.attributes.size(), 12, TEST_LOCATION);
3859     DALI_TEST_EQUALS(pipeline->vertexInputState.attributes[3].location, // 4th requested attr: aTexCoord2
3860                      11,
3861                      TEST_LOCATION);
3862     DALI_TEST_EQUALS(pipeline->vertexInputState.attributes[3].format, // 4th requested attr: aTexCoord2
3863                      Graphics::VertexInputFormat::FVECTOR3,
3864                      TEST_LOCATION);
3865   }
3866
3867   END_TEST;
3868 }
3869
3870 int UtcDaliRendererUniformArrayOfStruct(void)
3871 {
3872   TestApplication application;
3873   tet_infoline("Test that uniforms that are elements of arrays of structs can be accessed");
3874
3875   std::vector<UniformData> customUniforms{{"arrayof[10].color", Property::VECTOR4},
3876                                           {"arrayof[10].position", Property::VECTOR2},
3877                                           {"arrayof[10].normal", Property::VECTOR3}};
3878
3879   application.GetGraphicsController().AddCustomUniforms(customUniforms);
3880
3881   Geometry geometry = CreateQuadGeometry();
3882   Shader   shader   = Shader::New("vertexSrc", "fragmentSrc");
3883   Renderer renderer = Renderer::New(geometry, shader);
3884   Actor    actor    = Actor::New();
3885   actor.AddRenderer(renderer);
3886   actor[Actor::Property::SIZE] = Vector2(120, 120);
3887   application.GetScene().Add(actor);
3888
3889   // Define some properties to match the custom uniforms.
3890   // Ensure they can be written & read back from the abstraction.
3891
3892   struct UniformIndexPair
3893   {
3894     Property::Index index;
3895     std::string     name;
3896     UniformIndexPair(Property::Index index, std::string name)
3897     : index(index),
3898       name(name)
3899     {
3900     }
3901   };
3902   std::vector<UniformIndexPair> uniformIndices;
3903
3904   std::ostringstream oss;
3905   for(int i = 0; i < 10; ++i)
3906   {
3907     Property::Index index;
3908     oss << "arrayof[" << i << "].color";
3909     Vector4 color = Color::WHITE;
3910     color.r       = 25.5f * i;
3911     index         = renderer.RegisterProperty(oss.str(), color);
3912     uniformIndices.emplace_back(index, oss.str());
3913
3914     oss.str("");
3915     oss.clear();
3916     oss << "arrayof[" << i << "].position";
3917     Vector2 pos(i, 10 + i * 5);
3918     index = renderer.RegisterProperty(oss.str(), pos);
3919     uniformIndices.emplace_back(index, oss.str());
3920
3921     oss.str("");
3922     oss.clear();
3923     oss << "arrayof[" << i << "].normal";
3924     Vector3 normal(i, i * 10, i * 100);
3925     index = renderer.RegisterProperty(oss.str(), normal);
3926     uniformIndices.emplace_back(index, oss.str());
3927     oss.str("");
3928     oss.clear();
3929   }
3930   auto&           gl        = application.GetGlAbstraction();
3931   TraceCallStack& callStack = gl.GetSetUniformTrace();
3932   gl.EnableSetUniformCallTrace(true);
3933
3934   application.SendNotification();
3935   application.Render();
3936
3937   // Check that the uniforms match.
3938   TraceCallStack::NamedParams params;
3939   for(auto& uniformInfo : uniformIndices)
3940   {
3941     Property::Value value = renderer.GetProperty(uniformInfo.index);
3942     switch(value.GetType())
3943     {
3944       case Property::VECTOR2:
3945       {
3946         DALI_TEST_CHECK(callStack.FindMethodAndGetParameters(uniformInfo.name, params));
3947         Vector2 setValue;
3948         DALI_TEST_CHECK(gl.GetUniformValue<Vector2>(uniformInfo.name.c_str(), setValue));
3949         DALI_TEST_EQUALS(value.Get<Vector2>(), setValue, 0.001f, TEST_LOCATION);
3950         break;
3951       }
3952       case Property::VECTOR3:
3953       {
3954         DALI_TEST_CHECK(callStack.FindMethodAndGetParameters(uniformInfo.name, params));
3955         Vector3 setValue;
3956         DALI_TEST_CHECK(gl.GetUniformValue<Vector3>(uniformInfo.name.c_str(), setValue));
3957         DALI_TEST_EQUALS(value.Get<Vector3>(), setValue, 0.001f, TEST_LOCATION);
3958         break;
3959       }
3960       case Property::VECTOR4:
3961       {
3962         DALI_TEST_CHECK(callStack.FindMethodAndGetParameters(uniformInfo.name, params));
3963         Vector4 setValue;
3964         DALI_TEST_CHECK(gl.GetUniformValue<Vector4>(uniformInfo.name.c_str(), setValue));
3965         DALI_TEST_EQUALS(value.Get<Vector4>(), setValue, 0.001f, TEST_LOCATION);
3966         break;
3967       }
3968       default:
3969         break;
3970     }
3971   }
3972
3973   // There is a hash in the property name's uniform map: check this in debugger
3974   // There is a hash in the reflection. Check this in the debugger.
3975
3976   // Check that the reflection contains individual locs for each array entry's struct element
3977   // and that it hashes the whole string
3978
3979   // Ensure that the property name's hash is also for the whole string.
3980
3981   END_TEST;
3982 }
3983
3984 int utcDaliRendererPartialUpdateChangeUniform(void)
3985 {
3986   TestApplication application(
3987     TestApplication::DEFAULT_SURFACE_WIDTH,
3988     TestApplication::DEFAULT_SURFACE_HEIGHT,
3989     TestApplication::DEFAULT_HORIZONTAL_DPI,
3990     TestApplication::DEFAULT_VERTICAL_DPI,
3991     true,
3992     true);
3993
3994   tet_infoline("Check the damaged rect with changing uniform");
3995
3996   const TestGlAbstraction::ScissorParams& glScissorParams(application.GetGlAbstraction().GetScissorParams());
3997
3998   std::vector<Rect<int>> damagedRects;
3999   Rect<int>              clippingRect;
4000   application.SendNotification();
4001   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
4002
4003   // First render pass, nothing to render, adaptor would just do swap buffer.
4004   DALI_TEST_EQUALS(damagedRects.size(), 0, TEST_LOCATION);
4005   application.RenderWithPartialUpdate(damagedRects, clippingRect);
4006
4007   Shader   shader   = Shader::New("VertexSource", "FragmentSource");
4008   Geometry geometry = CreateQuadGeometry();
4009   Renderer renderer = Renderer::New(geometry, shader);
4010
4011   Property::Index colorIndex = renderer.RegisterProperty("uFadeColor", Color::WHITE);
4012
4013   Actor actor = Actor::New();
4014   actor.AddRenderer(renderer);
4015   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
4016   actor.SetProperty(Actor::Property::POSITION, Vector3(16.0f, 16.0f, 0.0f));
4017   actor.SetProperty(Actor::Property::SIZE, Vector3(16.0f, 16.0f, 0.0f));
4018   actor.SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS);
4019   Stage::GetCurrent().Add(actor);
4020
4021   application.SendNotification();
4022
4023   // 1. Actor added, damaged rect is added size of actor
4024   damagedRects.clear();
4025   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
4026   DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
4027
4028   // Aligned by 16
4029   clippingRect = Rect<int>(16, 768, 32, 32); // in screen coordinates
4030   DALI_TEST_EQUALS<Rect<int>>(clippingRect, damagedRects[0], TEST_LOCATION);
4031   application.RenderWithPartialUpdate(damagedRects, clippingRect);
4032   DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
4033   DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
4034   DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
4035   DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
4036
4037   damagedRects.clear();
4038   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
4039   application.RenderWithPartialUpdate(damagedRects, clippingRect);
4040
4041   // Ensure the damaged rect is empty
4042   DALI_TEST_EQUALS(damagedRects.size(), 0, TEST_LOCATION);
4043
4044   // 2. Change the uniform value
4045   renderer.SetProperty(colorIndex, Color::RED);
4046   application.SendNotification();
4047
4048   damagedRects.clear();
4049   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
4050   DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
4051
4052   // Aligned by 16
4053   clippingRect = Rect<int>(16, 768, 32, 32); // in screen coordinates
4054   DALI_TEST_EQUALS<Rect<int>>(clippingRect, damagedRects[0], TEST_LOCATION);
4055   application.RenderWithPartialUpdate(damagedRects, clippingRect);
4056   DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
4057   DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
4058   DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
4059   DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
4060
4061   damagedRects.clear();
4062   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
4063   application.RenderWithPartialUpdate(damagedRects, clippingRect);
4064
4065   // 3. Change the uniform value and another property together
4066   actor.SetProperty(Actor::Property::COLOR, Color::YELLOW);
4067   renderer.SetProperty(colorIndex, Color::BLUE);
4068   application.SendNotification();
4069
4070   damagedRects.clear();
4071   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
4072   DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
4073
4074   // Aligned by 16
4075   clippingRect = Rect<int>(16, 768, 32, 32); // in screen coordinates
4076   DALI_TEST_EQUALS<Rect<int>>(clippingRect, damagedRects[0], TEST_LOCATION);
4077   application.RenderWithPartialUpdate(damagedRects, clippingRect);
4078   DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
4079   DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
4080   DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
4081   DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
4082
4083   damagedRects.clear();
4084   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
4085   application.RenderWithPartialUpdate(damagedRects, clippingRect);
4086
4087   // 4. Change the uniform value only
4088   renderer.SetProperty(colorIndex, Color::RED); // Set the previous value (#2)
4089   application.SendNotification();
4090
4091   damagedRects.clear();
4092   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
4093   DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
4094
4095   // Aligned by 16
4096   clippingRect = Rect<int>(16, 768, 32, 32); // in screen coordinates
4097   DALI_TEST_EQUALS<Rect<int>>(clippingRect, damagedRects[0], TEST_LOCATION);
4098   application.RenderWithPartialUpdate(damagedRects, clippingRect);
4099   DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
4100   DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
4101   DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
4102   DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
4103
4104   END_TEST;
4105 }
4106
4107 int utcDaliRendererPartialUpdateAddRemoveRenderer(void)
4108 {
4109   TestApplication application(
4110     TestApplication::DEFAULT_SURFACE_WIDTH,
4111     TestApplication::DEFAULT_SURFACE_HEIGHT,
4112     TestApplication::DEFAULT_HORIZONTAL_DPI,
4113     TestApplication::DEFAULT_VERTICAL_DPI,
4114     true,
4115     true);
4116
4117   tet_infoline("Check the damaged rect with adding / removing renderer");
4118
4119   const TestGlAbstraction::ScissorParams& glScissorParams(application.GetGlAbstraction().GetScissorParams());
4120
4121   Shader   shader   = Shader::New("VertexSource", "FragmentSource");
4122   Geometry geometry = CreateQuadGeometry();
4123   Renderer renderer = Renderer::New(geometry, shader);
4124
4125   Actor actor = Actor::New();
4126   actor.AddRenderer(renderer);
4127   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
4128   actor.SetProperty(Actor::Property::POSITION, Vector3(16.0f, 16.0f, 0.0f));
4129   actor.SetProperty(Actor::Property::SIZE, Vector3(16.0f, 16.0f, 0.0f));
4130   actor.SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS);
4131   Stage::GetCurrent().Add(actor);
4132
4133   application.SendNotification();
4134
4135   std::vector<Rect<int>> damagedRects;
4136   Rect<int>              clippingRect;
4137
4138   // 1. Actor added, damaged rect is added size of actor
4139   damagedRects.clear();
4140   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
4141   DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
4142
4143   // Aligned by 16
4144   clippingRect = Rect<int>(16, 768, 32, 32); // in screen coordinates
4145   DALI_TEST_EQUALS<Rect<int>>(clippingRect, damagedRects[0], TEST_LOCATION);
4146   application.RenderWithPartialUpdate(damagedRects, clippingRect);
4147   DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
4148   DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
4149   DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
4150   DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
4151
4152   // 2. Remove renderer
4153   actor.RemoveRenderer(renderer);
4154   application.SendNotification();
4155
4156   damagedRects.clear();
4157   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
4158
4159   DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
4160   DALI_TEST_EQUALS<Rect<int>>(clippingRect, damagedRects[0], TEST_LOCATION);
4161
4162   application.RenderWithPartialUpdate(damagedRects, clippingRect);
4163
4164   // 3. Change a property value of the Renderer
4165   renderer.SetProperty(DevelRenderer::Property::OPACITY, 0.5f);
4166   application.SendNotification();
4167
4168   damagedRects.clear();
4169   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
4170
4171   DALI_TEST_EQUALS(damagedRects.size(), 0, TEST_LOCATION);
4172
4173   application.RenderWithPartialUpdate(damagedRects, clippingRect);
4174
4175   // 4. Add renderer again
4176   actor.AddRenderer(renderer);
4177   application.SendNotification();
4178
4179   damagedRects.clear();
4180   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
4181
4182   DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
4183   DALI_TEST_EQUALS<Rect<int>>(clippingRect, damagedRects[0], TEST_LOCATION);
4184
4185   application.RenderWithPartialUpdate(damagedRects, clippingRect);
4186
4187   // 5. Remove renderer agin
4188   actor.RemoveRenderer(renderer);
4189   application.SendNotification();
4190
4191   damagedRects.clear();
4192   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
4193
4194   DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
4195   DALI_TEST_EQUALS<Rect<int>>(clippingRect, damagedRects[0], TEST_LOCATION);
4196
4197   application.RenderWithPartialUpdate(damagedRects, clippingRect);
4198
4199   END_TEST;
4200 }