Friendly janitor cleaning up unnecessary header dependencies
[platform/core/uifw/dali-core.git] / dali / internal / event / effects / shader-effect-impl.h
index a40238b..7c5ff31 100644 (file)
@@ -1,28 +1,28 @@
 #ifndef __DALI_INTERNAL_SHADER_EFFECT_H__
 #define __DALI_INTERNAL_SHADER_EFFECT_H__
 
-//
-// Copyright (c) 2014 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Flora License, Version 1.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//     http://floralicense.org/license/
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an AS IS BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
+/*
+ * Copyright (c) 2014 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
 
 // 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/effects/shader-declarations.h>
 #include <dali/internal/event/common/proxy-object.h>
-#include <dali/internal/render/shaders/uniform-meta.h>
 #include <dali/internal/event/resources/resource-ticket.h>
 #include <dali/internal/render/shaders/shader.h>
 
@@ -33,8 +33,6 @@ namespace Dali
 namespace Internal
 {
 
-class ShaderFactory;
-
 namespace SceneGraph
 {
 class UpdateManager;
@@ -48,75 +46,20 @@ class UpdateManager;
 class ShaderEffect : public ProxyObject
 {
 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);
+  enum GeometryState
+  {
+    DOESNT_MODIFY_GEOMETRY,
+    MODIFIES_GEOMETRY
+  };
 
   /**
-   * 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
+   * 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 NewWithPrefix( const std::string& vertexShaderPrefix,
-                                        const std::string& vertexShader,
-                                        const std::string& fragmentShaderPrefix,
-                                        const std::string& fragmentShader,
-                                        GeometryType type,
-                                        Dali::ShaderEffect::GeometryHints hints );
-
-  /**
-   * 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.
-   * @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.
-   */
-  static ShaderEffectPtr New( const Property::Value& map );
+  static ShaderEffectPtr New( Dali::ShaderEffect::GeometryHints hints = Dali::ShaderEffect::HINT_NONE );
 
   /**
    * @copydoc Dali::ShaderEffect::SetEffectImage
@@ -148,27 +91,36 @@ public:
   /**
    * 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 );
+  void SetPrograms( GeometryType geometryType, const std::string& vertexSource, const std::string& fragmentSource );
 
   /**
    * Add a GeometryType specific 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
    */
-  void SetProgram( GeometryType geometryType, ShaderSubTypes subType,
-                   const std::string& vertexPrefix, const std::string& fragmentPrefix,
-                   const std::string& vertexSource, const std::string& fragmentSource );
+  void SetPrograms( GeometryType geometryType,
+                    const std::string& vertexPrefix, const std::string& fragmentPrefix,
+                    const std::string& vertexSource, const std::string& fragmentSource );
+
+  /**
+   * Send shader program to scene-graph object.
+   * @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] modifiesGeometry True if the shader modifies geometry
+   */
+  void SendProgramMessage( GeometryType geometryType, ShaderSubTypes subType,
+                           const std::string& vertexSource, const std::string& fragmentSource,
+                           bool modifiesGeometry );
 
   /**
    * Notify ShaderEffect that it's being used by an Actor.
@@ -218,6 +170,11 @@ public: // Default property extensions from ProxyObject
   virtual bool IsDefaultPropertyAnimatable( Property::Index index ) const;
 
   /**
+   * @copydoc Dali::Internal::ProxyObject::IsDefaultPropertyAConstraintInput()
+   */
+  virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const;
+
+  /**
    * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyType()
    */
   virtual Property::Type GetDefaultPropertyType( Property::Index index ) const;
@@ -257,7 +214,7 @@ protected:
   /**
    * Protected constructor.
    */
-  ShaderEffect( SceneGraph::UpdateManager& updateManager, ShaderFactory& shaderFactory, SceneGraph::Shader& sceneObject );
+  ShaderEffect( SceneGraph::UpdateManager& updateManager, Dali::ShaderEffect::GeometryHints hints );
 
   /**
    * A reference counted object may only be deleted by calling Unreference()
@@ -270,24 +227,16 @@ private:
   ShaderEffect( const ShaderEffect& );
   ShaderEffect& operator=( const ShaderEffect& rhs );
 
-  void OnImageLoaded( Dali::Image image ); ///< just a helper for image loaded callback
-
 private: // Data
 
-  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
-
+  SceneGraph::UpdateManager& mUpdateManager;///< reference to the update manager
+  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
   IntrusivePtr<Dali::ShaderEffect::Extension> mExtension;
-
-  std::vector<ResourceTicketPtr>  mTickets;             ///< Collection of shader program tickets
-
-  unsigned int  mConnectionCount;                       ///< number of on-stage ImageActors using this shader effect
+  std::vector<ResourceTicketPtr>  mTickets; ///< Collection of shader program tickets
+  unsigned int  mConnectionCount;           ///< number of on-stage ImageActors using this shader effect
+  Dali::ShaderEffect::GeometryHints  mGeometryHints; ///< shader geometry hints for building the geometry
+  Dali::Vector< UniformCoordinateType > mCoordinateTypes; ///< cached to avoid sending tons of unnecessary messages
 
   // Default properties
   typedef std::map<std::string, Property::Index> DefaultPropertyLookup;