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());
40 if(index >= textureCount)
42 mTextures.resize(index + 1);
44 bool samplerExist = true;
45 if(mSamplers.size() < index + 1)
47 mSamplers.resize(index + 1);
51 for(uint32_t i(textureCount); i <= index; ++i)
53 mTextures[i] = nullptr;
57 mSamplers[i] = nullptr;
62 mTextures[index] = texture;
64 Render::TextureKey renderTexture{};
67 renderTexture = texture->GetRenderTextureKey();
70 SceneGraph::SetTextureMessage(mEventThreadServices, *mSceneObject, index, renderTexture);
73 Texture* TextureSet::GetTexture(uint32_t index) const
75 Texture* result(nullptr);
76 if(index < mTextures.size())
78 result = mTextures[index].Get();
82 DALI_LOG_ERROR("Error: Invalid index to TextureSet::GetTexture\n");
88 void TextureSet::SetSampler(uint32_t index, SamplerPtr sampler)
90 uint32_t samplerCount = static_cast<uint32_t>(mSamplers.size());
91 if(samplerCount < index + 1)
93 mSamplers.resize(index + 1);
94 for(uint32_t i = samplerCount; i <= index; ++i)
96 mSamplers[i] = nullptr;
100 mSamplers[index] = sampler;
102 Render::Sampler* renderSampler(nullptr);
105 renderSampler = sampler->GetSamplerRenderObject();
108 SceneGraph::SetSamplerMessage(mEventThreadServices, *mSceneObject, index, renderSampler);
111 Sampler* TextureSet::GetSampler(uint32_t index) const
113 Sampler* result(nullptr);
114 if(index < mSamplers.size())
116 result = mSamplers[index].Get();
120 DALI_LOG_ERROR("Error: Invalid index to TextureSet::GetSampler\n");
126 uint32_t TextureSet::GetTextureCount() const
128 return static_cast<uint32_t>(mTextures.size());
131 const SceneGraph::TextureSet* TextureSet::GetTextureSetSceneObject() const
136 TextureSet::TextureSet()
137 : mEventThreadServices(EventThreadServices::Get()),
138 mSceneObject(nullptr)
142 void TextureSet::Initialize()
144 SceneGraph::UpdateManager& updateManager = mEventThreadServices.GetUpdateManager();
146 mSceneObject = SceneGraph::TextureSet::New();
147 OwnerPointer<SceneGraph::TextureSet> transferOwnership(mSceneObject);
148 AddTextureSetMessage(updateManager, transferOwnership);
151 TextureSet::~TextureSet()
153 if(EventThreadServices::IsCoreRunning())
155 SceneGraph::UpdateManager& updateManager = mEventThreadServices.GetUpdateManager();
156 RemoveTextureSetMessage(updateManager, *mSceneObject);
160 } // namespace Internal