From f610ac01f50165b2ea6bc4a81d02abf2e222d876 Mon Sep 17 00:00:00 2001 From: Kenneth Russel Date: Sun, 11 Nov 2001 21:30:13 +0000 Subject: Support for NVidia AllocateMemoryNV extension and fixed problem with extensions not being loaded --- C2J/manual/gl-manualCodedImplJNI1-14.java | 90 ++++++++++++++++++++++++------- 1 file changed, 70 insertions(+), 20 deletions(-) (limited to 'C2J/manual/gl-manualCodedImplJNI1-14.java') 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 + // + -- cgit v1.2.3