Skip to content

Commit

Permalink
Move to 32bit vertex indexing. This ensures we won't overflow when tr…
Browse files Browse the repository at this point in the history
…ying to display the judgment plot with ridiculously long marathon files.
  • Loading branch information
xwidghet committed Jun 13, 2017
1 parent c4f7ccc commit c217987
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 27 deletions.
36 changes: 18 additions & 18 deletions src/RageDisplay_D3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,7 @@ class RageCompiledGeometrySWD3D : public RageCompiledGeometry
meshInfo.iVertexCount, // NumVertices
meshInfo.iTriangleCount, // PrimitiveCount,
&m_vTriangles[0]+meshInfo.iTriangleStart,// pIndexData,
D3DFMT_INDEX16, // IndexDataFormat,
D3DFMT_INDEX32, // IndexDataFormat,
&m_vVertex[0], // pVertexStreamZeroData,
sizeof(m_vVertex[0]) // VertexStreamZeroStride
);
Expand Down Expand Up @@ -876,11 +876,11 @@ void RageDisplay_D3D::DrawQuadsInternal( const RageSpriteVertex v[], int iNumVer
int iNumIndices = iNumTriangles*3;

// make a temporary index buffer
static vector<uint16_t> vIndices;
unsigned uOldSize = vIndices.size();
unsigned uNewSize = max(uOldSize, static_cast<unsigned>(iNumIndices));
static vector<int> vIndices;
int iOldSize = vIndices.size();
int uNewSize = max( iOldSize, iNumIndices );
vIndices.resize( uNewSize );
for( uint16_t i=static_cast<uint16_t>(uOldSize/6); i<static_cast<uint16_t>(iNumQuads); i++ )
for(int i= iOldSize/6; i<iNumQuads; i++ )
{
vIndices[i*6+0] = i*4+0;
vIndices[i*6+1] = i*4+1;
Expand All @@ -903,7 +903,7 @@ void RageDisplay_D3D::DrawQuadsInternal( const RageSpriteVertex v[], int iNumVer
iNumVerts, // NumVertices
iNumTriangles, // PrimitiveCount,
&vIndices[0], // pIndexData,
D3DFMT_INDEX16, // IndexDataFormat,
D3DFMT_INDEX32, // IndexDataFormat,
v, // pVertexStreamZeroData,
sizeof(RageSpriteVertex) // VertexStreamZeroStride
);
Expand All @@ -917,11 +917,11 @@ void RageDisplay_D3D::DrawQuadStripInternal( const RageSpriteVertex v[], int iNu
int iNumIndices = iNumTriangles*3;

// make a temporary index buffer
static vector<uint16_t> vIndices;
unsigned uOldSize = vIndices.size();
unsigned uNewSize = max(uOldSize,(unsigned)iNumIndices);
vIndices.resize( uNewSize );
for( uint16_t i=(uint16_t)uOldSize/6; i<(uint16_t)iNumQuads; i++ )
static vector<int> vIndices;
int iOldSize = vIndices.size();
int iNewSize = max( iOldSize,iNumIndices );
vIndices.resize( iNewSize );
for( int i=iOldSize/6; i<iNumQuads; i++ )
{
vIndices[i*6+0] = i*2+0;
vIndices[i*6+1] = i*2+1;
Expand All @@ -944,7 +944,7 @@ void RageDisplay_D3D::DrawQuadStripInternal( const RageSpriteVertex v[], int iNu
iNumVerts, // NumVertices
iNumTriangles, // PrimitiveCount,
&vIndices[0], // pIndexData,
D3DFMT_INDEX16, // IndexDataFormat,
D3DFMT_INDEX32, // IndexDataFormat,
v, // pVertexStreamZeroData,
sizeof(RageSpriteVertex) // VertexStreamZeroStride
);
Expand All @@ -957,11 +957,11 @@ void RageDisplay_D3D::DrawSymmetricQuadStripInternal( const RageSpriteVertex v[]
int iNumIndices = iNumTriangles*3;

// make a temporary index buffer
static vector<uint16_t> vIndices;
unsigned uOldSize = vIndices.size();
unsigned uNewSize = max(uOldSize,(unsigned)iNumIndices);
vIndices.resize( uNewSize );
for( uint16_t i=(uint16_t)uOldSize/12; i<(uint16_t)iNumPieces; i++ )
static vector<int> vIndices;
int iOldSize = vIndices.size();
int iNewSize = max( iOldSize,iNumIndices );
vIndices.resize( iNewSize );
for(int i=iOldSize/12; i<iNumPieces; i++ )
{
// { 1, 3, 0 } { 1, 4, 3 } { 1, 5, 4 } { 1, 2, 5 }
vIndices[i*12+0] = i*3+1;
Expand Down Expand Up @@ -991,7 +991,7 @@ void RageDisplay_D3D::DrawSymmetricQuadStripInternal( const RageSpriteVertex v[]
iNumVerts, // NumVertices
iNumTriangles, // PrimitiveCount,
&vIndices[0], // pIndexData,
D3DFMT_INDEX16, // IndexDataFormat,
D3DFMT_INDEX32, // IndexDataFormat,
v, // pVertexStreamZeroData,
sizeof(RageSpriteVertex) // VertexStreamZeroStride
);
Expand Down
17 changes: 8 additions & 9 deletions src/RageDisplay_OGL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1045,7 +1045,7 @@ class RageCompiledGeometrySWOGL : public RageCompiledGeometry
glDrawElements(
GL_TRIANGLES,
meshInfo.iTriangleCount*3,
GL_UNSIGNED_SHORT,
GL_INT,
&m_vTriangles[0]+meshInfo.iTriangleStart );
}

Expand Down Expand Up @@ -1389,7 +1389,7 @@ void RageCompiledGeometryHWOGL::Draw( int iMeshIndex ) const
meshInfo.iVertexStart+meshInfo.iVertexCount-1,
// maximum array index contained in indices
meshInfo.iTriangleCount*3, // number of elements to be rendered
GL_UNSIGNED_SHORT,
GL_INT,
BUFFER_OFFSET(meshInfo.iTriangleStart*sizeof(msTriangle)) );
DebugAssertNoGLError();

Expand Down Expand Up @@ -1436,11 +1436,11 @@ void RageDisplay_Legacy::DrawSymmetricQuadStripInternal( const RageSpriteVertex
int iNumIndices = iNumTriangles*3;

// make a temporary index buffer
static vector<uint16_t> vIndices;
unsigned uOldSize = vIndices.size();
unsigned uNewSize = max(uOldSize,(unsigned)iNumIndices);
vIndices.resize( uNewSize );
for( uint16_t i=(uint16_t)uOldSize/12; i<(uint16_t)iNumPieces; i++ )
static vector<int> vIndices;
int iOldSize = vIndices.size();
int iNewSize = max( iOldSize,iNumIndices );
vIndices.resize( iNewSize );
for( int i=iOldSize/12; i<iNumPieces; i++ )
{
// { 1, 3, 0 } { 1, 4, 3 } { 1, 5, 4 } { 1, 2, 5 }
vIndices[i*12+0] = i*3+1;
Expand All @@ -1457,14 +1457,13 @@ void RageDisplay_Legacy::DrawSymmetricQuadStripInternal( const RageSpriteVertex
vIndices[i*12+11] = i*3+5;
}

//
SendCurrentMatrices();

SetupVertices( v, iNumVerts );
glDrawElements(
GL_TRIANGLES,
iNumIndices,
GL_UNSIGNED_SHORT,
GL_INT,
&vIndices[0] );
}

Expand Down

0 comments on commit c217987

Please sign in to comment.