Table of Contents

Class XRWebGLLayer

Namespace
CSharpToJavaScript.APIs.JS
Assembly
CSharpToJavaScript.dll
NOTE
Experimental
The XRWebGLLayer interface of the WebXR Device API provides a linkage between the WebXR device (or simulated XR device, in the case of an inline session) and a WebGL context used to render the scene for display on the device. In particular, it provides access to the WebGL framebuffer and viewport to ease access to the context.
[Value("XRWebGLLayer")]
public class XRWebGLLayer : XRLayer
Inheritance
XRWebGLLayer
Inherited Members

Remarks

Although XRWebGLLayer is currently the only type of framebuffer layer supported by WebGL, it's entirely possible that future updates to the WebXR specification may allow for other layer types and corresponding image sources.

-WebXR Device API
-Getting started with WebGL
-'WebGLRenderingContext' and WebGL2RenderingContext
-Drawing a frame in our "Movement and motion" WebXR example

See also on MDN

Constructors

XRWebGLLayer()

public XRWebGLLayer()

XRWebGLLayer(XRSession, Union235, XRWebGLLayerInit)

NOTE
Experimental
The WebXR Device API XRWebGLLayer() constructor creates and
returns a new XRWebGLLayer object, providing the linkage between the
WebXR device and the WebGL graphics layer used to render the 3D scene.
public XRWebGLLayer(XRSession session, Union235 context, XRWebGLLayerInit layerInit = null)

Parameters

session XRSession
context Union235
layerInit XRWebGLLayerInit

Remarks

Properties

Antialias

NOTE
Experimental
The read-only XRWebGLLayer property
antialias is a Boolean value which is true
if the rendering layer's frame buffer supports anti-aliasing. Otherwise, this
property's value is false. The specific anti-aliasing technique used is left
to the user agent discretion and cannot be specified by
the website or web app.
[Value("antialias")]
public bool Antialias { get; }

Property Value

bool

A Boolean value which is true if the WebGL rendering layer's frame buffer
is configured to support anti-aliasing. Otherwise, this property is false.When the WebXR compositor is enabled, this value corresponds to the value of the
antialias property on the object returned by the WebGL context's
WebGLRenderingContext.GetContextAttributes
method.

Remarks

FixedFoveation

NOTE
Experimental
The fixedFoveation property of the XRWebGLLayer interface is a number indicating the amount of foveation used by the XR compositor. Fixed Foveated Rendering (FFR) renders the edges of the eye textures at a lower resolution than the center and reduces the GPU load.
[Value("fixedFoveation")]
public Number? FixedFoveation { get; set; }

Property Value

Number

A number between 0 and 1.It's up to the user agent how to interpret the numbers in this range. When changing the foveation level, the effect will visible in the next XRFrame.Note that some user agents might implement certain levels of foveation, so you might need to adjust the foveation level in large increments to see an effect. Example levels:Some devices don't support foveated rendering. In that case fixedFoveation is null and setting it will not do anything.

Remarks

It is most useful for low contrast textures, such as background images but less for high contrast ones such as text or detailed images. Authors can adjust the level on a per frame basis to achieve the best tradeoff between performance and visual quality.

-Foveated rendering

See also on MDN

Framebuffer

NOTE
Experimental
The read-only XRWebGLLayer property
framebuffer is an opaque WebGLFramebuffer
which is used to buffer the rendered image if the XR compositor is being used. Otherwise, this property's value is
null. The opaque framebuffer is functionally nearly the same as a
standard WebGL framebuffer, except for the differences covered in the section
How opaque framebuffers are special below.
[Value("framebuffer")]
public WebGLFramebuffer? Framebuffer { get; }

Property Value

WebGLFramebuffer

A WebGLFramebuffer object representing the framebuffer into which the 3D
scene is being rendered, or null if the XR compositor is disabled for the session.

Remarks

FramebufferHeight

NOTE
Experimental
The read-only XRWebGLLayer property
framebufferHeight indicates the height of the
framebuffer, in pixels.
[Value("framebufferHeight")]
public ulong FramebufferHeight { get; }

