Graphics: Fix WorldInstance removal while being in use

This commit is contained in:
Jérôme Leclercq
2021-07-28 13:31:13 +02:00
parent 03236b70c1
commit 5b1123b971
8 changed files with 41 additions and 35 deletions

View File

@@ -18,7 +18,7 @@ namespace Nz
m_worldMatrix(Nz::Matrix4f::Identity()),
m_dataInvalided(true)
{
Nz::PredefinedInstanceData instanceUboOffsets = Nz::PredefinedInstanceData::GetOffsets();
PredefinedInstanceData instanceUboOffsets = PredefinedInstanceData::GetOffsets();
m_instanceDataBuffer = Graphics::Instance()->GetRenderDevice()->InstantiateBuffer(BufferType::Uniform);
if (!m_instanceDataBuffer->Initialize(instanceUboOffsets.totalSize, Nz::BufferUsage::DeviceLocal | Nz::BufferUsage::Dynamic))
@@ -39,11 +39,11 @@ namespace Nz
{
if (m_dataInvalided)
{
Nz::PredefinedInstanceData instanceUboOffsets = Nz::PredefinedInstanceData::GetOffsets();
PredefinedInstanceData instanceUboOffsets = PredefinedInstanceData::GetOffsets();
auto& allocation = uploadPool.Allocate(m_instanceDataBuffer->GetSize());
Nz::AccessByOffset<Nz::Matrix4f&>(allocation.mappedPtr, instanceUboOffsets.worldMatrixOffset) = m_worldMatrix;
Nz::AccessByOffset<Nz::Matrix4f&>(allocation.mappedPtr, instanceUboOffsets.invWorldMatrixOffset) = m_invWorldMatrix;
AccessByOffset<Matrix4f&>(allocation.mappedPtr, instanceUboOffsets.worldMatrixOffset) = m_worldMatrix;
AccessByOffset<Matrix4f&>(allocation.mappedPtr, instanceUboOffsets.invWorldMatrixOffset) = m_invWorldMatrix;
builder.CopyBuffer(allocation, m_instanceDataBuffer.get());