int X11_GL_CreateContext(_THIS) { int retval; #if SDL_VIDEO_OPENGL_GLX XSync( SDL_Display, False ); glx_context = this->gl_data->glXCreateContext(GFX_Display, glx_visualinfo, NULL, True); XSync( GFX_Display, False ); if ( glx_context == NULL ) { SDL_SetError("Could not create GL context"); return(-1); } if ( X11_GL_MakeCurrent(this) < 0 ) { return(-1); } gl_active = 1; if ( !glXExtensionSupported(this, "GLX_SGI_swap_control") ) { this->gl_data->glXSwapIntervalSGI = NULL; } if ( !glXExtensionSupported(this, "GLX_MESA_swap_control") ) { this->gl_data->glXSwapIntervalMESA = NULL; } if ( !glXExtensionSupported(this, "GLX_EXT_swap_control") ) { this->gl_data->glXSwapIntervalEXT = NULL; } if ( this->gl_config.swap_control >= 0 ) { int rc = -1; if ( this->gl_data->glXSwapIntervalEXT ) { rc = this->gl_data->glXSwapIntervalEXT(GFX_Display, SDL_Window, this->gl_config.swap_control); } else if ( this->gl_data->glXSwapIntervalMESA ) { rc = this->gl_data->glXSwapIntervalMESA(this->gl_config.swap_control); } else if ( this->gl_data->glXSwapIntervalSGI ) { rc = this->gl_data->glXSwapIntervalSGI(this->gl_config.swap_control); } if (rc == 0) { this->gl_data->swap_interval = this->gl_config.swap_control; } } #else SDL_SetError("X11 driver not configured with OpenGL"); #endif if ( gl_active ) { retval = 0; } else { retval = -1; } return(retval); }
int X11_GL_CreateContext(_THIS) { int retval; #if SDL_VIDEO_OPENGL_GLX /* We do this to create a clean separation between X and GLX errors. */ XSync( SDL_Display, False ); glx_context = this->gl_data->glXCreateContext(GFX_Display, glx_visualinfo, NULL, True); XSync( GFX_Display, False ); if ( glx_context == NULL ) { SDL_SetError("Could not create GL context"); return(-1); } if ( X11_GL_MakeCurrent(this) < 0 ) { return(-1); } gl_active = 1; if ( !glXExtensionSupported(this, "GLX_SGI_swap_control") ) { this->gl_data->glXSwapIntervalSGI = NULL; } if ( !glXExtensionSupported(this, "GLX_MESA_swap_control") ) { this->gl_data->glXSwapIntervalMESA = NULL; this->gl_data->glXGetSwapIntervalMESA = NULL; } if ( this->gl_config.swap_control >= 0 ) { if ( this->gl_data->glXSwapIntervalMESA ) { this->gl_data->glXSwapIntervalMESA(this->gl_config.swap_control); } else if ( this->gl_data->glXSwapIntervalSGI ) { this->gl_data->glXSwapIntervalSGI(this->gl_config.swap_control); } } #else SDL_SetError("X11 driver not configured with OpenGL"); #endif if ( gl_active ) { retval = 0; } else { retval = -1; } return(retval); }
SDL_GLContext X11_GL_CreateContext(_THIS, SDL_Window * window) { SDL_WindowData *data = (SDL_WindowData *) window->driverdata; Display *display = data->videodata->display; int screen = ((SDL_DisplayData *) SDL_GetDisplayForWindow(window)->driverdata)->screen; XWindowAttributes xattr; XVisualInfo v, *vinfo; int n; GLXContext context = NULL, share_context; PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribs = NULL; if (_this->gl_config.share_with_current_context) { share_context = (GLXContext)SDL_GL_GetCurrentContext(); } else { share_context = NULL; } /* We do this to create a clean separation between X and GLX errors. */ XSync(display, False); errorBase = _this->gl_data->errorBase; handler = XSetErrorHandler(X11_GL_CreateContextErrorHandler); XGetWindowAttributes(display, data->xwindow, &xattr); v.screen = screen; v.visualid = XVisualIDFromVisual(xattr.visual); vinfo = XGetVisualInfo(display, VisualScreenMask | VisualIDMask, &v, &n); if (vinfo) { if (_this->gl_config.major_version < 3 && _this->gl_config.profile_mask == 0 && _this->gl_config.flags == 0) { /* Create legacy context */ context = _this->gl_data->glXCreateContext(display, vinfo, share_context, True); } else { /* If we want a GL 3.0 context or later we need to get a temporary context to grab the new context creation function */ GLXContext temp_context = _this->gl_data->glXCreateContext(display, vinfo, NULL, True); if (temp_context) { /* max 8 attributes plus terminator */ int attribs[9] = { GLX_CONTEXT_MAJOR_VERSION_ARB, _this->gl_config.major_version, GLX_CONTEXT_MINOR_VERSION_ARB, _this->gl_config.minor_version, 0 }; int iattr = 4; /* SDL profile bits match GLX profile bits */ if( _this->gl_config.profile_mask != 0 ) { attribs[iattr++] = GLX_CONTEXT_PROFILE_MASK_ARB; attribs[iattr++] = _this->gl_config.profile_mask; } /* SDL flags match GLX flags */ if( _this->gl_config.flags != 0 ) { attribs[iattr++] = GLX_CONTEXT_FLAGS_ARB; attribs[iattr++] = _this->gl_config.flags; } attribs[iattr++] = 0; /* Get a pointer to the context creation function for GL 3.0 */ glXCreateContextAttribs = (PFNGLXCREATECONTEXTATTRIBSARBPROC) _this->gl_data-> glXGetProcAddress((GLubyte *) "glXCreateContextAttribsARB"); if (!glXCreateContextAttribs) { SDL_SetError("GL 3.x is not supported"); context = temp_context; } else { int glxAttribs[64]; /* Create a GL 3.x context */ GLXFBConfig *framebuffer_config = NULL; int fbcount = 0; GLXFBConfig *(*glXChooseFBConfig) (Display * disp, int screen, const int *attrib_list, int *nelements); glXChooseFBConfig = (GLXFBConfig * (*)(Display *, int, const int *, int *)) _this->gl_data-> glXGetProcAddress((GLubyte *) "glXChooseFBConfig"); X11_GL_GetAttributes(_this,display,screen,glxAttribs,64,SDL_TRUE); if (!glXChooseFBConfig || !(framebuffer_config = glXChooseFBConfig(display, DefaultScreen(display), glxAttribs, &fbcount))) { SDL_SetError ("No good framebuffers found. GL 3.x disabled"); context = temp_context; } else { context = glXCreateContextAttribs(display, framebuffer_config[0], share_context, True, attribs); _this->gl_data->glXDestroyContext(display, temp_context); } } } } XFree(vinfo); } XSync(display, False); XSetErrorHandler(handler); if (!context) { SDL_SetError("Could not create GL context"); return NULL; } if (X11_GL_MakeCurrent(_this, window, context) < 0) { X11_GL_DeleteContext(_this, context); return NULL; } return context; }
SDL_GLContext X11_GL_CreateContext(_THIS, SDL_Window * window) { SDL_WindowData *data = (SDL_WindowData *) window->driverdata; Display *display = data->videodata->display; int screen = ((SDL_DisplayData *) window->display->driverdata)->screen; XWindowAttributes xattr; XVisualInfo v, *vinfo; int n; GLXContext context = NULL; /* We do this to create a clean separation between X and GLX errors. */ XSync(display, False); XGetWindowAttributes(display, data->xwindow, &xattr); v.screen = screen; v.visualid = XVisualIDFromVisual(xattr.visual); vinfo = XGetVisualInfo(display, VisualScreenMask | VisualIDMask, &v, &n); if (vinfo) { if (_this->gl_config.major_version < 3) { context = _this->gl_data->glXCreateContext(display, vinfo, NULL, True); } else { /* If we want a GL 3.0 context or later we need to get a temporary context to grab the new context creation function */ GLXContext temp_context = _this->gl_data->glXCreateContext(display, vinfo, NULL, True); if (!temp_context) { SDL_SetError("Could not create GL context"); return NULL; } else { int attribs[] = { GLX_CONTEXT_MAJOR_VERSION_ARB, _this->gl_config.major_version, GLX_CONTEXT_MINOR_VERSION_ARB, _this->gl_config.minor_version, 0 }; /* Get a pointer to the context creation function for GL 3.0 */ PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribs = (PFNGLXCREATECONTEXTATTRIBSARBPROC) _this->gl_data-> glXGetProcAddress((GLubyte *) "glXCreateContextAttribsARB"); if (!glXCreateContextAttribs) { SDL_SetError("GL 3.x is not supported"); context = temp_context; } else { /* Create a GL 3.x context */ GLXFBConfig *framebuffer_config = NULL; int fbcount = 0; GLXFBConfig *(*glXChooseFBConfig) (Display * disp, int screen, const int *attrib_list, int *nelements); glXChooseFBConfig = (GLXFBConfig * (*)(Display *, int, const int *, int *)) _this->gl_data-> glXGetProcAddress((GLubyte *) "glXChooseFBConfig"); if (!glXChooseFBConfig || !(framebuffer_config = glXChooseFBConfig(display, DefaultScreen(display), NULL, &fbcount))) { SDL_SetError ("No good framebuffers found. GL 3.x disabled"); context = temp_context; } else { context = glXCreateContextAttribs(display, framebuffer_config[0], NULL, True, attribs); _this->gl_data->glXDestroyContext(display, temp_context); } } } } XFree(vinfo); } XSync(display, False); if (!context) { SDL_SetError("Could not create GL context"); return NULL; } if (X11_GL_MakeCurrent(_this, window, context) < 0) { X11_GL_DeleteContext(_this, context); return NULL; } return context; }
SDL_GLContext X11_GL_CreateContext(_THIS, SDL_Window * window) { SDL_WindowData *data = (SDL_WindowData *) window->driverdata; Display *display = data->videodata->display; int screen = ((SDL_DisplayData *) SDL_GetDisplayForWindow(window)->driverdata)->screen; XWindowAttributes xattr; XVisualInfo v, *vinfo; int n; GLXContext context = NULL, share_context; if (_this->gl_config.share_with_current_context) { share_context = (GLXContext)SDL_GL_GetCurrentContext(); } else { share_context = NULL; } /* We do this to create a clean separation between X and GLX errors. */ X11_XSync(display, False); errorHandlerOperation = "create GL context"; errorBase = _this->gl_data->errorBase; errorCode = Success; handler = X11_XSetErrorHandler(X11_GL_ErrorHandler); X11_XGetWindowAttributes(display, data->xwindow, &xattr); v.screen = screen; v.visualid = X11_XVisualIDFromVisual(xattr.visual); vinfo = X11_XGetVisualInfo(display, VisualScreenMask | VisualIDMask, &v, &n); if (vinfo) { if (_this->gl_config.major_version < 3 && _this->gl_config.profile_mask == 0 && _this->gl_config.flags == 0) { /* Create legacy context */ context = _this->gl_data->glXCreateContext(display, vinfo, share_context, True); } else { /* max 10 attributes plus terminator */ int attribs[11] = { GLX_CONTEXT_MAJOR_VERSION_ARB, _this->gl_config.major_version, GLX_CONTEXT_MINOR_VERSION_ARB, _this->gl_config.minor_version, 0 }; int iattr = 4; /* SDL profile bits match GLX profile bits */ if( _this->gl_config.profile_mask != 0 ) { attribs[iattr++] = GLX_CONTEXT_PROFILE_MASK_ARB; attribs[iattr++] = _this->gl_config.profile_mask; } /* SDL flags match GLX flags */ if( _this->gl_config.flags != 0 ) { attribs[iattr++] = GLX_CONTEXT_FLAGS_ARB; attribs[iattr++] = _this->gl_config.flags; } /* only set if glx extension is available */ if( _this->gl_data->HAS_GLX_ARB_context_flush_control ) { attribs[iattr++] = GLX_CONTEXT_RELEASE_BEHAVIOR_ARB; attribs[iattr++] = _this->gl_config.release_behavior ? GLX_CONTEXT_RELEASE_BEHAVIOR_FLUSH_ARB : GLX_CONTEXT_RELEASE_BEHAVIOR_NONE_ARB; } attribs[iattr++] = 0; /* Get a pointer to the context creation function for GL 3.0 */ if (!_this->gl_data->glXCreateContextAttribsARB) { SDL_SetError("OpenGL 3.0 and later are not supported by this system"); } else { int glxAttribs[64]; /* Create a GL 3.x context */ GLXFBConfig *framebuffer_config = NULL; int fbcount = 0; X11_GL_GetAttributes(_this,display,screen,glxAttribs,64,SDL_TRUE); if (!_this->gl_data->glXChooseFBConfig || !(framebuffer_config = _this->gl_data->glXChooseFBConfig(display, DefaultScreen(display), glxAttribs, &fbcount))) { SDL_SetError("No good framebuffers found. OpenGL 3.0 and later unavailable"); } else { context = _this->gl_data->glXCreateContextAttribsARB(display, framebuffer_config[0], share_context, True, attribs); X11_XFree(framebuffer_config); } } } X11_XFree(vinfo); } X11_XSync(display, False); X11_XSetErrorHandler(handler); if (!context) { if (errorCode == Success) { SDL_SetError("Could not create GL context"); } return NULL; } if (X11_GL_MakeCurrent(_this, window, context) < 0) { X11_GL_DeleteContext(_this, context); return NULL; } return context; }