Commit 7cfdd8ef authored by Sam Lantinga's avatar Sam Lantinga

I think this fixes bug #261

Make sure that you don't use a wgl function after the context is deleted.

--HG--
branch : SDL-1.2
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/branches/SDL-1.2%402476
parent 35308146
...@@ -109,14 +109,15 @@ static int ExtensionSupported(const char *extension, const char *extensions) ...@@ -109,14 +109,15 @@ static int ExtensionSupported(const char *extension, const char *extensions)
return 0; return 0;
} }
static void Init_WGL_ARB_extensions(_THIS) static int ChoosePixelFormatARB(_THIS, const int *iAttribs, const FLOAT *fAttribs)
{ {
HWND hwnd; HWND hwnd;
HDC hdc; HDC hdc;
HGLRC hglrc; HGLRC hglrc;
int pformat;
const char * (WINAPI *wglGetExtensionsStringARB)(HDC) = 0; const char * (WINAPI *wglGetExtensionsStringARB)(HDC) = 0;
const char *extensions; const char *extensions;
int pformat = 0;
UINT matches = 0;
hwnd = CreateWindow(SDL_Appname, SDL_Appname, WS_POPUP | WS_DISABLED, hwnd = CreateWindow(SDL_Appname, SDL_Appname, WS_POPUP | WS_DISABLED,
0, 0, 10, 10, 0, 0, 10, 10,
...@@ -125,8 +126,7 @@ static void Init_WGL_ARB_extensions(_THIS) ...@@ -125,8 +126,7 @@ static void Init_WGL_ARB_extensions(_THIS)
hdc = GetDC(hwnd); hdc = GetDC(hwnd);
pformat = ChoosePixelFormat(hdc, &GL_pfd); SetPixelFormat(hdc, ChoosePixelFormat(hdc, &GL_pfd), &GL_pfd);
SetPixelFormat(hdc, pformat, &GL_pfd);
hglrc = this->gl_data->wglCreateContext(hdc); hglrc = this->gl_data->wglCreateContext(hdc);
if ( hglrc ) { if ( hglrc ) {
...@@ -144,15 +144,12 @@ static void Init_WGL_ARB_extensions(_THIS) ...@@ -144,15 +144,12 @@ static void Init_WGL_ARB_extensions(_THIS)
this->gl_data->WGL_ARB_pixel_format = 0; this->gl_data->WGL_ARB_pixel_format = 0;
if( ExtensionSupported("WGL_ARB_pixel_format", extensions) ) { if( ExtensionSupported("WGL_ARB_pixel_format", extensions) ) {
this->gl_data->wglChoosePixelFormatARB = BOOL (WINAPI *wglChoosePixelFormatARB)(HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats);
wglChoosePixelFormatARB =
(BOOL (WINAPI *)(HDC, const int *, const FLOAT *, UINT, int *, UINT *)) (BOOL (WINAPI *)(HDC, const int *, const FLOAT *, UINT, int *, UINT *))
this->gl_data->wglGetProcAddress("wglChoosePixelFormatARB"); this->gl_data->wglGetProcAddress("wglChoosePixelFormatARB");
this->gl_data->wglGetPixelFormatAttribivARB = if( wglChoosePixelFormatARB &&
(BOOL (WINAPI *)(HDC, int, int, UINT, const int *, int *)) wglChoosePixelFormatARB(hdc, iAttribs, fAttribs, 1, &pformat, &matches) && pformat ) {
this->gl_data->wglGetProcAddress("wglGetPixelFormatAttribivARB");
if( (this->gl_data->wglChoosePixelFormatARB != NULL) &&
(this->gl_data->wglGetPixelFormatAttribivARB != NULL) ) {
this->gl_data->WGL_ARB_pixel_format = 1; this->gl_data->WGL_ARB_pixel_format = 1;
} }
} }
...@@ -164,6 +161,8 @@ static void Init_WGL_ARB_extensions(_THIS) ...@@ -164,6 +161,8 @@ static void Init_WGL_ARB_extensions(_THIS)
ReleaseDC(hwnd, hdc); ReleaseDC(hwnd, hdc);
DestroyWindow(hwnd); DestroyWindow(hwnd);
WIN_FlushMessageQueue(); WIN_FlushMessageQueue();
return pformat;
} }
#endif /* SDL_VIDEO_OPENGL */ #endif /* SDL_VIDEO_OPENGL */
...@@ -188,14 +187,6 @@ int WIN_GL_SetupWindow(_THIS) ...@@ -188,14 +187,6 @@ int WIN_GL_SetupWindow(_THIS)
} }
} }
for ( i=0; ; ++i ) {
/* Get the window device context for our OpenGL drawing */
GL_hdc = GetDC(SDL_Window);
if ( GL_hdc == NULL ) {
SDL_SetError("Unable to get DC for SDL_Window");
return(-1);
}
/* Set up the pixel format descriptor with our needed format */ /* Set up the pixel format descriptor with our needed format */
SDL_memset(&GL_pfd, 0, sizeof(GL_pfd)); SDL_memset(&GL_pfd, 0, sizeof(GL_pfd));
GL_pfd.nSize = sizeof(GL_pfd); GL_pfd.nSize = sizeof(GL_pfd);
...@@ -223,9 +214,6 @@ int WIN_GL_SetupWindow(_THIS) ...@@ -223,9 +214,6 @@ int WIN_GL_SetupWindow(_THIS)
GL_pfd.cDepthBits = this->gl_config.depth_size; GL_pfd.cDepthBits = this->gl_config.depth_size;
GL_pfd.cStencilBits = this->gl_config.stencil_size; GL_pfd.cStencilBits = this->gl_config.stencil_size;
/* initialize WGL_ARB_pixel_format */
Init_WGL_ARB_extensions(this);
/* setup WGL_ARB_pixel_format attribs */ /* setup WGL_ARB_pixel_format attribs */
iAttr = &iAttribs[0]; iAttr = &iAttribs[0];
...@@ -298,12 +286,18 @@ int WIN_GL_SetupWindow(_THIS) ...@@ -298,12 +286,18 @@ int WIN_GL_SetupWindow(_THIS)
*iAttr = 0; *iAttr = 0;
for ( i=0; ; ++i ) {
/* Get the window device context for our OpenGL drawing */
GL_hdc = GetDC(SDL_Window);
if ( GL_hdc == NULL ) {
SDL_SetError("Unable to get DC for SDL_Window");
return(-1);
}
/* Choose and set the closest available pixel format */ /* Choose and set the closest available pixel format */
if ( !this->gl_data->WGL_ARB_pixel_format || pixel_format = ChoosePixelFormatARB(this, iAttribs, fAttribs);
!this->gl_data->wglChoosePixelFormatARB(GL_hdc, iAttribs, fAttribs, 1, &pixel_format, &matching) || if ( !pixel_format ) {
!matching ) {
pixel_format = ChoosePixelFormat(GL_hdc, &GL_pfd); pixel_format = ChoosePixelFormat(GL_hdc, &GL_pfd);
this->gl_data->WGL_ARB_pixel_format = 0;
} }
if ( !pixel_format ) { if ( !pixel_format ) {
SDL_SetError("No matching GL pixel format available"); SDL_SetError("No matching GL pixel format available");
...@@ -335,6 +329,15 @@ int WIN_GL_SetupWindow(_THIS) ...@@ -335,6 +329,15 @@ int WIN_GL_SetupWindow(_THIS)
} }
gl_active = 1; gl_active = 1;
/* Get the wglGetPixelFormatAttribivARB pointer for the context */
if ( this->gl_data->WGL_ARB_pixel_format ) {
this->gl_data->wglGetPixelFormatAttribivARB =
(BOOL (WINAPI *)(HDC, int, int, UINT, const int *, int *))
this->gl_data->wglGetProcAddress("wglGetPixelFormatAttribivARB");
} else {
this->gl_data->wglGetPixelFormatAttribivARB = NULL;
}
/* Vsync control under Windows. Checking glGetString here is /* Vsync control under Windows. Checking glGetString here is
* somewhat a documented and reliable hack - it was originally * somewhat a documented and reliable hack - it was originally
* as a feature added by mistake, but since so many people rely * as a feature added by mistake, but since so many people rely
...@@ -416,7 +419,7 @@ int WIN_GL_GetAttribute(_THIS, SDL_GLattr attrib, int* value) ...@@ -416,7 +419,7 @@ int WIN_GL_GetAttribute(_THIS, SDL_GLattr attrib, int* value)
return -1; return -1;
} }
if ( this->gl_data->WGL_ARB_pixel_format ) { if ( this->gl_data->wglGetPixelFormatAttribivARB ) {
int wgl_attrib; int wgl_attrib;
switch(attrib) { switch(attrib) {
...@@ -566,7 +569,6 @@ void WIN_GL_UnloadLibrary(_THIS) ...@@ -566,7 +569,6 @@ void WIN_GL_UnloadLibrary(_THIS)
this->gl_data->wglCreateContext = NULL; this->gl_data->wglCreateContext = NULL;
this->gl_data->wglDeleteContext = NULL; this->gl_data->wglDeleteContext = NULL;
this->gl_data->wglMakeCurrent = NULL; this->gl_data->wglMakeCurrent = NULL;
this->gl_data->wglChoosePixelFormatARB = NULL;
this->gl_data->wglGetPixelFormatAttribivARB = NULL; this->gl_data->wglGetPixelFormatAttribivARB = NULL;
this->gl_data->wglSwapIntervalEXT = NULL; this->gl_data->wglSwapIntervalEXT = NULL;
this->gl_data->wglGetSwapIntervalEXT = NULL; this->gl_data->wglGetSwapIntervalEXT = NULL;
......
...@@ -44,10 +44,6 @@ struct SDL_PrivateGLData { ...@@ -44,10 +44,6 @@ struct SDL_PrivateGLData {
BOOL (WINAPI *wglMakeCurrent)(HDC hdc, HGLRC hglrc); BOOL (WINAPI *wglMakeCurrent)(HDC hdc, HGLRC hglrc);
BOOL (WINAPI *wglChoosePixelFormatARB)(HDC hdc, const int *piAttribIList,
const FLOAT *pfAttribFList,
UINT nMaxFormats, int *piFormats,
UINT *nNumFormats);
BOOL (WINAPI *wglGetPixelFormatAttribivARB)(HDC hdc, int iPixelFormat, BOOL (WINAPI *wglGetPixelFormatAttribivARB)(HDC hdc, int iPixelFormat,
int iLayerPlane, int iLayerPlane,
UINT nAttributes, UINT nAttributes,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment