Well, glBufferData (...)
does more than you think. True it supplies data to a VBO, but the more important point is that it allocates memory on the server side (GPU for all intents and purposes) for vertex storage.
In your example, the number of vertices, and therefore size required to store them does not seem to change when you refresh your data. What you should actually be doing is calling glBufferSubData (...)
to update the data without re-allocating space for it. Coupled with a correct usage flag (e.g. GL_DYNAMIC_DRAW
) this can be much more efficient than copying from client to server everytime something is drawn.
Think of glBufferData (...)
as a combination of malloc (...)
and memcpy (...)
. glBufferSubData (...)
on the other hand is memcpy (...)
. To this, end you can even do memory mapping of VBOs into your application's address space without having to allocate storage in both the client and server using glMapBuffer (...)
and glUnmapBuffer (...)
, which are analogous to mmap (...)
and munmap (...)
.