Code cleanup.
This commit is contained in:
parent
30261d1f82
commit
8193447a0d
|
@ -50,20 +50,29 @@ final class APIUtil {
|
||||||
|
|
||||||
private static final int BUFFERS_SIZE = 32;
|
private static final int BUFFERS_SIZE = 32;
|
||||||
|
|
||||||
private char[] arrayTL;
|
private char[] array;
|
||||||
private ByteBuffer bufferTL;
|
private ByteBuffer buffer;
|
||||||
private IntBuffer lengthsTL;
|
private IntBuffer lengths;
|
||||||
private final Buffers buffersTL;
|
|
||||||
|
private final IntBuffer ints;
|
||||||
|
private final LongBuffer longs;
|
||||||
|
private final FloatBuffer floats;
|
||||||
|
private final DoubleBuffer doubles;
|
||||||
|
|
||||||
APIUtil() {
|
APIUtil() {
|
||||||
arrayTL = new char[INITIAL_BUFFER_SIZE];
|
array = new char[INITIAL_BUFFER_SIZE];
|
||||||
bufferTL = BufferUtils.createByteBuffer(INITIAL_BUFFER_SIZE);
|
buffer = BufferUtils.createByteBuffer(INITIAL_BUFFER_SIZE);
|
||||||
lengthsTL = BufferUtils.createIntBuffer(INITIAL_LENGTHS_SIZE);
|
lengths = BufferUtils.createIntBuffer(INITIAL_LENGTHS_SIZE);
|
||||||
buffersTL = new Buffers();
|
|
||||||
|
ints = BufferUtils.createIntBuffer(BUFFERS_SIZE);
|
||||||
|
longs = BufferUtils.createLongBuffer(BUFFERS_SIZE);
|
||||||
|
|
||||||
|
floats = BufferUtils.createFloatBuffer(BUFFERS_SIZE);
|
||||||
|
doubles = BufferUtils.createDoubleBuffer(BUFFERS_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static char[] getArray(final ContextCapabilities caps, final int size) {
|
private static char[] getArray(final ContextCapabilities caps, final int size) {
|
||||||
char[] array = caps.util.arrayTL;
|
char[] array = caps.util.array;
|
||||||
|
|
||||||
if ( array.length < size ) {
|
if ( array.length < size ) {
|
||||||
int sizeNew = array.length << 1;
|
int sizeNew = array.length << 1;
|
||||||
|
@ -71,14 +80,14 @@ final class APIUtil {
|
||||||
sizeNew <<= 1;
|
sizeNew <<= 1;
|
||||||
|
|
||||||
array = new char[size];
|
array = new char[size];
|
||||||
caps.util.arrayTL = array;
|
caps.util.array = array;
|
||||||
}
|
}
|
||||||
|
|
||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ByteBuffer getBufferByte(final ContextCapabilities caps, final int size) {
|
static ByteBuffer getBufferByte(final ContextCapabilities caps, final int size) {
|
||||||
ByteBuffer buffer = caps.util.bufferTL;
|
ByteBuffer buffer = caps.util.buffer;
|
||||||
|
|
||||||
if ( buffer.capacity() < size ) {
|
if ( buffer.capacity() < size ) {
|
||||||
int sizeNew = buffer.capacity() << 1;
|
int sizeNew = buffer.capacity() << 1;
|
||||||
|
@ -86,7 +95,7 @@ final class APIUtil {
|
||||||
sizeNew <<= 1;
|
sizeNew <<= 1;
|
||||||
|
|
||||||
buffer = BufferUtils.createByteBuffer(size);
|
buffer = BufferUtils.createByteBuffer(size);
|
||||||
caps.util.bufferTL = buffer;
|
caps.util.buffer = buffer;
|
||||||
} else
|
} else
|
||||||
buffer.clear();
|
buffer.clear();
|
||||||
|
|
||||||
|
@ -94,7 +103,7 @@ final class APIUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ByteBuffer getBufferByteOffset(final ContextCapabilities caps, final int size) {
|
private static ByteBuffer getBufferByteOffset(final ContextCapabilities caps, final int size) {
|
||||||
ByteBuffer buffer = caps.util.bufferTL;
|
ByteBuffer buffer = caps.util.buffer;
|
||||||
|
|
||||||
if ( buffer.capacity() < size ) {
|
if ( buffer.capacity() < size ) {
|
||||||
int sizeNew = buffer.capacity() << 1;
|
int sizeNew = buffer.capacity() << 1;
|
||||||
|
@ -103,7 +112,7 @@ final class APIUtil {
|
||||||
|
|
||||||
final ByteBuffer bufferNew = BufferUtils.createByteBuffer(size);
|
final ByteBuffer bufferNew = BufferUtils.createByteBuffer(size);
|
||||||
bufferNew.put(buffer);
|
bufferNew.put(buffer);
|
||||||
caps.util.bufferTL = (buffer = bufferNew);
|
caps.util.buffer = (buffer = bufferNew);
|
||||||
} else {
|
} else {
|
||||||
buffer.position(buffer.limit());
|
buffer.position(buffer.limit());
|
||||||
buffer.limit(buffer.capacity());
|
buffer.limit(buffer.capacity());
|
||||||
|
@ -112,22 +121,20 @@ final class APIUtil {
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ShortBuffer getBufferShort(final ContextCapabilities caps) { return caps.util.buffersTL.shorts; }
|
static IntBuffer getBufferInt(final ContextCapabilities caps) { return caps.util.ints; }
|
||||||
|
|
||||||
static IntBuffer getBufferInt(final ContextCapabilities caps) { return caps.util.buffersTL.ints; }
|
static LongBuffer getBufferLong(final ContextCapabilities caps) { return caps.util.longs; }
|
||||||
|
|
||||||
static LongBuffer getBufferLong(final ContextCapabilities caps) { return caps.util.buffersTL.longs; }
|
static FloatBuffer getBufferFloat(final ContextCapabilities caps) { return caps.util.floats; }
|
||||||
|
|
||||||
static FloatBuffer getBufferFloat(final ContextCapabilities caps) { return caps.util.buffersTL.floats; }
|
static DoubleBuffer getBufferDouble(final ContextCapabilities caps) { return caps.util.doubles; }
|
||||||
|
|
||||||
static DoubleBuffer getBufferDouble(final ContextCapabilities caps) { return caps.util.buffersTL.doubles; }
|
|
||||||
|
|
||||||
static IntBuffer getLengths(final ContextCapabilities caps) {
|
static IntBuffer getLengths(final ContextCapabilities caps) {
|
||||||
return getLengths(caps, 1);
|
return getLengths(caps, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static IntBuffer getLengths(final ContextCapabilities caps, final int size) {
|
static IntBuffer getLengths(final ContextCapabilities caps, final int size) {
|
||||||
IntBuffer lengths = caps.util.lengthsTL;
|
IntBuffer lengths = caps.util.lengths;
|
||||||
|
|
||||||
if ( lengths.capacity() < size ) {
|
if ( lengths.capacity() < size ) {
|
||||||
int sizeNew = lengths.capacity();
|
int sizeNew = lengths.capacity();
|
||||||
|
@ -135,7 +142,7 @@ final class APIUtil {
|
||||||
sizeNew <<= 1;
|
sizeNew <<= 1;
|
||||||
|
|
||||||
lengths = BufferUtils.createIntBuffer(size);
|
lengths = BufferUtils.createIntBuffer(size);
|
||||||
caps.util.lengthsTL = lengths;
|
caps.util.lengths = lengths;
|
||||||
} else
|
} else
|
||||||
lengths.clear();
|
lengths.clear();
|
||||||
|
|
||||||
|
@ -286,24 +293,4 @@ final class APIUtil {
|
||||||
return MemoryUtil.getAddress0(getBufferByte(caps, 0));
|
return MemoryUtil.getAddress0(getBufferByte(caps, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class Buffers {
|
|
||||||
|
|
||||||
final ShortBuffer shorts;
|
|
||||||
final IntBuffer ints;
|
|
||||||
final LongBuffer longs;
|
|
||||||
|
|
||||||
final FloatBuffer floats;
|
|
||||||
final DoubleBuffer doubles;
|
|
||||||
|
|
||||||
Buffers() {
|
|
||||||
shorts = BufferUtils.createShortBuffer(BUFFERS_SIZE);
|
|
||||||
ints = BufferUtils.createIntBuffer(BUFFERS_SIZE);
|
|
||||||
longs = BufferUtils.createLongBuffer(BUFFERS_SIZE);
|
|
||||||
|
|
||||||
floats = BufferUtils.createFloatBuffer(BUFFERS_SIZE);
|
|
||||||
doubles = BufferUtils.createDoubleBuffer(BUFFERS_SIZE);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -39,9 +39,12 @@ import org.lwjgl.PointerBuffer;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.FloatBuffer;
|
import java.nio.FloatBuffer;
|
||||||
import java.nio.IntBuffer;
|
import java.nio.IntBuffer;
|
||||||
import java.nio.ShortBuffer;
|
|
||||||
|
|
||||||
/** @author spasi */
|
/**
|
||||||
|
* Utility class for OpenGL ES API calls.
|
||||||
|
*
|
||||||
|
* @author spasi
|
||||||
|
*/
|
||||||
final class APIUtil {
|
final class APIUtil {
|
||||||
|
|
||||||
private static final int INITIAL_BUFFER_SIZE = 256;
|
private static final int INITIAL_BUFFER_SIZE = 256;
|
||||||
|
@ -138,14 +141,10 @@ final class APIUtil {
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ShortBuffer getBufferShort() { return buffersTL.get().shorts; }
|
|
||||||
|
|
||||||
static IntBuffer getBufferInt() { return buffersTL.get().ints; }
|
static IntBuffer getBufferInt() { return buffersTL.get().ints; }
|
||||||
|
|
||||||
static FloatBuffer getBufferFloat() { return buffersTL.get().floats; }
|
static FloatBuffer getBufferFloat() { return buffersTL.get().floats; }
|
||||||
|
|
||||||
static PointerBuffer getBufferPointer() { return buffersTL.get().pointers; }
|
|
||||||
|
|
||||||
static IntBuffer getLengths() {
|
static IntBuffer getLengths() {
|
||||||
return getLengths(1);
|
return getLengths(1);
|
||||||
}
|
}
|
||||||
|
@ -312,18 +311,12 @@ final class APIUtil {
|
||||||
|
|
||||||
private static class Buffers {
|
private static class Buffers {
|
||||||
|
|
||||||
final ShortBuffer shorts;
|
|
||||||
final IntBuffer ints;
|
final IntBuffer ints;
|
||||||
final FloatBuffer floats;
|
final FloatBuffer floats;
|
||||||
|
|
||||||
final PointerBuffer pointers;
|
|
||||||
|
|
||||||
Buffers() {
|
Buffers() {
|
||||||
shorts = BufferUtils.createShortBuffer(BUFFERS_SIZE);
|
|
||||||
ints = BufferUtils.createIntBuffer(BUFFERS_SIZE);
|
ints = BufferUtils.createIntBuffer(BUFFERS_SIZE);
|
||||||
floats = BufferUtils.createFloatBuffer(BUFFERS_SIZE);
|
floats = BufferUtils.createFloatBuffer(BUFFERS_SIZE);
|
||||||
|
|
||||||
pointers = BufferUtils.createPointerBuffer(BUFFERS_SIZE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue