Add swap interval support for SDL 1.2 backend on Windows and Linux.

Refs #3054.
master
safety0ff 2012-01-11 15:46:06 -05:00
parent 96fdff1ca8
commit 358dcb434a
3 changed files with 170 additions and 9 deletions

View File

@ -45,8 +45,8 @@ bool wzActiveWindow(void); ///< Whether application currently has the mouse poin
int wzGetTicks(void); ///< Milliseconds since start of game int wzGetTicks(void); ///< Milliseconds since start of game
void wzFatalDialog(const char *text); ///< Throw up a modal warning dialog void wzFatalDialog(const char *text); ///< Throw up a modal warning dialog
QList<QSize> wzAvailableResolutions(); ///< Get list of available resolutions. QList<QSize> wzAvailableResolutions(); ///< Get list of available resolutions.
void wzSetSwapInterval(bool swap); void wzSetSwapInterval(int swap);
bool wzGetSwapInterval(); int wzGetSwapInterval();
QString wzGetSelection(); QString wzGetSelection();
// Thread related // Thread related

View File

@ -104,12 +104,12 @@ QList<QSize> wzAvailableResolutions()
return WzMainWindow::instance()->availableResolutions(); return WzMainWindow::instance()->availableResolutions();
} }
void wzSetSwapInterval(bool swap) void wzSetSwapInterval(int swap)
{ {
WzMainWindow::instance()->setSwapInterval(swap); WzMainWindow::instance()->setSwapInterval(swap);
} }
bool wzGetSwapInterval() int wzGetSwapInterval()
{ {
return WzMainWindow::instance()->swapInterval() > 0; return WzMainWindow::instance()->swapInterval();
} }

View File

@ -108,16 +108,177 @@ QString wzGetSelection()
return retval; return retval;
} }
void wzSetSwapInterval(bool swap)
#if defined(WZ_WS_X11)
#include <GL/glx.h> // GLXDrawable
// X11 polution
#ifdef Status
#undef Status
#endif // Status
#ifdef CursorShape
#undef CursorShape
#endif // CursorShape
#ifdef Bool
#undef Bool
#endif // Bool
#ifndef GLX_SWAP_INTERVAL_EXT
#define GLX_SWAP_INTERVAL_EXT 0x20F1
#endif // GLX_SWAP_INTERVAL_EXT
// Need this global for use case of only having glXSwapIntervalSGI
static int swapInterval = -1;
void wzSetSwapInterval(int interval)
{ {
// TBD typedef void (* PFNGLXQUERYDRAWABLEPROC) (Display *, GLXDrawable, int, unsigned int *);
typedef void ( * PFNGLXSWAPINTERVALEXTPROC) (Display*, GLXDrawable, int);
typedef int (* PFNGLXGETSWAPINTERVALMESAPROC)(void);
typedef int (* PFNGLXSWAPINTERVALMESAPROC)(unsigned);
typedef int (* PFNGLXSWAPINTERVALSGIPROC) (int);
PFNGLXSWAPINTERVALEXTPROC glXSwapIntervalEXT;
PFNGLXQUERYDRAWABLEPROC glXQueryDrawable;
PFNGLXGETSWAPINTERVALMESAPROC glXGetSwapIntervalMESA;
PFNGLXSWAPINTERVALMESAPROC glXSwapIntervalMESA;
PFNGLXSWAPINTERVALSGIPROC glXSwapIntervalSGI;
if (interval < 0)
interval = 0;
#if GLX_VERSION_1_2
// Hack-ish, but better than not supporting GLX_SWAP_INTERVAL_EXT?
GLXDrawable drawable = glXGetCurrentDrawable();
Display * display = glXGetCurrentDisplay();
glXSwapIntervalEXT = (PFNGLXSWAPINTERVALEXTPROC) SDL_GL_GetProcAddress("glXSwapIntervalEXT");
glXQueryDrawable = (PFNGLXQUERYDRAWABLEPROC) SDL_GL_GetProcAddress("glXQueryDrawable");
if (glXSwapIntervalEXT && glXQueryDrawable && drawable)
{
unsigned clampedInterval;
glXSwapIntervalEXT(display, drawable, interval);
glXQueryDrawable(display, drawable, GLX_SWAP_INTERVAL_EXT, &clampedInterval);
swapInterval = clampedInterval;
return;
}
#endif
glXSwapIntervalMESA = (PFNGLXSWAPINTERVALMESAPROC) SDL_GL_GetProcAddress("glXSwapIntervalMESA");
glXGetSwapIntervalMESA = (PFNGLXGETSWAPINTERVALMESAPROC) SDL_GL_GetProcAddress("glXGetSwapIntervalMESA");
if (glXSwapIntervalMESA && glXGetSwapIntervalMESA)
{
glXSwapIntervalMESA(interval);
swapInterval = glXGetSwapIntervalMESA();
return;
}
glXSwapIntervalSGI = (PFNGLXSWAPINTERVALSGIPROC) SDL_GL_GetProcAddress("glXSwapIntervalSGI");
if (glXSwapIntervalSGI)
{
if (interval < 1)
interval = 1;
if (glXSwapIntervalSGI(interval))
{
// Error, revert to default
swapInterval = 1;
glXSwapIntervalSGI(1);
}
else
{
swapInterval = interval;
}
return;
}
swapInterval = 0;
} }
bool wzGetSwapInterval() int wzGetSwapInterval()
{ {
return false; // TBD if (swapInterval >= 0)
return swapInterval;
typedef void (* PFNGLXQUERYDRAWABLEPROC) (Display *, GLXDrawable, int, unsigned int *);
typedef int (* PFNGLXGETSWAPINTERVALMESAPROC)(void);
typedef int (* PFNGLXSWAPINTERVALSGIPROC) (int);
PFNGLXQUERYDRAWABLEPROC glXQueryDrawable;
PFNGLXGETSWAPINTERVALMESAPROC glXGetSwapIntervalMESA;
PFNGLXSWAPINTERVALSGIPROC glXSwapIntervalSGI;
#if GLX_VERSION_1_2
// Hack-ish, but better than not supporting GLX_SWAP_INTERVAL_EXT?
GLXDrawable drawable = glXGetCurrentDrawable();
Display * display = glXGetCurrentDisplay();
glXQueryDrawable = (PFNGLXQUERYDRAWABLEPROC) SDL_GL_GetProcAddress("glXQueryDrawable");
if (glXQueryDrawable && drawable)
{
unsigned interval;
glXQueryDrawable(display, drawable, GLX_SWAP_INTERVAL_EXT, &interval);
swapInterval = interval;
return swapInterval;
}
#endif
glXGetSwapIntervalMESA = (PFNGLXGETSWAPINTERVALMESAPROC) SDL_GL_GetProcAddress("glXGetSwapIntervalMESA");
if (glXGetSwapIntervalMESA)
{
swapInterval = glXGetSwapIntervalMESA();
return swapInterval;
}
glXSwapIntervalSGI = (PFNGLXSWAPINTERVALSGIPROC) SDL_GL_GetProcAddress("glXSwapIntervalSGI");
if (glXSwapIntervalSGI)
{
swapInterval = 1;
}
else
{
swapInterval = 0;
}
return swapInterval;
} }
#elif defined(WZ_WS_WIN)
void wzSetSwapInterval(int interval)
{
typedef BOOL (WINAPI * PFNWGLSWAPINTERVALEXTPROC) (int);
PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT;
if (interval < 0)
interval = 0;
wglSwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC) SDL_GL_GetProcAddress("wglSwapIntervalEXT");
if (wglSwapIntervalEXT)
wglSwapIntervalEXT(interval);
}
int wzGetSwapInterval()
{
typedef int (WINAPI * PFNWGLGETSWAPINTERVALEXTPROC) (void);
PFNWGLGETSWAPINTERVALEXTPROC wglGetSwapIntervalEXT;
wglGetSwapIntervalEXT = (PFNWGLGETSWAPINTERVALEXTPROC) SDL_GL_GetProcAddress("wglGetSwapIntervalEXT");
if (wglGetSwapIntervalEXT)
return wglGetSwapIntervalEXT();
return 0;
}
#else
void wzSetSwapInterval(int)
{
return;
}
int wzGetSwapInterval()
{
return 0;
}
#endif
QList<QSize> wzAvailableResolutions() QList<QSize> wzAvailableResolutions()
{ {
QList<QSize> list; QList<QSize> list;