small index generator optimiztions

- rewrite loops to not use divisions and multiplications
- remove warnings as the current implementations seems to be correct (ignore additional vertices)
This commit is contained in:
degasus 2013-06-23 14:38:25 +02:00
parent b9953f5d6a
commit a2e132dd4b

View File

@ -80,14 +80,10 @@ template <bool pr> __forceinline void IndexGenerator::WriteTriangle(u32 index1,
template <bool pr> void IndexGenerator::AddList(u32 const numVerts) template <bool pr> void IndexGenerator::AddList(u32 const numVerts)
{ {
auto const numTris = numVerts / 3; for (u32 i = 2; i < numVerts; i+=3)
for (u32 i = 0; i != numTris; ++i)
{ {
WriteTriangle<pr>(index + i * 3, index + i * 3 + 1, index + i * 3 + 2); WriteTriangle<pr>(index + i - 2, index + i - 1, index + i);
} }
u32 remainingVerts = numVerts - numTris*3;
if(remainingVerts)
ERROR_LOG(VIDEO, "AddList: unknown count of vertices found");
} }
template <bool pr> void IndexGenerator::AddStrip(u32 const numVerts) template <bool pr> void IndexGenerator::AddStrip(u32 const numVerts)
@ -189,50 +185,41 @@ template <bool pr> void IndexGenerator::AddFan(u32 numVerts)
*/ */
template <bool pr> void IndexGenerator::AddQuads(u32 numVerts) template <bool pr> void IndexGenerator::AddQuads(u32 numVerts)
{ {
auto const numQuads = numVerts / 4; u32 i = 3;
for (u32 i = 0; i != numQuads; ++i) for (; i < numVerts; i+=4)
{ {
if(pr) if(pr)
{ {
*Tptr++ = index + i * 4 + 1; *Tptr++ = index + i - 2;
*Tptr++ = index + i * 4 + 2; *Tptr++ = index + i - 1;
*Tptr++ = index + i * 4 + 0; *Tptr++ = index + i - 3;
*Tptr++ = index + i * 4 + 3; *Tptr++ = index + i - 0;
*Tptr++ = s_primitive_restart; *Tptr++ = s_primitive_restart;
numT += 2; numT += 2;
} }
else else
{ {
WriteTriangle<pr>(index + i * 4, index + i * 4 + 1, index + i * 4 + 2); WriteTriangle<pr>(index + i - 3, index + i - 2, index + i - 1);
WriteTriangle<pr>(index + i * 4, index + i * 4 + 2, index + i * 4 + 3); WriteTriangle<pr>(index + i - 3, index + i - 1, index + i - 0);
} }
} }
// three vertices remaining, so render a triangle // three vertices remaining, so render a triangle
u32 remainingVerts = numVerts - numQuads*4; if(i == numVerts)
if(remainingVerts == 3)
{ {
WriteTriangle<pr>(index+numVerts-3, index+numVerts-2, index+numVerts-1); WriteTriangle<pr>(index+numVerts-3, index+numVerts-2, index+numVerts-1);
} }
else if(remainingVerts)
{
ERROR_LOG(VIDEO, "AddQuads: unknown count of vertices found");
}
} }
// Lines // Lines
void IndexGenerator::AddLineList(u32 numVerts) void IndexGenerator::AddLineList(u32 numVerts)
{ {
auto const numLines = numVerts / 2; for (u32 i = 1; i < numVerts; i+=2)
for (u32 i = 0; i != numLines; ++i)
{ {
*Lptr++ = index + i * 2; *Lptr++ = index + i - 1;
*Lptr++ = index + i * 2 + 1; *Lptr++ = index + i;
++numL; ++numL;
} }
u32 remainingVerts = numVerts - numLines*2;
if(remainingVerts)
ERROR_LOG(VIDEO, "AddLineList: unknown count of vertices found");
} }