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>
25 #include <mesh-builder.h>
29 void TestConstraintNoBlue( Vector4& current, const PropertyInputContainer& inputs )
35 void renderer_test_startup(void)
37 test_return_value = TET_UNDEF;
40 void renderer_test_cleanup(void)
42 test_return_value = TET_PASS;
46 int UtcDaliRendererNew01(void)
48 TestApplication application;
50 Geometry geometry = CreateQuadGeometry();
51 Shader shader = CreateShader();
52 Renderer renderer = Renderer::New(geometry, shader);
54 DALI_TEST_EQUALS( (bool)renderer, true, TEST_LOCATION );
58 int UtcDaliRendererNew02(void)
60 TestApplication application;
62 DALI_TEST_EQUALS( (bool)renderer, false, TEST_LOCATION );
66 int UtcDaliRendererCopyConstructor(void)
68 TestApplication application;
70 Geometry geometry = CreateQuadGeometry();
71 Shader shader = CreateShader();
72 Renderer renderer = Renderer::New(geometry, shader);
74 Renderer rendererCopy( renderer );
75 DALI_TEST_EQUALS( (bool)rendererCopy, true, TEST_LOCATION );
80 int UtcDaliRendererAssignmentOperator(void)
82 TestApplication application;
84 Geometry geometry = CreateQuadGeometry();
85 Shader shader = CreateShader();
86 Renderer renderer = Renderer::New(geometry, shader);
89 DALI_TEST_EQUALS( (bool)renderer2, false, TEST_LOCATION );
92 DALI_TEST_EQUALS( (bool)renderer2, true, TEST_LOCATION );
96 int UtcDaliRendererDownCast01(void)
98 TestApplication application;
100 Geometry geometry = CreateQuadGeometry();
101 Shader shader = CreateShader();
102 Renderer renderer = Renderer::New(geometry, shader);
104 BaseHandle handle(renderer);
105 Renderer renderer2 = Renderer::DownCast(handle);
106 DALI_TEST_EQUALS( (bool)renderer2, true, TEST_LOCATION );
110 int UtcDaliRendererDownCast02(void)
112 TestApplication application;
114 Handle handle = Handle::New(); // Create a custom object
115 Renderer renderer = Renderer::DownCast(handle);
116 DALI_TEST_EQUALS( (bool)renderer, false, TEST_LOCATION );
120 int UtcDaliRendererSetGetGeometry(void)
122 TestApplication application;
123 tet_infoline( "Test SetGeometry, GetGeometry" );
125 Geometry geometry1 = CreateQuadGeometry();
126 geometry1.RegisterProperty( "uFadeColor", Color::RED );
128 Geometry geometry2 = CreateQuadGeometry();
129 geometry2.RegisterProperty( "uFadeColor", Color::GREEN );
131 Shader shader = CreateShader();
132 Renderer renderer = Renderer::New(geometry1, shader);
133 Actor actor = Actor::New();
134 actor.AddRenderer(renderer);
135 actor.SetSize(400, 400);
136 Stage::GetCurrent().Add(actor);
138 TestGlAbstraction& gl = application.GetGlAbstraction();
139 application.SendNotification();
140 application.Render(0);
142 // Expect that the first geometry's fade color property is accessed
143 Vector4 actualValue(Vector4::ZERO);
144 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
145 DALI_TEST_EQUALS( actualValue, Color::RED, TEST_LOCATION );
147 DALI_TEST_EQUALS( renderer.GetGeometry(), geometry1, TEST_LOCATION );
149 // Set geometry2 to the renderer
150 renderer.SetGeometry( geometry2 );
152 application.SendNotification();
153 application.Render(0);
155 // Expect that the second geometry's fade color property is accessed
156 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
157 DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
159 DALI_TEST_EQUALS( renderer.GetGeometry(), geometry2, TEST_LOCATION );
164 int UtcDaliRendererSetGetShader(void)
166 TestApplication application;
167 tet_infoline( "Test SetShader, GetShader" );
169 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
170 glAbstraction.EnableCullFaceCallTrace(true);
172 Shader shader1 = CreateShader();
173 shader1.RegisterProperty( "uFadeColor", Color::RED );
175 Shader shader2 = CreateShader();
176 shader2.RegisterProperty( "uFadeColor", Color::GREEN );
178 Geometry geometry = CreateQuadGeometry();
179 Renderer renderer = Renderer::New(geometry, shader1);
180 Actor actor = Actor::New();
181 actor.AddRenderer(renderer);
182 actor.SetSize(400, 400);
183 Stage::GetCurrent().Add(actor);
185 TestGlAbstraction& gl = application.GetGlAbstraction();
186 application.SendNotification();
187 application.Render(0);
189 // Expect that the first shaders's fade color property is accessed
190 Vector4 actualValue(Vector4::ZERO);
191 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
192 DALI_TEST_EQUALS( actualValue, Color::RED, TEST_LOCATION );
194 DALI_TEST_EQUALS( renderer.GetShader(), shader1, TEST_LOCATION );
196 // set the second shader to the renderer
197 renderer.SetShader( shader2 );
199 application.SendNotification();
200 application.Render(0);
202 // Expect that the second shader's fade color property is accessed
203 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
204 DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
206 DALI_TEST_EQUALS( renderer.GetShader(), shader2, TEST_LOCATION );
211 int UtcDaliRendererSetGetDepthIndex(void)
213 TestApplication application;
215 tet_infoline("Test SetDepthIndex, GetDepthIndex");
217 Shader shader = CreateShader();
218 Geometry geometry = CreateQuadGeometry();
219 Renderer renderer = Renderer::New(geometry, shader);
220 Actor actor = Actor::New();
221 actor.AddRenderer(renderer);
222 actor.SetSize(400, 400);
223 Stage::GetCurrent().Add(actor);
225 application.SendNotification();
226 application.Render(0);
227 DALI_TEST_EQUALS( renderer.GetProperty<int>(Renderer::Property::DEPTH_INDEX), 0, TEST_LOCATION );
229 renderer.SetProperty( Renderer::Property::DEPTH_INDEX, 1 );
231 application.SendNotification();
232 application.Render(0);
233 DALI_TEST_EQUALS( renderer.GetProperty<int>(Renderer::Property::DEPTH_INDEX), 1, TEST_LOCATION );
235 renderer.SetProperty( Renderer::Property::DEPTH_INDEX, 10 );
237 application.SendNotification();
238 application.Render(0);
239 DALI_TEST_EQUALS( renderer.GetProperty<int>(Renderer::Property::DEPTH_INDEX), 10, TEST_LOCATION );
244 int UtcDaliRendererSetGetFaceCullingMode(void)
246 TestApplication application;
248 tet_infoline("Test SetFaceCullingMode(cullingMode)");
249 Geometry geometry = CreateQuadGeometry();
250 Shader shader = CreateShader();
251 Renderer renderer = Renderer::New( geometry, shader );
253 Actor actor = Actor::New();
254 actor.AddRenderer(renderer);
255 actor.SetSize(400, 400);
256 Stage::GetCurrent().Add(actor);
258 // By default, none of the faces should be culled
259 unsigned int cullFace = renderer.GetProperty<int>( Renderer::Property::FACE_CULLING_MODE );
260 DALI_TEST_CHECK( static_cast< Dali::Renderer::FaceCullingMode >( cullFace ) == Renderer::NONE );
262 TestGlAbstraction& gl = application.GetGlAbstraction();
263 TraceCallStack& cullFaceStack = gl.GetCullFaceTrace();
264 gl.EnableCullFaceCallTrace(true);
267 cullFaceStack.Reset();
268 renderer.SetProperty( Renderer::Property::FACE_CULLING_MODE, Renderer::CULL_BACK_AND_FRONT );
269 application.SendNotification();
270 application.Render();
272 DALI_TEST_EQUALS( cullFaceStack.CountMethod( "CullFace" ), 1, TEST_LOCATION );
274 std::ostringstream cullModeString;
275 cullModeString << GL_FRONT_AND_BACK;
277 DALI_TEST_CHECK( cullFaceStack.FindMethodAndParams( "CullFace", cullModeString.str() ) );
278 cullFace = renderer.GetProperty<int>( Renderer::Property::FACE_CULLING_MODE );
279 DALI_TEST_CHECK( static_cast< Dali::Renderer::FaceCullingMode >( cullFace ) == Renderer::CULL_BACK_AND_FRONT);
283 cullFaceStack.Reset();
284 renderer.SetProperty( Renderer::Property::FACE_CULLING_MODE, Renderer::CULL_BACK );
285 application.SendNotification();
286 application.Render();
288 DALI_TEST_EQUALS( cullFaceStack.CountMethod( "CullFace" ), 1, TEST_LOCATION );
290 std::ostringstream cullModeString;
291 cullModeString << GL_BACK;
293 DALI_TEST_CHECK( cullFaceStack.FindMethodAndParams( "CullFace", cullModeString.str() ) );
294 cullFace = renderer.GetProperty<int>( Renderer::Property::FACE_CULLING_MODE );
295 DALI_TEST_CHECK( static_cast< Dali::Renderer::FaceCullingMode >( cullFace ) == Renderer::CULL_BACK );
299 cullFaceStack.Reset();
300 renderer.SetProperty( Renderer::Property::FACE_CULLING_MODE, Renderer::CULL_FRONT );
301 application.SendNotification();
302 application.Render();
304 DALI_TEST_EQUALS( cullFaceStack.CountMethod( "CullFace" ), 1, TEST_LOCATION );
306 std::ostringstream cullModeString;
307 cullModeString << GL_FRONT;
309 DALI_TEST_CHECK( cullFaceStack.FindMethodAndParams( "CullFace", cullModeString.str() ) );
310 cullFace = renderer.GetProperty<int>( Renderer::Property::FACE_CULLING_MODE );
311 DALI_TEST_CHECK( static_cast< Dali::Renderer::FaceCullingMode >( cullFace ) == Renderer::CULL_FRONT );
315 cullFaceStack.Reset();
316 renderer.SetProperty( Renderer::Property::FACE_CULLING_MODE, Renderer::NONE );
317 application.SendNotification();
318 application.Render();
320 DALI_TEST_EQUALS( cullFaceStack.CountMethod( "CullFace" ), 0, TEST_LOCATION );
321 cullFace = renderer.GetProperty<int>( Renderer::Property::FACE_CULLING_MODE );
322 DALI_TEST_CHECK( static_cast< Dali::Renderer::FaceCullingMode >( cullFace ) == Renderer::NONE );
328 int UtcDaliRendererBlendingOptions01(void)
330 TestApplication application;
332 tet_infoline("Test SetBlendFunc(src, dest) ");
334 Geometry geometry = CreateQuadGeometry();
335 Shader shader = CreateShader();
336 Renderer renderer = Renderer::New( geometry, shader );
338 Actor actor = Actor::New();
339 // set a transparent actor color so that blending is enabled
340 actor.SetOpacity( 0.5f );
341 actor.AddRenderer(renderer);
342 actor.SetSize(400, 400);
343 Stage::GetCurrent().Add(actor);
345 renderer.SetBlendFunc(BlendingFactor::ONE_MINUS_SRC_COLOR, BlendingFactor::SRC_ALPHA_SATURATE);
347 // Test that Set was successful:
348 BlendingFactor::Type srcFactorRgb( BlendingFactor::ZERO );
349 BlendingFactor::Type destFactorRgb( BlendingFactor::ZERO );
350 BlendingFactor::Type srcFactorAlpha( BlendingFactor::ZERO );
351 BlendingFactor::Type destFactorAlpha( BlendingFactor::ZERO );
352 renderer.GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
354 DALI_TEST_EQUALS( BlendingFactor::ONE_MINUS_SRC_COLOR, srcFactorRgb, TEST_LOCATION );
355 DALI_TEST_EQUALS( BlendingFactor::SRC_ALPHA_SATURATE, destFactorRgb, TEST_LOCATION );
356 DALI_TEST_EQUALS( BlendingFactor::ONE_MINUS_SRC_COLOR, srcFactorAlpha, TEST_LOCATION );
357 DALI_TEST_EQUALS( BlendingFactor::SRC_ALPHA_SATURATE, destFactorAlpha, TEST_LOCATION );
359 application.SendNotification();
360 application.Render();
362 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
364 DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_SRC_COLOR, glAbstraction.GetLastBlendFuncSrcRgb(), TEST_LOCATION );
365 DALI_TEST_EQUALS( (GLenum)GL_SRC_ALPHA_SATURATE, glAbstraction.GetLastBlendFuncDstRgb(), TEST_LOCATION );
366 DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_SRC_COLOR, glAbstraction.GetLastBlendFuncSrcAlpha(), TEST_LOCATION );
367 DALI_TEST_EQUALS( (GLenum)GL_SRC_ALPHA_SATURATE, glAbstraction.GetLastBlendFuncDstAlpha(), TEST_LOCATION );
372 int UtcDaliRendererBlendingOptions02(void)
374 TestApplication application;
376 tet_infoline("Test SetBlendFunc(srcRgb, destRgb, srcAlpha, destAlpha) ");
378 Geometry geometry = CreateQuadGeometry();
379 Shader shader = CreateShader();
380 Renderer renderer = Renderer::New( geometry, shader );
382 Actor actor = Actor::New();
383 actor.SetOpacity( 0.5f ); // enable blending
384 actor.AddRenderer(renderer);
385 actor.SetSize(400, 400);
386 Stage::GetCurrent().Add(actor);
388 renderer.SetBlendFunc( BlendingFactor::CONSTANT_COLOR, BlendingFactor::ONE_MINUS_CONSTANT_COLOR,
389 BlendingFactor::CONSTANT_ALPHA, BlendingFactor::ONE_MINUS_CONSTANT_ALPHA );
391 // Test that Set was successful:
393 BlendingFactor::Type srcFactorRgb( BlendingFactor::ZERO );
394 BlendingFactor::Type destFactorRgb( BlendingFactor::ZERO );
395 BlendingFactor::Type srcFactorAlpha( BlendingFactor::ZERO );
396 BlendingFactor::Type destFactorAlpha( BlendingFactor::ZERO );
397 renderer.GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
399 DALI_TEST_EQUALS( BlendingFactor::CONSTANT_COLOR, srcFactorRgb, TEST_LOCATION );
400 DALI_TEST_EQUALS( BlendingFactor::ONE_MINUS_CONSTANT_COLOR, destFactorRgb, TEST_LOCATION );
401 DALI_TEST_EQUALS( BlendingFactor::CONSTANT_ALPHA, srcFactorAlpha, TEST_LOCATION );
402 DALI_TEST_EQUALS( BlendingFactor::ONE_MINUS_CONSTANT_ALPHA, destFactorAlpha, TEST_LOCATION );
405 application.SendNotification();
406 application.Render();
408 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
409 DALI_TEST_EQUALS( (GLenum)GL_CONSTANT_COLOR, glAbstraction.GetLastBlendFuncSrcRgb(), TEST_LOCATION );
410 DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_CONSTANT_COLOR, glAbstraction.GetLastBlendFuncDstRgb(), TEST_LOCATION );
411 DALI_TEST_EQUALS( (GLenum)GL_CONSTANT_ALPHA, glAbstraction.GetLastBlendFuncSrcAlpha(), TEST_LOCATION );
412 DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_CONSTANT_ALPHA, glAbstraction.GetLastBlendFuncDstAlpha(), TEST_LOCATION );
417 int UtcDaliRendererBlendingOptions03(void)
419 TestApplication application;
421 tet_infoline("Test GetBlendEquation() defaults ");
423 Geometry geometry = CreateQuadGeometry();
424 Shader shader = CreateShader();
425 Renderer renderer = Renderer::New( geometry, shader );
427 Actor actor = Actor::New();
428 actor.AddRenderer(renderer);
429 actor.SetSize(400, 400);
430 Stage::GetCurrent().Add(actor);
432 // Test the defaults as documented in blending.h
433 BlendingEquation::Type equationRgb( BlendingEquation::SUBTRACT );
434 BlendingEquation::Type equationAlpha( BlendingEquation::SUBTRACT );
435 renderer.GetBlendEquation( equationRgb, equationAlpha );
436 DALI_TEST_EQUALS( BlendingEquation::ADD, equationRgb, TEST_LOCATION );
437 DALI_TEST_EQUALS( BlendingEquation::ADD, equationAlpha, TEST_LOCATION );
442 int UtcDaliRendererBlendingOptions04(void)
444 TestApplication application;
446 tet_infoline("Test SetBlendEquation() ");
448 Geometry geometry = CreateQuadGeometry();
449 Shader shader = CreateShader();
450 Renderer renderer = Renderer::New( geometry, shader );
452 Actor actor = Actor::New();
453 actor.SetOpacity( 0.1f );
454 actor.AddRenderer(renderer);
455 actor.SetSize(400, 400);
456 Stage::GetCurrent().Add(actor);
458 // Test the single blending equation setting
460 renderer.SetBlendEquation( BlendingEquation::REVERSE_SUBTRACT );
461 BlendingEquation::Type equationRgba( BlendingEquation::SUBTRACT );
462 renderer.GetBlendEquation( equationRgba, equationRgba );
463 DALI_TEST_EQUALS( BlendingEquation::REVERSE_SUBTRACT, equationRgba, TEST_LOCATION );
466 renderer.SetBlendEquation( BlendingEquation::REVERSE_SUBTRACT, BlendingEquation::REVERSE_SUBTRACT );
468 // Test that Set was successful
470 BlendingEquation::Type equationRgb( BlendingEquation::SUBTRACT );
471 BlendingEquation::Type equationAlpha( BlendingEquation::SUBTRACT );
472 renderer.GetBlendEquation( equationRgb, equationAlpha );
473 DALI_TEST_EQUALS( BlendingEquation::REVERSE_SUBTRACT, equationRgb, TEST_LOCATION );
474 DALI_TEST_EQUALS( BlendingEquation::REVERSE_SUBTRACT, equationAlpha, TEST_LOCATION );
477 // Render & check GL commands
478 application.SendNotification();
479 application.Render();
481 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
482 DALI_TEST_EQUALS( (GLenum)GL_FUNC_REVERSE_SUBTRACT, glAbstraction.GetLastBlendEquationRgb(), TEST_LOCATION );
483 DALI_TEST_EQUALS( (GLenum)GL_FUNC_REVERSE_SUBTRACT, glAbstraction.GetLastBlendEquationAlpha(), TEST_LOCATION );
488 int UtcDaliRendererSetBlendMode01(void)
490 TestApplication application;
492 tet_infoline("Test setting the blend mode to on with an opaque color renders with blending enabled");
494 Geometry geometry = CreateQuadGeometry();
495 Shader shader = CreateShader();
496 Renderer renderer = Renderer::New( geometry, shader );
498 Actor actor = Actor::New();
499 actor.SetOpacity( 0.98f );
500 actor.AddRenderer(renderer);
501 actor.SetSize(400, 400);
502 Stage::GetCurrent().Add(actor);
504 renderer.SetProperty( Renderer::Property::BLENDING_MODE, BlendingMode::ON);
506 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
507 glAbstraction.EnableEnableDisableCallTrace(true);
509 application.SendNotification();
510 application.Render();
512 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
513 std::ostringstream blendStr;
514 blendStr << GL_BLEND;
515 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
520 int UtcDaliRendererSetBlendMode02(void)
522 TestApplication application;
524 tet_infoline("Test setting the blend mode to off with a transparent color renders with blending disabled (and not enabled)");
526 Geometry geometry = CreateQuadGeometry();
527 Shader shader = CreateShader();
528 Renderer renderer = Renderer::New( geometry, shader );
530 Actor actor = Actor::New();
531 actor.SetOpacity( 0.15f );
532 actor.AddRenderer(renderer);
533 actor.SetSize(400, 400);
534 Stage::GetCurrent().Add(actor);
536 renderer.SetProperty( Renderer::Property::BLENDING_MODE, BlendingMode::OFF);
538 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
539 glAbstraction.EnableEnableDisableCallTrace(true);
541 application.SendNotification();
542 application.Render();
544 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
545 std::ostringstream blendStr;
546 blendStr << GL_BLEND;
547 DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
552 int UtcDaliRendererSetBlendMode03(void)
554 TestApplication application;
556 tet_infoline("Test setting the blend mode to auto with a transparent color renders with blending enabled");
558 Geometry geometry = CreateQuadGeometry();
559 Shader shader = CreateShader();
560 Renderer renderer = Renderer::New( geometry, shader );
562 Actor actor = Actor::New();
563 actor.SetOpacity( 0.75f );
564 actor.AddRenderer(renderer);
565 actor.SetSize(400, 400);
566 Stage::GetCurrent().Add(actor);
568 renderer.SetProperty( Renderer::Property::BLENDING_MODE, BlendingMode::AUTO);
570 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
571 glAbstraction.EnableEnableDisableCallTrace(true);
573 application.SendNotification();
574 application.Render();
576 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
577 std::ostringstream blendStr;
578 blendStr << GL_BLEND;
579 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
584 int UtcDaliRendererSetBlendMode04(void)
586 TestApplication application;
588 tet_infoline("Test setting the blend mode to auto with an opaque color renders with blending disabled");
590 Geometry geometry = CreateQuadGeometry();
591 Shader shader = CreateShader();
592 Renderer renderer = Renderer::New( geometry, shader );
594 Actor actor = Actor::New();
595 actor.AddRenderer(renderer);
596 actor.SetSize(400, 400);
597 Stage::GetCurrent().Add(actor);
599 renderer.SetProperty( Renderer::Property::BLENDING_MODE, BlendingMode::AUTO);
601 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
602 glAbstraction.EnableEnableDisableCallTrace(true);
604 application.SendNotification();
605 application.Render();
607 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
608 std::ostringstream blendStr;
609 blendStr << GL_BLEND;
610 DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
615 int UtcDaliRendererSetBlendMode04b(void)
617 TestApplication application;
619 tet_infoline("Test setting the blend mode to auto with a transparent actor color renders with blending enabled");
621 Geometry geometry = CreateQuadGeometry();
622 Shader shader = CreateShader();
623 Renderer renderer = Renderer::New( geometry, shader );
625 Actor actor = Actor::New();
626 actor.AddRenderer(renderer);
627 actor.SetSize(400, 400);
628 actor.SetColor( Vector4(1.0f, 0.0f, 1.0f, 0.5f) );
629 Stage::GetCurrent().Add(actor);
631 renderer.SetProperty( Renderer::Property::BLENDING_MODE, BlendingMode::AUTO);
633 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
634 glAbstraction.EnableEnableDisableCallTrace(true);
636 application.SendNotification();
637 application.Render();
639 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
640 std::ostringstream blendStr;
641 blendStr << GL_BLEND;
642 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
647 int UtcDaliRendererSetBlendMode04c(void)
649 TestApplication application;
651 tet_infoline("Test setting the blend mode to auto with an opaque opaque actor color renders with blending disabled");
653 Geometry geometry = CreateQuadGeometry();
654 Shader shader = CreateShader();
655 Renderer renderer = Renderer::New( geometry, shader );
657 Actor actor = Actor::New();
658 actor.AddRenderer(renderer);
659 actor.SetSize(400, 400);
660 actor.SetColor( Color::MAGENTA );
661 Stage::GetCurrent().Add(actor);
663 renderer.SetProperty( Renderer::Property::BLENDING_MODE, BlendingMode::AUTO);
665 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
666 glAbstraction.EnableEnableDisableCallTrace(true);
668 application.SendNotification();
669 application.Render();
671 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
672 std::ostringstream blendStr;
673 blendStr << GL_BLEND;
674 DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
679 int UtcDaliRendererSetBlendMode05(void)
681 TestApplication application;
683 tet_infoline("Test setting the blend mode to auto with an opaque color and an image with an alpha channel renders with blending enabled");
685 Geometry geometry = CreateQuadGeometry();
686 BufferImage image = BufferImage::New( 40, 40, Pixel::RGBA8888 );
688 Shader shader = CreateShader();
689 TextureSet textureSet = CreateTextureSet( image );
690 Renderer renderer = Renderer::New( geometry, shader );
691 renderer.SetTextures( textureSet );
693 Actor actor = Actor::New();
694 actor.AddRenderer(renderer);
695 actor.SetSize(400, 400);
696 Stage::GetCurrent().Add(actor);
698 renderer.SetProperty( Renderer::Property::BLENDING_MODE, BlendingMode::AUTO);
700 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
701 glAbstraction.EnableEnableDisableCallTrace(true);
703 application.SendNotification();
704 application.Render();
706 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
707 std::ostringstream blendStr;
708 blendStr << GL_BLEND;
709 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
714 int UtcDaliRendererSetBlendMode06(void)
716 TestApplication application;
717 tet_infoline("Test setting the blend mode to auto with an opaque color and an image without an alpha channel and a shader with the hint OUTPUT_IS_TRANSPARENT renders with blending enabled");
719 Geometry geometry = CreateQuadGeometry();
720 Shader shader = Shader::New( "vertexSrc", "fragmentSrc", Shader::HINT_OUTPUT_IS_TRANSPARENT );
722 Renderer renderer = Renderer::New( geometry, shader );
724 Actor actor = Actor::New();
725 actor.AddRenderer(renderer);
726 actor.SetSize(400, 400);
727 Stage::GetCurrent().Add(actor);
729 renderer.SetProperty( Renderer::Property::BLENDING_MODE, BlendingMode::AUTO);
731 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
732 glAbstraction.EnableEnableDisableCallTrace(true);
734 application.SendNotification();
735 application.Render();
737 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
738 std::ostringstream blendStr;
739 blendStr << GL_BLEND;
740 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
745 int UtcDaliRendererSetBlendMode07(void)
747 TestApplication application;
748 tet_infoline("Test setting the blend mode to auto with an opaque color and an image without an alpha channel and a shader with the hint OUTPUT_IS_OPAQUE renders with blending disabled");
750 Geometry geometry = CreateQuadGeometry();
751 Shader shader = Shader::New( "vertexSrc", "fragmentSrc", Shader::HINT_OUTPUT_IS_OPAQUE );
753 BufferImage image = BufferImage::New( 50, 50, Pixel::RGB888 );
754 TextureSet textureSet = CreateTextureSet( image );
755 Renderer renderer = Renderer::New( geometry, shader );
756 renderer.SetTextures( textureSet );
758 Actor actor = Actor::New();
759 actor.AddRenderer(renderer);
760 actor.SetSize(400, 400);
761 Stage::GetCurrent().Add(actor);
763 renderer.SetProperty( Renderer::Property::BLENDING_MODE, BlendingMode::AUTO);
765 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
766 glAbstraction.EnableEnableDisableCallTrace(true);
768 application.SendNotification();
769 application.Render();
771 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
772 DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", "GL_BLEND" ) );
777 int UtcDaliRendererGetBlendMode(void)
779 TestApplication application;
781 tet_infoline("Test GetBlendMode()");
783 Geometry geometry = CreateQuadGeometry();
784 Shader shader = Shader::New( "vertexSrc", "fragmentSrc", Shader::HINT_OUTPUT_IS_OPAQUE );
785 Renderer renderer = Renderer::New( geometry, shader );
788 unsigned int mode = renderer.GetProperty<int>( Renderer::Property::BLENDING_MODE );
789 DALI_TEST_EQUALS( static_cast< BlendingMode::Type >( mode ), BlendingMode::AUTO, TEST_LOCATION );
792 renderer.SetProperty( Renderer::Property::BLENDING_MODE, BlendingMode::ON );
793 mode = renderer.GetProperty<int>( Renderer::Property::BLENDING_MODE );
794 DALI_TEST_EQUALS( static_cast< BlendingMode::Type >( mode ), BlendingMode::ON, TEST_LOCATION );
797 renderer.SetProperty( Renderer::Property::BLENDING_MODE, BlendingMode::OFF );
798 mode = renderer.GetProperty<int>( Renderer::Property::BLENDING_MODE );
799 DALI_TEST_EQUALS( static_cast< BlendingMode::Type >( mode ), BlendingMode::OFF, TEST_LOCATION );
804 int UtcDaliRendererSetBlendColor(void)
806 TestApplication application;
808 tet_infoline("Test SetBlendColor(color)");
810 Geometry geometry = CreateQuadGeometry();
811 Shader shader = Shader::New( "vertexSrc", "fragmentSrc", Shader::HINT_OUTPUT_IS_OPAQUE );
812 TextureSet textureSet = TextureSet::New();
813 BufferImage image = BufferImage::New( 50, 50, Pixel::RGBA8888 );
814 textureSet.SetImage( 0u, image );
815 Renderer renderer = Renderer::New( geometry, shader );
816 renderer.SetTextures( textureSet );
818 Actor actor = Actor::New();
819 actor.AddRenderer(renderer);
820 actor.SetSize(400, 400);
821 Stage::GetCurrent().Add(actor);
823 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
825 renderer.SetProperty( Renderer::Property::BLENDING_COLOR, Color::TRANSPARENT );
826 application.SendNotification();
827 application.Render();
828 DALI_TEST_EQUALS( glAbstraction.GetLastBlendColor(), Color::TRANSPARENT, TEST_LOCATION );
830 renderer.SetProperty( Renderer::Property::BLENDING_COLOR, Color::MAGENTA );
831 application.SendNotification();
832 application.Render();
833 DALI_TEST_EQUALS( glAbstraction.GetLastBlendColor(), Color::MAGENTA, TEST_LOCATION );
835 Vector4 color( 0.1f, 0.2f, 0.3f, 0.4f );
836 renderer.SetProperty( Renderer::Property::BLENDING_COLOR, color );
837 application.SendNotification();
838 application.Render();
839 DALI_TEST_EQUALS( glAbstraction.GetLastBlendColor(), color, TEST_LOCATION );
844 int UtcDaliRendererGetBlendColor(void)
846 TestApplication application;
848 tet_infoline("Test GetBlendColor()");
850 Geometry geometry = CreateQuadGeometry();
851 Shader shader = Shader::New( "vertexSrc", "fragmentSrc", Shader::HINT_OUTPUT_IS_OPAQUE );
852 Renderer renderer = Renderer::New( geometry, shader );
854 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>( Renderer::Property::BLENDING_COLOR ), Color::TRANSPARENT, TEST_LOCATION );
856 renderer.SetProperty( Renderer::Property::BLENDING_COLOR, Color::MAGENTA );
857 application.SendNotification();
858 application.Render();
859 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>( Renderer::Property::BLENDING_COLOR ), Color::MAGENTA, TEST_LOCATION );
861 Vector4 color( 0.1f, 0.2f, 0.3f, 0.4f );
862 renderer.SetProperty( Renderer::Property::BLENDING_COLOR, color );
863 application.SendNotification();
864 application.Render();
865 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>( Renderer::Property::BLENDING_COLOR ), color, TEST_LOCATION );
870 int UtcDaliRendererPreMultipledAlpha(void)
872 TestApplication application;
874 tet_infoline("Test BLEND_PRE_MULTIPLIED_ALPHA property");
876 Geometry geometry = CreateQuadGeometry();
877 Shader shader = Shader::New( "vertexSrc", "fragmentSrc", Shader::HINT_OUTPUT_IS_OPAQUE );
878 Renderer renderer = Renderer::New( geometry, shader );
880 Actor actor = Actor::New();
881 actor.AddRenderer(renderer);
882 actor.SetSize(400, 400);
883 actor.SetColor( Vector4(1.0f, 0.0f, 1.0f, 0.5f) );
884 Stage::GetCurrent().Add(actor);
886 Property::Value value = renderer.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
887 bool preMultipliedAlpha;
888 DALI_TEST_CHECK( value.Get( preMultipliedAlpha ) );
889 DALI_TEST_CHECK( !preMultipliedAlpha );
891 BlendingFactor::Type srcFactorRgb( BlendingFactor::ZERO );
892 BlendingFactor::Type destFactorRgb( BlendingFactor::ZERO );
893 BlendingFactor::Type srcFactorAlpha( BlendingFactor::ZERO );
894 BlendingFactor::Type destFactorAlpha( BlendingFactor::ZERO );
895 renderer.GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
896 DALI_TEST_EQUALS( DEFAULT_BLENDING_SRC_FACTOR_RGB, srcFactorRgb, TEST_LOCATION );
897 DALI_TEST_EQUALS( DEFAULT_BLENDING_DEST_FACTOR_RGB, destFactorRgb, TEST_LOCATION );
898 DALI_TEST_EQUALS( DEFAULT_BLENDING_SRC_FACTOR_ALPHA, srcFactorAlpha, TEST_LOCATION );
899 DALI_TEST_EQUALS( DEFAULT_BLENDING_DEST_FACTOR_ALPHA, destFactorAlpha, TEST_LOCATION );
901 application.SendNotification();
902 application.Render();
904 Vector4 actualValue(Vector4::ZERO);
905 TestGlAbstraction& gl = application.GetGlAbstraction();
906 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uColor", actualValue ) );
907 DALI_TEST_EQUALS( actualValue, Vector4(1.0f, 0.0f, 1.0f, 0.5f), TEST_LOCATION );
909 renderer.SetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, true);
911 application.SendNotification();
912 application.Render();
914 value = renderer.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
915 DALI_TEST_CHECK( value.Get( preMultipliedAlpha ) );
916 DALI_TEST_CHECK( preMultipliedAlpha );
918 renderer.GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
919 DALI_TEST_EQUALS( BlendingFactor::ONE, srcFactorRgb, TEST_LOCATION );
920 DALI_TEST_EQUALS( BlendingFactor::ONE_MINUS_SRC_ALPHA, destFactorRgb, TEST_LOCATION );
921 DALI_TEST_EQUALS( BlendingFactor::ONE, srcFactorAlpha, TEST_LOCATION );
922 DALI_TEST_EQUALS( BlendingFactor::ONE, destFactorAlpha, TEST_LOCATION );
924 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uColor", actualValue ) );
925 DALI_TEST_EQUALS( actualValue, Vector4(0.5f, 0.0f, 0.5f, 0.5f), TEST_LOCATION );
930 int UtcDaliRendererConstraint01(void)
932 TestApplication application;
934 tet_infoline("Test that a non-uniform renderer property can be constrained");
936 Shader shader = Shader::New("VertexSource", "FragmentSource");
937 Geometry geometry = CreateQuadGeometry();
938 Renderer renderer = Renderer::New( geometry, shader );
940 Actor actor = Actor::New();
941 actor.AddRenderer(renderer);
942 actor.SetSize(400, 400);
943 Stage::GetCurrent().Add(actor);
945 Vector4 initialColor = Color::WHITE;
946 Property::Index colorIndex = renderer.RegisterProperty( "uFadeColor", initialColor );
948 application.SendNotification();
949 application.Render(0);
950 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION );
953 Constraint constraint = Constraint::New<Vector4>( renderer, colorIndex, TestConstraintNoBlue );
955 application.SendNotification();
956 application.Render(0);
958 // Expect no blue component in either buffer - yellow
959 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(colorIndex), Color::YELLOW, TEST_LOCATION );
960 application.Render(0);
961 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(colorIndex), Color::YELLOW, TEST_LOCATION );
963 renderer.RemoveConstraints();
964 renderer.SetProperty(colorIndex, Color::WHITE );
965 application.SendNotification();
966 application.Render(0);
967 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(colorIndex), Color::WHITE, TEST_LOCATION );
972 int UtcDaliRendererConstraint02(void)
974 TestApplication application;
976 tet_infoline("Test that a uniform map renderer property can be constrained");
978 Shader shader = Shader::New("VertexSource", "FragmentSource");
979 Geometry geometry = CreateQuadGeometry();
980 Renderer renderer = Renderer::New( geometry, shader );
982 Actor actor = Actor::New();
983 actor.AddRenderer(renderer);
984 actor.SetSize(400, 400);
985 Stage::GetCurrent().Add(actor);
986 application.SendNotification();
987 application.Render(0);
989 Vector4 initialColor = Color::WHITE;
990 Property::Index colorIndex = renderer.RegisterProperty( "uFadeColor", initialColor );
992 TestGlAbstraction& gl = application.GetGlAbstraction();
994 application.SendNotification();
995 application.Render(0);
997 Vector4 actualValue(Vector4::ZERO);
998 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
999 DALI_TEST_EQUALS( actualValue, initialColor, TEST_LOCATION );
1002 Constraint constraint = Constraint::New<Vector4>( renderer, colorIndex, TestConstraintNoBlue );
1004 application.SendNotification();
1005 application.Render(0);
1007 // Expect no blue component in either buffer - yellow
1008 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1009 DALI_TEST_EQUALS( actualValue, Color::YELLOW, TEST_LOCATION );
1011 application.Render(0);
1012 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1013 DALI_TEST_EQUALS( actualValue, Color::YELLOW, TEST_LOCATION );
1015 renderer.RemoveConstraints();
1016 renderer.SetProperty(colorIndex, Color::WHITE );
1017 application.SendNotification();
1018 application.Render(0);
1020 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1021 DALI_TEST_EQUALS( actualValue, Color::WHITE, TEST_LOCATION );
1028 int UtcDaliRendererAnimatedProperty01(void)
1030 TestApplication application;
1032 tet_infoline("Test that a non-uniform renderer property can be animated");
1034 Shader shader = Shader::New("VertexSource", "FragmentSource");
1035 Geometry geometry = CreateQuadGeometry();
1036 Renderer renderer = Renderer::New( geometry, shader );
1038 Actor actor = Actor::New();
1039 actor.AddRenderer(renderer);
1040 actor.SetSize(400, 400);
1041 Stage::GetCurrent().Add(actor);
1043 Vector4 initialColor = Color::WHITE;
1044 Property::Index colorIndex = renderer.RegisterProperty( "uFadeColor", initialColor );
1046 application.SendNotification();
1047 application.Render(0);
1048 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION );
1050 Animation animation = Animation::New(1.0f);
1051 KeyFrames keyFrames = KeyFrames::New();
1052 keyFrames.Add(0.0f, initialColor);
1053 keyFrames.Add(1.0f, Color::TRANSPARENT);
1054 animation.AnimateBetween( Property( renderer, colorIndex ), keyFrames );
1057 application.SendNotification();
1058 application.Render(500);
1060 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(colorIndex), Color::WHITE * 0.5f, TEST_LOCATION );
1062 application.Render(500);
1064 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(colorIndex), Color::TRANSPARENT, TEST_LOCATION );
1069 int UtcDaliRendererAnimatedProperty02(void)
1071 TestApplication application;
1073 tet_infoline("Test that a uniform map renderer property can be animated");
1075 Shader shader = Shader::New("VertexSource", "FragmentSource");
1076 Geometry geometry = CreateQuadGeometry();
1077 Renderer renderer = Renderer::New( geometry, shader );
1079 Actor actor = Actor::New();
1080 actor.AddRenderer(renderer);
1081 actor.SetSize(400, 400);
1082 Stage::GetCurrent().Add(actor);
1083 application.SendNotification();
1084 application.Render(0);
1086 Vector4 initialColor = Color::WHITE;
1087 Property::Index colorIndex = renderer.RegisterProperty( "uFadeColor", initialColor );
1089 TestGlAbstraction& gl = application.GetGlAbstraction();
1091 application.SendNotification();
1092 application.Render(0);
1094 Vector4 actualValue(Vector4::ZERO);
1095 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1096 DALI_TEST_EQUALS( actualValue, initialColor, TEST_LOCATION );
1098 Animation animation = Animation::New(1.0f);
1099 KeyFrames keyFrames = KeyFrames::New();
1100 keyFrames.Add(0.0f, initialColor);
1101 keyFrames.Add(1.0f, Color::TRANSPARENT);
1102 animation.AnimateBetween( Property( renderer, colorIndex ), keyFrames );
1105 application.SendNotification();
1106 application.Render(500);
1108 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1109 DALI_TEST_EQUALS( actualValue, Color::WHITE * 0.5f, TEST_LOCATION );
1111 application.Render(500);
1112 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1113 DALI_TEST_EQUALS( actualValue, Color::TRANSPARENT, TEST_LOCATION );
1121 int UtcDaliRendererUniformMapPrecendence01(void)
1123 TestApplication application;
1125 tet_infoline("Test the uniform map precedence is applied properly");
1127 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1129 Shader shader = Shader::New("VertexSource", "FragmentSource");
1130 TextureSet textureSet = CreateTextureSet( image );
1132 PropertyBuffer vertexBuffer = CreatePropertyBuffer();
1133 Geometry geometry = CreateQuadGeometryFromBuffer(vertexBuffer);
1134 Renderer renderer = Renderer::New( geometry, shader );
1135 renderer.SetTextures( textureSet );
1137 Actor actor = Actor::New();
1138 actor.AddRenderer(renderer);
1139 actor.SetSize(400, 400);
1140 Stage::GetCurrent().Add(actor);
1141 application.SendNotification();
1142 application.Render(0);
1144 renderer.RegisterProperty( "uFadeColor", Color::RED );
1146 actor.RegisterProperty( "uFadeColor", Color::GREEN );
1148 Property::Index textureSetFadeColorIndex = textureSet.RegisterProperty( "uFadeColor", Color::BLUE );
1150 shader.RegisterProperty( "uFadeColor", Color::MAGENTA );
1152 geometry.RegisterProperty( "uFadeColor", Color::YELLOW );
1154 TestGlAbstraction& gl = application.GetGlAbstraction();
1156 application.SendNotification();
1157 application.Render(0);
1159 // Expect that the actor's fade color property is accessed
1160 Vector4 actualValue(Vector4::ZERO);
1161 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1162 DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
1164 // Animate texture set's fade color property. Should be no change to uniform
1165 Animation animation = Animation::New(1.0f);
1166 KeyFrames keyFrames = KeyFrames::New();
1167 keyFrames.Add(0.0f, Color::WHITE);
1168 keyFrames.Add(1.0f, Color::TRANSPARENT);
1169 animation.AnimateBetween( Property( textureSet, textureSetFadeColorIndex ), keyFrames );
1172 application.SendNotification();
1173 application.Render(500);
1175 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1176 DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
1178 application.Render(500);
1179 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1180 DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
1185 int UtcDaliRendererUniformMapPrecendence02(void)
1187 TestApplication application;
1189 tet_infoline("Test the uniform map precedence is applied properly");
1191 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1193 Shader shader = Shader::New("VertexSource", "FragmentSource");
1194 TextureSet textureSet = CreateTextureSet( image );
1196 PropertyBuffer vertexBuffer = CreatePropertyBuffer();
1197 Geometry geometry = CreateQuadGeometryFromBuffer(vertexBuffer);
1198 Renderer renderer = Renderer::New( geometry, shader );
1199 renderer.SetTextures( textureSet );
1201 Actor actor = Actor::New();
1202 actor.AddRenderer(renderer);
1203 actor.SetSize(400, 400);
1204 Stage::GetCurrent().Add(actor);
1205 application.SendNotification();
1206 application.Render(0);
1208 // Don't add property / uniform map to renderer
1210 actor.RegisterProperty( "uFadeColor", Color::GREEN );
1212 Property::Index textureSetFadeColorIndex = textureSet.RegisterProperty( "uFadeColor", Color::BLUE );
1214 shader.RegisterProperty( "uFadeColor", Color::MAGENTA );
1216 geometry.RegisterProperty( "uFadeColor", Color::YELLOW );
1219 TestGlAbstraction& gl = application.GetGlAbstraction();
1221 application.SendNotification();
1222 application.Render(0);
1224 // Expect that the actor's fade color property is accessed
1225 Vector4 actualValue(Vector4::ZERO);
1226 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1227 DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
1229 // Animate texture set's fade color property. Should be no change to uniform
1230 Animation animation = Animation::New(1.0f);
1231 KeyFrames keyFrames = KeyFrames::New();
1232 keyFrames.Add(0.0f, Color::WHITE);
1233 keyFrames.Add(1.0f, Color::TRANSPARENT);
1234 animation.AnimateBetween( Property( textureSet, textureSetFadeColorIndex ), keyFrames );
1237 application.SendNotification();
1238 application.Render(500);
1240 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1241 DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
1243 application.Render(500);
1244 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1245 DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
1251 int UtcDaliRendererUniformMapPrecendence03(void)
1253 TestApplication application;
1255 tet_infoline("Test the uniform map precedence is applied properly");
1257 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1259 Shader shader = Shader::New("VertexSource", "FragmentSource");
1260 TextureSet textureSet = CreateTextureSet( image );
1262 PropertyBuffer vertexBuffer = CreatePropertyBuffer();
1263 Geometry geometry = CreateQuadGeometryFromBuffer(vertexBuffer);
1264 Renderer renderer = Renderer::New( geometry, shader );
1265 renderer.SetTextures( textureSet );
1267 Actor actor = Actor::New();
1268 actor.AddRenderer(renderer);
1269 actor.SetSize(400, 400);
1270 Stage::GetCurrent().Add(actor);
1271 application.SendNotification();
1272 application.Render(0);
1274 // Don't add property / uniform map to renderer or actor
1276 textureSet.RegisterProperty( "uFadeColor", Color::BLUE );
1278 shader.RegisterProperty( "uFadeColor", Color::MAGENTA );
1280 Property::Index geometryFadeColorIndex = geometry.RegisterProperty( "uFadeColor", Color::YELLOW );
1282 geometry.RegisterProperty( "uFadeColor", Color::BLACK );
1285 TestGlAbstraction& gl = application.GetGlAbstraction();
1287 application.SendNotification();
1288 application.Render(0);
1290 // Expect that the texture set's fade color property is accessed
1291 Vector4 actualValue(Vector4::ZERO);
1292 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1293 DALI_TEST_EQUALS( actualValue, Color::BLUE, TEST_LOCATION );
1295 // Animate geometry's fade color property. Should be no change to uniform
1296 Animation animation = Animation::New(1.0f);
1297 KeyFrames keyFrames = KeyFrames::New();
1298 keyFrames.Add(0.0f, Color::WHITE);
1299 keyFrames.Add(1.0f, Color::TRANSPARENT);
1300 animation.AnimateBetween( Property( geometry, geometryFadeColorIndex ), keyFrames );
1303 application.SendNotification();
1304 application.Render(500);
1306 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1307 DALI_TEST_EQUALS( actualValue, Color::BLUE, TEST_LOCATION );
1309 application.Render(500);
1310 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1311 DALI_TEST_EQUALS( actualValue, Color::BLUE, TEST_LOCATION );
1317 int UtcDaliRendererUniformMapPrecendence04(void)
1319 TestApplication application;
1321 tet_infoline("Test the uniform map precedence is applied properly");
1323 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1325 Shader shader = Shader::New("VertexSource", "FragmentSource");
1326 TextureSet textureSet = CreateTextureSet( image );
1328 PropertyBuffer vertexBuffer = CreatePropertyBuffer();
1329 Geometry geometry = CreateQuadGeometryFromBuffer(vertexBuffer);
1330 Renderer renderer = Renderer::New( geometry, shader );
1331 renderer.SetTextures( textureSet );
1333 Actor actor = Actor::New();
1334 actor.AddRenderer(renderer);
1335 actor.SetSize(400, 400);
1336 Stage::GetCurrent().Add(actor);
1337 application.SendNotification();
1338 application.Render(0);
1340 // Don't add property / uniform map to renderer/actor/texture set
1341 shader.RegisterProperty( "uFadeColor", Color::MAGENTA );
1343 Property::Index geometryFadeColorIndex = geometry.RegisterProperty( "uFadeColor", Color::YELLOW );
1345 geometry.RegisterProperty( "uFadeColor", Color::BLACK );
1348 TestGlAbstraction& gl = application.GetGlAbstraction();
1350 application.SendNotification();
1351 application.Render(0);
1353 // Expect that the sampler's fade color property is accessed
1354 Vector4 actualValue(Vector4::ZERO);
1355 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1356 DALI_TEST_EQUALS( actualValue, Color::MAGENTA, TEST_LOCATION );
1358 // Animate geometry's fade color property. Should be no change to uniform
1359 Animation animation = Animation::New(1.0f);
1360 KeyFrames keyFrames = KeyFrames::New();
1361 keyFrames.Add(0.0f, Color::WHITE);
1362 keyFrames.Add(1.0f, Color::TRANSPARENT);
1363 animation.AnimateBetween( Property( geometry, geometryFadeColorIndex ), keyFrames );
1366 application.SendNotification();
1367 application.Render(500);
1369 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1370 DALI_TEST_EQUALS( actualValue, Color::MAGENTA, TEST_LOCATION );
1372 application.Render(500);
1373 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1374 DALI_TEST_EQUALS( actualValue, Color::MAGENTA, TEST_LOCATION );
1379 int UtcDaliRendererUniformMapPrecendence05(void)
1381 TestApplication application;
1383 tet_infoline("Test the uniform map precedence is applied properly");
1385 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1387 Shader shader = Shader::New("VertexSource", "FragmentSource");
1388 TextureSet textureSet = CreateTextureSet( image );
1390 PropertyBuffer vertexBuffer = CreatePropertyBuffer();
1391 Geometry geometry = CreateQuadGeometryFromBuffer(vertexBuffer);
1392 Renderer renderer = Renderer::New( geometry, shader );
1393 renderer.SetTextures( textureSet );
1395 Actor actor = Actor::New();
1396 actor.AddRenderer(renderer);
1397 actor.SetSize(400, 400);
1398 Stage::GetCurrent().Add(actor);
1399 application.SendNotification();
1400 application.Render(0);
1402 // Don't add property / uniform map to renderer/actor/texture set/sampler
1404 shader.RegisterProperty( "uFadeColor", Color::MAGENTA );
1406 Property::Index geometryFadeColorIndex = geometry.RegisterProperty( "uFadeColor", Color::YELLOW );
1408 geometry.RegisterProperty( "uFadeColor", Color::BLACK );
1411 TestGlAbstraction& gl = application.GetGlAbstraction();
1413 application.SendNotification();
1414 application.Render(0);
1416 // Expect that the shader's fade color property is accessed
1417 Vector4 actualValue(Vector4::ZERO);
1418 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1419 DALI_TEST_EQUALS( actualValue, Color::MAGENTA, TEST_LOCATION );
1421 // Animate geometry's fade color property. Should be no change to uniform
1422 Animation animation = Animation::New(1.0f);
1423 KeyFrames keyFrames = KeyFrames::New();
1424 keyFrames.Add(0.0f, Color::WHITE);
1425 keyFrames.Add(1.0f, Color::TRANSPARENT);
1426 animation.AnimateBetween( Property( geometry, geometryFadeColorIndex ), keyFrames );
1429 application.SendNotification();
1430 application.Render(500);
1432 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1433 DALI_TEST_EQUALS( actualValue, Color::MAGENTA, TEST_LOCATION );
1435 application.Render(500);
1436 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1437 DALI_TEST_EQUALS( actualValue, Color::MAGENTA, TEST_LOCATION );
1442 int UtcDaliRendererUniformMapMultipleUniforms01(void)
1444 TestApplication application;
1446 tet_infoline("Test the uniform maps are collected from all objects (same type)");
1448 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1450 Shader shader = Shader::New("VertexSource", "FragmentSource");
1451 TextureSet textureSet = CreateTextureSet( image );
1453 PropertyBuffer vertexBuffer = CreatePropertyBuffer();
1454 Geometry geometry = CreateQuadGeometryFromBuffer(vertexBuffer);
1455 Renderer renderer = Renderer::New( geometry, shader );
1456 renderer.SetTextures( textureSet );
1458 Actor actor = Actor::New();
1459 actor.AddRenderer(renderer);
1460 actor.SetSize(400, 400);
1461 Stage::GetCurrent().Add(actor);
1462 application.SendNotification();
1463 application.Render(0);
1465 renderer.RegisterProperty( "uUniform1", Color::RED );
1466 actor.RegisterProperty( "uUniform2", Color::GREEN );
1467 textureSet.RegisterProperty( "uUniform3", Color::BLUE );
1468 shader.RegisterProperty( "uUniform4", Color::MAGENTA );
1469 geometry.RegisterProperty( "uUniform5", Color::YELLOW );
1471 TestGlAbstraction& gl = application.GetGlAbstraction();
1473 application.SendNotification();
1474 application.Render(0);
1476 // Expect that each of the object's uniforms are set
1477 Vector4 uniform1Value(Vector4::ZERO);
1478 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uUniform1", uniform1Value ) );
1479 DALI_TEST_EQUALS( uniform1Value, Color::RED, TEST_LOCATION );
1481 Vector4 uniform2Value(Vector4::ZERO);
1482 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uUniform2", uniform2Value ) );
1483 DALI_TEST_EQUALS( uniform2Value, Color::GREEN, TEST_LOCATION );
1485 Vector4 uniform3Value(Vector4::ZERO);
1486 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uUniform3", uniform3Value ) );
1487 DALI_TEST_EQUALS( uniform3Value, Color::BLUE, TEST_LOCATION );
1489 Vector4 uniform5Value(Vector4::ZERO);
1490 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uUniform4", uniform5Value ) );
1491 DALI_TEST_EQUALS( uniform5Value, Color::MAGENTA, TEST_LOCATION );
1493 Vector4 uniform6Value(Vector4::ZERO);
1494 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uUniform5", uniform6Value ) );
1495 DALI_TEST_EQUALS( uniform6Value, Color::YELLOW, TEST_LOCATION );
1501 int UtcDaliRendererUniformMapMultipleUniforms02(void)
1503 TestApplication application;
1505 tet_infoline("Test the uniform maps are collected from all objects (different types)");
1507 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1509 Shader shader = Shader::New("VertexSource", "FragmentSource");
1510 TextureSet textureSet = CreateTextureSet( image );
1512 PropertyBuffer vertexBuffer = CreatePropertyBuffer();
1513 Geometry geometry = CreateQuadGeometryFromBuffer(vertexBuffer);
1514 Renderer renderer = Renderer::New( geometry, shader );
1515 renderer.SetTextures( textureSet );
1517 Actor actor = Actor::New();
1518 actor.AddRenderer(renderer);
1519 actor.SetSize(400, 400);
1520 Stage::GetCurrent().Add(actor);
1521 application.SendNotification();
1522 application.Render(0);
1524 Property::Value value1(Color::RED);
1525 renderer.RegisterProperty( "uFadeColor", value1 );
1527 Property::Value value2(1.0f);
1528 actor.RegisterProperty( "uFadeProgress", value2 );
1530 Property::Value value3(Vector3(0.5f, 0.5f, 1.0f));
1531 textureSet.RegisterProperty( "uFadePosition", value3);
1533 Property::Value value5(Matrix3::IDENTITY);
1534 shader.RegisterProperty( "uANormalMatrix", value5 );
1536 Property::Value value6(Matrix::IDENTITY);
1537 geometry.RegisterProperty( "uAWorldMatrix", value6 );
1539 TestGlAbstraction& gl = application.GetGlAbstraction();
1541 application.SendNotification();
1542 application.Render(0);
1544 // Expect that each of the object's uniforms are set
1545 Vector4 uniform1Value(Vector4::ZERO);
1546 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", uniform1Value ) );
1547 DALI_TEST_EQUALS( uniform1Value, value1.Get<Vector4>(), TEST_LOCATION );
1549 float uniform2Value(0.0f);
1550 DALI_TEST_CHECK( gl.GetUniformValue<float>( "uFadeProgress", uniform2Value ) );
1551 DALI_TEST_EQUALS( uniform2Value, value2.Get<float>(), TEST_LOCATION );
1553 Vector3 uniform3Value(Vector3::ZERO);
1554 DALI_TEST_CHECK( gl.GetUniformValue<Vector3>( "uFadePosition", uniform3Value ) );
1555 DALI_TEST_EQUALS( uniform3Value, value3.Get<Vector3>(), TEST_LOCATION );
1557 Matrix3 uniform5Value;
1558 DALI_TEST_CHECK( gl.GetUniformValue<Matrix3>( "uANormalMatrix", uniform5Value ) );
1559 DALI_TEST_EQUALS( uniform5Value, value5.Get<Matrix3>(), TEST_LOCATION );
1561 Matrix uniform6Value;
1562 DALI_TEST_CHECK( gl.GetUniformValue<Matrix>( "uAWorldMatrix", uniform6Value ) );
1563 DALI_TEST_EQUALS( uniform6Value, value6.Get<Matrix>(), TEST_LOCATION );
1569 int UtcDaliRendererRenderOrder2DLayer(void)
1571 TestApplication application;
1572 tet_infoline("Test the rendering order in a 2D layer is correct");
1574 Shader shader = Shader::New("VertexSource", "FragmentSource");
1575 PropertyBuffer vertexBuffer = CreatePropertyBuffer();
1576 Geometry geometry = CreateQuadGeometryFromBuffer(vertexBuffer);
1578 Actor actor0 = Actor::New();
1579 actor0.SetAnchorPoint(AnchorPoint::CENTER);
1580 actor0.SetParentOrigin(AnchorPoint::CENTER);
1581 actor0.SetPosition(0.0f,0.0f);
1582 Image image0 = BufferImage::New( 64, 64, Pixel::RGB888 );
1583 TextureSet textureSet0 = CreateTextureSet( image0 );
1584 Renderer renderer0 = Renderer::New( geometry, shader );
1585 renderer0.SetTextures( textureSet0 );
1586 actor0.AddRenderer(renderer0);
1587 actor0.SetSize(1, 1);
1588 Stage::GetCurrent().Add(actor0);
1589 application.SendNotification();
1590 application.Render(0);
1592 Actor actor1 = Actor::New();
1593 actor1.SetAnchorPoint(AnchorPoint::CENTER);
1594 actor1.SetParentOrigin(AnchorPoint::CENTER);
1595 actor1.SetPosition(0.0f,0.0f);
1596 Image image1= BufferImage::New( 64, 64, Pixel::RGB888 );
1597 TextureSet textureSet1 = CreateTextureSet( image1 );
1598 Renderer renderer1 = Renderer::New( geometry, shader );
1599 renderer1.SetTextures( textureSet1 );
1600 actor1.AddRenderer(renderer1);
1601 actor1.SetSize(1, 1);
1602 Stage::GetCurrent().Add(actor1);
1603 application.SendNotification();
1604 application.Render(0);
1606 Actor actor2 = Actor::New();
1607 actor2.SetAnchorPoint(AnchorPoint::CENTER);
1608 actor2.SetParentOrigin(AnchorPoint::CENTER);
1609 actor2.SetPosition(0.0f,0.0f);
1610 Image image2= BufferImage::New( 64, 64, Pixel::RGB888 );
1611 TextureSet textureSet2 = CreateTextureSet( image2 );
1612 Renderer renderer2 = Renderer::New( geometry, shader );
1613 renderer2.SetTextures( textureSet2 );
1614 actor2.AddRenderer(renderer2);
1615 actor2.SetSize(1, 1);
1616 Stage::GetCurrent().Add(actor2);
1617 application.SendNotification();
1618 application.Render(0);
1620 Actor actor3 = Actor::New();
1621 actor3.SetAnchorPoint(AnchorPoint::CENTER);
1622 actor3.SetParentOrigin(AnchorPoint::CENTER);
1623 actor3.SetPosition(0.0f,0.0f);
1624 Image image3 = BufferImage::New( 64, 64, Pixel::RGB888 );
1625 TextureSet textureSet3 = CreateTextureSet( image3 );
1626 Renderer renderer3 = Renderer::New( geometry, shader );
1627 renderer3.SetTextures( textureSet3 );
1628 actor3.AddRenderer(renderer3);
1629 actor3.SetSize(1, 1);
1630 Stage::GetCurrent().Add(actor3);
1631 application.SendNotification();
1632 application.Render(0);
1635 * Create the following hierarchy:
1648 * Expected rendering order : actor2 - actor1 - actor0 - actor3
1653 application.SendNotification();
1654 application.Render(0);
1656 TestGlAbstraction& gl = application.GetGlAbstraction();
1657 gl.EnableTextureCallTrace(true);
1658 application.SendNotification();
1659 application.Render(0);
1661 int textureBindIndex[4];
1662 for( unsigned int i(0); i<4; ++i )
1664 std::stringstream params;
1665 params << GL_TEXTURE_2D<<", "<<i+1;
1666 textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str() );
1669 //Check that actor1 has been rendered after actor2
1670 DALI_TEST_GREATER( textureBindIndex[1], textureBindIndex[2], TEST_LOCATION );
1672 //Check that actor0 has been rendered after actor1
1673 DALI_TEST_GREATER( textureBindIndex[0], textureBindIndex[1], TEST_LOCATION );
1675 //Check that actor3 has been rendered after actor0
1676 DALI_TEST_GREATER( textureBindIndex[3], textureBindIndex[0], TEST_LOCATION );
1681 int UtcDaliRendererRenderOrder2DLayerMultipleRenderers(void)
1683 TestApplication application;
1684 tet_infoline("Test the rendering order in a 2D layer is correct using multiple renderers per actor");
1687 * Creates the following hierarchy:
1689 * actor0------------------------>actor1
1693 * renderer0 renderer1 renderer2 renderer3 renderer4 renderer5
1695 * renderer0 has depth index 2
1696 * renderer1 has depth index 0
1697 * renderer2 has depth index 1
1699 * renderer3 has depth index 1
1700 * renderer4 has depth index 0
1701 * renderer5 has depth index -1
1703 * Expected rendering order: renderer1 - renderer2 - renderer0 - renderer5 - renderer4 - renderer3
1706 Shader shader = Shader::New("VertexSource", "FragmentSource");
1707 PropertyBuffer vertexBuffer = CreatePropertyBuffer();
1708 Geometry geometry = CreateQuadGeometryFromBuffer(vertexBuffer);
1710 Actor actor0 = Actor::New();
1711 actor0.SetAnchorPoint(AnchorPoint::CENTER);
1712 actor0.SetParentOrigin(AnchorPoint::CENTER);
1713 actor0.SetPosition(0.0f,0.0f);
1714 actor0.SetSize(1, 1);
1715 Stage::GetCurrent().Add(actor0);
1717 Actor actor1 = Actor::New();
1718 actor1.SetAnchorPoint(AnchorPoint::CENTER);
1719 actor1.SetParentOrigin(AnchorPoint::CENTER);
1720 actor1.SetPosition(0.0f,0.0f);
1721 actor1.SetSize(1, 1);
1725 Image image0 = BufferImage::New( 64, 64, Pixel::RGB888 );
1726 TextureSet textureSet0 = CreateTextureSet( image0 );
1727 Renderer renderer0 = Renderer::New( geometry, shader );
1728 renderer0.SetTextures( textureSet0 );
1729 renderer0.SetProperty( Renderer::Property::DEPTH_INDEX, 2 );
1730 actor0.AddRenderer(renderer0);
1731 application.SendNotification();
1732 application.Render(0);
1735 Image image1= BufferImage::New( 64, 64, Pixel::RGB888 );
1736 TextureSet textureSet1 = CreateTextureSet( image1 );
1737 Renderer renderer1 = Renderer::New( geometry, shader );
1738 renderer1.SetTextures( textureSet1 );
1739 renderer1.SetProperty( Renderer::Property::DEPTH_INDEX, 0 );
1740 actor0.AddRenderer(renderer1);
1741 application.SendNotification();
1742 application.Render(0);
1745 Image image2= BufferImage::New( 64, 64, Pixel::RGB888 );
1746 TextureSet textureSet2 = CreateTextureSet( image2 );
1747 Renderer renderer2 = Renderer::New( geometry, shader );
1748 renderer2.SetTextures( textureSet2 );
1749 renderer2.SetProperty( Renderer::Property::DEPTH_INDEX, 1 );
1750 actor0.AddRenderer(renderer2);
1751 application.SendNotification();
1752 application.Render(0);
1755 Image image3 = BufferImage::New( 64, 64, Pixel::RGB888 );
1756 TextureSet textureSet3 = CreateTextureSet( image3 );
1757 Renderer renderer3 = Renderer::New( geometry, shader );
1758 renderer3.SetTextures( textureSet3 );
1759 renderer3.SetProperty( Renderer::Property::DEPTH_INDEX, 1 );
1760 actor1.AddRenderer(renderer3);
1761 application.SendNotification();
1762 application.Render(0);
1765 Image image4= BufferImage::New( 64, 64, Pixel::RGB888 );
1766 TextureSet textureSet4 = CreateTextureSet( image4 );
1767 Renderer renderer4 = Renderer::New( geometry, shader );
1768 renderer4.SetTextures( textureSet4 );
1769 renderer4.SetProperty( Renderer::Property::DEPTH_INDEX, 0 );
1770 actor1.AddRenderer(renderer4);
1771 application.SendNotification();
1772 application.Render(0);
1775 Image image5= BufferImage::New( 64, 64, Pixel::RGB888 );
1776 TextureSet textureSet5 = CreateTextureSet( image5 );
1777 Renderer renderer5 = Renderer::New( geometry, shader );
1778 renderer5.SetTextures( textureSet5 );
1779 renderer5.SetProperty( Renderer::Property::DEPTH_INDEX, -1 );
1780 actor1.AddRenderer(renderer5);
1781 application.SendNotification();
1782 application.Render(0);
1785 TestGlAbstraction& gl = application.GetGlAbstraction();
1786 gl.EnableTextureCallTrace(true);
1787 application.SendNotification();
1788 application.Render(0);
1790 int textureBindIndex[6];
1791 for( unsigned int i(0); i<6; ++i )
1793 std::stringstream params;
1794 params << GL_TEXTURE_2D<<", "<<i+1;
1795 textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str() );
1798 //Check that renderer3 has been rendered after renderer4
1799 DALI_TEST_GREATER( textureBindIndex[3], textureBindIndex[4], TEST_LOCATION );
1801 //Check that renderer0 has been rendered after renderer2
1802 DALI_TEST_GREATER( textureBindIndex[4], textureBindIndex[5], TEST_LOCATION );
1804 //Check that renderer0 has been rendered after renderer2
1805 DALI_TEST_GREATER( textureBindIndex[5], textureBindIndex[0], TEST_LOCATION );
1807 //Check that renderer0 has been rendered after renderer2
1808 DALI_TEST_GREATER( textureBindIndex[0], textureBindIndex[2], TEST_LOCATION );
1810 //Check that renderer2 has been rendered after renderer1
1811 DALI_TEST_GREATER( textureBindIndex[2], textureBindIndex[1], TEST_LOCATION );
1816 int UtcDaliRendererRenderOrder2DLayerOverlay(void)
1818 TestApplication application;
1819 tet_infoline("Test the rendering order in a 2D layer is correct for overlays");
1821 Shader shader = Shader::New("VertexSource", "FragmentSource");
1822 PropertyBuffer vertexBuffer = CreatePropertyBuffer();
1823 Geometry geometry = CreateQuadGeometryFromBuffer(vertexBuffer);
1825 Actor actor0 = Actor::New();
1826 actor0.SetAnchorPoint(AnchorPoint::CENTER);
1827 actor0.SetParentOrigin(AnchorPoint::CENTER);
1828 Image image0 = BufferImage::New( 64, 64, Pixel::RGB888 );
1829 TextureSet textureSet0 = CreateTextureSet( image0 );
1830 Renderer renderer0 = Renderer::New( geometry, shader );
1831 renderer0.SetTextures( textureSet0 );
1832 actor0.AddRenderer(renderer0);
1833 actor0.SetPosition(0.0f,0.0f);
1834 actor0.SetSize(100, 100);
1835 Stage::GetCurrent().Add(actor0);
1836 actor0.SetDrawMode( DrawMode::OVERLAY_2D );
1837 application.SendNotification();
1838 application.Render(0);
1840 Actor actor1 = Actor::New();
1841 actor1.SetAnchorPoint(AnchorPoint::CENTER);
1842 actor1.SetParentOrigin(AnchorPoint::CENTER);
1843 Image image1= BufferImage::New( 64, 64, Pixel::RGB888 );
1844 TextureSet textureSet1 = CreateTextureSet( image1 );
1845 Renderer renderer1 = Renderer::New( geometry, shader );
1846 renderer1.SetTextures( textureSet1 );
1847 actor1.SetPosition(0.0f,0.0f);
1848 actor1.AddRenderer(renderer1);
1849 actor1.SetSize(100, 100);
1850 Stage::GetCurrent().Add(actor1);
1851 actor1.SetDrawMode( DrawMode::OVERLAY_2D );
1852 application.SendNotification();
1853 application.Render(0);
1855 Actor actor2 = Actor::New();
1856 actor2.SetAnchorPoint(AnchorPoint::CENTER);
1857 actor2.SetParentOrigin(AnchorPoint::CENTER);
1858 Image image2= BufferImage::New( 64, 64, Pixel::RGB888 );
1859 TextureSet textureSet2 = CreateTextureSet( image2 );
1860 Renderer renderer2 = Renderer::New( geometry, shader );
1861 renderer2.SetTextures( textureSet2 );
1862 actor2.AddRenderer(renderer2);
1863 actor2.SetPosition(0.0f,0.0f);
1864 actor2.SetSize(100, 100);
1865 Stage::GetCurrent().Add(actor2);
1866 application.SendNotification();
1867 application.Render(0);
1869 Actor actor3 = Actor::New();
1870 actor3.SetAnchorPoint(AnchorPoint::CENTER);
1871 actor3.SetParentOrigin(AnchorPoint::CENTER);
1872 Image image3 = BufferImage::New( 64, 64, Pixel::RGB888 );
1873 TextureSet textureSet3 = CreateTextureSet( image3 );
1874 Renderer renderer3 = Renderer::New( geometry, shader );
1875 renderer3.SetTextures( textureSet3 );
1876 actor3.SetPosition(0.0f,0.0f);
1877 actor3.AddRenderer(renderer3);
1878 actor3.SetSize(100, 100);
1879 Stage::GetCurrent().Add(actor3);
1880 actor3.SetDrawMode( DrawMode::OVERLAY_2D );
1881 application.SendNotification();
1882 application.Render(0);
1884 Actor actor4 = Actor::New();
1885 actor4.SetAnchorPoint(AnchorPoint::CENTER);
1886 actor4.SetParentOrigin(AnchorPoint::CENTER);
1887 Image image4 = BufferImage::New( 64, 64, Pixel::RGB888 );
1888 TextureSet textureSet4 = CreateTextureSet( image4 );
1889 Renderer renderer4 = Renderer::New( geometry, shader );
1890 renderer4.SetTextures( textureSet4 );
1891 actor4.AddRenderer(renderer4);
1892 actor4.SetPosition(0.0f,0.0f);
1893 actor4.SetSize(100, 100);
1894 Stage::GetCurrent().Add(actor4);
1895 application.SendNotification();
1896 application.Render(0);
1899 * Create the following hierarchy:
1906 * (Overlay) (Regular actor)
1916 * Expected rendering order : actor2 - actor4 - actor1 - actor0 - actor3
1918 Stage::GetCurrent().Add( actor2 );
1923 application.SendNotification();
1924 application.Render(0);
1926 TestGlAbstraction& gl = application.GetGlAbstraction();
1927 gl.EnableTextureCallTrace(true);
1928 application.SendNotification();
1929 application.Render(0);
1931 int textureBindIndex[5];
1932 for( unsigned int i(0); i<5; ++i )
1934 std::stringstream params;
1935 params << GL_TEXTURE_2D<<", "<<i+1;
1936 textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str() );
1939 //Check that actor4 has been rendered after actor2
1940 DALI_TEST_GREATER( textureBindIndex[4], textureBindIndex[2], TEST_LOCATION );
1942 //Check that actor1 has been rendered after actor4
1943 DALI_TEST_GREATER( textureBindIndex[1], textureBindIndex[4], TEST_LOCATION );
1945 //Check that actor0 has been rendered after actor1
1946 DALI_TEST_GREATER( textureBindIndex[0], textureBindIndex[1], TEST_LOCATION );
1948 //Check that actor3 has been rendered after actor0
1949 DALI_TEST_GREATER( textureBindIndex[3], textureBindIndex[0], TEST_LOCATION );
1954 int UtcDaliRendererSetIndexRange(void)
1958 "attribute vec2 aPosition;\n"
1961 " gl_Position = aPosition;\n"
1967 " gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0)\n"
1971 TestApplication application;
1972 tet_infoline("Test setting the range of indices to draw");
1974 TestGlAbstraction& gl = application.GetGlAbstraction();
1975 gl.EnableDrawCallTrace( true );
1977 Actor actor = Actor::New();
1978 actor.SetSize( 100, 100 );
1981 Geometry geometry = Geometry::New();
1982 geometry.SetGeometryType( Geometry::LINE_LOOP );
1984 // --------------------------------------------------------------------------
1986 unsigned indices[] = { 0, 2, 4, 6, 8, // offset = 0, count = 5
1987 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, // offset = 5, count = 10
1988 1, 3, 5, 7, 9, 1 }; // offset = 15, count = 6 // line strip
1989 Property::Map format;
1990 format["indices"] = Property::INTEGER;
1991 PropertyBuffer indexBuffer = PropertyBuffer::New( format );
1992 indexBuffer.SetData( indices, sizeof(indices)/sizeof(indices[0]));
1994 // --------------------------------------------------------------------------
2003 { Vector2( 0.0f, 1.00f) }, { Vector2( 0.0f, -1.00f) },
2004 { Vector2( -0.95f, 0.31f) }, { Vector2( 0.59f, 0.81f) },
2005 { Vector2( -0.59f, -0.81f) }, { Vector2( -0.95f, -0.31f) },
2006 { Vector2( 0.59f, -0.81f) }, { Vector2( 0.95f, -0.31f) },
2007 { Vector2( 0.95f, 0.31f) }, { Vector2( -0.59f, 0.81f) },
2009 Property::Map vertexFormat;
2010 vertexFormat["aPosition"] = Property::VECTOR2;
2011 PropertyBuffer vertexBuffer = PropertyBuffer::New( vertexFormat );
2012 vertexBuffer.SetData( shapes, sizeof(shapes)/sizeof(shapes[0]));
2014 // --------------------------------------------------------------------------
2015 geometry.SetIndexBuffer( indexBuffer );
2016 geometry.AddVertexBuffer( vertexBuffer );
2019 Shader shader = Shader::New( vertexShader,fragmentShader );
2020 Renderer renderer = Renderer::New( geometry, shader );
2021 actor.AddRenderer( renderer );
2023 Stage stage = Stage::GetCurrent();
2028 // LINE_LOOP, first 0, count 5
2030 renderer.SetIndexRange( 0, 5 );
2031 application.SendNotification();
2032 application.Render();
2033 sprintf( buffer, "%u, 5, %u, indices", GL_LINE_LOOP, GL_UNSIGNED_SHORT );
2034 bool result = gl.GetDrawTrace().FindMethodAndParams( "DrawElements" , buffer );
2035 DALI_TEST_CHECK( result );
2038 // LINE_LOOP, first 5, count 10
2040 renderer.SetIndexRange( 5, 10 );
2041 sprintf( buffer, "%u, 10, %u, indices", GL_LINE_LOOP, GL_UNSIGNED_SHORT );
2042 application.SendNotification();
2043 application.Render();
2044 bool result = gl.GetDrawTrace().FindMethodAndParams( "DrawElements" , buffer );
2045 DALI_TEST_CHECK( result );
2048 // LINE_STRIP, first 15, count 6
2050 renderer.SetIndexRange( 15, 6 );
2051 geometry.SetGeometryType( Geometry::LINE_STRIP );
2052 sprintf( buffer, "%u, 6, %u, indices", GL_LINE_STRIP, GL_UNSIGNED_SHORT );
2053 application.SendNotification();
2054 application.Render();
2055 bool result = gl.GetDrawTrace().FindMethodAndParams( "DrawElements" , buffer );
2056 DALI_TEST_CHECK( result );