WebGLRenderer

The WebGL renderer.

Constructor

new WebGLRenderer(contextopt)

Create a WebGLRenderer.

Parameters:
NameTypeAttributesDescription
contextWebGLRenderingContext<optional>

The WebGL Rendering Context privided by canvas. If not provided, you must call WebGLRenderer.init method with a valid context before using this renderer.

Extends

Members

capabilities :WebGLCapabilities

An object containing details about the capabilities of the current RenderingContext.

Type:
  • WebGLCapabilities

context :WebGLRenderingContext|WebGPURenderingContext

The Rendering Context privided by canvas.

Type:
  • WebGLRenderingContext | WebGPURenderingContext

(readonly) id :number

The unique id of this renderer. This will be incremented when the context is lost and restored.

Type:
  • number

lightingOptions :object

The lighting options.

Type:
  • object
Properties
NameTypeDescription
clusteredobject

The clustered lighting options.

Properties
NameTypeDescription
enabledboolean

Whether to use clustered lighting, defaults to false.

maxClusterLightsnumber

The maximum number of lights, defaults to 1024.

useFloatPrecisionboolean

Whether the lights are stored as floats, defaults to false (half floats).

gridDimensionsVector3

The number of cells in each dimension, defaults to Vector3(16, 8, 32).

maxLightsPerCellnumber

The maximum number of lights per cell, defaults to 256.

zClipVector2

The near and far clipping planes for the cells, defaults to Vector2(-1, -1) (clip based on camera near and far planes).

versionnumber

The version of the clustered lighting options. If the options change, the version should be incremented, defaults to 0.

shaderCompileOptions :object

The shader compiler options.

Type:
  • object
Properties
NameTypeDescription
checkErrorsboolean

Whether to use error checking when compiling shaders, defaults to true.

compileAsynchronouslyboolean

Whether to compile shaders asynchronously, defaults to false.

maxMaterialProgramsnumber

The maximum number of programs that one material can cache, defaults to 5.

Methods

beginOcclusionQuery(index)

Begin an occlusion query.

Parameters:
NameTypeDescription
indexnumber

The query index in the current occlusion query set.

beginRender(renderTarget)

Begin rendering.

Parameters:
NameTypeDescription
renderTargetRenderTargetBase

The render target to render to.

blitRenderTarget(read, draw, coloropt, depthopt, stencilopt)

Copy a frame buffer to another. This copy process can be used to perform multi-sampling (MSAA).

Parameters:
NameTypeAttributesDefaultDescription
readRenderTargetBase

The source renderTarget.

drawRenderTargetBase

The destination renderTarget.

colorboolean<optional>
true

Copy color buffer.

depthboolean<optional>
true

Copy depth buffer.

stencilboolean<optional>
true

Copy stencil buffer.

endOcclusionQuery()

End the current occlusion query.

endRender()

End rendering.

generateMipmaps(texture)

Generate mipmaps for the texture you pass in.

Parameters:
NameTypeDescription
textureTextureBase

The texture to update.

(protected) increaseId() → {number}

Used for context lost and restored.

Returns:
Type: 
number

init(context, optionsopt) → {Promise.<ThinRenderer>}

Initialize this renderer with a rendering context. This method is called automatically by WebGLRenderer constructor when a context is provided. For WebGPURenderer, you must call this method manually and wait for the promise to resolve.

Parameters:
NameTypeAttributesDescription
contextWebGLRenderingContext | WebGPURenderingContext

The rendering context.

optionsobject<optional>

The options for initializing this renderer.

Returns:

A promise that resolves when initialization completes.

Type: 
Promise.<ThinRenderer>

readQuerySetResults(querySet, dstBuffer, firstQueryopt, queryCountopt) → {Promise.<(Array|TypedArray)>}

Read back the results of a query set. This is an asynchronous operation.

Parameters:
NameTypeAttributesDefaultDescription
querySetQuerySet

The query set to read from.

dstBufferArray | TypedArray

The buffer to store the results.

firstQuerynumber<optional>
0

The first query index to read.

queryCountnumber<optional>
querySet.count

