[dali_2.3.21] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / particle-system / particle-renderer-impl.h
1 #ifndef DALI_TOOLKIT_PARTICLE_SYSTEM_INTERNAL_PARTICLE_RENDERER_H
2 #define DALI_TOOLKIT_PARTICLE_SYSTEM_INTERNAL_PARTICLE_RENDERER_H
3 /*
4  * Copyright (c) 2023 Samsung Electronics Co., Ltd.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19
20 #include <memory>
21
22 #include <dali-toolkit/public-api/particle-system/particle-emitter.h>
23 #include <dali-toolkit/public-api/particle-system/particle-renderer.h>
24 #include <dali-toolkit/public-api/particle-system/particle.h>
25
26 #include <dali/public-api/actors/actor.h>
27 #include <dali/public-api/object/base-object.h>
28 #include <dali/public-api/rendering/renderer.h>
29 #include <dali/public-api/rendering/vertex-buffer.h>
30 #include <dali/public-api/signals/render-callback.h>
31
32 namespace Dali::Graphics
33 {
34 class Controller;
35 class Shader;
36 } // namespace Dali::Graphics
37
38 namespace Dali::Toolkit::ParticleSystem
39 {
40 class ParticleEmitter;
41 }
42
43 namespace Dali::Toolkit::ParticleSystem::Internal
44 {
45 class ParticleEmitter;
46 class ParticleRenderer;
47 class ParticleList;
48
49 class ParticleRenderer : public Dali::BaseObject
50 {
51 public:
52   ParticleRenderer();
53
54   /**
55    * Create shader
56    */
57   void CreateShader();
58
59   void SetTexture(const Dali::Texture& texture);
60
61   void SetBlendingMode(BlendingMode blendingMode);
62
63   BlendingMode GetBlendingMode() const;
64
65   bool Initialize();
66
67   void PrepareToDie();
68
69   void SetEmitter(ParticleSystem::Internal::ParticleEmitter* emitter);
70
71   void UpdateParticlesTask(Internal::ParticleList& list,
72                            uint32_t                particleStartIndex,
73                            uint32_t                particleCount,
74                            uint8_t*                dst);
75
76   [[nodiscard]] Renderer GetRenderer() const;
77
78   uint32_t OnStreamBufferUpdate(void* data, size_t size);
79
80   bool mUsingStreamDivisor{true}; ///< If attribute divisor is supported, it's going to be used
81
82   Internal::ParticleEmitter* mEmitter{nullptr}; ///< Emitter implementation that uses the renderer
83
84   Dali::Texture      mTexture;
85   Dali::TextureSet   mTextureSet;
86   Dali::Renderer     mRenderer;
87   Dali::Shader       mShader;
88   Dali::Geometry     mGeometry;
89   Dali::VertexBuffer mVertexBuffer;
90   Dali::VertexBuffer mStreamBuffer;
91   BlendingMode       mBlendingMode{BlendingMode::DEFAULT};
92
93   std::unique_ptr<Dali::VertexBufferUpdateCallback> mStreamBufferUpdateCallback;
94
95   bool mInitialized{false};
96 };
97 } // namespace Dali::Toolkit::ParticleSystem::Internal
98 namespace Dali
99 {
100 inline Toolkit::ParticleSystem::Internal::ParticleRenderer& GetImplementation(Toolkit::ParticleSystem::ParticleRenderer& source)
101 {
102   DALI_ASSERT_ALWAYS(source && "ParticleRenderer handle is empty");
103
104   BaseObject& handle = source.GetBaseObject();
105
106   return static_cast<Toolkit::ParticleSystem::Internal::ParticleRenderer&>(handle);
107 }
108
109 inline const Toolkit::ParticleSystem::Internal::ParticleRenderer& GetImplementation(const Toolkit::ParticleSystem::ParticleRenderer& source)
110 {
111   DALI_ASSERT_ALWAYS(source && "ParticleRenderer handle is empty");
112
113   const BaseObject& handle = source.GetBaseObject();
114
115   return static_cast<const Toolkit::ParticleSystem::Internal::ParticleRenderer&>(handle);
116 }
117
118 } // namespace Dali
119
120 #endif // DALI_TOOLKIT_PARTICLE_SYSTEM_INTERNAL_PARTICLE_RENDERER_H