X-Git-Url: https://git.jsancho.org/?a=blobdiff_plain;f=Source%2FTexture.cpp;h=fc5c06be6d626f8775cece3384aa289cd75d7fce;hb=25e3d5e35a7fd7efdffc420efe3c41a91cefe43f;hp=5c8834d70be6e83ec69a6b6fa5b3bf5cf078293c;hpb=35b5d8a643d2ff04614a8b9f57026b57d4a82667;p=lugaru.git diff --git a/Source/Texture.cpp b/Source/Texture.cpp index 5c8834d..fc5c06b 100644 --- a/Source/Texture.cpp +++ b/Source/Texture.cpp @@ -8,7 +8,8 @@ extern TGAImageRec texture; extern bool trilinear; -class TextureRes { +class TextureRes +{ private: static vector list; @@ -20,6 +21,7 @@ private: int skinsize; GLubyte* data; int datalen; + GLubyte* skindata; void load(); @@ -35,110 +37,130 @@ public: vector TextureRes::list; -void TextureRes::load(){ +void TextureRes::load() +{ //load image into 'texture' global var - unsigned char filenamep[256]; - CopyCStringToPascal(ConvertFileName(filename.c_str()),filenamep); - upload_image(filenamep,hasAlpha); - - skinsize=texture.sizeX; - GLuint type=GL_RGBA; - if(texture.bpp==24) - type=GL_RGB; - - glPixelStorei(GL_UNPACK_ALIGNMENT,1); - - glDeleteTextures(1,&id); - glGenTextures(1,&id); - glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE); - - glBindTexture(GL_TEXTURE_2D, id); - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); - if(hasMipmap){ - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,(trilinear?GL_LINEAR_MIPMAP_LINEAR:GL_LINEAR_MIPMAP_NEAREST)); - glTexParameteri(GL_TEXTURE_2D,GL_GENERATE_MIPMAP,GL_TRUE); - }else{ - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); + if (!skindata) { + unsigned char filenamep[256]; + CopyCStringToPascal(ConvertFileName(filename.c_str()), filenamep); + upload_image(filenamep, hasAlpha); } - - if(isSkin){ - free(data); - const int nb=texture.sizeY*texture.sizeX*(texture.bpp/8); - data=(GLubyte*)malloc(nb*sizeof(GLubyte)); - datalen=0; - for(int i=0;i::iterator it=list.begin();it!=list.end();it++) - if(*it==this){ + glDeleteTextures(1, &id); + for (vector::iterator it = list.begin(); it != list.end(); it++) + if (*it == this) { list.erase(it); break; } } -void TextureRes::reloadAll(){ - for(vector::iterator it=list.begin();it!=list.end();it++) +void TextureRes::reloadAll() +{ + for (vector::iterator it = list.begin(); it != list.end(); it++) { + (*it)->id = 0; (*it)->load(); + } } -void Texture::load(const string& filename, bool hasMipmap, bool hasAlpha){ +void Texture::load(const string& filename, bool hasMipmap, bool hasAlpha) +{ destroy(); - tex=new TextureRes(filename,hasMipmap,hasAlpha); + tex = new TextureRes(filename, hasMipmap, hasAlpha); } -void Texture::load(const string& filename, bool hasMipmap, GLubyte* array, int* skinsizep){ +void Texture::load(const string& filename, bool hasMipmap, GLubyte* array, int* skinsizep) +{ destroy(); - tex=new TextureRes(filename,hasMipmap,array,skinsizep); + tex = new TextureRes(filename, hasMipmap, array, skinsizep); } -void Texture::destroy(){ - if(tex){ +void Texture::destroy() +{ + if (tex) { delete tex; - tex=NULL; + tex = NULL; } } -void Texture::bind(){ - if(tex) +void Texture::bind() +{ + if (tex) tex->bind(); else - glBindTexture(GL_TEXTURE_2D,0); + glBindTexture(GL_TEXTURE_2D, 0); } -void Texture::reloadAll(){ +void Texture::reloadAll() +{ TextureRes::reloadAll(); }