Class XRWebGLLayer
- Namespace
- CSharpToJavaScript.APIs.JS
- Assembly
- CSharpToJavaScript.dll
NOTE
ExperimentalXRWebGLLayer 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
Constructors
XRWebGLLayer()
public XRWebGLLayer()
XRWebGLLayer(XRSession, Union235, XRWebGLLayerInit)
NOTE
ExperimentalXRWebGLLayer() constructor creates andreturns 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
sessionXRSessioncontextUnion235layerInitXRWebGLLayerInit
Remarks
-WebXR Device API
-Getting started with WebGL
-Handling lost context in WebGL: Khronos WebGL wiki
Properties
Antialias
NOTE
Experimentalantialias is a Boolean value which is trueif the rendering layer's frame buffer supports anti-aliasing. Otherwise, this
property's value is
false. The specific anti-aliasing technique used is leftto 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
trueif the WebGL rendering layer's frame buffer
is configured to support anti-aliasing. Otherwise, this property isfalse.When the WebXR compositor is enabled, this value corresponds to the value of theantialiasproperty on the object returned by the WebGL context's
WebGLRenderingContext.GetContextAttributes
method.
Remarks
FixedFoveation
NOTE
ExperimentalfixedFoveation 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
fixedFoveationisnulland 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.
Framebuffer
NOTE
Experimentalframebuffer is an opaque WebGLFramebufferwhich 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 astandard 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, ornullif the XR compositor is disabled for the session.
Remarks
FramebufferHeight
NOTE
ExperimentalframebufferHeight indicates the height of theframebuffer, 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.
FramebufferWidth
NOTE
ExperimentalframebufferWidth 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.
IgnoreDepthValues
NOTE
ExperimentalignoreDepthValues is a Boolean value which istrue if the session has been configured to ignore the values in the depthbuffer 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
trueif the WebGL context's depth buffer is being
used while computing the locations of points in the 3D world. Otherwise, if this istrue, 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 isfalse
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
Methods
GetNativeFramebufferScaleFactor(XRSession)
NOTE
ExperimentalXRWebGLLayer.getNativeFramebufferScaleFactor() returns afloating-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
sessionXRSession
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.
GetViewport(XRView)
NOTE
ExperimentalgetViewport() method returns theXRViewport 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
viewXRView
Returns
- XRViewport
A XRViewport object representing the viewport which will restrict
drawing to the portion of the layer corresponding to the specifiedview.