t3d. WebGLRenderer

The WebGL renderer.

Constructor

new WebGLRenderer(context)

Create a WebGL renderer.
Parameters:
NameTypeDescription
contextWebGLRenderingContextThe Rendering Context privided by canvas.

Extends

Members

asyncReadPixel :Boolean

Whether to perform readPixel operations asynchronously.
Type:
  • Boolean
Default Value
  • false

capabilities :t3d.WebGLCapabilities

An object containing details about the capabilities of the current RenderingContext.
Type:
  • t3d.WebGLCapabilities

context :WebGLRenderingContext|WebGPURenderingContext

The Rendering Context privided by canvas.
Type:
  • WebGLRenderingContext | WebGPURenderingContext

shaderCompileOptions :Object

The shader compiler options.
Type:
  • Object
Properties
NameTypeDescription
checkErrorsBooleanWhether to use error checking when compiling shaders, defaults to true.
compileAsynchronouslyBooleanWhether to compile shaders asynchronously, defaults to false.

Methods

beginQuery(query, target)

Begin a query instance.
Parameters:
NameTypeDescription
queryt3d.Query
targett3d.QUERY_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
readt3d.RenderTargetBaseThe source renderTarget.
drawt3d.RenderTargetBaseThe destination renderTarget.
colorBoolean<optional>
trueCopy color buffer.
depthBoolean<optional>
trueCopy depth buffer.
stencilBoolean<optional>
trueCopy stencil buffer.

clear(coloropt, depthopt, stencilopt)

Clear the color, depth and stencil buffers.
Parameters:
NameTypeAttributesDefaultDescription
colorBoolean<optional>
falseClear color buffer.
depthBoolean<optional>
falseClear depth buffer.
stencilBoolean<optional>
falseClear stencil buffer.

endQuery(query)

End a query instance.
Parameters:
NameTypeDescription
queryt3d.Query

endRender()

End rendering.

getClearColor() → {t3d.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: 
t3d.Vector4

getQueryResult(query) → {Number}

Get the query result.
Parameters:
NameTypeDescription
queryt3d.Query
Returns:
The query result.
Type: 
Number

getRenderTarget() → {t3d.RenderTargetBase|Null}

Returns the current RenderTarget if there are; returns null otherwise.
Returns:
Type: 
t3d.RenderTargetBase | Null

(protected) increaseId()

Used for context lost and restored.

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
queryt3d.Query
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
queryt3d.Query
Returns:
Returns true if the timer query was disjoint.
Type: 
Boolean

queryCounter(query)

Records the current time into the corresponding query object.
Parameters:
NameTypeDescription
queryt3d.Query

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
xNumberThe x coordinate of the rectangle to read from.
yNumberThe y coordinate of the rectangle to read from.
widthNumberThe width of the rectangle to read from.
heightNumberThe height of the rectangle to read from.
bufferTypedArrayUint8Array 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, options=opt)

Render a single renderable item with render states.
Parameters:
NameTypeAttributesDescription
renderableObjectThe renderable item.
renderStatest3d.RenderStatesThe render states.
options=t3d.RenderOptions<optional>
The render options for this render task.

renderRenderableList(renderables, renderStates, options=opt)

Render a single renderable list with render states.
Parameters:
NameTypeAttributesDescription
renderablesArrayArray of renderable.
renderStatest3d.RenderStatesRender states.
options=t3d.RenderOptions<optional>
The render options for this render task.

renderScene(scene, camera, options=opt)

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
scenet3d.SceneThe scene to render.
camerat3d.CameraThe camera used to render the scene.
options=t3d.RenderOptions<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>
falseWhether clear the current vertex array object.

setBufferExternal(buffer, webglBuffer)

Bind webglBuffer to t3d's buffer.
Parameters:
NameTypeDescription
buffert3d.Buffer
webglBufferWebGLBuffer

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

Set clear color.
Parameters:
NameTypeDescription
rNumberRed component in the range 0.0 - 1.0.
gNumberGreen component in the range 0.0 - 1.0.
bNumberBlue component in the range 0.0 - 1.0.
aNumberAlpha component in the range 0.0 - 1.0.
premultipliedAlphaNumberWhether the alpha is premultiplied.

setRenderBufferExternal(renderBuffer, webglRenderbuffer)

Bind webglRenderbuffer to t3d's renderBuffer.
Parameters:
NameTypeDescription
renderBuffert3d.RenderBuffer
webglRenderbufferWebGLRenderbuffer

setRenderTarget(renderTarget)

This method sets the active rendertarget.
Parameters:
NameTypeDescription
renderTargett3d.RenderTargetBaseThe renderTarget that needs to be activated.

setTextureExternal(texture, webglTexture)

Bind webglTexture to t3d's texture.
Parameters:
NameTypeDescription
texturet3d.TextureBase
webglTextureWebGLTexture

updateRenderTargetMipmap(renderTarget)

Generate mipmaps for the renderTarget you pass in.
Parameters:
NameTypeDescription
renderTargett3d.RenderTargetBaseThe renderTarget to update.