Package arc.fx.util

Class PingPongBuffer


public final class PingPongBuffer extends Object
Encapsulates a framebuffer with the ability to ping-pong between two buffers.

Upon begin() the buffer is reset to a known initial state, this is usually done just before the first usage of the buffer.

Subsequent swap() calls will initiate writing to the next available buffer, returning the previously used one, effectively ping-ponging between the two. Until end() is called, chained rendering will be possible by retrieving the necessary buffers via getSrcTexture(), getSrcBuffer(), getDstTexture() or getDstBuffer().

When finished, end() should be called to stop capturing. When the OpenGL context is lost, rebind() should be called.

  • Constructor Details

    • PingPongBuffer

      public PingPongBuffer(Pixmap.Format fbFormat)
      Initializes ping-pong buffer with the size of the client's area (usually window size). If you use different OpenGL viewport, better use PingPongBuffer(Format, int, int) and specify the size manually.
      fbFormat - Pixel format of buffer.
    • PingPongBuffer

      public PingPongBuffer(Pixmap.Format fbFormat, int width, int height)
    • PingPongBuffer

      public PingPongBuffer(Pixmap.Format fbFormat, int width, int height, boolean depth, boolean stencil)
      Initializes ping-pong buffer with the given size.
      fbFormat - Pixel format of buffer.
  • Method Details

    • dispose

      public void dispose()
    • resize

      public void resize(int width, int height)
    • rebind

      public void rebind()
      Restores buffer OpenGL parameters. Could be useful in case of OpenGL context loss.
    • begin

      public void begin()
      Start capturing into the destination buffer. To swap buffers during capturing, call swap(). end() shall be called after rendering to ping-pong buffer is done.
    • swap

      public void swap()
      Swaps source/target buffers. May be called outside of capturing state.
    • end

      public void end()
      Finishes ping-ponging. Must be called after begin().
    • getSrcTexture

      public Texture getSrcTexture()
      the source texture of the current ping-pong chain.
    • getSrcBuffer

      public FrameBuffer getSrcBuffer()
      the source buffer of the current ping-pong chain.
    • getDstTexture

      public Texture getDstTexture()
      the result's texture of the latest swap().
    • getDstBuffer

      public FrameBuffer getDstBuffer()
      Returns the result's buffer of the latest swap().
    • setTextureParams

      public void setTextureParams(Texture.TextureWrap u, Texture.TextureWrap v, Texture.TextureFilter min, Texture.TextureFilter mag)
    • clear

      public void clear(Color clearColor)
      Cleans up managed buffers with specified color.
    • clear

      public void clear(float r, float g, float b, float a)
      Cleans up managed buffers with specified color.