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 | Field and Description |
|---|---|
protected static java.util.Map<Application,Array<GLFrameBuffer>> |
buffers
the frame buffers
|
protected T |
colorTexture
the color buffer texture
|
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 Pixmap.Format |
format
format
|
protected int |
framebufferHandle
the framebuffer handle
|
protected static int |
GL_DEPTH24_STENCIL8_OES |
protected boolean |
hasDepth
depth
|
protected boolean |
hasDepthStencilPackedBuffer
if has depth stencil packed buffer
|
protected boolean |
hasStencil
stencil
|
protected int |
height
height
|
protected int |
stencilbufferHandle
the stencilbuffer render object handle
|
protected int |
width
width
|
| Constructor and Description |
|---|
GLFrameBuffer(Pixmap.Format format,
int width,
int height,
boolean hasDepth)
Creates a new FrameBuffer having the given dimensions and potentially a depth buffer attached.
|
GLFrameBuffer(Pixmap.Format format,
int width,
int height,
boolean hasDepth,
boolean hasStencil)
Creates a new FrameBuffer having the given dimensions and potentially a depth and a stencil buffer attached.
|
| Modifier and Type | Method and Description |
|---|---|
protected abstract void |
attachFrameBufferColorTexture()
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 |
createColorTexture()
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() |
int |
getDepth() |
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() |
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 final int width
protected final int height
protected final boolean hasDepth
protected final boolean hasStencil
protected boolean hasDepthStencilPackedBuffer
protected final Pixmap.Format format
public GLFrameBuffer(Pixmap.Format format, int width, int height, boolean hasDepth)
format - width - height - hasDepth - public GLFrameBuffer(Pixmap.Format format, int width, int height, boolean hasDepth, boolean hasStencil)
format - the format of the color buffer; according to the OpenGL ES 2.0 spec, only RGB565, RGBA4444 and RGB5_A1 are
color-renderablewidth - the width of the framebuffer in pixelsheight - the height of the framebuffer in pixelshasDepth - whether to attach a depth bufferGdxRuntimeException - in case the FrameBuffer could not be createdprotected abstract T createColorTexture()
protected abstract void disposeColorTexture(T colorTexture)
protected abstract void attachFrameBufferColorTexture()
protected void build()
public void dispose()
dispose in interface Disposablepublic 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 T getColorBufferTexture()
public 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 int getDepth()
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()