Re: Performance Issues with VBOs
Posted by bgroenks96 on Dec 31, 2013; 4:16pm
URL: https://forum.jogamp.org/Performance-Issues-with-VBOs-tp4031089p4031096.html
Ok I ditched the buffer mapping and used glBufferSubData instead. This time, I got it to work. I think the problems before were either due to FloatBuffer byte ordering or lack of a call to Buffer.flip()
int buffSize = 8 * Buffers.SIZEOF_FLOAT;
if(texBound && texEnabled)
buffSize *= 2;
gl.glBindBuffer(GL_ARRAY_BUFFER, rectBuffId);
gl.glBufferData(GL_ARRAY_BUFFER, buffSize, null, usage.usage);
FloatBuffer floatBuff = Buffers.newDirectByteBuffer(buffSize).asFloatBuffer();
floatBuff.put(x); floatBuff.put(y);
floatBuff.put(x); floatBuff.put(y + ht);
floatBuff.put(x + wt); floatBuff.put(y);
floatBuff.put(x + wt); floatBuff.put(y + ht);
if(texBound && texEnabled)
floatBuff.put(texCoords);
floatBuff.flip();
gl.glBufferSubData(GL_ARRAY_BUFFER, 0, buffSize, floatBuff);
This gets me to about ~740 FPS, which is better than the original mapping code but worse than when GL_READ_WRITE was used.
I'm going to try rewriting some of the abstraction code to allow for more control over the buffer allocation process. The code above is being called every frame 100 times (100 objects) with each object also having the 'draw' method called. It seems to me because of how VBOs work that maybe it would be more efficient to allocate a big VBO that can hold all of the vertex data for all 100 objects, then draw them all at once.