2 * Copyright (c) 2017 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>
23 #include <dali/devel-api/object/handle-devel.h>
28 #include <dali-test-suite-utils.h>
29 #include <test-trace-call-stack.h>
30 #include <mesh-builder.h>
34 namespace // unnamed namespace
37 const BlendFactor::Type DEFAULT_BLEND_FACTOR_SRC_RGB( BlendFactor::SRC_ALPHA );
38 const BlendFactor::Type DEFAULT_BLEND_FACTOR_DEST_RGB( BlendFactor::ONE_MINUS_SRC_ALPHA );
39 const BlendFactor::Type DEFAULT_BLEND_FACTOR_SRC_ALPHA( BlendFactor::ONE );
40 const BlendFactor::Type DEFAULT_BLEND_FACTOR_DEST_ALPHA( BlendFactor::ONE_MINUS_SRC_ALPHA );
42 const BlendEquation::Type DEFAULT_BLEND_EQUATION_RGB( BlendEquation::ADD );
43 const BlendEquation::Type DEFAULT_BLEND_EQUATION_ALPHA( BlendEquation::ADD );
46 * @brief Get GL stencil test enumeration value as a string.
47 * @return The string representation of the value of GL_STENCIL_TEST
49 std::string GetStencilTestString(void)
51 std::stringstream stream;
52 stream << GL_STENCIL_TEST;
57 * @brief Get GL depth test enumeration value as a string.
58 * @return The string representation of the value of GL_DEPTH_TEST
60 std::string GetDepthTestString(void)
62 std::stringstream stream;
63 stream << GL_DEPTH_TEST;
67 void ResetDebugAndFlush( TestApplication& application, TraceCallStack& glEnableDisableStack, TraceCallStack& glStencilFunctionStack )
69 glEnableDisableStack.Reset();
70 glStencilFunctionStack.Reset();
71 application.SendNotification();
75 void TestConstraintNoBlue( Vector4& current, const PropertyInputContainer& inputs )
80 } // unnamed namespace
82 void renderer_test_startup(void)
84 test_return_value = TET_UNDEF;
87 void renderer_test_cleanup(void)
89 test_return_value = TET_PASS;
93 int UtcDaliRendererNew01(void)
95 TestApplication application;
97 Geometry geometry = CreateQuadGeometry();
98 Shader shader = CreateShader();
99 Renderer renderer = Renderer::New(geometry, shader);
101 DALI_TEST_EQUALS( (bool)renderer, true, TEST_LOCATION );
105 int UtcDaliRendererNew02(void)
107 TestApplication application;
109 DALI_TEST_EQUALS( (bool)renderer, false, TEST_LOCATION );
113 int UtcDaliRendererCopyConstructor(void)
115 TestApplication application;
117 Geometry geometry = CreateQuadGeometry();
118 Shader shader = CreateShader();
119 Renderer renderer = Renderer::New(geometry, shader);
121 Renderer rendererCopy( renderer );
122 DALI_TEST_EQUALS( (bool)rendererCopy, true, TEST_LOCATION );
127 int UtcDaliRendererAssignmentOperator(void)
129 TestApplication application;
131 Geometry geometry = CreateQuadGeometry();
132 Shader shader = CreateShader();
133 Renderer renderer = Renderer::New(geometry, shader);
136 DALI_TEST_EQUALS( (bool)renderer2, false, TEST_LOCATION );
138 renderer2 = renderer;
139 DALI_TEST_EQUALS( (bool)renderer2, true, TEST_LOCATION );
143 int UtcDaliRendererDownCast01(void)
145 TestApplication application;
147 Geometry geometry = CreateQuadGeometry();
148 Shader shader = CreateShader();
149 Renderer renderer = Renderer::New(geometry, shader);
151 BaseHandle handle(renderer);
152 Renderer renderer2 = Renderer::DownCast(handle);
153 DALI_TEST_EQUALS( (bool)renderer2, true, TEST_LOCATION );
157 int UtcDaliRendererDownCast02(void)
159 TestApplication application;
161 Handle handle = Handle::New(); // Create a custom object
162 Renderer renderer = Renderer::DownCast(handle);
163 DALI_TEST_EQUALS( (bool)renderer, false, TEST_LOCATION );
167 int UtcDaliRendererSetGetGeometry(void)
169 TestApplication application;
170 tet_infoline( "Test SetGeometry, GetGeometry" );
172 Geometry geometry1 = CreateQuadGeometry();
173 Geometry geometry2 = CreateQuadGeometry();
175 Shader shader = CreateShader();
176 Renderer renderer = Renderer::New(geometry1, shader);
177 Actor actor = Actor::New();
178 actor.AddRenderer(renderer);
179 actor.SetSize(400, 400);
180 Stage::GetCurrent().Add(actor);
182 application.SendNotification();
183 application.Render(0);
184 DALI_TEST_EQUALS( renderer.GetGeometry(), geometry1, TEST_LOCATION );
186 // Set geometry2 to the renderer
187 renderer.SetGeometry( geometry2 );
189 application.SendNotification();
190 application.Render(0);
191 DALI_TEST_EQUALS( renderer.GetGeometry(), geometry2, TEST_LOCATION );
196 int UtcDaliRendererSetGetShader(void)
198 TestApplication application;
199 tet_infoline( "Test SetShader, GetShader" );
201 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
202 glAbstraction.EnableCullFaceCallTrace(true);
204 Shader shader1 = CreateShader();
205 shader1.RegisterProperty( "uFadeColor", Color::RED );
207 Shader shader2 = CreateShader();
208 shader2.RegisterProperty( "uFadeColor", Color::GREEN );
210 Geometry geometry = CreateQuadGeometry();
211 Renderer renderer = Renderer::New(geometry, shader1);
212 Actor actor = Actor::New();
213 actor.AddRenderer(renderer);
214 actor.SetSize(400, 400);
215 Stage::GetCurrent().Add(actor);
217 TestGlAbstraction& gl = application.GetGlAbstraction();
218 application.SendNotification();
219 application.Render(0);
221 // Expect that the first shaders's fade color property is accessed
222 Vector4 actualValue(Vector4::ZERO);
223 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
224 DALI_TEST_EQUALS( actualValue, Color::RED, TEST_LOCATION );
226 DALI_TEST_EQUALS( renderer.GetShader(), shader1, TEST_LOCATION );
228 // set the second shader to the renderer
229 renderer.SetShader( shader2 );
231 application.SendNotification();
232 application.Render(0);
234 // Expect that the second shader's fade color property is accessed
235 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
236 DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
238 DALI_TEST_EQUALS( renderer.GetShader(), shader2, TEST_LOCATION );
243 int UtcDaliRendererSetGetDepthIndex(void)
245 TestApplication application;
247 tet_infoline("Test SetDepthIndex, GetDepthIndex");
249 Shader shader = CreateShader();
250 Geometry geometry = CreateQuadGeometry();
251 Renderer renderer = Renderer::New(geometry, shader);
252 Actor actor = Actor::New();
253 actor.AddRenderer(renderer);
254 actor.SetSize(400, 400);
255 Stage::GetCurrent().Add(actor);
257 application.SendNotification();
258 application.Render(0);
259 DALI_TEST_EQUALS( renderer.GetProperty<int>(Renderer::Property::DEPTH_INDEX), 0, TEST_LOCATION );
261 renderer.SetProperty( Renderer::Property::DEPTH_INDEX, 1 );
263 application.SendNotification();
264 application.Render(0);
265 DALI_TEST_EQUALS( renderer.GetProperty<int>(Renderer::Property::DEPTH_INDEX), 1, TEST_LOCATION );
267 renderer.SetProperty( Renderer::Property::DEPTH_INDEX, 10 );
269 application.SendNotification();
270 application.Render(0);
271 DALI_TEST_EQUALS( renderer.GetProperty<int>(Renderer::Property::DEPTH_INDEX), 10, TEST_LOCATION );
276 int UtcDaliRendererSetGetFaceCullingMode(void)
278 TestApplication application;
280 tet_infoline("Test SetFaceCullingMode(cullingMode)");
281 Geometry geometry = CreateQuadGeometry();
282 Shader shader = CreateShader();
283 Renderer renderer = Renderer::New( geometry, shader );
285 Actor actor = Actor::New();
286 actor.AddRenderer(renderer);
287 actor.SetSize(400, 400);
288 Stage::GetCurrent().Add(actor);
290 // By default, none of the faces should be culled
291 unsigned int cullFace = renderer.GetProperty<int>( Renderer::Property::FACE_CULLING_MODE );
292 DALI_TEST_CHECK( static_cast< FaceCullingMode::Type >( cullFace ) == FaceCullingMode::NONE );
294 TestGlAbstraction& gl = application.GetGlAbstraction();
295 TraceCallStack& cullFaceStack = gl.GetCullFaceTrace();
296 gl.EnableCullFaceCallTrace(true);
299 cullFaceStack.Reset();
300 renderer.SetProperty( Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::FRONT_AND_BACK );
301 application.SendNotification();
302 application.Render();
304 DALI_TEST_EQUALS( cullFaceStack.CountMethod( "CullFace" ), 1, TEST_LOCATION );
306 std::ostringstream cullModeString;
307 cullModeString << GL_FRONT_AND_BACK;
309 DALI_TEST_CHECK( cullFaceStack.FindMethodAndParams( "CullFace", cullModeString.str() ) );
310 cullFace = renderer.GetProperty<int>( Renderer::Property::FACE_CULLING_MODE );
311 DALI_TEST_CHECK( static_cast< FaceCullingMode::Type >( cullFace ) == FaceCullingMode::FRONT_AND_BACK );
315 cullFaceStack.Reset();
316 renderer.SetProperty( Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::BACK );
317 application.SendNotification();
318 application.Render();
320 DALI_TEST_EQUALS( cullFaceStack.CountMethod( "CullFace" ), 1, TEST_LOCATION );
322 std::ostringstream cullModeString;
323 cullModeString << GL_BACK;
325 DALI_TEST_CHECK( cullFaceStack.FindMethodAndParams( "CullFace", cullModeString.str() ) );
326 cullFace = renderer.GetProperty<int>( Renderer::Property::FACE_CULLING_MODE );
327 DALI_TEST_CHECK( static_cast< FaceCullingMode::Type >( cullFace ) == FaceCullingMode::BACK );
331 cullFaceStack.Reset();
332 renderer.SetProperty( Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::FRONT );
333 application.SendNotification();
334 application.Render();
336 DALI_TEST_EQUALS( cullFaceStack.CountMethod( "CullFace" ), 1, TEST_LOCATION );
338 std::ostringstream cullModeString;
339 cullModeString << GL_FRONT;
341 DALI_TEST_CHECK( cullFaceStack.FindMethodAndParams( "CullFace", cullModeString.str() ) );
342 cullFace = renderer.GetProperty<int>( Renderer::Property::FACE_CULLING_MODE );
343 DALI_TEST_CHECK( static_cast< FaceCullingMode::Type >( cullFace ) == FaceCullingMode::FRONT );
347 cullFaceStack.Reset();
348 renderer.SetProperty( Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::NONE );
349 application.SendNotification();
350 application.Render();
352 DALI_TEST_EQUALS( cullFaceStack.CountMethod( "CullFace" ), 0, TEST_LOCATION );
353 cullFace = renderer.GetProperty<int>( Renderer::Property::FACE_CULLING_MODE );
354 DALI_TEST_CHECK( static_cast< FaceCullingMode::Type >( cullFace ) == FaceCullingMode::NONE );
360 int UtcDaliRendererBlendOptions01(void)
362 TestApplication application;
364 tet_infoline("Test BLEND_FACTOR properties ");
366 Geometry geometry = CreateQuadGeometry();
367 Shader shader = CreateShader();
368 Renderer renderer = Renderer::New( geometry, shader );
370 Actor actor = Actor::New();
371 // set a transparent actor color so that blending is enabled
372 actor.SetOpacity( 0.5f );
373 actor.AddRenderer(renderer);
374 actor.SetSize(400, 400);
375 Stage::GetCurrent().Add(actor);
377 renderer.SetProperty( Renderer::Property::BLEND_FACTOR_SRC_RGB, BlendFactor::ONE_MINUS_SRC_COLOR );
378 renderer.SetProperty( Renderer::Property::BLEND_FACTOR_DEST_RGB, BlendFactor::SRC_ALPHA_SATURATE );
379 renderer.SetProperty( Renderer::Property::BLEND_FACTOR_SRC_ALPHA, BlendFactor::ONE_MINUS_SRC_COLOR );
380 renderer.SetProperty( Renderer::Property::BLEND_FACTOR_DEST_ALPHA, BlendFactor::SRC_ALPHA_SATURATE );
382 // Test that Set was successful:
383 int srcFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
384 int destFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
385 int srcFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
386 int destFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
388 DALI_TEST_EQUALS( (int)BlendFactor::ONE_MINUS_SRC_COLOR, srcFactorRgb, TEST_LOCATION );
389 DALI_TEST_EQUALS( (int)BlendFactor::SRC_ALPHA_SATURATE, destFactorRgb, TEST_LOCATION );
390 DALI_TEST_EQUALS( (int)BlendFactor::ONE_MINUS_SRC_COLOR, srcFactorAlpha, TEST_LOCATION );
391 DALI_TEST_EQUALS( (int)BlendFactor::SRC_ALPHA_SATURATE, destFactorAlpha, TEST_LOCATION );
393 application.SendNotification();
394 application.Render();
396 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
398 DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_SRC_COLOR, glAbstraction.GetLastBlendFuncSrcRgb(), TEST_LOCATION );
399 DALI_TEST_EQUALS( (GLenum)GL_SRC_ALPHA_SATURATE, glAbstraction.GetLastBlendFuncDstRgb(), TEST_LOCATION );
400 DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_SRC_COLOR, glAbstraction.GetLastBlendFuncSrcAlpha(), TEST_LOCATION );
401 DALI_TEST_EQUALS( (GLenum)GL_SRC_ALPHA_SATURATE, glAbstraction.GetLastBlendFuncDstAlpha(), TEST_LOCATION );
406 int UtcDaliRendererBlendOptions02(void)
408 TestApplication application;
410 tet_infoline("Test BLEND_FACTOR properties ");
412 Geometry geometry = CreateQuadGeometry();
413 Shader shader = CreateShader();
414 Renderer renderer = Renderer::New( geometry, shader );
416 Actor actor = Actor::New();
417 actor.SetOpacity( 0.5f ); // enable blending
418 actor.AddRenderer(renderer);
419 actor.SetSize(400, 400);
420 Stage::GetCurrent().Add(actor);
422 renderer.SetProperty( Renderer::Property::BLEND_FACTOR_SRC_RGB, BlendFactor::CONSTANT_COLOR );
423 renderer.SetProperty( Renderer::Property::BLEND_FACTOR_DEST_RGB, BlendFactor::ONE_MINUS_CONSTANT_COLOR );
424 renderer.SetProperty( Renderer::Property::BLEND_FACTOR_SRC_ALPHA, BlendFactor::CONSTANT_ALPHA );
425 renderer.SetProperty( Renderer::Property::BLEND_FACTOR_DEST_ALPHA, BlendFactor::ONE_MINUS_CONSTANT_ALPHA );
427 // Test that Set was successful:
429 int srcFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
430 int destFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
431 int srcFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
432 int destFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
434 DALI_TEST_EQUALS( (int)BlendFactor::CONSTANT_COLOR, srcFactorRgb, TEST_LOCATION );
435 DALI_TEST_EQUALS( (int)BlendFactor::ONE_MINUS_CONSTANT_COLOR, destFactorRgb, TEST_LOCATION );
436 DALI_TEST_EQUALS( (int)BlendFactor::CONSTANT_ALPHA, srcFactorAlpha, TEST_LOCATION );
437 DALI_TEST_EQUALS( (int)BlendFactor::ONE_MINUS_CONSTANT_ALPHA, destFactorAlpha, TEST_LOCATION );
440 application.SendNotification();
441 application.Render();
443 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
444 DALI_TEST_EQUALS( (GLenum)GL_CONSTANT_COLOR, glAbstraction.GetLastBlendFuncSrcRgb(), TEST_LOCATION );
445 DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_CONSTANT_COLOR, glAbstraction.GetLastBlendFuncDstRgb(), TEST_LOCATION );
446 DALI_TEST_EQUALS( (GLenum)GL_CONSTANT_ALPHA, glAbstraction.GetLastBlendFuncSrcAlpha(), TEST_LOCATION );
447 DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_CONSTANT_ALPHA, glAbstraction.GetLastBlendFuncDstAlpha(), TEST_LOCATION );
452 int UtcDaliRendererBlendOptions03(void)
454 TestApplication application;
456 tet_infoline("Test GetBlendEquation() defaults ");
458 Geometry geometry = CreateQuadGeometry();
459 Shader shader = CreateShader();
460 Renderer renderer = Renderer::New( geometry, shader );
462 Actor actor = Actor::New();
463 actor.AddRenderer(renderer);
464 actor.SetSize(400, 400);
465 Stage::GetCurrent().Add(actor);
467 // Test the defaults as documented in blending.h
468 int equationRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_EQUATION_RGB );
469 int equationAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_EQUATION_ALPHA );
471 DALI_TEST_EQUALS( (int)BlendEquation::ADD, equationRgb, TEST_LOCATION );
472 DALI_TEST_EQUALS( (int)BlendEquation::ADD, equationAlpha, TEST_LOCATION );
477 int UtcDaliRendererBlendOptions04(void)
479 TestApplication application;
481 tet_infoline("Test SetBlendEquation() ");
483 Geometry geometry = CreateQuadGeometry();
484 Shader shader = CreateShader();
485 Renderer renderer = Renderer::New( geometry, shader );
487 Actor actor = Actor::New();
488 actor.SetOpacity( 0.1f );
489 actor.AddRenderer(renderer);
490 actor.SetSize(400, 400);
491 Stage::GetCurrent().Add(actor);
493 // Test the single blending equation setting
495 renderer.SetProperty( Renderer::Property::BLEND_EQUATION_RGB, BlendEquation::REVERSE_SUBTRACT );
496 int equationRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_EQUATION_RGB );
497 DALI_TEST_EQUALS( (int)BlendEquation::REVERSE_SUBTRACT, equationRgb, TEST_LOCATION );
500 renderer.SetProperty( Renderer::Property::BLEND_EQUATION_RGB, BlendEquation::REVERSE_SUBTRACT );
501 renderer.SetProperty( Renderer::Property::BLEND_EQUATION_ALPHA, BlendEquation::REVERSE_SUBTRACT );
503 // Test that Set was successful
505 int equationRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_EQUATION_RGB );
506 int equationAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_EQUATION_ALPHA );
507 DALI_TEST_EQUALS( (int)BlendEquation::REVERSE_SUBTRACT, equationRgb, TEST_LOCATION );
508 DALI_TEST_EQUALS( (int)BlendEquation::REVERSE_SUBTRACT, equationAlpha, TEST_LOCATION );
511 // Render & check GL commands
512 application.SendNotification();
513 application.Render();
515 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
516 DALI_TEST_EQUALS( (GLenum)GL_FUNC_REVERSE_SUBTRACT, glAbstraction.GetLastBlendEquationRgb(), TEST_LOCATION );
517 DALI_TEST_EQUALS( (GLenum)GL_FUNC_REVERSE_SUBTRACT, glAbstraction.GetLastBlendEquationAlpha(), TEST_LOCATION );
522 int UtcDaliRendererSetBlendMode01(void)
524 TestApplication application;
526 tet_infoline("Test setting the blend mode to on with an opaque color renders with blending enabled");
528 Geometry geometry = CreateQuadGeometry();
529 Shader shader = CreateShader();
530 Renderer renderer = Renderer::New( geometry, shader );
532 Actor actor = Actor::New();
533 actor.SetOpacity( 0.98f );
534 actor.AddRenderer(renderer);
535 actor.SetSize(400, 400);
536 Stage::GetCurrent().Add(actor);
538 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::ON);
540 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
541 glAbstraction.EnableEnableDisableCallTrace(true);
543 application.SendNotification();
544 application.Render();
546 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
547 std::ostringstream blendStr;
548 blendStr << GL_BLEND;
549 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
554 int UtcDaliRendererSetBlendMode02(void)
556 TestApplication application;
558 tet_infoline("Test setting the blend mode to off with a transparent color renders with blending disabled (and not enabled)");
560 Geometry geometry = CreateQuadGeometry();
561 Shader shader = CreateShader();
562 Renderer renderer = Renderer::New( geometry, shader );
564 Actor actor = Actor::New();
565 actor.SetOpacity( 0.15f );
566 actor.AddRenderer(renderer);
567 actor.SetSize(400, 400);
568 Stage::GetCurrent().Add(actor);
570 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::OFF);
572 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
573 glAbstraction.EnableEnableDisableCallTrace(true);
575 application.SendNotification();
576 application.Render();
578 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
579 std::ostringstream blendStr;
580 blendStr << GL_BLEND;
581 DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
586 int UtcDaliRendererSetBlendMode03(void)
588 TestApplication application;
590 tet_infoline("Test setting the blend mode to auto with a transparent color renders with blending enabled");
592 Geometry geometry = CreateQuadGeometry();
593 Shader shader = CreateShader();
594 Renderer renderer = Renderer::New( geometry, shader );
596 Actor actor = Actor::New();
597 actor.SetOpacity( 0.75f );
598 actor.AddRenderer(renderer);
599 actor.SetSize(400, 400);
600 Stage::GetCurrent().Add(actor);
602 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::AUTO);
604 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
605 glAbstraction.EnableEnableDisableCallTrace(true);
607 application.SendNotification();
608 application.Render();
610 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
611 std::ostringstream blendStr;
612 blendStr << GL_BLEND;
613 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
618 int UtcDaliRendererSetBlendMode04(void)
620 TestApplication application;
622 tet_infoline("Test setting the blend mode to auto with an opaque color renders with blending disabled");
624 Geometry geometry = CreateQuadGeometry();
625 Shader shader = CreateShader();
626 Renderer renderer = Renderer::New( geometry, shader );
628 Actor actor = Actor::New();
629 actor.AddRenderer(renderer);
630 actor.SetSize(400, 400);
631 Stage::GetCurrent().Add(actor);
633 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::AUTO);
635 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
636 glAbstraction.EnableEnableDisableCallTrace(true);
638 application.SendNotification();
639 application.Render();
641 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
642 std::ostringstream blendStr;
643 blendStr << GL_BLEND;
644 DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
649 int UtcDaliRendererSetBlendMode04b(void)
651 TestApplication application;
653 tet_infoline("Test setting the blend mode to auto with a transparent actor color renders with blending enabled");
655 Geometry geometry = CreateQuadGeometry();
656 Shader shader = CreateShader();
657 Renderer renderer = Renderer::New( geometry, shader );
659 Actor actor = Actor::New();
660 actor.AddRenderer(renderer);
661 actor.SetSize(400, 400);
662 actor.SetColor( Vector4(1.0f, 0.0f, 1.0f, 0.5f) );
663 Stage::GetCurrent().Add(actor);
665 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::AUTO);
667 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
668 glAbstraction.EnableEnableDisableCallTrace(true);
670 application.SendNotification();
671 application.Render();
673 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
674 std::ostringstream blendStr;
675 blendStr << GL_BLEND;
676 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
681 int UtcDaliRendererSetBlendMode04c(void)
683 TestApplication application;
685 tet_infoline("Test setting the blend mode to auto with an opaque opaque actor color renders with blending disabled");
687 Geometry geometry = CreateQuadGeometry();
688 Shader shader = CreateShader();
689 Renderer renderer = Renderer::New( geometry, shader );
691 Actor actor = Actor::New();
692 actor.AddRenderer(renderer);
693 actor.SetSize(400, 400);
694 actor.SetColor( Color::MAGENTA );
695 Stage::GetCurrent().Add(actor);
697 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::AUTO);
699 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
700 glAbstraction.EnableEnableDisableCallTrace(true);
702 application.SendNotification();
703 application.Render();
705 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
706 std::ostringstream blendStr;
707 blendStr << GL_BLEND;
708 DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
713 int UtcDaliRendererSetBlendMode05(void)
715 TestApplication application;
717 tet_infoline("Test setting the blend mode to auto with an opaque color and an image with an alpha channel renders with blending enabled");
719 Geometry geometry = CreateQuadGeometry();
720 BufferImage image = BufferImage::New( 40, 40, Pixel::RGBA8888 );
722 Shader shader = CreateShader();
723 TextureSet textureSet = CreateTextureSet( image );
724 Renderer renderer = Renderer::New( geometry, shader );
725 renderer.SetTextures( textureSet );
727 Actor actor = Actor::New();
728 actor.AddRenderer(renderer);
729 actor.SetSize(400, 400);
730 Stage::GetCurrent().Add(actor);
732 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::AUTO);
734 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
735 glAbstraction.EnableEnableDisableCallTrace(true);
737 application.SendNotification();
738 application.Render();
740 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
741 std::ostringstream blendStr;
742 blendStr << GL_BLEND;
743 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
748 int UtcDaliRendererSetBlendMode06(void)
750 TestApplication application;
751 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");
753 Geometry geometry = CreateQuadGeometry();
754 Shader shader = Shader::New( "vertexSrc", "fragmentSrc", Shader::Hint::OUTPUT_IS_TRANSPARENT );
756 Renderer renderer = Renderer::New( geometry, shader );
758 Actor actor = Actor::New();
759 actor.AddRenderer(renderer);
760 actor.SetSize(400, 400);
761 Stage::GetCurrent().Add(actor);
763 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::AUTO);
765 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
766 glAbstraction.EnableEnableDisableCallTrace(true);
768 application.SendNotification();
769 application.Render();
771 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
772 std::ostringstream blendStr;
773 blendStr << GL_BLEND;
774 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
779 int UtcDaliRendererSetBlendMode07(void)
781 TestApplication application;
782 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");
784 Geometry geometry = CreateQuadGeometry();
785 Shader shader = Shader::New( "vertexSrc", "fragmentSrc" );
787 BufferImage image = BufferImage::New( 50, 50, Pixel::RGB888 );
788 TextureSet textureSet = CreateTextureSet( image );
789 Renderer renderer = Renderer::New( geometry, shader );
790 renderer.SetTextures( textureSet );
792 Actor actor = Actor::New();
793 actor.AddRenderer(renderer);
794 actor.SetSize(400, 400);
795 Stage::GetCurrent().Add(actor);
797 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::AUTO);
799 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
800 glAbstraction.EnableEnableDisableCallTrace(true);
802 application.SendNotification();
803 application.Render();
805 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
806 DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", "GL_BLEND" ) );
811 int UtcDaliRendererGetBlendMode(void)
813 TestApplication application;
815 tet_infoline("Test GetBlendMode()");
817 Geometry geometry = CreateQuadGeometry();
818 Shader shader = Shader::New( "vertexSrc", "fragmentSrc" );
819 Renderer renderer = Renderer::New( geometry, shader );
822 unsigned int mode = renderer.GetProperty<int>( Renderer::Property::BLEND_MODE );
823 DALI_TEST_EQUALS( static_cast< BlendMode::Type >( mode ), BlendMode::AUTO, TEST_LOCATION );
826 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::ON );
827 mode = renderer.GetProperty<int>( Renderer::Property::BLEND_MODE );
828 DALI_TEST_EQUALS( static_cast< BlendMode::Type >( mode ), BlendMode::ON, TEST_LOCATION );
831 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::OFF );
832 mode = renderer.GetProperty<int>( Renderer::Property::BLEND_MODE );
833 DALI_TEST_EQUALS( static_cast< BlendMode::Type >( mode ), BlendMode::OFF, TEST_LOCATION );
838 int UtcDaliRendererSetBlendColor(void)
840 TestApplication application;
842 tet_infoline("Test SetBlendColor(color)");
844 Geometry geometry = CreateQuadGeometry();
845 Shader shader = Shader::New( "vertexSrc", "fragmentSrc" );
846 TextureSet textureSet = TextureSet::New();
847 BufferImage image = BufferImage::New( 50, 50, Pixel::RGBA8888 );
848 TextureSetImage( textureSet, 0u, image );
849 Renderer renderer = Renderer::New( geometry, shader );
850 renderer.SetTextures( textureSet );
852 Actor actor = Actor::New();
853 actor.AddRenderer(renderer);
854 actor.SetSize(400, 400);
855 Stage::GetCurrent().Add(actor);
857 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
859 renderer.SetProperty( Renderer::Property::BLEND_COLOR, Color::TRANSPARENT );
860 application.SendNotification();
861 application.Render();
862 DALI_TEST_EQUALS( glAbstraction.GetLastBlendColor(), Color::TRANSPARENT, TEST_LOCATION );
864 renderer.SetProperty( Renderer::Property::BLEND_COLOR, Color::MAGENTA );
865 application.SendNotification();
866 application.Render();
867 DALI_TEST_EQUALS( glAbstraction.GetLastBlendColor(), Color::MAGENTA, TEST_LOCATION );
869 Vector4 color( 0.1f, 0.2f, 0.3f, 0.4f );
870 renderer.SetProperty( Renderer::Property::BLEND_COLOR, color );
871 application.SendNotification();
872 application.Render();
873 DALI_TEST_EQUALS( glAbstraction.GetLastBlendColor(), color, TEST_LOCATION );
878 int UtcDaliRendererGetBlendColor(void)
880 TestApplication application;
882 tet_infoline("Test GetBlendColor()");
884 Geometry geometry = CreateQuadGeometry();
885 Shader shader = Shader::New( "vertexSrc", "fragmentSrc" );
886 Renderer renderer = Renderer::New( geometry, shader );
888 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>( Renderer::Property::BLEND_COLOR ), Color::TRANSPARENT, TEST_LOCATION );
890 renderer.SetProperty( Renderer::Property::BLEND_COLOR, Color::MAGENTA );
891 application.SendNotification();
892 application.Render();
893 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>( Renderer::Property::BLEND_COLOR ), Color::MAGENTA, TEST_LOCATION );
895 Vector4 color( 0.1f, 0.2f, 0.3f, 0.4f );
896 renderer.SetProperty( Renderer::Property::BLEND_COLOR, color );
897 application.SendNotification();
898 application.Render();
899 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>( Renderer::Property::BLEND_COLOR ), color, TEST_LOCATION );
904 int UtcDaliRendererPreMultipledAlpha(void)
906 TestApplication application;
908 tet_infoline("Test BLEND_PRE_MULTIPLIED_ALPHA property");
910 Geometry geometry = CreateQuadGeometry();
911 Shader shader = Shader::New( "vertexSrc", "fragmentSrc" );
912 Renderer renderer = Renderer::New( geometry, shader );
914 Actor actor = Actor::New();
915 actor.AddRenderer(renderer);
916 actor.SetSize(400, 400);
917 actor.SetColor( Vector4(1.0f, 0.0f, 1.0f, 0.5f) );
918 Stage::GetCurrent().Add(actor);
920 Property::Value value = renderer.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
921 bool preMultipliedAlpha;
922 DALI_TEST_CHECK( value.Get( preMultipliedAlpha ) );
923 DALI_TEST_CHECK( !preMultipliedAlpha );
925 int srcFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
926 int destFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
927 int srcFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
928 int destFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
930 DALI_TEST_EQUALS( (int)DEFAULT_BLEND_FACTOR_SRC_RGB, srcFactorRgb, TEST_LOCATION );
931 DALI_TEST_EQUALS( (int)DEFAULT_BLEND_FACTOR_DEST_RGB, destFactorRgb, TEST_LOCATION );
932 DALI_TEST_EQUALS( (int)DEFAULT_BLEND_FACTOR_SRC_ALPHA, srcFactorAlpha, TEST_LOCATION );
933 DALI_TEST_EQUALS( (int)DEFAULT_BLEND_FACTOR_DEST_ALPHA, destFactorAlpha, TEST_LOCATION );
935 application.SendNotification();
936 application.Render();
938 Vector4 actualValue(Vector4::ZERO);
939 TestGlAbstraction& gl = application.GetGlAbstraction();
940 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uColor", actualValue ) );
941 DALI_TEST_EQUALS( actualValue, Vector4(1.0f, 0.0f, 1.0f, 0.5f), TEST_LOCATION );
943 renderer.SetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, true);
945 application.SendNotification();
946 application.Render();
948 value = renderer.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
949 DALI_TEST_CHECK( value.Get( preMultipliedAlpha ) );
950 DALI_TEST_CHECK( preMultipliedAlpha );
952 srcFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
953 destFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
954 srcFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
955 destFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
957 DALI_TEST_EQUALS( (int)BlendFactor::ONE, srcFactorRgb, TEST_LOCATION );
958 DALI_TEST_EQUALS( (int)BlendFactor::ONE_MINUS_SRC_ALPHA, destFactorRgb, TEST_LOCATION );
959 DALI_TEST_EQUALS( (int)BlendFactor::ONE, srcFactorAlpha, TEST_LOCATION );
960 DALI_TEST_EQUALS( (int)BlendFactor::ONE, destFactorAlpha, TEST_LOCATION );
962 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uColor", actualValue ) );
963 DALI_TEST_EQUALS( actualValue, Vector4(0.5f, 0.0f, 0.5f, 0.5f), TEST_LOCATION );
968 int UtcDaliRendererConstraint01(void)
970 TestApplication application;
972 tet_infoline("Test that a non-uniform renderer property can be constrained");
974 Shader shader = Shader::New("VertexSource", "FragmentSource");
975 Geometry geometry = CreateQuadGeometry();
976 Renderer renderer = Renderer::New( geometry, shader );
978 Actor actor = Actor::New();
979 actor.AddRenderer(renderer);
980 actor.SetSize(400, 400);
981 Stage::GetCurrent().Add(actor);
983 Vector4 initialColor = Color::WHITE;
984 Property::Index colorIndex = renderer.RegisterProperty( "uFadeColor", initialColor );
986 application.SendNotification();
987 application.Render(0);
988 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION );
991 Constraint constraint = Constraint::New<Vector4>( renderer, colorIndex, TestConstraintNoBlue );
993 application.SendNotification();
994 application.Render(0);
996 // Expect no blue component in either buffer - yellow
997 DALI_TEST_EQUALS( DevelHandle::GetCurrentProperty< Vector4 >( renderer, colorIndex ), Color::YELLOW, TEST_LOCATION );
998 application.Render(0);
999 DALI_TEST_EQUALS( DevelHandle::GetCurrentProperty< Vector4 >( renderer, colorIndex ), Color::YELLOW, TEST_LOCATION );
1001 renderer.RemoveConstraints();
1002 renderer.SetProperty(colorIndex, Color::WHITE );
1003 application.SendNotification();
1004 application.Render(0);
1005 DALI_TEST_EQUALS( DevelHandle::GetCurrentProperty< Vector4 >( renderer, colorIndex ), Color::WHITE, TEST_LOCATION );
1010 int UtcDaliRendererConstraint02(void)
1012 TestApplication application;
1014 tet_infoline("Test that a uniform map renderer property can be constrained");
1016 Shader shader = Shader::New("VertexSource", "FragmentSource");
1017 Geometry geometry = CreateQuadGeometry();
1018 Renderer renderer = Renderer::New( geometry, shader );
1020 Actor actor = Actor::New();
1021 actor.AddRenderer(renderer);
1022 actor.SetSize(400, 400);
1023 Stage::GetCurrent().Add(actor);
1024 application.SendNotification();
1025 application.Render(0);
1027 Vector4 initialColor = Color::WHITE;
1028 Property::Index colorIndex = renderer.RegisterProperty( "uFadeColor", initialColor );
1030 TestGlAbstraction& gl = application.GetGlAbstraction();
1032 application.SendNotification();
1033 application.Render(0);
1035 Vector4 actualValue(Vector4::ZERO);
1036 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1037 DALI_TEST_EQUALS( actualValue, initialColor, TEST_LOCATION );
1040 Constraint constraint = Constraint::New<Vector4>( renderer, colorIndex, TestConstraintNoBlue );
1042 application.SendNotification();
1043 application.Render(0);
1045 // Expect no blue component in either buffer - yellow
1046 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1047 DALI_TEST_EQUALS( actualValue, Color::YELLOW, TEST_LOCATION );
1049 application.Render(0);
1050 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1051 DALI_TEST_EQUALS( actualValue, Color::YELLOW, TEST_LOCATION );
1053 renderer.RemoveConstraints();
1054 renderer.SetProperty(colorIndex, Color::WHITE );
1055 application.SendNotification();
1056 application.Render(0);
1058 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1059 DALI_TEST_EQUALS( actualValue, Color::WHITE, TEST_LOCATION );
1064 int UtcDaliRendererAnimatedProperty01(void)
1066 TestApplication application;
1068 tet_infoline("Test that a non-uniform renderer property can be animated");
1070 Shader shader = Shader::New("VertexSource", "FragmentSource");
1071 Geometry geometry = CreateQuadGeometry();
1072 Renderer renderer = Renderer::New( geometry, shader );
1074 Actor actor = Actor::New();
1075 actor.AddRenderer(renderer);
1076 actor.SetSize(400, 400);
1077 Stage::GetCurrent().Add(actor);
1079 Vector4 initialColor = Color::WHITE;
1080 Property::Index colorIndex = renderer.RegisterProperty( "uFadeColor", initialColor );
1082 application.SendNotification();
1083 application.Render(0);
1084 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION );
1086 Animation animation = Animation::New(1.0f);
1087 KeyFrames keyFrames = KeyFrames::New();
1088 keyFrames.Add(0.0f, initialColor);
1089 keyFrames.Add(1.0f, Color::TRANSPARENT);
1090 animation.AnimateBetween( Property( renderer, colorIndex ), keyFrames );
1093 application.SendNotification();
1094 application.Render(500);
1096 DALI_TEST_EQUALS( DevelHandle::GetCurrentProperty< Vector4 >( renderer, colorIndex ), Color::WHITE * 0.5f, TEST_LOCATION );
1098 application.Render(500);
1100 DALI_TEST_EQUALS( DevelHandle::GetCurrentProperty< Vector4 >( renderer, colorIndex ), Color::TRANSPARENT, TEST_LOCATION );
1105 int UtcDaliRendererAnimatedProperty02(void)
1107 TestApplication application;
1109 tet_infoline("Test that a uniform map renderer property can be animated");
1111 Shader shader = Shader::New("VertexSource", "FragmentSource");
1112 Geometry geometry = CreateQuadGeometry();
1113 Renderer renderer = Renderer::New( geometry, shader );
1115 Actor actor = Actor::New();
1116 actor.AddRenderer(renderer);
1117 actor.SetSize(400, 400);
1118 Stage::GetCurrent().Add(actor);
1119 application.SendNotification();
1120 application.Render(0);
1122 Vector4 initialColor = Color::WHITE;
1123 Property::Index colorIndex = renderer.RegisterProperty( "uFadeColor", initialColor );
1125 TestGlAbstraction& gl = application.GetGlAbstraction();
1127 application.SendNotification();
1128 application.Render(0);
1130 Vector4 actualValue(Vector4::ZERO);
1131 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1132 DALI_TEST_EQUALS( actualValue, initialColor, TEST_LOCATION );
1134 Animation animation = Animation::New(1.0f);
1135 KeyFrames keyFrames = KeyFrames::New();
1136 keyFrames.Add(0.0f, initialColor);
1137 keyFrames.Add(1.0f, Color::TRANSPARENT);
1138 animation.AnimateBetween( Property( renderer, colorIndex ), keyFrames );
1141 application.SendNotification();
1142 application.Render(500);
1144 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1145 DALI_TEST_EQUALS( actualValue, Color::WHITE * 0.5f, TEST_LOCATION );
1147 application.Render(500);
1148 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1149 DALI_TEST_EQUALS( actualValue, Color::TRANSPARENT, TEST_LOCATION );
1154 int UtcDaliRendererUniformMapPrecendence01(void)
1156 TestApplication application;
1158 tet_infoline("Test the uniform map precedence is applied properly");
1160 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1162 Shader shader = Shader::New("VertexSource", "FragmentSource");
1163 TextureSet textureSet = CreateTextureSet( image );
1165 Geometry geometry = CreateQuadGeometry();
1166 Renderer renderer = Renderer::New( geometry, shader );
1167 renderer.SetTextures( textureSet );
1169 Actor actor = Actor::New();
1170 actor.AddRenderer(renderer);
1171 actor.SetSize(400, 400);
1172 Stage::GetCurrent().Add(actor);
1173 application.SendNotification();
1174 application.Render(0);
1176 renderer.RegisterProperty( "uFadeColor", Color::RED );
1177 actor.RegisterProperty( "uFadeColor", Color::GREEN );
1178 Property::Index shaderFadeColorIndex = shader.RegisterProperty( "uFadeColor", Color::MAGENTA );
1180 TestGlAbstraction& gl = application.GetGlAbstraction();
1182 application.SendNotification();
1183 application.Render(0);
1185 // Expect that the actor's fade color property is accessed
1186 Vector4 actualValue(Vector4::ZERO);
1187 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1188 DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
1190 // Animate shader's fade color property. Should be no change to uniform
1191 Animation animation = Animation::New(1.0f);
1192 KeyFrames keyFrames = KeyFrames::New();
1193 keyFrames.Add(0.0f, Color::WHITE);
1194 keyFrames.Add(1.0f, Color::TRANSPARENT);
1195 animation.AnimateBetween( Property( shader, shaderFadeColorIndex ), keyFrames );
1198 application.SendNotification();
1199 application.Render(500);
1201 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1202 DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
1204 application.Render(500);
1205 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1206 DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
1211 int UtcDaliRendererUniformMapPrecendence02(void)
1213 TestApplication application;
1215 tet_infoline("Test the uniform map precedence is applied properly");
1217 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1219 Shader shader = Shader::New("VertexSource", "FragmentSource");
1220 TextureSet textureSet = CreateTextureSet( image );
1222 Geometry geometry = CreateQuadGeometry();
1223 Renderer renderer = Renderer::New( geometry, shader );
1224 renderer.SetTextures( textureSet );
1226 Actor actor = Actor::New();
1227 actor.AddRenderer(renderer);
1228 actor.SetSize(400, 400);
1229 Stage::GetCurrent().Add(actor);
1230 application.SendNotification();
1231 application.Render(0);
1233 // Don't add property / uniform map to renderer
1234 actor.RegisterProperty( "uFadeColor", Color::GREEN );
1235 Property::Index shaderFadeColorIndex = shader.RegisterProperty( "uFadeColor", Color::BLUE );
1237 TestGlAbstraction& gl = application.GetGlAbstraction();
1239 application.SendNotification();
1240 application.Render(0);
1242 // Expect that the actor's fade color property is accessed
1243 Vector4 actualValue(Vector4::ZERO);
1244 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1245 DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
1247 // Animate texture set's fade color property. Should be no change to uniform
1248 Animation animation = Animation::New(1.0f);
1249 KeyFrames keyFrames = KeyFrames::New();
1250 keyFrames.Add(0.0f, Color::WHITE);
1251 keyFrames.Add(1.0f, Color::TRANSPARENT);
1252 animation.AnimateBetween( Property( shader, shaderFadeColorIndex ), keyFrames );
1255 application.SendNotification();
1256 application.Render(500);
1258 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1259 DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
1261 application.Render(500);
1262 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1263 DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
1269 int UtcDaliRendererUniformMapPrecendence03(void)
1271 TestApplication application;
1273 tet_infoline("Test the uniform map precedence is applied properly");
1275 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1277 Shader shader = Shader::New("VertexSource", "FragmentSource");
1278 TextureSet textureSet = CreateTextureSet( image );
1280 Geometry geometry = CreateQuadGeometry();
1281 Renderer renderer = Renderer::New( geometry, shader );
1282 renderer.SetTextures( textureSet );
1284 Actor actor = Actor::New();
1285 actor.AddRenderer(renderer);
1286 actor.SetSize(400, 400);
1287 Stage::GetCurrent().Add(actor);
1288 application.SendNotification();
1289 application.Render(0);
1291 // Don't add property / uniform map to renderer or actor
1292 shader.RegisterProperty( "uFadeColor", Color::BLACK );
1294 TestGlAbstraction& gl = application.GetGlAbstraction();
1296 application.SendNotification();
1297 application.Render(0);
1299 // Expect that the shader's fade color property is accessed
1300 Vector4 actualValue(Vector4::ZERO);
1301 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1302 DALI_TEST_EQUALS( actualValue, Color::BLACK, TEST_LOCATION );
1307 int UtcDaliRendererUniformMapMultipleUniforms01(void)
1309 TestApplication application;
1311 tet_infoline("Test the uniform maps are collected from all objects (same type)");
1313 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1315 Shader shader = Shader::New("VertexSource", "FragmentSource");
1316 TextureSet textureSet = CreateTextureSet( image );
1318 Geometry geometry = CreateQuadGeometry();
1319 Renderer renderer = Renderer::New( geometry, shader );
1320 renderer.SetTextures( textureSet );
1322 Actor actor = Actor::New();
1323 actor.AddRenderer(renderer);
1324 actor.SetSize(400, 400);
1325 Stage::GetCurrent().Add(actor);
1326 application.SendNotification();
1327 application.Render(0);
1329 renderer.RegisterProperty( "uUniform1", Color::RED );
1330 actor.RegisterProperty( "uUniform2", Color::GREEN );
1331 shader.RegisterProperty( "uUniform3", Color::MAGENTA );
1333 TestGlAbstraction& gl = application.GetGlAbstraction();
1335 application.SendNotification();
1336 application.Render(0);
1338 // Expect that each of the object's uniforms are set
1339 Vector4 uniform1Value(Vector4::ZERO);
1340 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uUniform1", uniform1Value ) );
1341 DALI_TEST_EQUALS( uniform1Value, Color::RED, TEST_LOCATION );
1343 Vector4 uniform2Value(Vector4::ZERO);
1344 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uUniform2", uniform2Value ) );
1345 DALI_TEST_EQUALS( uniform2Value, Color::GREEN, TEST_LOCATION );
1347 Vector4 uniform3Value(Vector4::ZERO);
1348 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uUniform3", uniform3Value ) );
1349 DALI_TEST_EQUALS( uniform3Value, Color::MAGENTA, TEST_LOCATION );
1354 int UtcDaliRendererUniformMapMultipleUniforms02(void)
1356 TestApplication application;
1358 tet_infoline("Test the uniform maps are collected from all objects (different types)");
1360 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1362 Shader shader = Shader::New("VertexSource", "FragmentSource");
1363 TextureSet textureSet = CreateTextureSet( image );
1365 Geometry geometry = CreateQuadGeometry();
1366 Renderer renderer = Renderer::New( geometry, shader );
1367 renderer.SetTextures( textureSet );
1369 Actor actor = Actor::New();
1370 actor.AddRenderer(renderer);
1371 actor.SetSize(400, 400);
1372 Stage::GetCurrent().Add(actor);
1373 application.SendNotification();
1374 application.Render(0);
1376 Property::Value value1(Color::RED);
1377 renderer.RegisterProperty( "uFadeColor", value1 );
1379 Property::Value value2(1.0f);
1380 actor.RegisterProperty( "uFadeProgress", value2 );
1382 Property::Value value3(Matrix3::IDENTITY);
1383 shader.RegisterProperty( "uANormalMatrix", value3 );
1385 TestGlAbstraction& gl = application.GetGlAbstraction();
1387 application.SendNotification();
1388 application.Render(0);
1390 // Expect that each of the object's uniforms are set
1391 Vector4 uniform1Value(Vector4::ZERO);
1392 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", uniform1Value ) );
1393 DALI_TEST_EQUALS( uniform1Value, value1.Get<Vector4>(), TEST_LOCATION );
1395 float uniform2Value(0.0f);
1396 DALI_TEST_CHECK( gl.GetUniformValue<float>( "uFadeProgress", uniform2Value ) );
1397 DALI_TEST_EQUALS( uniform2Value, value2.Get<float>(), TEST_LOCATION );
1399 Matrix3 uniform3Value;
1400 DALI_TEST_CHECK( gl.GetUniformValue<Matrix3>( "uANormalMatrix", uniform3Value ) );
1401 DALI_TEST_EQUALS( uniform3Value, value3.Get<Matrix3>(), TEST_LOCATION );
1407 Renderer CreateRenderer( Actor actor, Geometry geometry, Shader shader, int depthIndex )
1409 Image image0 = BufferImage::New( 64, 64, Pixel::RGB888 );
1410 TextureSet textureSet0 = CreateTextureSet( image0 );
1411 Renderer renderer0 = Renderer::New( geometry, shader );
1412 renderer0.SetTextures( textureSet0 );
1413 renderer0.SetProperty( Renderer::Property::DEPTH_INDEX, depthIndex );
1414 actor.AddRenderer(renderer0);
1419 Actor CreateActor( Actor parent, int siblingOrder, const char* location )
1421 Actor actor0 = Actor::New();
1422 actor0.SetAnchorPoint(AnchorPoint::CENTER);
1423 actor0.SetParentOrigin(AnchorPoint::CENTER);
1424 actor0.SetPosition(0.0f,0.0f);
1425 actor0.SetSize(100, 100);
1426 actor0.SetProperty( Dali::DevelActor::Property::SIBLING_ORDER, siblingOrder );
1427 DALI_TEST_EQUALS( actor0.GetProperty<int>( Dali::DevelActor::Property::SIBLING_ORDER), siblingOrder, TEST_INNER_LOCATION(location) );
1433 int UtcDaliRendererRenderOrder2DLayer(void)
1435 TestApplication application;
1436 tet_infoline("Test the rendering order in a 2D layer is correct");
1438 Shader shader = Shader::New("VertexSource", "FragmentSource");
1439 Geometry geometry = CreateQuadGeometry();
1441 Actor root = Stage::GetCurrent().GetRootLayer();
1443 Actor actor0 = CreateActor( root, 0, TEST_LOCATION );
1444 Renderer renderer0 = CreateRenderer( actor0, geometry, shader, 0 );
1446 Actor actor1 = CreateActor( root, 0, TEST_LOCATION );
1447 Renderer renderer1 = CreateRenderer( actor1, geometry, shader, 0 );
1449 Actor actor2 = CreateActor( root, 0, TEST_LOCATION );
1450 Renderer renderer2 = CreateRenderer( actor2, geometry, shader, 0 );
1452 Actor actor3 = CreateActor( root, 0, TEST_LOCATION );
1453 Renderer renderer3 = CreateRenderer( actor3, geometry, shader, 0 );
1455 application.SendNotification();
1456 application.Render(0);
1459 * Create the following hierarchy:
1472 * Expected rendering order : actor2 - actor1 - actor0 - actor3
1477 application.SendNotification();
1478 application.Render(0);
1480 TestGlAbstraction& gl = application.GetGlAbstraction();
1481 gl.EnableTextureCallTrace(true);
1482 application.SendNotification();
1483 application.Render(0);
1485 int textureBindIndex[4];
1486 for( unsigned int i(0); i<4; ++i )
1488 std::stringstream params;
1489 params << GL_TEXTURE_2D<<", "<<i+1;
1490 textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str() );
1493 //Check that actor1 has been rendered after actor2
1494 DALI_TEST_GREATER( textureBindIndex[1], textureBindIndex[2], TEST_LOCATION );
1496 //Check that actor0 has been rendered after actor1
1497 DALI_TEST_GREATER( textureBindIndex[0], textureBindIndex[1], TEST_LOCATION );
1499 //Check that actor3 has been rendered after actor0
1500 DALI_TEST_GREATER( textureBindIndex[3], textureBindIndex[0], TEST_LOCATION );
1505 int UtcDaliRendererRenderOrder2DLayerMultipleRenderers(void)
1507 TestApplication application;
1508 tet_infoline("Test the rendering order in a 2D layer is correct using multiple renderers per actor");
1511 * Creates the following hierarchy:
1513 * actor0------------------------>actor1
1517 * renderer0 renderer1 renderer2 renderer3 renderer4 renderer5
1519 * renderer0 has depth index 2
1520 * renderer1 has depth index 0
1521 * renderer2 has depth index 1
1523 * renderer3 has depth index 1
1524 * renderer4 has depth index 0
1525 * renderer5 has depth index -1
1527 * Expected rendering order: renderer1 - renderer2 - renderer0 - renderer5 - renderer4 - renderer3
1530 Shader shader = Shader::New("VertexSource", "FragmentSource");
1531 Geometry geometry = CreateQuadGeometry();
1533 Actor root = Stage::GetCurrent().GetRootLayer();
1535 Actor actor0 = CreateActor( root, 0, TEST_LOCATION );
1536 Actor actor1 = CreateActor( actor0, 0, TEST_LOCATION );
1537 Renderer renderer0 = CreateRenderer( actor0, geometry, shader, 2 );
1538 Renderer renderer1 = CreateRenderer( actor0, geometry, shader, 0 );
1539 Renderer renderer2 = CreateRenderer( actor0, geometry, shader, 1 );
1540 Renderer renderer3 = CreateRenderer( actor1, geometry, shader, 1 );
1541 Renderer renderer4 = CreateRenderer( actor1, geometry, shader, 0 );
1542 Renderer renderer5 = CreateRenderer( actor1, geometry, shader, -1 );
1544 application.SendNotification();
1545 application.Render(0);
1547 TestGlAbstraction& gl = application.GetGlAbstraction();
1548 gl.EnableTextureCallTrace(true);
1549 application.SendNotification();
1550 application.Render(0);
1552 int textureBindIndex[6];
1553 for( unsigned int i(0); i<6; ++i )
1555 std::stringstream params;
1556 params << GL_TEXTURE_2D<<", "<<i+1;
1557 textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str() );
1560 //Check that renderer3 has been rendered after renderer4
1561 DALI_TEST_GREATER( textureBindIndex[3], textureBindIndex[4], TEST_LOCATION );
1563 //Check that renderer0 has been rendered after renderer2
1564 DALI_TEST_GREATER( textureBindIndex[4], textureBindIndex[5], TEST_LOCATION );
1566 //Check that renderer0 has been rendered after renderer2
1567 DALI_TEST_GREATER( textureBindIndex[5], textureBindIndex[0], TEST_LOCATION );
1569 //Check that renderer0 has been rendered after renderer2
1570 DALI_TEST_GREATER( textureBindIndex[0], textureBindIndex[2], TEST_LOCATION );
1572 //Check that renderer2 has been rendered after renderer1
1573 DALI_TEST_GREATER( textureBindIndex[2], textureBindIndex[1], TEST_LOCATION );
1579 int UtcDaliRendererRenderOrder2DLayerSiblingOrder(void)
1581 TestApplication application;
1582 tet_infoline("Test the rendering order in a 2D layer is correct using sibling order");
1585 * Creates the following hierarchy:
1593 * actor0 (SIBLING_ORDER:1) actor1 (SIBLING_ORDER:0)
1597 * renderer0 renderer1 actor2 renderer2 renderer3 renderer4
1598 * DI:2 DI:0 | DI:0 DI:1 DI:2
1603 * actor0 has sibling order 1
1604 * actor1 has sibling order 0
1605 * actor2 has sibling order 0
1607 * renderer0 has depth index 2
1608 * renderer1 has depth index 0
1610 * renderer2 has depth index 0
1611 * renderer3 has depth index 1
1612 * renderer4 has depth index 2
1614 * renderer5 has depth index -1
1616 * Expected rendering order: renderer2 - renderer3 - renderer4 - renderer1 - renderer0 - renderer5
1619 Shader shader = Shader::New("VertexSource", "FragmentSource");
1620 Geometry geometry = CreateQuadGeometry();
1621 Actor root = Stage::GetCurrent().GetRootLayer();
1622 Actor actor0 = CreateActor( root, 1, TEST_LOCATION );
1623 Actor actor1 = CreateActor( root, 0, TEST_LOCATION );
1624 Actor actor2 = CreateActor( actor0, 0, TEST_LOCATION );
1626 Renderer renderer0 = CreateRenderer( actor0, geometry, shader, 2 );
1627 Renderer renderer1 = CreateRenderer( actor0, geometry, shader, 0 );
1628 Renderer renderer2 = CreateRenderer( actor1, geometry, shader, 0 );
1629 Renderer renderer3 = CreateRenderer( actor1, geometry, shader, 1 );
1630 Renderer renderer4 = CreateRenderer( actor1, geometry, shader, 2 );
1631 Renderer renderer5 = CreateRenderer( actor2, geometry, shader, -1 );
1633 application.SendNotification();
1634 application.Render();
1636 TestGlAbstraction& gl = application.GetGlAbstraction();
1637 gl.EnableTextureCallTrace(true);
1638 application.SendNotification();
1639 application.Render(0);
1641 int textureBindIndex[6];
1642 for( unsigned int i(0); i<6; ++i )
1644 std::stringstream params;
1645 params << GL_TEXTURE_2D<<", "<<i+1;
1646 textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str() );
1649 DALI_TEST_EQUALS( textureBindIndex[2], 0, TEST_LOCATION );
1650 DALI_TEST_EQUALS( textureBindIndex[3], 1, TEST_LOCATION );
1651 DALI_TEST_EQUALS( textureBindIndex[4], 2, TEST_LOCATION );
1652 DALI_TEST_EQUALS( textureBindIndex[1], 3, TEST_LOCATION );
1653 DALI_TEST_EQUALS( textureBindIndex[0], 4, TEST_LOCATION );
1654 DALI_TEST_EQUALS( textureBindIndex[5], 5, TEST_LOCATION );
1656 // Change sibling order of actor1
1657 // New Expected rendering order: renderer1 - renderer0 - renderer 5 - renderer2 - renderer3 - renderer4
1658 actor1.SetProperty( Dali::DevelActor::Property::SIBLING_ORDER, 2 );
1660 gl.GetTextureTrace().Reset();
1661 application.SendNotification();
1662 application.Render(0);
1664 for( unsigned int i(0); i<6; ++i )
1666 std::stringstream params;
1667 params << GL_TEXTURE_2D<<", "<<i+1;
1668 textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str() );
1671 DALI_TEST_EQUALS( textureBindIndex[1], 0, TEST_LOCATION );
1672 DALI_TEST_EQUALS( textureBindIndex[0], 1, TEST_LOCATION );
1673 DALI_TEST_EQUALS( textureBindIndex[5], 2, TEST_LOCATION );
1674 DALI_TEST_EQUALS( textureBindIndex[2], 3, TEST_LOCATION );
1675 DALI_TEST_EQUALS( textureBindIndex[3], 4, TEST_LOCATION );
1676 DALI_TEST_EQUALS( textureBindIndex[4], 5, TEST_LOCATION );
1681 int UtcDaliRendererRenderOrder2DLayerOverlay(void)
1683 TestApplication application;
1684 tet_infoline("Test the rendering order in a 2D layer is correct for overlays");
1686 Shader shader = Shader::New("VertexSource", "FragmentSource");
1687 Geometry geometry = CreateQuadGeometry();
1688 Actor root = Stage::GetCurrent().GetRootLayer();
1691 * Create the following hierarchy:
1698 * (Overlay) (Regular actor)
1708 * Expected rendering order : actor2 - actor4 - actor1 - actor0 - actor3
1711 Actor actor0 = CreateActor( root, 0, TEST_LOCATION );
1712 actor0.SetDrawMode( DrawMode::OVERLAY_2D );
1713 Renderer renderer0 = CreateRenderer( actor0, geometry, shader, 0 );
1715 Actor actor1 = CreateActor( root, 0, TEST_LOCATION );
1716 actor1.SetDrawMode( DrawMode::OVERLAY_2D );
1717 Renderer renderer1 = CreateRenderer( actor1, geometry, shader, 0 );
1719 Actor actor2 = CreateActor( root, 0, TEST_LOCATION );
1720 Renderer renderer2 = CreateRenderer( actor2, geometry, shader, 0 );
1722 Actor actor3 = CreateActor( root, 0, TEST_LOCATION );
1723 actor3.SetDrawMode( DrawMode::OVERLAY_2D );
1724 Renderer renderer3 = CreateRenderer( actor3, geometry, shader, 0 );
1726 Actor actor4 = CreateActor( root, 0, TEST_LOCATION );
1727 Renderer renderer4 = CreateRenderer( actor4, geometry, shader, 0 );
1729 application.SendNotification();
1730 application.Render(0);
1737 TestGlAbstraction& gl = application.GetGlAbstraction();
1738 gl.EnableTextureCallTrace(true);
1739 application.SendNotification();
1740 application.Render(0);
1742 int textureBindIndex[5];
1743 for( unsigned int i(0); i<5; ++i )
1745 std::stringstream params;
1746 params << GL_TEXTURE_2D<<", "<<i+1;
1747 textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str() );
1750 //Check that actor4 has been rendered after actor2
1751 DALI_TEST_GREATER( textureBindIndex[4], textureBindIndex[2], TEST_LOCATION );
1753 //Check that actor1 has been rendered after actor4
1754 DALI_TEST_GREATER( textureBindIndex[1], textureBindIndex[4], TEST_LOCATION );
1756 //Check that actor0 has been rendered after actor1
1757 DALI_TEST_GREATER( textureBindIndex[0], textureBindIndex[1], TEST_LOCATION );
1759 //Check that actor3 has been rendered after actor0
1760 DALI_TEST_GREATER( textureBindIndex[3], textureBindIndex[0], TEST_LOCATION );
1765 int UtcDaliRendererSetIndexRange(void)
1769 "attribute vec2 aPosition;\n"
1772 " gl_Position = aPosition;\n"
1778 " gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0)\n"
1782 TestApplication application;
1783 tet_infoline("Test setting the range of indices to draw");
1785 TestGlAbstraction& gl = application.GetGlAbstraction();
1786 gl.EnableDrawCallTrace( true );
1788 Actor actor = Actor::New();
1789 actor.SetSize( 100, 100 );
1792 Geometry geometry = Geometry::New();
1793 geometry.SetType( Geometry::LINE_LOOP );
1795 // --------------------------------------------------------------------------
1797 unsigned short indices[] = { 0, 2, 4, 6, 8, // offset = 0, count = 5
1798 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, // offset = 5, count = 10
1799 1, 3, 5, 7, 9, 1 }; // offset = 15, count = 6 // line strip
1801 // --------------------------------------------------------------------------
1810 { Vector2( 0.0f, 1.00f) }, { Vector2( 0.0f, -1.00f) },
1811 { Vector2( -0.95f, 0.31f) }, { Vector2( 0.59f, 0.81f) },
1812 { Vector2( -0.59f, -0.81f) }, { Vector2( -0.95f, -0.31f) },
1813 { Vector2( 0.59f, -0.81f) }, { Vector2( 0.95f, -0.31f) },
1814 { Vector2( 0.95f, 0.31f) }, { Vector2( -0.59f, 0.81f) },
1816 Property::Map vertexFormat;
1817 vertexFormat["aPosition"] = Property::VECTOR2;
1818 PropertyBuffer vertexBuffer = PropertyBuffer::New( vertexFormat );
1819 vertexBuffer.SetData( shapes, sizeof(shapes)/sizeof(shapes[0]));
1821 // --------------------------------------------------------------------------
1822 geometry.SetIndexBuffer( indices, sizeof(indices)/sizeof(indices[0]) );
1823 geometry.AddVertexBuffer( vertexBuffer );
1826 Shader shader = Shader::New( vertexShader,fragmentShader );
1827 Renderer renderer = Renderer::New( geometry, shader );
1828 actor.AddRenderer( renderer );
1830 Stage stage = Stage::GetCurrent();
1835 // LINE_LOOP, first 0, count 5
1837 renderer.SetIndexRange( 0, 5 );
1838 application.SendNotification();
1839 application.Render();
1840 sprintf( buffer, "%u, 5, %u, indices", GL_LINE_LOOP, GL_UNSIGNED_SHORT );
1841 bool result = gl.GetDrawTrace().FindMethodAndParams( "DrawElements" , buffer );
1842 DALI_TEST_CHECK( result );
1845 // LINE_LOOP, first 5, count 10
1847 renderer.SetIndexRange( 5, 10 );
1848 sprintf( buffer, "%u, 10, %u, indices", GL_LINE_LOOP, GL_UNSIGNED_SHORT );
1849 application.SendNotification();
1850 application.Render();
1851 bool result = gl.GetDrawTrace().FindMethodAndParams( "DrawElements" , buffer );
1852 DALI_TEST_CHECK( result );
1855 // LINE_STRIP, first 15, count 6
1857 renderer.SetIndexRange( 15, 6 );
1858 geometry.SetType( Geometry::LINE_STRIP );
1859 sprintf( buffer, "%u, 6, %u, indices", GL_LINE_STRIP, GL_UNSIGNED_SHORT );
1860 application.SendNotification();
1861 application.Render();
1862 bool result = gl.GetDrawTrace().FindMethodAndParams( "DrawElements" , buffer );
1863 DALI_TEST_CHECK( result );
1866 // Index out of bounds
1868 renderer.SetIndexRange( 15, 30 );
1869 geometry.SetType( Geometry::LINE_STRIP );
1870 sprintf( buffer, "%u, 6, %u, indices", GL_LINE_STRIP, GL_UNSIGNED_SHORT );
1871 application.SendNotification();
1872 application.Render();
1873 bool result = gl.GetDrawTrace().FindMethodAndParams( "DrawElements" , buffer );
1874 DALI_TEST_CHECK( result );
1877 // drawing whole buffer starting from 15 ( last valid primitive )
1879 renderer.SetIndexRange( 15, 0 );
1880 geometry.SetType( Geometry::LINE_STRIP );
1881 sprintf( buffer, "%u, 6, %u, indices", GL_LINE_STRIP, GL_UNSIGNED_SHORT );
1882 application.SendNotification();
1883 application.Render();
1884 bool result = gl.GetDrawTrace().FindMethodAndParams( "DrawElements" , buffer );
1885 DALI_TEST_CHECK( result );
1892 int UtcDaliRendererSetDepthFunction(void)
1894 TestApplication application;
1896 tet_infoline("Test setting the depth function");
1898 Geometry geometry = CreateQuadGeometry();
1899 Shader shader = CreateShader();
1900 Renderer renderer = Renderer::New( geometry, shader );
1902 Actor actor = Actor::New();
1903 actor.AddRenderer(renderer);
1904 actor.SetSize(400, 400);
1905 Stage stage = Stage::GetCurrent();
1906 stage.GetRootLayer().SetBehavior( Layer::LAYER_3D );
1909 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1910 glAbstraction.EnableEnableDisableCallTrace(true);
1911 glAbstraction.EnableDepthFunctionCallTrace(true);
1913 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
1914 TraceCallStack& glDepthFunctionStack = glAbstraction.GetDepthFunctionTrace();
1916 std::ostringstream depthTestStr;
1917 depthTestStr << GL_DEPTH_TEST;
1921 renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::NEVER);
1923 glEnableDisableStack.Reset();
1924 glDepthFunctionStack.Reset();
1925 application.SendNotification();
1926 application.Render();
1928 DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Enable", depthTestStr.str().c_str() ) );
1929 std::ostringstream depthFunctionStr;
1930 depthFunctionStr << GL_NEVER;
1931 DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
1936 renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::ALWAYS);
1938 glDepthFunctionStack.Reset();
1939 application.SendNotification();
1940 application.Render();
1942 std::ostringstream depthFunctionStr;
1943 depthFunctionStr << GL_ALWAYS;
1944 DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
1949 renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::LESS);
1951 glDepthFunctionStack.Reset();
1952 application.SendNotification();
1953 application.Render();
1955 std::ostringstream depthFunctionStr;
1956 depthFunctionStr << GL_LESS;
1957 DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
1962 renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::GREATER);
1964 glDepthFunctionStack.Reset();
1965 application.SendNotification();
1966 application.Render();
1968 std::ostringstream depthFunctionStr;
1969 depthFunctionStr << GL_GREATER;
1970 DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
1975 renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::EQUAL);
1977 glDepthFunctionStack.Reset();
1978 application.SendNotification();
1979 application.Render();
1981 std::ostringstream depthFunctionStr;
1982 depthFunctionStr << GL_EQUAL;
1983 DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
1988 renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::NOT_EQUAL);
1990 glDepthFunctionStack.Reset();
1991 application.SendNotification();
1992 application.Render();
1994 std::ostringstream depthFunctionStr;
1995 depthFunctionStr << GL_NOTEQUAL;
1996 DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
2001 renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::LESS_EQUAL);
2003 glDepthFunctionStack.Reset();
2004 application.SendNotification();
2005 application.Render();
2007 std::ostringstream depthFunctionStr;
2008 depthFunctionStr << GL_LEQUAL;
2009 DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
2014 renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::GREATER_EQUAL);
2016 glDepthFunctionStack.Reset();
2017 application.SendNotification();
2018 application.Render();
2020 std::ostringstream depthFunctionStr;
2021 depthFunctionStr << GL_GEQUAL;
2022 DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
2029 * @brief This templatized function checks an enumeration property is setting and getting correctly.
2030 * The checks performed are as follows:
2031 * - Check the initial/default value.
2032 * - Set a different value via enum.
2033 * - Check it was set.
2034 * - Set a different value via string.
2035 * - Check it was set.
2037 template< typename T >
2038 void CheckEnumerationProperty( Renderer& renderer, Property::Index propertyIndex, T initialValue, T firstCheckEnumeration, T secondCheckEnumeration, std::string secondCheckString )
2040 DALI_TEST_CHECK( renderer.GetProperty<int>( propertyIndex ) == static_cast<int>( initialValue ) );
2041 DALI_TEST_CHECK( DevelHandle::GetCurrentProperty< int >( renderer, propertyIndex ) == static_cast<int>( initialValue ) );
2042 renderer.SetProperty( propertyIndex, firstCheckEnumeration );
2043 DALI_TEST_CHECK( renderer.GetProperty<int>( propertyIndex ) == static_cast<int>( firstCheckEnumeration ) );
2044 DALI_TEST_CHECK( DevelHandle::GetCurrentProperty< int >( renderer, propertyIndex ) == static_cast<int>( firstCheckEnumeration ) );
2045 renderer.SetProperty( propertyIndex, secondCheckString );
2046 DALI_TEST_CHECK( renderer.GetProperty<int>( propertyIndex ) == static_cast<int>( secondCheckEnumeration ) );
2047 DALI_TEST_CHECK( DevelHandle::GetCurrentProperty< int >( renderer, propertyIndex ) == static_cast<int>( secondCheckEnumeration ) );
2050 int UtcDaliRendererEnumProperties(void)
2052 TestApplication application;
2053 tet_infoline( "Test Renderer enumeration properties can be set with both integer and string values" );
2055 Geometry geometry = CreateQuadGeometry();
2056 Shader shader = CreateShader();
2057 Renderer renderer = Renderer::New( geometry, shader );
2060 * Here we use a templatized function to perform several checks on each enumeration property.
2061 * @see CheckEnumerationProperty for details of the checks performed.
2064 CheckEnumerationProperty< FaceCullingMode::Type >( renderer, Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::NONE, FaceCullingMode::FRONT, FaceCullingMode::BACK, "BACK" );
2065 CheckEnumerationProperty< BlendMode::Type >( renderer, Renderer::Property::BLEND_MODE, BlendMode::AUTO, BlendMode::OFF, BlendMode::ON, "ON" );
2066 CheckEnumerationProperty< BlendEquation::Type >( renderer, Renderer::Property::BLEND_EQUATION_RGB, BlendEquation::ADD, BlendEquation::SUBTRACT, BlendEquation::REVERSE_SUBTRACT, "REVERSE_SUBTRACT" );
2067 CheckEnumerationProperty< BlendEquation::Type >( renderer, Renderer::Property::BLEND_EQUATION_ALPHA, BlendEquation::ADD, BlendEquation::SUBTRACT, BlendEquation::REVERSE_SUBTRACT, "REVERSE_SUBTRACT" );
2068 CheckEnumerationProperty< BlendFactor::Type >( renderer, Renderer::Property::BLEND_FACTOR_SRC_RGB, BlendFactor::SRC_ALPHA, BlendFactor::ONE, BlendFactor::SRC_COLOR, "SRC_COLOR" );
2069 CheckEnumerationProperty< BlendFactor::Type >( renderer, Renderer::Property::BLEND_FACTOR_DEST_RGB, BlendFactor::ONE_MINUS_SRC_ALPHA, BlendFactor::ONE, BlendFactor::SRC_COLOR, "SRC_COLOR" );
2070 CheckEnumerationProperty< BlendFactor::Type >( renderer, Renderer::Property::BLEND_FACTOR_SRC_ALPHA, BlendFactor::ONE, BlendFactor::ONE_MINUS_SRC_ALPHA, BlendFactor::SRC_COLOR, "SRC_COLOR" );
2071 CheckEnumerationProperty< BlendFactor::Type >( renderer, Renderer::Property::BLEND_FACTOR_DEST_ALPHA, BlendFactor::ONE_MINUS_SRC_ALPHA, BlendFactor::ONE, BlendFactor::SRC_COLOR, "SRC_COLOR" );
2072 CheckEnumerationProperty< DepthWriteMode::Type >( renderer, Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::AUTO, DepthWriteMode::OFF, DepthWriteMode::ON, "ON" );
2073 CheckEnumerationProperty< DepthFunction::Type >( renderer, Renderer::Property::DEPTH_FUNCTION, DepthFunction::LESS, DepthFunction::ALWAYS, DepthFunction::GREATER, "GREATER" );
2074 CheckEnumerationProperty< DepthTestMode::Type >( renderer, Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::AUTO, DepthTestMode::OFF, DepthTestMode::ON, "ON" );
2075 CheckEnumerationProperty< StencilFunction::Type >( renderer, Renderer::Property::STENCIL_FUNCTION, StencilFunction::ALWAYS, StencilFunction::LESS, StencilFunction::EQUAL, "EQUAL" );
2076 CheckEnumerationProperty< RenderMode::Type >( renderer, Renderer::Property::RENDER_MODE, RenderMode::AUTO, RenderMode::NONE, RenderMode::STENCIL, "STENCIL" );
2077 CheckEnumerationProperty< StencilOperation::Type >( renderer, Renderer::Property::STENCIL_OPERATION_ON_FAIL, StencilOperation::KEEP, StencilOperation::REPLACE, StencilOperation::INCREMENT, "INCREMENT" );
2078 CheckEnumerationProperty< StencilOperation::Type >( renderer, Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, StencilOperation::KEEP, StencilOperation::REPLACE, StencilOperation::INCREMENT, "INCREMENT" );
2079 CheckEnumerationProperty< StencilOperation::Type >( renderer, Renderer::Property::STENCIL_OPERATION_ON_Z_PASS, StencilOperation::KEEP, StencilOperation::REPLACE, StencilOperation::INCREMENT, "INCREMENT" );
2084 Renderer RendererTestFixture( TestApplication& application )
2086 Geometry geometry = CreateQuadGeometry();
2087 Shader shader = CreateShader();
2088 Renderer renderer = Renderer::New( geometry, shader );
2090 Actor actor = Actor::New();
2091 actor.AddRenderer( renderer );
2092 actor.SetSize( 400.0f, 400.0f );
2093 Stage stage = Stage::GetCurrent();
2094 stage.GetRootLayer().SetBehavior( Layer::LAYER_3D );
2100 int UtcDaliRendererSetDepthTestMode(void)
2102 TestApplication application;
2103 tet_infoline("Test setting the DepthTestMode");
2105 Renderer renderer = RendererTestFixture( application );
2106 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2107 glAbstraction.EnableEnableDisableCallTrace( true );
2108 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2110 glEnableDisableStack.Reset();
2111 application.SendNotification();
2112 application.Render();
2114 // Check depth-test is enabled by default.
2115 DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Enable", GetDepthTestString() ) );
2116 DALI_TEST_CHECK( !glEnableDisableStack.FindMethodAndParams( "Disable", GetDepthTestString() ) );
2118 // 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.
2119 renderer.SetProperty( Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::OFF );
2120 renderer.SetProperty( Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::OFF );
2122 glEnableDisableStack.Reset();
2123 application.SendNotification();
2124 application.Render();
2126 // Check the depth buffer was disabled.
2127 DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Disable", GetDepthTestString() ) );
2129 // Turn on automatic mode depth-testing.
2130 // Layer behavior is currently set to LAYER_3D so AUTO should enable depth-testing.
2131 renderer.SetProperty( Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::AUTO );
2133 glEnableDisableStack.Reset();
2134 application.SendNotification();
2135 application.Render();
2137 // Check depth-test is now enabled.
2138 DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Enable", GetDepthTestString() ) );
2139 DALI_TEST_CHECK( !glEnableDisableStack.FindMethodAndParams( "Disable", GetDepthTestString() ) );
2141 // Change the layer behavior to LAYER_2D.
2142 // Note this will also disable depth testing for the layer by default, we test this first.
2143 Stage::GetCurrent().GetRootLayer().SetBehavior( Layer::LAYER_2D );
2145 glEnableDisableStack.Reset();
2146 application.SendNotification();
2147 application.Render();
2149 // Check depth-test is disabled.
2150 DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Disable", GetDepthTestString() ) );
2152 // Turn the layer depth-test flag back on, and confirm that depth testing is now on.
2153 Stage::GetCurrent().GetRootLayer().SetDepthTestDisabled( false );
2155 glEnableDisableStack.Reset();
2156 application.SendNotification();
2157 application.Render();
2159 // Check depth-test is *still* disabled.
2160 DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Enable", GetDepthTestString() ) );
2165 int UtcDaliRendererSetDepthWriteMode(void)
2167 TestApplication application;
2168 tet_infoline("Test setting the DepthWriteMode");
2170 Renderer renderer = RendererTestFixture( application );
2171 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2173 application.SendNotification();
2174 application.Render();
2176 // Check the default depth-write status first.
2177 DALI_TEST_CHECK( glAbstraction.GetLastDepthMask() );
2179 // Turn off depth-writing.
2180 renderer.SetProperty( Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::OFF );
2182 application.SendNotification();
2183 application.Render();
2185 // Check depth-write is now disabled.
2186 DALI_TEST_CHECK( !glAbstraction.GetLastDepthMask() );
2188 // Test the AUTO mode for depth-writing.
2189 // As our renderer is opaque, depth-testing should be enabled.
2190 renderer.SetProperty( Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::AUTO );
2192 application.SendNotification();
2193 application.Render();
2195 // Check depth-write is now enabled.
2196 DALI_TEST_CHECK( glAbstraction.GetLastDepthMask() );
2198 // Now make the renderer be treated as translucent by enabling blending.
2199 // The AUTO depth-write mode should turn depth-write off in this scenario.
2200 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::ON );
2202 application.SendNotification();
2203 application.Render();
2205 // Check depth-write is now disabled.
2206 DALI_TEST_CHECK( !glAbstraction.GetLastDepthMask() );
2211 int UtcDaliRendererCheckStencilDefaults(void)
2213 TestApplication application;
2214 tet_infoline("Test the stencil defaults");
2216 Renderer renderer = RendererTestFixture( application );
2217 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2218 glAbstraction.EnableEnableDisableCallTrace( true );
2219 glAbstraction.EnableStencilFunctionCallTrace( true );
2220 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2221 TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2223 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2225 // Check the defaults:
2226 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_FUNCTION ).Get<int>() ), static_cast<int>( StencilFunction::ALWAYS ), TEST_LOCATION );
2227 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_FUNCTION_MASK ).Get<int>() ), 0xFF, TEST_LOCATION );
2228 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_FUNCTION_REFERENCE ).Get<int>() ), 0x00, TEST_LOCATION );
2229 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_MASK ).Get<int>() ), 0xFF, TEST_LOCATION );
2230 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_OPERATION_ON_FAIL ).Get<int>() ), static_cast<int>( StencilOperation::KEEP ), TEST_LOCATION );
2231 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 );
2232 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 );
2237 int UtcDaliRendererSetRenderModeToUseStencilBuffer(void)
2239 TestApplication application;
2240 tet_infoline("Test setting the RenderMode to use the stencil buffer");
2242 Renderer renderer = RendererTestFixture( application );
2243 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2244 glAbstraction.EnableEnableDisableCallTrace( true );
2245 glAbstraction.EnableStencilFunctionCallTrace( true );
2246 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2247 TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2249 // Set the StencilFunction to something other than the default, to confirm it is set as a property,
2250 // but NO GL call has been made while the RenderMode is set to not use the stencil buffer.
2251 renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::NONE );
2252 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2254 renderer.SetProperty( Renderer::Property::STENCIL_FUNCTION, StencilFunction::NEVER );
2255 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_FUNCTION ).Get<int>() ), static_cast<int>( StencilFunction::NEVER ), TEST_LOCATION );
2257 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2258 std::string methodString( "StencilFunc" );
2259 DALI_TEST_CHECK( !glStencilFunctionStack.FindMethod( methodString ) );
2261 // Test the other RenderModes that will not enable the stencil buffer.
2262 renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::AUTO );
2263 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2264 DALI_TEST_CHECK( !glStencilFunctionStack.FindMethod( methodString ) );
2266 renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::COLOR );
2267 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2268 DALI_TEST_CHECK( !glStencilFunctionStack.FindMethod( methodString ) );
2270 // Now set the RenderMode to modes that will use the stencil buffer, and check the StencilFunction has changed.
2271 renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::STENCIL );
2272 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2274 DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Enable", GetStencilTestString() ) );
2275 DALI_TEST_CHECK( glStencilFunctionStack.FindMethod( methodString ) );
2277 // Test the COLOR_STENCIL RenderMode as it also enables the stencil buffer.
2278 // First set a mode to turn off the stencil buffer, so the enable is required.
2279 renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::COLOR );
2280 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2281 renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::COLOR_STENCIL );
2282 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2284 DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Enable", GetStencilTestString() ) );
2285 DALI_TEST_CHECK( glStencilFunctionStack.FindMethod( methodString ) );
2290 // Helper function for the SetRenderModeToUseColorBuffer test.
2291 void CheckRenderModeColorMask( TestApplication& application, Renderer& renderer, RenderMode::Type renderMode, bool expectedValue )
2293 // Set the RenderMode property to a value that should not allow color buffer writes.
2294 renderer.SetProperty( Renderer::Property::RENDER_MODE, renderMode );
2295 application.SendNotification();
2296 application.Render();
2298 // Check if ColorMask has been called, and that the values are correct.
2299 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2300 const TestGlAbstraction::ColorMaskParams& colorMaskParams( glAbstraction.GetColorMaskParams() );
2302 DALI_TEST_EQUALS<bool>( colorMaskParams.red, expectedValue, TEST_LOCATION );
2303 DALI_TEST_EQUALS<bool>( colorMaskParams.green, expectedValue, TEST_LOCATION );
2304 DALI_TEST_EQUALS<bool>( colorMaskParams.blue, expectedValue, TEST_LOCATION );
2305 DALI_TEST_EQUALS<bool>( colorMaskParams.alpha, expectedValue, TEST_LOCATION );
2308 int UtcDaliRendererSetRenderModeToUseColorBuffer(void)
2310 TestApplication application;
2311 tet_infoline("Test setting the RenderMode to use the color buffer");
2313 Renderer renderer = RendererTestFixture( application );
2315 // Set the RenderMode property to a value that should not allow color buffer writes.
2316 // Then check if ColorMask has been called, and that the values are correct.
2317 CheckRenderModeColorMask( application, renderer, RenderMode::AUTO, true );
2318 CheckRenderModeColorMask( application, renderer, RenderMode::NONE, false );
2319 CheckRenderModeColorMask( application, renderer, RenderMode::COLOR, true );
2320 CheckRenderModeColorMask( application, renderer, RenderMode::STENCIL, false );
2321 CheckRenderModeColorMask( application, renderer, RenderMode::COLOR_STENCIL, true );
2326 int UtcDaliRendererSetStencilFunction(void)
2328 TestApplication application;
2329 tet_infoline("Test setting the StencilFunction");
2331 Renderer renderer = RendererTestFixture( application );
2332 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2333 glAbstraction.EnableEnableDisableCallTrace( true );
2334 glAbstraction.EnableStencilFunctionCallTrace( true );
2335 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2336 TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2338 // RenderMode must use the stencil for StencilFunction to operate.
2339 renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::STENCIL );
2340 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2343 * Lookup table for testing StencilFunction.
2344 * Note: This MUST be in the same order as the Dali::StencilFunction enum.
2346 const int StencilFunctionLookupTable[] = {
2355 }; const int StencilFunctionLookupTableCount = sizeof( StencilFunctionLookupTable ) / sizeof( StencilFunctionLookupTable[0] );
2358 * Loop through all types of StencilFunction, checking:
2359 * - The value is cached (set in event thread side)
2360 * - Causes "glStencilFunc" to be called
2361 * - Checks the correct parameters to "glStencilFunc" were used
2363 std::string nonChangingParameters = "0, 255";
2364 std::string methodString( "StencilFunc" );
2365 for( int i = 0; i < StencilFunctionLookupTableCount; ++i )
2367 // Set the property.
2368 renderer.SetProperty( Renderer::Property::STENCIL_FUNCTION, static_cast<Dali::StencilFunction::Type>( i ) );
2370 // Check GetProperty returns the same value.
2371 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_FUNCTION ).Get<int>() ), i, TEST_LOCATION );
2373 // Reset the trace debug.
2374 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2376 // Check the function is called and the parameters are correct.
2377 std::stringstream parameterStream;
2378 parameterStream << StencilFunctionLookupTable[ i ] << ", " << nonChangingParameters;
2380 DALI_TEST_CHECK( glStencilFunctionStack.FindMethodAndParams( methodString, parameterStream.str() ) );
2383 // Change the Function Reference only and check the behavior is correct:
2384 // 170 is 0xaa in hex / 10101010 in binary (every other bit set).
2385 int testValueReference = 170;
2386 renderer.SetProperty( Renderer::Property::STENCIL_FUNCTION_REFERENCE, testValueReference );
2388 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_FUNCTION_REFERENCE ).Get<int>() ), testValueReference, TEST_LOCATION );
2390 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2392 std::stringstream parameterStream;
2393 parameterStream << StencilFunctionLookupTable[ StencilOperation::DECREMENT_WRAP ] << ", " << testValueReference << ", 255";
2395 DALI_TEST_CHECK( glStencilFunctionStack.FindMethodAndParams( methodString, parameterStream.str() ) );
2398 // Change the Function Mask only and check the behavior is correct:
2399 // 85 is 0x55 in hex / 01010101 in binary (every other bit set).
2400 int testValueMask = 85;
2401 renderer.SetProperty( Renderer::Property::STENCIL_FUNCTION_MASK, testValueMask );
2403 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_FUNCTION_MASK ).Get<int>() ), testValueMask, TEST_LOCATION );
2405 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2407 // Clear the stringstream.
2408 parameterStream.str( std::string() );
2409 parameterStream << StencilFunctionLookupTable[ StencilOperation::DECREMENT_WRAP ] << ", " << testValueReference << ", " << testValueMask;
2411 DALI_TEST_CHECK( glStencilFunctionStack.FindMethodAndParams( methodString, parameterStream.str() ) );
2416 int UtcDaliRendererSetStencilOperation(void)
2418 TestApplication application;
2419 tet_infoline("Test setting the StencilOperation");
2421 Renderer renderer = RendererTestFixture( application );
2422 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2423 glAbstraction.EnableEnableDisableCallTrace( true );
2424 glAbstraction.EnableStencilFunctionCallTrace( true );
2425 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2426 TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2428 // RenderMode must use the stencil for StencilOperation to operate.
2429 renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::STENCIL );
2432 * Lookup table for testing StencilOperation.
2433 * Note: This MUST be in the same order as the Dali::StencilOperation enum.
2435 const int StencilOperationLookupTable[] = {
2444 }; const int StencilOperationLookupTableCount = sizeof( StencilOperationLookupTable ) / sizeof( StencilOperationLookupTable[0] );
2446 // Set all 3 StencilOperation properties to a default.
2447 renderer.SetProperty( Renderer::Property::STENCIL_OPERATION_ON_FAIL, StencilOperation::ZERO );
2448 renderer.SetProperty( Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, StencilOperation::ZERO );
2449 renderer.SetProperty( Renderer::Property::STENCIL_OPERATION_ON_Z_PASS, StencilOperation::ZERO );
2451 // Set our expected parameter list to the equivalent result.
2452 int parameters[] = { StencilOperationLookupTable[ StencilOperation::ZERO ], StencilOperationLookupTable[ StencilOperation::ZERO ], StencilOperationLookupTable[ StencilOperation::ZERO ] };
2454 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2457 * Loop through all types of StencilOperation, checking:
2458 * - The value is cached (set in event thread side)
2459 * - Causes "glStencilFunc" to be called
2460 * - Checks the correct parameters to "glStencilFunc" were used
2461 * - Checks the above for all 3 parameter placements of StencilOperation ( OnFail, OnZFail, OnPass )
2463 int stencilOperationPropertyKeys[] = { Renderer::Property::STENCIL_OPERATION_ON_FAIL, Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, Renderer::Property::STENCIL_OPERATION_ON_Z_PASS };
2464 std::string methodString( "StencilOp" );
2466 for( int parameterIndex = 0; parameterIndex < 3; ++parameterIndex )
2468 for( int i = 0; i < StencilOperationLookupTableCount; ++i )
2470 // Set the property (outer loop causes all 3 different properties to be set separately).
2471 renderer.SetProperty( stencilOperationPropertyKeys[ parameterIndex ], static_cast<Dali::StencilFunction::Type>( i ) );
2473 // Check GetProperty returns the same value.
2474 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( stencilOperationPropertyKeys[ parameterIndex ] ).Get<int>() ), i, TEST_LOCATION );
2476 // Reset the trace debug.
2477 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2479 // Check the function is called and the parameters are correct.
2480 // Set the expected parameter value at its correct index (only)
2481 parameters[ parameterIndex ] = StencilOperationLookupTable[ i ];
2483 // Build the parameter list.
2484 std::stringstream parameterStream;
2485 for( int parameterBuild = 0; parameterBuild < 3; ++parameterBuild )
2487 parameterStream << parameters[ parameterBuild ];
2488 // Comma-separate the parameters.
2489 if( parameterBuild < 2 )
2491 parameterStream << ", ";
2495 // Check the function was called and the parameters were correct.
2496 DALI_TEST_CHECK( glStencilFunctionStack.FindMethodAndParams( methodString, parameterStream.str() ) );
2503 int UtcDaliRendererSetStencilMask(void)
2505 TestApplication application;
2506 tet_infoline("Test setting the StencilMask");
2508 Renderer renderer = RendererTestFixture( application );
2509 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2510 glAbstraction.EnableEnableDisableCallTrace( true );
2511 glAbstraction.EnableStencilFunctionCallTrace( true );
2512 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2513 TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2515 // RenderMode must use the stencil for StencilMask to operate.
2516 renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::STENCIL );
2518 // Set the StencilMask property to a value.
2519 renderer.SetProperty( Renderer::Property::STENCIL_MASK, 0x00 );
2521 // Check GetProperty returns the same value.
2522 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_MASK ).Get<int>() ), 0x00, TEST_LOCATION );
2524 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2526 std::string methodString( "StencilMask" );
2527 std::string parameterString = "0";
2529 // Check the function was called and the parameters were correct.
2530 DALI_TEST_CHECK( glStencilFunctionStack.FindMethodAndParams( methodString, parameterString ) );
2532 // Set the StencilMask property to another value to ensure it has changed.
2533 renderer.SetProperty( Renderer::Property::STENCIL_MASK, 0xFF );
2535 // Check GetProperty returns the same value.
2536 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_MASK ).Get<int>() ), 0xFF, TEST_LOCATION );
2538 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2540 parameterString = "255";
2542 // Check the function was called and the parameters were correct.
2543 DALI_TEST_CHECK( glStencilFunctionStack.FindMethodAndParams( methodString, parameterString ) );
2548 int UtcDaliRendererWrongNumberOfTextures(void)
2550 TestApplication application;
2551 tet_infoline("Test renderer does render even if number of textures is different than active samplers in the shader");
2553 //Create a TextureSet with 4 textures (One more texture in the texture set than active samplers)
2554 //@note Shaders in the test suit have 3 active samplers. See TestGlAbstraction::GetActiveUniform()
2555 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, 64u, 64u );
2556 TextureSet textureSet = CreateTextureSet();
2557 textureSet.SetTexture(0, texture );
2558 textureSet.SetTexture(1, texture );
2559 textureSet.SetTexture(2, texture );
2560 textureSet.SetTexture(3, texture );
2561 Shader shader = Shader::New("VertexSource", "FragmentSource");
2562 Geometry geometry = CreateQuadGeometry();
2563 Renderer renderer = Renderer::New( geometry, shader );
2564 renderer.SetTextures( textureSet );
2566 Actor actor= Actor::New();
2567 actor.AddRenderer(renderer);
2568 actor.SetPosition(0.0f,0.0f);
2569 actor.SetSize(100, 100);
2570 Stage::GetCurrent().Add(actor);
2572 TestGlAbstraction& gl = application.GetGlAbstraction();
2573 TraceCallStack& drawTrace = gl.GetDrawTrace();
2575 drawTrace.Enable(true);
2577 application.SendNotification();
2578 application.Render(0);
2580 //Test we do the drawcall when TextureSet has more textures than there are active samplers in the shader
2581 DALI_TEST_EQUALS( drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION );
2583 //Create a TextureSet with 1 texture (two more active samplers than texture in the texture set)
2584 //@note Shaders in the test suit have 3 active samplers. See TestGlAbstraction::GetActiveUniform()
2585 textureSet = CreateTextureSet();
2586 renderer.SetTextures( textureSet );
2587 textureSet.SetTexture(0, texture );
2589 application.SendNotification();
2590 application.Render(0);
2592 //Test we do the drawcall when TextureSet has less textures than there are active samplers in the shader.
2593 DALI_TEST_EQUALS( drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION );