draw models with 2 textures with multitexture instead of 2 passes. D3D multitexture not tested yet

This commit is contained in:
Chris Danford
2004-02-04 09:55:18 +00:00
parent 9c7d8a60c2
commit 9502f1c262
12 changed files with 96 additions and 25 deletions
+2 -1
View File
@@ -219,7 +219,8 @@ void BitmapText::DrawChars()
unsigned end = start;
while(end < uEndGlyph && tex[end] == tex[start])
end++;
DISPLAY->SetTexture( tex[start] );
DISPLAY->ClearAllTextures();
DISPLAY->SetTexture( 0, tex[start] );
RageSpriteVertex &start_vertex = verts[start*4];
int iNumVertsToDraw = (end-start)*4;
DISPLAY->DrawQuads( &start_vertex, iNumVertsToDraw );
+3 -2
View File
@@ -122,11 +122,12 @@ void GraphDisplay::Update( float fDeltaTime )
void GraphDisplay::DrawPrimitives()
{
DISPLAY->SetTexture( m_pTexture );
DISPLAY->ClearAllTextures();
DISPLAY->SetTexture( 0, m_pTexture );
Actor::SetRenderStates(); // set Actor-specified render states
DISPLAY->DrawQuads( Slices, ARRAYSIZE(Slices) );
DISPLAY->SetTexture( NULL );
DISPLAY->SetTexture( 0, NULL );
}
+1 -1
View File
@@ -119,7 +119,7 @@ void GrooveGraph::Mountain::Update( float fDeltaTime )
void GrooveGraph::Mountain::DrawPrimitives()
{
DISPLAY->SetTexture( NULL );
DISPLAY->ClearAllTextures();
DISPLAY->SetTextureModeModulate();
RageSpriteVertex v[4];
+1 -1
View File
@@ -141,7 +141,7 @@ void GrooveRadar::GrooveRadarValueMap::DrawPrimitives()
// draw radar filling
const float fRadius = m_sprRadarBase.GetZoomedHeight()/2.0f*1.1f;
DISPLAY->SetTexture( NULL );
DISPLAY->ClearAllTextures();
DISPLAY->SetTextureModeModulate();
RageSpriteVertex v[12]; // needed to draw 5 fan primitives and 10 strip primitives
+9 -9
View File
@@ -569,22 +569,21 @@ void Model::DrawPrimitives()
mat.fShininess );
// render the first pass with texture 1
DISPLAY->SetTexture( mat.diffuse.ani.GetCurrentTexture() );
DISPLAY->SetTexture( 0, mat.diffuse.ani.GetCurrentTexture() );
DISPLAY->SetSphereEnironmentMapping( mat.diffuse.bSphereMapped );
// UGLY: This overrides the Actor's BlendMode
DISPLAY->SetBlendMode( mat.diffuse.blendMode );
DISPLAY->DrawIndexedTriangles( &TempVertices[0], pMesh->Vertices.size(), (Uint16*)&pMesh->Triangles[0], pMesh->Triangles.size()*3 );
// DISPLAY->SetBlendMode( mat.diffuse.blendMode );
// render the second pass with texture 2
if( mat.alpha.ani.GetCurrentTexture() )
{
DISPLAY->SetTexture( mat.alpha.ani.GetCurrentTexture() );
DISPLAY->SetTexture( 1, mat.alpha.ani.GetCurrentTexture() );
DISPLAY->SetSphereEnironmentMapping( mat.alpha.bSphereMapped );
// UGLY: This overrides the Actor's BlendMode
DISPLAY->SetBlendMode( mat.alpha.blendMode );
DISPLAY->DrawIndexedTriangles( &TempVertices[0], pMesh->Vertices.size(), (Uint16*)&pMesh->Triangles[0], pMesh->Triangles.size()*3 );
DISPLAY->SetTextureModeAdd();
}
DISPLAY->DrawIndexedTriangles( &TempVertices[0], pMesh->Vertices.size(), (Uint16*)&pMesh->Triangles[0], pMesh->Triangles.size()*3 );
DISPLAY->SetSphereEnironmentMapping( false );
}
else
@@ -600,7 +599,7 @@ void Model::DrawPrimitives()
diffuse,
specular,
shininess );
DISPLAY->SetTexture( NULL );
DISPLAY->ClearAllTextures();
DISPLAY->SetSphereEnironmentMapping( false );
DISPLAY->DrawIndexedTriangles( &TempVertices[0], pMesh->Vertices.size(), (Uint16*)&pMesh->Triangles[0], pMesh->Triangles.size()*3 );
}
@@ -638,7 +637,8 @@ void Model::DrawPrimitives()
Diffuse,
mat.Specular,
mat.fShininess );
DISPLAY->SetTexture( mat.diffuse.ani.GetCurrentTexture() );
DISPLAY->ClearAllTextures();
DISPLAY->SetTexture( 0, mat.diffuse.ani.GetCurrentTexture() );
}
else
{
@@ -653,7 +653,7 @@ void Model::DrawPrimitives()
diffuse,
specular,
shininess );
DISPLAY->SetTexture( NULL );
DISPLAY->ClearAllTextures();
}
DISPLAY->DrawIndexedTriangles( &TempVertices[0], pMesh->Vertices.size(), (Uint16*)&pMesh->Triangles[0], pMesh->Triangles.size()*3 );
+6 -3
View File
@@ -492,7 +492,8 @@ void NoteDisplay::DrawHoldTopCap( const HoldNote& hn, const bool bIsBeingHeld, f
RageSpriteVertex *v = &queue[0];
RageTexture* pTexture = pSprTopCap->GetTexture();
const RectF *pRect = pSprTopCap->GetCurrentTextureCoordRect();
DISPLAY->SetTexture( pTexture );
DISPLAY->ClearAllTextures();
DISPLAY->SetTexture( 0, pTexture );
DISPLAY->SetBlendMode( BLEND_NORMAL );
DISPLAY->SetBackfaceCull( false );
DISPLAY->SetTextureWrapping(false);
@@ -563,7 +564,8 @@ void NoteDisplay::DrawHoldBody( const HoldNote& hn, const bool bIsBeingHeld, flo
RageSpriteVertex *v = &queue[0];
RageTexture* pTexture = pSprBody->GetTexture();
const RectF *pRect = pSprBody->GetCurrentTextureCoordRect();
DISPLAY->SetTexture( pTexture );
DISPLAY->ClearAllTextures();
DISPLAY->SetTexture( 0, pTexture );
DISPLAY->SetBlendMode( BLEND_NORMAL );
DISPLAY->SetBackfaceCull( false );
DISPLAY->SetTextureWrapping( true );
@@ -665,7 +667,8 @@ void NoteDisplay::DrawHoldBottomCap( const HoldNote& hn, const bool bIsBeingHeld
RageSpriteVertex *v = &queue[0];
RageTexture* pTexture = pBottomCap->GetTexture();
const RectF *pRect = pBottomCap->GetCurrentTextureCoordRect();
DISPLAY->SetTexture( pTexture );
DISPLAY->ClearAllTextures();
DISPLAY->SetTexture( 0, pTexture );
DISPLAY->SetBlendMode( BLEND_NORMAL );
DISPLAY->SetBackfaceCull( false );
DISPLAY->SetTextureWrapping(false);
+4 -1
View File
@@ -16,6 +16,7 @@
const int REFRESH_DEFAULT = 0;
struct SDL_Surface;
const int MAX_TEXTURE_UNITS = 2;
// VertexArray holds vertex data in a format that is most efficient for
// the graphics API.
@@ -160,9 +161,11 @@ public:
int xoffset, int yoffset, int width, int height
) = 0;
virtual void DeleteTexture( unsigned uTexHandle ) = 0;
virtual void SetTexture( RageTexture* pTexture ) = 0;
virtual void ClearAllTextures() = 0;
virtual void SetTexture( int iTextureUnitIndex, RageTexture* pTexture ) = 0;
virtual void SetTextureModeModulate() = 0;
virtual void SetTextureModeGlow( GlowMode m=GLOW_WHITEN ) = 0;
virtual void SetTextureModeAdd() = 0;
virtual void SetTextureWrapping( bool b ) = 0;
virtual int GetMaxTextureSize() const = 0;
virtual void SetTextureFiltering( bool b ) = 0;
+20 -3
View File
@@ -864,17 +864,24 @@ void RageDisplay_D3D::DrawLineStrip( const RageSpriteVertex v[], int iNumVerts,
StatsAddVerts( iNumVerts );
}
*/
void RageDisplay_D3D::SetTexture( RageTexture* pTexture )
void RageDisplay_D3D::ClearAllTextures()
{
for( int i=0; i<MAX_TEXTURE_UNITS; i++ )
SetTexture( i, NULL );
}
void RageDisplay_D3D::SetTexture( int iTextureUnitIndex, RageTexture* pTexture )
{
if( pTexture == NULL )
{
g_pd3dDevice->SetTexture( 0, NULL );
g_pd3dDevice->SetTexture( iTextureUnitIndex, NULL );
return;
}
unsigned uTexHandle = pTexture->GetTexHandle();
IDirect3DTexture8* pTex = (IDirect3DTexture8*)uTexHandle;
g_pd3dDevice->SetTexture( 0, pTex );
g_pd3dDevice->SetTexture( iTextureUnitIndex, pTex );
// Set palette (if any)
SetPalette(uTexHandle);
@@ -899,6 +906,16 @@ void RageDisplay_D3D::SetTextureModeGlow(GlowMode m)
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE );
}
void RageDisplay_D3D::SetTextureModeAdd()
{
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG2 );
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE );
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE );
}
void RageDisplay_D3D::SetTextureFiltering( bool b )
{
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_MINFILTER, b ? D3DTEXF_LINEAR : D3DTEXF_POINT );
+3 -1
View File
@@ -42,9 +42,11 @@ public:
int xoffset, int yoffset, int width, int height
);
void DeleteTexture( unsigned uTexHandle );
void SetTexture( RageTexture* pTexture );
void ClearAllTextures();
void SetTexture( int iTextureUnitIndex, RageTexture* pTexture );
void SetTextureModeModulate();
void SetTextureModeGlow( GlowMode m=GLOW_WHITEN );
void SetTextureModeAdd();
void SetTextureWrapping( bool b );
int GetMaxTextureSize() const;
void SetTextureFiltering( bool b);
+42 -1
View File
@@ -45,6 +45,7 @@ namespace GLExt {
extern PWSWAPINTERVALEXTPROC wglSwapIntervalEXT;
extern PFNGLCOLORTABLEPROC glColorTableEXT;
extern PFNGLCOLORTABLEPARAMETERIVPROC glGetColorTableParameterivEXT;
extern PFNGLACTIVETEXTUREARBPROC glActiveTextureARB;
};
#if defined(DARWIN)
@@ -83,6 +84,7 @@ namespace GLExt {
PWSWAPINTERVALEXTPROC GLExt::wglSwapIntervalEXT = NULL;
PFNGLCOLORTABLEPROC GLExt::glColorTableEXT = NULL;
PFNGLCOLORTABLEPARAMETERIVPROC GLExt::glGetColorTableParameterivEXT = NULL;
PFNGLACTIVETEXTUREARBPROC GLExt::glActiveTextureARB = NULL;
static bool g_bEXT_texture_env_combine = true;
static bool g_bGL_EXT_bgra = true;
@@ -572,6 +574,7 @@ void SetupExtensions()
#endif
GLExt::glColorTableEXT = (PFNGLCOLORTABLEPROC) wind->GetProcAddress("glColorTableEXT");
GLExt::glGetColorTableParameterivEXT = (PFNGLCOLORTABLEPARAMETERIVPROC) wind->GetProcAddress("glGetColorTableParameterivEXT");
GLExt::glActiveTextureARB = (PFNGLACTIVETEXTUREARBPROC) wind->GetProcAddress("glActiveTextureARB");
g_bEXT_texture_env_combine = HasExtension("GL_EXT_texture_env_combine");
g_bGL_EXT_bgra = HasExtension("GL_EXT_bgra");
CheckPalettedTextures( false );
@@ -1013,8 +1016,40 @@ void RageDisplay_OGL::DrawLineStrip( const RageSpriteVertex v[], int iNumVerts,
glDisable(GL_POINT_SMOOTH);
}
void RageDisplay_OGL::SetTexture( RageTexture* pTexture )
void RageDisplay_OGL::ClearAllTextures()
{
for( int i=0; i<MAX_TEXTURE_UNITS; i++ )
SetTexture( i, NULL );
// HACK: Reset the active texture to 0.
// TODO: Change all texture functions to take a stage number.
if( GLExt::glActiveTextureARB )
GLExt::glActiveTextureARB(GL_TEXTURE0_ARB);
}
void RageDisplay_OGL::SetTexture( int iTextureUnitIndex, RageTexture* pTexture )
{
if( GLExt::glActiveTextureARB == NULL )
{
// multitexture isn't supported. Ignore all textures except for 0.
if( iTextureUnitIndex != 0 )
return;
}
else
{
switch( iTextureUnitIndex )
{
case 0:
GLExt::glActiveTextureARB(GL_TEXTURE0_ARB);
break;
case 1:
GLExt::glActiveTextureARB(GL_TEXTURE1_ARB);
break;
default:
ASSERT(0);
}
}
if( pTexture )
{
glEnable( GL_TEXTURE_2D );
@@ -1056,6 +1091,12 @@ void RageDisplay_OGL::SetTextureModeGlow(GlowMode m)
return;
}
}
void RageDisplay_OGL::SetTextureModeAdd()
{
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_ADD);
}
void RageDisplay_OGL::SetTextureFiltering( bool b )
{
+3 -1
View File
@@ -28,9 +28,11 @@ public:
int xoffset, int yoffset, int width, int height
);
void DeleteTexture( unsigned uTexHandle );
void SetTexture( RageTexture* pTexture );
void ClearAllTextures();
void SetTexture( int iTextureUnitIndex, RageTexture* pTexture );
void SetTextureModeModulate();
void SetTextureModeGlow( GlowMode m=GLOW_WHITEN );
void SetTextureModeAdd();
void SetTextureWrapping( bool b );
int GetMaxTextureSize() const;
void SetTextureFiltering( bool b);
+2 -1
View File
@@ -335,7 +335,8 @@ void Sprite::DrawTexture( const TweenState *state )
v[2].p = RageVector3( croppedQuadVerticies.right, croppedQuadVerticies.bottom, 0 ); // bottom right
v[3].p = RageVector3( croppedQuadVerticies.right, croppedQuadVerticies.top, 0 ); // top right
DISPLAY->SetTexture( m_pTexture );
DISPLAY->ClearAllTextures();
DISPLAY->SetTexture( 0, m_pTexture );
// Must call this after setting the texture or else texture
// parameters have no effect.