Class GLFrameBuffer<T extends GLTexture>

  • All Implemented Interfaces:
    Disposable
    Direct Known Subclasses:
    FrameBuffer, FrameBufferCubemap

    public abstract class GLFrameBuffer<T extends GLTexture>
    extends java.lang.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 getColorBufferTexture(). 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 Detail

      • GL_DEPTH24_STENCIL8_OES

        protected static final int GL_DEPTH24_STENCIL8_OES
        See Also:
        Constant Field Values
      • textureAttachments

        protected Array<T extends GLTexture> textureAttachments
        the color buffer texture
      • defaultFramebufferHandle

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

        protected static boolean defaultFramebufferHandleInitialized
        true if we have polled for the default handle already.
      • 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
    • Method Detail

      • getColorBufferTexture

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

        public Array<T> getTextureAttachments()
        Return the Texture attachments attached to the fbo
      • 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.
      • unbind

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

        public void begin()
        Binds the frame buffer and sets the viewport accordingly, so everything gets drawn to it.
      • 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.
      • end

        public void end​(int x,
                        int y,
                        int width,
                        int height)
        Unbinds the framebuffer and sets viewport sizes, all drawing will be performed to the normal framebuffer from here on.
        Parameters:
        x - the x-axis position of the viewport in pixels
        y - the y-asis position of the viewport in pixels
        width - the width of the viewport in pixels
        height - the height of the viewport in pixels
      • 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
      • invalidateAllFrameBuffers

        public static void invalidateAllFrameBuffers​(Application app)
        Invalidates all frame buffers. This can be used when the OpenGL context is lost to rebuild all managed frame buffers. This assumes that the texture attached to this buffer has already been rebuild! Use with care.
      • clearAllFrameBuffers

        public static void clearAllFrameBuffers​(Application app)
      • getManagedStatus

        public static java.lang.StringBuilder getManagedStatus​(java.lang.StringBuilder builder)
      • getManagedStatus

        public static java.lang.String getManagedStatus()