summaryrefslogtreecommitdiff
path: root/Runtime/Graphics/DynamicVertexBuffer.h
diff options
context:
space:
mode:
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;
+
+};