summaryrefslogtreecommitdiff
path: root/Runtime/Graphics/DynamicVertexBuffer.h
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-11-01 10:43:51 +0800
committerchai <chaifix@163.com>2021-11-01 10:43:51 +0800
commit78417f6cdedfcf60c8ca437190975644e942e01f (patch)
tree5140fe969fe70083d20096b030dc9e944f82a5c3 /Runtime/Graphics/DynamicVertexBuffer.h
parent8078aeed4e62c6b3aa48102554044768b402570c (diff)
*rename SharedVertexBuffer -> DynamicVertexBuffer
Diffstat (limited to 'Runtime/Graphics/DynamicVertexBuffer.h')
-rw-r--r--Runtime/Graphics/DynamicVertexBuffer.h54
1 files changed, 54 insertions, 0 deletions
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 <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 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<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;
+
+};