2 * Copyright (c) 2023 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>& GetTextureSetMemoryPool()
31 static Dali::Internal::MemoryPoolObjectAllocator<Dali::Internal::SceneGraph::TextureSet> gTextureSetMemoryPool;
32 return gTextureSetMemoryPool;
42 TextureSet* TextureSet::New()
44 return new(GetTextureSetMemoryPool().AllocateRawThreadSafe()) TextureSet();
47 TextureSet::TextureSet()
53 TextureSet::~TextureSet()
57 void TextureSet::operator delete(void* ptr)
59 GetTextureSetMemoryPool().FreeThreadSafe(static_cast<TextureSet*>(ptr));
62 void TextureSet::SetSampler(uint32_t index, Render::Sampler* sampler)
64 const uint32_t samplerCount = static_cast<uint32_t>(mSamplers.Size());
65 if(samplerCount < index + 1)
67 mSamplers.Resize(index + 1);
68 for(uint32_t i(samplerCount); i <= index; ++i)
70 mSamplers[i] = nullptr;
74 mSamplers[index] = sampler;
76 if(index < static_cast<uint32_t>(mTextures.Size()))
78 mTextures[index]->SetUpdated(true);
82 void TextureSet::SetTexture(uint32_t index, const Render::TextureKey& texture)
84 const uint32_t textureCount = static_cast<uint32_t>(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(uint32_t i(textureCount); i <= index; ++i)
98 mTextures[i] = Render::TextureKey{};
102 mSamplers[i] = nullptr;
107 mTextures[index] = texture;
110 mHasAlpha |= texture->HasAlphaChannel();
111 texture->SetUpdated(true);
115 bool TextureSet::HasAlpha() const
120 uint32_t TextureSet::GetMemoryPoolCapacity()
122 return GetTextureSetMemoryPool().GetCapacity();
125 } // namespace SceneGraph
127 } // namespace Internal