I’ve recently updated my app to use VBOs for vertex data, normals, colors, and vertex indexes.
I keep those VBOs bound, and the glVertexPointer/glNormalPointer/glColorPointer/indexes vertex pointers pointing to the data in the VBO. I’ve built a display list that draws my app’s polygon mesh using a series of calls to glDrawRangeElements().
Everything works beautifully until I need to change the vertex/normal data or the color data for my mesh.
When I need to update the mesh data, I set a rebuild_mesh flag. Then, in my draw routine, I update the mesh data in main memory. The new VBO code then tries to copy the updated vertex/normal data to the VBO using the call glBufferSubData.
Here’s the code I use to try to update the data for my vertex/normal VBOs:
glBindBuffer(GL_ARRAY_BUFFER, VBO_buffers[vertexes]);
unsigned long malloc_size = sizeof(GLfloat) * mesh_w * mesh_h * 3;
glBufferSubData(GL_ARRAY_BUFFER, 0, malloc_size, meshVertices);
glBindBuffer(GL_ARRAY_BUFFER, VBO_buffers[normals]);
glBufferSubData(GL_ARRAY_BUFFER, 0, malloc_size, meshNormals);
The code is instrumented to check for errors after each call (those calls were removed above for clarity.) I’m not getting any errors.
At the first glBufferSubData call, the machine goes to the Bahamas and doesn’t leave a forwarding address. (It stops responding to user input. Background processes continue to run, but nothing happens on the screen.) I have to do a forced shutdown in order to recover.
I’ve verified that the values being passed in are valid, and that my vertex and normals arrays are intact.
Is there some housekeeping I need to do before calling glBufferSubData, or is there some state in which this call is illegal?
Am I getting into trouble because my VBO is referenced by a display list? Do I need to delete the display list before updating the vertex data? I’m stumped.