Class FrameBufferCubemap
- All Implemented Interfaces:
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 cubemap for the color attachment and a renderbuffer for the depth buffer. You can get a hold of the
cubemap by GLFrameBuffer.getTexture()
. 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();
Gl.clearColor(0, 0, 0, 1);
Gl.clear(Gl.colorBufferBit | Gl.depthBufferBit);
//render something
}
frameBuffer.end();
Cubemap cubemap = frameBuffer.getColorBufferCubemap();
-
Nested Class Summary
Nested classes/interfaces inherited from class arc.graphics.gl.GLFrameBuffer
GLFrameBuffer.FloatFrameBufferBuilder, GLFrameBuffer.FrameBufferBuilder, GLFrameBuffer.FrameBufferCubemapBuilder, GLFrameBuffer.FrameBufferRenderBufferAttachmentSpec, GLFrameBuffer.FrameBufferTextureAttachmentSpec, GLFrameBuffer.GLFrameBufferBuilder<U extends GLFrameBuffer<? extends GLTexture>>
-
Field Summary
Fields inherited from class arc.graphics.gl.GLFrameBuffer
bufferBuilder, bufferNesting, currentBoundFramebuffer, defaultFramebufferHandle, defaultFramebufferHandleInitialized, depthbufferHandle, depthStencilPackedBufferHandle, framebufferHandle, GL_DEPTH24_STENCIL8_OES, hasDepthStencilPackedBuffer, isMRT, lastBoundFramebuffer, stencilbufferHandle, textureAttachments
-
Constructor Summary
ModifierConstructorDescriptionprotected
FrameBufferCubemap
(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
Modifier and TypeMethodDescriptionprotected void
attachFrameBufferColorTexture
(Cubemap texture) Override this method in a derived class to attach the backing texture to the GL framebuffer object.void
bind()
Makes the frame buffer current so everything gets drawn to it, must be followed by call to eithernextSide()
orbindSide(arc.graphics.Cubemap.CubemapSide)
to activate the side to render onto.protected void
bindSide
(Cubemap.CubemapSide side) Bind the side, making it active to render on.protected Cubemap
createTexture
(GLFrameBuffer.FrameBufferTextureAttachmentSpec attachmentSpec) Override this method in a derived class to set up the backing texture as you like.protected void
disposeColorTexture
(Cubemap colorTexture) Override this method in a derived class to dispose the backing texture as you like.getSide()
Get the currently bound side.boolean
nextSide()
Bind the next side of cubemap and return false if no more side.Methods inherited from class arc.graphics.gl.GLFrameBuffer
begin, begin, beginBind, build, dispose, end, endBind, getBufferNesting, getDepthBufferHandle, getDepthStencilPackedBuffer, getFramebufferHandle, getHeight, getStencilBufferHandle, getTexture, getTextureAttachments, getWidth, isBound, setFrameBufferViewport, unbind
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface arc.util.Disposable
isDisposed
-
Constructor Details
-
FrameBufferCubemap
protected FrameBufferCubemap(GLFrameBuffer.GLFrameBufferBuilder<? extends GLFrameBuffer<Cubemap>> bufferBuilder) Creates a GLFrameBuffer from the specifications provided by bufferBuilder -
FrameBufferCubemap
Creates a new FrameBuffer having the given dimensions and potentially a depth buffer attached. -
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:
ArcRuntimeException
- in case the FrameBuffer could not be created
-
-
Method Details
-
createTexture
Description copied from class:GLFrameBuffer
Override this method in a derived class to set up the backing texture as you like.- Specified by:
createTexture
in classGLFrameBuffer<Cubemap>
-
disposeColorTexture
Description copied from class:GLFrameBuffer
Override this method in a derived class to dispose the backing texture as you like.- Specified by:
disposeColorTexture
in classGLFrameBuffer<Cubemap>
-
attachFrameBufferColorTexture
Description copied from class:GLFrameBuffer
Override this method in a derived class to attach the backing texture to the GL framebuffer object.- Specified by:
attachFrameBufferColorTexture
in 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(arc.graphics.Cubemap.CubemapSide)
to activate the side to render onto.- Overrides:
bind
in 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
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
Get the currently bound side.
-