PS2GL
OpenGL*-like API for the PS2
Loading...
Searching...
No Matches
gblock.h
1/* Copyright (C) 2000,2001,2002 Sony Computer Entertainment America
2
3 This file is subject to the terms and conditions of the GNU Lesser
4 General Public License Version 2.1. See the file "COPYING" in the
5 main directory of this archive for more details. */
6
7#ifndef ps2gl_gblock_h
8#define ps2gl_gblock_h
9
10#include "ps2s/types.h"
11#include <stdio.h>
12
13#include "GL/gl.h"
14#include "ps2gl/debug.h"
15
16/********************************************
17 * CGeometryBlock
18 *
19 * This classes purpose in life is to accumulate similar, contiguous geometry, where 'similar'
20 * means same prim type, same number of words per vertex/normal/etc.
21 */
22
23namespace ArrayType {
24typedef enum { kLinear,
25 kIndexed,
26 kInvalidArray } tArrayType;
27}
28
30private:
31 int TotalVertices;
32 char WordsPerVertex, WordsPerNormal, WordsPerTexCoord, WordsPerColor;
33 char NumVertsToRestartStrip, NumVertsPerPrim;
34 bool StripsCanBeMerged;
35 bool AreVerticesValid, AreNormalsValid, AreTexCoordsValid, AreColorsValid;
36
37 GLenum PrimType;
38 ArrayType::tArrayType ArrayType;
39
40 static const int kMaxNumStrips = 40;
41 static const unsigned int kContinueFlag = 0x80000000;
42 unsigned char NumStrips;
43 unsigned int StripLengths[kMaxNumStrips];
44 const void* IStripLengths[kMaxNumStrips];
45 const void* Indices[kMaxNumStrips];
46 const void* Vertices[kMaxNumStrips];
47 const void* Normals[kMaxNumStrips];
48 const void* TexCoords[kMaxNumStrips];
49 const void* Colors[kMaxNumStrips];
50 unsigned char NumIndices[kMaxNumStrips];
51
52 // new geometry we are trying to add to the block
53
54 GLenum NewPrimType;
55 ArrayType::tArrayType NewArrayType;
56
57 const void *NewVertices, *NewNormals, *NewTexCoords, *NewColors;
58 const void *NewIndices, *NewIStripLengths;
59 int NumNewVertices, NumNewNormals, NumNewTexCoords, NumNewColors, NumNewIndices;
60 char WordsPerNewVertex, WordsPerNewNormal;
61 char WordsPerNewTexCoord, WordsPerNewColor;
62 bool AreNewVerticesValid, AreNewNormalsValid;
63 bool AreNewTexCoordsValid, AreNewColorsValid;
64
65 void CommitPrimType();
66 bool SameDataFormat();
67
68 bool MergeNewLinear();
69 bool MergeNewIndexed();
70
71public:
72 CGeometryBlock() { Reset(); }
73
74 // get/set info about geometry
75
76 inline void SetVerticesAreValid(bool valid) { AreNewVerticesValid = valid; }
77 inline void SetNormalsAreValid(bool valid) { AreNewNormalsValid = valid; }
78 inline void SetTexCoordsAreValid(bool valid) { AreNewTexCoordsValid = valid; }
79 inline void SetColorsAreValid(bool valid) { AreNewColorsValid = valid; }
80
81 inline bool GetVerticesAreValid() const { return AreVerticesValid; }
82 inline bool GetNormalsAreValid() const { return AreNormalsValid; }
83 inline bool GetTexCoordsAreValid() const { return AreTexCoordsValid; }
84 inline bool GetColorsAreValid() const { return AreColorsValid; }
85
86 inline int GetWordsPerVertex() const { return WordsPerVertex; }
87 inline int GetWordsPerNormal() const { return WordsPerNormal; }
88 inline int GetWordsPerTexCoord() const { return WordsPerTexCoord; }
89 inline int GetWordsPerColor() const { return WordsPerColor; }
90
91 inline void SetWordsPerVertex(char num) { WordsPerNewVertex = num; }
92 inline void SetWordsPerNormal(char num) { WordsPerNewNormal = num; }
93 inline void SetWordsPerTexCoord(char num) { WordsPerNewTexCoord = num; }
94 inline void SetWordsPerColor(char num) { WordsPerNewColor = num; }
95
96 inline void SetArrayType(ArrayType::tArrayType type) { NewArrayType = type; }
97 inline ArrayType::tArrayType GetNewArrayType() const { return NewArrayType; }
98 inline ArrayType::tArrayType GetArrayType() const { return ArrayType; }
99
100 inline void SetNumIndices(unsigned int num) { NumNewIndices = num; }
101 inline void SetIndices(const void* indices) { NewIndices = indices; }
102 inline void SetIStripLengths(const void* strips) { NewIStripLengths = strips; }
103
104 inline const void* GetVertices(int strip = 0)
105 {
106 mErrorIf(strip >= NumStrips, "Strip num is out of bounds");
107 return Vertices[strip];
108 }
109 inline const void* GetNormals(int strip = 0)
110 {
111 mErrorIf(strip >= NumStrips, "Strip num is out of bounds");
112 return Normals[strip];
113 }
114 inline const void* GetTexCoords(int strip = 0)
115 {
116 mErrorIf(strip >= NumStrips, "Strip num is out of bounds");
117 return TexCoords[strip];
118 }
119 inline const void* GetColors(int strip = 0)
120 {
121 mErrorIf(strip >= NumStrips, "Strip num is out of bounds");
122 return Colors[strip];
123 }
124 inline const void* GetIndices(int array)
125 {
126 mErrorIf(array >= NumStrips, "Strip num is out of bounds");
127 return Indices[array];
128 }
129 inline const void* GetIStripLengths(int array)
130 {
131 mErrorIf(array >= NumStrips, "Strip num is out of bounds");
132 return IStripLengths[array];
133 }
134
135 inline void SetVertices(const void* verts) { NewVertices = verts; }
136 inline void SetNormals(const void* norms) { NewNormals = norms; }
137 inline void SetTexCoords(const void* texcoords) { NewTexCoords = texcoords; }
138 inline void SetColors(const void* colors) { NewColors = colors; }
139
140 GLenum GetPrimType() const { return PrimType; }
141 void SetPrimType(GLenum type) { NewPrimType = type; }
142
143 inline int GetNumNewVertices() const { return NumNewVertices; }
144 inline int GetNumNewNormals() const { return NumNewNormals; }
145 inline int GetNumNewTexCoords() const { return NumNewTexCoords; }
146 inline int GetNumNewColors() const { return NumNewColors; }
147
148 inline int GetTotalVertices() const { return TotalVertices; }
149
150 // adding geometry
151
152 inline void AddVertices(int num = 1) { NumNewVertices += num; }
153 inline void AddNormals(int num = 1) { NumNewNormals += num; }
154 inline void AddTexCoords(int num = 1) { NumNewTexCoords += num; }
155 inline void AddColors(int num = 1) { NumNewColors += num; }
156
157 // prim
158
159 // this is here for custom renderers/prim types.. use with caution!!
160 inline void SetNumVertsPerPrim(int num) { NumVertsPerPrim = num; }
161 inline int GetNumVertsPerPrim() { return NumVertsPerPrim; }
162
163 // strip related
164
165 // this is here for custom renderers/prim types.. use with caution!!
166 inline void SetNumVertsToRestartStrip(int num) { NumVertsToRestartStrip = num; }
167 inline void SetStripsCanBeMerged(bool merge) { StripsCanBeMerged = merge; }
168
169 inline int GetNumStrips() const { return NumStrips; }
173 inline int GetNumVertsToRestartStrip() { return NumVertsToRestartStrip; }
174 inline bool GetStripsCanBeMerged() const { return StripsCanBeMerged; }
175 inline int GetStripLength(int num) const
176 {
177 mErrorIf(num >= NumStrips, "Strip num is out of bounds");
178 return (int)(StripLengths[num] & ~kContinueFlag);
179 }
180 inline bool StripIsContinued(int num) const
181 {
182 mErrorIf(num >= NumStrips, "Strip num is out of bounds");
183 return StripLengths[num] & kContinueFlag;
184 }
185
186 // "array" related (for indexed arrays)
187
188 inline int GetNumArrays() const { return NumStrips; }
189 inline int GetArrayLength(int array) const
190 {
191 return GetStripLength(array);
192 }
193 inline int GetNumIndices(int array) const
194 {
195 mErrorIf(array >= NumStrips, "Strip num is out of bounds");
196 return NumIndices[array];
197 }
198
199 // reset
200
201 void ResetCurStrip();
202 void ResetNew();
203 void Reset();
204
205 // merge / commit related
206
207 bool IsPending() const { return (PrimType != GL_INVALID_VALUE); }
208 bool MergeNew();
209 void MakeNewValuesCurrent();
210 void AdjustNewGeomPtrs(int offset)
211 {
212 if (AreNewVerticesValid)
213 NewVertices = (float*)NewVertices + offset * WordsPerNewVertex;
214 if (AreNewNormalsValid)
215 NewNormals = (float*)NewNormals + offset * WordsPerNewNormal;
216 if (AreNewTexCoordsValid)
217 NewTexCoords = (float*)NewTexCoords + offset * WordsPerNewTexCoord;
218 if (AreNewColorsValid)
219 NewColors = (float*)NewColors + offset * WordsPerNewColor;
220 }
221};
222
223#endif // ps2gl_gblock_h
int GetNumVertsToRestartStrip()
Definition gblock.h:173