summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-10-01 23:32:51 +0300
committerAndrei Karas <akaras@inbox.ru>2012-10-01 23:45:06 +0300
commit7fa069aec585316c34ada298ec557c7e800bf8f3 (patch)
tree64cb7078677a695eb9cc429e4546114d06ff6d37 /src
parentc195c960fc2ce7a5a211c26310ae98bfe39ab777 (diff)
downloadmv-7fa069aec585316c34ada298ec557c7e800bf8f3.tar.gz
mv-7fa069aec585316c34ada298ec557c7e800bf8f3.tar.bz2
mv-7fa069aec585316c34ada298ec557c7e800bf8f3.tar.xz
mv-7fa069aec585316c34ada298ec557c7e800bf8f3.zip
Using GL_ARB_sampler_objects.
Diffstat (limited to 'src')
-rw-r--r--src/defaults.cpp1
-rw-r--r--src/graphicsmanager.cpp62
-rw-r--r--src/graphicsmanager.h22
-rw-r--r--src/gui/setup_perfomance.cpp6
-rw-r--r--src/mgl.h1
-rw-r--r--src/resources/openglimagehelper.cpp35
-rw-r--r--src/resources/openglimagehelper.h13
7 files changed, 119 insertions, 21 deletions
diff --git a/src/defaults.cpp b/src/defaults.cpp
index 3f92d60ce..770c61ee0 100644
--- a/src/defaults.cpp
+++ b/src/defaults.cpp
@@ -263,6 +263,7 @@ DefaultsData* getConfigDefaults()
AddDEF("enableCompoundSpriteDelay", true);
AddDEF("npcfontSize", 13);
AddDEF("useAtlases", true);
+ AddDEF("useTextureSampler", true);
return configData;
}
diff --git a/src/graphicsmanager.cpp b/src/graphicsmanager.cpp
index 4b59c68f2..604f0eb3f 100644
--- a/src/graphicsmanager.cpp
+++ b/src/graphicsmanager.cpp
@@ -20,12 +20,10 @@
#include "graphicsmanager.h"
+#ifdef USE_OPENGL
#ifndef WIN32
-#define GL_GLEXT_PROTOTYPES 1
#include "GL/glx.h"
-// hack to hide warnings
-#undef GL_GLEXT_VERSION
-#undef GL_GLEXT_PROTOTYPES
+#endif
#endif
#include "configuration.h"
@@ -66,12 +64,20 @@ GraphicsManager::GraphicsManager() :
mPlatformMinor(0),
mPlatformMajor(0),
mMaxVertices(500),
+#ifdef USE_OPENGL
+ mUseTextureSampler(true),
+ mTextureSampler(0),
+#endif
mUseAtlases(false)
{
}
GraphicsManager::~GraphicsManager()
{
+#ifdef USE_OPENGL
+ if (mglGenSamplers && mTextureSampler)
+ mglDeleteSamplers(1, &mTextureSampler);
+#endif
}
int GraphicsManager::startDetection()
@@ -187,17 +193,20 @@ void GraphicsManager::initGraphics(bool noOpenGL)
imageHelper = new SDLImageHelper;
sdlImageHelper = imageHelper;
mainGraphics = new Graphics;
+ mUseTextureSampler = false;
break;
case 1:
default:
imageHelper = new OpenGLImageHelper;
sdlImageHelper = new SDLImageHelper;
mainGraphics = new NormalOpenGLGraphics;
+ mUseTextureSampler = true;
break;
case 2:
imageHelper = new OpenGLImageHelper;
sdlImageHelper = new SDLImageHelper;
mainGraphics = new SafeOpenGLGraphics;
+ mUseTextureSampler = false;
break;
};
mUseAtlases = imageHelper->useOpenGL()
@@ -605,6 +614,14 @@ void GraphicsManager::initOpenGLFunctions()
assignFunction(glDeleteSamplers, "glDeleteSamplers");
assignFunction(glBindSampler, "glBindSampler");
assignFunction(glSamplerParameteri, "glSamplerParameteri");
+ if (mglGenSamplers && config.getBoolValue("useTextureSampler"))
+ mUseTextureSampler &= true;
+ else
+ mUseTextureSampler = false;
+ }
+ else
+ {
+ mUseTextureSampler = false;
}
#ifdef WIN32
@@ -636,6 +653,43 @@ void GraphicsManager::initOpenGL()
updateExtensions();
initOpenGLFunctions();
updatePlanformExtensions();
+ createTextureSampler();
updateLimits();
#endif
}
+
+void GraphicsManager::createTextureSampler()
+{
+ OpenGLImageHelper::setUseTextureSampler(mUseTextureSampler);
+ if (mUseTextureSampler)
+ {
+ logger->log("using texture sampler");
+ getLastError();
+ mglGenSamplers(1, &mTextureSampler);
+ if (getLastError() != GL_NO_ERROR)
+ {
+ mUseTextureSampler = false;
+ logger->log("texture sampler error");
+ return;
+ }
+ OpenGLImageHelper::initTextureSampler(mTextureSampler);
+ mglBindSampler(0, mTextureSampler);
+ if (getLastError() != GL_NO_ERROR)
+ {
+ mUseTextureSampler = false;
+ logger->log("texture sampler error");
+ }
+ }
+}
+
+unsigned int GraphicsManager::getLastError()
+{
+ GLenum tmp = glGetError();
+ GLenum error = GL_NO_ERROR;
+ while (tmp != GL_NO_ERROR)
+ {
+ error = tmp;
+ tmp = glGetError();
+ }
+ return error;
+}
diff --git a/src/graphicsmanager.h b/src/graphicsmanager.h
index 84523d19f..450040eed 100644
--- a/src/graphicsmanager.h
+++ b/src/graphicsmanager.h
@@ -21,6 +21,18 @@
#ifndef GRAPHICSMANAGER_H
#define GRAPHICSMANAGER_H
+#include "main.h"
+
+#ifdef USE_OPENGL
+#ifndef WIN32
+#define GL_GLEXT_PROTOTYPES 1
+#include <SDL_opengl.h>
+// hack to hide warnings
+#undef GL_GLEXT_VERSION
+#undef GL_GLEXT_PROTOTYPES
+#endif
+#endif
+
#include <set>
#include <string>
@@ -75,12 +87,16 @@ class GraphicsManager final
Graphics *createGraphics();
+ void createTextureSampler();
+
int getMaxVertices() const
{ return mMaxVertices; }
bool getUseAtlases() const
{ return mUseAtlases; }
+ unsigned int getLastError();
+
private:
std::set<std::string> mExtensions;
@@ -98,7 +114,13 @@ class GraphicsManager final
int mMaxVertices;
+#ifdef USE_OPENGL
+ bool mUseTextureSampler;
+
+ GLuint mTextureSampler;
+#endif
bool mUseAtlases;
+
};
extern GraphicsManager graphicsManager;
diff --git a/src/gui/setup_perfomance.cpp b/src/gui/setup_perfomance.cpp
index 44a729a31..555e36020 100644
--- a/src/gui/setup_perfomance.cpp
+++ b/src/gui/setup_perfomance.cpp
@@ -69,9 +69,13 @@ Setup_Perfomance::Setup_Perfomance() :
new SetupItemCheckBox(_("Enable compound sprite delay (Software)"), "",
"enableCompoundSpriteDelay", this, "enableCompoundSpriteDelayEvent");
- new SetupItemCheckBox(_("Enable delayed images load (OpenGL)"), "",
+ new SetupItemCheckBox(_("Enable delayed images load (OpenGL)"), "",
"enableDelayedAnimations", this, "enableDelayedAnimationsEvent");
+ new SetupItemCheckBox(_("Enable texture sampler (OpenGL)"), "",
+ "useTextureSampler", this, "useTextureSamplerEvent");
+
+
new SetupItemLabel(_("Better quality (disable for better perfomance)"),
"", this);
diff --git a/src/mgl.h b/src/mgl.h
index 8526dbc67..65d5f8548 100644
--- a/src/mgl.h
+++ b/src/mgl.h
@@ -24,7 +24,6 @@
#define GL_GLEXT_PROTOTYPES 1
#include <SDL_opengl.h>
-#include <SDL_syswm.h>
#include <GL/glext.h>
#define GL_NUM_EXTENSIONS 0x821D
diff --git a/src/resources/openglimagehelper.cpp b/src/resources/openglimagehelper.cpp
index 8aed5330e..f1847c150 100644
--- a/src/resources/openglimagehelper.cpp
+++ b/src/resources/openglimagehelper.cpp
@@ -28,6 +28,7 @@
#include "game.h"
#include "graphicsmanager.h"
#include "logger.h"
+#include "mgl.h"
#include "normalopenglgraphics.h"
#include "safeopenglgraphics.h"
@@ -47,6 +48,7 @@ int OpenGLImageHelper::mInternalTextureType = GL_RGBA8;
int OpenGLImageHelper::mTextureSize = 0;
bool OpenGLImageHelper::mBlur = true;
int OpenGLImageHelper::mUseOpenGL = 0;
+bool OpenGLImageHelper::mUseTextureSampler = false;
Image *OpenGLImageHelper::load(SDL_RWops *const rw, Dye const &dye)
{
@@ -222,15 +224,18 @@ Image *OpenGLImageHelper::glLoad(SDL_Surface *tmpImage)
SDL_LockSurface(tmpImage);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
- if (mBlur)
+ if (!mUseTextureSampler)
{
- glTexParameteri(mTextureType, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(mTextureType, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- }
- else
- {
- glTexParameteri(mTextureType, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glTexParameteri(mTextureType, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ if (mBlur)
+ {
+ glTexParameteri(mTextureType, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(mTextureType, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ }
+ else
+ {
+ glTexParameteri(mTextureType, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexParameteri(mTextureType, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ }
}
glTexImage2D(mTextureType, 0, mInternalTextureType,
@@ -300,4 +305,18 @@ int OpenGLImageHelper::useOpenGL()
{
return mUseOpenGL;
}
+
+void OpenGLImageHelper::initTextureSampler(GLint id)
+{
+ if (mBlur)
+ {
+ mglSamplerParameteri(id, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ mglSamplerParameteri(id, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ }
+ else
+ {
+ mglSamplerParameteri(id, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ mglSamplerParameteri(id, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ }
+}
#endif
diff --git a/src/resources/openglimagehelper.h b/src/resources/openglimagehelper.h
index 292e18138..e1a6d48cc 100644
--- a/src/resources/openglimagehelper.h
+++ b/src/resources/openglimagehelper.h
@@ -33,14 +33,7 @@
#include <SDL.h>
#ifdef USE_OPENGL
-
-/* The definition of OpenGL extensions by SDL is giving problems with recent
- * gl.h headers, since they also include these definitions. As we're not using
- * extensions anyway it's safe to just disable the SDL version.
- */
-//#define NO_SDL_GLEXT
#define GL_GLEXT_PROTOTYPES 1
-
#include <SDL_opengl.h>
#endif
@@ -112,6 +105,11 @@ class OpenGLImageHelper final : public ImageHelper
static int getTextureSize()
{ return mTextureSize; }
+ static void initTextureSampler(GLint id);
+
+ static void setUseTextureSampler(bool b)
+ { mUseTextureSampler = b; }
+
protected:
/**
* Returns the first power of two equal or bigger than the input.
@@ -123,6 +121,7 @@ class OpenGLImageHelper final : public ImageHelper
static int mUseOpenGL;
static int mTextureSize;
static bool mBlur;
+ static bool mUseTextureSampler;
};
#endif