move texture load policy into RageTextureID, so it can be set to volatile consistently

for banners/backgrounds
This commit is contained in:
Glenn Maynard
2004-03-26 10:15:18 +00:00
parent 1d92cd087f
commit d5098c84ce
9 changed files with 34 additions and 17 deletions
+2 -2
View File
@@ -320,8 +320,8 @@ void Background::LoadFromSong( const Song* pSong )
/* Song backgrounds (even just background stills) can get very big; never keep them
* in memory. */
RageTexture::TexPolicy OldPolicy = TEXTUREMAN->GetDefaultTexturePolicy();
TEXTUREMAN->SetDefaultTexturePolicy( RageTexture::TEX_VOLATILE );
RageTextureID::TexPolicy OldPolicy = TEXTUREMAN->GetDefaultTexturePolicy();
TEXTUREMAN->SetDefaultTexturePolicy( RageTextureID::TEX_VOLATILE );
TEXTUREMAN->DisableOddDimensionWarning();
+1 -1
View File
@@ -261,8 +261,8 @@ RageTextureID BannerCache::LoadCachedBanner( CString BannerPath )
ID.filename.c_str(), src_width, src_height, img->w, img->h );
RageTexture *pTexture = new BannerTexture( ID, img, src_width, src_height );
ID.Policy = RageTextureID::TEX_VOLATILE;
TEXTUREMAN->RegisterTexture( ID, pTexture );
pTexture->m_Policy = RageTexture::TEX_VOLATILE;
TEXTUREMAN->UnloadTexture( pTexture );
return ID;
-1
View File
@@ -21,7 +21,6 @@ RageTexture::RageTexture( RageTextureID name ):
// LOG->Trace( "RageTexture::RageTexture()" );
m_iRefCount = 1;
m_Policy = TEXTUREMAN->GetDefaultTexturePolicy();
m_bWasUsed = false;
// SetActualID();
+2 -1
View File
@@ -64,7 +64,8 @@ public:
int GetNumFrames() const { return m_iFramesWide*m_iFramesHigh; }
/* Used by RageTextureManager. Order is important; see RageTextureManager.cpp. */
enum TexPolicy { TEX_CACHED, TEX_VOLATILE, TEX_DEFAULT } m_Policy;
const RageTextureID::TexPolicy &GetPolicy() const { return m_ID.Policy; }
RageTextureID::TexPolicy &GetPolicy() { return m_ID.Policy; }
int m_iRefCount;
bool m_bWasUsed;
+4
View File
@@ -1,5 +1,6 @@
#include "global.h"
#include "RageTextureID.h"
#include "RageTextureManager.h"
void RageTextureID::Init()
{
@@ -12,6 +13,7 @@ void RageTextureID::Init()
iColorDepth = -1; /* default */
bHotPinkColorKey = false;
AdditionalTextureHints = "";
Policy = TEXTUREMAN->GetDefaultTexturePolicy();
}
bool RageTextureID::operator<(const RageTextureID &rhs) const
@@ -27,6 +29,7 @@ bool RageTextureID::operator<(const RageTextureID &rhs) const
COMP(bStretch);
COMP(bHotPinkColorKey);
COMP(AdditionalTextureHints);
// COMP(Policy); // don't do this
#undef COMP
return false;
}
@@ -45,5 +48,6 @@ bool RageTextureID::operator==(const RageTextureID &rhs) const
EQUAL(bStretch) &&
EQUAL(bHotPinkColorKey) &&
EQUAL(AdditionalTextureHints);
// EQUAL(Policy); // don't do this
}
+6
View File
@@ -49,6 +49,12 @@ struct RageTextureID
bool operator< (const RageTextureID &rhs) const;
bool operator== (const RageTextureID &rhs) const;
/* Used by RageTextureManager. Order is important; see RageTextureManager.cpp.
* Note that this property is not considered for ordering/equality. Loading
* a texture with a different loading policy will reuse the same texture with
* a different policy. */
enum TexPolicy { TEX_CACHED, TEX_VOLATILE, TEX_DEFAULT } Policy;
void Init();
RageTextureID() { Init(); }
+9 -9
View File
@@ -52,7 +52,7 @@ RageTextureManager* TEXTUREMAN = NULL;
RageTextureManager::RageTextureManager()
{
m_iNoWarnAboutOddDimensions = 0;
m_TexturePolicy = RageTexture::TEX_DEFAULT;
m_TexturePolicy = RageTextureID::TEX_DEFAULT;
m_bDelayedDelete = false;
m_iMovieColorDepth = 16;
m_iTextureColorDepth = 16;
@@ -156,14 +156,14 @@ RageTexture* RageTextureManager::LoadTexture( RageTextureID ID )
void RageTextureManager::CacheTexture( RageTextureID ID )
{
RageTexture* pTexture = LoadTextureInternal( ID );
pTexture->m_Policy = min( pTexture->m_Policy, RageTexture::TEX_CACHED );
pTexture->GetPolicy() = min( pTexture->GetPolicy(), RageTextureID::TEX_CACHED );
UnloadTexture( pTexture );
}
void RageTextureManager::VolatileTexture( RageTextureID ID )
{
RageTexture* pTexture = LoadTextureInternal( ID );
pTexture->m_Policy = min( pTexture->m_Policy, RageTexture::TEX_VOLATILE );
pTexture->GetPolicy() = min( pTexture->GetPolicy(), RageTextureID::TEX_VOLATILE );
UnloadTexture( pTexture );
}
@@ -187,11 +187,11 @@ void RageTextureManager::UnloadTexture( RageTexture *t )
bDeleteThis = true;
/* Delete normal textures immediately unless m_bDelayedDelete is is on. */
if( t->m_Policy == RageTexture::TEX_DEFAULT && !m_bDelayedDelete )
if( t->GetPolicy() == RageTextureID::TEX_DEFAULT && !m_bDelayedDelete )
bDeleteThis = true;
/* Delete volatile textures after they've been used at least once. */
if( t->m_Policy == RageTexture::TEX_VOLATILE && t->m_bWasUsed )
if( t->GetPolicy() == RageTextureID::TEX_VOLATILE && t->m_bWasUsed )
bDeleteThis = true;
if( bDeleteThis )
@@ -237,20 +237,20 @@ void RageTextureManager::GarbageCollect( GCType type )
bool bDeleteThis = false;
if( type==screen_changed )
{
switch( t->m_Policy )
switch( t->GetPolicy() )
{
case RageTexture::TEX_DEFAULT:
case RageTextureID::TEX_DEFAULT:
/* If m_bDelayedDelete, wait until delayed_delete. If !m_bDelayedDelete,
* it should have been deleted when it reached no references, but we
* might have just changed the preference. */
if( !m_bDelayedDelete )
bDeleteThis = true;
break;
case RageTexture::TEX_CACHED:
case RageTextureID::TEX_CACHED:
if( !m_bDelayedDelete )
bDeleteThis = true;
break;
case RageTexture::TEX_VOLATILE:
case RageTextureID::TEX_VOLATILE:
bDeleteThis = true;
break;
default: ASSERT(0);
+3 -3
View File
@@ -36,8 +36,8 @@ public:
bool GetDelayedDelete() { return m_bDelayedDelete; };
int GetMaxTextureResolution() { return m_iMaxTextureResolution; };
RageTexture::TexPolicy GetDefaultTexturePolicy() const { return m_TexturePolicy; }
void SetDefaultTexturePolicy( RageTexture::TexPolicy p ) { m_TexturePolicy = p; }
RageTextureID::TexPolicy GetDefaultTexturePolicy() const { return m_TexturePolicy; }
void SetDefaultTexturePolicy( RageTextureID::TexPolicy p ) { m_TexturePolicy = p; }
// call this between Screens
void DeleteCachedTextures() { GarbageCollect(screen_changed); }
@@ -68,7 +68,7 @@ protected:
std::map<RageTextureID, RageTexture*> m_mapPathToTexture;
int m_iNoWarnAboutOddDimensions;
RageTexture::TexPolicy m_TexturePolicy;
RageTextureID::TexPolicy m_TexturePolicy;
};
extern RageTextureManager* TEXTUREMAN; // global and accessable from anywhere in our program
+7
View File
@@ -54,6 +54,11 @@ RageTextureID Sprite::SongBGTexture( RageTextureID ID )
/* Song backgrounds are, by definition, in the background, so there's no need to keep alpha. */
ID.iAlphaBits = 0;
/* By default, song graphics are volatile: they're removed after one use. This
* is because some screens iteratively load and display lots of them (eg. ScreenSelectMusic,,
* ScreenEditMenu) one at a time, and we don't want to have hundreds of banners loaded at once. */
ID.Policy = RageTextureID::TEX_VOLATILE;
// Don't we want to dither 16 bit textures at least?
// ID.bDither = true;
@@ -65,6 +70,8 @@ RageTextureID Sprite::SongBannerTexture( RageTextureID ID )
/* Song banners often have HOT PINK color keys. */
ID.bHotPinkColorKey = true;
ID.bDither = true;
ID.Policy = RageTextureID::TEX_VOLATILE;
return ID;
}