diff options
Diffstat (limited to 'src')
24 files changed, 414 insertions, 341 deletions
diff --git a/src/java/com/jogamp/gluegen/runtime/AbstractBuffer.java b/src/java/com/jogamp/gluegen/runtime/AbstractBuffer.java new file mode 100644 index 0000000..34e39ba --- /dev/null +++ b/src/java/com/jogamp/gluegen/runtime/AbstractBuffer.java @@ -0,0 +1,112 @@ +/* + * Copyright (c) 2010, Sven Gothel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of Sven Gothel nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL Sven Gothel BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Created on Saturday, March 27 2010 11:55 + */ +package com.jogamp.gluegen.runtime; + +import java.nio.ByteBuffer; +import java.nio.Buffer; +import java.util.HashMap; + +/** + * @author Michael Bien + * @author Sven Gothel + */ +public abstract class AbstractBuffer { + + protected final ByteBuffer bb; + protected int capacity; + protected int position; + + static { + NativeLibrary.ensureNativeLibLoaded(); + } + + protected AbstractBuffer(ByteBuffer bb, int elementSize) { + this.bb = bb; + + capacity = bb.capacity() / elementSize; + position = 0; + } + + public final int limit() { + return capacity; + } + + public final int capacity() { + return capacity; + } + + public final int position() { + return position; + } + + public final AbstractBuffer position(int newPos) { + if (0 > newPos || newPos >= capacity) { + throw new IndexOutOfBoundsException("Sorry to interrupt, but the position "+newPos+" was out of bounds. " + + "My capacity is "+capacity()+"."); + } + position = newPos; + return this; + } + + public final int remaining() { + return capacity - position; + } + + public final boolean hasRemaining() { + return position < capacity; + } + + public final AbstractBuffer rewind() { + position = 0; + return this; + } + + public boolean hasArray() { + return false; + } + + public int arrayOffset() { + return 0; + } + + public final ByteBuffer getBuffer() { + return bb; + } + + public final boolean isDirect() { + return bb.isDirect(); + } + + public String toString() { + return "AbstractBuffer[capacity "+capacity+", position "+position+", elementSize "+(bb.capacity()/capacity)+", ByteBuffer.capacity "+bb.capacity()+"]"; + } + +} diff --git a/src/java/com/jogamp/gluegen/runtime/AbstractLongBuffer.java b/src/java/com/jogamp/gluegen/runtime/AbstractLongBuffer.java new file mode 100644 index 0000000..63c2b5f --- /dev/null +++ b/src/java/com/jogamp/gluegen/runtime/AbstractLongBuffer.java @@ -0,0 +1,143 @@ +/* + * Copyright (c) 2010, Michael Bien + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of Michael Bien nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL Michael Bien BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Created on Saturday, March 27 2010 11:55 + */ +package com.jogamp.gluegen.runtime; + +import java.nio.ByteBuffer; +import java.nio.Buffer; +import java.util.HashMap; + +/** + * Hardware independent container for native pointer arrays. + * + * The native values (NIO direct ByteBuffer) might be 32bit or 64bit wide, + * depending of the CPU pointer width. + * + * @author Michael Bien + * @author Sven Gothel + */ +public abstract class AbstractLongBuffer extends AbstractBuffer { + + protected long[] backup; + + protected HashMap/*<aptr, buffer>*/ dataMap = new HashMap(); + + static { + NativeLibrary.ensureNativeLibLoaded(); + } + + protected AbstractLongBuffer(ByteBuffer bb, int elementSize) { + super(bb, elementSize); + + backup = new long[capacity]; + } + + final void updateBackup() { + for (int i = 0; i < capacity; i++) { + backup[i] = get(i); + } + } + + public final boolean hasArray() { + return true; + } + + public final long[] array() { + return backup; + } + + /** Absolute get method. Get the pointer value at the given index */ + public abstract long get(int idx); + + /** Relative get method. Get the pointer value at the current position and increment the position by one. */ + public final long get() { + long r = get(position); + position++; + return r; + } + + /** + * Relative bulk get method. Copy the pointer values <code> [ position .. position+length [</code> + * to the destination array <code> [ dest[offset] .. dest[offset+length] [ </code> + * and increment the position by <code>length</code>. */ + public final AbstractLongBuffer get(long[] dest, int offset, int length) { + if (dest.length<offset+length) { + throw new IndexOutOfBoundsException(); + } + if (remaining() < length) { + throw new IndexOutOfBoundsException(); + } + while(length>0) { + dest[offset++] = get(position++); + length--; + } + return this; + } + + /** Absolute put method. Put the pointer value at the given index */ + public abstract AbstractLongBuffer put(int index, long value); + + /** Relative put method. Put the pointer value at the current position and increment the position by one. */ + public final AbstractLongBuffer put(long value) { + put(position, value); + position++; + return this; + } + + /** + * Relative bulk put method. Put the pointer values <code> [ src[offset] .. src[offset+length] [</code> + * at the current position and increment the position by <code>length</code>. */ + public final AbstractLongBuffer put(long[] src, int offset, int length) { + if (src.length<offset+length) { + throw new IndexOutOfBoundsException(); + } + if (remaining() < length) { + throw new IndexOutOfBoundsException(); + } + while(length>0) { + put(position++, src[offset++]); + length--; + } + return this; + } + + /** + * Relative bulk get method. Copy the source values <code> src[position .. capacity] [</code> + * to this buffer and increment the position by <code>capacity-position</code>. */ + public AbstractLongBuffer put(AbstractLongBuffer src) { + if (remaining() < src.remaining()) { + throw new IndexOutOfBoundsException(); + } + while (src.hasRemaining()) { + put(src.get()); + } + return this; + } +} diff --git a/src/java/com/jogamp/gluegen/runtime/Int64Buffer.java b/src/java/com/jogamp/gluegen/runtime/Int64Buffer.java index 98d0834..4535bdb 100644 --- a/src/java/com/jogamp/gluegen/runtime/Int64Buffer.java +++ b/src/java/com/jogamp/gluegen/runtime/Int64Buffer.java @@ -37,15 +37,10 @@ import java.nio.ByteBuffer; * @author Michael Bien * @author Sven Gothel */ -public abstract class Int64Buffer { - - protected final ByteBuffer bb; - protected int capacity; - protected int position; - protected long[] backup; +public abstract class Int64Buffer extends AbstractLongBuffer { protected Int64Buffer(ByteBuffer bb) { - this.bb = bb; + super(bb, elementSize()); } public static Int64Buffer allocate(int size) { @@ -76,94 +71,12 @@ public abstract class Int64Buffer { } - void updateBackup() { - for (int i = 0; i < capacity; i++) { - backup[i] = get(i); - } - } - - int arrayOffset() { - return 0; - } - public static int elementSize() { return Buffers.SIZEOF_LONG; } - public int limit() { - return capacity; - } - - public int capacity() { - return capacity; - } - - public int position() { - return position; - } - - public Int64Buffer position(int newPos) { - if (0 > newPos || newPos >= capacity) { - throw new IndexOutOfBoundsException("Sorry to interrupt, but the position "+newPos+" was out of bounds. " + - "My capacity is "+capacity()+"."); - } - position = newPos; - return this; - } - - public int remaining() { - return capacity - position; - } - - public boolean hasRemaining() { - return position < capacity; - } - - public Int64Buffer rewind() { - position = 0; - return this; - } - - boolean hasArray() { - return true; - } - - public long[] array() { - return backup; - } - - public ByteBuffer getBuffer() { - return bb; - } - - public boolean isDirect() { - return bb.isDirect(); - } - - public long get() { - long r = get(position); - position++; - return r; - } - - public abstract long get(int idx); - - public abstract Int64Buffer put(int index, long value); - - public abstract Int64Buffer put(long value); - - public Int64Buffer put(Int64Buffer src) { - if (remaining() < src.remaining()) { - throw new IndexOutOfBoundsException(); - } - while (src.hasRemaining()) { - put(src.get()); - } - return this; - } - public String toString() { - return "Int64Buffer[capacity "+capacity+", position "+position+", elementSize "+elementSize()+", ByteBuffer.capacity "+bb.capacity()+"]"; + return "Int64Buffer:"+super.toString(); } } diff --git a/src/java/com/jogamp/gluegen/runtime/Int64BufferME_CDC_FP.java b/src/java/com/jogamp/gluegen/runtime/Int64BufferME_CDC_FP.java index cedb737..93863cf 100755 --- a/src/java/com/jogamp/gluegen/runtime/Int64BufferME_CDC_FP.java +++ b/src/java/com/jogamp/gluegen/runtime/Int64BufferME_CDC_FP.java @@ -55,7 +55,7 @@ final class Int64BufferME_CDC_FP extends Int64Buffer { backup = new long[capacity]; } - public long get(int idx) { + public final long get(int idx) { if (0 > idx || idx >= capacity) { throw new IndexOutOfBoundsException(); } @@ -68,7 +68,7 @@ final class Int64BufferME_CDC_FP extends Int64Buffer { return lo << 32 | hi; } - public Int64Buffer put(int idx, long v) { + public final AbstractLongBuffer put(int idx, long v) { if (0 > idx || idx >= capacity) { throw new IndexOutOfBoundsException(); } @@ -85,10 +85,4 @@ final class Int64BufferME_CDC_FP extends Int64Buffer { } return this; } - - public Int64Buffer put(long v) { - put(position, v); - position++; - return this; - } } diff --git a/src/java/com/jogamp/gluegen/runtime/Int64BufferSE.java b/src/java/com/jogamp/gluegen/runtime/Int64BufferSE.java index 166d0c6..a874133 100755 --- a/src/java/com/jogamp/gluegen/runtime/Int64BufferSE.java +++ b/src/java/com/jogamp/gluegen/runtime/Int64BufferSE.java @@ -49,21 +49,16 @@ final class Int64BufferSE extends Int64Buffer { super(bb); this.pb = bb.asLongBuffer(); - - capacity = bb.capacity() / elementSize(); - - position = 0; - backup = new long[capacity]; } - public long get(int idx) { + public final long get(int idx) { if (0 > idx || idx >= capacity) { throw new IndexOutOfBoundsException(); } return pb.get(idx); } - public Int64Buffer put(int idx, long v) { + public final AbstractLongBuffer put(int idx, long v) { if (0 > idx || idx >= capacity) { throw new IndexOutOfBoundsException(); } @@ -71,10 +66,4 @@ final class Int64BufferSE extends Int64Buffer { pb.put(idx, v); return this; } - - public Int64Buffer put(long v) { - put(position, v); - position++; - return this; - } } diff --git a/src/java/com/jogamp/gluegen/runtime/PointerBuffer.java b/src/java/com/jogamp/gluegen/runtime/PointerBuffer.java index 3ee7b54..cfc53a8 100644 --- a/src/java/com/jogamp/gluegen/runtime/PointerBuffer.java +++ b/src/java/com/jogamp/gluegen/runtime/PointerBuffer.java @@ -43,12 +43,7 @@ import java.util.HashMap; * @author Michael Bien * @author Sven Gothel */ -public abstract class PointerBuffer { - - protected final ByteBuffer bb; - protected int capacity; - protected int position; - protected long[] backup; +public abstract class PointerBuffer extends AbstractLongBuffer { protected HashMap/*<aptr, buffer>*/ dataMap = new HashMap(); @@ -57,7 +52,7 @@ public abstract class PointerBuffer { } protected PointerBuffer(ByteBuffer bb) { - this.bb = bb; + super(bb, elementSize()); } public static PointerBuffer allocate(int size) { @@ -88,88 +83,33 @@ public abstract class PointerBuffer { } - void updateBackup() { - for (int i = 0; i < capacity; i++) { - backup[i] = get(i); - } - } - - int arrayOffset() { - return 0; - } - public static int elementSize() { return Platform.is32Bit() ? Buffers.SIZEOF_INT : Buffers.SIZEOF_LONG; } - public int limit() { - return capacity; - } - - public int capacity() { - return capacity; - } - - public int position() { - return position; - } - - public PointerBuffer position(int newPos) { - if (0 > newPos || newPos >= capacity) { - throw new IndexOutOfBoundsException("Sorry to interrupt, but the position "+newPos+" was out of bounds. " + - "My capacity is "+capacity()+"."); + public final PointerBuffer put(PointerBuffer src) { + if (remaining() < src.remaining()) { + throw new IndexOutOfBoundsException(); + } + long addr; + while (src.hasRemaining()) { + addr = src.get(); + put(addr); + Long addrL = new Long(addr); + Buffer bb = (Buffer) dataMap.get(addrL); + if(null!=bb) { + dataMap.put(addrL, bb); + } else { + dataMap.remove(addrL); + } } - position = newPos; - return this; - } - - public int remaining() { - return capacity - position; - } - - public boolean hasRemaining() { - return position < capacity; - } - - public PointerBuffer rewind() { - position = 0; return this; } - boolean hasArray() { - return true; - } - - public long[] array() { - return backup; - } - - public ByteBuffer getBuffer() { - return bb; - } - - public boolean isDirect() { - return bb.isDirect(); - } - - public long get() { - long r = get(position); - position++; - return r; - } - - 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) { + public final PointerBuffer referenceBuffer(int index, Buffer bb) { if(null==bb) { throw new RuntimeException("Buffer is null"); } @@ -189,18 +129,18 @@ public abstract class PointerBuffer { /** 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) { + public final PointerBuffer referenceBuffer(Buffer bb) { referenceBuffer(position, bb); position++; return this; } - public Buffer getReferencedBuffer(int index) { + public final Buffer getReferencedBuffer(int index) { long addr = get(index); return (Buffer) dataMap.get(new Long(addr)); } - public Buffer getReferencedBuffer() { + public final Buffer getReferencedBuffer() { Buffer bb = getReferencedBuffer(position); position++; return bb; @@ -208,18 +148,8 @@ public abstract class PointerBuffer { private native long getDirectBufferAddressImpl(Object directBuffer); - public PointerBuffer put(PointerBuffer src) { - if (remaining() < src.remaining()) { - throw new IndexOutOfBoundsException(); - } - while (src.hasRemaining()) { - put(src.get()); - } - return this; - } - public String toString() { - return "PointerBuffer[capacity "+capacity+", position "+position+", elementSize "+elementSize()+", ByteBuffer.capacity "+bb.capacity()+"]"; + return "PointerBuffer:"+super.toString(); } } diff --git a/src/java/com/jogamp/gluegen/runtime/PointerBufferME_CDC_FP.java b/src/java/com/jogamp/gluegen/runtime/PointerBufferME_CDC_FP.java index 1134ee7..a660e1f 100755 --- a/src/java/com/jogamp/gluegen/runtime/PointerBufferME_CDC_FP.java +++ b/src/java/com/jogamp/gluegen/runtime/PointerBufferME_CDC_FP.java @@ -48,14 +48,9 @@ final class PointerBufferME_CDC_FP extends PointerBuffer { PointerBufferME_CDC_FP(ByteBuffer bb) { super(bb); this.pb = bb.asIntBuffer(); - - capacity = bb.capacity() / elementSize(); - - position = 0; - backup = new long[capacity]; } - public long get(int idx) { + public final long get(int idx) { if (0 > idx || idx >= capacity) { throw new IndexOutOfBoundsException(); } @@ -72,7 +67,7 @@ final class PointerBufferME_CDC_FP extends PointerBuffer { } } - public PointerBuffer put(int idx, long v) { + public final AbstractLongBuffer put(int idx, long v) { if (0 > idx || idx >= capacity) { throw new IndexOutOfBoundsException(); } @@ -93,10 +88,4 @@ final class PointerBufferME_CDC_FP extends PointerBuffer { } return this; } - - public PointerBuffer put(long v) { - put(position, v); - position++; - return this; - } } diff --git a/src/java/com/jogamp/gluegen/runtime/PointerBufferSE.java b/src/java/com/jogamp/gluegen/runtime/PointerBufferSE.java index 6f131a9..9943ec1 100755 --- a/src/java/com/jogamp/gluegen/runtime/PointerBufferSE.java +++ b/src/java/com/jogamp/gluegen/runtime/PointerBufferSE.java @@ -53,14 +53,9 @@ final class PointerBufferSE extends PointerBuffer { } else { this.pb = bb.asLongBuffer(); } - - capacity = bb.capacity() / elementSize(); - - position = 0; - backup = new long[capacity]; } - public long get(int idx) { + public final long get(int idx) { if (0 > idx || idx >= capacity) { throw new IndexOutOfBoundsException(); } @@ -71,7 +66,7 @@ final class PointerBufferSE extends PointerBuffer { } } - public PointerBuffer put(int idx, long v) { + public final AbstractLongBuffer put(int idx, long v) { if (0 > idx || idx >= capacity) { throw new IndexOutOfBoundsException(); } @@ -84,9 +79,4 @@ final class PointerBufferSE extends PointerBuffer { return this; } - public PointerBuffer put(long v) { - put(position, v); - position++; - return this; - } } diff --git a/src/java/com/sun/gluegen/test/TestPointerBufferEndian.java b/src/java/com/sun/gluegen/test/TestPointerBufferEndian.java deleted file mode 100644 index 96e4e87..0000000 --- a/src/java/com/sun/gluegen/test/TestPointerBufferEndian.java +++ /dev/null @@ -1,41 +0,0 @@ - -package com.sun.gluegen.test; - -import com.jogamp.gluegen.runtime.*; -import java.nio.*; - -public class TestPointerBufferEndian { - public static void main (String[] args) { - boolean direct = args.length>0 && args[0].equals("-direct"); - boolean ok = true; - int bitsPtr = Platform.getPointerSizeInBits(); - String bitsProp = System.getProperty("sun.arch.data.model"); - String os = System.getProperty("os.name"); - String cpu = System.getProperty("os.arch"); - System.out.println("OS: <"+os+"> CPU: <"+cpu+"> Bits: <"+bitsPtr+"/"+bitsProp+">"); - System.out.println("CPU is: "+ (Platform.is32Bit()?"32":"64") + " bit"); - System.out.println("Buffer is in: "+ (Platform.isLittleEndian()?"little":"big") + " endian"); - PointerBuffer ptr = direct ? PointerBuffer.allocateDirect(3) : PointerBuffer.allocate(3); - ptr.put(0, 0x0123456789ABCDEFL); - ptr.put(1, 0x8877665544332211L); - ptr.put(2, 0xAFFEDEADBEEFAFFEL); - long v = ptr.get(0); - if( 0x0123456789ABCDEFL != v ) { - System.out.println("Err[0] shall 0x0123456789ABCDEF, is: "+Long.toHexString(v)); - ok=false; - } - v = ptr.get(1); - if( 0x8877665544332211L != v ) { - System.out.println("Err[1] shall 0x8877665544332211, is: "+Long.toHexString(v)); - ok=false; - } - v = ptr.get(2); - if( 0xAFFEDEADBEEFAFFEL != v ) { - System.out.println("Err[2] shall 0xAFFEDEADBEEFAFFE, is: "+Long.toHexString(v)); - ok=false; - } - if(!ok) { - throw new RuntimeException("Long conversion failure"); - } - } -} diff --git a/src/java/com/sun/gluegen/test/TestStructAccessorEndian.java b/src/java/com/sun/gluegen/test/TestStructAccessorEndian.java deleted file mode 100644 index 7202056..0000000 --- a/src/java/com/sun/gluegen/test/TestStructAccessorEndian.java +++ /dev/null @@ -1,41 +0,0 @@ - -package com.sun.gluegen.test; - -import com.jogamp.gluegen.runtime.*; -import java.nio.*; - -public class TestStructAccessorEndian { - public static void main (String args[]) { - boolean ok = true; - int bitsPtr = Platform.getPointerSizeInBits(); - String bitsProp = System.getProperty("sun.arch.data.model"); - String os = System.getProperty("os.name"); - String cpu = System.getProperty("os.arch"); - System.out.println("OS: <"+os+"> CPU: <"+cpu+"> Bits: <"+bitsPtr+"/"+bitsProp+">"); - System.out.println("CPU is: "+ (Platform.is32Bit()?"32":"64") + " bit"); - System.out.println("Buffer is in: "+ (Platform.isLittleEndian()?"little":"big") + " endian"); - ByteBuffer tst = Buffers.newDirectByteBuffer(Buffers.SIZEOF_LONG * 3); - StructAccessor acc = new StructAccessor(tst); - acc.setLongAt(0, 0x0123456789ABCDEFL); - acc.setLongAt(1, 0x8877665544332211L); - acc.setLongAt(2, 0xAFFEDEADBEEFAFFEL); - long v = acc.getLongAt(0); - if( 0x0123456789ABCDEFL != v ) { - System.out.println("Err[0] shall 0x0123456789ABCDEF, is: "+Long.toHexString(v)); - ok=false; - } - v = acc.getLongAt(1); - if( 0x8877665544332211L != v ) { - System.out.println("Err[1] shall 0x8877665544332211, is: "+Long.toHexString(v)); - ok=false; - } - v = acc.getLongAt(2); - if( 0xAFFEDEADBEEFAFFEL != v ) { - System.out.println("Err[2] shall 0xAFFEDEADBEEFAFFE, is: "+Long.toHexString(v)); - ok=false; - } - if(!ok) { - throw new RuntimeException("Long conversion failure"); - } - } -} diff --git a/src/junit/com/jogamp/gluegen/test/junit/BaseTest1.java b/src/junit/com/jogamp/gluegen/test/junit/generation/BaseTest1.java index f144a26..0654392 100644 --- a/src/junit/com/jogamp/gluegen/test/junit/BaseTest1.java +++ b/src/junit/com/jogamp/gluegen/test/junit/generation/BaseTest1.java @@ -30,7 +30,7 @@ * SVEN GOTHEL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. */ -package com.jogamp.gluegen.test.junit; +package com.jogamp.gluegen.test.junit.generation; import com.jogamp.gluegen.runtime.Buffers; import com.jogamp.gluegen.runtime.PointerBuffer; @@ -52,7 +52,7 @@ import org.junit.BeforeClass; import org.junit.Test; import static java.lang.System.*; -import static com.jogamp.gluegen.test.junit.BuildEnvironment.*; +import static com.jogamp.gluegen.test.junit.generation.BuildEnvironment.*; /** * @author Michael Bien @@ -64,8 +64,8 @@ public class BaseTest1 { * Verifies the existence and creation of the generated class. */ public void testClassExist(String name) throws Exception { - String ifName = "com.jogamp.gluegen.test.junit.Binding"+name; - String implName = "com.jogamp.gluegen.test.junit.impl.Binding"+name+"Impl"; + String ifName = "com.jogamp.gluegen.test.junit.generation.Binding"+name; + String implName = "com.jogamp.gluegen.test.junit.generation.impl.Binding"+name+"Impl"; Class<?> clazzIf = Class.forName(ifName); Class<?> clazzImpl = Class.forName(implName); @@ -77,7 +77,7 @@ public class BaseTest1 { Object obj = clazzImpl.newInstance(); Assert.assertTrue("Not of type "+ifName, clazzIf.isAssignableFrom(obj.getClass())); - Assert.assertTrue("Not of type com.jogamp.gluegen.test.junit.BindingTest1", (obj instanceof com.jogamp.gluegen.test.junit.BindingTest1)); + Assert.assertTrue("Not of type com.jogamp.gluegen.test.junit.generation.BindingTest1", (obj instanceof com.jogamp.gluegen.test.junit.generation.BindingTest1)); } /** diff --git a/src/junit/com/jogamp/gluegen/test/junit/BuildEnvironment.java b/src/junit/com/jogamp/gluegen/test/junit/generation/BuildEnvironment.java index 16d5053..db5581d 100644 --- a/src/junit/com/jogamp/gluegen/test/junit/BuildEnvironment.java +++ b/src/junit/com/jogamp/gluegen/test/junit/generation/BuildEnvironment.java @@ -30,7 +30,7 @@ * SVEN GOTHEL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. */ -package com.jogamp.gluegen.test.junit; +package com.jogamp.gluegen.test.junit.generation; import java.io.File; import java.net.URISyntaxException; diff --git a/src/junit/com/jogamp/gluegen/test/junit/Test1p1JavaEmitter.java b/src/junit/com/jogamp/gluegen/test/junit/generation/Test1p1JavaEmitter.java index 54d82f9..f4c5027 100644 --- a/src/junit/com/jogamp/gluegen/test/junit/Test1p1JavaEmitter.java +++ b/src/junit/com/jogamp/gluegen/test/junit/generation/Test1p1JavaEmitter.java @@ -30,9 +30,9 @@ * SVEN GOTHEL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. */ -package com.jogamp.gluegen.test.junit; +package com.jogamp.gluegen.test.junit.generation; -import com.jogamp.gluegen.test.junit.impl.BindingTest1p1Impl; +import com.jogamp.gluegen.test.junit.generation.impl.BindingTest1p1Impl; import com.jogamp.gluegen.runtime.Buffers; import com.jogamp.gluegen.runtime.PointerBuffer; @@ -52,7 +52,7 @@ import org.junit.BeforeClass; import org.junit.Test; import static java.lang.System.*; -import static com.jogamp.gluegen.test.junit.BuildEnvironment.*; +import static com.jogamp.gluegen.test.junit.generation.BuildEnvironment.*; /** * @author Michael Bien diff --git a/src/junit/com/jogamp/gluegen/test/junit/Test1p2ProcAddressEmitter.java b/src/junit/com/jogamp/gluegen/test/junit/generation/Test1p2ProcAddressEmitter.java index 3bf90e9..2662786 100644 --- a/src/junit/com/jogamp/gluegen/test/junit/Test1p2ProcAddressEmitter.java +++ b/src/junit/com/jogamp/gluegen/test/junit/generation/Test1p2ProcAddressEmitter.java @@ -30,9 +30,9 @@ * SVEN GOTHEL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. */ -package com.jogamp.gluegen.test.junit; +package com.jogamp.gluegen.test.junit.generation; -import com.jogamp.gluegen.test.junit.impl.BindingTest1p2Impl; +import com.jogamp.gluegen.test.junit.generation.impl.BindingTest1p2Impl; import com.jogamp.gluegen.runtime.Buffers; import com.jogamp.gluegen.runtime.PointerBuffer; @@ -54,7 +54,7 @@ import org.junit.BeforeClass; import org.junit.Test; import static java.lang.System.*; -import static com.jogamp.gluegen.test.junit.BuildEnvironment.*; +import static com.jogamp.gluegen.test.junit.generation.BuildEnvironment.*; /** * @author Michael Bien diff --git a/src/junit/com/jogamp/gluegen/test/junit/test1-common.cfg b/src/junit/com/jogamp/gluegen/test/junit/generation/test1-common.cfg index 2709e80..2709e80 100644 --- a/src/junit/com/jogamp/gluegen/test/junit/test1-common.cfg +++ b/src/junit/com/jogamp/gluegen/test/junit/generation/test1-common.cfg diff --git a/src/junit/com/jogamp/gluegen/test/junit/test1-gluegen.c b/src/junit/com/jogamp/gluegen/test/junit/generation/test1-gluegen.c index bf6ad97..bf6ad97 100644 --- a/src/junit/com/jogamp/gluegen/test/junit/test1-gluegen.c +++ b/src/junit/com/jogamp/gluegen/test/junit/generation/test1-gluegen.c diff --git a/src/junit/com/jogamp/gluegen/test/junit/test1-gluegen.cfg b/src/junit/com/jogamp/gluegen/test/junit/generation/test1-gluegen.cfg index 9d0f856..971419e 100644 --- a/src/junit/com/jogamp/gluegen/test/junit/test1-gluegen.cfg +++ b/src/junit/com/jogamp/gluegen/test/junit/generation/test1-gluegen.cfg @@ -1,4 +1,4 @@ -Package com.jogamp.gluegen.test.junit +Package com.jogamp.gluegen.test.junit.generation JavaClass BindingTest1 Style InterfaceOnly JavaOutputDir classes diff --git a/src/junit/com/jogamp/gluegen/test/junit/test1.c b/src/junit/com/jogamp/gluegen/test/junit/generation/test1.c index f654467..f654467 100644 --- a/src/junit/com/jogamp/gluegen/test/junit/test1.c +++ b/src/junit/com/jogamp/gluegen/test/junit/generation/test1.c diff --git a/src/junit/com/jogamp/gluegen/test/junit/test1.h b/src/junit/com/jogamp/gluegen/test/junit/generation/test1.h index d0e50e5..d0e50e5 100644 --- a/src/junit/com/jogamp/gluegen/test/junit/test1.h +++ b/src/junit/com/jogamp/gluegen/test/junit/generation/test1.h diff --git a/src/junit/com/jogamp/gluegen/test/junit/generation/test1p1-gluegen.cfg b/src/junit/com/jogamp/gluegen/test/junit/generation/test1p1-gluegen.cfg new file mode 100644 index 0000000..2062512 --- /dev/null +++ b/src/junit/com/jogamp/gluegen/test/junit/generation/test1p1-gluegen.cfg @@ -0,0 +1,14 @@ +Package com.jogamp.gluegen.test.junit.generation +JavaClass BindingTest1p1 +Style InterfaceAndImpl +JavaOutputDir classes +NativeOutputDir native + +Extends BindingTest1p1 BindingTest1 + +Include test1-common.cfg + +Import com.jogamp.gluegen.test.junit.generation.BindingTest1 +Import com.jogamp.gluegen.test.junit.generation.BindingTest1p1 + + diff --git a/src/junit/com/jogamp/gluegen/test/junit/test1p2-gluegen.cfg b/src/junit/com/jogamp/gluegen/test/junit/generation/test1p2-gluegen.cfg index 1ec1b6d..f10a760 100644 --- a/src/junit/com/jogamp/gluegen/test/junit/test1p2-gluegen.cfg +++ b/src/junit/com/jogamp/gluegen/test/junit/generation/test1p2-gluegen.cfg @@ -1,4 +1,4 @@ -Package com.jogamp.gluegen.test.junit +Package com.jogamp.gluegen.test.junit.generation JavaClass BindingTest1p2 Style InterfaceAndImpl JavaOutputDir classes @@ -22,10 +22,10 @@ ForceProcAddressGen __ALL__ LocalProcAddressCallingConvention __ALL__ MYAPIENTRY Include test1-common.cfg -Include ../../../../../../../make/config/intptr.cfg +Include ../../../../../../../../make/config/intptr.cfg -Import com.jogamp.gluegen.test.junit.BindingTest1 -Import com.jogamp.gluegen.test.junit.BindingTest1p2 +Import com.jogamp.gluegen.test.junit.generation.BindingTest1 +Import com.jogamp.gluegen.test.junit.generation.BindingTest1p2 Import com.jogamp.gluegen.runtime.* CustomJavaCode BindingTest1p2Impl private static BindingTest1p2ProcAddressTable _table = new BindingTest1p2ProcAddressTable(); diff --git a/src/junit/com/jogamp/gluegen/test/junit/runtime/TestPointerBufferEndian.java b/src/junit/com/jogamp/gluegen/test/junit/runtime/TestPointerBufferEndian.java new file mode 100644 index 0000000..cab64c0 --- /dev/null +++ b/src/junit/com/jogamp/gluegen/test/junit/runtime/TestPointerBufferEndian.java @@ -0,0 +1,53 @@ + +package com.jogamp.gluegen.test.junit.runtime; + +import com.jogamp.gluegen.runtime.*; + +import java.nio.*; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +import static java.lang.System.*; + +public class TestPointerBufferEndian { + + protected void testImpl (boolean direct) { + int bitsPtr = Platform.getPointerSizeInBits(); + String bitsProp = System.getProperty("sun.arch.data.model"); + String os = System.getProperty("os.name"); + String cpu = System.getProperty("os.arch"); + System.out.println("OS: <"+os+"> CPU: <"+cpu+"> Bits: <"+bitsPtr+"/"+bitsProp+">"); + System.out.println("CPU is: "+ (Platform.is32Bit()?"32":"64") + " bit"); + System.out.println("Buffer is in: "+ (Platform.isLittleEndian()?"little":"big") + " endian"); + + long[] valuesSource = { 0x0123456789ABCDEFL, 0x8877665544332211L, 0xAFFEDEADBEEFAFFEL }; + long[] values32Bit = { 0x0000000089ABCDEFL, 0x0000000044332211L, 0x00000000BEEFAFFEL }; + + PointerBuffer ptr = direct ? PointerBuffer.allocateDirect(3) : PointerBuffer.allocate(valuesSource.length); + ptr.put(valuesSource, 0, valuesSource.length); + ptr.rewind(); + + int i=0; + while(ptr.hasRemaining()) { + long mask = Platform.is32Bit() ? 0x00000000FFFFFFFFL : 0xFFFFFFFFFFFFFFFFL ; + long v = ptr.get() & mask; + long t = Platform.is32Bit() ? values32Bit[i] : valuesSource[i]; + Assert.assertTrue("Value["+i+"] shall be 0x"+Long.toHexString(t)+", is: 0x"+Long.toHexString(v), t == v); + i++; + } + Assert.assertTrue("iterator "+i+" != "+valuesSource.length, i==valuesSource.length); + } + + @Test + public void testDirect () { + testImpl (true); + } + + @Test + public void testIndirect () { + testImpl (false); + } +} diff --git a/src/junit/com/jogamp/gluegen/test/junit/runtime/TestStructAccessorEndian.java b/src/junit/com/jogamp/gluegen/test/junit/runtime/TestStructAccessorEndian.java new file mode 100644 index 0000000..669fd78 --- /dev/null +++ b/src/junit/com/jogamp/gluegen/test/junit/runtime/TestStructAccessorEndian.java @@ -0,0 +1,42 @@ +package com.jogamp.gluegen.test.junit.runtime; + +import com.jogamp.gluegen.runtime.*; + +import java.nio.*; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +import static java.lang.System.*; + +public class TestStructAccessorEndian { + + @Test + public void testStructAccessorEndian1 () { + int bitsPtr = Platform.getPointerSizeInBits(); + String bitsProp = System.getProperty("sun.arch.data.model"); + String os = System.getProperty("os.name"); + String cpu = System.getProperty("os.arch"); + System.out.println("OS: <"+os+"> CPU: <"+cpu+"> Bits: <"+bitsPtr+"/"+bitsProp+">"); + System.out.println("CPU is: "+ (Platform.is32Bit()?"32":"64") + " bit"); + System.out.println("Buffer is in: "+ (Platform.isLittleEndian()?"little":"big") + " endian"); + + long[] valuesSource = { 0x0123456789ABCDEFL, 0x8877665544332211L, 0xAFFEDEADBEEFAFFEL }; + ByteBuffer tst = Buffers.newDirectByteBuffer(Buffers.SIZEOF_LONG * valuesSource.length); + StructAccessor acc = new StructAccessor(tst); + + int i; + + for(i=0; i<valuesSource.length; i++) { + acc.setLongAt(i, valuesSource[i]); + } + + for(i=0; i<valuesSource.length; i++) { + long v = acc.getLongAt(i); + long t = valuesSource[i]; + Assert.assertTrue("Value["+i+"] shall be 0x"+Long.toHexString(t)+", is: 0x"+Long.toHexString(v), t == v); + } + } +} diff --git a/src/junit/com/jogamp/gluegen/test/junit/test1p1-gluegen.cfg b/src/junit/com/jogamp/gluegen/test/junit/test1p1-gluegen.cfg deleted file mode 100644 index 78e4d8a..0000000 --- a/src/junit/com/jogamp/gluegen/test/junit/test1p1-gluegen.cfg +++ /dev/null @@ -1,14 +0,0 @@ -Package com.jogamp.gluegen.test.junit -JavaClass BindingTest1p1 -Style InterfaceAndImpl -JavaOutputDir classes -NativeOutputDir native - -Extends BindingTest1p1 BindingTest1 - -Include test1-common.cfg - -Import com.jogamp.gluegen.test.junit.BindingTest1 -Import com.jogamp.gluegen.test.junit.BindingTest1p1 - - |