Skip to main content

Class: LayerManager

Defined in: src/layers/LayerManager.ts:18

Owns the composition layers an app adds on top of the scene.

three.js sets layers: [projectionLayer] once when the session starts and never touches that array again, so anything extra has to be composed back in together with its layer. Dropping the projection layer would blank the scene, which is why setBaseLayer is required before anything is added.

Ordering follows the layers spec: earlier entries are composited behind later ones, so the projection layer goes first and app layers sit in front of it.

Constructors​

Constructor​

new LayerManager(): LayerManager

Returns​

LayerManager

Methods​

add()​

add(layer): boolean

Defined in: src/layers/LayerManager.ts:106

Adds a layer in front of the scene.

Parameters​

layer​

XRLayer

Layer to present.

Returns​

boolean

True when it was added and submitted.


getBinding()​

getBinding(): XRWebGLBinding | null

Defined in: src/layers/LayerManager.ts:67

Returns​

XRWebGLBinding | null

The WebGL binding, if the session has one.


getCapability()​

getCapability(): LayerCapability

Defined in: src/layers/LayerManager.ts:86

Returns​

LayerCapability

Which layer path this platform supports.


getContext()​

getContext(): WebGL2RenderingContext | null

Defined in: src/layers/LayerManager.ts:72

Returns​

WebGL2RenderingContext | null

The context layer textures are uploaded through.


getLayers()​

getLayers(): readonly XRLayer[]

Defined in: src/layers/LayerManager.ts:96

Returns​

readonly XRLayer[]

The layers currently composited in front of the scene.


isSupported()​

isSupported(): boolean

Defined in: src/layers/LayerManager.ts:91

Returns​

boolean

True when a layer can actually be presented.


remove()​

remove(layer): boolean

Defined in: src/layers/LayerManager.ts:125

Removes a layer.

Parameters​

layer​

XRLayer

Layer to stop presenting.

Returns​

boolean

True when it was present and removed.


setBaseLayer()​

setBaseLayer(layer): void

Defined in: src/layers/LayerManager.ts:81

Records the layer three.js renders the scene into.

Parameters​

layer​

The projection or WebGL layer backing the scene.

XRLayer | null

Returns​

void


setPreferWebGL()​

setPreferWebGL(prefer): void

Defined in: src/layers/LayerManager.ts:36

Forces the WebGL path on platforms that also offer a media binding.

Quest has both and would otherwise always take the media path, so without this the WebGL path cannot be exercised on the hardware most likely to be to hand.

Parameters​

prefer​

boolean

Whether to take WebGL over media.

Returns​

void


setSession()​

setSession(session, binding, gl): void

Defined in: src/layers/LayerManager.ts:49

Binds the manager to a session.

Parameters​

session​

The active session, or null when one ends.

XRSession | null

binding​

The WebGL binding, if one exists.

XRWebGLBinding | null

gl​

The context the binding was made against. Needed to upload frames into a layer's texture on the WebGL path.

WebGL2RenderingContext | null

Returns​

void