summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-04-26 22:24:38 +0300
committerAndrei Karas <akaras@inbox.ru>2012-04-27 03:49:15 +0300
commit70f471c5322231d7651c0275df46b3a9547f9ac0 (patch)
tree9bc0e4948f8fcfab71c2b4f900dd4c0f16611a96
parent129b19f69fbbdcd896150aa8faa7f20254169c0c (diff)
downloadmv-70f471c5322231d7651c0275df46b3a9547f9ac0.tar.gz
mv-70f471c5322231d7651c0275df46b3a9547f9ac0.tar.bz2
mv-70f471c5322231d7651c0275df46b3a9547f9ac0.tar.xz
mv-70f471c5322231d7651c0275df46b3a9547f9ac0.zip
Add option for enable textures compression (disabled by default)
-rw-r--r--src/defaults.cpp1
-rw-r--r--src/graphics.h3
-rw-r--r--src/gui/setup_perfomance.cpp9
-rw-r--r--src/openglgraphics.cpp57
-rw-r--r--src/openglgraphics.h2
-rw-r--r--src/resources/image.cpp17
-rw-r--r--src/resources/image.h9
7 files changed, 91 insertions, 7 deletions
diff --git a/src/defaults.cpp b/src/defaults.cpp
index be6e72f77..71d190a00 100644
--- a/src/defaults.cpp
+++ b/src/defaults.cpp
@@ -251,6 +251,7 @@ DefaultsData* getConfigDefaults()
AddDEF(configData, "audioChannels", 2);
AddDEF(configData, "repeateDelay", SDL_DEFAULT_REPEAT_DELAY);
AddDEF(configData, "repeateInterval", SDL_DEFAULT_REPEAT_INTERVAL);
+ AddDEF(configData, "compresstextures", false);
return configData;
}
diff --git a/src/graphics.h b/src/graphics.h
index 3ae2a7718..1779a14a5 100644
--- a/src/graphics.h
+++ b/src/graphics.h
@@ -257,6 +257,9 @@ class Graphics : public gcn::SDLGraphics
virtual int getMemoryUsage()
{ return 0; }
+ virtual void updateTextureFormat()
+ { }
+
virtual bool drawNet(int x1, int y1, int x2, int y2,
int width, int height);
diff --git a/src/gui/setup_perfomance.cpp b/src/gui/setup_perfomance.cpp
index 976f1123b..865839c52 100644
--- a/src/gui/setup_perfomance.cpp
+++ b/src/gui/setup_perfomance.cpp
@@ -79,6 +79,7 @@ Setup_Perfomance::Setup_Perfomance()
new SetupItemCheckBox(_("Enable reorder sprites."), "",
"enableReorderSprites", this, "enableReorderSpritesEvent");
+
new SetupItemLabel(_("Small memory (enable for lower memory usage)"),
"", this);
@@ -88,6 +89,14 @@ Setup_Perfomance::Setup_Perfomance()
new SetupItemCheckBox(_("Disable beings caching (Software)"), "",
"disableBeingCaching", this, "disableBeingCachingEvent");
+
+ new SetupItemLabel(_("Different options (enable or disable can improve perfomance)"),
+ "", this);
+
+ new SetupItemCheckBox(_("Enable texture compression (fast OpenGL)"), "",
+ "compresstextures", this, "compresstexturesEvent");
+
+
setDimension(gcn::Rectangle(0, 0, 550, 350));
}
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
diff --git a/src/openglgraphics.h b/src/openglgraphics.h
index 652447447..06f37db0d 100644
--- a/src/openglgraphics.h
+++ b/src/openglgraphics.h
@@ -150,6 +150,8 @@ class OpenGLGraphics : public Graphics
int getMemoryUsage();
+ void updateTextureFormat();
+
static void bindTexture(GLenum target, GLuint texture);
static GLuint mLastImage;
diff --git a/src/resources/image.cpp b/src/resources/image.cpp
index 54a969d57..274262304 100644
--- a/src/resources/image.cpp
+++ b/src/resources/image.cpp
@@ -44,6 +44,7 @@
#ifdef USE_OPENGL
int Image::mUseOpenGL = 0;
int Image::mTextureType = 0;
+int Image::mInternalTextureType = 4;
int Image::mTextureSize = 0;
bool Image::mBlur = true;
#endif
@@ -202,7 +203,8 @@ Image *Image::createTextSurface(SDL_Surface *tmpImage, float alpha)
if (mUseOpenGL)
{
img = _GLload(tmpImage);
- img->setAlpha(alpha);
+ if (img)
+ img->setAlpha(alpha);
return img;
}
#endif
@@ -778,9 +780,20 @@ Image *Image::_GLload(SDL_Surface *tmpImage)
glTexParameteri(mTextureType, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
}
- glTexImage2D(mTextureType, 0, 4, tmpImage->w, tmpImage->h,
+ glTexImage2D(mTextureType, 0, mInternalTextureType,
+ tmpImage->w, tmpImage->h,
0, GL_RGBA, GL_UNSIGNED_BYTE, tmpImage->pixels);
+/*
+ GLint compressed;
+ glGetTexLevelParameteriv(mTextureType, 0,
+ GL_TEXTURE_COMPRESSED_ARB, &compressed);
+ if (compressed)
+ logger->log("image compressed");
+ else
+ logger->log("image not compressed");
+*/
+
#ifdef DEBUG_OPENGL_LEAKS
textures_count ++;
#endif
diff --git a/src/resources/image.h b/src/resources/image.h
index 17eb3ec93..d4cfaa9ef 100644
--- a/src/resources/image.h
+++ b/src/resources/image.h
@@ -215,10 +215,19 @@ class Image : public Resource
static int getTextureType()
{ return mTextureType; }
+ static int getInternalTextureType()
+ { return mInternalTextureType; }
+
+ static void setInternalTextureType(int n)
+ { mInternalTextureType = n; }
+
static void setBlur(bool n)
{ mBlur = n; }
static int mTextureType;
+
+ static int mInternalTextureType;
+
#endif
bool isHasAlphaChannel() const