Package arc.graphics.gl
Class GLFrameBuffer<T extends GLTexture>
java.lang.Object
arc.graphics.gl.GLFrameBuffer<T>
- All Implemented Interfaces:
Disposable
- Direct Known Subclasses:
FrameBuffer
,FrameBufferCubemap
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 gltexture for the color attachment and a renderbuffer for the depth buffer. You can get a hold of the
gltexture by 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
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
static class
static class
protected static class
protected static class
protected static class
GLFrameBuffer.GLFrameBufferBuilder<U extends GLFrameBuffer<? extends GLTexture>>
-
Field Summary
Modifier and TypeFieldDescriptionprotected GLFrameBuffer.GLFrameBufferBuilder<? extends GLFrameBuffer<T>>
protected static int
# of nested buffers right nowprotected static GLFrameBuffer
the currently bound framebuffer; null for the default one.protected static int
the default framebuffer handle, a.k.a screen.protected static boolean
true if we have polled for the default handle already.protected int
the depthbuffer render object handleprotected int
the depth stencil packed render buffer object handleprotected int
the framebuffer handleprotected static final int
protected boolean
if has depth stencil packed bufferprotected boolean
if multiple texture attachments are presentprotected GLFrameBuffer
the framebuffer that was bound before this one began (null to indicate that nothing was bound)protected int
the stencilbuffer render object handlethe color buffer texture -
Constructor Summary
ModifierConstructorDescriptionprotected
GLFrameBuffer
(GLFrameBuffer.GLFrameBufferBuilder<? extends GLFrameBuffer<T>> bufferBuilder) Creates a GLFrameBuffer from the specifications provided by bufferBuilder -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract void
attachFrameBufferColorTexture
(T texture) Override this method in a derived class to attach the backing texture to the GL framebuffer object.void
begin()
Binds the frame buffer and sets the viewport accordingly, so everything gets drawn to it.void
Flushes the batch, begins this buffer and clears the screen.void
Begins the buffer without setting the viewport or flushing the batch.void
bind()
Makes the frame buffer current so everything gets drawn to it.protected void
build()
protected abstract T
createTexture
(GLFrameBuffer.FrameBufferTextureAttachmentSpec attachmentSpec) Override this method in a derived class to set up the backing texture as you like.void
dispose()
Releases all resources associated with the FrameBuffer.protected abstract void
disposeColorTexture
(T colorTexture) Override this method in a derived class to dispose the backing texture as you like.void
end()
Unbinds the framebuffer, all drawing will be performed to the normal framebuffer from here on.void
endBind()
Stop binding.static int
int
protected int
int
int
int
Convenience method to return the first Texture attachment present in the fboReturn the Texture attachments attached to the fboint
getWidth()
boolean
isBound()
protected void
Sets viewport to the dimensions of framebuffer.static void
unbind()
Unbinds the framebuffer, all drawing will be performed to the normal framebuffer from here on.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
-
Field Details
-
GL_DEPTH24_STENCIL8_OES
protected static final int GL_DEPTH24_STENCIL8_OES- See Also:
-
currentBoundFramebuffer
the currently bound framebuffer; null for the default one. -
defaultFramebufferHandle
protected static int defaultFramebufferHandlethe default framebuffer handle, a.k.a screen. -
bufferNesting
protected static int bufferNesting# of nested buffers right now -
defaultFramebufferHandleInitialized
protected static boolean defaultFramebufferHandleInitializedtrue if we have polled for the default handle already. -
textureAttachments
the color buffer texture -
lastBoundFramebuffer
the framebuffer that was bound before this one began (null to indicate that nothing was bound) -
framebufferHandle
protected int framebufferHandlethe framebuffer handle -
depthbufferHandle
protected int depthbufferHandlethe depthbuffer render object handle -
stencilbufferHandle
protected int stencilbufferHandlethe stencilbuffer render object handle -
depthStencilPackedBufferHandle
protected int depthStencilPackedBufferHandlethe depth stencil packed render buffer object handle -
hasDepthStencilPackedBuffer
protected boolean hasDepthStencilPackedBufferif has depth stencil packed buffer -
isMRT
protected boolean isMRTif multiple texture attachments are present -
bufferBuilder
protected GLFrameBuffer.GLFrameBufferBuilder<? extends GLFrameBuffer<T extends GLTexture>> bufferBuilder
-
-
Constructor Details
-
GLFrameBuffer
protected GLFrameBuffer(GLFrameBuffer.GLFrameBufferBuilder<? extends GLFrameBuffer<T>> bufferBuilder) Creates a GLFrameBuffer from the specifications provided by bufferBuilder
-
-
Method Details
-
getBufferNesting
public static int getBufferNesting() -
unbind
public static void unbind()Unbinds the framebuffer, all drawing will be performed to the normal framebuffer from here on. -
getTexture
Convenience method to return the first Texture attachment present in the fbo -
getTextureAttachments
Return the Texture attachments attached to the fbo -
createTexture
Override this method in a derived class to set up the backing texture as you like. -
disposeColorTexture
Override this method in a derived class to dispose the backing texture as you like. -
attachFrameBufferColorTexture
Override this method in a derived class to attach the backing texture to the GL framebuffer object. -
build
protected void build() -
dispose
public void dispose()Releases all resources associated with the FrameBuffer.- Specified by:
dispose
in interfaceDisposable
-
bind
public void bind()Makes the frame buffer current so everything gets drawn to it. -
isBound
public boolean isBound() -
begin
Flushes the batch, begins this buffer and clears the screen. -
begin
public void begin()Binds the frame buffer and sets the viewport accordingly, so everything gets drawn to it. -
beginBind
public void beginBind()Begins the buffer without setting the viewport or flushing the batch. -
setFrameBufferViewport
protected void setFrameBufferViewport()Sets viewport to the dimensions of framebuffer. Called bybegin()
. -
end
public void end()Unbinds the framebuffer, all drawing will be performed to the normal framebuffer from here on. -
endBind
public void endBind()Stop binding. This does not flush the batch or change the viewport. -
getFramebufferHandle
public int getFramebufferHandle()- Returns:
- The OpenGL handle of the framebuffer (see
GL20.glGenFramebuffer()
)
-
getDepthBufferHandle
public int getDepthBufferHandle()- Returns:
- The OpenGL handle of the (optional) depth buffer (see
GL20.glGenRenderbuffer()
). May return 0 even if depth buffer enabled
-
getStencilBufferHandle
public int getStencilBufferHandle()- Returns:
- The OpenGL handle of the (optional) stencil buffer (see
GL20.glGenRenderbuffer()
). May return 0 even if stencil buffer enabled
-
getDepthStencilPackedBuffer
protected int getDepthStencilPackedBuffer()- Returns:
- The OpenGL handle of the packed depth & stencil buffer (GL_DEPTH24_STENCIL8_OES) or 0 if not used.
-
getHeight
public int getHeight()- Returns:
- the height of the framebuffer in pixels
-
getWidth
public int getWidth()- Returns:
- the width of the framebuffer in pixels
-