src/video/x11/SDL_x11opengl.c
changeset 11441 f9cf3fb0b2f7
parent 11440 71be1b793327
child 11645 2088cd828335
equal deleted inserted replaced
11440:71be1b793327 11441:f9cf3fb0b2f7
   331 {
   331 {
   332     Display *display = ((SDL_VideoData *) _this->driverdata)->display;
   332     Display *display = ((SDL_VideoData *) _this->driverdata)->display;
   333     const int screen = DefaultScreen(display);
   333     const int screen = DefaultScreen(display);
   334     XVisualInfo *vinfo = NULL;
   334     XVisualInfo *vinfo = NULL;
   335     Window w = 0;
   335     Window w = 0;
   336     GLXContext current_context = 0;
   336     GLXContext prev_ctx = 0;
       
   337     GLXDrawable prev_drawable = 0;
   337     GLXContext context = 0;
   338     GLXContext context = 0;
   338     const char *(*glXQueryExtensionsStringFunc) (Display *, int);
   339     const char *(*glXQueryExtensionsStringFunc) (Display *, int);
   339     const char *extensions;
   340     const char *extensions;
   340 
   341 
   341     vinfo = X11_GL_GetVisual(_this, display, screen);
   342     vinfo = X11_GL_GetVisual(_this, display, screen);
   342     if (vinfo) {
   343     if (vinfo) {
   343         GLXContext (*glXGetCurrentContextFunc) (void) =
   344         GLXContext (*glXGetCurrentContextFunc) (void) =
   344             (GLXContext(*)(void))
   345             (GLXContext(*)(void))
   345                 X11_GL_GetProcAddress(_this, "glXGetCurrentContextFunc");
   346                 X11_GL_GetProcAddress(_this, "glXGetCurrentContext");
   346 
   347 
   347         if (glXGetCurrentContextFunc) {
   348         GLXDrawable (*glXGetCurrentDrawableFunc) (void) =
       
   349             (GLXDrawable(*)(void))
       
   350                 X11_GL_GetProcAddress(_this, "glXGetCurrentDrawable");
       
   351 
       
   352         if (glXGetCurrentContextFunc && glXGetCurrentDrawableFunc) {
   348             XSetWindowAttributes xattr;
   353             XSetWindowAttributes xattr;
   349             current_context = glXGetCurrentContextFunc();
   354             prev_ctx = glXGetCurrentContextFunc();
       
   355             prev_drawable = glXGetCurrentDrawableFunc();
   350 
   356 
   351             xattr.background_pixel = 0;
   357             xattr.background_pixel = 0;
   352             xattr.border_pixel = 0;
   358             xattr.border_pixel = 0;
   353             xattr.colormap =
   359             xattr.colormap =
   354                 X11_XCreateColormap(display, RootWindow(display, screen),
   360                 X11_XCreateColormap(display, RootWindow(display, screen),
   450     }
   456     }
   451 
   457 
   452     if (context) {
   458     if (context) {
   453         _this->gl_data->glXMakeCurrent(display, None, NULL);
   459         _this->gl_data->glXMakeCurrent(display, None, NULL);
   454         _this->gl_data->glXDestroyContext(display, context);
   460         _this->gl_data->glXDestroyContext(display, context);
   455         if (current_context) {
   461         if (prev_ctx && prev_drawable) {
   456             _this->gl_data->glXMakeCurrent(display, w, current_context);
   462             _this->gl_data->glXMakeCurrent(display, prev_drawable, prev_ctx);
   457         }
   463         }
   458     }
   464     }
   459 
   465 
   460     X11_XDestroyWindow(display, w);
   466     X11_XDestroyWindow(display, w);
   461     X11_PumpEvents(_this);
   467     X11_PumpEvents(_this);