G'day,
I'm trying to update part of a VBO with a call to glBufferSubData(). When I update from the start (0) of my existing shadow buffer, there is no problem, as the buffer starts reading from 0. The following will read 0 to y from the buffer and place it at 0 to y in the VBO:
gl.glBufferSubData(GL11.GL_ARRAY_BUFFER, 0, y, mPositionBuffer);
However, if I want to update a portion of the VBO (not from 0) I run into a problem; The following doesn't work, since it will write the values from the start of the buffer (0 to y) into position x to x+y of the VBO:
gl.glBufferSubData(GL11.GL_ARRAY_BUFFER, x, y, mPositionBuffer);
Changing the position using buffer.position(x) does not have any effect:
gl.glBufferSubData(GL11.GL_ARRAY_BUFFER, x, y, mPositionBuffer.position(x));
A solution is to slice() the buffer, which works great:
mPositionBuffer.position(x);
gl.glBufferSubData(GL11.GL_ARRAY_BUFFER, x, y, mPositionBuffer.slice());
But this causes garbage since a new buffer is generated by using slice, even though it uses the same data store.
The question: Is there a way to get the desired result (replace an offset part of a VBO using an offset into a buffer) without generating garbage? As you probably guessed, this is for an android game and in-game garbage collection is a no-no.
Thanks! Aert.