# pex-gl

> Create a RenderingContext (2d, webgl, webgl2, webgpu) for use in PEX.

Latest version **3.0.2** (published 2024-07-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install pex-gl
pnpm add pex-gl
yarn add pex-gl
bun add pex-gl
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.2 |
| Published | 2024-07-09 |
| First published | 2016-10-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=22.0.0 |
| Dependencies | 0 |
| Unpacked size | 13.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 15 |
| Author | Marcin Ignac |
| Maintainers | vorg, dmnsgn |
| Keywords | pex, gl, webgl, 3d, canvas, context, 2d, experimental-webgl, bitmaprenderer, webgl2, webgpu |

## Links

- npm: https://www.npmjs.com/package/pex-gl
- Repository: https://github.com/pex-gl/pex-gl
- Issues: https://github.com/pex-gl/pex-gl/issues
- npm.io page: https://npm.io/package/pex-gl

## Alternatives

- [exif-parser](https://npm.io/package/exif-parser.md) — 3.8M weekly downloads
- [vite-plugin-compression](https://npm.io/package/vite-plugin-compression.md) — 569.5K weekly downloads
- [pica](https://npm.io/package/pica.md) — 442.4K weekly downloads
- [@reportportal/client-javascript](https://npm.io/package/@reportportal/client-javascript.md) — 408.8K weekly downloads
- [@tldraw/state](https://npm.io/package/@tldraw/state.md) — 316.0K weekly downloads

## Recent versions

- 3.0.2 (latest) — 2024-07-09
- 3.0.0-alpha.0 (alpha) — 2022-06-06
- 3.0.1 — 2023-08-14
- 3.0.0 — 2023-05-10
- 2.7.0 — 2018-12-19
- 2.6.2 — 2018-05-29
- 2.6.1 — 2018-03-22
- 2.6.0 — 2018-03-21
- 2.5.0 — 2018-01-16
- 2.4.1 — 2017-04-26
- 2.4.0 — 2017-04-15
- 2.3.0 — 2017-04-13
- 2.2.0 — 2017-04-05
- 2.1.0 — 2017-03-27
- 2.0.1 — 2017-03-15
- … 13 more at https://npm.io/package/pex-gl/versions

## README

# pex-gl

[![npm version](https://img.shields.io/npm/v/pex-gl)](https://www.npmjs.com/package/pex-gl)
[![stability-stable](https://img.shields.io/badge/stability-stable-green.svg)](https://www.npmjs.com/package/pex-gl)
[![npm minzipped size](https://img.shields.io/bundlephobia/minzip/pex-gl)](https://bundlephobia.com/package/pex-gl)
[![dependencies](https://img.shields.io/librariesio/release/npm/pex-gl)](https://github.com/pex-gl/pex-gl/blob/main/package.json)
[![types](https://img.shields.io/npm/types/pex-gl)](https://github.com/microsoft/TypeScript)
[![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-fa6673.svg)](https://conventionalcommits.org)
[![styled with prettier](https://img.shields.io/badge/styled_with-Prettier-f8bc45.svg?logo=prettier)](https://github.com/prettier/prettier)
[![linted with eslint](https://img.shields.io/badge/linted_with-ES_Lint-4B32C3.svg?logo=eslint)](https://github.com/eslint/eslint)
[![license](https://img.shields.io/github/license/pex-gl/pex-gl)](https://github.com/pex-gl/pex-gl/blob/main/LICENSE.md)

Create a RenderingContext (2d, webgl, webgl2, bitmaprenderer, webgpu) for use in [PEX](https://pex.gl).

## Installation

```bash
npm install pex-gl
```

## Usage

```js
import createRenderingContext, { FALLBACKS } from "pex-gl";

// Creates a webgl context filling the window
const context = createRenderingContext();

// Creates a webgl context from an existing canvas and keeps its size
const context = createRenderingContext({ canvas });

// Creates a webgl context on a new canvas with given width and height
const context = createRenderingContext({ width, height });

// Creates a new canvas of type "webgpu"
const context = createRenderingContext({ type: "webgpu" });

// Creates a new canvas of type "webgl" or fallback to experimental-webgl in case it fails
const context = createRenderingContext({ type: "webgl" });

// Disable fallbacks for "webgl2"
FALLBACKS.webgl2 = [];
// Creates a new canvas of type "webgl2" and return null in case it fails
const context = createRenderingContext({ type: "webgl2" });
```

## API

<!-- api-start -->

## Modules

<dl>
<dt><a href="#module_pex-gl">pex-gl</a></dt>
<dd></dd>
</dl>

## Typedefs

<dl>
<dt><a href="#PexGLOptions">PexGLOptions</a> : <code>object</code></dt>
<dd><p>Options for context creation. All optional.</p>
</dd>
</dl>

<a name="module_pex-gl"></a>

## pex-gl

- [pex-gl](#module_pex-gl)
  - [.FALLBACKS](#module_pex-gl.FALLBACKS)
  - [.default([opts])](#module_pex-gl.default) ⇒ <code>RenderingContext</code>

<a name="module_pex-gl.FALLBACKS"></a>

### pex-gl.FALLBACKS

Context fallbacks map

**Kind**: static constant of [<code>pex-gl</code>](#module_pex-gl)
<a name="module_pex-gl.default"></a>

### pex-gl.default([opts]) ⇒ <code>RenderingContext</code>

Creates a rendering context.

**Kind**: static method of [<code>pex-gl</code>](#module_pex-gl)

| Param  | Type                                       | Default         |
| ------ | ------------------------------------------ | --------------- |
| [opts] | [<code>PexGLOptions</code>](#PexGLOptions) | <code>{}</code> |

<a name="PexGLOptions"></a>

## PexGLOptions : <code>object</code>

Options for context creation. All optional.

**Kind**: global typedef
**Properties**

| Name                   | Type                                                                                                                                                                           | Default                                          | Description                                    |
| ---------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------ | ---------------------------------------------- |
| [width]                | <code>number</code>                                                                                                                                                            | <code>window.innerWidth</code>                   | Request an initial canvas width.               |
| [height]               | <code>number</code>                                                                                                                                                            | <code>window.innerHeight</code>                  | Request an initial canvas height.              |
| [pixelRatio]           | <code>boolean</code>                                                                                                                                                           | <code>1</code>                                   | Multiply canvas dimensions with a given ratio. |
| [fullscreen]           | <code>boolean</code>                                                                                                                                                           | <code>!opts.width &amp;&amp; !opts.height</code> | Make the canvas fullscreen.                    |
| [type]                 | <code>&quot;2d&quot;</code> \| <code>&quot;bitmaprenderer&quot;</code> \| <code>&quot;webgl&quot;</code> \| <code>&quot;webgl2&quot;</code> \| <code>&quot;webgpu&quot;</code> | <code>&quot;webgl&quot;</code>                   | A "contextType" for getContext.                |
| [element]              | <code>HTMLElement</code>                                                                                                                                                       | <code>document.body</code>                       | Element to append the canvas to.               |
| [...contextAttributes] | <code>CanvasRenderingContext2DSettings</code> \| <code>WebGLContextAttributes</code>                                                                                           | <code>{}</code>                                  | Attributes to be passed to getContext.         |

<!-- api-end -->

## License

MIT. See [license file](https://github.com/pex-gl/pex-gl/blob/main/LICENSE.md).

---
_Source: https://npm.io/package/pex-gl · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
