1 #ifndef DALI_INTERNAL_SCENE_GRAPH_TEXTURE_SET_H
2 #define DALI_INTERNAL_SCENE_GRAPH_TEXTURE_SET_H
5 * Copyright (c) 2023 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
21 #include <dali/public-api/rendering/texture-set.h>
23 #include <dali/internal/common/buffer-index.h>
24 #include <dali/internal/common/message.h>
25 #include <dali/internal/event/common/event-thread-services.h>
26 #include <dali/internal/render/renderers/render-texture-key.h>
40 class RenderMessageDispatcher;
46 * Construct a new TextureSet.
48 static TextureSet* New();
51 * Destructor. Not virtual as not a base class and not inheriting anything
56 * Overriden delete operator
57 * Deletes the texture set from its global memory pool
59 void operator delete(void* ptr);
62 * Set the sampler to be used by the texture at position "index"
63 * @param[in] index The index of the texture
64 * @param[in] sampler The sampler to be used by the texture
66 void SetSampler(uint32_t index, Render::Sampler* sampler);
69 * Set the texture at position "index"
70 * @param[in] index The index of the texture
71 * @param[in] texture The texture
73 void SetTexture(uint32_t index, const Render::TextureKey& texture);
76 * Return whether any texture in the texture set has an alpha channel
77 * @return true if at least one texture in the texture set has an alpha channel, false otherwise
79 bool HasAlpha() const;
82 * Accessor for textures (used by RenderDataProvider impl)
84 const Vector<Render::TextureKey>& GetTextures()
90 * Accessor for samplers (used by RenderDataProvider impl)
92 const Vector<Render::Sampler*>& GetSamplers()
98 * Set the renderMessageDispatcher to send message.
99 * @param[in] renderMessageDispatcher The renderMessageDispatcher to send messages.
101 void SetRenderMessageDispatcher(RenderMessageDispatcher* renderMessageDispatcher);
104 * Get the capacity of the memory pools
105 * @return the capacity of the memory pools
107 static uint32_t GetMemoryPoolCapacity();
111 * Protected constructor; See also TextureSet::New()
117 * @brief Change the count of texture set. It will increase count automatically if we need more textures.
119 * @param[in] count The number of textures what this texture set want to hold
121 void SetTextureCount(uint32_t count);
124 * @brief Change the count of sampler set. It will increase count automatically if we need more samplers.
126 * @param[in] count The number of samplers what this texture set want to hold
128 void SetSamplerCount(uint32_t count);
131 * @brief Remove empty textures and samplers at the back of container, and resize.
133 void TrimContainers();
136 Vector<Render::Sampler*> mSamplers; ///< List of samplers used by each texture. Not owned
137 Vector<Render::TextureKey> mTextures; ///< List of Textures. Not owned
138 RenderMessageDispatcher* mRenderMessageDispatcher{nullptr}; ///< for sending messages to render thread. Not owned
139 bool mHasAlpha; ///< if any of the textures has an alpha channel
142 inline void SetTextureMessage(EventThreadServices& eventThreadServices, const TextureSet& textureSet, uint32_t index, const Render::TextureKey& textureKey)
144 using LocalType = MessageValue2<TextureSet, uint32_t, Render::TextureKey>;
146 // Reserve some memory inside the message queue
147 uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
149 // Construct message in the message queue memory; note that delete should not be called on the return value
150 new(slot) LocalType(&textureSet, &TextureSet::SetTexture, index, textureKey);
153 inline void SetSamplerMessage(EventThreadServices& eventThreadServices, const TextureSet& textureSet, uint32_t index, Render::Sampler* sampler)
155 using LocalType = MessageValue2<TextureSet, uint32_t, Render::Sampler*>;
157 // Reserve some memory inside the message queue
158 uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
160 // Construct message in the message queue memory; note that delete should not be called on the return value
161 new(slot) LocalType(&textureSet, &TextureSet::SetSampler, index, sampler);
164 } // namespace SceneGraph
166 } // namespace Internal
170 #endif // DALI_INTERNAL_SCENE_GRAPH_TEXTURE_SET_H