summaryrefslogtreecommitdiff
path: root/Runtime/Graphics/SharedVertexBuffer.h
blob: cc8975244fd60b8b6db0dcfa6a882c5a566a02e1 (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
#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 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;

};