diff --git a/Source/Core/VideoCommon/IndexGenerator.cpp b/Source/Core/VideoCommon/IndexGenerator.cpp index 884db29aee..0789ec1e1a 100644 --- a/Source/Core/VideoCommon/IndexGenerator.cpp +++ b/Source/Core/VideoCommon/IndexGenerator.cpp @@ -9,13 +9,13 @@ #include "IndexGenerator.h" //Init -u16 *IndexGenerator::Iptr; +u16 *IndexGenerator::index_buffer_current; u16 *IndexGenerator::BASEIptr; -u32 IndexGenerator::index; +u32 IndexGenerator::base_index; static const u16 s_primitive_restart = -1; -static void (*primitive_table[8])(u32); +static u16* (*primitive_table[8])(u16*, u32, u32); void IndexGenerator::Init() { @@ -41,36 +41,38 @@ void IndexGenerator::Init() void IndexGenerator::Start(u16* Indexptr) { - Iptr = Indexptr; + index_buffer_current = Indexptr; BASEIptr = Indexptr; - index = 0; + base_index = 0; } void IndexGenerator::AddIndices(int primitive, u32 numVerts) { - primitive_table[primitive](numVerts); - index += numVerts; + index_buffer_current = primitive_table[primitive](index_buffer_current, numVerts, base_index); + base_index += numVerts; } // Triangles -template __forceinline void IndexGenerator::WriteTriangle(u32 index1, u32 index2, u32 index3) +template __forceinline u16* IndexGenerator::WriteTriangle(u16 *Iptr, u32 index1, u32 index2, u32 index3) { *Iptr++ = index1; *Iptr++ = index2; *Iptr++ = index3; if(pr) *Iptr++ = s_primitive_restart; + return Iptr; } -template void IndexGenerator::AddList(u32 const numVerts) +template u16* IndexGenerator::AddList(u16 *Iptr, u32 const numVerts, u32 index) { for (u32 i = 2; i < numVerts; i+=3) { - WriteTriangle(index + i - 2, index + i - 1, index + i); + Iptr = WriteTriangle(Iptr, index + i - 2, index + i - 1, index + i); } + return Iptr; } -template void IndexGenerator::AddStrip(u32 const numVerts) +template u16* IndexGenerator::AddStrip(u16 *Iptr, u32 const numVerts, u32 index) { if(pr) { @@ -86,7 +88,7 @@ template void IndexGenerator::AddStrip(u32 const numVerts) bool wind = false; for (u32 i = 2; i < numVerts; ++i) { - WriteTriangle( + Iptr = WriteTriangle(Iptr, index + i - 2, index + i - !wind, index + i - wind); @@ -94,6 +96,7 @@ template void IndexGenerator::AddStrip(u32 const numVerts) wind ^= true; } } + return Iptr; } /** @@ -115,7 +118,7 @@ template void IndexGenerator::AddStrip(u32 const numVerts) * so we use 6 indices for 3 triangles */ -template void IndexGenerator::AddFan(u32 numVerts) +template u16* IndexGenerator::AddFan(u16 *Iptr, u32 numVerts, u32 index) { u32 i = 2; @@ -143,8 +146,9 @@ template void IndexGenerator::AddFan(u32 numVerts) for (; i < numVerts; ++i) { - WriteTriangle(index, index + i - 1, index + i); + Iptr = WriteTriangle(Iptr, index, index + i - 1, index + i); } + return Iptr; } /* @@ -164,7 +168,7 @@ template void IndexGenerator::AddFan(u32 numVerts) * A simple triangle has to be rendered for three vertices. * ZWW do this for sun rays */ -template void IndexGenerator::AddQuads(u32 numVerts) +template u16* IndexGenerator::AddQuads(u16 *Iptr, u32 numVerts, u32 index) { u32 i = 3; for (; i < numVerts; i+=4) @@ -179,52 +183,56 @@ template void IndexGenerator::AddQuads(u32 numVerts) } else { - WriteTriangle(index + i - 3, index + i - 2, index + i - 1); - WriteTriangle(index + i - 3, index + i - 1, index + i - 0); + Iptr = WriteTriangle(Iptr, index + i - 3, index + i - 2, index + i - 1); + Iptr = WriteTriangle(Iptr, index + i - 3, index + i - 1, index + i - 0); } } // three vertices remaining, so render a triangle if(i == numVerts) { - WriteTriangle(index+numVerts-3, index+numVerts-2, index+numVerts-1); + Iptr = WriteTriangle(Iptr, index+numVerts-3, index+numVerts-2, index+numVerts-1); } + return Iptr; } // Lines -void IndexGenerator::AddLineList(u32 numVerts) +u16* IndexGenerator::AddLineList(u16 *Iptr, u32 numVerts, u32 index) { for (u32 i = 1; i < numVerts; i+=2) { *Iptr++ = index + i - 1; *Iptr++ = index + i; } + return Iptr; } // shouldn't be used as strips as LineLists are much more common // so converting them to lists -void IndexGenerator::AddLineStrip(u32 numVerts) +u16* IndexGenerator::AddLineStrip(u16 *Iptr, u32 numVerts, u32 index) { for (u32 i = 1; i < numVerts; ++i) { *Iptr++ = index + i - 1; *Iptr++ = index + i; } + return Iptr; } // Points -void IndexGenerator::AddPoints(u32 numVerts) +u16* IndexGenerator::AddPoints(u16 *Iptr, u32 numVerts, u32 index) { for (u32 i = 0; i != numVerts; ++i) { *Iptr++ = index + i; } + return Iptr; } u32 IndexGenerator::GetRemainingIndices() { u32 max_index = 65534; // -1 is reserved for primitive restart (ogl + dx11) - return max_index - index; + return max_index - base_index; } diff --git a/Source/Core/VideoCommon/IndexGenerator.h b/Source/Core/VideoCommon/IndexGenerator.h index e6d1a0ba97..4b9a0fee3c 100644 --- a/Source/Core/VideoCommon/IndexGenerator.h +++ b/Source/Core/VideoCommon/IndexGenerator.h @@ -19,31 +19,31 @@ public: static void AddIndices(int primitive, u32 numVertices); // returns numprimitives - static u32 GetNumVerts() {return index;} + static u32 GetNumVerts() {return base_index;} - static u32 GetIndexLen() {return (u32)(Iptr - BASEIptr);} + static u32 GetIndexLen() {return (u32)(index_buffer_current - BASEIptr);} static u32 GetRemainingIndices(); private: // Triangles - template static void AddList(u32 numVerts); - template static void AddStrip(u32 numVerts); - template static void AddFan(u32 numVerts); - template static void AddQuads(u32 numVerts); + template static u16* AddList(u16 *Iptr, u32 numVerts, u32 index); + template static u16* AddStrip(u16 *Iptr, u32 numVerts, u32 index); + template static u16* AddFan(u16 *Iptr, u32 numVerts, u32 index); + template static u16* AddQuads(u16 *Iptr, u32 numVerts, u32 index); // Lines - static void AddLineList(u32 numVerts); - static void AddLineStrip(u32 numVerts); + static u16* AddLineList(u16 *Iptr, u32 numVerts, u32 index); + static u16* AddLineStrip(u16 *Iptr, u32 numVerts, u32 index); // Points - static void AddPoints(u32 numVerts); + static u16* AddPoints(u16 *Iptr, u32 numVerts, u32 index); - template static void WriteTriangle(u32 index1, u32 index2, u32 index3); + template static u16* WriteTriangle(u16 *Iptr, u32 index1, u32 index2, u32 index3); - static u16 *Iptr; + static u16 *index_buffer_current; static u16 *BASEIptr; - static u32 index; + static u32 base_index; }; #endif // _INDEXGENERATOR_H