Registry / web-framework / regl
library2.1.1jsnpmunverified

regl is a fast, functional WebGL framework that simplifies graphics programming by abstracting the WebGL API into "resources" and "commands." It emphasizes a data-flow approach, minimizing shared state to optimize performance. Instead of direct WebGL calls, developers define declarative commands describing the entire state for a draw call, which regl then compiles into optimized JavaScript. The current stable version is 2.1.1, last published a year ago as of November 2024. regl does not adhere to a strict release cadence, with updates occurring as needed for fixes and features. Its key differentiators include its functional paradigm, automatic state batching for performance, and a minimalistic API compared to raw WebGL, which appeals to users looking for a less verbose and more declarative approach to real-time graphics while maintaining high performance and stability.

npm install regl
INSTALL
IMPORT
SIG · REGL
R
regl
web-frameworkjavascriptv2.1.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

regl
import createREGL from 'regl'; const regl = createREGL();
import { regl } from 'regl'; // Incorrect named import, it's a default export (factory) const regl = require('regl'); // Missing function call to initialize
The default export is a factory function that creates the REGL instance. CommonJS examples often use `require('regl')()` directly.
regl (CommonJS)
const regl = require('regl')();
This is the prevalent usage pattern in older Node.js environments and many `regl` examples.
REGL (TypeScript Type)
import type { REGL, Buffer, Texture } from 'regl';
import { REGL } from 'regl'; // Imports the runtime value, not just the type
regl ships with TypeScript declarations. Use `import type` for type-only imports to avoid bundling issues and ensure correct type checking.

This example initializes a full-screen WebGL context with regl and draws a single animating triangle, demonstrating core concepts like defining commands with shaders, attributes, and uniforms.

const regl = require('regl')(); const drawTriangle = regl({ frag: ` precision mediump float; uniform vec4 color; void main() { gl_FragColor = color; }`, vert: ` precision mediump float; attribute vec2 position; void main() { gl_Position = vec4(position, 0, 1); }`, attributes: { position: regl.buffer([ [-2, -2], [4, -2], [4, 4] ]) }, uniforms: { color: regl.prop('color') }, count: 3 }); regl.frame(({time}) => { regl.clear({ color: [0, 0, 0, 0], depth: 1 }); drawTriangle({ color: [ Math.cos(time * 0.001), Math.sin(time * 0.0008), Math.cos(time * 0.003), 1 ] }); });
Debug
Known issues
gotchaWhen developing with `regl`, especially when using tools like Browserify, runtime error messages and sanity checks are removed by default in production builds to reduce bundle size. This can make debugging difficult in deployed applications.
fix
During development, ensure you compile or bundle with a debug flag (e.g., `--debug` for Browserify) to keep error messages and enable source maps. This helps catch issues faster.
affects: >=1.0.0
gotchaWebGL contexts can be lost by the browser due to various reasons (e.g., system resource constraints, GPU driver updates, switching GPUs). While `regl` includes basic context loss handling since v1.0.0, applications must be prepared to re-initialize all GPU-resident resources (textures, buffers, shaders) on a `webglcontextrestored` event.
fix
Implement a `webglcontextlost` event listener to call `event.preventDefault()` and a `webglcontextrestored` listener to systematically recreate and re-upload all necessary `regl` resources and re-evaluate commands.
affects: >=1.0.0
gotchaWebGL resources (buffers, textures, framebuffers, etc.) consume GPU memory. Failing to explicitly `destroy()` these resources when they are no longer needed can lead to memory leaks, especially in applications that frequently create and destroy dynamic content.
fix
Call the `.destroy()` method on `regl` resources (e.g., `regl.buffer(...).destroy()`, `regl.texture(...).destroy()`) once they are out of scope or no longer actively used, to free up GPU memory. Manage the lifecycle of these objects carefully.
affects: >=1.0.0
breakingIn `regl` versions prior to `0.6.0`, the order of arguments for dynamic functions was `(props, context)`. This was changed to `(context, props)` in `v0.6.0` to align with a more consistent pattern.
fix
If migrating from very old `regl` code or referencing outdated examples, be aware that dynamic functions now expect `(context, props)` as their argument signature. Adjust function definitions accordingly.
affects: >=0.6.0 <1.0.0
Errors
Common errors & fixes
GLSL shader compilation failed: ERROR: 0:1: 'precision' : syntax error
Invalid GLSL syntax or incompatible shader version for the WebGL context.
fix
Review the `frag` and `vert` shader strings for syntax errors, missing semicolons, incorrect variable declarations, or unsupported features. Check WebGL context version compatibility for specific GLSL features.
WebGL context lost. Unable to recover from software mode. Please restart your browser and reload the Viewer.
The browser's WebGL context has been lost, often due to system resource exhaustion, GPU driver issues, or the browser moving the tab to a different GPU process.
fix
Reload the browser tab or restart the browser. For programmatic handling, implement the context loss and restoration listeners described in the warnings.
TypeError: regl is not a function
The `regl` module's default export is a factory function that needs to be called to instantiate the `REGL` object. This error occurs if `require('regl')` or `import createREGL from 'regl'` is used without immediately invoking it.
fix
Ensure you call the imported `regl` factory function, typically as `const regl = require('regl')();` or `import createREGL from 'regl'; const regl = createREGL();`.
Upgrade
Version history
2.1.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
6
Resources
regl — npm install regl · libregistry