/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2019 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.
// INTERNAL INCLUDES
#include <dali/public-api/object/type-registry.h>
-#include <dali/devel-api/rendering/texture-set.h> // Dali::Internal::Render::TextureSet
-#include <dali/internal/event/common/object-impl-helper.h> // Dali::Internal::ObjectHelper
#include <dali/internal/update/manager/update-manager.h>
#include <dali/internal/update/rendering/scene-graph-texture-set.h>
return textureSet;
}
-void TextureSet::SetImage( size_t index, ImagePtr image )
+void TextureSet::SetTexture( uint32_t index, TexturePtr texture )
{
- size_t textureCount( mTextures.size() );
- if( index < textureCount )
- {
- if( mTextures[index].image && mOnStage )
- {
- mTextures[index].image->Disconnect();
- }
- }
- else
+ uint32_t textureCount = static_cast<uint32_t>( mTextures.size() );
+ if( index >= textureCount )
{
mTextures.resize(index + 1);
- for( size_t i(textureCount); i<=index; ++i )
+
+ bool samplerExist = true;
+ if( mSamplers.size() < index + 1 )
{
- mTextures[i].image = NULL;
- mTextures[i].sampler = NULL;
+ mSamplers.resize( index + 1 );
+ samplerExist = false;
}
- }
- mTextures[index].image = image;
-
- if( image )
- {
- if( mOnStage )
+ for( uint32_t i(textureCount); i<=index; ++i )
{
- image->Connect();
+ mTextures[i] = NULL;
+
+ if( !samplerExist )
+ {
+ mSamplers[i] = NULL;
+ }
}
- SceneGraph::SetImageMessage( mEventThreadServices, *mSceneObject, index, image->GetResourceId() );
}
- else
+
+ mTextures[index]= texture;
+
+ Render::Texture* renderTexture(0);
+ if( texture )
{
- SceneGraph::SetImageMessage( mEventThreadServices, *mSceneObject, index, Integration::InvalidResourceId );
+ renderTexture = texture->GetRenderObject();
}
+
+ SceneGraph::SetTextureMessage( mEventThreadServices, *mSceneObject, index, renderTexture );
}
-Image* TextureSet::GetImage( size_t index ) const
+Texture* TextureSet::GetTexture( uint32_t index ) const
{
- Image* result(0);
+ Texture* result(0);
if( index < mTextures.size() )
{
- result = mTextures[index].image.Get();
+ result = mTextures[index].Get();
}
else
{
- DALI_LOG_ERROR( "Error: Invalid index to TextureSet::GetImage");
+ DALI_LOG_ERROR( "Error: Invalid index to TextureSet::GetTexture\n");
}
return result;
}
-void TextureSet::SetSampler( size_t index, SamplerPtr sampler )
+void TextureSet::SetSampler( uint32_t index, SamplerPtr sampler )
{
- size_t textureCount( mTextures.size() );
- if( textureCount < index + 1 )
+ uint32_t samplerCount = static_cast<uint32_t>( mSamplers.size() );
+ if( samplerCount < index + 1 )
{
- mTextures.resize(index + 1);
- for( size_t i(textureCount); i<=index; ++i )
+ mSamplers.resize( index + 1 );
+ for( uint32_t i = samplerCount; i<=index; ++i )
{
- mTextures[i].image = NULL;
- mTextures[i].sampler = NULL;
+ mSamplers[i] = NULL;
}
}
- mTextures[index].sampler = sampler;
+ mSamplers[index] = sampler;
Render::Sampler* renderSampler(0);
if( sampler )
SceneGraph::SetSamplerMessage( mEventThreadServices, *mSceneObject, index, renderSampler );
}
-Sampler* TextureSet::GetSampler( size_t index ) const
+Sampler* TextureSet::GetSampler( uint32_t index ) const
{
Sampler* result(0);
- if( index < mTextures.size() )
+ if( index < mSamplers.size() )
{
- result = mTextures[index].sampler.Get();
+ result = mSamplers[index].Get();
}
else
{
- DALI_LOG_ERROR( "Error: Invalid index to TextureSet::GetSampler");
+ DALI_LOG_ERROR( "Error: Invalid index to TextureSet::GetSampler\n");
}
return result;
}
-size_t TextureSet::GetTextureCount() const
+uint32_t TextureSet::GetTextureCount() const
{
- return mTextures.size();
+ return static_cast<uint32_t>( mTextures.size() );
}
const SceneGraph::TextureSet* TextureSet::GetTextureSetSceneObject() const
return mSceneObject;
}
-bool TextureSet::OnStage() const
-{
- return mOnStage;
-}
-
-void TextureSet::Connect()
-{
- mOnStage = true;
-
- for( size_t i(0); i<mTextures.size(); ++i )
- {
- if( mTextures[i].image )
- {
- mTextures[i].image->Connect();
- SceneGraph::SetImageMessage( mEventThreadServices, *mSceneObject, i, mTextures[i].image->GetResourceId() );
- }
- else
- {
- SceneGraph::SetImageMessage( mEventThreadServices, *mSceneObject, i, Integration::InvalidResourceId );
- }
- }
-}
-
-void TextureSet::Disconnect()
-{
- for( size_t i(0); i<mTextures.size(); ++i )
- {
- if( mTextures[i].image )
- {
- mTextures[i].image->Disconnect();
- }
- }
-
- mOnStage = false;
-}
-
TextureSet::TextureSet()
-:mEventThreadServices( *Stage::GetCurrent() ),
- mSceneObject( NULL ),
- mTextures(),
- mOnStage( false )
+:mEventThreadServices( EventThreadServices::Get() ),
+ mSceneObject( NULL )
{
}
SceneGraph::UpdateManager& updateManager = mEventThreadServices.GetUpdateManager();
mSceneObject = SceneGraph::TextureSet::New();
- AddTextureSetMessage( updateManager, *mSceneObject );
+ OwnerPointer< SceneGraph::TextureSet > transferOwnership( mSceneObject );
+ AddTextureSetMessage( updateManager, transferOwnership );
}
TextureSet::~TextureSet()