optimizing Model drawing

This commit is contained in:
Chris Danford
2003-05-04 07:22:20 +00:00
parent 85986fe325
commit 4cbdfbf128
4 changed files with 41 additions and 50 deletions
+1 -1
View File
@@ -82,7 +82,7 @@ typedef struct
/* msMesh */
typedef struct msMesh
{
byte nFlags;
// byte nFlags;
char szName[MS_MAX_NAME];
char nMaterialIndex;
+24 -49
View File
@@ -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 );
+14
View File
@@ -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. */
+2
View File
@@ -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 );