diff --git a/stepmania/src/RageTexture.h b/stepmania/src/RageTexture.h index 369d21b168..fb44a8de76 100644 --- a/stepmania/src/RageTexture.h +++ b/stepmania/src/RageTexture.h @@ -61,6 +61,8 @@ public: int m_iRefCount; int m_iTimeOfLastUnload; + /* only called by RageTextureManager::InvalidateTextures */ + virtual void Invalidate() { } virtual unsigned int GetGLTextureID() = 0; // accessed by RageDisplay protected: diff --git a/stepmania/src/RageTextureManager.cpp b/stepmania/src/RageTextureManager.cpp index 5c415fae7f..4eca80aa22 100644 --- a/stepmania/src/RageTextureManager.cpp +++ b/stepmania/src/RageTextureManager.cpp @@ -183,10 +183,32 @@ void RageTextureManager::ReloadAll() } } -void RageTextureManager::SetPrefs( int iTextureColorDepth, int iSecondsBeforeUnload ) +/* In some cases, changing the display mode will reset the rendering context, + * releasing all textures. We don't want to reload immediately if that happens, + * since we might be changing texture preferences too, which also may have to reload + * textures. Instead, tell all textures that their texutre ID is invalid, so it + * doesn't try to free it later when we really do reload (since that ID might be + * associated with a different texture). Ack. */ +void RageTextureManager::InvalidateTextures() { + for( std::map::iterator i = m_mapPathToTexture.begin(); + i != m_mapPathToTexture.end(); ++i) + { + RageTexture* pTexture = i->second; + pTexture->Invalidate(); + } +} + +bool RageTextureManager::SetPrefs( int iTextureColorDepth, int iSecondsBeforeUnload ) +{ + bool need_reload = false; + if(m_iSecondsBeforeUnload != iSecondsBeforeUnload || + m_iTextureColorDepth != iTextureColorDepth) + need_reload = true; + m_iSecondsBeforeUnload = iSecondsBeforeUnload; m_iTextureColorDepth = iTextureColorDepth; + ASSERT( m_iTextureColorDepth==16 || m_iTextureColorDepth==32 ); - ReloadAll(); + return need_reload; } diff --git a/stepmania/src/RageTextureManager.h b/stepmania/src/RageTextureManager.h index 246002d389..1a81bc3412 100644 --- a/stepmania/src/RageTextureManager.h +++ b/stepmania/src/RageTextureManager.h @@ -27,10 +27,12 @@ public: void UnloadTexture( CString sTexturePath ); void ReloadAll(); - void SetPrefs( int iTextureColorDepth, int iSecsBeforeUnload ); + bool SetPrefs( int iTextureColorDepth, int iSecsBeforeUnload ); int GetTextureColorDepth() { return m_iTextureColorDepth; }; int GetSecsBeforeUnload() { return m_iSecondsBeforeUnload; }; + void InvalidateTextures(); + protected: void GCTextures();