Reputation:
I have a VBO that holds 4096 cubes, and I am wondering if I can edit the VBO to actually remove a cube. Here is my code for rendering my vbo (I know I am rendering it in the old fashion):
for (int y = 0; y < 16; y++) {
for (int x = 0; x < 16; x++) {
for (int z = 0; z < 16; z++) {
glPushMatrix();
glTranslatef(x, y, z);
glDrawArrays(GL_QUADS, 0, 24);
glPopMatrix();
}
}
}
glDisableClientState(GL_VERTEX_ARRAY);
Very simple. Now can I actually use a method to remove data from the vbo? Do I have to create a separate arraylist and add all the cubes to it and remove them from there? I am using LWJGL, I doubt that matters though.
Upvotes: 2
Views: 919
Reputation: 52082
I am wondering if I can edit the VBO to actually remove a cube.
glMapBuffer()
to get a writable pointer.
Swap the vertices you want to remove to the end of the VBO.
glUnmapBuffer()
to re-upload the VBO.
Make sure to reduce the count
argument to glDrawElements()
(or whatever you use) appropriately.
You can also get creative with glBufferSubData()
.
Upvotes: 1