From b4d3f5fc0d846c3b302e99846610e52955ec826b Mon Sep 17 00:00:00 2001
From: Michael Bien <mbien@fh-landshut.de>
Date: Tue, 22 Feb 2011 02:03:54 +0100
Subject:  - ensure slice uses the buffers original byteorder.  - create new
 buffers only if size > capacity not if >= capacity

---
 src/java/com/jogamp/common/nio/CachedBufferFactory.java | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

(limited to 'src/java/com')

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;
-- 
cgit v1.2.3


From 0fea7dfb1514ab1c3d5765057975be50d7282d0d Mon Sep 17 00:00:00 2001
From: Michael Bien <mbien@fh-landshut.de>
Date: Tue, 22 Feb 2011 04:50:38 +0100
Subject:  - Buffers.slice() should maintain byteorder when sliceing
 ByteBuffers  - simplified isDirect() and getArray()

---
 src/java/com/jogamp/common/nio/Buffers.java | 40 +++++++----------------------
 1 file changed, 9 insertions(+), 31 deletions(-)

(limited to 'src/java/com')

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());
-- 
cgit v1.2.3