callbacks: The start of my callback implementation.

Makefile.am: small fix for the CPPFLAGS variable
This commit is contained in:
Luke Holden 2002-11-29 06:06:16 +00:00
parent 92538f7674
commit fe7692179d
10 changed files with 273 additions and 1 deletions

View file

@ -1,7 +1,7 @@
noinst_LTLIBRARIES = libcommon.la
libcommon_la_SOURCES = $(COMMON)
liblwjgl_la_CPPFLAGS = -D_DEBUG
libcommon_la_CPPFLAGS = -D_DEBUG
COMMON = \
extal.c \

View file

@ -0,0 +1,23 @@
//
// File: CallbackContainer.cc
// Author: alterself
//
// Created on November 28, 2002, 8:42 PM
//
#include "CallbackContainer.h"
//
// Constructor
///
CallbackContainer::CallbackContainer()
{
}
//
// Destructor
//
CallbackContainer::~CallbackContainer()
{
}

View file

@ -0,0 +1,23 @@
//
// 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

@ -0,0 +1,23 @@
//
// File: CallbackManager.cc
// Author: alterself
//
// Created on November 28, 2002, 3:15 PM
//
#include "CallbackManager.h"
//
// Constructor
///
CallbackManager::CallbackManager()
{
}
//
// Destructor
//
CallbackManager::~CallbackManager()
{
}

View file

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

View file

@ -0,0 +1,53 @@
//
// File: GLUQuadricCallback.cc
// Author: alterself
//
// Created on November 28, 2002, 8:21 PM
//
#include "GLUQuadricCallback.h"
//
// Constructor
///
GLUQuadricCallbacks::GLUQuadricCallbacks(GLUquadricObj *quad):
CallbackContainer()
{
quadric = quad;
errorCallback = NULL;
}
//
// Destructor
//
GLUQuadricCallbacks::~GLUQuadricCallbacks()
{
if (errorCallback != NULL) {
delete errorCallback;
}
delete quad;
}
void GLUQuadricCallbacks::add(JavaMethod *cb, GLenum type)
{
/* If we are already refering to a callback, get rid of it */
if (gluError != NULL) {
delete errorCallback;
}
switch (type) {
case GLU_ERROR;
errorCallback = cb;
gluQuadricCallback(quad, type, *gluError)
break;
};
}
void 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);
}

View file

@ -0,0 +1,28 @@
//
// File: GLUQuadricCallback.h
// Author: alterself
//
// Created on November 28, 2002, 8:21 PM
//
#ifndef _GLUQuadricCallback_H
#define _GLUQuadricCallback_H
#include "extgl.h"
class GLUQuadricCallbacks : public Callback {
public:
GLUQuadricCallback(jint quad);
~GLUQuadricCallback();
void add(JavaMethod*, GLenum);
void gluError(GLenum);
protected:
private:
GLUquadricObj *quadric;
JavaMethod *errorCallback;
};
#endif /* _GLUQuadricCallback_H */

View file

@ -0,0 +1,27 @@
//
// File: Callback.cc
// Author: alterself
//
// Created on November 28, 2002, 3:37 PM
//
#include "Callback.h"
//
// Constructor
///
JavaMethod::JavaMethod(JNIEnv *newEnv, jobject newObj, string newMethod)
{
env = newEnv;
obj = newObj;
method = newMethod;
}
//
// Destructor
//
JavaMethod::~JavaMethod()
{
delete(method);
}

View file

@ -0,0 +1,28 @@
//
// File: Callback.h
// Author: alterself
//
// Created on November 28, 2002, 3:37 PM
//
#ifndef _JavaMethod_H
#define _JavaMethod_H
#include <string>
class JavaMethod {
public:
JavaMethod(JNIEnv *, jobject, string);
~JavaMethod();
protected:
private:
JNIEnv* env;
jobject obj;
string method;
};
#endif /* _JavaMethod_H */

View file

@ -0,0 +1,39 @@
This is just the start of my callback implementation.
As it is, it wont compile =)
Basically... we have 3 main classes...
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 which contains information on which method to call from where
GLUQuadricCallbacks is a CallbackContainer for working with quadric callbacks
eventually you can expect containers to 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:
/* 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);
}
/* get the callback container for this quad */
CallbackManager.get(quad)->add(new JavaMethod(env, obj, (char*)method), (GLenum) type);
}
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);
}