Reputation: 7319
I have an array of vertex attributes GLfloat *vxData
. I've bound both GL_ARRAY_BUFFER
and GL_ELEMENT_ARRAY_BUFFER
with vxData
and the correct index data, and the initial vertices render successfully.
At each render step I do:
glBindBuffer(GL_ARRAY_BUFFER, buffers[0]);
glBufferData(GL_ARRAY_BUFFER, vxDataSize, vxData, GL_STATIC_DRAW);
glDrawElements(...)
At some stage, vxData
changes size to accommodate fewer/more vertices, the index data is recreated to reflect this, and vxDataSize
is updated. For the render immediately following this change in data, is it correct to simply call the same lines above?
I'm aware of alternative possibilities e.g. using glMapBufferOES
, I'd simply like to know whether the above is technically correct for this scenario.
Upvotes: 1
Views: 2186
Reputation: 473407
Is it correct? Yes, you can do that and you should get functional code that renders what you expect it to. Is it good?
No.
First, you're lying to the OpenGL implementation. You told it that you were making STATIC data. STATIC means you upload to it once. If you're doing that every frame, then you should be using STREAM, not STATIC.
Second, you should not be making buffers bigger and smaller. It's one thing to flush the old data out, but if you're telling OpenGL that the buffer needs to be bigger, then it has to actually allocate memory. That's not good. Pick a size and stick with it. Pick the largest size you can expect to use and stay there.
Upvotes: 5