Introducing a new way to review your PRs.

Read the announcement

visgl / deck.gl

WebGL2 powered visualization framework

View on GitHub

23 documents · Updated Nov 20, 2026

docs / core-rendering-engine

Core rendering engine

The core rendering engine turns a Deck configuration into a live GPU scene. It combines views, view state, layers, effects, presentation targets, and input events so that the scene updates when needed and produces user-visible output and interaction results.

Runtime architecture

The runtime is coordinated by Deck, the main owner of the device, animation loop, presentation targets, view manager, layer manager, effect manager, renderer, picker, and widgets. Each manager owns one part of the scene. Deck passes shared device state, current props, viewports, layers, selected presentation contexts, and callbacks between them. (modules/…/deck.ts• L317-387, modules/…/deck.ts• L1662-1722)

The engine has two related outputs. The screen path produces color pixels for one or more presentation canvases. The picking path produces object references for pointer events and explicit pick queries. Both paths use the same layer, viewport, and presentation-target state so that a user-visible object and its interaction result remain aligned.

This diagram shows how configuration becomes viewports and layer state, then becomes pixels or interaction results.

flowchart TD
    Config[Deck configuration] --> Deck[Deck runtime]
    Deck --> Views[Views and view state]
    Deck --> Layers[Layer state]
    Deck --> Effects[Effects]
    Views --> Viewports[Viewports]
    Layers --> Draw[Screen rendering]
    Effects --> Draw
    Viewports --> Draw
    Draw --> Targets[Presentation targets]
    Layers --> Pick[Picking rendering]
    Viewports --> Pick
    Targets --> Canvas[Presentation canvases]
    Pick --> Events[Picking info and callbacks]

Runtime roles

The managers form clear boundaries. Deck accepts changes and schedules work. The canvas manager keeps presentation targets and event routes aligned. The view manager resolves camera state into viewports. The layer manager owns the active layer tree and its state. The renderer and picker turn that shared scene into GPU work or interaction results.

AreaRuntime responsibility
Device and canvasProvide the shared GPU device and drawing or presentation targets.
ViewsDefine camera types, layout, view state, and controller routing.
LayersRepresent drawable data, generated sublayers, GPU resources, and layer-local state.
EffectsAdd lighting, shader settings, or work before and after layer drawing.
RendererRun screen or debug draw passes for active viewports.
PickerRun an off-screen reference pass and turn pixels into picking information.
WidgetsReceive redraw and interaction results for user interface updates.

References: modules/…/deck.ts• L330-342 modules/…/deck.ts• L1662-1722 modules/…/deck-renderer.ts• L22-45 modules/…/deck-picker.ts• L70-97

Configuration and state

Deck treats props as the public description of the scene. A prop update is distributed to the managers, which decide whether it changes layout, layer state, effects, canvas presentation, or only the next draw. The existing canvas path remains the single-canvas contract. The experimental _canvases path opts into several presentation canvases and rejects incompatible single-canvas inputs. (modules/…/deck.ts• L517-607, modules/…/deck.ts• L1166-1196)

The runtime keeps camera state and layer state separate. View state controls where a view looks. Layer state controls how a layer prepares data and GPU resources. The managers use these states to rebuild only the affected part of the scene before the next redraw.

View and canvas state

The view manager converts view descriptions and view state into ordered viewports. A viewport contains the camera projection, the screen region used for drawing, and the presentation canvas route for that view. Each view uses the CSS size of its assigned canvas for layout. Its controller uses the event manager for the same canvas. (modules/…/view-manager.ts• L224-240, modules/…/view-manager.ts• L474-555)

The view manager keeps a view's canvas id and event manager together. If either changes, it replaces the controller so the controller does not keep listening to the old target. Deck also resolves that canvas id to the context used for rendering and picking. This keeps camera input, viewport layout, rendering, and picking in the same coordinate space. (modules/…/view-manager.ts• L496-529, modules/…/deck.ts• L746-760, modules/…/deck.ts• L1352-1362)

