1 #ifndef DALI_INTERNAL_SCENE_GRAPH_RENDERER2_H
2 #define DALI_INTERNAL_SCENE_GRAPH_RENDERER2_H
5 * Copyright (c) 2015 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/geometry.h>
22 #include <dali/internal/event/common/event-thread-services.h>
23 #include <dali/internal/update/common/animatable-property.h>
24 #include <dali/internal/update/common/double-buffered.h>
25 #include <dali/internal/update/common/double-buffered-property.h>
26 #include <dali/internal/update/common/property-owner.h>
27 #include <dali/internal/update/common/property-boolean.h>
28 #include <dali/internal/update/common/uniform-map.h>
29 #include <dali/internal/update/common/scene-graph-connection-change-propagator.h>
30 #include <dali/internal/render/data-providers/render-data-provider.h>
44 class SceneController;
47 typedef Dali::Vector< Renderer* > RendererContainer;
48 typedef RendererContainer::Iterator RendererIter;
49 typedef RendererContainer::ConstIterator RendererConstIter;
54 class Renderer : public PropertyOwner,
55 public UniformMapDataProvider,
56 public UniformMap::Observer,
57 public ConnectionChangePropagator::Observer
79 * Set the material for the renderer
80 * @param[in] bufferIndex The current frame's buffer index
81 * @param[in] material The material this renderer will use
83 void SetMaterial( BufferIndex bufferIndex, Material* material);
86 * Get the material of this renderer
87 * @return the material this renderer uses
89 Material& GetMaterial()
95 * Set the geometry for the renderer
96 * @param[in] bufferIndex The current frame's buffer index
97 * @param[in] geometry The geometry this renderer will use
99 void SetGeometry( BufferIndex bufferIndex, Geometry* material);
102 * Get the geometry of this renderer
103 * @return the geometry this renderer uses
105 Geometry& GetGeometry()
111 * Set the depth index
112 * @param[in] depthIndex the new depth index to use
114 void SetDepthIndex( int depthIndex );
117 * @brief Get the depth index
118 * @return The depth index
120 int GetDepthIndex() const
126 * Called when an actor with this renderer is added to the stage
128 void OnStageConnect();
131 * Called when an actor with this renderer is removed from the stage
133 void OnStageDisconnect();
136 * Prepare the object for rendering.
137 * This is called by the UpdateManager when an object is due to be rendered in the current frame.
138 * @param[in] updateBufferIndex The current update buffer index.
140 void PrepareRender( BufferIndex updateBufferIndex );
143 * Retrieve the Render thread renderer
144 * @return The associated render thread renderer
146 Render::Renderer& GetRenderer();
149 * Check whether the renderer has been marked as ready to render
150 * ready means that renderer has all resources and should produce correct result
151 * complete means all resources have finished loading
152 * It's possible that renderer is complete but not ready,
153 * for example in case of resource load failed
154 * @param[out] ready TRUE if the renderer has resources to render
155 * @param[out] complete TRUE if the renderer resources are complete
157 void GetReadyAndComplete( bool& ready, bool& complete ) const;
160 * Query whether the renderer is fully opaque, fully transparent or transparent.
161 * @param[in] updateBufferIndex The current update buffer index.
162 * @return OPAQUE if fully opaque, TRANSPARENT if fully transparent and TRANSLUCENT if in between
164 Opacity GetOpacity( BufferIndex updateBufferIndex, const Node& node ) const;
167 * Query whether the renderer is currently in use by an actor on the stage
169 bool IsReferenced() const
171 return mReferenceCount > 0;
175 public: // Implementation of ObjectOwnerContainer template methods
177 * Connect the object to the scene graph
179 * @param[in] sceneController The scene controller - used for sending messages to render thread
180 * @param[in] bufferIndex The current buffer index - used for sending messages to render thread
182 void ConnectToSceneGraph( SceneController& sceneController, BufferIndex bufferIndex );
185 * Disconnect the object from the scene graph
186 * @param[in] sceneController The scene controller - used for sending messages to render thread
187 * @param[in] bufferIndex The current buffer index - used for sending messages to render thread
189 void DisconnectFromSceneGraph( SceneController& sceneController, BufferIndex bufferIndex );
191 public: // Implementation of ConnectionChangePropagator
193 * @copydoc ConnectionChangePropagator::AddObserver
195 void AddConnectionObserver(ConnectionChangePropagator::Observer& observer){};
198 * @copydoc ConnectionChangePropagator::RemoveObserver
200 void RemoveConnectionObserver(ConnectionChangePropagator::Observer& observer){};
205 public: // UniformMap::Observer
207 * @copydoc UniformMap::Observer::UniformMappingsChanged
209 virtual void UniformMappingsChanged( const UniformMap& mappings );
211 public: // ConnectionChangePropagator::Observer
214 * @copydoc ConnectionChangePropagator::ConnectionsChanged
216 virtual void ConnectionsChanged( PropertyOwner& owner );
219 * @copydoc ConnectionChangePropagator::ConnectedUniformMapChanged
221 virtual void ConnectedUniformMapChanged( );
224 * @copydoc ConnectionChangePropagator::ConnectedUniformMapChanged
226 virtual void ObservedObjectDestroyed(PropertyOwner& owner);
228 public: // PropertyOwner implementation
230 * @copydoc Dali::Internal::SceneGraph::PropertyOwner::ResetDefaultProperties()
232 virtual void ResetDefaultProperties( BufferIndex updateBufferIndex ){};
234 public: // From UniformMapDataProvider
237 * @copydoc UniformMapDataProvider::GetUniformMapChanged
239 virtual bool GetUniformMapChanged( BufferIndex bufferIndex ) const{ return mUniformMapChanged[bufferIndex];}
242 * @copydoc UniformMapDataProvider::GetUniformMap
244 virtual const CollectedUniformMap& GetUniformMap( BufferIndex bufferIndex ) const;
249 * Helper function to create a new render data provider
250 * @return the new (initialized) data provider
252 RenderDataProvider* NewRenderDataProvider();
254 SceneController* mSceneController; ///< Used for initializing renderers whilst attached
255 Render::Renderer* mRenderer; ///< Raw pointer to the new renderer (that's owned by RenderManager)
256 Material* mMaterial; ///< The material this renderer uses. (Not owned)
257 Geometry* mGeometry; ///< The geometry this renderer uses. (Not owned)
259 CollectedUniformMap mCollectedUniformMap[2]; ///< Uniform maps collected by the renderer
260 unsigned int mReferenceCount; ///< Number of nodes currently using this renderer
261 unsigned int mRegenerateUniformMap; ///< 2 if the map should be regenerated, 1 if it should be copied.
262 bool mUniformMapChanged[2]; ///< Records if the uniform map has been altered this frame
263 bool mResendDataProviders; ///< True if the data providers should be resent to the renderer
264 bool mResendGeometry; ///< True if geometry should be resent to the renderer
265 bool mResourcesReady; ///< Set during the Update algorithm; true if the attachment has resources ready for the current frame.
266 bool mFinishedResourceAcquisition; ///< Set during DoPrepareResources; true if ready & all resource acquisition has finished (successfully or otherwise)
269 int mDepthIndex; ///< Used only in PrepareRenderInstructions
274 inline void SetMaterialMessage( EventThreadServices& eventThreadServices, const Renderer& renderer, const Material& material )
276 typedef MessageDoubleBuffered1< Renderer, Material* > LocalType;
278 // Reserve some memory inside the message queue
279 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
281 // Construct message in the message queue memory; note that delete should not be called on the return value
282 new (slot) LocalType( &renderer, &Renderer::SetMaterial, const_cast<Material*>(&material) );
285 inline void SetGeometryMessage( EventThreadServices& eventThreadServices, const Renderer& renderer, const Geometry& geometry )
287 typedef MessageDoubleBuffered1< Renderer, Geometry* > LocalType;
289 // Reserve some memory inside the message queue
290 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
292 // Construct message in the message queue memory; note that delete should not be called on the return value
293 new (slot) LocalType( &renderer, &Renderer::SetGeometry, const_cast<Geometry*>(&geometry) );
296 inline void SetDepthIndexMessage( EventThreadServices& eventThreadServices, const Renderer& attachment, int depthIndex )
298 typedef MessageValue1< Renderer, int > LocalType;
300 // Reserve some memory inside the message queue
301 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
303 // Construct message in the message queue memory; note that delete should not be called on the return value
304 new (slot) LocalType( &attachment, &Renderer::SetDepthIndex, depthIndex );
307 inline void OnStageConnectMessage( EventThreadServices& eventThreadServices, const Renderer& renderer )
309 typedef Message< Renderer > LocalType;
311 // Reserve some memory inside the message queue
312 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
314 // Construct message in the message queue memory; note that delete should not be called on the return value
315 new (slot) LocalType( &renderer, &Renderer::OnStageConnect );
318 inline void OnStageDisconnectMessage( EventThreadServices& eventThreadServices, const Renderer& renderer )
320 typedef Message< Renderer > LocalType;
322 // Reserve some memory inside the message queue
323 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
325 // Construct message in the message queue memory; note that delete should not be called on the return value
326 new (slot) LocalType( &renderer, &Renderer::OnStageDisconnect );
329 } // namespace SceneGraph
330 } // namespace Internal
333 #endif // DALI_INTERNAL_SCENE_GRAPH_RENDERER_H