diff options
author | Sven Gothel <[email protected]> | 2013-04-27 06:42:36 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2013-04-27 06:42:36 +0200 |
commit | 35e932c32dad33693caa249a8139708412e8d798 (patch) | |
tree | 9e7b94b0d917750419b16d6a390dfc4dad624999 /src/java | |
parent | 5039f22bf0a89d658f613d14000e71be4e27f56a (diff) |
Buffers: Add 'sizeOfBufferType(Class<?> bufferType)'
Diffstat (limited to 'src/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. */ |