I'm sending a large number of data to the
vertex shader. I use
glBufferData to generate my
VBO. Later on I have to replace the data in my
VBO so I do the following:
glBufferSubData(GL_ARRAY_BUFFER, sizeof(glm::mat4) * models().size(), &models, GL_DYNAMIC_DRAW);
What I noticed is when I used the above code (I'm assuming) that some of the previous data is left in the
VBO because I not only draw the new objects I want to but also some of the old ones.
Therefore I had to change my code to the following:
glBufferData(GL_ARRAY_BUFFER, sizeof(glm::mat4) * models().size(), &models, GL_DYNAMIC_DRAW);
The reason I don't like the above aproach is because according to Khronos
When replacing the entire data store, consider using glBufferSubData rather than completely recreating the data store with glBufferData. This avoids the cost of reallocating the data store.
How do I replace the whole
VBO with my new data, but if my new data is smaller than the old data then how do I reallocated the
VBO efficiently? Or is there something equivalent to a
NULL terminating character where the graphics card can know not to read any further data?
The reason I ask this is because from my understanding
glBufferStorage is like
glBufferData except that the
data store generated by
glBufferStorage is immutable meaning that the size of the
data store cannot be changed, as stated on Khronos and on Stackoverflow.
glBufferStorage and glNamedBufferStorage create a new immutable data store.
glBufferData creates a
data store which cannot shrink in size then what's the point of it? (Unless I'm misunderstanding its intended use)