libgdx API

com.badlogic.gdx.graphics.glutils
Class FrameBuffer

java.lang.Object
  extended by com.badlogic.gdx.graphics.glutils.FrameBuffer
All Implemented Interfaces:
Disposable
Direct Known Subclasses:
FloatFrameBuffer

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

Author:
mzechner

Field Summary
protected  Texture colorTexture
          the color buffer texture
protected  Pixmap.Format format
          format
protected  boolean hasDepth
          depth
protected  int height
          height
protected  int width
          width
 
Constructor Summary
FrameBuffer(Pixmap.Format format, int width, int height, boolean hasDepth)
          Creates a new FrameBuffer having the given dimensions and potentially a depth buffer attached.
 
Method Summary
 void begin()
          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.
 Texture getColorBufferTexture()
           
 int getHeight()
           
static java.lang.String getManagedStatus()
           
 int getWidth()
           
static void invalidateAllFrameBuffers(Application app)
          Invalidates all frame buffers.
protected  void setupTexture()
          Override this method in a derived class to set up the backing texture as you like.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

colorTexture

protected Texture colorTexture
the color buffer texture


width

protected final int width
width


height

protected final int height
height


hasDepth

protected final boolean hasDepth
depth


format

protected final Pixmap.Format format
format

Constructor Detail

FrameBuffer

public FrameBuffer(Pixmap.Format format,
                   int width,
                   int height,
                   boolean hasDepth)
Creates a new FrameBuffer having the given dimensions and potentially a depth buffer attached.

Parameters:
format - the format of the color buffer
width - the width of the framebuffer in pixels
height - the height of the framebuffer in pixels
hasDepth - whether to attach a depth buffer
Throws:
GdxRuntimeException - in case the FraeBuffer could not be created
Method Detail

setupTexture

protected void setupTexture()
Override this method in a derived class to set up the backing texture as you like.


dispose

public void dispose()
Releases all resources associated with the FrameBuffer.

Specified by:
dispose in interface Disposable

begin

public void begin()
Makes the frame buffer current so everything gets drawn to it.


end

public void end()
Unbinds the framebuffer, all drawing will be performed to the normal framebuffer from here on.


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.String getManagedStatus()

getColorBufferTexture

public Texture getColorBufferTexture()
Returns:
the color buffer texture

getHeight

public int getHeight()
Returns:
the height of the framebuffer in pixels

getWidth

public int getWidth()
Returns:
the width of the framebuffer in pixels

libgdx API

Copyright 2010 Mario Zechner (contact@badlogicgames.com), Nathan Sweet (admin@esotericsoftware.com)