pc.RenderTarget
A render target is a rectangular rendering surface.
// Create a 512x512x24-bit render target with a depth buffer
var colorBuffer = new pc.Texture(graphicsDevice, {
width: 512,
height: 512,
format: pc.PIXELFORMAT_R8_G8_B8
});
var renderTarget = new pc.RenderTarget({
colorBuffer: colorBuffer,
depth: true
});
// Set the render target on a layer
layer.renderTarget = renderTarget;
Summary
Properties
| colorBuffer | Color buffer set up on the render target.[read only] |
| depthBuffer | Depth buffer set up on the render target.[read only] |
| face | If the render target is bound to a cubemap, this property specifies which face of the cubemap is rendered to.[read only] |
| height | Height of the render target in pixels.[read only] |
| width | Width of the render target in pixels.[read only] |
Methods
| copy | Copies color and/or depth contents of source render target to this one. |
| destroy | Frees resources associated with this render target. |
| resolve | If samples > 1, resolves the anti-aliased render target (WebGL2 only). |
Details
Constructor
RenderTarget(options)
Creates a new render target. A color buffer or a depth buffer must be set.
// Create a 512x512x24-bit render target with a depth buffer
var colorBuffer = new pc.Texture(graphicsDevice, {
width: 512,
height: 512,
format: pc.PIXELFORMAT_R8_G8_B8
});
var renderTarget = new pc.RenderTarget({
colorBuffer: colorBuffer,
depth: true
});
// Set the render target on a layer
layer.renderTarget = renderTarget;
Parameters
| options | object | Object for passing optional arguments. |
| options.colorBuffer | pc.Texture | The texture that this render target will treat as a rendering surface. |
| options.depth | boolean | If set to true, depth buffer will be created. Defaults to true. Ignored if depthBuffer is defined. |
| options.stencil | boolean | If set to true, depth buffer will include stencil. Defaults to false. Ignored if depthBuffer is defined or depth is false. |
| options.depthBuffer | pc.Texture | The texture that this render target will treat as a depth/stencil surface (WebGL2 only). If set, the 'depth' and 'stencil' properties are ignored. Texture must have pc.PIXELFORMAT_DEPTH or PIXELFORMAT_DEPTHSTENCIL format. |
| options.samples | number | Number of hardware anti-aliasing samples (WebGL2 only). Default is 1. |
| options.autoResolve | boolean | If samples > 1, enables or disables automatic MSAA resolve after rendering to this RT (see pc.RenderTarget#resolve). Defaults to true; Defaults to true. |
| options.face | number | If the colorBuffer parameter is a cubemap, use this option to specify the face of the cubemap to render to. Can be:
Defaults to pc.CUBEFACE_POSX. |
Properties
Depth buffer set up on the render target. Only available, if depthBuffer was set in constructor. Not available, if depth property was used instead.
[read only]If the render target is bound to a cubemap, this property specifies which face of the cubemap is rendered to. Can be:
- pc.CUBEFACE_POSX
- pc.CUBEFACE_NEGX
- pc.CUBEFACE_POSY
- pc.CUBEFACE_NEGY
- pc.CUBEFACE_POSZ
- pc.CUBEFACE_NEGZ
Methods
copy(source, color, depth)
Copies color and/or depth contents of source render target to this one. Formats, sizes and anti-aliasing samples must match. Depth buffer can only be copied on WebGL 2.0.
Parameters
| source | pc.RenderTarget | Source render target to copy from. |
| color | boolean | Copy color buffer. |
| depth | boolean | Copy depth buffer. |
Returns
booleanTrue if the copy was successfull, false otherwise.
destroy()
Frees resources associated with this render target.
resolve(color, depth)
If samples > 1, resolves the anti-aliased render target (WebGL2 only). When you're rendering to an anti-aliased render target, pixels aren't written directly to the readable texture. Instead, they're first written to a MSAA buffer, where each sample for each pixel is stored independently. In order to read the results, you first need to 'resolve' the buffer - to average all samples and create a simple texture with one color per pixel. This function performs this averaging and updates the colorBuffer and the depthBuffer. If autoResolve is set to true, the resolve will happen after every rendering to this render target, otherwise you can do it manually, during the app update or inside a pc.Command.
Parameters
| color | boolean | Resolve color buffer. |
| depth | boolean | Resolve depth buffer. |