X-Git-Url: https://git.jsancho.org/?a=blobdiff_plain;f=Source%2FGraphic%2FTexture.cpp;h=69ff28ed5931727020b143305554da462f5bd0c7;hb=8b6e8f3ad7390309795eb35c0959264cb7924402;hp=fe732bfd3314e9802afb354776fa57b0a948aba7;hpb=3f8ee86c6085b5d6c7ee31b916d0e022239750ab;p=lugaru.git diff --git a/Source/Graphic/Texture.cpp b/Source/Graphic/Texture.cpp index fe732bf..69ff28e 100644 --- a/Source/Graphic/Texture.cpp +++ b/Source/Graphic/Texture.cpp @@ -76,21 +76,32 @@ void TextureRes::bind() glBindTexture(GL_TEXTURE_2D, id); } -TextureRes::TextureRes(const string& _filename, bool _hasMipmap): - id(0), filename(_filename), hasMipmap(_hasMipmap), isSkin(false), - skinsize(0), data(NULL), datalen(0) +TextureRes::TextureRes(const string& _filename, bool _hasMipmap) + : id(0) + , filename(_filename) + , hasMipmap(_hasMipmap) + , isSkin(false) + , skinsize(0) + , data(NULL) + , datalen(0) { load(); } -TextureRes::TextureRes(const string& _filename, bool _hasMipmap, GLubyte* array, int* skinsizep): - id(0), filename(_filename), hasMipmap(_hasMipmap), isSkin(true), - skinsize(0), data(NULL), datalen(0) +TextureRes::TextureRes(const string& _filename, bool _hasMipmap, GLubyte* array, int* skinsizep) + : id(0) + , filename(_filename) + , hasMipmap(_hasMipmap) + , isSkin(true) + , skinsize(0) + , data(NULL) + , datalen(0) { load(); *skinsizep = skinsize; - for (int i = 0; i < datalen; i++) + for (int i = 0; i < datalen; i++) { array[i] = data[i]; + } } TextureRes::~TextureRes() @@ -101,22 +112,12 @@ TextureRes::~TextureRes() void Texture::load(const string& filename, bool hasMipmap) { - destroy(); - tex = new TextureRes(Folders::getResourcePath(filename), hasMipmap); + tex.reset(new TextureRes(Folders::getResourcePath(filename), hasMipmap)); } void Texture::load(const string& filename, bool hasMipmap, GLubyte* array, int* skinsizep) { - destroy(); - tex = new TextureRes(Folders::getResourcePath(filename), hasMipmap, array, skinsizep); -} - -void Texture::destroy() -{ - if (tex) { - delete tex; - tex = NULL; - } + tex.reset(new TextureRes(Folders::getResourcePath(filename), hasMipmap, array, skinsizep)); } void Texture::bind()