-//
-// 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) 2020 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.
+ *
+ */
// CLASS HEADER
#include "gaussian-blur-view-impl.h"
// EXTERNAL INCLUDES
#include <sstream>
#include <iomanip>
+#include <dali/public-api/animation/constraint.h>
+#include <dali/public-api/animation/constraints.h>
+#include <dali/public-api/common/stage.h>
+#include <dali/public-api/object/type-registry.h>
+#include <dali/public-api/object/type-registry-helper.h>
+#include <dali/public-api/rendering/geometry.h>
+#include <dali/public-api/rendering/property-buffer.h>
+#include <dali/public-api/rendering/renderer.h>
+#include <dali/public-api/rendering/shader.h>
+#include <dali/public-api/render-tasks/render-task-list.h>
+#include <dali/integration-api/debug.h>
+#include <dali/devel-api/actors/actor-devel.h>
// INTERNAL INCLUDES
-#include <dali-toolkit/public-api/controls/gaussian-blur-view/gaussian-blur-view.h>
-
-#include <dali/integration-api/debug.h>
+#include <dali-toolkit/public-api/visuals/visual-properties.h>
+#include <dali-toolkit/internal/controls/control/control-renderers.h>
// TODO:
// pixel format / size - set from JSON
// aspect ratio property needs to be able to be constrained also for cameras, not possible currently. Therefore changing aspect ratio of GaussianBlurView won't currently work
// default near clip value
-// mChildrenRoot Add()/Remove() overloads - better solution
// Manager object - re-use render targets if there are multiple GaussianBlurViews created
-
/////////////////////////////////////////////////////////
// IMPLEMENTATION NOTES
// 2 modes:
// 1st mode, this control has a tree of actors (use Add() to add children) that are rendered and blurred.
// mRenderChildrenTask renders children to FB mRenderTargetForRenderingChildren
-// mHorizBlurTask renders mImageActorHorizBlur Actor showing FB mRenderTargetForRenderingChildren into FB mRenderTarget2
-// mVertBlurTask renders mImageActorVertBlur Actor showing FB mRenderTarget2 into FB mRenderTarget1
-// mCompositeTask renders mImageActorComposite Actor showing FB mRenderTarget1 into FB mRenderTargetForRenderingChildren
+// mHorizBlurTask renders mHorizBlurActor Actor showing FB mRenderTargetForRenderingChildren into FB mRenderTarget2
+// mVertBlurTask renders mVertBlurActor Actor showing FB mRenderTarget2 into FB mRenderTarget1
+// mCompositeTask renders mCompositingActor Actor showing FB mRenderTarget1 into FB mRenderTargetForRenderingChildren
//
// 2nd mode, an image is blurred and rendered to a supplied target framebuffer
-// mHorizBlurTask renders mImageActorHorizBlur Actor showing mUserInputImage into FB mRenderTarget2
-// mVertBlurTask renders mImageActorVertBlur Actor showing mRenderTarget2 into FB mUserOutputRenderTarget
+// mHorizBlurTask renders mHorizBlurActor Actor showing mUserInputImage into FB mRenderTarget2
+// mVertBlurTask renders mVertBlurActor Actor showing mRenderTarget2 into FB mUserOutputRenderTarget
//
// Only this 2nd mode handles ActivateOnce
return Toolkit::GaussianBlurView::New();
}
-TypeRegistration mType( typeid(Toolkit::GaussianBlurView), typeid(Toolkit::Control), Create );
-
+DALI_TYPE_REGISTRATION_BEGIN( Toolkit::GaussianBlurView, Toolkit::Control, Create )
+DALI_TYPE_REGISTRATION_END()
const unsigned int GAUSSIAN_BLUR_VIEW_DEFAULT_NUM_SAMPLES = 5;
const float GAUSSIAN_BLUR_VIEW_DEFAULT_BLUR_BELL_CURVE_WIDTH = 1.5f;
const Pixel::Format GAUSSIAN_BLUR_VIEW_DEFAULT_RENDER_TARGET_PIXEL_FORMAT = Pixel::RGBA8888;
const float GAUSSIAN_BLUR_VIEW_DEFAULT_BLUR_STRENGTH = 1.0f; // default, fully blurred
-const std::string GAUSSIAN_BLUR_VIEW_STRENGTH_PROPERTY_NAME("GaussianBlurStrengthPropertyName");
+const char* const GAUSSIAN_BLUR_VIEW_STRENGTH_PROPERTY_NAME = "GaussianBlurStrengthPropertyName";
const float GAUSSIAN_BLUR_VIEW_DEFAULT_DOWNSAMPLE_WIDTH_SCALE = 0.5f;
const float GAUSSIAN_BLUR_VIEW_DEFAULT_DOWNSAMPLE_HEIGHT_SCALE = 0.5f;
const float ARBITRARY_FIELD_OF_VIEW = Math::PI / 4.0f;
-const char* const GAUSSIAN_BLUR_FRAGMENT_SOURCE =
- "uniform vec2 uSampleOffsets[NUM_SAMPLES];\n"
- "uniform float uSampleWeights[NUM_SAMPLES];\n"
-
- "void main()\n"
- "{\n"
- " mediump vec4 col;\n"
- " col = texture2D(sTexture, vec2(vTexCoord.x, vTexCoord.y) + uSampleOffsets[0]) * uSampleWeights[0]; \n"
- " for (int i=1; i<NUM_SAMPLES; ++i) \n"
- " { \n"
- " col += texture2D(sTexture, vec2(vTexCoord.x, vTexCoord.y) + uSampleOffsets[i]) * uSampleWeights[i]; \n"
- " } \n"
- " gl_FragColor = col;\n"
- "}\n";
+const char* const GAUSSIAN_BLUR_FRAGMENT_SOURCE = DALI_COMPOSE_SHADER(
+ varying mediump vec2 vTexCoord;\n
+ uniform sampler2D sTexture;\n
+ uniform lowp vec4 uColor;\n
+ uniform mediump vec2 uSampleOffsets[NUM_SAMPLES];\n
+ uniform mediump float uSampleWeights[NUM_SAMPLES];\n
+
+ void main()\n
+ {\n
+ mediump vec4 col = texture2D(sTexture, vTexCoord + uSampleOffsets[0]) * uSampleWeights[0];\n
+ for (int i=1; i<NUM_SAMPLES; ++i)\n
+ {\n
+ col += texture2D(sTexture, vTexCoord + uSampleOffsets[i]) * uSampleWeights[i];\n
+ }\n
+ gl_FragColor = col;\n
+ }\n
+);
} // namespace
GaussianBlurView::GaussianBlurView()
- : ControlImpl( false ) // doesn't require touch events
- , mNumSamples(GAUSSIAN_BLUR_VIEW_DEFAULT_NUM_SAMPLES)
-
- , mPixelFormat(GAUSSIAN_BLUR_VIEW_DEFAULT_RENDER_TARGET_PIXEL_FORMAT)
- , mDownsampleWidthScale(GAUSSIAN_BLUR_VIEW_DEFAULT_DOWNSAMPLE_WIDTH_SCALE)
- , mDownsampleHeightScale(GAUSSIAN_BLUR_VIEW_DEFAULT_DOWNSAMPLE_HEIGHT_SCALE)
- , mDownsampledWidth( 0.0f )
- , mDownsampledHeight( 0.0f )
- , mBlurUserImage( false )
- , mBackgroundColor( Color::BLACK )
- , mTargetSize(Vector2::ZERO)
- , mLastSize(Vector2::ZERO)
- , mChildrenRoot(Actor::New())
- , mBlurStrengthPropertyIndex(Property::INVALID_INDEX)
+: Control( ControlBehaviour( DISABLE_SIZE_NEGOTIATION | DISABLE_STYLE_CHANGE_SIGNALS ) ),
+ mNumSamples(GAUSSIAN_BLUR_VIEW_DEFAULT_NUM_SAMPLES),
+ mBlurBellCurveWidth( 0.001f ),
+ mPixelFormat(GAUSSIAN_BLUR_VIEW_DEFAULT_RENDER_TARGET_PIXEL_FORMAT),
+ mDownsampleWidthScale(GAUSSIAN_BLUR_VIEW_DEFAULT_DOWNSAMPLE_WIDTH_SCALE),
+ mDownsampleHeightScale(GAUSSIAN_BLUR_VIEW_DEFAULT_DOWNSAMPLE_HEIGHT_SCALE),
+ mDownsampledWidth( 0.0f ),
+ mDownsampledHeight( 0.0f ),
+ mBlurUserImage( false ),
+ mRenderOnce( false ),
+ mBackgroundColor( Color::BLACK ),
+ mTargetSize(Vector2::ZERO),
+ mLastSize(Vector2::ZERO),
+ mChildrenRoot(Actor::New()),
+ mInternalRoot(Actor::New()),
+ mBlurStrengthPropertyIndex(Property::INVALID_INDEX),
+ mActivated( false )
{
SetBlurBellCurveWidth(GAUSSIAN_BLUR_VIEW_DEFAULT_BLUR_BELL_CURVE_WIDTH);
}
-GaussianBlurView::GaussianBlurView( const unsigned int numSamples, const float blurBellCurveWidth, const Pixel::Format renderTargetPixelFormat,
- const float downsampleWidthScale, const float downsampleHeightScale,
+GaussianBlurView::GaussianBlurView( const unsigned int numSamples,
+ const float blurBellCurveWidth,
+ const Pixel::Format renderTargetPixelFormat,
+ const float downsampleWidthScale,
+ const float downsampleHeightScale,
bool blurUserImage)
- : ControlImpl( false ) // doesn't require touch events
- , mNumSamples(numSamples)
- , mPixelFormat(renderTargetPixelFormat)
- , mDownsampleWidthScale(downsampleWidthScale)
- , mDownsampleHeightScale(downsampleHeightScale)
- , mDownsampledWidth( 0.0f )
- , mDownsampledHeight( 0.0f )
- , mBlurUserImage( blurUserImage )
- , mBackgroundColor( Color::BLACK )
- , mTargetSize(Vector2::ZERO)
- , mLastSize(Vector2::ZERO)
- , mChildrenRoot(Actor::New())
- , mBlurStrengthPropertyIndex(Property::INVALID_INDEX)
+: Control( ControlBehaviour( DISABLE_SIZE_NEGOTIATION | DISABLE_STYLE_CHANGE_SIGNALS ) ),
+ mNumSamples(numSamples),
+ mBlurBellCurveWidth( 0.001f ),
+ mPixelFormat(renderTargetPixelFormat),
+ mDownsampleWidthScale(downsampleWidthScale),
+ mDownsampleHeightScale(downsampleHeightScale),
+ mDownsampledWidth( 0.0f ),
+ mDownsampledHeight( 0.0f ),
+ mBlurUserImage( blurUserImage ),
+ mRenderOnce( false ),
+ mBackgroundColor( Color::BLACK ),
+ mTargetSize(Vector2::ZERO),
+ mLastSize(Vector2::ZERO),
+ mChildrenRoot(Actor::New()),
+ mInternalRoot(Actor::New()),
+ mBlurStrengthPropertyIndex(Property::INVALID_INDEX),
+ mActivated( false )
{
SetBlurBellCurveWidth(blurBellCurveWidth);
}
/////////////////////////////////////////////////////////////
// for creating a subtree for all user added child actors, so that we can have them exclusive to the mRenderChildrenTask and our other actors exclusive to our other tasks
-// TODO: overloading Actor::Add()/Remove() not nice since breaks polymorphism. Need another method to pass ownership of added child actors to our internal actor root.
+// DEPRECATED: overloading Actor::Add()/Remove() not nice since breaks polymorphism. Need another method to pass ownership of added child actors to our internal actor root.
void GaussianBlurView::Add(Actor child)
{
mChildrenRoot.Add(child);
mChildrenRoot.Remove(child);
}
-void GaussianBlurView::SetUserImageAndOutputRenderTarget(Image inputImage, FrameBufferImage outputRenderTarget)
+void GaussianBlurView::SetUserImageAndOutputRenderTarget(Texture inputImage, FrameBuffer outputRenderTarget)
{
// can only do this if the GaussianBlurView object was created with this parameter set
DALI_ASSERT_ALWAYS(mBlurUserImage);
mUserInputImage = inputImage;
- mImageActorHorizBlur.SetImage( mUserInputImage );
+
+ SetRendererTexture( mHorizBlurActor.GetRendererAt(0), inputImage );
mUserOutputRenderTarget = outputRenderTarget;
}
-FrameBufferImage GaussianBlurView::GetBlurredRenderTarget() const
+FrameBuffer GaussianBlurView::GetBlurredRenderTarget() const
{
if(!mUserOutputRenderTarget)
{
// Private methods
//
-/**
- * EqualToConstraintFloat
- *
- * f(current, property) = property
- */
-struct EqualToConstraintFloat
-{
- EqualToConstraintFloat(){}
-
- float operator()(const float current, const PropertyInput& property) {return property.GetFloat();}
-};
-
void GaussianBlurView::OnInitialize()
{
// root actor to parent all user added actors, needed to allow us to set that subtree as exclusive for our child render task
- mChildrenRoot.SetParentOrigin(ParentOrigin::CENTER);
- mChildrenRoot.ApplyConstraint( Constraint::New<Vector3>( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) ); // same size as GaussianBlurView object
-
+ mChildrenRoot.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER );
+ mInternalRoot.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER );
//////////////////////////////////////////////////////
// Create shaders
- // horiz
- std::ostringstream horizFragmentShaderStringStream;
- horizFragmentShaderStringStream << "#define NUM_SAMPLES " << mNumSamples << "\n";
- horizFragmentShaderStringStream << GAUSSIAN_BLUR_FRAGMENT_SOURCE;
- mHorizBlurShader = ShaderEffect::New( "", horizFragmentShaderStringStream.str() );
- // vert
- std::ostringstream vertFragmentShaderStringStream;
- vertFragmentShaderStringStream << "#define NUM_SAMPLES " << mNumSamples << "\n";
- vertFragmentShaderStringStream << GAUSSIAN_BLUR_FRAGMENT_SOURCE;
- mVertBlurShader = ShaderEffect::New( "", vertFragmentShaderStringStream.str() );
-
+ std::ostringstream fragmentStringStream;
+ fragmentStringStream << "#define NUM_SAMPLES " << mNumSamples << "\n";
+ fragmentStringStream << GAUSSIAN_BLUR_FRAGMENT_SOURCE;
+ std::string fragmentSource(fragmentStringStream.str());
//////////////////////////////////////////////////////
// Create actors
- // Create an ImageActor for performing a horizontal blur on the texture
- mImageActorHorizBlur = ImageActor::New();
- mImageActorHorizBlur.SetParentOrigin(ParentOrigin::CENTER);
- mImageActorHorizBlur.ScaleBy( Vector3(1.0f, -1.0f, 1.0f) ); // FIXME
- mImageActorHorizBlur.SetShaderEffect( mHorizBlurShader );
+ // Create an actor for performing a horizontal blur on the texture
+ mHorizBlurActor = Actor::New();
+ mHorizBlurActor.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER );
+ Renderer renderer = CreateRenderer( BASIC_VERTEX_SOURCE, fragmentSource.c_str() );
+ mHorizBlurActor.AddRenderer( renderer );
- // Create an ImageActor for performing a vertical blur on the texture
- mImageActorVertBlur = ImageActor::New();
- mImageActorVertBlur.SetParentOrigin(ParentOrigin::CENTER);
- mImageActorVertBlur.ScaleBy( Vector3(1.0f, -1.0f, 1.0f) ); // FIXME
- mImageActorVertBlur.SetShaderEffect( mVertBlurShader );
+ // Create an actor for performing a vertical blur on the texture
+ mVertBlurActor = Actor::New();
+ mVertBlurActor.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER );
+ renderer = CreateRenderer( BASIC_VERTEX_SOURCE, fragmentSource.c_str() );
+ mVertBlurActor.AddRenderer( renderer );
// Register a property that the user can control to fade the blur in / out via the GaussianBlurView object
- mBlurStrengthPropertyIndex = Self().RegisterProperty(GAUSSIAN_BLUR_VIEW_STRENGTH_PROPERTY_NAME, GAUSSIAN_BLUR_VIEW_DEFAULT_BLUR_STRENGTH);
+ Actor self = Self();
+ mBlurStrengthPropertyIndex = self.RegisterProperty(GAUSSIAN_BLUR_VIEW_STRENGTH_PROPERTY_NAME, GAUSSIAN_BLUR_VIEW_DEFAULT_BLUR_STRENGTH);
- // Create an ImageActor for compositing the blur and the original child actors render
+ // Create an image view for compositing the blur and the original child actors render
if(!mBlurUserImage)
{
- mImageActorComposite = ImageActor::New();
- mImageActorComposite.SetParentOrigin(ParentOrigin::CENTER);
- mImageActorComposite.ApplyConstraint( Constraint::New<Vector3>( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) ); // same size as GaussianBlurView object
- mImageActorComposite.ScaleBy( Vector3(1.0f, -1.0f, 1.0f) ); // FIXME
- mImageActorComposite.SetOpacity(GAUSSIAN_BLUR_VIEW_DEFAULT_BLUR_STRENGTH); // ensure alpha is enabled for this object and set default value
-
- Constraint blurStrengthConstraint = Constraint::New<float>( Actor::COLOR_ALPHA, ParentSource(mBlurStrengthPropertyIndex), EqualToConstraintFloat());
- mImageActorComposite.ApplyConstraint(blurStrengthConstraint);
-
- // Create an ImageActor for holding final result, i.e. the blurred image. This will get rendered to screen later, via default / user render task
- mTargetActor = ImageActor::New();
- mTargetActor.SetParentOrigin(ParentOrigin::CENTER);
- mTargetActor.ApplyConstraint( Constraint::New<Vector3>( Actor::SIZE, ParentSource( Actor::SIZE ), EqualToConstraint() ) ); // same size as GaussianBlurView object
- mTargetActor.ScaleBy( Vector3(1.0f, -1.0f, 1.0f) ); // FIXME
-
+ mCompositingActor = Actor::New();
+ mCompositingActor.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER );
+ mCompositingActor.SetProperty( DevelActor::Property::OPACITY,GAUSSIAN_BLUR_VIEW_DEFAULT_BLUR_STRENGTH); // ensure alpha is enabled for this object and set default value
+ renderer = CreateRenderer( BASIC_VERTEX_SOURCE, BASIC_FRAGMENT_SOURCE );
+ mCompositingActor.AddRenderer( renderer );
+
+ Constraint blurStrengthConstraint = Constraint::New<float>( mCompositingActor, Actor::Property::COLOR_ALPHA, EqualToConstraint());
+ blurStrengthConstraint.AddSource( Source( self, mBlurStrengthPropertyIndex) );
+ blurStrengthConstraint.Apply();
+
+ // Create an image view for holding final result, i.e. the blurred image. This will get rendered to screen later, via default / user render task
+ mTargetActor = Actor::New();
+ mTargetActor.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER );
+ renderer = CreateRenderer( BASIC_VERTEX_SOURCE, BASIC_FRAGMENT_SOURCE );
+ mTargetActor.AddRenderer( renderer );
//////////////////////////////////////////////////////
// Create cameras for the renders corresponding to the view size
mRenderFullSizeCamera = CameraActor::New();
- mRenderFullSizeCamera.SetParentOrigin(ParentOrigin::CENTER);
-
+ mRenderFullSizeCamera.SetInvertYAxis( true );
+ mRenderFullSizeCamera.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER );
//////////////////////////////////////////////////////
// Connect to actor tree
- Self().Add( mImageActorComposite );
- Self().Add( mTargetActor );
- Self().Add( mRenderFullSizeCamera );
+ mInternalRoot.Add( mCompositingActor );
+ mInternalRoot.Add( mTargetActor );
+ mInternalRoot.Add( mRenderFullSizeCamera );
}
-
//////////////////////////////////////////////////////
// Create camera for the renders corresponding to the (potentially downsampled) render targets' size
mRenderDownsampledCamera = CameraActor::New();
- mRenderDownsampledCamera.SetParentOrigin(ParentOrigin::CENTER);
-
+ mRenderDownsampledCamera.SetInvertYAxis( true );
+ mRenderDownsampledCamera.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER );
//////////////////////////////////////////////////////
// Connect to actor tree
Self().Add( mChildrenRoot );
- Self().Add( mImageActorHorizBlur );
- Self().Add( mImageActorVertBlur );
- Self().Add( mRenderDownsampledCamera );
+ mInternalRoot.Add( mHorizBlurActor );
+ mInternalRoot.Add( mVertBlurActor );
+ mInternalRoot.Add( mRenderDownsampledCamera );
}
-/**
- * ZrelativeToYconstraint
- *
- * f(current, property, scale) = Vector3(current.x, current.y, property.y * scale)
- */
-struct ZrelativeToYconstraint
+void GaussianBlurView::OnSizeSet(const Vector3& targetSize)
{
- ZrelativeToYconstraint( float scale )
- : mScale( scale )
- {}
+ mTargetSize = Vector2(targetSize);
+
+ mChildrenRoot.SetSize(targetSize);
- Vector3 operator()(const Vector3& current,
- const PropertyInput& property)
+ if( !mBlurUserImage )
{
- Vector3 v;
+ mCompositingActor.SetSize(targetSize);
+ mTargetActor.SetSize(targetSize);
+
+ // Children render camera must move when GaussianBlurView object is resized. This is since we cannot change render target size - so we need to remap the child actors' rendering
+ // accordingly so they still exactly fill the render target. Note that this means the effective resolution of the child render changes as the GaussianBlurView object changes
+ // size, this is the trade off for not being able to modify render target size
+ // Change camera z position based on GaussianBlurView actor height
+ float cameraPosConstraintScale = 0.5f / tanf(ARBITRARY_FIELD_OF_VIEW * 0.5f);
+ mRenderFullSizeCamera.SetZ(mTargetSize.height * cameraPosConstraintScale);
+ }
- v.x = current.x;
- v.y = current.y;
- v.z = property.GetVector3().y * mScale;
- return v;
+ // if we have already activated the blur, need to update render target sizes now to reflect the new size of this actor
+ if(mActivated)
+ {
+ Deactivate();
+ Activate();
}
- float mScale;
-};
+ Control::OnSizeSet( targetSize );
+}
-void GaussianBlurView::OnControlSizeSet(const Vector3& targetSize)
+void GaussianBlurView::OnChildAdd( Actor& child )
{
- mTargetSize = Vector2(targetSize);
-
- // if we are already on stage, need to update render target sizes now to reflect the new size of this actor
- if(Self().OnStage())
+ if( child != mChildrenRoot && child != mInternalRoot)
{
- AllocateResources();
+ mChildrenRoot.Add( child );
}
+
+ Control::OnChildAdd( child );
+}
+
+void GaussianBlurView::OnChildRemove( Actor& child )
+{
+ mChildrenRoot.Remove( child );
+
+ Control::OnChildRemove( child );
}
void GaussianBlurView::AllocateResources()
{
- // size of render targets etc is based on the size of this actor, ignoring z
- if(mTargetSize != mLastSize)
- {
- mLastSize = mTargetSize;
+ mLastSize = mTargetSize;
+
+ // get size of downsampled render targets
+ mDownsampledWidth = mTargetSize.width * mDownsampleWidthScale;
+ mDownsampledHeight = mTargetSize.height * mDownsampleHeightScale;
+
+ // Create and place a camera for the renders corresponding to the (potentially downsampled) render targets' size
+ mRenderDownsampledCamera.SetFieldOfView(ARBITRARY_FIELD_OF_VIEW);
+ // TODO: how do we pick a reasonable value for near clip? Needs to relate to normal camera the user renders with, but we don't have a handle on it
+ mRenderDownsampledCamera.SetNearClippingPlane(1.0f);
+ mRenderDownsampledCamera.SetAspectRatio(mDownsampledWidth / mDownsampledHeight);
+ mRenderDownsampledCamera.SetType(Dali::Camera::FREE_LOOK); // camera orientation based solely on actor
- // get size of downsampled render targets
- mDownsampledWidth = mTargetSize.width * mDownsampleWidthScale;
- mDownsampledHeight = mTargetSize.height * mDownsampleHeightScale;
+ mRenderDownsampledCamera.SetPosition(0.0f, 0.0f, ((mDownsampledHeight * 0.5f) / tanf(ARBITRARY_FIELD_OF_VIEW * 0.5f)));
- // Create and place a camera for the renders corresponding to the (potentially downsampled) render targets' size
- mRenderDownsampledCamera.SetFieldOfView(ARBITRARY_FIELD_OF_VIEW);
+ // setup for normal operation
+ if(!mBlurUserImage)
+ {
+ // Create and place a camera for the children render, corresponding to its render target size
+ mRenderFullSizeCamera.SetFieldOfView(ARBITRARY_FIELD_OF_VIEW);
// TODO: how do we pick a reasonable value for near clip? Needs to relate to normal camera the user renders with, but we don't have a handle on it
- mRenderDownsampledCamera.SetNearClippingPlane(1.0f);
- mRenderDownsampledCamera.SetAspectRatio(mDownsampledWidth / mDownsampledHeight);
- mRenderDownsampledCamera.SetType(Dali::Camera::FREE_LOOK); // camera orientation based solely on actor
- // Point the camera back into the scene
- mRenderDownsampledCamera.SetRotation(Quaternion(M_PI, Vector3::YAXIS));
-
- mRenderDownsampledCamera.SetPosition(0.0f, 0.0f, ((mDownsampledHeight * 0.5f) / tanf(ARBITRARY_FIELD_OF_VIEW * 0.5f)));
-
- // setup for normal operation
- if(!mBlurUserImage)
- {
- // Create and place a camera for the children render, corresponding to its render target size
- mRenderFullSizeCamera.SetFieldOfView(ARBITRARY_FIELD_OF_VIEW);
- // TODO: how do we pick a reasonable value for near clip? Needs to relate to normal camera the user renders with, but we don't have a handle on it
- mRenderFullSizeCamera.SetNearClippingPlane(1.0f);
- mRenderFullSizeCamera.SetAspectRatio(mTargetSize.width / mTargetSize.height);
- mRenderFullSizeCamera.SetType(Dali::Camera::FREE_LOOK); // camera orientation based solely on actor
- // Point the camera back into the scene
- mRenderFullSizeCamera.SetRotation(Quaternion(M_PI, Vector3::YAXIS));
-
- float cameraPosConstraintScale = 0.5f / tanf(ARBITRARY_FIELD_OF_VIEW * 0.5f);
- mRenderFullSizeCamera.SetPosition(0.0f, 0.0f, mTargetSize.height * cameraPosConstraintScale);
-
- // Children render camera must move when GaussianBlurView object is resized. This is since we cannot change render target size - so we need to remap the child actors' rendering
- // accordingly so they still exactly fill the render target. Note that this means the effective resolution of the child render changes as the GaussianBlurView object changes
- // size, this is the trade off for not being able to modify render target size
- // Change camera z position based on GaussianBlurView actor height
- mRenderFullSizeCamera.RemoveConstraints();
- mRenderFullSizeCamera.ApplyConstraint( Constraint::New<Vector3>( Actor::POSITION, ParentSource( Actor::SIZE ), ZrelativeToYconstraint(cameraPosConstraintScale) ) );
-
- // create offscreen buffer of new size to render our child actors to
- mRenderTargetForRenderingChildren = FrameBufferImage::New( mTargetSize.width, mTargetSize.height, mPixelFormat, Dali::Image::Unused );
-
- // Set ImageActor for performing a horizontal blur on the texture
- mImageActorHorizBlur.SetImage( mRenderTargetForRenderingChildren );
-
- // Create offscreen buffer for vert blur pass
- mRenderTarget1 = FrameBufferImage::New( mDownsampledWidth, mDownsampledHeight, mPixelFormat, Dali::Image::Unused );
-
- // use the completed blur in the first buffer and composite with the original child actors render
- mImageActorComposite.SetImage( mRenderTarget1 );
-
- // set up target actor for rendering result, i.e. the blurred image
- mTargetActor.SetImage(mRenderTargetForRenderingChildren);
- }
-
- // Create offscreen buffer for horiz blur pass
- mRenderTarget2 = FrameBufferImage::New( mDownsampledWidth, mDownsampledHeight, mPixelFormat, Dali::Image::Unused );
-
- // size needs to match render target
- mImageActorHorizBlur.SetSize(mDownsampledWidth, mDownsampledHeight);
-
- // size needs to match render target
- mImageActorVertBlur.SetImage( mRenderTarget2 );
- mImageActorVertBlur.SetSize(mDownsampledWidth, mDownsampledHeight);
-
- // set gaussian blur up for new sized render targets
- SetShaderConstants();
+ mRenderFullSizeCamera.SetNearClippingPlane(1.0f);
+ mRenderFullSizeCamera.SetAspectRatio(mTargetSize.width / mTargetSize.height);
+ mRenderFullSizeCamera.SetType(Dali::Camera::FREE_LOOK); // camera orientation based solely on actor
+
+ float cameraPosConstraintScale = 0.5f / tanf(ARBITRARY_FIELD_OF_VIEW * 0.5f);
+ mRenderFullSizeCamera.SetPosition(0.0f, 0.0f, mTargetSize.height * cameraPosConstraintScale);
+
+ // create offscreen buffer of new size to render our child actors to
+ mRenderTargetForRenderingChildren = FrameBuffer::New( mTargetSize.width, mTargetSize.height, FrameBuffer::Attachment::NONE );
+ Texture texture = Texture::New( TextureType::TEXTURE_2D, mPixelFormat, unsigned(mTargetSize.width), unsigned(mTargetSize.height) );
+ mRenderTargetForRenderingChildren.AttachColorTexture( texture );
+
+ // Set actor for performing a horizontal blur
+ SetRendererTexture( mHorizBlurActor.GetRendererAt(0), mRenderTargetForRenderingChildren );
+
+ // Create offscreen buffer for vert blur pass
+ mRenderTarget1 = FrameBuffer::New( mDownsampledWidth, mDownsampledHeight, FrameBuffer::Attachment::NONE );
+ texture = Texture::New(TextureType::TEXTURE_2D, mPixelFormat, unsigned(mDownsampledWidth), unsigned(mDownsampledHeight));
+ mRenderTarget1.AttachColorTexture( texture );
+
+ // use the completed blur in the first buffer and composite with the original child actors render
+ SetRendererTexture( mCompositingActor.GetRendererAt(0), mRenderTarget1 );
+
+ // set up target actor for rendering result, i.e. the blurred image
+ SetRendererTexture( mTargetActor.GetRendererAt(0), mRenderTargetForRenderingChildren );
}
+
+ // Create offscreen buffer for horiz blur pass
+ mRenderTarget2 = FrameBuffer::New( mDownsampledWidth, mDownsampledHeight, FrameBuffer::Attachment::NONE );
+ Texture texture = Texture::New(TextureType::TEXTURE_2D, mPixelFormat, unsigned(mDownsampledWidth), unsigned(mDownsampledHeight));
+ mRenderTarget2.AttachColorTexture( texture );
+
+ // size needs to match render target
+ mHorizBlurActor.SetSize(mDownsampledWidth, mDownsampledHeight);
+
+ // size needs to match render target
+ mVertBlurActor.SetSize(mDownsampledWidth, mDownsampledHeight);
+ SetRendererTexture( mVertBlurActor.GetRendererAt(0), mRenderTarget2 );
+
+ // set gaussian blur up for new sized render targets
+ SetShaderConstants();
}
void GaussianBlurView::CreateRenderTasks()
mRenderChildrenTask.SetClearColor( mBackgroundColor );
mRenderChildrenTask.SetCameraActor(mRenderFullSizeCamera);
- mRenderChildrenTask.SetTargetFrameBuffer( mRenderTargetForRenderingChildren );
+ mRenderChildrenTask.SetFrameBuffer( mRenderTargetForRenderingChildren );
}
// perform a horizontal blur targeting the second buffer
mHorizBlurTask = taskList.CreateTask();
- mHorizBlurTask.SetSourceActor( mImageActorHorizBlur );
+ mHorizBlurTask.SetSourceActor( mHorizBlurActor );
mHorizBlurTask.SetExclusive(true);
mHorizBlurTask.SetInputEnabled( false );
mHorizBlurTask.SetClearEnabled( true );
mHorizBlurTask.SetClearColor( mBackgroundColor );
+ mHorizBlurTask.SetCameraActor(mRenderDownsampledCamera);
+ mHorizBlurTask.SetFrameBuffer( mRenderTarget2 );
if( mRenderOnce && mBlurUserImage )
{
mHorizBlurTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
// use the second buffer and perform a horizontal blur targeting the first buffer
mVertBlurTask = taskList.CreateTask();
- mVertBlurTask.SetSourceActor( mImageActorVertBlur );
+ mVertBlurTask.SetSourceActor( mVertBlurActor );
mVertBlurTask.SetExclusive(true);
mVertBlurTask.SetInputEnabled( false );
mVertBlurTask.SetClearEnabled( true );
mVertBlurTask.SetClearColor( mBackgroundColor );
+ mVertBlurTask.SetCameraActor(mRenderDownsampledCamera);
+ if(mUserOutputRenderTarget)
+ {
+ mVertBlurTask.SetFrameBuffer( mUserOutputRenderTarget );
+ }
+ else
+ {
+ mVertBlurTask.SetFrameBuffer( mRenderTarget1 );
+ }
if( mRenderOnce && mBlurUserImage )
{
mVertBlurTask.SetRefreshRate(RenderTask::REFRESH_ONCE);
if(!mBlurUserImage)
{
mCompositeTask = taskList.CreateTask();
- mCompositeTask.SetSourceActor( mImageActorComposite );
+ mCompositeTask.SetSourceActor( mCompositingActor );
mCompositeTask.SetExclusive(true);
mCompositeTask.SetInputEnabled( false );
mCompositeTask.SetCameraActor(mRenderFullSizeCamera);
- mCompositeTask.SetTargetFrameBuffer( mRenderTargetForRenderingChildren );
- }
-
- mHorizBlurTask.SetCameraActor(mRenderDownsampledCamera);
- mVertBlurTask.SetCameraActor(mRenderDownsampledCamera);
-
- mHorizBlurTask.SetTargetFrameBuffer( mRenderTarget2 );
- if(mUserOutputRenderTarget)
- {
- mVertBlurTask.SetTargetFrameBuffer( mUserOutputRenderTarget );
- }
- else
- {
- mVertBlurTask.SetTargetFrameBuffer( mRenderTarget1 );
+ mCompositeTask.SetFrameBuffer( mRenderTargetForRenderingChildren );
}
}
taskList.RemoveTask(mCompositeTask);
}
-void GaussianBlurView::OnStageDisconnection()
-{
- // TODO: can't call this here, since SetImage() calls fails similarly to above
- // Need to fix the stage connection so this callback can be used arbitrarily. At that point we can simplify the API by removing the need for Activate() / Deactivate()
- //Deactivate();
-}
-
-void GaussianBlurView::OnControlStageConnection()
-{
- // TODO: can't call this here, since SetImage() calls fail to connect images to stage, since parent chain not fully on stage yet
- // Need to fix the stage connection so this callback can be used arbitrarily. At that point we can simplify the API by removing the need for Activate() / Deactivate()
- //Activate();
-}
-
void GaussianBlurView::Activate()
{
- // make sure resources are allocated and start the render tasks processing
- AllocateResources();
- CreateRenderTasks();
+ if( !mActivated )
+ {
+ // make sure resources are allocated and start the render tasks processing
+ Self().Add( mInternalRoot );
+ AllocateResources();
+ CreateRenderTasks();
+ mActivated = true;
+ }
}
void GaussianBlurView::ActivateOnce()
void GaussianBlurView::Deactivate()
{
- // stop render tasks processing
- // Note: render target resources are automatically freed since we set the Image::Unused flag
- RemoveRenderTasks();
- mRenderOnce = false;
+ if( mActivated )
+ {
+ // stop render tasks processing
+ // Note: render target resources are automatically freed since we set the Image::Unused flag
+ mInternalRoot.Unparent();
+ mRenderTargetForRenderingChildren.Reset();
+ mRenderTarget1.Reset();
+ mRenderTarget2.Reset();
+ RemoveRenderTasks();
+ mRenderOnce = false;
+ mActivated = false;
+ }
}
void GaussianBlurView::SetBlurBellCurveWidth(float blurBellCurveWidth)
Vector2 yAxis(0.0f, 1.0f);
for (i = 0; i < mNumSamples; ++i )
{
- mHorizBlurShader.SetUniform( GetSampleOffsetsPropertyName( i ), uvOffsets[ i ] * xAxis );
- mHorizBlurShader.SetUniform( GetSampleWeightsPropertyName( i ), weights[ i ] );
+ mHorizBlurActor.RegisterProperty( GetSampleOffsetsPropertyName( i ), uvOffsets[ i ] * xAxis );
+ mHorizBlurActor.RegisterProperty( GetSampleWeightsPropertyName( i ), weights[ i ] );
- mVertBlurShader.SetUniform( GetSampleOffsetsPropertyName( i ), uvOffsets[ i ] * yAxis );
- mVertBlurShader.SetUniform( GetSampleWeightsPropertyName( i ), weights[ i ] );
+ mVertBlurActor.RegisterProperty( GetSampleOffsetsPropertyName( i ), uvOffsets[ i ] * yAxis );
+ mVertBlurActor.RegisterProperty( GetSampleWeightsPropertyName( i ), weights[ i ] );
}
delete[] uvOffsets;