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/public-api/dali-core.h>
20 #include <dali/devel-api/images/texture-set-image.h>
25 #include <dali-test-suite-utils.h>
26 #include <test-trace-call-stack.h>
27 #include <mesh-builder.h>
31 namespace // unnamed namespace
34 const BlendFactor::Type DEFAULT_BLEND_FACTOR_SRC_RGB( BlendFactor::SRC_ALPHA );
35 const BlendFactor::Type DEFAULT_BLEND_FACTOR_DEST_RGB( BlendFactor::ONE_MINUS_SRC_ALPHA );
36 const BlendFactor::Type DEFAULT_BLEND_FACTOR_SRC_ALPHA( BlendFactor::ONE );
37 const BlendFactor::Type DEFAULT_BLEND_FACTOR_DEST_ALPHA( BlendFactor::ONE_MINUS_SRC_ALPHA );
39 const BlendEquation::Type DEFAULT_BLEND_EQUATION_RGB( BlendEquation::ADD );
40 const BlendEquation::Type DEFAULT_BLEND_EQUATION_ALPHA( BlendEquation::ADD );
43 * @brief Get GL stencil test enumeration value as a string.
44 * @return The string representation of the value of GL_STENCIL_TEST
46 std::string GetStencilTestString(void)
48 std::stringstream stream;
49 stream << GL_STENCIL_TEST;
54 * @brief Get GL depth test enumeration value as a string.
55 * @return The string representation of the value of GL_DEPTH_TEST
57 std::string GetDepthTestString(void)
59 std::stringstream stream;
60 stream << GL_DEPTH_TEST;
64 void ResetDebugAndFlush( TestApplication& application, TraceCallStack& glEnableDisableStack, TraceCallStack& glStencilFunctionStack )
66 glEnableDisableStack.Reset();
67 glStencilFunctionStack.Reset();
68 application.SendNotification();
72 void TestConstraintNoBlue( Vector4& current, const PropertyInputContainer& inputs )
77 } // unnamed namespace
79 void renderer_test_startup(void)
81 test_return_value = TET_UNDEF;
84 void renderer_test_cleanup(void)
86 test_return_value = TET_PASS;
90 int UtcDaliRendererNew01(void)
92 TestApplication application;
94 Geometry geometry = CreateQuadGeometry();
95 Shader shader = CreateShader();
96 Renderer renderer = Renderer::New(geometry, shader);
98 DALI_TEST_EQUALS( (bool)renderer, true, TEST_LOCATION );
102 int UtcDaliRendererNew02(void)
104 TestApplication application;
106 DALI_TEST_EQUALS( (bool)renderer, false, TEST_LOCATION );
110 int UtcDaliRendererCopyConstructor(void)
112 TestApplication application;
114 Geometry geometry = CreateQuadGeometry();
115 Shader shader = CreateShader();
116 Renderer renderer = Renderer::New(geometry, shader);
118 Renderer rendererCopy( renderer );
119 DALI_TEST_EQUALS( (bool)rendererCopy, true, TEST_LOCATION );
124 int UtcDaliRendererAssignmentOperator(void)
126 TestApplication application;
128 Geometry geometry = CreateQuadGeometry();
129 Shader shader = CreateShader();
130 Renderer renderer = Renderer::New(geometry, shader);
133 DALI_TEST_EQUALS( (bool)renderer2, false, TEST_LOCATION );
135 renderer2 = renderer;
136 DALI_TEST_EQUALS( (bool)renderer2, true, TEST_LOCATION );
140 int UtcDaliRendererDownCast01(void)
142 TestApplication application;
144 Geometry geometry = CreateQuadGeometry();
145 Shader shader = CreateShader();
146 Renderer renderer = Renderer::New(geometry, shader);
148 BaseHandle handle(renderer);
149 Renderer renderer2 = Renderer::DownCast(handle);
150 DALI_TEST_EQUALS( (bool)renderer2, true, TEST_LOCATION );
154 int UtcDaliRendererDownCast02(void)
156 TestApplication application;
158 Handle handle = Handle::New(); // Create a custom object
159 Renderer renderer = Renderer::DownCast(handle);
160 DALI_TEST_EQUALS( (bool)renderer, false, TEST_LOCATION );
164 int UtcDaliRendererSetGetGeometry(void)
166 TestApplication application;
167 tet_infoline( "Test SetGeometry, GetGeometry" );
169 Geometry geometry1 = CreateQuadGeometry();
170 Geometry geometry2 = CreateQuadGeometry();
172 Shader shader = CreateShader();
173 Renderer renderer = Renderer::New(geometry1, shader);
174 Actor actor = Actor::New();
175 actor.AddRenderer(renderer);
176 actor.SetSize(400, 400);
177 Stage::GetCurrent().Add(actor);
179 application.SendNotification();
180 application.Render(0);
181 DALI_TEST_EQUALS( renderer.GetGeometry(), geometry1, TEST_LOCATION );
183 // Set geometry2 to the renderer
184 renderer.SetGeometry( geometry2 );
186 application.SendNotification();
187 application.Render(0);
188 DALI_TEST_EQUALS( renderer.GetGeometry(), geometry2, TEST_LOCATION );
193 int UtcDaliRendererSetGetShader(void)
195 TestApplication application;
196 tet_infoline( "Test SetShader, GetShader" );
198 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
199 glAbstraction.EnableCullFaceCallTrace(true);
201 Shader shader1 = CreateShader();
202 shader1.RegisterProperty( "uFadeColor", Color::RED );
204 Shader shader2 = CreateShader();
205 shader2.RegisterProperty( "uFadeColor", Color::GREEN );
207 Geometry geometry = CreateQuadGeometry();
208 Renderer renderer = Renderer::New(geometry, shader1);
209 Actor actor = Actor::New();
210 actor.AddRenderer(renderer);
211 actor.SetSize(400, 400);
212 Stage::GetCurrent().Add(actor);
214 TestGlAbstraction& gl = application.GetGlAbstraction();
215 application.SendNotification();
216 application.Render(0);
218 // Expect that the first shaders's fade color property is accessed
219 Vector4 actualValue(Vector4::ZERO);
220 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
221 DALI_TEST_EQUALS( actualValue, Color::RED, TEST_LOCATION );
223 DALI_TEST_EQUALS( renderer.GetShader(), shader1, TEST_LOCATION );
225 // set the second shader to the renderer
226 renderer.SetShader( shader2 );
228 application.SendNotification();
229 application.Render(0);
231 // Expect that the second shader's fade color property is accessed
232 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
233 DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
235 DALI_TEST_EQUALS( renderer.GetShader(), shader2, TEST_LOCATION );
240 int UtcDaliRendererSetGetDepthIndex(void)
242 TestApplication application;
244 tet_infoline("Test SetDepthIndex, GetDepthIndex");
246 Shader shader = CreateShader();
247 Geometry geometry = CreateQuadGeometry();
248 Renderer renderer = Renderer::New(geometry, shader);
249 Actor actor = Actor::New();
250 actor.AddRenderer(renderer);
251 actor.SetSize(400, 400);
252 Stage::GetCurrent().Add(actor);
254 application.SendNotification();
255 application.Render(0);
256 DALI_TEST_EQUALS( renderer.GetProperty<int>(Renderer::Property::DEPTH_INDEX), 0, TEST_LOCATION );
258 renderer.SetProperty( Renderer::Property::DEPTH_INDEX, 1 );
260 application.SendNotification();
261 application.Render(0);
262 DALI_TEST_EQUALS( renderer.GetProperty<int>(Renderer::Property::DEPTH_INDEX), 1, TEST_LOCATION );
264 renderer.SetProperty( Renderer::Property::DEPTH_INDEX, 10 );
266 application.SendNotification();
267 application.Render(0);
268 DALI_TEST_EQUALS( renderer.GetProperty<int>(Renderer::Property::DEPTH_INDEX), 10, TEST_LOCATION );
273 int UtcDaliRendererSetGetFaceCullingMode(void)
275 TestApplication application;
277 tet_infoline("Test SetFaceCullingMode(cullingMode)");
278 Geometry geometry = CreateQuadGeometry();
279 Shader shader = CreateShader();
280 Renderer renderer = Renderer::New( geometry, shader );
282 Actor actor = Actor::New();
283 actor.AddRenderer(renderer);
284 actor.SetSize(400, 400);
285 Stage::GetCurrent().Add(actor);
287 // By default, none of the faces should be culled
288 unsigned int cullFace = renderer.GetProperty<int>( Renderer::Property::FACE_CULLING_MODE );
289 DALI_TEST_CHECK( static_cast< FaceCullingMode::Type >( cullFace ) == FaceCullingMode::NONE );
291 TestGlAbstraction& gl = application.GetGlAbstraction();
292 TraceCallStack& cullFaceStack = gl.GetCullFaceTrace();
293 gl.EnableCullFaceCallTrace(true);
296 cullFaceStack.Reset();
297 renderer.SetProperty( Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::FRONT_AND_BACK );
298 application.SendNotification();
299 application.Render();
301 DALI_TEST_EQUALS( cullFaceStack.CountMethod( "CullFace" ), 1, TEST_LOCATION );
303 std::ostringstream cullModeString;
304 cullModeString << GL_FRONT_AND_BACK;
306 DALI_TEST_CHECK( cullFaceStack.FindMethodAndParams( "CullFace", cullModeString.str() ) );
307 cullFace = renderer.GetProperty<int>( Renderer::Property::FACE_CULLING_MODE );
308 DALI_TEST_CHECK( static_cast< FaceCullingMode::Type >( cullFace ) == FaceCullingMode::FRONT_AND_BACK );
312 cullFaceStack.Reset();
313 renderer.SetProperty( Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::BACK );
314 application.SendNotification();
315 application.Render();
317 DALI_TEST_EQUALS( cullFaceStack.CountMethod( "CullFace" ), 1, TEST_LOCATION );
319 std::ostringstream cullModeString;
320 cullModeString << GL_BACK;
322 DALI_TEST_CHECK( cullFaceStack.FindMethodAndParams( "CullFace", cullModeString.str() ) );
323 cullFace = renderer.GetProperty<int>( Renderer::Property::FACE_CULLING_MODE );
324 DALI_TEST_CHECK( static_cast< FaceCullingMode::Type >( cullFace ) == FaceCullingMode::BACK );
328 cullFaceStack.Reset();
329 renderer.SetProperty( Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::FRONT );
330 application.SendNotification();
331 application.Render();
333 DALI_TEST_EQUALS( cullFaceStack.CountMethod( "CullFace" ), 1, TEST_LOCATION );
335 std::ostringstream cullModeString;
336 cullModeString << GL_FRONT;
338 DALI_TEST_CHECK( cullFaceStack.FindMethodAndParams( "CullFace", cullModeString.str() ) );
339 cullFace = renderer.GetProperty<int>( Renderer::Property::FACE_CULLING_MODE );
340 DALI_TEST_CHECK( static_cast< FaceCullingMode::Type >( cullFace ) == FaceCullingMode::FRONT );
344 cullFaceStack.Reset();
345 renderer.SetProperty( Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::NONE );
346 application.SendNotification();
347 application.Render();
349 DALI_TEST_EQUALS( cullFaceStack.CountMethod( "CullFace" ), 0, TEST_LOCATION );
350 cullFace = renderer.GetProperty<int>( Renderer::Property::FACE_CULLING_MODE );
351 DALI_TEST_CHECK( static_cast< FaceCullingMode::Type >( cullFace ) == FaceCullingMode::NONE );
357 int UtcDaliRendererBlendOptions01(void)
359 TestApplication application;
361 tet_infoline("Test BLEND_FACTOR properties ");
363 Geometry geometry = CreateQuadGeometry();
364 Shader shader = CreateShader();
365 Renderer renderer = Renderer::New( geometry, shader );
367 Actor actor = Actor::New();
368 // set a transparent actor color so that blending is enabled
369 actor.SetOpacity( 0.5f );
370 actor.AddRenderer(renderer);
371 actor.SetSize(400, 400);
372 Stage::GetCurrent().Add(actor);
374 renderer.SetProperty( Renderer::Property::BLEND_FACTOR_SRC_RGB, BlendFactor::ONE_MINUS_SRC_COLOR );
375 renderer.SetProperty( Renderer::Property::BLEND_FACTOR_DEST_RGB, BlendFactor::SRC_ALPHA_SATURATE );
376 renderer.SetProperty( Renderer::Property::BLEND_FACTOR_SRC_ALPHA, BlendFactor::ONE_MINUS_SRC_COLOR );
377 renderer.SetProperty( Renderer::Property::BLEND_FACTOR_DEST_ALPHA, BlendFactor::SRC_ALPHA_SATURATE );
379 // Test that Set was successful:
380 int srcFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
381 int destFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
382 int srcFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
383 int destFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
385 DALI_TEST_EQUALS( (int)BlendFactor::ONE_MINUS_SRC_COLOR, srcFactorRgb, TEST_LOCATION );
386 DALI_TEST_EQUALS( (int)BlendFactor::SRC_ALPHA_SATURATE, destFactorRgb, TEST_LOCATION );
387 DALI_TEST_EQUALS( (int)BlendFactor::ONE_MINUS_SRC_COLOR, srcFactorAlpha, TEST_LOCATION );
388 DALI_TEST_EQUALS( (int)BlendFactor::SRC_ALPHA_SATURATE, destFactorAlpha, TEST_LOCATION );
390 application.SendNotification();
391 application.Render();
393 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
395 DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_SRC_COLOR, glAbstraction.GetLastBlendFuncSrcRgb(), TEST_LOCATION );
396 DALI_TEST_EQUALS( (GLenum)GL_SRC_ALPHA_SATURATE, glAbstraction.GetLastBlendFuncDstRgb(), TEST_LOCATION );
397 DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_SRC_COLOR, glAbstraction.GetLastBlendFuncSrcAlpha(), TEST_LOCATION );
398 DALI_TEST_EQUALS( (GLenum)GL_SRC_ALPHA_SATURATE, glAbstraction.GetLastBlendFuncDstAlpha(), TEST_LOCATION );
403 int UtcDaliRendererBlendOptions02(void)
405 TestApplication application;
407 tet_infoline("Test BLEND_FACTOR properties ");
409 Geometry geometry = CreateQuadGeometry();
410 Shader shader = CreateShader();
411 Renderer renderer = Renderer::New( geometry, shader );
413 Actor actor = Actor::New();
414 actor.SetOpacity( 0.5f ); // enable blending
415 actor.AddRenderer(renderer);
416 actor.SetSize(400, 400);
417 Stage::GetCurrent().Add(actor);
419 renderer.SetProperty( Renderer::Property::BLEND_FACTOR_SRC_RGB, BlendFactor::CONSTANT_COLOR );
420 renderer.SetProperty( Renderer::Property::BLEND_FACTOR_DEST_RGB, BlendFactor::ONE_MINUS_CONSTANT_COLOR );
421 renderer.SetProperty( Renderer::Property::BLEND_FACTOR_SRC_ALPHA, BlendFactor::CONSTANT_ALPHA );
422 renderer.SetProperty( Renderer::Property::BLEND_FACTOR_DEST_ALPHA, BlendFactor::ONE_MINUS_CONSTANT_ALPHA );
424 // Test that Set was successful:
426 int srcFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
427 int destFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
428 int srcFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
429 int destFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
431 DALI_TEST_EQUALS( (int)BlendFactor::CONSTANT_COLOR, srcFactorRgb, TEST_LOCATION );
432 DALI_TEST_EQUALS( (int)BlendFactor::ONE_MINUS_CONSTANT_COLOR, destFactorRgb, TEST_LOCATION );
433 DALI_TEST_EQUALS( (int)BlendFactor::CONSTANT_ALPHA, srcFactorAlpha, TEST_LOCATION );
434 DALI_TEST_EQUALS( (int)BlendFactor::ONE_MINUS_CONSTANT_ALPHA, destFactorAlpha, TEST_LOCATION );
437 application.SendNotification();
438 application.Render();
440 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
441 DALI_TEST_EQUALS( (GLenum)GL_CONSTANT_COLOR, glAbstraction.GetLastBlendFuncSrcRgb(), TEST_LOCATION );
442 DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_CONSTANT_COLOR, glAbstraction.GetLastBlendFuncDstRgb(), TEST_LOCATION );
443 DALI_TEST_EQUALS( (GLenum)GL_CONSTANT_ALPHA, glAbstraction.GetLastBlendFuncSrcAlpha(), TEST_LOCATION );
444 DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_CONSTANT_ALPHA, glAbstraction.GetLastBlendFuncDstAlpha(), TEST_LOCATION );
449 int UtcDaliRendererBlendOptions03(void)
451 TestApplication application;
453 tet_infoline("Test GetBlendEquation() defaults ");
455 Geometry geometry = CreateQuadGeometry();
456 Shader shader = CreateShader();
457 Renderer renderer = Renderer::New( geometry, shader );
459 Actor actor = Actor::New();
460 actor.AddRenderer(renderer);
461 actor.SetSize(400, 400);
462 Stage::GetCurrent().Add(actor);
464 // Test the defaults as documented in blending.h
465 int equationRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_EQUATION_RGB );
466 int equationAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_EQUATION_ALPHA );
468 DALI_TEST_EQUALS( (int)BlendEquation::ADD, equationRgb, TEST_LOCATION );
469 DALI_TEST_EQUALS( (int)BlendEquation::ADD, equationAlpha, TEST_LOCATION );
474 int UtcDaliRendererBlendOptions04(void)
476 TestApplication application;
478 tet_infoline("Test SetBlendEquation() ");
480 Geometry geometry = CreateQuadGeometry();
481 Shader shader = CreateShader();
482 Renderer renderer = Renderer::New( geometry, shader );
484 Actor actor = Actor::New();
485 actor.SetOpacity( 0.1f );
486 actor.AddRenderer(renderer);
487 actor.SetSize(400, 400);
488 Stage::GetCurrent().Add(actor);
490 // Test the single blending equation setting
492 renderer.SetProperty( Renderer::Property::BLEND_EQUATION_RGB, BlendEquation::REVERSE_SUBTRACT );
493 int equationRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_EQUATION_RGB );
494 DALI_TEST_EQUALS( (int)BlendEquation::REVERSE_SUBTRACT, equationRgb, TEST_LOCATION );
497 renderer.SetProperty( Renderer::Property::BLEND_EQUATION_RGB, BlendEquation::REVERSE_SUBTRACT );
498 renderer.SetProperty( Renderer::Property::BLEND_EQUATION_ALPHA, BlendEquation::REVERSE_SUBTRACT );
500 // Test that Set was successful
502 int equationRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_EQUATION_RGB );
503 int equationAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_EQUATION_ALPHA );
504 DALI_TEST_EQUALS( (int)BlendEquation::REVERSE_SUBTRACT, equationRgb, TEST_LOCATION );
505 DALI_TEST_EQUALS( (int)BlendEquation::REVERSE_SUBTRACT, equationAlpha, TEST_LOCATION );
508 // Render & check GL commands
509 application.SendNotification();
510 application.Render();
512 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
513 DALI_TEST_EQUALS( (GLenum)GL_FUNC_REVERSE_SUBTRACT, glAbstraction.GetLastBlendEquationRgb(), TEST_LOCATION );
514 DALI_TEST_EQUALS( (GLenum)GL_FUNC_REVERSE_SUBTRACT, glAbstraction.GetLastBlendEquationAlpha(), TEST_LOCATION );
519 int UtcDaliRendererSetBlendMode01(void)
521 TestApplication application;
523 tet_infoline("Test setting the blend mode to on with an opaque color renders with blending enabled");
525 Geometry geometry = CreateQuadGeometry();
526 Shader shader = CreateShader();
527 Renderer renderer = Renderer::New( geometry, shader );
529 Actor actor = Actor::New();
530 actor.SetOpacity( 0.98f );
531 actor.AddRenderer(renderer);
532 actor.SetSize(400, 400);
533 Stage::GetCurrent().Add(actor);
535 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::ON);
537 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
538 glAbstraction.EnableEnableDisableCallTrace(true);
540 application.SendNotification();
541 application.Render();
543 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
544 std::ostringstream blendStr;
545 blendStr << GL_BLEND;
546 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
551 int UtcDaliRendererSetBlendMode02(void)
553 TestApplication application;
555 tet_infoline("Test setting the blend mode to off with a transparent color renders with blending disabled (and not enabled)");
557 Geometry geometry = CreateQuadGeometry();
558 Shader shader = CreateShader();
559 Renderer renderer = Renderer::New( geometry, shader );
561 Actor actor = Actor::New();
562 actor.SetOpacity( 0.15f );
563 actor.AddRenderer(renderer);
564 actor.SetSize(400, 400);
565 Stage::GetCurrent().Add(actor);
567 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::OFF);
569 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
570 glAbstraction.EnableEnableDisableCallTrace(true);
572 application.SendNotification();
573 application.Render();
575 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
576 std::ostringstream blendStr;
577 blendStr << GL_BLEND;
578 DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
583 int UtcDaliRendererSetBlendMode03(void)
585 TestApplication application;
587 tet_infoline("Test setting the blend mode to auto with a transparent color renders with blending enabled");
589 Geometry geometry = CreateQuadGeometry();
590 Shader shader = CreateShader();
591 Renderer renderer = Renderer::New( geometry, shader );
593 Actor actor = Actor::New();
594 actor.SetOpacity( 0.75f );
595 actor.AddRenderer(renderer);
596 actor.SetSize(400, 400);
597 Stage::GetCurrent().Add(actor);
599 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::AUTO);
601 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
602 glAbstraction.EnableEnableDisableCallTrace(true);
604 application.SendNotification();
605 application.Render();
607 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
608 std::ostringstream blendStr;
609 blendStr << GL_BLEND;
610 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
615 int UtcDaliRendererSetBlendMode04(void)
617 TestApplication application;
619 tet_infoline("Test setting the blend mode to auto with an opaque color renders with blending disabled");
621 Geometry geometry = CreateQuadGeometry();
622 Shader shader = CreateShader();
623 Renderer renderer = Renderer::New( geometry, shader );
625 Actor actor = Actor::New();
626 actor.AddRenderer(renderer);
627 actor.SetSize(400, 400);
628 Stage::GetCurrent().Add(actor);
630 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::AUTO);
632 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
633 glAbstraction.EnableEnableDisableCallTrace(true);
635 application.SendNotification();
636 application.Render();
638 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
639 std::ostringstream blendStr;
640 blendStr << GL_BLEND;
641 DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
646 int UtcDaliRendererSetBlendMode04b(void)
648 TestApplication application;
650 tet_infoline("Test setting the blend mode to auto with a transparent actor color renders with blending enabled");
652 Geometry geometry = CreateQuadGeometry();
653 Shader shader = CreateShader();
654 Renderer renderer = Renderer::New( geometry, shader );
656 Actor actor = Actor::New();
657 actor.AddRenderer(renderer);
658 actor.SetSize(400, 400);
659 actor.SetColor( Vector4(1.0f, 0.0f, 1.0f, 0.5f) );
660 Stage::GetCurrent().Add(actor);
662 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::AUTO);
664 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
665 glAbstraction.EnableEnableDisableCallTrace(true);
667 application.SendNotification();
668 application.Render();
670 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
671 std::ostringstream blendStr;
672 blendStr << GL_BLEND;
673 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
678 int UtcDaliRendererSetBlendMode04c(void)
680 TestApplication application;
682 tet_infoline("Test setting the blend mode to auto with an opaque opaque actor color renders with blending disabled");
684 Geometry geometry = CreateQuadGeometry();
685 Shader shader = CreateShader();
686 Renderer renderer = Renderer::New( geometry, shader );
688 Actor actor = Actor::New();
689 actor.AddRenderer(renderer);
690 actor.SetSize(400, 400);
691 actor.SetColor( Color::MAGENTA );
692 Stage::GetCurrent().Add(actor);
694 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::AUTO);
696 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
697 glAbstraction.EnableEnableDisableCallTrace(true);
699 application.SendNotification();
700 application.Render();
702 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
703 std::ostringstream blendStr;
704 blendStr << GL_BLEND;
705 DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
710 int UtcDaliRendererSetBlendMode05(void)
712 TestApplication application;
714 tet_infoline("Test setting the blend mode to auto with an opaque color and an image with an alpha channel renders with blending enabled");
716 Geometry geometry = CreateQuadGeometry();
717 BufferImage image = BufferImage::New( 40, 40, Pixel::RGBA8888 );
719 Shader shader = CreateShader();
720 TextureSet textureSet = CreateTextureSet( image );
721 Renderer renderer = Renderer::New( geometry, shader );
722 renderer.SetTextures( textureSet );
724 Actor actor = Actor::New();
725 actor.AddRenderer(renderer);
726 actor.SetSize(400, 400);
727 Stage::GetCurrent().Add(actor);
729 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::AUTO);
731 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
732 glAbstraction.EnableEnableDisableCallTrace(true);
734 application.SendNotification();
735 application.Render();
737 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
738 std::ostringstream blendStr;
739 blendStr << GL_BLEND;
740 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
745 int UtcDaliRendererSetBlendMode06(void)
747 TestApplication application;
748 tet_infoline("Test setting the blend mode to auto with an opaque color and an image without an alpha channel and a shader with the hint OUTPUT_IS_TRANSPARENT renders with blending enabled");
750 Geometry geometry = CreateQuadGeometry();
751 Shader shader = Shader::New( "vertexSrc", "fragmentSrc", Shader::Hint::OUTPUT_IS_TRANSPARENT );
753 Renderer renderer = Renderer::New( geometry, shader );
755 Actor actor = Actor::New();
756 actor.AddRenderer(renderer);
757 actor.SetSize(400, 400);
758 Stage::GetCurrent().Add(actor);
760 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::AUTO);
762 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
763 glAbstraction.EnableEnableDisableCallTrace(true);
765 application.SendNotification();
766 application.Render();
768 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
769 std::ostringstream blendStr;
770 blendStr << GL_BLEND;
771 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
776 int UtcDaliRendererSetBlendMode07(void)
778 TestApplication application;
779 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");
781 Geometry geometry = CreateQuadGeometry();
782 Shader shader = Shader::New( "vertexSrc", "fragmentSrc" );
784 BufferImage image = BufferImage::New( 50, 50, Pixel::RGB888 );
785 TextureSet textureSet = CreateTextureSet( image );
786 Renderer renderer = Renderer::New( geometry, shader );
787 renderer.SetTextures( textureSet );
789 Actor actor = Actor::New();
790 actor.AddRenderer(renderer);
791 actor.SetSize(400, 400);
792 Stage::GetCurrent().Add(actor);
794 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::AUTO);
796 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
797 glAbstraction.EnableEnableDisableCallTrace(true);
799 application.SendNotification();
800 application.Render();
802 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
803 DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", "GL_BLEND" ) );
808 int UtcDaliRendererGetBlendMode(void)
810 TestApplication application;
812 tet_infoline("Test GetBlendMode()");
814 Geometry geometry = CreateQuadGeometry();
815 Shader shader = Shader::New( "vertexSrc", "fragmentSrc" );
816 Renderer renderer = Renderer::New( geometry, shader );
819 unsigned int mode = renderer.GetProperty<int>( Renderer::Property::BLEND_MODE );
820 DALI_TEST_EQUALS( static_cast< BlendMode::Type >( mode ), BlendMode::AUTO, TEST_LOCATION );
823 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::ON );
824 mode = renderer.GetProperty<int>( Renderer::Property::BLEND_MODE );
825 DALI_TEST_EQUALS( static_cast< BlendMode::Type >( mode ), BlendMode::ON, TEST_LOCATION );
828 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::OFF );
829 mode = renderer.GetProperty<int>( Renderer::Property::BLEND_MODE );
830 DALI_TEST_EQUALS( static_cast< BlendMode::Type >( mode ), BlendMode::OFF, TEST_LOCATION );
835 int UtcDaliRendererSetBlendColor(void)
837 TestApplication application;
839 tet_infoline("Test SetBlendColor(color)");
841 Geometry geometry = CreateQuadGeometry();
842 Shader shader = Shader::New( "vertexSrc", "fragmentSrc" );
843 TextureSet textureSet = TextureSet::New();
844 BufferImage image = BufferImage::New( 50, 50, Pixel::RGBA8888 );
845 TextureSetImage( textureSet, 0u, image );
846 Renderer renderer = Renderer::New( geometry, shader );
847 renderer.SetTextures( textureSet );
849 Actor actor = Actor::New();
850 actor.AddRenderer(renderer);
851 actor.SetSize(400, 400);
852 Stage::GetCurrent().Add(actor);
854 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
856 renderer.SetProperty( Renderer::Property::BLEND_COLOR, Color::TRANSPARENT );
857 application.SendNotification();
858 application.Render();
859 DALI_TEST_EQUALS( glAbstraction.GetLastBlendColor(), Color::TRANSPARENT, TEST_LOCATION );
861 renderer.SetProperty( Renderer::Property::BLEND_COLOR, Color::MAGENTA );
862 application.SendNotification();
863 application.Render();
864 DALI_TEST_EQUALS( glAbstraction.GetLastBlendColor(), Color::MAGENTA, TEST_LOCATION );
866 Vector4 color( 0.1f, 0.2f, 0.3f, 0.4f );
867 renderer.SetProperty( Renderer::Property::BLEND_COLOR, color );
868 application.SendNotification();
869 application.Render();
870 DALI_TEST_EQUALS( glAbstraction.GetLastBlendColor(), color, TEST_LOCATION );
875 int UtcDaliRendererGetBlendColor(void)
877 TestApplication application;
879 tet_infoline("Test GetBlendColor()");
881 Geometry geometry = CreateQuadGeometry();
882 Shader shader = Shader::New( "vertexSrc", "fragmentSrc" );
883 Renderer renderer = Renderer::New( geometry, shader );
885 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>( Renderer::Property::BLEND_COLOR ), Color::TRANSPARENT, TEST_LOCATION );
887 renderer.SetProperty( Renderer::Property::BLEND_COLOR, Color::MAGENTA );
888 application.SendNotification();
889 application.Render();
890 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>( Renderer::Property::BLEND_COLOR ), Color::MAGENTA, TEST_LOCATION );
892 Vector4 color( 0.1f, 0.2f, 0.3f, 0.4f );
893 renderer.SetProperty( Renderer::Property::BLEND_COLOR, color );
894 application.SendNotification();
895 application.Render();
896 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>( Renderer::Property::BLEND_COLOR ), color, TEST_LOCATION );
901 int UtcDaliRendererPreMultipledAlpha(void)
903 TestApplication application;
905 tet_infoline("Test BLEND_PRE_MULTIPLIED_ALPHA property");
907 Geometry geometry = CreateQuadGeometry();
908 Shader shader = Shader::New( "vertexSrc", "fragmentSrc" );
909 Renderer renderer = Renderer::New( geometry, shader );
911 Actor actor = Actor::New();
912 actor.AddRenderer(renderer);
913 actor.SetSize(400, 400);
914 actor.SetColor( Vector4(1.0f, 0.0f, 1.0f, 0.5f) );
915 Stage::GetCurrent().Add(actor);
917 Property::Value value = renderer.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
918 bool preMultipliedAlpha;
919 DALI_TEST_CHECK( value.Get( preMultipliedAlpha ) );
920 DALI_TEST_CHECK( !preMultipliedAlpha );
922 int srcFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
923 int destFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
924 int srcFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
925 int destFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
927 DALI_TEST_EQUALS( (int)DEFAULT_BLEND_FACTOR_SRC_RGB, srcFactorRgb, TEST_LOCATION );
928 DALI_TEST_EQUALS( (int)DEFAULT_BLEND_FACTOR_DEST_RGB, destFactorRgb, TEST_LOCATION );
929 DALI_TEST_EQUALS( (int)DEFAULT_BLEND_FACTOR_SRC_ALPHA, srcFactorAlpha, TEST_LOCATION );
930 DALI_TEST_EQUALS( (int)DEFAULT_BLEND_FACTOR_DEST_ALPHA, destFactorAlpha, TEST_LOCATION );
932 application.SendNotification();
933 application.Render();
935 Vector4 actualValue(Vector4::ZERO);
936 TestGlAbstraction& gl = application.GetGlAbstraction();
937 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uColor", actualValue ) );
938 DALI_TEST_EQUALS( actualValue, Vector4(1.0f, 0.0f, 1.0f, 0.5f), TEST_LOCATION );
940 renderer.SetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, true);
942 application.SendNotification();
943 application.Render();
945 value = renderer.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
946 DALI_TEST_CHECK( value.Get( preMultipliedAlpha ) );
947 DALI_TEST_CHECK( preMultipliedAlpha );
949 srcFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
950 destFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
951 srcFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
952 destFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
954 DALI_TEST_EQUALS( (int)BlendFactor::ONE, srcFactorRgb, TEST_LOCATION );
955 DALI_TEST_EQUALS( (int)BlendFactor::ONE_MINUS_SRC_ALPHA, destFactorRgb, TEST_LOCATION );
956 DALI_TEST_EQUALS( (int)BlendFactor::ONE, srcFactorAlpha, TEST_LOCATION );
957 DALI_TEST_EQUALS( (int)BlendFactor::ONE, destFactorAlpha, TEST_LOCATION );
959 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uColor", actualValue ) );
960 DALI_TEST_EQUALS( actualValue, Vector4(0.5f, 0.0f, 0.5f, 0.5f), TEST_LOCATION );
965 int UtcDaliRendererConstraint01(void)
967 TestApplication application;
969 tet_infoline("Test that a non-uniform renderer property can be constrained");
971 Shader shader = Shader::New("VertexSource", "FragmentSource");
972 Geometry geometry = CreateQuadGeometry();
973 Renderer renderer = Renderer::New( geometry, shader );
975 Actor actor = Actor::New();
976 actor.AddRenderer(renderer);
977 actor.SetSize(400, 400);
978 Stage::GetCurrent().Add(actor);
980 Vector4 initialColor = Color::WHITE;
981 Property::Index colorIndex = renderer.RegisterProperty( "uFadeColor", initialColor );
983 application.SendNotification();
984 application.Render(0);
985 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION );
988 Constraint constraint = Constraint::New<Vector4>( renderer, colorIndex, TestConstraintNoBlue );
990 application.SendNotification();
991 application.Render(0);
993 // Expect no blue component in either buffer - yellow
994 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(colorIndex), Color::YELLOW, TEST_LOCATION );
995 application.Render(0);
996 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(colorIndex), Color::YELLOW, TEST_LOCATION );
998 renderer.RemoveConstraints();
999 renderer.SetProperty(colorIndex, Color::WHITE );
1000 application.SendNotification();
1001 application.Render(0);
1002 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(colorIndex), Color::WHITE, TEST_LOCATION );
1007 int UtcDaliRendererConstraint02(void)
1009 TestApplication application;
1011 tet_infoline("Test that a uniform map renderer property can be constrained");
1013 Shader shader = Shader::New("VertexSource", "FragmentSource");
1014 Geometry geometry = CreateQuadGeometry();
1015 Renderer renderer = Renderer::New( geometry, shader );
1017 Actor actor = Actor::New();
1018 actor.AddRenderer(renderer);
1019 actor.SetSize(400, 400);
1020 Stage::GetCurrent().Add(actor);
1021 application.SendNotification();
1022 application.Render(0);
1024 Vector4 initialColor = Color::WHITE;
1025 Property::Index colorIndex = renderer.RegisterProperty( "uFadeColor", initialColor );
1027 TestGlAbstraction& gl = application.GetGlAbstraction();
1029 application.SendNotification();
1030 application.Render(0);
1032 Vector4 actualValue(Vector4::ZERO);
1033 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1034 DALI_TEST_EQUALS( actualValue, initialColor, TEST_LOCATION );
1037 Constraint constraint = Constraint::New<Vector4>( renderer, colorIndex, TestConstraintNoBlue );
1039 application.SendNotification();
1040 application.Render(0);
1042 // Expect no blue component in either buffer - yellow
1043 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1044 DALI_TEST_EQUALS( actualValue, Color::YELLOW, TEST_LOCATION );
1046 application.Render(0);
1047 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1048 DALI_TEST_EQUALS( actualValue, Color::YELLOW, TEST_LOCATION );
1050 renderer.RemoveConstraints();
1051 renderer.SetProperty(colorIndex, Color::WHITE );
1052 application.SendNotification();
1053 application.Render(0);
1055 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1056 DALI_TEST_EQUALS( actualValue, Color::WHITE, TEST_LOCATION );
1061 int UtcDaliRendererAnimatedProperty01(void)
1063 TestApplication application;
1065 tet_infoline("Test that a non-uniform renderer property can be animated");
1067 Shader shader = Shader::New("VertexSource", "FragmentSource");
1068 Geometry geometry = CreateQuadGeometry();
1069 Renderer renderer = Renderer::New( geometry, shader );
1071 Actor actor = Actor::New();
1072 actor.AddRenderer(renderer);
1073 actor.SetSize(400, 400);
1074 Stage::GetCurrent().Add(actor);
1076 Vector4 initialColor = Color::WHITE;
1077 Property::Index colorIndex = renderer.RegisterProperty( "uFadeColor", initialColor );
1079 application.SendNotification();
1080 application.Render(0);
1081 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION );
1083 Animation animation = Animation::New(1.0f);
1084 KeyFrames keyFrames = KeyFrames::New();
1085 keyFrames.Add(0.0f, initialColor);
1086 keyFrames.Add(1.0f, Color::TRANSPARENT);
1087 animation.AnimateBetween( Property( renderer, colorIndex ), keyFrames );
1090 application.SendNotification();
1091 application.Render(500);
1093 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(colorIndex), Color::WHITE * 0.5f, TEST_LOCATION );
1095 application.Render(500);
1097 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(colorIndex), Color::TRANSPARENT, TEST_LOCATION );
1102 int UtcDaliRendererAnimatedProperty02(void)
1104 TestApplication application;
1106 tet_infoline("Test that a uniform map renderer property can be animated");
1108 Shader shader = Shader::New("VertexSource", "FragmentSource");
1109 Geometry geometry = CreateQuadGeometry();
1110 Renderer renderer = Renderer::New( geometry, shader );
1112 Actor actor = Actor::New();
1113 actor.AddRenderer(renderer);
1114 actor.SetSize(400, 400);
1115 Stage::GetCurrent().Add(actor);
1116 application.SendNotification();
1117 application.Render(0);
1119 Vector4 initialColor = Color::WHITE;
1120 Property::Index colorIndex = renderer.RegisterProperty( "uFadeColor", initialColor );
1122 TestGlAbstraction& gl = application.GetGlAbstraction();
1124 application.SendNotification();
1125 application.Render(0);
1127 Vector4 actualValue(Vector4::ZERO);
1128 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1129 DALI_TEST_EQUALS( actualValue, initialColor, TEST_LOCATION );
1131 Animation animation = Animation::New(1.0f);
1132 KeyFrames keyFrames = KeyFrames::New();
1133 keyFrames.Add(0.0f, initialColor);
1134 keyFrames.Add(1.0f, Color::TRANSPARENT);
1135 animation.AnimateBetween( Property( renderer, colorIndex ), keyFrames );
1138 application.SendNotification();
1139 application.Render(500);
1141 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1142 DALI_TEST_EQUALS( actualValue, Color::WHITE * 0.5f, TEST_LOCATION );
1144 application.Render(500);
1145 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1146 DALI_TEST_EQUALS( actualValue, Color::TRANSPARENT, TEST_LOCATION );
1151 int UtcDaliRendererUniformMapPrecendence01(void)
1153 TestApplication application;
1155 tet_infoline("Test the uniform map precedence is applied properly");
1157 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1159 Shader shader = Shader::New("VertexSource", "FragmentSource");
1160 TextureSet textureSet = CreateTextureSet( image );
1162 Geometry geometry = CreateQuadGeometry();
1163 Renderer renderer = Renderer::New( geometry, shader );
1164 renderer.SetTextures( textureSet );
1166 Actor actor = Actor::New();
1167 actor.AddRenderer(renderer);
1168 actor.SetSize(400, 400);
1169 Stage::GetCurrent().Add(actor);
1170 application.SendNotification();
1171 application.Render(0);
1173 renderer.RegisterProperty( "uFadeColor", Color::RED );
1174 actor.RegisterProperty( "uFadeColor", Color::GREEN );
1175 Property::Index shaderFadeColorIndex = shader.RegisterProperty( "uFadeColor", Color::MAGENTA );
1177 TestGlAbstraction& gl = application.GetGlAbstraction();
1179 application.SendNotification();
1180 application.Render(0);
1182 // Expect that the actor's fade color property is accessed
1183 Vector4 actualValue(Vector4::ZERO);
1184 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1185 DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
1187 // Animate shader's fade color property. Should be no change to uniform
1188 Animation animation = Animation::New(1.0f);
1189 KeyFrames keyFrames = KeyFrames::New();
1190 keyFrames.Add(0.0f, Color::WHITE);
1191 keyFrames.Add(1.0f, Color::TRANSPARENT);
1192 animation.AnimateBetween( Property( shader, shaderFadeColorIndex ), keyFrames );
1195 application.SendNotification();
1196 application.Render(500);
1198 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1199 DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
1201 application.Render(500);
1202 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1203 DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
1208 int UtcDaliRendererUniformMapPrecendence02(void)
1210 TestApplication application;
1212 tet_infoline("Test the uniform map precedence is applied properly");
1214 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1216 Shader shader = Shader::New("VertexSource", "FragmentSource");
1217 TextureSet textureSet = CreateTextureSet( image );
1219 Geometry geometry = CreateQuadGeometry();
1220 Renderer renderer = Renderer::New( geometry, shader );
1221 renderer.SetTextures( textureSet );
1223 Actor actor = Actor::New();
1224 actor.AddRenderer(renderer);
1225 actor.SetSize(400, 400);
1226 Stage::GetCurrent().Add(actor);
1227 application.SendNotification();
1228 application.Render(0);
1230 // Don't add property / uniform map to renderer
1231 actor.RegisterProperty( "uFadeColor", Color::GREEN );
1232 Property::Index shaderFadeColorIndex = shader.RegisterProperty( "uFadeColor", Color::BLUE );
1234 TestGlAbstraction& gl = application.GetGlAbstraction();
1236 application.SendNotification();
1237 application.Render(0);
1239 // Expect that the actor's fade color property is accessed
1240 Vector4 actualValue(Vector4::ZERO);
1241 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1242 DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
1244 // Animate texture set's fade color property. Should be no change to uniform
1245 Animation animation = Animation::New(1.0f);
1246 KeyFrames keyFrames = KeyFrames::New();
1247 keyFrames.Add(0.0f, Color::WHITE);
1248 keyFrames.Add(1.0f, Color::TRANSPARENT);
1249 animation.AnimateBetween( Property( shader, shaderFadeColorIndex ), keyFrames );
1252 application.SendNotification();
1253 application.Render(500);
1255 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1256 DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
1258 application.Render(500);
1259 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1260 DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
1266 int UtcDaliRendererUniformMapPrecendence03(void)
1268 TestApplication application;
1270 tet_infoline("Test the uniform map precedence is applied properly");
1272 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1274 Shader shader = Shader::New("VertexSource", "FragmentSource");
1275 TextureSet textureSet = CreateTextureSet( image );
1277 Geometry geometry = CreateQuadGeometry();
1278 Renderer renderer = Renderer::New( geometry, shader );
1279 renderer.SetTextures( textureSet );
1281 Actor actor = Actor::New();
1282 actor.AddRenderer(renderer);
1283 actor.SetSize(400, 400);
1284 Stage::GetCurrent().Add(actor);
1285 application.SendNotification();
1286 application.Render(0);
1288 // Don't add property / uniform map to renderer or actor
1289 shader.RegisterProperty( "uFadeColor", Color::BLACK );
1291 TestGlAbstraction& gl = application.GetGlAbstraction();
1293 application.SendNotification();
1294 application.Render(0);
1296 // Expect that the shader's fade color property is accessed
1297 Vector4 actualValue(Vector4::ZERO);
1298 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1299 DALI_TEST_EQUALS( actualValue, Color::BLACK, TEST_LOCATION );
1304 int UtcDaliRendererUniformMapMultipleUniforms01(void)
1306 TestApplication application;
1308 tet_infoline("Test the uniform maps are collected from all objects (same type)");
1310 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1312 Shader shader = Shader::New("VertexSource", "FragmentSource");
1313 TextureSet textureSet = CreateTextureSet( image );
1315 Geometry geometry = CreateQuadGeometry();
1316 Renderer renderer = Renderer::New( geometry, shader );
1317 renderer.SetTextures( textureSet );
1319 Actor actor = Actor::New();
1320 actor.AddRenderer(renderer);
1321 actor.SetSize(400, 400);
1322 Stage::GetCurrent().Add(actor);
1323 application.SendNotification();
1324 application.Render(0);
1326 renderer.RegisterProperty( "uUniform1", Color::RED );
1327 actor.RegisterProperty( "uUniform2", Color::GREEN );
1328 shader.RegisterProperty( "uUniform3", Color::MAGENTA );
1330 TestGlAbstraction& gl = application.GetGlAbstraction();
1332 application.SendNotification();
1333 application.Render(0);
1335 // Expect that each of the object's uniforms are set
1336 Vector4 uniform1Value(Vector4::ZERO);
1337 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uUniform1", uniform1Value ) );
1338 DALI_TEST_EQUALS( uniform1Value, Color::RED, TEST_LOCATION );
1340 Vector4 uniform2Value(Vector4::ZERO);
1341 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uUniform2", uniform2Value ) );
1342 DALI_TEST_EQUALS( uniform2Value, Color::GREEN, TEST_LOCATION );
1344 Vector4 uniform3Value(Vector4::ZERO);
1345 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uUniform3", uniform3Value ) );
1346 DALI_TEST_EQUALS( uniform3Value, Color::MAGENTA, TEST_LOCATION );
1351 int UtcDaliRendererUniformMapMultipleUniforms02(void)
1353 TestApplication application;
1355 tet_infoline("Test the uniform maps are collected from all objects (different types)");
1357 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1359 Shader shader = Shader::New("VertexSource", "FragmentSource");
1360 TextureSet textureSet = CreateTextureSet( image );
1362 Geometry geometry = CreateQuadGeometry();
1363 Renderer renderer = Renderer::New( geometry, shader );
1364 renderer.SetTextures( textureSet );
1366 Actor actor = Actor::New();
1367 actor.AddRenderer(renderer);
1368 actor.SetSize(400, 400);
1369 Stage::GetCurrent().Add(actor);
1370 application.SendNotification();
1371 application.Render(0);
1373 Property::Value value1(Color::RED);
1374 renderer.RegisterProperty( "uFadeColor", value1 );
1376 Property::Value value2(1.0f);
1377 actor.RegisterProperty( "uFadeProgress", value2 );
1379 Property::Value value3(Matrix3::IDENTITY);
1380 shader.RegisterProperty( "uANormalMatrix", value3 );
1382 TestGlAbstraction& gl = application.GetGlAbstraction();
1384 application.SendNotification();
1385 application.Render(0);
1387 // Expect that each of the object's uniforms are set
1388 Vector4 uniform1Value(Vector4::ZERO);
1389 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", uniform1Value ) );
1390 DALI_TEST_EQUALS( uniform1Value, value1.Get<Vector4>(), TEST_LOCATION );
1392 float uniform2Value(0.0f);
1393 DALI_TEST_CHECK( gl.GetUniformValue<float>( "uFadeProgress", uniform2Value ) );
1394 DALI_TEST_EQUALS( uniform2Value, value2.Get<float>(), TEST_LOCATION );
1396 Matrix3 uniform3Value;
1397 DALI_TEST_CHECK( gl.GetUniformValue<Matrix3>( "uANormalMatrix", uniform3Value ) );
1398 DALI_TEST_EQUALS( uniform3Value, value3.Get<Matrix3>(), TEST_LOCATION );
1403 int UtcDaliRendererRenderOrder2DLayer(void)
1405 TestApplication application;
1406 tet_infoline("Test the rendering order in a 2D layer is correct");
1408 Shader shader = Shader::New("VertexSource", "FragmentSource");
1409 Geometry geometry = CreateQuadGeometry();
1411 Actor actor0 = Actor::New();
1412 actor0.SetAnchorPoint(AnchorPoint::CENTER);
1413 actor0.SetParentOrigin(AnchorPoint::CENTER);
1414 actor0.SetPosition(0.0f,0.0f);
1415 Image image0 = BufferImage::New( 64, 64, Pixel::RGB888 );
1416 TextureSet textureSet0 = CreateTextureSet( image0 );
1417 Renderer renderer0 = Renderer::New( geometry, shader );
1418 renderer0.SetTextures( textureSet0 );
1419 actor0.AddRenderer(renderer0);
1420 actor0.SetSize(1, 1);
1421 Stage::GetCurrent().Add(actor0);
1422 application.SendNotification();
1423 application.Render(0);
1425 Actor actor1 = Actor::New();
1426 actor1.SetAnchorPoint(AnchorPoint::CENTER);
1427 actor1.SetParentOrigin(AnchorPoint::CENTER);
1428 actor1.SetPosition(0.0f,0.0f);
1429 Image image1= BufferImage::New( 64, 64, Pixel::RGB888 );
1430 TextureSet textureSet1 = CreateTextureSet( image1 );
1431 Renderer renderer1 = Renderer::New( geometry, shader );
1432 renderer1.SetTextures( textureSet1 );
1433 actor1.AddRenderer(renderer1);
1434 actor1.SetSize(1, 1);
1435 Stage::GetCurrent().Add(actor1);
1436 application.SendNotification();
1437 application.Render(0);
1439 Actor actor2 = Actor::New();
1440 actor2.SetAnchorPoint(AnchorPoint::CENTER);
1441 actor2.SetParentOrigin(AnchorPoint::CENTER);
1442 actor2.SetPosition(0.0f,0.0f);
1443 Image image2= BufferImage::New( 64, 64, Pixel::RGB888 );
1444 TextureSet textureSet2 = CreateTextureSet( image2 );
1445 Renderer renderer2 = Renderer::New( geometry, shader );
1446 renderer2.SetTextures( textureSet2 );
1447 actor2.AddRenderer(renderer2);
1448 actor2.SetSize(1, 1);
1449 Stage::GetCurrent().Add(actor2);
1450 application.SendNotification();
1451 application.Render(0);
1453 Actor actor3 = Actor::New();
1454 actor3.SetAnchorPoint(AnchorPoint::CENTER);
1455 actor3.SetParentOrigin(AnchorPoint::CENTER);
1456 actor3.SetPosition(0.0f,0.0f);
1457 Image image3 = BufferImage::New( 64, 64, Pixel::RGB888 );
1458 TextureSet textureSet3 = CreateTextureSet( image3 );
1459 Renderer renderer3 = Renderer::New( geometry, shader );
1460 renderer3.SetTextures( textureSet3 );
1461 actor3.AddRenderer(renderer3);
1462 actor3.SetSize(1, 1);
1463 Stage::GetCurrent().Add(actor3);
1464 application.SendNotification();
1465 application.Render(0);
1468 * Create the following hierarchy:
1481 * Expected rendering order : actor2 - actor1 - actor0 - actor3
1486 application.SendNotification();
1487 application.Render(0);
1489 TestGlAbstraction& gl = application.GetGlAbstraction();
1490 gl.EnableTextureCallTrace(true);
1491 application.SendNotification();
1492 application.Render(0);
1494 int textureBindIndex[4];
1495 for( unsigned int i(0); i<4; ++i )
1497 std::stringstream params;
1498 params << GL_TEXTURE_2D<<", "<<i+1;
1499 textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str() );
1502 //Check that actor1 has been rendered after actor2
1503 DALI_TEST_GREATER( textureBindIndex[1], textureBindIndex[2], TEST_LOCATION );
1505 //Check that actor0 has been rendered after actor1
1506 DALI_TEST_GREATER( textureBindIndex[0], textureBindIndex[1], TEST_LOCATION );
1508 //Check that actor3 has been rendered after actor0
1509 DALI_TEST_GREATER( textureBindIndex[3], textureBindIndex[0], TEST_LOCATION );
1514 int UtcDaliRendererRenderOrder2DLayerMultipleRenderers(void)
1516 TestApplication application;
1517 tet_infoline("Test the rendering order in a 2D layer is correct using multiple renderers per actor");
1520 * Creates the following hierarchy:
1522 * actor0------------------------>actor1
1526 * renderer0 renderer1 renderer2 renderer3 renderer4 renderer5
1528 * renderer0 has depth index 2
1529 * renderer1 has depth index 0
1530 * renderer2 has depth index 1
1532 * renderer3 has depth index 1
1533 * renderer4 has depth index 0
1534 * renderer5 has depth index -1
1536 * Expected rendering order: renderer1 - renderer2 - renderer0 - renderer5 - renderer4 - renderer3
1539 Shader shader = Shader::New("VertexSource", "FragmentSource");
1540 Geometry geometry = CreateQuadGeometry();
1542 Actor actor0 = Actor::New();
1543 actor0.SetAnchorPoint(AnchorPoint::CENTER);
1544 actor0.SetParentOrigin(AnchorPoint::CENTER);
1545 actor0.SetPosition(0.0f,0.0f);
1546 actor0.SetSize(1, 1);
1547 Stage::GetCurrent().Add(actor0);
1549 Actor actor1 = Actor::New();
1550 actor1.SetAnchorPoint(AnchorPoint::CENTER);
1551 actor1.SetParentOrigin(AnchorPoint::CENTER);
1552 actor1.SetPosition(0.0f,0.0f);
1553 actor1.SetSize(1, 1);
1557 Image image0 = BufferImage::New( 64, 64, Pixel::RGB888 );
1558 TextureSet textureSet0 = CreateTextureSet( image0 );
1559 Renderer renderer0 = Renderer::New( geometry, shader );
1560 renderer0.SetTextures( textureSet0 );
1561 renderer0.SetProperty( Renderer::Property::DEPTH_INDEX, 2 );
1562 actor0.AddRenderer(renderer0);
1563 application.SendNotification();
1564 application.Render(0);
1567 Image image1= BufferImage::New( 64, 64, Pixel::RGB888 );
1568 TextureSet textureSet1 = CreateTextureSet( image1 );
1569 Renderer renderer1 = Renderer::New( geometry, shader );
1570 renderer1.SetTextures( textureSet1 );
1571 renderer1.SetProperty( Renderer::Property::DEPTH_INDEX, 0 );
1572 actor0.AddRenderer(renderer1);
1573 application.SendNotification();
1574 application.Render(0);
1577 Image image2= BufferImage::New( 64, 64, Pixel::RGB888 );
1578 TextureSet textureSet2 = CreateTextureSet( image2 );
1579 Renderer renderer2 = Renderer::New( geometry, shader );
1580 renderer2.SetTextures( textureSet2 );
1581 renderer2.SetProperty( Renderer::Property::DEPTH_INDEX, 1 );
1582 actor0.AddRenderer(renderer2);
1583 application.SendNotification();
1584 application.Render(0);
1587 Image image3 = BufferImage::New( 64, 64, Pixel::RGB888 );
1588 TextureSet textureSet3 = CreateTextureSet( image3 );
1589 Renderer renderer3 = Renderer::New( geometry, shader );
1590 renderer3.SetTextures( textureSet3 );
1591 renderer3.SetProperty( Renderer::Property::DEPTH_INDEX, 1 );
1592 actor1.AddRenderer(renderer3);
1593 application.SendNotification();
1594 application.Render(0);
1597 Image image4= BufferImage::New( 64, 64, Pixel::RGB888 );
1598 TextureSet textureSet4 = CreateTextureSet( image4 );
1599 Renderer renderer4 = Renderer::New( geometry, shader );
1600 renderer4.SetTextures( textureSet4 );
1601 renderer4.SetProperty( Renderer::Property::DEPTH_INDEX, 0 );
1602 actor1.AddRenderer(renderer4);
1603 application.SendNotification();
1604 application.Render(0);
1607 Image image5= BufferImage::New( 64, 64, Pixel::RGB888 );
1608 TextureSet textureSet5 = CreateTextureSet( image5 );
1609 Renderer renderer5 = Renderer::New( geometry, shader );
1610 renderer5.SetTextures( textureSet5 );
1611 renderer5.SetProperty( Renderer::Property::DEPTH_INDEX, -1 );
1612 actor1.AddRenderer(renderer5);
1613 application.SendNotification();
1614 application.Render(0);
1617 TestGlAbstraction& gl = application.GetGlAbstraction();
1618 gl.EnableTextureCallTrace(true);
1619 application.SendNotification();
1620 application.Render(0);
1622 int textureBindIndex[6];
1623 for( unsigned int i(0); i<6; ++i )
1625 std::stringstream params;
1626 params << GL_TEXTURE_2D<<", "<<i+1;
1627 textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str() );
1630 //Check that renderer3 has been rendered after renderer4
1631 DALI_TEST_GREATER( textureBindIndex[3], textureBindIndex[4], TEST_LOCATION );
1633 //Check that renderer0 has been rendered after renderer2
1634 DALI_TEST_GREATER( textureBindIndex[4], textureBindIndex[5], TEST_LOCATION );
1636 //Check that renderer0 has been rendered after renderer2
1637 DALI_TEST_GREATER( textureBindIndex[5], textureBindIndex[0], TEST_LOCATION );
1639 //Check that renderer0 has been rendered after renderer2
1640 DALI_TEST_GREATER( textureBindIndex[0], textureBindIndex[2], TEST_LOCATION );
1642 //Check that renderer2 has been rendered after renderer1
1643 DALI_TEST_GREATER( textureBindIndex[2], textureBindIndex[1], TEST_LOCATION );
1648 int UtcDaliRendererRenderOrder2DLayerOverlay(void)
1650 TestApplication application;
1651 tet_infoline("Test the rendering order in a 2D layer is correct for overlays");
1653 Shader shader = Shader::New("VertexSource", "FragmentSource");
1654 Geometry geometry = CreateQuadGeometry();
1656 Actor actor0 = Actor::New();
1657 actor0.SetAnchorPoint(AnchorPoint::CENTER);
1658 actor0.SetParentOrigin(AnchorPoint::CENTER);
1659 Image image0 = BufferImage::New( 64, 64, Pixel::RGB888 );
1660 TextureSet textureSet0 = CreateTextureSet( image0 );
1661 Renderer renderer0 = Renderer::New( geometry, shader );
1662 renderer0.SetTextures( textureSet0 );
1663 actor0.AddRenderer(renderer0);
1664 actor0.SetPosition(0.0f,0.0f);
1665 actor0.SetSize(100, 100);
1666 Stage::GetCurrent().Add(actor0);
1667 actor0.SetDrawMode( DrawMode::OVERLAY_2D );
1668 application.SendNotification();
1669 application.Render(0);
1671 Actor actor1 = Actor::New();
1672 actor1.SetAnchorPoint(AnchorPoint::CENTER);
1673 actor1.SetParentOrigin(AnchorPoint::CENTER);
1674 Image image1= BufferImage::New( 64, 64, Pixel::RGB888 );
1675 TextureSet textureSet1 = CreateTextureSet( image1 );
1676 Renderer renderer1 = Renderer::New( geometry, shader );
1677 renderer1.SetTextures( textureSet1 );
1678 actor1.SetPosition(0.0f,0.0f);
1679 actor1.AddRenderer(renderer1);
1680 actor1.SetSize(100, 100);
1681 Stage::GetCurrent().Add(actor1);
1682 actor1.SetDrawMode( DrawMode::OVERLAY_2D );
1683 application.SendNotification();
1684 application.Render(0);
1686 Actor actor2 = Actor::New();
1687 actor2.SetAnchorPoint(AnchorPoint::CENTER);
1688 actor2.SetParentOrigin(AnchorPoint::CENTER);
1689 Image image2= BufferImage::New( 64, 64, Pixel::RGB888 );
1690 TextureSet textureSet2 = CreateTextureSet( image2 );
1691 Renderer renderer2 = Renderer::New( geometry, shader );
1692 renderer2.SetTextures( textureSet2 );
1693 actor2.AddRenderer(renderer2);
1694 actor2.SetPosition(0.0f,0.0f);
1695 actor2.SetSize(100, 100);
1696 Stage::GetCurrent().Add(actor2);
1697 application.SendNotification();
1698 application.Render(0);
1700 Actor actor3 = Actor::New();
1701 actor3.SetAnchorPoint(AnchorPoint::CENTER);
1702 actor3.SetParentOrigin(AnchorPoint::CENTER);
1703 Image image3 = BufferImage::New( 64, 64, Pixel::RGB888 );
1704 TextureSet textureSet3 = CreateTextureSet( image3 );
1705 Renderer renderer3 = Renderer::New( geometry, shader );
1706 renderer3.SetTextures( textureSet3 );
1707 actor3.SetPosition(0.0f,0.0f);
1708 actor3.AddRenderer(renderer3);
1709 actor3.SetSize(100, 100);
1710 Stage::GetCurrent().Add(actor3);
1711 actor3.SetDrawMode( DrawMode::OVERLAY_2D );
1712 application.SendNotification();
1713 application.Render(0);
1715 Actor actor4 = Actor::New();
1716 actor4.SetAnchorPoint(AnchorPoint::CENTER);
1717 actor4.SetParentOrigin(AnchorPoint::CENTER);
1718 Image image4 = BufferImage::New( 64, 64, Pixel::RGB888 );
1719 TextureSet textureSet4 = CreateTextureSet( image4 );
1720 Renderer renderer4 = Renderer::New( geometry, shader );
1721 renderer4.SetTextures( textureSet4 );
1722 actor4.AddRenderer(renderer4);
1723 actor4.SetPosition(0.0f,0.0f);
1724 actor4.SetSize(100, 100);
1725 Stage::GetCurrent().Add(actor4);
1726 application.SendNotification();
1727 application.Render(0);
1730 * Create the following hierarchy:
1737 * (Overlay) (Regular actor)
1747 * Expected rendering order : actor2 - actor4 - actor1 - actor0 - actor3
1749 Stage::GetCurrent().Add( actor2 );
1754 application.SendNotification();
1755 application.Render(0);
1757 TestGlAbstraction& gl = application.GetGlAbstraction();
1758 gl.EnableTextureCallTrace(true);
1759 application.SendNotification();
1760 application.Render(0);
1762 int textureBindIndex[5];
1763 for( unsigned int i(0); i<5; ++i )
1765 std::stringstream params;
1766 params << GL_TEXTURE_2D<<", "<<i+1;
1767 textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str() );
1770 //Check that actor4 has been rendered after actor2
1771 DALI_TEST_GREATER( textureBindIndex[4], textureBindIndex[2], TEST_LOCATION );
1773 //Check that actor1 has been rendered after actor4
1774 DALI_TEST_GREATER( textureBindIndex[1], textureBindIndex[4], TEST_LOCATION );
1776 //Check that actor0 has been rendered after actor1
1777 DALI_TEST_GREATER( textureBindIndex[0], textureBindIndex[1], TEST_LOCATION );
1779 //Check that actor3 has been rendered after actor0
1780 DALI_TEST_GREATER( textureBindIndex[3], textureBindIndex[0], TEST_LOCATION );
1785 int UtcDaliRendererSetIndexRange(void)
1789 "attribute vec2 aPosition;\n"
1792 " gl_Position = aPosition;\n"
1798 " gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0)\n"
1802 TestApplication application;
1803 tet_infoline("Test setting the range of indices to draw");
1805 TestGlAbstraction& gl = application.GetGlAbstraction();
1806 gl.EnableDrawCallTrace( true );
1808 Actor actor = Actor::New();
1809 actor.SetSize( 100, 100 );
1812 Geometry geometry = Geometry::New();
1813 geometry.SetType( Geometry::LINE_LOOP );
1815 // --------------------------------------------------------------------------
1817 unsigned short indices[] = { 0, 2, 4, 6, 8, // offset = 0, count = 5
1818 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, // offset = 5, count = 10
1819 1, 3, 5, 7, 9, 1 }; // offset = 15, count = 6 // line strip
1821 // --------------------------------------------------------------------------
1830 { Vector2( 0.0f, 1.00f) }, { Vector2( 0.0f, -1.00f) },
1831 { Vector2( -0.95f, 0.31f) }, { Vector2( 0.59f, 0.81f) },
1832 { Vector2( -0.59f, -0.81f) }, { Vector2( -0.95f, -0.31f) },
1833 { Vector2( 0.59f, -0.81f) }, { Vector2( 0.95f, -0.31f) },
1834 { Vector2( 0.95f, 0.31f) }, { Vector2( -0.59f, 0.81f) },
1836 Property::Map vertexFormat;
1837 vertexFormat["aPosition"] = Property::VECTOR2;
1838 PropertyBuffer vertexBuffer = PropertyBuffer::New( vertexFormat );
1839 vertexBuffer.SetData( shapes, sizeof(shapes)/sizeof(shapes[0]));
1841 // --------------------------------------------------------------------------
1842 geometry.SetIndexBuffer( indices, sizeof(indices)/sizeof(indices[0]) );
1843 geometry.AddVertexBuffer( vertexBuffer );
1846 Shader shader = Shader::New( vertexShader,fragmentShader );
1847 Renderer renderer = Renderer::New( geometry, shader );
1848 actor.AddRenderer( renderer );
1850 Stage stage = Stage::GetCurrent();
1855 // LINE_LOOP, first 0, count 5
1857 renderer.SetIndexRange( 0, 5 );
1858 application.SendNotification();
1859 application.Render();
1860 sprintf( buffer, "%u, 5, %u, indices", GL_LINE_LOOP, GL_UNSIGNED_SHORT );
1861 bool result = gl.GetDrawTrace().FindMethodAndParams( "DrawElements" , buffer );
1862 DALI_TEST_CHECK( result );
1865 // LINE_LOOP, first 5, count 10
1867 renderer.SetIndexRange( 5, 10 );
1868 sprintf( buffer, "%u, 10, %u, indices", GL_LINE_LOOP, GL_UNSIGNED_SHORT );
1869 application.SendNotification();
1870 application.Render();
1871 bool result = gl.GetDrawTrace().FindMethodAndParams( "DrawElements" , buffer );
1872 DALI_TEST_CHECK( result );
1875 // LINE_STRIP, first 15, count 6
1877 renderer.SetIndexRange( 15, 6 );
1878 geometry.SetType( Geometry::LINE_STRIP );
1879 sprintf( buffer, "%u, 6, %u, indices", GL_LINE_STRIP, GL_UNSIGNED_SHORT );
1880 application.SendNotification();
1881 application.Render();
1882 bool result = gl.GetDrawTrace().FindMethodAndParams( "DrawElements" , buffer );
1883 DALI_TEST_CHECK( result );
1886 // Index out of bounds
1888 renderer.SetIndexRange( 15, 30 );
1889 geometry.SetType( Geometry::LINE_STRIP );
1890 sprintf( buffer, "%u, 6, %u, indices", GL_LINE_STRIP, GL_UNSIGNED_SHORT );
1891 application.SendNotification();
1892 application.Render();
1893 bool result = gl.GetDrawTrace().FindMethodAndParams( "DrawElements" , buffer );
1894 DALI_TEST_CHECK( result );
1897 // drawing whole buffer starting from 15 ( last valid primitive )
1899 renderer.SetIndexRange( 15, 0 );
1900 geometry.SetType( Geometry::LINE_STRIP );
1901 sprintf( buffer, "%u, 6, %u, indices", GL_LINE_STRIP, GL_UNSIGNED_SHORT );
1902 application.SendNotification();
1903 application.Render();
1904 bool result = gl.GetDrawTrace().FindMethodAndParams( "DrawElements" , buffer );
1905 DALI_TEST_CHECK( result );
1912 int UtcDaliRendererSetDepthFunction(void)
1914 TestApplication application;
1916 tet_infoline("Test setting the depth function");
1918 Geometry geometry = CreateQuadGeometry();
1919 Shader shader = CreateShader();
1920 Renderer renderer = Renderer::New( geometry, shader );
1922 Actor actor = Actor::New();
1923 actor.AddRenderer(renderer);
1924 actor.SetSize(400, 400);
1925 Stage stage = Stage::GetCurrent();
1926 stage.GetRootLayer().SetBehavior( Layer::LAYER_3D );
1929 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1930 glAbstraction.EnableEnableDisableCallTrace(true);
1931 glAbstraction.EnableDepthFunctionCallTrace(true);
1933 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
1934 TraceCallStack& glDepthFunctionStack = glAbstraction.GetDepthFunctionTrace();
1936 std::ostringstream depthTestStr;
1937 depthTestStr << GL_DEPTH_TEST;
1941 renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::NEVER);
1943 glEnableDisableStack.Reset();
1944 glDepthFunctionStack.Reset();
1945 application.SendNotification();
1946 application.Render();
1948 DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Enable", depthTestStr.str().c_str() ) );
1949 std::ostringstream depthFunctionStr;
1950 depthFunctionStr << GL_NEVER;
1951 DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
1956 renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::ALWAYS);
1958 glDepthFunctionStack.Reset();
1959 application.SendNotification();
1960 application.Render();
1962 std::ostringstream depthFunctionStr;
1963 depthFunctionStr << GL_ALWAYS;
1964 DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
1969 renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::LESS);
1971 glDepthFunctionStack.Reset();
1972 application.SendNotification();
1973 application.Render();
1975 std::ostringstream depthFunctionStr;
1976 depthFunctionStr << GL_LESS;
1977 DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
1982 renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::GREATER);
1984 glDepthFunctionStack.Reset();
1985 application.SendNotification();
1986 application.Render();
1988 std::ostringstream depthFunctionStr;
1989 depthFunctionStr << GL_GREATER;
1990 DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
1995 renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::EQUAL);
1997 glDepthFunctionStack.Reset();
1998 application.SendNotification();
1999 application.Render();
2001 std::ostringstream depthFunctionStr;
2002 depthFunctionStr << GL_EQUAL;
2003 DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
2008 renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::NOT_EQUAL);
2010 glDepthFunctionStack.Reset();
2011 application.SendNotification();
2012 application.Render();
2014 std::ostringstream depthFunctionStr;
2015 depthFunctionStr << GL_NOTEQUAL;
2016 DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
2021 renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::LESS_EQUAL);
2023 glDepthFunctionStack.Reset();
2024 application.SendNotification();
2025 application.Render();
2027 std::ostringstream depthFunctionStr;
2028 depthFunctionStr << GL_LEQUAL;
2029 DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
2034 renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::GREATER_EQUAL);
2036 glDepthFunctionStack.Reset();
2037 application.SendNotification();
2038 application.Render();
2040 std::ostringstream depthFunctionStr;
2041 depthFunctionStr << GL_GEQUAL;
2042 DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
2048 Renderer RendererTestFixture( TestApplication& application )
2050 Geometry geometry = CreateQuadGeometry();
2051 Shader shader = CreateShader();
2052 Renderer renderer = Renderer::New( geometry, shader );
2054 Actor actor = Actor::New();
2055 actor.AddRenderer( renderer );
2056 actor.SetSize( 400.0f, 400.0f );
2057 Stage stage = Stage::GetCurrent();
2058 stage.GetRootLayer().SetBehavior( Layer::LAYER_3D );
2064 int UtcDaliRendererSetDepthTestMode(void)
2066 TestApplication application;
2067 tet_infoline("Test setting the DepthTestMode");
2069 Renderer renderer = RendererTestFixture( application );
2070 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2071 glAbstraction.EnableEnableDisableCallTrace( true );
2072 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2074 glEnableDisableStack.Reset();
2075 application.SendNotification();
2076 application.Render();
2078 // Check depth-test is enabled by default.
2079 DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Enable", GetDepthTestString() ) );
2080 DALI_TEST_CHECK( !glEnableDisableStack.FindMethodAndParams( "Disable", GetDepthTestString() ) );
2082 // 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.
2083 renderer.SetProperty( Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::OFF );
2084 renderer.SetProperty( Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::OFF );
2086 glEnableDisableStack.Reset();
2087 application.SendNotification();
2088 application.Render();
2090 // Check the depth buffer was disabled.
2091 DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Disable", GetDepthTestString() ) );
2093 // Turn on automatic mode depth-testing.
2094 // Layer behavior is currently set to LAYER_3D so AUTO should enable depth-testing.
2095 renderer.SetProperty( Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::AUTO );
2097 glEnableDisableStack.Reset();
2098 application.SendNotification();
2099 application.Render();
2101 // Check depth-test is now enabled.
2102 DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Enable", GetDepthTestString() ) );
2103 DALI_TEST_CHECK( !glEnableDisableStack.FindMethodAndParams( "Disable", GetDepthTestString() ) );
2105 // Change the layer behavior to LAYER_2D.
2106 // Note this will also disable depth testing for the layer by default, we test this first.
2107 Stage::GetCurrent().GetRootLayer().SetBehavior( Layer::LAYER_2D );
2109 glEnableDisableStack.Reset();
2110 application.SendNotification();
2111 application.Render();
2113 // Check depth-test is disabled.
2114 DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Disable", GetDepthTestString() ) );
2116 // Turn the layer depth-test flag back on, and confirm that depth testing is *still* off.
2117 // This is because our renderer has DepthTestMode::AUTO and our layer behavior is LAYER_2D.
2118 Stage::GetCurrent().GetRootLayer().SetDepthTestDisabled( false );
2120 glEnableDisableStack.Reset();
2121 application.SendNotification();
2122 application.Render();
2124 // Check depth-test is *still* disabled.
2125 DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Disable", GetDepthTestString() ) );
2130 int UtcDaliRendererSetDepthWriteMode(void)
2132 TestApplication application;
2133 tet_infoline("Test setting the DepthWriteMode");
2135 Renderer renderer = RendererTestFixture( application );
2136 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2138 application.SendNotification();
2139 application.Render();
2141 // Check the default depth-write status first.
2142 DALI_TEST_CHECK( glAbstraction.GetLastDepthMask() );
2144 // Turn off depth-writing.
2145 renderer.SetProperty( Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::OFF );
2147 application.SendNotification();
2148 application.Render();
2150 // Check depth-write is now disabled.
2151 DALI_TEST_CHECK( !glAbstraction.GetLastDepthMask() );
2153 // Test the AUTO mode for depth-writing.
2154 // As our renderer is opaque, depth-testing should be enabled.
2155 renderer.SetProperty( Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::AUTO );
2157 application.SendNotification();
2158 application.Render();
2160 // Check depth-write is now enabled.
2161 DALI_TEST_CHECK( glAbstraction.GetLastDepthMask() );
2163 // Now make the renderer be treated as translucent by enabling blending.
2164 // The AUTO depth-write mode should turn depth-write off in this scenario.
2165 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::ON );
2167 application.SendNotification();
2168 application.Render();
2170 // Check depth-write is now disabled.
2171 DALI_TEST_CHECK( !glAbstraction.GetLastDepthMask() );
2176 int UtcDaliRendererCheckStencilDefaults(void)
2178 TestApplication application;
2179 tet_infoline("Test the stencil defaults");
2181 Renderer renderer = RendererTestFixture( application );
2182 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2183 glAbstraction.EnableEnableDisableCallTrace( true );
2184 glAbstraction.EnableStencilFunctionCallTrace( true );
2185 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2186 TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2188 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2190 // Check the defaults:
2191 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_FUNCTION ).Get<int>() ), static_cast<int>( StencilFunction::ALWAYS ), TEST_LOCATION );
2192 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_FUNCTION_MASK ).Get<int>() ), 0xFF, TEST_LOCATION );
2193 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_FUNCTION_REFERENCE ).Get<int>() ), 0x00, TEST_LOCATION );
2194 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_MASK ).Get<int>() ), 0xFF, TEST_LOCATION );
2195 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_OPERATION_ON_FAIL ).Get<int>() ), static_cast<int>( StencilOperation::KEEP ), TEST_LOCATION );
2196 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 );
2197 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 );
2202 int UtcDaliRendererSetStencilMode(void)
2204 TestApplication application;
2205 tet_infoline("Test setting the StencilMode");
2207 Renderer renderer = RendererTestFixture( application );
2208 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2209 glAbstraction.EnableEnableDisableCallTrace( true );
2210 glAbstraction.EnableStencilFunctionCallTrace( true );
2211 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2212 TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2214 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2216 // Set the StencilFunction to something other than the default, to confirm it is set as a property,
2217 // but NO GL call has been made while the StencilMode is set to OFF.
2218 renderer.SetProperty( Renderer::Property::STENCIL_FUNCTION, StencilFunction::NEVER );
2219 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_FUNCTION ).Get<int>() ), static_cast<int>( StencilFunction::NEVER ), TEST_LOCATION );
2220 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2222 std::string methodString( "StencilFunc" );
2223 DALI_TEST_CHECK( !glStencilFunctionStack.FindMethod( methodString ) );
2225 // Now set the StencilMode to ON and check the StencilFunction has changed.
2226 renderer.SetProperty( Renderer::Property::STENCIL_MODE, StencilMode::ON );
2227 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2229 DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Enable", GetStencilTestString() ) );
2230 DALI_TEST_CHECK( glStencilFunctionStack.FindMethod( methodString ) );
2235 int UtcDaliRendererSetStencilFunction(void)
2237 TestApplication application;
2238 tet_infoline("Test setting the StencilFunction");
2240 Renderer renderer = RendererTestFixture( application );
2241 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2242 glAbstraction.EnableEnableDisableCallTrace( true );
2243 glAbstraction.EnableStencilFunctionCallTrace( true );
2244 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2245 TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2247 // StencilMode must be ON for StencilFunction to operate.
2248 renderer.SetProperty( Renderer::Property::STENCIL_MODE, StencilMode::ON );
2249 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2252 * Lookup table for testing StencilFunction.
2253 * Note: This MUST be in the same order as the Dali::StencilFunction enum.
2255 const int StencilFunctionLookupTable[] = {
2264 }; const int StencilFunctionLookupTableCount = sizeof( StencilFunctionLookupTable ) / sizeof( StencilFunctionLookupTable[0] );
2267 * Loop through all types of StencilFunction, checking:
2268 * - The value is cached (set in event thread side)
2269 * - Causes "glStencilFunc" to be called
2270 * - Checks the correct parameters to "glStencilFunc" were used
2272 std::string nonChangingParameters = "0, 255";
2273 std::string methodString( "StencilFunc" );
2274 for( int i = 0; i < StencilFunctionLookupTableCount; ++i )
2276 // Set the property.
2277 renderer.SetProperty( Renderer::Property::STENCIL_FUNCTION, static_cast<Dali::StencilFunction::Type>( i ) );
2279 // Check GetProperty returns the same value.
2280 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_FUNCTION ).Get<int>() ), i, TEST_LOCATION );
2282 // Reset the trace debug.
2283 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2285 // Check the function is called and the parameters are correct.
2286 std::stringstream parameterStream;
2287 parameterStream << StencilFunctionLookupTable[ i ] << ", " << nonChangingParameters;
2289 DALI_TEST_CHECK( glStencilFunctionStack.FindMethodAndParams( methodString, parameterStream.str() ) );
2292 // Change the Function Reference only and check the behavior is correct:
2293 // 170 is 0xaa in hex / 10101010 in binary (every other bit set).
2294 int testValueReference = 170;
2295 renderer.SetProperty( Renderer::Property::STENCIL_FUNCTION_REFERENCE, testValueReference );
2297 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_FUNCTION_REFERENCE ).Get<int>() ), testValueReference, TEST_LOCATION );
2299 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2301 std::stringstream parameterStream;
2302 parameterStream << StencilFunctionLookupTable[ StencilOperation::DECREMENT_WRAP ] << ", " << testValueReference << ", 255";
2304 DALI_TEST_CHECK( glStencilFunctionStack.FindMethodAndParams( methodString, parameterStream.str() ) );
2307 // Change the Function Mask only and check the behavior is correct:
2308 // 85 is 0x55 in hex / 01010101 in binary (every other bit set).
2309 int testValueMask = 85;
2310 renderer.SetProperty( Renderer::Property::STENCIL_FUNCTION_MASK, testValueMask );
2312 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_FUNCTION_MASK ).Get<int>() ), testValueMask, TEST_LOCATION );
2314 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2316 // Clear the stringstream.
2317 parameterStream.str( std::string() );
2318 parameterStream << StencilFunctionLookupTable[ StencilOperation::DECREMENT_WRAP ] << ", " << testValueReference << ", " << testValueMask;
2320 DALI_TEST_CHECK( glStencilFunctionStack.FindMethodAndParams( methodString, parameterStream.str() ) );
2325 int UtcDaliRendererSetStencilOperation(void)
2327 TestApplication application;
2328 tet_infoline("Test setting the StencilOperation");
2330 Renderer renderer = RendererTestFixture( application );
2331 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2332 glAbstraction.EnableEnableDisableCallTrace( true );
2333 glAbstraction.EnableStencilFunctionCallTrace( true );
2334 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2335 TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2337 // StencilMode must be ON for StencilOperation to operate.
2338 renderer.SetProperty( Renderer::Property::STENCIL_MODE, StencilMode::ON );
2341 * Lookup table for testing StencilOperation.
2342 * Note: This MUST be in the same order as the Dali::StencilOperation enum.
2344 const int StencilOperationLookupTable[] = {
2353 }; const int StencilOperationLookupTableCount = sizeof( StencilOperationLookupTable ) / sizeof( StencilOperationLookupTable[0] );
2355 // Set all 3 StencilOperation properties to a default.
2356 renderer.SetProperty( Renderer::Property::STENCIL_OPERATION_ON_FAIL, StencilOperation::ZERO );
2357 renderer.SetProperty( Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, StencilOperation::ZERO );
2358 renderer.SetProperty( Renderer::Property::STENCIL_OPERATION_ON_Z_PASS, StencilOperation::ZERO );
2360 // Set our expected parameter list to the equivalent result.
2361 int parameters[] = { StencilOperationLookupTable[ StencilOperation::ZERO ], StencilOperationLookupTable[ StencilOperation::ZERO ], StencilOperationLookupTable[ StencilOperation::ZERO ] };
2363 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2366 * Loop through all types of StencilOperation, checking:
2367 * - The value is cached (set in event thread side)
2368 * - Causes "glStencilFunc" to be called
2369 * - Checks the correct parameters to "glStencilFunc" were used
2370 * - Checks the above for all 3 parameter placements of StencilOperation ( OnFail, OnZFail, OnPass )
2372 int stencilOperationPropertyKeys[] = { Renderer::Property::STENCIL_OPERATION_ON_FAIL, Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, Renderer::Property::STENCIL_OPERATION_ON_Z_PASS };
2373 std::string methodString( "StencilOp" );
2375 for( int parameterIndex = 0; parameterIndex < 3; ++parameterIndex )
2377 for( int i = 0; i < StencilOperationLookupTableCount; ++i )
2379 // Set the property (outer loop causes all 3 different properties to be set separately).
2380 renderer.SetProperty( stencilOperationPropertyKeys[ parameterIndex ], static_cast<Dali::StencilFunction::Type>( i ) );
2382 // Check GetProperty returns the same value.
2383 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( stencilOperationPropertyKeys[ parameterIndex ] ).Get<int>() ), i, TEST_LOCATION );
2385 // Reset the trace debug.
2386 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2388 // Check the function is called and the parameters are correct.
2389 // Set the expected parameter value at its correct index (only)
2390 parameters[ parameterIndex ] = StencilOperationLookupTable[ i ];
2392 // Build the parameter list.
2393 std::stringstream parameterStream;
2394 for( int parameterBuild = 0; parameterBuild < 3; ++parameterBuild )
2396 parameterStream << parameters[ parameterBuild ];
2397 // Comma-separate the parameters.
2398 if( parameterBuild < 2 )
2400 parameterStream << ", ";
2404 // Check the function was called and the parameters were correct.
2405 DALI_TEST_CHECK( glStencilFunctionStack.FindMethodAndParams( methodString, parameterStream.str() ) );
2412 int UtcDaliRendererSetStencilMask(void)
2414 TestApplication application;
2415 tet_infoline("Test setting the StencilMask");
2417 Renderer renderer = RendererTestFixture( application );
2418 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2419 glAbstraction.EnableEnableDisableCallTrace( true );
2420 glAbstraction.EnableStencilFunctionCallTrace( true );
2421 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2422 TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2424 // StencilMode must be ON for StencilMask to operate.
2425 renderer.SetProperty( Renderer::Property::STENCIL_MODE, StencilMode::ON );
2427 // Set the StencilMask property to a value.
2428 renderer.SetProperty( Renderer::Property::STENCIL_MASK, 0x00 );
2430 // Check GetProperty returns the same value.
2431 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_MASK ).Get<int>() ), 0x00, TEST_LOCATION );
2433 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2435 std::string methodString( "StencilMask" );
2436 std::string parameterString = "0";
2438 // Check the function was called and the parameters were correct.
2439 DALI_TEST_CHECK( glStencilFunctionStack.FindMethodAndParams( methodString, parameterString ) );
2441 // Set the StencilMask property to another value to ensure it has changed.
2442 renderer.SetProperty( Renderer::Property::STENCIL_MASK, 0xFF );
2444 // Check GetProperty returns the same value.
2445 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_MASK ).Get<int>() ), 0xFF, TEST_LOCATION );
2447 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2449 parameterString = "255";
2451 // Check the function was called and the parameters were correct.
2452 DALI_TEST_CHECK( glStencilFunctionStack.FindMethodAndParams( methodString, parameterString ) );
2457 int UtcDaliRendererSetWriteToColorBuffer(void)
2459 TestApplication application;
2460 tet_infoline("Test setting the WriteToColorBuffer flag");
2462 Renderer renderer = RendererTestFixture( application );
2463 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2465 // Set the StencilMask property to a value.
2466 renderer.SetProperty( Renderer::Property::WRITE_TO_COLOR_BUFFER, false );
2468 // Check GetProperty returns the same value.
2469 DALI_TEST_CHECK( !renderer.GetProperty( Renderer::Property::WRITE_TO_COLOR_BUFFER ).Get<bool>() );
2471 application.SendNotification();
2472 application.Render();
2474 // Check if ColorMask has been called, and that the values are correct.
2475 const TestGlAbstraction::ColorMaskParams& colorMaskParams( glAbstraction.GetColorMaskParams() );
2477 DALI_TEST_EQUALS<bool>( colorMaskParams.red, false, TEST_LOCATION );
2478 DALI_TEST_EQUALS<bool>( colorMaskParams.green, false, TEST_LOCATION );
2479 DALI_TEST_EQUALS<bool>( colorMaskParams.blue, false, TEST_LOCATION );
2480 DALI_TEST_EQUALS<bool>( colorMaskParams.alpha, false, TEST_LOCATION );
2482 // Set the StencilMask property to true.
2483 renderer.SetProperty( Renderer::Property::WRITE_TO_COLOR_BUFFER, true );
2485 // Check GetProperty returns the same value.
2486 DALI_TEST_CHECK( renderer.GetProperty( Renderer::Property::WRITE_TO_COLOR_BUFFER ).Get<bool>() );
2488 application.SendNotification();
2489 application.Render();
2491 // Check if ColorMask has been called, and that the values are correct.
2492 const TestGlAbstraction::ColorMaskParams& colorMaskParamsChanged( glAbstraction.GetColorMaskParams() );
2494 DALI_TEST_EQUALS<bool>( colorMaskParamsChanged.red, true, TEST_LOCATION );
2495 DALI_TEST_EQUALS<bool>( colorMaskParamsChanged.green, true, TEST_LOCATION );
2496 DALI_TEST_EQUALS<bool>( colorMaskParamsChanged.blue, true, TEST_LOCATION );
2497 DALI_TEST_EQUALS<bool>( colorMaskParamsChanged.alpha, true, TEST_LOCATION );