X-Git-Url: https://git.jsancho.org/?a=blobdiff_plain;ds=inline;f=Source%2FGraphic%2FTexture.cpp;h=94e4e09c3185bcd2ea01e6c3120e6f2679fc1217;hb=6a8cb464330e92163c8feaf101b8b5837c973bba;hp=3f5211ac20cc0bebe35950808a0c007d37d3bc4a;hpb=b84825978803615f45a9f128232e62431042aec0;p=lugaru.git
diff --git a/Source/Graphic/Texture.cpp b/Source/Graphic/Texture.cpp
index 3f5211a..94e4e09 100644
--- a/Source/Graphic/Texture.cpp
+++ b/Source/Graphic/Texture.cpp
@@ -1,6 +1,6 @@
/*
Copyright (C) 2003, 2010 - Wolfire Games
-Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file)
+Copyright (C) 2010-2017 - Lugaru contributors (see AUTHORS file)
This file is part of Lugaru.
@@ -18,17 +18,15 @@ You should have received a copy of the GNU General Public License
along with Lugaru. If not, see .
*/
-#include "Graphic/gamegl.h"
-#include "Graphic/Texture.h"
-#include "Utils/Folders.h"
-#include "Utils/ImageIO.h"
+#include "Graphic/Texture.hpp"
+
+#include "Utils/Folders.hpp"
+#include "Utils/ImageIO.hpp"
using namespace std;
extern bool trilinear;
-vector TextureRes::list;
-
void TextureRes::load()
{
ImageRec texture;
@@ -41,8 +39,9 @@ void TextureRes::load()
skinsize = texture.sizeX;
GLuint type = GL_RGBA;
- if (texture.bpp == 24)
+ if (texture.bpp == 24) {
type = GL_RGB;
+ }
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
@@ -64,9 +63,11 @@ void TextureRes::load()
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)
+ 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);
@@ -78,60 +79,55 @@ 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();
- list.push_back(this);
}
-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];
- list.push_back(this);
+ }
}
TextureRes::~TextureRes()
{
free(data);
glDeleteTextures(1, &id);
- for (vector::iterator it = list.begin(); it != list.end(); it++)
- if (*it == this) {
- list.erase(it);
- break;
- }
}
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()
{
- if (tex)
+ if (tex) {
tex->bind();
- else
+ } else {
glBindTexture(GL_TEXTURE_2D, 0);
+ }
}