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