Class: WebGlStage

WebGlStage(opts)

A Stage implementation using WebGl.

Constructor

new WebGlStage(opts)

Parameters:
Name Type Description
opts Object
Properties
Name Type Attributes Default Description
antialias boolean <optional>
false
preserveDrawingBuffer boolean <optional>
false
generateMipmaps boolean <optional>
false

The antialias and preserveDrawingBuffer options control the WebGL context attributes of the same name. The alpha and premultipliedAlpha WebGL context attributes are set to their default true value and cannot be overriden; this allows semitransparent textures to be composited with the page. See: https://www.khronos.org/registry/webgl/specs/1.0/#WEBGLCONTEXTATTRIBUTES

The generateMipmaps option controls texture mipmap generation. Mipmaps may improve rendering quality, at the cost of increased memory usage. Due to technical limitations, they are only generated for textures whose dimensions are a power of two. See: https://www.khronos.org/webgl/wiki/WebGL_and_OpenGL_Differences#Non-Power_of_Two_Texture_Support

Extends

Methods

addLayer(layer, i)

Adds a layer into the stage.

Parameters:
Name Type Description
layer Layer

The layer to add.

i number | undefined

The optional position, where 0 ≤ i ≤ n and n is the current number of layers. The default is n, which inserts at the top of the display stack.

Inherited From:
Throws:

An error if the layer already belongs to the stage or if the position is invalid.

createTexture(tile, asset, done)

Create a texture for the given tile and asset. Called by TextureStore.

Parameters:
Name Type Description
tile Tile
asset Asset
done function
Inherited From:

destroy()

Destructor.

Overrides:

domElement() → {HTMLElement}

Inherited From:
Returns:

DOM element where layers are rendered

Type
HTMLElement

hasLayer(layer) → {boolean}

Return whether a layer belongs to the stage.

Parameters:
Name Type Description
layer Layer
Inherited From:
Returns:
Type
boolean

height() → {number}

Get the stage height.

Inherited From:
Returns:
Type
number

listLayers() → {Array.<Layer>}

Returns a list of all layers belonging to the stage. The returned list is in display order, background to foreground.

Inherited From:
Returns:
Type
Array.<Layer>

moveLayer(layer, i)

Moves a layer into a different position in the display stack.

Parameters:
Name Type Description
layer Layer

The layer to move.

i number

The position, where 0 ≤ i ≤ n-1 and n is the current number of layers.

Inherited From:
Throws:

An error if the layer does not belong to the stage or if the position is invalid.

registerRenderer(geometryType, viewType, Renderer)

Registers a Renderer for the given Geometry and View type.

The registerDefaultRenderers utility function may be used to register all known renderers for a stage type into that stage. Most users will not need to register renderers, as Viewer does it for them.

Parameters:
Name Type Description
geometryType string

The geometry type, as given by Geometry#type.

viewType string

The view type, as given by View#type.

Renderer *

The renderer class.

Inherited From:

removeAllLayers()

Removes all layers from the stage.

Inherited From:

removeLayer(layer)

Removes a Layer from the stage.

Parameters:
Name Type Description
layer Layer

The layer to remove.

Inherited From:
Throws:

An error if the layer does not belong to the stage.

render()

Render the current frame. Usually called from a RenderLoop.

This contains the rendering logic common to all stage types. Subclasses define the startFrame() and endFrame() methods to perform their own logic.

Inherited From:

setSize(obj)

Set the stage dimensions.

This contains the size update logic common to all stage types. Subclasses define the _setSize() method to perform their own logic, if required.

Parameters:
Name Type Description
obj Object
Properties
Name Type Description
width number
height number
Inherited From:

size(obj)

Get the stage dimensions. If an object argument is supplied, the object is filled in with the result and returned. Otherwise, a fresh object is returned.

Parameters:
Name Type Description
obj Object
Properties
Name Type Description
width number
height number
Inherited From:

type() → {string}

Returns the stage type, used to determine the appropriate renderer for a given geometry and view.

See also Stage#registerRenderer.

Overrides:
Returns:
Type
string

webGlContext() → {WebGLRenderingContext}

Returns:
Type
WebGLRenderingContext

width() → {number}

Get the stage width.

Inherited From:
Returns:
Type
number

Events

renderInvalid

Signals that the contents of the stage have been invalidated and must be rendered again.

Inherited From: