* 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
This commit is contained in:
parent
fd03d28d81
commit
b007fd672a
@ -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;
|
||||
|
||||
/**
|
||||
* <code>IndexBuffer</code> 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.
|
||||
|
@ -45,7 +45,8 @@ public class IndexByteBuffer extends IndexBuffer {
|
||||
private ByteBuffer buf;
|
||||
|
||||
public IndexByteBuffer(ByteBuffer buffer) {
|
||||
this.buf = buffer;
|
||||
buf = buffer;
|
||||
buf.rewind();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -45,7 +45,8 @@ public class IndexIntBuffer extends IndexBuffer {
|
||||
private IntBuffer buf;
|
||||
|
||||
public IndexIntBuffer(IntBuffer buffer) {
|
||||
this.buf = buffer;
|
||||
buf = buffer;
|
||||
buf.rewind();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -45,7 +45,8 @@ public class IndexShortBuffer extends IndexBuffer {
|
||||
private ShortBuffer buf;
|
||||
|
||||
public IndexShortBuffer(ShortBuffer buffer) {
|
||||
this.buf = buffer;
|
||||
buf = buffer;
|
||||
buf.rewind();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
x
Reference in New Issue
Block a user