Przeglądaj źródła

Fixes for MacOS

danaugrs 8 lat temu
rodzic
commit
1b2ed32665
5 zmienionych plików z 92 dodań i 80 usunięć
  1. 22 20
      audio/al/loader.c
  2. 21 19
      audio/ov/loader.c
  3. 27 1
      audio/vorbis/loader.c
  4. 11 20
      gls/glapi.c
  5. 11 20
      gls/glapi2go/template.go

+ 22 - 20
audio/al/loader.c

@@ -12,7 +12,7 @@ typedef void (*alProc)(void);
 static HMODULE libal;
 
 static int open_libal(void) {
-
+ 
 	libal = LoadLibraryA("OpenAL32.dll");
     if (libal == NULL) {
         return -1;
@@ -21,41 +21,41 @@ static int open_libal(void) {
 }
 
 static void close_libal(void) {
+
 	FreeLibrary(libal);
 }
 
 static alProc get_proc(const char *proc) {
+
     return (alProc) GetProcAddress(libal, proc);
 }
 //
 // Mac --------------------------------------------------------------------
 //
-#elif defined(__APPLE__) || defined(__APPLE_CC__)
-#include <Carbon/Carbon.h>
+#elif defined(__APPLE__)
+#include <dlfcn.h>
 
-CFBundleRef bundle;
-CFURLRef bundleURL;
+static void *libal;
+
+static int open_libal(void) {
 
-static void open_libal(void) {
-	bundleURL = CFURLCreateWithFileSystemPath(kCFAllocatorDefault,
-		CFSTR("/System/Library/Frameworks/OpenAL.framework"),
-		kCFURLPOSIXPathStyle, true);
-	bundle = CFBundleCreate(kCFAllocatorDefault, bundleURL);
-	assert(bundle != NULL);
+    libal = dlopen("/System/Library/Frameworks/OpenAL.framework/OpenAL", RTLD_LAZY | RTLD_GLOBAL);
+    if (!libal) {
+        return -1;
+    }
+    return 0;
 }
 
 static void close_libal(void) {
-	CFRelease(bundle);
-	CFRelease(bundleURL);
+
+    dlclose(libal);
 }
 
-static alProc get_proc(const char *proc) {
-	GL3WglProc res;
-	CFStringRef procname = CFStringCreateWithCString(kCFAllocatorDefault, proc,
-		kCFStringEncodingASCII);
-	res = (GL3WglProc) CFBundleGetFunctionPointerForName(bundle, procname);
-	CFRelease(procname);
-	return res;
+static void* get_proc(const char *proc) {
+
+    void* res;
+    *(void **)(&res) = dlsym(libal, proc);
+    return res;
 }
 //
 // Linux --------------------------------------------------------------------
@@ -86,10 +86,12 @@ static int open_libal(void) {
 }
 
 static void close_libal(void) {
+
 	dlclose(libal);
 }
 
 static alProc get_proc(const char *proc) {
+    
     return dlsym(libal, proc);
 }
 #endif

+ 21 - 19
audio/ov/loader.c

@@ -25,41 +25,41 @@ static int open_libvbf(void) {
 }
 
 static void close_libvbf(void) {
+
 	FreeLibrary(libvbf);
 }
 
 static alProc get_proc(const char *proc) {
+
     return (alProc) GetProcAddress(libvbf, proc);
 }
 //
 // Mac --------------------------------------------------------------------
 //
-#elif defined(__APPLE__) || defined(__APPLE_CC__)
-#include <Carbon/Carbon.h>
+#elif defined(__APPLE__)
+#include <dlfcn.h>
 
-CFBundleRef bundle;
-CFURLRef bundleURL;
+static void *libvbf;
 
-static void open_libvbf(void) {
-	bundleURL = CFURLCreateWithFileSystemPath(kCFAllocatorDefault,
-		CFSTR("/System/Library/Frameworks/OpenAL.framework"),
-		kCFURLPOSIXPathStyle, true);
-	bundle = CFBundleCreate(kCFAllocatorDefault, bundleURL);
-	assert(bundle != NULL);
+static int open_libvbf(void) {
+
+    libvbf = dlopen("/System/Library/Frameworks/libvorbisfile.framework/libvorbisfile", RTLD_LAZY | RTLD_GLOBAL);
+    if (!libvbf) {
+        return -1;
+    }
+    return 0;
 }
 
 static void close_libvbf(void) {
-	CFRelease(bundle);
-	CFRelease(bundleURL);
+
+    dlclose(libvbf);
 }
 
-static alProc get_proc(const char *proc) {
-	GL3WglProc res;
-	CFStringRef procname = CFStringCreateWithCString(kCFAllocatorDefault, proc,
-		kCFStringEncodingASCII);
-	res = (GL3WglProc) CFBundleGetFunctionPointerForName(bundle, procname);
-	CFRelease(procname);
-	return res;
+static void* get_proc(const char *proc) {
+
+    void* res;
+    *(void **)(&res) = dlsym(libvbf, proc);
+    return res;
 }
 //
 // Linux --------------------------------------------------------------------
@@ -90,10 +90,12 @@ static int open_libvbf(void) {
 }
 
 static void close_libvbf(void) {
+
 	dlclose(libvbf);
 }
 
 static alProc get_proc(const char *proc) {
+
     return dlsym(libvbf, proc);
 }
 #endif

+ 27 - 1
audio/vorbis/loader.c

@@ -26,19 +26,42 @@ static int open_libvb(void) {
 }
 
 static void close_libvb(void) {
+
 	FreeLibrary(libvb);
 }
 
 static alProc get_proc(const char *proc) {
+
     return (alProc) GetProcAddress(libvb, proc);
 }
 //
 // Mac --------------------------------------------------------------------
 //
-#elif defined(__APPLE__) || defined(__APPLE_CC__)
+#elif defined(__APPLE__)
+#include <dlfcn.h>
+
+static void *libvb;
 
+static int open_libvb(void) {
 
+    libvb = dlopen("/System/Library/Frameworks/libvorbis.framework/libvorbis", RTLD_LAZY | RTLD_GLOBAL);
+    if (!libvb) {
+        return -1;
+    }
+    return 0;
+}
 
+static void close_libvb(void) {
+
+    dlclose(libvb);
+}
+
+static void* get_proc(const char *proc) {
+
+    void* res;
+    *(void **)(&res) = dlsym(libvb, proc);
+    return res;
+}
 //
 // Linux --------------------------------------------------------------------
 //
@@ -68,10 +91,12 @@ static int open_libvb(void) {
 }
 
 static void close_libvb(void) {
+
 	dlclose(libvb);
 }
 
 static alProc get_proc(const char *proc) {
+
     return dlsym(libvb, proc);
 }
 #endif
@@ -96,6 +121,7 @@ int vorbis_load() {
 }
 
 static void load_procs(void) {
+
     p_vorbis_version_string = (LPVORBISVERSIONSTRING)get_proc("vorbis_version_string");
 }
 

+ 11 - 20
gls/glapi.c

@@ -53,38 +53,29 @@ static void* get_proc(const char *proc) {
 //
 // OpenGL function loader for Mac OS
 //
-#elif defined(__APPLE__) || defined(__APPLE_CC__)
-#include <Carbon/Carbon.h>
-
-CFBundleRef bundle;
-CFURLRef bundleURL;
+#elif defined(__APPLE__)
+#include <dlfcn.h>
 
-// open_libgl opens the OpenGL shared object for OSX
-static void open_libgl(void) {
+static void *libgl;
 
-	bundleURL = CFURLCreateWithFileSystemPath(kCFAllocatorDefault,
-		CFSTR("/System/Library/Frameworks/OpenGL.framework"),
-		kCFURLPOSIXPathStyle, true);
+static int open_libgl(void) {
 
-	bundle = CFBundleCreate(kCFAllocatorDefault, bundleURL);
-	assert(bundle != NULL);
+	libgl = dlopen("/System/Library/Frameworks/OpenGL.framework/OpenGL", RTLD_LAZY | RTLD_GLOBAL);
+	if (!libgl) {
+		return -1;
+	}
+	return 0;
 }
 
-// close_libgl closes the OpenGL shared object object for OSX
 static void close_libgl(void) {
 
-	CFRelease(bundle);
-	CFRelease(bundleURL);
+	dlclose(libgl);
 }
 
-// get_proc gets the pointer for an OpenGL function for OSX
 static void* get_proc(const char *proc) {
 
 	void* res;
-	CFStringRef procname = CFStringCreateWithCString(kCFAllocatorDefault, proc,
-		kCFStringEncodingASCII);
-	*(void **)(&res) = CFBundleGetFunctionPointerForName(bundle, procname);
-	CFRelease(procname);
+	*(void **)(&res) = dlsym(libgl, proc);
 	return res;
 }
 

+ 11 - 20
gls/glapi2go/template.go

@@ -136,38 +136,29 @@ static void* get_proc(const char *proc) {
 //
 // OpenGL function loader for Mac OS
 //
-#elif defined(__APPLE__) || defined(__APPLE_CC__)
-#include <Carbon/Carbon.h>
-
-CFBundleRef bundle;
-CFURLRef bundleURL;
+#elif defined(__APPLE__)
+#include <dlfcn.h>
 
-// open_libgl opens the OpenGL shared object for OSX
-static void open_libgl(void) {
+static void *libgl;
 
-	bundleURL = CFURLCreateWithFileSystemPath(kCFAllocatorDefault,
-		CFSTR("/System/Library/Frameworks/OpenGL.framework"),
-		kCFURLPOSIXPathStyle, true);
+static int open_libgl(void) {
 
-	bundle = CFBundleCreate(kCFAllocatorDefault, bundleURL);
-	assert(bundle != NULL);
+	libgl = dlopen("/System/Library/Frameworks/OpenGL.framework/OpenGL", RTLD_LAZY | RTLD_GLOBAL);
+	if (!libgl) {
+		return -1;
+	}
+	return 0;
 }
 
-// close_libgl closes the OpenGL shared object object for OSX
 static void close_libgl(void) {
 
-	CFRelease(bundle);
-	CFRelease(bundleURL);
+	dlclose(libgl);
 }
 
-// get_proc gets the pointer for an OpenGL function for OSX
 static void* get_proc(const char *proc) {
 
 	void* res;
-	CFStringRef procname = CFStringCreateWithCString(kCFAllocatorDefault, proc,
-		kCFStringEncodingASCII);
-	*(void **)(&res) = CFBundleGetFunctionPointerForName(bundle, procname);
-	CFRelease(procname);
+	*(void **)(&res) = dlsym(libgl, proc);
 	return res;
 }