DeviceCapabilities

View source

Groups browser capability flags used by a Device resource.

A new instance starts with webgpu, webgl, and webAudio set to false. Its canvas flag is initialized from window.CanvasRenderingContext2D. DevicePlugin refreshes the canvas, webgl, and webgpu flags from the current browser environment; webAudio remains application-managed.

Examples

import { Device } from '@wimaengine/device'

const device = new Device()
if (device.capabilities.webgpu) {
  console.log('Use the WebGPU renderer')
}

Constructor


constructor()

Properties


webgpu: boolean

View source

Whether the browser exposes WebGPU support. Defaults to false until DevicePlugin checks the current browser environment.

Default: false

webgl: boolean

View source

Whether the browser exposes WebGL support. Defaults to false until DevicePlugin checks the current browser environment.

Default: false

canvas: boolean

View source

Whether the browser exposes 2D canvas support.

Initialized from window.CanvasRenderingContext2D. DevicePlugin refreshes this flag when it populates the Device resource.

Default: !!window.CanvasRenderingContext2D

webAudio: boolean

View source

Whether the browser exposes WebAudio support.

This flag defaults to false and is not populated by DevicePlugin. Application code may set it before serialization.

Default: false

Methods


staticserialize(value: DeviceCapabilities): DeviceCapabilitiesSerial

View source

Converts capability flags to plain serializable data.

The result contains webgpu, webgl, canvas, and webAudio fields. The source instance is not changed, and the values are copied as-is.

Parameters

NameDescriptionDefault
value

Capabilities to serialize.

—

Returns

The copied capability flags.

staticdeserialize(value: DeviceCapabilitiesSerial, out?: DeviceCapabilities): DeviceCapabilities

View source

Restores capability flags from plain serializable data.

If out is supplied, its object identity is preserved and all four fields are overwritten. Otherwise, a new DeviceCapabilities is returned. The input is expected to contain the four capability fields; this method performs no validation or coercion.

Parameters

NameDescriptionDefault
value

Serialized capability flags.

—
out?

Instance to populate and return.

...

Returns

The populated instance.