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