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
-
↳
RenderTarget
Table of contents
Constructors
Properties
- renderer
- depth
- width
- height
- viewport
- drawBuffersChanged
- drawBuffers
- id
- name
- userData
- byteLength
- options
Accessors
Methods
- create
- clear
- getTexture
- resize
- bind
- unbind
- removeStats
- destroy
- createHandle
- deleteHandle
- toString
- swapHandle
- restoreHandle
- delete
Constructors
constructor
• new RenderTarget(renderer
, options?
): RenderTarget
Parameters
Name | Type | Description |
---|---|---|
renderer | Renderer | Renderer 对象 |
options | Partial <RenderTargetOptions > | 配置项,详见 #RenderTargetOptions |
Returns
Overrides
Defined in
Properties
renderer
• renderer: Renderer
Inherited from
Defined in
depth
• depth: boolean
Defined in
width
• width: number
RenderTarget
宽度
Defined in
height
• height: number
RenderTarget
高度
Defined in
viewport
• viewport: Vector4
RenderTarget
视图大小,默认是一个四维向量
Defined in
drawBuffersChanged
• drawBuffersChanged: boolean
绘制对象是否变化
Defined in
drawBuffers
• drawBuffers: number
[]
绘制缓存(绘制缓存设置了上一次绑定帧缓存状态,如果没有帧缓存可用的话,则用绘制缓存)
Defined in
id
• id: string
Inherited from
Defined in
name
• name: WithUndef
<string
>
Inherited from
Defined in
userData
• userData: any
Inherited from
Defined in
byteLength
• byteLength: number
Inherited from
Defined in
options
• options: Partial
<RenderTargetOptions
>
Inherited from
Defined in
Accessors
gl
• get
gl(): WebGLRenderingContext
| WebGL2RenderingContext
获取 webgl
实例
Returns
WebGLRenderingContext
| WebGL2RenderingContext
Inherited from
Resource.gl
Defined in
rendererState
• get
rendererState(): State
获取渲染状态
Returns
Inherited from
Resource.rendererState
Defined in
texture
• get
texture(): any
Returns
any
Defined in
clearColors
• get
clearColors(): [number
, number
, number
, number
][]
获取清屏颜色值
Returns
[number
, number
, number
, number
][]
Defined in
• set
clearColors(colors
): void
设置清屏颜色值
Parameters
Name | Type |
---|---|
colors | [number , number , number , number ][] |
Returns
void
Defined in
clearDepth
• get
clearDepth(): number
获取深度缓冲区的深度值
Returns
number
Defined in
• set
clearDepth(depth
): void
设置清除深度缓冲区的深度值
Parameters
Name | Type | Description |
---|---|---|
depth | number | 深度值 |
Returns
void
Defined in
clearStencil
• get
clearStencil(): number
获取缓冲区的默认值
Returns
number
Defined in
• set
clearStencil(stencil
): void
设置清除模版缓冲区的默认值
Parameters
Name | Type | Description |
---|---|---|
stencil | number | 模版缓冲区默认值 |
Returns
void
Defined in
handle
• get
handle(): any
Returns
any
Inherited from
Resource.handle
Defined in
Methods
create
▸ create(attachments
): any
创建帧缓冲关联对象
Parameters
Name | Type |
---|---|
attachments | Attachment [] |
Returns
any
Defined in
clear
▸ clear(): void
清空此帧缓冲区
Returns
void
Defined in
getTexture
▸ getTexture(key
): any
Parameters
Name | Type |
---|---|
key | any |
Returns
any
Defined in
resize
▸ resize(width
, height
): void
重新设置此帧缓冲区的大小
Parameters
Name | Type | Description |
---|---|---|
width | number | 宽度 |
height | number | 高度 |
Returns
void
Defined in
bind
▸ bind(fbo?
): void
绑定帧缓冲区
Parameters
Name | Type | Description |
---|---|---|
fbo | number | 如果未传入 fbo ,默认是此 RenderTarget 创建的帧缓冲 |
Returns
void
Overrides
Defined in
unbind
▸ unbind(fbo?
): void
解绑帧缓冲区
Parameters
Name | Type | Description |
---|---|---|
fbo | number | 如果未传入 fbo ,默认是此 RenderTarget 创建的帧缓冲 |
Returns
void
Overrides
Defined in
removeStats
▸ removeStats(): void
Returns
void
Overrides
Defined in
destroy
▸ destroy(): void
销毁此 RenderTarget
- 销毁关联的纹理缓冲区
- 销毁关联的渲染缓冲区
- 销毁帧缓冲区
Returns
void
Overrides
Defined in
createHandle
▸ createHandle(): null
| WebGLFramebuffer
创建帧缓冲区
Returns
null
| WebGLFramebuffer
Overrides
Defined in
deleteHandle
▸ deleteHandle(): void
移除帧缓冲区
Returns
void
Overrides
Defined in
toString
▸ toString(): string
将此实例转换为字符串标识
Returns
string
Overrides
Defined in
swapHandle
▸ swapHandle(handle
): void
交换为新的 handle
(一般我们会用在虚拟 webgl 环境中)
Parameters
Name | Type |
---|---|
handle | any |
Returns
void
Inherited from
Defined in
restoreHandle
▸ restoreHandle(): void
恢复为原有 handle
Returns
void
Inherited from
Defined in
delete
▸ delete(«destructured»?
): RenderTarget
Parameters
Name | Type | Default value |
---|---|---|
«destructured» | Object | {} |
› deleteChildren | undefined | boolean | false |