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