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/update/common/scene-graph-property-buffer.h>
31 #include <dali/internal/render/data-providers/geometry-data-provider.h>
32 #include <dali/internal/render/data-providers/render-data-provider.h>
33 #include <dali/internal/render/renderers/render-new-renderer.h>
34 #include <dali/internal/update/resources/resource-manager.h>
50 typedef Dali::Vector< Renderer* > RendererContainer;
51 typedef RendererContainer::Iterator RendererIter;
52 typedef RendererContainer::ConstIterator RendererConstIter;
57 class Renderer : public PropertyOwner,
58 public UniformMapDataProvider,
59 public UniformMap::Observer,
60 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 * Prepare the object resources.
146 * This must be called by the UpdateManager before calling PrepareRender, for each frame.
147 * @param[in] updateBufferIndex The current update buffer index.
148 * @param[in] resourceManager The resource manager.
150 void PrepareResources( BufferIndex updateBufferIndex, ResourceManager& resourceManager );
153 * Check whether the renderer has been marked as ready to render
154 * @param[out] ready TRUE if the renderer has resources to render
155 * @param[out] complete TRUE if the renderer resources are complete
156 * (e.g. image has finished loading, framebuffer is ready to render, native image
157 * framebuffer has been rendered)
159 void GetReadyAndComplete(bool& ready, bool& complete) const;
162 * Query whether the renderer is fully opaque.
163 * @param[in] updateBufferIndex The current update buffer index.
164 * @return True if fully opaque.
166 bool IsFullyOpaque( 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 * Helper function to create a new render data provider
252 * @return the new (initialized) data provider
254 RenderDataProvider* NewRenderDataProvider();
256 SceneController* mSceneController; ///< Used for initializing renderers whilst attached
257 Render::NewRenderer* mRenderer; ///< Raw pointer to the new renderer (that's owned by RenderManager)
258 Material* mMaterial; ///< The material this renderer uses. (Not owned)
259 Geometry* mGeometry; ///< The geometry this renderer uses. (Not owned)
261 Dali::Vector< Integration::ResourceId > mTrackedResources; ///< Filled during PrepareResources if there are uncomplete, tracked resources.
263 CollectedUniformMap mCollectedUniformMap[2]; ///< Uniform maps collected by the renderer
264 unsigned int mReferenceCount; ///< Number of nodes currently using this renderer
265 unsigned int mRegenerateUniformMap; ///< 2 if the map should be regenerated, 1 if it should be copied.
266 bool mUniformMapChanged[2]; ///< Records if the uniform map has been altered this frame
267 bool mResendDataProviders : 1; ///< True if the data providers should be resent to the renderer
268 bool mResendGeometry : 1; ///< True if geometry should be resent to the renderer
269 bool mHasUntrackedResources : 1; ///< Set during PrepareResources, true if have tried to follow untracked resources
270 bool mFinishedResourceAcquisition : 1; ///< Set during DoPrepareResources; true if ready & all resource acquisition has finished (successfully or otherwise)
271 bool mResourcesReady : 1; ///< Set during the Update algorithm; true if the attachment has resources ready for the current frame.
274 int mDepthIndex; ///< Used only in PrepareRenderInstructions
279 inline void SetMaterialMessage( EventThreadServices& eventThreadServices, const Renderer& renderer, const Material& material )
281 typedef MessageDoubleBuffered1< Renderer, Material* > LocalType;
283 // Reserve some memory inside the message queue
284 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
286 // Construct message in the message queue memory; note that delete should not be called on the return value
287 new (slot) LocalType( &renderer, &Renderer::SetMaterial, const_cast<Material*>(&material) );
290 inline void SetGeometryMessage( EventThreadServices& eventThreadServices, const Renderer& renderer, const Geometry& geometry )
292 typedef MessageDoubleBuffered1< Renderer, Geometry* > LocalType;
294 // Reserve some memory inside the message queue
295 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
297 // Construct message in the message queue memory; note that delete should not be called on the return value
298 new (slot) LocalType( &renderer, &Renderer::SetGeometry, const_cast<Geometry*>(&geometry) );
301 inline void SetDepthIndexMessage( EventThreadServices& eventThreadServices, const Renderer& attachment, int depthIndex )
303 typedef MessageValue1< Renderer, int > LocalType;
305 // Reserve some memory inside the message queue
306 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
308 // Construct message in the message queue memory; note that delete should not be called on the return value
309 new (slot) LocalType( &attachment, &Renderer::SetDepthIndex, depthIndex );
312 inline void OnStageConnectMessage( EventThreadServices& eventThreadServices, const Renderer& renderer )
314 typedef Message< Renderer > LocalType;
316 // Reserve some memory inside the message queue
317 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
319 // Construct message in the message queue memory; note that delete should not be called on the return value
320 new (slot) LocalType( &renderer, &Renderer::OnStageConnect );
323 inline void OnStageDisconnectMessage( EventThreadServices& eventThreadServices, const Renderer& renderer )
325 typedef Message< Renderer > LocalType;
327 // Reserve some memory inside the message queue
328 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
330 // Construct message in the message queue memory; note that delete should not be called on the return value
331 new (slot) LocalType( &renderer, &Renderer::OnStageDisconnect );
334 } // namespace SceneGraph
335 } // namespace Internal
338 #endif // DALI_INTERNAL_SCENE_GRAPH_RENDERER_H