2 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali/public-api/dali-core.h>
20 #include <dali/devel-api/images/texture-set-image.h>
24 #include <dali-test-suite-utils.h>
25 #include <mesh-builder.h>
29 namespace // unnamed namespace
32 const BlendFactor::Type DEFAULT_BLEND_FACTOR_SRC_RGB( BlendFactor::SRC_ALPHA );
33 const BlendFactor::Type DEFAULT_BLEND_FACTOR_DEST_RGB( BlendFactor::ONE_MINUS_SRC_ALPHA );
34 const BlendFactor::Type DEFAULT_BLEND_FACTOR_SRC_ALPHA( BlendFactor::ONE );
35 const BlendFactor::Type DEFAULT_BLEND_FACTOR_DEST_ALPHA( BlendFactor::ONE_MINUS_SRC_ALPHA );
37 const BlendEquation::Type DEFAULT_BLEND_EQUATION_RGB( BlendEquation::ADD );
38 const BlendEquation::Type DEFAULT_BLEND_EQUATION_ALPHA( BlendEquation::ADD );
40 void TestConstraintNoBlue( Vector4& current, const PropertyInputContainer& inputs )
45 } // unnamed namespace
47 void renderer_test_startup(void)
49 test_return_value = TET_UNDEF;
52 void renderer_test_cleanup(void)
54 test_return_value = TET_PASS;
58 int UtcDaliRendererNew01(void)
60 TestApplication application;
62 Geometry geometry = CreateQuadGeometry();
63 Shader shader = CreateShader();
64 Renderer renderer = Renderer::New(geometry, shader);
66 DALI_TEST_EQUALS( (bool)renderer, true, TEST_LOCATION );
70 int UtcDaliRendererNew02(void)
72 TestApplication application;
74 DALI_TEST_EQUALS( (bool)renderer, false, TEST_LOCATION );
78 int UtcDaliRendererCopyConstructor(void)
80 TestApplication application;
82 Geometry geometry = CreateQuadGeometry();
83 Shader shader = CreateShader();
84 Renderer renderer = Renderer::New(geometry, shader);
86 Renderer rendererCopy( renderer );
87 DALI_TEST_EQUALS( (bool)rendererCopy, true, TEST_LOCATION );
92 int UtcDaliRendererAssignmentOperator(void)
94 TestApplication application;
96 Geometry geometry = CreateQuadGeometry();
97 Shader shader = CreateShader();
98 Renderer renderer = Renderer::New(geometry, shader);
101 DALI_TEST_EQUALS( (bool)renderer2, false, TEST_LOCATION );
103 renderer2 = renderer;
104 DALI_TEST_EQUALS( (bool)renderer2, true, TEST_LOCATION );
108 int UtcDaliRendererDownCast01(void)
110 TestApplication application;
112 Geometry geometry = CreateQuadGeometry();
113 Shader shader = CreateShader();
114 Renderer renderer = Renderer::New(geometry, shader);
116 BaseHandle handle(renderer);
117 Renderer renderer2 = Renderer::DownCast(handle);
118 DALI_TEST_EQUALS( (bool)renderer2, true, TEST_LOCATION );
122 int UtcDaliRendererDownCast02(void)
124 TestApplication application;
126 Handle handle = Handle::New(); // Create a custom object
127 Renderer renderer = Renderer::DownCast(handle);
128 DALI_TEST_EQUALS( (bool)renderer, false, TEST_LOCATION );
132 int UtcDaliRendererSetGetGeometry(void)
134 TestApplication application;
135 tet_infoline( "Test SetGeometry, GetGeometry" );
137 Geometry geometry1 = CreateQuadGeometry();
138 Geometry geometry2 = CreateQuadGeometry();
140 Shader shader = CreateShader();
141 Renderer renderer = Renderer::New(geometry1, shader);
142 Actor actor = Actor::New();
143 actor.AddRenderer(renderer);
144 actor.SetSize(400, 400);
145 Stage::GetCurrent().Add(actor);
147 application.SendNotification();
148 application.Render(0);
149 DALI_TEST_EQUALS( renderer.GetGeometry(), geometry1, TEST_LOCATION );
151 // Set geometry2 to the renderer
152 renderer.SetGeometry( geometry2 );
154 application.SendNotification();
155 application.Render(0);
156 DALI_TEST_EQUALS( renderer.GetGeometry(), geometry2, TEST_LOCATION );
161 int UtcDaliRendererSetGetShader(void)
163 TestApplication application;
164 tet_infoline( "Test SetShader, GetShader" );
166 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
167 glAbstraction.EnableCullFaceCallTrace(true);
169 Shader shader1 = CreateShader();
170 shader1.RegisterProperty( "uFadeColor", Color::RED );
172 Shader shader2 = CreateShader();
173 shader2.RegisterProperty( "uFadeColor", Color::GREEN );
175 Geometry geometry = CreateQuadGeometry();
176 Renderer renderer = Renderer::New(geometry, shader1);
177 Actor actor = Actor::New();
178 actor.AddRenderer(renderer);
179 actor.SetSize(400, 400);
180 Stage::GetCurrent().Add(actor);
182 TestGlAbstraction& gl = application.GetGlAbstraction();
183 application.SendNotification();
184 application.Render(0);
186 // Expect that the first shaders's fade color property is accessed
187 Vector4 actualValue(Vector4::ZERO);
188 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
189 DALI_TEST_EQUALS( actualValue, Color::RED, TEST_LOCATION );
191 DALI_TEST_EQUALS( renderer.GetShader(), shader1, TEST_LOCATION );
193 // set the second shader to the renderer
194 renderer.SetShader( shader2 );
196 application.SendNotification();
197 application.Render(0);
199 // Expect that the second shader's fade color property is accessed
200 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
201 DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
203 DALI_TEST_EQUALS( renderer.GetShader(), shader2, TEST_LOCATION );
208 int UtcDaliRendererSetGetDepthIndex(void)
210 TestApplication application;
212 tet_infoline("Test SetDepthIndex, GetDepthIndex");
214 Shader shader = CreateShader();
215 Geometry geometry = CreateQuadGeometry();
216 Renderer renderer = Renderer::New(geometry, shader);
217 Actor actor = Actor::New();
218 actor.AddRenderer(renderer);
219 actor.SetSize(400, 400);
220 Stage::GetCurrent().Add(actor);
222 application.SendNotification();
223 application.Render(0);
224 DALI_TEST_EQUALS( renderer.GetProperty<int>(Renderer::Property::DEPTH_INDEX), 0, TEST_LOCATION );
226 renderer.SetProperty( Renderer::Property::DEPTH_INDEX, 1 );
228 application.SendNotification();
229 application.Render(0);
230 DALI_TEST_EQUALS( renderer.GetProperty<int>(Renderer::Property::DEPTH_INDEX), 1, TEST_LOCATION );
232 renderer.SetProperty( Renderer::Property::DEPTH_INDEX, 10 );
234 application.SendNotification();
235 application.Render(0);
236 DALI_TEST_EQUALS( renderer.GetProperty<int>(Renderer::Property::DEPTH_INDEX), 10, TEST_LOCATION );
241 int UtcDaliRendererSetGetFaceCullingMode(void)
243 TestApplication application;
245 tet_infoline("Test SetFaceCullingMode(cullingMode)");
246 Geometry geometry = CreateQuadGeometry();
247 Shader shader = CreateShader();
248 Renderer renderer = Renderer::New( geometry, shader );
250 Actor actor = Actor::New();
251 actor.AddRenderer(renderer);
252 actor.SetSize(400, 400);
253 Stage::GetCurrent().Add(actor);
255 // By default, none of the faces should be culled
256 unsigned int cullFace = renderer.GetProperty<int>( Renderer::Property::FACE_CULLING_MODE );
257 DALI_TEST_CHECK( static_cast< FaceCullingMode::Type >( cullFace ) == FaceCullingMode::NONE );
259 TestGlAbstraction& gl = application.GetGlAbstraction();
260 TraceCallStack& cullFaceStack = gl.GetCullFaceTrace();
261 gl.EnableCullFaceCallTrace(true);
264 cullFaceStack.Reset();
265 renderer.SetProperty( Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::FRONT_AND_BACK );
266 application.SendNotification();
267 application.Render();
269 DALI_TEST_EQUALS( cullFaceStack.CountMethod( "CullFace" ), 1, TEST_LOCATION );
271 std::ostringstream cullModeString;
272 cullModeString << GL_FRONT_AND_BACK;
274 DALI_TEST_CHECK( cullFaceStack.FindMethodAndParams( "CullFace", cullModeString.str() ) );
275 cullFace = renderer.GetProperty<int>( Renderer::Property::FACE_CULLING_MODE );
276 DALI_TEST_CHECK( static_cast< FaceCullingMode::Type >( cullFace ) == FaceCullingMode::FRONT_AND_BACK );
280 cullFaceStack.Reset();
281 renderer.SetProperty( Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::BACK );
282 application.SendNotification();
283 application.Render();
285 DALI_TEST_EQUALS( cullFaceStack.CountMethod( "CullFace" ), 1, TEST_LOCATION );
287 std::ostringstream cullModeString;
288 cullModeString << GL_BACK;
290 DALI_TEST_CHECK( cullFaceStack.FindMethodAndParams( "CullFace", cullModeString.str() ) );
291 cullFace = renderer.GetProperty<int>( Renderer::Property::FACE_CULLING_MODE );
292 DALI_TEST_CHECK( static_cast< FaceCullingMode::Type >( cullFace ) == FaceCullingMode::BACK );
296 cullFaceStack.Reset();
297 renderer.SetProperty( Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::FRONT );
298 application.SendNotification();
299 application.Render();
301 DALI_TEST_EQUALS( cullFaceStack.CountMethod( "CullFace" ), 1, TEST_LOCATION );
303 std::ostringstream cullModeString;
304 cullModeString << GL_FRONT;
306 DALI_TEST_CHECK( cullFaceStack.FindMethodAndParams( "CullFace", cullModeString.str() ) );
307 cullFace = renderer.GetProperty<int>( Renderer::Property::FACE_CULLING_MODE );
308 DALI_TEST_CHECK( static_cast< FaceCullingMode::Type >( cullFace ) == FaceCullingMode::FRONT );
312 cullFaceStack.Reset();
313 renderer.SetProperty( Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::NONE );
314 application.SendNotification();
315 application.Render();
317 DALI_TEST_EQUALS( cullFaceStack.CountMethod( "CullFace" ), 0, TEST_LOCATION );
318 cullFace = renderer.GetProperty<int>( Renderer::Property::FACE_CULLING_MODE );
319 DALI_TEST_CHECK( static_cast< FaceCullingMode::Type >( cullFace ) == FaceCullingMode::NONE );
325 int UtcDaliRendererBlendOptions01(void)
327 TestApplication application;
329 tet_infoline("Test BLEND_FACTOR properties ");
331 Geometry geometry = CreateQuadGeometry();
332 Shader shader = CreateShader();
333 Renderer renderer = Renderer::New( geometry, shader );
335 Actor actor = Actor::New();
336 // set a transparent actor color so that blending is enabled
337 actor.SetOpacity( 0.5f );
338 actor.AddRenderer(renderer);
339 actor.SetSize(400, 400);
340 Stage::GetCurrent().Add(actor);
342 renderer.SetProperty( Renderer::Property::BLEND_FACTOR_SRC_RGB, BlendFactor::ONE_MINUS_SRC_COLOR );
343 renderer.SetProperty( Renderer::Property::BLEND_FACTOR_DEST_RGB, BlendFactor::SRC_ALPHA_SATURATE );
344 renderer.SetProperty( Renderer::Property::BLEND_FACTOR_SRC_ALPHA, BlendFactor::ONE_MINUS_SRC_COLOR );
345 renderer.SetProperty( Renderer::Property::BLEND_FACTOR_DEST_ALPHA, BlendFactor::SRC_ALPHA_SATURATE );
347 // Test that Set was successful:
348 int srcFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
349 int destFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
350 int srcFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
351 int destFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
353 DALI_TEST_EQUALS( (int)BlendFactor::ONE_MINUS_SRC_COLOR, srcFactorRgb, TEST_LOCATION );
354 DALI_TEST_EQUALS( (int)BlendFactor::SRC_ALPHA_SATURATE, destFactorRgb, TEST_LOCATION );
355 DALI_TEST_EQUALS( (int)BlendFactor::ONE_MINUS_SRC_COLOR, srcFactorAlpha, TEST_LOCATION );
356 DALI_TEST_EQUALS( (int)BlendFactor::SRC_ALPHA_SATURATE, destFactorAlpha, TEST_LOCATION );
358 application.SendNotification();
359 application.Render();
361 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
363 DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_SRC_COLOR, glAbstraction.GetLastBlendFuncSrcRgb(), TEST_LOCATION );
364 DALI_TEST_EQUALS( (GLenum)GL_SRC_ALPHA_SATURATE, glAbstraction.GetLastBlendFuncDstRgb(), TEST_LOCATION );
365 DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_SRC_COLOR, glAbstraction.GetLastBlendFuncSrcAlpha(), TEST_LOCATION );
366 DALI_TEST_EQUALS( (GLenum)GL_SRC_ALPHA_SATURATE, glAbstraction.GetLastBlendFuncDstAlpha(), TEST_LOCATION );
371 int UtcDaliRendererBlendOptions02(void)
373 TestApplication application;
375 tet_infoline("Test BLEND_FACTOR properties ");
377 Geometry geometry = CreateQuadGeometry();
378 Shader shader = CreateShader();
379 Renderer renderer = Renderer::New( geometry, shader );
381 Actor actor = Actor::New();
382 actor.SetOpacity( 0.5f ); // enable blending
383 actor.AddRenderer(renderer);
384 actor.SetSize(400, 400);
385 Stage::GetCurrent().Add(actor);
387 renderer.SetProperty( Renderer::Property::BLEND_FACTOR_SRC_RGB, BlendFactor::CONSTANT_COLOR );
388 renderer.SetProperty( Renderer::Property::BLEND_FACTOR_DEST_RGB, BlendFactor::ONE_MINUS_CONSTANT_COLOR );
389 renderer.SetProperty( Renderer::Property::BLEND_FACTOR_SRC_ALPHA, BlendFactor::CONSTANT_ALPHA );
390 renderer.SetProperty( Renderer::Property::BLEND_FACTOR_DEST_ALPHA, BlendFactor::ONE_MINUS_CONSTANT_ALPHA );
392 // Test that Set was successful:
394 int srcFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
395 int destFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
396 int srcFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
397 int destFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
399 DALI_TEST_EQUALS( (int)BlendFactor::CONSTANT_COLOR, srcFactorRgb, TEST_LOCATION );
400 DALI_TEST_EQUALS( (int)BlendFactor::ONE_MINUS_CONSTANT_COLOR, destFactorRgb, TEST_LOCATION );
401 DALI_TEST_EQUALS( (int)BlendFactor::CONSTANT_ALPHA, srcFactorAlpha, TEST_LOCATION );
402 DALI_TEST_EQUALS( (int)BlendFactor::ONE_MINUS_CONSTANT_ALPHA, destFactorAlpha, TEST_LOCATION );
405 application.SendNotification();
406 application.Render();
408 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
409 DALI_TEST_EQUALS( (GLenum)GL_CONSTANT_COLOR, glAbstraction.GetLastBlendFuncSrcRgb(), TEST_LOCATION );
410 DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_CONSTANT_COLOR, glAbstraction.GetLastBlendFuncDstRgb(), TEST_LOCATION );
411 DALI_TEST_EQUALS( (GLenum)GL_CONSTANT_ALPHA, glAbstraction.GetLastBlendFuncSrcAlpha(), TEST_LOCATION );
412 DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_CONSTANT_ALPHA, glAbstraction.GetLastBlendFuncDstAlpha(), TEST_LOCATION );
417 int UtcDaliRendererBlendOptions03(void)
419 TestApplication application;
421 tet_infoline("Test GetBlendEquation() defaults ");
423 Geometry geometry = CreateQuadGeometry();
424 Shader shader = CreateShader();
425 Renderer renderer = Renderer::New( geometry, shader );
427 Actor actor = Actor::New();
428 actor.AddRenderer(renderer);
429 actor.SetSize(400, 400);
430 Stage::GetCurrent().Add(actor);
432 // Test the defaults as documented in blending.h
433 int equationRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_EQUATION_RGB );
434 int equationAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_EQUATION_ALPHA );
436 DALI_TEST_EQUALS( (int)BlendEquation::ADD, equationRgb, TEST_LOCATION );
437 DALI_TEST_EQUALS( (int)BlendEquation::ADD, equationAlpha, TEST_LOCATION );
442 int UtcDaliRendererBlendOptions04(void)
444 TestApplication application;
446 tet_infoline("Test SetBlendEquation() ");
448 Geometry geometry = CreateQuadGeometry();
449 Shader shader = CreateShader();
450 Renderer renderer = Renderer::New( geometry, shader );
452 Actor actor = Actor::New();
453 actor.SetOpacity( 0.1f );
454 actor.AddRenderer(renderer);
455 actor.SetSize(400, 400);
456 Stage::GetCurrent().Add(actor);
458 // Test the single blending equation setting
460 renderer.SetProperty( Renderer::Property::BLEND_EQUATION_RGB, BlendEquation::REVERSE_SUBTRACT );
461 int equationRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_EQUATION_RGB );
462 DALI_TEST_EQUALS( (int)BlendEquation::REVERSE_SUBTRACT, equationRgb, TEST_LOCATION );
465 renderer.SetProperty( Renderer::Property::BLEND_EQUATION_RGB, BlendEquation::REVERSE_SUBTRACT );
466 renderer.SetProperty( Renderer::Property::BLEND_EQUATION_ALPHA, BlendEquation::REVERSE_SUBTRACT );
468 // Test that Set was successful
470 int equationRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_EQUATION_RGB );
471 int equationAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_EQUATION_ALPHA );
472 DALI_TEST_EQUALS( (int)BlendEquation::REVERSE_SUBTRACT, equationRgb, TEST_LOCATION );
473 DALI_TEST_EQUALS( (int)BlendEquation::REVERSE_SUBTRACT, equationAlpha, TEST_LOCATION );
476 // Render & check GL commands
477 application.SendNotification();
478 application.Render();
480 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
481 DALI_TEST_EQUALS( (GLenum)GL_FUNC_REVERSE_SUBTRACT, glAbstraction.GetLastBlendEquationRgb(), TEST_LOCATION );
482 DALI_TEST_EQUALS( (GLenum)GL_FUNC_REVERSE_SUBTRACT, glAbstraction.GetLastBlendEquationAlpha(), TEST_LOCATION );
487 int UtcDaliRendererSetBlendMode01(void)
489 TestApplication application;
491 tet_infoline("Test setting the blend mode to on with an opaque color renders with blending enabled");
493 Geometry geometry = CreateQuadGeometry();
494 Shader shader = CreateShader();
495 Renderer renderer = Renderer::New( geometry, shader );
497 Actor actor = Actor::New();
498 actor.SetOpacity( 0.98f );
499 actor.AddRenderer(renderer);
500 actor.SetSize(400, 400);
501 Stage::GetCurrent().Add(actor);
503 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::ON);
505 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
506 glAbstraction.EnableEnableDisableCallTrace(true);
508 application.SendNotification();
509 application.Render();
511 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
512 std::ostringstream blendStr;
513 blendStr << GL_BLEND;
514 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
519 int UtcDaliRendererSetBlendMode02(void)
521 TestApplication application;
523 tet_infoline("Test setting the blend mode to off with a transparent color renders with blending disabled (and not enabled)");
525 Geometry geometry = CreateQuadGeometry();
526 Shader shader = CreateShader();
527 Renderer renderer = Renderer::New( geometry, shader );
529 Actor actor = Actor::New();
530 actor.SetOpacity( 0.15f );
531 actor.AddRenderer(renderer);
532 actor.SetSize(400, 400);
533 Stage::GetCurrent().Add(actor);
535 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::OFF);
537 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
538 glAbstraction.EnableEnableDisableCallTrace(true);
540 application.SendNotification();
541 application.Render();
543 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
544 std::ostringstream blendStr;
545 blendStr << GL_BLEND;
546 DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
551 int UtcDaliRendererSetBlendMode03(void)
553 TestApplication application;
555 tet_infoline("Test setting the blend mode to auto with a transparent color renders with blending enabled");
557 Geometry geometry = CreateQuadGeometry();
558 Shader shader = CreateShader();
559 Renderer renderer = Renderer::New( geometry, shader );
561 Actor actor = Actor::New();
562 actor.SetOpacity( 0.75f );
563 actor.AddRenderer(renderer);
564 actor.SetSize(400, 400);
565 Stage::GetCurrent().Add(actor);
567 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::AUTO);
569 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
570 glAbstraction.EnableEnableDisableCallTrace(true);
572 application.SendNotification();
573 application.Render();
575 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
576 std::ostringstream blendStr;
577 blendStr << GL_BLEND;
578 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
583 int UtcDaliRendererSetBlendMode04(void)
585 TestApplication application;
587 tet_infoline("Test setting the blend mode to auto with an opaque color renders with blending disabled");
589 Geometry geometry = CreateQuadGeometry();
590 Shader shader = CreateShader();
591 Renderer renderer = Renderer::New( geometry, shader );
593 Actor actor = Actor::New();
594 actor.AddRenderer(renderer);
595 actor.SetSize(400, 400);
596 Stage::GetCurrent().Add(actor);
598 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::AUTO);
600 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
601 glAbstraction.EnableEnableDisableCallTrace(true);
603 application.SendNotification();
604 application.Render();
606 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
607 std::ostringstream blendStr;
608 blendStr << GL_BLEND;
609 DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
614 int UtcDaliRendererSetBlendMode04b(void)
616 TestApplication application;
618 tet_infoline("Test setting the blend mode to auto with a transparent actor color renders with blending enabled");
620 Geometry geometry = CreateQuadGeometry();
621 Shader shader = CreateShader();
622 Renderer renderer = Renderer::New( geometry, shader );
624 Actor actor = Actor::New();
625 actor.AddRenderer(renderer);
626 actor.SetSize(400, 400);
627 actor.SetColor( Vector4(1.0f, 0.0f, 1.0f, 0.5f) );
628 Stage::GetCurrent().Add(actor);
630 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::AUTO);
632 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
633 glAbstraction.EnableEnableDisableCallTrace(true);
635 application.SendNotification();
636 application.Render();
638 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
639 std::ostringstream blendStr;
640 blendStr << GL_BLEND;
641 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
646 int UtcDaliRendererSetBlendMode04c(void)
648 TestApplication application;
650 tet_infoline("Test setting the blend mode to auto with an opaque opaque actor color renders with blending disabled");
652 Geometry geometry = CreateQuadGeometry();
653 Shader shader = CreateShader();
654 Renderer renderer = Renderer::New( geometry, shader );
656 Actor actor = Actor::New();
657 actor.AddRenderer(renderer);
658 actor.SetSize(400, 400);
659 actor.SetColor( Color::MAGENTA );
660 Stage::GetCurrent().Add(actor);
662 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::AUTO);
664 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
665 glAbstraction.EnableEnableDisableCallTrace(true);
667 application.SendNotification();
668 application.Render();
670 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
671 std::ostringstream blendStr;
672 blendStr << GL_BLEND;
673 DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
678 int UtcDaliRendererSetBlendMode05(void)
680 TestApplication application;
682 tet_infoline("Test setting the blend mode to auto with an opaque color and an image with an alpha channel renders with blending enabled");
684 Geometry geometry = CreateQuadGeometry();
685 BufferImage image = BufferImage::New( 40, 40, Pixel::RGBA8888 );
687 Shader shader = CreateShader();
688 TextureSet textureSet = CreateTextureSet( image );
689 Renderer renderer = Renderer::New( geometry, shader );
690 renderer.SetTextures( textureSet );
692 Actor actor = Actor::New();
693 actor.AddRenderer(renderer);
694 actor.SetSize(400, 400);
695 Stage::GetCurrent().Add(actor);
697 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::AUTO);
699 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
700 glAbstraction.EnableEnableDisableCallTrace(true);
702 application.SendNotification();
703 application.Render();
705 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
706 std::ostringstream blendStr;
707 blendStr << GL_BLEND;
708 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
713 int UtcDaliRendererSetBlendMode06(void)
715 TestApplication application;
716 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");
718 Geometry geometry = CreateQuadGeometry();
719 Shader shader = Shader::New( "vertexSrc", "fragmentSrc", Shader::HINT_OUTPUT_IS_TRANSPARENT );
721 Renderer renderer = Renderer::New( geometry, shader );
723 Actor actor = Actor::New();
724 actor.AddRenderer(renderer);
725 actor.SetSize(400, 400);
726 Stage::GetCurrent().Add(actor);
728 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::AUTO);
730 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
731 glAbstraction.EnableEnableDisableCallTrace(true);
733 application.SendNotification();
734 application.Render();
736 TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace();
737 std::ostringstream blendStr;
738 blendStr << GL_BLEND;
739 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
744 int UtcDaliRendererSetBlendMode07(void)
746 TestApplication application;
747 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");
749 Geometry geometry = CreateQuadGeometry();
750 Shader shader = Shader::New( "vertexSrc", "fragmentSrc" );
752 BufferImage image = BufferImage::New( 50, 50, Pixel::RGB888 );
753 TextureSet textureSet = CreateTextureSet( image );
754 Renderer renderer = Renderer::New( geometry, shader );
755 renderer.SetTextures( textureSet );
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 DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", "GL_BLEND" ) );
776 int UtcDaliRendererGetBlendMode(void)
778 TestApplication application;
780 tet_infoline("Test GetBlendMode()");
782 Geometry geometry = CreateQuadGeometry();
783 Shader shader = Shader::New( "vertexSrc", "fragmentSrc" );
784 Renderer renderer = Renderer::New( geometry, shader );
787 unsigned int mode = renderer.GetProperty<int>( Renderer::Property::BLEND_MODE );
788 DALI_TEST_EQUALS( static_cast< BlendMode::Type >( mode ), BlendMode::AUTO, TEST_LOCATION );
791 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::ON );
792 mode = renderer.GetProperty<int>( Renderer::Property::BLEND_MODE );
793 DALI_TEST_EQUALS( static_cast< BlendMode::Type >( mode ), BlendMode::ON, TEST_LOCATION );
796 renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::OFF );
797 mode = renderer.GetProperty<int>( Renderer::Property::BLEND_MODE );
798 DALI_TEST_EQUALS( static_cast< BlendMode::Type >( mode ), BlendMode::OFF, TEST_LOCATION );
803 int UtcDaliRendererSetBlendColor(void)
805 TestApplication application;
807 tet_infoline("Test SetBlendColor(color)");
809 Geometry geometry = CreateQuadGeometry();
810 Shader shader = Shader::New( "vertexSrc", "fragmentSrc" );
811 TextureSet textureSet = TextureSet::New();
812 BufferImage image = BufferImage::New( 50, 50, Pixel::RGBA8888 );
813 TextureSetImage( textureSet, 0u, image );
814 Renderer renderer = Renderer::New( geometry, shader );
815 renderer.SetTextures( textureSet );
817 Actor actor = Actor::New();
818 actor.AddRenderer(renderer);
819 actor.SetSize(400, 400);
820 Stage::GetCurrent().Add(actor);
822 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
824 renderer.SetProperty( Renderer::Property::BLEND_COLOR, Color::TRANSPARENT );
825 application.SendNotification();
826 application.Render();
827 DALI_TEST_EQUALS( glAbstraction.GetLastBlendColor(), Color::TRANSPARENT, TEST_LOCATION );
829 renderer.SetProperty( Renderer::Property::BLEND_COLOR, Color::MAGENTA );
830 application.SendNotification();
831 application.Render();
832 DALI_TEST_EQUALS( glAbstraction.GetLastBlendColor(), Color::MAGENTA, TEST_LOCATION );
834 Vector4 color( 0.1f, 0.2f, 0.3f, 0.4f );
835 renderer.SetProperty( Renderer::Property::BLEND_COLOR, color );
836 application.SendNotification();
837 application.Render();
838 DALI_TEST_EQUALS( glAbstraction.GetLastBlendColor(), color, TEST_LOCATION );
843 int UtcDaliRendererGetBlendColor(void)
845 TestApplication application;
847 tet_infoline("Test GetBlendColor()");
849 Geometry geometry = CreateQuadGeometry();
850 Shader shader = Shader::New( "vertexSrc", "fragmentSrc" );
851 Renderer renderer = Renderer::New( geometry, shader );
853 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>( Renderer::Property::BLEND_COLOR ), Color::TRANSPARENT, TEST_LOCATION );
855 renderer.SetProperty( Renderer::Property::BLEND_COLOR, Color::MAGENTA );
856 application.SendNotification();
857 application.Render();
858 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>( Renderer::Property::BLEND_COLOR ), Color::MAGENTA, TEST_LOCATION );
860 Vector4 color( 0.1f, 0.2f, 0.3f, 0.4f );
861 renderer.SetProperty( Renderer::Property::BLEND_COLOR, color );
862 application.SendNotification();
863 application.Render();
864 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>( Renderer::Property::BLEND_COLOR ), color, TEST_LOCATION );
869 int UtcDaliRendererPreMultipledAlpha(void)
871 TestApplication application;
873 tet_infoline("Test BLEND_PRE_MULTIPLIED_ALPHA property");
875 Geometry geometry = CreateQuadGeometry();
876 Shader shader = Shader::New( "vertexSrc", "fragmentSrc" );
877 Renderer renderer = Renderer::New( geometry, shader );
879 Actor actor = Actor::New();
880 actor.AddRenderer(renderer);
881 actor.SetSize(400, 400);
882 actor.SetColor( Vector4(1.0f, 0.0f, 1.0f, 0.5f) );
883 Stage::GetCurrent().Add(actor);
885 Property::Value value = renderer.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
886 bool preMultipliedAlpha;
887 DALI_TEST_CHECK( value.Get( preMultipliedAlpha ) );
888 DALI_TEST_CHECK( !preMultipliedAlpha );
890 int srcFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
891 int destFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
892 int srcFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
893 int destFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
895 DALI_TEST_EQUALS( (int)DEFAULT_BLEND_FACTOR_SRC_RGB, srcFactorRgb, TEST_LOCATION );
896 DALI_TEST_EQUALS( (int)DEFAULT_BLEND_FACTOR_DEST_RGB, destFactorRgb, TEST_LOCATION );
897 DALI_TEST_EQUALS( (int)DEFAULT_BLEND_FACTOR_SRC_ALPHA, srcFactorAlpha, TEST_LOCATION );
898 DALI_TEST_EQUALS( (int)DEFAULT_BLEND_FACTOR_DEST_ALPHA, destFactorAlpha, TEST_LOCATION );
900 application.SendNotification();
901 application.Render();
903 Vector4 actualValue(Vector4::ZERO);
904 TestGlAbstraction& gl = application.GetGlAbstraction();
905 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uColor", actualValue ) );
906 DALI_TEST_EQUALS( actualValue, Vector4(1.0f, 0.0f, 1.0f, 0.5f), TEST_LOCATION );
908 renderer.SetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, true);
910 application.SendNotification();
911 application.Render();
913 value = renderer.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
914 DALI_TEST_CHECK( value.Get( preMultipliedAlpha ) );
915 DALI_TEST_CHECK( preMultipliedAlpha );
917 srcFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
918 destFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
919 srcFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
920 destFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
922 DALI_TEST_EQUALS( (int)BlendFactor::ONE, srcFactorRgb, TEST_LOCATION );
923 DALI_TEST_EQUALS( (int)BlendFactor::ONE_MINUS_SRC_ALPHA, destFactorRgb, TEST_LOCATION );
924 DALI_TEST_EQUALS( (int)BlendFactor::ONE, srcFactorAlpha, TEST_LOCATION );
925 DALI_TEST_EQUALS( (int)BlendFactor::ONE, destFactorAlpha, TEST_LOCATION );
927 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uColor", actualValue ) );
928 DALI_TEST_EQUALS( actualValue, Vector4(0.5f, 0.0f, 0.5f, 0.5f), TEST_LOCATION );
933 int UtcDaliRendererConstraint01(void)
935 TestApplication application;
937 tet_infoline("Test that a non-uniform renderer property can be constrained");
939 Shader shader = Shader::New("VertexSource", "FragmentSource");
940 Geometry geometry = CreateQuadGeometry();
941 Renderer renderer = Renderer::New( geometry, shader );
943 Actor actor = Actor::New();
944 actor.AddRenderer(renderer);
945 actor.SetSize(400, 400);
946 Stage::GetCurrent().Add(actor);
948 Vector4 initialColor = Color::WHITE;
949 Property::Index colorIndex = renderer.RegisterProperty( "uFadeColor", initialColor );
951 application.SendNotification();
952 application.Render(0);
953 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION );
956 Constraint constraint = Constraint::New<Vector4>( renderer, colorIndex, TestConstraintNoBlue );
958 application.SendNotification();
959 application.Render(0);
961 // Expect no blue component in either buffer - yellow
962 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(colorIndex), Color::YELLOW, TEST_LOCATION );
963 application.Render(0);
964 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(colorIndex), Color::YELLOW, TEST_LOCATION );
966 renderer.RemoveConstraints();
967 renderer.SetProperty(colorIndex, Color::WHITE );
968 application.SendNotification();
969 application.Render(0);
970 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(colorIndex), Color::WHITE, TEST_LOCATION );
975 int UtcDaliRendererConstraint02(void)
977 TestApplication application;
979 tet_infoline("Test that a uniform map renderer property can be constrained");
981 Shader shader = Shader::New("VertexSource", "FragmentSource");
982 Geometry geometry = CreateQuadGeometry();
983 Renderer renderer = Renderer::New( geometry, shader );
985 Actor actor = Actor::New();
986 actor.AddRenderer(renderer);
987 actor.SetSize(400, 400);
988 Stage::GetCurrent().Add(actor);
989 application.SendNotification();
990 application.Render(0);
992 Vector4 initialColor = Color::WHITE;
993 Property::Index colorIndex = renderer.RegisterProperty( "uFadeColor", initialColor );
995 TestGlAbstraction& gl = application.GetGlAbstraction();
997 application.SendNotification();
998 application.Render(0);
1000 Vector4 actualValue(Vector4::ZERO);
1001 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1002 DALI_TEST_EQUALS( actualValue, initialColor, TEST_LOCATION );
1005 Constraint constraint = Constraint::New<Vector4>( renderer, colorIndex, TestConstraintNoBlue );
1007 application.SendNotification();
1008 application.Render(0);
1010 // Expect no blue component in either buffer - yellow
1011 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1012 DALI_TEST_EQUALS( actualValue, Color::YELLOW, TEST_LOCATION );
1014 application.Render(0);
1015 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1016 DALI_TEST_EQUALS( actualValue, Color::YELLOW, TEST_LOCATION );
1018 renderer.RemoveConstraints();
1019 renderer.SetProperty(colorIndex, Color::WHITE );
1020 application.SendNotification();
1021 application.Render(0);
1023 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1024 DALI_TEST_EQUALS( actualValue, Color::WHITE, TEST_LOCATION );
1031 int UtcDaliRendererAnimatedProperty01(void)
1033 TestApplication application;
1035 tet_infoline("Test that a non-uniform renderer property can be animated");
1037 Shader shader = Shader::New("VertexSource", "FragmentSource");
1038 Geometry geometry = CreateQuadGeometry();
1039 Renderer renderer = Renderer::New( geometry, shader );
1041 Actor actor = Actor::New();
1042 actor.AddRenderer(renderer);
1043 actor.SetSize(400, 400);
1044 Stage::GetCurrent().Add(actor);
1046 Vector4 initialColor = Color::WHITE;
1047 Property::Index colorIndex = renderer.RegisterProperty( "uFadeColor", initialColor );
1049 application.SendNotification();
1050 application.Render(0);
1051 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION );
1053 Animation animation = Animation::New(1.0f);
1054 KeyFrames keyFrames = KeyFrames::New();
1055 keyFrames.Add(0.0f, initialColor);
1056 keyFrames.Add(1.0f, Color::TRANSPARENT);
1057 animation.AnimateBetween( Property( renderer, colorIndex ), keyFrames );
1060 application.SendNotification();
1061 application.Render(500);
1063 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(colorIndex), Color::WHITE * 0.5f, TEST_LOCATION );
1065 application.Render(500);
1067 DALI_TEST_EQUALS( renderer.GetProperty<Vector4>(colorIndex), Color::TRANSPARENT, TEST_LOCATION );
1072 int UtcDaliRendererAnimatedProperty02(void)
1074 TestApplication application;
1076 tet_infoline("Test that a uniform map renderer property can be animated");
1078 Shader shader = Shader::New("VertexSource", "FragmentSource");
1079 Geometry geometry = CreateQuadGeometry();
1080 Renderer renderer = Renderer::New( geometry, shader );
1082 Actor actor = Actor::New();
1083 actor.AddRenderer(renderer);
1084 actor.SetSize(400, 400);
1085 Stage::GetCurrent().Add(actor);
1086 application.SendNotification();
1087 application.Render(0);
1089 Vector4 initialColor = Color::WHITE;
1090 Property::Index colorIndex = renderer.RegisterProperty( "uFadeColor", initialColor );
1092 TestGlAbstraction& gl = application.GetGlAbstraction();
1094 application.SendNotification();
1095 application.Render(0);
1097 Vector4 actualValue(Vector4::ZERO);
1098 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1099 DALI_TEST_EQUALS( actualValue, initialColor, TEST_LOCATION );
1101 Animation animation = Animation::New(1.0f);
1102 KeyFrames keyFrames = KeyFrames::New();
1103 keyFrames.Add(0.0f, initialColor);
1104 keyFrames.Add(1.0f, Color::TRANSPARENT);
1105 animation.AnimateBetween( Property( renderer, colorIndex ), keyFrames );
1108 application.SendNotification();
1109 application.Render(500);
1111 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1112 DALI_TEST_EQUALS( actualValue, Color::WHITE * 0.5f, TEST_LOCATION );
1114 application.Render(500);
1115 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1116 DALI_TEST_EQUALS( actualValue, Color::TRANSPARENT, TEST_LOCATION );
1121 int UtcDaliRendererUniformMapPrecendence01(void)
1123 TestApplication application;
1125 tet_infoline("Test the uniform map precedence is applied properly");
1127 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1129 Shader shader = Shader::New("VertexSource", "FragmentSource");
1130 TextureSet textureSet = CreateTextureSet( image );
1132 Geometry geometry = CreateQuadGeometry();
1133 Renderer renderer = Renderer::New( geometry, shader );
1134 renderer.SetTextures( textureSet );
1136 Actor actor = Actor::New();
1137 actor.AddRenderer(renderer);
1138 actor.SetSize(400, 400);
1139 Stage::GetCurrent().Add(actor);
1140 application.SendNotification();
1141 application.Render(0);
1143 renderer.RegisterProperty( "uFadeColor", Color::RED );
1144 actor.RegisterProperty( "uFadeColor", Color::GREEN );
1145 Property::Index shaderFadeColorIndex = shader.RegisterProperty( "uFadeColor", Color::MAGENTA );
1147 TestGlAbstraction& gl = application.GetGlAbstraction();
1149 application.SendNotification();
1150 application.Render(0);
1152 // Expect that the actor's fade color property is accessed
1153 Vector4 actualValue(Vector4::ZERO);
1154 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1155 DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
1157 // Animate shader's fade color property. Should be no change to uniform
1158 Animation animation = Animation::New(1.0f);
1159 KeyFrames keyFrames = KeyFrames::New();
1160 keyFrames.Add(0.0f, Color::WHITE);
1161 keyFrames.Add(1.0f, Color::TRANSPARENT);
1162 animation.AnimateBetween( Property( shader, shaderFadeColorIndex ), keyFrames );
1165 application.SendNotification();
1166 application.Render(500);
1168 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1169 DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
1171 application.Render(500);
1172 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1173 DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
1178 int UtcDaliRendererUniformMapPrecendence02(void)
1180 TestApplication application;
1182 tet_infoline("Test the uniform map precedence is applied properly");
1184 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1186 Shader shader = Shader::New("VertexSource", "FragmentSource");
1187 TextureSet textureSet = CreateTextureSet( image );
1189 Geometry geometry = CreateQuadGeometry();
1190 Renderer renderer = Renderer::New( geometry, shader );
1191 renderer.SetTextures( textureSet );
1193 Actor actor = Actor::New();
1194 actor.AddRenderer(renderer);
1195 actor.SetSize(400, 400);
1196 Stage::GetCurrent().Add(actor);
1197 application.SendNotification();
1198 application.Render(0);
1200 // Don't add property / uniform map to renderer
1201 actor.RegisterProperty( "uFadeColor", Color::GREEN );
1202 Property::Index shaderFadeColorIndex = shader.RegisterProperty( "uFadeColor", Color::BLUE );
1204 TestGlAbstraction& gl = application.GetGlAbstraction();
1206 application.SendNotification();
1207 application.Render(0);
1209 // Expect that the actor's fade color property is accessed
1210 Vector4 actualValue(Vector4::ZERO);
1211 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1212 DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
1214 // Animate texture set's fade color property. Should be no change to uniform
1215 Animation animation = Animation::New(1.0f);
1216 KeyFrames keyFrames = KeyFrames::New();
1217 keyFrames.Add(0.0f, Color::WHITE);
1218 keyFrames.Add(1.0f, Color::TRANSPARENT);
1219 animation.AnimateBetween( Property( shader, shaderFadeColorIndex ), keyFrames );
1222 application.SendNotification();
1223 application.Render(500);
1225 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1226 DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
1228 application.Render(500);
1229 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1230 DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
1236 int UtcDaliRendererUniformMapPrecendence03(void)
1238 TestApplication application;
1240 tet_infoline("Test the uniform map precedence is applied properly");
1242 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1244 Shader shader = Shader::New("VertexSource", "FragmentSource");
1245 TextureSet textureSet = CreateTextureSet( image );
1247 Geometry geometry = CreateQuadGeometry();
1248 Renderer renderer = Renderer::New( geometry, shader );
1249 renderer.SetTextures( textureSet );
1251 Actor actor = Actor::New();
1252 actor.AddRenderer(renderer);
1253 actor.SetSize(400, 400);
1254 Stage::GetCurrent().Add(actor);
1255 application.SendNotification();
1256 application.Render(0);
1258 // Don't add property / uniform map to renderer or actor
1259 shader.RegisterProperty( "uFadeColor", Color::BLACK );
1261 TestGlAbstraction& gl = application.GetGlAbstraction();
1263 application.SendNotification();
1264 application.Render(0);
1266 // Expect that the shader's fade color property is accessed
1267 Vector4 actualValue(Vector4::ZERO);
1268 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1269 DALI_TEST_EQUALS( actualValue, Color::BLACK, TEST_LOCATION );
1274 int UtcDaliRendererUniformMapMultipleUniforms01(void)
1276 TestApplication application;
1278 tet_infoline("Test the uniform maps are collected from all objects (same type)");
1280 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1282 Shader shader = Shader::New("VertexSource", "FragmentSource");
1283 TextureSet textureSet = CreateTextureSet( image );
1285 Geometry geometry = CreateQuadGeometry();
1286 Renderer renderer = Renderer::New( geometry, shader );
1287 renderer.SetTextures( textureSet );
1289 Actor actor = Actor::New();
1290 actor.AddRenderer(renderer);
1291 actor.SetSize(400, 400);
1292 Stage::GetCurrent().Add(actor);
1293 application.SendNotification();
1294 application.Render(0);
1296 renderer.RegisterProperty( "uUniform1", Color::RED );
1297 actor.RegisterProperty( "uUniform2", Color::GREEN );
1298 shader.RegisterProperty( "uUniform3", Color::MAGENTA );
1300 TestGlAbstraction& gl = application.GetGlAbstraction();
1302 application.SendNotification();
1303 application.Render(0);
1305 // Expect that each of the object's uniforms are set
1306 Vector4 uniform1Value(Vector4::ZERO);
1307 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uUniform1", uniform1Value ) );
1308 DALI_TEST_EQUALS( uniform1Value, Color::RED, TEST_LOCATION );
1310 Vector4 uniform2Value(Vector4::ZERO);
1311 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uUniform2", uniform2Value ) );
1312 DALI_TEST_EQUALS( uniform2Value, Color::GREEN, TEST_LOCATION );
1314 Vector4 uniform3Value(Vector4::ZERO);
1315 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uUniform3", uniform3Value ) );
1316 DALI_TEST_EQUALS( uniform3Value, Color::MAGENTA, TEST_LOCATION );
1321 int UtcDaliRendererUniformMapMultipleUniforms02(void)
1323 TestApplication application;
1325 tet_infoline("Test the uniform maps are collected from all objects (different types)");
1327 Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
1329 Shader shader = Shader::New("VertexSource", "FragmentSource");
1330 TextureSet textureSet = CreateTextureSet( image );
1332 Geometry geometry = CreateQuadGeometry();
1333 Renderer renderer = Renderer::New( geometry, shader );
1334 renderer.SetTextures( textureSet );
1336 Actor actor = Actor::New();
1337 actor.AddRenderer(renderer);
1338 actor.SetSize(400, 400);
1339 Stage::GetCurrent().Add(actor);
1340 application.SendNotification();
1341 application.Render(0);
1343 Property::Value value1(Color::RED);
1344 renderer.RegisterProperty( "uFadeColor", value1 );
1346 Property::Value value2(1.0f);
1347 actor.RegisterProperty( "uFadeProgress", value2 );
1349 Property::Value value3(Matrix3::IDENTITY);
1350 shader.RegisterProperty( "uANormalMatrix", value3 );
1352 TestGlAbstraction& gl = application.GetGlAbstraction();
1354 application.SendNotification();
1355 application.Render(0);
1357 // Expect that each of the object's uniforms are set
1358 Vector4 uniform1Value(Vector4::ZERO);
1359 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", uniform1Value ) );
1360 DALI_TEST_EQUALS( uniform1Value, value1.Get<Vector4>(), TEST_LOCATION );
1362 float uniform2Value(0.0f);
1363 DALI_TEST_CHECK( gl.GetUniformValue<float>( "uFadeProgress", uniform2Value ) );
1364 DALI_TEST_EQUALS( uniform2Value, value2.Get<float>(), TEST_LOCATION );
1366 Matrix3 uniform3Value;
1367 DALI_TEST_CHECK( gl.GetUniformValue<Matrix3>( "uANormalMatrix", uniform3Value ) );
1368 DALI_TEST_EQUALS( uniform3Value, value3.Get<Matrix3>(), TEST_LOCATION );
1374 int UtcDaliRendererRenderOrder2DLayer(void)
1376 TestApplication application;
1377 tet_infoline("Test the rendering order in a 2D layer is correct");
1379 Shader shader = Shader::New("VertexSource", "FragmentSource");
1380 Geometry geometry = CreateQuadGeometry();
1382 Actor actor0 = Actor::New();
1383 actor0.SetAnchorPoint(AnchorPoint::CENTER);
1384 actor0.SetParentOrigin(AnchorPoint::CENTER);
1385 actor0.SetPosition(0.0f,0.0f);
1386 Image image0 = BufferImage::New( 64, 64, Pixel::RGB888 );
1387 TextureSet textureSet0 = CreateTextureSet( image0 );
1388 Renderer renderer0 = Renderer::New( geometry, shader );
1389 renderer0.SetTextures( textureSet0 );
1390 actor0.AddRenderer(renderer0);
1391 actor0.SetSize(1, 1);
1392 Stage::GetCurrent().Add(actor0);
1393 application.SendNotification();
1394 application.Render(0);
1396 Actor actor1 = Actor::New();
1397 actor1.SetAnchorPoint(AnchorPoint::CENTER);
1398 actor1.SetParentOrigin(AnchorPoint::CENTER);
1399 actor1.SetPosition(0.0f,0.0f);
1400 Image image1= BufferImage::New( 64, 64, Pixel::RGB888 );
1401 TextureSet textureSet1 = CreateTextureSet( image1 );
1402 Renderer renderer1 = Renderer::New( geometry, shader );
1403 renderer1.SetTextures( textureSet1 );
1404 actor1.AddRenderer(renderer1);
1405 actor1.SetSize(1, 1);
1406 Stage::GetCurrent().Add(actor1);
1407 application.SendNotification();
1408 application.Render(0);
1410 Actor actor2 = Actor::New();
1411 actor2.SetAnchorPoint(AnchorPoint::CENTER);
1412 actor2.SetParentOrigin(AnchorPoint::CENTER);
1413 actor2.SetPosition(0.0f,0.0f);
1414 Image image2= BufferImage::New( 64, 64, Pixel::RGB888 );
1415 TextureSet textureSet2 = CreateTextureSet( image2 );
1416 Renderer renderer2 = Renderer::New( geometry, shader );
1417 renderer2.SetTextures( textureSet2 );
1418 actor2.AddRenderer(renderer2);
1419 actor2.SetSize(1, 1);
1420 Stage::GetCurrent().Add(actor2);
1421 application.SendNotification();
1422 application.Render(0);
1424 Actor actor3 = Actor::New();
1425 actor3.SetAnchorPoint(AnchorPoint::CENTER);
1426 actor3.SetParentOrigin(AnchorPoint::CENTER);
1427 actor3.SetPosition(0.0f,0.0f);
1428 Image image3 = BufferImage::New( 64, 64, Pixel::RGB888 );
1429 TextureSet textureSet3 = CreateTextureSet( image3 );
1430 Renderer renderer3 = Renderer::New( geometry, shader );
1431 renderer3.SetTextures( textureSet3 );
1432 actor3.AddRenderer(renderer3);
1433 actor3.SetSize(1, 1);
1434 Stage::GetCurrent().Add(actor3);
1435 application.SendNotification();
1436 application.Render(0);
1439 * Create the following hierarchy:
1452 * Expected rendering order : actor2 - actor1 - actor0 - actor3
1457 application.SendNotification();
1458 application.Render(0);
1460 TestGlAbstraction& gl = application.GetGlAbstraction();
1461 gl.EnableTextureCallTrace(true);
1462 application.SendNotification();
1463 application.Render(0);
1465 int textureBindIndex[4];
1466 for( unsigned int i(0); i<4; ++i )
1468 std::stringstream params;
1469 params << GL_TEXTURE_2D<<", "<<i+1;
1470 textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str() );
1473 //Check that actor1 has been rendered after actor2
1474 DALI_TEST_GREATER( textureBindIndex[1], textureBindIndex[2], TEST_LOCATION );
1476 //Check that actor0 has been rendered after actor1
1477 DALI_TEST_GREATER( textureBindIndex[0], textureBindIndex[1], TEST_LOCATION );
1479 //Check that actor3 has been rendered after actor0
1480 DALI_TEST_GREATER( textureBindIndex[3], textureBindIndex[0], TEST_LOCATION );
1485 int UtcDaliRendererRenderOrder2DLayerMultipleRenderers(void)
1487 TestApplication application;
1488 tet_infoline("Test the rendering order in a 2D layer is correct using multiple renderers per actor");
1491 * Creates the following hierarchy:
1493 * actor0------------------------>actor1
1497 * renderer0 renderer1 renderer2 renderer3 renderer4 renderer5
1499 * renderer0 has depth index 2
1500 * renderer1 has depth index 0
1501 * renderer2 has depth index 1
1503 * renderer3 has depth index 1
1504 * renderer4 has depth index 0
1505 * renderer5 has depth index -1
1507 * Expected rendering order: renderer1 - renderer2 - renderer0 - renderer5 - renderer4 - renderer3
1510 Shader shader = Shader::New("VertexSource", "FragmentSource");
1511 Geometry geometry = CreateQuadGeometry();
1513 Actor actor0 = Actor::New();
1514 actor0.SetAnchorPoint(AnchorPoint::CENTER);
1515 actor0.SetParentOrigin(AnchorPoint::CENTER);
1516 actor0.SetPosition(0.0f,0.0f);
1517 actor0.SetSize(1, 1);
1518 Stage::GetCurrent().Add(actor0);
1520 Actor actor1 = Actor::New();
1521 actor1.SetAnchorPoint(AnchorPoint::CENTER);
1522 actor1.SetParentOrigin(AnchorPoint::CENTER);
1523 actor1.SetPosition(0.0f,0.0f);
1524 actor1.SetSize(1, 1);
1528 Image image0 = BufferImage::New( 64, 64, Pixel::RGB888 );
1529 TextureSet textureSet0 = CreateTextureSet( image0 );
1530 Renderer renderer0 = Renderer::New( geometry, shader );
1531 renderer0.SetTextures( textureSet0 );
1532 renderer0.SetProperty( Renderer::Property::DEPTH_INDEX, 2 );
1533 actor0.AddRenderer(renderer0);
1534 application.SendNotification();
1535 application.Render(0);
1538 Image image1= BufferImage::New( 64, 64, Pixel::RGB888 );
1539 TextureSet textureSet1 = CreateTextureSet( image1 );
1540 Renderer renderer1 = Renderer::New( geometry, shader );
1541 renderer1.SetTextures( textureSet1 );
1542 renderer1.SetProperty( Renderer::Property::DEPTH_INDEX, 0 );
1543 actor0.AddRenderer(renderer1);
1544 application.SendNotification();
1545 application.Render(0);
1548 Image image2= BufferImage::New( 64, 64, Pixel::RGB888 );
1549 TextureSet textureSet2 = CreateTextureSet( image2 );
1550 Renderer renderer2 = Renderer::New( geometry, shader );
1551 renderer2.SetTextures( textureSet2 );
1552 renderer2.SetProperty( Renderer::Property::DEPTH_INDEX, 1 );
1553 actor0.AddRenderer(renderer2);
1554 application.SendNotification();
1555 application.Render(0);
1558 Image image3 = BufferImage::New( 64, 64, Pixel::RGB888 );
1559 TextureSet textureSet3 = CreateTextureSet( image3 );
1560 Renderer renderer3 = Renderer::New( geometry, shader );
1561 renderer3.SetTextures( textureSet3 );
1562 renderer3.SetProperty( Renderer::Property::DEPTH_INDEX, 1 );
1563 actor1.AddRenderer(renderer3);
1564 application.SendNotification();
1565 application.Render(0);
1568 Image image4= BufferImage::New( 64, 64, Pixel::RGB888 );
1569 TextureSet textureSet4 = CreateTextureSet( image4 );
1570 Renderer renderer4 = Renderer::New( geometry, shader );
1571 renderer4.SetTextures( textureSet4 );
1572 renderer4.SetProperty( Renderer::Property::DEPTH_INDEX, 0 );
1573 actor1.AddRenderer(renderer4);
1574 application.SendNotification();
1575 application.Render(0);
1578 Image image5= BufferImage::New( 64, 64, Pixel::RGB888 );
1579 TextureSet textureSet5 = CreateTextureSet( image5 );
1580 Renderer renderer5 = Renderer::New( geometry, shader );
1581 renderer5.SetTextures( textureSet5 );
1582 renderer5.SetProperty( Renderer::Property::DEPTH_INDEX, -1 );
1583 actor1.AddRenderer(renderer5);
1584 application.SendNotification();
1585 application.Render(0);
1588 TestGlAbstraction& gl = application.GetGlAbstraction();
1589 gl.EnableTextureCallTrace(true);
1590 application.SendNotification();
1591 application.Render(0);
1593 int textureBindIndex[6];
1594 for( unsigned int i(0); i<6; ++i )
1596 std::stringstream params;
1597 params << GL_TEXTURE_2D<<", "<<i+1;
1598 textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str() );
1601 //Check that renderer3 has been rendered after renderer4
1602 DALI_TEST_GREATER( textureBindIndex[3], textureBindIndex[4], TEST_LOCATION );
1604 //Check that renderer0 has been rendered after renderer2
1605 DALI_TEST_GREATER( textureBindIndex[4], textureBindIndex[5], TEST_LOCATION );
1607 //Check that renderer0 has been rendered after renderer2
1608 DALI_TEST_GREATER( textureBindIndex[5], textureBindIndex[0], TEST_LOCATION );
1610 //Check that renderer0 has been rendered after renderer2
1611 DALI_TEST_GREATER( textureBindIndex[0], textureBindIndex[2], TEST_LOCATION );
1613 //Check that renderer2 has been rendered after renderer1
1614 DALI_TEST_GREATER( textureBindIndex[2], textureBindIndex[1], TEST_LOCATION );
1619 int UtcDaliRendererRenderOrder2DLayerOverlay(void)
1621 TestApplication application;
1622 tet_infoline("Test the rendering order in a 2D layer is correct for overlays");
1624 Shader shader = Shader::New("VertexSource", "FragmentSource");
1625 Geometry geometry = CreateQuadGeometry();
1627 Actor actor0 = Actor::New();
1628 actor0.SetAnchorPoint(AnchorPoint::CENTER);
1629 actor0.SetParentOrigin(AnchorPoint::CENTER);
1630 Image image0 = BufferImage::New( 64, 64, Pixel::RGB888 );
1631 TextureSet textureSet0 = CreateTextureSet( image0 );
1632 Renderer renderer0 = Renderer::New( geometry, shader );
1633 renderer0.SetTextures( textureSet0 );
1634 actor0.AddRenderer(renderer0);
1635 actor0.SetPosition(0.0f,0.0f);
1636 actor0.SetSize(100, 100);
1637 Stage::GetCurrent().Add(actor0);
1638 actor0.SetDrawMode( DrawMode::OVERLAY_2D );
1639 application.SendNotification();
1640 application.Render(0);
1642 Actor actor1 = Actor::New();
1643 actor1.SetAnchorPoint(AnchorPoint::CENTER);
1644 actor1.SetParentOrigin(AnchorPoint::CENTER);
1645 Image image1= BufferImage::New( 64, 64, Pixel::RGB888 );
1646 TextureSet textureSet1 = CreateTextureSet( image1 );
1647 Renderer renderer1 = Renderer::New( geometry, shader );
1648 renderer1.SetTextures( textureSet1 );
1649 actor1.SetPosition(0.0f,0.0f);
1650 actor1.AddRenderer(renderer1);
1651 actor1.SetSize(100, 100);
1652 Stage::GetCurrent().Add(actor1);
1653 actor1.SetDrawMode( DrawMode::OVERLAY_2D );
1654 application.SendNotification();
1655 application.Render(0);
1657 Actor actor2 = Actor::New();
1658 actor2.SetAnchorPoint(AnchorPoint::CENTER);
1659 actor2.SetParentOrigin(AnchorPoint::CENTER);
1660 Image image2= BufferImage::New( 64, 64, Pixel::RGB888 );
1661 TextureSet textureSet2 = CreateTextureSet( image2 );
1662 Renderer renderer2 = Renderer::New( geometry, shader );
1663 renderer2.SetTextures( textureSet2 );
1664 actor2.AddRenderer(renderer2);
1665 actor2.SetPosition(0.0f,0.0f);
1666 actor2.SetSize(100, 100);
1667 Stage::GetCurrent().Add(actor2);
1668 application.SendNotification();
1669 application.Render(0);
1671 Actor actor3 = Actor::New();
1672 actor3.SetAnchorPoint(AnchorPoint::CENTER);
1673 actor3.SetParentOrigin(AnchorPoint::CENTER);
1674 Image image3 = BufferImage::New( 64, 64, Pixel::RGB888 );
1675 TextureSet textureSet3 = CreateTextureSet( image3 );
1676 Renderer renderer3 = Renderer::New( geometry, shader );
1677 renderer3.SetTextures( textureSet3 );
1678 actor3.SetPosition(0.0f,0.0f);
1679 actor3.AddRenderer(renderer3);
1680 actor3.SetSize(100, 100);
1681 Stage::GetCurrent().Add(actor3);
1682 actor3.SetDrawMode( DrawMode::OVERLAY_2D );
1683 application.SendNotification();
1684 application.Render(0);
1686 Actor actor4 = Actor::New();
1687 actor4.SetAnchorPoint(AnchorPoint::CENTER);
1688 actor4.SetParentOrigin(AnchorPoint::CENTER);
1689 Image image4 = BufferImage::New( 64, 64, Pixel::RGB888 );
1690 TextureSet textureSet4 = CreateTextureSet( image4 );
1691 Renderer renderer4 = Renderer::New( geometry, shader );
1692 renderer4.SetTextures( textureSet4 );
1693 actor4.AddRenderer(renderer4);
1694 actor4.SetPosition(0.0f,0.0f);
1695 actor4.SetSize(100, 100);
1696 Stage::GetCurrent().Add(actor4);
1697 application.SendNotification();
1698 application.Render(0);
1701 * Create the following hierarchy:
1708 * (Overlay) (Regular actor)
1718 * Expected rendering order : actor2 - actor4 - actor1 - actor0 - actor3
1720 Stage::GetCurrent().Add( actor2 );
1725 application.SendNotification();
1726 application.Render(0);
1728 TestGlAbstraction& gl = application.GetGlAbstraction();
1729 gl.EnableTextureCallTrace(true);
1730 application.SendNotification();
1731 application.Render(0);
1733 int textureBindIndex[5];
1734 for( unsigned int i(0); i<5; ++i )
1736 std::stringstream params;
1737 params << GL_TEXTURE_2D<<", "<<i+1;
1738 textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str() );
1741 //Check that actor4 has been rendered after actor2
1742 DALI_TEST_GREATER( textureBindIndex[4], textureBindIndex[2], TEST_LOCATION );
1744 //Check that actor1 has been rendered after actor4
1745 DALI_TEST_GREATER( textureBindIndex[1], textureBindIndex[4], TEST_LOCATION );
1747 //Check that actor0 has been rendered after actor1
1748 DALI_TEST_GREATER( textureBindIndex[0], textureBindIndex[1], TEST_LOCATION );
1750 //Check that actor3 has been rendered after actor0
1751 DALI_TEST_GREATER( textureBindIndex[3], textureBindIndex[0], TEST_LOCATION );
1756 int UtcDaliRendererSetIndexRange(void)
1760 "attribute vec2 aPosition;\n"
1763 " gl_Position = aPosition;\n"
1769 " gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0)\n"
1773 TestApplication application;
1774 tet_infoline("Test setting the range of indices to draw");
1776 TestGlAbstraction& gl = application.GetGlAbstraction();
1777 gl.EnableDrawCallTrace( true );
1779 Actor actor = Actor::New();
1780 actor.SetSize( 100, 100 );
1783 Geometry geometry = Geometry::New();
1784 geometry.SetGeometryType( Geometry::LINE_LOOP );
1786 // --------------------------------------------------------------------------
1788 unsigned short indices[] = { 0, 2, 4, 6, 8, // offset = 0, count = 5
1789 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, // offset = 5, count = 10
1790 1, 3, 5, 7, 9, 1 }; // offset = 15, count = 6 // line strip
1792 // --------------------------------------------------------------------------
1801 { Vector2( 0.0f, 1.00f) }, { Vector2( 0.0f, -1.00f) },
1802 { Vector2( -0.95f, 0.31f) }, { Vector2( 0.59f, 0.81f) },
1803 { Vector2( -0.59f, -0.81f) }, { Vector2( -0.95f, -0.31f) },
1804 { Vector2( 0.59f, -0.81f) }, { Vector2( 0.95f, -0.31f) },
1805 { Vector2( 0.95f, 0.31f) }, { Vector2( -0.59f, 0.81f) },
1807 Property::Map vertexFormat;
1808 vertexFormat["aPosition"] = Property::VECTOR2;
1809 PropertyBuffer vertexBuffer = PropertyBuffer::New( vertexFormat );
1810 vertexBuffer.SetData( shapes, sizeof(shapes)/sizeof(shapes[0]));
1812 // --------------------------------------------------------------------------
1813 geometry.SetIndexBuffer( indices, sizeof(indices)/sizeof(indices[0]) );
1814 geometry.AddVertexBuffer( vertexBuffer );
1817 Shader shader = Shader::New( vertexShader,fragmentShader );
1818 Renderer renderer = Renderer::New( geometry, shader );
1819 actor.AddRenderer( renderer );
1821 Stage stage = Stage::GetCurrent();
1826 // LINE_LOOP, first 0, count 5
1828 renderer.SetIndexRange( 0, 5 );
1829 application.SendNotification();
1830 application.Render();
1831 sprintf( buffer, "%u, 5, %u, indices", GL_LINE_LOOP, GL_UNSIGNED_SHORT );
1832 bool result = gl.GetDrawTrace().FindMethodAndParams( "DrawElements" , buffer );
1833 DALI_TEST_CHECK( result );
1836 // LINE_LOOP, first 5, count 10
1838 renderer.SetIndexRange( 5, 10 );
1839 sprintf( buffer, "%u, 10, %u, indices", GL_LINE_LOOP, GL_UNSIGNED_SHORT );
1840 application.SendNotification();
1841 application.Render();
1842 bool result = gl.GetDrawTrace().FindMethodAndParams( "DrawElements" , buffer );
1843 DALI_TEST_CHECK( result );
1846 // LINE_STRIP, first 15, count 6
1848 renderer.SetIndexRange( 15, 6 );
1849 geometry.SetGeometryType( Geometry::LINE_STRIP );
1850 sprintf( buffer, "%u, 6, %u, indices", GL_LINE_STRIP, GL_UNSIGNED_SHORT );
1851 application.SendNotification();
1852 application.Render();
1853 bool result = gl.GetDrawTrace().FindMethodAndParams( "DrawElements" , buffer );
1854 DALI_TEST_CHECK( result );
1857 // Index out of bounds
1859 renderer.SetIndexRange( 15, 30 );
1860 geometry.SetGeometryType( Geometry::LINE_STRIP );
1861 sprintf( buffer, "%u, 6, %u, indices", GL_LINE_STRIP, GL_UNSIGNED_SHORT );
1862 application.SendNotification();
1863 application.Render();
1864 bool result = gl.GetDrawTrace().FindMethodAndParams( "DrawElements" , buffer );
1865 DALI_TEST_CHECK( result );
1868 // drawing whole buffer starting from 15 ( last valid primitive )
1870 renderer.SetIndexRange( 15, 0 );
1871 geometry.SetGeometryType( Geometry::LINE_STRIP );
1872 sprintf( buffer, "%u, 6, %u, indices", GL_LINE_STRIP, GL_UNSIGNED_SHORT );
1873 application.SendNotification();
1874 application.Render();
1875 bool result = gl.GetDrawTrace().FindMethodAndParams( "DrawElements" , buffer );
1876 DALI_TEST_CHECK( result );
1883 int UtcDaliRendererSetDepthFunction(void)
1885 TestApplication application;
1887 tet_infoline("Test setting the depth function");
1889 Geometry geometry = CreateQuadGeometry();
1890 Shader shader = CreateShader();
1891 Renderer renderer = Renderer::New( geometry, shader );
1893 Actor actor = Actor::New();
1894 actor.AddRenderer(renderer);
1895 actor.SetSize(400, 400);
1896 Stage stage = Stage::GetCurrent();
1897 stage.GetRootLayer().SetBehavior( Layer::LAYER_3D );
1900 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1901 glAbstraction.EnableEnableDisableCallTrace(true);
1902 glAbstraction.EnableDepthFunctionCallTrace(true);
1904 TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
1905 TraceCallStack& glDepthFunctionStack = glAbstraction.GetDepthFunctionTrace();
1907 std::ostringstream depthTestStr;
1908 depthTestStr << GL_DEPTH_TEST;
1912 renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::NEVER);
1914 glEnableDisableStack.Reset();
1915 glDepthFunctionStack.Reset();
1916 application.SendNotification();
1917 application.Render();
1919 DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Enable", depthTestStr.str().c_str() ) );
1920 std::ostringstream depthFunctionStr;
1921 depthFunctionStr << GL_NEVER;
1922 DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
1927 renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::ALWAYS);
1929 glDepthFunctionStack.Reset();
1930 application.SendNotification();
1931 application.Render();
1933 std::ostringstream depthFunctionStr;
1934 depthFunctionStr << GL_ALWAYS;
1935 DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
1940 renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::LESS);
1942 glDepthFunctionStack.Reset();
1943 application.SendNotification();
1944 application.Render();
1946 std::ostringstream depthFunctionStr;
1947 depthFunctionStr << GL_LESS;
1948 DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
1953 renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::GREATER);
1955 glDepthFunctionStack.Reset();
1956 application.SendNotification();
1957 application.Render();
1959 std::ostringstream depthFunctionStr;
1960 depthFunctionStr << GL_GREATER;
1961 DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
1966 renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::EQUAL);
1968 glDepthFunctionStack.Reset();
1969 application.SendNotification();
1970 application.Render();
1972 std::ostringstream depthFunctionStr;
1973 depthFunctionStr << GL_EQUAL;
1974 DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
1979 renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::NOT_EQUAL);
1981 glDepthFunctionStack.Reset();
1982 application.SendNotification();
1983 application.Render();
1985 std::ostringstream depthFunctionStr;
1986 depthFunctionStr << GL_NOTEQUAL;
1987 DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
1992 renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::LESS_EQUAL);
1994 glDepthFunctionStack.Reset();
1995 application.SendNotification();
1996 application.Render();
1998 std::ostringstream depthFunctionStr;
1999 depthFunctionStr << GL_LEQUAL;
2000 DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
2005 renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::GREATER_EQUAL);
2007 glDepthFunctionStack.Reset();
2008 application.SendNotification();
2009 application.Render();
2011 std::ostringstream depthFunctionStr;
2012 depthFunctionStr << GL_GEQUAL;
2013 DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );