Merge "Clean up the code to build successfully on macOS" into devel/master
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-Renderer.cpp
1 /*
2  * Copyright (c) 2020 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/stage.h>
21 #include <dali/devel-api/rendering/renderer-devel.h>
22 #include <dali/integration-api/render-task-list-integ.h>
23 #include <dali/public-api/dali-core.h>
24 #include <dali/devel-api/common/capabilities.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
33 using namespace Dali;
34
35 namespace // unnamed namespace
36 {
37 const BlendFactor::Type DEFAULT_BLEND_FACTOR_SRC_RGB(BlendFactor::SRC_ALPHA);
38 const BlendFactor::Type DEFAULT_BLEND_FACTOR_DEST_RGB(BlendFactor::ONE_MINUS_SRC_ALPHA);
39 const BlendFactor::Type DEFAULT_BLEND_FACTOR_SRC_ALPHA(BlendFactor::ONE);
40 const BlendFactor::Type DEFAULT_BLEND_FACTOR_DEST_ALPHA(BlendFactor::ONE_MINUS_SRC_ALPHA);
41
42 const BlendEquation::Type DEFAULT_BLEND_EQUATION_RGB(BlendEquation::ADD);
43 const BlendEquation::Type DEFAULT_BLEND_EQUATION_ALPHA(BlendEquation::ADD);
44
45 /**
46  * @brief Get GL stencil test enumeration value as a string.
47  * @return The string representation of the value of GL_STENCIL_TEST
48  */
49 std::string GetStencilTestString(void)
50 {
51   std::stringstream stream;
52   stream << GL_STENCIL_TEST;
53   return stream.str();
54 }
55
56 /**
57  * @brief Get GL depth test enumeration value as a string.
58  * @return The string representation of the value of GL_DEPTH_TEST
59  */
60 std::string GetDepthTestString(void)
61 {
62   std::stringstream stream;
63   stream << GL_DEPTH_TEST;
64   return stream.str();
65 }
66
67 void ResetDebugAndFlush(TestApplication& application, TraceCallStack& glEnableDisableStack, TraceCallStack& glStencilFunctionStack)
68 {
69   glEnableDisableStack.Reset();
70   glStencilFunctionStack.Reset();
71   application.SendNotification();
72   application.Render();
73 }
74
75 void TestConstraintNoBlue(Vector4& current, const PropertyInputContainer& inputs)
76 {
77   current.b = 0.0f;
78 }
79
80 } // unnamed namespace
81
82 void renderer_test_startup(void)
83 {
84   test_return_value = TET_UNDEF;
85 }
86
87 void renderer_test_cleanup(void)
88 {
89   test_return_value = TET_PASS;
90 }
91
92 int UtcDaliRendererNew01(void)
93 {
94   TestApplication application;
95
96   Geometry geometry = CreateQuadGeometry();
97   Shader   shader   = CreateShader();
98   Renderer renderer = Renderer::New(geometry, shader);
99
100   DALI_TEST_EQUALS((bool)renderer, true, TEST_LOCATION);
101   END_TEST;
102 }
103
104 int UtcDaliRendererNew02(void)
105 {
106   TestApplication application;
107   Renderer        renderer;
108   DALI_TEST_EQUALS((bool)renderer, false, TEST_LOCATION);
109   END_TEST;
110 }
111
112 int UtcDaliRendererCopyConstructor(void)
113 {
114   TestApplication application;
115
116   Geometry geometry = CreateQuadGeometry();
117   Shader   shader   = CreateShader();
118   Renderer renderer = Renderer::New(geometry, shader);
119
120   Renderer rendererCopy(renderer);
121   DALI_TEST_EQUALS((bool)rendererCopy, true, TEST_LOCATION);
122
123   END_TEST;
124 }
125
126 int UtcDaliRendererAssignmentOperator(void)
127 {
128   TestApplication application;
129
130   Geometry geometry = CreateQuadGeometry();
131   Shader   shader   = CreateShader();
132   Renderer renderer = Renderer::New(geometry, shader);
133
134   Renderer renderer2;
135   DALI_TEST_EQUALS((bool)renderer2, false, TEST_LOCATION);
136
137   renderer2 = renderer;
138   DALI_TEST_EQUALS((bool)renderer2, true, TEST_LOCATION);
139   END_TEST;
140 }
141
142 int UtcDaliRendererMoveConstructor(void)
143 {
144   TestApplication application;
145
146   Geometry geometry = CreateQuadGeometry();
147   Shader   shader   = Shader::New("vertexSrc", "fragmentSrc");
148   Renderer renderer = Renderer::New(geometry, shader);
149   DALI_TEST_CHECK(renderer);
150   DALI_TEST_EQUALS(1, renderer.GetBaseObject().ReferenceCount(), TEST_LOCATION);
151   DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::TRANSPARENT, TEST_LOCATION);
152
153   renderer.SetProperty(Renderer::Property::BLEND_COLOR, Color::MAGENTA);
154   application.SendNotification();
155   application.Render();
156   DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::MAGENTA, TEST_LOCATION);
157
158   Renderer move = std::move(renderer);
159   DALI_TEST_CHECK(move);
160   DALI_TEST_EQUALS(1, move.GetBaseObject().ReferenceCount(), TEST_LOCATION);
161   DALI_TEST_EQUALS(move.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::MAGENTA, TEST_LOCATION);
162   DALI_TEST_CHECK(!renderer);
163
164   END_TEST;
165 }
166
167 int UtcDaliRendererMoveAssignment(void)
168 {
169   TestApplication application;
170
171   Geometry geometry = CreateQuadGeometry();
172   Shader   shader   = Shader::New("vertexSrc", "fragmentSrc");
173   Renderer renderer = Renderer::New(geometry, shader);
174   DALI_TEST_CHECK(renderer);
175   DALI_TEST_EQUALS(1, renderer.GetBaseObject().ReferenceCount(), TEST_LOCATION);
176   DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::TRANSPARENT, TEST_LOCATION);
177
178   renderer.SetProperty(Renderer::Property::BLEND_COLOR, Color::MAGENTA);
179   application.SendNotification();
180   application.Render();
181   DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::MAGENTA, TEST_LOCATION);
182
183   Renderer move;
184   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 UtcDaliRendererDownCast01(void)
194 {
195   TestApplication application;
196
197   Geometry geometry = CreateQuadGeometry();
198   Shader   shader   = CreateShader();
199   Renderer renderer = Renderer::New(geometry, shader);
200
201   BaseHandle handle(renderer);
202   Renderer   renderer2 = Renderer::DownCast(handle);
203   DALI_TEST_EQUALS((bool)renderer2, true, TEST_LOCATION);
204   END_TEST;
205 }
206
207 int UtcDaliRendererDownCast02(void)
208 {
209   TestApplication application;
210
211   Handle   handle   = Handle::New(); // Create a custom object
212   Renderer renderer = Renderer::DownCast(handle);
213   DALI_TEST_EQUALS((bool)renderer, false, TEST_LOCATION);
214   END_TEST;
215 }
216
217 // using a template to auto deduce the parameter types
218 template<typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8>
219 void TEST_RENDERER_PROPERTY(P1 renderer, P2 stringName, P3 type, P4 isWriteable, P5 isAnimateable, P6 isConstraintInput, P7 enumName, P8 LOCATION)
220 {
221   DALI_TEST_EQUALS(renderer.GetPropertyName(enumName), stringName, LOCATION);
222   DALI_TEST_EQUALS(renderer.GetPropertyIndex(stringName), static_cast<Property::Index>(enumName), LOCATION);
223   DALI_TEST_EQUALS(renderer.GetPropertyType(enumName), type, LOCATION);
224   DALI_TEST_EQUALS(renderer.IsPropertyWritable(enumName), isWriteable, LOCATION);
225   DALI_TEST_EQUALS(renderer.IsPropertyAnimatable(enumName), isAnimateable, LOCATION);
226   DALI_TEST_EQUALS(renderer.IsPropertyAConstraintInput(enumName), isConstraintInput, LOCATION);
227 }
228
229 int UtcDaliRendererDefaultProperties(void)
230 {
231   TestApplication application;
232   /* from renderer-impl.cpp
233   DALI_PROPERTY( "depthIndex",                      INTEGER,   true, false,  false, Dali::Renderer::Property::DEPTH_INDEX )
234   DALI_PROPERTY( "faceCullingMode",                 INTEGER,   true, false,  false, Dali::Renderer::Property::FACE_CULLING_MODE )
235   DALI_PROPERTY( "blendMode",                       INTEGER,   true, false,  false, Dali::Renderer::Property::BLEND_MODE )
236   DALI_PROPERTY( "blendEquationRgb",                INTEGER,   true, false,  false, Dali::Renderer::Property::BLEND_EQUATION_RGB )
237   DALI_PROPERTY( "blendEquationAlpha",              INTEGER,   true, false,  false, Dali::Renderer::Property::BLEND_EQUATION_ALPHA )
238   DALI_PROPERTY( "blendFactorSrcRgb",               INTEGER,   true, false,  false, Dali::Renderer::Property::BLEND_FACTOR_SRC_RGB )
239   DALI_PROPERTY( "blendFactorDestRgb",              INTEGER,   true, false,  false, Dali::Renderer::Property::BLEND_FACTOR_DEST_RGB )
240   DALI_PROPERTY( "blendFactorSrcAlpha",             INTEGER,   true, false,  false, Dali::Renderer::Property::BLEND_FACTOR_SRC_ALPHA )
241   DALI_PROPERTY( "blendFactorDestAlpha",            INTEGER,   true, false,  false, Dali::Renderer::Property::BLEND_FACTOR_DEST_ALPHA )
242   DALI_PROPERTY( "blendColor",                      VECTOR4,   true, false,  false, Dali::Renderer::Property::BLEND_COLOR )
243   DALI_PROPERTY( "blendPreMultipliedAlpha",         BOOLEAN,   true, false,  false, Dali::Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA )
244   DALI_PROPERTY( "indexRangeFirst",                 INTEGER,   true, false,  false, Dali::Renderer::Property::INDEX_RANGE_FIRST )
245   DALI_PROPERTY( "indexRangeCount",                 INTEGER,   true, false,  false, Dali::Renderer::Property::INDEX_RANGE_COUNT )
246   DALI_PROPERTY( "depthWriteMode",                  INTEGER,   true, false,  false, Dali::Renderer::Property::DEPTH_WRITE_MODE )
247   DALI_PROPERTY( "depthFunction",                   INTEGER,   true, false,  false, Dali::Renderer::Property::DEPTH_FUNCTION )
248   DALI_PROPERTY( "depthTestMode",                   INTEGER,   true, false,  false, Dali::Renderer::Property::DEPTH_TEST_MODE )
249   DALI_PROPERTY( "renderMode",                      INTEGER,   true, false,  false, Dali::Renderer::Property::RENDER_MODE )
250   DALI_PROPERTY( "stencilFunction",                 INTEGER,   true, false,  false, Dali::Renderer::Property::STENCIL_FUNCTION )
251   DALI_PROPERTY( "stencilFunctionMask",             INTEGER,   true, false,  false, Dali::Renderer::Property::STENCIL_FUNCTION_MASK )
252   DALI_PROPERTY( "stencilFunctionReference",        INTEGER,   true, false,  false, Dali::Renderer::Property::STENCIL_FUNCTION_REFERENCE )
253   DALI_PROPERTY( "stencilMask",                     INTEGER,   true, false,  false, Dali::Renderer::Property::STENCIL_MASK )
254   DALI_PROPERTY( "stencilOperationOnFail",          INTEGER,   true, false,  false, Dali::Renderer::Property::STENCIL_OPERATION_ON_FAIL )
255   DALI_PROPERTY( "stencilOperationOnZFail",         INTEGER,   true, false,  false, Dali::Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL )
256   DALI_PROPERTY( "stencilOperationOnZPass",         INTEGER,   true, false,  false, Dali::Renderer::Property::STENCIL_OPERATION_ON_Z_PASS )
257   DALI_PROPERTY( "opacity",                         FLOAT,     true, true,   true,  Dali::DevelRenderer::Property::OPACITY )
258   DALI_PROPERTY( "renderingBehavior",               INTEGER,   true, false,  false, Dali::DevelRenderer::Property::RENDERING_BEHAVIOR )
259   DALI_PROPERTY( "blendEquation",                   INTEGER,   true, false,  false, Dali::DevelRenderer::Property::BLEND_EQUATION )
260 */
261
262   Geometry geometry = CreateQuadGeometry();
263   Shader   shader   = CreateShader();
264   Renderer renderer = Renderer::New(geometry, shader);
265   DALI_TEST_EQUALS(renderer.GetPropertyCount(), 27, TEST_LOCATION);
266
267   TEST_RENDERER_PROPERTY(renderer, "depthIndex", Property::INTEGER, true, false, false, Renderer::Property::DEPTH_INDEX, TEST_LOCATION);
268   TEST_RENDERER_PROPERTY(renderer, "faceCullingMode", Property::INTEGER, true, false, false, Renderer::Property::FACE_CULLING_MODE, TEST_LOCATION);
269   TEST_RENDERER_PROPERTY(renderer, "blendMode", Property::INTEGER, true, false, false, Renderer::Property::BLEND_MODE, TEST_LOCATION);
270   TEST_RENDERER_PROPERTY(renderer, "blendEquationRgb", Property::INTEGER, true, false, false, Renderer::Property::BLEND_EQUATION_RGB, TEST_LOCATION);
271   TEST_RENDERER_PROPERTY(renderer, "blendEquationAlpha", Property::INTEGER, true, false, false, Renderer::Property::BLEND_EQUATION_ALPHA, TEST_LOCATION);
272   TEST_RENDERER_PROPERTY(renderer, "blendFactorSrcRgb", Property::INTEGER, true, false, false, Renderer::Property::BLEND_FACTOR_SRC_RGB, TEST_LOCATION);
273   TEST_RENDERER_PROPERTY(renderer, "blendFactorDestRgb", Property::INTEGER, true, false, false, Renderer::Property::BLEND_FACTOR_DEST_RGB, TEST_LOCATION);
274   TEST_RENDERER_PROPERTY(renderer, "blendFactorSrcAlpha", Property::INTEGER, true, false, false, Renderer::Property::BLEND_FACTOR_SRC_ALPHA, TEST_LOCATION);
275   TEST_RENDERER_PROPERTY(renderer, "blendFactorDestAlpha", Property::INTEGER, true, false, false, Renderer::Property::BLEND_FACTOR_DEST_ALPHA, TEST_LOCATION);
276   TEST_RENDERER_PROPERTY(renderer, "blendColor", Property::VECTOR4, true, false, false, Renderer::Property::BLEND_COLOR, TEST_LOCATION);
277   TEST_RENDERER_PROPERTY(renderer, "blendPreMultipliedAlpha", Property::BOOLEAN, true, false, false, Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, TEST_LOCATION);
278   TEST_RENDERER_PROPERTY(renderer, "indexRangeFirst", Property::INTEGER, true, false, false, Renderer::Property::INDEX_RANGE_FIRST, TEST_LOCATION);
279   TEST_RENDERER_PROPERTY(renderer, "indexRangeCount", Property::INTEGER, true, false, false, Renderer::Property::INDEX_RANGE_COUNT, TEST_LOCATION);
280   TEST_RENDERER_PROPERTY(renderer, "depthWriteMode", Property::INTEGER, true, false, false, Renderer::Property::DEPTH_WRITE_MODE, TEST_LOCATION);
281   TEST_RENDERER_PROPERTY(renderer, "depthFunction", Property::INTEGER, true, false, false, Renderer::Property::DEPTH_FUNCTION, TEST_LOCATION);
282   TEST_RENDERER_PROPERTY(renderer, "depthTestMode", Property::INTEGER, true, false, false, Renderer::Property::DEPTH_TEST_MODE, TEST_LOCATION);
283   TEST_RENDERER_PROPERTY(renderer, "renderMode", Property::INTEGER, true, false, false, Renderer::Property::RENDER_MODE, TEST_LOCATION);
284   TEST_RENDERER_PROPERTY(renderer, "stencilFunction", Property::INTEGER, true, false, false, Renderer::Property::STENCIL_FUNCTION, TEST_LOCATION);
285   TEST_RENDERER_PROPERTY(renderer, "stencilFunctionMask", Property::INTEGER, true, false, false, Renderer::Property::STENCIL_FUNCTION_MASK, TEST_LOCATION);
286   TEST_RENDERER_PROPERTY(renderer, "stencilFunctionReference", Property::INTEGER, true, false, false, Renderer::Property::STENCIL_FUNCTION_REFERENCE, TEST_LOCATION);
287   TEST_RENDERER_PROPERTY(renderer, "stencilMask", Property::INTEGER, true, false, false, Renderer::Property::STENCIL_MASK, TEST_LOCATION);
288   TEST_RENDERER_PROPERTY(renderer, "stencilOperationOnFail", Property::INTEGER, true, false, false, Renderer::Property::STENCIL_OPERATION_ON_FAIL, TEST_LOCATION);
289   TEST_RENDERER_PROPERTY(renderer, "stencilOperationOnZFail", Property::INTEGER, true, false, false, Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, TEST_LOCATION);
290   TEST_RENDERER_PROPERTY(renderer, "stencilOperationOnZPass", Property::INTEGER, true, false, false, Renderer::Property::STENCIL_OPERATION_ON_Z_PASS, TEST_LOCATION);
291   TEST_RENDERER_PROPERTY(renderer, "opacity", Property::FLOAT, true, true, true, DevelRenderer::Property::OPACITY, TEST_LOCATION);
292   TEST_RENDERER_PROPERTY(renderer, "renderingBehavior", Property::INTEGER, true, false, false, DevelRenderer::Property::RENDERING_BEHAVIOR, TEST_LOCATION);
293   TEST_RENDERER_PROPERTY(renderer, "blendEquation", Property::INTEGER, true, false, false, DevelRenderer::Property::BLEND_EQUATION, TEST_LOCATION);
294
295   END_TEST;
296 }
297
298 int UtcDaliRendererSetGetGeometry(void)
299 {
300   TestApplication application;
301   tet_infoline("Test SetGeometry, GetGeometry");
302
303   Geometry geometry1 = CreateQuadGeometry();
304   Geometry geometry2 = CreateQuadGeometry();
305
306   Shader   shader   = CreateShader();
307   Renderer renderer = Renderer::New(geometry1, shader);
308   Actor    actor    = Actor::New();
309   actor.AddRenderer(renderer);
310   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
311   application.GetScene().Add(actor);
312
313   application.SendNotification();
314   application.Render(0);
315   DALI_TEST_EQUALS(renderer.GetGeometry(), geometry1, TEST_LOCATION);
316
317   // Set geometry2 to the renderer
318   renderer.SetGeometry(geometry2);
319
320   application.SendNotification();
321   application.Render(0);
322   DALI_TEST_EQUALS(renderer.GetGeometry(), geometry2, TEST_LOCATION);
323
324   END_TEST;
325 }
326
327 int UtcDaliRendererSetGetShader(void)
328 {
329   TestApplication application;
330   tet_infoline("Test SetShader, GetShader");
331
332   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
333   glAbstraction.EnableCullFaceCallTrace(true);
334
335   Shader shader1 = CreateShader();
336   shader1.RegisterProperty("uFadeColor", Color::RED);
337
338   Shader shader2 = CreateShader();
339   shader2.RegisterProperty("uFadeColor", Color::GREEN);
340
341   Geometry geometry = CreateQuadGeometry();
342   Renderer renderer = Renderer::New(geometry, shader1);
343   Actor    actor    = Actor::New();
344   actor.AddRenderer(renderer);
345   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
346   application.GetScene().Add(actor);
347
348   TestGlAbstraction& gl = application.GetGlAbstraction();
349   application.SendNotification();
350   application.Render(0);
351
352   // Expect that the first shaders's fade color property is accessed
353   Vector4 actualValue(Vector4::ZERO);
354   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
355   DALI_TEST_EQUALS(actualValue, Color::RED, TEST_LOCATION);
356
357   DALI_TEST_EQUALS(renderer.GetShader(), shader1, TEST_LOCATION);
358
359   // set the second shader to the renderer
360   renderer.SetShader(shader2);
361
362   application.SendNotification();
363   application.Render(0);
364
365   // Expect that the second shader's fade color property is accessed
366   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
367   DALI_TEST_EQUALS(actualValue, Color::GREEN, TEST_LOCATION);
368
369   DALI_TEST_EQUALS(renderer.GetShader(), shader2, TEST_LOCATION);
370
371   END_TEST;
372 }
373
374 int UtcDaliRendererSetGetDepthIndex(void)
375 {
376   TestApplication application;
377
378   tet_infoline("Test SetDepthIndex, GetDepthIndex");
379
380   Shader   shader   = CreateShader();
381   Geometry geometry = CreateQuadGeometry();
382   Renderer renderer = Renderer::New(geometry, shader);
383   Actor    actor    = Actor::New();
384   actor.AddRenderer(renderer);
385   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
386   application.GetScene().Add(actor);
387
388   application.SendNotification();
389   application.Render(0);
390   DALI_TEST_EQUALS(renderer.GetProperty<int>(Renderer::Property::DEPTH_INDEX), 0, TEST_LOCATION);
391
392   renderer.SetProperty(Renderer::Property::DEPTH_INDEX, 1);
393
394   DALI_TEST_EQUALS(renderer.GetProperty<int>(Renderer::Property::DEPTH_INDEX), 1, TEST_LOCATION);
395   DALI_TEST_EQUALS(renderer.GetCurrentProperty<int>(Renderer::Property::DEPTH_INDEX), 0, TEST_LOCATION);
396
397   application.SendNotification();
398   application.Render(0);
399   DALI_TEST_EQUALS(renderer.GetCurrentProperty<int>(Renderer::Property::DEPTH_INDEX), 1, TEST_LOCATION);
400
401   renderer.SetProperty(Renderer::Property::DEPTH_INDEX, 10);
402
403   DALI_TEST_EQUALS(renderer.GetProperty<int>(Renderer::Property::DEPTH_INDEX), 10, TEST_LOCATION);
404   DALI_TEST_EQUALS(renderer.GetCurrentProperty<int>(Renderer::Property::DEPTH_INDEX), 1, TEST_LOCATION);
405
406   application.SendNotification();
407   application.Render(0);
408   DALI_TEST_EQUALS(renderer.GetCurrentProperty<int>(Renderer::Property::DEPTH_INDEX), 10, TEST_LOCATION);
409
410   END_TEST;
411 }
412
413 int UtcDaliRendererSetGetFaceCullingMode(void)
414 {
415   TestApplication application;
416
417   tet_infoline("Test SetFaceCullingMode(cullingMode)");
418   Geometry geometry = CreateQuadGeometry();
419   Shader   shader   = CreateShader();
420   Renderer renderer = Renderer::New(geometry, shader);
421
422   Actor actor = Actor::New();
423   actor.AddRenderer(renderer);
424   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
425   application.GetScene().Add(actor);
426
427   // By default, none of the faces should be culled
428   unsigned int cullFace = renderer.GetProperty<int>(Renderer::Property::FACE_CULLING_MODE);
429   DALI_TEST_CHECK(static_cast<FaceCullingMode::Type>(cullFace) == FaceCullingMode::NONE);
430
431   TestGlAbstraction& gl            = application.GetGlAbstraction();
432   TraceCallStack&    cullFaceStack = gl.GetCullFaceTrace();
433   gl.EnableCullFaceCallTrace(true);
434
435   {
436     cullFaceStack.Reset();
437     renderer.SetProperty(Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::FRONT_AND_BACK);
438     application.SendNotification();
439     application.Render();
440
441     DALI_TEST_EQUALS(cullFaceStack.CountMethod("CullFace"), 1, TEST_LOCATION);
442
443     std::ostringstream cullModeString;
444     cullModeString << GL_FRONT_AND_BACK;
445
446     DALI_TEST_CHECK(cullFaceStack.FindMethodAndParams("CullFace", cullModeString.str()));
447     cullFace = renderer.GetProperty<int>(Renderer::Property::FACE_CULLING_MODE);
448     DALI_TEST_CHECK(static_cast<FaceCullingMode::Type>(cullFace) == FaceCullingMode::FRONT_AND_BACK);
449   }
450
451   {
452     cullFaceStack.Reset();
453     renderer.SetProperty(Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::BACK);
454     application.SendNotification();
455     application.Render();
456
457     DALI_TEST_EQUALS(cullFaceStack.CountMethod("CullFace"), 1, TEST_LOCATION);
458
459     std::ostringstream cullModeString;
460     cullModeString << GL_BACK;
461
462     DALI_TEST_CHECK(cullFaceStack.FindMethodAndParams("CullFace", cullModeString.str()));
463     cullFace = renderer.GetProperty<int>(Renderer::Property::FACE_CULLING_MODE);
464     DALI_TEST_CHECK(static_cast<FaceCullingMode::Type>(cullFace) == FaceCullingMode::BACK);
465   }
466
467   {
468     cullFaceStack.Reset();
469     renderer.SetProperty(Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::FRONT);
470     application.SendNotification();
471     application.Render();
472
473     DALI_TEST_EQUALS(cullFaceStack.CountMethod("CullFace"), 1, TEST_LOCATION);
474
475     std::ostringstream cullModeString;
476     cullModeString << GL_FRONT;
477
478     DALI_TEST_CHECK(cullFaceStack.FindMethodAndParams("CullFace", cullModeString.str()));
479     cullFace = renderer.GetProperty<int>(Renderer::Property::FACE_CULLING_MODE);
480     DALI_TEST_CHECK(static_cast<FaceCullingMode::Type>(cullFace) == FaceCullingMode::FRONT);
481   }
482
483   {
484     cullFaceStack.Reset();
485     renderer.SetProperty(Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::NONE);
486     application.SendNotification();
487     application.Render();
488
489     DALI_TEST_EQUALS(cullFaceStack.CountMethod("CullFace"), 0, TEST_LOCATION);
490     cullFace = renderer.GetProperty<int>(Renderer::Property::FACE_CULLING_MODE);
491     DALI_TEST_CHECK(static_cast<FaceCullingMode::Type>(cullFace) == FaceCullingMode::NONE);
492   }
493
494   END_TEST;
495 }
496
497 int UtcDaliRendererBlendOptions01(void)
498 {
499   TestApplication application;
500
501   tet_infoline("Test BLEND_FACTOR properties ");
502
503   Geometry geometry = CreateQuadGeometry();
504   Shader   shader   = CreateShader();
505   Renderer renderer = Renderer::New(geometry, shader);
506
507   Actor actor = Actor::New();
508   // set a transparent actor color so that blending is enabled
509   actor.SetProperty(Actor::Property::OPACITY, 0.5f);
510   actor.AddRenderer(renderer);
511   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
512   application.GetScene().Add(actor);
513
514   renderer.SetProperty(Renderer::Property::BLEND_FACTOR_SRC_RGB, BlendFactor::ONE_MINUS_SRC_COLOR);
515   renderer.SetProperty(Renderer::Property::BLEND_FACTOR_DEST_RGB, BlendFactor::SRC_ALPHA_SATURATE);
516   renderer.SetProperty(Renderer::Property::BLEND_FACTOR_SRC_ALPHA, BlendFactor::ONE_MINUS_SRC_COLOR);
517   renderer.SetProperty(Renderer::Property::BLEND_FACTOR_DEST_ALPHA, BlendFactor::SRC_ALPHA_SATURATE);
518
519   // Test that Set was successful:
520   int srcFactorRgb    = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
521   int destFactorRgb   = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
522   int srcFactorAlpha  = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
523   int destFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
524
525   DALI_TEST_EQUALS((int)BlendFactor::ONE_MINUS_SRC_COLOR, srcFactorRgb, TEST_LOCATION);
526   DALI_TEST_EQUALS((int)BlendFactor::SRC_ALPHA_SATURATE, destFactorRgb, TEST_LOCATION);
527   DALI_TEST_EQUALS((int)BlendFactor::ONE_MINUS_SRC_COLOR, srcFactorAlpha, TEST_LOCATION);
528   DALI_TEST_EQUALS((int)BlendFactor::SRC_ALPHA_SATURATE, destFactorAlpha, TEST_LOCATION);
529
530   application.SendNotification();
531   application.Render();
532
533   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
534
535   DALI_TEST_EQUALS((GLenum)GL_ONE_MINUS_SRC_COLOR, glAbstraction.GetLastBlendFuncSrcRgb(), TEST_LOCATION);
536   DALI_TEST_EQUALS((GLenum)GL_SRC_ALPHA_SATURATE, glAbstraction.GetLastBlendFuncDstRgb(), TEST_LOCATION);
537   DALI_TEST_EQUALS((GLenum)GL_ONE_MINUS_SRC_COLOR, glAbstraction.GetLastBlendFuncSrcAlpha(), TEST_LOCATION);
538   DALI_TEST_EQUALS((GLenum)GL_SRC_ALPHA_SATURATE, glAbstraction.GetLastBlendFuncDstAlpha(), TEST_LOCATION);
539
540   END_TEST;
541 }
542
543 int UtcDaliRendererBlendOptions02(void)
544 {
545   TestApplication application;
546
547   tet_infoline("Test BLEND_FACTOR properties ");
548
549   Geometry geometry = CreateQuadGeometry();
550   Shader   shader   = CreateShader();
551   Renderer renderer = Renderer::New(geometry, shader);
552
553   Actor actor = Actor::New();
554   actor.SetProperty(Actor::Property::OPACITY, 0.5f); // enable blending
555   actor.AddRenderer(renderer);
556   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
557   application.GetScene().Add(actor);
558
559   renderer.SetProperty(Renderer::Property::BLEND_FACTOR_SRC_RGB, BlendFactor::CONSTANT_COLOR);
560   renderer.SetProperty(Renderer::Property::BLEND_FACTOR_DEST_RGB, BlendFactor::ONE_MINUS_CONSTANT_COLOR);
561   renderer.SetProperty(Renderer::Property::BLEND_FACTOR_SRC_ALPHA, BlendFactor::CONSTANT_ALPHA);
562   renderer.SetProperty(Renderer::Property::BLEND_FACTOR_DEST_ALPHA, BlendFactor::ONE_MINUS_CONSTANT_ALPHA);
563
564   // Test that Set was successful:
565   {
566     int srcFactorRgb    = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
567     int destFactorRgb   = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
568     int srcFactorAlpha  = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
569     int destFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
570
571     DALI_TEST_EQUALS((int)BlendFactor::CONSTANT_COLOR, srcFactorRgb, TEST_LOCATION);
572     DALI_TEST_EQUALS((int)BlendFactor::ONE_MINUS_CONSTANT_COLOR, destFactorRgb, TEST_LOCATION);
573     DALI_TEST_EQUALS((int)BlendFactor::CONSTANT_ALPHA, srcFactorAlpha, TEST_LOCATION);
574     DALI_TEST_EQUALS((int)BlendFactor::ONE_MINUS_CONSTANT_ALPHA, destFactorAlpha, TEST_LOCATION);
575   }
576
577   application.SendNotification();
578   application.Render();
579
580   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
581   DALI_TEST_EQUALS((GLenum)GL_CONSTANT_COLOR, glAbstraction.GetLastBlendFuncSrcRgb(), TEST_LOCATION);
582   DALI_TEST_EQUALS((GLenum)GL_ONE_MINUS_CONSTANT_COLOR, glAbstraction.GetLastBlendFuncDstRgb(), TEST_LOCATION);
583   DALI_TEST_EQUALS((GLenum)GL_CONSTANT_ALPHA, glAbstraction.GetLastBlendFuncSrcAlpha(), TEST_LOCATION);
584   DALI_TEST_EQUALS((GLenum)GL_ONE_MINUS_CONSTANT_ALPHA, glAbstraction.GetLastBlendFuncDstAlpha(), TEST_LOCATION);
585
586   END_TEST;
587 }
588
589 int UtcDaliRendererBlendOptions03(void)
590 {
591   TestApplication application;
592
593   tet_infoline("Test GetBlendEquation() defaults ");
594
595   Geometry geometry = CreateQuadGeometry();
596   Shader   shader   = CreateShader();
597   Renderer renderer = Renderer::New(geometry, shader);
598
599   Actor actor = Actor::New();
600   actor.AddRenderer(renderer);
601   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
602   application.GetScene().Add(actor);
603
604   // Test the defaults as documented in blending.h
605   int equationRgb   = renderer.GetProperty<int>(Renderer::Property::BLEND_EQUATION_RGB);
606   int equationAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_EQUATION_ALPHA);
607
608   DALI_TEST_EQUALS((int)BlendEquation::ADD, equationRgb, TEST_LOCATION);
609   DALI_TEST_EQUALS((int)BlendEquation::ADD, equationAlpha, TEST_LOCATION);
610
611   END_TEST;
612 }
613
614 int UtcDaliRendererBlendOptions04(void)
615 {
616   TestApplication application;
617
618   tet_infoline("Test SetBlendEquation() ");
619
620   Geometry geometry = CreateQuadGeometry();
621   Shader   shader   = CreateShader();
622   Renderer renderer = Renderer::New(geometry, shader);
623
624   Actor actor = Actor::New();
625   actor.SetProperty(Actor::Property::OPACITY, 0.1f);
626   actor.AddRenderer(renderer);
627   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
628   application.GetScene().Add(actor);
629
630   // Test the single blending equation setting
631   {
632     renderer.SetProperty(Renderer::Property::BLEND_EQUATION_RGB, BlendEquation::REVERSE_SUBTRACT);
633     int equationRgb = renderer.GetProperty<int>(Renderer::Property::BLEND_EQUATION_RGB);
634     DALI_TEST_EQUALS((int)BlendEquation::REVERSE_SUBTRACT, equationRgb, TEST_LOCATION);
635   }
636
637   renderer.SetProperty(Renderer::Property::BLEND_EQUATION_RGB, BlendEquation::REVERSE_SUBTRACT);
638   renderer.SetProperty(Renderer::Property::BLEND_EQUATION_ALPHA, BlendEquation::REVERSE_SUBTRACT);
639
640   // Test that Set was successful
641   {
642     int equationRgb   = renderer.GetProperty<int>(Renderer::Property::BLEND_EQUATION_RGB);
643     int equationAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_EQUATION_ALPHA);
644     DALI_TEST_EQUALS((int)BlendEquation::REVERSE_SUBTRACT, equationRgb, TEST_LOCATION);
645     DALI_TEST_EQUALS((int)BlendEquation::REVERSE_SUBTRACT, equationAlpha, TEST_LOCATION);
646   }
647
648   // Render & check GL commands
649   application.SendNotification();
650   application.Render();
651
652   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
653   DALI_TEST_EQUALS((GLenum)GL_FUNC_REVERSE_SUBTRACT, glAbstraction.GetLastBlendEquationRgb(), TEST_LOCATION);
654   DALI_TEST_EQUALS((GLenum)GL_FUNC_REVERSE_SUBTRACT, glAbstraction.GetLastBlendEquationAlpha(), TEST_LOCATION);
655
656   END_TEST;
657 }
658
659 int UtcDaliRendererBlendOptions05(void)
660 {
661   TestApplication application;
662
663   tet_infoline("Test SetAdvancedBlendEquation ");
664
665   Geometry geometry = CreateQuadGeometry();
666   Shader shader = CreateShader();
667   Renderer renderer = Renderer::New( geometry, shader );
668
669   Actor actor = Actor::New();
670   actor.SetProperty(Actor::Property::OPACITY, 0.1f);
671
672   actor.AddRenderer(renderer);
673   actor.SetProperty(Actor::Property::SIZE, Vector2(400, 400));
674   application.GetScene().Add(actor);
675
676   if( Dali::Capabilities::IsBlendEquationSupported( DevelBlendEquation::MAX ) )
677   {
678     renderer.SetProperty( DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::MAX );
679     int equationRgb = renderer.GetProperty<int>( DevelRenderer::Property::BLEND_EQUATION );
680     DALI_TEST_EQUALS( (int)DevelBlendEquation::MAX, equationRgb, TEST_LOCATION );
681   }
682
683   if( Dali::Capabilities::IsBlendEquationSupported( DevelBlendEquation::SCREEN ) )
684   {
685     renderer.SetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, true );
686     renderer.SetProperty( DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::SCREEN );
687     int equation = renderer.GetProperty<int>( DevelRenderer::Property::BLEND_EQUATION );
688
689     DALI_TEST_EQUALS( (int)DevelBlendEquation::SCREEN, equation, TEST_LOCATION );
690     DALI_TEST_EQUALS( DevelRenderer::IsAdvancedBlendEquationApplied( renderer ), true, TEST_LOCATION );
691
692     application.SendNotification();
693     application.Render();
694   }
695
696   if( Dali::Capabilities::IsBlendEquationSupported( DevelBlendEquation::SCREEN ) &&
697       Dali::Capabilities::IsBlendEquationSupported( DevelBlendEquation::MULTIPLY ) )
698   {
699     renderer.SetProperty( DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::ADD );
700     renderer.SetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, true );
701     renderer.SetProperty( DevelRenderer::Property::BLEND_EQUATION_RGB, DevelBlendEquation::SCREEN );
702     renderer.SetProperty( DevelRenderer::Property::BLEND_EQUATION_ALPHA, DevelBlendEquation::MULTIPLY );
703     int equationRgb = renderer.GetProperty<int>( DevelRenderer::Property::BLEND_EQUATION_RGB );
704     int equationAlpha = renderer.GetProperty<int>( DevelRenderer::Property::BLEND_EQUATION_ALPHA );
705
706     DALI_TEST_EQUALS( (int)DevelBlendEquation::ADD, equationRgb, TEST_LOCATION );
707     DALI_TEST_EQUALS( (int)DevelBlendEquation::ADD, equationAlpha, TEST_LOCATION );
708     DALI_TEST_EQUALS( DevelRenderer::IsAdvancedBlendEquationApplied( renderer ), false, TEST_LOCATION );
709
710     application.SendNotification();
711     application.Render();
712   }
713
714   tet_infoline("Error Checking\n");
715   if( Dali::Capabilities::IsBlendEquationSupported( DevelBlendEquation::MULTIPLY ) &&
716       Dali::Capabilities::IsBlendEquationSupported( DevelBlendEquation::SCREEN ) &&
717       Dali::Capabilities::IsBlendEquationSupported( DevelBlendEquation::OVERLAY ) &&
718       Dali::Capabilities::IsBlendEquationSupported( DevelBlendEquation::DARKEN ) &&
719       Dali::Capabilities::IsBlendEquationSupported( DevelBlendEquation::LIGHTEN ) &&
720       Dali::Capabilities::IsBlendEquationSupported( DevelBlendEquation::COLOR_DODGE ) &&
721       Dali::Capabilities::IsBlendEquationSupported( DevelBlendEquation::COLOR_BURN ) &&
722       Dali::Capabilities::IsBlendEquationSupported( DevelBlendEquation::HARD_LIGHT ) &&
723       Dali::Capabilities::IsBlendEquationSupported( DevelBlendEquation::SOFT_LIGHT ) &&
724       Dali::Capabilities::IsBlendEquationSupported( DevelBlendEquation::DIFFERENCE ) &&
725       Dali::Capabilities::IsBlendEquationSupported( DevelBlendEquation::EXCLUSION ) &&
726       Dali::Capabilities::IsBlendEquationSupported( DevelBlendEquation::HUE ) &&
727       Dali::Capabilities::IsBlendEquationSupported( DevelBlendEquation::SATURATION ) &&
728       Dali::Capabilities::IsBlendEquationSupported( DevelBlendEquation::COLOR ) &&
729       Dali::Capabilities::IsBlendEquationSupported( DevelBlendEquation::LUMINOSITY ) )
730   {
731     renderer.SetProperty( DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::MULTIPLY );
732     DALI_TEST_EQUALS( (int)DevelBlendEquation::MULTIPLY, renderer.GetProperty<int>( DevelRenderer::Property::BLEND_EQUATION ), TEST_LOCATION );
733
734     renderer.SetProperty( DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::SCREEN );
735     DALI_TEST_EQUALS( (int)DevelBlendEquation::SCREEN, renderer.GetProperty<int>( DevelRenderer::Property::BLEND_EQUATION ), TEST_LOCATION );
736
737     renderer.SetProperty( DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::OVERLAY );
738     DALI_TEST_EQUALS( (int)DevelBlendEquation::OVERLAY, renderer.GetProperty<int>( DevelRenderer::Property::BLEND_EQUATION ), TEST_LOCATION );
739
740     renderer.SetProperty( DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::DARKEN );
741     DALI_TEST_EQUALS( (int)DevelBlendEquation::DARKEN, renderer.GetProperty<int>( DevelRenderer::Property::BLEND_EQUATION ), TEST_LOCATION );
742
743     renderer.SetProperty( DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::LIGHTEN );
744     DALI_TEST_EQUALS( (int)DevelBlendEquation::LIGHTEN, renderer.GetProperty<int>( DevelRenderer::Property::BLEND_EQUATION ), TEST_LOCATION );
745
746     renderer.SetProperty( DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::COLOR_DODGE );
747     DALI_TEST_EQUALS( (int)DevelBlendEquation::COLOR_DODGE, renderer.GetProperty<int>( DevelRenderer::Property::BLEND_EQUATION ), TEST_LOCATION );
748
749     renderer.SetProperty( DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::COLOR_BURN );
750     DALI_TEST_EQUALS( (int)DevelBlendEquation::COLOR_BURN, renderer.GetProperty<int>( DevelRenderer::Property::BLEND_EQUATION ), TEST_LOCATION );
751
752     renderer.SetProperty( DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::HARD_LIGHT );
753     DALI_TEST_EQUALS( (int)DevelBlendEquation::HARD_LIGHT, renderer.GetProperty<int>( DevelRenderer::Property::BLEND_EQUATION ), TEST_LOCATION );
754
755     renderer.SetProperty( DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::SOFT_LIGHT );
756     DALI_TEST_EQUALS( (int)DevelBlendEquation::SOFT_LIGHT, renderer.GetProperty<int>( DevelRenderer::Property::BLEND_EQUATION ), TEST_LOCATION );
757
758     renderer.SetProperty( DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::DIFFERENCE );
759     DALI_TEST_EQUALS( (int)DevelBlendEquation::DIFFERENCE, renderer.GetProperty<int>( DevelRenderer::Property::BLEND_EQUATION ), TEST_LOCATION );
760
761     renderer.SetProperty( DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::EXCLUSION );
762     DALI_TEST_EQUALS( (int)DevelBlendEquation::EXCLUSION, renderer.GetProperty<int>( DevelRenderer::Property::BLEND_EQUATION ), TEST_LOCATION );
763
764     renderer.SetProperty( DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::HUE );
765     DALI_TEST_EQUALS( (int)DevelBlendEquation::HUE, renderer.GetProperty<int>( DevelRenderer::Property::BLEND_EQUATION ), TEST_LOCATION );
766
767     renderer.SetProperty( DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::SATURATION );
768     DALI_TEST_EQUALS( (int)DevelBlendEquation::SATURATION, renderer.GetProperty<int>( DevelRenderer::Property::BLEND_EQUATION ), TEST_LOCATION );
769
770     renderer.SetProperty( DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::COLOR );
771     DALI_TEST_EQUALS( (int)DevelBlendEquation::COLOR, renderer.GetProperty<int>( DevelRenderer::Property::BLEND_EQUATION ), TEST_LOCATION );
772
773     renderer.SetProperty( DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::LUMINOSITY );
774     DALI_TEST_EQUALS( (int)DevelBlendEquation::LUMINOSITY, renderer.GetProperty<int>( DevelRenderer::Property::BLEND_EQUATION ), TEST_LOCATION );
775   }
776
777   END_TEST;
778 }
779
780 int UtcDaliRendererSetBlendMode01(void)
781 {
782   TestApplication application;
783
784   tet_infoline("Test setting the blend mode to on with an opaque color renders with blending enabled");
785
786   Geometry geometry = CreateQuadGeometry();
787   Shader   shader   = CreateShader();
788   Renderer renderer = Renderer::New(geometry, shader);
789
790   Actor actor = Actor::New();
791   actor.SetProperty(Actor::Property::OPACITY, 0.98f);
792   actor.AddRenderer(renderer);
793   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
794   application.GetScene().Add(actor);
795
796   renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON);
797
798   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
799   glAbstraction.EnableEnableDisableCallTrace(true);
800
801   application.SendNotification();
802   application.Render();
803
804   TraceCallStack&    glEnableStack = glAbstraction.GetEnableDisableTrace();
805   std::ostringstream blendStr;
806   blendStr << GL_BLEND;
807   DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str().c_str()));
808
809   END_TEST;
810 }
811
812 int UtcDaliRendererSetBlendMode01b(void)
813 {
814   TestApplication application;
815
816   tet_infoline("Test setting the blend mode to on with an transparent color renders with blending enabled");
817
818   Geometry geometry = CreateQuadGeometry();
819   Shader   shader   = CreateShader();
820   Renderer renderer = Renderer::New(geometry, shader);
821
822   Actor actor = Actor::New();
823   actor.SetProperty(Actor::Property::OPACITY, 0.0f);
824   actor.AddRenderer(renderer);
825   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
826   application.GetScene().Add(actor);
827
828   renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON);
829
830   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
831   glAbstraction.EnableEnableDisableCallTrace(true);
832   glAbstraction.EnableDrawCallTrace(true);
833
834   application.SendNotification();
835   application.Render();
836
837   TraceCallStack&    glEnableStack = glAbstraction.GetEnableDisableTrace();
838   std::ostringstream blendStr;
839   blendStr << GL_BLEND;
840   DALI_TEST_CHECK(!glEnableStack.FindMethod("Enable"));
841
842   DALI_TEST_CHECK(!glAbstraction.GetDrawTrace().FindMethod("DrawElements"));
843
844   END_TEST;
845 }
846
847 int UtcDaliRendererSetBlendMode02(void)
848 {
849   TestApplication application;
850
851   tet_infoline("Test setting the blend mode to off with a transparent color renders with blending disabled (and not enabled)");
852
853   Geometry geometry = CreateQuadGeometry();
854   Shader   shader   = CreateShader();
855   Renderer renderer = Renderer::New(geometry, shader);
856
857   Actor actor = Actor::New();
858   actor.SetProperty(Actor::Property::OPACITY, 0.15f);
859   actor.AddRenderer(renderer);
860   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
861   application.GetScene().Add(actor);
862
863   renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::OFF);
864
865   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
866   glAbstraction.EnableEnableDisableCallTrace(true);
867
868   application.SendNotification();
869   application.Render();
870
871   TraceCallStack&    glEnableStack = glAbstraction.GetEnableDisableTrace();
872   std::ostringstream blendStr;
873   blendStr << GL_BLEND;
874   DALI_TEST_CHECK(!glEnableStack.FindMethodAndParams("Enable", blendStr.str().c_str()));
875
876   END_TEST;
877 }
878
879 int UtcDaliRendererSetBlendMode03(void)
880 {
881   TestApplication application;
882
883   tet_infoline("Test setting the blend mode to auto with a transparent color renders with blending enabled");
884
885   Geometry geometry = CreateQuadGeometry();
886   Shader   shader   = CreateShader();
887   Renderer renderer = Renderer::New(geometry, shader);
888
889   Actor actor = Actor::New();
890   actor.SetProperty(Actor::Property::OPACITY, 0.75f);
891   actor.AddRenderer(renderer);
892   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
893   application.GetScene().Add(actor);
894
895   renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::AUTO);
896
897   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
898   glAbstraction.EnableEnableDisableCallTrace(true);
899
900   application.SendNotification();
901   application.Render();
902
903   TraceCallStack&    glEnableStack = glAbstraction.GetEnableDisableTrace();
904   std::ostringstream blendStr;
905   blendStr << GL_BLEND;
906   DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str().c_str()));
907
908   END_TEST;
909 }
910
911 int UtcDaliRendererSetBlendMode04(void)
912 {
913   TestApplication application;
914
915   tet_infoline("Test setting the blend mode to auto with an opaque color renders with blending disabled");
916
917   Geometry geometry = CreateQuadGeometry();
918   Shader   shader   = CreateShader();
919   Renderer renderer = Renderer::New(geometry, shader);
920
921   Actor actor = Actor::New();
922   actor.AddRenderer(renderer);
923   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
924   application.GetScene().Add(actor);
925
926   renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::AUTO);
927
928   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
929   glAbstraction.EnableEnableDisableCallTrace(true);
930
931   application.SendNotification();
932   application.Render();
933
934   TraceCallStack&    glEnableStack = glAbstraction.GetEnableDisableTrace();
935   std::ostringstream blendStr;
936   blendStr << GL_BLEND;
937   DALI_TEST_CHECK(!glEnableStack.FindMethodAndParams("Enable", blendStr.str().c_str()));
938
939   END_TEST;
940 }
941
942 int UtcDaliRendererSetBlendMode04b(void)
943 {
944   TestApplication application;
945
946   tet_infoline("Test setting the blend mode to auto with a transparent actor color renders with blending enabled");
947
948   Geometry geometry = CreateQuadGeometry();
949   Shader   shader   = CreateShader();
950   Renderer renderer = Renderer::New(geometry, shader);
951
952   Actor actor = Actor::New();
953   actor.AddRenderer(renderer);
954   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
955   actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 0.5f));
956   application.GetScene().Add(actor);
957
958   renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::AUTO);
959
960   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
961   glAbstraction.EnableEnableDisableCallTrace(true);
962
963   application.SendNotification();
964   application.Render();
965
966   TraceCallStack&    glEnableStack = glAbstraction.GetEnableDisableTrace();
967   std::ostringstream blendStr;
968   blendStr << GL_BLEND;
969   DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str().c_str()));
970
971   END_TEST;
972 }
973
974 int UtcDaliRendererSetBlendMode04c(void)
975 {
976   TestApplication application;
977
978   tet_infoline("Test setting the blend mode to auto with an opaque opaque actor color renders with blending disabled");
979
980   Geometry geometry = CreateQuadGeometry();
981   Shader   shader   = CreateShader();
982   Renderer renderer = Renderer::New(geometry, shader);
983
984   Actor actor = Actor::New();
985   actor.AddRenderer(renderer);
986   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
987   actor.SetProperty(Actor::Property::COLOR, Color::MAGENTA);
988   application.GetScene().Add(actor);
989
990   renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::AUTO);
991
992   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
993   glAbstraction.EnableEnableDisableCallTrace(true);
994
995   application.SendNotification();
996   application.Render();
997
998   TraceCallStack&    glEnableStack = glAbstraction.GetEnableDisableTrace();
999   std::ostringstream blendStr;
1000   blendStr << GL_BLEND;
1001   DALI_TEST_CHECK(!glEnableStack.FindMethodAndParams("Enable", blendStr.str().c_str()));
1002
1003   END_TEST;
1004 }
1005
1006 int UtcDaliRendererSetBlendMode05(void)
1007 {
1008   TestApplication application;
1009
1010   tet_infoline("Test setting the blend mode to auto with an opaque color and an image with an alpha channel renders with blending enabled");
1011
1012   Geometry geometry = CreateQuadGeometry();
1013   Texture  image    = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 40, 40);
1014
1015   Shader     shader     = CreateShader();
1016   TextureSet textureSet = CreateTextureSet(image);
1017   Renderer   renderer   = Renderer::New(geometry, shader);
1018   renderer.SetTextures(textureSet);
1019
1020   Actor actor = Actor::New();
1021   actor.AddRenderer(renderer);
1022   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1023   application.GetScene().Add(actor);
1024
1025   renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::AUTO);
1026
1027   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1028   glAbstraction.EnableEnableDisableCallTrace(true);
1029
1030   application.SendNotification();
1031   application.Render();
1032
1033   TraceCallStack&    glEnableStack = glAbstraction.GetEnableDisableTrace();
1034   std::ostringstream blendStr;
1035   blendStr << GL_BLEND;
1036   DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str().c_str()));
1037
1038   END_TEST;
1039 }
1040
1041 int UtcDaliRendererSetBlendMode06(void)
1042 {
1043   TestApplication application;
1044   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");
1045
1046   Geometry geometry = CreateQuadGeometry();
1047   Shader   shader   = Shader::New("vertexSrc", "fragmentSrc", Shader::Hint::OUTPUT_IS_TRANSPARENT);
1048
1049   Renderer renderer = Renderer::New(geometry, shader);
1050
1051   Actor actor = Actor::New();
1052   actor.AddRenderer(renderer);
1053   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1054   application.GetScene().Add(actor);
1055
1056   renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::AUTO);
1057
1058   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1059   glAbstraction.EnableEnableDisableCallTrace(true);
1060
1061   application.SendNotification();
1062   application.Render();
1063
1064   TraceCallStack&    glEnableStack = glAbstraction.GetEnableDisableTrace();
1065   std::ostringstream blendStr;
1066   blendStr << GL_BLEND;
1067   DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str().c_str()));
1068
1069   END_TEST;
1070 }
1071
1072 int UtcDaliRendererSetBlendMode07(void)
1073 {
1074   TestApplication application;
1075   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");
1076
1077   Geometry geometry = CreateQuadGeometry();
1078   Shader   shader   = Shader::New("vertexSrc", "fragmentSrc");
1079
1080   Texture    image      = Texture::New(TextureType::TEXTURE_2D, Pixel::RGB888, 50, 50);
1081   TextureSet textureSet = CreateTextureSet(image);
1082   Renderer   renderer   = Renderer::New(geometry, shader);
1083   renderer.SetTextures(textureSet);
1084
1085   Actor actor = Actor::New();
1086   actor.AddRenderer(renderer);
1087   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1088   application.GetScene().Add(actor);
1089
1090   renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::AUTO);
1091
1092   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1093   glAbstraction.EnableEnableDisableCallTrace(true);
1094
1095   application.SendNotification();
1096   application.Render();
1097
1098   TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
1099   DALI_TEST_CHECK(!glEnableStack.FindMethodAndParams("Enable", "GL_BLEND"));
1100
1101   END_TEST;
1102 }
1103
1104 int UtcDaliRendererGetBlendMode(void)
1105 {
1106   TestApplication application;
1107
1108   tet_infoline("Test GetBlendMode()");
1109
1110   Geometry geometry = CreateQuadGeometry();
1111   Shader   shader   = Shader::New("vertexSrc", "fragmentSrc");
1112   Renderer renderer = Renderer::New(geometry, shader);
1113
1114   // default value
1115   unsigned int mode = renderer.GetProperty<int>(Renderer::Property::BLEND_MODE);
1116   DALI_TEST_EQUALS(static_cast<BlendMode::Type>(mode), BlendMode::AUTO, TEST_LOCATION);
1117
1118   // ON
1119   renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON);
1120   mode = renderer.GetProperty<int>(Renderer::Property::BLEND_MODE);
1121   DALI_TEST_EQUALS(static_cast<BlendMode::Type>(mode), BlendMode::ON, TEST_LOCATION);
1122
1123   // OFF
1124   renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::OFF);
1125   mode = renderer.GetProperty<int>(Renderer::Property::BLEND_MODE);
1126   DALI_TEST_EQUALS(static_cast<BlendMode::Type>(mode), BlendMode::OFF, TEST_LOCATION);
1127
1128   END_TEST;
1129 }
1130
1131 int UtcDaliRendererSetBlendColor(void)
1132 {
1133   TestApplication application;
1134
1135   tet_infoline("Test SetBlendColor(color)");
1136
1137   Geometry   geometry   = CreateQuadGeometry();
1138   Shader     shader     = Shader::New("vertexSrc", "fragmentSrc");
1139   TextureSet textureSet = TextureSet::New();
1140   Texture    image      = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 50, 50);
1141   textureSet.SetTexture(0u, image);
1142   Renderer renderer = Renderer::New(geometry, shader);
1143   renderer.SetTextures(textureSet);
1144
1145   Actor actor = Actor::New();
1146   actor.AddRenderer(renderer);
1147   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1148   application.GetScene().Add(actor);
1149
1150   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1151
1152   renderer.SetProperty(Renderer::Property::BLEND_COLOR, Color::TRANSPARENT);
1153
1154   application.SendNotification();
1155   application.Render();
1156
1157   DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::TRANSPARENT, TEST_LOCATION);
1158   DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::TRANSPARENT, TEST_LOCATION);
1159   DALI_TEST_EQUALS(glAbstraction.GetLastBlendColor(), Color::TRANSPARENT, TEST_LOCATION);
1160
1161   renderer.SetProperty(Renderer::Property::BLEND_COLOR, Color::MAGENTA);
1162
1163   DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::MAGENTA, TEST_LOCATION);
1164   DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::TRANSPARENT, TEST_LOCATION);
1165
1166   application.SendNotification();
1167   application.Render();
1168
1169   DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::MAGENTA, TEST_LOCATION);
1170   DALI_TEST_EQUALS(glAbstraction.GetLastBlendColor(), Color::MAGENTA, TEST_LOCATION);
1171
1172   Vector4 color(0.1f, 0.2f, 0.3f, 0.4f);
1173   renderer.SetProperty(Renderer::Property::BLEND_COLOR, color);
1174   application.SendNotification();
1175   application.Render();
1176   DALI_TEST_EQUALS(glAbstraction.GetLastBlendColor(), color, TEST_LOCATION);
1177
1178   END_TEST;
1179 }
1180
1181 int UtcDaliRendererGetBlendColor(void)
1182 {
1183   TestApplication application;
1184
1185   tet_infoline("Test GetBlendColor()");
1186
1187   Geometry geometry = CreateQuadGeometry();
1188   Shader   shader   = Shader::New("vertexSrc", "fragmentSrc");
1189   Renderer renderer = Renderer::New(geometry, shader);
1190
1191   DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::TRANSPARENT, TEST_LOCATION);
1192
1193   renderer.SetProperty(Renderer::Property::BLEND_COLOR, Color::MAGENTA);
1194   application.SendNotification();
1195   application.Render();
1196   DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), Color::MAGENTA, TEST_LOCATION);
1197
1198   Vector4 color(0.1f, 0.2f, 0.3f, 0.4f);
1199   renderer.SetProperty(Renderer::Property::BLEND_COLOR, color);
1200   application.SendNotification();
1201   application.Render();
1202   DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(Renderer::Property::BLEND_COLOR), color, TEST_LOCATION);
1203
1204   END_TEST;
1205 }
1206
1207 int UtcDaliRendererPreMultipledAlpha(void)
1208 {
1209   TestApplication application;
1210
1211   tet_infoline("Test BLEND_PRE_MULTIPLIED_ALPHA property");
1212
1213   Geometry geometry = CreateQuadGeometry();
1214   Shader   shader   = Shader::New("vertexSrc", "fragmentSrc");
1215   Renderer renderer = Renderer::New(geometry, shader);
1216
1217   Actor actor = Actor::New();
1218   actor.AddRenderer(renderer);
1219   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1220   actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 0.5f));
1221   application.GetScene().Add(actor);
1222
1223   Property::Value value = renderer.GetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
1224   bool            preMultipliedAlpha;
1225   DALI_TEST_CHECK(value.Get(preMultipliedAlpha));
1226   DALI_TEST_CHECK(!preMultipliedAlpha);
1227
1228   int srcFactorRgb    = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
1229   int destFactorRgb   = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
1230   int srcFactorAlpha  = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
1231   int destFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
1232
1233   DALI_TEST_EQUALS((int)DEFAULT_BLEND_FACTOR_SRC_RGB, srcFactorRgb, TEST_LOCATION);
1234   DALI_TEST_EQUALS((int)DEFAULT_BLEND_FACTOR_DEST_RGB, destFactorRgb, TEST_LOCATION);
1235   DALI_TEST_EQUALS((int)DEFAULT_BLEND_FACTOR_SRC_ALPHA, srcFactorAlpha, TEST_LOCATION);
1236   DALI_TEST_EQUALS((int)DEFAULT_BLEND_FACTOR_DEST_ALPHA, destFactorAlpha, TEST_LOCATION);
1237
1238   application.SendNotification();
1239   application.Render();
1240
1241   Vector4            actualValue(Vector4::ZERO);
1242   TestGlAbstraction& gl = application.GetGlAbstraction();
1243   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uColor", actualValue));
1244   DALI_TEST_EQUALS(actualValue, Vector4(1.0f, 0.0f, 1.0f, 0.5f), TEST_LOCATION);
1245
1246   // Enable pre-multiplied alpha
1247   renderer.SetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, true);
1248
1249   application.SendNotification();
1250   application.Render();
1251
1252   value = renderer.GetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
1253   DALI_TEST_CHECK(value.Get(preMultipliedAlpha));
1254   DALI_TEST_CHECK(preMultipliedAlpha);
1255
1256   value = renderer.GetCurrentProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
1257   DALI_TEST_CHECK(value.Get(preMultipliedAlpha));
1258   DALI_TEST_CHECK(preMultipliedAlpha);
1259
1260   srcFactorRgb    = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
1261   destFactorRgb   = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
1262   srcFactorAlpha  = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
1263   destFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
1264
1265   DALI_TEST_EQUALS((int)BlendFactor::ONE, srcFactorRgb, TEST_LOCATION);
1266   DALI_TEST_EQUALS((int)BlendFactor::ONE_MINUS_SRC_ALPHA, destFactorRgb, TEST_LOCATION);
1267   DALI_TEST_EQUALS((int)BlendFactor::ONE, srcFactorAlpha, TEST_LOCATION);
1268   DALI_TEST_EQUALS((int)BlendFactor::ONE_MINUS_SRC_ALPHA, destFactorAlpha, TEST_LOCATION);
1269
1270   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uColor", actualValue));
1271   DALI_TEST_EQUALS(actualValue, Vector4(0.5f, 0.0f, 0.5f, 0.5f), TEST_LOCATION);
1272
1273   // Disable pre-multiplied alpha again
1274   renderer.SetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, false);
1275
1276   application.SendNotification();
1277   application.Render();
1278
1279   value = renderer.GetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
1280   DALI_TEST_CHECK(value.Get(preMultipliedAlpha));
1281   DALI_TEST_CHECK(!preMultipliedAlpha);
1282
1283   value = renderer.GetCurrentProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA);
1284   DALI_TEST_CHECK(value.Get(preMultipliedAlpha));
1285   DALI_TEST_CHECK(!preMultipliedAlpha);
1286
1287   srcFactorRgb    = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_RGB);
1288   destFactorRgb   = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_RGB);
1289   srcFactorAlpha  = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_SRC_ALPHA);
1290   destFactorAlpha = renderer.GetProperty<int>(Renderer::Property::BLEND_FACTOR_DEST_ALPHA);
1291
1292   DALI_TEST_EQUALS((int)BlendFactor::SRC_ALPHA, srcFactorRgb, TEST_LOCATION);
1293   DALI_TEST_EQUALS((int)BlendFactor::ONE_MINUS_SRC_ALPHA, destFactorRgb, TEST_LOCATION);
1294   DALI_TEST_EQUALS((int)BlendFactor::ONE, srcFactorAlpha, TEST_LOCATION);
1295   DALI_TEST_EQUALS((int)BlendFactor::ONE_MINUS_SRC_ALPHA, destFactorAlpha, TEST_LOCATION);
1296
1297   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uColor", actualValue));
1298   DALI_TEST_EQUALS(actualValue, Vector4(1.0f, 0.0f, 1.0f, 0.5f), TEST_LOCATION);
1299
1300   END_TEST;
1301 }
1302
1303 int UtcDaliRendererConstraint01(void)
1304 {
1305   TestApplication application;
1306
1307   tet_infoline("Test that a non-uniform renderer property can be constrained");
1308
1309   Shader   shader   = Shader::New("VertexSource", "FragmentSource");
1310   Geometry geometry = CreateQuadGeometry();
1311   Renderer renderer = Renderer::New(geometry, shader);
1312
1313   Actor actor = Actor::New();
1314   actor.AddRenderer(renderer);
1315   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1316   application.GetScene().Add(actor);
1317
1318   Vector4         initialColor = Color::WHITE;
1319   Property::Index colorIndex   = renderer.RegisterProperty("uFadeColor", initialColor);
1320
1321   application.SendNotification();
1322   application.Render(0);
1323   DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION);
1324
1325   // Apply constraint
1326   Constraint constraint = Constraint::New<Vector4>(renderer, colorIndex, TestConstraintNoBlue);
1327   constraint.Apply();
1328   application.SendNotification();
1329   application.Render(0);
1330
1331   // Expect no blue component in either buffer - yellow
1332   DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(colorIndex), Color::YELLOW, TEST_LOCATION);
1333   application.Render(0);
1334   DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(colorIndex), Color::YELLOW, TEST_LOCATION);
1335
1336   renderer.RemoveConstraints();
1337   renderer.SetProperty(colorIndex, Color::WHITE);
1338   application.SendNotification();
1339   application.Render(0);
1340   DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(colorIndex), Color::WHITE, TEST_LOCATION);
1341
1342   END_TEST;
1343 }
1344
1345 int UtcDaliRendererConstraint02(void)
1346 {
1347   TestApplication application;
1348
1349   tet_infoline("Test that a uniform map renderer property can be constrained");
1350
1351   Shader   shader   = Shader::New("VertexSource", "FragmentSource");
1352   Geometry geometry = CreateQuadGeometry();
1353   Renderer renderer = Renderer::New(geometry, shader);
1354
1355   Actor actor = Actor::New();
1356   actor.AddRenderer(renderer);
1357   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1358   application.GetScene().Add(actor);
1359   application.SendNotification();
1360   application.Render(0);
1361
1362   Vector4         initialColor = Color::WHITE;
1363   Property::Index colorIndex   = renderer.RegisterProperty("uFadeColor", initialColor);
1364
1365   TestGlAbstraction& gl = application.GetGlAbstraction();
1366
1367   application.SendNotification();
1368   application.Render(0);
1369
1370   Vector4 actualValue(Vector4::ZERO);
1371   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1372   DALI_TEST_EQUALS(actualValue, initialColor, TEST_LOCATION);
1373
1374   // Apply constraint
1375   Constraint constraint = Constraint::New<Vector4>(renderer, colorIndex, TestConstraintNoBlue);
1376   constraint.Apply();
1377   application.SendNotification();
1378   application.Render(0);
1379
1380   // Expect no blue component in either buffer - yellow
1381   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1382   DALI_TEST_EQUALS(actualValue, Color::YELLOW, TEST_LOCATION);
1383
1384   application.Render(0);
1385   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1386   DALI_TEST_EQUALS(actualValue, Color::YELLOW, TEST_LOCATION);
1387
1388   renderer.RemoveConstraints();
1389   renderer.SetProperty(colorIndex, Color::WHITE);
1390   application.SendNotification();
1391   application.Render(0);
1392
1393   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1394   DALI_TEST_EQUALS(actualValue, Color::WHITE, TEST_LOCATION);
1395
1396   END_TEST;
1397 }
1398
1399 int UtcDaliRendererAnimatedProperty01(void)
1400 {
1401   TestApplication application;
1402
1403   tet_infoline("Test that a non-uniform renderer property can be animated");
1404
1405   Shader   shader   = Shader::New("VertexSource", "FragmentSource");
1406   Geometry geometry = CreateQuadGeometry();
1407   Renderer renderer = Renderer::New(geometry, shader);
1408
1409   Actor actor = Actor::New();
1410   actor.AddRenderer(renderer);
1411   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1412   application.GetScene().Add(actor);
1413
1414   Vector4         initialColor = Color::WHITE;
1415   Property::Index colorIndex   = renderer.RegisterProperty("uFadeColor", initialColor);
1416
1417   application.SendNotification();
1418   application.Render(0);
1419   DALI_TEST_EQUALS(renderer.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION);
1420
1421   Animation animation = Animation::New(1.0f);
1422   KeyFrames keyFrames = KeyFrames::New();
1423   keyFrames.Add(0.0f, initialColor);
1424   keyFrames.Add(1.0f, Color::TRANSPARENT);
1425   animation.AnimateBetween(Property(renderer, colorIndex), keyFrames);
1426   animation.Play();
1427
1428   application.SendNotification();
1429   application.Render(500);
1430
1431   DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(colorIndex), Color::WHITE * 0.5f, TEST_LOCATION);
1432
1433   application.Render(500);
1434
1435   DALI_TEST_EQUALS(renderer.GetCurrentProperty<Vector4>(colorIndex), Color::TRANSPARENT, TEST_LOCATION);
1436
1437   END_TEST;
1438 }
1439
1440 int UtcDaliRendererAnimatedProperty02(void)
1441 {
1442   TestApplication application;
1443
1444   tet_infoline("Test that a uniform map renderer property can be animated");
1445
1446   Shader   shader   = Shader::New("VertexSource", "FragmentSource");
1447   Geometry geometry = CreateQuadGeometry();
1448   Renderer renderer = Renderer::New(geometry, shader);
1449
1450   Actor actor = Actor::New();
1451   actor.AddRenderer(renderer);
1452   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1453   application.GetScene().Add(actor);
1454   application.SendNotification();
1455   application.Render(0);
1456
1457   Vector4         initialColor = Color::WHITE;
1458   Property::Index colorIndex   = renderer.RegisterProperty("uFadeColor", initialColor);
1459
1460   TestGlAbstraction& gl = application.GetGlAbstraction();
1461
1462   application.SendNotification();
1463   application.Render(0);
1464
1465   Vector4 actualValue(Vector4::ZERO);
1466   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1467   DALI_TEST_EQUALS(actualValue, initialColor, TEST_LOCATION);
1468
1469   Animation animation = Animation::New(1.0f);
1470   KeyFrames keyFrames = KeyFrames::New();
1471   keyFrames.Add(0.0f, initialColor);
1472   keyFrames.Add(1.0f, Color::TRANSPARENT);
1473   animation.AnimateBetween(Property(renderer, colorIndex), keyFrames);
1474   animation.Play();
1475
1476   application.SendNotification();
1477   application.Render(500);
1478
1479   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1480   DALI_TEST_EQUALS(actualValue, Color::WHITE * 0.5f, TEST_LOCATION);
1481
1482   application.Render(500);
1483   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1484   DALI_TEST_EQUALS(actualValue, Color::TRANSPARENT, TEST_LOCATION);
1485
1486   END_TEST;
1487 }
1488
1489 int UtcDaliRendererUniformMapPrecendence01(void)
1490 {
1491   TestApplication application;
1492
1493   tet_infoline("Test the uniform map precedence is applied properly");
1494
1495   Texture image = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64);
1496
1497   Shader     shader     = Shader::New("VertexSource", "FragmentSource");
1498   TextureSet textureSet = CreateTextureSet(image);
1499
1500   Geometry geometry = CreateQuadGeometry();
1501   Renderer renderer = Renderer::New(geometry, shader);
1502   renderer.SetTextures(textureSet);
1503
1504   Actor actor = Actor::New();
1505   actor.AddRenderer(renderer);
1506   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1507   application.GetScene().Add(actor);
1508   application.SendNotification();
1509   application.Render(0);
1510
1511   renderer.RegisterProperty("uFadeColor", Color::RED);
1512   actor.RegisterProperty("uFadeColor", Color::GREEN);
1513   Property::Index shaderFadeColorIndex = shader.RegisterProperty("uFadeColor", Color::MAGENTA);
1514
1515   TestGlAbstraction& gl = application.GetGlAbstraction();
1516
1517   application.SendNotification();
1518   application.Render(0);
1519
1520   // Expect that the actor's fade color property is accessed
1521   Vector4 actualValue(Vector4::ZERO);
1522   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1523   DALI_TEST_EQUALS(actualValue, Color::GREEN, TEST_LOCATION);
1524
1525   // Animate shader's fade color property. Should be no change to uniform
1526   Animation animation = Animation::New(1.0f);
1527   KeyFrames keyFrames = KeyFrames::New();
1528   keyFrames.Add(0.0f, Color::WHITE);
1529   keyFrames.Add(1.0f, Color::TRANSPARENT);
1530   animation.AnimateBetween(Property(shader, shaderFadeColorIndex), keyFrames);
1531   animation.Play();
1532
1533   application.SendNotification();
1534   application.Render(500);
1535
1536   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1537   DALI_TEST_EQUALS(actualValue, Color::GREEN, TEST_LOCATION);
1538
1539   application.Render(500);
1540   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1541   DALI_TEST_EQUALS(actualValue, Color::GREEN, TEST_LOCATION);
1542
1543   END_TEST;
1544 }
1545
1546 int UtcDaliRendererUniformMapPrecendence02(void)
1547 {
1548   TestApplication application;
1549
1550   tet_infoline("Test the uniform map precedence is applied properly");
1551
1552   Texture image = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64);
1553
1554   Shader     shader     = Shader::New("VertexSource", "FragmentSource");
1555   TextureSet textureSet = CreateTextureSet(image);
1556
1557   Geometry geometry = CreateQuadGeometry();
1558   Renderer renderer = Renderer::New(geometry, shader);
1559   renderer.SetTextures(textureSet);
1560
1561   Actor actor = Actor::New();
1562   actor.AddRenderer(renderer);
1563   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1564   application.GetScene().Add(actor);
1565   application.SendNotification();
1566   application.Render(0);
1567
1568   // Don't add property / uniform map to renderer
1569   actor.RegisterProperty("uFadeColor", Color::GREEN);
1570   Property::Index shaderFadeColorIndex = shader.RegisterProperty("uFadeColor", Color::BLUE);
1571
1572   TestGlAbstraction& gl = application.GetGlAbstraction();
1573
1574   application.SendNotification();
1575   application.Render(0);
1576
1577   // Expect that the actor's fade color property is accessed
1578   Vector4 actualValue(Vector4::ZERO);
1579   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1580   DALI_TEST_EQUALS(actualValue, Color::GREEN, TEST_LOCATION);
1581
1582   // Animate texture set's fade color property. Should be no change to uniform
1583   Animation animation = Animation::New(1.0f);
1584   KeyFrames keyFrames = KeyFrames::New();
1585   keyFrames.Add(0.0f, Color::WHITE);
1586   keyFrames.Add(1.0f, Color::TRANSPARENT);
1587   animation.AnimateBetween(Property(shader, shaderFadeColorIndex), keyFrames);
1588   animation.Play();
1589
1590   application.SendNotification();
1591   application.Render(500);
1592
1593   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1594   DALI_TEST_EQUALS(actualValue, Color::GREEN, TEST_LOCATION);
1595
1596   application.Render(500);
1597   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1598   DALI_TEST_EQUALS(actualValue, Color::GREEN, TEST_LOCATION);
1599
1600   END_TEST;
1601 }
1602
1603 int UtcDaliRendererUniformMapPrecendence03(void)
1604 {
1605   TestApplication application;
1606
1607   tet_infoline("Test the uniform map precedence is applied properly");
1608
1609   Texture image = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64);
1610
1611   Shader     shader     = Shader::New("VertexSource", "FragmentSource");
1612   TextureSet textureSet = CreateTextureSet(image);
1613
1614   Geometry geometry = CreateQuadGeometry();
1615   Renderer renderer = Renderer::New(geometry, shader);
1616   renderer.SetTextures(textureSet);
1617
1618   Actor actor = Actor::New();
1619   actor.AddRenderer(renderer);
1620   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1621   application.GetScene().Add(actor);
1622   application.SendNotification();
1623   application.Render(0);
1624
1625   // Don't add property / uniform map to renderer or actor
1626   shader.RegisterProperty("uFadeColor", Color::BLACK);
1627
1628   TestGlAbstraction& gl = application.GetGlAbstraction();
1629
1630   application.SendNotification();
1631   application.Render(0);
1632
1633   // Expect that the shader's fade color property is accessed
1634   Vector4 actualValue(Vector4::ZERO);
1635   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", actualValue));
1636   DALI_TEST_EQUALS(actualValue, Color::BLACK, TEST_LOCATION);
1637
1638   END_TEST;
1639 }
1640
1641 int UtcDaliRendererUniformMapMultipleUniforms01(void)
1642 {
1643   TestApplication application;
1644
1645   tet_infoline("Test the uniform maps are collected from all objects (same type)");
1646
1647   Texture image = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64);
1648
1649   Shader     shader     = Shader::New("VertexSource", "FragmentSource");
1650   TextureSet textureSet = CreateTextureSet(image);
1651
1652   Geometry geometry = CreateQuadGeometry();
1653   Renderer renderer = Renderer::New(geometry, shader);
1654   renderer.SetTextures(textureSet);
1655
1656   Actor actor = Actor::New();
1657   actor.AddRenderer(renderer);
1658   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1659   application.GetScene().Add(actor);
1660   application.SendNotification();
1661   application.Render(0);
1662
1663   renderer.RegisterProperty("uUniform1", Color::RED);
1664   actor.RegisterProperty("uUniform2", Color::GREEN);
1665   shader.RegisterProperty("uUniform3", Color::MAGENTA);
1666
1667   TestGlAbstraction& gl = application.GetGlAbstraction();
1668
1669   application.SendNotification();
1670   application.Render(0);
1671
1672   // Expect that each of the object's uniforms are set
1673   Vector4 uniform1Value(Vector4::ZERO);
1674   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uUniform1", uniform1Value));
1675   DALI_TEST_EQUALS(uniform1Value, Color::RED, TEST_LOCATION);
1676
1677   Vector4 uniform2Value(Vector4::ZERO);
1678   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uUniform2", uniform2Value));
1679   DALI_TEST_EQUALS(uniform2Value, Color::GREEN, TEST_LOCATION);
1680
1681   Vector4 uniform3Value(Vector4::ZERO);
1682   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uUniform3", uniform3Value));
1683   DALI_TEST_EQUALS(uniform3Value, Color::MAGENTA, TEST_LOCATION);
1684
1685   END_TEST;
1686 }
1687
1688 int UtcDaliRendererUniformMapMultipleUniforms02(void)
1689 {
1690   TestApplication application;
1691
1692   tet_infoline("Test the uniform maps are collected from all objects (different types)");
1693
1694   Texture image = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64);
1695
1696   Shader     shader     = Shader::New("VertexSource", "FragmentSource");
1697   TextureSet textureSet = CreateTextureSet(image);
1698
1699   Geometry geometry = CreateQuadGeometry();
1700   Renderer renderer = Renderer::New(geometry, shader);
1701   renderer.SetTextures(textureSet);
1702
1703   Actor actor = Actor::New();
1704   actor.AddRenderer(renderer);
1705   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
1706   application.GetScene().Add(actor);
1707   application.SendNotification();
1708   application.Render(0);
1709
1710   Property::Value value1(Color::RED);
1711   renderer.RegisterProperty("uFadeColor", value1);
1712
1713   Property::Value value2(1.0f);
1714   actor.RegisterProperty("uFadeProgress", value2);
1715
1716   Property::Value value3(Matrix3::IDENTITY);
1717   shader.RegisterProperty("uANormalMatrix", value3);
1718
1719   TestGlAbstraction& gl = application.GetGlAbstraction();
1720
1721   application.SendNotification();
1722   application.Render(0);
1723
1724   // Expect that each of the object's uniforms are set
1725   Vector4 uniform1Value(Vector4::ZERO);
1726   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uFadeColor", uniform1Value));
1727   DALI_TEST_EQUALS(uniform1Value, value1.Get<Vector4>(), TEST_LOCATION);
1728
1729   float uniform2Value(0.0f);
1730   DALI_TEST_CHECK(gl.GetUniformValue<float>("uFadeProgress", uniform2Value));
1731   DALI_TEST_EQUALS(uniform2Value, value2.Get<float>(), TEST_LOCATION);
1732
1733   Matrix3 uniform3Value;
1734   DALI_TEST_CHECK(gl.GetUniformValue<Matrix3>("uANormalMatrix", uniform3Value));
1735   DALI_TEST_EQUALS(uniform3Value, value3.Get<Matrix3>(), TEST_LOCATION);
1736
1737   END_TEST;
1738 }
1739
1740 Renderer CreateRenderer(Actor actor, Geometry geometry, Shader shader, int depthIndex)
1741 {
1742   Texture    image0      = Texture::New(TextureType::TEXTURE_2D, Pixel::RGB888, 64, 64);
1743   TextureSet textureSet0 = CreateTextureSet(image0);
1744   Renderer   renderer0   = Renderer::New(geometry, shader);
1745   renderer0.SetTextures(textureSet0);
1746   renderer0.SetProperty(Renderer::Property::DEPTH_INDEX, depthIndex);
1747   actor.AddRenderer(renderer0);
1748   return renderer0;
1749 }
1750
1751 Actor CreateActor(Actor parent, int siblingOrder, const char* location)
1752 {
1753   Actor actor = Actor::New();
1754   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
1755   actor.SetProperty(Actor::Property::PARENT_ORIGIN, AnchorPoint::CENTER);
1756   actor.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 0.0f));
1757   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1758   parent.Add(actor);
1759   actor.SetProperty(Dali::DevelActor::Property::SIBLING_ORDER, siblingOrder);
1760   DALI_TEST_EQUALS(actor.GetProperty<int>(Dali::DevelActor::Property::SIBLING_ORDER), siblingOrder, TEST_INNER_LOCATION(location));
1761
1762   return actor;
1763 }
1764
1765 int UtcDaliRendererRenderOrder2DLayer(void)
1766 {
1767   TestApplication application;
1768   tet_infoline("Test the rendering order in a 2D layer is correct");
1769
1770   Shader   shader   = Shader::New("VertexSource", "FragmentSource");
1771   Geometry geometry = CreateQuadGeometry();
1772
1773   Actor root = application.GetScene().GetRootLayer();
1774
1775   Actor    actor0    = CreateActor(root, 0, TEST_LOCATION);
1776   Renderer renderer0 = CreateRenderer(actor0, geometry, shader, 0);
1777
1778   Actor    actor1    = CreateActor(root, 0, TEST_LOCATION);
1779   Renderer renderer1 = CreateRenderer(actor1, geometry, shader, 0);
1780
1781   Actor    actor2    = CreateActor(root, 0, TEST_LOCATION);
1782   Renderer renderer2 = CreateRenderer(actor2, geometry, shader, 0);
1783
1784   Actor    actor3    = CreateActor(root, 0, TEST_LOCATION);
1785   Renderer renderer3 = CreateRenderer(actor3, geometry, shader, 0);
1786
1787   application.SendNotification();
1788   application.Render(0);
1789
1790   /*
1791    * Create the following hierarchy:
1792    *
1793    *            actor2
1794    *              /
1795    *             /
1796    *          actor1
1797    *           /
1798    *          /
1799    *       actor0
1800    *        /
1801    *       /
1802    *    actor3
1803    *
1804    *  Expected rendering order : actor2 - actor1 - actor0 - actor3
1805    */
1806   actor2.Add(actor1);
1807   actor1.Add(actor0);
1808   actor0.Add(actor3);
1809   application.SendNotification();
1810   application.Render(0);
1811
1812   TestGlAbstraction& gl = application.GetGlAbstraction();
1813   gl.EnableTextureCallTrace(true);
1814   application.SendNotification();
1815   application.Render(0);
1816
1817   int textureBindIndex[4];
1818   for(unsigned int i(0); i < 4; ++i)
1819   {
1820     std::stringstream params;
1821     params << GL_TEXTURE_2D << ", " << i + 1;
1822     textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str());
1823   }
1824
1825   //Check that actor1 has been rendered after actor2
1826   DALI_TEST_GREATER(textureBindIndex[1], textureBindIndex[2], TEST_LOCATION);
1827
1828   //Check that actor0 has been rendered after actor1
1829   DALI_TEST_GREATER(textureBindIndex[0], textureBindIndex[1], TEST_LOCATION);
1830
1831   //Check that actor3 has been rendered after actor0
1832   DALI_TEST_GREATER(textureBindIndex[3], textureBindIndex[0], TEST_LOCATION);
1833
1834   END_TEST;
1835 }
1836
1837 int UtcDaliRendererRenderOrder2DLayerMultipleRenderers(void)
1838 {
1839   TestApplication application;
1840   tet_infoline("Test the rendering order in a 2D layer is correct using multiple renderers per actor");
1841
1842   /*
1843    * Creates the following hierarchy:
1844    *
1845    *             actor0------------------------>actor1
1846    *            /   |   \                    /   |   \
1847    *          /     |     \                /     |     \
1848    *        /       |       \            /       |       \
1849    * renderer0 renderer1 renderer2 renderer3 renderer4 renderer5
1850    *
1851    *  renderer0 has depth index 2
1852    *  renderer1 has depth index 0
1853    *  renderer2 has depth index 1
1854    *
1855    *  renderer3 has depth index 1
1856    *  renderer4 has depth index 0
1857    *  renderer5 has depth index -1
1858    *
1859    *  Expected rendering order: renderer1 - renderer2 - renderer0 - renderer5 - renderer4 - renderer3
1860    */
1861
1862   Shader   shader   = Shader::New("VertexSource", "FragmentSource");
1863   Geometry geometry = CreateQuadGeometry();
1864
1865   Actor root = application.GetScene().GetRootLayer();
1866
1867   Actor    actor0    = CreateActor(root, 0, TEST_LOCATION);
1868   Actor    actor1    = CreateActor(actor0, 0, TEST_LOCATION);
1869   Renderer renderer0 = CreateRenderer(actor0, geometry, shader, 2);
1870   Renderer renderer1 = CreateRenderer(actor0, geometry, shader, 0);
1871   Renderer renderer2 = CreateRenderer(actor0, geometry, shader, 1);
1872   Renderer renderer3 = CreateRenderer(actor1, geometry, shader, 1);
1873   Renderer renderer4 = CreateRenderer(actor1, geometry, shader, 0);
1874   Renderer renderer5 = CreateRenderer(actor1, geometry, shader, -1);
1875
1876   application.SendNotification();
1877   application.Render(0);
1878
1879   TestGlAbstraction& gl = application.GetGlAbstraction();
1880   gl.EnableTextureCallTrace(true);
1881   application.SendNotification();
1882   application.Render(0);
1883
1884   int textureBindIndex[6];
1885   for(unsigned int i(0); i < 6; ++i)
1886   {
1887     std::stringstream params;
1888     params << GL_TEXTURE_2D << ", " << i + 1;
1889     textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str());
1890   }
1891
1892   //Check that renderer3 has been rendered after renderer4
1893   DALI_TEST_GREATER(textureBindIndex[3], textureBindIndex[4], TEST_LOCATION);
1894
1895   //Check that renderer0 has been rendered after renderer2
1896   DALI_TEST_GREATER(textureBindIndex[4], textureBindIndex[5], TEST_LOCATION);
1897
1898   //Check that renderer5 has been rendered after renderer2
1899   DALI_TEST_GREATER(textureBindIndex[5], textureBindIndex[0], TEST_LOCATION);
1900
1901   //Check that renderer0 has been rendered after renderer2
1902   DALI_TEST_GREATER(textureBindIndex[0], textureBindIndex[2], TEST_LOCATION);
1903
1904   //Check that renderer2 has been rendered after renderer1
1905   DALI_TEST_GREATER(textureBindIndex[2], textureBindIndex[1], TEST_LOCATION);
1906
1907   END_TEST;
1908 }
1909
1910 int UtcDaliRendererRenderOrder2DLayerSiblingOrder(void)
1911 {
1912   TestApplication application;
1913   tet_infoline("Test the rendering order in a 2D layer is correct using sibling order");
1914
1915   /*
1916    * Creates the following hierarchy:
1917    *
1918    *                            Layer
1919    *                           /    \
1920    *                         /        \
1921    *                       /            \
1922    *                     /                \
1923    *                   /                    \
1924    *             actor0 (SIBLING_ORDER:1)     actor1 (SIBLING_ORDER:0)
1925    *            /   |   \                    /   |   \
1926    *          /     |     \                /     |     \
1927    *        /       |       \            /       |       \
1928    * renderer0 renderer1  actor2     renderer2 renderer3 renderer4
1929    *    DI:2      DI:0      |           DI:0      DI:1      DI:2
1930    *                        |
1931    *                   renderer5
1932    *                      DI:-1
1933    *
1934    *  actor0 has sibling order 1
1935    *  actor1 has sibling order 0
1936    *  actor2 has sibling order 0
1937    *
1938    *  renderer0 has depth index 2
1939    *  renderer1 has depth index 0
1940    *
1941    *  renderer2 has depth index 0
1942    *  renderer3 has depth index 1
1943    *  renderer4 has depth index 2
1944    *
1945    *  renderer5 has depth index -1
1946    *
1947    *  Expected rendering order: renderer2 - renderer3 - renderer4 - renderer1 - renderer0 - renderer5
1948    */
1949
1950   Shader   shader   = Shader::New("VertexSource", "FragmentSource");
1951   Geometry geometry = CreateQuadGeometry();
1952   Actor    root     = application.GetScene().GetRootLayer();
1953   Actor    actor0   = CreateActor(root, 1, TEST_LOCATION);
1954   Actor    actor1   = CreateActor(root, 0, TEST_LOCATION);
1955   Actor    actor2   = CreateActor(actor0, 0, TEST_LOCATION);
1956
1957   Renderer renderer0 = CreateRenderer(actor0, geometry, shader, 2);
1958   Renderer renderer1 = CreateRenderer(actor0, geometry, shader, 0);
1959   Renderer renderer2 = CreateRenderer(actor1, geometry, shader, 0);
1960   Renderer renderer3 = CreateRenderer(actor1, geometry, shader, 1);
1961   Renderer renderer4 = CreateRenderer(actor1, geometry, shader, 2);
1962   Renderer renderer5 = CreateRenderer(actor2, geometry, shader, -1);
1963
1964   application.SendNotification();
1965   application.Render();
1966
1967   TestGlAbstraction& gl = application.GetGlAbstraction();
1968   gl.EnableTextureCallTrace(true);
1969   application.SendNotification();
1970   application.Render(0);
1971
1972   int textureBindIndex[6];
1973   for(unsigned int i(0); i < 6; ++i)
1974   {
1975     std::stringstream params;
1976     params << GL_TEXTURE_2D << ", " << i + 1;
1977     textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str());
1978   }
1979
1980   DALI_TEST_EQUALS(textureBindIndex[2], 0, TEST_LOCATION);
1981   DALI_TEST_EQUALS(textureBindIndex[3], 1, TEST_LOCATION);
1982   DALI_TEST_EQUALS(textureBindIndex[4], 2, TEST_LOCATION);
1983   DALI_TEST_EQUALS(textureBindIndex[1], 3, TEST_LOCATION);
1984   DALI_TEST_EQUALS(textureBindIndex[0], 4, TEST_LOCATION);
1985   DALI_TEST_EQUALS(textureBindIndex[5], 5, TEST_LOCATION);
1986
1987   // Change sibling order of actor1
1988   // New Expected rendering order: renderer1 - renderer0 - renderer 5 - renderer2 - renderer3 - renderer4
1989   actor1.SetProperty(Dali::DevelActor::Property::SIBLING_ORDER, 2);
1990
1991   gl.GetTextureTrace().Reset();
1992   application.SendNotification();
1993   application.Render(0);
1994
1995   for(unsigned int i(0); i < 6; ++i)
1996   {
1997     std::stringstream params;
1998     params << GL_TEXTURE_2D << ", " << i + 1;
1999     textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str());
2000   }
2001
2002   DALI_TEST_EQUALS(textureBindIndex[1], 0, TEST_LOCATION);
2003   DALI_TEST_EQUALS(textureBindIndex[0], 1, TEST_LOCATION);
2004   DALI_TEST_EQUALS(textureBindIndex[5], 2, TEST_LOCATION);
2005   DALI_TEST_EQUALS(textureBindIndex[2], 3, TEST_LOCATION);
2006   DALI_TEST_EQUALS(textureBindIndex[3], 4, TEST_LOCATION);
2007   DALI_TEST_EQUALS(textureBindIndex[4], 5, TEST_LOCATION);
2008
2009   END_TEST;
2010 }
2011
2012 int UtcDaliRendererRenderOrder2DLayerOverlay(void)
2013 {
2014   TestApplication application;
2015   tet_infoline("Test the rendering order in a 2D layer is correct for overlays");
2016
2017   Shader   shader   = Shader::New("VertexSource", "FragmentSource");
2018   Geometry geometry = CreateQuadGeometry();
2019   Actor    root     = application.GetScene().GetRootLayer();
2020
2021   /*
2022    * Create the following hierarchy:
2023    *
2024    *               actor2
2025    *             (Regular actor)
2026    *              /      \
2027    *             /        \
2028    *         actor1       actor4
2029    *       (Overlay)     (Regular actor)
2030    *          /
2031    *         /
2032    *     actor0
2033    *    (Overlay)
2034    *      /
2035    *     /
2036    *  actor3
2037    * (Overlay)
2038    *
2039    *  Expected rendering order : actor2 - actor4 - actor1 - actor0 - actor3
2040    */
2041
2042   Actor actor0 = CreateActor(root, 0, TEST_LOCATION);
2043   actor0.SetProperty(Actor::Property::DRAW_MODE, DrawMode::OVERLAY_2D);
2044   Renderer renderer0 = CreateRenderer(actor0, geometry, shader, 0);
2045
2046   Actor actor1 = CreateActor(root, 0, TEST_LOCATION);
2047   actor1.SetProperty(Actor::Property::DRAW_MODE, DrawMode::OVERLAY_2D);
2048   Renderer renderer1 = CreateRenderer(actor1, geometry, shader, 0);
2049
2050   Actor    actor2    = CreateActor(root, 0, TEST_LOCATION);
2051   Renderer renderer2 = CreateRenderer(actor2, geometry, shader, 0);
2052
2053   Actor actor3 = CreateActor(root, 0, TEST_LOCATION);
2054   actor3.SetProperty(Actor::Property::DRAW_MODE, DrawMode::OVERLAY_2D);
2055   Renderer renderer3 = CreateRenderer(actor3, geometry, shader, 0);
2056
2057   Actor    actor4    = CreateActor(root, 0, TEST_LOCATION);
2058   Renderer renderer4 = CreateRenderer(actor4, geometry, shader, 0);
2059
2060   application.SendNotification();
2061   application.Render(0);
2062
2063   actor2.Add(actor1);
2064   actor2.Add(actor4);
2065   actor1.Add(actor0);
2066   actor0.Add(actor3);
2067
2068   TestGlAbstraction& gl = application.GetGlAbstraction();
2069   gl.EnableTextureCallTrace(true);
2070   application.SendNotification();
2071   application.Render(0);
2072
2073   int textureBindIndex[5];
2074   for(unsigned int i(0); i < 5; ++i)
2075   {
2076     std::stringstream params;
2077     params << GL_TEXTURE_2D << ", " << i + 1;
2078     textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str());
2079   }
2080
2081   //Check that actor4 has been rendered after actor2
2082   DALI_TEST_GREATER(textureBindIndex[4], textureBindIndex[2], TEST_LOCATION);
2083
2084   //Check that actor1 has been rendered after actor4
2085   DALI_TEST_GREATER(textureBindIndex[1], textureBindIndex[4], TEST_LOCATION);
2086
2087   //Check that actor0 has been rendered after actor1
2088   DALI_TEST_GREATER(textureBindIndex[0], textureBindIndex[1], TEST_LOCATION);
2089
2090   //Check that actor3 has been rendered after actor0
2091   DALI_TEST_GREATER(textureBindIndex[3], textureBindIndex[0], TEST_LOCATION);
2092
2093   END_TEST;
2094 }
2095
2096 int UtcDaliRendererSetIndexRange(void)
2097 {
2098   std::string
2099     vertexShader(
2100       "attribute vec2 aPosition;\n"
2101       "void main()\n"
2102       "{\n"
2103       "  gl_Position = aPosition;\n"
2104       "}"),
2105     fragmentShader(
2106       "void main()\n"
2107       "{\n"
2108       "  gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0)\n"
2109       "}\n");
2110
2111   TestApplication application;
2112   tet_infoline("Test setting the range of indices to draw");
2113
2114   TestGlAbstraction& gl = application.GetGlAbstraction();
2115   gl.EnableDrawCallTrace(true);
2116
2117   Actor actor = Actor::New();
2118   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2119
2120   // create geometry
2121   Geometry geometry = Geometry::New();
2122   geometry.SetType(Geometry::LINE_LOOP);
2123
2124   // --------------------------------------------------------------------------
2125   // index buffer
2126   unsigned short indices[] = {0, 2, 4, 6, 8, // offset = 0, count = 5
2127                               0,
2128                               1,
2129                               2,
2130                               3,
2131                               4,
2132                               5,
2133                               6,
2134                               7,
2135                               8,
2136                               9, // offset = 5, count = 10
2137                               1,
2138                               3,
2139                               5,
2140                               7,
2141                               9,
2142                               1}; // offset = 15,  count = 6 // line strip
2143
2144   // --------------------------------------------------------------------------
2145   // vertex buffer
2146   struct Vertex
2147   {
2148     Vector2 position;
2149   };
2150   Vertex shapes[] =
2151     {
2152       // pentagon                   // star
2153       {Vector2(0.0f, 1.00f)},
2154       {Vector2(0.0f, -1.00f)},
2155       {Vector2(-0.95f, 0.31f)},
2156       {Vector2(0.59f, 0.81f)},
2157       {Vector2(-0.59f, -0.81f)},
2158       {Vector2(-0.95f, -0.31f)},
2159       {Vector2(0.59f, -0.81f)},
2160       {Vector2(0.95f, -0.31f)},
2161       {Vector2(0.95f, 0.31f)},
2162       {Vector2(-0.59f, 0.81f)},
2163     };
2164   Property::Map vertexFormat;
2165   vertexFormat["aPosition"] = Property::VECTOR2;
2166   VertexBuffer vertexBuffer = VertexBuffer::New(vertexFormat);
2167   vertexBuffer.SetData(shapes, sizeof(shapes) / sizeof(shapes[0]));
2168
2169   // --------------------------------------------------------------------------
2170   geometry.SetIndexBuffer(indices, sizeof(indices) / sizeof(indices[0]));
2171   geometry.AddVertexBuffer(vertexBuffer);
2172
2173   // create shader
2174   Shader   shader   = Shader::New(vertexShader, fragmentShader);
2175   Renderer renderer = Renderer::New(geometry, shader);
2176   actor.AddRenderer(renderer);
2177
2178   Integration::Scene scene = application.GetScene();
2179   scene.Add(actor);
2180
2181   char buffer[128];
2182
2183   // LINE_LOOP, first 0, count 5
2184   {
2185     renderer.SetIndexRange(0, 5);
2186     application.SendNotification();
2187     application.Render();
2188
2189     Property::Value value = renderer.GetProperty(Renderer::Property::INDEX_RANGE_FIRST);
2190     int             convertedValue;
2191     DALI_TEST_CHECK(value.Get(convertedValue));
2192     DALI_TEST_CHECK(convertedValue == 0);
2193
2194     value = renderer.GetCurrentProperty(Renderer::Property::INDEX_RANGE_FIRST);
2195     DALI_TEST_CHECK(value.Get(convertedValue));
2196     DALI_TEST_CHECK(convertedValue == 0);
2197
2198     value = renderer.GetProperty(Renderer::Property::INDEX_RANGE_COUNT);
2199     DALI_TEST_CHECK(value.Get(convertedValue));
2200     DALI_TEST_CHECK(convertedValue == 5);
2201
2202     value = renderer.GetCurrentProperty(Renderer::Property::INDEX_RANGE_COUNT);
2203     DALI_TEST_CHECK(value.Get(convertedValue));
2204     DALI_TEST_CHECK(convertedValue == 5);
2205
2206     sprintf(buffer, "%u, 5, %u, indices", GL_LINE_LOOP, GL_UNSIGNED_SHORT);
2207     bool result = gl.GetDrawTrace().FindMethodAndParams("DrawElements", buffer);
2208     DALI_TEST_CHECK(result);
2209   }
2210
2211   // LINE_LOOP, first 5, count 10
2212   {
2213     renderer.SetIndexRange(5, 10);
2214     sprintf(buffer, "%u, 10, %u, indices", GL_LINE_LOOP, GL_UNSIGNED_SHORT);
2215     application.SendNotification();
2216     application.Render();
2217     bool result = gl.GetDrawTrace().FindMethodAndParams("DrawElements", buffer);
2218     DALI_TEST_CHECK(result);
2219   }
2220
2221   // LINE_STRIP, first 15, count 6
2222   {
2223     renderer.SetIndexRange(15, 6);
2224     geometry.SetType(Geometry::LINE_STRIP);
2225     sprintf(buffer, "%u, 6, %u, indices", GL_LINE_STRIP, GL_UNSIGNED_SHORT);
2226     application.SendNotification();
2227     application.Render();
2228     bool result = gl.GetDrawTrace().FindMethodAndParams("DrawElements", buffer);
2229     DALI_TEST_CHECK(result);
2230   }
2231
2232   // Index out of bounds
2233   {
2234     renderer.SetIndexRange(15, 30);
2235     geometry.SetType(Geometry::LINE_STRIP);
2236     sprintf(buffer, "%u, 6, %u, indices", GL_LINE_STRIP, GL_UNSIGNED_SHORT);
2237     application.SendNotification();
2238     application.Render();
2239     bool result = gl.GetDrawTrace().FindMethodAndParams("DrawElements", buffer);
2240     DALI_TEST_CHECK(result);
2241   }
2242
2243   // drawing whole buffer starting from 15 ( last valid primitive )
2244   {
2245     renderer.SetIndexRange(15, 0);
2246     geometry.SetType(Geometry::LINE_STRIP);
2247     sprintf(buffer, "%u, 6, %u, indices", GL_LINE_STRIP, GL_UNSIGNED_SHORT);
2248     application.SendNotification();
2249     application.Render();
2250     bool result = gl.GetDrawTrace().FindMethodAndParams("DrawElements", buffer);
2251     DALI_TEST_CHECK(result);
2252   }
2253
2254   END_TEST;
2255 }
2256
2257 int UtcDaliRendererSetDepthFunction(void)
2258 {
2259   TestApplication application;
2260
2261   tet_infoline("Test setting the depth function");
2262
2263   Geometry geometry = CreateQuadGeometry();
2264   Shader   shader   = CreateShader();
2265   Renderer renderer = Renderer::New(geometry, shader);
2266
2267   Actor actor = Actor::New();
2268   actor.AddRenderer(renderer);
2269   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
2270   Integration::Scene scene = application.GetScene();
2271   scene.GetRootLayer().SetProperty(Layer::Property::BEHAVIOR, Layer::LAYER_3D);
2272   scene.Add(actor);
2273
2274   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2275   glAbstraction.EnableEnableDisableCallTrace(true);
2276   glAbstraction.EnableDepthFunctionCallTrace(true);
2277
2278   TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2279   TraceCallStack& glDepthFunctionStack = glAbstraction.GetDepthFunctionTrace();
2280
2281   std::ostringstream depthTestStr;
2282   depthTestStr << GL_DEPTH_TEST;
2283
2284   //GL_NEVER
2285   {
2286     renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::NEVER);
2287
2288     glEnableDisableStack.Reset();
2289     glDepthFunctionStack.Reset();
2290     application.SendNotification();
2291     application.Render();
2292
2293     DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Enable", depthTestStr.str().c_str()));
2294     std::ostringstream depthFunctionStr;
2295     depthFunctionStr << GL_NEVER;
2296     DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2297   }
2298
2299   //GL_ALWAYS
2300   {
2301     renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::ALWAYS);
2302
2303     glDepthFunctionStack.Reset();
2304     application.SendNotification();
2305     application.Render();
2306
2307     std::ostringstream depthFunctionStr;
2308     depthFunctionStr << GL_ALWAYS;
2309     DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2310   }
2311
2312   //GL_LESS
2313   {
2314     renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::LESS);
2315
2316     glDepthFunctionStack.Reset();
2317     application.SendNotification();
2318     application.Render();
2319
2320     std::ostringstream depthFunctionStr;
2321     depthFunctionStr << GL_LESS;
2322     DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2323   }
2324
2325   //GL_GREATER
2326   {
2327     renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::GREATER);
2328
2329     glDepthFunctionStack.Reset();
2330     application.SendNotification();
2331     application.Render();
2332
2333     std::ostringstream depthFunctionStr;
2334     depthFunctionStr << GL_GREATER;
2335     DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2336   }
2337
2338   //GL_EQUAL
2339   {
2340     renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::EQUAL);
2341
2342     glDepthFunctionStack.Reset();
2343     application.SendNotification();
2344     application.Render();
2345
2346     std::ostringstream depthFunctionStr;
2347     depthFunctionStr << GL_EQUAL;
2348     DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2349   }
2350
2351   //GL_NOTEQUAL
2352   {
2353     renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::NOT_EQUAL);
2354
2355     glDepthFunctionStack.Reset();
2356     application.SendNotification();
2357     application.Render();
2358
2359     std::ostringstream depthFunctionStr;
2360     depthFunctionStr << GL_NOTEQUAL;
2361     DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2362   }
2363
2364   //GL_LEQUAL
2365   {
2366     renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::LESS_EQUAL);
2367
2368     glDepthFunctionStack.Reset();
2369     application.SendNotification();
2370     application.Render();
2371
2372     std::ostringstream depthFunctionStr;
2373     depthFunctionStr << GL_LEQUAL;
2374     DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2375   }
2376
2377   //GL_GEQUAL
2378   {
2379     renderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::GREATER_EQUAL);
2380
2381     glDepthFunctionStack.Reset();
2382     application.SendNotification();
2383     application.Render();
2384
2385     std::ostringstream depthFunctionStr;
2386     depthFunctionStr << GL_GEQUAL;
2387     DALI_TEST_CHECK(glDepthFunctionStack.FindMethodAndParams("DepthFunc", depthFunctionStr.str().c_str()));
2388   }
2389
2390   END_TEST;
2391 }
2392
2393 /**
2394  * @brief This templatized function checks an enumeration property is setting and getting correctly.
2395  * The checks performed are as follows:
2396  *  - Check the initial/default value.
2397  *  - Set a different value via enum.
2398  *  - Check it was set.
2399  *  - Set a different value via string.
2400  *  - Check it was set.
2401  */
2402 template<typename T>
2403 void CheckEnumerationProperty(TestApplication& application, Renderer& renderer, Property::Index propertyIndex, T initialValue, T firstCheckEnumeration, T secondCheckEnumeration, std::string secondCheckString)
2404 {
2405   application.SendNotification();
2406   application.Render();
2407
2408   DALI_TEST_CHECK(renderer.GetProperty<int>(propertyIndex) == static_cast<int>(initialValue));
2409   DALI_TEST_CHECK(renderer.GetCurrentProperty<int>(propertyIndex) == static_cast<int>(initialValue));
2410   renderer.SetProperty(propertyIndex, firstCheckEnumeration);
2411   DALI_TEST_CHECK(renderer.GetProperty<int>(propertyIndex) == static_cast<int>(firstCheckEnumeration));
2412   DALI_TEST_CHECK(renderer.GetCurrentProperty<int>(propertyIndex) != static_cast<int>(firstCheckEnumeration));
2413
2414   application.SendNotification();
2415   application.Render();
2416
2417   DALI_TEST_CHECK(renderer.GetProperty<int>(propertyIndex) == static_cast<int>(firstCheckEnumeration));
2418   DALI_TEST_CHECK(renderer.GetCurrentProperty<int>(propertyIndex) == static_cast<int>(firstCheckEnumeration));
2419
2420   renderer.SetProperty(propertyIndex, secondCheckString);
2421   DALI_TEST_CHECK(renderer.GetProperty<int>(propertyIndex) == static_cast<int>(secondCheckEnumeration));
2422   DALI_TEST_CHECK(renderer.GetCurrentProperty<int>(propertyIndex) != static_cast<int>(secondCheckEnumeration));
2423
2424   application.SendNotification();
2425   application.Render();
2426
2427   DALI_TEST_CHECK(renderer.GetProperty<int>(propertyIndex) == static_cast<int>(secondCheckEnumeration));
2428   DALI_TEST_CHECK(renderer.GetCurrentProperty<int>(propertyIndex) == static_cast<int>(secondCheckEnumeration));
2429 }
2430
2431 int UtcDaliRendererEnumProperties(void)
2432 {
2433   TestApplication application;
2434   tet_infoline("Test Renderer enumeration properties can be set with both integer and string values");
2435
2436   Geometry geometry = CreateQuadGeometry();
2437   Shader   shader   = CreateShader();
2438   Renderer renderer = Renderer::New(geometry, shader);
2439
2440   Actor actor = Actor::New();
2441   actor.AddRenderer(renderer);
2442   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
2443   application.GetScene().Add(actor);
2444
2445   /*
2446    * Here we use a templatized function to perform several checks on each enumeration property.
2447    * @see CheckEnumerationProperty for details of the checks performed.
2448    */
2449
2450   CheckEnumerationProperty<FaceCullingMode::Type>(application, renderer, Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::NONE, FaceCullingMode::FRONT, FaceCullingMode::BACK, "BACK");
2451   CheckEnumerationProperty<BlendMode::Type>(application, renderer, Renderer::Property::BLEND_MODE, BlendMode::AUTO, BlendMode::OFF, BlendMode::ON, "ON");
2452   CheckEnumerationProperty<BlendEquation::Type>(application, renderer, Renderer::Property::BLEND_EQUATION_RGB, BlendEquation::ADD, BlendEquation::SUBTRACT, BlendEquation::REVERSE_SUBTRACT, "REVERSE_SUBTRACT");
2453   CheckEnumerationProperty<BlendEquation::Type>(application, renderer, Renderer::Property::BLEND_EQUATION_ALPHA, BlendEquation::ADD, BlendEquation::SUBTRACT, BlendEquation::REVERSE_SUBTRACT, "REVERSE_SUBTRACT");
2454   CheckEnumerationProperty<BlendFactor::Type>(application, renderer, Renderer::Property::BLEND_FACTOR_SRC_RGB, BlendFactor::SRC_ALPHA, BlendFactor::ONE, BlendFactor::SRC_COLOR, "SRC_COLOR");
2455   CheckEnumerationProperty<BlendFactor::Type>(application, renderer, Renderer::Property::BLEND_FACTOR_DEST_RGB, BlendFactor::ONE_MINUS_SRC_ALPHA, BlendFactor::ONE, BlendFactor::SRC_COLOR, "SRC_COLOR");
2456   CheckEnumerationProperty<BlendFactor::Type>(application, renderer, Renderer::Property::BLEND_FACTOR_SRC_ALPHA, BlendFactor::ONE, BlendFactor::ONE_MINUS_SRC_ALPHA, BlendFactor::SRC_COLOR, "SRC_COLOR");
2457   CheckEnumerationProperty<BlendFactor::Type>(application, renderer, Renderer::Property::BLEND_FACTOR_DEST_ALPHA, BlendFactor::ONE_MINUS_SRC_ALPHA, BlendFactor::ONE, BlendFactor::SRC_COLOR, "SRC_COLOR");
2458   CheckEnumerationProperty<DepthWriteMode::Type>(application, renderer, Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::AUTO, DepthWriteMode::OFF, DepthWriteMode::ON, "ON");
2459   CheckEnumerationProperty<DepthFunction::Type>(application, renderer, Renderer::Property::DEPTH_FUNCTION, DepthFunction::LESS, DepthFunction::ALWAYS, DepthFunction::GREATER, "GREATER");
2460   CheckEnumerationProperty<DepthTestMode::Type>(application, renderer, Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::AUTO, DepthTestMode::OFF, DepthTestMode::ON, "ON");
2461   CheckEnumerationProperty<StencilFunction::Type>(application, renderer, Renderer::Property::STENCIL_FUNCTION, StencilFunction::ALWAYS, StencilFunction::LESS, StencilFunction::EQUAL, "EQUAL");
2462   CheckEnumerationProperty<RenderMode::Type>(application, renderer, Renderer::Property::RENDER_MODE, RenderMode::AUTO, RenderMode::NONE, RenderMode::STENCIL, "STENCIL");
2463   CheckEnumerationProperty<StencilOperation::Type>(application, renderer, Renderer::Property::STENCIL_OPERATION_ON_FAIL, StencilOperation::KEEP, StencilOperation::REPLACE, StencilOperation::INCREMENT, "INCREMENT");
2464   CheckEnumerationProperty<StencilOperation::Type>(application, renderer, Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, StencilOperation::KEEP, StencilOperation::REPLACE, StencilOperation::INCREMENT, "INCREMENT");
2465   CheckEnumerationProperty<StencilOperation::Type>(application, renderer, Renderer::Property::STENCIL_OPERATION_ON_Z_PASS, StencilOperation::KEEP, StencilOperation::REPLACE, StencilOperation::INCREMENT, "INCREMENT");
2466
2467   if( Dali::Capabilities::IsBlendEquationSupported( DevelBlendEquation::MAX ) &&
2468       Dali::Capabilities::IsBlendEquationSupported( DevelBlendEquation::MIN ) )
2469   {
2470     application.SendNotification();
2471     application.Render();
2472     CheckEnumerationProperty< DevelBlendEquation::Type >( application, renderer, DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::REVERSE_SUBTRACT, DevelBlendEquation::MAX, DevelBlendEquation::MIN, "MIN" );
2473   }
2474
2475   if( Dali::Capabilities::IsBlendEquationSupported( DevelBlendEquation::SCREEN ) )
2476   {
2477     application.SendNotification();
2478     application.Render();
2479     CheckEnumerationProperty< DevelBlendEquation::Type >( application, renderer, DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::MIN, DevelBlendEquation::MULTIPLY, DevelBlendEquation::SCREEN, "SCREEN" );
2480   }
2481
2482   END_TEST;
2483 }
2484
2485 Renderer RendererTestFixture(TestApplication& application)
2486 {
2487   Geometry geometry = CreateQuadGeometry();
2488   Shader   shader   = CreateShader();
2489   Renderer renderer = Renderer::New(geometry, shader);
2490
2491   Actor actor = Actor::New();
2492   actor.AddRenderer(renderer);
2493   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
2494   Integration::Scene scene = application.GetScene();
2495   scene.GetRootLayer().SetProperty(Layer::Property::BEHAVIOR, Layer::LAYER_3D);
2496   scene.Add(actor);
2497
2498   return renderer;
2499 }
2500
2501 int UtcDaliRendererSetDepthTestMode(void)
2502 {
2503   TestApplication application;
2504   tet_infoline("Test setting the DepthTestMode");
2505
2506   Renderer           renderer      = RendererTestFixture(application);
2507   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2508   glAbstraction.EnableEnableDisableCallTrace(true);
2509   TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2510
2511   glEnableDisableStack.Reset();
2512   application.SendNotification();
2513   application.Render();
2514
2515   // Check depth-test is enabled by default.
2516   DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Enable", GetDepthTestString()));
2517   DALI_TEST_CHECK(!glEnableDisableStack.FindMethodAndParams("Disable", GetDepthTestString()));
2518
2519   // 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.
2520   renderer.SetProperty(Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::OFF);
2521   renderer.SetProperty(Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::OFF);
2522
2523   glEnableDisableStack.Reset();
2524   application.SendNotification();
2525   application.Render();
2526
2527   // Check the depth buffer was disabled.
2528   DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Disable", GetDepthTestString()));
2529
2530   // Turn on automatic mode depth-testing.
2531   // Layer behavior is currently set to LAYER_3D so AUTO should enable depth-testing.
2532   renderer.SetProperty(Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::AUTO);
2533
2534   glEnableDisableStack.Reset();
2535   application.SendNotification();
2536   application.Render();
2537
2538   // Check depth-test is now enabled.
2539   DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Enable", GetDepthTestString()));
2540   DALI_TEST_CHECK(!glEnableDisableStack.FindMethodAndParams("Disable", GetDepthTestString()));
2541
2542   // Change the layer behavior to LAYER_UI.
2543   // Note this will also disable depth testing for the layer by default, we test this first.
2544   application.GetScene().GetRootLayer().SetProperty(Layer::Property::BEHAVIOR, Layer::LAYER_UI);
2545
2546   glEnableDisableStack.Reset();
2547   application.SendNotification();
2548   application.Render();
2549
2550   // Check depth-test is disabled.
2551   DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Disable", GetDepthTestString()));
2552
2553   // Turn the layer depth-test flag back on, and confirm that depth testing is now on.
2554   application.GetScene().GetRootLayer().SetProperty(Layer::Property::DEPTH_TEST, true);
2555
2556   glEnableDisableStack.Reset();
2557   application.SendNotification();
2558   application.Render();
2559
2560   // Check depth-test is *still* disabled.
2561   DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Enable", GetDepthTestString()));
2562
2563   END_TEST;
2564 }
2565
2566 int UtcDaliRendererSetDepthWriteMode(void)
2567 {
2568   TestApplication application;
2569   tet_infoline("Test setting the DepthWriteMode");
2570
2571   Renderer           renderer      = RendererTestFixture(application);
2572   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2573
2574   application.SendNotification();
2575   application.Render();
2576
2577   // Check the default depth-write status first.
2578   DALI_TEST_CHECK(glAbstraction.GetLastDepthMask());
2579
2580   // Turn off depth-writing.
2581   renderer.SetProperty(Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::OFF);
2582
2583   application.SendNotification();
2584   application.Render();
2585
2586   // Check depth-write is now disabled.
2587   DALI_TEST_CHECK(!glAbstraction.GetLastDepthMask());
2588
2589   // Test the AUTO mode for depth-writing.
2590   // As our renderer is opaque, depth-testing should be enabled.
2591   renderer.SetProperty(Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::AUTO);
2592
2593   application.SendNotification();
2594   application.Render();
2595
2596   // Check depth-write is now enabled.
2597   DALI_TEST_CHECK(glAbstraction.GetLastDepthMask());
2598
2599   // Now make the renderer be treated as translucent by enabling blending.
2600   // The AUTO depth-write mode should turn depth-write off in this scenario.
2601   renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON);
2602
2603   application.SendNotification();
2604   application.Render();
2605
2606   // Check depth-write is now disabled.
2607   DALI_TEST_CHECK(!glAbstraction.GetLastDepthMask());
2608
2609   END_TEST;
2610 }
2611
2612 int UtcDaliRendererCheckStencilDefaults(void)
2613 {
2614   TestApplication application;
2615   tet_infoline("Test the stencil defaults");
2616
2617   Renderer           renderer      = RendererTestFixture(application);
2618   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2619   glAbstraction.EnableEnableDisableCallTrace(true);
2620   glAbstraction.EnableStencilFunctionCallTrace(true);
2621   TraceCallStack& glEnableDisableStack   = glAbstraction.GetEnableDisableTrace();
2622   TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2623
2624   ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2625
2626   // Check the defaults:
2627   DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_FUNCTION).Get<int>()), static_cast<int>(StencilFunction::ALWAYS), TEST_LOCATION);
2628   DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_FUNCTION_MASK).Get<int>()), 0xFF, TEST_LOCATION);
2629   DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_FUNCTION_REFERENCE).Get<int>()), 0x00, TEST_LOCATION);
2630   DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_MASK).Get<int>()), 0xFF, TEST_LOCATION);
2631   DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_OPERATION_ON_FAIL).Get<int>()), static_cast<int>(StencilOperation::KEEP), TEST_LOCATION);
2632   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);
2633   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);
2634
2635   END_TEST;
2636 }
2637
2638 int UtcDaliRendererSetRenderModeToUseStencilBuffer(void)
2639 {
2640   TestApplication application;
2641   tet_infoline("Test setting the RenderMode to use the stencil buffer");
2642
2643   Renderer           renderer      = RendererTestFixture(application);
2644   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2645   glAbstraction.EnableEnableDisableCallTrace(true);
2646   glAbstraction.EnableStencilFunctionCallTrace(true);
2647   TraceCallStack& glEnableDisableStack   = glAbstraction.GetEnableDisableTrace();
2648   TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2649
2650   // Set the StencilFunction to something other than the default, to confirm it is set as a property,
2651   // but NO GL call has been made while the RenderMode is set to not use the stencil buffer.
2652   renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::NONE);
2653   ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2654
2655   renderer.SetProperty(Renderer::Property::STENCIL_FUNCTION, StencilFunction::NEVER);
2656   DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_FUNCTION).Get<int>()), static_cast<int>(StencilFunction::NEVER), TEST_LOCATION);
2657
2658   ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2659   std::string methodString("StencilFunc");
2660   DALI_TEST_CHECK(!glStencilFunctionStack.FindMethod(methodString));
2661
2662   // Test the other RenderModes that will not enable the stencil buffer.
2663   renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::AUTO);
2664   ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2665   DALI_TEST_CHECK(!glStencilFunctionStack.FindMethod(methodString));
2666
2667   renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::COLOR);
2668   ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2669   DALI_TEST_CHECK(!glStencilFunctionStack.FindMethod(methodString));
2670
2671   // Now set the RenderMode to modes that will use the stencil buffer, and check the StencilFunction has changed.
2672   renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::STENCIL);
2673   ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2674
2675   DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Enable", GetStencilTestString()));
2676   DALI_TEST_CHECK(glStencilFunctionStack.FindMethod(methodString));
2677
2678   // Test the COLOR_STENCIL RenderMode as it also enables the stencil buffer.
2679   // First set a mode to turn off the stencil buffer, so the enable is required.
2680   renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::COLOR);
2681   ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2682   renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::COLOR_STENCIL);
2683   // Set a different stencil function as the last one is cached.
2684   renderer.SetProperty(Renderer::Property::STENCIL_FUNCTION, StencilFunction::ALWAYS);
2685   ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2686
2687   DALI_TEST_CHECK(glEnableDisableStack.FindMethodAndParams("Enable", GetStencilTestString()));
2688   DALI_TEST_CHECK(glStencilFunctionStack.FindMethod(methodString));
2689
2690   END_TEST;
2691 }
2692
2693 // Helper function for the SetRenderModeToUseColorBuffer test.
2694 void CheckRenderModeColorMask(TestApplication& application, Renderer& renderer, RenderMode::Type renderMode, bool expectedValue)
2695 {
2696   // Set the RenderMode property to a value that should not allow color buffer writes.
2697   renderer.SetProperty(Renderer::Property::RENDER_MODE, renderMode);
2698   application.SendNotification();
2699   application.Render();
2700
2701   // Check if ColorMask has been called, and that the values are correct.
2702   TestGlAbstraction&                        glAbstraction = application.GetGlAbstraction();
2703   const TestGlAbstraction::ColorMaskParams& colorMaskParams(glAbstraction.GetColorMaskParams());
2704
2705   DALI_TEST_EQUALS<bool>(colorMaskParams.red, expectedValue, TEST_LOCATION);
2706   DALI_TEST_EQUALS<bool>(colorMaskParams.green, expectedValue, TEST_LOCATION);
2707   DALI_TEST_EQUALS<bool>(colorMaskParams.blue, expectedValue, TEST_LOCATION);
2708   DALI_TEST_EQUALS<bool>(colorMaskParams.alpha, expectedValue, TEST_LOCATION);
2709 }
2710
2711 int UtcDaliRendererSetRenderModeToUseColorBuffer(void)
2712 {
2713   TestApplication application;
2714   tet_infoline("Test setting the RenderMode to use the color buffer");
2715
2716   Renderer renderer = RendererTestFixture(application);
2717
2718   // Set the RenderMode property to a value that should not allow color buffer writes.
2719   // Then check if ColorMask has been called, and that the values are correct.
2720   CheckRenderModeColorMask(application, renderer, RenderMode::AUTO, true);
2721   CheckRenderModeColorMask(application, renderer, RenderMode::NONE, false);
2722   CheckRenderModeColorMask(application, renderer, RenderMode::COLOR, true);
2723   CheckRenderModeColorMask(application, renderer, RenderMode::STENCIL, false);
2724   CheckRenderModeColorMask(application, renderer, RenderMode::COLOR_STENCIL, true);
2725
2726   END_TEST;
2727 }
2728
2729 int UtcDaliRendererSetStencilFunction(void)
2730 {
2731   TestApplication application;
2732   tet_infoline("Test setting the StencilFunction");
2733
2734   Renderer           renderer      = RendererTestFixture(application);
2735   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2736   glAbstraction.EnableEnableDisableCallTrace(true);
2737   glAbstraction.EnableStencilFunctionCallTrace(true);
2738   TraceCallStack& glEnableDisableStack   = glAbstraction.GetEnableDisableTrace();
2739   TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2740
2741   // RenderMode must use the stencil for StencilFunction to operate.
2742   renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::STENCIL);
2743   ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2744
2745   /*
2746    * Lookup table for testing StencilFunction.
2747    * Note: This MUST be in the same order as the Dali::StencilFunction enum.
2748    */
2749   const int StencilFunctionLookupTable[] = {
2750     GL_NEVER,
2751     GL_LESS,
2752     GL_EQUAL,
2753     GL_LEQUAL,
2754     GL_GREATER,
2755     GL_NOTEQUAL,
2756     GL_GEQUAL,
2757     GL_ALWAYS};
2758   const int StencilFunctionLookupTableCount = sizeof(StencilFunctionLookupTable) / sizeof(StencilFunctionLookupTable[0]);
2759
2760   /*
2761    * Loop through all types of StencilFunction, checking:
2762    *  - The value is cached (set in event thread side)
2763    *  - Causes "glStencilFunc" to be called
2764    *  - Checks the correct parameters to "glStencilFunc" were used
2765    */
2766   std::string nonChangingParameters = "0, 255";
2767   std::string methodString("StencilFunc");
2768   for(int i = 0; i < StencilFunctionLookupTableCount; ++i)
2769   {
2770     // Set the property.
2771     renderer.SetProperty(Renderer::Property::STENCIL_FUNCTION, static_cast<Dali::StencilFunction::Type>(i));
2772
2773     // Check GetProperty returns the same value.
2774     DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_FUNCTION).Get<int>()), i, TEST_LOCATION);
2775
2776     // Reset the trace debug.
2777     ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2778
2779     // Check the function is called and the parameters are correct.
2780     std::stringstream parameterStream;
2781     parameterStream << StencilFunctionLookupTable[i] << ", " << nonChangingParameters;
2782
2783     DALI_TEST_CHECK(glStencilFunctionStack.FindMethodAndParams(methodString, parameterStream.str()));
2784   }
2785
2786   // Change the Function Reference only and check the behavior is correct:
2787   // 170 is 0xaa in hex / 10101010 in binary (every other bit set).
2788   int testValueReference = 170;
2789   renderer.SetProperty(Renderer::Property::STENCIL_FUNCTION_REFERENCE, testValueReference);
2790
2791   DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_FUNCTION_REFERENCE).Get<int>()), testValueReference, TEST_LOCATION);
2792
2793   ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2794
2795   DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetCurrentProperty(Renderer::Property::STENCIL_FUNCTION_REFERENCE).Get<int>()), testValueReference, TEST_LOCATION);
2796
2797   std::stringstream parameterStream;
2798   parameterStream << StencilFunctionLookupTable[StencilOperation::DECREMENT_WRAP] << ", " << testValueReference << ", 255";
2799
2800   DALI_TEST_CHECK(glStencilFunctionStack.FindMethodAndParams(methodString, parameterStream.str()));
2801
2802   // Change the Function Mask only and check the behavior is correct:
2803   // 85 is 0x55 in hex / 01010101 in binary (every other bit set).
2804   int testValueMask = 85;
2805   renderer.SetProperty(Renderer::Property::STENCIL_FUNCTION_MASK, testValueMask);
2806
2807   DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_FUNCTION_MASK).Get<int>()), testValueMask, TEST_LOCATION);
2808
2809   ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2810
2811   DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetCurrentProperty(Renderer::Property::STENCIL_FUNCTION_MASK).Get<int>()), testValueMask, TEST_LOCATION);
2812
2813   // Clear the stringstream.
2814   parameterStream.str(std::string());
2815   parameterStream << StencilFunctionLookupTable[StencilOperation::DECREMENT_WRAP] << ", " << testValueReference << ", " << testValueMask;
2816
2817   DALI_TEST_CHECK(glStencilFunctionStack.FindMethodAndParams(methodString, parameterStream.str()));
2818
2819   END_TEST;
2820 }
2821
2822 int UtcDaliRendererSetStencilOperation(void)
2823 {
2824   TestApplication application;
2825   tet_infoline("Test setting the StencilOperation");
2826
2827   Renderer           renderer      = RendererTestFixture(application);
2828   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2829   glAbstraction.EnableEnableDisableCallTrace(true);
2830   glAbstraction.EnableStencilFunctionCallTrace(true);
2831   TraceCallStack& glEnableDisableStack   = glAbstraction.GetEnableDisableTrace();
2832   TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2833
2834   // RenderMode must use the stencil for StencilOperation to operate.
2835   renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::STENCIL);
2836
2837   /*
2838    * Lookup table for testing StencilOperation.
2839    * Note: This MUST be in the same order as the Dali::StencilOperation enum.
2840    */
2841   const int StencilOperationLookupTable[] = {
2842     GL_ZERO,
2843     GL_KEEP,
2844     GL_REPLACE,
2845     GL_INCR,
2846     GL_DECR,
2847     GL_INVERT,
2848     GL_INCR_WRAP,
2849     GL_DECR_WRAP};
2850   const int StencilOperationLookupTableCount = sizeof(StencilOperationLookupTable) / sizeof(StencilOperationLookupTable[0]);
2851
2852   // Set all 3 StencilOperation properties to a default.
2853   renderer.SetProperty(Renderer::Property::STENCIL_OPERATION_ON_FAIL, StencilOperation::KEEP);
2854   renderer.SetProperty(Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, StencilOperation::ZERO);
2855   renderer.SetProperty(Renderer::Property::STENCIL_OPERATION_ON_Z_PASS, StencilOperation::ZERO);
2856
2857   // Set our expected parameter list to the equivalent result.
2858   int parameters[] = {StencilOperationLookupTable[StencilOperation::ZERO], StencilOperationLookupTable[StencilOperation::ZERO], StencilOperationLookupTable[StencilOperation::ZERO]};
2859
2860   ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2861
2862   /*
2863    * Loop through all types of StencilOperation, checking:
2864    *  - The value is cached (set in event thread side)
2865    *  - Causes "glStencilFunc" to be called
2866    *  - Checks the correct parameters to "glStencilFunc" were used
2867    *  - Checks the above for all 3 parameter placements of StencilOperation ( OnFail, OnZFail, OnPass )
2868    */
2869   std::string methodString("StencilOp");
2870
2871   for(int i = 0; i < StencilOperationLookupTableCount; ++i)
2872   {
2873     for(int j = 0; j < StencilOperationLookupTableCount; ++j)
2874     {
2875       for(int k = 0; k < StencilOperationLookupTableCount; ++k)
2876       {
2877         // Set the property (outer loop causes all 3 different properties to be set separately).
2878         renderer.SetProperty(Renderer::Property::STENCIL_OPERATION_ON_FAIL, static_cast<Dali::StencilFunction::Type>(i));
2879         renderer.SetProperty(Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, static_cast<Dali::StencilFunction::Type>(j));
2880         renderer.SetProperty(Renderer::Property::STENCIL_OPERATION_ON_Z_PASS, static_cast<Dali::StencilFunction::Type>(k));
2881
2882         // Check GetProperty returns the same value.
2883         DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_OPERATION_ON_FAIL).Get<int>()), i, TEST_LOCATION);
2884         DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL).Get<int>()), j, TEST_LOCATION);
2885         DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_OPERATION_ON_Z_PASS).Get<int>()), k, TEST_LOCATION);
2886
2887         // Reset the trace debug.
2888         ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2889
2890         // Check the function is called and the parameters are correct.
2891         // Set the expected parameter value at its correct index (only)
2892         parameters[0u] = StencilOperationLookupTable[i];
2893         parameters[1u] = StencilOperationLookupTable[j];
2894         parameters[2u] = StencilOperationLookupTable[k];
2895
2896         // Build the parameter list.
2897         std::stringstream parameterStream;
2898         for(int parameterBuild = 0; parameterBuild < 3; ++parameterBuild)
2899         {
2900           parameterStream << parameters[parameterBuild];
2901           // Comma-separate the parameters.
2902           if(parameterBuild < 2)
2903           {
2904             parameterStream << ", ";
2905           }
2906         }
2907
2908         // Check the function was called and the parameters were correct.
2909         DALI_TEST_CHECK(glStencilFunctionStack.FindMethodAndParams(methodString, parameterStream.str()));
2910       }
2911     }
2912   }
2913
2914   END_TEST;
2915 }
2916
2917 int UtcDaliRendererSetStencilMask(void)
2918 {
2919   TestApplication application;
2920   tet_infoline("Test setting the StencilMask");
2921
2922   Renderer           renderer      = RendererTestFixture(application);
2923   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2924   glAbstraction.EnableEnableDisableCallTrace(true);
2925   glAbstraction.EnableStencilFunctionCallTrace(true);
2926   TraceCallStack& glEnableDisableStack   = glAbstraction.GetEnableDisableTrace();
2927   TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2928
2929   // RenderMode must use the stencil for StencilMask to operate.
2930   renderer.SetProperty(Renderer::Property::RENDER_MODE, RenderMode::STENCIL);
2931
2932   // Set the StencilMask property to a value.
2933   renderer.SetProperty(Renderer::Property::STENCIL_MASK, 0x00);
2934
2935   // Check GetProperty returns the same value.
2936   DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_MASK).Get<int>()), 0x00, TEST_LOCATION);
2937
2938   ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2939
2940   DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetCurrentProperty(Renderer::Property::STENCIL_MASK).Get<int>()), 0x00, TEST_LOCATION);
2941
2942   std::string methodString("StencilMask");
2943   std::string parameterString = "0";
2944
2945   // Check the function was called and the parameters were correct.
2946   DALI_TEST_CHECK(glStencilFunctionStack.FindMethodAndParams(methodString, parameterString));
2947
2948   // Set the StencilMask property to another value to ensure it has changed.
2949   renderer.SetProperty(Renderer::Property::STENCIL_MASK, 0xFF);
2950
2951   // Check GetProperty returns the same value.
2952   DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetProperty(Renderer::Property::STENCIL_MASK).Get<int>()), 0xFF, TEST_LOCATION);
2953
2954   ResetDebugAndFlush(application, glEnableDisableStack, glStencilFunctionStack);
2955
2956   DALI_TEST_EQUALS<int>(static_cast<int>(renderer.GetCurrentProperty(Renderer::Property::STENCIL_MASK).Get<int>()), 0xFF, TEST_LOCATION);
2957
2958   parameterString = "255";
2959
2960   // Check the function was called and the parameters were correct.
2961   DALI_TEST_CHECK(glStencilFunctionStack.FindMethodAndParams(methodString, parameterString));
2962
2963   END_TEST;
2964 }
2965
2966 int UtcDaliRendererWrongNumberOfTextures(void)
2967 {
2968   TestApplication application;
2969   tet_infoline("Test renderer does render even if number of textures is different than active samplers in the shader");
2970
2971   //Create a TextureSet with 4 textures (One more texture in the texture set than active samplers)
2972   //@note Shaders in the test suit have 3 active samplers. See TestGlAbstraction::GetActiveUniform()
2973   Texture    texture    = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 64u, 64u);
2974   TextureSet textureSet = CreateTextureSet();
2975   textureSet.SetTexture(0, texture);
2976   textureSet.SetTexture(1, texture);
2977   textureSet.SetTexture(2, texture);
2978   textureSet.SetTexture(3, texture);
2979   Shader   shader   = Shader::New("VertexSource", "FragmentSource");
2980   Geometry geometry = CreateQuadGeometry();
2981   Renderer renderer = Renderer::New(geometry, shader);
2982   renderer.SetTextures(textureSet);
2983
2984   Actor actor = Actor::New();
2985   actor.AddRenderer(renderer);
2986   actor.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 0.0f));
2987   actor.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
2988   application.GetScene().Add(actor);
2989
2990   TestGlAbstraction& gl        = application.GetGlAbstraction();
2991   TraceCallStack&    drawTrace = gl.GetDrawTrace();
2992   drawTrace.Reset();
2993   drawTrace.Enable(true);
2994
2995   application.SendNotification();
2996   application.Render(0);
2997
2998   //Test we do the drawcall when TextureSet has more textures than there are active samplers in the shader
2999   DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION);
3000
3001   //Create a TextureSet with 1 texture (two more active samplers than texture in the texture set)
3002   //@note Shaders in the test suit have 3 active samplers. See TestGlAbstraction::GetActiveUniform()
3003   textureSet = CreateTextureSet();
3004   renderer.SetTextures(textureSet);
3005   textureSet.SetTexture(0, texture);
3006   drawTrace.Reset();
3007   application.SendNotification();
3008   application.Render(0);
3009
3010   //Test we do the drawcall when TextureSet has less textures than there are active samplers in the shader.
3011   DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION);
3012
3013   END_TEST;
3014 }
3015
3016 int UtcDaliRendererOpacity(void)
3017 {
3018   TestApplication application;
3019
3020   tet_infoline("Test OPACITY property");
3021
3022   Geometry geometry = CreateQuadGeometry();
3023   Shader   shader   = Shader::New("vertexSrc", "fragmentSrc");
3024   Renderer renderer = Renderer::New(geometry, shader);
3025
3026   Actor actor = Actor::New();
3027   actor.AddRenderer(renderer);
3028   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3029   actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 1.0f));
3030   application.GetScene().Add(actor);
3031
3032   Property::Value value = renderer.GetProperty(DevelRenderer::Property::OPACITY);
3033   float           opacity;
3034   DALI_TEST_CHECK(value.Get(opacity));
3035   DALI_TEST_EQUALS(opacity, 1.0f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3036
3037   application.SendNotification();
3038   application.Render();
3039
3040   Vector4            actualValue;
3041   TestGlAbstraction& gl = application.GetGlAbstraction();
3042   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uColor", actualValue));
3043   DALI_TEST_EQUALS(actualValue.a, 1.0f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3044
3045   renderer.SetProperty(DevelRenderer::Property::OPACITY, 0.5f);
3046
3047   application.SendNotification();
3048   application.Render();
3049
3050   value = renderer.GetProperty(DevelRenderer::Property::OPACITY);
3051   DALI_TEST_CHECK(value.Get(opacity));
3052   DALI_TEST_EQUALS(opacity, 0.5f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3053
3054   value = renderer.GetCurrentProperty(DevelRenderer::Property::OPACITY);
3055   DALI_TEST_CHECK(value.Get(opacity));
3056   DALI_TEST_EQUALS(opacity, 0.5f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3057
3058   DALI_TEST_CHECK(gl.GetUniformValue<Vector4>("uColor", actualValue));
3059   DALI_TEST_EQUALS(actualValue.a, 0.5f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3060
3061   END_TEST;
3062 }
3063
3064 int UtcDaliRendererOpacityAnimation(void)
3065 {
3066   TestApplication application;
3067
3068   tet_infoline("Test OPACITY property animation");
3069
3070   Geometry geometry = CreateQuadGeometry();
3071   Shader   shader   = Shader::New("vertexSrc", "fragmentSrc");
3072   Renderer renderer = Renderer::New(geometry, shader);
3073
3074   Actor actor = Actor::New();
3075   actor.AddRenderer(renderer);
3076   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3077   actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 1.0f));
3078   application.GetScene().Add(actor);
3079
3080   application.SendNotification();
3081   application.Render(0);
3082
3083   Property::Value value = renderer.GetProperty(DevelRenderer::Property::OPACITY);
3084   float           opacity;
3085   DALI_TEST_CHECK(value.Get(opacity));
3086   DALI_TEST_EQUALS(opacity, 1.0f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3087
3088   Animation animation = Animation::New(1.0f);
3089   animation.AnimateTo(Property(renderer, DevelRenderer::Property::OPACITY), 0.0f);
3090   animation.Play();
3091
3092   application.SendNotification();
3093   application.Render(1000);
3094
3095   value = renderer.GetProperty(DevelRenderer::Property::OPACITY);
3096   DALI_TEST_CHECK(value.Get(opacity));
3097   DALI_TEST_EQUALS(opacity, 0.0f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3098
3099   // Need to clear the animation before setting the property as the animation value is baked and will override any previous setters
3100   animation.Clear();
3101   renderer.SetProperty(DevelRenderer::Property::OPACITY, 0.1f);
3102
3103   animation.AnimateBy(Property(renderer, DevelRenderer::Property::OPACITY), 0.5f);
3104   animation.Play();
3105
3106   application.SendNotification();
3107   application.Render(1000);
3108
3109   value = renderer.GetProperty(DevelRenderer::Property::OPACITY);
3110   DALI_TEST_CHECK(value.Get(opacity));
3111   DALI_TEST_EQUALS(opacity, 0.6f, Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3112   DALI_TEST_EQUALS(opacity, renderer.GetCurrentProperty(DevelRenderer::Property::OPACITY).Get<float>(), Dali::Math::MACHINE_EPSILON_1, TEST_LOCATION);
3113
3114   END_TEST;
3115 }
3116
3117 int UtcDaliRendererInvalidProperty(void)
3118 {
3119   TestApplication application;
3120
3121   tet_infoline("Test invalid property");
3122
3123   Geometry geometry = CreateQuadGeometry();
3124   Shader   shader   = Shader::New("vertexSrc", "fragmentSrc");
3125   Renderer renderer = Renderer::New(geometry, shader);
3126
3127   Actor actor = Actor::New();
3128   actor.AddRenderer(renderer);
3129   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3130   application.GetScene().Add(actor);
3131
3132   application.SendNotification();
3133   application.Render(0);
3134
3135   Property::Value value = renderer.GetProperty(Renderer::Property::DEPTH_INDEX + 100);
3136   DALI_TEST_CHECK(value.GetType() == Property::Type::NONE);
3137
3138   value = renderer.GetCurrentProperty(Renderer::Property::DEPTH_INDEX + 100);
3139   DALI_TEST_CHECK(value.GetType() == Property::Type::NONE);
3140
3141   END_TEST;
3142 }
3143
3144 int UtcDaliRendererRenderingBehavior(void)
3145 {
3146   TestApplication application;
3147
3148   tet_infoline("Test RENDERING_BEHAVIOR property");
3149
3150   Geometry geometry = CreateQuadGeometry();
3151   Shader   shader   = Shader::New("vertexSrc", "fragmentSrc");
3152   Renderer renderer = Renderer::New(geometry, shader);
3153
3154   Actor actor = Actor::New();
3155   actor.AddRenderer(renderer);
3156   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3157   actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 1.0f));
3158   application.GetScene().Add(actor);
3159
3160   Property::Value value = renderer.GetProperty(DevelRenderer::Property::RENDERING_BEHAVIOR);
3161   int             renderingBehavior;
3162   DALI_TEST_CHECK(value.Get(renderingBehavior));
3163   DALI_TEST_EQUALS(static_cast<DevelRenderer::Rendering::Type>(renderingBehavior), DevelRenderer::Rendering::IF_REQUIRED, TEST_LOCATION);
3164
3165   application.SendNotification();
3166   application.Render();
3167
3168   uint32_t updateStatus = application.GetUpdateStatus();
3169
3170   DALI_TEST_CHECK(!(updateStatus & Integration::KeepUpdating::STAGE_KEEP_RENDERING));
3171
3172   renderer.SetProperty(DevelRenderer::Property::RENDERING_BEHAVIOR, DevelRenderer::Rendering::CONTINUOUSLY);
3173
3174   value = renderer.GetProperty(DevelRenderer::Property::RENDERING_BEHAVIOR);
3175   DALI_TEST_CHECK(value.Get(renderingBehavior));
3176   DALI_TEST_EQUALS(static_cast<DevelRenderer::Rendering::Type>(renderingBehavior), DevelRenderer::Rendering::CONTINUOUSLY, TEST_LOCATION);
3177
3178   // Render and check the update status
3179   application.SendNotification();
3180   application.Render();
3181
3182   updateStatus = application.GetUpdateStatus();
3183
3184   DALI_TEST_CHECK(updateStatus & Integration::KeepUpdating::STAGE_KEEP_RENDERING);
3185
3186   value = renderer.GetCurrentProperty(DevelRenderer::Property::RENDERING_BEHAVIOR);
3187   DALI_TEST_CHECK(value.Get(renderingBehavior));
3188   DALI_TEST_EQUALS(static_cast<DevelRenderer::Rendering::Type>(renderingBehavior), DevelRenderer::Rendering::CONTINUOUSLY, TEST_LOCATION);
3189
3190   // Render again and check the update status
3191   application.SendNotification();
3192   application.Render();
3193
3194   updateStatus = application.GetUpdateStatus();
3195
3196   DALI_TEST_CHECK(updateStatus & Integration::KeepUpdating::STAGE_KEEP_RENDERING);
3197
3198   // Change rendering behavior
3199   renderer.SetProperty(DevelRenderer::Property::RENDERING_BEHAVIOR, DevelRenderer::Rendering::IF_REQUIRED);
3200
3201   // Render and check the update status
3202   application.SendNotification();
3203   application.Render();
3204
3205   updateStatus = application.GetUpdateStatus();
3206
3207   DALI_TEST_CHECK(!(updateStatus & Integration::KeepUpdating::STAGE_KEEP_RENDERING));
3208
3209   END_TEST;
3210 }
3211
3212 int UtcDaliRendererRegenerateUniformMap(void)
3213 {
3214   TestApplication application;
3215
3216   tet_infoline("Test regenerating uniform map when attaching renderer to the node");
3217
3218   Geometry geometry = CreateQuadGeometry();
3219   Shader   shader   = Shader::New("vertexSrc", "fragmentSrc");
3220   Renderer renderer = Renderer::New(geometry, shader);
3221
3222   Actor actor = Actor::New();
3223   actor.AddRenderer(renderer);
3224   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3225   actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 1.0f));
3226   application.GetScene().Add(actor);
3227
3228   application.SendNotification();
3229   application.Render();
3230
3231   actor.RemoveRenderer(renderer);
3232   shader = Shader::New("vertexSrc", "fragmentSrc");
3233   shader.RegisterProperty("opacity", 0.5f);
3234   renderer.SetShader(shader);
3235
3236   Stage::GetCurrent().KeepRendering(1.0f);
3237
3238   // Update for several frames
3239   application.SendNotification();
3240   application.Render();
3241   application.SendNotification();
3242   application.Render();
3243   application.SendNotification();
3244   application.Render();
3245   application.SendNotification();
3246   application.Render();
3247
3248   // Add Renderer
3249   actor.AddRenderer(renderer);
3250   application.SendNotification();
3251   application.Render();
3252
3253   // Nothing to test here, the test must not crash
3254   auto updateStatus = application.GetUpdateStatus();
3255   DALI_TEST_CHECK(updateStatus & Integration::KeepUpdating::STAGE_KEEP_RENDERING);
3256
3257   END_TEST;
3258 }
3259
3260 int UtcDaliRendererAddDrawCommands(void)
3261 {
3262   TestApplication application;
3263
3264   tet_infoline("Test adding draw commands to the renderer");
3265
3266   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
3267   glAbstraction.EnableEnableDisableCallTrace(true);
3268
3269   Geometry geometry = CreateQuadGeometry();
3270   Shader   shader   = Shader::New("vertexSrc", "fragmentSrc");
3271   Renderer renderer = Renderer::New(geometry, shader);
3272
3273   renderer.SetProperty(Renderer::Property::BLEND_MODE, Dali::BlendMode::ON);
3274   Actor actor = Actor::New();
3275   actor.AddRenderer(renderer);
3276   actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
3277   actor.SetProperty(Actor::Property::COLOR, Vector4(1.0f, 0.0f, 1.0f, 1.0f));
3278   application.GetScene().Add(actor);
3279
3280   // Expect delivering a single draw call
3281   auto& drawTrace = glAbstraction.GetDrawTrace();
3282   drawTrace.Reset();
3283   drawTrace.Enable(true);
3284   application.SendNotification();
3285   application.Render();
3286
3287   DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION);
3288
3289   auto drawCommand1         = DevelRenderer::DrawCommand{};
3290   drawCommand1.drawType     = DevelRenderer::DrawType::INDEXED;
3291   drawCommand1.firstIndex   = 0;
3292   drawCommand1.elementCount = 2;
3293   drawCommand1.queue        = DevelRenderer::RENDER_QUEUE_OPAQUE;
3294
3295   auto drawCommand2         = DevelRenderer::DrawCommand{};
3296   drawCommand2.drawType     = DevelRenderer::DrawType::INDEXED;
3297   drawCommand2.firstIndex   = 2;
3298   drawCommand2.elementCount = 2;
3299   drawCommand2.queue        = DevelRenderer::RENDER_QUEUE_TRANSPARENT;
3300
3301   auto drawCommand3         = DevelRenderer::DrawCommand{};
3302   drawCommand3.drawType     = DevelRenderer::DrawType::ARRAY;
3303   drawCommand3.firstIndex   = 2;
3304   drawCommand3.elementCount = 2;
3305   drawCommand3.queue        = DevelRenderer::RENDER_QUEUE_OPAQUE;
3306
3307   DevelRenderer::AddDrawCommand(renderer, drawCommand1);
3308   DevelRenderer::AddDrawCommand(renderer, drawCommand2);
3309   DevelRenderer::AddDrawCommand(renderer, drawCommand3);
3310
3311   drawTrace.Reset();
3312   drawTrace.Enable(true);
3313   application.SendNotification();
3314   application.Render();
3315
3316   DALI_TEST_EQUALS(drawTrace.CountMethod("DrawElements"), 3, TEST_LOCATION);
3317
3318   END_TEST;
3319 }
3320 int UtcDaliRendererSetGeometryNegative(void)
3321 {
3322   TestApplication application;
3323   Dali::Renderer  instance;
3324   try
3325   {
3326     Dali::Geometry arg1;
3327     instance.SetGeometry(arg1);
3328     DALI_TEST_CHECK(false); // Should not get here
3329   }
3330   catch(...)
3331   {
3332     DALI_TEST_CHECK(true); // We expect an assert
3333   }
3334   END_TEST;
3335 }
3336
3337 int UtcDaliRendererSetTexturesNegative(void)
3338 {
3339   TestApplication application;
3340   Dali::Renderer  instance;
3341   try
3342   {
3343     Dali::TextureSet arg1;
3344     instance.SetTextures(arg1);
3345     DALI_TEST_CHECK(false); // Should not get here
3346   }
3347   catch(...)
3348   {
3349     DALI_TEST_CHECK(true); // We expect an assert
3350   }
3351   END_TEST;
3352 }
3353
3354 int UtcDaliRendererSetShaderNegative(void)
3355 {
3356   TestApplication application;
3357   Dali::Renderer  instance;
3358   try
3359   {
3360     Dali::Shader arg1;
3361     instance.SetShader(arg1);
3362     DALI_TEST_CHECK(false); // Should not get here
3363   }
3364   catch(...)
3365   {
3366     DALI_TEST_CHECK(true); // We expect an assert
3367   }
3368   END_TEST;
3369 }
3370
3371 int UtcDaliRendererGetGeometryNegative(void)
3372 {
3373   TestApplication application;
3374   Dali::Renderer  instance;
3375   try
3376   {
3377     instance.GetGeometry();
3378     DALI_TEST_CHECK(false); // Should not get here
3379   }
3380   catch(...)
3381   {
3382     DALI_TEST_CHECK(true); // We expect an assert
3383   }
3384   END_TEST;
3385 }
3386
3387 int UtcDaliRendererGetTexturesNegative(void)
3388 {
3389   TestApplication application;
3390   Dali::Renderer  instance;
3391   try
3392   {
3393     instance.GetTextures();
3394     DALI_TEST_CHECK(false); // Should not get here
3395   }
3396   catch(...)
3397   {
3398     DALI_TEST_CHECK(true); // We expect an assert
3399   }
3400   END_TEST;
3401 }
3402
3403 int UtcDaliRendererGetShaderNegative(void)
3404 {
3405   TestApplication application;
3406   Dali::Renderer  instance;
3407   try
3408   {
3409     instance.GetShader();
3410     DALI_TEST_CHECK(false); // Should not get here
3411   }
3412   catch(...)
3413   {
3414     DALI_TEST_CHECK(true); // We expect an assert
3415   }
3416   END_TEST;
3417 }