00001
#include "texture_manager.h"
00002
00003
CTextureManager* CTextureManager::m_pInstance = 0;
00004
00005 CTextureManager::CTextureManager ()
00006 {
00007
00008 }
00009
00010 CTextureManager::~CTextureManager ()
00011 {
00012
for (std::map<std::string, CTexture*>::iterator it = m_Textures.begin (); it != m_Textures.end (); it++)
00013
delete it->second;
00014 }
00015
00016 CTextureManager*
CTextureManager::Instance ()
00017 {
00018
if (m_pInstance == 0)
00019 m_pInstance =
new CTextureManager;
00020
return m_pInstance;
00021 }
00022
00023 void CTextureManager::Kill ()
00024 {
00025
if (m_pInstance != 0)
00026 {
00027
delete m_pInstance;
00028 m_pInstance = 0;
00029 }
00030 }
00031
00032 CTexture2D*
CTextureManager::Texture2D (
const char* szFilename)
00033 {
00034
CTexture2D *pTexture = 0;
00035
00036 std::map<std::string, CTexture*>::iterator ItTexture = m_Textures.find (szFilename);
00037
if (ItTexture != m_Textures.end ())
00038 {
00039
if (ItTexture->second->Type () ==
TEXTURE_TYPE_TEXTURE_2D)
00040 {
00041 pTexture = static_cast<CTexture2D*>(ItTexture->second);
00042 std::map <std::string, unsigned int>::iterator ItNumber = m_Number.find (szFilename);
00043 ItNumber->second++;
00044 }
00045
else
00046 {
00047 pTexture = 0;
00048 }
00049 }
00050
else
00051 {
00052 pTexture =
new CTexture2D (szFilename);
00053 m_Textures.insert (std::pair<std::string, CTexture*>(szFilename, pTexture));
00054 m_Number.insert (std::pair<std::string, unsigned int>(szFilename, 1));
00055 }
00056
00057
return pTexture;
00058 }
00059
00060 CMipmaps2D*
CTextureManager::Mipmaps2D (
const char* szMipmap1,
const char* szMipmap2,
const char* szMipmap3,
const char* szMipmap4,
const char* szMipmap5)
00061 {
00062
CMipmaps2D *pTexture = 0;
00063
00064 std::map<std::string, CTexture*>::iterator ItTexture = m_Textures.find (szMipmap1);
00065
if (ItTexture != m_Textures.end ())
00066 {
00067 std::map <std::string, unsigned int>::iterator ItNumber = m_Number.find (szMipmap1);
00068
if (ItTexture->second->Type () ==
TEXTURE_TYPE_MIPMAPS_2D)
00069 {
00070 pTexture = static_cast<CMipmaps2D*>(ItTexture->second);
00071 ItNumber->second++;
00072 }
00073
else
00074 {
00075 pTexture = 0;
00076 }
00077 }
00078
else
00079 {
00080 pTexture =
new CMipmaps2D (szMipmap1, szMipmap2, szMipmap3, szMipmap4, szMipmap5);
00081 m_Textures.insert (std::pair<std::string, CTexture*>(szMipmap1, pTexture));
00082 m_Number.insert (std::pair<std::string, unsigned int>(szMipmap1, 1));
00083 }
00084
00085
return pTexture;
00086 }
00087
00088 bool CTextureManager::Delete (
CTexture* pTexture)
00089 {
00090
if (!pTexture)
00091
return false;
00092
00093 std::map<std::string, CTexture*>::iterator ItTexture = m_Textures.find (pTexture->
GetFilename ());
00094 std::map <std::string, unsigned int>::iterator ItNumber = m_Number.find (pTexture->
GetFilename ());
00095
00096 ItNumber->second--;
00097
if (ItNumber->second <= 0)
00098 {
00099
delete ItTexture->second;
00100 m_Textures.erase (ItTexture);
00101 m_Number.erase (ItNumber);
00102 }
00103
00104
return true;
00105 }