From 511a5e5ee5dc1e54c1f31e31a48d083a7b184d3e Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Wed, 18 Feb 2009 20:22:07 +0000 Subject: use GL_GENERATE_MIPMAP instead of gluBuild2DMipmaps, set sane glTexParameteri values --- src/render/textures.cc | 46 +++++++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 21 deletions(-) (limited to 'src/render/textures.cc') diff --git a/src/render/textures.cc b/src/render/textures.cc index a340814..8f9249a 100644 --- a/src/render/textures.cc +++ b/src/render/textures.cc @@ -170,11 +170,27 @@ size_t Textures::load(const std::string &name, const bool filter) texture_type = GL_RGBA; else texture_type = GL_RGB; + + if (filter) { + // scaling functions + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST); + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); + // 4 levels of mipmaps + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 4); + // hardware generated mipmaps (requires OpenGL 1.4) + glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); + } else { + // scaling functions + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); + // no mipmaps, base level only + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAX_LEVEL, 0); + } + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); - gluBuild2DMipmaps(GL_TEXTURE_2D, image->channels(), - image->width(), image->height(), texture_type, GL_UNSIGNED_BYTE, image->data()); - - set_filter(filter); + glTexImage2D(GL_TEXTURE_2D, 0, + image->channels(), image->width(), image->height(), 0, + texture_type, GL_UNSIGNED_BYTE, image->data()); // add to the registry registry[name] = id; @@ -206,13 +222,13 @@ size_t Textures::bind(const std::string &name, const bool filter) { size_t id = 0; iterator it = registry.find(name); - if (it != registry.end()) + if (it != registry.end()) { id = (*it).second; - else + glBindTexture(GL_TEXTURE_2D, textures[id]); + } else { id = load(name); - - glBindTexture(GL_TEXTURE_2D, textures[id]); - set_filter(filter); + } + return id; } @@ -223,19 +239,7 @@ size_t Textures::bind(const size_t texture, const bool filter) id = 0; glBindTexture(GL_TEXTURE_2D, textures[id]); - set_filter(filter); return id; } -void Textures::set_filter(const bool filter) -{ - if (filter) { - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST); - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_LINEAR); - } else { - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); - } -} - } -- cgit v1.2.3