Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/render/gl.h2
-rw-r--r--src/render/render.cc4
-rw-r--r--src/render/state.cc33
-rw-r--r--src/render/state.h2
-rw-r--r--src/render/textures.cc42
5 files changed, 67 insertions, 16 deletions
diff --git a/src/render/gl.h b/src/render/gl.h
index 83241f9..e182117 100644
--- a/src/render/gl.h
+++ b/src/render/gl.h
@@ -11,8 +11,10 @@
#ifdef _OSX
#include "OpenGL/gl.h"
+#include "OpenGL/glu.h"
#else
#include "GL/gl.h"
+#include "GL/glu.h"
#endif
#include "math/vector2f.h"
diff --git a/src/render/render.cc b/src/render/render.cc
index 0c7b35d..9f364cb 100644
--- a/src/render/render.cc
+++ b/src/render/render.cc
@@ -62,6 +62,10 @@ void init(int width, int height)
// initialize render state
State::init(width, height);
+ if (!State::has_generate_mipmaps()) {
+ con_print << " no hardware generated mipmap support" << std::endl;
+ }
+
Camera::init();
Textures::init();
diff --git a/src/render/state.cc b/src/render/state.cc
index 649493e..cc402ff 100644
--- a/src/render/state.cc
+++ b/src/render/state.cc
@@ -4,19 +4,46 @@
the terms of the GNU General Public License version 2
*/
+#include <string>
+#include <sstream>
+
#include "render/state.h"
#include "render/gl.h"
#include "render/render.h"
namespace render {
-int State::render_width;
-int State::render_height;
-float State::render_aspect;
+int State::render_width = 0;
+int State::render_height = 0;
+float State::render_aspect = 0;
+bool State::render_has_generate_mipmaps = 0;
void State::init(int width, int height)
{
resize(width, height);
+
+ render_has_generate_mipmaps = false;
+
+ std::string version(gl::version());
+ for (size_t i =0; i < version.size(); i++) {
+ if (version[i] == '.')
+ version[i] = ' ';
+ }
+
+ std::stringstream versionstream(version);
+ int major, minor;
+ if (versionstream >> major >> minor) {
+
+ if (major > 1) {
+ render_has_generate_mipmaps = true;
+ } else if (major == 1) {
+ if (minor >3)
+ render_has_generate_mipmaps = true;
+ }
+
+ } else {
+ con_warn << "Could not determine OpenGL version!" << std::endl;
+ }
}
void State::shutdown()
diff --git a/src/render/state.h b/src/render/state.h
index 59626c4..df4d7cd 100644
--- a/src/render/state.h
+++ b/src/render/state.h
@@ -21,12 +21,14 @@ public:
inline static int width() { return render_width; }
inline static int height() { return render_height; }
inline static float aspect() { return render_aspect; }
+ inline static bool has_generate_mipmaps() { return render_has_generate_mipmaps; }
private:
static int render_width;
static int render_height;
static float render_aspect;
+ static bool render_has_generate_mipmaps;
};
} // namespace render
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;