In our single-threaded OGL pipeline, we enqueue parameters for each rendering
operation onto a java.nio.ByteBuffer. For example, a fillRect() operation
currently looks like this:
buf.putInt(FILL_RECT);
buf.putInt(x).putInt(y).putInt(w).putInt(h);
We have a number of operations whose parameters consist entirely of integers (no floats, longs, etc). For these operations we can exploit the fact that we always keep the current buffer position aligned on a 4-byte boundary, and therefore use an IntBuffer view on the original ByteBuffer to enqueue those
int parameters. (In a microbenchmark, tested on both Solaris/SPARC and Linux,
I found that using IntBuffer.put() can be up to 3x faster than
ByteBuffer.putInt() when the buffer is in the native machine endianness.)
So for the above example, we would instead use:
IntBuffer ibuf = buf.asIntBuffer();
ibuf.put(FILL_RECT);
ibuf.put(x).put(y).put(w).put(h);
buf.position(buf.position() + 20);
###@###.### 2005-05-20 00:09:21 GMT