From 9502f1c26228bb788457f73fa126102b13a9b176 Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Wed, 4 Feb 2004 09:55:18 +0000 Subject: [PATCH] draw models with 2 textures with multitexture instead of 2 passes. D3D multitexture not tested yet --- stepmania/src/BitmapText.cpp | 3 ++- stepmania/src/GraphDisplay.cpp | 5 ++-- stepmania/src/GrooveGraph.cpp | 2 +- stepmania/src/GrooveRadar.cpp | 2 +- stepmania/src/Model.cpp | 18 ++++++------- stepmania/src/NoteDisplay.cpp | 9 ++++--- stepmania/src/RageDisplay.h | 5 +++- stepmania/src/RageDisplay_D3D.cpp | 23 ++++++++++++++--- stepmania/src/RageDisplay_D3D.h | 4 ++- stepmania/src/RageDisplay_OGL.cpp | 43 ++++++++++++++++++++++++++++++- stepmania/src/RageDisplay_OGL.h | 4 ++- stepmania/src/Sprite.cpp | 3 ++- 12 files changed, 96 insertions(+), 25 deletions(-) diff --git a/stepmania/src/BitmapText.cpp b/stepmania/src/BitmapText.cpp index 4ae79f9439..1a4086461a 100644 --- a/stepmania/src/BitmapText.cpp +++ b/stepmania/src/BitmapText.cpp @@ -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 ); diff --git a/stepmania/src/GraphDisplay.cpp b/stepmania/src/GraphDisplay.cpp index 43f98bb047..f4b1d63ae4 100644 --- a/stepmania/src/GraphDisplay.cpp +++ b/stepmania/src/GraphDisplay.cpp @@ -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 ); } diff --git a/stepmania/src/GrooveGraph.cpp b/stepmania/src/GrooveGraph.cpp index 8b32b7ca4d..80e4c2d5ca 100644 --- a/stepmania/src/GrooveGraph.cpp +++ b/stepmania/src/GrooveGraph.cpp @@ -119,7 +119,7 @@ void GrooveGraph::Mountain::Update( float fDeltaTime ) void GrooveGraph::Mountain::DrawPrimitives() { - DISPLAY->SetTexture( NULL ); + DISPLAY->ClearAllTextures(); DISPLAY->SetTextureModeModulate(); RageSpriteVertex v[4]; diff --git a/stepmania/src/GrooveRadar.cpp b/stepmania/src/GrooveRadar.cpp index 268284675d..4d528ca2f1 100644 --- a/stepmania/src/GrooveRadar.cpp +++ b/stepmania/src/GrooveRadar.cpp @@ -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 diff --git a/stepmania/src/Model.cpp b/stepmania/src/Model.cpp index 38554d9867..c81cb2c525 100644 --- a/stepmania/src/Model.cpp +++ b/stepmania/src/Model.cpp @@ -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 ); diff --git a/stepmania/src/NoteDisplay.cpp b/stepmania/src/NoteDisplay.cpp index 7527f4bdac..9a1bd80973 100644 --- a/stepmania/src/NoteDisplay.cpp +++ b/stepmania/src/NoteDisplay.cpp @@ -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); diff --git a/stepmania/src/RageDisplay.h b/stepmania/src/RageDisplay.h index 0a97c8670b..07e4bb32da 100644 --- a/stepmania/src/RageDisplay.h +++ b/stepmania/src/RageDisplay.h @@ -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; diff --git a/stepmania/src/RageDisplay_D3D.cpp b/stepmania/src/RageDisplay_D3D.cpp index 7fa890279c..f012e00db2 100644 --- a/stepmania/src/RageDisplay_D3D.cpp +++ b/stepmania/src/RageDisplay_D3D.cpp @@ -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; iSetTexture( 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 ); diff --git a/stepmania/src/RageDisplay_D3D.h b/stepmania/src/RageDisplay_D3D.h index 98e18f7507..ae48b413c6 100644 --- a/stepmania/src/RageDisplay_D3D.h +++ b/stepmania/src/RageDisplay_D3D.h @@ -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); diff --git a/stepmania/src/RageDisplay_OGL.cpp b/stepmania/src/RageDisplay_OGL.cpp index 80bfd35182..254904fb58 100644 --- a/stepmania/src/RageDisplay_OGL.cpp +++ b/stepmania/src/RageDisplay_OGL.cpp @@ -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; iSetTexture( m_pTexture ); + DISPLAY->ClearAllTextures(); + DISPLAY->SetTexture( 0, m_pTexture ); // Must call this after setting the texture or else texture // parameters have no effect.