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
|
#pragma once
#include <vector>
#include "../Utilities/UtilMacros.h"
#include "OpenGL.h"
#include "GPUDataBuffer.h"
#include "DefaultVertexLayout.h"
#include "CustomVertexLayout.h"
#include "Primitive.h"
// 实际使用过程中,通常是一个VBO和一个IBO一起,submesh对应的是IBO中的不同的段,而不是不同的IBO
class VertexBuffer
{
public:
enum VertexBufferType
{
VertexBufferType_Static, // device
VertexBufferType_Stream, // pinned (best performance)
VertexBufferType_Dynamic,// device
};
VertexBuffer(int vbSize, int ibSize, VertexBufferType type);
~VertexBuffer();
// 填充数据
void GetChunk(uint sizePerVert, uint sizePerIndex, int maxVerts, int maxIndices, EPrimitive primitive, void **out_vb, void **out_ib);
// 提交数据
void FlushChunk(int actualVerts, int actualIndices);
GET(GPU::DataBuffer*, VB, m_VB);
GET(GPU::DataBuffer*, IB, m_IB);
void Draw(CustomVertexLayout& layout);
private:
void FillCustomVertexLayout(CustomVertexLayout& dst);
VertexBufferType m_Type;
GPU::DataBuffer* m_VB;
GPU::DataBuffer* m_IB;
int m_SizePerVertex;
int m_CurIndexCount;
EPrimitive m_Primitive;
};
|