File tree Expand file tree Collapse file tree 2 files changed +12
-1
lines changed Expand file tree Collapse file tree 2 files changed +12
-1
lines changed Original file line number Diff line number Diff line change 1- /* global Promise, screen */
1+ /* global Promise, screen, CustomEvent */
22var initMetaTags = require ( './metaTags' ) . inject ;
33var initWakelock = require ( './wakelock' ) ;
44var loadingScreen = require ( './loadingScreen' ) ;
@@ -309,6 +309,14 @@ module.exports.AScene = registerElement('a-scene', {
309309
310310 // Callback that happens on enter VR success or enter fullscreen (any API).
311311 function enterVRSuccess ( ) {
312+ // vrdisplaypresentchange fires only once when the first requestPresent is completed;
313+ // the first requestPresent could be called from ondisplayactivate and there is no way
314+ // to setup everything from there. Thus, we need to emulate another vrdisplaypresentchange
315+ // for the actual requestPresent. Need to make sure there are no issues with firing the
316+ // vrdisplaypresentchange multiple times.
317+ var event = new CustomEvent ( 'vrdisplaypresentchange' , { detail : { display : utils . device . getVRDisplay ( ) } } ) ;
318+ window . dispatchEvent ( event ) ;
319+
312320 self . addState ( 'vr-mode' ) ;
313321 self . emit ( 'enter-vr' , { target : self } ) ;
314322 // Lock to landscape orientation on mobile.
Original file line number Diff line number Diff line change @@ -9,6 +9,9 @@ window.addEventListener('vrdisplayactivate', function (evt) {
99 if ( navigator . xr ) { return ; }
1010 canvasEl = document . createElement ( 'canvas' ) ;
1111 vrDisplay = evt . display ;
12+ // We need to make sure the canvas has a WebGL context associated with it.
13+ // Otherwise, the requestPresent could be denied.
14+ canvasEl . getContext ( 'webgl' , { } ) ;
1215 // Request present immediately. a-scene will be allowed to enter VR without user gesture.
1316 vrDisplay . requestPresent ( [ { source : canvasEl } ] ) . then ( function ( ) { } , function ( ) { } ) ;
1417} ) ;
You can’t perform that action at this time.
0 commit comments