summaryrefslogtreecommitdiff
path: root/Runtime/Graphics/VertexBuffer.h
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2020-10-19 09:13:58 +0800
committerchai <chaifix@163.com>2020-10-19 09:13:58 +0800
commitf0807fc44dde14531759306317611bab87c8fccf (patch)
tree6e78fed61c16a70cda5fa732635f89f9faac9720 /Runtime/Graphics/VertexBuffer.h
parent639b34294ffc20721c66db46e59e07d9100ac4b8 (diff)
+gamelab proj
Diffstat (limited to 'Runtime/Graphics/VertexBuffer.h')
-rw-r--r--Runtime/Graphics/VertexBuffer.h103
1 files changed, 103 insertions, 0 deletions
diff --git a/Runtime/Graphics/VertexBuffer.h b/Runtime/Graphics/VertexBuffer.h
new file mode 100644
index 0000000..33c0783
--- /dev/null
+++ b/Runtime/Graphics/VertexBuffer.h
@@ -0,0 +1,103 @@
+#ifndef VBO_H
+#define VBO_H
+
+#include <vector>
+
+#include "../Utilities/UtilMacros.h"
+#include "../Shaders/ShaderChannel.h"
+
+#include "OpenGL.h"
+#include "GpuDataBuffer.h"
+
+enum VertexAttr
+{
+ VertexAttr_Position = 0,
+ VertexAttr_Normal = 1,
+ VertexAttr_Tangent = 2,
+ VertexAttr_Color = 3,
+ VertexAttr_TexCoord0 = 4,
+ VertexAttr_TexCoord1 = 5,
+
+ VertexAttr_Count = 6
+};
+
+enum RenderMode
+{
+ RenderMode_Triangle = 1,
+ RenderMode_Line = 2,
+ RenderMode_Point = 3,
+};
+
+struct VertexInputInfo
+{
+ const void* pointer; // either cpu memory or gpu memory
+ uint componentType; // one of VertexAttrFormat
+ uint componentNum;
+ uint16 stride;
+};
+
+// gpu side vertex attributes array
+struct VertexArrayInfo
+{
+ uint32 enableMask;
+ GLuint buffers[VertexAttr_Count];
+ VertexInputInfo attributes[VertexAttr_Count];
+};
+
+class VertexBuffer
+{
+public:
+ enum VertexBufferType
+ {
+ VertexBufferType_Static, // device
+ VertexBufferType_Stream, // pinned (best performance)
+ VertexBufferType_Dynamic,// device
+ };
+
+ VertexBuffer(VertexBufferType type);
+ ~VertexBuffer();
+
+ void Draw();
+
+private:
+
+ VertexBufferType m_Type;
+ GPU::DataBuffer *m_VB, *m_IB;// vertex buffer and index buffer
+
+};
+
+class SharedVertexBuffer
+{
+public:
+ void GetChunk(uint attrs, int maxVerts, int maxIndices, RenderMode mode, void **out_vb, void **out_ib);
+ void ReleaseChunk(int actualVerts, int actualIndices);
+
+ void DrawChunk();
+
+private:
+
+ void FillVertexArrayInfo(VertexArrayInfo& 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, *m_CurIB;
+
+ // restore vbo and ibo data if not using pinned memory mapping
+ std::vector<byte> m_CurVBData;
+ std::vector<uint16> m_CurIBData;
+
+ RenderMode m_CurRenderMode;
+
+ uint m_CurAttrMask;
+ uint m_CurStride;
+
+ uint m_CurVertexCount;
+ uint m_CurIndexCount;
+
+};
+
+#endif \ No newline at end of file