WebGLRenderer

The WebGL renderer.

Constructor

new WebGLRenderer(context)

Create a WebGL renderer.

Parameters:
NameTypeDescription
contextWebGLRenderingContext

The Rendering Context privided by canvas.

Extends

Members

asyncReadPixel :boolean

Whether to perform readPixel operations asynchronously.

Type:
  • boolean
Default Value
  • false

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

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

beginQuery(query, target)

Begin a query instance.

Parameters:
NameTypeDescription
queryQuery
targetQUERY_TYPE

beginRender()

Begin rendering.

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.

clear(coloropt, depthopt, stencilopt)

Clear the color, depth and stencil buffers.

Parameters:
NameTypeAttributesDefaultDescription
colorboolean<optional>
false

Clear color buffer.

depthboolean<optional>
false

Clear depth buffer.

stencilboolean<optional>
false

Clear stencil buffer.

endQuery(query)

End a query instance.

Parameters:
NameTypeDescription
queryQuery

endRender()

End rendering.

getClearColor() → {Vector4}

Returns a Vector4 instance with the current clear color and alpha. Note: Do not modify the value of Vector4, it is read-only.

Returns:
Type: 
Vector4

getQueryResult(query) → {number}

Get the query result.

Parameters:
NameTypeDescription
queryQuery
Returns:

The query result.

Type: 
number

getRenderTarget() → {RenderTargetBase|null}

Returns the current RenderTarget if there are; returns null otherwise.

Returns:
Type: 
RenderTargetBase | null

(protected) increaseId() → {number}

Used for context lost and restored.

Returns:
Type: 
number

init()

Initialize the renderer. This method will be called automatically by the constructor. In the case of context lost, you can call this function to restart the renderer.

isQueryResultAvailable(query) → {boolean}

Check if the query result is available.

Parameters:
NameTypeDescription
queryQuery
Returns:

If query result is available.

Type: 
boolean

isTimerQueryDisjoint(query) → {boolean}

Returns true if the timer query was disjoint, indicating that timing results are invalid. This is rare and might occur, for example, if the GPU was throttled while timing.

Parameters:
NameTypeDescription
queryQuery
Returns:

Returns true if the timer query was disjoint.

Type: 
boolean

queryCounter(query)

Records the current time into the corresponding query object.

Parameters:
NameTypeDescription
queryQuery

readRenderTargetPixels(x, y, width, height, buffer) → {Promise.<TypedArray>}

Reads the pixel data from the current render target into the provided buffer. The Renderer.asyncReadPixel property determines whether this operation is synchronous or asynchronous. To maintain consistency, this method always returns a Promise object.

Parameters:
NameTypeDescription
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

Uint8Array is the only destination type supported in all cases, other types are renderTarget and platform dependent.

Returns:

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

Type: 
Promise.<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, 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.

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

setClearColor(r, g, b, a, premultipliedAlpha)

Set clear color.

Parameters:
NameTypeDescription
rnumber

Red component in the range 0.0 - 1.0.

gnumber

Green component in the range 0.0 - 1.0.

bnumber

Blue component in the range 0.0 - 1.0.

anumber

Alpha component in the range 0.0 - 1.0.

premultipliedAlphanumber

Whether the alpha is premultiplied.

setRenderBufferExternal(renderBuffer, webglRenderbuffer)

Bind webglRenderbuffer to RenderBuffer.

Parameters:
NameTypeDescription
renderBufferRenderBuffer
webglRenderbufferWebGLRenderbuffer

setRenderTarget(renderTarget)

This method sets the active rendertarget.

Parameters:
NameTypeDescription
renderTargetRenderTargetBase

The renderTarget that needs to be activated.

setTextureExternal(texture, webglTexture)

Bind webglTexture to Texture.

Parameters:
NameTypeDescription
textureTextureBase
webglTextureWebGLTexture

updateRenderTargetMipmap(renderTarget)

Generate mipmaps for the renderTarget you pass in.

Parameters:
NameTypeDescription
renderTargetRenderTargetBase

The renderTarget to update.