Skip to content

Commit

Permalink
Quartz driver OpenGL updates:
Browse files Browse the repository at this point in the history
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().
  • Loading branch information
icculus committed Nov 22, 2005
1 parent 7f5b03c commit 5e504d5
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 18 deletions.
65 changes: 47 additions & 18 deletions src/video/quartz/SDL_QuartzGL.m
Expand Up @@ -168,32 +168,61 @@ void QZ_TearDownOpenGL (_THIS) {
/* SDL OpenGL functions */

int QZ_GL_LoadLibrary (_THIS, const char *location) {
this->gl_config.driver_loaded = 1;
return 0;
}
CFURLRef bundleURL;
CFStringRef cfstr;

void* QZ_GL_GetProcAddress (_THIS, const char *proc) {
if ( gl_context != NULL ) {
SDL_SetError("OpenGL context already created");
return -1;
}

/* We may want to cache the bundleRef at some point */
CFBundleRef bundle;
CFURLRef bundleURL = CFURLCreateWithFileSystemPath (kCFAllocatorDefault,
CFSTR("/System/Library/Frameworks/OpenGL.framework"), kCFURLPOSIXPathStyle, true);
if (opengl_bundle != NULL)
CFRelease(opengl_bundle);

CFStringRef functionName = CFStringCreateWithCString
(kCFAllocatorDefault, proc, kCFStringEncodingASCII);
opengl_bundle = NULL;
this->gl_config.driver_loaded = 0;

if (location == NULL)
location = "/System/Library/Frameworks/OpenGL.framework";

void *function;
cfstr = CFStringCreateWithCString(kCFAllocatorDefault, location,
kCFStringEncodingUTF8);
if (cfstr == NULL) {
SDL_OutOfMemory();
return -1;
}

bundle = CFBundleCreate (kCFAllocatorDefault, bundleURL);
assert (bundle != NULL);
bundleURL = CFURLCreateWithFileSystemPath (kCFAllocatorDefault,
cfstr, kCFURLPOSIXPathStyle, true);

function = CFBundleGetFunctionPointerForName (bundle, functionName);
CFRelease(cfstr);

if (bundleURL == NULL) {
SDL_OutOfMemory();
return -1;
}

CFRelease ( bundleURL );
CFRelease ( functionName );
CFRelease ( bundle );
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) {
CFStringRef funcName = CFStringCreateWithCString
(kCFAllocatorDefault, proc, kCFStringEncodingASCII);

return function;
void *func = CFBundleGetFunctionPointerForName(opengl_bundle, funcName);
CFRelease (funcName);
return func;
}

int QZ_GL_GetAttribute (_THIS, SDL_GLattr attrib, int* value) {
Expand Down
2 changes: 2 additions & 0 deletions src/video/quartz/SDL_QuartzVideo.h
Expand Up @@ -117,6 +117,7 @@ typedef struct SDL_PrivateVideoData {
Sint16 yuv_width, yuv_height;
CGrafPtr yuv_port;

CFBundleRef opengl_bundle; /* dynamically loaded OpenGL library. */
} SDL_PrivateVideoData;

#define _THIS SDL_VideoDevice *this
Expand Down Expand Up @@ -154,6 +155,7 @@ typedef struct SDL_PrivateVideoData {
#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 {
Expand Down
6 changes: 6 additions & 0 deletions src/video/quartz/SDL_QuartzVideo.m
Expand Up @@ -1489,6 +1489,12 @@ static void QZ_VideoQuit (_THIS) {

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) */
Expand Down

0 comments on commit 5e504d5

Please sign in to comment.