From dfb24aff4c683471fec95392a9d3a46687f40f28 Mon Sep 17 00:00:00 2001 From: Thorbjørn Lindeijer Date: Sun, 22 Jul 2012 21:50:50 +0200 Subject: Removed manual calling of glFlush and made glFinish optional Actually neither glFlush nor glFinish need to be called manually [1]. However, the rendering pipeline is then free to queue up future frames which can cause a lag which is especially noticable with mouse movement. To avoid this lag, we call glFinish after SDL_GL_SwapBuffers. This makes sure processing of the next frame does not start before the current frame is being displayed. [1] http://www.opengl.org/wiki/Common_Mistakes#glFinish_and_glFlush Reviewed-by: Yohann Ferreira Sounded-fine-to: Erik Schilling --- src/openglgraphics.cpp | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'src/openglgraphics.cpp') 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() -- cgit v1.2.3-70-g09d2