Top Description Inners Fields Constructors Methods
com.jogamp.opengl

public Class FBObject

extends Object
Class Inheritance
Imports
java.util.Arrays, com.jogamp.opengl.GL, .GL2ES2, .GL2ES3, .GL2GL3, .GL3, .GLBase, .GLCapabilities, .GLCapabilitiesImmutable, .GLContext, .GLException, .GLProfile, .FBObject.Attachment.Type, jogamp.opengl.Debug, com.jogamp.common.ExceptionUtils, com.jogamp.common.util.PropertyAccess

Core utility class simplifying usage of framebuffer objects (FBO) with all GLProfiles.

Supports on-the-fly reconfiguration of dimension and multisample buffers via reset(GL, int, int, int, boolean) while preserving the Attachment references.

Integrates default read/write framebuffers via GLContext#getDefaultReadFramebuffer() and GLContext#getDefaultReadFramebuffer(), which is being hooked at GL#glBindFramebuffer(int, int) when the default (zero) framebuffer is selected.

FIXME: Implement support for Type#DEPTH_TEXTURE, Type#STENCIL_TEXTURE .

Nested and Inner Type Summary

Modifier and TypeClass and Description
public abstract static class
FBObject.Attachment

Common super class of all FBO attachments

public static class
FBObject.ColorAttachment

Color render buffer FBO attachment

public static interface
FBObject.Colorbuffer

Generic color buffer FBO attachment, either of type ColorAttachment or TextureAttachment.

private static enum
public static class
FBObject.RenderAttachment

Other renderbuffer attachment which maybe a colorbuffer, depth or stencil.

public static class
FBObject.TextureAttachment

Texture FBO attachment

Field Summary

Modifier and TypeField and Description
private boolean
public static final int
CHOSEN_BITS

Request current context drawable's chosen depth- or stencil-bits; value

private FBObject.Colorbuffer[]
private int
protected static final boolean
public static final int
DEFAULT_BITS

Request default bit count for depth- or stencil buffer (depth 24 bits, stencil 8 bits), value

private FBObject.RenderAttachment
private boolean
private boolean
private int
private static final boolean
private boolean
private int
private boolean
private boolean
private int
public static final int
MAXIMUM_BITS

Request maximum bit count for depth- or stencil buffer (depth 32 bits, stencil 16 bits), value

private int
private int
private int
private boolean
private boolean
public static final int
REQUESTED_BITS

Request current context drawable's requested depth- or stencil-bits; value

private boolean
private int
private FBObject.Colorbuffer
private FBObject
private boolean
private FBObject.RenderAttachment
private boolean
private boolean
private boolean
private boolean
private int
private static final int
private int
private int

Constructor Summary

AccessConstructor and Description
public
FBObject()

Creates an uninitialized FBObject instance.

Method Summary

Modifier and TypeMethod and Description
private final void
addColorAttachment(final int point, final FBObject.Colorbuffer ca, final boolean validate)

public final FBObject.ColorAttachment

Returns:

ColorAttachment instance describing the new attached colorbuffer if bound and configured successfully, otherwise GLException is thrown
attachColorbuffer
(final GL
the current GL context
gl
,
final int
the color attachment point ranging from [0..getMaxColorAttachments()-1]
attachmentPoint
,
final boolean
set to true if you request alpha channel, otherwise false;
alpha
)

Attaches a newly created and initialized Colorbuffer, i.e. a ColorAttachment, at the given attachment point.

public final FBObject.ColorAttachment

Returns:

ColorAttachment instance describing the new attached colorbuffer if bound and configured successfully, otherwise GLException is thrown
attachColorbuffer
(final GL
the current GL context
gl
,
final int
the color attachment point ranging from [0..getMaxColorAttachments()-1]
attachmentPoint
,
final int internalFormat)

Attaches a newly created and initialized Colorbuffer, i.e. a ColorAttachment, at the given attachment point.

