Skip to main content

Class: Renderer

渲染器

Table of contents

Constructors

Properties

Accessors

Methods

Constructors

constructor

new Renderer(gl, opts?): Renderer

Parameters

NameType
glWebGLRenderingContext | WebGL2RenderingContext | HTMLCanvasElement
optsPartial<RendererOptions>

Returns

Renderer

Defined in

src/core/Renderer.ts:228

Properties

vertexAttribDivisor

vertexAttribDivisor: (index: number, divisor: number) => void | (index: number, divisor: number) => void

Defined in

src/core/Renderer.ts:205


drawArraysInstanced

drawArraysInstanced: (mode: number, first: number, count: number, primcount: number) => void | (mode: number, first: number, count: number, instanceCount: number) => void

Defined in

src/core/Renderer.ts:208


drawElementsInstanced

drawElementsInstanced: (mode: number, count: number, type: number, offset: number, primcount: number) => void | (mode: number, count: number, type: number, offset: number, instanceCount: number) => void

Defined in

src/core/Renderer.ts:211


createVertexArray

createVertexArray: () => null | WebGLVertexArrayObjectOES | () => null | WebGLVertexArrayObject

Defined in

src/core/Renderer.ts:214


bindVertexArray

bindVertexArray: (arrayObject: null | WebGLVertexArrayObjectOES) => void | (array: null | WebGLVertexArrayObject) => void

Defined in

src/core/Renderer.ts:217


deleteVertexArray

deleteVertexArray: (arrayObject: null | WebGLVertexArrayObjectOES) => void | (vertexArray: null | WebGLVertexArrayObject) => void

Defined in

src/core/Renderer.ts:220


width

width: number

Defined in

src/core/Renderer.ts:224


height

height: number

Defined in

src/core/Renderer.ts:226

Accessors

gl

get gl(): WebGLRenderingContext | WebGL2RenderingContext

获取 gl 实例

Returns

WebGLRenderingContext | WebGL2RenderingContext

Defined in

src/core/Renderer.ts:383


attributes

get attributes(): Object

获取 Renderer 的内部属性值

Returns

Object

NameType
dprnumber
flipYboolean
depthWithUndef<boolean>
colorboolean
antialiasWithUndef<boolean>
alphaWithUndef<boolean>
stencilWithUndef<boolean>
autoClearboolean
frustumCullboolean
premultipliedAlphaWithUndef<boolean>
preserveDrawingBufferWithUndef<boolean>

Defined in

src/core/Renderer.ts:390


canvas

get canvas(): HTMLCanvasElement | OffscreenCanvas

获取 canvas 实例

Returns

HTMLCanvasElement | OffscreenCanvas

Defined in

src/core/Renderer.ts:409


isWebGL

get isWebGL(): boolean

判断是否是 webgl1

Returns

boolean

Defined in

src/core/Renderer.ts:416


isWebGL2

get isWebGL2(): boolean

判断是否是 webgl2

Returns

boolean

Defined in

src/core/Renderer.ts:423


extensions

get extensions(): Object

获取已开启的扩展

Returns

Object

NameType
ANGLE_instanced_arraysExtensions
EXT_texture_filter_anisotropicExtensions
EXT_blend_minmaxExtensions
EXT_color_buffer_floatExtensions
EXT_color_buffer_half_floatExtensions
EXT_frag_depthExtensions
EXT_shader_texture_lodExtensions
OES_element_index_uintExtensions
OES_standard_derivativesExtensions
OES_texture_floatExtensions
OES_texture_float_linearExtensions
OES_texture_half_floatExtensions
OES_texture_half_float_linearExtensions
OES_vertex_array_objectExtensions
WEBGL_color_buffer_floatExtensions
WEBGL_debug_renderer_infoExtensions
WEBGL_depth_textureExtensions
WEBGL_draw_buffersExtensions
WEBGL_lose_contextExtensions

Defined in

src/core/Renderer.ts:430


size

get size(): Object

获取 canvas 画布大小

Returns

Object

NameType
widthnumber
heightnumber

Defined in

src/core/Renderer.ts:445


state

get state(): State

获取 renderState

Returns

State

Defined in

src/core/Renderer.ts:455


premultipliedAlpha

get premultipliedAlpha(): WithUndef<boolean>

获取 premultipliedAlpha 配置

Returns

WithUndef<boolean>

Defined in

src/core/Renderer.ts:462

Methods

extension

extension(key): Extensions

获取指定的扩展

Parameters

NameType
keyExtensionKeys

Returns

Extensions

Defined in

src/core/Renderer.ts:438


setSize

setSize(width, height): void

设置画布宽高

Parameters

NameTypeDescription
widthnumber
heightnumber

Returns

void

Defined in

src/core/Renderer.ts:471


setViewport

setViewport(width, height, x?, y?): void

设置 webglviewport

Parameters

NameTypeDefault value
widthanyundefined
heightanyundefined
xnumber0
ynumber0

Returns

void

Defined in

src/core/Renderer.ts:486


getRenderList

getRenderList(«destructured»): any[]

获取渲染列表(排序先不实现)

Parameters

NameType
«destructured»Object
› sceneany
› cameraany

Returns

any[]

Defined in

src/core/Renderer.ts:512


render

render(params): void

渲染函数,一般会在每一帧中调用此方法

Parameters

NameType
paramsRenderParams

Returns

void

Defined in

src/core/Renderer.ts:533


clear

clear(color?, depth?, stencil?): void

清空画布

Parameters

NameTypeDescription
colorboolean颜色
depthWithUndef<boolean>深度
stencilWithUndef<boolean>模板

Returns

void

Defined in

src/core/Renderer.ts:583


resetState

resetState(force?, vao?): void

重置内部 WebGL 状态。 需要注意的是一般单独使用时我们不需要去重置状态,但是在跨多个 WebGL 库共享单个 WebGL 上下文时我们需要关注此方法。默认情况下 我们会重置所有的状态,但是当我们确认多个共享库使用的状态完全相同时我们可以考虑仅重置部分状态以提高性能。但是有可能会出现无法预料的情况 请在你确认状态完全匹配时使用 force = false 重置部分状态。

Parameters

NameTypeDefault valueDescription
forcebooleantrue是否强制重置所用状态,默认是 true
vaoWithNull<WebGLVertexArrayObject | WebGLVertexArrayObjectOES>null

Returns

void

Defined in

src/core/Renderer.ts:601