From 1bc84de412775abcef84c1f604160121f245b131 Mon Sep 17 00:00:00 2001 From: Thorbjørn Lindeijer Date: Sun, 22 Jul 2012 21:24:31 +0200 Subject: Added support for ARB_texture_non_power_of_two extension If the graphics driver supports this, there is no need to create textures with power-of-two dimensions. It is then also preferred to use regular textures than relying on the older GL_ARB_texture_rectangle extension. Reviewed-by: Erik Schilling --- src/openglgraphics.cpp | 5 ++++- src/resources/image.cpp | 3 ++- src/resources/image.h | 1 + 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/openglgraphics.cpp b/src/openglgraphics.cpp index 66d0d0fc..50fee075 100644 --- a/src/openglgraphics.cpp +++ b/src/openglgraphics.cpp @@ -113,14 +113,17 @@ bool OpenGLGraphics::setVideoMode(int w, int h, int bpp, bool fs, bool hwaccel) char const *glExtensions = (char const *)glGetString(GL_EXTENSIONS); GLint texSize; bool rectTex = strstr(glExtensions, "GL_ARB_texture_rectangle"); - if (rectTex) + bool npotTex = strstr(glExtensions, "GL_ARB_texture_non_power_of_two"); + if (rectTex && !npotTex) { Image::mTextureType = GL_TEXTURE_RECTANGLE_ARB; + Image::mPowerOfTwoTextures = false; glGetIntegerv(GL_MAX_RECTANGLE_TEXTURE_SIZE_ARB, &texSize); } else { Image::mTextureType = GL_TEXTURE_2D; + Image::mPowerOfTwoTextures = !npotTex; glGetIntegerv(GL_MAX_TEXTURE_SIZE, &texSize); } Image::mTextureSize = texSize; diff --git a/src/resources/image.cpp b/src/resources/image.cpp index 9a3e2ba2..3afa479f 100644 --- a/src/resources/image.cpp +++ b/src/resources/image.cpp @@ -36,6 +36,7 @@ #ifdef USE_OPENGL bool Image::mUseOpenGL = false; +bool Image::mPowerOfTwoTextures = true; int Image::mTextureType = 0; int Image::mTextureSize = 0; #endif @@ -544,7 +545,7 @@ void Image::setLoadAsOpenGL(bool useOpenGL) int Image::powerOfTwo(int input) { int value; - if (mTextureType == GL_TEXTURE_2D) + if (mPowerOfTwoTextures) { value = 1; while (value < input && value < mTextureSize) diff --git a/src/resources/image.h b/src/resources/image.h index 7df74c3f..33db7848 100644 --- a/src/resources/image.h +++ b/src/resources/image.h @@ -249,6 +249,7 @@ class Image : public Resource int mTexWidth, mTexHeight; static bool mUseOpenGL; + static bool mPowerOfTwoTextures; static int mTextureType; static int mTextureSize; #endif -- cgit v1.2.3-60-g2f50