public final FBObject.Colorbuffer

Returns:

given Colorbuffer instance if bound and configured successfully, otherwise GLException is thrown
attachColorbuffer
(final GL gl, final int
the color attachment point ranging from [0..getMaxColorAttachments()-1]
attachmentPoint
,
final FBObject.Colorbuffer
the to be attached Colorbuffer
colbuf
)

Attaches a Colorbuffer at the given attachment point and initializes it, if not done yet.

private final FBObject.Colorbuffer
attachColorbufferImpl(final GL gl, final int attachmentPoint, final FBObject.Colorbuffer colbuf)

public final void
attachRenderbuffer(final GL gl, final FBObject.Attachment.Type atype, final int
desired bits for depth or stencil, may use generic values DEFAULT_BITS, REQUESTED_BITS, CHOSEN_BITS or MAXIMUM_BITS.
reqBits
)

Attaches one depth, stencil or packed-depth-stencil buffer to this FBO's instance, selecting the internalFormat automatically.

public final void
attachRenderbuffer(final GL
the current GL context
gl
,
final int internalFormat)

Attaches one depth, stencil or packed-depth-stencil buffer to this FBO's instance, depending on the internalFormat.

protected final void
attachRenderbufferImpl(final GL gl, final FBObject.Attachment.Type atype, final int internalFormat)

private final void
attachRenderbufferImpl2(final GL gl, final FBObject.Attachment.Type atype, final int internalFormat)

public final FBObject.TextureAttachment

Returns:

TextureAttachment instance describing the new attached texture colorbuffer if bound and configured successfully, otherwise GLException is thrown
attachTexture2D
(final GL
the current GL context
gl
,
final int
the color attachment point ranging from [0..getMaxColorAttachments()-1]
attachmentPoint
,
final boolean
set to true if you request alpha channel, otherwise false;
alpha
)

Attaches a Colorbuffer, i.e. TextureAttachment, to this FBO's instance at the given attachment point, selecting the texture data type and format automatically.

public final FBObject.TextureAttachment

Returns:

TextureAttachment instance describing the new attached texture colorbuffer if bound and configured successfully, otherwise GLException is thrown
attachTexture2D
(final GL
the current GL context
gl
,
final int
the color attachment point ranging from [0..getMaxColorAttachments()-1]
attachmentPoint
,
final boolean
set to true if you request alpha channel, otherwise false;
alpha
,
final int
if > 0 value for GL#GL_TEXTURE_MAG_FILTER
magFilter
,
final int
if > 0 value for GL#GL_TEXTURE_MIN_FILTER
minFilter
,
final int
if > 0 value for GL#GL_TEXTURE_WRAP_S
wrapS
,
final int
if > 0 value for GL#GL_TEXTURE_WRAP_T
wrapT
)

Attaches a Colorbuffer, i.e. TextureAttachment, to this FBO's instance at the given attachment point, selecting the texture data type and format automatically.

public final FBObject.TextureAttachment

Returns:

TextureAttachment instance describing the new attached texture colorbuffer if bound and configured successfully, otherwise GLException is thrown
attachTexture2D
(final GL
the current GL context
gl
,
final int
the color attachment point ranging from [0..getMaxColorAttachments()-1]
attachmentPoint
,
final int internalFormat, final int dataFormat, final int dataType, final int
if > 0 value for GL#GL_TEXTURE_MAG_FILTER
magFilter
,
final int
if > 0 value for GL#GL_TEXTURE_MIN_FILTER
minFilter
,
final int
if > 0 value for GL#GL_TEXTURE_WRAP_S
wrapS
,
final int
if > 0 value for GL#GL_TEXTURE_WRAP_T
wrapT
)

Attaches a Colorbuffer, i.e. TextureAttachment, to this FBO's instance at the given attachment point.

public final void
bind(final GL
the current GL context
gl
)

