aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKenneth Russel <[email protected]>2001-11-11 21:30:13 +0000
committerKenneth Russel <[email protected]>2001-11-11 21:30:13 +0000
commitf610ac01f50165b2ea6bc4a81d02abf2e222d876 (patch)
tree2b54144d82803e6665a371b6eeeae6812a16e3ac
parent3b0e7fd364c6d61b97f4f2daf405b30e662fddc7 (diff)
Support for NVidia AllocateMemoryNV extension and fixed problem with extensions not being loaded
-rw-r--r--C2J/manual/gl-manualCodedImplJNI1-14.java90
-rw-r--r--C2J/manual/gl-manualCodedImplJNI14.c136
-rw-r--r--C2J/manual/gl-manualCodedVirt1-14.java55
-rw-r--r--C2J/manual/glx-disp-fetch.hc6
-rw-r--r--C2J/manual/glx-disp-var.h3
-rw-r--r--C2J/manual/glx-disp-var.hc3
-rwxr-xr-xC2J/manual/wgl-disp-fetch.hc55
-rw-r--r--C2J/manual/wgl-disp-var.h4
-rw-r--r--C2J/manual/wgl-disp-var.hc3
-rw-r--r--CNativeCode/OpenGL_JauJNI14_funcs.c224
-rw-r--r--CNativeCode/OpenGL_misc.c33
-rw-r--r--CNativeCode/gl4java_utils_DirectBufferCleanup.c12
-rwxr-xr-xCNativeCode/gltool.c47
-rwxr-xr-xCNativeCode/gltool.h20
-rw-r--r--CNativeCode/glxtool.c12
-rwxr-xr-xCNativeCode/glxtool.h2
-rw-r--r--CNativeCode/ptrtypes.h26
-rwxr-xr-xCNativeCode/wgltool.c1442
-rwxr-xr-xCNativeCode/wgltool.h84
-rwxr-xr-xWin32VC6/GL4JavaJauGljJNI14/GL4JavaJauGljJNI14.dsp264
-rw-r--r--gl4java/GLContext.java.skel44
-rw-r--r--gl4java/GLFunc14.java75
-rw-r--r--gl4java/GLFunc14JauJNI.java90
-rw-r--r--gl4java/utils/DirectBufferCleanup.java110
-rw-r--r--makefile4
25 files changed, 1663 insertions, 1181 deletions
diff --git a/C2J/manual/gl-manualCodedImplJNI1-14.java b/C2J/manual/gl-manualCodedImplJNI1-14.java
index 7e490ba..0fc04ce 100644
--- a/C2J/manual/gl-manualCodedImplJNI1-14.java
+++ b/C2J/manual/gl-manualCodedImplJNI1-14.java
@@ -1,20 +1,70 @@
-/**
- * @(#) GLFunc14JauJNI.java
- */
-
-
-package gl4java;
-
-import java.nio.*;
-
-/**
- * The default implementation class for OpenGL native function mapping
- *
- * @version 2.00, 21. April 1999
- * @author Sven Goethel
- */
-public class GLFunc14JauJNI
- implements GLFunc14
-{
-
-
+/**
+ * @(#) GLFunc14JauJNI.java
+ */
+
+
+package gl4java;
+
+import java.nio.*;
+import gl4java.utils.DirectBufferCleanup;
+
+/**
+ * The default implementation class for OpenGL native function mapping
+ *
+ * @version 2.00, 21. April 1999
+ * @author Sven Goethel
+ */
+public class GLFunc14JauJNI
+ implements GLFunc14
+{
+
+ //----------------------------------------------------------------------
+ // Special-case routines requiring hand coding
+ //
+
+ /** Access to the underlying wglAllocateMemoryNV or
+ glXAllocateMemoryNV routine, if present. Presence of this
+ routine can be queried by calling GLContext.gljTestGLProc with
+ the argument "glAllocateMemoryNV". */
+ public ByteBuffer glAllocateMemoryNV(int size,
+ float readFreq,
+ float writeFreq,
+ float priority) {
+ long address = glAllocateMemoryNV0(size, readFreq, writeFreq, priority);
+ if (address == 0) {
+ throw new OutOfMemoryError();
+ }
+ ByteBuffer buf = newDirectByteBuffer(address, size);
+ registerForCleanup(this, buf);
+ return buf;
+ }
+
+ /** This delegates to either wglAllocateMemoryNV or
+ glXAllocateMemoryNV in the native code, depending on the window
+ system */
+ private native long glAllocateMemoryNV0(int size, float readFreq, float writeFreq, float priority);
+
+ /** This delegates to either wglFreeMemoryNV or glXFreeMemoryNV in
+ the native code, depending on the window system */
+ private native void glFreeMemoryNV0(long addr);
+
+ /** Allocate a direct byte buffer pointing at an arbitrary memory
+ address -- must be hidden for security reasons */
+ private native ByteBuffer newDirectByteBuffer(long addr, int capacity);
+
+ private static volatile DirectBufferCleanup cleanup;
+ private static synchronized void registerForCleanup(final GLFunc14JauJNI gl, Buffer buf) {
+ if (cleanup == null) {
+ cleanup = new DirectBufferCleanup(new DirectBufferCleanup.Callback() {
+ public void cleanup(long addr) {
+ gl.glFreeMemoryNV0(addr);
+ }
+ });
+ }
+ cleanup.register(buf);
+ }
+
+ //----------------------------------------------------------------------
+ // All other routines below are autogenerated
+ //
+
diff --git a/C2J/manual/gl-manualCodedImplJNI14.c b/C2J/manual/gl-manualCodedImplJNI14.c
index 9bbf519..73bad7e 100644
--- a/C2J/manual/gl-manualCodedImplJNI14.c
+++ b/C2J/manual/gl-manualCodedImplJNI14.c
@@ -1,37 +1,99 @@
-/** THIS IS A MANUAL CODED PART
- gl-manualCodedImplJNI.java
-*/
-
-static const char _gl_n_a_string[] = "GL-String not avaiable !";
-
-JNIEXPORT jstring JNICALL
-Java_gl4java_GLFunc14JauJNI_glGetString ( JNIEnv *env, jobject obj,
- jint name )
-{
- const char * tmpString=0;
-
- if ( disp__glGetString == NULL )
- return (*env)->NewStringUTF(env, _gl_n_a_string);
-
- tmpString = disp__glGetString ( /* jint */ name);
- if(tmpString==NULL)
- tmpString=_gl_n_a_string;
-
- return (*env)->NewStringUTF(env, tmpString);
-}
-
-static const char * _gl_lib_vendor_="Jausoft - Sven Goethel Software Development";
-static const char * _gl_lib_version_="2.8.0.8";
-
-JNIEXPORT jstring JNICALL
-Java_gl4java_GLFunc14JauJNI_getNativeVendor ( JNIEnv *env, jobject obj )
-{
- return (*env)->NewStringUTF(env, _gl_lib_vendor_);
-}
-
-JNIEXPORT jstring JNICALL
-Java_gl4java_GLFunc14JauJNI_getNativeVersion ( JNIEnv *env, jobject obj )
-{
- return (*env)->NewStringUTF(env, _gl_lib_version_);
-}
-
+/** THIS IS A MANUAL CODED PART
+ gl-manualCodedImplJNI.java
+*/
+
+static const char _gl_n_a_string[] = "GL-String not avaiable !";
+
+JNIEXPORT jstring JNICALL
+Java_gl4java_GLFunc14JauJNI_glGetString ( JNIEnv *env, jobject obj,
+ jint name )
+{
+ const char * tmpString=0;
+
+ if ( disp__glGetString == NULL )
+ return (*env)->NewStringUTF(env, _gl_n_a_string);
+
+ tmpString = disp__glGetString ( /* jint */ name);
+ if(tmpString==NULL)
+ tmpString=_gl_n_a_string;
+
+ return (*env)->NewStringUTF(env, tmpString);
+}
+
+static const char * _gl_lib_vendor_="Jausoft - Sven Goethel Software Development";
+static const char * _gl_lib_version_="2.8.0.8";
+
+JNIEXPORT jstring JNICALL
+Java_gl4java_GLFunc14JauJNI_getNativeVendor ( JNIEnv *env, jobject obj )
+{
+ return (*env)->NewStringUTF(env, _gl_lib_vendor_);
+}
+
+JNIEXPORT jstring JNICALL
+Java_gl4java_GLFunc14JauJNI_getNativeVersion ( JNIEnv *env, jobject obj )
+{
+ return (*env)->NewStringUTF(env, _gl_lib_version_);
+}
+
+//----------------------------------------------------------------------
+// Support for NVidia routines
+//
+
+#include "ptrtypes.h"
+
+#ifdef _X11_
+ #include <GL/glx.h>
+ #include <dlfcn.h>
+ #include "glxtool.h"
+ #include <unistd.h>
+#endif
+
+#ifdef _WIN32_
+ #include "wgltool.h"
+#endif
+
+#define GET_GL_PROCADDRESS(a) getGLProcAddressHelper (NULL, NULL, (a), NULL, 1, 0);
+
+JNIEXPORT jlong JNICALL
+Java_gl4java_GLFunc14JauJNI_glAllocateMemoryNV0(JNIEnv* env, jobject unused,
+ jint size,
+ jfloat readFreq,
+ jfloat writeFreq,
+ jfloat priority)
+{
+ void* (CALLBACK *disp__glAllocateMemoryNV)(int, float, float, float) =
+#ifdef _WIN32_
+ disp__wglAllocateMemoryNV;
+#elif defined(_X11_)
+ disp__glXAllocateMemoryNV;
+#else
+ NULL;
+#endif
+
+ if (disp__glAllocateMemoryNV == NULL) return 0;
+
+ return ((uintptr_t) disp__glAllocateMemoryNV(size, readFreq, writeFreq, priority));
+}
+
+JNIEXPORT void JNICALL
+Java_gl4java_GLFunc14JauJNI_glFreeMemoryNV0(JNIEnv* env, jobject unused, jlong address)
+{
+ void (CALLBACK *disp__glFreeMemoryNV)(void*) =
+#if (defined(_WIN32_))
+ disp__wglFreeMemoryNV;
+#elif defined(_X11_)
+ disp__glXFreeMemoryNV;
+#else
+ NULL;
+#endif
+
+ if (disp__glFreeMemoryNV == NULL) return;
+
+ disp__glFreeMemoryNV((void*) ((uintptr_t) address));
+}
+
+JNIEXPORT jobject JNICALL
+Java_gl4java_GLFunc14JauJNI_newDirectByteBuffer(JNIEnv* env, jobject unused, jlong addr, jint capacity)
+{
+ return (*env)->NewDirectByteBuffer(env, (void *) ((uintptr_t) addr), capacity);
+}
diff --git a/C2J/manual/gl-manualCodedVirt1-14.java b/C2J/manual/gl-manualCodedVirt1-14.java
index 38bb132..881b23f 100644
--- a/C2J/manual/gl-manualCodedVirt1-14.java
+++ b/C2J/manual/gl-manualCodedVirt1-14.java
@@ -1,19 +1,36 @@
-/**
- * @(#) GLFunc14.java
- */
-
-
-package gl4java;
-
-import java.nio.*;
-
-/**
- * The base interface for OpenGL native function mapping
- *
- * @version 2.00, 21. April 1999
- * @author Sven Goethel
- */
-public interface GLFunc14
- extends GLFunc
-{
-
+/**
+ * @(#) GLFunc14.java
+ */
+
+
+package gl4java;
+
+import java.nio.*;
+
+/**
+ * The base interface for OpenGL native function mapping
+ *
+ * @version 2.00, 21. April 1999
+ * @author Sven Goethel
+ */
+public interface GLFunc14
+ extends GLFunc
+{
+
+ //----------------------------------------------------------------------
+ // Special-case routines requiring hand coding
+ //
+
+ /** Access to the underlying wglAllocateMemoryNV or
+ glXAllocateMemoryNV routine, if present. Presence of this
+ routine can be queried by calling GLContext.gljTestGLProc with
+ the argument "glAllocateMemoryNV". */
+ public ByteBuffer glAllocateMemoryNV(int size,
+ float readFreq,
+ float writeFreq,
+ float priority);
+
+ //----------------------------------------------------------------------
+ // All other routines below are autogenerated
+ //
+
diff --git a/C2J/manual/glx-disp-fetch.hc b/C2J/manual/glx-disp-fetch.hc
index 89ae276..f35991c 100644
--- a/C2J/manual/glx-disp-fetch.hc
+++ b/C2J/manual/glx-disp-fetch.hc
@@ -35,3 +35,9 @@
disp__glXSwapBuffers = (void (CALLBACK *) (Display *, GLXDrawable))
GET_GL_PROCADDRESS("glXSwapBuffers");
+ /* NVidia support */
+ disp__glXAllocateMemoryNV = (void* (CALLBACK * )(int, float, float, float))
+ GET_GL_PROCADDRESS("glXAllocateMemoryNV");
+
+ disp__glXFreeMemoryNV = (void (CALLBACK * )(void*))
+ GET_GL_PROCADDRESS("glXFreeMemoryNV");
diff --git a/C2J/manual/glx-disp-var.h b/C2J/manual/glx-disp-var.h
index c87ccfd..2c05490 100644
--- a/C2J/manual/glx-disp-var.h
+++ b/C2J/manual/glx-disp-var.h
@@ -13,3 +13,6 @@ LIBAPI int (CALLBACK * disp__glXGetConfig) (Display *, XVisualInfo *, int, int *
LIBAPI Bool (CALLBACK * disp__glXMakeCurrent) (Display *, GLXDrawable, GLXContext);
LIBAPI void (CALLBACK * disp__glXSwapBuffers) (Display *, GLXDrawable);
+/* NVidia support */
+LIBAPI void* (CALLBACK * disp__glXAllocateMemoryNV)(int, float, float, float);
+LIBAPI void (CALLBACK * disp__glXFreeMemoryNV) (void*);
diff --git a/C2J/manual/glx-disp-var.hc b/C2J/manual/glx-disp-var.hc
index c24a839..99cc0a3 100644
--- a/C2J/manual/glx-disp-var.hc
+++ b/C2J/manual/glx-disp-var.hc
@@ -13,3 +13,6 @@ int (CALLBACK * disp__glXGetConfig) (Display *, XVisualInfo *, int, int *) = NUL
Bool (CALLBACK * disp__glXMakeCurrent) (Display *, GLXDrawable, GLXContext) = NULL;
void (CALLBACK * disp__glXSwapBuffers) (Display *, GLXDrawable) = NULL;
+/* NVidia support */
+void* (CALLBACK * disp__glXAllocateMemoryNV)(int, float, float, float) = NULL;
+void (CALLBACK * disp__glXFreeMemoryNV) (void*) = NULL;
diff --git a/C2J/manual/wgl-disp-fetch.hc b/C2J/manual/wgl-disp-fetch.hc
index 4a84ecc..049ca18 100755
--- a/C2J/manual/wgl-disp-fetch.hc
+++ b/C2J/manual/wgl-disp-fetch.hc
@@ -1,26 +1,31 @@
-
- disp__wglCopyContext = (BOOL (CALLBACK *)(HGLRC, HGLRC, UINT))
- GET_GL_PROCADDRESS("wglCopyContext");
-
- disp__wglCreateContext = (HGLRC (CALLBACK *)(HDC))
- GET_GL_PROCADDRESS("wglCreateContext");
-
- disp__wglCreateLayerContext = (HGLRC (CALLBACK *)(HDC, int))
- GET_GL_PROCADDRESS("wglCreateLayerContext");
-
- disp__wglDeleteContext = (BOOL (CALLBACK *)(HGLRC))
- GET_GL_PROCADDRESS("wglDeleteContext");
-
- disp__wglGetCurrentContext = (HGLRC (CALLBACK *)(VOID))
- GET_GL_PROCADDRESS("wglGetCurrentContext");
-
- disp__wglGetCurrentDC = (HDC (CALLBACK *)(VOID))
- GET_GL_PROCADDRESS("wglGetCurrentDC");
-
- disp__wglMakeCurrent = (BOOL (CALLBACK *)(HDC, HGLRC))
- GET_GL_PROCADDRESS("wglMakeCurrent");
-
- disp__wglShareLists = (BOOL (CALLBACK *)(HGLRC, HGLRC))
- GET_GL_PROCADDRESS("wglShareLists");
-
+ disp__wglCopyContext = (BOOL (CALLBACK *)(HGLRC, HGLRC, UINT))
+ GET_GL_PROCADDRESS("wglCopyContext");
+
+ disp__wglCreateContext = (HGLRC (CALLBACK *)(HDC))
+ GET_GL_PROCADDRESS("wglCreateContext");
+
+ disp__wglCreateLayerContext = (HGLRC (CALLBACK *)(HDC, int))
+ GET_GL_PROCADDRESS("wglCreateLayerContext");
+
+ disp__wglDeleteContext = (BOOL (CALLBACK *)(HGLRC))
+ GET_GL_PROCADDRESS("wglDeleteContext");
+
+ disp__wglGetCurrentContext = (HGLRC (CALLBACK *)(VOID))
+ GET_GL_PROCADDRESS("wglGetCurrentContext");
+
+ disp__wglGetCurrentDC = (HDC (CALLBACK *)(VOID))
+ GET_GL_PROCADDRESS("wglGetCurrentDC");
+
+ disp__wglMakeCurrent = (BOOL (CALLBACK *)(HDC, HGLRC))
+ GET_GL_PROCADDRESS("wglMakeCurrent");
+
+ disp__wglShareLists = (BOOL (CALLBACK *)(HGLRC, HGLRC))
+ GET_GL_PROCADDRESS("wglShareLists");
+
+ /* NVidia support */
+ disp__wglAllocateMemoryNV = (void* (CALLBACK * )(int, float, float, float))
+ GET_GL_PROCADDRESS("wglAllocateMemoryNV");
+
+ disp__wglFreeMemoryNV = (void (CALLBACK * )(void*))
+ GET_GL_PROCADDRESS("wglFreeMemoryNV");
diff --git a/C2J/manual/wgl-disp-var.h b/C2J/manual/wgl-disp-var.h
index 44b47e3..8bf14ce 100644
--- a/C2J/manual/wgl-disp-var.h
+++ b/C2J/manual/wgl-disp-var.h
@@ -9,4 +9,8 @@ LIBAPI HDC (CALLBACK * disp__wglGetCurrentDC)(VOID);
LIBAPI BOOL (CALLBACK * disp__wglMakeCurrent)(HDC, HGLRC);
LIBAPI BOOL (CALLBACK * disp__wglShareLists)(HGLRC, HGLRC);
+/* NVidia support */
+LIBAPI void* (CALLBACK * disp__wglAllocateMemoryNV)(int, float, float, float);
+LIBAPI void (CALLBACK * disp__wglFreeMemoryNV) (void*);
+
diff --git a/C2J/manual/wgl-disp-var.hc b/C2J/manual/wgl-disp-var.hc
index 8d4cde1..81dc2e5 100644
--- a/C2J/manual/wgl-disp-var.hc
+++ b/C2J/manual/wgl-disp-var.hc
@@ -8,4 +8,7 @@ HDC (CALLBACK * disp__wglGetCurrentDC)(VOID) = NULL;
BOOL (CALLBACK * disp__wglMakeCurrent)(HDC, HGLRC) = NULL;
BOOL (CALLBACK * disp__wglShareLists)(HGLRC, HGLRC) = NULL;
+/* NVidia support */
+void* (CALLBACK * disp__wglAllocateMemoryNV)(int, float, float, float) = NULL;
+void (CALLBACK * disp__wglFreeMemoryNV) (void*) = NULL;
diff --git a/CNativeCode/OpenGL_JauJNI14_funcs.c b/CNativeCode/OpenGL_JauJNI14_funcs.c
index fd518d5..691fd11 100644
--- a/CNativeCode/OpenGL_JauJNI14_funcs.c
+++ b/CNativeCode/OpenGL_JauJNI14_funcs.c
@@ -4,87 +4,149 @@
*/
-/*
- * Leo Chan -- 1995
- *
- * This mammoth C file takes care of all the native implementation for the
- * bulk of OpenGL commands
- * ---------------
- *
- * Sven Goethel
- *
- * September 1997
- */
-
-/*
- * need to include the JAVA internal header files for macros and function
- * prototypes required to maipulated JAVA data structures and functions
- *
- * StubPreamble.h includes the structure and macro definitions neede to
- * convert JAVA data structures into C data structures.
- *
- */
-
-#include "OpenGL_misc.h"
-
-/*
- * the next thing to include are special headers that were created by
- * JAVAH. They include the C structure definitions for the JAVA classes
- */
-#include "gl4java_GLFunc14JauJNI.h"
-
-/*--------------------------------------------------------------------------
- * here on in is just regular apple pie C
- */
-
-#ifndef LIBAPIENTRY
- #define LIBAPIENTRY
-#endif
-#ifndef LIBAPI
- #define LIBAPI
-#endif
-
-#ifndef CALLBACK
- #define CALLBACK
-#endif
-/** THIS IS A MANUAL CODED PART
- gl-manualCodedImplJNI.java
-*/
-
-static const char _gl_n_a_string[] = "GL-String not avaiable !";
-
-JNIEXPORT jstring JNICALL
-Java_gl4java_GLFunc14JauJNI_glGetString ( JNIEnv *env, jobject obj,
- jint name )
-{
- const char * tmpString=0;
-
- if ( disp__glGetString == NULL )
- return (*env)->NewStringUTF(env, _gl_n_a_string);
-
- tmpString = disp__glGetString ( /* jint */ name);
- if(tmpString==NULL)
- tmpString=_gl_n_a_string;
-
- return (*env)->NewStringUTF(env, tmpString);
-}
-
-static const char * _gl_lib_vendor_="Jausoft - Sven Goethel Software Development";
-static const char * _gl_lib_version_="2.8.0.8";
-
-JNIEXPORT jstring JNICALL
-Java_gl4java_GLFunc14JauJNI_getNativeVendor ( JNIEnv *env, jobject obj )
-{
- return (*env)->NewStringUTF(env, _gl_lib_vendor_);
-}
-
-JNIEXPORT jstring JNICALL
-Java_gl4java_GLFunc14JauJNI_getNativeVersion ( JNIEnv *env, jobject obj )
-{
- return (*env)->NewStringUTF(env, _gl_lib_version_);
-}
-
+/*
+ * Leo Chan -- 1995
+ *
+ * This mammoth C file takes care of all the native implementation for the
+ * bulk of OpenGL commands
+ * ---------------
+ *
+ * Sven Goethel
+ *
+ * September 1997
+ */
+
+/*
+ * need to include the JAVA internal header files for macros and function
+ * prototypes required to maipulated JAVA data structures and functions
+ *
+ * StubPreamble.h includes the structure and macro definitions neede to
+ * convert JAVA data structures into C data structures.
+ *
+ */
+
+#include "OpenGL_misc.h"
+
+/*
+ * the next thing to include are special headers that were created by
+ * JAVAH. They include the C structure definitions for the JAVA classes
+ */
+#include "gl4java_GLFunc14JauJNI.h"
+
+/*--------------------------------------------------------------------------
+ * here on in is just regular apple pie C
+ */
+
+#ifndef LIBAPIENTRY
+ #define LIBAPIENTRY
+#endif
+#ifndef LIBAPI
+ #define LIBAPI
+#endif
+
+#ifndef CALLBACK
+ #define CALLBACK
+#endif
+/** THIS IS A MANUAL CODED PART
+ gl-manualCodedImplJNI.java
+*/
+
+static const char _gl_n_a_string[] = "GL-String not avaiable !";
+
+JNIEXPORT jstring JNICALL
+Java_gl4java_GLFunc14JauJNI_glGetString ( JNIEnv *env, jobject obj,
+ jint name )
+{
+ const char * tmpString=0;
+
+ if ( disp__glGetString == NULL )
+ return (*env)->NewStringUTF(env, _gl_n_a_string);
+
+ tmpString = disp__glGetString ( /* jint */ name);
+ if(tmpString==NULL)
+ tmpString=_gl_n_a_string;
+
+ return (*env)->NewStringUTF(env, tmpString);
+}
+
+static const char * _gl_lib_vendor_="Jausoft - Sven Goethel Software Development";
+static const char * _gl_lib_version_="2.8.0.8";
+
+JNIEXPORT jstring JNICALL
+Java_gl4java_GLFunc14JauJNI_getNativeVendor ( JNIEnv *env, jobject obj )
+{
+ return (*env)->NewStringUTF(env, _gl_lib_vendor_);
+}
+
+JNIEXPORT jstring JNICALL
+Java_gl4java_GLFunc14JauJNI_getNativeVersion ( JNIEnv *env, jobject obj )
+{
+ return (*env)->NewStringUTF(env, _gl_lib_version_);
+}
+
+//----------------------------------------------------------------------
+// Support for NVidia routines
+//
+
+#include "ptrtypes.h"
+
+#ifdef _X11_
+ #include <GL/glx.h>
+ #include <dlfcn.h>
+ #include "glxtool.h"
+ #include <unistd.h>
+#endif
+
+#ifdef _WIN32_
+ #include "wgltool.h"
+#endif
+
+#define GET_GL_PROCADDRESS(a) getGLProcAddressHelper (NULL, NULL, (a), NULL, 1, 0);
+
+JNIEXPORT jlong JNICALL
+Java_gl4java_GLFunc14JauJNI_glAllocateMemoryNV0(JNIEnv* env, jobject unused,
+ jint size,
+ jfloat readFreq,
+ jfloat writeFreq,
+ jfloat priority)
+{
+ void* (CALLBACK *disp__glAllocateMemoryNV)(int, float, float, float) =
+#ifdef _WIN32_
+ disp__wglAllocateMemoryNV;
+#elif defined(_X11_)
+ disp__glXAllocateMemoryNV;
+#else
+ NULL;
+#endif
+
+ if (disp__glAllocateMemoryNV == NULL) return 0;
+
+ return ((uintptr_t) disp__glAllocateMemoryNV(size, readFreq, writeFreq, priority));
+}
+
+JNIEXPORT void JNICALL
+Java_gl4java_GLFunc14JauJNI_glFreeMemoryNV0(JNIEnv* env, jobject unused, jlong address)
+{
+ void (CALLBACK *disp__glFreeMemoryNV)(void*) =
+#if (defined(_WIN32_))
+ disp__wglFreeMemoryNV;
+#elif defined(_X11_)
+ disp__glXFreeMemoryNV;
+#else
+ NULL;
+#endif
+
+ if (disp__glFreeMemoryNV == NULL) return;
+
+ disp__glFreeMemoryNV((void*) ((uintptr_t) address));
+}
+
+JNIEXPORT jobject JNICALL
+Java_gl4java_GLFunc14JauJNI_newDirectByteBuffer(JNIEnv* env, jobject unused, jlong addr, jint capacity)
+{
+ return (*env)->NewDirectByteBuffer(env, (void *) ((uintptr_t) addr), capacity);
+}
/**
* C2J Parser Version 3.0
* Jausoft - Sven Goethel Software Development
diff --git a/CNativeCode/OpenGL_misc.c b/CNativeCode/OpenGL_misc.c
index ff00cce..babb470 100644
--- a/CNativeCode/OpenGL_misc.c
+++ b/CNativeCode/OpenGL_misc.c
@@ -793,6 +793,9 @@ Java_gl4java_GLContext_gljFetchOSGLFunctions (
JNIEnv *env, jclass jclass,
jstring gllibname, jstring glulibname, jboolean force )
{
+ // FIXME: this routine is currently unused by the GL4Java
+ // implementation and should be removed in a subsequent
+ // release
const char * gllib;
const char * glulib;
@@ -808,42 +811,44 @@ Java_gl4java_GLContext_gljFetchOSGLFunctions (
(*env)->ReleaseStringUTFChars(env, glulibname, glulib);
#ifdef _X11_
- fetch_GLX_FUNCS (libGLName, libGLUName, (force==JNI_TRUE)?1:0);
+ fetch_GLX_FUNCS (libGLName, libGLUName, (force==JNI_TRUE)?1:0, 0);
#endif
#ifdef _WIN32_
- fetch_WGL_FUNCS (libGLName, libGLUName, (force==JNI_TRUE)?1:0);
+ fetch_WGL_FUNCS (libGLName, libGLUName, (force==JNI_TRUE)?1:0, 0);
#endif
return JNI_TRUE;
}
JNIEXPORT jboolean JNICALL
-Java_gl4java_GLContext_gljFetchGLFunctions (
+Java_gl4java_GLContext_gljFetchGLFunctions0 (
JNIEnv *env, jclass jclass,
- jstring gllibname, jstring glulibname, jboolean force )
+ jstring gllibname, jstring glulibname, jboolean force, jboolean reload )
{
const char * gllib;
const char * glulib;
- gllib = (*env)->GetStringUTFChars(env, gllibname, 0);
- glulib = (*env)->GetStringUTFChars(env, glulibname, 0);
+ if (!reload) {
+ gllib = (*env)->GetStringUTFChars(env, gllibname, 0);
+ glulib = (*env)->GetStringUTFChars(env, glulibname, 0);
- strncpy (libGLName, gllib, 798);
- strncpy (libGLUName, glulib, 798);
- libGLName[799] = 0;
- libGLUName[799] = 0;
+ strncpy (libGLName, gllib, 798);
+ strncpy (libGLUName, glulib, 798);
+ libGLName[799] = 0;
+ libGLUName[799] = 0;
- (*env)->ReleaseStringUTFChars(env, gllibname, gllib);
- (*env)->ReleaseStringUTFChars(env, glulibname, glulib);
+ (*env)->ReleaseStringUTFChars(env, gllibname, gllib);
+ (*env)->ReleaseStringUTFChars(env, glulibname, glulib);
+ }
- fetch_GL_FUNCS (libGLName, libGLUName, (force==JNI_TRUE)?1:0);
+ fetch_GL_FUNCS (libGLName, libGLUName, (force==JNI_TRUE)?1:0, (reload==JNI_TRUE)?1:0);
return JNI_TRUE;
}
JNIEXPORT jboolean JNICALL
-Java_gl4java_GLContext_gljTestGLProc (
+Java_gl4java_GLContext_gljTestGLProc0 (
JNIEnv *env, jobject obj, jstring name, jboolean verbose )
{
jboolean res;
diff --git a/CNativeCode/gl4java_utils_DirectBufferCleanup.c b/CNativeCode/gl4java_utils_DirectBufferCleanup.c
new file mode 100644
index 0000000..14f32b8
--- /dev/null
+++ b/CNativeCode/gl4java_utils_DirectBufferCleanup.c
@@ -0,0 +1,12 @@
+#include "gl4java_utils_DirectBufferCleanup.h"
+
+/*
+ * Class: hiperf_DirectBufferCleanup
+ * Method: getDirectBufferAddress
+ * Signature: (Ljava/nio/Buffer;)J
+ */
+JNIEXPORT jlong JNICALL Java_gl4java_utils_DirectBufferCleanup_getDirectBufferAddress
+ (JNIEnv *env, jclass unused, jobject buf)
+{
+ return (jlong) (*env)->GetDirectBufferAddress(env, buf);
+}
diff --git a/CNativeCode/gltool.c b/CNativeCode/gltool.c
index 9854180..5676290 100755
--- a/CNativeCode/gltool.c
+++ b/CNativeCode/gltool.c
@@ -27,10 +27,10 @@
#ifdef _X11_
#include "glxtool.h"
#endif
-
-#ifdef _WIN32_
- #include "wgltool.h"
-#endif
+
+#ifdef _WIN32_
+ #include "wgltool.h"
+#endif
static int _glLibsLoaded = 0;
@@ -84,8 +84,8 @@ void LIBAPIENTRY check_wgl_error (HWND wnd, const char *file, int line)
#endif
void LIBAPIENTRY check_gl_error (const char *file, int line)
-{
- print_gl_error("GLCHECK", file, line, disp__glGetError());
+{
+ print_gl_error("GLCHECK", file, line, disp__glGetError());
}
void LIBAPIENTRY __sglBegin(const char * file, int line, GLenum mode)
@@ -304,7 +304,7 @@ void * LIBAPIENTRY getGLProcAddressHelper
if(!loadGLLibrary (libGLName, libGLUName))
return NULL;
-
+
if (disp__wglGetProcAddress == NULL && __firstAccess)
{
disp__wglGetProcAddress = ( PROC (CALLBACK *)(LPCSTR) )
@@ -523,21 +523,22 @@ void * LIBAPIENTRY getGLProcAddressHelper
void LIBAPIENTRY fetch_GL_FUNCS (const char * libGLName,
- const char * libGLUName, int force)
+ const char * libGLUName, int force, int reload)
{
static int _firstRun = 1;
- if(force)
- {
- unloadGLLibrary();
- _firstRun = 1;
- }
+ if (!reload) {
+ if(force) {
+ unloadGLLibrary();
+ _firstRun = 1;
+ }
- if(!_firstRun)
- return;
+ if(!_firstRun)
+ return;
- if(!loadGLLibrary (libGLName, libGLUName))
- return;
+ if(!loadGLLibrary (libGLName, libGLUName))
+ return;
+ }
#define GET_GL_PROCADDRESS(a) getGLProcAddressHelper (libGLName, libGLUName, (a), NULL, 0, 0);
@@ -547,12 +548,12 @@ void LIBAPIENTRY fetch_GL_FUNCS (const char * libGLName,
_firstRun=0;
#ifdef _X11_
- fetch_GLX_FUNCS (libGLName, libGLUName, force);
-#endif
-
-#ifdef _WIN32_
- fetch_WGL_FUNCS (libGLName, libGLUName, force);
-#endif
+ fetch_GLX_FUNCS (libGLName, libGLUName, force, reload);
+#endif
+
+#ifdef _WIN32_
+ fetch_WGL_FUNCS (libGLName, libGLUName, force, reload);
+#endif
}
diff --git a/CNativeCode/gltool.h b/CNativeCode/gltool.h
index 6939e03..fa8a639 100755
--- a/CNativeCode/gltool.h
+++ b/CNativeCode/gltool.h
@@ -28,7 +28,7 @@
#include <string.h>
#ifdef _WIN32_
- #include <windows.h>
+ #include <windows.h>
#ifdef LIBAPIENTRY
#undef LIBAPIENTRY
@@ -81,14 +81,14 @@
#include "gl-disp-var.h"
#include "glu-disp-var.h"
- #ifndef GLDEBUG
+ #ifndef GLDEBUG
#ifndef NDEBUG
#define NDEBUG
- #endif
- #else
- #ifdef NDEBUG
- #undef NDEBUG
- #endif
+ #endif
+ #else
+ #ifdef NDEBUG
+ #undef NDEBUG
+ #endif
#endif
#ifdef _WIN32_
@@ -122,8 +122,8 @@
(HWND wnd, const char *file, int line);
#endif
- LIBAPI void LIBAPIENTRY print_gl_error
- (const char *msg, const char *file, int line, GLenum errorcode);
+ LIBAPI void LIBAPIENTRY print_gl_error
+ (const char *msg, const char *file, int line, GLenum errorcode);
LIBAPI void LIBAPIENTRY check_gl_error
(const char *file, int line);
@@ -150,5 +150,5 @@
const char *func, int *method, int debug, int verbose);
LIBAPI void LIBAPIENTRY fetch_GL_FUNCS
- (const char * libGLName, const char * libGLUName, int force);
+ (const char * libGLName, const char * libGLUName, int force, int reload);
#endif
diff --git a/CNativeCode/glxtool.c b/CNativeCode/glxtool.c
index c027f5c..449933d 100644
--- a/CNativeCode/glxtool.c
+++ b/CNativeCode/glxtool.c
@@ -19,15 +19,17 @@
* use fetch_GL_FUNCS (gltool.c) instead
*/
void LIBAPIENTRY fetch_GLX_FUNCS (const char * libGLName,
- const char * libGLUName, int force)
+ const char * libGLUName, int force, int reload)
{
static int _firstRun = 1;
- if(force)
- _firstRun = 1;
+ if (!reload) {
+ if(force)
+ _firstRun = 1;
- if(!_firstRun)
- return;
+ if(!_firstRun)
+ return;
+ }
#define GET_GL_PROCADDRESS(a) getGLProcAddressHelper (libGLName, libGLUName, (a), NULL, 1, 0);
diff --git a/CNativeCode/glxtool.h b/CNativeCode/glxtool.h
index 03e28a5..d6d7332 100755
--- a/CNativeCode/glxtool.h
+++ b/CNativeCode/glxtool.h
@@ -91,7 +91,7 @@
*/
LIBAPI void LIBAPIENTRY fetch_GLX_FUNCS
(const char * libGLName,
- const char * libGLUName, int force);
+ const char * libGLUName, int force, int reload);
LIBAPI int LIBAPIENTRY x11gl_myErrorHandler(
Display *pDisp, XErrorEvent *p_error);
diff --git a/CNativeCode/ptrtypes.h b/CNativeCode/ptrtypes.h
new file mode 100644
index 0000000..5d730ce
--- /dev/null
+++ b/CNativeCode/ptrtypes.h
@@ -0,0 +1,26 @@
+#ifndef _PTRTYPES_H_
+#define _PTRTYPES_H_
+
+#if (defined(WIN32))
+
+typedef unsigned int uintptr_t;
+
+#elif defined(linux)
+
+typedef unsigned int uintptr_t;
+
+#elif defined(__sun) /* Solaris */
+
+#ifdef _LP64
+typedef unsigned long uintptr_t;
+#else
+typedef unsigned int uintptr_t;
+#endif
+
+#else
+
+#error Please port ptrtypes.h to your platform
+
+#endif
+
+#endif /* #defined _PTRTYPES_H_ */
diff --git a/CNativeCode/wgltool.c b/CNativeCode/wgltool.c
index d57335c..73d7a10 100755
--- a/CNativeCode/wgltool.c
+++ b/CNativeCode/wgltool.c
@@ -19,734 +19,736 @@
* use fetch_GL_FUNCS (gltool.c) instead
*/
void LIBAPIENTRY fetch_WGL_FUNCS (const char * libGLName,
- const char * libGLUName, int force)
+ const char * libGLUName, int force, int reload)
{
static int _firstRun = 1;
- if(force)
- _firstRun = 1;
+ if (!reload) {
+ if(force)
+ _firstRun = 1;
- if(!_firstRun)
- return;
+ if(!_firstRun)
+ return;
- if(!loadGLLibrary (libGLName, libGLUName))
- return;
-
- #define GET_GL_PROCADDRESS(a) getGLProcAddressHelper (libGLName, libGLUName, (a), NULL, 1, 0);
+ if(!loadGLLibrary (libGLName, libGLUName))
+ return;
+ }
+
+ #define GET_GL_PROCADDRESS(a) getGLProcAddressHelper (libGLName, libGLUName, (a), NULL, 1, 0);
#include "wgl-disp-fetch.hc"
_firstRun=0;
}
-
-
-HGLRC LIBAPIENTRY get_GC( HDC * hDC, GLCapabilities *glCaps,
- HGLRC shareWith,
- int offScreenRenderer,
- int width, int height, HBITMAP *pix,
- int verbose)
-
-{
- const char * text=0;
- HDC hDCOrig = 0;
-
- // Color Palette handle
- HPALETTE hPalette = NULL;
- HGLRC tempRC=0;
-
- if( *hDC == 0 && !offScreenRenderer)
- printf( "get_GC: Error, HDC is zero\n");
-
- // Select the pixel format
- if(offScreenRenderer)
- {
- hDCOrig = *hDC;
- *hDC = CreateCompatibleDC(hDCOrig);
- // setupDIB(*hDC, pix, width, height);
- setupDIB(hDCOrig, *hDC, pix, width, height);
- /* SetDCPixelFormat(hDCOffScr, doubleBuffer, stereo, stencilBits, offScreenRenderer); */
- /* setupPalette(hDC); USE MY PROC */
- }
-
- SetDCPixelFormat(*hDC, glCaps, offScreenRenderer, verbose);
-
- // Create palette if needed
- hPalette = GetOpenGLPalette(*hDC);
-
- tempRC = disp__wglCreateContext( *hDC );
-
- if(verbose)
- {
- fprintf(stderr,"\n\nPIXELFORMAT OF GL-Context SETTINGS:\n");
- text=GetTextualPixelFormatByHDC(*hDC);
- fprintf(stderr,text);
- }
-
- /* check if the context could be created */
- if( tempRC == NULL ) {
- fprintf(stderr, "getGC context could NOT be created \n");
- return( 0 );
- }
-
- /* associated the context with the X window */
- if( disp__wglMakeCurrent( *hDC, tempRC ) == FALSE) {
- fprintf(stderr,"wglMakeCurrent(%p,%p) failed on new context!!!\n", *hDC,tempRC);
- fprintf(stderr,"Error code = %d\n",(int)GetLastError());
- disp__wglMakeCurrent(NULL, NULL);
- disp__wglDeleteContext( tempRC );
- return( 0 );
- }
-
- if(shareWith!=NULL && disp__wglShareLists(shareWith, tempRC)==FALSE)
- {
- fprintf(stderr,"\nERROR: Could not share lists between the new and the given GLContext (Win32Native)!\n");
- fprintf(stderr,"Error code = %d\n",(int)GetLastError());
- disp__wglMakeCurrent(NULL, NULL);
- disp__wglDeleteContext( tempRC );
- return( 0 );
- }
-
- if(verbose)
- printf( "HGLRC (glContext) created: %p\n", tempRC );
-
- return tempRC;
-}
-
-void LIBAPIENTRY setPixelFormatByGLCapabilities(
- PIXELFORMATDESCRIPTOR *pfd,
- GLCapabilities *glCaps,
- int offScreenRenderer,
- HDC hdc)
-{
-
- int colorBits = glCaps->redBits + glCaps->greenBits + glCaps->blueBits;
-
- pfd->nSize=sizeof(PIXELFORMATDESCRIPTOR);
- pfd->nVersion=1;
- pfd->dwFlags=PFD_SUPPORT_OPENGL | PFD_GENERIC_ACCELERATED; /* refined later */
- pfd->iPixelType=0;
- pfd->cColorBits=0;
- pfd->cRedBits=0;
- pfd->cRedShift=0;
- pfd->cGreenBits=0;
- pfd->cGreenShift=0;
- pfd->cBlueBits=0;
- pfd->cBlueShift=0;
- pfd->cAlphaBits=0;
- pfd->cAlphaShift=0;
- pfd->cAccumBits=0;
- pfd->cAccumRedBits=0;
- pfd->cAccumGreenBits=0;
- pfd->cAccumBlueBits=0;
- pfd->cAccumAlphaBits=0;
- pfd->cDepthBits=32;
- pfd->cStencilBits=0;
- pfd->cAuxBuffers=0;
- pfd->iLayerType=PFD_MAIN_PLANE;
- pfd->bReserved=0;
- pfd->dwLayerMask=0;
- pfd->dwVisibleMask=0;
- pfd->dwDamageMask=0;
-
- if(COLOR_RGBA == glCaps->color)
- pfd->iPixelType=PFD_TYPE_RGBA;
- else
- pfd->iPixelType=PFD_TYPE_COLORINDEX;
-
- if(offScreenRenderer)
- pfd->dwFlags |= PFD_DRAW_TO_BITMAP; // Draw to Bitmap
- else
- pfd->dwFlags |= PFD_DRAW_TO_WINDOW; // Draw to Window (not to bitmap)
-
-
- if(BUFFER_DOUBLE==glCaps->buffer)
- pfd->dwFlags |= PFD_DOUBLEBUFFER ; // Double buffered is optional
-
- if(STEREO_ON==glCaps->stereo)
- pfd->dwFlags |= PFD_STEREO ; // Stereo is optional
-
- if(hdc!=NULL && GetDeviceCaps(hdc, BITSPIXEL)<colorBits)
- pfd->cColorBits = GetDeviceCaps(hdc, BITSPIXEL);
- else
- pfd->cColorBits = (BYTE)colorBits;
-
- pfd->cStencilBits = (BYTE) glCaps->stencilBits;
-}
-
-
-void LIBAPIENTRY SetDCPixelFormat(HDC hDC, GLCapabilities *glCaps,
- int offScreenRenderer, int verbose)
-{
- int nPixelFormat=-1;
- const char * text=0;
-
- PIXELFORMATDESCRIPTOR pfd ;
-
- if(verbose)
- {
- fprintf(stdout, "GL4Java SetDCPixelFormat: input capabilities:\n");
- printGLCapabilities ( glCaps );
- }
-
- if(glCaps->nativeVisualID>=0)
- {
- if ( 0 < DescribePixelFormat( hDC, (int)(glCaps->nativeVisualID),
- sizeof(pfd), &pfd ) )
- {
- nPixelFormat=(int)(glCaps->nativeVisualID);
- if(verbose)
- {
- fprintf(stderr,"\n\nUSER found stored PIXELFORMAT number: %ld\n",
- nPixelFormat);
- fflush(stderr);
- }
- } else {
- fprintf(stderr,"\n\nUSER no stored PIXELFORMAT number found !!\n");
- nPixelFormat = -1;
- fflush(stderr);
- }
- }
-
- if(nPixelFormat<0)
- setPixelFormatByGLCapabilities( &pfd, glCaps, offScreenRenderer, hDC);
-
- if(verbose)
- {
- fprintf(stderr,"\n\nUSER CHOOSED PIXELFORMAT (TRYING):\n");
- text=GetTextualPixelFormatByPFD(&pfd, nPixelFormat);
- fprintf(stderr,text);
- fflush(stderr);
- }
-
- // Choose a pixel format that best matches that described in pfd
- if( hDC == 0 )
- printf( "SetDCPixelFormat: Error, no HDC-Contex is given\n");
- else if(nPixelFormat<0)
- nPixelFormat = ChoosePixelFormat(hDC, &pfd);
-
- if( nPixelFormat == 0 )
- printf( "SetDCPixelFormat: Error with PixelFormat\n" );
-
- // Set the pixel format for the device context
- if( SetPixelFormat(hDC, nPixelFormat, &pfd) == FALSE)
- printf( "setpixel failed\n" );
- else {
- (void) setGLCapabilities ( hDC, nPixelFormat, glCaps );
- if(verbose)
- {
- fprintf(stdout, "GL4Java SetDCPixelFormat: used capabilities:\n");
- printGLCapabilities ( glCaps );
- }
- }
- fflush(stdout);
- fflush(stderr);
-}
-
-
-// If necessary, creates a 3-3-2 palette for the device context listed.
-HPALETTE LIBAPIENTRY GetOpenGLPalette(HDC hDC)
-{
- HPALETTE hRetPal = NULL; // Handle to palette to be created
- PIXELFORMATDESCRIPTOR pfd; // Pixel Format Descriptor
- LOGPALETTE *pPal=0; // Pointer to memory for logical palette
- int nPixelFormat=0; // Pixel format index
- int nColors=0; // Number of entries in palette
- int i=0; // Counting variable
- BYTE RedRange=0,GreenRange=0,BlueRange=0;
- // Range for each color entry (7,7,and 3)
-
-
- // Get the pixel format index and retrieve the pixel format description
- nPixelFormat = GetPixelFormat(hDC);
- DescribePixelFormat(hDC, nPixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
-
- // Does this pixel format require a palette? If not, do not create a
- // palette and just return NULL
- if(!(pfd.dwFlags & PFD_NEED_PALETTE))
- return NULL;
-
- // Number of entries in palette. 8 bits yeilds 256 entries
- nColors = 1 << pfd.cColorBits;
-
- // Allocate space for a logical palette structure plus all the palette entries
- pPal = (LOGPALETTE*)malloc(sizeof(LOGPALETTE) + nColors*sizeof(PALETTEENTRY));
-
- // Fill in palette header
- pPal->palVersion = 0x300; // Windows 3.0
- pPal->palNumEntries = nColors; // table size
-
- // Build mask of all 1's. This creates a number represented by having
- // the low order x bits set, where x = pfd.cRedBits, pfd.cGreenBits, and
- // pfd.cBlueBits.
- RedRange = (1 << pfd.cRedBits) -1;
- GreenRange = (1 << pfd.cGreenBits) - 1;
- BlueRange = (1 << pfd.cBlueBits) -1;
-
- // Loop through all the palette entries
- for(i = 0; i < nColors; i++)
- {
- // Fill in the 8-bit equivalents for each component
- pPal->palPalEntry[i].peRed = (i >> pfd.cRedShift) & RedRange;
- pPal->palPalEntry[i].peRed = (unsigned char)(
- (double) pPal->palPalEntry[i].peRed * 255.0 / RedRange);
-
- pPal->palPalEntry[i].peGreen = (i >> pfd.cGreenShift) & GreenRange;
- pPal->palPalEntry[i].peGreen = (unsigned char)(
- (double)pPal->palPalEntry[i].peGreen * 255.0 / GreenRange);
-
- pPal->palPalEntry[i].peBlue = (i >> pfd.cBlueShift) & BlueRange;
- pPal->palPalEntry[i].peBlue = (unsigned char)(
- (double)pPal->palPalEntry[i].peBlue * 255.0 / BlueRange);
-
- pPal->palPalEntry[i].peFlags = (unsigned char) NULL;
- }
-
-
- // Create the palette
- hRetPal = CreatePalette(pPal);
-
- // Go ahead and select and realize the palette for this device context
- SelectPalette(hDC,hRetPal,FALSE);
- RealizePalette(hDC);
-
- // Free the memory used for the logical palette structure
- free(pPal);
-
- // Return the handle to the new palette
- return hRetPal;
-}
-
-
-static void
-PrintMessage( const char *Format, ... )
-{
- va_list ArgList;
- char Buffer[256];
-
- va_start(ArgList, Format);
- vsprintf(Buffer, Format, ArgList);
- va_end(ArgList);
-
- fprintf(stderr, Buffer);
-}
-
-
-int LIBAPIENTRY
-PixelFormatDescriptorFromDc( HDC Dc, PIXELFORMATDESCRIPTOR *Pfd )
-{
- int PfdIndex;
-
- if ( 0 < (PfdIndex = GetPixelFormat( Dc )) )
- {
- if ( 0 < DescribePixelFormat( Dc, PfdIndex, sizeof(*Pfd), Pfd ) )
- {
- return(PfdIndex);
- }
- else
- {
- PrintMessage("Could not get a description of pixel format %d\n",
- PfdIndex );
- }
- }
- else
- {
- PrintMessage("Could not get pixel format for Dc 0x%08lX\n", Dc );
- }
- return( 0 );
-}
-
-
-const char * LIBAPIENTRY
-GetTextualPixelFormatByPFD(PIXELFORMATDESCRIPTOR *ppfd, int format)
-{
- static char buffer[2000];
- char line[200];
-
- sprintf(buffer,"Pixel format %d\n", format);
- sprintf(line," dwFlags - 0x%x\n", ppfd->dwFlags);
- if (ppfd->dwFlags & PFD_DOUBLEBUFFER) { strcat(buffer, line); sprintf(line,"\tPFD_DOUBLEBUFFER\n "); }
- if (ppfd->dwFlags & PFD_STEREO) { strcat(buffer, line); sprintf(line,"\tPFD_STEREO\n "); }
- if (ppfd->dwFlags & PFD_DRAW_TO_WINDOW) { strcat(buffer, line); sprintf(line,"\tPFD_DRAW_TO_WINDOW\n "); }
- if (ppfd->dwFlags & PFD_DRAW_TO_BITMAP) { strcat(buffer, line); sprintf(line,"\tPFD_DRAW_TO_BITMAP\n "); }
- if (ppfd->dwFlags & PFD_SUPPORT_GDI) { strcat(buffer, line); sprintf(line,"\tPFD_SUPPORT_GDI\n "); }
- if (ppfd->dwFlags & PFD_SUPPORT_OPENGL) { strcat(buffer, line); sprintf(line,"\tPFD_SUPPORT_OPENGL\n "); }
- if (ppfd->dwFlags & PFD_GENERIC_ACCELERATED) { strcat(buffer, line); sprintf(line,"\tPFD_GENERIC_ACCELERATED\n "); }
- if (ppfd->dwFlags & PFD_GENERIC_FORMAT) { strcat(buffer, line); sprintf(line,"\tPFD_GENERIC_FORMAT\n "); }
- if (ppfd->dwFlags & PFD_NEED_PALETTE) { strcat(buffer, line); sprintf(line,"\tPFD_NEED_PALETTE\n "); }
- if (ppfd->dwFlags & PFD_NEED_SYSTEM_PALETTE) { strcat(buffer, line); sprintf(line,"\tPFD_NEED_SYSTEM_PALETTE\n "); }
- strcat(buffer, line); sprintf(line,"\n");
- strcat(buffer, line); sprintf(line," iPixelType - %d\n", ppfd->iPixelType);
- if (ppfd->iPixelType == PFD_TYPE_RGBA) { strcat(buffer, line); sprintf(line,"\tPGD_TYPE_RGBA\n"); }
- if (ppfd->iPixelType == PFD_TYPE_COLORINDEX) { strcat(buffer, line); sprintf(line,"\tPGD_TYPE_COLORINDEX\n"); }
- strcat(buffer, line); sprintf(line," cColorBits - %d\n", ppfd->cColorBits);
- strcat(buffer, line); sprintf(line," cRedBits - %d\n", ppfd->cRedBits);
- strcat(buffer, line); sprintf(line," cRedShift - %d\n", ppfd->cRedShift);
- strcat(buffer, line); sprintf(line," cGreenBits - %d\n", ppfd->cGreenBits);
- strcat(buffer, line); sprintf(line," cGreenShift - %d\n", ppfd->cGreenShift);
- strcat(buffer, line); sprintf(line," cBlueBits - %d\n", ppfd->cBlueBits);
- strcat(buffer, line); sprintf(line," cBlueShift - %d\n", ppfd->cBlueShift);
- strcat(buffer, line); sprintf(line," cAlphaBits - %d (N.A.)\n", ppfd->cAlphaBits);
- strcat(buffer, line); sprintf(line," cAlphaShift - 0x%x (N.A.)\n", ppfd->cAlphaShift);
- strcat(buffer, line); sprintf(line," cAccumBits - %d\n", ppfd->cAccumBits);
- strcat(buffer, line); sprintf(line," cAccumRedBits - %d\n", ppfd->cAccumRedBits);
- strcat(buffer, line); sprintf(line," cAccumGreenBits - %d\n", ppfd->cAccumGreenBits);
- strcat(buffer, line); sprintf(line," cAccumBlueBits - %d\n", ppfd->cAccumBlueBits);
- strcat(buffer, line); sprintf(line," cAccumAlphaBits - %d\n", ppfd->cAccumAlphaBits);
- strcat(buffer, line); sprintf(line," cDepthBits - %d\n", ppfd->cDepthBits);
- strcat(buffer, line); sprintf(line," cStencilBits - %d\n", ppfd->cStencilBits);
- strcat(buffer, line); sprintf(line," cAuxBuffers - %d\n", ppfd->cAuxBuffers);
- strcat(buffer, line); sprintf(line," iLayerType - %d\n", ppfd->iLayerType);
- strcat(buffer, line); sprintf(line," bReserved - %d\n", ppfd->bReserved);
- strcat(buffer, line); sprintf(line," dwLayerMask - 0x%x\n", ppfd->dwLayerMask);
- strcat(buffer, line); sprintf(line," dwVisibleMask - 0x%x\n", ppfd->dwVisibleMask);
- strcat(buffer, line); sprintf(line," dwDamageMask - 0x%x\n", ppfd->dwDamageMask);
- strcat(buffer, line);
- return buffer;
-}
-
-const char * LIBAPIENTRY GetTextualPixelFormatByHDC(HDC hdc)
-{
- PIXELFORMATDESCRIPTOR pfd, *ppfd=0;
- int format=0;
-
- ppfd = &pfd;
- format = PixelFormatDescriptorFromDc( hdc, ppfd );
-
- return GetTextualPixelFormatByPFD(ppfd, format);
-}
-
-/*****************************************************************/
-
-/* Struct used to manage color ramps */
-typedef struct {
- GLfloat amb[3]; /* ambient color / bottom of ramp */
- GLfloat diff[3]; /* diffuse color / middle of ramp */
- GLfloat spec[3]; /* specular color / top of ramp */
- GLfloat ratio; /* ratio of diffuse to specular in ramp */
- GLint indexes[3]; /* where ramp was placed in palette */
-} colorIndexState ;
-
-#define NUM_COLORS (sizeof(colors) / sizeof(colors[0]))
-
-void LIBAPIENTRY
-setupDIB(HDC hDCOrig, HDC hDC, HBITMAP * hBitmap, int width, int height)
-{
- BITMAPINFO *bmInfo=0;
- BITMAPINFOHEADER *bmHeader=0;
- UINT usage=0;
- VOID *base=0;
- int bmiSize=0;
- int bitsPerPixel=0;
- HBITMAP hOldBitmap=0;
-
- bmiSize = sizeof(*bmInfo);
- bitsPerPixel = GetDeviceCaps(hDC, BITSPIXEL);
-
- switch (bitsPerPixel) {
- case 8:
- // bmiColors is 256 WORD palette indices
- bmiSize += (256 * sizeof(WORD)) - sizeof(RGBQUAD);
- break;
- case 16:
- // bmiColors is 3 WORD component masks
- bmiSize += (3 * sizeof(DWORD)) - sizeof(RGBQUAD);
- break;
- case 24:
- case 32:
- default:
- // bmiColors not used
- break;
- }
-
- bmInfo = (BITMAPINFO *) calloc(1, bmiSize);
- bmHeader = &bmInfo->bmiHeader;
-
- bmHeader->biSize = sizeof(*bmHeader);
- bmHeader->biWidth = width;
- bmHeader->biHeight = height;
- bmHeader->biPlanes = 1; // must be 1
- bmHeader->biBitCount = bitsPerPixel;
- bmHeader->biXPelsPerMeter = 0;
- bmHeader->biYPelsPerMeter = 0;
- bmHeader->biClrUsed = 0; // all are used
- bmHeader->biClrImportant = 0; // all are important
-
- switch (bitsPerPixel) {
- case 8:
- bmHeader->biCompression = BI_RGB;
- bmHeader->biSizeImage = 0;
- usage = DIB_PAL_COLORS;
- // bmiColors is 256 WORD palette indices
- {
- WORD *palIndex = (WORD *) &bmInfo->bmiColors[0];
- int i;
-
- for (i=0; i<256; i++) {
- palIndex[i] = i;
- }
- }
- break;
- case 16:
- bmHeader->biCompression = BI_RGB;
- bmHeader->biSizeImage = 0;
- usage = DIB_RGB_COLORS;
- // bmiColors is 3 WORD component masks
- {
- DWORD *compMask = (DWORD *) &bmInfo->bmiColors[0];
-
- compMask[0] = 0xF800;
- compMask[1] = 0x07E0;
- compMask[2] = 0x001F;
- }
- break;
- case 24:
- case 32:
- default:
- bmHeader->biCompression = BI_RGB;
- bmHeader->biSizeImage = 0;
- usage = DIB_RGB_COLORS;
- // bmiColors not used
- break;
- }
-
- *hBitmap = CreateDIBSection(hDC, bmInfo, usage, &base, NULL, 0);
- if (*hBitmap == NULL) {
- (void) MessageBox(WindowFromDC(hDC),
- "Failed to create DIBSection.",
- "OpenGL application error",
- MB_ICONERROR | MB_OK);
- exit(1);
- }
-
- hOldBitmap = SelectObject(hDC, *hBitmap);
- if(hOldBitmap!=0)
- DeleteObject(hOldBitmap);
-
- free(bmInfo);
-}
-
-
-/*
-static void
-setupDIB(HDC hDCOrig, HDC hDC, HBITMAP * hBitmap, int width, int height)
-{
- HBITMAP hOldBitmap=0;
-
- *hBitmap = CreateCompatibleBitmap( hDCOrig, width, height );
- if (*hBitmap == NULL) {
- fprintf(stderr,"Failed to create CreateCompatibleBitmap! \n");
- fflush(stderr);
- return;
- }
-
- hOldBitmap = SelectObject(hDC, *hBitmap);
- if(hOldBitmap!=0)
- DeleteObject(hOldBitmap);
-}
-*/
-
-
-void LIBAPIENTRY resizeDIB(HDC hDC, HBITMAP *hOldBitmap, HBITMAP *hBitmap)
-{
- /*
- SelectObject(hDC, *hOldBitmap);
- DeleteObject(*hBitmap);
- setupDIB(hDC, hBitmap);
- */
-}
-
-HPALETTE LIBAPIENTRY setupPalette(HDC hDC)
-{
- HPALETTE hPalette = NULL;
- PIXELFORMATDESCRIPTOR pfd;
- LOGPALETTE* pPal=0;
- int pixelFormat = GetPixelFormat(hDC);
- int paletteSize=0;
- colorIndexState colors[] = {
- {
- { 0.0F, 0.0F, 0.0F },
- { 0.1F, 0.6F, 0.3F },
- { 1.0F, 1.0F, 1.0F },
- 0.75F, { 0, 0, 0 },
- },
- {
- { 0.0F, 0.0F, 0.0F },
- { 0.0F, 0.2F, 0.5F },
- { 1.0F, 1.0F, 1.0F },
- 0.75F, { 0, 0, 0 },
- },
- {
- { 0.0F, 0.05F, 0.05F },
- { 0.6F, 0.0F, 0.8F },
- { 1.0F, 1.0F, 1.0F },
- 0.75F, { 0, 0, 0 },
- },
- };
-
-
- DescribePixelFormat(hDC, pixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
-
- /*
- ** Determine if a palette is needed and if so what size.
- */
- if (pfd.dwFlags & PFD_NEED_PALETTE) {
- paletteSize = 1 << pfd.cColorBits;
- } else if (pfd.iPixelType == PFD_TYPE_COLORINDEX) {
- paletteSize = 4096;
- } else {
- return NULL;
- }
-
- pPal = (LOGPALETTE*)
- malloc(sizeof(LOGPALETTE) + paletteSize * sizeof(PALETTEENTRY));
- pPal->palVersion = 0x300;
- pPal->palNumEntries = paletteSize;
-
- if (pfd.iPixelType == PFD_TYPE_RGBA) {
- /*
- ** Fill the logical paletee with RGB color ramps
- */
- int redMask = (1 << pfd.cRedBits) - 1;
- int greenMask = (1 << pfd.cGreenBits) - 1;
- int blueMask = (1 << pfd.cBlueBits) - 1;
- int i;
-
-
-
- for (i=0; i<paletteSize; ++i) {
- pPal->palPalEntry[i].peRed =
- (((i >> pfd.cRedShift) & redMask) * 255) / redMask;
- pPal->palPalEntry[i].peGreen =
- (((i >> pfd.cGreenShift) & greenMask) * 255) / greenMask;
- pPal->palPalEntry[i].peBlue =
- (((i >> pfd.cBlueShift) & blueMask) * 255) / blueMask;
- pPal->palPalEntry[i].peFlags = 0;
- }
- } else {
- /*
- ** Fill the logical palette with color ramps.
- **
- ** Set up the logical palette so that it can be realized
- ** into the system palette as an identity palette.
- **
- ** 1) The default static entries should be present and at the right
- ** location. The easiest way to do this is to grab them from
- ** the current system palette.
- **
- ** 2) All non-static entries should be initialized to unique values.
- ** The easiest way to do this is to ensure that all of the non-static
- ** entries have the PC_NOCOLLAPSE flag bit set.
- */
- int numRamps = NUM_COLORS;
- int rampSize = (paletteSize - 20) / numRamps;
- int extra = (paletteSize - 20) - (numRamps * rampSize);
- int i, r;
-
- /*
- ** Initialize static entries by copying them from the
- ** current system palette.
- */
- GetSystemPaletteEntries(hDC, 0, paletteSize, &pPal->palPalEntry[0]);
-
- /*
- ** Fill in non-static entries with desired colors.
- */
- for (r=0; r<numRamps; ++r) {
- int rampBase = r * rampSize + 10;
- PALETTEENTRY *pe = &pPal->palPalEntry[rampBase];
- int diffSize = (int) (rampSize * colors[r].ratio);
- int specSize = rampSize - diffSize;
-
- for (i=0; i<rampSize; ++i) {
- GLfloat *c0, *c1;
- GLint a;
-
- if (i < diffSize) {
- c0 = colors[r].amb;
- c1 = colors[r].diff;
- a = (i * 255) / (diffSize - 1);
- } else {
- c0 = colors[r].diff;
- c1 = colors[r].spec;
- a = ((i - diffSize) * 255) / (specSize - 1);
- }
-
- pe[i].peRed = (BYTE) (a * (c1[0] - c0[0]) + 255 * c0[0]);
- pe[i].peGreen = (BYTE) (a * (c1[1] - c0[1]) + 255 * c0[1]);
- pe[i].peBlue = (BYTE) (a * (c1[2] - c0[2]) + 255 * c0[2]);
- pe[i].peFlags = PC_NOCOLLAPSE;
- }
-
- colors[r].indexes[0] = rampBase;
- colors[r].indexes[1] = rampBase + (diffSize-1);
- colors[r].indexes[2] = rampBase + (rampSize-1);
- }
-
- /*
- ** Initialize any remaining non-static entries.
- */
- for (i=0; i<extra; ++i) {
- int index = numRamps*rampSize+10+i;
- PALETTEENTRY *pe = &pPal->palPalEntry[index];
-
- pe->peRed = (BYTE) 0;
- pe->peGreen = (BYTE) 0;
- pe->peBlue = (BYTE) 0;
- pe->peFlags = PC_NOCOLLAPSE;
- }
- }
-
- hPalette = CreatePalette(pPal);
- free(pPal);
-
- if (hPalette) {
- SelectPalette(hDC, hPalette, FALSE);
- RealizePalette(hDC);
- }
-
- return hPalette;
-}
-
-
-int LIBAPIENTRY setGLCapabilities ( HDC hdc,
- int nPixelFormat,
- GLCapabilities *glCaps )
-{
- PIXELFORMATDESCRIPTOR pfd;
-
- (void) PixelFormatDescriptorFromDc( hdc, &pfd);
-
- if (pfd.dwFlags & PFD_DOUBLEBUFFER)
- glCaps->buffer=BUFFER_DOUBLE;
- else
- glCaps->buffer=BUFFER_SINGLE;
-
- if (pfd.dwFlags & PFD_STEREO)
- glCaps->stereo=STEREO_ON;
- else
- glCaps->stereo=STEREO_OFF;
-
- if (pfd.iPixelType == PFD_TYPE_RGBA)
- glCaps->color=COLOR_RGBA;
-
- if (pfd.iPixelType == PFD_TYPE_COLORINDEX)
- glCaps->color=COLOR_INDEX;
-
- glCaps->depthBits = pfd.cDepthBits;
- glCaps->stencilBits = pfd.cStencilBits;
-
- glCaps->redBits = pfd.cRedBits;
- glCaps->greenBits= pfd.cGreenBits;
- glCaps->blueBits= pfd.cBlueBits;
- /* glCaps->alphaBits= pfd.cAlphaBits; N.A. */
- glCaps->accumRedBits = pfd.cAccumRedBits;
- glCaps->accumGreenBits= pfd.cAccumGreenBits;
- glCaps->accumBlueBits= pfd.cAccumBlueBits;
- glCaps->accumAlphaBits= pfd.cAccumAlphaBits;
-
- glCaps->nativeVisualID=nPixelFormat;
-
- return 1;
-}
-
+
+
+HGLRC LIBAPIENTRY get_GC( HDC * hDC, GLCapabilities *glCaps,
+ HGLRC shareWith,
+ int offScreenRenderer,
+ int width, int height, HBITMAP *pix,
+ int verbose)
+
+{
+ const char * text=0;
+ HDC hDCOrig = 0;
+
+ // Color Palette handle
+ HPALETTE hPalette = NULL;
+ HGLRC tempRC=0;
+
+ if( *hDC == 0 && !offScreenRenderer)
+ printf( "get_GC: Error, HDC is zero\n");
+
+ // Select the pixel format
+ if(offScreenRenderer)
+ {
+ hDCOrig = *hDC;
+ *hDC = CreateCompatibleDC(hDCOrig);
+ // setupDIB(*hDC, pix, width, height);
+ setupDIB(hDCOrig, *hDC, pix, width, height);
+ /* SetDCPixelFormat(hDCOffScr, doubleBuffer, stereo, stencilBits, offScreenRenderer); */
+ /* setupPalette(hDC); USE MY PROC */
+ }
+
+ SetDCPixelFormat(*hDC, glCaps, offScreenRenderer, verbose);
+
+ // Create palette if needed
+ hPalette = GetOpenGLPalette(*hDC);
+
+ tempRC = disp__wglCreateContext( *hDC );
+
+ if(verbose)
+ {
+ fprintf(stderr,"\n\nPIXELFORMAT OF GL-Context SETTINGS:\n");
+ text=GetTextualPixelFormatByHDC(*hDC);
+ fprintf(stderr,text);
+ }
+
+ /* check if the context could be created */
+ if( tempRC == NULL ) {
+ fprintf(stderr, "getGC context could NOT be created \n");
+ return( 0 );
+ }
+
+ /* associated the context with the X window */
+ if( disp__wglMakeCurrent( *hDC, tempRC ) == FALSE) {
+ fprintf(stderr,"wglMakeCurrent(%p,%p) failed on new context!!!\n", *hDC,tempRC);
+ fprintf(stderr,"Error code = %d\n",(int)GetLastError());
+ disp__wglMakeCurrent(NULL, NULL);
+ disp__wglDeleteContext( tempRC );
+ return( 0 );
+ }
+
+ if(shareWith!=NULL && disp__wglShareLists(shareWith, tempRC)==FALSE)
+ {
+ fprintf(stderr,"\nERROR: Could not share lists between the new and the given GLContext (Win32Native)!\n");
+ fprintf(stderr,"Error code = %d\n",(int)GetLastError());
+ disp__wglMakeCurrent(NULL, NULL);
+ disp__wglDeleteContext( tempRC );
+ return( 0 );
+ }
+
+ if(verbose)
+ printf( "HGLRC (glContext) created: %p\n", tempRC );
+
+ return tempRC;
+}
+
+void LIBAPIENTRY setPixelFormatByGLCapabilities(
+ PIXELFORMATDESCRIPTOR *pfd,
+ GLCapabilities *glCaps,
+ int offScreenRenderer,
+ HDC hdc)
+{
+
+ int colorBits = glCaps->redBits + glCaps->greenBits + glCaps->blueBits;
+
+ pfd->nSize=sizeof(PIXELFORMATDESCRIPTOR);
+ pfd->nVersion=1;
+ pfd->dwFlags=PFD_SUPPORT_OPENGL | PFD_GENERIC_ACCELERATED; /* refined later */
+ pfd->iPixelType=0;
+ pfd->cColorBits=0;
+ pfd->cRedBits=0;
+ pfd->cRedShift=0;
+ pfd->cGreenBits=0;
+ pfd->cGreenShift=0;
+ pfd->cBlueBits=0;
+ pfd->cBlueShift=0;
+ pfd->cAlphaBits=0;
+ pfd->cAlphaShift=0;
+ pfd->cAccumBits=0;
+ pfd->cAccumRedBits=0;
+ pfd->cAccumGreenBits=0;
+ pfd->cAccumBlueBits=0;
+ pfd->cAccumAlphaBits=0;
+ pfd->cDepthBits=32;
+ pfd->cStencilBits=0;
+ pfd->cAuxBuffers=0;
+ pfd->iLayerType=PFD_MAIN_PLANE;
+ pfd->bReserved=0;
+ pfd->dwLayerMask=0;
+ pfd->dwVisibleMask=0;
+ pfd->dwDamageMask=0;
+
+ if(COLOR_RGBA == glCaps->color)
+ pfd->iPixelType=PFD_TYPE_RGBA;
+ else
+ pfd->iPixelType=PFD_TYPE_COLORINDEX;
+
+ if(offScreenRenderer)
+ pfd->dwFlags |= PFD_DRAW_TO_BITMAP; // Draw to Bitmap
+ else
+ pfd->dwFlags |= PFD_DRAW_TO_WINDOW; // Draw to Window (not to bitmap)
+
+
+ if(BUFFER_DOUBLE==glCaps->buffer)
+ pfd->dwFlags |= PFD_DOUBLEBUFFER ; // Double buffered is optional
+
+ if(STEREO_ON==glCaps->stereo)
+ pfd->dwFlags |= PFD_STEREO ; // Stereo is optional
+
+ if(hdc!=NULL && GetDeviceCaps(hdc, BITSPIXEL)<colorBits)
+ pfd->cColorBits = GetDeviceCaps(hdc, BITSPIXEL);
+ else
+ pfd->cColorBits = (BYTE)colorBits;
+
+ pfd->cStencilBits = (BYTE) glCaps->stencilBits;
+}
+
+
+void LIBAPIENTRY SetDCPixelFormat(HDC hDC, GLCapabilities *glCaps,
+ int offScreenRenderer, int verbose)
+{
+ int nPixelFormat=-1;
+ const char * text=0;
+
+ PIXELFORMATDESCRIPTOR pfd ;
+
+ if(verbose)
+ {
+ fprintf(stdout, "GL4Java SetDCPixelFormat: input capabilities:\n");
+ printGLCapabilities ( glCaps );
+ }
+
+ if(glCaps->nativeVisualID>=0)
+ {
+ if ( 0 < DescribePixelFormat( hDC, (int)(glCaps->nativeVisualID),
+ sizeof(pfd), &pfd ) )
+ {
+ nPixelFormat=(int)(glCaps->nativeVisualID);
+ if(verbose)
+ {
+ fprintf(stderr,"\n\nUSER found stored PIXELFORMAT number: %ld\n",
+ nPixelFormat);
+ fflush(stderr);
+ }
+ } else {
+ fprintf(stderr,"\n\nUSER no stored PIXELFORMAT number found !!\n");
+ nPixelFormat = -1;
+ fflush(stderr);
+ }
+ }
+
+ if(nPixelFormat<0)
+ setPixelFormatByGLCapabilities( &pfd, glCaps, offScreenRenderer, hDC);
+
+ if(verbose)
+ {
+ fprintf(stderr,"\n\nUSER CHOOSED PIXELFORMAT (TRYING):\n");
+ text=GetTextualPixelFormatByPFD(&pfd, nPixelFormat);
+ fprintf(stderr,text);
+ fflush(stderr);
+ }
+
+ // Choose a pixel format that best matches that described in pfd
+ if( hDC == 0 )
+ printf( "SetDCPixelFormat: Error, no HDC-Contex is given\n");
+ else if(nPixelFormat<0)
+ nPixelFormat = ChoosePixelFormat(hDC, &pfd);
+
+ if( nPixelFormat == 0 )
+ printf( "SetDCPixelFormat: Error with PixelFormat\n" );
+
+ // Set the pixel format for the device context
+ if( SetPixelFormat(hDC, nPixelFormat, &pfd) == FALSE)
+ printf( "setpixel failed\n" );
+ else {
+ (void) setGLCapabilities ( hDC, nPixelFormat, glCaps );
+ if(verbose)
+ {
+ fprintf(stdout, "GL4Java SetDCPixelFormat: used capabilities:\n");
+ printGLCapabilities ( glCaps );
+ }
+ }
+ fflush(stdout);
+ fflush(stderr);
+}
+
+
+// If necessary, creates a 3-3-2 palette for the device context listed.
+HPALETTE LIBAPIENTRY GetOpenGLPalette(HDC hDC)
+{
+ HPALETTE hRetPal = NULL; // Handle to palette to be created
+ PIXELFORMATDESCRIPTOR pfd; // Pixel Format Descriptor
+ LOGPALETTE *pPal=0; // Pointer to memory for logical palette
+ int nPixelFormat=0; // Pixel format index
+ int nColors=0; // Number of entries in palette
+ int i=0; // Counting variable
+ BYTE RedRange=0,GreenRange=0,BlueRange=0;
+ // Range for each color entry (7,7,and 3)
+
+
+ // Get the pixel format index and retrieve the pixel format description
+ nPixelFormat = GetPixelFormat(hDC);
+ DescribePixelFormat(hDC, nPixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
+
+ // Does this pixel format require a palette? If not, do not create a
+ // palette and just return NULL
+ if(!(pfd.dwFlags & PFD_NEED_PALETTE))
+ return NULL;
+
+ // Number of entries in palette. 8 bits yeilds 256 entries
+ nColors = 1 << pfd.cColorBits;
+
+ // Allocate space for a logical palette structure plus all the palette entries
+ pPal = (LOGPALETTE*)malloc(sizeof(LOGPALETTE) + nColors*sizeof(PALETTEENTRY));
+
+ // Fill in palette header
+ pPal->palVersion = 0x300; // Windows 3.0
+ pPal->palNumEntries = nColors; // table size
+
+ // Build mask of all 1's. This creates a number represented by having
+ // the low order x bits set, where x = pfd.cRedBits, pfd.cGreenBits, and
+ // pfd.cBlueBits.
+ RedRange = (1 << pfd.cRedBits) -1;
+ GreenRange = (1 << pfd.cGreenBits) - 1;
+ BlueRange = (1 << pfd.cBlueBits) -1;
+
+ // Loop through all the palette entries
+ for(i = 0; i < nColors; i++)
+ {
+ // Fill in the 8-bit equivalents for each component
+ pPal->palPalEntry[i].peRed = (i >> pfd.cRedShift) & RedRange;
+ pPal->palPalEntry[i].peRed = (unsigned char)(
+ (double) pPal->palPalEntry[i].peRed * 255.0 / RedRange);
+
+ pPal->palPalEntry[i].peGreen = (i >> pfd.cGreenShift) & GreenRange;
+ pPal->palPalEntry[i].peGreen = (unsigned char)(
+ (double)pPal->palPalEntry[i].peGreen * 255.0 / GreenRange);
+
+ pPal->palPalEntry[i].peBlue = (i >> pfd.cBlueShift) & BlueRange;
+ pPal->palPalEntry[i].peBlue = (unsigned char)(
+ (double)pPal->palPalEntry[i].peBlue * 255.0 / BlueRange);
+
+ pPal->palPalEntry[i].peFlags = (unsigned char) NULL;
+ }
+
+
+ // Create the palette
+ hRetPal = CreatePalette(pPal);
+
+ // Go ahead and select and realize the palette for this device context
+ SelectPalette(hDC,hRetPal,FALSE);
+ RealizePalette(hDC);
+
+ // Free the memory used for the logical palette structure
+ free(pPal);
+
+ // Return the handle to the new palette
+ return hRetPal;
+}
+
+
+static void
+PrintMessage( const char *Format, ... )
+{
+ va_list ArgList;
+ char Buffer[256];
+
+ va_start(ArgList, Format);
+ vsprintf(Buffer, Format, ArgList);
+ va_end(ArgList);
+
+ fprintf(stderr, Buffer);
+}
+
+
+int LIBAPIENTRY
+PixelFormatDescriptorFromDc( HDC Dc, PIXELFORMATDESCRIPTOR *Pfd )
+{
+ int PfdIndex;
+
+ if ( 0 < (PfdIndex = GetPixelFormat( Dc )) )
+ {
+ if ( 0 < DescribePixelFormat( Dc, PfdIndex, sizeof(*Pfd), Pfd ) )
+ {
+ return(PfdIndex);
+ }
+ else
+ {
+ PrintMessage("Could not get a description of pixel format %d\n",
+ PfdIndex );
+ }
+ }
+ else
+ {
+ PrintMessage("Could not get pixel format for Dc 0x%08lX\n", Dc );
+ }
+ return( 0 );
+}
+
+
+const char * LIBAPIENTRY
+GetTextualPixelFormatByPFD(PIXELFORMATDESCRIPTOR *ppfd, int format)
+{
+ static char buffer[2000];
+ char line[200];
+
+ sprintf(buffer,"Pixel format %d\n", format);
+ sprintf(line," dwFlags - 0x%x\n", ppfd->dwFlags);
+ if (ppfd->dwFlags & PFD_DOUBLEBUFFER) { strcat(buffer, line); sprintf(line,"\tPFD_DOUBLEBUFFER\n "); }
+ if (ppfd->dwFlags & PFD_STEREO) { strcat(buffer, line); sprintf(line,"\tPFD_STEREO\n "); }
+ if (ppfd->dwFlags & PFD_DRAW_TO_WINDOW) { strcat(buffer, line); sprintf(line,"\tPFD_DRAW_TO_WINDOW\n "); }
+ if (ppfd->dwFlags & PFD_DRAW_TO_BITMAP) { strcat(buffer, line); sprintf(line,"\tPFD_DRAW_TO_BITMAP\n "); }
+ if (ppfd->dwFlags & PFD_SUPPORT_GDI) { strcat(buffer, line); sprintf(line,"\tPFD_SUPPORT_GDI\n "); }
+ if (ppfd->dwFlags & PFD_SUPPORT_OPENGL) { strcat(buffer, line); sprintf(line,"\tPFD_SUPPORT_OPENGL\n "); }
+ if (ppfd->dwFlags & PFD_GENERIC_ACCELERATED) { strcat(buffer, line); sprintf(line,"\tPFD_GENERIC_ACCELERATED\n "); }
+ if (ppfd->dwFlags & PFD_GENERIC_FORMAT) { strcat(buffer, line); sprintf(line,"\tPFD_GENERIC_FORMAT\n "); }
+ if (ppfd->dwFlags & PFD_NEED_PALETTE) { strcat(buffer, line); sprintf(line,"\tPFD_NEED_PALETTE\n "); }
+ if (ppfd->dwFlags & PFD_NEED_SYSTEM_PALETTE) { strcat(buffer, line); sprintf(line,"\tPFD_NEED_SYSTEM_PALETTE\n "); }
+ strcat(buffer, line); sprintf(line,"\n");
+ strcat(buffer, line); sprintf(line," iPixelType - %d\n", ppfd->iPixelType);
+ if (ppfd->iPixelType == PFD_TYPE_RGBA) { strcat(buffer, line); sprintf(line,"\tPGD_TYPE_RGBA\n"); }
+ if (ppfd->iPixelType == PFD_TYPE_COLORINDEX) { strcat(buffer, line); sprintf(line,"\tPGD_TYPE_COLORINDEX\n"); }
+ strcat(buffer, line); sprintf(line," cColorBits - %d\n", ppfd->cColorBits);
+ strcat(buffer, line); sprintf(line," cRedBits - %d\n", ppfd->cRedBits);
+ strcat(buffer, line); sprintf(line," cRedShift - %d\n", ppfd->cRedShift);
+ strcat(buffer, line); sprintf(line," cGreenBits - %d\n", ppfd->cGreenBits);
+ strcat(buffer, line); sprintf(line," cGreenShift - %d\n", ppfd->cGreenShift);
+ strcat(buffer, line); sprintf(line," cBlueBits - %d\n", ppfd->cBlueBits);
+ strcat(buffer, line); sprintf(line," cBlueShift - %d\n", ppfd->cBlueShift);
+ strcat(buffer, line); sprintf(line," cAlphaBits - %d (N.A.)\n", ppfd->cAlphaBits);
+ strcat(buffer, line); sprintf(line," cAlphaShift - 0x%x (N.A.)\n", ppfd->cAlphaShift);
+ strcat(buffer, line); sprintf(line," cAccumBits - %d\n", ppfd->cAccumBits);
+ strcat(buffer, line); sprintf(line," cAccumRedBits - %d\n", ppfd->cAccumRedBits);
+ strcat(buffer, line); sprintf(line," cAccumGreenBits - %d\n", ppfd->cAccumGreenBits);
+ strcat(buffer, line); sprintf(line," cAccumBlueBits - %d\n", ppfd->cAccumBlueBits);
+ strcat(buffer, line); sprintf(line," cAccumAlphaBits - %d\n", ppfd->cAccumAlphaBits);
+ strcat(buffer, line); sprintf(line," cDepthBits - %d\n", ppfd->cDepthBits);
+ strcat(buffer, line); sprintf(line," cStencilBits - %d\n", ppfd->cStencilBits);
+ strcat(buffer, line); sprintf(line," cAuxBuffers - %d\n", ppfd->cAuxBuffers);
+ strcat(buffer, line); sprintf(line," iLayerType - %d\n", ppfd->iLayerType);
+ strcat(buffer, line); sprintf(line," bReserved - %d\n", ppfd->bReserved);
+ strcat(buffer, line); sprintf(line," dwLayerMask - 0x%x\n", ppfd->dwLayerMask);
+ strcat(buffer, line); sprintf(line," dwVisibleMask - 0x%x\n", ppfd->dwVisibleMask);
+ strcat(buffer, line); sprintf(line," dwDamageMask - 0x%x\n", ppfd->dwDamageMask);
+ strcat(buffer, line);
+ return buffer;
+}
+
+const char * LIBAPIENTRY GetTextualPixelFormatByHDC(HDC hdc)
+{
+ PIXELFORMATDESCRIPTOR pfd, *ppfd=0;
+ int format=0;
+
+ ppfd = &pfd;
+ format = PixelFormatDescriptorFromDc( hdc, ppfd );
+
+ return GetTextualPixelFormatByPFD(ppfd, format);
+}
+
+/*****************************************************************/
+
+/* Struct used to manage color ramps */
+typedef struct {
+ GLfloat amb[3]; /* ambient color / bottom of ramp */
+ GLfloat diff[3]; /* diffuse color / middle of ramp */
+ GLfloat spec[3]; /* specular color / top of ramp */
+ GLfloat ratio; /* ratio of diffuse to specular in ramp */
+ GLint indexes[3]; /* where ramp was placed in palette */
+} colorIndexState ;
+
+#define NUM_COLORS (sizeof(colors) / sizeof(colors[0]))
+
+void LIBAPIENTRY
+setupDIB(HDC hDCOrig, HDC hDC, HBITMAP * hBitmap, int width, int height)
+{
+ BITMAPINFO *bmInfo=0;
+ BITMAPINFOHEADER *bmHeader=0;
+ UINT usage=0;
+ VOID *base=0;
+ int bmiSize=0;
+ int bitsPerPixel=0;
+ HBITMAP hOldBitmap=0;
+
+ bmiSize = sizeof(*bmInfo);
+ bitsPerPixel = GetDeviceCaps(hDC, BITSPIXEL);
+
+ switch (bitsPerPixel) {
+ case 8:
+ // bmiColors is 256 WORD palette indices
+ bmiSize += (256 * sizeof(WORD)) - sizeof(RGBQUAD);
+ break;
+ case 16:
+ // bmiColors is 3 WORD component masks
+ bmiSize += (3 * sizeof(DWORD)) - sizeof(RGBQUAD);
+ break;
+ case 24:
+ case 32:
+ default:
+ // bmiColors not used
+ break;
+ }
+
+ bmInfo = (BITMAPINFO *) calloc(1, bmiSize);
+ bmHeader = &bmInfo->bmiHeader;
+
+ bmHeader->biSize = sizeof(*bmHeader);
+ bmHeader->biWidth = width;
+ bmHeader->biHeight = height;
+ bmHeader->biPlanes = 1; // must be 1
+ bmHeader->biBitCount = bitsPerPixel;
+ bmHeader->biXPelsPerMeter = 0;
+ bmHeader->biYPelsPerMeter = 0;
+ bmHeader->biClrUsed = 0; // all are used
+ bmHeader->biClrImportant = 0; // all are important
+
+ switch (bitsPerPixel) {
+ case 8:
+ bmHeader->biCompression = BI_RGB;
+ bmHeader->biSizeImage = 0;
+ usage = DIB_PAL_COLORS;
+ // bmiColors is 256 WORD palette indices
+ {
+ WORD *palIndex = (WORD *) &bmInfo->bmiColors[0];
+ int i;
+
+ for (i=0; i<256; i++) {
+ palIndex[i] = i;
+ }
+ }
+ break;
+ case 16:
+ bmHeader->biCompression = BI_RGB;
+ bmHeader->biSizeImage = 0;
+ usage = DIB_RGB_COLORS;
+ // bmiColors is 3 WORD component masks
+ {
+ DWORD *compMask = (DWORD *) &bmInfo->bmiColors[0];
+
+ compMask[0] = 0xF800;
+ compMask[1] = 0x07E0;
+ compMask[2] = 0x001F;
+ }
+ break;
+ case 24:
+ case 32:
+ default:
+ bmHeader->biCompression = BI_RGB;
+ bmHeader->biSizeImage = 0;
+ usage = DIB_RGB_COLORS;
+ // bmiColors not used
+ break;
+ }
+
+ *hBitmap = CreateDIBSection(hDC, bmInfo, usage, &base, NULL, 0);
+ if (*hBitmap == NULL) {
+ (void) MessageBox(WindowFromDC(hDC),
+ "Failed to create DIBSection.",
+ "OpenGL application error",
+ MB_ICONERROR | MB_OK);
+ exit(1);
+ }
+
+ hOldBitmap = SelectObject(hDC, *hBitmap);
+ if(hOldBitmap!=0)
+ DeleteObject(hOldBitmap);
+
+ free(bmInfo);
+}
+
+
+/*
+static void
+setupDIB(HDC hDCOrig, HDC hDC, HBITMAP * hBitmap, int width, int height)
+{
+ HBITMAP hOldBitmap=0;
+
+ *hBitmap = CreateCompatibleBitmap( hDCOrig, width, height );
+ if (*hBitmap == NULL) {
+ fprintf(stderr,"Failed to create CreateCompatibleBitmap! \n");
+ fflush(stderr);
+ return;
+ }
+
+ hOldBitmap = SelectObject(hDC, *hBitmap);
+ if(hOldBitmap!=0)
+ DeleteObject(hOldBitmap);
+}
+*/
+
+
+void LIBAPIENTRY resizeDIB(HDC hDC, HBITMAP *hOldBitmap, HBITMAP *hBitmap)
+{
+ /*
+ SelectObject(hDC, *hOldBitmap);
+ DeleteObject(*hBitmap);
+ setupDIB(hDC, hBitmap);
+ */
+}
+
+HPALETTE LIBAPIENTRY setupPalette(HDC hDC)
+{
+ HPALETTE hPalette = NULL;
+ PIXELFORMATDESCRIPTOR pfd;
+ LOGPALETTE* pPal=0;
+ int pixelFormat = GetPixelFormat(hDC);
+ int paletteSize=0;
+ colorIndexState colors[] = {
+ {
+ { 0.0F, 0.0F, 0.0F },
+ { 0.1F, 0.6F, 0.3F },
+ { 1.0F, 1.0F, 1.0F },
+ 0.75F, { 0, 0, 0 },
+ },
+ {
+ { 0.0F, 0.0F, 0.0F },
+ { 0.0F, 0.2F, 0.5F },
+ { 1.0F, 1.0F, 1.0F },
+ 0.75F, { 0, 0, 0 },
+ },
+ {
+ { 0.0F, 0.05F, 0.05F },
+ { 0.6F, 0.0F, 0.8F },
+ { 1.0F, 1.0F, 1.0F },
+ 0.75F, { 0, 0, 0 },
+ },
+ };
+
+
+ DescribePixelFormat(hDC, pixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
+
+ /*
+ ** Determine if a palette is needed and if so what size.
+ */
+ if (pfd.dwFlags & PFD_NEED_PALETTE) {
+ paletteSize = 1 << pfd.cColorBits;
+ } else if (pfd.iPixelType == PFD_TYPE_COLORINDEX) {
+ paletteSize = 4096;
+ } else {
+ return NULL;
+ }
+
+ pPal = (LOGPALETTE*)
+ malloc(sizeof(LOGPALETTE) + paletteSize * sizeof(PALETTEENTRY));
+ pPal->palVersion = 0x300;
+ pPal->palNumEntries = paletteSize;
+
+ if (pfd.iPixelType == PFD_TYPE_RGBA) {
+ /*
+ ** Fill the logical paletee with RGB color ramps
+ */
+ int redMask = (1 << pfd.cRedBits) - 1;
+ int greenMask = (1 << pfd.cGreenBits) - 1;
+ int blueMask = (1 << pfd.cBlueBits) - 1;
+ int i;
+
+
+
+ for (i=0; i<paletteSize; ++i) {
+ pPal->palPalEntry[i].peRed =
+ (((i >> pfd.cRedShift) & redMask) * 255) / redMask;
+ pPal->palPalEntry[i].peGreen =
+ (((i >> pfd.cGreenShift) & greenMask) * 255) / greenMask;
+ pPal->palPalEntry[i].peBlue =
+ (((i >> pfd.cBlueShift) & blueMask) * 255) / blueMask;
+ pPal->palPalEntry[i].peFlags = 0;
+ }
+ } else {
+ /*
+ ** Fill the logical palette with color ramps.
+ **
+ ** Set up the logical palette so that it can be realized
+ ** into the system palette as an identity palette.
+ **
+ ** 1) The default static entries should be present and at the right
+ ** location. The easiest way to do this is to grab them from
+ ** the current system palette.
+ **
+ ** 2) All non-static entries should be initialized to unique values.
+ ** The easiest way to do this is to ensure that all of the non-static
+ ** entries have the PC_NOCOLLAPSE flag bit set.
+ */
+ int numRamps = NUM_COLORS;
+ int rampSize = (paletteSize - 20) / numRamps;
+ int extra = (paletteSize - 20) - (numRamps * rampSize);
+ int i, r;
+
+ /*
+ ** Initialize static entries by copying them from the
+ ** current system palette.
+ */
+ GetSystemPaletteEntries(hDC, 0, paletteSize, &pPal->palPalEntry[0]);
+
+ /*
+ ** Fill in non-static entries with desired colors.
+ */
+ for (r=0; r<numRamps; ++r) {
+ int rampBase = r * rampSize + 10;
+ PALETTEENTRY *pe = &pPal->palPalEntry[rampBase];
+ int diffSize = (int) (rampSize * colors[r].ratio);
+ int specSize = rampSize - diffSize;
+
+ for (i=0; i<rampSize; ++i) {
+ GLfloat *c0, *c1;
+ GLint a;
+
+ if (i < diffSize) {
+ c0 = colors[r].amb;
+ c1 = colors[r].diff;
+ a = (i * 255) / (diffSize - 1);
+ } else {
+ c0 = colors[r].diff;
+ c1 = colors[r].spec;
+ a = ((i - diffSize) * 255) / (specSize - 1);
+ }
+
+ pe[i].peRed = (BYTE) (a * (c1[0] - c0[0]) + 255 * c0[0]);
+ pe[i].peGreen = (BYTE) (a * (c1[1] - c0[1]) + 255 * c0[1]);
+ pe[i].peBlue = (BYTE) (a * (c1[2] - c0[2]) + 255 * c0[2]);
+ pe[i].peFlags = PC_NOCOLLAPSE;
+ }
+
+ colors[r].indexes[0] = rampBase;
+ colors[r].indexes[1] = rampBase + (diffSize-1);
+ colors[r].indexes[2] = rampBase + (rampSize-1);
+ }
+
+ /*
+ ** Initialize any remaining non-static entries.
+ */
+ for (i=0; i<extra; ++i) {
+ int index = numRamps*rampSize+10+i;
+ PALETTEENTRY *pe = &pPal->palPalEntry[index];
+
+ pe->peRed = (BYTE) 0;
+ pe->peGreen = (BYTE) 0;
+ pe->peBlue = (BYTE) 0;
+ pe->peFlags = PC_NOCOLLAPSE;
+ }
+ }
+
+ hPalette = CreatePalette(pPal);
+ free(pPal);
+
+ if (hPalette) {
+ SelectPalette(hDC, hPalette, FALSE);
+ RealizePalette(hDC);
+ }
+
+ return hPalette;
+}
+
+
+int LIBAPIENTRY setGLCapabilities ( HDC hdc,
+ int nPixelFormat,
+ GLCapabilities *glCaps )
+{
+ PIXELFORMATDESCRIPTOR pfd;
+
+ (void) PixelFormatDescriptorFromDc( hdc, &pfd);
+
+ if (pfd.dwFlags & PFD_DOUBLEBUFFER)
+ glCaps->buffer=BUFFER_DOUBLE;
+ else
+ glCaps->buffer=BUFFER_SINGLE;
+
+ if (pfd.dwFlags & PFD_STEREO)
+ glCaps->stereo=STEREO_ON;
+ else
+ glCaps->stereo=STEREO_OFF;
+
+ if (pfd.iPixelType == PFD_TYPE_RGBA)
+ glCaps->color=COLOR_RGBA;
+
+ if (pfd.iPixelType == PFD_TYPE_COLORINDEX)
+ glCaps->color=COLOR_INDEX;
+
+ glCaps->depthBits = pfd.cDepthBits;
+ glCaps->stencilBits = pfd.cStencilBits;
+
+ glCaps->redBits = pfd.cRedBits;
+ glCaps->greenBits= pfd.cGreenBits;
+ glCaps->blueBits= pfd.cBlueBits;
+ /* glCaps->alphaBits= pfd.cAlphaBits; N.A. */
+ glCaps->accumRedBits = pfd.cAccumRedBits;
+ glCaps->accumGreenBits= pfd.cAccumGreenBits;
+ glCaps->accumBlueBits= pfd.cAccumBlueBits;
+ glCaps->accumAlphaBits= pfd.cAccumAlphaBits;
+
+ glCaps->nativeVisualID=nPixelFormat;
+
+ return 1;
+}
+
diff --git a/CNativeCode/wgltool.h b/CNativeCode/wgltool.h
index cb64425..b44e366 100755
--- a/CNativeCode/wgltool.h
+++ b/CNativeCode/wgltool.h
@@ -13,13 +13,13 @@
#define _WGLTOOL_H
- #include "gltool.h"
+ #include "gltool.h"
- #include "glcaps.h"
+ #include "glcaps.h"
- #include <windows.h>
+ #include <windows.h>
#include <wingdi.h>
-
+
#include "wgl-disp-var.h"
/**
@@ -28,43 +28,43 @@
*/
LIBAPI void LIBAPIENTRY fetch_WGL_FUNCS
(const char * libGLName,
- const char * libGLUName, int force);
-
-
- LIBAPI void LIBAPIENTRY setPixelFormatByGLCapabilities(
- PIXELFORMATDESCRIPTOR *pfd,
- GLCapabilities *glCaps,
- int offScreenRenderer,
- HDC hdc);
-
- // Set Pixel Format function - forward declaration
- LIBAPI void LIBAPIENTRY SetDCPixelFormat(HDC hDC, GLCapabilities *glCaps,
- int offScreenRenderer, int verbose);
-
- LIBAPI HPALETTE LIBAPIENTRY GetOpenGLPalette(HDC hDC);
-
- LIBAPI HGLRC LIBAPIENTRY get_GC( HDC *hDC, GLCapabilities *glCaps,
- HGLRC shareWith, int offScreenRenderer,
- int width, int height, HBITMAP *pix,
- int verbose);
-
- LIBAPI int LIBAPIENTRY PixelFormatDescriptorFromDc( HDC Dc,
- PIXELFORMATDESCRIPTOR *Pfd );
-
- const char * LIBAPIENTRY GetTextualPixelFormatByHDC(HDC hdc);
-
- const char * LIBAPIENTRY GetTextualPixelFormatByPFD(
- PIXELFORMATDESCRIPTOR *ppfd, int format);
-
- LIBAPI void LIBAPIENTRY setupDIB(HDC hDCOrig, HDC hDC, HBITMAP * hBitmap,
- int width, int height);
-
- LIBAPI void LIBAPIENTRY resizeDIB(HDC hDC, HBITMAP *hOldBitmap,
- HBITMAP *hBitmap);
-
- LIBAPI HPALETTE LIBAPIENTRY setupPalette(HDC hDC);
-
- LIBAPI int LIBAPIENTRY setGLCapabilities ( HDC hdc, int nPixelFormat,
- GLCapabilities *glCaps );
+ const char * libGLUName, int force, int reload);
+
+
+ LIBAPI void LIBAPIENTRY setPixelFormatByGLCapabilities(
+ PIXELFORMATDESCRIPTOR *pfd,
+ GLCapabilities *glCaps,
+ int offScreenRenderer,
+ HDC hdc);
+
+ // Set Pixel Format function - forward declaration
+ LIBAPI void LIBAPIENTRY SetDCPixelFormat(HDC hDC, GLCapabilities *glCaps,
+ int offScreenRenderer, int verbose);
+
+ LIBAPI HPALETTE LIBAPIENTRY GetOpenGLPalette(HDC hDC);
+
+ LIBAPI HGLRC LIBAPIENTRY get_GC( HDC *hDC, GLCapabilities *glCaps,
+ HGLRC shareWith, int offScreenRenderer,
+ int width, int height, HBITMAP *pix,
+ int verbose);
+
+ LIBAPI int LIBAPIENTRY PixelFormatDescriptorFromDc( HDC Dc,
+ PIXELFORMATDESCRIPTOR *Pfd );
+
+ const char * LIBAPIENTRY GetTextualPixelFormatByHDC(HDC hdc);
+
+ const char * LIBAPIENTRY GetTextualPixelFormatByPFD(
+ PIXELFORMATDESCRIPTOR *ppfd, int format);
+
+ LIBAPI void LIBAPIENTRY setupDIB(HDC hDCOrig, HDC hDC, HBITMAP * hBitmap,
+ int width, int height);
+
+ LIBAPI void LIBAPIENTRY resizeDIB(HDC hDC, HBITMAP *hOldBitmap,
+ HBITMAP *hBitmap);
+
+ LIBAPI HPALETTE LIBAPIENTRY setupPalette(HDC hDC);
+
+ LIBAPI int LIBAPIENTRY setGLCapabilities ( HDC hdc, int nPixelFormat,
+ GLCapabilities *glCaps );
#endif
diff --git a/Win32VC6/GL4JavaJauGljJNI14/GL4JavaJauGljJNI14.dsp b/Win32VC6/GL4JavaJauGljJNI14/GL4JavaJauGljJNI14.dsp
index 5886a42..ff1df40 100755
--- a/Win32VC6/GL4JavaJauGljJNI14/GL4JavaJauGljJNI14.dsp
+++ b/Win32VC6/GL4JavaJauGljJNI14/GL4JavaJauGljJNI14.dsp
@@ -1,130 +1,134 @@
-# Microsoft Developer Studio Project File - Name="GL4JavaJauGljJNI14" - Package Owner=<4>
-# Microsoft Developer Studio Generated Build File, Format Version 6.00
-# ** NICHT BEARBEITEN **
-
-# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
-
-CFG=GL4JavaJauGljJNI14 - Win32 Release
-!MESSAGE Dies ist kein g�ltiges Makefile. Zum Erstellen dieses Projekts mit NMAKE
-!MESSAGE verwenden Sie den Befehl "Makefile exportieren" und f�hren Sie den Befehl
-!MESSAGE
-!MESSAGE NMAKE /f "GL4JavaJauGljJNI14.mak".
-!MESSAGE
-!MESSAGE Sie k�nnen beim Ausf�hren von NMAKE eine Konfiguration angeben
-!MESSAGE durch Definieren des Makros CFG in der Befehlszeile. Zum Beispiel:
-!MESSAGE
-!MESSAGE NMAKE /f "GL4JavaJauGljJNI14.mak" CFG="GL4JavaJauGljJNI14 - Win32 Release"
-!MESSAGE
-!MESSAGE F�r die Konfiguration stehen zur Auswahl:
-!MESSAGE
-!MESSAGE "GL4JavaJauGljJNI14 - Win32 Release" (basierend auf "Win32 (x86) Dynamic-Link Library")
-!MESSAGE
-
-# Begin Project
-# PROP AllowPerConfigDependencies 0
-# PROP Scc_ProjName ""
-# PROP Scc_LocalPath ""
-CPP=cl.exe
-MTL=midl.exe
-RSC=rc.exe
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "Release"
-# PROP BASE Intermediate_Dir "Release"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "../libs"
-# PROP Intermediate_Dir "../temp"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
-# ADD CPP /nologo /MT /W3 /GX /O2 /I "d:\jdk1.4\include" /I "d:\jdk1.4\include\win32" /I "..\..\CCLassHeaders" /I "..\..\CNativeCode" /D "NO_VSNPRINTF" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_WIN32_" /D "_MSVC_" /D "_MT" /D "_GL_DYNAMIC_BINDING_" /FD /c
-# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32
-# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32
-# ADD BASE RSC /l 0x407 /d "NDEBUG"
-# ADD RSC /l 0x407 /d "NDEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /machine:I386
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib jawt.lib /nologo /subsystem:windows /dll /machine:I386 /libpath:"d:\java2\lib"
-# SUBTRACT LINK32 /pdb:none /debug
-# Begin Target
-
-# Name "GL4JavaJauGljJNI14 - Win32 Release"
-# Begin Source File
-
-SOURCE=..\..\CNativeCode\GLCallbackHelperJNI.c
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\CNativeCode\glcaps.c
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\CNativeCode\GLDrawableFactory_Win32_SunJDK13.c
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\CNativeCode\glf.c
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\CNativeCode\GLF_JNI12_funcs.c
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\CNativeCode\gltool.c
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\CNativeCode\GLUCallbackJNI.c
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\CNativeCode\jawt_misc.c
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\CNativeCode\jni12tools.c
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\CNativeCode\OpenGL_JauJNI12_funcs.c
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\CNativeCode\OpenGL_JauJNI14_funcs.c
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\CNativeCode\OpenGL_misc.c
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\CNativeCode\OpenGL_Win32_common.c
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\CNativeCode\OpenGL_Win32_jawt.c
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\CNativeCode\OpenGLU_JauJNI12_funcs.c
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\CNativeCode\OpenGLU_JauJNI14_funcs.c
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\CNativeCode\Tool_JNI12_funcs.c
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\CNativeCode\wgltool.c
-# End Source File
-# End Target
-# End Project
+# Microsoft Developer Studio Project File - Name="GL4JavaJauGljJNI14" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
+
+CFG=GL4JavaJauGljJNI14 - Win32 Release
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "GL4JavaJauGljJNI14.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "GL4JavaJauGljJNI14.mak" CFG="GL4JavaJauGljJNI14 - Win32 Release"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "GL4JavaJauGljJNI14 - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+MTL=midl.exe
+RSC=rc.exe
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "../libs"
+# PROP Intermediate_Dir "../temp"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
+# ADD CPP /nologo /MT /W3 /GX /O2 /I "d:\jdk1.4\include" /I "d:\jdk1.4\include\win32" /I "..\..\CCLassHeaders" /I "..\..\CNativeCode" /D "NO_VSNPRINTF" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_WIN32_" /D "_MSVC_" /D "_MT" /D "_GL_DYNAMIC_BINDING_" /FD /c
+# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32
+# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win32
+# ADD BASE RSC /l 0x407 /d "NDEBUG"
+# ADD RSC /l 0x407 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib jawt.lib /nologo /subsystem:windows /dll /machine:I386 /libpath:"d:\jdk1.4\lib"
+# SUBTRACT LINK32 /pdb:none /debug
+# Begin Target
+
+# Name "GL4JavaJauGljJNI14 - Win32 Release"
+# Begin Source File
+
+SOURCE=..\..\CNativeCode\gl4java_utils_DirectBufferCleanup.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\CNativeCode\GLCallbackHelperJNI.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\CNativeCode\glcaps.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\CNativeCode\GLDrawableFactory_Win32_SunJDK13.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\CNativeCode\glf.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\CNativeCode\GLF_JNI12_funcs.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\CNativeCode\gltool.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\CNativeCode\GLUCallbackJNI.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\CNativeCode\jawt_misc.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\CNativeCode\jni12tools.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\CNativeCode\OpenGL_JauJNI12_funcs.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\CNativeCode\OpenGL_JauJNI14_funcs.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\CNativeCode\OpenGL_misc.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\CNativeCode\OpenGL_Win32_common.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\CNativeCode\OpenGL_Win32_jawt.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\CNativeCode\OpenGLU_JauJNI12_funcs.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\CNativeCode\OpenGLU_JauJNI14_funcs.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\CNativeCode\Tool_JNI12_funcs.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\CNativeCode\wgltool.c
+# End Source File
+# End Target
+# End Project
diff --git a/gl4java/GLContext.java.skel b/gl4java/GLContext.java.skel
index 0bf5461..50aa7c3 100644
--- a/gl4java/GLContext.java.skel
+++ b/gl4java/GLContext.java.skel
@@ -2449,6 +2449,14 @@ public class GLContext extends Object
notifyAll(); // notify gljFree after action is done ..
+ // Workaround for problem on Windows where extensions do not
+ // become visible until the first time an OpenGL context is
+ // made current (at least with NVidia's drivers).
+ if (firstContextMakeCurrent) {
+ firstContextMakeCurrent = false;
+ gljFetchGLFunctions0(null, null, false, true);
+ }
+
return result;
}
@@ -2730,15 +2738,43 @@ public class GLContext extends Object
*/
public final static native boolean gljFetchOSGLFunctions
( String gllibname, String glulibname, boolean force );
- public final static native boolean gljFetchGLFunctions
- ( String gllibname, String glulibname, boolean force );
+ public final static boolean gljFetchGLFunctions(String gllibname,
+ String glulibname,
+ boolean force) {
+ return gljFetchGLFunctions0(gllibname, glulibname, force, false);
+ }
+
+ // This routine is used internally only. On Windows it appears
+ // that extensions only become visible once an OpenGL context is
+ // made current for the first time (at least with NVidia's
+ // drivers). To avoid making drastic changes to the code
+ // structure, we reload all of the OpenGL functions the first time
+ // a context is made current. (This could be made more efficient
+ // by only loading extensions' routines at this time.)
+ private volatile static boolean firstContextMakeCurrent = true;
+ private final static native boolean gljFetchGLFunctions0(String gllibname,
+ String glulibname,
+ boolean force,
+ boolean reload);
/**
* This functions checks the existence of
* the GL functions !
*/
- public final static native boolean gljTestGLProc
- ( String name, boolean verbose );
+ public final static boolean gljTestGLProc ( String name, boolean verbose ) {
+ // Special case any routines which are exposed in a different fashion
+ if (name.equals("glAllocateMemoryNV")) {
+ int os = getNativeOSType();
+ if (os == OsWindoof) {
+ name = "wglAllocateMemoryNV";
+ } else if (os == OsX11) {
+ name = "glXAllocateMemoryNV";
+ } // else will fail anyway; fall through
+ }
+ return gljTestGLProc0(name, verbose);
+ }
+
+ private static final native boolean gljTestGLProc0(String name, boolean verbose);
/**
* This functions reads the pixel from the GL frame
diff --git a/gl4java/GLFunc14.java b/gl4java/GLFunc14.java
index 59555ba..0cf527d 100644
--- a/gl4java/GLFunc14.java
+++ b/gl4java/GLFunc14.java
@@ -4,35 +4,52 @@
*/
-/**
- * @(#) GLFunc14.java
- */
-
-
-package gl4java;
-
-import java.nio.*;
-
-/**
- * The base interface for OpenGL native function mapping
- *
- * @version 2.00, 21. April 1999
- * @author Sven Goethel
- */
-public interface GLFunc14
- extends GLFunc
-{
-
-
-public String glGetString ( int name ) ;
-
-public String getNativeVendor ( ) ;
-public String getNativeVersion ( ) ;
-
-public String getClassVendor ( ) ;
-public String getClassVersion ( ) ;
-
-public static final String[] GL_PROC_NAMES = {
+/**
+ * @(#) GLFunc14.java
+ */
+
+
+package gl4java;
+
+import java.nio.*;
+
+/**
+ * The base interface for OpenGL native function mapping
+ *
+ * @version 2.00, 21. April 1999
+ * @author Sven Goethel
+ */
+public interface GLFunc14
+ extends GLFunc
+{
+
+ //----------------------------------------------------------------------
+ // Special-case routines requiring hand coding
+ //
+
+ /** Access to the underlying wglAllocateMemoryNV or
+ glXAllocateMemoryNV routine, if present. Presence of this
+ routine can be queried by calling GLContext.gljTestGLProc with
+ the argument "glAllocateMemoryNV". */
+ public ByteBuffer glAllocateMemoryNV(int size,
+ float readFreq,
+ float writeFreq,
+ float priority);
+
+ //----------------------------------------------------------------------
+ // All other routines below are autogenerated
+ //
+
+
+public String glGetString ( int name ) ;
+
+public String getNativeVendor ( ) ;
+public String getNativeVersion ( ) ;
+
+public String getClassVendor ( ) ;
+public String getClassVersion ( ) ;
+
+public static final String[] GL_PROC_NAMES = {
/**
* C2J Parser Version 3.0
* Jausoft - Sven Goethel Software Development
diff --git a/gl4java/GLFunc14JauJNI.java b/gl4java/GLFunc14JauJNI.java
index 12a0e12..62b48ac 100644
--- a/gl4java/GLFunc14JauJNI.java
+++ b/gl4java/GLFunc14JauJNI.java
@@ -4,26 +4,76 @@
*/
-/**
- * @(#) GLFunc14JauJNI.java
- */
-
-
-package gl4java;
-
-import java.nio.*;
-
-/**
- * The default implementation class for OpenGL native function mapping
- *
- * @version 2.00, 21. April 1999
- * @author Sven Goethel
- */
-public class GLFunc14JauJNI
- implements GLFunc14
-{
-
-
+/**
+ * @(#) GLFunc14JauJNI.java
+ */
+
+
+package gl4java;
+
+import java.nio.*;
+import gl4java.utils.DirectBufferCleanup;
+
+/**
+ * The default implementation class for OpenGL native function mapping
+ *
+ * @version 2.00, 21. April 1999
+ * @author Sven Goethel
+ */
+public class GLFunc14JauJNI
+ implements GLFunc14
+{
+
+ //----------------------------------------------------------------------
+ // Special-case routines requiring hand coding
+ //
+
+ /** Access to the underlying wglAllocateMemoryNV or
+ glXAllocateMemoryNV routine, if present. Presence of this
+ routine can be queried by calling GLContext.gljTestGLProc with
+ the argument "glAllocateMemoryNV". */
+ public ByteBuffer glAllocateMemoryNV(int size,
+ float readFreq,
+ float writeFreq,
+ float priority) {
+ long address = glAllocateMemoryNV0(size, readFreq, writeFreq, priority);
+ if (address == 0) {
+ throw new OutOfMemoryError();
+ }
+ ByteBuffer buf = newDirectByteBuffer(address, size);
+ registerForCleanup(this, buf);
+ return buf;
+ }
+
+ /** This delegates to either wglAllocateMemoryNV or
+ glXAllocateMemoryNV in the native code, depending on the window
+ system */
+ private native long glAllocateMemoryNV0(int size, float readFreq, float writeFreq, float priority);
+
+ /** This delegates to either wglFreeMemoryNV or glXFreeMemoryNV in
+ the native code, depending on the window system */
+ private native void glFreeMemoryNV0(long addr);
+
+ /** Allocate a direct byte buffer pointing at an arbitrary memory
+ address -- must be hidden for security reasons */
+ private native ByteBuffer newDirectByteBuffer(long addr, int capacity);
+
+ private static volatile DirectBufferCleanup cleanup;
+ private static synchronized void registerForCleanup(final GLFunc14JauJNI gl, Buffer buf) {
+ if (cleanup == null) {
+ cleanup = new DirectBufferCleanup(new DirectBufferCleanup.Callback() {
+ public void cleanup(long addr) {
+ gl.glFreeMemoryNV0(addr);
+ }
+ });
+ }
+ cleanup.register(buf);
+ }
+
+ //----------------------------------------------------------------------
+ // All other routines below are autogenerated
+ //
+
public final native String glGetString ( int name ) ;
diff --git a/gl4java/utils/DirectBufferCleanup.java b/gl4java/utils/DirectBufferCleanup.java
new file mode 100644
index 0000000..378cd76
--- /dev/null
+++ b/gl4java/utils/DirectBufferCleanup.java
@@ -0,0 +1,110 @@
+package gl4java.utils;
+
+import java.lang.ref.PhantomReference;
+import java.lang.ref.Reference;
+import java.lang.ref.ReferenceQueue;
+import java.nio.*;
+import java.util.HashMap;
+import java.util.Map;
+
+/** Provides a cleanup mechanism for direct buffers instantiated via
+ the JNI entry point <code>NewDirectByteBuffer</code>. A direct
+ buffer can be <i>registered</i> with a DirectBufferCleanup. When
+ that buffer is reclaimed by the garbage collector, the callback
+ associated with that DirectBufferCleanup is called on the address
+ the direct buffer was associated with. */
+
+public class DirectBufferCleanup {
+
+ // Put DirectBufferCleanup.c into its own library if extracting just
+ // this mechanism
+ // static {
+ // System.loadLibrary("DirectBufferCleanup");
+ // }
+
+ public static interface Callback {
+ public void cleanup(long addr);
+ }
+
+ public DirectBufferCleanup(Callback cb) {
+ this.cb = cb;
+ refToAddrMap = new HashMap();
+ queue = new ReferenceQueue();
+ start();
+ }
+
+ /** The DirectBufferCleanup contains an internal thread which is
+ started automatically upon construction. This method starts the
+ thread again if it is manually stopped via the {@link #stop}
+ method. */
+ public synchronized void start() {
+ if (t == null) {
+ t = new Thread(new Runnable() {
+ public void run() {
+ while (!done) {
+ try {
+ Reference r = queue.remove();
+ Long addr = (Long) refToAddrMap.remove(r);
+ cb.cleanup(addr.longValue());
+ r.clear();
+ } catch (InterruptedException e) {
+ }
+ }
+ t = null;
+ }
+ });
+ done = false;
+ t.start();
+ }
+ }
+
+ /** Stops the internal thread of this DirectBufferCleanup. Should
+ not typically be necessary. */
+ public synchronized void stop() {
+ done = true;
+ while (t != null) {
+ try {
+ wait();
+ } catch (InterruptedException e) {
+ }
+ }
+ }
+
+ /** Registers the given buffer (which must be a direct buffer) for
+ later cleanup when it is reclaimed by the garbage collector.
+
+ @throw IllegalArgumentException if the passed buffer is not
+ direct.
+ */
+
+ public void register(Buffer buf) throws IllegalArgumentException {
+ try {
+ long addr = getDirectBufferAddress(buf);
+ if (addr == 0) throw new IllegalArgumentException();
+ refToAddrMap.put(new PhantomReference(buf, queue),
+ new Long(addr));
+ } catch (ClassCastException e) {
+ throw new IllegalArgumentException();
+ }
+ }
+
+ //----------------------------------------------------------------------
+ // Internals only below this point
+ //
+
+ private Callback cb;
+
+ // Maps PhantomReferences to addresses
+ private Map refToAddrMap;
+
+ // Reference queue which gets notified
+ private ReferenceQueue queue;
+
+ // Thread watching reference queue
+ private volatile Thread t;
+
+ // Native method providing direct buffer address via JNI
+ private static native long getDirectBufferAddress(Buffer buf);
+
+ private volatile boolean done = false;
+}
diff --git a/makefile b/makefile
index 849f63a..9e2b4e2 100644
--- a/makefile
+++ b/makefile
@@ -198,7 +198,8 @@ FILES_WITH_NATIVES_13 = \
ifdef JAVAC_14
FILES_WITH_NATIVES_14 = \
$(PACKAGEDIR)/GLFunc14JauJNI.java \
- $(PACKAGEDIR)/GLUFunc14JauJNI.java
+ $(PACKAGEDIR)/GLUFunc14JauJNI.java \
+ $(PACKAGEDIR)/utils/DirectBufferCleanup.java
else
FILES_WITH_NATIVES_14 =
endif
@@ -415,6 +416,7 @@ FILES4.c = $(CNATIVEDIR)/OpenGL_X11_jawt.c \
$(CNATIVEDIR)/OpenGLU_JauJNI12_funcs.c \
$(CNATIVEDIR)/OpenGL_JauJNI14_funcs.c \
$(CNATIVEDIR)/OpenGLU_JauJNI14_funcs.c \
+ $(CNATIVEDIR)/gl4java_utils_DirectBufferCleanup.c \
$(CNATIVEDIR)/glf.c \
$(CNATIVEDIR)/GLF_JNI12_funcs.c \
$(CNATIVEDIR)/GLUCallbackJNI.c