Merge "Remove API to set if a geometry requires writing to the depth buffer" into...
[platform/core/uifw/dali-core.git] / dali / internal / update / manager / update-manager.h
index 2385265..8ccae95 100644 (file)
@@ -76,9 +76,8 @@ class RenderManager;
 class RenderTaskList;
 class RenderQueue;
 class TextureCache;
-class Geometry;
 class PropertyBuffer;
-class Material;
+class TextureSet;
 
 /**
  * UpdateManager maintains a scene graph i.e. a tree of nodes and attachments and
@@ -95,7 +94,6 @@ public:
   /**
    * Construct a new UpdateManager.
    * @param[in] notificationManager This should be notified when animations have finished.
-   * @param[in] glSyncAbstraction Used to determine when framebuffers are ready
    * @param[in] animationFinishedNotifier The CompleteNotificationInterface that handles animation completions
    * @param[in] propertyNotifier The PropertyNotifier
    * @param[in] resourceManager The resource manager used to load textures etc.
@@ -107,7 +105,6 @@ public:
    * @param[in] touchResampler Used for re-sampling touch events.
    */
   UpdateManager( NotificationManager& notificationManager,
-                 Integration::GlSyncAbstraction& glSyncAbstraction,
                  CompleteNotificationInterface& animationFinishedNotifier,
                  PropertyNotifier& propertyNotifier,
                  ResourceManager& resourceManager,
@@ -167,14 +164,6 @@ public:
   void DisconnectNode( Node* node );
 
   /**
-   * Called when a property is set on a disconnected Node (via public API)
-   * A disconnected Node has has no parent or children, and its properties cannot be animated/constrained.
-   * @pre The node does not have a parent.
-   * @param[in] node The node to set as "active".
-   */
-  void SetNodeActive( Node* node );
-
-  /**
    * Destroy a Node owned by UpdateManager.
    * This is not immediate; Nodes are passed to the RenderQueue to allow GL resources to be deleted.
    * In the following update, the previously queued Nodes may be deleted.
@@ -254,19 +243,11 @@ public:
   void PropertyNotificationSetNotify( PropertyNotification* propertyNotification, PropertyNotification::NotifyMode notifyMode );
 
   /**
-   * @brief Get the geometry owner
+   * @brief Get the renderer owner
    *
-   * @return The geometry owner
+   * @return The renderer owner
    */
-  ObjectOwnerContainer< Geometry >& GetGeometryOwner();
-
   ObjectOwnerContainer< Renderer >& GetRendererOwner();
-  /**
-   * @brief Get the material owner
-   *
-   * @return The material owner
-   */
-  ObjectOwnerContainer< Material >& GetMaterialOwner();
 
   /**
    * @brief Get the property buffer owner
@@ -294,6 +275,21 @@ public:
   void RemoveShader(Shader* shader);
 
   /**
+   * Add a newly created TextureSet.
+   * @param[in] textureSet The texture set to add.
+   * @post The TextureSet is owned by the UpdateManager.
+   */
+  void AddTextureSet(TextureSet* textureSet);
+
+  /**
+   * Remove a TextureSet.
+   * @pre The TextureSet has been added to the UpdateManager.
+   * @param[in] textureSet The TextureSet to remove.
+   * @post The TextureSet is destroyed.
+   */
+  void RemoveTextureSet(TextureSet* textureSet);
+
+  /**
    * Set the shader program for a Shader object
    * @param[in] shader        The shader to modify
    * @param[in] shaderData    Source code, hash over source, and optional compiled binary for the shader program
@@ -399,7 +395,7 @@ public:
   void SetWrapMode( Render::Sampler* sampler, unsigned int uWrapMode, unsigned int vWrapMode );
 
   /**
-   * Add a new sampler to RenderManager
+   * Add a new property buffer to RenderManager
    * @param[in] propertryBuffer The property buffer to add
    * @post Sends a message to RenderManager to add the property buffer.
    * The property buffer will be owned by RenderManager
@@ -425,17 +421,54 @@ public:
    * Sets the data of an existing property buffer
    * @param[in] propertyBuffer The property buffer.
    * @param[in] data The new data of the buffer
+   * @param[in] size The new size of the buffer
    * @post Sends a message to RenderManager to set the new data to the property buffer.
    */
-  void SetPropertyBufferData(Render::PropertyBuffer* propertyBuffer, Dali::Vector<char>* data);
+  void SetPropertyBufferData(Render::PropertyBuffer* propertyBuffer, Dali::Vector<char>* data, size_t size);
 
   /**
-   * Sets the size of an existing property buffer
-   * @param[in] propertyBuffer The property buffer.
-   * @param[in] size The new size of the buffer
-   * @post Sends a message to RenderManager to set the new size to the property buffer.
+   * Adds a geometry to the RenderManager
+   * @param[in] geometry The geometry to add
+   * @post Sends a message to RenderManager to add the Geometry
+   * The geometry will be owned by RenderManager
+   */
+  void AddGeometry( Render::Geometry* geometry );
+
+  /**
+   * Removes an existing Geometry from RenderManager
+   * @param[in] geometry The geometry to remove
+   * @post The geometry will be destroyed in the render thread
+   */
+  void RemoveGeometry( Render::Geometry* geometry );
+
+  /**
+   * Sets the geometry type of an existing Geometry
+   * @param[in] geometry The geometry
+   * @param[in] geometryType The type of the geometry
+   */
+  void SetGeometryType( Render::Geometry* geometry, unsigned int geometryType );
+
+  /**
+   * Sets the index buffer to be used by a geometry
+   * @param[in] geometry The geometry
+   * @param[in] indices A vector containing the indices for the geometry
    */
-  void SetPropertyBufferSize(Render::PropertyBuffer* propertyBuffer, size_t size );
+  void SetIndexBuffer( Render::Geometry* geometry, Dali::Vector<unsigned short>& indices );
+
+  /**
+   * Adds a vertex buffer to a geomtry
+   * @param[in] geometry The geometry
+   * @param[in] propertyBuffer The property buffer
+   */
+  void AddVertexBuffer( Render::Geometry* geometry, Render::PropertyBuffer* propertyBuffer );
+
+  /**
+   * Removes a vertex buffer from a geometry
+   * @param[in] geometry The geometry
+   * @param[in] propertyBuffer The property buffer
+   */
+  void RemoveVertexBuffer( Render::Geometry* geometry, Render::PropertyBuffer* propertyBuffer );
+
 
 public:
 
@@ -521,12 +554,22 @@ private:
   void Animate( BufferIndex bufferIndex, float elapsedSeconds );
 
   /**
-   * Perform constraint updates.
-   * @note Applies constraints to nodes first (depth first search order).
-   * Then shader constraints second (construction order)
+   * Applies constraints to CustomObjects
+   * @param[in] bufferIndex to use
+   */
+  void ConstrainCustomObjects( BufferIndex bufferIndex );
+
+  /**
+   * Applies constraints to RenderTasks
+   * @param[in] bufferIndex to use
+   */
+  void ConstrainRenderTasks( BufferIndex bufferIndex );
+
+  /**
+   * Applies constraints to Shaders
    * @param[in] bufferIndex to use
    */
-  void ApplyConstraints( BufferIndex bufferIndex );
+  void ConstrainShaders( BufferIndex bufferIndex );
 
   /**
    * Perform property notification updates
@@ -535,6 +578,11 @@ private:
   void ProcessPropertyNotifications( BufferIndex bufferIndex );
 
   /**
+   * Prepare textures for rendering
+   */
+  void PrepareTextureSets( BufferIndex bufferIndex );
+
+  /**
    * Pass shader binaries queued here on to event thread.
    */
   void ForwardCompiledShadersToEventThread();
@@ -640,7 +688,6 @@ inline void AttachToNodeMessage( UpdateManager& manager, const Node& constParent
   // Scene graph thread can modify this object.
   Node& parent = const_cast< Node& >( constParent );
 
-  // @todo MESH_REWORK Don't pass by owner pointer after merge with SceneGraph::RenderableAttachment ? (not needed if we split RendererAttachment to 2 objects)
   typedef MessageValue2< UpdateManager, Node*, NodeAttachmentOwner > LocalType;
 
   // Reserve some memory inside the message queue
@@ -884,6 +931,30 @@ inline void RemoveMessage( UpdateManager& manager, ObjectOwnerContainer<T>& owne
   new (slot) LocalType( &owner, &ObjectOwnerContainer<T>::Remove, &object );
 }
 
+// The render thread can safely change the Shader
+inline void AddTextureSetMessage( UpdateManager& manager, TextureSet& textureSet )
+{
+  typedef MessageValue1< UpdateManager, OwnerPointer< TextureSet > > LocalType;
+
+  // Reserve some memory inside the message queue
+  unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
+
+  // Construct message in the message queue memory; note that delete should not be called on the return value
+  new (slot) LocalType( &manager, &UpdateManager::AddTextureSet, &textureSet );
+}
+
+// The render thread can safely change the Shader
+inline void RemoveTextureSetMessage( UpdateManager& manager, TextureSet& textureSet )
+{
+  typedef MessageValue1< UpdateManager, TextureSet* > LocalType;
+
+  // Reserve some memory inside the message queue
+  unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
+
+  // Construct message in the message queue memory; note that delete should not be called on the return value
+  new (slot) LocalType( &manager, &UpdateManager::RemoveTextureSet, &textureSet );
+}
+
 inline void AddSamplerMessage( UpdateManager& manager, Render::Sampler& sampler )
 {
   typedef MessageValue1< UpdateManager, Render::Sampler* > LocalType;
@@ -961,28 +1032,122 @@ inline void SetPropertyBufferFormat( UpdateManager& manager, Render::PropertyBuf
   new (slot) LocalType( &manager, &UpdateManager::SetPropertyBufferFormat, &propertyBuffer, format );
 }
 
-inline void SetPropertyBufferData( UpdateManager& manager, Render::PropertyBuffer& propertyBuffer, Vector<char>* data )
+inline void SetPropertyBufferData( UpdateManager& manager, Render::PropertyBuffer& propertyBuffer, Vector<char>* data, size_t size )
+{
+  typedef MessageValue3< UpdateManager, Render::PropertyBuffer*, Vector<char>*, size_t  > LocalType;
+
+  // Reserve some memory inside the message queue
+  unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
+
+  // Construct message in the message queue memory; note that delete should not be called on the return value
+  new (slot) LocalType( &manager, &UpdateManager::SetPropertyBufferData, &propertyBuffer, data, size );
+}
+
+inline void AddGeometry( UpdateManager& manager, Render::Geometry& geometry )
+{
+  typedef MessageValue1< UpdateManager, Render::Geometry*  > LocalType;
+
+  // Reserve some memory inside the message queue
+  unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
+
+  // Construct message in the message queue memory; note that delete should not be called on the return value
+  new (slot) LocalType( &manager, &UpdateManager::AddGeometry, &geometry );
+}
+
+inline void RemoveGeometry( UpdateManager& manager, Render::Geometry& geometry )
+{
+  typedef MessageValue1< UpdateManager, Render::Geometry*  > LocalType;
+
+  // Reserve some memory inside the message queue
+  unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
+
+  // Construct message in the message queue memory; note that delete should not be called on the return value
+  new (slot) LocalType( &manager, &UpdateManager::RemoveGeometry, &geometry );
+}
+
+inline void AddVertexBufferMessage( UpdateManager& manager, Render::Geometry& geometry, const Render::PropertyBuffer& vertexBuffer )
 {
-  typedef MessageValue2< UpdateManager, Render::PropertyBuffer*, Vector<char>*  > LocalType;
+  typedef MessageValue2< UpdateManager, Render::Geometry*, Render::PropertyBuffer* > LocalType;
 
   // Reserve some memory inside the message queue
   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
 
   // Construct message in the message queue memory; note that delete should not be called on the return value
-  new (slot) LocalType( &manager, &UpdateManager::SetPropertyBufferData, &propertyBuffer, data );
+  new (slot) LocalType( &manager, &UpdateManager::AddVertexBuffer, &geometry, const_cast<Render::PropertyBuffer*>(&vertexBuffer) );
 }
 
-inline void SetPropertyBufferSize( UpdateManager& manager, Render::PropertyBuffer& propertyBuffer, size_t size )
+inline void RemoveVertexBufferMessage( UpdateManager& manager, Render::Geometry& geometry, const Render::PropertyBuffer& vertexBuffer )
 {
-  typedef MessageValue2< UpdateManager, Render::PropertyBuffer*, size_t  > LocalType;
+  typedef MessageValue2< UpdateManager, Render::Geometry*, Render::PropertyBuffer* > LocalType;
 
   // Reserve some memory inside the message queue
   unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
 
   // Construct message in the message queue memory; note that delete should not be called on the return value
-  new (slot) LocalType( &manager, &UpdateManager::SetPropertyBufferSize, &propertyBuffer, size );
+  new (slot) LocalType( &manager, &UpdateManager::RemoveVertexBuffer, &geometry, const_cast<Render::PropertyBuffer*>(&vertexBuffer) );
 }
 
+// Custom message type for SetIndexBuffer() used to move data with Vector::Swap()
+template< typename T >
+class IndexBufferMessage : public MessageBase
+{
+public:
+
+  /**
+   * Constructor which does a Vector::Swap()
+   */
+  IndexBufferMessage( T* manager, Render::Geometry* geometry, Dali::Vector<unsigned short>& indices )
+  : MessageBase(),
+    mManager( manager ),
+    mRenderGeometry( geometry )
+  {
+    mIndices.Swap( indices );
+  }
+
+  /**
+   * Virtual destructor
+   */
+  virtual ~IndexBufferMessage()
+  {
+  }
+
+  /**
+   * @copydoc MessageBase::Process
+   */
+  virtual void Process( BufferIndex /*bufferIndex*/ )
+  {
+    DALI_ASSERT_DEBUG( mManager && "Message does not have an object" );
+    mManager->SetIndexBuffer( mRenderGeometry, mIndices );
+  }
+
+private:
+
+  T* mManager;
+  Render::Geometry* mRenderGeometry;
+  Dali::Vector<unsigned short> mIndices;
+};
+
+inline void SetIndexBufferMessage( UpdateManager& manager, Render::Geometry& geometry, Dali::Vector<unsigned short>& indices )
+{
+  typedef IndexBufferMessage< UpdateManager > LocalType;
+
+  // Reserve some memory inside the message queue
+  unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
+
+  // Construct message in the message queue memory; note that delete should not be called on the return value
+  new (slot) LocalType( &manager, &geometry, indices );
+}
+
+inline void SetGeometryTypeMessage( UpdateManager& manager, Render::Geometry& geometry, unsigned int geometryType )
+{
+  typedef MessageValue2< UpdateManager, Render::Geometry*, unsigned int > LocalType;
+
+  // Reserve some memory inside the message queue
+  unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
+
+  // Construct message in the message queue memory; note that delete should not be called on the return value
+  new (slot) LocalType( &manager, &UpdateManager::SetGeometryType, &geometry, geometryType );
+}
 
 } // namespace SceneGraph