From 1ade683e2d00a1808823ed01011575d11cf480a8 Mon Sep 17 00:00:00 2001 From: Luke Holden Date: Sat, 30 Nov 2002 03:28:30 +0000 Subject: [PATCH] GLU: added quadricCallback(...) methods GLUQuadricCallbacks: Should now be fully implemented removed files: See the README.txt file for more information. --- src/java/org/lwjgl/opengl/GLU.java | 14 ++++ src/native/acinclude.m4 | 52 ++++++++++++++ src/native/aclocal.m4 | 52 ++++++++++++++ .../common/callbacks/CallbackContainer.cpp | 23 ------- .../common/callbacks/CallbackContainer.h | 23 ------- .../common/callbacks/CallbackManager.cpp | 46 ------------- src/native/common/callbacks/CallbackManager.h | 30 -------- .../common/callbacks/GLUQuadricCallbacks.cpp | 66 +++++++++++------- .../common/callbacks/GLUQuadricCallbacks.h | 14 ++-- src/native/common/callbacks/JavaMethod.h | 18 +++-- src/native/common/callbacks/Makefile.am | 5 -- src/native/common/callbacks/README.txt | 69 ++++++++++++------- src/native/common/org_lwjgl_opengl_GLU.cpp | 30 ++++++++ src/native/common/org_lwjgl_opengl_GLU.h | 16 +++++ 14 files changed, 269 insertions(+), 189 deletions(-) delete mode 100644 src/native/common/callbacks/CallbackContainer.cpp delete mode 100644 src/native/common/callbacks/CallbackContainer.h delete mode 100644 src/native/common/callbacks/CallbackManager.cpp delete mode 100644 src/native/common/callbacks/CallbackManager.h diff --git a/src/java/org/lwjgl/opengl/GLU.java b/src/java/org/lwjgl/opengl/GLU.java index 84f14140..7c61e240 100644 --- a/src/java/org/lwjgl/opengl/GLU.java +++ b/src/java/org/lwjgl/opengl/GLU.java @@ -353,4 +353,18 @@ public class GLU implements GLUConstants { int slices, int stacks ); + + + public native void quadricCallback( + int target, + int type, + String method + ); + public native void quadricCallback( + int target, + int type, + Object obj, + String method + ); + } diff --git a/src/native/acinclude.m4 b/src/native/acinclude.m4 index d7022837..8fa78a7a 100644 --- a/src/native/acinclude.m4 +++ b/src/native/acinclude.m4 @@ -46,6 +46,54 @@ dnl but WITHOUT ANY WARRANTY, to the extent permitted by law; without dnl even the implied warranty of MERCHANTABILITY or FITNESS FOR A dnl PARTICULAR PURPOSE. +dnl aclocal.m4 generated automatically by aclocal 1.4-p5 + +dnl Copyright (C) 1994, 1995-8, 1999, 2001 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl This program is distributed in the hope that it will be useful, +dnl but WITHOUT ANY WARRANTY, to the extent permitted by law; without +dnl even the implied warranty of MERCHANTABILITY or FITNESS FOR A +dnl PARTICULAR PURPOSE. + +dnl aclocal.m4 generated automatically by aclocal 1.4-p5 + +dnl Copyright (C) 1994, 1995-8, 1999, 2001 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl This program is distributed in the hope that it will be useful, +dnl but WITHOUT ANY WARRANTY, to the extent permitted by law; without +dnl even the implied warranty of MERCHANTABILITY or FITNESS FOR A +dnl PARTICULAR PURPOSE. + +dnl aclocal.m4 generated automatically by aclocal 1.4-p5 + +dnl Copyright (C) 1994, 1995-8, 1999, 2001 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl This program is distributed in the hope that it will be useful, +dnl but WITHOUT ANY WARRANTY, to the extent permitted by law; without +dnl even the implied warranty of MERCHANTABILITY or FITNESS FOR A +dnl PARTICULAR PURPOSE. + +dnl aclocal.m4 generated automatically by aclocal 1.4-p5 + +dnl Copyright (C) 1994, 1995-8, 1999, 2001 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl This program is distributed in the hope that it will be useful, +dnl but WITHOUT ANY WARRANTY, to the extent permitted by law; without +dnl even the implied warranty of MERCHANTABILITY or FITNESS FOR A +dnl PARTICULAR PURPOSE. + # Do all the work for Automake. This macro actually does too much -- # some checks are only needed if your package does certain things. # But this isn't really a big deal. @@ -3606,3 +3654,7 @@ ifelse([AC_DISABLE_FAST_INSTALL]) + + + + diff --git a/src/native/aclocal.m4 b/src/native/aclocal.m4 index 442cbb85..b5e65698 100644 --- a/src/native/aclocal.m4 +++ b/src/native/aclocal.m4 @@ -58,6 +58,54 @@ dnl but WITHOUT ANY WARRANTY, to the extent permitted by law; without dnl even the implied warranty of MERCHANTABILITY or FITNESS FOR A dnl PARTICULAR PURPOSE. +dnl aclocal.m4 generated automatically by aclocal 1.4-p5 + +dnl Copyright (C) 1994, 1995-8, 1999, 2001 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl This program is distributed in the hope that it will be useful, +dnl but WITHOUT ANY WARRANTY, to the extent permitted by law; without +dnl even the implied warranty of MERCHANTABILITY or FITNESS FOR A +dnl PARTICULAR PURPOSE. + +dnl aclocal.m4 generated automatically by aclocal 1.4-p5 + +dnl Copyright (C) 1994, 1995-8, 1999, 2001 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl This program is distributed in the hope that it will be useful, +dnl but WITHOUT ANY WARRANTY, to the extent permitted by law; without +dnl even the implied warranty of MERCHANTABILITY or FITNESS FOR A +dnl PARTICULAR PURPOSE. + +dnl aclocal.m4 generated automatically by aclocal 1.4-p5 + +dnl Copyright (C) 1994, 1995-8, 1999, 2001 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl This program is distributed in the hope that it will be useful, +dnl but WITHOUT ANY WARRANTY, to the extent permitted by law; without +dnl even the implied warranty of MERCHANTABILITY or FITNESS FOR A +dnl PARTICULAR PURPOSE. + +dnl aclocal.m4 generated automatically by aclocal 1.4-p5 + +dnl Copyright (C) 1994, 1995-8, 1999, 2001 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl This program is distributed in the hope that it will be useful, +dnl but WITHOUT ANY WARRANTY, to the extent permitted by law; without +dnl even the implied warranty of MERCHANTABILITY or FITNESS FOR A +dnl PARTICULAR PURPOSE. + # Do all the work for Automake. This macro actually does too much -- # some checks are only needed if your package does certain things. # But this isn't really a big deal. @@ -3619,3 +3667,7 @@ ifelse([AC_DISABLE_FAST_INSTALL]) + + + + diff --git a/src/native/common/callbacks/CallbackContainer.cpp b/src/native/common/callbacks/CallbackContainer.cpp deleted file mode 100644 index 02db926c..00000000 --- a/src/native/common/callbacks/CallbackContainer.cpp +++ /dev/null @@ -1,23 +0,0 @@ -// -// File: CallbackContainer.cc -// Author: alterself -// -// Created on November 28, 2002, 8:42 PM -// - -#include "CallbackContainer.h" - -// -// Constructor -/// -CallbackContainer::CallbackContainer() -{ -} - -// -// Destructor -// -CallbackContainer::~CallbackContainer() -{ -} - diff --git a/src/native/common/callbacks/CallbackContainer.h b/src/native/common/callbacks/CallbackContainer.h deleted file mode 100644 index 0b8fa6d9..00000000 --- a/src/native/common/callbacks/CallbackContainer.h +++ /dev/null @@ -1,23 +0,0 @@ -// -// File: CallbackContainer.h -// Author: alterself -// -// Created on November 28, 2002, 8:42 PM -// - -#ifndef _CallbackContainer_H -#define _CallbackContainer_H - -class CallbackContainer { -public: - CallbackContainer(); - ~CallbackContainer(); - -protected: - -private: - -}; - -#endif /* _CallbackContainer_H */ - diff --git a/src/native/common/callbacks/CallbackManager.cpp b/src/native/common/callbacks/CallbackManager.cpp deleted file mode 100644 index 622e29c3..00000000 --- a/src/native/common/callbacks/CallbackManager.cpp +++ /dev/null @@ -1,46 +0,0 @@ -// -// File: CallbackManager.cc -// Author: alterself -// -// Created on November 28, 2002, 3:15 PM -// - -#include "CallbackManager.h" - -// -// Constructor -/// -CallbackManager::CallbackManager() -{ -} - -// -// Destructor -// -CallbackManager::~CallbackManager() -{ - data.clear(); -} - -bool CallbackManager::add(jint key, CallbackContainer *value) -{ - data[key] = value; -} - -bool CallbackManager::del(jint key) -{ - if (data.find(key) != data.end()) { - delete data[key]; - data.erase(key); - } -} - -CallbackContainer * CallbackManager::get(jint key) -{ - if (data.find(key) == data.end()) { - return NULL; - } - else { - return data[key]; - } -} diff --git a/src/native/common/callbacks/CallbackManager.h b/src/native/common/callbacks/CallbackManager.h deleted file mode 100644 index b0afbdf3..00000000 --- a/src/native/common/callbacks/CallbackManager.h +++ /dev/null @@ -1,30 +0,0 @@ -// -// File: CallbackManager.h -// Author: alterself -// -// Created on November 28, 2002, 3:15 PM -// - -#ifndef _CallbackManager_H -#define _CallbackManager_H -#include -#include - -#include "CallbackContainer.h" - -class CallbackManager { -public: - CallbackManager(); - ~CallbackManager(); - - bool add(jint, CallbackContainer*); - bool del(jint); - CallbackContainer* get(jint); - -protected: -private: - std::map data; -}; - -#endif /* _CallbackManager_H */ - diff --git a/src/native/common/callbacks/GLUQuadricCallbacks.cpp b/src/native/common/callbacks/GLUQuadricCallbacks.cpp index 6dd7c23b..0fc982ef 100644 --- a/src/native/common/callbacks/GLUQuadricCallbacks.cpp +++ b/src/native/common/callbacks/GLUQuadricCallbacks.cpp @@ -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(GLUquadricObj *quad): // 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); } diff --git a/src/native/common/callbacks/GLUQuadricCallbacks.h b/src/native/common/callbacks/GLUQuadricCallbacks.h index e78248db..ca4f97bd 100644 --- a/src/native/common/callbacks/GLUQuadricCallbacks.h +++ b/src/native/common/callbacks/GLUQuadricCallbacks.h @@ -14,26 +14,24 @@ #include #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 */ diff --git a/src/native/common/callbacks/JavaMethod.h b/src/native/common/callbacks/JavaMethod.h index 92c4d672..2b3a87f9 100644 --- a/src/native/common/callbacks/JavaMethod.h +++ b/src/native/common/callbacks/JavaMethod.h @@ -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: diff --git a/src/native/common/callbacks/Makefile.am b/src/native/common/callbacks/Makefile.am index 31869b8c..4da41418 100644 --- a/src/native/common/callbacks/Makefile.am +++ b/src/native/common/callbacks/Makefile.am @@ -6,11 +6,6 @@ libcallbacks_la_CPPFLAGS = -D_DEBUG INCLUDES = -I../ COMMON = \ - CallbackContainer.cpp \ - CallbackContainer.h \ - CallbackManager.cpp \ - CallbackManager.h \ - JavaMethod.cpp \ JavaMethod.h CALLBACKS = \ diff --git a/src/native/common/callbacks/README.txt b/src/native/common/callbacks/README.txt index 15e0dbfe..54cb12cf 100644 --- a/src/native/common/callbacks/README.txt +++ b/src/native/common/callbacks/README.txt @@ -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"); + diff --git a/src/native/common/org_lwjgl_opengl_GLU.cpp b/src/native/common/org_lwjgl_opengl_GLU.cpp index 46d34ef1..611ae23f 100644 --- a/src/native/common/org_lwjgl_opengl_GLU.cpp +++ b/src/native/common/org_lwjgl_opengl_GLU.cpp @@ -48,6 +48,8 @@ #include "checkGLerror.h" #include "GL/glu.h" +#include "callbacks/GLUQuadricCallbacks.h" + /* * Class: org_lwjgl_opengl_GLU * Method: getString @@ -275,3 +277,31 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GLU_sphere CHECK_GL_ERROR } +/* + * 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 +} + +/* + * 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 +} + diff --git a/src/native/common/org_lwjgl_opengl_GLU.h b/src/native/common/org_lwjgl_opengl_GLU.h index 33b924f3..380bd98a 100644 --- a/src/native/common/org_lwjgl_opengl_GLU.h +++ b/src/native/common/org_lwjgl_opengl_GLU.h @@ -175,6 +175,22 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GLU_quadricTexture JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GLU_sphere (JNIEnv *, jobject, jint, jdouble, jint, jint); +/* + * 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 *, jobject, jint, jint, jstring); + +/* + * 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 *, jobject, jint, jint, jobject, jstring); + #ifdef __cplusplus } #endif