move vertex buffers into a separate object in perparation for HW vertex buffers
This commit is contained in:
@@ -1,169 +0,0 @@
|
|||||||
#ifndef Milkshape_H
|
|
||||||
#define Milkshape_H
|
|
||||||
/*
|
|
||||||
-----------------------------------------------------------------------------
|
|
||||||
Class: Milkshape
|
|
||||||
|
|
||||||
Desc: Types defined in msLib.h. C arrays converted to use std::vector
|
|
||||||
|
|
||||||
Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved.
|
|
||||||
Chris Danford
|
|
||||||
-----------------------------------------------------------------------------
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**********************************************************************
|
|
||||||
*
|
|
||||||
* Constants
|
|
||||||
*
|
|
||||||
**********************************************************************/
|
|
||||||
|
|
||||||
#define MS_MAX_NAME 32
|
|
||||||
#define MS_MAX_PATH 256
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**********************************************************************
|
|
||||||
*
|
|
||||||
* Types
|
|
||||||
*
|
|
||||||
**********************************************************************/
|
|
||||||
|
|
||||||
#ifndef byte
|
|
||||||
typedef unsigned char byte;
|
|
||||||
#endif /* byte */
|
|
||||||
|
|
||||||
#ifndef word
|
|
||||||
typedef unsigned short word;
|
|
||||||
#endif /* word */
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct msVec2 {
|
|
||||||
float v[2];
|
|
||||||
operator float* () { return v; };
|
|
||||||
operator const float* () const { return v; };
|
|
||||||
} msVec2;
|
|
||||||
typedef struct msVec3 {
|
|
||||||
float v[3];
|
|
||||||
operator float* () { return v; };
|
|
||||||
operator const float* () const { return v; };
|
|
||||||
} msVec3;
|
|
||||||
typedef struct msVec4 {
|
|
||||||
float v[4];
|
|
||||||
operator float* () { return v; };
|
|
||||||
operator const float* () const { return v; };
|
|
||||||
} msVec4;
|
|
||||||
|
|
||||||
|
|
||||||
/* msFlag */
|
|
||||||
typedef enum {
|
|
||||||
eSelected = 1, eSelected2 = 2, eHidden = 4, eDirty = 8, eAveraged = 16, eUnused = 32
|
|
||||||
} msFlag;
|
|
||||||
|
|
||||||
/* msVertex */
|
|
||||||
typedef struct msVertex
|
|
||||||
{
|
|
||||||
// byte nFlags;
|
|
||||||
msVec3 Vertex;
|
|
||||||
msVec2 uv;
|
|
||||||
msVec3 Normal;
|
|
||||||
char nBoneIndex;
|
|
||||||
} msVertex;
|
|
||||||
|
|
||||||
/* msTriangle */
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
// word nFlags;
|
|
||||||
word nVertexIndices[3];
|
|
||||||
// word nNormalIndices[3];
|
|
||||||
// msVec3 Normal;
|
|
||||||
// byte nSmoothingGroup;
|
|
||||||
} msTriangle;
|
|
||||||
|
|
||||||
/* msMesh */
|
|
||||||
typedef struct msMesh
|
|
||||||
{
|
|
||||||
// byte nFlags;
|
|
||||||
char szName[MS_MAX_NAME];
|
|
||||||
char nMaterialIndex;
|
|
||||||
|
|
||||||
vector<msVertex> Vertices;
|
|
||||||
|
|
||||||
// vector<msVec3> Normals;
|
|
||||||
|
|
||||||
vector<msTriangle> Triangles;
|
|
||||||
} msMesh;
|
|
||||||
|
|
||||||
/* msMaterial */
|
|
||||||
class RageTexture;
|
|
||||||
|
|
||||||
typedef struct msMaterial
|
|
||||||
{
|
|
||||||
int nFlags;
|
|
||||||
char szName[MS_MAX_NAME];
|
|
||||||
msVec4 Ambient;
|
|
||||||
msVec4 Diffuse;
|
|
||||||
msVec4 Specular;
|
|
||||||
msVec4 Emissive;
|
|
||||||
float fShininess;
|
|
||||||
float fTransparency;
|
|
||||||
char szDiffuseTexture[MS_MAX_PATH];
|
|
||||||
char szAlphaTexture[MS_MAX_PATH]; // not used in SM. Use alpha in diffuse texture instead
|
|
||||||
int nName; // not used in SM. What is this for?
|
|
||||||
RageTexture* pTexture;
|
|
||||||
} msMaterial;
|
|
||||||
|
|
||||||
/* msPositionKey */
|
|
||||||
typedef struct msPositionKey
|
|
||||||
{
|
|
||||||
float fTime;
|
|
||||||
msVec3 Position;
|
|
||||||
} msPositionKey;
|
|
||||||
|
|
||||||
/* msRotationKey */
|
|
||||||
typedef struct msRotationKey
|
|
||||||
{
|
|
||||||
float fTime;
|
|
||||||
msVec3 Rotation;
|
|
||||||
} msRotationKey;
|
|
||||||
|
|
||||||
/* msBone */
|
|
||||||
typedef struct msBone
|
|
||||||
{
|
|
||||||
int nFlags;
|
|
||||||
char szName[MS_MAX_NAME];
|
|
||||||
char szParentName[MS_MAX_NAME];
|
|
||||||
msVec3 Position;
|
|
||||||
msVec3 Rotation;
|
|
||||||
|
|
||||||
vector<msPositionKey> PositionKeys;
|
|
||||||
|
|
||||||
int nNumRotationKeys;
|
|
||||||
int nNumAllocedRotationKeys;
|
|
||||||
vector<msRotationKey> RotationKeys;
|
|
||||||
} msBone;
|
|
||||||
|
|
||||||
/* msModel */
|
|
||||||
typedef struct msModel
|
|
||||||
{
|
|
||||||
vector<msMesh> Meshes;
|
|
||||||
|
|
||||||
vector<msMaterial> Materials;
|
|
||||||
|
|
||||||
vector<msBone> Bones;
|
|
||||||
|
|
||||||
int FindBoneByName( const char* szName )
|
|
||||||
{
|
|
||||||
for( unsigned i=0; i<Bones.size(); i++ )
|
|
||||||
if( strcmp(Bones[i].szName, szName)==0 )
|
|
||||||
return i;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int nFrame;
|
|
||||||
int nTotalFrames;
|
|
||||||
|
|
||||||
msVec3 Position;
|
|
||||||
msVec3 Rotation;
|
|
||||||
} msModel;
|
|
||||||
|
|
||||||
#endif
|
|
||||||
+56
-34
@@ -55,6 +55,13 @@ void Model::Clear ()
|
|||||||
m_Materials.clear();
|
m_Materials.clear();
|
||||||
m_mapNameToAnimation.clear();
|
m_mapNameToAnimation.clear();
|
||||||
m_pCurAnimation = NULL;
|
m_pCurAnimation = NULL;
|
||||||
|
|
||||||
|
for (unsigned i = 0; i < m_vpTempVerticesByMesh.size(); i++)
|
||||||
|
{
|
||||||
|
RageModelVertexArray *&pTemp = m_vpTempVerticesByMesh[i];
|
||||||
|
DISPLAY->DeleteRageModelVertexArray( pTemp );
|
||||||
|
}
|
||||||
|
m_vpTempVerticesByMesh.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Model::Load( CString sFile )
|
void Model::Load( CString sFile )
|
||||||
@@ -115,10 +122,9 @@ void Model::LoadPieces( CString sMeshesPath, CString sMaterialsPath, CString sBo
|
|||||||
for (int i = 0; i < (int)m_pGeometry->m_Meshes.size(); i++)
|
for (int i = 0; i < (int)m_pGeometry->m_Meshes.size(); i++)
|
||||||
{
|
{
|
||||||
msMesh& mesh = m_pGeometry->m_Meshes[i];
|
msMesh& mesh = m_pGeometry->m_Meshes[i];
|
||||||
for (int j = 0; j < (int)mesh.Vertices.size(); j++)
|
for (int j = 0; j < (int)mesh.Vertices->sizeVerts(); j++)
|
||||||
{
|
{
|
||||||
RageModelVertex &vert = mesh.Vertices[j];
|
if( mesh.Vertices->Bone(j) != -1 )
|
||||||
if( vert.boneIndex != -1 )
|
|
||||||
{
|
{
|
||||||
bHasAnyPerVertexBones = true;
|
bHasAnyPerVertexBones = true;
|
||||||
break;
|
break;
|
||||||
@@ -129,11 +135,19 @@ void Model::LoadPieces( CString sMeshesPath, CString sMaterialsPath, CString sBo
|
|||||||
m_bUseTempVertices = bHasAnyPerVertexBones;
|
m_bUseTempVertices = bHasAnyPerVertexBones;
|
||||||
if( m_bUseTempVertices )
|
if( m_bUseTempVertices )
|
||||||
{
|
{
|
||||||
m_vTempVerticesByMesh.resize( m_pGeometry->m_Meshes.size() );
|
m_vpTempVerticesByMesh.resize( m_pGeometry->m_Meshes.size() );
|
||||||
for (int i = 0; i < (int)m_pGeometry->m_Meshes.size(); i++)
|
for (unsigned i = 0; i < m_pGeometry->m_Meshes.size(); i++)
|
||||||
{
|
{
|
||||||
msMesh& Mesh = m_pGeometry->m_Meshes[i];
|
msMesh &mesh = m_pGeometry->m_Meshes[i];
|
||||||
m_vTempVerticesByMesh[i].resize( Mesh.Vertices.size() );
|
RageModelVertexArray *&pOrig = mesh.Vertices;
|
||||||
|
RageModelVertexArray *&pTemp = m_vpTempVerticesByMesh[i];
|
||||||
|
pTemp = DISPLAY->CreateRageModelVertexArray();
|
||||||
|
pTemp->resizeVerts( pOrig->sizeVerts() );
|
||||||
|
pTemp->resizeTriangles( pOrig->sizeTriangles() );
|
||||||
|
|
||||||
|
// copy triangles
|
||||||
|
for (unsigned j = 0; j < pOrig->sizeTriangles(); j++)
|
||||||
|
pTemp->Triangle(j) = pOrig->Triangle(j);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -455,7 +469,7 @@ void Model::DrawPrimitives()
|
|||||||
for (int i = 0; i < (int)m_pGeometry->m_Meshes.size(); i++)
|
for (int i = 0; i < (int)m_pGeometry->m_Meshes.size(); i++)
|
||||||
{
|
{
|
||||||
msMesh *pMesh = &m_pGeometry->m_Meshes[i];
|
msMesh *pMesh = &m_pGeometry->m_Meshes[i];
|
||||||
RageModelVertexVector& TempVertices = m_bUseTempVertices ? m_vTempVerticesByMesh[i] : pMesh->Vertices;
|
const RageModelVertexArray* TempVertices = m_bUseTempVertices ? m_vpTempVerticesByMesh[i] : pMesh->Vertices;
|
||||||
|
|
||||||
if( pMesh->nMaterialIndex != -1 ) // has a material
|
if( pMesh->nMaterialIndex != -1 ) // has a material
|
||||||
{
|
{
|
||||||
@@ -518,7 +532,7 @@ void Model::DrawPrimitives()
|
|||||||
DISPLAY->PreMultMatrix( mat );
|
DISPLAY->PreMultMatrix( mat );
|
||||||
}
|
}
|
||||||
|
|
||||||
DISPLAY->DrawIndexedTriangles( &TempVertices[0], pMesh->Vertices.size(), (Uint16*)&pMesh->Triangles[0], pMesh->Triangles.size()*3 );
|
DISPLAY->DrawIndexedTriangles( TempVertices );
|
||||||
DISPLAY->SetSphereEnironmentMapping( false );
|
DISPLAY->SetSphereEnironmentMapping( false );
|
||||||
|
|
||||||
if( pMesh->nBoneIndex != -1 )
|
if( pMesh->nBoneIndex != -1 )
|
||||||
@@ -538,7 +552,7 @@ void Model::DrawPrimitives()
|
|||||||
for (int i = 0; i < (int)m_pGeometry->m_Meshes.size(); i++)
|
for (int i = 0; i < (int)m_pGeometry->m_Meshes.size(); i++)
|
||||||
{
|
{
|
||||||
msMesh *pMesh = &m_pGeometry->m_Meshes[i];
|
msMesh *pMesh = &m_pGeometry->m_Meshes[i];
|
||||||
RageModelVertexVector& TempVertices = m_bUseTempVertices ? m_vTempVerticesByMesh[i] : pMesh->Vertices;
|
const RageModelVertexArray* pTempVertices = m_bUseTempVertices ? m_vpTempVerticesByMesh[i] : pMesh->Vertices;
|
||||||
|
|
||||||
// apply material
|
// apply material
|
||||||
if( pMesh->nMaterialIndex != -1 )
|
if( pMesh->nMaterialIndex != -1 )
|
||||||
@@ -578,9 +592,8 @@ void Model::DrawPrimitives()
|
|||||||
DISPLAY->ClearAllTextures();
|
DISPLAY->ClearAllTextures();
|
||||||
}
|
}
|
||||||
|
|
||||||
DISPLAY->DrawIndexedTriangles( &TempVertices[0], pMesh->Vertices.size(), (Uint16*)&pMesh->Triangles[0], pMesh->Triangles.size()*3 );
|
DISPLAY->DrawIndexedTriangles( pTempVertices );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -610,7 +623,7 @@ void Model::PlayAnimation( CString sAniName, float fPlayRate )
|
|||||||
int nBoneCount = (int)m_pCurAnimation->Bones.size();
|
int nBoneCount = (int)m_pCurAnimation->Bones.size();
|
||||||
m_vpBones.resize( nBoneCount );
|
m_vpBones.resize( nBoneCount );
|
||||||
|
|
||||||
int i, j;
|
int i;
|
||||||
for (i = 0; i < nBoneCount; i++)
|
for (i = 0; i < nBoneCount; i++)
|
||||||
{
|
{
|
||||||
msBone *pBone = &m_pCurAnimation->Bones[i];
|
msBone *pBone = &m_pCurAnimation->Bones[i];
|
||||||
@@ -643,22 +656,25 @@ void Model::PlayAnimation( CString sAniName, float fPlayRate )
|
|||||||
for (i = 0; i < (int)m_pGeometry->m_Meshes.size(); i++)
|
for (i = 0; i < (int)m_pGeometry->m_Meshes.size(); i++)
|
||||||
{
|
{
|
||||||
msMesh *pMesh = &m_pGeometry->m_Meshes[i];
|
msMesh *pMesh = &m_pGeometry->m_Meshes[i];
|
||||||
for (j = 0; j < (int)pMesh->Vertices.size(); j++)
|
RageModelVertexArray* Vertices = pMesh->Vertices;
|
||||||
|
for (unsigned j = 0; j < Vertices->sizeVerts(); j++)
|
||||||
{
|
{
|
||||||
RageModelVertex *pVertex = &pMesh->Vertices[j];
|
// int nBoneIndex = (pMesh->nBoneIndex!=-1) ? pMesh->nBoneIndex : bone;
|
||||||
// int nBoneIndex = (pMesh->nBoneIndex!=-1) ? pMesh->nBoneIndex : pVertex->boneIndex;
|
RageVector3 &pos = Vertices->Position(j);
|
||||||
if (pVertex->boneIndex != -1)
|
Sint8 bone = Vertices->Bone(j);
|
||||||
|
if (bone != -1)
|
||||||
{
|
{
|
||||||
pVertex->p[0] -= m_vpBones[pVertex->boneIndex].mAbsolute.m[3][0];
|
pos[0] -= m_vpBones[bone].mAbsolute.m[3][0];
|
||||||
pVertex->p[1] -= m_vpBones[pVertex->boneIndex].mAbsolute.m[3][1];
|
pos[1] -= m_vpBones[bone].mAbsolute.m[3][1];
|
||||||
pVertex->p[2] -= m_vpBones[pVertex->boneIndex].mAbsolute.m[3][2];
|
pos[2] -= m_vpBones[bone].mAbsolute.m[3][2];
|
||||||
|
|
||||||
RageVector3 vTmp;
|
RageVector3 vTmp;
|
||||||
|
|
||||||
RageMatrix inverse;
|
RageMatrix inverse;
|
||||||
RageMatrixTranspose( &inverse, &m_vpBones[pVertex->boneIndex].mAbsolute ); // transpose = inverse for rotation matrices
|
RageMatrixTranspose( &inverse, &m_vpBones[bone].mAbsolute ); // transpose = inverse for rotation matrices
|
||||||
RageVec3TransformNormal( &vTmp, &pVertex->p, &inverse );
|
RageVec3TransformNormal( &vTmp, &pos, &inverse );
|
||||||
|
|
||||||
pVertex->p = vTmp;
|
pos = vTmp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -822,24 +838,30 @@ void Model::Update( float fDelta )
|
|||||||
for (int i = 0; i < (int)m_pGeometry->m_Meshes.size(); i++)
|
for (int i = 0; i < (int)m_pGeometry->m_Meshes.size(); i++)
|
||||||
{
|
{
|
||||||
msMesh *pMesh = &m_pGeometry->m_Meshes[i];
|
msMesh *pMesh = &m_pGeometry->m_Meshes[i];
|
||||||
RageModelVertexVector& TempVertices = m_vTempVerticesByMesh[i];
|
RageModelVertexArray* pOrigVertices = pMesh->Vertices;
|
||||||
for (int j = 0; j < (int)pMesh->Vertices.size(); j++)
|
RageModelVertexArray* pTempVertices = m_vpTempVerticesByMesh[i];
|
||||||
|
for (unsigned j = 0; j < pOrigVertices->sizeVerts(); j++)
|
||||||
{
|
{
|
||||||
RageModelVertex& tempVert = TempVertices[j];
|
|
||||||
RageModelVertex& originalVert = pMesh->Vertices[j];
|
|
||||||
|
|
||||||
tempVert.t = originalVert.t;
|
RageVector3& tempPos = pTempVertices->Position(j);
|
||||||
|
RageVector3& originalPos = pOrigVertices->Position(j);
|
||||||
|
RageVector3& tempNormal = pTempVertices->Normal(j);
|
||||||
|
RageVector3& originalNormal = pOrigVertices->Normal(j);
|
||||||
|
RageVector2& tempTex = pTempVertices->TexCoord(j);
|
||||||
|
RageVector2& originalTex = pOrigVertices->TexCoord(j);
|
||||||
|
Sint8 bone = pOrigVertices->Bone(j);
|
||||||
|
|
||||||
if( originalVert.boneIndex == -1 )
|
tempTex = originalTex;
|
||||||
|
|
||||||
|
if( bone == -1 )
|
||||||
{
|
{
|
||||||
tempVert.n = originalVert.n;
|
tempNormal = originalNormal;
|
||||||
tempVert.p = originalVert.p;
|
tempPos = originalPos;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int bone = originalVert.boneIndex;
|
RageVec3TransformNormal( &tempNormal, &originalNormal, &m_vpBones[bone].mFinal );
|
||||||
RageVec3TransformNormal( &tempVert.n, &originalVert.n, &m_vpBones[bone].mFinal );
|
RageVec3TransformCoord( &tempPos, &originalPos, &m_vpBones[bone].mFinal );
|
||||||
RageVec3TransformCoord( &tempVert.p, &originalVert.p, &m_vpBones[bone].mFinal );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,8 +70,7 @@ private:
|
|||||||
// Otherwise, render directly from the mesh's vertices
|
// Otherwise, render directly from the mesh's vertices
|
||||||
bool m_bUseTempVertices;
|
bool m_bUseTempVertices;
|
||||||
|
|
||||||
typedef vector<RageModelVertex> RageModelVertexVector;
|
vector<RageModelVertexArray*> m_vpTempVerticesByMesh;
|
||||||
vector<RageModelVertexVector> m_vTempVerticesByMesh;
|
|
||||||
|
|
||||||
float m_fCurrFrame;
|
float m_fCurrFrame;
|
||||||
CString m_sDefaultAnimation;
|
CString m_sDefaultAnimation;
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
#include "RageTexture.h"
|
#include "RageTexture.h"
|
||||||
#include "RageTextureManager.h"
|
#include "RageTextureManager.h"
|
||||||
#include "RageLog.h"
|
#include "RageLog.h"
|
||||||
|
#include "RageDisplay.h"
|
||||||
|
|
||||||
AnimatedTexture::AnimatedTexture()
|
AnimatedTexture::AnimatedTexture()
|
||||||
{
|
{
|
||||||
@@ -123,3 +124,16 @@ void AnimatedTexture::Unload()
|
|||||||
fSecsIntoFrame = 0;
|
fSecsIntoFrame = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
msMesh::msMesh()
|
||||||
|
{
|
||||||
|
ZERO( szName );
|
||||||
|
Vertices = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
msMesh::~msMesh()
|
||||||
|
{
|
||||||
|
Vertices = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -66,14 +66,20 @@ typedef struct
|
|||||||
// byte nSmoothingGroup; // we don't care about this, so don't save it
|
// byte nSmoothingGroup; // we don't care about this, so don't save it
|
||||||
} msTriangle;
|
} msTriangle;
|
||||||
|
|
||||||
|
|
||||||
|
class RageModelVertexArray;
|
||||||
|
|
||||||
/* msMesh */
|
/* msMesh */
|
||||||
typedef struct msMesh
|
typedef struct msMesh
|
||||||
{
|
{
|
||||||
|
msMesh();
|
||||||
|
~msMesh();
|
||||||
|
|
||||||
// byte nFlags; // we don't care about saving this flag
|
// byte nFlags; // we don't care about saving this flag
|
||||||
char szName[MS_MAX_NAME];
|
char szName[MS_MAX_NAME];
|
||||||
char nMaterialIndex;
|
char nMaterialIndex;
|
||||||
|
|
||||||
vector<RageModelVertex> Vertices;
|
RageModelVertexArray* Vertices;
|
||||||
// vector<msVertex> Vertices;
|
// vector<msVertex> Vertices;
|
||||||
|
|
||||||
// vector<msVec3> Normals; // each vertex holds its own normal
|
// vector<msVec3> Normals; // each vertex holds its own normal
|
||||||
@@ -83,7 +89,7 @@ typedef struct msMesh
|
|||||||
// of transforming each vertex on the CPU;
|
// of transforming each vertex on the CPU;
|
||||||
char nBoneIndex; // -1 = no bone
|
char nBoneIndex; // -1 = no bone
|
||||||
|
|
||||||
vector<msTriangle> Triangles;
|
// vector<msTriangle> Triangles;
|
||||||
} msMesh;
|
} msMesh;
|
||||||
|
|
||||||
/* msMaterial */
|
/* msMaterial */
|
||||||
|
|||||||
+23
-15
@@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
#include "SDL_types.h"
|
#include "SDL_types.h"
|
||||||
#include "RageTypes.h"
|
#include "RageTypes.h"
|
||||||
|
#include "ModelTypes.h"
|
||||||
|
|
||||||
const int REFRESH_DEFAULT = 0;
|
const int REFRESH_DEFAULT = 0;
|
||||||
struct SDL_Surface;
|
struct SDL_Surface;
|
||||||
@@ -20,23 +21,27 @@ const int MAX_TEXTURE_UNITS = 2;
|
|||||||
|
|
||||||
// VertexArray holds vertex data in a format that is most efficient for
|
// VertexArray holds vertex data in a format that is most efficient for
|
||||||
// the graphics API.
|
// the graphics API.
|
||||||
/*struct VertexArray
|
class RageModelVertexArray
|
||||||
{
|
{
|
||||||
VertexArray();
|
public:
|
||||||
~VertexArray();
|
virtual ~RageModelVertexArray() { }
|
||||||
unsigned size();
|
|
||||||
void resize( unsigned new_size );
|
|
||||||
RageVector2& TexCoord( int index );
|
|
||||||
RageColor& Color( int index );
|
|
||||||
RageVector3& Normal( int index );
|
|
||||||
RageVector3& Position( int index );
|
|
||||||
// convenience. Remove this later!
|
|
||||||
void Set( int index, const RageSpriteVertex& v );
|
|
||||||
|
|
||||||
struct Impl;
|
virtual size_t sizeVerts() const = 0;
|
||||||
Impl* pImpl;
|
virtual void resizeVerts( size_t size ) = 0;
|
||||||
|
|
||||||
|
virtual size_t sizeTriangles() const = 0;
|
||||||
|
virtual void resizeTriangles( size_t size ) = 0;
|
||||||
|
|
||||||
|
virtual RageVector3& Position( int index ) = 0;
|
||||||
|
virtual RageVector3& Normal ( int index ) = 0;
|
||||||
|
virtual RageVector2& TexCoord( int index ) = 0;
|
||||||
|
virtual Sint8& Bone ( int index ) = 0;
|
||||||
|
|
||||||
|
virtual msTriangle& Triangle( int index ) = 0;
|
||||||
|
|
||||||
|
virtual void SendVertices() const = 0;
|
||||||
};
|
};
|
||||||
*/
|
|
||||||
|
|
||||||
class RageDisplay
|
class RageDisplay
|
||||||
{
|
{
|
||||||
@@ -200,12 +205,15 @@ public:
|
|||||||
|
|
||||||
virtual void SetSphereEnironmentMapping( bool b ) = 0;
|
virtual void SetSphereEnironmentMapping( bool b ) = 0;
|
||||||
|
|
||||||
|
virtual RageModelVertexArray* CreateRageModelVertexArray() = 0;
|
||||||
|
virtual void DeleteRageModelVertexArray( RageModelVertexArray* p ) = 0;
|
||||||
|
|
||||||
void DrawQuad( const RageSpriteVertex v[] ) { DrawQuads(v,4); } /* alias. upper-left, upper-right, lower-left, lower-right */
|
void DrawQuad( const RageSpriteVertex v[] ) { DrawQuads(v,4); } /* alias. upper-left, upper-right, lower-left, lower-right */
|
||||||
virtual void DrawQuads( const RageSpriteVertex v[], int iNumVerts ) = 0;
|
virtual void DrawQuads( const RageSpriteVertex v[], int iNumVerts ) = 0;
|
||||||
virtual void DrawFan( const RageSpriteVertex v[], int iNumVerts ) = 0;
|
virtual void DrawFan( const RageSpriteVertex v[], int iNumVerts ) = 0;
|
||||||
virtual void DrawStrip( const RageSpriteVertex v[], int iNumVerts ) = 0;
|
virtual void DrawStrip( const RageSpriteVertex v[], int iNumVerts ) = 0;
|
||||||
virtual void DrawTriangles( const RageSpriteVertex v[], int iNumVerts ) = 0;
|
virtual void DrawTriangles( const RageSpriteVertex v[], int iNumVerts ) = 0;
|
||||||
virtual void DrawIndexedTriangles( const RageModelVertex v[], int iNumVerts, const Uint16* pIndices, int iNumIndices ) = 0;
|
virtual void DrawIndexedTriangles( const RageModelVertexArray *p ) = 0;
|
||||||
virtual void DrawLineStrip( const RageSpriteVertex v[], int iNumVerts, float LineWidth );
|
virtual void DrawLineStrip( const RageSpriteVertex v[], int iNumVerts, float LineWidth );
|
||||||
|
|
||||||
void DrawCircle( const RageSpriteVertex &v, float radius );
|
void DrawCircle( const RageSpriteVertex &v, float radius );
|
||||||
|
|||||||
@@ -734,6 +734,94 @@ RageDisplay::VideoModeParams RageDisplay_D3D::GetVideoModeParams() const { retur
|
|||||||
g_pd3dDevice->SetTransform( D3DTS_WORLD, (D3DMATRIX*)&m );
|
g_pd3dDevice->SetTransform( D3DTS_WORLD, (D3DMATRIX*)&m );
|
||||||
|
|
||||||
|
|
||||||
|
class RageModelVertexArraySW : public RageModelVertexArray
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
RageModelVertexArraySW()
|
||||||
|
{
|
||||||
|
m_sizeVerts = 0;
|
||||||
|
m_sizeTriangles = 0;
|
||||||
|
m_pVertex = NULL;
|
||||||
|
m_pTriangles = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
~RageModelVertexArraySW()
|
||||||
|
{
|
||||||
|
m_sizeVerts = 0;
|
||||||
|
m_sizeTriangles = 0;
|
||||||
|
SAFE_DELETE( m_pVertex );
|
||||||
|
SAFE_DELETE( m_pTriangles );
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t sizeVerts() const
|
||||||
|
{
|
||||||
|
return m_sizeVerts;
|
||||||
|
}
|
||||||
|
void resizeVerts( size_t size )
|
||||||
|
{
|
||||||
|
SAFE_DELETE( m_pVertex );
|
||||||
|
|
||||||
|
m_sizeVerts = size;
|
||||||
|
m_pVertex = new Vertex[size];
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t sizeTriangles() const
|
||||||
|
{
|
||||||
|
return m_sizeTriangles;
|
||||||
|
}
|
||||||
|
void resizeTriangles( size_t size )
|
||||||
|
{
|
||||||
|
SAFE_DELETE( m_pTriangles );
|
||||||
|
|
||||||
|
m_sizeTriangles = size;
|
||||||
|
m_pTriangles = new msTriangle[size];
|
||||||
|
}
|
||||||
|
|
||||||
|
RageVector3& Position ( int index ) { return m_pVertex[index].p; }
|
||||||
|
RageVector2& TexCoord ( int index ) { return m_pVertex[index].t; }
|
||||||
|
RageVector3& Normal ( int index ) { return m_pVertex[index].n; }
|
||||||
|
Sint8& Bone ( int index ) { return m_pVertex[index].bone; }
|
||||||
|
msTriangle& Triangle ( int index ) { return m_pTriangles[index]; }
|
||||||
|
|
||||||
|
void SendVertices() const
|
||||||
|
{
|
||||||
|
g_pd3dDevice->SetVertexShader( D3DFVF_RageModelVertex );
|
||||||
|
g_pd3dDevice->DrawIndexedPrimitiveUP(
|
||||||
|
D3DPT_TRIANGLELIST, // PrimitiveType
|
||||||
|
0, // MinIndex
|
||||||
|
m_sizeVerts, // NumVertices
|
||||||
|
m_sizeTriangles, // PrimitiveCount,
|
||||||
|
m_pTriangles, // pIndexData,
|
||||||
|
D3DFMT_INDEX16, // IndexDataFormat,
|
||||||
|
m_pVertex, // pVertexStreamZeroData,
|
||||||
|
sizeof(Vertex) // VertexStreamZeroStride
|
||||||
|
);
|
||||||
|
}
|
||||||
|
protected:
|
||||||
|
size_t m_sizeVerts;
|
||||||
|
size_t m_sizeTriangles;
|
||||||
|
|
||||||
|
struct Vertex
|
||||||
|
{
|
||||||
|
RageVector3 p; // position
|
||||||
|
RageVector3 n; // normal
|
||||||
|
RageVector2 t; // texture coordinates
|
||||||
|
Sint8 bone;
|
||||||
|
} *m_pVertex;
|
||||||
|
|
||||||
|
msTriangle *m_pTriangles;
|
||||||
|
};
|
||||||
|
|
||||||
|
RageModelVertexArray* RageDisplay_D3D::CreateRageModelVertexArray()
|
||||||
|
{
|
||||||
|
return new RageModelVertexArraySW;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RageDisplay_D3D::DeleteRageModelVertexArray( RageModelVertexArray* p )
|
||||||
|
{
|
||||||
|
delete p;
|
||||||
|
}
|
||||||
|
|
||||||
void RageDisplay_D3D::DrawQuads( const RageSpriteVertex v[], int iNumVerts )
|
void RageDisplay_D3D::DrawQuads( const RageSpriteVertex v[], int iNumVerts )
|
||||||
{
|
{
|
||||||
ASSERT( (iNumVerts%4) == 0 );
|
ASSERT( (iNumVerts%4) == 0 );
|
||||||
@@ -820,23 +908,13 @@ void RageDisplay_D3D::DrawTriangles( const RageSpriteVertex v[], int iNumVerts )
|
|||||||
StatsAddVerts( iNumVerts );
|
StatsAddVerts( iNumVerts );
|
||||||
}
|
}
|
||||||
|
|
||||||
void RageDisplay_D3D::DrawIndexedTriangles( const RageModelVertex v[], int iNumVerts, const Uint16 pIndices[], int iNumIndices )
|
void RageDisplay_D3D::DrawIndexedTriangles( const RageModelVertexArray *p )
|
||||||
{
|
{
|
||||||
if( iNumIndices == 0 )
|
|
||||||
return;
|
|
||||||
g_pd3dDevice->SetVertexShader( D3DFVF_RageModelVertex );
|
|
||||||
SEND_CURRENT_MATRICES;
|
SEND_CURRENT_MATRICES;
|
||||||
g_pd3dDevice->DrawIndexedPrimitiveUP(
|
|
||||||
D3DPT_TRIANGLELIST, // PrimitiveType
|
p->SendVertices();
|
||||||
0, // MinIndex
|
|
||||||
iNumVerts, // NumVertices
|
StatsAddVerts( p->sizeTriangles()*3 );
|
||||||
iNumIndices/3, // PrimitiveCount,
|
|
||||||
pIndices, // pIndexData,
|
|
||||||
D3DFMT_INDEX16, // IndexDataFormat,
|
|
||||||
v, // pVertexStreamZeroData,
|
|
||||||
sizeof(RageModelVertex) // VertexStreamZeroStride
|
|
||||||
);
|
|
||||||
StatsAddVerts( iNumIndices );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Use the default poly-based implementation. D3D lines apparently don't support
|
/* Use the default poly-based implementation. D3D lines apparently don't support
|
||||||
|
|||||||
@@ -75,11 +75,14 @@ public:
|
|||||||
|
|
||||||
void SetSphereEnironmentMapping( bool b );
|
void SetSphereEnironmentMapping( bool b );
|
||||||
|
|
||||||
|
RageModelVertexArray* CreateRageModelVertexArray();
|
||||||
|
void DeleteRageModelVertexArray( RageModelVertexArray* p );
|
||||||
|
|
||||||
void DrawQuads( const RageSpriteVertex v[], int iNumVerts );
|
void DrawQuads( const RageSpriteVertex v[], int iNumVerts );
|
||||||
void DrawFan( const RageSpriteVertex v[], int iNumVerts );
|
void DrawFan( const RageSpriteVertex v[], int iNumVerts );
|
||||||
void DrawStrip( const RageSpriteVertex v[], int iNumVerts );
|
void DrawStrip( const RageSpriteVertex v[], int iNumVerts );
|
||||||
void DrawTriangles( const RageSpriteVertex v[], int iNumVerts );
|
void DrawTriangles( const RageSpriteVertex v[], int iNumVerts );
|
||||||
void DrawIndexedTriangles( const RageModelVertex v[], int iNumVerts, const Uint16* pIndices, int iNumIndices );
|
void DrawIndexedTriangles( const RageModelVertexArray *p );
|
||||||
// void DrawLineStrip( const RageSpriteVertex v[], int iNumVerts, float LineWidth );
|
// void DrawLineStrip( const RageSpriteVertex v[], int iNumVerts, float LineWidth );
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|||||||
@@ -125,3 +125,13 @@ void RageDisplay_Null::EndFrame()
|
|||||||
ProcessStatsOnFlip();
|
ProcessStatsOnFlip();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
RageModelVertexArray* RageDisplay_Null::CreateRageModelVertexArray()
|
||||||
|
{
|
||||||
|
ASSERT( 0 );
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RageDisplay_Null::DeleteRageModelVertexArray( RageModelVertexArray* p )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|||||||
@@ -60,11 +60,14 @@ public:
|
|||||||
|
|
||||||
void SetSphereEnironmentMapping( bool b ) { }
|
void SetSphereEnironmentMapping( bool b ) { }
|
||||||
|
|
||||||
|
RageModelVertexArray* CreateRageModelVertexArray();
|
||||||
|
void DeleteRageModelVertexArray( RageModelVertexArray* p );
|
||||||
|
|
||||||
void DrawQuads( const RageSpriteVertex v[], int iNumVerts ) { }
|
void DrawQuads( const RageSpriteVertex v[], int iNumVerts ) { }
|
||||||
void DrawFan( const RageSpriteVertex v[], int iNumVerts ) { }
|
void DrawFan( const RageSpriteVertex v[], int iNumVerts ) { }
|
||||||
void DrawStrip( const RageSpriteVertex v[], int iNumVerts ) { }
|
void DrawStrip( const RageSpriteVertex v[], int iNumVerts ) { }
|
||||||
void DrawTriangles( const RageSpriteVertex v[], int iNumVerts ) { }
|
void DrawTriangles( const RageSpriteVertex v[], int iNumVerts ) { }
|
||||||
void DrawIndexedTriangles( const RageModelVertex v[], int iNumVerts, const Uint16* pIndices, int iNumIndices ) { }
|
void DrawIndexedTriangles( const RageModelVertexArray *p ) { }
|
||||||
void DrawLineStrip( const RageSpriteVertex v[], int iNumVerts, float LineWidth ) { }
|
void DrawLineStrip( const RageSpriteVertex v[], int iNumVerts, float LineWidth ) { }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|||||||
@@ -883,51 +883,111 @@ static void SetupVertices( const RageSpriteVertex v[], int iNumVerts )
|
|||||||
glNormalPointer(GL_FLOAT, 0, Normal);
|
glNormalPointer(GL_FLOAT, 0, Normal);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define SEND_CURRENT_MATRICES \
|
void RageDisplay_OGL::SendCurrentMatrices()
|
||||||
glMatrixMode( GL_PROJECTION ); \
|
|
||||||
glLoadMatrixf( (const float*)GetProjectionTop() ); \
|
|
||||||
RageMatrix modelView; \
|
|
||||||
RageMatrixMultiply( &modelView, GetCentering(), GetViewTop() ); \
|
|
||||||
RageMatrixMultiply( &modelView, &modelView, GetWorldTop() ); \
|
|
||||||
glMatrixMode( GL_MODELVIEW ); \
|
|
||||||
glLoadMatrixf( (const float*)&modelView ); \
|
|
||||||
|
|
||||||
static void SetupVertices( const RageModelVertex v[], int iNumVerts )
|
|
||||||
{
|
{
|
||||||
static float *Vertex, *Texture, *Normal;
|
glMatrixMode( GL_PROJECTION );
|
||||||
static int Size = 0;
|
glLoadMatrixf( (const float*)GetProjectionTop() );
|
||||||
if(iNumVerts > Size)
|
RageMatrix modelView;
|
||||||
|
RageMatrixMultiply( &modelView, GetCentering(), GetViewTop() );
|
||||||
|
RageMatrixMultiply( &modelView, &modelView, GetWorldTop() );
|
||||||
|
glMatrixMode( GL_MODELVIEW );
|
||||||
|
glLoadMatrixf( (const float*)&modelView );
|
||||||
|
}
|
||||||
|
|
||||||
|
class RageModelVertexArraySW : public RageModelVertexArray
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
RageModelVertexArraySW()
|
||||||
{
|
{
|
||||||
Size = iNumVerts;
|
m_sizeVerts = 0;
|
||||||
delete [] Vertex;
|
m_sizeTriangles = 0;
|
||||||
delete [] Texture;
|
m_pPosition = NULL;
|
||||||
delete [] Normal;
|
m_pTexture = NULL;
|
||||||
Vertex = new float[Size*3];
|
m_pNormal = NULL;
|
||||||
Texture = new float[Size*2];
|
m_pBone = NULL;
|
||||||
Normal = new float[Size*3];
|
m_pTriangles = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(unsigned i = 0; i < unsigned(iNumVerts); ++i)
|
~RageModelVertexArraySW()
|
||||||
{
|
{
|
||||||
Vertex[i*3+0] = v[i].p[0];
|
m_sizeVerts = 0;
|
||||||
Vertex[i*3+1] = v[i].p[1];
|
m_sizeTriangles = 0;
|
||||||
Vertex[i*3+2] = v[i].p[2];
|
SAFE_DELETE( m_pPosition );
|
||||||
Texture[i*2+0] = v[i].t[0];
|
SAFE_DELETE( m_pTexture );
|
||||||
Texture[i*2+1] = v[i].t[1];
|
SAFE_DELETE( m_pNormal );
|
||||||
Normal[i*3+0] = v[i].n[0];
|
SAFE_DELETE( m_pBone );
|
||||||
Normal[i*3+1] = v[i].n[1];
|
SAFE_DELETE( m_pTriangles );
|
||||||
Normal[i*3+2] = v[i].n[2];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t sizeVerts() const
|
||||||
|
{
|
||||||
|
return m_sizeVerts;
|
||||||
|
}
|
||||||
|
void resizeVerts( size_t size )
|
||||||
|
{
|
||||||
|
SAFE_DELETE( m_pPosition );
|
||||||
|
SAFE_DELETE( m_pTexture );
|
||||||
|
SAFE_DELETE( m_pNormal );
|
||||||
|
SAFE_DELETE( m_pBone );
|
||||||
|
|
||||||
|
m_sizeVerts = size;
|
||||||
|
m_pPosition = new RageVector3[size];
|
||||||
|
m_pTexture = new RageVector2[size];
|
||||||
|
m_pNormal = new RageVector3[size];
|
||||||
|
m_pBone = new Sint8[size];
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t sizeTriangles() const
|
||||||
|
{
|
||||||
|
return m_sizeTriangles;
|
||||||
|
}
|
||||||
|
void resizeTriangles( size_t size )
|
||||||
|
{
|
||||||
|
SAFE_DELETE( m_pTriangles );
|
||||||
|
|
||||||
|
m_sizeTriangles = size;
|
||||||
|
m_pTriangles = new msTriangle[size];
|
||||||
|
}
|
||||||
|
|
||||||
|
RageVector3& Position ( int index ) { return m_pPosition[index]; }
|
||||||
|
RageVector2& TexCoord ( int index ) { return m_pTexture[index]; }
|
||||||
|
RageVector3& Normal ( int index ) { return m_pNormal[index]; }
|
||||||
|
Sint8& Bone ( int index ) { return m_pBone[index]; }
|
||||||
|
msTriangle& Triangle ( int index ) { return m_pTriangles[index]; }
|
||||||
|
|
||||||
|
void SendVertices() const
|
||||||
|
{
|
||||||
glEnableClientState(GL_VERTEX_ARRAY);
|
glEnableClientState(GL_VERTEX_ARRAY);
|
||||||
glVertexPointer(3, GL_FLOAT, 0, Vertex);
|
glVertexPointer(3, GL_FLOAT, 0, m_pPosition);
|
||||||
|
|
||||||
glDisableClientState(GL_COLOR_ARRAY);
|
glDisableClientState(GL_COLOR_ARRAY);
|
||||||
|
|
||||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||||
glTexCoordPointer(2, GL_FLOAT, 0, Texture);
|
glTexCoordPointer(2, GL_FLOAT, 0, m_pTexture);
|
||||||
|
|
||||||
glEnableClientState(GL_NORMAL_ARRAY);
|
glEnableClientState(GL_NORMAL_ARRAY);
|
||||||
glNormalPointer(GL_FLOAT, 0, Normal);
|
glNormalPointer(GL_FLOAT, 0, m_pNormal);
|
||||||
|
|
||||||
|
glDrawElements( GL_TRIANGLES, m_sizeTriangles*3, GL_UNSIGNED_SHORT, m_pTriangles );
|
||||||
|
}
|
||||||
|
protected:
|
||||||
|
size_t m_sizeVerts;
|
||||||
|
size_t m_sizeTriangles;
|
||||||
|
RageVector3 *m_pPosition;
|
||||||
|
RageVector2 *m_pTexture;
|
||||||
|
RageVector3 *m_pNormal;
|
||||||
|
Sint8 *m_pBone;
|
||||||
|
msTriangle *m_pTriangles;
|
||||||
|
};
|
||||||
|
|
||||||
|
RageModelVertexArray* RageDisplay_OGL::CreateRageModelVertexArray()
|
||||||
|
{
|
||||||
|
return new RageModelVertexArraySW;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RageDisplay_OGL::DeleteRageModelVertexArray( RageModelVertexArray* p )
|
||||||
|
{
|
||||||
|
delete p;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RageDisplay_OGL::DrawQuads( const RageSpriteVertex v[], int iNumVerts )
|
void RageDisplay_OGL::DrawQuads( const RageSpriteVertex v[], int iNumVerts )
|
||||||
@@ -937,7 +997,7 @@ void RageDisplay_OGL::DrawQuads( const RageSpriteVertex v[], int iNumVerts )
|
|||||||
if(iNumVerts == 0)
|
if(iNumVerts == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
SEND_CURRENT_MATRICES;
|
SendCurrentMatrices();
|
||||||
|
|
||||||
SetupVertices( v, iNumVerts );
|
SetupVertices( v, iNumVerts );
|
||||||
glDrawArrays( GL_QUADS, 0, iNumVerts );
|
glDrawArrays( GL_QUADS, 0, iNumVerts );
|
||||||
@@ -950,7 +1010,7 @@ void RageDisplay_OGL::DrawFan( const RageSpriteVertex v[], int iNumVerts )
|
|||||||
ASSERT( iNumVerts >= 3 );
|
ASSERT( iNumVerts >= 3 );
|
||||||
glMatrixMode( GL_PROJECTION );
|
glMatrixMode( GL_PROJECTION );
|
||||||
|
|
||||||
SEND_CURRENT_MATRICES;
|
SendCurrentMatrices();
|
||||||
|
|
||||||
SetupVertices( v, iNumVerts );
|
SetupVertices( v, iNumVerts );
|
||||||
glDrawArrays( GL_TRIANGLE_FAN, 0, iNumVerts );
|
glDrawArrays( GL_TRIANGLE_FAN, 0, iNumVerts );
|
||||||
@@ -961,7 +1021,7 @@ void RageDisplay_OGL::DrawStrip( const RageSpriteVertex v[], int iNumVerts )
|
|||||||
{
|
{
|
||||||
ASSERT( iNumVerts >= 3 );
|
ASSERT( iNumVerts >= 3 );
|
||||||
|
|
||||||
SEND_CURRENT_MATRICES;
|
SendCurrentMatrices();
|
||||||
|
|
||||||
SetupVertices( v, iNumVerts );
|
SetupVertices( v, iNumVerts );
|
||||||
glDrawArrays( GL_TRIANGLE_STRIP, 0, iNumVerts );
|
glDrawArrays( GL_TRIANGLE_STRIP, 0, iNumVerts );
|
||||||
@@ -974,25 +1034,20 @@ void RageDisplay_OGL::DrawTriangles( const RageSpriteVertex v[], int iNumVerts )
|
|||||||
return;
|
return;
|
||||||
ASSERT( (iNumVerts%3) == 0 );
|
ASSERT( (iNumVerts%3) == 0 );
|
||||||
|
|
||||||
SEND_CURRENT_MATRICES;
|
SendCurrentMatrices();
|
||||||
|
|
||||||
SetupVertices( v, iNumVerts );
|
SetupVertices( v, iNumVerts );
|
||||||
glDrawArrays( GL_TRIANGLES, 0, iNumVerts );
|
glDrawArrays( GL_TRIANGLES, 0, iNumVerts );
|
||||||
StatsAddVerts( iNumVerts );
|
StatsAddVerts( iNumVerts );
|
||||||
}
|
}
|
||||||
|
|
||||||
void RageDisplay_OGL::DrawIndexedTriangles( const RageModelVertex v[], int iNumVerts, const Uint16 pIndices[], int iNumIndices )
|
void RageDisplay_OGL::DrawIndexedTriangles( const RageModelVertexArray *p )
|
||||||
{
|
{
|
||||||
if( iNumIndices == 0 )
|
SendCurrentMatrices();
|
||||||
return;
|
|
||||||
ASSERT( (iNumIndices%3) == 0 );
|
|
||||||
|
|
||||||
SEND_CURRENT_MATRICES;
|
p->SendVertices();
|
||||||
|
|
||||||
SetupVertices( v, iNumVerts );
|
StatsAddVerts( p->sizeTriangles()*3 );
|
||||||
// glInterleavedArrays( RageSpriteVertexFormat, sizeof(RageSpriteVertex), v );
|
|
||||||
glDrawElements( GL_TRIANGLES, iNumIndices, GL_UNSIGNED_SHORT, pIndices );
|
|
||||||
StatsAddVerts( iNumIndices );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RageDisplay_OGL::DrawLineStrip( const RageSpriteVertex v[], int iNumVerts, float LineWidth )
|
void RageDisplay_OGL::DrawLineStrip( const RageSpriteVertex v[], int iNumVerts, float LineWidth )
|
||||||
@@ -1005,7 +1060,7 @@ void RageDisplay_OGL::DrawLineStrip( const RageSpriteVertex v[], int iNumVerts,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SEND_CURRENT_MATRICES;
|
SendCurrentMatrices();
|
||||||
|
|
||||||
/* Draw a nice AA'd line loop. One problem with this is that point and line
|
/* Draw a nice AA'd line loop. One problem with this is that point and line
|
||||||
* sizes don't always precisely match, which doesn't look quite right.
|
* sizes don't always precisely match, which doesn't look quite right.
|
||||||
|
|||||||
@@ -61,11 +61,14 @@ public:
|
|||||||
|
|
||||||
void SetSphereEnironmentMapping( bool b );
|
void SetSphereEnironmentMapping( bool b );
|
||||||
|
|
||||||
|
RageModelVertexArray* CreateRageModelVertexArray();
|
||||||
|
void DeleteRageModelVertexArray( RageModelVertexArray* p );
|
||||||
|
|
||||||
void DrawQuads( const RageSpriteVertex v[], int iNumVerts );
|
void DrawQuads( const RageSpriteVertex v[], int iNumVerts );
|
||||||
void DrawFan( const RageSpriteVertex v[], int iNumVerts );
|
void DrawFan( const RageSpriteVertex v[], int iNumVerts );
|
||||||
void DrawStrip( const RageSpriteVertex v[], int iNumVerts );
|
void DrawStrip( const RageSpriteVertex v[], int iNumVerts );
|
||||||
void DrawTriangles( const RageSpriteVertex v[], int iNumVerts );
|
void DrawTriangles( const RageSpriteVertex v[], int iNumVerts );
|
||||||
void DrawIndexedTriangles( const RageModelVertex v[], int iNumVerts, const Uint16* pIndices, int iNumIndices );
|
void DrawIndexedTriangles( const RageModelVertexArray *p );
|
||||||
void DrawLineStrip( const RageSpriteVertex v[], int iNumVerts, float LineWidth );
|
void DrawLineStrip( const RageSpriteVertex v[], int iNumVerts, float LineWidth );
|
||||||
|
|
||||||
CString GetTextureDiagnostics( unsigned id ) const;
|
CString GetTextureDiagnostics( unsigned id ) const;
|
||||||
@@ -77,6 +80,7 @@ protected:
|
|||||||
RageMatrix GetOrthoMatrix( float l, float r, float b, float t, float zn, float zf );
|
RageMatrix GetOrthoMatrix( float l, float r, float b, float t, float zn, float zf );
|
||||||
PixelFormat GetImgPixelFormat( SDL_Surface* &img, bool &FreeImg, int width, int height );
|
PixelFormat GetImgPixelFormat( SDL_Surface* &img, bool &FreeImg, int width, int height );
|
||||||
bool SupportsSurfaceFormat( PixelFormat pixfmt );
|
bool SupportsSurfaceFormat( PixelFormat pixfmt );
|
||||||
|
void SendCurrentMatrices();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
#include "RageUtil.h"
|
#include "RageUtil.h"
|
||||||
#include "RageFile.h"
|
#include "RageFile.h"
|
||||||
#include "RageMath.h"
|
#include "RageMath.h"
|
||||||
|
#include "RageDisplay.h"
|
||||||
|
|
||||||
|
|
||||||
RageModelGeometry::RageModelGeometry ()
|
RageModelGeometry::RageModelGeometry ()
|
||||||
@@ -22,6 +23,13 @@ RageModelGeometry::RageModelGeometry ()
|
|||||||
|
|
||||||
RageModelGeometry::~RageModelGeometry ()
|
RageModelGeometry::~RageModelGeometry ()
|
||||||
{
|
{
|
||||||
|
for (unsigned i = 0; i < m_Meshes.size(); i++)
|
||||||
|
{
|
||||||
|
msMesh& mesh = m_Meshes[i];
|
||||||
|
RageModelVertexArray *&pVertices = mesh.Vertices;
|
||||||
|
DISPLAY->DeleteRageModelVertexArray( pVertices );
|
||||||
|
pVertices = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RageModelGeometry::OptimizeBones()
|
void RageModelGeometry::OptimizeBones()
|
||||||
@@ -32,13 +40,12 @@ void RageModelGeometry::OptimizeBones()
|
|||||||
|
|
||||||
// check to see if all vertices have the same bone index
|
// check to see if all vertices have the same bone index
|
||||||
bool bAllVertsUseSameBone = true;
|
bool bAllVertsUseSameBone = true;
|
||||||
char nBoneIndex = !mesh.Vertices.empty() ? mesh.Vertices[0].boneIndex : (char) -1;
|
char nBoneIndex = !mesh.Vertices->sizeVerts()==0 ? mesh.Vertices->Bone(0) : (char) -1;
|
||||||
if( nBoneIndex != -1 )
|
if( nBoneIndex != -1 )
|
||||||
{
|
{
|
||||||
for (unsigned j = 1; j < mesh.Vertices.size(); j++)
|
for (unsigned j = 1; j < mesh.Vertices->sizeVerts(); j++)
|
||||||
{
|
{
|
||||||
RageModelVertex& vertex = mesh.Vertices[j];
|
if( mesh.Vertices->Bone(j) != nBoneIndex )
|
||||||
if( vertex.boneIndex != nBoneIndex )
|
|
||||||
{
|
{
|
||||||
bAllVertsUseSameBone = false;
|
bAllVertsUseSameBone = false;
|
||||||
break;
|
break;
|
||||||
@@ -50,10 +57,9 @@ void RageModelGeometry::OptimizeBones()
|
|||||||
mesh.nBoneIndex = nBoneIndex;
|
mesh.nBoneIndex = nBoneIndex;
|
||||||
|
|
||||||
// clear all vertex/bone associations;
|
// clear all vertex/bone associations;
|
||||||
for (unsigned j = 0; j < mesh.Vertices.size(); j++)
|
for (unsigned j = 0; j < mesh.Vertices->sizeVerts(); j++)
|
||||||
{
|
{
|
||||||
RageModelVertex& vertex = mesh.Vertices[j];
|
mesh.Vertices->Bone(j) = -1;
|
||||||
vertex.boneIndex = -1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -99,11 +105,14 @@ void RageModelGeometry::LoadMilkshapeAscii( CString sPath )
|
|||||||
int nNumMeshes = 0;
|
int nNumMeshes = 0;
|
||||||
if (sscanf (sLine, "Meshes: %d", &nNumMeshes) == 1)
|
if (sscanf (sLine, "Meshes: %d", &nNumMeshes) == 1)
|
||||||
{
|
{
|
||||||
|
ASSERT( m_Meshes.empty() );
|
||||||
m_Meshes.resize( nNumMeshes );
|
m_Meshes.resize( nNumMeshes );
|
||||||
|
|
||||||
for (i = 0; i < nNumMeshes; i++)
|
for (i = 0; i < nNumMeshes; i++)
|
||||||
{
|
{
|
||||||
msMesh& mesh = m_Meshes[i];
|
msMesh& mesh = m_Meshes[i];
|
||||||
|
RageModelVertexArray *&pVertices = mesh.Vertices;
|
||||||
|
pVertices = DISPLAY->CreateRageModelVertexArray();
|
||||||
|
|
||||||
if( f.GetLine( sLine ) <= 0 )
|
if( f.GetLine( sLine ) <= 0 )
|
||||||
THROW
|
THROW
|
||||||
@@ -128,18 +137,18 @@ void RageModelGeometry::LoadMilkshapeAscii( CString sPath )
|
|||||||
if (sscanf (sLine, "%d", &nNumVertices) != 1)
|
if (sscanf (sLine, "%d", &nNumVertices) != 1)
|
||||||
THROW
|
THROW
|
||||||
|
|
||||||
mesh.Vertices.resize( nNumVertices );
|
pVertices->resizeVerts( nNumVertices );
|
||||||
|
|
||||||
for (j = 0; j < nNumVertices; j++)
|
for (j = 0; j < nNumVertices; j++)
|
||||||
{
|
{
|
||||||
if( f.GetLine( sLine ) <= 0 )
|
if( f.GetLine( sLine ) <= 0 )
|
||||||
THROW
|
THROW
|
||||||
|
|
||||||
RageVector3 Vertex;
|
RageVector3 pos;
|
||||||
RageVector2 uv;
|
RageVector2 uv;
|
||||||
if (sscanf (sLine, "%d %f %f %f %f %f %d",
|
if (sscanf (sLine, "%d %f %f %f %f %f %d",
|
||||||
&nFlags,
|
&nFlags,
|
||||||
&Vertex[0], &Vertex[1], &Vertex[2],
|
&pos[0], &pos[1], &pos[2],
|
||||||
&uv[0], &uv[1],
|
&uv[0], &uv[1],
|
||||||
&nIndex
|
&nIndex
|
||||||
) != 7)
|
) != 7)
|
||||||
@@ -147,12 +156,11 @@ void RageModelGeometry::LoadMilkshapeAscii( CString sPath )
|
|||||||
THROW
|
THROW
|
||||||
}
|
}
|
||||||
|
|
||||||
RageModelVertex& vertex = mesh.Vertices[j];
|
|
||||||
// vertex.nFlags = nFlags;
|
// vertex.nFlags = nFlags;
|
||||||
memcpy( vertex.p, Vertex, sizeof(vertex.p) );
|
pVertices->Position(j) = pos;
|
||||||
memcpy( vertex.t, uv, sizeof(vertex.t) );
|
pVertices->TexCoord(j) = uv;
|
||||||
vertex.boneIndex = (byte)nIndex;
|
pVertices->Bone(j) = (byte)nIndex;
|
||||||
RageVec3AddToBounds( RageVector3(Vertex), m_vMins, m_vMaxs );
|
RageVec3AddToBounds( RageVector3(pos), m_vMins, m_vMaxs );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -193,7 +201,7 @@ void RageModelGeometry::LoadMilkshapeAscii( CString sPath )
|
|||||||
if (sscanf (sLine, "%d", &nNumTriangles) != 1)
|
if (sscanf (sLine, "%d", &nNumTriangles) != 1)
|
||||||
THROW
|
THROW
|
||||||
|
|
||||||
mesh.Triangles.resize( nNumTriangles );
|
pVertices->resizeTriangles( nNumTriangles );
|
||||||
|
|
||||||
for (j = 0; j < nNumTriangles; j++)
|
for (j = 0; j < nNumTriangles; j++)
|
||||||
{
|
{
|
||||||
@@ -215,12 +223,13 @@ void RageModelGeometry::LoadMilkshapeAscii( CString sPath )
|
|||||||
// deflate the normals into vertices
|
// deflate the normals into vertices
|
||||||
for( int k=0; k<3; k++ )
|
for( int k=0; k<3; k++ )
|
||||||
{
|
{
|
||||||
RageModelVertex& vertex = mesh.Vertices[ nIndices[k] ];
|
//RageModelVertex& vertex = mesh.Vertices[ nIndices[k] ];
|
||||||
RageVector3& normal = Normals[ nNormalIndices[k] ];
|
//RageVector3& normal = Normals[ nNormalIndices[k] ];
|
||||||
vertex.n = normal;
|
//vertex.n = normal;
|
||||||
|
mesh.Vertices->Normal( nIndices[k] ) = Normals[ nNormalIndices[k] ];
|
||||||
}
|
}
|
||||||
|
|
||||||
msTriangle& Triangle = mesh.Triangles[j];
|
msTriangle& Triangle = pVertices->Triangle(j);
|
||||||
// Triangle.nFlags = nFlags;
|
// Triangle.nFlags = nFlags;
|
||||||
memcpy( &Triangle.nVertexIndices, nIndices, sizeof(Triangle.nVertexIndices) );
|
memcpy( &Triangle.nVertexIndices, nIndices, sizeof(Triangle.nVertexIndices) );
|
||||||
// Triangle.nSmoothingGroup = nIndex;
|
// Triangle.nSmoothingGroup = nIndex;
|
||||||
|
|||||||
+15
-13
@@ -218,19 +218,21 @@ struct RageSpriteVertex // has color
|
|||||||
RageVector2 t; // texture coordinates
|
RageVector2 t; // texture coordinates
|
||||||
};
|
};
|
||||||
|
|
||||||
struct RageModelVertex // doesn't have color. Relies on material color
|
|
||||||
{
|
//struct RageModelVertex // doesn't have color. Relies on material color
|
||||||
/* Zero out by default. */
|
//{
|
||||||
RageModelVertex():
|
// /* Zero out by default. */
|
||||||
p(0,0,0),
|
// RageModelVertex():
|
||||||
n(0,0,0),
|
// p(0,0,0),
|
||||||
t(0,0)
|
// n(0,0,0),
|
||||||
{ }
|
// t(0,0)
|
||||||
RageVector3 p; // position
|
// { }
|
||||||
RageVector3 n; // normal
|
// RageVector3 p; // position
|
||||||
RageVector2 t; // texture coordinates
|
// RageVector3 n; // normal
|
||||||
Sint8 boneIndex;
|
// RageVector2 t; // texture coordinates
|
||||||
};
|
// Sint8 bone;
|
||||||
|
//};
|
||||||
|
|
||||||
|
|
||||||
// RageMatrix elements are specified in row-major order. This
|
// RageMatrix elements are specified in row-major order. This
|
||||||
// means that the translate terms are located in the fourth row and the
|
// means that the translate terms are located in the fourth row and the
|
||||||
|
|||||||
Reference in New Issue
Block a user