forked from FrictionalGames/HPL1Engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
VertexBuffer.h
168 lines (132 loc) · 4.98 KB
/
VertexBuffer.h
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/*
* Copyright (C) 2006-2010 - Frictional Games
*
* This file is part of HPL1 Engine.
*
* HPL1 Engine is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HPL1 Engine is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with HPL1 Engine. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef HPL_VERTEXBUFFER_H
#define HPL_VERTEXBUFFER_H
#include "graphics/GraphicsTypes.h"
#include "math/MathTypes.h"
#include "system/SystemTypes.h"
#include "math/BoundingVolume.h"
namespace hpl {
class cBoundingVolume;
enum eVertexBufferDrawType
{
eVertexBufferDrawType_Tri,
eVertexBufferDrawType_Quad,
eVertexBufferDrawType_Lines,
eVertexBufferDrawType_LastEnum
};
enum eVertexBufferUsageType
{
eVertexBufferUsageType_Static,
eVertexBufferUsageType_Dynamic,
eVertexBufferUsageType_Stream,
eVertexBufferUsageType_LastEnum
};
typedef tFlag tVertexFlag;
#define eVertexFlag_Normal (0x00000001)
#define eVertexFlag_Position (0x00000002)
#define eVertexFlag_Color0 (0x00000004)
#define eVertexFlag_Color1 (0x00000008)
#define eVertexFlag_Texture0 (0x00000010)
#define eVertexFlag_Texture1 (0x00000020)
#define eVertexFlag_Texture2 (0x00000040)
#define eVertexFlag_Texture3 (0x00000080)
#define eVertexFlag_Texture4 (0x00000100)
#define klNumOfVertexFlags (9)
const tVertexFlag kvVertexFlags[] = {eVertexFlag_Normal,eVertexFlag_Position,eVertexFlag_Color0,
eVertexFlag_Color1,eVertexFlag_Texture0,eVertexFlag_Texture1,eVertexFlag_Texture2,
eVertexFlag_Texture3,eVertexFlag_Texture4};
const int kvVertexElements[] = {3, //Normal
4, //Position
4, //Color0
4, //Color1
3, //Texture0
3, //Texture1
3, //Texture2
3, //Texture3
3 //Texture4
};
typedef tFlag tVertexCompileFlag;
#define eVertexCompileFlag_CreateTangents (0x00000001)
class iLowLevelGraphics;
class iVertexBuffer
{
public:
iVertexBuffer(iLowLevelGraphics* apLowLevelGraphics,tVertexFlag aFlags,
eVertexBufferDrawType aDrawType,eVertexBufferUsageType aUsageType,
int alReserveVtxSize,int alReserveIdxSize) :
mVertexFlags(aFlags), mpLowLevelGraphics(apLowLevelGraphics),
mDrawType(aDrawType), mUsageType(aUsageType), mlElementNum(-1),
mbTangents(false){}
virtual ~iVertexBuffer(){}
tVertexFlag GetFlags(){ return mVertexFlags;}
virtual void AddVertex(tVertexFlag aType,const cVector3f& avVtx)=0;
virtual void AddColor(tVertexFlag aType,const cColor& aColor)=0;
virtual void AddIndex(unsigned int alIndex)=0;
virtual bool Compile(tVertexCompileFlag aFlags)=0;
virtual void UpdateData(tVertexFlag aTypes, bool abIndices)=0;
/**
* This creates a double of the vertex array with w=0.
* \param abUpdateData if the hardware buffer should be updated aswell.
*/
virtual void CreateShadowDouble(bool abUpdateData)=0;
/**
* Transform the entire buffer with transform.
*/
virtual void Transform(const cMatrixf &mtxTransform)=0;
virtual void Draw(eVertexBufferDrawType aDrawType = eVertexBufferDrawType_LastEnum)=0;
virtual void DrawIndices(unsigned int *apIndices, int alCount,
eVertexBufferDrawType aDrawType = eVertexBufferDrawType_LastEnum)=0;
virtual void Bind()=0;
virtual void UnBind()=0;
virtual iVertexBuffer* CreateCopy(eVertexBufferUsageType aUsageType)=0;
virtual cBoundingVolume CreateBoundingVolume()=0;
virtual float* GetArray(tVertexFlag aType)=0;
virtual unsigned int* GetIndices()=0;
virtual int GetVertexNum()=0;
virtual int GetIndexNum()=0;
/**
* Resizes an array to a custom size, the size is number of elements and NOT number of vertices.
*/
virtual void ResizeArray(tVertexFlag aType, int alSize)=0;
virtual void ResizeIndices(int alSize)=0;
//For debugging purposes, quite slow to use.
virtual cVector3f GetVector3(tVertexFlag aType, unsigned alIdx)=0;
virtual cVector3f GetVector4(tVertexFlag aType, unsigned alIdx)=0;
virtual cColor GetColor(tVertexFlag aType, unsigned alIdx)=0;
virtual unsigned int GetIndex(tVertexFlag aType, unsigned alIdx)=0;
/**
* Set the number of of elements to draw.
* \param alNum If < 0, draw all indices.
*/
void SetElementNum(int alNum){ mlElementNum = alNum;}
int GetElementNum(){ return mlElementNum;}
tVertexFlag GetVertexFlags(){ return mVertexFlags;}
bool HasTangents(){ return mbTangents;}
void SetTangents(bool abX){ mbTangents = abX;}
protected:
tVertexFlag mVertexFlags;
eVertexBufferDrawType mDrawType;
eVertexBufferUsageType mUsageType;
iLowLevelGraphics* mpLowLevelGraphics;
int mlElementNum;
bool mbTangents;
};
};
#endif // HPL_RENDERER3D_H