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