From 1e74408a5f15cd4318e870b7b994fa105ce00484 Mon Sep 17 00:00:00 2001 From: Gregory Pierce Date: Mon, 30 Dec 2002 07:09:35 +0000 Subject: [PATCH] Changes to bring in minimal functionality of the OSX port. Still needs virtual function definitions before GL functions can be called properly. --- src/native/macosx/RenderingContext.cpp | 69 +------------------ src/native/macosx/RenderingContext.h | 23 +++---- src/native/macosx/org_lwjgl_Display.cpp | 49 +++++++------ src/native/macosx/org_lwjgl_Sys.cpp | 3 +- .../macosx/org_lwjgl_input_Keyboard.cpp | 4 +- src/native/macosx/org_lwjgl_input_Mouse.cpp | 2 +- src/native/macosx/org_lwjgl_opengl_BaseGL.cpp | 55 ++++++++++++++- 7 files changed, 98 insertions(+), 107 deletions(-) diff --git a/src/native/macosx/RenderingContext.cpp b/src/native/macosx/RenderingContext.cpp index f31550c8..01da7281 100644 --- a/src/native/macosx/RenderingContext.cpp +++ b/src/native/macosx/RenderingContext.cpp @@ -1,13 +1,12 @@ /* * RenderingContext.cpp - * lwjgl + * lwjglOSX * - * Created by Gregory Pierce on Wed Sep 04 2002. + * Created by Gregory Pierce on Sat Dec 28 2002. * Copyright (c) 2002 __MyCompanyName__. All rights reserved. * */ - #include "RenderingContext.h" RenderingContext::RenderingContext() @@ -16,68 +15,4 @@ RenderingContext::RenderingContext() RenderingContext::~RenderingContext() { -} - -/* - ** OpenGL Setup - */ -//GetWindowPort(win) -bool RenderingContext::setupAGL( AGLDrawable pAGLDrawable ) -{ - AGLPixelFormat fmt; - GLboolean ok; - GLint attrib[] = { AGL_RGBA, AGL_NONE }; - - - /* Choose an rgb pixel format */ - fmt = aglChoosePixelFormat(NULL, 0, attrib); - if(fmt == NULL) - { - return false; - } - - /* Create an AGL context */ - aglContext = aglCreateContext(fmt, NULL); - if(aglContext == NULL) - { - return false; - } - - /* Attach the window to the context */ - ok = aglSetDrawable(aglContext, pAGLDrawable ); - if(!ok) - { - return false; - } - - /* Make the context the current context */ - ok = aglSetCurrentContext(aglContext); - if(!ok) - { - return false; - } - - /* Pixel format is no longer needed */ - aglDestroyPixelFormat(fmt); - - return true; -} - -void RenderingContext::destroy(void) -{ - cleanupAGL(); - - // cleanup the window - // - DisposeWindow( windowPtr ); -} - -/* - ** OpenGL Cleanup - */ -void RenderingContext::cleanupAGL() -{ - aglSetCurrentContext(NULL); - aglSetDrawable(aglContext, NULL); - aglDestroyContext(aglContext); } \ No newline at end of file diff --git a/src/native/macosx/RenderingContext.h b/src/native/macosx/RenderingContext.h index ee5beab6..b7dc1450 100644 --- a/src/native/macosx/RenderingContext.h +++ b/src/native/macosx/RenderingContext.h @@ -1,29 +1,26 @@ /* * RenderingContext.h - * lwjgl + * lwjglOSX * - * Created by Gregory Pierce on Wed Sep 04 2002. + * Created by Gregory Pierce on Sat Dec 28 2002. * Copyright (c) 2002 __MyCompanyName__. All rights reserved. * */ #pragma once - #include #include -#include +#include class RenderingContext { - AGLContext aglContext; - Rect rect; - WindowPtr windowPtr; - public: + AGLContext aglContext; + WindowPtr windowPtr; + Rect rect; + + RenderingContext(); ~RenderingContext(); - - void RenderingContext::cleanupAGL(void); - void RenderingContext::destroy(void); - bool RenderingContext::setupAGL( AGLDrawable pAGLDrawable ); -}; \ No newline at end of file +}; + diff --git a/src/native/macosx/org_lwjgl_Display.cpp b/src/native/macosx/org_lwjgl_Display.cpp index 7d5cce84..ca21025b 100644 --- a/src/native/macosx/org_lwjgl_Display.cpp +++ b/src/native/macosx/org_lwjgl_Display.cpp @@ -33,11 +33,11 @@ #include #include #include -#include "RenderingContext.h" #include "org_lwjgl_Display.h" +#include "RenderingContext.h" -RenderingContext * renderingContext; +RenderingContext * renderingContext; /* @@ -61,38 +61,37 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_Display_nCreate { #ifdef _DEBUG printf("Creating display: size %dx%d %dhz %dbpp...\n", width, height, freq, bpp); -#endif - renderingContext = new RenderingContext(); +#endif + InitCursor(); + SetRect( &renderingContext->rect, 0, 0, width, height ); + renderingContext->windowPtr = NewCWindow( NULL, &renderingContext->rect, "LWJGL", true, kWindowShadowDialogProc, (WindowPtr) -1L, true, 0L ); - Rect rect; - SetRect( &rect, 0, 0, width, height ); - - WindowPtr windowPtr = NewCWindow( NULL, &rect, "LWJGL", true, kWindowShadowDialogProc, (WindowPtr) -1L, true, 0L ); + /* + CreateNewWindow( kDocumentWindowClass, + kWindowStandardDocumentAttributes | + kWindowStandardHandlerAttribute, + &rect, + &windowPtr ); + */ - SetPortWindowPort( windowPtr ); + SetPortWindowPort( renderingContext->windowPtr ); - if ( windowPtr == NULL ) + if ( renderingContext->windowPtr == NULL ) { printf("Failed to create a window\n"); - return 1; + return JNI_TRUE; } - ShowWindow( windowPtr ); -/* - pAGLContext = setupAGL( attrib, (AGLDrawable) windowPtr); - if(ctx == NULL) - { - return 1; - } -*/ + ShowWindow( renderingContext->windowPtr ); + jfieldID fid_handle = env->GetStaticFieldID(clazz, "handle", "I"); - env->SetStaticIntField(clazz, fid_handle, (jint) windowPtr ); + env->SetStaticIntField(clazz, fid_handle, (jint) renderingContext->windowPtr ); - return 0; + return JNI_TRUE; } /* @@ -105,7 +104,13 @@ JNIEXPORT void JNICALL Java_org_lwjgl_Display_nDestroy { // cleanup the AGL context // - renderingContext->destroy(); + aglSetCurrentContext(NULL); + aglSetDrawable(renderingContext->aglContext, NULL); + aglDestroyContext(renderingContext->aglContext); + + // cleanup the window + // + DisposeWindow( renderingContext->windowPtr ); #ifdef _DEBUG diff --git a/src/native/macosx/org_lwjgl_Sys.cpp b/src/native/macosx/org_lwjgl_Sys.cpp index 6c34a768..22221468 100644 --- a/src/native/macosx/org_lwjgl_Sys.cpp +++ b/src/native/macosx/org_lwjgl_Sys.cpp @@ -71,7 +71,7 @@ JNIEXPORT jobject JNICALL Java_org_lwjgl_Sys_createDirectBuffer JNIEXPORT jlong JNICALL Java_org_lwjgl_Sys_getTimerResolution (JNIEnv * env, jclass clazz) { - return 0L; + return 0L; } /* @@ -82,6 +82,7 @@ JNIEXPORT jlong JNICALL Java_org_lwjgl_Sys_getTimerResolution JNIEXPORT jlong JNICALL Java_org_lwjgl_Sys_getTime (JNIEnv * env, jclass clazz) { + return 0L; } /* diff --git a/src/native/macosx/org_lwjgl_input_Keyboard.cpp b/src/native/macosx/org_lwjgl_input_Keyboard.cpp index 98f8e04b..959ad3ea 100644 --- a/src/native/macosx/org_lwjgl_input_Keyboard.cpp +++ b/src/native/macosx/org_lwjgl_input_Keyboard.cpp @@ -60,8 +60,8 @@ JNIEXPORT void JNICALL Java_org_lwjgl_input_Keyboard_initIDs globalClassLock = env->NewGlobalRef(clazz); } - fid_readBuffer = env->GetStaticFieldID(clazz, "readBuffer", "Ljava/nio/ByteBuffer;"); - fid_readBufferAddress = env->GetStaticFieldID(clazz, "readBufferAddress", "I"); + //fid_readBuffer = env->GetStaticFieldID(clazz, "readBuffer", "Ljava/nio/ByteBuffer;"); + //fid_readBufferAddress = env->GetStaticFieldID(clazz, "readBufferAddress", "I"); } diff --git a/src/native/macosx/org_lwjgl_input_Mouse.cpp b/src/native/macosx/org_lwjgl_input_Mouse.cpp index 09cc9a56..229c2768 100644 --- a/src/native/macosx/org_lwjgl_input_Mouse.cpp +++ b/src/native/macosx/org_lwjgl_input_Mouse.cpp @@ -69,7 +69,7 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_input_Mouse_nCreate * Signature: ()I */ JNIEXPORT jint JNICALL Java_org_lwjgl_input_Mouse_nGetNumButtons(JNIEnv *env, jclass clazz) { - return (jint)NUM_BUTTONS; + return (jint)2; } /* diff --git a/src/native/macosx/org_lwjgl_opengl_BaseGL.cpp b/src/native/macosx/org_lwjgl_opengl_BaseGL.cpp index 920bff73..7ba63773 100644 --- a/src/native/macosx/org_lwjgl_opengl_BaseGL.cpp +++ b/src/native/macosx/org_lwjgl_opengl_BaseGL.cpp @@ -41,7 +41,9 @@ #include "extgl.h" #include "org_lwjgl_opengl_BaseGL.h" +#include "RenderingContext.h" +extern RenderingContext * renderingContext; /* * Class: org_lwjgl_opengl_BaseGL @@ -51,7 +53,42 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_BaseGL_nCreate (JNIEnv * env, jobject obj, jint colorBits, jint alphaBits, jint depthBits, jint stencilBits) { - return JNI_TRUE; + AGLPixelFormat fmt; + GLboolean ok; + GLint attrib[] = { AGL_RGBA, AGL_NONE }; + + /* Choose an rgb pixel format */ + fmt = aglChoosePixelFormat(NULL, 0, attrib); + if(fmt == NULL) + { + return JNI_FALSE; + } + + /* Create an AGL context */ + renderingContext->aglContext = aglCreateContext(fmt, NULL); + if( renderingContext->aglContext == NULL) + { + return JNI_FALSE; + } + + /* Attach the window to the context */ + ok = aglSetDrawable(renderingContext->aglContext, GetWindowPort(renderingContext->windowPtr) ); + if(!ok) + { + return JNI_FALSE; + } + + /* Make the context the current context */ + ok = aglSetCurrentContext(renderingContext->aglContext); + if(!ok) + { + return JNI_FALSE; + } + + /* Pixel format is no longer needed */ + aglDestroyPixelFormat(fmt); + + return JNI_TRUE; } /* @@ -62,6 +99,13 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_BaseGL_nCreate JNIEXPORT void JNICALL Java_org_lwjgl_opengl_BaseGL_nDestroy (JNIEnv * env, jobject obj) { + // clear out the current rendering context + // + aglSetCurrentContext( NULL ); + + // destroy the context + // + aglDestroyContext( renderingContext->aglContext ); } /* @@ -71,6 +115,9 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_BaseGL_nDestroy */ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_BaseGL_swapBuffers(JNIEnv * env, jobject obj) { + // swap the rendering buffer + // + aglSwapBuffers( renderingContext->aglContext ); } /* @@ -81,6 +128,9 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_BaseGL_swapBuffers(JNIEnv * env, jo JNIEXPORT void JNICALL Java_org_lwjgl_opengl_BaseGL_nMakeCurrent (JNIEnv * env, jobject obj) { + // make the current context the one we have stored + // + aglSetCurrentContext( renderingContext->aglContext ); } /* @@ -91,4 +141,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_BaseGL_nMakeCurrent JNIEXPORT void JNICALL Java_org_lwjgl_opengl_BaseGL_nReleaseContext (JNIEnv *, jobject) { + // release the context + // + aglSetCurrentContext( NULL ); }