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 / deck-instance-and-render-loop

Deck instance and render loop

The Deck instance is the core runtime that turns application state into rendered frames. It coordinates the GPU device, canvas targets, views, layers, effects, picking, widgets, and the frame loop so that changes appear on the right output surface.

Runtime configuration

modules/…/deck.ts defines the runtime contract for output, device choice, scene content, camera state, frame policy, and application callbacks. A configuration change is merged into the current runtime and passed to the managers that own the affected part of a frame.

The main configuration areas are:

AreaPurpose
Device and outputReuse or create a GPU device and render to one canvas or to experimental multi-canvas targets.
Views and camera stateDefine view regions and choose externally controlled or Deck-tracked camera state.
Scene contentProvide layers and effects that describe the rendered scene.
Frame policyControl device-pixel use, GPU parameters, continuous animation, render targets, and layer filtering.
Integration callbacksObserve device setup, resize, view changes, rendering, loading, errors, and input.

If no view is supplied, Deck creates a full-screen MapView. The controller shorthand applies to that default view. viewState has priority over internal state, while initialViewState enables Deck to track camera changes after interaction. modules/…/deck.ts• L1535-1555

References: modules/…/deck.ts• L105-274 modules/…/deck.ts• L276-330 modules/…/deck.ts• L1541-1555

Device and canvas resources

Deck uses a luma.gl Device as the shared owner of GPU work. It can use a supplied device or WebGL context, or create a device with a canvas context and the required rendering defaults. Shader and pipeline caches support reuse across layer draws. modules/…/deck.ts• L455-492 modules/…/deck.ts• L1491-1533

The normal path renders to one canvas. Experimental multi-canvas mode renders into an offscreen device canvas, then presents the result to each configured canvas. A view can select its target with canvasId; a view without one uses the first target. CanvasManager keeps those targets and their event resources aligned. modules/…/deck.ts• L161-166 modules/…/deck.ts• L1203-1283

Canvas contexts provide the authoritative CSS size and drawing-buffer size. Deck mirrors the active size into its runtime, invalidates view layout after resize, and matches the offscreen drawing buffer to the selected presentation target before a multi-canvas render or pick. modules/…/deck.ts• L1293-1459

Deck owns resize handling while it is active, but it preserves the ownership boundary for supplied devices and canvases. Finalization stops the loop and releases Deck-managed resources without removing an application-owned canvas. modules/…/deck.ts• L495-541 modules/…/deck.ts• L1299-1329

References: modules/…/deck.ts• L455-492 modules/…/deck.ts• L1203-1283 modules/…/deck.ts• L1293-1459 modules/…/deck.ts• L1491-1533

View and viewport management

The view system turns named view descriptions and camera state into active viewports. A view defines a region and camera rules. A viewport is the resolved camera and coordinate transform for that region at the current canvas size. For custom projections, the viewport also carries the resolved target coordinate system and the conversions needed to keep projection, distance, and pointer operations in one coordinate model. modules/…/custom-projection-viewport.ts• L29-40 modules/…/custom-projection-viewport.ts• L213-288

Deck keeps viewport layout in CSS pixels for view and input decisions. The render path uses the matching device-pixel drawing buffer for GPU work. In multi-canvas mode, each view and viewport keeps its canvas assignment so layout, input, rendering, and picking use the same target. modules/…/deck.ts• L723-735 modules/…/deck.ts• L1796-1833

The view manager can wait for asynchronous view setup before it creates a viewport. A failed view remains known to the runtime so a later descriptor can retry it. This allows projection or other view resources to become ready without breaking the rest of the frame. modules/…/view-manager.ts• L339-449 modules/…/custom-projection-view.ts• L33-99

The runtime supports view types with different camera and coordinate rules. The Deck loop treats the resulting viewports as the common input to rendering and picking. See Custom projections for the projection-specific contract. modules/…/custom-projection-viewport.ts• L42-109 modules/…/custom-projection-viewport.ts• L118-210

