• Creates a graphics device.

    Parameters

    • canvas: HTMLCanvasElement

      The canvas element.

    • options: {
          antialias?: boolean;
          depth?: boolean;
          deviceTypes?: string[];
          glslangUrl?: string;
          powerPreference?: "default" | "high-performance" | "low-power";
          stencil?: boolean;
          twgslUrl?: string;
          xrCompatible?: boolean;
      } = {}

      Graphics device options.

      • Optionalantialias?: boolean

        Boolean that indicates whether or not to perform anti-aliasing if possible. Defaults to true.

      • Optionaldepth?: boolean

        Boolean that indicates that the drawing buffer is requested to have a depth buffer of at least 16 bits. Defaults to true.

      • OptionaldeviceTypes?: string[]

        An array of DEVICETYPE_*** constants, defining the order in which the devices are attempted to get created. Defaults to an empty array. If the specified array does not contain [DEVICETYPE_WEBGL2 or DEVICETYPE_WEBGL1], those are internally added to its end in this order. Typically, you'd only specify DEVICETYPE_WEBGPU, or leave it empty.

      • OptionalglslangUrl?: string

        The URL to the glslang script. Required if the DEVICETYPE_WEBGPU type is added to deviceTypes array. Not used for DEVICETYPE_WEBGL1 or DEVICETYPE_WEBGL2 device type creation.

      • OptionalpowerPreference?: "default" | "high-performance" | "low-power"

        A hint indicating what configuration of GPU would be selected. Possible values are:

        • 'default': Let the user agent decide which GPU configuration is most suitable. This is the default value.
        • 'high-performance': Prioritizes rendering performance over power consumption.
        • 'low-power': Prioritizes power saving over rendering performance.

        Defaults to 'default'.

      • Optionalstencil?: boolean

        Boolean that indicates that the drawing buffer is requested to have a stencil buffer of at least 8 bits. Defaults to true.

      • OptionaltwgslUrl?: string

        An url to twgsl script, required if glslangUrl was specified.

      • OptionalxrCompatible?: boolean

        Boolean that hints to the user agent to use a compatible graphics adapter for an immersive XR device.

    Returns Promise<any>

    • Promise object representing the created graphics device.