public class FrameBuffer extends NativeObject
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.
Modifier and Type | Class and Description |
---|---|
static class |
FrameBuffer.FrameBufferBufferTarget |
static class |
FrameBuffer.FrameBufferTarget |
static class |
FrameBuffer.FrameBufferTextureTarget |
static class |
FrameBuffer.RenderBuffer
RenderBuffer represents either a texture or a
buffer that will be rendered to. |
Modifier and Type | Field and Description |
---|---|
static int |
SLOT_DEPTH |
static int |
SLOT_DEPTH_STENCIL |
static int |
SLOT_UNDEF |
handleRef, id, INVALID_ID, objectManager, OBJTYPE_AUDIOBUFFER, OBJTYPE_AUDIOSTREAM, OBJTYPE_BO, OBJTYPE_FILTER, OBJTYPE_FRAMEBUFFER, OBJTYPE_SHADER, OBJTYPE_SHADERSOURCE, OBJTYPE_TEXTURE, OBJTYPE_VERTEXBUFFER, updateNeeded
Modifier | Constructor and Description |
---|---|
protected |
FrameBuffer(FrameBuffer src) |
|
FrameBuffer(int width,
int height,
int samples)
Creates a new FrameBuffer with the given width, height, and number
of samples.
|
Modifier and Type | Method and Description |
---|---|
void |
addColorBuffer(Image.Format format)
Deprecated.
Use addColorTarget
|
void |
addColorTarget(FrameBuffer.FrameBufferBufferTarget colorBuf) |
void |
addColorTarget(FrameBuffer.FrameBufferTextureTarget colorBuf) |
void |
addColorTarget(FrameBuffer.FrameBufferTextureTarget colorBuf,
TextureCubeMap.Face face)
Adds a texture to one of the color Buffers Array.
|
void |
addColorTexture(Texture2D tex)
Deprecated.
Use addColorTarget
|
void |
addColorTexture(TextureArray tex,
int layer)
Deprecated.
Use addColorTarget
|
void |
addColorTexture(TextureCubeMap tex,
TextureCubeMap.Face face)
Deprecated.
Use addColorTarget
|
void |
clearColorTargets()
Clears all color targets that were set or added previously.
|
NativeObject |
createDestructableClone()
Creates a shallow clone of this GL Object.
|
void |
deleteObject(java.lang.Object rendererObject)
Deletes the GL object from the GPU when it is no longer used.
|
FrameBuffer.RenderBuffer |
getColorBuffer()
Deprecated.
Use getColorTarget()
|
FrameBuffer.RenderBuffer |
getColorBuffer(int index)
Deprecated.
Use getColorTarget(int)
|
FrameBuffer.RenderBuffer |
getColorTarget() |
FrameBuffer.RenderBuffer |
getColorTarget(int index) |
FrameBuffer.RenderBuffer |
getDepthBuffer()
Deprecated.
Use getDepthTarget()
|
FrameBuffer.RenderBuffer |
getDepthTarget() |
int |
getHeight() |
int |
getNumColorBuffers()
Deprecated.
Use getNumColorTargets
|
int |
getNumColorTargets() |
int |
getSamples() |
int |
getTargetIndex() |
long |
getUniqueId()
Returns a unique ID for this NativeObject.
|
int |
getWidth() |
boolean |
isMultiTarget() |
boolean |
isSrgb()
Determines if this framebuffer contains SRGB data.
|
void |
resetObject()
Called when the GL context is restarted to reset all IDs.
|
void |
setColorBuffer(Image.Format format)
Deprecated.
Use addColorTarget
|
void |
setColorTexture(Texture2D tex)
Deprecated.
Use addColorTarget
|
void |
setColorTexture(TextureArray tex,
int layer)
Deprecated.
Use addColorTarget
|
void |
setColorTexture(TextureCubeMap tex,
TextureCubeMap.Face face)
Deprecated.
Use addColorTarget
|
void |
setDepthBuffer(Image.Format format)
Deprecated.
Use setDepthTarget
|
void |
setDepthTarget(FrameBuffer.FrameBufferBufferTarget depthBuf) |
void |
setDepthTarget(FrameBuffer.FrameBufferTextureTarget depthBuf) |
void |
setDepthTexture(Texture2D tex)
Deprecated.
Use setDepthTarget
|
void |
setDepthTexture(TextureArray tex,
int layer)
Deprecated.
Use setDepthTarget
|
void |
setMultiTarget(boolean enabled)
If enabled, any shaders rendering into this
FrameBuffer
will be able to write several results into the renderbuffers
by using the gl_FragData array. |
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. |
java.lang.String |
toString() |
clearUpdateNeeded, clone, deleteNativeBuffers, dispose, getId, getWeakRef, isUpdateNeeded, setId, setUpdateNeeded
public static final int SLOT_UNDEF
public static final int SLOT_DEPTH
public static final int SLOT_DEPTH_STENCIL
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 the
Caps.NonPowerOfTwoTextures
, then an exception will be thrown
if the width and height arguments are not power of two.
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.java.lang.IllegalArgumentException
- If width or height are not positive.protected FrameBuffer(FrameBuffer src)
public void addColorTarget(FrameBuffer.FrameBufferBufferTarget colorBuf)
public void addColorTarget(FrameBuffer.FrameBufferTextureTarget colorBuf)
public void addColorTarget(FrameBuffer.FrameBufferTextureTarget colorBuf, TextureCubeMap.Face face)
TextureCubeMap
ordinal number for the
position in the color buffer ArrayList.colorBuf
- texture to add to the color Bufferface
- position to add to the color bufferpublic void setDepthTarget(FrameBuffer.FrameBufferBufferTarget depthBuf)
public void setDepthTarget(FrameBuffer.FrameBufferTextureTarget depthBuf)
public int getNumColorTargets()
public FrameBuffer.RenderBuffer getColorTarget(int index)
public FrameBuffer.RenderBuffer getColorTarget()
public FrameBuffer.RenderBuffer getDepthTarget()
@Deprecated public void setDepthBuffer(Image.Format format)
FrameBuffer
.format
- The format to use for the depth buffer.java.lang.IllegalArgumentException
- If format
is not a depth format.@Deprecated public void setColorBuffer(Image.Format format)
FrameBuffer
.format
- The format to use for the color buffer.java.lang.IllegalArgumentException
- If format
is not a color format.public void setMultiTarget(boolean enabled)
FrameBuffer
will be able to write several results into the renderbuffers
by using the gl_FragData
array. Every slot in that
array maps into a color buffer attached to this framebuffer.enabled
- True to enable MRT (multiple rendering targets).public boolean isMultiTarget()
setMultiTarget(boolean)
public void setTargetIndex(int index)
setMultiTarget(boolean)
is false)
then this specifies the color target to which the scene should be rendered.
By default the value is 0.
index
- The color attachment index.java.lang.IllegalArgumentException
- If index is negative or doesn't map
to any attachment on this framebuffer.public int getTargetIndex()
setTargetIndex(int)
@Deprecated public void setColorTexture(Texture2D tex)
addColorTexture(com.jme3.texture.Texture2D)
and adds this texture as the
only target.tex
- The color texture to set.@Deprecated public void setColorTexture(TextureArray tex, int layer)
addColorTexture(com.jme3.texture.Texture2D)
and adds this texture as the
only target.tex
- The color texture array to set.layer
- (default=-1)@Deprecated public void setColorTexture(TextureCubeMap tex, TextureCubeMap.Face face)
addColorTexture(com.jme3.texture.Texture2D)
and adds this texture as the
only target.tex
- The cube-map texture to set.face
- The face of the cube-map to render to.public void clearColorTargets()
@Deprecated public void addColorBuffer(Image.Format format)
gl_FragData
.
If MRT is not enabled, then the index set with setTargetIndex(int)
is rendered to by the shader.format
- the format of the color bufferaddColorTexture(com.jme3.texture.Texture2D)
@Deprecated public void addColorTexture(Texture2D tex)
gl_FragData
.
If MRT is not enabled, then the index set with setTargetIndex(int)
is rendered to by the shader.tex
- The texture to add.addColorBuffer(com.jme3.texture.Image.Format)
@Deprecated public void addColorTexture(TextureArray tex, int layer)
gl_FragData
.
If MRT is not enabled, then the index set with setTargetIndex(int)
is rendered to by the shader.tex
- The texture array to add.layer
- (default=-1)@Deprecated public void addColorTexture(TextureCubeMap tex, TextureCubeMap.Face face)
gl_FragData
.
If MRT is not enabled, then the index set with setTargetIndex(int)
is rendered to by the shader.tex
- The cube-map texture to add.face
- The face of the cube-map to render to.@Deprecated public void setDepthTexture(Texture2D tex)
tex
- The color texture to set.@Deprecated public void setDepthTexture(TextureArray tex, int layer)
tex
- the TextureArray to applylayer
- (default=-1)@Deprecated public int getNumColorBuffers()
@Deprecated public FrameBuffer.RenderBuffer getColorBuffer(int index)
index
- the zero-base index (≥0)@Deprecated public FrameBuffer.RenderBuffer getColorBuffer()
setTargetIndex(int)
, or null
if no color buffers are attached.
If MRT is disabled, the first color buffer is returned.@Deprecated public FrameBuffer.RenderBuffer getDepthBuffer()
public int getHeight()
public int getWidth()
public int getSamples()
public java.lang.String toString()
toString
in class NativeObject
public void resetObject()
NativeObject
resetObject
in class NativeObject
public void deleteObject(java.lang.Object rendererObject)
NativeObject
deleteObject
in class NativeObject
rendererObject
- The renderer to be used to delete the objectpublic NativeObject createDestructableClone()
NativeObject
createDestructableClone
in class NativeObject
public long getUniqueId()
NativeObject
getUniqueId
in class NativeObject
public void setSrgb(boolean srgb)
sRGB 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. If
blending
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.srgb
- If the framebuffer color values should be stored in sRGB
color space.java.lang.IllegalStateException
- If the texture attached to this framebuffer
is not sRGB.public boolean isSrgb()