TextureAtlas.beginFrame() returned a consume-once boolean, so after a page merge only the FIRST renderer to draw rebuilt its vertex model. Terminals sharing the atlas via CharAtlasCache kept stale texture-page indexes/coords and drew garbled glyphs on their next partial render (vscode#322756). Replace the flag with a monotonic TextureAtlas.pagesVersion, bumped on page merges and overflow-page creation. Each GlyphRenderer tracks its own last-seen value in beginFrame(), so every terminal sharing the atlas rebuilds its model independently. setAtlas() resets the tracker to force a rebuild when the atlas instance changes. WebglSharedAtlasGarble now passes (was diff ~130/255 vs tolerance 14); full webgl addon suite 74/74 green.
@xterm/addon-webgl
An addon for xterm.js that enables a WebGL2-based renderer. This addon requires xterm.js v4+.
Install
npm install --save @xterm/addon-webgl
Usage
import { Terminal } from '@xterm/xterm';
import { WebglAddon } from '@xterm/addon-webgl';
const terminal = new Terminal();
terminal.open(element);
terminal.loadAddon(new WebglAddon());
See the full API for more advanced usage.
Handling Context Loss
The browser may drop WebGL contexts for various reasons like OOM or after the system has been suspended. There is an API exposed that fires the webglcontextlost event on the canvas so embedders can handle it however they wish. An easy, but suboptimal way, to handle this is by disposing of WebglAddon when the event fires:
const terminal = new Terminal();
const addon = new WebglAddon();
addon.onContextLoss(e => {
addon.dispose();
});
terminal.loadAddon(addon);
Read more about handling WebGL context losses on the Khronos wiki.