summaryrefslogtreecommitdiffstats
path: root/src/java/com/jogamp/common
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2011-02-22 17:34:47 +0100
committerSven Gothel <[email protected]>2011-02-22 17:34:47 +0100
commitec4fcc9699db753a6d462c8c3df7ba71949c9fdd (patch)
tree00812e354af24c048899be2aae3b6db11ded2d28 /src/java/com/jogamp/common
parent65ab75dec5b3ab063a5cdb034325426d27e3b425 (diff)
parent0fea7dfb1514ab1c3d5765057975be50d7282d0d (diff)
Merge remote branch 'mbien/master'
Diffstat (limited to 'src/java/com/jogamp/common')
-rwxr-xr-xsrc/java/com/jogamp/common/nio/Buffers.java40
-rw-r--r--src/java/com/jogamp/common/nio/CachedBufferFactory.java4
2 files changed, 11 insertions, 33 deletions
diff --git a/src/java/com/jogamp/common/nio/Buffers.java b/src/java/com/jogamp/common/nio/Buffers.java
index d46391f..45cb5a6 100755
--- a/src/java/com/jogamp/common/nio/Buffers.java
+++ b/src/java/com/jogamp/common/nio/Buffers.java
@@ -208,12 +208,13 @@ public class Buffers {
}
/**
- * Calls slice on the specified buffer.
+ * Calls slice on the specified buffer while maintaining the byteorder.
* @see #slice(java.nio.Buffer, int, int)
*/
public static <B extends Buffer> B slice(B buffer) {
if (buffer instanceof ByteBuffer) {
- return (B) ((ByteBuffer) buffer).slice();
+ ByteBuffer bb = (ByteBuffer) buffer;
+ return (B) bb.slice().order(bb.order()); // bb can change byte order on slice and duplicate
} else if (buffer instanceof IntBuffer) {
return (B) ((IntBuffer) buffer).slice();
} else if (buffer instanceof ShortBuffer) {
@@ -231,7 +232,8 @@ public class Buffers {
}
/**
- * Slices the specified buffer with offset as position and offset+size as limit.
+ * Slices the specified buffer with offset as position and offset+size as limit
+ * while maintaining the byteorder.
* Concurrency warning: this method changes the buffers position and limit but
* will restore it before return.
*/
@@ -293,24 +295,12 @@ public class Buffers {
if (buf == null) {
return true;
}
- if (buf instanceof ByteBuffer) {
- return ((ByteBuffer) buf).isDirect();
- } else if (buf instanceof FloatBuffer) {
- return ((FloatBuffer) buf).isDirect();
- } else if (buf instanceof IntBuffer) {
- return ((IntBuffer) buf).isDirect();
- } else if (buf instanceof ShortBuffer) {
- return ((ShortBuffer) buf).isDirect();
+ if (buf instanceof Buffer) {
+ return ((Buffer) buf).isDirect();
} else if (buf instanceof Int64Buffer) {
return ((Int64Buffer) buf).isDirect();
} else if (buf instanceof PointerBuffer) {
return ((PointerBuffer) buf).isDirect();
- } else if (buf instanceof DoubleBuffer) {
- return ((DoubleBuffer) buf).isDirect();
- } else if (buf instanceof LongBuffer) {
- return ((LongBuffer) buf).isDirect();
- }else if (buf instanceof CharBuffer) {
- return ((CharBuffer) buf).isDirect();
}
throw new IllegalArgumentException("Unexpected buffer type " + buf.getClass().getName());
}
@@ -360,24 +350,12 @@ public class Buffers {
if (buf == null) {
return null;
}
- if (buf instanceof ByteBuffer) {
- return ((ByteBuffer) buf).array();
- } else if (buf instanceof FloatBuffer) {
- return ((FloatBuffer) buf).array();
- } else if (buf instanceof IntBuffer) {
- return ((IntBuffer) buf).array();
- } else if (buf instanceof ShortBuffer) {
- return ((ShortBuffer) buf).array();
+ if (buf instanceof Buffer) {
+ return ((Buffer) buf).array();
} else if (buf instanceof Int64Buffer) {
return ((Int64Buffer) buf).array();
} else if (buf instanceof PointerBuffer) {
return ((PointerBuffer) buf).array();
- }else if (buf instanceof DoubleBuffer) {
- return ((DoubleBuffer) buf).array();
- } else if (buf instanceof LongBuffer) {
- return ((LongBuffer) buf).array();
- } else if (buf instanceof CharBuffer) {
- return ((CharBuffer) buf).array();
}
throw new IllegalArgumentException("Disallowed array backing store type in buffer " + buf.getClass().getName());
diff --git a/src/java/com/jogamp/common/nio/CachedBufferFactory.java b/src/java/com/jogamp/common/nio/CachedBufferFactory.java
index 36bac13..dbeed2d 100644
--- a/src/java/com/jogamp/common/nio/CachedBufferFactory.java
+++ b/src/java/com/jogamp/common/nio/CachedBufferFactory.java
@@ -168,7 +168,7 @@ public class CachedBufferFactory {
public ByteBuffer newDirectByteBuffer(int size) {
// if large enough... just create it
- if (size >= currentBuffer.capacity()) {
+ if (size > currentBuffer.capacity()) {
checkIfFixed();
return Buffers.newDirectByteBuffer(size);
}
@@ -180,7 +180,7 @@ public class CachedBufferFactory {
}
currentBuffer.limit(currentBuffer.position() + size);
- ByteBuffer result = currentBuffer.slice();
+ ByteBuffer result = currentBuffer.slice().order(currentBuffer.order());
currentBuffer.position(currentBuffer.limit());
currentBuffer.limit(currentBuffer.capacity());
return result;