glbuffersubdata with an offset into buffer, without causing garbage
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 (repl开发者_JAVA技巧ace 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.
looks like I've got the same Problem.
The only solution that came into my mind is to use the android ndk to create an alternative implementation of glBufferSubData, which adds the offset to the pointer (the one derived from mPositionBuffer) before passing it down to the actual opengl function.
This sounds too bad, I hope there is a better solution.
Well, i guess one could use a static buffer as a reference and has a slicer for the io operation. It wouldn't then call the garbage collecter has long has the class lives trough.
精彩评论