Search code examples
gpuframebufferbgfx

BGFX and double buffering


Does BGFX internally double buffer everything? Or is this the application programmer's responsibility?

All the BGFX examples that render-off screen don't seem create double the buffers.

Would I need to call createFrameBuffer() twice, once for front and once for back, and render them alternately?

I want to avoid unnecessary stalls of the GPU. In OpenGL I would have done this via buffer orphaning. But I have a suspicion that in BGFX I may have to do this more explicitly?


Solution

  • The transient buffers in bgfx do use orphaning. See code here, which is called here.

    If you're not using transient data, then yes I think you have to do it more explicitly.

    For instance, the "27-terrain" example does dynamic streaming of vertex data, and allows you to switch among several modes at runtime. You can see the logic here. The default case just destroys/recreates the buffer every time. Note the different calls in the different cases: createVertexBuffer vs createDynamicVertexBuffer.