UTC coverage for new mesh
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / 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 using namespace Dali;
22
23 #include <mesh-builder.h>
24
25 namespace
26 {
27 void TestConstraintNoBlue( Vector4& current, const PropertyInputContainer& inputs )
28 {
29   current.b = 0.0f;
30 }
31 }
32
33 void renderer_test_startup(void)
34 {
35   test_return_value = TET_UNDEF;
36 }
37
38 void renderer_test_cleanup(void)
39 {
40   test_return_value = TET_PASS;
41 }
42
43
44 int UtcDaliRendererNew01(void)
45 {
46   TestApplication application;
47
48   Geometry geometry = CreateQuadGeometry();
49   Material material = CreateMaterial(1.0f);
50   Renderer renderer = Renderer::New(geometry, material);
51
52   DALI_TEST_EQUALS( (bool)renderer, true, TEST_LOCATION );
53   END_TEST;
54 }
55
56 int UtcDaliRendererNew02(void)
57 {
58   TestApplication application;
59   Renderer renderer;
60   DALI_TEST_EQUALS( (bool)renderer, false, TEST_LOCATION );
61   END_TEST;
62 }
63
64 int UtcDaliRendererCopyConstructor(void)
65 {
66   TestApplication application;
67
68   Geometry geometry = CreateQuadGeometry();
69   Material material = CreateMaterial(1.0f);
70   Renderer renderer = Renderer::New(geometry, material);
71
72   Renderer rendererCopy( renderer );
73   DALI_TEST_EQUALS( (bool)rendererCopy, true, TEST_LOCATION );
74
75   END_TEST;
76 }
77
78 int UtcDaliRendererAssignmentOperator(void)
79 {
80   TestApplication application;
81
82   Geometry geometry = CreateQuadGeometry();
83   Material material = CreateMaterial(1.0f);
84   Renderer renderer = Renderer::New(geometry, material);
85
86   Renderer renderer2;
87   DALI_TEST_EQUALS( (bool)renderer2, false, TEST_LOCATION );
88
89   renderer2 = renderer;
90   DALI_TEST_EQUALS( (bool)renderer2, true, TEST_LOCATION );
91   END_TEST;
92 }
93
94 int UtcDaliRendererDownCast01(void)
95 {
96   TestApplication application;
97
98   Geometry geometry = CreateQuadGeometry();
99   Material material = CreateMaterial(1.0f);
100   Renderer renderer = Renderer::New(geometry, material);
101
102   BaseHandle handle(renderer);
103   Renderer renderer2 = Renderer::DownCast(handle);
104   DALI_TEST_EQUALS( (bool)renderer2, true, TEST_LOCATION );
105   END_TEST;
106 }
107
108 int UtcDaliRendererDownCast02(void)
109 {
110   TestApplication application;
111
112   Handle handle = Handle::New(); // Create a custom object
113   Renderer renderer = Renderer::DownCast(handle);
114   DALI_TEST_EQUALS( (bool)renderer, false, TEST_LOCATION );
115   END_TEST;
116 }
117
118 int UtcDaliRendererSetGetGeometry(void)
119 {
120   TestApplication application;
121   tet_infoline( "Test SetGeometry, GetGeometry" );
122
123   Geometry geometry1 = CreateQuadGeometry();
124   geometry1.RegisterProperty( "uFadeColor", Color::RED );
125
126   Geometry geometry2 = CreateQuadGeometry();
127   geometry2.RegisterProperty( "uFadeColor", Color::GREEN );
128
129   Material material = CreateMaterial(1.0f);
130   Renderer renderer = Renderer::New(geometry1, material);
131   Actor actor = Actor::New();
132   actor.AddRenderer(renderer);
133   actor.SetSize(400, 400);
134   Stage::GetCurrent().Add(actor);
135
136   TestGlAbstraction& gl = application.GetGlAbstraction();
137   application.SendNotification();
138   application.Render(0);
139
140   // Expect that the first geometry's fade color property is accessed
141   Vector4 actualValue(Vector4::ZERO);
142   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
143   DALI_TEST_EQUALS( actualValue, Color::RED, TEST_LOCATION );
144
145   DALI_TEST_EQUALS( renderer.GetGeometry(), geometry1, TEST_LOCATION );
146
147   // Set geometry2 to the renderer
148   renderer.SetGeometry( geometry2 );
149
150   application.SendNotification();
151   application.Render(0);
152
153   // Expect that the second geometry's fade color property is accessed
154   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
155   DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
156
157   DALI_TEST_EQUALS( renderer.GetGeometry(), geometry2, TEST_LOCATION );
158
159   END_TEST;
160 }
161
162 int UtcDaliRendererSetGetMaterial(void)
163 {
164   TestApplication application;
165   tet_infoline( "Test SetMaterial, GetMaterial" );
166
167   TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
168   glAbstraction.EnableCullFaceCallTrace(true);
169
170   Material material1 = CreateMaterial(1.0f);
171   material1.RegisterProperty( "uFadeColor", Color::RED );
172
173   Material material2 = CreateMaterial(1.0f);
174   material2.RegisterProperty( "uFadeColor", Color::GREEN );
175
176   Geometry geometry = CreateQuadGeometry();
177   Renderer renderer = Renderer::New(geometry, material1);
178   Actor actor = Actor::New();
179   actor.AddRenderer(renderer);
180   actor.SetSize(400, 400);
181   Stage::GetCurrent().Add(actor);
182
183   TestGlAbstraction& gl = application.GetGlAbstraction();
184   application.SendNotification();
185   application.Render(0);
186
187   // Expect that the first material's fade color property is accessed
188   Vector4 actualValue(Vector4::ZERO);
189   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
190   DALI_TEST_EQUALS( actualValue, Color::RED, TEST_LOCATION );
191
192   DALI_TEST_EQUALS( renderer.GetMaterial(), material1, TEST_LOCATION );
193
194   // set the second material to the renderer
195   renderer.SetMaterial( material2 );
196
197   application.SendNotification();
198   application.Render(0);
199
200   // Expect that the second material's fade color property is accessed
201   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
202   DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
203
204   DALI_TEST_EQUALS( renderer.GetMaterial(), material2, TEST_LOCATION );
205
206   END_TEST;
207 }
208
209 int UtcDaliRendererSetGetDepthIndex(void)
210 {
211   TestApplication application;
212
213   tet_infoline("Test SetDepthIndex, GetCurrentDepthIndex");
214
215   Material material = CreateMaterial(1.0f);
216   Geometry geometry = CreateQuadGeometry();
217   Renderer renderer = Renderer::New(geometry, material);
218   Actor actor = Actor::New();
219   actor.AddRenderer(renderer);
220   actor.SetSize(400, 400);
221   Stage::GetCurrent().Add(actor);
222
223   application.SendNotification();
224   application.Render(0);
225   DALI_TEST_EQUALS( renderer.GetCurrentDepthIndex(), 0, TEST_LOCATION );
226   DALI_TEST_EQUALS( renderer.GetProperty<int>(Renderer::Property::DEPTH_INDEX), 0, TEST_LOCATION );
227
228   renderer.SetDepthIndex(1);
229
230   application.SendNotification();
231   application.Render(0);
232   DALI_TEST_EQUALS( renderer.GetCurrentDepthIndex(), 1, TEST_LOCATION );
233   DALI_TEST_EQUALS( renderer.GetProperty<int>(Renderer::Property::DEPTH_INDEX), 1, TEST_LOCATION );
234
235   renderer.SetDepthIndex(10);
236
237   application.SendNotification();
238   application.Render(0);
239   DALI_TEST_EQUALS( renderer.GetCurrentDepthIndex(), 10, TEST_LOCATION );
240   DALI_TEST_EQUALS( renderer.GetProperty<int>(Renderer::Property::DEPTH_INDEX), 10, TEST_LOCATION );
241
242   END_TEST;
243 }
244
245 int UtcDaliRendererConstraint01(void)
246 {
247   TestApplication application;
248
249   tet_infoline("Test that a non-uniform renderer property can be constrained");
250
251   Shader shader = Shader::New("VertexSource", "FragmentSource");
252   Material material = Material::New( shader );
253   material.SetProperty(Material::Property::COLOR, Color::WHITE);
254
255   Geometry geometry = CreateQuadGeometry();
256   Renderer renderer = Renderer::New( geometry, material );
257
258   Actor actor = Actor::New();
259   actor.AddRenderer(renderer);
260   actor.SetSize(400, 400);
261   Stage::GetCurrent().Add(actor);
262
263   Vector4 initialColor = Color::WHITE;
264   Property::Index colorIndex = renderer.RegisterProperty( "uFadeColor", initialColor );
265
266   application.SendNotification();
267   application.Render(0);
268   DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION );
269
270   // Apply constraint
271   Constraint constraint = Constraint::New<Vector4>( renderer, colorIndex, TestConstraintNoBlue );
272   constraint.Apply();
273   application.SendNotification();
274   application.Render(0);
275
276   // Expect no blue component in either buffer - yellow
277   DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(colorIndex), Color::YELLOW, TEST_LOCATION );
278   application.Render(0);
279   DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(colorIndex), Color::YELLOW, TEST_LOCATION );
280
281   renderer.RemoveConstraints();
282   renderer.SetProperty(colorIndex, Color::WHITE );
283   application.SendNotification();
284   application.Render(0);
285   DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(colorIndex), Color::WHITE, TEST_LOCATION );
286
287   END_TEST;
288 }
289
290 int UtcDaliRendererConstraint02(void)
291 {
292   TestApplication application;
293
294   tet_infoline("Test that a uniform map renderer property can be constrained");
295
296   Shader shader = Shader::New("VertexSource", "FragmentSource");
297   Material material = Material::New( shader );
298   material.SetProperty(Material::Property::COLOR, Color::WHITE);
299
300   Geometry geometry = CreateQuadGeometry();
301   Renderer renderer = Renderer::New( geometry, material );
302
303   Actor actor = Actor::New();
304   actor.AddRenderer(renderer);
305   actor.SetSize(400, 400);
306   Stage::GetCurrent().Add(actor);
307   application.SendNotification();
308   application.Render(0);
309
310   Vector4 initialColor = Color::WHITE;
311   Property::Index colorIndex = renderer.RegisterProperty( "uFadeColor", initialColor );
312
313   TestGlAbstraction& gl = application.GetGlAbstraction();
314
315   application.SendNotification();
316   application.Render(0);
317
318   Vector4 actualValue(Vector4::ZERO);
319   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
320   DALI_TEST_EQUALS( actualValue, initialColor, TEST_LOCATION );
321
322   // Apply constraint
323   Constraint constraint = Constraint::New<Vector4>( renderer, colorIndex, TestConstraintNoBlue );
324   constraint.Apply();
325   application.SendNotification();
326   application.Render(0);
327
328    // Expect no blue component in either buffer - yellow
329   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
330   DALI_TEST_EQUALS( actualValue, Color::YELLOW, TEST_LOCATION );
331
332   application.Render(0);
333   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
334   DALI_TEST_EQUALS( actualValue, Color::YELLOW, TEST_LOCATION );
335
336   renderer.RemoveConstraints();
337   renderer.SetProperty(colorIndex, Color::WHITE );
338   application.SendNotification();
339   application.Render(0);
340
341   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
342   DALI_TEST_EQUALS( actualValue, Color::WHITE, TEST_LOCATION );
343
344   END_TEST;
345 }
346
347
348
349 int UtcDaliRendererAnimatedProperty01(void)
350 {
351   TestApplication application;
352
353   tet_infoline("Test that a non-uniform renderer property can be animated");
354
355   Shader shader = Shader::New("VertexSource", "FragmentSource");
356   Material material = Material::New( shader );
357   material.SetProperty(Material::Property::COLOR, Color::WHITE);
358
359   Geometry geometry = CreateQuadGeometry();
360   Renderer renderer = Renderer::New( geometry, material );
361
362   Actor actor = Actor::New();
363   actor.AddRenderer(renderer);
364   actor.SetSize(400, 400);
365   Stage::GetCurrent().Add(actor);
366
367   Vector4 initialColor = Color::WHITE;
368   Property::Index colorIndex = renderer.RegisterProperty( "uFadeColor", initialColor );
369
370   application.SendNotification();
371   application.Render(0);
372   DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION );
373
374   Animation  animation = Animation::New(1.0f);
375   KeyFrames keyFrames = KeyFrames::New();
376   keyFrames.Add(0.0f, initialColor);
377   keyFrames.Add(1.0f, Color::TRANSPARENT);
378   animation.AnimateBetween( Property( renderer, colorIndex ), keyFrames );
379   animation.Play();
380
381   application.SendNotification();
382   application.Render(500);
383
384   DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(colorIndex), Color::WHITE * 0.5f, TEST_LOCATION );
385
386   application.Render(500);
387
388   DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(colorIndex), Color::TRANSPARENT, TEST_LOCATION );
389
390   END_TEST;
391 }
392
393 int UtcDaliRendererAnimatedProperty02(void)
394 {
395   TestApplication application;
396
397   tet_infoline("Test that a uniform map renderer property can be animated");
398
399   Shader shader = Shader::New("VertexSource", "FragmentSource");
400   Material material = Material::New( shader );
401   material.SetProperty(Material::Property::COLOR, Color::WHITE);
402
403   Geometry geometry = CreateQuadGeometry();
404   Renderer renderer = Renderer::New( geometry, material );
405
406   Actor actor = Actor::New();
407   actor.AddRenderer(renderer);
408   actor.SetSize(400, 400);
409   Stage::GetCurrent().Add(actor);
410   application.SendNotification();
411   application.Render(0);
412
413   Vector4 initialColor = Color::WHITE;
414   Property::Index colorIndex = renderer.RegisterProperty( "uFadeColor", initialColor );
415
416   TestGlAbstraction& gl = application.GetGlAbstraction();
417
418   application.SendNotification();
419   application.Render(0);
420
421   Vector4 actualValue(Vector4::ZERO);
422   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
423   DALI_TEST_EQUALS( actualValue, initialColor, TEST_LOCATION );
424
425   Animation  animation = Animation::New(1.0f);
426   KeyFrames keyFrames = KeyFrames::New();
427   keyFrames.Add(0.0f, initialColor);
428   keyFrames.Add(1.0f, Color::TRANSPARENT);
429   animation.AnimateBetween( Property( renderer, colorIndex ), keyFrames );
430   animation.Play();
431
432   application.SendNotification();
433   application.Render(500);
434
435   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
436   DALI_TEST_EQUALS( actualValue, Color::WHITE * 0.5f, TEST_LOCATION );
437
438   application.Render(500);
439   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
440   DALI_TEST_EQUALS( actualValue, Color::TRANSPARENT, TEST_LOCATION );
441
442   END_TEST;
443 }
444
445
446
447
448 int UtcDaliRendererUniformMapPrecendence01(void)
449 {
450   TestApplication application;
451
452   tet_infoline("Test the uniform map precedence is applied properly");
453
454   Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
455   Sampler sampler = Sampler::New(image, "sTexture");
456   sampler.SetUniformName( "sEffectTexture" );
457
458   Shader shader = Shader::New("VertexSource", "FragmentSource");
459   Material material = Material::New( shader );
460   material.AddSampler( sampler );
461   material.SetProperty(Material::Property::COLOR, Color::WHITE);
462
463   PropertyBuffer vertexBuffer = CreatePropertyBuffer();
464   Geometry geometry = CreateQuadGeometryFromBuffer(vertexBuffer);
465   Renderer renderer = Renderer::New( geometry, material );
466
467   Actor actor = Actor::New();
468   actor.AddRenderer(renderer);
469   actor.SetSize(400, 400);
470   Stage::GetCurrent().Add(actor);
471   application.SendNotification();
472   application.Render(0);
473
474   renderer.RegisterProperty( "uFadeColor", Color::RED );
475
476   actor.RegisterProperty( "uFadeColor", Color::GREEN );
477
478   Property::Index materialFadeColorIndex = material.RegisterProperty( "uFadeColor", Color::BLUE );
479
480   sampler.RegisterProperty( "uFadeColor", Color::CYAN );
481   shader.RegisterProperty( "uFadeColor", Color::MAGENTA );
482
483   geometry.RegisterProperty( "uFadeColor", Color::YELLOW );
484
485   vertexBuffer.RegisterProperty( "uFadeColor", Color::BLACK );
486
487
488   TestGlAbstraction& gl = application.GetGlAbstraction();
489
490   application.SendNotification();
491   application.Render(0);
492
493   // Expect that the renderer's fade color property is accessed
494   Vector4 actualValue(Vector4::ZERO);
495   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
496   DALI_TEST_EQUALS( actualValue, Color::RED, TEST_LOCATION );
497
498   // Animate material's fade color property. Should be no change to uniform
499   Animation  animation = Animation::New(1.0f);
500   KeyFrames keyFrames = KeyFrames::New();
501   keyFrames.Add(0.0f, Color::WHITE);
502   keyFrames.Add(1.0f, Color::TRANSPARENT);
503   animation.AnimateBetween( Property( material, materialFadeColorIndex ), keyFrames );
504   animation.Play();
505
506   application.SendNotification();
507   application.Render(500);
508
509   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
510   DALI_TEST_EQUALS( actualValue, Color::RED, TEST_LOCATION );
511
512   application.Render(500);
513   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
514   DALI_TEST_EQUALS( actualValue, Color::RED, TEST_LOCATION );
515
516   END_TEST;
517 }
518
519 int UtcDaliRendererUniformMapPrecendence02(void)
520 {
521   TestApplication application;
522
523   tet_infoline("Test the uniform map precedence is applied properly");
524
525   Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
526   Sampler sampler = Sampler::New(image, "sTexture");
527   sampler.SetUniformName( "sEffectTexture" );
528
529   Shader shader = Shader::New("VertexSource", "FragmentSource");
530   Material material = Material::New( shader );
531   material.AddSampler( sampler );
532   material.SetProperty(Material::Property::COLOR, Color::WHITE);
533
534   PropertyBuffer vertexBuffer = CreatePropertyBuffer();
535   Geometry geometry = CreateQuadGeometryFromBuffer(vertexBuffer);
536   Renderer renderer = Renderer::New( geometry, material );
537
538   Actor actor = Actor::New();
539   actor.AddRenderer(renderer);
540   actor.SetSize(400, 400);
541   Stage::GetCurrent().Add(actor);
542   application.SendNotification();
543   application.Render(0);
544
545   // Don't add property / uniform map to renderer
546
547   actor.RegisterProperty( "uFadeColor", Color::GREEN );
548
549   Property::Index materialFadeColorIndex = material.RegisterProperty( "uFadeColor", Color::BLUE );
550
551   sampler.RegisterProperty( "uFadeColor", Color::CYAN );
552   shader.RegisterProperty( "uFadeColor", Color::MAGENTA );
553
554   geometry.RegisterProperty( "uFadeColor", Color::YELLOW );
555
556   vertexBuffer.RegisterProperty( "uFadeColor", Color::BLACK );
557
558
559   TestGlAbstraction& gl = application.GetGlAbstraction();
560
561   application.SendNotification();
562   application.Render(0);
563
564   // Expect that the actor's fade color property is accessed
565   Vector4 actualValue(Vector4::ZERO);
566   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
567   DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
568
569   // Animate material's fade color property. Should be no change to uniform
570   Animation  animation = Animation::New(1.0f);
571   KeyFrames keyFrames = KeyFrames::New();
572   keyFrames.Add(0.0f, Color::WHITE);
573   keyFrames.Add(1.0f, Color::TRANSPARENT);
574   animation.AnimateBetween( Property( material, materialFadeColorIndex ), keyFrames );
575   animation.Play();
576
577   application.SendNotification();
578   application.Render(500);
579
580   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
581   DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
582
583   application.Render(500);
584   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
585   DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
586
587   END_TEST;
588 }
589
590
591 int UtcDaliRendererUniformMapPrecendence03(void)
592 {
593   TestApplication application;
594
595   tet_infoline("Test the uniform map precedence is applied properly");
596
597   Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
598   Sampler sampler = Sampler::New(image, "sTexture");
599   sampler.SetUniformName( "sEffectTexture" );
600
601   Shader shader = Shader::New("VertexSource", "FragmentSource");
602   Material material = Material::New( shader );
603   material.AddSampler( sampler );
604   material.SetProperty(Material::Property::COLOR, Color::WHITE);
605
606   PropertyBuffer vertexBuffer = CreatePropertyBuffer();
607   Geometry geometry = CreateQuadGeometryFromBuffer(vertexBuffer);
608   Renderer renderer = Renderer::New( geometry, material );
609
610   Actor actor = Actor::New();
611   actor.AddRenderer(renderer);
612   actor.SetSize(400, 400);
613   Stage::GetCurrent().Add(actor);
614   application.SendNotification();
615   application.Render(0);
616
617   // Don't add property / uniform map to renderer or actor
618
619   material.RegisterProperty( "uFadeColor", Color::BLUE );
620
621   sampler.RegisterProperty( "uFadeColor", Color::CYAN );
622   shader.RegisterProperty( "uFadeColor", Color::MAGENTA );
623
624   Property::Index geometryFadeColorIndex = geometry.RegisterProperty( "uFadeColor", Color::YELLOW );
625
626   vertexBuffer.RegisterProperty( "uFadeColor", Color::BLACK );
627
628
629   TestGlAbstraction& gl = application.GetGlAbstraction();
630
631   application.SendNotification();
632   application.Render(0);
633
634   // Expect that the material's fade color property is accessed
635   Vector4 actualValue(Vector4::ZERO);
636   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
637   DALI_TEST_EQUALS( actualValue, Color::BLUE, TEST_LOCATION );
638
639   // Animate geometry's fade color property. Should be no change to uniform
640   Animation  animation = Animation::New(1.0f);
641   KeyFrames keyFrames = KeyFrames::New();
642   keyFrames.Add(0.0f, Color::WHITE);
643   keyFrames.Add(1.0f, Color::TRANSPARENT);
644   animation.AnimateBetween( Property( geometry, geometryFadeColorIndex ), keyFrames );
645   animation.Play();
646
647   application.SendNotification();
648   application.Render(500);
649
650   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
651   DALI_TEST_EQUALS( actualValue, Color::BLUE, TEST_LOCATION );
652
653   application.Render(500);
654   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
655   DALI_TEST_EQUALS( actualValue, Color::BLUE, TEST_LOCATION );
656
657   END_TEST;
658 }
659
660
661 int UtcDaliRendererUniformMapPrecendence04(void)
662 {
663   TestApplication application;
664
665   tet_infoline("Test the uniform map precedence is applied properly");
666
667   Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
668   Sampler sampler = Sampler::New(image, "sTexture");
669   sampler.SetUniformName( "sEffectTexture" );
670
671   Shader shader = Shader::New("VertexSource", "FragmentSource");
672   Material material = Material::New( shader );
673   material.AddSampler( sampler );
674   material.SetProperty(Material::Property::COLOR, Color::WHITE);
675
676   PropertyBuffer vertexBuffer = CreatePropertyBuffer();
677   Geometry geometry = CreateQuadGeometryFromBuffer(vertexBuffer);
678   Renderer renderer = Renderer::New( geometry, material );
679
680   Actor actor = Actor::New();
681   actor.AddRenderer(renderer);
682   actor.SetSize(400, 400);
683   Stage::GetCurrent().Add(actor);
684   application.SendNotification();
685   application.Render(0);
686
687   // Don't add property / uniform map to renderer/actor/material
688
689   sampler.RegisterProperty( "uFadeColor", Color::CYAN );
690   shader.RegisterProperty( "uFadeColor", Color::MAGENTA );
691
692   Property::Index geometryFadeColorIndex = geometry.RegisterProperty( "uFadeColor", Color::YELLOW );
693
694   vertexBuffer.RegisterProperty( "uFadeColor", Color::BLACK );
695
696
697   TestGlAbstraction& gl = application.GetGlAbstraction();
698
699   application.SendNotification();
700   application.Render(0);
701
702   // Expect that the sampler's fade color property is accessed
703   Vector4 actualValue(Vector4::ZERO);
704   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
705   DALI_TEST_EQUALS( actualValue, Color::CYAN, TEST_LOCATION );
706
707   // Animate geometry's fade color property. Should be no change to uniform
708   Animation  animation = Animation::New(1.0f);
709   KeyFrames keyFrames = KeyFrames::New();
710   keyFrames.Add(0.0f, Color::WHITE);
711   keyFrames.Add(1.0f, Color::TRANSPARENT);
712   animation.AnimateBetween( Property( geometry, geometryFadeColorIndex ), keyFrames );
713   animation.Play();
714
715   application.SendNotification();
716   application.Render(500);
717
718   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
719   DALI_TEST_EQUALS( actualValue, Color::CYAN, TEST_LOCATION );
720
721   application.Render(500);
722   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
723   DALI_TEST_EQUALS( actualValue, Color::CYAN, TEST_LOCATION );
724
725   END_TEST;
726 }
727
728 int UtcDaliRendererUniformMapPrecendence05(void)
729 {
730   TestApplication application;
731
732   tet_infoline("Test the uniform map precedence is applied properly");
733
734   Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
735   Sampler sampler = Sampler::New(image, "sTexture");
736   sampler.SetUniformName( "sEffectTexture" );
737
738   Shader shader = Shader::New("VertexSource", "FragmentSource");
739   Material material = Material::New( shader );
740   material.AddSampler( sampler );
741   material.SetProperty(Material::Property::COLOR, Color::WHITE);
742
743   PropertyBuffer vertexBuffer = CreatePropertyBuffer();
744   Geometry geometry = CreateQuadGeometryFromBuffer(vertexBuffer);
745   Renderer renderer = Renderer::New( geometry, material );
746
747   Actor actor = Actor::New();
748   actor.AddRenderer(renderer);
749   actor.SetSize(400, 400);
750   Stage::GetCurrent().Add(actor);
751   application.SendNotification();
752   application.Render(0);
753
754   // Don't add property / uniform map to renderer/actor/material/sampler
755
756   shader.RegisterProperty( "uFadeColor", Color::MAGENTA );
757
758   Property::Index geometryFadeColorIndex = geometry.RegisterProperty( "uFadeColor", Color::YELLOW );
759
760   vertexBuffer.RegisterProperty( "uFadeColor", Color::BLACK );
761
762
763   TestGlAbstraction& gl = application.GetGlAbstraction();
764
765   application.SendNotification();
766   application.Render(0);
767
768   // Expect that the shader's fade color property is accessed
769   Vector4 actualValue(Vector4::ZERO);
770   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
771   DALI_TEST_EQUALS( actualValue, Color::MAGENTA, TEST_LOCATION );
772
773   // Animate geometry's fade color property. Should be no change to uniform
774   Animation  animation = Animation::New(1.0f);
775   KeyFrames keyFrames = KeyFrames::New();
776   keyFrames.Add(0.0f, Color::WHITE);
777   keyFrames.Add(1.0f, Color::TRANSPARENT);
778   animation.AnimateBetween( Property( geometry, geometryFadeColorIndex ), keyFrames );
779   animation.Play();
780
781   application.SendNotification();
782   application.Render(500);
783
784   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
785   DALI_TEST_EQUALS( actualValue, Color::MAGENTA, TEST_LOCATION );
786
787   application.Render(500);
788   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
789   DALI_TEST_EQUALS( actualValue, Color::MAGENTA, TEST_LOCATION );
790
791   END_TEST;
792 }
793
794 int UtcDaliRendererUniformMapPrecendence06(void)
795 {
796   TestApplication application;
797
798   tet_infoline("Test the uniform map precedence is applied properly");
799
800   Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
801   Sampler sampler = Sampler::New(image, "sTexture");
802   sampler.SetUniformName( "sEffectTexture" );
803
804   Shader shader = Shader::New("VertexSource", "FragmentSource");
805   Material material = Material::New( shader );
806   material.AddSampler( sampler );
807   material.SetProperty(Material::Property::COLOR, Color::WHITE);
808
809   PropertyBuffer vertexBuffer = CreatePropertyBuffer();
810   Geometry geometry = CreateQuadGeometryFromBuffer(vertexBuffer);
811   Renderer renderer = Renderer::New( geometry, material );
812
813   Actor actor = Actor::New();
814   actor.AddRenderer(renderer);
815   actor.SetSize(400, 400);
816   Stage::GetCurrent().Add(actor);
817   application.SendNotification();
818   application.Render(0);
819
820   // Don't add property / uniform map to renderer/actor/material/sampler/shader
821
822   geometry.RegisterProperty( "uFadeColor", Color::YELLOW );
823
824   Property::Index vertexFadeColorIndex = vertexBuffer.RegisterProperty( "uFadeColor", Color::BLACK );
825
826
827   TestGlAbstraction& gl = application.GetGlAbstraction();
828
829   application.SendNotification();
830   application.Render(0);
831
832   // Expect that the geometry's fade color property is accessed
833   Vector4 actualValue(Vector4::ZERO);
834   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
835   DALI_TEST_EQUALS( actualValue, Color::YELLOW, TEST_LOCATION );
836
837   // Animate vertex buffer's fade color property. Should be no change to uniform
838   Animation  animation = Animation::New(1.0f);
839   KeyFrames keyFrames = KeyFrames::New();
840   keyFrames.Add(0.0f, Color::WHITE);
841   keyFrames.Add(1.0f, Color::TRANSPARENT);
842   animation.AnimateBetween( Property( vertexBuffer, vertexFadeColorIndex ), keyFrames );
843   animation.Play();
844
845   application.SendNotification();
846   application.Render(500);
847
848   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
849   DALI_TEST_EQUALS( actualValue, Color::YELLOW, TEST_LOCATION );
850
851   application.Render(500);
852   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
853   DALI_TEST_EQUALS( actualValue, Color::YELLOW, TEST_LOCATION );
854
855   END_TEST;
856 }
857
858 int UtcDaliRendererUniformMapPrecendence07(void)
859 {
860   TestApplication application;
861
862   tet_infoline("Test the uniform map precedence is applied properly");
863
864   Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
865   Sampler sampler = Sampler::New(image, "sTexture");
866   sampler.SetUniformName( "sEffectTexture" );
867
868   Shader shader = Shader::New("VertexSource", "FragmentSource");
869   Material material = Material::New( shader );
870   material.AddSampler( sampler );
871   material.SetProperty(Material::Property::COLOR, Color::WHITE);
872
873   PropertyBuffer vertexBuffer = CreatePropertyBuffer();
874   Geometry geometry = CreateQuadGeometryFromBuffer(vertexBuffer);
875   Renderer renderer = Renderer::New( geometry, material );
876
877   Actor actor = Actor::New();
878   actor.AddRenderer(renderer);
879   actor.SetSize(400, 400);
880   Stage::GetCurrent().Add(actor);
881   application.SendNotification();
882   application.Render(0);
883
884   // Don't add property / uniform map to renderer/actor/material/sampler/shader/geometry
885
886   Property::Index vertexFadeColorIndex = vertexBuffer.RegisterProperty( "uFadeColor", Color::BLACK );
887
888   TestGlAbstraction& gl = application.GetGlAbstraction();
889
890   application.SendNotification();
891   application.Render(0);
892
893   // Expect that the vertex buffer's fade color property is accessed
894   Vector4 actualValue(Vector4::ZERO);
895   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
896   DALI_TEST_EQUALS( actualValue, Color::BLACK, TEST_LOCATION );
897
898   // Animate vertex buffer's fade color property. Should change the uniform
899   Animation  animation = Animation::New(1.0f);
900   KeyFrames keyFrames = KeyFrames::New();
901   keyFrames.Add(0.0f, Color::WHITE);
902   keyFrames.Add(1.0f, Color::TRANSPARENT);
903   animation.AnimateBetween( Property( vertexBuffer, vertexFadeColorIndex ), keyFrames );
904   animation.Play();
905
906   application.SendNotification();
907   application.Render(500);
908
909   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
910   DALI_TEST_EQUALS( actualValue, Color::WHITE*0.5f, TEST_LOCATION );
911
912   application.Render(500);
913   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
914   DALI_TEST_EQUALS( actualValue, Color::TRANSPARENT, TEST_LOCATION );
915
916   END_TEST;
917 }
918
919
920 int UtcDaliRendererUniformMapMultipleUniforms01(void)
921 {
922   TestApplication application;
923
924   tet_infoline("Test the uniform maps are collected from all objects (same type)");
925
926   Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
927   Sampler sampler = Sampler::New(image, "sTexture");
928   sampler.SetUniformName( "sEffectTexture" );
929
930   Shader shader = Shader::New("VertexSource", "FragmentSource");
931   Material material = Material::New( shader );
932   material.AddSampler( sampler );
933   material.SetProperty(Material::Property::COLOR, Color::WHITE);
934
935   PropertyBuffer vertexBuffer = CreatePropertyBuffer();
936   Geometry geometry = CreateQuadGeometryFromBuffer(vertexBuffer);
937   Renderer renderer = Renderer::New( geometry, material );
938
939   Actor actor = Actor::New();
940   actor.AddRenderer(renderer);
941   actor.SetSize(400, 400);
942   Stage::GetCurrent().Add(actor);
943   application.SendNotification();
944   application.Render(0);
945
946   renderer.RegisterProperty( "uUniform1", Color::RED );
947   actor.RegisterProperty( "uUniform2", Color::GREEN );
948   material.RegisterProperty( "uUniform3", Color::BLUE );
949   sampler.RegisterProperty( "uUniform4", Color::CYAN );
950   shader.RegisterProperty( "uUniform5", Color::MAGENTA );
951   geometry.RegisterProperty( "uUniform6", Color::YELLOW );
952   vertexBuffer.RegisterProperty( "uUniform7", Color::BLACK );
953
954
955   TestGlAbstraction& gl = application.GetGlAbstraction();
956
957   application.SendNotification();
958   application.Render(0);
959
960   // Expect that each of the object's uniforms are set
961   Vector4 uniform1Value(Vector4::ZERO);
962   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uUniform1", uniform1Value ) );
963   DALI_TEST_EQUALS( uniform1Value, Color::RED, TEST_LOCATION );
964
965   Vector4 uniform2Value(Vector4::ZERO);
966   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uUniform2", uniform2Value ) );
967   DALI_TEST_EQUALS( uniform2Value, Color::GREEN, TEST_LOCATION );
968
969   Vector4 uniform3Value(Vector4::ZERO);
970   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uUniform3", uniform3Value ) );
971   DALI_TEST_EQUALS( uniform3Value, Color::BLUE, TEST_LOCATION );
972
973   Vector4 uniform4Value(Vector4::ZERO);
974   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uUniform4", uniform4Value ) );
975   DALI_TEST_EQUALS( uniform4Value, Color::CYAN, TEST_LOCATION );
976
977   Vector4 uniform5Value(Vector4::ZERO);
978   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uUniform5", uniform5Value ) );
979   DALI_TEST_EQUALS( uniform5Value, Color::MAGENTA, TEST_LOCATION );
980
981   Vector4 uniform6Value(Vector4::ZERO);
982   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uUniform6", uniform6Value ) );
983   DALI_TEST_EQUALS( uniform6Value, Color::YELLOW, TEST_LOCATION );
984
985   Vector4 uniform7Value(Vector4::ZERO);
986   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uUniform7", uniform7Value ) );
987   DALI_TEST_EQUALS( uniform7Value, Color::BLACK, TEST_LOCATION );
988
989
990   END_TEST;
991 }
992
993
994 int UtcDaliRendererUniformMapMultipleUniforms02(void)
995 {
996   TestApplication application;
997
998   tet_infoline("Test the uniform maps are collected from all objects (different types)");
999
1000   Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1001   Sampler sampler = Sampler::New(image, "sTexture");
1002   sampler.SetUniformName( "sEffectTexture" );
1003
1004   Shader shader = Shader::New("VertexSource", "FragmentSource");
1005   Material material = Material::New( shader );
1006   material.AddSampler( sampler );
1007   material.SetProperty(Material::Property::COLOR, Color::WHITE);
1008
1009   PropertyBuffer vertexBuffer = CreatePropertyBuffer();
1010   Geometry geometry = CreateQuadGeometryFromBuffer(vertexBuffer);
1011   Renderer renderer = Renderer::New( geometry, material );
1012
1013   Actor actor = Actor::New();
1014   actor.AddRenderer(renderer);
1015   actor.SetSize(400, 400);
1016   Stage::GetCurrent().Add(actor);
1017   application.SendNotification();
1018   application.Render(0);
1019
1020   Property::Value value1(Color::RED);
1021   renderer.RegisterProperty( "uFadeColor", value1 );
1022
1023   Property::Value value2(1.0f);
1024   actor.RegisterProperty( "uFadeProgress", value2 );
1025
1026   Property::Value value3(Vector3(0.5f, 0.5f, 1.0f));
1027   material.RegisterProperty( "uFadePosition", value3);
1028
1029   Property::Value value4(Vector2(0.5f, 1.0f));
1030   sampler.RegisterProperty( "uFadeUV", value4 );
1031
1032   Property::Value value5(Matrix3::IDENTITY);
1033   shader.RegisterProperty( "uANormalMatrix", value5 );
1034
1035   Property::Value value6(Matrix::IDENTITY);
1036   geometry.RegisterProperty( "uAWorldMatrix", value6 );
1037
1038   Property::Value value7(7);
1039   vertexBuffer.RegisterProperty( "uAnotherFadeColor", value7 );
1040
1041
1042   TestGlAbstraction& gl = application.GetGlAbstraction();
1043
1044   application.SendNotification();
1045   application.Render(0);
1046
1047   // Expect that each of the object's uniforms are set
1048   Vector4 uniform1Value(Vector4::ZERO);
1049   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", uniform1Value ) );
1050   DALI_TEST_EQUALS( uniform1Value, value1.Get<Vector4>(), TEST_LOCATION );
1051
1052   float uniform2Value(0.0f);
1053   DALI_TEST_CHECK( gl.GetUniformValue<float>( "uFadeProgress", uniform2Value ) );
1054   DALI_TEST_EQUALS( uniform2Value, value2.Get<float>(), TEST_LOCATION );
1055
1056   Vector3 uniform3Value(Vector3::ZERO);
1057   DALI_TEST_CHECK( gl.GetUniformValue<Vector3>( "uFadePosition", uniform3Value ) );
1058   DALI_TEST_EQUALS( uniform3Value, value3.Get<Vector3>(), TEST_LOCATION );
1059
1060   Vector2 uniform4Value(Vector2::ZERO);
1061   DALI_TEST_CHECK( gl.GetUniformValue<Vector2>( "uFadeUV", uniform4Value ) );
1062   DALI_TEST_EQUALS( uniform4Value, value4.Get<Vector2>(), TEST_LOCATION );
1063
1064   Matrix3 uniform5Value;
1065   DALI_TEST_CHECK( gl.GetUniformValue<Matrix3>( "uANormalMatrix", uniform5Value ) );
1066   DALI_TEST_EQUALS( uniform5Value, value5.Get<Matrix3>(), TEST_LOCATION );
1067
1068   Matrix uniform6Value;
1069   DALI_TEST_CHECK( gl.GetUniformValue<Matrix>( "uAWorldMatrix", uniform6Value ) );
1070   DALI_TEST_EQUALS( uniform6Value, value6.Get<Matrix>(), TEST_LOCATION );
1071
1072   int uniform7Value = 0;
1073   DALI_TEST_CHECK( gl.GetUniformValue<int>( "uAnotherFadeColor", uniform7Value ) );
1074   DALI_TEST_EQUALS( uniform7Value, value7.Get<int>(), TEST_LOCATION );
1075
1076   END_TEST;
1077 }