Skip to main content

Class: RenderTarget

RenderTarget 是一种用于将场景渲染到纹理的方法,主要用于做离屏渲染和后处理等效果。

示例代码:

const options = {
width: 256,
height: 256,
minFilter: renderer.gl.NEAREST,
magFilter: renderer.gl.NEAREST
};
const current = new RenderTarget(renderer, options);

current.resize(width, height);
current.bind();
renderer.setViewport(0, 0, width, height);
mesh.updateMatrixWorld();
mesh.draw();
current.unbind();

Hierarchy

Table of contents

Constructors

Properties

Accessors

Methods

Constructors

constructor

new RenderTarget(renderer, options?): RenderTarget

Parameters

NameTypeDescription
rendererRendererRenderer 对象
optionsPartial<RenderTargetOptions>配置项,详见 #RenderTargetOptions

Returns

RenderTarget

Overrides

Resource.constructor

Defined in

src/core/RenderTarget.ts:131

Properties

renderer

renderer: Renderer

Inherited from

Resource.renderer

Defined in

src/core/Base.ts:7


depth

depth: boolean

Defined in

src/core/RenderTarget.ts:85


width

width: number

RenderTarget 宽度

Defined in

src/core/RenderTarget.ts:90


height

height: number

RenderTarget 高度

Defined in

src/core/RenderTarget.ts:95


viewport

viewport: Vector4

RenderTarget 视图大小,默认是一个四维向量

Defined in

src/core/RenderTarget.ts:100


drawBuffersChanged

drawBuffersChanged: boolean

绘制对象是否变化

Defined in

src/core/RenderTarget.ts:105


drawBuffers

drawBuffers: number[]

绘制缓存(绘制缓存设置了上一次绑定帧缓存状态,如果没有帧缓存可用的话,则用绘制缓存)

Defined in

src/core/RenderTarget.ts:110


id

id: string

Inherited from

Resource.id

Defined in

src/core/Resource.ts:21


name

name: WithUndef<string>

Inherited from

Resource.name

Defined in

src/core/Resource.ts:23


userData

userData: any

Inherited from

Resource.userData

Defined in

src/core/Resource.ts:25


byteLength

byteLength: number

Inherited from

Resource.byteLength

Defined in

src/core/Resource.ts:28


options

options: Partial<RenderTargetOptions>

Inherited from

Resource.options

Defined in

src/core/Resource.ts:30

Accessors

gl

get gl(): WebGLRenderingContext | WebGL2RenderingContext

获取 webgl 实例

Returns

WebGLRenderingContext | WebGL2RenderingContext

Inherited from

Resource.gl

Defined in

src/core/Base.ts:16


rendererState

get rendererState(): State

获取渲染状态

Returns

State

Inherited from

Resource.rendererState

Defined in

src/core/Base.ts:23


texture

get texture(): any

Returns

any

Defined in

src/core/RenderTarget.ts:232


clearColors

get clearColors(): [number, number, number, number][]

获取清屏颜色值

Returns

[number, number, number, number][]

Defined in

src/core/RenderTarget.ts:247

set clearColors(colors): void

设置清屏颜色值

Parameters

NameType
colors[number, number, number, number][]

Returns

void

Defined in

src/core/RenderTarget.ts:240


clearDepth

get clearDepth(): number

获取深度缓冲区的深度值

Returns

number

Defined in

src/core/RenderTarget.ts:262

set clearDepth(depth): void

设置清除深度缓冲区的深度值

Parameters

NameTypeDescription
depthnumber深度值

Returns

void

Defined in

src/core/RenderTarget.ts:255


clearStencil

get clearStencil(): number

获取缓冲区的默认值

Returns

number

Defined in

src/core/RenderTarget.ts:277

set clearStencil(stencil): void

设置清除模版缓冲区的默认值

Parameters

NameTypeDescription
stencilnumber模版缓冲区默认值

Returns

void

Defined in

src/core/RenderTarget.ts:270


handle

get handle(): any

Returns

any

Inherited from

Resource.handle

Defined in

src/core/Resource.ts:47

Methods

create

create(attachments): any

创建帧缓冲关联对象

Parameters

NameType
attachmentsAttachment[]

Returns

any

Defined in

src/core/RenderTarget.ts:285


clear

clear(): void

清空此帧缓冲区

Returns

void

Defined in

src/core/RenderTarget.ts:370


getTexture

getTexture(key): any

Parameters

NameType
keyany

Returns

any

Defined in

src/core/RenderTarget.ts:394


resize

resize(width, height): void

重新设置此帧缓冲区的大小

Parameters

NameTypeDescription
widthnumber宽度
heightnumber高度

Returns

void

Defined in

src/core/RenderTarget.ts:403


bind

bind(fbo?): void

绑定帧缓冲区

Parameters

NameTypeDescription
fbonumber如果未传入 fbo,默认是此 RenderTarget 创建的帧缓冲

Returns

void

Overrides

Resource.bind

Defined in

src/core/RenderTarget.ts:426


unbind

unbind(fbo?): void

解绑帧缓冲区

Parameters

NameTypeDescription
fbonumber如果未传入 fbo,默认是此 RenderTarget 创建的帧缓冲

Returns

void

Overrides

Resource.unbind

Defined in

src/core/RenderTarget.ts:434


removeStats

removeStats(): void

Returns

void

Overrides

Resource.removeStats

Defined in

src/core/RenderTarget.ts:439


destroy

destroy(): void

销毁此 RenderTarget

  • 销毁关联的纹理缓冲区
  • 销毁关联的渲染缓冲区
  • 销毁帧缓冲区

Returns

void

Overrides

Resource.destroy

Defined in

src/core/RenderTarget.ts:447


createHandle

createHandle(): null | WebGLFramebuffer

创建帧缓冲区

Returns

null | WebGLFramebuffer

Overrides

Resource.createHandle

Defined in

src/core/RenderTarget.ts:460


deleteHandle

deleteHandle(): void

移除帧缓冲区

Returns

void

Overrides

Resource.deleteHandle

Defined in

src/core/RenderTarget.ts:467


toString

toString(): string

将此实例转换为字符串标识

Returns

string

Overrides

Resource.toString

Defined in

src/core/RenderTarget.ts:474


swapHandle

swapHandle(handle): void

交换为新的 handle(一般我们会用在虚拟 webgl 环境中)

Parameters

NameType
handleany

Returns

void

Inherited from

Resource.swapHandle

Defined in

src/core/Resource.ts:55


restoreHandle

restoreHandle(): void

恢复为原有 handle

Returns

void

Inherited from

Resource.restoreHandle

Defined in

src/core/Resource.ts:63


delete

delete(«destructured»?): RenderTarget

Parameters

NameTypeDefault value
«destructured»Object{}
› deleteChildrenundefined | booleanfalse

Returns

RenderTarget

Inherited from

Resource.delete

Defined in

src/core/Resource.ts:74