From df0f47b18178c03a8c56d3e3d6b481769f3f1a30 Mon Sep 17 00:00:00 2001 From: Michael Bien Date: Mon, 29 Mar 2010 15:37:41 +0200 Subject: added sizeOfBufferElem(Buffer buf) to Buffers. --- src/java/com/jogamp/gluegen/runtime/Buffers.java | 33 +++++++++++++++++++++--- 1 file changed, 29 insertions(+), 4 deletions(-) (limited to 'src/java/com/jogamp/gluegen') 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 @@ -219,6 +219,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 @@ -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()); } /** -- cgit v1.2.3