npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@canvas-tile-engine/renderer-webgl

v0.7.0

Published

Lightweight library for building interactive 2D grid-based maps and visualizations with WebGL

Downloads

78

Readme

@canvas-tile-engine/renderer-webgl

npm version bundle size license

GPU-accelerated WebGL renderer for Canvas Tile Engine. It implements the same renderer contract as @canvas-tile-engine/renderer-canvas, so most apps switch by changing only the renderer instance.

Use it when your scene has many dynamic primitives and you want batched GPU drawing while keeping the same core engine, config, event callbacks, layers, and draw helpers.

Install

npm install @canvas-tile-engine/core @canvas-tile-engine/renderer-webgl

With React:

npm install @canvas-tile-engine/core @canvas-tile-engine/react @canvas-tile-engine/renderer-webgl

Quick Start

<div id="map">
    <canvas></canvas>
</div>
import { CanvasTileEngine, type CanvasTileEngineConfig } from "@canvas-tile-engine/core";
import { RendererWebGL } from "@canvas-tile-engine/renderer-webgl";

const wrapper = document.getElementById("map") as HTMLDivElement;

const config: CanvasTileEngineConfig = {
    scale: 48,
    size: { width: 800, height: 500 },
    backgroundColor: "#0f172a",
    eventHandlers: { drag: true, zoom: true, hover: true, click: true },
};

const engine = new CanvasTileEngine(wrapper, config, new RendererWebGL(), { x: 0, y: 0 });

engine.drawGridLines(1, 1, "#1e293b", 0);
engine.drawRect({ x: 0, y: 0, size: 1, radius: 4, style: { fillStyle: "#22c55e" } }, 1);
engine.drawCircle({ x: 2, y: 1, size: 0.8, style: { fillStyle: "#38bdf8" } }, 1);
engine.render();

With React

import { CanvasTileEngine, useCanvasTileEngine } from "@canvas-tile-engine/react";
import { RendererWebGL } from "@canvas-tile-engine/renderer-webgl";

export function Map() {
    const engine = useCanvasTileEngine();

    return (
        <CanvasTileEngine engine={engine} config={config} renderer={new RendererWebGL()}>
            <CanvasTileEngine.GridLines cellSize={1} layer={0} />
            <CanvasTileEngine.Rect items={tiles} layer={1} />
        </CanvasTileEngine>
    );
}

How It Works

RendererWebGL creates two stacked canvases inside the wrapper:

| Surface | Draws | | ----------------- | ---------------------------------------------------------------------------- | | WebGL canvas | Rects, circles, images, lines, paths, grid lines, and shape strokes. | | 2D overlay canvas | Text, coordinate overlay, debug HUD, addDrawFunction, and engine.onDraw. |

Geometry is batched by layer. Filled rects, rounded rects, and circles use shader-based rendering; lines and paths are expanded into triangles; images are uploaded as cached GPU textures.

Differences From Canvas2D

  • Text and user custom draw functions live on the upper 2D overlay, so they composite above every WebGL primitive even if their layer number is lower. Ordering within each surface is preserved.
  • drawStaticRect, drawStaticCircle, and drawStaticImage delegate to dynamic drawing. A WebGL layer is already batched, so the Canvas2D offscreen static cache is usually unnecessary.
  • Image sources are uploaded to the GPU and cached. Dimension changes are detected automatically, but if you mutate pixels at the same size, call renderer.invalidateTexture(source).
  • The renderer prefers WebGL 2 and falls back to WebGL 1. If neither is available, init() throws.

Canvas Fallback

import { CanvasTileEngine } from "@canvas-tile-engine/core";
import { RendererCanvas } from "@canvas-tile-engine/renderer-canvas";
import { RendererWebGL } from "@canvas-tile-engine/renderer-webgl";

let engine;

try {
    engine = new CanvasTileEngine(wrapper, config, new RendererWebGL(), center);
} catch {
    engine = new CanvasTileEngine(wrapper, config, new RendererCanvas(), center);
}

Texture Invalidation

const renderer = new RendererWebGL();
const engine = new CanvasTileEngine(wrapper, config, renderer);

// Later, after mutating an image/canvas source without changing dimensions:
renderer.invalidateTexture(source);
engine.render();

Documentation

License

MIT