1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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;
};
|