From d8ae04d77357175003526109b6b8d782d8daf6df Mon Sep 17 00:00:00 2001 From: terminx Date: Tue, 22 Jul 2008 21:03:09 +0000 Subject: [PATCH] Support for turning vsync on and off git-svn-id: https://svn.eduke32.com/eduke32@889 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/build/include/baselayer.h | 4 ++++ polymer/build/include/glbuild.h | 1 + polymer/build/src/baselayer.c | 1 + polymer/build/src/glbuild.c | 5 +++++ polymer/build/src/polymost.c | 9 ++++++++- polymer/build/src/sdlayer.c | 12 ++++++++++++ polymer/build/src/winlayer.c | 27 ++++++++++++++++++++++++--- polymer/eduke32/source/config.c | 4 ++++ polymer/eduke32/source/menus.c | 12 +++++++++++- 9 files changed, 70 insertions(+), 5 deletions(-) diff --git a/polymer/build/include/baselayer.h b/polymer/build/include/baselayer.h index 7effef569..6d1b9ad3c 100644 --- a/polymer/build/include/baselayer.h +++ b/polymer/build/include/baselayer.h @@ -16,6 +16,8 @@ extern const char **_buildargv; extern char quitevent, appactive; +extern int vsync; + // NOTE: these are implemented in game-land so they may be overridden in game specific ways extern int startwin_open(void); extern int startwin_close(void); @@ -55,9 +57,11 @@ struct glinfo { char multitex; char envcombine; char vbos; + char vsync; char dumped; }; extern struct glinfo glinfo; +extern void setvsync(int sync); #endif extern char inputdevices; diff --git a/polymer/build/include/glbuild.h b/polymer/build/include/glbuild.h index f6226bb83..6f12d4bc4 100644 --- a/polymer/build/include/glbuild.h +++ b/polymer/build/include/glbuild.h @@ -220,6 +220,7 @@ extern int (WINAPI * bwglChoosePixelFormat)(HDC,CONST PIXELFORMATDESCRIPTOR*); extern int (WINAPI * bwglDescribePixelFormat)(HDC,int,UINT,LPPIXELFORMATDESCRIPTOR); extern int (WINAPI * bwglGetPixelFormat)(HDC); extern BOOL (WINAPI * bwglSetPixelFormat)(HDC,int,const PIXELFORMATDESCRIPTOR*); +extern BOOL (WINAPI * bwglSwapIntervalEXT)(int); #endif #endif //USE_OPENGL diff --git a/polymer/build/src/baselayer.c b/polymer/build/src/baselayer.c index 3ebd662d7..3cd8681fc 100644 --- a/polymer/build/src/baselayer.c +++ b/polymer/build/src/baselayer.c @@ -42,6 +42,7 @@ struct glinfo glinfo = 0, // multitexturing 0, // env_combine 0, // Vertex Buffer Objects + 0, // VSync support 0, // GL info dumped }; #endif diff --git a/polymer/build/src/glbuild.c b/polymer/build/src/glbuild.c index afecb38e7..9c294f326 100644 --- a/polymer/build/src/glbuild.c +++ b/polymer/build/src/glbuild.c @@ -186,6 +186,7 @@ int (WINAPI * bwglChoosePixelFormat)(HDC,CONST PIXELFORMATDESCRIPTOR*); int (WINAPI * bwglDescribePixelFormat)(HDC,int,UINT,LPPIXELFORMATDESCRIPTOR); int (WINAPI * bwglGetPixelFormat)(HDC); BOOL (WINAPI * bwglSetPixelFormat)(HDC,int,const PIXELFORMATDESCRIPTOR*); +BOOL (WINAPI * bwglSwapIntervalEXT)(int); static HANDLE hGLDLL, hGLUDLL; #else @@ -423,6 +424,9 @@ int loadglextensions(void) bglGetQueryObjectivARB = GETPROCEXTSOFT("glGetQueryObjectivARB"); bglGetQueryObjectuivARB = GETPROCEXTSOFT("glGetQueryObjectuivARB"); +#ifdef RENDERTYPEWIN + bwglSwapIntervalEXT = GETPROCEXTSOFT("wglSwapIntervalEXT"); +#endif return err; } @@ -586,6 +590,7 @@ int unloadgldriver(void) bwglDescribePixelFormat = NULL; bwglGetPixelFormat = NULL; bwglSetPixelFormat = NULL; + bwglSwapIntervalEXT = NULL; #endif return 0; diff --git a/polymer/build/src/polymost.c b/polymer/build/src/polymost.c index 9d4b810a6..126593d19 100644 --- a/polymer/build/src/polymost.c +++ b/polymer/build/src/polymost.c @@ -177,7 +177,7 @@ int r_parallaxskypanning = 0; // line of sight checks before mddraw() int r_cullobstructedmodels = 0; #define CULL_DELAY 5 -#define CULL_OFFSET 256 +#define CULL_OFFSET 384 // fullbright cvar int r_fullbrights = 1; @@ -5974,6 +5974,12 @@ static int osdcmd_polymostvars(const osdfuncparm_t *parm) else r_fullbrights = (val != 0); return OSDCMD_OK; } + else if (!Bstrcasecmp(parm->name, "r_swapinterval")) + { + if (showval) { OSD_Printf("r_swapinterval is %d\n", vsync); } + else vsync = (val != 0); + return OSDCMD_OK; + } #endif return OSDCMD_SHOWHELP; } @@ -6026,6 +6032,7 @@ void polymost_initosdfuncs(void) OSD_RegisterFunction("r_polygonmode","r_polygonmode: debugging feature",osdcmd_polymostvars); //FUK OSD_RegisterFunction("r_redbluemode","r_redbluemode: enable/disable experimental OpenGL red-blue glasses mode",osdcmd_polymostvars); OSD_RegisterFunction("r_shadescale","r_shadescale: multiplier for lighting",osdcmd_polymostvars); + OSD_RegisterFunction("r_swapinterval","r_swapinterval: sets the GL swap interval (VSync)",osdcmd_polymostvars); OSD_RegisterFunction("r_texcachecompression","r_texcachecompression: enable/disable compression of files in the OpenGL compressed texture cache",osdcmd_polymostvars); OSD_RegisterFunction("r_texcache","r_texcache: enable/disable OpenGL compressed texture cache",osdcmd_polymostvars); OSD_RegisterFunction("r_texcompr","r_texcompr: enable/disable OpenGL texture compression",osdcmd_polymostvars); diff --git a/polymer/build/src/sdlayer.c b/polymer/build/src/sdlayer.c index f9341bfdb..9ec24b7be 100644 --- a/polymer/build/src/sdlayer.c +++ b/polymer/build/src/sdlayer.c @@ -61,6 +61,7 @@ extern int curbrightness, gammabrightness; // OpenGL stuff static char nogl=0; #endif +int vsync=1; // input char inputdevices=0; @@ -205,6 +206,15 @@ int main(int argc, char *argv[]) return r; } +#if defined(USE_OPENGL) && defined(POLYMOST) +void setvsync(int sync) +{ + vsync = sync; + resetvideomode(); + if (setgamemode(fullscreen,xdim,ydim,bpp)) + OSD_Printf("restartvid: Reset failed...\n"); +} +#endif // // initsystem() -- init SDL systems @@ -967,6 +977,8 @@ int setvideomode(int x, int y, int c, int fs) SDL_GL_SetAttribute(attributes[i].attr, j); } + SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, vsync); + sdl_surface = SDL_SetVideoMode(x, y, c, SDL_OPENGL | ((fs&1)?SDL_FULLSCREEN:0)); if (!sdl_surface) { diff --git a/polymer/build/src/winlayer.c b/polymer/build/src/winlayer.c index b356f54f0..46a9ab357 100644 --- a/polymer/build/src/winlayer.c +++ b/polymer/build/src/winlayer.c @@ -116,7 +116,7 @@ char offscreenrendering=0; int glcolourdepth=32; char videomodereset = 0; char silentvideomodeswitch = 0; - +int vsync=1; // input and events char inputdevices=0; char quitevent=0, appactive=1, realfs=0, regrabmouse=0; @@ -2065,6 +2065,11 @@ int checkvideomode(int *x, int *y, int c, int fs, int forced) // // setvideomode() -- set the video mode // + +#if defined(USE_OPENGL) && defined(POLYMOST) +static HWND hGLWindow = NULL; +#endif + int setvideomode(int x, int y, int c, int fs) { char i,inp[NUM_INPUTS]; @@ -2109,6 +2114,9 @@ int setvideomode(int x, int y, int c, int fs) if (gammabrightness && setgamma() < 0) gammabrightness = 0; } +#if defined(USE_OPENGL) && defined(POLYMOST) + if (hGLWindow && glinfo.vsync) bwglSwapIntervalEXT(vsync); +#endif for (i=0;i