Revert "[3.0] Version downgrade (1.2.0 to 1.1.45)"
[platform/core/uifw/dali-core.git] / dali / internal / update / rendering / scene-graph-renderer.h
index 705049c..1a86cb9 100644 (file)
@@ -1,5 +1,5 @@
-#ifndef DALI_INTERNAL_SCENE_GRAPH_RENDERER2_H
-#define DALI_INTERNAL_SCENE_GRAPH_RENDERER2_H
+#ifndef DALI_INTERNAL_SCENE_GRAPH_RENDERER_H
+#define DALI_INTERNAL_SCENE_GRAPH_RENDERER_H
 
 /*
  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
  * limitations under the License.
  */
 
-
-#include <dali/devel-api/rendering/geometry.h>
-#include <dali/devel-api/rendering/renderer.h> // Dali::Renderer
+#include <dali/public-api/rendering/geometry.h>
+#include <dali/public-api/rendering/renderer.h> // Dali::Renderer
 #include <dali/internal/common/blending-options.h>
+#include <dali/internal/common/type-abstraction-enums.h>
 #include <dali/internal/event/common/event-thread-services.h>
 #include <dali/internal/update/common/property-owner.h>
 #include <dali/internal/update/common/uniform-map.h>
 #include <dali/internal/update/common/scene-graph-connection-change-propagator.h>
 #include <dali/internal/render/data-providers/render-data-provider.h>
