Commit 93d2b832 authored by Ryan C. Gordon's avatar Ryan C. Gordon

Added support for GLX_EXT_swap_control, and cleaned up some other extensions.

This allows the Nvidia Linux drivers to use SDL_GL_SetSwapInterval(0).
parent d05ada52
...@@ -138,6 +138,9 @@ X11_GL_LoadLibrary(_THIS, const char *path) ...@@ -138,6 +138,9 @@ X11_GL_LoadLibrary(_THIS, const char *path)
_this->gl_data->glXSwapBuffers = _this->gl_data->glXSwapBuffers =
(void (*)(Display *, GLXDrawable)) (void (*)(Display *, GLXDrawable))
X11_GL_GetProcAddress(_this, "glXSwapBuffers"); X11_GL_GetProcAddress(_this, "glXSwapBuffers");
_this->gl_data->glXQueryDrawable =
(void (*)(Display*,GLXDrawable,int,unsigned int*))
X11_GL_GetProcAddress(_this, "glXQueryDrawable");
if (!_this->gl_data->glXChooseVisual || if (!_this->gl_data->glXChooseVisual ||
!_this->gl_data->glXCreateContext || !_this->gl_data->glXCreateContext ||
...@@ -254,22 +257,28 @@ X11_GL_InitExtensions(_THIS) ...@@ -254,22 +257,28 @@ X11_GL_InitExtensions(_THIS)
extensions = NULL; extensions = NULL;
} }
/* Check for SGI_swap_control */ /* Check for GLX_EXT_swap_control */
if (HasExtension("GLX_SGI_swap_control", extensions)) { if (HasExtension("GLX_EXT_swap_control", extensions)) {
_this->gl_data->glXSwapIntervalSGI = _this->gl_data->glXSwapIntervalEXT =
(int (*)(int)) X11_GL_GetProcAddress(_this, "glXSwapIntervalSGI"); (void (*)(Display*,GLXDrawable,int))
X11_GL_GetProcAddress(_this, "glXSwapIntervalEXT");
} }
/* Check for GLX_MESA_swap_control */ /* Check for GLX_MESA_swap_control */
if (HasExtension("GLX_MESA_swap_control", extensions)) { if (HasExtension("GLX_MESA_swap_control", extensions)) {
_this->gl_data->glXSwapIntervalMESA = _this->gl_data->glXSwapIntervalMESA =
(GLint(*)(unsigned)) X11_GL_GetProcAddress(_this, (int(*)(int)) X11_GL_GetProcAddress(_this, "glXSwapIntervalMESA");
"glXSwapIntervalMESA");
_this->gl_data->glXGetSwapIntervalMESA = _this->gl_data->glXGetSwapIntervalMESA =
(GLint(*)(void)) X11_GL_GetProcAddress(_this, (int(*)(void)) X11_GL_GetProcAddress(_this,
"glXGetSwapIntervalMESA"); "glXGetSwapIntervalMESA");
} }
/* Check for GLX_SGI_swap_control */
if (HasExtension("GLX_SGI_swap_control", extensions)) {
_this->gl_data->glXSwapIntervalSGI =
(int (*)(int)) X11_GL_GetProcAddress(_this, "glXSwapIntervalSGI");
}
/* Check for GLX_EXT_visual_rating */ /* Check for GLX_EXT_visual_rating */
if (HasExtension("GLX_EXT_visual_rating", extensions)) { if (HasExtension("GLX_EXT_visual_rating", extensions)) {
_this->gl_data->HAS_GLX_EXT_visual_rating = SDL_TRUE; _this->gl_data->HAS_GLX_EXT_visual_rating = SDL_TRUE;
...@@ -506,12 +515,11 @@ X11_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context) ...@@ -506,12 +515,11 @@ X11_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
} }
/* /*
0 is a valid argument to glxSwapIntervalMESA and setting it to 0 0 is a valid argument to glxSwapInterval(MESA|EXT) and setting it to 0
with the MESA version of the extension will undo the effect of a will undo the effect of a previous call with a value that is greater
previous call with a value that is greater than zero (or at least than zero (or at least that is what the docs say). OTOH, 0 is an invalid
that is what the FM says. OTOH, 0 is an invalid argument to argument to glxSwapIntervalSGI and it returns an error if you call it
glxSwapIntervalSGI and it returns an error if you call it with 0 as with 0 as an argument.
an argument.
*/ */
static int swapinterval = -1; static int swapinterval = -1;
...@@ -520,7 +528,15 @@ X11_GL_SetSwapInterval(_THIS, int interval) ...@@ -520,7 +528,15 @@ X11_GL_SetSwapInterval(_THIS, int interval)
{ {
int status; int status;
if (_this->gl_data->glXSwapIntervalMESA) { if (_this->gl_data->glXSwapIntervalEXT) {
Display *display = ((SDL_VideoData *) _this->driverdata)->display;
const SDL_WindowData *windowdata = (SDL_WindowData *)
_this->current_glwin->driverdata;
Window drawable = windowdata->xwindow;
_this->gl_data->glXSwapIntervalEXT(display, drawable, interval);
status = 0; /* always succeeds, apparently. */
swapinterval = interval;
} else if (_this->gl_data->glXSwapIntervalMESA) {
status = _this->gl_data->glXSwapIntervalMESA(interval); status = _this->gl_data->glXSwapIntervalMESA(interval);
if (status != 0) { if (status != 0) {
SDL_SetError("glxSwapIntervalMESA failed"); SDL_SetError("glxSwapIntervalMESA failed");
...@@ -546,7 +562,16 @@ X11_GL_SetSwapInterval(_THIS, int interval) ...@@ -546,7 +562,16 @@ X11_GL_SetSwapInterval(_THIS, int interval)
int int
X11_GL_GetSwapInterval(_THIS) X11_GL_GetSwapInterval(_THIS)
{ {
if (_this->gl_data->glXGetSwapIntervalMESA) { if (_this->gl_data->glXSwapIntervalEXT) {
Display *display = ((SDL_VideoData *) _this->driverdata)->display;
const SDL_WindowData *windowdata = (SDL_WindowData *)
_this->current_glwin->driverdata;
Window drawable = windowdata->xwindow;
unsigned int value = 0;
_this->gl_data->glXQueryDrawable(display, drawable,
GLX_SWAP_INTERVAL_EXT, &value);
return (int) value;
} else if (_this->gl_data->glXGetSwapIntervalMESA) {
return _this->gl_data->glXGetSwapIntervalMESA(); return _this->gl_data->glXGetSwapIntervalMESA();
} else { } else {
return swapinterval; return swapinterval;
......
...@@ -31,26 +31,17 @@ struct SDL_GLDriverData ...@@ -31,26 +31,17 @@ struct SDL_GLDriverData
{ {
SDL_bool HAS_GLX_EXT_visual_rating; SDL_bool HAS_GLX_EXT_visual_rating;
void *(*glXGetProcAddress) (const GLubyte * procName); void *(*glXGetProcAddress) (const GLubyte*);
XVisualInfo *(*glXChooseVisual) (Display*,int,int*);
XVisualInfo *(*glXChooseVisual) GLXContext (*glXCreateContext) (Display*,XVisualInfo*,GLXContext,Bool);
(Display * dpy, int screen, int *attribList); void (*glXDestroyContext) (Display*, GLXContext);
Bool(*glXMakeCurrent) (Display*,GLXDrawable,GLXContext);
GLXContext(*glXCreateContext) void (*glXSwapBuffers) (Display*, GLXDrawable);
(Display * dpy, XVisualInfo * vis, GLXContext shareList, Bool direct); void (*glXQueryDrawable) (Display*,GLXDrawable,int,unsigned int*);
void (*glXSwapIntervalEXT) (Display*,GLXDrawable,int);
void (*glXDestroyContext) int (*glXSwapIntervalSGI) (int);
(Display * dpy, GLXContext ctx); int (*glXSwapIntervalMESA) (int);
int (*glXGetSwapIntervalMESA) (void);
Bool(*glXMakeCurrent)
(Display * dpy, GLXDrawable drawable, GLXContext ctx);
void (*glXSwapBuffers)
(Display * dpy, GLXDrawable drawable);
int (*glXSwapIntervalSGI) (int interval);
GLint(*glXSwapIntervalMESA) (unsigned interval);
GLint(*glXGetSwapIntervalMESA) (void);
}; };
/* OpenGL functions */ /* OpenGL functions */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment