1 #ifndef DALI_TOOLKIT_INTERNAL_BUBBLE_EMITTER_IMPL_H
2 #define DALI_TOOLKIT_INTERNAL_BUBBLE_EMITTER_IMPL_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/devel-api/common/stage.h>
23 #include <dali/public-api/actors/camera-actor.h>
24 #include <dali/public-api/render-tasks/render-task.h>
25 #include <dali/public-api/rendering/frame-buffer.h>
26 #include <dali/public-api/rendering/geometry.h>
27 #include <dali/public-api/rendering/renderer.h>
28 #include <dali/public-api/rendering/sampler.h>
29 #include <dali/public-api/rendering/shader.h>
30 #include <dali/public-api/rendering/vertex-buffer.h>
33 #include <dali-toolkit/devel-api/controls/bubble-effect/bubble-emitter.h>
34 #include <dali-toolkit/public-api/controls/control-impl.h>
45 * BubbleEmitter implementation class.
47 class BubbleEmitter : public Control
56 * @copydoc Toolkit::BubbleEmitter::New
58 static Toolkit::BubbleEmitter New(const Vector2& winSize,
60 unsigned int maximumNumberOfBubble,
61 const Vector2& bubbleSizeRange);
64 * @copydoc Toolkit::BubbleEmitter::GetRootActor
69 * @copydoc Toolkit::BubbleEmitter::SetBackground
71 void SetBackground(Texture bgTexture, const Vector3& hsvDelta);
74 * @copydoc Toolkit::BubbleEmitter::SetShape
76 void SetBubbleShape(Texture shapeTexture);
79 * @copydoc Toolkit::BubbleEmiter::SetBubbleScale
81 void SetBubbleScale(float scale);
84 * @copydoc Toolkit::BubbleEmitter::SetBubbleDensity
86 void SetBubbleDensity(unsigned int density);
89 * @copydoc Toolkit::BubbleEmitter::EmitBubble
91 void EmitBubble(Animation& animation, const Vector2& emitPosition, const Vector2& direction, const Vector2& displacement);
94 * @copydoc Toolkit::BubbleEmitter::Restore
100 * Construct a new BubbleEmitter object.
101 * @param[in] movementArea The size of the bubble moving area
102 * @param[in] shapeTexture The alpha channnel of this texture defines the bubble shape.
103 * @param[in] maximumNumberOfBubble The maximum number of bubble needed.
104 * @param[in] bubbleSizeRange The size range of the bubbles; x component is the minimal size, and y component is the maximum size.
106 BubbleEmitter(const Vector2& movementArea,
107 Texture shapeTexture,
108 unsigned int maximumNumberOfBubble,
109 const Vector2& bubbleSizeRange);
112 * This method is called after the CubeTransitionEffect has been initialized.
113 * The meshActors and BubbleEffects are created here.
118 * Create the geometry of a mesh.
119 * @param[in] numOfPatch The triangle number in the mesh is 2*numOfPatch; two triangles for each bubble.
120 * @return The mesh geometry.
122 Geometry CreateGeometry(unsigned int numOfPatch);
125 * Callback function of the finished signal of off-screen render task.
126 * @param[in] source The render task used to create the color adjusted background texture.
128 void OnRenderFinished(RenderTask& source);
131 * Callback function from Stage to tell us if the context has been regained.
133 void OnContextRegained();
136 * Set the uniform values to the shader effect to emit a bubble
137 * @param[in] bubbleRenderer The BubbleRenderer
138 * @param[in] curUniform The index of the uniform array in the shader
139 * @param[in] emitPosition The start position of the bubble movement.
140 * @param[in] direction The direction used to constrain the bubble to move in an adjacent direction around it.
141 * @param[in] displacement The displacement used to bound the moving distance of the bubble.
143 void SetBubbleParameter(BubbleRenderer& bubbleRenderer, unsigned int curUniform, const Vector2& emitPosition, const Vector2& direction, const Vector2& displacement);
146 Actor mBubbleRoot; ///<The bubble root actor. Need to add it to stage to get the bubbles rendered.
147 Texture mShapeTexture; ///< The alpha channnel of this texture defines the bubble shape.
148 Texture mBackgroundTexture; ///< The original background texture
149 Texture mEffectTexture; ///< Texture which stores the adjusted color of the background image.The bubbles pick color from this image.
150 FrameBuffer mFrameBuffer; ///< FrameBuffer used for offscreen rendering
151 CameraActor mCameraActor; ///< The render task views the scene from the perspective of this actor.
153 Geometry mMeshGeometry; ///< The mesh geometry which contains the vertices and indices data
154 TextureSet mTextureSet; ///< The texture set which controls the bubble display
155 std::vector<BubbleRenderer> mBubbleRenderers; ///< The BubbleRenderer vector, its size is mNumShader.
157 Vector2 mMovementArea; ///< The size of the bubble moving area, usually the same size as the background.
158 Vector2 mBubbleSizeRange; ///< The size range of the bubbles; x component is the low bound, and y component is the up bound.
159 Vector3 mHSVDelta; ///< The HSV difference used to adjust the background image color.
161 unsigned int mNumBubblePerRenderer; ///< How many bubbles for each BubbleRenderer.
162 unsigned int mNumRenderer; ///< How many BubbleRenderers are used.
163 unsigned int mDensity; ///< How many bubbles will emit at each time, they are controlled by same uniforms in the shader.
164 unsigned int mTotalNumOfBubble; ///< mNumBubblePerShader*mNumShader.
165 unsigned int mCurrentBubble; ///< Keep track of the index for the newly emitted bubble
166 unsigned int mRandomSeed; ///< Seed to generate random number.
168 bool mRenderTaskRunning; ///< If the background render task is currently running
171 } // namespace Internal
173 // Helpers for public-api forwarding methods
174 inline Internal::BubbleEmitter& GetImpl(Dali::Toolkit::BubbleEmitter& obj)
176 DALI_ASSERT_ALWAYS(obj && "BubbleEmitter handle is empty");
177 Dali::RefObject& handle = obj.GetImplementation();
178 return static_cast<Toolkit::Internal::BubbleEmitter&>(handle);
181 inline const Internal::BubbleEmitter& GetImpl(const Dali::Toolkit::BubbleEmitter& obj)
183 DALI_ASSERT_ALWAYS(obj && "BubbleEmitter handle is empty");
184 const Dali::RefObject& handle = obj.GetImplementation();
185 return static_cast<const Toolkit::Internal::BubbleEmitter&>(handle);
188 } // namespace Toolkit
192 #endif // DALI_TOOLKIT_INTERNAL_BUBBLE_EMITTER_IMPL_H