From 4773f20fad64327929473bba08263df3853cbfe0 Mon Sep 17 00:00:00 2001 From: Henrik Rydgard Date: Mon, 28 Jan 2013 19:04:12 +0100 Subject: [PATCH] Fix spiky polygon glitches with vertex cache in Dissidia and maybe more. --- GPU/GLES/IndexGenerator.cpp | 302 +++++++++++++++++---------------- GPU/GLES/IndexGenerator.h | 36 ++-- GPU/GLES/TransformPipeline.cpp | 39 +++-- 3 files changed, 199 insertions(+), 178 deletions(-) diff --git a/GPU/GLES/IndexGenerator.cpp b/GPU/GLES/IndexGenerator.cpp index 9aba3ddf5e..612b9cbecb 100644 --- a/GPU/GLES/IndexGenerator.cpp +++ b/GPU/GLES/IndexGenerator.cpp @@ -116,126 +116,6 @@ void IndexGenerator::AddFan(int numVerts) seenPrims_ |= 1 << GE_PRIM_TRIANGLE_FAN; } -void IndexGenerator::TranslatePoints(int numVerts, const u8 *inds, int offset) -{ - for (int i = 0; i < numVerts; i++) - { - *inds_++ = index_ + offset + inds[i]; - } - index_ += numVerts; - count_ += numVerts; - prim_ = GE_PRIM_POINTS; - seenPrims_ |= (1 << GE_PRIM_POINTS) | SEEN_INDEX8; -} - -void IndexGenerator::TranslatePoints(int numVerts, const u16 *inds, int offset) -{ - for (int i = 0; i < numVerts; i++) - { - *inds_++ = index_ + offset + inds[i]; - } - index_ += numVerts; - count_ += numVerts; - prim_ = GE_PRIM_POINTS; - seenPrims_ |= (1 << GE_PRIM_POINTS) | SEEN_INDEX16; -} - -void IndexGenerator::TranslateList(int numVerts, const u8 *inds, int offset) -{ - int numTris = numVerts / 3; - for (int i = 0; i < numTris; i++) - { - *inds_++ = index_ + offset + inds[i*3]; - *inds_++ = index_ + offset + inds[i*3 + 1]; - *inds_++ = index_ + offset + inds[i*3 + 2]; - } - index_ += numVerts; - count_ += numTris * 3; - prim_ = GE_PRIM_TRIANGLES; - seenPrims_ |= (1 << GE_PRIM_TRIANGLES) | SEEN_INDEX8; -} - -void IndexGenerator::TranslateStrip(int numVerts, const u8 *inds, int offset) -{ - bool wind = false; - int numTris = numVerts - 2; - for (int i = 0; i < numTris; i++) - { - *inds_++ = index_ + offset + inds[i]; - *inds_++ = index_ + offset + inds[i + (wind?2:1)]; - *inds_++ = index_ + offset + inds[i + (wind?1:2)]; - wind = !wind; - } - index_ += numVerts; - count_ += numTris * 3; - prim_ = GE_PRIM_TRIANGLES; - seenPrims_ |= (1 << GE_PRIM_TRIANGLE_STRIP) | SEEN_INDEX8; -} - -void IndexGenerator::TranslateFan(int numVerts, const u8 *inds, int offset) -{ - if (numVerts <= 0) return; - int numTris = numVerts - 2; - for (int i = 0; i < numTris; i++) - { - *inds_++ = index_ + offset + inds[0]; - *inds_++ = index_ + offset + inds[i + 1]; - *inds_++ = index_ + offset + inds[i + 2]; - } - index_ += numVerts; - count_ += numTris * 3; - prim_ = GE_PRIM_TRIANGLES; - seenPrims_ |= (1 << GE_PRIM_TRIANGLE_FAN) | SEEN_INDEX8; -} - -void IndexGenerator::TranslateList(int numVerts, const u16 *inds, int offset) -{ - int numTris = numVerts / 3; - for (int i = 0; i < numTris; i++) - { - *inds_++ = index_ + offset + inds[i*3]; - *inds_++ = index_ + offset + inds[i*3 + 1]; - *inds_++ = index_ + offset + inds[i*3 + 2]; - } - index_ += numVerts; - count_ += numTris * 3; - prim_ = GE_PRIM_TRIANGLES; - seenPrims_ |= (1 << GE_PRIM_TRIANGLES) | SEEN_INDEX16; -} - -void IndexGenerator::TranslateStrip(int numVerts, const u16 *inds, int offset) -{ - bool wind = false; - int numTris = numVerts - 2; - for (int i = 0; i < numTris; i++) - { - *inds_++ = index_ + offset + inds[i]; - *inds_++ = index_ + offset + inds[i + (wind?2:1)]; - *inds_++ = index_ + offset + inds[i + (wind?1:2)]; - wind = !wind; - } - index_ += numVerts; - count_ += numTris * 3; - prim_ = GE_PRIM_TRIANGLES; - seenPrims_ |= (1 << GE_PRIM_TRIANGLE_STRIP) | SEEN_INDEX16; -} - -void IndexGenerator::TranslateFan(int numVerts, const u16 *inds, int offset) -{ - if (numVerts <= 0) return; - int numTris = numVerts - 2; - for (int i = 0; i < numTris; i++) - { - *inds_++ = index_ + offset + inds[0]; - *inds_++ = index_ + offset + inds[i + 1]; - *inds_++ = index_ + offset + inds[i + 2]; - } - index_ += numVerts; - count_ += numTris * 3; - prim_ = GE_PRIM_TRIANGLES; - seenPrims_ |= (1 << GE_PRIM_TRIANGLE_FAN) | SEEN_INDEX16; -} - //Lines void IndexGenerator::AddLineList(int numVerts) { @@ -279,13 +159,142 @@ void IndexGenerator::AddRectangles(int numVerts) seenPrims_ |= 1 << GE_PRIM_RECTANGLES; } -void IndexGenerator::TranslateLineList(int numVerts, const u8 *inds, int offset) +void IndexGenerator::TranslatePoints(int numInds, const u8 *inds, int indexLowerBound, int indexUpperBound) { - int numLines = numVerts / 2; + int numVerts = indexUpperBound - indexLowerBound + 1; + for (int i = 0; i < numInds; i++) + { + *inds_++ = index_ - indexLowerBound + inds[i]; + } + index_ += numVerts; + count_ += numInds; + prim_ = GE_PRIM_POINTS; + seenPrims_ |= (1 << GE_PRIM_POINTS) | SEEN_INDEX8; +} + +void IndexGenerator::TranslatePoints(int numInds, const u16 *inds, int indexLowerBound, int indexUpperBound) +{ + int numVerts = indexUpperBound - indexLowerBound + 1; + for (int i = 0; i < numInds; i++) + { + *inds_++ = index_ - indexLowerBound + inds[i]; + } + index_ += numVerts; + count_ += numInds; + prim_ = GE_PRIM_POINTS; + seenPrims_ |= (1 << GE_PRIM_POINTS) | SEEN_INDEX16; +} + +void IndexGenerator::TranslateList(int numInds, const u8 *inds, int indexLowerBound, int indexUpperBound) +{ + int numVerts = indexUpperBound - indexLowerBound + 1; + int numTris = numInds / 3; + for (int i = 0; i < numTris; i++) + { + *inds_++ = index_ - indexLowerBound + inds[i*3]; + *inds_++ = index_ - indexLowerBound + inds[i*3 + 1]; + *inds_++ = index_ - indexLowerBound + inds[i*3 + 2]; + } + index_ += numVerts; + count_ += numTris * 3; + prim_ = GE_PRIM_TRIANGLES; + seenPrims_ |= (1 << GE_PRIM_TRIANGLES) | SEEN_INDEX8; +} + +void IndexGenerator::TranslateStrip(int numInds, const u8 *inds, int indexLowerBound, int indexUpperBound) +{ + int numVerts = indexUpperBound - indexLowerBound + 1; + bool wind = false; + int numTris = numInds - 2; + for (int i = 0; i < numTris; i++) + { + *inds_++ = index_ - indexLowerBound + inds[i]; + *inds_++ = index_ - indexLowerBound + inds[i + (wind?2:1)]; + *inds_++ = index_ - indexLowerBound + inds[i + (wind?1:2)]; + wind = !wind; + } + index_ += numVerts; + count_ += numTris * 3; + prim_ = GE_PRIM_TRIANGLES; + seenPrims_ |= (1 << GE_PRIM_TRIANGLE_STRIP) | SEEN_INDEX8; +} + +void IndexGenerator::TranslateFan(int numInds, const u8 *inds, int indexLowerBound, int indexUpperBound) +{ + int numVerts = indexUpperBound - indexLowerBound + 1; + if (numInds <= 0) return; + int numTris = numInds - 2; + for (int i = 0; i < numTris; i++) + { + *inds_++ = index_ - indexLowerBound + inds[0]; + *inds_++ = index_ - indexLowerBound + inds[i + 1]; + *inds_++ = index_ - indexLowerBound + inds[i + 2]; + } + index_ += numVerts; + count_ += numTris * 3; + prim_ = GE_PRIM_TRIANGLES; + seenPrims_ |= (1 << GE_PRIM_TRIANGLE_FAN) | SEEN_INDEX8; +} + +void IndexGenerator::TranslateList(int numInds, const u16 *inds, int indexLowerBound, int indexUpperBound) +{ + int numVerts = indexUpperBound - indexLowerBound + 1; + int numTris = numInds / 3; + for (int i = 0; i < numTris; i++) + { + *inds_++ = index_ - indexLowerBound + inds[i*3]; + *inds_++ = index_ - indexLowerBound + inds[i*3 + 1]; + *inds_++ = index_ - indexLowerBound + inds[i*3 + 2]; + } + index_ += numVerts; + count_ += numTris * 3; + prim_ = GE_PRIM_TRIANGLES; + seenPrims_ |= (1 << GE_PRIM_TRIANGLES) | SEEN_INDEX16; +} + +void IndexGenerator::TranslateStrip(int numInds, const u16 *inds, int indexLowerBound, int indexUpperBound) +{ + int numVerts = indexUpperBound - indexLowerBound + 1; + bool wind = false; + int numTris = numInds - 2; + for (int i = 0; i < numTris; i++) + { + *inds_++ = index_ - indexLowerBound + inds[i]; + *inds_++ = index_ - indexLowerBound + inds[i + (wind?2:1)]; + *inds_++ = index_ - indexLowerBound + inds[i + (wind?1:2)]; + wind = !wind; + } + index_ += numVerts; + count_ += numTris * 3; + prim_ = GE_PRIM_TRIANGLES; + seenPrims_ |= (1 << GE_PRIM_TRIANGLE_STRIP) | SEEN_INDEX16; +} + +void IndexGenerator::TranslateFan(int numInds, const u16 *inds, int indexLowerBound, int indexUpperBound) +{ + int numVerts = indexUpperBound - indexLowerBound + 1; + if (numInds <= 0) return; + int numTris = numInds - 2; + for (int i = 0; i < numTris; i++) + { + *inds_++ = index_ - indexLowerBound + inds[0]; + *inds_++ = index_ - indexLowerBound + inds[i + 1]; + *inds_++ = index_ - indexLowerBound + inds[i + 2]; + } + index_ += numVerts; + count_ += numTris * 3; + prim_ = GE_PRIM_TRIANGLES; + seenPrims_ |= (1 << GE_PRIM_TRIANGLE_FAN) | SEEN_INDEX16; +} + +void IndexGenerator::TranslateLineList(int numInds, const u8 *inds, int indexLowerBound, int indexUpperBound) +{ + int numVerts = indexUpperBound - indexLowerBound + 1; + int numLines = numInds / 2; for (int i = 0; i < numLines; i++) { - *inds_++ = index_ + offset + inds[i*2]; - *inds_++ = index_ + offset + inds[i*2+1]; + *inds_++ = index_ - indexLowerBound + inds[i*2]; + *inds_++ = index_ - indexLowerBound + inds[i*2+1]; } index_ += numVerts; count_ += numLines * 2; @@ -293,13 +302,14 @@ void IndexGenerator::TranslateLineList(int numVerts, const u8 *inds, int offset) seenPrims_ |= (1 << GE_PRIM_LINES) | SEEN_INDEX8; } -void IndexGenerator::TranslateLineStrip(int numVerts, const u8 *inds, int offset) +void IndexGenerator::TranslateLineStrip(int numInds, const u8 *inds, int indexLowerBound, int indexUpperBound) { - int numLines = numVerts - 1; + int numVerts = indexUpperBound - indexLowerBound + 1; + int numLines = numInds - 1; for (int i = 0; i < numLines; i++) { - *inds_++ = index_ + offset + inds[i]; - *inds_++ = index_ + offset + inds[i + 1]; + *inds_++ = index_ - indexLowerBound + inds[i]; + *inds_++ = index_ - indexLowerBound + inds[i + 1]; } index_ += numVerts; count_ += numLines * 2; @@ -307,13 +317,14 @@ void IndexGenerator::TranslateLineStrip(int numVerts, const u8 *inds, int offset seenPrims_ |= (1 << GE_PRIM_LINE_STRIP) | SEEN_INDEX8; } -void IndexGenerator::TranslateLineList(int numVerts, const u16 *inds, int offset) +void IndexGenerator::TranslateLineList(int numInds, const u16 *inds, int indexLowerBound, int indexUpperBound) { - int numLines = numVerts / 2; + int numVerts = indexUpperBound - indexLowerBound + 1; + int numLines = numInds / 2; for (int i = 0; i < numLines; i++) { - *inds_++ = index_ + offset + inds[i*2]; - *inds_++ = index_ + offset + inds[i*2+1]; + *inds_++ = index_ - indexLowerBound + inds[i*2]; + *inds_++ = index_ - indexLowerBound + inds[i*2+1]; } index_ += numVerts; count_ += numLines * 2; @@ -321,13 +332,14 @@ void IndexGenerator::TranslateLineList(int numVerts, const u16 *inds, int offset seenPrims_ |= (1 << GE_PRIM_LINES) | SEEN_INDEX16; } -void IndexGenerator::TranslateLineStrip(int numVerts, const u16 *inds, int offset) +void IndexGenerator::TranslateLineStrip(int numInds, const u16 *inds, int indexLowerBound, int indexUpperBound) { - int numLines = numVerts - 1; + int numVerts = indexUpperBound - indexLowerBound + 1; + int numLines = numInds - 1; for (int i = 0; i < numLines; i++) { - *inds_++ = index_ + offset + inds[i]; - *inds_++ = index_ + offset + inds[i + 1]; + *inds_++ = index_ - indexLowerBound + inds[i]; + *inds_++ = index_ - indexLowerBound + inds[i + 1]; } index_ += numVerts; count_ += numLines * 2; @@ -335,13 +347,14 @@ void IndexGenerator::TranslateLineStrip(int numVerts, const u16 *inds, int offse seenPrims_ |= (1 << GE_PRIM_LINE_STRIP) | SEEN_INDEX16; } -void IndexGenerator::TranslateRectangles(int numVerts, const u8 *inds, int offset) +void IndexGenerator::TranslateRectangles(int numInds, const u8 *inds, int indexLowerBound, int indexUpperBound) { - int numRects = numVerts / 2; + int numVerts = indexUpperBound - indexLowerBound + 1; + int numRects = numInds / 2; for (int i = 0; i < numRects; i++) { - *inds_++ = index_ + offset + inds[i*2]; - *inds_++ = index_ + offset + inds[i*2+1]; + *inds_++ = index_ - indexLowerBound + inds[i*2]; + *inds_++ = index_ - indexLowerBound + inds[i*2+1]; } index_ += numVerts; count_ += numRects * 2; @@ -349,13 +362,14 @@ void IndexGenerator::TranslateRectangles(int numVerts, const u8 *inds, int offse seenPrims_ |= (1 << GE_PRIM_RECTANGLES) | SEEN_INDEX8; } -void IndexGenerator::TranslateRectangles(int numVerts, const u16 *inds, int offset) +void IndexGenerator::TranslateRectangles(int numInds, const u16 *inds, int indexLowerBound, int indexUpperBound) { - int numRects = numVerts / 2; + int numVerts = indexUpperBound - indexLowerBound + 1; + int numRects = numInds / 2; for (int i = 0; i < numRects; i++) { - *inds_++ = index_ + offset + inds[i*2]; - *inds_++ = index_ + offset + inds[i*2+1]; + *inds_++ = index_ - indexLowerBound + inds[i*2]; + *inds_++ = index_ - indexLowerBound + inds[i*2+1]; } index_ += numVerts; count_ += numRects * 2; diff --git a/GPU/GLES/IndexGenerator.h b/GPU/GLES/IndexGenerator.h index 38f49f4903..2d1bbfdd86 100644 --- a/GPU/GLES/IndexGenerator.h +++ b/GPU/GLES/IndexGenerator.h @@ -18,8 +18,10 @@ #pragma once +#include #include "CommonTypes.h" #include "../ge_constants.h" +#undef max class IndexGenerator { @@ -42,28 +44,28 @@ public: // Rectangles void AddRectangles(int numVerts); - void TranslatePoints(int numVerts, const u8 *inds, int offset); - void TranslatePoints(int numVerts, const u16 *inds, int offset); + void TranslatePoints(int numVerts, const u8 *inds, int indexLowerBound, int indexUpperBound); + void TranslatePoints(int numVerts, const u16 *inds, int indexLowerBound, int indexUpperBound); // Translates already indexed lists - void TranslateLineList(int numVerts, const u8 *inds, int offset); - void TranslateLineList(int numVerts, const u16 *inds, int offset); - void TranslateLineStrip(int numVerts, const u8 *inds, int offset); - void TranslateLineStrip(int numVerts, const u16 *inds, int offset); + void TranslateLineList(int numVerts, const u8 *inds, int indexLowerBound, int indexUpperBound); + void TranslateLineList(int numVerts, const u16 *inds, int indexLowerBound, int indexUpperBound); + void TranslateLineStrip(int numVerts, const u8 *inds, int indexLowerBound, int indexUpperBound); + void TranslateLineStrip(int numVerts, const u16 *inds, int indexLowerBound, int indexUpperBound); - void TranslateRectangles(int numVerts, const u8 *inds, int offset); - void TranslateRectangles(int numVerts, const u16 *inds, int offset); + void TranslateRectangles(int numVerts, const u8 *inds, int indexLowerBound, int indexUpperBound); + void TranslateRectangles(int numVerts, const u16 *inds, int indexLowerBound, int indexUpperBound); - void TranslateList(int numVerts, const u8 *inds, int offset); - void TranslateStrip(int numVerts, const u8 *inds, int offset); - void TranslateFan(int numVerts, const u8 *inds, int offset); - void TranslateList(int numVerts, const u16 *inds, int offset); - void TranslateStrip(int numVerts, const u16 *inds, int offset); - void TranslateFan(int numVerts, const u16 *inds, int offset); + void TranslateList(int numVerts, const u8 *inds, int indexLowerBound, int indexUpperBound); + void TranslateList(int numVerts, const u16 *inds, int indexLowerBound, int indexUpperBound); + void TranslateStrip(int numVerts, const u8 *inds, int indexLowerBound, int indexUpperBound); + void TranslateStrip(int numVerts, const u16 *inds, int indexLowerBound, int indexUpperBound); + void TranslateFan(int numVerts, const u8 *inds, int indexLowerBound, int indexUpperBound); + void TranslateFan(int numVerts, const u16 *inds, int indexLowerBound, int indexUpperBound); - int MaxIndex() { return index_; } - int VertexCount() { return count_; } + int MaxIndex() const { return index_; } + int VertexCount() const { return count_; } - bool Empty() { return index_ == 0; } + bool Empty() const { return index_ == 0; } void SetIndex(int ind) { index_ = ind; } int SeenPrims() const { return seenPrims_; } diff --git a/GPU/GLES/TransformPipeline.cpp b/GPU/GLES/TransformPipeline.cpp index 86662422f1..eef9d57bcb 100644 --- a/GPU/GLES/TransformPipeline.cpp +++ b/GPU/GLES/TransformPipeline.cpp @@ -675,7 +675,6 @@ void TransformDrawEngine::SubmitPrim(void *verts, void *inds, int prim, int vert if (!indexGen.PrimCompatible(prevPrim_, prim) || numDrawCalls >= MAX_DEFERRED_DRAW_CALLS) Flush(); - prevPrim_ = prim; // If vtype has changed, setup the vertex decoder. // TODO: Simply cache the setup decoders instead. @@ -738,25 +737,25 @@ void TransformDrawEngine::DecodeVerts() { case GE_VTYPE_IDX_8BIT >> GE_VTYPE_IDX_SHIFT: switch (dc.prim) { - case GE_PRIM_POINTS: indexGen.TranslatePoints(vertexCount, (const u8 *)inds, -indexLowerBound); break; - case GE_PRIM_LINES: indexGen.TranslateLineList(vertexCount, (const u8 *)inds, -indexLowerBound); break; - case GE_PRIM_LINE_STRIP: indexGen.TranslateLineStrip(vertexCount, (const u8 *)inds, -indexLowerBound); break; - case GE_PRIM_TRIANGLES: indexGen.TranslateList(vertexCount, (const u8 *)inds, -indexLowerBound); break; - case GE_PRIM_TRIANGLE_STRIP: indexGen.TranslateStrip(vertexCount, (const u8 *)inds, -indexLowerBound); break; - case GE_PRIM_TRIANGLE_FAN: indexGen.TranslateFan(vertexCount, (const u8 *)inds, -indexLowerBound); break; - case GE_PRIM_RECTANGLES: indexGen.TranslateRectangles(vertexCount, (const u8 *)inds, -indexLowerBound); break; // Same + case GE_PRIM_POINTS: indexGen.TranslatePoints(vertexCount, (const u8 *)inds, indexLowerBound, indexUpperBound); break; + case GE_PRIM_LINES: indexGen.TranslateLineList(vertexCount, (const u8 *)inds, indexLowerBound, indexUpperBound); break; + case GE_PRIM_LINE_STRIP: indexGen.TranslateLineStrip(vertexCount, (const u8 *)inds, indexLowerBound, indexUpperBound); break; + case GE_PRIM_TRIANGLES: indexGen.TranslateList(vertexCount, (const u8 *)inds, indexLowerBound, indexUpperBound); break; + case GE_PRIM_TRIANGLE_STRIP: indexGen.TranslateStrip(vertexCount, (const u8 *)inds, indexLowerBound, indexUpperBound); break; + case GE_PRIM_TRIANGLE_FAN: indexGen.TranslateFan(vertexCount, (const u8 *)inds, indexLowerBound, indexUpperBound); break; + case GE_PRIM_RECTANGLES: indexGen.TranslateRectangles(vertexCount, (const u8 *)inds, indexLowerBound, indexUpperBound); break; // Same } break; case GE_VTYPE_IDX_16BIT >> GE_VTYPE_IDX_SHIFT: switch (dc.prim) { - case GE_PRIM_POINTS: indexGen.TranslatePoints(vertexCount, (const u16 *)inds, -indexLowerBound); break; - case GE_PRIM_LINES: indexGen.TranslateLineList(vertexCount, (const u16 *)inds, -indexLowerBound); break; - case GE_PRIM_LINE_STRIP: indexGen.TranslateLineStrip(vertexCount, (const u16 *)inds, -indexLowerBound); break; - case GE_PRIM_TRIANGLES: indexGen.TranslateList(vertexCount, (const u16 *)inds, -indexLowerBound); break; - case GE_PRIM_TRIANGLE_STRIP: indexGen.TranslateStrip(vertexCount, (const u16 *)inds, -indexLowerBound); break; - case GE_PRIM_TRIANGLE_FAN: indexGen.TranslateFan(vertexCount, (const u16 *)inds, -indexLowerBound); break; - case GE_PRIM_RECTANGLES: indexGen.TranslateRectangles(vertexCount, (const u16 *)inds, -indexLowerBound); break; // Same + case GE_PRIM_POINTS: indexGen.TranslatePoints(vertexCount, (const u16 *)inds, indexLowerBound, indexUpperBound); break; + case GE_PRIM_LINES: indexGen.TranslateLineList(vertexCount, (const u16 *)inds, indexLowerBound, indexUpperBound); break; + case GE_PRIM_LINE_STRIP: indexGen.TranslateLineStrip(vertexCount, (const u16 *)inds, indexLowerBound, indexUpperBound); break; + case GE_PRIM_TRIANGLES: indexGen.TranslateList(vertexCount, (const u16 *)inds, indexLowerBound, indexUpperBound); break; + case GE_PRIM_TRIANGLE_STRIP: indexGen.TranslateStrip(vertexCount, (const u16 *)inds, indexLowerBound, indexUpperBound); break; + case GE_PRIM_TRIANGLE_FAN: indexGen.TranslateFan(vertexCount, (const u16 *)inds, indexLowerBound, indexUpperBound); break; + case GE_PRIM_RECTANGLES: indexGen.TranslateRectangles(vertexCount, (const u16 *)inds, indexLowerBound, indexUpperBound); break; // Same } break; } @@ -909,6 +908,12 @@ void TransformDrawEngine::Flush() { // there is no need for the index buffer we built. We can then use glDrawArrays instead // for a very minor speed boost. if (useElements) { + // Sanity Check + for (int i = 0; i < indexGen.VertexCount(); i++) { + if (decIndex[i] >= indexGen.MaxIndex()) { + ERROR_LOG(G3D, "WTF? %i %i", indexGen.VertexCount(), indexGen.MaxIndex()); + } + } glGenBuffers(1, &vai->ebo); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vai->ebo); glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(short) * indexGen.VertexCount(), (GLvoid *)decIndex, GL_STATIC_DRAW); @@ -958,6 +963,7 @@ void TransformDrawEngine::Flush() { rotateVBO: gpuStats.numUncachedVertsDrawn += indexGen.VertexCount(); useElements = !indexGen.SeenOnlyPurePrims(); + vertexCount = indexGen.VertexCount(); if (g_Config.bUseVBO) { // Just rotate VBO. vbo = vbo_[curVbo_]; @@ -969,13 +975,12 @@ rotateVBO: glBufferData(GL_ARRAY_BUFFER, dec.GetDecVtxFmt().stride * indexGen.MaxIndex(), decoded, GL_STREAM_DRAW); if (useElements) { glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo); - glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(short) * indexGen.VertexCount(), (GLvoid *)decIndex, GL_STREAM_DRAW); + glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(short) * vertexCount, (GLvoid *)decIndex, GL_STREAM_DRAW); } } else { glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); } - vertexCount = indexGen.VertexCount(); prim = indexGen.Prim(); }