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/property-owner.h>
24 #include <dali/internal/update/common/uniform-map.h>
25 #include <dali/internal/update/common/scene-graph-connection-change-propagator.h>
26 #include <dali/internal/render/data-providers/render-data-provider.h>
40 class SceneController;
43 typedef Dali::Vector< Renderer* > RendererContainer;
44 typedef RendererContainer::Iterator RendererIter;
45 typedef RendererContainer::ConstIterator RendererConstIter;
50 class Renderer : public PropertyOwner,
51 public UniformMapDataProvider,
52 public UniformMap::Observer,
53 public ConnectionChangePropagator::Observer
65 * Construct a new Renderer
67 static Renderer* New();
75 * Overriden delete operator
76 * Deletes the renderer from its global memory pool
78 void operator delete( void* ptr );
81 * Set the material for the renderer
82 * @param[in] bufferIndex The current frame's buffer index
83 * @param[in] material The material this renderer will use
85 void SetMaterial( BufferIndex bufferIndex, Material* material);
88 * Get the material of this renderer
89 * @return the material this renderer uses
91 Material& GetMaterial()
97 * Set the geometry for the renderer
98 * @param[in] bufferIndex The current frame's buffer index
99 * @param[in] geometry The geometry this renderer will use
101 void SetGeometry( BufferIndex bufferIndex, Geometry* material);
104 * Get the geometry of this renderer
105 * @return the geometry this renderer uses
107 Geometry& GetGeometry()
113 * Set the depth index
114 * @param[in] depthIndex the new depth index to use
116 void SetDepthIndex( int depthIndex );
119 * @brief Get the depth index
120 * @return The depth index
122 int GetDepthIndex() const
128 * Called when an actor with this renderer is added to the stage
130 void OnStageConnect();
133 * Called when an actor with this renderer is removed from the stage
135 void OnStageDisconnect();
138 * Prepare the object for rendering.
139 * This is called by the UpdateManager when an object is due to be rendered in the current frame.
140 * @param[in] updateBufferIndex The current update buffer index.
142 void PrepareRender( BufferIndex updateBufferIndex );
145 * Retrieve the Render thread renderer
146 * @return The associated render thread renderer
148 Render::Renderer& GetRenderer();
151 * Check whether the renderer has been marked as ready to render
152 * ready means that renderer has all resources and should produce correct result
153 * complete means all resources have finished loading
154 * It's possible that renderer is complete but not ready,
155 * for example in case of resource load failed
156 * @param[out] ready TRUE if the renderer has resources to render
157 * @param[out] complete TRUE if the renderer resources are complete
159 void GetReadyAndComplete( bool& ready, bool& complete ) const;
162 * Query whether the renderer is fully opaque, fully transparent or transparent.
163 * @param[in] updateBufferIndex The current update buffer index.
164 * @return OPAQUE if fully opaque, TRANSPARENT if fully transparent and TRANSLUCENT if in between
166 Opacity GetOpacity( BufferIndex updateBufferIndex, const Node& node ) const;
169 * Query whether the renderer is currently in use by an actor on the stage
171 bool IsReferenced() const
173 return mReferenceCount > 0;
177 public: // Implementation of ObjectOwnerContainer template methods
179 * Connect the object to the scene graph
181 * @param[in] sceneController The scene controller - used for sending messages to render thread
182 * @param[in] bufferIndex The current buffer index - used for sending messages to render thread
184 void ConnectToSceneGraph( SceneController& sceneController, BufferIndex bufferIndex );
187 * Disconnect the object from the scene graph
188 * @param[in] sceneController The scene controller - used for sending messages to render thread
189 * @param[in] bufferIndex The current buffer index - used for sending messages to render thread
191 void DisconnectFromSceneGraph( SceneController& sceneController, BufferIndex bufferIndex );
193 public: // Implementation of ConnectionChangePropagator
195 * @copydoc ConnectionChangePropagator::AddObserver
197 void AddConnectionObserver(ConnectionChangePropagator::Observer& observer){};
200 * @copydoc ConnectionChangePropagator::RemoveObserver
202 void RemoveConnectionObserver(ConnectionChangePropagator::Observer& observer){};
207 public: // UniformMap::Observer
209 * @copydoc UniformMap::Observer::UniformMappingsChanged
211 virtual void UniformMappingsChanged( const UniformMap& mappings );
213 public: // ConnectionChangePropagator::Observer
216 * @copydoc ConnectionChangePropagator::ConnectionsChanged
218 virtual void ConnectionsChanged( PropertyOwner& owner );
221 * @copydoc ConnectionChangePropagator::ConnectedUniformMapChanged
223 virtual void ConnectedUniformMapChanged( );
226 * @copydoc ConnectionChangePropagator::ConnectedUniformMapChanged
228 virtual void ObservedObjectDestroyed(PropertyOwner& owner);
230 public: // PropertyOwner implementation
232 * @copydoc Dali::Internal::SceneGraph::PropertyOwner::ResetDefaultProperties()
234 virtual void ResetDefaultProperties( BufferIndex updateBufferIndex ){};
236 public: // From UniformMapDataProvider
239 * @copydoc UniformMapDataProvider::GetUniformMapChanged
241 virtual bool GetUniformMapChanged( BufferIndex bufferIndex ) const{ return mUniformMapChanged[bufferIndex];}
244 * @copydoc UniformMapDataProvider::GetUniformMap
246 virtual const CollectedUniformMap& GetUniformMap( BufferIndex bufferIndex ) const;
251 * Protected constructor; See also Renderer::New()
256 * Helper function to create a new render data provider
257 * @return the new (initialized) data provider
259 RenderDataProvider* NewRenderDataProvider();
261 SceneController* mSceneController; ///< Used for initializing renderers whilst attached
262 Render::Renderer* mRenderer; ///< Raw pointer to the new renderer (that's owned by RenderManager)
263 Material* mMaterial; ///< The material this renderer uses. (Not owned)
264 Geometry* mGeometry; ///< The geometry this renderer uses. (Not owned)
266 CollectedUniformMap mCollectedUniformMap[2]; ///< Uniform maps collected by the renderer
267 unsigned int mReferenceCount; ///< Number of nodes currently using this renderer
268 unsigned int mRegenerateUniformMap; ///< 2 if the map should be regenerated, 1 if it should be copied.
269 bool mUniformMapChanged[2]; ///< Records if the uniform map has been altered this frame
270 bool mResendDataProviders; ///< True if the data providers should be resent to the renderer
271 bool mResendGeometry; ///< True if geometry should be resent to the renderer
272 bool mResourcesReady; ///< Set during the Update algorithm; true if the attachment has resources ready for the current frame.
273 bool mFinishedResourceAcquisition; ///< Set during DoPrepareResources; true if ready & all resource acquisition has finished (successfully or otherwise)
276 int mDepthIndex; ///< Used only in PrepareRenderInstructions
281 inline void SetMaterialMessage( EventThreadServices& eventThreadServices, const Renderer& renderer, const Material& material )
283 typedef MessageDoubleBuffered1< Renderer, Material* > LocalType;
285 // Reserve some memory inside the message queue
286 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
288 // Construct message in the message queue memory; note that delete should not be called on the return value
289 new (slot) LocalType( &renderer, &Renderer::SetMaterial, const_cast<Material*>(&material) );
292 inline void SetGeometryMessage( EventThreadServices& eventThreadServices, const Renderer& renderer, const Geometry& geometry )
294 typedef MessageDoubleBuffered1< Renderer, Geometry* > LocalType;
296 // Reserve some memory inside the message queue
297 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
299 // Construct message in the message queue memory; note that delete should not be called on the return value
300 new (slot) LocalType( &renderer, &Renderer::SetGeometry, const_cast<Geometry*>(&geometry) );
303 inline void SetDepthIndexMessage( EventThreadServices& eventThreadServices, const Renderer& attachment, int depthIndex )
305 typedef MessageValue1< Renderer, int > LocalType;
307 // Reserve some memory inside the message queue
308 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
310 // Construct message in the message queue memory; note that delete should not be called on the return value
311 new (slot) LocalType( &attachment, &Renderer::SetDepthIndex, depthIndex );
314 inline void OnStageConnectMessage( EventThreadServices& eventThreadServices, const Renderer& renderer )
316 typedef Message< Renderer > LocalType;
318 // Reserve some memory inside the message queue
319 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
321 // Construct message in the message queue memory; note that delete should not be called on the return value
322 new (slot) LocalType( &renderer, &Renderer::OnStageConnect );
325 inline void OnStageDisconnectMessage( EventThreadServices& eventThreadServices, const Renderer& renderer )
327 typedef Message< Renderer > LocalType;
329 // Reserve some memory inside the message queue
330 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
332 // Construct message in the message queue memory; note that delete should not be called on the return value
333 new (slot) LocalType( &renderer, &Renderer::OnStageDisconnect );
336 } // namespace SceneGraph
337 } // namespace Internal
340 #endif // DALI_INTERNAL_SCENE_GRAPH_RENDERER_H