OffscreenRenderTarget

Render Target that render to offscreen textures or renderbuffers.

Constructor

new OffscreenRenderTarget(width, height)

Create a new OffscreenRenderTarget.

Parameters:
NameTypeDescription
widthnumber

The width of the render target.

heightnumber

The height of the render target.

Extends

Members

activeCubeFace :number

An alias for OffscreenRenderTarget#activeLayer. Specifically represents the currently rendered cube face (0-5) when using cube textures.

Type:
  • number

activeLayer :number

The active layer index for rendering. For cube render targets, this represents the active cube face.

Type:
  • number
Default Value
  • 0

activeMipmapLevel :number

The active mipmap level for rendering. Not supported in WebGL1.

Type:
  • number
Default Value
  • 0

clearColor :boolean

Whether to clear the color buffer before rendering to this render target.

Type:
  • boolean
Default Value
  • true

clearDepth :boolean

Whether to clear the depth buffer before rendering to this render target.

Type:
  • boolean
Default Value
  • true

clearStencil :boolean

Whether to clear the stencil buffer before rendering to this render target.

Type:
  • boolean
Default Value
  • true

colorClearValue :Color4

Clear color value.

Type:

depthClearValue :number

Clear depth value.

Type:
  • number
Default Value
  • 1

height :number

The height of the render target.

Type:
  • number

(readonly) isOffscreenRenderTarget :boolean

This flag can be used for type testing.

Type:
  • boolean
Default Value
  • true

(readonly) isRenderTarget :boolean

This flag can be used for type testing.

Type:
  • boolean
Default Value
  • true

occlusionQuerySet :QuerySet|null

A querySet that will store the occlusion query results. If null, occlusion queries are disabled.

Type:
Default Value
  • null

stencilClearValue :number

Clear stencil value.

Type:
  • number
Default Value
  • 0

texture :TextureBase|null

The main texture attachment which is the first color attachment.

Type:

timestampWrites :object

An array of objects defining where and when timestamp query values will be written.

Type:
  • object
Properties
NameTypeDescription
querySetQuerySet | null

A timestamp querySet. If null, timestamp queries are disabled.

beginningOfPassWriteIndexnumber

A number specifying the query index in querySet where the timestamp at the beginning of the render pass will be written.

endOfPassWriteIndexnumber

A number specifying the query index in querySet where the timestamp at the end of the render pass will be written.

width :number

The width of the render target.

Type:
  • number

Methods

addEventListener(type, listener)

Adds a listener to an event type.

Parameters:
NameTypeDescription
typestring

The type of event to listen to.

listenerfunction

The function that gets called when the event is fired.

attach(target, attachmentopt) → {OffscreenRenderTarget}

Attach a texture(RTT) or renderbuffer to the framebuffer. Notice: For now, dynamic Attachment during rendering is not supported.

Parameters:
NameTypeAttributesDefaultDescription
targetTextureBase | RenderBuffer

The texture or renderbuffer to attach.

attachmentATTACHMENT<optional>
ATTACHMENT.COLOR_ATTACHMENT0

The attachment point.

Returns:

Self for chaining.

Type: 
OffscreenRenderTarget

detach(attachmentopt) → {OffscreenRenderTarget}

Detach a texture(RTT) or renderbuffer.

Parameters:
NameTypeAttributesDefaultDescription
attachmentATTACHMENT<optional>
ATTACHMENT.COLOR_ATTACHMENT0

The attachment point to detach.

Returns:

Self for chaining.

Type: 
OffscreenRenderTarget

dispatchEvent(event)

Fire an event.

Parameters:
NameTypeDescription
eventobject

The event that gets fired.

dispose(disposeAttachmentsopt)

Dispose the render target.

Parameters:
NameTypeAttributesDefaultDescription
disposeAttachmentsboolean<optional>
true

Whether to dispose attachments as well.

getAttachment(attachmentopt) → {TextureBase|RenderBuffer|null}

Get the attached attachment at the specified attachment point.

Parameters:
NameTypeAttributesDefaultDescription
attachmentATTACHMENT<optional>
ATTACHMENT.COLOR_ATTACHMENT0

The attachment point.

Returns:

The attached texture or renderbuffer.

Type: 
TextureBase | RenderBuffer | null

