X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=automated-tests%2Fsrc%2Fdali-devel%2Futc-Dali-Material.cpp;h=4ec8459687905208b61188d727574b3f33d6f683;hb=777cc8604ba7d780fd5d424fe15824dfab22d0c7;hp=433520fb403ea9df1cd53148f726ed7ae9e96268;hpb=7882128f66bc91dbca9573caddd312115be440c4;p=platform%2Fcore%2Fuifw%2Fdali-core.git diff --git a/automated-tests/src/dali-devel/utc-Dali-Material.cpp b/automated-tests/src/dali-devel/utc-Dali-Material.cpp index 433520f..4ec8459 100644 --- a/automated-tests/src/dali-devel/utc-Dali-Material.cpp +++ b/automated-tests/src/dali-devel/utc-Dali-Material.cpp @@ -66,14 +66,12 @@ int UtcDaliMaterialCopyConstructor(void) Shader shader = Shader::New("vertexSrc", "fragmentSrc"); Image image = BufferImage::New(32, 32, Pixel::RGBA8888); - Sampler sampler = Sampler::New(image, "sTexture"); Material material = Material::New(shader); - material.AddSampler( sampler ); + material.AddTexture( image, "sTexture" ); Material materialCopy(material); DALI_TEST_CHECK( materialCopy ); - DALI_TEST_EQUALS( materialCopy.GetSamplerAt(0), sampler, TEST_LOCATION ); END_TEST; } @@ -84,16 +82,13 @@ int UtcDaliMaterialAssignmentOperator(void) Shader shader = Shader::New("vertexSrc", "fragmentSrc"); Image image = BufferImage::New(32, 32, Pixel::RGBA8888); - Sampler sampler = Sampler::New(image, "sTexture"); Material material = Material::New(shader); - material.AddSampler( sampler ); Material material2; DALI_TEST_CHECK( !material2 ); material2 = material; DALI_TEST_CHECK( material2 ); - DALI_TEST_EQUALS( material2.GetSamplerAt(0), sampler, TEST_LOCATION ); END_TEST; } @@ -194,58 +189,14 @@ int UtcDaliMaterialGetShader(void) END_TEST; } -int UtcDaliMaterialAddSampler(void) +int UtcDaliMaterialGetNumberOfTextures(void) { TestApplication application; - tet_infoline("Test AddSampler(sampler)"); + tet_infoline("Test GetNumberOfTextures()"); Image image = BufferImage::New(32, 32, Pixel::RGBA8888); - Sampler sampler1 = Sampler::New(image, "sTexture1"); - Sampler sampler2 = Sampler::New(image, "sTexture2"); - - Material material = CreateMaterial(0.5f); - - Geometry geometry = CreateQuadGeometry(); - Renderer renderer = Renderer::New( geometry, material ); - Actor actor = Actor::New(); - actor.AddRenderer(renderer); - actor.SetParentOrigin( ParentOrigin::CENTER ); - actor.SetSize(400, 400); - Stage::GetCurrent().Add( actor ); - - TestGlAbstraction& gl = application.GetGlAbstraction(); - int textureUnit=-1; - - material.AddSampler( sampler1 ); - application.SendNotification(); - application.Render(); - DALI_TEST_CHECK( gl.GetUniformValue( "sTexture1", textureUnit ) ); - DALI_TEST_EQUALS( textureUnit, 0, TEST_LOCATION ); - - material.AddSampler( sampler2 ); - application.SendNotification(); - application.Render(); - DALI_TEST_CHECK( gl.GetUniformValue( "sTexture2", textureUnit ) ); - DALI_TEST_EQUALS( textureUnit, 1, TEST_LOCATION ); - - END_TEST; -} - -int UtcDaliMaterialGetNumberOfSampler(void) -{ - TestApplication application; - - tet_infoline("Test GetNumberOfSampler()"); - - Image image = BufferImage::New(32, 32, Pixel::RGBA8888); - Sampler sampler0 = Sampler::New(image, "sTexture0"); - Sampler sampler1 = Sampler::New(image, "sTexture1"); - Sampler sampler2 = Sampler::New(image, "sTexture2"); - Sampler sampler3 = Sampler::New(image, "sTexture3"); - Sampler sampler4 = Sampler::New(image, "sTexture4"); - - Material material = CreateMaterial(0.5f); + Material material = CreateMaterial(); Geometry geometry = CreateQuadGeometry(); Renderer renderer = Renderer::New( geometry, material ); @@ -255,149 +206,135 @@ int UtcDaliMaterialGetNumberOfSampler(void) actor.SetSize(400, 400); Stage::GetCurrent().Add( actor ); - material.AddSampler( sampler0 ); - material.AddSampler( sampler1 ); - DALI_TEST_EQUALS( material.GetNumberOfSamplers(), 2u, TEST_LOCATION ); + material.AddTexture( image, "sTexture0" ); + material.AddTexture( image, "sTexture1" ); + DALI_TEST_EQUALS( material.GetNumberOfTextures(), 2u, TEST_LOCATION ); - material.AddSampler( sampler2 ); - material.AddSampler( sampler3 ); - material.AddSampler( sampler4 ); - DALI_TEST_EQUALS( material.GetNumberOfSamplers(), 5u, TEST_LOCATION ); + material.AddTexture( image, "sTexture2" ); + material.AddTexture( image, "sTexture3" ); + material.AddTexture( image, "sTexture4" ); + DALI_TEST_EQUALS( material.GetNumberOfTextures(), 5u, TEST_LOCATION ); - material.RemoveSampler(3); // remove sampler3 - DALI_TEST_EQUALS( material.GetNumberOfSamplers(), 4u, TEST_LOCATION ); + material.RemoveTexture(3); + DALI_TEST_EQUALS( material.GetNumberOfTextures(), 4u, TEST_LOCATION ); - material.RemoveSampler(3); // remove sampler4 - material.RemoveSampler(0); // remove sampler0 - DALI_TEST_EQUALS( material.GetNumberOfSamplers(), 2u, TEST_LOCATION ); + material.RemoveTexture(3); + material.RemoveTexture(0); + DALI_TEST_EQUALS( material.GetNumberOfTextures(), 2u, TEST_LOCATION ); END_TEST; } -int UtcDaliMaterialRemoveSampler(void) +int UtcDaliMaterialConstraint(void) { TestApplication application; - tet_infoline("Test RemoveSampler(index)"); - Image image = BufferImage::New(32, 32, Pixel::RGBA8888); - Sampler sampler1 = Sampler::New(image, "sTexture1"); - Sampler sampler2 = Sampler::New(image, "sTexture2"); + tet_infoline("Test that a custom material property can be constrained"); - Material material = CreateMaterial(0.5f); + Shader shader = Shader::New( "VertexSource", "FragmentSource"); + Material material = Material::New( shader ); Geometry geometry = CreateQuadGeometry(); Renderer renderer = Renderer::New( geometry, material ); + Actor actor = Actor::New(); actor.AddRenderer(renderer); - actor.SetParentOrigin( ParentOrigin::CENTER ); actor.SetSize(400, 400); - Stage::GetCurrent().Add( actor ); + Stage::GetCurrent().Add(actor); - material.AddSampler( sampler1 ); - material.AddSampler( sampler2 ); + Vector4 initialColor = Color::WHITE; + Property::Index colorIndex = material.RegisterProperty( "uFadeColor", initialColor ); - TestGlAbstraction& gl = application.GetGlAbstraction(); - int textureUnit=-1; application.SendNotification(); - application.Render(); - DALI_TEST_CHECK( gl.GetUniformValue( "sTexture1", textureUnit ) ); - DALI_TEST_EQUALS( textureUnit, 0, TEST_LOCATION ); - DALI_TEST_CHECK( gl.GetUniformValue( "sTexture2", textureUnit ) ); - DALI_TEST_EQUALS( textureUnit, 1, TEST_LOCATION ); + application.Render(0); + DALI_TEST_EQUALS( material.GetProperty(colorIndex), initialColor, TEST_LOCATION ); - material.RemoveSampler(0); // remove sampler1 + // Apply constraint + Constraint constraint = Constraint::New( material, colorIndex, TestConstraintNoBlue ); + constraint.Apply(); application.SendNotification(); - application.Render(); - // Todo: test the sampler is removed from gl, cannot pass this test with current implementation - //DALI_TEST_CHECK( ! gl.GetUniformValue( "sTexture1", textureUnit ) ); - DALI_TEST_EQUALS( material.GetNumberOfSamplers(), 1u, TEST_LOCATION ); + application.Render(0); + + // Expect no blue component in either buffer - yellow + DALI_TEST_EQUALS( material.GetProperty(colorIndex), Color::YELLOW, TEST_LOCATION ); + application.Render(0); + DALI_TEST_EQUALS( material.GetProperty(colorIndex), Color::YELLOW, TEST_LOCATION ); - material.RemoveSampler(0); // remove sampler2 + material.RemoveConstraints(); + material.SetProperty(colorIndex, Color::WHITE ); application.SendNotification(); - application.Render(); - // Todo: test the sampler is removed from gl, cannot pass this test with current implementation - //DALI_TEST_CHECK( ! gl.GetUniformValue( "sTexture2", textureUnit ) ); - DALI_TEST_EQUALS( material.GetNumberOfSamplers(), 0u, TEST_LOCATION ); + application.Render(0); + DALI_TEST_EQUALS( material.GetProperty(colorIndex), Color::WHITE, TEST_LOCATION ); END_TEST; } -int UtcDaliMaterialGetSamplerAt(void) +int UtcDaliMaterialConstraint02(void) { TestApplication application; - tet_infoline("Test GetSamplerAt(index)"); - - Image image = BufferImage::New(16, 16, Pixel::RGBA8888); - Sampler sampler1 = Sampler::New(image, "sTexture1"); - Sampler sampler2 = Sampler::New(image, "sTexture2"); - Sampler sampler3 = Sampler::New(image, "sTexture3"); + tet_infoline("Test that a uniform map material property can be constrained"); - Material material = CreateMaterial(0.5f); - material.AddSampler( sampler1 ); - material.AddSampler( sampler2 ); - material.AddSampler( sampler3 ); + Shader shader = Shader::New( "VertexSource", "FragmentSource"); + Material material = Material::New( shader ); Geometry geometry = CreateQuadGeometry(); Renderer renderer = Renderer::New( geometry, material ); + Actor actor = Actor::New(); actor.AddRenderer(renderer); - actor.SetParentOrigin( ParentOrigin::CENTER ); actor.SetSize(400, 400); - Stage::GetCurrent().Add( actor ); - + Stage::GetCurrent().Add(actor); application.SendNotification(); - application.Render(); + application.Render(0); - DALI_TEST_EQUALS( material.GetSamplerAt( 0 ), sampler1, TEST_LOCATION ); - DALI_TEST_EQUALS( material.GetSamplerAt( 1 ), sampler2, TEST_LOCATION ); - DALI_TEST_EQUALS( material.GetSamplerAt( 2 ), sampler3, TEST_LOCATION ); + Vector4 initialColor = Color::WHITE; + Property::Index colorIndex = material.RegisterProperty( "uFadeColor", initialColor ); - Sampler sampler = material.GetSamplerAt( 1 ); - DALI_TEST_EQUALS( sampler.GetImage().GetWidth(), 16u, TEST_LOCATION ); + TestGlAbstraction& gl = application.GetGlAbstraction(); - END_TEST; -} + application.SendNotification(); + application.Render(0); -int UtcDaliMaterialSetFaceCullingMode(void) -{ - TestApplication application; + Vector4 actualValue(Vector4::ZERO); + DALI_TEST_CHECK( gl.GetUniformValue( "uFadeColor", actualValue ) ); + DALI_TEST_EQUALS( actualValue, initialColor, TEST_LOCATION ); - tet_infoline("Test SetFaceCullingMode(cullingMode)"); - Geometry geometry = CreateQuadGeometry(); - Material material = CreateMaterial(0.5f); - Renderer renderer = Renderer::New( geometry, material ); + // Apply constraint + Constraint constraint = Constraint::New( material, colorIndex, TestConstraintNoBlue ); + constraint.Apply(); + application.SendNotification(); + application.Render(0); - Actor actor = Actor::New(); - actor.AddRenderer(renderer); - actor.SetSize(400, 400); - Stage::GetCurrent().Add(actor); + // Expect no blue component in either buffer - yellow + DALI_TEST_CHECK( gl.GetUniformValue( "uFadeColor", actualValue ) ); + DALI_TEST_EQUALS( actualValue, Color::YELLOW, TEST_LOCATION ); - TestGlAbstraction& gl = application.GetGlAbstraction(); - TraceCallStack& cullFaceStack = gl.GetCullFaceTrace(); - cullFaceStack.Reset(); - gl.EnableCullFaceCallTrace(true); + application.Render(0); + DALI_TEST_CHECK( gl.GetUniformValue( "uFadeColor", actualValue ) ); + DALI_TEST_EQUALS( actualValue, Color::YELLOW, TEST_LOCATION ); - material.SetFaceCullingMode( Material::CULL_BACK_AND_FRONT); + material.RemoveConstraints(); + material.SetProperty(colorIndex, Color::WHITE ); application.SendNotification(); - application.Render(); + application.Render(0); - // Todo: test the glCullFace(GL_FRONT_AND_BACK) is actually been called, cannot pass this test with current implementation - DALI_TEST_EQUALS( cullFaceStack.CountMethod( "CullFace" ), 0, TEST_LOCATION); - //string parameter("GL_FRONT_AND_BACK" ); - //DALI_TEST_CHECK( cullFaceStack.TestMethodAndParams(0, "CullFace", parameter) ); + DALI_TEST_CHECK( gl.GetUniformValue( "uFadeColor", actualValue ) ); + DALI_TEST_EQUALS( actualValue, Color::WHITE, TEST_LOCATION ); END_TEST; } -int UtcDaliMaterialBlendingOptions01(void) +int UtcDaliMaterialAnimatedProperty01(void) { TestApplication application; - tet_infoline("Test SetBlendFunc(src, dest) "); + tet_infoline("Test that a non-uniform material property can be animated"); + + Shader shader = Shader::New( "VertexSource", "FragmentSource"); + Material material = Material::New( shader ); Geometry geometry = CreateQuadGeometry(); - Material material = CreateMaterial(0.5f); Renderer renderer = Renderer::New( geometry, material ); Actor actor = Actor::New(); @@ -405,765 +342,417 @@ int UtcDaliMaterialBlendingOptions01(void) actor.SetSize(400, 400); Stage::GetCurrent().Add(actor); - material.SetBlendFunc(BlendingFactor::ONE_MINUS_SRC_COLOR, BlendingFactor::SRC_ALPHA_SATURATE); + Vector4 initialColor = Color::WHITE; + Property::Index colorIndex = material.RegisterProperty( "uFadeColor", initialColor ); - // Test that Set was successful: - { - BlendingFactor::Type srcFactorRgb( BlendingFactor::ZERO ); - BlendingFactor::Type destFactorRgb( BlendingFactor::ZERO ); - BlendingFactor::Type srcFactorAlpha( BlendingFactor::ZERO ); - BlendingFactor::Type destFactorAlpha( BlendingFactor::ZERO ); - material.GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha ); + application.SendNotification(); + application.Render(0); + DALI_TEST_EQUALS( material.GetProperty(colorIndex), initialColor, TEST_LOCATION ); - DALI_TEST_EQUALS( BlendingFactor::ONE_MINUS_SRC_COLOR, srcFactorRgb, TEST_LOCATION ); - DALI_TEST_EQUALS( BlendingFactor::SRC_ALPHA_SATURATE, destFactorRgb, TEST_LOCATION ); - DALI_TEST_EQUALS( BlendingFactor::ONE_MINUS_SRC_COLOR, srcFactorAlpha, TEST_LOCATION ); - DALI_TEST_EQUALS( BlendingFactor::SRC_ALPHA_SATURATE, destFactorAlpha, TEST_LOCATION ); - } + Animation animation = Animation::New(1.0f); + KeyFrames keyFrames = KeyFrames::New(); + keyFrames.Add(0.0f, initialColor); + keyFrames.Add(1.0f, Color::TRANSPARENT); + animation.AnimateBetween( Property( material, colorIndex ), keyFrames ); + animation.Play(); application.SendNotification(); - application.Render(); + application.Render(500); + + DALI_TEST_EQUALS( material.GetProperty(colorIndex), Color::WHITE * 0.5f, TEST_LOCATION ); - TestGlAbstraction& glAbstraction = application.GetGlAbstraction(); + application.Render(500); - DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_SRC_COLOR, glAbstraction.GetLastBlendFuncSrcRgb(), TEST_LOCATION ); - DALI_TEST_EQUALS( (GLenum)GL_SRC_ALPHA_SATURATE, glAbstraction.GetLastBlendFuncDstRgb(), TEST_LOCATION ); - DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_SRC_COLOR, glAbstraction.GetLastBlendFuncSrcAlpha(), TEST_LOCATION ); - DALI_TEST_EQUALS( (GLenum)GL_SRC_ALPHA_SATURATE, glAbstraction.GetLastBlendFuncDstAlpha(), TEST_LOCATION ); + DALI_TEST_EQUALS( material.GetProperty(colorIndex), Color::TRANSPARENT, TEST_LOCATION ); END_TEST; } -int UtcDaliMaterialBlendingOptions02(void) +int UtcDaliMaterialAnimatedProperty02(void) { TestApplication application; - tet_infoline("Test SetBlendFunc(srcRgb, destRgb, srcAlpha, destAlpha) "); + tet_infoline("Test that a uniform map material property can be animated"); + + Shader shader = Shader::New( "VertexSource", "FragmentSource"); + Material material = Material::New( shader ); Geometry geometry = CreateQuadGeometry(); - Material material = CreateMaterial(0.5f); Renderer renderer = Renderer::New( geometry, material ); Actor actor = Actor::New(); actor.AddRenderer(renderer); actor.SetSize(400, 400); Stage::GetCurrent().Add(actor); - - material.SetBlendFunc( BlendingFactor::CONSTANT_COLOR, BlendingFactor::ONE_MINUS_CONSTANT_COLOR, - BlendingFactor::CONSTANT_ALPHA, BlendingFactor::ONE_MINUS_CONSTANT_ALPHA ); - - // Test that Set was successful: - { - BlendingFactor::Type srcFactorRgb( BlendingFactor::ZERO ); - BlendingFactor::Type destFactorRgb( BlendingFactor::ZERO ); - BlendingFactor::Type srcFactorAlpha( BlendingFactor::ZERO ); - BlendingFactor::Type destFactorAlpha( BlendingFactor::ZERO ); - material.GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha ); - - DALI_TEST_EQUALS( BlendingFactor::CONSTANT_COLOR, srcFactorRgb, TEST_LOCATION ); - DALI_TEST_EQUALS( BlendingFactor::ONE_MINUS_CONSTANT_COLOR, destFactorRgb, TEST_LOCATION ); - DALI_TEST_EQUALS( BlendingFactor::CONSTANT_ALPHA, srcFactorAlpha, TEST_LOCATION ); - DALI_TEST_EQUALS( BlendingFactor::ONE_MINUS_CONSTANT_ALPHA, destFactorAlpha, TEST_LOCATION ); - } - application.SendNotification(); - application.Render(); - - TestGlAbstraction& glAbstraction = application.GetGlAbstraction(); - DALI_TEST_EQUALS( (GLenum)GL_CONSTANT_COLOR, glAbstraction.GetLastBlendFuncSrcRgb(), TEST_LOCATION ); - DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_CONSTANT_COLOR, glAbstraction.GetLastBlendFuncDstRgb(), TEST_LOCATION ); - DALI_TEST_EQUALS( (GLenum)GL_CONSTANT_ALPHA, glAbstraction.GetLastBlendFuncSrcAlpha(), TEST_LOCATION ); - DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_CONSTANT_ALPHA, glAbstraction.GetLastBlendFuncDstAlpha(), TEST_LOCATION ); + application.Render(0); - END_TEST; -} + Vector4 initialColor = Color::WHITE; + Property::Index colorIndex = material.RegisterProperty( "uFadeColor", initialColor ); + TestGlAbstraction& gl = application.GetGlAbstraction(); + application.SendNotification(); + application.Render(0); -int UtcDaliMaterialBlendingOptions03(void) -{ - TestApplication application; + Vector4 actualValue(Vector4::ZERO); + DALI_TEST_CHECK( gl.GetUniformValue( "uFadeColor", actualValue ) ); + DALI_TEST_EQUALS( actualValue, initialColor, TEST_LOCATION ); - tet_infoline("Test GetBlendEquation() defaults "); + Animation animation = Animation::New(1.0f); + KeyFrames keyFrames = KeyFrames::New(); + keyFrames.Add(0.0f, initialColor); + keyFrames.Add(1.0f, Color::TRANSPARENT); + animation.AnimateBetween( Property( material, colorIndex ), keyFrames ); + animation.Play(); - Geometry geometry = CreateQuadGeometry(); - Material material = CreateMaterial(0.5f); - Renderer renderer = Renderer::New( geometry, material ); + application.SendNotification(); + application.Render(500); - Actor actor = Actor::New(); - actor.AddRenderer(renderer); - actor.SetSize(400, 400); - Stage::GetCurrent().Add(actor); + DALI_TEST_CHECK( gl.GetUniformValue( "uFadeColor", actualValue ) ); + DALI_TEST_EQUALS( actualValue, Color::WHITE * 0.5f, TEST_LOCATION ); - // Test the defaults as documented in blending.h - { - BlendingEquation::Type equationRgb( BlendingEquation::SUBTRACT ); - BlendingEquation::Type equationAlpha( BlendingEquation::SUBTRACT ); - material.GetBlendEquation( equationRgb, equationAlpha ); - DALI_TEST_EQUALS( BlendingEquation::ADD, equationRgb, TEST_LOCATION ); - DALI_TEST_EQUALS( BlendingEquation::ADD, equationAlpha, TEST_LOCATION ); - } + application.Render(500); + DALI_TEST_CHECK( gl.GetUniformValue( "uFadeColor", actualValue ) ); + DALI_TEST_EQUALS( actualValue, Color::TRANSPARENT, TEST_LOCATION ); END_TEST; } -int UtcDaliMaterialBlendingOptions04(void) +int UtcDaliMaterialSetTextureUniformName01(void) { TestApplication application; - tet_infoline("Test SetBlendEquation() "); + Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 ); + + Material material = CreateMaterial(); + material.AddTexture( image, "sTexture" ); + + int textureIndex = material.GetTextureIndex( "sTexture" ); + DALI_TEST_EQUALS( textureIndex, 0, TEST_LOCATION ); + + material.SetTextureUniformName( 0, "sEffectTexture" ); + textureIndex = material.GetTextureIndex( "sEffectTexture" ); + DALI_TEST_EQUALS( textureIndex, 0, TEST_LOCATION ); Geometry geometry = CreateQuadGeometry(); - Material material = CreateMaterial(0.5f); Renderer renderer = Renderer::New( geometry, material ); - Actor actor = Actor::New(); actor.AddRenderer(renderer); + actor.SetParentOrigin( ParentOrigin::CENTER ); actor.SetSize(400, 400); - Stage::GetCurrent().Add(actor); - // Test the single blending equation setting - { - material.SetBlendEquation( BlendingEquation::REVERSE_SUBTRACT ); - BlendingEquation::Type equationRgba( BlendingEquation::SUBTRACT ); - material.GetBlendEquation( equationRgba, equationRgba ); - DALI_TEST_EQUALS( BlendingEquation::REVERSE_SUBTRACT, equationRgba, TEST_LOCATION ); - } - - material.SetBlendEquation( BlendingEquation::REVERSE_SUBTRACT, BlendingEquation::REVERSE_SUBTRACT ); - - // Test that Set was successful - { - BlendingEquation::Type equationRgb( BlendingEquation::SUBTRACT ); - BlendingEquation::Type equationAlpha( BlendingEquation::SUBTRACT ); - material.GetBlendEquation( equationRgb, equationAlpha ); - DALI_TEST_EQUALS( BlendingEquation::REVERSE_SUBTRACT, equationRgb, TEST_LOCATION ); - DALI_TEST_EQUALS( BlendingEquation::REVERSE_SUBTRACT, equationAlpha, TEST_LOCATION ); - } - - // Render & check GL commands + Stage::GetCurrent().Add( actor ); + + TestGlAbstraction& gl = application.GetGlAbstraction(); + application.SendNotification(); application.Render(); - TestGlAbstraction& glAbstraction = application.GetGlAbstraction(); - DALI_TEST_EQUALS( (GLenum)GL_FUNC_REVERSE_SUBTRACT, glAbstraction.GetLastBlendEquationRgb(), TEST_LOCATION ); - DALI_TEST_EQUALS( (GLenum)GL_FUNC_REVERSE_SUBTRACT, glAbstraction.GetLastBlendEquationAlpha(), TEST_LOCATION ); + int textureUnit=-1; + DALI_TEST_CHECK( gl.GetUniformValue( "sEffectTexture", textureUnit ) ); + DALI_TEST_EQUALS( textureUnit, 0, TEST_LOCATION ); END_TEST; } -int UtcDaliMaterialSetBlendMode01(void) +int UtcDaliMaterialSetTextureUniformName02(void) { TestApplication application; - tet_infoline("Test setting the blend mode to on with an opaque color renders with blending enabled"); + Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 ); + Image image2 = BufferImage::New( 64, 64, Pixel::RGBA8888 ); + + Material material = CreateMaterial(); + material.AddTexture( image, "sTexture"); + material.SetTextureUniformName( 0, "sEffectTexture" ); + material.AddTexture( image2, "sTexture2"); + + int textureIndex = material.GetTextureIndex( "sEffectTexture" ); + DALI_TEST_EQUALS( textureIndex, 0, TEST_LOCATION ); + + textureIndex = material.GetTextureIndex( "sTexture2" ); + DALI_TEST_EQUALS( textureIndex, 1, TEST_LOCATION ); Geometry geometry = CreateQuadGeometry(); - Material material = CreateMaterial(1.0f); Renderer renderer = Renderer::New( geometry, material ); - Actor actor = Actor::New(); actor.AddRenderer(renderer); + actor.SetParentOrigin( ParentOrigin::CENTER ); actor.SetSize(400, 400); - Stage::GetCurrent().Add(actor); - material.SetBlendMode(BlendingMode::ON); + Stage::GetCurrent().Add( actor ); - TestGlAbstraction& glAbstraction = application.GetGlAbstraction(); - glAbstraction.EnableCullFaceCallTrace(true); + TestGlAbstraction& gl = application.GetGlAbstraction(); application.SendNotification(); application.Render(); - TraceCallStack& glEnableStack = glAbstraction.GetCullFaceTrace(); - std::ostringstream blendStr; - blendStr << GL_BLEND; - DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) ); + int textureUnit=-1; + DALI_TEST_CHECK( gl.GetUniformValue( "sEffectTexture", textureUnit ) ); + DALI_TEST_EQUALS( textureUnit, 0, TEST_LOCATION ); + + DALI_TEST_CHECK( gl.GetUniformValue( "sTexture2", textureUnit ) ); + DALI_TEST_EQUALS( textureUnit, 1, TEST_LOCATION ); END_TEST; } - -int UtcDaliMaterialSetBlendMode02(void) +int UtcDaliMaterialAddTexture01(void) { TestApplication application; - tet_infoline("Test setting the blend mode to off with a transparent color renders with blending disabled (and not enabled)"); + Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 ); + + Material material = CreateMaterial(); + material.AddTexture( image, "sTexture"); Geometry geometry = CreateQuadGeometry(); - Material material = CreateMaterial(0.5f); Renderer renderer = Renderer::New( geometry, material ); - Actor actor = Actor::New(); actor.AddRenderer(renderer); + actor.SetParentOrigin( ParentOrigin::CENTER ); actor.SetSize(400, 400); - Stage::GetCurrent().Add(actor); - material.SetBlendMode(BlendingMode::OFF); + Stage::GetCurrent().Add( actor ); - TestGlAbstraction& glAbstraction = application.GetGlAbstraction(); - glAbstraction.EnableCullFaceCallTrace(true); + TestGlAbstraction& gl = application.GetGlAbstraction(); + TraceCallStack& texParameterTrace = gl.GetTexParameterTrace(); + texParameterTrace.Reset(); + texParameterTrace.Enable( true ); application.SendNotification(); application.Render(); - TraceCallStack& glEnableStack = glAbstraction.GetCullFaceTrace(); - std::ostringstream blendStr; - blendStr << GL_BLEND; - DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) ); + int textureUnit=-1; + DALI_TEST_CHECK( gl.GetUniformValue( "sTexture", textureUnit ) ); + DALI_TEST_EQUALS( textureUnit, 0, TEST_LOCATION ); + + texParameterTrace.Enable( false ); + + // Verify gl state + // There are three calls to TexParameteri when the texture is first created + // as the texture is using default sampling parametrers there shouldn't be any more calls to TexParameteri + DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 3, TEST_LOCATION); END_TEST; } -int UtcDaliMaterialSetBlendMode03(void) +int UtcDaliMaterialAddTexture02(void) { TestApplication application; - tet_infoline("Test setting the blend mode to auto with a transparent material color renders with blending enabled"); + Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 ); + + Material material = CreateMaterial(); + + Sampler sampler = Sampler::New(); + sampler.SetFilterMode( FilterMode::NEAREST, FilterMode::NEAREST ); + material.AddTexture( image, "sTexture", sampler ); Geometry geometry = CreateQuadGeometry(); - Material material = CreateMaterial(0.5f); Renderer renderer = Renderer::New( geometry, material ); - Actor actor = Actor::New(); actor.AddRenderer(renderer); + actor.SetParentOrigin( ParentOrigin::CENTER ); actor.SetSize(400, 400); - Stage::GetCurrent().Add(actor); - material.SetBlendMode(BlendingMode::AUTO); + Stage::GetCurrent().Add( actor ); - TestGlAbstraction& glAbstraction = application.GetGlAbstraction(); - glAbstraction.EnableCullFaceCallTrace(true); + TestGlAbstraction& gl = application.GetGlAbstraction(); + TraceCallStack& texParameterTrace = gl.GetTexParameterTrace(); + texParameterTrace.Reset(); + texParameterTrace.Enable( true ); application.SendNotification(); application.Render(); - TraceCallStack& glEnableStack = glAbstraction.GetCullFaceTrace(); - std::ostringstream blendStr; - blendStr << GL_BLEND; - DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) ); + int textureUnit=-1; + DALI_TEST_CHECK( gl.GetUniformValue( "sTexture", textureUnit ) ); + DALI_TEST_EQUALS( textureUnit, 0, TEST_LOCATION ); + + texParameterTrace.Enable( false ); + + // Verify gl state + // There are three calls to TexParameteri when the texture is first created + // Texture minification and magnification filters are now different than default so + //there should have been two extra TexParameteri calls to set the new filter mode + DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 4, TEST_LOCATION); END_TEST; } -int UtcDaliMaterialSetBlendMode04(void) +int UtcDaliMaterialRemoveTexture(void) { TestApplication application; - tet_infoline("Test setting the blend mode to auto with an opaque color renders with blending disabled"); - - Geometry geometry = CreateQuadGeometry(); - Material material = CreateMaterial(1.0f); - Renderer renderer = Renderer::New( geometry, material ); + Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 ); - Actor actor = Actor::New(); - actor.AddRenderer(renderer); - actor.SetSize(400, 400); - Stage::GetCurrent().Add(actor); + Material material = CreateMaterial(); + material.RemoveTexture(0); + DALI_TEST_EQUALS( material.GetNumberOfTextures(), 0u, TEST_LOCATION ); - material.SetBlendMode(BlendingMode::AUTO); + material.RemoveTexture(1); + DALI_TEST_EQUALS( material.GetNumberOfTextures(), 0u, TEST_LOCATION ); - TestGlAbstraction& glAbstraction = application.GetGlAbstraction(); - glAbstraction.EnableCullFaceCallTrace(true); + Sampler sampler = Sampler::New(); + sampler.SetFilterMode( FilterMode::NEAREST, FilterMode::NEAREST ); + material.AddTexture( image, "sTexture", sampler ); + DALI_TEST_EQUALS( material.GetNumberOfTextures(), 1u, TEST_LOCATION ); - application.SendNotification(); - application.Render(); + material.RemoveTexture(1); + DALI_TEST_EQUALS( material.GetNumberOfTextures(), 1u, TEST_LOCATION ); - TraceCallStack& glEnableStack = glAbstraction.GetCullFaceTrace(); - std::ostringstream blendStr; - blendStr << GL_BLEND; - DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) ); + material.RemoveTexture(0); + DALI_TEST_EQUALS( material.GetNumberOfTextures(), 0u, TEST_LOCATION ); END_TEST; } -int UtcDaliMaterialSetBlendMode04b(void) +int UtcDaliMaterialSetSampler(void) { TestApplication application; - tet_infoline("Test setting the blend mode to auto with an opaque material color and a transparent actor color renders with blending enabled"); + Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 ); + + Material material = CreateMaterial(); + material.AddTexture( image, "sTexture"); Geometry geometry = CreateQuadGeometry(); - Material material = CreateMaterial(1.0f); Renderer renderer = Renderer::New( geometry, material ); - Actor actor = Actor::New(); actor.AddRenderer(renderer); + actor.SetParentOrigin( ParentOrigin::CENTER ); actor.SetSize(400, 400); - actor.SetColor( Vector4(1.0f, 0.0f, 1.0f, 0.5f) ); - Stage::GetCurrent().Add(actor); - material.SetBlendMode(BlendingMode::AUTO); + Stage::GetCurrent().Add( actor ); - TestGlAbstraction& glAbstraction = application.GetGlAbstraction(); - glAbstraction.EnableCullFaceCallTrace(true); + TestGlAbstraction& gl = application.GetGlAbstraction(); + TraceCallStack& texParameterTrace = gl.GetTexParameterTrace(); + texParameterTrace.Reset(); + texParameterTrace.Enable( true ); application.SendNotification(); application.Render(); - TraceCallStack& glEnableStack = glAbstraction.GetCullFaceTrace(); - std::ostringstream blendStr; - blendStr << GL_BLEND; - DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) ); - - END_TEST; -} - -int UtcDaliMaterialSetBlendMode04c(void) -{ - TestApplication application; + int textureUnit=-1; + DALI_TEST_CHECK( gl.GetUniformValue( "sTexture", textureUnit ) ); + DALI_TEST_EQUALS( textureUnit, 0, TEST_LOCATION ); - tet_infoline("Test setting the blend mode to auto with an opaque material color and an opaque actor color renders with blending disabled"); + texParameterTrace.Enable( false ); - Geometry geometry = CreateQuadGeometry(); - Material material = CreateMaterial(1.0f); - Renderer renderer = Renderer::New( geometry, material ); + // Verify gl state + // There are three calls to TexParameteri when the texture is first created + // as the texture is using default sampling parametrers there shouldn't be any more calls to TexParameteri + DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 3, TEST_LOCATION); - Actor actor = Actor::New(); - actor.AddRenderer(renderer); - actor.SetSize(400, 400); - actor.SetColor( Color::MAGENTA ); - Stage::GetCurrent().Add(actor); + texParameterTrace.Reset(); + texParameterTrace.Enable( true ); - material.SetBlendMode(BlendingMode::AUTO); + Sampler sampler = Sampler::New(); + sampler.SetFilterMode( FilterMode::NEAREST, FilterMode::NEAREST ); + material.SetTextureSampler(0, sampler ); - TestGlAbstraction& glAbstraction = application.GetGlAbstraction(); - glAbstraction.EnableCullFaceCallTrace(true); application.SendNotification(); application.Render(); - TraceCallStack& glEnableStack = glAbstraction.GetCullFaceTrace(); - std::ostringstream blendStr; - blendStr << GL_BLEND; - DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) ); + texParameterTrace.Enable( false ); + + // Verify gl state + //There should have been two calls to TexParameteri to set the new filtering mode + DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 2, TEST_LOCATION); + END_TEST; } -int UtcDaliMaterialSetBlendMode05(void) +int UtcDaliMaterialGetTextureIndex(void) { TestApplication application; - tet_infoline("Test setting the blend mode to auto with an opaque color and an image with an alpha channel renders with blending enabled"); + Image image0 = BufferImage::New( 64, 64, Pixel::RGBA8888 ); + Image image1 = BufferImage::New( 64, 64, Pixel::RGBA8888 ); + Image image2 = BufferImage::New( 64, 64, Pixel::RGBA8888 ); + Image image3 = BufferImage::New( 64, 64, Pixel::RGBA8888 ); - Geometry geometry = CreateQuadGeometry(); - BufferImage image = BufferImage::New( 40, 40, Pixel::RGBA8888 ); - Material material = CreateMaterial(1.0f, image); - Renderer renderer = Renderer::New( geometry, material ); - - Actor actor = Actor::New(); - actor.AddRenderer(renderer); - actor.SetSize(400, 400); - Stage::GetCurrent().Add(actor); - - material.SetBlendMode(BlendingMode::AUTO); - - TestGlAbstraction& glAbstraction = application.GetGlAbstraction(); - glAbstraction.EnableCullFaceCallTrace(true); - - application.SendNotification(); - application.Render(); - - TraceCallStack& glEnableStack = glAbstraction.GetCullFaceTrace(); - std::ostringstream blendStr; - blendStr << GL_BLEND; - DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) ); - - END_TEST; -} - -int UtcDaliMaterialSetBlendMode06(void) -{ - TestApplication application; - 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"); - - Geometry geometry = CreateQuadGeometry(); - Shader shader = Shader::New( "vertexSrc", "fragmentSrc", Shader::HINT_OUTPUT_IS_TRANSPARENT ); - Material material = Material::New(shader); - material.SetProperty(Material::Property::COLOR, Color::WHITE); - - Renderer renderer = Renderer::New( geometry, material ); - - Actor actor = Actor::New(); - actor.AddRenderer(renderer); - actor.SetSize(400, 400); - Stage::GetCurrent().Add(actor); - - material.SetBlendMode(BlendingMode::AUTO); - - TestGlAbstraction& glAbstraction = application.GetGlAbstraction(); - glAbstraction.EnableCullFaceCallTrace(true); - - application.SendNotification(); - application.Render(); - - TraceCallStack& glEnableStack = glAbstraction.GetCullFaceTrace(); - std::ostringstream blendStr; - blendStr << GL_BLEND; - DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) ); - - END_TEST; -} - - -//Todo: test the Shader::HINT_OUTPUT_IS_OPAQUE would disable the blending, the test cannot pass with current implementation -/*int UtcDaliMaterialSetBlendMode07(void) -{ - TestApplication application; - 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"); - Geometry geometry = CreateQuadGeometry(); - Shader shader = Shader::New( "vertexSrc", "fragmentSrc", Shader::HINT_OUTPUT_IS_OPAQUE ); - Material material = Material::New(shader); - material.SetProperty(Material::Property::COLOR, Color::TRANSPARENT); - - Renderer renderer = Renderer::New( geometry, material ); - - Actor actor = Actor::New(); - actor.AddRenderer(renderer); - actor.SetSize(400, 400); - Stage::GetCurrent().Add(actor); - - material.SetBlendMode(BlendingMode::AUTO); - - TestGlAbstraction& glAbstraction = application.GetGlAbstraction(); - glAbstraction.EnableCullFaceCallTrace(true); - - application.SendNotification(); - application.Render(); - - TraceCallStack& glEnableStack = glAbstraction.GetCullFaceTrace(); - std::ostringstream blendStr; - blendStr << GL_BLEND; - DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) ); - - END_TEST; -}*/ - -int UtcDaliMaterialSetBlendMode08(void) -{ - TestApplication application; - 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"); - - Geometry geometry = CreateQuadGeometry(); - Shader shader = Shader::New( "vertexSrc", "fragmentSrc", Shader::HINT_OUTPUT_IS_OPAQUE ); - Material material = Material::New(shader); - material.SetProperty(Material::Property::COLOR, Color::WHITE); - BufferImage image = BufferImage::New( 50, 50, Pixel::RGB888 ); - Sampler sampler = Sampler::New( image, "sTexture" ); - material.AddSampler( sampler ); - Renderer renderer = Renderer::New( geometry, material ); - - Actor actor = Actor::New(); - actor.AddRenderer(renderer); - actor.SetSize(400, 400); - Stage::GetCurrent().Add(actor); - - material.SetBlendMode(BlendingMode::AUTO); - - TestGlAbstraction& glAbstraction = application.GetGlAbstraction(); - glAbstraction.EnableCullFaceCallTrace(true); - - application.SendNotification(); - application.Render(); - - TraceCallStack& glEnableStack = glAbstraction.GetCullFaceTrace(); - std::ostringstream blendStr; - blendStr << GL_BLEND; - DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) ); - - END_TEST; -} - -int UtcDaliMaterialGetBlendMode(void) -{ - TestApplication application; - - tet_infoline("Test GetBlendMode()"); - - Shader shader = Shader::New( "vertexSrc", "fragmentSrc", Shader::HINT_OUTPUT_IS_OPAQUE ); - Material material = Material::New(shader); - - // default value - DALI_TEST_EQUALS( material.GetBlendMode(), BlendingMode::OFF, TEST_LOCATION ); - - // AUTO - material.SetBlendMode(BlendingMode::AUTO); - DALI_TEST_EQUALS( material.GetBlendMode(), BlendingMode::AUTO, TEST_LOCATION ); - - // ON - material.SetBlendMode(BlendingMode::ON); - DALI_TEST_EQUALS( material.GetBlendMode(), BlendingMode::ON, TEST_LOCATION ); - - // OFF - material.SetBlendMode(BlendingMode::OFF); - DALI_TEST_EQUALS( material.GetBlendMode(), BlendingMode::OFF, TEST_LOCATION ); - - END_TEST; -} - -int UtcDaliMaterialSetBlendColor(void) -{ - TestApplication application; - - tet_infoline("Test SetBlendColor(color)"); - - Geometry geometry = CreateQuadGeometry(); - Shader shader = Shader::New( "vertexSrc", "fragmentSrc", Shader::HINT_OUTPUT_IS_OPAQUE ); - Material material = Material::New(shader); - material.SetProperty(Material::Property::COLOR, Color::WHITE); - BufferImage image = BufferImage::New( 50, 50, Pixel::RGBA8888 ); - Sampler sampler = Sampler::New( image, "sTexture" ); - material.AddSampler( sampler ); - Renderer renderer = Renderer::New( geometry, material ); - - Actor actor = Actor::New(); - actor.AddRenderer(renderer); - actor.SetSize(400, 400); - Stage::GetCurrent().Add(actor); - - TestGlAbstraction& glAbstraction = application.GetGlAbstraction(); - - application.SendNotification(); - application.Render(); - DALI_TEST_EQUALS( glAbstraction.GetLastBlendColor(), Color::TRANSPARENT, TEST_LOCATION ); - - material.SetBlendColor( Color::MAGENTA ); - application.SendNotification(); - application.Render(); - DALI_TEST_EQUALS( glAbstraction.GetLastBlendColor(), Color::MAGENTA, TEST_LOCATION ); - - Vector4 color( 0.1f, 0.2f, 0.3f, 0.4f ); - material.SetBlendColor( color ); - application.SendNotification(); - application.Render(); - DALI_TEST_EQUALS( glAbstraction.GetLastBlendColor(), color, TEST_LOCATION ); - END_TEST; -} + Material material = CreateMaterial(); + material.AddTexture( image0, "sTexture0"); + material.AddTexture( image1, "sTexture1"); + material.AddTexture( image2, "sTexture2"); + material.AddTexture( image3, "sTexture3"); -int UtcDaliMaterialGetBlendColor(void) -{ - TestApplication application; + int textureIndex = material.GetTextureIndex( "sTexture0" ); + DALI_TEST_EQUALS( textureIndex, 0, TEST_LOCATION ); - tet_infoline("Test GetBlendColor()"); + textureIndex = material.GetTextureIndex( "sTexture1" ); + DALI_TEST_EQUALS( textureIndex, 1, TEST_LOCATION ); - Shader shader = Shader::New( "vertexSrc", "fragmentSrc", Shader::HINT_OUTPUT_IS_OPAQUE ); - Material material = Material::New(shader); - - DALI_TEST_EQUALS( material.GetBlendColor(), Color::TRANSPARENT, TEST_LOCATION ); - - material.SetBlendColor( Color::MAGENTA ); - application.SendNotification(); - application.Render(); - DALI_TEST_EQUALS( material.GetBlendColor(), Color::MAGENTA, TEST_LOCATION ); - - Vector4 color( 0.1f, 0.2f, 0.3f, 0.4f ); - material.SetBlendColor( color ); - application.SendNotification(); - application.Render(); - DALI_TEST_EQUALS( material.GetBlendColor(), color, TEST_LOCATION ); - - END_TEST; -} - -int UtcDaliMaterialConstraint(void) -{ - TestApplication application; - - tet_infoline("Test that a custom material property can be constrained"); - - Shader shader = Shader::New( "VertexSource", "FragmentSource"); - Material material = Material::New( shader ); - material.SetProperty(Material::Property::COLOR, Color::WHITE); - - Geometry geometry = CreateQuadGeometry(); - Renderer renderer = Renderer::New( geometry, material ); - - Actor actor = Actor::New(); - actor.AddRenderer(renderer); - actor.SetSize(400, 400); - Stage::GetCurrent().Add(actor); + textureIndex = material.GetTextureIndex( "sTexture2" ); + DALI_TEST_EQUALS( textureIndex, 2, TEST_LOCATION ); - Vector4 initialColor = Color::WHITE; - Property::Index colorIndex = material.RegisterProperty( "uFadeColor", initialColor ); + textureIndex = material.GetTextureIndex( "sTexture3" ); + DALI_TEST_EQUALS( textureIndex, 3, TEST_LOCATION ); - application.SendNotification(); - application.Render(0); - DALI_TEST_EQUALS( material.GetProperty(colorIndex), initialColor, TEST_LOCATION ); + material.RemoveTexture(1); - // Apply constraint - Constraint constraint = Constraint::New( material, colorIndex, TestConstraintNoBlue ); - constraint.Apply(); - application.SendNotification(); - application.Render(0); + textureIndex = material.GetTextureIndex( "sTexture0" ); + DALI_TEST_EQUALS( textureIndex, 0, TEST_LOCATION ); - // Expect no blue component in either buffer - yellow - DALI_TEST_EQUALS( material.GetProperty(colorIndex), Color::YELLOW, TEST_LOCATION ); - application.Render(0); - DALI_TEST_EQUALS( material.GetProperty(colorIndex), Color::YELLOW, TEST_LOCATION ); + textureIndex = material.GetTextureIndex( "sTexture2" ); + DALI_TEST_EQUALS( textureIndex, 1, TEST_LOCATION ); - material.RemoveConstraints(); - material.SetProperty(colorIndex, Color::WHITE ); - application.SendNotification(); - application.Render(0); - DALI_TEST_EQUALS( material.GetProperty(colorIndex), Color::WHITE, TEST_LOCATION ); + textureIndex = material.GetTextureIndex( "sTexture3" ); + DALI_TEST_EQUALS( textureIndex, 2, TEST_LOCATION ); END_TEST; } -int UtcDaliMaterialConstraint02(void) +int UtcDaliMaterialGetTextureP(void) { TestApplication application; - tet_infoline("Test that a uniform map material property can be constrained"); - - Shader shader = Shader::New( "VertexSource", "FragmentSource"); - Material material = Material::New( shader ); - material.SetProperty(Material::Property::COLOR, Color::WHITE); - - Geometry geometry = CreateQuadGeometry(); - Renderer renderer = Renderer::New( geometry, material ); - - Actor actor = Actor::New(); - actor.AddRenderer(renderer); - actor.SetSize(400, 400); - Stage::GetCurrent().Add(actor); - application.SendNotification(); - application.Render(0); - - Vector4 initialColor = Color::WHITE; - Property::Index colorIndex = material.RegisterProperty( "uFadeColor", initialColor ); - - TestGlAbstraction& gl = application.GetGlAbstraction(); + Image image0 = BufferImage::New( 64, 64, Pixel::RGBA8888 ); + Image image1 = BufferImage::New( 64, 64, Pixel::RGBA8888 ); + Image image2 = BufferImage::New( 64, 64, Pixel::RGBA8888 ); + Image image3 = BufferImage::New( 64, 64, Pixel::RGBA8888 ); - application.SendNotification(); - application.Render(0); - Vector4 actualValue(Vector4::ZERO); - DALI_TEST_CHECK( gl.GetUniformValue( "uFadeColor", actualValue ) ); - DALI_TEST_EQUALS( actualValue, initialColor, TEST_LOCATION ); + Material material = CreateMaterial(); + material.AddTexture( image0, "sTexture0"); + material.AddTexture( image1, "sTexture1"); + material.AddTexture( image2, "sTexture2"); + material.AddTexture( image3, "sTexture3"); - // Apply constraint - Constraint constraint = Constraint::New( material, colorIndex, TestConstraintNoBlue ); - constraint.Apply(); - application.SendNotification(); - application.Render(0); + Image textureImage0 = material.GetTexture( "sTexture0" ); + DALI_TEST_EQUALS( textureImage0, image0, TEST_LOCATION ); - // Expect no blue component in either buffer - yellow - DALI_TEST_CHECK( gl.GetUniformValue( "uFadeColor", actualValue ) ); - DALI_TEST_EQUALS( actualValue, Color::YELLOW, TEST_LOCATION ); + Image textureImage1 = material.GetTexture( "sTexture1" ); + DALI_TEST_EQUALS( textureImage1, image1, TEST_LOCATION ); - application.Render(0); - DALI_TEST_CHECK( gl.GetUniformValue( "uFadeColor", actualValue ) ); - DALI_TEST_EQUALS( actualValue, Color::YELLOW, TEST_LOCATION ); + Image textureImage2 = material.GetTexture( "sTexture2" ); + DALI_TEST_EQUALS( textureImage2, image2, TEST_LOCATION ); - material.RemoveConstraints(); - material.SetProperty(colorIndex, Color::WHITE ); - application.SendNotification(); - application.Render(0); - - DALI_TEST_CHECK( gl.GetUniformValue( "uFadeColor", actualValue ) ); - DALI_TEST_EQUALS( actualValue, Color::WHITE, TEST_LOCATION ); + Image textureImage3 = material.GetTexture( "sTexture3" ); + DALI_TEST_EQUALS( textureImage3, image3, TEST_LOCATION ); END_TEST; } - - -int UtcDaliMaterialAnimatedProperty01(void) +int UtcDaliMaterialGetTextureN(void) { TestApplication application; - tet_infoline("Test that a non-uniform material property can be animated"); - - Shader shader = Shader::New( "VertexSource", "FragmentSource"); - Material material = Material::New( shader ); - material.SetProperty(Material::Property::COLOR, Color::WHITE); - - Geometry geometry = CreateQuadGeometry(); - Renderer renderer = Renderer::New( geometry, material ); - - Actor actor = Actor::New(); - actor.AddRenderer(renderer); - actor.SetSize(400, 400); - Stage::GetCurrent().Add(actor); - - Vector4 initialColor = Color::WHITE; - Property::Index colorIndex = material.RegisterProperty( "uFadeColor", initialColor ); + Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 ); - application.SendNotification(); - application.Render(0); - DALI_TEST_EQUALS( material.GetProperty(colorIndex), initialColor, TEST_LOCATION ); + Material material = CreateMaterial(); + material.AddTexture( image, "sTexture"); - Animation animation = Animation::New(1.0f); - KeyFrames keyFrames = KeyFrames::New(); - keyFrames.Add(0.0f, initialColor); - keyFrames.Add(1.0f, Color::TRANSPARENT); - animation.AnimateBetween( Property( material, colorIndex ), keyFrames ); - animation.Play(); - - application.SendNotification(); - application.Render(500); - - DALI_TEST_EQUALS( material.GetProperty(colorIndex), Color::WHITE * 0.5f, TEST_LOCATION ); - - application.Render(500); - - DALI_TEST_EQUALS( material.GetProperty(colorIndex), Color::TRANSPARENT, TEST_LOCATION ); + Image textureImage = material.GetTexture( "sTextureTEST" ); + DALI_TEST_CHECK( !textureImage ); END_TEST; } -int UtcDaliMaterialAnimatedProperty02(void) -{ - TestApplication application; - - tet_infoline("Test that a uniform map material property can be animated"); - - Shader shader = Shader::New( "VertexSource", "FragmentSource"); - Material material = Material::New( shader ); - material.SetProperty(Material::Property::COLOR, Color::WHITE); - - Geometry geometry = CreateQuadGeometry(); - Renderer renderer = Renderer::New( geometry, material ); - - Actor actor = Actor::New(); - actor.AddRenderer(renderer); - actor.SetSize(400, 400); - Stage::GetCurrent().Add(actor); - application.SendNotification(); - application.Render(0); - - Vector4 initialColor = Color::WHITE; - Property::Index colorIndex = material.RegisterProperty( "uFadeColor", initialColor ); - - TestGlAbstraction& gl = application.GetGlAbstraction(); - - application.SendNotification(); - application.Render(0); - - Vector4 actualValue(Vector4::ZERO); - DALI_TEST_CHECK( gl.GetUniformValue( "uFadeColor", actualValue ) ); - DALI_TEST_EQUALS( actualValue, initialColor, TEST_LOCATION ); - - Animation animation = Animation::New(1.0f); - KeyFrames keyFrames = KeyFrames::New(); - keyFrames.Add(0.0f, initialColor); - keyFrames.Add(1.0f, Color::TRANSPARENT); - animation.AnimateBetween( Property( material, colorIndex ), keyFrames ); - animation.Play(); - - application.SendNotification(); - application.Render(500); - - DALI_TEST_CHECK( gl.GetUniformValue( "uFadeColor", actualValue ) ); - DALI_TEST_EQUALS( actualValue, Color::WHITE * 0.5f, TEST_LOCATION ); - - application.Render(500); - DALI_TEST_CHECK( gl.GetUniformValue( "uFadeColor", actualValue ) ); - DALI_TEST_EQUALS( actualValue, Color::TRANSPARENT, TEST_LOCATION ); - - END_TEST; -}