From ad92547914b90c52f87b94e3320f32a5ac38ccf2 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Wed, 23 Feb 2005 13:22:44 +0000 Subject: [PATCH] Moved platform specific stuff from extgl.c into platform directories --- src/native/common/extgl.c | 159 ----------------------------------- src/native/linux/extgl_glx.c | 57 ++++++++++++- src/native/macosx/context.m | 40 +++++++++ src/native/win32/extgl_wgl.c | 35 ++++++++ 4 files changed, 128 insertions(+), 163 deletions(-) diff --git a/src/native/common/extgl.c b/src/native/common/extgl.c index 425f7ce4..26da7030 100644 --- a/src/native/common/extgl.c +++ b/src/native/common/extgl.c @@ -38,80 +38,6 @@ THE POSSIBILITY OF SUCH DAMAGE. #include "extgl.h" #include "common_tools.h" -/* turn off the warning for the borland compiler*/ -#ifdef __BORLANDC__ -#pragma warn -8064 -#pragma warn -8065 -#endif /* __BORLANDC__ */ - -#ifdef _X11 - -#include -#endif - -#ifdef _WIN32 -HMODULE lib_gl_handle = NULL; -#endif - -#ifdef _X11 -void * lib_gl_handle = NULL; - -typedef void * (APIENTRY * glXGetProcAddressARBPROC) (const GLubyte *procName); - -static glXGetProcAddressARBPROC glXGetProcAddressARB; -#endif - -#ifdef _MACOSX -#include -static const struct mach_header *opengl_lib_handle = NULL; -#endif - -/* getProcAddress */ - -void *extgl_GetProcAddress(const char *name) -{ -#ifdef _WIN32 - void *t = wglGetProcAddress(name); - if (t == NULL) - { - t = GetProcAddress(lib_gl_handle, name); - if (t == NULL) - { - printfDebug("Could not locate symbol %s\n", name); - } - } - return t; -#endif - -#ifdef _X11 - void *t = (void*)glXGetProcAddressARB((const GLubyte*)name); - if (t == NULL) - { - t = dlsym(lib_gl_handle, name); - if (t == NULL) - { - printfDebug("Could not locate symbol %s\n", name); - } - } - return t; -#endif - -#ifdef _MACOSX - #define BUFFER_SIZE 1024 - char mach_name[BUFFER_SIZE] = "_"; - strncat(mach_name, name, BUFFER_SIZE - 1); - - if (NSIsSymbolNameDefinedInImage(opengl_lib_handle, mach_name)) { - NSSymbol sym = NSLookupSymbolInImage(opengl_lib_handle, mach_name, NSLOOKUPSYMBOLINIMAGE_OPTION_BIND | NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR); - void *address = NSAddressOfSymbol(sym); - return address; - } else { - printfDebug("Could not locate symbol %s\n", name); - return NULL; - } -#endif -} - void extgl_InitializeClass(JNIEnv *env, jclass clazz, int num_functions, JavaMethodAndExtFunction *functions) { ext_InitializeClass(env, clazz, &extgl_GetProcAddress, num_functions, functions); } @@ -120,12 +46,6 @@ bool extgl_InitializeFunctions(int num_functions, ExtFunction *functions) { return ext_InitializeFunctions(&extgl_GetProcAddress, num_functions, functions); } -#ifdef _MACOSX -static const struct mach_header *loadImage(const char *lib_name) { - return NSAddImage(lib_name, NSADDIMAGE_OPTION_RETURN_ON_ERROR); -} -#endif - bool extgl_QueryExtension(JNIEnv *env, const GLubyte*extensions, const char *name) { const GLubyte *start; @@ -161,82 +81,3 @@ bool extgl_QueryExtension(JNIEnv *env, const GLubyte*extensions, const char *nam } -/*-----------------------------------------------------*/ -/* AGL stuff END*/ -/*-----------------------------------------------------*/ - -#ifdef _MACOSX -bool extgl_Open(JNIEnv *env) { - if (opengl_lib_handle != NULL) - return true; - opengl_lib_handle = loadImage("/System/Library/Frameworks/OpenGL.framework/Libraries/libGL.dylib"); - if (opengl_lib_handle != NULL) { - return true; - } else { - throwException(env, "Could not load OpenGL library"); - return false; - } -} -#endif - -#ifdef _X11 -bool extgl_Open(JNIEnv *env) -{ -#define BUFFER_SIZE 2000 - static char buffer[BUFFER_SIZE]; - if (lib_gl_handle != NULL) - return true; - lib_gl_handle = dlopen("libGL.so.1", RTLD_LAZY | RTLD_GLOBAL); - if (lib_gl_handle == NULL) { - snprintf(buffer, BUFFER_SIZE, "Error loading libGL.so.1: %s", dlerror()); - buffer[BUFFER_SIZE - 1] = '\0'; - throwException(env, buffer); - return false; - } - glXGetProcAddressARB = (glXGetProcAddressARBPROC)dlsym(lib_gl_handle, "glXGetProcAddressARB"); - if (glXGetProcAddressARB == NULL) { - extgl_Close(); - throwException(env, "Could not get address of glXGetProcAddressARB"); - return false; - } - return true; -} - -#endif /* X11 */ - -#ifdef _WIN32 -bool extgl_Open(JNIEnv *env) -{ - if (lib_gl_handle != NULL) - return true; - // load the dynamic libraries for OpenGL - lib_gl_handle = LoadLibrary("opengl32.dll"); - if (lib_gl_handle == NULL) { - throwException(env, "Could not load OpenGL library"); - return false; - } - return true; -} -#endif /* WIN32 */ - -void extgl_Close(void) -{ -#ifdef _X11 - dlclose(lib_gl_handle); - lib_gl_handle = NULL; -#endif -#ifdef _WIN32 - FreeLibrary(lib_gl_handle); - lib_gl_handle = NULL; -#endif -#ifdef _MACOSX - opengl_lib_handle = NULL; -#endif -} - -/* turn on the warning for the borland compiler*/ -#ifdef __BORLANDC__ -#pragma warn .8064 -#pragma warn .8065 -#endif /* __BORLANDC__ */ - diff --git a/src/native/linux/extgl_glx.c b/src/native/linux/extgl_glx.c index 20621b62..77ddd393 100644 --- a/src/native/linux/extgl_glx.c +++ b/src/native/linux/extgl_glx.c @@ -29,6 +29,7 @@ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include #include "extgl_glx.h" GLXExtensions extension_flags; @@ -75,6 +76,54 @@ glXQueryExtensionsStringPROC glXQueryExtensionsString = NULL; /* GLX_SGI_swap_control */ glXSwapIntervalSGIPROC glXSwapIntervalSGI = NULL; +static void * lib_gl_handle = NULL; + +typedef void * (APIENTRY * glXGetProcAddressARBPROC) (const GLubyte *procName); + +static glXGetProcAddressARBPROC glXGetProcAddressARB; + +bool extgl_Open(JNIEnv *env) +{ +#define BUFFER_SIZE 2000 + static char buffer[BUFFER_SIZE]; + if (lib_gl_handle != NULL) + return true; + lib_gl_handle = dlopen("libGL.so.1", RTLD_LAZY | RTLD_GLOBAL); + if (lib_gl_handle == NULL) { + snprintf(buffer, BUFFER_SIZE, "Error loading libGL.so.1: %s", dlerror()); + buffer[BUFFER_SIZE - 1] = '\0'; + throwException(env, buffer); + return false; + } + glXGetProcAddressARB = (glXGetProcAddressARBPROC)dlsym(lib_gl_handle, "glXGetProcAddressARB"); + if (glXGetProcAddressARB == NULL) { + extgl_Close(); + throwException(env, "Could not get address of glXGetProcAddressARB"); + return false; + } + return true; +} + +void *extgl_GetProcAddress(const char *name) +{ + void *t = (void*)glXGetProcAddressARB((const GLubyte*)name); + if (t == NULL) + { + t = dlsym(lib_gl_handle, name); + if (t == NULL) + { + printfDebug("Could not locate symbol %s\n", name); + } + } + return t; +} + +void extgl_Close(void) +{ + dlclose(lib_gl_handle); + lib_gl_handle = NULL; +} + /** returns true if the extention is available */ static bool GLXQueryExtension(JNIEnv* env, Display *disp, int screen, const char *name) { @@ -153,15 +202,15 @@ bool extgl_InitGLX(JNIEnv *env, Display *disp, int screen) { int major, minor; /* Assume glx ver >= 1.2 */ - extension_flags.GLX12 = true; if (!extgl_InitGLX12()) return false; - extgl_InitGLXSupportedExtensions(env, disp, screen); - if (glXQueryVersion(disp, &major, &minor) != True) - return false; + extension_flags.GLX12 = true; if (major > 1 || (major == 1 && minor >= 3)) extension_flags.GLX13 = true; extgl_InitGLX13(env); + extgl_InitGLXSupportedExtensions(env, disp, screen); + if (glXQueryVersion(disp, &major, &minor) != True) + return false; extgl_InitGLXSGISwapControl(env); return true; } diff --git a/src/native/macosx/context.m b/src/native/macosx/context.m index b0ddc13f..59c27efc 100644 --- a/src/native/macosx/context.m +++ b/src/native/macosx/context.m @@ -42,6 +42,46 @@ #import #import +#include +static const struct mach_header *opengl_lib_handle = NULL; + +void *extgl_GetProcAddress(const char *name) +{ + #define BUFFER_SIZE 1024 + char mach_name[BUFFER_SIZE] = "_"; + strncat(mach_name, name, BUFFER_SIZE - 1); + + if (NSIsSymbolNameDefinedInImage(opengl_lib_handle, mach_name)) { + NSSymbol sym = NSLookupSymbolInImage(opengl_lib_handle, mach_name, NSLOOKUPSYMBOLINIMAGE_OPTION_BIND | NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR); + void *address = NSAddressOfSymbol(sym); + return address; + } else { + printfDebug("Could not locate symbol %s\n", name); + return NULL; + } +} + +static const struct mach_header *loadImage(const char *lib_name) { + return NSAddImage(lib_name, NSADDIMAGE_OPTION_RETURN_ON_ERROR); +} + +bool extgl_Open(JNIEnv *env) { + if (opengl_lib_handle != NULL) + return true; + opengl_lib_handle = loadImage("/System/Library/Frameworks/OpenGL.framework/Libraries/libGL.dylib"); + if (opengl_lib_handle != NULL) { + return true; + } else { + throwException(env, "Could not load OpenGL library"); + return false; + } +} + +void extgl_Close(void) +{ + opengl_lib_handle = NULL; +} + NSOpenGLPixelFormat *choosePixelFormat(JNIEnv *env, jobject pixel_format, bool use_display_bpp, bool support_window, bool support_pbuffer, bool double_buffered) { int bpp; jclass cls_pixel_format = (*env)->GetObjectClass(env, pixel_format); diff --git a/src/native/win32/extgl_wgl.c b/src/native/win32/extgl_wgl.c index 5057d3f9..a76cf373 100644 --- a/src/native/win32/extgl_wgl.c +++ b/src/native/win32/extgl_wgl.c @@ -78,6 +78,41 @@ wglGetSwapIntervalEXTPROC wglGetSwapIntervalEXT = NULL; wglMakeContextCurrentARBPROC wglMakeContextCurrentARB = NULL; wglGetCurrentReadDCARBPROC wglGetCurrentReadDCARB = NULL; +static HMODULE lib_gl_handle = NULL; + +void *extgl_GetProcAddress(const char *name) +{ + void *t = wglGetProcAddress(name); + if (t == NULL) + { + t = GetProcAddress(lib_gl_handle, name); + if (t == NULL) + { + printfDebug("Could not locate symbol %s\n", name); + } + } + return t; +} + +bool extgl_Open(JNIEnv *env) +{ + if (lib_gl_handle != NULL) + return true; + // load the dynamic libraries for OpenGL + lib_gl_handle = LoadLibrary("opengl32.dll"); + if (lib_gl_handle == NULL) { + throwException(env, "Could not load OpenGL library"); + return false; + } + return true; +} + +void extgl_Close(void) +{ + FreeLibrary(lib_gl_handle); + lib_gl_handle = NULL; +} + /** returns true if the extension is available */ static bool WGLQueryExtension(JNIEnv *env, const char *name) {