fix native size error bug when size value is undefined

This commit is contained in:
jerrywwl
2019-04-01 20:28:57 +08:00
parent 0b689adea0
commit 4d5a07ebdf
6 changed files with 35 additions and 41 deletions
+8 -7
View File
File diff suppressed because one or more lines are too long
+20 -31
View File
@@ -665,6 +665,7 @@ class Game extends EventTarget {
}
width = element.clientWidth;
height = element.clientHeight;
this.canvas = localCanvas = document.createElement("CANVAS");
this.container = localContainer = document.createElement("DIV");
element.appendChild(localContainer);
@@ -682,39 +683,27 @@ class Game extends EventTarget {
this._determineRenderType();
// WebGL context created successfully
if (this.renderType === this.RENDER_TYPE_WEBGL) {
var opts = {
'stencil': true,
// MSAA is causing serious performance dropdown on some browsers.
'antialias': cc.macro.ENABLE_WEBGL_ANTIALIAS,
'alpha': cc.macro.ENABLE_TRANSPARENT_CANVAS
};
if (isWeChatGame || isQQPlay) {
opts['preserveDrawingBuffer'] = true;
let useWebGL2 = (window.WebGL2RenderingContext !== null);
const userAgent = navigator.userAgent.toLowerCase();
if (userAgent.indexOf('safari') !== -1) {
if (userAgent.indexOf('chrome') === -1) {
useWebGL2 = false;
}
}
// useWebGL2 = false;
if (useWebGL2) {
this._gfxDevice = new cc.WebGL2GFXDevice();
} else {
this._gfxDevice = new cc.WebGLGFXDevice();
}
{
let useWebGL2 = (window.WebGL2RenderingContext !== null);
const userAgent = navigator.userAgent.toLowerCase();
if (userAgent.indexOf('safari') !== -1) {
if (userAgent.indexOf('chrome') === -1) {
useWebGL2 = false;
}
}
// useWebGL2 = false;
if (useWebGL2) {
this._gfxDevice = new cc.WebGL2GFXDevice();
} else {
this._gfxDevice = new cc.WebGLGFXDevice();
}
this._gfxDevice.initialize({
canvasElm: localCanvas,
debug: true,
nativeWidth: screen.width,
nativeHeight: screen.height,
});
}
this._gfxDevice.initialize({
canvasElm: localCanvas,
debug: true,
nativeWidth: screen.width,
nativeHeight: screen.height,
});
}
if (!this._gfxDevice) {
+4
View File
@@ -214,9 +214,13 @@ class View extends EventTarget {
// Frame size changed, do resize works
var width = view._originalDesignResolutionSize.width;
var height = view._originalDesignResolutionSize.height;
view._resizing = true;
if (width > 0)
view.setDesignResolutionSize(width, height, view._resolutionPolicy);
// cc.director.root.resize(cc.winSize.width, cc.winSize.height);
view._resizing = false;
view.emit('canvas-resize');
+1 -1
View File
@@ -235,7 +235,7 @@ export class WebGLGFXDevice extends GFXDevice {
this._width = this._canvas.width;
this._height = this._canvas.height;
this._nativeWidth = Math.max(info.nativeWidth || this._width, 0);
this._nativeHeight = Math.max(info.nativeHeight || this._width, 0);
this._nativeHeight = Math.max(info.nativeHeight || this._height, 0);
this._colorFmt = GFXFormat.RGBA8;
+1 -1
View File
@@ -165,7 +165,7 @@ export class WebGL2GFXDevice extends GFXDevice {
this._width = this._canvas.width;
this._height = this._canvas.height;
this._nativeWidth = Math.max(info.nativeWidth || this._width, 0);
this._nativeHeight = Math.max(info.nativeHeight || this._width, 0);
this._nativeHeight = Math.max(info.nativeHeight || this._height, 0);
this._colorFmt = GFXFormat.RGBA8;
+1 -1
View File
@@ -33,7 +33,7 @@ export class ToneMapFlow extends RenderFlow {
return true;
}
public destroy (): void {
public destroy () {
if (this._material) {
this._material.destroy();
}