|
From: Elias N. <eli...@us...> - 2003-09-29 11:58:58
|
Update of /cvsroot/java-game-lib/LWJGL/src/native/common In directory sc8-pr-cvs1:/tmp/cvs-serv17295/common Modified Files: extgl.cpp Log Message: Index: extgl.cpp CVS Browser: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/java-game-lib/LWJGL/src/native/common/extgl.cpp =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/native/common/extgl.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- extgl.cpp 29 Sep 2003 09:26:20 -0000 1.4 +++ extgl.cpp 29 Sep 2003 11:58:35 -0000 1.5 @@ -1286,7 +1286,8 @@ #endif #ifdef _AGL -CFBundleRef gBundleRefOpenGL = NULL; +CFBundleRef opengl_bundle_ref = NULL; +CFBundleRef agl_bundle_ref = NULL; #endif #define EXTGL_SANITY_CHECK(e,h,x) if (extgl_error) { \ @@ -1319,13 +1320,14 @@ #ifdef _AGL // ------------------------- -OSStatus aglInitEntryPoints (void) +static CFBundleRef loadBundle(const Str255 frameworkName) { OSStatus err = noErr; - const Str255 frameworkName = "\pOpenGL.framework"; FSRefParam fileRefParam; FSRef fileRef; CFURLRef bundleURLOpenGL; + CFBundleRef bundle_ref; + memset(&fileRefParam, 0, sizeof(fileRefParam)); memset(&fileRef, 0, sizeof(fileRef)); fileRefParam.ioNamePtr = frameworkName; @@ -1336,8 +1338,10 @@ err = FindFolder (kSystemDomain, kFrameworksFolderType, false, &fileRefParam.ioVRefNum, &fileRefParam.ioDirID); if (noErr != err) { - DebugStr ("\pCould not find frameworks folder"); - return err; +#ifdef _DEBUG + printf("Could not find frameworks folder\n"); +#endif + return NULL; } // make FSRef for folder @@ -1350,7 +1354,7 @@ #ifdef _DEBUG printf("Could make FSref to frameworks folder\n"); #endif - return err; + return NULL; } // create URL to folder @@ -1359,58 +1363,40 @@ if (!bundleURLOpenGL) { #ifdef _DEBUG - printf("Could create OpenGL Framework bundle URL\n"); + printf("Could create framework URL\n"); #endif - return paramErr; + return NULL; } - // create ref to GL's bundle - // - gBundleRefOpenGL = CFBundleCreate (kCFAllocatorDefault,bundleURLOpenGL); - if (!gBundleRefOpenGL) + bundle_ref = CFBundleCreate(kCFAllocatorDefault,bundleURLOpenGL); + CFRelease (bundleURLOpenGL); + if (bundle_ref == NULL) { #ifdef _DEBUG - printf("Could not create OpenGL Framework bundle\n"); + printf("Could not load framework\n"); #endif - return paramErr; + return NULL; } - // release created bundle - // - CFRelease (bundleURLOpenGL); - // if the code was successfully loaded, look for our function. - if (!CFBundleLoadExecutable (gBundleRefOpenGL)) + if (!CFBundleLoadExecutable(bundle_ref)) { #ifdef _DEBUG printf("Could not load MachO executable\n"); #endif - return paramErr; + CFRelease(bundle_ref); + return NULL; } - return err; + return bundle_ref; } - -static void aglDellocEntryPoints (void) +static void aglUnloadFramework(CFBundleRef f) { - if (gBundleRefOpenGL != NULL) - { - // unload the bundle's code. - CFBundleUnloadExecutable (gBundleRefOpenGL); - CFRelease (gBundleRefOpenGL); - gBundleRefOpenGL = NULL; - } + CFBundleUnloadExecutable(f); + CFRelease(f); } - -static void * aglGetProcAddress (char * pszProc) -{ - CFStringRef str = CFStringCreateWithCStringNoCopy(NULL, pszProc, kCFStringEncodingUTF8, kCFAllocatorNull); - void *func_pointer = CFBundleGetFunctionPointerForName(gBundleRefOpenGL, str); - CFRelease(str); - return func_pointer; -} #endif /* getProcAddress */ @@ -1456,14 +1442,19 @@ #endif #ifdef _AGL - void *t = aglGetProcAddress(name); - if (t == NULL) { + CFStringRef str = CFStringCreateWithCStringNoCopy(NULL, name, kCFStringEncodingUTF8, kCFAllocatorNull); + void *func_pointer = CFBundleGetFunctionPointerForName(opengl_bundle_ref, str); + if (func_pointer == NULL) { + func_pointer = CFBundleGetFunctionPointerForName(agl_bundle_ref, str); + if (func_pointer == NULL) { #ifdef _DEBUG - printf("Could not locate symbol %s\n", name); + printf("Could not locate symbol %s\n", name); #endif - extgl_error = true; + extgl_error = true; + } } - return t; + CFRelease(str); + return func_pointer; #endif } @@ -3298,6 +3289,20 @@ return true; } +#ifdef _AGL +bool extgl_Open(void) { + opengl_bundle_ref = loadBundle("\pOpenGL.framework"); + if (opengl_bundle_ref == NULL) + return false; + agl_bundle_ref = loadBundle("\pAGL.framework"); + if (agl_bundle_ref == NULL) { + aglUnloadFramework(opengl_bundle_ref); + return false; + } + return true; +} +#endif + #ifdef _X11 bool extgl_Open() { @@ -3313,6 +3318,7 @@ #ifdef _DEBUG printf("Error loading libGLU.so.1: %s\n", dlerror()); #endif + dlclose(lib_gl_handle); return false; } return true; @@ -3329,29 +3335,13 @@ if (lib_gl_handle == NULL) return false; lib_glu_handle = LoadLibrary("glu32.dll"); - if (lib_glu_handle == NULL) - return false; - return true; -} -#endif /* WIN32 */ - -#ifdef _AGL -bool extgl_Open(void) -{ - OSStatus err = aglInitEntryPoints(); - if ( noErr != err ) - { - // if we encountered an error while initializing OpenGL - // we're hosed - return - // + if (lib_glu_handle == NULL) { + FreeLibrary(lib_gl_handle); return false; } - - // open gl framework initialized just fine - // return true; } -#endif /* _AGL */ +#endif /* WIN32 */ void extgl_Close(void) { @@ -3364,7 +3354,8 @@ FreeLibrary(lib_glu_handle); #endif #ifdef _AGL - aglDellocEntryPoints(); + aglUnloadFramework(opengl_bundle_ref); + aglUnloadFramework(agl_bundle_ref); #endif } |