/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 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.
#include "scene-graph-texture-set.h"
// INTERNAL HEADERS
-#include <dali/public-api/actors/blending.h>
-#include <dali/public-api/shader-effects/shader-effect.h>
-#include <dali/devel-api/rendering/texture-set.h>
-#include <dali/integration-api/resource-declarations.h>
#include <dali/internal/common/internal-constants.h>
-#include <dali/internal/update/resources/texture-metadata.h>
-#include <dali/internal/update/resources/resource-manager.h>
-#include <dali/internal/render/shaders/scene-graph-shader.h>
#include <dali/internal/common/memory-pool-object-allocator.h>
+#include <dali/internal/render/renderers/render-texture.h>
+#include <dali/internal/update/rendering/scene-graph-renderer.h>
namespace //Unnamed namespace
{
//Memory pool used to allocate new texture sets. Memory used by this pool will be released when shutting down DALi
Dali::Internal::MemoryPoolObjectAllocator<Dali::Internal::SceneGraph::TextureSet> gTextureSetMemoryPool;
-}
+} // namespace
namespace Dali
{
-
namespace Internal
{
-
namespace SceneGraph
{
-
TextureSet* TextureSet::New()
{
- return new ( gTextureSetMemoryPool.AllocateRawThreadSafe() ) TextureSet();
+ return new(gTextureSetMemoryPool.AllocateRawThreadSafe()) TextureSet();
}
TextureSet::TextureSet()
: mSamplers(),
- mTextureId(),
- mConnectionObservers(),
- mResourcesReady( false ),
- mFinishedResourceAcquisition( false ),
- mChanged( true ),
- mHasAlpha( false )
+ mHasAlpha(false)
{
- // Observe own property-owner's uniform map
- AddUniformMapObserver( *this );
}
TextureSet::~TextureSet()
{
- mConnectionObservers.Destroy( *this );
}
-void TextureSet::operator delete( void* ptr )
+void TextureSet::operator delete(void* ptr)
{
- gTextureSetMemoryPool.FreeThreadSafe( static_cast<TextureSet*>( ptr ) );
+ gTextureSetMemoryPool.FreeThreadSafe(static_cast<TextureSet*>(ptr));
}
-void TextureSet::Prepare( const ResourceManager& resourceManager )
+void TextureSet::SetSampler(uint32_t index, Render::Sampler* sampler)
{
- if( mChanged )
+ const uint32_t samplerCount = static_cast<uint32_t>(mSamplers.Size());
+ if(samplerCount < index + 1)
{
- unsigned int opaqueCount = 0;
- unsigned int completeCount = 0;
- unsigned int failedCount = 0;
- unsigned int frameBufferCount = 0;
- const std::size_t textureCount( mTextureId.Count() );
- if( textureCount > 0 )
+ mSamplers.Resize(index + 1);
+ for(uint32_t i(samplerCount); i <= index; ++i)
{
- for( unsigned int i(0); i<textureCount; ++i )
- {
- const ResourceId textureId = mTextureId[ i ];
- TextureMetadata* metadata = NULL;
- if( textureId != Integration::InvalidResourceId )
- {
- // if there is metadata, resource is loaded
- if( resourceManager.GetTextureMetadata( textureId, metadata ) )
- {
- DALI_ASSERT_DEBUG( metadata );
- // metadata is valid pointer from now on
- if( metadata->IsFullyOpaque() )
- {
- ++opaqueCount;
- }
-
- if( metadata->IsFramebuffer() )
- {
- if( metadata->HasFrameBufferBeenRenderedTo() )
- {
- ++completeCount;
- }
- else
- {
- frameBufferCount++;
- }
- }
- else
- {
- // loaded so will complete this frame
- ++completeCount;
- }
- // no point checking failure as there is no metadata for failed loads
- }
- // if no metadata, loading can be failed
- else if( resourceManager.HasResourceLoadFailed( textureId ) )
- {
- ++failedCount;
- }
- }
- else
- {
- //If the texture is not valid it is considerer opaque and complete
- ++opaqueCount;
- ++completeCount;
- }
- }
+ mSamplers[i] = nullptr;
}
+ }
- mHasAlpha = ( opaqueCount != textureCount );
-
- // ready for rendering when all textures are either successfully loaded or they are FBOs
- mResourcesReady = (completeCount + frameBufferCount >= textureCount);
-
- // Texture set is complete if all resources are either loaded or failed or, if they are FBOs have been rendererd to
- mFinishedResourceAcquisition = ( completeCount + failedCount == textureCount );
+ mSamplers[index] = sampler;
- if( mFinishedResourceAcquisition )
- {
- // Texture set is now considered not changed
- mChanged = false;
- }
+ if(index < static_cast<uint32_t>(mTextures.Size()))
+ {
+ mTextures[index]->SetUpdated(true);
}
}
-void TextureSet::SetImage( size_t index, ResourceId imageId )
+void TextureSet::SetTexture(uint32_t index, Render::Texture* texture)
{
- size_t textureCount( mTextureId.Size() );
- if( textureCount < index + 1 )
+ const uint32_t textureCount = static_cast<uint32_t>(mTextures.Size());
+ if(textureCount < index + 1)
{
- mTextureId.Resize( index + 1 );
- mSamplers.Resize( index + 1 );
- for( size_t i(textureCount); i<=index; ++i )
+ mTextures.Resize(index + 1);
+
+ bool samplerExist = true;
+ if(mSamplers.Size() < index + 1)
{
- mTextureId[i] = Integration::InvalidResourceId;
- mSamplers[i] = NULL;
+ mSamplers.Resize(index + 1);
+ samplerExist = false;
}
- }
-
- mTextureId[index] = imageId;
- mChanged = true;
- mConnectionObservers.ConnectionsChanged(*this);
-}
-void TextureSet::SetSampler( size_t index, Render::Sampler* sampler )
-{
- size_t samplerCount( mSamplers.Size() );
- if( samplerCount < index + 1 )
- {
- mSamplers.Resize( index + 1 );
- mTextureId.Resize( index + 1 );
- for( size_t i(samplerCount); i<=index; ++i )
+ for(uint32_t i(textureCount); i <= index; ++i)
{
- mTextureId[i] = Integration::InvalidResourceId;
- mSamplers[i] = NULL;
+ mTextures[i] = nullptr;
+
+ if(!samplerExist)
+ {
+ mSamplers[i] = nullptr;
+ }
}
}
- mSamplers[index] = sampler;
-
- mChanged = true;
- mConnectionObservers.ConnectionsChanged(*this);
+ mTextures[index] = texture;
+ if(texture)
+ {
+ mHasAlpha |= texture->HasAlphaChannel();
+ texture->SetUpdated(true);
+ }
}
bool TextureSet::HasAlpha() const
return mHasAlpha;
}
-void TextureSet::GetResourcesStatus( bool& resourcesReady, bool& finishedResourceAcquisition )
-{
- resourcesReady = mResourcesReady;
- finishedResourceAcquisition = mFinishedResourceAcquisition;
-}
-
-void TextureSet::ConnectToSceneGraph( SceneController& sceneController, BufferIndex bufferIndex )
-{
-}
-
-void TextureSet::DisconnectFromSceneGraph( SceneController& sceneController, BufferIndex bufferIndex )
-{
-}
-
-void TextureSet::AddConnectionObserver( ConnectionChangePropagator::Observer& observer )
-{
- mConnectionObservers.Add(observer);
-}
-
-void TextureSet::RemoveConnectionObserver( ConnectionChangePropagator::Observer& observer )
-{
- mConnectionObservers.Remove(observer);
-}
-
-void TextureSet::UniformMappingsChanged( const UniformMap& mappings )
+uint32_t TextureSet::GetMemoryPoolCapacity()
{
- // Our uniform map has changed.
- // Inform connected observers.
- mConnectionObservers.ConnectedUniformMapChanged();
+ return gTextureSetMemoryPool.GetCapacity();
}
} // namespace SceneGraph