removeEventListener(type, listener)

Removes a listener from an event type.

Parameters:
NameTypeDescription
typestring

The type of the listener that gets removed.

listenerfunction

The listener function that gets removed.

resize(width, height, depthopt)

Resize the render target to the specified dimensions. This will resize all attached attachments.

Parameters:
NameTypeAttributesDescription
widthnumber

The new width of the render target.

heightnumber

The new height of the render target.

depthnumber<optional>

DEPRECATED: Depth parameter is no longer used. Individual textures manage their own depth dimensions.

setClear(coloropt, depthopt, stencilopt) → {RenderTargetBase}

Sets the clear state.

Parameters:
NameTypeAttributesDescription
colorboolean<optional>

Whether to clear the color buffer.

depthboolean<optional>

Whether to clear the depth buffer.

stencilboolean<optional>

Whether to clear the stencil buffer.

Returns:

A reference to this render target.

Type: 
RenderTargetBase

setColorClearValue(r, g, b, a) → {RenderTargetBase}

Sets the clear values.

Parameters:
NameTypeDescription
rnumber

Red channel value between 0.0 and 1.0.

gnumber

Green channel value between 0.0 and 1.0.

bnumber

Blue channel value between 0.0 and 1.0.

anumber

Alpha channel value between 0.0 and 1.0.

Returns:

A reference to this render target.

Type: 
RenderTargetBase

setDepthClearValue(depth) → {RenderTargetBase}

Sets the clear depth value.

Parameters:
NameTypeDescription
depthnumber

The depth value.

Returns:

A reference to this render target.

Type: 
RenderTargetBase

setOcclusionQuerySet(querySet) → {RenderTargetBase}

Sets the occlusion query set.

Parameters:
NameTypeDescription
querySetQuerySet | null

The occlusion query set. If null, occlusion queries are disabled.

Returns:

A reference to this render target.

Type: 
RenderTargetBase

setStencilClearValue(stencil) → {RenderTargetBase}

Sets the clear stencil value.

Parameters:
NameTypeDescription
stencilnumber

The stencil value.

Returns:

A reference to this render target.

Type: 
RenderTargetBase

setTimestampWrites(querySet, beginIndexopt, endIndexopt) → {RenderTargetBase}

Sets the timestamp query set and the query indices.

Parameters:
NameTypeAttributesDefaultDescription
querySetQuerySet | null

The timestamp query set. If null, timestamp queries are disabled.

beginIndexnumber<optional>
0

The query index in querySet where the timestamp at the beginning of the render pass will be written.

endIndexnumber<optional>
1

The query index in querySet where the timestamp at the end of the render pass will be written.

Returns:

A reference to this render target.

Type: 
RenderTargetBase

(static) create2D(width, height) → {OffscreenRenderTarget}

Create a simple offscreen render target with a color texture and a depth-stencil renderbuffer.

Parameters:
NameTypeDescription
widthnumber

The width of the render target.

heightnumber

The height of the render target.

Returns:

The created offscreen render target.

Type: 
OffscreenRenderTarget

(static) create2DArray(width, height, depth) → {OffscreenRenderTarget}

Create a simple offscreen render target with a 2D array color texture. Note: No depth-stencil attachment is created by default.

Parameters:
NameTypeDescription
widthnumber

The width of the render target.

heightnumber

The height of the render target.

depthnumber

The depth of the 2D array texture (number of layers).

Returns:

The created offscreen render target.

Type: 
OffscreenRenderTarget

(static) create3D(width, height, depth) → {OffscreenRenderTarget}

Create a simple offscreen render target with a 3D color texture. Note: No depth-stencil attachment is created by default.

Parameters:
NameTypeDescription
widthnumber

The width of the render target.

heightnumber

The height of the render target.

depthnumber

The depth of the 3D texture.

Returns:

The created offscreen render target.

Type: 
OffscreenRenderTarget

(static) createCube(width, height) → {OffscreenRenderTarget}

Create a simple offscreen render target with a cube color texture and a depth-stencil renderbuffer.

Parameters:
NameTypeDescription
widthnumber

The width of the render target.

heightnumber

The height of the render target.

Returns:

The created offscreen render target.

Type: 
OffscreenRenderTarget