Skip to content

Commit

Permalink
use gl.deleteTexture(...)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikekucera committed Dec 16, 2024
1 parent 7d4b112 commit 6b94597
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/extensions/renderer/canvas/webgl/atlas.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -452,7 +456,6 @@ export class AtlasManager {
}

_cacheScratchCanvas(opts) {
console.log("cachedScratchFactory", opts);
let prevW = -1;
let prevH = -1;
let scratchCanvas = null;
Expand Down
9 changes: 7 additions & 2 deletions src/extensions/renderer/canvas/webgl/webgl-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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 ];
Expand Down

0 comments on commit 6b94597

Please sign in to comment.