Class FramebufferPool

java.lang.Object
lol.trq.helios.fbo.FramebufferPool
All Implemented Interfaces:
AutoCloseable

public final class FramebufferPool extends Object implements AutoCloseable
Reuses offscreen framebuffers across frames.

Screen-relative sizes come from SurfaceSize, in framebuffer pixels, so effects stay sharp on high-DPI screens. When the surface size changes, every idle buffer is deleted, and buffers lent out under the old size are deleted when they come back. Use it on the GL thread only.

  • Constructor Details

    • FramebufferPool

      public FramebufferPool(GlBackend gl, SurfaceSize surface)
      Creates a pool.
      Parameters:
      gl - the backend
      surface - the window framebuffer size
  • Method Details

    • acquireScreen

      public Framebuffer acquireScreen(int divisor, boolean depthStencil)
      Borrows a framebuffer the size of the window, or a fraction of it.
      Parameters:
      divisor - 1 for full size, 2 for half, and so on
      depthStencil - whether a depth-stencil buffer is needed
      Returns:
      the framebuffer; give it back with release(Framebuffer)
    • acquire

      public Framebuffer acquire(int width, int height, boolean depthStencil)
      Borrows a framebuffer of a fixed size.
      Parameters:
      width - width in pixels
      height - height in pixels
      depthStencil - whether a depth-stencil buffer is needed
      Returns:
      the framebuffer; give it back with release(Framebuffer)
    • release

      public void release(Framebuffer fb)
      Gives a framebuffer back.
      Parameters:
      fb - a framebuffer from this pool
      Throws:
      IllegalArgumentException - if it is not currently lent out by this pool
    • idleCount

      public int idleCount()
      Returns how many framebuffers sit idle.
      Returns:
      the idle count
    • lentCount

      public int lentCount()
      Returns how many framebuffers are lent out.
      Returns:
      the lent count
    • createdCount

      public int createdCount()
      Returns how many framebuffers this pool has created in total.
      Returns:
      the creation count
    • trim

      public void trim()
      Deletes every idle framebuffer. Lent ones are deleted when released.
    • close

      public void close()
      Deletes every idle framebuffer and retires the lent ones, as after a resize.
      Specified by:
      close in interface AutoCloseable