home *** CD-ROM | disk | FTP | other *** search
- #include "TextureHandler.h"
-
- #include "Tokenizer.h"
- #include "log.h"
-
- // init of static members
- std::vector<textureRefCounterPair_t> TextureHandler::textures;
-
- Texture* TextureHandler::getTexture(const char* filename){
-
- std::vector<textureRefCounterPair_t>::iterator i;
- for(i=textures.begin();i<textures.end();i++){
- if(i->first->filename!=NULL && streq(filename, i->first->filename)){
- i->second++;
- return i->first;
- }
- }
-
- return loadTexture(filename);
- }
-
- int TextureHandler::getNumTextures(){
- return textures.size();
- }
-
- Texture* TextureHandler::loadTexture(const char* filename){
- Texture* t = new Texture(filename);
-
- textureRefCounterPair_t p(t, 1);
- textures.push_back(p);
-
- return t;
- }
-
- void TextureHandler::releaseTexture(Texture* tex){
- if(tex==NULL)
- return;
-
- std::vector<textureRefCounterPair_t>::iterator i;
- for(i=textures.begin();i<textures.end();i++){
- if(i->first==tex){
- i->second--;
- if(i->second==0){
- // if(i->first->filename!=NULL)
- // log("TextureHandler::releaseTexture(): Texture '%s' not referenced any more (I'll delete it).\n", i->first->filename);
- delete i->first;
- textures.erase(i);
- }
- }
- }
- }
-
- void TextureHandler::reloadTextures(){
- log("reloading textures...\n");
-
- std::vector<textureRefCounterPair_t>::iterator i;
- for(i=textures.begin();i<textures.end();i++){
- if(i->first->filename!=NULL){
- i->first->reload();
- }
- }
-
- }
-