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/devel-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 * Return whether any texture in the texture set has an alpha channel
84 * @return true if at least one texture in the texture set has an alpha channel, false otherwise
86 bool HasAlpha() const;
89 * Get the resource status
90 * Note, we need two values as it's possible that some resource failed to load
91 * in which case resourcesReady is false (the texture set is not good to be used for rendering)
92 * but finishedResourceAcquisition if true as there is no more loading going on
93 * @param[out] resourcesReady if the texture set is ready to be used for rendering
94 * @param[out] finishedResourceAcquisition if
96 void GetResourcesStatus( bool& resourcesReady, bool& finishedResourceAcquisition );
99 * Adds a renderer to the Renderers list of the texture set.
100 * Renderers using the TextureSet get a notification when the texture set changes
102 * @param[in] renderer The renderer using the TextureSet
104 void AddObserver( Renderer* renderer );
107 * Removes a renderer from the TextureSet renderers list
109 * @param[in] renderer The renderer no longer using the TextureSet
111 void RemoveObserver( Renderer* renderer );
114 * Get the ResourceId of a texture in the TextureSet
115 * @param[in] index The index of the texture in the textures array
116 * @return the ResourceId
118 ResourceId GetTextureId( size_t index )
120 return mTextureId[index];
124 * Get the sampler of a texture in the TextureSet
125 * @param[in] index The index of the texture in the textures array
126 * @return the sampler used by the texture
128 Render::Sampler* GetTextureSampler( size_t index )
130 return mSamplers[index];
134 * Get the number of textures in the texture set
135 * @return The number of textures
137 size_t GetTextureCount()
139 return mTextureId.Size();
146 * Protected constructor; See also TextureSet::New()
151 * Helper method to notify the renderers observing the TextureSet
152 * that the TextureSet has changed
154 void NotifyChangeToRenderers();
158 Vector< Render::Sampler* > mSamplers; ///< List of samplers used by each texture. Not owned
159 Vector< ResourceId > mTextureId; ///< List of texture ids
160 Vector<Renderer*> mRenderers; ///< List of renderers using the TextureSet
161 bool mResourcesReady; ///< if the textures are ready to be used for rendering
162 bool mFinishedResourceAcquisition; ///< if resource loading is completed
163 bool mChanged; ///< if the texture set has changed since the last frame
164 bool mHasAlpha; ///< if any of the textures has an alpha channel
167 inline void SetImageMessage( EventThreadServices& eventThreadServices, const TextureSet& textureSet, size_t index, ResourceId resourceId )
169 typedef MessageValue2< TextureSet, size_t, ResourceId > LocalType;
171 // Reserve some memory inside the message queue
172 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
174 // Construct message in the message queue memory; note that delete should not be called on the return value
175 new (slot) LocalType( &textureSet, &TextureSet::SetImage, index, resourceId );
178 inline void SetSamplerMessage( EventThreadServices& eventThreadServices, const TextureSet& textureSet, size_t index, Render::Sampler* sampler )
180 typedef MessageValue2< TextureSet, size_t, Render::Sampler* > LocalType;
182 // Reserve some memory inside the message queue
183 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
185 // Construct message in the message queue memory; note that delete should not be called on the return value
186 new (slot) LocalType( &textureSet, &TextureSet::SetSampler, index, sampler );
189 } // namespace SceneGraph
191 } // namespace Internal
195 #endif // DALI_INTERNAL_SCENE_GRAPH_TEXTURE_SET_H