2 * Copyright (c) 2015 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.
18 #include <dali/public-api/dali-core.h>
19 #include <dali-test-suite-utils.h>
23 #include <mesh-builder.h>
27 void TestConstraintNoBlue( Vector4& current, const PropertyInputContainer& inputs )
34 void material_test_startup(void)
36 test_return_value = TET_UNDEF;
39 void material_test_cleanup(void)
41 test_return_value = TET_PASS;
44 int UtcDaliMaterialNew01(void)
46 TestApplication application;
48 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
49 Material material = Material::New(shader);
51 DALI_TEST_CHECK( material );
55 int UtcDaliMaterialNew02(void)
57 TestApplication application;
59 DALI_TEST_CHECK( !material );
63 int UtcDaliMaterialCopyConstructor(void)
65 TestApplication application;
67 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
68 Image image = BufferImage::New(32, 32, Pixel::RGBA8888);
69 Sampler sampler = Sampler::New(image, "sTexture");
70 Material material = Material::New(shader);
71 material.AddSampler( sampler );
73 Material materialCopy(material);
75 DALI_TEST_CHECK( materialCopy );
76 DALI_TEST_EQUALS( materialCopy.GetSamplerAt(0), sampler, TEST_LOCATION );
81 int UtcDaliMaterialAssignmentOperator(void)
83 TestApplication application;
85 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
86 Image image = BufferImage::New(32, 32, Pixel::RGBA8888);
87 Sampler sampler = Sampler::New(image, "sTexture");
88 Material material = Material::New(shader);
89 material.AddSampler( sampler );
92 DALI_TEST_CHECK( !material2 );
95 DALI_TEST_CHECK( material2 );
96 DALI_TEST_EQUALS( material2.GetSamplerAt(0), sampler, TEST_LOCATION );
101 int UtcDaliMaterialDownCast01(void)
103 TestApplication application;
104 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
105 Material material = Material::New(shader);
107 BaseHandle handle(material);
108 Material material2 = Material::DownCast(handle);
109 DALI_TEST_CHECK( material2 );
114 int UtcDaliMaterialDownCast02(void)
116 TestApplication application;
118 Handle handle = Handle::New(); // Create a custom object
119 Material material = Material::DownCast(handle);
120 DALI_TEST_CHECK( !material );
124 int UtcDaliMaterialSetShader(void)
126 TestApplication application;
128 tet_infoline("Test SetShader(shader) ");
130 Shader shader1 = Shader::New( "vertexSrc1", "fragmentSrc1" );
131 shader1.RegisterProperty( "uFadeColor", Color::CYAN );
133 Shader shader2 = Shader::New( "vertexSrc1", "fragmentSrc1" );
134 shader2.RegisterProperty( "uFadeColor", Color::MAGENTA );
137 Material material = Material::New(shader1);
139 Geometry geometry = CreateQuadGeometry();
140 Renderer renderer = Renderer::New( geometry, material );
142 Actor actor = Actor::New();
143 actor.AddRenderer(renderer);
144 actor.SetSize(400, 400);
145 Stage::GetCurrent().Add(actor);
147 TestGlAbstraction& gl = application.GetGlAbstraction();
148 application.SendNotification();
149 application.Render(0);
150 Vector4 actualValue(Vector4::ZERO);
151 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
152 DALI_TEST_EQUALS( actualValue, Color::CYAN, TEST_LOCATION );
155 material.SetShader( shader2 );
157 application.SendNotification();
158 application.Render(0);
159 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
160 DALI_TEST_EQUALS( actualValue, Color::MAGENTA, TEST_LOCATION );
163 material.SetShader( shader1 );
165 application.SendNotification();
166 application.Render(0);
167 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
168 DALI_TEST_EQUALS( actualValue, Color::CYAN, TEST_LOCATION );
173 int UtcDaliMaterialGetShader(void)
175 TestApplication application;
177 tet_infoline("Test GetShader() ");
179 Shader shader1 = Shader::New( "vertexSrc1", "fragmentSrc1" );
180 Shader shader2 = Shader::New( "vertexSrc1", "fragmentSrc1" );
183 Material material = Material::New(shader1);
184 DALI_TEST_EQUALS( shader1, material.GetShader(), TEST_LOCATION );
187 material.SetShader( shader2 );
188 DALI_TEST_EQUALS( shader2, material.GetShader(), TEST_LOCATION );
191 material.SetShader( shader1 );
192 DALI_TEST_EQUALS( shader1, material.GetShader(), TEST_LOCATION );
197 int UtcDaliMaterialAddSampler(void)
199 TestApplication application;
201 tet_infoline("Test AddSampler(sampler)");
203 Image image = BufferImage::New(32, 32, Pixel::RGBA8888);
204 Sampler sampler1 = Sampler::New(image, "sTexture1");
205 Sampler sampler2 = Sampler::New(image, "sTexture2");
207 Material material = CreateMaterial(0.5f);
209 Geometry geometry = CreateQuadGeometry();
210 Renderer renderer = Renderer::New( geometry, material );
211 Actor actor = Actor::New();
212 actor.AddRenderer(renderer);
213 actor.SetParentOrigin( ParentOrigin::CENTER );
214 actor.SetSize(400, 400);
215 Stage::GetCurrent().Add( actor );
217 TestGlAbstraction& gl = application.GetGlAbstraction();
220 material.AddSampler( sampler1 );
221 application.SendNotification();
222 application.Render();
223 DALI_TEST_CHECK( gl.GetUniformValue<int>( "sTexture1", textureUnit ) );
224 DALI_TEST_EQUALS( textureUnit, 0, TEST_LOCATION );
226 material.AddSampler( sampler2 );
227 application.SendNotification();
228 application.Render();
229 DALI_TEST_CHECK( gl.GetUniformValue<int>( "sTexture2", textureUnit ) );
230 DALI_TEST_EQUALS( textureUnit, 1, TEST_LOCATION );
235 int UtcDaliMaterialGetNumberOfSampler(void)
237 TestApplication application;
239 tet_infoline("Test GetNumberOfSampler()");
241 Image image = BufferImage::New(32, 32, Pixel::RGBA8888);
242 Sampler sampler0 = Sampler::New(image, "sTexture0");
243 Sampler sampler1 = Sampler::New(image, "sTexture1");
244 Sampler sampler2 = Sampler::New(image, "sTexture2");
245 Sampler sampler3 = Sampler::New(image, "sTexture3");
246 Sampler sampler4 = Sampler::New(image, "sTexture4");
248 Material material = CreateMaterial(0.5f);
250 Geometry geometry = CreateQuadGeometry();
251 Renderer renderer = Renderer::New( geometry, material );
252 Actor actor = Actor::New();
253 actor.AddRenderer(renderer);
254 actor.SetParentOrigin( ParentOrigin::CENTER );
255 actor.SetSize(400, 400);
256 Stage::GetCurrent().Add( actor );
258 material.AddSampler( sampler0 );
259 material.AddSampler( sampler1 );
260 DALI_TEST_EQUALS( material.GetNumberOfSamplers(), 2u, TEST_LOCATION );
262 material.AddSampler( sampler2 );
263 material.AddSampler( sampler3 );
264 material.AddSampler( sampler4 );
265 DALI_TEST_EQUALS( material.GetNumberOfSamplers(), 5u, TEST_LOCATION );
267 material.RemoveSampler(3); // remove sampler3
268 DALI_TEST_EQUALS( material.GetNumberOfSamplers(), 4u, TEST_LOCATION );
270 material.RemoveSampler(3); // remove sampler4
271 material.RemoveSampler(0); // remove sampler0
272 DALI_TEST_EQUALS( material.GetNumberOfSamplers(), 2u, TEST_LOCATION );
277 int UtcDaliMaterialRemoveSampler(void)
279 TestApplication application;
281 tet_infoline("Test RemoveSampler(index)");
282 Image image = BufferImage::New(32, 32, Pixel::RGBA8888);
283 Sampler sampler1 = Sampler::New(image, "sTexture1");
284 Sampler sampler2 = Sampler::New(image, "sTexture2");
286 Material material = CreateMaterial(0.5f);
288 Geometry geometry = CreateQuadGeometry();
289 Renderer renderer = Renderer::New( geometry, material );
290 Actor actor = Actor::New();
291 actor.AddRenderer(renderer);
292 actor.SetParentOrigin( ParentOrigin::CENTER );
293 actor.SetSize(400, 400);
294 Stage::GetCurrent().Add( actor );
296 material.AddSampler( sampler1 );
297 material.AddSampler( sampler2 );
299 TestGlAbstraction& gl = application.GetGlAbstraction();
301 application.SendNotification();
302 application.Render();
303 DALI_TEST_CHECK( gl.GetUniformValue<int>( "sTexture1", textureUnit ) );
304 DALI_TEST_EQUALS( textureUnit, 0, TEST_LOCATION );
305 DALI_TEST_CHECK( gl.GetUniformValue<int>( "sTexture2", textureUnit ) );
306 DALI_TEST_EQUALS( textureUnit, 1, TEST_LOCATION );
308 material.RemoveSampler(0); // remove sampler1
309 application.SendNotification();
310 application.Render();
311 // Todo: test the sampler is removed from gl, cannot pass this test with current implementation
312 //DALI_TEST_CHECK( ! gl.GetUniformValue<int>( "sTexture1", textureUnit ) );
313 DALI_TEST_EQUALS( material.GetNumberOfSamplers(), 1u, TEST_LOCATION );
315 material.RemoveSampler(0); // remove sampler2
316 application.SendNotification();
317 application.Render();
318 // Todo: test the sampler is removed from gl, cannot pass this test with current implementation
319 //DALI_TEST_CHECK( ! gl.GetUniformValue<int>( "sTexture2", textureUnit ) );
320 DALI_TEST_EQUALS( material.GetNumberOfSamplers(), 0u, TEST_LOCATION );
325 int UtcDaliMaterialGetSamplerAt(void)
327 TestApplication application;
329 tet_infoline("Test GetSamplerAt(index)");
331 Image image = BufferImage::New(16, 16, Pixel::RGBA8888);
332 Sampler sampler1 = Sampler::New(image, "sTexture1");
333 Sampler sampler2 = Sampler::New(image, "sTexture2");
334 Sampler sampler3 = Sampler::New(image, "sTexture3");
336 Material material = CreateMaterial(0.5f);
337 material.AddSampler( sampler1 );
338 material.AddSampler( sampler2 );
339 material.AddSampler( sampler3 );
341 Geometry geometry = CreateQuadGeometry();
342 Renderer renderer = Renderer::New( geometry, material );
343 Actor actor = Actor::New();
344 actor.AddRenderer(renderer);
345 actor.SetParentOrigin( ParentOrigin::CENTER );
346 actor.SetSize(400, 400);
347 Stage::GetCurrent().Add( actor );
349 application.SendNotification();
350 application.Render();
352 DALI_TEST_EQUALS( material.GetSamplerAt( 0 ), sampler1, TEST_LOCATION );
353 DALI_TEST_EQUALS( material.GetSamplerAt( 1 ), sampler2, TEST_LOCATION );
354 DALI_TEST_EQUALS( material.GetSamplerAt( 2 ), sampler3, TEST_LOCATION );
356 Sampler sampler = material.GetSamplerAt( 1 );
357 DALI_TEST_EQUALS( sampler.GetImage().GetWidth(), 16u, TEST_LOCATION );
362 int UtcDaliMaterialSetFaceCullingMode(void)
364 TestApplication application;
366 tet_infoline("Test SetFaceCullingMode(cullingMode)");
367 Geometry geometry = CreateQuadGeometry();
368 Material material = CreateMaterial(0.5f);
369 Renderer renderer = Renderer::New( geometry, material );
371 Actor actor = Actor::New();
372 actor.AddRenderer(renderer);
373 actor.SetSize(400, 400);
374 Stage::GetCurrent().Add(actor);
376 TestGlAbstraction& gl = application.GetGlAbstraction();
377 TraceCallStack& cullFaceStack = gl.GetCullFaceTrace();
378 cullFaceStack.Reset();
379 gl.EnableCullFaceCallTrace(true);
381 material.SetFaceCullingMode( Material::CULL_BACK_AND_FRONT);
382 application.SendNotification();
383 application.Render();
385 // Todo: test the glCullFace(GL_FRONT_AND_BACK) is actually been called, cannot pass this test with current implementation
386 DALI_TEST_EQUALS( cullFaceStack.CountMethod( "CullFace" ), 0, TEST_LOCATION);
387 //string parameter("GL_FRONT_AND_BACK" );
388 //DALI_TEST_CHECK( cullFaceStack.TestMethodAndParams(0, "CullFace", parameter) );
393 int UtcDaliMaterialBlendingOptions01(void)
395 TestApplication application;
397 tet_infoline("Test SetBlendFunc(src, dest) ");
399 Geometry geometry = CreateQuadGeometry();
400 Material material = CreateMaterial(0.5f);
401 Renderer renderer = Renderer::New( geometry, material );
403 Actor actor = Actor::New();
404 actor.AddRenderer(renderer);
405 actor.SetSize(400, 400);
406 Stage::GetCurrent().Add(actor);
408 material.SetBlendFunc(BlendingFactor::ONE_MINUS_SRC_COLOR, BlendingFactor::SRC_ALPHA_SATURATE);
410 // Test that Set was successful:
412 BlendingFactor::Type srcFactorRgb( BlendingFactor::ZERO );
413 BlendingFactor::Type destFactorRgb( BlendingFactor::ZERO );
414 BlendingFactor::Type srcFactorAlpha( BlendingFactor::ZERO );
415 BlendingFactor::Type destFactorAlpha( BlendingFactor::ZERO );
416 material.GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
418 DALI_TEST_EQUALS( BlendingFactor::ONE_MINUS_SRC_COLOR, srcFactorRgb, TEST_LOCATION );
419 DALI_TEST_EQUALS( BlendingFactor::SRC_ALPHA_SATURATE, destFactorRgb, TEST_LOCATION );
420 DALI_TEST_EQUALS( BlendingFactor::ONE_MINUS_SRC_COLOR, srcFactorAlpha, TEST_LOCATION );
421 DALI_TEST_EQUALS( BlendingFactor::SRC_ALPHA_SATURATE, destFactorAlpha, TEST_LOCATION );
424 application.SendNotification();
425 application.Render();
427 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
429 DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_SRC_COLOR, glAbstraction.GetLastBlendFuncSrcRgb(), TEST_LOCATION );
430 DALI_TEST_EQUALS( (GLenum)GL_SRC_ALPHA_SATURATE, glAbstraction.GetLastBlendFuncDstRgb(), TEST_LOCATION );
431 DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_SRC_COLOR, glAbstraction.GetLastBlendFuncSrcAlpha(), TEST_LOCATION );
432 DALI_TEST_EQUALS( (GLenum)GL_SRC_ALPHA_SATURATE, glAbstraction.GetLastBlendFuncDstAlpha(), TEST_LOCATION );
437 int UtcDaliMaterialBlendingOptions02(void)
439 TestApplication application;
441 tet_infoline("Test SetBlendFunc(srcRgb, destRgb, srcAlpha, destAlpha) ");
443 Geometry geometry = CreateQuadGeometry();
444 Material material = CreateMaterial(0.5f);
445 Renderer renderer = Renderer::New( geometry, material );
447 Actor actor = Actor::New();
448 actor.AddRenderer(renderer);
449 actor.SetSize(400, 400);
450 Stage::GetCurrent().Add(actor);
452 material.SetBlendFunc( BlendingFactor::CONSTANT_COLOR, BlendingFactor::ONE_MINUS_CONSTANT_COLOR,
453 BlendingFactor::CONSTANT_ALPHA, BlendingFactor::ONE_MINUS_CONSTANT_ALPHA );
455 // Test that Set was successful:
457 BlendingFactor::Type srcFactorRgb( BlendingFactor::ZERO );
458 BlendingFactor::Type destFactorRgb( BlendingFactor::ZERO );
459 BlendingFactor::Type srcFactorAlpha( BlendingFactor::ZERO );
460 BlendingFactor::Type destFactorAlpha( BlendingFactor::ZERO );
461 material.GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
463 DALI_TEST_EQUALS( BlendingFactor::CONSTANT_COLOR, srcFactorRgb, TEST_LOCATION );
464 DALI_TEST_EQUALS( BlendingFactor::ONE_MINUS_CONSTANT_COLOR, destFactorRgb, TEST_LOCATION );
465 DALI_TEST_EQUALS( BlendingFactor::CONSTANT_ALPHA, srcFactorAlpha, TEST_LOCATION );
466 DALI_TEST_EQUALS( BlendingFactor::ONE_MINUS_CONSTANT_ALPHA, destFactorAlpha, TEST_LOCATION );
469 application.SendNotification();
470 application.Render();
472 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
473 DALI_TEST_EQUALS( (GLenum)GL_CONSTANT_COLOR, glAbstraction.GetLastBlendFuncSrcRgb(), TEST_LOCATION );
474 DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_CONSTANT_COLOR, glAbstraction.GetLastBlendFuncDstRgb(), TEST_LOCATION );
475 DALI_TEST_EQUALS( (GLenum)GL_CONSTANT_ALPHA, glAbstraction.GetLastBlendFuncSrcAlpha(), TEST_LOCATION );
476 DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_CONSTANT_ALPHA, glAbstraction.GetLastBlendFuncDstAlpha(), TEST_LOCATION );
483 int UtcDaliMaterialBlendingOptions03(void)
485 TestApplication application;
487 tet_infoline("Test GetBlendEquation() defaults ");
489 Geometry geometry = CreateQuadGeometry();
490 Material material = CreateMaterial(0.5f);
491 Renderer renderer = Renderer::New( geometry, material );
493 Actor actor = Actor::New();
494 actor.AddRenderer(renderer);
495 actor.SetSize(400, 400);
496 Stage::GetCurrent().Add(actor);
498 // Test the defaults as documented in blending.h
500 BlendingEquation::Type equationRgb( BlendingEquation::SUBTRACT );
501 BlendingEquation::Type equationAlpha( BlendingEquation::SUBTRACT );
502 material.GetBlendEquation( equationRgb, equationAlpha );
503 DALI_TEST_EQUALS( BlendingEquation::ADD, equationRgb, TEST_LOCATION );
504 DALI_TEST_EQUALS( BlendingEquation::ADD, equationAlpha, TEST_LOCATION );
511 int UtcDaliMaterialBlendingOptions04(void)
513 TestApplication application;
515 tet_infoline("Test SetBlendEquation() ");
517 Geometry geometry = CreateQuadGeometry();
518 Material material = CreateMaterial(0.5f);
519 Renderer renderer = Renderer::New( geometry, material );
521 Actor actor = Actor::New();
522 actor.AddRenderer(renderer);
523 actor.SetSize(400, 400);
524 Stage::GetCurrent().Add(actor);
526 // Test the single blending equation setting
528 material.SetBlendEquation( BlendingEquation::REVERSE_SUBTRACT );
529 BlendingEquation::Type equationRgba( BlendingEquation::SUBTRACT );
530 material.GetBlendEquation( equationRgba, equationRgba );
531 DALI_TEST_EQUALS( BlendingEquation::REVERSE_SUBTRACT, equationRgba, TEST_LOCATION );
534 material.SetBlendEquation( BlendingEquation::REVERSE_SUBTRACT, BlendingEquation::REVERSE_SUBTRACT );
536 // Test that Set was successful
538 BlendingEquation::Type equationRgb( BlendingEquation::SUBTRACT );
539 BlendingEquation::Type equationAlpha( BlendingEquation::SUBTRACT );
540 material.GetBlendEquation( equationRgb, equationAlpha );
541 DALI_TEST_EQUALS( BlendingEquation::REVERSE_SUBTRACT, equationRgb, TEST_LOCATION );
542 DALI_TEST_EQUALS( BlendingEquation::REVERSE_SUBTRACT, equationAlpha, TEST_LOCATION );
545 // Render & check GL commands
546 application.SendNotification();
547 application.Render();
549 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
550 DALI_TEST_EQUALS( (GLenum)GL_FUNC_REVERSE_SUBTRACT, glAbstraction.GetLastBlendEquationRgb(), TEST_LOCATION );
551 DALI_TEST_EQUALS( (GLenum)GL_FUNC_REVERSE_SUBTRACT, glAbstraction.GetLastBlendEquationAlpha(), TEST_LOCATION );
556 int UtcDaliMaterialSetBlendMode01(void)
558 TestApplication application;
560 tet_infoline("Test setting the blend mode to on with an opaque color renders with blending enabled");
562 Geometry geometry = CreateQuadGeometry();
563 Material material = CreateMaterial(1.0f);
564 Renderer renderer = Renderer::New( geometry, material );
566 Actor actor = Actor::New();
567 actor.AddRenderer(renderer);
568 actor.SetSize(400, 400);
569 Stage::GetCurrent().Add(actor);
571 material.SetBlendMode(BlendingMode::ON);
573 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
574 glAbstraction.EnableCullFaceCallTrace(true);
576 application.SendNotification();
577 application.Render();
579 TraceCallStack& glEnableStack = glAbstraction.GetCullFaceTrace();
580 std::ostringstream blendStr;
581 blendStr << GL_BLEND;
582 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
588 int UtcDaliMaterialSetBlendMode02(void)
590 TestApplication application;
592 tet_infoline("Test setting the blend mode to off with a transparent color renders with blending disabled (and not enabled)");
594 Geometry geometry = CreateQuadGeometry();
595 Material material = CreateMaterial(0.5f);
596 Renderer renderer = Renderer::New( geometry, material );
598 Actor actor = Actor::New();
599 actor.AddRenderer(renderer);
600 actor.SetSize(400, 400);
601 Stage::GetCurrent().Add(actor);
603 material.SetBlendMode(BlendingMode::OFF);
605 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
606 glAbstraction.EnableCullFaceCallTrace(true);
608 application.SendNotification();
609 application.Render();
611 TraceCallStack& glEnableStack = glAbstraction.GetCullFaceTrace();
612 std::ostringstream blendStr;
613 blendStr << GL_BLEND;
614 DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
619 int UtcDaliMaterialSetBlendMode03(void)
621 TestApplication application;
623 tet_infoline("Test setting the blend mode to auto with a transparent material color renders with blending enabled");
625 Geometry geometry = CreateQuadGeometry();
626 Material material = CreateMaterial(0.5f);
627 Renderer renderer = Renderer::New( geometry, material );
629 Actor actor = Actor::New();
630 actor.AddRenderer(renderer);
631 actor.SetSize(400, 400);
632 Stage::GetCurrent().Add(actor);
634 material.SetBlendMode(BlendingMode::AUTO);
636 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
637 glAbstraction.EnableCullFaceCallTrace(true);
639 application.SendNotification();
640 application.Render();
642 TraceCallStack& glEnableStack = glAbstraction.GetCullFaceTrace();
643 std::ostringstream blendStr;
644 blendStr << GL_BLEND;
645 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
650 int UtcDaliMaterialSetBlendMode04(void)
652 TestApplication application;
654 tet_infoline("Test setting the blend mode to auto with an opaque color renders with blending disabled");
656 Geometry geometry = CreateQuadGeometry();
657 Material material = CreateMaterial(1.0f);
658 Renderer renderer = Renderer::New( geometry, material );
660 Actor actor = Actor::New();
661 actor.AddRenderer(renderer);
662 actor.SetSize(400, 400);
663 Stage::GetCurrent().Add(actor);
665 material.SetBlendMode(BlendingMode::AUTO);
667 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
668 glAbstraction.EnableCullFaceCallTrace(true);
670 application.SendNotification();
671 application.Render();
673 TraceCallStack& glEnableStack = glAbstraction.GetCullFaceTrace();
674 std::ostringstream blendStr;
675 blendStr << GL_BLEND;
676 DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
681 int UtcDaliMaterialSetBlendMode04b(void)
683 TestApplication application;
685 tet_infoline("Test setting the blend mode to auto with an opaque material color and a transparent actor color renders with blending enabled");
687 Geometry geometry = CreateQuadGeometry();
688 Material material = CreateMaterial(1.0f);
689 Renderer renderer = Renderer::New( geometry, material );
691 Actor actor = Actor::New();
692 actor.AddRenderer(renderer);
693 actor.SetSize(400, 400);
694 actor.SetColor( Vector4(1.0f, 0.0f, 1.0f, 0.5f) );
695 Stage::GetCurrent().Add(actor);
697 material.SetBlendMode(BlendingMode::AUTO);
699 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
700 glAbstraction.EnableCullFaceCallTrace(true);
702 application.SendNotification();
703 application.Render();
705 TraceCallStack& glEnableStack = glAbstraction.GetCullFaceTrace();
706 std::ostringstream blendStr;
707 blendStr << GL_BLEND;
708 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
713 int UtcDaliMaterialSetBlendMode04c(void)
715 TestApplication application;
717 tet_infoline("Test setting the blend mode to auto with an opaque material color and an opaque actor color renders with blending disabled");
719 Geometry geometry = CreateQuadGeometry();
720 Material material = CreateMaterial(1.0f);
721 Renderer renderer = Renderer::New( geometry, material );
723 Actor actor = Actor::New();
724 actor.AddRenderer(renderer);
725 actor.SetSize(400, 400);
726 actor.SetColor( Color::MAGENTA );
727 Stage::GetCurrent().Add(actor);
729 material.SetBlendMode(BlendingMode::AUTO);
731 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
732 glAbstraction.EnableCullFaceCallTrace(true);
734 application.SendNotification();
735 application.Render();
737 TraceCallStack& glEnableStack = glAbstraction.GetCullFaceTrace();
738 std::ostringstream blendStr;
739 blendStr << GL_BLEND;
740 DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
745 int UtcDaliMaterialSetBlendMode05(void)
747 TestApplication application;
749 tet_infoline("Test setting the blend mode to auto with an opaque color and an image with an alpha channel renders with blending enabled");
751 Geometry geometry = CreateQuadGeometry();
752 BufferImage image = BufferImage::New( 40, 40, Pixel::RGBA8888 );
753 Material material = CreateMaterial(1.0f, image);
754 Renderer renderer = Renderer::New( geometry, material );
756 Actor actor = Actor::New();
757 actor.AddRenderer(renderer);
758 actor.SetSize(400, 400);
759 Stage::GetCurrent().Add(actor);
761 material.SetBlendMode(BlendingMode::AUTO);
763 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
764 glAbstraction.EnableCullFaceCallTrace(true);
766 application.SendNotification();
767 application.Render();
769 TraceCallStack& glEnableStack = glAbstraction.GetCullFaceTrace();
770 std::ostringstream blendStr;
771 blendStr << GL_BLEND;
772 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
777 int UtcDaliMaterialSetBlendMode06(void)
779 TestApplication application;
780 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");
782 Geometry geometry = CreateQuadGeometry();
783 Shader shader = Shader::New( "vertexSrc", "fragmentSrc", Shader::HINT_OUTPUT_IS_TRANSPARENT );
784 Material material = Material::New(shader);
785 material.SetProperty(Material::Property::COLOR, Color::WHITE);
787 Renderer renderer = Renderer::New( geometry, material );
789 Actor actor = Actor::New();
790 actor.AddRenderer(renderer);
791 actor.SetSize(400, 400);
792 Stage::GetCurrent().Add(actor);
794 material.SetBlendMode(BlendingMode::AUTO);
796 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
797 glAbstraction.EnableCullFaceCallTrace(true);
799 application.SendNotification();
800 application.Render();
802 TraceCallStack& glEnableStack = glAbstraction.GetCullFaceTrace();
803 std::ostringstream blendStr;
804 blendStr << GL_BLEND;
805 DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
811 //Todo: test the Shader::HINT_OUTPUT_IS_OPAQUE would disable the blending, the test cannot pass with current implementation
812 /*int UtcDaliMaterialSetBlendMode07(void)
814 TestApplication application;
815 tet_infoline("Test setting the blend mode to auto with a transparent color and an image without an alpha channel and a shader with the hint OUTPUT_IS_OPAQUE renders with blending disabled");
816 Geometry geometry = CreateQuadGeometry();
817 Shader shader = Shader::New( "vertexSrc", "fragmentSrc", Shader::HINT_OUTPUT_IS_OPAQUE );
818 Material material = Material::New(shader);
819 material.SetProperty(Material::Property::COLOR, Color::TRANSPARENT);
821 Renderer renderer = Renderer::New( geometry, material );
823 Actor actor = Actor::New();
824 actor.AddRenderer(renderer);
825 actor.SetSize(400, 400);
826 Stage::GetCurrent().Add(actor);
828 material.SetBlendMode(BlendingMode::AUTO);
830 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
831 glAbstraction.EnableCullFaceCallTrace(true);
833 application.SendNotification();
834 application.Render();
836 TraceCallStack& glEnableStack = glAbstraction.GetCullFaceTrace();
837 std::ostringstream blendStr;
838 blendStr << GL_BLEND;
839 DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
844 int UtcDaliMaterialSetBlendMode08(void)
846 TestApplication application;
847 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");
849 Geometry geometry = CreateQuadGeometry();
850 Shader shader = Shader::New( "vertexSrc", "fragmentSrc", Shader::HINT_OUTPUT_IS_OPAQUE );
851 Material material = Material::New(shader);
852 material.SetProperty(Material::Property::COLOR, Color::WHITE);
853 BufferImage image = BufferImage::New( 50, 50, Pixel::RGB888 );
854 Sampler sampler = Sampler::New( image, "sTexture" );
855 material.AddSampler( sampler );
856 Renderer renderer = Renderer::New( geometry, material );
858 Actor actor = Actor::New();
859 actor.AddRenderer(renderer);
860 actor.SetSize(400, 400);
861 Stage::GetCurrent().Add(actor);
863 material.SetBlendMode(BlendingMode::AUTO);
865 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
866 glAbstraction.EnableCullFaceCallTrace(true);
868 application.SendNotification();
869 application.Render();
871 TraceCallStack& glEnableStack = glAbstraction.GetCullFaceTrace();
872 std::ostringstream blendStr;
873 blendStr << GL_BLEND;
874 DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
879 int UtcDaliMaterialGetBlendMode(void)
881 TestApplication application;
883 tet_infoline("Test GetBlendMode()");
885 Shader shader = Shader::New( "vertexSrc", "fragmentSrc", Shader::HINT_OUTPUT_IS_OPAQUE );
886 Material material = Material::New(shader);
889 DALI_TEST_EQUALS( material.GetBlendMode(), BlendingMode::OFF, TEST_LOCATION );
892 material.SetBlendMode(BlendingMode::AUTO);
893 DALI_TEST_EQUALS( material.GetBlendMode(), BlendingMode::AUTO, TEST_LOCATION );
896 material.SetBlendMode(BlendingMode::ON);
897 DALI_TEST_EQUALS( material.GetBlendMode(), BlendingMode::ON, TEST_LOCATION );
900 material.SetBlendMode(BlendingMode::OFF);
901 DALI_TEST_EQUALS( material.GetBlendMode(), BlendingMode::OFF, TEST_LOCATION );
906 int UtcDaliMaterialSetBlendColor(void)
908 TestApplication application;
910 tet_infoline("Test SetBlendColor(color)");
912 Geometry geometry = CreateQuadGeometry();
913 Shader shader = Shader::New( "vertexSrc", "fragmentSrc", Shader::HINT_OUTPUT_IS_OPAQUE );
914 Material material = Material::New(shader);
915 material.SetProperty(Material::Property::COLOR, Color::WHITE);
916 BufferImage image = BufferImage::New( 50, 50, Pixel::RGBA8888 );
917 Sampler sampler = Sampler::New( image, "sTexture" );
918 material.AddSampler( sampler );
919 Renderer renderer = Renderer::New( geometry, material );
921 Actor actor = Actor::New();
922 actor.AddRenderer(renderer);
923 actor.SetSize(400, 400);
924 Stage::GetCurrent().Add(actor);
926 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
928 application.SendNotification();
929 application.Render();
930 DALI_TEST_EQUALS( glAbstraction.GetLastBlendColor(), Color::TRANSPARENT, TEST_LOCATION );
932 material.SetBlendColor( Color::MAGENTA );
933 application.SendNotification();
934 application.Render();
935 DALI_TEST_EQUALS( glAbstraction.GetLastBlendColor(), Color::MAGENTA, TEST_LOCATION );
937 Vector4 color( 0.1f, 0.2f, 0.3f, 0.4f );
938 material.SetBlendColor( color );
939 application.SendNotification();
940 application.Render();
941 DALI_TEST_EQUALS( glAbstraction.GetLastBlendColor(), color, TEST_LOCATION );
946 int UtcDaliMaterialGetBlendColor(void)
948 TestApplication application;
950 tet_infoline("Test GetBlendColor()");
952 Shader shader = Shader::New( "vertexSrc", "fragmentSrc", Shader::HINT_OUTPUT_IS_OPAQUE );
953 Material material = Material::New(shader);
955 DALI_TEST_EQUALS( material.GetBlendColor(), Color::TRANSPARENT, TEST_LOCATION );
957 material.SetBlendColor( Color::MAGENTA );
958 application.SendNotification();
959 application.Render();
960 DALI_TEST_EQUALS( material.GetBlendColor(), Color::MAGENTA, TEST_LOCATION );
962 Vector4 color( 0.1f, 0.2f, 0.3f, 0.4f );
963 material.SetBlendColor( color );
964 application.SendNotification();
965 application.Render();
966 DALI_TEST_EQUALS( material.GetBlendColor(), color, TEST_LOCATION );
971 int UtcDaliMaterialConstraint(void)
973 TestApplication application;
975 tet_infoline("Test that a custom material property can be constrained");
977 Shader shader = Shader::New( "VertexSource", "FragmentSource");
978 Material material = Material::New( shader );
979 material.SetProperty(Material::Property::COLOR, Color::WHITE);
981 Geometry geometry = CreateQuadGeometry();
982 Renderer renderer = Renderer::New( geometry, material );
984 Actor actor = Actor::New();
985 actor.AddRenderer(renderer);
986 actor.SetSize(400, 400);
987 Stage::GetCurrent().Add(actor);
989 Vector4 initialColor = Color::WHITE;
990 Property::Index colorIndex = material.RegisterProperty( "uFadeColor", initialColor );
992 application.SendNotification();
993 application.Render(0);
994 DALI_TEST_EQUALS( material.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION );
997 Constraint constraint = Constraint::New<Vector4>( material, colorIndex, TestConstraintNoBlue );
999 application.SendNotification();
1000 application.Render(0);
1002 // Expect no blue component in either buffer - yellow
1003 DALI_TEST_EQUALS( material.GetProperty<Vector4>(colorIndex), Color::YELLOW, TEST_LOCATION );
1004 application.Render(0);
1005 DALI_TEST_EQUALS( material.GetProperty<Vector4>(colorIndex), Color::YELLOW, TEST_LOCATION );
1007 material.RemoveConstraints();
1008 material.SetProperty(colorIndex, Color::WHITE );
1009 application.SendNotification();
1010 application.Render(0);
1011 DALI_TEST_EQUALS( material.GetProperty<Vector4>(colorIndex), Color::WHITE, TEST_LOCATION );
1016 int UtcDaliMaterialConstraint02(void)
1018 TestApplication application;
1020 tet_infoline("Test that a uniform map material property can be constrained");
1022 Shader shader = Shader::New( "VertexSource", "FragmentSource");
1023 Material material = Material::New( shader );
1024 material.SetProperty(Material::Property::COLOR, Color::WHITE);
1026 Geometry geometry = CreateQuadGeometry();
1027 Renderer renderer = Renderer::New( geometry, material );
1029 Actor actor = Actor::New();
1030 actor.AddRenderer(renderer);
1031 actor.SetSize(400, 400);
1032 Stage::GetCurrent().Add(actor);
1033 application.SendNotification();
1034 application.Render(0);
1036 Vector4 initialColor = Color::WHITE;
1037 Property::Index colorIndex = material.RegisterProperty( "uFadeColor", initialColor );
1039 TestGlAbstraction& gl = application.GetGlAbstraction();
1041 application.SendNotification();
1042 application.Render(0);
1044 Vector4 actualValue(Vector4::ZERO);
1045 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1046 DALI_TEST_EQUALS( actualValue, initialColor, TEST_LOCATION );
1049 Constraint constraint = Constraint::New<Vector4>( material, colorIndex, TestConstraintNoBlue );
1051 application.SendNotification();
1052 application.Render(0);
1054 // Expect no blue component in either buffer - yellow
1055 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1056 DALI_TEST_EQUALS( actualValue, Color::YELLOW, TEST_LOCATION );
1058 application.Render(0);
1059 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1060 DALI_TEST_EQUALS( actualValue, Color::YELLOW, TEST_LOCATION );
1062 material.RemoveConstraints();
1063 material.SetProperty(colorIndex, Color::WHITE );
1064 application.SendNotification();
1065 application.Render(0);
1067 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1068 DALI_TEST_EQUALS( actualValue, Color::WHITE, TEST_LOCATION );
1075 int UtcDaliMaterialAnimatedProperty01(void)
1077 TestApplication application;
1079 tet_infoline("Test that a non-uniform material property can be animated");
1081 Shader shader = Shader::New( "VertexSource", "FragmentSource");
1082 Material material = Material::New( shader );
1083 material.SetProperty(Material::Property::COLOR, Color::WHITE);
1085 Geometry geometry = CreateQuadGeometry();
1086 Renderer renderer = Renderer::New( geometry, material );
1088 Actor actor = Actor::New();
1089 actor.AddRenderer(renderer);
1090 actor.SetSize(400, 400);
1091 Stage::GetCurrent().Add(actor);
1093 Vector4 initialColor = Color::WHITE;
1094 Property::Index colorIndex = material.RegisterProperty( "uFadeColor", initialColor );
1096 application.SendNotification();
1097 application.Render(0);
1098 DALI_TEST_EQUALS( material.GetProperty<Vector4>(colorIndex), initialColor, TEST_LOCATION );
1100 Animation animation = Animation::New(1.0f);
1101 KeyFrames keyFrames = KeyFrames::New();
1102 keyFrames.Add(0.0f, initialColor);
1103 keyFrames.Add(1.0f, Color::TRANSPARENT);
1104 animation.AnimateBetween( Property( material, colorIndex ), keyFrames );
1107 application.SendNotification();
1108 application.Render(500);
1110 DALI_TEST_EQUALS( material.GetProperty<Vector4>(colorIndex), Color::WHITE * 0.5f, TEST_LOCATION );
1112 application.Render(500);
1114 DALI_TEST_EQUALS( material.GetProperty<Vector4>(colorIndex), Color::TRANSPARENT, TEST_LOCATION );
1119 int UtcDaliMaterialAnimatedProperty02(void)
1121 TestApplication application;
1123 tet_infoline("Test that a uniform map material property can be animated");
1125 Shader shader = Shader::New( "VertexSource", "FragmentSource");
1126 Material material = Material::New( shader );
1127 material.SetProperty(Material::Property::COLOR, Color::WHITE);
1129 Geometry geometry = CreateQuadGeometry();
1130 Renderer renderer = Renderer::New( geometry, material );
1132 Actor actor = Actor::New();
1133 actor.AddRenderer(renderer);
1134 actor.SetSize(400, 400);
1135 Stage::GetCurrent().Add(actor);
1136 application.SendNotification();
1137 application.Render(0);
1139 Vector4 initialColor = Color::WHITE;
1140 Property::Index colorIndex = material.RegisterProperty( "uFadeColor", initialColor );
1142 TestGlAbstraction& gl = application.GetGlAbstraction();
1144 application.SendNotification();
1145 application.Render(0);
1147 Vector4 actualValue(Vector4::ZERO);
1148 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1149 DALI_TEST_EQUALS( actualValue, initialColor, TEST_LOCATION );
1151 Animation animation = Animation::New(1.0f);
1152 KeyFrames keyFrames = KeyFrames::New();
1153 keyFrames.Add(0.0f, initialColor);
1154 keyFrames.Add(1.0f, Color::TRANSPARENT);
1155 animation.AnimateBetween( Property( material, colorIndex ), keyFrames );
1158 application.SendNotification();
1159 application.Render(500);
1161 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1162 DALI_TEST_EQUALS( actualValue, Color::WHITE * 0.5f, TEST_LOCATION );
1164 application.Render(500);
1165 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
1166 DALI_TEST_EQUALS( actualValue, Color::TRANSPARENT, TEST_LOCATION );