*** empty log message ***

This commit is contained in:
Elias Naur 2003-09-29 11:58:35 +00:00
parent 4111a08857
commit 42e8f13cbe
2 changed files with 80 additions and 69 deletions

View File

@ -1286,7 +1286,8 @@ void * lib_glu_handle = NULL;
#endif #endif
#ifdef _AGL #ifdef _AGL
CFBundleRef gBundleRefOpenGL = NULL; CFBundleRef opengl_bundle_ref = NULL;
CFBundleRef agl_bundle_ref = NULL;
#endif #endif
#define EXTGL_SANITY_CHECK(e,h,x) if (extgl_error) { \ #define EXTGL_SANITY_CHECK(e,h,x) if (extgl_error) { \
@ -1319,13 +1320,14 @@ static void insertExtension(JNIEnv *env, jobject ext_set, const char *ext) {
#ifdef _AGL #ifdef _AGL
// ------------------------- // -------------------------
OSStatus aglInitEntryPoints (void) static CFBundleRef loadBundle(const Str255 frameworkName)
{ {
OSStatus err = noErr; OSStatus err = noErr;
const Str255 frameworkName = "\pOpenGL.framework";
FSRefParam fileRefParam; FSRefParam fileRefParam;
FSRef fileRef; FSRef fileRef;
CFURLRef bundleURLOpenGL; CFURLRef bundleURLOpenGL;
CFBundleRef bundle_ref;
memset(&fileRefParam, 0, sizeof(fileRefParam)); memset(&fileRefParam, 0, sizeof(fileRefParam));
memset(&fileRef, 0, sizeof(fileRef)); memset(&fileRef, 0, sizeof(fileRef));
fileRefParam.ioNamePtr = frameworkName; fileRefParam.ioNamePtr = frameworkName;
@ -1336,8 +1338,10 @@ OSStatus aglInitEntryPoints (void)
err = FindFolder (kSystemDomain, kFrameworksFolderType, false, &fileRefParam.ioVRefNum, &fileRefParam.ioDirID); err = FindFolder (kSystemDomain, kFrameworksFolderType, false, &fileRefParam.ioVRefNum, &fileRefParam.ioDirID);
if (noErr != err) if (noErr != err)
{ {
DebugStr ("\pCould not find frameworks folder"); #ifdef _DEBUG
return err; printf("Could not find frameworks folder\n");
#endif
return NULL;
} }
// make FSRef for folder // make FSRef for folder
@ -1350,7 +1354,7 @@ OSStatus aglInitEntryPoints (void)
#ifdef _DEBUG #ifdef _DEBUG
printf("Could make FSref to frameworks folder\n"); printf("Could make FSref to frameworks folder\n");
#endif #endif
return err; return NULL;
} }
// create URL to folder // create URL to folder
@ -1359,58 +1363,40 @@ OSStatus aglInitEntryPoints (void)
if (!bundleURLOpenGL) if (!bundleURLOpenGL)
{ {
#ifdef _DEBUG #ifdef _DEBUG
printf("Could create OpenGL Framework bundle URL\n"); printf("Could create framework URL\n");
#endif #endif
return paramErr; return NULL;
} }
// create ref to GL's bundle bundle_ref = CFBundleCreate(kCFAllocatorDefault,bundleURLOpenGL);
// CFRelease (bundleURLOpenGL);
gBundleRefOpenGL = CFBundleCreate (kCFAllocatorDefault,bundleURLOpenGL); if (bundle_ref == NULL)
if (!gBundleRefOpenGL)
{ {
#ifdef _DEBUG #ifdef _DEBUG
printf("Could not create OpenGL Framework bundle\n"); printf("Could not load framework\n");
#endif #endif
return paramErr; return NULL;
} }
// release created bundle
//
CFRelease (bundleURLOpenGL);
// 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(bundle_ref))
{ {
#ifdef _DEBUG #ifdef _DEBUG
printf("Could not load MachO executable\n"); printf("Could not load MachO executable\n");
#endif #endif
return paramErr; CFRelease(bundle_ref);
return NULL;
} }
return err; return bundle_ref;
} }
static void aglUnloadFramework(CFBundleRef f)
static void aglDellocEntryPoints (void)
{ {
if (gBundleRefOpenGL != NULL) CFBundleUnloadExecutable(f);
{ CFRelease(f);
// unload the bundle's code.
CFBundleUnloadExecutable (gBundleRefOpenGL);
CFRelease (gBundleRefOpenGL);
gBundleRefOpenGL = NULL;
}
} }
static void * aglGetProcAddress (char * pszProc)
{
CFStringRef str = CFStringCreateWithCStringNoCopy(NULL, pszProc, kCFStringEncodingUTF8, kCFAllocatorNull);
void *func_pointer = CFBundleGetFunctionPointerForName(gBundleRefOpenGL, str);
CFRelease(str);
return func_pointer;
}
#endif #endif
/* getProcAddress */ /* getProcAddress */
@ -1456,14 +1442,19 @@ static void *extgl_GetProcAddress(char *name)
#endif #endif
#ifdef _AGL #ifdef _AGL
void *t = aglGetProcAddress(name); CFStringRef str = CFStringCreateWithCStringNoCopy(NULL, name, kCFStringEncodingUTF8, kCFAllocatorNull);
if (t == NULL) { void *func_pointer = CFBundleGetFunctionPointerForName(opengl_bundle_ref, str);
if (func_pointer == NULL) {
func_pointer = CFBundleGetFunctionPointerForName(agl_bundle_ref, str);
if (func_pointer == NULL) {
#ifdef _DEBUG #ifdef _DEBUG
printf("Could not locate symbol %s\n", name); printf("Could not locate symbol %s\n", name);
#endif #endif
extgl_error = true; extgl_error = true;
}
} }
return t; CFRelease(str);
return func_pointer;
#endif #endif
} }
@ -3298,6 +3289,20 @@ bool extgl_Initialize(JNIEnv *env, jobject ext_set)
return true; return true;
} }
#ifdef _AGL
bool extgl_Open(void) {
opengl_bundle_ref = loadBundle("\pOpenGL.framework");
if (opengl_bundle_ref == NULL)
return false;
agl_bundle_ref = loadBundle("\pAGL.framework");
if (agl_bundle_ref == NULL) {
aglUnloadFramework(opengl_bundle_ref);
return false;
}
return true;
}
#endif
#ifdef _X11 #ifdef _X11
bool extgl_Open() bool extgl_Open()
{ {
@ -3313,6 +3318,7 @@ bool extgl_Open()
#ifdef _DEBUG #ifdef _DEBUG
printf("Error loading libGLU.so.1: %s\n", dlerror()); printf("Error loading libGLU.so.1: %s\n", dlerror());
#endif #endif
dlclose(lib_gl_handle);
return false; return false;
} }
return true; return true;
@ -3329,30 +3335,14 @@ bool extgl_Open(void)
if (lib_gl_handle == NULL) if (lib_gl_handle == NULL)
return false; return false;
lib_glu_handle = LoadLibrary("glu32.dll"); lib_glu_handle = LoadLibrary("glu32.dll");
if (lib_glu_handle == NULL) if (lib_glu_handle == NULL) {
FreeLibrary(lib_gl_handle);
return false; return false;
}
return true; return true;
} }
#endif /* WIN32 */ #endif /* WIN32 */
#ifdef _AGL
bool extgl_Open(void)
{
OSStatus err = aglInitEntryPoints();
if ( noErr != err )
{
// if we encountered an error while initializing OpenGL
// we're hosed - return
//
return false;
}
// open gl framework initialized just fine
//
return true;
}
#endif /* _AGL */
void extgl_Close(void) void extgl_Close(void)
{ {
#ifdef _X11 #ifdef _X11
@ -3364,7 +3354,8 @@ void extgl_Close(void)
FreeLibrary(lib_glu_handle); FreeLibrary(lib_glu_handle);
#endif #endif
#ifdef _AGL #ifdef _AGL
aglDellocEntryPoints(); aglUnloadFramework(opengl_bundle_ref);
aglUnloadFramework(agl_bundle_ref);
#endif #endif
} }

