I'm currently working on a sprite renderer whose data changes every tick, so I've been looking for ways to stream a buffer object, I came across buffer orphaning... which confused me a bit.
- Firstly, when you call glBufferData with a NULL pointer, is new memory allocated and as such does it matter if the size of the buffer changes?
- Secondly, do you need to call glMap/glUnmap every time you update the buffer or does a single glMap work? And does GL_INVALIDATE_BUFFER do the same than just setting data to NULL?
Finally, Am I missing anything in the following implementation?
Every tick:
glBindBuffer(GL_ARRAY_BUFFER, ssb->buffers[1]); glBufferData(GL_ARRAY_BUFFER, length, NULL, GL_STREAM_DRAW); void* buffer = glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY); memcpy(buffer, data, length); glUnmapBuffer(GL_ARRAY_BUFFER);