The number of queries to read.

Returns:

A promise that resolves with the passed in buffer after it has been filled with the results.

Type: 
Promise.<(Array|TypedArray)>

readTexturePixels(texture, x, y, width, height, buffer, zIndexopt, mipLevelopt) → {Promise.<TypedArray>}

Read pixels from a texture. This is an asynchronous operation. See ThinRenderer#readTexturePixelsSync for the synchronous version.

Parameters:
NameTypeAttributesDefaultDescription
textureTextureBase

The texture to read from.

xnumber

The x coordinate of the rectangle to read from.

ynumber

The y coordinate of the rectangle to read from.

widthnumber

The width of the rectangle to read from.

heightnumber

The height of the rectangle to read from.

bufferTypedArray

The buffer to store the pixel data.

zIndexnumber<optional>
0

For CubeTexture, the face index; for Texture3D/TextureArray, the layer/slice index.

mipLevelnumber<optional>
0

The mip level to read.

Returns:

A promise that resolves with the passed in buffer after it has been filled with the pixel data.

Type: 
Promise.<TypedArray>

readTexturePixelsSync(texture, x, y, width, height, buffer, zIndexopt, mipLevelopt) → {TypedArray}

Read pixels from a texture. This is a synchronous operation. See ThinRenderer#readTexturePixels for the asynchronous version.

Parameters:
NameTypeAttributesDefaultDescription
textureTextureBase

The texture to read from.

xnumber

The x coordinate of the rectangle to read from.

ynumber

The y coordinate of the rectangle to read from.

widthnumber

The width of the rectangle to read from.

heightnumber

The height of the rectangle to read from.

bufferTypedArray

The buffer to store the pixel data.

zIndexnumber<optional>
0

For CubeTexture, the face index; for Texture3D/TextureArray, the layer/slice index.

mipLevelnumber<optional>
0

The mip level to read.

Returns:

The passed in buffer after it has been filled with the pixel data.

Type: 
TypedArray

renderRenderableItem(renderable, renderStates, optionsopt)

Render a single renderable item with render states.

Parameters:
NameTypeAttributesDescription
renderableobject

The renderable item.

renderStatesRenderStates

The render states.

optionsRenderOptions<optional>

The render options for this render task.

renderRenderableList(renderables, renderStates, optionsopt)

Render a single renderable list with render states.

Parameters:
NameTypeAttributesDescription
renderablesArray

Array of renderable.

renderStatesRenderStates

Render states.

optionsRenderOptions<optional>

The render options for this render task.

renderScene(scene, camera, renderTarget, optionsopt)

Render a scene with a particular camera. This method will render all layers in scene's RenderQueue by default. If you need a customized rendering process, it is recommended to use renderRenderableList method.

Parameters:
NameTypeAttributesDescription
sceneScene

The scene to render.

cameraCamera

The camera used to render the scene.

renderTargetRenderTargetBase

The render target to render to.

optionsRenderOptions<optional>

The render options for this scene render task.

resetState()

Reset all render states cached in this renderer. This is useful when you use multiple renderers in one application.

resetVertexArrayBindings(forceopt)

Reset vertex array object bindings.

Parameters:
NameTypeAttributesDefaultDescription
forceboolean<optional>
false

Whether clear the current vertex array object.

setBufferExternal(buffer, webglBuffer)

Bind webglBuffer to Buffer.

Parameters:
NameTypeDescription
bufferBuffer
webglBufferWebGLBuffer

setFramebufferExternal(renderTarget, webglFramebuffer)

Bind webglFramebuffer to RenderTarget.

Parameters:
NameTypeDescription
renderTargetRenderTarget
webglFramebufferWebGLFramebuffer

setRenderBufferExternal(renderBuffer, webglRenderbuffer)

Bind webglRenderbuffer to RenderBuffer.

Parameters:
NameTypeDescription
renderBufferRenderBuffer
webglRenderbufferWebGLRenderbuffer

setTextureExternal(texture, webglTexture)

Bind webglTexture to Texture.

Parameters:
NameTypeDescription
textureTextureBase
webglTextureWebGLTexture