Add stride to GPUVertexLayout

This commit is contained in:
Wojtek Figat
2024-12-17 15:58:26 +01:00
parent d1ac9cd2bc
commit 80299c8552
8 changed files with 74 additions and 13 deletions

View File

@@ -5,9 +5,11 @@
#include "Engine/Core/Log.h"
#endif
#include "Engine/Core/Collections/Dictionary.h"
#include "Engine/Core/Math/Math.h"
#include "Engine/Core/Types/Span.h"
#include "Engine/Graphics/GPUDevice.h"
#include "Engine/Graphics/GPUBuffer.h"
#include "Engine/Graphics/PixelFormatExtensions.h"
#if GPU_ENABLE_RESOURCE_NAMING
#include "Engine/Scripting/Enums.h"
#endif
@@ -74,6 +76,20 @@ GPUVertexLayout::GPUVertexLayout()
{
}
void GPUVertexLayout::SetElements(const Elements& elements, uint32 offsets[GPU_MAX_VS_ELEMENTS])
{
_elements = elements;
uint32 strides[GPU_MAX_VB_BINDED] = {};
for (int32 i = 0; i < elements.Count(); i++)
{
const VertexElement& e = elements[i];
strides[e.Slot] = Math::Max(strides[e.Slot], offsets[i]);
}
_stride = 0;
for (int32 i = 0; i < GPU_MAX_VB_BINDED; i++)
_stride += strides[i];
}
GPUVertexLayout* GPUVertexLayout::Get(const Elements& elements)
{
// Hash input layout
@@ -144,7 +160,7 @@ GPUVertexLayout* GPUVertexLayout::Get(const Span<GPUBuffer*>& vertexBuffers)
anyValid = true;
int32 start = elements.Count();
elements.Add(layouts.Layouts[slot]->GetElements());
for (int32 j = start; j < elements.Count() ;j++)
for (int32 j = start; j < elements.Count(); j++)
elements.Get()[j].Slot = (byte)slot;
}
}