public class FBObject extends Object
GLProfile
s.
Supports on-the-fly reconfiguration of dimension and multisample buffers via reset(GL, int, int, int)
while preserving the FBObject.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 FBObject.Attachment.Type.DEPTH_TEXTURE
, FBObject.Attachment.Type.STENCIL_TEXTURE
.
Modifier and Type | Class and Description |
---|---|
static class |
FBObject.Attachment
Common super class of all attachments
|
static class |
FBObject.ColorAttachment
Color render buffer attachment
|
static interface |
FBObject.Colorbuffer
Marker interface, denotes a color buffer attachment.
|
static class |
FBObject.RenderAttachment
Other renderbuffer attachment which maybe a colorbuffer, depth or stencil.
|
static class |
FBObject.TextureAttachment
Texture attachment
|
Constructor and Description |
---|
FBObject()
Creates an uninitialized FBObject instance.
|
Modifier and Type | Method and Description |
---|---|
FBObject.ColorAttachment |
attachColorbuffer(GL gl,
int attachmentPoint,
boolean alpha)
Attaches a Color Buffer to this FBO's instance at the given attachment point,
selecting the format automatically.
|
FBObject.ColorAttachment |
attachColorbuffer(GL gl,
int attachmentPoint,
FBObject.ColorAttachment colA)
Attaches a Color Buffer to this FBO's instance at the given attachment point.
|
FBObject.ColorAttachment |
attachColorbuffer(GL gl,
int attachmentPoint,
int internalFormat)
Attaches a Color Buffer to this FBO's instance at the given attachment point.
|
void |
attachRenderbuffer(GL gl,
FBObject.Attachment.Type atype,
int reqBits)
Attaches one depth, stencil or packed-depth-stencil buffer to this FBO's instance,
selecting the internalFormat automatically.
|
void |
attachRenderbuffer(GL gl,
int internalFormat)
Attaches one depth, stencil or packed-depth-stencil buffer to this FBO's instance,
depending on the
internalFormat . |
FBObject.TextureAttachment |
attachTexture2D(GL gl,
int attachmentPoint,
boolean alpha)
Attaches a Texture2D Color Buffer to this FBO's instance at the given attachment point,
selecting the texture data type and format automatically.
|
FBObject.TextureAttachment |
attachTexture2D(GL gl,
int attachmentPoint,
boolean alpha,
int magFilter,
int minFilter,
int wrapS,
int wrapT)
Attaches a Texture2D Color Buffer to this FBO's instance at the given attachment point,
selecting the texture data type and format automatically.
|
FBObject.TextureAttachment |
attachTexture2D(GL gl,
int attachmentPoint,
FBObject.TextureAttachment texA)
Attaches a Texture2D Color Buffer to this FBO's instance at the given attachment point.
|
FBObject.TextureAttachment |
attachTexture2D(GL gl,
int attachmentPoint,
int internalFormat,
int dataFormat,
int dataType,
int magFilter,
int minFilter,
int wrapS,
int wrapT)
Attaches a Texture2D Color Buffer to this FBO's instance at the given attachment point.
|
void |
bind(GL gl)
Bind this FBO, i.e.
|
void |
destroy(GL gl) |
void |
detachAll(GL gl)
|
void |
detachAllColorbuffer(GL gl)
Detaches all
FBObject.ColorAttachment s and FBObject.TextureAttachment s. |
void |
detachAllRenderbuffer(GL gl) |
void |
detachAllTexturebuffer(GL gl)
Detaches all
FBObject.TextureAttachment s |
void |
detachColorbuffer(GL gl,
int attachmentPoint)
Leaves the FBO bound!
|
void |
detachRenderbuffer(GL gl,
FBObject.Attachment.Type atype) |
int |
getColorAttachmentCount()
Return the number of color/texture attachments
|
FBObject.Colorbuffer |
getColorbuffer(FBObject.Colorbuffer ca)
Returns the passed
FBObject.Colorbuffer if it is attached to this FBO, otherwise null. |
FBObject.Colorbuffer |
getColorbuffer(int attachmentPoint)
Return the
FBObject.Colorbuffer attachment at attachmentPoint if it is attached to this FBO, otherwise null. |
int |
getColorbufferAttachmentPoint(FBObject.Colorbuffer ca)
Finds the passed
FBObject.Colorbuffer within the valid range of attachment points
using reference comparison only. |
FBObject.RenderAttachment |
getDepthAttachment()
Return the depth
FBObject.RenderAttachment attachment. |
int |
getHeight()
Returns the height
|
int |
getMaxColorAttachments()
Returns the maximum number of colorbuffer attachments.
|
int |
getMaxSamples()
Returns the maximum number of samples for multisampling.
|
static int |
getMaxSamples(GL gl) |
int |
getNumSamples()
Returns the number of samples for multisampling (MSAA).
|
int |
getReadFramebuffer()
Returns the framebuffer name to read from.
|
FBObject.TextureAttachment |
getSamplingSink()
Return the multisampling
FBObject.TextureAttachment sink, if using multisampling. |
FBObject |
getSamplingSinkFBO()
Return the complete multisampling
FBObject sink, if using multisampling. |
int |
getStatus()
Note that the status may reflect an incomplete state during transition of attachments.
|
String |
getStatusString()
return the
getStatus() as a string. |
static String |
getStatusString(int fbStatus) |
FBObject.RenderAttachment |
getStencilAttachment()
Return the stencil
FBObject.RenderAttachment attachment, if exist. |
int |
getWidth()
Returns the width
|
int |
getWriteFramebuffer()
Returns the framebuffer name to render to.
|
boolean |
isBound()
|
boolean |
isBound(GL gl)
|
boolean |
isDepthStencilPackedFormat() |
boolean |
isInitialized()
Returns
true if this instance has been initialized with reset(GL, int, int)
or reset(GL, int, int, int) , otherwise false |
boolean |
isSamplingBufferDirty()
Returns
true if the multisampling colorbuffer (msaa-buffer)
has been flagged dirty by a previous call of bind(GL) ,
otherwise false . |
boolean |
isStatusValid()
The status may even be valid if incomplete during transition of attachments.
|
void |
reset(GL gl,
int newWidth,
int newHeight)
Initializes or resets this FBO's instance.
|
void |
reset(GL gl,
int newWidth,
int newHeight,
int newSamples)
Initializes or resets this FBO's instance.
|
static boolean |
supportsBasicFBO(GL gl)
Returns
true if basic FBO support is available, otherwise false . |
boolean |
supportsDepth(int bits)
Returns
true if GL.GL_DEPTH_COMPONENT16 , GL.GL_DEPTH_COMPONENT24 or GL.GL_DEPTH_COMPONENT32 is supported, otherwise false . |
boolean |
supportsFBO(boolean full)
Returns
true if basic or full FBO is supported, otherwise false . |
static boolean |
supportsFullFBO(GL gl)
Returns
true if full FBO support is available, otherwise false . |
boolean |
supportsPackedDepthStencil()
|
boolean |
supportsRGBA8()
|
boolean |
supportsStencil(int 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 . |
void |
syncSamplingBuffer(GL gl)
Samples the multisampling colorbuffer (msaa-buffer) to it's sink
getSamplingSink() . |
String |
toString() |
void |
unbind(GL gl)
Unbind this FBO, i.e.
|
void |
unuse(GL gl)
Unbind texture, ie bind 'non' texture 0
|
void |
use(GL gl,
FBObject.TextureAttachment ta)
Bind the given texture colorbuffer.
|
public FBObject()
Call init(GL, int, int, int)
.. etc to use it.
public static final boolean supportsBasicFBO(GL gl)
true
if basic FBO support is available, otherwise false
.
Basic FBO is supported if the context is either GL-ES >= 2.0, GL >= core 3.0 or implements the extensions
ARB_ES2_compatibility
, ARB_framebuffer_object
, EXT_framebuffer_object
or OES_framebuffer_object
.
Basic FBO support may only include one color attachment and no multisampling, as well as limited internal formats for renderbuffer.
GLContext.hasFBO()
public static final boolean supportsFullFBO(GL gl)
true
if full FBO support is available, otherwise false
.
Full FBO is supported if the context is either GL >= core 3.0 or implements the extensions
ARB_framebuffer_object
, or all of
EXT_framebuffer_object
, EXT_framebuffer_multisample
,
EXT_framebuffer_blit
, GL_EXT_packed_depth_stencil
.
Full FBO support includes multiple color attachments and multisampling.
public static final int getMaxSamples(GL gl)
public final FBObject.Colorbuffer getColorbuffer(int attachmentPoint)
FBObject.Colorbuffer
attachment at attachmentPoint
if it is attached to this FBO, otherwise null.#attachColorbuffer(GL, boolean)
,
#attachColorbuffer(GL, boolean)
,
attachTexture2D(GL, int, boolean, int, int, int, int)
,
attachTexture2D(GL, int, int, int, int, int, int, int, int)
public final int getColorbufferAttachmentPoint(FBObject.Colorbuffer ca)
FBObject.Colorbuffer
within the valid range of attachment points
using reference comparison only.
Note: Slow. Implementation uses a logN array search to save resources, i.e. not using a HashMap.
ca
- the FBObject.Colorbuffer
to look for.FBObject.Colorbuffer
could not be found, otherwise [0..getMaxColorAttachments()
-1]public final FBObject.Colorbuffer getColorbuffer(FBObject.Colorbuffer ca)
FBObject.Colorbuffer
if it is attached to this FBO, otherwise null.
Implementation compares the reference only.
Note: Slow. Uses getColorbufferAttachmentPoint(Colorbuffer)
to determine it's attachment point
to be used for getColorbuffer(int)
#attachColorbuffer(GL, boolean)
,
#attachColorbuffer(GL, boolean)
,
attachTexture2D(GL, int, boolean, int, int, int, int)
,
attachTexture2D(GL, int, int, int, int, int, int, int, int)
public final void reset(GL gl, int newWidth, int newHeight)
In case the new parameters are compatible with the current ones no action will be performed. Otherwise all attachments will be recreated to match the new given parameters.
Currently incompatibility and hence recreation is given if the size or sample count doesn't match for subsequent calls.
Leaves the FBO bound state untouched
gl
- the current GL contextnewWidth
- newHeight
- GLException
- in case of an errorpublic final void reset(GL gl, int newWidth, int newHeight, int newSamples)
In case the new parameters are compatible with the current ones no action will be performed. Otherwise all attachments will be recreated to match the new given parameters.
Currently incompatibility and hence recreation is given if the size or sample count doesn't match for subsequent calls.
Leaves the FBO bound state untouched
gl
- the current GL contextnewWidth
- newHeight
- newSamples
- if > 0, MSAA will be used, otherwise no multisampling. Will be capped to getMaxSamples()
.GLException
- in case of an errorpublic final int getStatus()
GL.GL_FRAMEBUFFER_COMPLETE
if ok, otherwise return GL FBO error state or -1#validateStatus()
public final String getStatusString()
getStatus()
as a string.public static final String getStatusString(int fbStatus)
public final boolean isStatusValid()
getStatus()
public final FBObject.TextureAttachment attachTexture2D(GL gl, int attachmentPoint, boolean alpha) throws GLException
Using default min/mag filter GL.GL_NEAREST
and default wrapS/wrapT GL.GL_CLAMP_TO_EDGE
.
Leaves the FBO bound.
gl
- the current GL contextattachmentPoint
- the color attachment point ranging from [0..getMaxColorAttachments()
-1]alpha
- set to true
if you request alpha channel, otherwise false
;GLException
- in case the texture colorbuffer couldn't be allocated or MSAA has been chosenpublic final FBObject.TextureAttachment attachTexture2D(GL gl, int attachmentPoint, boolean alpha, int magFilter, int minFilter, int wrapS, int wrapT) throws GLException
Leaves the FBO bound.
gl
- the current GL contextattachmentPoint
- the color attachment point ranging from [0..getMaxColorAttachments()
-1]alpha
- set to true
if you request alpha channel, otherwise false
;magFilter
- if > 0 value for GL.GL_TEXTURE_MAG_FILTER
minFilter
- if > 0 value for GL.GL_TEXTURE_MIN_FILTER
wrapS
- if > 0 value for GL.GL_TEXTURE_WRAP_S
wrapT
- if > 0 value for GL.GL_TEXTURE_WRAP_T
GLException
- in case the texture colorbuffer couldn't be allocated or MSAA has been chosenpublic final FBObject.TextureAttachment attachTexture2D(GL gl, int attachmentPoint, int internalFormat, int dataFormat, int dataType, int magFilter, int minFilter, int wrapS, int wrapT) throws GLException
Leaves the FBO bound.
gl
- the current GL contextattachmentPoint
- the color attachment point ranging from [0..getMaxColorAttachments()
-1]internalFormat
- internalFormat parameter to GL.glTexImage2D(int, int, int, int, int, int, int, int, long)
dataFormat
- format parameter to GL.glTexImage2D(int, int, int, int, int, int, int, int, long)
dataType
- type parameter to GL.glTexImage2D(int, int, int, int, int, int, int, int, long)
magFilter
- if > 0 value for GL.GL_TEXTURE_MAG_FILTER
minFilter
- if > 0 value for GL.GL_TEXTURE_MIN_FILTER
wrapS
- if > 0 value for GL.GL_TEXTURE_WRAP_S
wrapT
- if > 0 value for GL.GL_TEXTURE_WRAP_T
GLException
- in case the texture colorbuffer couldn't be allocated or MSAA has been chosenpublic final FBObject.TextureAttachment attachTexture2D(GL gl, int attachmentPoint, FBObject.TextureAttachment texA) throws GLException
In case the passed TextureAttachment texA
is uninitialized, i.e. it's texture name is zero
,
a new texture name is generated and setup w/ the texture parameter.
Otherwise, i.e. texture name is not zero
, the passed TextureAttachment texA
is
considered complete and assumed matching this FBO requirement. A GL error may occur is the latter is untrue.
Leaves the FBO bound.
gl
- the current GL contextattachmentPoint
- the color attachment point ranging from [0..getMaxColorAttachments()
-1]texA
- the to be attached FBObject.TextureAttachment
. Maybe complete or uninitialized, see above.texA
instance describing the new attached texture colorbuffer if bound and configured successfully, otherwise GLException is thrownGLException
- in case the texture colorbuffer couldn't be allocated or MSAA has been chosenpublic final FBObject.ColorAttachment attachColorbuffer(GL gl, int attachmentPoint, boolean alpha) throws GLException
Leaves the FBO bound.
gl
- the current GL contextattachmentPoint
- the color attachment point ranging from [0..getMaxColorAttachments()
-1]alpha
- set to true
if you request alpha channel, otherwise false
;GLException
- in case the colorbuffer couldn't be allocatedpublic final FBObject.ColorAttachment attachColorbuffer(GL gl, int attachmentPoint, int internalFormat) throws GLException, IllegalArgumentException
Leaves the FBO bound.
gl
- the current GL contextattachmentPoint
- the color attachment point ranging from [0..getMaxColorAttachments()
-1]internalFormat
- usually GL.GL_RGBA4
, GL.GL_RGB5_A1
, GL.GL_RGB565
, GL.GL_RGB8
or GL.GL_RGBA8
GLException
- in case the colorbuffer couldn't be allocatedIllegalArgumentException
- if internalFormat
doesn't reflect a colorbufferpublic final FBObject.ColorAttachment attachColorbuffer(GL gl, int attachmentPoint, FBObject.ColorAttachment colA) throws GLException
Leaves the FBO bound.
gl
- attachmentPoint
- the color attachment point ranging from [0..getMaxColorAttachments()
-1]colA
- the template for the new FBObject.ColorAttachment
GLException
- in case the colorbuffer couldn't be allocatedpublic final void attachRenderbuffer(GL gl, FBObject.Attachment.Type atype, int reqBits) throws GLException, IllegalArgumentException
Stencil and depth buffer can be attached only once.
In case the desired type or bit-number is not supported, the next available one is chosen.
Use getDepthAttachment()
and/or getStencilAttachment()
to retrieve details
about the attached buffer. The details cannot be returned, since it's possible 2 buffers
are being created, depth and stencil.
Leaves the FBO bound.
gl
- atype
- either FBObject.Attachment.Type.DEPTH
, FBObject.Attachment.Type.STENCIL
or FBObject.Attachment.Type.DEPTH_STENCIL
reqBits
- desired bits for depth or -1 for default (24 bits)GLException
- in case the renderbuffer couldn't be allocated or one is already attached.IllegalArgumentException
getDepthAttachment()
,
getStencilAttachment()
public final void attachRenderbuffer(GL gl, int internalFormat) throws GLException, IllegalArgumentException
internalFormat
.
Stencil and depth buffer can be attached only once.
Use getDepthAttachment()
and/or getStencilAttachment()
to retrieve details
about the attached buffer. The details cannot be returned, since it's possible 2 buffers
are being created, depth and stencil.
Leaves the FBO bound.
gl
- the current GL contextinternalFormat
- GL.GL_DEPTH_COMPONENT16
, GL.GL_DEPTH_COMPONENT24
, GL.GL_DEPTH_COMPONENT32
,
GL.GL_STENCIL_INDEX1
, GL.GL_STENCIL_INDEX4
, GL.GL_STENCIL_INDEX8
or GL.GL_DEPTH24_STENCIL8
GLException
- in case the renderbuffer couldn't be allocated or one is already attached.IllegalArgumentException
getDepthAttachment()
,
getStencilAttachment()
public final void detachColorbuffer(GL gl, int attachmentPoint) throws IllegalArgumentException
Leaves the FBO bound!
gl
- ca
- IllegalArgumentException
public final void detachRenderbuffer(GL gl, FBObject.Attachment.Type atype) throws IllegalArgumentException
gl
- reqAType
- FBObject.Attachment.Type.DEPTH
, FBObject.Attachment.Type.DEPTH
or FBObject.Attachment.Type.DEPTH_STENCIL
IllegalArgumentException
public final boolean isDepthStencilPackedFormat()
public final void detachAll(GL gl)
FBObject.ColorAttachment
s, FBObject.TextureAttachment
s and FBObject.RenderAttachment
s.
Leaves the FBO bound!
An attached sampling sink texture will be detached as well, see getSamplingSink()
.
gl
- the current GL contextpublic final void detachAllColorbuffer(GL gl)
FBObject.ColorAttachment
s and FBObject.TextureAttachment
s.
Leaves the FBO bound!
An attached sampling sink texture will be detached as well, see getSamplingSink()
.
gl
- the current GL contextpublic final void detachAllTexturebuffer(GL gl)
FBObject.TextureAttachment
s
Leaves the FBO bound!
An attached sampling sink texture will be detached as well, see getSamplingSink()
.
gl
- the current GL contextpublic final void detachAllRenderbuffer(GL gl)
public final void destroy(GL gl)
gl
- the current GL contextpublic final void bind(GL gl) throws GLException
getWriteFramebuffer()
.
If multisampling is used, it sets the read framebuffer to the sampling sink getWriteFramebuffer()
,
if full FBO is supported.
In case you have attached more than one color buffer,
you may want to setup GL2GL3.glDrawBuffers(int, int[], int)
.
gl
- the current GL contextGLException
public final void unbind(GL gl) throws GLException
GLBase.getDefaultDrawFramebuffer()
.
If full FBO is supported, sets the read and write framebuffer individually to default, hence not disturbing
an optional operating MSAA FBO, see GLBase.getDefaultReadFramebuffer()
and GLBase.getDefaultDrawFramebuffer()
gl
- the current GL contextGLException
public final boolean isBound(GL gl)
true
if framebuffer object is bound via bind(GL)
, otherwise false
.
Method verifies the bound state via GLBase.getBoundFramebuffer(int)
.
gl
- the current GL contextpublic final boolean isBound()
public final void syncSamplingBuffer(GL gl)
getSamplingSink()
.
The operation is skipped, if no multisampling is used or
the msaa-buffer has not been flagged dirty by a previous call of bind(GL)
,
see isSamplingBufferDirty()
If full FBO is supported, sets the read and write framebuffer individually to default after sampling, hence not disturbing
an optional operating MSAA FBO, see GLBase.getDefaultReadFramebuffer()
and GLBase.getDefaultDrawFramebuffer()
In case you intend to employ glReadPixels(..)
you may want to call glBindFramebuffer
(GL2GL3.GL_READ_FRAMEBUFFER
, getReadFramebuffer()
);
Leaves the FBO unbound.
gl
- the current GL contextta
- FBObject.TextureAttachment
to use, prev. attached w/ attachTexture2D(..)
IllegalArgumentException
public final void use(GL gl, FBObject.TextureAttachment ta) throws IllegalArgumentException
If multisampling is being used, syncSamplingBuffer(GL)
is being called.
Leaves the FBO unbound!
gl
- the current GL contextta
- FBObject.TextureAttachment
to use, prev. attached w/ attachTexture2D(..)
IllegalArgumentException
public final void unuse(GL gl)
Leaves the FBO unbound.
public final boolean supportsFBO(boolean full) throws GLException
true
if basic or full FBO is supported, otherwise false
.full
- true
for full FBO supported query, otherwise false
for basic FBO support query.GLException
- if #init(GL)
hasn't been called.supportsFullFBO(GL)
,
supportsBasicFBO(GL)
public final boolean supportsRGBA8() throws GLException
GLException
- if #init(GL)
hasn't been called.public final boolean supportsDepth(int bits) throws GLException
true
if GL.GL_DEPTH_COMPONENT16
, GL.GL_DEPTH_COMPONENT24
or GL.GL_DEPTH_COMPONENT32
is supported, otherwise false
.bits
- 16, 24 or 32 bitsGLException
- if #init(GL)
hasn't been called.public final boolean supportsStencil(int bits) throws GLException
true
if GL.GL_STENCIL_INDEX1
, GL.GL_STENCIL_INDEX4
, GL.GL_STENCIL_INDEX8
or GL2GL3.GL_STENCIL_INDEX16
is supported, otherwise false
.bits
- 1, 4, 8 or 16 bitsGLException
- if #init(GL)
hasn't been called.public final boolean supportsPackedDepthStencil() throws GLException
GLException
- if #init(GL)
hasn't been called.public final int getMaxColorAttachments() throws GLException
GLException
- if #init(GL)
hasn't been called.public final int getMaxSamples() throws GLException
GLException
- if #init(GL)
hasn't been called.public final boolean isInitialized()
true
if this instance has been initialized with reset(GL, int, int)
or reset(GL, int, int, int)
, otherwise false
public final int getWidth()
public final int getHeight()
public final int getNumSamples()
public final int getWriteFramebuffer()
public final int getReadFramebuffer()
public final int getColorAttachmentCount()
public final FBObject.RenderAttachment getStencilAttachment()
FBObject.RenderAttachment
attachment, if exist. Maybe share the same FBObject.Attachment.getName()
as getDepthAttachment()
, if packed depth-stencil is being used.public final FBObject.RenderAttachment getDepthAttachment()
FBObject.RenderAttachment
attachment. Maybe share the same FBObject.Attachment.getName()
as getStencilAttachment()
, if packed depth-stencil is being used.public final FBObject getSamplingSinkFBO()
FBObject
sink, if using multisampling.public final FBObject.TextureAttachment getSamplingSink()
FBObject.TextureAttachment
sink, if using multisampling.public final boolean isSamplingBufferDirty()
true
if the multisampling colorbuffer (msaa-buffer)
has been flagged dirty by a previous call of bind(GL)
,
otherwise false
.Copyright 2010 JogAmp Community.