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 UtcDaliRendererDownCast01(void)
66 TestApplication application;
68 Geometry geometry = CreateQuadGeometry();
69 Material material = CreateMaterial(1.0f);
70 Renderer renderer = Renderer::New(geometry, material);
72 BaseHandle handle(renderer);
73 Renderer renderer2 = Renderer::DownCast(handle);
74 DALI_TEST_EQUALS( (bool)renderer2, true, TEST_LOCATION );
78 int UtcDaliRendererDownCast02(void)
80 TestApplication application;
82 Handle handle = Handle::New(); // Create a custom object
83 Renderer renderer = Renderer::DownCast(handle);
84 DALI_TEST_EQUALS( (bool)renderer, false, TEST_LOCATION );
89 int UtcDaliRendererConstraint01(void)
91 TestApplication application;
93 tet_infoline("Test that a non-uniform renderer property can be constrained");
95 Shader shader = Shader::New("VertexSource", "FragmentSource");
96 Material material = Material::New( shader );
97 material.SetProperty(Material::Property::COLOR, Color::WHITE);
99 Geometry geometry = CreateQuadGeometry();
100 Renderer renderer = Renderer::New( geometry, material );
102 Actor actor = Actor::New();
103 actor.AddRenderer(renderer);
104 actor.SetSize(400, 400);
105 Stage::GetCurrent().Add(actor);
107 Vector4 initialColor = Color::WHITE;
108 Property::Index colorIndex = renderer.RegisterProperty( "fade-color", initialColor );
110 application.SendNotification();
111 application.Render(0);
112 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION );
115 Constraint constraint = Constraint::New<Vector4>( renderer, colorIndex, TestConstraintNoBlue );
117 application.SendNotification();
118 application.Render(0);
120 // Expect no blue component in either buffer - yellow
121 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(colorIndex), Color::YELLOW, TEST_LOCATION );
122 application.Render(0);
123 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(colorIndex), Color::YELLOW, TEST_LOCATION );
125 renderer.RemoveConstraints();
126 renderer.SetProperty(colorIndex, Color::WHITE );
127 application.SendNotification();
128 application.Render(0);
129 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(colorIndex), Color::WHITE, TEST_LOCATION );
134 int UtcDaliRendererConstraint02(void)
136 TestApplication application;
138 tet_infoline("Test that a uniform map renderer property can be constrained");
140 Shader shader = Shader::New("VertexSource", "FragmentSource");
141 Material material = Material::New( shader );
142 material.SetProperty(Material::Property::COLOR, Color::WHITE);
144 Geometry geometry = CreateQuadGeometry();
145 Renderer renderer = Renderer::New( geometry, material );
147 Actor actor = Actor::New();
148 actor.AddRenderer(renderer);
149 actor.SetSize(400, 400);
150 Stage::GetCurrent().Add(actor);
151 application.SendNotification();
152 application.Render(0);
154 Vector4 initialColor = Color::WHITE;
155 Property::Index colorIndex = renderer.RegisterProperty( "fade-color", initialColor );
156 renderer.AddUniformMapping( colorIndex, std::string("uFadeColor") );
158 TestGlAbstraction& gl = application.GetGlAbstraction();
160 application.SendNotification();
161 application.Render(0);
163 Vector4 actualValue(Vector4::ZERO);
164 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
165 DALI_TEST_EQUALS( actualValue, initialColor, TEST_LOCATION );
168 Constraint constraint = Constraint::New<Vector4>( renderer, colorIndex, TestConstraintNoBlue );
170 application.SendNotification();
171 application.Render(0);
173 // Expect no blue component in either buffer - yellow
174 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
175 DALI_TEST_EQUALS( actualValue, Color::YELLOW, TEST_LOCATION );
177 application.Render(0);
178 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
179 DALI_TEST_EQUALS( actualValue, Color::YELLOW, TEST_LOCATION );
181 renderer.RemoveConstraints();
182 renderer.SetProperty(colorIndex, Color::WHITE );
183 application.SendNotification();
184 application.Render(0);
186 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
187 DALI_TEST_EQUALS( actualValue, Color::WHITE, TEST_LOCATION );
194 int UtcDaliRendererAnimatedProperty01(void)
196 TestApplication application;
198 tet_infoline("Test that a non-uniform renderer property can be animated");
200 Shader shader = Shader::New("VertexSource", "FragmentSource");
201 Material material = Material::New( shader );
202 material.SetProperty(Material::Property::COLOR, Color::WHITE);
204 Geometry geometry = CreateQuadGeometry();
205 Renderer renderer = Renderer::New( geometry, material );
207 Actor actor = Actor::New();
208 actor.AddRenderer(renderer);
209 actor.SetSize(400, 400);
210 Stage::GetCurrent().Add(actor);
212 Vector4 initialColor = Color::WHITE;
213 Property::Index colorIndex = renderer.RegisterProperty( "fade-color", initialColor );
215 application.SendNotification();
216 application.Render(0);
217 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION );
219 Animation animation = Animation::New(1.0f);
220 KeyFrames keyFrames = KeyFrames::New();
221 keyFrames.Add(0.0f, initialColor);
222 keyFrames.Add(1.0f, Color::TRANSPARENT);
223 animation.AnimateBetween( Property( renderer, colorIndex ), keyFrames );
226 application.SendNotification();
227 application.Render(500);
229 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(colorIndex), Color::WHITE * 0.5f, TEST_LOCATION );
231 application.Render(500);
233 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(colorIndex), Color::TRANSPARENT, TEST_LOCATION );
238 int UtcDaliRendererAnimatedProperty02(void)
240 TestApplication application;
242 tet_infoline("Test that a uniform map renderer property can be animated");
244 Shader shader = Shader::New("VertexSource", "FragmentSource");
245 Material material = Material::New( shader );
246 material.SetProperty(Material::Property::COLOR, Color::WHITE);
248 Geometry geometry = CreateQuadGeometry();
249 Renderer renderer = Renderer::New( geometry, material );
251 Actor actor = Actor::New();
252 actor.AddRenderer(renderer);
253 actor.SetSize(400, 400);
254 Stage::GetCurrent().Add(actor);
255 application.SendNotification();
256 application.Render(0);
258 Vector4 initialColor = Color::WHITE;
259 Property::Index colorIndex = renderer.RegisterProperty( "fade-color", initialColor );
260 renderer.AddUniformMapping( colorIndex, std::string("uFadeColor") );
262 TestGlAbstraction& gl = application.GetGlAbstraction();
264 application.SendNotification();
265 application.Render(0);
267 Vector4 actualValue(Vector4::ZERO);
268 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
269 DALI_TEST_EQUALS( actualValue, initialColor, TEST_LOCATION );
271 Animation animation = Animation::New(1.0f);
272 KeyFrames keyFrames = KeyFrames::New();
273 keyFrames.Add(0.0f, initialColor);
274 keyFrames.Add(1.0f, Color::TRANSPARENT);
275 animation.AnimateBetween( Property( renderer, colorIndex ), keyFrames );
278 application.SendNotification();
279 application.Render(500);
281 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
282 DALI_TEST_EQUALS( actualValue, Color::WHITE * 0.5f, TEST_LOCATION );
284 application.Render(500);
285 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
286 DALI_TEST_EQUALS( actualValue, Color::TRANSPARENT, TEST_LOCATION );
294 int UtcDaliRendererUniformMapPrecendence01(void)
296 TestApplication application;
298 tet_infoline("Test the uniform map precedence is applied properly");
300 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
301 Sampler sampler = Sampler::New(image, "sTexture");
302 sampler.SetUniformName( "sEffectTexture" );
304 Shader shader = Shader::New("VertexSource", "FragmentSource");
305 Material material = Material::New( shader );
306 material.AddSampler( sampler );
307 material.SetProperty(Material::Property::COLOR, Color::WHITE);
309 PropertyBuffer vertexBuffer = CreatePropertyBuffer();
310 Geometry geometry = CreateQuadGeometryFromBuffer(vertexBuffer);
311 Renderer renderer = Renderer::New( geometry, material );
313 Actor actor = Actor::New();
314 actor.AddRenderer(renderer);
315 actor.SetSize(400, 400);
316 Stage::GetCurrent().Add(actor);
317 application.SendNotification();
318 application.Render(0);
320 Property::Index rendererFadeColorIndex = renderer.RegisterProperty( "fade-color-a", Color::RED );
321 renderer.AddUniformMapping( rendererFadeColorIndex, std::string("uFadeColor") );
323 Property::Index actorFadeColorIndex = actor.RegisterProperty( "fade-color-b", Color::GREEN );
324 actor.AddUniformMapping( actorFadeColorIndex, std::string("uFadeColor") );
326 Property::Index materialFadeColorIndex = material.RegisterProperty( "fade-color-c", Color::BLUE );
327 material.AddUniformMapping( materialFadeColorIndex, std::string("uFadeColor") );
329 Property::Index samplerFadeColorIndex = sampler.RegisterProperty( "fade-color-d", Color::CYAN );
330 sampler.AddUniformMapping( samplerFadeColorIndex, std::string("uFadeColor") );
331 Property::Index shaderFadeColorIndex = shader.RegisterProperty( "fade-color-e", Color::MAGENTA );
332 shader.AddUniformMapping( shaderFadeColorIndex, std::string("uFadeColor") );
334 Property::Index geometryFadeColorIndex = geometry.RegisterProperty( "fade-color-f", Color::YELLOW );
335 geometry.AddUniformMapping( geometryFadeColorIndex, std::string("uFadeColor") );
337 Property::Index vertexFadeColorIndex = vertexBuffer.RegisterProperty( "fade-color-g", Color::BLACK );
338 vertexBuffer.AddUniformMapping( vertexFadeColorIndex, std::string("uFadeColor") );
341 TestGlAbstraction& gl = application.GetGlAbstraction();
343 application.SendNotification();
344 application.Render(0);
346 // Expect that the renderer's fade color property is accessed
347 Vector4 actualValue(Vector4::ZERO);
348 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
349 DALI_TEST_EQUALS( actualValue, Color::RED, TEST_LOCATION );
351 // Animate material's fade color property. Should be no change to uniform
352 Animation animation = Animation::New(1.0f);
353 KeyFrames keyFrames = KeyFrames::New();
354 keyFrames.Add(0.0f, Color::WHITE);
355 keyFrames.Add(1.0f, Color::TRANSPARENT);
356 animation.AnimateBetween( Property( material, materialFadeColorIndex ), keyFrames );
359 application.SendNotification();
360 application.Render(500);
362 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
363 DALI_TEST_EQUALS( actualValue, Color::RED, TEST_LOCATION );
365 application.Render(500);
366 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
367 DALI_TEST_EQUALS( actualValue, Color::RED, TEST_LOCATION );
372 int UtcDaliRendererUniformMapPrecendence02(void)
374 TestApplication application;
376 tet_infoline("Test the uniform map precedence is applied properly");
378 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
379 Sampler sampler = Sampler::New(image, "sTexture");
380 sampler.SetUniformName( "sEffectTexture" );
382 Shader shader = Shader::New("VertexSource", "FragmentSource");
383 Material material = Material::New( shader );
384 material.AddSampler( sampler );
385 material.SetProperty(Material::Property::COLOR, Color::WHITE);
387 PropertyBuffer vertexBuffer = CreatePropertyBuffer();
388 Geometry geometry = CreateQuadGeometryFromBuffer(vertexBuffer);
389 Renderer renderer = Renderer::New( geometry, material );
391 Actor actor = Actor::New();
392 actor.AddRenderer(renderer);
393 actor.SetSize(400, 400);
394 Stage::GetCurrent().Add(actor);
395 application.SendNotification();
396 application.Render(0);
398 // Don't add property / uniform map to renderer
400 Property::Index actorFadeColorIndex = actor.RegisterProperty( "fade-color-b", Color::GREEN );
401 actor.AddUniformMapping( actorFadeColorIndex, std::string("uFadeColor") );
403 Property::Index materialFadeColorIndex = material.RegisterProperty( "fade-color-c", Color::BLUE );
404 material.AddUniformMapping( materialFadeColorIndex, std::string("uFadeColor") );
406 Property::Index samplerFadeColorIndex = sampler.RegisterProperty( "fade-color-d", Color::CYAN );
407 sampler.AddUniformMapping( samplerFadeColorIndex, std::string("uFadeColor") );
408 Property::Index shaderFadeColorIndex = shader.RegisterProperty( "fade-color-e", Color::MAGENTA );
409 shader.AddUniformMapping( shaderFadeColorIndex, std::string("uFadeColor") );
411 Property::Index geometryFadeColorIndex = geometry.RegisterProperty( "fade-color-f", Color::YELLOW );
412 geometry.AddUniformMapping( geometryFadeColorIndex, std::string("uFadeColor") );
414 Property::Index vertexFadeColorIndex = vertexBuffer.RegisterProperty( "fade-color-g", Color::BLACK );
415 vertexBuffer.AddUniformMapping( vertexFadeColorIndex, std::string("uFadeColor") );
418 TestGlAbstraction& gl = application.GetGlAbstraction();
420 application.SendNotification();
421 application.Render(0);
423 // Expect that the actor's fade color property is accessed
424 Vector4 actualValue(Vector4::ZERO);
425 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
426 DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
428 // Animate material's fade color property. Should be no change to uniform
429 Animation animation = Animation::New(1.0f);
430 KeyFrames keyFrames = KeyFrames::New();
431 keyFrames.Add(0.0f, Color::WHITE);
432 keyFrames.Add(1.0f, Color::TRANSPARENT);
433 animation.AnimateBetween( Property( material, materialFadeColorIndex ), keyFrames );
436 application.SendNotification();
437 application.Render(500);
439 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
440 DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
442 application.Render(500);
443 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
444 DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
450 int UtcDaliRendererUniformMapPrecendence03(void)
452 TestApplication application;
454 tet_infoline("Test the uniform map precedence is applied properly");
456 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
457 Sampler sampler = Sampler::New(image, "sTexture");
458 sampler.SetUniformName( "sEffectTexture" );
460 Shader shader = Shader::New("VertexSource", "FragmentSource");
461 Material material = Material::New( shader );
462 material.AddSampler( sampler );
463 material.SetProperty(Material::Property::COLOR, Color::WHITE);
465 PropertyBuffer vertexBuffer = CreatePropertyBuffer();
466 Geometry geometry = CreateQuadGeometryFromBuffer(vertexBuffer);
467 Renderer renderer = Renderer::New( geometry, material );
469 Actor actor = Actor::New();
470 actor.AddRenderer(renderer);
471 actor.SetSize(400, 400);
472 Stage::GetCurrent().Add(actor);
473 application.SendNotification();
474 application.Render(0);
476 // Don't add property / uniform map to renderer or actor
478 Property::Index materialFadeColorIndex = material.RegisterProperty( "fade-color-c", Color::BLUE );
479 material.AddUniformMapping( materialFadeColorIndex, std::string("uFadeColor") );
481 Property::Index samplerFadeColorIndex = sampler.RegisterProperty( "fade-color-d", Color::CYAN );
482 sampler.AddUniformMapping( samplerFadeColorIndex, std::string("uFadeColor") );
483 Property::Index shaderFadeColorIndex = shader.RegisterProperty( "fade-color-e", Color::MAGENTA );
484 shader.AddUniformMapping( shaderFadeColorIndex, std::string("uFadeColor") );
486 Property::Index geometryFadeColorIndex = geometry.RegisterProperty( "fade-color-f", Color::YELLOW );
487 geometry.AddUniformMapping( geometryFadeColorIndex, std::string("uFadeColor") );
489 Property::Index vertexFadeColorIndex = vertexBuffer.RegisterProperty( "fade-color-g", Color::BLACK );
490 vertexBuffer.AddUniformMapping( vertexFadeColorIndex, std::string("uFadeColor") );
493 TestGlAbstraction& gl = application.GetGlAbstraction();
495 application.SendNotification();
496 application.Render(0);
498 // Expect that the material's fade color property is accessed
499 Vector4 actualValue(Vector4::ZERO);
500 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
501 DALI_TEST_EQUALS( actualValue, Color::BLUE, TEST_LOCATION );
503 // Animate geometry's fade color property. Should be no change to uniform
504 Animation animation = Animation::New(1.0f);
505 KeyFrames keyFrames = KeyFrames::New();
506 keyFrames.Add(0.0f, Color::WHITE);
507 keyFrames.Add(1.0f, Color::TRANSPARENT);
508 animation.AnimateBetween( Property( geometry, geometryFadeColorIndex ), keyFrames );
511 application.SendNotification();
512 application.Render(500);
514 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
515 DALI_TEST_EQUALS( actualValue, Color::BLUE, TEST_LOCATION );
517 application.Render(500);
518 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
519 DALI_TEST_EQUALS( actualValue, Color::BLUE, TEST_LOCATION );
525 int UtcDaliRendererUniformMapPrecendence04(void)
527 TestApplication application;
529 tet_infoline("Test the uniform map precedence is applied properly");
531 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
532 Sampler sampler = Sampler::New(image, "sTexture");
533 sampler.SetUniformName( "sEffectTexture" );
535 Shader shader = Shader::New("VertexSource", "FragmentSource");
536 Material material = Material::New( shader );
537 material.AddSampler( sampler );
538 material.SetProperty(Material::Property::COLOR, Color::WHITE);
540 PropertyBuffer vertexBuffer = CreatePropertyBuffer();
541 Geometry geometry = CreateQuadGeometryFromBuffer(vertexBuffer);
542 Renderer renderer = Renderer::New( geometry, material );
544 Actor actor = Actor::New();
545 actor.AddRenderer(renderer);
546 actor.SetSize(400, 400);
547 Stage::GetCurrent().Add(actor);
548 application.SendNotification();
549 application.Render(0);
551 // Don't add property / uniform map to renderer/actor/material
553 Property::Index samplerFadeColorIndex = sampler.RegisterProperty( "fade-color-d", Color::CYAN );
554 sampler.AddUniformMapping( samplerFadeColorIndex, std::string("uFadeColor") );
555 Property::Index shaderFadeColorIndex = shader.RegisterProperty( "fade-color-e", Color::MAGENTA );
556 shader.AddUniformMapping( shaderFadeColorIndex, std::string("uFadeColor") );
558 Property::Index geometryFadeColorIndex = geometry.RegisterProperty( "fade-color-f", Color::YELLOW );
559 geometry.AddUniformMapping( geometryFadeColorIndex, std::string("uFadeColor") );
561 Property::Index vertexFadeColorIndex = vertexBuffer.RegisterProperty( "fade-color-g", Color::BLACK );
562 vertexBuffer.AddUniformMapping( vertexFadeColorIndex, std::string("uFadeColor") );
565 TestGlAbstraction& gl = application.GetGlAbstraction();
567 application.SendNotification();
568 application.Render(0);
570 // Expect that the sampler's fade color property is accessed
571 Vector4 actualValue(Vector4::ZERO);
572 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
573 DALI_TEST_EQUALS( actualValue, Color::CYAN, TEST_LOCATION );
575 // Animate geometry's fade color property. Should be no change to uniform
576 Animation animation = Animation::New(1.0f);
577 KeyFrames keyFrames = KeyFrames::New();
578 keyFrames.Add(0.0f, Color::WHITE);
579 keyFrames.Add(1.0f, Color::TRANSPARENT);
580 animation.AnimateBetween( Property( geometry, geometryFadeColorIndex ), keyFrames );
583 application.SendNotification();
584 application.Render(500);
586 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
587 DALI_TEST_EQUALS( actualValue, Color::CYAN, TEST_LOCATION );
589 application.Render(500);
590 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
591 DALI_TEST_EQUALS( actualValue, Color::CYAN, TEST_LOCATION );
596 int UtcDaliRendererUniformMapPrecendence05(void)
598 TestApplication application;
600 tet_infoline("Test the uniform map precedence is applied properly");
602 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
603 Sampler sampler = Sampler::New(image, "sTexture");
604 sampler.SetUniformName( "sEffectTexture" );
606 Shader shader = Shader::New("VertexSource", "FragmentSource");
607 Material material = Material::New( shader );
608 material.AddSampler( sampler );
609 material.SetProperty(Material::Property::COLOR, Color::WHITE);
611 PropertyBuffer vertexBuffer = CreatePropertyBuffer();
612 Geometry geometry = CreateQuadGeometryFromBuffer(vertexBuffer);
613 Renderer renderer = Renderer::New( geometry, material );
615 Actor actor = Actor::New();
616 actor.AddRenderer(renderer);
617 actor.SetSize(400, 400);
618 Stage::GetCurrent().Add(actor);
619 application.SendNotification();
620 application.Render(0);
622 // Don't add property / uniform map to renderer/actor/material/sampler
624 Property::Index shaderFadeColorIndex = shader.RegisterProperty( "fade-color-e", Color::MAGENTA );
625 shader.AddUniformMapping( shaderFadeColorIndex, std::string("uFadeColor") );
627 Property::Index geometryFadeColorIndex = geometry.RegisterProperty( "fade-color-f", Color::YELLOW );
628 geometry.AddUniformMapping( geometryFadeColorIndex, std::string("uFadeColor") );
630 Property::Index vertexFadeColorIndex = vertexBuffer.RegisterProperty( "fade-color-g", Color::BLACK );
631 vertexBuffer.AddUniformMapping( vertexFadeColorIndex, std::string("uFadeColor") );
634 TestGlAbstraction& gl = application.GetGlAbstraction();
636 application.SendNotification();
637 application.Render(0);
639 // Expect that the shader's fade color property is accessed
640 Vector4 actualValue(Vector4::ZERO);
641 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
642 DALI_TEST_EQUALS( actualValue, Color::MAGENTA, TEST_LOCATION );
644 // Animate geometry's fade color property. Should be no change to uniform
645 Animation animation = Animation::New(1.0f);
646 KeyFrames keyFrames = KeyFrames::New();
647 keyFrames.Add(0.0f, Color::WHITE);
648 keyFrames.Add(1.0f, Color::TRANSPARENT);
649 animation.AnimateBetween( Property( geometry, geometryFadeColorIndex ), keyFrames );
652 application.SendNotification();
653 application.Render(500);
655 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
656 DALI_TEST_EQUALS( actualValue, Color::MAGENTA, TEST_LOCATION );
658 application.Render(500);
659 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
660 DALI_TEST_EQUALS( actualValue, Color::MAGENTA, TEST_LOCATION );
665 int UtcDaliRendererUniformMapPrecendence06(void)
667 TestApplication application;
669 tet_infoline("Test the uniform map precedence is applied properly");
671 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
672 Sampler sampler = Sampler::New(image, "sTexture");
673 sampler.SetUniformName( "sEffectTexture" );
675 Shader shader = Shader::New("VertexSource", "FragmentSource");
676 Material material = Material::New( shader );
677 material.AddSampler( sampler );
678 material.SetProperty(Material::Property::COLOR, Color::WHITE);
680 PropertyBuffer vertexBuffer = CreatePropertyBuffer();
681 Geometry geometry = CreateQuadGeometryFromBuffer(vertexBuffer);
682 Renderer renderer = Renderer::New( geometry, material );
684 Actor actor = Actor::New();
685 actor.AddRenderer(renderer);
686 actor.SetSize(400, 400);
687 Stage::GetCurrent().Add(actor);
688 application.SendNotification();
689 application.Render(0);
691 // Don't add property / uniform map to renderer/actor/material/sampler/shader
693 Property::Index geometryFadeColorIndex = geometry.RegisterProperty( "fade-color-f", Color::YELLOW );
694 geometry.AddUniformMapping( geometryFadeColorIndex, std::string("uFadeColor") );
696 Property::Index vertexFadeColorIndex = vertexBuffer.RegisterProperty( "fade-color-g", Color::BLACK );
697 vertexBuffer.AddUniformMapping( vertexFadeColorIndex, std::string("uFadeColor") );
700 TestGlAbstraction& gl = application.GetGlAbstraction();
702 application.SendNotification();
703 application.Render(0);
705 // Expect that the geometry's fade color property is accessed
706 Vector4 actualValue(Vector4::ZERO);
707 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
708 DALI_TEST_EQUALS( actualValue, Color::YELLOW, TEST_LOCATION );
710 // Animate vertex buffer's fade color property. Should be no change to uniform
711 Animation animation = Animation::New(1.0f);
712 KeyFrames keyFrames = KeyFrames::New();
713 keyFrames.Add(0.0f, Color::WHITE);
714 keyFrames.Add(1.0f, Color::TRANSPARENT);
715 animation.AnimateBetween( Property( vertexBuffer, vertexFadeColorIndex ), keyFrames );
718 application.SendNotification();
719 application.Render(500);
721 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
722 DALI_TEST_EQUALS( actualValue, Color::YELLOW, TEST_LOCATION );
724 application.Render(500);
725 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
726 DALI_TEST_EQUALS( actualValue, Color::YELLOW, TEST_LOCATION );
731 int UtcDaliRendererUniformMapPrecendence07(void)
733 TestApplication application;
735 tet_infoline("Test the uniform map precedence is applied properly");
737 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
738 Sampler sampler = Sampler::New(image, "sTexture");
739 sampler.SetUniformName( "sEffectTexture" );
741 Shader shader = Shader::New("VertexSource", "FragmentSource");
742 Material material = Material::New( shader );
743 material.AddSampler( sampler );
744 material.SetProperty(Material::Property::COLOR, Color::WHITE);
746 PropertyBuffer vertexBuffer = CreatePropertyBuffer();
747 Geometry geometry = CreateQuadGeometryFromBuffer(vertexBuffer);
748 Renderer renderer = Renderer::New( geometry, material );
750 Actor actor = Actor::New();
751 actor.AddRenderer(renderer);
752 actor.SetSize(400, 400);
753 Stage::GetCurrent().Add(actor);
754 application.SendNotification();
755 application.Render(0);
757 // Don't add property / uniform map to renderer/actor/material/sampler/shader/geometry
759 Property::Index vertexFadeColorIndex = vertexBuffer.RegisterProperty( "fade-color-g", Color::BLACK );
760 vertexBuffer.AddUniformMapping( vertexFadeColorIndex, std::string("uFadeColor") );
762 TestGlAbstraction& gl = application.GetGlAbstraction();
764 application.SendNotification();
765 application.Render(0);
767 // Expect that the vertex buffer's fade color property is accessed
768 Vector4 actualValue(Vector4::ZERO);
769 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
770 DALI_TEST_EQUALS( actualValue, Color::BLACK, TEST_LOCATION );
772 // Animate vertex buffer's fade color property. Should change the uniform
773 Animation animation = Animation::New(1.0f);
774 KeyFrames keyFrames = KeyFrames::New();
775 keyFrames.Add(0.0f, Color::WHITE);
776 keyFrames.Add(1.0f, Color::TRANSPARENT);
777 animation.AnimateBetween( Property( vertexBuffer, vertexFadeColorIndex ), keyFrames );
780 application.SendNotification();
781 application.Render(500);
783 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
784 DALI_TEST_EQUALS( actualValue, Color::WHITE*0.5f, TEST_LOCATION );
786 application.Render(500);
787 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
788 DALI_TEST_EQUALS( actualValue, Color::TRANSPARENT, TEST_LOCATION );
794 int UtcDaliRendererUniformMapMultipleUniforms01(void)
796 TestApplication application;
798 tet_infoline("Test the uniform maps are collected from all objects (same type)");
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 Property::Index rendererFadeColorIndex = renderer.RegisterProperty( "fade-color", Color::RED );
821 renderer.AddUniformMapping( rendererFadeColorIndex, std::string("uUniform1") );
823 Property::Index actorFadeColorIndex = actor.RegisterProperty( "fade-color", Color::GREEN );
824 actor.AddUniformMapping( actorFadeColorIndex, std::string("uUniform2") );
826 Property::Index materialFadeColorIndex = material.RegisterProperty( "fade-color", Color::BLUE );
827 material.AddUniformMapping( materialFadeColorIndex, std::string("uUniform3") );
829 Property::Index samplerFadeColorIndex = sampler.RegisterProperty( "fade-color", Color::CYAN );
830 sampler.AddUniformMapping( samplerFadeColorIndex, std::string("uUniform4") );
831 Property::Index shaderFadeColorIndex = shader.RegisterProperty( "fade-color", Color::MAGENTA );
832 shader.AddUniformMapping( shaderFadeColorIndex, std::string("uUniform5") );
834 Property::Index geometryFadeColorIndex = geometry.RegisterProperty( "fade-color", Color::YELLOW );
835 geometry.AddUniformMapping( geometryFadeColorIndex, std::string("uUniform6") );
837 Property::Index vertexFadeColorIndex = vertexBuffer.RegisterProperty( "fade-color", Color::BLACK );
838 vertexBuffer.AddUniformMapping( vertexFadeColorIndex, std::string("uUniform7") );
841 TestGlAbstraction& gl = application.GetGlAbstraction();
843 application.SendNotification();
844 application.Render(0);
846 // Expect that each of the object's uniforms are set
847 Vector4 uniform1Value(Vector4::ZERO);
848 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uUniform1", uniform1Value ) );
849 DALI_TEST_EQUALS( uniform1Value, Color::RED, TEST_LOCATION );
851 Vector4 uniform2Value(Vector4::ZERO);
852 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uUniform2", uniform2Value ) );
853 DALI_TEST_EQUALS( uniform2Value, Color::GREEN, TEST_LOCATION );
855 Vector4 uniform3Value(Vector4::ZERO);
856 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uUniform3", uniform3Value ) );
857 DALI_TEST_EQUALS( uniform3Value, Color::BLUE, TEST_LOCATION );
859 Vector4 uniform4Value(Vector4::ZERO);
860 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uUniform4", uniform4Value ) );
861 DALI_TEST_EQUALS( uniform4Value, Color::CYAN, TEST_LOCATION );
863 Vector4 uniform5Value(Vector4::ZERO);
864 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uUniform5", uniform5Value ) );
865 DALI_TEST_EQUALS( uniform5Value, Color::MAGENTA, TEST_LOCATION );
867 Vector4 uniform6Value(Vector4::ZERO);
868 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uUniform6", uniform6Value ) );
869 DALI_TEST_EQUALS( uniform6Value, Color::YELLOW, TEST_LOCATION );
871 Vector4 uniform7Value(Vector4::ZERO);
872 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uUniform7", uniform7Value ) );
873 DALI_TEST_EQUALS( uniform7Value, Color::BLACK, TEST_LOCATION );
880 int UtcDaliRendererUniformMapMultipleUniforms02(void)
882 TestApplication application;
884 tet_infoline("Test the uniform maps are collected from all objects (different types)");
886 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
887 Sampler sampler = Sampler::New(image, "sTexture");
888 sampler.SetUniformName( "sEffectTexture" );
890 Shader shader = Shader::New("VertexSource", "FragmentSource");
891 Material material = Material::New( shader );
892 material.AddSampler( sampler );
893 material.SetProperty(Material::Property::COLOR, Color::WHITE);
895 PropertyBuffer vertexBuffer = CreatePropertyBuffer();
896 Geometry geometry = CreateQuadGeometryFromBuffer(vertexBuffer);
897 Renderer renderer = Renderer::New( geometry, material );
899 Actor actor = Actor::New();
900 actor.AddRenderer(renderer);
901 actor.SetSize(400, 400);
902 Stage::GetCurrent().Add(actor);
903 application.SendNotification();
904 application.Render(0);
906 Property::Value value1(Color::RED);
907 Property::Index rendererIndex = renderer.RegisterProperty( "fade-color", value1 );
908 renderer.AddUniformMapping( rendererIndex, std::string("uUniform1") );
910 Property::Value value2(1.0f);
911 Property::Index actorIndex = actor.RegisterProperty( "fade-progress", value2 );
912 actor.AddUniformMapping( actorIndex, std::string("uUniform2") );
914 Property::Value value3(Vector3(0.5f, 0.5f, 1.0f));
915 Property::Index materialIndex = material.RegisterProperty( "fade-position", value3);
916 material.AddUniformMapping( materialIndex, std::string("uUniform3") );
918 Property::Value value4(Vector2(0.5f, 1.0f));
919 Property::Index samplerIndex = sampler.RegisterProperty( "fade-uv", value4 );
920 sampler.AddUniformMapping( samplerIndex, std::string("uUniform4") );
922 Property::Value value5(Matrix3::IDENTITY);
923 Property::Index shaderIndex = shader.RegisterProperty( "a-normal-matrix", value5 );
924 shader.AddUniformMapping( shaderIndex, std::string("uUniform5") );
926 Property::Value value6(Matrix::IDENTITY);
927 Property::Index geometryIndex = geometry.RegisterProperty( "a-world-matrix", value6 );
928 geometry.AddUniformMapping( geometryIndex, std::string("uUniform6") );
930 Property::Value value7(7);
931 Property::Index vertexIndex = vertexBuffer.RegisterProperty( "fade-color", value7 );
932 vertexBuffer.AddUniformMapping( vertexIndex, std::string("uUniform7") );
935 TestGlAbstraction& gl = application.GetGlAbstraction();
937 application.SendNotification();
938 application.Render(0);
940 // Expect that each of the object's uniforms are set
941 Vector4 uniform1Value(Vector4::ZERO);
942 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uUniform1", uniform1Value ) );
943 DALI_TEST_EQUALS( uniform1Value, value1.Get<Vector4>(), TEST_LOCATION );
945 float uniform2Value(0.0f);
946 DALI_TEST_CHECK( gl.GetUniformValue<float>( "uUniform2", uniform2Value ) );
947 DALI_TEST_EQUALS( uniform2Value, value2.Get<float>(), TEST_LOCATION );
949 Vector3 uniform3Value(Vector3::ZERO);
950 DALI_TEST_CHECK( gl.GetUniformValue<Vector3>( "uUniform3", uniform3Value ) );
951 DALI_TEST_EQUALS( uniform3Value, value3.Get<Vector3>(), TEST_LOCATION );
953 Vector2 uniform4Value(Vector2::ZERO);
954 DALI_TEST_CHECK( gl.GetUniformValue<Vector2>( "uUniform4", uniform4Value ) );
955 DALI_TEST_EQUALS( uniform4Value, value4.Get<Vector2>(), TEST_LOCATION );
957 Matrix3 uniform5Value;
958 DALI_TEST_CHECK( gl.GetUniformValue<Matrix3>( "uUniform5", uniform5Value ) );
959 DALI_TEST_EQUALS( uniform5Value, value5.Get<Matrix3>(), TEST_LOCATION );
961 Matrix uniform6Value;
962 DALI_TEST_CHECK( gl.GetUniformValue<Matrix>( "uUniform6", uniform6Value ) );
963 DALI_TEST_EQUALS( uniform6Value, value6.Get<Matrix>(), TEST_LOCATION );
965 int uniform7Value = 0;
966 DALI_TEST_CHECK( gl.GetUniformValue<int>( "uUniform7", uniform7Value ) );
967 DALI_TEST_EQUALS( uniform7Value, value7.Get<int>(), TEST_LOCATION );