-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Separate different vertexbuffers and indexbuffers into different Components.
- Loading branch information
Showing
10 changed files
with
192 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
Engine/Source/Runtime/ECWorld/ParticleRibbonComponent.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
#include "Log/Log.h" | ||
#include "ParticleRibbonComponent.h" | ||
#include "Rendering/Utility/VertexLayoutUtility.h" | ||
#include "Utilities/MeshUtils.hpp" | ||
|
||
#include <limits> | ||
|
||
namespace engine | ||
{ | ||
void ParticleRibbonComponent::Build() | ||
{ | ||
PaddingRibbonVertexBuffer(); | ||
PaddingRibbonIndexBuffer(); | ||
} | ||
|
||
void ParticleRibbonComponent::PaddingRibbonVertexBuffer() | ||
{ | ||
//vertexbuffer | ||
constexpr int meshVertexCount = Particle::GetMeshVertexCount<ParticleType::Ribbon>(); | ||
//75 is from particle's MaxCount,There only padding once. | ||
const int MAX_VERTEX_COUNT = 75 * meshVertexCount; | ||
size_t vertexCount = MAX_VERTEX_COUNT; | ||
uint32_t csVertexCount = MAX_VERTEX_COUNT; | ||
//prePos Vertex format/layout | ||
cd::VertexFormat m_pRibbonPrePosVertexFormat; | ||
m_pRibbonPrePosVertexFormat.AddVertexAttributeLayout(cd::VertexAttributeType::Position, cd::GetAttributeValueType<cd::Point::ValueType>(), cd::Point::Size); | ||
m_pRibbonPrePosVertexFormat.AddVertexAttributeLayout(cd::VertexAttributeType::BoneWeight, cd::AttributeValueType::Float, 1U); | ||
bgfx::VertexLayout prePosLayout; | ||
VertexLayoutUtility::CreateVertexLayout(prePosLayout, m_pRibbonPrePosVertexFormat.GetVertexAttributeLayouts()); | ||
//remain Vertex format/layout | ||
cd::VertexFormat m_pRibbonRemainVertexFormat; | ||
m_pRibbonRemainVertexFormat.AddVertexAttributeLayout(cd::VertexAttributeType::Color, cd::GetAttributeValueType<cd::Color::ValueType>(), cd::Color::Size); | ||
m_pRibbonRemainVertexFormat.AddVertexAttributeLayout(cd::VertexAttributeType::UV, cd::GetAttributeValueType<cd::UV::ValueType>(), cd::UV::Size); | ||
bgfx::VertexLayout color_UV_Layout; | ||
VertexLayoutUtility::CreateVertexLayout(color_UV_Layout, m_pRibbonRemainVertexFormat.GetVertexAttributeLayouts()); | ||
|
||
const uint32_t remainVertexFormatStride = m_pRibbonRemainVertexFormat.GetStride(); | ||
|
||
m_ribbonParticleRemainVertexBuffer.resize(vertexCount * remainVertexFormatStride); | ||
|
||
uint32_t currentRemainDataSize = 0U; | ||
auto currentRemainDataPtr = m_ribbonParticleRemainVertexBuffer.data(); | ||
|
||
std::vector<VertexData> vertexDataBuffer; | ||
vertexDataBuffer.resize(MAX_VERTEX_COUNT); | ||
// pos color uv | ||
// only a picture now | ||
for (int i = 0; i < MAX_VERTEX_COUNT; i += meshVertexCount) | ||
{ | ||
vertexDataBuffer[i] = { cd::Vec3f(0.0f,1.0f,0.0f),cd::Vec4f(1.0f,1.0f,1.0f,1.0f),cd::Vec2f(0.5f,0.5f) }; | ||
vertexDataBuffer[i + 1] = { cd::Vec3f(0.0f,-1.0f,0.0f),cd::Vec4f(1.0f,1.0f,1.0f,1.0f),cd::Vec2f(0.5f,0.5f) }; | ||
} | ||
|
||
for (int i = 0; i < MAX_VERTEX_COUNT; ++i) | ||
{ | ||
std::memcpy(¤tRemainDataPtr[currentRemainDataSize], &vertexDataBuffer[i].color, sizeof(cd::Color)); | ||
currentRemainDataSize += sizeof(cd::Color); | ||
std::memcpy(¤tRemainDataPtr[currentRemainDataSize], &vertexDataBuffer[i].uv, sizeof(cd::UV)); | ||
currentRemainDataSize += sizeof(cd::UV); | ||
} | ||
m_ribbonParticlePrePosVertexBufferHandle = bgfx::createDynamicVertexBuffer(csVertexCount, prePosLayout, BGFX_BUFFER_COMPUTE_READ_WRITE).idx; | ||
const bgfx::Memory* pRibbonParticleRemainVBRef = bgfx::makeRef(m_ribbonParticleRemainVertexBuffer.data(), static_cast<uint32_t>(m_ribbonParticleRemainVertexBuffer.size())); | ||
m_ribbonParticleRemainVertexBufferHandle = bgfx::createVertexBuffer(pRibbonParticleRemainVBRef, color_UV_Layout).idx; | ||
} | ||
|
||
void ParticleRibbonComponent::PaddingRibbonIndexBuffer() | ||
{ | ||
constexpr int meshVertexCount = Particle::GetMeshVertexCount<ParticleType::Ribbon>();; | ||
const bool useU16Index = meshVertexCount <= static_cast<uint32_t>(std::numeric_limits<uint16_t>::max()) + 1U; | ||
const uint32_t indexTypeSize = useU16Index ? sizeof(uint16_t) : sizeof(uint32_t); | ||
//TODO: 75 is from particle's MaxCount There only padding once. | ||
const int MAX_VERTEX_COUNT = (75 - 1) * meshVertexCount; | ||
int indexCountForOneRibbon = 6; | ||
const uint32_t indicesCount = MAX_VERTEX_COUNT / meshVertexCount * indexCountForOneRibbon; | ||
m_ribbonParticleIndexBuffer.resize(indicesCount * indexTypeSize); | ||
/// | ||
/* size_t indexTypeSize = sizeof(uint16_t); | ||
m_particleIndexBuffer.resize(m_particleSystem.GetMaxCount() / 4 * 6 * indexTyp | ||
eSize);*/ | ||
uint32_t currentDataSize = 0U; | ||
auto currentDataPtr = m_ribbonParticleIndexBuffer.data(); | ||
|
||
std::vector<uint16_t> indexes; | ||
|
||
for (uint16_t i = 0; i < MAX_VERTEX_COUNT; i += meshVertexCount) | ||
{ | ||
uint16_t vertexIndex = static_cast<uint16_t>(i); | ||
indexes.push_back(vertexIndex); | ||
indexes.push_back(vertexIndex + 1); | ||
indexes.push_back(vertexIndex + 2); | ||
|
||
indexes.push_back(vertexIndex + 2); | ||
indexes.push_back(vertexIndex + 1); | ||
indexes.push_back(vertexIndex + 3); | ||
} | ||
|
||
for (const auto& index : indexes) | ||
{ | ||
std::memcpy(¤tDataPtr[currentDataSize], &index, indexTypeSize); | ||
currentDataSize += static_cast<uint32_t>(indexTypeSize); | ||
} | ||
m_ribbonParticleIndexBufferHandle = bgfx::createIndexBuffer(bgfx::makeRef(m_ribbonParticleIndexBuffer.data(), static_cast<uint32_t>(m_ribbonParticleIndexBuffer.size())), 0U).idx; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#include "Base/Template.h" | ||
#include "Core/StringCrc.h" | ||
#include "Math/Vector.hpp" | ||
#include "Math/Transform.hpp" | ||
#include "Material/ShaderSchema.h" | ||
#include "Material/MaterialType.h" | ||
#include "ParticleSystem/ParticlePool.h" | ||
#include "Scene/Mesh.h" | ||
#include "Scene/Types.h" | ||
#include "Scene/VertexFormat.h" | ||
|
||
namespace engine | ||
{ | ||
|
||
class ParticleRibbonComponent final | ||
{ | ||
public: | ||
static constexpr StringCrc GetClassName() | ||
{ | ||
constexpr StringCrc className("ParticleRibbonComponent"); | ||
return className; | ||
} | ||
|
||
ParticleRibbonComponent() = default; | ||
ParticleRibbonComponent(const ParticleRibbonComponent&) = default; | ||
ParticleRibbonComponent& operator=(const ParticleRibbonComponent&) = default; | ||
ParticleRibbonComponent(ParticleRibbonComponent&&) = default; | ||
ParticleRibbonComponent& operator=(ParticleRibbonComponent&&) = default; | ||
~ParticleRibbonComponent() = default; | ||
|
||
void PaddingRibbonVertexBuffer(); | ||
void PaddingRibbonIndexBuffer(); | ||
|
||
void Build(); | ||
|
||
uint16_t& GetRibbonParticlePrePosVertexBufferHandle() { return m_ribbonParticlePrePosVertexBufferHandle; } | ||
uint16_t& GetRibbonParticleRemainVertexBufferHandle() { return m_ribbonParticleRemainVertexBufferHandle; } | ||
uint16_t& GetRibbonParticleIndexBufferHandle() { return m_ribbonParticleIndexBufferHandle; } | ||
|
||
std::vector<std::byte>& GetRibbonPrePosVertexBuffer() { return m_ribbonParticlePrePosVertexBuffer; } | ||
std::vector<std::byte>& GetRibbonRemainVertexBuffer() { return m_ribbonParticleRemainVertexBuffer; } | ||
std::vector<std::byte>& GetRibbonIndexBuffer() { return m_ribbonParticleIndexBuffer; } | ||
|
||
private: | ||
//particle vertex/index | ||
struct VertexData | ||
{ | ||
cd::Vec3f pos; | ||
cd::Vec4f color; | ||
cd::UV uv; | ||
}; | ||
|
||
std::vector<std::byte> m_ribbonParticlePrePosVertexBuffer; | ||
std::vector<std::byte> m_ribbonParticleRemainVertexBuffer; | ||
std::vector<std::byte> m_ribbonParticleIndexBuffer; | ||
uint16_t m_ribbonParticlePrePosVertexBufferHandle = UINT16_MAX; | ||
uint16_t m_ribbonParticleRemainVertexBufferHandle = UINT16_MAX; | ||
uint16_t m_ribbonParticleIndexBufferHandle = UINT16_MAX; | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.