Renderer

clay. Renderer

# new Renderer()

Source:

Extends

Members

# (static) COLOR_BUFFER_BIT :number

Source:
Type:
  • number

# (static) DEPTH_BUFFER_BIT :number

Source:
Type:
  • number

# (static) STENCIL_BUFFER_BIT :number

Source:
Type:
  • number

# __uid__ :number

Source:
Inherited From:
Type:
  • number

# alpha :boolean

Source:

If enable alpha, default true

Type:
  • boolean

# antialias :boolean

Source:

If enable antialias, default true

Type:
  • boolean

# (readonly) canvas :HTMLCanvasElement

Source:
Type:
  • HTMLCanvasElement

# clearBit :number

Source:

Default: _gl.COLOR_BUFFER_BIT | _gl.DEPTH_BUFFER_BIT | _gl.STENCIL_BUFFER_BIT

Type:
  • number

# clearColor :Array.<number>

Source:

Clear color

Type:
  • Array.<number>

# depth :boolean

Source:

If enable depth buffer, default true

Type:
  • boolean

# gl :WebGLRenderingContext

Source:

WebGL Context created from given canvas

Type:
  • WebGLRenderingContext

# maxJointNumber :number

Source:

Max joint number

Type:
  • number

# premultipliedAlpha :boolean

Source:

If enable premultiplied alpha, default true

Type:
  • boolean

# preserveDrawingBuffer :boolean

Source:

If preserve drawing buffer, default false

Type:
  • boolean

# stencil :boolean

Source:

If enable stencil buffer, default false

Type:
  • boolean

# throwError :boolean

Source:

If throw context error, usually turned on in debug mode

Type:
  • boolean

# viewport :Object

Source:

Renderer viewport, read-only, can be set by setViewport method

Type:
  • Object

Methods

# after(name, action, contextopt)

Source:
Inherited From:
Mixes In:

Alias of once('after' + name)

Parameters:
Name Type Attributes Description
name string
action function
context Object <optional>

# before(name, action, contextopt)

Source:
Inherited From:
Mixes In:

Alias of once('before' + name)

Parameters:
Name Type Attributes Description
name string
action function
context Object <optional>

# dispose()

Source:

Dispose renderer

# disposeFrameBuffer(frameBuffer)

Source:

Dispose given frame buffer

Parameters:
Name Type Description
frameBuffer clay.FrameBuffer

# disposeGeometry(geometry)

Source:

Dispose given geometry

Parameters:
Name Type Description
geometry clay.Geometry

# disposeNode(node, disposeGeometryopt, disposeTextureopt)

Source:

Dispose given node, including all geometries, textures and shaders attached on it or its descendant

Parameters:
Name Type Attributes Default Description
node clay.Node
disposeGeometry boolean <optional>
false

If dispose the geometries used in the descendant mesh

disposeTexture boolean <optional>
false

If dispose the textures used in the descendant mesh

# disposeScene(scene)

Source:

Dispose given scene, including all geometris, textures and shaders in the scene

Parameters:
Name Type Description
scene clay.Scene

# disposeTexture(texture)

Source:

Dispose given texture

Parameters:
Name Type Description
texture clay.Texture

# error(action, contextopt)

Source:
Inherited From:
Mixes In:

Alias of on('error')

Parameters:
Name Type Attributes Description
action function
context Object <optional>

# getDevicePixelRatio(devicePixelRatio)

Source:

Get devicePixelRatio

Parameters:
Name Type Description
devicePixelRatio number

# getGLExtension(name) → {object}

Source:

Get WebGL extension

Parameters:
Name Type Description
name string
Returns:
Type
object

# getGLParameter(name) → {*}

Source:

Get WebGL parameter

Parameters:
Name Type Description
name string
Returns:
Type
*

# getHeight() → {number}

Source:

Get renderer height

Returns:
Type
number

# getViewportAspect() → {number}

Source:

Get viewport aspect,

Returns:
Type
number

# getWidth() → {number}

Source:

Get renderer width

Returns:
Type
number

# has(name, action) → {boolean}

Source:
Inherited From:
Mixes In:

If registered the event handler

Parameters:
Name Type Description
name string
action function
Returns:
Type
boolean

# off(action, contextopt)

Source:
Inherited From:
Mixes In:

Remove event listener

Parameters:
Name Type Attributes Description
action function
context Object <optional>

# on(name, action, contextopt)

Source:
Inherited From:
Mixes In:

Register event handler

Parameters:
Name Type Attributes Description
name string
action function
context Object <optional>

# once(name, action, contextopt)

Source:
Inherited From:
Mixes In:

Register event, event will only be triggered once and then removed

Parameters:
Name Type Attributes Description
name string
action function
context Object <optional>

# render(scene, camera, notUpdateSceneopt, preZopt) → {IRenderInfo}

Source:

Render the scene in camera to the screen or binded offline framebuffer

Parameters:
Name Type Attributes Description
scene clay.Scene
camera clay.Camera
notUpdateScene boolean <optional>

If not call the scene.update methods in the rendering, default true

preZ boolean <optional>

If use preZ optimization, default false

Returns:
Type
IRenderInfo

# renderPass(list, cameraopt, passConfigopt) → {IRenderInfo}

Source:

Render a single renderable list in camera in sequence

Parameters:
Name Type Attributes Description
list Array.<clay.Renderable>

List of all renderables.

camera clay.Camera <optional>

Camera provide view matrix and porjection matrix. It can be null.

passConfig Object <optional>
Properties
Name Type Attributes Description
getMaterial function <optional>

Get renderable material.

getUniform function <optional>

Get material uniform value.

isMaterialChanged function <optional>

If material changed.

beforeRender function <optional>

Before render each renderable.

afterRender function <optional>

After render each renderable

ifRender function <optional>

If render the renderable.

sortCompare function <optional>

Sort compare function.

Returns:
Type
IRenderInfo

# resize(width, height)

Source:

Resize the canvas

Parameters:
Name Type Description
width number
height number

# restoreClear()

Source:

Pop clear from stack, restore in the renderer

# restoreViewport()

Source:

Pop viewport from stack, restore in the renderer

# saveClear()

Source:

Push current clear into a stack

# saveViewport()

Source:

Push current viewport into a stack

# screenToNDC(x, y, outopt) → {clay.Vector2}

Source:

Convert screen coords to normalized device coordinates(NDC) Screen coords can get from mouse event, it is positioned relative to canvas element NDC can be used in ray casting with Camera.prototype.castRay methods

Parameters:
Name Type Attributes Description
x number
y number
out clay.Vector2 <optional>
Returns:
Type
clay.Vector2

# setDevicePixelRatio(devicePixelRatio)

Source:

Set devicePixelRatio

Parameters:
Name Type Description
devicePixelRatio number

# setViewport(x, yopt, widthopt, heightopt, devicePixelRatioopt)

Source:

Set rendering viewport

Example
setViewport(0,0,width,height,1)
 setViewport({
     x: 0,
     y: 0,
     width: width,
     height: height,
     devicePixelRatio: 1
 })
Parameters:
Name Type Attributes Description
x number | Object
y number <optional>
width number <optional>
height number <optional>
devicePixelRatio number <optional>

Defaultly use the renderere devicePixelRatio It needs to be 1 when setViewport is called by frameBuffer

# success(action, contextopt)

Source:
Inherited From:
Mixes In:

Alias of on('success')

Parameters:
Name Type Attributes Description
action function
context Object <optional>

# trigger(name)

Source:
Inherited From:
Mixes In:

Trigger event

Parameters:
Name Type Description
name string