From bec5197da754b908fbcb3693d758485902d94608 Mon Sep 17 00:00:00 2001 From: skyjake Date: Sun, 15 Apr 2012 19:04:01 +0300 Subject: [PATCH] GL|Fixed: Toggling vid-vsync at runtime On Windows and Mac OS X, the GL context swap interval is changed using the appropriate native calls. On other platforms the Canvas will be recreated with the updated GL format. --- doomsday/engine/portable/include/gl_defer.h | 2 +- doomsday/engine/portable/src/canvaswindow.cpp | 9 +++++++++ doomsday/engine/portable/src/dgl_common.c | 6 +----- doomsday/engine/portable/src/gl_defer.c | 9 ++------- doomsday/engine/portable/src/gl_main.c | 18 +++++++++++++++--- doomsday/engine/portable/src/sys_opengl.c | 4 +--- 6 files changed, 29 insertions(+), 19 deletions(-) diff --git a/doomsday/engine/portable/include/gl_defer.h b/doomsday/engine/portable/include/gl_defer.h index 4c5945a4a4..25a4ce2e73 100644 --- a/doomsday/engine/portable/include/gl_defer.h +++ b/doomsday/engine/portable/include/gl_defer.h @@ -72,7 +72,7 @@ void GL_ReleaseReservedNames(void); */ void GL_DeferTextureUpload(const struct texturecontent_s* content); -//void GL_DeferSetVSync(boolean enableVSync); +void GL_DeferSetVSync(boolean enableVSync); // Deferring functions for various function signatures. #define LIBDENG_GL_DEFER1(form, x) void GL_Defer_##form(void (GL_CALL *ptr)(x), x) diff --git a/doomsday/engine/portable/src/canvaswindow.cpp b/doomsday/engine/portable/src/canvaswindow.cpp index 4456576e61..e7fa796726 100644 --- a/doomsday/engine/portable/src/canvaswindow.cpp +++ b/doomsday/engine/portable/src/canvaswindow.cpp @@ -92,6 +92,15 @@ void CanvasWindow::initCanvasAfterRecreation(Canvas& canvas) void CanvasWindow::recreateCanvas() { + /// @todo Instead of recreating, there is also the option of modifying the + /// existing QGLContext -- however, changing its format causes it to be + /// reset. We are doing it this way because we wish to retain the current + /// GL context's texture objects by sharing them with the new Canvas. + + /// @todo See if reseting the QGLContext actually causes all textures to be + /// lost. If not, it would be better to just change the format and + /// reinitialize the context state. + // We'll re-trap the mouse after the new canvas is ready. d->mouseWasTrapped = canvas().isMouseTrapped(); canvas().trapMouse(false); diff --git a/doomsday/engine/portable/src/dgl_common.c b/doomsday/engine/portable/src/dgl_common.c index 7c2f903a9f..aa69938827 100644 --- a/doomsday/engine/portable/src/dgl_common.c +++ b/doomsday/engine/portable/src/dgl_common.c @@ -350,9 +350,6 @@ boolean GL_Grab(int x, int y, int width, int height, dgltexformat_t format, void void GL_SetVSync(boolean on) { - Con_SetInteger("vid-vsync", on? 1 : 0); - - /* // Outside the main thread we'll need to defer the call. if(!Sys_InMainThread()) { @@ -381,8 +378,7 @@ void GL_SetVSync(boolean on) CGLSetParameter(context, kCGLCPSwapInterval, params); } } -#endif*/ - +#endif } void GL_SetMultisample(boolean on) diff --git a/doomsday/engine/portable/src/gl_defer.c b/doomsday/engine/portable/src/gl_defer.c index 4cd759bb86..793e9180b8 100644 --- a/doomsday/engine/portable/src/gl_defer.c +++ b/doomsday/engine/portable/src/gl_defer.c @@ -41,7 +41,7 @@ typedef enum { // Higher-level or non-OpenGL operations: DTT_UPLOAD_TEXTURECONTENT = DEFERREDTASK_TYPES_FIRST, - //DTT_SET_VSYNC, + DTT_SET_VSYNC, // OpenGL API calls: DTT_FUNC_PTR_BEGIN, @@ -208,10 +208,9 @@ static void processTask(deferredtask_t* task) GL_UploadTextureContent(task->data); break; - /* case DTT_SET_VSYNC: GL_SetVSync(*(boolean*)task->data); - break;*/ + break; case DTT_FUNC_PTR_E: api->func.ptr_e(api->param.e); @@ -252,11 +251,9 @@ static void destroyTaskData(deferredtask_t* d) GL_DestroyTextureContent(d->data); break; - /* case DTT_SET_VSYNC: M_Free(d->data); break; - */ case DTT_FUNC_PTR_UINT_ARRAY: M_Free(api->param.uintArray.values); @@ -441,9 +438,7 @@ void GL_DeferTextureUpload(const struct texturecontent_s* content) enqueueTask(DTT_UPLOAD_TEXTURECONTENT, GL_ConstructTextureContentCopy(content)); } -/* void GL_DeferSetVSync(boolean enableVSync) { enqueueTask(DTT_SET_VSYNC, M_MemDup(&enableVSync, sizeof(enableVSync))); } -*/ diff --git a/doomsday/engine/portable/src/gl_main.c b/doomsday/engine/portable/src/gl_main.c index f37085b2db..5c39db7c42 100644 --- a/doomsday/engine/portable/src/gl_main.c +++ b/doomsday/engine/portable/src/gl_main.c @@ -130,7 +130,7 @@ static viewport_t currentView; // CODE -------------------------------------------------------------------- -static void videoSettingsChanged(void) +static void videoFSAAChanged(void) { if(!novideo && Window_Main()) { @@ -138,6 +138,18 @@ static void videoSettingsChanged(void) } } +static void videoVsyncChanged(void) +{ + if(!novideo && Window_Main()) + { +#if defined(WIN32) || defined(MACOSX) + GL_SetVSync(Con_GetByte("vid-vsync") != 0); +#else + Window_UpdateCanvasFormat(Window_Main()); +#endif + } +} + void GL_Register(void) { // Cvars @@ -155,8 +167,8 @@ void GL_Register(void) C_VAR_INT("rend-mobj-smooth-turn", &useSRVOAngle, 0, 0, 1); // * video - C_VAR_BYTE2("vid-vsync", &vsyncEnabled, 0, 0, 1, videoSettingsChanged); - C_VAR_BYTE2("vid-fsaa", &fsaaEnabled, 0, 0, 1, videoSettingsChanged); + C_VAR_BYTE2("vid-vsync", &vsyncEnabled, 0, 0, 1, videoVsyncChanged); + C_VAR_BYTE2("vid-fsaa", &fsaaEnabled, 0, 0, 1, videoFSAAChanged); C_VAR_INT("vid-res-x", &defResX, CVF_NO_MAX|CVF_READ_ONLY|CVF_NO_ARCHIVE, 320, 0); C_VAR_INT("vid-res-y", &defResY, CVF_NO_MAX|CVF_READ_ONLY|CVF_NO_ARCHIVE, 240, 0); C_VAR_INT("vid-bpp", &defBPP, CVF_READ_ONLY|CVF_NO_ARCHIVE, 16, 32); diff --git a/doomsday/engine/portable/src/sys_opengl.c b/doomsday/engine/portable/src/sys_opengl.c index 0862dc8a40..e51ae20849 100644 --- a/doomsday/engine/portable/src/sys_opengl.c +++ b/doomsday/engine/portable/src/sys_opengl.c @@ -187,10 +187,8 @@ static void initialize(void) } if(0 == GL_state.extensions.wglSwapIntervalEXT || NULL == wglSwapIntervalEXT) GL_state.features.vsync = false; -#elif defined(MACOSX) - GL_state.features.vsync = true; #else - GL_state.features.vsync = false; + GL_state.features.vsync = true; #endif }