Various Mac stuff

This commit is contained in:
Elias Naur 2003-09-29 09:26:20 +00:00
parent 26ca56212c
commit 4111a08857
4 changed files with 245 additions and 191 deletions

View File

@ -30,8 +30,43 @@ public final class Window {
static { static {
System.loadLibrary(Sys.getLibraryName()); System.loadLibrary(Sys.getLibraryName());
/*
* elias: Mac OS X hacks. We need to fetch the toolkit to acquire a Dock icon, a system menu
* and to make windows behave normally. We also need to intercept the quit event from
* Swing. Luckily, Swing can be assumed to be present on Mac OS X. Because some of this
* is apple extensions to java, we need stub files to successfully compile on other platforms.
*
* Additionally, because of the way swing works, applications now need to do an
* explicit System.exit() to quit. Returning from the main thread is not enough any
* more.
*
* I've wasted a significant amount of time searching for an acceptable solution, without
* finding a way to avoid Swing. AFAIK,
*
* 1. There's no way to acquire the Dock icon, system menu and normal window behaviour.
* For that, you either need a proper bundled, native application or initialize Swing.
* 2. Even if there were a way around it, Swing is automatically started anyway if you
* use Java Web Start.
* 3. Swing gains total control over the main event loop, so the native library need to
* work around by maintaining an internal event queue. That's really boring stuff, indeed.
*
* I have posted a bug report to apple regarding the behaviour.
*
*/
if (Display.getPlatform() == Display.PLATFORM_AGL) {
java.awt.Toolkit.getDefaultToolkit();
new com.apple.eawt.Application().addApplicationListener(new com.apple.eawt.ApplicationAdapter() {
public void handleQuit(com.apple.eawt.ApplicationEvent e) {
e.setHandled(false);
apple_quit = true;
}
});
}
} }
/** Special quit boolean set from the apple version */
private static boolean apple_quit;
/** Whether the window is currently created, ie. has a native peer */ /** Whether the window is currently created, ie. has a native peer */
private static boolean created; private static boolean created;
@ -150,7 +185,9 @@ public final class Window {
*/ */
public static boolean isCloseRequested() { public static boolean isCloseRequested() {
assert isCreated() : "Cannot determine state of uncreated window"; assert isCreated() : "Cannot determine state of uncreated window";
return nIsCloseRequested(); boolean result = nIsCloseRequested() || apple_quit;
apple_quit = false;
return result;
} }
private static native boolean nIsCloseRequested(); private static native boolean nIsCloseRequested();
@ -305,6 +342,7 @@ public final class Window {
throws Exception; throws Exception;
private static void createWindow() throws Exception { private static void createWindow() throws Exception {
apple_quit = false;
HashSet extensions = new HashSet(); HashSet extensions = new HashSet();
nCreate(title, x, y, width, height, fullscreen, color, alpha, depth, stencil, extensions); nCreate(title, x, y, width, height, fullscreen, color, alpha, depth, stencil, extensions);
GLCaps.determineAvailableExtensions(extensions); GLCaps.determineAvailableExtensions(extensions);

View File

@ -88,6 +88,42 @@ glXQueryServerStringPROC glXQueryServerString = NULL;
glXQueryExtensionsStringPROC glXQueryExtensionsString = NULL; glXQueryExtensionsStringPROC glXQueryExtensionsString = NULL;
#endif #endif
#ifdef _AGL
aglChoosePixelFormatPROC aglChoosePixelFormat = NULL;
aglDestroyPixelFormatPROC aglDestroyPixelFormat = NULL;
aglNextPixelFormatPROC aglNextPixelFormat = NULL;
aglDescribePixelFormatPROC aglDescribePixelFormat = NULL;
aglDevicesOfPixelFormatPROC aglDevicesOfPixelFormat = NULL;
aglQueryRendererInfoPROC aglQueryRendererInfo = NULL;
aglDestroyRendererInfoPROC aglDestroyRendererInfo = NULL;
aglNextRendererInfoPROC aglNextRendererInfo = NULL;
aglDescribeRendererPROC aglDescribeRenderer = NULL;
aglCreateContextPROC aglCreateContext = NULL;
aglDestroyContextPROC aglDestroyContext = NULL;
aglCopyContextPROC aglCopyContext = NULL;
aglUpdateContextPROC aglUpdateContext = NULL;
aglSetCurrentContextPROC aglSetCurrentContext = NULL;
aglGetCurrentContextPROC aglGetCurrentContext = NULL;
aglSetDrawablePROC aglSetDrawable = NULL;
aglSetOffScreenPROC aglSetOffScreen = NULL;
aglSetFullScreenPROC aglSetFullScreen = NULL;
aglGetDrawablePROC aglGetDrawable = NULL;
aglSetVirtualScreenPROC aglSetVirtualScreen = NULL;
aglGetVirtualScreenPROC aglGetVirtualScreen = NULL;
aglGetVersionPROC aglGetVersion = NULL;
aglSwapBuffersPROC aglSwapBuffers = NULL;
aglEnablePROC aglEnable = NULL;
aglDisablePROC aglDisable = NULL;
aglIsEnabledPROC aglIsEnabled = NULL;
aglSetIntegerPROC aglSetInteger = NULL;
aglGetIntegerPROC aglGetInteger = NULL;
aglUseFontPROC aglUseFont = NULL;
aglGetErrorPROC aglGetError = NULL;
aglErrorStringPROC aglErrorString = NULL;
aglResetLibraryPROC aglResetLibrary = NULL;
aglSurfaceTexturePROC aglSurfaceTexture = NULL;
#endif
gluBeginCurvePROC gluBeginCurve = NULL; gluBeginCurvePROC gluBeginCurve = NULL;
gluBeginPolygonPROC gluBeginPolygon = NULL; gluBeginPolygonPROC gluBeginPolygon = NULL;
gluBeginSurfacePROC gluBeginSurface = NULL; gluBeginSurfacePROC gluBeginSurface = NULL;
@ -1311,7 +1347,9 @@ OSStatus aglInitEntryPoints (void)
if (noErr != err) if (noErr != err)
{ {
DebugStr ("\pCould make FSref to frameworks folder"); #ifdef _DEBUG
printf("Could make FSref to frameworks folder\n");
#endif
return err; return err;
} }
@ -1320,7 +1358,9 @@ OSStatus aglInitEntryPoints (void)
bundleURLOpenGL = CFURLCreateFromFSRef (kCFAllocatorDefault, &fileRef); bundleURLOpenGL = CFURLCreateFromFSRef (kCFAllocatorDefault, &fileRef);
if (!bundleURLOpenGL) if (!bundleURLOpenGL)
{ {
DebugStr ("\pCould create OpenGL Framework bundle URL"); #ifdef _DEBUG
printf("Could create OpenGL Framework bundle URL\n");
#endif
return paramErr; return paramErr;
} }
@ -1329,7 +1369,9 @@ OSStatus aglInitEntryPoints (void)
gBundleRefOpenGL = CFBundleCreate (kCFAllocatorDefault,bundleURLOpenGL); gBundleRefOpenGL = CFBundleCreate (kCFAllocatorDefault,bundleURLOpenGL);
if (!gBundleRefOpenGL) if (!gBundleRefOpenGL)
{ {
DebugStr ("\pCould not create OpenGL Framework bundle"); #ifdef _DEBUG
printf("Could not create OpenGL Framework bundle\n");
#endif
return paramErr; return paramErr;
} }
@ -1340,7 +1382,9 @@ OSStatus aglInitEntryPoints (void)
// if the code was successfully loaded, look for our function. // if the code was successfully loaded, look for our function.
if (!CFBundleLoadExecutable (gBundleRefOpenGL)) if (!CFBundleLoadExecutable (gBundleRefOpenGL))
{ {
DebugStr ("\pCould not load MachO executable"); #ifdef _DEBUG
printf("Could not load MachO executable\n");
#endif
return paramErr; return paramErr;
} }
@ -1362,7 +1406,10 @@ static void aglDellocEntryPoints (void)
static void * aglGetProcAddress (char * pszProc) static void * aglGetProcAddress (char * pszProc)
{ {
return CFBundleGetFunctionPointerForName (gBundleRefOpenGL,CFStringCreateWithCStringNoCopy (NULL, pszProc, CFStringGetSystemEncoding (), NULL)); CFStringRef str = CFStringCreateWithCStringNoCopy(NULL, pszProc, kCFStringEncodingUTF8, kCFAllocatorNull);
void *func_pointer = CFBundleGetFunctionPointerForName(gBundleRefOpenGL, str);
CFRelease(str);
return func_pointer;
} }
#endif #endif
@ -1579,11 +1626,42 @@ static void extgl_InitializeWGL(JNIEnv *env, jobject ext_set)
/*-----------------------------------------------------*/ /*-----------------------------------------------------*/
#ifdef _AGL #ifdef _AGL
static int extgl_InitializeAGL(JNIEnv *env, jobject ext_set) bool extgl_InitAGL(JNIEnv *env, jobject ext_set)
{ {
// add in AGL extensions here aglChoosePixelFormat = (aglChoosePixelFormatPROC)extgl_GetProcAddress("aglChoosePixelFormat");
aglDestroyPixelFormat = (aglDestroyPixelFormatPROC)extgl_GetProcAddress("aglDestroyPixelFormat");
return 0; aglNextPixelFormat = (aglNextPixelFormatPROC)extgl_GetProcAddress("aglNextPixelFormat");
aglDescribePixelFormat = (aglDescribePixelFormatPROC)extgl_GetProcAddress("aglDescribePixelFormat");
aglDevicesOfPixelFormat = (aglDevicesOfPixelFormatPROC)extgl_GetProcAddress("aglDevicesOfPixelFormat");
aglQueryRendererInfo = (aglQueryRendererInfoPROC)extgl_GetProcAddress("aglQueryRendererInfo");
aglDestroyRendererInfo = (aglDestroyRendererInfoPROC)extgl_GetProcAddress("aglDestroyRendererInfo");
aglNextRendererInfo = (aglNextRendererInfoPROC)extgl_GetProcAddress("aglNextRendererInfo");
aglDescribeRenderer = (aglDescribeRendererPROC)extgl_GetProcAddress("aglDescribeRenderer");
aglCreateContext = (aglCreateContextPROC)extgl_GetProcAddress("aglCreateContext");
aglDestroyContext = (aglDestroyContextPROC)extgl_GetProcAddress("aglDestroyContext");
aglCopyContext = (aglCopyContextPROC)extgl_GetProcAddress("aglCopyContext");
aglUpdateContext = (aglUpdateContextPROC)extgl_GetProcAddress("aglUpdateContext");
aglSetCurrentContext = (aglSetCurrentContextPROC)extgl_GetProcAddress("aglSetCurrentContext");
aglGetCurrentContext = (aglGetCurrentContextPROC)extgl_GetProcAddress("aglGetCurrentContext");
aglSetDrawable = (aglSetDrawablePROC)extgl_GetProcAddress("aglSetDrawable");
aglSetOffScreen = (aglSetOffScreenPROC)extgl_GetProcAddress("aglSetOffScreen");
aglSetFullScreen = (aglSetFullScreenPROC)extgl_GetProcAddress("aglSetFullScreen");
aglGetDrawable = (aglGetDrawablePROC)extgl_GetProcAddress("aglGetDrawable");
aglSetVirtualScreen = (aglSetVirtualScreenPROC)extgl_GetProcAddress("aglSetVirtualScreen");
aglGetVirtualScreen = (aglGetVirtualScreenPROC)extgl_GetProcAddress("aglGetVirtualScreen");
aglGetVersion = (aglGetVersionPROC)extgl_GetProcAddress("aglGetVersion");
aglSwapBuffers = (aglSwapBuffersPROC)extgl_GetProcAddress("aglSwapBuffers");
aglEnable = (aglEnablePROC)extgl_GetProcAddress("aglEnable");
aglDisable = (aglDisablePROC)extgl_GetProcAddress("aglDisable");
aglIsEnabled = (aglIsEnabledPROC)extgl_GetProcAddress("aglIsEnabled");
aglSetInteger = (aglSetIntegerPROC)extgl_GetProcAddress("aglSetInteger");
aglGetInteger = (aglGetIntegerPROC)extgl_GetProcAddress("aglGetInteger");
aglUseFont = (aglUseFontPROC)extgl_GetProcAddress("aglUseFont");
aglGetError = (aglGetErrorPROC)extgl_GetProcAddress("aglGetError");
aglErrorString = (aglErrorStringPROC)extgl_GetProcAddress("aglErrorString");
aglResetLibrary = (aglResetLibraryPROC)extgl_GetProcAddress("aglResetLibrary");
aglSurfaceTexture = (aglSurfaceTexturePROC)extgl_GetProcAddress("aglSurfaceTexture");
return !extgl_error;
} }
#endif #endif
@ -3046,7 +3124,6 @@ static void extgl_InitSupportedExtensions(JNIEnv *env, jobject ext_set)
extgl_Extensions.OpenGL12 = false; extgl_Extensions.OpenGL12 = false;
extgl_Extensions.OpenGL13 = false; extgl_Extensions.OpenGL13 = false;
extgl_Extensions.OpenGL14 = false; extgl_Extensions.OpenGL14 = false;
if (s != NULL) if (s != NULL)
{ {
// Fall trhough // Fall trhough
@ -3154,7 +3231,6 @@ static void extgl_InitSupportedExtensions(JNIEnv *env, jobject ext_set)
bool extgl_Initialize(JNIEnv *env, jobject ext_set) bool extgl_Initialize(JNIEnv *env, jobject ext_set)
{ {
extgl_error = false; extgl_error = false;
extgl_InitOpenGL1_1(); extgl_InitOpenGL1_1();
extgl_InitGLU12(); extgl_InitGLU12();
if (extgl_error) if (extgl_error)
@ -3219,11 +3295,6 @@ bool extgl_Initialize(JNIEnv *env, jobject ext_set)
/* load WGL extensions */ /* load WGL extensions */
extgl_InitializeWGL(env, ext_set); extgl_InitializeWGL(env, ext_set);
#endif #endif
#ifdef _AGL
/* load AGL extensions */
extgl_InitializeAGL(env, ext_set);
#endif
return true; return true;
} }

View File

@ -343,73 +343,73 @@ typedef CGrafPtr AGLDrawable;
void aglDellocEntryPoints (void); void aglDellocEntryPoints (void);
void * aglGetProcAddress (char * pszProc); void * aglGetProcAddress (char * pszProc);
*/ */
typedef AGLPixelFormat (APIENTRY * aglChoosePixelFormatEXTPROC)(const AGLDevice *gdevs, GLint ndev, const GLint *attribs); typedef AGLPixelFormat (APIENTRY * aglChoosePixelFormatPROC)(const AGLDevice *gdevs, GLint ndev, const GLint *attribs);
typedef void (APIENTRY * aglDestroyPixelFormatEXTPROC)(AGLPixelFormat pix); typedef void (APIENTRY * aglDestroyPixelFormatPROC)(AGLPixelFormat pix);
typedef AGLPixelFormat (APIENTRY * aglNextPixelFormatEXTPROC)(AGLPixelFormat pix); typedef AGLPixelFormat (APIENTRY * aglNextPixelFormatPROC)(AGLPixelFormat pix);
typedef GLboolean (APIENTRY * aglDescribePixelFormatEXTPROC)(AGLPixelFormat pix, GLint attrib, GLint *value); typedef GLboolean (APIENTRY * aglDescribePixelFormatPROC)(AGLPixelFormat pix, GLint attrib, GLint *value);
typedef AGLDevice * (APIENTRY * aglDevicesOfPixelFormatEXTPROC)(AGLPixelFormat pix, GLint *ndevs); typedef AGLDevice * (APIENTRY * aglDevicesOfPixelFormatPROC)(AGLPixelFormat pix, GLint *ndevs);
typedef AGLRendererInfo (APIENTRY * aglQueryRendererInfoEXTPROC)(const AGLDevice *gdevs, GLint ndev); typedef AGLRendererInfo (APIENTRY * aglQueryRendererInfoPROC)(const AGLDevice *gdevs, GLint ndev);
typedef void (APIENTRY * aglDestroyRendererInfoEXTPROC)(AGLRendererInfo rend); typedef void (APIENTRY * aglDestroyRendererInfoPROC)(AGLRendererInfo rend);
typedef AGLRendererInfo (APIENTRY * aglNextRendererInfoEXTPROC)(AGLRendererInfo rend); typedef AGLRendererInfo (APIENTRY * aglNextRendererInfoPROC)(AGLRendererInfo rend);
typedef GLboolean (APIENTRY * aglDescribeRendererEXTPROC)(AGLRendererInfo rend, GLint prop, GLint *value); typedef GLboolean (APIENTRY * aglDescribeRendererPROC)(AGLRendererInfo rend, GLint prop, GLint *value);
typedef AGLContext (APIENTRY * aglCreateContextEXTPROC)(AGLPixelFormat pix, AGLContext share); typedef AGLContext (APIENTRY * aglCreateContextPROC)(AGLPixelFormat pix, AGLContext share);
typedef GLboolean (APIENTRY * aglDestroyContextEXTPROC)(AGLContext ctx); typedef GLboolean (APIENTRY * aglDestroyContextPROC)(AGLContext ctx);
typedef GLboolean (APIENTRY * aglCopyContextEXTPROC)(AGLContext src, AGLContext dst, GLuint mask); typedef GLboolean (APIENTRY * aglCopyContextPROC)(AGLContext src, AGLContext dst, GLuint mask);
typedef GLboolean (APIENTRY * aglUpdateContextEXTPROC)(AGLContext ctx); typedef GLboolean (APIENTRY * aglUpdateContextPROC)(AGLContext ctx);
typedef GLboolean (APIENTRY * aglSetCurrentContextEXTPROC)(AGLContext ctx); typedef GLboolean (APIENTRY * aglSetCurrentContextPROC)(AGLContext ctx);
typedef AGLContext (APIENTRY * aglGetCurrentContextEXTPROC)(void); typedef AGLContext (APIENTRY * aglGetCurrentContextPROC)(void);
typedef GLboolean (APIENTRY * aglSetDrawableEXTPROC)(AGLContext ctx, AGLDrawable draw); typedef GLboolean (APIENTRY * aglSetDrawablePROC)(AGLContext ctx, AGLDrawable draw);
typedef GLboolean (APIENTRY * aglSetOffScreenEXTPROC)(AGLContext ctx, GLsizei width, GLsizei height, GLsizei rowbytes, GLvoid *baseaddr); typedef GLboolean (APIENTRY * aglSetOffScreenPROC)(AGLContext ctx, GLsizei width, GLsizei height, GLsizei rowbytes, GLvoid *baseaddr);
typedef GLboolean (APIENTRY * aglSetFullScreenEXTPROC)(AGLContext ctx, GLsizei width, GLsizei height, GLsizei freq, GLint device); typedef GLboolean (APIENTRY * aglSetFullScreenPROC)(AGLContext ctx, GLsizei width, GLsizei height, GLsizei freq, GLint device);
typedef AGLDrawable (APIENTRY * aglGetDrawableEXTPROC)(AGLContext ctx); typedef AGLDrawable (APIENTRY * aglGetDrawablePROC)(AGLContext ctx);
typedef GLboolean (APIENTRY * aglSetVirtualScreenEXTPROC)(AGLContext ctx, GLint screen); typedef GLboolean (APIENTRY * aglSetVirtualScreenPROC)(AGLContext ctx, GLint screen);
typedef GLint (APIENTRY * aglGetVirtualScreenEXTPROC)(AGLContext ctx); typedef GLint (APIENTRY * aglGetVirtualScreenPROC)(AGLContext ctx);
typedef void (APIENTRY * aglGetVersionEXTPROC)(GLint *major, GLint *minor); typedef void (APIENTRY * aglGetVersionPROC)(GLint *major, GLint *minor);
typedef void (APIENTRY * aglSwapBuffersEXTPROC)(AGLContext ctx); typedef void (APIENTRY * aglSwapBuffersPROC)(AGLContext ctx);
typedef GLboolean (APIENTRY * aglEnableEXTPROC)(AGLContext ctx, GLenum pname); typedef GLboolean (APIENTRY * aglEnablePROC)(AGLContext ctx, GLenum pname);
typedef GLboolean (APIENTRY * aglDisableEXTPROC)(AGLContext ctx, GLenum pname); typedef GLboolean (APIENTRY * aglDisablePROC)(AGLContext ctx, GLenum pname);
typedef GLboolean (APIENTRY * aglIsEnabledEXTPROC)(AGLContext ctx, GLenum pname); typedef GLboolean (APIENTRY * aglIsEnabledPROC)(AGLContext ctx, GLenum pname);
typedef GLboolean (APIENTRY * aglSetIntegerEXTPROC)(AGLContext ctx, GLenum pname, const GLint *params); typedef GLboolean (APIENTRY * aglSetIntegerPROC)(AGLContext ctx, GLenum pname, const GLint *params);
typedef GLboolean (APIENTRY * aglGetIntegerEXTPROC)(AGLContext ctx, GLenum pname, GLint *params); typedef GLboolean (APIENTRY * aglGetIntegerPROC)(AGLContext ctx, GLenum pname, GLint *params);
typedef GLboolean (APIENTRY * aglUseFontEXTPROC)(AGLContext ctx, GLint fontID, Style face, GLint size, GLint first, GLint count, GLint base); typedef GLboolean (APIENTRY * aglUseFontPROC)(AGLContext ctx, GLint fontID, Style face, GLint size, GLint first, GLint count, GLint base);
typedef GLenum (APIENTRY * aglGetErrorEXTPROC)(void); typedef GLenum (APIENTRY * aglGetErrorPROC)(void);
typedef const GLubyte * (APIENTRY * aglErrorStringEXTPROC)(GLenum code); typedef const GLubyte * (APIENTRY * aglErrorStringPROC)(GLenum code);
typedef void (APIENTRY * aglResetLibraryEXTPROC)(void); typedef void (APIENTRY * aglResetLibraryPROC)(void);
typedef void (APIENTRY * aglSurfaceTextureEXTPROC) (AGLContext context, GLenum target, GLenum internalformat, AGLContext surfacecontext); typedef void (APIENTRY * aglSurfaceTexturePROC) (AGLContext context, GLenum target, GLenum internalformat, AGLContext surfacecontext);
extern aglChoosePixelFormatEXTPROC aglChoosePixelFormat; extern aglChoosePixelFormatPROC aglChoosePixelFormat;
extern aglDestroyPixelFormatEXTPROC aglDestroyPixelFormat; extern aglDestroyPixelFormatPROC aglDestroyPixelFormat;
extern aglNextPixelFormatEXTPROC aglNextPixelFormat; extern aglNextPixelFormatPROC aglNextPixelFormat;
extern aglDescribePixelFormatEXTPROC aglDescribePixelFormat; extern aglDescribePixelFormatPROC aglDescribePixelFormat;
extern aglDevicesOfPixelFormatEXTPROC aglDevicesOfPixelFormat; extern aglDevicesOfPixelFormatPROC aglDevicesOfPixelFormat;
extern aglQueryRendererInfoEXTPROC aglQueryRendererInfo; extern aglQueryRendererInfoPROC aglQueryRendererInfo;
extern aglDestroyRendererInfoEXTPROC aglDestroyRendererInfo; extern aglDestroyRendererInfoPROC aglDestroyRendererInfo;
extern aglNextRendererInfoEXTPROC aglNextRendererInfo; extern aglNextRendererInfoPROC aglNextRendererInfo;
extern aglDescribeRendererEXTPROC aglDescribeRenderer; extern aglDescribeRendererPROC aglDescribeRenderer;
extern aglCreateContextEXTPROC aglCreateContext; extern aglCreateContextPROC aglCreateContext;
extern aglDestroyContextEXTPROC aglDestroyContext; extern aglDestroyContextPROC aglDestroyContext;
extern aglCopyContextEXTPROC aglCopyContext; extern aglCopyContextPROC aglCopyContext;
extern aglUpdateContextEXTPROC aglUpdateContext; extern aglUpdateContextPROC aglUpdateContext;
extern aglSetCurrentContextEXTPROC aglSetCurrentContext; extern aglSetCurrentContextPROC aglSetCurrentContext;
extern aglGetCurrentContextEXTPROC aglGetCurrentContext; extern aglGetCurrentContextPROC aglGetCurrentContext;
extern aglSetDrawableEXTPROC aglSetDrawable; extern aglSetDrawablePROC aglSetDrawable;
extern aglSetOffScreenEXTPROC aglSetOffScreen; extern aglSetOffScreenPROC aglSetOffScreen;
extern aglSetFullScreenEXTPROC aglSetFullScreen; extern aglSetFullScreenPROC aglSetFullScreen;
extern aglGetDrawableEXTPROC aglGetDrawable; extern aglGetDrawablePROC aglGetDrawable;
extern aglSetVirtualScreenEXTPROC aglSetVirtualScreen; extern aglSetVirtualScreenPROC aglSetVirtualScreen;
extern aglGetVirtualScreenEXTPROC aglGetVirtualScreen; extern aglGetVirtualScreenPROC aglGetVirtualScreen;
extern aglGetVersionEXTPROC aglGetVersion; extern aglGetVersionPROC aglGetVersion;
extern aglSwapBuffersEXTPROC aglSwapBuffers; extern aglSwapBuffersPROC aglSwapBuffers;
extern aglEnableEXTPROC aglEnable; extern aglEnablePROC aglEnable;
extern aglDisableEXTPROC aglDisable; extern aglDisablePROC aglDisable;
extern aglIsEnabledEXTPROC aglIsEnabled; extern aglIsEnabledPROC aglIsEnabled;
extern aglSetIntegerEXTPROC aglSetInteger; extern aglSetIntegerPROC aglSetInteger;
extern aglGetIntegerEXTPROC aglGetInteger; extern aglGetIntegerPROC aglGetInteger;
extern aglUseFontEXTPROC aglUseFont; extern aglUseFontPROC aglUseFont;
extern aglGetErrorEXTPROC aglGetError; extern aglGetErrorPROC aglGetError;
extern aglErrorStringEXTPROC aglErrorString; extern aglErrorStringPROC aglErrorString;
extern aglResetLibraryEXTPROC aglResetlibrary; extern aglResetLibraryPROC aglResetLibrary;
extern aglSurfaceTextureEXTPROC aglSurfaceTexture; extern aglSurfaceTexturePROC aglSurfaceTexture;
/************************************************************************/ /************************************************************************/
@ -5425,6 +5425,9 @@ bool extgl_Open(void);
#ifdef _X11 #ifdef _X11
bool extgl_InitGLX(JNIEnv *env, jobject ext_set, Display *disp, int screen); bool extgl_InitGLX(JNIEnv *env, jobject ext_set, Display *disp, int screen);
#endif #endif
#ifdef _AGL
bool extgl_InitAGL(JNIEnv *env, jobject ext_set);
#endif
void extgl_Close(void); void extgl_Close(void);

View File

@ -42,6 +42,7 @@
#include <Carbon/Carbon.h> #include <Carbon/Carbon.h>
#include <JavaVM/jni.h> #include <JavaVM/jni.h>
#include "org_lwjgl_opengl_Window.h" #include "org_lwjgl_opengl_Window.h"
#include "extgl.h"
static WindowRef win_ref; static WindowRef win_ref;
static bool close_requested; static bool close_requested;
@ -56,24 +57,9 @@ static void throwException(JNIEnv * env, const char * err)
env->DeleteLocalRef(cls); env->DeleteLocalRef(cls);
} }
/*static void dumpRootMenu() {
MenuRef root = AcquireRootMenu();
if (root == NULL)
printf("NULL menu\n");
UInt16 count = CountMenuItems(root);
printf("item count: %d\n", count);
for (int i = 0; i < count; i++) {
Str255 menu_text;
GetMenuItemText(root, i, menu_text);
printf("Item text: %s\n", menu_text);
}
ReleaseMenu(root);
}
*/
static void setWindowTitle(JNIEnv *env, jstring title_obj) { static void setWindowTitle(JNIEnv *env, jstring title_obj) {
const char* title = env->GetStringUTFChars(title_obj, NULL); const char* title = env->GetStringUTFChars(title_obj, NULL);
int str_len = env->GetStringUTFLength(title_obj); CFStringRef cf_title = CFStringCreateWithCStringNoCopy(NULL, title, kCFStringEncodingUTF8, kCFAllocatorNull);
CFStringRef cf_title = CFStringCreateWithBytes(NULL, (const UInt8*)title, str_len, kCFStringEncodingUTF8, false);
if (cf_title == NULL) { if (cf_title == NULL) {
#ifdef _DEBUG #ifdef _DEBUG
printf("Could not set window title\n"); printf("Could not set window title\n");
@ -81,18 +67,8 @@ static void setWindowTitle(JNIEnv *env, jstring title_obj) {
return; return;
} }
SetWindowTitleWithCFString(win_ref, cf_title); SetWindowTitleWithCFString(win_ref, cf_title);
/* MenuRef root;
OSStatus err = CreateNewMenu(1, 0, &root);
assert(err == noErr);
MenuItemIndex item_index;
err = AppendMenuItemTextWithCFString(root, cf_title, 0, FOUR_CHAR_CODE('1234'), &item_index);
assert(err == noErr);
err = SetRootMenu(root);
assert(err == noErr);
ReleaseMenu(root);*/
CFRelease(cf_title); CFRelease(cf_title);
env->ReleaseStringUTFChars(title_obj, title); env->ReleaseStringUTFChars(title_obj, title);
// dumpRootMenu();
} }
static pascal OSStatus doQuit(EventHandlerCallRef next_handler, EventRef event, void *user_data) { static pascal OSStatus doQuit(EventHandlerCallRef next_handler, EventRef event, void *user_data) {
@ -102,37 +78,47 @@ printf("Close requested\n");
} }
static void registerEventHandlers(JNIEnv *env) { static void registerEventHandlers(JNIEnv *env) {
/*EventTargetRef event_target = GetWindowEventTarget(win_ref); EventTypeSpec event_type;
status = InstallStandardEventHandler(event_target);
if (noErr != status) {
DisposeWindow(win_ref);
throwException(env, "Could not install default window event handler");
return;
}*/
EventTypeSpec event_types[1];
OSStatus err; OSStatus err;
EventHandlerUPP handler_upp = NewEventHandlerUPP(doQuit); EventHandlerUPP handler_upp = NewEventHandlerUPP(doQuit);
event_types[0].eventClass = kEventClassWindow; event_type.eventClass = kEventClassWindow;
event_types[0].eventKind = kEventWindowClose; event_type.eventKind = kEventWindowClose;
err = InstallWindowEventHandler(win_ref, handler_upp, 1, event_types, NULL, NULL); err = InstallWindowEventHandler(win_ref, handler_upp, 1, &event_type, NULL, NULL);
if (noErr != err) { if (noErr != err) {
DisposeEventHandlerUPP(handler_upp); DisposeEventHandlerUPP(handler_upp);
throwException(env, "Could not register window event handler"); throwException(env, "Could not register window event handler");
return; return;
} }
event_types[0].eventClass = kEventClassApplication;
event_types[0].eventKind = kEventAppQuit;
/*event_types[1].eventClass = kEventClassAppleEvent;
event_types[1].eventKind = kEventAppleEvent;*/
err = InstallApplicationEventHandler(handler_upp, 1, event_types, NULL, NULL);
if (noErr != err) {
DisposeEventHandlerUPP(handler_upp);
throwException(env, "Could not register application event handler");
return;
}
DisposeEventHandlerUPP(handler_upp); DisposeEventHandlerUPP(handler_upp);
} }
static void destroy(void) {
DisposeWindow(win_ref);
extgl_Close();
}
static bool createContext(JNIEnv *env, jint bpp, jint alpha, jint depth, jint stencil) {
SetPort(GetWindowPort(win_ref));
GLint attrib[] = {AGL_RGBA,
AGL_DOUBLEBUFFER,
AGL_ACCELERATED,
AGL_SINGLE_RENDERER,
AGL_FULLSCREEN,
AGL_MINIMUM_POLICY,
AGL_PIXEL_SIZE, bpp,
AGL_DEPTH_SIZE, depth,
AGL_ALPHA_SIZE, alpha,
AGL_STENCIL_SIZE, stencil,
AGL_NONE};
AGLPixelFormat format = aglChoosePixelFormat(NULL, 0, attrib);
if (format == NULL) {
throwException(env, "Could not find matching pixel format");
return false;
}
printf("Found matching pixel format\n ");
aglDestroyPixelFormat(format);
return true;
}
JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_Window_nIsCloseRequested(JNIEnv *, jclass) { JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_Window_nIsCloseRequested(JNIEnv *, jclass) {
const bool saved = close_requested; const bool saved = close_requested;
@ -140,50 +126,22 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_Window_nIsCloseRequested(JNIEnv
return saved; return saved;
} }
/*OSErr aehandler(const AppleEvent * theAppleEvent, AppleEvent * reply, SInt32 handlerRefcon) {
printf("handler called\n");
return noErr;
}
*/
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_nCreate(JNIEnv *env, jclass clazz, jstring title, jint x, jint y, jint width, jint height, jboolean fullscreen, jint bpp, jint alpha, jint depth, jint stencil, jobject ext_set) { JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_nCreate(JNIEnv *env, jclass clazz, jstring title, jint x, jint y, jint width, jint height, jboolean fullscreen, jint bpp, jint alpha, jint depth, jint stencil, jobject ext_set) {
Rect rect; Rect rect;
OSStatus status; OSStatus status;
const WindowAttributes window_attr = kWindowCloseBoxAttribute| const WindowAttributes window_attr = kWindowCloseBoxAttribute|
kWindowCollapseBoxAttribute| kWindowCollapseBoxAttribute|
kWindowStandardHandlerAttribute; kWindowStandardHandlerAttribute;
// CPSEnableForegroundOperation();
/*//AEObjectInit();
AEEventHandlerUPP handler = NewAEEventHandlerUPP(aehandler);
if (noErr != AEInstallEventHandler(kCoreEventClass, kAEOpenApplication, handler, 0, FALSE))
printf("error\n");
if (noErr != AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, handler, 0, FALSE))
printf("error\n");
if (noErr != AEInstallEventHandler(kCoreEventClass, kAEPrintDocuments, handler, 0, FALSE))
printf("error\n");
if (noErr != AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, handler, 0, FALSE))
printf("error\n");
DisposeAEEventHandlerUPP(handler);*/
/*
* Hacks to activate the application window
*/
/*CFBundleRef bundle = CFBundleGetMainBundle();
if (bundle != NULL) {
printf("bundle != NULL\n");
CFRelease(bundle);
}*/
/*ProcessSerialNumber PSN;
GetCurrentProcess(&PSN);
SetFrontProcess(&PSN);*/
EventLoopRef queue = GetCurrentEventLoop();
EventLoopRef main = GetMainEventLoop();
QuitEventLoop(queue);
QuitEventLoop(main);
/*if (queue == main)
printf("equals\n");*/
SetRect(&rect, x, y, x + width, y + height); SetRect(&rect, x, y, x + width, y + height);
close_requested = false; close_requested = false;
if (!extgl_Open()) {
throwException(env, "Could not load gl library");
return;
}
if (!extgl_InitAGL(env, ext_set)) {
throwException(env, "Could not load agl function pointers");
return;
}
status = CreateNewWindow(kDocumentWindowClass, window_attr, &rect, &win_ref); status = CreateNewWindow(kDocumentWindowClass, window_attr, &rect, &win_ref);
if (noErr != status) { if (noErr != status) {
throwException(env, "Could not create window"); throwException(env, "Could not create window");
@ -193,43 +151,27 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_nCreate(JNIEnv *env, jclass
setWindowTitle(env, title); setWindowTitle(env, title);
const RGBColor background_color = { 0, 0, 0 }; const RGBColor background_color = { 0, 0, 0 };
SetWindowContentColor(win_ref, &background_color); SetWindowContentColor(win_ref, &background_color);
status = TransitionWindow(win_ref, kWindowZoomTransitionEffect, kWindowShowTransitionAction, NULL); if (!createContext(env, bpp, alpha, depth, stencil)) {
if (noErr != status) {
DisposeWindow(win_ref); DisposeWindow(win_ref);
throwException(env, "Could not show window"); extgl_Close();
return; return;
} }
if (!extgl_Initialize(env, ext_set)) {
destroy();
throwException(env, "Could not load gl function pointers");
return;
}
TransitionWindow(win_ref, kWindowZoomTransitionEffect, kWindowShowTransitionAction, NULL);
SelectWindow(win_ref); SelectWindow(win_ref);
InitCursor();
//QuitApplicationEventLoop();
//RunApplicationEventLoop();
} }
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_update JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_update
(JNIEnv *env, jclass clazz) (JNIEnv *env, jclass clazz)
{ {
/*EventRef event;
OSStatus err;
int num_events = GetNumEventsInQueue(GetCurrentEventQueue());
for (int i = 0; i < num_events; i++) {
UInt32 class_type = GetEventClass(event);
UInt32 kind = GetEventKind(event);
UInt32 test = FOUR_CHAR_CODE('eppc');
EventTime event_time = GetEventTime(event);
//UInt32 test = FOUR_CHAR_CODE('appl');
printf("recieved event: %x %x %x at %f\n", class_type, kind, test, event_time);
err = ReceiveNextEvent(0, NULL, 0, true, &event);
/* if (kind == kEventClassAppleEvent)
AEProcessAppleEvent(event);*/
/* ReleaseEvent(event);
}
//RunCurrentEventLoop(0);
/* if (eventLoopTimedOutErr != RunCurrentEventLoop(0))
printf("Could not run current event loop\n");*/
} }
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_nDestroy JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_nDestroy
(JNIEnv *env, jclass clazz) (JNIEnv *env, jclass clazz)
{ {
DisposeWindow(win_ref); destroy();
} }