src/video/quartz/SDL_QuartzGL.m
changeset 1181 49d3efec6651
parent 1177 e967ab22e6fd
child 1189 c96b326b90ba
     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) {