Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
libgui|Windows|macOS: Setting vsync
  • Loading branch information
skyjake committed Oct 12, 2016
1 parent c0d82ea commit 2a5fc99
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
1 change: 1 addition & 0 deletions doomsday/sdk/libgui/CMakeLists.txt
Expand Up @@ -115,6 +115,7 @@ endif ()

if (APPLE)
link_framework (libgui PRIVATE Cocoa)
link_framework (libgui PRIVATE OpenGL)
endif ()

if (DENG_X11)
Expand Down
5 changes: 4 additions & 1 deletion doomsday/sdk/libgui/include/de/graphics/glinfo.h
Expand Up @@ -111,7 +111,10 @@ class LIBGUI_PUBLIC GLInfo
static QOpenGLExtension_EXT_framebuffer_blit *EXT_framebuffer_blit();
static QOpenGLExtension_EXT_framebuffer_multisample *EXT_framebuffer_multisample();
static QOpenGLExtension_EXT_framebuffer_object *EXT_framebuffer_object();
static QOpenGLExtension_NV_framebuffer_multisample_coverage *NV_framebuffer_multisample_coverage();
static QOpenGLExtension_NV_framebuffer_multisample_coverage
*NV_framebuffer_multisample_coverage();

static void setSwapInterval(int interval);

private:
DENG2_PRIVATE(d)
Expand Down
40 changes: 40 additions & 0 deletions doomsday/sdk/libgui/src/graphics/glinfo.cpp
Expand Up @@ -43,6 +43,10 @@ DENG2_PIMPL_NOREF(GLInfo), public QOpenGLFunctions_Doomsday
std::unique_ptr<QOpenGLExtension_EXT_framebuffer_object> EXT_framebuffer_object;
std::unique_ptr<QOpenGLExtension_NV_framebuffer_multisample_coverage> NV_framebuffer_multisample_coverage;

#ifdef WIN32
BOOL (APIENTRY *wglSwapIntervalEXT)(int interval) = nullptr;
#endif

Impl()
{
zap(ext);
Expand Down Expand Up @@ -158,6 +162,12 @@ DENG2_PIMPL_NOREF(GLInfo), public QOpenGLFunctions_Doomsday
#ifdef WIN32
ext.Windows_ARB_multisample = query("WGL_ARB_multisample");
ext.Windows_EXT_swap_control = query("WGL_EXT_swap_control");

if (ext.Windows_EXT_swap_control)
{
wglSwapIntervalEXT = de::function_cast<decltype(wglSwapIntervalEXT)>
(QOpenGLContext::currentContext()->getProcAddress("wglSwapIntervalEXT"));
}
#endif

#ifdef DENG_X11
Expand Down Expand Up @@ -286,6 +296,36 @@ QOpenGLExtension_NV_framebuffer_multisample_coverage *GLInfo::NV_framebuffer_mul
return info.d->NV_framebuffer_multisample_coverage.get();
}

void GLInfo::setSwapInterval(int interval)
{
DENG2_ASSERT(info.d->inited);

#if defined (WIN32)
if (extensions().Windows_EXT_swap_control)
{
info.d->wglSwapIntervalEXT(interval);
}
#endif

#if defined (MACOSX)
{
CGLContextObj context = CGLGetCurrentContext();
DENG2_ASSERT(context != nullptr);
if (context)
{
GLint params[1] = { interval };
CGLSetParameter(context, kCGLCPSwapInterval, params);
}
}
#endif

#if defined (Q_WS_X11)
{
//setXSwapInterval(on? 1 : 0);
}
#endif
}

GLInfo::Extensions const &GLInfo::extensions()
{
DENG2_ASSERT(info.d->inited);
Expand Down

0 comments on commit 2a5fc99

Please sign in to comment.