Class FBObject
- java.lang.Object
-
- com.jogamp.opengl.FBObject
-
public class FBObject extends Object
Core utility class simplifying usage of framebuffer objects (FBO) with allGLProfiles.Supports on-the-fly reconfiguration of dimension and multisample buffers via
#reset(GL, int, int, int, boolean)while preserving theFBObject.Attachmentreferences.Integrates default read/write framebuffers via
GLContext.getDefaultReadFramebuffer()andGLContext.getDefaultReadFramebuffer(), which is being hooked atGL.glBindFramebuffer(int, int)when the default (zero) framebuffer is selected.FIXME: Implement support for
FBObject.Attachment.Type.DEPTH_TEXTURE,FBObject.Attachment.Type.STENCIL_TEXTURE.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classFBObject.AttachmentCommon super class of all FBO attachmentsstatic classFBObject.ColorAttachmentColor render buffer FBO attachmentstatic interfaceFBObject.ColorbufferGeneric color buffer FBO attachment, either of typeFBObject.ColorAttachmentorFBObject.TextureAttachment.static classFBObject.RenderAttachmentOther renderbuffer attachment which maybe a colorbuffer, depth or stencil.static classFBObject.TextureAttachmentTexture FBO attachment
-
Field Summary
Fields Modifier and Type Field Description static intCHOSEN_BITSstatic intDEFAULT_BITSRequest default bit count for depth- or stencil buffer (depth 24 bits, stencil 8 bits), value 0static intMAXIMUM_BITSRequest maximum bit count for depth- or stencil buffer (depth 32 bits, stencil 16 bits), value -3static intREQUESTED_BITS
-
Constructor Summary
Constructors Constructor Description FBObject()Creates an uninitialized FBObject instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description FBObject.ColorAttachmentattachColorbuffer(GL gl, int attachmentPoint, boolean alpha)Attaches a newly created andinitializedFBObject.Colorbuffer, i.e.FBObject.ColorAttachmentattachColorbuffer(GL gl, int attachmentPoint, int internalFormat)Attaches a newly created andinitializedFBObject.Colorbuffer, i.e.FBObject.ColorbufferattachColorbuffer(GL gl, int attachmentPoint, FBObject.Colorbuffer colbuf)Attaches aFBObject.Colorbufferat the given attachment point andinitializesit, if not done yet.voidattachRenderbuffer(GL gl, int internalFormat)Attaches one depth, stencil or packed-depth-stencil buffer to this FBO's instance, depending on theinternalFormat.voidattachRenderbuffer(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.FBObject.TextureAttachmentattachTexture2D(GL gl, int attachmentPoint, boolean alpha)Attaches aFBObject.Colorbuffer, i.e.FBObject.TextureAttachmentattachTexture2D(GL gl, int attachmentPoint, boolean alpha, int magFilter, int minFilter, int wrapS, int wrapT)Attaches aFBObject.Colorbuffer, i.e.FBObject.TextureAttachmentattachTexture2D(GL gl, int attachmentPoint, int internalFormat, int dataFormat, int dataType, int magFilter, int minFilter, int wrapS, int wrapT)Attaches aFBObject.Colorbuffer, i.e.voidbind(GL gl)Bind this FBO, i.e.FBObject.ColorAttachmentcreateColorAttachment(boolean alpha)Creates aFBObject.ColorAttachment, selecting the format automatically.static FBObject.ColorAttachmentcreateColorAttachment(int internalFormat, int samples, int width, int height)Creates aFBObject.ColorAttachment, selecting the format automatically.static FBObject.TextureAttachmentcreateColorTextureAttachment(int internalFormat, int width, int height, int dataFormat, int dataType, int magFilter, int minFilter, int wrapS, int wrapT)Creates a colorFBObject.TextureAttachment, i.e.static FBObject.TextureAttachmentcreateColorTextureAttachment(GL gl, boolean alpha, int width, int height)Creates a colorFBObject.TextureAttachment, i.e.static FBObject.TextureAttachmentcreateColorTextureAttachment(GL gl, boolean alpha, int width, int height, int magFilter, int minFilter, int wrapS, int wrapT)Creates a colorFBObject.TextureAttachment, i.e.static FBObject.TextureAttachmentcreateColorTextureAttachment(GL gl, int internalFormat, int width, int height, int magFilter, int minFilter, int wrapS, int wrapT)static FBObject.RenderAttachmentcreateRenderAttachment(FBObject.Attachment.Type type, int internalFormat, int samples, int width, int height)voiddestroy(GL gl)voiddetachAll(GL gl)Detaches allFBObject.ColorAttachments,FBObject.TextureAttachments andFBObject.RenderAttachments and disposes them.voiddetachAllColorbuffer(GL gl)Detaches allFBObject.ColorAttachments andFBObject.TextureAttachments and disposes them.voiddetachAllRenderbuffer(GL gl)voiddetachAllTexturebuffer(GL gl)Detaches allFBObject.TextureAttachments and disposes them.FBObject.ColorbufferdetachColorbuffer(GL gl, int attachmentPoint, boolean dispose)Detaches aFBObject.Colorbuffer, i.e.voiddetachRenderbuffer(GL gl, FBObject.Attachment.Type atype, boolean dispose)voidformatToGLCapabilities(GLCapabilities caps)Writes the internal format of the attachments to the given GLCapabilities object.FBObject.ColorbuffergetColorbuffer(int attachmentPoint)Return theFBObject.Colorbufferattachment atattachmentPointif it is attached to this FBO, otherwise null.FBObject.ColorbuffergetColorbuffer(FBObject.Colorbuffer ca)Returns the passedFBObject.Colorbufferif it is attached to this FBO, otherwise null.intgetColorbufferAttachmentPoint(FBObject.Colorbuffer ca)Finds the passedFBObject.Colorbufferwithin the valid range of attachment points using reference comparison only.intgetColorbufferCount()Return the number of attachedFBObject.ColorbuffersintgetDefaultDrawBuffer()intgetDefaultReadBuffer()FBObject.RenderAttachmentgetDepthAttachment()Return the depthFBObject.RenderAttachmentattachment.intgetHeight()Returns the heightintgetMaxColorAttachments()Returns the maximum number of colorbuffer attachments.intgetMaxRenderbufferSize()intgetMaxSamples()intgetMaxTextureSize()intgetNumSamples()Returns the number of samples for multisampling (MSAA).intgetReadFramebuffer()Returns the framebuffer name to read from.FBObject.ColorbuffergetSamplingSink()Return the multisamplingFBObject.Colorbuffersink, if using multisampling.FBObjectgetSamplingSinkFBO()Return the complete multisamplingFBObjectsink, if using multisampling.intgetStatus()Note that the status may reflect an incomplete state during transition of attachments.StringgetStatusString()return thegetStatus()as a string.static StringgetStatusString(int fbStatus)FBObject.RenderAttachmentgetStencilAttachment()Return the stencilFBObject.RenderAttachmentattachment, if exist.intgetTextureAttachmentCount()Return the number of attachedFBObject.TextureAttachmentsintgetWidth()Returns the widthintgetWriteFramebuffer()Returns the framebuffer name to render to.booleanhasAttachmentUsingAlpha()Returns true if any attachedFBObject.Colorbufferuses alpha, otherwise false.booleanhasFullFBOSupport()voidinit(GL gl, int newWidth, int newHeight, int newSamples)Initializes this FBO's instance.booleanisBound()booleanisBound(GL gl)booleanisDepthStencilPackedFormat()booleanisInitialized()Returnstrueif this instance has been initialized with#reset(GL, int, int)or#reset(GL, int, int, int, boolean), otherwisefalsebooleanisModified()Returnstrueif size, sample-count or any attachment of this instance or itssampling-sinkhas been modified since lastsync,use,resetorresetSamplingSink.booleanisSamplingBufferDirty()Returnstrueif the multisampling colorbuffer (msaa-buffer) has been flagged dirty by a previous call ofbind(GL), otherwisefalse.booleanisStatusValid()The status may even be valid if incomplete during transition of attachments.voidmarkUnbound()Method simply marks this FBO unbound w/o interfering w/ the bound framebuffer as perfomed byunbind(GL).booleanreset(GL gl, int newWidth, int newHeight, int newSamples)Resets this FBO's instance.booleanresetSamplingSink(GL gl)Manually validates the MSAA sampling sink, if used.FBObjectsetSamplingSink(FBObject newSamplingSink)Setting this FBO sampling sink.booleansupportsDepth(int bits)ReturnstrueifGL.GL_DEPTH_COMPONENT16,GL.GL_DEPTH_COMPONENT24orGL.GL_DEPTH_COMPONENT32is supported, otherwisefalse.booleansupportsPackedDepthStencil()booleansupportsRGBA8()booleansupportsStencil(int bits)ReturnstrueifGL.GL_STENCIL_INDEX1,GL.GL_STENCIL_INDEX4,GL.GL_STENCIL_INDEX8orGL2GL3.GL_STENCIL_INDEX16is supported, otherwisefalse.voidsyncSamplingSink(GL gl)If multisampling is being used and flagged dirty by a previous call ofbind(GL)or after initialization, the msaa-buffers are sampled to it's sink#getSamplingTextureSink().StringtoString()voidunbind(GL gl)Unbind this FBO, i.e.voidunuse(GL gl)Unbind texture, ie bind 'non' texture 0voiduse(GL gl, FBObject.TextureAttachment ta)
-
-
-
Field Detail
-
DEFAULT_BITS
public static final int DEFAULT_BITS
Request default bit count for depth- or stencil buffer (depth 24 bits, stencil 8 bits), value 0- See Also:
- Constant Field Values
-
REQUESTED_BITS
public static final int REQUESTED_BITS
- See Also:
- Constant Field Values
-
CHOSEN_BITS
public static final int CHOSEN_BITS
- See Also:
- Constant Field Values
-
MAXIMUM_BITS
public static final int MAXIMUM_BITS
Request maximum bit count for depth- or stencil buffer (depth 32 bits, stencil 16 bits), value -3- See Also:
- Constant Field Values
-
-
Constructor Detail
-
FBObject
public FBObject()
Creates an uninitialized FBObject instance.Call
init(GL, int, int, int).. etc to use it.
-
-
Method Detail
-
createColorTextureAttachment
public static final FBObject.TextureAttachment createColorTextureAttachment(GL gl, boolean alpha, int width, int height)
Creates a colorFBObject.TextureAttachment, i.e. typeFBObject.Attachment.Type.COLOR_TEXTURE, selecting the texture data type and format automatically.Using default min/mag filter
GL.GL_NEARESTand default wrapS/wrapTGL.GL_CLAMP_TO_EDGE.- Parameters:
gl- the usedGLContext'sGLobjectalpha- set totrueif you request alpha channel, otherwisefalse;width- texture widthheight- texture height- Returns:
- the created and uninitialized color
FBObject.TextureAttachment
-
createColorTextureAttachment
public static final FBObject.TextureAttachment createColorTextureAttachment(GL gl, boolean alpha, int width, int height, int magFilter, int minFilter, int wrapS, int wrapT)
Creates a colorFBObject.TextureAttachment, i.e. typeFBObject.Attachment.Type.COLOR_TEXTURE, selecting the texture data type and format automatically.For GLES3, sampling-sink format must be equal w/ the sampling-source
FBObject.Colorbuffer, see details below. Implementation aligns w/createColorAttachment(boolean)and is enforced viasampleSinkExFormatMismatch(GL).ES3 BlitFramebuffer Requirements: OpenGL ES 3.0.2 p194: 4.3.2 Copying Pixels
If SAMPLE_BUFFERS for the read framebuffer is greater than zero, no copy is performed and an INVALID_OPERATION error is generated if the formats of the read and draw framebuffers are not identical or if the source and destination rectangles are not defined with the same (X0, Y 0) and (X1, Y 1) bounds.
Texture and Renderbuffer format details:ES2 Base iFormat: OpenGL ES 2.0.24 p66: 3.7.1 Texture Image Specification, Table 3.8 ALPHA, LUMINANCE, LUMINANCE_ALPHA, RGB, RGBA ES3 Base iFormat: OpenGL ES 3.0.2 p125: 3.8.3 Texture Image Specification, Table 3.11 ALPHA, LUMINANCE, LUMINANCE_ALPHA, RGB, RGBA DEPTH_COMPONENT, STENCIL_COMPONENT, RED, RG ES3 Required Texture and Renderbuffer iFormat: OpenGL ES 3.0.2 p126: 3.8.3 Texture Image Specification - RGBA32I, RGBA32UI, RGBA16I, RGBA16UI, RGBA8, RGBA8I, RGBA8UI, SRGB8_ALPHA8, RGB10_A2, RGB10_A2UI, RGBA4, and RGB5_A1. - RGB8 and RGB565. - RG32I, RG32UI, RG16I, RG16UI, RG8, RG8I, and RG8UI. - R32I, R32UI, R16I, R16UI, R8, R8I, and R8UI.- Parameters:
gl- the usedGLContext'sGLobjectalpha- set totrueif you request alpha channel, otherwisefalse;width- texture widthheight- texture heightmagFilter- if > 0 value forGL.GL_TEXTURE_MAG_FILTERminFilter- if > 0 value forGL.GL_TEXTURE_MIN_FILTERwrapS- if > 0 value forGL.GL_TEXTURE_WRAP_SwrapT- if > 0 value forGL.GL_TEXTURE_WRAP_T- Returns:
- the created and uninitialized color
FBObject.TextureAttachment
-
createColorTextureAttachment
public static final FBObject.TextureAttachment createColorTextureAttachment(GL gl, int internalFormat, int width, int height, int magFilter, int minFilter, int wrapS, int wrapT)
-
createColorTextureAttachment
public static final FBObject.TextureAttachment createColorTextureAttachment(int internalFormat, int width, int height, int dataFormat, int dataType, int magFilter, int minFilter, int wrapS, int wrapT)
Creates a colorFBObject.TextureAttachment, i.e. typeFBObject.Attachment.Type.COLOR_TEXTURE.- Parameters:
internalFormat- internalFormat parameter toGL.glTexImage2D(int, int, int, int, int, int, int, int, long)width- texture widthheight- texture heightdataFormat- format parameter toGL.glTexImage2D(int, int, int, int, int, int, int, int, long)dataType- type parameter toGL.glTexImage2D(int, int, int, int, int, int, int, int, long)magFilter- if > 0 value forGL.GL_TEXTURE_MAG_FILTERminFilter- if > 0 value forGL.GL_TEXTURE_MIN_FILTERwrapS- if > 0 value forGL.GL_TEXTURE_WRAP_SwrapT- if > 0 value forGL.GL_TEXTURE_WRAP_T- Returns:
- the created and uninitialized color
FBObject.TextureAttachment
-
getColorbuffer
public final FBObject.Colorbuffer getColorbuffer(int attachmentPoint)
Return theFBObject.Colorbufferattachment atattachmentPointif it is attached to this FBO, otherwise null.- See Also:
#attachColorbuffer(GL, boolean),#attachColorbuffer(GL, boolean),attachTexture2D(GL, int, boolean, int, int, int, int),attachTexture2D(GL, int, int, int, int, int, int, int, int)
-
getColorbufferAttachmentPoint
public final int getColorbufferAttachmentPoint(FBObject.Colorbuffer ca)
Finds the passedFBObject.Colorbufferwithin 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.
- Parameters:
ca- theFBObject.Colorbufferto look for.- Returns:
- -1 if the
FBObject.Colorbuffercould not be found, otherwise [0..getMaxColorAttachments()-1]
-
getColorbuffer
public final FBObject.Colorbuffer getColorbuffer(FBObject.Colorbuffer ca)
Returns the passedFBObject.Colorbufferif 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 forgetColorbuffer(int)- See Also:
#attachColorbuffer(GL, boolean),#attachColorbuffer(GL, boolean),attachTexture2D(GL, int, boolean, int, int, int, int),attachTexture2D(GL, int, int, int, int, int, int, int, int)
-
hasAttachmentUsingAlpha
public final boolean hasAttachmentUsingAlpha()
Returns true if any attachedFBObject.Colorbufferuses alpha, otherwise false.
-
init
public void init(GL gl, int newWidth, int newHeight, int newSamples) throws IllegalStateException, GLException
Initializes this FBO's instance.The sampling sink is not initializes, allowing manual assignment via
setSamplingSink(FBObject)ifnewSamples > 0.Leaves the FBO bound
- Parameters:
gl- the current GL contextnewWidth- the initial width, it's minimum is capped to 1newHeight- the initial height, it's minimum is capped to 1newSamples- if > 0, MSAA will be used, otherwise no multisampling. Will be capped togetMaxSamples().- Throws:
IllegalStateException- if already initializedGLException- in case of an error, i.e. size too big, etc ..
-
reset
public final boolean reset(GL gl, int newWidth, int newHeight, int newSamples) throws GLException, IllegalStateException
Resets this FBO's instance.In case the new parameters are compatible with the current ones no action will be performed and method returns immediately.
Otherwise all attachments will be recreated to match the new given parameters.resetSamplingSink(GL)is being issued immediately to match the new configuration.Leaves the FBO bound state untouched
- Parameters:
gl- the current GL contextnewWidth- the new width, it's minimum is capped to 1newHeight- the new height, it's minimum is capped to 1newSamples- if > 0, MSAA will be used, otherwise no multisampling. Will be capped togetMaxSamples().- Returns:
trueif this instance has been modified, otherwisefalse.- Throws:
IllegalStateException- if not initialized viainit(GL, int, int, int).GLException- in case of an error, i.e. size too big, etc ..
-
formatToGLCapabilities
public final void formatToGLCapabilities(GLCapabilities caps)
Writes the internal format of the attachments to the given GLCapabilities object.- Parameters:
caps- the destination for format bits
-
getStatus
public final int getStatus()
Note that the status may reflect an incomplete state during transition of attachments.- Returns:
- The FB status.
GL.GL_FRAMEBUFFER_COMPLETEif ok, otherwise return GL FBO error state or -1 - See Also:
#validateStatus()
-
getStatusString
public final String getStatusString()
return thegetStatus()as a string.
-
getStatusString
public static final String getStatusString(int fbStatus)
-
isStatusValid
public final boolean isStatusValid()
The status may even be valid if incomplete during transition of attachments.- See Also:
getStatus()
-
attachTexture2D
public final FBObject.TextureAttachment attachTexture2D(GL gl, int attachmentPoint, boolean alpha) throws GLException
Attaches aFBObject.Colorbuffer, i.e.FBObject.TextureAttachment, to this FBO's instance at the given attachment point, selecting the texture data type and format automatically.Using default min/mag filter
GL.GL_NEARESTand default wrapS/wrapTGL.GL_CLAMP_TO_EDGE.Leaves the FBO bound.
- Parameters:
gl- the current GL contextattachmentPoint- the color attachment point ranging from [0..getMaxColorAttachments()-1]alpha- set totrueif you request alpha channel, otherwisefalse;- Returns:
- TextureAttachment instance describing the new attached texture colorbuffer if bound and configured successfully, otherwise GLException is thrown
- Throws:
GLException- in case the texture colorbuffer couldn't be allocated or MSAA has been chosen- See Also:
#createColorTextureAttachment(GLProfile, boolean, int, int)
-
attachTexture2D
public final FBObject.TextureAttachment attachTexture2D(GL gl, int attachmentPoint, boolean alpha, int magFilter, int minFilter, int wrapS, int wrapT) throws GLException
Attaches aFBObject.Colorbuffer, i.e.FBObject.TextureAttachment, to this FBO's instance at the given attachment point, selecting the texture data type and format automatically.Leaves the FBO bound.
- Parameters:
gl- the current GL contextattachmentPoint- the color attachment point ranging from [0..getMaxColorAttachments()-1]alpha- set totrueif you request alpha channel, otherwisefalse;magFilter- if > 0 value forGL.GL_TEXTURE_MAG_FILTERminFilter- if > 0 value forGL.GL_TEXTURE_MIN_FILTERwrapS- if > 0 value forGL.GL_TEXTURE_WRAP_SwrapT- if > 0 value forGL.GL_TEXTURE_WRAP_T- Returns:
- TextureAttachment instance describing the new attached texture colorbuffer if bound and configured successfully, otherwise GLException is thrown
- Throws:
GLException- in case the texture colorbuffer couldn't be allocated or MSAA has been chosen- See Also:
#createColorTextureAttachment(GLProfile, boolean, int, int, int, int, int, int)
-
attachTexture2D
public final FBObject.TextureAttachment attachTexture2D(GL gl, int attachmentPoint, int internalFormat, int dataFormat, int dataType, int magFilter, int minFilter, int wrapS, int wrapT) throws GLException
Attaches aFBObject.Colorbuffer, i.e.FBObject.TextureAttachment, to this FBO's instance at the given attachment point.Leaves the FBO bound.
- Parameters:
gl- the current GL contextattachmentPoint- the color attachment point ranging from [0..getMaxColorAttachments()-1]internalFormat- internalFormat parameter toGL.glTexImage2D(int, int, int, int, int, int, int, int, long)dataFormat- format parameter toGL.glTexImage2D(int, int, int, int, int, int, int, int, long)dataType- type parameter toGL.glTexImage2D(int, int, int, int, int, int, int, int, long)magFilter- if > 0 value forGL.GL_TEXTURE_MAG_FILTERminFilter- if > 0 value forGL.GL_TEXTURE_MIN_FILTERwrapS- if > 0 value forGL.GL_TEXTURE_WRAP_SwrapT- if > 0 value forGL.GL_TEXTURE_WRAP_T- Returns:
- TextureAttachment instance describing the new attached texture colorbuffer if bound and configured successfully, otherwise GLException is thrown
- Throws:
GLException- in case the texture colorbuffer couldn't be allocated or MSAA has been chosen- See Also:
createColorTextureAttachment(int, int, int, int, int, int, int, int, int)
-
createColorAttachment
public final FBObject.ColorAttachment createColorAttachment(boolean alpha)
Creates aFBObject.ColorAttachment, selecting the format automatically.For GLES3, sampling-sink
FBObject.Colorbufferformat must be equal w/ the sampling-sourceFBObject.Colorbuffer. Implementation aligns w/#createColorTextureAttachment(GLProfile, boolean, int, int, int, int, int, int)and is enforced viasampleSinkExFormatMismatch(GL).- Parameters:
alpha- set totrueif you request alpha channel, otherwisefalse;- Returns:
- uninitialized ColorAttachment instance describing the new attached colorbuffer
-
createColorAttachment
public static final FBObject.ColorAttachment createColorAttachment(int internalFormat, int samples, int width, int height)
Creates aFBObject.ColorAttachment, selecting the format automatically.For GLES3, sampling-sink
FBObject.Colorbufferformat must be equal w/ the sampling-sourceFBObject.Colorbuffer. Implementation aligns w/#createColorTextureAttachment(GLProfile, boolean, int, int, int, int, int, int)and is enforced viasampleSinkExFormatMismatch(GL).- Parameters:
alpha- set totrueif you request alpha channel, otherwisefalse;- Returns:
- uninitialized ColorAttachment instance describing the new attached colorbuffer
-
createRenderAttachment
public static final FBObject.RenderAttachment createRenderAttachment(FBObject.Attachment.Type type, int internalFormat, int samples, int width, int height)
-
attachColorbuffer
public final FBObject.ColorAttachment attachColorbuffer(GL gl, int attachmentPoint, boolean alpha) throws GLException
Attaches a newly created andinitializedFBObject.Colorbuffer, i.e. aFBObject.ColorAttachment, at the given attachment point.The
FBObject.ColorAttachmentis created usingalphaiftrueand currentsample countandsize.Leaves the FBO bound.
- Parameters:
gl- the current GL contextattachmentPoint- the color attachment point ranging from [0..getMaxColorAttachments()-1]alpha- set totrueif you request alpha channel, otherwisefalse;- Returns:
- ColorAttachment instance describing the new attached colorbuffer if bound and configured successfully, otherwise GLException is thrown
- Throws:
GLException- in case the colorbuffer couldn't be allocated- See Also:
createColorAttachment(boolean)
-
attachColorbuffer
public final FBObject.ColorAttachment attachColorbuffer(GL gl, int attachmentPoint, int internalFormat) throws GLException, IllegalArgumentException
Attaches a newly created andinitializedFBObject.Colorbuffer, i.e. aFBObject.ColorAttachment, at the given attachment point.The
FBObject.ColorAttachmentis created using the giveninternalFormatand currentsample countandsize.Leaves the FBO bound.
- Parameters:
gl- the current GL contextattachmentPoint- the color attachment point ranging from [0..getMaxColorAttachments()-1]internalFormat- usuallyGL.GL_RGBA4,GL.GL_RGB5_A1,GL.GL_RGB565,GL.GL_RGB8orGL.GL_RGBA8- Returns:
- ColorAttachment instance describing the new attached colorbuffer if bound and configured successfully, otherwise GLException is thrown
- Throws:
GLException- in case the colorbuffer couldn't be allocatedIllegalArgumentException- ifinternalFormatdoesn't reflect a colorbuffer
-
attachColorbuffer
public final FBObject.Colorbuffer attachColorbuffer(GL gl, int attachmentPoint, FBObject.Colorbuffer colbuf) throws GLException
Attaches aFBObject.Colorbufferat the given attachment point andinitializesit, if not done yet.FBObject.Colorbuffermay be aFBObject.ColorAttachmentorFBObject.TextureAttachment.If
FBObject.Colorbufferis aFBObject.TextureAttachmentand is uninitialized, i.e. it's texture name iszero, a new texture name is generated and setup w/ the texture parameter.
Otherwise, i.e. texture name is notzero, the passed TextureAttachmenttexAis considered complete and assumed matching this FBO requirement. A GL error may occur is the latter is untrue.Leaves the FBO bound.
- Parameters:
gl-attachmentPoint- the color attachment point ranging from [0..getMaxColorAttachments()-1]colbuf- the to be attachedFBObject.Colorbuffer- Returns:
- given
FBObject.Colorbufferinstance if bound and configured successfully, otherwise GLException is thrown - Throws:
GLException- in case the colorbuffer couldn't be allocated or MSAA has been chosen in case of aFBObject.TextureAttachment
-
attachRenderbuffer
public final void attachRenderbuffer(GL gl, FBObject.Attachment.Type atype, int reqBits) throws GLException, IllegalArgumentException
Attaches one depth, stencil or packed-depth-stencil buffer to this FBO's instance, selecting the internalFormat automatically.Stencil and depth buffer can be attached only once.
In case the bit-count is not supported, the next available one is chosen, i.e. next higher (preferred) or lower bit-count.
Use
getDepthAttachment()and/orgetStencilAttachment()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.
- Parameters:
gl-atype- eitherFBObject.Attachment.Type.DEPTH,FBObject.Attachment.Type.STENCILorFBObject.Attachment.Type.DEPTH_STENCILreqBits- desired bits for depth or stencil, may use generic valuesDEFAULT_BITS,REQUESTED_BITS,CHOSEN_BITSorMAXIMUM_BITS.- Throws:
GLException- in case the renderbuffer couldn't be allocated or one is already attached.IllegalArgumentException- See Also:
getDepthAttachment(),getStencilAttachment()
-
attachRenderbuffer
public final void attachRenderbuffer(GL gl, int internalFormat) throws GLException, IllegalArgumentException
Attaches one depth, stencil or packed-depth-stencil buffer to this FBO's instance, depending on theinternalFormat.Stencil and depth buffer can be attached only once.
Use
getDepthAttachment()and/orgetStencilAttachment()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.
- Parameters:
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_INDEX8orGL.GL_DEPTH24_STENCIL8- Throws:
GLException- in case the renderbuffer couldn't be allocated or one is already attached.IllegalArgumentException- See Also:
getDepthAttachment(),getStencilAttachment()
-
detachColorbuffer
public final FBObject.Colorbuffer detachColorbuffer(GL gl, int attachmentPoint, boolean dispose) throws IllegalArgumentException
Detaches aFBObject.Colorbuffer, i.e.FBObject.ColorAttachmentorFBObject.TextureAttachment.Leaves the FBO bound!
- Parameters:
gl-attachmentPoint-dispose- true if the Colorbuffer shall be disposed- Returns:
- the detached Colorbuffer
- Throws:
IllegalArgumentException
-
detachRenderbuffer
public final void detachRenderbuffer(GL gl, FBObject.Attachment.Type atype, boolean dispose) throws IllegalArgumentException
- Parameters:
gl-dispose- true if the Colorbuffer shall be disposedreqAType-FBObject.Attachment.Type.DEPTH,FBObject.Attachment.Type.DEPTHorFBObject.Attachment.Type.DEPTH_STENCIL- Throws:
IllegalArgumentException
-
isDepthStencilPackedFormat
public final boolean isDepthStencilPackedFormat()
-
detachAll
public final void detachAll(GL gl)
Detaches allFBObject.ColorAttachments,FBObject.TextureAttachments andFBObject.RenderAttachments and disposes them.Leaves the FBO bound, if initialized!
An attached sampling sink texture will be detached as well, see
#getSamplingTextureSink().- Parameters:
gl- the current GL context
-
detachAllColorbuffer
public final void detachAllColorbuffer(GL gl)
Detaches allFBObject.ColorAttachments andFBObject.TextureAttachments and disposes them.Leaves the FBO bound, if initialized!
An attached sampling sink texture will be detached as well, see
#getSamplingTextureSink().- Parameters:
gl- the current GL context
-
detachAllTexturebuffer
public final void detachAllTexturebuffer(GL gl)
Detaches allFBObject.TextureAttachments and disposes them.Leaves the FBO bound, if initialized!
An attached sampling sink texture will be detached as well, see
#getSamplingTextureSink().- Parameters:
gl- the current GL context
-
detachAllRenderbuffer
public final void detachAllRenderbuffer(GL gl)
-
destroy
public final void destroy(GL gl)
- Parameters:
gl- the current GL context
-
resetSamplingSink
public final boolean resetSamplingSink(GL gl) throws GLException
Manually validates the MSAA sampling sink, if used.If MSAA is being used and no sampling sink is attached via
setSamplingSink(FBObject)a new sampling sink is being created.If the sampling sink size or attributes differs from the source, its attachments are reset to match the source.
Automatically called by
#reset(GL, int, int, int, boolean)andsyncSamplingSink(GL).It is recommended to call this method after initializing the FBO and attaching renderbuffer etc for the 1st time if access to sampling sink resources is required.
Leaves the FBO bound state untouched
- Parameters:
gl- the current GL context- Returns:
trueif this instance has been modified, otherwisefalse.- Throws:
GLException- in case of an error, i.e. size too big, etc ..
-
setSamplingSink
public FBObject setSamplingSink(FBObject newSamplingSink) throws IllegalStateException, GLException
Setting this FBO sampling sink.- Parameters:
newSamplingSink- the new and initialized FBO sampling sink to use, or null to remove current sampling sink- Returns:
- the previous sampling sink or null if none was attached
- Throws:
GLException- if this FBO doesn't use MSAA or the given sink uses MSAA itselfIllegalStateException- if thenewSamplingSinkis not null and not initialized
-
bind
public final void bind(GL gl) throws GLException
Bind this FBO, i.e. bind write framebuffer togetWriteFramebuffer().If multisampling is used, it sets the read framebuffer to the sampling sink
getWriteFramebuffer().In case you have attached more than one color buffer, you may want to setup
GL2ES2.glDrawBuffers(int, int[], int).- Parameters:
gl- the current GL context- Throws:
GLException
-
unbind
public final void unbind(GL gl) throws GLException
Unbind this FBO, i.e. bind read and write framebuffer to default, seeGLBase.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()andGLBase.getDefaultDrawFramebuffer()- Parameters:
gl- the current GL context- Throws:
GLException
-
markUnbound
public final void markUnbound()
Method simply marks this FBO unbound w/o interfering w/ the bound framebuffer as perfomed byunbind(GL).Only use this method if a subsequent
unbind(GL),use(GL, TextureAttachment)orbind(GL)follows on any FBO.
-
isBound
public final boolean isBound(GL gl)
Returnstrueif framebuffer object is bound viabind(GL), otherwisefalse.Method verifies the bound state via
GLBase.getBoundFramebuffer(int).- Parameters:
gl- the current GL context
-
isBound
public final boolean isBound()
-
syncSamplingSink
public final void syncSamplingSink(GL gl)
If multisampling is being used and flagged dirty by a previous call ofbind(GL)or after initialization, the msaa-buffers are sampled to it's sink#getSamplingTextureSink().Method also resets the sampling sink configuration via
resetSamplingSink(GL)if used and required.Method is called automatically by
use(GL, TextureAttachment).Method always resets the framebuffer binding to default in the end. 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()andGLBase.getDefaultDrawFramebuffer()In case you use this FBO w/o the
GLFBODrawableand intend to employglReadPixels(..)you may want to callglBindFramebuffer(GL.GL_READ_FRAMEBUFFER,getReadFramebuffer());Leaves the FBO unbound.
- Parameters:
gl- the current GL contextta-FBObject.TextureAttachmentto use, prev. attached w/attachTexture2D(..)- Throws:
IllegalArgumentException
-
use
public final void use(GL gl, FBObject.TextureAttachment ta) throws IllegalArgumentException
Synchronize the sampling sinkand bind the givenFBObject.TextureAttachment, if notnull.If using a
FBObject.TextureAttachmentand multiple texture units, ensure you callGL.glActiveTexture(int)first!syncSamplingSink(GL)is being calledLeaves the FBO unbound!
- Parameters:
gl- the current GL contextta-FBObject.TextureAttachmentto use, prev. attached w/attachTexture2D(..), may benullin case noFBObject.TextureAttachmentis used.- Throws:
IllegalArgumentException
-
unuse
public final void unuse(GL gl)
Unbind texture, ie bind 'non' texture 0Leaves the FBO unbound.
-
hasFullFBOSupport
public final boolean hasFullFBOSupport() throws GLException- Throws:
GLException- See Also:
GLBase.hasFullFBOSupport()
-
supportsRGBA8
public final boolean supportsRGBA8() throws GLException- Throws:
GLException- if#init(GL)hasn't been called.
-
supportsDepth
public final boolean supportsDepth(int bits) throws GLExceptionReturnstrueifGL.GL_DEPTH_COMPONENT16,GL.GL_DEPTH_COMPONENT24orGL.GL_DEPTH_COMPONENT32is supported, otherwisefalse.- Parameters:
bits- 16, 24 or 32 bits- Throws:
GLException- if#init(GL)hasn't been called.
-
supportsStencil
public final boolean supportsStencil(int bits) throws GLExceptionReturnstrueifGL.GL_STENCIL_INDEX1,GL.GL_STENCIL_INDEX4,GL.GL_STENCIL_INDEX8orGL2GL3.GL_STENCIL_INDEX16is supported, otherwisefalse.- Parameters:
bits- 1, 4, 8 or 16 bits- Throws:
GLException- if#init(GL)hasn't been called.
-
supportsPackedDepthStencil
public final boolean supportsPackedDepthStencil() throws GLException- Throws:
GLException- if#init(GL)hasn't been called.
-
getMaxColorAttachments
public final int getMaxColorAttachments() throws GLExceptionReturns the maximum number of colorbuffer attachments.- Throws:
GLException- if#init(GL)hasn't been called.
-
getMaxTextureSize
public final int getMaxTextureSize() throws GLException- Throws:
GLException
-
getMaxRenderbufferSize
public final int getMaxRenderbufferSize() throws GLException- Throws:
GLException
-
getMaxSamples
public final int getMaxSamples() throws GLException- Throws:
GLException- See Also:
GLBase.getMaxRenderbufferSamples()
-
isInitialized
public final boolean isInitialized()
Returnstrueif this instance has been initialized with#reset(GL, int, int)or#reset(GL, int, int, int, boolean), otherwisefalse
-
getWidth
public final int getWidth()
Returns the width
-
getHeight
public final int getHeight()
Returns the height
-
getNumSamples
public final int getNumSamples()
Returns the number of samples for multisampling (MSAA). zero if no multisampling is used.
-
getWriteFramebuffer
public final int getWriteFramebuffer()
Returns the framebuffer name to render to.
-
getReadFramebuffer
public final int getReadFramebuffer()
Returns the framebuffer name to read from. Depending on multisampling, this may be a different framebuffer.
-
getDefaultDrawBuffer
public final int getDefaultDrawBuffer()
-
getDefaultReadBuffer
public final int getDefaultReadBuffer()
-
getColorbufferCount
public final int getColorbufferCount()
Return the number of attachedFBObject.Colorbuffers
-
getTextureAttachmentCount
public final int getTextureAttachmentCount()
Return the number of attachedFBObject.TextureAttachments
-
getStencilAttachment
public final FBObject.RenderAttachment getStencilAttachment()
Return the stencilFBObject.RenderAttachmentattachment, if exist. Maybe share the sameFBObject.Attachment.getName()asgetDepthAttachment(), if packed depth-stencil is being used.
-
getDepthAttachment
public final FBObject.RenderAttachment getDepthAttachment()
Return the depthFBObject.RenderAttachmentattachment. Maybe share the sameFBObject.Attachment.getName()asgetStencilAttachment(), if packed depth-stencil is being used.
-
getSamplingSinkFBO
public final FBObject getSamplingSinkFBO()
Return the complete multisamplingFBObjectsink, if using multisampling.
-
getSamplingSink
public final FBObject.Colorbuffer getSamplingSink()
Return the multisamplingFBObject.Colorbuffersink, if using multisampling.
-
isSamplingBufferDirty
public final boolean isSamplingBufferDirty()
Returnstrueif the multisampling colorbuffer (msaa-buffer) has been flagged dirty by a previous call ofbind(GL), otherwisefalse.
-
isModified
public final boolean isModified()
Returnstrueif size, sample-count or any attachment of this instance or itssampling-sinkhas been modified since lastsync,use,resetorresetSamplingSink.Otherwise method returns
false.
-
-