changeset 1181:49d3efec6651

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().
author Ryan C. Gordon <icculus@icculus.org>
date Tue, 22 Nov 2005 08:21:39 +0000
parents bdcb8bb4c831
children e8e8dcb68e7a
files src/video/quartz/SDL_QuartzGL.m src/video/quartz/SDL_QuartzVideo.h src/video/quartz/SDL_QuartzVideo.m
diffstat 3 files changed, 58 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/src/video/quartz/SDL_QuartzGL.m	Tue Nov 22 07:10:07 2005 +0000
+++ b/src/video/quartz/SDL_QuartzGL.m	Tue Nov 22 08:21:39 2005 +0000
@@ -168,32 +168,61 @@
 /* SDL OpenGL functions */
 
 int    QZ_GL_LoadLibrary    (_THIS, const char *location) {
-    this->gl_config.driver_loaded = 1;
-    return 0;
+    CFURLRef bundleURL;
+    CFStringRef cfstr;
+
+    if ( gl_context != NULL ) {
+        SDL_SetError("OpenGL context already created");
+        return -1;
+    }
+
+    if (opengl_bundle != NULL)
+        CFRelease(opengl_bundle);
+
+    opengl_bundle = NULL;
+    this->gl_config.driver_loaded = 0;
+
+    if (location == NULL)
+        location = "/System/Library/Frameworks/OpenGL.framework";
+
+    cfstr = CFStringCreateWithCString(kCFAllocatorDefault, location,
+                                      kCFStringEncodingUTF8);
+    if (cfstr == NULL) {
+        SDL_OutOfMemory();
+        return -1;
+    }
+
+    bundleURL = CFURLCreateWithFileSystemPath (kCFAllocatorDefault,
+                        cfstr, kCFURLPOSIXPathStyle, true);
+
+    CFRelease(cfstr);
+
+    if (bundleURL == NULL) {
+        SDL_OutOfMemory();
+        return -1;
+    }
+
+    opengl_bundle = CFBundleCreate (kCFAllocatorDefault, bundleURL);
+
+    CFRelease(bundleURL);
+
+    if (opengl_bundle != NULL) {
+        this->gl_config.driver_loaded = 1;
+        return 0;
+    }
+
+    /* not exactly descriptive, but okay... */
+    SDL_SetError("Could not load OpenGL library");
+    return -1;
 }
 
 void*  QZ_GL_GetProcAddress (_THIS, const char *proc) {
-
-    /* We may want to cache the bundleRef at some point */
-    CFBundleRef bundle;
-    CFURLRef bundleURL = CFURLCreateWithFileSystemPath (kCFAllocatorDefault,
-                                                        CFSTR("/System/Library/Frameworks/OpenGL.framework"), kCFURLPOSIXPathStyle, true);
-
-    CFStringRef functionName = CFStringCreateWithCString
+    CFStringRef funcName = CFStringCreateWithCString
         (kCFAllocatorDefault, proc, kCFStringEncodingASCII);
 
-    void *function;
-
-    bundle = CFBundleCreate (kCFAllocatorDefault, bundleURL);
-    assert (bundle != NULL);
-
-    function = CFBundleGetFunctionPointerForName (bundle, functionName);
-
-    CFRelease ( bundleURL );
-    CFRelease ( functionName );
-    CFRelease ( bundle );
-
-    return function;
+    void *func = CFBundleGetFunctionPointerForName(opengl_bundle, funcName);
+    CFRelease (funcName);
+    return func;
 }
 
 int    QZ_GL_GetAttribute   (_THIS, SDL_GLattr attrib, int* value) {
--- a/src/video/quartz/SDL_QuartzVideo.h	Tue Nov 22 07:10:07 2005 +0000
+++ b/src/video/quartz/SDL_QuartzVideo.h	Tue Nov 22 08:21:39 2005 +0000
@@ -117,6 +117,7 @@
     Sint16                  yuv_width, yuv_height;
     CGrafPtr                yuv_port;
 
+    CFBundleRef opengl_bundle;    /* dynamically loaded OpenGL library. */
 } SDL_PrivateVideoData;
 
 #define _THIS    SDL_VideoDevice *this
@@ -154,6 +155,7 @@
 #define current_buffer (this->hidden->current_buffer)
 #define quit_thread (this->hidden->quit_thread)
 #define system_version (this->hidden->system_version)
+#define opengl_bundle (this->hidden->opengl_bundle)
 
 /* grab states - the input is in one of these states */
 enum {
--- a/src/video/quartz/SDL_QuartzVideo.m	Tue Nov 22 07:10:07 2005 +0000
+++ b/src/video/quartz/SDL_QuartzVideo.m	Tue Nov 22 08:21:39 2005 +0000
@@ -1489,6 +1489,12 @@
     
     QZ_UnsetVideoMode (this);
     CGPaletteRelease (palette);
+
+    if (opengl_bundle) {
+        CFRelease(opengl_bundle);
+        opengl_bundle = NULL;
+    }
+    this->gl_config.driver_loaded = 0;
 }
 
 #if 0 /* Not used (apparently, it's really slow) */