Renderer
Source: Renderer.ts:123
High-level WebGL interface that runs the WebGL handler in real time.
Fires
event:predraw - Triggered before each frame is rendered.event:resize - Triggered when the canvas is resized.event:mousemove - Triggered when the mouse moves over the canvas.event:mousestop - Triggered when the mouse stops moving.event:lclick - Triggered on left mouse button click.event:rclick - Triggered on right mouse button click.event:mclick - Triggered on middle mouse button click.event:ldblclick - Triggered on left mouse button double-click.event:rdblclick - Triggered on right mouse button double-click.event:mdblclick - Triggered on middle mouse button double-click.event:lup - Triggered when the left mouse button is released.event:rup - Triggered when the right mouse button is released.event:mup - Triggered when the middle mouse button is released.event:ldown - Triggered when the left mouse button is pressed.event:rdown - Triggered when the right mouse button is pressed.event:mdown - Triggered when the middle mouse button is pressed.event:lhold - Triggered while the left mouse button is held.event:rhold - Triggered while the right mouse button is held.event:mhold - Triggered while the middle mouse button is held.event:mousewheel - Triggered on mouse wheel scroll.event:touchstart - Triggered on touch start.event:touchend - Triggered on the touch end.event:touchcancel - Triggered on touch cancel.event:touchmove - Triggered on touch move.event:doubletouch - Triggered on double touch.event:touchleave - Triggered when touch leaves the canvas.event:touchenter - Triggered when touch enters the canvas.
Constructor
new Renderer(
handler: Handler | string | HTMLCanvasElement,
params?: IRendererParams,
): RendererParameters
handler(Handler | string | HTMLCanvasElement) — WebGL handler instance or canvas target selector/element.params(IRendererParams, optional, default: "{}") — Renderer parameters: - controls: Control instances to add to the renderer - msaa: MSAA (Multi-Sample Anti-Aliasing) level - autoActivate: Start rendering automatically after creation - deferredDisabled: Disable deferred shading pipeline and render deferred objects with forward shaders - fontsSrc: Path to font resources - gamma: Gamma correction value - exposure: HDR exposure value - frameOpacity: Scene objects opacity used with transparentBackground to achieve an AR effect - toneMapping: HDR tone mapping operator - dpi: Device pixel ratio - clearColor: RGBA clear color array - lightPosition: Light position[x, y, z]- lightAmbient: Light ambient color[r, g, b]- lightDiffuse: Light diffuse color[r, g, b]- lightSpecular: Light specular[r, g, b, shininess]
Instance Methods
setToneMapping(operator: string)
Sets HDR tone mapping operator and recompiles tone mapping shader.
Parameters
operator(string) — Tone mapping operator name.
getToneMapping(): string
Returns HDR tone mapping operator.
Returns
string
applyDepthForCamera()
Sets depth compare and clear value for the camera (reverse-Z vs classic). Pass null to restore the classic depth state: depthFunc(LESS), clearDepth(1), and clip-control NEGATIVE_ONE_TO_ONE.
setEventsActivity(activity: boolean)
Enables or disables renderer events.
Parameters
activity(boolean) — Events activity flag.
addPickingCallback(sender: any, callback: function): number
Adds a picking render callback.
Parameters
sender(any) — Callback context.callback(function) — Render callback function.
Returns
number— Callback ID.
removePickingCallback(id: number)
Removes a picking render callback.
Parameters
id(number) — Callback ID to remove.
assignPickingColor(obj: Object)
Assigns a picking color to an object.
Parameters
obj(Object) — Object that receives a picking color.
clearPickingColor(obj: Object)
Removes the picking color from an object.
Parameters
obj(Object) — Object to clear the picking color from.
getWidth(): number
Returns the canvas client width.
Returns
number
getHeight(): number
Returns the canvas client height.
Returns
number
getViewportCenter(): Vec2
Returns the canvas viewport center.
Returns
addControl(control: Control)
Adds a control to the renderer.
Parameters
control(Control) — Control.
addControls(cArr: Array.<Control>)
Adds an array of controls to the renderer.
Parameters
cArr(Array.<Control>) — Control array.
removeControl(control: Control)
Removes a control from the renderer.
Parameters
control(Control) — Control.
getInnerContainer()
The element the canvas is drawn in.
getUIContainer()
Where the interface goes: the container given for it, or the inner one.
initialize()
Renderer initialization.
addScene(scene: Scene)
Adds a scene to the renderer.
Parameters
scene(Scene) — Scene.
addSceneBefore(scene: Scene, sceneBefore: Scene)
Adds a scene to the renderer before a specific node.
Parameters
addScenes(nodesArr: Array.<Scene>)
Adds scenes to the renderer.
Parameters
nodesArr(Array.<Scene>) — Render nodes array.
enqueueEntityCollectionsToDraw()
TODO: replace with cache-friendly linked list by BillboardHandler, LabelHandler etc.
markForDepthRefresh()
Forces the depth buffer to be refreshed in the next frame. Has an effect for terrain altitude estimate precision.
requestRedraw()
Requests the next frame to be rendered.
draw()
Draw nodes.
getDistanceFromPixel(
px: Vec2 | IBaseInputState,
): number | undefined
Returns the distance from the active (screen) camera to the 3d-surface using the defined screen coordinates
Parameters
px(Vec2 | IBaseInputState) — Screen coordinates.
Returns
number | undefined
getCartesianFromPixel(
px: Vec2 | IBaseInputState,
): Vec3 | undefined
Returns 3d coordinates from screen coordinates
Parameters
px(Vec2 | IBaseInputState) — Screen coordinates.
Returns
Vec3| undefined
start()
Function starts renderer
addProgram(program: ShaderProgram)
Adds a shader program to the renderer if it has not been added yet.
Parameters
program(ShaderProgram) — ShaderProgram instance.
addPrograms(...programs: ShaderProgram | Array.<ShaderProgram>)
Adds one or more programs to the renderer. Supports both individual programs and nested program arrays.
Parameters
programs(ShaderProgram | Array.<ShaderProgram>) — ShaderProgram list.
addShaders(...programs: ShaderProgram | Array.<ShaderProgram>)
Alias for Renderer.addPrograms.
Parameters
programs(ShaderProgram | Array.<ShaderProgram>) — ShaderProgram list.
Instance Fields
billboardsTextureAtlas: TextureAtlas
Texture atlas for the billboard images.
fontAtlas: FontAtlas
Texture font atlas for the font families and styles.
strokeTextureAtlas: TextureAtlas
Texture atlas for the rays, polylines, and strips.
exposure: number
HDR exposure.
gamma: number
Gamma correction value.
whitepoint: number
Tone mapping white point.
frameOpacity: number
Scene objects opacity used with transparentBackground to achieve an AR effect.
brightThreshold: number
Bloom bright pass threshold.
isIdle
Returns true when the renderer skips frames because nothing has been changed.