Bind this FBO, i.e. bind write framebuffer to getWriteFramebuffer().

private final void
private final boolean
checkNoError(final GL gl, final int err, final String exceptionMessage)

private static int
checkPreGLError(final GL gl)

public final FBObject.ColorAttachment

Returns:

uninitialized ColorAttachment instance describing the new attached colorbuffer
createColorAttachment
(final boolean
set to true if you request alpha channel, otherwise false;
alpha
)

Creates a ColorAttachment, selecting the format automatically.

public static final FBObject.ColorAttachment

Returns:

uninitialized ColorAttachment instance describing the new attached colorbuffer
createColorAttachment
(final int
set to true if you request alpha channel, otherwise false;
internalFormat
,
final int samples, final int width, final int height)

Creates a ColorAttachment, selecting the format automatically.

public static final FBObject.TextureAttachment

Returns:

the created and uninitialized color TextureAttachment
createColorTextureAttachment
(final GL
the used GLContext's GL object
gl
,
final boolean
set to true if you request alpha channel, otherwise false;
alpha
,
final int
texture width
width
,
final int
texture height
height
)

Creates a color TextureAttachment, i.e. type Type#COLOR_TEXTURE, selecting the texture data type and format automatically.

public static final FBObject.TextureAttachment

Returns:

the created and uninitialized color TextureAttachment
createColorTextureAttachment
(final GL
the used GLContext's GL object
gl
,
final boolean
set to true if you request alpha channel, otherwise false;
alpha
,
final int
texture width
width
,
final int
texture height
height
,
final int
if > 0 value for GL#GL_TEXTURE_MAG_FILTER
magFilter
,
final int
if > 0 value for GL#GL_TEXTURE_MIN_FILTER
minFilter
,
final int
if > 0 value for GL#GL_TEXTURE_WRAP_S
wrapS
,
final int
if > 0 value for GL#GL_TEXTURE_WRAP_T
wrapT
)

Creates a color TextureAttachment, i.e. type Type#COLOR_TEXTURE, selecting the texture data type and format automatically.

public static final FBObject.TextureAttachment
createColorTextureAttachment(final GL gl, final int internalFormat, final int width, final int height, final int magFilter, final int minFilter, final int wrapS, final int wrapT)

public static final FBObject.TextureAttachment

Returns:

the created and uninitialized color TextureAttachment
createColorTextureAttachment
(final int internalFormat, final int
texture width
width
,
final int
texture height
height
,
final int dataFormat, final int dataType, final int
if > 0 value for GL#GL_TEXTURE_MAG_FILTER
magFilter
,
final int
if > 0 value for GL#GL_TEXTURE_MIN_FILTER
minFilter
,
final int
if > 0 value for GL#GL_TEXTURE_WRAP_S
wrapS
,
final int
if > 0 value for GL#GL_TEXTURE_WRAP_T
wrapT
)

Creates a color TextureAttachment, i.e. type Type#COLOR_TEXTURE.

public static final FBObject.RenderAttachment
createRenderAttachment(final FBObject.Attachment.Type type, final int internalFormat, final int samples, final int width, final int height)

public final void
destroy(final GL
the current GL context
gl
)

public final void
detachAll(final GL
the current GL context
gl
)

Detaches all ColorAttachments, TextureAttachments and RenderAttachments and disposes them.

public final void
detachAllColorbuffer(final GL
the current GL context
gl
)

Detaches all ColorAttachments and TextureAttachments and disposes them.

private final void
detachAllImpl(final GL gl, final boolean detachNonColorbuffer, final boolean recreate, final int sampleCountChange)

public final void
public final void
detachAllTexturebuffer(final GL
the current GL context
gl
)

Detaches all TextureAttachments and disposes them.

public final FBObject.Colorbuffer

Returns:

the detached Colorbuffer
detachColorbuffer
(final GL gl, final int attachmentPoint, final boolean
true if the Colorbuffer shall be disposed
dispose
)

