diff --git a/cocos/gfx/webgl/webgl-window.ts b/cocos/gfx/webgl/webgl-window.ts index caba748898..b0e2ce1ce3 100644 --- a/cocos/gfx/webgl/webgl-window.ts +++ b/cocos/gfx/webgl/webgl-window.ts @@ -39,6 +39,8 @@ export class WebGLGFXWindow extends GFXWindow { this._width = info.width; this._height = info.height; + this._nativeWidth = this._width; + this._nativeHeight = this._height; this._colorFmt = info.colorFmt; this._depthStencilFmt = info.depthStencilFmt; @@ -164,5 +166,39 @@ export class WebGLGFXWindow extends GFXWindow { public resize (width: number, height: number) { this._width = width; this._height = height; + if (width > this._nativeWidth || + height > this._nativeHeight) { + this._nativeWidth = width; + this._nativeHeight = height; + + if (this._depthStencilTex) { + this._depthStencilTex.resize(width, height); + this._depthStencilTexView!.destroy(); + this._depthStencilTexView!.initialize({ + texture : this._depthStencilTex, + type : GFXTextureViewType.TV2D, + format : this._depthStencilFmt, + }); + } + + if (this._colorTex) { + this._colorTex.resize(width, height); + this._colorTexView!.destroy(); + this._colorTexView!.initialize({ + texture : this._colorTex, + type : GFXTextureViewType.TV2D, + format : this._colorFmt, + }); + } + + if (this._framebuffer && this._framebuffer.isOffscreen) { + this._framebuffer.destroy(); + this._framebuffer.initialize({ + renderPass: this._renderPass!, + colorViews: [ this._colorTexView! ], + depthStencilView: this._depthStencilTexView!, + }); + } + } } } diff --git a/cocos/gfx/webgl2/webgl2-window.ts b/cocos/gfx/webgl2/webgl2-window.ts index e25285fb31..2296d7cf49 100644 --- a/cocos/gfx/webgl2/webgl2-window.ts +++ b/cocos/gfx/webgl2/webgl2-window.ts @@ -39,6 +39,8 @@ export class WebGL2GFXWindow extends GFXWindow { this._width = info.width; this._height = info.height; + this._nativeWidth = this._width; + this._nativeHeight = this._height; this._colorFmt = info.colorFmt; this._depthStencilFmt = info.depthStencilFmt; @@ -164,5 +166,39 @@ export class WebGL2GFXWindow extends GFXWindow { public resize (width: number, height: number) { this._width = width; this._height = height; + if (width > this._nativeWidth || + height > this._nativeHeight) { + this._nativeWidth = width; + this._nativeHeight = height; + + if (this._depthStencilTex) { + this._depthStencilTex.resize(width, height); + this._depthStencilTexView!.destroy(); + this._depthStencilTexView!.initialize({ + texture : this._depthStencilTex, + type : GFXTextureViewType.TV2D, + format : this._depthStencilFmt, + }); + } + + if (this._colorTex) { + this._colorTex.resize(width, height); + this._colorTexView!.destroy(); + this._colorTexView!.initialize({ + texture : this._colorTex, + type : GFXTextureViewType.TV2D, + format : this._colorFmt, + }); + } + + if (this._framebuffer && this._framebuffer.isOffscreen) { + this._framebuffer.destroy(); + this._framebuffer.initialize({ + renderPass: this._renderPass!, + colorViews: [ this._colorTexView! ], + depthStencilView: this._depthStencilTexView!, + }); + } + } } } diff --git a/cocos/gfx/window.ts b/cocos/gfx/window.ts index 3a18ece46a..bdc865e70a 100644 --- a/cocos/gfx/window.ts +++ b/cocos/gfx/window.ts @@ -56,6 +56,8 @@ export abstract class GFXWindow extends GFXObject { protected _top: number = 0; protected _width: number = 0; protected _height: number = 0; + protected _nativeWidth: number = 0; + protected _nativeHeight: number = 0; protected _colorFmt: GFXFormat = GFXFormat.UNKNOWN; protected _depthStencilFmt: GFXFormat = GFXFormat.UNKNOWN; protected _isOffscreen: boolean = false;