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