Remove on/off stage behavior from Shader 25/44425/4
authorPaul Wisbey <p.wisbey@samsung.com>
Thu, 16 Jul 2015 09:28:37 +0000 (10:28 +0100)
committerPaul Wisbey <p.wisbey@samsung.com>
Tue, 28 Jul 2015 09:11:06 +0000 (02:11 -0700)
Change-Id: I2ee41d546fee1c32c017a507ea9bfac9e471822e

automated-tests/src/dali/utc-Dali-ShaderEffect.cpp
dali/internal/event/rendering/material-impl.cpp
dali/internal/event/rendering/material-impl.h
dali/internal/event/rendering/shader-impl.cpp
dali/internal/event/rendering/shader-impl.h

index 16c2921..0ce5d47 100644 (file)
@@ -539,6 +539,42 @@ int UtcDaliShaderEffectMethodApplyConstraint(void)
   END_TEST;
 }
 
+int UtcDaliShaderEffectMethodApplyConstraintOffStage(void)
+{
+  // The same test as UtcDaliShaderEffectMethodApplyConstraint,
+  // except the Actor is off-stage when the constraint is applied to the shader
+  TestApplication application;
+
+  ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
+  DALI_TEST_CHECK( effect );
+
+  BufferImage image = CreateBufferImage();
+
+  effect.SetUniform( "uVec3", Vector3( 1.0f, 2.0f, 3.0f ) );
+
+  ImageActor actor = ImageActor::New( image );
+  actor.SetSize( 100.0f, 100.0f );
+  actor.SetName("TestImageFilenameActor");
+  actor.SetShaderEffect(effect);
+  // Note - Do not add actor to stage here
+
+  Property::Index uVecProperty = effect.GetPropertyIndex("uVec3");
+
+  Constraint constraint = Constraint::New<Vector3>( effect, uVecProperty, TestConstraintToVector3(Vector3(4.0f, 9.0f, 16.0f)) );
+  constraint.Apply();
+
+  // Note - Now we add the actor (after constraint was applied to the shader)
+  Stage::GetCurrent().Add(actor);
+
+  application.SendNotification();
+  application.Render();
+
+  // Test effects of Constraint.
+  DALI_TEST_CHECK(
+      application.GetGlAbstraction().CheckUniformValue(
+          "uVec3", Vector3( 4.0f, 9.0f, 16.0f ) ) );
+  END_TEST;
+}
 
 int UtcDaliShaderEffectMethodApplyConstraintFromActor(void)
 {
index 7220438..c02df3d 100644 (file)
@@ -72,7 +72,7 @@ MaterialPtr Material::New()
 void Material::SetShader( Shader& shader )
 {
   DALI_ASSERT_DEBUG( mSceneObject )
-  mShaderConnector.Set( shader, OnStage() );
+  mShader = &shader;
 
   const SceneGraph::Shader& sceneGraphShader = dynamic_cast<const SceneGraph::Shader&>( *shader.GetSceneObject() );
   SceneGraph::SetShaderMessage( GetEventThreadServices(), *mSceneObject, sceneGraphShader );
@@ -80,7 +80,7 @@ void Material::SetShader( Shader& shader )
 
 Shader* Material::GetShader() const
 {
-  return mShaderConnector.Get().Get();
+  return mShader.Get();
 }
 
 void Material::AddSampler( Sampler& sampler )
@@ -548,7 +548,6 @@ void Material::Connect()
   {
     it->OnStageConnect();
   }
-  mShaderConnector.OnStageConnect();
 }
 
 void Material::Disconnect()
@@ -562,7 +561,6 @@ void Material::Disconnect()
   {
     it->OnStageDisconnect();
   }
-  mShaderConnector.OnStageDisconnect();
 }
 
 Material::Material()
index ec566d9..9c4f54e 100644 (file)
@@ -270,8 +270,7 @@ private: // unimplemented methods
   Material& operator=( const Material& );
 
 private: //data
-  typedef ObjectConnector<Shader> ShaderConnector;
-  ShaderConnector mShaderConnector; ///< Connector that holds the shader used by this material
+  IntrusivePtr<Shader> mShader; ///< Connector that holds the shader used by this material
 
   typedef ObjectConnector<Sampler> SamplerConnector;
   typedef std::vector< SamplerConnector > SamplerConnectorContainer;
