diff src/video/wincommon/SDL_wingl.c @ 1736:3b2a92126f4d

Implemented bug #2, 117: Date: Mon, 21 Mar 2005 12:06:14 +0100 From: Per Inge Mathisen Subject: Re: [SDL] Outstanding patches? The patch adds support for setting SDL_GL_SWAP_CONTROL to Windows and X11. In Windows you can also query this enum to check that it is working, or see what the default is - such functionality does not exist in GLX. For more information on the standards implemented: http://oss.sgi.com/projects/ogl-sample/registry/SGI/swap_control.txt http://oss.sgi.com/projects/ogl-sample/registry/EXT/wgl_swap_control.txt
author Sam Lantinga <slouken@libsdl.org>
date Thu, 27 Apr 2006 07:59:16 +0000
parents ce84e28c2c07
children eacc5bc01d1c
line wrap: on
line diff
--- a/src/video/wincommon/SDL_wingl.c	Wed Apr 26 23:17:39 2006 +0000
+++ b/src/video/wincommon/SDL_wingl.c	Thu Apr 27 07:59:16 2006 +0000
@@ -177,6 +177,7 @@
 	int iAttribs[64];
 	int *iAttr;
 	float fAttribs[1] = { 0 };
+	const char *wglext;
 
 	/* load the gl driver from a default path */
 	if ( ! this->gl_config.driver_loaded ) {
@@ -323,7 +324,25 @@
 		SDL_SetError("Unable to create GL context");
 		return(-1);
 	}
+	if ( WIN_GL_MakeCurrent(this) < 0 ) {
+		return(-1);
+	}
 	gl_active = 1;
+
+	/* Vsync control under Windows.  Checking glGetString here is
+	 * somewhat a documented and reliable hack - it was originally
+	 * as a feature added by mistake, but since so many people rely
+	 * on it, it will not be removed.  strstr should be safe here.*/
+	wglext = (const char *)this->glGetString(GL_EXTENSIONS);
+	if ( !SDL_strstr(wglext, "WGL_EXT_swap_control") ) {
+		this->gl_data->wglSwapIntervalEXT = NULL;
+		this->gl_data->wglGetSwapIntervalEXT = NULL;
+	}
+	if ( this->gl_config.swap_control >= 0 ) {
+		if ( this->gl_data->wglSwapIntervalEXT ) {
+			this->gl_data->wglSwapIntervalEXT(this->gl_config.swap_control);
+		}
+	}
 #else
 	SDL_SetError("WIN driver not configured with OpenGL");
 #endif
@@ -423,6 +442,12 @@
 		    case SDL_GL_MULTISAMPLESAMPLES:
 			wgl_attrib = WGL_SAMPLES_ARB;
 			break;
+		    case SDL_GL_SWAP_CONTROL:
+			if ( this->gl_data->wglGetSwapIntervalEXT ) {
+				return this->gl_data->wglGetSwapIntervalEXT();
+			} else {
+				return -1;
+			}
 		    default:
 			return(-1);
 		}
@@ -509,6 +534,8 @@
 		this->gl_data->wglMakeCurrent = NULL;
 		this->gl_data->wglChoosePixelFormatARB = NULL;
 		this->gl_data->wglGetPixelFormatAttribivARB = NULL;
+		this->gl_data->wglSwapIntervalEXT = NULL;
+		this->gl_data->wglGetSwapIntervalEXT = NULL;
 
 		this->gl_config.dll_handle = NULL;
 		this->gl_config.driver_loaded = 0;
@@ -547,6 +574,10 @@
 		GetProcAddress(handle, "wglDeleteContext");
 	this->gl_data->wglMakeCurrent = (BOOL (WINAPI *)(HDC, HGLRC))
 		GetProcAddress(handle, "wglMakeCurrent");
+	this->gl_data->wglSwapIntervalEXT = (void (WINAPI *)(int))
+		GetProcAddress(handle, "wglSwapIntervalEXT");
+	this->gl_data->wglGetSwapIntervalEXT = (int (WINAPI *)(void))
+		GetProcAddress(handle, "wglGetSwapIntervalEXT");
 
 	if ( (this->gl_data->wglGetProcAddress == NULL) ||
 	     (this->gl_data->wglCreateContext == NULL) ||