X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=automated-tests%2Fsrc%2Fdali%2Futc-Dali-Sampler.cpp;h=ba71e7cf5364345e87473b7fad0b54f028099d8c;hb=23757de09d484bd019f758bc3a20e60e26a79456;hp=09b45eb3e0696189c6631c03302e325100cb3a92;hpb=4ea88b4672a98bdfc230cf7c948bd0db11f2739d;p=platform%2Fcore%2Fuifw%2Fdali-core.git diff --git a/automated-tests/src/dali/utc-Dali-Sampler.cpp b/automated-tests/src/dali/utc-Dali-Sampler.cpp index 09b45eb..ba71e7c 100644 --- a/automated-tests/src/dali/utc-Dali-Sampler.cpp +++ b/automated-tests/src/dali/utc-Dali-Sampler.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * Copyright (c) 2016 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,13 +15,18 @@ * */ +// EXTERNAL INCLUDES #include +#include +#include +#include + +// INTERNAL INCLUDES #include +#include using namespace Dali; -#include - void sampler_test_startup(void) { test_return_value = TET_UNDEF; @@ -35,9 +40,7 @@ void sampler_test_cleanup(void) int UtcDaliSamplerNew01(void) { TestApplication application; - - Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 ); - Sampler sampler = Sampler::New(image, "sTexture"); + Sampler sampler = Sampler::New(); DALI_TEST_EQUALS( (bool)sampler, true, TEST_LOCATION ); END_TEST; @@ -51,11 +54,31 @@ int UtcDaliSamplerNew02(void) END_TEST; } +int UtcDaliSamplerCopyConstructor(void) +{ + TestApplication application; + tet_infoline("Testing Dali::Handle::Handle(const Handle&)"); + + // Initialize an object, ref count == 1 + Sampler sampler = Sampler::New(); + + DALI_TEST_EQUALS(1, sampler.GetBaseObject().ReferenceCount(), TEST_LOCATION); + + // Copy the object, ref count == 2 + Sampler copy(sampler); + DALI_TEST_CHECK(copy); + if (copy) + { + DALI_TEST_EQUALS(2, copy.GetBaseObject().ReferenceCount(), TEST_LOCATION); + } + + END_TEST; +} + int UtcDaliSamplerDownCast01(void) { TestApplication application; - Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 ); - Sampler sampler = Sampler::New(image, "sTexture"); + Sampler sampler = Sampler::New(); BaseHandle handle(sampler); Sampler sampler2 = Sampler::DownCast(handle); @@ -73,128 +96,288 @@ int UtcDaliSamplerDownCast02(void) END_TEST; } +int UtcDaliSamplerAssignmentOperator(void) +{ + TestApplication application; + Sampler sampler1 = Sampler::New(); + + Sampler sampler2; + + DALI_TEST_CHECK(!(sampler1 == sampler2)); + + sampler2 = sampler1; + + DALI_TEST_CHECK(sampler1 == sampler2); + + sampler2 = Sampler::New(); + + DALI_TEST_CHECK(!(sampler1 == sampler2)); -int UtcDaliSamplerSetUniformName01(void) + END_TEST; +} + +int UtcSamplerSetFilterMode(void) { TestApplication application; Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 ); - Sampler sampler = Sampler::New(image, "sTexture"); - sampler.SetUniformName( "sEffectTexture" ); + Sampler sampler = Sampler::New(); - Material material = CreateMaterial(1.0f); - material.AddSampler( sampler ); + TextureSet textureSet = CreateTextureSet(); + TextureSetImage( textureSet, 0u, image ); + textureSet.SetSampler( 0u, sampler ); + Shader shader = CreateShader(); Geometry geometry = CreateQuadGeometry(); - Renderer renderer = Renderer::New( geometry, material ); + Renderer renderer = Renderer::New( geometry, shader ); + renderer.SetTextures( textureSet ); Actor actor = Actor::New(); actor.AddRenderer(renderer); actor.SetParentOrigin( ParentOrigin::CENTER ); actor.SetSize(400, 400); - Stage::GetCurrent().Add( actor ); + TestGlAbstraction& gl = application.GetGlAbstraction(); + /**************************************************************/ + // Default/Default + TraceCallStack& texParameterTrace = gl.GetTexParameterTrace(); + texParameterTrace.Reset(); + texParameterTrace.Enable( true ); + + sampler.SetFilterMode( FilterMode::DEFAULT, FilterMode::DEFAULT ); + application.SendNotification(); + application.Render(); + + texParameterTrace.Enable( false ); + + // Verify gl state + + // There are three calls to TexParameteri when the texture is first created + // Texture mag filter is not called as the first time set it uses the system default + DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 3, TEST_LOCATION); + + std::stringstream out; + out << GL_TEXTURE_2D << ", " << GL_TEXTURE_MIN_FILTER << ", " << GL_LINEAR; + DALI_TEST_EQUALS( texParameterTrace.TestMethodAndParams(2, "TexParameteri", out.str()), true, TEST_LOCATION); + + /**************************************************************/ + // Default/Default + texParameterTrace.Reset(); + texParameterTrace.Enable( true ); + + sampler.SetFilterMode( FilterMode::DEFAULT, FilterMode::DEFAULT ); + + // Flush the queue and render once + application.SendNotification(); + application.Render(); + + texParameterTrace.Enable( false ); + + // Verify gl state + + // Should not make any calls when settings are the same + DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 0, TEST_LOCATION); + + /**************************************************************/ + // Nearest/Nearest + texParameterTrace.Reset(); + texParameterTrace.Enable( true ); + + sampler.SetFilterMode( FilterMode::NEAREST, FilterMode::NEAREST ); + + // Flush the queue and render once application.SendNotification(); application.Render(); - int textureUnit=-1; - DALI_TEST_CHECK( gl.GetUniformValue( "sEffectTexture", textureUnit ) ); - DALI_TEST_EQUALS( textureUnit, 0, TEST_LOCATION ); + texParameterTrace.Enable( false ); + + // Verify actor gl state + DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 2, TEST_LOCATION); + + out.str(""); + out << GL_TEXTURE_2D << ", " << GL_TEXTURE_MIN_FILTER << ", " << GL_NEAREST; + DALI_TEST_EQUALS( texParameterTrace.TestMethodAndParams(0, "TexParameteri", out.str()), true, TEST_LOCATION); + + out.str(""); + out << GL_TEXTURE_2D << ", " << GL_TEXTURE_MAG_FILTER << ", " << GL_NEAREST; + DALI_TEST_EQUALS( texParameterTrace.TestMethodAndParams(1, "TexParameteri", out.str()), true, TEST_LOCATION); + + + /**************************************************************/ + // Nearest/Linear + texParameterTrace.Reset(); + texParameterTrace.Enable( true ); + + sampler.SetFilterMode( FilterMode::NEAREST, FilterMode::LINEAR ); + + // Flush the queue and render once + application.SendNotification(); + application.Render(); + + texParameterTrace.Enable( false ); + + // Verify actor gl state + DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 1, TEST_LOCATION); + + out.str(""); + out << GL_TEXTURE_2D << ", " << GL_TEXTURE_MAG_FILTER << ", " << GL_LINEAR; + DALI_TEST_EQUALS( texParameterTrace.TestMethodAndParams(0, "TexParameteri", out.str()), true, TEST_LOCATION); + + /**************************************************************/ + // NONE/NONE + texParameterTrace.Reset(); + texParameterTrace.Enable( true ); + + sampler.SetFilterMode( FilterMode::NONE, FilterMode::NONE ); + + // Flush the queue and render once + application.SendNotification(); + application.Render(); + + texParameterTrace.Enable( false ); + + // Verify actor gl state + DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 1, TEST_LOCATION); + + out.str(""); + out << GL_TEXTURE_2D << ", " << GL_TEXTURE_MIN_FILTER << ", " << GL_NEAREST_MIPMAP_LINEAR; + DALI_TEST_EQUALS( texParameterTrace.TestMethodAndParams(0, "TexParameteri", out.str()), true, TEST_LOCATION); END_TEST; } - -int UtcDaliSamplerSetUniformName02(void) +int UtcSamplerSetWrapMode1(void) { TestApplication application; Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 ); - Image image2 = BufferImage::New( 64, 64, Pixel::RGBA8888 ); - Sampler sampler1 = Sampler::New(image, "sTexture"); - sampler1.SetUniformName( "sEffectTexture" ); - - Sampler sampler2 = Sampler::New(image2, "sTexture2"); - - Material material = CreateMaterial(1.0f); - material.AddSampler( sampler1 ); - material.AddSampler( sampler2 ); + TextureSet textureSet = CreateTextureSet(); + Sampler sampler = Sampler::New(); + TextureSetImage( textureSet, 0u, image ); + textureSet.SetSampler( 0u, sampler ); + Shader shader = CreateShader(); Geometry geometry = CreateQuadGeometry(); - Renderer renderer = Renderer::New( geometry, material ); + Renderer renderer = Renderer::New( geometry, shader ); + renderer.SetTextures( textureSet ); + Actor actor = Actor::New(); actor.AddRenderer(renderer); actor.SetParentOrigin( ParentOrigin::CENTER ); actor.SetSize(400, 400); - Stage::GetCurrent().Add( actor ); TestGlAbstraction& gl = application.GetGlAbstraction(); + //**************************************** + // CLAMP_TO_EDGE / CLAMP_TO_EDGE + TraceCallStack& texParameterTrace = gl.GetTexParameterTrace(); + texParameterTrace.Reset(); + texParameterTrace.Enable( true ); + + application.SendNotification(); + application.Render(); + + texParameterTrace.Enable( false ); + + // Verify gl state + + // There are three calls to TexParameteri when the texture is first created + // Texture mag filter is not called as the first time set it uses the system default + DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 3, TEST_LOCATION); + + std::stringstream out; + out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_CLAMP_TO_EDGE; + DALI_TEST_EQUALS( texParameterTrace.TestMethodAndParams(0, "TexParameteri", out.str()), true, TEST_LOCATION); + + out.str(""); + out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_CLAMP_TO_EDGE; + DALI_TEST_EQUALS( texParameterTrace.TestMethodAndParams(1, "TexParameteri", out.str()), true, TEST_LOCATION); + + texParameterTrace.Reset(); + texParameterTrace.Enable( true ); + + sampler.SetWrapMode( WrapMode::CLAMP_TO_EDGE, WrapMode::CLAMP_TO_EDGE ); + + // Flush the queue and render once application.SendNotification(); application.Render(); - int textureUnit=-1; - DALI_TEST_CHECK( gl.GetUniformValue( "sEffectTexture", textureUnit ) ); - DALI_TEST_EQUALS( textureUnit, 0, TEST_LOCATION ); + texParameterTrace.Enable( false ); + + // Verify gl state - DALI_TEST_CHECK( gl.GetUniformValue( "sTexture2", textureUnit ) ); - DALI_TEST_EQUALS( textureUnit, 1, TEST_LOCATION ); + // Should not make any calls when settings are the same + DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 0, TEST_LOCATION); + + //Todo: Test the other wrap mode ( REPEAT, MIRRORED_REPEAT ) , currently not support!! END_TEST; } - -int UtcDaliSamplerUniformMap01(void) +int UtcSamplerSetWrapMode2(void) { TestApplication application; - Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 ); - Sampler sampler = Sampler::New(image, "sTexture"); - sampler.SetUniformName( "sEffectTexture" ); + // Create a cube-map texture. + unsigned int width = 8u; + unsigned int height = 8u; + Texture texture = Texture::New( TextureType::TEXTURE_CUBE, Pixel::RGBA8888, width, height ); + + // Create source image data. + unsigned int bufferSize( width * height * 4 ); + unsigned char* buffer= new unsigned char[ bufferSize ]; + memset( buffer, 0u, bufferSize ); + + PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::DELETE_ARRAY ); + + // Upload the source image data to all 6 sides of our cube-map. + texture.Upload( pixelData, CubeMapLayer::POSITIVE_X, 0u, 0u, 0u, width, height ); + texture.Upload( pixelData, CubeMapLayer::NEGATIVE_X, 0u, 0u, 0u, width, height ); + texture.Upload( pixelData, CubeMapLayer::POSITIVE_Y, 0u, 0u, 0u, width, height ); + texture.Upload( pixelData, CubeMapLayer::NEGATIVE_Y, 0u, 0u, 0u, width, height ); + texture.Upload( pixelData, CubeMapLayer::POSITIVE_Z, 0u, 0u, 0u, width, height ); + texture.Upload( pixelData, CubeMapLayer::NEGATIVE_Z, 0u, 0u, 0u, width, height ); - Material material = CreateMaterial(1.0f); - material.AddSampler( sampler ); + // Finalize the cube-map setup. + TextureSet textureSet = TextureSet::New(); + textureSet.SetTexture( 0u, texture ); + Sampler sampler = Sampler::New(); + textureSet.SetSampler( 0u, sampler ); + + Shader shader = CreateShader(); Geometry geometry = CreateQuadGeometry(); - Renderer renderer = Renderer::New( geometry, material ); + Renderer renderer = Renderer::New( geometry, shader ); + renderer.SetTextures( textureSet ); + Actor actor = Actor::New(); actor.AddRenderer(renderer); actor.SetParentOrigin( ParentOrigin::CENTER ); - actor.SetSize(400, 400); + actor.SetSize( 400, 400 ); Stage::GetCurrent().Add( actor ); - float initialValue = 1.0f; - Property::Index widthClampIndex = sampler.RegisterProperty("width-clamp", initialValue ); - sampler.AddUniformMapping( widthClampIndex, std::string("uWidthClamp") ); - TestGlAbstraction& gl = application.GetGlAbstraction(); application.SendNotification(); application.Render(); - float actualValue=0.0f; - DALI_TEST_CHECK( gl.GetUniformValue( "uWidthClamp", actualValue ) ); - DALI_TEST_EQUALS( actualValue, initialValue, TEST_LOCATION ); + TraceCallStack& texParameterTrace = gl.GetTexParameterTrace(); + texParameterTrace.Reset(); + texParameterTrace.Enable( true ); - Animation animation = Animation::New(1.0f); - KeyFrames keyFrames = KeyFrames::New(); - keyFrames.Add(0.0f, 0.0f); - keyFrames.Add(1.0f, 640.0f); - animation.AnimateBetween( Property( sampler, widthClampIndex ), keyFrames ); - animation.Play(); + // Call the 3 dimensional wrap mode API. + sampler.SetWrapMode( WrapMode::CLAMP_TO_EDGE, WrapMode::CLAMP_TO_EDGE, WrapMode::CLAMP_TO_EDGE ); application.SendNotification(); - application.Render( 500 ); + application.Render(); - DALI_TEST_CHECK( gl.GetUniformValue( "uWidthClamp", actualValue ) ); - DALI_TEST_EQUALS( actualValue, 320.0f, TEST_LOCATION ); + texParameterTrace.Enable( false ); - application.Render( 500 ); - DALI_TEST_CHECK( gl.GetUniformValue( "uWidthClamp", actualValue ) ); - DALI_TEST_EQUALS( actualValue, 640.0f, TEST_LOCATION ); + // Verify that 3 TexParameteri calls occurred. + DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 3u, TEST_LOCATION ); END_TEST; }