Mercurial > sdl-ios-xcode
diff 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 |
line wrap: on
line diff
--- a/src/video/win32/SDL_win32opengl.c Thu Jul 12 05:32:07 2007 +0000 +++ b/src/video/win32/SDL_win32opengl.c Thu Jul 12 06:31:36 2007 +0000 @@ -292,32 +292,11 @@ } static void -WIN_GL_InitExtensions(_THIS) +WIN_GL_InitExtensions(_THIS, HDC hdc) { - HWND hwnd; - HDC hdc; - PIXELFORMATDESCRIPTOR pfd; - int pixel_format; - HGLRC hglrc; const char *(WINAPI * wglGetExtensionsStringARB) (HDC) = 0; const char *extensions; - hwnd = - CreateWindow(SDL_Appname, SDL_Appname, (WS_POPUP | WS_DISABLED), 0, 0, - 10, 10, NULL, NULL, SDL_Instance, NULL); - WIN_PumpEvents(_this); - - hdc = GetDC(hwnd); - - WIN_GL_SetupPixelFormat(_this, &pfd); - pixel_format = ChoosePixelFormat(hdc, &pfd); - SetPixelFormat(hdc, pixel_format, &pfd); - - hglrc = _this->gl_data->wglCreateContext(hdc); - if (hglrc) { - _this->gl_data->wglMakeCurrent(hdc, hglrc); - } - wglGetExtensionsStringARB = (const char *(WINAPI *) (HDC)) _this->gl_data->wglGetProcAddress("wglGetExtensionsStringARB"); if (wglGetExtensionsStringARB) { @@ -350,15 +329,48 @@ WIN_GL_GetProcAddress(_this, "wglSwapIntervalEXT"); _this->gl_data->wglGetSwapIntervalEXT = WIN_GL_GetProcAddress(_this, "wglGetSwapIntervalEXT"); + } else { + _this->gl_data->wglSwapIntervalEXT = NULL; + _this->gl_data->wglGetSwapIntervalEXT = NULL; } +} + +static int +WIN_GL_ChoosePixelFormatARB(_THIS, int *iAttribs, float *fAttribs) +{ + HWND hwnd; + HDC hdc; + HGLRC hglrc; + int pixel_format = 0; + unsigned int matching; + hwnd = + CreateWindow(SDL_Appname, SDL_Appname, (WS_POPUP | WS_DISABLED), 0, 0, + 10, 10, NULL, NULL, SDL_Instance, NULL); + WIN_PumpEvents(_this); + + hdc = GetDC(hwnd); + + hglrc = _this->gl_data->wglCreateContext(hdc); if (hglrc) { + _this->gl_data->wglMakeCurrent(hdc, hglrc); + + WIN_GL_InitExtensions(_this, hdc); + + if (_this->gl_data->WGL_ARB_pixel_format) { + _this->gl_data->wglChoosePixelFormatARB(hdc, iAttribs, fAttribs, + 1, &pixel_format, + &matching); + } + _this->gl_data->wglMakeCurrent(NULL, NULL); _this->gl_data->wglDeleteContext(hglrc); } ReleaseDC(hwnd, hdc); DestroyWindow(hwnd); WIN_PumpEvents(_this); + + return pixel_format; } static int @@ -383,9 +395,6 @@ return -1; } - /* Initialize extensions */ - WIN_GL_InitExtensions(_this); - return 0; } @@ -408,7 +417,6 @@ HDC hdc = ((SDL_WindowData *) window->driverdata)->hdc; PIXELFORMATDESCRIPTOR pfd; int pixel_format; - unsigned int matching; int iAttribs[64]; int *iAttr; float fAttribs[1] = { 0 }; @@ -495,10 +503,8 @@ *iAttr = 0; /* Choose and set the closest available pixel format */ - if (!_this->gl_data->WGL_ARB_pixel_format - || !_this->gl_data->wglChoosePixelFormatARB(hdc, iAttribs, fAttribs, - 1, &pixel_format, - &matching) || !matching) { + pixel_format = WIN_GL_ChoosePixelFormatARB(_this, iAttribs, fAttribs); + if (!pixel_format) { pixel_format = WIN_GL_ChoosePixelFormat(hdc, &pfd); } if (!pixel_format) { @@ -522,8 +528,22 @@ WIN_GL_CreateContext(_THIS, SDL_Window * window) { HDC hdc = ((SDL_WindowData *) window->driverdata)->hdc; + HGLRC context; - return _this->gl_data->wglCreateContext(hdc); + context = _this->gl_data->wglCreateContext(hdc); + if (!context) { + SDL_SetError("Could not create GL context"); + return NULL; + } + + if (WIN_GL_MakeCurrent(_this, window, context) < 0) { + WIN_GL_DeleteContext(_this, context); + return NULL; + } + + WIN_GL_InitExtensions(_this, hdc); + + return context; } int