Class: WebGLRenderer

WebGLRenderer

new WebGLRenderer(params)

WebGL渲染器

Name Type Description
params Object optional

初始化参数,所有params都会复制到实例上

Fires:
  • event:init 初始化事件
  • event:beforeRender 渲染前事件
  • event:beforeRenderScene 渲染场景前事件
  • event:afterRender 渲染后事件
  • event:initFailed 初始化失败事件
  • event:webglContextLost webglContextLost 事件
  • event:webglContextRestored webglContextRestored 事件

Mixes In

Members Show Inherited

Name Type Default Description
className String WebGLRenderer
isWebGLRenderer Boolean true
gl WebGLRenderingContext null

gl

width Number 0

height Number 0

pixelRatio Number 1

像素密度

domElement HTMLCanvasElement null

dom元素

useInstanced Boolean false

是否使用instanced

useVao Boolean true

是否使用VAO

alpha Boolean false

是否开启透明背景

depth Boolean true
stencil Boolean false
antialias Boolean true

是否开启抗锯齿

premultipliedAlpha Boolean true

Boolean that indicates that the page compositor will assume the drawing buffer contains colors with pre-multiplied alpha.

preserveDrawingBuffer Boolean false

If the value is true the buffers will not be cleared and will preserve their values until cleared or overwritten by the author.

failIfMajorPerformanceCaveat Boolean false

Boolean that indicates if a context will be created if the system performance is low.

gameMode Boolean false

游戏模式, UC浏览器专用

useFramebuffer Boolean false

是否使用framebuffer

framebufferOption Object {}

framebuffer配置

useLogDepth Boolean false

是否使用对数深度

vertexPrecision String highp

顶点着色器精度, 可以是以下值:highp, mediump, lowp

fragmentPrecision String mediump

片段着色器精度, 可以是以下值:highp, mediump, lowp

fog Fog null

offsetX Number 0

偏移值

offsetY Number 0

偏移值

forceMaterial Material null

强制渲染时使用的材质

isInitFailed Boolean false

是否初始化失败

isWebGL2 Boolean false

是否是 WebGL2

preferWebGL2 Boolean false

是否优先使用 WebGL2

clearColor Color new Color(1, 1, 1, 1)

背景色

renderInfo RenderInfo new RenderInfo

渲染信息

renderList RenderList new RenderList

渲染列表

lightManager ILightManager new LightManager

灯光管理器

resourceManager WebGLResourceManager new WebGLResourceManager

资源管理器

isInit Boolean false

是否初始化

state WebGLState null

state,初始化后生成。

framebuffer Framebuffer null

framebuffer,只在 useFramebuffer 为 true 时初始化后生成

Methods Show Inherited

resize(width, height, force)

改变大小

Name Type Default Description
width Number

height Number

force Boolean false optional

是否强制刷新

设置viewport偏移值

Name Type Description
x Number

x

y Number

y

viewport(x, y, width, height)

设置viewport

Name Type Default Description
x Number this.offsetX optional

x

y Number this.offsetY optional

y

width Number this.gl.drawingBufferWidth optional

width

height Number this.gl.drawingBufferHeight optional

height

初始化回调

Returns:
Type Description
WebGLRenderer this

初始化 context

setupDepthTest(material)

设置深度检测

Name Type Description
material Material

setupSampleAlphaToCoverage(material)

设置alphaToCoverage

Name Type Description
material Material

setupCullFace(material)

设置背面剔除

Name Type Description
material Material

setupBlend(material)

设置混合

Name Type Description
material Material

setupStencil(material)

设置模板

Name Type Description
material Material

setupUniforms(program, mesh, force)

设置通用的 uniform

Name Type Default Description
program Program
mesh Mesh
force Boolean false optional

是否强制更新

setupVao(vao, program, mesh)

设置vao

Name Type Description
vao VertexArrayObject
program Program
mesh Mesh

setupMaterial(program, mesh)

设置材质

Name Type Description
program Program
mesh Mesh

setupMesh(mesh, useInstanced){Object}

设置mesh

Name Type Description
mesh Mesh
useInstanced Boolean
Returns:
Name Type Description
res Object
Name Type Description
res.vao VertexArrayObject
res.program Program
res.geometry Geometry

addRenderInfo(faceCount, drawCount)

增加渲染信息

Name Type Description
faceCount Number

面数量

drawCount Number

绘图数量

render(stage, camera, fireEvent)

渲染

Name Type Default Description
stage Stage | Node
camera Camera
fireEvent Boolean false optional

是否发送事件

渲染场景

clear(clearColor)

清除背景

Name Type Default Description
clearColor Color this.clearColor optional

清除深度

清除模板

renderToScreen(framebuffer)

将framebuffer渲染到屏幕

Name Type Description
framebuffer Framebuffer

渲染一个mesh

Name Type Description
mesh Mesh

renderInstancedMeshes(meshes)

渲染一组 instanced mesh

Name Type Description
meshes Array.<Mesh>

renderMultipleMeshes(meshes)

渲染一组普通mesh

Name Type Description
meshes Array.<Mesh>

releaseGLResource()

销毁 WebGL 资源