X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fcontrols%2Fbloom-view%2Fbloom-view-impl.cpp;h=c05e9549e83edc6eedb0897b13cdb60dc9e80195;hp=cf24627c288bbc25b21ebf4f11c00df4e690e6ad;hb=3b814d1a154260d5d83923ec3b876aac095eee94;hpb=1c3cb32385174b852b8d57b531625f733238f664 diff --git a/dali-toolkit/internal/controls/bloom-view/bloom-view-impl.cpp b/dali-toolkit/internal/controls/bloom-view/bloom-view-impl.cpp index cf24627..c05e954 100644 --- a/dali-toolkit/internal/controls/bloom-view/bloom-view-impl.cpp +++ b/dali-toolkit/internal/controls/bloom-view/bloom-view-impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2017 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. @@ -21,15 +21,21 @@ // EXTERNAL INCLUDES #include #include +#include #include #include +#include #include +#include #include +#include +#include // INTERNAL INCLUDES -#include -#include -#include "../gaussian-blur-view/gaussian-blur-view-impl.h" +#include +#include +#include +#include namespace Dali { @@ -50,7 +56,8 @@ BaseHandle Create() return Toolkit::BloomView::New(); } -TypeRegistration mType( typeid(Toolkit::BloomView), typeid(Toolkit::Control), Create ); +DALI_TYPE_REGISTRATION_BEGIN( Toolkit::BloomView, Toolkit::Control, Create ) +DALI_TYPE_REGISTRATION_END() // default parameters const float BLOOM_THRESHOLD_DEFAULT = 0.25f; @@ -70,14 +77,13 @@ const float BLOOM_GAUSSIAN_BLUR_VIEW_DEFAULT_DOWNSAMPLE_HEIGHT_SCALE = 0.5f; const float ARBITRARY_FIELD_OF_VIEW = Math::PI / 4.0f; -const std::string BLOOM_BLUR_STRENGTH_PROPERTY_NAME( "BlurStrengthProperty" ); - -const std::string BLOOM_THRESHOLD_PROPERTY_NAME( "uBloomThreshold" ); -const std::string RECIP_ONE_MINUS_BLOOM_THRESHOLD_PROPERTY_NAME( "uRecipOneMinusBloomThreshold" ); -const std::string BLOOM_INTENSITY_PROPERTY_NAME( "uBloomIntensity" ); -const std::string BLOOM_SATURATION_PROPERTY_NAME( "uBloomSaturation" ); -const std::string IMAGE_INTENSITY_PROPERTY_NAME( "uImageIntensity" ); -const std::string IMAGE_SATURATION_PROPERTY_NAME( "uImageSaturation" ); +const char* const BLOOM_BLUR_STRENGTH_PROPERTY_NAME = "BlurStrengthProperty"; +const char* const BLOOM_THRESHOLD_PROPERTY_NAME = "uBloomThreshold"; +const char* const RECIP_ONE_MINUS_BLOOM_THRESHOLD_PROPERTY_NAME = "uRecipOneMinusBloomThreshold"; +const char* const BLOOM_INTENSITY_PROPERTY_NAME = "uBloomIntensity"; +const char* const BLOOM_SATURATION_PROPERTY_NAME = "uBloomSaturation"; +const char* const IMAGE_INTENSITY_PROPERTY_NAME = "uImageIntensity"; +const char* const IMAGE_SATURATION_PROPERTY_NAME = "uImageSaturation"; /////////////////////////////////////////////////////// // @@ -85,17 +91,25 @@ const std::string IMAGE_SATURATION_PROPERTY_NAME( "uImageSaturation" ); // const char* const BLOOM_EXTRACT_FRAGMENT_SOURCE = - "uniform float uBloomThreshold;\n" - "uniform float uRecipOneMinusBloomThreshold;\n" + "varying mediump vec2 vTexCoord;\n" + "uniform sampler2D sTexture;\n" + "uniform lowp vec4 uColor;\n" + "uniform mediump float uBloomThreshold;\n" + "uniform mediump float uRecipOneMinusBloomThreshold;\n" "void main()\n" "{\n" " mediump vec4 col;\n" - " col = texture2D(sTexture, vec2(vTexCoord.x, vTexCoord.y));\n" + " col = texture2D(sTexture, vTexCoord);\n" " col = (col - uBloomThreshold) * uRecipOneMinusBloomThreshold;\n" // remove intensities lower than the thresold and remap intensities above the threshold to [0..1] " gl_FragColor = clamp(col, 0.0, 1.0);\n" "}\n"; const char* const COMPOSITE_FRAGMENT_SOURCE = + "precision mediump float;\n" + "varying mediump vec2 vTexCoord;\n" + "uniform sampler2D sTexture;\n" + "uniform sampler2D sEffect;\n" + "uniform lowp vec4 uColor;\n" "uniform float uBloomIntensity;\n" "uniform float uImageIntensity;\n" "uniform float uBloomSaturation;\n" @@ -111,8 +125,8 @@ const char* const COMPOSITE_FRAGMENT_SOURCE = "{\n" " mediump vec4 image;\n" " mediump vec4 bloom;\n" - " image = texture2D(sTexture, vec2(vTexCoord.x, vTexCoord.y));\n" - " bloom = texture2D(sEffect, vec2(vTexCoord.x, vTexCoord.y));\n" + " image = texture2D(sTexture, vTexCoord);\n" + " bloom = texture2D(sEffect, vTexCoord);\n" " image = ChangeSaturation(image, uImageSaturation) * uImageIntensity;\n" " bloom = ChangeSaturation(bloom, uBloomSaturation) * uBloomIntensity;\n" " image *= 1.0 - clamp(bloom, 0.0, 1.0);\n" // darken base where bloom is strong, to prevent excessive burn-out of result @@ -124,45 +138,49 @@ const char* const COMPOSITE_FRAGMENT_SOURCE = BloomView::BloomView() - : Control( CONTROL_BEHAVIOUR_NONE ) - , mBlurNumSamples(BLOOM_GAUSSIAN_BLUR_VIEW_DEFAULT_NUM_SAMPLES) - , mBlurBellCurveWidth(BLOOM_GAUSSIAN_BLUR_VIEW_DEFAULT_BLUR_BELL_CURVE_WIDTH) - , mPixelFormat(BLOOM_GAUSSIAN_BLUR_VIEW_DEFAULT_RENDER_TARGET_PIXEL_FORMAT) - , mDownsampleWidthScale(BLOOM_GAUSSIAN_BLUR_VIEW_DEFAULT_DOWNSAMPLE_WIDTH_SCALE) - , mDownsampleHeightScale(BLOOM_GAUSSIAN_BLUR_VIEW_DEFAULT_DOWNSAMPLE_HEIGHT_SCALE) - , mDownsampledWidth( 0.0f ) - , mDownsampledHeight( 0.0f ) - , mTargetSize(Vector2::ZERO) - , mLastSize(Vector2::ZERO) - , mChildrenRoot(Actor::New()) - , mBloomThresholdPropertyIndex(Property::INVALID_INDEX) - , mBlurStrengthPropertyIndex(Property::INVALID_INDEX) - , mBloomIntensityPropertyIndex(Property::INVALID_INDEX) - , mBloomSaturationPropertyIndex(Property::INVALID_INDEX) - , mImageIntensityPropertyIndex(Property::INVALID_INDEX) - , mImageSaturationPropertyIndex(Property::INVALID_INDEX) +: Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ), + mBlurNumSamples(BLOOM_GAUSSIAN_BLUR_VIEW_DEFAULT_NUM_SAMPLES), + mBlurBellCurveWidth(BLOOM_GAUSSIAN_BLUR_VIEW_DEFAULT_BLUR_BELL_CURVE_WIDTH), + mPixelFormat(BLOOM_GAUSSIAN_BLUR_VIEW_DEFAULT_RENDER_TARGET_PIXEL_FORMAT), + mDownsampleWidthScale(BLOOM_GAUSSIAN_BLUR_VIEW_DEFAULT_DOWNSAMPLE_WIDTH_SCALE), + mDownsampleHeightScale(BLOOM_GAUSSIAN_BLUR_VIEW_DEFAULT_DOWNSAMPLE_HEIGHT_SCALE), + mDownsampledWidth( 0.0f ), + mDownsampledHeight( 0.0f ), + mTargetSize(Vector2::ZERO), + mLastSize(Vector2::ZERO), + mChildrenRoot(Actor::New()), + mInternalRoot(Actor::New() ), + mBloomThresholdPropertyIndex(Property::INVALID_INDEX), + mBlurStrengthPropertyIndex(Property::INVALID_INDEX), + mBloomIntensityPropertyIndex(Property::INVALID_INDEX), + mBloomSaturationPropertyIndex(Property::INVALID_INDEX), + mImageIntensityPropertyIndex(Property::INVALID_INDEX), + mImageSaturationPropertyIndex(Property::INVALID_INDEX), + mActivated( false ) { } BloomView::BloomView( const unsigned int blurNumSamples, const float blurBellCurveWidth, const Pixel::Format renderTargetPixelFormat, const float downsampleWidthScale, const float downsampleHeightScale) - : Control( CONTROL_BEHAVIOUR_NONE ) - , mBlurNumSamples(blurNumSamples) - , mBlurBellCurveWidth(blurBellCurveWidth) - , mPixelFormat(renderTargetPixelFormat) - , mDownsampleWidthScale(downsampleWidthScale) - , mDownsampleHeightScale(downsampleHeightScale) - , mDownsampledWidth( 0.0f ) - , mDownsampledHeight( 0.0f ) - , mTargetSize(Vector2::ZERO) - , mLastSize(Vector2::ZERO) - , mChildrenRoot(Actor::New()) - , mBloomThresholdPropertyIndex(Property::INVALID_INDEX) - , mBlurStrengthPropertyIndex(Property::INVALID_INDEX) - , mBloomIntensityPropertyIndex(Property::INVALID_INDEX) - , mBloomSaturationPropertyIndex(Property::INVALID_INDEX) - , mImageIntensityPropertyIndex(Property::INVALID_INDEX) - , mImageSaturationPropertyIndex(Property::INVALID_INDEX) +: Control( ControlBehaviour( CONTROL_BEHAVIOUR_DEFAULT ) ), + mBlurNumSamples(blurNumSamples), + mBlurBellCurveWidth(blurBellCurveWidth), + mPixelFormat(renderTargetPixelFormat), + mDownsampleWidthScale(downsampleWidthScale), + mDownsampleHeightScale(downsampleHeightScale), + mDownsampledWidth( 0.0f ), + mDownsampledHeight( 0.0f ), + mTargetSize(Vector2::ZERO), + mLastSize(Vector2::ZERO), + mChildrenRoot(Actor::New()), + mInternalRoot(Actor::New()), + mBloomThresholdPropertyIndex(Property::INVALID_INDEX), + mBlurStrengthPropertyIndex(Property::INVALID_INDEX), + mBloomIntensityPropertyIndex(Property::INVALID_INDEX), + mBloomSaturationPropertyIndex(Property::INVALID_INDEX), + mImageIntensityPropertyIndex(Property::INVALID_INDEX), + mImageSaturationPropertyIndex(Property::INVALID_INDEX), + mActivated( false ) { } @@ -197,24 +215,6 @@ Toolkit::BloomView BloomView::New(const unsigned int blurNumSamples, const float return handle; } -///////////////////////////////////////////////////////////// -// 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. -void BloomView::Add(Actor child) -{ - mChildrenRoot.Add(child); -} - -void BloomView::Remove(Actor child) -{ - mChildrenRoot.Remove(child); -} - - - - - - /////////////////////////////////////////////////////////// // // Private methods @@ -223,76 +223,64 @@ void BloomView::Remove(Actor child) void BloomView::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.SetPositionInheritanceMode( Dali::USE_PARENT_POSITION ); - - ////////////////////////////////////////////////////// - // Create shaders - - // Create shader used for extracting the bright parts of an image - mBloomExtractShader = ShaderEffect::New( "", BLOOM_EXTRACT_FRAGMENT_SOURCE ); - - // Create shader used to composite bloom and original image to output render target - mCompositeShader = ShaderEffect::New( "", COMPOSITE_FRAGMENT_SOURCE ); - + mChildrenRoot.SetParentOrigin( ParentOrigin::CENTER ); + mInternalRoot.SetParentOrigin( ParentOrigin::CENTER ); ////////////////////////////////////////////////////// // Create actors - // Create an ImageActor for rendering from the scene texture to the bloom texture - mBloomExtractImageActor = ImageActor::New(); - mBloomExtractImageActor.SetPositionInheritanceMode( Dali::USE_PARENT_POSITION ); - mBloomExtractImageActor.ScaleBy( Vector3(1.0f, -1.0f, 1.0f) ); // FIXME - mBloomExtractImageActor.SetShaderEffect( mBloomExtractShader ); - - // Create an ImageActor for compositing the result (scene and bloom textures) to output - mCompositeImageActor = ImageActor::New(); - mCompositeImageActor.SetPositionInheritanceMode( Dali::USE_PARENT_POSITION ); - mCompositeImageActor.SetShaderEffect( mCompositeShader ); - mCompositeImageActor.ScaleBy( Vector3(1.0f, -1.0f, 1.0f) ); // FIXME + // Create an image view for rendering from the scene texture to the bloom texture + mBloomExtractImageView = Toolkit::ImageView::New(); + mBloomExtractImageView.SetParentOrigin( ParentOrigin::CENTER ); - // Create an ImageActor for holding final result, i.e. the blurred image. This will get rendered to screen later, via default / user render task - mTargetImageActor = ImageActor::New(); - mTargetImageActor.SetPositionInheritanceMode( Dali::USE_PARENT_POSITION ); - mTargetImageActor.ScaleBy( Vector3(1.0f, -1.0f, 1.0f) ); // FIXME + // Create an image view for compositing the result (scene and bloom textures) to output + mCompositeImageView = Toolkit::ImageView::New(); + mCompositeImageView.SetParentOrigin( ParentOrigin::CENTER ); + // 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 + mTargetImageView = Toolkit::ImageView::New(); + mTargetImageView.SetParentOrigin( ParentOrigin::CENTER ); // Create the Gaussian Blur object + render tasks // Note that we use mBloomExtractTarget as the source image and also re-use this as the gaussian blur final render target. This saves the gaussian blur code from creating it // render targets etc internally, so we make better use of resources // Note, this also internally creates the render tasks used by the Gaussian blur, this must occur after the bloom extraction and before the compositing mGaussianBlurView = Dali::Toolkit::GaussianBlurView::New(mBlurNumSamples, mBlurBellCurveWidth, mPixelFormat, mDownsampleWidthScale, mDownsampleHeightScale, true); - mGaussianBlurView.SetPositionInheritanceMode( Dali::USE_PARENT_POSITION ); + mGaussianBlurView.SetParentOrigin( ParentOrigin::CENTER ); ////////////////////////////////////////////////////// // Create cameras for the renders corresponding to the (potentially downsampled) render targets' size mRenderDownsampledCamera = CameraActor::New(); mRenderDownsampledCamera.SetParentOrigin(ParentOrigin::CENTER); + mRenderDownsampledCamera.SetInvertYAxis( true ); mRenderFullSizeCamera = CameraActor::New(); mRenderFullSizeCamera.SetParentOrigin(ParentOrigin::CENTER); + mRenderFullSizeCamera.SetInvertYAxis( true ); //////////////////////////////// // Connect to actor tree Self().Add( mChildrenRoot ); - Self().Add( mBloomExtractImageActor ); - Self().Add( mGaussianBlurView ); - Self().Add( mCompositeImageActor ); - Self().Add( mTargetImageActor ); - Self().Add( mRenderDownsampledCamera ); - Self().Add( mRenderFullSizeCamera ); + Self().Add( mInternalRoot ); + mInternalRoot.Add( mBloomExtractImageView ); + mInternalRoot.Add( mGaussianBlurView ); + mInternalRoot.Add( mCompositeImageView ); + mInternalRoot.Add( mTargetImageView ); + mInternalRoot.Add( mRenderDownsampledCamera ); + mInternalRoot.Add( mRenderFullSizeCamera ); // bind properties for / set shader constants to defaults SetupProperties(); } -void BloomView::OnControlSizeSet(const Vector3& targetSize) +void BloomView::OnSizeSet(const Vector3& targetSize) { mTargetSize = Vector2(targetSize); mChildrenRoot.SetSize(targetSize); - mCompositeImageActor.SetSize(targetSize); - mTargetImageActor.SetSize(targetSize); + mCompositeImageView.SetSize(targetSize); + mTargetImageView.SetSize(targetSize); // Children render camera must move when GaussianBlurView object is // resized. This is since we cannot change render target size - so we need @@ -304,17 +292,37 @@ void BloomView::OnControlSizeSet(const Vector3& targetSize) float cameraPosConstraintScale = 0.5f / tanf(ARBITRARY_FIELD_OF_VIEW * 0.5f); mRenderFullSizeCamera.SetZ( mTargetSize.height * cameraPosConstraintScale); - // 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 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(); + } + + Control::OnSizeSet( targetSize ); +} + +void BloomView::OnChildAdd( Actor& child ) +{ + if( child != mChildrenRoot && child != mInternalRoot) { - AllocateResources(); + mChildrenRoot.Add( child ); } + + Control::OnChildAdd( child ); +} + +void BloomView::OnChildRemove( Actor& child ) +{ + mChildrenRoot.Remove( child ); + + Control::OnChildRemove( child ); } void BloomView::AllocateResources() { // size of render targets etc is based on the size of this actor, ignoring z - if(mTargetSize != mLastSize) + if(mTargetSize != mLastSize || !mActivated) { mLastSize = mTargetSize; @@ -332,7 +340,6 @@ void BloomView::AllocateResources() mRenderDownsampledCamera.SetNearClippingPlane(1.0f); mRenderDownsampledCamera.SetAspectRatio(mDownsampledWidth / mDownsampledHeight); mRenderDownsampledCamera.SetType(Dali::Camera::FREE_LOOK); // camera orientation based solely on actor - mRenderDownsampledCamera.SetRotation(Quaternion(M_PI, Vector3::YAXIS)); // Rotate to look at origin mRenderDownsampledCamera.SetPosition(0.0f, 0.0f, ((mDownsampledHeight * 0.5f) / tanf(ARBITRARY_FIELD_OF_VIEW * 0.5f))); @@ -342,7 +349,6 @@ void BloomView::AllocateResources() mRenderFullSizeCamera.SetNearClippingPlane(1.0f); mRenderFullSizeCamera.SetAspectRatio(mTargetSize.width / mTargetSize.height); mRenderFullSizeCamera.SetType(Dali::Camera::FREE_LOOK); // camera orientation based solely on actor - mRenderFullSizeCamera.SetRotation(Quaternion(M_PI, Vector3::YAXIS)); // Rotate to look at origin float cameraPosConstraintScale = 0.5f / tanf(ARBITRARY_FIELD_OF_VIEW * 0.5f); mRenderFullSizeCamera.SetPosition(0.0f, 0.0f, mTargetSize.height * cameraPosConstraintScale); @@ -352,31 +358,44 @@ void BloomView::AllocateResources() mGaussianBlurView.SetSize(mTargetSize); GetImpl(mGaussianBlurView).AllocateResources(); + mGaussianBlurView.SetVisible( true ); ////////////////////////////////////////////////////// // Create render targets // create off screen buffer of new size to render our child actors to - mRenderTargetForRenderingChildren = FrameBufferImage::New( mTargetSize.width, mTargetSize.height, mPixelFormat, Dali::Image::UNUSED ); - mBloomExtractTarget = FrameBufferImage::New( mDownsampledWidth, mDownsampledHeight, mPixelFormat, Dali::Image::UNUSED ); - mOutputRenderTarget = FrameBufferImage::New( mTargetSize.width, mTargetSize.height, mPixelFormat, Dali::Image::UNUSED); + mRenderTargetForRenderingChildren = FrameBufferImage::New( mTargetSize.width, mTargetSize.height, mPixelFormat ); + mBloomExtractTarget = FrameBufferImage::New( mDownsampledWidth, mDownsampledHeight, mPixelFormat ); + FrameBufferImage mBlurExtractTarget = FrameBufferImage::New( mDownsampledWidth, mDownsampledHeight, mPixelFormat ); + mOutputRenderTarget = FrameBufferImage::New( mTargetSize.width, mTargetSize.height, mPixelFormat ); ////////////////////////////////////////////////////// // Point actors and render tasks at new render targets - mBloomExtractImageActor.SetImage( mRenderTargetForRenderingChildren ); - mBloomExtractImageActor.SetSize(mDownsampledWidth, mDownsampledHeight); // size needs to match render target + mBloomExtractImageView.SetImage( mRenderTargetForRenderingChildren ); + mBloomExtractImageView.SetSize(mDownsampledWidth, mDownsampledHeight); // size needs to match render target + // Create shader used for extracting the bright parts of an image + Property::Map customShader; + customShader[ Toolkit::Visual::Shader::Property::FRAGMENT_SHADER ] = BLOOM_EXTRACT_FRAGMENT_SOURCE; + Property::Map visualMap; + visualMap.Insert( Toolkit::Visual::Property::SHADER, customShader ); + mBloomExtractImageView.SetProperty( Toolkit::ImageView::Property::IMAGE, visualMap ); // set GaussianBlurView to blur our extracted bloom - mGaussianBlurView.SetUserImageAndOutputRenderTarget(mBloomExtractTarget, mBloomExtractTarget); + mGaussianBlurView.SetUserImageAndOutputRenderTarget(mBloomExtractTarget, mBlurExtractTarget); // use the completed blur in the first buffer and composite with the original child actors render - mCompositeImageActor.SetImage( mRenderTargetForRenderingChildren ); - mCompositeShader.SetEffectImage( mBloomExtractTarget ); + mCompositeImageView.SetImage( mRenderTargetForRenderingChildren ); + // Create shader used to composite bloom and original image to output render target + customShader[ Toolkit::Visual::Shader::Property::FRAGMENT_SHADER ] = COMPOSITE_FRAGMENT_SOURCE; + visualMap[ Toolkit::Visual::Property::SHADER ] = customShader; + mCompositeImageView.SetProperty( Toolkit::ImageView::Property::IMAGE, visualMap ); + TextureSet textureSet = mCompositeImageView.GetRendererAt(0).GetTextures(); + TextureSetImage( textureSet, 1u, mBlurExtractTarget ); // set up target actor for rendering result, i.e. the blurred image - mTargetImageActor.SetImage(mOutputRenderTarget); + mTargetImageView.SetImage(mOutputRenderTarget); } } @@ -390,30 +409,28 @@ void BloomView::CreateRenderTasks() mRenderChildrenTask.SetExclusive(true); mRenderChildrenTask.SetInputEnabled( false ); mRenderChildrenTask.SetClearEnabled( true ); + mRenderChildrenTask.SetCameraActor(mRenderFullSizeCamera); // use camera that covers render target exactly + mRenderChildrenTask.SetTargetFrameBuffer( mRenderTargetForRenderingChildren ); // Extract the bright part of the image and render to a new buffer. Downsampling also occurs at this stage to save pixel fill, if it is set up. mBloomExtractTask = taskList.CreateTask(); - mBloomExtractTask.SetSourceActor( mBloomExtractImageActor ); + mBloomExtractTask.SetSourceActor( mBloomExtractImageView ); mBloomExtractTask.SetExclusive(true); mBloomExtractTask.SetInputEnabled( false ); mBloomExtractTask.SetClearEnabled( true ); + mBloomExtractTask.SetCameraActor(mRenderDownsampledCamera); + mBloomExtractTask.SetTargetFrameBuffer( mBloomExtractTarget ); // GaussianBlurView tasks must be created here, so they are executed in the correct order with respect to BloomView tasks GetImpl(mGaussianBlurView).CreateRenderTasks(); - // Use an image actor displaying the children render and composite it with the blurred bloom buffer, targeting the output + // Use an image view displaying the children render and composite it with the blurred bloom buffer, targeting the output mCompositeTask = taskList.CreateTask(); - mCompositeTask.SetSourceActor( mCompositeImageActor ); + mCompositeTask.SetSourceActor( mCompositeImageView ); mCompositeTask.SetExclusive(true); mCompositeTask.SetInputEnabled( false ); mCompositeTask.SetClearEnabled( true ); - - mRenderChildrenTask.SetCameraActor(mRenderFullSizeCamera); // use camera that covers render target exactly - mBloomExtractTask.SetCameraActor(mRenderDownsampledCamera); mCompositeTask.SetCameraActor(mRenderFullSizeCamera); - - mRenderChildrenTask.SetTargetFrameBuffer( mRenderTargetForRenderingChildren ); - mBloomExtractTask.SetTargetFrameBuffer( mBloomExtractTarget ); mCompositeTask.SetTargetFrameBuffer( mOutputRenderTarget ); } @@ -429,25 +446,12 @@ void BloomView::RemoveRenderTasks() taskList.RemoveTask(mCompositeTask); } -void BloomView::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 BloomView::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 BloomView::Activate() { // make sure resources are allocated and start the render tasks processing AllocateResources(); CreateRenderTasks(); + mActivated = true; } void BloomView::Deactivate() @@ -455,19 +459,20 @@ void BloomView::Deactivate() // stop render tasks processing // Note: render target resources are automatically freed since we set the Image::Unused flag RemoveRenderTasks(); -} -/** - * EqualToConstraintFloat - * - * f(current, property) = property - */ -struct EqualToConstraintFloat -{ - EqualToConstraintFloat(){} + mRenderTargetForRenderingChildren.Reset(); + mBloomExtractTarget.Reset(); + mOutputRenderTarget.Reset(); - float operator()(const float current, const PropertyInput& property) {return property.GetFloat();} -}; + // Reset children + mBloomExtractImageView.SetImage( "" ); + mTargetImageView.SetImage( "" ); + mCompositeImageView.SetImage( "" ); + + mGaussianBlurView.SetVisible( false ); + + mActivated = false; +} /** * RecipOneMinusConstraint @@ -478,9 +483,9 @@ struct RecipOneMinusConstraint { RecipOneMinusConstraint(){} - float operator()(const float current, const PropertyInput& property) + void operator()( float& current, const PropertyInputContainer& inputs ) { - return 1.0f / (1.0f - property.GetFloat()); + current = 1.0f / ( 1.0f - inputs[0]->GetFloat() ); } }; @@ -495,19 +500,21 @@ void BloomView::SetupProperties() // bloom threshold // set defaults, makes sure properties are registered with shader - mBloomExtractShader.SetUniform( BLOOM_THRESHOLD_PROPERTY_NAME, BLOOM_THRESHOLD_DEFAULT ); - mBloomExtractShader.SetUniform( RECIP_ONE_MINUS_BLOOM_THRESHOLD_PROPERTY_NAME, 1.0f / (1.0f - BLOOM_THRESHOLD_DEFAULT) ); + mBloomExtractImageView.RegisterProperty( BLOOM_THRESHOLD_PROPERTY_NAME, BLOOM_THRESHOLD_DEFAULT ); + mBloomExtractImageView.RegisterProperty( RECIP_ONE_MINUS_BLOOM_THRESHOLD_PROPERTY_NAME, 1.0f / (1.0f - BLOOM_THRESHOLD_DEFAULT) ); // Register a property that the user can control to change the bloom threshold mBloomThresholdPropertyIndex = self.RegisterProperty(BLOOM_THRESHOLD_PROPERTY_NAME, BLOOM_THRESHOLD_DEFAULT); - Property::Index shaderBloomThresholdPropertyIndex = mBloomExtractShader.GetPropertyIndex(BLOOM_THRESHOLD_PROPERTY_NAME); - Constraint bloomThresholdConstraint = Constraint::New(shaderBloomThresholdPropertyIndex, Source(self, mBloomThresholdPropertyIndex), EqualToConstraintFloat()); - mBloomExtractShader.ApplyConstraint(bloomThresholdConstraint); + Property::Index shaderBloomThresholdPropertyIndex = mBloomExtractImageView.GetPropertyIndex(BLOOM_THRESHOLD_PROPERTY_NAME); + Constraint bloomThresholdConstraint = Constraint::New( mBloomExtractImageView, shaderBloomThresholdPropertyIndex, EqualToConstraint()); + bloomThresholdConstraint.AddSource( Source(self, mBloomThresholdPropertyIndex) ); + bloomThresholdConstraint.Apply(); // precalc 1.0 / (1.0 - threshold) on CPU to save shader insns, using constraint to tie to the normal threshold property - Property::Index shaderRecipOneMinusBloomThresholdPropertyIndex = mBloomExtractShader.GetPropertyIndex(RECIP_ONE_MINUS_BLOOM_THRESHOLD_PROPERTY_NAME); - Constraint thresholdConstraint = Constraint::New( shaderRecipOneMinusBloomThresholdPropertyIndex, LocalSource(shaderBloomThresholdPropertyIndex), RecipOneMinusConstraint()); - mBloomExtractShader.ApplyConstraint(thresholdConstraint); + Property::Index shaderRecipOneMinusBloomThresholdPropertyIndex = mBloomExtractImageView.GetPropertyIndex(RECIP_ONE_MINUS_BLOOM_THRESHOLD_PROPERTY_NAME); + Constraint thresholdConstraint = Constraint::New( mBloomExtractImageView, shaderRecipOneMinusBloomThresholdPropertyIndex, RecipOneMinusConstraint()); + thresholdConstraint.AddSource( LocalSource(shaderBloomThresholdPropertyIndex) ); + thresholdConstraint.Apply(); //////////////////////////////////////////// @@ -515,8 +522,9 @@ void BloomView::SetupProperties() // Register a property that the user can control to fade the blur in / out via internal GaussianBlurView object mBlurStrengthPropertyIndex = self.RegisterProperty(BLOOM_BLUR_STRENGTH_PROPERTY_NAME, BLOOM_BLUR_STRENGTH_DEFAULT); - Constraint blurStrengthConstraint = Constraint::New( mGaussianBlurView.GetBlurStrengthPropertyIndex(), Source(self, mBlurStrengthPropertyIndex), EqualToConstraintFloat()); - mGaussianBlurView.ApplyConstraint(blurStrengthConstraint); + Constraint blurStrengthConstraint = Constraint::New( mGaussianBlurView, mGaussianBlurView.GetBlurStrengthPropertyIndex(), EqualToConstraint()); + blurStrengthConstraint.AddSource( Source(self, mBlurStrengthPropertyIndex) ); + blurStrengthConstraint.Apply(); //////////////////////////////////////////// @@ -524,10 +532,11 @@ void BloomView::SetupProperties() // Register a property that the user can control to fade the bloom intensity via internally hidden shader mBloomIntensityPropertyIndex = self.RegisterProperty(BLOOM_INTENSITY_PROPERTY_NAME, BLOOM_INTENSITY_DEFAULT); - mCompositeShader.SetUniform( BLOOM_INTENSITY_PROPERTY_NAME, BLOOM_INTENSITY_DEFAULT ); - Property::Index shaderBloomIntensityPropertyIndex = mCompositeShader.GetPropertyIndex(BLOOM_INTENSITY_PROPERTY_NAME); - Constraint bloomIntensityConstraint = Constraint::New( shaderBloomIntensityPropertyIndex, Source(self, mBloomIntensityPropertyIndex), EqualToConstraintFloat()); - mCompositeShader.ApplyConstraint(bloomIntensityConstraint); + mCompositeImageView.RegisterProperty( BLOOM_INTENSITY_PROPERTY_NAME, BLOOM_INTENSITY_DEFAULT ); + Property::Index shaderBloomIntensityPropertyIndex = mCompositeImageView.GetPropertyIndex(BLOOM_INTENSITY_PROPERTY_NAME); + Constraint bloomIntensityConstraint = Constraint::New( mCompositeImageView, shaderBloomIntensityPropertyIndex, EqualToConstraint()); + bloomIntensityConstraint.AddSource( Source(self, mBloomIntensityPropertyIndex) ); + bloomIntensityConstraint.Apply(); //////////////////////////////////////////// @@ -535,10 +544,11 @@ void BloomView::SetupProperties() // Register a property that the user can control to fade the bloom saturation via internally hidden shader mBloomSaturationPropertyIndex = self.RegisterProperty(BLOOM_SATURATION_PROPERTY_NAME, BLOOM_SATURATION_DEFAULT); - mCompositeShader.SetUniform( BLOOM_SATURATION_PROPERTY_NAME, BLOOM_SATURATION_DEFAULT ); - Property::Index shaderBloomSaturationPropertyIndex = mCompositeShader.GetPropertyIndex(BLOOM_SATURATION_PROPERTY_NAME); - Constraint bloomSaturationConstraint = Constraint::New( shaderBloomSaturationPropertyIndex, Source(self, mBloomSaturationPropertyIndex), EqualToConstraintFloat()); - mCompositeShader.ApplyConstraint(bloomSaturationConstraint); + mCompositeImageView.RegisterProperty( BLOOM_SATURATION_PROPERTY_NAME, BLOOM_SATURATION_DEFAULT ); + Property::Index shaderBloomSaturationPropertyIndex = mCompositeImageView.GetPropertyIndex(BLOOM_SATURATION_PROPERTY_NAME); + Constraint bloomSaturationConstraint = Constraint::New( mCompositeImageView, shaderBloomSaturationPropertyIndex, EqualToConstraint()); + bloomSaturationConstraint.AddSource( Source(self, mBloomSaturationPropertyIndex) ); + bloomSaturationConstraint.Apply(); //////////////////////////////////////////// @@ -546,10 +556,11 @@ void BloomView::SetupProperties() // Register a property that the user can control to fade the image intensity via internally hidden shader mImageIntensityPropertyIndex = self.RegisterProperty(IMAGE_INTENSITY_PROPERTY_NAME, IMAGE_INTENSITY_DEFAULT); - mCompositeShader.SetUniform( IMAGE_INTENSITY_PROPERTY_NAME, IMAGE_INTENSITY_DEFAULT ); - Property::Index shaderImageIntensityPropertyIndex = mCompositeShader.GetPropertyIndex(IMAGE_INTENSITY_PROPERTY_NAME); - Constraint imageIntensityConstraint = Constraint::New( shaderImageIntensityPropertyIndex, Source(self, mImageIntensityPropertyIndex), EqualToConstraintFloat()); - mCompositeShader.ApplyConstraint(imageIntensityConstraint); + mCompositeImageView.RegisterProperty( IMAGE_INTENSITY_PROPERTY_NAME, IMAGE_INTENSITY_DEFAULT ); + Property::Index shaderImageIntensityPropertyIndex = mCompositeImageView.GetPropertyIndex(IMAGE_INTENSITY_PROPERTY_NAME); + Constraint imageIntensityConstraint = Constraint::New( mCompositeImageView, shaderImageIntensityPropertyIndex, EqualToConstraint()); + imageIntensityConstraint.AddSource( Source(self, mImageIntensityPropertyIndex) ); + imageIntensityConstraint.Apply(); //////////////////////////////////////////// @@ -557,10 +568,11 @@ void BloomView::SetupProperties() // Register a property that the user can control to fade the image saturation via internally hidden shader mImageSaturationPropertyIndex = self.RegisterProperty(IMAGE_SATURATION_PROPERTY_NAME, IMAGE_SATURATION_DEFAULT); - mCompositeShader.SetUniform( IMAGE_SATURATION_PROPERTY_NAME, IMAGE_SATURATION_DEFAULT ); - Property::Index shaderImageSaturationPropertyIndex = mCompositeShader.GetPropertyIndex(IMAGE_SATURATION_PROPERTY_NAME); - Constraint imageSaturationConstraint = Constraint::New( shaderImageSaturationPropertyIndex, Source(self, mImageSaturationPropertyIndex), EqualToConstraintFloat()); - mCompositeShader.ApplyConstraint(imageSaturationConstraint); + mCompositeImageView.RegisterProperty( IMAGE_SATURATION_PROPERTY_NAME, IMAGE_SATURATION_DEFAULT ); + Property::Index shaderImageSaturationPropertyIndex = mCompositeImageView.GetPropertyIndex(IMAGE_SATURATION_PROPERTY_NAME); + Constraint imageSaturationConstraint = Constraint::New( mCompositeImageView, shaderImageSaturationPropertyIndex, EqualToConstraint()); + imageSaturationConstraint.AddSource( Source(self, mImageSaturationPropertyIndex) ); + imageSaturationConstraint.Apply(); } } // namespace Internal