mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-06 19:42:39 +08:00
fix native size error bug when size value is undefined
This commit is contained in:
Vendored
+8
-7
File diff suppressed because one or more lines are too long
+20
-31
@@ -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) {
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ export class ToneMapFlow extends RenderFlow {
|
||||
return true;
|
||||
}
|
||||
|
||||
public destroy (): void {
|
||||
public destroy () {
|
||||
if (this._material) {
|
||||
this._material.destroy();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user