From 677599de35d8fe02a42dfa8a2c245bb69e5e37f3 Mon Sep 17 00:00:00 2001 From: "J.C" Date: Tue, 14 Sep 2021 18:28:59 +0800 Subject: [PATCH] 2 subtle improvements (#9318) * add an optional parameter `out` * no need to create temp function when clear the `targetTexture` --- cocos/core/components/camera-component.ts | 12 +++++------- cocos/core/pipeline/render-pipeline.ts | 4 ++-- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/cocos/core/components/camera-component.ts b/cocos/core/components/camera-component.ts index 4cf8ee7f82..05e9a12757 100644 --- a/cocos/core/components/camera-component.ts +++ b/cocos/core/components/camera-component.ts @@ -580,18 +580,16 @@ export class Camera extends Component { } protected _checkTargetTextureEvent (old: RenderTexture | null) { - const resizeFunc = (window: RenderWindow) => { - if (this._camera) { - this._camera.setFixedSize(window.width, window.height); - } - }; - if (old) { old.off('resize'); } if (this._targetTexture) { - this._targetTexture.on('resize', resizeFunc, this); + this._targetTexture.on('resize', (window: RenderWindow) => { + if (this._camera) { + this._camera.setFixedSize(window.width, window.height); + } + }, this); } } diff --git a/cocos/core/pipeline/render-pipeline.ts b/cocos/core/pipeline/render-pipeline.ts index 9f11672acb..ad24b5497b 100644 --- a/cocos/core/pipeline/render-pipeline.ts +++ b/cocos/core/pipeline/render-pipeline.ts @@ -182,8 +182,8 @@ export abstract class RenderPipeline extends Asset { * @param camera the camera * @returns */ - public generateRenderArea (camera: Camera): Rect { - const res = new Rect(); + public generateRenderArea (camera: Camera, out?: Rect): Rect { + const res = out || new Rect(); const vp = camera.viewport; const sceneData = this.pipelineSceneData; // render area is not oriented