APIdia Launch Partner
Top Description Fields Constructors Methods
com.badlogic.gdx.graphics.glutils

public Class FrameBufferCubemap

extends GLFrameBuffer<Cubemap>
Class Inheritance
Imports
com.badlogic.gdx.Gdx, com.badlogic.gdx.graphics.Cubemap, .GL20, .Pixmap, .Texture.TextureFilter, .Texture.TextureWrap, com.badlogic.gdx.utils.GdxRuntimeException

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 cubemap for the color attachment and a renderbuffer for the depth buffer. You can get a hold of the cubemap by FrameBufferCubemap#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

Typical use:
FrameBufferCubemap frameBuffer = new FrameBufferCubemap(Format.RGBA8888, fSize, fSize, true);
frameBuffer.begin();
while( frameBuffer.nextSide() ) {
frameBuffer.getSide().getUp(camera.up);
frameBuffer.getSide().getDirection(camera.direction);
camera.update();
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
modelBatch.begin(camera);
modelBatch.render(renderableProviders);
modelBatch.end();
}
frameBuffer.end();
Cubemap cubemap = frameBuffer.getColorBufferCubemap();

Author
realitix

Field Summary

Modifier and TypeField and Description
private static final Cubemap.CubemapSide[]
cubemapSides

cubemap sides cache

private int
currentSide

the zero-based index of the active side

Inherited from com.badlogic.gdx.graphics.glutils.GLFrameBuffer:
bufferBuilderbufferscolorBufferHandlesdefaultFramebufferHandledefaultFramebufferHandleInitializeddepthbufferHandledepthStencilPackedBufferHandleframebufferHandleGL_DEPTH24_STENCIL8_OEShasDepthStencilPackedBufferisMRTstencilbufferHandletextureAttachments

Constructor Summary

AccessConstructor and Description
pack-priv
protected
FrameBufferCubemap(GLFrameBuffer.GLFrameBufferBuilder<? extends GLFrameBuffer<Cubemap>> bufferBuilder)

Creates a GLFrameBuffer from the specifications provided by bufferBuilder

public
FrameBufferCubemap(Pixmap.Format format, int width, int height, boolean hasDepth)

Creates a new FrameBuffer having the given dimensions and potentially a depth buffer attached.

public
FrameBufferCubemap(Pixmap.Format
the format of the color buffer; according to the OpenGL ES 2.0 spec, only RGB565, RGBA4444 and RGB5_A1 are color-renderable
format
,
int
the width of the cubemap in pixels
width
,
int
the height of the cubemap in pixels
height
,
boolean
whether to attach a depth buffer
hasDepth
,
boolean
whether to attach a stencil buffer
hasStencil
)

Creates a new FrameBuffer having the given dimensions and potentially a depth and a stencil buffer attached.

Method Summary

Modifier and TypeMethod and Description
protected void
attachFrameBufferColorTexture(Cubemap texture)

Implements abstract com.badlogic.gdx.graphics.glutils.GLFrameBuffer.attachFrameBufferColorTexture.

Override this method in a derived class to attach the backing texture to the GL framebuffer object.

public void
bind()

Overrides com.badlogic.gdx.graphics.glutils.GLFrameBuffer.bind.

Makes the frame buffer current so everything gets drawn to it, must be followed by call to either nextSide() or bindSide(com.badlogic.gdx.graphics.Cubemap.CubemapSide) to activate the side to render onto.

protected void
bindSide(final Cubemap.CubemapSide
The side to bind
side
)

Bind the side, making it active to render on.

protected Cubemap
createTexture(GLFrameBuffer.FrameBufferTextureAttachmentSpec attachmentSpec)

Implements abstract com.badlogic.gdx.graphics.glutils.GLFrameBuffer.createTexture.

Override this method in a derived class to set up the backing texture as you like.

protected void
disposeColorTexture(Cubemap colorTexture)

Implements abstract com.badlogic.gdx.graphics.glutils.GLFrameBuffer.disposeColorTexture.

Override this method in a derived class to dispose the backing texture as you like.

public Cubemap.CubemapSide
getSide()

