I’m trying to make an optimized draw path basically by instead of doing OpenGL draw calls immediately, storing the call in an intelligent way in memory, then at the end of the repaint have the buffer draw itself. It’ll take all its data, put it into 3 FloatBuffers per texture, and then draw it all to the screen.
But it’s pretty slow. If I draw 10,000 untextured quads to the screen using glRectf I get at least 60 fps (I have it limited at the moment) whereas throwing everything into a few FloatBuffers and then using glDrawArrays gets only around 20. Very slow for something that is supposed to be optimized.
After profiling it I was able to determine that most of the time is taken up creating the FloatBuffers. I try adding it via array batches to speed it up, but that doesn’t necessarily help. It takes about 10-40ms to add 10,000 quads (that’s 40,000 vertex values, 40,000 texcoord values, and 80,000 color values). When every update is supposed to take 16ms (for 60fps) that’s pretty intensely high.
Does anyone have any pointers for how to optimize this process? I do it like this:
- Call draw on a quad, creates an object that stores 3 arrays of Objects (Vertex2D, Vertex2D, Color4D) and adds it to the appropriate place in the buffer Collection.
- Compile all the separate draw objects that were created into 3 FloatBuffers per texture.
[list]
[li]Construct 3 FloatBuffers using BufferUtils.createFloatBuffer(size). - Turn the 3 arrays of Vertex2D etc objects into float[] arrays.
- Copy that array to the FloatBuffer with FloatBuffer.put().
- Repeat the above 2 for every object that has the same texture.
[/li]
- Call glDrawArrays on the buffers.
[/list]
The possible optimizations I can see would perhaps be to do one single FloatBuffer.put() per texture by combining everything into one big array and then copying them all over at once. Similarly, if I could somehow know how many things will be drawn beforehand (which I can’t) I can reuse buffers. Or perhaps I can just make 3 big buffers that I keep reusing and use the last param of glDrawArrays to limit how much is used each time.
I’m just not sure the best way to do this. Advice? Thanks.

Still takes around 5ms to fill all the buffers. There’s still some other stuff I can do to optimize this, but it honestly might not even make sense to bother.