2 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include <dali/public-api/dali-core.h>
19 #include <dali-test-suite-utils.h>
23 #include <mesh-builder.h>
27 void TestConstraintNoBlue( Vector4& current, const PropertyInputContainer& inputs )
33 void renderer_test_startup(void)
35 test_return_value = TET_UNDEF;
38 void renderer_test_cleanup(void)
40 test_return_value = TET_PASS;
44 int UtcDaliRendererNew01(void)
46 TestApplication application;
48 Geometry geometry = CreateQuadGeometry();
49 Material material = CreateMaterial(1.0f);
50 Renderer renderer = Renderer::New(geometry, material);
52 DALI_TEST_EQUALS( (bool)renderer, true, TEST_LOCATION );
56 int UtcDaliRendererNew02(void)
58 TestApplication application;
60 DALI_TEST_EQUALS( (bool)renderer, false, TEST_LOCATION );
64 int UtcDaliRendererCopyConstructor(void)
66 TestApplication application;
68 Geometry geometry = CreateQuadGeometry();
69 Material material = CreateMaterial(1.0f);
70 Renderer renderer = Renderer::New(geometry, material);
72 Renderer rendererCopy( renderer );
73 DALI_TEST_EQUALS( (bool)rendererCopy, true, TEST_LOCATION );
78 int UtcDaliRendererAssignmentOperator(void)
80 TestApplication application;
82 Geometry geometry = CreateQuadGeometry();
83 Material material = CreateMaterial(1.0f);
84 Renderer renderer = Renderer::New(geometry, material);
87 DALI_TEST_EQUALS( (bool)renderer2, false, TEST_LOCATION );
90 DALI_TEST_EQUALS( (bool)renderer2, true, TEST_LOCATION );
94 int UtcDaliRendererDownCast01(void)
96 TestApplication application;
98 Geometry geometry = CreateQuadGeometry();
99 Material material = CreateMaterial(1.0f);
100 Renderer renderer = Renderer::New(geometry, material);
102 BaseHandle handle(renderer);
103 Renderer renderer2 = Renderer::DownCast(handle);
104 DALI_TEST_EQUALS( (bool)renderer2, true, TEST_LOCATION );
108 int UtcDaliRendererDownCast02(void)
110 TestApplication application;
112 Handle handle = Handle::New(); // Create a custom object
113 Renderer renderer = Renderer::DownCast(handle);
114 DALI_TEST_EQUALS( (bool)renderer, false, TEST_LOCATION );
118 int UtcDaliRendererSetGetGeometry(void)
120 TestApplication application;
121 tet_infoline( "Test SetGeometry, GetGeometry" );
123 Geometry geometry1 = CreateQuadGeometry();
124 geometry1.RegisterProperty( "uFadeColor", Color::RED );
126 Geometry geometry2 = CreateQuadGeometry();
127 geometry2.RegisterProperty( "uFadeColor", Color::GREEN );
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);
136 TestGlAbstraction& gl = application.GetGlAbstraction();
137 application.SendNotification();
138 application.Render(0);
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 );
145 DALI_TEST_EQUALS( renderer.GetGeometry(), geometry1, TEST_LOCATION );
147 // Set geometry2 to the renderer
148 renderer.SetGeometry( geometry2 );
150 application.SendNotification();
151 application.Render(0);
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 );
157 DALI_TEST_EQUALS( renderer.GetGeometry(), geometry2, TEST_LOCATION );
162 int UtcDaliRendererSetGetMaterial(void)
164 TestApplication application;
165 tet_infoline( "Test SetMaterial, GetMaterial" );
167 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
168 glAbstraction.EnableCullFaceCallTrace(true);
170 Material material1 = CreateMaterial(1.0f);
171 material1.RegisterProperty( "uFadeColor", Color::RED );
173 Material material2 = CreateMaterial(1.0f);
174 material2.RegisterProperty( "uFadeColor", Color::GREEN );
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);
183 TestGlAbstraction& gl = application.GetGlAbstraction();
184 application.SendNotification();
185 application.Render(0);
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 );
192 DALI_TEST_EQUALS( renderer.GetMaterial(), material1, TEST_LOCATION );
194 // set the second material to the renderer
195 renderer.SetMaterial( material2 );
197 application.SendNotification();
198 application.Render(0);
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 );
204 DALI_TEST_EQUALS( renderer.GetMaterial(), material2, TEST_LOCATION );
209 int UtcDaliRendererSetGetDepthIndex(void)
211 TestApplication application;
213 tet_infoline("Test SetDepthIndex, GetDepthIndex");
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);
223 application.SendNotification();
224 application.Render(0);
225 DALI_TEST_EQUALS( renderer.GetDepthIndex(), 0, TEST_LOCATION );
226 DALI_TEST_EQUALS( renderer.GetProperty<int>(Renderer::Property::DEPTH_INDEX), 0, TEST_LOCATION );
228 renderer.SetDepthIndex(1);
230 application.SendNotification();
231 application.Render(0);
232 DALI_TEST_EQUALS( renderer.GetDepthIndex(), 1, TEST_LOCATION );
233 DALI_TEST_EQUALS( renderer.GetProperty<int>(Renderer::Property::DEPTH_INDEX), 1, TEST_LOCATION );
235 renderer.SetDepthIndex(10);
237 application.SendNotification();
238 application.Render(0);
239 DALI_TEST_EQUALS( renderer.GetDepthIndex(), 10, TEST_LOCATION );
240 DALI_TEST_EQUALS( renderer.GetProperty<int>(Renderer::Property::DEPTH_INDEX), 10, TEST_LOCATION );
245 int UtcDaliRendererConstraint01(void)
247 TestApplication application;
249 tet_infoline("Test that a non-uniform renderer property can be constrained");
251 Shader shader = Shader::New("VertexSource", "FragmentSource");
252 Material material = Material::New( shader );
253 material.SetProperty(Material::Property::COLOR, Color::WHITE);
255 Geometry geometry = CreateQuadGeometry();
256 Renderer renderer = Renderer::New( geometry, material );
258 Actor actor = Actor::New();
259 actor.AddRenderer(renderer);
260 actor.SetSize(400, 400);
261 Stage::GetCurrent().Add(actor);
263 Vector4 initialColor = Color::WHITE;
264 Property::Index colorIndex = renderer.RegisterProperty( "uFadeColor", initialColor );
266 application.SendNotification();
267 application.Render(0);
268 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION );
271 Constraint constraint = Constraint::New<Vector4>( renderer, colorIndex, TestConstraintNoBlue );
273 application.SendNotification();
274 application.Render(0);
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 );
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 );
290 int UtcDaliRendererConstraint02(void)
292 TestApplication application;
294 tet_infoline("Test that a uniform map renderer property can be constrained");
296 Shader shader = Shader::New("VertexSource", "FragmentSource");
297 Material material = Material::New( shader );
298 material.SetProperty(Material::Property::COLOR, Color::WHITE);
300 Geometry geometry = CreateQuadGeometry();
301 Renderer renderer = Renderer::New( geometry, material );
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);
310 Vector4 initialColor = Color::WHITE;
311 Property::Index colorIndex = renderer.RegisterProperty( "uFadeColor", initialColor );
313 TestGlAbstraction& gl = application.GetGlAbstraction();
315 application.SendNotification();
316 application.Render(0);
318 Vector4 actualValue(Vector4::ZERO);
319 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
320 DALI_TEST_EQUALS( actualValue, initialColor, TEST_LOCATION );
323 Constraint constraint = Constraint::New<Vector4>( renderer, colorIndex, TestConstraintNoBlue );
325 application.SendNotification();
326 application.Render(0);
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 );
332 application.Render(0);
333 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
334 DALI_TEST_EQUALS( actualValue, Color::YELLOW, TEST_LOCATION );
336 renderer.RemoveConstraints();
337 renderer.SetProperty(colorIndex, Color::WHITE );
338 application.SendNotification();
339 application.Render(0);
341 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
342 DALI_TEST_EQUALS( actualValue, Color::WHITE, TEST_LOCATION );
349 int UtcDaliRendererAnimatedProperty01(void)
351 TestApplication application;
353 tet_infoline("Test that a non-uniform renderer property can be animated");
355 Shader shader = Shader::New("VertexSource", "FragmentSource");
356 Material material = Material::New( shader );
357 material.SetProperty(Material::Property::COLOR, Color::WHITE);
359 Geometry geometry = CreateQuadGeometry();
360 Renderer renderer = Renderer::New( geometry, material );
362 Actor actor = Actor::New();
363 actor.AddRenderer(renderer);
364 actor.SetSize(400, 400);
365 Stage::GetCurrent().Add(actor);
367 Vector4 initialColor = Color::WHITE;
368 Property::Index colorIndex = renderer.RegisterProperty( "uFadeColor", initialColor );
370 application.SendNotification();
371 application.Render(0);
372 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION );
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 );
381 application.SendNotification();
382 application.Render(500);
384 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(colorIndex), Color::WHITE * 0.5f, TEST_LOCATION );
386 application.Render(500);
388 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(colorIndex), Color::TRANSPARENT, TEST_LOCATION );
393 int UtcDaliRendererAnimatedProperty02(void)
395 TestApplication application;
397 tet_infoline("Test that a uniform map renderer property can be animated");
399 Shader shader = Shader::New("VertexSource", "FragmentSource");
400 Material material = Material::New( shader );
401 material.SetProperty(Material::Property::COLOR, Color::WHITE);
403 Geometry geometry = CreateQuadGeometry();
404 Renderer renderer = Renderer::New( geometry, material );
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);
413 Vector4 initialColor = Color::WHITE;
414 Property::Index colorIndex = renderer.RegisterProperty( "uFadeColor", initialColor );
416 TestGlAbstraction& gl = application.GetGlAbstraction();
418 application.SendNotification();
419 application.Render(0);
421 Vector4 actualValue(Vector4::ZERO);
422 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
423 DALI_TEST_EQUALS( actualValue, initialColor, TEST_LOCATION );
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 );
432 application.SendNotification();
433 application.Render(500);
435 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
436 DALI_TEST_EQUALS( actualValue, Color::WHITE * 0.5f, TEST_LOCATION );
438 application.Render(500);
439 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
440 DALI_TEST_EQUALS( actualValue, Color::TRANSPARENT, TEST_LOCATION );
448 int UtcDaliRendererUniformMapPrecendence01(void)
450 TestApplication application;
452 tet_infoline("Test the uniform map precedence is applied properly");
454 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
455 Sampler sampler = Sampler::New(image, "sTexture");
456 sampler.SetUniformName( "sEffectTexture" );
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);
463 PropertyBuffer vertexBuffer = CreatePropertyBuffer();
464 Geometry geometry = CreateQuadGeometryFromBuffer(vertexBuffer);
465 Renderer renderer = Renderer::New( geometry, material );
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);
474 renderer.RegisterProperty( "uFadeColor", Color::RED );
476 actor.RegisterProperty( "uFadeColor", Color::GREEN );
478 Property::Index materialFadeColorIndex = material.RegisterProperty( "uFadeColor", Color::BLUE );
480 sampler.RegisterProperty( "uFadeColor", Color::CYAN );
481 shader.RegisterProperty( "uFadeColor", Color::MAGENTA );
483 geometry.RegisterProperty( "uFadeColor", Color::YELLOW );
485 vertexBuffer.RegisterProperty( "uFadeColor", Color::BLACK );
488 TestGlAbstraction& gl = application.GetGlAbstraction();
490 application.SendNotification();
491 application.Render(0);
493 // Expect that the actor'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::GREEN, TEST_LOCATION );
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 );
506 application.SendNotification();
507 application.Render(500);
509 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
510 DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
512 application.Render(500);
513 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
514 DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
519 int UtcDaliRendererUniformMapPrecendence02(void)
521 TestApplication application;
523 tet_infoline("Test the uniform map precedence is applied properly");
525 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
526 Sampler sampler = Sampler::New(image, "sTexture");
527 sampler.SetUniformName( "sEffectTexture" );
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);
534 PropertyBuffer vertexBuffer = CreatePropertyBuffer();
535 Geometry geometry = CreateQuadGeometryFromBuffer(vertexBuffer);
536 Renderer renderer = Renderer::New( geometry, material );
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);
545 // Don't add property / uniform map to renderer
547 actor.RegisterProperty( "uFadeColor", Color::GREEN );
549 Property::Index materialFadeColorIndex = material.RegisterProperty( "uFadeColor", Color::BLUE );
551 sampler.RegisterProperty( "uFadeColor", Color::CYAN );
552 shader.RegisterProperty( "uFadeColor", Color::MAGENTA );
554 geometry.RegisterProperty( "uFadeColor", Color::YELLOW );
556 vertexBuffer.RegisterProperty( "uFadeColor", Color::BLACK );
559 TestGlAbstraction& gl = application.GetGlAbstraction();
561 application.SendNotification();
562 application.Render(0);
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 );
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 );
577 application.SendNotification();
578 application.Render(500);
580 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
581 DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
583 application.Render(500);
584 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
585 DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
591 int UtcDaliRendererUniformMapPrecendence03(void)
593 TestApplication application;
595 tet_infoline("Test the uniform map precedence is applied properly");
597 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
598 Sampler sampler = Sampler::New(image, "sTexture");
599 sampler.SetUniformName( "sEffectTexture" );
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);
606 PropertyBuffer vertexBuffer = CreatePropertyBuffer();
607 Geometry geometry = CreateQuadGeometryFromBuffer(vertexBuffer);
608 Renderer renderer = Renderer::New( geometry, material );
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);
617 // Don't add property / uniform map to renderer or actor
619 material.RegisterProperty( "uFadeColor", Color::BLUE );
621 sampler.RegisterProperty( "uFadeColor", Color::CYAN );
622 shader.RegisterProperty( "uFadeColor", Color::MAGENTA );
624 Property::Index geometryFadeColorIndex = geometry.RegisterProperty( "uFadeColor", Color::YELLOW );
626 vertexBuffer.RegisterProperty( "uFadeColor", Color::BLACK );
629 TestGlAbstraction& gl = application.GetGlAbstraction();
631 application.SendNotification();
632 application.Render(0);
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 );
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 );
647 application.SendNotification();
648 application.Render(500);
650 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
651 DALI_TEST_EQUALS( actualValue, Color::BLUE, TEST_LOCATION );
653 application.Render(500);
654 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
655 DALI_TEST_EQUALS( actualValue, Color::BLUE, TEST_LOCATION );
661 int UtcDaliRendererUniformMapPrecendence04(void)
663 TestApplication application;
665 tet_infoline("Test the uniform map precedence is applied properly");
667 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
668 Sampler sampler = Sampler::New(image, "sTexture");
669 sampler.SetUniformName( "sEffectTexture" );
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);
676 PropertyBuffer vertexBuffer = CreatePropertyBuffer();
677 Geometry geometry = CreateQuadGeometryFromBuffer(vertexBuffer);
678 Renderer renderer = Renderer::New( geometry, material );
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);
687 // Don't add property / uniform map to renderer/actor/material
689 sampler.RegisterProperty( "uFadeColor", Color::CYAN );
690 shader.RegisterProperty( "uFadeColor", Color::MAGENTA );
692 Property::Index geometryFadeColorIndex = geometry.RegisterProperty( "uFadeColor", Color::YELLOW );
694 vertexBuffer.RegisterProperty( "uFadeColor", Color::BLACK );
697 TestGlAbstraction& gl = application.GetGlAbstraction();
699 application.SendNotification();
700 application.Render(0);
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 );
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 );
715 application.SendNotification();
716 application.Render(500);
718 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
719 DALI_TEST_EQUALS( actualValue, Color::CYAN, TEST_LOCATION );
721 application.Render(500);
722 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
723 DALI_TEST_EQUALS( actualValue, Color::CYAN, TEST_LOCATION );
728 int UtcDaliRendererUniformMapPrecendence05(void)
730 TestApplication application;
732 tet_infoline("Test the uniform map precedence is applied properly");
734 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
735 Sampler sampler = Sampler::New(image, "sTexture");
736 sampler.SetUniformName( "sEffectTexture" );
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);
743 PropertyBuffer vertexBuffer = CreatePropertyBuffer();
744 Geometry geometry = CreateQuadGeometryFromBuffer(vertexBuffer);
745 Renderer renderer = Renderer::New( geometry, material );
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);
754 // Don't add property / uniform map to renderer/actor/material/sampler
756 shader.RegisterProperty( "uFadeColor", Color::MAGENTA );
758 Property::Index geometryFadeColorIndex = geometry.RegisterProperty( "uFadeColor", Color::YELLOW );
760 vertexBuffer.RegisterProperty( "uFadeColor", Color::BLACK );
763 TestGlAbstraction& gl = application.GetGlAbstraction();
765 application.SendNotification();
766 application.Render(0);
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 );
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 );
781 application.SendNotification();
782 application.Render(500);
784 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
785 DALI_TEST_EQUALS( actualValue, Color::MAGENTA, TEST_LOCATION );
787 application.Render(500);
788 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
789 DALI_TEST_EQUALS( actualValue, Color::MAGENTA, TEST_LOCATION );
794 int UtcDaliRendererUniformMapPrecendence06(void)
796 TestApplication application;
798 tet_infoline("Test the uniform map precedence is applied properly");
800 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
801 Sampler sampler = Sampler::New(image, "sTexture");
802 sampler.SetUniformName( "sEffectTexture" );
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);
809 PropertyBuffer vertexBuffer = CreatePropertyBuffer();
810 Geometry geometry = CreateQuadGeometryFromBuffer(vertexBuffer);
811 Renderer renderer = Renderer::New( geometry, material );
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);
820 // Don't add property / uniform map to renderer/actor/material/sampler/shader
822 geometry.RegisterProperty( "uFadeColor", Color::YELLOW );
824 Property::Index vertexFadeColorIndex = vertexBuffer.RegisterProperty( "uFadeColor", Color::BLACK );
827 TestGlAbstraction& gl = application.GetGlAbstraction();
829 application.SendNotification();
830 application.Render(0);
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 );
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 );
845 application.SendNotification();
846 application.Render(500);
848 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
849 DALI_TEST_EQUALS( actualValue, Color::YELLOW, TEST_LOCATION );
851 application.Render(500);
852 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
853 DALI_TEST_EQUALS( actualValue, Color::YELLOW, TEST_LOCATION );
858 int UtcDaliRendererUniformMapPrecendence07(void)
860 TestApplication application;
862 tet_infoline("Test the uniform map precedence is applied properly");
864 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
865 Sampler sampler = Sampler::New(image, "sTexture");
866 sampler.SetUniformName( "sEffectTexture" );
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);
873 PropertyBuffer vertexBuffer = CreatePropertyBuffer();
874 Geometry geometry = CreateQuadGeometryFromBuffer(vertexBuffer);
875 Renderer renderer = Renderer::New( geometry, material );
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);
884 // Don't add property / uniform map to renderer/actor/material/sampler/shader/geometry
886 Property::Index vertexFadeColorIndex = vertexBuffer.RegisterProperty( "uFadeColor", Color::BLACK );
888 TestGlAbstraction& gl = application.GetGlAbstraction();
890 application.SendNotification();
891 application.Render(0);
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 );
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 );
906 application.SendNotification();
907 application.Render(500);
909 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
910 DALI_TEST_EQUALS( actualValue, Color::WHITE*0.5f, TEST_LOCATION );
912 application.Render(500);
913 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
914 DALI_TEST_EQUALS( actualValue, Color::TRANSPARENT, TEST_LOCATION );
920 int UtcDaliRendererUniformMapMultipleUniforms01(void)
922 TestApplication application;
924 tet_infoline("Test the uniform maps are collected from all objects (same type)");
926 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
927 Sampler sampler = Sampler::New(image, "sTexture");
928 sampler.SetUniformName( "sEffectTexture" );
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);
935 PropertyBuffer vertexBuffer = CreatePropertyBuffer();
936 Geometry geometry = CreateQuadGeometryFromBuffer(vertexBuffer);
937 Renderer renderer = Renderer::New( geometry, material );
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);
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 );
955 TestGlAbstraction& gl = application.GetGlAbstraction();
957 application.SendNotification();
958 application.Render(0);
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 );
965 Vector4 uniform2Value(Vector4::ZERO);
966 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uUniform2", uniform2Value ) );
967 DALI_TEST_EQUALS( uniform2Value, Color::GREEN, TEST_LOCATION );
969 Vector4 uniform3Value(Vector4::ZERO);
970 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uUniform3", uniform3Value ) );
971 DALI_TEST_EQUALS( uniform3Value, Color::BLUE, TEST_LOCATION );
973 Vector4 uniform4Value(Vector4::ZERO);
974 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uUniform4", uniform4Value ) );
975 DALI_TEST_EQUALS( uniform4Value, Color::CYAN, TEST_LOCATION );
977 Vector4 uniform5Value(Vector4::ZERO);
978 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uUniform5", uniform5Value ) );
979 DALI_TEST_EQUALS( uniform5Value, Color::MAGENTA, TEST_LOCATION );
981 Vector4 uniform6Value(Vector4::ZERO);
982 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uUniform6", uniform6Value ) );
983 DALI_TEST_EQUALS( uniform6Value, Color::YELLOW, TEST_LOCATION );
985 Vector4 uniform7Value(Vector4::ZERO);
986 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uUniform7", uniform7Value ) );
987 DALI_TEST_EQUALS( uniform7Value, Color::BLACK, TEST_LOCATION );
994 int UtcDaliRendererUniformMapMultipleUniforms02(void)
996 TestApplication application;
998 tet_infoline("Test the uniform maps are collected from all objects (different types)");
1000 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1001 Sampler sampler = Sampler::New(image, "sTexture");
1002 sampler.SetUniformName( "sEffectTexture" );
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);
1009 PropertyBuffer vertexBuffer = CreatePropertyBuffer();
1010 Geometry geometry = CreateQuadGeometryFromBuffer(vertexBuffer);
1011 Renderer renderer = Renderer::New( geometry, material );
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);
1020 Property::Value value1(Color::RED);
1021 renderer.RegisterProperty( "uFadeColor", value1 );
1023 Property::Value value2(1.0f);
1024 actor.RegisterProperty( "uFadeProgress", value2 );
1026 Property::Value value3(Vector3(0.5f, 0.5f, 1.0f));
1027 material.RegisterProperty( "uFadePosition", value3);
1029 Property::Value value4(Vector2(0.5f, 1.0f));
1030 sampler.RegisterProperty( "uFadeUV", value4 );
1032 Property::Value value5(Matrix3::IDENTITY);
1033 shader.RegisterProperty( "uANormalMatrix", value5 );
1035 Property::Value value6(Matrix::IDENTITY);
1036 geometry.RegisterProperty( "uAWorldMatrix", value6 );
1038 Property::Value value7(7);
1039 vertexBuffer.RegisterProperty( "uAnotherFadeColor", value7 );
1042 TestGlAbstraction& gl = application.GetGlAbstraction();
1044 application.SendNotification();
1045 application.Render(0);
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 );
1052 float uniform2Value(0.0f);
1053 DALI_TEST_CHECK( gl.GetUniformValue<float>( "uFadeProgress", uniform2Value ) );
1054 DALI_TEST_EQUALS( uniform2Value, value2.Get<float>(), TEST_LOCATION );
1056 Vector3 uniform3Value(Vector3::ZERO);
1057 DALI_TEST_CHECK( gl.GetUniformValue<Vector3>( "uFadePosition", uniform3Value ) );
1058 DALI_TEST_EQUALS( uniform3Value, value3.Get<Vector3>(), TEST_LOCATION );
1060 Vector2 uniform4Value(Vector2::ZERO);
1061 DALI_TEST_CHECK( gl.GetUniformValue<Vector2>( "uFadeUV", uniform4Value ) );
1062 DALI_TEST_EQUALS( uniform4Value, value4.Get<Vector2>(), TEST_LOCATION );
1064 Matrix3 uniform5Value;
1065 DALI_TEST_CHECK( gl.GetUniformValue<Matrix3>( "uANormalMatrix", uniform5Value ) );
1066 DALI_TEST_EQUALS( uniform5Value, value5.Get<Matrix3>(), TEST_LOCATION );
1068 Matrix uniform6Value;
1069 DALI_TEST_CHECK( gl.GetUniformValue<Matrix>( "uAWorldMatrix", uniform6Value ) );
1070 DALI_TEST_EQUALS( uniform6Value, value6.Get<Matrix>(), TEST_LOCATION );
1072 int uniform7Value = 0;
1073 DALI_TEST_CHECK( gl.GetUniformValue<int>( "uAnotherFadeColor", uniform7Value ) );
1074 DALI_TEST_EQUALS( uniform7Value, value7.Get<int>(), TEST_LOCATION );