diff options
author | chai <chaifix@163.com> | 2021-12-13 00:07:19 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2021-12-13 00:07:19 +0800 |
commit | 60cbbdec07ab7a5636eac5b3c024ae44e937f4d4 (patch) | |
tree | b2c7b0a868f18159dbc43d8954e1bd7668549a88 /Client/Source/Graphics/DynamicVertexBuffer.h |
+init
Diffstat (limited to 'Client/Source/Graphics/DynamicVertexBuffer.h')
-rw-r--r-- | Client/Source/Graphics/DynamicVertexBuffer.h | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/Client/Source/Graphics/DynamicVertexBuffer.h b/Client/Source/Graphics/DynamicVertexBuffer.h new file mode 100644 index 0000000..ad65d80 --- /dev/null +++ b/Client/Source/Graphics/DynamicVertexBuffer.h @@ -0,0 +1,54 @@ +#pragma once +#include <vector> + +#include "../Utilities/UtilMacros.h" + +#include "OpenGL.h" +#include "GPUDataBuffer.h" +#include "DefaultVertexLayout.h" +#include "CustomVertexLayout.h" +#include "Primitive.h" + +// 动态填充的VBO +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 + static const int kDataBufferThreshold = 1024; + + GPU::DataBuffer *m_CurVB; + GPU::DataBuffer *m_CurIB; + + std::vector<byte> m_CurVBData; + std::vector<uint16> m_CurIBData; + + EPrimitive m_CurPrimitive; + + uint m_CurAttrMask; // default layout only + uint m_CurStride; // default layout only + + uint m_CurVertexCount; + uint m_CurIndexCount; + +};
\ No newline at end of file |