Detaches a Colorbuffer, i.e. ColorAttachment or TextureAttachment.

private final FBObject.Colorbuffer
detachColorbufferImpl(final GL gl, final int attachmentPoint, final FBObject.DetachAction detachAction, final int sampleCountChange)

public final void
detachRenderbuffer(final GL gl, final FBObject.Attachment.Type atype, final boolean
true if the Colorbuffer shall be disposed
dispose
)

private final FBObject.RenderAttachment
detachRenderbufferImpl(final GL gl, FBObject.Attachment.Type atype, final FBObject.DetachAction detachAction)

public final void
formatToGLCapabilities(final GLCapabilities
the destination for format bits
caps
)

Writes the internal format of the attachments to the given GLCapabilities object.

private final void
private final void
public final FBObject.Colorbuffer
getColorbuffer(final int attachmentPoint)

Return the Colorbuffer attachment at attachmentPoint if it is attached to this FBO, otherwise null.

public final FBObject.Colorbuffer
getColorbuffer(final FBObject.Colorbuffer ca)

Returns the passed Colorbuffer if it is attached to this FBO, otherwise null.

public final int

Returns:

-1 if the Colorbuffer could not be found, otherwise [0..getMaxColorAttachments()-1]
getColorbufferAttachmentPoint
(final FBObject.Colorbuffer
the Colorbuffer to look for.
ca
)

Finds the passed Colorbuffer within the valid range of attachment points using reference comparison only.

public final int
getColorbufferCount()

Return the number of attached Colorbuffers

public final int
public final FBObject.RenderAttachment
getDepthAttachment()

Return the depth RenderAttachment attachment.

private final int
getDepthIFormat(final int reqBits)

public final int
getHeight()

Returns the height

public final int
getMaxColorAttachments()

Returns the maximum number of colorbuffer attachments.

public final int
public final int
public final int
public final int
getNumSamples()

Returns the number of samples for multisampling (MSAA).

public final int
getReadFramebuffer()

Returns the framebuffer name to read from.

public final FBObject.Colorbuffer
getSamplingSink()

Return the multisampling Colorbuffer sink, if using multisampling.

public final FBObject
getSamplingSinkFBO()

Return the complete multisampling FBObject sink, if using multisampling.

public final int

Returns:

The FB status. GL.GL_FRAMEBUFFER_COMPLETE if ok, otherwise return GL FBO error state or -1
getStatus
()

Note that the status may reflect an incomplete state during transition of attachments.

public final String
getStatusString()

return the getStatus() as a string.

public static final String
getStatusString(final int fbStatus)

public final FBObject.RenderAttachment
getStencilAttachment()

Return the stencil RenderAttachment attachment, if exist.

private final int
getStencilIFormat(final int reqBits)

public final int
getTextureAttachmentCount()

Return the number of attached TextureAttachments

public final int
getWidth()

Returns the width

public final int
getWriteFramebuffer()

Returns the framebuffer name to render to.

private static boolean
hasAlpha(final int format)

public final boolean
hasAttachmentUsingAlpha()

Returns true if any attached Colorbuffer uses alpha, otherwise false.

public final boolean
public void
init(final GL
the current GL context
gl
,
final int
the initial width, it's minimum is capped to 1
newWidth
,
final int
the initial height, it's minimum is capped to 1
newHeight
,
final int
if > 0, MSAA will be used, otherwise no multisampling. Will be capped to getMaxSamples().
newSamples
)

Initializes this FBO's instance.

public final boolean
isBound(final GL
the current GL context
gl
)

Returns true if framebuffer object is bound via bind(GL), otherwise false.

public final boolean
isBound()

Returns true if framebuffer object is bound via bind(GL), otherwise false.

public final boolean
public final boolean
isInitialized()

Returns true if this instance has been initialized with reset(GL, int, int) or reset(GL, int, int, int, boolean), otherwise false

