x11: Correctly restore previous GL context after sacrificial context is done.
authorRyan C. Gordon <icculus@icculus.org>
Fri, 01 Sep 2017 14:08:09 -0400
changeset 11441f9cf3fb0b2f7
parent 11440 71be1b793327
child 11442 11413fa29401
x11: Correctly restore previous GL context after sacrificial context is done.
src/video/x11/SDL_x11opengl.c
     1.1 --- a/src/video/x11/SDL_x11opengl.c	Fri Sep 01 14:00:11 2017 -0400
     1.2 +++ b/src/video/x11/SDL_x11opengl.c	Fri Sep 01 14:08:09 2017 -0400
     1.3 @@ -333,7 +333,8 @@
     1.4      const int screen = DefaultScreen(display);
     1.5      XVisualInfo *vinfo = NULL;
     1.6      Window w = 0;
     1.7 -    GLXContext current_context = 0;
     1.8 +    GLXContext prev_ctx = 0;
     1.9 +    GLXDrawable prev_drawable = 0;
    1.10      GLXContext context = 0;
    1.11      const char *(*glXQueryExtensionsStringFunc) (Display *, int);
    1.12      const char *extensions;
    1.13 @@ -342,11 +343,16 @@
    1.14      if (vinfo) {
    1.15          GLXContext (*glXGetCurrentContextFunc) (void) =
    1.16              (GLXContext(*)(void))
    1.17 -                X11_GL_GetProcAddress(_this, "glXGetCurrentContextFunc");
    1.18 +                X11_GL_GetProcAddress(_this, "glXGetCurrentContext");
    1.19  
    1.20 -        if (glXGetCurrentContextFunc) {
    1.21 +        GLXDrawable (*glXGetCurrentDrawableFunc) (void) =
    1.22 +            (GLXDrawable(*)(void))
    1.23 +                X11_GL_GetProcAddress(_this, "glXGetCurrentDrawable");
    1.24 +
    1.25 +        if (glXGetCurrentContextFunc && glXGetCurrentDrawableFunc) {
    1.26              XSetWindowAttributes xattr;
    1.27 -            current_context = glXGetCurrentContextFunc();
    1.28 +            prev_ctx = glXGetCurrentContextFunc();
    1.29 +            prev_drawable = glXGetCurrentDrawableFunc();
    1.30  
    1.31              xattr.background_pixel = 0;
    1.32              xattr.border_pixel = 0;
    1.33 @@ -452,8 +458,8 @@
    1.34      if (context) {
    1.35          _this->gl_data->glXMakeCurrent(display, None, NULL);
    1.36          _this->gl_data->glXDestroyContext(display, context);
    1.37 -        if (current_context) {
    1.38 -            _this->gl_data->glXMakeCurrent(display, w, current_context);
    1.39 +        if (prev_ctx && prev_drawable) {
    1.40 +            _this->gl_data->glXMakeCurrent(display, prev_drawable, prev_ctx);
    1.41          }
    1.42      }
    1.43