1 ////////////////////////////////////////////////////////////////////////////////
2 // Scorched3D (c) 2000-2011
3 //
4 // This file is part of Scorched3D.
5 //
6 // Scorched3D is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
10 //
11 // Scorched3D is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License along
17 // with this program; if not, write to the Free Software Foundation, Inc.,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 ////////////////////////////////////////////////////////////////////////////////
20
21 #include <GLEXT/GLTextureStore.h>
22
23 GLTextureStore *GLTextureStore::instance_ = 0;
24
instance()25 GLTextureStore *GLTextureStore::instance()
26 {
27 if (!instance_)
28 {
29 instance_ = new GLTextureStore;
30 }
31 return instance_;
32 }
33
GLTextureStore()34 GLTextureStore::GLTextureStore()
35 {
36 }
37
~GLTextureStore()38 GLTextureStore::~GLTextureStore()
39 {
40 }
41
resetModFiles()42 void GLTextureStore::resetModFiles()
43 {
44 std::map<std::string, GLTextureReferenceData *>::iterator itor;
45 for (itor = references_.begin();
46 itor != references_.end();
47 ++itor)
48 {
49 if (itor->second->getImageID().getImageLocation() == S3D::eModLocation)
50 {
51 itor->second->reset();
52 }
53 }
54 }
55
getTextureReference(const ImageID & imageId,unsigned texState)56 GLTextureReferenceData *GLTextureStore::getTextureReference(const ImageID &imageId, unsigned texState)
57 {
58 std::string hash = ((ImageID &)imageId).getStringHash() + char(texState);
59 std::map<std::string, GLTextureReferenceData *>::iterator itor = references_.find(hash);
60 if (itor != references_.end())
61 {
62 return itor->second;
63 }
64
65 GLTextureReferenceData *result = new GLTextureReferenceData(imageId, texState);
66 result->incrementReferenceCount();
67 references_[hash] = result;
68 return result;
69 }
70
removeTextureReference(GLTextureReferenceData * reference)71 void GLTextureStore::removeTextureReference(GLTextureReferenceData *reference)
72 {
73 if (reference->incrementReferenceCount() <= 0)
74 {
75 std::string hash = ((ImageID &)reference->getImageID()).getStringHash() + char(reference->getTexState());
76 references_.erase(hash);
77 delete reference;
78 }
79 }
80