0
votes

I'm displaying text from Bitmap Fonts on screen with OpenGL, and I'm creating a VBO for vertexes, another for indexes and one for UVs.

I get a string value, and I create a single vertex, uv and index data from all the characters so I only have 1 draw call.

Now I'm trying to figure what to do when that string changes. If it's the same length of the previous string, I can use glBufferData() and glBufferSubData(), but what should I do if it's a different size?

Can I bind the VBO, call glBufferData() with a different size and upload the new data? Or should I just delete the VBO and create a new one?

What's the proper way to deal with this?

1
There is no single correct way. You can either create a new buffer with a new size (invalidating the old one with a null pointer preferrably) or you can create a larger buffer from the beginning and map subranges, which removes the need for the driver to do allocations. It's possible to do unsynchronized mappings of subranges of one large buffer, and it's possible to do a buffer copy from some subranges of the COPY_READ_BUFFER target to the actual buffer. Each works. The more complicated approaches are a bit faster, but most likely it's no big difference.Damon

1 Answers

0
votes

Allocate a bigger buffer then you need and map subranges so the driver doesn't have to reallocate the memory every time the string changes.