From 6b94597e5210af57688795b589a60d00c2c5a9ed Mon Sep 17 00:00:00 2001 From: Mike Kucera Date: Mon, 16 Dec 2024 10:57:33 -0500 Subject: [PATCH] use gl.deleteTexture(...) --- src/extensions/renderer/canvas/webgl/atlas.js | 7 +++++-- src/extensions/renderer/canvas/webgl/webgl-util.js | 9 +++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/extensions/renderer/canvas/webgl/atlas.js b/src/extensions/renderer/canvas/webgl/atlas.js index c2eaa3238..85e13ee8b 100644 --- a/src/extensions/renderer/canvas/webgl/atlas.js +++ b/src/extensions/renderer/canvas/webgl/atlas.js @@ -198,7 +198,11 @@ export class Atlas { bufferIfNeeded(gl) { if(!this.buffered) { - this.texture = util.bufferTexture(gl, this.canvas); + if(this.texture) { + this.texture.deleteTexture(); + this.texture = null; + } + this.texture = util.bufferTexture(gl, this.canvas, this.debugID); this.buffered = true; } } @@ -452,7 +456,6 @@ export class AtlasManager { } _cacheScratchCanvas(opts) { - console.log("cachedScratchFactory", opts); let prevW = -1; let prevH = -1; let scratchCanvas = null; diff --git a/src/extensions/renderer/canvas/webgl/webgl-util.js b/src/extensions/renderer/canvas/webgl/webgl-util.js index 2c6fe9556..193a8e19d 100644 --- a/src/extensions/renderer/canvas/webgl/webgl-util.js +++ b/src/extensions/renderer/canvas/webgl/webgl-util.js @@ -113,8 +113,7 @@ export function vec4ToIndex(vec4) { ); } - -export function bufferTexture(gl, textureCanvas) { +export function bufferTexture(gl, textureCanvas, debugID) { const texture = gl.createTexture(); gl.bindTexture(gl.TEXTURE_2D, texture); @@ -130,9 +129,15 @@ export function bufferTexture(gl, textureCanvas) { gl.generateMipmap(gl.TEXTURE_2D); gl.bindTexture(gl.TEXTURE_2D, null); + + texture.deleteTexture = () => { + gl.deleteTexture(texture); + }; + return texture; } + function getTypeInfo(gl, glslType) { switch(glslType) { case 'float': return [ 1, gl.FLOAT, 4 ];