|
From: Gregory P. <gre...@us...> - 2002-12-30 07:09:38
|
Update of /cvsroot/java-game-lib/LWJGL/src/native/macosx In directory sc8-pr-cvs1:/tmp/cvs-serv18882 Modified Files: org_lwjgl_opengl_BaseGL.cpp org_lwjgl_input_Mouse.cpp org_lwjgl_input_Keyboard.cpp org_lwjgl_Sys.cpp org_lwjgl_Display.cpp RenderingContext.h RenderingContext.cpp Log Message: Changes to bring in minimal functionality of the OSX port. Still needs virtual function definitions before GL functions can be called properly. Index: org_lwjgl_opengl_BaseGL.cpp CVS Browser: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/java-game-lib/LWJGL/src/native/macosx/org_lwjgl_opengl_BaseGL.cpp =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/native/macosx/org_lwjgl_opengl_BaseGL.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- org_lwjgl_opengl_BaseGL.cpp 18 Dec 2002 03:38:57 -0000 1.1 +++ org_lwjgl_opengl_BaseGL.cpp 30 Dec 2002 07:09:35 -0000 1.2 @@ -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 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_swapBuffers(JNIEnv * env, jobject obj) { + // swap the rendering buffer + // + aglSwapBuffers( renderingContext->aglContext ); } /* @@ -81,6 +128,9 @@ 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_nReleaseContext (JNIEnv *, jobject) { + // release the context + // + aglSetCurrentContext( NULL ); } Index: org_lwjgl_input_Mouse.cpp CVS Browser: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/java-game-lib/LWJGL/src/native/macosx/org_lwjgl_input_Mouse.cpp =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/native/macosx/org_lwjgl_input_Mouse.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- org_lwjgl_input_Mouse.cpp 18 Dec 2002 03:38:57 -0000 1.1 +++ org_lwjgl_input_Mouse.cpp 30 Dec 2002 07:09:35 -0000 1.2 @@ -69,7 +69,7 @@ * Signature: ()I */ JNIEXPORT jint JNICALL Java_org_lwjgl_input_Mouse_nGetNumButtons(JNIEnv *env, jclass clazz) { - return (jint)NUM_BUTTONS; + return (jint)2; } /* Index: org_lwjgl_input_Keyboard.cpp CVS Browser: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/java-game-lib/LWJGL/src/native/macosx/org_lwjgl_input_Keyboard.cpp =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/native/macosx/org_lwjgl_input_Keyboard.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- org_lwjgl_input_Keyboard.cpp 23 Dec 2002 21:50:49 -0000 1.2 +++ org_lwjgl_input_Keyboard.cpp 30 Dec 2002 07:09:35 -0000 1.3 @@ -60,8 +60,8 @@ 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"); } Index: org_lwjgl_Sys.cpp CVS Browser: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/java-game-lib/LWJGL/src/native/macosx/org_lwjgl_Sys.cpp =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/native/macosx/org_lwjgl_Sys.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- org_lwjgl_Sys.cpp 18 Dec 2002 03:38:57 -0000 1.1 +++ org_lwjgl_Sys.cpp 30 Dec 2002 07:09:35 -0000 1.2 @@ -71,7 +71,7 @@ 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_getTime (JNIEnv * env, jclass clazz) { + return 0L; } /* Index: org_lwjgl_Display.cpp CVS Browser: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/java-game-lib/LWJGL/src/native/macosx/org_lwjgl_Display.cpp =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/native/macosx/org_lwjgl_Display.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- org_lwjgl_Display.cpp 20 Dec 2002 23:00:37 -0000 1.4 +++ org_lwjgl_Display.cpp 30 Dec 2002 07:09:35 -0000 1.5 @@ -33,11 +33,11 @@ #include <AGL/agl.h> #include <OpenGL/gl.h> #include <JavaVM/jni.h> -#include "RenderingContext.h" #include "org_lwjgl_Display.h" +#include "RenderingContext.h" -RenderingContext * renderingContext; +RenderingContext * renderingContext; /* @@ -61,38 +61,37 @@ { #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 @@ { // cleanup the AGL context // - renderingContext->destroy(); + aglSetCurrentContext(NULL); + aglSetDrawable(renderingContext->aglContext, NULL); + aglDestroyContext(renderingContext->aglContext); + + // cleanup the window + // + DisposeWindow( renderingContext->windowPtr ); #ifdef _DEBUG Index: RenderingContext.h CVS Browser: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/java-game-lib/LWJGL/src/native/macosx/RenderingContext.h =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/native/macosx/RenderingContext.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- RenderingContext.h 8 Sep 2002 06:20:02 -0000 1.1 +++ RenderingContext.h 30 Dec 2002 07:09:35 -0000 1.2 @@ -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 <Carbon/Carbon.h> #include <AGL/agl.h> -#include <DrawSprocket/DrawSprocket.h> +#include <OpenGL/gl.h> 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 +}; + Index: RenderingContext.cpp CVS Browser: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/java-game-lib/LWJGL/src/native/macosx/RenderingContext.cpp =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/native/macosx/RenderingContext.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- RenderingContext.cpp 8 Sep 2002 06:20:19 -0000 1.1 +++ RenderingContext.cpp 30 Dec 2002 07:09:35 -0000 1.2 @@ -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() { -} - -/* - ** 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); } |