X-Git-Url: https://git.jsancho.org/?a=blobdiff_plain;f=Source%2FTexture.cpp;h=dd2d1cc63ff0e0b7760bcfa4bb7324c3ba8a35b0;hb=cc92cb7b7f9b87cb791c504bf930d622d74db368;hp=fc5c06be6d626f8775cece3384aa289cd75d7fce;hpb=24004d6ab1e68faaf85ece11b566449997da5013;p=lugaru.git diff --git a/Source/Texture.cpp b/Source/Texture.cpp index fc5c06b..dd2d1cc 100644 --- a/Source/Texture.cpp +++ b/Source/Texture.cpp @@ -1,50 +1,39 @@ -#include "gamegl.h" -#include "Texture.h" -#include "TGALoader.h" +/* +Copyright (C) 2003, 2010 - Wolfire Games +Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file) -using namespace std; +This file is part of Lugaru. -extern TGAImageRec texture; -extern bool trilinear; - - -class TextureRes -{ -private: - static vector list; +Lugaru is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. - GLuint id; - string filename; - bool hasMipmap; - bool hasAlpha; - bool isSkin; - int skinsize; - GLubyte* data; - int datalen; - GLubyte* skindata; +Lugaru is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. - void load(); +You should have received a copy of the GNU General Public License +along with Lugaru. If not, see . +*/ -public: - TextureRes(const string& filename, bool hasMipmap, bool hasAlpha); - TextureRes(const string& filename, bool hasMipmap, GLubyte* array, int* skinsize); - ~TextureRes(); - void bind(); +#include "gamegl.h" +#include "Texture.h" +#include "ImageIO.h" - static void reloadAll(); -}; +using namespace std; +extern bool trilinear; vector TextureRes::list; void TextureRes::load() { - //load image into 'texture' global var - if (!skindata) { - unsigned char filenamep[256]; - CopyCStringToPascal(ConvertFileName(filename.c_str()), filenamep); - upload_image(filenamep, hasAlpha); - } + ImageRec texture; + + //load image into 'texture' + load_image(ConvertFileName(filename.c_str()), texture); skinsize = texture.sizeX; GLuint type = GL_RGBA; @@ -67,18 +56,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); } @@ -89,23 +74,22 @@ void TextureRes::bind() glBindTexture(GL_TEXTURE_2D, id); } -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) +TextureRes::TextureRes(const string& _filename, bool _hasMipmap): + id(0), filename(_filename), hasMipmap(_hasMipmap), isSkin(false), + skinsize(0), data(NULL), datalen(0) { load(); list.push_back(this); } 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) + id(0), filename(_filename), hasMipmap(_hasMipmap), isSkin(true), + 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); } @@ -120,21 +104,10 @@ 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) +void Texture::load(const string& filename, bool hasMipmap) { destroy(); - tex = new TextureRes(filename, hasMipmap, hasAlpha); + tex = new TextureRes(filename, hasMipmap); } void Texture::load(const string& filename, bool hasMipmap, GLubyte* array, int* skinsizep) @@ -158,9 +131,3 @@ void Texture::bind() else glBindTexture(GL_TEXTURE_2D, 0); } - -void Texture::reloadAll() -{ - TextureRes::reloadAll(); -} -