View File

@ -45,6 +45,7 @@
#include "extgl.h" #include "extgl.h"
static WindowRef win_ref; static WindowRef win_ref;
static AGLContext context;
static bool close_requested; static bool close_requested;
/* /*
@ -59,7 +60,7 @@ static void throwException(JNIEnv * env, const char * err)
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);
CFStringRef cf_title = CFStringCreateWithCStringNoCopy(NULL, title, kCFStringEncodingUTF8, kCFAllocatorNull); CFStringRef cf_title = CFStringCreateWithCString(NULL, title, kCFStringEncodingUTF8);
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");
@ -93,17 +94,20 @@ static void registerEventHandlers(JNIEnv *env) {
} }
static void destroy(void) { static void destroy(void) {
aglSetCurrentContext(NULL);
aglDestroyContext(context);
DisposeWindow(win_ref); DisposeWindow(win_ref);
extgl_Close(); extgl_Close();
} }
static bool createContext(JNIEnv *env, jint bpp, jint alpha, jint depth, jint stencil) { static bool createContext(JNIEnv *env, jint bpp, jint alpha, jint depth, jint stencil) {
SetPort(GetWindowPort(win_ref)); AGLDrawable drawable = GetWindowPort(win_ref);
SetPort(drawable);
GLint attrib[] = {AGL_RGBA, GLint attrib[] = {AGL_RGBA,
AGL_DOUBLEBUFFER, AGL_DOUBLEBUFFER,
AGL_ACCELERATED, AGL_ACCELERATED,
AGL_SINGLE_RENDERER, //AGL_FULLSCREEN,
AGL_FULLSCREEN, AGL_NO_RECOVERY,
AGL_MINIMUM_POLICY, AGL_MINIMUM_POLICY,
AGL_PIXEL_SIZE, bpp, AGL_PIXEL_SIZE, bpp,
AGL_DEPTH_SIZE, depth, AGL_DEPTH_SIZE, depth,
@ -115,8 +119,23 @@ static bool createContext(JNIEnv *env, jint bpp, jint alpha, jint depth, jint st
throwException(env, "Could not find matching pixel format"); throwException(env, "Could not find matching pixel format");
return false; return false;
} }
printf("Found matching pixel format\n "); context = aglCreateContext (format, NULL);
aglDestroyPixelFormat(format); aglDestroyPixelFormat(format);
if (context == NULL) {
throwException(env, "Could not create context");
return false;
}
//if (aglSetFullScreen(context, 800, 600, 85, 0) == GL_FALSE) {
if (aglSetDrawable(context, drawable) == GL_FALSE) {
aglDestroyContext(context);
throwException(env, "Could not attach context");
return false;
}
if (aglSetCurrentContext(context) == GL_FALSE) {
aglDestroyContext(context);
throwException(env, "Could not set current context");
return false;
}
return true; return true;
} }
@ -139,7 +158,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_nCreate(JNIEnv *env, jclass
return; return;
} }
if (!extgl_InitAGL(env, ext_set)) { if (!extgl_InitAGL(env, ext_set)) {
throwException(env, "Could not load agl function pointers"); throwException(env, "Could not load agl symbols");
return; return;
} }
status = CreateNewWindow(kDocumentWindowClass, window_attr, &rect, &win_ref); status = CreateNewWindow(kDocumentWindowClass, window_attr, &rect, &win_ref);
@ -168,6 +187,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_nCreate(JNIEnv *env, jclass
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)
{ {
aglSwapBuffers(context);
} }
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_nDestroy JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_nDestroy