diff options
Diffstat (limited to 'src/net/java/games/gluegen/runtime')
-rw-r--r-- | src/net/java/games/gluegen/runtime/BufferFactory.java | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/net/java/games/gluegen/runtime/BufferFactory.java b/src/net/java/games/gluegen/runtime/BufferFactory.java index 2efb78ca6..67ffea1d8 100644 --- a/src/net/java/games/gluegen/runtime/BufferFactory.java +++ b/src/net/java/games/gluegen/runtime/BufferFactory.java @@ -47,4 +47,29 @@ public class BufferFactory { buf.order(ByteOrder.nativeOrder()); return buf; } + + /** Helper routine to tell whether a buffer is direct or not. Null + pointers are considered direct. isDirect() should really be + public in Buffer and not replicated in all subclasses. */ + public static boolean isDirect(Buffer buf) { + if (buf == null) { + return true; + } + if (buf instanceof ByteBuffer) { + return ((ByteBuffer) buf).isDirect(); + } else if (buf instanceof FloatBuffer) { + return ((FloatBuffer) buf).isDirect(); + } else if (buf instanceof DoubleBuffer) { + return ((DoubleBuffer) buf).isDirect(); + } else if (buf instanceof CharBuffer) { + return ((CharBuffer) buf).isDirect(); + } else if (buf instanceof ShortBuffer) { + return ((ShortBuffer) buf).isDirect(); + } else if (buf instanceof IntBuffer) { + return ((IntBuffer) buf).isDirect(); + } else if (buf instanceof LongBuffer) { + return ((LongBuffer) buf).isDirect(); + } + throw new RuntimeException("Unknown buffer type " + buf.getClass().getName()); + } } |