From b007fd672acb71020680b095f77b29e7b545b1ce Mon Sep 17 00:00:00 2001 From: "Sha..rd" Date: Thu, 14 Jun 2012 00:52:04 +0000 Subject: [PATCH] * Added IndexBuffer.wrapIndexBuffer() for wrapping any buffer (convenience method) * All index buffers now rewind the buffer before allowing any read/write ops git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9493 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../src/core/com/jme3/scene/mesh/IndexBuffer.java | 15 +++++++++++++++ .../core/com/jme3/scene/mesh/IndexByteBuffer.java | 3 ++- .../core/com/jme3/scene/mesh/IndexIntBuffer.java | 3 ++- .../com/jme3/scene/mesh/IndexShortBuffer.java | 3 ++- 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/engine/src/core/com/jme3/scene/mesh/IndexBuffer.java b/engine/src/core/com/jme3/scene/mesh/IndexBuffer.java index 5c41c046b..3d02805f2 100644 --- a/engine/src/core/com/jme3/scene/mesh/IndexBuffer.java +++ b/engine/src/core/com/jme3/scene/mesh/IndexBuffer.java @@ -34,6 +34,9 @@ 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; /** * IndexBuffer is an abstraction for integer index buffers, @@ -44,6 +47,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. diff --git a/engine/src/core/com/jme3/scene/mesh/IndexByteBuffer.java b/engine/src/core/com/jme3/scene/mesh/IndexByteBuffer.java index fd3bec410..c35d73b37 100644 --- a/engine/src/core/com/jme3/scene/mesh/IndexByteBuffer.java +++ b/engine/src/core/com/jme3/scene/mesh/IndexByteBuffer.java @@ -45,7 +45,8 @@ public class IndexByteBuffer extends IndexBuffer { private ByteBuffer buf; public IndexByteBuffer(ByteBuffer buffer) { - this.buf = buffer; + buf = buffer; + buf.rewind(); } @Override diff --git a/engine/src/core/com/jme3/scene/mesh/IndexIntBuffer.java b/engine/src/core/com/jme3/scene/mesh/IndexIntBuffer.java index 336930191..f479c9795 100644 --- a/engine/src/core/com/jme3/scene/mesh/IndexIntBuffer.java +++ b/engine/src/core/com/jme3/scene/mesh/IndexIntBuffer.java @@ -45,7 +45,8 @@ public class IndexIntBuffer extends IndexBuffer { private IntBuffer buf; public IndexIntBuffer(IntBuffer buffer) { - this.buf = buffer; + buf = buffer; + buf.rewind(); } @Override diff --git a/engine/src/core/com/jme3/scene/mesh/IndexShortBuffer.java b/engine/src/core/com/jme3/scene/mesh/IndexShortBuffer.java index 5017e6fb4..0b07ac76a 100644 --- a/engine/src/core/com/jme3/scene/mesh/IndexShortBuffer.java +++ b/engine/src/core/com/jme3/scene/mesh/IndexShortBuffer.java @@ -45,7 +45,8 @@ public class IndexShortBuffer extends IndexBuffer { private ShortBuffer buf; public IndexShortBuffer(ShortBuffer buffer) { - this.buf = buffer; + buf = buffer; + buf.rewind(); } @Override