Quartz driver OpenGL updates:
authorRyan C. Gordon
Tue, 22 Nov 2005 08:21:39 +0000
changeset 118149d3efec6651
parent 1180 bdcb8bb4c831
child 1182 e8e8dcb68e7a
Quartz driver OpenGL updates:

Driver can now open whatever library is specified in SDL_GL_LoadLibrary()
call (previously, it ignored this parameter), and uses the default system
library when NULL is specified.

Also, library is loaded once in SDL_GL_LoadLibrary() and not every call to
SDL_GL_GetProcAddress().
src/video/quartz/SDL_QuartzGL.m
src/video/quartz/SDL_QuartzVideo.h
src/video/quartz/SDL_QuartzVideo.m
     1.1 --- a/src/video/quartz/SDL_QuartzGL.m	Tue Nov 22 07:10:07 2005 +0000
     1.2 +++ b/src/video/quartz/SDL_QuartzGL.m	Tue Nov 22 08:21:39 2005 +0000
     1.3 @@ -168,32 +168,61 @@
     1.4  /* SDL OpenGL functions */
     1.5  
     1.6  int    QZ_GL_LoadLibrary    (_THIS, const char *location) {
     1.7 -    this->gl_config.driver_loaded = 1;
     1.8 -    return 0;
     1.9 +    CFURLRef bundleURL;
    1.10 +    CFStringRef cfstr;
    1.11 +
    1.12 +    if ( gl_context != NULL ) {
    1.13 +        SDL_SetError("OpenGL context already created");
    1.14 +        return -1;
    1.15 +    }
    1.16 +
    1.17 +    if (opengl_bundle != NULL)
    1.18 +        CFRelease(opengl_bundle);
    1.19 +
    1.20 +    opengl_bundle = NULL;
    1.21 +    this->gl_config.driver_loaded = 0;
    1.22 +
    1.23 +    if (location == NULL)
    1.24 +        location = "/System/Library/Frameworks/OpenGL.framework";
    1.25 +
    1.26 +    cfstr = CFStringCreateWithCString(kCFAllocatorDefault, location,
    1.27 +                                      kCFStringEncodingUTF8);
    1.28 +    if (cfstr == NULL) {
    1.29 +        SDL_OutOfMemory();
    1.30 +        return -1;
    1.31 +    }
    1.32 +
    1.33 +    bundleURL = CFURLCreateWithFileSystemPath (kCFAllocatorDefault,
    1.34 +                        cfstr, kCFURLPOSIXPathStyle, true);
    1.35 +
    1.36 +    CFRelease(cfstr);
    1.37 +
    1.38 +    if (bundleURL == NULL) {
    1.39 +        SDL_OutOfMemory();
    1.40 +        return -1;
    1.41 +    }
    1.42 +
    1.43 +    opengl_bundle = CFBundleCreate (kCFAllocatorDefault, bundleURL);
    1.44 +
    1.45 +    CFRelease(bundleURL);
    1.46 +
    1.47 +    if (opengl_bundle != NULL) {
    1.48 +        this->gl_config.driver_loaded = 1;
    1.49 +        return 0;
    1.50 +    }
    1.51 +
    1.52 +    /* not exactly descriptive, but okay... */
    1.53 +    SDL_SetError("Could not load OpenGL library");
    1.54 +    return -1;
    1.55  }
    1.56  
    1.57  void*  QZ_GL_GetProcAddress (_THIS, const char *proc) {
    1.58 -
    1.59 -    /* We may want to cache the bundleRef at some point */
    1.60 -    CFBundleRef bundle;
    1.61 -    CFURLRef bundleURL = CFURLCreateWithFileSystemPath (kCFAllocatorDefault,
    1.62 -                                                        CFSTR("/System/Library/Frameworks/OpenGL.framework"), kCFURLPOSIXPathStyle, true);
    1.63 -
    1.64 -    CFStringRef functionName = CFStringCreateWithCString
    1.65 +    CFStringRef funcName = CFStringCreateWithCString
    1.66          (kCFAllocatorDefault, proc, kCFStringEncodingASCII);
    1.67  
    1.68 -    void *function;
    1.69 -
    1.70 -    bundle = CFBundleCreate (kCFAllocatorDefault, bundleURL);
    1.71 -    assert (bundle != NULL);
    1.72 -
    1.73 -    function = CFBundleGetFunctionPointerForName (bundle, functionName);
    1.74 -
    1.75 -    CFRelease ( bundleURL );
    1.76 -    CFRelease ( functionName );
    1.77 -    CFRelease ( bundle );
    1.78 -
    1.79 -    return function;
    1.80 +    void *func = CFBundleGetFunctionPointerForName(opengl_bundle, funcName);
    1.81 +    CFRelease (funcName);
    1.82 +    return func;
    1.83  }
    1.84  
    1.85  int    QZ_GL_GetAttribute   (_THIS, SDL_GLattr attrib, int* value) {
     2.1 --- a/src/video/quartz/SDL_QuartzVideo.h	Tue Nov 22 07:10:07 2005 +0000
     2.2 +++ b/src/video/quartz/SDL_QuartzVideo.h	Tue Nov 22 08:21:39 2005 +0000
     2.3 @@ -117,6 +117,7 @@
     2.4      Sint16                  yuv_width, yuv_height;
     2.5      CGrafPtr                yuv_port;
     2.6  
     2.7 +    CFBundleRef opengl_bundle;    /* dynamically loaded OpenGL library. */
     2.8  } SDL_PrivateVideoData;
     2.9  
    2.10  #define _THIS    SDL_VideoDevice *this
    2.11 @@ -154,6 +155,7 @@
    2.12  #define current_buffer (this->hidden->current_buffer)
    2.13  #define quit_thread (this->hidden->quit_thread)
    2.14  #define system_version (this->hidden->system_version)
    2.15 +#define opengl_bundle (this->hidden->opengl_bundle)
    2.16  
    2.17  /* grab states - the input is in one of these states */
    2.18  enum {
     3.1 --- a/src/video/quartz/SDL_QuartzVideo.m	Tue Nov 22 07:10:07 2005 +0000
     3.2 +++ b/src/video/quartz/SDL_QuartzVideo.m	Tue Nov 22 08:21:39 2005 +0000
     3.3 @@ -1489,6 +1489,12 @@
     3.4      
     3.5      QZ_UnsetVideoMode (this);
     3.6      CGPaletteRelease (palette);
     3.7 +
     3.8 +    if (opengl_bundle) {
     3.9 +        CFRelease(opengl_bundle);
    3.10 +        opengl_bundle = NULL;
    3.11 +    }
    3.12 +    this->gl_config.driver_loaded = 0;
    3.13  }
    3.14  
    3.15  #if 0 /* Not used (apparently, it's really slow) */