VBO manipulation

Started by w00tguy123, April 13, 2011, 02:38:59

Previous topic - Next topic

w00tguy123

I've created a huge VBO to hold thousands of cubes. How do I add, subtract, or change data in this VBO? Specifically, I want to add or subtract a cube at x,y,z. I'm very new to OpenGL and VBOs so even a conceptual answer will help.

I figure I'd bind the VBO, and then use glBufferSubData somehow, but I'm not sure how that would work since I used a ton of putFloat() commands when creating the VBO and I don't think those can be put into whatever a "const GLvoid *" is (void pointer in java?), which is the last argument of glBufferSubData.

w00tguy123

Well, I found out what I needed to do.
GL15.glBufferSubData(ARBVertexBufferObject.GL_ARRAY_BUFFER_ARB, 0, dataBuffer);
// define new verts


You have to bind the buffer and map it to a bytebuffer before calling this. The 0 means I'm replacing values starting from the beginning of the array.

Adding and subtracting data might be a little complex, especially since I cull unseen faces from each cube (if one is touching another). I suppose I need to work with the indices rather than the vertex data for this.

Edit: Attempting to sub data into my index buffer removes everything except for the few verts that i substituted... Anyone got and tutorials or links that deal with this kind of stuff? I'm just recreating the entire index buffer now but there's probably a better way.