1 #ifndef DALI_TOOLKIT_INTERNAL_BLOOM_VIEW_H
2 #define DALI_TOOLKIT_INTERNAL_BLOOM_VIEW_H
5 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <dali/public-api/actors/camera-actor.h>
23 #include <dali/public-api/render-tasks/render-task.h>
24 #include <dali/public-api/rendering/frame-buffer.h>
29 #include <dali-toolkit/devel-api/controls/bloom-view/bloom-view.h>
30 #include <dali-toolkit/devel-api/controls/gaussian-blur-view/gaussian-blur-view.h>
31 #include <dali-toolkit/public-api/controls/control-impl.h>
32 #include <dali-toolkit/public-api/controls/image-view/image-view.h>
43 * BloomEffect implementation class
45 class BloomView : public Control
49 * @copydoc Dali::Toolkit::BloomView::BloomView
54 * @copydoc Dali::Toolkit::BloomView::BloomView
56 BloomView(const unsigned int numSamples, const float blurBellCurveWidth, const Pixel::Format renderTargetPixelFormat, 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, const float downsampleWidthScale, const float downsampleHeightScale);
71 Property::Index GetBloomThresholdPropertyIndex() const
73 return mBloomThresholdPropertyIndex;
75 Property::Index GetBlurStrengthPropertyIndex() const
77 return mBlurStrengthPropertyIndex;
79 Property::Index GetBloomIntensityPropertyIndex() const
81 return mBloomIntensityPropertyIndex;
83 Property::Index GetBloomSaturationPropertyIndex() const
85 return mBloomSaturationPropertyIndex;
87 Property::Index GetImageIntensityPropertyIndex() const
89 return mImageIntensityPropertyIndex;
91 Property::Index GetImageSaturationPropertyIndex() const
93 return mImageSaturationPropertyIndex;
97 void OnInitialize() override;
98 void OnSizeSet(const Vector3& targetSize) override;
101 * @copydoc Control::OnChildAdd()
103 void OnChildAdd(Actor& child) override;
106 * @copydoc Control::OnChildRemove()
108 void OnChildRemove(Actor& child) override;
110 void AllocateResources();
111 void CreateRenderTasks();
112 void RemoveRenderTasks();
114 void SetupProperties();
116 /////////////////////////////////////////////////////////////
117 unsigned int mBlurNumSamples; // number of blur samples in each of horiz/vert directions
118 float mBlurBellCurveWidth; // constant used when calculating the gaussian weights
119 Pixel::Format mPixelFormat; // pixel format used by render targets
121 /////////////////////////////////////////////////////////////
122 // downsampling is used for the separated blur passes to get increased blur with the same number of samples and also to make rendering quicker
123 float mDownsampleWidthScale;
124 float mDownsampleHeightScale;
125 float mDownsampledWidth;
126 float mDownsampledHeight;
128 /////////////////////////////////////////////////////////////
129 // for checking if we need to reallocate render targets
133 /////////////////////////////////////////////////////////////
134 // 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
136 // for creating a subtree for the internal actors
139 /////////////////////////////////////////////////////////////
140 // for mapping offscreen renders to render target sizes
141 CameraActor mRenderFullSizeCamera;
142 CameraActor mRenderDownsampledCamera;
144 /////////////////////////////////////////////////////////////
145 // for rendering all user added children to offscreen target
146 FrameBuffer mRenderTargetForRenderingChildren;
147 RenderTask mRenderChildrenTask;
149 /////////////////////////////////////////////////////////////
150 // for extracting bright parts of image to an offscreen target
151 FrameBuffer mBloomExtractTarget; // for rendering bright parts of image into separate texture, also used as target for gaussian blur
152 RenderTask mBloomExtractTask;
153 Actor mBloomExtractActor;
155 /////////////////////////////////////////////////////////////
156 // for blurring extracted bloom
157 Dali::Toolkit::GaussianBlurView mGaussianBlurView;
159 /////////////////////////////////////////////////////////////
160 // for compositing bloom and children renders to offscreen target
161 RenderTask mCompositeTask;
163 Actor mCompositeActor;
165 /////////////////////////////////////////////////////////////
166 // for holding blurred result
167 FrameBuffer mOutputRenderTarget;
170 /////////////////////////////////////////////////////////////
171 // Properties for setting by user, e.g. by animations
172 Property::Index mBloomThresholdPropertyIndex;
173 Property::Index mBlurStrengthPropertyIndex;
174 Property::Index mBloomIntensityPropertyIndex;
175 Property::Index mBloomSaturationPropertyIndex;
176 Property::Index mImageIntensityPropertyIndex;
177 Property::Index mImageSaturationPropertyIndex;
182 // Undefined copy constructor.
183 BloomView(const BloomView&);
185 // Undefined assignment operator.
186 BloomView& operator=(const BloomView&);
189 } // namespace Internal
191 // Helpers for public-api forwarding methods
192 inline Toolkit::Internal::BloomView& GetImpl(Toolkit::BloomView& obj)
194 DALI_ASSERT_ALWAYS(obj);
195 Dali::RefObject& handle = obj.GetImplementation();
196 return static_cast<Toolkit::Internal::BloomView&>(handle);
199 inline const Toolkit::Internal::BloomView& GetImpl(const Toolkit::BloomView& obj)
201 DALI_ASSERT_ALWAYS(obj);
202 const Dali::RefObject& handle = obj.GetImplementation();
203 return static_cast<const Toolkit::Internal::BloomView&>(handle);
206 } // namespace Toolkit
210 #endif // DALI_TOOLKIT_INTERNAL_BLOOM_VIEW_H