00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <graph/TextureStore.h>
00022 #include <graph/OptionsDisplay.h>
00023 #include <image/ImageFactory.h>
00024 #include <GLEXT/GLTexture.h>
00025 #include <common/Defines.h>
00026
00027 TextureStore *TextureStore::instance_ = 0;
00028
00029 TextureStore *TextureStore::instance()
00030 {
00031 if (!instance_)
00032 {
00033 instance_ = new TextureStore;
00034 }
00035 return instance_;
00036 }
00037
00038 TextureStore::TextureStore()
00039 {
00040 }
00041
00042 TextureStore::~TextureStore()
00043 {
00044 }
00045
00046 GLTexture *TextureStore::loadTexture(const std::string &name,
00047 const std::string &aname,
00048 bool invert)
00049 {
00050 std::string wholeName;
00051 wholeName += name;
00052 wholeName += "::";
00053 wholeName += aname;
00054
00055
00056 std::map<std::string, GLTexture *>::iterator itor =
00057 skins_.find(wholeName);
00058 if (itor != skins_.end())
00059 {
00060 return (*itor).second;
00061 }
00062
00063
00064 Image *map = 0;
00065 if (aname[0])
00066 {
00067 map = ImageFactory::loadImage(name, aname, invert);
00068 if (!map->getBits())
00069 {
00070 S3D::dialogMessage("Scorched3D load texture", S3D::formatStringBuffer(
00071 "Failed to load texture file \"%s\",\n"
00072 "alpha file \"%s\"",
00073 name.c_str(),
00074 aname.c_str()));
00075 return 0;
00076 }
00077 }
00078 else
00079 {
00080 map = ImageFactory::loadImage(name);
00081 if (!map->getBits())
00082 {
00083 S3D::dialogMessage("Scorched3D load texture", S3D::formatStringBuffer(
00084 "Failed to load texture file \"%s\"",
00085 name.c_str()));
00086 return 0;
00087 }
00088 }
00089
00090
00091 #ifdef dDOUBLE
00092
00093
00094 if (OptionsDisplay::instance()->getTexSize() == 0)
00095 {
00096 map->resize(map->getWidth() / 2,
00097 map->getHeight() / 2);
00098 }
00099 #endif
00100
00101
00102 GLTexture *texture = new GLTexture;
00103 if (!texture->create(*map))
00104 {
00105 delete map;
00106 S3D::dialogMessage("Scorched3D create texture", S3D::formatStringBuffer(
00107 "Failed to create texture \"%s\"",
00108 name.c_str()));
00109 return 0;
00110 }
00111 delete map;
00112
00113 skins_[wholeName] = texture;
00114 return texture;
00115 }
00116