From 78417f6cdedfcf60c8ca437190975644e942e01f Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 1 Nov 2021 10:43:51 +0800 Subject: *rename SharedVertexBuffer -> DynamicVertexBuffer --- Runtime/Graphics/DynamicVertexBuffer.h | 54 ++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 Runtime/Graphics/DynamicVertexBuffer.h (limited to 'Runtime/Graphics/DynamicVertexBuffer.h') diff --git a/Runtime/Graphics/DynamicVertexBuffer.h b/Runtime/Graphics/DynamicVertexBuffer.h new file mode 100644 index 0000000..a849f4c --- /dev/null +++ b/Runtime/Graphics/DynamicVertexBuffer.h @@ -0,0 +1,54 @@ +#pragma once +#include + +#include "../Utilities/UtilMacros.h" +#include "../Shaders/ShaderChannel.h" + +#include "OpenGL.h" +#include "GPUDataBuffer.h" +#include "DefaultVertexLayout.h" +#include "CustomVertexLayout.h" +#include "Primitive.h" + +class DynamicVertexBuffer +{ +public: + DynamicVertexBuffer(); + ~DynamicVertexBuffer(); + + // default layout + void GetChunk(uint attrs, int maxVerts, int maxIndices, EPrimitive primitive, void **out_vb, void **out_ib); + void DrawChunk(); + + // custom layout + void GetChunk(uint sizePerVert, uint sizePerIndex, int maxVerts, int maxIndices, EPrimitive primitive, void **out_vb, void **out_ib); + void DrawChunk(CustomVertexLayout& layout); + + // common + void ReleaseChunk(int actualVerts, int actualIndices); + +private: + + void FillCustomVertexLayout(CustomVertexLayout& dst); + void FillDefaultVertexLayout(DefaultVertexLayout& dst); + + void Clean(); + + // 如果数据大小超过这个限制,用内存数据,而不是glBufferData + enum { DataBufferThreshold = 1024 }; + + GPU::DataBuffer *m_CurVB; + GPU::DataBuffer *m_CurIB; + + std::vector m_CurVBData; + std::vector m_CurIBData; + + EPrimitive m_CurPrimitive; + + uint m_CurAttrMask; // default layout + uint m_CurStride; // default layout + + uint m_CurVertexCount; + uint m_CurIndexCount; + +}; -- cgit v1.1-26-g67d0