summaryrefslogtreecommitdiffstats
path: root/src/java/com/jogamp/gluegen
diff options
context:
space:
mode:
Diffstat (limited to 'src/java/com/jogamp/gluegen')
-rwxr-xr-xsrc/java/com/jogamp/gluegen/runtime/Buffers.java33
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());
}
/**