Add stride to GPUVertexLayout
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
#include "GPUBufferDescription.h"
|
||||
#include "PixelFormatExtensions.h"
|
||||
#include "RenderTask.h"
|
||||
#include "Shaders/GPUVertexLayout.h"
|
||||
#include "Async/Tasks/GPUCopyResourceTask.h"
|
||||
#include "Engine/Core/Utilities.h"
|
||||
#include "Engine/Core/Types/String.h"
|
||||
@@ -75,6 +76,20 @@ GPUBufferDescription GPUBufferDescription::Vertex(GPUVertexLayout* layout, uint3
|
||||
return desc;
|
||||
}
|
||||
|
||||
GPUBufferDescription GPUBufferDescription::Vertex(GPUVertexLayout* layout, uint32 elementsCount, const void* data)
|
||||
{
|
||||
const uint32 stride = layout ? layout->GetStride() : 0;
|
||||
CHECK_RETURN_DEBUG(stride, GPUBufferDescription());
|
||||
return Vertex(layout, stride, elementsCount, data);
|
||||
}
|
||||
|
||||
GPUBufferDescription GPUBufferDescription::Vertex(GPUVertexLayout* layout, uint32 elementsCount, GPUResourceUsage usage)
|
||||
{
|
||||
const uint32 stride = layout ? layout->GetStride() : 0;
|
||||
CHECK_RETURN_DEBUG(stride, GPUBufferDescription());
|
||||
return Vertex(layout, stride, elementsCount, usage);
|
||||
}
|
||||
|
||||
void GPUBufferDescription::Clear()
|
||||
{
|
||||
Platform::MemoryClear(this, sizeof(GPUBufferDescription));
|
||||
|
||||
@@ -202,6 +202,24 @@ public:
|
||||
/// <returns>The buffer description.</returns>
|
||||
static GPUBufferDescription Vertex(GPUVertexLayout* layout, uint32 elementStride, uint32 elementsCount, GPUResourceUsage usage = GPUResourceUsage::Default);
|
||||
|
||||
/// <summary>
|
||||
/// Creates vertex buffer description.
|
||||
/// </summary>
|
||||
/// <param name="layout">The vertex buffer layout.</param>
|
||||
/// <param name="elementsCount">The elements count.</param>
|
||||
/// <param name="data">The data.</param>
|
||||
/// <returns>The buffer description.</returns>
|
||||
static GPUBufferDescription Vertex(GPUVertexLayout* layout, uint32 elementsCount, const void* data);
|
||||
|
||||
/// <summary>
|
||||
/// Creates vertex buffer description.
|
||||
/// </summary>
|
||||
/// <param name="layout">The vertex buffer layout.</param>
|
||||
/// <param name="elementsCount">The elements count.</param>
|
||||
/// <param name="usage">The usage mode.</param>
|
||||
/// <returns>The buffer description.</returns>
|
||||
static GPUBufferDescription Vertex(GPUVertexLayout* layout, uint32 elementsCount, GPUResourceUsage usage = GPUResourceUsage::Default);
|
||||
|
||||
/// <summary>
|
||||
/// Creates vertex buffer description.
|
||||
/// [Deprecated in v1.10]
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,11 +16,15 @@ API_CLASS(Sealed, NoSpawn) class FLAXENGINE_API GPUVertexLayout : public GPUReso
|
||||
DECLARE_SCRIPTING_TYPE_NO_SPAWN(GPUVertexLayout);
|
||||
typedef Array<VertexElement, FixedAllocation<GPU_MAX_VS_ELEMENTS>> Elements;
|
||||
|
||||
protected:
|
||||
private:
|
||||
Elements _elements;
|
||||
uint32 _stride;
|
||||
|
||||
protected:
|
||||
GPUVertexLayout();
|
||||
|
||||
void SetElements(const Elements& elements, uint32 offsets[GPU_MAX_VS_ELEMENTS]);
|
||||
|
||||
public:
|
||||
/// <summary>
|
||||
/// Gets the list of elements used by this layout.
|
||||
@@ -30,6 +34,14 @@ public:
|
||||
return _elements;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the size in bytes of all elements in the layout structure (including their offsets).
|
||||
/// </summary>
|
||||
API_PROPERTY() FORCE_INLINE uint32 GetStride() const
|
||||
{
|
||||
return _stride;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the vertex layout for a given list of elements. Uses internal cache to skip creating layout if it's already exists for a given list.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user