Mercurial > sdl-ios-xcode
comparison src/video/win32/SDL_win32opengl.c @ 2178:114a541cfae2
Creating a context makes it current, per the documentation.
Applied a variant of the multi-card OpenGL fix from SDL 1.2
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Thu, 12 Jul 2007 06:31:36 +0000 |
parents | abbe2c1dcf0a |
children | 5ed37b16c1a7 |
comparison
equal
deleted
inserted
replaced
2177:4f896c20caf6 | 2178:114a541cfae2 |
---|---|
290 } | 290 } |
291 return SDL_FALSE; | 291 return SDL_FALSE; |
292 } | 292 } |
293 | 293 |
294 static void | 294 static void |
295 WIN_GL_InitExtensions(_THIS) | 295 WIN_GL_InitExtensions(_THIS, HDC hdc) |
296 { | 296 { |
297 HWND hwnd; | |
298 HDC hdc; | |
299 PIXELFORMATDESCRIPTOR pfd; | |
300 int pixel_format; | |
301 HGLRC hglrc; | |
302 const char *(WINAPI * wglGetExtensionsStringARB) (HDC) = 0; | 297 const char *(WINAPI * wglGetExtensionsStringARB) (HDC) = 0; |
303 const char *extensions; | 298 const char *extensions; |
304 | |
305 hwnd = | |
306 CreateWindow(SDL_Appname, SDL_Appname, (WS_POPUP | WS_DISABLED), 0, 0, | |
307 10, 10, NULL, NULL, SDL_Instance, NULL); | |
308 WIN_PumpEvents(_this); | |
309 | |
310 hdc = GetDC(hwnd); | |
311 | |
312 WIN_GL_SetupPixelFormat(_this, &pfd); | |
313 pixel_format = ChoosePixelFormat(hdc, &pfd); | |
314 SetPixelFormat(hdc, pixel_format, &pfd); | |
315 | |
316 hglrc = _this->gl_data->wglCreateContext(hdc); | |
317 if (hglrc) { | |
318 _this->gl_data->wglMakeCurrent(hdc, hglrc); | |
319 } | |
320 | 299 |
321 wglGetExtensionsStringARB = (const char *(WINAPI *) (HDC)) | 300 wglGetExtensionsStringARB = (const char *(WINAPI *) (HDC)) |
322 _this->gl_data->wglGetProcAddress("wglGetExtensionsStringARB"); | 301 _this->gl_data->wglGetProcAddress("wglGetExtensionsStringARB"); |
323 if (wglGetExtensionsStringARB) { | 302 if (wglGetExtensionsStringARB) { |
324 extensions = wglGetExtensionsStringARB(hdc); | 303 extensions = wglGetExtensionsStringARB(hdc); |
348 if (HasExtension("WGL_EXT_swap_control", extensions)) { | 327 if (HasExtension("WGL_EXT_swap_control", extensions)) { |
349 _this->gl_data->wglSwapIntervalEXT = | 328 _this->gl_data->wglSwapIntervalEXT = |
350 WIN_GL_GetProcAddress(_this, "wglSwapIntervalEXT"); | 329 WIN_GL_GetProcAddress(_this, "wglSwapIntervalEXT"); |
351 _this->gl_data->wglGetSwapIntervalEXT = | 330 _this->gl_data->wglGetSwapIntervalEXT = |
352 WIN_GL_GetProcAddress(_this, "wglGetSwapIntervalEXT"); | 331 WIN_GL_GetProcAddress(_this, "wglGetSwapIntervalEXT"); |
353 } | 332 } else { |
354 | 333 _this->gl_data->wglSwapIntervalEXT = NULL; |
334 _this->gl_data->wglGetSwapIntervalEXT = NULL; | |
335 } | |
336 } | |
337 | |
338 static int | |
339 WIN_GL_ChoosePixelFormatARB(_THIS, int *iAttribs, float *fAttribs) | |
340 { | |
341 HWND hwnd; | |
342 HDC hdc; | |
343 HGLRC hglrc; | |
344 int pixel_format = 0; | |
345 unsigned int matching; | |
346 | |
347 hwnd = | |
348 CreateWindow(SDL_Appname, SDL_Appname, (WS_POPUP | WS_DISABLED), 0, 0, | |
349 10, 10, NULL, NULL, SDL_Instance, NULL); | |
350 WIN_PumpEvents(_this); | |
351 | |
352 hdc = GetDC(hwnd); | |
353 | |
354 hglrc = _this->gl_data->wglCreateContext(hdc); | |
355 if (hglrc) { | 355 if (hglrc) { |
356 _this->gl_data->wglMakeCurrent(hdc, hglrc); | |
357 | |
358 WIN_GL_InitExtensions(_this, hdc); | |
359 | |
360 if (_this->gl_data->WGL_ARB_pixel_format) { | |
361 _this->gl_data->wglChoosePixelFormatARB(hdc, iAttribs, fAttribs, | |
362 1, &pixel_format, | |
363 &matching); | |
364 } | |
365 | |
356 _this->gl_data->wglMakeCurrent(NULL, NULL); | 366 _this->gl_data->wglMakeCurrent(NULL, NULL); |
357 _this->gl_data->wglDeleteContext(hglrc); | 367 _this->gl_data->wglDeleteContext(hglrc); |
358 } | 368 } |
359 ReleaseDC(hwnd, hdc); | 369 ReleaseDC(hwnd, hdc); |
360 DestroyWindow(hwnd); | 370 DestroyWindow(hwnd); |
361 WIN_PumpEvents(_this); | 371 WIN_PumpEvents(_this); |
372 | |
373 return pixel_format; | |
362 } | 374 } |
363 | 375 |
364 static int | 376 static int |
365 WIN_GL_Initialize(_THIS) | 377 WIN_GL_Initialize(_THIS) |
366 { | 378 { |
381 | 393 |
382 if (WIN_GL_LoadLibrary(_this, NULL) < 0) { | 394 if (WIN_GL_LoadLibrary(_this, NULL) < 0) { |
383 return -1; | 395 return -1; |
384 } | 396 } |
385 | 397 |
386 /* Initialize extensions */ | |
387 WIN_GL_InitExtensions(_this); | |
388 | |
389 return 0; | 398 return 0; |
390 } | 399 } |
391 | 400 |
392 static void | 401 static void |
393 WIN_GL_Shutdown(_THIS) | 402 WIN_GL_Shutdown(_THIS) |
406 WIN_GL_SetupWindow(_THIS, SDL_Window * window) | 415 WIN_GL_SetupWindow(_THIS, SDL_Window * window) |
407 { | 416 { |
408 HDC hdc = ((SDL_WindowData *) window->driverdata)->hdc; | 417 HDC hdc = ((SDL_WindowData *) window->driverdata)->hdc; |
409 PIXELFORMATDESCRIPTOR pfd; | 418 PIXELFORMATDESCRIPTOR pfd; |
410 int pixel_format; | 419 int pixel_format; |
411 unsigned int matching; | |
412 int iAttribs[64]; | 420 int iAttribs[64]; |
413 int *iAttr; | 421 int *iAttr; |
414 float fAttribs[1] = { 0 }; | 422 float fAttribs[1] = { 0 }; |
415 | 423 |
416 if (WIN_GL_Initialize(_this) < 0) { | 424 if (WIN_GL_Initialize(_this) < 0) { |
493 } | 501 } |
494 | 502 |
495 *iAttr = 0; | 503 *iAttr = 0; |
496 | 504 |
497 /* Choose and set the closest available pixel format */ | 505 /* Choose and set the closest available pixel format */ |
498 if (!_this->gl_data->WGL_ARB_pixel_format | 506 pixel_format = WIN_GL_ChoosePixelFormatARB(_this, iAttribs, fAttribs); |
499 || !_this->gl_data->wglChoosePixelFormatARB(hdc, iAttribs, fAttribs, | 507 if (!pixel_format) { |
500 1, &pixel_format, | |
501 &matching) || !matching) { | |
502 pixel_format = WIN_GL_ChoosePixelFormat(hdc, &pfd); | 508 pixel_format = WIN_GL_ChoosePixelFormat(hdc, &pfd); |
503 } | 509 } |
504 if (!pixel_format) { | 510 if (!pixel_format) { |
505 SDL_SetError("No matching GL pixel format available"); | 511 SDL_SetError("No matching GL pixel format available"); |
506 return -1; | 512 return -1; |
520 | 526 |
521 SDL_GLContext | 527 SDL_GLContext |
522 WIN_GL_CreateContext(_THIS, SDL_Window * window) | 528 WIN_GL_CreateContext(_THIS, SDL_Window * window) |
523 { | 529 { |
524 HDC hdc = ((SDL_WindowData *) window->driverdata)->hdc; | 530 HDC hdc = ((SDL_WindowData *) window->driverdata)->hdc; |
525 | 531 HGLRC context; |
526 return _this->gl_data->wglCreateContext(hdc); | 532 |
533 context = _this->gl_data->wglCreateContext(hdc); | |
534 if (!context) { | |
535 SDL_SetError("Could not create GL context"); | |
536 return NULL; | |
537 } | |
538 | |
539 if (WIN_GL_MakeCurrent(_this, window, context) < 0) { | |
540 WIN_GL_DeleteContext(_this, context); | |
541 return NULL; | |
542 } | |
543 | |
544 WIN_GL_InitExtensions(_this, hdc); | |
545 | |
546 return context; | |
527 } | 547 } |
528 | 548 |
529 int | 549 int |
530 WIN_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context) | 550 WIN_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context) |
531 { | 551 { |