#include <mesh-builder.h>
using namespace Dali;
+
+namespace
+{
+
+enum SetSampler
+{
+ SET_SAMPLER,
+ DONT_SET_SAMPLER
+};
+
+Actor CreateActor( SetSampler setSamplerOption )
+{
+ Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64 );
+
+ Shader shader = CreateShader();
+ TextureSet textureSet = CreateTextureSet();
+
+ Sampler sampler = Sampler::New();
+ sampler.SetFilterMode( FilterMode::NEAREST, FilterMode::NEAREST );
+ textureSet.SetTexture( 0u, texture );
+ if( setSamplerOption == SET_SAMPLER )
+ {
+ textureSet.SetSampler( 0u, sampler );
+ }
+
+ Geometry geometry = CreateQuadGeometry();
+ Renderer renderer = Renderer::New( geometry, shader );
+ renderer.SetTextures( textureSet );
+
+ Actor actor = Actor::New();
+ actor.AddRenderer(renderer);
+ actor.SetParentOrigin( ParentOrigin::CENTER );
+ actor.SetSize(400, 400);
+
+ return actor;
+}
+
+} // namespace
+
+
void texture_set_test_startup(void)
{
test_return_value = TET_UNDEF;
{
TestApplication application;
- Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64 );
-
- Shader shader = CreateShader();
- TextureSet textureSet = CreateTextureSet();
- textureSet.SetTexture( 0u, texture );
-
- Geometry geometry = CreateQuadGeometry();
- 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 actor = CreateActor( DONT_SET_SAMPLER );
Stage::GetCurrent().Add( actor );
{
TestApplication application;
- Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, 64, 64 );
+ Actor actor = CreateActor(SET_SAMPLER);
- Shader shader = CreateShader();
- TextureSet textureSet = CreateTextureSet();
+ Stage::GetCurrent().Add( actor );
- Sampler sampler = Sampler::New();
- sampler.SetFilterMode( FilterMode::NEAREST, FilterMode::NEAREST );
- textureSet.SetTexture( 0u, texture );
- textureSet.SetSampler( 0u, sampler );
+ TestGlAbstraction& gl = application.GetGlAbstraction();
- Geometry geometry = CreateQuadGeometry();
- Renderer renderer = Renderer::New( geometry, shader );
- renderer.SetTextures( textureSet );
+ TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
+ texParameterTrace.Reset();
+ texParameterTrace.Enable( true );
+ application.SendNotification();
+ application.Render();
- Actor actor = Actor::New();
- actor.AddRenderer(renderer);
- actor.SetParentOrigin( ParentOrigin::CENTER );
- actor.SetSize(400, 400);
+ int textureUnit=-1;
+ DALI_TEST_CHECK( gl.GetUniformValue<int>( "sTexture", textureUnit ) );
+ DALI_TEST_EQUALS( textureUnit, 0, TEST_LOCATION );
- Stage::GetCurrent().Add( actor );
+ texParameterTrace.Enable( false );
+
+ // Verify gl state
+ // There are four 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" ), 6, TEST_LOCATION);
+
+ END_TEST;
+}
+
+int UtcDaliTextureSetMultiple(void)
+{
+ TestApplication application;
+
+ Actor actor1 = CreateActor(SET_SAMPLER);
+ Actor actor2 = CreateActor(SET_SAMPLER);
+
+ Stage::GetCurrent().Add( actor1 );
+ Stage::GetCurrent().Add( actor2 );
TestGlAbstraction& gl = application.GetGlAbstraction();
texParameterTrace.Enable( false );
// Verify gl state
- // There are four calls to TexParameteri when the texture is first created
+ // For each actor there are four 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" ), 6, TEST_LOCATION);
+ DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 2 * 6, TEST_LOCATION);
END_TEST;
}
+
int UtcDaliTextureSetSetSampler(void)
{
TestApplication application;
{
/**
+ * Function which compares render items by shader/textureSet/geometry
+ * @param[in] lhs Left hand side item
+ * @param[in] rhs Right hand side item
+ * @return True if left item is greater than right
+ */
+bool PartialCompareItems( const RenderInstructionProcessor::SortAttributes& lhs,
+ const RenderInstructionProcessor::SortAttributes& rhs )
+{
+ if( lhs.shader == rhs.shader )
+ {
+ if( lhs.textureSet == rhs.textureSet )
+ {
+ return lhs.geometry < rhs.geometry;
+ }
+ return lhs.textureSet < rhs.textureSet;
+ }
+ return lhs.shader < rhs.shader;
+}
+
+/**
* Function which sorts render items by depth index then by instance
- * ptrs of shader/geometry/material.
+ * ptrs of shader/textureSet/geometry.
* @param[in] lhs Left hand side item
* @param[in] rhs Right hand side item
* @return True if left item is greater than right
// encapsulates the same data (e.g. the middle-order bits of the ptrs).
if( lhs.renderItem->mDepthIndex == rhs.renderItem->mDepthIndex )
{
- if( lhs.shader == rhs.shader )
- {
- if( lhs.textureResourceId == rhs.textureResourceId )
- {
- return lhs.geometry < rhs.geometry;
- }
- return lhs.textureResourceId < rhs.textureResourceId;
- }
- return lhs.shader < rhs.shader;
+ return PartialCompareItems(lhs, rhs);
}
return lhs.renderItem->mDepthIndex < rhs.renderItem->mDepthIndex;
}
if( lhsIsOpaque )
{
// If both RenderItems are opaque, sort using shader, then material then geometry.
- if( lhs.shader == rhs.shader )
- {
- if( lhs.textureResourceId == rhs.textureResourceId )
- {
- return lhs.geometry < rhs.geometry;
- }
- return lhs.textureResourceId < rhs.textureResourceId;
- }
- return lhs.shader < rhs.shader;
+ return PartialCompareItems( lhs, rhs );
}
else
{
// If both RenderItems are transparent, sort using Z, then shader, then material, then geometry.
if( Equals( lhs.zValue, rhs.zValue ) )
{
- if( lhs.shader == rhs.shader )
- {
- if( lhs.textureResourceId == rhs.textureResourceId )
- {
- return lhs.geometry < rhs.geometry;
- }
- return lhs.textureResourceId < rhs.textureResourceId;
- }
- return lhs.shader < rhs.shader;
+ return PartialCompareItems( lhs, rhs );
}
return lhs.zValue > rhs.zValue;
}
RenderItem& item = renderList.GetNextFreeItem();
item.mRenderer = &renderable.mRenderer->GetRenderer();
item.mNode = renderable.mNode;
+ item.mTextureSet = renderable.mRenderer->GetTextures();
item.mIsOpaque = ( opacity == Renderer::OPAQUE );
item.mDepthIndex = renderable.mRenderer->GetDepthIndex();
item.mRenderer->SetSortAttributes( bufferIndex, mSortingHelper[ index ] );
+ // texture set
+ mSortingHelper[ index ].textureSet = item.mTextureSet;
+
// The default sorting function should get inlined here.
mSortingHelper[ index ].zValue = Internal::Layer::ZValue( item.mModelViewMatrix.GetTranslation3() ) - item.mDepthIndex;
RenderItem& item = renderList.GetItem( index );
item.mRenderer->SetSortAttributes( bufferIndex, mSortingHelper[ index ] );
+
+ // texture set
+ mSortingHelper[ index ].textureSet = item.mTextureSet;
+
+
mSortingHelper[ index ].zValue = (*sortFunction)( item.mModelViewMatrix.GetTranslation3() ) - item.mDepthIndex;
// Keep the RenderItem pointer in the helper so we can quickly reorder items after sort.