xrCompatible attribute is not set for WebXR
See original GitHub issuexrCompatible GL context attribute is not set for WebXR
There is an attempt to set it in WebGLRenderer.js:
var contextAttributes = {
alpha: _alpha,
depth: _depth,
stencil: _stencil,
antialias: _antialias,
premultipliedAlpha: _premultipliedAlpha,
preserveDrawingBuffer: _preserveDrawingBuffer,
powerPreference: _powerPreference,
failIfMajorPerformanceCaveat: _failIfMajorPerformanceCaveat,
xrCompatible: true
};
// event listeners must be registered before WebGL context is created, see #12753
_canvas.addEventListener( 'webglcontextlost', onContextLost, false );
_canvas.addEventListener( 'webglcontextrestored', onContextRestore, false );
_gl = _context || _canvas.getContext( 'webgl', contextAttributes ) || _canvas.getContext( 'experimental-webgl', contextAttributes );
HOWEVER, this ‘contextAttributes’ got completely ignored, since it gets here with the _context not null, and therefore the attribute is not set.
Instead of setting the attribute the context at creation time, you can make the context “XR compatible” by calling a makeXRCompatible method in WebXRManager.js, right before creation of the WebGLLayer:
if ( gl.makeXRCompatible !== undefined ) {
gl.makeXRCompatible();
}
// eslint-disable-next-line no-undef
session.updateRenderState( { baseLayer: new XRWebGLLayer( session, gl ) } );
Three.js version
- [x ] Dev
- [x ] r109
- …
Browser
- All of them
- Chrome
- Firefox
- Internet Explorer
OS
- All of them
- Windows
- macOS
- Linux
- Android
- iOS
Hardware Requirements (graphics card, VR Device, …)
Issue Analytics
- State:
- Created 4 years ago
- Comments:10 (5 by maintainers)
Top Results From Across the Web
WebGLRenderingContext.makeXRCompatible() - Web APIs
xr property exists), we use requestSession() to request a new WebXR session and set the usingXR flag to true . If the other...
Read more >WebXR Device API - W3C
The user agent has a list of immersive XR devices (a list of XR device), which MUST be initially an empty list.
Read more >WebXR Device API Explained - Immersive Web
A XRWebGLLayer created with an inline session will not allocate a new WebGL framebuffer but instead set the framebuffer attribute to null ....
Read more >WebXR render canvas and streaming - Questions - Babylon.js
WebXR is not using the canvas directly to render the data to the device, ... Once the canvas is marked as XR compatible,...
Read more >Starting up and shutting down a WebXR session - Web APIs
The value of xr will be null or undefined if WebXR isn't available. ... Either way, you need to be prepared for the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think we have to distinguish the two cases. When creating
WebGLRenderer
like so:the renderer will internally create a rendering context with the respective context parameters. The XR examples do not set
xrCompatible
totrue
because the renderer does this internally.However, if you create
WebGLRenderer
like so:you have to set
xrCompatible
totrue
on application level when creating the rendering context. In this case the internal context attributes get ignored since the context from the constructor parameter is used. This happens when using WebGL 2 like Mozilla Hubs does.I hope this makes it more clear now.
makeXRCompatible()
may force a context loss/restore on some devices, so it’s best if you can set thexrCompatible
flag during context creation when you’re actually responsible for creating the context.