I have some vertex data that changes every frame, but because I don't know the (max) number of vertices ahead of time, I have to use glBufferData
every frame, instead of using glBufferSubData
. I'm only allocating the VAO/VBO itself once during initialization.
My question is: Given that I'm using glBufferData
every frame (and thus, I guess, reallocating fresh buffers every frame), should I be using GL_DYNAMIC_DRAW
or GL_STATIC_DRAW
?
My instinct is GL_STATIC_DRAW
since I'm never going to be writing over existing buffer memory, but otoh I'm wondering if GL_DYNAMIC_DRAW
affects anything in subsequent glBufferData
(not glBufferSubData
) calls on the same VBO.
GL_STATIC_DRAW is typically used when you don't expect the data to change frequently, and it's suitable for situations where you upload the data once and render it multiple times without altering it. Using GL_STATIC_DRAW tells the OpenGL driver to optimize for static data, and the driver may make certain assumptions that could hinder performance if the data is frequently updated.
On the other hand, GL_DYNAMIC_DRAW indicates that the data may change often, and the driver will optimize for that scenario, making it more suitable for your use case where you're calling glBufferData every frame with fresh data.
Using GL_DYNAMIC_DRAW should not negatively impact subsequent calls to glBufferData, even if you are creating fresh buffers each frame. It's more about how you intend to use the data within the buffer. For frequently changing data, GL_DYNAMIC_DRAW is the more appropriate choice