diff --git a/src/image/p5.Image.js b/src/image/p5.Image.js index 1db788cd9c..1eaef608d1 100644 --- a/src/image/p5.Image.js +++ b/src/image/p5.Image.js @@ -2037,4 +2037,12 @@ p5.Image = class { } } }; + +p5.Image.prototype.freeTexture = function () { + if (this._getTexture) { + const tex = this._getTexture(); + if (tex && tex.free) tex.free(); + } +}; + export default p5.Image; diff --git a/src/webgl/p5.Texture.js b/src/webgl/p5.Texture.js index 04b59b487d..bbd91a9edf 100644 --- a/src/webgl/p5.Texture.js +++ b/src/webgl/p5.Texture.js @@ -455,6 +455,15 @@ p5.Texture = class Texture { } }; +// manual cleanup capability +p5.Texture.prototype.free = function () { + if (this.gl && this.glTex) { + this.gl.deleteTexture(this.glTex); + this.glTex = null; + this._isFinalized = false; + } +}; + export class MipmapTexture extends p5.Texture { constructor(renderer, levels, settings) { super(renderer, levels, settings);