public class FrameBuffer 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 texture for the color attachment and a renderbuffer for the depth buffer. You can get a hold of the
texture 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 Texture |
colorTexture
the color buffer texture
|
protected Pixmap.Format |
format
format
|
protected boolean |
hasDepth
depth
|
protected boolean |
hasStencil
stencil
|
protected int |
height
height
|
protected int |
width
width
|
Constructor and Description |
---|
FrameBuffer(Pixmap.Format format,
int width,
int height,
boolean hasDepth)
Creates a new FrameBuffer having the given dimensions and potentially a depth buffer attached.
|
FrameBuffer(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 |
---|---|
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.
|
static void |
clearAllFrameBuffers(Application app) |
void |
dispose()
Releases all resources associated with the FrameBuffer.
|
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.
|
Texture |
getColorBufferTexture() |
int |
getHeight() |
static java.lang.String |
getManagedStatus() |
static java.lang.StringBuilder |
getManagedStatus(java.lang.StringBuilder builder) |
int |
getWidth() |
static void |
invalidateAllFrameBuffers(Application app)
Invalidates all frame buffers.
|
protected void |
setDefaultFrameBufferViewport()
Sets viewport to the dimensions of default framebuffer (window).
|
protected void |
setFrameBufferViewport()
Sets viewport to the dimensions of framebuffer.
|
protected void |
setupTexture()
Override this method in a derived class to set up the backing texture as you like.
|
static void |
unbind()
Unbinds the framebuffer, all drawing will be performed to the normal framebuffer from here on.
|
protected Texture colorTexture
protected final int width
protected final int height
protected final boolean hasDepth
protected final boolean hasStencil
protected final Pixmap.Format format
public FrameBuffer(Pixmap.Format format, int width, int height, boolean hasDepth)
format
- width
- height
- hasDepth
- public FrameBuffer(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 void setupTexture()
public void dispose()
dispose
in interface Disposable
public void bind()
public static void unbind()
public void begin()
protected void setFrameBufferViewport()
begin()
.public void end()
protected void setDefaultFrameBufferViewport()
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 Texture getColorBufferTexture()
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()