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.
19 #include <dali/internal/event/rendering/texture-set-impl.h> // Dali::Internal::TextureSet
22 #include <dali/internal/update/manager/update-manager.h>
23 #include <dali/internal/update/rendering/scene-graph-texture-set.h>
24 #include <dali/public-api/object/type-registry.h>
30 TextureSetPtr TextureSet::New()
32 TextureSetPtr textureSet(new TextureSet());
33 textureSet->Initialize();
37 void TextureSet::SetTexture(uint32_t index, TexturePtr texture)
39 uint32_t textureCount = static_cast<uint32_t>(mTextures.size());
41 if(textureCount < index + 1)
43 SetTextureCount(index + 1);
46 mTextures[index] = texture;
48 Render::TextureKey renderTexture{};
51 renderTexture = texture->GetRenderTextureKey();
54 SceneGraph::SetTextureMessage(mEventThreadServices, *mSceneObject, index, renderTexture);
58 // Check wheter we need to pop back textures
63 Texture* TextureSet::GetTexture(uint32_t index) const
65 Texture* result(nullptr);
66 if(index < mTextures.size())
68 result = mTextures[index].Get();
72 DALI_LOG_ERROR("Error: Invalid index to TextureSet::GetTexture\n");
78 void TextureSet::SetSampler(uint32_t index, SamplerPtr sampler)
80 uint32_t samplerCount = static_cast<uint32_t>(mSamplers.size());
81 if(samplerCount < index + 1)
83 SetSamplerCount(index + 1);
86 mSamplers[index] = sampler;
88 Render::Sampler* renderSampler(nullptr);
91 renderSampler = sampler->GetSamplerRenderObject();
94 SceneGraph::SetSamplerMessage(mEventThreadServices, *mSceneObject, index, renderSampler);
98 // Check wheter we need to pop back sampler
103 Sampler* TextureSet::GetSampler(uint32_t index) const
105 Sampler* result(nullptr);
106 if(index < mSamplers.size())
108 result = mSamplers[index].Get();
112 DALI_LOG_ERROR("Error: Invalid index to TextureSet::GetSampler\n");
118 uint32_t TextureSet::GetTextureCount() const
120 return static_cast<uint32_t>(mTextures.size());
123 const SceneGraph::TextureSet* TextureSet::GetTextureSetSceneObject() const
128 void TextureSet::SetTextureCount(uint32_t count)
130 uint32_t textureCount = static_cast<uint32_t>(mTextures.size());
131 if(textureCount != count)
133 mTextures.resize(count, nullptr);
137 void TextureSet::SetSamplerCount(uint32_t count)
139 uint32_t samplerCount = static_cast<uint32_t>(mSamplers.size());
140 if(samplerCount != count)
142 mSamplers.resize(count, nullptr);
146 void TextureSet::TrimContainers()
148 uint32_t textureCount = static_cast<uint32_t>(mTextures.size());
149 uint32_t samplerCount = static_cast<uint32_t>(mSamplers.size());
151 while(textureCount > 0u)
153 if(mTextures[textureCount - 1u])
160 while(samplerCount > 0u)
162 if(mSamplers[samplerCount - 1u])
169 SetTextureCount(textureCount);
170 SetSamplerCount(samplerCount);
173 TextureSet::TextureSet()
174 : mEventThreadServices(EventThreadServices::Get()),
175 mSceneObject(nullptr)
179 void TextureSet::Initialize()
181 SceneGraph::UpdateManager& updateManager = mEventThreadServices.GetUpdateManager();
183 mSceneObject = SceneGraph::TextureSet::New();
184 OwnerPointer<SceneGraph::TextureSet> transferOwnership(mSceneObject);
185 AddTextureSetMessage(updateManager, transferOwnership);
188 TextureSet::~TextureSet()
190 if(EventThreadServices::IsCoreRunning())
192 SceneGraph::UpdateManager& updateManager = mEventThreadServices.GetUpdateManager();
193 RemoveTextureSetMessage(updateManager, *mSceneObject);
197 } // namespace Internal