mirror of
https://github.com/visgl/luma.gl.git
synced 2025-12-08 17:36:19 +00:00
@luma.gl/webgl
WebGL Device Adapter
This module contains the WebGL adapter for the "abstract" luma.gl API (@luma.gl/core).
Importing webgl2Adapter from @luma.gl/webgl enables WebGL devices to
be created using luma.createDevice(props). See CreateDeviceProps for WebGL property options.
import {luma} from '@luma.gl/core';
import {webgl2Adapter}'@luma.gl/webgl';
const device = await luma.createDevice({adapters: [webgl2Adapter], createCanvasContext: {width: 800: height: 600}});
// 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 WebGL2RenderingContext. The context is available on the WebGLDevice subclass:
// @ts-expect-error
const gl = device.handle;
With a bit more work, typescript users can retrieve the WebGL2RenderingContext
without ignoring type errors:
import {cast} from '@luma.gl/core';
import {WebGLDevice} from '@luma.gl/webgl'; // Installs the WebGLDevice adapter
const webglDevice = cast<WebGLDevice>(device);
const gl = webglDevice.handle;