From c3a0714e4aca59da198731e9938af875a36a7eeb Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Tue, 13 Feb 2007 07:39:49 +0000 Subject: [PATCH] make Quad less special. Create a "default" texture object for the "no texture" properties. This way, loaded sprites always have a texture loaded. --- stepmania/src/Quad.cpp | 3 +++ stepmania/src/Quad.h | 5 ----- stepmania/src/RageDisplay.h | 3 +++ stepmania/src/RageDisplay_Null.h | 1 + stepmania/src/RageDisplay_OGL.h | 1 + stepmania/src/RageTextureManager.cpp | 28 +++++++++++++++++++++++++++- stepmania/src/RageTextureManager.h | 2 ++ stepmania/src/Sprite.cpp | 4 +--- stepmania/src/Sprite.h | 4 +--- 9 files changed, 39 insertions(+), 12 deletions(-) diff --git a/stepmania/src/Quad.cpp b/stepmania/src/Quad.cpp index e073cfe438..c5a001bf43 100644 --- a/stepmania/src/Quad.cpp +++ b/stepmania/src/Quad.cpp @@ -1,12 +1,15 @@ #include "global.h" #include "Quad.h" #include "ActorUtil.h" +#include "RageTextureManager.h" REGISTER_ACTOR_CLASS( Quad ) void Quad::LoadFromNode( const XNode* pNode ) { + Load( TEXTUREMAN->GetDefaultTextureID() ); + // HACK: Bypass Sprite's texture loading. Sprite should really derive from Quad. Actor::LoadFromNode( pNode ); } diff --git a/stepmania/src/Quad.h b/stepmania/src/Quad.h index 1b41b6500a..7f39f1db8f 100644 --- a/stepmania/src/Quad.h +++ b/stepmania/src/Quad.h @@ -9,11 +9,6 @@ class Quad : public Sprite { public: - Quad() - { - SetDrawIfTextureNull( true ); - } - void LoadFromNode( const XNode* pNode ); virtual Quad *Copy() const; }; diff --git a/stepmania/src/RageDisplay.h b/stepmania/src/RageDisplay.h index b094af90a1..ee51fbbfe0 100644 --- a/stepmania/src/RageDisplay.h +++ b/stepmania/src/RageDisplay.h @@ -194,6 +194,9 @@ public: RageSurface* img, // must be in pixfmt bool bGenerateMipMaps ) = 0; + /* Return a texture handle to the default texture, an opaque, all-white, + * immutable texture. Deleting or updating this texture has no effect. */ + virtual unsigned CreateTextureDefault() = 0; virtual void UpdateTexture( unsigned iTexHandle, RageSurface* img, diff --git a/stepmania/src/RageDisplay_Null.h b/stepmania/src/RageDisplay_Null.h index 267d910a7d..121e23a4b0 100644 --- a/stepmania/src/RageDisplay_Null.h +++ b/stepmania/src/RageDisplay_Null.h @@ -24,6 +24,7 @@ public: PixelFormat pixfmt, RageSurface* img, bool bGenerateMipMaps ) { return 1; } + unsigned CreateTextureDefault() { return 0; } void UpdateTexture( unsigned iTexHandle, RageSurface* img, diff --git a/stepmania/src/RageDisplay_OGL.h b/stepmania/src/RageDisplay_OGL.h index 138619b52e..6bebddde3e 100644 --- a/stepmania/src/RageDisplay_OGL.h +++ b/stepmania/src/RageDisplay_OGL.h @@ -34,6 +34,7 @@ public: PixelFormat pixfmt, RageSurface* img, bool bGenerateMipMaps ); + unsigned CreateTextureDefault() { return 0; } void UpdateTexture( unsigned iTexHandle, RageSurface* img, diff --git a/stepmania/src/RageTextureManager.cpp b/stepmania/src/RageTextureManager.cpp index 2a62e4dd4a..913e6165e8 100644 --- a/stepmania/src/RageTextureManager.cpp +++ b/stepmania/src/RageTextureManager.cpp @@ -89,6 +89,30 @@ void RageTextureManager::RegisterTexture( RageTextureID ID, RageTexture *pTextur m_mapPathToTexture[ID] = pTexture; } +static const RString g_sDefaultTextureName = "__blank__"; +RageTextureID RageTextureManager::GetDefaultTextureID() +{ + return RageTextureID( g_sDefaultTextureName ); +} + +class RageTexture_Default: public RageTexture +{ +public: + RageTexture_Default(): + RageTexture( RageTextureID() ) + { + m_uTexHandle = DISPLAY->CreateTextureDefault(); + m_iSourceWidth = m_iSourceHeight = 1; + m_iTextureWidth = m_iTextureHeight = 1; + m_iImageWidth = m_iImageHeight = 1; + CreateFrameRects(); + } + unsigned GetTexHandle() const { return m_uTexHandle; } + +private: + unsigned m_uTexHandle; +}; + // Load and unload textures from disk. RageTexture* RageTextureManager::LoadTextureInternal( RageTextureID ID ) { @@ -112,7 +136,9 @@ RageTexture* RageTextureManager::LoadTextureInternal( RageTextureID ID ) sExt.MakeLower(); RageTexture* pTexture; - if( sExt == "avi" || sExt == "mpg" || sExt == "mpeg" ) + if( ID.filename == g_sDefaultTextureName ) + pTexture = new RageTexture_Default; + else if( sExt == "avi" || sExt == "mpg" || sExt == "mpeg" ) pTexture = RageMovieTexture::Create( ID ); else pTexture = new RageBitmapTexture( ID ); diff --git a/stepmania/src/RageTextureManager.h b/stepmania/src/RageTextureManager.h index 6ef6a001c8..959495dd63 100644 --- a/stepmania/src/RageTextureManager.h +++ b/stepmania/src/RageTextureManager.h @@ -84,6 +84,8 @@ public: void EnableOddDimensionWarning() { m_iNoWarnAboutOddDimensions--; } bool GetOddDimensionWarning() const { return m_iNoWarnAboutOddDimensions == 0; } + RageTextureID GetDefaultTextureID(); + private: void DeleteTexture( RageTexture *t ); enum GCType { screen_changed, delayed_delete }; diff --git a/stepmania/src/Sprite.cpp b/stepmania/src/Sprite.cpp index 3dccaf9cdf..225d182a83 100644 --- a/stepmania/src/Sprite.cpp +++ b/stepmania/src/Sprite.cpp @@ -20,7 +20,6 @@ REGISTER_ACTOR_CLASS( Sprite ) Sprite::Sprite() { m_pTexture = NULL; - m_bDrawIfTextureNull = false; m_iCurState = 0; m_fSecsIntoState = 0.0f; m_bUsingCustomTexCoords = false; @@ -43,7 +42,6 @@ Sprite::Sprite( const Sprite &cpy ): Actor( cpy ) { #define CPY(a) a = cpy.a - CPY( m_bDrawIfTextureNull ); CPY( m_States ); CPY( m_iCurState ); CPY( m_fSecsIntoState ); @@ -557,7 +555,7 @@ void Sprite::DrawTexture( const TweenState *state ) bool Sprite::EarlyAbortDraw() const { - return m_pTexture == NULL && !m_bDrawIfTextureNull; + return m_pTexture == NULL; } void Sprite::DrawPrimitives() diff --git a/stepmania/src/Sprite.h b/stepmania/src/Sprite.h index c7344da634..20a696b811 100644 --- a/stepmania/src/Sprite.h +++ b/stepmania/src/Sprite.h @@ -67,16 +67,14 @@ public: virtual void PushSelf( lua_State *L ); protected: - void SetDrawIfTextureNull( bool b ) { m_bDrawIfTextureNull = b; } + void LoadFromTexture( RageTextureID ID ); private: - void LoadFromTexture( RageTextureID ID ); void LoadStatesFromTexture(); void DrawTexture( const TweenState *state ); RageTexture* m_pTexture; - bool m_bDrawIfTextureNull; struct State {