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