Class PingPongBuffer

java.lang.Object
gaiasky.util.gdx.contrib.postprocess.utils.PingPongBuffer

public final class PingPongBuffer
extends java.lang.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 capture() 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 getSouceTexture(), getSourceBuffer(), getResultTexture() or getResultBuffer().

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

  • Field Summary

    Fields
    Modifier and Type Field Description
    int height  
    boolean ownResources  
    com.badlogic.gdx.graphics.Texture texture1  
    com.badlogic.gdx.graphics.Texture texture2  
    com.badlogic.gdx.graphics.Texture textureDepth  
    com.badlogic.gdx.graphics.Texture textureVel  
    int width  
  • Constructor Summary

    Constructors
    Constructor Description
    PingPongBuffer​(int width, int height, com.badlogic.gdx.graphics.Pixmap.Format frameBufferFormat, boolean hasDepth)  
    PingPongBuffer​(int width, int height, com.badlogic.gdx.graphics.Pixmap.Format frameBufferFormat, boolean hasDepth, boolean hasVelocity, boolean preventFloatBuffer)
    Creates a new ping-pong buffer and owns the resources.
    PingPongBuffer​(GaiaSkyFrameBuffer buffer1, GaiaSkyFrameBuffer buffer2)
    Creates a new ping-pong buffer with the given buffers.
  • Method Summary

    Modifier and Type Method Description
    void begin()
    Ensures the initial buffer state is always the same before starting ping-ponging.
    com.badlogic.gdx.graphics.Texture capture()
    Starts and/or continue ping-ponging, begin capturing on the next available buffer, returns the result of the previous capture() call.
    static GaiaSkyFrameBuffer createMainFrameBuffer​(int width, int height, boolean hasDepth, boolean hasVelocity, com.badlogic.gdx.graphics.Pixmap.Format frameBufferFormat, boolean preventFloatBuffer)  
    void dispose()
    Free the resources, if any.
    void end()
    Finishes ping-ponging, must always be called after a call to capture()
    com.badlogic.gdx.graphics.Texture getDepthTexture()  
    GaiaSkyFrameBuffer getMainBuffer()  
    GaiaSkyFrameBuffer getResultBuffer()  
    com.badlogic.gdx.graphics.Texture getResultTexture()  
    com.badlogic.gdx.graphics.Texture getSouceTexture()  
    GaiaSkyFrameBuffer getSourceBuffer()  
    void rebind()
    When needed graphics memory could be invalidated so buffers should be rebuilt.
    void reset()
    Restore the previous buffers if the instance was owning resources.
    void set​(GaiaSkyFrameBuffer buffer1, GaiaSkyFrameBuffer buffer2)
    An instance of this object can also be used to manipulate some other externally-allocated buffers, applying just the same ping-ponging behavior.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • texture1

      public com.badlogic.gdx.graphics.Texture texture1
    • texture2

      public com.badlogic.gdx.graphics.Texture texture2
    • textureDepth

      public com.badlogic.gdx.graphics.Texture textureDepth
    • textureVel

      public com.badlogic.gdx.graphics.Texture textureVel
    • width

      public int width
    • height

      public int height
    • ownResources

      public final boolean ownResources
  • Constructor Details

    • PingPongBuffer

      public PingPongBuffer​(int width, int height, com.badlogic.gdx.graphics.Pixmap.Format frameBufferFormat, boolean hasDepth)
    • PingPongBuffer

      public PingPongBuffer​(int width, int height, com.badlogic.gdx.graphics.Pixmap.Format frameBufferFormat, boolean hasDepth, boolean hasVelocity, boolean preventFloatBuffer)
      Creates a new ping-pong buffer and owns the resources.
    • PingPongBuffer

      public PingPongBuffer​(GaiaSkyFrameBuffer buffer1, GaiaSkyFrameBuffer buffer2)
      Creates a new ping-pong buffer with the given buffers.
  • Method Details

    • createMainFrameBuffer

      public static GaiaSkyFrameBuffer createMainFrameBuffer​(int width, int height, boolean hasDepth, boolean hasVelocity, com.badlogic.gdx.graphics.Pixmap.Format frameBufferFormat, boolean preventFloatBuffer)
    • set

      public void set​(GaiaSkyFrameBuffer buffer1, GaiaSkyFrameBuffer buffer2)
      An instance of this object can also be used to manipulate some other externally-allocated buffers, applying just the same ping-ponging behavior.

      If this instance of the object was owning the resources, they will be preserved and will be restored by a reset() call.

      Parameters:
      buffer1 - the first buffer
      buffer2 - the second buffer
    • reset

      public void reset()
      Restore the previous buffers if the instance was owning resources.
    • dispose

      public void dispose()
      Free the resources, if any.
    • rebind

      public void rebind()
      When needed graphics memory could be invalidated so buffers should be rebuilt.
    • begin

      public void begin()
      Ensures the initial buffer state is always the same before starting ping-ponging.
    • capture

      public com.badlogic.gdx.graphics.Texture capture()
      Starts and/or continue ping-ponging, begin capturing on the next available buffer, returns the result of the previous capture() call.
      Returns:
      the Texture containing the result.
    • end

      public void end()
      Finishes ping-ponging, must always be called after a call to capture()
    • getSouceTexture

      public com.badlogic.gdx.graphics.Texture getSouceTexture()
      Returns:
      the source texture of the current ping-pong chain.
    • getSourceBuffer

      public GaiaSkyFrameBuffer getSourceBuffer()
      Returns:
      the source buffer of the current ping-pong chain.
    • getResultTexture

      public com.badlogic.gdx.graphics.Texture getResultTexture()
      Returns:
      the result's texture of the latest capture().
    • getResultBuffer

      public GaiaSkyFrameBuffer getResultBuffer()
      Returns:
      Returns the result's buffer of the latest capture().
    • getMainBuffer

      public GaiaSkyFrameBuffer getMainBuffer()
    • getDepthTexture

      public com.badlogic.gdx.graphics.Texture getDepthTexture()
      Returns:
      the depth texture attachment containing the depth buffer