summaryrefslogtreecommitdiffstats
path: root/src/java/com/jogamp/gluegen/runtime
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2010-03-29 04:51:49 +0200
committerSven Gothel <[email protected]>2010-03-29 04:51:49 +0200
commit69fe372b874d913e2d1c27f1d103e1fced668ecf (patch)
treecf402337903ba3d02bbab628f2f82a23908a5f11 /src/java/com/jogamp/gluegen/runtime
parent2138fc787c1e497be7f373aa68b3f751c955008f (diff)
parent2d76c16b9384d383d3e6a9d7cb727f2591a39228 (diff)
Resolved conflicts
Diffstat (limited to 'src/java/com/jogamp/gluegen/runtime')
-rwxr-xr-xsrc/java/com/jogamp/gluegen/runtime/Buffers.java (renamed from src/java/com/jogamp/gluegen/runtime/BufferFactory.java)346
-rw-r--r--src/java/com/jogamp/gluegen/runtime/Int64Buffer.java6
-rwxr-xr-xsrc/java/com/jogamp/gluegen/runtime/Int64BufferME_CDC_FP.java4
-rw-r--r--src/java/com/jogamp/gluegen/runtime/Platform.java2
-rw-r--r--src/java/com/jogamp/gluegen/runtime/PointerBuffer.java6
-rwxr-xr-xsrc/java/com/jogamp/gluegen/runtime/PointerBufferME_CDC_FP.java4
-rw-r--r--src/java/com/jogamp/gluegen/runtime/StructAccessor.java4
7 files changed, 353 insertions, 19 deletions
diff --git a/src/java/com/jogamp/gluegen/runtime/BufferFactory.java b/src/java/com/jogamp/gluegen/runtime/Buffers.java
index 9b52640..96c9430 100755
--- a/src/java/com/jogamp/gluegen/runtime/BufferFactory.java
+++ b/src/java/com/jogamp/gluegen/runtime/Buffers.java
@@ -45,7 +45,7 @@ import java.nio.*;
* @author Sven Gothel
* @author Michael Bien
*/
-public class BufferFactory {
+public class Buffers {
public static final int SIZEOF_BYTE = 1;
public static final int SIZEOF_SHORT = 2;
@@ -55,15 +55,153 @@ public class BufferFactory {
public static final int SIZEOF_LONG = 8;
public static final int SIZEOF_DOUBLE = 8;
- public static boolean isLittleEndian() {
- return Platform.isLittleEndian();
+ private Buffers() {}
+
+ /**
+ * Allocates a new direct ByteBuffer with the specified number of
+ * elements. The returned buffer will have its byte order set to
+ * the host platform's native byte order.
+ */
+ public static ByteBuffer newDirectByteBuffer(int numElements) {
+ return nativeOrder(ByteBuffer.allocateDirect(numElements));
+ }
+
+ public static ByteBuffer newDirectByteBuffer(byte[] values, int offset, int lenght) {
+ return (ByteBuffer)newDirectByteBuffer(lenght).put(values, offset, lenght).rewind();
+ }
+
+ public static ByteBuffer newDirectByteBuffer(byte[] values, int offset) {
+ return newDirectByteBuffer(values, offset, values.length-offset);
+ }
+
+ public static ByteBuffer newDirectByteBuffer(byte[] values) {
+ return newDirectByteBuffer(values, 0);
}
/**
- * Helper routine to create a direct ByteBuffer with native order
+ * Allocates a new direct DoubleBuffer with the specified number of
+ * elements. The returned buffer will have its byte order set to
+ * the host platform's native byte order.
*/
- public static ByteBuffer newDirectByteBuffer(int size) {
- return nativeOrder(ByteBuffer.allocateDirect(size));
+ public static DoubleBuffer newDirectDoubleBuffer(int numElements) {
+ return newDirectByteBuffer(numElements * SIZEOF_DOUBLE).asDoubleBuffer();
+ }
+
+ public static DoubleBuffer newDirectDoubleBuffer(double[] values, int offset, int lenght) {
+ return (DoubleBuffer)newDirectDoubleBuffer(lenght).put(values, offset, lenght).rewind();
+ }
+
+ public static DoubleBuffer newDirectDoubleBuffer(double[] values, int offset) {
+ return newDirectDoubleBuffer(values, offset, values.length - offset);
+ }
+
+ public static DoubleBuffer newDirectDoubleBuffer(double[] values) {
+ return newDirectDoubleBuffer(values, 0);
+ }
+
+ /**
+ * Allocates a new direct FloatBuffer with the specified number of
+ * elements. The returned buffer will have its byte order set to
+ * the host platform's native byte order.
+ */
+ public static FloatBuffer newDirectFloatBuffer(int numElements) {
+ return newDirectByteBuffer(numElements * SIZEOF_FLOAT).asFloatBuffer();
+ }
+
+ public static FloatBuffer newDirectFloatBuffer(float[] values, int offset, int lenght) {
+ return (FloatBuffer)newDirectFloatBuffer(lenght).put(values, offset, lenght).rewind();
+ }
+
+ public static FloatBuffer newDirectFloatBuffer(float[] values, int offset) {
+ return newDirectFloatBuffer(values, offset, values.length - offset);
+ }
+
+ public static FloatBuffer newDirectFloatBuffer(float[] values) {
+ return newDirectFloatBuffer(values, 0);
+ }
+
+ /**
+ * Allocates a new direct IntBuffer with the specified number of
+ * elements. The returned buffer will have its byte order set to
+ * the host platform's native byte order.
+ */
+ public static IntBuffer newDirectIntBuffer(int numElements) {
+ return newDirectByteBuffer(numElements * SIZEOF_INT).asIntBuffer();
+ }
+
+ public static IntBuffer newDirectIntBuffer(int[] values, int offset, int lenght) {
+ return (IntBuffer)newDirectIntBuffer(lenght).put(values, offset, lenght).rewind();
+ }
+
+ public static IntBuffer newDirectIntBuffer(int[] values, int offset) {
+ return newDirectIntBuffer(values, offset, values.length - offset);
+ }
+
+ public static IntBuffer newDirectIntBuffer(int[] values) {
+ return newDirectIntBuffer(values, 0);
+ }
+
+ /**
+ * Allocates a new direct LongBuffer with the specified number of
+ * elements. The returned buffer will have its byte order set to
+ * the host platform's native byte order.
+ */
+ public static LongBuffer newDirectLongBuffer(int numElements) {
+ return newDirectByteBuffer(numElements * SIZEOF_LONG).asLongBuffer();
+ }
+
+ public static LongBuffer newDirectLongBuffer(long[] values, int offset, int lenght) {
+ return (LongBuffer)newDirectLongBuffer(lenght).put(values, offset, lenght).rewind();
+ }
+
+ public static LongBuffer newDirectLongBuffer(long[] values, int offset) {
+ return newDirectLongBuffer(values, offset, values.length - offset);
+ }
+
+ public static LongBuffer newDirectLongBuffer(long[] values) {
+ return newDirectLongBuffer(values, 0);
+ }
+
+ /**
+ * Allocates a new direct ShortBuffer with the specified number of
+ * elements. The returned buffer will have its byte order set to
+ * the host platform's native byte order.
+ */
+ public static ShortBuffer newDirectShortBuffer(int numElements) {
+ return newDirectByteBuffer(numElements * SIZEOF_SHORT).asShortBuffer();
+ }
+
+ public static ShortBuffer newDirectShortBuffer(short[] values, int offset, int lenght) {
+ return (ShortBuffer)newDirectShortBuffer(lenght).put(values, offset, lenght).rewind();
+ }
+
+ public static ShortBuffer newDirectShortBuffer(short[] values, int offset) {
+ return newDirectShortBuffer(values, offset, values.length - offset);
+ }
+
+ public static ShortBuffer newDirectShortBuffer(short[] values) {
+ return newDirectShortBuffer(values, 0);
+ }
+
+ /**
+ * Allocates a new direct CharBuffer with the specified number of
+ * elements. The returned buffer will have its byte order set to
+ * the host platform's native byte order.
+ */
+ public static CharBuffer newDirectCharBuffer(int numElements) {
+ return newDirectByteBuffer(numElements * SIZEOF_SHORT).asCharBuffer();
+ }
+
+ public static CharBuffer newDirectCharBuffer(char[] values, int offset, int lenght) {
+ return (CharBuffer)newDirectCharBuffer(lenght).put(values, offset, lenght).rewind();
+ }
+
+ public static CharBuffer newDirectCharBuffer(char[] values, int offset) {
+ return newDirectCharBuffer(values, offset, values.length - offset);
+ }
+
+ public static CharBuffer newDirectCharBuffer(char[] values) {
+ return newDirectCharBuffer(values, 0);
}
/**
@@ -228,6 +366,201 @@ public class BufferFactory {
throw new RuntimeException("Unknown buffer type " + buf.getClass().getName());
}
+
+ //----------------------------------------------------------------------
+ // Copy routines (type-to-type)
+ //
+ /**
+ * Copies the <i>remaining</i> elements (as defined by
+ * <code>limit() - position()</code>) in the passed ByteBuffer into
+ * a newly-allocated direct ByteBuffer. The returned buffer will
+ * have its byte order set to the host platform's native byte
+ * order. The position of the newly-allocated buffer will be zero,
+ * and the position of the passed buffer is unchanged (though its
+ * mark is changed).
+ */
+ public static ByteBuffer copyByteBuffer(ByteBuffer orig) {
+ ByteBuffer dest = newDirectByteBuffer(orig.remaining());
+ dest.put(orig);
+ dest.rewind();
+ return dest;
+ }
+
+ /**
+ * Copies the <i>remaining</i> elements (as defined by
+ * <code>limit() - position()</code>) in the passed FloatBuffer
+ * into a newly-allocated direct FloatBuffer. The returned buffer
+ * will have its byte order set to the host platform's native byte
+ * order. The position of the newly-allocated buffer will be zero,
+ * and the position of the passed buffer is unchanged (though its
+ * mark is changed).
+ */
+ public static FloatBuffer copyFloatBuffer(FloatBuffer orig) {
+ return copyFloatBufferAsByteBuffer(orig).asFloatBuffer();
+ }
+
+ /**
+ * Copies the <i>remaining</i> elements (as defined by
+ * <code>limit() - position()</code>) in the passed IntBuffer
+ * into a newly-allocated direct IntBuffer. The returned buffer
+ * will have its byte order set to the host platform's native byte
+ * order. The position of the newly-allocated buffer will be zero,
+ * and the position of the passed buffer is unchanged (though its
+ * mark is changed).
+ */
+ public static IntBuffer copyIntBuffer(IntBuffer orig) {
+ return copyIntBufferAsByteBuffer(orig).asIntBuffer();
+ }
+
+ /**
+ * Copies the <i>remaining</i> elements (as defined by
+ * <code>limit() - position()</code>) in the passed ShortBuffer
+ * into a newly-allocated direct ShortBuffer. The returned buffer
+ * will have its byte order set to the host platform's native byte
+ * order. The position of the newly-allocated buffer will be zero,
+ * and the position of the passed buffer is unchanged (though its
+ * mark is changed).
+ */
+ public static ShortBuffer copyShortBuffer(ShortBuffer orig) {
+ return copyShortBufferAsByteBuffer(orig).asShortBuffer();
+ }
+
+ //----------------------------------------------------------------------
+ // Copy routines (type-to-ByteBuffer)
+ //
+ /**
+ * Copies the <i>remaining</i> elements (as defined by
+ * <code>limit() - position()</code>) in the passed FloatBuffer
+ * into a newly-allocated direct ByteBuffer. The returned buffer
+ * will have its byte order set to the host platform's native byte
+ * order. The position of the newly-allocated buffer will be zero,
+ * and the position of the passed buffer is unchanged (though its
+ * mark is changed).
+ */
+ public static ByteBuffer copyFloatBufferAsByteBuffer(FloatBuffer orig) {
+ ByteBuffer dest = newDirectByteBuffer(orig.remaining() * SIZEOF_FLOAT);
+ dest.asFloatBuffer().put(orig);
+ dest.rewind();
+ return dest;
+ }
+
+ /**
+ * Copies the <i>remaining</i> elements (as defined by
+ * <code>limit() - position()</code>) in the passed IntBuffer into
+ * a newly-allocated direct ByteBuffer. The returned buffer will
+ * have its byte order set to the host platform's native byte
+ * order. The position of the newly-allocated buffer will be zero,
+ * and the position of the passed buffer is unchanged (though its
+ * mark is changed).
+ */
+ public static ByteBuffer copyIntBufferAsByteBuffer(IntBuffer orig) {
+ ByteBuffer dest = newDirectByteBuffer(orig.remaining() * SIZEOF_INT);
+ dest.asIntBuffer().put(orig);
+ dest.rewind();
+ return dest;
+ }
+
+ /**
+ * Copies the <i>remaining</i> elements (as defined by
+ * <code>limit() - position()</code>) in the passed ShortBuffer
+ * into a newly-allocated direct ByteBuffer. The returned buffer
+ * will have its byte order set to the host platform's native byte
+ * order. The position of the newly-allocated buffer will be zero,
+ * and the position of the passed buffer is unchanged (though its
+ * mark is changed).
+ */
+ public static ByteBuffer copyShortBufferAsByteBuffer(ShortBuffer orig) {
+ ByteBuffer dest = newDirectByteBuffer(orig.remaining() * SIZEOF_SHORT);
+ dest.asShortBuffer().put(orig);
+ dest.rewind();
+ return dest;
+ }
+
+ //----------------------------------------------------------------------
+ // Conversion routines
+ //
+ public final static FloatBuffer getFloatBuffer(DoubleBuffer source) {
+ source.rewind();
+ FloatBuffer dest = newDirectFloatBuffer(source.limit());
+ while (source.hasRemaining()) {
+ dest.put((float) source.get());
+ }
+ return dest;
+ }
+
+ //----------------------------------------------------------------------
+ // Convenient put methods with generic target Buffer
+ //
+ public static Buffer put(Buffer dest, Buffer src) {
+ if ((dest instanceof ByteBuffer) && (src instanceof ByteBuffer)) {
+ return ((ByteBuffer) dest).put((ByteBuffer) src);
+ } else if ((dest instanceof ShortBuffer) && (src instanceof ShortBuffer)) {
+ return ((ShortBuffer) dest).put((ShortBuffer) src);
+ } else if ((dest instanceof IntBuffer) && (src instanceof IntBuffer)) {
+ return ((IntBuffer) dest).put((IntBuffer) src);
+ } else if ((dest instanceof FloatBuffer) && (src instanceof FloatBuffer)) {
+ return ((FloatBuffer) dest).put((FloatBuffer) src);
+ } else if (Platform.isJavaSE()) {
+ if ((dest instanceof LongBuffer) && (src instanceof LongBuffer)) {
+ return ((LongBuffer) dest).put((LongBuffer) src);
+ } else if ((dest instanceof DoubleBuffer) && (src instanceof DoubleBuffer)) {
+ return ((DoubleBuffer) dest).put((DoubleBuffer) src);
+ } else if ((dest instanceof CharBuffer) && (src instanceof CharBuffer)) {
+ return ((CharBuffer) dest).put((CharBuffer) src);
+ }
+ }
+ throw new RuntimeException("Incompatible Buffer classes: dest = " + dest.getClass().getName() + ", src = " + src.getClass().getName());
+ }
+
+ public static Buffer putb(Buffer dest, byte v) {
+ if (dest instanceof ByteBuffer) {
+ return ((ByteBuffer) dest).put(v);
+ } else if (dest instanceof ShortBuffer) {
+ return ((ShortBuffer) dest).put((short) v);
+ } else if (dest instanceof IntBuffer) {
+ return ((IntBuffer) dest).put((int) v);
+ } else {
+ throw new RuntimeException("Byte doesn't match Buffer Class: " + dest);
+ }
+ }
+
+ public static Buffer puts(Buffer dest, short v) {
+ if (dest instanceof ShortBuffer) {
+ return ((ShortBuffer) dest).put(v);
+ } else if (dest instanceof IntBuffer) {
+ return ((IntBuffer) dest).put((int) v);
+ } else {
+ throw new RuntimeException("Short doesn't match Buffer Class: " + dest);
+ }
+ }
+
+ public static void puti(Buffer dest, int v) {
+ if (dest instanceof IntBuffer) {
+ ((IntBuffer) dest).put(v);
+ } else {
+ throw new RuntimeException("Integer doesn't match Buffer Class: " + dest);
+ }
+ }
+
+ public static void putf(Buffer dest, float v) {
+ if (dest instanceof FloatBuffer) {
+ ((FloatBuffer) dest).put(v);
+/* TODO FixedPoint required
+ } else if (dest instanceof IntBuffer) {
+ ((IntBuffer) dest).put(FixedPoint.toFixed(v));
+*/
+ } else {
+ throw new RuntimeException("Float doesn't match Buffer Class: " + dest);
+ }
+ }
+ public static void putd(Buffer dest, double v) {
+ if (dest instanceof FloatBuffer) {
+ ((FloatBuffer) dest).put((float) v);
+ } else {
+ throw new RuntimeException("Double doesn't match Buffer Class: " + dest);
+ }
+ }
+
public static void rangeCheck(byte[] array, int offset, int minElementsRemaining) {
if (array == null) {
return;
@@ -344,4 +677,5 @@ public class BufferFactory {
throw new IndexOutOfBoundsException("Required " + minBytesRemaining + " remaining bytes in buffer, only had " + bytesRemaining);
}
}
+
}
diff --git a/src/java/com/jogamp/gluegen/runtime/Int64Buffer.java b/src/java/com/jogamp/gluegen/runtime/Int64Buffer.java
index ad218bc..5f7cc33 100644
--- a/src/java/com/jogamp/gluegen/runtime/Int64Buffer.java
+++ b/src/java/com/jogamp/gluegen/runtime/Int64Buffer.java
@@ -58,9 +58,9 @@ public abstract class Int64Buffer {
public static Int64Buffer allocateDirect(int size) {
if (Platform.isJavaSE()) {
- return new Int64BufferSE(BufferFactory.newDirectByteBuffer(elementSize() * size));
+ return new Int64BufferSE(Buffers.newDirectByteBuffer(elementSize() * size));
} else {
- return new Int64BufferME_CDC_FP(BufferFactory.newDirectByteBuffer(elementSize() * size));
+ return new Int64BufferME_CDC_FP(Buffers.newDirectByteBuffer(elementSize() * size));
}
}
@@ -87,7 +87,7 @@ public abstract class Int64Buffer {
}
public static int elementSize() {
- return BufferFactory.SIZEOF_LONG;
+ return Buffers.SIZEOF_LONG;
}
public int limit() {
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 ec43897..cedb737 100755
--- a/src/java/com/jogamp/gluegen/runtime/Int64BufferME_CDC_FP.java
+++ b/src/java/com/jogamp/gluegen/runtime/Int64BufferME_CDC_FP.java
@@ -62,7 +62,7 @@ final class Int64BufferME_CDC_FP extends Int64Buffer {
idx = idx << 1; // 8-byte to 4-byte offset
long lo = 0x00000000FFFFFFFFL & ((long) pb.get(idx));
long hi = 0x00000000FFFFFFFFL & ((long) pb.get(idx + 1));
- if (BufferFactory.isLittleEndian()) {
+ if (Platform.isLittleEndian()) {
return hi << 32 | lo;
}
return lo << 32 | hi;
@@ -76,7 +76,7 @@ final class Int64BufferME_CDC_FP extends Int64Buffer {
idx = idx << 1; // 8-byte to 4-byte offset
int lo = (int) ((v) & 0x00000000FFFFFFFFL);
int hi = (int) ((v >> 32) & 0x00000000FFFFFFFFL);
- if (BufferFactory.isLittleEndian()) {
+ if (Platform.isLittleEndian()) {
pb.put(idx, lo);
pb.put(idx + 1, hi);
} else {
diff --git a/src/java/com/jogamp/gluegen/runtime/Platform.java b/src/java/com/jogamp/gluegen/runtime/Platform.java
index e4090c4..a621279 100644
--- a/src/java/com/jogamp/gluegen/runtime/Platform.java
+++ b/src/java/com/jogamp/gluegen/runtime/Platform.java
@@ -107,7 +107,7 @@ public class Platform {
JAVA_SE = se;
// byte order
- ByteBuffer tst_b = BufferFactory.newDirectByteBuffer(BufferFactory.SIZEOF_INT); // 32bit in native order
+ ByteBuffer tst_b = Buffers.newDirectByteBuffer(Buffers.SIZEOF_INT); // 32bit in native order
IntBuffer tst_i = tst_b.asIntBuffer();
ShortBuffer tst_s = tst_b.asShortBuffer();
tst_i.put(0, 0x0A0B0C0D);
diff --git a/src/java/com/jogamp/gluegen/runtime/PointerBuffer.java b/src/java/com/jogamp/gluegen/runtime/PointerBuffer.java
index 8e30ed8..a89dace 100644
--- a/src/java/com/jogamp/gluegen/runtime/PointerBuffer.java
+++ b/src/java/com/jogamp/gluegen/runtime/PointerBuffer.java
@@ -62,9 +62,9 @@ public abstract class PointerBuffer {
public static PointerBuffer allocateDirect(int size) {
if (Platform.isJavaSE()) {
- return new PointerBufferSE(BufferFactory.newDirectByteBuffer(elementSize() * size));
+ return new PointerBufferSE(Buffers.newDirectByteBuffer(elementSize() * size));
} else {
- return new PointerBufferME_CDC_FP(BufferFactory.newDirectByteBuffer(elementSize() * size));
+ return new PointerBufferME_CDC_FP(Buffers.newDirectByteBuffer(elementSize() * size));
}
}
@@ -91,7 +91,7 @@ public abstract class PointerBuffer {
}
public static int elementSize() {
- return Platform.is32Bit() ? BufferFactory.SIZEOF_INT : BufferFactory.SIZEOF_LONG;
+ return Platform.is32Bit() ? Buffers.SIZEOF_INT : Buffers.SIZEOF_LONG;
}
public int limit() {
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 0ae7af6..1134ee7 100755
--- a/src/java/com/jogamp/gluegen/runtime/PointerBufferME_CDC_FP.java
+++ b/src/java/com/jogamp/gluegen/runtime/PointerBufferME_CDC_FP.java
@@ -65,7 +65,7 @@ final class PointerBufferME_CDC_FP extends PointerBuffer {
idx = idx << 1; // 8-byte to 4-byte offset
long lo = 0x00000000FFFFFFFFL & ((long) pb.get(idx));
long hi = 0x00000000FFFFFFFFL & ((long) pb.get(idx + 1));
- if (BufferFactory.isLittleEndian()) {
+ if (Platform.isLittleEndian()) {
return hi << 32 | lo;
}
return lo << 32 | hi;
@@ -83,7 +83,7 @@ final class PointerBufferME_CDC_FP extends PointerBuffer {
idx = idx << 1; // 8-byte to 4-byte offset
int lo = (int) ((v) & 0x00000000FFFFFFFFL);
int hi = (int) ((v >> 32) & 0x00000000FFFFFFFFL);
- if (BufferFactory.isLittleEndian()) {
+ if (Platform.isLittleEndian()) {
pb.put(idx, lo);
pb.put(idx + 1, hi);
} else {
diff --git a/src/java/com/jogamp/gluegen/runtime/StructAccessor.java b/src/java/com/jogamp/gluegen/runtime/StructAccessor.java
index 80673a3..6f3ad7d 100644
--- a/src/java/com/jogamp/gluegen/runtime/StructAccessor.java
+++ b/src/java/com/jogamp/gluegen/runtime/StructAccessor.java
@@ -251,7 +251,7 @@ public class StructAccessor {
IntBuffer intBuffer = intBuffer();
long lo = 0x00000000FFFFFFFFL & ((long) intBuffer.get(slot));
long hi = 0x00000000FFFFFFFFL & ((long) intBuffer.get(slot + 1));
- if (BufferFactory.isLittleEndian()) {
+ if (Platform.isLittleEndian()) {
return hi << 32 | lo;
}
return lo << 32 | hi;
@@ -262,7 +262,7 @@ public class StructAccessor {
IntBuffer intBuffer = intBuffer();
int lo = (int) ((v) & 0x00000000FFFFFFFFL);
int hi = (int) ((v >> 32) & 0x00000000FFFFFFFFL);
- if (BufferFactory.isLittleEndian()) {
+ if (Platform.isLittleEndian()) {
intBuffer.put(slot, lo);
intBuffer.put(slot + 1, hi);
} else {