use of java.nio.DoubleBuffer in project robovm by robovm.
the class MachineSizedFloatPtr method set.
/**
* Copies {@code count} floats from {@code src} starting at offset {@code offset}
* to the memory pointed to by this {@link MachineSizedFloatPtr}. Does
* {@code float} to {@code double} conversion if running on a 64-bit
* platform.
*
* @param src the source.
* @param offset the offset within the source array to start copying from.
* @param count the number of elements to copy.
*/
public void set(float[] src, int offset, int count) {
if (_sizeOf() == 4) {
asFloatBuffer(count).put(src, offset, count);
} else {
Arrays.checkOffsetAndCount(src.length, offset, count);
DoubleBuffer buf = asDoubleBuffer(count);
for (int i = 0; i < count; i++) {
buf.put(src[i + offset]);
}
}
}
use of java.nio.DoubleBuffer in project spaceships-demo by puniverse.
the class VAO method setVertex.
public void setVertex(GL3 gl, String attributeName, VBO vbo) {
vbo.bind(gl);
final int location = getLocation(gl, attributeName);
gl.glEnableVertexAttribArray(location);
if (vbo.getBuffer() instanceof FloatBuffer)
gl.glVertexAttribPointer(location, vbo.getComponents(), vbo.getComponentType(), vbo.isNormalized(), vbo.getStride(), 0);
else if (vbo.getBuffer() instanceof IntBuffer)
gl.glVertexAttribIPointer(location, vbo.getComponents(), vbo.getComponentType(), vbo.getStride(), 0);
else if (vbo.getBuffer() instanceof DoubleBuffer)
gl.glVertexAttribPointer(location, vbo.getComponents(), vbo.getComponentType(), false, vbo.getStride(), 0);
else
throw new GLException("Unrecognized buffer type: " + vbo.getBuffer().getClass().getName());
}
use of java.nio.DoubleBuffer in project playn by threerings.
the class JavaGL20 method glBufferData.
@Override
public void glBufferData(int target, int size, Buffer data, int usage) {
if (data == null) {
GL15.glBufferData(target, size, usage);
return;
}
// Limit the buffer to the given size, restoring it afterwards
int oldLimit = data.limit();
if (data instanceof ByteBuffer) {
ByteBuffer subData = (ByteBuffer) data;
subData.limit(subData.position() + size);
GL15.glBufferData(target, subData, usage);
} else if (data instanceof IntBuffer) {
IntBuffer subData = (IntBuffer) data;
subData.limit(subData.position() + size / 4);
GL15.glBufferData(target, subData, usage);
} else if (data instanceof FloatBuffer) {
FloatBuffer subData = (FloatBuffer) data;
subData.limit(subData.position() + size / 4);
GL15.glBufferData(target, subData, usage);
} else if (data instanceof DoubleBuffer) {
DoubleBuffer subData = (DoubleBuffer) data;
subData.limit(subData.position() + size / 8);
GL15.glBufferData(target, subData, usage);
} else if (data instanceof ShortBuffer) {
ShortBuffer subData = (ShortBuffer) data;
subData.limit(subData.position() + size / 2);
GL15.glBufferData(target, subData, usage);
}
data.limit(oldLimit);
}
use of java.nio.DoubleBuffer in project playn by threerings.
the class JavaGL20 method glBufferSubData.
@Override
public void glBufferSubData(int target, int offset, int size, Buffer data) {
// Limit the buffer to the given size, restoring it afterwards
int oldLimit = data.limit();
if (data instanceof ByteBuffer) {
ByteBuffer subData = (ByteBuffer) data;
subData.limit(subData.position() + size);
GL15.glBufferSubData(target, offset, subData);
} else if (data instanceof IntBuffer) {
IntBuffer subData = (IntBuffer) data;
subData.limit(subData.position() + size / 4);
GL15.glBufferSubData(target, offset, subData);
} else if (data instanceof FloatBuffer) {
FloatBuffer subData = (FloatBuffer) data;
subData.limit(subData.position() + size / 4);
GL15.glBufferSubData(target, offset, subData);
} else if (data instanceof DoubleBuffer) {
DoubleBuffer subData = (DoubleBuffer) data;
subData.limit(subData.position() + size / 8);
GL15.glBufferSubData(target, offset, subData);
} else if (data instanceof ShortBuffer) {
ShortBuffer subData = (ShortBuffer) data;
subData.limit(subData.position() + size / 2);
GL15.glBufferSubData(target, offset, subData);
}
data.limit(oldLimit);
}
use of java.nio.DoubleBuffer in project android_frameworks_base by ParanoidAndroid.
the class GLLogWrapper method toByteBuffer.
private ByteBuffer toByteBuffer(int byteCount, Buffer input) {
ByteBuffer result = null;
boolean convertWholeBuffer = (byteCount < 0);
if (input instanceof ByteBuffer) {
ByteBuffer input2 = (ByteBuffer) input;
int position = input2.position();
if (convertWholeBuffer) {
byteCount = input2.limit() - position;
}
result = ByteBuffer.allocate(byteCount).order(input2.order());
for (int i = 0; i < byteCount; i++) {
result.put(input2.get());
}
input2.position(position);
} else if (input instanceof CharBuffer) {
CharBuffer input2 = (CharBuffer) input;
int position = input2.position();
if (convertWholeBuffer) {
byteCount = (input2.limit() - position) * 2;
}
result = ByteBuffer.allocate(byteCount).order(input2.order());
CharBuffer result2 = result.asCharBuffer();
for (int i = 0; i < byteCount / 2; i++) {
result2.put(input2.get());
}
input2.position(position);
} else if (input instanceof ShortBuffer) {
ShortBuffer input2 = (ShortBuffer) input;
int position = input2.position();
if (convertWholeBuffer) {
byteCount = (input2.limit() - position) * 2;
}
result = ByteBuffer.allocate(byteCount).order(input2.order());
ShortBuffer result2 = result.asShortBuffer();
for (int i = 0; i < byteCount / 2; i++) {
result2.put(input2.get());
}
input2.position(position);
} else if (input instanceof IntBuffer) {
IntBuffer input2 = (IntBuffer) input;
int position = input2.position();
if (convertWholeBuffer) {
byteCount = (input2.limit() - position) * 4;
}
result = ByteBuffer.allocate(byteCount).order(input2.order());
IntBuffer result2 = result.asIntBuffer();
for (int i = 0; i < byteCount / 4; i++) {
result2.put(input2.get());
}
input2.position(position);
} else if (input instanceof FloatBuffer) {
FloatBuffer input2 = (FloatBuffer) input;
int position = input2.position();
if (convertWholeBuffer) {
byteCount = (input2.limit() - position) * 4;
}
result = ByteBuffer.allocate(byteCount).order(input2.order());
FloatBuffer result2 = result.asFloatBuffer();
for (int i = 0; i < byteCount / 4; i++) {
result2.put(input2.get());
}
input2.position(position);
} else if (input instanceof DoubleBuffer) {
DoubleBuffer input2 = (DoubleBuffer) input;
int position = input2.position();
if (convertWholeBuffer) {
byteCount = (input2.limit() - position) * 8;
}
result = ByteBuffer.allocate(byteCount).order(input2.order());
DoubleBuffer result2 = result.asDoubleBuffer();
for (int i = 0; i < byteCount / 8; i++) {
result2.put(input2.get());
}
input2.position(position);
} else if (input instanceof LongBuffer) {
LongBuffer input2 = (LongBuffer) input;
int position = input2.position();
if (convertWholeBuffer) {
byteCount = (input2.limit() - position) * 8;
}
result = ByteBuffer.allocate(byteCount).order(input2.order());
LongBuffer result2 = result.asLongBuffer();
for (int i = 0; i < byteCount / 8; i++) {
result2.put(input2.get());
}
input2.position(position);
} else {
throw new RuntimeException("Unimplemented Buffer subclass.");
}
result.rewind();
// The OpenGL API will interpret the result in hardware byte order,
// so we better do that as well:
result.order(ByteOrder.nativeOrder());
return result;
}
Aggregations