src/video/windows/SDL_windowsopengl.c
changeset 7553 f0091f8eae33
parent 7412 50211a1fd557
child 7559 0dd3b05797f9
equal deleted inserted replaced
7552:463f78515a07 7553:f0091f8eae33
    20 */
    20 */
    21 #include "SDL_config.h"
    21 #include "SDL_config.h"
    22 
    22 
    23 #if SDL_VIDEO_DRIVER_WINDOWS
    23 #if SDL_VIDEO_DRIVER_WINDOWS
    24 
    24 
       
    25 #include "SDL_assert.h"
    25 #include "SDL_windowsvideo.h"
    26 #include "SDL_windowsvideo.h"
    26 
    27 
    27 /* WGL implementation of SDL OpenGL support */
    28 /* WGL implementation of SDL OpenGL support */
    28 
    29 
    29 #if SDL_VIDEO_OPENGL_WGL
    30 #if SDL_VIDEO_OPENGL_WGL
   405             _this->gl_data->wglChoosePixelFormatARB(hdc, iAttribs, fAttribs,
   406             _this->gl_data->wglChoosePixelFormatARB(hdc, iAttribs, fAttribs,
   406                                                     1, &pixel_format,
   407                                                     1, &pixel_format,
   407                                                     &matching);
   408                                                     &matching);
   408         }
   409         }
   409 
   410 
   410         _this->gl_data->wglMakeCurrent(NULL, NULL);
   411         _this->gl_data->wglMakeCurrent(hdc, NULL);
   411         _this->gl_data->wglDeleteContext(hglrc);
   412         _this->gl_data->wglDeleteContext(hglrc);
   412     }
   413     }
   413     ReleaseDC(hwnd, hdc);
   414     ReleaseDC(hwnd, hdc);
   414     DestroyWindow(hwnd);
   415     DestroyWindow(hwnd);
   415     WIN_PumpEvents(_this);
   416     WIN_PumpEvents(_this);
   620 
   621 
   621     if (!_this->gl_data) {
   622     if (!_this->gl_data) {
   622         return SDL_SetError("OpenGL not initialized");
   623         return SDL_SetError("OpenGL not initialized");
   623     }
   624     }
   624 
   625 
   625     if (window) {
   626     /* sanity check that higher level handled this. */
   626         hdc = ((SDL_WindowData *) window->driverdata)->hdc;
   627     SDL_assert(window || (!window && !context));
   627     } else {
   628 
   628         hdc = NULL;
   629     /* Some Windows drivers freak out if hdc is NULL, even when context is
   629     }
   630        NULL, against spec. Since hdc is _supposed_ to be ignored if context
       
   631        is NULL, we either use the current GL window, or do nothing if we
       
   632        already have no current context. */
       
   633     if (!window) {
       
   634         window = SDL_GL_GetCurrentWindow();
       
   635         if (!window) {
       
   636             SDL_assert(SDL_GL_GetCurrentContext() == NULL);
       
   637             return 0;  /* already done. */
       
   638         }
       
   639     }
       
   640 
       
   641     hdc = ((SDL_WindowData *) window->driverdata)->hdc;
   630     if (!_this->gl_data->wglMakeCurrent(hdc, (HGLRC) context)) {
   642     if (!_this->gl_data->wglMakeCurrent(hdc, (HGLRC) context)) {
   631         return WIN_SetError("wglMakeCurrent()");
   643         return WIN_SetError("wglMakeCurrent()");
   632     }
   644     }
   633     return 0;
   645     return 0;
   634 }
   646 }