2002-11-29 07:06:16 +01:00
|
|
|
//
|
|
|
|
|
// File: GLUQuadricCallback.cc
|
|
|
|
|
// Author: alterself
|
|
|
|
|
//
|
|
|
|
|
// Created on November 28, 2002, 8:21 PM
|
|
|
|
|
//
|
|
|
|
|
|
2002-11-30 01:19:59 +01:00
|
|
|
#include "GLUQuadricCallbacks.h"
|
2002-11-29 07:06:16 +01:00
|
|
|
|
2002-11-30 04:28:30 +01:00
|
|
|
JavaMethod* GLUQuadricCallbacks::errorCallback;
|
|
|
|
|
|
2002-11-29 07:06:16 +01:00
|
|
|
//
|
|
|
|
|
// Constructor
|
|
|
|
|
///
|
2002-11-30 04:28:30 +01:00
|
|
|
GLUQuadricCallbacks::GLUQuadricCallbacks()
|
2002-11-29 07:06:16 +01:00
|
|
|
{
|
|
|
|
|
errorCallback = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Destructor
|
|
|
|
|
//
|
|
|
|
|
GLUQuadricCallbacks::~GLUQuadricCallbacks()
|
|
|
|
|
{
|
2002-11-30 04:28:30 +01:00
|
|
|
clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GLUQuadricCallbacks::clear() {
|
2002-11-29 07:06:16 +01:00
|
|
|
if (errorCallback != NULL) {
|
|
|
|
|
delete errorCallback;
|
2002-11-30 04:28:30 +01:00
|
|
|
}
|
2002-11-29 07:06:16 +01:00
|
|
|
}
|
|
|
|
|
|
2002-11-30 01:19:59 +01:00
|
|
|
typedef void (GLAPIENTRY *callback_t)();
|
|
|
|
|
|
2002-11-30 04:28:30 +01:00
|
|
|
void GLUQuadricCallbacks::set(jint globj, JavaMethod* cb, jint type)
|
|
|
|
|
{
|
2002-11-29 07:06:16 +01:00
|
|
|
switch (type) {
|
2002-11-30 01:19:59 +01:00
|
|
|
case GLU_ERROR:
|
2002-11-30 04:28:30 +01:00
|
|
|
/* 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);
|
|
|
|
|
}
|
2002-11-29 07:06:16 +01:00
|
|
|
break;
|
2002-11-30 01:19:59 +01:00
|
|
|
}
|
2002-11-29 07:06:16 +01:00
|
|
|
}
|
|
|
|
|
|
2002-11-30 01:19:59 +01:00
|
|
|
void CALLBACK GLUQuadricCallbacks::gluError(GLenum type) {
|
|
|
|
|
|
2002-11-30 04:28:30 +01:00
|
|
|
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);
|
2002-11-30 01:19:59 +01:00
|
|
|
}
|