GLU: added quadricCallback(...) methods

GLUQuadricCallbacks: Should now be fully implemented

removed files:
See the README.txt file for more information.
This commit is contained in:
Luke Holden 2002-11-30 03:28:30 +00:00
parent b4adb68d25
commit 1ade683e2d
14 changed files with 269 additions and 189 deletions

View File

@ -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
);
}

View File

@ -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])

52
src/native/aclocal.m4 vendored
View File

@ -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])

View File

@ -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()
{
}

View File

@ -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 */

View File

@ -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];
}
}

View File

@ -1,30 +0,0 @@
//
// File: CallbackManager.h
// Author: alterself
//
// Created on November 28, 2002, 3:15 PM
//
#ifndef _CallbackManager_H
#define _CallbackManager_H
#include <map>
#include <jni.h>
#include "CallbackContainer.h"
class CallbackManager {
public:
CallbackManager();
~CallbackManager();
bool add(jint, CallbackContainer*);
bool del(jint);
CallbackContainer* get(jint);
protected:
private:
std::map<jint, CallbackContainer*> data;
};
#endif /* _CallbackManager_H */

View File

@ -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);
}

View File

@ -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 */

View File

@ -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:

View File

@ -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 = \

View File

@ -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");

View File

@ -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
}

View File

@ -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