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);
57 Texture* TextureSet::GetTexture(uint32_t index) const
59 Texture* result(nullptr);
60 if(index < mTextures.size())
62 result = mTextures[index].Get();
66 DALI_LOG_ERROR("Error: Invalid index to TextureSet::GetTexture\n");
72 void TextureSet::SetSampler(uint32_t index, SamplerPtr sampler)
74 uint32_t samplerCount = static_cast<uint32_t>(mSamplers.size());
75 if(samplerCount < index + 1)
77 SetSamplerCount(index + 1);
80 mSamplers[index] = sampler;
82 Render::Sampler* renderSampler(nullptr);
85 renderSampler = sampler->GetSamplerRenderObject();
88 SceneGraph::SetSamplerMessage(mEventThreadServices, *mSceneObject, index, renderSampler);
91 Sampler* TextureSet::GetSampler(uint32_t index) const
93 Sampler* result(nullptr);
94 if(index < mSamplers.size())
96 result = mSamplers[index].Get();
100 DALI_LOG_ERROR("Error: Invalid index to TextureSet::GetSampler\n");
106 uint32_t TextureSet::GetTextureCount() const
108 return static_cast<uint32_t>(mTextures.size());
111 const SceneGraph::TextureSet* TextureSet::GetTextureSetSceneObject() const
116 void TextureSet::SetTextureCount(uint32_t count)
118 uint32_t textureCount = static_cast<uint32_t>(mTextures.size());
119 if(textureCount != count)
121 mTextures.resize(count, nullptr);
125 void TextureSet::SetSamplerCount(uint32_t count)
127 uint32_t samplerCount = static_cast<uint32_t>(mSamplers.size());
128 if(samplerCount != count)
130 mSamplers.resize(count, nullptr);
134 void TextureSet::TrimContainers()
136 uint32_t textureCount = static_cast<uint32_t>(mTextures.size());
137 uint32_t samplerCount = static_cast<uint32_t>(mSamplers.size());
139 while(textureCount > 0u)
141 if(mTextures[textureCount - 1u])
148 while(samplerCount > 0u)
150 if(mSamplers[samplerCount - 1u])
157 SetTextureCount(textureCount);
158 SetSamplerCount(samplerCount);
161 TextureSet::TextureSet()
162 : mEventThreadServices(EventThreadServices::Get()),
163 mSceneObject(nullptr)
167 void TextureSet::Initialize()
169 SceneGraph::UpdateManager& updateManager = mEventThreadServices.GetUpdateManager();
171 mSceneObject = SceneGraph::TextureSet::New();
172 OwnerPointer<SceneGraph::TextureSet> transferOwnership(mSceneObject);
173 AddTextureSetMessage(updateManager, transferOwnership);
176 TextureSet::~TextureSet()
178 if(EventThreadServices::IsCoreRunning())
180 SceneGraph::UpdateManager& updateManager = mEventThreadServices.GetUpdateManager();
181 RemoveTextureSetMessage(updateManager, *mSceneObject);
185 } // namespace Internal