Re: Poll: does anyone using java3d use the J3DBuffer API?
Posted by InteractiveMesh on Feb 28, 2013; 6:13pm
URL: https://forum.jogamp.org/Poll-does-anyone-using-java3d-use-the-J3DBuffer-API-tp4028335p4028414.html
Java 3D 1.5.2 compatible loader and importer will be affected if they support J3DBuffer (e.g. InteractiveMesh's X3D importer and possibly others in work).
J3D's J3DBuffer class is now independent of the utilities package and is implemented as follows. A few classes have to be adapted according to the changed API.
public class J3DBuffer {
/**
* Type of the wrapped NIO buffer object.
*/
public static enum BufferType {
/**
* Specifies a J3DBuffer object with a null NIO buffer object.
*/
NULL,
/**
* Specifies a J3DBuffer object with a wrapped NIO ByteBuffer object.
*/
BYTE,
// CHAR,
/**
* Specifies a J3DBuffer object with a wrapped NIO DoubleBuffer object.
*/
DOUBLE,
/**
* Specifies a J3DBuffer object with a wrapped NIO FloatBuffer object.
*/
FLOAT,
// INT,
// LONG,
// SHORT;
}
private Buffer originalBuffer = null;
private Buffer readOnlyBuffer = null;
private BufferType bufferType = BufferType.NULL;
/**
* Constructs a J3DBuffer object and initializes it with
* a null NIO buffer object. The NIO buffer object
* must be set to a non-null value before using this J3DBuffer
* object in a J3D node component.
*/
public J3DBuffer() {
this(null);
}
/**
* Constructs a J3DBuffer object and initializes it with
* the specified NIO buffer object.
*
* @param buffer the NIO buffer wrapped by this J3DBuffer
*
* @exception IllegalArgumentException if the specified buffer is
* neither of type ByteBuffer, DoubleBuffer, nor FloatBuffer, or
* not a direct buffer, or if the byte order of the specified
* buffer does not match the native byte order of the underlying
* platform.
*/
public J3DBuffer(Buffer buffer) {
setBuffer(buffer);
}
/**
* Sets the NIO buffer object in this J3DBuffer to
* the specified object.
*
* @param buffer the NIO buffer wrapped by this J3DBuffer
*
* @exception IllegalArgumentException if the specified buffer is
* neither of type ByteBuffer, DoubleBuffer, nor FloatBuffer, or
* not a direct buffer, or if the byte order of the specified
* buffer does not match the native byte order of the underlying
* platform.
*/
public void setBuffer(Buffer buffer) {
BufferType bType = BufferType.NULL;
boolean direct = false;
ByteOrder order = ByteOrder.BIG_ENDIAN;
if (buffer instanceof ByteBuffer) {
bType = BufferType.BYTE;
direct = ((ByteBuffer)buffer).isDirect();
order = ((ByteBuffer)buffer).order();
}
else if (buffer instanceof FloatBuffer) {
bType = BufferType.FLOAT;
direct = ((FloatBuffer)buffer).isDirect();
order = ((FloatBuffer)buffer).order();
}
else if (buffer instanceof DoubleBuffer) {
bType = BufferType.DOUBLE;
direct = ((DoubleBuffer)buffer).isDirect();
order = ((DoubleBuffer)buffer).order();
}
// Verify that the buffer is direct and has the correct byte order
if (buffer != null) {
if (bType == BufferType.NULL) {
throw new IllegalArgumentException(J3dI18N.getString("J3DBuffer3"));
}
if (!direct) {
throw new IllegalArgumentException(J3dI18N.getString("J3DBuffer1"));
}
if (order != ByteOrder.nativeOrder()) {
throw new IllegalArgumentException(J3dI18N.getString("J3DBuffer2"));
}
}
bufferType = bType;
originalBuffer = buffer;
// Make a read-only view of the buffer if the type is one
// of the internally supported types: byte, float, or double
switch (bufferType) {
case BYTE:
readOnlyBuffer = ((ByteBuffer)buffer).asReadOnlyBuffer();
readOnlyBuffer.rewind();
break;
case FLOAT:
readOnlyBuffer = ((FloatBuffer)buffer).asReadOnlyBuffer();
readOnlyBuffer.rewind();
break;
case DOUBLE:
readOnlyBuffer = ((DoubleBuffer)buffer).asReadOnlyBuffer();
readOnlyBuffer.rewind();
break;
default:
readOnlyBuffer = null;
}
}
/**
* Retrieves the wrapped NIO buffer object from this J3DBuffer.
* @return the current NIO buffer wrapped by this J3DBuffer
*/
public Buffer getBuffer() {
return originalBuffer;
}
Buffer getReadOnlyBuffer() {
return readOnlyBuffer;
}
/**
* Retrieves the read-only view of the wrapped NIO byte buffer.
* @return the read-only view of the wrapped byte buffer
* @throws ClassCastException if the wrapped buffer is not of type <code>BufferType.BYTE</code>
*/
public ByteBuffer getByteBuffer() {
return (ByteBuffer)readOnlyBuffer;
}
/**
* Retrieves the read-only view of the wrapped NIO double buffer.
* @return the read-only view of the wrapped double buffer
* @throws ClassCastException if the wrapped buffer is not of type <code>BufferType.DOUBLE</code>
*/
public DoubleBuffer getDoubleBuffer() {
return (DoubleBuffer)readOnlyBuffer;
}
/**
* Retrieves the read-only view of the wrapped NIO float buffer.
* @return the read-only view of the wrapped float buffer
* @throws ClassCastException if the wrapped buffer is not of type <code>BufferType.FLOAT</code>
*/
public FloatBuffer getFloatBuffer() {
return (FloatBuffer)readOnlyBuffer;
}
/**
* Retrieves the type of the wrapped NIO buffer.
* @return the type of the wrapped buffer
*/
public BufferType getBufferType() {
return bufferType;
}
}
Signed-off-by: August Lammersdorf <aldorf@interactivemesh.com>