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>
43 class SceneController;
46 typedef Dali::Vector< Renderer* > RendererContainer;
47 typedef RendererContainer::Iterator RendererIter;
48 typedef RendererContainer::ConstIterator RendererConstIter;
53 class Renderer : public PropertyOwner,
54 public UniformMapDataProvider,
55 public UniformMap::Observer,
56 public ConnectionChangePropagator::Observer
68 * Construct a new Renderer
70 static Renderer* New();
78 * Overriden delete operator
79 * Deletes the renderer from its global memory pool
81 void operator delete( void* ptr );
84 * Set the texture set for the renderer
85 * @param[in] textureSet The texture set this renderer will use
87 void SetTextures( TextureSet* textureSet );
91 * Set the shader for the renderer
92 * @param[in] shader The shader this renderer will use
94 void SetShader( Shader* shader );
97 * Get the shader used by this renderer
98 * @return the shader this renderer uses
106 * Set the geometry for the renderer
107 * @param[in] geometry The geometry this renderer will use
109 void SetGeometry( Render::Geometry* geometry );
112 * Set the depth index
113 * @param[in] depthIndex the new depth index to use
115 void SetDepthIndex( int depthIndex );
118 * @brief Get the depth index
119 * @return The depth index
121 int GetDepthIndex() const
127 * Set the face culling mode
128 * @param[in] faceCullingMode to use
130 void SetFaceCullingMode( unsigned int faceCullingMode );
133 * Set the blending mode
134 * @param[in] blendingMode to use
136 void SetBlendingMode( unsigned int blendingMode );
139 * Set the blending options. This should only be called from the update thread.
140 * @param[in] options A bitmask of blending options.
142 void SetBlendingOptions( unsigned int options );
145 * Set the blend color for blending operation
146 * @param blendColor to pass to GL
148 void SetBlendColor( const Vector4& blendColor );
151 * Set the index of first element for indexed draw
152 * @param[in] firstElement index of first element to draw
154 void SetIndexedDrawFirstElement( size_t firstElement );
157 * Set the number of elements to draw by indexed draw
158 * @param[in] elementsCount number of elements to draw
160 void SetIndexedDrawElementsCount( size_t elementsCount );
163 * @brief Set whether the Pre-multiplied Alpha Blending is required
165 * @param[in] preMultipled whether alpha is pre-multiplied.
167 void EnablePreMultipliedAlpha( bool preMultipled );
170 * Called when an actor with this renderer is added to the stage
172 void OnStageConnect();
175 * Called when an actor with this renderer is removed from the stage
177 void OnStageDisconnect();
180 * Prepare the object for rendering.
181 * This is called by the UpdateManager when an object is due to be rendered in the current frame.
182 * @param[in] updateBufferIndex The current update buffer index.
184 void PrepareRender( BufferIndex updateBufferIndex );
187 * Retrieve the Render thread renderer
188 * @return The associated render thread renderer
190 Render::Renderer& GetRenderer();
193 * Check whether the renderer has been marked as ready to render
194 * ready means that renderer has all resources and should produce correct result
195 * complete means all resources have finished loading
196 * It's possible that renderer is complete but not ready,
197 * for example in case of resource load failed
198 * @param[out] ready TRUE if the renderer has resources to render
199 * @param[out] complete TRUE if the renderer resources are complete
201 void GetReadyAndComplete( bool& ready, bool& complete ) const;
204 * Query whether the renderer is fully opaque, fully transparent or transparent.
205 * @param[in] updateBufferIndex The current update buffer index.
206 * @return OPAQUE if fully opaque, TRANSPARENT if fully transparent and TRANSLUCENT if in between
208 Opacity GetOpacity( BufferIndex updateBufferIndex, const Node& node ) const;
211 * Query whether the renderer is currently in use by an actor on the stage
213 bool IsReferenced() const
215 return mReferenceCount > 0;
219 * Called by the TextureSet to notify to the renderer that it has changed
221 void TextureSetChanged();
223 public: // Implementation of ObjectOwnerContainer template methods
225 * Connect the object to the scene graph
227 * @param[in] sceneController The scene controller - used for sending messages to render thread
228 * @param[in] bufferIndex The current buffer index - used for sending messages to render thread
230 void ConnectToSceneGraph( SceneController& sceneController, BufferIndex bufferIndex );
233 * Disconnect the object from the scene graph
234 * @param[in] sceneController The scene controller - used for sending messages to render thread
235 * @param[in] bufferIndex The current buffer index - used for sending messages to render thread
237 void DisconnectFromSceneGraph( SceneController& sceneController, BufferIndex bufferIndex );
239 public: // Implementation of ConnectionChangePropagator
241 * @copydoc ConnectionChangePropagator::AddObserver
243 void AddConnectionObserver(ConnectionChangePropagator::Observer& observer){};
246 * @copydoc ConnectionChangePropagator::RemoveObserver
248 void RemoveConnectionObserver(ConnectionChangePropagator::Observer& observer){};
253 public: // UniformMap::Observer
255 * @copydoc UniformMap::Observer::UniformMappingsChanged
257 virtual void UniformMappingsChanged( const UniformMap& mappings );
259 public: // ConnectionChangePropagator::Observer
262 * @copydoc ConnectionChangePropagator::ConnectionsChanged
264 virtual void ConnectionsChanged( PropertyOwner& owner );
267 * @copydoc ConnectionChangePropagator::ConnectedUniformMapChanged
269 virtual void ConnectedUniformMapChanged( );
272 * @copydoc ConnectionChangePropagator::ConnectedUniformMapChanged
274 virtual void ObservedObjectDestroyed(PropertyOwner& owner);
276 public: // PropertyOwner implementation
278 * @copydoc Dali::Internal::SceneGraph::PropertyOwner::ResetDefaultProperties()
280 virtual void ResetDefaultProperties( BufferIndex updateBufferIndex ){};
282 public: // From UniformMapDataProvider
285 * @copydoc UniformMapDataProvider::GetUniformMapChanged
287 virtual bool GetUniformMapChanged( BufferIndex bufferIndex ) const{ return mUniformMapChanged[bufferIndex];}
290 * @copydoc UniformMapDataProvider::GetUniformMap
292 virtual const CollectedUniformMap& GetUniformMap( BufferIndex bufferIndex ) const;
297 * Protected constructor; See also Renderer::New()
302 * Helper function to create a new render data provider
303 * @return the new (initialized) data provider
305 RenderDataProvider* NewRenderDataProvider();
309 SceneController* mSceneController; ///< Used for initializing renderers whilst attached
310 Render::Renderer* mRenderer; ///< Raw pointer to the renderer (that's owned by RenderManager)
311 TextureSet* mTextureSet; ///< The texture set this renderer uses. (Not owned)
312 Render::Geometry* mGeometry; ///< The geometry this renderer uses. (Not owned)
315 Vector4* mBlendColor; ///< The blend color for blending operation
316 unsigned int mBlendBitmask; ///< The bitmask of blending options
317 Dali::Renderer::FaceCullingMode mFaceCullingMode; ///< The mode of face culling
318 BlendingMode::Type mBlendingMode; ///< The mode of blending
320 CollectedUniformMap mCollectedUniformMap[2]; ///< Uniform maps collected by the renderer
322 size_t mIndexedDrawFirstElement; ///< first element index to be drawn using indexed draw
323 size_t mIndexedDrawElementsCount; ///< number of elements to be drawn using indexed draw
324 unsigned int mReferenceCount; ///< Number of nodes currently using this renderer
325 unsigned int mRegenerateUniformMap; ///< 2 if the map should be regenerated, 1 if it should be copied.
326 unsigned char mResendFlag; ///< Indicate whether data should be resent to the renderer
327 bool mUniformMapChanged[2]; ///< Records if the uniform map has been altered this frame
328 bool mResourcesReady; ///< Set during the Update algorithm; true if the attachment has resources ready for the current frame.
329 bool mFinishedResourceAcquisition; ///< Set during DoPrepareResources; true if ready & all resource acquisition has finished (successfully or otherwise)
330 bool mPremultipledAlphaEnabled; ///< Flag indicating whether the Pre-multiplied Alpha Blending is required
333 int mDepthIndex; ///< Used only in PrepareRenderInstructions
338 inline void SetTexturesMessage( EventThreadServices& eventThreadServices, const Renderer& renderer, const TextureSet& textureSet )
340 typedef MessageValue1< Renderer, TextureSet* > LocalType;
342 // Reserve some memory inside the message queue
343 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
345 // Construct message in the message queue memory; note that delete should not be called on the return value
346 new (slot) LocalType( &renderer, &Renderer::SetTextures, const_cast<TextureSet*>(&textureSet) );
349 inline void SetGeometryMessage( EventThreadServices& eventThreadServices, const Renderer& renderer, const Render::Geometry& geometry )
351 typedef MessageValue1< Renderer, Render::Geometry* > LocalType;
353 // Reserve some memory inside the message queue
354 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
356 // Construct message in the message queue memory; note that delete should not be called on the return value
357 new (slot) LocalType( &renderer, &Renderer::SetGeometry, const_cast<Render::Geometry*>(&geometry) );
360 inline void SetShaderMessage( EventThreadServices& eventThreadServices, const Renderer& renderer, Shader& shader )
362 typedef MessageValue1< Renderer, Shader* > LocalType;
364 // Reserve some memory inside the message queue
365 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
367 // Construct message in the message queue memory; note that delete should not be called on the return value
368 new (slot) LocalType( &renderer, &Renderer::SetShader, &shader );
371 inline void SetDepthIndexMessage( EventThreadServices& eventThreadServices, const Renderer& attachment, int depthIndex )
373 typedef MessageValue1< Renderer, int > LocalType;
375 // Reserve some memory inside the message queue
376 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
378 // Construct message in the message queue memory; note that delete should not be called on the return value
379 new (slot) LocalType( &attachment, &Renderer::SetDepthIndex, depthIndex );
382 inline void SetFaceCullingModeMessage( EventThreadServices& eventThreadServices, const Renderer& renderer, Dali::Renderer::FaceCullingMode faceCullingMode )
384 typedef MessageValue1< Renderer, unsigned int > LocalType;
386 // Reserve some memory inside the message queue
387 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
389 new (slot) LocalType( &renderer, &Renderer::SetFaceCullingMode, faceCullingMode );
392 inline void SetBlendingModeMessage( EventThreadServices& eventThreadServices, const Renderer& renderer, BlendingMode::Type blendingMode )
394 typedef MessageValue1< Renderer, unsigned int > LocalType;
396 // Reserve some memory inside the message queue
397 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
399 new (slot) LocalType( &renderer, &Renderer::SetBlendingMode, blendingMode );
402 inline void SetBlendingOptionsMessage( EventThreadServices& eventThreadServices, const Renderer& renderer, unsigned int options )
404 typedef MessageValue1< Renderer, unsigned int > LocalType;
406 // Reserve some memory inside the message queue
407 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
409 new (slot) LocalType( &renderer, &Renderer::SetBlendingOptions, options );
412 inline void SetBlendColorMessage( EventThreadServices& eventThreadServices, const Renderer& renderer, const Vector4& blendColor )
414 typedef MessageValue1< Renderer, Vector4 > LocalType;
416 // Reserve some memory inside the message queue
417 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
419 new (slot) LocalType( &renderer, &Renderer::SetBlendColor, blendColor );
422 inline void SetIndexedDrawFirstElementMessage( EventThreadServices& eventThreadServices, const Renderer& renderer, size_t firstElement )
424 typedef MessageValue1< Renderer, size_t > LocalType;
426 // Reserve some memory inside the message queue
427 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
429 new (slot) LocalType( &renderer, &Renderer::SetIndexedDrawFirstElement, firstElement );
432 inline void SetIndexedDrawElementsCountMessage( EventThreadServices& eventThreadServices, const Renderer& renderer, size_t elementsCount )
434 typedef MessageValue1< Renderer, size_t > LocalType;
436 // Reserve some memory inside the message queue
437 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
439 new (slot) LocalType( &renderer, &Renderer::SetIndexedDrawElementsCount, elementsCount );
442 inline void SetEnablePreMultipliedAlphaMessage( EventThreadServices& eventThreadServices, const Renderer& renderer, bool preMultiplied )
444 typedef MessageValue1< Renderer, bool > LocalType;
446 // Reserve some memory inside the message queue
447 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
449 new (slot) LocalType( &renderer, &Renderer::EnablePreMultipliedAlpha, preMultiplied );
452 inline void OnStageConnectMessage( EventThreadServices& eventThreadServices, const Renderer& renderer )
454 typedef Message< Renderer > LocalType;
456 // Reserve some memory inside the message queue
457 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
459 // Construct message in the message queue memory; note that delete should not be called on the return value
460 new (slot) LocalType( &renderer, &Renderer::OnStageConnect );
463 inline void OnStageDisconnectMessage( EventThreadServices& eventThreadServices, const Renderer& renderer )
465 typedef Message< Renderer > LocalType;
467 // Reserve some memory inside the message queue
468 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
470 // Construct message in the message queue memory; note that delete should not be called on the return value
471 new (slot) LocalType( &renderer, &Renderer::OnStageDisconnect );
474 } // namespace SceneGraph
475 } // namespace Internal
478 #endif // DALI_INTERNAL_SCENE_GRAPH_RENDERER_H