From 63e03181abc55bbe5fb2492c140482b5d692bf20 Mon Sep 17 00:00:00 2001 From: Tibor Udvari Date: Thu, 12 Sep 2024 22:47:14 +0200 Subject: [PATCH] fix: background function override --- src/p5xr/core/p5overrides.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/p5xr/core/p5overrides.js b/src/p5xr/core/p5overrides.js index 0d8e4d7..0d4c65f 100644 --- a/src/p5xr/core/p5overrides.js +++ b/src/p5xr/core/p5overrides.js @@ -1,6 +1,22 @@ import { lineVert, lineFrag } from '../shaders/lineShader'; import compareVersions from '../utilities/versionComparator'; +/** + * Override default p5 background to take viewport into account + * Important for stereo rendering + * @ignore + */ +const originalBackground = p5.prototype.background; +p5.prototype.background = function (...args) { + const gl = this._renderer.GL; + const viewport = this._renderer._viewport; + gl.scissor(viewport[0], viewport[1], viewport[2], viewport[3]); + gl.enable(gl.SCISSOR_TEST); + originalBackground.call(this, ...args); + gl.disable(gl.SCISSOR_TEST); + return this; +}; + /** * Override default p5 line shader to avoid issue in v1.10.0 * https://github.com/processing/p5.js/issues/7200