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 size_t rendererCount = mRenderers.Size();
55 for( size_t i(0); i<rendererCount; ++i )
57 mRenderers[i]->TextureSetDeleted();
61 void TextureSet::operator delete( void* ptr )
63 gTextureSetMemoryPool.FreeThreadSafe( static_cast<TextureSet*>( ptr ) );
66 void TextureSet::SetSampler( size_t index, Render::Sampler* sampler )
68 size_t samplerCount( mSamplers.Size() );
69 if( samplerCount < index + 1 )
71 mSamplers.Resize( index + 1 );
72 for( size_t i(samplerCount); i<=index; ++i )
78 mSamplers[index] = sampler;
79 NotifyChangeToRenderers();
82 void TextureSet::SetTexture( size_t index, Render::Texture* texture )
84 const size_t textureCount( mTextures.Size() );
85 if( textureCount < index + 1 )
87 mTextures.Resize( index + 1 );
89 bool samplerExist = true;
90 if( mSamplers.Size() < index + 1 )
92 mSamplers.Resize( index + 1 );
96 for( size_t i(textureCount); i<=index; ++i )
107 mTextures[index] = texture;
110 mHasAlpha |= texture->HasAlphaChannel();
113 NotifyChangeToRenderers();
116 bool TextureSet::HasAlpha() const
121 void TextureSet::AddObserver( Renderer* renderer )
123 size_t rendererCount( mRenderers.Size() );
124 for( size_t i(0); i<rendererCount; ++i )
126 if( mRenderers[i] == renderer )
128 //Renderer already in the list
133 mRenderers.PushBack( renderer );
136 void TextureSet::RemoveObserver( Renderer* renderer )
138 size_t rendererCount( mRenderers.Size() );
139 for( size_t i(0); i<rendererCount; ++i )
141 if( mRenderers[i] == renderer )
143 mRenderers.Remove( mRenderers.Begin() + i );
149 void TextureSet::NotifyChangeToRenderers()
151 size_t rendererCount = mRenderers.Size();
152 for( size_t i(0); i<rendererCount; ++i )
154 mRenderers[i]->TextureSetChanged();
158 } // namespace SceneGraph
160 } // namespace Internal