Changed ImageActor and to use new renderers and removed ImageAttachement.
[platform/core/uifw/dali-core.git] / dali / internal / event / effects / shader-effect-impl.h
index 82acf80..2443804 100644 (file)
  */
 
 // INTERNAL INCLUDES
-#include <dali/public-api/object/ref-object.h>
+#include <dali/public-api/images/image.h>
 #include <dali/public-api/shader-effects/shader-effect.h>
+#include <dali/internal/event/actors/actor-impl.h>
 #include <dali/internal/event/effects/shader-declarations.h>
-#include <dali/internal/event/common/proxy-object.h>
-#include <dali/internal/render/shaders/uniform-meta.h>
+#include <dali/internal/event/common/object-impl.h>
 #include <dali/internal/event/resources/resource-ticket.h>
-#include <dali/internal/render/shaders/shader.h>
-
+#include <dali/internal/render/shaders/scene-graph-shader.h>
 
 namespace Dali
 {
@@ -34,90 +33,36 @@ namespace Dali
 namespace Internal
 {
 
-class ShaderFactory;
-
 namespace SceneGraph
 {
 class UpdateManager;
 }
 
 /**
- * An abstract base class for a shader effect proxy.
+ * An abstract base class for a shader effect object.
  * The corresponding scene-graph object is a collection of shader programs,
  * which can apply the same effect to different geometry types.
  */
-class ShaderEffect : public ProxyObject
+class ShaderEffect : public Object
 {
 public:
-
   typedef Dali::ShaderEffect::UniformCoordinateType UniformCoordinateType;
 
-  /**
-   * Create a new ShaderEffect with no programs
-   * @param hints GeometryHints to define the geometry of the rendered object
-   * @return A smart-pointer to a newly allocated shader effect.
-   */
-  static ShaderEffectPtr New(Dali::ShaderEffect::GeometryHints hints = Dali::ShaderEffect::HINT_NONE);
+  struct Uniform
+  {
+    std::string mName;
+    Property::Index mIndex;
+    Property::Value mValue;
+  };
 
-  /**
-   * Create a new ShaderEffect
-   * @param vertexShader code for the effect. If empty, the default version will be used
-   * @param fragmentShader code for the effect. If empty, the default version will be used
-   * @param type GeometryType
-   * @param hints GeometryHints to define the geometry of the rendered object
-   * @return A smart-pointer to a newly allocated shader effect.
-   */
-  static ShaderEffectPtr New( const std::string& vertexShader,
-                              const std::string& fragmentShader,
-                              GeometryType type,
-                              Dali::ShaderEffect::GeometryHints hints );
-  /**
-   * Create a new ShaderEffect
-   * @param vertexShaderPrefix code for the effect. It will be inserted before the default uniforms.
-   * @param vertexShader code for the effect. If empty, the default version will be used
-   * @param fragmentShaderPrefix code for the effect. It will be inserted before the default uniforms.
-   * @param fragmentShader code for the effect. If empty, the default version will be used
-   * @param type GeometryType
-   * @param hints GeometryHints to define the geometry of the rendered object
-   * @return A smart-pointer to a newly allocated shader effect.
-   */
-  static ShaderEffectPtr NewWithPrefix( const std::string& vertexShaderPrefix,
-                                        const std::string& vertexShader,
-                                        const std::string& fragmentShaderPrefix,
-                                        const std::string& fragmentShader,
-                                        GeometryType type,
-                                        Dali::ShaderEffect::GeometryHints hints );
+  typedef std::vector< Uniform > UniformArray;
 
   /**
-   * Create a new ShaderEffect.
-   * If you pass in an empty string in the following arguments, the default version will be used instead.
-   * @param imageVertexShader code for the effect.
-   * @param imageFragmentShader code for the effect.
-   * @param textVertexShader code for the effect.
-   * @param textFragmentShader code for the effect.
-   * @param texturedMeshVertexShader code for the effect.
-   * @param texturedMeshFragmentShader code for the effect.
-   * @param meshVertexShader code for the effect.
-   * @param meshFragmentShader code for the effect.
+   * Create a new ShaderEffect with no programs
    * @param hints GeometryHints to define the geometry of the rendered object
-   * @return A handle to a shader effect
-   */
-  static ShaderEffectPtr New( const std::string& imageVertexShader,
-                              const std::string& imageFragmentShader,
-                              const std::string& textVertexShader,
-                              const std::string& textFragmentShader,
-                              const std::string& texturedMeshVertexShader,
-                              const std::string& texturedMeshFragmentShader,
-                              const std::string& meshVertexShader,
-                              const std::string& meshFragmentShader,
-                              Dali::ShaderEffect::GeometryHints hints );
-
-  /**
-   * Creates object with data from the property value map
-   * @param [in] map The property value map with fields such as 'vertex-filename' '..'
-   * @return a pointer to a newly created object.
+   * @return A smart-pointer to a newly allocated shader effect.
    */
-  static ShaderEffectPtr New( const Property::Value& map );
+  static ShaderEffectPtr New( Dali::ShaderEffect::GeometryHints hints = Dali::ShaderEffect::HINT_NONE );
 
   /**
    * @copydoc Dali::ShaderEffect::SetEffectImage
@@ -132,138 +77,140 @@ public:
                    UniformCoordinateType uniformCoordinateType );
 
   /**
-   * @copydoc Dali::ShaderEffect::AttachExtension()
+   * Returns the uniforms set for the shaders
+   * 
+   * @return Returns and array of uniforms set for the shaders
    */
-  void AttachExtension( Dali::ShaderEffect::Extension *object );
+  const UniformArray& GetUniforms() {return mUniforms;}
 
   /**
-   * @copydoc Dali::ShaderEffect::GetExtension()
+   * Returns the GeometryHints used
+   * 
+   * @return Returns the GeometryHints used
    */
-  Dali::ShaderEffect::Extension& GetExtension();
-
-  /**
-   * @copydoc Dali::ShaderEffect::GetExtension() const
-   */
-  const Dali::ShaderEffect::Extension& GetExtension() const;
-
-  enum FixedVertexShader
-  {
-    FLEXIBLE,
-    FIXED,
-  };
+  Dali::ShaderEffect::GeometryHints  GetGeometryHints() const {return mGeometryHints;}
 
   /**
    * Add a GeometryType specific default program to this ShaderEffect
    * @param[in] geometryType    The GeometryType rendered by the shader program
-   * @param[in] subType         The subtype, one of ShaderSubTypes.
    * @param[in] vertexSource    The source code for the vertex shader
    * @param[in] fragmentSource  The source code for the fragment shader
    */
-  void SetProgram( GeometryType geometryType, ShaderSubTypes subType,
-                   const std::string& vertexSource, const std::string& fragmentSource,
-                   FixedVertexShader fixedVertexShader=FLEXIBLE);
+  void SetPrograms( const std::string& vertexSource, const std::string& fragmentSource );
 
   /**
-   * Add a GeometryType specific default program to this ShaderEffect.
+   * Add a default program to this ShaderEffect.
    * This overload allows the optional prefixing for both the vertex and fragment shader.
    * A useful prefix may be shader \#defines for conditional compilation.
-   * @param[in] geometryType    The GeometryType rendered by the shader program
-   * @param[in] subType         The subtype, one of ShaderSubTypes.
    * @param[in] vertexPrefix    The prefix source code for the vertex shader
    * @param[in] fragmentPrefix  The prefix source code for the fragment shader
    * @param[in] vertexSource    The source code for the vertex shader
    * @param[in] fragmentSource  The source code for the fragment shader
-   * @param[in] fixedVertexShader True if this shader doesn't change the vertices
    */
-  void SetProgram( GeometryType geometryType, ShaderSubTypes subType,
-                   const std::string& vertexPrefix, const std::string& fragmentPrefix,
-                   const std::string& vertexSource, const std::string& fragmentSource,
-                   FixedVertexShader fixedVertexShader=FLEXIBLE);
+  void SetPrograms( const std::string& vertexPrefix, const std::string& fragmentPrefix,
+                    const std::string& vertexSource, const std::string& fragmentSource );
 
   /**
-   * Notify ShaderEffect that it's being used by an Actor.
+   * @brief Notify ShaderEffect that it's being used by an Actor.
+   *
+   * @param[in] actor The Actor that is connecting to this ShaderEffect 
    */
-  void Connect();
+  void Connect( ActorPtr actor );
 
   /**
-   * Notify ShaderEffect that an Actor is no longer using it.
+   * @brief Notify ShaderEffect that an Actor is no longer using it.
+   *
+   * @param[in] actor The Actor that is disconnecting from this ShaderEffect 
    */
-  void Disconnect();
+  void Disconnect( ActorPtr actor );
 
-public: // Default property extensions from ProxyObject
+public:
 
   /**
-   * @copydoc Dali::Internal::ProxyObject::IsSceneObjectRemovable()
+   * Returns the vertex shader for this ShaderEffect
+   *
+   * @return Returns the vertex shader for this ShaderEffect
    */
-  virtual bool IsSceneObjectRemovable() const;
+  const std::string& GetVertexShader() const {return mVertexSource;}
 
   /**
-   * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyCount()
+   * Returns the fragment shader for this ShaderEffect
+   *
+   * @return Returns the fragment shader for this ShaderEffect
+   */
+  const std::string& GetFragmentShader() const {return mFragmentSource;}
+
+  /**
+   * Returns the fragment shader for this ShaderEffect
+   *
+   * @return Returns the fragment shader for this ShaderEffect
+   */
+  Dali::Image GetEffectImage() const {return mEffectImage;}
+
+public: // Default property extensions from Object
+
+  /**
+   * @copydoc Dali::Internal::Object::GetDefaultPropertyCount()
    */
   virtual unsigned int GetDefaultPropertyCount() const;
 
   /**
-   * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyIndices()
+   * @copydoc Dali::Internal::Object::GetDefaultPropertyIndices()
    */
   virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const;
 
   /**
-   * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyName()
+   * @copydoc Dali::Internal::Object::GetDefaultPropertyName()
    */
-  virtual const std::string& GetDefaultPropertyName( Property::Index index ) const;
+  virtual const char* GetDefaultPropertyName( Property::Index index ) const;
 
   /**
-   * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyIndex()
+   * @copydoc Dali::Internal::Object::GetDefaultPropertyIndex()
    */
   virtual Property::Index GetDefaultPropertyIndex( const std::string& name ) const;
 
   /**
-   * @copydoc Dali::Internal::ProxyObject::IsDefaultPropertyWritable()
+   * @copydoc Dali::Internal::Object::IsDefaultPropertyWritable()
    */
   virtual bool IsDefaultPropertyWritable( Property::Index index ) const;
 
   /**
-   * @copydoc Dali::Internal::ProxyObject::IsDefaultPropertyAnimatable()
+   * @copydoc Dali::Internal::Object::IsDefaultPropertyAnimatable()
    */
   virtual bool IsDefaultPropertyAnimatable( Property::Index index ) const;
 
   /**
-   * @copydoc Dali::Internal::ProxyObject::IsDefaultPropertyAConstraintInput()
+   * @copydoc Dali::Internal::Object::IsDefaultPropertyAConstraintInput()
    */
   virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const;
 
   /**
-   * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyType()
+   * @copydoc Dali::Internal::Object::GetDefaultPropertyType()
    */
   virtual Property::Type GetDefaultPropertyType( Property::Index index ) const;
 
   /**
-   * @copydoc Dali::Internal::ProxyObject::SetDefaultProperty()
+   * @copydoc Dali::Internal::Object::SetDefaultProperty()
    */
   virtual void SetDefaultProperty( Property::Index index, const Property::Value& propertyValue );
 
   /**
-   * @copydoc Dali::Internal::ProxyObject::GetDefaultProperty()
+   * @copydoc Dali::Internal::Object::GetDefaultProperty()
    */
   virtual Property::Value GetDefaultProperty( Property::Index index ) const;
 
   /**
-   * @copydoc Dali::Internal::ProxyObject::InstallSceneObjectProperty()
-   */
-  virtual void InstallSceneObjectProperty( SceneGraph::PropertyBase& newProperty, const std::string& name, unsigned int index );
-
-  /**
-   * @copydoc Dali::Internal::ProxyObject::GetSceneObject()
+   * @copydoc Dali::Internal::Object::GetSceneObject()
    */
   virtual const SceneGraph::PropertyOwner* GetSceneObject() const;
 
   /**
-   * @copydoc Dali::Internal::ProxyObject::GetSceneObjectAnimatableProperty()
+   * @copydoc Dali::Internal::Object::GetSceneObjectAnimatableProperty()
    */
   virtual const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty( Property::Index index ) const;
 
   /**
-   * @copydoc Dali::Internal::ProxyObject::GetSceneObjectInputProperty()
+   * @copydoc Dali::Internal::Object::GetSceneObjectInputProperty()
    */
   virtual const PropertyInputImpl* GetSceneObjectInputProperty( Property::Index index ) const;
 
@@ -271,8 +218,10 @@ protected:
 
   /**
    * Protected constructor.
+   * @param[in] eventThreadServices the interface to use for sending messages to the update thread
+   * @param[in] hints Geometry hints
    */
-  ShaderEffect( SceneGraph::UpdateManager& updateManager, ShaderFactory& shaderFactory, SceneGraph::Shader& sceneObject );
+  ShaderEffect( EventThreadServices& eventThreadServices, Dali::ShaderEffect::GeometryHints hints );
 
   /**
    * A reference counted object may only be deleted by calling Unreference()
@@ -285,69 +234,19 @@ private:
   ShaderEffect( const ShaderEffect& );
   ShaderEffect& operator=( const ShaderEffect& rhs );
 
-  /**
-   * Set the given program for all shader types set in the geometryType bitfield.
-   * @param[in] geometryType         A GeometryType bitfield
-   * @param[in] vertexShaderPrefix   The prefix source code for the vertex shader
-   * @param[in] vertexShader         The source code for the vertex shader
-   * @param[in] fragmentShaderPrefix The prefix source code for the fragment shader
-   * @param[in] fragmentShader       The source code for the fragment shader
-   */
-  void SetPrograms( GeometryType  geometryTypes,
-                    const std::string& vertexShaderPrefix,
-                    const std::string& vertexShader,
-                    const std::string& fragmentShaderPrefix,
-                    const std::string& fragmentShader );
-
-  /**
-   * Wrap the given prefix and body code around the predefined prefix source for the
-   * given geometry type. Specifying an empty string for the body code means that the
-   * predefined body code is used instead.
-   *
-   * @param[in] geometryType    The GeometryType rendered by the shader program
-   * @param[in] subType         The subtype, one of ShaderSubTypes.
-   * @param[in] vertexPrefix    The prefix source code for the vertex shader
-   * @param[in] fragmentPrefix  The prefix source code for the fragment shader
-   * @param[in] vertexSource    The source code for the vertex shader
-   * @param[in] fragmentSource  The source code for the fragment shader
-   */
-  void SetWrappedProgram( GeometryType geometryType, ShaderSubTypes subType,
-                          const std::string& vertexPrefix, const std::string& fragmentPrefix,
-                          const std::string& vertexSource, const std::string& fragmentSource );
-
-  /**
-   * Send shader program to scene-graph object.
-   * Uses the shader hints to determine whether the vertices are fixed.
-   * @param[in] geometryType    The GeometryType rendered by the shader program
-   * @param[in] subType         The subtype, one of ShaderSubTypes.
-   * @param[in] vertexSource    The source code for the vertex shader
-   * @param[in] fragmentSource  The source code for the fragment shader
-   * @param[in] fixedVertexShader True if this shader doesn't change the vertices
-   */
-  void SetProgramImpl( GeometryType geometryType, ShaderSubTypes subType,
-                       const std::string& vertexSource, const std::string& fragmentSource,
-                       FixedVertexShader fixedVertexShader );
-
 private: // Data
+  std::vector< ActorPtr > mConnectedActors;               ///< The array of actors that are currently connected to this ShaderEffect
+  UniformArray mUniforms;                                 ///< The array of uniforms set for this ShaderEffect
 
-  SceneGraph::UpdateManager& mUpdateManager;            ///< reference to the update manager
-  ShaderFactory& mShaderFactory;                        ///< reference to the shader factory
-
-  SceneGraph::Shader* mSceneObject;                     ///< pointer to the scene shader, should not be changed on this thread
-
-  Dali::Image mImage;                                   ///< Client-side handle for the effect image
-
-  CustomUniformMetaLookup mCustomMetadata;            ///< Used for accessing metadata for custom Shader properties
-
-  IntrusivePtr<Dali::ShaderEffect::Extension> mExtension;
-
-  std::vector<ResourceTicketPtr>  mTickets;             ///< Collection of shader program tickets
+  std::string mVertexSource;                              ///< The vertex shader source
+  std::string mFragmentSource;                            ///< The fragment shader source
 
-  unsigned int  mConnectionCount;                       ///< number of on-stage ImageActors using this shader effect
+  EventThreadServices& mEventThreadServices;              ///< Event thread services, for sending messages
+  SceneGraph::Shader* mSceneObject;                       ///< Pointer to the scene shader, should not be changed on this thread
 
-  // Default properties
-  typedef std::map<std::string, Property::Index> DefaultPropertyLookup;
-  static DefaultPropertyLookup* mDefaultPropertyLookup;
+  Dali::Image mEffectImage;                               ///< The Client-side handle to the effect image
+  Dali::ShaderEffect::GeometryHints  mGeometryHints;      ///< shader geometry hints for building the geometry
+  float mGridDensity;                                     ///< The grid denisty
 };
 
 } // namespace Internal