Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Workaround some Windows OpenGL drivers mishandling wglMakeCurrent().
Browse files Browse the repository at this point in the history
You should be able to do wglMakeCurrent(NULL, NULL), according to MSDN, since
the first parameter is ignored if the second is NULL, but this causes problems
on some drivers, so make sure we always have a valid HDC in the first
parameter (and exit early if we already have no current context in the
NULL, NULL case).
  • Loading branch information
icculus committed Jul 31, 2013
1 parent ce3a539 commit 7e681bd
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/video/windows/SDL_windowsopengl.c
Expand Up @@ -22,6 +22,7 @@

#if SDL_VIDEO_DRIVER_WINDOWS

#include "SDL_assert.h"
#include "SDL_windowsvideo.h"

/* WGL implementation of SDL OpenGL support */
Expand Down Expand Up @@ -407,7 +408,7 @@ WIN_GL_ChoosePixelFormatARB(_THIS, int *iAttribs, float *fAttribs)
&matching);
}

_this->gl_data->wglMakeCurrent(NULL, NULL);
_this->gl_data->wglMakeCurrent(hdc, NULL);
_this->gl_data->wglDeleteContext(hglrc);
}
ReleaseDC(hwnd, hdc);
Expand Down Expand Up @@ -622,11 +623,22 @@ WIN_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
return SDL_SetError("OpenGL not initialized");
}

if (window) {
hdc = ((SDL_WindowData *) window->driverdata)->hdc;
} else {
hdc = NULL;
/* sanity check that higher level handled this. */
SDL_assert(window || (!window && !context));

/* Some Windows drivers freak out if hdc is NULL, even when context is
NULL, against spec. Since hdc is _supposed_ to be ignored if context
is NULL, we either use the current GL window, or do nothing if we
already have no current context. */
if (!window) {
window = SDL_GL_GetCurrentWindow();
if (!window) {
SDL_assert(SDL_GL_GetCurrentContext() == NULL);
return 0; /* already done. */
}
}

hdc = ((SDL_WindowData *) window->driverdata)->hdc;
if (!_this->gl_data->wglMakeCurrent(hdc, (HGLRC) context)) {
return WIN_SetError("wglMakeCurrent()");
}
Expand Down

0 comments on commit 7e681bd

Please sign in to comment.