References: modules/…/deck.ts• L723-735 modules/…/deck.ts• L1541-1555 modules/…/deck.ts• L1711-1729 modules/…/deck.ts• L1866-1869 modules/…/deck.ts• L1796-1833 modules/…/view-manager.ts• L339-449 modules/…/custom-projection-view.ts• L33-99 modules/…/custom-projection-viewport.ts• L29-40 modules/…/custom-projection-viewport.ts• L42-109 modules/…/custom-projection-viewport.ts• L118-210 modules/…/custom-projection-viewport.ts• L213-288

Redraw scheduling

Deck uses change-driven redraw scheduling. The runtime records a redraw reason, then checks the view, layer, effect, and renderer managers before it draws. _animate changes this policy by requesting a frame on every animation tick. modules/…/deck.ts• L645-677

setProps merges new settings into the current runtime. It resolves views, camera state, dimensions, and event managers before passing the result to each manager. Manager-level redraw flags let a layer, effect, view, or renderer request work without forcing unrelated frames. modules/…/deck.ts• L543-637 modules/…/deck-renderer.ts• L50-70

redraw clears pending flags as part of the draw decision. A caller can force a frame with a reason. A custom render callback can replace the default draw path, but then the callback owns the render work. modules/…/deck.ts• L645-704

References: modules/…/deck.ts• L543-637 modules/…/deck.ts• L645-704 modules/…/deck-renderer.ts• L50-70 modules/…/deck-renderer.ts• L129-135

Frame lifecycle

The animation loop runs one Deck frame handler. The handler updates metrics and cursor state, resolves ready viewports, updates asynchronous layer work, services the latest pointer request, draws when needed, and then advances view transitions. Transition updates occur after the draw so changes raised during a frame are rendered on the next frame. modules/…/deck.ts• L1849-1887

The normal frame order is:

sequenceDiagram
    participant Loop as Animation loop
    participant Deck
    participant Views as View manager
    participant Layers as Layer manager
    participant Picker
    participant Renderer
    participant GPU as Device and canvas

    Loop->>Deck: Start frame
    Deck->>Views: Resolve ready viewports
    Deck->>Layers: Update pending layer work
    Deck->>Picker: Process latest pointer request
    Deck->>Deck: Check redraw reasons
    alt redraw needed
        Deck->>Renderer: Render layers for active viewports
        Renderer->>GPU: Submit draw work
    end
    Deck->>Views: Advance view transitions
    Views-->>Deck: Request later state update when needed

Initialization follows the same ownership order. The device becomes ready first. Deck creates the timeline and input routing, then the view manager, layer manager, effect manager, renderer, picker, and widgets. The view manager starts before the layer manager because layers need an initial viewport. modules/…/deck.ts• L1657-1764

References: modules/…/deck.ts• L1461-1488 modules/…/deck.ts• L1657-1764 modules/…/deck.ts• L1849-1887

Rendering cycle

The default draw cycle combines the current layers, views, viewports, effects, and target into a renderer request. Deck calls the render callbacks around that work and updates widgets after a screen pass. modules/…/deck.ts• L1766-1845

The renderer chooses a draw pass or a picking pass, applies the active layer filter, and sends the resolved request to the layer pass. It skips the viewport work when no viewport is active, while still updating render statistics. modules/…/deck-renderer.ts• L72-127

For one canvas, the renderer writes to the current framebuffer or to the configured framebuffer. For multiple canvases, Deck groups viewports by canvas, matches the offscreen device buffer to each target, renders that group, and presents it. A target with no matching view is still cleared and presented so old pixels do not remain visible. modules/…/deck.ts• L1796-1833

Effects can prepare work before the layer pass and apply post-render work after it. When an effect needs post-processing, the renderer uses reusable intermediate framebuffers sized to the active drawing buffer, then swaps those buffers between effects. modules/…/deck-renderer.ts• L101-121 modules/…/deck-renderer.ts• L154-213

Picking uses the same viewports, layers, effects, and canvas target as rendering. Deck resizes the selected target first, then sends the request to the picker. Pointer movement is coalesced so the frame loop processes only the latest hover request. modules/…/deck.ts• L1067-1167 modules/…/deck.ts• L1565-1639

References: modules/…/deck.ts• L1766-1845 modules/…/deck.ts• L1796-1833 modules/…/deck.ts• L1067-1167 modules/…/deck.ts• L1565-1639 modules/…/deck-renderer.ts• L72-127 modules/…/deck-renderer.ts• L154-213

