I’m using OpenGL ES 2.0 on iOS in Swift. The posting guidelines mention that the focus here is mostly on desktop OpenGL, but that ES questions are still welcome. Although I could be wrong, I think this question isn’t specific to ES.
Typically, the order of operations when setting up for drawing seems to be something like this (I’m not using VAOs):
glBindBuffer()
glBufferData()/glBufferSubData()
glEnableVertexAttribArray()
glVertexAttribPointer()
glDrawElements()
I’m wondering though if there’s anything wrong with creating the buffer store and/or modifying buffer contents after setting up the vertex attributes, e.g.:
glBindBuffer()
glEnableVertexAttribArray()
glVertexAttribPointer()
glBufferData()/glBufferSubData()
glDrawElements()
An example case where this might come up in practice would be a quad batching system. In such a system you might set up the vertex attribute state once at the beginning:
glBindBuffer()
glBufferData()
glEnableVertexAttribArray()
glVertexAttribPointer()
Then, for each batch:
glBufferSubData()
glDrawElements()
Here, you’d be calling glBufferSubData() (repeatedly) after having called glVertexAttribPointer().
The spec says that glVertexAttribPointer() stores the buffer ID only (which should be independent of the storage location and contents), so it doesn’t seem like calling glBufferData() or glBufferSubData() subsequent to that would cause any problems. And, I’m not seeing any problems with it in practice. Of course, just because something happens to work in practice doesn’t necessarily mean it’ll always work.
Is calling glBufferData() or glBufferSubData() on a buffer that’s currently part of vertex attribute state safe to do? Or is there some reason it shouldn’t be done that I’m missing?