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/devel-api/rendering/renderer.h> // Dali::Renderer
23 #include <dali/internal/common/blending-options.h>
24 #include <dali/internal/event/common/event-thread-services.h>
25 #include <dali/internal/update/common/property-owner.h>
26 #include <dali/internal/update/common/uniform-map.h>
27 #include <dali/internal/update/common/scene-graph-connection-change-propagator.h>
28 #include <dali/internal/render/data-providers/render-data-provider.h>
42 class SceneController;
45 typedef Dali::Vector< Renderer* > RendererContainer;
46 typedef RendererContainer::Iterator RendererIter;
47 typedef RendererContainer::ConstIterator RendererConstIter;
52 class Renderer : public PropertyOwner,
53 public UniformMapDataProvider,
54 public UniformMap::Observer,
55 public ConnectionChangePropagator::Observer
67 * Construct a new Renderer
69 static Renderer* New();
77 * Overriden delete operator
78 * Deletes the renderer from its global memory pool
80 void operator delete( void* ptr );
83 * Set the material for the renderer
84 * @param[in] bufferIndex The current frame's buffer index
85 * @param[in] material The material this renderer will use
87 void SetMaterial( BufferIndex bufferIndex, Material* material);
90 * Get the material of this renderer
91 * @return the material this renderer uses
93 Material& GetMaterial()
99 * Set the geometry for the renderer
100 * @param[in] bufferIndex The current frame's buffer index
101 * @param[in] geometry The geometry this renderer will use
103 void SetGeometry( BufferIndex bufferIndex, Geometry* material);
106 * Get the geometry of this renderer
107 * @return the geometry this renderer uses
109 Geometry& GetGeometry()
115 * Set the depth index
116 * @param[in] depthIndex the new depth index to use
118 void SetDepthIndex( int depthIndex );
121 * @brief Get the depth index
122 * @return The depth index
124 int GetDepthIndex() const
130 * Set the face culling mode
131 * @param[in] faceCullingMode to use
133 void SetFaceCullingMode( unsigned int faceCullingMode );
136 * Set the blending mode
137 * @param[in] blendingMode to use
139 void SetBlendingMode( unsigned int blendingMode );
142 * Set the blending options. This should only be called from the update thread.
143 * @param[in] options A bitmask of blending options.
145 void SetBlendingOptions( unsigned int options );
148 * Set the blend color for blending operation
149 * @param blendColor to pass to GL
151 void SetBlendColor( const Vector4& blendColor );
154 * @brief Set whether the Pre-multiplied Alpha Blending is required
156 * @param[in] preMultipled whether alpha is pre-multiplied.
158 void EnablePreMultipliedAlpha( bool preMultipled );
161 * Called when an actor with this renderer is added to the stage
163 void OnStageConnect();
166 * Called when an actor with this renderer is removed from the stage
168 void OnStageDisconnect();
171 * Prepare the object for rendering.
172 * This is called by the UpdateManager when an object is due to be rendered in the current frame.
173 * @param[in] updateBufferIndex The current update buffer index.
175 void PrepareRender( BufferIndex updateBufferIndex );
178 * Retrieve the Render thread renderer
179 * @return The associated render thread renderer
181 Render::Renderer& GetRenderer();
184 * Check whether the renderer has been marked as ready to render
185 * ready means that renderer has all resources and should produce correct result
186 * complete means all resources have finished loading
187 * It's possible that renderer is complete but not ready,
188 * for example in case of resource load failed
189 * @param[out] ready TRUE if the renderer has resources to render
190 * @param[out] complete TRUE if the renderer resources are complete
192 void GetReadyAndComplete( bool& ready, bool& complete ) const;
195 * Query whether the renderer is fully opaque, fully transparent or transparent.
196 * @param[in] updateBufferIndex The current update buffer index.
197 * @return OPAQUE if fully opaque, TRANSPARENT if fully transparent and TRANSLUCENT if in between
199 Opacity GetOpacity( BufferIndex updateBufferIndex, const Node& node ) const;
202 * Query whether the renderer is currently in use by an actor on the stage
204 bool IsReferenced() const
206 return mReferenceCount > 0;
210 public: // Implementation of ObjectOwnerContainer template methods
212 * Connect the object to the scene graph
214 * @param[in] sceneController The scene controller - used for sending messages to render thread
215 * @param[in] bufferIndex The current buffer index - used for sending messages to render thread
217 void ConnectToSceneGraph( SceneController& sceneController, BufferIndex bufferIndex );
220 * Disconnect the object from the scene graph
221 * @param[in] sceneController The scene controller - used for sending messages to render thread
222 * @param[in] bufferIndex The current buffer index - used for sending messages to render thread
224 void DisconnectFromSceneGraph( SceneController& sceneController, BufferIndex bufferIndex );
226 public: // Implementation of ConnectionChangePropagator
228 * @copydoc ConnectionChangePropagator::AddObserver
230 void AddConnectionObserver(ConnectionChangePropagator::Observer& observer){};
233 * @copydoc ConnectionChangePropagator::RemoveObserver
235 void RemoveConnectionObserver(ConnectionChangePropagator::Observer& observer){};
240 public: // UniformMap::Observer
242 * @copydoc UniformMap::Observer::UniformMappingsChanged
244 virtual void UniformMappingsChanged( const UniformMap& mappings );
246 public: // ConnectionChangePropagator::Observer
249 * @copydoc ConnectionChangePropagator::ConnectionsChanged
251 virtual void ConnectionsChanged( PropertyOwner& owner );
254 * @copydoc ConnectionChangePropagator::ConnectedUniformMapChanged
256 virtual void ConnectedUniformMapChanged( );
259 * @copydoc ConnectionChangePropagator::ConnectedUniformMapChanged
261 virtual void ObservedObjectDestroyed(PropertyOwner& owner);
263 public: // PropertyOwner implementation
265 * @copydoc Dali::Internal::SceneGraph::PropertyOwner::ResetDefaultProperties()
267 virtual void ResetDefaultProperties( BufferIndex updateBufferIndex ){};
269 public: // From UniformMapDataProvider
272 * @copydoc UniformMapDataProvider::GetUniformMapChanged
274 virtual bool GetUniformMapChanged( BufferIndex bufferIndex ) const{ return mUniformMapChanged[bufferIndex];}
277 * @copydoc UniformMapDataProvider::GetUniformMap
279 virtual const CollectedUniformMap& GetUniformMap( BufferIndex bufferIndex ) const;
284 * Protected constructor; See also Renderer::New()
289 * Helper function to create a new render data provider
290 * @return the new (initialized) data provider
292 RenderDataProvider* NewRenderDataProvider();
296 SceneController* mSceneController; ///< Used for initializing renderers whilst attached
297 Render::Renderer* mRenderer; ///< Raw pointer to the new renderer (that's owned by RenderManager)
298 Material* mMaterial; ///< The material this renderer uses. (Not owned)
299 Geometry* mGeometry; ///< The geometry this renderer uses. (Not owned)
301 Vector4* mBlendColor; ///< The blend color for blending operation
302 unsigned int mBlendBitmask; ///< The bitmask of blending options
303 Dali::Renderer::FaceCullingMode mFaceCullingMode; ///< The mode of face culling
304 BlendingMode::Type mBlendingMode; ///< The mode of blending
306 CollectedUniformMap mCollectedUniformMap[2]; ///< Uniform maps collected by the renderer
307 unsigned int mReferenceCount; ///< Number of nodes currently using this renderer
308 unsigned int mRegenerateUniformMap; ///< 2 if the map should be regenerated, 1 if it should be copied.
309 unsigned char mResendFlag; ///< Indicate whether data should be resent to the renderer
310 bool mUniformMapChanged[2]; ///< Records if the uniform map has been altered this frame
311 bool mResourcesReady; ///< Set during the Update algorithm; true if the attachment has resources ready for the current frame.
312 bool mFinishedResourceAcquisition; ///< Set during DoPrepareResources; true if ready & all resource acquisition has finished (successfully or otherwise)
313 bool mPremultipledAlphaEnabled; ///< Flag indicating whether the Pre-multiplied Alpha Blending is required
316 int mDepthIndex; ///< Used only in PrepareRenderInstructions
321 inline void SetMaterialMessage( EventThreadServices& eventThreadServices, const Renderer& renderer, const Material& material )
323 typedef MessageDoubleBuffered1< Renderer, Material* > LocalType;
325 // Reserve some memory inside the message queue
326 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
328 // Construct message in the message queue memory; note that delete should not be called on the return value
329 new (slot) LocalType( &renderer, &Renderer::SetMaterial, const_cast<Material*>(&material) );
332 inline void SetGeometryMessage( EventThreadServices& eventThreadServices, const Renderer& renderer, const Geometry& geometry )
334 typedef MessageDoubleBuffered1< Renderer, Geometry* > LocalType;
336 // Reserve some memory inside the message queue
337 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
339 // Construct message in the message queue memory; note that delete should not be called on the return value
340 new (slot) LocalType( &renderer, &Renderer::SetGeometry, const_cast<Geometry*>(&geometry) );
343 inline void SetDepthIndexMessage( EventThreadServices& eventThreadServices, const Renderer& attachment, int depthIndex )
345 typedef MessageValue1< Renderer, int > LocalType;
347 // Reserve some memory inside the message queue
348 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
350 // Construct message in the message queue memory; note that delete should not be called on the return value
351 new (slot) LocalType( &attachment, &Renderer::SetDepthIndex, depthIndex );
354 inline void SetFaceCullingModeMessage( EventThreadServices& eventThreadServices, const Renderer& renderer, Dali::Renderer::FaceCullingMode faceCullingMode )
356 typedef MessageValue1< Renderer, unsigned int > LocalType;
358 // Reserve some memory inside the message queue
359 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
361 new (slot) LocalType( &renderer, &Renderer::SetFaceCullingMode, faceCullingMode );
364 inline void SetBlendingModeMessage( EventThreadServices& eventThreadServices, const Renderer& renderer, BlendingMode::Type blendingMode )
366 typedef MessageValue1< Renderer, unsigned int > LocalType;
368 // Reserve some memory inside the message queue
369 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
371 new (slot) LocalType( &renderer, &Renderer::SetBlendingMode, blendingMode );
374 inline void SetBlendingOptionsMessage( EventThreadServices& eventThreadServices, const Renderer& renderer, unsigned int options )
376 typedef MessageValue1< Renderer, unsigned int > LocalType;
378 // Reserve some memory inside the message queue
379 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
381 new (slot) LocalType( &renderer, &Renderer::SetBlendingOptions, options );
384 inline void SetBlendColorMessage( EventThreadServices& eventThreadServices, const Renderer& renderer, const Vector4& blendColor )
386 typedef MessageValue1< Renderer, Vector4 > LocalType;
388 // Reserve some memory inside the message queue
389 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
391 new (slot) LocalType( &renderer, &Renderer::SetBlendColor, blendColor );
394 inline void SetEnablePreMultipliedAlphaMessage( EventThreadServices& eventThreadServices, const Renderer& renderer, bool preMultiplied )
396 typedef MessageValue1< Renderer, bool > LocalType;
398 // Reserve some memory inside the message queue
399 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
401 new (slot) LocalType( &renderer, &Renderer::EnablePreMultipliedAlpha, preMultiplied );
404 inline void OnStageConnectMessage( EventThreadServices& eventThreadServices, const Renderer& renderer )
406 typedef Message< Renderer > LocalType;
408 // Reserve some memory inside the message queue
409 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
411 // Construct message in the message queue memory; note that delete should not be called on the return value
412 new (slot) LocalType( &renderer, &Renderer::OnStageConnect );
415 inline void OnStageDisconnectMessage( EventThreadServices& eventThreadServices, const Renderer& renderer )
417 typedef Message< Renderer > LocalType;
419 // Reserve some memory inside the message queue
420 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
422 // Construct message in the message queue memory; note that delete should not be called on the return value
423 new (slot) LocalType( &renderer, &Renderer::OnStageDisconnect );
426 } // namespace SceneGraph
427 } // namespace Internal
430 #endif // DALI_INTERNAL_SCENE_GRAPH_RENDERER_H