UNPKG

@babylonjs/core

Version:

Getting started? Play directly with the Babylon.js API using our [playground](https://playground.babylonjs.com/). It also contains a lot of samples to learn how to use it.

85 lines 3.44 kB
/** * The kind of underlying native binding an {@link IWebXRGraphicsBinding} wraps. * @internal */ export var WebXRGraphicsBindingType; (function (WebXRGraphicsBindingType) { /** * Backed by an XRWebGLBinding (WebGL / WebGL2). */ WebXRGraphicsBindingType[WebXRGraphicsBindingType["WebGL"] = 0] = "WebGL"; /** * Backed by an XRGPUBinding (WebGPU). */ WebXRGraphicsBindingType[WebXRGraphicsBindingType["WebGPU"] = 1] = "WebGPU"; })(WebXRGraphicsBindingType || (WebXRGraphicsBindingType = {})); /** * WebGL implementation of {@link IWebXRGraphicsBinding}, wrapping an `XRWebGLBinding`. * @internal */ export class WebXRWebGLGraphicsBinding { /** * Creates a new WebGL graphics binding. * @param session the XR session the binding is created for * @param context the WebGL rendering context to bind to */ constructor(session, context) { /** * The kind of native binding that is wrapped. */ this.bindingType = 0 /* WebXRGraphicsBindingType.WebGL */; this.binding = new XRWebGLBinding(session, context); } /** * Creates a new WebGL graphics binding from an engine, extracting its WebGL context. * The WebGL-specific context access is localized here so callers can stay graphics-API-agnostic. * @param session the XR session the binding is created for * @param engine the engine whose WebGL context should be bound * @returns the created WebGL graphics binding */ static CreateFromEngine(session, engine) { const gl = engine._gl; if (!gl) { throw new Error("WebXRWebGLGraphicsBinding requires a WebGL-capable engine."); } return new WebXRWebGLGraphicsBinding(session, gl); } } /** * WebGPU implementation of {@link IWebXRGraphicsBinding}, wrapping an `XRGPUBinding`. * * This is introduced as part of the WebGPU-for-WebXR plumbing and is not consumed yet: * the per-frame layer/sub-image operations are wired up by later phases. The `XRGPUBinding` * requires a WebGPU-compatible XR session (created with the `webgpu` feature descriptor) and a * `GPUDevice` obtained from an `xrCompatible` adapter, otherwise its constructor throws. * @internal */ export class WebXRWebGPUGraphicsBinding { /** * Creates a new WebGPU graphics binding. * @param session the XR session the binding is created for * @param device the WebGPU device to bind to */ constructor(session, device) { /** * The kind of native binding that is wrapped. */ this.bindingType = 1 /* WebXRGraphicsBindingType.WebGPU */; this.binding = new XRGPUBinding(session, device); } /** * Creates a new WebGPU graphics binding from an engine, extracting its `GPUDevice`. * The WebGPU-specific device access is localized here so callers can stay graphics-API-agnostic. * @param session the XR session the binding is created for * @param engine the engine whose WebGPU device should be bound * @returns the created WebGPU graphics binding */ static CreateFromEngine(session, engine) { const device = engine._device; if (!device) { throw new Error("WebXRWebGPUGraphicsBinding requires a WebGPU-capable engine."); } return new WebXRWebGPUGraphicsBinding(session, device); } } //# sourceMappingURL=webXRGraphicsBinding.js.map