Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add swap interval control to QtGame. There's no longer any need to re…
…start to change vsync settings. Refs #2815.
- Loading branch information
Showing
11 changed files
with
162 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#include "swapinterval.h" | ||
#include "lib/framework/wzglobal.h" | ||
#include "lib/framework/opengl.h" | ||
|
||
#if defined(WZ_WS_X11) | ||
|
||
#include <GL/glxew.h> | ||
// X11 polution | ||
#ifdef Status | ||
#undef Status | ||
#endif | ||
#ifdef CursorShape | ||
#undef CursorShape | ||
#endif | ||
#ifdef Bool | ||
#undef Bool | ||
#endif | ||
|
||
#include <QtGui/QX11Info> | ||
#include <QtOpenGL/QGLWidget> | ||
|
||
|
||
void setSwapInterval(QGLWidget const &glWidget, int * interval) | ||
{ | ||
QGLContext const &context = *glWidget.context(); | ||
QX11Info const &xinfo = glWidget.x11Info(); | ||
if (GLXEW_EXT_swap_control) | ||
{ | ||
unsigned clampedInterval; | ||
if (*interval < 0) | ||
*interval = 0; | ||
glXSwapIntervalEXT(xinfo.display(), glWidget.winId(), *interval); | ||
glXQueryDrawable(xinfo.display(), glWidget.winId(), GLX_SWAP_INTERVAL_EXT, &clampedInterval); | ||
*interval = clampedInterval; | ||
} | ||
else if (xinfo.display() && strstr(glXQueryExtensionsString(xinfo.display(), xinfo.screen()), "GLX_MESA_swap_control")) | ||
{ | ||
typedef int (* PFNGLXSWAPINTERVALMESAPROC)(unsigned); | ||
typedef int (* PFNGLXGETSWAPINTERVALMESAPROC)(void); | ||
PFNGLXSWAPINTERVALMESAPROC glXSwapIntervalMESA = (PFNGLXSWAPINTERVALMESAPROC) context.getProcAddress("glXSwapIntervalMESA"); | ||
PFNGLXGETSWAPINTERVALMESAPROC glXGetSwapIntervalMESA = (PFNGLXGETSWAPINTERVALMESAPROC) context.getProcAddress("glXGetSwapIntervalMESA"); | ||
|
||
if (glXSwapIntervalMESA && glXGetSwapIntervalMESA) | ||
{ | ||
if (*interval < 0) | ||
*interval = 0; | ||
glXSwapIntervalMESA(*interval); | ||
*interval = glXGetSwapIntervalMESA(); | ||
} | ||
} | ||
else if (GLXEW_SGI_swap_control) | ||
{ | ||
if (*interval < 1) | ||
*interval = 1; | ||
if (glXSwapIntervalSGI(*interval)) | ||
{ | ||
// Error, revert to default | ||
*interval = 1; | ||
glXSwapIntervalSGI(1); | ||
} | ||
} | ||
else | ||
{ | ||
*interval = -1; | ||
} | ||
} | ||
|
||
#elif defined(WZ_WS_WIN) | ||
#include <GL/wglew.h> | ||
#include <QtOpenGL/QGLWidget> | ||
|
||
void setSwapInterval(QGLWidget const &, int * interval) | ||
{ | ||
if (WGLEW_EXT_swap_control) | ||
{ | ||
if (*interval < 0) | ||
*interval = 0; | ||
wglSwapIntervalEXT(*interval); | ||
*interval = wglGetSwapIntervalEXT(); | ||
} | ||
else | ||
{ | ||
*interval = -1; | ||
} | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#ifndef QTGAME_SWAPINTERVAL_H | ||
#define QTGAME_SWAPINTERVAL_H | ||
|
||
class QGLWidget; | ||
extern void setSwapInterval(QGLWidget const &glWidget, int * interval); | ||
|
||
#endif // QTGAME_SWAPINTERVAL_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#import "swapinterval.h" | ||
#import "lib/framework/wzglobal.h" | ||
|
||
#ifdef WZ_OS_MAC | ||
|
||
#import <AppKit/NSOpenGL.h> | ||
|
||
void setSwapInterval(QGLWidget const &, int * interval) | ||
{ | ||
NSOpenGLContext *context = [NSOpenGLContext currentContext]; | ||
if (*interval >= 0) | ||
{ | ||
[context setValues:interval forParameter:NSOpenGLCPSwapInterval]; | ||
} | ||
[context getValues:interval forParameter:NSOpenGLCPSwapInterval]; | ||
} | ||
|
||
#endif // WZ_OS_MAC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters