summaryrefslogtreecommitdiffstats
path: root/make/config/jogl/glx-CustomCCode.c
diff options
context:
space:
mode:
authorKenneth Russel <[email protected]>2009-06-15 22:57:38 +0000
committerKenneth Russel <[email protected]>2009-06-15 22:57:38 +0000
commita959c53b7ac91e489bf0959391e892790b9ff248 (patch)
tree4664742a4f9f6daa694364292e376ad2e6ee97d1 /make/config/jogl/glx-CustomCCode.c
parent506b634b780dcd23aa61015c2ceba3e687196abf (diff)
Copied JOGL_2_SANDBOX r1957 on to trunk; JOGL_2_SANDBOX branch is now closed
git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/trunk@1959 232f8b59-042b-4e1e-8c03-345bb8c30851
Diffstat (limited to 'make/config/jogl/glx-CustomCCode.c')
-rwxr-xr-xmake/config/jogl/glx-CustomCCode.c151
1 files changed, 151 insertions, 0 deletions
diff --git a/make/config/jogl/glx-CustomCCode.c b/make/config/jogl/glx-CustomCCode.c
new file mode 100755
index 000000000..93347a174
--- /dev/null
+++ b/make/config/jogl/glx-CustomCCode.c
@@ -0,0 +1,151 @@
+#include <inttypes.h>
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <GL/glx.h>
+/* Linux headers don't work properly */
+#define __USE_GNU
+#include <dlfcn.h>
+#undef __USE_GNU
+
+/* HP-UX doesn't define RTLD_DEFAULT. */
+#if defined(_HPUX) && !defined(RTLD_DEFAULT)
+#define RTLD_DEFAULT NULL
+#endif
+
+/* We expect glXGetProcAddressARB to be defined */
+extern void (*glXGetProcAddressARB(const GLubyte *procname))();
+
+static const char * clazzNameInternalBufferUtil = "com/sun/opengl/impl/InternalBufferUtil";
+static const char * clazzNameInternalBufferUtilStaticCstrName = "copyByteBuffer";
+static const char * clazzNameInternalBufferUtilStaticCstrSignature = "(Ljava/nio/ByteBuffer;)Ljava/nio/ByteBuffer;";
+static const char * clazzNameByteBuffer = "java/nio/ByteBuffer";
+static jclass clazzInternalBufferUtil = NULL;
+static jmethodID cstrInternalBufferUtil = NULL;
+static jclass clazzByteBuffer = NULL;
+
+static void _initClazzAccess(JNIEnv *env) {
+ if(NULL!=cstrInternalBufferUtil) return ;
+
+ jclass c = (*env)->FindClass(env, clazzNameInternalBufferUtil);
+ if(NULL==c) {
+ fprintf(stderr, "FatalError: Java_com_sun_opengl_impl_x11_glx_GLX: can't find %s\n", clazzNameInternalBufferUtil);
+ (*env)->FatalError(env, clazzNameInternalBufferUtil);
+ }
+ clazzInternalBufferUtil = (jclass)(*env)->NewGlobalRef(env, c);
+ if(NULL==clazzInternalBufferUtil) {
+ fprintf(stderr, "FatalError: Java_com_sun_opengl_impl_x11_glx_GLX: can't use %s\n", clazzNameInternalBufferUtil);
+ (*env)->FatalError(env, clazzNameInternalBufferUtil);
+ }
+ c = (*env)->FindClass(env, clazzNameByteBuffer);
+ if(NULL==c) {
+ fprintf(stderr, "FatalError: Java_com_sun_opengl_impl_x11_glx_GLX: can't find %s\n", clazzNameByteBuffer);
+ (*env)->FatalError(env, clazzNameByteBuffer);
+ }
+ clazzByteBuffer = (jclass)(*env)->NewGlobalRef(env, c);
+ if(NULL==c) {
+ fprintf(stderr, "FatalError: Java_com_sun_opengl_impl_x11_glx_GLX: can't use %s\n", clazzNameByteBuffer);
+ (*env)->FatalError(env, clazzNameByteBuffer);
+ }
+
+ cstrInternalBufferUtil = (*env)->GetStaticMethodID(env, clazzInternalBufferUtil,
+ clazzNameInternalBufferUtilStaticCstrName, clazzNameInternalBufferUtilStaticCstrSignature);
+ if(NULL==cstrInternalBufferUtil) {
+ fprintf(stderr, "FatalError: Java_com_sun_opengl_impl_x11_glx_GLX:: can't create %s.%s %s\n",
+ clazzNameInternalBufferUtil,
+ clazzNameInternalBufferUtilStaticCstrName, clazzNameInternalBufferUtilStaticCstrSignature);
+ (*env)->FatalError(env, clazzNameInternalBufferUtilStaticCstrName);
+ }
+}
+
+/* Java->C glue code:
+ * Java package: com.sun.opengl.impl.x11.glx.GLX
+ * Java method: XVisualInfo glXGetVisualFromFBConfig(long dpy, long config)
+ * C function: XVisualInfo * glXGetVisualFromFBConfig(Display * dpy, GLXFBConfig config);
+ */
+JNIEXPORT jobject JNICALL
+Java_com_sun_opengl_impl_x11_glx_GLX_glXGetVisualFromFBConfigCopied0__JJ(JNIEnv *env, jclass _unused, jlong dpy, jlong config) {
+ XVisualInfo * _res;
+ _res = glXGetVisualFromFBConfig((Display *) (intptr_t) dpy, (GLXFBConfig) (intptr_t) config);
+ if (_res == NULL) return NULL;
+
+ _initClazzAccess(env);
+
+ jobject jbyteSource = (*env)->NewDirectByteBuffer(env, _res, sizeof(XVisualInfo));
+ jobject jbyteCopy = (*env)->CallStaticObjectMethod(env,
+ clazzInternalBufferUtil, cstrInternalBufferUtil, jbyteSource);
+
+ // FIXME: remove reference/gc jbyteSource ??
+ XFree(_res);
+
+ return jbyteCopy;
+}
+
+/* Java->C glue code:
+ * Java package: com.sun.opengl.impl.x11.glx.GLX
+ * Java method: java.nio.LongBuffer glXChooseFBConfig(long dpy, int screen, java.nio.IntBuffer attribList, java.nio.IntBuffer nitems)
+ * C function: GLXFBConfig * glXChooseFBConfig(Display * dpy, int screen, const int * attribList, int * nitems);
+ */
+JNIEXPORT jobject JNICALL
+Java_com_sun_opengl_impl_x11_glx_GLX_glXChooseFBConfigCopied1__JILjava_lang_Object_2ILjava_lang_Object_2I(JNIEnv *env, jclass _unused, jlong dpy, jint screen, jobject attribList, jint attribList_byte_offset, jobject nitems, jint nitems_byte_offset) {
+ int * _ptr2 = NULL;
+ int * _ptr3 = NULL;
+ GLXFBConfig * _res;
+ int count;
+ if (attribList != NULL) {
+ _ptr2 = (int *) (((char*) (*env)->GetPrimitiveArrayCritical(env, attribList, NULL)) + attribList_byte_offset);
+ }
+ if (nitems != NULL) {
+ _ptr3 = (int *) (((char*) (*env)->GetPrimitiveArrayCritical(env, nitems, NULL)) + nitems_byte_offset);
+ }
+ _res = glXChooseFBConfig((Display *) (intptr_t) dpy, (int) screen, (int *) _ptr2, (int *) _ptr3);
+ count = _ptr3[0];
+ if (attribList != NULL) {
+ (*env)->ReleasePrimitiveArrayCritical(env, attribList, _ptr2, 0);
+ }
+ if (nitems != NULL) {
+ (*env)->ReleasePrimitiveArrayCritical(env, nitems, _ptr3, 0);
+ }
+ if (_res == NULL) return NULL;
+
+ _initClazzAccess(env);
+
+ jobject jbyteSource = (*env)->NewDirectByteBuffer(env, _res, count * sizeof(GLXFBConfig));
+ jobject jbyteCopy = (*env)->CallStaticObjectMethod(env,
+ clazzInternalBufferUtil, cstrInternalBufferUtil, jbyteSource);
+
+ // FIXME: remove reference/gc jbyteSource ??
+ XFree(_res);
+
+ return jbyteCopy;
+}
+
+/* Java->C glue code:
+ * Java package: com.sun.opengl.impl.x11.glx.GLX
+ * Java method: XVisualInfo glXChooseVisual(long dpy, int screen, java.nio.IntBuffer attribList)
+ * C function: XVisualInfo * glXChooseVisual(Display * dpy, int screen, int * attribList);
+ */
+JNIEXPORT jobject JNICALL
+Java_com_sun_opengl_impl_x11_glx_GLX_glXChooseVisualCopied1__JILjava_lang_Object_2I(JNIEnv *env, jclass _unused, jlong dpy, jint screen, jobject attribList, jint attribList_byte_offset) {
+ int * _ptr2 = NULL;
+ XVisualInfo * _res;
+ if (attribList != NULL) {
+ _ptr2 = (int *) (((char*) (*env)->GetPrimitiveArrayCritical(env, attribList, NULL)) + attribList_byte_offset);
+ }
+ _res = glXChooseVisual((Display *) (intptr_t) dpy, (int) screen, (int *) _ptr2);
+ if (attribList != NULL) {
+ (*env)->ReleasePrimitiveArrayCritical(env, attribList, _ptr2, 0);
+ }
+ if (_res == NULL) return NULL;
+
+ _initClazzAccess(env);
+
+ jobject jbyteSource = (*env)->NewDirectByteBuffer(env, _res, sizeof(XVisualInfo));
+ jobject jbyteCopy = (*env)->CallStaticObjectMethod(env,
+ clazzInternalBufferUtil, cstrInternalBufferUtil, jbyteSource);
+
+ // FIXME: remove reference/gc jbyteSource ??
+ XFree(_res);
+
+ return jbyteCopy;
+}
+