下面列出了java.nio.Buffer#flip ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* @param newSize size required in bytes
*/
public void loadBufferData(Buffer buf, int newSize) {
boolean clear = false;
if (buf.position() != 0) {
log.debug("flip your buffer!");
buf.flip();
}
GLState.bindBuffer(target, id);
/* reuse memory allocated for vbo when possible and allocated
* memory is less then four times the new data */
if (!GLAdapter.NO_BUFFER_SUB_DATA && !clear &&
(size > newSize) && (size < newSize * 4)) {
gl.bufferSubData(target, 0, newSize, buf);
} else {
mBufferMemoryUsage += newSize - size;
size = newSize;
//GL.bufferData(target, size, buf, GL20.DYNAMIC_DRAW);
gl.bufferData(target, size, buf, GL.STATIC_DRAW);
}
}
/**
* Adapted from {@code com.google.common.io.CharStreams.toString()}.
*/
public static String toString(Reader reader) throws IOException {
if (reader == null) {
return null;
}
try {
StringBuilder to = new StringBuilder();
CharBuffer charBuf = CharBuffer.allocate(BUF_SIZE);
// must cast to super class Buffer otherwise break when running with java 11
Buffer buf = charBuf;
while (reader.read(charBuf) != -1) {
buf.flip();
to.append(charBuf);
buf.clear();
}
return to.toString();
} finally {
ensureClosed(reader);
}
}
private void readActivationEventsToBuffer(FileChannel activationEventsFileChannel, long eof, ByteBuffer byteBuffer) throws IOException {
Buffer buf = byteBuffer;
buf.clear();
long remaining = eof - activationEventsFileChannel.position();
activationEventsFileChannel.read(byteBuffer);
buf.flip();
if (remaining < buf.capacity()) {
buf.limit((int) remaining);
}
}
long startProcessingActivationEventsFile() throws IOException {
Buffer activationEventsBuffer = this.activationEventsBuffer;
if (activationEventsFileChannel.position() > 0) {
flushActivationEvents();
activationEventsBuffer.limit(0);
} else {
activationEventsBuffer.flip();
}
long eof = activationEventsFileChannel.position();
activationEventsFileChannel.position(0);
return eof;
}
static void nioBuffToGL(GL2GL3 gl, Renderer r, int bufferHandle, int itemSize, Buffer buff) {
buff.flip();
int size = buff.limit() * itemSize;
gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, bufferHandle);
gl.glBufferData(GL2GL3.GL_ARRAY_BUFFER, size, buff, GL2GL3.GL_STATIC_DRAW);
gl.glBindBuffer(GL2GL3.GL_ARRAY_BUFFER, 0);
r.usingVRAM(size);
}
private static void flipBuffer(Buffer buf) {
buf.flip();
}
static void flipBuffer(Buffer buffer) {
buffer.flip();
}
/**
* Flip the provided buffer.
* <p>
* This wrapper around {@link Buffer#flip()} is required because of
* incompatible ABI changes between Java 8 and 11. In Java 8, {@link ByteBuffer#flip()} returns
* a {@link Buffer}, whereas in Java 11, this method returns a {@link ByteBuffer}.
* <p>
* If this function is used, any object of {@link Buffer} (and subclasses) are first cast to
* {@link Buffer} objects, then flipped, thus avoiding the binary incompatibility.
*
* @param buffer The buffer to flip
*/
static void flip(Buffer buffer) {
buffer.flip();
}