From a2e132dd4b53d636641ecc4e74fdab7444f4b68e Mon Sep 17 00:00:00 2001 From: degasus Date: Sun, 23 Jun 2013 14:38:25 +0200 Subject: [PATCH] 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) --- .../Core/VideoCommon/Src/IndexGenerator.cpp | 41 +++++++------------ 1 file changed, 14 insertions(+), 27 deletions(-) diff --git a/Source/Core/VideoCommon/Src/IndexGenerator.cpp b/Source/Core/VideoCommon/Src/IndexGenerator.cpp index 3970d8c82f..25597862e0 100644 --- a/Source/Core/VideoCommon/Src/IndexGenerator.cpp +++ b/Source/Core/VideoCommon/Src/IndexGenerator.cpp @@ -80,14 +80,10 @@ template __forceinline void IndexGenerator::WriteTriangle(u32 index1, template void IndexGenerator::AddList(u32 const numVerts) { - auto const numTris = numVerts / 3; - for (u32 i = 0; i != numTris; ++i) + for (u32 i = 2; i < numVerts; i+=3) { - WriteTriangle(index + i * 3, index + i * 3 + 1, index + i * 3 + 2); + WriteTriangle(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 void IndexGenerator::AddStrip(u32 const numVerts) @@ -189,50 +185,41 @@ template void IndexGenerator::AddFan(u32 numVerts) */ template void IndexGenerator::AddQuads(u32 numVerts) { - auto const numQuads = numVerts / 4; - for (u32 i = 0; i != numQuads; ++i) + u32 i = 3; + for (; i < numVerts; i+=4) { if(pr) { - *Tptr++ = index + i * 4 + 1; - *Tptr++ = index + i * 4 + 2; - *Tptr++ = index + i * 4 + 0; - *Tptr++ = index + i * 4 + 3; + *Tptr++ = index + i - 2; + *Tptr++ = index + i - 1; + *Tptr++ = index + i - 3; + *Tptr++ = index + i - 0; *Tptr++ = s_primitive_restart; numT += 2; } else { - WriteTriangle(index + i * 4, index + i * 4 + 1, index + i * 4 + 2); - WriteTriangle(index + i * 4, index + i * 4 + 2, index + i * 4 + 3); + WriteTriangle(index + i - 3, index + i - 2, index + i - 1); + WriteTriangle(index + i - 3, index + i - 1, index + i - 0); } } // three vertices remaining, so render a triangle - u32 remainingVerts = numVerts - numQuads*4; - if(remainingVerts == 3) + if(i == numVerts) { WriteTriangle(index+numVerts-3, index+numVerts-2, index+numVerts-1); } - else if(remainingVerts) - { - ERROR_LOG(VIDEO, "AddQuads: unknown count of vertices found"); - } } // Lines void IndexGenerator::AddLineList(u32 numVerts) { - auto const numLines = numVerts / 2; - for (u32 i = 0; i != numLines; ++i) + for (u32 i = 1; i < numVerts; i+=2) { - *Lptr++ = index + i * 2; - *Lptr++ = index + i * 2 + 1; + *Lptr++ = index + i - 1; + *Lptr++ = index + i; ++numL; } - u32 remainingVerts = numVerts - numLines*2; - if(remainingVerts) - ERROR_LOG(VIDEO, "AddLineList: unknown count of vertices found"); }