7#include "ps2gl/gblock.h"
8#include "ps2gl/gmanager.h"
10using namespace ArrayType;
16bool CGeometryBlock::SameDataFormat()
20 if (AreVerticesValid != AreNewVerticesValid
21 || AreNormalsValid != AreNewNormalsValid
22 || AreTexCoordsValid != AreNewTexCoordsValid
23 || AreColorsValid != AreNewColorsValid)
25 else if (AreNewVerticesValid && WordsPerVertex != WordsPerNewVertex)
27 else if (AreNewNormalsValid && WordsPerNormal != WordsPerNewNormal)
29 else if (AreNewTexCoordsValid && WordsPerTexCoord != WordsPerNewTexCoord)
31 else if (AreNewColorsValid && WordsPerColor != WordsPerNewColor)
37bool CGeometryBlock::MergeNew()
40 mErrorIf(NumNewVertices == 0,
"Trying to merge geometry with no vertices!");
44 if (NewArrayType == kLinear)
45 success = MergeNewLinear();
47 success = MergeNewIndexed();
52bool CGeometryBlock::MergeNewIndexed()
56 if (NewPrimType != PrimType
57 || NewArrayType != ArrayType
58 || NumStrips >= kMaxNumStrips)
62 Vertices[NumStrips] = NewVertices;
63 Normals[NumStrips] = NewNormals;
64 TexCoords[NumStrips] = NewTexCoords;
65 Colors[NumStrips] = NewColors;
67 StripLengths[NumStrips] = (
unsigned int)NumNewVertices;
68 IStripLengths[NumStrips] = NewIStripLengths;
69 Indices[NumStrips] = NewIndices;
70 NumIndices[NumStrips] = NumNewIndices;
80bool CGeometryBlock::MergeNewLinear()
84 if (NewPrimType != PrimType
85 || NewArrayType != ArrayType
87 || NumStrips == kMaxNumStrips)
92 TotalVertices += NumNewVertices;
98 int stripLength = GetStripLength(NumStrips - 1);
99 if ((
float*)Vertices[NumStrips - 1] + WordsPerVertex * stripLength
100 == (
float*)NewVertices
102 || (
float*)Normals[NumStrips - 1] + WordsPerNormal * stripLength
103 == (
float*)NewNormals)
104 && (!AreTexCoordsValid
105 || (
float*)TexCoords[NumStrips - 1] + WordsPerTexCoord * stripLength
106 == (
float*)NewTexCoords)
108 || (
float*)Colors[NumStrips - 1] + WordsPerColor * stripLength
109 == (
float*)NewColors)) {
111 bool mergeUser =
true;
112 if (CGeomManager::IsUserPrimType(PrimType))
113 mergeUser = CGeomManager::GetUserPrimMerge(PrimType);
117 if (PrimType != GL_LINE_STRIP
118 && PrimType != GL_TRIANGLE_STRIP
119 && PrimType != GL_TRIANGLE_FAN
120 && PrimType != GL_QUAD_STRIP
123 StripLengths[NumStrips - 1] += (
unsigned int)NumNewVertices;
124 }
else if (PrimType != GL_TRIANGLE_FAN) {
125 StripLengths[NumStrips - 1] |= kContinueFlag;
131 Vertices[NumStrips] = NewVertices;
132 Normals[NumStrips] = NewNormals;
133 TexCoords[NumStrips] = NewTexCoords;
134 Colors[NumStrips] = NewColors;
136 StripLengths[NumStrips] = (
unsigned int)NumNewVertices;
148void CGeometryBlock::MakeNewValuesCurrent()
151 ArrayType = NewArrayType;
155 Vertices[NumStrips] = NewVertices;
156 Normals[NumStrips] = NewNormals;
157 TexCoords[NumStrips] = NewTexCoords;
158 Colors[NumStrips] = NewColors;
159 IStripLengths[NumStrips] = NewIStripLengths;
160 Indices[NumStrips] = NewIndices;
161 NumIndices[NumStrips] = NumNewIndices;
163 TotalVertices = NumNewVertices;
164 StripLengths[NumStrips] = (
unsigned int)NumNewVertices;
166 WordsPerVertex = WordsPerNewVertex;
167 WordsPerNormal = WordsPerNewNormal;
168 WordsPerTexCoord = WordsPerNewTexCoord;
169 WordsPerColor = WordsPerNewColor;
171 AreVerticesValid = AreNewVerticesValid;
172 AreNormalsValid = AreNewNormalsValid;
173 AreTexCoordsValid = AreNewTexCoordsValid;
174 AreColorsValid = AreNewColorsValid;
179void CGeometryBlock::ResetNew()
181 NewPrimType = GL_INVALID_VALUE;
182 NewArrayType = kInvalidArray;
183 NumNewVertices = NumNewNormals = NumNewTexCoords = NumNewColors = 0;
185 NewVertices = NewNormals = NewTexCoords = NewColors = NULL;
186 NewIndices = NewIStripLengths = NULL;
188 WordsPerNewVertex = WordsPerNewNormal = WordsPerNewTexCoord = WordsPerNewColor = 0;
189 AreNewVerticesValid = AreNewNormalsValid = AreNewTexCoordsValid = AreNewColorsValid =
false;
192void CGeometryBlock::ResetCurStrip()
194 Vertices[NumStrips] = Normals[NumStrips] = NULL;
195 TexCoords[NumStrips] = Colors[NumStrips] = NULL;
196 StripLengths[NumStrips] = 0;
197 Indices[NumStrips] = 0;
198 IStripLengths[NumStrips] = 0;
199 NumIndices[NumStrips] = 0;
202void CGeometryBlock::Reset()
205 WordsPerVertex = WordsPerNormal = WordsPerTexCoord = WordsPerColor = 0;
206 AreVerticesValid = AreNormalsValid = AreTexCoordsValid = AreColorsValid =
false;
207 PrimType = GL_INVALID_VALUE;
208 NumVertsPerPrim = NumVertsToRestartStrip = -1;
214void CGeometryBlock::CommitPrimType()
216 if (PrimType != NewPrimType) {
217 if (!CGeomManager::IsUserPrimType(NewPrimType)) {
218 switch (NewPrimType) {
221 NumVertsToRestartStrip = 0;
225 NumVertsToRestartStrip = 1;
227 case GL_TRIANGLE_STRIP:
228 case GL_TRIANGLE_FAN:
237 NumVertsToRestartStrip = 2;
241 NumVertsToRestartStrip = 0;
245 NumVertsToRestartStrip = 0;
249 NumVertsToRestartStrip = 0;
252 mError(
"Unknown prim type: 0x%08x", NewPrimType);
255 if (NewPrimType == GL_TRIANGLE_FAN)
256 StripsCanBeMerged =
false;
258 StripsCanBeMerged =
true;
261 PrimType = NewPrimType;