diff options
Diffstat (limited to 'src/java/com/jogamp/common/nio/Buffers.java')
-rw-r--r-- | src/java/com/jogamp/common/nio/Buffers.java | 25 |
1 files changed, 24 insertions, 1 deletions
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 <code>0</code> if the given buffer is <code>null</code>. */ public static int sizeOfBufferElem(Buffer buffer) { if (buffer == null) { @@ -354,6 +355,28 @@ public class Buffers { } /** + * 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 <b>are</b> considered direct. */ |