1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
|
#include <stdio.h> /* android */
#include <stdlib.h>
#include <stdarg.h>
#include "jogamp_opengl_GLDebugMessageHandler.h"
#include "JoglCommon.h"
#include <GL/gl.h>
#include <GL/glext.h>
// #define VERBOSE_ON 1
#ifdef VERBOSE_ON
#define DBG_PRINT(...) fprintf(stderr, __VA_ARGS__); fflush(stderr)
#else
#define DBG_PRINT(...)
#endif
static jmethodID glDebugMessageARB = NULL; // int source, int type, int id, int severity, String msg
static jmethodID glDebugMessageAMD = NULL; // int id, int category, int severity, String msg
typedef void (APIENTRY* _local_PFNGLDEBUGMESSAGECALLBACKARBPROC) (GLDEBUGPROCARB callback, const GLvoid *userParam);
typedef void (APIENTRY* _local_GLDEBUGPROCARB)(GLenum source,GLenum type,GLuint id,GLenum severity,GLsizei length,const GLchar *message,GLvoid *userParam);
typedef void (APIENTRY* _local_PFNGLDEBUGMESSAGECALLBACKAMDPROC) (GLDEBUGPROCAMD callback, const GLvoid *userParam);
typedef void (APIENTRY* _local_GLDEBUGPROCAMD)(GLuint id,GLenum category,GLenum severity,GLsizei length,const GLchar *message,GLvoid *userParam);
/*
* Class: jogamp_opengl_GLDebugMessageHandler
* Method: initIDs0
* Signature: (V)Z
*/
JNIEXPORT jboolean JNICALL Java_jogamp_opengl_GLDebugMessageHandler_initIDs0
(JNIEnv *env, jclass clazz)
{
jboolean res;
JoglCommon_init(env);
glDebugMessageARB = (*env)->GetMethodID(env, clazz, "glDebugMessageARB", "(IIIILjava/lang/String;)V");
glDebugMessageAMD = (*env)->GetMethodID(env, clazz, "glDebugMessageAMD", "(IIILjava/lang/String;)V");
res = ( NULL != glDebugMessageARB && NULL != glDebugMessageAMD ) ? JNI_TRUE : JNI_FALSE ;
DBG_PRINT("GLDebugMessageHandler.initIDS0: OK: %d, ARB %p, AMD %p\n", res, glDebugMessageARB, glDebugMessageAMD);
return res;
}
typedef struct {
JavaVM *vm;
int version;
jobject obj;
int extType;
} DebugHandlerType;
// GLDEBUGARB(GLenum source,GLenum type,GLuint id,GLenum severity,GLsizei length,const GLchar *message,GLvoid *userParam);
static void GLDebugMessageARBCallback(GLenum source, GLenum type, GLuint id, GLenum severity,
GLsizei length, const GLchar *message, GLvoid *userParam) {
DebugHandlerType * handle = (DebugHandlerType*) (intptr_t) userParam;
JavaVM *vm = handle->vm;
int version = handle->version;
jobject obj = handle->obj;
JNIEnv *curEnv = NULL;
JNIEnv *newEnv = NULL;
int envRes ;
DBG_PRINT("GLDebugMessageARBCallback: 00 - %s, vm %p, version 0x%X, jobject %p, extType %d\n",
message, handle->vm, handle->version, (void*)handle->obj, handle->extType);
// retrieve this thread's JNIEnv curEnv - or detect it's detached
envRes = (*vm)->GetEnv(vm, (void **) &curEnv, version) ;
DBG_PRINT("GLDebugMessageARBCallback: 01 - JVM Env: curEnv %p, res 0x%X\n", curEnv, envRes);
if( JNI_EDETACHED == envRes ) {
// detached thread - attach to JVM
if( JNI_OK != ( envRes = (*vm)->AttachCurrentThread(vm, (void**) &newEnv, NULL) ) ) {
fprintf(stderr, "GLDebugMessageARBCallback: can't attach thread: %d\n", envRes);
return;
}
curEnv = newEnv;
DBG_PRINT("GLDebugMessageARBCallback: 02 - attached .. \n");
} else if( JNI_OK != envRes ) {
// oops ..
fprintf(stderr, "GLDebugMessageARBCallback: can't GetEnv: %d\n", envRes);
return;
}
(*curEnv)->CallVoidMethod(curEnv, obj, glDebugMessageARB,
(jint) source, (jint) type, (jint) id, (jint) severity,
(*curEnv)->NewStringUTF(curEnv, message));
if( NULL != newEnv ) {
// detached attached thread
(*vm)->DetachCurrentThread(vm);
DBG_PRINT("GLDebugMessageARBCallback: 04 - detached .. \n");
}
DBG_PRINT("GLDebugMessageARBCallback: 0X\n");
/**
* On Java 32bit on 64bit Windows and w/ GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB disables,
* the unit test com.jogamp.opengl.test.junit.jogl.acore.TestGLDebug00NEWT crashes after this point.
*/
}
// GLDEBUGAMD(GLuint id,GLenum category,GLenum severity,GLsizei length,const GLchar *message,GLvoid *userParam);
static void GLDebugMessageAMDCallback(GLuint id, GLenum category, GLenum severity,
GLsizei length, const GLchar *message, GLvoid *userParam) {
DebugHandlerType * handle = (DebugHandlerType*) (intptr_t) userParam;
JavaVM *vm = handle->vm;
int version = handle->version;
jobject obj = handle->obj;
JNIEnv *curEnv = NULL;
JNIEnv *newEnv = NULL;
int envRes ;
DBG_PRINT("GLDebugMessageAMDCallback: 00 - %s, vm %p, version 0x%X, jobject %p, extType %d\n",
message, handle->vm, handle->version, (void*)handle->obj, handle->extType);
// retrieve this thread's JNIEnv curEnv - or detect it's detached
envRes = (*vm)->GetEnv(vm, (void **) &curEnv, version) ;
DBG_PRINT("GLDebugMessageAMDCallback: 01 - JVM Env: curEnv %p, res 0x%X\n", curEnv, envRes);
if( JNI_EDETACHED == envRes ) {
// detached thread - attach to JVM
if( JNI_OK != ( envRes = (*vm)->AttachCurrentThread(vm, (void**) &newEnv, NULL) ) ) {
fprintf(stderr, "GLDebugMessageAMDCallback: can't attach thread: %d\n", envRes);
return;
}
curEnv = newEnv;
DBG_PRINT("GLDebugMessageAMDCallback: 02 - attached .. \n");
} else if( JNI_OK != envRes ) {
// oops ..
fprintf(stderr, "GLDebugMessageAMDCallback: can't GetEnv: %d\n", envRes);
return;
}
(*curEnv)->CallVoidMethod(curEnv, obj, glDebugMessageAMD,
(jint) id, (jint) category, (jint) severity,
(*curEnv)->NewStringUTF(curEnv, message));
if( NULL != newEnv ) {
// detached attached thread
(*vm)->DetachCurrentThread(vm);
DBG_PRINT("GLDebugMessageAMDCallback: 04 - detached .. \n");
}
DBG_PRINT("GLDebugMessageAMDCallback: 0X\n");
/**
* On Java 32bit on 64bit Windows,
* the unit test com.jogamp.opengl.test.junit.jogl.acore.TestGLDebug00NEWT crashes after this point.
*/
}
/*
* Class: jogamp_opengl_GLDebugMessageHandler
* Method: register0
* Signature: (JI)J
*/
JNIEXPORT jlong JNICALL Java_jogamp_opengl_GLDebugMessageHandler_register0
(JNIEnv *env, jobject obj, jlong procAddress, jint extType)
{
JavaVM *vm;
DebugHandlerType * handle = malloc(sizeof(DebugHandlerType));
if(0 != (*env)->GetJavaVM(env, &vm)) {
vm = NULL;
JoglCommon_throwNewRuntimeException(env, "GetJavaVM failed");
}
handle->vm = vm;
handle->version = (*env)->GetVersion(env);
handle->obj = (*env)->NewGlobalRef(env, obj);
handle->extType = extType;
DBG_PRINT("GLDebugMessageHandler.register0: vm %p, version 0x%X, jobject %p, extType %d\n",
handle->vm, handle->version, (void*)handle->obj, handle->extType);
if(jogamp_opengl_GLDebugMessageHandler_EXT_ARB == extType) {
_local_PFNGLDEBUGMESSAGECALLBACKARBPROC ptr_glDebugMessageCallbackARB;
ptr_glDebugMessageCallbackARB = (_local_PFNGLDEBUGMESSAGECALLBACKARBPROC) (intptr_t) procAddress;
ptr_glDebugMessageCallbackARB((_local_GLDEBUGPROCARB)GLDebugMessageARBCallback, handle);
} else if(jogamp_opengl_GLDebugMessageHandler_EXT_AMD == extType) {
_local_PFNGLDEBUGMESSAGECALLBACKAMDPROC ptr_glDebugMessageCallbackAMD;
ptr_glDebugMessageCallbackAMD = (_local_PFNGLDEBUGMESSAGECALLBACKAMDPROC) (intptr_t) procAddress;
ptr_glDebugMessageCallbackAMD((_local_GLDEBUGPROCAMD)GLDebugMessageAMDCallback, handle);
} else {
JoglCommon_throwNewRuntimeException(env, "unsupported extension type %d", extType);
}
return (jlong) (intptr_t) handle;
}
/*
* Class: jogamp_opengl_GLDebugMessageHandler
* Method: unregister0
* Signature: (JJ)V
*/
JNIEXPORT void JNICALL Java_jogamp_opengl_GLDebugMessageHandler_unregister0
(JNIEnv *env, jobject obj, jlong procAddress, jlong jhandle)
{
DebugHandlerType * handle = (DebugHandlerType*) (intptr_t) jhandle;
DBG_PRINT("GLDebugMessageHandler.unregister0: vm %p, version 0x%X, jobject %p, extType %d\n",
handle->vm, handle->version, (void*)handle->obj, handle->extType);
if(JNI_FALSE == (*env)->IsSameObject(env, obj, handle->obj)) {
JoglCommon_throwNewRuntimeException(env, "wrong handle (obj doesn't match)");
}
if(jogamp_opengl_GLDebugMessageHandler_EXT_ARB == handle->extType) {
_local_PFNGLDEBUGMESSAGECALLBACKARBPROC ptr_glDebugMessageCallbackARB;
ptr_glDebugMessageCallbackARB = (_local_PFNGLDEBUGMESSAGECALLBACKARBPROC) (intptr_t) procAddress;
ptr_glDebugMessageCallbackARB((_local_GLDEBUGPROCARB)NULL, NULL);
} else if(jogamp_opengl_GLDebugMessageHandler_EXT_AMD == handle->extType) {
_local_PFNGLDEBUGMESSAGECALLBACKAMDPROC ptr_glDebugMessageCallbackAMD;
ptr_glDebugMessageCallbackAMD = (_local_PFNGLDEBUGMESSAGECALLBACKAMDPROC) (intptr_t) procAddress;
ptr_glDebugMessageCallbackAMD((_local_GLDEBUGPROCAMD)NULL, NULL);
} else {
JoglCommon_throwNewRuntimeException(env, "unsupported extension type %d", handle->extType);
}
(*env)->DeleteGlobalRef(env, handle->obj);
free(handle);
}
|