Is it possible to in-place resize VBOs?

前端 未结 3 1885
北恋
北恋 2020-12-20 12:34

The title says everything, but just to be clear I\'ll add some extra words.

In this case, resize means:

  • getting more storage space at the end
相关标签:
3条回答
  • 2020-12-20 12:54

    I think without doing a copy you won't get around this, because the only way to resize a buffer is to call glBufferData and there is IMO no way to tell the driver to keep the old data.

    What you probably can do to at least not copy it to the CPU and back again, is creating some kind of auxiliary VBO for these purposes and copy directly from the VBO into the auxiliary VBO (using the ARB_copy_buffer extension), resize the VBO and copy its contents back.

    But I think the best way is just to allocate a larger buffer beforehand, so the resize is not neccessary, but of course in this case you need to know approximately how much extra storage you need.

    0 讨论(0)
  • 2020-12-20 13:02

    Assuming you have support for a recent OpenGL standard, an alternative to VBOs might be to store your data in textures ( again, assuming you have enough memory on your card ). Copying data between old and new textures would take place on the card and not affect the data transfer.

    Exactly how you achieve this depends on exactly what your code is doing. But in principle, you use texture data to overwrite dummy vertex data in your drawing calls, or maybe use instancing. It would require a lot of thought and rework.

    0 讨论(0)
  • 2020-12-20 13:11

    Revisiting this question after some years, the landscape has changed a bit with newer versions and extensions.

    GPU Side Copying

    The extension mentioned in Christian Rau's answer is core since 3.1 which allows us to copy contents (via glCopyBufferSubData) from one VBO to another. Hopefully, the driver does this on the GPU side!

    Using this function we could create a larger buffer and copy the leading data over. This has the disadvantage of doubling the memory requirements because we need both buffers.

    True resizing

    The good news is: With sparse buffers an even better solution is on the horizon.

    Given this extension we can allocate a virtual buffer with more than enough space for our data without ever paying for the unneeded space. We only have to "commit" the regions of memory we physically want to store data in. This means we can "grow" the VBO by committing new pages at the end of it.

    The bad news is: As of the current OpenGL version (4.5) this is still an extension and not yet core, so adopting this might not be possible. You should also not that there are some details in the specification that are not yet worked out. For example, mapping of sparse buffers is disallowed in the current extension but support might be added in future versions.

    I would be keen to hear about the availability of this extension if you have any data on that.

    0 讨论(0)
提交回复
热议问题