summaryrefslogtreecommitdiff
path: root/Runtime/Graphics/VertexBuffer.h
blob: 05aa16c5f726709f2832a48d15f95422cb13badb (plain)
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#ifndef VBO_H
#define VBO_H

#include <vector>

#include "../Utilities/UtilMacros.h"
#include "../Shaders/ShaderChannel.h"

#include "OpenGL.h"
#include "GPUDataBuffer.h"
#include "DefaultVertexLayout.h"
#include "CustomVertexLayout.h"

enum EPrimitive
{
	Primitive_Triangle = 1,
	Primitive_Line = 2,
	Primitive_Point = 3,
};

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;
	GPU::DataBuffer *m_IB;// vertex buffer and index buffer

};

class SharedVertexBuffer
{
public: 
	SharedVertexBuffer();
	~SharedVertexBuffer();

	void GetChunk(uint attrs, int maxVerts, int maxIndices, EPrimitive primitive, void **out_vb, void **out_ib);
	void ReleaseChunk(int actualVerts, int actualIndices);

	void DrawChunk();

private: 

	void FillVertexDataInfo(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;
	uint m_CurStride;

	uint m_CurVertexCount;
	uint m_CurIndexCount;

};

#endif