Sfoglia il codice sorgente

Merge branch 'master' into gltf

leonsal 8 anni fa
parent
commit
ccddf5e8fc
7 ha cambiato i file con 105 aggiunte e 89 eliminazioni
  1. 12 8
      README.md
  2. 1 1
      audio/al/al.go
  3. 22 20
      audio/al/loader.c
  4. 21 19
      audio/ov/loader.c
  5. 27 1
      audio/vorbis/loader.c
  6. 11 20
      gls/glapi.c
  7. 11 20
      gls/glapi2go/template.go

+ 12 - 8
README.md

@@ -12,7 +12,11 @@ G3N was heavily inspired and based on the [three.js](https://threejs.org/) Javas
   <img style="float: right;" src="https://github.com/g3n/g3n.github.io/blob/master/g3n_banner_small.png" alt="G3N Banner"/>
 </p>
 
-# Dependencies
+## Highlighted Projects
+
+[Gokoban - 3D Puzzle Game](https://github.com/danaugrs/gokoban)
+
+## Dependencies
 
 The engine needs an OpenGL driver installed in the system and
 on Unix like systems depends on some C libraries that can be installed using the distribution package manager.
@@ -38,14 +42,14 @@ The following libraries are necessary for the optional audio support:
 
 G3N was only tested with Go1.7.4+
 
-# Installation
+## Installation
 
 The following command will download the engine and all its dependencies, compile and
 install the packages. Make sure your GOPATH is set correctly. 
 
 `go get -u github.com/g3n/engine/...`
 
-# Features
+## Features
 
 * Hierarchical scene graph. Any node can contain other nodes.
 * Supports perspective and orthographic cameras. The camera can be controlled
@@ -62,7 +66,7 @@ install the packages. Make sure your GOPATH is set correctly.
 * Spatial audio support allowing playing sound from wave or Ogg Vorbis files.
 * Users' applications can use their own vertex and fragment shaders.
 
-# Basic application
+## Basic application
 
 The following code shows a basic G3N application 
 ([hellog3n](https://github.com/g3n/demos/tree/master/hellog3n))
@@ -170,12 +174,12 @@ func main() {
   <img style="float: right;" src="https://github.com/g3n/demos/blob/master/hellog3n/screenshot.png" alt="hellog3n Screenshot"/>
 </p>
 
-# To Do
+## To Do
 
 G3N is a basic game engine. There is a lot of things to do.
 We will soon insert here a list of the most important missing features.
 
-# Documentation
+## Documentation
 
 For the engine API reference, please use
 [![GoDoc](https://godoc.org/github.com/g3n/engine?status.svg)](https://godoc.org/github.com/g3n/engine).
@@ -184,12 +188,12 @@ of the demos from [G3ND](https://github.com/g3n/g3nd).
 We intend to write in the future documentation topics
 to build a user guide in the [wiki](https://github.com/g3n/engine/wiki).
 
-# Contributing
+## Contributing
 
 If you spot a bug or create a new feature you are encouraged to
 send pull requests.
 
-# Community
+## Community
 
 Join our [channel](https://gophers.slack.com/messages/g3n) on Gophers Slack.
 

+ 1 - 1
audio/al/al.go

@@ -12,7 +12,7 @@ The OpenAL documentation can be accessed at https://openal.org/documentation/
 package al
 
 /*
-#cgo darwin   CFLAGS:  -DGO_DARWIN
+#cgo darwin   CFLAGS:  -DGO_DARWIN  -I../include
 #cgo linux    CFLAGS:  -DGO_LINUX   -I../include
 #cgo windows  CFLAGS:  -DGO_WINDOWS -I../include
 #cgo darwin   LDFLAGS:

+ 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;
 }