Class FrameBuffer
- All Implemented Interfaces:
Cloneable
FrameBuffer
s are rendering surfaces allowing
off-screen rendering and render-to-texture functionality.
Instead of the scene rendering to the screen, it is rendered into the
FrameBuffer, the result can be either a texture or a buffer.
A FrameBuffer
supports two methods of rendering,
using a Texture
or using a buffer.
When using a texture, the result of the rendering will be rendered
onto the texture, after which the texture can be placed on an object
and rendered as if the texture was uploaded from disk.
When using a buffer, the result is rendered onto
a buffer located on the GPU, the data of this buffer is not accessible
to the user. buffers are useful if one
wishes to retrieve only the color content of the scene, but still desires
depth testing (which requires a depth buffer).
Buffers can be copied to other framebuffers
including the main screen, by using
Renderer.copyFrameBuffer(com.jme3.texture.FrameBuffer, com.jme3.texture.FrameBuffer, boolean, boolean)
.
The content of a FrameBuffer.RenderBuffer
can be retrieved by using
Renderer.readFrameBuffer(com.jme3.texture.FrameBuffer, java.nio.ByteBuffer)
.
FrameBuffer
s have several attachment points, there are
several color attachment points and a single depth
attachment point.
The color attachment points support image formats such as
Image.Format.RGBA8
, allowing rendering the color content of the scene.
The depth attachment point requires a depth image format.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
static class
static class
static class
RenderBuffer
represents either a texture or a buffer that will be rendered to. -
Field Summary
Modifier and TypeFieldDescriptionstatic final int
static final int
static final int
Fields inherited from class com.jme3.util.NativeObject
handleRef, id, INVALID_ID, objectManager, OBJTYPE_AUDIOBUFFER, OBJTYPE_AUDIOSTREAM, OBJTYPE_BO, OBJTYPE_FILTER, OBJTYPE_FRAMEBUFFER, OBJTYPE_SHADER, OBJTYPE_SHADERSOURCE, OBJTYPE_TEXTURE, OBJTYPE_VERTEXBUFFER, updateNeeded
-
Constructor Summary
ModifierConstructorDescriptionFrameBuffer
(int width, int height, int samples) Creates a new FrameBuffer with the given width, height, and number of samples.protected
FrameBuffer
(FrameBuffer src) -
Method Summary
Modifier and TypeMethodDescriptionvoid
addColorBuffer
(Image.Format format) Deprecated.Use addColorTargetvoid
void
void
addColorTarget
(FrameBuffer.FrameBufferTextureTarget colorBuf, TextureCubeMap.Face face) Adds a texture to one of the color Buffers Array.void
addColorTexture
(Texture2D tex) Deprecated.Use addColorTargetvoid
addColorTexture
(TextureArray tex, int layer) Deprecated.Use addColorTargetvoid
addColorTexture
(TextureCubeMap tex, TextureCubeMap.Face face) Deprecated.Use addColorTargetvoid
Clears all color targets that were set or added previously.Creates a shallow clone of this GL Object.void
deleteObject
(Object rendererObject) Deletes the GL object from the GPU when it is no longer used.Deprecated.Use getColorTarget()getColorBuffer
(int index) Deprecated.Use getColorTarget(int)getColorTarget
(int index) Deprecated.Use getDepthTarget()int
getName()
int
Deprecated.Use getNumColorTargetsint
int
int
long
Returns a unique ID for this NativeObject.int
getWidth()
boolean
boolean
isSrgb()
Determines if this framebuffer contains SRGB data.void
Called when the GL context is restarted to reset all IDs.void
setColorBuffer
(Image.Format format) Deprecated.Use addColorTargetvoid
setColorTexture
(Texture2D tex) Deprecated.Use addColorTargetvoid
setColorTexture
(TextureArray tex, int layer) Deprecated.Use addColorTargetvoid
setColorTexture
(TextureCubeMap tex, TextureCubeMap.Face face) Deprecated.Use addColorTargetvoid
setDepthBuffer
(Image.Format format) Deprecated.Use setDepthTargetvoid
void
void
setDepthTexture
(Texture2D tex) Deprecated.Use setDepthTargetvoid
setDepthTexture
(TextureArray tex, int layer) Deprecated.Use setDepthTargetvoid
Hints the renderer to generate mipmaps for this framebuffer if necessaryvoid
setMultiTarget
(boolean enabled) If enabled, any shaders rendering into thisFrameBuffer
will be able to write several results into the renderbuffers by using thegl_FragData
array.void
void
setSrgb
(boolean srgb) Specifies that the color values stored in this framebuffer are in SRGB format.void
setTargetIndex
(int index) If MRT is not enabled (setMultiTarget(boolean)
is false) then this specifies the color target to which the scene should be rendered.toString()
Methods inherited from class com.jme3.util.NativeObject
clearUpdateNeeded, clone, deleteNativeBuffers, dispose, getId, getWeakRef, isUpdateNeeded, setId, setUpdateNeeded
-
Field Details
-
SLOT_UNDEF
public static final int SLOT_UNDEF- See Also:
-
SLOT_DEPTH
public static final int SLOT_DEPTH- See Also:
-
SLOT_DEPTH_STENCIL
public static final int SLOT_DEPTH_STENCIL- See Also:
-
-
Constructor Details
-
FrameBuffer
public FrameBuffer(int width, int height, int samples) Creates a new FrameBuffer with the given width, height, and number of samples. If any textures are attached to this FrameBuffer, then they must have the same number of samples as given in this constructor.
Note that if the
Renderer
does not expose theCaps.NonPowerOfTwoTextures
, then an exception will be thrown if the width and height arguments are not power of two.- Parameters:
width
- The width to useheight
- The height to usesamples
- The number of samples to use for a multisampled framebuffer, or 1 if the framebuffer should be single-sampled.- Throws:
IllegalArgumentException
- If width or height are not positive.
-
FrameBuffer
-
-
Method Details
-
addColorTarget
-
addColorTarget
-
addColorTarget
Adds a texture to one of the color Buffers Array. It usesTextureCubeMap
ordinal number for the position in the color buffer ArrayList.- Parameters:
colorBuf
- texture to add to the color Bufferface
- position to add to the color buffer
-
setDepthTarget
-
setDepthTarget
-
getNumColorTargets
public int getNumColorTargets() -
getColorTarget
-
getColorTarget
-
getDepthTarget
-
setDepthBuffer
Deprecated.Use setDepthTargetEnables the use of a depth buffer for thisFrameBuffer
.- Parameters:
format
- The format to use for the depth buffer.- Throws:
IllegalArgumentException
- Ifformat
is not a depth format.
-
setColorBuffer
Deprecated.Use addColorTargetEnables the use of a color buffer for thisFrameBuffer
.- Parameters:
format
- The format to use for the color buffer.- Throws:
IllegalArgumentException
- Ifformat
is not a color format.
-
setMultiTarget
public void setMultiTarget(boolean enabled) If enabled, any shaders rendering into thisFrameBuffer
will be able to write several results into the renderbuffers by using thegl_FragData
array. Every slot in that array maps into a color buffer attached to this framebuffer.- Parameters:
enabled
- True to enable MRT (multiple rendering targets).
-
isMultiTarget
public boolean isMultiTarget()- Returns:
- True if MRT (multiple rendering targets) is enabled.
- See Also:
-
setTargetIndex
public void setTargetIndex(int index) If MRT is not enabled (setMultiTarget(boolean)
is false) then this specifies the color target to which the scene should be rendered.By default the value is 0.
- Parameters:
index
- The color attachment index.- Throws:
IllegalArgumentException
- If index is negative or doesn't map to any attachment on this framebuffer.
-
getTargetIndex
public int getTargetIndex()- Returns:
- The color target to which the scene should be rendered.
- See Also:
-
setColorTexture
Deprecated.Use addColorTargetSet the color texture to use for this framebuffer. This automatically clears all existing textures added previously withaddColorTexture(com.jme3.texture.Texture2D)
and adds this texture as the only target.- Parameters:
tex
- The color texture to set.
-
setColorTexture
Deprecated.Use addColorTargetSet the color texture array to use for this framebuffer. This automatically clears all existing textures added previously withaddColorTexture(com.jme3.texture.Texture2D)
and adds this texture as the only target.- Parameters:
tex
- The color texture array to set.layer
- (default=-1)
-
setColorTexture
Deprecated.Use addColorTargetSet the color texture to use for this framebuffer. This automatically clears all existing textures added previously withaddColorTexture(com.jme3.texture.Texture2D)
and adds this texture as the only target.- Parameters:
tex
- The cube-map texture to set.face
- The face of the cube-map to render to.
-
clearColorTargets
public void clearColorTargets()Clears all color targets that were set or added previously. -
addColorBuffer
Deprecated.Use addColorTargetAdd a color buffer without a texture bound to it. If MRT is enabled, then each subsequently added texture or buffer can be rendered to through a shader that writes to the arraygl_FragData
. If MRT is not enabled, then the index set withsetTargetIndex(int)
is rendered to by the shader.- Parameters:
format
- the format of the color buffer- See Also:
-
addColorTexture
Deprecated.Use addColorTargetAdd a color texture to use for this framebuffer. If MRT is enabled, then each subsequently added texture can be rendered to through a shader that writes to the arraygl_FragData
. If MRT is not enabled, then the index set withsetTargetIndex(int)
is rendered to by the shader.- Parameters:
tex
- The texture to add.- See Also:
-
addColorTexture
Deprecated.Use addColorTargetAdd a color texture array to use for this framebuffer. If MRT is enabled, then each subsequently added texture can be rendered to through a shader that writes to the arraygl_FragData
. If MRT is not enabled, then the index set withsetTargetIndex(int)
is rendered to by the shader.- Parameters:
tex
- The texture array to add.layer
- (default=-1)
-
addColorTexture
Deprecated.Use addColorTargetAdd a color texture to use for this framebuffer. If MRT is enabled, then each subsequently added texture can be rendered to through a shader that writes to the arraygl_FragData
. If MRT is not enabled, then the index set withsetTargetIndex(int)
is rendered to by the shader.- Parameters:
tex
- The cube-map texture to add.face
- The face of the cube-map to render to.
-
setDepthTexture
Deprecated.Use setDepthTargetSet the depth texture to use for this framebuffer.- Parameters:
tex
- The color texture to set.
-
setDepthTexture
Deprecated.Use setDepthTarget- Parameters:
tex
- the TextureArray to applylayer
- (default=-1)
-
getNumColorBuffers
Deprecated.Use getNumColorTargets- Returns:
- The number of color buffers attached to this texture.
-
getColorBuffer
Deprecated.Use getColorTarget(int)- Parameters:
index
- the zero-base index (≥0)- Returns:
- The color buffer at the given index.
-
getColorBuffer
Deprecated.Use getColorTarget()- Returns:
- The color buffer with the index set by
setTargetIndex(int)
, or null if no color buffers are attached. If MRT is disabled, the first color buffer is returned.
-
getDepthBuffer
Deprecated.Use getDepthTarget()- Returns:
- The depth buffer attached to this FrameBuffer, or null if no depth buffer is attached
-
getHeight
public int getHeight()- Returns:
- The height in pixels of this framebuffer.
-
getWidth
public int getWidth()- Returns:
- The width in pixels of this framebuffer.
-
getSamples
public int getSamples()- Returns:
- The number of samples when using a multisample framebuffer, or 1 if this is a single-sampled framebuffer.
-
toString
- Overrides:
toString
in classNativeObject
-
resetObject
public void resetObject()Description copied from class:NativeObject
Called when the GL context is restarted to reset all IDs. Prevents "white textures" on display restart.- Specified by:
resetObject
in classNativeObject
-
deleteObject
Description copied from class:NativeObject
Deletes the GL object from the GPU when it is no longer used. Called automatically by the GL object manager.- Specified by:
deleteObject
in classNativeObject
- Parameters:
rendererObject
- The renderer to be used to delete the object
-
createDestructableClone
Description copied from class:NativeObject
Creates a shallow clone of this GL Object. The deleteObject method should be functional for this object.- Specified by:
createDestructableClone
in classNativeObject
- Returns:
- a new instance
-
getUniqueId
public long getUniqueId()Description copied from class:NativeObject
Returns a unique ID for this NativeObject. No other NativeObject shall have the same ID.- Specified by:
getUniqueId
in classNativeObject
- Returns:
- unique ID for this NativeObject.
-
setSrgb
public void setSrgb(boolean srgb) Specifies that the color values stored in this framebuffer are in SRGB format. The FrameBuffer must have an SRGB texture attached. The Renderer must expose thesRGB pipeline
capability for this option to take any effect. Rendering operations performed on this framebuffer shall undergo a linear -> sRGB color space conversion when this flag is enabled. Ifblending
is enabled, it will be performed in linear space by first decoding the stored sRGB pixel values into linear, combining with the shader result, and then converted back to sRGB upon being written into the framebuffer.- Parameters:
srgb
- If the framebuffer color values should be stored in sRGB color space.- Throws:
IllegalStateException
- If the texture attached to this framebuffer is not sRGB.
-
isSrgb
public boolean isSrgb()Determines if this framebuffer contains SRGB data.- Returns:
- True if the framebuffer color values are in SRGB space, false if in linear space.
-
getName
-
setName
-
setMipMapsGenerationHint
Hints the renderer to generate mipmaps for this framebuffer if necessary- Parameters:
v
- true to enable, null to use the default value for the renderer (default to null)
-
getMipMapsGenerationHint
-