src/video/x11/SDL_x11opengl.c
changeset 3057 089a77aebb7d
parent 3013 8cc00819c8d6
child 3100 7dc982143c06
     1.1 --- a/src/video/x11/SDL_x11opengl.c	Sun Feb 08 15:35:06 2009 +0000
     1.2 +++ b/src/video/x11/SDL_x11opengl.c	Mon Feb 09 05:32:12 2009 +0000
     1.3 @@ -65,37 +65,39 @@
     1.4  #define GL_UnloadObject	SDL_UnloadObject
     1.5  #endif
     1.6  
     1.7 -static int X11_GL_InitializeMemory(_THIS);
     1.8 +static void X11_GL_InitExtensions(_THIS);
     1.9  
    1.10  int
    1.11  X11_GL_LoadLibrary(_THIS, const char *path)
    1.12  {
    1.13      void *handle;
    1.14  
    1.15 -    if (_this->gl_config.driver_loaded) {
    1.16 -        /* do not return without reinitializing the function hooks */
    1.17 -        if (path) {
    1.18 -            SDL_SetError("OpenGL library already loaded");
    1.19 -        }
    1.20 -        handle = _this->gl_config.dll_handle;
    1.21 -    } else {
    1.22 -        if (path == NULL) {
    1.23 -            path = SDL_getenv("SDL_OPENGL_LIBRARY");
    1.24 -        }
    1.25 -        if (path == NULL) {
    1.26 -            path = DEFAULT_OPENGL;
    1.27 -        }
    1.28 -        handle = GL_LoadObject(path);
    1.29 -        if (!handle) {
    1.30 -            return -1;
    1.31 -        }
    1.32 -        _this->gl_config.dll_handle = handle;
    1.33 -        SDL_strlcpy(_this->gl_config.driver_path, path,
    1.34 -                    SDL_arraysize(_this->gl_config.driver_path));
    1.35 +    /* Load the OpenGL library */
    1.36 +    if (path == NULL) {
    1.37 +        path = SDL_getenv("SDL_OPENGL_LIBRARY");
    1.38      }
    1.39 -    X11_GL_InitializeMemory(_this);
    1.40 +    if (path == NULL) {
    1.41 +        path = DEFAULT_OPENGL;
    1.42 +    }
    1.43 +    _this->gl_config.dll_handle = SDL_LoadObject(path);
    1.44 +    if (!_this->gl_config.dll_handle) {
    1.45 +        return -1;
    1.46 +    }
    1.47 +    SDL_strlcpy(_this->gl_config.driver_path, path,
    1.48 +                SDL_arraysize(_this->gl_config.driver_path));
    1.49  
    1.50 -    /* Load new function pointers */
    1.51 +    /* Allocate OpenGL memory */
    1.52 +    _this->gl_data =
    1.53 +        (struct SDL_GLDriverData *) SDL_calloc(1,
    1.54 +                                               sizeof(struct
    1.55 +                                                      SDL_GLDriverData));
    1.56 +    if (!_this->gl_data) {
    1.57 +        SDL_OutOfMemory();
    1.58 +        return -1;
    1.59 +    }
    1.60 +
    1.61 +    /* Load function pointers */
    1.62 +    handle = _this->gl_config.dll_handle;
    1.63      _this->gl_data->glXGetProcAddress =
    1.64          (void *(*)(const GLubyte *)) GL_LoadFunction(handle,
    1.65                                                       "glXGetProcAddressARB");
    1.66 @@ -123,7 +125,9 @@
    1.67          return -1;
    1.68      }
    1.69  
    1.70 -    ++_this->gl_config.driver_loaded;
    1.71 +    /* Initialize extensions */
    1.72 +    X11_GL_InitExtensions(_this);
    1.73 +
    1.74      return 0;
    1.75  }
    1.76  
    1.77 @@ -139,16 +143,21 @@
    1.78      return GL_LoadFunction(handle, proc);
    1.79  }
    1.80  
    1.81 -static void
    1.82 +void
    1.83  X11_GL_UnloadLibrary(_THIS)
    1.84  {
    1.85 -    if (_this->gl_config.driver_loaded > 0) {
    1.86 -        if (--_this->gl_config.driver_loaded > 0) {
    1.87 -            return;
    1.88 -        }
    1.89 -        GL_UnloadObject(_this->gl_config.dll_handle);
    1.90 -        _this->gl_config.dll_handle = NULL;
    1.91 -    }
    1.92 +    /* Don't actually unload the library, since it may have registered
    1.93 +     * X11 shutdown hooks, per the notes at:
    1.94 +     * http://dri.sourceforge.net/doc/DRIuserguide.html
    1.95 +     */
    1.96 +#if 0
    1.97 +    GL_UnloadObject(_this->gl_config.dll_handle);
    1.98 +    _this->gl_config.dll_handle = NULL;
    1.99 +#endif
   1.100 +
   1.101 +    /* Free OpenGL memory */
   1.102 +    SDL_free(_this->gl_data);
   1.103 +    _this->gl_data = NULL;
   1.104  }
   1.105  
   1.106  static SDL_bool
   1.107 @@ -254,62 +263,6 @@
   1.108      X11_PumpEvents(_this);
   1.109  }
   1.110  
   1.111 -static int
   1.112 -X11_GL_InitializeMemory(_THIS)
   1.113 -{
   1.114 -    if (_this->gl_data) {
   1.115 -        return 0;
   1.116 -    }
   1.117 -
   1.118 -    _this->gl_data =
   1.119 -        (struct SDL_GLDriverData *) SDL_calloc(1,
   1.120 -                                               sizeof(struct
   1.121 -                                                      SDL_GLDriverData));
   1.122 -    if (!_this->gl_data) {
   1.123 -        SDL_OutOfMemory();
   1.124 -        return -1;
   1.125 -    }
   1.126 -    _this->gl_data->initialized = 0;
   1.127 -
   1.128 -    return 0;
   1.129 -}
   1.130 -
   1.131 -int
   1.132 -X11_GL_Initialize(_THIS)
   1.133 -{
   1.134 -
   1.135 -    if (X11_GL_InitializeMemory(_this) < 0) {
   1.136 -        return -1;
   1.137 -    }
   1.138 -    ++_this->gl_data->initialized;
   1.139 -
   1.140 -    if (X11_GL_LoadLibrary(_this, NULL) < 0) {
   1.141 -        return -1;
   1.142 -    }
   1.143 -
   1.144 -    /* Initialize extensions */
   1.145 -    X11_GL_InitExtensions(_this);
   1.146 -
   1.147 -    return 0;
   1.148 -}
   1.149 -
   1.150 -void
   1.151 -X11_GL_Shutdown(_THIS)
   1.152 -{
   1.153 -    if (!_this->gl_data || (--_this->gl_data->initialized > 0)) {
   1.154 -        return;
   1.155 -    }
   1.156 -
   1.157 -    /* Don't actually unload the library, since it may have registered
   1.158 -     * X11 shutdown hooks, per the notes at:
   1.159 -     * http://dri.sourceforge.net/doc/DRIuserguide.html
   1.160 -     * //X11_GL_UnloadLibrary(_this);
   1.161 -     */
   1.162 -
   1.163 -    SDL_free(_this->gl_data);
   1.164 -    _this->gl_data = NULL;
   1.165 -}
   1.166 -
   1.167  XVisualInfo *
   1.168  X11_GL_GetVisual(_THIS, Display * display, int screen)
   1.169  {