diff options
author | Stijn Buys <ingar@osirion.org> | 2008-09-27 17:16:15 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2008-09-27 17:16:15 +0000 |
commit | ca0c1d3e6f8b5fa4eb2e0a86fcf47b12fb600786 (patch) | |
tree | 5d72e330f11350065806e83cc8712693241b9aad /src/render/textures.cc | |
parent | 29984680d6e0e52efec489497b1796e056164442 (diff) |
mission targets, texture unloading, private messages
Diffstat (limited to 'src/render/textures.cc')
-rw-r--r-- | src/render/textures.cc | 67 |
1 files changed, 57 insertions, 10 deletions
diff --git a/src/render/textures.cc b/src/render/textures.cc index a041c32..b6b7f05 100644 --- a/src/render/textures.cc +++ b/src/render/textures.cc @@ -19,14 +19,18 @@ namespace render { std::map<std::string, size_t> Textures::registry; -size_t Textures::index = 0; GLuint Textures::textures[MAXTEXTURES]; void Textures::init() { - clear(); con_print << "^BLoading textures..." << std::endl; + if (registry.size()) { + clear(); + } else { + memset(textures,0, sizeof(textures)); + } + // "no texture" bitmap load("textures/common/notex"); @@ -51,14 +55,54 @@ void Textures::shutdown() clear(); } +void Textures::list() +{ + for (iterator it = registry.begin(); it != registry.end(); it++) { + con_print << " " << (*it).first << " " << (*it).second << std::endl; + } + con_print << registry.size() << " loaded textures" << std::endl; +} + void Textures::clear() { - if (index) - glDeleteTextures(index, textures); + for (size_t i=0; i < MAXTEXTURES; i++) { + if (textures[i]) { + glDeleteTextures(1, &textures[i]); + } + } registry.clear(); memset(textures,0, sizeof(textures)); - index = 0; +} + +void Textures::unload(std::string name) +{ + iterator it = registry.find(name); + if (it != registry.end()) { + con_debug << " unloading " << (*it).first << std::endl; + size_t id = (*it).second; + if (textures[id]) { + glDeleteTextures(1, &textures[id]); + } + registry.erase(it); + + } +} + +void Textures::unload(size_t id) +{ + // find in map + for (iterator it = registry.begin(); it != registry.end(); it++) { + if ((*it).second == id) { + con_debug << " unloading " << (*it).first << std::endl; + size_t id = (*it).second; + if (textures[id]) { + glDeleteTextures(1, &textures[id]); + } + registry.erase(it); + break; + } + } } size_t Textures::load(std::string name, bool filter) @@ -68,7 +112,12 @@ size_t Textures::load(std::string name, bool filter) if (it != registry.end()) return (*it).second; - if (index == MAXTEXTURES) { + // find first available texture + size_t id = 0; + while ((id < MAXTEXTURES) && (textures[id])) { + id++; + } + if (id == MAXTEXTURES) { con_error << "Texture limit " << MAXTEXTURES << " exceeded!" << std::endl; registry[name] = 0; return 0; @@ -105,8 +154,6 @@ size_t Textures::load(std::string name, bool filter) return 0; } - size_t id = index; - glGenTextures(1, &textures[id]); glBindTexture(GL_TEXTURE_2D, textures[id]); @@ -123,7 +170,6 @@ size_t Textures::load(std::string name, bool filter) // add to the registry registry[name] = id; - index++; // delete image data delete image; @@ -157,7 +203,7 @@ size_t Textures::bind(std::string name, bool filter) size_t Textures::bind(size_t texture, bool filter) { size_t id = texture; - if (texture >= index) + if (!textures[id]) id = 0; glBindTexture(GL_TEXTURE_2D, textures[id]); @@ -175,4 +221,5 @@ void Textures::set_filter(bool filter) glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); } } + } |