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

View File

@ -45,6 +45,7 @@
#include "extgl.h"
static WindowRef win_ref;
static AGLContext context;
static bool close_requested;
/*
@ -59,7 +60,7 @@ static void throwException(JNIEnv * env, const char * err)
static void setWindowTitle(JNIEnv *env, jstring title_obj) {
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) {
#ifdef _DEBUG
printf("Could not set window title\n");
@ -93,17 +94,20 @@ static void registerEventHandlers(JNIEnv *env) {
}
static void destroy(void) {
aglSetCurrentContext(NULL);
aglDestroyContext(context);
DisposeWindow(win_ref);
extgl_Close();
}
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,
AGL_DOUBLEBUFFER,
AGL_ACCELERATED,
AGL_SINGLE_RENDERER,
AGL_FULLSCREEN,
//AGL_FULLSCREEN,
AGL_NO_RECOVERY,
AGL_MINIMUM_POLICY,
AGL_PIXEL_SIZE, bpp,
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");
return false;
}
printf("Found matching pixel format\n ");
context = aglCreateContext (format, NULL);
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;
}
@ -139,7 +158,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_nCreate(JNIEnv *env, jclass
return;
}
if (!extgl_InitAGL(env, ext_set)) {
throwException(env, "Could not load agl function pointers");
throwException(env, "Could not load agl symbols");
return;
}
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
(JNIEnv *env, jclass clazz)
{
aglSwapBuffers(context);
}
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_nDestroy