Rendering API Stencil Implementation
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-Renderer.cpp
1 /*
2  * Copyright (c) 2016 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/public-api/dali-core.h>
20 #include <dali/devel-api/images/texture-set-image.h>
21 #include <cstdio>
22 #include <string>
23
24 // INTERNAL INCLUDES
25 #include <dali-test-suite-utils.h>
26 #include <test-trace-call-stack.h>
27 #include <mesh-builder.h>
28
29 using namespace Dali;
30
31 namespace // unnamed namespace
32 {
33
34 const BlendFactor::Type   DEFAULT_BLEND_FACTOR_SRC_RGB(    BlendFactor::SRC_ALPHA );
35 const BlendFactor::Type   DEFAULT_BLEND_FACTOR_DEST_RGB(   BlendFactor::ONE_MINUS_SRC_ALPHA );
36 const BlendFactor::Type   DEFAULT_BLEND_FACTOR_SRC_ALPHA(  BlendFactor::ONE );
37 const BlendFactor::Type   DEFAULT_BLEND_FACTOR_DEST_ALPHA( BlendFactor::ONE_MINUS_SRC_ALPHA );
38
39 const BlendEquation::Type DEFAULT_BLEND_EQUATION_RGB(   BlendEquation::ADD );
40 const BlendEquation::Type DEFAULT_BLEND_EQUATION_ALPHA( BlendEquation::ADD );
41
42 /**
43  * @brief Get GL stencil test enumeration value as a string.
44  * @return The string representation of the value of GL_STENCIL_TEST
45  */
46 std::string GetStencilTestString(void)
47 {
48   std::stringstream stream;
49   stream << GL_STENCIL_TEST;
50   return stream.str();
51 }
52
53 void ResetDebugAndFlush( TestApplication& application, TraceCallStack& glEnableDisableStack, TraceCallStack& glStencilFunctionStack )
54 {
55   glEnableDisableStack.Reset();
56   glStencilFunctionStack.Reset();
57   application.SendNotification();
58   application.Render();
59 }
60
61 void TestConstraintNoBlue( Vector4& current, const PropertyInputContainer& inputs )
62 {
63   current.b = 0.0f;
64 }
65
66 } // unnamed namespace
67
68 void renderer_test_startup(void)
69 {
70   test_return_value = TET_UNDEF;
71 }
72
73 void renderer_test_cleanup(void)
74 {
75   test_return_value = TET_PASS;
76 }
77
78
79 int UtcDaliRendererNew01(void)
80 {
81   TestApplication application;
82
83   Geometry geometry = CreateQuadGeometry();
84   Shader shader = CreateShader();
85   Renderer renderer = Renderer::New(geometry, shader);
86
87   DALI_TEST_EQUALS( (bool)renderer, true, TEST_LOCATION );
88   END_TEST;
89 }
90
91 int UtcDaliRendererNew02(void)
92 {
93   TestApplication application;
94   Renderer renderer;
95   DALI_TEST_EQUALS( (bool)renderer, false, TEST_LOCATION );
96   END_TEST;
97 }
98
99 int UtcDaliRendererCopyConstructor(void)
100 {
101   TestApplication application;
102
103   Geometry geometry = CreateQuadGeometry();
104   Shader shader = CreateShader();
105   Renderer renderer = Renderer::New(geometry, shader);
106
107   Renderer rendererCopy( renderer );
108   DALI_TEST_EQUALS( (bool)rendererCopy, true, TEST_LOCATION );
109
110   END_TEST;
111 }
112
113 int UtcDaliRendererAssignmentOperator(void)
114 {
115   TestApplication application;
116
117   Geometry geometry = CreateQuadGeometry();
118   Shader shader = CreateShader();
119   Renderer renderer = Renderer::New(geometry, shader);
120
121   Renderer renderer2;
122   DALI_TEST_EQUALS( (bool)renderer2, false, TEST_LOCATION );
123
124   renderer2 = renderer;
125   DALI_TEST_EQUALS( (bool)renderer2, true, TEST_LOCATION );
126   END_TEST;
127 }
128
129 int UtcDaliRendererDownCast01(void)
130 {
131   TestApplication application;
132
133   Geometry geometry = CreateQuadGeometry();
134   Shader shader = CreateShader();
135   Renderer renderer = Renderer::New(geometry, shader);
136
137   BaseHandle handle(renderer);
138   Renderer renderer2 = Renderer::DownCast(handle);
139   DALI_TEST_EQUALS( (bool)renderer2, true, TEST_LOCATION );
140   END_TEST;
141 }
142
143 int UtcDaliRendererDownCast02(void)
144 {
145   TestApplication application;
146
147   Handle handle = Handle::New(); // Create a custom object
148   Renderer renderer = Renderer::DownCast(handle);
149   DALI_TEST_EQUALS( (bool)renderer, false, TEST_LOCATION );
150   END_TEST;
151 }
152
153 int UtcDaliRendererSetGetGeometry(void)
154 {
155   TestApplication application;
156   tet_infoline( "Test SetGeometry, GetGeometry" );
157
158   Geometry geometry1 = CreateQuadGeometry();
159   Geometry geometry2 = CreateQuadGeometry();
160
161   Shader shader = CreateShader();
162   Renderer renderer = Renderer::New(geometry1, shader);
163   Actor actor = Actor::New();
164   actor.AddRenderer(renderer);
165   actor.SetSize(400, 400);
166   Stage::GetCurrent().Add(actor);
167
168   application.SendNotification();
169   application.Render(0);
170   DALI_TEST_EQUALS( renderer.GetGeometry(), geometry1, TEST_LOCATION );
171
172   // Set geometry2 to the renderer
173   renderer.SetGeometry( geometry2 );
174
175   application.SendNotification();
176   application.Render(0);
177   DALI_TEST_EQUALS( renderer.GetGeometry(), geometry2, TEST_LOCATION );
178
179   END_TEST;
180 }
181
182 int UtcDaliRendererSetGetShader(void)
183 {
184   TestApplication application;
185   tet_infoline( "Test SetShader, GetShader" );
186
187   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
188   glAbstraction.EnableCullFaceCallTrace(true);
189
190   Shader shader1 = CreateShader();
191   shader1.RegisterProperty( "uFadeColor", Color::RED );
192
193   Shader shader2 = CreateShader();
194   shader2.RegisterProperty( "uFadeColor", Color::GREEN );
195
196   Geometry geometry = CreateQuadGeometry();
197   Renderer renderer = Renderer::New(geometry, shader1);
198   Actor actor = Actor::New();
199   actor.AddRenderer(renderer);
200   actor.SetSize(400, 400);
201   Stage::GetCurrent().Add(actor);
202
203   TestGlAbstraction& gl = application.GetGlAbstraction();
204   application.SendNotification();
205   application.Render(0);
206
207   // Expect that the first shaders's fade color property is accessed
208   Vector4 actualValue(Vector4::ZERO);
209   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
210   DALI_TEST_EQUALS( actualValue, Color::RED, TEST_LOCATION );
211
212   DALI_TEST_EQUALS( renderer.GetShader(), shader1, TEST_LOCATION );
213
214   // set the second shader to the renderer
215   renderer.SetShader( shader2 );
216
217   application.SendNotification();
218   application.Render(0);
219
220   // Expect that the second shader's fade color property is accessed
221   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
222   DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
223
224   DALI_TEST_EQUALS( renderer.GetShader(), shader2, TEST_LOCATION );
225
226   END_TEST;
227 }
228
229 int UtcDaliRendererSetGetDepthIndex(void)
230 {
231   TestApplication application;
232
233   tet_infoline("Test SetDepthIndex, GetDepthIndex");
234
235   Shader shader = CreateShader();
236   Geometry geometry = CreateQuadGeometry();
237   Renderer renderer = Renderer::New(geometry, shader);
238   Actor actor = Actor::New();
239   actor.AddRenderer(renderer);
240   actor.SetSize(400, 400);
241   Stage::GetCurrent().Add(actor);
242
243   application.SendNotification();
244   application.Render(0);
245   DALI_TEST_EQUALS( renderer.GetProperty<int>(Renderer::Property::DEPTH_INDEX), 0, TEST_LOCATION );
246
247   renderer.SetProperty( Renderer::Property::DEPTH_INDEX, 1 );
248
249   application.SendNotification();
250   application.Render(0);
251   DALI_TEST_EQUALS( renderer.GetProperty<int>(Renderer::Property::DEPTH_INDEX), 1, TEST_LOCATION );
252
253   renderer.SetProperty( Renderer::Property::DEPTH_INDEX, 10 );
254
255   application.SendNotification();
256   application.Render(0);
257   DALI_TEST_EQUALS( renderer.GetProperty<int>(Renderer::Property::DEPTH_INDEX), 10, TEST_LOCATION );
258
259   END_TEST;
260 }
261
262 int UtcDaliRendererSetGetFaceCullingMode(void)
263 {
264   TestApplication application;
265
266   tet_infoline("Test SetFaceCullingMode(cullingMode)");
267   Geometry geometry = CreateQuadGeometry();
268   Shader shader = CreateShader();
269   Renderer renderer = Renderer::New( geometry, shader );
270
271   Actor actor = Actor::New();
272   actor.AddRenderer(renderer);
273   actor.SetSize(400, 400);
274   Stage::GetCurrent().Add(actor);
275
276   // By default, none of the faces should be culled
277   unsigned int cullFace = renderer.GetProperty<int>( Renderer::Property::FACE_CULLING_MODE );
278   DALI_TEST_CHECK( static_cast< FaceCullingMode::Type >( cullFace ) == FaceCullingMode::NONE );
279
280   TestGlAbstraction& gl = application.GetGlAbstraction();
281   TraceCallStack& cullFaceStack = gl.GetCullFaceTrace();
282   gl.EnableCullFaceCallTrace(true);
283
284   {
285     cullFaceStack.Reset();
286     renderer.SetProperty( Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::FRONT_AND_BACK );
287     application.SendNotification();
288     application.Render();
289
290     DALI_TEST_EQUALS( cullFaceStack.CountMethod( "CullFace" ), 1, TEST_LOCATION );
291
292     std::ostringstream cullModeString;
293     cullModeString << GL_FRONT_AND_BACK;
294
295     DALI_TEST_CHECK( cullFaceStack.FindMethodAndParams( "CullFace", cullModeString.str() ) );
296     cullFace = renderer.GetProperty<int>( Renderer::Property::FACE_CULLING_MODE );
297     DALI_TEST_CHECK( static_cast< FaceCullingMode::Type >( cullFace ) == FaceCullingMode::FRONT_AND_BACK );
298   }
299
300   {
301     cullFaceStack.Reset();
302     renderer.SetProperty( Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::BACK );
303     application.SendNotification();
304     application.Render();
305
306     DALI_TEST_EQUALS( cullFaceStack.CountMethod( "CullFace" ), 1, TEST_LOCATION );
307
308     std::ostringstream cullModeString;
309     cullModeString << GL_BACK;
310
311     DALI_TEST_CHECK( cullFaceStack.FindMethodAndParams( "CullFace", cullModeString.str() ) );
312     cullFace = renderer.GetProperty<int>( Renderer::Property::FACE_CULLING_MODE );
313     DALI_TEST_CHECK( static_cast< FaceCullingMode::Type >( cullFace ) == FaceCullingMode::BACK );
314   }
315
316   {
317     cullFaceStack.Reset();
318     renderer.SetProperty( Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::FRONT );
319     application.SendNotification();
320     application.Render();
321
322     DALI_TEST_EQUALS( cullFaceStack.CountMethod( "CullFace" ), 1, TEST_LOCATION );
323
324     std::ostringstream cullModeString;
325     cullModeString << GL_FRONT;
326
327     DALI_TEST_CHECK( cullFaceStack.FindMethodAndParams( "CullFace", cullModeString.str() ) );
328     cullFace = renderer.GetProperty<int>( Renderer::Property::FACE_CULLING_MODE );
329     DALI_TEST_CHECK( static_cast< FaceCullingMode::Type >( cullFace ) == FaceCullingMode::FRONT );
330   }
331
332   {
333     cullFaceStack.Reset();
334     renderer.SetProperty( Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::NONE );
335     application.SendNotification();
336     application.Render();
337
338     DALI_TEST_EQUALS( cullFaceStack.CountMethod( "CullFace" ), 0, TEST_LOCATION );
339     cullFace = renderer.GetProperty<int>( Renderer::Property::FACE_CULLING_MODE );
340     DALI_TEST_CHECK( static_cast< FaceCullingMode::Type >( cullFace ) == FaceCullingMode::NONE );
341   }
342
343   END_TEST;
344 }
345
346 int UtcDaliRendererBlendOptions01(void)
347 {
348   TestApplication application;
349
350   tet_infoline("Test BLEND_FACTOR properties ");
351
352   Geometry geometry = CreateQuadGeometry();
353   Shader shader = CreateShader();
354   Renderer renderer = Renderer::New( geometry, shader );
355
356   Actor actor = Actor::New();
357   // set a transparent actor color so that blending is enabled
358   actor.SetOpacity( 0.5f );
359   actor.AddRenderer(renderer);
360   actor.SetSize(400, 400);
361   Stage::GetCurrent().Add(actor);
362
363   renderer.SetProperty( Renderer::Property::BLEND_FACTOR_SRC_RGB,    BlendFactor::ONE_MINUS_SRC_COLOR );
364   renderer.SetProperty( Renderer::Property::BLEND_FACTOR_DEST_RGB,   BlendFactor::SRC_ALPHA_SATURATE  );
365   renderer.SetProperty( Renderer::Property::BLEND_FACTOR_SRC_ALPHA,  BlendFactor::ONE_MINUS_SRC_COLOR );
366   renderer.SetProperty( Renderer::Property::BLEND_FACTOR_DEST_ALPHA, BlendFactor::SRC_ALPHA_SATURATE  );
367
368   // Test that Set was successful:
369   int srcFactorRgb    = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
370   int destFactorRgb   = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
371   int srcFactorAlpha  = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
372   int destFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
373
374   DALI_TEST_EQUALS( (int)BlendFactor::ONE_MINUS_SRC_COLOR, srcFactorRgb,    TEST_LOCATION );
375   DALI_TEST_EQUALS( (int)BlendFactor::SRC_ALPHA_SATURATE,  destFactorRgb,   TEST_LOCATION );
376   DALI_TEST_EQUALS( (int)BlendFactor::ONE_MINUS_SRC_COLOR, srcFactorAlpha,  TEST_LOCATION );
377   DALI_TEST_EQUALS( (int)BlendFactor::SRC_ALPHA_SATURATE,  destFactorAlpha, TEST_LOCATION );
378
379   application.SendNotification();
380   application.Render();
381
382   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
383
384   DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_SRC_COLOR, glAbstraction.GetLastBlendFuncSrcRgb(),   TEST_LOCATION );
385   DALI_TEST_EQUALS( (GLenum)GL_SRC_ALPHA_SATURATE,  glAbstraction.GetLastBlendFuncDstRgb(),   TEST_LOCATION );
386   DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_SRC_COLOR, glAbstraction.GetLastBlendFuncSrcAlpha(), TEST_LOCATION );
387   DALI_TEST_EQUALS( (GLenum)GL_SRC_ALPHA_SATURATE,  glAbstraction.GetLastBlendFuncDstAlpha(), TEST_LOCATION );
388
389   END_TEST;
390 }
391
392 int UtcDaliRendererBlendOptions02(void)
393 {
394   TestApplication application;
395
396   tet_infoline("Test BLEND_FACTOR properties ");
397
398   Geometry geometry = CreateQuadGeometry();
399   Shader shader = CreateShader();
400   Renderer renderer = Renderer::New( geometry, shader );
401
402   Actor actor = Actor::New();
403   actor.SetOpacity( 0.5f ); // enable blending
404   actor.AddRenderer(renderer);
405   actor.SetSize(400, 400);
406   Stage::GetCurrent().Add(actor);
407
408   renderer.SetProperty( Renderer::Property::BLEND_FACTOR_SRC_RGB,    BlendFactor::CONSTANT_COLOR );
409   renderer.SetProperty( Renderer::Property::BLEND_FACTOR_DEST_RGB,   BlendFactor::ONE_MINUS_CONSTANT_COLOR );
410   renderer.SetProperty( Renderer::Property::BLEND_FACTOR_SRC_ALPHA,  BlendFactor::CONSTANT_ALPHA );
411   renderer.SetProperty( Renderer::Property::BLEND_FACTOR_DEST_ALPHA, BlendFactor::ONE_MINUS_CONSTANT_ALPHA  );
412
413   // Test that Set was successful:
414   {
415     int srcFactorRgb    = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
416     int destFactorRgb   = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
417     int srcFactorAlpha  = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
418     int destFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
419
420     DALI_TEST_EQUALS( (int)BlendFactor::CONSTANT_COLOR,            srcFactorRgb,    TEST_LOCATION );
421     DALI_TEST_EQUALS( (int)BlendFactor::ONE_MINUS_CONSTANT_COLOR,  destFactorRgb,   TEST_LOCATION );
422     DALI_TEST_EQUALS( (int)BlendFactor::CONSTANT_ALPHA,            srcFactorAlpha,  TEST_LOCATION );
423     DALI_TEST_EQUALS( (int)BlendFactor::ONE_MINUS_CONSTANT_ALPHA,  destFactorAlpha, TEST_LOCATION );
424   }
425
426   application.SendNotification();
427   application.Render();
428
429   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
430   DALI_TEST_EQUALS( (GLenum)GL_CONSTANT_COLOR,           glAbstraction.GetLastBlendFuncSrcRgb(),   TEST_LOCATION );
431   DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_CONSTANT_COLOR, glAbstraction.GetLastBlendFuncDstRgb(),   TEST_LOCATION );
432   DALI_TEST_EQUALS( (GLenum)GL_CONSTANT_ALPHA,           glAbstraction.GetLastBlendFuncSrcAlpha(), TEST_LOCATION );
433   DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_CONSTANT_ALPHA, glAbstraction.GetLastBlendFuncDstAlpha(), TEST_LOCATION );
434
435   END_TEST;
436 }
437
438 int UtcDaliRendererBlendOptions03(void)
439 {
440   TestApplication application;
441
442   tet_infoline("Test GetBlendEquation() defaults ");
443
444   Geometry geometry = CreateQuadGeometry();
445   Shader shader = CreateShader();
446   Renderer renderer = Renderer::New( geometry, shader );
447
448   Actor actor = Actor::New();
449   actor.AddRenderer(renderer);
450   actor.SetSize(400, 400);
451   Stage::GetCurrent().Add(actor);
452
453   // Test the defaults as documented in blending.h
454   int equationRgb   = renderer.GetProperty<int>( Renderer::Property::BLEND_EQUATION_RGB );
455   int equationAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_EQUATION_ALPHA );
456
457   DALI_TEST_EQUALS( (int)BlendEquation::ADD, equationRgb,   TEST_LOCATION );
458   DALI_TEST_EQUALS( (int)BlendEquation::ADD, equationAlpha, TEST_LOCATION );
459
460   END_TEST;
461 }
462
463 int UtcDaliRendererBlendOptions04(void)
464 {
465   TestApplication application;
466
467   tet_infoline("Test SetBlendEquation() ");
468
469   Geometry geometry = CreateQuadGeometry();
470   Shader shader = CreateShader();
471   Renderer renderer = Renderer::New( geometry, shader );
472
473   Actor actor = Actor::New();
474   actor.SetOpacity( 0.1f );
475   actor.AddRenderer(renderer);
476   actor.SetSize(400, 400);
477   Stage::GetCurrent().Add(actor);
478
479   // Test the single blending equation setting
480   {
481     renderer.SetProperty( Renderer::Property::BLEND_EQUATION_RGB, BlendEquation::REVERSE_SUBTRACT );
482     int equationRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_EQUATION_RGB );
483     DALI_TEST_EQUALS( (int)BlendEquation::REVERSE_SUBTRACT, equationRgb, TEST_LOCATION );
484   }
485
486   renderer.SetProperty( Renderer::Property::BLEND_EQUATION_RGB,   BlendEquation::REVERSE_SUBTRACT );
487   renderer.SetProperty( Renderer::Property::BLEND_EQUATION_ALPHA, BlendEquation::REVERSE_SUBTRACT );
488
489   // Test that Set was successful
490   {
491     int equationRgb   = renderer.GetProperty<int>( Renderer::Property::BLEND_EQUATION_RGB );
492     int equationAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_EQUATION_ALPHA );
493     DALI_TEST_EQUALS( (int)BlendEquation::REVERSE_SUBTRACT, equationRgb, TEST_LOCATION );
494     DALI_TEST_EQUALS( (int)BlendEquation::REVERSE_SUBTRACT, equationAlpha, TEST_LOCATION );
495   }
496
497   // Render & check GL commands
498   application.SendNotification();
499   application.Render();
500
501   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
502   DALI_TEST_EQUALS( (GLenum)GL_FUNC_REVERSE_SUBTRACT, glAbstraction.GetLastBlendEquationRgb(),   TEST_LOCATION );
503   DALI_TEST_EQUALS( (GLenum)GL_FUNC_REVERSE_SUBTRACT, glAbstraction.GetLastBlendEquationAlpha(), TEST_LOCATION );
504
505   END_TEST;
506 }
507
508 int UtcDaliRendererSetBlendMode01(void)
509 {
510   TestApplication application;
511
512   tet_infoline("Test setting the blend mode to on with an opaque color renders with blending enabled");
513
514   Geometry geometry = CreateQuadGeometry();
515   Shader shader = CreateShader();
516   Renderer renderer = Renderer::New( geometry, shader );
517
518   Actor actor = Actor::New();
519   actor.SetOpacity( 0.98f );
520   actor.AddRenderer(renderer);
521   actor.SetSize(400, 400);
522   Stage::GetCurrent().Add(actor);
523
524   renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::ON);
525
526   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
527   glAbstraction.EnableEnableDisableCallTrace(true);
528
529   application.SendNotification();
530   application.Render();
531
532   TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
533   std::ostringstream blendStr;
534   blendStr << GL_BLEND;
535   DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
536
537   END_TEST;
538 }
539
540 int UtcDaliRendererSetBlendMode02(void)
541 {
542   TestApplication application;
543
544   tet_infoline("Test setting the blend mode to off with a transparent color renders with blending disabled (and not enabled)");
545
546   Geometry geometry = CreateQuadGeometry();
547   Shader shader = CreateShader();
548   Renderer renderer = Renderer::New( geometry, shader );
549
550   Actor actor = Actor::New();
551   actor.SetOpacity( 0.15f );
552   actor.AddRenderer(renderer);
553   actor.SetSize(400, 400);
554   Stage::GetCurrent().Add(actor);
555
556   renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::OFF);
557
558   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
559   glAbstraction.EnableEnableDisableCallTrace(true);
560
561   application.SendNotification();
562   application.Render();
563
564   TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
565   std::ostringstream blendStr;
566   blendStr << GL_BLEND;
567   DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
568
569   END_TEST;
570 }
571
572 int UtcDaliRendererSetBlendMode03(void)
573 {
574   TestApplication application;
575
576   tet_infoline("Test setting the blend mode to auto with a transparent color renders with blending enabled");
577
578   Geometry geometry = CreateQuadGeometry();
579   Shader shader = CreateShader();
580   Renderer renderer = Renderer::New( geometry, shader );
581
582   Actor actor = Actor::New();
583   actor.SetOpacity( 0.75f );
584   actor.AddRenderer(renderer);
585   actor.SetSize(400, 400);
586   Stage::GetCurrent().Add(actor);
587
588   renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::AUTO);
589
590   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
591   glAbstraction.EnableEnableDisableCallTrace(true);
592
593   application.SendNotification();
594   application.Render();
595
596   TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
597   std::ostringstream blendStr;
598   blendStr << GL_BLEND;
599   DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
600
601   END_TEST;
602 }
603
604 int UtcDaliRendererSetBlendMode04(void)
605 {
606   TestApplication application;
607
608   tet_infoline("Test setting the blend mode to auto with an opaque color renders with blending disabled");
609
610   Geometry geometry = CreateQuadGeometry();
611   Shader shader = CreateShader();
612   Renderer renderer = Renderer::New( geometry, shader );
613
614   Actor actor = Actor::New();
615   actor.AddRenderer(renderer);
616   actor.SetSize(400, 400);
617   Stage::GetCurrent().Add(actor);
618
619   renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::AUTO);
620
621   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
622   glAbstraction.EnableEnableDisableCallTrace(true);
623
624   application.SendNotification();
625   application.Render();
626
627   TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
628   std::ostringstream blendStr;
629   blendStr << GL_BLEND;
630   DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
631
632   END_TEST;
633 }
634
635 int UtcDaliRendererSetBlendMode04b(void)
636 {
637   TestApplication application;
638
639   tet_infoline("Test setting the blend mode to auto with a transparent actor color renders with blending enabled");
640
641   Geometry geometry = CreateQuadGeometry();
642   Shader shader = CreateShader();
643   Renderer renderer = Renderer::New( geometry, shader );
644
645   Actor actor = Actor::New();
646   actor.AddRenderer(renderer);
647   actor.SetSize(400, 400);
648   actor.SetColor( Vector4(1.0f, 0.0f, 1.0f, 0.5f) );
649   Stage::GetCurrent().Add(actor);
650
651   renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::AUTO);
652
653   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
654   glAbstraction.EnableEnableDisableCallTrace(true);
655
656   application.SendNotification();
657   application.Render();
658
659   TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
660   std::ostringstream blendStr;
661   blendStr << GL_BLEND;
662   DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
663
664   END_TEST;
665 }
666
667 int UtcDaliRendererSetBlendMode04c(void)
668 {
669   TestApplication application;
670
671   tet_infoline("Test setting the blend mode to auto with an opaque opaque actor color renders with blending disabled");
672
673   Geometry geometry = CreateQuadGeometry();
674   Shader shader = CreateShader();
675   Renderer renderer = Renderer::New( geometry, shader );
676
677   Actor actor = Actor::New();
678   actor.AddRenderer(renderer);
679   actor.SetSize(400, 400);
680   actor.SetColor( Color::MAGENTA );
681   Stage::GetCurrent().Add(actor);
682
683   renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::AUTO);
684
685   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
686   glAbstraction.EnableEnableDisableCallTrace(true);
687
688   application.SendNotification();
689   application.Render();
690
691   TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
692   std::ostringstream blendStr;
693   blendStr << GL_BLEND;
694   DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
695
696   END_TEST;
697 }
698
699 int UtcDaliRendererSetBlendMode05(void)
700 {
701   TestApplication application;
702
703   tet_infoline("Test setting the blend mode to auto with an opaque color and an image with an alpha channel renders with blending enabled");
704
705   Geometry geometry = CreateQuadGeometry();
706   BufferImage image = BufferImage::New( 40, 40, Pixel::RGBA8888 );
707
708   Shader shader = CreateShader();
709   TextureSet textureSet = CreateTextureSet( image );
710   Renderer renderer = Renderer::New( geometry, shader );
711   renderer.SetTextures( textureSet );
712
713   Actor actor = Actor::New();
714   actor.AddRenderer(renderer);
715   actor.SetSize(400, 400);
716   Stage::GetCurrent().Add(actor);
717
718   renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::AUTO);
719
720   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
721   glAbstraction.EnableEnableDisableCallTrace(true);
722
723   application.SendNotification();
724   application.Render();
725
726   TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
727   std::ostringstream blendStr;
728   blendStr << GL_BLEND;
729   DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
730
731   END_TEST;
732 }
733
734 int UtcDaliRendererSetBlendMode06(void)
735 {
736   TestApplication application;
737   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");
738
739   Geometry geometry = CreateQuadGeometry();
740   Shader shader = Shader::New( "vertexSrc", "fragmentSrc", Shader::HINT_OUTPUT_IS_TRANSPARENT );
741
742   Renderer renderer = Renderer::New( geometry, shader );
743
744   Actor actor = Actor::New();
745   actor.AddRenderer(renderer);
746   actor.SetSize(400, 400);
747   Stage::GetCurrent().Add(actor);
748
749   renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::AUTO);
750
751   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
752   glAbstraction.EnableEnableDisableCallTrace(true);
753
754   application.SendNotification();
755   application.Render();
756
757   TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
758   std::ostringstream blendStr;
759   blendStr << GL_BLEND;
760   DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
761
762   END_TEST;
763 }
764
765 int UtcDaliRendererSetBlendMode07(void)
766 {
767   TestApplication application;
768   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");
769
770   Geometry geometry = CreateQuadGeometry();
771   Shader shader = Shader::New( "vertexSrc", "fragmentSrc" );
772
773   BufferImage image = BufferImage::New( 50, 50, Pixel::RGB888 );
774   TextureSet textureSet = CreateTextureSet( image );
775   Renderer renderer = Renderer::New( geometry, shader );
776   renderer.SetTextures( textureSet );
777
778   Actor actor = Actor::New();
779   actor.AddRenderer(renderer);
780   actor.SetSize(400, 400);
781   Stage::GetCurrent().Add(actor);
782
783   renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::AUTO);
784
785   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
786   glAbstraction.EnableEnableDisableCallTrace(true);
787
788   application.SendNotification();
789   application.Render();
790
791   TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
792   DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", "GL_BLEND" ) );
793
794   END_TEST;
795 }
796
797 int UtcDaliRendererGetBlendMode(void)
798 {
799   TestApplication application;
800
801   tet_infoline("Test GetBlendMode()");
802
803   Geometry geometry = CreateQuadGeometry();
804   Shader shader = Shader::New( "vertexSrc", "fragmentSrc" );
805   Renderer renderer = Renderer::New( geometry, shader );
806
807   // default value
808   unsigned int mode = renderer.GetProperty<int>( Renderer::Property::BLEND_MODE );
809   DALI_TEST_EQUALS( static_cast< BlendMode::Type >( mode ), BlendMode::AUTO, TEST_LOCATION );
810
811   // ON
812   renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::ON );
813   mode = renderer.GetProperty<int>( Renderer::Property::BLEND_MODE );
814   DALI_TEST_EQUALS( static_cast< BlendMode::Type >( mode ), BlendMode::ON, TEST_LOCATION );
815
816   // OFF
817   renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::OFF );
818   mode = renderer.GetProperty<int>( Renderer::Property::BLEND_MODE );
819   DALI_TEST_EQUALS( static_cast< BlendMode::Type >( mode ), BlendMode::OFF, TEST_LOCATION );
820
821   END_TEST;
822 }
823
824 int UtcDaliRendererSetBlendColor(void)
825 {
826   TestApplication application;
827
828   tet_infoline("Test SetBlendColor(color)");
829
830   Geometry geometry = CreateQuadGeometry();
831   Shader shader = Shader::New( "vertexSrc", "fragmentSrc" );
832   TextureSet textureSet = TextureSet::New();
833   BufferImage image = BufferImage::New( 50, 50, Pixel::RGBA8888 );
834   TextureSetImage( textureSet, 0u, image );
835   Renderer renderer = Renderer::New( geometry, shader );
836   renderer.SetTextures( textureSet );
837
838   Actor actor = Actor::New();
839   actor.AddRenderer(renderer);
840   actor.SetSize(400, 400);
841   Stage::GetCurrent().Add(actor);
842
843   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
844
845   renderer.SetProperty( Renderer::Property::BLEND_COLOR, Color::TRANSPARENT );
846   application.SendNotification();
847   application.Render();
848   DALI_TEST_EQUALS( glAbstraction.GetLastBlendColor(), Color::TRANSPARENT, TEST_LOCATION );
849
850   renderer.SetProperty( Renderer::Property::BLEND_COLOR, Color::MAGENTA );
851   application.SendNotification();
852   application.Render();
853   DALI_TEST_EQUALS( glAbstraction.GetLastBlendColor(), Color::MAGENTA, TEST_LOCATION );
854
855   Vector4 color( 0.1f, 0.2f, 0.3f, 0.4f );
856   renderer.SetProperty( Renderer::Property::BLEND_COLOR, color );
857   application.SendNotification();
858   application.Render();
859   DALI_TEST_EQUALS( glAbstraction.GetLastBlendColor(), color, TEST_LOCATION );
860
861   END_TEST;
862 }
863
864 int UtcDaliRendererGetBlendColor(void)
865 {
866   TestApplication application;
867
868   tet_infoline("Test GetBlendColor()");
869
870   Geometry geometry = CreateQuadGeometry();
871   Shader shader = Shader::New( "vertexSrc", "fragmentSrc" );
872   Renderer renderer = Renderer::New( geometry, shader );
873
874   DALI_TEST_EQUALS( renderer.GetProperty<Vector4>( Renderer::Property::BLEND_COLOR ), Color::TRANSPARENT, TEST_LOCATION );
875
876   renderer.SetProperty( Renderer::Property::BLEND_COLOR, Color::MAGENTA );
877   application.SendNotification();
878   application.Render();
879   DALI_TEST_EQUALS( renderer.GetProperty<Vector4>( Renderer::Property::BLEND_COLOR ), Color::MAGENTA, TEST_LOCATION );
880
881   Vector4 color( 0.1f, 0.2f, 0.3f, 0.4f );
882   renderer.SetProperty( Renderer::Property::BLEND_COLOR, color );
883   application.SendNotification();
884   application.Render();
885   DALI_TEST_EQUALS( renderer.GetProperty<Vector4>( Renderer::Property::BLEND_COLOR ), color, TEST_LOCATION );
886
887   END_TEST;
888 }
889
890 int UtcDaliRendererPreMultipledAlpha(void)
891 {
892   TestApplication application;
893
894   tet_infoline("Test BLEND_PRE_MULTIPLIED_ALPHA property");
895
896   Geometry geometry = CreateQuadGeometry();
897   Shader shader = Shader::New( "vertexSrc", "fragmentSrc" );
898   Renderer renderer = Renderer::New( geometry, shader );
899
900   Actor actor = Actor::New();
901   actor.AddRenderer(renderer);
902   actor.SetSize(400, 400);
903   actor.SetColor( Vector4(1.0f, 0.0f, 1.0f, 0.5f) );
904   Stage::GetCurrent().Add(actor);
905
906   Property::Value value = renderer.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
907   bool preMultipliedAlpha;
908   DALI_TEST_CHECK( value.Get( preMultipliedAlpha ) );
909   DALI_TEST_CHECK( !preMultipliedAlpha );
910
911   int srcFactorRgb    = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
912   int destFactorRgb   = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
913   int srcFactorAlpha  = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
914   int destFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
915
916   DALI_TEST_EQUALS( (int)DEFAULT_BLEND_FACTOR_SRC_RGB,    srcFactorRgb,    TEST_LOCATION );
917   DALI_TEST_EQUALS( (int)DEFAULT_BLEND_FACTOR_DEST_RGB,   destFactorRgb,   TEST_LOCATION );
918   DALI_TEST_EQUALS( (int)DEFAULT_BLEND_FACTOR_SRC_ALPHA,  srcFactorAlpha,  TEST_LOCATION );
919   DALI_TEST_EQUALS( (int)DEFAULT_BLEND_FACTOR_DEST_ALPHA, destFactorAlpha, TEST_LOCATION );
920
921   application.SendNotification();
922   application.Render();
923
924   Vector4 actualValue(Vector4::ZERO);
925   TestGlAbstraction& gl = application.GetGlAbstraction();
926   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uColor", actualValue ) );
927   DALI_TEST_EQUALS( actualValue, Vector4(1.0f, 0.0f, 1.0f, 0.5f), TEST_LOCATION );
928
929   renderer.SetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, true);
930
931   application.SendNotification();
932   application.Render();
933
934   value = renderer.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
935   DALI_TEST_CHECK( value.Get( preMultipliedAlpha ) );
936   DALI_TEST_CHECK( preMultipliedAlpha );
937
938   srcFactorRgb    = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
939   destFactorRgb   = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
940   srcFactorAlpha  = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
941   destFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
942
943   DALI_TEST_EQUALS( (int)BlendFactor::ONE,                 srcFactorRgb,    TEST_LOCATION );
944   DALI_TEST_EQUALS( (int)BlendFactor::ONE_MINUS_SRC_ALPHA, destFactorRgb,   TEST_LOCATION );
945   DALI_TEST_EQUALS( (int)BlendFactor::ONE,                 srcFactorAlpha,  TEST_LOCATION );
946   DALI_TEST_EQUALS( (int)BlendFactor::ONE,                 destFactorAlpha, TEST_LOCATION );
947
948   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uColor", actualValue ) );
949   DALI_TEST_EQUALS( actualValue, Vector4(0.5f, 0.0f, 0.5f, 0.5f), TEST_LOCATION );
950
951   END_TEST;
952 }
953
954 int UtcDaliRendererConstraint01(void)
955 {
956   TestApplication application;
957
958   tet_infoline("Test that a non-uniform renderer property can be constrained");
959
960   Shader shader = Shader::New("VertexSource", "FragmentSource");
961   Geometry geometry = CreateQuadGeometry();
962   Renderer renderer = Renderer::New( geometry, shader );
963
964   Actor actor = Actor::New();
965   actor.AddRenderer(renderer);
966   actor.SetSize(400, 400);
967   Stage::GetCurrent().Add(actor);
968
969   Vector4 initialColor = Color::WHITE;
970   Property::Index colorIndex = renderer.RegisterProperty( "uFadeColor", initialColor );
971
972   application.SendNotification();
973   application.Render(0);
974   DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION );
975
976   // Apply constraint
977   Constraint constraint = Constraint::New<Vector4>( renderer, colorIndex, TestConstraintNoBlue );
978   constraint.Apply();
979   application.SendNotification();
980   application.Render(0);
981
982   // Expect no blue component in either buffer - yellow
983   DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(colorIndex), Color::YELLOW, TEST_LOCATION );
984   application.Render(0);
985   DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(colorIndex), Color::YELLOW, TEST_LOCATION );
986
987   renderer.RemoveConstraints();
988   renderer.SetProperty(colorIndex, Color::WHITE );
989   application.SendNotification();
990   application.Render(0);
991   DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(colorIndex), Color::WHITE, TEST_LOCATION );
992
993   END_TEST;
994 }
995
996 int UtcDaliRendererConstraint02(void)
997 {
998   TestApplication application;
999
1000   tet_infoline("Test that a uniform map renderer property can be constrained");
1001
1002   Shader shader = Shader::New("VertexSource", "FragmentSource");
1003   Geometry geometry = CreateQuadGeometry();
1004   Renderer renderer = Renderer::New( geometry, shader );
1005
1006   Actor actor = Actor::New();
1007   actor.AddRenderer(renderer);
1008   actor.SetSize(400, 400);
1009   Stage::GetCurrent().Add(actor);
1010   application.SendNotification();
1011   application.Render(0);
1012
1013   Vector4 initialColor = Color::WHITE;
1014   Property::Index colorIndex = renderer.RegisterProperty( "uFadeColor", initialColor );
1015
1016   TestGlAbstraction& gl = application.GetGlAbstraction();
1017
1018   application.SendNotification();
1019   application.Render(0);
1020
1021   Vector4 actualValue(Vector4::ZERO);
1022   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1023   DALI_TEST_EQUALS( actualValue, initialColor, TEST_LOCATION );
1024
1025   // Apply constraint
1026   Constraint constraint = Constraint::New<Vector4>( renderer, colorIndex, TestConstraintNoBlue );
1027   constraint.Apply();
1028   application.SendNotification();
1029   application.Render(0);
1030
1031    // Expect no blue component in either buffer - yellow
1032   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1033   DALI_TEST_EQUALS( actualValue, Color::YELLOW, TEST_LOCATION );
1034
1035   application.Render(0);
1036   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1037   DALI_TEST_EQUALS( actualValue, Color::YELLOW, TEST_LOCATION );
1038
1039   renderer.RemoveConstraints();
1040   renderer.SetProperty(colorIndex, Color::WHITE );
1041   application.SendNotification();
1042   application.Render(0);
1043
1044   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1045   DALI_TEST_EQUALS( actualValue, Color::WHITE, TEST_LOCATION );
1046
1047   END_TEST;
1048 }
1049
1050
1051
1052 int UtcDaliRendererAnimatedProperty01(void)
1053 {
1054   TestApplication application;
1055
1056   tet_infoline("Test that a non-uniform renderer property can be animated");
1057
1058   Shader shader = Shader::New("VertexSource", "FragmentSource");
1059   Geometry geometry = CreateQuadGeometry();
1060   Renderer renderer = Renderer::New( geometry, shader );
1061
1062   Actor actor = Actor::New();
1063   actor.AddRenderer(renderer);
1064   actor.SetSize(400, 400);
1065   Stage::GetCurrent().Add(actor);
1066
1067   Vector4 initialColor = Color::WHITE;
1068   Property::Index colorIndex = renderer.RegisterProperty( "uFadeColor", initialColor );
1069
1070   application.SendNotification();
1071   application.Render(0);
1072   DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION );
1073
1074   Animation  animation = Animation::New(1.0f);
1075   KeyFrames keyFrames = KeyFrames::New();
1076   keyFrames.Add(0.0f, initialColor);
1077   keyFrames.Add(1.0f, Color::TRANSPARENT);
1078   animation.AnimateBetween( Property( renderer, colorIndex ), keyFrames );
1079   animation.Play();
1080
1081   application.SendNotification();
1082   application.Render(500);
1083
1084   DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(colorIndex), Color::WHITE * 0.5f, TEST_LOCATION );
1085
1086   application.Render(500);
1087
1088   DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(colorIndex), Color::TRANSPARENT, TEST_LOCATION );
1089
1090   END_TEST;
1091 }
1092
1093 int UtcDaliRendererAnimatedProperty02(void)
1094 {
1095   TestApplication application;
1096
1097   tet_infoline("Test that a uniform map renderer property can be animated");
1098
1099   Shader shader = Shader::New("VertexSource", "FragmentSource");
1100   Geometry geometry = CreateQuadGeometry();
1101   Renderer renderer = Renderer::New( geometry, shader );
1102
1103   Actor actor = Actor::New();
1104   actor.AddRenderer(renderer);
1105   actor.SetSize(400, 400);
1106   Stage::GetCurrent().Add(actor);
1107   application.SendNotification();
1108   application.Render(0);
1109
1110   Vector4 initialColor = Color::WHITE;
1111   Property::Index colorIndex = renderer.RegisterProperty( "uFadeColor", initialColor );
1112
1113   TestGlAbstraction& gl = application.GetGlAbstraction();
1114
1115   application.SendNotification();
1116   application.Render(0);
1117
1118   Vector4 actualValue(Vector4::ZERO);
1119   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1120   DALI_TEST_EQUALS( actualValue, initialColor, TEST_LOCATION );
1121
1122   Animation  animation = Animation::New(1.0f);
1123   KeyFrames keyFrames = KeyFrames::New();
1124   keyFrames.Add(0.0f, initialColor);
1125   keyFrames.Add(1.0f, Color::TRANSPARENT);
1126   animation.AnimateBetween( Property( renderer, colorIndex ), keyFrames );
1127   animation.Play();
1128
1129   application.SendNotification();
1130   application.Render(500);
1131
1132   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1133   DALI_TEST_EQUALS( actualValue, Color::WHITE * 0.5f, TEST_LOCATION );
1134
1135   application.Render(500);
1136   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1137   DALI_TEST_EQUALS( actualValue, Color::TRANSPARENT, TEST_LOCATION );
1138
1139   END_TEST;
1140 }
1141
1142 int UtcDaliRendererUniformMapPrecendence01(void)
1143 {
1144   TestApplication application;
1145
1146   tet_infoline("Test the uniform map precedence is applied properly");
1147
1148   Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1149
1150   Shader shader = Shader::New("VertexSource", "FragmentSource");
1151   TextureSet textureSet = CreateTextureSet( image );
1152
1153   Geometry geometry = CreateQuadGeometry();
1154   Renderer renderer = Renderer::New( geometry, shader );
1155   renderer.SetTextures( textureSet );
1156
1157   Actor actor = Actor::New();
1158   actor.AddRenderer(renderer);
1159   actor.SetSize(400, 400);
1160   Stage::GetCurrent().Add(actor);
1161   application.SendNotification();
1162   application.Render(0);
1163
1164   renderer.RegisterProperty( "uFadeColor", Color::RED );
1165   actor.RegisterProperty( "uFadeColor", Color::GREEN );
1166   Property::Index shaderFadeColorIndex = shader.RegisterProperty( "uFadeColor", Color::MAGENTA );
1167
1168   TestGlAbstraction& gl = application.GetGlAbstraction();
1169
1170   application.SendNotification();
1171   application.Render(0);
1172
1173   // Expect that the actor's fade color property is accessed
1174   Vector4 actualValue(Vector4::ZERO);
1175   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1176   DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
1177
1178   // Animate shader's fade color property. Should be no change to uniform
1179   Animation  animation = Animation::New(1.0f);
1180   KeyFrames keyFrames = KeyFrames::New();
1181   keyFrames.Add(0.0f, Color::WHITE);
1182   keyFrames.Add(1.0f, Color::TRANSPARENT);
1183   animation.AnimateBetween( Property( shader, shaderFadeColorIndex ), keyFrames );
1184   animation.Play();
1185
1186   application.SendNotification();
1187   application.Render(500);
1188
1189   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1190   DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
1191
1192   application.Render(500);
1193   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1194   DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
1195
1196   END_TEST;
1197 }
1198
1199 int UtcDaliRendererUniformMapPrecendence02(void)
1200 {
1201   TestApplication application;
1202
1203   tet_infoline("Test the uniform map precedence is applied properly");
1204
1205   Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1206
1207   Shader shader = Shader::New("VertexSource", "FragmentSource");
1208   TextureSet textureSet = CreateTextureSet( image );
1209
1210   Geometry geometry = CreateQuadGeometry();
1211   Renderer renderer = Renderer::New( geometry, shader );
1212   renderer.SetTextures( textureSet );
1213
1214   Actor actor = Actor::New();
1215   actor.AddRenderer(renderer);
1216   actor.SetSize(400, 400);
1217   Stage::GetCurrent().Add(actor);
1218   application.SendNotification();
1219   application.Render(0);
1220
1221   // Don't add property / uniform map to renderer
1222   actor.RegisterProperty( "uFadeColor", Color::GREEN );
1223   Property::Index shaderFadeColorIndex = shader.RegisterProperty( "uFadeColor", Color::BLUE );
1224
1225   TestGlAbstraction& gl = application.GetGlAbstraction();
1226
1227   application.SendNotification();
1228   application.Render(0);
1229
1230   // Expect that the actor's fade color property is accessed
1231   Vector4 actualValue(Vector4::ZERO);
1232   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1233   DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
1234
1235   // Animate texture set's fade color property. Should be no change to uniform
1236   Animation  animation = Animation::New(1.0f);
1237   KeyFrames keyFrames = KeyFrames::New();
1238   keyFrames.Add(0.0f, Color::WHITE);
1239   keyFrames.Add(1.0f, Color::TRANSPARENT);
1240   animation.AnimateBetween( Property( shader, shaderFadeColorIndex ), keyFrames );
1241   animation.Play();
1242
1243   application.SendNotification();
1244   application.Render(500);
1245
1246   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1247   DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
1248
1249   application.Render(500);
1250   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1251   DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
1252
1253   END_TEST;
1254 }
1255
1256
1257 int UtcDaliRendererUniformMapPrecendence03(void)
1258 {
1259   TestApplication application;
1260
1261   tet_infoline("Test the uniform map precedence is applied properly");
1262
1263   Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1264
1265   Shader shader = Shader::New("VertexSource", "FragmentSource");
1266   TextureSet textureSet = CreateTextureSet( image );
1267
1268   Geometry geometry = CreateQuadGeometry();
1269   Renderer renderer = Renderer::New( geometry, shader );
1270   renderer.SetTextures( textureSet );
1271
1272   Actor actor = Actor::New();
1273   actor.AddRenderer(renderer);
1274   actor.SetSize(400, 400);
1275   Stage::GetCurrent().Add(actor);
1276   application.SendNotification();
1277   application.Render(0);
1278
1279   // Don't add property / uniform map to renderer or actor
1280   shader.RegisterProperty( "uFadeColor", Color::BLACK );
1281
1282   TestGlAbstraction& gl = application.GetGlAbstraction();
1283
1284   application.SendNotification();
1285   application.Render(0);
1286
1287   // Expect that the shader's fade color property is accessed
1288   Vector4 actualValue(Vector4::ZERO);
1289   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1290   DALI_TEST_EQUALS( actualValue, Color::BLACK, TEST_LOCATION );
1291
1292   END_TEST;
1293 }
1294
1295 int UtcDaliRendererUniformMapMultipleUniforms01(void)
1296 {
1297   TestApplication application;
1298
1299   tet_infoline("Test the uniform maps are collected from all objects (same type)");
1300
1301   Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1302
1303   Shader shader = Shader::New("VertexSource", "FragmentSource");
1304   TextureSet textureSet = CreateTextureSet( image );
1305
1306   Geometry geometry = CreateQuadGeometry();
1307   Renderer renderer = Renderer::New( geometry, shader );
1308   renderer.SetTextures( textureSet );
1309
1310   Actor actor = Actor::New();
1311   actor.AddRenderer(renderer);
1312   actor.SetSize(400, 400);
1313   Stage::GetCurrent().Add(actor);
1314   application.SendNotification();
1315   application.Render(0);
1316
1317   renderer.RegisterProperty( "uUniform1", Color::RED );
1318   actor.RegisterProperty( "uUniform2", Color::GREEN );
1319   shader.RegisterProperty( "uUniform3", Color::MAGENTA );
1320
1321   TestGlAbstraction& gl = application.GetGlAbstraction();
1322
1323   application.SendNotification();
1324   application.Render(0);
1325
1326   // Expect that each of the object's uniforms are set
1327   Vector4 uniform1Value(Vector4::ZERO);
1328   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uUniform1", uniform1Value ) );
1329   DALI_TEST_EQUALS( uniform1Value, Color::RED, TEST_LOCATION );
1330
1331   Vector4 uniform2Value(Vector4::ZERO);
1332   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uUniform2", uniform2Value ) );
1333   DALI_TEST_EQUALS( uniform2Value, Color::GREEN, TEST_LOCATION );
1334
1335   Vector4 uniform3Value(Vector4::ZERO);
1336   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uUniform3", uniform3Value ) );
1337   DALI_TEST_EQUALS( uniform3Value, Color::MAGENTA, TEST_LOCATION );
1338
1339   END_TEST;
1340 }
1341
1342 int UtcDaliRendererUniformMapMultipleUniforms02(void)
1343 {
1344   TestApplication application;
1345
1346   tet_infoline("Test the uniform maps are collected from all objects (different types)");
1347
1348   Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1349
1350   Shader shader = Shader::New("VertexSource", "FragmentSource");
1351   TextureSet textureSet = CreateTextureSet( image );
1352
1353   Geometry geometry = CreateQuadGeometry();
1354   Renderer renderer = Renderer::New( geometry, shader );
1355   renderer.SetTextures( textureSet );
1356
1357   Actor actor = Actor::New();
1358   actor.AddRenderer(renderer);
1359   actor.SetSize(400, 400);
1360   Stage::GetCurrent().Add(actor);
1361   application.SendNotification();
1362   application.Render(0);
1363
1364   Property::Value value1(Color::RED);
1365   renderer.RegisterProperty( "uFadeColor", value1 );
1366
1367   Property::Value value2(1.0f);
1368   actor.RegisterProperty( "uFadeProgress", value2 );
1369
1370   Property::Value value3(Matrix3::IDENTITY);
1371   shader.RegisterProperty( "uANormalMatrix", value3 );
1372
1373   TestGlAbstraction& gl = application.GetGlAbstraction();
1374
1375   application.SendNotification();
1376   application.Render(0);
1377
1378   // Expect that each of the object's uniforms are set
1379   Vector4 uniform1Value(Vector4::ZERO);
1380   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", uniform1Value ) );
1381   DALI_TEST_EQUALS( uniform1Value, value1.Get<Vector4>(), TEST_LOCATION );
1382
1383   float uniform2Value(0.0f);
1384   DALI_TEST_CHECK( gl.GetUniformValue<float>( "uFadeProgress", uniform2Value ) );
1385   DALI_TEST_EQUALS( uniform2Value, value2.Get<float>(), TEST_LOCATION );
1386
1387   Matrix3 uniform3Value;
1388   DALI_TEST_CHECK( gl.GetUniformValue<Matrix3>( "uANormalMatrix", uniform3Value ) );
1389   DALI_TEST_EQUALS( uniform3Value, value3.Get<Matrix3>(), TEST_LOCATION );
1390
1391   END_TEST;
1392 }
1393
1394
1395 int UtcDaliRendererRenderOrder2DLayer(void)
1396 {
1397   TestApplication application;
1398   tet_infoline("Test the rendering order in a 2D layer is correct");
1399
1400   Shader shader = Shader::New("VertexSource", "FragmentSource");
1401   Geometry geometry = CreateQuadGeometry();
1402
1403   Actor actor0 = Actor::New();
1404   actor0.SetAnchorPoint(AnchorPoint::CENTER);
1405   actor0.SetParentOrigin(AnchorPoint::CENTER);
1406   actor0.SetPosition(0.0f,0.0f);
1407   Image image0 = BufferImage::New( 64, 64, Pixel::RGB888 );
1408   TextureSet textureSet0 = CreateTextureSet( image0 );
1409   Renderer renderer0 = Renderer::New( geometry, shader );
1410   renderer0.SetTextures( textureSet0 );
1411   actor0.AddRenderer(renderer0);
1412   actor0.SetSize(1, 1);
1413   Stage::GetCurrent().Add(actor0);
1414   application.SendNotification();
1415   application.Render(0);
1416
1417   Actor actor1 = Actor::New();
1418   actor1.SetAnchorPoint(AnchorPoint::CENTER);
1419   actor1.SetParentOrigin(AnchorPoint::CENTER);
1420   actor1.SetPosition(0.0f,0.0f);
1421   Image image1= BufferImage::New( 64, 64, Pixel::RGB888 );
1422   TextureSet textureSet1 = CreateTextureSet( image1 );
1423   Renderer renderer1 = Renderer::New( geometry, shader );
1424   renderer1.SetTextures( textureSet1 );
1425   actor1.AddRenderer(renderer1);
1426   actor1.SetSize(1, 1);
1427   Stage::GetCurrent().Add(actor1);
1428   application.SendNotification();
1429   application.Render(0);
1430
1431   Actor actor2 = Actor::New();
1432   actor2.SetAnchorPoint(AnchorPoint::CENTER);
1433   actor2.SetParentOrigin(AnchorPoint::CENTER);
1434   actor2.SetPosition(0.0f,0.0f);
1435   Image image2= BufferImage::New( 64, 64, Pixel::RGB888 );
1436   TextureSet textureSet2 = CreateTextureSet( image2 );
1437   Renderer renderer2 = Renderer::New( geometry, shader );
1438   renderer2.SetTextures( textureSet2 );
1439   actor2.AddRenderer(renderer2);
1440   actor2.SetSize(1, 1);
1441   Stage::GetCurrent().Add(actor2);
1442   application.SendNotification();
1443   application.Render(0);
1444
1445   Actor actor3 = Actor::New();
1446   actor3.SetAnchorPoint(AnchorPoint::CENTER);
1447   actor3.SetParentOrigin(AnchorPoint::CENTER);
1448   actor3.SetPosition(0.0f,0.0f);
1449   Image image3 = BufferImage::New( 64, 64, Pixel::RGB888 );
1450   TextureSet textureSet3 = CreateTextureSet( image3 );
1451   Renderer renderer3 = Renderer::New( geometry, shader );
1452   renderer3.SetTextures( textureSet3 );
1453   actor3.AddRenderer(renderer3);
1454   actor3.SetSize(1, 1);
1455   Stage::GetCurrent().Add(actor3);
1456   application.SendNotification();
1457   application.Render(0);
1458
1459   /*
1460    * Create the following hierarchy:
1461    *
1462    *            actor2
1463    *              /
1464    *             /
1465    *          actor1
1466    *           /
1467    *          /
1468    *       actor0
1469    *        /
1470    *       /
1471    *    actor3
1472    *
1473    *  Expected rendering order : actor2 - actor1 - actor0 - actor3
1474    */
1475   actor2.Add(actor1);
1476   actor1.Add(actor0);
1477   actor0.Add(actor3);
1478   application.SendNotification();
1479   application.Render(0);
1480
1481   TestGlAbstraction& gl = application.GetGlAbstraction();
1482   gl.EnableTextureCallTrace(true);
1483   application.SendNotification();
1484   application.Render(0);
1485
1486   int textureBindIndex[4];
1487   for( unsigned int i(0); i<4; ++i )
1488   {
1489     std::stringstream params;
1490     params << GL_TEXTURE_2D<<", "<<i+1;
1491     textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str() );
1492   }
1493
1494   //Check that actor1 has been rendered after actor2
1495   DALI_TEST_GREATER( textureBindIndex[1], textureBindIndex[2], TEST_LOCATION );
1496
1497   //Check that actor0 has been rendered after actor1
1498   DALI_TEST_GREATER( textureBindIndex[0], textureBindIndex[1], TEST_LOCATION );
1499
1500   //Check that actor3 has been rendered after actor0
1501   DALI_TEST_GREATER( textureBindIndex[3], textureBindIndex[0], TEST_LOCATION );
1502
1503   END_TEST;
1504 }
1505
1506 int UtcDaliRendererRenderOrder2DLayerMultipleRenderers(void)
1507 {
1508   TestApplication application;
1509   tet_infoline("Test the rendering order in a 2D layer is correct using multiple renderers per actor");
1510
1511   /*
1512    * Creates the following hierarchy:
1513    *
1514    *             actor0------------------------>actor1
1515    *            /   |   \                    /   |   \
1516    *          /     |     \                /     |     \
1517    *        /       |       \            /       |       \
1518    * renderer0 renderer1 renderer2 renderer3 renderer4 renderer5
1519    *
1520    *  renderer0 has depth index 2
1521    *  renderer1 has depth index 0
1522    *  renderer2 has depth index 1
1523    *
1524    *  renderer3 has depth index 1
1525    *  renderer4 has depth index 0
1526    *  renderer5 has depth index -1
1527    *
1528    *  Expected rendering order: renderer1 - renderer2 - renderer0 - renderer5 - renderer4 - renderer3
1529    */
1530
1531   Shader shader = Shader::New("VertexSource", "FragmentSource");
1532   Geometry geometry = CreateQuadGeometry();
1533
1534   Actor actor0 = Actor::New();
1535   actor0.SetAnchorPoint(AnchorPoint::CENTER);
1536   actor0.SetParentOrigin(AnchorPoint::CENTER);
1537   actor0.SetPosition(0.0f,0.0f);
1538   actor0.SetSize(1, 1);
1539   Stage::GetCurrent().Add(actor0);
1540
1541   Actor actor1 = Actor::New();
1542   actor1.SetAnchorPoint(AnchorPoint::CENTER);
1543   actor1.SetParentOrigin(AnchorPoint::CENTER);
1544   actor1.SetPosition(0.0f,0.0f);
1545   actor1.SetSize(1, 1);
1546   actor0.Add(actor1);
1547
1548   //Renderer0
1549   Image image0 = BufferImage::New( 64, 64, Pixel::RGB888 );
1550   TextureSet textureSet0 = CreateTextureSet( image0 );
1551   Renderer renderer0 = Renderer::New( geometry, shader );
1552   renderer0.SetTextures( textureSet0 );
1553   renderer0.SetProperty( Renderer::Property::DEPTH_INDEX, 2 );
1554   actor0.AddRenderer(renderer0);
1555   application.SendNotification();
1556   application.Render(0);
1557
1558   //Renderer1
1559   Image image1= BufferImage::New( 64, 64, Pixel::RGB888 );
1560   TextureSet textureSet1 = CreateTextureSet( image1 );
1561   Renderer renderer1 = Renderer::New( geometry, shader );
1562   renderer1.SetTextures( textureSet1 );
1563   renderer1.SetProperty( Renderer::Property::DEPTH_INDEX, 0 );
1564   actor0.AddRenderer(renderer1);
1565   application.SendNotification();
1566   application.Render(0);
1567
1568   //Renderer2
1569   Image image2= BufferImage::New( 64, 64, Pixel::RGB888 );
1570   TextureSet textureSet2 = CreateTextureSet( image2 );
1571   Renderer renderer2 = Renderer::New( geometry, shader );
1572   renderer2.SetTextures( textureSet2 );
1573   renderer2.SetProperty( Renderer::Property::DEPTH_INDEX, 1 );
1574   actor0.AddRenderer(renderer2);
1575   application.SendNotification();
1576   application.Render(0);
1577
1578   //Renderer3
1579   Image image3 = BufferImage::New( 64, 64, Pixel::RGB888 );
1580   TextureSet textureSet3 = CreateTextureSet( image3 );
1581   Renderer renderer3 = Renderer::New( geometry, shader );
1582   renderer3.SetTextures( textureSet3 );
1583   renderer3.SetProperty( Renderer::Property::DEPTH_INDEX, 1 );
1584   actor1.AddRenderer(renderer3);
1585   application.SendNotification();
1586   application.Render(0);
1587
1588   //Renderer4
1589   Image image4= BufferImage::New( 64, 64, Pixel::RGB888 );
1590   TextureSet textureSet4 = CreateTextureSet( image4 );
1591   Renderer renderer4 = Renderer::New( geometry, shader );
1592   renderer4.SetTextures( textureSet4 );
1593   renderer4.SetProperty( Renderer::Property::DEPTH_INDEX, 0 );
1594   actor1.AddRenderer(renderer4);
1595   application.SendNotification();
1596   application.Render(0);
1597
1598   //Renderer5
1599   Image image5= BufferImage::New( 64, 64, Pixel::RGB888 );
1600   TextureSet textureSet5 = CreateTextureSet( image5 );
1601   Renderer renderer5 = Renderer::New( geometry, shader );
1602   renderer5.SetTextures( textureSet5 );
1603   renderer5.SetProperty( Renderer::Property::DEPTH_INDEX, -1 );
1604   actor1.AddRenderer(renderer5);
1605   application.SendNotification();
1606   application.Render(0);
1607
1608
1609   TestGlAbstraction& gl = application.GetGlAbstraction();
1610   gl.EnableTextureCallTrace(true);
1611   application.SendNotification();
1612   application.Render(0);
1613
1614   int textureBindIndex[6];
1615   for( unsigned int i(0); i<6; ++i )
1616   {
1617     std::stringstream params;
1618     params << GL_TEXTURE_2D<<", "<<i+1;
1619     textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str() );
1620   }
1621
1622   //Check that renderer3 has been rendered after renderer4
1623   DALI_TEST_GREATER( textureBindIndex[3], textureBindIndex[4], TEST_LOCATION );
1624
1625   //Check that renderer0 has been rendered after renderer2
1626   DALI_TEST_GREATER( textureBindIndex[4], textureBindIndex[5], TEST_LOCATION );
1627
1628   //Check that renderer0 has been rendered after renderer2
1629   DALI_TEST_GREATER( textureBindIndex[5], textureBindIndex[0], TEST_LOCATION );
1630
1631   //Check that renderer0 has been rendered after renderer2
1632   DALI_TEST_GREATER( textureBindIndex[0], textureBindIndex[2], TEST_LOCATION );
1633
1634   //Check that renderer2 has been rendered after renderer1
1635   DALI_TEST_GREATER( textureBindIndex[2], textureBindIndex[1], TEST_LOCATION );
1636
1637   END_TEST;
1638 }
1639
1640 int UtcDaliRendererRenderOrder2DLayerOverlay(void)
1641 {
1642   TestApplication application;
1643   tet_infoline("Test the rendering order in a 2D layer is correct for overlays");
1644
1645   Shader shader = Shader::New("VertexSource", "FragmentSource");
1646   Geometry geometry = CreateQuadGeometry();
1647
1648   Actor actor0 = Actor::New();
1649   actor0.SetAnchorPoint(AnchorPoint::CENTER);
1650   actor0.SetParentOrigin(AnchorPoint::CENTER);
1651   Image image0 = BufferImage::New( 64, 64, Pixel::RGB888 );
1652   TextureSet textureSet0 = CreateTextureSet( image0 );
1653   Renderer renderer0 = Renderer::New( geometry, shader );
1654   renderer0.SetTextures( textureSet0 );
1655   actor0.AddRenderer(renderer0);
1656   actor0.SetPosition(0.0f,0.0f);
1657   actor0.SetSize(100, 100);
1658   Stage::GetCurrent().Add(actor0);
1659   actor0.SetDrawMode( DrawMode::OVERLAY_2D );
1660   application.SendNotification();
1661   application.Render(0);
1662
1663   Actor actor1 = Actor::New();
1664   actor1.SetAnchorPoint(AnchorPoint::CENTER);
1665   actor1.SetParentOrigin(AnchorPoint::CENTER);
1666   Image image1= BufferImage::New( 64, 64, Pixel::RGB888 );
1667   TextureSet textureSet1 = CreateTextureSet( image1 );
1668   Renderer renderer1 = Renderer::New( geometry, shader );
1669   renderer1.SetTextures( textureSet1 );
1670   actor1.SetPosition(0.0f,0.0f);
1671   actor1.AddRenderer(renderer1);
1672   actor1.SetSize(100, 100);
1673   Stage::GetCurrent().Add(actor1);
1674   actor1.SetDrawMode( DrawMode::OVERLAY_2D );
1675   application.SendNotification();
1676   application.Render(0);
1677
1678   Actor actor2 = Actor::New();
1679   actor2.SetAnchorPoint(AnchorPoint::CENTER);
1680   actor2.SetParentOrigin(AnchorPoint::CENTER);
1681   Image image2= BufferImage::New( 64, 64, Pixel::RGB888 );
1682   TextureSet textureSet2 = CreateTextureSet( image2 );
1683   Renderer renderer2 = Renderer::New( geometry, shader );
1684   renderer2.SetTextures( textureSet2 );
1685   actor2.AddRenderer(renderer2);
1686   actor2.SetPosition(0.0f,0.0f);
1687   actor2.SetSize(100, 100);
1688   Stage::GetCurrent().Add(actor2);
1689   application.SendNotification();
1690   application.Render(0);
1691
1692   Actor actor3 = Actor::New();
1693   actor3.SetAnchorPoint(AnchorPoint::CENTER);
1694   actor3.SetParentOrigin(AnchorPoint::CENTER);
1695   Image image3 = BufferImage::New( 64, 64, Pixel::RGB888 );
1696   TextureSet textureSet3 = CreateTextureSet( image3 );
1697   Renderer renderer3 = Renderer::New( geometry, shader );
1698   renderer3.SetTextures( textureSet3 );
1699   actor3.SetPosition(0.0f,0.0f);
1700   actor3.AddRenderer(renderer3);
1701   actor3.SetSize(100, 100);
1702   Stage::GetCurrent().Add(actor3);
1703   actor3.SetDrawMode( DrawMode::OVERLAY_2D );
1704   application.SendNotification();
1705   application.Render(0);
1706
1707   Actor actor4 = Actor::New();
1708   actor4.SetAnchorPoint(AnchorPoint::CENTER);
1709   actor4.SetParentOrigin(AnchorPoint::CENTER);
1710   Image image4 = BufferImage::New( 64, 64, Pixel::RGB888 );
1711   TextureSet textureSet4 = CreateTextureSet( image4 );
1712   Renderer renderer4 = Renderer::New( geometry, shader );
1713   renderer4.SetTextures( textureSet4 );
1714   actor4.AddRenderer(renderer4);
1715   actor4.SetPosition(0.0f,0.0f);
1716   actor4.SetSize(100, 100);
1717   Stage::GetCurrent().Add(actor4);
1718   application.SendNotification();
1719   application.Render(0);
1720
1721   /*
1722    * Create the following hierarchy:
1723    *
1724    *               actor2
1725    *             (Regular actor)
1726    *              /      \
1727    *             /        \
1728    *         actor1       actor4
1729    *       (Overlay)     (Regular actor)
1730    *          /
1731    *         /
1732    *     actor0
1733    *    (Overlay)
1734    *      /
1735    *     /
1736    *  actor3
1737    * (Overlay)
1738    *
1739    *  Expected rendering order : actor2 - actor4 - actor1 - actor0 - actor3
1740    */
1741   Stage::GetCurrent().Add( actor2 );
1742   actor2.Add(actor1);
1743   actor2.Add(actor4);
1744   actor1.Add(actor0);
1745   actor0.Add(actor3);
1746   application.SendNotification();
1747   application.Render(0);
1748
1749   TestGlAbstraction& gl = application.GetGlAbstraction();
1750   gl.EnableTextureCallTrace(true);
1751   application.SendNotification();
1752   application.Render(0);
1753
1754   int textureBindIndex[5];
1755   for( unsigned int i(0); i<5; ++i )
1756   {
1757     std::stringstream params;
1758     params << GL_TEXTURE_2D<<", "<<i+1;
1759     textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str() );
1760   }
1761
1762   //Check that actor4 has been rendered after actor2
1763   DALI_TEST_GREATER( textureBindIndex[4], textureBindIndex[2], TEST_LOCATION );
1764
1765   //Check that actor1 has been rendered after actor4
1766   DALI_TEST_GREATER( textureBindIndex[1], textureBindIndex[4], TEST_LOCATION );
1767
1768   //Check that actor0 has been rendered after actor1
1769   DALI_TEST_GREATER( textureBindIndex[0], textureBindIndex[1], TEST_LOCATION );
1770
1771   //Check that actor3 has been rendered after actor0
1772   DALI_TEST_GREATER( textureBindIndex[3], textureBindIndex[0], TEST_LOCATION );
1773
1774   END_TEST;
1775 }
1776
1777 int UtcDaliRendererSetIndexRange(void)
1778 {
1779   std::string
1780       vertexShader(
1781         "attribute vec2 aPosition;\n"
1782         "void main()\n"
1783         "{\n"
1784         "  gl_Position = aPosition;\n"
1785         "}"
1786         ),
1787       fragmentShader(
1788         "void main()\n"
1789         "{\n"
1790         "  gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0)\n"
1791         "}\n"
1792         );
1793
1794   TestApplication application;
1795   tet_infoline("Test setting the range of indices to draw");
1796
1797   TestGlAbstraction& gl = application.GetGlAbstraction();
1798   gl.EnableDrawCallTrace( true );
1799
1800   Actor actor = Actor::New();
1801   actor.SetSize( 100, 100 );
1802
1803   // create geometry
1804   Geometry geometry = Geometry::New();
1805   geometry.SetGeometryType( Geometry::LINE_LOOP );
1806
1807   // --------------------------------------------------------------------------
1808   // index buffer
1809   unsigned short indices[] = { 0, 2, 4, 6, 8, // offset = 0, count = 5
1810                          0, 1, 2, 3, 4, 5, 6, 7, 8, 9, // offset = 5, count = 10
1811                          1, 3, 5, 7, 9, 1 }; // offset = 15,  count = 6 // line strip
1812
1813   // --------------------------------------------------------------------------
1814   // vertex buffer
1815   struct Vertex
1816   {
1817     Vector2 position;
1818   };
1819   Vertex shapes[] =
1820   {
1821     // pentagon                   // star
1822     { Vector2(  0.0f,   1.00f) }, { Vector2(  0.0f,  -1.00f) },
1823     { Vector2( -0.95f,  0.31f) }, { Vector2(  0.59f,  0.81f) },
1824     { Vector2( -0.59f, -0.81f) }, { Vector2( -0.95f, -0.31f) },
1825     { Vector2(  0.59f, -0.81f) }, { Vector2(  0.95f, -0.31f) },
1826     { Vector2(  0.95f,  0.31f) }, { Vector2( -0.59f,  0.81f) },
1827   };
1828   Property::Map vertexFormat;
1829   vertexFormat["aPosition"] = Property::VECTOR2;
1830   PropertyBuffer vertexBuffer = PropertyBuffer::New( vertexFormat );
1831   vertexBuffer.SetData( shapes, sizeof(shapes)/sizeof(shapes[0]));
1832
1833   // --------------------------------------------------------------------------
1834   geometry.SetIndexBuffer( indices, sizeof(indices)/sizeof(indices[0]) );
1835   geometry.AddVertexBuffer( vertexBuffer );
1836
1837   // create shader
1838   Shader shader = Shader::New( vertexShader,fragmentShader );
1839   Renderer renderer = Renderer::New( geometry, shader );
1840   actor.AddRenderer( renderer );
1841
1842   Stage stage = Stage::GetCurrent();
1843   stage.Add( actor );
1844
1845   char buffer[ 128 ];
1846
1847   // LINE_LOOP, first 0, count 5
1848   {
1849     renderer.SetIndexRange( 0, 5 );
1850     application.SendNotification();
1851     application.Render();
1852     sprintf( buffer, "%u, 5, %u, indices", GL_LINE_LOOP, GL_UNSIGNED_SHORT );
1853     bool result = gl.GetDrawTrace().FindMethodAndParams( "DrawElements" , buffer );
1854     DALI_TEST_CHECK( result );
1855   }
1856
1857   // LINE_LOOP, first 5, count 10
1858   {
1859     renderer.SetIndexRange( 5, 10 );
1860     sprintf( buffer, "%u, 10, %u, indices", GL_LINE_LOOP, GL_UNSIGNED_SHORT );
1861     application.SendNotification();
1862     application.Render();
1863     bool result = gl.GetDrawTrace().FindMethodAndParams( "DrawElements" , buffer );
1864     DALI_TEST_CHECK( result );
1865   }
1866
1867   // LINE_STRIP, first 15, count 6
1868   {
1869     renderer.SetIndexRange( 15, 6 );
1870     geometry.SetGeometryType( Geometry::LINE_STRIP );
1871     sprintf( buffer, "%u, 6, %u, indices", GL_LINE_STRIP, GL_UNSIGNED_SHORT );
1872     application.SendNotification();
1873     application.Render();
1874     bool result = gl.GetDrawTrace().FindMethodAndParams( "DrawElements" , buffer );
1875     DALI_TEST_CHECK( result );
1876   }
1877
1878   // Index out of bounds
1879   {
1880     renderer.SetIndexRange( 15, 30 );
1881     geometry.SetGeometryType( Geometry::LINE_STRIP );
1882     sprintf( buffer, "%u, 6, %u, indices", GL_LINE_STRIP, GL_UNSIGNED_SHORT );
1883     application.SendNotification();
1884     application.Render();
1885     bool result = gl.GetDrawTrace().FindMethodAndParams( "DrawElements" , buffer );
1886     DALI_TEST_CHECK( result );
1887   }
1888
1889   // drawing whole buffer starting from 15 ( last valid primitive )
1890   {
1891     renderer.SetIndexRange( 15, 0 );
1892     geometry.SetGeometryType( Geometry::LINE_STRIP );
1893     sprintf( buffer, "%u, 6, %u, indices", GL_LINE_STRIP, GL_UNSIGNED_SHORT );
1894     application.SendNotification();
1895     application.Render();
1896     bool result = gl.GetDrawTrace().FindMethodAndParams( "DrawElements" , buffer );
1897     DALI_TEST_CHECK( result );
1898   }
1899
1900   END_TEST;
1901 }
1902
1903
1904 int UtcDaliRendererSetDepthFunction(void)
1905 {
1906   TestApplication application;
1907
1908   tet_infoline("Test setting the depth function");
1909
1910   Geometry geometry = CreateQuadGeometry();
1911   Shader shader = CreateShader();
1912   Renderer renderer = Renderer::New( geometry, shader );
1913
1914   Actor actor = Actor::New();
1915   actor.AddRenderer(renderer);
1916   actor.SetSize(400, 400);
1917   Stage stage = Stage::GetCurrent();
1918   stage.GetRootLayer().SetBehavior( Layer::LAYER_3D );
1919   stage.Add(actor);
1920
1921   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1922   glAbstraction.EnableEnableDisableCallTrace(true);
1923   glAbstraction.EnableDepthFunctionCallTrace(true);
1924
1925   TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
1926   TraceCallStack& glDepthFunctionStack = glAbstraction.GetDepthFunctionTrace();
1927
1928   std::ostringstream depthTestStr;
1929   depthTestStr << GL_DEPTH_TEST;
1930
1931   //GL_NEVER
1932   {
1933     renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::NEVER);
1934
1935     glEnableDisableStack.Reset();
1936     glDepthFunctionStack.Reset();
1937     application.SendNotification();
1938     application.Render();
1939
1940     DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Enable", depthTestStr.str().c_str() ) );
1941     std::ostringstream depthFunctionStr;
1942     depthFunctionStr << GL_NEVER;
1943     DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
1944   }
1945
1946   //GL_ALWAYS
1947   {
1948     renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::ALWAYS);
1949
1950     glDepthFunctionStack.Reset();
1951     application.SendNotification();
1952     application.Render();
1953
1954     std::ostringstream depthFunctionStr;
1955     depthFunctionStr << GL_ALWAYS;
1956     DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
1957   }
1958
1959   //GL_LESS
1960   {
1961     renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::LESS);
1962
1963     glDepthFunctionStack.Reset();
1964     application.SendNotification();
1965     application.Render();
1966
1967     std::ostringstream depthFunctionStr;
1968     depthFunctionStr << GL_LESS;
1969     DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
1970   }
1971
1972   //GL_GREATER
1973   {
1974     renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::GREATER);
1975
1976     glDepthFunctionStack.Reset();
1977     application.SendNotification();
1978     application.Render();
1979
1980     std::ostringstream depthFunctionStr;
1981     depthFunctionStr << GL_GREATER;
1982     DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
1983   }
1984
1985   //GL_EQUAL
1986   {
1987     renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::EQUAL);
1988
1989     glDepthFunctionStack.Reset();
1990     application.SendNotification();
1991     application.Render();
1992
1993     std::ostringstream depthFunctionStr;
1994     depthFunctionStr << GL_EQUAL;
1995     DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
1996   }
1997
1998   //GL_NOTEQUAL
1999   {
2000     renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::NOT_EQUAL);
2001
2002     glDepthFunctionStack.Reset();
2003     application.SendNotification();
2004     application.Render();
2005
2006     std::ostringstream depthFunctionStr;
2007     depthFunctionStr << GL_NOTEQUAL;
2008     DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
2009   }
2010
2011   //GL_LEQUAL
2012   {
2013     renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::LESS_EQUAL);
2014
2015     glDepthFunctionStack.Reset();
2016     application.SendNotification();
2017     application.Render();
2018
2019     std::ostringstream depthFunctionStr;
2020     depthFunctionStr << GL_LEQUAL;
2021     DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
2022   }
2023
2024   //GL_GEQUAL
2025   {
2026     renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::GREATER_EQUAL);
2027
2028     glDepthFunctionStack.Reset();
2029     application.SendNotification();
2030     application.Render();
2031
2032     std::ostringstream depthFunctionStr;
2033     depthFunctionStr << GL_GEQUAL;
2034     DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
2035   }
2036
2037   END_TEST;
2038 }
2039
2040 Renderer StencilTestFixture( TestApplication& application )
2041 {
2042   Geometry geometry = CreateQuadGeometry();
2043   Shader shader = CreateShader();
2044   Renderer renderer = Renderer::New( geometry, shader );
2045
2046   Actor actor = Actor::New();
2047   actor.AddRenderer( renderer );
2048   actor.SetSize( 400.0f, 400.0f );
2049   Stage stage = Stage::GetCurrent();
2050   stage.GetRootLayer().SetBehavior( Layer::LAYER_3D );
2051   stage.Add( actor );
2052
2053   return renderer;
2054 }
2055
2056 int UtcDaliRendererCheckStencilDefaults(void)
2057 {
2058   TestApplication application;
2059   tet_infoline("Test the stencil defaults");
2060
2061   Renderer renderer = StencilTestFixture( application );
2062   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2063   glAbstraction.EnableEnableDisableCallTrace( true );
2064   glAbstraction.EnableStencilFunctionCallTrace( true );
2065   TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2066   TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2067
2068   ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2069
2070   // Check the defaults:
2071   DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_FUNCTION ).Get<int>() ), static_cast<int>( StencilFunction::ALWAYS ), TEST_LOCATION );
2072   DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_FUNCTION_MASK ).Get<int>() ), 0xFF, TEST_LOCATION );
2073   DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_FUNCTION_REFERENCE ).Get<int>() ), 0x00, TEST_LOCATION );
2074   DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_MASK ).Get<int>() ), 0xFF, TEST_LOCATION );
2075   DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_OPERATION_ON_FAIL ).Get<int>() ), static_cast<int>( StencilOperation::KEEP ), TEST_LOCATION );
2076   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 );
2077   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 );
2078
2079   END_TEST;
2080 }
2081
2082 int UtcDaliRendererSetStencilMode(void)
2083 {
2084   TestApplication application;
2085   tet_infoline("Test setting the StencilMode");
2086
2087   Renderer renderer = StencilTestFixture( application );
2088   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2089   glAbstraction.EnableEnableDisableCallTrace( true );
2090   glAbstraction.EnableStencilFunctionCallTrace( true );
2091   TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2092   TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2093
2094   ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2095
2096   // Set the StencilFunction to something other than the default, to confirm it is set as a property,
2097   // but NO GL call has been made while the StencilMode is set to OFF.
2098   renderer.SetProperty( Renderer::Property::STENCIL_FUNCTION, StencilFunction::NEVER );
2099   DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_FUNCTION ).Get<int>() ), static_cast<int>( StencilFunction::NEVER ), TEST_LOCATION );
2100   ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2101
2102   std::string methodString( "StencilFunc" );
2103   DALI_TEST_CHECK( !glStencilFunctionStack.FindMethod( methodString ) );
2104
2105   // Now set the StencilMode to ON and check the StencilFunction has changed.
2106   renderer.SetProperty( Renderer::Property::STENCIL_MODE, StencilMode::ON );
2107   ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2108
2109   DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Enable", GetStencilTestString() ) );
2110   DALI_TEST_CHECK( glStencilFunctionStack.FindMethod( methodString ) );
2111
2112   END_TEST;
2113 }
2114
2115 int UtcDaliRendererSetStencilFunction(void)
2116 {
2117   TestApplication application;
2118   tet_infoline("Test setting the StencilFunction");
2119
2120   Renderer renderer = StencilTestFixture( application );
2121   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2122   glAbstraction.EnableEnableDisableCallTrace( true );
2123   glAbstraction.EnableStencilFunctionCallTrace( true );
2124   TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2125   TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2126
2127   // StencilMode must be ON for StencilFunction to operate.
2128   renderer.SetProperty( Renderer::Property::STENCIL_MODE, StencilMode::ON );
2129   ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2130
2131   /*
2132    * Lookup table for testing StencilFunction.
2133    * Note: This MUST be in the same order as the Dali::StencilFunction enum.
2134    */
2135   const int StencilFunctionLookupTable[] = {
2136       GL_NEVER,
2137       GL_LESS,
2138       GL_EQUAL,
2139       GL_LEQUAL,
2140       GL_GREATER,
2141       GL_NOTEQUAL,
2142       GL_GEQUAL,
2143       GL_ALWAYS
2144   }; const int StencilFunctionLookupTableCount = sizeof( StencilFunctionLookupTable ) / sizeof( StencilFunctionLookupTable[0] );
2145
2146   /*
2147    * Loop through all types of StencilFunction, checking:
2148    *  - The value is cached (set in event thread side)
2149    *  - Causes "glStencilFunc" to be called
2150    *  - Checks the correct parameters to "glStencilFunc" were used
2151    */
2152   std::string nonChangingParameters = "0, 255";
2153   std::string methodString( "StencilFunc" );
2154   for( int i = 0; i < StencilFunctionLookupTableCount; ++i )
2155   {
2156     // Set the property.
2157     renderer.SetProperty( Renderer::Property::STENCIL_FUNCTION, static_cast<Dali::StencilFunction::Type>( i ) );
2158
2159     // Check GetProperty returns the same value.
2160     DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_FUNCTION ).Get<int>() ), i, TEST_LOCATION );
2161
2162     // Reset the trace debug.
2163     ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2164
2165     // Check the function is called and the parameters are correct.
2166     std::stringstream parameterStream;
2167     parameterStream << StencilFunctionLookupTable[ i ] << ", " << nonChangingParameters;
2168
2169     DALI_TEST_CHECK( glStencilFunctionStack.FindMethodAndParams( methodString, parameterStream.str() ) );
2170   }
2171
2172   // Change the Function Reference only and check the behavior is correct:
2173   // 170 is 0xaa in hex / 10101010 in binary (every other bit set).
2174   int testValueReference = 170;
2175   renderer.SetProperty( Renderer::Property::STENCIL_FUNCTION_REFERENCE, testValueReference );
2176
2177   DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_FUNCTION_REFERENCE ).Get<int>() ), testValueReference, TEST_LOCATION );
2178
2179   ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2180
2181   std::stringstream parameterStream;
2182   parameterStream << StencilFunctionLookupTable[ StencilOperation::DECREMENT_WRAP ] << ", " << testValueReference << ", 255";
2183
2184   DALI_TEST_CHECK( glStencilFunctionStack.FindMethodAndParams( methodString, parameterStream.str() ) );
2185
2186
2187   // Change the Function Mask only and check the behavior is correct:
2188   // 85 is 0x55 in hex / 01010101 in binary (every other bit set).
2189   int testValueMask = 85;
2190   renderer.SetProperty( Renderer::Property::STENCIL_FUNCTION_MASK, testValueMask );
2191
2192   DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_FUNCTION_MASK ).Get<int>() ), testValueMask, TEST_LOCATION );
2193
2194   ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2195
2196   // Clear the stringstream.
2197   parameterStream.str( std::string() );
2198   parameterStream << StencilFunctionLookupTable[ StencilOperation::DECREMENT_WRAP ] << ", " << testValueReference << ", " << testValueMask;
2199
2200   DALI_TEST_CHECK( glStencilFunctionStack.FindMethodAndParams( methodString, parameterStream.str() ) );
2201
2202   END_TEST;
2203 }
2204
2205 int UtcDaliRendererSetStencilOperation(void)
2206 {
2207   TestApplication application;
2208   tet_infoline("Test setting the StencilOperation");
2209
2210   Renderer renderer = StencilTestFixture( application );
2211   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2212   glAbstraction.EnableEnableDisableCallTrace( true );
2213   glAbstraction.EnableStencilFunctionCallTrace( true );
2214   TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2215   TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2216
2217   // StencilMode must be ON for StencilOperation to operate.
2218   renderer.SetProperty( Renderer::Property::STENCIL_MODE, StencilMode::ON );
2219
2220   /*
2221    * Lookup table for testing StencilOperation.
2222    * Note: This MUST be in the same order as the Dali::StencilOperation enum.
2223    */
2224   const int StencilOperationLookupTable[] = {
2225     GL_ZERO,
2226     GL_KEEP,
2227     GL_REPLACE,
2228     GL_INCR,
2229     GL_DECR,
2230     GL_INVERT,
2231     GL_INCR_WRAP,
2232     GL_DECR_WRAP
2233   }; const int StencilOperationLookupTableCount = sizeof( StencilOperationLookupTable ) / sizeof( StencilOperationLookupTable[0] );
2234
2235   // Set all 3 StencilOperation properties to a default.
2236   renderer.SetProperty( Renderer::Property::STENCIL_OPERATION_ON_FAIL, StencilOperation::ZERO );
2237   renderer.SetProperty( Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, StencilOperation::ZERO );
2238   renderer.SetProperty( Renderer::Property::STENCIL_OPERATION_ON_Z_PASS, StencilOperation::ZERO );
2239
2240   // Set our expected parameter list to the equivalent result.
2241   int parameters[] = { StencilOperationLookupTable[ StencilOperation::ZERO ], StencilOperationLookupTable[ StencilOperation::ZERO ], StencilOperationLookupTable[ StencilOperation::ZERO ] };
2242
2243   ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2244
2245   /*
2246    * Loop through all types of StencilOperation, checking:
2247    *  - The value is cached (set in event thread side)
2248    *  - Causes "glStencilFunc" to be called
2249    *  - Checks the correct parameters to "glStencilFunc" were used
2250    *  - Checks the above for all 3 parameter placements of StencilOperation ( OnFail, OnZFail, OnPass )
2251    */
2252   int stencilOperationPropertyKeys[] = { Renderer::Property::STENCIL_OPERATION_ON_FAIL, Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, Renderer::Property::STENCIL_OPERATION_ON_Z_PASS };
2253   std::string methodString( "StencilOp" );
2254
2255   for( int parameterIndex = 0; parameterIndex < 3; ++parameterIndex )
2256   {
2257     for( int i = 0; i < StencilOperationLookupTableCount; ++i )
2258     {
2259       // Set the property (outer loop causes all 3 different properties to be set separately).
2260       renderer.SetProperty( stencilOperationPropertyKeys[ parameterIndex ], static_cast<Dali::StencilFunction::Type>( i ) );
2261
2262       // Check GetProperty returns the same value.
2263       DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( stencilOperationPropertyKeys[ parameterIndex ] ).Get<int>() ), i, TEST_LOCATION );
2264
2265       // Reset the trace debug.
2266       ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2267
2268       // Check the function is called and the parameters are correct.
2269       // Set the expected parameter value at its correct index (only)
2270       parameters[ parameterIndex ] = StencilOperationLookupTable[ i ];
2271
2272       // Build the parameter list.
2273       std::stringstream parameterStream;
2274       for( int parameterBuild = 0; parameterBuild < 3; ++parameterBuild )
2275       {
2276         parameterStream << parameters[ parameterBuild ];
2277         // Comma-separate the parameters.
2278         if( parameterBuild < 2 )
2279         {
2280           parameterStream << ", ";
2281         }
2282       }
2283
2284       // Check the function was called and the parameters were correct.
2285       DALI_TEST_CHECK( glStencilFunctionStack.FindMethodAndParams( methodString, parameterStream.str() ) );
2286     }
2287   }
2288
2289   END_TEST;
2290 }
2291
2292 int UtcDaliRendererSetStencilMask(void)
2293 {
2294   TestApplication application;
2295   tet_infoline("Test setting the StencilMask");
2296
2297   Renderer renderer = StencilTestFixture( application );
2298   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2299   glAbstraction.EnableEnableDisableCallTrace( true );
2300   glAbstraction.EnableStencilFunctionCallTrace( true );
2301   TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2302   TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2303
2304   // StencilMode must be ON for StencilMask to operate.
2305   renderer.SetProperty( Renderer::Property::STENCIL_MODE, StencilMode::ON );
2306
2307   // Set the StencilMask property to a value.
2308   renderer.SetProperty( Renderer::Property::STENCIL_MASK, 0x00 );
2309
2310   // Check GetProperty returns the same value.
2311   DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_MASK ).Get<int>() ), 0x00, TEST_LOCATION );
2312
2313   ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2314
2315   std::string methodString( "StencilMask" );
2316   std::string parameterString = "0";
2317
2318   // Check the function was called and the parameters were correct.
2319   DALI_TEST_CHECK( glStencilFunctionStack.FindMethodAndParams( methodString, parameterString ) );
2320
2321   // Set the StencilMask property to another value to ensure it has changed.
2322   renderer.SetProperty( Renderer::Property::STENCIL_MASK, 0xFF );
2323
2324   // Check GetProperty returns the same value.
2325   DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_MASK ).Get<int>() ), 0xFF, TEST_LOCATION );
2326
2327   ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2328
2329   parameterString = "255";
2330
2331   // Check the function was called and the parameters were correct.
2332   DALI_TEST_CHECK( glStencilFunctionStack.FindMethodAndParams( methodString, parameterString ) );
2333
2334   END_TEST;
2335 }
2336
2337 int UtcDaliRendererSetWriteToColorBuffer(void)
2338 {
2339   TestApplication application;
2340   tet_infoline("Test setting the WriteToColorBuffer flag");
2341
2342   Renderer renderer = StencilTestFixture( application );
2343   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2344
2345   // Set the StencilMask property to a value.
2346   renderer.SetProperty( Renderer::Property::WRITE_TO_COLOR_BUFFER, false );
2347
2348   // Check GetProperty returns the same value.
2349   DALI_TEST_CHECK( !renderer.GetProperty( Renderer::Property::WRITE_TO_COLOR_BUFFER ).Get<bool>() );
2350
2351   application.SendNotification();
2352   application.Render();
2353
2354   // Check if ColorMask has been called, and that the values are correct.
2355   const TestGlAbstraction::ColorMaskParams& colorMaskParams( glAbstraction.GetColorMaskParams() );
2356
2357   DALI_TEST_EQUALS<bool>( colorMaskParams.red,   false, TEST_LOCATION );
2358   DALI_TEST_EQUALS<bool>( colorMaskParams.green, false, TEST_LOCATION );
2359   DALI_TEST_EQUALS<bool>( colorMaskParams.blue,  false, TEST_LOCATION );
2360   DALI_TEST_EQUALS<bool>( colorMaskParams.alpha, false, TEST_LOCATION );
2361
2362   // Set the StencilMask property to true.
2363   renderer.SetProperty( Renderer::Property::WRITE_TO_COLOR_BUFFER, true );
2364
2365   // Check GetProperty returns the same value.
2366   DALI_TEST_CHECK( renderer.GetProperty( Renderer::Property::WRITE_TO_COLOR_BUFFER ).Get<bool>() );
2367
2368   application.SendNotification();
2369   application.Render();
2370
2371   // Check if ColorMask has been called, and that the values are correct.
2372   const TestGlAbstraction::ColorMaskParams& colorMaskParamsChanged( glAbstraction.GetColorMaskParams() );
2373
2374   DALI_TEST_EQUALS<bool>( colorMaskParamsChanged.red,   true, TEST_LOCATION );
2375   DALI_TEST_EQUALS<bool>( colorMaskParamsChanged.green, true, TEST_LOCATION );
2376   DALI_TEST_EQUALS<bool>( colorMaskParamsChanged.blue,  true, TEST_LOCATION );
2377   DALI_TEST_EQUALS<bool>( colorMaskParamsChanged.alpha, true, TEST_LOCATION );
2378
2379   END_TEST;
2380 }