SuperBlurView bug fix: alpha uniform gets wrong value from constraint 40/106740/2
authorXiangyin Ma <x1.ma@samsung.com>
Thu, 22 Dec 2016 15:50:47 +0000 (15:50 +0000)
committerAdeel Kazmi <adeel.kazmi@samsung.com>
Thu, 29 Dec 2016 15:21:50 +0000 (07:21 -0800)
Change-Id: I4a0168b9c942e5a9d8b5d9b751ac29b4364f62ce

dali-toolkit/internal/controls/super-blur-view/super-blur-view-impl.cpp

index 3141edc..4e74276 100644 (file)
@@ -162,20 +162,20 @@ void SuperBlurView::OnInitialize()
 
 void SuperBlurView::SetImage(Image inputImage)
 {
 
 void SuperBlurView::SetImage(Image inputImage)
 {
-  if( mTargetSize == Vector2::ZERO || mInputImage == inputImage)
+  mInputImage = inputImage;
+  if( mTargetSize == Vector2::ZERO )
   {
     return;
   }
 
   ClearBlurResource();
 
   {
     return;
   }
 
   ClearBlurResource();
 
-  mInputImage = inputImage;
   Actor self( Self() );
 
   mVisuals[0] = Toolkit::VisualFactory::Get().CreateVisual( mInputImage );
   RegisterVisual( 0, mVisuals[0] ); // Will clean up previously registered visuals for this index.
   mVisuals[0].SetDepthIndex(0);
   Actor self( Self() );
 
   mVisuals[0] = Toolkit::VisualFactory::Get().CreateVisual( mInputImage );
   RegisterVisual( 0, mVisuals[0] ); // Will clean up previously registered visuals for this index.
   mVisuals[0].SetDepthIndex(0);
-  SetShaderEffect( mVisuals[0] );
+  // custom shader is not applied on the original image.
 
   BlurImage( 0,  inputImage);
   for(unsigned int i=1; i<mBlurLevels;i++)
 
   BlurImage( 0,  inputImage);
   for(unsigned int i=1; i<mBlurLevels;i++)
@@ -264,8 +264,8 @@ void SuperBlurView::SetShaderEffect( Toolkit::Visual::Base& visual )
   std::stringstream verterShaderString;
   shaderMap[ "fragmentShader" ] = FRAGMENT_SHADER;
 
   std::stringstream verterShaderString;
   shaderMap[ "fragmentShader" ] = FRAGMENT_SHADER;
 
-  Internal::Visual::Base& rendererImpl = Toolkit::GetImplementation( visual );
-  rendererImpl.SetCustomShader( shaderMap );
+  Internal::Visual::Base& visualImpl = Toolkit::GetImplementation( visual );
+  visualImpl.SetCustomShader( shaderMap );
 }
 
 void SuperBlurView::OnSizeSet( const Vector3& targetSize )
 }
 
 void SuperBlurView::OnSizeSet( const Vector3& targetSize )
@@ -296,22 +296,29 @@ void SuperBlurView::OnSizeSet( const Vector3& targetSize )
 
 void SuperBlurView::OnStageConnection( int depth )
 {
 
 void SuperBlurView::OnStageConnection( int depth )
 {
-  // Chaining up first ensures visuals have SetOnStage called to create their renderers
-  Control::OnStageConnection( depth );
-
   if( mTargetSize == Vector2::ZERO )
   {
     return;
   }
 
   if( mTargetSize == Vector2::ZERO )
   {
     return;
   }
 
+  // Chaining up first ensures visuals have SetOnStage called to create their renderers
+  Control::OnStageConnection( depth );
+
   Actor self = Self();
   Actor self = Self();
-  for(unsigned int i=1; i<=mBlurLevels;i++)
+  for(unsigned int i=0; i<=mBlurLevels;i++)
   {
   {
+    // Note that the renderer indices are depending on the order they been added to the actor
+    // which might be different from the blur level of its texture.
+    // We can check the depth index of the renderer to know which blurred image it renders.
     Renderer renderer = self.GetRendererAt( i );
     Renderer renderer = self.GetRendererAt( i );
-    Property::Index index = renderer.RegisterProperty( ALPHA_UNIFORM_NAME, 0.f );
-    Constraint constraint = Constraint::New<float>( renderer, index, ActorOpacityConstraint(mBlurLevels, i-1) );
-    constraint.AddSource( Source( self, mBlurStrengthPropertyIndex ) );
-    constraint.Apply();
+    int depthIndex = renderer.GetProperty<int>(Renderer::Property::DEPTH_INDEX);
+    if( depthIndex > 0 )
+    {
+      Property::Index index = renderer.RegisterProperty( ALPHA_UNIFORM_NAME, 0.f );
+      Constraint constraint = Constraint::New<float>( renderer, index, ActorOpacityConstraint(mBlurLevels, depthIndex-1) );
+      constraint.AddSource( Source( self, mBlurStrengthPropertyIndex ) );
+      constraint.Apply();
+    }
   }
 }
 
   }
 }