From: Côme Chilliet Date: Sat, 26 Nov 2016 08:20:49 +0000 (+0800) Subject: Started to clean Texture/TextureRes by removing unused skindata and reloadAll methods X-Git-Url: https://git.jsancho.org/?a=commitdiff_plain;h=cedb9cffef6e30a2c04239c60027029da48b3897;p=lugaru.git Started to clean Texture/TextureRes by removing unused skindata and reloadAll methods --- diff --git a/Source/Texture.cpp b/Source/Texture.cpp index e8bcaa9..adbef9f 100644 --- a/Source/Texture.cpp +++ b/Source/Texture.cpp @@ -27,42 +27,12 @@ using namespace std; extern ImageRec texture; extern bool trilinear; - -class TextureRes -{ -private: - static vector list; - - GLuint id; - string filename; - bool hasMipmap; - bool hasAlpha; - bool isSkin; - int skinsize; - GLubyte* data; - int datalen; - GLubyte* skindata; - - void load(); - -public: - TextureRes(const string& filename, bool hasMipmap, bool hasAlpha); - TextureRes(const string& filename, bool hasMipmap, GLubyte* array, int* skinsize); - ~TextureRes(); - void bind(); - - static void reloadAll(); -}; - - vector TextureRes::list; void TextureRes::load() { //load image into 'texture' global var - if (!skindata) { - upload_image(ConvertFileName(filename.c_str())); - } + upload_image(ConvertFileName(filename.c_str())); skinsize = texture.sizeX; GLuint type = GL_RGBA; @@ -85,18 +55,14 @@ void TextureRes::load() } if (isSkin) { - if (skindata) { - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, skinsize, skinsize, 0, GL_RGB, GL_UNSIGNED_BYTE, skindata); - } else { - 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 < nb; i++) - if ((i + 1) % 4 || type == GL_RGB) - data[datalen++] = texture.data[i]; - glTexImage2D(GL_TEXTURE_2D, 0, type, texture.sizeX, texture.sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, data); - } + 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 < nb; i++) + if ((i + 1) % 4 || type == GL_RGB) + data[datalen++] = texture.data[i]; + glTexImage2D(GL_TEXTURE_2D, 0, type, texture.sizeX, texture.sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, data); } else { glTexImage2D(GL_TEXTURE_2D, 0, type, texture.sizeX, texture.sizeY, 0, type, GL_UNSIGNED_BYTE, texture.data); } @@ -109,7 +75,7 @@ void TextureRes::bind() TextureRes::TextureRes(const string& _filename, bool _hasMipmap, bool _hasAlpha): id(0), filename(_filename), hasMipmap(_hasMipmap), hasAlpha(_hasAlpha), isSkin(false), - skinsize(0), data(NULL), datalen(0), skindata(NULL) + skinsize(0), data(NULL), datalen(0) { load(); list.push_back(this); @@ -117,13 +83,12 @@ TextureRes::TextureRes(const string& _filename, bool _hasMipmap, bool _hasAlpha) TextureRes::TextureRes(const string& _filename, bool _hasMipmap, GLubyte* array, int* skinsizep): id(0), filename(_filename), hasMipmap(_hasMipmap), hasAlpha(false), isSkin(true), - skinsize(0), data(NULL), datalen(0), skindata(NULL) + skinsize(0), data(NULL), datalen(0) { load(); *skinsizep = skinsize; for (int i = 0; i < datalen; i++) array[i] = data[i]; - skindata = array; list.push_back(this); } @@ -138,15 +103,6 @@ TextureRes::~TextureRes() } } -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) { destroy(); @@ -174,9 +130,3 @@ void Texture::bind() else glBindTexture(GL_TEXTURE_2D, 0); } - -void Texture::reloadAll() -{ - TextureRes::reloadAll(); -} - diff --git a/Source/Texture.h b/Source/Texture.h index e9642b9..111712c 100644 --- a/Source/Texture.h +++ b/Source/Texture.h @@ -26,7 +26,28 @@ along with Lugaru. If not, see . #include using namespace std; -class TextureRes; +class TextureRes +{ +private: + static vector list; + + GLuint id; + string filename; + bool hasMipmap; + bool hasAlpha; + bool isSkin; + int skinsize; + GLubyte* data; + int datalen; + + void load(); + +public: + TextureRes(const string& filename, bool hasMipmap, bool hasAlpha); + TextureRes(const string& filename, bool hasMipmap, GLubyte* array, int* skinsize); + ~TextureRes(); + void bind(); +}; class Texture { @@ -38,8 +59,6 @@ public: void load(const string& filename, bool hasMipmap, GLubyte* array, int* skinsizep); void destroy(); void bind(); - - static void reloadAll(); }; #endif