comparison 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
comparison
equal deleted inserted replaced
1652:dc219ba4cf45 1736:3b2a92126f4d
175 int i; 175 int i;
176 unsigned int matching; 176 unsigned int matching;
177 int iAttribs[64]; 177 int iAttribs[64];
178 int *iAttr; 178 int *iAttr;
179 float fAttribs[1] = { 0 }; 179 float fAttribs[1] = { 0 };
180 const char *wglext;
180 181
181 /* load the gl driver from a default path */ 182 /* load the gl driver from a default path */
182 if ( ! this->gl_config.driver_loaded ) { 183 if ( ! this->gl_config.driver_loaded ) {
183 /* no driver has been loaded, use default (ourselves) */ 184 /* no driver has been loaded, use default (ourselves) */
184 if ( WIN_GL_LoadLibrary(this, NULL) < 0 ) { 185 if ( WIN_GL_LoadLibrary(this, NULL) < 0 ) {
321 GL_hrc = this->gl_data->wglCreateContext(GL_hdc); 322 GL_hrc = this->gl_data->wglCreateContext(GL_hdc);
322 if ( GL_hrc == NULL ) { 323 if ( GL_hrc == NULL ) {
323 SDL_SetError("Unable to create GL context"); 324 SDL_SetError("Unable to create GL context");
324 return(-1); 325 return(-1);
325 } 326 }
327 if ( WIN_GL_MakeCurrent(this) < 0 ) {
328 return(-1);
329 }
326 gl_active = 1; 330 gl_active = 1;
331
332 /* Vsync control under Windows. Checking glGetString here is
333 * somewhat a documented and reliable hack - it was originally
334 * as a feature added by mistake, but since so many people rely
335 * on it, it will not be removed. strstr should be safe here.*/
336 wglext = (const char *)this->glGetString(GL_EXTENSIONS);
337 if ( !SDL_strstr(wglext, "WGL_EXT_swap_control") ) {
338 this->gl_data->wglSwapIntervalEXT = NULL;
339 this->gl_data->wglGetSwapIntervalEXT = NULL;
340 }
341 if ( this->gl_config.swap_control >= 0 ) {
342 if ( this->gl_data->wglSwapIntervalEXT ) {
343 this->gl_data->wglSwapIntervalEXT(this->gl_config.swap_control);
344 }
345 }
327 #else 346 #else
328 SDL_SetError("WIN driver not configured with OpenGL"); 347 SDL_SetError("WIN driver not configured with OpenGL");
329 #endif 348 #endif
330 if ( gl_active ) { 349 if ( gl_active ) {
331 retval = 0; 350 retval = 0;
421 wgl_attrib = WGL_SAMPLE_BUFFERS_ARB; 440 wgl_attrib = WGL_SAMPLE_BUFFERS_ARB;
422 break; 441 break;
423 case SDL_GL_MULTISAMPLESAMPLES: 442 case SDL_GL_MULTISAMPLESAMPLES:
424 wgl_attrib = WGL_SAMPLES_ARB; 443 wgl_attrib = WGL_SAMPLES_ARB;
425 break; 444 break;
445 case SDL_GL_SWAP_CONTROL:
446 if ( this->gl_data->wglGetSwapIntervalEXT ) {
447 return this->gl_data->wglGetSwapIntervalEXT();
448 } else {
449 return -1;
450 }
426 default: 451 default:
427 return(-1); 452 return(-1);
428 } 453 }
429 this->gl_data->wglGetPixelFormatAttribivARB(GL_hdc, pixel_format, 0, 1, &wgl_attrib, value); 454 this->gl_data->wglGetPixelFormatAttribivARB(GL_hdc, pixel_format, 0, 1, &wgl_attrib, value);
430 455
507 this->gl_data->wglCreateContext = NULL; 532 this->gl_data->wglCreateContext = NULL;
508 this->gl_data->wglDeleteContext = NULL; 533 this->gl_data->wglDeleteContext = NULL;
509 this->gl_data->wglMakeCurrent = NULL; 534 this->gl_data->wglMakeCurrent = NULL;
510 this->gl_data->wglChoosePixelFormatARB = NULL; 535 this->gl_data->wglChoosePixelFormatARB = NULL;
511 this->gl_data->wglGetPixelFormatAttribivARB = NULL; 536 this->gl_data->wglGetPixelFormatAttribivARB = NULL;
537 this->gl_data->wglSwapIntervalEXT = NULL;
538 this->gl_data->wglGetSwapIntervalEXT = NULL;
512 539
513 this->gl_config.dll_handle = NULL; 540 this->gl_config.dll_handle = NULL;
514 this->gl_config.driver_loaded = 0; 541 this->gl_config.driver_loaded = 0;
515 } 542 }
516 } 543 }
545 GetProcAddress(handle, "wglCreateContext"); 572 GetProcAddress(handle, "wglCreateContext");
546 this->gl_data->wglDeleteContext = (BOOL (WINAPI *)(HGLRC)) 573 this->gl_data->wglDeleteContext = (BOOL (WINAPI *)(HGLRC))
547 GetProcAddress(handle, "wglDeleteContext"); 574 GetProcAddress(handle, "wglDeleteContext");
548 this->gl_data->wglMakeCurrent = (BOOL (WINAPI *)(HDC, HGLRC)) 575 this->gl_data->wglMakeCurrent = (BOOL (WINAPI *)(HDC, HGLRC))
549 GetProcAddress(handle, "wglMakeCurrent"); 576 GetProcAddress(handle, "wglMakeCurrent");
577 this->gl_data->wglSwapIntervalEXT = (void (WINAPI *)(int))
578 GetProcAddress(handle, "wglSwapIntervalEXT");
579 this->gl_data->wglGetSwapIntervalEXT = (int (WINAPI *)(void))
580 GetProcAddress(handle, "wglGetSwapIntervalEXT");
550 581
551 if ( (this->gl_data->wglGetProcAddress == NULL) || 582 if ( (this->gl_data->wglGetProcAddress == NULL) ||
552 (this->gl_data->wglCreateContext == NULL) || 583 (this->gl_data->wglCreateContext == NULL) ||
553 (this->gl_data->wglDeleteContext == NULL) || 584 (this->gl_data->wglDeleteContext == NULL) ||
554 (this->gl_data->wglMakeCurrent == NULL) ) { 585 (this->gl_data->wglMakeCurrent == NULL) ) {