When I update my vertex array on iOS in OpenGL 2.0, the original vertex data is staying on the screen -- ie the 1st flush is persistent (the initial set of points I sent down to the GPU gets rendered every frame), but the 2nd, 3rd, 4th, .. nth flushes all seem to overwrite the same memory.
So I'm doing:
vector<VertexType> rawDynamicData ;
glGenVertexArraysOES( 1, &va ) ; CHECK_GL ;
glBindVertexArrayOES( va ) ; CHECK_GL ;
glGenBuffers( 1, &vb ) ; CHECK_GL ;
glBindBuffer( GL_ARRAY_BUFFER, vb ) ; CHECK_GL ;
glBufferData( glBufferData(
GL_ARRAY_BUFFER, //Specifies the target buffer object.
rawDynamicData.size() * sizeof( VertexType ),
&rawDynamicData[0],
GL_DYNAMIC_DRAW // I plan to update the data every frame
) ; CHECK_GL ;
On subsequent frames, I'm just calling again:
// update the data
glBufferData( glBufferData(
GL_ARRAY_BUFFER, //Specifies the target buffer object.
rawDynamicData.size() * sizeof( VertexType ),
&rawDynamicData[0],
GL_DYNAMIC_DRAW // I plan to update the data every frame
) ; CHECK_GL ;
I also tried
//update the data
GLvoid* vbo_buffer = glMapBufferOES(GL_ARRAY_BUFFER, GL_WRITE_ONLY_OES);
memcpy(vbo_buffer, &rawDynamicData[0], rawDynamicData.size()*sizeof(VertexType) );
glUnmapBufferOES(GL_ARRAY_BUFFER);
But with both ways, I get this:
The white points were the initial data, and the red points are the result of subsequent calls to glBufferData
So this question has a couple of parts regarding dynamic vbos in OpenGL ES 2.0:
What is the correct command order for creating a dynamic vertex buffer whose elements will be completely updated on every frame?
Can the vertex buffer grow between frames? Or do I have to flush exactly the same size?
I know about using "client memory" pointers, can you do this in OpenGL ES 2.0 (to avoid the memcpy) or is that deprecated, should use vertex buffers exclusively?