Let's try rodolfo's fix of 4322
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4343 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
parent
4d5eba2ec9
commit
e6b30e574e
|
@ -145,3 +145,152 @@ void IndexGenerator::AddPoints(int numVerts)
|
|||
numPrims += numVerts;
|
||||
adds++;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//Init
|
||||
void IndexGenerator2::Start(unsigned short *Triangleptr,unsigned short *Lineptr,unsigned short *Pointptr)
|
||||
{
|
||||
Tptr = Triangleptr;
|
||||
Lptr = Lineptr;
|
||||
Pptr = Pointptr;
|
||||
index = 0;
|
||||
numT = 0;
|
||||
numL = 0;
|
||||
numP = 0;
|
||||
Tadds = 0;
|
||||
Ladds = 0;
|
||||
Padds = 0;
|
||||
TindexLen = 0;
|
||||
LindexLen = 0;
|
||||
PindexLen = 0;
|
||||
LastTPrimitive = None;
|
||||
LastLPrimitive = None;
|
||||
}
|
||||
// Triangles
|
||||
void IndexGenerator2::AddList(int numVerts)
|
||||
{
|
||||
int numTris = numVerts / 3;
|
||||
if (numTris <= 0) return;
|
||||
for (int i = 0; i < numTris; i++)
|
||||
{
|
||||
*Tptr++ = index+i*3;
|
||||
*Tptr++ = index+i*3+1;
|
||||
*Tptr++ = index+i*3+2;
|
||||
}
|
||||
TindexLen += numVerts;
|
||||
index += numVerts;
|
||||
numT += numTris;
|
||||
Tadds++;
|
||||
LastTPrimitive = List;
|
||||
}
|
||||
|
||||
void IndexGenerator2::AddStrip(int numVerts)
|
||||
{
|
||||
int numTris = numVerts - 2;
|
||||
if (numTris <= 0) return;
|
||||
bool wind = false;
|
||||
for (int i = 0; i < numTris; i++)
|
||||
{
|
||||
*Tptr++ = index+i;
|
||||
*Tptr++ = index+i+(wind?2:1);
|
||||
*Tptr++ = index+i+(wind?1:2);
|
||||
wind = !wind;
|
||||
}
|
||||
TindexLen += numTris * 3;
|
||||
index += numVerts;
|
||||
numT += numTris;
|
||||
Tadds++;
|
||||
LastTPrimitive = Strip;
|
||||
}
|
||||
void IndexGenerator2::AddFan(int numVerts)
|
||||
{
|
||||
int numTris = numVerts - 2;
|
||||
if (numTris <= 0) return;
|
||||
for (int i = 0; i < numTris; i++)
|
||||
{
|
||||
*Tptr++ = index;
|
||||
*Tptr++ = index+i+1;
|
||||
*Tptr++ = index+i+2;
|
||||
}
|
||||
TindexLen += numTris * 3;
|
||||
index += numVerts;
|
||||
numT += numTris;
|
||||
Tadds++;
|
||||
LastTPrimitive = Fan;
|
||||
}
|
||||
|
||||
void IndexGenerator2::AddQuads(int numVerts)
|
||||
{
|
||||
int numTris = (numVerts/4)*2;
|
||||
if (numTris <= 0) return;
|
||||
for (int i = 0; i < numTris / 2; i++)
|
||||
{
|
||||
*Tptr++ = index+i*4;
|
||||
*Tptr++ = index+i*4+1;
|
||||
*Tptr++ = index+i*4+3;
|
||||
*Tptr++ = index+i*4+1;
|
||||
*Tptr++ = index+i*4+2;
|
||||
*Tptr++ = index+i*4+3;
|
||||
}
|
||||
TindexLen += numTris * 3;
|
||||
index += numVerts;
|
||||
numT += numTris;
|
||||
Tadds++;
|
||||
LastTPrimitive = List;
|
||||
}
|
||||
|
||||
|
||||
//Lines
|
||||
void IndexGenerator2::AddLineList(int numVerts)
|
||||
{
|
||||
int numLines= numVerts / 2;
|
||||
if (numLines <= 0) return;
|
||||
for (int i = 0; i < numLines; i++)
|
||||
{
|
||||
*Lptr++ = index+i*2;
|
||||
*Lptr++ = index+i*2+1;
|
||||
}
|
||||
LindexLen += numVerts;
|
||||
index += numVerts;
|
||||
numL += numLines;
|
||||
Ladds++;
|
||||
LastLPrimitive = List;
|
||||
}
|
||||
|
||||
void IndexGenerator2::AddLineStrip(int numVerts)
|
||||
{
|
||||
int numLines = numVerts - 1;
|
||||
if (numLines <= 0) return;
|
||||
for (int i = 0; i < numLines; i++)
|
||||
{
|
||||
*Lptr++ = index+i;
|
||||
*Lptr++ = index+i+1;
|
||||
}
|
||||
LindexLen += numLines * 2;
|
||||
index += numVerts;
|
||||
numL += numLines;
|
||||
Ladds++;
|
||||
LastLPrimitive = Strip;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//Points
|
||||
void IndexGenerator2::AddPoints(int numVerts)
|
||||
{
|
||||
for (int i = 0; i < numVerts; i++)
|
||||
{
|
||||
*Pptr++ = index+i;
|
||||
}
|
||||
index += numVerts;
|
||||
numP += numVerts;
|
||||
PindexLen+=numVerts;
|
||||
Padds++;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -21,6 +21,8 @@
|
|||
#ifndef _INDEXGENERATOR_H
|
||||
#define _INDEXGENERATOR_H
|
||||
|
||||
|
||||
|
||||
class IndexGenerator
|
||||
{
|
||||
public:
|
||||
|
@ -46,4 +48,55 @@ private:
|
|||
bool onlyLists;
|
||||
};
|
||||
|
||||
class IndexGenerator2
|
||||
{
|
||||
public:
|
||||
//Init
|
||||
void Start(unsigned short *Triangleptr,unsigned short *Lineptr,unsigned short *Pointptr);
|
||||
//Triangles
|
||||
void AddList(int numVerts);
|
||||
void AddStrip(int numVerts);
|
||||
void AddFan(int numVerts);
|
||||
void AddQuads(int numVerts);
|
||||
//Lines
|
||||
void AddLineList(int numVerts);
|
||||
void AddLineStrip(int numVerts);
|
||||
//Points
|
||||
void AddPoints(int numVerts);
|
||||
//Interface
|
||||
int GetNumTriangles() {return numT;}
|
||||
int GetNumLines() {return numL;}
|
||||
int GetNumPoints() {return numP;}
|
||||
int GetNumVerts() {return index;} //returns numprimitives
|
||||
int GetNumAdds() {return Tadds + Ladds + Padds;}
|
||||
int GetTriangleindexLen() {return TindexLen;}
|
||||
int GetLineindexLen() {return LindexLen;}
|
||||
int GetPointindexLen() {return PindexLen;}
|
||||
public:
|
||||
enum IndexPrimitiveType
|
||||
{
|
||||
None,
|
||||
List,
|
||||
Strip,
|
||||
Fan
|
||||
};
|
||||
private:
|
||||
unsigned short *Tptr;
|
||||
unsigned short *Lptr;
|
||||
unsigned short *Pptr;
|
||||
int numT;
|
||||
int numL;
|
||||
int numP;
|
||||
int index;
|
||||
int Tadds;
|
||||
int Ladds;
|
||||
int Padds;
|
||||
int TindexLen;
|
||||
int LindexLen;
|
||||
int PindexLen;
|
||||
IndexPrimitiveType LastTPrimitive;
|
||||
IndexPrimitiveType LastLPrimitive;
|
||||
|
||||
};
|
||||
|
||||
#endif // _INDEXGENERATOR_H
|
|
@ -39,8 +39,6 @@
|
|||
#include "VertexManager.h"
|
||||
#include "IndexGenerator.h"
|
||||
|
||||
#define MAX_BUFFER_SIZE 0x50000
|
||||
|
||||
// internal state for loading vertices
|
||||
extern NativeVertexFormat *g_nativeVertexFmt;
|
||||
|
||||
|
@ -71,20 +69,21 @@ static const GLenum c_primitiveType[8] =
|
|||
GL_POINTS
|
||||
};
|
||||
|
||||
static IndexGenerator indexGen;
|
||||
static IndexGenerator2 indexGen;
|
||||
|
||||
static GLenum lastPrimitive;
|
||||
static GLenum CurrentRenderPrimitive;
|
||||
|
||||
static u8 *LocalVBuffer;
|
||||
static u16 *IBuffer;
|
||||
static u16 *TIBuffer;
|
||||
static u16 *LIBuffer;
|
||||
static u16 *PIBuffer;
|
||||
|
||||
#define MAXVBUFFERSIZE 0x50000
|
||||
#define MAXIBUFFERSIZE 0x20000
|
||||
#define MAXVBOBUFFERCOUNT 0x4
|
||||
|
||||
static GLuint s_vboBuffers[MAXVBOBUFFERCOUNT] = {0};
|
||||
static GLuint s_IBuffers[MAXVBOBUFFERCOUNT] = {0};
|
||||
static int s_nCurVBOIndex = 0; // current free buffer
|
||||
|
||||
|
||||
|
@ -94,7 +93,9 @@ bool Init()
|
|||
lastPrimitive = GL_ZERO;
|
||||
CurrentRenderPrimitive = GL_ZERO;
|
||||
LocalVBuffer = new u8[MAXVBUFFERSIZE];
|
||||
IBuffer = new u16[MAXIBUFFERSIZE];
|
||||
TIBuffer = new u16[MAXIBUFFERSIZE];
|
||||
LIBuffer = new u16[MAXIBUFFERSIZE];
|
||||
PIBuffer = new u16[MAXIBUFFERSIZE];
|
||||
s_pCurBufferPointer = LocalVBuffer;
|
||||
s_nCurVBOIndex = 0;
|
||||
glGenBuffers(ARRAYSIZE(s_vboBuffers), s_vboBuffers);
|
||||
|
@ -105,13 +106,19 @@ bool Init()
|
|||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
g_nativeVertexFmt = NULL;
|
||||
GL_REPORT_ERRORD();
|
||||
u16 *Tptr = TIBuffer;
|
||||
u16 *Lptr = LIBuffer;
|
||||
u16 *Pptr = PIBuffer;
|
||||
indexGen.Start(Tptr,Lptr,Pptr);
|
||||
return true;
|
||||
}
|
||||
|
||||
void Shutdown()
|
||||
{
|
||||
delete [] LocalVBuffer;
|
||||
delete [] IBuffer;
|
||||
delete [] TIBuffer;
|
||||
delete [] LIBuffer;
|
||||
delete [] PIBuffer;
|
||||
glDeleteBuffers(ARRAYSIZE(s_vboBuffers), s_vboBuffers);
|
||||
s_nCurVBOIndex = 0;
|
||||
ResetBuffer();
|
||||
|
@ -122,8 +129,10 @@ void ResetBuffer()
|
|||
s_nCurVBOIndex = (s_nCurVBOIndex + 1) % ARRAYSIZE(s_vboBuffers);
|
||||
s_pCurBufferPointer = LocalVBuffer;
|
||||
CurrentRenderPrimitive = GL_ZERO;
|
||||
u16 *ptr = 0;
|
||||
indexGen.Start((unsigned short*)ptr);
|
||||
u16 *Tptr = TIBuffer;
|
||||
u16 *Lptr = LIBuffer;
|
||||
u16 *Pptr = PIBuffer;
|
||||
indexGen.Start(Tptr,Lptr,Pptr);
|
||||
}
|
||||
|
||||
void AddIndices(int _primitive, int _numVertices)
|
||||
|
@ -135,7 +144,7 @@ void AddIndices(int _primitive, int _numVertices)
|
|||
case GL_TRIANGLE_STRIP: indexGen.AddStrip(_numVertices); return;
|
||||
case GL_TRIANGLE_FAN: indexGen.AddFan(_numVertices); return;
|
||||
case GL_LINE_STRIP: indexGen.AddLineStrip(_numVertices); return;
|
||||
case GL_LINES: indexGen.AddLineList(_numVertices); return;
|
||||
case GL_LINES: indexGen.AddLineList(_numVertices); return;
|
||||
case GL_POINTS: indexGen.AddPoints(_numVertices); return;
|
||||
}
|
||||
}
|
||||
|
@ -158,40 +167,28 @@ void AddVertices(int primitive, int numvertices)
|
|||
|
||||
ADDSTAT(stats.thisFrame.numPrims, numvertices);
|
||||
|
||||
if (CurrentRenderPrimitive != c_RenderprimitiveType[primitive])
|
||||
{
|
||||
// We are NOT collecting the right type.
|
||||
Flush();
|
||||
CurrentRenderPrimitive = c_RenderprimitiveType[primitive];
|
||||
u16 *ptr = 0;
|
||||
if (lastPrimitive != GL_POINTS)
|
||||
{
|
||||
ptr = IBuffer;
|
||||
}
|
||||
indexGen.Start((unsigned short*)ptr);
|
||||
AddIndices(c_primitiveType[primitive], numvertices);
|
||||
}
|
||||
else // We are collecting the right type, keep going
|
||||
{
|
||||
INCSTAT(stats.thisFrame.numPrimitiveJoins);
|
||||
AddIndices(c_primitiveType[primitive], numvertices);
|
||||
}
|
||||
INCSTAT(stats.thisFrame.numPrimitiveJoins);
|
||||
AddIndices(c_primitiveType[primitive], numvertices);
|
||||
|
||||
}
|
||||
|
||||
inline void Draw(int numVertices, int indexLen)
|
||||
inline void Draw()
|
||||
{
|
||||
|
||||
if (CurrentRenderPrimitive != GL_POINT)
|
||||
{
|
||||
glDrawElements(CurrentRenderPrimitive, indexLen, GL_UNSIGNED_SHORT, IBuffer);
|
||||
if(indexGen.GetNumTriangles() > 0)
|
||||
{
|
||||
glDrawElements(GL_TRIANGLES, indexGen.GetTriangleindexLen(), GL_UNSIGNED_SHORT, TIBuffer);
|
||||
INCSTAT(stats.thisFrame.numIndexedDrawCalls);
|
||||
}
|
||||
else
|
||||
if(indexGen.GetNumLines() > 0)
|
||||
{
|
||||
glDrawArrays(CurrentRenderPrimitive,0,numVertices);
|
||||
INCSTAT(stats.thisFrame.numDrawCalls);
|
||||
glDrawElements(GL_LINES, indexGen.GetLineindexLen(), GL_UNSIGNED_SHORT, LIBuffer);
|
||||
INCSTAT(stats.thisFrame.numIndexedDrawCalls);
|
||||
}
|
||||
|
||||
if(indexGen.GetNumPoints() > 0)
|
||||
{
|
||||
glDrawElements(GL_POINTS, indexGen.GetPointindexLen(), GL_UNSIGNED_SHORT, PIBuffer);
|
||||
INCSTAT(stats.thisFrame.numIndexedDrawCalls);
|
||||
}
|
||||
}
|
||||
|
||||
void Flush()
|
||||
|
@ -320,8 +317,7 @@ void Flush()
|
|||
PRIM_LOG("");
|
||||
#endif
|
||||
|
||||
int numIndexes = indexGen.GetindexLen();
|
||||
Draw(numVerts,numIndexes);
|
||||
Draw();
|
||||
|
||||
// run through vertex groups again to set alpha
|
||||
if (!g_ActiveConfig.bDstAlphaPass && bpmem.dstalpha.enable && bpmem.blendmode.alphaupdate)
|
||||
|
@ -335,7 +331,7 @@ void Flush()
|
|||
|
||||
glDisable(GL_BLEND);
|
||||
|
||||
Draw(numVerts,numIndexes);
|
||||
Draw();
|
||||
// restore color mask
|
||||
Renderer::SetColorMask();
|
||||
|
||||
|
|
Loading…
Reference in New Issue