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