src/video/x11/SDL_x11opengl.c
changeset 9330 26eb20aad02f
parent 8967 8ca9ce569f65
child 9354 5709598d628a
equal deleted inserted replaced
9329:64bb8e49c6a6 9330:26eb20aad02f
   371     if (HasExtension("GLX_SGI_swap_control", extensions)) {
   371     if (HasExtension("GLX_SGI_swap_control", extensions)) {
   372         _this->gl_data->glXSwapIntervalSGI =
   372         _this->gl_data->glXSwapIntervalSGI =
   373             (int (*)(int)) X11_GL_GetProcAddress(_this, "glXSwapIntervalSGI");
   373             (int (*)(int)) X11_GL_GetProcAddress(_this, "glXSwapIntervalSGI");
   374     }
   374     }
   375 
   375 
       
   376     /* Check for GLX_ARB_create_context */
       
   377     if (HasExtension("GLX_ARB_create_context", extensions)) {
       
   378         _this->gl_data->glXCreateContextAttribsARB =
       
   379             (GLXContext (*)(Display*,GLXFBConfig,GLXContext,Bool,const int *))
       
   380                 X11_GL_GetProcAddress(_this, "glXCreateContextAttribsARB");
       
   381         _this->gl_data->glXChooseFBConfig =
       
   382             (GLXFBConfig *(*)(Display *, int, const int *, int *))
       
   383                 X11_GL_GetProcAddress(_this, "glXChooseFBConfig");
       
   384     }
       
   385 
   376     /* Check for GLX_EXT_visual_rating */
   386     /* Check for GLX_EXT_visual_rating */
   377     if (HasExtension("GLX_EXT_visual_rating", extensions)) {
   387     if (HasExtension("GLX_EXT_visual_rating", extensions)) {
   378         _this->gl_data->HAS_GLX_EXT_visual_rating = SDL_TRUE;
   388         _this->gl_data->HAS_GLX_EXT_visual_rating = SDL_TRUE;
   379     }
   389     }
   380 
   390 
   574         ((SDL_DisplayData *) SDL_GetDisplayForWindow(window)->driverdata)->screen;
   584         ((SDL_DisplayData *) SDL_GetDisplayForWindow(window)->driverdata)->screen;
   575     XWindowAttributes xattr;
   585     XWindowAttributes xattr;
   576     XVisualInfo v, *vinfo;
   586     XVisualInfo v, *vinfo;
   577     int n;
   587     int n;
   578     GLXContext context = NULL, share_context;
   588     GLXContext context = NULL, share_context;
   579     PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribs = NULL;
       
   580 
   589 
   581     if (_this->gl_config.share_with_current_context) {
   590     if (_this->gl_config.share_with_current_context) {
   582         share_context = (GLXContext)SDL_GL_GetCurrentContext();
   591         share_context = (GLXContext)SDL_GL_GetCurrentContext();
   583     } else {
   592     } else {
   584         share_context = NULL;
   593         share_context = NULL;
   599             _this->gl_config.flags == 0) {
   608             _this->gl_config.flags == 0) {
   600             /* Create legacy context */
   609             /* Create legacy context */
   601             context =
   610             context =
   602                 _this->gl_data->glXCreateContext(display, vinfo, share_context, True);
   611                 _this->gl_data->glXCreateContext(display, vinfo, share_context, True);
   603         } else {
   612         } else {
   604             /* If we want a GL 3.0 context or later we need to get a temporary
   613             /* max 8 attributes plus terminator */
   605                context to grab the new context creation function */
   614             int attribs[9] = {
   606             GLXContext temp_context =
   615                 GLX_CONTEXT_MAJOR_VERSION_ARB,
   607                 _this->gl_data->glXCreateContext(display, vinfo, NULL, True);
   616                 _this->gl_config.major_version,
   608             if (temp_context) {
   617                 GLX_CONTEXT_MINOR_VERSION_ARB,
   609                 /* max 8 attributes plus terminator */
   618                 _this->gl_config.minor_version,
   610                 int attribs[9] = {
   619                 0
   611                     GLX_CONTEXT_MAJOR_VERSION_ARB,
   620             };
   612                     _this->gl_config.major_version,
   621             int iattr = 4;
   613                     GLX_CONTEXT_MINOR_VERSION_ARB,
   622 
   614                     _this->gl_config.minor_version,
   623             /* SDL profile bits match GLX profile bits */
   615                     0
   624             if( _this->gl_config.profile_mask != 0 ) {
   616                 };
   625                 attribs[iattr++] = GLX_CONTEXT_PROFILE_MASK_ARB;
   617                 int iattr = 4;
   626                 attribs[iattr++] = _this->gl_config.profile_mask;
   618 
   627             }
   619                 /* SDL profile bits match GLX profile bits */
   628 
   620                 if( _this->gl_config.profile_mask != 0 ) {
   629             /* SDL flags match GLX flags */
   621                     attribs[iattr++] = GLX_CONTEXT_PROFILE_MASK_ARB;
   630             if( _this->gl_config.flags != 0 ) {
   622                     attribs[iattr++] = _this->gl_config.profile_mask;
   631                 attribs[iattr++] = GLX_CONTEXT_FLAGS_ARB;
   623                 }
   632                 attribs[iattr++] = _this->gl_config.flags;
   624 
   633             }
   625                 /* SDL flags match GLX flags */
   634 
   626                 if( _this->gl_config.flags != 0 ) {
   635             attribs[iattr++] = 0;
   627                     attribs[iattr++] = GLX_CONTEXT_FLAGS_ARB;
   636 
   628                     attribs[iattr++] = _this->gl_config.flags;
   637             /* Get a pointer to the context creation function for GL 3.0 */
   629                 }
   638             if (!_this->gl_data->glXCreateContextAttribsARB) {
   630 
   639                 SDL_SetError("OpenGL 3.0 and later are not supported by this system");
   631                 attribs[iattr++] = 0;
   640             } else {
   632 
   641                 int glxAttribs[64];
   633                 /* Get a pointer to the context creation function for GL 3.0 */
   642 
   634                 glXCreateContextAttribs =
   643                 /* Create a GL 3.x context */
   635                     (PFNGLXCREATECONTEXTATTRIBSARBPROC) _this->gl_data->
   644                 GLXFBConfig *framebuffer_config = NULL;
   636                     glXGetProcAddress((GLubyte *)
   645                 int fbcount = 0;
   637                                       "glXCreateContextAttribsARB");
   646 
   638                 if (!glXCreateContextAttribs) {
   647                 X11_GL_GetAttributes(_this,display,screen,glxAttribs,64,SDL_TRUE);
   639                     SDL_SetError("GL 3.x is not supported");
   648 
   640                     context = temp_context;
   649                 if (!_this->gl_data->glXChooseFBConfig
       
   650                     || !(framebuffer_config =
       
   651                         _this->gl_data->glXChooseFBConfig(display,
       
   652                                           DefaultScreen(display), glxAttribs,
       
   653                                           &fbcount))) {
       
   654                     SDL_SetError("No good framebuffers found. OpenGL 3.0 and later unavailable");
   641                 } else {
   655                 } else {
   642                     int glxAttribs[64];
   656                     context = _this->gl_data->glXCreateContextAttribsARB(display,
   643 
       
   644                     /* Create a GL 3.x context */
       
   645                     GLXFBConfig *framebuffer_config = NULL;
       
   646                     int fbcount = 0;
       
   647                     GLXFBConfig *(*glXChooseFBConfig) (Display * disp,
       
   648                                                        int screen,
       
   649                                                        const int *attrib_list,
       
   650                                                        int *nelements);
       
   651 
       
   652                     glXChooseFBConfig =
       
   653                         (GLXFBConfig *
       
   654                          (*)(Display *, int, const int *,
       
   655                              int *)) _this->gl_data->
       
   656                         glXGetProcAddress((GLubyte *) "glXChooseFBConfig");
       
   657 
       
   658                     X11_GL_GetAttributes(_this,display,screen,glxAttribs,64,SDL_TRUE);
       
   659 
       
   660                     if (!glXChooseFBConfig
       
   661                         || !(framebuffer_config =
       
   662                              glXChooseFBConfig(display,
       
   663                                                DefaultScreen(display), glxAttribs,
       
   664                                                &fbcount))) {
       
   665                         SDL_SetError
       
   666                             ("No good framebuffers found. GL 3.x disabled");
       
   667                         context = temp_context;
       
   668                     } else {
       
   669                         context =
       
   670                             glXCreateContextAttribs(display,
       
   671                                                     framebuffer_config[0],
   657                                                     framebuffer_config[0],
   672                                                     share_context, True, attribs);
   658                                                     share_context, True, attribs);
   673                         _this->gl_data->glXDestroyContext(display,
       
   674                                                           temp_context);
       
   675                     }
       
   676                 }
   659                 }
   677             }
   660             }
   678         }
   661         }
   679         X11_XFree(vinfo);
   662         X11_XFree(vinfo);
   680     }
   663     }