Moved platform specific stuff from extgl.c into platform directories
This commit is contained in:
parent
1162d267f8
commit
ad92547914
|
@ -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 <dlfcn.h>
|
||||
#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 <mach-o/dyld.h>
|
||||
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__ */
|
||||
|
||||
|
|
|
@ -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 <dlfcn.h>
|
||||
#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;
|
||||
}
|
||||
|
|
|
@ -42,6 +42,46 @@
|
|||
#import <Cocoa/Cocoa.h>
|
||||
#import <Carbon/Carbon.h>
|
||||
|
||||
#include <mach-o/dyld.h>
|
||||
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);
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue