@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(...)
:
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:
// @ts-expect-error
const gl = device.gl;
With a bit more work, typescript users can retrieve the WebGLRenderingContext
without ignoring type errors:
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;