Class GLFrameBuffer<T extends GLTexture>
- java.lang.Object
-
- com.badlogic.gdx.graphics.glutils.GLFrameBuffer<T>
-
- 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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classGLFrameBuffer.FloatFrameBufferBuilderstatic classGLFrameBuffer.FrameBufferBuilderstatic classGLFrameBuffer.FrameBufferCubemapBuilderprotected static classGLFrameBuffer.FrameBufferRenderBufferAttachmentSpecprotected static classGLFrameBuffer.FrameBufferTextureAttachmentSpecstatic classGLFrameBuffer.GLFrameBufferBuilder<U extends GLFrameBuffer<? extends GLTexture>>
-
Field Summary
Fields Modifier and Type Field Description protected GLFrameBuffer.GLFrameBufferBuilder<? extends GLFrameBuffer<T>>bufferBuilderprotected static java.util.Map<Application,Array<GLFrameBuffer>>buffersthe frame buffersprotected static intdefaultFramebufferHandlethe default framebuffer handle, a.k.a screen.protected static booleandefaultFramebufferHandleInitializedtrue if we have polled for the default handle already.protected intdepthbufferHandlethe depthbuffer render object handleprotected intdepthStencilPackedBufferHandlethe depth stencil packed render buffer object handleprotected intframebufferHandlethe framebuffer handleprotected static intGL_DEPTH24_STENCIL8_OESprotected booleanhasDepthStencilPackedBufferif has depth stencil packed bufferprotected booleanisMRTif multiple texture attachments are presentprotected intstencilbufferHandlethe stencilbuffer render object handleprotected Array<T>textureAttachmentsthe color buffer texture
-
Constructor Summary
Constructors Modifier Constructor Description protectedGLFrameBuffer(GLFrameBuffer.GLFrameBufferBuilder<? extends GLFrameBuffer<T>> bufferBuilder)Creates a GLFrameBuffer from the specifications provided by bufferBuilder
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract voidattachFrameBufferColorTexture(T texture)Override this method in a derived class to attach the backing texture to the GL framebuffer object.voidbegin()Binds the frame buffer and sets the viewport accordingly, so everything gets drawn to it.voidbind()Makes the frame buffer current so everything gets drawn to it.protected voidbuild()static voidclearAllFrameBuffers(Application app)protected abstract TcreateTexture(GLFrameBuffer.FrameBufferTextureAttachmentSpec attachmentSpec)Override this method in a derived class to set up the backing texture as you like.voiddispose()Releases all resources associated with the FrameBuffer.protected abstract voiddisposeColorTexture(T colorTexture)Override this method in a derived class to dispose the backing texture as you like.voidend()Unbinds the framebuffer, all drawing will be performed to the normal framebuffer from here on.voidend(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.TgetColorBufferTexture()Convenience method to return the first Texture attachment present in the fbointgetDepthBufferHandle()protected intgetDepthStencilPackedBuffer()intgetFramebufferHandle()intgetHeight()static java.lang.StringgetManagedStatus()static java.lang.StringBuildergetManagedStatus(java.lang.StringBuilder builder)intgetStencilBufferHandle()Array<T>getTextureAttachments()Return the Texture attachments attached to the fbointgetWidth()static voidinvalidateAllFrameBuffers(Application app)Invalidates all frame buffers.protected voidsetFrameBufferViewport()Sets viewport to the dimensions of framebuffer.static voidunbind()Unbinds the framebuffer, all drawing will be performed to the normal framebuffer from here on.
-
-
-
Field Detail
-
buffers
protected static final java.util.Map<Application,Array<GLFrameBuffer>> buffers
the frame buffers
-
GL_DEPTH24_STENCIL8_OES
protected static final int GL_DEPTH24_STENCIL8_OES
- See Also:
- Constant Field Values
-
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
-
bufferBuilder
protected GLFrameBuffer.GLFrameBufferBuilder<? extends GLFrameBuffer<T extends GLTexture>> bufferBuilder
-
-
Constructor Detail
-
GLFrameBuffer
protected GLFrameBuffer(GLFrameBuffer.GLFrameBufferBuilder<? extends GLFrameBuffer<T>> bufferBuilder)
Creates a GLFrameBuffer from the specifications provided by bufferBuilder
-
-
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
-
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:
disposein interfaceDisposable
-
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 bybegin().
-
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 pixelsy- the y-asis position of the viewport in pixelswidth- the width of the viewport in pixelsheight- 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()
-
-