diff options
author | Michael Bien <[email protected]> | 2010-03-29 15:37:41 +0200 |
---|---|---|
committer | Michael Bien <[email protected]> | 2010-03-29 15:37:41 +0200 |
commit | df0f47b18178c03a8c56d3e3d6b481769f3f1a30 (patch) | |
tree | a4fa896cf0dccf5bf7ea07f22a51b6b5e6c51066 /src/java/com/jogamp/gluegen/runtime | |
parent | ec4bdff4eabf5e1668b3e52d1c2708444fb76856 (diff) |
added sizeOfBufferElem(Buffer buf) to Buffers.
Diffstat (limited to 'src/java/com/jogamp/gluegen/runtime')
-rwxr-xr-x | src/java/com/jogamp/gluegen/runtime/Buffers.java | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/src/java/com/jogamp/gluegen/runtime/Buffers.java b/src/java/com/jogamp/gluegen/runtime/Buffers.java index 3b4bc28..11b2739 100755 --- a/src/java/com/jogamp/gluegen/runtime/Buffers.java +++ b/src/java/com/jogamp/gluegen/runtime/Buffers.java @@ -220,6 +220,33 @@ public class Buffers { } /** + * Returns the size of a single element of this buffer in bytes. + */ + public static final int sizeOfBufferElem(Buffer buffer) { + if (buffer == null) { + return 0; + } + if (buffer instanceof ByteBuffer) { + return SIZEOF_BYTE; + } else if (buffer instanceof IntBuffer) { + return SIZEOF_INT; + } else if (buffer instanceof ShortBuffer) { + return SIZEOF_SHORT; + } else if (buffer instanceof FloatBuffer) { + return SIZEOF_FLOAT; + } else if (Platform.isJavaSE()) { + if (buffer instanceof DoubleBuffer) { + return SIZEOF_DOUBLE; + } else if (buffer instanceof LongBuffer) { + return SIZEOF_LONG; + } else if (buffer instanceof CharBuffer) { + return SIZEOF_CHAR; + } + } + throw new RuntimeException("Unexpected buffer type " + buffer.getClass().getName()); + } + + /** * Helper routine to tell whether a buffer is direct or not. Null * pointers are considered NOT direct. isDirect() should really be * public in Buffer and not replicated in all subclasses. @@ -283,8 +310,7 @@ public class Buffers { return pointerBuffer.position() * PointerBuffer.elementSize(); } - throw new RuntimeException("Disallowed array backing store type in buffer " - + buf.getClass().getName()); + throw new RuntimeException("Disallowed array backing store type in buffer " + buf.getClass().getName()); } /** @@ -315,8 +341,7 @@ public class Buffers { } } - throw new RuntimeException("Disallowed array backing store type in buffer " - + buf.getClass().getName()); + throw new RuntimeException("Disallowed array backing store type in buffer " + buf.getClass().getName()); } /** |