1 #ifndef __DALI_TOOLKIT_INTERNAL_BLOOM_VIEW_H__
2 #define __DALI_TOOLKIT_INTERNAL_BLOOM_VIEW_H__
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
7 // Licensed under the Flora License, Version 1.0 (the License);
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://floralicense.org/license/
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an AS IS BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
25 #include <dali/dali.h>
26 #include <dali-toolkit/public-api/controls/control-impl.h>
27 #include <dali-toolkit/public-api/controls/gaussian-blur-view/gaussian-blur-view.h>
28 #include <dali-toolkit/public-api/controls/bloom-view/bloom-view.h>
42 * BloomEffect implementation class
44 class BloomView : public ControlImpl
48 * @copydoc Dali::Toolkit::BloomView::BloomView
53 * @copydoc Dali::Toolkit::BloomView::BloomView
55 BloomView(const unsigned int numSamples, const float blurBellCurveWidth, const Pixel::Format renderTargetPixelFormat,
56 const float downsampleWidthScale, const float downsampleHeightScale);
59 * @copydoc Dali::Toolkit::BloomView::~BloomView
64 * @copydoc Dali::Toolkit::BloomView::New
66 static Dali::Toolkit::BloomView New();
67 static Dali::Toolkit::BloomView New( const unsigned int numSamples, const float blurBellCurveWidth, const Pixel::Format renderTargetPixelFormat,
68 const float downsampleWidthScale, const float downsampleHeightScale);
70 void Add(Actor child);
71 void Remove(Actor child);
76 Property::Index GetBloomThresholdPropertyIndex() const {return mBloomThresholdPropertyIndex;}
77 Property::Index GetBlurStrengthPropertyIndex() const {return mBlurStrengthPropertyIndex;}
78 Property::Index GetBloomIntensityPropertyIndex() const {return mBloomIntensityPropertyIndex;}
79 Property::Index GetBloomSaturationPropertyIndex() const {return mBloomSaturationPropertyIndex;}
80 Property::Index GetImageIntensityPropertyIndex() const {return mImageIntensityPropertyIndex;}
81 Property::Index GetImageSaturationPropertyIndex() const {return mImageSaturationPropertyIndex;}
85 virtual void OnInitialize();
86 virtual void OnControlSizeSet(const Vector3& targetSize);
87 virtual void OnStageDisconnection();
89 virtual void OnControlStageConnection();
91 void AllocateResources();
92 void CreateRenderTasks();
93 void RemoveRenderTasks();
95 void SetupProperties();
98 /////////////////////////////////////////////////////////////
99 unsigned int mBlurNumSamples; // number of blur samples in each of horiz/vert directions
100 float mBlurBellCurveWidth; // constant used when calculating the gaussian weights
101 Pixel::Format mPixelFormat; // pixel format used by render targets
103 /////////////////////////////////////////////////////////////
104 // downsampling is used for the separated blur passes to get increased blur with the same number of samples and also to make rendering quicker
105 float mDownsampleWidthScale;
106 float mDownsampleHeightScale;
107 float mDownsampledWidth;
108 float mDownsampledHeight;
111 /////////////////////////////////////////////////////////////
112 // for checking if we need to reallocate render targets
116 /////////////////////////////////////////////////////////////
117 // 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
120 /////////////////////////////////////////////////////////////
121 // for mapping offscreen renders to render target sizes
122 CameraActor mRenderFullSizeCamera;
123 CameraActor mRenderDownsampledCamera;
125 /////////////////////////////////////////////////////////////
126 // for rendering all user added children to offscreen target
127 FrameBufferImage mRenderTargetForRenderingChildren;
128 RenderTask mRenderChildrenTask;
130 /////////////////////////////////////////////////////////////
131 // for extracting bright parts of image to an offscreen target
132 FrameBufferImage mBloomExtractTarget; // for rendering bright parts of image into separate texture, also used as target for gaussian blur
133 RenderTask mBloomExtractTask;
134 ShaderEffect mBloomExtractShader;
135 ImageActor mBloomExtractImageActor;
137 /////////////////////////////////////////////////////////////
138 // for blurring extracted bloom
139 Dali::Toolkit::GaussianBlurView mGaussianBlurView;
141 /////////////////////////////////////////////////////////////
142 // for compositing bloom and children renders to offscreen target
143 RenderTask mCompositeTask;
144 ShaderEffect mCompositeShader;
145 ImageActor mCompositeImageActor;
147 /////////////////////////////////////////////////////////////
148 // for holding blurred result
149 FrameBufferImage mOutputRenderTarget;
150 ImageActor mTargetImageActor;
152 /////////////////////////////////////////////////////////////
153 // Properties for setting by user, e.g. by animations
154 Property::Index mBloomThresholdPropertyIndex;
155 Property::Index mBlurStrengthPropertyIndex;
156 Property::Index mBloomIntensityPropertyIndex;
157 Property::Index mBloomSaturationPropertyIndex;
158 Property::Index mImageIntensityPropertyIndex;
159 Property::Index mImageSaturationPropertyIndex;
163 // Undefined copy constructor.
164 BloomView( const BloomView& );
166 // Undefined assignment operator.
167 BloomView& operator=( const BloomView& );
170 } // namespace Internal
172 // Helpers for public-api forwarding methods
173 inline Toolkit::Internal::BloomView& GetImpl( Toolkit::BloomView& obj )
175 DALI_ASSERT_ALWAYS(obj);
176 Dali::RefObject& handle = obj.GetImplementation();
177 return static_cast<Toolkit::Internal::BloomView&>(handle);
180 inline const Toolkit::Internal::BloomView& GetImpl( const Toolkit::BloomView& obj )
182 DALI_ASSERT_ALWAYS(obj);
183 const Dali::RefObject& handle = obj.GetImplementation();
184 return static_cast<const Toolkit::Internal::BloomView&>(handle);
187 } // namespace Toolkit
191 #endif // __DALI_TOOLKIT_INTERNAL_BLOOM_VIEW_H__