From ad79d5bb069e256acff7f47c37329b65e44ca355 Mon Sep 17 00:00:00 2001 From: fuzhenn Date: Tue, 7 Nov 2023 16:20:12 +0800 Subject: [PATCH] update viewport if necessary, fix maptalks/issues#499 --- src/index.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/index.ts b/src/index.ts index b9bd75a..c32c3f9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -88,6 +88,7 @@ const TEMP_POINT = new maptalks.Point(0, 0); const TEMP_VECTOR3 = new THREE.Vector3(); const heightCache = new Map(); const KEY_FBO = '__webglFramebuffer'; +const TEMP_V4 = new THREE.Vector4(); // const MATRIX4 = new THREE.Matrix4(); @@ -1630,6 +1631,11 @@ class ThreeRenderer extends maptalks.renderer.CanvasLayerRenderer { this.context.render(this.scene, this.camera); renderTargetProps[KEY_FBO] = threeCreatedFBO; } else { + const { width, height } = this.canvas; + const viewport = this.context.getViewport(TEMP_V4); + if (viewport.width !== width || viewport.height !== height) { + this.context.setViewport(0, 0, width, height); + } this.context.render(this.scene, this.camera); } this.context.setRenderTarget(null);