summaryrefslogtreecommitdiff
path: root/Runtime/Graphics/DynamicVertexBuffer.h
blob: 6f21010480884721bafcaa1f5c4ff16478852395 (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
#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"

// 动态填充的VBO
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
    static const int kDataBufferThreshold = 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 only
	uint m_CurStride; // default layout only

	uint m_CurVertexCount;
	uint m_CurIndexCount;

};