From 4cbdfbf128103a2d439065b2c8a5cfa7a6e80f96 Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Sun, 4 May 2003 07:22:20 +0000 Subject: [PATCH] optimizing Model drawing --- stepmania/src/Milkshape.h | 2 +- stepmania/src/Model.cpp | 73 ++++++++++++----------------------- stepmania/src/RageDisplay.cpp | 14 +++++++ stepmania/src/RageDisplay.h | 2 + 4 files changed, 41 insertions(+), 50 deletions(-) diff --git a/stepmania/src/Milkshape.h b/stepmania/src/Milkshape.h index d819a5c79d..4ad7fcdf59 100644 --- a/stepmania/src/Milkshape.h +++ b/stepmania/src/Milkshape.h @@ -82,7 +82,7 @@ typedef struct /* msMesh */ typedef struct msMesh { - byte nFlags; +// byte nFlags; char szName[MS_MAX_NAME]; char nMaterialIndex; diff --git a/stepmania/src/Model.cpp b/stepmania/src/Model.cpp index 94fab3afd1..bdffae2073 100644 --- a/stepmania/src/Model.cpp +++ b/stepmania/src/Model.cpp @@ -98,7 +98,7 @@ bool Model::LoadMilkshapeAscii( CString sPath ) } strcpy( mesh.szName, szName ); - mesh.nFlags = nFlags; +// mesh.nFlags = nFlags; mesh.nMaterialIndex = nIndex; // @@ -715,6 +715,7 @@ void Model::DrawPrimitives() for (int i = 0; i < (int)m_pModel->Meshes.size(); i++) { msMesh *pMesh = &m_pModel->Meshes[i]; + RageVertexVector& TempVertices = m_vTempVerticesByBone[i]; // apply material if( pMesh->nMaterialIndex != -1 ) @@ -744,59 +745,33 @@ void Model::DrawPrimitives() DISPLAY->SetTexture( NULL ); } - glBegin( GL_TRIANGLES ); - - for (int j = 0; j < (int)pMesh->Triangles.size(); j++) + // process vertices + for (int j = 0; j < (int)pMesh->Vertices.size(); j++) { - RageVertex verts[3]; + RageVertex& tempVert = TempVertices[j]; + msVertex& originalVert = pMesh->Vertices[j]; - msTriangle *pTriangle = &pMesh->Triangles[j]; - word nIndices[3];//, nNormalIndices[3]; - memcpy( nIndices, pTriangle->nVertexIndices, sizeof(nIndices) ); -// memcpy( nNormalIndices, pTriangle->nNormalIndices, sizeof(nNormalIndices) ); - for (int k = 0; k < 3; k++) + tempVert.c = RageColor(1,1,1,1); + + memcpy( &tempVert.t, originalVert.uv, sizeof(originalVert.uv) ); + + memcpy( &tempVert.n, originalVert.Normal, sizeof(originalVert.Normal) ); + + if( originalVert.nBoneIndex == -1 ) { - RageVertex& v = verts[k]; - - msVertex *pVertex = &pMesh->Vertices[ nIndices[k] ]; - - v.c = RageColor(1,1,1,1); - float white[4] = {1,1,0,1}; - glColor4fv( white ); - - v.t.x = pVertex->uv[0]; - v.t.y = pVertex->uv[1]; - glTexCoord2f( pVertex->uv[0], pVertex->uv[1] ); - - v.n.x = pVertex->Normal[0]; - v.n.y = pVertex->Normal[1]; - v.n.z = pVertex->Normal[2]; - glNormal3fv( pVertex->Normal ); - - if (pVertex->nBoneIndex == -1) - { - v.p.x = pVertex->Vertex[0]; - v.p.y = pVertex->Vertex[1]; - v.p.z = pVertex->Vertex[2]; - glVertex3fv( &v.p.x ); - } - else - { - msVec3 Vertex; - VectorRotate (pVertex->Vertex, m_pBones[pVertex->nBoneIndex].mFinal, Vertex); - Vertex[0] += m_pBones[pVertex->nBoneIndex].mFinal[0][3]; - Vertex[1] += m_pBones[pVertex->nBoneIndex].mFinal[1][3]; - Vertex[2] += m_pBones[pVertex->nBoneIndex].mFinal[2][3]; - v.p.x = Vertex[0]; - v.p.y = Vertex[1]; - v.p.z = Vertex[2]; - glVertex3fv( Vertex ); - } - + memcpy( &tempVert.p, originalVert.Vertex, sizeof(originalVert.Vertex) ); + } + else + { + int bone = originalVert.nBoneIndex; + VectorRotate (originalVert.Vertex, m_pBones[originalVert.nBoneIndex].mFinal, tempVert.p); + tempVert.p[0] += m_pBones[bone].mFinal[0][3]; + tempVert.p[1] += m_pBones[bone].mFinal[1][3]; + tempVert.p[2] += m_pBones[bone].mFinal[2][3]; } -// DISPLAY->DrawTriangles( verts, 3 ); } - glEnd(); + + DISPLAY->DrawIndexedTriangles( TempVertices.begin(), (Uint16*)pMesh->Triangles.begin(), pMesh->Triangles.size()*3 ); } DISPLAY->SetLightOff( 0 ); diff --git a/stepmania/src/RageDisplay.cpp b/stepmania/src/RageDisplay.cpp index eb8f8f0929..a04646025b 100644 --- a/stepmania/src/RageDisplay.cpp +++ b/stepmania/src/RageDisplay.cpp @@ -472,12 +472,26 @@ void RageDisplay::DrawStrip( const RageVertex v[], int iNumVerts ) void RageDisplay::DrawTriangles( const RageVertex v[], int iNumVerts ) { + if( iNumVerts == 0 ) + return; ASSERT( iNumVerts >= 3 ); + ASSERT( (iNumVerts%3) == 0 ); glInterleavedArrays( RageVertexFormat, sizeof(RageVertex), v ); glDrawArrays( GL_TRIANGLES, 0, iNumVerts ); g_iVertsRenderedSinceLastCheck += iNumVerts; } +void RageDisplay::DrawIndexedTriangles( const RageVertex v[], const Uint16 pIndices[], int iNumIndices ) +{ + if( iNumIndices == 0 ) + return; + ASSERT( iNumIndices >= 3 ); + ASSERT( (iNumIndices%3) == 0 ); + glInterleavedArrays( RageVertexFormat, sizeof(RageVertex), v ); + glDrawElements( GL_TRIANGLES, iNumIndices, GL_UNSIGNED_SHORT, pIndices ); + g_iVertsRenderedSinceLastCheck += iNumIndices; +} + /* Draw a line as a quad. GL_LINES with antialiasing off can draw line * ends at odd angles--they're forced to axis-alignment regardless of the * angle of the line. */ diff --git a/stepmania/src/RageDisplay.h b/stepmania/src/RageDisplay.h index 186b4bf9aa..d791a290f6 100644 --- a/stepmania/src/RageDisplay.h +++ b/stepmania/src/RageDisplay.h @@ -16,6 +16,7 @@ class RageTexture; struct RageMatrix; struct RageVertex; +#include "SDL_types.h" #include "RageTypes.h" const int REFRESH_DEFAULT = 0; @@ -90,6 +91,7 @@ public: void DrawFan( const RageVertex v[], int iNumVerts ); void DrawStrip( const RageVertex v[], int iNumVerts ); void DrawTriangles( const RageVertex v[], int iNumVerts ); + void DrawIndexedTriangles( const RageVertex v[], const Uint16 pIndices[], int iNumIndices ); void DrawLoop( const RageVertex v[], int iNumVerts, float LineWidth ); void DrawLoop_LinesAndPoints( const RageVertex v[], int iNumVerts, float LineWidth ); void DrawLoop_Polys( const RageVertex v[], int iNumVerts, float LineWidth );