aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2010-03-30 01:58:15 +0200
committerSven Gothel <[email protected]>2010-03-30 01:58:15 +0200
commitdadccfbd5641e08c4201ef58145f40d71b0ea76d (patch)
tree1ba26c4c19b2ac2c65807ea41ea7849df5adb4e0
parent7220416bcef3140883d3966d921442feae3107c4 (diff)
parentdf0f47b18178c03a8c56d3e3d6b481769f3f1a30 (diff)
Merge branch 'master' of github.com:mbien/gluegen
-rwxr-xr-xsrc/java/com/jogamp/gluegen/runtime/Buffers.java35
1 files changed, 30 insertions, 5 deletions
diff --git a/src/java/com/jogamp/gluegen/runtime/Buffers.java b/src/java/com/jogamp/gluegen/runtime/Buffers.java
index 96c9430..49f6e8b 100755
--- a/src/java/com/jogamp/gluegen/runtime/Buffers.java
+++ b/src/java/com/jogamp/gluegen/runtime/Buffers.java
@@ -55,7 +55,7 @@ public class Buffers {
public static final int SIZEOF_LONG = 8;
public static final int SIZEOF_DOUBLE = 8;
- private Buffers() {}
+ protected Buffers() {}
/**
* Allocates a new direct ByteBuffer with the specified number of
@@ -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.
@@ -288,8 +315,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());
}
/**
@@ -322,8 +348,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());
}
/**