View state may be controlled by the application through viewState or tracked inside Deck from initialViewState. Controllers report user changes through the view-state callback, and the next update applies the resulting state to the viewport set. (modules/…/deck.ts• L519-535, modules/…/deck.ts• L1854-1867)

The single-canvas path uses the device's default canvas context. Multi-canvas mode renders through an off-screen context, resizes that context to the selected presentation target before drawing or picking, and presents each target after its assigned viewports finish. A resize on any target invalidates view layout, including when the default target size does not change. (modules/…/deck.ts• L1231-1246, modules/…/deck.ts• L1364-1373, modules/…/deck.ts• L1397-1459)

References: modules/…/view-manager.ts• L89-105 modules/…/view-manager.ts• L224-240 modules/…/view-manager.ts• L257-283 modules/…/view-manager.ts• L395-555 modules/…/canvas-manager.ts• L75-149 modules/…/deck.ts• L746-760 modules/…/deck.ts• L1231-1246 modules/…/deck.ts• L1352-1373 modules/…/deck.ts• L1397-1459

Layer state

The layer manager receives a possibly nested layer list and resolves it into the flat set that can be rendered. It matches new layers to old layers by id, transfers state for matched layers, creates sublayers for composite layers, and finalizes layers that are no longer present. This lets a new configuration reuse the state that belongs to the same logical layer.

Layer matching and sublayer creation wait when no viewport is available. When viewports become available, the manager reconnects retained layers to a materialized viewport and marks them for a fresh update. A layer whose coordinate system needs an asynchronous source definition also waits until that definition is ready. (modules/…/layer-manager.ts• L214-300, modules/…/layer-manager.ts• L397-484)

When a layer needs an update, its lifecycle prepares data and resources before drawing. A layer can mark itself for a redraw or request a deeper update when props, data, async values, attributes, or generated sublayers change. The dedicated layer lifecycle and state page describes this contract in more detail.

References: modules/…/layer-manager.ts• L135-212 modules/…/layer-manager.ts• L214-274 modules/…/layer-manager.ts• L282-300 modules/…/layer-manager.ts• L327-423 modules/…/layer-manager.ts• L445-484

Rendering pipeline

The render pipeline takes the current layer set and viewport set and draws each eligible layer into a target. DeckRenderer selects the normal draw pass or the picking-color pass, supplies the active canvas context, and applies view, layer, device-pixel, effect, and pass settings before it calls the layer to issue its GPU draw work. (modules/…/deck.ts• L1766-1845, modules/…/deck-renderer.ts• L72-127)

The pipeline keeps screen drawing, picking, and shadow rendering as related pass types over the same scene. A screen pass writes normal colors. A picking pass writes encoded object references to an off-screen target. A shadow pass writes depth information to a shadow map. Effects can contribute shader settings to the passes that need them.

Viewport rendering

For each viewport, the layers pass sets the viewport region, applies view clear rules, checks visibility and layer filters, then draws eligible drawable layers in stack order. The active viewport is also placed in layer context so layer projection and state updates use the same camera that produced the pixels. A layer is activated for shared geometry preparation during normal rendering, while picking reuses that prepared state. (modules/…/layers-pass.ts• L139-195, modules/…/layers-pass.ts• L269-397, modules/…/layers-pass.ts• L434-479)

Layer parameters are resolved from the broadest scope to the narrowest scope. Deck settings provide defaults, view settings refine them, and layer settings provide the final layer-specific values. Shader module properties carry projection, picking, layer, and effect data into the GPU model. (modules/…/layers-pass.ts• L227-266, modules/…/layers-pass.ts• L482-531)

The pass supports viewports with multiple physical subviewports. WebGL can draw them in one render pass. WebGPU submits each physical viewport before shared model uniforms change for the next one. This keeps the same logical scene correct on both device types. When a pass uses a color mask, WebGL applies that mask while clearing as well as while drawing, so a mask pass does not erase channels that belong to another pass. (modules/…/layers-pass.ts• L95-147, modules/…/layers-pass.ts• L151-207)

