question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

xrCompatible attribute is not set for WebXR

See original GitHub issue
xrCompatible 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:closed
  • Created 4 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
Mugen87commented, Oct 22, 2019

I mean, I don’t see ANY of the webvr* examples setting ‘xrCompatible:true’ when WebGLRenderer is created. What am I missing here?

I think we have to distinguish the two cases. When creating WebGLRenderer like so:

var renderer = new THREE.WebGLRenderer();

the renderer will internally create a rendering context with the respective context parameters. The XR examples do not set xrCompatible to true because the renderer does this internally.

However, if you create WebGLRenderer like so:

var renderer = new THREE.WebGLRenderer( { canvas: canvas, context: context } );

you have to set xrCompatible to true 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.

2reactions
tojicommented, Oct 9, 2019

makeXRCompatible() may force a context loss/restore on some devices, so it’s best if you can set the xrCompatible flag during context creation when you’re actually responsible for creating the context.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found