| 1 |
## @xterm/addon-webgl |
| 2 |
|
| 3 |
An addon for [xterm.js](https://github.com/xtermjs/xterm.js) that enables a WebGL2-based renderer. This addon requires xterm.js v4+. |
| 4 |
|
| 5 |
### Install |
| 6 |
|
| 7 |
```bash |
| 8 |
npm install --save @xterm/addon-webgl |
| 9 |
``` |
| 10 |
|
| 11 |
### Usage |
| 12 |
|
| 13 |
```ts |
| 14 |
import { Terminal } from '@xterm/xterm'; |
| 15 |
import { WebglAddon } from '@xterm/addon-webgl'; |
| 16 |
|
| 17 |
const terminal = new Terminal(); |
| 18 |
terminal.open(element); |
| 19 |
terminal.loadAddon(new WebglAddon()); |
| 20 |
``` |
| 21 |
|
| 22 |
See the full [API](https://github.com/xtermjs/xterm.js/blob/master/addons/addon-webgl/typings/addon-webgl.d.ts) for more advanced usage. |
| 23 |
|
| 24 |
### Handling Context Loss |
| 25 |
|
| 26 |
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 fired 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: |
| 27 |
|
| 28 |
```ts |
| 29 |
const terminal = new Terminal(); |
| 30 |
const addon = new WebglAddon(); |
| 31 |
addon.onContextLoss(e => { |
| 32 |
addon.dispose(); |
| 33 |
}); |
| 34 |
terminal.loadAddon(addon); |
| 35 |
``` |
| 36 |
|
| 37 |
Read more about handling WebGL context losses on the [Khronos wiki](https://www.khronos.org/webgl/wiki/HandlingContextLost). |