From 35e932c32dad33693caa249a8139708412e8d798 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Sat, 27 Apr 2013 06:42:36 +0200 Subject: Buffers: Add 'sizeOfBufferType(Class bufferType)' --- src/java/com/jogamp/common/nio/Buffers.java | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/java/com/jogamp/common/nio/Buffers.java b/src/java/com/jogamp/common/nio/Buffers.java index 22647d7..2be7fd7 100644 --- a/src/java/com/jogamp/common/nio/Buffers.java +++ b/src/java/com/jogamp/common/nio/Buffers.java @@ -329,7 +329,8 @@ public class Buffers { } /** - * Returns the size of a single element of this buffer in bytes. + * Returns the size of a single element of the given buffer in bytes + * or 0 if the given buffer is null. */ public static int sizeOfBufferElem(Buffer buffer) { if (buffer == null) { @@ -353,6 +354,28 @@ public class Buffers { throw new RuntimeException("Unexpected buffer type " + buffer.getClass().getName()); } + /** + * Returns the size of a single element of given buffer type in bytes. + */ + public static int sizeOfBufferType(Class bufferType) { + if (ByteBuffer.class.isInstance(bufferType)) { + return SIZEOF_BYTE; + } else if (IntBuffer.class.isInstance(bufferType)) { + return SIZEOF_INT; + } else if (ShortBuffer.class.isInstance(bufferType)) { + return SIZEOF_SHORT; + } else if (FloatBuffer.class.isInstance(bufferType)) { + return SIZEOF_FLOAT; + } else if (DoubleBuffer.class.isInstance(bufferType)) { + return SIZEOF_DOUBLE; + } else if (LongBuffer.class.isInstance(bufferType)) { + return SIZEOF_LONG; + } else if (CharBuffer.class.isInstance(bufferType)) { + return SIZEOF_CHAR; + } + throw new RuntimeException("Unexpected buffer type " + bufferType.getName()); + } + /** * Helper routine to tell whether a buffer is direct or not. Null * pointers are considered direct. -- cgit v1.2.3