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()
56 void TextureSet::operator delete( void* ptr )
58 gTextureSetMemoryPool.FreeThreadSafe( static_cast<TextureSet*>( ptr ) );
61 void TextureSet::SetSampler( size_t index, Render::Sampler* sampler )
63 size_t samplerCount( mSamplers.Size() );
64 if( samplerCount < index + 1 )
66 mSamplers.Resize( index + 1 );
67 for( size_t i(samplerCount); i<=index; ++i )
73 mSamplers[index] = sampler;
74 NotifyChangeToRenderers();
77 void TextureSet::SetTexture( size_t index, Render::NewTexture* texture )
79 const size_t textureCount( mTextures.Size() );
80 if( textureCount < index + 1 )
82 mTextures.Resize( index + 1 );
84 bool samplerExist = true;
85 if( mSamplers.Size() < index + 1 )
87 mSamplers.Resize( index + 1 );
91 for( size_t i(textureCount); i<=index; ++i )
102 mTextures[index] = texture;
105 mHasAlpha |= texture->HasAlphaChannel();
108 NotifyChangeToRenderers();
111 bool TextureSet::HasAlpha() const
116 void TextureSet::AddObserver( Renderer* renderer )
118 size_t rendererCount( mRenderers.Size() );
119 for( size_t i(0); i<rendererCount; ++i )
121 if( mRenderers[i] == renderer )
123 //Renderer already in the list
128 mRenderers.PushBack( renderer );
131 void TextureSet::RemoveObserver( Renderer* renderer )
133 size_t rendererCount( mRenderers.Size() );
134 for( size_t i(0); i<rendererCount; ++i )
136 if( mRenderers[i] == renderer )
138 mRenderers.Remove( mRenderers.Begin() + i );
144 void TextureSet::NotifyChangeToRenderers()
146 size_t rendererCount = mRenderers.Size();
147 for( size_t i(0); i<rendererCount; ++i )
149 mRenderers[i]->TextureSetChanged();
153 } // namespace SceneGraph
155 } // namespace Internal