Add particle data layout debugger tab
This commit is contained in:
@@ -519,4 +519,39 @@ bool ParticleEmitter::HasShaderCode() const
|
||||
return false;
|
||||
}
|
||||
|
||||
Array<ParticleEmitter::Attribute> ParticleEmitter::GetLayout() const
|
||||
{
|
||||
Array<Attribute> result;
|
||||
ScopeLock lock(Locker);
|
||||
result.Resize(Graph.Layout.Attributes.Count());
|
||||
for (int32 i = 0; i < result.Count(); i++)
|
||||
{
|
||||
auto& dst = result[i];
|
||||
const auto& src = Graph.Layout.Attributes[i];
|
||||
dst.Name = src.Name;
|
||||
switch (src.ValueType)
|
||||
{
|
||||
case ParticleAttribute::ValueTypes::Float:
|
||||
dst.Format = PixelFormat::R32_Float;
|
||||
break;
|
||||
case ParticleAttribute::ValueTypes::Float2:
|
||||
dst.Format = PixelFormat::R32G32_Float;
|
||||
break;
|
||||
case ParticleAttribute::ValueTypes::Float3:
|
||||
dst.Format = PixelFormat::R32G32B32_Float;
|
||||
break;
|
||||
case ParticleAttribute::ValueTypes::Float4:
|
||||
dst.Format = PixelFormat::R32G32B32A32_Float;
|
||||
break;
|
||||
case ParticleAttribute::ValueTypes::Int:
|
||||
dst.Format = PixelFormat::R32_SInt;
|
||||
break;
|
||||
case ParticleAttribute::ValueTypes::Uint:
|
||||
dst.Format = PixelFormat::R32_UInt;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -177,10 +177,16 @@ public:
|
||||
void GetReferences(Array<Guid>& assets, Array<String>& files) const override;
|
||||
bool Save(const StringView& path = StringView::Empty) override;
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the particle emitter has valid shader code present.
|
||||
/// </summary>
|
||||
API_PROPERTY() bool HasShaderCode() const;
|
||||
API_STRUCT(Internal) struct Attribute
|
||||
{
|
||||
DECLARE_SCRIPTING_TYPE_MINIMAL(Attribute);
|
||||
API_FIELD() PixelFormat Format;
|
||||
API_FIELD() String Name;
|
||||
};
|
||||
|
||||
private:
|
||||
API_PROPERTY(Internal) bool HasShaderCode() const;
|
||||
API_PROPERTY(Internal) Array<Attribute> GetLayout() const;
|
||||
#endif
|
||||
|
||||
protected:
|
||||
|
||||
@@ -6,6 +6,89 @@
|
||||
#include "Engine/Graphics/GPUDevice.h"
|
||||
#include "Engine/Graphics/DynamicBuffer.h"
|
||||
|
||||
int32 ParticleAttribute::GetSize() const
|
||||
{
|
||||
switch (ValueType)
|
||||
{
|
||||
case ValueTypes::Float2:
|
||||
return 8;
|
||||
case ValueTypes::Float3:
|
||||
return 12;
|
||||
case ValueTypes::Float4:
|
||||
return 16;
|
||||
case ValueTypes::Float:
|
||||
case ValueTypes::Int:
|
||||
case ValueTypes::Uint:
|
||||
return 4;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void ParticleLayout::Clear()
|
||||
{
|
||||
Size = 0;
|
||||
Attributes.Clear();
|
||||
}
|
||||
|
||||
void ParticleLayout::UpdateLayout()
|
||||
{
|
||||
Size = 0;
|
||||
for (int32 i = 0; i < Attributes.Count(); i++)
|
||||
{
|
||||
Attributes[i].Offset = Size;
|
||||
Size += Attributes[i].GetSize();
|
||||
}
|
||||
}
|
||||
|
||||
int32 ParticleLayout::FindAttribute(const StringView& name) const
|
||||
{
|
||||
for (int32 i = 0; i < Attributes.Count(); i++)
|
||||
{
|
||||
if (name == Attributes[i].Name)
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32 ParticleLayout::FindAttribute(const StringView& name, ParticleAttribute::ValueTypes valueType) const
|
||||
{
|
||||
for (int32 i = 0; i < Attributes.Count(); i++)
|
||||
{
|
||||
if (Attributes[i].ValueType == valueType && name == Attributes[i].Name)
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32 ParticleLayout::FindAttributeOffset(const StringView& name, int32 fallbackValue) const
|
||||
{
|
||||
for (int32 i = 0; i < Attributes.Count(); i++)
|
||||
{
|
||||
if (name == Attributes[i].Name)
|
||||
return Attributes[i].Offset;
|
||||
}
|
||||
return fallbackValue;
|
||||
}
|
||||
|
||||
int32 ParticleLayout::FindAttributeOffset(const StringView& name, ParticleAttribute::ValueTypes valueType, int32 fallbackValue) const
|
||||
{
|
||||
for (int32 i = 0; i < Attributes.Count(); i++)
|
||||
{
|
||||
if (Attributes[i].ValueType == valueType && name == Attributes[i].Name)
|
||||
return Attributes[i].Offset;
|
||||
}
|
||||
return fallbackValue;
|
||||
}
|
||||
|
||||
int32 ParticleLayout::AddAttribute(const StringView& name, ParticleAttribute::ValueTypes valueType)
|
||||
{
|
||||
auto& a = Attributes.AddOne();
|
||||
a.Name = String(*name, name.Length());
|
||||
a.ValueType = valueType;
|
||||
return Attributes.Count() - 1;
|
||||
}
|
||||
|
||||
ParticleBuffer::ParticleBuffer()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -52,25 +52,7 @@ struct ParticleAttribute
|
||||
/// <summary>
|
||||
/// Gets the size of the attribute (in bytes).
|
||||
/// </summary>
|
||||
/// <returns>The size (in bytes).</returns>
|
||||
int32 GetSize() const
|
||||
{
|
||||
switch (ValueType)
|
||||
{
|
||||
case ValueTypes::Float2:
|
||||
return 8;
|
||||
case ValueTypes::Float3:
|
||||
return 12;
|
||||
case ValueTypes::Float4:
|
||||
return 16;
|
||||
case ValueTypes::Float:
|
||||
case ValueTypes::Int:
|
||||
case ValueTypes::Uint:
|
||||
return 4;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
int32 GetSize() const;
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
@@ -93,41 +75,19 @@ public:
|
||||
/// <summary>
|
||||
/// Clears the layout data.
|
||||
/// </summary>
|
||||
void Clear()
|
||||
{
|
||||
Size = 0;
|
||||
Attributes.Clear();
|
||||
}
|
||||
void Clear();
|
||||
|
||||
/// <summary>
|
||||
/// Updates the attributes layout (calculates offset) and updates the total size of the layout.
|
||||
/// </summary>
|
||||
void UpdateLayout()
|
||||
{
|
||||
Size = 0;
|
||||
for (int32 i = 0; i < Attributes.Count(); i++)
|
||||
{
|
||||
Attributes[i].Offset = Size;
|
||||
Size += Attributes[i].GetSize();
|
||||
}
|
||||
}
|
||||
void UpdateLayout();
|
||||
|
||||
/// <summary>
|
||||
/// Finds the attribute by the name.
|
||||
/// </summary>
|
||||
/// <param name="name">The name.</param>
|
||||
/// <returns>The attribute index or -1 if cannot find it.</returns>
|
||||
int32 FindAttribute(const StringView& name) const
|
||||
{
|
||||
for (int32 i = 0; i < Attributes.Count(); i++)
|
||||
{
|
||||
if (name == Attributes[i].Name)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
int32 FindAttribute(const StringView& name) const;
|
||||
|
||||
/// <summary>
|
||||
/// Finds the attribute by the name and type.
|
||||
@@ -135,17 +95,7 @@ public:
|
||||
/// <param name="name">The name.</param>
|
||||
/// <param name="valueType">The type.</param>
|
||||
/// <returns>The attribute index or -1 if cannot find it.</returns>
|
||||
int32 FindAttribute(const StringView& name, ParticleAttribute::ValueTypes valueType) const
|
||||
{
|
||||
for (int32 i = 0; i < Attributes.Count(); i++)
|
||||
{
|
||||
if (Attributes[i].ValueType == valueType && name == Attributes[i].Name)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
int32 FindAttribute(const StringView& name, ParticleAttribute::ValueTypes valueType) const;
|
||||
|
||||
/// <summary>
|
||||
/// Finds the attribute offset by the name.
|
||||
@@ -153,17 +103,7 @@ public:
|
||||
/// <param name="name">The name.</param>
|
||||
/// <param name="fallbackValue">The fallback value to return if attribute is missing.</param>
|
||||
/// <returns>The attribute offset or fallback value if cannot find it.</returns>
|
||||
int32 FindAttributeOffset(const StringView& name, int32 fallbackValue = 0) const
|
||||
{
|
||||
for (int32 i = 0; i < Attributes.Count(); i++)
|
||||
{
|
||||
if (name == Attributes[i].Name)
|
||||
{
|
||||
return Attributes[i].Offset;
|
||||
}
|
||||
}
|
||||
return fallbackValue;
|
||||
}
|
||||
int32 FindAttributeOffset(const StringView& name, int32 fallbackValue = 0) const;
|
||||
|
||||
/// <summary>
|
||||
/// Finds the attribute offset by the name.
|
||||
@@ -172,17 +112,7 @@ public:
|
||||
/// <param name="valueType">The type.</param>
|
||||
/// <param name="fallbackValue">The fallback value to return if attribute is missing.</param>
|
||||
/// <returns>The attribute offset or fallback value if cannot find it.</returns>
|
||||
int32 FindAttributeOffset(const StringView& name, ParticleAttribute::ValueTypes valueType, int32 fallbackValue = 0) const
|
||||
{
|
||||
for (int32 i = 0; i < Attributes.Count(); i++)
|
||||
{
|
||||
if (Attributes[i].ValueType == valueType && name == Attributes[i].Name)
|
||||
{
|
||||
return Attributes[i].Offset;
|
||||
}
|
||||
}
|
||||
return fallbackValue;
|
||||
}
|
||||
int32 FindAttributeOffset(const StringView& name, ParticleAttribute::ValueTypes valueType, int32 fallbackValue = 0) const;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the attribute offset by the attribute index.
|
||||
@@ -201,13 +131,7 @@ public:
|
||||
/// <param name="name">The name.</param>
|
||||
/// <param name="valueType">The value type.</param>
|
||||
/// <returns>The attribute index or -1 if cannot find it.</returns>
|
||||
int32 AddAttribute(const StringView& name, ParticleAttribute::ValueTypes valueType)
|
||||
{
|
||||
auto& a = Attributes.AddOne();
|
||||
a.Name = String(*name, name.Length());
|
||||
a.ValueType = valueType;
|
||||
return Attributes.Count() - 1;
|
||||
}
|
||||
int32 AddAttribute(const StringView& name, ParticleAttribute::ValueTypes valueType);
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user