1 #ifndef DALI_INTERNAL_SCENE_GRAPH_TEXTURE_SET_H
2 #define DALI_INTERNAL_SCENE_GRAPH_TEXTURE_SET_H
5 * Copyright (c) 2021 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/internal/common/buffer-index.h>
22 #include <dali/internal/common/message.h>
23 #include <dali/internal/event/common/event-thread-services.h>
24 #include <dali/public-api/rendering/texture-set.h>
43 * Construct a new TextureSet.
45 static TextureSet* New();
48 * Destructor. Not virtual as not a base class and not inheriting anything
53 * Overriden delete operator
54 * Deletes the texture set from its global memory pool
56 void operator delete(void* ptr);
59 * Set the sampler to be used by the texture at position "index"
60 * @param[in] index The index of the texture
61 * @param[in] sampler The sampler to be used by the texture
63 void SetSampler(uint32_t index, Render::Sampler* sampler);
66 * Set the texture at position "index"
67 * @param[in] index The index of the texture
68 * @param[in] texture The texture
70 void SetTexture(uint32_t index, Render::Texture* texture);
73 * Return whether any texture in the texture set has an alpha channel
74 * @return true if at least one texture in the texture set has an alpha channel, false otherwise
76 bool HasAlpha() const;
79 * Adds a renderer to the Renderers list of the texture set.
80 * Renderers using the TextureSet get a notification when the texture set changes
82 * @param[in] renderer The renderer using the TextureSet
84 void AddObserver(Renderer* renderer);
87 * Removes a renderer from the TextureSet renderers list
89 * @param[in] renderer The renderer no longer using the TextureSet
91 void RemoveObserver(Renderer* renderer);
94 * Get the sampler of a texture in the TextureSet
95 * @param[in] index The index of the texture in the textures array
96 * @return the sampler used by the texture
98 Render::Sampler* GetTextureSampler(uint32_t index)
100 return mSamplers[index];
104 * Get the number of Textures in the texture set
105 * @return The number of Textures
107 uint32_t GetTextureCount()
109 return static_cast<uint32_t>(mTextures.Size());
113 * Get the pointer to a Texture in the TextureSet
114 * @param[in] index The index of the texture in the textures array
115 * @return the pointer to the Texture in that position
117 Render::Texture* GetTexture(uint32_t index)
119 return mTextures[index];
124 * Protected constructor; See also TextureSet::New()
129 * Helper method to notify the renderers observing the TextureSet
130 * that the TextureSet has changed
132 void NotifyChangeToRenderers();
135 Vector<Render::Sampler*> mSamplers; ///< List of samplers used by each texture. Not owned
136 Vector<Render::Texture*> mTextures; ///< List of Textures. Not owned
137 Vector<Renderer*> mRenderers; ///< List of renderers using the TextureSet
138 bool mHasAlpha; ///< if any of the textures has an alpha channel
141 inline void SetTextureMessage(EventThreadServices& eventThreadServices, const TextureSet& textureSet, uint32_t index, Render::Texture* texture)
143 using LocalType = MessageValue2<TextureSet, uint32_t, Render::Texture*>;
145 // Reserve some memory inside the message queue
146 uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
148 // Construct message in the message queue memory; note that delete should not be called on the return value
149 new(slot) LocalType(&textureSet, &TextureSet::SetTexture, index, texture);
152 inline void SetSamplerMessage(EventThreadServices& eventThreadServices, const TextureSet& textureSet, uint32_t index, Render::Sampler* sampler)
154 using LocalType = MessageValue2<TextureSet, uint32_t, Render::Sampler*>;
156 // Reserve some memory inside the message queue
157 uint32_t* slot = eventThreadServices.ReserveMessageSlot(sizeof(LocalType));
159 // Construct message in the message queue memory; note that delete should not be called on the return value
160 new(slot) LocalType(&textureSet, &TextureSet::SetSampler, index, sampler);
163 } // namespace SceneGraph
165 } // namespace Internal
169 #endif // DALI_INTERNAL_SCENE_GRAPH_TEXTURE_SET_H