1 #ifndef DALI_INTERNAL_SCENE_GRAPH_TEXTURE_SET_H
2 #define DALI_INTERNAL_SCENE_GRAPH_TEXTURE_SET_H
5 * Copyright (c) 2016 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>
22 #include <dali/internal/common/buffer-index.h>
23 #include <dali/internal/common/message.h>
24 #include <dali/internal/event/common/event-thread-services.h>
25 #include <dali/internal/update/resources/resource-manager-declarations.h>
31 class ResourceManager;
47 * Construct a new TextureSet.
49 static TextureSet* New();
54 virtual ~TextureSet();
57 * Overriden delete operator
58 * Deletes the texture set from its global memory pool
60 void operator delete( void* ptr );
63 * Prepare the texture set, check texture loading status, opacity etc
64 * @param resourceManager for checking texture details and loading status
66 void Prepare( const ResourceManager& resourceManager );
69 * Set the resource id for the texture at position "index"
70 * @param[in] index The index of the texture
71 * @param[in] imageId the resource id of the imag
73 void SetImage( size_t index, ResourceId imageId );
76 * Set the sampler to be used by the texture at position "index"
77 * @param[in] index The index of the texture
78 * @param[in] sampler The sampler to be used by the texture
80 void SetSampler( size_t index, Render::Sampler* sampler );
83 * Set the texture at position "index"
84 * @param[in] index The index of the texture
85 * @param[in] texture The texture
87 void SetTexture( size_t index, Render::NewTexture* texture );
90 * Return whether any texture in the texture set has an alpha channel
91 * @return true if at least one texture in the texture set has an alpha channel, false otherwise
93 bool HasAlpha() const;
96 * Get the resource status
97 * Note, we need two values as it's possible that some resource failed to load
98 * in which case resourcesReady is false (the texture set is not good to be used for rendering)
99 * but finishedResourceAcquisition if true as there is no more loading going on
100 * @param[out] resourcesReady if the texture set is ready to be used for rendering
101 * @param[out] finishedResourceAcquisition if
103 void GetResourcesStatus( bool& resourcesReady, bool& finishedResourceAcquisition );
106 * Adds a renderer to the Renderers list of the texture set.
107 * Renderers using the TextureSet get a notification when the texture set changes
109 * @param[in] renderer The renderer using the TextureSet
111 void AddObserver( Renderer* renderer );
114 * Removes a renderer from the TextureSet renderers list
116 * @param[in] renderer The renderer no longer using the TextureSet
118 void RemoveObserver( Renderer* renderer );
121 * Get the ResourceId of a texture in the TextureSet
122 * @param[in] index The index of the texture in the textures array
123 * @return the ResourceId
125 ResourceId GetTextureId( size_t index )
127 return mTextureId[index];
131 * Get the sampler of a texture in the TextureSet
132 * @param[in] index The index of the texture in the textures array
133 * @return the sampler used by the texture
135 Render::Sampler* GetTextureSampler( size_t index )
137 return mSamplers[index];
141 * Get the number of textures in the texture set
142 * @return The number of textures
144 size_t GetTextureCount()
146 return mTextureId.Size();
150 * Get the number of NewTextures in the texture set
151 * @return The number of NewTextures
153 size_t GetNewTextureCount()
155 return mTextures.Size();
159 * Get the pointer to a NewTexture in the TextureSet
160 * @param[in] index The index of the texture in the textures array
161 * @return the pointer to the NewTexture in that position
163 Render::NewTexture* GetNewTexture( size_t index )
165 return mTextures[index];
171 * Protected constructor; See also TextureSet::New()
176 * Helper method to notify the renderers observing the TextureSet
177 * that the TextureSet has changed
179 void NotifyChangeToRenderers();
183 Vector< Render::Sampler* > mSamplers; ///< List of samplers used by each texture. Not owned
184 Vector< Render::NewTexture* > mTextures; ///< List of NewTextures. Not owned
185 Vector< ResourceId > mTextureId; ///< List of texture ids
186 Vector<Renderer*> mRenderers; ///< List of renderers using the TextureSet
187 bool mResourcesReady; ///< if the textures are ready to be used for rendering
188 bool mFinishedResourceAcquisition; ///< if resource loading is completed
189 bool mChanged; ///< if the texture set has changed since the last frame
190 bool mHasAlpha; ///< if any of the textures has an alpha channel
193 inline void SetImageMessage( EventThreadServices& eventThreadServices, const TextureSet& textureSet, size_t index, ResourceId resourceId )
195 typedef MessageValue2< TextureSet, size_t, ResourceId > LocalType;
197 // Reserve some memory inside the message queue
198 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
200 // Construct message in the message queue memory; note that delete should not be called on the return value
201 new (slot) LocalType( &textureSet, &TextureSet::SetImage, index, resourceId );
204 inline void SetTextureMessage( EventThreadServices& eventThreadServices, const TextureSet& textureSet, size_t index, Render::NewTexture* texture )
206 typedef MessageValue2< TextureSet, size_t, Render::NewTexture* > LocalType;
208 // Reserve some memory inside the message queue
209 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
211 // Construct message in the message queue memory; note that delete should not be called on the return value
212 new (slot) LocalType( &textureSet, &TextureSet::SetTexture, index, texture );
215 inline void SetSamplerMessage( EventThreadServices& eventThreadServices, const TextureSet& textureSet, size_t index, Render::Sampler* sampler )
217 typedef MessageValue2< TextureSet, size_t, Render::Sampler* > LocalType;
219 // Reserve some memory inside the message queue
220 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
222 // Construct message in the message queue memory; note that delete should not be called on the return value
223 new (slot) LocalType( &textureSet, &TextureSet::SetSampler, index, sampler );
226 } // namespace SceneGraph
228 } // namespace Internal
232 #endif // DALI_INTERNAL_SCENE_GRAPH_TEXTURE_SET_H