OpenGL-ES 2.0 glCopyBufferSubData alternative

85 Views Asked by At

Due to a downgrade in my project's hardware I need to switch from OpenGL-ES 3.2 to OpenGL 2.0.

The feature that I'm struggling with is glCopyBufferSubData, which allows you to copy data between 2 VBO's.

The problem that I'm facing is that I have meshes that dynamically grow, and it's impossible to tell how big they will get from the start. So I have to sometimes expand the VBO buffers in increments, for example once every 100 vertexes I would allocate space for another 100.

Here's how I used to do that (Java LWJGL code):

// Input:
// buffer - an empty buffer object of new expanded size
// vertexCount - number of vertexes currently written into the old buffer
public void reCreate(FloatBuffer buffer, int vertexCount)
    {
        glBindBuffer(GL_COPY_READ_BUFFER, ID);

        int newVboID = glGenBuffers();
        glBindBuffer(GL_ARRAY_BUFFER, newVboID);

        // allocates new memory for the new VBO
        glBufferData(GL_ARRAY_BUFFER, buffer, GL_STATIC_DRAW);

        // copy data from old VBO to new
        glCopyBufferSubData(GL_COPY_READ_BUFFER, GL_ARRAY_BUFFER, 0, 0, vertexCount * FLOAT_SIZE);

        // replace VBO ID and delete the old VBO
        glDeleteBuffers(ID);
        ID = newVboID;

        // unbind buffers
        glBindBuffer(GL_COPY_READ_BUFFER, 0);
        glBindBuffer(GL_ARRAY_BUFFER, 0);
    }

How can I achieve the same goal in 2.0? I.e. basically allocating more memory for VBO data array? The only way I can think of is to read data from VBO into the client application and then just create a new VBO with that data. But that's gonna be very slow.

Oh, I also can't keep the data client-side (to avoid reading from VBO) because of memory concerns. It's too much.

0

There are 0 best solutions below