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>
27 #include <dali-test-suite-utils.h>
28 #include <test-trace-call-stack.h>
29 #include <mesh-builder.h>
33 namespace // unnamed namespace
36 const BlendFactor::Type DEFAULT_BLEND_FACTOR_SRC_RGB( BlendFactor::SRC_ALPHA );
37 const BlendFactor::Type DEFAULT_BLEND_FACTOR_DEST_RGB( BlendFactor::ONE_MINUS_SRC_ALPHA );
38 const BlendFactor::Type DEFAULT_BLEND_FACTOR_SRC_ALPHA( BlendFactor::ONE );
39 const BlendFactor::Type DEFAULT_BLEND_FACTOR_DEST_ALPHA( BlendFactor::ONE_MINUS_SRC_ALPHA );
41 const BlendEquation::Type DEFAULT_BLEND_EQUATION_RGB( BlendEquation::ADD );
42 const BlendEquation::Type DEFAULT_BLEND_EQUATION_ALPHA( BlendEquation::ADD );
45 * @brief Get GL stencil test enumeration value as a string.
46 * @return The string representation of the value of GL_STENCIL_TEST
48 std::string GetStencilTestString(void)
50 std::stringstream stream;
51 stream << GL_STENCIL_TEST;
56 * @brief Get GL depth test enumeration value as a string.
57 * @return The string representation of the value of GL_DEPTH_TEST
59 std::string GetDepthTestString(void)
61 std::stringstream stream;
62 stream << GL_DEPTH_TEST;
66 void ResetDebugAndFlush( TestApplication& application, TraceCallStack& glEnableDisableStack, TraceCallStack& glStencilFunctionStack )
68 glEnableDisableStack.Reset();
69 glStencilFunctionStack.Reset();
70 application.SendNotification();
74 void TestConstraintNoBlue( Vector4& current, const PropertyInputContainer& inputs )
79 } // unnamed namespace
81 void renderer_test_startup(void)
83 test_return_value = TET_UNDEF;
86 void renderer_test_cleanup(void)
88 test_return_value = TET_PASS;
92 int UtcDaliRendererNew01(void)
94 TestApplication application;
96 Geometry geometry = CreateQuadGeometry();
97 Shader shader = CreateShader();
98 Renderer renderer = Renderer::New(geometry, shader);
100 DALI_TEST_EQUALS( (bool)renderer, true, TEST_LOCATION );
104 int UtcDaliRendererNew02(void)
106 TestApplication application;
108 DALI_TEST_EQUALS( (bool)renderer, false, TEST_LOCATION );
112 int UtcDaliRendererCopyConstructor(void)
114 TestApplication application;
116 Geometry geometry = CreateQuadGeometry();
117 Shader shader = CreateShader();
118 Renderer renderer = Renderer::New(geometry, shader);
120 Renderer rendererCopy( renderer );
121 DALI_TEST_EQUALS( (bool)rendererCopy, true, TEST_LOCATION );
126 int UtcDaliRendererAssignmentOperator(void)
128 TestApplication application;
130 Geometry geometry = CreateQuadGeometry();
131 Shader shader = CreateShader();
132 Renderer renderer = Renderer::New(geometry, shader);
135 DALI_TEST_EQUALS( (bool)renderer2, false, TEST_LOCATION );
137 renderer2 = renderer;
138 DALI_TEST_EQUALS( (bool)renderer2, true, TEST_LOCATION );
142 int UtcDaliRendererDownCast01(void)
144 TestApplication application;
146 Geometry geometry = CreateQuadGeometry();
147 Shader shader = CreateShader();
148 Renderer renderer = Renderer::New(geometry, shader);
150 BaseHandle handle(renderer);
151 Renderer renderer2 = Renderer::DownCast(handle);
152 DALI_TEST_EQUALS( (bool)renderer2, true, TEST_LOCATION );
156 int UtcDaliRendererDownCast02(void)
158 TestApplication application;
160 Handle handle = Handle::New(); // Create a custom object
161 Renderer renderer = Renderer::DownCast(handle);
162 DALI_TEST_EQUALS( (bool)renderer, false, TEST_LOCATION );
166 int UtcDaliRendererSetGetGeometry(void)
168 TestApplication application;
169 tet_infoline( "Test SetGeometry, GetGeometry" );
171 Geometry geometry1 = CreateQuadGeometry();
172 Geometry geometry2 = CreateQuadGeometry();
174 Shader shader = CreateShader();
175 Renderer renderer = Renderer::New(geometry1, shader);
176 Actor actor = Actor::New();
177 actor.AddRenderer(renderer);
178 actor.SetSize(400, 400);
179 Stage::GetCurrent().Add(actor);
181 application.SendNotification();
182 application.Render(0);
183 DALI_TEST_EQUALS( renderer.GetGeometry(), geometry1, TEST_LOCATION );
185 // Set geometry2 to the renderer
186 renderer.SetGeometry( geometry2 );
188 application.SendNotification();
189 application.Render(0);
190 DALI_TEST_EQUALS( renderer.GetGeometry(), geometry2, TEST_LOCATION );
195 int UtcDaliRendererSetGetShader(void)
197 TestApplication application;
198 tet_infoline( "Test SetShader, GetShader" );
200 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
201 glAbstraction.EnableCullFaceCallTrace(true);
203 Shader shader1 = CreateShader();
204 shader1.RegisterProperty( "uFadeColor", Color::RED );
206 Shader shader2 = CreateShader();
207 shader2.RegisterProperty( "uFadeColor", Color::GREEN );
209 Geometry geometry = CreateQuadGeometry();
210 Renderer renderer = Renderer::New(geometry, shader1);
211 Actor actor = Actor::New();
212 actor.AddRenderer(renderer);
213 actor.SetSize(400, 400);
214 Stage::GetCurrent().Add(actor);
216 TestGlAbstraction& gl = application.GetGlAbstraction();
217 application.SendNotification();
218 application.Render(0);
220 // Expect that the first shaders's fade color property is accessed
221 Vector4 actualValue(Vector4::ZERO);
222 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
223 DALI_TEST_EQUALS( actualValue, Color::RED, TEST_LOCATION );
225 DALI_TEST_EQUALS( renderer.GetShader(), shader1, TEST_LOCATION );
227 // set the second shader to the renderer
228 renderer.SetShader( shader2 );
230 application.SendNotification();
231 application.Render(0);
233 // Expect that the second shader's fade color property is accessed
234 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
235 DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
237 DALI_TEST_EQUALS( renderer.GetShader(), shader2, TEST_LOCATION );
242 int UtcDaliRendererSetGetDepthIndex(void)
244 TestApplication application;
246 tet_infoline("Test SetDepthIndex, GetDepthIndex");
248 Shader shader = CreateShader();
249 Geometry geometry = CreateQuadGeometry();
250 Renderer renderer = Renderer::New(geometry, shader);
251 Actor actor = Actor::New();
252 actor.AddRenderer(renderer);
253 actor.SetSize(400, 400);
254 Stage::GetCurrent().Add(actor);
256 application.SendNotification();
257 application.Render(0);
258 DALI_TEST_EQUALS( renderer.GetProperty<int>(Renderer::Property::DEPTH_INDEX), 0, TEST_LOCATION );
260 renderer.SetProperty( Renderer::Property::DEPTH_INDEX, 1 );
262 application.SendNotification();
263 application.Render(0);
264 DALI_TEST_EQUALS( renderer.GetProperty<int>(Renderer::Property::DEPTH_INDEX), 1, TEST_LOCATION );
266 renderer.SetProperty( Renderer::Property::DEPTH_INDEX, 10 );
268 application.SendNotification();
269 application.Render(0);
270 DALI_TEST_EQUALS( renderer.GetProperty<int>(Renderer::Property::DEPTH_INDEX), 10, TEST_LOCATION );
275 int UtcDaliRendererSetGetFaceCullingMode(void)
277 TestApplication application;
279 tet_infoline("Test SetFaceCullingMode(cullingMode)");
280 Geometry geometry = CreateQuadGeometry();
281 Shader shader = CreateShader();
282 Renderer renderer = Renderer::New( geometry, shader );
284 Actor actor = Actor::New();
285 actor.AddRenderer(renderer);
286 actor.SetSize(400, 400);
287 Stage::GetCurrent().Add(actor);
289 // By default, none of the faces should be culled
290 unsigned int cullFace = renderer.GetProperty<int>( Renderer::Property::FACE_CULLING_MODE );
291 DALI_TEST_CHECK( static_cast< FaceCullingMode::Type >( cullFace ) == FaceCullingMode::NONE );
293 TestGlAbstraction& gl = application.GetGlAbstraction();
294 TraceCallStack& cullFaceStack = gl.GetCullFaceTrace();
295 gl.EnableCullFaceCallTrace(true);
298 cullFaceStack.Reset();
299 renderer.SetProperty( Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::FRONT_AND_BACK );
300 application.SendNotification();
301 application.Render();
303 DALI_TEST_EQUALS( cullFaceStack.CountMethod( "CullFace" ), 1, TEST_LOCATION );
305 std::ostringstream cullModeString;
306 cullModeString << GL_FRONT_AND_BACK;
308 DALI_TEST_CHECK( cullFaceStack.FindMethodAndParams( "CullFace", cullModeString.str() ) );
309 cullFace = renderer.GetProperty<int>( Renderer::Property::FACE_CULLING_MODE );
310 DALI_TEST_CHECK( static_cast< FaceCullingMode::Type >( cullFace ) == FaceCullingMode::FRONT_AND_BACK );
314 cullFaceStack.Reset();
315 renderer.SetProperty( Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::BACK );
316 application.SendNotification();
317 application.Render();
319 DALI_TEST_EQUALS( cullFaceStack.CountMethod( "CullFace" ), 1, TEST_LOCATION );
321 std::ostringstream cullModeString;
322 cullModeString << GL_BACK;
324 DALI_TEST_CHECK( cullFaceStack.FindMethodAndParams( "CullFace", cullModeString.str() ) );
325 cullFace = renderer.GetProperty<int>( Renderer::Property::FACE_CULLING_MODE );
326 DALI_TEST_CHECK( static_cast< FaceCullingMode::Type >( cullFace ) == FaceCullingMode::BACK );
330 cullFaceStack.Reset();
331 renderer.SetProperty( Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::FRONT );
332 application.SendNotification();
333 application.Render();
335 DALI_TEST_EQUALS( cullFaceStack.CountMethod( "CullFace" ), 1, TEST_LOCATION );
337 std::ostringstream cullModeString;
338 cullModeString << GL_FRONT;
340 DALI_TEST_CHECK( cullFaceStack.FindMethodAndParams( "CullFace", cullModeString.str() ) );
341 cullFace = renderer.GetProperty<int>( Renderer::Property::FACE_CULLING_MODE );
342 DALI_TEST_CHECK( static_cast< FaceCullingMode::Type >( cullFace ) == FaceCullingMode::FRONT );
346 cullFaceStack.Reset();
347 renderer.SetProperty( Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::NONE );
348 application.SendNotification();
349 application.Render();
351 DALI_TEST_EQUALS( cullFaceStack.CountMethod( "CullFace" ), 0, TEST_LOCATION );
352 cullFace = renderer.GetProperty<int>( Renderer::Property::FACE_CULLING_MODE );
353 DALI_TEST_CHECK( static_cast< FaceCullingMode::Type >( cullFace ) == FaceCullingMode::NONE );
359 int UtcDaliRendererBlendOptions01(void)
361 TestApplication application;
363 tet_infoline("Test BLEND_FACTOR properties ");
365 Geometry geometry = CreateQuadGeometry();
366 Shader shader = CreateShader();
367 Renderer renderer = Renderer::New( geometry, shader );
369 Actor actor = Actor::New();
370 // set a transparent actor color so that blending is enabled
371 actor.SetOpacity( 0.5f );
372 actor.AddRenderer(renderer);
373 actor.SetSize(400, 400);
374 Stage::GetCurrent().Add(actor);
376 renderer.SetProperty( Renderer::Property::BLEND_FACTOR_SRC_RGB, BlendFactor::ONE_MINUS_SRC_COLOR );
377 renderer.SetProperty( Renderer::Property::BLEND_FACTOR_DEST_RGB, BlendFactor::SRC_ALPHA_SATURATE );
378 renderer.SetProperty( Renderer::Property::BLEND_FACTOR_SRC_ALPHA, BlendFactor::ONE_MINUS_SRC_COLOR );
379 renderer.SetProperty( Renderer::Property::BLEND_FACTOR_DEST_ALPHA, BlendFactor::SRC_ALPHA_SATURATE );
381 // Test that Set was successful:
382 int srcFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
383 int destFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
384 int srcFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
385 int destFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
387 DALI_TEST_EQUALS( (int)BlendFactor::ONE_MINUS_SRC_COLOR, srcFactorRgb, TEST_LOCATION );
388 DALI_TEST_EQUALS( (int)BlendFactor::SRC_ALPHA_SATURATE, destFactorRgb, TEST_LOCATION );
389 DALI_TEST_EQUALS( (int)BlendFactor::ONE_MINUS_SRC_COLOR, srcFactorAlpha, TEST_LOCATION );
390 DALI_TEST_EQUALS( (int)BlendFactor::SRC_ALPHA_SATURATE, destFactorAlpha, TEST_LOCATION );
392 application.SendNotification();
393 application.Render();
395 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
397 DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_SRC_COLOR, glAbstraction.GetLastBlendFuncSrcRgb(), TEST_LOCATION );
398 DALI_TEST_EQUALS( (GLenum)GL_SRC_ALPHA_SATURATE, glAbstraction.GetLastBlendFuncDstRgb(), TEST_LOCATION );
399 DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_SRC_COLOR, glAbstraction.GetLastBlendFuncSrcAlpha(), TEST_LOCATION );
400 DALI_TEST_EQUALS( (GLenum)GL_SRC_ALPHA_SATURATE, glAbstraction.GetLastBlendFuncDstAlpha(), TEST_LOCATION );
405 int UtcDaliRendererBlendOptions02(void)
407 TestApplication application;
409 tet_infoline("Test BLEND_FACTOR properties ");
411 Geometry geometry = CreateQuadGeometry();
412 Shader shader = CreateShader();
413 Renderer renderer = Renderer::New( geometry, shader );
415 Actor actor = Actor::New();
416 actor.SetOpacity( 0.5f ); // enable blending
417 actor.AddRenderer(renderer);
418 actor.SetSize(400, 400);
419 Stage::GetCurrent().Add(actor);
421 renderer.SetProperty( Renderer::Property::BLEND_FACTOR_SRC_RGB, BlendFactor::CONSTANT_COLOR );
422 renderer.SetProperty( Renderer::Property::BLEND_FACTOR_DEST_RGB, BlendFactor::ONE_MINUS_CONSTANT_COLOR );
423 renderer.SetProperty( Renderer::Property::BLEND_FACTOR_SRC_ALPHA, BlendFactor::CONSTANT_ALPHA );
424 renderer.SetProperty( Renderer::Property::BLEND_FACTOR_DEST_ALPHA, BlendFactor::ONE_MINUS_CONSTANT_ALPHA );
426 // Test that Set was successful:
428 int srcFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
429 int destFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
430 int srcFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
431 int destFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
433 DALI_TEST_EQUALS( (int)BlendFactor::CONSTANT_COLOR, srcFactorRgb, TEST_LOCATION );
434 DALI_TEST_EQUALS( (int)BlendFactor::ONE_MINUS_CONSTANT_COLOR, destFactorRgb, TEST_LOCATION );
435 DALI_TEST_EQUALS( (int)BlendFactor::CONSTANT_ALPHA, srcFactorAlpha, TEST_LOCATION );
436 DALI_TEST_EQUALS( (int)BlendFactor::ONE_MINUS_CONSTANT_ALPHA, destFactorAlpha, TEST_LOCATION );
439 application.SendNotification();
440 application.Render();
442 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
443 DALI_TEST_EQUALS( (GLenum)GL_CONSTANT_COLOR, glAbstraction.GetLastBlendFuncSrcRgb(), TEST_LOCATION );
444 DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_CONSTANT_COLOR, glAbstraction.GetLastBlendFuncDstRgb(), TEST_LOCATION );
445 DALI_TEST_EQUALS( (GLenum)GL_CONSTANT_ALPHA, glAbstraction.GetLastBlendFuncSrcAlpha(), TEST_LOCATION );
446 DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_CONSTANT_ALPHA, glAbstraction.GetLastBlendFuncDstAlpha(), TEST_LOCATION );
451 int UtcDaliRendererBlendOptions03(void)
453 TestApplication application;
455 tet_infoline("Test GetBlendEquation() defaults ");
457 Geometry geometry = CreateQuadGeometry();
458 Shader shader = CreateShader();
459 Renderer renderer = Renderer::New( geometry, shader );
461 Actor actor = Actor::New();
462 actor.AddRenderer(renderer);
463 actor.SetSize(400, 400);
464 Stage::GetCurrent().Add(actor);
466 // Test the defaults as documented in blending.h
467 int equationRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_EQUATION_RGB );
468 int equationAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_EQUATION_ALPHA );
470 DALI_TEST_EQUALS( (int)BlendEquation::ADD, equationRgb, TEST_LOCATION );
471 DALI_TEST_EQUALS( (int)BlendEquation::ADD, equationAlpha, TEST_LOCATION );
476 int UtcDaliRendererBlendOptions04(void)
478 TestApplication application;
480 tet_infoline("Test SetBlendEquation() ");
482 Geometry geometry = CreateQuadGeometry();
483 Shader shader = CreateShader();
484 Renderer renderer = Renderer::New( geometry, shader );
486 Actor actor = Actor::New();
487 actor.SetOpacity( 0.1f );
488 actor.AddRenderer(renderer);
489 actor.SetSize(400, 400);
490 Stage::GetCurrent().Add(actor);
492 // Test the single blending equation setting
494 renderer.SetProperty( Renderer::Property::BLEND_EQUATION_RGB, BlendEquation::REVERSE_SUBTRACT );
495 int equationRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_EQUATION_RGB );
496 DALI_TEST_EQUALS( (int)BlendEquation::REVERSE_SUBTRACT, equationRgb, TEST_LOCATION );
499 renderer.SetProperty( Renderer::Property::BLEND_EQUATION_RGB, BlendEquation::REVERSE_SUBTRACT );
500 renderer.SetProperty( Renderer::Property::BLEND_EQUATION_ALPHA, BlendEquation::REVERSE_SUBTRACT );
502 // Test that Set was successful
504 int equationRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_EQUATION_RGB );
505 int equationAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_EQUATION_ALPHA );
506 DALI_TEST_EQUALS( (int)BlendEquation::REVERSE_SUBTRACT, equationRgb, TEST_LOCATION );
507 DALI_TEST_EQUALS( (int)BlendEquation::REVERSE_SUBTRACT, equationAlpha, TEST_LOCATION );
510 // Render & check GL commands
511 application.SendNotification();
512 application.Render();
514 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
515 DALI_TEST_EQUALS( (GLenum)GL_FUNC_REVERSE_SUBTRACT, glAbstraction.GetLastBlendEquationRgb(), TEST_LOCATION );
516 DALI_TEST_EQUALS( (GLenum)GL_FUNC_REVERSE_SUBTRACT, glAbstraction.GetLastBlendEquationAlpha(), TEST_LOCATION );
521 int UtcDaliRendererSetBlendMode01(void)
523 TestApplication application;
525 tet_infoline("Test setting the blend mode to on with an opaque color renders with blending enabled");
527 Geometry geometry = CreateQuadGeometry();
528 Shader shader = CreateShader();
529 Renderer renderer = Renderer::New( geometry, shader );
531 Actor actor = Actor::New();
532 actor.SetOpacity( 0.98f );
533 actor.AddRenderer(renderer);
534 actor.SetSize(400, 400);
535 Stage::GetCurrent().Add(actor);
537 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::ON);
539 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
540 glAbstraction.EnableEnableDisableCallTrace(true);
542 application.SendNotification();
543 application.Render();
545 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
546 std::ostringstream blendStr;
547 blendStr << GL_BLEND;
548 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
553 int UtcDaliRendererSetBlendMode02(void)
555 TestApplication application;
557 tet_infoline("Test setting the blend mode to off with a transparent color renders with blending disabled (and not enabled)");
559 Geometry geometry = CreateQuadGeometry();
560 Shader shader = CreateShader();
561 Renderer renderer = Renderer::New( geometry, shader );
563 Actor actor = Actor::New();
564 actor.SetOpacity( 0.15f );
565 actor.AddRenderer(renderer);
566 actor.SetSize(400, 400);
567 Stage::GetCurrent().Add(actor);
569 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::OFF);
571 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
572 glAbstraction.EnableEnableDisableCallTrace(true);
574 application.SendNotification();
575 application.Render();
577 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
578 std::ostringstream blendStr;
579 blendStr << GL_BLEND;
580 DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
585 int UtcDaliRendererSetBlendMode03(void)
587 TestApplication application;
589 tet_infoline("Test setting the blend mode to auto with a transparent color renders with blending enabled");
591 Geometry geometry = CreateQuadGeometry();
592 Shader shader = CreateShader();
593 Renderer renderer = Renderer::New( geometry, shader );
595 Actor actor = Actor::New();
596 actor.SetOpacity( 0.75f );
597 actor.AddRenderer(renderer);
598 actor.SetSize(400, 400);
599 Stage::GetCurrent().Add(actor);
601 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::AUTO);
603 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
604 glAbstraction.EnableEnableDisableCallTrace(true);
606 application.SendNotification();
607 application.Render();
609 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
610 std::ostringstream blendStr;
611 blendStr << GL_BLEND;
612 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
617 int UtcDaliRendererSetBlendMode04(void)
619 TestApplication application;
621 tet_infoline("Test setting the blend mode to auto with an opaque color renders with blending disabled");
623 Geometry geometry = CreateQuadGeometry();
624 Shader shader = CreateShader();
625 Renderer renderer = Renderer::New( geometry, shader );
627 Actor actor = Actor::New();
628 actor.AddRenderer(renderer);
629 actor.SetSize(400, 400);
630 Stage::GetCurrent().Add(actor);
632 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::AUTO);
634 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
635 glAbstraction.EnableEnableDisableCallTrace(true);
637 application.SendNotification();
638 application.Render();
640 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
641 std::ostringstream blendStr;
642 blendStr << GL_BLEND;
643 DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
648 int UtcDaliRendererSetBlendMode04b(void)
650 TestApplication application;
652 tet_infoline("Test setting the blend mode to auto with a transparent actor color renders with blending enabled");
654 Geometry geometry = CreateQuadGeometry();
655 Shader shader = CreateShader();
656 Renderer renderer = Renderer::New( geometry, shader );
658 Actor actor = Actor::New();
659 actor.AddRenderer(renderer);
660 actor.SetSize(400, 400);
661 actor.SetColor( Vector4(1.0f, 0.0f, 1.0f, 0.5f) );
662 Stage::GetCurrent().Add(actor);
664 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::AUTO);
666 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
667 glAbstraction.EnableEnableDisableCallTrace(true);
669 application.SendNotification();
670 application.Render();
672 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
673 std::ostringstream blendStr;
674 blendStr << GL_BLEND;
675 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
680 int UtcDaliRendererSetBlendMode04c(void)
682 TestApplication application;
684 tet_infoline("Test setting the blend mode to auto with an opaque opaque actor color renders with blending disabled");
686 Geometry geometry = CreateQuadGeometry();
687 Shader shader = CreateShader();
688 Renderer renderer = Renderer::New( geometry, shader );
690 Actor actor = Actor::New();
691 actor.AddRenderer(renderer);
692 actor.SetSize(400, 400);
693 actor.SetColor( Color::MAGENTA );
694 Stage::GetCurrent().Add(actor);
696 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::AUTO);
698 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
699 glAbstraction.EnableEnableDisableCallTrace(true);
701 application.SendNotification();
702 application.Render();
704 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
705 std::ostringstream blendStr;
706 blendStr << GL_BLEND;
707 DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
712 int UtcDaliRendererSetBlendMode05(void)
714 TestApplication application;
716 tet_infoline("Test setting the blend mode to auto with an opaque color and an image with an alpha channel renders with blending enabled");
718 Geometry geometry = CreateQuadGeometry();
719 BufferImage image = BufferImage::New( 40, 40, Pixel::RGBA8888 );
721 Shader shader = CreateShader();
722 TextureSet textureSet = CreateTextureSet( image );
723 Renderer renderer = Renderer::New( geometry, shader );
724 renderer.SetTextures( textureSet );
726 Actor actor = Actor::New();
727 actor.AddRenderer(renderer);
728 actor.SetSize(400, 400);
729 Stage::GetCurrent().Add(actor);
731 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::AUTO);
733 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
734 glAbstraction.EnableEnableDisableCallTrace(true);
736 application.SendNotification();
737 application.Render();
739 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
740 std::ostringstream blendStr;
741 blendStr << GL_BLEND;
742 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
747 int UtcDaliRendererSetBlendMode06(void)
749 TestApplication application;
750 tet_infoline("Test setting the blend mode to auto with an opaque color and an image without an alpha channel and a shader with the hint OUTPUT_IS_TRANSPARENT renders with blending enabled");
752 Geometry geometry = CreateQuadGeometry();
753 Shader shader = Shader::New( "vertexSrc", "fragmentSrc", Shader::Hint::OUTPUT_IS_TRANSPARENT );
755 Renderer renderer = Renderer::New( geometry, shader );
757 Actor actor = Actor::New();
758 actor.AddRenderer(renderer);
759 actor.SetSize(400, 400);
760 Stage::GetCurrent().Add(actor);
762 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::AUTO);
764 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
765 glAbstraction.EnableEnableDisableCallTrace(true);
767 application.SendNotification();
768 application.Render();
770 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
771 std::ostringstream blendStr;
772 blendStr << GL_BLEND;
773 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
778 int UtcDaliRendererSetBlendMode07(void)
780 TestApplication application;
781 tet_infoline("Test setting the blend mode to auto with an opaque color and an image without an alpha channel and a shader with the hint OUTPUT_IS_OPAQUE renders with blending disabled");
783 Geometry geometry = CreateQuadGeometry();
784 Shader shader = Shader::New( "vertexSrc", "fragmentSrc" );
786 BufferImage image = BufferImage::New( 50, 50, Pixel::RGB888 );
787 TextureSet textureSet = CreateTextureSet( image );
788 Renderer renderer = Renderer::New( geometry, shader );
789 renderer.SetTextures( textureSet );
791 Actor actor = Actor::New();
792 actor.AddRenderer(renderer);
793 actor.SetSize(400, 400);
794 Stage::GetCurrent().Add(actor);
796 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::AUTO);
798 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
799 glAbstraction.EnableEnableDisableCallTrace(true);
801 application.SendNotification();
802 application.Render();
804 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
805 DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", "GL_BLEND" ) );
810 int UtcDaliRendererGetBlendMode(void)
812 TestApplication application;
814 tet_infoline("Test GetBlendMode()");
816 Geometry geometry = CreateQuadGeometry();
817 Shader shader = Shader::New( "vertexSrc", "fragmentSrc" );
818 Renderer renderer = Renderer::New( geometry, shader );
821 unsigned int mode = renderer.GetProperty<int>( Renderer::Property::BLEND_MODE );
822 DALI_TEST_EQUALS( static_cast< BlendMode::Type >( mode ), BlendMode::AUTO, TEST_LOCATION );
825 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::ON );
826 mode = renderer.GetProperty<int>( Renderer::Property::BLEND_MODE );
827 DALI_TEST_EQUALS( static_cast< BlendMode::Type >( mode ), BlendMode::ON, TEST_LOCATION );
830 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::OFF );
831 mode = renderer.GetProperty<int>( Renderer::Property::BLEND_MODE );
832 DALI_TEST_EQUALS( static_cast< BlendMode::Type >( mode ), BlendMode::OFF, TEST_LOCATION );
837 int UtcDaliRendererSetBlendColor(void)
839 TestApplication application;
841 tet_infoline("Test SetBlendColor(color)");
843 Geometry geometry = CreateQuadGeometry();
844 Shader shader = Shader::New( "vertexSrc", "fragmentSrc" );
845 TextureSet textureSet = TextureSet::New();
846 BufferImage image = BufferImage::New( 50, 50, Pixel::RGBA8888 );
847 TextureSetImage( textureSet, 0u, image );
848 Renderer renderer = Renderer::New( geometry, shader );
849 renderer.SetTextures( textureSet );
851 Actor actor = Actor::New();
852 actor.AddRenderer(renderer);
853 actor.SetSize(400, 400);
854 Stage::GetCurrent().Add(actor);
856 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
858 renderer.SetProperty( Renderer::Property::BLEND_COLOR, Color::TRANSPARENT );
859 application.SendNotification();
860 application.Render();
861 DALI_TEST_EQUALS( glAbstraction.GetLastBlendColor(), Color::TRANSPARENT, TEST_LOCATION );
863 renderer.SetProperty( Renderer::Property::BLEND_COLOR, Color::MAGENTA );
864 application.SendNotification();
865 application.Render();
866 DALI_TEST_EQUALS( glAbstraction.GetLastBlendColor(), Color::MAGENTA, TEST_LOCATION );
868 Vector4 color( 0.1f, 0.2f, 0.3f, 0.4f );
869 renderer.SetProperty( Renderer::Property::BLEND_COLOR, color );
870 application.SendNotification();
871 application.Render();
872 DALI_TEST_EQUALS( glAbstraction.GetLastBlendColor(), color, TEST_LOCATION );
877 int UtcDaliRendererGetBlendColor(void)
879 TestApplication application;
881 tet_infoline("Test GetBlendColor()");
883 Geometry geometry = CreateQuadGeometry();
884 Shader shader = Shader::New( "vertexSrc", "fragmentSrc" );
885 Renderer renderer = Renderer::New( geometry, shader );
887 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>( Renderer::Property::BLEND_COLOR ), Color::TRANSPARENT, TEST_LOCATION );
889 renderer.SetProperty( Renderer::Property::BLEND_COLOR, Color::MAGENTA );
890 application.SendNotification();
891 application.Render();
892 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>( Renderer::Property::BLEND_COLOR ), Color::MAGENTA, TEST_LOCATION );
894 Vector4 color( 0.1f, 0.2f, 0.3f, 0.4f );
895 renderer.SetProperty( Renderer::Property::BLEND_COLOR, color );
896 application.SendNotification();
897 application.Render();
898 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>( Renderer::Property::BLEND_COLOR ), color, TEST_LOCATION );
903 int UtcDaliRendererPreMultipledAlpha(void)
905 TestApplication application;
907 tet_infoline("Test BLEND_PRE_MULTIPLIED_ALPHA property");
909 Geometry geometry = CreateQuadGeometry();
910 Shader shader = Shader::New( "vertexSrc", "fragmentSrc" );
911 Renderer renderer = Renderer::New( geometry, shader );
913 Actor actor = Actor::New();
914 actor.AddRenderer(renderer);
915 actor.SetSize(400, 400);
916 actor.SetColor( Vector4(1.0f, 0.0f, 1.0f, 0.5f) );
917 Stage::GetCurrent().Add(actor);
919 Property::Value value = renderer.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
920 bool preMultipliedAlpha;
921 DALI_TEST_CHECK( value.Get( preMultipliedAlpha ) );
922 DALI_TEST_CHECK( !preMultipliedAlpha );
924 int srcFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
925 int destFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
926 int srcFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
927 int destFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
929 DALI_TEST_EQUALS( (int)DEFAULT_BLEND_FACTOR_SRC_RGB, srcFactorRgb, TEST_LOCATION );
930 DALI_TEST_EQUALS( (int)DEFAULT_BLEND_FACTOR_DEST_RGB, destFactorRgb, TEST_LOCATION );
931 DALI_TEST_EQUALS( (int)DEFAULT_BLEND_FACTOR_SRC_ALPHA, srcFactorAlpha, TEST_LOCATION );
932 DALI_TEST_EQUALS( (int)DEFAULT_BLEND_FACTOR_DEST_ALPHA, destFactorAlpha, TEST_LOCATION );
934 application.SendNotification();
935 application.Render();
937 Vector4 actualValue(Vector4::ZERO);
938 TestGlAbstraction& gl = application.GetGlAbstraction();
939 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uColor", actualValue ) );
940 DALI_TEST_EQUALS( actualValue, Vector4(1.0f, 0.0f, 1.0f, 0.5f), TEST_LOCATION );
942 renderer.SetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, true);
944 application.SendNotification();
945 application.Render();
947 value = renderer.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
948 DALI_TEST_CHECK( value.Get( preMultipliedAlpha ) );
949 DALI_TEST_CHECK( preMultipliedAlpha );
951 srcFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
952 destFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
953 srcFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
954 destFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
956 DALI_TEST_EQUALS( (int)BlendFactor::ONE, srcFactorRgb, TEST_LOCATION );
957 DALI_TEST_EQUALS( (int)BlendFactor::ONE_MINUS_SRC_ALPHA, destFactorRgb, TEST_LOCATION );
958 DALI_TEST_EQUALS( (int)BlendFactor::ONE, srcFactorAlpha, TEST_LOCATION );
959 DALI_TEST_EQUALS( (int)BlendFactor::ONE, destFactorAlpha, TEST_LOCATION );
961 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uColor", actualValue ) );
962 DALI_TEST_EQUALS( actualValue, Vector4(0.5f, 0.0f, 0.5f, 0.5f), TEST_LOCATION );
967 int UtcDaliRendererConstraint01(void)
969 TestApplication application;
971 tet_infoline("Test that a non-uniform renderer property can be constrained");
973 Shader shader = Shader::New("VertexSource", "FragmentSource");
974 Geometry geometry = CreateQuadGeometry();
975 Renderer renderer = Renderer::New( geometry, shader );
977 Actor actor = Actor::New();
978 actor.AddRenderer(renderer);
979 actor.SetSize(400, 400);
980 Stage::GetCurrent().Add(actor);
982 Vector4 initialColor = Color::WHITE;
983 Property::Index colorIndex = renderer.RegisterProperty( "uFadeColor", initialColor );
985 application.SendNotification();
986 application.Render(0);
987 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION );
990 Constraint constraint = Constraint::New<Vector4>( renderer, colorIndex, TestConstraintNoBlue );
992 application.SendNotification();
993 application.Render(0);
995 // Expect no blue component in either buffer - yellow
996 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector4 >( colorIndex ), Color::YELLOW, TEST_LOCATION );
997 application.Render(0);
998 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector4 >( colorIndex ), Color::YELLOW, TEST_LOCATION );
1000 renderer.RemoveConstraints();
1001 renderer.SetProperty(colorIndex, Color::WHITE );
1002 application.SendNotification();
1003 application.Render(0);
1004 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector4 >( colorIndex ), Color::WHITE, TEST_LOCATION );
1009 int UtcDaliRendererConstraint02(void)
1011 TestApplication application;
1013 tet_infoline("Test that a uniform map renderer property can be constrained");
1015 Shader shader = Shader::New("VertexSource", "FragmentSource");
1016 Geometry geometry = CreateQuadGeometry();
1017 Renderer renderer = Renderer::New( geometry, shader );
1019 Actor actor = Actor::New();
1020 actor.AddRenderer(renderer);
1021 actor.SetSize(400, 400);
1022 Stage::GetCurrent().Add(actor);
1023 application.SendNotification();
1024 application.Render(0);
1026 Vector4 initialColor = Color::WHITE;
1027 Property::Index colorIndex = renderer.RegisterProperty( "uFadeColor", initialColor );
1029 TestGlAbstraction& gl = application.GetGlAbstraction();
1031 application.SendNotification();
1032 application.Render(0);
1034 Vector4 actualValue(Vector4::ZERO);
1035 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1036 DALI_TEST_EQUALS( actualValue, initialColor, TEST_LOCATION );
1039 Constraint constraint = Constraint::New<Vector4>( renderer, colorIndex, TestConstraintNoBlue );
1041 application.SendNotification();
1042 application.Render(0);
1044 // Expect no blue component in either buffer - yellow
1045 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1046 DALI_TEST_EQUALS( actualValue, Color::YELLOW, TEST_LOCATION );
1048 application.Render(0);
1049 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1050 DALI_TEST_EQUALS( actualValue, Color::YELLOW, TEST_LOCATION );
1052 renderer.RemoveConstraints();
1053 renderer.SetProperty(colorIndex, Color::WHITE );
1054 application.SendNotification();
1055 application.Render(0);
1057 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1058 DALI_TEST_EQUALS( actualValue, Color::WHITE, TEST_LOCATION );
1063 int UtcDaliRendererAnimatedProperty01(void)
1065 TestApplication application;
1067 tet_infoline("Test that a non-uniform renderer property can be animated");
1069 Shader shader = Shader::New("VertexSource", "FragmentSource");
1070 Geometry geometry = CreateQuadGeometry();
1071 Renderer renderer = Renderer::New( geometry, shader );
1073 Actor actor = Actor::New();
1074 actor.AddRenderer(renderer);
1075 actor.SetSize(400, 400);
1076 Stage::GetCurrent().Add(actor);
1078 Vector4 initialColor = Color::WHITE;
1079 Property::Index colorIndex = renderer.RegisterProperty( "uFadeColor", initialColor );
1081 application.SendNotification();
1082 application.Render(0);
1083 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION );
1085 Animation animation = Animation::New(1.0f);
1086 KeyFrames keyFrames = KeyFrames::New();
1087 keyFrames.Add(0.0f, initialColor);
1088 keyFrames.Add(1.0f, Color::TRANSPARENT);
1089 animation.AnimateBetween( Property( renderer, colorIndex ), keyFrames );
1092 application.SendNotification();
1093 application.Render(500);
1095 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector4 >( colorIndex ), Color::WHITE * 0.5f, TEST_LOCATION );
1097 application.Render(500);
1099 DALI_TEST_EQUALS( renderer.GetCurrentProperty< Vector4 >( colorIndex ), Color::TRANSPARENT, TEST_LOCATION );
1104 int UtcDaliRendererAnimatedProperty02(void)
1106 TestApplication application;
1108 tet_infoline("Test that a uniform map renderer property can be animated");
1110 Shader shader = Shader::New("VertexSource", "FragmentSource");
1111 Geometry geometry = CreateQuadGeometry();
1112 Renderer renderer = Renderer::New( geometry, shader );
1114 Actor actor = Actor::New();
1115 actor.AddRenderer(renderer);
1116 actor.SetSize(400, 400);
1117 Stage::GetCurrent().Add(actor);
1118 application.SendNotification();
1119 application.Render(0);
1121 Vector4 initialColor = Color::WHITE;
1122 Property::Index colorIndex = renderer.RegisterProperty( "uFadeColor", initialColor );
1124 TestGlAbstraction& gl = application.GetGlAbstraction();
1126 application.SendNotification();
1127 application.Render(0);
1129 Vector4 actualValue(Vector4::ZERO);
1130 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1131 DALI_TEST_EQUALS( actualValue, initialColor, TEST_LOCATION );
1133 Animation animation = Animation::New(1.0f);
1134 KeyFrames keyFrames = KeyFrames::New();
1135 keyFrames.Add(0.0f, initialColor);
1136 keyFrames.Add(1.0f, Color::TRANSPARENT);
1137 animation.AnimateBetween( Property( renderer, colorIndex ), keyFrames );
1140 application.SendNotification();
1141 application.Render(500);
1143 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1144 DALI_TEST_EQUALS( actualValue, Color::WHITE * 0.5f, TEST_LOCATION );
1146 application.Render(500);
1147 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1148 DALI_TEST_EQUALS( actualValue, Color::TRANSPARENT, TEST_LOCATION );
1153 int UtcDaliRendererUniformMapPrecendence01(void)
1155 TestApplication application;
1157 tet_infoline("Test the uniform map precedence is applied properly");
1159 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1161 Shader shader = Shader::New("VertexSource", "FragmentSource");
1162 TextureSet textureSet = CreateTextureSet( image );
1164 Geometry geometry = CreateQuadGeometry();
1165 Renderer renderer = Renderer::New( geometry, shader );
1166 renderer.SetTextures( textureSet );
1168 Actor actor = Actor::New();
1169 actor.AddRenderer(renderer);
1170 actor.SetSize(400, 400);
1171 Stage::GetCurrent().Add(actor);
1172 application.SendNotification();
1173 application.Render(0);
1175 renderer.RegisterProperty( "uFadeColor", Color::RED );
1176 actor.RegisterProperty( "uFadeColor", Color::GREEN );
1177 Property::Index shaderFadeColorIndex = shader.RegisterProperty( "uFadeColor", Color::MAGENTA );
1179 TestGlAbstraction& gl = application.GetGlAbstraction();
1181 application.SendNotification();
1182 application.Render(0);
1184 // Expect that the actor's fade color property is accessed
1185 Vector4 actualValue(Vector4::ZERO);
1186 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1187 DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
1189 // Animate shader's fade color property. Should be no change to uniform
1190 Animation animation = Animation::New(1.0f);
1191 KeyFrames keyFrames = KeyFrames::New();
1192 keyFrames.Add(0.0f, Color::WHITE);
1193 keyFrames.Add(1.0f, Color::TRANSPARENT);
1194 animation.AnimateBetween( Property( shader, shaderFadeColorIndex ), keyFrames );
1197 application.SendNotification();
1198 application.Render(500);
1200 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1201 DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
1203 application.Render(500);
1204 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1205 DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
1210 int UtcDaliRendererUniformMapPrecendence02(void)
1212 TestApplication application;
1214 tet_infoline("Test the uniform map precedence is applied properly");
1216 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1218 Shader shader = Shader::New("VertexSource", "FragmentSource");
1219 TextureSet textureSet = CreateTextureSet( image );
1221 Geometry geometry = CreateQuadGeometry();
1222 Renderer renderer = Renderer::New( geometry, shader );
1223 renderer.SetTextures( textureSet );
1225 Actor actor = Actor::New();
1226 actor.AddRenderer(renderer);
1227 actor.SetSize(400, 400);
1228 Stage::GetCurrent().Add(actor);
1229 application.SendNotification();
1230 application.Render(0);
1232 // Don't add property / uniform map to renderer
1233 actor.RegisterProperty( "uFadeColor", Color::GREEN );
1234 Property::Index shaderFadeColorIndex = shader.RegisterProperty( "uFadeColor", Color::BLUE );
1236 TestGlAbstraction& gl = application.GetGlAbstraction();
1238 application.SendNotification();
1239 application.Render(0);
1241 // Expect that the actor's fade color property is accessed
1242 Vector4 actualValue(Vector4::ZERO);
1243 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1244 DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
1246 // Animate texture set's fade color property. Should be no change to uniform
1247 Animation animation = Animation::New(1.0f);
1248 KeyFrames keyFrames = KeyFrames::New();
1249 keyFrames.Add(0.0f, Color::WHITE);
1250 keyFrames.Add(1.0f, Color::TRANSPARENT);
1251 animation.AnimateBetween( Property( shader, shaderFadeColorIndex ), keyFrames );
1254 application.SendNotification();
1255 application.Render(500);
1257 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1258 DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
1260 application.Render(500);
1261 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1262 DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
1268 int UtcDaliRendererUniformMapPrecendence03(void)
1270 TestApplication application;
1272 tet_infoline("Test the uniform map precedence is applied properly");
1274 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1276 Shader shader = Shader::New("VertexSource", "FragmentSource");
1277 TextureSet textureSet = CreateTextureSet( image );
1279 Geometry geometry = CreateQuadGeometry();
1280 Renderer renderer = Renderer::New( geometry, shader );
1281 renderer.SetTextures( textureSet );
1283 Actor actor = Actor::New();
1284 actor.AddRenderer(renderer);
1285 actor.SetSize(400, 400);
1286 Stage::GetCurrent().Add(actor);
1287 application.SendNotification();
1288 application.Render(0);
1290 // Don't add property / uniform map to renderer or actor
1291 shader.RegisterProperty( "uFadeColor", Color::BLACK );
1293 TestGlAbstraction& gl = application.GetGlAbstraction();
1295 application.SendNotification();
1296 application.Render(0);
1298 // Expect that the shader's fade color property is accessed
1299 Vector4 actualValue(Vector4::ZERO);
1300 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1301 DALI_TEST_EQUALS( actualValue, Color::BLACK, TEST_LOCATION );
1306 int UtcDaliRendererUniformMapMultipleUniforms01(void)
1308 TestApplication application;
1310 tet_infoline("Test the uniform maps are collected from all objects (same type)");
1312 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1314 Shader shader = Shader::New("VertexSource", "FragmentSource");
1315 TextureSet textureSet = CreateTextureSet( image );
1317 Geometry geometry = CreateQuadGeometry();
1318 Renderer renderer = Renderer::New( geometry, shader );
1319 renderer.SetTextures( textureSet );
1321 Actor actor = Actor::New();
1322 actor.AddRenderer(renderer);
1323 actor.SetSize(400, 400);
1324 Stage::GetCurrent().Add(actor);
1325 application.SendNotification();
1326 application.Render(0);
1328 renderer.RegisterProperty( "uUniform1", Color::RED );
1329 actor.RegisterProperty( "uUniform2", Color::GREEN );
1330 shader.RegisterProperty( "uUniform3", Color::MAGENTA );
1332 TestGlAbstraction& gl = application.GetGlAbstraction();
1334 application.SendNotification();
1335 application.Render(0);
1337 // Expect that each of the object's uniforms are set
1338 Vector4 uniform1Value(Vector4::ZERO);
1339 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uUniform1", uniform1Value ) );
1340 DALI_TEST_EQUALS( uniform1Value, Color::RED, TEST_LOCATION );
1342 Vector4 uniform2Value(Vector4::ZERO);
1343 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uUniform2", uniform2Value ) );
1344 DALI_TEST_EQUALS( uniform2Value, Color::GREEN, TEST_LOCATION );
1346 Vector4 uniform3Value(Vector4::ZERO);
1347 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uUniform3", uniform3Value ) );
1348 DALI_TEST_EQUALS( uniform3Value, Color::MAGENTA, TEST_LOCATION );
1353 int UtcDaliRendererUniformMapMultipleUniforms02(void)
1355 TestApplication application;
1357 tet_infoline("Test the uniform maps are collected from all objects (different types)");
1359 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1361 Shader shader = Shader::New("VertexSource", "FragmentSource");
1362 TextureSet textureSet = CreateTextureSet( image );
1364 Geometry geometry = CreateQuadGeometry();
1365 Renderer renderer = Renderer::New( geometry, shader );
1366 renderer.SetTextures( textureSet );
1368 Actor actor = Actor::New();
1369 actor.AddRenderer(renderer);
1370 actor.SetSize(400, 400);
1371 Stage::GetCurrent().Add(actor);
1372 application.SendNotification();
1373 application.Render(0);
1375 Property::Value value1(Color::RED);
1376 renderer.RegisterProperty( "uFadeColor", value1 );
1378 Property::Value value2(1.0f);
1379 actor.RegisterProperty( "uFadeProgress", value2 );
1381 Property::Value value3(Matrix3::IDENTITY);
1382 shader.RegisterProperty( "uANormalMatrix", value3 );
1384 TestGlAbstraction& gl = application.GetGlAbstraction();
1386 application.SendNotification();
1387 application.Render(0);
1389 // Expect that each of the object's uniforms are set
1390 Vector4 uniform1Value(Vector4::ZERO);
1391 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", uniform1Value ) );
1392 DALI_TEST_EQUALS( uniform1Value, value1.Get<Vector4>(), TEST_LOCATION );
1394 float uniform2Value(0.0f);
1395 DALI_TEST_CHECK( gl.GetUniformValue<float>( "uFadeProgress", uniform2Value ) );
1396 DALI_TEST_EQUALS( uniform2Value, value2.Get<float>(), TEST_LOCATION );
1398 Matrix3 uniform3Value;
1399 DALI_TEST_CHECK( gl.GetUniformValue<Matrix3>( "uANormalMatrix", uniform3Value ) );
1400 DALI_TEST_EQUALS( uniform3Value, value3.Get<Matrix3>(), TEST_LOCATION );
1406 Renderer CreateRenderer( Actor actor, Geometry geometry, Shader shader, int depthIndex )
1408 Image image0 = BufferImage::New( 64, 64, Pixel::RGB888 );
1409 TextureSet textureSet0 = CreateTextureSet( image0 );
1410 Renderer renderer0 = Renderer::New( geometry, shader );
1411 renderer0.SetTextures( textureSet0 );
1412 renderer0.SetProperty( Renderer::Property::DEPTH_INDEX, depthIndex );
1413 actor.AddRenderer(renderer0);
1418 Actor CreateActor( Actor parent, int siblingOrder, const char* location )
1420 Actor actor = Actor::New();
1421 actor.SetAnchorPoint(AnchorPoint::CENTER);
1422 actor.SetParentOrigin(AnchorPoint::CENTER);
1423 actor.SetPosition(0.0f,0.0f);
1424 actor.SetSize(100, 100);
1426 actor.SetProperty( Dali::DevelActor::Property::SIBLING_ORDER, siblingOrder );
1427 DALI_TEST_EQUALS( actor.GetProperty<int>( Dali::DevelActor::Property::SIBLING_ORDER), siblingOrder, TEST_INNER_LOCATION(location) );
1432 int UtcDaliRendererRenderOrder2DLayer(void)
1434 TestApplication application;
1435 tet_infoline("Test the rendering order in a 2D layer is correct");
1437 Shader shader = Shader::New("VertexSource", "FragmentSource");
1438 Geometry geometry = CreateQuadGeometry();
1440 Actor root = Stage::GetCurrent().GetRootLayer();
1442 Actor actor0 = CreateActor( root, 0, TEST_LOCATION );
1443 Renderer renderer0 = CreateRenderer( actor0, geometry, shader, 0 );
1445 Actor actor1 = CreateActor( root, 0, TEST_LOCATION );
1446 Renderer renderer1 = CreateRenderer( actor1, geometry, shader, 0 );
1448 Actor actor2 = CreateActor( root, 0, TEST_LOCATION );
1449 Renderer renderer2 = CreateRenderer( actor2, geometry, shader, 0 );
1451 Actor actor3 = CreateActor( root, 0, TEST_LOCATION );
1452 Renderer renderer3 = CreateRenderer( actor3, geometry, shader, 0 );
1454 application.SendNotification();
1455 application.Render(0);
1458 * Create the following hierarchy:
1471 * Expected rendering order : actor2 - actor1 - actor0 - actor3
1476 application.SendNotification();
1477 application.Render(0);
1479 TestGlAbstraction& gl = application.GetGlAbstraction();
1480 gl.EnableTextureCallTrace(true);
1481 application.SendNotification();
1482 application.Render(0);
1484 int textureBindIndex[4];
1485 for( unsigned int i(0); i<4; ++i )
1487 std::stringstream params;
1488 params << GL_TEXTURE_2D<<", "<<i+1;
1489 textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str() );
1492 //Check that actor1 has been rendered after actor2
1493 DALI_TEST_GREATER( textureBindIndex[1], textureBindIndex[2], TEST_LOCATION );
1495 //Check that actor0 has been rendered after actor1
1496 DALI_TEST_GREATER( textureBindIndex[0], textureBindIndex[1], TEST_LOCATION );
1498 //Check that actor3 has been rendered after actor0
1499 DALI_TEST_GREATER( textureBindIndex[3], textureBindIndex[0], TEST_LOCATION );
1504 int UtcDaliRendererRenderOrder2DLayerMultipleRenderers(void)
1506 TestApplication application;
1507 tet_infoline("Test the rendering order in a 2D layer is correct using multiple renderers per actor");
1510 * Creates the following hierarchy:
1512 * actor0------------------------>actor1
1516 * renderer0 renderer1 renderer2 renderer3 renderer4 renderer5
1518 * renderer0 has depth index 2
1519 * renderer1 has depth index 0
1520 * renderer2 has depth index 1
1522 * renderer3 has depth index 1
1523 * renderer4 has depth index 0
1524 * renderer5 has depth index -1
1526 * Expected rendering order: renderer1 - renderer2 - renderer0 - renderer5 - renderer4 - renderer3
1529 Shader shader = Shader::New("VertexSource", "FragmentSource");
1530 Geometry geometry = CreateQuadGeometry();
1532 Actor root = Stage::GetCurrent().GetRootLayer();
1534 Actor actor0 = CreateActor( root, 0, TEST_LOCATION );
1535 Actor actor1 = CreateActor( actor0, 0, TEST_LOCATION );
1536 Renderer renderer0 = CreateRenderer( actor0, geometry, shader, 2 );
1537 Renderer renderer1 = CreateRenderer( actor0, geometry, shader, 0 );
1538 Renderer renderer2 = CreateRenderer( actor0, geometry, shader, 1 );
1539 Renderer renderer3 = CreateRenderer( actor1, geometry, shader, 1 );
1540 Renderer renderer4 = CreateRenderer( actor1, geometry, shader, 0 );
1541 Renderer renderer5 = CreateRenderer( actor1, geometry, shader, -1 );
1543 application.SendNotification();
1544 application.Render(0);
1546 TestGlAbstraction& gl = application.GetGlAbstraction();
1547 gl.EnableTextureCallTrace(true);
1548 application.SendNotification();
1549 application.Render(0);
1551 int textureBindIndex[6];
1552 for( unsigned int i(0); i<6; ++i )
1554 std::stringstream params;
1555 params << GL_TEXTURE_2D<<", "<<i+1;
1556 textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str() );
1559 //Check that renderer3 has been rendered after renderer4
1560 DALI_TEST_GREATER( textureBindIndex[3], textureBindIndex[4], TEST_LOCATION );
1562 //Check that renderer0 has been rendered after renderer2
1563 DALI_TEST_GREATER( textureBindIndex[4], textureBindIndex[5], TEST_LOCATION );
1565 //Check that renderer5 has been rendered after renderer2
1566 DALI_TEST_GREATER( textureBindIndex[5], textureBindIndex[0], TEST_LOCATION );
1568 //Check that renderer0 has been rendered after renderer2
1569 DALI_TEST_GREATER( textureBindIndex[0], textureBindIndex[2], TEST_LOCATION );
1571 //Check that renderer2 has been rendered after renderer1
1572 DALI_TEST_GREATER( textureBindIndex[2], textureBindIndex[1], TEST_LOCATION );
1578 int UtcDaliRendererRenderOrder2DLayerSiblingOrder(void)
1580 TestApplication application;
1581 tet_infoline("Test the rendering order in a 2D layer is correct using sibling order");
1584 * Creates the following hierarchy:
1592 * actor0 (SIBLING_ORDER:1) actor1 (SIBLING_ORDER:0)
1596 * renderer0 renderer1 actor2 renderer2 renderer3 renderer4
1597 * DI:2 DI:0 | DI:0 DI:1 DI:2
1602 * actor0 has sibling order 1
1603 * actor1 has sibling order 0
1604 * actor2 has sibling order 0
1606 * renderer0 has depth index 2
1607 * renderer1 has depth index 0
1609 * renderer2 has depth index 0
1610 * renderer3 has depth index 1
1611 * renderer4 has depth index 2
1613 * renderer5 has depth index -1
1615 * Expected rendering order: renderer2 - renderer3 - renderer4 - renderer1 - renderer0 - renderer5
1618 Shader shader = Shader::New("VertexSource", "FragmentSource");
1619 Geometry geometry = CreateQuadGeometry();
1620 Actor root = Stage::GetCurrent().GetRootLayer();
1621 Actor actor0 = CreateActor( root, 1, TEST_LOCATION );
1622 Actor actor1 = CreateActor( root, 0, TEST_LOCATION );
1623 Actor actor2 = CreateActor( actor0, 0, TEST_LOCATION );
1625 Renderer renderer0 = CreateRenderer( actor0, geometry, shader, 2 );
1626 Renderer renderer1 = CreateRenderer( actor0, geometry, shader, 0 );
1627 Renderer renderer2 = CreateRenderer( actor1, geometry, shader, 0 );
1628 Renderer renderer3 = CreateRenderer( actor1, geometry, shader, 1 );
1629 Renderer renderer4 = CreateRenderer( actor1, geometry, shader, 2 );
1630 Renderer renderer5 = CreateRenderer( actor2, geometry, shader, -1 );
1632 application.SendNotification();
1633 application.Render();
1635 TestGlAbstraction& gl = application.GetGlAbstraction();
1636 gl.EnableTextureCallTrace(true);
1637 application.SendNotification();
1638 application.Render(0);
1640 int textureBindIndex[6];
1641 for( unsigned int i(0); i<6; ++i )
1643 std::stringstream params;
1644 params << GL_TEXTURE_2D<<", "<<i+1;
1645 textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str() );
1648 DALI_TEST_EQUALS( textureBindIndex[2], 0, TEST_LOCATION );
1649 DALI_TEST_EQUALS( textureBindIndex[3], 1, TEST_LOCATION );
1650 DALI_TEST_EQUALS( textureBindIndex[4], 2, TEST_LOCATION );
1651 DALI_TEST_EQUALS( textureBindIndex[1], 3, TEST_LOCATION );
1652 DALI_TEST_EQUALS( textureBindIndex[0], 4, TEST_LOCATION );
1653 DALI_TEST_EQUALS( textureBindIndex[5], 5, TEST_LOCATION );
1655 // Change sibling order of actor1
1656 // New Expected rendering order: renderer1 - renderer0 - renderer 5 - renderer2 - renderer3 - renderer4
1657 actor1.SetProperty( Dali::DevelActor::Property::SIBLING_ORDER, 2 );
1659 gl.GetTextureTrace().Reset();
1660 application.SendNotification();
1661 application.Render(0);
1663 for( unsigned int i(0); i<6; ++i )
1665 std::stringstream params;
1666 params << GL_TEXTURE_2D<<", "<<i+1;
1667 textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str() );
1670 DALI_TEST_EQUALS( textureBindIndex[1], 0, TEST_LOCATION );
1671 DALI_TEST_EQUALS( textureBindIndex[0], 1, TEST_LOCATION );
1672 DALI_TEST_EQUALS( textureBindIndex[5], 2, TEST_LOCATION );
1673 DALI_TEST_EQUALS( textureBindIndex[2], 3, TEST_LOCATION );
1674 DALI_TEST_EQUALS( textureBindIndex[3], 4, TEST_LOCATION );
1675 DALI_TEST_EQUALS( textureBindIndex[4], 5, TEST_LOCATION );
1680 int UtcDaliRendererRenderOrder2DLayerOverlay(void)
1682 TestApplication application;
1683 tet_infoline("Test the rendering order in a 2D layer is correct for overlays");
1685 Shader shader = Shader::New("VertexSource", "FragmentSource");
1686 Geometry geometry = CreateQuadGeometry();
1687 Actor root = Stage::GetCurrent().GetRootLayer();
1690 * Create the following hierarchy:
1697 * (Overlay) (Regular actor)
1707 * Expected rendering order : actor2 - actor4 - actor1 - actor0 - actor3
1710 Actor actor0 = CreateActor( root, 0, TEST_LOCATION );
1711 actor0.SetDrawMode( DrawMode::OVERLAY_2D );
1712 Renderer renderer0 = CreateRenderer( actor0, geometry, shader, 0 );
1714 Actor actor1 = CreateActor( root, 0, TEST_LOCATION );
1715 actor1.SetDrawMode( DrawMode::OVERLAY_2D );
1716 Renderer renderer1 = CreateRenderer( actor1, geometry, shader, 0 );
1718 Actor actor2 = CreateActor( root, 0, TEST_LOCATION );
1719 Renderer renderer2 = CreateRenderer( actor2, geometry, shader, 0 );
1721 Actor actor3 = CreateActor( root, 0, TEST_LOCATION );
1722 actor3.SetDrawMode( DrawMode::OVERLAY_2D );
1723 Renderer renderer3 = CreateRenderer( actor3, geometry, shader, 0 );
1725 Actor actor4 = CreateActor( root, 0, TEST_LOCATION );
1726 Renderer renderer4 = CreateRenderer( actor4, geometry, shader, 0 );
1728 application.SendNotification();
1729 application.Render(0);
1736 TestGlAbstraction& gl = application.GetGlAbstraction();
1737 gl.EnableTextureCallTrace(true);
1738 application.SendNotification();
1739 application.Render(0);
1741 int textureBindIndex[5];
1742 for( unsigned int i(0); i<5; ++i )
1744 std::stringstream params;
1745 params << GL_TEXTURE_2D<<", "<<i+1;
1746 textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str() );
1749 //Check that actor4 has been rendered after actor2
1750 DALI_TEST_GREATER( textureBindIndex[4], textureBindIndex[2], TEST_LOCATION );
1752 //Check that actor1 has been rendered after actor4
1753 DALI_TEST_GREATER( textureBindIndex[1], textureBindIndex[4], TEST_LOCATION );
1755 //Check that actor0 has been rendered after actor1
1756 DALI_TEST_GREATER( textureBindIndex[0], textureBindIndex[1], TEST_LOCATION );
1758 //Check that actor3 has been rendered after actor0
1759 DALI_TEST_GREATER( textureBindIndex[3], textureBindIndex[0], TEST_LOCATION );
1764 int UtcDaliRendererSetIndexRange(void)
1768 "attribute vec2 aPosition;\n"
1771 " gl_Position = aPosition;\n"
1777 " gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0)\n"
1781 TestApplication application;
1782 tet_infoline("Test setting the range of indices to draw");
1784 TestGlAbstraction& gl = application.GetGlAbstraction();
1785 gl.EnableDrawCallTrace( true );
1787 Actor actor = Actor::New();
1788 actor.SetSize( 100, 100 );
1791 Geometry geometry = Geometry::New();
1792 geometry.SetType( Geometry::LINE_LOOP );
1794 // --------------------------------------------------------------------------
1796 unsigned short indices[] = { 0, 2, 4, 6, 8, // offset = 0, count = 5
1797 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, // offset = 5, count = 10
1798 1, 3, 5, 7, 9, 1 }; // offset = 15, count = 6 // line strip
1800 // --------------------------------------------------------------------------
1809 { Vector2( 0.0f, 1.00f) }, { Vector2( 0.0f, -1.00f) },
1810 { Vector2( -0.95f, 0.31f) }, { Vector2( 0.59f, 0.81f) },
1811 { Vector2( -0.59f, -0.81f) }, { Vector2( -0.95f, -0.31f) },
1812 { Vector2( 0.59f, -0.81f) }, { Vector2( 0.95f, -0.31f) },
1813 { Vector2( 0.95f, 0.31f) }, { Vector2( -0.59f, 0.81f) },
1815 Property::Map vertexFormat;
1816 vertexFormat["aPosition"] = Property::VECTOR2;
1817 PropertyBuffer vertexBuffer = PropertyBuffer::New( vertexFormat );
1818 vertexBuffer.SetData( shapes, sizeof(shapes)/sizeof(shapes[0]));
1820 // --------------------------------------------------------------------------
1821 geometry.SetIndexBuffer( indices, sizeof(indices)/sizeof(indices[0]) );
1822 geometry.AddVertexBuffer( vertexBuffer );
1825 Shader shader = Shader::New( vertexShader,fragmentShader );
1826 Renderer renderer = Renderer::New( geometry, shader );
1827 actor.AddRenderer( renderer );
1829 Stage stage = Stage::GetCurrent();
1834 // LINE_LOOP, first 0, count 5
1836 renderer.SetIndexRange( 0, 5 );
1837 application.SendNotification();
1838 application.Render();
1839 sprintf( buffer, "%u, 5, %u, indices", GL_LINE_LOOP, GL_UNSIGNED_SHORT );
1840 bool result = gl.GetDrawTrace().FindMethodAndParams( "DrawElements" , buffer );
1841 DALI_TEST_CHECK( result );
1844 // LINE_LOOP, first 5, count 10
1846 renderer.SetIndexRange( 5, 10 );
1847 sprintf( buffer, "%u, 10, %u, indices", GL_LINE_LOOP, GL_UNSIGNED_SHORT );
1848 application.SendNotification();
1849 application.Render();
1850 bool result = gl.GetDrawTrace().FindMethodAndParams( "DrawElements" , buffer );
1851 DALI_TEST_CHECK( result );
1854 // LINE_STRIP, first 15, count 6
1856 renderer.SetIndexRange( 15, 6 );
1857 geometry.SetType( Geometry::LINE_STRIP );
1858 sprintf( buffer, "%u, 6, %u, indices", GL_LINE_STRIP, GL_UNSIGNED_SHORT );
1859 application.SendNotification();
1860 application.Render();
1861 bool result = gl.GetDrawTrace().FindMethodAndParams( "DrawElements" , buffer );
1862 DALI_TEST_CHECK( result );
1865 // Index out of bounds
1867 renderer.SetIndexRange( 15, 30 );
1868 geometry.SetType( Geometry::LINE_STRIP );
1869 sprintf( buffer, "%u, 6, %u, indices", GL_LINE_STRIP, GL_UNSIGNED_SHORT );
1870 application.SendNotification();
1871 application.Render();
1872 bool result = gl.GetDrawTrace().FindMethodAndParams( "DrawElements" , buffer );
1873 DALI_TEST_CHECK( result );
1876 // drawing whole buffer starting from 15 ( last valid primitive )
1878 renderer.SetIndexRange( 15, 0 );
1879 geometry.SetType( Geometry::LINE_STRIP );
1880 sprintf( buffer, "%u, 6, %u, indices", GL_LINE_STRIP, GL_UNSIGNED_SHORT );
1881 application.SendNotification();
1882 application.Render();
1883 bool result = gl.GetDrawTrace().FindMethodAndParams( "DrawElements" , buffer );
1884 DALI_TEST_CHECK( result );
1891 int UtcDaliRendererSetDepthFunction(void)
1893 TestApplication application;
1895 tet_infoline("Test setting the depth function");
1897 Geometry geometry = CreateQuadGeometry();
1898 Shader shader = CreateShader();
1899 Renderer renderer = Renderer::New( geometry, shader );
1901 Actor actor = Actor::New();
1902 actor.AddRenderer(renderer);
1903 actor.SetSize(400, 400);
1904 Stage stage = Stage::GetCurrent();
1905 stage.GetRootLayer().SetBehavior( Layer::LAYER_3D );
1908 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1909 glAbstraction.EnableEnableDisableCallTrace(true);
1910 glAbstraction.EnableDepthFunctionCallTrace(true);
1912 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
1913 TraceCallStack& glDepthFunctionStack = glAbstraction.GetDepthFunctionTrace();
1915 std::ostringstream depthTestStr;
1916 depthTestStr << GL_DEPTH_TEST;
1920 renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::NEVER);
1922 glEnableDisableStack.Reset();
1923 glDepthFunctionStack.Reset();
1924 application.SendNotification();
1925 application.Render();
1927 DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Enable", depthTestStr.str().c_str() ) );
1928 std::ostringstream depthFunctionStr;
1929 depthFunctionStr << GL_NEVER;
1930 DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
1935 renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::ALWAYS);
1937 glDepthFunctionStack.Reset();
1938 application.SendNotification();
1939 application.Render();
1941 std::ostringstream depthFunctionStr;
1942 depthFunctionStr << GL_ALWAYS;
1943 DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
1948 renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::LESS);
1950 glDepthFunctionStack.Reset();
1951 application.SendNotification();
1952 application.Render();
1954 std::ostringstream depthFunctionStr;
1955 depthFunctionStr << GL_LESS;
1956 DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
1961 renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::GREATER);
1963 glDepthFunctionStack.Reset();
1964 application.SendNotification();
1965 application.Render();
1967 std::ostringstream depthFunctionStr;
1968 depthFunctionStr << GL_GREATER;
1969 DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
1974 renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::EQUAL);
1976 glDepthFunctionStack.Reset();
1977 application.SendNotification();
1978 application.Render();
1980 std::ostringstream depthFunctionStr;
1981 depthFunctionStr << GL_EQUAL;
1982 DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
1987 renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::NOT_EQUAL);
1989 glDepthFunctionStack.Reset();
1990 application.SendNotification();
1991 application.Render();
1993 std::ostringstream depthFunctionStr;
1994 depthFunctionStr << GL_NOTEQUAL;
1995 DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
2000 renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::LESS_EQUAL);
2002 glDepthFunctionStack.Reset();
2003 application.SendNotification();
2004 application.Render();
2006 std::ostringstream depthFunctionStr;
2007 depthFunctionStr << GL_LEQUAL;
2008 DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
2013 renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::GREATER_EQUAL);
2015 glDepthFunctionStack.Reset();
2016 application.SendNotification();
2017 application.Render();
2019 std::ostringstream depthFunctionStr;
2020 depthFunctionStr << GL_GEQUAL;
2021 DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
2028 * @brief This templatized function checks an enumeration property is setting and getting correctly.
2029 * The checks performed are as follows:
2030 * - Check the initial/default value.
2031 * - Set a different value via enum.
2032 * - Check it was set.
2033 * - Set a different value via string.
2034 * - Check it was set.
2036 template< typename T >
2037 void CheckEnumerationProperty( Renderer& renderer, Property::Index propertyIndex, T initialValue, T firstCheckEnumeration, T secondCheckEnumeration, std::string secondCheckString )
2039 DALI_TEST_CHECK( renderer.GetProperty<int>( propertyIndex ) == static_cast<int>( initialValue ) );
2040 DALI_TEST_CHECK( renderer.GetCurrentProperty< int >( propertyIndex ) == static_cast<int>( initialValue ) );
2041 renderer.SetProperty( propertyIndex, firstCheckEnumeration );
2042 DALI_TEST_CHECK( renderer.GetProperty<int>( propertyIndex ) == static_cast<int>( firstCheckEnumeration ) );
2043 DALI_TEST_CHECK( renderer.GetCurrentProperty< int >( propertyIndex ) == static_cast<int>( firstCheckEnumeration ) );
2044 renderer.SetProperty( propertyIndex, secondCheckString );
2045 DALI_TEST_CHECK( renderer.GetProperty<int>( propertyIndex ) == static_cast<int>( secondCheckEnumeration ) );
2046 DALI_TEST_CHECK( renderer.GetCurrentProperty< int >( propertyIndex ) == static_cast<int>( secondCheckEnumeration ) );
2049 int UtcDaliRendererEnumProperties(void)
2051 TestApplication application;
2052 tet_infoline( "Test Renderer enumeration properties can be set with both integer and string values" );
2054 Geometry geometry = CreateQuadGeometry();
2055 Shader shader = CreateShader();
2056 Renderer renderer = Renderer::New( geometry, shader );
2059 * Here we use a templatized function to perform several checks on each enumeration property.
2060 * @see CheckEnumerationProperty for details of the checks performed.
2063 CheckEnumerationProperty< FaceCullingMode::Type >( renderer, Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::NONE, FaceCullingMode::FRONT, FaceCullingMode::BACK, "BACK" );
2064 CheckEnumerationProperty< BlendMode::Type >( renderer, Renderer::Property::BLEND_MODE, BlendMode::AUTO, BlendMode::OFF, BlendMode::ON, "ON" );
2065 CheckEnumerationProperty< BlendEquation::Type >( renderer, Renderer::Property::BLEND_EQUATION_RGB, BlendEquation::ADD, BlendEquation::SUBTRACT, BlendEquation::REVERSE_SUBTRACT, "REVERSE_SUBTRACT" );
2066 CheckEnumerationProperty< BlendEquation::Type >( renderer, Renderer::Property::BLEND_EQUATION_ALPHA, BlendEquation::ADD, BlendEquation::SUBTRACT, BlendEquation::REVERSE_SUBTRACT, "REVERSE_SUBTRACT" );
2067 CheckEnumerationProperty< BlendFactor::Type >( renderer, Renderer::Property::BLEND_FACTOR_SRC_RGB, BlendFactor::SRC_ALPHA, BlendFactor::ONE, BlendFactor::SRC_COLOR, "SRC_COLOR" );
2068 CheckEnumerationProperty< BlendFactor::Type >( renderer, Renderer::Property::BLEND_FACTOR_DEST_RGB, BlendFactor::ONE_MINUS_SRC_ALPHA, BlendFactor::ONE, BlendFactor::SRC_COLOR, "SRC_COLOR" );
2069 CheckEnumerationProperty< BlendFactor::Type >( renderer, Renderer::Property::BLEND_FACTOR_SRC_ALPHA, BlendFactor::ONE, BlendFactor::ONE_MINUS_SRC_ALPHA, BlendFactor::SRC_COLOR, "SRC_COLOR" );
2070 CheckEnumerationProperty< BlendFactor::Type >( renderer, Renderer::Property::BLEND_FACTOR_DEST_ALPHA, BlendFactor::ONE_MINUS_SRC_ALPHA, BlendFactor::ONE, BlendFactor::SRC_COLOR, "SRC_COLOR" );
2071 CheckEnumerationProperty< DepthWriteMode::Type >( renderer, Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::AUTO, DepthWriteMode::OFF, DepthWriteMode::ON, "ON" );
2072 CheckEnumerationProperty< DepthFunction::Type >( renderer, Renderer::Property::DEPTH_FUNCTION, DepthFunction::LESS, DepthFunction::ALWAYS, DepthFunction::GREATER, "GREATER" );
2073 CheckEnumerationProperty< DepthTestMode::Type >( renderer, Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::AUTO, DepthTestMode::OFF, DepthTestMode::ON, "ON" );
2074 CheckEnumerationProperty< StencilFunction::Type >( renderer, Renderer::Property::STENCIL_FUNCTION, StencilFunction::ALWAYS, StencilFunction::LESS, StencilFunction::EQUAL, "EQUAL" );
2075 CheckEnumerationProperty< RenderMode::Type >( renderer, Renderer::Property::RENDER_MODE, RenderMode::AUTO, RenderMode::NONE, RenderMode::STENCIL, "STENCIL" );
2076 CheckEnumerationProperty< StencilOperation::Type >( renderer, Renderer::Property::STENCIL_OPERATION_ON_FAIL, StencilOperation::KEEP, StencilOperation::REPLACE, StencilOperation::INCREMENT, "INCREMENT" );
2077 CheckEnumerationProperty< StencilOperation::Type >( renderer, Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, StencilOperation::KEEP, StencilOperation::REPLACE, StencilOperation::INCREMENT, "INCREMENT" );
2078 CheckEnumerationProperty< StencilOperation::Type >( renderer, Renderer::Property::STENCIL_OPERATION_ON_Z_PASS, StencilOperation::KEEP, StencilOperation::REPLACE, StencilOperation::INCREMENT, "INCREMENT" );
2083 Renderer RendererTestFixture( TestApplication& application )
2085 Geometry geometry = CreateQuadGeometry();
2086 Shader shader = CreateShader();
2087 Renderer renderer = Renderer::New( geometry, shader );
2089 Actor actor = Actor::New();
2090 actor.AddRenderer( renderer );
2091 actor.SetSize( 400.0f, 400.0f );
2092 Stage stage = Stage::GetCurrent();
2093 stage.GetRootLayer().SetBehavior( Layer::LAYER_3D );
2099 int UtcDaliRendererSetDepthTestMode(void)
2101 TestApplication application;
2102 tet_infoline("Test setting the DepthTestMode");
2104 Renderer renderer = RendererTestFixture( application );
2105 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2106 glAbstraction.EnableEnableDisableCallTrace( true );
2107 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2109 glEnableDisableStack.Reset();
2110 application.SendNotification();
2111 application.Render();
2113 // Check depth-test is enabled by default.
2114 DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Enable", GetDepthTestString() ) );
2115 DALI_TEST_CHECK( !glEnableDisableStack.FindMethodAndParams( "Disable", GetDepthTestString() ) );
2117 // 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.
2118 renderer.SetProperty( Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::OFF );
2119 renderer.SetProperty( Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::OFF );
2121 glEnableDisableStack.Reset();
2122 application.SendNotification();
2123 application.Render();
2125 // Check the depth buffer was disabled.
2126 DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Disable", GetDepthTestString() ) );
2128 // Turn on automatic mode depth-testing.
2129 // Layer behavior is currently set to LAYER_3D so AUTO should enable depth-testing.
2130 renderer.SetProperty( Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::AUTO );
2132 glEnableDisableStack.Reset();
2133 application.SendNotification();
2134 application.Render();
2136 // Check depth-test is now enabled.
2137 DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Enable", GetDepthTestString() ) );
2138 DALI_TEST_CHECK( !glEnableDisableStack.FindMethodAndParams( "Disable", GetDepthTestString() ) );
2140 // Change the layer behavior to LAYER_2D.
2141 // Note this will also disable depth testing for the layer by default, we test this first.
2142 Stage::GetCurrent().GetRootLayer().SetBehavior( Layer::LAYER_2D );
2144 glEnableDisableStack.Reset();
2145 application.SendNotification();
2146 application.Render();
2148 // Check depth-test is disabled.
2149 DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Disable", GetDepthTestString() ) );
2151 // Turn the layer depth-test flag back on, and confirm that depth testing is now on.
2152 Stage::GetCurrent().GetRootLayer().SetDepthTestDisabled( false );
2154 glEnableDisableStack.Reset();
2155 application.SendNotification();
2156 application.Render();
2158 // Check depth-test is *still* disabled.
2159 DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Enable", GetDepthTestString() ) );
2164 int UtcDaliRendererSetDepthWriteMode(void)
2166 TestApplication application;
2167 tet_infoline("Test setting the DepthWriteMode");
2169 Renderer renderer = RendererTestFixture( application );
2170 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2172 application.SendNotification();
2173 application.Render();
2175 // Check the default depth-write status first.
2176 DALI_TEST_CHECK( glAbstraction.GetLastDepthMask() );
2178 // Turn off depth-writing.
2179 renderer.SetProperty( Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::OFF );
2181 application.SendNotification();
2182 application.Render();
2184 // Check depth-write is now disabled.
2185 DALI_TEST_CHECK( !glAbstraction.GetLastDepthMask() );
2187 // Test the AUTO mode for depth-writing.
2188 // As our renderer is opaque, depth-testing should be enabled.
2189 renderer.SetProperty( Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::AUTO );
2191 application.SendNotification();
2192 application.Render();
2194 // Check depth-write is now enabled.
2195 DALI_TEST_CHECK( glAbstraction.GetLastDepthMask() );
2197 // Now make the renderer be treated as translucent by enabling blending.
2198 // The AUTO depth-write mode should turn depth-write off in this scenario.
2199 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::ON );
2201 application.SendNotification();
2202 application.Render();
2204 // Check depth-write is now disabled.
2205 DALI_TEST_CHECK( !glAbstraction.GetLastDepthMask() );
2210 int UtcDaliRendererCheckStencilDefaults(void)
2212 TestApplication application;
2213 tet_infoline("Test the stencil defaults");
2215 Renderer renderer = RendererTestFixture( application );
2216 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2217 glAbstraction.EnableEnableDisableCallTrace( true );
2218 glAbstraction.EnableStencilFunctionCallTrace( true );
2219 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2220 TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2222 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2224 // Check the defaults:
2225 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_FUNCTION ).Get<int>() ), static_cast<int>( StencilFunction::ALWAYS ), TEST_LOCATION );
2226 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_FUNCTION_MASK ).Get<int>() ), 0xFF, TEST_LOCATION );
2227 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_FUNCTION_REFERENCE ).Get<int>() ), 0x00, TEST_LOCATION );
2228 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_MASK ).Get<int>() ), 0xFF, TEST_LOCATION );
2229 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_OPERATION_ON_FAIL ).Get<int>() ), static_cast<int>( StencilOperation::KEEP ), TEST_LOCATION );
2230 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 );
2231 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 );
2236 int UtcDaliRendererSetRenderModeToUseStencilBuffer(void)
2238 TestApplication application;
2239 tet_infoline("Test setting the RenderMode to use the stencil buffer");
2241 Renderer renderer = RendererTestFixture( application );
2242 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2243 glAbstraction.EnableEnableDisableCallTrace( true );
2244 glAbstraction.EnableStencilFunctionCallTrace( true );
2245 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2246 TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2248 // Set the StencilFunction to something other than the default, to confirm it is set as a property,
2249 // but NO GL call has been made while the RenderMode is set to not use the stencil buffer.
2250 renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::NONE );
2251 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2253 renderer.SetProperty( Renderer::Property::STENCIL_FUNCTION, StencilFunction::NEVER );
2254 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_FUNCTION ).Get<int>() ), static_cast<int>( StencilFunction::NEVER ), TEST_LOCATION );
2256 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2257 std::string methodString( "StencilFunc" );
2258 DALI_TEST_CHECK( !glStencilFunctionStack.FindMethod( methodString ) );
2260 // Test the other RenderModes that will not enable the stencil buffer.
2261 renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::AUTO );
2262 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2263 DALI_TEST_CHECK( !glStencilFunctionStack.FindMethod( methodString ) );
2265 renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::COLOR );
2266 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2267 DALI_TEST_CHECK( !glStencilFunctionStack.FindMethod( methodString ) );
2269 // Now set the RenderMode to modes that will use the stencil buffer, and check the StencilFunction has changed.
2270 renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::STENCIL );
2271 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2273 DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Enable", GetStencilTestString() ) );
2274 DALI_TEST_CHECK( glStencilFunctionStack.FindMethod( methodString ) );
2276 // Test the COLOR_STENCIL RenderMode as it also enables the stencil buffer.
2277 // First set a mode to turn off the stencil buffer, so the enable is required.
2278 renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::COLOR );
2279 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2280 renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::COLOR_STENCIL );
2281 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2283 DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Enable", GetStencilTestString() ) );
2284 DALI_TEST_CHECK( glStencilFunctionStack.FindMethod( methodString ) );
2289 // Helper function for the SetRenderModeToUseColorBuffer test.
2290 void CheckRenderModeColorMask( TestApplication& application, Renderer& renderer, RenderMode::Type renderMode, bool expectedValue )
2292 // Set the RenderMode property to a value that should not allow color buffer writes.
2293 renderer.SetProperty( Renderer::Property::RENDER_MODE, renderMode );
2294 application.SendNotification();
2295 application.Render();
2297 // Check if ColorMask has been called, and that the values are correct.
2298 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2299 const TestGlAbstraction::ColorMaskParams& colorMaskParams( glAbstraction.GetColorMaskParams() );
2301 DALI_TEST_EQUALS<bool>( colorMaskParams.red, expectedValue, TEST_LOCATION );
2302 DALI_TEST_EQUALS<bool>( colorMaskParams.green, expectedValue, TEST_LOCATION );
2303 DALI_TEST_EQUALS<bool>( colorMaskParams.blue, expectedValue, TEST_LOCATION );
2304 DALI_TEST_EQUALS<bool>( colorMaskParams.alpha, expectedValue, TEST_LOCATION );
2307 int UtcDaliRendererSetRenderModeToUseColorBuffer(void)
2309 TestApplication application;
2310 tet_infoline("Test setting the RenderMode to use the color buffer");
2312 Renderer renderer = RendererTestFixture( application );
2314 // Set the RenderMode property to a value that should not allow color buffer writes.
2315 // Then check if ColorMask has been called, and that the values are correct.
2316 CheckRenderModeColorMask( application, renderer, RenderMode::AUTO, true );
2317 CheckRenderModeColorMask( application, renderer, RenderMode::NONE, false );
2318 CheckRenderModeColorMask( application, renderer, RenderMode::COLOR, true );
2319 CheckRenderModeColorMask( application, renderer, RenderMode::STENCIL, false );
2320 CheckRenderModeColorMask( application, renderer, RenderMode::COLOR_STENCIL, true );
2325 int UtcDaliRendererSetStencilFunction(void)
2327 TestApplication application;
2328 tet_infoline("Test setting the StencilFunction");
2330 Renderer renderer = RendererTestFixture( application );
2331 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2332 glAbstraction.EnableEnableDisableCallTrace( true );
2333 glAbstraction.EnableStencilFunctionCallTrace( true );
2334 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2335 TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2337 // RenderMode must use the stencil for StencilFunction to operate.
2338 renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::STENCIL );
2339 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2342 * Lookup table for testing StencilFunction.
2343 * Note: This MUST be in the same order as the Dali::StencilFunction enum.
2345 const int StencilFunctionLookupTable[] = {
2354 }; const int StencilFunctionLookupTableCount = sizeof( StencilFunctionLookupTable ) / sizeof( StencilFunctionLookupTable[0] );
2357 * Loop through all types of StencilFunction, checking:
2358 * - The value is cached (set in event thread side)
2359 * - Causes "glStencilFunc" to be called
2360 * - Checks the correct parameters to "glStencilFunc" were used
2362 std::string nonChangingParameters = "0, 255";
2363 std::string methodString( "StencilFunc" );
2364 for( int i = 0; i < StencilFunctionLookupTableCount; ++i )
2366 // Set the property.
2367 renderer.SetProperty( Renderer::Property::STENCIL_FUNCTION, static_cast<Dali::StencilFunction::Type>( i ) );
2369 // Check GetProperty returns the same value.
2370 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_FUNCTION ).Get<int>() ), i, TEST_LOCATION );
2372 // Reset the trace debug.
2373 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2375 // Check the function is called and the parameters are correct.
2376 std::stringstream parameterStream;
2377 parameterStream << StencilFunctionLookupTable[ i ] << ", " << nonChangingParameters;
2379 DALI_TEST_CHECK( glStencilFunctionStack.FindMethodAndParams( methodString, parameterStream.str() ) );
2382 // Change the Function Reference only and check the behavior is correct:
2383 // 170 is 0xaa in hex / 10101010 in binary (every other bit set).
2384 int testValueReference = 170;
2385 renderer.SetProperty( Renderer::Property::STENCIL_FUNCTION_REFERENCE, testValueReference );
2387 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_FUNCTION_REFERENCE ).Get<int>() ), testValueReference, TEST_LOCATION );
2389 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2391 std::stringstream parameterStream;
2392 parameterStream << StencilFunctionLookupTable[ StencilOperation::DECREMENT_WRAP ] << ", " << testValueReference << ", 255";
2394 DALI_TEST_CHECK( glStencilFunctionStack.FindMethodAndParams( methodString, parameterStream.str() ) );
2397 // Change the Function Mask only and check the behavior is correct:
2398 // 85 is 0x55 in hex / 01010101 in binary (every other bit set).
2399 int testValueMask = 85;
2400 renderer.SetProperty( Renderer::Property::STENCIL_FUNCTION_MASK, testValueMask );
2402 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_FUNCTION_MASK ).Get<int>() ), testValueMask, TEST_LOCATION );
2404 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2406 // Clear the stringstream.
2407 parameterStream.str( std::string() );
2408 parameterStream << StencilFunctionLookupTable[ StencilOperation::DECREMENT_WRAP ] << ", " << testValueReference << ", " << testValueMask;
2410 DALI_TEST_CHECK( glStencilFunctionStack.FindMethodAndParams( methodString, parameterStream.str() ) );
2415 int UtcDaliRendererSetStencilOperation(void)
2417 TestApplication application;
2418 tet_infoline("Test setting the StencilOperation");
2420 Renderer renderer = RendererTestFixture( application );
2421 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2422 glAbstraction.EnableEnableDisableCallTrace( true );
2423 glAbstraction.EnableStencilFunctionCallTrace( true );
2424 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2425 TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2427 // RenderMode must use the stencil for StencilOperation to operate.
2428 renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::STENCIL );
2431 * Lookup table for testing StencilOperation.
2432 * Note: This MUST be in the same order as the Dali::StencilOperation enum.
2434 const int StencilOperationLookupTable[] = {
2443 }; const int StencilOperationLookupTableCount = sizeof( StencilOperationLookupTable ) / sizeof( StencilOperationLookupTable[0] );
2445 // Set all 3 StencilOperation properties to a default.
2446 renderer.SetProperty( Renderer::Property::STENCIL_OPERATION_ON_FAIL, StencilOperation::ZERO );
2447 renderer.SetProperty( Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, StencilOperation::ZERO );
2448 renderer.SetProperty( Renderer::Property::STENCIL_OPERATION_ON_Z_PASS, StencilOperation::ZERO );
2450 // Set our expected parameter list to the equivalent result.
2451 int parameters[] = { StencilOperationLookupTable[ StencilOperation::ZERO ], StencilOperationLookupTable[ StencilOperation::ZERO ], StencilOperationLookupTable[ StencilOperation::ZERO ] };
2453 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2456 * Loop through all types of StencilOperation, checking:
2457 * - The value is cached (set in event thread side)
2458 * - Causes "glStencilFunc" to be called
2459 * - Checks the correct parameters to "glStencilFunc" were used
2460 * - Checks the above for all 3 parameter placements of StencilOperation ( OnFail, OnZFail, OnPass )
2462 int stencilOperationPropertyKeys[] = { Renderer::Property::STENCIL_OPERATION_ON_FAIL, Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, Renderer::Property::STENCIL_OPERATION_ON_Z_PASS };
2463 std::string methodString( "StencilOp" );
2465 for( int parameterIndex = 0; parameterIndex < 3; ++parameterIndex )
2467 for( int i = 0; i < StencilOperationLookupTableCount; ++i )
2469 // Set the property (outer loop causes all 3 different properties to be set separately).
2470 renderer.SetProperty( stencilOperationPropertyKeys[ parameterIndex ], static_cast<Dali::StencilFunction::Type>( i ) );
2472 // Check GetProperty returns the same value.
2473 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( stencilOperationPropertyKeys[ parameterIndex ] ).Get<int>() ), i, TEST_LOCATION );
2475 // Reset the trace debug.
2476 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2478 // Check the function is called and the parameters are correct.
2479 // Set the expected parameter value at its correct index (only)
2480 parameters[ parameterIndex ] = StencilOperationLookupTable[ i ];
2482 // Build the parameter list.
2483 std::stringstream parameterStream;
2484 for( int parameterBuild = 0; parameterBuild < 3; ++parameterBuild )
2486 parameterStream << parameters[ parameterBuild ];
2487 // Comma-separate the parameters.
2488 if( parameterBuild < 2 )
2490 parameterStream << ", ";
2494 // Check the function was called and the parameters were correct.
2495 DALI_TEST_CHECK( glStencilFunctionStack.FindMethodAndParams( methodString, parameterStream.str() ) );
2502 int UtcDaliRendererSetStencilMask(void)
2504 TestApplication application;
2505 tet_infoline("Test setting the StencilMask");
2507 Renderer renderer = RendererTestFixture( application );
2508 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
2509 glAbstraction.EnableEnableDisableCallTrace( true );
2510 glAbstraction.EnableStencilFunctionCallTrace( true );
2511 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
2512 TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
2514 // RenderMode must use the stencil for StencilMask to operate.
2515 renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::STENCIL );
2517 // Set the StencilMask property to a value.
2518 renderer.SetProperty( Renderer::Property::STENCIL_MASK, 0x00 );
2520 // Check GetProperty returns the same value.
2521 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_MASK ).Get<int>() ), 0x00, TEST_LOCATION );
2523 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2525 std::string methodString( "StencilMask" );
2526 std::string parameterString = "0";
2528 // Check the function was called and the parameters were correct.
2529 DALI_TEST_CHECK( glStencilFunctionStack.FindMethodAndParams( methodString, parameterString ) );
2531 // Set the StencilMask property to another value to ensure it has changed.
2532 renderer.SetProperty( Renderer::Property::STENCIL_MASK, 0xFF );
2534 // Check GetProperty returns the same value.
2535 DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_MASK ).Get<int>() ), 0xFF, TEST_LOCATION );
2537 ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
2539 parameterString = "255";
2541 // Check the function was called and the parameters were correct.
2542 DALI_TEST_CHECK( glStencilFunctionStack.FindMethodAndParams( methodString, parameterString ) );
2547 int UtcDaliRendererWrongNumberOfTextures(void)
2549 TestApplication application;
2550 tet_infoline("Test renderer does render even if number of textures is different than active samplers in the shader");
2552 //Create a TextureSet with 4 textures (One more texture in the texture set than active samplers)
2553 //@note Shaders in the test suit have 3 active samplers. See TestGlAbstraction::GetActiveUniform()
2554 Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, 64u, 64u );
2555 TextureSet textureSet = CreateTextureSet();
2556 textureSet.SetTexture(0, texture );
2557 textureSet.SetTexture(1, texture );
2558 textureSet.SetTexture(2, texture );
2559 textureSet.SetTexture(3, texture );
2560 Shader shader = Shader::New("VertexSource", "FragmentSource");
2561 Geometry geometry = CreateQuadGeometry();
2562 Renderer renderer = Renderer::New( geometry, shader );
2563 renderer.SetTextures( textureSet );
2565 Actor actor= Actor::New();
2566 actor.AddRenderer(renderer);
2567 actor.SetPosition(0.0f,0.0f);
2568 actor.SetSize(100, 100);
2569 Stage::GetCurrent().Add(actor);
2571 TestGlAbstraction& gl = application.GetGlAbstraction();
2572 TraceCallStack& drawTrace = gl.GetDrawTrace();
2574 drawTrace.Enable(true);
2576 application.SendNotification();
2577 application.Render(0);
2579 //Test we do the drawcall when TextureSet has more textures than there are active samplers in the shader
2580 DALI_TEST_EQUALS( drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION );
2582 //Create a TextureSet with 1 texture (two more active samplers than texture in the texture set)
2583 //@note Shaders in the test suit have 3 active samplers. See TestGlAbstraction::GetActiveUniform()
2584 textureSet = CreateTextureSet();
2585 renderer.SetTextures( textureSet );
2586 textureSet.SetTexture(0, texture );
2588 application.SendNotification();
2589 application.Render(0);
2591 //Test we do the drawcall when TextureSet has less textures than there are active samplers in the shader.
2592 DALI_TEST_EQUALS( drawTrace.CountMethod("DrawElements"), 1, TEST_LOCATION );