From: Luke H. <lh...@us...> - 2002-11-30 03:28:33
|
Update of /cvsroot/java-game-lib/LWJGL/src/native/common/callbacks In directory sc8-pr-cvs1:/tmp/cvs-serv13660/native/common/callbacks Modified Files: GLUQuadricCallbacks.cpp GLUQuadricCallbacks.h JavaMethod.h Makefile.am README.txt Removed Files: CallbackContainer.cpp CallbackContainer.h CallbackManager.cpp CallbackManager.h Log Message: GLU: added quadricCallback(...) methods GLUQuadricCallbacks: Should now be fully implemented removed files: See the README.txt file for more information. Index: GLUQuadricCallbacks.cpp CVS Browser: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/java-game-lib/LWJGL/src/native/common/callbacks/GLUQuadricCallbacks.cpp =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/native/common/callbacks/GLUQuadricCallbacks.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- GLUQuadricCallbacks.cpp 30 Nov 2002 00:19:59 -0000 1.2 +++ GLUQuadricCallbacks.cpp 30 Nov 2002 03:28:30 -0000 1.3 @@ -7,13 +7,13 @@ #include "GLUQuadricCallbacks.h" +JavaMethod* GLUQuadricCallbacks::errorCallback; + // // Constructor /// -GLUQuadricCallbacks::GLUQuadricCallbacks(GLUquadricObj *quad): - CallbackContainer() +GLUQuadricCallbacks::GLUQuadricCallbacks() { - quadric = quad; errorCallback = NULL; } @@ -22,38 +22,58 @@ // GLUQuadricCallbacks::~GLUQuadricCallbacks() { + clear(); +} + +void GLUQuadricCallbacks::clear() { if (errorCallback != NULL) { delete errorCallback; - } + } } typedef void (GLAPIENTRY *callback_t)(); - -/* having a couple issues. I cant use a pointer to a method as a function pointer? */ - -void GLUQuadricCallbacks::add(JavaMethod *cb, GLenum type) -{ - /* If we are already refering to a callback, get rid of it */ - if (errorCallback != NULL) { - delete errorCallback; - } - +void GLUQuadricCallbacks::set(jint globj, JavaMethod* cb, jint type) +{ switch (type) { case GLU_ERROR: - errorCallback = cb; -// gluQuadricCallback(quadric, type, (callback_t) this->gluError); + /* If we are already refering to a callback, get rid of it */ + if (errorCallback != NULL) { + delete errorCallback; + } + if (cb == NULL) { + gluQuadricCallback((GLUquadricObj *) globj, + (GLenum) type, + NULL); + } + else { + errorCallback = cb; + gluQuadricCallback((GLUquadricObj *) globj, + (GLenum) type, + (callback_t) GLUQuadricCallbacks::gluError); + } break; } } void CALLBACK GLUQuadricCallbacks::gluError(GLenum type) { -// jclass cls = (*errorCallback->env)->GetObjectClass(errorCallback->env, errorCallback->obj); -// jmethodID mid = (*errorCallback->env)->getMethodID(errorCallback->env, cls, errorCallback->method.c_str()); -// if (mid == 0) { -// return; -// } -// /* Hopefully this will end up calling the java method for handling GLU_ERROR for this quad */ -// (*errorCallback->env)->CallVoidMethod(errorCallback->env, errorCallback->obj, mid, (jint) type); + if (errorCallback == NULL) { + return; + } + + JNIEnv * env = errorCallback->env; + jobject obj = errorCallback->obj; + + jclass cls = (jclass) env->GetObjectClass(obj); + + jmethodID mid = env->GetMethodID(cls, + errorCallback->method.c_str(), + "(I)V"); + + if (mid == 0) { + return; + } + /* Hopefully this will end up calling the java method for handling GLU_ERROR for this quad */ + env->CallVoidMethod(obj, mid, (jint) type); } Index: GLUQuadricCallbacks.h CVS Browser: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/java-game-lib/LWJGL/src/native/common/callbacks/GLUQuadricCallbacks.h =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/native/common/callbacks/GLUQuadricCallbacks.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- GLUQuadricCallbacks.h 30 Nov 2002 00:19:59 -0000 1.2 +++ GLUQuadricCallbacks.h 30 Nov 2002 03:28:30 -0000 1.3 @@ -14,26 +14,24 @@ #include <stdio.h> #include "JavaMethod.h" -#include "CallbackContainer.h" #ifndef CALLBACK #define CALLBACK #endif -class GLUQuadricCallbacks : public CallbackContainer { +class GLUQuadricCallbacks { public: - GLUQuadricCallbacks(GLUquadricObj *quad); + GLUQuadricCallbacks(); ~GLUQuadricCallbacks(); - void add(JavaMethod*, GLenum); - void CALLBACK gluError(GLenum); + static void CALLBACK gluError(GLenum); + static void set(jint, JavaMethod*, jint); + static void clear(); protected: private: - JavaMethod* errorCallback; - GLUquadricObj* quadric; + static JavaMethod* errorCallback; }; - #endif /* _GLUQuadricCallbacks_H */ Index: JavaMethod.h CVS Browser: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/java-game-lib/LWJGL/src/native/common/callbacks/JavaMethod.h =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/native/common/callbacks/JavaMethod.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- JavaMethod.h 30 Nov 2002 00:19:59 -0000 1.2 +++ JavaMethod.h 30 Nov 2002 03:28:30 -0000 1.3 @@ -12,12 +12,20 @@ class JavaMethod { public: - JavaMethod(JNIEnv *, jobject, std::string); - ~JavaMethod(); + JavaMethod(JNIEnv *newEnv, jobject newObj, std::string newMethod) + { + env = newEnv; + obj = newObj; + method = newMethod; + } + ~JavaMethod() + { - JNIEnv* env; - jobject obj; - std::string method; + } + + JNIEnv* env; + jobject obj; + std::string method; protected: private: Index: Makefile.am CVS Browser: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/java-game-lib/LWJGL/src/native/common/callbacks/Makefile.am =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/native/common/callbacks/Makefile.am,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- Makefile.am 30 Nov 2002 00:19:59 -0000 1.1 +++ Makefile.am 30 Nov 2002 03:28:30 -0000 1.2 @@ -6,11 +6,6 @@ INCLUDES = -I../ COMMON = \ - CallbackContainer.cpp \ - CallbackContainer.h \ - CallbackManager.cpp \ - CallbackManager.h \ - JavaMethod.cpp \ JavaMethod.h CALLBACKS = \ Index: README.txt CVS Browser: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/java-game-lib/LWJGL/src/native/common/callbacks/README.txt =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/native/common/callbacks/README.txt,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- README.txt 30 Nov 2002 00:19:59 -0000 1.7 +++ README.txt 30 Nov 2002 03:28:30 -0000 1.8 @@ -1,45 +1,62 @@ This is just the start of my callback implementation. -Basically... we have 3 main classes... +Unfortunatly, you cant pass a non static method as an object pointer... +So we can only have callbacks for a single GLU object. However, +according to the OpenGL redbook... this should not be an issue. For example +the redbook states that, a single tess object should be used for an +entire program... and reused for each tessleation. -CallbackManager, which maintains a mapping of objects to callback containers -CallbackContainer, the base class which we extend to implement callbacks for specific objects -JavaMethod, which is a data object that contains information on the method to call. +The implementation: -GLUQuadricCallbacks is a CallbackContainer for working with quadric callbacks -eventually you can expect containers to callbacks for glu nurbs and glu tesselators. +JavaMethod: a data object that contains information on the method to call. + +GLUQuadricCallbacks: a class for working with quadric callbacks + +eventually you can expect callbacks for glu nurbs and glu tesselators. Of course callbacks for other object types should be easy to do using this framework. -Eventually... to add a callback you would do things like: +Note quite as elegent as I wanted, but it works. -/* quad is the reference to our GLUquadricObj - * type is one of the error types specified by gluQuadricCallback - * method is the name of the java method to call */ -JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GLU_quadricCallback - (JNIEnv * env, jobject obj, jint quad, jint type, jint method) { - /* if this quad has no callback container, make one */ - if (CallbackManager.get(quad) == null) { - CallbackManager.put(quad, new GLUQuadricCallbacks((GLUquadricObj *) quad); - } +You would write a callback like this: - /* get the callback container for this quad */ - ((GLUQuadricCallbacks *) CallbackManager.get(quad))->add(new JavaMethod(env, obj, (char*) method), (GLenum) type); +/* + * Class: org_lwjgl_opengl_GLU + * Method: quadricCallback + * Signature: (IILjava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GLU_quadricCallback__IILjava_lang_String_2 + (JNIEnv * env, jobject obj, jint quad, jint type, jstring method) +{ + GLUQuadricCallbacks::set(quad, + new JavaMethod(env, obj, env->GetStringUTFChars(method, 0)), + type); + CHECK_GL_ERROR } -JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GLU_deleteQuadric - (JNIEnv * env, jobject obj, jint quad) { - /* Delete the quadric from memory */ - gluDeleteQuadric((GLUquadricObj *) quad); - - /* delete any callbacks we assigned to the quadric */ - CallbackManager.del(quad); +/* + * Class: org_lwjgl_opengl_GLU + * Method: quadricCallback + * Signature: (IILjava/lang/Object;Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GLU_quadricCallback__IILjava_lang_Object_2Ljava_lang_String_2 + (JNIEnv * env, jobject obj, jint quad, jint type, jobject target, jstring method) +{ + GLUQuadricCallbacks::set(quad, + new JavaMethod(env, target, env->GetStringUTFChars(method, 0)), + type); + CHECK_GL_ERROR } -then from java: +and call it from java: /* myquadric is a reference to a GLUquadricObj returned by glu.newQuadric() * GLU.ERROR is the callback type * errorCallback is the method you wish to be called */ glu.quadricCallback(myquadric, GLU.ERROR, "errorCallback"); + +or + +glu.quadricCallback(myquadric, GLU.ERROR, someObject, "errorCallback"); + --- CallbackContainer.cpp DELETED --- CVS Browser: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/java-game-lib/LWJGL/src/native/common/callbacks/CallbackContainer.cpp --- CallbackContainer.h DELETED --- CVS Browser: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/java-game-lib/LWJGL/src/native/common/callbacks/CallbackContainer.h --- CallbackManager.cpp DELETED --- CVS Browser: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/java-game-lib/LWJGL/src/native/common/callbacks/CallbackManager.cpp --- CallbackManager.h DELETED --- CVS Browser: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/java-game-lib/LWJGL/src/native/common/callbacks/CallbackManager.h |