Class GLFrameBuffer<T extends GLTexture>

java.lang.Object
arc.graphics.gl.GLFrameBuffer<T>
All Implemented Interfaces:
Disposable
Direct Known Subclasses:
FrameBuffer, FrameBufferCubemap

public abstract class GLFrameBuffer<T extends GLTexture> extends Object implements Disposable

Encapsulates OpenGL ES 2.0 frame buffer objects. This is a simple helper class which should cover most FBO uses. It will automatically create a gltexture for the color attachment and a renderbuffer for the depth buffer. You can get a hold of the gltexture by getTexture(). This class will only work with OpenGL ES 2.0.

FrameBuffers are managed. In case of an OpenGL context loss, which only happens on Android when a user switches to another application or receives an incoming call, the framebuffer will be automatically recreated.

A FrameBuffer must be disposed if it is no longer needed

  • Field Details

    • GL_DEPTH24_STENCIL8_OES

      protected static final int GL_DEPTH24_STENCIL8_OES
      See Also:
    • currentBoundFramebuffer

      protected static GLFrameBuffer currentBoundFramebuffer
      the currently bound framebuffer; null for the default one.
    • defaultFramebufferHandle

      protected static int defaultFramebufferHandle
      the default framebuffer handle, a.k.a screen.
    • bufferNesting

      protected static int bufferNesting
      # of nested buffers right now
    • defaultFramebufferHandleInitialized

      protected static boolean defaultFramebufferHandleInitialized
      true if we have polled for the default handle already.
    • textureAttachments

      protected Seq<T extends GLTexture> textureAttachments
      the color buffer texture
    • lastBoundFramebuffer

      protected GLFrameBuffer lastBoundFramebuffer
      the framebuffer that was bound before this one began (null to indicate that nothing was bound)
    • framebufferHandle

      protected int framebufferHandle
      the framebuffer handle
    • depthbufferHandle

      protected int depthbufferHandle
      the depthbuffer render object handle
    • stencilbufferHandle

      protected int stencilbufferHandle
      the stencilbuffer render object handle
    • depthStencilPackedBufferHandle

      protected int depthStencilPackedBufferHandle
      the depth stencil packed render buffer object handle
    • hasDepthStencilPackedBuffer

      protected boolean hasDepthStencilPackedBuffer
      if has depth stencil packed buffer
    • isMRT

      protected boolean isMRT
      if multiple texture attachments are present
    • bufferBuilder

      protected GLFrameBuffer.GLFrameBufferBuilder<? extends GLFrameBuffer<T extends GLTexture>> bufferBuilder
  • Constructor Details

  • Method Details

    • getBufferNesting

      public static int getBufferNesting()
    • unbind

      public static void unbind()
      Unbinds the framebuffer, all drawing will be performed to the normal framebuffer from here on.
    • getTexture

      public T getTexture()
      Convenience method to return the first Texture attachment present in the fbo
    • getTextureAttachments

      public Seq<T> getTextureAttachments()
      Return the Texture attachments attached to the fbo
    • createTexture

      protected abstract T createTexture(GLFrameBuffer.FrameBufferTextureAttachmentSpec attachmentSpec)
      Override this method in a derived class to set up the backing texture as you like.
    • disposeColorTexture

      protected abstract void disposeColorTexture(T colorTexture)
      Override this method in a derived class to dispose the backing texture as you like.
    • attachFrameBufferColorTexture

      protected abstract void attachFrameBufferColorTexture(T texture)
      Override this method in a derived class to attach the backing texture to the GL framebuffer object.
    • build

      protected void build()
    • dispose

      public void dispose()
      Releases all resources associated with the FrameBuffer.
      Specified by:
      dispose in interface Disposable
    • bind

      public void bind()
      Makes the frame buffer current so everything gets drawn to it.
    • isBound

      public boolean isBound()
    • begin

      public void begin(Color clearColor)
      Flushes the batch, begins this buffer and clears the screen.
    • begin

      public void begin()
      Binds the frame buffer and sets the viewport accordingly, so everything gets drawn to it.
    • beginBind

      public void beginBind()
      Begins the buffer without setting the viewport or flushing the batch.
    • setFrameBufferViewport

      protected void setFrameBufferViewport()
      Sets viewport to the dimensions of framebuffer. Called by begin().
    • end

      public void end()
      Unbinds the framebuffer, all drawing will be performed to the normal framebuffer from here on.
    • endBind

      public void endBind()
      Stop binding. This does not flush the batch or change the viewport.
    • getFramebufferHandle

      public int getFramebufferHandle()
      Returns:
      The OpenGL handle of the framebuffer (see GL20.glGenFramebuffer())
    • getDepthBufferHandle

      public int getDepthBufferHandle()
      Returns:
      The OpenGL handle of the (optional) depth buffer (see GL20.glGenRenderbuffer()). May return 0 even if depth buffer enabled
    • getStencilBufferHandle

      public int getStencilBufferHandle()
      Returns:
      The OpenGL handle of the (optional) stencil buffer (see GL20.glGenRenderbuffer()). May return 0 even if stencil buffer enabled
    • getDepthStencilPackedBuffer

      protected int getDepthStencilPackedBuffer()
      Returns:
      The OpenGL handle of the packed depth & stencil buffer (GL_DEPTH24_STENCIL8_OES) or 0 if not used.
    • getHeight

      public int getHeight()
      Returns:
      the height of the framebuffer in pixels
    • getWidth

      public int getWidth()
      Returns:
      the width of the framebuffer in pixels