Skip to content

Commit

Permalink
GL|Fixed: Toggling vid-vsync at runtime
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
skyjake committed Apr 15, 2012
1 parent 0f4f1a5 commit bec5197
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 19 deletions.
2 changes: 1 addition & 1 deletion doomsday/engine/portable/include/gl_defer.h
Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions doomsday/engine/portable/src/canvaswindow.cpp
Expand Up @@ -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);
Expand Down
6 changes: 1 addition & 5 deletions doomsday/engine/portable/src/dgl_common.c
Expand Up @@ -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())
{
Expand Down Expand Up @@ -381,8 +378,7 @@ void GL_SetVSync(boolean on)
CGLSetParameter(context, kCGLCPSwapInterval, params);
}
}
#endif*/

#endif
}

void GL_SetMultisample(boolean on)
Expand Down
9 changes: 2 additions & 7 deletions doomsday/engine/portable/src/gl_defer.c
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)));
}
*/
18 changes: 15 additions & 3 deletions doomsday/engine/portable/src/gl_main.c
Expand Up @@ -130,14 +130,26 @@ static viewport_t currentView;

// CODE --------------------------------------------------------------------

static void videoSettingsChanged(void)
static void videoFSAAChanged(void)
{
if(!novideo && Window_Main())
{
Window_UpdateCanvasFormat(Window_Main());
}
}

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
Expand All @@ -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);
Expand Down
4 changes: 1 addition & 3 deletions doomsday/engine/portable/src/sys_opengl.c
Expand Up @@ -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
}

Expand Down

0 comments on commit bec5197

Please sign in to comment.