Resource coordination

Deck gives its managers a shared device, timeline, view state, viewport set, and error path. This shared context lets layer updates, effects, rendering, picking, and input use one frame model instead of separate resource state. modules/…/deck.ts• L1699-1746

The runtime also owns cross-cutting resources for layers and effects. It reports render and pick work through metrics, while callbacks can expose device setup, resize, render boundaries, view changes, loading, and errors. modules/…/deck.ts• L223-260 modules/…/deck.ts• L2020-2049

Finalization stops and destroys the animation loop, finalizes the managers, destroys event and presentation resources, and removes only a canvas that Deck created. This keeps external device and canvas lifetime under application control. modules/…/deck.ts• L495-541

References: modules/…/deck.ts• L223-260 modules/…/deck.ts• L1699-1764 modules/…/deck.ts• L2020-2049 modules/…/deck.ts• L495-541 modules/…/deck-renderer.ts• L137-143

Layer matching, update, and cleanup are described in Layer lifecycle and state. Pointer queries and event handling are described in Interaction and picking. This page is a child of Core rendering engine. Projection-specific camera behavior is described in Custom projections.

References: modules/…/deck.ts• L543-637 modules/…/deck.ts• L762-870 modules/…/deck.ts• L1891-2007

Change checklist

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

  • Changes to view layout or canvas routing must keep viewport selection, controller input, rendering, and picking on the same canvas.
  • Changes to resize handling must preserve the link between each canvas context's CSS size and its drawing buffer.
  • Changes to device replacement or finalization must preserve the ownership boundary for supplied devices and canvases.
  • Changes to redraw flags must account for layer work raised during a frame and view transitions applied after the draw.
  • Changes to multi-canvas presentation must keep target resizing, viewport grouping, clearing, and presentation in the same cycle.
  • Changes to effect passes must preserve the target and intermediate-buffer order for post-render processing.
  • Changes to camera or projection contracts must keep view state, viewport conversion, input, and picking coordinates aligned.

Important failure modes

TriggerConsequenceGuard
A view has no usable sizeIt produces no active viewport and its content is not drawn.Keep the selected canvas layout valid before rendering.
A view is not readyIts viewport is absent until setup completes or a replacement descriptor retries it.Keep the view active and report setup errors through onError.
A secondary canvas changes size without layout invalidationIts viewports use stale dimensions.Invalidate all canvas-specific layouts on any target resize.
A multi-canvas target uses a stale device buffer sizeRendering or picking uses the wrong pixel coordinates.Resize the device buffer to the selected presentation target first.
A redraw flag is cleared outside the draw decisionA visual change can wait for an unrelated later event.Clear flags only while deciding whether to draw.
An effect's intermediate buffers use a stale size or wrong swap orderPost-processing can sample incorrect pixels or render at the wrong size.Resize buffers from the active drawing buffer and swap only the returned buffers.
A supplied device or canvas is treated as Deck-ownedDeck can replace resize behavior or remove an application resource.Preserve external ownership during replacement and finalization.
The WebGL context is lostRendering stops and onError receives a context-loss error.Handle the error and recreate or replace the device.

Key files

FileWhy to read it
modules/…/deck.tsPrimary runtime owner. It connects configuration, devices, canvases, views, managers, frame scheduling, rendering, picking, and cleanup.
modules/…/deck-renderer.tsConnects layer passes and effects to render targets and manages post-render buffers.
modules/…/view-manager.tsExplains how view descriptions become viewports and how view state, layout, canvas routing, and input stay aligned.
modules/…/view.tsDefines the view contract for layout, state, setup, and viewport creation.
modules/…/custom-projection-view.tsShows how a projection-specific view prepares its coordinate system before viewport creation.
modules/…/custom-projection-viewport.tsShows how a resolved custom projection becomes a camera and coordinate transform used by rendering and input.
modules/…/canvas-manager.tsExplains multi-canvas presentation and per-canvas event resources.
modules/…/layer-manager.tsShows how shared layer state becomes redraw work and how layers receive the active viewport.
modules/…/effect-manager.tsShows how effects become the effect set used by the renderer.