ScummVM API documentation
VertexBuffer.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 /*
23  * Copyright (C) 2006-2010 - Frictional Games
24  *
25  * This file is part of HPL1 Engine.
26  */
27 
28 #ifndef HPL_VERTEXBUFFER_H
29 #define HPL_VERTEXBUFFER_H
30 
31 #include "hpl1/engine/graphics/GraphicsTypes.h"
32 #include "hpl1/engine/math/BoundingVolume.h"
33 #include "hpl1/engine/math/MathTypes.h"
34 #include "hpl1/engine/system/SystemTypes.h"
35 
36 namespace hpl {
37 
38 class cBoundingVolume;
39 
40 enum eVertexBufferDrawType {
41  eVertexBufferDrawType_Tri,
42  eVertexBufferDrawType_Quad,
43  eVertexBufferDrawType_Lines,
44  eVertexBufferDrawType_LastEnum
45 };
46 
47 enum eVertexBufferUsageType {
48  eVertexBufferUsageType_Static,
49  eVertexBufferUsageType_Dynamic,
50  eVertexBufferUsageType_Stream,
51  eVertexBufferUsageType_LastEnum
52 };
53 
54 typedef tFlag tVertexFlag;
55 
56 #define eVertexFlag_Normal (0x00000001)
57 #define eVertexFlag_Position (0x00000002)
58 #define eVertexFlag_Color0 (0x00000004)
59 #define eVertexFlag_Color1 (0x00000008)
60 #define eVertexFlag_Texture0 (0x00000010)
61 #define eVertexFlag_Texture1 (0x00000020)
62 #define eVertexFlag_Texture2 (0x00000040)
63 #define eVertexFlag_Texture3 (0x00000080)
64 #define eVertexFlag_Texture4 (0x00000100)
65 
66 #define klNumOfVertexFlags (9)
67 
68 const tVertexFlag kvVertexFlags[] = {eVertexFlag_Normal, eVertexFlag_Position, eVertexFlag_Color0,
69  eVertexFlag_Color1, eVertexFlag_Texture0, eVertexFlag_Texture1, eVertexFlag_Texture2,
70  eVertexFlag_Texture3, eVertexFlag_Texture4};
71 
72 const int kvVertexElements[] = {
73  3, // Normal
74  4, // Position
75  4, // Color0
76  4, // Color1
77  3, // Texture0
78  3, // Texture1
79  3, // Texture2
80  3, // Texture3
81  3 // Texture4
82 };
83 
84 typedef tFlag tVertexCompileFlag;
85 
86 #define eVertexCompileFlag_CreateTangents (0x00000001)
87 
88 class iLowLevelGraphics;
89 
91 public:
92  iVertexBuffer(iLowLevelGraphics *apLowLevelGraphics, tVertexFlag aFlags,
93  eVertexBufferDrawType aDrawType, eVertexBufferUsageType aUsageType,
94  int alReserveVtxSize, int alReserveIdxSize) : mVertexFlags(aFlags), mpLowLevelGraphics(apLowLevelGraphics),
95  mDrawType(aDrawType), mUsageType(aUsageType), mlElementNum(-1),
96  mbTangents(false) {}
97 
98  virtual ~iVertexBuffer() {}
99 
100  tVertexFlag GetFlags() { return mVertexFlags; }
101 
102  virtual void AddVertex(tVertexFlag aType, const cVector3f &avVtx) = 0;
103  virtual void AddColor(tVertexFlag aType, const cColor &aColor) = 0;
104  virtual void AddIndex(unsigned int alIndex) = 0;
105 
106  virtual bool Compile(tVertexCompileFlag aFlags) = 0;
107  virtual void UpdateData(tVertexFlag aTypes, bool abIndices) = 0;
108 
113  virtual void CreateShadowDouble(bool abUpdateData) = 0;
114 
118  virtual void Transform(const cMatrixf &mtxTransform) = 0;
119 
120  virtual void Draw(eVertexBufferDrawType aDrawType = eVertexBufferDrawType_LastEnum) = 0;
121  virtual void DrawIndices(unsigned int *apIndices, int alCount,
122  eVertexBufferDrawType aDrawType = eVertexBufferDrawType_LastEnum) = 0;
123 
124  virtual void Bind() = 0;
125  virtual void UnBind() = 0;
126 
127  virtual iVertexBuffer *CreateCopy(eVertexBufferUsageType aUsageType) = 0;
128 
129  virtual cBoundingVolume CreateBoundingVolume() = 0;
130 
131  virtual float *GetArray(tVertexFlag aType) = 0;
132  virtual unsigned int *GetIndices() = 0;
133 
134  virtual int GetVertexNum() = 0;
135  virtual int GetIndexNum() = 0;
136 
140  virtual void ResizeArray(tVertexFlag aType, int alSize) = 0;
141  virtual void ResizeIndices(int alSize) = 0;
142 
143  // For debugging purposes, quite slow to use.
144  virtual cVector3f GetVector3(tVertexFlag aType, unsigned alIdx) = 0;
145  virtual cVector3f GetVector4(tVertexFlag aType, unsigned alIdx) = 0;
146  virtual cColor GetColor(tVertexFlag aType, unsigned alIdx) = 0;
147  virtual unsigned int GetIndex(tVertexFlag aType, unsigned alIdx) = 0;
148 
153  void SetElementNum(int alNum) { mlElementNum = alNum; }
154  int GetElementNum() { return mlElementNum; }
155 
156  tVertexFlag GetVertexFlags() { return mVertexFlags; }
157 
158  bool HasTangents() { return mbTangents; }
159  void SetTangents(bool abX) { mbTangents = abX; }
160 
161 protected:
162  tVertexFlag mVertexFlags;
163  eVertexBufferDrawType mDrawType;
164  eVertexBufferUsageType mUsageType;
165  iLowLevelGraphics *mpLowLevelGraphics;
166 
167  int mlElementNum;
168 
169  bool mbTangents;
170 };
171 
172 } // namespace hpl
173 
174 #endif // HPL_RENDERER3D_H
virtual void ResizeArray(tVertexFlag aType, int alSize)=0
Definition: AI.h:36
virtual void CreateShadowDouble(bool abUpdateData)=0
Definition: VertexBuffer.h:90
Definition: BoundingVolume.h:71
virtual void Transform(const cMatrixf &mtxTransform)=0
Definition: Color.h:37
void SetElementNum(int alNum)
Definition: VertexBuffer.h:153
Definition: LowLevelGraphics.h:200