+#include <dali/internal/render/renderers/render-renderer.h>
 
 namespace Dali
 {
@@ -86,6 +87,14 @@ public:
    */
   void SetTextures( TextureSet* textureSet );
 
+  /**
+   * Returns current texture set object
+   * @return Pointer to the texture set
+   */
+  const TextureSet* GetTextures() const
+  {
+    return mTextureSet;
+  }
 
   /**
    * Set the shader for the renderer
@@ -97,7 +106,7 @@ public:
    * Get the shader used by this renderer
    * @return the shader this renderer uses
    */
-  Shader& GetShader()
+  const Shader& GetShader() const
   {
     return *mShader;
   }
@@ -109,6 +118,15 @@ public:
   void SetGeometry( Render::Geometry* geometry );
 
   /**
+   * Get the geometry of this renderer
+   * @return the geometry this renderer uses
+   */
+  const Render::Geometry& GetGeometry() const
+  {
+    return *mGeometry;
+  }
+
+  /**
    * Set the depth index
    * @param[in] depthIndex the new depth index to use
    */
@@ -127,13 +145,13 @@ public:
    * Set the face culling mode
    * @param[in] faceCullingMode to use
    */
-  void SetFaceCullingMode( unsigned int faceCullingMode );
+  void SetFaceCullingMode( FaceCullingMode::Type faceCullingMode );
 
   /**
    * Set the blending mode
    * @param[in] blendingMode to use
    */
-  void SetBlendMode( unsigned int blendingMode );
+  void SetBlendMode( BlendMode::Type blendingMode );
 
   /**
    * Set the blending options. This should only be called from the update thread.
@@ -161,7 +179,6 @@ public:
 
   /**
    * @brief Set whether the Pre-multiplied Alpha Blending is required
-   *
    * @param[in] preMultipled whether alpha is pre-multiplied.
    */
   void EnablePreMultipliedAlpha( bool preMultipled );
@@ -170,17 +187,88 @@ public:
    * Sets the depth buffer write mode
    * @param[in] depthWriteMode The depth buffer write mode
    */
-  void SetDepthWriteMode( unsigned int depthWriteMode );
+  void SetDepthWriteMode( DepthWriteMode::Type depthWriteMode );
 
   /**
-   * Called when an actor with this renderer is added to the stage
+   * Sets the depth buffer test mode
+   * @param[in] depthTestMode The depth buffer test mode
    */
-  void OnStageConnect();
+  void SetDepthTestMode( DepthTestMode::Type depthTestMode );
 
-  /*
-   * Called when an actor with this renderer is removed from the stage
+  /**
+   * Sets the depth function
+   * @param[in] depthFunction The depth function
    */
-  void OnStageDisconnect();
+  void SetDepthFunction( DepthFunction::Type depthFunction );
+
+  /**
+   * Sets the stencil mode
+   * @param[in] mode The stencil function
+   */
+  void SetStencilMode( StencilMode::Type mode );
+
+  /**
+   * Sets the stencil function
+   * @param[in] stencilFunction The stencil function
+   */
+  void SetStencilFunction( StencilFunction::Type stencilFunction );
+
+  /**
+   * Sets the stencil function mask
+   * @param[in] stencilFunctionMask The stencil function mask
+   */
+  void SetStencilFunctionMask( int stencilFunctionMask );
+
+  /**
+   * Sets the stencil function reference
+   * @param[in] stencilFunctionReference The stencil function reference
+   */
+  void SetStencilFunctionReference( int stencilFunctionReference );
+
+  /**
+   * Sets the stencil mask
+   * @param[in] stencilMask The stencil mask
+   */
+  void SetStencilMask( int stencilMask );
+
+  /**
+   * Sets the stencil operation for when the stencil test fails
+   * @param[in] stencilOperationOnFail The stencil operation
+   */
+  void SetStencilOperationOnFail( StencilOperation::Type stencilOperationOnFail );
+
+  /**
+   * Sets the stencil operation for when the depth test fails
+   * @param[in] stencilOperationOnZFail The stencil operation
+   */
+  void SetStencilOperationOnZFail( StencilOperation::Type stencilOperationOnZFail );
+
+  /**
+   * Sets the stencil operation for when the depth test passes
+   * @param[in] stencilOperationOnZPass The stencil operation
+   */
+  void SetStencilOperationOnZPass( StencilOperation::Type stencilOperationOnZPass );
+
+  /**
+   * Sets whether or not to write to the color buffer
+   * @param[in] writeToColorBuffer True to write to the color buffer
+   */
+  void SetWriteToColorBuffer( bool writeToColorBuffer );
+
+  /**
+   * Turns on batching feature for the renderer
+   * @param[in] batchingEnabled if true, enables the batching mode for the renderer
+   */
+  void SetBatchingEnabled( bool batchingEnabled );
+
+  /**
+   * Tests whether batching feature is enabled for this renderer
+   * @return batching state
+   */
+  bool IsBatchingEnabled() const
+  {
+    return mBatchingEnabled;
+  }
 
   /**
    * Prepare the object for rendering.
@@ -214,14 +302,6 @@ public:
   Opacity GetOpacity( BufferIndex updateBufferIndex, const Node& node ) const;
 
   /**
-   * Query whether the renderer is currently in use by an actor on the stage
-   */
-  bool IsReferenced() const
-  {
-    return mReferenceCount > 0;
-  }
-
-  /**
    * Called by the TextureSet to notify to the renderer that it has changed
    */
   void TextureSetChanged();
@@ -312,33 +392,38 @@ private:
 
 private:
 
-  SceneController*   mSceneController; ///< Used for initializing renderers
-  Render::Renderer*  mRenderer;        ///< Raw pointer to the renderer (that's owned by RenderManager)
-  TextureSet*        mTextureSet;      ///< The texture set this renderer uses. (Not owned)
-  Render::Geometry*  mGeometry;        ///< The geometry this renderer uses. (Not owned)
-  Shader*            mShader;
-
-  Vector4*              mBlendColor;      ///< The blend color for blending operation
-  unsigned int          mBlendBitmask;    ///< The bitmask of blending options
-  FaceCullingMode::Type mFaceCullingMode; ///< The mode of face culling
-  BlendMode::Type       mBlendMode;       ///< The mode of blending
-  DepthWriteMode::Type  mDepthWriteMode;  ///< The depth write mode
-
-  CollectedUniformMap mCollectedUniformMap[2]; ///< Uniform maps collected by the renderer
-
-  size_t mIndexedDrawFirstElement;             ///< first element index to be drawn using indexed draw
-  size_t mIndexedDrawElementsCount;            ///< number of elements to be drawn using indexed draw
-  unsigned int mReferenceCount;                ///< Number of nodes currently using this renderer
-  unsigned int mRegenerateUniformMap;          ///< 2 if the map should be regenerated, 1 if it should be copied.
-  unsigned char mResendFlag;                   ///< Indicate whether data should be resent to the renderer
-  bool         mUniformMapChanged[2];          ///< Records if the uniform map has been altered this frame
-  bool         mResourcesReady;                ///< Set during the Update algorithm; true if the renderer has resources ready for the current frame.
-  bool         mFinishedResourceAcquisition;   ///< Set during DoPrepareResources; true if ready & all resource acquisition has finished (successfully or otherwise)
-  bool         mPremultipledAlphaEnabled : 1;  ///< Flag indicating whether the Pre-multiplied Alpha Blending is required
-
+  CollectedUniformMap          mCollectedUniformMap[2];           ///< Uniform maps collected by the renderer
+  SceneController*             mSceneController;                  ///< Used for initializing renderers
+  Render::Renderer*            mRenderer;                         ///< Raw pointer to the renderer (that's owned by RenderManager)
+  TextureSet*                  mTextureSet;                       ///< The texture set this renderer uses. (Not owned)
+  Render::Geometry*            mGeometry;                         ///< The geometry this renderer uses. (Not owned)
+  Shader*                      mShader;                           ///< The shader this renderer uses. (Not owned)
+  Vector4*                     mBlendColor;                       ///< The blend color for blending operation
+
+  Render::Renderer::StencilParameters mStencilParameters;         ///< Struct containing all stencil related options
+
+  size_t                       mIndexedDrawFirstElement;          ///< first element index to be drawn using indexed draw
+  size_t                       mIndexedDrawElementsCount;         ///< number of elements to be drawn using indexed draw
+  unsigned int                 mBlendBitmask;                     ///< The bitmask of blending options
+  unsigned int                 mRegenerateUniformMap;             ///< 2 if the map should be regenerated, 1 if it should be copied.
+  unsigned int                 mResendFlag;                       ///< Indicate whether data should be resent to the renderer
+
+  DepthFunction::Type          mDepthFunction:3;                  ///< Local copy of the depth function
+  FaceCullingMode::Type        mFaceCullingMode:2;                ///< Local copy of the mode of face culling
+  BlendMode::Type              mBlendMode:2;                      ///< Local copy of the mode of blending
+  DepthWriteMode::Type         mDepthWriteMode:2;                 ///< Local copy of the depth write mode
+  DepthTestMode::Type          mDepthTestMode:2;                  ///< Local copy of the depth test mode
+  bool                         mWriteToColorBuffer:1;             ///< Local copy of the write to color buffer flag
+
+  bool                         mUniformMapChanged[2];             ///< Records if the uniform map has been altered this frame
+  bool                         mResourcesReady;                   ///< Set during the Update algorithm; true if the renderer has resources ready for the current frame.
+  bool                         mFinishedResourceAcquisition;      ///< Set during DoPrepareResources; true if ready & all resource acquisition has finished (successfully or otherwise)
+  bool                         mPremultipledAlphaEnabled:1;       ///< Flag indicating whether the Pre-multiplied Alpha Blending is required
 
 public:
-  int mDepthIndex; ///< Used only in PrepareRenderInstructions
+
+  bool                         mBatchingEnabled : 1;              ///< Flag indicating whether the render supports batching
+  int                          mDepthIndex;                       ///< Used only in PrepareRenderInstructions
 };
 
 
