Class PostProcessor

  • All Implemented Interfaces:
    com.badlogic.gdx.utils.Disposable

    public final class PostProcessor
    extends java.lang.Object
    implements com.badlogic.gdx.utils.Disposable
    Provides a way to capture the rendered scene to an off-screen buffer and to apply a chain of effects on it before rendering to screen.

    Effects can be added or removed via addEffect(PostProcessorEffect) and removeEffect(PostProcessorEffect).

    • Constructor Summary

      Constructors 
      Constructor Description
      PostProcessor​(IPostProcessor.RenderType rt, boolean useDepth, boolean useAlphaChannel, boolean use32Bits)
      Construct a new PostProcessor with FBO dimensions set to the size of the screen
      PostProcessor​(IPostProcessor.RenderType rt, int fboWidth, int fboHeight, boolean useDepth, boolean useAlphaChannel, boolean use32Bits)
      Construct a new PostProcessor with the given parameters, defaulting to TextureWrap.ClampToEdge as texture wrap mode
      PostProcessor​(IPostProcessor.RenderType rt, int fboWidth, int fboHeight, boolean useDepth, boolean useAlphaChannel, boolean use32Bits, com.badlogic.gdx.graphics.Texture.TextureWrap u, com.badlogic.gdx.graphics.Texture.TextureWrap v)
      Construct a new PostProcessor with the given parameters and the specified texture wrap mode
      PostProcessor​(IPostProcessor.RenderType rt, com.badlogic.gdx.math.Rectangle viewport, boolean useDepth, boolean useAlphaChannel, boolean use32Bits)
      Construct a new PostProcessor with the given parameters and viewport, defaulting to TextureWrap.ClampToEdge as texture wrap mode
      PostProcessor​(IPostProcessor.RenderType rt, com.badlogic.gdx.math.Rectangle viewport, boolean useDepth, boolean useAlphaChannel, boolean use32Bits, com.badlogic.gdx.graphics.Texture.TextureWrap u, com.badlogic.gdx.graphics.Texture.TextureWrap v)
      Construct a new PostProcessor with the given parameters, viewport and the specified texture wrap mode
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addEffect​(PostProcessorEffect effect)
      Adds the specified effect to the effect chain and transfer ownership to the PostProcessor, it will manage cleaning it up for you.
      int buildEnabledEffectsList()  
      boolean capture()
      Starts capturing the scene, clears the buffer with the clear color specified by setClearColor(Color) or setClearColor(float r, float g, float b, float a).
      GaiaSkyFrameBuffer captured()
      After a capture/captureEnd action, returns the just captured buffer
      GaiaSkyFrameBuffer captureEnd()
      Stops capturing the scene and returns the result, or null if nothing was captured.
      boolean captureNoClear()
      Starts capturing the scene as capture(), but without clearing the screen.
      void dispose()
      Frees owned resources.
      void dispose​(boolean cleanAllBuffers)  
      PingPongBuffer getCombinedBuffer()  
      int getEnabledEffectsCount()
      Returns the number of the currently enabled effects
      static com.badlogic.gdx.graphics.Pixmap.Format getFramebufferFormat()
      Returns the internal framebuffer format, computed from the parameters specified during construction.
      boolean isEnabled()
      Whether or not the post-processor is enabled
      boolean isReady()
      If called before capturing it will indicate if the next capture call will succeed or not.
      static boolean isStateEnabled​(int pname)
      Provides a way to query the pipeline for the most used states
      static PingPongBuffer newPingPongBuffer​(int width, int height, com.badlogic.gdx.graphics.Pixmap.Format frameBufferFormat, boolean hasDepth)
      Creates and returns a managed PingPongBuffer buffer, just create and forget.
      static PingPongBuffer newPingPongBuffer​(int width, int height, com.badlogic.gdx.graphics.Pixmap.Format frameBufferFormat, boolean hasDepth, boolean preventFloatBuffer)
      Creates and returns a managed PingPongBuffer buffer, just create and forget.
      void rebind()
      Regenerates and/or rebinds owned resources when needed, eg.
      void removeEffect​(PostProcessorEffect effect)
      Removes the specified effect from the effect chain.
      void render()
      Convenience method to render to screen.
      void render​(com.badlogic.gdx.graphics.glutils.FrameBuffer dest)
      Stops capturing the scene and apply the effect chain, if there is one.
      protected void restoreViewport​(com.badlogic.gdx.graphics.glutils.FrameBuffer dest)
      Restores the previously set viewport if one was specified earlier and the destination buffer is the screen
      void setBufferTextureWrap​(com.badlogic.gdx.graphics.Texture.TextureWrap u, com.badlogic.gdx.graphics.Texture.TextureWrap v)  
      void setClearBits​(int bits)
      Sets the clear bit for when glClear is invoked.
      void setClearColor​(float r, float g, float b, float a)
      Sets the color that will be used to clear the buffer.
      void setClearColor​(com.badlogic.gdx.graphics.Color color)
      Sets the color that will be used to clear the buffer.
      void setClearDepth​(float depth)
      Sets the depth value with which to clear the depth buffer when needed.
      void setEnabled​(boolean enabled)
      Sets whether or not the post-processor should be enabled
      void setListener​(PostProcessorListener listener)
      Sets the listener that will receive events triggered by the PostProcessor rendering pipeline.
      void setViewport​(com.badlogic.gdx.math.Rectangle viewport)
      Sets the viewport to be restored, if null is specified then the viewport will NOT be restored at all.
      • Methods inherited from class java.lang.Object

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

      • EnableQueryStates

        public static boolean EnableQueryStates
        Enable pipeline state queries: beware the pipeline can stall!
      • currentPostProcessor

        public static PostProcessor currentPostProcessor
    • Constructor Detail

      • PostProcessor

        public PostProcessor​(IPostProcessor.RenderType rt,
                             boolean useDepth,
                             boolean useAlphaChannel,
                             boolean use32Bits)
        Construct a new PostProcessor with FBO dimensions set to the size of the screen
      • PostProcessor

        public PostProcessor​(IPostProcessor.RenderType rt,
                             int fboWidth,
                             int fboHeight,
                             boolean useDepth,
                             boolean useAlphaChannel,
                             boolean use32Bits)
        Construct a new PostProcessor with the given parameters, defaulting to TextureWrap.ClampToEdge as texture wrap mode
      • PostProcessor

        public PostProcessor​(IPostProcessor.RenderType rt,
                             com.badlogic.gdx.math.Rectangle viewport,
                             boolean useDepth,
                             boolean useAlphaChannel,
                             boolean use32Bits)
        Construct a new PostProcessor with the given parameters and viewport, defaulting to TextureWrap.ClampToEdge as texture wrap mode
      • PostProcessor

        public PostProcessor​(IPostProcessor.RenderType rt,
                             com.badlogic.gdx.math.Rectangle viewport,
                             boolean useDepth,
                             boolean useAlphaChannel,
                             boolean use32Bits,
                             com.badlogic.gdx.graphics.Texture.TextureWrap u,
                             com.badlogic.gdx.graphics.Texture.TextureWrap v)
        Construct a new PostProcessor with the given parameters, viewport and the specified texture wrap mode
      • PostProcessor

        public PostProcessor​(IPostProcessor.RenderType rt,
                             int fboWidth,
                             int fboHeight,
                             boolean useDepth,
                             boolean useAlphaChannel,
                             boolean use32Bits,
                             com.badlogic.gdx.graphics.Texture.TextureWrap u,
                             com.badlogic.gdx.graphics.Texture.TextureWrap v)
        Construct a new PostProcessor with the given parameters and the specified texture wrap mode
    • Method Detail

      • newPingPongBuffer

        public static PingPongBuffer newPingPongBuffer​(int width,
                                                       int height,
                                                       com.badlogic.gdx.graphics.Pixmap.Format frameBufferFormat,
                                                       boolean hasDepth)
        Creates and returns a managed PingPongBuffer buffer, just create and forget. If rebind() is called on context loss, managed PingPongBuffers will be rebound for you.

        This is a drop-in replacement for the same-signature PingPongBuffer's constructor.

      • newPingPongBuffer

        public static PingPongBuffer newPingPongBuffer​(int width,
                                                       int height,
                                                       com.badlogic.gdx.graphics.Pixmap.Format frameBufferFormat,
                                                       boolean hasDepth,
                                                       boolean preventFloatBuffer)
        Creates and returns a managed PingPongBuffer buffer, just create and forget. If rebind() is called on context loss, managed PingPongBuffers will be rebound for you.

        This is a drop-in replacement for the same-signature PingPongBuffer's constructor.

      • isStateEnabled

        public static boolean isStateEnabled​(int pname)
        Provides a way to query the pipeline for the most used states
      • setViewport

        public void setViewport​(com.badlogic.gdx.math.Rectangle viewport)
        Sets the viewport to be restored, if null is specified then the viewport will NOT be restored at all.

        The predefined effects will restore the viewport settings at the final blitting stage (render to screen) by invoking the restoreViewport static method.

      • dispose

        public void dispose()
        Frees owned resources.
        Specified by:
        dispose in interface com.badlogic.gdx.utils.Disposable
      • dispose

        public void dispose​(boolean cleanAllBuffers)
      • isEnabled

        public boolean isEnabled()
        Whether or not the post-processor is enabled
      • isReady

        public boolean isReady()
        If called before capturing it will indicate if the next capture call will succeed or not.
      • setEnabled

        public void setEnabled​(boolean enabled)
        Sets whether or not the post-processor should be enabled
      • getEnabledEffectsCount

        public int getEnabledEffectsCount()
        Returns the number of the currently enabled effects
      • setListener

        public void setListener​(PostProcessorListener listener)
        Sets the listener that will receive events triggered by the PostProcessor rendering pipeline.
      • addEffect

        public void addEffect​(PostProcessorEffect effect)
        Adds the specified effect to the effect chain and transfer ownership to the PostProcessor, it will manage cleaning it up for you. The order of the inserted effects IS important, since effects will be applied in a FIFO fashion, the first added is the first being applied.
      • removeEffect

        public void removeEffect​(PostProcessorEffect effect)
        Removes the specified effect from the effect chain.
      • getFramebufferFormat

        public static com.badlogic.gdx.graphics.Pixmap.Format getFramebufferFormat()
        Returns the internal framebuffer format, computed from the parameters specified during construction. NOTE: the returned Format will be valid after construction and NOT early!
      • setClearColor

        public void setClearColor​(com.badlogic.gdx.graphics.Color color)
        Sets the color that will be used to clear the buffer.
      • setClearColor

        public void setClearColor​(float r,
                                  float g,
                                  float b,
                                  float a)
        Sets the color that will be used to clear the buffer.
      • setClearBits

        public void setClearBits​(int bits)
        Sets the clear bit for when glClear is invoked.
      • setClearDepth

        public void setClearDepth​(float depth)
        Sets the depth value with which to clear the depth buffer when needed.
      • setBufferTextureWrap

        public void setBufferTextureWrap​(com.badlogic.gdx.graphics.Texture.TextureWrap u,
                                         com.badlogic.gdx.graphics.Texture.TextureWrap v)
      • capture

        public boolean capture()
        Starts capturing the scene, clears the buffer with the clear color specified by setClearColor(Color) or setClearColor(float r, float g, float b, float a).
        Returns:
        true or false, whether or not capturing has been initiated. Capturing will fail in case there are no enabled effects in the chain or this instance is not enabled or capturing is already started.
      • captureNoClear

        public boolean captureNoClear()
        Starts capturing the scene as capture(), but without clearing the screen.
        Returns:
        true or false, whether or not capturing has been initiated.
      • captureEnd

        public GaiaSkyFrameBuffer captureEnd()
        Stops capturing the scene and returns the result, or null if nothing was captured.
      • captured

        public GaiaSkyFrameBuffer captured()
        After a capture/captureEnd action, returns the just captured buffer
      • rebind

        public void rebind()
        Regenerates and/or rebinds owned resources when needed, eg. when the OpenGL context is lost.
      • render

        public void render​(com.badlogic.gdx.graphics.glutils.FrameBuffer dest)
        Stops capturing the scene and apply the effect chain, if there is one. If the specified output FrameBuffer is NULL, then the rendering will be performed to screen.
      • render

        public void render()
        Convenience method to render to screen.
      • buildEnabledEffectsList

        public int buildEnabledEffectsList()
      • restoreViewport

        protected void restoreViewport​(com.badlogic.gdx.graphics.glutils.FrameBuffer dest)
        Restores the previously set viewport if one was specified earlier and the destination buffer is the screen