diff options
-rw-r--r-- | src/openglgraphics.cpp | 23 | ||||
-rw-r--r-- | src/openglgraphics.h | 11 |
2 files changed, 31 insertions, 3 deletions
diff --git a/src/openglgraphics.cpp b/src/openglgraphics.cpp index 50fee075..f30e866d 100644 --- a/src/openglgraphics.cpp +++ b/src/openglgraphics.cpp @@ -44,7 +44,8 @@ GLuint OpenGLGraphics::mLastImage = 0; OpenGLGraphics::OpenGLGraphics(): mAlpha(false), mTexture(false), mColorAlpha(false), - mSync(false) + mSync(false), + mReduceInputLag(true) { mFloatTexArray = new GLfloat[vertexBufSize * 4]; mIntTexArray = new GLint[vertexBufSize * 4]; @@ -63,6 +64,11 @@ void OpenGLGraphics::setSync(bool sync) mSync = sync; } +void OpenGLGraphics::setReduceInputLag(bool reduceInputLag) +{ + mReduceInputLag = reduceInputLag; +} + bool OpenGLGraphics::setVideoMode(int w, int h, int bpp, bool fs, bool hwaccel) { logger->log("Setting video mode %dx%d %s", @@ -604,9 +610,20 @@ void OpenGLGraphics::drawRescaledImagePattern(Image *image, void OpenGLGraphics::updateScreen() { - glFlush(); - glFinish(); SDL_GL_SwapBuffers(); + + /* + * glFinish flushes all OpenGL commands and makes sure they have been + * executed before continuing. If we do not do this we allow the next + * frame to be prepared while the current one isn't even displaying yet, + * which can cause input lag that is especially noticable at mouse + * movement. + * + * The setting is optional since calling glFinish can reduce performance + * and increase CPU usage. + */ + if (mReduceInputLag) + glFinish(); } void OpenGLGraphics::_beginDraw() diff --git a/src/openglgraphics.h b/src/openglgraphics.h index a1d78e46..63c32261 100644 --- a/src/openglgraphics.h +++ b/src/openglgraphics.h @@ -43,6 +43,16 @@ class OpenGLGraphics : public Graphics void setSync(bool sync); bool getSync() const { return mSync; } + /** + * Sets whether input lag should be reduced. + * + * This means waiting until the graphics card has finished drawing and + * displaying the current frame until continuing towards the next, + * possibly at the cost of performance and CPU usage. + */ + void setReduceInputLag(bool reduceInputLag); + bool getReduceInputLag() const { return mReduceInputLag; } + bool setVideoMode(int w, int h, int bpp, bool fs, bool hwaccel); bool drawImage(Image *image, @@ -114,6 +124,7 @@ class OpenGLGraphics : public Graphics bool mAlpha, mTexture; bool mColorAlpha; bool mSync; + bool mReduceInputLag; }; #endif //USE_OPENGL |