/*
- * 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.
*
*/
+// EXTERNAL INCLUDES
#include <dali/public-api/dali-core.h>
+#include <dali/devel-api/images/texture-set-image.h>
+#include <unistd.h>
+#include <string.h>
+
+// INTERNAL INCLUDES
#include <dali-test-suite-utils.h>
+#include <mesh-builder.h>
using namespace Dali;
-#include <mesh-builder.h>
-
void sampler_test_startup(void)
{
test_return_value = TET_UNDEF;
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;
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);
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<int>( "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<int>( "sEffectTexture", textureUnit ) );
- DALI_TEST_EQUALS( textureUnit, 0, TEST_LOCATION );
+ texParameterTrace.Enable( false );
+
+ // Verify gl state
- DALI_TEST_CHECK( gl.GetUniformValue<int>( "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<float>( "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<float>( "uWidthClamp", actualValue ) );
- DALI_TEST_EQUALS( actualValue, 320.0f, TEST_LOCATION );
+ texParameterTrace.Enable( false );
- application.Render( 500 );
- DALI_TEST_CHECK( gl.GetUniformValue<float>( "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;
}