Max 5 API Reference
00001 #include "jit.common.h" 00002 #include "jit.agl.h" 00003 00004 #ifdef MAC_VERSION 00005 00006 CFBundleRef gBundleRefOpenGL = NULL; 00007 CFBundleRef gBundleRefAGL = NULL; 00008 00009 CFBundleRef OpenFrameworkRef (const unsigned char *frameworkName, OSStatus *err); 00010 00011 OSStatus aglInitEntryPoints (void) 00012 { 00013 OSStatus err = noErr; 00014 const Str255 frameworkNameOGL = "\pOpenGL.framework"; 00015 const Str255 frameworkNameAGL = "\pAGL.framework"; 00016 00017 gBundleRefOpenGL = OpenFrameworkRef((const unsigned char *)frameworkNameOGL,&err); 00018 gBundleRefAGL = OpenFrameworkRef((const unsigned char *)frameworkNameAGL,&err); 00019 00020 return err; 00021 } 00022 00023 CFBundleRef OpenFrameworkRef (const unsigned char *frameworkName, OSStatus *err) 00024 { 00025 FSRefParam fileRefParam; 00026 FSRef fileRef; 00027 CFURLRef bundleURLOpenGL; 00028 CFBundleRef bundleRef=NULL; 00029 00030 *err = noErr; 00031 00032 setmem(&fileRefParam, sizeof(fileRefParam), 0); 00033 setmem(&fileRef, sizeof(fileRef), 0); 00034 00035 fileRefParam.ioNamePtr = frameworkName; 00036 fileRefParam.newRef = &fileRef; 00037 00038 // find frameworks directory/folder 00039 *err = FindFolder (kSystemDomain, kFrameworksFolderType, false, 00040 &fileRefParam.ioVRefNum, &fileRefParam.ioDirID); 00041 if (noErr != *err) { 00042 error("jit.gl: could not find frameworks folder for AGL"); 00043 *err = paramErr; 00044 return NULL; 00045 } 00046 00047 // make FSRef for folder 00048 *err = PBMakeFSRefSync (&fileRefParam); 00049 if (noErr != *err) 00050 { 00051 error("jit.gl: could not make FSref to frameworks folder for AGL"); 00052 return NULL; 00053 } 00054 00055 // create URL to folder 00056 bundleURLOpenGL = CFURLCreateFromFSRef (kCFAllocatorDefault, &fileRef); 00057 if (!bundleURLOpenGL) 00058 { 00059 error("jit.gl: could not create OpenGL Framework bundle URL for AGL"); 00060 *err = paramErr; 00061 return NULL; 00062 } 00063 00064 // create ref to GL's bundle 00065 bundleRef = CFBundleCreate (kCFAllocatorDefault, bundleURLOpenGL); 00066 if (!bundleRef) 00067 { 00068 error("jit.gl: could not create OpenGL Framework bundle for AGL"); 00069 *err = paramErr; 00070 return NULL; 00071 } 00072 00073 // release created bundle 00074 CFRelease (bundleURLOpenGL); 00075 00076 // if the code was successfully loaded, look for our function. 00077 if (!CFBundleLoadExecutable (bundleRef)) 00078 { 00079 error("jit.gl: could not load MachO executable for AGL"); 00080 *err = paramErr; 00081 return NULL; 00082 } 00083 00084 return bundleRef; 00085 } 00086 00087 00088 void aglDellocEntryPoints (void) 00089 { 00090 if (gBundleRefOpenGL != NULL) 00091 { 00092 // unload the bundle's code. 00093 CFBundleUnloadExecutable (gBundleRefOpenGL); 00094 CFRelease (gBundleRefOpenGL); 00095 gBundleRefOpenGL = NULL; 00096 } 00097 if (gBundleRefAGL != NULL) 00098 { 00099 // unload the bundle's code. 00100 CFBundleUnloadExecutable (gBundleRefAGL); 00101 CFRelease (gBundleRefAGL); 00102 gBundleRefAGL = NULL; 00103 } 00104 } 00105 00106 void * aglGetProcAddress (char * pszProc) 00107 { 00108 void *rv; 00109 00110 rv = CFBundleGetFunctionPointerForName (gBundleRefAGL, 00111 CFStringCreateWithCStringNoCopy (NULL, 00112 pszProc, CFStringGetSystemEncoding (), NULL)); 00113 if (!rv) { 00114 rv = CFBundleGetFunctionPointerForName (gBundleRefOpenGL, 00115 CFStringCreateWithCStringNoCopy (NULL, 00116 pszProc, CFStringGetSystemEncoding (), NULL)); 00117 } 00118 if (!rv) 00119 error("%s: NULL (FrameworkRef=%x)",pszProc,gBundleRefOpenGL); 00120 return rv; 00121 } 00122 00123 #endif
Copyright © 2008, Cycling '74