View clearing follows the pass being run. Screen rendering uses the view's clear color, while picking keeps its reference buffer clear so background pixels do not become object references. If no viewport is active, the pass still clears and submits the target so an old frame cannot remain visible. (modules/…/layers-pass.ts• L111-147, modules/…/layers-pass.ts• L318-356)

Custom projection views use this same viewport path while supplying their own coordinate transformation. The custom projections page describes how that projection support reaches layers and rendered output.

The projection shader library provides the shared GPU coordinate contract for these views. It maps layer positions into common space for flat, globe, auto-offset, and custom geospatial modes, then maps common positions to clip space. Custom geospatial rendering can use an external local scale field. Globe rendering also handles horizon occlusion and billboard placement so screen output follows the active projection across GPU backends. (modules/…/project.glsl.ts• L23-43, modules/…/project.glsl.ts• L109-150, modules/…/project.glsl.ts• L287-379, modules/…/project.glsl.ts• L406-477, modules/…/project.wgsl.ts• L33-61, modules/…/project.wgsl.ts• L293-386, modules/…/project.wgsl.ts• L416-481)

In multi-canvas mode, Deck groups viewports by presentation target. It resizes the shared render context for the target, renders each group, and presents it before moving to the next group. A target with no assigned viewports is still cleared and presented so stale pixels do not remain visible. (modules/…/deck.ts• L1796-1830)

References: modules/…/deck.ts• L1766-1845 modules/…/deck-renderer.ts• L50-127 modules/…/layers-pass.ts• L91-207 modules/…/layers-pass.ts• L201-281 modules/…/layers-pass.ts• L288-412 modules/…/layers-pass.ts• L434-531 modules/…/project.glsl.ts• L23-43 modules/…/project.glsl.ts• L86-150 modules/…/project.glsl.ts• L287-379 modules/…/project.glsl.ts• L406-477 modules/…/project.wgsl.ts• L33-61 modules/…/project.wgsl.ts• L293-386 modules/…/project.wgsl.ts• L416-481

Shared path rendering

The core shader library provides shared GPU rules for path geometry and style. Path layers use this shared contract to turn line data and path settings into strokes across supported rendering backends. The shader also exposes extension points for path color, filtering, and style changes, so layer extensions can change the result without replacing the common path model. (modules/…/path.wgsl.ts• L7-35, modules/…/path.wgsl.ts• L281-477, modules/…/path.wgsl.ts• L480-568)

Path uniforms carry the shared stroke settings between layer state and the GPU. The contract covers width, units, joins, caps, miter limits, and billboard behavior. Core exports the shader and uniform contract as internal symbols so related layers and extensions can use the same rendering rules. (modules/…/path-uniforms.ts• L36-62, modules/…/index.ts• L168-181)

References: modules/…/path-uniforms.ts• L7-62 modules/…/path.wgsl.ts• L7-35 modules/…/path.wgsl.ts• L281-477 modules/…/path.wgsl.ts• L480-568 modules/…/index.ts• L168-181

Effect processing

Effects extend the layer draw without changing the layer list. They can prepare GPU state before drawing, add shader settings for layers, and process the rendered image after drawing. The effect manager keeps user effects and default effects in render order, and it supplies lighting when the application has not supplied a lighting effect. (modules/…/effect-manager.ts• L33-55, modules/…/effect-manager.ts• L71-105)

When an effect has a post-render stage, DeckRenderer renders the scene into temporary buffers instead of sending it straight to the presentation target. It then passes the current buffer through each post-render effect, swaps buffers between stages, and sends the final result to the target. The buffers follow the selected canvas context's drawing size. (modules/…/deck-renderer.ts• L101-121, modules/…/deck-renderer.ts• L154-212)

References: modules/…/effect.ts• L21-43 modules/…/effect-manager.ts• L67-115 modules/…/deck-renderer.ts• L101-121 modules/…/deck-renderer.ts• L154-212

Screen composition

Screen composition turns an intermediate color buffer into the next render target. A screen pass samples the prior buffer with its size and applies the selected screen shader module, which lets post-render stages form a chain before the final image is presented. (modules/…/screen-pass.ts• L27-87, modules/…/screen-pass-uniforms.ts• L8-25)

References: modules/…/deck-renderer.ts• L88-108 modules/…/screen-pass.ts• L27-87 modules/…/screen-pass-uniforms.ts• L8-25

Shadow rendering

Shadow rendering is a separate layer pass that builds a packed depth map for later lighting. It stores the map in a framebuffer with color and depth attachments, resizes that target to the active viewport's device-pixel size, and uses depth-first draw settings without color blending. Layers can opt out through their shadow setting. (modules/…/shadow-pass.ts• L10-45, modules/…/shadow-pass.ts• L55-74, modules/…/shadow-pass.ts• L76-105)

The pass disables lighting while it writes depth and removes polygon depth bias from the shadow-map draw. These rules keep the packed depth value unchanged and reduce self-shadowing when the map is used by the lighting stage. (modules/…/shadow-pass.ts• L76-105)

References: modules/…/shadow-pass.ts• L10-45 modules/…/shadow-pass.ts• L55-74 modules/…/shadow-pass.ts• L76-105

Update scheduling

The render loop is a demand-driven coordinator. Changes set redraw or update reasons in the relevant manager. On each animation frame, Deck resolves pending viewports, updates layers, services pending picking work, redraws if any manager is dirty, and then advances view transitions. The Deck instance and render loop page explains this frame order and its timing rules. (modules/…/deck.ts• L1849-1887)

Dirty state

The runtime distinguishes between a redraw and an update. A redraw repeats GPU drawing with existing prepared state. An update can rebuild layers, regenerate attributes, or rebuild viewports before it causes a redraw. Deck.needsRedraw combines these signals with effect and renderer signals, so a caller can inspect one reason before it invokes redraw. (modules/…/deck.ts• L618-649, modules/…/layer-manager.ts• L135-178)

The animation loop can redraw every frame when animation is enabled. Otherwise, the engine skips frames with no pending work. This keeps static scenes quiet while still allowing transitions, async data, pointer picking, canvas resizing, and explicit redraw requests to produce fresh output. (modules/…/deck.ts• L628-677, modules/…/deck.ts• L1849-1887)

References: modules/…/deck.ts• L618-677 modules/…/deck.ts• L1849-1887 modules/…/view-manager.ts• L194-222 modules/…/view-manager.ts• L339-371 modules/…/layer-manager.ts• L157-178

User interactions and picking

Picking connects GPU output to user-visible interaction. The engine renders pickable layers into a separate buffer, encodes the layer and object identity in pixel values, reads the affected pixels, and builds PickingInfo for controllers, layers, application callbacks, and widgets. The interaction and picking page covers the event and query behavior in detail.

Pointer interaction

Pointer movement is coalesced until the next animation frame. The frame then runs a point pick for the latest position on the event's presentation canvas and dispatches hover information. Click and drag events use a pick at the start of the gesture, then pass the resulting info to the layer first and to the Deck and widget callbacks when the layer does not handle the event. (modules/…/deck.ts• L1565-1638, modules/…/deck.ts• L1875-1970)

Async hover picks are tied to the latest pointer request. If the pointer moves again before an earlier GPU query returns, Deck ignores the older result. This prevents a delayed query from moving the cursor state or hover callback back to an earlier position. (modules/…/deck.ts• L1600-1638)

This ordering gives a layer the first chance to handle its own interaction while preserving application-wide callbacks as a fallback. The same picking information also drives cursor state and the default tooltip widget.

References: modules/…/deck.ts• L399-412 modules/…/deck.ts• L1565-1638 modules/…/deck.ts• L1518-1592 modules/…/deck.ts• L1875-1970

Picking queries

Point and rectangle queries select the requested presentation canvas and the viewports that contain the request, render only the relevant pickable layers, and decode the result into one or more objects. In multi-canvas mode, an omitted canvas id uses the default presentation target. Before the query, Deck resizes the shared render context to that target. CSS-pixel input is then converted through the selected context into drawing-buffer pixels so the query remains correct when device-pixel scaling changes. (modules/…/deck.ts• L1067-1166, modules/…/deck.ts• L1359-1373, modules/…/deck-picker.ts• L178-287)

