Mac OS X: Ported OpenGL library code to use frameworks instead of accessing libGL.dylib directly
This commit is contained in:
parent
19d2d219ec
commit
8f7540ce43
|
@ -37,36 +37,41 @@
|
||||||
* @version $Revision$
|
* @version $Revision$
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#import <CoreFoundation/CoreFoundation.h>
|
||||||
#import "context.h"
|
#import "context.h"
|
||||||
|
|
||||||
#import <Cocoa/Cocoa.h>
|
static CFBundleRef opengl_bundle = NULL;
|
||||||
#import <Carbon/Carbon.h>
|
|
||||||
|
|
||||||
#include <mach-o/dyld.h>
|
void *extgl_GetProcAddress(const char *name) {
|
||||||
static const struct mach_header *opengl_lib_handle = NULL;
|
CFStringRef cf_name = CFStringCreateWithCString(NULL, name, kCFStringEncodingUTF8);
|
||||||
|
void *address = CFBundleGetFunctionPointerForName(opengl_bundle, cf_name);
|
||||||
void *extgl_GetProcAddress(const char *name)
|
CFRelease(cf_name);
|
||||||
{
|
|
||||||
#define BUFFER_SIZE 1024
|
|
||||||
char mach_name[BUFFER_SIZE] = "_";
|
|
||||||
strncat(mach_name, name, BUFFER_SIZE - 1);
|
|
||||||
|
|
||||||
NSSymbol sym = NSLookupSymbolInImage(opengl_lib_handle, mach_name, NSLOOKUPSYMBOLINIMAGE_OPTION_BIND | NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR);
|
|
||||||
void *address = NSAddressOfSymbol(sym);
|
|
||||||
if (address == NULL)
|
if (address == NULL)
|
||||||
printfDebug("Could not locate symbol %s\n", name);
|
printfDebug("Could not locate symbol %s\n", name);
|
||||||
return address;
|
return address;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct mach_header *loadImage(const char *lib_name) {
|
static CFBundleRef loadFramework(JNIEnv *env) {
|
||||||
return NSAddImage(lib_name, NSADDIMAGE_OPTION_RETURN_ON_ERROR);
|
CFStringRef framework_path = CFSTR("/System/Library/Frameworks/OpenGL.framework");
|
||||||
|
if (framework_path == NULL) {
|
||||||
|
printfDebugJava(env, "Failed to allocate string");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
CFURLRef url = CFURLCreateWithFileSystemPath(NULL, framework_path, kCFURLPOSIXPathStyle, TRUE);
|
||||||
|
if (url == NULL) {
|
||||||
|
printfDebugJava(env, "Failed to allocate URL");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
CFBundleRef opengl_bundle = CFBundleCreate(NULL, url);
|
||||||
|
CFRelease(url);
|
||||||
|
return opengl_bundle;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool extgl_Open(JNIEnv *env) {
|
bool extgl_Open(JNIEnv *env) {
|
||||||
if (opengl_lib_handle != NULL)
|
if (opengl_bundle != NULL)
|
||||||
return true;
|
return true;
|
||||||
opengl_lib_handle = loadImage("/System/Library/Frameworks/OpenGL.framework/Libraries/libGL.dylib");
|
opengl_bundle = loadFramework(env);
|
||||||
if (opengl_lib_handle != NULL) {
|
if (opengl_bundle != NULL) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
throwException(env, "Could not load OpenGL library");
|
throwException(env, "Could not load OpenGL library");
|
||||||
|
@ -76,7 +81,10 @@ bool extgl_Open(JNIEnv *env) {
|
||||||
|
|
||||||
void extgl_Close(void)
|
void extgl_Close(void)
|
||||||
{
|
{
|
||||||
opengl_lib_handle = NULL;
|
if (opengl_bundle != NULL) {
|
||||||
|
CFRelease(opengl_bundle);
|
||||||
|
opengl_bundle = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NSOpenGLPixelFormat *choosePixelFormat(JNIEnv *env, jobject pixel_format, bool use_display_bpp, bool support_window, bool support_pbuffer, bool double_buffered) {
|
NSOpenGLPixelFormat *choosePixelFormat(JNIEnv *env, jobject pixel_format, bool use_display_bpp, bool support_window, bool support_pbuffer, bool double_buffered) {
|
||||||
|
|
Loading…
Reference in New Issue