1 #ifndef DALI_TOOLKIT_INTERNAL_SHADOW_VIEW_H
2 #define DALI_TOOLKIT_INTERNAL_SHADOW_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/animation/constraints.h>
24 #include <dali/public-api/object/property-map.h>
25 #include <dali/public-api/render-tasks/render-task.h>
30 #include <dali-toolkit/devel-api/controls/shadow-view/shadow-view.h>
31 #include <dali-toolkit/internal/filters/blur-two-pass-filter.h>
32 #include <dali-toolkit/public-api/controls/control-impl.h>
33 #include <dali-toolkit/public-api/controls/image-view/image-view.h>
44 * ShadowView implementation class
46 class ShadowView : public Control
50 * @copydoc Dali::Toolkit::ShadowView::ShadowView
55 * @copydoc Dali::Toolkit::ShadowView::ShadowView
57 ShadowView(float downsampleWidthScale, float downsampleHeightScale);
60 * @copydoc Dali::Toolkit::ShadowView::~ShadowView
62 virtual ~ShadowView();
65 * @copydoc Dali::Toolkit::ShadowView::New(float downsampleWidthScale, float downsampleHeightScale)
67 static Dali::Toolkit::ShadowView New(float downsampleWidthScale, float downsampleHeightScale);
70 * @copydoc Dali::Toolkit::ShadowView::SetShadowPlaneBackground(Actor shadowPlaneBackground)
72 void SetShadowPlaneBackground(Actor shadowPlaneBackground);
75 * @copydoc Dali::Toolkit::ShadowView::SetPointLight(Actor pointLight)
77 void SetPointLight(Actor pointLight);
80 * @copydoc Dali::Toolkit::ShadowView::SetPointLightFieldOfView(float fieldOfView)
82 void SetPointLightFieldOfView(float fieldOfView);
85 * @copydoc Dali::Toolkit::ShadowView::SetShadowColor(Vector4 color)
87 void SetShadowColor(Vector4 color);
90 * @copydoc Dali::Toolkit::ShadowView::Activate()
95 * @copydoc Dali::Toolkit::ShadowView::Deactivate()
100 * @copydoc Dali::Toolkit::ShadowView::GetBlurStrengthPropertyIndex()
102 Property::Index GetBlurStrengthPropertyIndex() const
104 return mBlurStrengthPropertyIndex;
108 * @copydoc Dali::Toolkit::ShadowView::GetShadowColorPropertyIndex()
110 Property::Index GetShadowColorPropertyIndex() const
112 return mShadowColorPropertyIndex;
115 void SetShaderConstants();
118 void OnInitialize() override;
121 * @copydoc Control::OnChildAdd()
123 void OnChildAdd(Actor& child) override;
126 * @copydoc Control::OnChildRemove()
128 void OnChildRemove(Actor& child) override;
131 * Constrain the camera actor to the position of the point light, pointing
132 * at the center of the shadow plane.
134 void ConstrainCamera();
136 void CreateRenderTasks();
137 void RemoveRenderTasks();
138 void CreateBlurFilter();
141 Actor mShadowPlane; // Shadow renders into this actor
142 Actor mShadowPlaneBg; // mShadowPlane renders directly in front of this actor
143 Actor mPointLight; // Shadow is cast from this point light
145 /////////////////////////////////////////////////////////////
146 FrameBuffer mSceneFromLightRenderTarget; // for rendering normal scene seen from light to texture instead of the screen
148 FrameBuffer mOutputFrameBuffer;
150 Actor mChildrenRoot; // Subtree for all user added child actors that should be rendered normally
151 Actor mBlurRootActor; // Root actor for blur filter processing
152 RenderTask mRenderSceneTask;
154 CameraActor mCameraActor; // Constrained to same position as mPointLight and pointing at mShadowPlane
156 Property::Map mShadowVisualMap;
157 BlurTwoPassFilter mBlurFilter;
159 Vector4 mCachedShadowColor; ///< Cached Shadow color.
160 Vector4 mCachedBackgroundColor; ///< Cached Shadow background color (same as shadow color but with alpha at 0.0)
162 /////////////////////////////////////////////////////////////
163 // Properties that can be animated
164 Property::Index mBlurStrengthPropertyIndex;
165 Property::Index mShadowColorPropertyIndex;
166 float mDownsampleWidthScale;
167 float mDownsampleHeightScale;
170 // Undefined copy constructor.
171 ShadowView(const ShadowView&);
173 // Undefined assignment operator.
174 ShadowView& operator=(const ShadowView&);
177 } // namespace Internal
179 // Helpers for public-api forwarding methods
180 inline Toolkit::Internal::ShadowView& GetImpl(Toolkit::ShadowView& obj)
182 DALI_ASSERT_ALWAYS(obj);
183 Dali::RefObject& handle = obj.GetImplementation();
184 return static_cast<Toolkit::Internal::ShadowView&>(handle);
187 inline const Toolkit::Internal::ShadowView& GetImpl(const Toolkit::ShadowView& obj)
189 DALI_ASSERT_ALWAYS(obj);
190 const Dali::RefObject& handle = obj.GetImplementation();
191 return static_cast<const Toolkit::Internal::ShadowView&>(handle);
194 } // namespace Toolkit
198 #endif // DALI_TOOLKIT_INTERNAL_SHADOW_VIEW_H