/*
- * 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;
tet_infoline("Testing Dali::Handle::Handle(const Handle&)");
// Initialize an object, ref count == 1
- Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
- Sampler sampler = Sampler::New(image, "sTexture");
+ Sampler sampler = Sampler::New();
DALI_TEST_EQUALS(1, sampler.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);
int UtcDaliSamplerAssignmentOperator(void)
{
TestApplication application;
-
- Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
- Sampler sampler1 = Sampler::New(image, "sTexture");
+ Sampler sampler1 = Sampler::New();
Sampler sampler2;
DALI_TEST_CHECK(sampler1 == sampler2);
- sampler2 = Sampler::New(image, "sTexture");
+ sampler2 = Sampler::New();
DALI_TEST_CHECK(!(sampler1 == sampler2));
END_TEST;
}
-int UtcDaliSamplerSetUniformName01(void)
-{
- TestApplication application;
-
- Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
- Sampler sampler = Sampler::New(image, "sTexture");
- sampler.SetUniformName( "sEffectTexture" );
-
- Material material = CreateMaterial(1.0f);
- material.AddSampler( sampler );
-
- 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();
-
- application.SendNotification();
- application.Render();
-
- int textureUnit=-1;
- DALI_TEST_CHECK( gl.GetUniformValue<int>( "sEffectTexture", textureUnit ) );
- DALI_TEST_EQUALS( textureUnit, 0, TEST_LOCATION );
-
- END_TEST;
-}
-
-int UtcDaliSamplerSetUniformName02(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 );
-
- 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();
-
- application.SendNotification();
- application.Render();
-
- int textureUnit=-1;
- DALI_TEST_CHECK( gl.GetUniformValue<int>( "sEffectTexture", textureUnit ) );
- DALI_TEST_EQUALS( textureUnit, 0, TEST_LOCATION );
-
- DALI_TEST_CHECK( gl.GetUniformValue<int>( "sTexture2", textureUnit ) );
- DALI_TEST_EQUALS( textureUnit, 1, TEST_LOCATION );
-
- END_TEST;
-}
-
-int UtcDaliSamplerSetGetImage(void)
-{
- TestApplication application;
-
- Image image1 = BufferImage::New( 64, 64, Pixel::RGBA8888 );
- Image image2 = BufferImage::New( 64, 64, Pixel::RGBA8888 );
- Sampler sampler = Sampler::New(image1, "sTexture");
-
- DALI_TEST_CHECK(image1 == sampler.GetImage());
-
- sampler.SetImage( image2 );
- DALI_TEST_CHECK(!(image1 == sampler.GetImage()));
- DALI_TEST_CHECK(image2 == sampler.GetImage());
-
- END_TEST;
-}
-
int UtcSamplerSetFilterMode(void)
{
TestApplication application;
Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
- Sampler sampler = Sampler::New(image, "sTexture");
+ 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 );
- float initialValue = 1.0f;
- sampler.RegisterProperty("uWidthClamp", initialValue );
TestGlAbstraction& gl = application.GetGlAbstraction();
texParameterTrace.Reset();
texParameterTrace.Enable( true );
- sampler.SetFilterMode( Sampler::DEFAULT, Sampler::DEFAULT );
+ sampler.SetFilterMode( FilterMode::DEFAULT, FilterMode::DEFAULT );
application.SendNotification();
application.Render();
// Verify gl state
- // There are two calls to TexParameteri when the texture is first created
+ // 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);
texParameterTrace.Reset();
texParameterTrace.Enable( true );
- sampler.SetFilterMode( Sampler::DEFAULT, Sampler::DEFAULT );
+ sampler.SetFilterMode( FilterMode::DEFAULT, FilterMode::DEFAULT );
// Flush the queue and render once
application.SendNotification();
texParameterTrace.Reset();
texParameterTrace.Enable( true );
- sampler.SetFilterMode( Sampler::NEAREST, Sampler::NEAREST );
+ sampler.SetFilterMode( FilterMode::NEAREST, FilterMode::NEAREST );
// Flush the queue and render once
application.SendNotification();
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( Sampler::NEAREST, Sampler::LINEAR );
+ sampler.SetFilterMode( FilterMode::NEAREST, FilterMode::LINEAR );
// Flush the queue and render once
application.SendNotification();
texParameterTrace.Reset();
texParameterTrace.Enable( true );
- sampler.SetFilterMode( Sampler::NONE, Sampler::NONE );
+ sampler.SetFilterMode( FilterMode::NONE, FilterMode::NONE );
// Flush the queue and render once
application.SendNotification();
END_TEST;
}
-int UtcSamplerSetWrapMode(void)
+int UtcSamplerSetWrapMode1(void)
{
TestApplication application;
Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
- Sampler sampler = Sampler::New(image, "sTexture");
-
- Material material = CreateMaterial(1.0f);
- material.AddSampler( sampler );
+ 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 );
// Verify gl state
- // There are two calls to TexParameteri when the texture is first created
+ // 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);
texParameterTrace.Reset();
texParameterTrace.Enable( true );
- sampler.SetWrapMode( Sampler::CLAMP_TO_EDGE, Sampler::CLAMP_TO_EDGE );
+ sampler.SetWrapMode( WrapMode::CLAMP_TO_EDGE, WrapMode::CLAMP_TO_EDGE );
// Flush the queue and render once
application.SendNotification();
END_TEST;
}
-int UtcSamplerSetAffectsTransparency(void)
+int UtcSamplerSetWrapMode2(void)
{
TestApplication application;
- Image image = BufferImage::New( 64, 64, Pixel::RGBA8888 );
- Sampler sampler = Sampler::New(image, "sTexture");
+ // 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 );
- Material material = CreateMaterial(1.0f);
- material.AddSampler( sampler );
+ // 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 );
+ // 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 );
TestGlAbstraction& gl = application.GetGlAbstraction();
- // Test SetAffectsTransparency( false )
- sampler.SetAffectsTransparency( false );
-
- gl.EnableCullFaceCallTrace(true);
application.SendNotification();
application.Render();
- TraceCallStack& glEnableStack = gl.GetCullFaceTrace();
- std::ostringstream blendStr;
- blendStr << GL_BLEND;
- DALI_TEST_CHECK( ! glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
+ TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
+ texParameterTrace.Reset();
+ texParameterTrace.Enable( true );
- // Test SetAffectsTransparency( true )
- sampler.SetAffectsTransparency( true );
+ // Call the 3 dimensional wrap mode API.
+ sampler.SetWrapMode( WrapMode::CLAMP_TO_EDGE, WrapMode::CLAMP_TO_EDGE, WrapMode::CLAMP_TO_EDGE );
- glEnableStack.Reset();
- gl.EnableCullFaceCallTrace(true);
application.SendNotification();
application.Render();
- DALI_TEST_CHECK( glEnableStack.FindMethodAndParams( "Enable", blendStr.str().c_str() ) );
+ texParameterTrace.Enable( false );
+
+ // Verify that 3 TexParameteri calls occurred.
+ DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 3u, TEST_LOCATION );
END_TEST;
}