2 * Copyright (c) 2022 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()
49 TextureSet::~TextureSet()
53 void TextureSet::operator delete(void* ptr)
55 gTextureSetMemoryPool.FreeThreadSafe(static_cast<TextureSet*>(ptr));
58 void TextureSet::SetSampler(uint32_t index, Render::Sampler* sampler)
60 const uint32_t samplerCount = static_cast<uint32_t>(mSamplers.Size());
61 if(samplerCount < index + 1)
63 mSamplers.Resize(index + 1);
64 for(uint32_t i(samplerCount); i <= index; ++i)
66 mSamplers[i] = nullptr;
70 mSamplers[index] = sampler;
72 if(index < static_cast<uint32_t>(mTextures.Size()))
74 mTextures[index]->SetUpdated(true);
78 void TextureSet::SetTexture(uint32_t index, Render::Texture* texture)
80 const uint32_t textureCount = static_cast<uint32_t>(mTextures.Size());
81 if(textureCount < index + 1)
83 mTextures.Resize(index + 1);
85 bool samplerExist = true;
86 if(mSamplers.Size() < index + 1)
88 mSamplers.Resize(index + 1);
92 for(uint32_t i(textureCount); i <= index; ++i)
94 mTextures[i] = nullptr;
98 mSamplers[i] = nullptr;
103 mTextures[index] = texture;
106 mHasAlpha |= texture->HasAlphaChannel();
107 texture->SetUpdated(true);
111 bool TextureSet::HasAlpha() const
116 } // namespace SceneGraph
118 } // namespace Internal