Get the currently bound side.

public boolean
nextSide()

Bind the next side of cubemap and return false if no more side.

Inherited from com.badlogic.gdx.graphics.glutils.GLFrameBuffer:
beginbuildclearAllFrameBuffersdisposeendendgetColorBufferHandlegetColorBufferTexturegetDepthBufferHandlegetDepthStencilPackedBuffergetFramebufferHandlegetHeightgetManagedStatusgetManagedStatusgetStencilBufferHandlegetTextureAttachmentsgetWidthinvalidateAllFrameBufferssetFrameBufferViewporttransfertransferunbind

Field Detail

cubemapSidesback to summary
private static final Cubemap.CubemapSide[] cubemapSides

cubemap sides cache

currentSideback to summary
private int currentSide

the zero-based index of the active side

Constructor Detail

FrameBufferCubemapback to summary
pack-priv FrameBufferCubemap()
FrameBufferCubemapback to summary
protected FrameBufferCubemap(GLFrameBuffer.GLFrameBufferBuilder<? extends GLFrameBuffer<Cubemap>> bufferBuilder)

Creates a GLFrameBuffer from the specifications provided by bufferBuilder

FrameBufferCubemapback to summary
public FrameBufferCubemap(Pixmap.Format format, int width, int height, boolean hasDepth)

Creates a new FrameBuffer having the given dimensions and potentially a depth buffer attached.

FrameBufferCubemapback to summary
public FrameBufferCubemap(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.

Parameters
format:Pixmap.Format

the format of the color buffer; according to the OpenGL ES 2.0 spec, only RGB565, RGBA4444 and RGB5_A1 are color-renderable

width:int

the width of the cubemap in pixels

height:int

the height of the cubemap in pixels

hasDepth:boolean

whether to attach a depth buffer

hasStencil:boolean

whether to attach a stencil buffer

Exceptions
GdxRuntimeException:
in case the FrameBuffer could not be created

Method Detail

attachFrameBufferColorTextureback to summary
protected void attachFrameBufferColorTexture(Cubemap texture)

Implements abstract com.badlogic.gdx.graphics.glutils.GLFrameBuffer.attachFrameBufferColorTexture.

Doc from com.badlogic.gdx.graphics.glutils.GLFrameBuffer.attachFrameBufferColorTexture.

Override this method in a derived class to attach the backing texture to the GL framebuffer object.

Annotations
@Override
bindback to summary
public void bind()

Overrides com.badlogic.gdx.graphics.glutils.GLFrameBuffer.bind.

Makes the frame buffer current so everything gets drawn to it, must be followed by call to either nextSide() or bindSide(com.badlogic.gdx.graphics.Cubemap.CubemapSide) to activate the side to render onto.

Annotations
@Override
bindSideback to summary
protected void bindSide(final Cubemap.CubemapSide side)

Bind the side, making it active to render on. Should be called in between a call to begin() and end().

Parameters
side:Cubemap.CubemapSide

The side to bind

createTextureback to summary
protected Cubemap createTexture(GLFrameBuffer.FrameBufferTextureAttachmentSpec attachmentSpec)

Implements abstract com.badlogic.gdx.graphics.glutils.GLFrameBuffer.createTexture.

Doc from com.badlogic.gdx.graphics.glutils.GLFrameBuffer.createTexture.

Override this method in a derived class to set up the backing texture as you like.

Annotations
@Override
disposeColorTextureback to summary
protected void disposeColorTexture(Cubemap colorTexture)

Implements abstract com.badlogic.gdx.graphics.glutils.GLFrameBuffer.disposeColorTexture.

Doc from com.badlogic.gdx.graphics.glutils.GLFrameBuffer.disposeColorTexture.

Override this method in a derived class to dispose the backing texture as you like.

Annotations
@Override
getSideback to summary
public Cubemap.CubemapSide getSide()

Get the currently bound side.

nextSideback to summary
public boolean nextSide()

Bind the next side of cubemap and return false if no more side. Should be called in between a call to begin() and #end to cycle to each side of the cubemap to render on.