From ea90bd0715db95ebf3ba523c75493f4e73e7ffc1 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Thu, 14 Apr 2011 05:02:32 +0000 Subject: [PATCH] - added verticle synch option, to enable use: EnableVSynch=true --- source/glest_game/main/main.cpp | 5 +++++ source/shared_lib/include/platform/sdl/window.h | 4 ++++ source/shared_lib/sources/platform/sdl/window.cpp | 10 ++++++++++ 3 files changed, 19 insertions(+) diff --git a/source/glest_game/main/main.cpp b/source/glest_game/main/main.cpp index 95257e03..707a6f6f 100644 --- a/source/glest_game/main/main.cpp +++ b/source/glest_game/main/main.cpp @@ -2165,6 +2165,11 @@ int glestMain(int argc, char** argv) { if(SystemFlags::VERBOSE_MODE_ENABLED) printf("**WARNING** Disabling VBO's\n"); } + if(config.getBool("EnableVSynch","false") == true) { + Window::setTryVSynch(true); + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("**ENABLED OPENGL VSYNCH**\n"); + } + //float pingTime = Socket::getAveragePingMS("soft-haus.com"); //printf("Ping time = %f\n",pingTime); diff --git a/source/shared_lib/include/platform/sdl/window.h b/source/shared_lib/include/platform/sdl/window.h index dee6217b..663410f4 100644 --- a/source/shared_lib/include/platform/sdl/window.h +++ b/source/shared_lib/include/platform/sdl/window.h @@ -133,6 +133,7 @@ private: static bool isKeyPressedDown; static bool isFullScreen; static SDL_keysym keystate; + static bool tryVSynch; static void setLastMouseEvent(int64 lastMouseEvent) {Window::lastMouseEvent = lastMouseEvent;} static int64 getLastMouseEvent() {return Window::lastMouseEvent;} @@ -164,6 +165,9 @@ public: Window(); virtual ~Window(); + static bool getTryVSynch() { return tryVSynch; } + static void setTryVSynch(bool value) { tryVSynch = value; } + WindowHandle getHandle() {return 0;} string getText(); int getX() { return 0; } diff --git a/source/shared_lib/sources/platform/sdl/window.cpp b/source/shared_lib/sources/platform/sdl/window.cpp index 94d905d0..d21b3002 100644 --- a/source/shared_lib/sources/platform/sdl/window.cpp +++ b/source/shared_lib/sources/platform/sdl/window.cpp @@ -58,6 +58,8 @@ bool Window::allowAltEnterFullscreenToggle = true; #endif int Window::lastShowMouseState = 0; +bool Window::tryVSynch = false; + // ========== PUBLIC ========== Window::Window() { @@ -360,6 +362,14 @@ void Window::setupGraphicsScreen(int depthBits, int stencilBits, bool hardware_a SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, newStencilBits); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, newDepthBits); + const SDL_VideoInfo *info = SDL_GetVideoInfo(); +#ifdef SDL_GL_SWAP_CONTROL + if(Window::tryVSynch == true) { + /* we want vsync for smooth scrolling */ + SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 1); + } +#endif + // setup LOD bias factor //const float lodBias = std::max(std::min( configHandler->Get("TextureLODBias", 0.0f) , 4.0f), -4.0f); const float lodBias = max(min(0.0f,4.0f),-4.0f);