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