From 80dca084b568e4e77d2a4031ce8625cdabc660ab Mon Sep 17 00:00:00 2001 From: chai Date: Thu, 28 Oct 2021 01:52:12 +0800 Subject: + custom vertex buffer --- Runtime/Graphics/SharedVertexBuffer.h | 54 +++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 Runtime/Graphics/SharedVertexBuffer.h (limited to 'Runtime/Graphics/SharedVertexBuffer.h') diff --git a/Runtime/Graphics/SharedVertexBuffer.h b/Runtime/Graphics/SharedVertexBuffer.h new file mode 100644 index 0000000..001eb2c --- /dev/null +++ b/Runtime/Graphics/SharedVertexBuffer.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 SharedVertexBuffer +{ +public: + SharedVertexBuffer(); + ~SharedVertexBuffer(); + + // default layout + void GetChunk(uint attrs, int maxVerts, int maxIndices, EPrimitive primitive, void **out_vb, void **out_ib); + void ReleaseChunk(int actualVerts, int actualIndices); + 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); + +private: + + void FillCustomVertexLayout(CustomVertexLayout& dst); + void FillDefaultVertexLayout(DefaultVertexLayout& dst); + + void Clean(); + + // if vertex databuffer size beyond this value, use pinned memory mapping, instead of glBufferData. + enum { DataBufferThreshold = 1024 }; + + // shared vbo and ibo + GPU::DataBuffer *m_CurVB; + GPU::DataBuffer *m_CurIB; + + // restore vbo and ibo data if not using pinned memory mapping + 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