2024-01-27 15:33:04 -05:00

38 lines
1.1 KiB
Markdown

# @luma.gl/webgl
## WebGL Device Adapter
This module contains the WebGL adapter for the "abstract" luma.gl API (`@luma.gl/core`).
Simply importing `@luma.gl/webgl` installs the adapter and enables WebGL devices to
be created using `luma.createDevice(...)`:
```typescript
import {luma} from '@luma.gl/core';
import '@luma.gl/webgl'; // Installs the WebGLDevice adapter
const device = await luma.createDevice({type: 'webgl', canvas: ...});
// Resources can now be created
const buffer = device.createBuffer(...);
```
To use a luma.gl WebGL `Device` with raw WebGL calls, the application needs to access
the `WebGLRenderingContext`. The context is available on the `WebGLDevice` subclass:
```typescript
// @ts-expect-error
const gl = device.gl;
```
With a bit more work, typescript users can retrieve the `WebGLRenderingContext`
without ignoring type errors:
```typescript
import {cast} from '@luma.gl/core';
import {WebGLDevice} from '@luma.gl/webgl'; // Installs the WebGLDevice adapter
const webglDevice = cast<WebGPUDevice>(device);
const gl = webglDevice.gl;
```