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