comparison src/video/wincommon/SDL_wingl.c @ 1656:96c2f89cc7e1 SDL-1.3

SDL-trunk-1.3-merge-1
author Sam Lantinga <slouken@libsdl.org>
date Thu, 27 Apr 2006 09:09:48 +0000
parents ce84e28c2c07
children 14717b52abc0
comparison
equal deleted inserted replaced
1655:59227394023d 1656:96c2f89cc7e1
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 ) {
287 if ( this->gl_config.multisamplesamples ) { 288 if ( this->gl_config.multisamplesamples ) {
288 *iAttr++ = WGL_SAMPLES_ARB; 289 *iAttr++ = WGL_SAMPLES_ARB;
289 *iAttr++ = this->gl_config.multisamplesamples; 290 *iAttr++ = this->gl_config.multisamplesamples;
290 } 291 }
291 292
293 if ( this->gl_config.accelerated >= 0 ) {
294 *iAttr++ = WGL_ACCELERATION_ARB;
295 *iAttr++ = (this->gl_config.accelerated ? WGL_GENERIC_ACCELERATION_ARB : WGL_NO_ACCELERATION_ARB);
296 }
297
292 *iAttr = 0; 298 *iAttr = 0;
293 299
294 /* Choose and set the closest available pixel format */ 300 /* Choose and set the closest available pixel format */
295 if ( !this->gl_data->WGL_ARB_pixel_format || 301 if ( !this->gl_data->WGL_ARB_pixel_format ||
296 !this->gl_data->wglChoosePixelFormatARB(GL_hdc, iAttribs, fAttribs, 1, &pixel_format, &matching) || 302 !this->gl_data->wglChoosePixelFormatARB(GL_hdc, iAttribs, fAttribs, 1, &pixel_format, &matching) ||
321 GL_hrc = this->gl_data->wglCreateContext(GL_hdc); 327 GL_hrc = this->gl_data->wglCreateContext(GL_hdc);
322 if ( GL_hrc == NULL ) { 328 if ( GL_hrc == NULL ) {
323 SDL_SetError("Unable to create GL context"); 329 SDL_SetError("Unable to create GL context");
324 return(-1); 330 return(-1);
325 } 331 }
332 if ( WIN_GL_MakeCurrent(this) < 0 ) {
333 return(-1);
334 }
326 gl_active = 1; 335 gl_active = 1;
336
337 /* Vsync control under Windows. Checking glGetString here is
338 * somewhat a documented and reliable hack - it was originally
339 * as a feature added by mistake, but since so many people rely
340 * on it, it will not be removed. strstr should be safe here.*/
341 wglext = (const char *)this->glGetString(GL_EXTENSIONS);
342 if ( !SDL_strstr(wglext, "WGL_EXT_swap_control") ) {
343 this->gl_data->wglSwapIntervalEXT = NULL;
344 this->gl_data->wglGetSwapIntervalEXT = NULL;
345 }
346 if ( this->gl_config.swap_control >= 0 ) {
347 if ( this->gl_data->wglSwapIntervalEXT ) {
348 this->gl_data->wglSwapIntervalEXT(this->gl_config.swap_control);
349 }
350 }
327 #else 351 #else
328 SDL_SetError("WIN driver not configured with OpenGL"); 352 SDL_SetError("WIN driver not configured with OpenGL");
329 #endif 353 #endif
330 if ( gl_active ) { 354 if ( gl_active ) {
331 retval = 0; 355 retval = 0;
421 wgl_attrib = WGL_SAMPLE_BUFFERS_ARB; 445 wgl_attrib = WGL_SAMPLE_BUFFERS_ARB;
422 break; 446 break;
423 case SDL_GL_MULTISAMPLESAMPLES: 447 case SDL_GL_MULTISAMPLESAMPLES:
424 wgl_attrib = WGL_SAMPLES_ARB; 448 wgl_attrib = WGL_SAMPLES_ARB;
425 break; 449 break;
450 case SDL_GL_ACCELERATED_VISUAL:
451 wgl_attrib = WGL_ACCELERATION_ARB;
452 this->gl_data->wglGetPixelFormatAttribivARB(GL_hdc, pixel_format, 0, 1, &wgl_attrib, value);
453 if ( *value == WGL_NO_ACCELERATION_ARB ) {
454 *value = SDL_FALSE;
455 } else {
456 *value = SDL_TRUE;
457 }
458 return 0;
459 break;
460 case SDL_GL_SWAP_CONTROL:
461 if ( this->gl_data->wglGetSwapIntervalEXT ) {
462 return this->gl_data->wglGetSwapIntervalEXT();
463 } else {
464 return -1;
465 }
426 default: 466 default:
427 return(-1); 467 return(-1);
428 } 468 }
429 this->gl_data->wglGetPixelFormatAttribivARB(GL_hdc, pixel_format, 0, 1, &wgl_attrib, value); 469 this->gl_data->wglGetPixelFormatAttribivARB(GL_hdc, pixel_format, 0, 1, &wgl_attrib, value);
430 470
507 this->gl_data->wglCreateContext = NULL; 547 this->gl_data->wglCreateContext = NULL;
508 this->gl_data->wglDeleteContext = NULL; 548 this->gl_data->wglDeleteContext = NULL;
509 this->gl_data->wglMakeCurrent = NULL; 549 this->gl_data->wglMakeCurrent = NULL;
510 this->gl_data->wglChoosePixelFormatARB = NULL; 550 this->gl_data->wglChoosePixelFormatARB = NULL;
511 this->gl_data->wglGetPixelFormatAttribivARB = NULL; 551 this->gl_data->wglGetPixelFormatAttribivARB = NULL;
552 this->gl_data->wglSwapIntervalEXT = NULL;
553 this->gl_data->wglGetSwapIntervalEXT = NULL;
512 554
513 this->gl_config.dll_handle = NULL; 555 this->gl_config.dll_handle = NULL;
514 this->gl_config.driver_loaded = 0; 556 this->gl_config.driver_loaded = 0;
515 } 557 }
516 } 558 }
545 GetProcAddress(handle, "wglCreateContext"); 587 GetProcAddress(handle, "wglCreateContext");
546 this->gl_data->wglDeleteContext = (BOOL (WINAPI *)(HGLRC)) 588 this->gl_data->wglDeleteContext = (BOOL (WINAPI *)(HGLRC))
547 GetProcAddress(handle, "wglDeleteContext"); 589 GetProcAddress(handle, "wglDeleteContext");
548 this->gl_data->wglMakeCurrent = (BOOL (WINAPI *)(HDC, HGLRC)) 590 this->gl_data->wglMakeCurrent = (BOOL (WINAPI *)(HDC, HGLRC))
549 GetProcAddress(handle, "wglMakeCurrent"); 591 GetProcAddress(handle, "wglMakeCurrent");
592 this->gl_data->wglSwapIntervalEXT = (void (WINAPI *)(int))
593 GetProcAddress(handle, "wglSwapIntervalEXT");
594 this->gl_data->wglGetSwapIntervalEXT = (int (WINAPI *)(void))
595 GetProcAddress(handle, "wglGetSwapIntervalEXT");
550 596
551 if ( (this->gl_data->wglGetProcAddress == NULL) || 597 if ( (this->gl_data->wglGetProcAddress == NULL) ||
552 (this->gl_data->wglCreateContext == NULL) || 598 (this->gl_data->wglCreateContext == NULL) ||
553 (this->gl_data->wglDeleteContext == NULL) || 599 (this->gl_data->wglDeleteContext == NULL) ||
554 (this->gl_data->wglMakeCurrent == NULL) ) { 600 (this->gl_data->wglMakeCurrent == NULL) ) {