2 * Copyright (c) 2016 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.
19 #include <dali/devel-api/actors/actor-devel.h>
21 #include <dali/public-api/dali-core.h>
22 #include <dali/devel-api/images/texture-set-image.h>
27 #include <dali-test-suite-utils.h>
28 #include <test-trace-call-stack.h>
29 #include <mesh-builder.h>
33 namespace // unnamed namespace
36 const BlendFactor::Type DEFAULT_BLEND_FACTOR_SRC_RGB( BlendFactor::SRC_ALPHA );
37 const BlendFactor::Type DEFAULT_BLEND_FACTOR_DEST_RGB( BlendFactor::ONE_MINUS_SRC_ALPHA );
38 const BlendFactor::Type DEFAULT_BLEND_FACTOR_SRC_ALPHA( BlendFactor::ONE );
39 const BlendFactor::Type DEFAULT_BLEND_FACTOR_DEST_ALPHA( BlendFactor::ONE_MINUS_SRC_ALPHA );
41 const BlendEquation::Type DEFAULT_BLEND_EQUATION_RGB( BlendEquation::ADD );
42 const BlendEquation::Type DEFAULT_BLEND_EQUATION_ALPHA( BlendEquation::ADD );
45 * @brief Get GL stencil test enumeration value as a string.
46 * @return The string representation of the value of GL_STENCIL_TEST
48 std::string GetStencilTestString(void)
50 std::stringstream stream;
51 stream << GL_STENCIL_TEST;
56 * @brief Get GL depth test enumeration value as a string.
57 * @return The string representation of the value of GL_DEPTH_TEST
59 std::string GetDepthTestString(void)
61 std::stringstream stream;
62 stream << GL_DEPTH_TEST;
66 void ResetDebugAndFlush( TestApplication& application, TraceCallStack& glEnableDisableStack, TraceCallStack& glStencilFunctionStack )
68 glEnableDisableStack.Reset();
69 glStencilFunctionStack.Reset();
70 application.SendNotification();
74 void TestConstraintNoBlue( Vector4& current, const PropertyInputContainer& inputs )
79 } // unnamed namespace
81 void renderer_test_startup(void)
83 test_return_value = TET_UNDEF;
86 void renderer_test_cleanup(void)
88 test_return_value = TET_PASS;
92 int UtcDaliRendererNew01(void)
94 TestApplication application;
96 Geometry geometry = CreateQuadGeometry();
97 Shader shader = CreateShader();
98 Renderer renderer = Renderer::New(geometry, shader);
100 DALI_TEST_EQUALS( (bool)renderer, true, TEST_LOCATION );
104 int UtcDaliRendererNew02(void)
106 TestApplication application;
108 DALI_TEST_EQUALS( (bool)renderer, false, TEST_LOCATION );
112 int UtcDaliRendererCopyConstructor(void)
114 TestApplication application;
116 Geometry geometry = CreateQuadGeometry();
117 Shader shader = CreateShader();
118 Renderer renderer = Renderer::New(geometry, shader);
120 Renderer rendererCopy( renderer );
121 DALI_TEST_EQUALS( (bool)rendererCopy, true, TEST_LOCATION );
126 int UtcDaliRendererAssignmentOperator(void)
128 TestApplication application;
130 Geometry geometry = CreateQuadGeometry();
131 Shader shader = CreateShader();
132 Renderer renderer = Renderer::New(geometry, shader);
135 DALI_TEST_EQUALS( (bool)renderer2, false, TEST_LOCATION );
137 renderer2 = renderer;
138 DALI_TEST_EQUALS( (bool)renderer2, true, TEST_LOCATION );
142 int UtcDaliRendererDownCast01(void)
144 TestApplication application;
146 Geometry geometry = CreateQuadGeometry();
147 Shader shader = CreateShader();
148 Renderer renderer = Renderer::New(geometry, shader);
150 BaseHandle handle(renderer);
151 Renderer renderer2 = Renderer::DownCast(handle);
152 DALI_TEST_EQUALS( (bool)renderer2, true, TEST_LOCATION );
156 int UtcDaliRendererDownCast02(void)
158 TestApplication application;
160 Handle handle = Handle::New(); // Create a custom object
161 Renderer renderer = Renderer::DownCast(handle);
162 DALI_TEST_EQUALS( (bool)renderer, false, TEST_LOCATION );
166 int UtcDaliRendererSetGetGeometry(void)
168 TestApplication application;
169 tet_infoline( "Test SetGeometry, GetGeometry" );
171 Geometry geometry1 = CreateQuadGeometry();
172 Geometry geometry2 = CreateQuadGeometry();
174 Shader shader = CreateShader();
175 Renderer renderer = Renderer::New(geometry1, shader);
176 Actor actor = Actor::New();
177 actor.AddRenderer(renderer);
178 actor.SetSize(400, 400);
179 Stage::GetCurrent().Add(actor);
181 application.SendNotification();
182 application.Render(0);
183 DALI_TEST_EQUALS( renderer.GetGeometry(), geometry1, TEST_LOCATION );
185 // Set geometry2 to the renderer
186 renderer.SetGeometry( geometry2 );
188 application.SendNotification();
189 application.Render(0);
190 DALI_TEST_EQUALS( renderer.GetGeometry(), geometry2, TEST_LOCATION );
195 int UtcDaliRendererSetGetShader(void)
197 TestApplication application;
198 tet_infoline( "Test SetShader, GetShader" );
200 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
201 glAbstraction.EnableCullFaceCallTrace(true);
203 Shader shader1 = CreateShader();
204 shader1.RegisterProperty( "uFadeColor", Color::RED );
206 Shader shader2 = CreateShader();
207 shader2.RegisterProperty( "uFadeColor", Color::GREEN );
209 Geometry geometry = CreateQuadGeometry();
210 Renderer renderer = Renderer::New(geometry, shader1);
211 Actor actor = Actor::New();
212 actor.AddRenderer(renderer);
213 actor.SetSize(400, 400);
214 Stage::GetCurrent().Add(actor);
216 TestGlAbstraction& gl = application.GetGlAbstraction();
217 application.SendNotification();
218 application.Render(0);
220 // Expect that the first shaders's fade color property is accessed
221 Vector4 actualValue(Vector4::ZERO);
222 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
223 DALI_TEST_EQUALS( actualValue, Color::RED, TEST_LOCATION );
225 DALI_TEST_EQUALS( renderer.GetShader(), shader1, TEST_LOCATION );
227 // set the second shader to the renderer
228 renderer.SetShader( shader2 );
230 application.SendNotification();
231 application.Render(0);
233 // Expect that the second shader's fade color property is accessed
234 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
235 DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
237 DALI_TEST_EQUALS( renderer.GetShader(), shader2, TEST_LOCATION );
242 int UtcDaliRendererSetGetDepthIndex(void)
244 TestApplication application;
246 tet_infoline("Test SetDepthIndex, GetDepthIndex");
248 Shader shader = CreateShader();
249 Geometry geometry = CreateQuadGeometry();
250 Renderer renderer = Renderer::New(geometry, shader);
251 Actor actor = Actor::New();
252 actor.AddRenderer(renderer);
253 actor.SetSize(400, 400);
254 Stage::GetCurrent().Add(actor);
256 application.SendNotification();
257 application.Render(0);
258 DALI_TEST_EQUALS( renderer.GetProperty<int>(Renderer::Property::DEPTH_INDEX), 0, TEST_LOCATION );
260 renderer.SetProperty( Renderer::Property::DEPTH_INDEX, 1 );
262 application.SendNotification();
263 application.Render(0);
264 DALI_TEST_EQUALS( renderer.GetProperty<int>(Renderer::Property::DEPTH_INDEX), 1, TEST_LOCATION );
266 renderer.SetProperty( Renderer::Property::DEPTH_INDEX, 10 );
268 application.SendNotification();
269 application.Render(0);
270 DALI_TEST_EQUALS( renderer.GetProperty<int>(Renderer::Property::DEPTH_INDEX), 10, TEST_LOCATION );
275 int UtcDaliRendererSetGetFaceCullingMode(void)
277 TestApplication application;
279 tet_infoline("Test SetFaceCullingMode(cullingMode)");
280 Geometry geometry = CreateQuadGeometry();
281 Shader shader = CreateShader();
282 Renderer renderer = Renderer::New( geometry, shader );
284 Actor actor = Actor::New();
285 actor.AddRenderer(renderer);
286 actor.SetSize(400, 400);
287 Stage::GetCurrent().Add(actor);
289 // By default, none of the faces should be culled
290 unsigned int cullFace = renderer.GetProperty<int>( Renderer::Property::FACE_CULLING_MODE );
291 DALI_TEST_CHECK( static_cast< FaceCullingMode::Type >( cullFace ) == FaceCullingMode::NONE );
293 TestGlAbstraction& gl = application.GetGlAbstraction();
294 TraceCallStack& cullFaceStack = gl.GetCullFaceTrace();
295 gl.EnableCullFaceCallTrace(true);
298 cullFaceStack.Reset();
299 renderer.SetProperty( Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::FRONT_AND_BACK );
300 application.SendNotification();
301 application.Render();
303 DALI_TEST_EQUALS( cullFaceStack.CountMethod( "CullFace" ), 1, TEST_LOCATION );
305 std::ostringstream cullModeString;
306 cullModeString << GL_FRONT_AND_BACK;
308 DALI_TEST_CHECK( cullFaceStack.FindMethodAndParams( "CullFace", cullModeString.str() ) );
309 cullFace = renderer.GetProperty<int>( Renderer::Property::FACE_CULLING_MODE );
310 DALI_TEST_CHECK( static_cast< FaceCullingMode::Type >( cullFace ) == FaceCullingMode::FRONT_AND_BACK );
314 cullFaceStack.Reset();
315 renderer.SetProperty( Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::BACK );
316 application.SendNotification();
317 application.Render();
319 DALI_TEST_EQUALS( cullFaceStack.CountMethod( "CullFace" ), 1, TEST_LOCATION );
321 std::ostringstream cullModeString;
322 cullModeString << GL_BACK;
324 DALI_TEST_CHECK( cullFaceStack.FindMethodAndParams( "CullFace", cullModeString.str() ) );
325 cullFace = renderer.GetProperty<int>( Renderer::Property::FACE_CULLING_MODE );
326 DALI_TEST_CHECK( static_cast< FaceCullingMode::Type >( cullFace ) == FaceCullingMode::BACK );
330 cullFaceStack.Reset();
331 renderer.SetProperty( Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::FRONT );
332 application.SendNotification();
333 application.Render();
335 DALI_TEST_EQUALS( cullFaceStack.CountMethod( "CullFace" ), 1, TEST_LOCATION );
337 std::ostringstream cullModeString;
338 cullModeString << GL_FRONT;
340 DALI_TEST_CHECK( cullFaceStack.FindMethodAndParams( "CullFace", cullModeString.str() ) );
341 cullFace = renderer.GetProperty<int>( Renderer::Property::FACE_CULLING_MODE );
342 DALI_TEST_CHECK( static_cast< FaceCullingMode::Type >( cullFace ) == FaceCullingMode::FRONT );
346 cullFaceStack.Reset();
347 renderer.SetProperty( Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::NONE );
348 application.SendNotification();
349 application.Render();
351 DALI_TEST_EQUALS( cullFaceStack.CountMethod( "CullFace" ), 0, TEST_LOCATION );
352 cullFace = renderer.GetProperty<int>( Renderer::Property::FACE_CULLING_MODE );
353 DALI_TEST_CHECK( static_cast< FaceCullingMode::Type >( cullFace ) == FaceCullingMode::NONE );
359 int UtcDaliRendererBlendOptions01(void)
361 TestApplication application;
363 tet_infoline("Test BLEND_FACTOR properties ");
365 Geometry geometry = CreateQuadGeometry();
366 Shader shader = CreateShader();
367 Renderer renderer = Renderer::New( geometry, shader );
369 Actor actor = Actor::New();
370 // set a transparent actor color so that blending is enabled
371 actor.SetOpacity( 0.5f );
372 actor.AddRenderer(renderer);
373 actor.SetSize(400, 400);
374 Stage::GetCurrent().Add(actor);
376 renderer.SetProperty( Renderer::Property::BLEND_FACTOR_SRC_RGB, BlendFactor::ONE_MINUS_SRC_COLOR );
377 renderer.SetProperty( Renderer::Property::BLEND_FACTOR_DEST_RGB, BlendFactor::SRC_ALPHA_SATURATE );
378 renderer.SetProperty( Renderer::Property::BLEND_FACTOR_SRC_ALPHA, BlendFactor::ONE_MINUS_SRC_COLOR );
379 renderer.SetProperty( Renderer::Property::BLEND_FACTOR_DEST_ALPHA, BlendFactor::SRC_ALPHA_SATURATE );
381 // Test that Set was successful:
382 int srcFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
383 int destFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
384 int srcFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
385 int destFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
387 DALI_TEST_EQUALS( (int)BlendFactor::ONE_MINUS_SRC_COLOR, srcFactorRgb, TEST_LOCATION );
388 DALI_TEST_EQUALS( (int)BlendFactor::SRC_ALPHA_SATURATE, destFactorRgb, TEST_LOCATION );
389 DALI_TEST_EQUALS( (int)BlendFactor::ONE_MINUS_SRC_COLOR, srcFactorAlpha, TEST_LOCATION );
390 DALI_TEST_EQUALS( (int)BlendFactor::SRC_ALPHA_SATURATE, destFactorAlpha, TEST_LOCATION );
392 application.SendNotification();
393 application.Render();
395 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
397 DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_SRC_COLOR, glAbstraction.GetLastBlendFuncSrcRgb(), TEST_LOCATION );
398 DALI_TEST_EQUALS( (GLenum)GL_SRC_ALPHA_SATURATE, glAbstraction.GetLastBlendFuncDstRgb(), TEST_LOCATION );
399 DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_SRC_COLOR, glAbstraction.GetLastBlendFuncSrcAlpha(), TEST_LOCATION );
400 DALI_TEST_EQUALS( (GLenum)GL_SRC_ALPHA_SATURATE, glAbstraction.GetLastBlendFuncDstAlpha(), TEST_LOCATION );
405 int UtcDaliRendererBlendOptions02(void)
407 TestApplication application;
409 tet_infoline("Test BLEND_FACTOR properties ");
411 Geometry geometry = CreateQuadGeometry();
412 Shader shader = CreateShader();
413 Renderer renderer = Renderer::New( geometry, shader );
415 Actor actor = Actor::New();
416 actor.SetOpacity( 0.5f ); // enable blending
417 actor.AddRenderer(renderer);
418 actor.SetSize(400, 400);
419 Stage::GetCurrent().Add(actor);
421 renderer.SetProperty( Renderer::Property::BLEND_FACTOR_SRC_RGB, BlendFactor::CONSTANT_COLOR );
422 renderer.SetProperty( Renderer::Property::BLEND_FACTOR_DEST_RGB, BlendFactor::ONE_MINUS_CONSTANT_COLOR );
423 renderer.SetProperty( Renderer::Property::BLEND_FACTOR_SRC_ALPHA, BlendFactor::CONSTANT_ALPHA );
424 renderer.SetProperty( Renderer::Property::BLEND_FACTOR_DEST_ALPHA, BlendFactor::ONE_MINUS_CONSTANT_ALPHA );
426 // Test that Set was successful:
428 int srcFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
429 int destFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
430 int srcFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
431 int destFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
433 DALI_TEST_EQUALS( (int)BlendFactor::CONSTANT_COLOR, srcFactorRgb, TEST_LOCATION );
434 DALI_TEST_EQUALS( (int)BlendFactor::ONE_MINUS_CONSTANT_COLOR, destFactorRgb, TEST_LOCATION );
435 DALI_TEST_EQUALS( (int)BlendFactor::CONSTANT_ALPHA, srcFactorAlpha, TEST_LOCATION );
436 DALI_TEST_EQUALS( (int)BlendFactor::ONE_MINUS_CONSTANT_ALPHA, destFactorAlpha, TEST_LOCATION );
439 application.SendNotification();
440 application.Render();
442 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
443 DALI_TEST_EQUALS( (GLenum)GL_CONSTANT_COLOR, glAbstraction.GetLastBlendFuncSrcRgb(), TEST_LOCATION );
444 DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_CONSTANT_COLOR, glAbstraction.GetLastBlendFuncDstRgb(), TEST_LOCATION );
445 DALI_TEST_EQUALS( (GLenum)GL_CONSTANT_ALPHA, glAbstraction.GetLastBlendFuncSrcAlpha(), TEST_LOCATION );
446 DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_CONSTANT_ALPHA, glAbstraction.GetLastBlendFuncDstAlpha(), TEST_LOCATION );
451 int UtcDaliRendererBlendOptions03(void)
453 TestApplication application;
455 tet_infoline("Test GetBlendEquation() defaults ");
457 Geometry geometry = CreateQuadGeometry();
458 Shader shader = CreateShader();
459 Renderer renderer = Renderer::New( geometry, shader );
461 Actor actor = Actor::New();
462 actor.AddRenderer(renderer);
463 actor.SetSize(400, 400);
464 Stage::GetCurrent().Add(actor);
466 // Test the defaults as documented in blending.h
467 int equationRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_EQUATION_RGB );
468 int equationAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_EQUATION_ALPHA );
470 DALI_TEST_EQUALS( (int)BlendEquation::ADD, equationRgb, TEST_LOCATION );
471 DALI_TEST_EQUALS( (int)BlendEquation::ADD, equationAlpha, TEST_LOCATION );
476 int UtcDaliRendererBlendOptions04(void)
478 TestApplication application;
480 tet_infoline("Test SetBlendEquation() ");
482 Geometry geometry = CreateQuadGeometry();
483 Shader shader = CreateShader();
484 Renderer renderer = Renderer::New( geometry, shader );
486 Actor actor = Actor::New();
487 actor.SetOpacity( 0.1f );
488 actor.AddRenderer(renderer);
489 actor.SetSize(400, 400);
490 Stage::GetCurrent().Add(actor);
492 // Test the single blending equation setting
494 renderer.SetProperty( Renderer::Property::BLEND_EQUATION_RGB, BlendEquation::REVERSE_SUBTRACT );
495 int equationRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_EQUATION_RGB );
496 DALI_TEST_EQUALS( (int)BlendEquation::REVERSE_SUBTRACT, equationRgb, TEST_LOCATION );
499 renderer.SetProperty( Renderer::Property::BLEND_EQUATION_RGB, BlendEquation::REVERSE_SUBTRACT );
500 renderer.SetProperty( Renderer::Property::BLEND_EQUATION_ALPHA, BlendEquation::REVERSE_SUBTRACT );
502 // Test that Set was successful
504 int equationRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_EQUATION_RGB );
505 int equationAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_EQUATION_ALPHA );
506 DALI_TEST_EQUALS( (int)BlendEquation::REVERSE_SUBTRACT, equationRgb, TEST_LOCATION );
507 DALI_TEST_EQUALS( (int)BlendEquation::REVERSE_SUBTRACT, equationAlpha, TEST_LOCATION );
510 // Render & check GL commands
511 application.SendNotification();
512 application.Render();
514 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
515 DALI_TEST_EQUALS( (GLenum)GL_FUNC_REVERSE_SUBTRACT, glAbstraction.GetLastBlendEquationRgb(), TEST_LOCATION );
516 DALI_TEST_EQUALS( (GLenum)GL_FUNC_REVERSE_SUBTRACT, glAbstraction.GetLastBlendEquationAlpha(), TEST_LOCATION );
521 int UtcDaliRendererSetBlendMode01(void)
523 TestApplication application;
525 tet_infoline("Test setting the blend mode to on with an opaque color renders with blending enabled");
527 Geometry geometry = CreateQuadGeometry();
528 Shader shader = CreateShader();
529 Renderer renderer = Renderer::New( geometry, shader );
531 Actor actor = Actor::New();
532 actor.SetOpacity( 0.98f );
533 actor.AddRenderer(renderer);
534 actor.SetSize(400, 400);
535 Stage::GetCurrent().Add(actor);
537 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::ON);
539 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
540 glAbstraction.EnableEnableDisableCallTrace(true);
542 application.SendNotification();
543 application.Render();
545 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
546 std::ostringstream blendStr;
547 blendStr << GL_BLEND;
548 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
553 int UtcDaliRendererSetBlendMode02(void)
555 TestApplication application;
557 tet_infoline("Test setting the blend mode to off with a transparent color renders with blending disabled (and not enabled)");
559 Geometry geometry = CreateQuadGeometry();
560 Shader shader = CreateShader();
561 Renderer renderer = Renderer::New( geometry, shader );
563 Actor actor = Actor::New();
564 actor.SetOpacity( 0.15f );
565 actor.AddRenderer(renderer);
566 actor.SetSize(400, 400);
567 Stage::GetCurrent().Add(actor);
569 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::OFF);
571 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
572 glAbstraction.EnableEnableDisableCallTrace(true);
574 application.SendNotification();
575 application.Render();
577 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
578 std::ostringstream blendStr;
579 blendStr << GL_BLEND;
580 DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
585 int UtcDaliRendererSetBlendMode03(void)
587 TestApplication application;
589 tet_infoline("Test setting the blend mode to auto with a transparent color renders with blending enabled");
591 Geometry geometry = CreateQuadGeometry();
592 Shader shader = CreateShader();
593 Renderer renderer = Renderer::New( geometry, shader );
595 Actor actor = Actor::New();
596 actor.SetOpacity( 0.75f );
597 actor.AddRenderer(renderer);
598 actor.SetSize(400, 400);
599 Stage::GetCurrent().Add(actor);
601 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::AUTO);
603 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
604 glAbstraction.EnableEnableDisableCallTrace(true);
606 application.SendNotification();
607 application.Render();
609 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
610 std::ostringstream blendStr;
611 blendStr << GL_BLEND;
612 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
617 int UtcDaliRendererSetBlendMode04(void)
619 TestApplication application;
621 tet_infoline("Test setting the blend mode to auto with an opaque color renders with blending disabled");
623 Geometry geometry = CreateQuadGeometry();
624 Shader shader = CreateShader();
625 Renderer renderer = Renderer::New( geometry, shader );
627 Actor actor = Actor::New();
628 actor.AddRenderer(renderer);
629 actor.SetSize(400, 400);
630 Stage::GetCurrent().Add(actor);
632 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::AUTO);
634 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
635 glAbstraction.EnableEnableDisableCallTrace(true);
637 application.SendNotification();
638 application.Render();
640 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
641 std::ostringstream blendStr;
642 blendStr << GL_BLEND;
643 DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
648 int UtcDaliRendererSetBlendMode04b(void)
650 TestApplication application;
652 tet_infoline("Test setting the blend mode to auto with a transparent actor color renders with blending enabled");
654 Geometry geometry = CreateQuadGeometry();
655 Shader shader = CreateShader();
656 Renderer renderer = Renderer::New( geometry, shader );
658 Actor actor = Actor::New();
659 actor.AddRenderer(renderer);
660 actor.SetSize(400, 400);
661 actor.SetColor( Vector4(1.0f, 0.0f, 1.0f, 0.5f) );
662 Stage::GetCurrent().Add(actor);
664 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::AUTO);
666 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
667 glAbstraction.EnableEnableDisableCallTrace(true);
669 application.SendNotification();
670 application.Render();
672 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
673 std::ostringstream blendStr;
674 blendStr << GL_BLEND;
675 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
680 int UtcDaliRendererSetBlendMode04c(void)
682 TestApplication application;
684 tet_infoline("Test setting the blend mode to auto with an opaque opaque actor color renders with blending disabled");
686 Geometry geometry = CreateQuadGeometry();
687 Shader shader = CreateShader();
688 Renderer renderer = Renderer::New( geometry, shader );
690 Actor actor = Actor::New();
691 actor.AddRenderer(renderer);
692 actor.SetSize(400, 400);
693 actor.SetColor( Color::MAGENTA );
694 Stage::GetCurrent().Add(actor);
696 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::AUTO);
698 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
699 glAbstraction.EnableEnableDisableCallTrace(true);
701 application.SendNotification();
702 application.Render();
704 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
705 std::ostringstream blendStr;
706 blendStr << GL_BLEND;
707 DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
712 int UtcDaliRendererSetBlendMode05(void)
714 TestApplication application;
716 tet_infoline("Test setting the blend mode to auto with an opaque color and an image with an alpha channel renders with blending enabled");
718 Geometry geometry = CreateQuadGeometry();
719 BufferImage image = BufferImage::New( 40, 40, Pixel::RGBA8888 );
721 Shader shader = CreateShader();
722 TextureSet textureSet = CreateTextureSet( image );
723 Renderer renderer = Renderer::New( geometry, shader );
724 renderer.SetTextures( textureSet );
726 Actor actor = Actor::New();
727 actor.AddRenderer(renderer);
728 actor.SetSize(400, 400);
729 Stage::GetCurrent().Add(actor);
731 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::AUTO);
733 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
734 glAbstraction.EnableEnableDisableCallTrace(true);
736 application.SendNotification();
737 application.Render();
739 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
740 std::ostringstream blendStr;
741 blendStr << GL_BLEND;
742 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
747 int UtcDaliRendererSetBlendMode06(void)
749 TestApplication application;
750 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");
752 Geometry geometry = CreateQuadGeometry();
753 Shader shader = Shader::New( "vertexSrc", "fragmentSrc", Shader::Hint::OUTPUT_IS_TRANSPARENT );
755 Renderer renderer = Renderer::New( geometry, shader );
757 Actor actor = Actor::New();
758 actor.AddRenderer(renderer);
759 actor.SetSize(400, 400);
760 Stage::GetCurrent().Add(actor);
762 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::AUTO);
764 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
765 glAbstraction.EnableEnableDisableCallTrace(true);
767 application.SendNotification();
768 application.Render();
770 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
771 std::ostringstream blendStr;
772 blendStr << GL_BLEND;
773 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
778 int UtcDaliRendererSetBlendMode07(void)
780 TestApplication application;
781 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");
783 Geometry geometry = CreateQuadGeometry();
784 Shader shader = Shader::New( "vertexSrc", "fragmentSrc" );
786 BufferImage image = BufferImage::New( 50, 50, Pixel::RGB888 );
787 TextureSet textureSet = CreateTextureSet( image );
788 Renderer renderer = Renderer::New( geometry, shader );
789 renderer.SetTextures( textureSet );
791 Actor actor = Actor::New();
792 actor.AddRenderer(renderer);
793 actor.SetSize(400, 400);
794 Stage::GetCurrent().Add(actor);
796 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::AUTO);
798 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
799 glAbstraction.EnableEnableDisableCallTrace(true);
801 application.SendNotification();
802 application.Render();
804 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
805 DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", "GL_BLEND" ) );
810 int UtcDaliRendererGetBlendMode(void)
812 TestApplication application;
814 tet_infoline("Test GetBlendMode()");
816 Geometry geometry = CreateQuadGeometry();
817 Shader shader = Shader::New( "vertexSrc", "fragmentSrc" );
818 Renderer renderer = Renderer::New( geometry, shader );
821 unsigned int mode = renderer.GetProperty<int>( Renderer::Property::BLEND_MODE );
822 DALI_TEST_EQUALS( static_cast< BlendMode::Type >( mode ), BlendMode::AUTO, TEST_LOCATION );
825 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::ON );
826 mode = renderer.GetProperty<int>( Renderer::Property::BLEND_MODE );
827 DALI_TEST_EQUALS( static_cast< BlendMode::Type >( mode ), BlendMode::ON, TEST_LOCATION );
830 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::OFF );
831 mode = renderer.GetProperty<int>( Renderer::Property::BLEND_MODE );
832 DALI_TEST_EQUALS( static_cast< BlendMode::Type >( mode ), BlendMode::OFF, TEST_LOCATION );
837 int UtcDaliRendererSetBlendColor(void)
839 TestApplication application;
841 tet_infoline("Test SetBlendColor(color)");
843 Geometry geometry = CreateQuadGeometry();
844 Shader shader = Shader::New( "vertexSrc", "fragmentSrc" );
845 TextureSet textureSet = TextureSet::New();
846 BufferImage image = BufferImage::New( 50, 50, Pixel::RGBA8888 );
847 TextureSetImage( textureSet, 0u, image );
848 Renderer renderer = Renderer::New( geometry, shader );
849 renderer.SetTextures( textureSet );
851 Actor actor = Actor::New();
852 actor.AddRenderer(renderer);
853 actor.SetSize(400, 400);
854 Stage::GetCurrent().Add(actor);
856 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
858 renderer.SetProperty( Renderer::Property::BLEND_COLOR, Color::TRANSPARENT );
859 application.SendNotification();
860 application.Render();
861 DALI_TEST_EQUALS( glAbstraction.GetLastBlendColor(), Color::TRANSPARENT, TEST_LOCATION );
863 renderer.SetProperty( Renderer::Property::BLEND_COLOR, Color::MAGENTA );
864 application.SendNotification();
865 application.Render();
866 DALI_TEST_EQUALS( glAbstraction.GetLastBlendColor(), Color::MAGENTA, TEST_LOCATION );
868 Vector4 color( 0.1f, 0.2f, 0.3f, 0.4f );
869 renderer.SetProperty( Renderer::Property::BLEND_COLOR, color );
870 application.SendNotification();
871 application.Render();
872 DALI_TEST_EQUALS( glAbstraction.GetLastBlendColor(), color, TEST_LOCATION );
877 int UtcDaliRendererGetBlendColor(void)
879 TestApplication application;
881 tet_infoline("Test GetBlendColor()");
883 Geometry geometry = CreateQuadGeometry();
884 Shader shader = Shader::New( "vertexSrc", "fragmentSrc" );
885 Renderer renderer = Renderer::New( geometry, shader );
887 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>( Renderer::Property::BLEND_COLOR ), Color::TRANSPARENT, TEST_LOCATION );
889 renderer.SetProperty( Renderer::Property::BLEND_COLOR, Color::MAGENTA );
890 application.SendNotification();
891 application.Render();
892 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>( Renderer::Property::BLEND_COLOR ), Color::MAGENTA, TEST_LOCATION );
894 Vector4 color( 0.1f, 0.2f, 0.3f, 0.4f );
895 renderer.SetProperty( Renderer::Property::BLEND_COLOR, color );
896 application.SendNotification();
897 application.Render();
898 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>( Renderer::Property::BLEND_COLOR ), color, TEST_LOCATION );
903 int UtcDaliRendererPreMultipledAlpha(void)
905 TestApplication application;
907 tet_infoline("Test BLEND_PRE_MULTIPLIED_ALPHA property");
909 Geometry geometry = CreateQuadGeometry();
910 Shader shader = Shader::New( "vertexSrc", "fragmentSrc" );
911 Renderer renderer = Renderer::New( geometry, shader );
913 Actor actor = Actor::New();
914 actor.AddRenderer(renderer);
915 actor.SetSize(400, 400);
916 actor.SetColor( Vector4(1.0f, 0.0f, 1.0f, 0.5f) );
917 Stage::GetCurrent().Add(actor);
919 Property::Value value = renderer.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
920 bool preMultipliedAlpha;
921 DALI_TEST_CHECK( value.Get( preMultipliedAlpha ) );
922 DALI_TEST_CHECK( !preMultipliedAlpha );
924 int srcFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
925 int destFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
926 int srcFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
927 int destFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
929 DALI_TEST_EQUALS( (int)DEFAULT_BLEND_FACTOR_SRC_RGB, srcFactorRgb, TEST_LOCATION );
930 DALI_TEST_EQUALS( (int)DEFAULT_BLEND_FACTOR_DEST_RGB, destFactorRgb, TEST_LOCATION );
931 DALI_TEST_EQUALS( (int)DEFAULT_BLEND_FACTOR_SRC_ALPHA, srcFactorAlpha, TEST_LOCATION );
932 DALI_TEST_EQUALS( (int)DEFAULT_BLEND_FACTOR_DEST_ALPHA, destFactorAlpha, TEST_LOCATION );
934 application.SendNotification();
935 application.Render();
937 Vector4 actualValue(Vector4::ZERO);
938 TestGlAbstraction& gl = application.GetGlAbstraction();
939 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uColor", actualValue ) );
940 DALI_TEST_EQUALS( actualValue, Vector4(1.0f, 0.0f, 1.0f, 0.5f), TEST_LOCATION );
942 renderer.SetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, true);
944 application.SendNotification();
945 application.Render();
947 value = renderer.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
948 DALI_TEST_CHECK( value.Get( preMultipliedAlpha ) );
949 DALI_TEST_CHECK( preMultipliedAlpha );
951 srcFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
952 destFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
953 srcFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
954 destFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
956 DALI_TEST_EQUALS( (int)BlendFactor::ONE, srcFactorRgb, TEST_LOCATION );
957 DALI_TEST_EQUALS( (int)BlendFactor::ONE_MINUS_SRC_ALPHA, destFactorRgb, TEST_LOCATION );
958 DALI_TEST_EQUALS( (int)BlendFactor::ONE, srcFactorAlpha, TEST_LOCATION );
959 DALI_TEST_EQUALS( (int)BlendFactor::ONE, destFactorAlpha, TEST_LOCATION );
961 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uColor", actualValue ) );
962 DALI_TEST_EQUALS( actualValue, Vector4(0.5f, 0.0f, 0.5f, 0.5f), TEST_LOCATION );
967 int UtcDaliRendererConstraint01(void)
969 TestApplication application;
971 tet_infoline("Test that a non-uniform renderer property can be constrained");
973 Shader shader = Shader::New("VertexSource", "FragmentSource");
974 Geometry geometry = CreateQuadGeometry();
975 Renderer renderer = Renderer::New( geometry, shader );
977 Actor actor = Actor::New();
978 actor.AddRenderer(renderer);
979 actor.SetSize(400, 400);
980 Stage::GetCurrent().Add(actor);
982 Vector4 initialColor = Color::WHITE;
983 Property::Index colorIndex = renderer.RegisterProperty( "uFadeColor", initialColor );
985 application.SendNotification();
986 application.Render(0);
987 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION );
990 Constraint constraint = Constraint::New<Vector4>( renderer, colorIndex, TestConstraintNoBlue );
992 application.SendNotification();
993 application.Render(0);
995 // Expect no blue component in either buffer - yellow
996 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(colorIndex), Color::YELLOW, TEST_LOCATION );
997 application.Render(0);
998 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(colorIndex), Color::YELLOW, TEST_LOCATION );
1000 renderer.RemoveConstraints();
1001 renderer.SetProperty(colorIndex, Color::WHITE );
1002 application.SendNotification();
1003 application.Render(0);
1004 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(colorIndex), Color::WHITE, TEST_LOCATION );
1009 int UtcDaliRendererConstraint02(void)
1011 TestApplication application;
1013 tet_infoline("Test that a uniform map renderer property can be constrained");
1015 Shader shader = Shader::New("VertexSource", "FragmentSource");
1016 Geometry geometry = CreateQuadGeometry();
1017 Renderer renderer = Renderer::New( geometry, shader );
1019 Actor actor = Actor::New();
1020 actor.AddRenderer(renderer);
1021 actor.SetSize(400, 400);
1022 Stage::GetCurrent().Add(actor);
1023 application.SendNotification();
1024 application.Render(0);
1026 Vector4 initialColor = Color::WHITE;
1027 Property::Index colorIndex = renderer.RegisterProperty( "uFadeColor", initialColor );
1029 TestGlAbstraction& gl = application.GetGlAbstraction();
1031 application.SendNotification();
1032 application.Render(0);
1034 Vector4 actualValue(Vector4::ZERO);
1035 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1036 DALI_TEST_EQUALS( actualValue, initialColor, TEST_LOCATION );
1039 Constraint constraint = Constraint::New<Vector4>( renderer, colorIndex, TestConstraintNoBlue );
1041 application.SendNotification();
1042 application.Render(0);
1044 // Expect no blue component in either buffer - yellow
1045 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1046 DALI_TEST_EQUALS( actualValue, Color::YELLOW, TEST_LOCATION );
1048 application.Render(0);
1049 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1050 DALI_TEST_EQUALS( actualValue, Color::YELLOW, TEST_LOCATION );
1052 renderer.RemoveConstraints();
1053 renderer.SetProperty(colorIndex, Color::WHITE );
1054 application.SendNotification();
1055 application.Render(0);
1057 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1058 DALI_TEST_EQUALS( actualValue, Color::WHITE, TEST_LOCATION );
1063 int UtcDaliRendererAnimatedProperty01(void)
1065 TestApplication application;
1067 tet_infoline("Test that a non-uniform renderer property can be animated");
1069 Shader shader = Shader::New("VertexSource", "FragmentSource");
1070 Geometry geometry = CreateQuadGeometry();
1071 Renderer renderer = Renderer::New( geometry, shader );
1073 Actor actor = Actor::New();
1074 actor.AddRenderer(renderer);
1075 actor.SetSize(400, 400);
1076 Stage::GetCurrent().Add(actor);
1078 Vector4 initialColor = Color::WHITE;
1079 Property::Index colorIndex = renderer.RegisterProperty( "uFadeColor", initialColor );
1081 application.SendNotification();
1082 application.Render(0);
1083 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION );
1085 Animation animation = Animation::New(1.0f);
1086 KeyFrames keyFrames = KeyFrames::New();
1087 keyFrames.Add(0.0f, initialColor);
1088 keyFrames.Add(1.0f, Color::TRANSPARENT);
1089 animation.AnimateBetween( Property( renderer, colorIndex ), keyFrames );
1092 application.SendNotification();
1093 application.Render(500);
1095 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(colorIndex), Color::WHITE * 0.5f, TEST_LOCATION );
1097 application.Render(500);
1099 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(colorIndex), Color::TRANSPARENT, TEST_LOCATION );
1104 int UtcDaliRendererAnimatedProperty02(void)
1106 TestApplication application;
1108 tet_infoline("Test that a uniform map renderer property can be animated");
1110 Shader shader = Shader::New("VertexSource", "FragmentSource");
1111 Geometry geometry = CreateQuadGeometry();
1112 Renderer renderer = Renderer::New( geometry, shader );
1114 Actor actor = Actor::New();
1115 actor.AddRenderer(renderer);
1116 actor.SetSize(400, 400);
1117 Stage::GetCurrent().Add(actor);
1118 application.SendNotification();
1119 application.Render(0);
1121 Vector4 initialColor = Color::WHITE;
1122 Property::Index colorIndex = renderer.RegisterProperty( "uFadeColor", initialColor );
1124 TestGlAbstraction& gl = application.GetGlAbstraction();
1126 application.SendNotification();
1127 application.Render(0);
1129 Vector4 actualValue(Vector4::ZERO);
1130 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1131 DALI_TEST_EQUALS( actualValue, initialColor, TEST_LOCATION );
1133 Animation animation = Animation::New(1.0f);
1134 KeyFrames keyFrames = KeyFrames::New();
1135 keyFrames.Add(0.0f, initialColor);
1136 keyFrames.Add(1.0f, Color::TRANSPARENT);
1137 animation.AnimateBetween( Property( renderer, colorIndex ), keyFrames );
1140 application.SendNotification();
1141 application.Render(500);
1143 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1144 DALI_TEST_EQUALS( actualValue, Color::WHITE * 0.5f, TEST_LOCATION );
1146 application.Render(500);
1147 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1148 DALI_TEST_EQUALS( actualValue, Color::TRANSPARENT, TEST_LOCATION );
1153 int UtcDaliRendererUniformMapPrecendence01(void)
1155 TestApplication application;
1157 tet_infoline("Test the uniform map precedence is applied properly");
1159 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1161 Shader shader = Shader::New("VertexSource", "FragmentSource");
1162 TextureSet textureSet = CreateTextureSet( image );
1164 Geometry geometry = CreateQuadGeometry();
1165 Renderer renderer = Renderer::New( geometry, shader );
1166 renderer.SetTextures( textureSet );
1168 Actor actor = Actor::New();
1169 actor.AddRenderer(renderer);
1170 actor.SetSize(400, 400);
1171 Stage::GetCurrent().Add(actor);
1172 application.SendNotification();
1173 application.Render(0);
1175 renderer.RegisterProperty( "uFadeColor", Color::RED );
1176 actor.RegisterProperty( "uFadeColor", Color::GREEN );
1177 Property::Index shaderFadeColorIndex = shader.RegisterProperty( "uFadeColor", Color::MAGENTA );
1179 TestGlAbstraction& gl = application.GetGlAbstraction();
1181 application.SendNotification();
1182 application.Render(0);
1184 // Expect that the actor's fade color property is accessed
1185 Vector4 actualValue(Vector4::ZERO);
1186 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1187 DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
1189 // Animate shader's fade color property. Should be no change to uniform
1190 Animation animation = Animation::New(1.0f);
1191 KeyFrames keyFrames = KeyFrames::New();
1192 keyFrames.Add(0.0f, Color::WHITE);
1193 keyFrames.Add(1.0f, Color::TRANSPARENT);
1194 animation.AnimateBetween( Property( shader, shaderFadeColorIndex ), keyFrames );
1197 application.SendNotification();
1198 application.Render(500);
1200 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1201 DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
1203 application.Render(500);
1204 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1205 DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
1210 int UtcDaliRendererUniformMapPrecendence02(void)
1212 TestApplication application;
1214 tet_infoline("Test the uniform map precedence is applied properly");
1216 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1218 Shader shader = Shader::New("VertexSource", "FragmentSource");
1219 TextureSet textureSet = CreateTextureSet( image );
1221 Geometry geometry = CreateQuadGeometry();
1222 Renderer renderer = Renderer::New( geometry, shader );
1223 renderer.SetTextures( textureSet );
1225 Actor actor = Actor::New();
1226 actor.AddRenderer(renderer);
1227 actor.SetSize(400, 400);
1228 Stage::GetCurrent().Add(actor);
1229 application.SendNotification();
1230 application.Render(0);
1232 // Don't add property / uniform map to renderer
1233 actor.RegisterProperty( "uFadeColor", Color::GREEN );
1234 Property::Index shaderFadeColorIndex = shader.RegisterProperty( "uFadeColor", Color::BLUE );
1236 TestGlAbstraction& gl = application.GetGlAbstraction();
1238 application.SendNotification();
1239 application.Render(0);
1241 // Expect that the actor's fade color property is accessed
1242 Vector4 actualValue(Vector4::ZERO);
1243 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1244 DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
1246 // Animate texture set's fade color property. Should be no change to uniform
1247 Animation animation = Animation::New(1.0f);
1248 KeyFrames keyFrames = KeyFrames::New();
1249 keyFrames.Add(0.0f, Color::WHITE);
1250 keyFrames.Add(1.0f, Color::TRANSPARENT);
1251 animation.AnimateBetween( Property( shader, shaderFadeColorIndex ), keyFrames );
1254 application.SendNotification();
1255 application.Render(500);
1257 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1258 DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
1260 application.Render(500);
1261 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1262 DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
1268 int UtcDaliRendererUniformMapPrecendence03(void)
1270 TestApplication application;
1272 tet_infoline("Test the uniform map precedence is applied properly");
1274 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1276 Shader shader = Shader::New("VertexSource", "FragmentSource");
1277 TextureSet textureSet = CreateTextureSet( image );
1279 Geometry geometry = CreateQuadGeometry();
1280 Renderer renderer = Renderer::New( geometry, shader );
1281 renderer.SetTextures( textureSet );
1283 Actor actor = Actor::New();
1284 actor.AddRenderer(renderer);
1285 actor.SetSize(400, 400);
1286 Stage::GetCurrent().Add(actor);
1287 application.SendNotification();
1288 application.Render(0);
1290 // Don't add property / uniform map to renderer or actor
1291 shader.RegisterProperty( "uFadeColor", Color::BLACK );
1293 TestGlAbstraction& gl = application.GetGlAbstraction();
1295 application.SendNotification();
1296 application.Render(0);
1298 // Expect that the shader's fade color property is accessed
1299 Vector4 actualValue(Vector4::ZERO);
1300 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1301 DALI_TEST_EQUALS( actualValue, Color::BLACK, TEST_LOCATION );
1306 int UtcDaliRendererUniformMapMultipleUniforms01(void)
1308 TestApplication application;
1310 tet_infoline("Test the uniform maps are collected from all objects (same type)");
1312 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1314 Shader shader = Shader::New("VertexSource", "FragmentSource");
1315 TextureSet textureSet = CreateTextureSet( image );
1317 Geometry geometry = CreateQuadGeometry();
1318 Renderer renderer = Renderer::New( geometry, shader );
1319 renderer.SetTextures( textureSet );
1321 Actor actor = Actor::New();
1322 actor.AddRenderer(renderer);
1323 actor.SetSize(400, 400);
1324 Stage::GetCurrent().Add(actor);
1325 application.SendNotification();
1326 application.Render(0);
1328 renderer.RegisterProperty( "uUniform1", Color::RED );
1329 actor.RegisterProperty( "uUniform2", Color::GREEN );
1330 shader.RegisterProperty( "uUniform3", Color::MAGENTA );
1332 TestGlAbstraction& gl = application.GetGlAbstraction();
1334 application.SendNotification();
1335 application.Render(0);
1337 // Expect that each of the object's uniforms are set
1338 Vector4 uniform1Value(Vector4::ZERO);
1339 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uUniform1", uniform1Value ) );
1340 DALI_TEST_EQUALS( uniform1Value, Color::RED, TEST_LOCATION );
1342 Vector4 uniform2Value(Vector4::ZERO);
1343 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uUniform2", uniform2Value ) );
1344 DALI_TEST_EQUALS( uniform2Value, Color::GREEN, TEST_LOCATION );
1346 Vector4 uniform3Value(Vector4::ZERO);
1347 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uUniform3", uniform3Value ) );
1348 DALI_TEST_EQUALS( uniform3Value, Color::MAGENTA, TEST_LOCATION );
1353 int UtcDaliRendererUniformMapMultipleUniforms02(void)
1355 TestApplication application;
1357 tet_infoline("Test the uniform maps are collected from all objects (different types)");
1359 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1361 Shader shader = Shader::New("VertexSource", "FragmentSource");
1362 TextureSet textureSet = CreateTextureSet( image );
1364 Geometry geometry = CreateQuadGeometry();
1365 Renderer renderer = Renderer::New( geometry, shader );
1366 renderer.SetTextures( textureSet );
1368 Actor actor = Actor::New();
1369 actor.AddRenderer(renderer);
1370 actor.SetSize(400, 400);
1371 Stage::GetCurrent().Add(actor);
1372 application.SendNotification();
1373 application.Render(0);
1375 Property::Value value1(Color::RED);
1376 renderer.RegisterProperty( "uFadeColor", value1 );
1378 Property::Value value2(1.0f);
1379 actor.RegisterProperty( "uFadeProgress", value2 );
1381 Property::Value value3(Matrix3::IDENTITY);
1382 shader.RegisterProperty( "uANormalMatrix", value3 );
1384 TestGlAbstraction& gl = application.GetGlAbstraction();
1386 application.SendNotification();
1387 application.Render(0);
1389 // Expect that each of the object's uniforms are set
1390 Vector4 uniform1Value(Vector4::ZERO);
1391 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", uniform1Value ) );
1392 DALI_TEST_EQUALS( uniform1Value, value1.Get<Vector4>(), TEST_LOCATION );
1394 float uniform2Value(0.0f);
1395 DALI_TEST_CHECK( gl.GetUniformValue<float>( "uFadeProgress", uniform2Value ) );
1396 DALI_TEST_EQUALS( uniform2Value, value2.Get<float>(), TEST_LOCATION );
1398 Matrix3 uniform3Value;
1399 DALI_TEST_CHECK( gl.GetUniformValue<Matrix3>( "uANormalMatrix", uniform3Value ) );
1400 DALI_TEST_EQUALS( uniform3Value, value3.Get<Matrix3>(), TEST_LOCATION );
1405 int UtcDaliRendererRenderOrder2DLayer(void)
1407 TestApplication application;
1408 tet_infoline("Test the rendering order in a 2D layer is correct");
1410 Shader shader = Shader::New("VertexSource", "FragmentSource");
1411 Geometry geometry = CreateQuadGeometry();
1413 Actor actor0 = Actor::New();
1414 actor0.SetAnchorPoint(AnchorPoint::CENTER);
1415 actor0.SetParentOrigin(AnchorPoint::CENTER);
1416 actor0.SetPosition(0.0f,0.0f);
1417 Image image0 = BufferImage::New( 64, 64, Pixel::RGB888 );
1418 TextureSet textureSet0 = CreateTextureSet( image0 );
1419 Renderer renderer0 = Renderer::New( geometry, shader );
1420 renderer0.SetTextures( textureSet0 );
1421 actor0.AddRenderer(renderer0);
1422 actor0.SetSize(1, 1);
1423 Stage::GetCurrent().Add(actor0);
1424 application.SendNotification();
1425 application.Render(0);
1427 Actor actor1 = Actor::New();
1428 actor1.SetAnchorPoint(AnchorPoint::CENTER);
1429 actor1.SetParentOrigin(AnchorPoint::CENTER);
1430 actor1.SetPosition(0.0f,0.0f);
1431 Image image1= BufferImage::New( 64, 64, Pixel::RGB888 );
1432 TextureSet textureSet1 = CreateTextureSet( image1 );
1433 Renderer renderer1 = Renderer::New( geometry, shader );
1434 renderer1.SetTextures( textureSet1 );
1435 actor1.AddRenderer(renderer1);
1436 actor1.SetSize(1, 1);
1437 Stage::GetCurrent().Add(actor1);
1438 application.SendNotification();
1439 application.Render(0);
1441 Actor actor2 = Actor::New();
1442 actor2.SetAnchorPoint(AnchorPoint::CENTER);
1443 actor2.SetParentOrigin(AnchorPoint::CENTER);
1444 actor2.SetPosition(0.0f,0.0f);
1445 Image image2= BufferImage::New( 64, 64, Pixel::RGB888 );
1446 TextureSet textureSet2 = CreateTextureSet( image2 );
1447 Renderer renderer2 = Renderer::New( geometry, shader );
1448 renderer2.SetTextures( textureSet2 );
1449 actor2.AddRenderer(renderer2);
1450 actor2.SetSize(1, 1);
1451 Stage::GetCurrent().Add(actor2);
1452 application.SendNotification();
1453 application.Render(0);
1455 Actor actor3 = Actor::New();
1456 actor3.SetAnchorPoint(AnchorPoint::CENTER);
1457 actor3.SetParentOrigin(AnchorPoint::CENTER);
1458 actor3.SetPosition(0.0f,0.0f);
1459 Image image3 = BufferImage::New( 64, 64, Pixel::RGB888 );
1460 TextureSet textureSet3 = CreateTextureSet( image3 );
1461 Renderer renderer3 = Renderer::New( geometry, shader );
1462 renderer3.SetTextures( textureSet3 );
1463 actor3.AddRenderer(renderer3);
1464 actor3.SetSize(1, 1);
1465 Stage::GetCurrent().Add(actor3);
1466 application.SendNotification();
1467 application.Render(0);
1470 * Create the following hierarchy:
1483 * Expected rendering order : actor2 - actor1 - actor0 - actor3
1488 application.SendNotification();
1489 application.Render(0);
1491 TestGlAbstraction& gl = application.GetGlAbstraction();
1492 gl.EnableTextureCallTrace(true);
1493 application.SendNotification();
1494 application.Render(0);
1496 int textureBindIndex[4];
1497 for( unsigned int i(0); i<4; ++i )
1499 std::stringstream params;
1500 params << GL_TEXTURE_2D<<", "<<i+1;
1501 textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str() );
1504 //Check that actor1 has been rendered after actor2
1505 DALI_TEST_GREATER( textureBindIndex[1], textureBindIndex[2], TEST_LOCATION );
1507 //Check that actor0 has been rendered after actor1
1508 DALI_TEST_GREATER( textureBindIndex[0], textureBindIndex[1], TEST_LOCATION );
1510 //Check that actor3 has been rendered after actor0
1511 DALI_TEST_GREATER( textureBindIndex[3], textureBindIndex[0], TEST_LOCATION );
1516 int UtcDaliRendererRenderOrder2DLayerMultipleRenderers(void)
1518 TestApplication application;
1519 tet_infoline("Test the rendering order in a 2D layer is correct using multiple renderers per actor");
1522 * Creates the following hierarchy:
1524 * actor0------------------------>actor1
1528 * renderer0 renderer1 renderer2 renderer3 renderer4 renderer5
1530 * renderer0 has depth index 2
1531 * renderer1 has depth index 0
1532 * renderer2 has depth index 1
1534 * renderer3 has depth index 1
1535 * renderer4 has depth index 0
1536 * renderer5 has depth index -1
1538 * Expected rendering order: renderer1 - renderer2 - renderer0 - renderer5 - renderer4 - renderer3
1541 Shader shader = Shader::New("VertexSource", "FragmentSource");
1542 Geometry geometry = CreateQuadGeometry();
1544 Actor actor0 = Actor::New();
1545 actor0.SetAnchorPoint(AnchorPoint::CENTER);
1546 actor0.SetParentOrigin(AnchorPoint::CENTER);
1547 actor0.SetPosition(0.0f,0.0f);
1548 actor0.SetSize(1, 1);
1549 Stage::GetCurrent().Add(actor0);
1551 Actor actor1 = Actor::New();
1552 actor1.SetAnchorPoint(AnchorPoint::CENTER);
1553 actor1.SetParentOrigin(AnchorPoint::CENTER);
1554 actor1.SetPosition(0.0f,0.0f);
1555 actor1.SetSize(1, 1);
1559 Image image0 = BufferImage::New( 64, 64, Pixel::RGB888 );
1560 TextureSet textureSet0 = CreateTextureSet( image0 );
1561 Renderer renderer0 = Renderer::New( geometry, shader );
1562 renderer0.SetTextures( textureSet0 );
1563 renderer0.SetProperty( Renderer::Property::DEPTH_INDEX, 2 );
1564 actor0.AddRenderer(renderer0);
1565 application.SendNotification();
1566 application.Render(0);
1569 Image image1= BufferImage::New( 64, 64, Pixel::RGB888 );
1570 TextureSet textureSet1 = CreateTextureSet( image1 );
1571 Renderer renderer1 = Renderer::New( geometry, shader );
1572 renderer1.SetTextures( textureSet1 );
1573 renderer1.SetProperty( Renderer::Property::DEPTH_INDEX, 0 );
1574 actor0.AddRenderer(renderer1);
1575 application.SendNotification();
1576 application.Render(0);
1579 Image image2= BufferImage::New( 64, 64, Pixel::RGB888 );
1580 TextureSet textureSet2 = CreateTextureSet( image2 );
1581 Renderer renderer2 = Renderer::New( geometry, shader );
1582 renderer2.SetTextures( textureSet2 );
1583 renderer2.SetProperty( Renderer::Property::DEPTH_INDEX, 1 );
1584 actor0.AddRenderer(renderer2);
1585 application.SendNotification();
1586 application.Render(0);
1589 Image image3 = BufferImage::New( 64, 64, Pixel::RGB888 );
1590 TextureSet textureSet3 = CreateTextureSet( image3 );
1591 Renderer renderer3 = Renderer::New( geometry, shader );
1592 renderer3.SetTextures( textureSet3 );
1593 renderer3.SetProperty( Renderer::Property::DEPTH_INDEX, 1 );
1594 actor1.AddRenderer(renderer3);
1595 application.SendNotification();
1596 application.Render(0);
1599 Image image4= BufferImage::New( 64, 64, Pixel::RGB888 );
1600 TextureSet textureSet4 = CreateTextureSet( image4 );
1601 Renderer renderer4 = Renderer::New( geometry, shader );
1602 renderer4.SetTextures( textureSet4 );
1603 renderer4.SetProperty( Renderer::Property::DEPTH_INDEX, 0 );
1604 actor1.AddRenderer(renderer4);
1605 application.SendNotification();
1606 application.Render(0);
1609 Image image5= BufferImage::New( 64, 64, Pixel::RGB888 );
1610 TextureSet textureSet5 = CreateTextureSet( image5 );
1611 Renderer renderer5 = Renderer::New( geometry, shader );
1612 renderer5.SetTextures( textureSet5 );
1613 renderer5.SetProperty( Renderer::Property::DEPTH_INDEX, -1 );
1614 actor1.AddRenderer(renderer5);
1615 application.SendNotification();
1616 application.Render(0);
1619 TestGlAbstraction& gl = application.GetGlAbstraction();
1620 gl.EnableTextureCallTrace(true);
1621 application.SendNotification();
1622 application.Render(0);
1624 int textureBindIndex[6];
1625 for( unsigned int i(0); i<6; ++i )
1627 std::stringstream params;
1628 params << GL_TEXTURE_2D<<", "<<i+1;
1629 textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str() );
1632 //Check that renderer3 has been rendered after renderer4
1633 DALI_TEST_GREATER( textureBindIndex[3], textureBindIndex[4], TEST_LOCATION );
1635 //Check that renderer0 has been rendered after renderer2
1636 DALI_TEST_GREATER( textureBindIndex[4], textureBindIndex[5], TEST_LOCATION );
1638 //Check that renderer0 has been rendered after renderer2
1639 DALI_TEST_GREATER( textureBindIndex[5], textureBindIndex[0], TEST_LOCATION );
1641 //Check that renderer0 has been rendered after renderer2
1642 DALI_TEST_GREATER( textureBindIndex[0], textureBindIndex[2], TEST_LOCATION );
1644 //Check that renderer2 has been rendered after renderer1
1645 DALI_TEST_GREATER( textureBindIndex[2], textureBindIndex[1], TEST_LOCATION );
1650 int UtcDaliRendererRenderOrder2DLayerSiblingOrder(void)
1652 TestApplication application;
1653 tet_infoline("Test the rendering order in a 2D layer is correct using sibling order");
1656 * Creates the following hierarchy:
1664 * actor0 (SIBLING_ORDER:1) actor1 (SIBLING_ORDER:0)
1668 * renderer0 renderer1 actor2 renderer2 renderer3 renderer4
1673 * actor0 has sibling order 1
1674 * actor1 has sibling order 0
1675 * actor2 has sibling order 0
1677 * renderer0 has depth index 2
1678 * renderer1 has depth index 0
1680 * renderer2 has depth index 0
1681 * renderer3 has depth index 1
1682 * renderer4 has depth index 2
1684 * renderer5 has depth index -1
1686 * Expected rendering order: renderer2 - renderer3 - renderer4 - renderer1 - renderer0 - renderer5
1689 Shader shader = Shader::New("VertexSource", "FragmentSource");
1690 Geometry geometry = CreateQuadGeometry();
1692 Actor actor0 = Actor::New();
1693 actor0.SetAnchorPoint(AnchorPoint::CENTER);
1694 actor0.SetParentOrigin(AnchorPoint::CENTER);
1695 actor0.SetPosition(0.0f,0.0f);
1696 actor0.SetSize(1, 1);
1697 actor0.SetProperty( Dali::DevelActor::Property::SIBLING_ORDER, 1 );
1698 DALI_TEST_EQUALS( actor0.GetProperty<int>( Dali::DevelActor::Property::SIBLING_ORDER), 1, TEST_LOCATION );
1699 Stage::GetCurrent().Add(actor0);
1701 Actor actor1 = Actor::New();
1702 actor1.SetAnchorPoint(AnchorPoint::CENTER);
1703 actor1.SetParentOrigin(AnchorPoint::CENTER);
1704 actor1.SetPosition(0.0f,0.0f);
1705 actor1.SetSize(1, 1);
1706 DALI_TEST_EQUALS( actor1.GetProperty<int>( Dali::DevelActor::Property::SIBLING_ORDER), 0, TEST_LOCATION );
1707 Stage::GetCurrent().Add(actor1);
1709 Actor actor2 = Actor::New();
1710 actor2.SetAnchorPoint(AnchorPoint::CENTER);
1711 actor2.SetParentOrigin(AnchorPoint::CENTER);
1712 actor2.SetPosition(0.0f,0.0f);
1713 actor2.SetSize(1, 1);
1714 DALI_TEST_EQUALS( actor1.GetProperty<int>( Dali::DevelActor::Property::SIBLING_ORDER), 0, TEST_LOCATION );
1718 Image image0 = BufferImage::New( 64, 64, Pixel::RGB888 );
1719 TextureSet textureSet0 = CreateTextureSet( image0 );
1720 Renderer renderer0 = Renderer::New( geometry, shader );
1721 renderer0.SetTextures( textureSet0 );
1722 renderer0.SetProperty( Renderer::Property::DEPTH_INDEX, 2 );
1723 actor0.AddRenderer(renderer0);
1724 application.SendNotification();
1725 application.Render(0);
1728 Image image1= BufferImage::New( 64, 64, Pixel::RGB888 );
1729 TextureSet textureSet1 = CreateTextureSet( image1 );
1730 Renderer renderer1 = Renderer::New( geometry, shader );
1731 renderer1.SetTextures( textureSet1 );
1732 renderer1.SetProperty( Renderer::Property::DEPTH_INDEX, 0 );
1733 actor0.AddRenderer(renderer1);
1734 application.SendNotification();
1735 application.Render(0);
1738 Image image2= BufferImage::New( 64, 64, Pixel::RGB888 );
1739 TextureSet textureSet2 = CreateTextureSet( image2 );
1740 Renderer renderer2 = Renderer::New( geometry, shader );
1741 renderer2.SetTextures( textureSet2 );
1742 renderer2.SetProperty( Renderer::Property::DEPTH_INDEX, 0 );
1743 actor1.AddRenderer(renderer2);
1744 application.SendNotification();
1745 application.Render(0);
1748 Image image3 = BufferImage::New( 64, 64, Pixel::RGB888 );
1749 TextureSet textureSet3 = CreateTextureSet( image3 );
1750 Renderer renderer3 = Renderer::New( geometry, shader );
1751 renderer3.SetTextures( textureSet3 );
1752 renderer3.SetProperty( Renderer::Property::DEPTH_INDEX, 1 );
1753 actor1.AddRenderer(renderer3);
1754 application.SendNotification();
1755 application.Render(0);
1758 Image image4= BufferImage::New( 64, 64, Pixel::RGB888 );
1759 TextureSet textureSet4 = CreateTextureSet( image4 );
1760 Renderer renderer4 = Renderer::New( geometry, shader );
1761 renderer4.SetTextures( textureSet4 );
1762 renderer4.SetProperty( Renderer::Property::DEPTH_INDEX, 2 );
1763 actor1.AddRenderer(renderer4);
1764 application.SendNotification();
1765 application.Render(0);
1768 Image image5= BufferImage::New( 64, 64, Pixel::RGB888 );
1769 TextureSet textureSet5 = CreateTextureSet( image5 );
1770 Renderer renderer5 = Renderer::New( geometry, shader );
1771 renderer5.SetTextures( textureSet5 );
1772 renderer5.SetProperty( Renderer::Property::DEPTH_INDEX, -1 );
1773 actor2.AddRenderer(renderer5);
1774 application.SendNotification();
1775 application.Render(0);
1778 TestGlAbstraction& gl = application.GetGlAbstraction();
1779 gl.EnableTextureCallTrace(true);
1780 application.SendNotification();
1781 application.Render(0);
1783 int textureBindIndex[6];
1784 for( unsigned int i(0); i<6; ++i )
1786 std::stringstream params;
1787 params << GL_TEXTURE_2D<<", "<<i+1;
1788 textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str() );
1791 DALI_TEST_EQUALS( textureBindIndex[2], 0, TEST_LOCATION );
1792 DALI_TEST_EQUALS( textureBindIndex[3], 1, TEST_LOCATION );
1793 DALI_TEST_EQUALS( textureBindIndex[4], 2, TEST_LOCATION );
1794 DALI_TEST_EQUALS( textureBindIndex[1], 3, TEST_LOCATION );
1795 DALI_TEST_EQUALS( textureBindIndex[0], 4, TEST_LOCATION );
1796 DALI_TEST_EQUALS( textureBindIndex[5], 5, TEST_LOCATION );
1798 //Change sibling order of actor1
1799 //New Expected rendering order: renderer1 - renderer0 - renderer2 - renderer3 - renderer4 - renderer5
1800 actor1.SetProperty( Dali::DevelActor::Property::SIBLING_ORDER, 2 );
1802 gl.GetTextureTrace().Reset();
1803 application.SendNotification();
1804 application.Render(0);
1806 for( unsigned int i(0); i<6; ++i )
1808 std::stringstream params;
1809 params << GL_TEXTURE_2D<<", "<<i+1;
1810 textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str() );
1813 DALI_TEST_EQUALS( textureBindIndex[1], 0, TEST_LOCATION );
1814 DALI_TEST_EQUALS( textureBindIndex[0], 1, TEST_LOCATION );
1815 DALI_TEST_EQUALS( textureBindIndex[2], 2, TEST_LOCATION );
1816 DALI_TEST_EQUALS( textureBindIndex[3], 3, TEST_LOCATION );
1817 DALI_TEST_EQUALS( textureBindIndex[4], 4, TEST_LOCATION );
1818 DALI_TEST_EQUALS( textureBindIndex[5], 5, TEST_LOCATION );
1823 int UtcDaliRendererRenderOrder2DLayerOverlay(void)
1825 TestApplication application;
1826 tet_infoline("Test the rendering order in a 2D layer is correct for overlays");
1828 Shader shader = Shader::New("VertexSource", "FragmentSource");
1829 Geometry geometry = CreateQuadGeometry();
1831 Actor actor0 = Actor::New();
1832 actor0.SetAnchorPoint(AnchorPoint::CENTER);
1833 actor0.SetParentOrigin(AnchorPoint::CENTER);
1834 Image image0 = BufferImage::New( 64, 64, Pixel::RGB888 );
1835 TextureSet textureSet0 = CreateTextureSet( image0 );
1836 Renderer renderer0 = Renderer::New( geometry, shader );
1837 renderer0.SetTextures( textureSet0 );
1838 actor0.AddRenderer(renderer0);
1839 actor0.SetPosition(0.0f,0.0f);
1840 actor0.SetSize(100, 100);
1841 Stage::GetCurrent().Add(actor0);
1842 actor0.SetDrawMode( DrawMode::OVERLAY_2D );
1843 application.SendNotification();
1844 application.Render(0);
1846 Actor actor1 = Actor::New();
1847 actor1.SetAnchorPoint(AnchorPoint::CENTER);
1848 actor1.SetParentOrigin(AnchorPoint::CENTER);
1849 Image image1= BufferImage::New( 64, 64, Pixel::RGB888 );
1850 TextureSet textureSet1 = CreateTextureSet( image1 );
1851 Renderer renderer1 = Renderer::New( geometry, shader );
1852 renderer1.SetTextures( textureSet1 );
1853 actor1.SetPosition(0.0f,0.0f);
1854 actor1.AddRenderer(renderer1);
1855 actor1.SetSize(100, 100);
1856 Stage::GetCurrent().Add(actor1);
1857 actor1.SetDrawMode( DrawMode::OVERLAY_2D );
1858 application.SendNotification();
1859 application.Render(0);
1861 Actor actor2 = Actor::New();
1862 actor2.SetAnchorPoint(AnchorPoint::CENTER);
1863 actor2.SetParentOrigin(AnchorPoint::CENTER);
1864 Image image2= BufferImage::New( 64, 64, Pixel::RGB888 );
1865 TextureSet textureSet2 = CreateTextureSet( image2 );
1866 Renderer renderer2 = Renderer::New( geometry, shader );
1867 renderer2.SetTextures( textureSet2 );
1868 actor2.AddRenderer(renderer2);
1869 actor2.SetPosition(0.0f,0.0f);
1870 actor2.SetSize(100, 100);
1871 Stage::GetCurrent().Add(actor2);
1872 application.SendNotification();
1873 application.Render(0);
1875 Actor actor3 = Actor::New();
1876 actor3.SetAnchorPoint(AnchorPoint::CENTER);
1877 actor3.SetParentOrigin(AnchorPoint::CENTER);
1878 Image image3 = BufferImage::New( 64, 64, Pixel::RGB888 );
1879 TextureSet textureSet3 = CreateTextureSet( image3 );
1880 Renderer renderer3 = Renderer::New( geometry, shader );
1881 renderer3.SetTextures( textureSet3 );
1882 actor3.SetPosition(0.0f,0.0f);
1883 actor3.AddRenderer(renderer3);
1884 actor3.SetSize(100, 100);
1885 Stage::GetCurrent().Add(actor3);
1886 actor3.SetDrawMode( DrawMode::OVERLAY_2D );
1887 application.SendNotification();
1888 application.Render(0);
1890 Actor actor4 = Actor::New();
1891 actor4.SetAnchorPoint(AnchorPoint::CENTER);
1892 actor4.SetParentOrigin(AnchorPoint::CENTER);
1893 Image image4 = BufferImage::New( 64, 64, Pixel::RGB888 );
1894 TextureSet textureSet4 = CreateTextureSet( image4 );
1895 Renderer renderer4 = Renderer::New( geometry, shader );
1896 renderer4.SetTextures( textureSet4 );
1897 actor4.AddRenderer(renderer4);
1898 actor4.SetPosition(0.0f,0.0f);
1899 actor4.SetSize(100, 100);
1900 Stage::GetCurrent().Add(actor4);
1901 application.SendNotification();
1902 application.Render(0);
1905 * Create the following hierarchy:
1912 * (Overlay) (Regular actor)
1922 * Expected rendering order : actor2 - actor4 - actor1 - actor0 - actor3
1924 Stage::GetCurrent().Add( actor2 );
1929 application.SendNotification();
1930 application.Render(0);
1932 TestGlAbstraction& gl = application.GetGlAbstraction();
1933 gl.EnableTextureCallTrace(true);
1934 application.SendNotification();
1935 application.Render(0);
1937 int textureBindIndex[5];
1938 for( unsigned int i(0); i<5; ++i )
1940 std::stringstream params;
1941 params << GL_TEXTURE_2D<<", "<<i+1;
1942 textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str() );
1945 //Check that actor4 has been rendered after actor2
1946 DALI_TEST_GREATER( textureBindIndex[4], textureBindIndex[2], TEST_LOCATION );
1948 //Check that actor1 has been rendered after actor4
1949 DALI_TEST_GREATER( textureBindIndex[1], textureBindIndex[4], TEST_LOCATION );
1951 //Check that actor0 has been rendered after actor1
1952 DALI_TEST_GREATER( textureBindIndex[0], textureBindIndex[1], TEST_LOCATION );
1954 //Check that actor3 has been rendered after actor0
1955 DALI_TEST_GREATER( textureBindIndex[3], textureBindIndex[0], TEST_LOCATION );
1960 int UtcDaliRendererSetIndexRange(void)
1964 "attribute vec2 aPosition;\n"
1967 " gl_Position = aPosition;\n"
1973 " gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0)\n"
1977 TestApplication application;
1978 tet_infoline("Test setting the range of indices to draw");
1980 TestGlAbstraction& gl = application.GetGlAbstraction();
1981 gl.EnableDrawCallTrace( true );
1983 Actor actor = Actor::New();
1984 actor.SetSize( 100, 100 );
1987 Geometry geometry = Geometry::New();
1988 geometry.SetType( Geometry::LINE_LOOP );
1990 // --------------------------------------------------------------------------
1992 unsigned short indices[] = { 0, 2, 4, 6, 8, // offset = 0, count = 5
1993 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, // offset = 5, count = 10
1994 1, 3, 5, 7, 9, 1 }; // offset = 15, count = 6 // line strip
1996 // --------------------------------------------------------------------------
2005 { Vector2( 0.0f, 1.00f) }, { Vector2( 0.0f, -1.00f) },
2006 { Vector2( -0.95f, 0.31f) }, { Vector2( 0.59f, 0.81f) },
2007 { Vector2( -0.59f, -0.81f) }, { Vector2( -0.95f, -0.31f) },
2008 { Vector2( 0.59f, -0.81f) }, { Vector2( 0.95f, -0.31f) },
2009 { Vector2( 0.95f, 0.31f) }, { Vector2( -0.59f, 0.81f) },
2011 Property::Map vertexFormat;
2012 vertexFormat["aPosition"] = Property::VECTOR2;
2013 PropertyBuffer vertexBuffer = PropertyBuffer::New( vertexFormat );
2014 vertexBuffer.SetData( shapes, sizeof(shapes)/sizeof(shapes[0]));
2016 // --------------------------------------------------------------------------
2017 geometry.SetIndexBuffer( indices, sizeof(indices)/sizeof(indices[0]) );
2018 geometry.AddVertexBuffer( vertexBuffer );
2021 Shader shader = Shader::New( vertexShader,fragmentShader );
2022 Renderer renderer = Renderer::New( geometry, shader );
2023 actor.AddRenderer( renderer );
2025 Stage stage = Stage::GetCurrent();
2030 // LINE_LOOP, first 0, count 5
2032 renderer.SetIndexRange( 0, 5 );
2033 application.SendNotification();
2034 application.Render();
2035 sprintf( buffer, "%u, 5, %u, indices", GL_LINE_LOOP, GL_UNSIGNED_SHORT );
2036 bool result = gl.GetDrawTrace().FindMethodAndParams( "DrawElements" , buffer );
2037 DALI_TEST_CHECK( result );
2040 // LINE_LOOP, first 5, count 10
2042 renderer.SetIndexRange( 5, 10 );
2043 sprintf( buffer, "%u, 10, %u, indices", GL_LINE_LOOP, GL_UNSIGNED_SHORT );
2044 application.SendNotification();
2045 application.Render();
2046 bool result = gl.GetDrawTrace().FindMethodAndParams( "DrawElements" , buffer );
2047 DALI_TEST_CHECK( result );
2050 // LINE_STRIP, first 15, count 6
2052 renderer.SetIndexRange( 15, 6 );
2053 geometry.SetType( Geometry::LINE_STRIP );
2054 sprintf( buffer, "%u, 6, %u, indices", GL_LINE_STRIP, GL_UNSIGNED_SHORT );
2055 application.SendNotification();
2056 application.Render();
2057 bool result = gl.GetDrawTrace().FindMethodAndParams( "DrawElements" , buffer );
2058 DALI_TEST_CHECK( result );
2061 // Index out of bounds
2063 renderer.SetIndexRange( 15, 30 );
2064 geometry.SetType( Geometry::LINE_STRIP );
2065 sprintf( buffer, "%u, 6, %u, indices", GL_LINE_STRIP, GL_UNSIGNED_SHORT );
2066 application.SendNotification();
2067 application.Render();
2068 bool result = gl.GetDrawTrace().FindMethodAndParams( "DrawElements" , buffer );
2069 DALI_TEST_CHECK( result );
2072 // drawing whole buffer starting from 15 ( last valid primitive )
2074 renderer.SetIndexRange( 15, 0 );
2075 geometry.SetType( Geometry::LINE_STRIP );
2076 sprintf( buffer, "%u, 6, %u, indices", GL_LINE_STRIP, GL_UNSIGNED_SHORT );
2077 application.SendNotification();
2078 application.Render();
2079 bool result = gl.GetDrawTrace().FindMethodAndParams( "DrawElements" , buffer );
2080 DALI_TEST_CHECK( result );
2087 int UtcDaliRendererSetDepthFunction(void)
2089 TestApplication application;
2091 tet_infoline("Test setting the depth function");
2093 Geometry geometry = CreateQuadGeometry();
2094 Shader shader = CreateShader();
2095 Renderer renderer = Renderer::New( geometry, shader );
2097 Actor actor = Actor::New();
2098 actor.AddRenderer(renderer);
2099 actor.SetSize(400, 400);
2100 Stage stage = Stage::GetCurrent();
2101 stage.GetRootLayer().SetBehavior( Layer::LAYER_3D );
2104 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2105 glAbstraction.EnableEnableDisableCallTrace(true);
2106 glAbstraction.EnableDepthFunctionCallTrace(true);
2108 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2109 TraceCallStack& glDepthFunctionStack = glAbstraction.GetDepthFunctionTrace();
2111 std::ostringstream depthTestStr;
2112 depthTestStr << GL_DEPTH_TEST;
2116 renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::NEVER);
2118 glEnableDisableStack.Reset();
2119 glDepthFunctionStack.Reset();
2120 application.SendNotification();
2121 application.Render();
2123 DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Enable", depthTestStr.str().c_str() ) );
2124 std::ostringstream depthFunctionStr;
2125 depthFunctionStr << GL_NEVER;
2126 DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
2131 renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::ALWAYS);
2133 glDepthFunctionStack.Reset();
2134 application.SendNotification();
2135 application.Render();
2137 std::ostringstream depthFunctionStr;
2138 depthFunctionStr << GL_ALWAYS;
2139 DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
2144 renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::LESS);
2146 glDepthFunctionStack.Reset();
2147 application.SendNotification();
2148 application.Render();
2150 std::ostringstream depthFunctionStr;
2151 depthFunctionStr << GL_LESS;
2152 DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
2157 renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::GREATER);
2159 glDepthFunctionStack.Reset();
2160 application.SendNotification();
2161 application.Render();
2163 std::ostringstream depthFunctionStr;
2164 depthFunctionStr << GL_GREATER;
2165 DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
2170 renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::EQUAL);
2172 glDepthFunctionStack.Reset();
2173 application.SendNotification();
2174 application.Render();
2176 std::ostringstream depthFunctionStr;
2177 depthFunctionStr << GL_EQUAL;
2178 DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
2183 renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::NOT_EQUAL);
2185 glDepthFunctionStack.Reset();
2186 application.SendNotification();
2187 application.Render();
2189 std::ostringstream depthFunctionStr;
2190 depthFunctionStr << GL_NOTEQUAL;
2191 DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
2196 renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::LESS_EQUAL);
2198 glDepthFunctionStack.Reset();
2199 application.SendNotification();
2200 application.Render();
2202 std::ostringstream depthFunctionStr;
2203 depthFunctionStr << GL_LEQUAL;
2204 DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
2209 renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::GREATER_EQUAL);
2211 glDepthFunctionStack.Reset();
2212 application.SendNotification();
2213 application.Render();
2215 std::ostringstream depthFunctionStr;
2216 depthFunctionStr << GL_GEQUAL;
2217 DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
2224 * @brief This templatized function checks an enumeration property is setting and getting correctly.
2225 * The checks performed are as follows:
2226 * - Check the initial/default value.
2227 * - Set a different value via enum.
2228 * - Check it was set.
2229 * - Set a different value via string.
2230 * - Check it was set.
2232 template< typename T >
2233 void CheckEnumerationProperty( Renderer& renderer, Property::Index propertyIndex, T initialValue, T firstCheckEnumeration, T secondCheckEnumeration, std::string secondCheckString )
2235 DALI_TEST_CHECK( renderer.GetProperty<int>( propertyIndex ) == static_cast<int>( initialValue ) );
2236 renderer.SetProperty( propertyIndex, firstCheckEnumeration );
2237 DALI_TEST_CHECK( renderer.GetProperty<int>( propertyIndex ) == static_cast<int>( firstCheckEnumeration ) );
2238 renderer.SetProperty( propertyIndex, secondCheckString );
2239 DALI_TEST_CHECK( renderer.GetProperty<int>( propertyIndex ) == static_cast<int>( secondCheckEnumeration ) );
2242 int UtcDaliRendererEnumProperties(void)
2244 TestApplication application;
2245 tet_infoline( "Test Renderer enumeration properties can be set with both integer and string values" );
2247 Geometry geometry = CreateQuadGeometry();
2248 Shader shader = CreateShader();
2249 Renderer renderer = Renderer::New( geometry, shader );
2252 * Here we use a templatized function to perform several checks on each enumeration property.
2253 * @see CheckEnumerationProperty for details of the checks performed.
2256 CheckEnumerationProperty< FaceCullingMode::Type >( renderer, Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::NONE, FaceCullingMode::FRONT, FaceCullingMode::BACK, "BACK" );
2257 CheckEnumerationProperty< BlendMode::Type >( renderer, Renderer::Property::BLEND_MODE, BlendMode::AUTO, BlendMode::OFF, BlendMode::ON, "ON" );
2258 CheckEnumerationProperty< BlendEquation::Type >( renderer, Renderer::Property::BLEND_EQUATION_RGB, BlendEquation::ADD, BlendEquation::SUBTRACT, BlendEquation::REVERSE_SUBTRACT, "REVERSE_SUBTRACT" );
2259 CheckEnumerationProperty< BlendEquation::Type >( renderer, Renderer::Property::BLEND_EQUATION_ALPHA, BlendEquation::ADD, BlendEquation::SUBTRACT, BlendEquation::REVERSE_SUBTRACT, "REVERSE_SUBTRACT" );
2260 CheckEnumerationProperty< BlendFactor::Type >( renderer, Renderer::Property::BLEND_FACTOR_SRC_RGB, BlendFactor::SRC_ALPHA, BlendFactor::ONE, BlendFactor::SRC_COLOR, "SRC_COLOR" );
2261 CheckEnumerationProperty< BlendFactor::Type >( renderer, Renderer::Property::BLEND_FACTOR_DEST_RGB, BlendFactor::ONE_MINUS_SRC_ALPHA, BlendFactor::ONE, BlendFactor::SRC_COLOR, "SRC_COLOR" );
2262 CheckEnumerationProperty< BlendFactor::Type >( renderer, Renderer::Property::BLEND_FACTOR_SRC_ALPHA, BlendFactor::ONE, BlendFactor::ONE_MINUS_SRC_ALPHA, BlendFactor::SRC_COLOR, "SRC_COLOR" );
2263 CheckEnumerationProperty< BlendFactor::Type >( renderer, Renderer::Property::BLEND_FACTOR_DEST_ALPHA, BlendFactor::ONE_MINUS_SRC_ALPHA, BlendFactor::ONE, BlendFactor::SRC_COLOR, "SRC_COLOR" );
2264 CheckEnumerationProperty< DepthWriteMode::Type >( renderer, Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::AUTO, DepthWriteMode::OFF, DepthWriteMode::ON, "ON" );
2265 CheckEnumerationProperty< DepthFunction::Type >( renderer, Renderer::Property::DEPTH_FUNCTION, DepthFunction::LESS, DepthFunction::ALWAYS, DepthFunction::GREATER, "GREATER" );
2266 CheckEnumerationProperty< DepthTestMode::Type >( renderer, Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::AUTO, DepthTestMode::OFF, DepthTestMode::ON, "ON" );
2267 CheckEnumerationProperty< StencilFunction::Type >( renderer, Renderer::Property::STENCIL_FUNCTION, StencilFunction::ALWAYS, StencilFunction::LESS, StencilFunction::EQUAL, "EQUAL" );
2268 CheckEnumerationProperty< RenderMode::Type >( renderer, Renderer::Property::RENDER_MODE, RenderMode::AUTO, RenderMode::NONE, RenderMode::STENCIL, "STENCIL" );
2269 CheckEnumerationProperty< StencilOperation::Type >( renderer, Renderer::Property::STENCIL_OPERATION_ON_FAIL, StencilOperation::KEEP, StencilOperation::REPLACE, StencilOperation::INCREMENT, "INCREMENT" );
2270 CheckEnumerationProperty< StencilOperation::Type >( renderer, Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, StencilOperation::KEEP, StencilOperation::REPLACE, StencilOperation::INCREMENT, "INCREMENT" );
2271 CheckEnumerationProperty< StencilOperation::Type >( renderer, Renderer::Property::STENCIL_OPERATION_ON_Z_PASS, StencilOperation::KEEP, StencilOperation::REPLACE, StencilOperation::INCREMENT, "INCREMENT" );
2276 Renderer RendererTestFixture( TestApplication& application )
2278 Geometry geometry = CreateQuadGeometry();
2279 Shader shader = CreateShader();
2280 Renderer renderer = Renderer::New( geometry, shader );
2282 Actor actor = Actor::New();
2283 actor.AddRenderer( renderer );
2284 actor.SetSize( 400.0f, 400.0f );
2285 Stage stage = Stage::GetCurrent();
2286 stage.GetRootLayer().SetBehavior( Layer::LAYER_3D );
2292 int UtcDaliRendererSetDepthTestMode(void)
2294 TestApplication application;
2295 tet_infoline("Test setting the DepthTestMode");
2297 Renderer renderer = RendererTestFixture( application );
2298 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2299 glAbstraction.EnableEnableDisableCallTrace( true );
2300 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2302 glEnableDisableStack.Reset();
2303 application.SendNotification();
2304 application.Render();
2306 // Check depth-test is enabled by default.
2307 DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Enable", GetDepthTestString() ) );
2308 DALI_TEST_CHECK( !glEnableDisableStack.FindMethodAndParams( "Disable", GetDepthTestString() ) );
2310 // Turn off depth-testing. We want to check if the depth buffer has been disabled, so we need to turn off depth-write as well for this case.
2311 renderer.SetProperty( Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::OFF );
2312 renderer.SetProperty( Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::OFF );
2314 glEnableDisableStack.Reset();
2315 application.SendNotification();
2316 application.Render();
2318 // Check the depth buffer was disabled.
2319 DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Disable", GetDepthTestString() ) );
2321 // Turn on automatic mode depth-testing.
2322 // Layer behavior is currently set to LAYER_3D so AUTO should enable depth-testing.
2323 renderer.SetProperty( Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::AUTO );
2325 glEnableDisableStack.Reset();
2326 application.SendNotification();
2327 application.Render();
2329 // Check depth-test is now enabled.
2330 DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Enable", GetDepthTestString() ) );
2331 DALI_TEST_CHECK( !glEnableDisableStack.FindMethodAndParams( "Disable", GetDepthTestString() ) );
2333 // Change the layer behavior to LAYER_2D.
2334 // Note this will also disable depth testing for the layer by default, we test this first.
2335 Stage::GetCurrent().GetRootLayer().SetBehavior( Layer::LAYER_2D );
2337 glEnableDisableStack.Reset();
2338 application.SendNotification();
2339 application.Render();
2341 // Check depth-test is disabled.
2342 DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Disable", GetDepthTestString() ) );
2344 // Turn the layer depth-test flag back on, and confirm that depth testing is now on.
2345 Stage::GetCurrent().GetRootLayer().SetDepthTestDisabled( false );
2347 glEnableDisableStack.Reset();
2348 application.SendNotification();
2349 application.Render();
2351 // Check depth-test is *still* disabled.
2352 DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Enable", GetDepthTestString() ) );
2357 int UtcDaliRendererSetDepthWriteMode(void)
2359 TestApplication application;
2360 tet_infoline("Test setting the DepthWriteMode");
2362 Renderer renderer = RendererTestFixture( application );
2363 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2365 application.SendNotification();
2366 application.Render();
2368 // Check the default depth-write status first.
2369 DALI_TEST_CHECK( glAbstraction.GetLastDepthMask() );
2371 // Turn off depth-writing.
2372 renderer.SetProperty( Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::OFF );
2374 application.SendNotification();
2375 application.Render();
2377 // Check depth-write is now disabled.
2378 DALI_TEST_CHECK( !glAbstraction.GetLastDepthMask() );
2380 // Test the AUTO mode for depth-writing.
2381 // As our renderer is opaque, depth-testing should be enabled.
2382 renderer.SetProperty( Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::AUTO );
2384 application.SendNotification();
2385 application.Render();
2387 // Check depth-write is now enabled.
2388 DALI_TEST_CHECK( glAbstraction.GetLastDepthMask() );
2390 // Now make the renderer be treated as translucent by enabling blending.
2391 // The AUTO depth-write mode should turn depth-write off in this scenario.
2392 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::ON );
2394 application.SendNotification();
2395 application.Render();
2397 // Check depth-write is now disabled.
2398 DALI_TEST_CHECK( !glAbstraction.GetLastDepthMask() );
2403 int UtcDaliRendererCheckStencilDefaults(void)
2405 TestApplication application;
2406 tet_infoline("Test the stencil defaults");
2408 Renderer renderer = RendererTestFixture( application );
2409 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2410 glAbstraction.EnableEnableDisableCallTrace( true );
2411 glAbstraction.EnableStencilFunctionCallTrace( true );
2412 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2413 TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2415 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2417 // Check the defaults:
2418 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_FUNCTION ).Get<int>() ), static_cast<int>( StencilFunction::ALWAYS ), TEST_LOCATION );
2419 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_FUNCTION_MASK ).Get<int>() ), 0xFF, TEST_LOCATION );
2420 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_FUNCTION_REFERENCE ).Get<int>() ), 0x00, TEST_LOCATION );
2421 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_MASK ).Get<int>() ), 0xFF, TEST_LOCATION );
2422 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_OPERATION_ON_FAIL ).Get<int>() ), static_cast<int>( StencilOperation::KEEP ), TEST_LOCATION );
2423 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL ).Get<int>() ), static_cast<int>( StencilOperation::KEEP ), TEST_LOCATION );
2424 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_OPERATION_ON_Z_PASS ).Get<int>() ), static_cast<int>( StencilOperation::KEEP ), TEST_LOCATION );
2429 int UtcDaliRendererSetRenderModeToUseStencilBuffer(void)
2431 TestApplication application;
2432 tet_infoline("Test setting the RenderMode to use the stencil buffer");
2434 Renderer renderer = RendererTestFixture( application );
2435 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2436 glAbstraction.EnableEnableDisableCallTrace( true );
2437 glAbstraction.EnableStencilFunctionCallTrace( true );
2438 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2439 TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2441 // Set the StencilFunction to something other than the default, to confirm it is set as a property,
2442 // but NO GL call has been made while the RenderMode is set to not use the stencil buffer.
2443 renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::NONE );
2444 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2446 renderer.SetProperty( Renderer::Property::STENCIL_FUNCTION, StencilFunction::NEVER );
2447 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_FUNCTION ).Get<int>() ), static_cast<int>( StencilFunction::NEVER ), TEST_LOCATION );
2449 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2450 std::string methodString( "StencilFunc" );
2451 DALI_TEST_CHECK( !glStencilFunctionStack.FindMethod( methodString ) );
2453 // Test the other RenderModes that will not enable the stencil buffer.
2454 renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::AUTO );
2455 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2456 DALI_TEST_CHECK( !glStencilFunctionStack.FindMethod( methodString ) );
2458 renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::COLOR );
2459 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2460 DALI_TEST_CHECK( !glStencilFunctionStack.FindMethod( methodString ) );
2462 // Now set the RenderMode to modes that will use the stencil buffer, and check the StencilFunction has changed.
2463 renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::STENCIL );
2464 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2466 DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Enable", GetStencilTestString() ) );
2467 DALI_TEST_CHECK( glStencilFunctionStack.FindMethod( methodString ) );
2469 // Test the COLOR_STENCIL RenderMode as it also enables the stencil buffer.
2470 // First set a mode to turn off the stencil buffer, so the enable is required.
2471 renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::COLOR );
2472 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2473 renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::COLOR_STENCIL );
2474 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2476 DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Enable", GetStencilTestString() ) );
2477 DALI_TEST_CHECK( glStencilFunctionStack.FindMethod( methodString ) );
2482 // Helper function for the SetRenderModeToUseColorBuffer test.
2483 void CheckRenderModeColorMask( TestApplication& application, Renderer& renderer, RenderMode::Type renderMode, bool expectedValue )
2485 // Set the RenderMode property to a value that should not allow color buffer writes.
2486 renderer.SetProperty( Renderer::Property::RENDER_MODE, renderMode );
2487 application.SendNotification();
2488 application.Render();
2490 // Check if ColorMask has been called, and that the values are correct.
2491 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2492 const TestGlAbstraction::ColorMaskParams& colorMaskParams( glAbstraction.GetColorMaskParams() );
2494 DALI_TEST_EQUALS<bool>( colorMaskParams.red, expectedValue, TEST_LOCATION );
2495 DALI_TEST_EQUALS<bool>( colorMaskParams.green, expectedValue, TEST_LOCATION );
2496 DALI_TEST_EQUALS<bool>( colorMaskParams.blue, expectedValue, TEST_LOCATION );
2497 DALI_TEST_EQUALS<bool>( colorMaskParams.alpha, expectedValue, TEST_LOCATION );
2500 int UtcDaliRendererSetRenderModeToUseColorBuffer(void)
2502 TestApplication application;
2503 tet_infoline("Test setting the RenderMode to use the color buffer");
2505 Renderer renderer = RendererTestFixture( application );
2507 // Set the RenderMode property to a value that should not allow color buffer writes.
2508 // Then check if ColorMask has been called, and that the values are correct.
2509 CheckRenderModeColorMask( application, renderer, RenderMode::AUTO, true );
2510 CheckRenderModeColorMask( application, renderer, RenderMode::NONE, false );
2511 CheckRenderModeColorMask( application, renderer, RenderMode::COLOR, true );
2512 CheckRenderModeColorMask( application, renderer, RenderMode::STENCIL, false );
2513 CheckRenderModeColorMask( application, renderer, RenderMode::COLOR_STENCIL, true );
2518 int UtcDaliRendererSetStencilFunction(void)
2520 TestApplication application;
2521 tet_infoline("Test setting the StencilFunction");
2523 Renderer renderer = RendererTestFixture( application );
2524 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2525 glAbstraction.EnableEnableDisableCallTrace( true );
2526 glAbstraction.EnableStencilFunctionCallTrace( true );
2527 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2528 TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2530 // RenderMode must use the stencil for StencilFunction to operate.
2531 renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::STENCIL );
2532 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2535 * Lookup table for testing StencilFunction.
2536 * Note: This MUST be in the same order as the Dali::StencilFunction enum.
2538 const int StencilFunctionLookupTable[] = {
2547 }; const int StencilFunctionLookupTableCount = sizeof( StencilFunctionLookupTable ) / sizeof( StencilFunctionLookupTable[0] );
2550 * Loop through all types of StencilFunction, checking:
2551 * - The value is cached (set in event thread side)
2552 * - Causes "glStencilFunc" to be called
2553 * - Checks the correct parameters to "glStencilFunc" were used
2555 std::string nonChangingParameters = "0, 255";
2556 std::string methodString( "StencilFunc" );
2557 for( int i = 0; i < StencilFunctionLookupTableCount; ++i )
2559 // Set the property.
2560 renderer.SetProperty( Renderer::Property::STENCIL_FUNCTION, static_cast<Dali::StencilFunction::Type>( i ) );
2562 // Check GetProperty returns the same value.
2563 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_FUNCTION ).Get<int>() ), i, TEST_LOCATION );
2565 // Reset the trace debug.
2566 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2568 // Check the function is called and the parameters are correct.
2569 std::stringstream parameterStream;
2570 parameterStream << StencilFunctionLookupTable[ i ] << ", " << nonChangingParameters;
2572 DALI_TEST_CHECK( glStencilFunctionStack.FindMethodAndParams( methodString, parameterStream.str() ) );
2575 // Change the Function Reference only and check the behavior is correct:
2576 // 170 is 0xaa in hex / 10101010 in binary (every other bit set).
2577 int testValueReference = 170;
2578 renderer.SetProperty( Renderer::Property::STENCIL_FUNCTION_REFERENCE, testValueReference );
2580 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_FUNCTION_REFERENCE ).Get<int>() ), testValueReference, TEST_LOCATION );
2582 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2584 std::stringstream parameterStream;
2585 parameterStream << StencilFunctionLookupTable[ StencilOperation::DECREMENT_WRAP ] << ", " << testValueReference << ", 255";
2587 DALI_TEST_CHECK( glStencilFunctionStack.FindMethodAndParams( methodString, parameterStream.str() ) );
2590 // Change the Function Mask only and check the behavior is correct:
2591 // 85 is 0x55 in hex / 01010101 in binary (every other bit set).
2592 int testValueMask = 85;
2593 renderer.SetProperty( Renderer::Property::STENCIL_FUNCTION_MASK, testValueMask );
2595 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_FUNCTION_MASK ).Get<int>() ), testValueMask, TEST_LOCATION );
2597 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2599 // Clear the stringstream.
2600 parameterStream.str( std::string() );
2601 parameterStream << StencilFunctionLookupTable[ StencilOperation::DECREMENT_WRAP ] << ", " << testValueReference << ", " << testValueMask;
2603 DALI_TEST_CHECK( glStencilFunctionStack.FindMethodAndParams( methodString, parameterStream.str() ) );
2608 int UtcDaliRendererSetStencilOperation(void)
2610 TestApplication application;
2611 tet_infoline("Test setting the StencilOperation");
2613 Renderer renderer = RendererTestFixture( application );
2614 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2615 glAbstraction.EnableEnableDisableCallTrace( true );
2616 glAbstraction.EnableStencilFunctionCallTrace( true );
2617 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2618 TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2620 // RenderMode must use the stencil for StencilOperation to operate.
2621 renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::STENCIL );
2624 * Lookup table for testing StencilOperation.
2625 * Note: This MUST be in the same order as the Dali::StencilOperation enum.
2627 const int StencilOperationLookupTable[] = {
2636 }; const int StencilOperationLookupTableCount = sizeof( StencilOperationLookupTable ) / sizeof( StencilOperationLookupTable[0] );
2638 // Set all 3 StencilOperation properties to a default.
2639 renderer.SetProperty( Renderer::Property::STENCIL_OPERATION_ON_FAIL, StencilOperation::ZERO );
2640 renderer.SetProperty( Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, StencilOperation::ZERO );
2641 renderer.SetProperty( Renderer::Property::STENCIL_OPERATION_ON_Z_PASS, StencilOperation::ZERO );
2643 // Set our expected parameter list to the equivalent result.
2644 int parameters[] = { StencilOperationLookupTable[ StencilOperation::ZERO ], StencilOperationLookupTable[ StencilOperation::ZERO ], StencilOperationLookupTable[ StencilOperation::ZERO ] };
2646 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2649 * Loop through all types of StencilOperation, checking:
2650 * - The value is cached (set in event thread side)
2651 * - Causes "glStencilFunc" to be called
2652 * - Checks the correct parameters to "glStencilFunc" were used
2653 * - Checks the above for all 3 parameter placements of StencilOperation ( OnFail, OnZFail, OnPass )
2655 int stencilOperationPropertyKeys[] = { Renderer::Property::STENCIL_OPERATION_ON_FAIL, Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, Renderer::Property::STENCIL_OPERATION_ON_Z_PASS };
2656 std::string methodString( "StencilOp" );
2658 for( int parameterIndex = 0; parameterIndex < 3; ++parameterIndex )
2660 for( int i = 0; i < StencilOperationLookupTableCount; ++i )
2662 // Set the property (outer loop causes all 3 different properties to be set separately).
2663 renderer.SetProperty( stencilOperationPropertyKeys[ parameterIndex ], static_cast<Dali::StencilFunction::Type>( i ) );
2665 // Check GetProperty returns the same value.
2666 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( stencilOperationPropertyKeys[ parameterIndex ] ).Get<int>() ), i, TEST_LOCATION );
2668 // Reset the trace debug.
2669 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2671 // Check the function is called and the parameters are correct.
2672 // Set the expected parameter value at its correct index (only)
2673 parameters[ parameterIndex ] = StencilOperationLookupTable[ i ];
2675 // Build the parameter list.
2676 std::stringstream parameterStream;
2677 for( int parameterBuild = 0; parameterBuild < 3; ++parameterBuild )
2679 parameterStream << parameters[ parameterBuild ];
2680 // Comma-separate the parameters.
2681 if( parameterBuild < 2 )
2683 parameterStream << ", ";
2687 // Check the function was called and the parameters were correct.
2688 DALI_TEST_CHECK( glStencilFunctionStack.FindMethodAndParams( methodString, parameterStream.str() ) );
2695 int UtcDaliRendererSetStencilMask(void)
2697 TestApplication application;
2698 tet_infoline("Test setting the StencilMask");
2700 Renderer renderer = RendererTestFixture( application );
2701 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2702 glAbstraction.EnableEnableDisableCallTrace( true );
2703 glAbstraction.EnableStencilFunctionCallTrace( true );
2704 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2705 TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2707 // RenderMode must use the stencil for StencilMask to operate.
2708 renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::STENCIL );
2710 // Set the StencilMask property to a value.
2711 renderer.SetProperty( Renderer::Property::STENCIL_MASK, 0x00 );
2713 // Check GetProperty returns the same value.
2714 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_MASK ).Get<int>() ), 0x00, TEST_LOCATION );
2716 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2718 std::string methodString( "StencilMask" );
2719 std::string parameterString = "0";
2721 // Check the function was called and the parameters were correct.
2722 DALI_TEST_CHECK( glStencilFunctionStack.FindMethodAndParams( methodString, parameterString ) );
2724 // Set the StencilMask property to another value to ensure it has changed.
2725 renderer.SetProperty( Renderer::Property::STENCIL_MASK, 0xFF );
2727 // Check GetProperty returns the same value.
2728 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_MASK ).Get<int>() ), 0xFF, TEST_LOCATION );
2730 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2732 parameterString = "255";
2734 // Check the function was called and the parameters were correct.
2735 DALI_TEST_CHECK( glStencilFunctionStack.FindMethodAndParams( methodString, parameterString ) );
2740 int UtcDaliRendererWrongNumberOfTextures(void)
2742 TestApplication application;
2743 tet_infoline("Test renderer does render even if number of textures is different than active samplers in the shader");
2745 //Create a TextureSet with 4 textures (One more texture in the texture set than active samplers)
2746 //@note Shaders in the test suit have 3 active samplers. See TestGlAbstraction::GetActiveUniform()
2747 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, 64u, 64u );
2748 TextureSet textureSet = CreateTextureSet();
2749 textureSet.SetTexture(0, texture );
2750 textureSet.SetTexture(1, texture );
2751 textureSet.SetTexture(2, texture );
2752 textureSet.SetTexture(3, texture );
2753 Shader shader = Shader::New("VertexSource", "FragmentSource");
2754 Geometry geometry = CreateQuadGeometry();
2755 Renderer renderer = Renderer::New( geometry, shader );
2756 renderer.SetTextures( textureSet );
2758 Actor actor= Actor::New();
2759 actor.AddRenderer(renderer);
2760 actor.SetPosition(0.0f,0.0f);
2761 actor.SetSize(100, 100);
2762 Stage::GetCurrent().Add(actor);
2764 TestGlAbstraction& gl = application.GetGlAbstraction();
2765 TraceCallStack& drawTrace = gl.GetDrawTrace();
2767 drawTrace.Enable(true);
2769 application.SendNotification();
2770 application.Render(0);
2772 //Test we do the drawcall when TextureSet has more textures than there are active samplers in the shader
2773 DALI_TEST_EQUALS( drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION );
2775 //Create a TextureSet with 1 texture (two more active samplers than texture in the texture set)
2776 //@note Shaders in the test suit have 3 active samplers. See TestGlAbstraction::GetActiveUniform()
2777 textureSet = CreateTextureSet();
2778 renderer.SetTextures( textureSet );
2779 textureSet.SetTexture(0, texture );
2781 application.SendNotification();
2782 application.Render(0);
2784 //Test we do the drawcall when TextureSet has less textures than there are active samplers in the shader.
2785 DALI_TEST_EQUALS( drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION );