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-03-21 09:58:26 +0000
committerStijn Buys <ingar@osirion.org>2009-03-21 09:58:26 +0000
commit27e026234be657e7a0f939405914784633a2e1f3 (patch)
tree14911521510b739ee5e465e9612d305325e8bc1f /src/render/textures.cc
parent0cae375e9f299e3541ecef99a1728dcf23cb3b76 (diff)
autodetect hardware generated mipmap support
Diffstat (limited to 'src/render/textures.cc')
-rw-r--r--src/render/textures.cc42
1 files changed, 29 insertions, 13 deletions
diff --git a/src/render/textures.cc b/src/render/textures.cc
index 8f9249a..f5a5c62 100644
--- a/src/render/textures.cc
+++ b/src/render/textures.cc
@@ -12,6 +12,7 @@
#include "render/tgafile.h"
#include "render/pngfile.h"
#include "render/jpgfile.h"
+#include "render/state.h"
#include "sys/sys.h"
#include "core/application.h"
@@ -165,20 +166,20 @@ size_t Textures::load(const std::string &name, const bool filter)
glGenTextures(1, &textures[id]);
glBindTexture(GL_TEXTURE_2D, textures[id]);
- int texture_type;
- if (image->channels() == 4)
- texture_type = GL_RGBA;
- else
- texture_type = GL_RGB;
-
+ int texture_format;
+ int texture_internalformat;
+
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);
+
+ if (State::has_generate_mipmaps()) {
+ // 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);
@@ -186,11 +187,26 @@ size_t Textures::load(const std::string &name, const bool filter)
// no mipmaps, base level only
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAX_LEVEL, 0);
}
- glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
+ //glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
+
+ if (image->channels() == 4) {
+ texture_format = GL_RGBA;
+ texture_internalformat = GL_RGBA8;
+ } else {
+ texture_format = GL_RGB;
+ texture_internalformat = GL_RGB8;
+ }
+
+ if (filter && !State::has_generate_mipmaps()) {
+ gluBuild2DMipmaps(GL_TEXTURE_2D,
+ texture_internalformat, image->width(), image->height(),
+ texture_format, GL_UNSIGNED_BYTE, image->data());
+ } else {
- glTexImage2D(GL_TEXTURE_2D, 0,
- image->channels(), image->width(), image->height(), 0,
- texture_type, GL_UNSIGNED_BYTE, image->data());
+ glTexImage2D(GL_TEXTURE_2D, 0,
+ texture_internalformat, image->width(), image->height(), 0,
+ texture_format, GL_UNSIGNED_BYTE, image->data());
+ }
// add to the registry
registry[name] = id;
@@ -226,7 +242,7 @@ size_t Textures::bind(const std::string &name, const bool filter)
id = (*it).second;
glBindTexture(GL_TEXTURE_2D, textures[id]);
} else {
- id = load(name);
+ id = load(name, filter);
}
return id;