diff options
author | Sven Gothel <[email protected]> | 2010-03-30 03:39:16 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2010-03-30 03:39:16 +0200 |
commit | 84e5ba7a4821469f43c0f4bbeaa8e383b203d050 (patch) | |
tree | 012162d83b2fecf503a89c973609a73b2c1a4a83 /src/java/com/jogamp/gluegen/runtime | |
parent | dadccfbd5641e08c4201ef58145f40d71b0ea76d (diff) |
http://www.jogamp.org/bugzilla/show_bug.cgi?id=392
32bit/64bit values and arrays are misrepresented
- PointerBuffer: Adding methods
PointeRBuffer referenceBuffer(int index, Buffer data)
PointeRBuffer referenceBuffer(Buffer data)
Buffer getReferencedBuffer(int index)
Buffer getReferencedBuffer()
Adding a reference of a given direct Buffer
to this pointer buffer, and retrieving a
previously referenced direct Buffer.
This allows a more convenient handling of PointerBuffer
with the user API's ..
Diffstat (limited to 'src/java/com/jogamp/gluegen/runtime')
-rw-r--r-- | src/java/com/jogamp/gluegen/runtime/PointerBuffer.java | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/java/com/jogamp/gluegen/runtime/PointerBuffer.java b/src/java/com/jogamp/gluegen/runtime/PointerBuffer.java index 0adbb36..3ee7b54 100644 --- a/src/java/com/jogamp/gluegen/runtime/PointerBuffer.java +++ b/src/java/com/jogamp/gluegen/runtime/PointerBuffer.java @@ -31,6 +31,8 @@ package com.jogamp.gluegen.runtime; import java.nio.ByteBuffer; +import java.nio.Buffer; +import java.util.HashMap; /** * Hardware independent container for native pointer arrays. @@ -48,6 +50,12 @@ public abstract class PointerBuffer { protected int position; protected long[] backup; + protected HashMap/*<aptr, buffer>*/ dataMap = new HashMap(); + + static { + NativeLibrary.ensureNativeLibLoaded(); + } + protected PointerBuffer(ByteBuffer bb) { this.bb = bb; } @@ -152,10 +160,54 @@ public abstract class PointerBuffer { public abstract long get(int idx); + /** put the pointer value at position index */ public abstract PointerBuffer put(int index, long value); + /** put the pointer value at the end */ public abstract PointerBuffer put(long value); + /** Put the address of the given direct Buffer at the given position + of this pointer array. + Adding a reference of the given direct Buffer to this object. */ + public PointerBuffer referenceBuffer(int index, Buffer bb) { + if(null==bb) { + throw new RuntimeException("Buffer is null"); + } + if(!bb.isDirect()) { + throw new RuntimeException("Buffer is not direct"); + } + long bbAddr = getDirectBufferAddressImpl(bb); + if(0==bbAddr) { + throw new RuntimeException("Couldn't determine native address of given Buffer: "+bb); + } + + put(index, bbAddr); + dataMap.put(new Long(bbAddr), bb); + return this; + } + + /** Put the address of the given direct Buffer at the end + of this pointer array. + Adding a reference of the given direct Buffer to this object. */ + public PointerBuffer referenceBuffer(Buffer bb) { + referenceBuffer(position, bb); + position++; + return this; + } + + public Buffer getReferencedBuffer(int index) { + long addr = get(index); + return (Buffer) dataMap.get(new Long(addr)); + } + + public Buffer getReferencedBuffer() { + Buffer bb = getReferencedBuffer(position); + position++; + return bb; + } + + private native long getDirectBufferAddressImpl(Object directBuffer); + public PointerBuffer put(PointerBuffer src) { if (remaining() < src.remaining()) { throw new IndexOutOfBoundsException(); |