The picker supports synchronous queries for WebGL and asynchronous queries for devices such as WebGPU. Deck selects the mode automatically unless the application sets it. A synchronous request on WebGPU is rejected. A point query can inspect overlapping objects by repeating the pass while temporarily hiding the object already found. A depth query can also request a three-dimensional coordinate for layers that support it. (modules/…/deck.ts• L946-970, modules/…/deck-picker.ts• L293-390)

The picker skips the GPU pass when picking is disabled or when no layer can be picked. Otherwise, it keeps a separate color buffer for object identity and an optional depth buffer for three-dimensional results. (modules/…/deck-picker.ts• L178-225, modules/…/deck-picker.ts• L293-390)

References: modules/…/deck-picker.ts• L99-115 modules/…/deck-picker.ts• L178-225 modules/…/deck-picker.ts• L293-390 modules/…/deck.ts• L946-970 modules/…/deck.ts• L1067-1166

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep view canvas routing aligned across ViewManager, CanvasManager, controller events, viewport lookup, and picking queries. A view that draws on one canvas but picks on another produces plausible but wrong interaction results.
  • Preserve layer ids and parent relationships when changing layer generation. The layer manager uses them to transfer state and match generated sublayers across updates.
  • Do not let layer matching or sublayer generation run without a valid viewport. The first available viewport also establishes the projection context for retained layers.
  • Review effect participation in screen, picking, and shadow passes. An effect that changes shader inputs or depth behavior may need matching support to keep interaction and lighting geometry consistent.
  • Update redraw and update signals when changing async props, transitions, or shared shader modules. A missing signal can leave valid state prepared but invisible until a later change.
  • Keep CSS-pixel and drawing-buffer conversions in step when changing canvas sizing or device-pixel policy. View layout and picking use CSS coordinates, while GPU targets use drawing-buffer coordinates.
  • Keep the single-canvas and multi-canvas contracts separate. Multi-canvas mode needs an off-screen-capable device and cannot also use canvas, gl, or a device with a non-off-screen default context.
  • Keep each view's canvasId, presentation target, event manager, viewport set, and picking query aligned. A stale target map can send correct-looking events to the wrong view.
  • Keep screen-pass input buffers, output targets, and texture-size uniforms aligned when changing post-render effect chains. A mismatch can produce a valid frame with incorrect sampling.
  • Preserve the layer-pass clear and submission rules when changing picking or mask passes. Incorrect clear behavior can leave stale pixels or erase channels owned by another stage.
  • Keep renderer buffer sizes tied to the active presentation context when changing post-render effects or multi-canvas presentation. A buffer sized for another target can make the final image sample the wrong area.
  • Keep the automatic picking mode aligned with device type. WebGPU requires asynchronous picking, while controller position picking needs a synchronous mode to return a result immediately.
  • Keep path shader exports, uniform names, and backend types aligned when changing shared path rendering. A mismatch can break path-layer shader assembly or produce different stroke behavior across devices.
  • Keep the projection uniform layout and coordinate helpers aligned between the GLSL and WGSL shader contracts. A mismatch can change position, scale, or globe visibility by backend.

Important failure modes

