OSDN Git Service

add IndexBuffer#wrapIndexBuffer
authorkobayasi <kobayasi@pscnet.co.jp>
Sat, 6 Jul 2013 15:18:59 +0000 (00:18 +0900)
committerkobayasi <kobayasi@pscnet.co.jp>
Sat, 6 Jul 2013 15:18:59 +0000 (00:18 +0900)
engine/src/core/com/jme3/scene/mesh/IndexBuffer.java

index 5c41c04..a67bb67 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009-2010 jMonkeyEngine
+ * Copyright (c) 2009-2012 jMonkeyEngine
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
-
 package com.jme3.scene.mesh;
 
 import com.jme3.util.BufferUtils;
 import java.nio.Buffer;
+import java.nio.ByteBuffer;
+import java.nio.IntBuffer;
+import java.nio.ShortBuffer;
 
 /**
  * <code>IndexBuffer</code> is an abstraction for integer index buffers,
@@ -44,6 +46,18 @@ import java.nio.Buffer;
  */
 public abstract class IndexBuffer {
     
+    public static IndexBuffer wrapIndexBuffer(Buffer buf) {
+        if (buf instanceof ByteBuffer) {
+            return new IndexByteBuffer((ByteBuffer) buf);
+        } else if (buf instanceof ShortBuffer) {
+            return new IndexShortBuffer((ShortBuffer) buf);
+        } else if (buf instanceof IntBuffer) {
+            return new IndexIntBuffer((IntBuffer) buf);
+        } else {
+            throw new UnsupportedOperationException("Index buffer type unsupported: "+ buf.getClass());
+        }
+    }
+    
     /**
      * Creates an index buffer that can contain the given amount
      * of vertices.