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
75 * Set the material for the renderer
76 * @param[in] bufferIndex The current frame's buffer index
77 * @param[in] material The material this renderer will use
79 void SetMaterial( BufferIndex bufferIndex, Material* material);
82 * Get the material of this renderer
83 * @return the material this renderer uses
85 Material& GetMaterial()
91 * Set the geometry for the renderer
92 * @param[in] bufferIndex The current frame's buffer index
93 * @param[in] geometry The geometry this renderer will use
95 void SetGeometry( BufferIndex bufferIndex, Geometry* material);
98 * Get the geometry of this renderer
99 * @return the geometry this renderer uses
101 Geometry& GetGeometry()
107 * Set the depth index
108 * @param[in] depthIndex the new depth index to use
110 void SetDepthIndex( int depthIndex );
113 * @brief Get the depth index
114 * @return The depth index
116 int GetDepthIndex() const
122 * Called when an actor with this renderer is added to the stage
124 void OnStageConnect();
127 * Called when an actor with this renderer is removed from the stage
129 void OnStageDisconnect();
132 * Prepare the object for rendering.
133 * This is called by the UpdateManager when an object is due to be rendered in the current frame.
134 * @param[in] updateBufferIndex The current update buffer index.
136 void PrepareRender( BufferIndex updateBufferIndex );
139 * Retrieve the Render thread renderer
140 * @return The associated render thread renderer
142 Render::Renderer& GetRenderer();
145 * Check whether the renderer has been marked as ready to render
146 * ready means that renderer has all resources and should produce correct result
147 * complete means all resources have finished loading
148 * It's possible that renderer is complete but not ready,
149 * for example in case of resource load failed
150 * @param[out] ready TRUE if the renderer has resources to render
151 * @param[out] complete TRUE if the renderer resources are complete
153 void GetReadyAndComplete( bool& ready, bool& complete ) const;
156 * Query whether the renderer is fully opaque, fully transparent or transparent.
157 * @param[in] updateBufferIndex The current update buffer index.
158 * @return OPAQUE if fully opaque, TRANSPARENT if fully transparent and TRANSLUCENT if in between
160 Opacity GetOpacity( BufferIndex updateBufferIndex, const Node& node ) const;
163 * Query whether the renderer is currently in use by an actor on the stage
165 bool IsReferenced() const
167 return mReferenceCount > 0;
171 public: // Implementation of ObjectOwnerContainer template methods
173 * Connect the object to the scene graph
175 * @param[in] sceneController The scene controller - used for sending messages to render thread
176 * @param[in] bufferIndex The current buffer index - used for sending messages to render thread
178 void ConnectToSceneGraph( SceneController& sceneController, BufferIndex bufferIndex );
181 * Disconnect the object from the scene graph
182 * @param[in] sceneController The scene controller - used for sending messages to render thread
183 * @param[in] bufferIndex The current buffer index - used for sending messages to render thread
185 void DisconnectFromSceneGraph( SceneController& sceneController, BufferIndex bufferIndex );
187 public: // Implementation of ConnectionChangePropagator
189 * @copydoc ConnectionChangePropagator::AddObserver
191 void AddConnectionObserver(ConnectionChangePropagator::Observer& observer){};
194 * @copydoc ConnectionChangePropagator::RemoveObserver
196 void RemoveConnectionObserver(ConnectionChangePropagator::Observer& observer){};
201 public: // UniformMap::Observer
203 * @copydoc UniformMap::Observer::UniformMappingsChanged
205 virtual void UniformMappingsChanged( const UniformMap& mappings );
207 public: // ConnectionChangePropagator::Observer
210 * @copydoc ConnectionChangePropagator::ConnectionsChanged
212 virtual void ConnectionsChanged( PropertyOwner& owner );
215 * @copydoc ConnectionChangePropagator::ConnectedUniformMapChanged
217 virtual void ConnectedUniformMapChanged( );
220 * @copydoc ConnectionChangePropagator::ConnectedUniformMapChanged
222 virtual void ObservedObjectDestroyed(PropertyOwner& owner);
224 public: // PropertyOwner implementation
226 * @copydoc Dali::Internal::SceneGraph::PropertyOwner::ResetDefaultProperties()
228 virtual void ResetDefaultProperties( BufferIndex updateBufferIndex ){};
230 public: // From UniformMapDataProvider
233 * @copydoc UniformMapDataProvider::GetUniformMapChanged
235 virtual bool GetUniformMapChanged( BufferIndex bufferIndex ) const{ return mUniformMapChanged[bufferIndex];}
238 * @copydoc UniformMapDataProvider::GetUniformMap
240 virtual const CollectedUniformMap& GetUniformMap( BufferIndex bufferIndex ) const;
245 * Helper function to create a new render data provider
246 * @return the new (initialized) data provider
248 RenderDataProvider* NewRenderDataProvider();
250 SceneController* mSceneController; ///< Used for initializing renderers whilst attached
251 Render::Renderer* mRenderer; ///< Raw pointer to the new renderer (that's owned by RenderManager)
252 Material* mMaterial; ///< The material this renderer uses. (Not owned)
253 Geometry* mGeometry; ///< The geometry this renderer uses. (Not owned)
255 CollectedUniformMap mCollectedUniformMap[2]; ///< Uniform maps collected by the renderer
256 unsigned int mReferenceCount; ///< Number of nodes currently using this renderer
257 unsigned int mRegenerateUniformMap; ///< 2 if the map should be regenerated, 1 if it should be copied.
258 bool mUniformMapChanged[2]; ///< Records if the uniform map has been altered this frame
259 bool mResendDataProviders; ///< True if the data providers should be resent to the renderer
260 bool mResendGeometry; ///< True if geometry should be resent to the renderer
261 bool mResourcesReady; ///< Set during the Update algorithm; true if the attachment has resources ready for the current frame.
262 bool mFinishedResourceAcquisition; ///< Set during DoPrepareResources; true if ready & all resource acquisition has finished (successfully or otherwise)
265 int mDepthIndex; ///< Used only in PrepareRenderInstructions
270 inline void SetMaterialMessage( EventThreadServices& eventThreadServices, const Renderer& renderer, const Material& material )
272 typedef MessageDoubleBuffered1< Renderer, Material* > LocalType;
274 // Reserve some memory inside the message queue
275 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
277 // Construct message in the message queue memory; note that delete should not be called on the return value
278 new (slot) LocalType( &renderer, &Renderer::SetMaterial, const_cast<Material*>(&material) );
281 inline void SetGeometryMessage( EventThreadServices& eventThreadServices, const Renderer& renderer, const Geometry& geometry )
283 typedef MessageDoubleBuffered1< Renderer, Geometry* > 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::SetGeometry, const_cast<Geometry*>(&geometry) );
292 inline void SetDepthIndexMessage( EventThreadServices& eventThreadServices, const Renderer& attachment, int depthIndex )
294 typedef MessageValue1< Renderer, int > 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( &attachment, &Renderer::SetDepthIndex, depthIndex );
303 inline void OnStageConnectMessage( EventThreadServices& eventThreadServices, const Renderer& renderer )
305 typedef Message< Renderer > 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( &renderer, &Renderer::OnStageConnect );
314 inline void OnStageDisconnectMessage( 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::OnStageDisconnect );
325 } // namespace SceneGraph
326 } // namespace Internal
329 #endif // DALI_INTERNAL_SCENE_GRAPH_RENDERER_H