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