Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2009-02-18 20:22:07 +0000
committerStijn Buys <ingar@osirion.org>2009-02-18 20:22:07 +0000
commit511a5e5ee5dc1e54c1f31e31a48d083a7b184d3e (patch)
treef699b6e213fa371f5c2f1bf1556570a1270cc563 /src/render/textures.cc
parent4baca0eb3d71710cd598ffcb356ff302b9814c7c (diff)
use GL_GENERATE_MIPMAP instead of gluBuild2DMipmaps,
set sane glTexParameteri values
Diffstat (limited to 'src/render/textures.cc')
-rw-r--r--src/render/textures.cc46
1 files changed, 25 insertions, 21 deletions
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);
- }
-}
-
}