diff --git a/cocos/core/director.js b/cocos/core/director.js index 6c303d9d2b..1893563376 100644 --- a/cocos/core/director.js +++ b/cocos/core/director.js @@ -160,12 +160,6 @@ class Director extends EventTarget { init () { - this._root = new Root(cc.game._gfxDevice); - let rootInfo = {}; - if(!this._root.initialize(rootInfo)) { - return false; - } - this._totalFrames = 0; this._lastUpdate = performance.now(); this._paused = false; @@ -180,6 +174,13 @@ class Director extends EventTarget { } this.sharedInit(); + + this._root = new Root(cc.game._gfxDevice); + let rootInfo = {}; + if(!this._root.initialize(rootInfo)) { + return false; + } + return true; } diff --git a/cocos/core/game.js b/cocos/core/game.js index 0f55fd0a9d..ba86e5c6b4 100644 --- a/cocos/core/game.js +++ b/cocos/core/game.js @@ -699,15 +699,18 @@ class Game extends EventTarget { this._gfxDevice = new cc.WebGLGFXDevice(); } - let nativeWidth = Math.floor(screen.width * cc.view._devicePixelRatio); - let nativeHeight = Math.floor(screen.height * cc.view._devicePixelRatio); - this._gfxDevice.initialize({ + const opts = { canvasElm: localCanvas, debug: true, devicePixelRatio: window.devicePixelRatio, - nativeWidth, - nativeHeight, - }); + nativeWidth: Math.floor(screen.width * cc.view._devicePixelRatio), + nativeHeight: Math.floor(screen.height * cc.view._devicePixelRatio), + }; + // fallback if WebGL2 is actually unavailable + if (!this._gfxDevice.initialize(opts) && useWebGL2) { + this._gfxDevice = new cc.WebGLGFXDevice(); + this._gfxDevice.initialize(opts); + } } if (!this._gfxDevice) {