@@ -387,9 +472,9 @@ inline void SetDepthIndexMessage( EventThreadServices& eventThreadServices, cons
   new (slot) LocalType( &renderer, &Renderer::SetDepthIndex, depthIndex );
 }
 
-inline void SetFaceCullingModeMessage( EventThreadServices& eventThreadServices, const Renderer& renderer, Dali::FaceCullingMode::Type faceCullingMode )
+inline void SetFaceCullingModeMessage( EventThreadServices& eventThreadServices, const Renderer& renderer, FaceCullingMode::Type faceCullingMode )
 {
-  typedef MessageValue1< Renderer, unsigned int > LocalType;
+  typedef MessageValue1< Renderer, FaceCullingMode::Type > LocalType;
 
   // Reserve some memory inside the message queue
   unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
@@ -399,7 +484,7 @@ inline void SetFaceCullingModeMessage( EventThreadServices& eventThreadServices,
 
 inline void SetBlendModeMessage( EventThreadServices& eventThreadServices, const Renderer& renderer, BlendMode::Type blendingMode )
 {
-  typedef MessageValue1< Renderer, unsigned int > LocalType;
+  typedef MessageValue1< Renderer, BlendMode::Type > LocalType;
 
   // Reserve some memory inside the message queue
   unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
@@ -457,9 +542,9 @@ inline void SetEnablePreMultipliedAlphaMessage( EventThreadServices& eventThread
   new (slot) LocalType( &renderer, &Renderer::EnablePreMultipliedAlpha, preMultiplied );
 }
 
-inline void SetDepthWriteModeMessage( EventThreadServices& eventThreadServices, const Renderer& renderer, Dali::DepthWriteMode::Type depthWriteMode )
+inline void SetDepthWriteModeMessage( EventThreadServices& eventThreadServices, const Renderer& renderer, DepthWriteMode::Type depthWriteMode )
 {
-  typedef MessageValue1< Renderer, unsigned int > LocalType;
+  typedef MessageValue1< Renderer, DepthWriteMode::Type > LocalType;
 
   // Reserve some memory inside the message queue
   unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
@@ -467,26 +552,124 @@ inline void SetDepthWriteModeMessage( EventThreadServices& eventThreadServices,
   new (slot) LocalType( &renderer, &Renderer::SetDepthWriteMode, depthWriteMode );
 }
 
-inline void OnStageConnectMessage( EventThreadServices& eventThreadServices, const Renderer& renderer )
+inline void SetDepthTestModeMessage( EventThreadServices& eventThreadServices, const Renderer& renderer, DepthTestMode::Type depthTestMode )
 {
-  typedef Message< Renderer > LocalType;
+  typedef MessageValue1< Renderer, DepthTestMode::Type > LocalType;
 
   // Reserve some memory inside the message queue
   unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
 
-  // Construct message in the message queue memory; note that delete should not be called on the return value
-  new (slot) LocalType( &renderer, &Renderer::OnStageConnect );
+  new (slot) LocalType( &renderer, &Renderer::SetDepthTestMode, depthTestMode );
 }
 
-inline void OnStageDisconnectMessage( EventThreadServices& eventThreadServices, const Renderer& renderer )
+inline void SetDepthFunctionMessage( EventThreadServices& eventThreadServices, const Renderer& renderer, DepthFunction::Type depthFunction )
 {
-  typedef Message< Renderer > LocalType;
+  typedef MessageValue1< Renderer, DepthFunction::Type > LocalType;
 
   // Reserve some memory inside the message queue
   unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
 
-  // Construct message in the message queue memory; note that delete should not be called on the return value
-  new (slot) LocalType( &renderer, &Renderer::OnStageDisconnect );
+  new (slot) LocalType( &renderer, &Renderer::SetDepthFunction, depthFunction );
+}
+
+inline void SetStencilModeMessage( EventThreadServices& eventThreadServices, const Renderer& renderer, StencilMode::Type mode )
+{
+  typedef MessageValue1< Renderer, StencilMode::Type > LocalType;
+
+  // Reserve some memory inside the message queue
+  unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
+
+  new (slot) LocalType( &renderer, &Renderer::SetStencilMode, mode );
+}
+
+inline void SetStencilFunctionMessage( EventThreadServices& eventThreadServices, const Renderer& renderer, StencilFunction::Type stencilFunction )
+{
+  typedef MessageValue1< Renderer, StencilFunction::Type > LocalType;
+
+  // Reserve some memory inside the message queue
+  unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
+
+  new (slot) LocalType( &renderer, &Renderer::SetStencilFunction, stencilFunction );
+}
+
+inline void SetStencilFunctionMaskMessage( EventThreadServices& eventThreadServices, const Renderer& renderer, int mask )
+{
+  typedef MessageValue1< Renderer, int > LocalType;
+
+  // Reserve some memory inside the message queue
+  unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
+
+  new (slot) LocalType( &renderer, &Renderer::SetStencilFunctionMask, mask );
+}
+
+inline void SetStencilFunctionReferenceMessage( EventThreadServices& eventThreadServices, const Renderer& renderer, int stencilFunctionReference )
+{
+  typedef MessageValue1< Renderer, int > LocalType;
+
+  // Reserve some memory inside the message queue
+  unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
+
+  new (slot) LocalType( &renderer, &Renderer::SetStencilFunctionReference, stencilFunctionReference );
+}
+
+inline void SetStencilMaskMessage( EventThreadServices& eventThreadServices, const Renderer& renderer, int stencilMask )
+{
+  typedef MessageValue1< Renderer, int > LocalType;
+
+  // Reserve some memory inside the message queue
+  unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
+
+  new (slot) LocalType( &renderer, &Renderer::SetStencilMask, stencilMask );
+}
+
+inline void SetStencilOperationOnFailMessage( EventThreadServices& eventThreadServices, const Renderer& renderer, StencilOperation::Type stencilOperation )
+{
+  typedef MessageValue1< Renderer, StencilOperation::Type > LocalType;
+
+  // Reserve some memory inside the message queue
+  unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
+
+  new (slot) LocalType( &renderer, &Renderer::SetStencilOperationOnFail, stencilOperation );
+}
+
+inline void SetStencilOperationOnZFailMessage( EventThreadServices& eventThreadServices, const Renderer& renderer, StencilOperation::Type stencilOperation )
+{
+  typedef MessageValue1< Renderer, StencilOperation::Type > LocalType;
+
+  // Reserve some memory inside the message queue
+  unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
+
+  new (slot) LocalType( &renderer, &Renderer::SetStencilOperationOnZFail, stencilOperation );
+}
+
+inline void SetStencilOperationOnZPassMessage( EventThreadServices& eventThreadServices, const Renderer& renderer, StencilOperation::Type stencilOperation )
+{
+  typedef MessageValue1< Renderer, StencilOperation::Type > LocalType;
+
+  // Reserve some memory inside the message queue
+  unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
+
+  new (slot) LocalType( &renderer, &Renderer::SetStencilOperationOnZPass, stencilOperation );
+}
+
+inline void SetWriteToColorBufferMessage( EventThreadServices& eventThreadServices, const Renderer& renderer, bool writeToColorBuffer )
+{
+  typedef MessageValue1< Renderer, bool > LocalType;
+
+  // Reserve some memory inside the message queue
+  unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
+
+  new (slot) LocalType( &renderer, &Renderer::SetWriteToColorBuffer, writeToColorBuffer );
+}
+
+inline void SetBatchingEnabledMessage( EventThreadServices& eventThreadServices, const Renderer& renderer, bool batchable )
+{
+  typedef MessageValue1< Renderer, bool > LocalType;
+
+  // Reserve some memory inside the message queue
+  unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
+
+  new (slot) LocalType( &renderer, &Renderer::SetBatchingEnabled, batchable );
 }
 
 } // namespace SceneGraph