Particle System 70/293770/3
authorAdam Bialogonski <adam.b@samsung.com>
Fri, 2 Jun 2023 14:01:42 +0000 (15:01 +0100)
committerAdam Bialogonski <adam.b@samsung.com>
Fri, 2 Jun 2023 18:43:16 +0000 (19:43 +0100)
- added base lifetime stream
- fixed default particle color
- fixed freelist management

Change-Id: I7ef1ef03200420b3db4e9877bbdeeb1e876ba101

dali-toolkit/internal/particle-system/particle-impl.h
dali-toolkit/internal/particle-system/particle-list-impl.cpp
dali-toolkit/internal/particle-system/particle-renderer-impl.cpp
dali-toolkit/public-api/particle-system/particle-emitter.cpp
dali-toolkit/public-api/particle-system/particle-types.h

index 08aea33..db46db4 100644 (file)
@@ -41,7 +41,7 @@ public:
 
   void* GetByIndex(uint32_t streamIndex);
 
-  uint32_t GetIndex() const;
+  [[nodiscard]] uint32_t GetIndex() const;
 
 private:
   Internal::ParticleList& mOwnerList;
index 550cbd8..7371c34 100644 (file)
@@ -23,7 +23,6 @@
 
 namespace Dali::Toolkit::ParticleSystem::Internal
 {
-
 template<>
 ParticleStream::StreamDataType StreamDataTypeWrapper<Vector3>::GetType()
 {
@@ -86,9 +85,14 @@ ParticleList::ParticleList(uint32_t capacity, ParticleSystem::ParticleList::Part
   }
   if(streamFlags & ParticleStream::LIFETIME_STREAM_BIT)
   {
-    AddStream(0.0f, "aStreamLifetime", false);
+    AddStream(0.0f, "aStreamLifetime", true);
     mBuiltInStreamMap[uint32_t(ParticleStream::LIFETIME_STREAM_BIT)] = mDataStreams.size() - 1;
   }
+  if(streamFlags & ParticleStream::LIFETIME_STREAM_BIT)
+  {
+    AddStream(0.0f, "aStreamLifetimeBase", true);
+    mBuiltInStreamMap[uint32_t(ParticleStream::LIFETIME_BASE_STREAM_BIT)] = mDataStreams.size() - 1;
+  }
 
   // create free chain
   mFreeChain.resize(capacity);
@@ -187,6 +191,9 @@ ParticleSystem::Particle ParticleList::NewParticle(float lifetime)
 
     particle.Get<float>(ParticleStream::LIFETIME_STREAM_BIT) = lifetime;
 
+    // Store initial lifetime
+    particle.Get<float>(ParticleStream::LIFETIME_BASE_STREAM_BIT) = lifetime;
+
     return mParticles.back();
   }
   return {nullptr};
@@ -211,11 +218,11 @@ void ParticleList::ReleaseParticle(uint32_t particleIndex)
 
   // Point at this slot of memory as next free slot
   auto& p = *it;
-  if(mFreeIndex)
+  if(mFreeIndex > -1)
   {
     mFreeChain[p.GetIndex()] = mFreeIndex;
-    mFreeIndex               = p.GetIndex();
   }
+  mFreeIndex = p.GetIndex();
 
   // Remove particle from the list
   mParticles.erase(it);
index b86c434..a22ffc2 100644 (file)
@@ -224,17 +224,16 @@ void ParticleRenderer::CreateShader()
   {
     mTexture         = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, 2u, 2u);
     auto* pixelArray = new uint32_t[4]{
-      0xFF0000FF, 0xFF0000FF, 0xFF0000FF, 0xFF0000FF};
+      0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF};
 
     auto pixelData = PixelData::New(reinterpret_cast<uint8_t*>(pixelArray), 16, 2, 2, Pixel::Format::RGBA8888, PixelData::DELETE_ARRAY);
     mTexture.Upload(pixelData);
   }
-
   mTextureSet = TextureSet::New();
   mTextureSet.SetTexture(0, mTexture);
-  // mTextureSet.SetSampler(0, Sampler());
-
   mRenderer.SetTextures(mTextureSet);
+  mTextureSet.SetSampler(0, Sampler());
+
 
   // Attach renderer to the parent actor
   mEmitter->GetActor().AddRenderer(mRenderer);
