Class FrameBufferCubemap
- java.lang.Object
-
- com.badlogic.gdx.graphics.glutils.GLFrameBuffer<Cubemap>
-
- com.badlogic.gdx.graphics.glutils.FrameBufferCubemap
-
- All Implemented Interfaces:
Disposable
public class FrameBufferCubemap extends GLFrameBuffer<Cubemap>
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
GLFrameBuffer.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();
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.badlogic.gdx.graphics.glutils.GLFrameBuffer
GLFrameBuffer.FloatFrameBufferBuilder, GLFrameBuffer.FrameBufferBuilder, GLFrameBuffer.FrameBufferCubemapBuilder, GLFrameBuffer.FrameBufferRenderBufferAttachmentSpec, GLFrameBuffer.FrameBufferTextureAttachmentSpec, GLFrameBuffer.GLFrameBufferBuilder<U extends GLFrameBuffer<? extends GLTexture>>
-
-
Field Summary
-
Fields inherited from class com.badlogic.gdx.graphics.glutils.GLFrameBuffer
bufferBuilder, buffers, defaultFramebufferHandle, defaultFramebufferHandleInitialized, depthbufferHandle, depthStencilPackedBufferHandle, framebufferHandle, GL_DEPTH24_STENCIL8_OES, hasDepthStencilPackedBuffer, isMRT, stencilbufferHandle, textureAttachments
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedFrameBufferCubemap(GLFrameBuffer.GLFrameBufferBuilder<? extends GLFrameBuffer<Cubemap>> bufferBuilder)Creates a GLFrameBuffer from the specifications provided by bufferBuilderFrameBufferCubemap(Pixmap.Format format, int width, int height, boolean hasDepth)Creates a new FrameBuffer having the given dimensions and potentially a depth buffer attached.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.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidattachFrameBufferColorTexture(Cubemap texture)Override this method in a derived class to attach the backing texture to the GL framebuffer object.voidbind()Makes the frame buffer current so everything gets drawn to it, must be followed by call to eithernextSide()orbindSide(com.badlogic.gdx.graphics.Cubemap.CubemapSide)to activate the side to render onto.protected voidbindSide(Cubemap.CubemapSide side)Bind the side, making it active to render on.protected CubemapcreateTexture(GLFrameBuffer.FrameBufferTextureAttachmentSpec attachmentSpec)Override this method in a derived class to set up the backing texture as you like.protected voiddisposeColorTexture(Cubemap colorTexture)Override this method in a derived class to dispose the backing texture as you like.Cubemap.CubemapSidegetSide()Get the currently bound side.booleannextSide()Bind the next side of cubemap and return false if no more side.-
Methods inherited from class com.badlogic.gdx.graphics.glutils.GLFrameBuffer
begin, build, clearAllFrameBuffers, dispose, end, end, getColorBufferTexture, getDepthBufferHandle, getDepthStencilPackedBuffer, getFramebufferHandle, getHeight, getManagedStatus, getManagedStatus, getStencilBufferHandle, getTextureAttachments, getWidth, invalidateAllFrameBuffers, setFrameBufferViewport, unbind
-
-
-
-
Constructor Detail
-
FrameBufferCubemap
protected FrameBufferCubemap(GLFrameBuffer.GLFrameBufferBuilder<? extends GLFrameBuffer<Cubemap>> bufferBuilder)
Creates a GLFrameBuffer from the specifications provided by bufferBuilder- Parameters:
bufferBuilder-
-
FrameBufferCubemap
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.- Parameters:
format-width-height-hasDepth-
-
FrameBufferCubemap
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- 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 cubemap in pixelsheight- the height of the cubemap in pixelshasDepth- whether to attach a depth bufferhasStencil- whether to attach a stencil buffer- Throws:
GdxRuntimeException- in case the FrameBuffer could not be created
-
-
Method Detail
-
createTexture
protected Cubemap createTexture(GLFrameBuffer.FrameBufferTextureAttachmentSpec attachmentSpec)
Description copied from class:GLFrameBufferOverride this method in a derived class to set up the backing texture as you like.- Specified by:
createTexturein classGLFrameBuffer<Cubemap>
-
disposeColorTexture
protected void disposeColorTexture(Cubemap colorTexture)
Description copied from class:GLFrameBufferOverride this method in a derived class to dispose the backing texture as you like.- Specified by:
disposeColorTexturein classGLFrameBuffer<Cubemap>
-
attachFrameBufferColorTexture
protected void attachFrameBufferColorTexture(Cubemap texture)
Description copied from class:GLFrameBufferOverride this method in a derived class to attach the backing texture to the GL framebuffer object.- Specified by:
attachFrameBufferColorTexturein classGLFrameBuffer<Cubemap>
-
bind
public void bind()
Makes the frame buffer current so everything gets drawn to it, must be followed by call to eithernextSide()orbindSide(com.badlogic.gdx.graphics.Cubemap.CubemapSide)to activate the side to render onto.- Overrides:
bindin classGLFrameBuffer<Cubemap>
-
nextSide
public boolean nextSide()
Bind the next side of cubemap and return false if no more side. Should be called in between a call toGLFrameBuffer.begin()and #end to cycle to each side of the cubemap to render on.
-
bindSide
protected void bindSide(Cubemap.CubemapSide side)
Bind the side, making it active to render on. Should be called in between a call toGLFrameBuffer.begin()andGLFrameBuffer.end().- Parameters:
side- The side to bind
-
getSide
public Cubemap.CubemapSide getSide()
Get the currently bound side.
-
-