TriggerConsequenceGuard
Two active layers use the same idState matching becomes ambiguous and a new layer can reuse the wrong prior state.Give every logical layer and generated sublayer a stable unique id.
viewState and initialViewState are both suppliedAutomatic view-state tracking is disabled, so later camera changes must come from the controlled state path.Use one camera ownership model for each Deck instance.
A view has not finished initializingIts viewport is absent until initialization completes, so its layers and controller cannot use that view yet.Keep the view in the active set and allow the next update to rebuild its viewport after initialization.
Picking is disabled or no layer is pickablePoint and gesture queries return empty picking information and layer interaction callbacks do not receive an object.Enable picking and set pickable on the intended layers.
Synchronous picking is requested on a WebGPU deviceThe picking mode is rejected and the error callback receives the configuration error.Use asynchronous picking with WebGPU.
More than 255 pickable layers are encoded in one picking passLater layers cannot receive a unique alpha code and only the first 255 are pickable.Reduce the active pickable layer set or split the interaction scope.
The GPU context is lostRendering cannot produce reliable new output until the device or context is restored by the host integration.Handle onError and recreate or reconnect the device as required by the host.
Multi-canvas mode runs without OffscreenCanvas supportDeck cannot create the shared render target and initialization fails.Use a supported browser or the existing single-canvas path.
_canvases is combined with canvas, gl, or a non-off-screen device contextThe canvas configuration is invalid and Deck rejects it rather than mixing incompatible presentation paths.Configure either the single-canvas contract or the multi-canvas contract.
A view's canvas context changes size but the shared render context is not resized before a passRendering or picking uses stale drawing-buffer dimensions and can sample or present the wrong region.Resize the shared context from the selected presentation target before rendering or picking.
A mask pass clears channels outside its write maskA later rendering stage loses color or picking data produced by another stage.Keep the WebGL color mask active while the pass clears and draws.
A render target is not cleared when no viewport is assignedA presentation canvas can show pixels from an earlier frame.Keep the empty-target clear and submit path active for each presentation target.
A shadow target uses stale viewport dimensionsShadow results do not match the current scene size and can produce wrong lighting.Let the shadow pass resize its target from the active viewport before rendering.
A consumer keeps importing a moved path shader module from its old package pathShader assembly fails before the path layer can render.Use the core shader exports and keep dependent imports aligned with the shared module location.
Path uniform layouts differ between the shader declaration and the values supplied by a layerPath width, cap, join, or billboard settings are read incorrectly by the GPU.Treat the shared WGSL, GLSL, and TypeScript uniform definitions as one contract.
GLSL and WGSL projection helpers or uniform layouts divergeThe same layer can have different position, scale, or globe visibility behavior on different GPU backends.Keep projection modes, uniform fields, coordinate transforms, and clip-space rules aligned in both shader contracts.

Key files

FileWhy to read it
modules/…/deck.tsMain runtime boundary. It accepts configuration, owns managers and presentation targets, schedules frames, routes canvas contexts, and dispatches public callbacks.
modules/…/view-manager.tsShows how view descriptions become viewports, controllers, canvas routes, and camera state.
modules/…/canvas-manager.tsShows how optional presentation canvases share one device while keeping size and event routing local.
modules/…/layer-manager.tsShows how the active layer tree is matched, updated, deferred until a viewport exists, and exposed to the renderer.
modules/…/layer.tsDefines the layer contract between prepared layer state, GPU resources, drawing, and picking information.
modules/…/deck-renderer.tsConnects active layers and viewports to draw or picking passes, effects, intermediate buffers, and presentation targets.
modules/…/layers-pass.tsExplains the shared per-viewport draw path and the rules for layer visibility, filters, parameters, projection, clearing, and device submission.
modules/…/screen-pass.tsShows how an intermediate rendered image is composed into the next target during screen-stage processing.
modules/…/screen-pass-uniforms.tsDefines the screen-stage data that identifies the source texture and its size.
modules/…/shadow-pass.tsShows the separate depth-map pass used to support shadow lighting.
modules/…/deck-picker.tsExplains off-screen picking, target-specific coordinate conversion, object decoding, overlap queries, and three-dimensional depth picks.
modules/…/effect-manager.tsExplains effect ownership, default lighting, ordering, and effect lifecycle.
modules/…/index.tsShows the core package boundary and the internal exports for shared rendering and path shader contracts.
modules/…/project.glsl.tsDefines the GLSL projection contract for coordinate transforms, scale, globe visibility, and clip-space output.
modules/…/project.wgsl.tsDefines the matching WGSL projection contract for WebGPU rendering.
modules/…/path-uniforms.tsDefines the shared path stroke settings passed from layer state to GPU shaders.
modules/…/path.wgsl.tsShows the shared path shader behavior and extension points used during GPU rendering.