Add BlendMode::ON_WITHOUT_CULL to keep rendering even Transparent.
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-Renderer.cpp
1 /*
2  * Copyright (c) 2021 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
702   if(Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::MAX))
703   {
704     renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::MAX);
705     int equationRgb = renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION);
706     DALI_TEST_EQUALS((int)DevelBlendEquation::MAX, equationRgb, TEST_LOCATION);
707   }
708
709   if(Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::SCREEN))
710   {
711     renderer.SetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, true);
712     renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::SCREEN);
713     int equation = renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION);
714
715     DALI_TEST_EQUALS((int)DevelBlendEquation::SCREEN, equation, TEST_LOCATION);
716     DALI_TEST_EQUALS(DevelRenderer::IsAdvancedBlendEquationApplied(renderer), true, TEST_LOCATION);
717
718     application.SendNotification();
719     application.Render();
720   }
721
722   if(Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::SCREEN) &&
723      Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::MULTIPLY))
724   {
725     renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::ADD);
726     renderer.SetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, true);
727     renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION_RGB, DevelBlendEquation::SCREEN);
728     renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION_ALPHA, DevelBlendEquation::MULTIPLY);
729     int equationRgb   = renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION_RGB);
730     int equationAlpha = renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION_ALPHA);
731
732     DALI_TEST_EQUALS((int)DevelBlendEquation::ADD, equationRgb, TEST_LOCATION);
733     DALI_TEST_EQUALS((int)DevelBlendEquation::ADD, equationAlpha, TEST_LOCATION);
734     DALI_TEST_EQUALS(DevelRenderer::IsAdvancedBlendEquationApplied(renderer), false, TEST_LOCATION);
735
736     application.SendNotification();
737     application.Render();
738   }
739
740   tet_infoline("Error Checking\n");
741   if(Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::MULTIPLY) &&
742      Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::SCREEN) &&
743      Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::OVERLAY) &&
744      Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::DARKEN) &&
745      Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::LIGHTEN) &&
746      Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::COLOR_DODGE) &&
747      Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::COLOR_BURN) &&
748      Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::HARD_LIGHT) &&
749      Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::SOFT_LIGHT) &&
750      Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::DIFFERENCE) &&
751      Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::EXCLUSION) &&
752      Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::HUE) &&
753      Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::SATURATION) &&
754      Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::COLOR) &&
755      Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::LUMINOSITY))
756   {
757     renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::MULTIPLY);
758     DALI_TEST_EQUALS((int)DevelBlendEquation::MULTIPLY, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
759
760     renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::SCREEN);
761     DALI_TEST_EQUALS((int)DevelBlendEquation::SCREEN, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
762
763     renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::OVERLAY);
764     DALI_TEST_EQUALS((int)DevelBlendEquation::OVERLAY, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
765
766     renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::DARKEN);
767     DALI_TEST_EQUALS((int)DevelBlendEquation::DARKEN, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
768
769     renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::LIGHTEN);
770     DALI_TEST_EQUALS((int)DevelBlendEquation::LIGHTEN, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
771
772     renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::COLOR_DODGE);
773     DALI_TEST_EQUALS((int)DevelBlendEquation::COLOR_DODGE, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
774
775     renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::COLOR_BURN);
776     DALI_TEST_EQUALS((int)DevelBlendEquation::COLOR_BURN, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
777
778     renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::HARD_LIGHT);
779     DALI_TEST_EQUALS((int)DevelBlendEquation::HARD_LIGHT, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
780
781     renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::SOFT_LIGHT);
782     DALI_TEST_EQUALS((int)DevelBlendEquation::SOFT_LIGHT, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
783
784     renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::DIFFERENCE);
785     DALI_TEST_EQUALS((int)DevelBlendEquation::DIFFERENCE, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
786
787     renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::EXCLUSION);
788     DALI_TEST_EQUALS((int)DevelBlendEquation::EXCLUSION, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
789
790     renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::HUE);
791     DALI_TEST_EQUALS((int)DevelBlendEquation::HUE, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
792
793     renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::SATURATION);
794     DALI_TEST_EQUALS((int)DevelBlendEquation::SATURATION, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
795
796     renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::COLOR);
797     DALI_TEST_EQUALS((int)DevelBlendEquation::COLOR, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
798
799     renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::LUMINOSITY);
800     DALI_TEST_EQUALS((int)DevelBlendEquation::LUMINOSITY, renderer.GetProperty<int>(DevelRenderer::Property::BLEND_EQUATION), TEST_LOCATION);
801   }
802
803   END_TEST;
804 }
805
806 int UtcDaliRendererSetBlendMode01(void)
807 {
808   TestApplication application;
809
810   tet_infoline("Test setting the blend mode to on with an opaque color renders with blending enabled");
811
812   Geometry geometry = CreateQuadGeometry();
813   Shader   shader   = CreateShader();
814   Renderer renderer = Renderer::New(geometry, shader);
815
816   Actor actor = Actor::New();
817   actor.SetProperty(Actor::Property::OPACITY, 1.0f);
818   actor.AddRenderer(renderer);
819   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
820   application.GetScene().Add(actor);
821
822   renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON);
823
824   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
825   glAbstraction.EnableEnableDisableCallTrace(true);
826
827   application.SendNotification();
828   application.Render();
829
830   TraceCallStack&             glEnableStack = glAbstraction.GetEnableDisableTrace();
831   TraceCallStack::NamedParams params;
832   params["cap"] << std::hex << GL_BLEND;
833   DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", params));
834
835   END_TEST;
836 }
837
838 int UtcDaliRendererSetBlendMode01b(void)
839 {
840   TestApplication application;
841
842   tet_infoline("Test setting the blend mode to on with an transparent color renders with blending enabled");
843
844   Geometry geometry = CreateQuadGeometry();
845   Shader   shader   = CreateShader();
846   Renderer renderer = Renderer::New(geometry, shader);
847
848   Actor actor = Actor::New();
849   actor.SetProperty(Actor::Property::OPACITY, 0.0f);
850   actor.AddRenderer(renderer);
851   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
852   application.GetScene().Add(actor);
853
854   renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON);
855
856   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
857   glAbstraction.EnableEnableDisableCallTrace(true);
858   glAbstraction.EnableDrawCallTrace(true);
859
860   application.SendNotification();
861   application.Render();
862
863   TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
864   DALI_TEST_CHECK(!glEnableStack.FindMethod("Enable"));
865
866   DALI_TEST_CHECK(!glAbstraction.GetDrawTrace().FindMethod("DrawElements"));
867
868   END_TEST;
869 }
870
871 int UtcDaliRendererSetBlendMode02(void)
872 {
873   TestApplication application;
874
875   tet_infoline("Test setting the blend mode to off with a transparent color renders with blending disabled (and not enabled)");
876
877   Geometry geometry = CreateQuadGeometry();
878   Shader   shader   = CreateShader();
879   Renderer renderer = Renderer::New(geometry, shader);
880
881   Actor actor = Actor::New();
882   actor.SetProperty(Actor::Property::OPACITY, 0.15f);
883   actor.AddRenderer(renderer);
884   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
885   application.GetScene().Add(actor);
886
887   renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::OFF);
888
889   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
890   glAbstraction.EnableEnableDisableCallTrace(true);
891
892   application.SendNotification();
893   application.Render();
894
895   TraceCallStack&             glEnableStack = glAbstraction.GetEnableDisableTrace();
896   TraceCallStack::NamedParams params;
897   params["cap"] << std::hex << GL_BLEND;
898   DALI_TEST_CHECK(!glEnableStack.FindMethodAndParams("Enable", params));
899
900   END_TEST;
901 }
902
903 int UtcDaliRendererSetBlendMode03(void)
904 {
905   TestApplication application;
906
907   tet_infoline("Test setting the blend mode to auto with a transparent color renders with blending enabled");
908
909   Geometry geometry = CreateQuadGeometry();
910   Shader   shader   = CreateShader();
911   Renderer renderer = Renderer::New(geometry, shader);
912
913   Actor actor = Actor::New();
914   actor.SetProperty(Actor::Property::OPACITY, 0.75f);
915   actor.AddRenderer(renderer);
916   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
917   application.GetScene().Add(actor);
918
919   renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::AUTO);
920
921   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
922   glAbstraction.EnableEnableDisableCallTrace(true);
923
924   application.SendNotification();
925   application.Render();
926
927   TraceCallStack&             glEnableStack = glAbstraction.GetEnableDisableTrace();
928   TraceCallStack::NamedParams params;
929   params["cap"] << std::hex << GL_BLEND;
930   DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", params));
931
932   END_TEST;
933 }
934
935 int UtcDaliRendererSetBlendMode04(void)
936 {
937   TestApplication application;
938
939   tet_infoline("Test setting the blend mode to auto with an opaque color renders with blending disabled");
940
941   Geometry geometry = CreateQuadGeometry();
942   Shader   shader   = CreateShader();
943   Renderer renderer = Renderer::New(geometry, shader);
944
945   Actor actor = Actor::New();
946   actor.AddRenderer(renderer);
947   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
948   application.GetScene().Add(actor);
949
950   renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::AUTO);
951
952   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
953   glAbstraction.EnableEnableDisableCallTrace(true);
954
955   application.SendNotification();
956   application.Render();
957
958   TraceCallStack&             glEnableStack = glAbstraction.GetEnableDisableTrace();
959   TraceCallStack::NamedParams params;
960   params["cap"] << std::hex << GL_BLEND;
961   DALI_TEST_CHECK(!glEnableStack.FindMethodAndParams("Enable", params));
962   DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Disable", params));
963
964   END_TEST;
965 }
966
967 int UtcDaliRendererSetBlendMode04b(void)
968 {
969   TestApplication application;
970
971   tet_infoline("Test setting the blend mode to auto with a transparent actor color renders with blending enabled");
972
973   Geometry geometry = CreateQuadGeometry();
974   Shader   shader   = CreateShader();
975   Renderer renderer = Renderer::New(geometry, shader);
976
977   Actor actor = Actor::New();
978   actor.AddRenderer(renderer);
979   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
980   actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 0.5f));
981   application.GetScene().Add(actor);
982
983   renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::AUTO);
984
985   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
986   glAbstraction.EnableEnableDisableCallTrace(true);
987
988   application.SendNotification();
989   application.Render();
990
991   TraceCallStack&             glEnableStack = glAbstraction.GetEnableDisableTrace();
992   TraceCallStack::NamedParams params;
993   params["cap"] << std::hex << GL_BLEND;
994   DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", params));
995
996   END_TEST;
997 }
998
999 int UtcDaliRendererSetBlendMode04c(void)
1000 {
1001   TestApplication application;
1002
1003   tet_infoline("Test setting the blend mode to auto with an opaque opaque actor color renders with blending disabled");
1004
1005   Geometry geometry = CreateQuadGeometry();
1006   Shader   shader   = CreateShader();
1007   Renderer renderer = Renderer::New(geometry, shader);
1008
1009   Actor actor = Actor::New();
1010   actor.AddRenderer(renderer);
1011   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1012   actor.SetProperty(Actor::Property::COLOR, Color::MAGENTA);
1013   application.GetScene().Add(actor);
1014
1015   renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::AUTO);
1016
1017   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1018   glAbstraction.EnableEnableDisableCallTrace(true);
1019
1020   application.SendNotification();
1021   application.Render();
1022
1023   TraceCallStack&             glEnableStack = glAbstraction.GetEnableDisableTrace();
1024   TraceCallStack::NamedParams params;
1025   params["cap"] << std::hex << GL_BLEND;
1026   DALI_TEST_CHECK(!glEnableStack.FindMethodAndParams("Enable", params));
1027   DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Disable", params));
1028
1029   END_TEST;
1030 }
1031
1032 int UtcDaliRendererSetBlendMode05(void)
1033 {
1034   TestApplication application;
1035
1036   tet_infoline("Test setting the blend mode to auto with an opaque color and an image with an alpha channel renders with blending enabled");
1037
1038   Geometry geometry = CreateQuadGeometry();
1039   Texture  image    = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 40, 40);
1040
1041   Shader     shader     = CreateShader();
1042   TextureSet textureSet = CreateTextureSet(image);
1043   Renderer   renderer   = Renderer::New(geometry, shader);
1044   renderer.SetTextures(textureSet);
1045
1046   Actor actor = Actor::New();
1047   actor.AddRenderer(renderer);
1048   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1049   application.GetScene().Add(actor);
1050
1051   renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::AUTO);
1052
1053   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1054   glAbstraction.EnableEnableDisableCallTrace(true);
1055
1056   application.SendNotification();
1057   application.Render();
1058
1059   TraceCallStack&             glEnableStack = glAbstraction.GetEnableDisableTrace();
1060   TraceCallStack::NamedParams params;
1061   params["cap"] << std::hex << GL_BLEND;
1062   DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", params));
1063
1064   END_TEST;
1065 }
1066
1067 int UtcDaliRendererSetBlendMode06(void)
1068 {
1069   TestApplication application;
1070   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");
1071
1072   Geometry geometry = CreateQuadGeometry();
1073   Shader   shader   = Shader::New("vertexSrc", "fragmentSrc", Shader::Hint::OUTPUT_IS_TRANSPARENT);
1074
1075   Renderer renderer = Renderer::New(geometry, shader);
1076
1077   Actor actor = Actor::New();
1078   actor.AddRenderer(renderer);
1079   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1080   application.GetScene().Add(actor);
1081
1082   renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::AUTO);
1083
1084   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1085   glAbstraction.EnableEnableDisableCallTrace(true);
1086
1087   application.SendNotification();
1088   application.Render();
1089
1090   TraceCallStack&             glEnableStack = glAbstraction.GetEnableDisableTrace();
1091   TraceCallStack::NamedParams params;
1092   params["cap"] << std::hex << GL_BLEND;
1093   DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", params));
1094
1095   END_TEST;
1096 }
1097
1098 int UtcDaliRendererSetBlendMode07(void)
1099 {
1100   TestApplication application;
1101   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");
1102
1103   Geometry geometry = CreateQuadGeometry();
1104   Shader   shader   = Shader::New("vertexSrc", "fragmentSrc");
1105
1106   Texture    image      = Texture::New(TextureType::TEXTURE_2D, Pixel::RGB888, 50, 50);
1107   TextureSet textureSet = CreateTextureSet(image);
1108   Renderer   renderer   = Renderer::New(geometry, shader);
1109   renderer.SetTextures(textureSet);
1110
1111   Actor actor = Actor::New();
1112   actor.AddRenderer(renderer);
1113   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1114   application.GetScene().Add(actor);
1115
1116   renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::AUTO);
1117
1118   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1119   glAbstraction.EnableEnableDisableCallTrace(true);
1120
1121   application.SendNotification();
1122   application.Render();
1123
1124   TraceCallStack&             glEnableStack = glAbstraction.GetEnableDisableTrace();
1125   TraceCallStack::NamedParams params;
1126   params["cap"] << std::hex << GL_BLEND;
1127   DALI_TEST_CHECK(!glEnableStack.FindMethodAndParams("Enable", params));
1128
1129   END_TEST;
1130 }
1131
1132 int UtcDaliRendererSetBlendMode08(void)
1133 {
1134   TestApplication application;
1135
1136   tet_infoline("Test setting the blend mode to auto with opaque color and Advanced Blend Equation.");
1137
1138   if(Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::SCREEN))
1139   {
1140     Geometry geometry = CreateQuadGeometry();
1141     Shader   shader   = CreateShader();
1142     Renderer renderer = Renderer::New(geometry, shader);
1143
1144     Actor actor = Actor::New();
1145     actor.SetProperty(Actor::Property::OPACITY, 1.0f);
1146     actor.AddRenderer(renderer);
1147     actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1148     application.GetScene().Add(actor);
1149
1150     renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::AUTO);
1151     renderer.SetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, true);
1152     renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::SCREEN);
1153
1154     TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1155     glAbstraction.EnableEnableDisableCallTrace(true);
1156
1157     application.SendNotification();
1158     application.Render();
1159
1160     TraceCallStack&             glEnableStack = glAbstraction.GetEnableDisableTrace();
1161     TraceCallStack::NamedParams params;
1162     params["cap"] << std::hex << GL_BLEND;
1163     DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", params));
1164   }
1165
1166   END_TEST;
1167 }
1168
1169 int UtcDaliRendererSetBlendMode08b(void)
1170 {
1171   TestApplication application;
1172
1173   tet_infoline("Test setting the blend mode to off with opaque color and Advanced Blend Equation.");
1174
1175   if(Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::SCREEN))
1176   {
1177     Geometry geometry = CreateQuadGeometry();
1178     Shader   shader   = CreateShader();
1179     Renderer renderer = Renderer::New(geometry, shader);
1180
1181     Actor actor = Actor::New();
1182     actor.SetProperty(Actor::Property::OPACITY, 1.0f);
1183     actor.AddRenderer(renderer);
1184     actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1185     application.GetScene().Add(actor);
1186
1187     renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::OFF);
1188     renderer.SetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, true);
1189     renderer.SetProperty(DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::SCREEN);
1190
1191     TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1192     glAbstraction.EnableEnableDisableCallTrace(true);
1193
1194     application.SendNotification();
1195     application.Render();
1196
1197     TraceCallStack&             glEnableStack = glAbstraction.GetEnableDisableTrace();
1198     TraceCallStack::NamedParams params;
1199     params["cap"] << std::hex << GL_BLEND;
1200     DALI_TEST_CHECK(!glEnableStack.FindMethodAndParams("Enable", params));
1201   }
1202
1203   END_TEST;
1204 }
1205
1206 int UtcDaliRendererSetBlendMode09(void)
1207 {
1208   TestApplication application;
1209
1210   tet_infoline("Test setting the blend mode to on_without_cull with an opaque color renders with blending enabled");
1211
1212   Geometry geometry = CreateQuadGeometry();
1213   Shader   shader   = CreateShader();
1214   Renderer renderer = Renderer::New(geometry, shader);
1215
1216   Actor actor = Actor::New();
1217   actor.SetProperty(Actor::Property::OPACITY, 1.0f);
1218   actor.AddRenderer(renderer);
1219   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1220   application.GetScene().Add(actor);
1221
1222   renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON_WITHOUT_CULL);
1223
1224   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1225   glAbstraction.EnableEnableDisableCallTrace(true);
1226
1227   application.SendNotification();
1228   application.Render();
1229
1230   TraceCallStack&             glEnableStack = glAbstraction.GetEnableDisableTrace();
1231   TraceCallStack::NamedParams params;
1232   params["cap"] << std::hex << GL_BLEND;
1233   DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", params));
1234
1235   END_TEST;
1236 }
1237
1238 int UtcDaliRendererSetBlendMode09b(void)
1239 {
1240   TestApplication application;
1241
1242   tet_infoline("Test setting the blend mode to on_without_cull with an transparent color renders with blending enabled");
1243
1244   Geometry geometry = CreateQuadGeometry();
1245   Shader   shader   = CreateShader();
1246   Renderer renderer = Renderer::New(geometry, shader);
1247
1248   Actor actor = Actor::New();
1249   actor.SetProperty(Actor::Property::OPACITY, 0.0f);
1250   actor.AddRenderer(renderer);
1251   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1252   application.GetScene().Add(actor);
1253
1254   renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON_WITHOUT_CULL);
1255
1256   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1257   glAbstraction.EnableEnableDisableCallTrace(true);
1258   glAbstraction.EnableDrawCallTrace(true);
1259
1260   application.SendNotification();
1261   application.Render();
1262
1263   TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
1264   DALI_TEST_CHECK(glEnableStack.FindMethod("Enable"));
1265
1266   DALI_TEST_CHECK(glAbstraction.GetDrawTrace().FindMethod("DrawElements"));
1267
1268   END_TEST;
1269 }
1270
1271 int UtcDaliRendererGetBlendMode(void)
1272 {
1273   TestApplication application;
1274
1275   tet_infoline("Test GetBlendMode()");
1276
1277   Geometry geometry = CreateQuadGeometry();
1278   Shader   shader   = Shader::New("vertexSrc", "fragmentSrc");
1279   Renderer renderer = Renderer::New(geometry, shader);
1280
1281   // default value
1282   unsigned int mode = renderer.GetProperty<int>(Renderer::Property::BLEND_MODE);
1283   DALI_TEST_EQUALS(static_cast<BlendMode::Type>(mode), BlendMode::AUTO, TEST_LOCATION);
1284
1285   // ON
1286   renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON);
1287   mode = renderer.GetProperty<int>(Renderer::Property::BLEND_MODE);
1288   DALI_TEST_EQUALS(static_cast<BlendMode::Type>(mode), BlendMode::ON, TEST_LOCATION);
1289
1290   // OFF
1291   renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::OFF);
1292   mode = renderer.GetProperty<int>(Renderer::Property::BLEND_MODE);
1293   DALI_TEST_EQUALS(static_cast<BlendMode::Type>(mode), BlendMode::OFF, TEST_LOCATION);
1294
1295   // ON_WITHOUT_CULL
1296   renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON_WITHOUT_CULL);
1297   mode = renderer.GetProperty<int>(Renderer::Property::BLEND_MODE);
1298   DALI_TEST_EQUALS(static_cast<BlendMode::Type>(mode), BlendMode::ON_WITHOUT_CULL, TEST_LOCATION);
1299
1300   END_TEST;
1301 }
1302
1303 int UtcDaliRendererSetBlendColor(void)
1304 {
1305   TestApplication application;
1306
1307   tet_infoline("Test SetBlendColor(color)");
1308
1309   Geometry   geometry   = CreateQuadGeometry();
1310   Shader     shader     = Shader::New("vertexSrc", "fragmentSrc");
1311   TextureSet textureSet = TextureSet::New();
1312   Texture    image      = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 50, 50);
1313   textureSet.SetTexture(0u, image);
1314   Renderer renderer = Renderer::New(geometry, shader);
1315   renderer.SetTextures(textureSet);
1316
1317   Actor actor = Actor::New();
1318   actor.AddRenderer(renderer);
1319   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1320   application.GetScene().Add(actor);
1321
1322   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1323
1324   renderer.SetProperty(Renderer::Property::BLEND_COLOR, Color::TRANSPARENT);
1325
1326   application.SendNotification();
1327   application.Render();
1328
1329   DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::TRANSPARENT, TEST_LOCATION);
1330   DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::TRANSPARENT, TEST_LOCATION);
1331   DALI_TEST_EQUALS(glAbstraction.GetLastBlendColor(), Color::TRANSPARENT, TEST_LOCATION);
1332
1333   renderer.SetProperty(Renderer::Property::BLEND_COLOR, Color::MAGENTA);
1334
1335   DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::MAGENTA, TEST_LOCATION);
1336   DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::TRANSPARENT, TEST_LOCATION);
1337
1338   application.SendNotification();
1339   application.Render();
1340
1341   DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::MAGENTA, TEST_LOCATION);
1342   DALI_TEST_EQUALS(glAbstraction.GetLastBlendColor(), Color::MAGENTA, TEST_LOCATION);
1343
1344   Vector4 color(0.1f, 0.2f, 0.3f, 0.4f);
1345   renderer.SetProperty(Renderer::Property::BLEND_COLOR, color);
1346   application.SendNotification();
1347   application.Render();
1348   DALI_TEST_EQUALS(glAbstraction.GetLastBlendColor(), color, TEST_LOCATION);
1349
1350   END_TEST;
1351 }
1352
1353 int UtcDaliRendererGetBlendColor(void)
1354 {
1355   TestApplication application;
1356
1357   tet_infoline("Test GetBlendColor()");
1358
1359   Geometry geometry = CreateQuadGeometry();
1360   Shader   shader   = Shader::New("vertexSrc", "fragmentSrc");
1361   Renderer renderer = Renderer::New(geometry, shader);
1362
1363   DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::TRANSPARENT, TEST_LOCATION);
1364
1365   renderer.SetProperty(Renderer::Property::BLEND_COLOR, Color::MAGENTA);
1366   application.SendNotification();
1367   application.Render();
1368   DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::MAGENTA, TEST_LOCATION);
1369
1370   Vector4 color(0.1f, 0.2f, 0.3f, 0.4f);
1371   renderer.SetProperty(Renderer::Property::BLEND_COLOR, color);
1372   application.SendNotification();
1373   application.Render();
1374   DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), color, TEST_LOCATION);
1375
1376   END_TEST;
1377 }
1378
1379 int UtcDaliRendererPreMultipledAlpha(void)
1380 {
1381   TestApplication application;
1382
1383   tet_infoline("Test BLEND_PRE_MULTIPLIED_ALPHA property");
1384
1385   Geometry geometry = CreateQuadGeometry();
1386   Shader   shader   = Shader::New("vertexSrc", "fragmentSrc");
1387   Renderer renderer = Renderer::New(geometry, shader);
1388
1389   Actor actor = Actor::New();
1390   actor.AddRenderer(renderer);
1391   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1392   actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 0.5f));
1393   application.GetScene().Add(actor);
1394
1395   Property::Value value = renderer.GetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
1396   bool            preMultipliedAlpha;
1397   DALI_TEST_CHECK(value.Get(preMultipliedAlpha));
1398   DALI_TEST_CHECK(!preMultipliedAlpha);
1399
1400   int srcFactorRgb    = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
1401   int destFactorRgb   = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
1402   int srcFactorAlpha  = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
1403   int destFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
1404
1405   DALI_TEST_EQUALS((int)DEFAULT_BLEND_FACTOR_SRC_RGB, srcFactorRgb, TEST_LOCATION);
1406   DALI_TEST_EQUALS((int)DEFAULT_BLEND_FACTOR_DEST_RGB, destFactorRgb, TEST_LOCATION);
1407   DALI_TEST_EQUALS((int)DEFAULT_BLEND_FACTOR_SRC_ALPHA, srcFactorAlpha, TEST_LOCATION);
1408   DALI_TEST_EQUALS((int)DEFAULT_BLEND_FACTOR_DEST_ALPHA, destFactorAlpha, TEST_LOCATION);
1409
1410   application.SendNotification();
1411   application.Render();
1412
1413   Vector4            actualValue(Vector4::ZERO);
1414   TestGlAbstraction& gl = application.GetGlAbstraction();
1415   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uColor", actualValue));
1416   DALI_TEST_EQUALS(actualValue, Vector4(1.0f, 0.0f, 1.0f, 0.5f), TEST_LOCATION);
1417
1418   // Enable pre-multiplied alpha
1419   renderer.SetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, true);
1420
1421   application.SendNotification();
1422   application.Render();
1423
1424   value = renderer.GetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
1425   DALI_TEST_CHECK(value.Get(preMultipliedAlpha));
1426   DALI_TEST_CHECK(preMultipliedAlpha);
1427
1428   value = renderer.GetCurrentProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
1429   DALI_TEST_CHECK(value.Get(preMultipliedAlpha));
1430   DALI_TEST_CHECK(preMultipliedAlpha);
1431
1432   srcFactorRgb    = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
1433   destFactorRgb   = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
1434   srcFactorAlpha  = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
1435   destFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
1436
1437   DALI_TEST_EQUALS((int)BlendFactor::ONE, srcFactorRgb, TEST_LOCATION);
1438   DALI_TEST_EQUALS((int)BlendFactor::ONE_MINUS_SRC_ALPHA, destFactorRgb, TEST_LOCATION);
1439   DALI_TEST_EQUALS((int)BlendFactor::ONE, srcFactorAlpha, TEST_LOCATION);
1440   DALI_TEST_EQUALS((int)BlendFactor::ONE_MINUS_SRC_ALPHA, destFactorAlpha, TEST_LOCATION);
1441
1442   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uColor", actualValue));
1443   DALI_TEST_EQUALS(actualValue, Vector4(0.5f, 0.0f, 0.5f, 0.5f), TEST_LOCATION);
1444
1445   // Disable pre-multiplied alpha again
1446   renderer.SetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, false);
1447
1448   application.SendNotification();
1449   application.Render();
1450
1451   value = renderer.GetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
1452   DALI_TEST_CHECK(value.Get(preMultipliedAlpha));
1453   DALI_TEST_CHECK(!preMultipliedAlpha);
1454
1455   value = renderer.GetCurrentProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
1456   DALI_TEST_CHECK(value.Get(preMultipliedAlpha));
1457   DALI_TEST_CHECK(!preMultipliedAlpha);
1458
1459   srcFactorRgb    = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
1460   destFactorRgb   = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
1461   srcFactorAlpha  = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
1462   destFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
1463
1464   DALI_TEST_EQUALS((int)BlendFactor::SRC_ALPHA, srcFactorRgb, TEST_LOCATION);
1465   DALI_TEST_EQUALS((int)BlendFactor::ONE_MINUS_SRC_ALPHA, destFactorRgb, TEST_LOCATION);
1466   DALI_TEST_EQUALS((int)BlendFactor::ONE, srcFactorAlpha, TEST_LOCATION);
1467   DALI_TEST_EQUALS((int)BlendFactor::ONE_MINUS_SRC_ALPHA, destFactorAlpha, TEST_LOCATION);
1468
1469   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uColor", actualValue));
1470   DALI_TEST_EQUALS(actualValue, Vector4(1.0f, 0.0f, 1.0f, 0.5f), TEST_LOCATION);
1471
1472   END_TEST;
1473 }
1474
1475 int UtcDaliRendererConstraint01(void)
1476 {
1477   TestApplication application;
1478
1479   tet_infoline("Test that a non-uniform renderer property can be constrained");
1480
1481   Shader   shader   = Shader::New("VertexSource", "FragmentSource");
1482   Geometry geometry = CreateQuadGeometry();
1483   Renderer renderer = Renderer::New(geometry, shader);
1484
1485   Actor actor = Actor::New();
1486   actor.AddRenderer(renderer);
1487   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1488   application.GetScene().Add(actor);
1489
1490   Vector4         initialColor = Color::WHITE;
1491   Property::Index colorIndex   = renderer.RegisterProperty("uFadeColor", initialColor);
1492
1493   application.SendNotification();
1494   application.Render(0);
1495   DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION);
1496
1497   // Apply constraint
1498   Constraint constraint = Constraint::New<Vector4>(renderer, colorIndex, TestConstraintNoBlue);
1499   constraint.Apply();
1500   application.SendNotification();
1501   application.Render(0);
1502
1503   // Expect no blue component in either buffer - yellow
1504   DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(colorIndex), Color::YELLOW, TEST_LOCATION);
1505   application.Render(0);
1506   DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(colorIndex), Color::YELLOW, TEST_LOCATION);
1507
1508   renderer.RemoveConstraints();
1509   renderer.SetProperty(colorIndex, Color::WHITE);
1510   application.SendNotification();
1511   application.Render(0);
1512   DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(colorIndex), Color::WHITE, TEST_LOCATION);
1513
1514   END_TEST;
1515 }
1516
1517 int UtcDaliRendererConstraint02(void)
1518 {
1519   TestApplication application;
1520
1521   tet_infoline("Test that a uniform map renderer property can be constrained");
1522
1523   Shader   shader   = Shader::New("VertexSource", "FragmentSource");
1524   Geometry geometry = CreateQuadGeometry();
1525   Renderer renderer = Renderer::New(geometry, shader);
1526
1527   Actor actor = Actor::New();
1528   actor.AddRenderer(renderer);
1529   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1530   application.GetScene().Add(actor);
1531   application.SendNotification();
1532   application.Render(0);
1533
1534   Vector4         initialColor = Color::WHITE;
1535   Property::Index colorIndex   = renderer.RegisterProperty("uFadeColor", initialColor);
1536
1537   TestGlAbstraction& gl = application.GetGlAbstraction();
1538
1539   application.SendNotification();
1540   application.Render(0);
1541
1542   Vector4 actualValue(Vector4::ZERO);
1543   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1544   DALI_TEST_EQUALS(actualValue, initialColor, TEST_LOCATION);
1545
1546   // Apply constraint
1547   Constraint constraint = Constraint::New<Vector4>(renderer, colorIndex, TestConstraintNoBlue);
1548   constraint.Apply();
1549   application.SendNotification();
1550   application.Render(0);
1551
1552   // Expect no blue component in either buffer - yellow
1553   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1554   DALI_TEST_EQUALS(actualValue, Color::YELLOW, TEST_LOCATION);
1555
1556   application.Render(0);
1557   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1558   DALI_TEST_EQUALS(actualValue, Color::YELLOW, TEST_LOCATION);
1559
1560   renderer.RemoveConstraints();
1561   renderer.SetProperty(colorIndex, Color::WHITE);
1562   application.SendNotification();
1563   application.Render(0);
1564
1565   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1566   DALI_TEST_EQUALS(actualValue, Color::WHITE, TEST_LOCATION);
1567
1568   END_TEST;
1569 }
1570
1571 int UtcDaliRendererAnimatedProperty01(void)
1572 {
1573   TestApplication application;
1574
1575   tet_infoline("Test that a non-uniform renderer property can be animated");
1576
1577   Shader   shader   = Shader::New("VertexSource", "FragmentSource");
1578   Geometry geometry = CreateQuadGeometry();
1579   Renderer renderer = Renderer::New(geometry, shader);
1580
1581   Actor actor = Actor::New();
1582   actor.AddRenderer(renderer);
1583   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1584   application.GetScene().Add(actor);
1585
1586   Vector4         initialColor = Color::WHITE;
1587   Property::Index colorIndex   = renderer.RegisterProperty("uFadeColor", initialColor);
1588
1589   application.SendNotification();
1590   application.Render(0);
1591   DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION);
1592
1593   Animation animation = Animation::New(1.0f);
1594   KeyFrames keyFrames = KeyFrames::New();
1595   keyFrames.Add(0.0f, initialColor);
1596   keyFrames.Add(1.0f, Color::TRANSPARENT);
1597   animation.AnimateBetween(Property(renderer, colorIndex), keyFrames);
1598   animation.Play();
1599
1600   application.SendNotification();
1601   application.Render(500);
1602
1603   DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(colorIndex), Color::WHITE * 0.5f, TEST_LOCATION);
1604
1605   application.Render(500);
1606
1607   DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(colorIndex), Color::TRANSPARENT, TEST_LOCATION);
1608
1609   END_TEST;
1610 }
1611
1612 int UtcDaliRendererAnimatedProperty02(void)
1613 {
1614   TestApplication application;
1615
1616   tet_infoline("Test that a uniform map renderer property can be animated");
1617
1618   Shader   shader   = Shader::New("VertexSource", "FragmentSource");
1619   Geometry geometry = CreateQuadGeometry();
1620   Renderer renderer = Renderer::New(geometry, shader);
1621
1622   Actor actor = Actor::New();
1623   actor.AddRenderer(renderer);
1624   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1625   application.GetScene().Add(actor);
1626   application.SendNotification();
1627   application.Render(0);
1628
1629   Vector4         initialColor = Color::WHITE;
1630   Property::Index colorIndex   = renderer.RegisterProperty("uFadeColor", initialColor);
1631
1632   TestGlAbstraction& gl = application.GetGlAbstraction();
1633
1634   application.SendNotification();
1635   application.Render(0);
1636
1637   Vector4 actualValue(Vector4::ZERO);
1638   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1639   DALI_TEST_EQUALS(actualValue, initialColor, TEST_LOCATION);
1640
1641   Animation animation = Animation::New(1.0f);
1642   KeyFrames keyFrames = KeyFrames::New();
1643   keyFrames.Add(0.0f, initialColor);
1644   keyFrames.Add(1.0f, Color::TRANSPARENT);
1645   animation.AnimateBetween(Property(renderer, colorIndex), keyFrames);
1646   animation.Play();
1647
1648   application.SendNotification();
1649   application.Render(500);
1650
1651   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1652   DALI_TEST_EQUALS(actualValue, Color::WHITE * 0.5f, TEST_LOCATION);
1653
1654   application.Render(500);
1655   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1656   DALI_TEST_EQUALS(actualValue, Color::TRANSPARENT, TEST_LOCATION);
1657
1658   END_TEST;
1659 }
1660
1661 int UtcDaliRendererUniformMapPrecendence01(void)
1662 {
1663   TestApplication application;
1664
1665   tet_infoline("Test the uniform map precedence is applied properly");
1666
1667   Texture image = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64);
1668
1669   Shader     shader     = Shader::New("VertexSource", "FragmentSource");
1670   TextureSet textureSet = CreateTextureSet(image);
1671
1672   Geometry geometry = CreateQuadGeometry();
1673   Renderer renderer = Renderer::New(geometry, shader);
1674   renderer.SetTextures(textureSet);
1675
1676   Actor actor = Actor::New();
1677   actor.AddRenderer(renderer);
1678   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1679   application.GetScene().Add(actor);
1680   application.SendNotification();
1681   application.Render(0);
1682
1683   renderer.RegisterProperty("uFadeColor", Color::RED);
1684   actor.RegisterProperty("uFadeColor", Color::GREEN);
1685   Property::Index shaderFadeColorIndex = shader.RegisterProperty("uFadeColor", Color::MAGENTA);
1686
1687   TestGlAbstraction& gl = application.GetGlAbstraction();
1688
1689   application.SendNotification();
1690   application.Render(0);
1691
1692   // Expect that the actor's fade color property is accessed
1693   Vector4 actualValue(Vector4::ZERO);
1694   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1695   DALI_TEST_EQUALS(actualValue, Color::GREEN, TEST_LOCATION);
1696
1697   // Animate shader's fade color property. Should be no change to uniform
1698   Animation animation = Animation::New(1.0f);
1699   KeyFrames keyFrames = KeyFrames::New();
1700   keyFrames.Add(0.0f, Color::WHITE);
1701   keyFrames.Add(1.0f, Color::TRANSPARENT);
1702   animation.AnimateBetween(Property(shader, shaderFadeColorIndex), keyFrames);
1703   animation.Play();
1704
1705   application.SendNotification();
1706   application.Render(500);
1707
1708   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1709   DALI_TEST_EQUALS(actualValue, Color::GREEN, TEST_LOCATION);
1710
1711   application.Render(500);
1712   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1713   DALI_TEST_EQUALS(actualValue, Color::GREEN, TEST_LOCATION);
1714
1715   END_TEST;
1716 }
1717
1718 int UtcDaliRendererUniformMapPrecendence02(void)
1719 {
1720   TestApplication application;
1721
1722   tet_infoline("Test the uniform map precedence is applied properly");
1723
1724   Texture image = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64);
1725
1726   Shader     shader     = Shader::New("VertexSource", "FragmentSource");
1727   TextureSet textureSet = CreateTextureSet(image);
1728
1729   Geometry geometry = CreateQuadGeometry();
1730   Renderer renderer = Renderer::New(geometry, shader);
1731   renderer.SetTextures(textureSet);
1732
1733   Actor actor = Actor::New();
1734   actor.AddRenderer(renderer);
1735   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1736   application.GetScene().Add(actor);
1737   application.SendNotification();
1738   application.Render(0);
1739
1740   // Don't add property / uniform map to renderer
1741   actor.RegisterProperty("uFadeColor", Color::GREEN);
1742   Property::Index shaderFadeColorIndex = shader.RegisterProperty("uFadeColor", Color::BLUE);
1743
1744   TestGlAbstraction& gl = application.GetGlAbstraction();
1745
1746   application.SendNotification();
1747   application.Render(0);
1748
1749   // Expect that the actor's fade color property is accessed
1750   Vector4 actualValue(Vector4::ZERO);
1751   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1752   DALI_TEST_EQUALS(actualValue, Color::GREEN, TEST_LOCATION);
1753
1754   // Animate texture set's fade color property. Should be no change to uniform
1755   Animation animation = Animation::New(1.0f);
1756   KeyFrames keyFrames = KeyFrames::New();
1757   keyFrames.Add(0.0f, Color::WHITE);
1758   keyFrames.Add(1.0f, Color::TRANSPARENT);
1759   animation.AnimateBetween(Property(shader, shaderFadeColorIndex), keyFrames);
1760   animation.Play();
1761
1762   application.SendNotification();
1763   application.Render(500);
1764
1765   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1766   DALI_TEST_EQUALS(actualValue, Color::GREEN, TEST_LOCATION);
1767
1768   application.Render(500);
1769   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1770   DALI_TEST_EQUALS(actualValue, Color::GREEN, TEST_LOCATION);
1771
1772   END_TEST;
1773 }
1774
1775 int UtcDaliRendererUniformMapPrecendence03(void)
1776 {
1777   TestApplication application;
1778
1779   tet_infoline("Test the uniform map precedence is applied properly");
1780
1781   Texture image = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64);
1782
1783   Shader     shader     = Shader::New("VertexSource", "FragmentSource");
1784   TextureSet textureSet = CreateTextureSet(image);
1785
1786   Geometry geometry = CreateQuadGeometry();
1787   Renderer renderer = Renderer::New(geometry, shader);
1788   renderer.SetTextures(textureSet);
1789
1790   Actor actor = Actor::New();
1791   actor.AddRenderer(renderer);
1792   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1793   application.GetScene().Add(actor);
1794   application.SendNotification();
1795   application.Render(0);
1796
1797   // Don't add property / uniform map to renderer or actor
1798   shader.RegisterProperty("uFadeColor", Color::BLACK);
1799
1800   TestGlAbstraction& gl = application.GetGlAbstraction();
1801
1802   application.SendNotification();
1803   application.Render(0);
1804
1805   // Expect that the shader's fade color property is accessed
1806   Vector4 actualValue(Vector4::ZERO);
1807   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1808   DALI_TEST_EQUALS(actualValue, Color::BLACK, TEST_LOCATION);
1809
1810   END_TEST;
1811 }
1812
1813 int UtcDaliRendererUniformMapMultipleUniforms01(void)
1814 {
1815   TestApplication application;
1816
1817   tet_infoline("Test the uniform maps are collected from all objects (same type)");
1818
1819   Texture image = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64);
1820
1821   Shader     shader     = Shader::New("VertexSource", "FragmentSource");
1822   TextureSet textureSet = CreateTextureSet(image);
1823
1824   Geometry geometry = CreateQuadGeometry();
1825   Renderer renderer = Renderer::New(geometry, shader);
1826   renderer.SetTextures(textureSet);
1827
1828   Actor actor = Actor::New();
1829   actor.AddRenderer(renderer);
1830   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1831   application.GetScene().Add(actor);
1832   application.SendNotification();
1833   application.Render(0);
1834
1835   renderer.RegisterProperty("uUniform1", Color::RED);
1836   actor.RegisterProperty("uUniform2", Color::GREEN);
1837   shader.RegisterProperty("uUniform3", Color::MAGENTA);
1838
1839   TestGlAbstraction& gl = application.GetGlAbstraction();
1840
1841   application.SendNotification();
1842   application.Render(0);
1843
1844   // Expect that each of the object's uniforms are set
1845   Vector4 uniform1Value(Vector4::ZERO);
1846   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uUniform1", uniform1Value));
1847   DALI_TEST_EQUALS(uniform1Value, Color::RED, TEST_LOCATION);
1848
1849   Vector4 uniform2Value(Vector4::ZERO);
1850   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uUniform2", uniform2Value));
1851   DALI_TEST_EQUALS(uniform2Value, Color::GREEN, TEST_LOCATION);
1852
1853   Vector4 uniform3Value(Vector4::ZERO);
1854   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uUniform3", uniform3Value));
1855   DALI_TEST_EQUALS(uniform3Value, Color::MAGENTA, TEST_LOCATION);
1856
1857   END_TEST;
1858 }
1859
1860 int UtcDaliRendererUniformMapMultipleUniforms02(void)
1861 {
1862   TestApplication application;
1863
1864   tet_infoline("Test the uniform maps are collected from all objects (different types)");
1865
1866   Texture image = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64);
1867
1868   Shader     shader     = Shader::New("VertexSource", "FragmentSource");
1869   TextureSet textureSet = CreateTextureSet(image);
1870
1871   Geometry geometry = CreateQuadGeometry();
1872   Renderer renderer = Renderer::New(geometry, shader);
1873   renderer.SetTextures(textureSet);
1874
1875   Actor actor = Actor::New();
1876   actor.AddRenderer(renderer);
1877   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1878   application.GetScene().Add(actor);
1879   application.SendNotification();
1880   application.Render(0);
1881
1882   Property::Value value1(Color::RED);
1883   renderer.RegisterProperty("uFadeColor", value1);
1884
1885   Property::Value value2(1.0f);
1886   actor.RegisterProperty("uFadeProgress", value2);
1887
1888   Property::Value value3(Matrix3::IDENTITY);
1889   shader.RegisterProperty("uANormalMatrix", value3);
1890
1891   TestGlAbstraction& gl = application.GetGlAbstraction();
1892
1893   application.SendNotification();
1894   application.Render(0);
1895
1896   // Expect that each of the object's uniforms are set
1897   Vector4 uniform1Value(Vector4::ZERO);
1898   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", uniform1Value));
1899   DALI_TEST_EQUALS(uniform1Value, value1.Get<Vector4>(), TEST_LOCATION);
1900
1901   float uniform2Value(0.0f);
1902   DALI_TEST_CHECK(gl.GetUniformValue<float>("uFadeProgress", uniform2Value));
1903   DALI_TEST_EQUALS(uniform2Value, value2.Get<float>(), TEST_LOCATION);
1904
1905   Matrix3 uniform3Value;
1906   DALI_TEST_CHECK(gl.GetUniformValue<Matrix3>("uANormalMatrix", uniform3Value));
1907   DALI_TEST_EQUALS(uniform3Value, value3.Get<Matrix3>(), TEST_LOCATION);
1908
1909   END_TEST;
1910 }
1911
1912 int UtcDaliRendererRenderOrder2DLayer(void)
1913 {
1914   TestApplication application;
1915   tet_infoline("Test the rendering order in a 2D layer is correct");
1916
1917   Shader   shader   = Shader::New("VertexSource", "FragmentSource");
1918   Geometry geometry = CreateQuadGeometry();
1919
1920   Actor root = application.GetScene().GetRootLayer();
1921
1922   Actor    actor0    = CreateActor(root, 0, TEST_LOCATION);
1923   Renderer renderer0 = CreateRenderer(actor0, geometry, shader, 0);
1924
1925   Actor    actor1    = CreateActor(root, 0, TEST_LOCATION);
1926   Renderer renderer1 = CreateRenderer(actor1, geometry, shader, 0);
1927
1928   Actor    actor2    = CreateActor(root, 0, TEST_LOCATION);
1929   Renderer renderer2 = CreateRenderer(actor2, geometry, shader, 0);
1930
1931   Actor    actor3    = CreateActor(root, 0, TEST_LOCATION);
1932   Renderer renderer3 = CreateRenderer(actor3, geometry, shader, 0);
1933
1934   application.SendNotification();
1935   application.Render(0);
1936
1937   /*
1938    * Create the following hierarchy:
1939    *
1940    *            actor2
1941    *              /
1942    *             /
1943    *          actor1
1944    *           /
1945    *          /
1946    *       actor0
1947    *        /
1948    *       /
1949    *    actor3
1950    *
1951    *  Expected rendering order : actor2 - actor1 - actor0 - actor3
1952    */
1953   actor2.Add(actor1);
1954   actor1.Add(actor0);
1955   actor0.Add(actor3);
1956   application.SendNotification();
1957   application.Render(0);
1958
1959   TestGlAbstraction& gl = application.GetGlAbstraction();
1960   gl.GetTextureTrace().Reset();
1961   gl.EnableTextureCallTrace(true);
1962   application.SendNotification();
1963   application.Render(0);
1964
1965   int textureBindIndex[4];
1966   for(unsigned int i(0); i < 4; ++i)
1967   {
1968     std::stringstream params;
1969     params << std::hex << GL_TEXTURE_2D << std::dec << ", " << i + 1;
1970     textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str());
1971   }
1972
1973   //Check that actor1 has been rendered after actor2
1974   DALI_TEST_GREATER(textureBindIndex[1], textureBindIndex[2], TEST_LOCATION);
1975
1976   //Check that actor0 has been rendered after actor1
1977   DALI_TEST_GREATER(textureBindIndex[0], textureBindIndex[1], TEST_LOCATION);
1978
1979   //Check that actor3 has been rendered after actor0
1980   DALI_TEST_GREATER(textureBindIndex[3], textureBindIndex[0], TEST_LOCATION);
1981
1982   END_TEST;
1983 }
1984
1985 int UtcDaliRendererRenderOrder2DLayerMultipleRenderers(void)
1986 {
1987   TestApplication application;
1988   tet_infoline("Test the rendering order in a 2D layer is correct using multiple renderers per actor");
1989
1990   /*
1991    * Creates the following hierarchy:
1992    *
1993    *             actor0------------------------>actor1
1994    *            /   |   \                    /   |   \
1995    *          /     |     \                /     |     \
1996    *        /       |       \            /       |       \
1997    * renderer0 renderer1 renderer2 renderer3 renderer4 renderer5
1998    *
1999    *  renderer0 has depth index 2
2000    *  renderer1 has depth index 0
2001    *  renderer2 has depth index 1
2002    *
2003    *  renderer3 has depth index 1
2004    *  renderer4 has depth index 0
2005    *  renderer5 has depth index -1
2006    *
2007    *  Expected rendering order: renderer1 - renderer2 - renderer0 - renderer5 - renderer4 - renderer3
2008    */
2009
2010   Shader   shader   = Shader::New("VertexSource", "FragmentSource");
2011   Geometry geometry = CreateQuadGeometry();
2012
2013   Actor root = application.GetScene().GetRootLayer();
2014
2015   Actor    actor0    = CreateActor(root, 0, TEST_LOCATION);
2016   Actor    actor1    = CreateActor(actor0, 0, TEST_LOCATION);
2017   Renderer renderer0 = CreateRenderer(actor0, geometry, shader, 2);
2018   Renderer renderer1 = CreateRenderer(actor0, geometry, shader, 0);
2019   Renderer renderer2 = CreateRenderer(actor0, geometry, shader, 1);
2020   Renderer renderer3 = CreateRenderer(actor1, geometry, shader, 1);
2021   Renderer renderer4 = CreateRenderer(actor1, geometry, shader, 0);
2022   Renderer renderer5 = CreateRenderer(actor1, geometry, shader, -1);
2023
2024   application.SendNotification();
2025   application.Render(0);
2026
2027   TestGlAbstraction& gl = application.GetGlAbstraction();
2028   gl.GetTextureTrace().Reset();
2029   gl.EnableTextureCallTrace(true);
2030   application.SendNotification();
2031   application.Render(0);
2032
2033   int textureBindIndex[6];
2034   for(unsigned int i(0); i < 6; ++i)
2035   {
2036     std::stringstream params;
2037     params << std::hex << GL_TEXTURE_2D << std::dec << ", " << i + 1;
2038     textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str());
2039   }
2040
2041   //Check that renderer3 has been rendered after renderer4
2042   DALI_TEST_GREATER(textureBindIndex[3], textureBindIndex[4], TEST_LOCATION);
2043
2044   //Check that renderer0 has been rendered after renderer2
2045   DALI_TEST_GREATER(textureBindIndex[4], textureBindIndex[5], TEST_LOCATION);
2046
2047   //Check that renderer5 has been rendered after renderer2
2048   DALI_TEST_GREATER(textureBindIndex[5], textureBindIndex[0], TEST_LOCATION);
2049
2050   //Check that renderer0 has been rendered after renderer2
2051   DALI_TEST_GREATER(textureBindIndex[0], textureBindIndex[2], TEST_LOCATION);
2052
2053   //Check that renderer2 has been rendered after renderer1
2054   DALI_TEST_GREATER(textureBindIndex[2], textureBindIndex[1], TEST_LOCATION);
2055
2056   END_TEST;
2057 }
2058
2059 int UtcDaliRendererRenderOrder2DLayerSiblingOrder(void)
2060 {
2061   TestApplication application;
2062   tet_infoline("Test the rendering order in a 2D layer is correct using sibling order");
2063
2064   /*
2065    * Creates the following hierarchy:
2066    *
2067    *                            Layer
2068    *                           /    \
2069    *                         /        \
2070    *                       /            \
2071    *                     /                \
2072    *                   /                    \
2073    *             actor0 (SIBLING_ORDER:1)     actor1 (SIBLING_ORDER:0)
2074    *            /   |   \                    /   |   \
2075    *          /     |     \                /     |     \
2076    *        /       |       \            /       |       \
2077    * renderer0 renderer1  actor2     renderer2 renderer3 renderer4
2078    *    DI:2      DI:0      |           DI:0      DI:1      DI:2
2079    *                        |
2080    *                   renderer5
2081    *                      DI:-1
2082    *
2083    *  actor0 has sibling order 1
2084    *  actor1 has sibling order 0
2085    *  actor2 has sibling order 0
2086    *
2087    *  renderer0 has depth index 2
2088    *  renderer1 has depth index 0
2089    *
2090    *  renderer2 has depth index 0
2091    *  renderer3 has depth index 1
2092    *  renderer4 has depth index 2
2093    *
2094    *  renderer5 has depth index -1
2095    *
2096    *  Expected rendering order: renderer2 - renderer3 - renderer4 - renderer1 - renderer0 - renderer5
2097    */
2098
2099   Shader   shader   = Shader::New("VertexSource", "FragmentSource");
2100   Geometry geometry = CreateQuadGeometry();
2101   Actor    root     = application.GetScene().GetRootLayer();
2102   Actor    actor0   = CreateActor(root, 1, TEST_LOCATION);
2103   Actor    actor1   = CreateActor(root, 0, TEST_LOCATION);
2104   Actor    actor2   = CreateActor(actor0, 0, TEST_LOCATION);
2105
2106   Renderer renderer0 = CreateRenderer(actor0, geometry, shader, 2);
2107   Renderer renderer1 = CreateRenderer(actor0, geometry, shader, 0);
2108   Renderer renderer2 = CreateRenderer(actor1, geometry, shader, 0);
2109   Renderer renderer3 = CreateRenderer(actor1, geometry, shader, 1);
2110   Renderer renderer4 = CreateRenderer(actor1, geometry, shader, 2);
2111   Renderer renderer5 = CreateRenderer(actor2, geometry, shader, -1);
2112
2113   application.SendNotification();
2114   application.Render();
2115
2116   TestGlAbstraction& gl = application.GetGlAbstraction();
2117   gl.GetTextureTrace().Reset();
2118   gl.EnableTextureCallTrace(true);
2119   application.SendNotification();
2120   application.Render(0);
2121
2122   int textureBindIndex[6];
2123   for(unsigned int i(0); i < 6; ++i)
2124   {
2125     std::stringstream params;
2126     params << std::hex << GL_TEXTURE_2D << std::dec << ", " << i + 1;
2127     textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str());
2128   }
2129
2130   DALI_TEST_EQUALS(textureBindIndex[2], 0, TEST_LOCATION);
2131   DALI_TEST_EQUALS(textureBindIndex[3], 1, TEST_LOCATION);
2132   DALI_TEST_EQUALS(textureBindIndex[4], 2, TEST_LOCATION);
2133   DALI_TEST_EQUALS(textureBindIndex[1], 3, TEST_LOCATION);
2134   DALI_TEST_EQUALS(textureBindIndex[0], 4, TEST_LOCATION);
2135   DALI_TEST_EQUALS(textureBindIndex[5], 5, TEST_LOCATION);
2136
2137   // Change sibling order of actor1
2138   // New Expected rendering order: renderer1 - renderer0 - renderer 5 - renderer2 - renderer3 - renderer4
2139   actor1.SetProperty(Dali::DevelActor::Property::SIBLING_ORDER, 2);
2140
2141   gl.GetTextureTrace().Reset();
2142   application.SendNotification();
2143   application.Render(0);
2144
2145   for(unsigned int i(0); i < 6; ++i)
2146   {
2147     std::stringstream params;
2148     params << std::hex << GL_TEXTURE_2D << std::dec << ", " << i + 1;
2149     textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str());
2150   }
2151
2152   DALI_TEST_EQUALS(textureBindIndex[1], 0, TEST_LOCATION);
2153   DALI_TEST_EQUALS(textureBindIndex[0], 1, TEST_LOCATION);
2154   DALI_TEST_EQUALS(textureBindIndex[5], 2, TEST_LOCATION);
2155   DALI_TEST_EQUALS(textureBindIndex[2], 3, TEST_LOCATION);
2156   DALI_TEST_EQUALS(textureBindIndex[3], 4, TEST_LOCATION);
2157   DALI_TEST_EQUALS(textureBindIndex[4], 5, TEST_LOCATION);
2158
2159   END_TEST;
2160 }
2161
2162 int UtcDaliRendererRenderOrder2DLayerOverlay(void)
2163 {
2164   TestApplication application;
2165   tet_infoline("Test the rendering order in a 2D layer is correct for overlays");
2166
2167   Shader   shader   = Shader::New("VertexSource", "FragmentSource");
2168   Geometry geometry = CreateQuadGeometry();
2169   Actor    root     = application.GetScene().GetRootLayer();
2170
2171   /*
2172    * Create the following hierarchy:
2173    *
2174    *               actor2
2175    *             (Regular actor)
2176    *              /      \
2177    *             /        \
2178    *         actor1       actor4
2179    *       (Overlay)     (Regular actor)
2180    *          /
2181    *         /
2182    *     actor0
2183    *    (Overlay)
2184    *      /
2185    *     /
2186    *  actor3
2187    * (Overlay)
2188    *
2189    *  Expected rendering order : actor2 - actor4 - actor1 - actor0 - actor3
2190    */
2191
2192   Actor actor0 = CreateActor(root, 0, TEST_LOCATION);
2193   actor0.SetProperty(Actor::Property::DRAW_MODE, DrawMode::OVERLAY_2D);
2194   Renderer renderer0 = CreateRenderer(actor0, geometry, shader, 0);
2195
2196   Actor actor1 = CreateActor(root, 0, TEST_LOCATION);
2197   actor1.SetProperty(Actor::Property::DRAW_MODE, DrawMode::OVERLAY_2D);
2198   Renderer renderer1 = CreateRenderer(actor1, geometry, shader, 0);
2199
2200   Actor    actor2    = CreateActor(root, 0, TEST_LOCATION);
2201   Renderer renderer2 = CreateRenderer(actor2, geometry, shader, 0);
2202
2203   Actor actor3 = CreateActor(root, 0, TEST_LOCATION);
2204   actor3.SetProperty(Actor::Property::DRAW_MODE, DrawMode::OVERLAY_2D);
2205   Renderer renderer3 = CreateRenderer(actor3, geometry, shader, 0);
2206
2207   Actor    actor4    = CreateActor(root, 0, TEST_LOCATION);
2208   Renderer renderer4 = CreateRenderer(actor4, geometry, shader, 0);
2209
2210   application.SendNotification();
2211   application.Render(0);
2212
2213   actor2.Add(actor1);
2214   actor2.Add(actor4);
2215   actor1.Add(actor0);
2216   actor0.Add(actor3);
2217
2218   TestGlAbstraction& gl = application.GetGlAbstraction();
2219   gl.GetTextureTrace().Reset();
2220   gl.EnableTextureCallTrace(true);
2221   application.SendNotification();
2222   application.Render(0);
2223
2224   int textureBindIndex[5];
2225   for(unsigned int i(0); i < 5; ++i)
2226   {
2227     std::stringstream params;
2228     params << std::hex << GL_TEXTURE_2D << std::dec << ", " << i + 1;
2229     textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str());
2230   }
2231
2232   //Check that actor4 has been rendered after actor2
2233   DALI_TEST_GREATER(textureBindIndex[4], textureBindIndex[2], TEST_LOCATION);
2234
2235   //Check that actor1 has been rendered after actor4
2236   DALI_TEST_GREATER(textureBindIndex[1], textureBindIndex[4], TEST_LOCATION);
2237
2238   //Check that actor0 has been rendered after actor1
2239   DALI_TEST_GREATER(textureBindIndex[0], textureBindIndex[1], TEST_LOCATION);
2240
2241   //Check that actor3 has been rendered after actor0
2242   DALI_TEST_GREATER(textureBindIndex[3], textureBindIndex[0], TEST_LOCATION);
2243
2244   END_TEST;
2245 }
2246
2247 int UtcDaliRendererSetIndexRange(void)
2248 {
2249   std::string
2250     vertexShader(
2251       "attribute vec2 aPosition;\n"
2252       "void main()\n"
2253       "{\n"
2254       "  gl_Position = aPosition;\n"
2255       "}"),
2256     fragmentShader(
2257       "void main()\n"
2258       "{\n"
2259       "  gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0)\n"
2260       "}\n");
2261
2262   TestApplication application;
2263   tet_infoline("Test setting the range of indices to draw");
2264
2265   TestGlAbstraction& gl = application.GetGlAbstraction();
2266   gl.EnableDrawCallTrace(true);
2267
2268   Actor actor = Actor::New();
2269   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2270
2271   // create geometry
2272   Geometry geometry = Geometry::New();
2273   geometry.SetType(Geometry::LINE_LOOP);
2274
2275   // --------------------------------------------------------------------------
2276   // index buffer
2277   unsigned short indices[] = {0, 2, 4, 6, 8, // offset = 0, count = 5
2278                               0,
2279                               1,
2280                               2,
2281                               3,
2282                               4,
2283                               5,
2284                               6,
2285                               7,
2286                               8,
2287                               9, // offset = 5, count = 10
2288                               1,
2289                               3,
2290                               5,
2291                               7,
2292                               9,
2293                               1}; // offset = 15,  count = 6 // line strip
2294
2295   // --------------------------------------------------------------------------
2296   // vertex buffer
2297   struct Vertex
2298   {
2299     Vector2 position;
2300   };
2301   Vertex shapes[] =
2302     {
2303       // pentagon                   // star
2304       {Vector2(0.0f, 1.00f)},
2305       {Vector2(0.0f, -1.00f)},
2306       {Vector2(-0.95f, 0.31f)},
2307       {Vector2(0.59f, 0.81f)},
2308       {Vector2(-0.59f, -0.81f)},
2309       {Vector2(-0.95f, -0.31f)},
2310       {Vector2(0.59f, -0.81f)},
2311       {Vector2(0.95f, -0.31f)},
2312       {Vector2(0.95f, 0.31f)},
2313       {Vector2(-0.59f, 0.81f)},
2314     };
2315   Property::Map vertexFormat;
2316   vertexFormat["aPosition"] = Property::VECTOR2;
2317   VertexBuffer vertexBuffer = VertexBuffer::New(vertexFormat);
2318   vertexBuffer.SetData(shapes, sizeof(shapes) / sizeof(shapes[0]));
2319
2320   // --------------------------------------------------------------------------
2321   geometry.SetIndexBuffer(indices, sizeof(indices) / sizeof(indices[0]));
2322   geometry.AddVertexBuffer(vertexBuffer);
2323
2324   // create shader
2325   Shader   shader   = Shader::New(vertexShader, fragmentShader);
2326   Renderer renderer = Renderer::New(geometry, shader);
2327   actor.AddRenderer(renderer);
2328
2329   Integration::Scene scene = application.GetScene();
2330   scene.Add(actor);
2331
2332   char buffer[128];
2333
2334   // LINE_LOOP, first 0, count 5
2335   {
2336     renderer.SetIndexRange(0, 5);
2337     application.SendNotification();
2338     application.Render();
2339
2340     Property::Value value = renderer.GetProperty(Renderer::Property::INDEX_RANGE_FIRST);
2341     int             convertedValue;
2342     DALI_TEST_CHECK(value.Get(convertedValue));
2343     DALI_TEST_CHECK(convertedValue == 0);
2344
2345     value = renderer.GetCurrentProperty(Renderer::Property::INDEX_RANGE_FIRST);
2346     DALI_TEST_CHECK(value.Get(convertedValue));
2347     DALI_TEST_CHECK(convertedValue == 0);
2348
2349     value = renderer.GetProperty(Renderer::Property::INDEX_RANGE_COUNT);
2350     DALI_TEST_CHECK(value.Get(convertedValue));
2351     DALI_TEST_CHECK(convertedValue == 5);
2352
2353     value = renderer.GetCurrentProperty(Renderer::Property::INDEX_RANGE_COUNT);
2354     DALI_TEST_CHECK(value.Get(convertedValue));
2355     DALI_TEST_CHECK(convertedValue == 5);
2356
2357     sprintf(buffer, "%u, 5, %u, indices", GL_LINE_LOOP, GL_UNSIGNED_SHORT);
2358     bool result = gl.GetDrawTrace().FindMethodAndParams("DrawElements", buffer);
2359     DALI_TEST_CHECK(result);
2360   }
2361
2362   // LINE_LOOP, first 5, count 10
2363   {
2364     renderer.SetIndexRange(5, 10);
2365     sprintf(buffer, "%u, 10, %u, indices", GL_LINE_LOOP, GL_UNSIGNED_SHORT);
2366     application.SendNotification();
2367     application.Render();
2368     bool result = gl.GetDrawTrace().FindMethodAndParams("DrawElements", buffer);
2369     DALI_TEST_CHECK(result);
2370   }
2371
2372   // LINE_STRIP, first 15, count 6
2373   {
2374     renderer.SetIndexRange(15, 6);
2375     geometry.SetType(Geometry::LINE_STRIP);
2376     sprintf(buffer, "%u, 6, %u, indices", GL_LINE_STRIP, GL_UNSIGNED_SHORT);
2377     application.SendNotification();
2378     application.Render();
2379     bool result = gl.GetDrawTrace().FindMethodAndParams("DrawElements", buffer);
2380     DALI_TEST_CHECK(result);
2381   }
2382
2383   // Index out of bounds
2384   {
2385     renderer.SetIndexRange(15, 30);
2386     geometry.SetType(Geometry::LINE_STRIP);
2387     sprintf(buffer, "%u, 6, %u, indices", GL_LINE_STRIP, GL_UNSIGNED_SHORT);
2388     application.SendNotification();
2389     application.Render();
2390     bool result = gl.GetDrawTrace().FindMethodAndParams("DrawElements", buffer);
2391     DALI_TEST_CHECK(result);
2392   }
2393
2394   // drawing whole buffer starting from 15 ( last valid primitive )
2395   {
2396     renderer.SetIndexRange(15, 0);
2397     geometry.SetType(Geometry::LINE_STRIP);
2398     sprintf(buffer, "%u, 6, %u, indices", GL_LINE_STRIP, GL_UNSIGNED_SHORT);
2399     application.SendNotification();
2400     application.Render();
2401     bool result = gl.GetDrawTrace().FindMethodAndParams("DrawElements", buffer);
2402     DALI_TEST_CHECK(result);
2403   }
2404
2405   END_TEST;
2406 }
2407
2408 int UtcDaliRendererSetDepthFunction(void)
2409 {
2410   TestApplication application;
2411
2412   tet_infoline("Test setting the depth function");
2413
2414   Geometry geometry = CreateQuadGeometry();
2415   Shader   shader   = CreateShader();
2416   Renderer renderer = Renderer::New(geometry, shader);
2417
2418   Actor actor = Actor::New();
2419   actor.AddRenderer(renderer);
2420   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
2421   Integration::Scene scene = application.GetScene();
2422   scene.GetRootLayer().SetProperty(Layer::Property::BEHAVIOR, Layer::LAYER_3D);
2423   scene.Add(actor);
2424
2425   TestGlAbstraction& glAbstraction        = application.GetGlAbstraction();
2426   TraceCallStack&    glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2427   TraceCallStack&    glDepthFunctionStack = glAbstraction.GetDepthFunctionTrace();
2428
2429   glEnableDisableStack.Enable(true);
2430   glDepthFunctionStack.Enable(true);
2431   glEnableDisableStack.EnableLogging(true);
2432   glDepthFunctionStack.EnableLogging(true);
2433
2434   std::ostringstream depthTestStr;
2435   depthTestStr << std::hex << GL_DEPTH_TEST;
2436
2437   //GL_NEVER
2438   {
2439     renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::NEVER);
2440
2441     glEnableDisableStack.Reset();
2442     glDepthFunctionStack.Reset();
2443     application.SendNotification();
2444     application.Render();
2445
2446     DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Enable", depthTestStr.str().c_str()));
2447     std::ostringstream depthFunctionStr;
2448     depthFunctionStr << std::hex << GL_NEVER;
2449     DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2450   }
2451
2452   //GL_ALWAYS
2453   {
2454     renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::ALWAYS);
2455
2456     glDepthFunctionStack.Reset();
2457     application.SendNotification();
2458     application.Render();
2459
2460     std::ostringstream depthFunctionStr;
2461     depthFunctionStr << std::hex << GL_ALWAYS;
2462     DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2463   }
2464
2465   //GL_LESS
2466   {
2467     renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::LESS);
2468
2469     glDepthFunctionStack.Reset();
2470     application.SendNotification();
2471     application.Render();
2472
2473     std::ostringstream depthFunctionStr;
2474     depthFunctionStr << std::hex << GL_LESS;
2475     DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2476   }
2477
2478   //GL_GREATER
2479   {
2480     renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::GREATER);
2481
2482     glDepthFunctionStack.Reset();
2483     application.SendNotification();
2484     application.Render();
2485
2486     std::ostringstream depthFunctionStr;
2487     depthFunctionStr << std::hex << GL_GREATER;
2488     DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2489   }
2490
2491   //GL_EQUAL
2492   {
2493     renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::EQUAL);
2494
2495     glDepthFunctionStack.Reset();
2496     application.SendNotification();
2497     application.Render();
2498
2499     std::ostringstream depthFunctionStr;
2500     depthFunctionStr << std::hex << GL_EQUAL;
2501     DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2502   }
2503
2504   //GL_NOTEQUAL
2505   {
2506     renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::NOT_EQUAL);
2507
2508     glDepthFunctionStack.Reset();
2509     application.SendNotification();
2510     application.Render();
2511
2512     std::ostringstream depthFunctionStr;
2513     depthFunctionStr << std::hex << GL_NOTEQUAL;
2514     DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2515   }
2516
2517   //GL_LEQUAL
2518   {
2519     renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::LESS_EQUAL);
2520
2521     glDepthFunctionStack.Reset();
2522     application.SendNotification();
2523     application.Render();
2524
2525     std::ostringstream depthFunctionStr;
2526     depthFunctionStr << std::hex << GL_LEQUAL;
2527     DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2528   }
2529
2530   //GL_GEQUAL
2531   {
2532     renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::GREATER_EQUAL);
2533
2534     glDepthFunctionStack.Reset();
2535     application.SendNotification();
2536     application.Render();
2537
2538     std::ostringstream depthFunctionStr;
2539     depthFunctionStr << std::hex << GL_GEQUAL;
2540     DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2541   }
2542
2543   END_TEST;
2544 }
2545
2546 /**
2547  * @brief This templatized function checks an enumeration property is setting and getting correctly.
2548  * The checks performed are as follows:
2549  *  - Check the initial/default value.
2550  *  - Set a different value via enum.
2551  *  - Check it was set.
2552  *  - Set a different value via string.
2553  *  - Check it was set.
2554  */
2555 template<typename T>
2556 void CheckEnumerationProperty(TestApplication& application, Renderer& renderer, Property::Index propertyIndex, T initialValue, T firstCheckEnumeration, T secondCheckEnumeration, std::string secondCheckString)
2557 {
2558   application.SendNotification();
2559   application.Render();
2560
2561   DALI_TEST_CHECK(renderer.GetProperty<int>(propertyIndex) == static_cast<int>(initialValue));
2562   DALI_TEST_CHECK(renderer.GetCurrentProperty<int>(propertyIndex) == static_cast<int>(initialValue));
2563   renderer.SetProperty(propertyIndex, firstCheckEnumeration);
2564   DALI_TEST_CHECK(renderer.GetProperty<int>(propertyIndex) == static_cast<int>(firstCheckEnumeration));
2565   DALI_TEST_CHECK(renderer.GetCurrentProperty<int>(propertyIndex) != static_cast<int>(firstCheckEnumeration));
2566
2567   application.SendNotification();
2568   application.Render();
2569
2570   DALI_TEST_CHECK(renderer.GetProperty<int>(propertyIndex) == static_cast<int>(firstCheckEnumeration));
2571   DALI_TEST_CHECK(renderer.GetCurrentProperty<int>(propertyIndex) == static_cast<int>(firstCheckEnumeration));
2572
2573   renderer.SetProperty(propertyIndex, secondCheckString);
2574   DALI_TEST_CHECK(renderer.GetProperty<int>(propertyIndex) == static_cast<int>(secondCheckEnumeration));
2575   DALI_TEST_CHECK(renderer.GetCurrentProperty<int>(propertyIndex) != static_cast<int>(secondCheckEnumeration));
2576
2577   application.SendNotification();
2578   application.Render();
2579
2580   DALI_TEST_CHECK(renderer.GetProperty<int>(propertyIndex) == static_cast<int>(secondCheckEnumeration));
2581   DALI_TEST_CHECK(renderer.GetCurrentProperty<int>(propertyIndex) == static_cast<int>(secondCheckEnumeration));
2582 }
2583
2584 int UtcDaliRendererEnumProperties(void)
2585 {
2586   TestApplication application;
2587   tet_infoline("Test Renderer enumeration properties can be set with both integer and string values");
2588
2589   Geometry geometry = CreateQuadGeometry();
2590   Shader   shader   = CreateShader();
2591   Renderer renderer = Renderer::New(geometry, shader);
2592
2593   Actor actor = Actor::New();
2594   actor.AddRenderer(renderer);
2595   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
2596   application.GetScene().Add(actor);
2597
2598   /*
2599    * Here we use a templatized function to perform several checks on each enumeration property.
2600    * @see CheckEnumerationProperty for details of the checks performed.
2601    */
2602
2603   CheckEnumerationProperty<FaceCullingMode::Type>(application, renderer, Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::NONE, FaceCullingMode::FRONT, FaceCullingMode::BACK, "BACK");
2604   CheckEnumerationProperty<BlendMode::Type>(application, renderer, Renderer::Property::BLEND_MODE, BlendMode::AUTO, BlendMode::OFF, BlendMode::ON, "ON");
2605   CheckEnumerationProperty<BlendEquation::Type>(application, renderer, Renderer::Property::BLEND_EQUATION_RGB, BlendEquation::ADD, BlendEquation::SUBTRACT, BlendEquation::REVERSE_SUBTRACT, "REVERSE_SUBTRACT");
2606   CheckEnumerationProperty<BlendEquation::Type>(application, renderer, Renderer::Property::BLEND_EQUATION_ALPHA, BlendEquation::ADD, BlendEquation::SUBTRACT, BlendEquation::REVERSE_SUBTRACT, "REVERSE_SUBTRACT");
2607   CheckEnumerationProperty<BlendFactor::Type>(application, renderer, Renderer::Property::BLEND_FACTOR_SRC_RGB, BlendFactor::SRC_ALPHA, BlendFactor::ONE, BlendFactor::SRC_COLOR, "SRC_COLOR");
2608   CheckEnumerationProperty<BlendFactor::Type>(application, renderer, Renderer::Property::BLEND_FACTOR_DEST_RGB, BlendFactor::ONE_MINUS_SRC_ALPHA, BlendFactor::ONE, BlendFactor::SRC_COLOR, "SRC_COLOR");
2609   CheckEnumerationProperty<BlendFactor::Type>(application, renderer, Renderer::Property::BLEND_FACTOR_SRC_ALPHA, BlendFactor::ONE, BlendFactor::ONE_MINUS_SRC_ALPHA, BlendFactor::SRC_COLOR, "SRC_COLOR");
2610   CheckEnumerationProperty<BlendFactor::Type>(application, renderer, Renderer::Property::BLEND_FACTOR_DEST_ALPHA, BlendFactor::ONE_MINUS_SRC_ALPHA, BlendFactor::ONE, BlendFactor::SRC_COLOR, "SRC_COLOR");
2611   CheckEnumerationProperty<DepthWriteMode::Type>(application, renderer, Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::AUTO, DepthWriteMode::OFF, DepthWriteMode::ON, "ON");
2612   CheckEnumerationProperty<DepthFunction::Type>(application, renderer, Renderer::Property::DEPTH_FUNCTION, DepthFunction::LESS, DepthFunction::ALWAYS, DepthFunction::GREATER, "GREATER");
2613   CheckEnumerationProperty<DepthTestMode::Type>(application, renderer, Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::AUTO, DepthTestMode::OFF, DepthTestMode::ON, "ON");
2614   CheckEnumerationProperty<StencilFunction::Type>(application, renderer, Renderer::Property::STENCIL_FUNCTION, StencilFunction::ALWAYS, StencilFunction::LESS, StencilFunction::EQUAL, "EQUAL");
2615   CheckEnumerationProperty<RenderMode::Type>(application, renderer, Renderer::Property::RENDER_MODE, RenderMode::AUTO, RenderMode::NONE, RenderMode::STENCIL, "STENCIL");
2616   CheckEnumerationProperty<StencilOperation::Type>(application, renderer, Renderer::Property::STENCIL_OPERATION_ON_FAIL, StencilOperation::KEEP, StencilOperation::REPLACE, StencilOperation::INCREMENT, "INCREMENT");
2617   CheckEnumerationProperty<StencilOperation::Type>(application, renderer, Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, StencilOperation::KEEP, StencilOperation::REPLACE, StencilOperation::INCREMENT, "INCREMENT");
2618   CheckEnumerationProperty<StencilOperation::Type>(application, renderer, Renderer::Property::STENCIL_OPERATION_ON_Z_PASS, StencilOperation::KEEP, StencilOperation::REPLACE, StencilOperation::INCREMENT, "INCREMENT");
2619
2620   if(Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::MAX) &&
2621      Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::MIN))
2622   {
2623     application.SendNotification();
2624     application.Render();
2625     CheckEnumerationProperty<DevelBlendEquation::Type>(application, renderer, DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::REVERSE_SUBTRACT, DevelBlendEquation::MAX, DevelBlendEquation::MIN, "MIN");
2626   }
2627
2628   if(Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::SCREEN))
2629   {
2630     application.SendNotification();
2631     application.Render();
2632     CheckEnumerationProperty<DevelBlendEquation::Type>(application, renderer, DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::MIN, DevelBlendEquation::MULTIPLY, DevelBlendEquation::SCREEN, "SCREEN");
2633   }
2634
2635   END_TEST;
2636 }
2637
2638 Renderer RendererTestFixture(TestApplication& application)
2639 {
2640   Geometry geometry = CreateQuadGeometry();
2641   Shader   shader   = CreateShader();
2642   Renderer renderer = Renderer::New(geometry, shader);
2643
2644   Actor actor = Actor::New();
2645   actor.AddRenderer(renderer);
2646   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
2647   Integration::Scene scene = application.GetScene();
2648   scene.GetRootLayer().SetProperty(Layer::Property::BEHAVIOR, Layer::LAYER_3D);
2649   scene.Add(actor);
2650
2651   return renderer;
2652 }
2653
2654 int UtcDaliRendererSetDepthTestMode(void)
2655 {
2656   TestApplication application;
2657   tet_infoline("Test setting the DepthTestMode");
2658
2659   Renderer           renderer             = RendererTestFixture(application);
2660   TestGlAbstraction& glAbstraction        = application.GetGlAbstraction();
2661   TraceCallStack&    glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2662   glEnableDisableStack.Enable(true);
2663   glEnableDisableStack.EnableLogging(true);
2664
2665   glEnableDisableStack.Reset();
2666   application.SendNotification();
2667   application.Render();
2668
2669   // Check depth-test is enabled by default.
2670   DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Enable", GetDepthTestString()));
2671   DALI_TEST_CHECK(!glEnableDisableStack.FindMethodAndParams("Disable", GetDepthTestString()));
2672
2673   // 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.
2674   renderer.SetProperty(Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::OFF);
2675   renderer.SetProperty(Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::OFF);
2676
2677   glEnableDisableStack.Reset();
2678   application.SendNotification();
2679   application.Render();
2680
2681   // Check the depth buffer was disabled.
2682   DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Disable", GetDepthTestString()));
2683
2684   // Turn on automatic mode depth-testing.
2685   // Layer behavior is currently set to LAYER_3D so AUTO should enable depth-testing.
2686   renderer.SetProperty(Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::AUTO);
2687
2688   glEnableDisableStack.Reset();
2689   application.SendNotification();
2690   application.Render();
2691
2692   // Check depth-test is now enabled.
2693   DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Enable", GetDepthTestString()));
2694   DALI_TEST_CHECK(!glEnableDisableStack.FindMethodAndParams("Disable", GetDepthTestString()));
2695
2696   // Change the layer behavior to LAYER_UI.
2697   // Note this will also disable depth testing for the layer by default, we test this first.
2698   application.GetScene().GetRootLayer().SetProperty(Layer::Property::BEHAVIOR, Layer::LAYER_UI);
2699
2700   glEnableDisableStack.Reset();
2701   application.SendNotification();
2702   application.Render();
2703
2704   // Check depth-test is disabled.
2705   DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Disable", GetDepthTestString()));
2706
2707   // Turn the layer depth-test flag back on, and confirm that depth testing is now on.
2708   application.GetScene().GetRootLayer().SetProperty(Layer::Property::DEPTH_TEST, true);
2709
2710   glEnableDisableStack.Reset();
2711   application.SendNotification();
2712   application.Render();
2713
2714   // Check depth-test is *still* disabled.
2715   DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Enable", GetDepthTestString()));
2716
2717   END_TEST;
2718 }
2719
2720 int UtcDaliRendererSetDepthWriteMode(void)
2721 {
2722   TestApplication application;
2723   tet_infoline("Test setting the DepthWriteMode");
2724
2725   Renderer           renderer      = RendererTestFixture(application);
2726   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2727
2728   application.SendNotification();
2729   application.Render();
2730
2731   // Check the default depth-write status first.
2732   DALI_TEST_CHECK(glAbstraction.GetLastDepthMask());
2733
2734   // Turn off depth-writing.
2735   renderer.SetProperty(Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::OFF);
2736
2737   application.SendNotification();
2738   application.Render();
2739
2740   // Check depth-write is now disabled.
2741   DALI_TEST_CHECK(!glAbstraction.GetLastDepthMask());
2742
2743   // Test the AUTO mode for depth-writing.
2744   // As our renderer is opaque, depth-testing should be enabled.
2745   renderer.SetProperty(Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::AUTO);
2746
2747   application.SendNotification();
2748   application.Render();
2749
2750   // Check depth-write is now enabled.
2751   DALI_TEST_CHECK(glAbstraction.GetLastDepthMask());
2752
2753   // Now make the renderer be treated as translucent by enabling blending.
2754   // The AUTO depth-write mode should turn depth-write off in this scenario.
2755   renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON);
2756
2757   application.SendNotification();
2758   application.Render();
2759
2760   // Check depth-write is now disabled.
2761   DALI_TEST_CHECK(!glAbstraction.GetLastDepthMask());
2762
2763   END_TEST;
2764 }
2765
2766 int UtcDaliRendererCheckStencilDefaults(void)
2767 {
2768   TestApplication application;
2769   tet_infoline("Test the stencil defaults");
2770
2771   Renderer           renderer               = RendererTestFixture(application);
2772   TestGlAbstraction& glAbstraction          = application.GetGlAbstraction();
2773   TraceCallStack&    glEnableDisableStack   = glAbstraction.GetEnableDisableTrace();
2774   TraceCallStack&    glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2775   glEnableDisableStack.Enable(true);
2776   glEnableDisableStack.EnableLogging(true);
2777   glStencilFunctionStack.Enable(true);
2778   glStencilFunctionStack.EnableLogging(true);
2779
2780   ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2781
2782   // Check the defaults:
2783   DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_FUNCTION).Get<int>()), static_cast<int>(StencilFunction::ALWAYS), TEST_LOCATION);
2784   DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_FUNCTION_MASK).Get<int>()), 0xFF, TEST_LOCATION);
2785   DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_FUNCTION_REFERENCE).Get<int>()), 0x00, TEST_LOCATION);
2786   DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_MASK).Get<int>()), 0xFF, TEST_LOCATION);
2787   DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_OPERATION_ON_FAIL).Get<int>()), static_cast<int>(StencilOperation::KEEP), TEST_LOCATION);
2788   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);
2789   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);
2790
2791   END_TEST;
2792 }
2793
2794 int UtcDaliRendererSetRenderModeToUseStencilBuffer(void)
2795 {
2796   TestApplication application;
2797   tet_infoline("Test setting the RenderMode to use the stencil buffer");
2798
2799   Renderer           renderer               = RendererTestFixture(application);
2800   TestGlAbstraction& glAbstraction          = application.GetGlAbstraction();
2801   TraceCallStack&    glEnableDisableStack   = glAbstraction.GetEnableDisableTrace();
2802   TraceCallStack&    glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2803   glEnableDisableStack.Enable(true);
2804   glEnableDisableStack.EnableLogging(true);
2805   glStencilFunctionStack.Enable(true);
2806   glStencilFunctionStack.EnableLogging(true);
2807
2808   // Set the StencilFunction to something other than the default, to confirm it is set as a property,
2809   // but NO GL call has been made while the RenderMode is set to not use the stencil buffer.
2810   renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::NONE);
2811   ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2812
2813   renderer.SetProperty(Renderer::Property::STENCIL_FUNCTION, StencilFunction::NEVER);
2814   DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_FUNCTION).Get<int>()), static_cast<int>(StencilFunction::NEVER), TEST_LOCATION);
2815
2816   ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2817   std::string methodString("StencilFunc");
2818   DALI_TEST_CHECK(!glStencilFunctionStack.FindMethod(methodString));
2819
2820   // Test the other RenderModes that will not enable the stencil buffer.
2821   renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::AUTO);
2822   ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2823   DALI_TEST_CHECK(!glStencilFunctionStack.FindMethod(methodString));
2824
2825   renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::COLOR);
2826   ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2827   DALI_TEST_CHECK(!glStencilFunctionStack.FindMethod(methodString));
2828
2829   // Now set the RenderMode to modes that will use the stencil buffer, and check the StencilFunction has changed.
2830   renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::STENCIL);
2831   ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2832
2833   DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Enable", GetStencilTestString()));
2834   DALI_TEST_CHECK(glStencilFunctionStack.FindMethod(methodString));
2835
2836   // Test the COLOR_STENCIL RenderMode as it also enables the stencil buffer.
2837   // First set a mode to turn off the stencil buffer, so the enable is required.
2838   renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::COLOR);
2839   ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2840   renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::COLOR_STENCIL);
2841   // Set a different stencil function as the last one is cached.
2842   renderer.SetProperty(Renderer::Property::STENCIL_FUNCTION, StencilFunction::ALWAYS);
2843   ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2844
2845   DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Enable", GetStencilTestString()));
2846   DALI_TEST_CHECK(glStencilFunctionStack.FindMethod(methodString));
2847
2848   END_TEST;
2849 }
2850
2851 // Helper function for the SetRenderModeToUseColorBuffer test.
2852 void CheckRenderModeColorMask(TestApplication& application, Renderer& renderer, RenderMode::Type renderMode, bool expectedValue)
2853 {
2854   // Set the RenderMode property to a value that should not allow color buffer writes.
2855   renderer.SetProperty(Renderer::Property::RENDER_MODE, renderMode);
2856   application.SendNotification();
2857   application.Render();
2858
2859   // Check if ColorMask has been called, and that the values are correct.
2860   TestGlAbstraction&                        glAbstraction = application.GetGlAbstraction();
2861   const TestGlAbstraction::ColorMaskParams& colorMaskParams(glAbstraction.GetColorMaskParams());
2862
2863   DALI_TEST_EQUALS<bool>(colorMaskParams.red, expectedValue, TEST_LOCATION);
2864   DALI_TEST_EQUALS<bool>(colorMaskParams.green, expectedValue, TEST_LOCATION);
2865   DALI_TEST_EQUALS<bool>(colorMaskParams.blue, expectedValue, TEST_LOCATION);
2866   // @todo Only check alpha if framebuffer supports it.
2867   //DALI_TEST_EQUALS<bool>(colorMaskParams.alpha, expectedValue, TEST_LOCATION);
2868 }
2869
2870 int UtcDaliRendererSetRenderModeToUseColorBuffer(void)
2871 {
2872   TestApplication application;
2873   tet_infoline("Test setting the RenderMode to use the color buffer");
2874
2875   Renderer renderer = RendererTestFixture(application);
2876
2877   // Set the RenderMode property to a value that should not allow color buffer writes.
2878   // Then check if ColorMask has been called, and that the values are correct.
2879   CheckRenderModeColorMask(application, renderer, RenderMode::AUTO, true);
2880   CheckRenderModeColorMask(application, renderer, RenderMode::NONE, false);
2881   CheckRenderModeColorMask(application, renderer, RenderMode::COLOR, true);
2882   CheckRenderModeColorMask(application, renderer, RenderMode::STENCIL, false);
2883   CheckRenderModeColorMask(application, renderer, RenderMode::COLOR_STENCIL, true);
2884
2885   END_TEST;
2886 }
2887
2888 int UtcDaliRendererSetStencilFunction(void)
2889 {
2890   TestApplication application;
2891   tet_infoline("Test setting the StencilFunction");
2892
2893   Renderer           renderer               = RendererTestFixture(application);
2894   TestGlAbstraction& glAbstraction          = application.GetGlAbstraction();
2895   TraceCallStack&    glEnableDisableStack   = glAbstraction.GetEnableDisableTrace();
2896   TraceCallStack&    glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2897   glEnableDisableStack.Enable(true);
2898   glEnableDisableStack.EnableLogging(true);
2899   glStencilFunctionStack.Enable(true);
2900   glStencilFunctionStack.EnableLogging(true);
2901
2902   // RenderMode must use the stencil for StencilFunction to operate.
2903   renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::STENCIL);
2904   ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2905
2906   /*
2907    * Lookup table for testing StencilFunction.
2908    * Note: This MUST be in the same order as the Dali::StencilFunction enum.
2909    */
2910   const int StencilFunctionLookupTable[] = {
2911     GL_NEVER,
2912     GL_LESS,
2913     GL_EQUAL,
2914     GL_LEQUAL,
2915     GL_GREATER,
2916     GL_NOTEQUAL,
2917     GL_GEQUAL,
2918     GL_ALWAYS};
2919   const int StencilFunctionLookupTableCount = sizeof(StencilFunctionLookupTable) / sizeof(StencilFunctionLookupTable[0]);
2920
2921   /*
2922    * Loop through all types of StencilFunction, checking:
2923    *  - The value is cached (set in event thread side)
2924    *  - Causes "glStencilFunc" to be called
2925    *  - Checks the correct parameters to "glStencilFunc" were used
2926    */
2927   std::string nonChangingParameters = "0, 255";
2928   std::string methodString("StencilFunc");
2929   for(int i = 0; i < StencilFunctionLookupTableCount; ++i)
2930   {
2931     // Set the property.
2932     renderer.SetProperty(Renderer::Property::STENCIL_FUNCTION, static_cast<Dali::StencilFunction::Type>(i));
2933
2934     // Check GetProperty returns the same value.
2935     DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_FUNCTION).Get<int>()), i, TEST_LOCATION);
2936
2937     // Reset the trace debug.
2938     ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2939
2940     // Check the function is called and the parameters are correct.
2941     std::stringstream parameterStream;
2942     parameterStream << StencilFunctionLookupTable[i] << ", " << nonChangingParameters;
2943
2944     DALI_TEST_CHECK(glStencilFunctionStack.FindMethodAndParams(methodString, parameterStream.str()));
2945   }
2946
2947   // Change the Function Reference only and check the behavior is correct:
2948   // 170 is 0xaa in hex / 10101010 in binary (every other bit set).
2949   int testValueReference = 170;
2950   renderer.SetProperty(Renderer::Property::STENCIL_FUNCTION_REFERENCE, testValueReference);
2951
2952   DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_FUNCTION_REFERENCE).Get<int>()), testValueReference, TEST_LOCATION);
2953
2954   ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2955
2956   DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetCurrentProperty(Renderer::Property::STENCIL_FUNCTION_REFERENCE).Get<int>()), testValueReference, TEST_LOCATION);
2957
2958   std::stringstream parameterStream;
2959   parameterStream << StencilFunctionLookupTable[StencilOperation::DECREMENT_WRAP] << ", " << testValueReference << ", 255";
2960
2961   DALI_TEST_CHECK(glStencilFunctionStack.FindMethodAndParams(methodString, parameterStream.str()));
2962
2963   // Change the Function Mask only and check the behavior is correct:
2964   // 85 is 0x55 in hex / 01010101 in binary (every other bit set).
2965   int testValueMask = 85;
2966   renderer.SetProperty(Renderer::Property::STENCIL_FUNCTION_MASK, testValueMask);
2967
2968   DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_FUNCTION_MASK).Get<int>()), testValueMask, TEST_LOCATION);
2969
2970   ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2971
2972   DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetCurrentProperty(Renderer::Property::STENCIL_FUNCTION_MASK).Get<int>()), testValueMask, TEST_LOCATION);
2973
2974   // Clear the stringstream.
2975   parameterStream.str(std::string());
2976   parameterStream << StencilFunctionLookupTable[StencilOperation::DECREMENT_WRAP] << ", " << testValueReference << ", " << testValueMask;
2977
2978   DALI_TEST_CHECK(glStencilFunctionStack.FindMethodAndParams(methodString, parameterStream.str()));
2979
2980   END_TEST;
2981 }
2982
2983 int UtcDaliRendererSetStencilOperation(void)
2984 {
2985   TestApplication application;
2986   tet_infoline("Test setting the StencilOperation");
2987
2988   Renderer           renderer               = RendererTestFixture(application);
2989   TestGlAbstraction& glAbstraction          = application.GetGlAbstraction();
2990   TraceCallStack&    glEnableDisableStack   = glAbstraction.GetEnableDisableTrace();
2991   TraceCallStack&    glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2992   glEnableDisableStack.Enable(true);
2993   glEnableDisableStack.EnableLogging(true);
2994   glStencilFunctionStack.Enable(true);
2995   glStencilFunctionStack.EnableLogging(true);
2996
2997   // RenderMode must use the stencil for StencilOperation to operate.
2998   renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::STENCIL);
2999
3000   /*
3001    * Lookup table for testing StencilOperation.
3002    * Note: This MUST be in the same order as the Dali::StencilOperation enum.
3003    */
3004   const int StencilOperationLookupTable[] = {
3005     GL_ZERO,
3006     GL_KEEP,
3007     GL_REPLACE,
3008     GL_INCR,
3009     GL_DECR,
3010     GL_INVERT,
3011     GL_INCR_WRAP,
3012     GL_DECR_WRAP};
3013   const int StencilOperationLookupTableCount = sizeof(StencilOperationLookupTable) / sizeof(StencilOperationLookupTable[0]);
3014
3015   // Set all 3 StencilOperation properties to a default.
3016   renderer.SetProperty(Renderer::Property::STENCIL_OPERATION_ON_FAIL, StencilOperation::KEEP);
3017   renderer.SetProperty(Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, StencilOperation::ZERO);
3018   renderer.SetProperty(Renderer::Property::STENCIL_OPERATION_ON_Z_PASS, StencilOperation::ZERO);
3019
3020   // Set our expected parameter list to the equivalent result.
3021   int parameters[] = {StencilOperationLookupTable[StencilOperation::ZERO], StencilOperationLookupTable[StencilOperation::ZERO], StencilOperationLookupTable[StencilOperation::ZERO]};
3022
3023   ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
3024
3025   /*
3026    * Loop through all types of StencilOperation, checking:
3027    *  - The value is cached (set in event thread side)
3028    *  - Causes "glStencilFunc" to be called
3029    *  - Checks the correct parameters to "glStencilFunc" were used
3030    *  - Checks the above for all 3 parameter placements of StencilOperation ( OnFail, OnZFail, OnPass )
3031    */
3032   std::string methodString("StencilOp");
3033
3034   for(int i = 0; i < StencilOperationLookupTableCount; ++i)
3035   {
3036     for(int j = 0; j < StencilOperationLookupTableCount; ++j)
3037     {
3038       for(int k = 0; k < StencilOperationLookupTableCount; ++k)
3039       {
3040         // Set the property (outer loop causes all 3 different properties to be set separately).
3041         renderer.SetProperty(Renderer::Property::STENCIL_OPERATION_ON_FAIL, static_cast<Dali::StencilFunction::Type>(i));
3042         renderer.SetProperty(Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, static_cast<Dali::StencilFunction::Type>(j));
3043         renderer.SetProperty(Renderer::Property::STENCIL_OPERATION_ON_Z_PASS, static_cast<Dali::StencilFunction::Type>(k));
3044
3045         // Check GetProperty returns the same value.
3046         DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_OPERATION_ON_FAIL).Get<int>()), i, TEST_LOCATION);
3047         DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL).Get<int>()), j, TEST_LOCATION);
3048         DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_OPERATION_ON_Z_PASS).Get<int>()), k, TEST_LOCATION);
3049
3050         // Reset the trace debug.
3051         ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
3052
3053         // Check the function is called and the parameters are correct.
3054         // Set the expected parameter value at its correct index (only)
3055         parameters[0u] = StencilOperationLookupTable[i];
3056         parameters[1u] = StencilOperationLookupTable[j];
3057         parameters[2u] = StencilOperationLookupTable[k];
3058
3059         // Build the parameter list.
3060         std::stringstream parameterStream;
3061         for(int parameterBuild = 0; parameterBuild < 3; ++parameterBuild)
3062         {
3063           parameterStream << parameters[parameterBuild];
3064           // Comma-separate the parameters.
3065           if(parameterBuild < 2)
3066           {
3067             parameterStream << ", ";
3068           }
3069         }
3070
3071         // Check the function was called and the parameters were correct.
3072         DALI_TEST_CHECK(glStencilFunctionStack.FindMethodAndParams(methodString, parameterStream.str()));
3073       }
3074     }
3075   }
3076
3077   END_TEST;
3078 }
3079
3080 int UtcDaliRendererSetStencilMask(void)
3081 {
3082   TestApplication application;
3083   tet_infoline("Test setting the StencilMask");
3084
3085   Renderer           renderer               = RendererTestFixture(application);
3086   TestGlAbstraction& glAbstraction          = application.GetGlAbstraction();
3087   TraceCallStack&    glEnableDisableStack   = glAbstraction.GetEnableDisableTrace();
3088   TraceCallStack&    glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
3089   glEnableDisableStack.Enable(true);
3090   glEnableDisableStack.EnableLogging(true);
3091   glStencilFunctionStack.Enable(true);
3092   glStencilFunctionStack.EnableLogging(true);
3093
3094   // RenderMode must use the stencil for StencilMask to operate.
3095   renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::STENCIL);
3096
3097   // Set the StencilMask property to a value.
3098   renderer.SetProperty(Renderer::Property::STENCIL_MASK, 0x00);
3099
3100   // Check GetProperty returns the same value.
3101   DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_MASK).Get<int>()), 0x00, TEST_LOCATION);
3102
3103   ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
3104
3105   DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetCurrentProperty(Renderer::Property::STENCIL_MASK).Get<int>()), 0x00, TEST_LOCATION);
3106
3107   std::string methodString("StencilMask");
3108   std::string parameterString = "0";
3109
3110   // Check the function was called and the parameters were correct.
3111   DALI_TEST_CHECK(glStencilFunctionStack.FindMethodAndParams(methodString, parameterString));
3112
3113   // Set the StencilMask property to another value to ensure it has changed.
3114   renderer.SetProperty(Renderer::Property::STENCIL_MASK, 0xFF);
3115
3116   // Check GetProperty returns the same value.
3117   DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_MASK).Get<int>()), 0xFF, TEST_LOCATION);
3118
3119   ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
3120
3121   DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetCurrentProperty(Renderer::Property::STENCIL_MASK).Get<int>()), 0xFF, TEST_LOCATION);
3122
3123   parameterString = "255";
3124
3125   // Check the function was called and the parameters were correct.
3126   DALI_TEST_CHECK(glStencilFunctionStack.FindMethodAndParams(methodString, parameterString));
3127
3128   END_TEST;
3129 }
3130
3131 int UtcDaliRendererWrongNumberOfTextures(void)
3132 {
3133   TestApplication application;
3134   tet_infoline("Test renderer does render even if number of textures is different than active samplers in the shader");
3135
3136   //Create a TextureSet with 4 textures (One more texture in the texture set than active samplers)
3137   //@note Shaders in the test suit have 3 active samplers. See TestGlAbstraction::GetActiveUniform()
3138   Texture    texture    = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64u, 64u);
3139   TextureSet textureSet = CreateTextureSet();
3140   textureSet.SetTexture(0, texture);
3141   textureSet.SetTexture(1, texture);
3142   textureSet.SetTexture(2, texture);
3143   textureSet.SetTexture(3, texture);
3144   Shader   shader   = Shader::New("VertexSource", "FragmentSource");
3145   Geometry geometry = CreateQuadGeometry();
3146   Renderer renderer = Renderer::New(geometry, shader);
3147   renderer.SetTextures(textureSet);
3148
3149   Actor actor = Actor::New();
3150   actor.AddRenderer(renderer);
3151   actor.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 0.0f));
3152   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
3153   application.GetScene().Add(actor);
3154
3155   TestGlAbstraction& gl        = application.GetGlAbstraction();
3156   TraceCallStack&    drawTrace = gl.GetDrawTrace();
3157   drawTrace.Reset();
3158   drawTrace.Enable(true);
3159   drawTrace.EnableLogging(true);
3160
3161   application.SendNotification();
3162   application.Render(0);
3163
3164   //Test we do the drawcall when TextureSet has more textures than there are active samplers in the shader
3165   DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION);
3166
3167   //Create a TextureSet with 1 texture (two more active samplers than texture in the texture set)
3168   //@note Shaders in the test suit have 3 active samplers. See TestGlAbstraction::GetActiveUniform()
3169   textureSet = CreateTextureSet();
3170   renderer.SetTextures(textureSet);
3171   textureSet.SetTexture(0, texture);
3172   drawTrace.Reset();
3173   application.SendNotification();
3174   application.Render(0);
3175
3176   //Test we do the drawcall when TextureSet has less textures than there are active samplers in the shader.
3177   DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION);
3178
3179   END_TEST;
3180 }
3181
3182 int UtcDaliRendererOpacity(void)
3183 {
3184   TestApplication application;
3185
3186   tet_infoline("Test OPACITY property");
3187
3188   Geometry geometry = CreateQuadGeometry();
3189   Shader   shader   = Shader::New("vertexSrc", "fragmentSrc");
3190   Renderer renderer = Renderer::New(geometry, shader);
3191
3192   Actor actor = Actor::New();
3193   actor.AddRenderer(renderer);
3194   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3195   actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 1.0f));
3196   application.GetScene().Add(actor);
3197
3198   Property::Value value = renderer.GetProperty(DevelRenderer::Property::OPACITY);
3199   float           opacity;
3200   DALI_TEST_CHECK(value.Get(opacity));
3201   DALI_TEST_EQUALS(opacity, 1.0f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3202
3203   application.SendNotification();
3204   application.Render();
3205
3206   Vector4            actualValue;
3207   TestGlAbstraction& gl = application.GetGlAbstraction();
3208   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uColor", actualValue));
3209   DALI_TEST_EQUALS(actualValue.a, 1.0f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3210
3211   renderer.SetProperty(DevelRenderer::Property::OPACITY, 0.5f);
3212
3213   application.SendNotification();
3214   application.Render();
3215
3216   value = renderer.GetProperty(DevelRenderer::Property::OPACITY);
3217   DALI_TEST_CHECK(value.Get(opacity));
3218   DALI_TEST_EQUALS(opacity, 0.5f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3219
3220   value = renderer.GetCurrentProperty(DevelRenderer::Property::OPACITY);
3221   DALI_TEST_CHECK(value.Get(opacity));
3222   DALI_TEST_EQUALS(opacity, 0.5f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3223
3224   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uColor", actualValue));
3225   DALI_TEST_EQUALS(actualValue.a, 0.5f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3226
3227   END_TEST;
3228 }
3229
3230 int UtcDaliRendererOpacityAnimation(void)
3231 {
3232   TestApplication application;
3233
3234   tet_infoline("Test OPACITY property animation");
3235
3236   Geometry geometry = CreateQuadGeometry();
3237   Shader   shader   = Shader::New("vertexSrc", "fragmentSrc");
3238   Renderer renderer = Renderer::New(geometry, shader);
3239
3240   Actor actor = Actor::New();
3241   actor.AddRenderer(renderer);
3242   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3243   actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 1.0f));
3244   application.GetScene().Add(actor);
3245
3246   application.SendNotification();
3247   application.Render(0);
3248
3249   Property::Value value = renderer.GetProperty(DevelRenderer::Property::OPACITY);
3250   float           opacity;
3251   DALI_TEST_CHECK(value.Get(opacity));
3252   DALI_TEST_EQUALS(opacity, 1.0f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3253
3254   Animation animation = Animation::New(1.0f);
3255   animation.AnimateTo(Property(renderer, DevelRenderer::Property::OPACITY), 0.0f);
3256   animation.Play();
3257
3258   application.SendNotification();
3259   application.Render(1000);
3260
3261   value = renderer.GetProperty(DevelRenderer::Property::OPACITY);
3262   DALI_TEST_CHECK(value.Get(opacity));
3263   DALI_TEST_EQUALS(opacity, 0.0f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3264
3265   // Need to clear the animation before setting the property as the animation value is baked and will override any previous setters
3266   animation.Clear();
3267   renderer.SetProperty(DevelRenderer::Property::OPACITY, 0.1f);
3268
3269   animation.AnimateBy(Property(renderer, DevelRenderer::Property::OPACITY), 0.5f);
3270   animation.Play();
3271
3272   application.SendNotification();
3273   application.Render(1000);
3274
3275   value = renderer.GetProperty(DevelRenderer::Property::OPACITY);
3276   DALI_TEST_CHECK(value.Get(opacity));
3277   DALI_TEST_EQUALS(opacity, 0.6f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3278   DALI_TEST_EQUALS(opacity, renderer.GetCurrentProperty(DevelRenderer::Property::OPACITY).Get<float>(), Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3279
3280   END_TEST;
3281 }
3282
3283 int UtcDaliRendererInvalidProperty(void)
3284 {
3285   TestApplication application;
3286
3287   tet_infoline("Test invalid property");
3288
3289   Geometry geometry = CreateQuadGeometry();
3290   Shader   shader   = Shader::New("vertexSrc", "fragmentSrc");
3291   Renderer renderer = Renderer::New(geometry, shader);
3292
3293   Actor actor = Actor::New();
3294   actor.AddRenderer(renderer);
3295   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3296   application.GetScene().Add(actor);
3297
3298   application.SendNotification();
3299   application.Render(0);
3300
3301   Property::Value value = renderer.GetProperty(Renderer::Property::DEPTH_INDEX + 100);
3302   DALI_TEST_CHECK(value.GetType() == Property::Type::NONE);
3303
3304   value = renderer.GetCurrentProperty(Renderer::Property::DEPTH_INDEX + 100);
3305   DALI_TEST_CHECK(value.GetType() == Property::Type::NONE);
3306
3307   END_TEST;
3308 }
3309
3310 int UtcDaliRendererRenderingBehavior(void)
3311 {
3312   TestApplication application;
3313
3314   tet_infoline("Test RENDERING_BEHAVIOR property");
3315
3316   Geometry geometry = CreateQuadGeometry();
3317   Shader   shader   = Shader::New("vertexSrc", "fragmentSrc");
3318   Renderer renderer = Renderer::New(geometry, shader);
3319
3320   Actor actor = Actor::New();
3321   actor.AddRenderer(renderer);
3322   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3323   actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 1.0f));
3324   application.GetScene().Add(actor);
3325
3326   Property::Value value = renderer.GetProperty(DevelRenderer::Property::RENDERING_BEHAVIOR);
3327   int             renderingBehavior;
3328   DALI_TEST_CHECK(value.Get(renderingBehavior));
3329   DALI_TEST_EQUALS(static_cast<DevelRenderer::Rendering::Type>(renderingBehavior), DevelRenderer::Rendering::IF_REQUIRED, TEST_LOCATION);
3330
3331   application.SendNotification();
3332   application.Render();
3333
3334   uint32_t updateStatus = application.GetUpdateStatus();
3335
3336   DALI_TEST_CHECK(!(updateStatus & Integration::KeepUpdating::STAGE_KEEP_RENDERING));
3337
3338   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
3339   TraceCallStack&    drawTrace     = glAbstraction.GetDrawTrace();
3340   drawTrace.Enable(true);
3341   drawTrace.Reset();
3342
3343   renderer.SetProperty(DevelRenderer::Property::RENDERING_BEHAVIOR, DevelRenderer::Rendering::CONTINUOUSLY);
3344
3345   value = renderer.GetProperty(DevelRenderer::Property::RENDERING_BEHAVIOR);
3346   DALI_TEST_CHECK(value.Get(renderingBehavior));
3347   DALI_TEST_EQUALS(static_cast<DevelRenderer::Rendering::Type>(renderingBehavior), DevelRenderer::Rendering::CONTINUOUSLY, TEST_LOCATION);
3348
3349   // Render and check the update status
3350   application.SendNotification();
3351   application.Render();
3352
3353   updateStatus = application.GetUpdateStatus();
3354
3355   DALI_TEST_CHECK(updateStatus & Integration::KeepUpdating::STAGE_KEEP_RENDERING);
3356
3357   value = renderer.GetCurrentProperty(DevelRenderer::Property::RENDERING_BEHAVIOR);
3358   DALI_TEST_CHECK(value.Get(renderingBehavior));
3359   DALI_TEST_EQUALS(static_cast<DevelRenderer::Rendering::Type>(renderingBehavior), DevelRenderer::Rendering::CONTINUOUSLY, TEST_LOCATION);
3360
3361   DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION);
3362
3363   drawTrace.Reset();
3364
3365   // Render again and check the update status
3366   application.SendNotification();
3367   application.Render();
3368
3369   updateStatus = application.GetUpdateStatus();
3370
3371   DALI_TEST_CHECK(updateStatus & Integration::KeepUpdating::STAGE_KEEP_RENDERING);
3372
3373   DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION);
3374
3375   {
3376     // Render again and check the update status
3377     Animation animation = Animation::New(1.0f);
3378     animation.AnimateTo(Property(renderer, DevelRenderer::Property::OPACITY), 0.0f, TimePeriod(0.5f, 0.5f));
3379     animation.Play();
3380
3381     drawTrace.Reset();
3382
3383     application.SendNotification();
3384     application.Render(0);
3385
3386     DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION);
3387
3388     drawTrace.Reset();
3389
3390     application.SendNotification();
3391     application.Render(100);
3392
3393     updateStatus = application.GetUpdateStatus();
3394
3395     DALI_TEST_CHECK(updateStatus & Integration::KeepUpdating::STAGE_KEEP_RENDERING);
3396
3397     DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION);
3398   }
3399
3400   // Change rendering behavior
3401   renderer.SetProperty(DevelRenderer::Property::RENDERING_BEHAVIOR, DevelRenderer::Rendering::IF_REQUIRED);
3402
3403   // Render and check the update status
3404   application.SendNotification();
3405   application.Render();
3406
3407   updateStatus = application.GetUpdateStatus();
3408
3409   DALI_TEST_CHECK(!(updateStatus & Integration::KeepUpdating::STAGE_KEEP_RENDERING));
3410
3411   END_TEST;
3412 }
3413
3414 int UtcDaliRendererRegenerateUniformMap(void)
3415 {
3416   TestApplication application;
3417
3418   tet_infoline("Test regenerating uniform map when attaching renderer to the node");
3419
3420   Geometry geometry = CreateQuadGeometry();
3421   Shader   shader   = Shader::New("vertexSrc", "fragmentSrc");
3422   Renderer renderer = Renderer::New(geometry, shader);
3423
3424   Actor actor = Actor::New();
3425   actor.AddRenderer(renderer);
3426   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3427   actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 1.0f));
3428   application.GetScene().Add(actor);
3429
3430   application.SendNotification();
3431   application.Render();
3432
3433   actor.RemoveRenderer(renderer);
3434   shader = Shader::New("vertexSrc", "fragmentSrc");
3435   shader.RegisterProperty("opacity", 0.5f);
3436   renderer.SetShader(shader);
3437
3438   Stage::GetCurrent().KeepRendering(1.0f);
3439
3440   // Update for several frames
3441   application.SendNotification();
3442   application.Render();
3443   application.SendNotification();
3444   application.Render();
3445   application.SendNotification();
3446   application.Render();
3447   application.SendNotification();
3448   application.Render();
3449
3450   // Add Renderer
3451   actor.AddRenderer(renderer);
3452   application.SendNotification();
3453   application.Render();
3454
3455   // Nothing to test here, the test must not crash
3456   auto updateStatus = application.GetUpdateStatus();
3457   DALI_TEST_CHECK(updateStatus & Integration::KeepUpdating::STAGE_KEEP_RENDERING);
3458
3459   END_TEST;
3460 }
3461
3462 int UtcDaliRendererAddDrawCommands(void)
3463 {
3464   TestApplication application;
3465
3466   tet_infoline("Test adding draw commands to the renderer");
3467
3468   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
3469   glAbstraction.EnableEnableDisableCallTrace(true);
3470
3471   Geometry geometry = CreateQuadGeometry();
3472   Shader   shader   = Shader::New("vertexSrc", "fragmentSrc");
3473   Renderer renderer = Renderer::New(geometry, shader);
3474
3475   renderer.SetProperty(Renderer::Property::BLEND_MODE, Dali::BlendMode::ON);
3476   Actor actor = Actor::New();
3477   actor.AddRenderer(renderer);
3478   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3479   actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 1.0f));
3480   application.GetScene().Add(actor);
3481
3482   // Expect delivering a single draw call
3483   auto& drawTrace = glAbstraction.GetDrawTrace();
3484   drawTrace.Reset();
3485   drawTrace.Enable(true);
3486   application.SendNotification();
3487   application.Render();
3488
3489   DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION);
3490
3491   tet_infoline("\n\nTesting extension draw commands\n");
3492   auto drawCommand1         = DevelRenderer::DrawCommand{};
3493   drawCommand1.drawType     = DevelRenderer::DrawType::INDEXED;
3494   drawCommand1.firstIndex   = 0;
3495   drawCommand1.elementCount = 2;
3496   drawCommand1.queue        = DevelRenderer::RENDER_QUEUE_OPAQUE;
3497
3498   auto drawCommand2         = DevelRenderer::DrawCommand{};
3499   drawCommand2.drawType     = DevelRenderer::DrawType::INDEXED;
3500   drawCommand2.firstIndex   = 2;
3501   drawCommand2.elementCount = 2;
3502   drawCommand2.queue        = DevelRenderer::RENDER_QUEUE_TRANSPARENT;
3503
3504   auto drawCommand3         = DevelRenderer::DrawCommand{};
3505   drawCommand3.drawType     = DevelRenderer::DrawType::ARRAY;
3506   drawCommand3.firstIndex   = 2;
3507   drawCommand3.elementCount = 2;
3508   drawCommand3.queue        = DevelRenderer::RENDER_QUEUE_OPAQUE;
3509
3510   DevelRenderer::AddDrawCommand(renderer, drawCommand1);
3511   DevelRenderer::AddDrawCommand(renderer, drawCommand2);
3512   DevelRenderer::AddDrawCommand(renderer, drawCommand3);
3513
3514   drawTrace.Reset();
3515   drawTrace.Enable(true);
3516   application.SendNotification();
3517   application.Render();
3518
3519   DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 3, TEST_LOCATION);
3520   END_TEST;
3521 }
3522 int UtcDaliRendererSetGeometryNegative(void)
3523 {
3524   TestApplication application;
3525   Dali::Renderer  instance;
3526   try
3527   {
3528     Dali::Geometry arg1;
3529     instance.SetGeometry(arg1);
3530     DALI_TEST_CHECK(false); // Should not get here
3531   }
3532   catch(...)
3533   {
3534     DALI_TEST_CHECK(true); // We expect an assert
3535   }
3536   END_TEST;
3537 }
3538
3539 int UtcDaliRendererSetTexturesNegative(void)
3540 {
3541   TestApplication application;
3542   Dali::Renderer  instance;
3543   try
3544   {
3545     Dali::TextureSet arg1;
3546     instance.SetTextures(arg1);
3547     DALI_TEST_CHECK(false); // Should not get here
3548   }
3549   catch(...)
3550   {
3551     DALI_TEST_CHECK(true); // We expect an assert
3552   }
3553   END_TEST;
3554 }
3555
3556 int UtcDaliRendererSetShaderNegative(void)
3557 {
3558   TestApplication application;
3559   Dali::Renderer  instance;
3560   try
3561   {
3562     Dali::Shader arg1;
3563     instance.SetShader(arg1);
3564     DALI_TEST_CHECK(false); // Should not get here
3565   }
3566   catch(...)
3567   {
3568     DALI_TEST_CHECK(true); // We expect an assert
3569   }
3570   END_TEST;
3571 }
3572
3573 int UtcDaliRendererGetGeometryNegative(void)
3574 {
3575   TestApplication application;
3576   Dali::Renderer  instance;
3577   try
3578   {
3579     instance.GetGeometry();
3580     DALI_TEST_CHECK(false); // Should not get here
3581   }
3582   catch(...)
3583   {
3584     DALI_TEST_CHECK(true); // We expect an assert
3585   }
3586   END_TEST;
3587 }
3588
3589 int UtcDaliRendererGetTexturesNegative(void)
3590 {
3591   TestApplication application;
3592   Dali::Renderer  instance;
3593   try
3594   {
3595     instance.GetTextures();
3596     DALI_TEST_CHECK(false); // Should not get here
3597   }
3598   catch(...)
3599   {
3600     DALI_TEST_CHECK(true); // We expect an assert
3601   }
3602   END_TEST;
3603 }
3604
3605 int UtcDaliRendererGetShaderNegative(void)
3606 {
3607   TestApplication application;
3608   Dali::Renderer  instance;
3609   try
3610   {
3611     instance.GetShader();
3612     DALI_TEST_CHECK(false); // Should not get here
3613   }
3614   catch(...)
3615   {
3616     DALI_TEST_CHECK(true); // We expect an assert
3617   }
3618   END_TEST;
3619 }
3620
3621 int UtcDaliRendererCheckTextureBindingP(void)
3622 {
3623   TestApplication application;
3624
3625   tet_infoline("Test adding draw commands to the renderer");
3626
3627   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
3628   glAbstraction.EnableEnableDisableCallTrace(true);
3629
3630   Geometry geometry = CreateQuadGeometry();
3631   Shader   shader   = Shader::New("vertexSrc", "fragmentSrc");
3632   Renderer renderer = Renderer::New(geometry, shader);
3633
3634   renderer.SetProperty(Renderer::Property::BLEND_MODE, Dali::BlendMode::ON);
3635   Actor actor = Actor::New();
3636   actor.AddRenderer(renderer);
3637   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3638   actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 1.0f));
3639   application.GetScene().Add(actor);
3640
3641   TestGraphicsController& graphics        = application.GetGraphicsController();
3642   TraceCallStack&         cmdBufCallstack = graphics.mCommandBufferCallStack;
3643   cmdBufCallstack.Enable(true);
3644
3645   application.SendNotification();
3646   application.Render();
3647
3648   DALI_TEST_CHECK(!cmdBufCallstack.FindMethod("BindTextures"));
3649
3650   Texture    image0      = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGB888, 64, 64);
3651   TextureSet textureSet0 = CreateTextureSet(image0);
3652   renderer.SetTextures(textureSet0);
3653
3654   application.SendNotification();
3655   application.Render();
3656
3657   DALI_TEST_CHECK(cmdBufCallstack.FindMethod("BindTextures"));
3658   END_TEST;
3659 }
3660
3661 int UtcDaliRendererPreparePipeline(void)
3662 {
3663   TestApplication application;
3664
3665   tet_infoline("Test that rendering an actor binds the attributes locs from the reflection");
3666
3667   Property::Map vf            = CreateModelVertexFormat();
3668   Geometry      modelGeometry = CreateModelGeometry(vf);
3669   Shader        shader        = Shader::New("vertexSrc", "fragmentSrc");
3670   Renderer      renderer      = Renderer::New(modelGeometry, shader);
3671   Actor         actor         = Actor::New();
3672
3673   // Change the order up to get a fair test
3674   Property::Map modelVF;
3675   modelVF["aBoneIndex[0]"]   = Property::INTEGER;
3676   modelVF["aBoneIndex[1]"]   = Property::INTEGER;
3677   modelVF["aBoneIndex[2]"]   = Property::INTEGER;
3678   modelVF["aBoneIndex[3]"]   = Property::INTEGER;
3679   modelVF["aBoneWeights[0]"] = Property::FLOAT;
3680   modelVF["aBoneWeights[1]"] = Property::FLOAT;
3681   modelVF["aBoneWeights[2]"] = Property::FLOAT;
3682   modelVF["aBoneWeights[3]"] = Property::FLOAT;
3683   modelVF["aPosition"]       = Property::VECTOR3;
3684   modelVF["aNormal"]         = Property::VECTOR3;
3685   modelVF["aTexCoord1"]      = Property::VECTOR3;
3686   modelVF["aTexCoord2"]      = Property::VECTOR3;
3687
3688   Property::Array vfs;
3689   vfs.PushBack(modelVF);
3690   TestGraphicsController& graphics = application.GetGraphicsController();
3691   graphics.SetVertexFormats(vfs);
3692
3693   actor.AddRenderer(renderer);
3694   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3695   actor.SetProperty(Actor::Property::COLOR, Color::WHITE);
3696   application.GetScene().Add(actor);
3697
3698   TraceCallStack& cmdBufCallstack   = graphics.mCommandBufferCallStack;
3699   TraceCallStack& graphicsCallstack = graphics.mCallStack;
3700   cmdBufCallstack.Enable(true);
3701   graphicsCallstack.Enable(true);
3702
3703   application.SendNotification();
3704   application.Render();
3705
3706   DALI_TEST_CHECK(graphicsCallstack.FindMethod("SubmitCommandBuffers"));
3707   std::vector<Graphics::SubmitInfo>& submissions = graphics.mSubmitStack;
3708   DALI_TEST_CHECK(submissions.size() > 0);
3709
3710   TestGraphicsCommandBuffer* cmdBuf = static_cast<TestGraphicsCommandBuffer*>((submissions.back().cmdBuffer[0]));
3711
3712   auto result   = cmdBuf->GetChildCommandsByType(0 | CommandType::BIND_PIPELINE);
3713   auto pipeline = result[0]->data.bindPipeline.pipeline;
3714
3715   if(pipeline)
3716   {
3717     DALI_TEST_EQUALS(pipeline->vertexInputState.attributes.size(), 12, TEST_LOCATION);
3718     DALI_TEST_EQUALS(pipeline->vertexInputState.attributes[3].location, // 4th requested attr: aTexCoord2
3719                      11,
3720                      TEST_LOCATION);
3721     DALI_TEST_EQUALS(pipeline->vertexInputState.attributes[3].format, // 4th requested attr: aTexCoord2
3722                      Graphics::VertexInputFormat::FVECTOR3,
3723                      TEST_LOCATION);
3724   }
3725
3726   END_TEST;
3727 }