src/video/x11/SDL_x11opengl.c
changeset 6393 a773384edf20
parent 6382 64d54101773a
child 6522 edacce9402fb
     1.1 --- a/src/video/x11/SDL_x11opengl.c	Sat Aug 11 10:15:59 2012 -0700
     1.2 +++ b/src/video/x11/SDL_x11opengl.c	Sun Aug 12 11:16:24 2012 -0700
     1.3 @@ -484,7 +484,13 @@
     1.4      XWindowAttributes xattr;
     1.5      XVisualInfo v, *vinfo;
     1.6      int n;
     1.7 -    GLXContext context = NULL;
     1.8 +    GLXContext context = NULL, share_context;
     1.9 +
    1.10 +    if (_this->gl_config.share_with_current_context) {
    1.11 +        share_context = (GLXContext)(_this->current_glctx);
    1.12 +    } else {
    1.13 +        share_context = NULL;
    1.14 +    }
    1.15  
    1.16      /* We do this to create a clean separation between X and GLX errors. */
    1.17      XSync(display, False);
    1.18 @@ -493,9 +499,12 @@
    1.19      v.visualid = XVisualIDFromVisual(xattr.visual);
    1.20      vinfo = XGetVisualInfo(display, VisualScreenMask | VisualIDMask, &v, &n);
    1.21      if (vinfo) {
    1.22 -        if (_this->gl_config.major_version < 3) {
    1.23 +        if (_this->gl_config.major_version < 3 &&
    1.24 +            _this->gl_config.profile_mask == 0 &&
    1.25 +            _this->gl_config.flags == 0) {
    1.26 +            /* Create legacy context */
    1.27              context =
    1.28 -                _this->gl_data->glXCreateContext(display, vinfo, NULL, True);
    1.29 +                _this->gl_data->glXCreateContext(display, vinfo, share_context, True);
    1.30          } else {
    1.31              /* If we want a GL 3.0 context or later we need to get a temporary
    1.32                 context to grab the new context creation function */
    1.33 @@ -505,7 +514,7 @@
    1.34                  SDL_SetError("Could not create GL context");
    1.35                  return NULL;
    1.36              } else {
    1.37 -	        /* max 8 attributes plus terminator */
    1.38 +                /* max 8 attributes plus terminator */
    1.39                  int attribs[9] = {
    1.40                      GLX_CONTEXT_MAJOR_VERSION_ARB,
    1.41                      _this->gl_config.major_version,
    1.42 @@ -513,21 +522,21 @@
    1.43                      _this->gl_config.minor_version,
    1.44                      0
    1.45                  };
    1.46 -		int iattr = 4;
    1.47 +                int iattr = 4;
    1.48  
    1.49 -		/* SDL profile bits match GLX profile bits */
    1.50 -		if( _this->gl_config.profile_mask != 0 ) {
    1.51 -		    attribs[iattr++] = GLX_CONTEXT_PROFILE_MASK_ARB;
    1.52 -		    attribs[iattr++] = _this->gl_config.profile_mask;
    1.53 -		}
    1.54 +                /* SDL profile bits match GLX profile bits */
    1.55 +                if( _this->gl_config.profile_mask != 0 ) {
    1.56 +                    attribs[iattr++] = GLX_CONTEXT_PROFILE_MASK_ARB;
    1.57 +                    attribs[iattr++] = _this->gl_config.profile_mask;
    1.58 +                }
    1.59  
    1.60 -		/* SDL flags match GLX flags */
    1.61 -		if( _this->gl_config.flags != 0 ) {
    1.62 -		    attribs[iattr++] = GLX_CONTEXT_FLAGS_ARB;
    1.63 -		    attribs[iattr++] = _this->gl_config.flags;
    1.64 -		}
    1.65 +                /* SDL flags match GLX flags */
    1.66 +                if( _this->gl_config.flags != 0 ) {
    1.67 +                    attribs[iattr++] = GLX_CONTEXT_FLAGS_ARB;
    1.68 +                    attribs[iattr++] = _this->gl_config.flags;
    1.69 +                }
    1.70  
    1.71 -		attribs[iattr++] = 0;
    1.72 +                attribs[iattr++] = 0;
    1.73  
    1.74                  /* Get a pointer to the context creation function for GL 3.0 */
    1.75                  PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribs =
    1.76 @@ -568,7 +577,7 @@
    1.77                          context =
    1.78                              glXCreateContextAttribs(display,
    1.79                                                      framebuffer_config[0],
    1.80 -                                                    NULL, True, attribs);
    1.81 +                                                    share_context, True, attribs);
    1.82                          _this->gl_data->glXDestroyContext(display,
    1.83                                                            temp_context);
    1.84                      }