Add Default Uniform : uActorColor
[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   Vector4            actualActorColor(Vector4::ZERO);
1415   TestGlAbstraction& gl = application.GetGlAbstraction();
1416   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uColor", actualValue));
1417   DALI_TEST_EQUALS(actualValue, Vector4(1.0f, 0.0f, 1.0f, 0.5f), TEST_LOCATION);
1418   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uActorColor", actualActorColor));
1419   DALI_TEST_EQUALS(actualActorColor, Vector4(1.0f, 0.0f, 1.0f, 0.5f), TEST_LOCATION);
1420
1421   // Enable pre-multiplied alpha
1422   renderer.SetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, true);
1423
1424   application.SendNotification();
1425   application.Render();
1426
1427   value = renderer.GetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
1428   DALI_TEST_CHECK(value.Get(preMultipliedAlpha));
1429   DALI_TEST_CHECK(preMultipliedAlpha);
1430
1431   value = renderer.GetCurrentProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
1432   DALI_TEST_CHECK(value.Get(preMultipliedAlpha));
1433   DALI_TEST_CHECK(preMultipliedAlpha);
1434
1435   srcFactorRgb    = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
1436   destFactorRgb   = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
1437   srcFactorAlpha  = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
1438   destFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
1439
1440   DALI_TEST_EQUALS((int)BlendFactor::ONE, srcFactorRgb, TEST_LOCATION);
1441   DALI_TEST_EQUALS((int)BlendFactor::ONE_MINUS_SRC_ALPHA, destFactorRgb, TEST_LOCATION);
1442   DALI_TEST_EQUALS((int)BlendFactor::ONE, srcFactorAlpha, TEST_LOCATION);
1443   DALI_TEST_EQUALS((int)BlendFactor::ONE_MINUS_SRC_ALPHA, destFactorAlpha, TEST_LOCATION);
1444
1445   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uColor", actualValue));
1446   DALI_TEST_EQUALS(actualValue, Vector4(0.5f, 0.0f, 0.5f, 0.5f), TEST_LOCATION);
1447   // Note : uActorColor doesn't premultiplied.
1448   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uActorColor", actualActorColor));
1449   DALI_TEST_EQUALS(actualActorColor, Vector4(1.0f, 0.0f, 1.0f, 0.5f), TEST_LOCATION);
1450
1451   // Disable pre-multiplied alpha again
1452   renderer.SetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, false);
1453
1454   application.SendNotification();
1455   application.Render();
1456
1457   value = renderer.GetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
1458   DALI_TEST_CHECK(value.Get(preMultipliedAlpha));
1459   DALI_TEST_CHECK(!preMultipliedAlpha);
1460
1461   value = renderer.GetCurrentProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
1462   DALI_TEST_CHECK(value.Get(preMultipliedAlpha));
1463   DALI_TEST_CHECK(!preMultipliedAlpha);
1464
1465   srcFactorRgb    = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
1466   destFactorRgb   = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
1467   srcFactorAlpha  = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
1468   destFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
1469
1470   DALI_TEST_EQUALS((int)BlendFactor::SRC_ALPHA, srcFactorRgb, TEST_LOCATION);
1471   DALI_TEST_EQUALS((int)BlendFactor::ONE_MINUS_SRC_ALPHA, destFactorRgb, TEST_LOCATION);
1472   DALI_TEST_EQUALS((int)BlendFactor::ONE, srcFactorAlpha, TEST_LOCATION);
1473   DALI_TEST_EQUALS((int)BlendFactor::ONE_MINUS_SRC_ALPHA, destFactorAlpha, TEST_LOCATION);
1474
1475   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uColor", actualValue));
1476   DALI_TEST_EQUALS(actualValue, Vector4(1.0f, 0.0f, 1.0f, 0.5f), TEST_LOCATION);
1477   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uActorColor", actualActorColor));
1478   DALI_TEST_EQUALS(actualActorColor, Vector4(1.0f, 0.0f, 1.0f, 0.5f), TEST_LOCATION);
1479
1480   END_TEST;
1481 }
1482
1483 int UtcDaliRendererConstraint01(void)
1484 {
1485   TestApplication application;
1486
1487   tet_infoline("Test that a non-uniform renderer property can be constrained");
1488
1489   Shader   shader   = Shader::New("VertexSource", "FragmentSource");
1490   Geometry geometry = CreateQuadGeometry();
1491   Renderer renderer = Renderer::New(geometry, shader);
1492
1493   Actor actor = Actor::New();
1494   actor.AddRenderer(renderer);
1495   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1496   application.GetScene().Add(actor);
1497
1498   Vector4         initialColor = Color::WHITE;
1499   Property::Index colorIndex   = renderer.RegisterProperty("uFadeColor", initialColor);
1500
1501   application.SendNotification();
1502   application.Render(0);
1503   DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION);
1504
1505   // Apply constraint
1506   Constraint constraint = Constraint::New<Vector4>(renderer, colorIndex, TestConstraintNoBlue);
1507   constraint.Apply();
1508   application.SendNotification();
1509   application.Render(0);
1510
1511   // Expect no blue component in either buffer - yellow
1512   DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(colorIndex), Color::YELLOW, TEST_LOCATION);
1513   application.Render(0);
1514   DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(colorIndex), Color::YELLOW, TEST_LOCATION);
1515
1516   renderer.RemoveConstraints();
1517   renderer.SetProperty(colorIndex, Color::WHITE);
1518   application.SendNotification();
1519   application.Render(0);
1520   DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(colorIndex), Color::WHITE, TEST_LOCATION);
1521
1522   END_TEST;
1523 }
1524
1525 int UtcDaliRendererConstraint02(void)
1526 {
1527   TestApplication application;
1528
1529   tet_infoline("Test that a uniform map renderer property can be constrained");
1530
1531   Shader   shader   = Shader::New("VertexSource", "FragmentSource");
1532   Geometry geometry = CreateQuadGeometry();
1533   Renderer renderer = Renderer::New(geometry, shader);
1534
1535   Actor actor = Actor::New();
1536   actor.AddRenderer(renderer);
1537   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1538   application.GetScene().Add(actor);
1539   application.SendNotification();
1540   application.Render(0);
1541
1542   Vector4         initialColor = Color::WHITE;
1543   Property::Index colorIndex   = renderer.RegisterProperty("uFadeColor", initialColor);
1544
1545   TestGlAbstraction& gl = application.GetGlAbstraction();
1546
1547   application.SendNotification();
1548   application.Render(0);
1549
1550   Vector4 actualValue(Vector4::ZERO);
1551   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1552   DALI_TEST_EQUALS(actualValue, initialColor, TEST_LOCATION);
1553
1554   // Apply constraint
1555   Constraint constraint = Constraint::New<Vector4>(renderer, colorIndex, TestConstraintNoBlue);
1556   constraint.Apply();
1557   application.SendNotification();
1558   application.Render(0);
1559
1560   // Expect no blue component in either buffer - yellow
1561   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1562   DALI_TEST_EQUALS(actualValue, Color::YELLOW, TEST_LOCATION);
1563
1564   application.Render(0);
1565   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1566   DALI_TEST_EQUALS(actualValue, Color::YELLOW, TEST_LOCATION);
1567
1568   renderer.RemoveConstraints();
1569   renderer.SetProperty(colorIndex, Color::WHITE);
1570   application.SendNotification();
1571   application.Render(0);
1572
1573   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1574   DALI_TEST_EQUALS(actualValue, Color::WHITE, TEST_LOCATION);
1575
1576   END_TEST;
1577 }
1578
1579 int UtcDaliRendererAnimatedProperty01(void)
1580 {
1581   TestApplication application;
1582
1583   tet_infoline("Test that a non-uniform renderer property can be animated");
1584
1585   Shader   shader   = Shader::New("VertexSource", "FragmentSource");
1586   Geometry geometry = CreateQuadGeometry();
1587   Renderer renderer = Renderer::New(geometry, shader);
1588
1589   Actor actor = Actor::New();
1590   actor.AddRenderer(renderer);
1591   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1592   application.GetScene().Add(actor);
1593
1594   Vector4         initialColor = Color::WHITE;
1595   Property::Index colorIndex   = renderer.RegisterProperty("uFadeColor", initialColor);
1596
1597   application.SendNotification();
1598   application.Render(0);
1599   DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION);
1600
1601   Animation animation = Animation::New(1.0f);
1602   KeyFrames keyFrames = KeyFrames::New();
1603   keyFrames.Add(0.0f, initialColor);
1604   keyFrames.Add(1.0f, Color::TRANSPARENT);
1605   animation.AnimateBetween(Property(renderer, colorIndex), keyFrames);
1606   animation.Play();
1607
1608   application.SendNotification();
1609   application.Render(500);
1610
1611   DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(colorIndex), Color::WHITE * 0.5f, TEST_LOCATION);
1612
1613   application.Render(500);
1614
1615   DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(colorIndex), Color::TRANSPARENT, TEST_LOCATION);
1616
1617   END_TEST;
1618 }
1619
1620 int UtcDaliRendererAnimatedProperty02(void)
1621 {
1622   TestApplication application;
1623
1624   tet_infoline("Test that a uniform map renderer property can be animated");
1625
1626   Shader   shader   = Shader::New("VertexSource", "FragmentSource");
1627   Geometry geometry = CreateQuadGeometry();
1628   Renderer renderer = Renderer::New(geometry, shader);
1629
1630   Actor actor = Actor::New();
1631   actor.AddRenderer(renderer);
1632   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1633   application.GetScene().Add(actor);
1634   application.SendNotification();
1635   application.Render(0);
1636
1637   Vector4         initialColor = Color::WHITE;
1638   Property::Index colorIndex   = renderer.RegisterProperty("uFadeColor", initialColor);
1639
1640   TestGlAbstraction& gl = application.GetGlAbstraction();
1641
1642   application.SendNotification();
1643   application.Render(0);
1644
1645   Vector4 actualValue(Vector4::ZERO);
1646   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1647   DALI_TEST_EQUALS(actualValue, initialColor, TEST_LOCATION);
1648
1649   Animation animation = Animation::New(1.0f);
1650   KeyFrames keyFrames = KeyFrames::New();
1651   keyFrames.Add(0.0f, initialColor);
1652   keyFrames.Add(1.0f, Color::TRANSPARENT);
1653   animation.AnimateBetween(Property(renderer, colorIndex), keyFrames);
1654   animation.Play();
1655
1656   application.SendNotification();
1657   application.Render(500);
1658
1659   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1660   DALI_TEST_EQUALS(actualValue, Color::WHITE * 0.5f, TEST_LOCATION);
1661
1662   application.Render(500);
1663   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1664   DALI_TEST_EQUALS(actualValue, Color::TRANSPARENT, TEST_LOCATION);
1665
1666   END_TEST;
1667 }
1668
1669 int UtcDaliRendererUniformMapPrecendence01(void)
1670 {
1671   TestApplication application;
1672
1673   tet_infoline("Test the uniform map precedence is applied properly");
1674
1675   Texture image = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64);
1676
1677   Shader     shader     = Shader::New("VertexSource", "FragmentSource");
1678   TextureSet textureSet = CreateTextureSet(image);
1679
1680   Geometry geometry = CreateQuadGeometry();
1681   Renderer renderer = Renderer::New(geometry, shader);
1682   renderer.SetTextures(textureSet);
1683
1684   Actor actor = Actor::New();
1685   actor.AddRenderer(renderer);
1686   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1687   application.GetScene().Add(actor);
1688   application.SendNotification();
1689   application.Render(0);
1690
1691   renderer.RegisterProperty("uFadeColor", Color::RED);
1692   actor.RegisterProperty("uFadeColor", Color::GREEN);
1693   Property::Index shaderFadeColorIndex = shader.RegisterProperty("uFadeColor", Color::MAGENTA);
1694
1695   TestGlAbstraction& gl = application.GetGlAbstraction();
1696
1697   application.SendNotification();
1698   application.Render(0);
1699
1700   // Expect that the actor's fade color property is accessed
1701   Vector4 actualValue(Vector4::ZERO);
1702   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1703   DALI_TEST_EQUALS(actualValue, Color::GREEN, TEST_LOCATION);
1704
1705   // Animate shader's fade color property. Should be no change to uniform
1706   Animation animation = Animation::New(1.0f);
1707   KeyFrames keyFrames = KeyFrames::New();
1708   keyFrames.Add(0.0f, Color::WHITE);
1709   keyFrames.Add(1.0f, Color::TRANSPARENT);
1710   animation.AnimateBetween(Property(shader, shaderFadeColorIndex), keyFrames);
1711   animation.Play();
1712
1713   application.SendNotification();
1714   application.Render(500);
1715
1716   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1717   DALI_TEST_EQUALS(actualValue, Color::GREEN, TEST_LOCATION);
1718
1719   application.Render(500);
1720   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1721   DALI_TEST_EQUALS(actualValue, Color::GREEN, TEST_LOCATION);
1722
1723   END_TEST;
1724 }
1725
1726 int UtcDaliRendererUniformMapPrecendence02(void)
1727 {
1728   TestApplication application;
1729
1730   tet_infoline("Test the uniform map precedence is applied properly");
1731
1732   Texture image = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64);
1733
1734   Shader     shader     = Shader::New("VertexSource", "FragmentSource");
1735   TextureSet textureSet = CreateTextureSet(image);
1736
1737   Geometry geometry = CreateQuadGeometry();
1738   Renderer renderer = Renderer::New(geometry, shader);
1739   renderer.SetTextures(textureSet);
1740
1741   Actor actor = Actor::New();
1742   actor.AddRenderer(renderer);
1743   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1744   application.GetScene().Add(actor);
1745   application.SendNotification();
1746   application.Render(0);
1747
1748   // Don't add property / uniform map to renderer
1749   actor.RegisterProperty("uFadeColor", Color::GREEN);
1750   Property::Index shaderFadeColorIndex = shader.RegisterProperty("uFadeColor", Color::BLUE);
1751
1752   TestGlAbstraction& gl = application.GetGlAbstraction();
1753
1754   application.SendNotification();
1755   application.Render(0);
1756
1757   // Expect that the actor's fade color property is accessed
1758   Vector4 actualValue(Vector4::ZERO);
1759   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1760   DALI_TEST_EQUALS(actualValue, Color::GREEN, TEST_LOCATION);
1761
1762   // Animate texture set's fade color property. Should be no change to uniform
1763   Animation animation = Animation::New(1.0f);
1764   KeyFrames keyFrames = KeyFrames::New();
1765   keyFrames.Add(0.0f, Color::WHITE);
1766   keyFrames.Add(1.0f, Color::TRANSPARENT);
1767   animation.AnimateBetween(Property(shader, shaderFadeColorIndex), keyFrames);
1768   animation.Play();
1769
1770   application.SendNotification();
1771   application.Render(500);
1772
1773   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1774   DALI_TEST_EQUALS(actualValue, Color::GREEN, TEST_LOCATION);
1775
1776   application.Render(500);
1777   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1778   DALI_TEST_EQUALS(actualValue, Color::GREEN, TEST_LOCATION);
1779
1780   END_TEST;
1781 }
1782
1783 int UtcDaliRendererUniformMapPrecendence03(void)
1784 {
1785   TestApplication application;
1786
1787   tet_infoline("Test the uniform map precedence is applied properly");
1788
1789   Texture image = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64);
1790
1791   Shader     shader     = Shader::New("VertexSource", "FragmentSource");
1792   TextureSet textureSet = CreateTextureSet(image);
1793
1794   Geometry geometry = CreateQuadGeometry();
1795   Renderer renderer = Renderer::New(geometry, shader);
1796   renderer.SetTextures(textureSet);
1797
1798   Actor actor = Actor::New();
1799   actor.AddRenderer(renderer);
1800   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1801   application.GetScene().Add(actor);
1802   application.SendNotification();
1803   application.Render(0);
1804
1805   // Don't add property / uniform map to renderer or actor
1806   shader.RegisterProperty("uFadeColor", Color::BLACK);
1807
1808   TestGlAbstraction& gl = application.GetGlAbstraction();
1809
1810   application.SendNotification();
1811   application.Render(0);
1812
1813   // Expect that the shader's fade color property is accessed
1814   Vector4 actualValue(Vector4::ZERO);
1815   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1816   DALI_TEST_EQUALS(actualValue, Color::BLACK, TEST_LOCATION);
1817
1818   END_TEST;
1819 }
1820
1821 int UtcDaliRendererUniformMapMultipleUniforms01(void)
1822 {
1823   TestApplication application;
1824
1825   tet_infoline("Test the uniform maps are collected from all objects (same type)");
1826
1827   Texture image = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64);
1828
1829   Shader     shader     = Shader::New("VertexSource", "FragmentSource");
1830   TextureSet textureSet = CreateTextureSet(image);
1831
1832   Geometry geometry = CreateQuadGeometry();
1833   Renderer renderer = Renderer::New(geometry, shader);
1834   renderer.SetTextures(textureSet);
1835
1836   Actor actor = Actor::New();
1837   actor.AddRenderer(renderer);
1838   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1839   application.GetScene().Add(actor);
1840   application.SendNotification();
1841   application.Render(0);
1842
1843   renderer.RegisterProperty("uUniform1", Color::RED);
1844   actor.RegisterProperty("uUniform2", Color::GREEN);
1845   shader.RegisterProperty("uUniform3", Color::MAGENTA);
1846
1847   TestGlAbstraction& gl = application.GetGlAbstraction();
1848
1849   application.SendNotification();
1850   application.Render(0);
1851
1852   // Expect that each of the object's uniforms are set
1853   Vector4 uniform1Value(Vector4::ZERO);
1854   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uUniform1", uniform1Value));
1855   DALI_TEST_EQUALS(uniform1Value, Color::RED, TEST_LOCATION);
1856
1857   Vector4 uniform2Value(Vector4::ZERO);
1858   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uUniform2", uniform2Value));
1859   DALI_TEST_EQUALS(uniform2Value, Color::GREEN, TEST_LOCATION);
1860
1861   Vector4 uniform3Value(Vector4::ZERO);
1862   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uUniform3", uniform3Value));
1863   DALI_TEST_EQUALS(uniform3Value, Color::MAGENTA, TEST_LOCATION);
1864
1865   END_TEST;
1866 }
1867
1868 int UtcDaliRendererUniformMapMultipleUniforms02(void)
1869 {
1870   TestApplication application;
1871
1872   tet_infoline("Test the uniform maps are collected from all objects (different types)");
1873
1874   Texture image = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64);
1875
1876   Shader     shader     = Shader::New("VertexSource", "FragmentSource");
1877   TextureSet textureSet = CreateTextureSet(image);
1878
1879   Geometry geometry = CreateQuadGeometry();
1880   Renderer renderer = Renderer::New(geometry, shader);
1881   renderer.SetTextures(textureSet);
1882
1883   Actor actor = Actor::New();
1884   actor.AddRenderer(renderer);
1885   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1886   application.GetScene().Add(actor);
1887   application.SendNotification();
1888   application.Render(0);
1889
1890   Property::Value value1(Color::RED);
1891   renderer.RegisterProperty("uFadeColor", value1);
1892
1893   Property::Value value2(1.0f);
1894   actor.RegisterProperty("uFadeProgress", value2);
1895
1896   Property::Value value3(Matrix3::IDENTITY);
1897   shader.RegisterProperty("uANormalMatrix", value3);
1898
1899   TestGlAbstraction& gl = application.GetGlAbstraction();
1900
1901   application.SendNotification();
1902   application.Render(0);
1903
1904   // Expect that each of the object's uniforms are set
1905   Vector4 uniform1Value(Vector4::ZERO);
1906   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", uniform1Value));
1907   DALI_TEST_EQUALS(uniform1Value, value1.Get<Vector4>(), TEST_LOCATION);
1908
1909   float uniform2Value(0.0f);
1910   DALI_TEST_CHECK(gl.GetUniformValue<float>("uFadeProgress", uniform2Value));
1911   DALI_TEST_EQUALS(uniform2Value, value2.Get<float>(), TEST_LOCATION);
1912
1913   Matrix3 uniform3Value;
1914   DALI_TEST_CHECK(gl.GetUniformValue<Matrix3>("uANormalMatrix", uniform3Value));
1915   DALI_TEST_EQUALS(uniform3Value, value3.Get<Matrix3>(), TEST_LOCATION);
1916
1917   END_TEST;
1918 }
1919
1920 int UtcDaliRendererRenderOrder2DLayer(void)
1921 {
1922   TestApplication application;
1923   tet_infoline("Test the rendering order in a 2D layer is correct");
1924
1925   Shader   shader   = Shader::New("VertexSource", "FragmentSource");
1926   Geometry geometry = CreateQuadGeometry();
1927
1928   Actor root = application.GetScene().GetRootLayer();
1929
1930   Actor    actor0    = CreateActor(root, 0, TEST_LOCATION);
1931   Renderer renderer0 = CreateRenderer(actor0, geometry, shader, 0);
1932
1933   Actor    actor1    = CreateActor(root, 0, TEST_LOCATION);
1934   Renderer renderer1 = CreateRenderer(actor1, geometry, shader, 0);
1935
1936   Actor    actor2    = CreateActor(root, 0, TEST_LOCATION);
1937   Renderer renderer2 = CreateRenderer(actor2, geometry, shader, 0);
1938
1939   Actor    actor3    = CreateActor(root, 0, TEST_LOCATION);
1940   Renderer renderer3 = CreateRenderer(actor3, geometry, shader, 0);
1941
1942   application.SendNotification();
1943   application.Render(0);
1944
1945   /*
1946    * Create the following hierarchy:
1947    *
1948    *            actor2
1949    *              /
1950    *             /
1951    *          actor1
1952    *           /
1953    *          /
1954    *       actor0
1955    *        /
1956    *       /
1957    *    actor3
1958    *
1959    *  Expected rendering order : actor2 - actor1 - actor0 - actor3
1960    */
1961   actor2.Add(actor1);
1962   actor1.Add(actor0);
1963   actor0.Add(actor3);
1964   application.SendNotification();
1965   application.Render(0);
1966
1967   TestGlAbstraction& gl = application.GetGlAbstraction();
1968   gl.GetTextureTrace().Reset();
1969   gl.EnableTextureCallTrace(true);
1970   application.SendNotification();
1971   application.Render(0);
1972
1973   int textureBindIndex[4];
1974   for(unsigned int i(0); i < 4; ++i)
1975   {
1976     std::stringstream params;
1977     params << std::hex << GL_TEXTURE_2D << std::dec << ", " << i + 1;
1978     textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str());
1979   }
1980
1981   //Check that actor1 has been rendered after actor2
1982   DALI_TEST_GREATER(textureBindIndex[1], textureBindIndex[2], TEST_LOCATION);
1983
1984   //Check that actor0 has been rendered after actor1
1985   DALI_TEST_GREATER(textureBindIndex[0], textureBindIndex[1], TEST_LOCATION);
1986
1987   //Check that actor3 has been rendered after actor0
1988   DALI_TEST_GREATER(textureBindIndex[3], textureBindIndex[0], TEST_LOCATION);
1989
1990   END_TEST;
1991 }
1992
1993 int UtcDaliRendererRenderOrder2DLayerMultipleRenderers(void)
1994 {
1995   TestApplication application;
1996   tet_infoline("Test the rendering order in a 2D layer is correct using multiple renderers per actor");
1997
1998   /*
1999    * Creates the following hierarchy:
2000    *
2001    *             actor0------------------------>actor1
2002    *            /   |   \                    /   |   \
2003    *          /     |     \                /     |     \
2004    *        /       |       \            /       |       \
2005    * renderer0 renderer1 renderer2 renderer3 renderer4 renderer5
2006    *
2007    *  renderer0 has depth index 2
2008    *  renderer1 has depth index 0
2009    *  renderer2 has depth index 1
2010    *
2011    *  renderer3 has depth index 1
2012    *  renderer4 has depth index 0
2013    *  renderer5 has depth index -1
2014    *
2015    *  Expected rendering order: renderer1 - renderer2 - renderer0 - renderer5 - renderer4 - renderer3
2016    */
2017
2018   Shader   shader   = Shader::New("VertexSource", "FragmentSource");
2019   Geometry geometry = CreateQuadGeometry();
2020
2021   Actor root = application.GetScene().GetRootLayer();
2022
2023   Actor    actor0    = CreateActor(root, 0, TEST_LOCATION);
2024   Actor    actor1    = CreateActor(actor0, 0, TEST_LOCATION);
2025   Renderer renderer0 = CreateRenderer(actor0, geometry, shader, 2);
2026   Renderer renderer1 = CreateRenderer(actor0, geometry, shader, 0);
2027   Renderer renderer2 = CreateRenderer(actor0, geometry, shader, 1);
2028   Renderer renderer3 = CreateRenderer(actor1, geometry, shader, 1);
2029   Renderer renderer4 = CreateRenderer(actor1, geometry, shader, 0);
2030   Renderer renderer5 = CreateRenderer(actor1, geometry, shader, -1);
2031
2032   application.SendNotification();
2033   application.Render(0);
2034
2035   TestGlAbstraction& gl = application.GetGlAbstraction();
2036   gl.GetTextureTrace().Reset();
2037   gl.EnableTextureCallTrace(true);
2038   application.SendNotification();
2039   application.Render(0);
2040
2041   int textureBindIndex[6];
2042   for(unsigned int i(0); i < 6; ++i)
2043   {
2044     std::stringstream params;
2045     params << std::hex << GL_TEXTURE_2D << std::dec << ", " << i + 1;
2046     textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str());
2047   }
2048
2049   //Check that renderer3 has been rendered after renderer4
2050   DALI_TEST_GREATER(textureBindIndex[3], textureBindIndex[4], TEST_LOCATION);
2051
2052   //Check that renderer0 has been rendered after renderer2
2053   DALI_TEST_GREATER(textureBindIndex[4], textureBindIndex[5], TEST_LOCATION);
2054
2055   //Check that renderer5 has been rendered after renderer2
2056   DALI_TEST_GREATER(textureBindIndex[5], textureBindIndex[0], TEST_LOCATION);
2057
2058   //Check that renderer0 has been rendered after renderer2
2059   DALI_TEST_GREATER(textureBindIndex[0], textureBindIndex[2], TEST_LOCATION);
2060
2061   //Check that renderer2 has been rendered after renderer1
2062   DALI_TEST_GREATER(textureBindIndex[2], textureBindIndex[1], TEST_LOCATION);
2063
2064   END_TEST;
2065 }
2066
2067 int UtcDaliRendererRenderOrder2DLayerSiblingOrder(void)
2068 {
2069   TestApplication application;
2070   tet_infoline("Test the rendering order in a 2D layer is correct using sibling order");
2071
2072   /*
2073    * Creates the following hierarchy:
2074    *
2075    *                            Layer
2076    *                           /    \
2077    *                         /        \
2078    *                       /            \
2079    *                     /                \
2080    *                   /                    \
2081    *             actor0 (SIBLING_ORDER:1)     actor1 (SIBLING_ORDER:0)
2082    *            /   |   \                    /   |   \
2083    *          /     |     \                /     |     \
2084    *        /       |       \            /       |       \
2085    * renderer0 renderer1  actor2     renderer2 renderer3 renderer4
2086    *    DI:2      DI:0      |           DI:0      DI:1      DI:2
2087    *                        |
2088    *                   renderer5
2089    *                      DI:-1
2090    *
2091    *  actor0 has sibling order 1
2092    *  actor1 has sibling order 0
2093    *  actor2 has sibling order 0
2094    *
2095    *  renderer0 has depth index 2
2096    *  renderer1 has depth index 0
2097    *
2098    *  renderer2 has depth index 0
2099    *  renderer3 has depth index 1
2100    *  renderer4 has depth index 2
2101    *
2102    *  renderer5 has depth index -1
2103    *
2104    *  Expected rendering order: renderer2 - renderer3 - renderer4 - renderer1 - renderer0 - renderer5
2105    */
2106
2107   Shader   shader   = Shader::New("VertexSource", "FragmentSource");
2108   Geometry geometry = CreateQuadGeometry();
2109   Actor    root     = application.GetScene().GetRootLayer();
2110   Actor    actor0   = CreateActor(root, 1, TEST_LOCATION);
2111   Actor    actor1   = CreateActor(root, 0, TEST_LOCATION);
2112   Actor    actor2   = CreateActor(actor0, 0, TEST_LOCATION);
2113
2114   Renderer renderer0 = CreateRenderer(actor0, geometry, shader, 2);
2115   Renderer renderer1 = CreateRenderer(actor0, geometry, shader, 0);
2116   Renderer renderer2 = CreateRenderer(actor1, geometry, shader, 0);
2117   Renderer renderer3 = CreateRenderer(actor1, geometry, shader, 1);
2118   Renderer renderer4 = CreateRenderer(actor1, geometry, shader, 2);
2119   Renderer renderer5 = CreateRenderer(actor2, geometry, shader, -1);
2120
2121   application.SendNotification();
2122   application.Render();
2123
2124   TestGlAbstraction& gl = application.GetGlAbstraction();
2125   gl.GetTextureTrace().Reset();
2126   gl.EnableTextureCallTrace(true);
2127   application.SendNotification();
2128   application.Render(0);
2129
2130   int textureBindIndex[6];
2131   for(unsigned int i(0); i < 6; ++i)
2132   {
2133     std::stringstream params;
2134     params << std::hex << GL_TEXTURE_2D << std::dec << ", " << i + 1;
2135     textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str());
2136   }
2137
2138   DALI_TEST_EQUALS(textureBindIndex[2], 0, TEST_LOCATION);
2139   DALI_TEST_EQUALS(textureBindIndex[3], 1, TEST_LOCATION);
2140   DALI_TEST_EQUALS(textureBindIndex[4], 2, TEST_LOCATION);
2141   DALI_TEST_EQUALS(textureBindIndex[1], 3, TEST_LOCATION);
2142   DALI_TEST_EQUALS(textureBindIndex[0], 4, TEST_LOCATION);
2143   DALI_TEST_EQUALS(textureBindIndex[5], 5, TEST_LOCATION);
2144
2145   // Change sibling order of actor1
2146   // New Expected rendering order: renderer1 - renderer0 - renderer 5 - renderer2 - renderer3 - renderer4
2147   actor1.SetProperty(Dali::DevelActor::Property::SIBLING_ORDER, 2);
2148
2149   gl.GetTextureTrace().Reset();
2150   application.SendNotification();
2151   application.Render(0);
2152
2153   for(unsigned int i(0); i < 6; ++i)
2154   {
2155     std::stringstream params;
2156     params << std::hex << GL_TEXTURE_2D << std::dec << ", " << i + 1;
2157     textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str());
2158   }
2159
2160   DALI_TEST_EQUALS(textureBindIndex[1], 0, TEST_LOCATION);
2161   DALI_TEST_EQUALS(textureBindIndex[0], 1, TEST_LOCATION);
2162   DALI_TEST_EQUALS(textureBindIndex[5], 2, TEST_LOCATION);
2163   DALI_TEST_EQUALS(textureBindIndex[2], 3, TEST_LOCATION);
2164   DALI_TEST_EQUALS(textureBindIndex[3], 4, TEST_LOCATION);
2165   DALI_TEST_EQUALS(textureBindIndex[4], 5, TEST_LOCATION);
2166
2167   END_TEST;
2168 }
2169
2170 int UtcDaliRendererRenderOrder2DLayerOverlay(void)
2171 {
2172   TestApplication application;
2173   tet_infoline("Test the rendering order in a 2D layer is correct for overlays");
2174
2175   Shader   shader   = Shader::New("VertexSource", "FragmentSource");
2176   Geometry geometry = CreateQuadGeometry();
2177   Actor    root     = application.GetScene().GetRootLayer();
2178
2179   /*
2180    * Create the following hierarchy:
2181    *
2182    *               actor2
2183    *             (Regular actor)
2184    *              /      \
2185    *             /        \
2186    *         actor1       actor4
2187    *       (Overlay)     (Regular actor)
2188    *          /
2189    *         /
2190    *     actor0
2191    *    (Overlay)
2192    *      /
2193    *     /
2194    *  actor3
2195    * (Overlay)
2196    *
2197    *  Expected rendering order : actor2 - actor4 - actor1 - actor0 - actor3
2198    */
2199
2200   Actor actor0 = CreateActor(root, 0, TEST_LOCATION);
2201   actor0.SetProperty(Actor::Property::DRAW_MODE, DrawMode::OVERLAY_2D);
2202   Renderer renderer0 = CreateRenderer(actor0, geometry, shader, 0);
2203
2204   Actor actor1 = CreateActor(root, 0, TEST_LOCATION);
2205   actor1.SetProperty(Actor::Property::DRAW_MODE, DrawMode::OVERLAY_2D);
2206   Renderer renderer1 = CreateRenderer(actor1, geometry, shader, 0);
2207
2208   Actor    actor2    = CreateActor(root, 0, TEST_LOCATION);
2209   Renderer renderer2 = CreateRenderer(actor2, geometry, shader, 0);
2210
2211   Actor actor3 = CreateActor(root, 0, TEST_LOCATION);
2212   actor3.SetProperty(Actor::Property::DRAW_MODE, DrawMode::OVERLAY_2D);
2213   Renderer renderer3 = CreateRenderer(actor3, geometry, shader, 0);
2214
2215   Actor    actor4    = CreateActor(root, 0, TEST_LOCATION);
2216   Renderer renderer4 = CreateRenderer(actor4, geometry, shader, 0);
2217
2218   application.SendNotification();
2219   application.Render(0);
2220
2221   actor2.Add(actor1);
2222   actor2.Add(actor4);
2223   actor1.Add(actor0);
2224   actor0.Add(actor3);
2225
2226   TestGlAbstraction& gl = application.GetGlAbstraction();
2227   gl.GetTextureTrace().Reset();
2228   gl.EnableTextureCallTrace(true);
2229   application.SendNotification();
2230   application.Render(0);
2231
2232   int textureBindIndex[5];
2233   for(unsigned int i(0); i < 5; ++i)
2234   {
2235     std::stringstream params;
2236     params << std::hex << GL_TEXTURE_2D << std::dec << ", " << i + 1;
2237     textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str());
2238   }
2239
2240   //Check that actor4 has been rendered after actor2
2241   DALI_TEST_GREATER(textureBindIndex[4], textureBindIndex[2], TEST_LOCATION);
2242
2243   //Check that actor1 has been rendered after actor4
2244   DALI_TEST_GREATER(textureBindIndex[1], textureBindIndex[4], TEST_LOCATION);
2245
2246   //Check that actor0 has been rendered after actor1
2247   DALI_TEST_GREATER(textureBindIndex[0], textureBindIndex[1], TEST_LOCATION);
2248
2249   //Check that actor3 has been rendered after actor0
2250   DALI_TEST_GREATER(textureBindIndex[3], textureBindIndex[0], TEST_LOCATION);
2251
2252   END_TEST;
2253 }
2254
2255 int UtcDaliRendererSetIndexRange(void)
2256 {
2257   std::string
2258     vertexShader(
2259       "attribute vec2 aPosition;\n"
2260       "void main()\n"
2261       "{\n"
2262       "  gl_Position = aPosition;\n"
2263       "}"),
2264     fragmentShader(
2265       "void main()\n"
2266       "{\n"
2267       "  gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0)\n"
2268       "}\n");
2269
2270   TestApplication application;
2271   tet_infoline("Test setting the range of indices to draw");
2272
2273   TestGlAbstraction& gl = application.GetGlAbstraction();
2274   gl.EnableDrawCallTrace(true);
2275
2276   Actor actor = Actor::New();
2277   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2278
2279   // create geometry
2280   Geometry geometry = Geometry::New();
2281   geometry.SetType(Geometry::LINE_LOOP);
2282
2283   // --------------------------------------------------------------------------
2284   // index buffer
2285   unsigned short indices[] = {0, 2, 4, 6, 8, // offset = 0, count = 5
2286                               0,
2287                               1,
2288                               2,
2289                               3,
2290                               4,
2291                               5,
2292                               6,
2293                               7,
2294                               8,
2295                               9, // offset = 5, count = 10
2296                               1,
2297                               3,
2298                               5,
2299                               7,
2300                               9,
2301                               1}; // offset = 15,  count = 6 // line strip
2302
2303   // --------------------------------------------------------------------------
2304   // vertex buffer
2305   struct Vertex
2306   {
2307     Vector2 position;
2308   };
2309   Vertex shapes[] =
2310     {
2311       // pentagon                   // star
2312       {Vector2(0.0f, 1.00f)},
2313       {Vector2(0.0f, -1.00f)},
2314       {Vector2(-0.95f, 0.31f)},
2315       {Vector2(0.59f, 0.81f)},
2316       {Vector2(-0.59f, -0.81f)},
2317       {Vector2(-0.95f, -0.31f)},
2318       {Vector2(0.59f, -0.81f)},
2319       {Vector2(0.95f, -0.31f)},
2320       {Vector2(0.95f, 0.31f)},
2321       {Vector2(-0.59f, 0.81f)},
2322     };
2323   Property::Map vertexFormat;
2324   vertexFormat["aPosition"] = Property::VECTOR2;
2325   VertexBuffer vertexBuffer = VertexBuffer::New(vertexFormat);
2326   vertexBuffer.SetData(shapes, sizeof(shapes) / sizeof(shapes[0]));
2327
2328   // --------------------------------------------------------------------------
2329   geometry.SetIndexBuffer(indices, sizeof(indices) / sizeof(indices[0]));
2330   geometry.AddVertexBuffer(vertexBuffer);
2331
2332   // create shader
2333   Shader   shader   = Shader::New(vertexShader, fragmentShader);
2334   Renderer renderer = Renderer::New(geometry, shader);
2335   actor.AddRenderer(renderer);
2336
2337   Integration::Scene scene = application.GetScene();
2338   scene.Add(actor);
2339
2340   char buffer[128];
2341
2342   // LINE_LOOP, first 0, count 5
2343   {
2344     renderer.SetIndexRange(0, 5);
2345     application.SendNotification();
2346     application.Render();
2347
2348     Property::Value value = renderer.GetProperty(Renderer::Property::INDEX_RANGE_FIRST);
2349     int             convertedValue;
2350     DALI_TEST_CHECK(value.Get(convertedValue));
2351     DALI_TEST_CHECK(convertedValue == 0);
2352
2353     value = renderer.GetCurrentProperty(Renderer::Property::INDEX_RANGE_FIRST);
2354     DALI_TEST_CHECK(value.Get(convertedValue));
2355     DALI_TEST_CHECK(convertedValue == 0);
2356
2357     value = renderer.GetProperty(Renderer::Property::INDEX_RANGE_COUNT);
2358     DALI_TEST_CHECK(value.Get(convertedValue));
2359     DALI_TEST_CHECK(convertedValue == 5);
2360
2361     value = renderer.GetCurrentProperty(Renderer::Property::INDEX_RANGE_COUNT);
2362     DALI_TEST_CHECK(value.Get(convertedValue));
2363     DALI_TEST_CHECK(convertedValue == 5);
2364
2365     sprintf(buffer, "%u, 5, %u, indices", GL_LINE_LOOP, GL_UNSIGNED_SHORT);
2366     bool result = gl.GetDrawTrace().FindMethodAndParams("DrawElements", buffer);
2367     DALI_TEST_CHECK(result);
2368   }
2369
2370   // LINE_LOOP, first 5, count 10
2371   {
2372     renderer.SetIndexRange(5, 10);
2373     sprintf(buffer, "%u, 10, %u, indices", GL_LINE_LOOP, GL_UNSIGNED_SHORT);
2374     application.SendNotification();
2375     application.Render();
2376     bool result = gl.GetDrawTrace().FindMethodAndParams("DrawElements", buffer);
2377     DALI_TEST_CHECK(result);
2378   }
2379
2380   // LINE_STRIP, first 15, count 6
2381   {
2382     renderer.SetIndexRange(15, 6);
2383     geometry.SetType(Geometry::LINE_STRIP);
2384     sprintf(buffer, "%u, 6, %u, indices", GL_LINE_STRIP, GL_UNSIGNED_SHORT);
2385     application.SendNotification();
2386     application.Render();
2387     bool result = gl.GetDrawTrace().FindMethodAndParams("DrawElements", buffer);
2388     DALI_TEST_CHECK(result);
2389   }
2390
2391   // Index out of bounds
2392   {
2393     renderer.SetIndexRange(15, 30);
2394     geometry.SetType(Geometry::LINE_STRIP);
2395     sprintf(buffer, "%u, 6, %u, indices", GL_LINE_STRIP, GL_UNSIGNED_SHORT);
2396     application.SendNotification();
2397     application.Render();
2398     bool result = gl.GetDrawTrace().FindMethodAndParams("DrawElements", buffer);
2399     DALI_TEST_CHECK(result);
2400   }
2401
2402   // drawing whole buffer starting from 15 ( last valid primitive )
2403   {
2404     renderer.SetIndexRange(15, 0);
2405     geometry.SetType(Geometry::LINE_STRIP);
2406     sprintf(buffer, "%u, 6, %u, indices", GL_LINE_STRIP, GL_UNSIGNED_SHORT);
2407     application.SendNotification();
2408     application.Render();
2409     bool result = gl.GetDrawTrace().FindMethodAndParams("DrawElements", buffer);
2410     DALI_TEST_CHECK(result);
2411   }
2412
2413   END_TEST;
2414 }
2415
2416 int UtcDaliRendererSetDepthFunction(void)
2417 {
2418   TestApplication application;
2419
2420   tet_infoline("Test setting the depth function");
2421
2422   Geometry geometry = CreateQuadGeometry();
2423   Shader   shader   = CreateShader();
2424   Renderer renderer = Renderer::New(geometry, shader);
2425
2426   Actor actor = Actor::New();
2427   actor.AddRenderer(renderer);
2428   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
2429   Integration::Scene scene = application.GetScene();
2430   scene.GetRootLayer().SetProperty(Layer::Property::BEHAVIOR, Layer::LAYER_3D);
2431   scene.Add(actor);
2432
2433   TestGlAbstraction& glAbstraction        = application.GetGlAbstraction();
2434   TraceCallStack&    glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2435   TraceCallStack&    glDepthFunctionStack = glAbstraction.GetDepthFunctionTrace();
2436
2437   glEnableDisableStack.Enable(true);
2438   glDepthFunctionStack.Enable(true);
2439   glEnableDisableStack.EnableLogging(true);
2440   glDepthFunctionStack.EnableLogging(true);
2441
2442   std::ostringstream depthTestStr;
2443   depthTestStr << std::hex << GL_DEPTH_TEST;
2444
2445   //GL_NEVER
2446   {
2447     renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::NEVER);
2448
2449     glEnableDisableStack.Reset();
2450     glDepthFunctionStack.Reset();
2451     application.SendNotification();
2452     application.Render();
2453
2454     DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Enable", depthTestStr.str().c_str()));
2455     std::ostringstream depthFunctionStr;
2456     depthFunctionStr << std::hex << GL_NEVER;
2457     DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2458   }
2459
2460   //GL_ALWAYS
2461   {
2462     renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::ALWAYS);
2463
2464     glDepthFunctionStack.Reset();
2465     application.SendNotification();
2466     application.Render();
2467
2468     std::ostringstream depthFunctionStr;
2469     depthFunctionStr << std::hex << GL_ALWAYS;
2470     DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2471   }
2472
2473   //GL_LESS
2474   {
2475     renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::LESS);
2476
2477     glDepthFunctionStack.Reset();
2478     application.SendNotification();
2479     application.Render();
2480
2481     std::ostringstream depthFunctionStr;
2482     depthFunctionStr << std::hex << GL_LESS;
2483     DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2484   }
2485
2486   //GL_GREATER
2487   {
2488     renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::GREATER);
2489
2490     glDepthFunctionStack.Reset();
2491     application.SendNotification();
2492     application.Render();
2493
2494     std::ostringstream depthFunctionStr;
2495     depthFunctionStr << std::hex << GL_GREATER;
2496     DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2497   }
2498
2499   //GL_EQUAL
2500   {
2501     renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::EQUAL);
2502
2503     glDepthFunctionStack.Reset();
2504     application.SendNotification();
2505     application.Render();
2506
2507     std::ostringstream depthFunctionStr;
2508     depthFunctionStr << std::hex << GL_EQUAL;
2509     DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2510   }
2511
2512   //GL_NOTEQUAL
2513   {
2514     renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::NOT_EQUAL);
2515
2516     glDepthFunctionStack.Reset();
2517     application.SendNotification();
2518     application.Render();
2519
2520     std::ostringstream depthFunctionStr;
2521     depthFunctionStr << std::hex << GL_NOTEQUAL;
2522     DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2523   }
2524
2525   //GL_LEQUAL
2526   {
2527     renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::LESS_EQUAL);
2528
2529     glDepthFunctionStack.Reset();
2530     application.SendNotification();
2531     application.Render();
2532
2533     std::ostringstream depthFunctionStr;
2534     depthFunctionStr << std::hex << GL_LEQUAL;
2535     DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2536   }
2537
2538   //GL_GEQUAL
2539   {
2540     renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::GREATER_EQUAL);
2541
2542     glDepthFunctionStack.Reset();
2543     application.SendNotification();
2544     application.Render();
2545
2546     std::ostringstream depthFunctionStr;
2547     depthFunctionStr << std::hex << GL_GEQUAL;
2548     DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2549   }
2550
2551   END_TEST;
2552 }
2553
2554 /**
2555  * @brief This templatized function checks an enumeration property is setting and getting correctly.
2556  * The checks performed are as follows:
2557  *  - Check the initial/default value.
2558  *  - Set a different value via enum.
2559  *  - Check it was set.
2560  *  - Set a different value via string.
2561  *  - Check it was set.
2562  */
2563 template<typename T>
2564 void CheckEnumerationProperty(TestApplication& application, Renderer& renderer, Property::Index propertyIndex, T initialValue, T firstCheckEnumeration, T secondCheckEnumeration, std::string secondCheckString)
2565 {
2566   application.SendNotification();
2567   application.Render();
2568
2569   DALI_TEST_CHECK(renderer.GetProperty<int>(propertyIndex) == static_cast<int>(initialValue));
2570   DALI_TEST_CHECK(renderer.GetCurrentProperty<int>(propertyIndex) == static_cast<int>(initialValue));
2571   renderer.SetProperty(propertyIndex, firstCheckEnumeration);
2572   DALI_TEST_CHECK(renderer.GetProperty<int>(propertyIndex) == static_cast<int>(firstCheckEnumeration));
2573   DALI_TEST_CHECK(renderer.GetCurrentProperty<int>(propertyIndex) != static_cast<int>(firstCheckEnumeration));
2574
2575   application.SendNotification();
2576   application.Render();
2577
2578   DALI_TEST_CHECK(renderer.GetProperty<int>(propertyIndex) == static_cast<int>(firstCheckEnumeration));
2579   DALI_TEST_CHECK(renderer.GetCurrentProperty<int>(propertyIndex) == static_cast<int>(firstCheckEnumeration));
2580
2581   renderer.SetProperty(propertyIndex, secondCheckString);
2582   DALI_TEST_CHECK(renderer.GetProperty<int>(propertyIndex) == static_cast<int>(secondCheckEnumeration));
2583   DALI_TEST_CHECK(renderer.GetCurrentProperty<int>(propertyIndex) != static_cast<int>(secondCheckEnumeration));
2584
2585   application.SendNotification();
2586   application.Render();
2587
2588   DALI_TEST_CHECK(renderer.GetProperty<int>(propertyIndex) == static_cast<int>(secondCheckEnumeration));
2589   DALI_TEST_CHECK(renderer.GetCurrentProperty<int>(propertyIndex) == static_cast<int>(secondCheckEnumeration));
2590 }
2591
2592 int UtcDaliRendererEnumProperties(void)
2593 {
2594   TestApplication application;
2595   tet_infoline("Test Renderer enumeration properties can be set with both integer and string values");
2596
2597   Geometry geometry = CreateQuadGeometry();
2598   Shader   shader   = CreateShader();
2599   Renderer renderer = Renderer::New(geometry, shader);
2600
2601   Actor actor = Actor::New();
2602   actor.AddRenderer(renderer);
2603   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
2604   application.GetScene().Add(actor);
2605
2606   /*
2607    * Here we use a templatized function to perform several checks on each enumeration property.
2608    * @see CheckEnumerationProperty for details of the checks performed.
2609    */
2610
2611   CheckEnumerationProperty<FaceCullingMode::Type>(application, renderer, Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::NONE, FaceCullingMode::FRONT, FaceCullingMode::BACK, "BACK");
2612   CheckEnumerationProperty<BlendMode::Type>(application, renderer, Renderer::Property::BLEND_MODE, BlendMode::AUTO, BlendMode::OFF, BlendMode::ON, "ON");
2613   CheckEnumerationProperty<BlendEquation::Type>(application, renderer, Renderer::Property::BLEND_EQUATION_RGB, BlendEquation::ADD, BlendEquation::SUBTRACT, BlendEquation::REVERSE_SUBTRACT, "REVERSE_SUBTRACT");
2614   CheckEnumerationProperty<BlendEquation::Type>(application, renderer, Renderer::Property::BLEND_EQUATION_ALPHA, BlendEquation::ADD, BlendEquation::SUBTRACT, BlendEquation::REVERSE_SUBTRACT, "REVERSE_SUBTRACT");
2615   CheckEnumerationProperty<BlendFactor::Type>(application, renderer, Renderer::Property::BLEND_FACTOR_SRC_RGB, BlendFactor::SRC_ALPHA, BlendFactor::ONE, BlendFactor::SRC_COLOR, "SRC_COLOR");
2616   CheckEnumerationProperty<BlendFactor::Type>(application, renderer, Renderer::Property::BLEND_FACTOR_DEST_RGB, BlendFactor::ONE_MINUS_SRC_ALPHA, BlendFactor::ONE, BlendFactor::SRC_COLOR, "SRC_COLOR");
2617   CheckEnumerationProperty<BlendFactor::Type>(application, renderer, Renderer::Property::BLEND_FACTOR_SRC_ALPHA, BlendFactor::ONE, BlendFactor::ONE_MINUS_SRC_ALPHA, BlendFactor::SRC_COLOR, "SRC_COLOR");
2618   CheckEnumerationProperty<BlendFactor::Type>(application, renderer, Renderer::Property::BLEND_FACTOR_DEST_ALPHA, BlendFactor::ONE_MINUS_SRC_ALPHA, BlendFactor::ONE, BlendFactor::SRC_COLOR, "SRC_COLOR");
2619   CheckEnumerationProperty<DepthWriteMode::Type>(application, renderer, Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::AUTO, DepthWriteMode::OFF, DepthWriteMode::ON, "ON");
2620   CheckEnumerationProperty<DepthFunction::Type>(application, renderer, Renderer::Property::DEPTH_FUNCTION, DepthFunction::LESS, DepthFunction::ALWAYS, DepthFunction::GREATER, "GREATER");
2621   CheckEnumerationProperty<DepthTestMode::Type>(application, renderer, Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::AUTO, DepthTestMode::OFF, DepthTestMode::ON, "ON");
2622   CheckEnumerationProperty<StencilFunction::Type>(application, renderer, Renderer::Property::STENCIL_FUNCTION, StencilFunction::ALWAYS, StencilFunction::LESS, StencilFunction::EQUAL, "EQUAL");
2623   CheckEnumerationProperty<RenderMode::Type>(application, renderer, Renderer::Property::RENDER_MODE, RenderMode::AUTO, RenderMode::NONE, RenderMode::STENCIL, "STENCIL");
2624   CheckEnumerationProperty<StencilOperation::Type>(application, renderer, Renderer::Property::STENCIL_OPERATION_ON_FAIL, StencilOperation::KEEP, StencilOperation::REPLACE, StencilOperation::INCREMENT, "INCREMENT");
2625   CheckEnumerationProperty<StencilOperation::Type>(application, renderer, Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, StencilOperation::KEEP, StencilOperation::REPLACE, StencilOperation::INCREMENT, "INCREMENT");
2626   CheckEnumerationProperty<StencilOperation::Type>(application, renderer, Renderer::Property::STENCIL_OPERATION_ON_Z_PASS, StencilOperation::KEEP, StencilOperation::REPLACE, StencilOperation::INCREMENT, "INCREMENT");
2627
2628   if(Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::MAX) &&
2629      Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::MIN))
2630   {
2631     application.SendNotification();
2632     application.Render();
2633     CheckEnumerationProperty<DevelBlendEquation::Type>(application, renderer, DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::REVERSE_SUBTRACT, DevelBlendEquation::MAX, DevelBlendEquation::MIN, "MIN");
2634   }
2635
2636   if(Dali::Capabilities::IsBlendEquationSupported(DevelBlendEquation::SCREEN))
2637   {
2638     application.SendNotification();
2639     application.Render();
2640     CheckEnumerationProperty<DevelBlendEquation::Type>(application, renderer, DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::MIN, DevelBlendEquation::MULTIPLY, DevelBlendEquation::SCREEN, "SCREEN");
2641   }
2642
2643   END_TEST;
2644 }
2645
2646 Renderer RendererTestFixture(TestApplication& application)
2647 {
2648   Geometry geometry = CreateQuadGeometry();
2649   Shader   shader   = CreateShader();
2650   Renderer renderer = Renderer::New(geometry, shader);
2651
2652   Actor actor = Actor::New();
2653   actor.AddRenderer(renderer);
2654   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
2655   Integration::Scene scene = application.GetScene();
2656   scene.GetRootLayer().SetProperty(Layer::Property::BEHAVIOR, Layer::LAYER_3D);
2657   scene.Add(actor);
2658
2659   return renderer;
2660 }
2661
2662 int UtcDaliRendererSetDepthTestMode(void)
2663 {
2664   TestApplication application;
2665   tet_infoline("Test setting the DepthTestMode");
2666
2667   Renderer           renderer             = RendererTestFixture(application);
2668   TestGlAbstraction& glAbstraction        = application.GetGlAbstraction();
2669   TraceCallStack&    glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2670   glEnableDisableStack.Enable(true);
2671   glEnableDisableStack.EnableLogging(true);
2672
2673   glEnableDisableStack.Reset();
2674   application.SendNotification();
2675   application.Render();
2676
2677   // Check depth-test is enabled by default.
2678   DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Enable", GetDepthTestString()));
2679   DALI_TEST_CHECK(!glEnableDisableStack.FindMethodAndParams("Disable", GetDepthTestString()));
2680
2681   // 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.
2682   renderer.SetProperty(Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::OFF);
2683   renderer.SetProperty(Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::OFF);
2684
2685   glEnableDisableStack.Reset();
2686   application.SendNotification();
2687   application.Render();
2688
2689   // Check the depth buffer was disabled.
2690   DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Disable", GetDepthTestString()));
2691
2692   // Turn on automatic mode depth-testing.
2693   // Layer behavior is currently set to LAYER_3D so AUTO should enable depth-testing.
2694   renderer.SetProperty(Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::AUTO);
2695
2696   glEnableDisableStack.Reset();
2697   application.SendNotification();
2698   application.Render();
2699
2700   // Check depth-test is now enabled.
2701   DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Enable", GetDepthTestString()));
2702   DALI_TEST_CHECK(!glEnableDisableStack.FindMethodAndParams("Disable", GetDepthTestString()));
2703
2704   // Change the layer behavior to LAYER_UI.
2705   // Note this will also disable depth testing for the layer by default, we test this first.
2706   application.GetScene().GetRootLayer().SetProperty(Layer::Property::BEHAVIOR, Layer::LAYER_UI);
2707
2708   glEnableDisableStack.Reset();
2709   application.SendNotification();
2710   application.Render();
2711
2712   // Check depth-test is disabled.
2713   DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Disable", GetDepthTestString()));
2714
2715   // Turn the layer depth-test flag back on, and confirm that depth testing is now on.
2716   application.GetScene().GetRootLayer().SetProperty(Layer::Property::DEPTH_TEST, true);
2717
2718   glEnableDisableStack.Reset();
2719   application.SendNotification();
2720   application.Render();
2721
2722   // Check depth-test is *still* disabled.
2723   DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Enable", GetDepthTestString()));
2724
2725   END_TEST;
2726 }
2727
2728 int UtcDaliRendererSetDepthWriteMode(void)
2729 {
2730   TestApplication application;
2731   tet_infoline("Test setting the DepthWriteMode");
2732
2733   Renderer           renderer      = RendererTestFixture(application);
2734   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2735
2736   application.SendNotification();
2737   application.Render();
2738
2739   // Check the default depth-write status first.
2740   DALI_TEST_CHECK(glAbstraction.GetLastDepthMask());
2741
2742   // Turn off depth-writing.
2743   renderer.SetProperty(Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::OFF);
2744
2745   application.SendNotification();
2746   application.Render();
2747
2748   // Check depth-write is now disabled.
2749   DALI_TEST_CHECK(!glAbstraction.GetLastDepthMask());
2750
2751   // Test the AUTO mode for depth-writing.
2752   // As our renderer is opaque, depth-testing should be enabled.
2753   renderer.SetProperty(Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::AUTO);
2754
2755   application.SendNotification();
2756   application.Render();
2757
2758   // Check depth-write is now enabled.
2759   DALI_TEST_CHECK(glAbstraction.GetLastDepthMask());
2760
2761   // Now make the renderer be treated as translucent by enabling blending.
2762   // The AUTO depth-write mode should turn depth-write off in this scenario.
2763   renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON);
2764
2765   application.SendNotification();
2766   application.Render();
2767
2768   // Check depth-write is now disabled.
2769   DALI_TEST_CHECK(!glAbstraction.GetLastDepthMask());
2770
2771   END_TEST;
2772 }
2773
2774 int UtcDaliRendererCheckStencilDefaults(void)
2775 {
2776   TestApplication application;
2777   tet_infoline("Test the stencil defaults");
2778
2779   Renderer           renderer               = RendererTestFixture(application);
2780   TestGlAbstraction& glAbstraction          = application.GetGlAbstraction();
2781   TraceCallStack&    glEnableDisableStack   = glAbstraction.GetEnableDisableTrace();
2782   TraceCallStack&    glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2783   glEnableDisableStack.Enable(true);
2784   glEnableDisableStack.EnableLogging(true);
2785   glStencilFunctionStack.Enable(true);
2786   glStencilFunctionStack.EnableLogging(true);
2787
2788   ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2789
2790   // Check the defaults:
2791   DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_FUNCTION).Get<int>()), static_cast<int>(StencilFunction::ALWAYS), TEST_LOCATION);
2792   DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_FUNCTION_MASK).Get<int>()), 0xFF, TEST_LOCATION);
2793   DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_FUNCTION_REFERENCE).Get<int>()), 0x00, TEST_LOCATION);
2794   DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_MASK).Get<int>()), 0xFF, TEST_LOCATION);
2795   DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_OPERATION_ON_FAIL).Get<int>()), static_cast<int>(StencilOperation::KEEP), TEST_LOCATION);
2796   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);
2797   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);
2798
2799   END_TEST;
2800 }
2801
2802 int UtcDaliRendererSetRenderModeToUseStencilBuffer(void)
2803 {
2804   TestApplication application;
2805   tet_infoline("Test setting the RenderMode to use the stencil buffer");
2806
2807   Renderer           renderer               = RendererTestFixture(application);
2808   TestGlAbstraction& glAbstraction          = application.GetGlAbstraction();
2809   TraceCallStack&    glEnableDisableStack   = glAbstraction.GetEnableDisableTrace();
2810   TraceCallStack&    glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2811   glEnableDisableStack.Enable(true);
2812   glEnableDisableStack.EnableLogging(true);
2813   glStencilFunctionStack.Enable(true);
2814   glStencilFunctionStack.EnableLogging(true);
2815
2816   // Set the StencilFunction to something other than the default, to confirm it is set as a property,
2817   // but NO GL call has been made while the RenderMode is set to not use the stencil buffer.
2818   renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::NONE);
2819   ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2820
2821   renderer.SetProperty(Renderer::Property::STENCIL_FUNCTION, StencilFunction::NEVER);
2822   DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_FUNCTION).Get<int>()), static_cast<int>(StencilFunction::NEVER), TEST_LOCATION);
2823
2824   ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2825   std::string methodString("StencilFunc");
2826   DALI_TEST_CHECK(!glStencilFunctionStack.FindMethod(methodString));
2827
2828   // Test the other RenderModes that will not enable the stencil buffer.
2829   renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::AUTO);
2830   ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2831   DALI_TEST_CHECK(!glStencilFunctionStack.FindMethod(methodString));
2832
2833   renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::COLOR);
2834   ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2835   DALI_TEST_CHECK(!glStencilFunctionStack.FindMethod(methodString));
2836
2837   // Now set the RenderMode to modes that will use the stencil buffer, and check the StencilFunction has changed.
2838   renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::STENCIL);
2839   ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2840
2841   DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Enable", GetStencilTestString()));
2842   DALI_TEST_CHECK(glStencilFunctionStack.FindMethod(methodString));
2843
2844   // Test the COLOR_STENCIL RenderMode as it also enables the stencil buffer.
2845   // First set a mode to turn off the stencil buffer, so the enable is required.
2846   renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::COLOR);
2847   ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2848   renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::COLOR_STENCIL);
2849   // Set a different stencil function as the last one is cached.
2850   renderer.SetProperty(Renderer::Property::STENCIL_FUNCTION, StencilFunction::ALWAYS);
2851   ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2852
2853   DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Enable", GetStencilTestString()));
2854   DALI_TEST_CHECK(glStencilFunctionStack.FindMethod(methodString));
2855
2856   END_TEST;
2857 }
2858
2859 // Helper function for the SetRenderModeToUseColorBuffer test.
2860 void CheckRenderModeColorMask(TestApplication& application, Renderer& renderer, RenderMode::Type renderMode, bool expectedValue)
2861 {
2862   // Set the RenderMode property to a value that should not allow color buffer writes.
2863   renderer.SetProperty(Renderer::Property::RENDER_MODE, renderMode);
2864   application.SendNotification();
2865   application.Render();
2866
2867   // Check if ColorMask has been called, and that the values are correct.
2868   TestGlAbstraction&                        glAbstraction = application.GetGlAbstraction();
2869   const TestGlAbstraction::ColorMaskParams& colorMaskParams(glAbstraction.GetColorMaskParams());
2870
2871   DALI_TEST_EQUALS<bool>(colorMaskParams.red, expectedValue, TEST_LOCATION);
2872   DALI_TEST_EQUALS<bool>(colorMaskParams.green, expectedValue, TEST_LOCATION);
2873   DALI_TEST_EQUALS<bool>(colorMaskParams.blue, expectedValue, TEST_LOCATION);
2874   // @todo Only check alpha if framebuffer supports it.
2875   //DALI_TEST_EQUALS<bool>(colorMaskParams.alpha, expectedValue, TEST_LOCATION);
2876 }
2877
2878 int UtcDaliRendererSetRenderModeToUseColorBuffer(void)
2879 {
2880   TestApplication application;
2881   tet_infoline("Test setting the RenderMode to use the color buffer");
2882
2883   Renderer renderer = RendererTestFixture(application);
2884
2885   // Set the RenderMode property to a value that should not allow color buffer writes.
2886   // Then check if ColorMask has been called, and that the values are correct.
2887   CheckRenderModeColorMask(application, renderer, RenderMode::AUTO, true);
2888   CheckRenderModeColorMask(application, renderer, RenderMode::NONE, false);
2889   CheckRenderModeColorMask(application, renderer, RenderMode::COLOR, true);
2890   CheckRenderModeColorMask(application, renderer, RenderMode::STENCIL, false);
2891   CheckRenderModeColorMask(application, renderer, RenderMode::COLOR_STENCIL, true);
2892
2893   END_TEST;
2894 }
2895
2896 int UtcDaliRendererSetStencilFunction(void)
2897 {
2898   TestApplication application;
2899   tet_infoline("Test setting the StencilFunction");
2900
2901   Renderer           renderer               = RendererTestFixture(application);
2902   TestGlAbstraction& glAbstraction          = application.GetGlAbstraction();
2903   TraceCallStack&    glEnableDisableStack   = glAbstraction.GetEnableDisableTrace();
2904   TraceCallStack&    glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2905   glEnableDisableStack.Enable(true);
2906   glEnableDisableStack.EnableLogging(true);
2907   glStencilFunctionStack.Enable(true);
2908   glStencilFunctionStack.EnableLogging(true);
2909
2910   // RenderMode must use the stencil for StencilFunction to operate.
2911   renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::STENCIL);
2912   ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2913
2914   /*
2915    * Lookup table for testing StencilFunction.
2916    * Note: This MUST be in the same order as the Dali::StencilFunction enum.
2917    */
2918   const int StencilFunctionLookupTable[] = {
2919     GL_NEVER,
2920     GL_LESS,
2921     GL_EQUAL,
2922     GL_LEQUAL,
2923     GL_GREATER,
2924     GL_NOTEQUAL,
2925     GL_GEQUAL,
2926     GL_ALWAYS};
2927   const int StencilFunctionLookupTableCount = sizeof(StencilFunctionLookupTable) / sizeof(StencilFunctionLookupTable[0]);
2928
2929   /*
2930    * Loop through all types of StencilFunction, checking:
2931    *  - The value is cached (set in event thread side)
2932    *  - Causes "glStencilFunc" to be called
2933    *  - Checks the correct parameters to "glStencilFunc" were used
2934    */
2935   std::string nonChangingParameters = "0, 255";
2936   std::string methodString("StencilFunc");
2937   for(int i = 0; i < StencilFunctionLookupTableCount; ++i)
2938   {
2939     // Set the property.
2940     renderer.SetProperty(Renderer::Property::STENCIL_FUNCTION, static_cast<Dali::StencilFunction::Type>(i));
2941
2942     // Check GetProperty returns the same value.
2943     DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_FUNCTION).Get<int>()), i, TEST_LOCATION);
2944
2945     // Reset the trace debug.
2946     ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2947
2948     // Check the function is called and the parameters are correct.
2949     std::stringstream parameterStream;
2950     parameterStream << StencilFunctionLookupTable[i] << ", " << nonChangingParameters;
2951
2952     DALI_TEST_CHECK(glStencilFunctionStack.FindMethodAndParams(methodString, parameterStream.str()));
2953   }
2954
2955   // Change the Function Reference only and check the behavior is correct:
2956   // 170 is 0xaa in hex / 10101010 in binary (every other bit set).
2957   int testValueReference = 170;
2958   renderer.SetProperty(Renderer::Property::STENCIL_FUNCTION_REFERENCE, testValueReference);
2959
2960   DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_FUNCTION_REFERENCE).Get<int>()), testValueReference, TEST_LOCATION);
2961
2962   ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2963
2964   DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetCurrentProperty(Renderer::Property::STENCIL_FUNCTION_REFERENCE).Get<int>()), testValueReference, TEST_LOCATION);
2965
2966   std::stringstream parameterStream;
2967   parameterStream << StencilFunctionLookupTable[StencilOperation::DECREMENT_WRAP] << ", " << testValueReference << ", 255";
2968
2969   DALI_TEST_CHECK(glStencilFunctionStack.FindMethodAndParams(methodString, parameterStream.str()));
2970
2971   // Change the Function Mask only and check the behavior is correct:
2972   // 85 is 0x55 in hex / 01010101 in binary (every other bit set).
2973   int testValueMask = 85;
2974   renderer.SetProperty(Renderer::Property::STENCIL_FUNCTION_MASK, testValueMask);
2975
2976   DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_FUNCTION_MASK).Get<int>()), testValueMask, TEST_LOCATION);
2977
2978   ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2979
2980   DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetCurrentProperty(Renderer::Property::STENCIL_FUNCTION_MASK).Get<int>()), testValueMask, TEST_LOCATION);
2981
2982   // Clear the stringstream.
2983   parameterStream.str(std::string());
2984   parameterStream << StencilFunctionLookupTable[StencilOperation::DECREMENT_WRAP] << ", " << testValueReference << ", " << testValueMask;
2985
2986   DALI_TEST_CHECK(glStencilFunctionStack.FindMethodAndParams(methodString, parameterStream.str()));
2987
2988   END_TEST;
2989 }
2990
2991 int UtcDaliRendererSetStencilOperation(void)
2992 {
2993   TestApplication application;
2994   tet_infoline("Test setting the StencilOperation");
2995
2996   Renderer           renderer               = RendererTestFixture(application);
2997   TestGlAbstraction& glAbstraction          = application.GetGlAbstraction();
2998   TraceCallStack&    glEnableDisableStack   = glAbstraction.GetEnableDisableTrace();
2999   TraceCallStack&    glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
3000   glEnableDisableStack.Enable(true);
3001   glEnableDisableStack.EnableLogging(true);
3002   glStencilFunctionStack.Enable(true);
3003   glStencilFunctionStack.EnableLogging(true);
3004
3005   // RenderMode must use the stencil for StencilOperation to operate.
3006   renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::STENCIL);
3007
3008   /*
3009    * Lookup table for testing StencilOperation.
3010    * Note: This MUST be in the same order as the Dali::StencilOperation enum.
3011    */
3012   const int StencilOperationLookupTable[] = {
3013     GL_ZERO,
3014     GL_KEEP,
3015     GL_REPLACE,
3016     GL_INCR,
3017     GL_DECR,
3018     GL_INVERT,
3019     GL_INCR_WRAP,
3020     GL_DECR_WRAP};
3021   const int StencilOperationLookupTableCount = sizeof(StencilOperationLookupTable) / sizeof(StencilOperationLookupTable[0]);
3022
3023   // Set all 3 StencilOperation properties to a default.
3024   renderer.SetProperty(Renderer::Property::STENCIL_OPERATION_ON_FAIL, StencilOperation::KEEP);
3025   renderer.SetProperty(Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, StencilOperation::ZERO);
3026   renderer.SetProperty(Renderer::Property::STENCIL_OPERATION_ON_Z_PASS, StencilOperation::ZERO);
3027
3028   // Set our expected parameter list to the equivalent result.
3029   int parameters[] = {StencilOperationLookupTable[StencilOperation::ZERO], StencilOperationLookupTable[StencilOperation::ZERO], StencilOperationLookupTable[StencilOperation::ZERO]};
3030
3031   ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
3032
3033   /*
3034    * Loop through all types of StencilOperation, checking:
3035    *  - The value is cached (set in event thread side)
3036    *  - Causes "glStencilFunc" to be called
3037    *  - Checks the correct parameters to "glStencilFunc" were used
3038    *  - Checks the above for all 3 parameter placements of StencilOperation ( OnFail, OnZFail, OnPass )
3039    */
3040   std::string methodString("StencilOp");
3041
3042   for(int i = 0; i < StencilOperationLookupTableCount; ++i)
3043   {
3044     for(int j = 0; j < StencilOperationLookupTableCount; ++j)
3045     {
3046       for(int k = 0; k < StencilOperationLookupTableCount; ++k)
3047       {
3048         // Set the property (outer loop causes all 3 different properties to be set separately).
3049         renderer.SetProperty(Renderer::Property::STENCIL_OPERATION_ON_FAIL, static_cast<Dali::StencilFunction::Type>(i));
3050         renderer.SetProperty(Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, static_cast<Dali::StencilFunction::Type>(j));
3051         renderer.SetProperty(Renderer::Property::STENCIL_OPERATION_ON_Z_PASS, static_cast<Dali::StencilFunction::Type>(k));
3052
3053         // Check GetProperty returns the same value.
3054         DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_OPERATION_ON_FAIL).Get<int>()), i, TEST_LOCATION);
3055         DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL).Get<int>()), j, TEST_LOCATION);
3056         DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_OPERATION_ON_Z_PASS).Get<int>()), k, TEST_LOCATION);
3057
3058         // Reset the trace debug.
3059         ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
3060
3061         // Check the function is called and the parameters are correct.
3062         // Set the expected parameter value at its correct index (only)
3063         parameters[0u] = StencilOperationLookupTable[i];
3064         parameters[1u] = StencilOperationLookupTable[j];
3065         parameters[2u] = StencilOperationLookupTable[k];
3066
3067         // Build the parameter list.
3068         std::stringstream parameterStream;
3069         for(int parameterBuild = 0; parameterBuild < 3; ++parameterBuild)
3070         {
3071           parameterStream << parameters[parameterBuild];
3072           // Comma-separate the parameters.
3073           if(parameterBuild < 2)
3074           {
3075             parameterStream << ", ";
3076           }
3077         }
3078
3079         // Check the function was called and the parameters were correct.
3080         DALI_TEST_CHECK(glStencilFunctionStack.FindMethodAndParams(methodString, parameterStream.str()));
3081       }
3082     }
3083   }
3084
3085   END_TEST;
3086 }
3087
3088 int UtcDaliRendererSetStencilMask(void)
3089 {
3090   TestApplication application;
3091   tet_infoline("Test setting the StencilMask");
3092
3093   Renderer           renderer               = RendererTestFixture(application);
3094   TestGlAbstraction& glAbstraction          = application.GetGlAbstraction();
3095   TraceCallStack&    glEnableDisableStack   = glAbstraction.GetEnableDisableTrace();
3096   TraceCallStack&    glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
3097   glEnableDisableStack.Enable(true);
3098   glEnableDisableStack.EnableLogging(true);
3099   glStencilFunctionStack.Enable(true);
3100   glStencilFunctionStack.EnableLogging(true);
3101
3102   // RenderMode must use the stencil for StencilMask to operate.
3103   renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::STENCIL);
3104
3105   // Set the StencilMask property to a value.
3106   renderer.SetProperty(Renderer::Property::STENCIL_MASK, 0x00);
3107
3108   // Check GetProperty returns the same value.
3109   DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_MASK).Get<int>()), 0x00, TEST_LOCATION);
3110
3111   ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
3112
3113   DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetCurrentProperty(Renderer::Property::STENCIL_MASK).Get<int>()), 0x00, TEST_LOCATION);
3114
3115   std::string methodString("StencilMask");
3116   std::string parameterString = "0";
3117
3118   // Check the function was called and the parameters were correct.
3119   DALI_TEST_CHECK(glStencilFunctionStack.FindMethodAndParams(methodString, parameterString));
3120
3121   // Set the StencilMask property to another value to ensure it has changed.
3122   renderer.SetProperty(Renderer::Property::STENCIL_MASK, 0xFF);
3123
3124   // Check GetProperty returns the same value.
3125   DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_MASK).Get<int>()), 0xFF, TEST_LOCATION);
3126
3127   ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
3128
3129   DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetCurrentProperty(Renderer::Property::STENCIL_MASK).Get<int>()), 0xFF, TEST_LOCATION);
3130
3131   parameterString = "255";
3132
3133   // Check the function was called and the parameters were correct.
3134   DALI_TEST_CHECK(glStencilFunctionStack.FindMethodAndParams(methodString, parameterString));
3135
3136   END_TEST;
3137 }
3138
3139 int UtcDaliRendererWrongNumberOfTextures(void)
3140 {
3141   TestApplication application;
3142   tet_infoline("Test renderer does render even if number of textures is different than active samplers in the shader");
3143
3144   //Create a TextureSet with 4 textures (One more texture in the texture set than active samplers)
3145   //@note Shaders in the test suit have 3 active samplers. See TestGlAbstraction::GetActiveUniform()
3146   Texture    texture    = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64u, 64u);
3147   TextureSet textureSet = CreateTextureSet();
3148   textureSet.SetTexture(0, texture);
3149   textureSet.SetTexture(1, texture);
3150   textureSet.SetTexture(2, texture);
3151   textureSet.SetTexture(3, texture);
3152   Shader   shader   = Shader::New("VertexSource", "FragmentSource");
3153   Geometry geometry = CreateQuadGeometry();
3154   Renderer renderer = Renderer::New(geometry, shader);
3155   renderer.SetTextures(textureSet);
3156
3157   Actor actor = Actor::New();
3158   actor.AddRenderer(renderer);
3159   actor.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 0.0f));
3160   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
3161   application.GetScene().Add(actor);
3162
3163   TestGlAbstraction& gl        = application.GetGlAbstraction();
3164   TraceCallStack&    drawTrace = gl.GetDrawTrace();
3165   drawTrace.Reset();
3166   drawTrace.Enable(true);
3167   drawTrace.EnableLogging(true);
3168
3169   application.SendNotification();
3170   application.Render(0);
3171
3172   //Test we do the drawcall when TextureSet has more textures than there are active samplers in the shader
3173   DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION);
3174
3175   //Create a TextureSet with 1 texture (two more active samplers than texture in the texture set)
3176   //@note Shaders in the test suit have 3 active samplers. See TestGlAbstraction::GetActiveUniform()
3177   textureSet = CreateTextureSet();
3178   renderer.SetTextures(textureSet);
3179   textureSet.SetTexture(0, texture);
3180   drawTrace.Reset();
3181   application.SendNotification();
3182   application.Render(0);
3183
3184   //Test we do the drawcall when TextureSet has less textures than there are active samplers in the shader.
3185   DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION);
3186
3187   END_TEST;
3188 }
3189
3190 int UtcDaliRendererOpacity(void)
3191 {
3192   TestApplication application;
3193
3194   tet_infoline("Test OPACITY property");
3195
3196   Geometry geometry = CreateQuadGeometry();
3197   Shader   shader   = Shader::New("vertexSrc", "fragmentSrc");
3198   Renderer renderer = Renderer::New(geometry, shader);
3199
3200   Actor actor = Actor::New();
3201   actor.AddRenderer(renderer);
3202   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3203   actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 1.0f));
3204   application.GetScene().Add(actor);
3205
3206   Property::Value value = renderer.GetProperty(DevelRenderer::Property::OPACITY);
3207   float           opacity;
3208   DALI_TEST_CHECK(value.Get(opacity));
3209   DALI_TEST_EQUALS(opacity, 1.0f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3210
3211   application.SendNotification();
3212   application.Render();
3213
3214   Vector4            actualValue;
3215   Vector4            actualActorColor;
3216   TestGlAbstraction& gl = application.GetGlAbstraction();
3217   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uColor", actualValue));
3218   DALI_TEST_EQUALS(actualValue.a, 1.0f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3219   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uActorColor", actualActorColor));
3220   DALI_TEST_EQUALS(actualActorColor.a, 1.0f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3221
3222   renderer.SetProperty(DevelRenderer::Property::OPACITY, 0.5f);
3223
3224   application.SendNotification();
3225   application.Render();
3226
3227   value = renderer.GetProperty(DevelRenderer::Property::OPACITY);
3228   DALI_TEST_CHECK(value.Get(opacity));
3229   DALI_TEST_EQUALS(opacity, 0.5f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3230
3231   value = renderer.GetCurrentProperty(DevelRenderer::Property::OPACITY);
3232   DALI_TEST_CHECK(value.Get(opacity));
3233   DALI_TEST_EQUALS(opacity, 0.5f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3234
3235   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uColor", actualValue));
3236   DALI_TEST_EQUALS(actualValue.a, 0.5f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3237
3238   // Note : Renderer opacity doesn't apply to uActorColor.
3239   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uActorColor", actualActorColor));
3240   DALI_TEST_EQUALS(actualActorColor.a, 1.0f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3241
3242   END_TEST;
3243 }
3244
3245 int UtcDaliRendererOpacityAnimation(void)
3246 {
3247   TestApplication application;
3248
3249   tet_infoline("Test OPACITY property animation");
3250
3251   Geometry geometry = CreateQuadGeometry();
3252   Shader   shader   = Shader::New("vertexSrc", "fragmentSrc");
3253   Renderer renderer = Renderer::New(geometry, shader);
3254
3255   Actor actor = Actor::New();
3256   actor.AddRenderer(renderer);
3257   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3258   actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 1.0f));
3259   application.GetScene().Add(actor);
3260
3261   application.SendNotification();
3262   application.Render(0);
3263
3264   Property::Value value = renderer.GetProperty(DevelRenderer::Property::OPACITY);
3265   float           opacity;
3266   DALI_TEST_CHECK(value.Get(opacity));
3267   DALI_TEST_EQUALS(opacity, 1.0f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3268
3269   Animation animation = Animation::New(1.0f);
3270   animation.AnimateTo(Property(renderer, DevelRenderer::Property::OPACITY), 0.0f);
3271   animation.Play();
3272
3273   application.SendNotification();
3274   application.Render(1000);
3275
3276   value = renderer.GetProperty(DevelRenderer::Property::OPACITY);
3277   DALI_TEST_CHECK(value.Get(opacity));
3278   DALI_TEST_EQUALS(opacity, 0.0f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3279
3280   // Need to clear the animation before setting the property as the animation value is baked and will override any previous setters
3281   animation.Clear();
3282   renderer.SetProperty(DevelRenderer::Property::OPACITY, 0.1f);
3283
3284   animation.AnimateBy(Property(renderer, DevelRenderer::Property::OPACITY), 0.5f);
3285   animation.Play();
3286
3287   application.SendNotification();
3288   application.Render(1000);
3289
3290   value = renderer.GetProperty(DevelRenderer::Property::OPACITY);
3291   DALI_TEST_CHECK(value.Get(opacity));
3292   DALI_TEST_EQUALS(opacity, 0.6f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3293   DALI_TEST_EQUALS(opacity, renderer.GetCurrentProperty(DevelRenderer::Property::OPACITY).Get<float>(), Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3294
3295   END_TEST;
3296 }
3297
3298 int UtcDaliRendererInvalidProperty(void)
3299 {
3300   TestApplication application;
3301
3302   tet_infoline("Test invalid property");
3303
3304   Geometry geometry = CreateQuadGeometry();
3305   Shader   shader   = Shader::New("vertexSrc", "fragmentSrc");
3306   Renderer renderer = Renderer::New(geometry, shader);
3307
3308   Actor actor = Actor::New();
3309   actor.AddRenderer(renderer);
3310   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3311   application.GetScene().Add(actor);
3312
3313   application.SendNotification();
3314   application.Render(0);
3315
3316   Property::Value value = renderer.GetProperty(Renderer::Property::DEPTH_INDEX + 100);
3317   DALI_TEST_CHECK(value.GetType() == Property::Type::NONE);
3318
3319   value = renderer.GetCurrentProperty(Renderer::Property::DEPTH_INDEX + 100);
3320   DALI_TEST_CHECK(value.GetType() == Property::Type::NONE);
3321
3322   END_TEST;
3323 }
3324
3325 int UtcDaliRendererRenderingBehavior(void)
3326 {
3327   TestApplication application;
3328
3329   tet_infoline("Test RENDERING_BEHAVIOR property");
3330
3331   Geometry geometry = CreateQuadGeometry();
3332   Shader   shader   = Shader::New("vertexSrc", "fragmentSrc");
3333   Renderer renderer = Renderer::New(geometry, shader);
3334
3335   Actor actor = Actor::New();
3336   actor.AddRenderer(renderer);
3337   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3338   actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 1.0f));
3339   application.GetScene().Add(actor);
3340
3341   Property::Value value = renderer.GetProperty(DevelRenderer::Property::RENDERING_BEHAVIOR);
3342   int             renderingBehavior;
3343   DALI_TEST_CHECK(value.Get(renderingBehavior));
3344   DALI_TEST_EQUALS(static_cast<DevelRenderer::Rendering::Type>(renderingBehavior), DevelRenderer::Rendering::IF_REQUIRED, TEST_LOCATION);
3345
3346   application.SendNotification();
3347   application.Render();
3348
3349   uint32_t updateStatus = application.GetUpdateStatus();
3350
3351   DALI_TEST_CHECK(!(updateStatus & Integration::KeepUpdating::STAGE_KEEP_RENDERING));
3352
3353   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
3354   TraceCallStack&    drawTrace     = glAbstraction.GetDrawTrace();
3355   drawTrace.Enable(true);
3356   drawTrace.Reset();
3357
3358   renderer.SetProperty(DevelRenderer::Property::RENDERING_BEHAVIOR, DevelRenderer::Rendering::CONTINUOUSLY);
3359
3360   value = renderer.GetProperty(DevelRenderer::Property::RENDERING_BEHAVIOR);
3361   DALI_TEST_CHECK(value.Get(renderingBehavior));
3362   DALI_TEST_EQUALS(static_cast<DevelRenderer::Rendering::Type>(renderingBehavior), DevelRenderer::Rendering::CONTINUOUSLY, TEST_LOCATION);
3363
3364   // Render and check the update status
3365   application.SendNotification();
3366   application.Render();
3367
3368   updateStatus = application.GetUpdateStatus();
3369
3370   DALI_TEST_CHECK(updateStatus & Integration::KeepUpdating::STAGE_KEEP_RENDERING);
3371
3372   value = renderer.GetCurrentProperty(DevelRenderer::Property::RENDERING_BEHAVIOR);
3373   DALI_TEST_CHECK(value.Get(renderingBehavior));
3374   DALI_TEST_EQUALS(static_cast<DevelRenderer::Rendering::Type>(renderingBehavior), DevelRenderer::Rendering::CONTINUOUSLY, TEST_LOCATION);
3375
3376   DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION);
3377
3378   drawTrace.Reset();
3379
3380   // Render again and check the update status
3381   application.SendNotification();
3382   application.Render();
3383
3384   updateStatus = application.GetUpdateStatus();
3385
3386   DALI_TEST_CHECK(updateStatus & Integration::KeepUpdating::STAGE_KEEP_RENDERING);
3387
3388   DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION);
3389
3390   {
3391     // Render again and check the update status
3392     Animation animation = Animation::New(1.0f);
3393     animation.AnimateTo(Property(renderer, DevelRenderer::Property::OPACITY), 0.0f, TimePeriod(0.5f, 0.5f));
3394     animation.Play();
3395
3396     drawTrace.Reset();
3397
3398     application.SendNotification();
3399     application.Render(0);
3400
3401     DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION);
3402
3403     drawTrace.Reset();
3404
3405     application.SendNotification();
3406     application.Render(100);
3407
3408     updateStatus = application.GetUpdateStatus();
3409
3410     DALI_TEST_CHECK(updateStatus & Integration::KeepUpdating::STAGE_KEEP_RENDERING);
3411
3412     DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION);
3413   }
3414
3415   // Change rendering behavior
3416   renderer.SetProperty(DevelRenderer::Property::RENDERING_BEHAVIOR, DevelRenderer::Rendering::IF_REQUIRED);
3417
3418   // Render and check the update status
3419   application.SendNotification();
3420   application.Render();
3421
3422   updateStatus = application.GetUpdateStatus();
3423
3424   DALI_TEST_CHECK(!(updateStatus & Integration::KeepUpdating::STAGE_KEEP_RENDERING));
3425
3426   END_TEST;
3427 }
3428
3429 int UtcDaliRendererRegenerateUniformMap(void)
3430 {
3431   TestApplication application;
3432
3433   tet_infoline("Test regenerating uniform map when attaching renderer to the node");
3434
3435   Geometry geometry = CreateQuadGeometry();
3436   Shader   shader   = Shader::New("vertexSrc", "fragmentSrc");
3437   Renderer renderer = Renderer::New(geometry, shader);
3438
3439   Actor actor = Actor::New();
3440   actor.AddRenderer(renderer);
3441   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3442   actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 1.0f));
3443   application.GetScene().Add(actor);
3444
3445   application.SendNotification();
3446   application.Render();
3447
3448   actor.RemoveRenderer(renderer);
3449   shader = Shader::New("vertexSrc", "fragmentSrc");
3450   shader.RegisterProperty("opacity", 0.5f);
3451   renderer.SetShader(shader);
3452
3453   Stage::GetCurrent().KeepRendering(1.0f);
3454
3455   // Update for several frames
3456   application.SendNotification();
3457   application.Render();
3458   application.SendNotification();
3459   application.Render();
3460   application.SendNotification();
3461   application.Render();
3462   application.SendNotification();
3463   application.Render();
3464
3465   // Add Renderer
3466   actor.AddRenderer(renderer);
3467   application.SendNotification();
3468   application.Render();
3469
3470   // Nothing to test here, the test must not crash
3471   auto updateStatus = application.GetUpdateStatus();
3472   DALI_TEST_CHECK(updateStatus & Integration::KeepUpdating::STAGE_KEEP_RENDERING);
3473
3474   END_TEST;
3475 }
3476
3477 int UtcDaliRendererAddDrawCommands(void)
3478 {
3479   TestApplication application;
3480
3481   tet_infoline("Test adding draw commands to the renderer");
3482
3483   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
3484   glAbstraction.EnableEnableDisableCallTrace(true);
3485
3486   Geometry geometry = CreateQuadGeometry();
3487   Shader   shader   = Shader::New("vertexSrc", "fragmentSrc");
3488   Renderer renderer = Renderer::New(geometry, shader);
3489
3490   renderer.SetProperty(Renderer::Property::BLEND_MODE, Dali::BlendMode::ON);
3491   Actor actor = Actor::New();
3492   actor.AddRenderer(renderer);
3493   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3494   actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 1.0f));
3495   application.GetScene().Add(actor);
3496
3497   // Expect delivering a single draw call
3498   auto& drawTrace = glAbstraction.GetDrawTrace();
3499   drawTrace.Reset();
3500   drawTrace.Enable(true);
3501   application.SendNotification();
3502   application.Render();
3503
3504   DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION);
3505
3506   tet_infoline("\n\nTesting extension draw commands\n");
3507   auto drawCommand1         = DevelRenderer::DrawCommand{};
3508   drawCommand1.drawType     = DevelRenderer::DrawType::INDEXED;
3509   drawCommand1.firstIndex   = 0;
3510   drawCommand1.elementCount = 2;
3511   drawCommand1.queue        = DevelRenderer::RENDER_QUEUE_OPAQUE;
3512
3513   auto drawCommand2         = DevelRenderer::DrawCommand{};
3514   drawCommand2.drawType     = DevelRenderer::DrawType::INDEXED;
3515   drawCommand2.firstIndex   = 2;
3516   drawCommand2.elementCount = 2;
3517   drawCommand2.queue        = DevelRenderer::RENDER_QUEUE_TRANSPARENT;
3518
3519   auto drawCommand3         = DevelRenderer::DrawCommand{};
3520   drawCommand3.drawType     = DevelRenderer::DrawType::ARRAY;
3521   drawCommand3.firstIndex   = 2;
3522   drawCommand3.elementCount = 2;
3523   drawCommand3.queue        = DevelRenderer::RENDER_QUEUE_OPAQUE;
3524
3525   DevelRenderer::AddDrawCommand(renderer, drawCommand1);
3526   DevelRenderer::AddDrawCommand(renderer, drawCommand2);
3527   DevelRenderer::AddDrawCommand(renderer, drawCommand3);
3528
3529   drawTrace.Reset();
3530   drawTrace.Enable(true);
3531   application.SendNotification();
3532   application.Render();
3533
3534   DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 3, TEST_LOCATION);
3535   END_TEST;
3536 }
3537 int UtcDaliRendererSetGeometryNegative(void)
3538 {
3539   TestApplication application;
3540   Dali::Renderer  instance;
3541   try
3542   {
3543     Dali::Geometry arg1;
3544     instance.SetGeometry(arg1);
3545     DALI_TEST_CHECK(false); // Should not get here
3546   }
3547   catch(...)
3548   {
3549     DALI_TEST_CHECK(true); // We expect an assert
3550   }
3551   END_TEST;
3552 }
3553
3554 int UtcDaliRendererSetTexturesNegative(void)
3555 {
3556   TestApplication application;
3557   Dali::Renderer  instance;
3558   try
3559   {
3560     Dali::TextureSet arg1;
3561     instance.SetTextures(arg1);
3562     DALI_TEST_CHECK(false); // Should not get here
3563   }
3564   catch(...)
3565   {
3566     DALI_TEST_CHECK(true); // We expect an assert
3567   }
3568   END_TEST;
3569 }
3570
3571 int UtcDaliRendererSetShaderNegative(void)
3572 {
3573   TestApplication application;
3574   Dali::Renderer  instance;
3575   try
3576   {
3577     Dali::Shader arg1;
3578     instance.SetShader(arg1);
3579     DALI_TEST_CHECK(false); // Should not get here
3580   }
3581   catch(...)
3582   {
3583     DALI_TEST_CHECK(true); // We expect an assert
3584   }
3585   END_TEST;
3586 }
3587
3588 int UtcDaliRendererGetGeometryNegative(void)
3589 {
3590   TestApplication application;
3591   Dali::Renderer  instance;
3592   try
3593   {
3594     instance.GetGeometry();
3595     DALI_TEST_CHECK(false); // Should not get here
3596   }
3597   catch(...)
3598   {
3599     DALI_TEST_CHECK(true); // We expect an assert
3600   }
3601   END_TEST;
3602 }
3603
3604 int UtcDaliRendererGetTexturesNegative(void)
3605 {
3606   TestApplication application;
3607   Dali::Renderer  instance;
3608   try
3609   {
3610     instance.GetTextures();
3611     DALI_TEST_CHECK(false); // Should not get here
3612   }
3613   catch(...)
3614   {
3615     DALI_TEST_CHECK(true); // We expect an assert
3616   }
3617   END_TEST;
3618 }
3619
3620 int UtcDaliRendererGetShaderNegative(void)
3621 {
3622   TestApplication application;
3623   Dali::Renderer  instance;
3624   try
3625   {
3626     instance.GetShader();
3627     DALI_TEST_CHECK(false); // Should not get here
3628   }
3629   catch(...)
3630   {
3631     DALI_TEST_CHECK(true); // We expect an assert
3632   }
3633   END_TEST;
3634 }
3635
3636 int UtcDaliRendererCheckTextureBindingP(void)
3637 {
3638   TestApplication application;
3639
3640   tet_infoline("Test adding draw commands to the renderer");
3641
3642   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
3643   glAbstraction.EnableEnableDisableCallTrace(true);
3644
3645   Geometry geometry = CreateQuadGeometry();
3646   Shader   shader   = Shader::New("vertexSrc", "fragmentSrc");
3647   Renderer renderer = Renderer::New(geometry, shader);
3648
3649   renderer.SetProperty(Renderer::Property::BLEND_MODE, Dali::BlendMode::ON);
3650   Actor actor = Actor::New();
3651   actor.AddRenderer(renderer);
3652   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3653   actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 1.0f));
3654   application.GetScene().Add(actor);
3655
3656   TestGraphicsController& graphics        = application.GetGraphicsController();
3657   TraceCallStack&         cmdBufCallstack = graphics.mCommandBufferCallStack;
3658   cmdBufCallstack.Enable(true);
3659
3660   application.SendNotification();
3661   application.Render();
3662
3663   DALI_TEST_CHECK(!cmdBufCallstack.FindMethod("BindTextures"));
3664
3665   Texture    image0      = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGB888, 64, 64);
3666   TextureSet textureSet0 = CreateTextureSet(image0);
3667   renderer.SetTextures(textureSet0);
3668
3669   application.SendNotification();
3670   application.Render();
3671
3672   DALI_TEST_CHECK(cmdBufCallstack.FindMethod("BindTextures"));
3673   END_TEST;
3674 }
3675
3676 int UtcDaliRendererPreparePipeline(void)
3677 {
3678   TestApplication application;
3679
3680   tet_infoline("Test that rendering an actor binds the attributes locs from the reflection");
3681
3682   Property::Map vf            = CreateModelVertexFormat();
3683   Geometry      modelGeometry = CreateModelGeometry(vf);
3684   Shader        shader        = Shader::New("vertexSrc", "fragmentSrc");
3685   Renderer      renderer      = Renderer::New(modelGeometry, shader);
3686   Actor         actor         = Actor::New();
3687
3688   // Change the order up to get a fair test
3689   Property::Map modelVF;
3690   modelVF["aBoneIndex[0]"]   = Property::INTEGER;
3691   modelVF["aBoneIndex[1]"]   = Property::INTEGER;
3692   modelVF["aBoneIndex[2]"]   = Property::INTEGER;
3693   modelVF["aBoneIndex[3]"]   = Property::INTEGER;
3694   modelVF["aBoneWeights[0]"] = Property::FLOAT;
3695   modelVF["aBoneWeights[1]"] = Property::FLOAT;
3696   modelVF["aBoneWeights[2]"] = Property::FLOAT;
3697   modelVF["aBoneWeights[3]"] = Property::FLOAT;
3698   modelVF["aPosition"]       = Property::VECTOR3;
3699   modelVF["aNormal"]         = Property::VECTOR3;
3700   modelVF["aTexCoord1"]      = Property::VECTOR3;
3701   modelVF["aTexCoord2"]      = Property::VECTOR3;
3702
3703   Property::Array vfs;
3704   vfs.PushBack(modelVF);
3705   TestGraphicsController& graphics = application.GetGraphicsController();
3706   graphics.SetVertexFormats(vfs);
3707
3708   actor.AddRenderer(renderer);
3709   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3710   actor.SetProperty(Actor::Property::COLOR, Color::WHITE);
3711   application.GetScene().Add(actor);
3712
3713   TraceCallStack& cmdBufCallstack   = graphics.mCommandBufferCallStack;
3714   TraceCallStack& graphicsCallstack = graphics.mCallStack;
3715   cmdBufCallstack.Enable(true);
3716   graphicsCallstack.Enable(true);
3717
3718   application.SendNotification();
3719   application.Render();
3720
3721   DALI_TEST_CHECK(graphicsCallstack.FindMethod("SubmitCommandBuffers"));
3722   std::vector<Graphics::SubmitInfo>& submissions = graphics.mSubmitStack;
3723   DALI_TEST_CHECK(submissions.size() > 0);
3724
3725   TestGraphicsCommandBuffer* cmdBuf = static_cast<TestGraphicsCommandBuffer*>((submissions.back().cmdBuffer[0]));
3726
3727   auto result   = cmdBuf->GetChildCommandsByType(0 | CommandType::BIND_PIPELINE);
3728   auto pipeline = result[0]->data.bindPipeline.pipeline;
3729
3730   if(pipeline)
3731   {
3732     DALI_TEST_EQUALS(pipeline->vertexInputState.attributes.size(), 12, TEST_LOCATION);
3733     DALI_TEST_EQUALS(pipeline->vertexInputState.attributes[3].location, // 4th requested attr: aTexCoord2
3734                      11,
3735                      TEST_LOCATION);
3736     DALI_TEST_EQUALS(pipeline->vertexInputState.attributes[3].format, // 4th requested attr: aTexCoord2
3737                      Graphics::VertexInputFormat::FVECTOR3,
3738                      TEST_LOCATION);
3739   }
3740
3741   END_TEST;
3742 }