Suppose (mostly for compatibility reasons) that I want to implement an immediate mode style interface of my own using VBOs, without any actual calls to glBegin etc.
Now I can think of a few ways to do it, my first guess would be something like:
- A vertex buffer is created with the GL_STREAM_DRAW flag
- The vertex buffer is mapped in my “glBegin” call
- Vertex data is copied into the mapped buffer during my “glVertex” etc. calls
- The vertex buffer is unmapped in my “glEnd” call, and a call is made to glDrawArrays to draw the geometry
My concerns are mostly related to pipeline stalls; namely the calls to map and unmap the buffer. Stalls would be a big problem for this, because the buffer would be mapped and unmapped quite a bit. My understanding is the GL_STREAM_DRAW usage flag exists for cases like this… but I just thought I’d ask the boards here to see if there is already a consensus on what is best for these types of things. Maybe I should use my own staging buffer, and call glBufferSubData instead?
As a side question, what is the difference between GL_DYNAMIC_DRAW and GL_STREAM_DRAW anyways? I can see how they would both be different from GL_STATIC_DRAW, but what is the difference between these last two? (I do understand they are just hints, and that on some implementations the difference might be “none”, but they are separate enums for some reason… what is it? Even reading the spec it seems unclear.)