@@ -305,7 +304,7 @@ uint32_t ParticleRenderer::OnStreamBufferUpdate(void* streamData, size_t size)
   else
   {
     // Partial to handle
-    [[maybe_unused]] auto partialSize = (particleCount / workerCount);
+    auto partialSize = (particleCount / workerCount);
 
     struct UpdateTask
     {
@@ -348,8 +347,7 @@ uint32_t ParticleRenderer::OnStreamBufferUpdate(void* streamData, size_t size)
       }
 
       tasks.emplace_back(*this, list, index, count, streamData);
-      taskQueue.emplace_back([&t = tasks.back()](uint32_t threadId)
-                             { t.Update(); });
+      taskQueue.emplace_back([&t = tasks.back()](uint32_t threadId) { t.Update(); });
     }
 
     // Execute worker tasks
index 6a3e746..c854e23 100644 (file)
 #include <dali-toolkit/public-api/particle-system/particle-emitter.h>
 
 // INTERNAL INCLUDES
-#include <dali-toolkit/public-api/particle-system/particle-source.h>
 #include <dali-toolkit/internal/particle-system/particle-emitter-impl.h>
+#include <dali-toolkit/public-api/particle-system/particle-source.h>
 
 // EXTERNAL INCLUDES
 #include <utility>
 
 namespace Dali::Toolkit::ParticleSystem
 {
-
 ParticleEmitter ParticleEmitter::New()
 {
   return {new Dali::Toolkit::ParticleSystem::Internal::ParticleEmitter()};
index 383865d..41622a6 100644 (file)
@@ -29,16 +29,17 @@ using ParticleStreamTypeFlagBit = uint32_t;
 
 namespace ParticleStream DALI_TOOLKIT_API
 {
-constexpr ParticleStreamTypeFlagBit POSITION_STREAM_BIT = 1 << 0; ///< 3D Position stream
-constexpr ParticleStreamTypeFlagBit ROTATION_STREAM_BIT = 1 << 1; ///< 3D Rotation stream
-constexpr ParticleStreamTypeFlagBit SCALE_STREAM_BIT    = 1 << 2; ///< 3D Scale stream
-constexpr ParticleStreamTypeFlagBit SIZE_STREAM_BIT     = 1 << 3;
-constexpr ParticleStreamTypeFlagBit COLOR_STREAM_BIT    = 1 << 4;
-constexpr ParticleStreamTypeFlagBit OPACITY_STREAM_BIT  = 1 << 5;
-constexpr ParticleStreamTypeFlagBit VELOCITY_STREAM_BIT = 1 << 6;
-constexpr ParticleStreamTypeFlagBit LIFETIME_STREAM_BIT = 1 << 7;
-constexpr ParticleStreamTypeFlagBit ALL_STREAMS         = 255;
-constexpr ParticleStreamTypeFlagBit DEFAULT_STREAMS     = 255; ///< Default streams
+constexpr ParticleStreamTypeFlagBit POSITION_STREAM_BIT      = 1 << 0; ///< 3D Position stream
+constexpr ParticleStreamTypeFlagBit ROTATION_STREAM_BIT      = 1 << 1; ///< 3D Rotation stream
+constexpr ParticleStreamTypeFlagBit SCALE_STREAM_BIT         = 1 << 2; ///< 3D Scale stream
+constexpr ParticleStreamTypeFlagBit SIZE_STREAM_BIT          = 1 << 3;
+constexpr ParticleStreamTypeFlagBit COLOR_STREAM_BIT         = 1 << 4;
+constexpr ParticleStreamTypeFlagBit OPACITY_STREAM_BIT       = 1 << 5;
+constexpr ParticleStreamTypeFlagBit VELOCITY_STREAM_BIT      = 1 << 6;
+constexpr ParticleStreamTypeFlagBit LIFETIME_STREAM_BIT      = 1 << 7;
+constexpr ParticleStreamTypeFlagBit LIFETIME_BASE_STREAM_BIT = 1 << 8;
+constexpr ParticleStreamTypeFlagBit ALL_STREAMS              = 255;
+constexpr ParticleStreamTypeFlagBit DEFAULT_STREAMS          = 255; ///< Default streams
 
 /**
  * Stream data types
@@ -55,6 +56,6 @@ enum class StreamDataType
   INT4
 };
 
-} // namespace ParticleStream DALI_TOOLKIT_API
+} // namespace ParticleStream
 } // namespace Dali::Toolkit::ParticleSystem
 #endif // DALI_TOOLKIT_PARTICLE_SYSTEM_PARTICLE_TYPES_H
\ No newline at end of file