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
Modifier and Type | Class and Description |
---|---|
static class |
GLFrameBuffer.FloatFrameBufferBuilder |
static class |
GLFrameBuffer.FrameBufferBuilder |
static class |
GLFrameBuffer.FrameBufferCubemapBuilder |
protected static class |
GLFrameBuffer.FrameBufferRenderBufferAttachmentSpec |
protected static class |
GLFrameBuffer.FrameBufferTextureAttachmentSpec |
protected static class |
GLFrameBuffer.GLFrameBufferBuilder<U extends GLFrameBuffer<? extends GLTexture>> |
Modifier and Type | Field and Description |
---|---|
protected GLFrameBuffer.GLFrameBufferBuilder<? extends GLFrameBuffer<T>> |
bufferBuilder |
protected static java.util.Map<Application,Array<GLFrameBuffer>> |
buffers
the frame buffers
|
protected static int |
defaultFramebufferHandle
the default framebuffer handle, a.k.a screen.
|
protected static boolean |
defaultFramebufferHandleInitialized
true if we have polled for the default handle already.
|
protected int |
depthbufferHandle
the depthbuffer render object handle
|
protected int |
depthStencilPackedBufferHandle
the depth stencil packed render buffer object handle
|
protected int |
framebufferHandle
the framebuffer handle
|
protected static int |
GL_DEPTH24_STENCIL8_OES |
protected boolean |
hasDepthStencilPackedBuffer
if has depth stencil packed buffer
|
protected boolean |
isMRT
if multiple texture attachments are present
|
protected int |
stencilbufferHandle
the stencilbuffer render object handle
|
protected Array<T> |
textureAttachments
the color buffer texture
|
Modifier | Constructor and Description |
---|---|
protected |
GLFrameBuffer(GLFrameBuffer.GLFrameBufferBuilder<? extends GLFrameBuffer<T>> bufferBuilder)
Creates a GLFrameBuffer from the specifications provided by bufferBuilder
|
Modifier and Type | Method and Description |
---|---|
protected abstract void |
attachFrameBufferColorTexture(T texture)
Override this method in a derived class to attach the backing texture to the GL framebuffer object.
|
void |
begin()
Binds the frame buffer and sets the viewport accordingly, so everything gets drawn to it.
|
void |
bind()
Makes the frame buffer current so everything gets drawn to it.
|
protected void |
build() |
static void |
clearAllFrameBuffers(Application app) |
protected abstract T |
createTexture(GLFrameBuffer.FrameBufferTextureAttachmentSpec attachmentSpec)
Override this method in a derived class to set up the backing texture as you like.
|
void |
dispose()
Releases all resources associated with the FrameBuffer.
|
protected abstract void |
disposeColorTexture(T colorTexture)
Override this method in a derived class to dispose the backing texture as you like.
|
void |
end()
Unbinds the framebuffer, all drawing will be performed to the normal framebuffer from here on.
|
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.
|
T |
getColorBufferTexture()
Convenience method to return the first Texture attachment present in the fbo
|
int |
getDepthBufferHandle() |
protected int |
getDepthStencilPackedBuffer() |
int |
getFramebufferHandle() |
int |
getHeight() |
static java.lang.String |
getManagedStatus() |
static java.lang.StringBuilder |
getManagedStatus(java.lang.StringBuilder builder) |
int |
getStencilBufferHandle() |
Array<T> |
getTextureAttachments()
Return the Texture attachments attached to the fbo
|
int |
getWidth() |
static void |
invalidateAllFrameBuffers(Application app)
Invalidates all frame buffers.
|
protected void |
setFrameBufferViewport()
Sets viewport to the dimensions of framebuffer.
|
static void |
unbind()
Unbinds the framebuffer, all drawing will be performed to the normal framebuffer from here on.
|
protected static final java.util.Map<Application,Array<GLFrameBuffer>> buffers
protected static final int GL_DEPTH24_STENCIL8_OES
protected static int defaultFramebufferHandle
protected static boolean defaultFramebufferHandleInitialized
protected int framebufferHandle
protected int depthbufferHandle
protected int stencilbufferHandle
protected int depthStencilPackedBufferHandle
protected boolean hasDepthStencilPackedBuffer
protected boolean isMRT
protected GLFrameBuffer.GLFrameBufferBuilder<? extends GLFrameBuffer<T extends GLTexture>> bufferBuilder
protected GLFrameBuffer(GLFrameBuffer.GLFrameBufferBuilder<? extends GLFrameBuffer<T>> bufferBuilder)
public T getColorBufferTexture()
public Array<T> getTextureAttachments()
protected abstract T createTexture(GLFrameBuffer.FrameBufferTextureAttachmentSpec attachmentSpec)
protected abstract void disposeColorTexture(T colorTexture)
protected abstract void attachFrameBufferColorTexture(T texture)
protected void build()
public void dispose()
dispose
in interface Disposable
public void bind()
public static void unbind()
public void begin()
protected void setFrameBufferViewport()
begin()
.public void end()
public void end(int x, int y, int width, int height)
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 pixelspublic int getFramebufferHandle()
GL20.glGenFramebuffer()
)public int getDepthBufferHandle()
GL20.glGenRenderbuffer()
). May return 0 even if depth
buffer enabledpublic int getStencilBufferHandle()
GL20.glGenRenderbuffer()
). May return 0 even if
stencil buffer enabledprotected int getDepthStencilPackedBuffer()
public int getHeight()
public int getWidth()
public static void invalidateAllFrameBuffers(Application app)
public static void clearAllFrameBuffers(Application app)
public static java.lang.StringBuilder getManagedStatus(java.lang.StringBuilder builder)
public static java.lang.String getManagedStatus()