00001 /* 00002 * RageTextureManager - Interface for loading and releasing textures. 00003 */ 00004 00005 #ifndef RAGE_TEXTURE_MANAGER_H 00006 #define RAGE_TEXTURE_MANAGER_H 00007 00008 #include "RageTexture.h" 00009 00010 #include <map> 00011 00012 struct RageTextureManagerPrefs 00013 { 00014 int m_iTextureColorDepth; 00015 int m_iMovieColorDepth; 00016 bool m_bDelayedDelete; 00017 int m_iMaxTextureResolution; 00018 bool m_bMipMaps; 00019 00020 RageTextureManagerPrefs() 00021 { 00022 m_bDelayedDelete = false; 00023 m_iMovieColorDepth = 16; 00024 m_iTextureColorDepth = 16; 00025 m_iMaxTextureResolution = 1024; 00026 m_bMipMaps = false; 00027 } 00028 RageTextureManagerPrefs( 00029 int iTextureColorDepth, 00030 int iMovieColorDepth, 00031 bool bDelayedDelete, 00032 int iMaxTextureResolution, 00033 bool bMipMaps ) 00034 { 00035 m_bDelayedDelete = bDelayedDelete; 00036 m_iMovieColorDepth = iMovieColorDepth; 00037 m_iTextureColorDepth = iTextureColorDepth; 00038 m_iMaxTextureResolution = iMaxTextureResolution; 00039 m_bMipMaps = bMipMaps; 00040 } 00041 00042 bool operator!=( const RageTextureManagerPrefs& rhs ) 00043 { 00044 return 00045 m_iTextureColorDepth != rhs.m_iTextureColorDepth || 00046 m_iMovieColorDepth != rhs.m_iMovieColorDepth || 00047 m_bDelayedDelete != rhs.m_bDelayedDelete || 00048 m_iMaxTextureResolution != rhs.m_iMaxTextureResolution || 00049 m_bMipMaps != rhs.m_bMipMaps; 00050 } 00051 }; 00052 00053 class RageTextureManager 00054 { 00055 public: 00056 RageTextureManager(); 00057 void Update( float fDeltaTime ); 00058 ~RageTextureManager(); 00059 00060 RageTexture* LoadTexture( RageTextureID ID ); 00061 bool IsTextureRegistered( RageTextureID ID ) const; 00062 void RegisterTexture( RageTextureID ID, RageTexture *p ); 00063 void CacheTexture( RageTextureID ID ); 00064 void VolatileTexture( RageTextureID ID ); 00065 void PermanentTexture( RageTextureID ID ); 00066 void UnloadTexture( RageTexture *t ); 00067 void ReloadAll(); 00068 00069 bool SetPrefs( RageTextureManagerPrefs prefs ); 00070 RageTextureManagerPrefs GetPrefs() { return m_Prefs; }; 00071 00072 RageTextureID::TexPolicy GetDefaultTexturePolicy() const { return m_TexturePolicy; } 00073 void SetDefaultTexturePolicy( RageTextureID::TexPolicy p ) { m_TexturePolicy = p; } 00074 00075 // call this between Screens 00076 void DeleteCachedTextures() { GarbageCollect(screen_changed); } 00077 00078 // call this on switch theme 00079 void DoDelayedDelete() { GarbageCollect(delayed_delete); } 00080 00081 void InvalidateTextures(); 00082 00083 void AdjustTextureID(RageTextureID &ID) const; 00084 void DiagnosticOutput() const; 00085 00086 void DisableOddDimensionWarning() { m_iNoWarnAboutOddDimensions++; } 00087 void EnableOddDimensionWarning() { m_iNoWarnAboutOddDimensions--; } 00088 bool GetOddDimensionWarning() const { return m_iNoWarnAboutOddDimensions == 0; } 00089 00090 protected: 00091 void DeleteTexture( RageTexture *t ); 00092 enum GCType { screen_changed, delayed_delete }; 00093 void GarbageCollect( GCType type ); 00094 00095 RageTextureManagerPrefs m_Prefs; 00096 00097 RageTexture* LoadTextureInternal( RageTextureID ID ); 00098 00099 std::map<RageTextureID, RageTexture*> m_mapPathToTexture; 00100 int m_iNoWarnAboutOddDimensions; 00101 RageTextureID::TexPolicy m_TexturePolicy; 00102 }; 00103 00104 extern RageTextureManager* TEXTUREMAN; // global and accessable from anywhere in our program 00105 00106 #endif 00107 00108 /* 00109 * Copyright (c) 2001-2004 Chris Danford, Glenn Maynard 00110 * All rights reserved. 00111 * 00112 * Permission is hereby granted, free of charge, to any person obtaining a 00113 * copy of this software and associated documentation files (the 00114 * "Software"), to deal in the Software without restriction, including 00115 * without limitation the rights to use, copy, modify, merge, publish, 00116 * distribute, and/or sell copies of the Software, and to permit persons to 00117 * whom the Software is furnished to do so, provided that the above 00118 * copyright notice(s) and this permission notice appear in all copies of 00119 * the Software and that both the above copyright notice(s) and this 00120 * permission notice appear in supporting documentation. 00121 * 00122 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 00123 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00124 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF 00125 * THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS 00126 * INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT 00127 * OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS 00128 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR 00129 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 00130 * PERFORMANCE OF THIS SOFTWARE. 00131 */