2 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include "scene-graph-texture-set.h"
21 #include <dali/internal/common/internal-constants.h>
22 #include <dali/internal/common/memory-pool-object-allocator.h>
23 #include <dali/internal/update/rendering/scene-graph-renderer.h>
25 namespace //Unnamed namespace
27 //Memory pool used to allocate new texture sets. Memory used by this pool will be released when shutting down DALi
28 Dali::Internal::MemoryPoolObjectAllocator<Dali::Internal::SceneGraph::TextureSet> gTextureSetMemoryPool;
40 TextureSet* TextureSet::New()
42 return new ( gTextureSetMemoryPool.AllocateRawThreadSafe() ) TextureSet();
45 TextureSet::TextureSet()
52 TextureSet::~TextureSet()
54 for( auto&& renderer : mRenderers )
56 renderer->TextureSetDeleted();
60 void TextureSet::operator delete( void* ptr )
62 gTextureSetMemoryPool.FreeThreadSafe( static_cast<TextureSet*>( ptr ) );
65 void TextureSet::SetSampler( uint32_t index, Render::Sampler* sampler )
67 const uint32_t samplerCount = static_cast<uint32_t>( mSamplers.Size() );
68 if( samplerCount < index + 1 )
70 mSamplers.Resize( index + 1 );
71 for( uint32_t i(samplerCount); i<=index; ++i )
77 mSamplers[index] = sampler;
78 NotifyChangeToRenderers();
81 void TextureSet::SetTexture( uint32_t index, Render::Texture* texture )
83 const uint32_t textureCount = static_cast<uint32_t>( mTextures.Size() );
84 if( textureCount < index + 1 )
86 mTextures.Resize( index + 1 );
88 bool samplerExist = true;
89 if( mSamplers.Size() < index + 1 )
91 mSamplers.Resize( index + 1 );
95 for( uint32_t i(textureCount); i<=index; ++i )
106 mTextures[index] = texture;
109 mHasAlpha |= texture->HasAlphaChannel();
112 NotifyChangeToRenderers();
115 bool TextureSet::HasAlpha() const
120 void TextureSet::AddObserver( Renderer* renderer )
122 for( auto&& element : mRenderers )
124 if( element == renderer )
126 //Renderer already in the list
131 mRenderers.PushBack( renderer );
134 void TextureSet::RemoveObserver( Renderer* renderer )
136 for( auto&& iter = mRenderers.Begin(), end = mRenderers.End(); iter != end; ++iter )
138 if( *iter == renderer )
140 mRenderers.Remove( iter );
146 void TextureSet::NotifyChangeToRenderers()
148 for( auto&& element : mRenderers )
150 element->TextureSetChanged();
154 } // namespace SceneGraph
156 } // namespace Internal