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 texture set for the renderer
84 * @param[in] textureSet The texture set this renderer will use
86 void SetTextures( TextureSet* textureSet );
90 * Set the shader for the renderer
91 * @param[in] shader The shader this renderer will use
93 void SetShader( Shader* shader );
96 * Get the shader used by this renderer
97 * @return the shader this renderer uses
105 * Set the geometry for the renderer
106 * @param[in] geometry The geometry this renderer will use
108 void SetGeometry( Geometry* geometry );
111 * Get the geometry of this renderer
112 * @return the geometry this renderer uses
114 Geometry& GetGeometry()
120 * Set the depth index
121 * @param[in] depthIndex the new depth index to use
123 void SetDepthIndex( int depthIndex );
126 * @brief Get the depth index
127 * @return The depth index
129 int GetDepthIndex() const
135 * Set the face culling mode
136 * @param[in] faceCullingMode to use
138 void SetFaceCullingMode( unsigned int faceCullingMode );
141 * Set the blending mode
142 * @param[in] blendingMode to use
144 void SetBlendingMode( unsigned int blendingMode );
147 * Set the blending options. This should only be called from the update thread.
148 * @param[in] options A bitmask of blending options.
150 void SetBlendingOptions( unsigned int options );
153 * Set the blend color for blending operation
154 * @param blendColor to pass to GL
156 void SetBlendColor( const Vector4& blendColor );
159 * @brief Set whether the Pre-multiplied Alpha Blending is required
161 * @param[in] preMultipled whether alpha is pre-multiplied.
163 void EnablePreMultipliedAlpha( bool preMultipled );
166 * Called when an actor with this renderer is added to the stage
168 void OnStageConnect();
171 * Called when an actor with this renderer is removed from the stage
173 void OnStageDisconnect();
176 * Prepare the object for rendering.
177 * This is called by the UpdateManager when an object is due to be rendered in the current frame.
178 * @param[in] updateBufferIndex The current update buffer index.
180 void PrepareRender( BufferIndex updateBufferIndex );
183 * Retrieve the Render thread renderer
184 * @return The associated render thread renderer
186 Render::Renderer& GetRenderer();
189 * Check whether the renderer has been marked as ready to render
190 * ready means that renderer has all resources and should produce correct result
191 * complete means all resources have finished loading
192 * It's possible that renderer is complete but not ready,
193 * for example in case of resource load failed
194 * @param[out] ready TRUE if the renderer has resources to render
195 * @param[out] complete TRUE if the renderer resources are complete
197 void GetReadyAndComplete( bool& ready, bool& complete ) const;
200 * Query whether the renderer is fully opaque, fully transparent or transparent.
201 * @param[in] updateBufferIndex The current update buffer index.
202 * @return OPAQUE if fully opaque, TRANSPARENT if fully transparent and TRANSLUCENT if in between
204 Opacity GetOpacity( BufferIndex updateBufferIndex, const Node& node ) const;
207 * Query whether the renderer is currently in use by an actor on the stage
209 bool IsReferenced() const
211 return mReferenceCount > 0;
215 public: // Implementation of ObjectOwnerContainer template methods
217 * Connect the object to the scene graph
219 * @param[in] sceneController The scene controller - used for sending messages to render thread
220 * @param[in] bufferIndex The current buffer index - used for sending messages to render thread
222 void ConnectToSceneGraph( SceneController& sceneController, BufferIndex bufferIndex );
225 * Disconnect the object from the scene graph
226 * @param[in] sceneController The scene controller - used for sending messages to render thread
227 * @param[in] bufferIndex The current buffer index - used for sending messages to render thread
229 void DisconnectFromSceneGraph( SceneController& sceneController, BufferIndex bufferIndex );
231 public: // Implementation of ConnectionChangePropagator
233 * @copydoc ConnectionChangePropagator::AddObserver
235 void AddConnectionObserver(ConnectionChangePropagator::Observer& observer){};
238 * @copydoc ConnectionChangePropagator::RemoveObserver
240 void RemoveConnectionObserver(ConnectionChangePropagator::Observer& observer){};
245 public: // UniformMap::Observer
247 * @copydoc UniformMap::Observer::UniformMappingsChanged
249 virtual void UniformMappingsChanged( const UniformMap& mappings );
251 public: // ConnectionChangePropagator::Observer
254 * @copydoc ConnectionChangePropagator::ConnectionsChanged
256 virtual void ConnectionsChanged( PropertyOwner& owner );
259 * @copydoc ConnectionChangePropagator::ConnectedUniformMapChanged
261 virtual void ConnectedUniformMapChanged( );
264 * @copydoc ConnectionChangePropagator::ConnectedUniformMapChanged
266 virtual void ObservedObjectDestroyed(PropertyOwner& owner);
268 public: // PropertyOwner implementation
270 * @copydoc Dali::Internal::SceneGraph::PropertyOwner::ResetDefaultProperties()
272 virtual void ResetDefaultProperties( BufferIndex updateBufferIndex ){};
274 public: // From UniformMapDataProvider
277 * @copydoc UniformMapDataProvider::GetUniformMapChanged
279 virtual bool GetUniformMapChanged( BufferIndex bufferIndex ) const{ return mUniformMapChanged[bufferIndex];}
282 * @copydoc UniformMapDataProvider::GetUniformMap
284 virtual const CollectedUniformMap& GetUniformMap( BufferIndex bufferIndex ) const;
289 * Protected constructor; See also Renderer::New()
294 * Helper function to create a new render data provider
295 * @return the new (initialized) data provider
297 RenderDataProvider* NewRenderDataProvider();
301 SceneController* mSceneController; ///< Used for initializing renderers whilst attached
302 Render::Renderer* mRenderer; ///< Raw pointer to the new renderer (that's owned by RenderManager)
303 TextureSet* mTextureSet; ///< The texture set this renderer uses. (Not owned)
304 Geometry* mGeometry; ///< The geometry this renderer uses. (Not owned)
307 Vector4* mBlendColor; ///< The blend color for blending operation
308 unsigned int mBlendBitmask; ///< The bitmask of blending options
309 Dali::Renderer::FaceCullingMode mFaceCullingMode; ///< The mode of face culling
310 BlendingMode::Type mBlendingMode; ///< The mode of blending
312 CollectedUniformMap mCollectedUniformMap[2]; ///< Uniform maps collected by the renderer
313 unsigned int mReferenceCount; ///< Number of nodes currently using this renderer
314 unsigned int mRegenerateUniformMap; ///< 2 if the map should be regenerated, 1 if it should be copied.
315 unsigned char mResendFlag; ///< Indicate whether data should be resent to the renderer
316 bool mUniformMapChanged[2]; ///< Records if the uniform map has been altered this frame
317 bool mResourcesReady; ///< Set during the Update algorithm; true if the attachment has resources ready for the current frame.
318 bool mFinishedResourceAcquisition; ///< Set during DoPrepareResources; true if ready & all resource acquisition has finished (successfully or otherwise)
319 bool mPremultipledAlphaEnabled; ///< Flag indicating whether the Pre-multiplied Alpha Blending is required
322 int mDepthIndex; ///< Used only in PrepareRenderInstructions
327 inline void SetTexturesMessage( EventThreadServices& eventThreadServices, const Renderer& renderer, const TextureSet& textureSet )
329 typedef MessageValue1< Renderer, TextureSet* > LocalType;
331 // Reserve some memory inside the message queue
332 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
334 // Construct message in the message queue memory; note that delete should not be called on the return value
335 new (slot) LocalType( &renderer, &Renderer::SetTextures, const_cast<TextureSet*>(&textureSet) );
338 inline void SetGeometryMessage( EventThreadServices& eventThreadServices, const Renderer& renderer, const Geometry& geometry )
340 typedef MessageValue1< Renderer, Geometry* > 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::SetGeometry, const_cast<Geometry*>(&geometry) );
349 inline void SetShaderMessage( EventThreadServices& eventThreadServices, const Renderer& renderer, Shader& shader )
351 typedef MessageValue1< Renderer, Shader* > 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::SetShader, &shader );
360 inline void SetDepthIndexMessage( EventThreadServices& eventThreadServices, const Renderer& attachment, int depthIndex )
362 typedef MessageValue1< Renderer, int > 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( &attachment, &Renderer::SetDepthIndex, depthIndex );
371 inline void SetFaceCullingModeMessage( EventThreadServices& eventThreadServices, const Renderer& renderer, Dali::Renderer::FaceCullingMode faceCullingMode )
373 typedef MessageValue1< Renderer, unsigned int > LocalType;
375 // Reserve some memory inside the message queue
376 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
378 new (slot) LocalType( &renderer, &Renderer::SetFaceCullingMode, faceCullingMode );
381 inline void SetBlendingModeMessage( EventThreadServices& eventThreadServices, const Renderer& renderer, BlendingMode::Type blendingMode )
383 typedef MessageValue1< Renderer, unsigned int > LocalType;
385 // Reserve some memory inside the message queue
386 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
388 new (slot) LocalType( &renderer, &Renderer::SetBlendingMode, blendingMode );
391 inline void SetBlendingOptionsMessage( EventThreadServices& eventThreadServices, const Renderer& renderer, unsigned int options )
393 typedef MessageValue1< Renderer, unsigned int > LocalType;
395 // Reserve some memory inside the message queue
396 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
398 new (slot) LocalType( &renderer, &Renderer::SetBlendingOptions, options );
401 inline void SetBlendColorMessage( EventThreadServices& eventThreadServices, const Renderer& renderer, const Vector4& blendColor )
403 typedef MessageValue1< Renderer, Vector4 > LocalType;
405 // Reserve some memory inside the message queue
406 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
408 new (slot) LocalType( &renderer, &Renderer::SetBlendColor, blendColor );
411 inline void SetEnablePreMultipliedAlphaMessage( EventThreadServices& eventThreadServices, const Renderer& renderer, bool preMultiplied )
413 typedef MessageValue1< Renderer, bool > LocalType;
415 // Reserve some memory inside the message queue
416 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
418 new (slot) LocalType( &renderer, &Renderer::EnablePreMultipliedAlpha, preMultiplied );
421 inline void OnStageConnectMessage( EventThreadServices& eventThreadServices, const Renderer& renderer )
423 typedef Message< Renderer > LocalType;
425 // Reserve some memory inside the message queue
426 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
428 // Construct message in the message queue memory; note that delete should not be called on the return value
429 new (slot) LocalType( &renderer, &Renderer::OnStageConnect );
432 inline void OnStageDisconnectMessage( EventThreadServices& eventThreadServices, const Renderer& renderer )
434 typedef Message< Renderer > LocalType;
436 // Reserve some memory inside the message queue
437 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
439 // Construct message in the message queue memory; note that delete should not be called on the return value
440 new (slot) LocalType( &renderer, &Renderer::OnStageDisconnect );
443 } // namespace SceneGraph
444 } // namespace Internal
447 #endif // DALI_INTERNAL_SCENE_GRAPH_RENDERER_H