This syncs renderer size on map resize and skips render frames when canvas or drawing buffer dimensions are zero to prevent GL_INVALID_FRAMEBUFFER_OPERATION errors. Made-with: Cursor
This commit is contained in:
+18
-1
@@ -168,6 +168,17 @@ async function renderSharedAssetFromQuery() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function createThreeLayer() {
|
function createThreeLayer() {
|
||||||
|
function syncRendererSize(m) {
|
||||||
|
if (!threeRenderer) return;
|
||||||
|
const canvas = m.getCanvas();
|
||||||
|
if (!canvas) return;
|
||||||
|
const width = canvas.clientWidth || canvas.width || 0;
|
||||||
|
const height = canvas.clientHeight || canvas.height || 0;
|
||||||
|
if (width <= 0 || height <= 0) return;
|
||||||
|
threeRenderer.setPixelRatio(window.devicePixelRatio || 1);
|
||||||
|
threeRenderer.setSize(width, height, false);
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: "threejs-custom-layer",
|
id: "threejs-custom-layer",
|
||||||
type: "custom",
|
type: "custom",
|
||||||
@@ -187,14 +198,20 @@ function createThreeLayer() {
|
|||||||
antialias: true,
|
antialias: true,
|
||||||
});
|
});
|
||||||
threeRenderer.autoClear = false;
|
threeRenderer.autoClear = false;
|
||||||
|
syncRendererSize(m);
|
||||||
|
m.on("resize", () => syncRendererSize(m));
|
||||||
},
|
},
|
||||||
render(gl, matrix) {
|
render(gl, matrix) {
|
||||||
|
const canvas = map.getCanvas();
|
||||||
|
if (!canvas || canvas.width <= 0 || canvas.height <= 0 || gl.drawingBufferWidth <= 0 || gl.drawingBufferHeight <= 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
const m = new THREE.Matrix4().fromArray(matrix);
|
const m = new THREE.Matrix4().fromArray(matrix);
|
||||||
threeCamera.projectionMatrix = m;
|
threeCamera.projectionMatrix = m;
|
||||||
|
syncRendererSize(map);
|
||||||
threeRenderer.resetState();
|
threeRenderer.resetState();
|
||||||
threeRenderer.render(threeScene, threeCamera);
|
threeRenderer.render(threeScene, threeCamera);
|
||||||
map.triggerRepaint();
|
map.triggerRepaint();
|
||||||
gl.disable(gl.DEPTH_TEST);
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user