diff options
author | chai <chaifix@163.com> | 2021-10-28 01:52:12 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2021-10-28 01:52:12 +0800 |
commit | 80dca084b568e4e77d2a4031ce8625cdabc660ab (patch) | |
tree | d8c0172aeddca648ec89cbbbda72a938f3ef7433 /Runtime/Graphics/SharedVertexBuffer.h | |
parent | 1b6f71b2777bdc74d63f988346a8cfee766718b0 (diff) |
+ custom vertex buffer
Diffstat (limited to 'Runtime/Graphics/SharedVertexBuffer.h')
-rw-r--r-- | Runtime/Graphics/SharedVertexBuffer.h | 54 |
1 files changed, 54 insertions, 0 deletions
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 <vector> + +#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<byte> m_CurVBData; + std::vector<uint16> m_CurIBData; + + EPrimitive m_CurPrimitive; + + uint m_CurAttrMask; // default layout + uint m_CurStride; // default layout + + uint m_CurVertexCount; + uint m_CurIndexCount; + +}; |