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/event/common/event-thread-services.h>
24 #include <dali/internal/update/common/animatable-property.h>
25 #include <dali/internal/update/common/property-owner.h>
26 #include <dali/internal/update/common/scene-graph-connection-change-propagator.h>
27 #include <dali/internal/update/common/uniform-map.h>
28 #include <dali/internal/update/resources/resource-manager-declarations.h>
34 class ResourceManager;
44 class ConnectionObserver;
45 class SceneController;
47 class TextureSet : public PropertyOwner, public UniformMap::Observer
52 * Construct a new TextureSet.
54 static TextureSet* New();
59 virtual ~TextureSet();
62 * Overriden delete operator
63 * Deletes the texture set from its global memory pool
65 void operator delete( void* ptr );
68 * Prepare the texture set, check texture loading status, opacity etc
69 * @param resourceManager for checking texture details and loading status
71 void Prepare( const ResourceManager& resourceManager );
74 * Set the resource id for the texture at position "index"
75 * @param[in] index The index of the texture
76 * @param[in] imageId the resource id of the imag
78 void SetImage( size_t index, ResourceId imageId );
81 * Set the sampler to be used by the texture at position "index"
82 * @param[in] index The index of the texture
83 * @param[in] sampler The sampler to be used by the texture
85 void SetSampler( size_t index, Render::Sampler* sampler );
88 * Return whether any texture in the texture set has an alpha channel
89 * @return true if at least one texture in the texture set has an alpha channel, false otherwise
91 bool HasAlpha() const;
94 * Get the resource status
95 * Note, we need two values as it's possible that some resource failed to load
96 * in which case resourcesReady is false (the texture set is not good to be used for rendering)
97 * but finishedResourceAcquisition if true as there is no more loading going on
98 * @param[out] resourcesReady if the texture set is ready to be used for rendering
99 * @param[out] finishedResourceAcquisition if
101 void GetResourcesStatus( bool& resourcesReady, bool& finishedResourceAcquisition );
104 public: // Implementation of ObjectOwnerContainer template methods
107 * Connect the object to the scene graph
109 * @param[in] sceneController The scene controller - used for sending messages to render thread
110 * @param[in] bufferIndex The current buffer index - used for sending messages to render thread
112 void ConnectToSceneGraph( SceneController& sceneController, BufferIndex bufferIndex );
115 * Disconnect the object from the scene graph
116 * @param[in] sceneController The scene controller - used for sending messages to render thread
117 * @param[in] bufferIndex The current buffer index - used for sending messages to render thread
119 void DisconnectFromSceneGraph( SceneController& sceneController, BufferIndex bufferIndex );
121 public: // Implementation of ConnectionChangePropagator
124 * @copydoc ConnectionChangePropagator::AddObserver
126 void AddConnectionObserver(ConnectionChangePropagator::Observer& observer);
129 * @copydoc ConnectionChangePropagator::RemoveObserver
131 void RemoveConnectionObserver(ConnectionChangePropagator::Observer& observer);
136 * Get the ResourceId of a texture in the TextureSet
137 * @param[in] index The index of the texture in the textures array
138 * @return the ResourceId
140 ResourceId GetTextureId( size_t index )
142 return mTextureId[index];
146 * Get the sampler of a texture in the TextureSet
147 * @param[in] index The index of the texture in the textures array
148 * @return the sampler used by the texture
150 Render::Sampler* GetTextureSampler( size_t index )
152 return mSamplers[index];
156 * Get the number of textures in the texture set
157 * @return The number of textures
159 size_t GetTextureCount()
161 return mTextureId.Size();
164 public: // UniformMap::Observer
166 * @copydoc UniformMap::Observer::UniformMappingsChanged
168 virtual void UniformMappingsChanged( const UniformMap& mappings );
173 * Protected constructor; See also TextureSet::New()
179 Vector< Render::Sampler* > mSamplers; // Not owned
180 Vector< ResourceId > mTextureId;
181 ConnectionChangePropagator mConnectionObservers;
182 bool mResourcesReady; ///< if the textures are ready to be used for rendering
183 bool mFinishedResourceAcquisition; ///< if resource loading is completed
184 bool mChanged; ///< if the texture set has changed since the last frame
185 bool mHasAlpha; ///< if any of the textures has an alpha channel
188 inline void SetImageMessage( EventThreadServices& eventThreadServices, const TextureSet& textureSet, size_t index, ResourceId resourceId )
190 typedef MessageValue2< TextureSet, size_t, ResourceId > LocalType;
192 // Reserve some memory inside the message queue
193 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
195 // Construct message in the message queue memory; note that delete should not be called on the return value
196 new (slot) LocalType( &textureSet, &TextureSet::SetImage, index, resourceId );
199 inline void SetSamplerMessage( EventThreadServices& eventThreadServices, const TextureSet& textureSet, size_t index, Render::Sampler* sampler )
201 typedef MessageValue2< TextureSet, size_t, Render::Sampler* > LocalType;
203 // Reserve some memory inside the message queue
204 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
206 // Construct message in the message queue memory; note that delete should not be called on the return value
207 new (slot) LocalType( &textureSet, &TextureSet::SetSampler, index, sampler );
210 } // namespace SceneGraph
212 } // namespace Internal
216 #endif // DALI_INTERNAL_SCENE_GRAPH_TEXTURE_SET_H