Fixed bug #721
authorSam Lantinga <slouken@libsdl.org>
Fri, 03 Apr 2009 17:19:05 +0000
changeset 3105cdeee9f9b14b
parent 3104 86ea6c073d87
child 3106 3fde47894732
Fixed bug #721

From michalziulek@gmail.com 2009-03-28 07:43:34 (-) [reply]

There is a bug in OpenGL 3.x context creation code.
Function glXGetProcAddress is used directly where it should be:
_this->gl_data->glXGetProcAddress. I have attached patch which fixes this on
x11 and win32. Thanks.
src/video/win32/SDL_win32opengl.c
src/video/x11/SDL_x11opengl.c
     1.1 --- a/src/video/win32/SDL_win32opengl.c	Fri Apr 03 13:35:05 2009 +0000
     1.2 +++ b/src/video/win32/SDL_win32opengl.c	Fri Apr 03 17:19:05 2009 +0000
     1.3 @@ -512,7 +512,7 @@
     1.4              return NULL;
     1.5          }
     1.6                  
     1.7 -        wglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC) wglGetProcAddress("wglCreateContextAttribsARB");
     1.8 +        wglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC) _this->gl_data->wglGetProcAddress("wglCreateContextAttribsARB");
     1.9          if (!wglCreateContextAttribsARB) {
    1.10              SDL_SetError("GL 3.x is not supported");
    1.11              context = temp_context;
    1.12 @@ -525,7 +525,7 @@
    1.13              /* Create the GL 3.x context */
    1.14              context = wglCreateContextAttribsARB(hdc, 0, attribs);
    1.15              /* Delete the GL 2.x context */
    1.16 -            wglDeleteContext(temp_context);
    1.17 +            _this->gl_data->wglDeleteContext(temp_context);
    1.18          }
    1.19      }
    1.20      
     2.1 --- a/src/video/x11/SDL_x11opengl.c	Fri Apr 03 13:35:05 2009 +0000
     2.2 +++ b/src/video/x11/SDL_x11opengl.c	Fri Apr 03 17:19:05 2009 +0000
     2.3 @@ -413,21 +413,24 @@
     2.4                  };
     2.5                                  
     2.6                  /* Get a pointer to the context creation function for GL 3.0 */
     2.7 -                PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribs = (PFNGLXCREATECONTEXTATTRIBSARBPROC)glXGetProcAddress((GLubyte*)"glXCreateContextAttribsARB");
     2.8 +                PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribs = (PFNGLXCREATECONTEXTATTRIBSARBPROC)_this->gl_data->glXGetProcAddress((GLubyte*)"glXCreateContextAttribsARB");
     2.9                  if (!glXCreateContextAttribs) {
    2.10                      SDL_SetError("GL 3.x is not supported");
    2.11                      context = temp_context;
    2.12                  } else {
    2.13 -                    /* Create a GL 3.0 context */
    2.14 +                    /* Create a GL 3.x context */
    2.15                      GLXFBConfig *framebuffer_config = NULL;
    2.16                      int fbcount = 0;                
    2.17 -                    framebuffer_config = glXChooseFBConfig(display, DefaultScreen(display), NULL, &fbcount);
    2.18 -                    if (!framebuffer_config) {
    2.19 -                        SDL_SetError("No good framebuffers found. GL 3.0 disabled");
    2.20 +                    GLXFBConfig* (*glXChooseFBConfig)(Display* disp, int screen, const int* attrib_list, int* nelements);
    2.21 +
    2.22 +                    glXChooseFBConfig = (GLXFBConfig* (*)(Display*, int, const int*, int*))_this->gl_data->glXGetProcAddress((GLubyte*)"glXChooseFBConfig");
    2.23 +
    2.24 +                    if (!glXChooseFBConfig || !(framebuffer_config = glXChooseFBConfig(display, DefaultScreen(display), NULL, &fbcount))) {
    2.25 +                        SDL_SetError("No good framebuffers found. GL 3.x disabled");
    2.26                          context = temp_context;
    2.27                      } else {                                    
    2.28                          context = glXCreateContextAttribs(display, framebuffer_config[0], NULL, True, attribs);
    2.29 -                        glXDestroyContext(display, temp_context);
    2.30 +                        _this->gl_data->glXDestroyContext(display, temp_context);
    2.31                      }
    2.32                  }
    2.33              }