use modern construct 'override' in the derive class.
[platform/core/uifw/dali-core.git] / dali / internal / render / shaders / scene-graph-shader.h
index 8c8bd73..12d1dd3 100644 (file)
@@ -1,8 +1,8 @@
-#ifndef __DALI_INTERNAL_SCENE_GRAPH_SHADER_H__
-#define __DALI_INTERNAL_SCENE_GRAPH_SHADER_H__
+#ifndef DALI_INTERNAL_SCENE_GRAPH_SHADER_H
+#define DALI_INTERNAL_SCENE_GRAPH_SHADER_H
 
 /*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  */
 
 // INTERNAL INCLUDES
-#include <dali/public-api/common/dali-vector.h>
-#include <dali/public-api/shader-effects/shader-effect.h>
-
 #include <dali/internal/common/shader-data.h>
-
-#include <dali/internal/common/buffer-index.h>
-#include <dali/internal/common/type-abstraction-enums.h>
-
-#include <dali/internal/event/common/event-thread-services.h>
-#include <dali/internal/event/effects/shader-declarations.h>
-
 #include <dali/internal/update/common/property-owner.h>
-
-#include <dali/internal/render/gl-resources/gl-resource-owner.h>
-#include <dali/internal/render/gl-resources/texture-declarations.h>
-#include <dali/internal/render/common/render-manager.h>
+#include <dali/internal/update/common/scene-graph-connection-change-propagator.h>
 
 
 namespace Dali
 {
-
 namespace Internal
 {
 
 class Program;
+class ProgramCache;
 
 namespace SceneGraph
 {
 
-class RenderQueue;
-class UniformMeta;
-class TextureCache;
-
+class ConnectionObserver;
+class SceneController;
 /**
- * A base class for a collection of shader programs, to apply an effect to different geometry types.
- * This class is also the default shader so its easier to override default behaviour
+ * A holder class for Program; also enables sharing of uniform properties
  */
-class Shader : public PropertyOwner
+class Shader : public PropertyOwner, public UniformMap::Observer
 {
 public:
 
   /**
    * Constructor
-   * @param hints Geometry hints
+   * @param hints Shader hints
    */
-  Shader( Dali::ShaderEffect::GeometryHints& hints );
+  Shader( Dali::Shader::Hint::Value& hints );
 
   /**
    * Virtual destructor
    */
-  virtual ~Shader();
-
-  /**
-   * Second stage initialization, called when added to the UpdateManager
-   * @param renderQueue Used to queue messages from update to render thread.
-   * @param textureCache Used to retrieve effect textures when rendering.
-   */
-  void Initialize( RenderQueue& renderQueue, TextureCache& textureCache );
+  ~Shader() override;
 
   ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-  // The following methods are called during UpdateManager::Update()
+  // The following methods are called during Update
   ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
   /**
-   * Query whether a shader geometry hint is set.
+   * Query whether a shader hint is set.
    * @pre The shader has been initialized.
-   * @param[in] hint The geometry hint to check.
-   * @return True if the given geometry hint is set.
-   */
-  bool GeometryHintEnabled( Dali::ShaderEffect::GeometryHints hint ) const
-  {
-    return mGeometryHints & hint;
-  }
-
-  /**
-   * Retrieve the set of geometry hints.
-   * @return The hints.
-   */
-  Dali::ShaderEffect::GeometryHints GetGeometryHints() const
-  {
-    return mGeometryHints;
-  }
-
-  /**
-   * Set the geometry hints.
-   * @param[in] hints The hints.
+   * @param[in] hint The hint to check.
+   * @return True if the given hint is set.
    */
-  void SetGeometryHints( Dali::ShaderEffect::GeometryHints hints )
+  bool HintEnabled( Dali::Shader::Hint::Value hint ) const
   {
-    mGeometryHints = hints;
+    return mHints & hint;
   }
 
   /**
@@ -135,103 +94,11 @@ public:
     // no default properties
   }
 
-  /**
-   * Set the ID used to access textures
-   * @pre This method is not thread-safe, and should only be called from the update-thread.
-   * @param[in] updateBufferIndex The current update buffer index.
-   * @param[in] textureId The texture ID.
-   */
-  void ForwardTextureId( BufferIndex updateBufferIndex, Integration::ResourceId textureId );
-
-  /**
-   * Gets the effect texture resource ID
-   * This is zero if there is effect texture
-   * @return the resource Id
-   */
-  Integration::ResourceId GetEffectTextureResourceId();
-
-  /**
-   * Forwards the meta data from the update thread to the render thread for actual
-   * installation. (Installation is to a std::vector, which is not thread safe)
-   * @sa InstallUniformMetaInRender
-   * @pre This method should only be called from the update thread.
-   * @param[in] updateBufferIndex The current update buffer index.
-   * @param[in] meta A pointer to a UniformMeta to be owned by the Shader.
-   */
-  void ForwardUniformMeta( BufferIndex updateBufferIndex, UniformMeta* meta );
-
-  /**
-   * Forwards coordinate type to render
-   * @sa InstallUniformMetaInRender
-   * @pre This method should only be called from the update thread.
-   * @param[in] updateBufferIndex The current update buffer index.
-   * @param[in] index of the metadata.
-   * @param[in] type the coordinate type.
-   */
-  void ForwardCoordinateType( BufferIndex updateBufferIndex, unsigned int index, Dali::ShaderEffect::UniformCoordinateType type );
-
-  /**
-   * Forwards the grid density.
-   * @pre This method is not thread-safe, and should only be called from the update thread.
-   * @param[in] updateBufferIndex The current update buffer index.
-   * @param[in] density The grid density.
-   */
-  void ForwardGridDensity( BufferIndex updateBufferIndex, float density );
-
-  /**
-   * Forwards hints.
-   * @pre This method is not thread-safe, and should only be called from the update thread.
-   * @param[in] updateBufferIndex The current update buffer index.
-   * @param[in] hint The geometry hints.
-   */
-  void ForwardHints( BufferIndex updateBufferIndex, Dali::ShaderEffect::GeometryHints hint );
-
   ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-  // The following methods are called in Render thread
+  // The following methods are called during Render
   ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
   /**
-   * Set the ID used to access textures
-   * @pre This method is not thread-safe, and should only be called from the render thread.
-   * @param[in] textureId The texture ID.
-   */
-  void SetTextureId( Integration::ResourceId textureId );
-
-  /**
-   * Get the texture id, that will be used in the next call to Shader::Apply()
-   * @return textureId The texture ID
-   */
-  Integration::ResourceId GetTextureIdToRender();
-
-  /**
-   * Sets grid density
-   * @pre This method is not thread-safe, and should only be called from the update thread.
-   * @param[in] value The grid density
-   */
-  void SetGridDensity(float value);
-
-  /**
-   * Get the grid density ID.
-   * @pre This method is not thread-safe, and should only be called from the render thread.
-   * @return The grid density.
-   */
-  float GetGridDensity();
-
-  /**
-   * Installs metadata related to a newly installed uniform property.
-   * @pre This method is not thread-safe, and should only be called from the render-thread.
-   * @param[in] meta A pointer to a UniformMeta to be owned by the Shader.
-   */
-  void InstallUniformMetaInRender( UniformMeta* meta );
-
-  /**
-   * Sets the uniform coordinate type
-   * @param index of the uniform
-   * @param type to set
-   */
-  void SetCoordinateTypeInRender( unsigned int index, Dali::ShaderEffect::UniformCoordinateType type );
-
-  /**
    * @brief Set the program for this shader.
    * @param[in] shaderData        The program's vertex/fragment source and optionally precompiled shader binary.
    * @param[in] programCache      Owner of the Programs.
@@ -248,52 +115,37 @@ public:
    */
   Program* GetProgram();
 
+public: // Implementation of ConnectionChangePropagator
+
   /**
-   * Sets the shader specific uniforms including custom uniforms
-   * @pre The shader has been initialized.
-   * @pre This method is not thread-safe, and should only be called from the render-thread.
-   * @param[in] context The context used to render.
-   * @param[in] program to use.
-   * @param[in] bufferIndex The buffer to read shader properties from.
-   * @param[in] type        the type of the object (geometry) that is being rendered.
-   * @param[in] subType     Identifier for geometry types with specialised default shaders
+   * @copydoc ConnectionChangePropagator::AddObserver
    */
-  void SetUniforms( Context& context,
-                    Program& program,
-                    BufferIndex bufferIndex );
-
-private: // Data
+  void AddConnectionObserver(ConnectionChangePropagator::Observer& observer);
 
-  Dali::ShaderEffect::GeometryHints mGeometryHints;    ///< shader geometry hints for building the geometry
-  float                          mGridDensity;      ///< grid density
+  /**
+   * @copydoc ConnectionChangePropagator::RemoveObserver
+   */
+  void RemoveConnectionObserver(ConnectionChangePropagator::Observer& observer);
 
-  Texture*                       mTexture;          ///< Raw Pointer to Texture
-  Integration::ResourceId        mRenderTextureId;  ///< Copy of the texture ID for the render thread
-  Integration::ResourceId        mUpdateTextureId;  ///< Copy of the texture ID for update thread
+public: // UniformMap::Observer
+  /**
+   * @copydoc UniformMap::Observer::UniformMappingsChanged
+   */
+  void UniformMappingsChanged( const UniformMap& mappings ) override;
 
-  Program*                       mProgram;
+private: // Data
 
-  typedef OwnerContainer< UniformMeta* > UniformMetaContainer;
-  UniformMetaContainer           mUniformMetadata;     ///< A container of owned UniformMeta values; one for each property in PropertyOwner::mDynamicProperties
+  Dali::Shader::Hint::Value     mHints;
 
-  // These members are only safe to access during UpdateManager::Update()
-  RenderQueue*                   mRenderQueue;                   ///< Used for queuing a message for the next Render
+  Program*                       mProgram;
 
-  // These members are only safe to access in render thread
-  TextureCache*                  mTextureCache; // Used for retrieving textures in the render thread
+  ConnectionChangePropagator     mConnectionObservers;
 };
 
-// Messages for Shader, to be processed in Update thread.
-void SetTextureIdMessage( EventThreadServices& eventThreadServices, const Shader& shader, Integration::ResourceId textureId );
-void SetGridDensityMessage( EventThreadServices& eventThreadServices, const Shader& shader, float density );
-void SetHintsMessage( EventThreadServices& eventThreadServices, const Shader& shader, Dali::ShaderEffect::GeometryHints hint );
-void InstallUniformMetaMessage( EventThreadServices& eventThreadServices, const Shader& shader, UniformMeta& meta );
-void SetCoordinateTypeMessage( EventThreadServices& eventThreadServices, const Shader& shader, unsigned int index, Dali::ShaderEffect::UniformCoordinateType type );
-
 } // namespace SceneGraph
 
 } // namespace Internal
 
 } // namespace Dali
 
-#endif // __DALI_INTERNAL_SCENE_GRAPH_SHADER_H__
+#endif // DALI_INTERNAL_SCENE_GRAPH_SHADER_H