index 1ff7b5e..ecf64cb 100644 (file)
@@ -175,17 +175,14 @@ const SceneGraph::PropertyBase* Shader::GetSceneObjectAnimatableProperty( Proper
   DALI_ASSERT_ALWAYS( IsPropertyAnimatable( index ) && "Property is not animatable" );
   const SceneGraph::PropertyBase* property = NULL;
 
-  if( OnStage() )
-  {
-    property = SHADER_IMPL.GetRegisteredSceneGraphProperty( this,
-                                                            &Shader::FindAnimatableProperty,
-                                                            &Shader::FindCustomProperty,
-                                                            index );
+  property = SHADER_IMPL.GetRegisteredSceneGraphProperty( this,
+                                                          &Shader::FindAnimatableProperty,
+                                                          &Shader::FindCustomProperty,
+                                                          index );
 
-    if( property == NULL && index < DEFAULT_PROPERTY_MAX_COUNT )
-    {
-      DALI_ASSERT_ALWAYS( 0 && "Property is not animatable" );
-    }
+  if( property == NULL && index < DEFAULT_PROPERTY_MAX_COUNT )
+  {
+    DALI_ASSERT_ALWAYS( 0 && "Property is not animatable" );
   }
 
   return property;
@@ -195,25 +192,22 @@ const PropertyInputImpl* Shader::GetSceneObjectInputProperty( Property::Index in
 {
   const PropertyInputImpl* property = NULL;
 
-  if( OnStage() )
+  const SceneGraph::PropertyBase* baseProperty =
+    SHADER_IMPL.GetRegisteredSceneGraphProperty( this,
+                                                 &Shader::FindAnimatableProperty,
+                                                 &Shader::FindCustomProperty,
+                                                 index );
+  property = static_cast<const PropertyInputImpl*>( baseProperty );
+
+  if( property == NULL && index < DEFAULT_PROPERTY_MAX_COUNT )
   {
-    const SceneGraph::PropertyBase* baseProperty =
-      SHADER_IMPL.GetRegisteredSceneGraphProperty( this,
-                                                   &Shader::FindAnimatableProperty,
-                                                   &Shader::FindCustomProperty,
-                                                   index );
-    property = static_cast<const PropertyInputImpl*>( baseProperty );
-
-    if( property == NULL && index < DEFAULT_PROPERTY_MAX_COUNT )
+    if( index == Dali::Shader::Property::SHADER_HINTS )
+    {
+      // @todo MESH_REWORK - return the property
+    }
+    else
     {
-      if( index == Dali::Shader::Property::SHADER_HINTS )
-      {
-        // @todo MESH_REWORK - return the property
-      }
-      else
-      {
-        DALI_ASSERT_ALWAYS( 0 && "Property is not a valid constraint input" );
-      }
+      DALI_ASSERT_ALWAYS( 0 && "Property is not a valid constraint input" );
     }
   }
 
@@ -225,24 +219,8 @@ int Shader::GetPropertyComponentIndex( Property::Index index ) const
   return Property::INVALID_COMPONENT_INDEX;
 }
 
-bool Shader::OnStage() const
-{
-  return mOnStage;
-}
-
-void Shader::Connect()
-{
-  mOnStage = true;
-}
-
-void Shader::Disconnect()
-{
-  mOnStage = false;
-}
-
 Shader::Shader()
-: mSceneObject( NULL ),
-  mOnStage( false )
+: mSceneObject( NULL )
 {
 }
 
index f71289d..a1b25cf 100644 (file)
@@ -22,7 +22,6 @@
 #include <dali/public-api/common/dali-common.h> // DALI_ASSERT_ALWAYS
 #include <dali/public-api/common/intrusive-ptr.h> // Dali::IntrusivePtr
 #include <dali/devel-api/rendering/shader.h> // Dali::Shader
-#include <dali/internal/event/common/connectable.h> // Dali::Internal::Connectable
 #include <dali/internal/event/common/object-connector.h> // Dali::Internal::ObjectConnector
 #include <dali/internal/event/common/object-impl.h> // Dali::Internal::Object
 #include <dali/internal/event/resources/resource-ticket.h> // Dali::Internal::ResourceTicketPtr
@@ -43,7 +42,7 @@ typedef IntrusivePtr<Shader> ShaderPtr;
  * Shader is an object that contains an array of structures of values that
  * can be accessed as properties.
  */
-class Shader : public Object, public Connectable
+class Shader : public Object
 {
 public:
 
@@ -143,22 +142,6 @@ public: // Default property extensions from Object
    */
   virtual int GetPropertyComponentIndex( Property::Index index ) const;
 
-public: // Functions from Connectable
-  /**
-   * @copydoc Dali::Internal::Connectable::OnStage()
-   */
-  virtual bool OnStage() const;
-
-  /**
-   * @copydoc Dali::Internal::Connectable::Connect()
-   */
-  virtual void Connect();
-
-  /**
-   * @copydoc Dali::Internal::Connectable::Disconnect()
-   */
-  virtual void Disconnect();
-
 private: // implementation
   Shader();
 
@@ -179,7 +162,6 @@ private: // unimplemented methods
 
 private:
   SceneGraph::Shader* mSceneObject;
-  bool mOnStage;
 };
 
 } // namespace Internal