Direct Buffer
//package org.glscene.util;
import java.io.Serializable;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import javax.microedition.khronos.opengles.GL10;
interface DirectBufferable {
public void putInto(ByteBuffer buffer);
}
abstract class DirectBuffer implements Serializable {
public static final long serialVersionUID = 1L;
protected transient ByteBuffer fBuffer;
protected int fGLSize;
protected void allocate(int size) {
if (size == 0) {
fBuffer = null;
} else {
fBuffer = ByteBuffer.allocateDirect(size);
fBuffer.order(ByteOrder.nativeOrder());
}
}
protected void put(DirectBufferable aBufferable) {
aBufferable.putInto(fBuffer);
fBuffer.position(0);
}
abstract public int GLType();
public boolean empty() {
return (fBuffer != null);
}
public int size() {
if (fBuffer == null) {
return 0;
} else {
return (fBuffer.capacity() >> 2);
}
}
public void glVertexPointer(GL10 gl) {
gl.glVertexPointer(fGLSize, GLType(), 0, fBuffer);
}
public void glVertexPointer(GL10 gl, int size, int stride) {
gl.glVertexPointer(size, GLType(), stride, fBuffer);
}
public void glNormalPointer(GL10 gl) {
gl.glNormalPointer(GLType(), 0, fBuffer);
}
public void glNormalPointer(GL10 gl, int stride) {
gl.glNormalPointer(GLType(), stride, fBuffer);
}
public void glColorPointer(GL10 gl) {
gl.glColorPointer(fGLSize, GLType(), 0, fBuffer);
}
public void glColorPointer(GL10 gl, int size, int stride) {
gl.glColorPointer(size, GLType(), stride, fBuffer);
}
public void glTexCoordPointer(GL10 gl) {
gl.glTexCoordPointer(fGLSize, GLType(), 0, fBuffer);
}
public void glTexCoordPointer(GL10 gl, int size, int stride) {
gl.glTexCoordPointer(size, GLType(), stride, fBuffer);
}
}
Related examples in the same category