diff options
author | Andrei Karas <akaras@inbox.ru> | 2012-04-26 22:24:38 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2012-04-27 03:49:15 +0300 |
commit | 70f471c5322231d7651c0275df46b3a9547f9ac0 (patch) | |
tree | 9bc0e4948f8fcfab71c2b4f900dd4c0f16611a96 /src/openglgraphics.cpp | |
parent | 129b19f69fbbdcd896150aa8faa7f20254169c0c (diff) | |
download | manaplus-70f471c5322231d7651c0275df46b3a9547f9ac0.tar.gz manaplus-70f471c5322231d7651c0275df46b3a9547f9ac0.tar.bz2 manaplus-70f471c5322231d7651c0275df46b3a9547f9ac0.tar.xz manaplus-70f471c5322231d7651c0275df46b3a9547f9ac0.zip |
Add option for enable textures compression (disabled by default)
Diffstat (limited to 'src/openglgraphics.cpp')
-rw-r--r-- | src/openglgraphics.cpp | 57 |
1 files changed, 52 insertions, 5 deletions
diff --git a/src/openglgraphics.cpp b/src/openglgraphics.cpp index e5523c479..6e0bbf829 100644 --- a/src/openglgraphics.cpp +++ b/src/openglgraphics.cpp @@ -150,11 +150,12 @@ bool OpenGLGraphics::setVideoMode(int w, int h, int bpp, bool fs, splitToStringSet(mExtensions, glExtensions, ' '); + updateTextureFormat(); updateMemoryInfo(); GLint texSize; bool rectTex = supportExtension("GL_ARB_texture_rectangle"); - if (rectTex) + if (rectTex && Image::getInternalTextureType() == 4) { logger->log1("using GL_ARB_texture_rectangle"); Image::mTextureType = GL_TEXTURE_RECTANGLE_ARB; @@ -204,8 +205,8 @@ static inline void drawQuad(Image *image, dstX, dstY + height }; - glVertexPointer(2, GL_FLOAT, 0, &vert); - glTexCoordPointer(2, GL_INT, 0, &tex); + glVertexPointer(2, GL_INT, 0, &vert); + glTexCoordPointer(2, GL_FLOAT, 0, &tex); glDrawArrays(GL_QUADS, 0, 4); } @@ -266,8 +267,8 @@ static inline void drawRescaledQuad(Image *image, dstX, dstY + desiredHeight }; - glVertexPointer(2, GL_FLOAT, 0, &vert); - glTexCoordPointer(2, GL_INT, 0, &tex); + glVertexPointer(2, GL_INT, 0, &vert); + glTexCoordPointer(2, GL_FLOAT, 0, &tex); glDrawArrays(GL_QUADS, 0, 4); } @@ -1512,4 +1513,50 @@ int OpenGLGraphics::getMemoryUsage() return 0; } +void OpenGLGraphics::updateTextureFormat() +{ + if (!config.getBoolValue("compresstextures")) + return; + + if (supportExtension("GL_ARB_texture_compression")) + { + if (supportExtension("GL_EXT_texture_compression_s3tc") + || supportExtension("3DFX_texture_compression_FXT1")) + { + GLint num; + GLint *formats = nullptr; + glGetIntegerv(GL_NUM_COMPRESSED_TEXTURE_FORMATS, &num); + logger->log("support %d compressed formats", num); + formats = new GLint[num > 10 ? num : 10]; + glGetIntegerv(GL_COMPRESSED_TEXTURE_FORMATS, formats); + for (int f = 0; f < num; f ++) + { + if (formats[f] == GL_COMPRESSED_RGBA_S3TC_DXT5_EXT) + { + delete []formats; + Image::setInternalTextureType( + GL_COMPRESSED_RGBA_S3TC_DXT5_EXT); + logger->log("using s3tc texture compression"); + return; + } + else if (formats[f] == GL_COMPRESSED_RGBA_FXT1_3DFX) + { + delete []formats; + Image::setInternalTextureType( + GL_COMPRESSED_RGBA_FXT1_3DFX); + logger->log("using fxt1 texture compression"); + return; + } + } + Image::setInternalTextureType(GL_COMPRESSED_RGBA_ARB); + logger->log("using texture compression"); + } + else + { + Image::setInternalTextureType(GL_COMPRESSED_RGBA_ARB); + logger->log("using texture compression"); + } + } +} + #endif // USE_OPENGL |