Property Value

ulong

The height in pixels of the XR device's framebuffer. Each of the framebuffer's
attachments (pixel, depth, color, and/or stencil buffers, for example) are all this many
pixels tall.

Remarks

You can get the width of the framebuffer using the
FramebufferWidth property.

-WebXR Device API

See also on MDN

FramebufferWidth

NOTE
Experimental
The read-only XRWebGLLayer property
framebufferWidth specifies the width of the framebuffer,
in pixels.
[Value("framebufferWidth")]
public ulong FramebufferWidth { get; }

Property Value

ulong

The width in pixels of the XR device's framebuffer. Each of the framebuffer's
attachments (pixel, depth, color, and/or stencil buffers, for example) are all this many
pixels wide.

Remarks

You can get the height of the framebuffer using the
FramebufferHeight property.

-WebXR Device API

See also on MDN

IgnoreDepthValues

NOTE
Experimental
The read-only XRWebGLLayer property
ignoreDepthValues is a Boolean value which is
true if the session has been configured to ignore the values in the depth
buffer while rendering the scene. If the depth buffer is being used to determine the
position of vertices, this property is false.
[Value("ignoreDepthValues")]
public bool IgnoreDepthValues { get; }

Property Value

bool

A Boolean value which is true if the WebGL context's depth buffer is being
used while computing the locations of points in the 3D world. Otherwise, if this is
true, the depth buffer's values are being used to assist in placing objects
in the scene. Since the XR compositor uses the depth buffer by default, this value is false
unless explicitly set otherwise when creating the XRWebGLLayer using its
constructor, XRWebGLLayer(XRSession, Union235, XRWebGLLayerInit).

Remarks

The value of ignoreDepthValues can only be set when the
XRWebGLLayer is instantiated, by setting the corresponding value in the constructor's options parameter.

-WebXR Device API
-WebGL depth buffer related methods: WebGLRenderingContext.DepthFunc, WebGLRenderingContext.ClearDepth

See also on MDN

Methods

GetNativeFramebufferScaleFactor(XRSession)

NOTE
Experimental
The static method
XRWebGLLayer.getNativeFramebufferScaleFactor() returns a
floating-point scaling factor by which one can multiply the specified
XRSession's resolution to get the native resolution of the WebXR
device's frame buffer.
[Value("getNativeFramebufferScaleFactor")]
public static Number GetNativeFramebufferScaleFactor(XRSession session)

Parameters

session XRSession

Returns

Number

A floating-point value which, when multiplied by the XRSession's
recommended framebuffer dimensions, results in the XR device's native frame buffer
resolution. If the session has ended, this function returns 0.0.

Remarks

This information can be used when creating a new XRWebGLLayer to configure
the framebufferScaleFactor in the layerInit configuration object
specified when calling the XRWebGLLayer() constructor. See the
Usage notes and Examples for details.

If the scaling factor is 1.0, then the frame buffer pixels and the native display
pixels are the same size. If the scaling factor is greater than zero, then the frame
buffer is smaller than the display's native dimensions, resulting in the output being
up-scaled for display to the screen after rendering into the frame buffer. If the
scaling factor is less than zero, the frame buffer is larger than the native
resolution of the display, resulting in the frame buffer's contents being scaled down
for display to the XR device. This can happen for display environments which use
superscaling or anti-aliasing techniques to improve perceived image quality.

-WebXR Device API
-WebXR performance guide

See also on MDN

GetViewport(XRView)

NOTE
Experimental
The XRWebGLLayer interface's
getViewport() method returns the
XRViewport that should be used to render the specified
XRView into the WebGL layer. For WebXR devices which use a
single framebuffer for both the left and right eyes, the returned viewport represents
the region of the framebuffer into which the scene should be rendered for the eye
represented by the view.
[Value("getViewport")]
public XRViewport? GetViewport(XRView view)

Parameters

view XRView

Returns

XRViewport

A XRViewport object representing the viewport which will restrict
drawing to the portion of the layer corresponding to the specified view.

Remarks