public final boolean
isModified()

Returns true if size, sample-count or any attachment of this instance or its sampling-sink has been modified since last sync, use, reset or resetSamplingSink.

public final boolean
isSamplingBufferDirty()

Returns true if the multisampling colorbuffer (msaa-buffer) has been flagged dirty by a previous call of bind(GL), otherwise false.

public final boolean
isStatusValid()

The status may even be valid if incomplete during transition of attachments.

public final void
markUnbound()

Method simply marks this FBO unbound w/o interfering w/ the bound framebuffer as perfomed by unbind(GL).

pack-priv int
private final void
removeColorAttachment(final int point, final FBObject.Colorbuffer ca)

public final boolean

Returns:

true if this instance has been modified, otherwise false.
reset
(final GL
the current GL context
gl
,
int
the new width, it's minimum is capped to 1
newWidth
,
int
the new height, it's minimum is capped to 1
newHeight
,
int
if > 0, MSAA will be used, otherwise no multisampling. Will be capped to getMaxSamples().
newSamples
)

Resets this FBO's instance.

public final boolean

Returns:

true if this instance has been modified, otherwise false.
resetSamplingSink
(final GL
the current GL context
gl
)

Manually validates the MSAA sampling sink, if used.

private final void
resetSizeImpl(final GL
the current GL context
gl
,
final int
the new width, it's minimum is capped to 1
newWidth
,
final int
the new height, it's minimum is capped to 1
newHeight
)

Simply resets this instance's size only, w/o validation.

private final boolean
private final boolean
sampleSinkExFormatMismatch(final GL gl)

For GLES3, sampling-sink Colorbuffer internal format must be equal w/ the sampling-source Colorbuffer.

private final boolean
public FBObject

Returns:

the previous sampling sink or null if none was attached
setSamplingSink
(final FBObject
the new and initialized FBO sampling sink to use, or null to remove current sampling sink
newSamplingSink
)

Setting this FBO sampling sink.

public final boolean
supportsDepth(final int
16, 24 or 32 bits
bits
)

Returns true if GL#GL_DEPTH_COMPONENT16, GL#GL_DEPTH_COMPONENT24 or GL#GL_DEPTH_COMPONENT32 is supported, otherwise false.

public final boolean
supportsPackedDepthStencil()

Returns true if GL#GL_DEPTH24_STENCIL8 is supported, otherwise false.

public final boolean
supportsRGBA8()

Returns true if renderbuffer accepts internal format GL#GL_RGB8 and GL#GL_RGBA8, otherwise false.

public final boolean
supportsStencil(final int
1, 4, 8 or 16 bits
bits
)

Returns true if GL#GL_STENCIL_INDEX1, GL#GL_STENCIL_INDEX4, GL#GL_STENCIL_INDEX8 or GL2GL3#GL_STENCIL_INDEX16 is supported, otherwise false.

public final void
syncSamplingSink(final GL
the current GL context
gl
)

If multisampling is being used and flagged dirty by a previous call of bind(GL) or after initialization, the msaa-buffers are sampled to it's sink getSamplingTextureSink().

pack-priv static String
toHexString(final int v)

public final String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
public final void
unbind(final GL
the current GL context
gl
)

Unbind this FBO, i.e. bind read and write framebuffer to default, see GLBase#getDefaultDrawFramebuffer().

public final void
unuse(final GL gl)

Unbind texture, ie bind 'non' texture 0

Leaves the FBO unbound.

private final void
updateStatus(final GL gl)

public final void
use(final GL
the current GL context
gl
,
final FBObject.TextureAttachment
TextureAttachment to use, prev. attached w/ attachTexture2D(..), may be null in case no TextureAttachment is used.
ta
)

Synchronize the sampling sink and bind the given TextureAttachment, if not null.

private final void
validateAddColorAttachment(final int point, final FBObject.Colorbuffer ca)

private void
private final void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait