2 * Copyright (c) 2021 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/render/renderers/render-texture.h>
24 #include <dali/internal/update/rendering/scene-graph-renderer.h>
26 namespace //Unnamed namespace
28 //Memory pool used to allocate new texture sets. Memory used by this pool will be released when shutting down DALi
29 Dali::Internal::MemoryPoolObjectAllocator<Dali::Internal::SceneGraph::TextureSet> gTextureSetMemoryPool;
38 TextureSet* TextureSet::New()
40 return new(gTextureSetMemoryPool.AllocateRawThreadSafe()) TextureSet();
43 TextureSet::TextureSet()
50 TextureSet::~TextureSet()
52 for(auto&& renderer : mRenderers)
54 renderer->TextureSetDeleted();
58 void TextureSet::operator delete(void* ptr)
60 gTextureSetMemoryPool.FreeThreadSafe(static_cast<TextureSet*>(ptr));
63 void TextureSet::SetSampler(uint32_t index, Render::Sampler* sampler)
65 const uint32_t samplerCount = static_cast<uint32_t>(mSamplers.Size());
66 if(samplerCount < index + 1)
68 mSamplers.Resize(index + 1);
69 for(uint32_t i(samplerCount); i <= index; ++i)
71 mSamplers[i] = nullptr;
75 mSamplers[index] = sampler;
76 NotifyChangeToRenderers();
79 void TextureSet::SetTexture(uint32_t index, Render::Texture* texture)
81 const uint32_t textureCount = static_cast<uint32_t>(mTextures.Size());
82 if(textureCount < index + 1)
84 mTextures.Resize(index + 1);
86 bool samplerExist = true;
87 if(mSamplers.Size() < index + 1)
89 mSamplers.Resize(index + 1);
93 for(uint32_t i(textureCount); i <= index; ++i)
95 mTextures[i] = nullptr;
99 mSamplers[i] = nullptr;
104 mTextures[index] = texture;
107 mHasAlpha |= texture->HasAlphaChannel();
110 NotifyChangeToRenderers();
113 bool TextureSet::HasAlpha() const
118 void TextureSet::AddObserver(Renderer* renderer)
120 for(auto&& element : mRenderers)
122 if(element == renderer)
124 //Renderer already in the list
129 mRenderers.PushBack(renderer);
132 void TextureSet::RemoveObserver(Renderer* renderer)
134 for(auto &&iter = mRenderers.Begin(), end = mRenderers.End(); iter != end; ++iter)
136 if(*iter == renderer)
138 mRenderers.Remove(iter);
144 void TextureSet::NotifyChangeToRenderers()
146 for(auto&& element : mRenderers)
148 element->TextureSetChanged();
152 } // namespace SceneGraph
154 } // namespace Internal