user1650305
user1650305

Reputation:

Deleting data out of a OpenGL VBO

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

Answers (1)

genpfault
genpfault

Reputation: 52082

I am wondering if I can edit the VBO to actually remove a cube.

  1. glMapBuffer() to get a writable pointer.

  2. Swap the vertices you want to remove to the end of the VBO.

  3. glUnmapBuffer() to re-upload the VBO.

  4. Make sure to reduce the count argument to glDrawElements() (or whatever you use) appropriately.

You can also get creative with glBufferSubData().

Upvotes: 1

Related Questions