From 04f79aa7b4bcf99bf20258e2e2f9d95a278354d8 Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Sat, 29 Oct 2022 14:33:50 -0700 Subject: [PATCH] Share page texture binding code --- addons/xterm-addon-webgl/src/GlyphRenderer.ts | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/addons/xterm-addon-webgl/src/GlyphRenderer.ts b/addons/xterm-addon-webgl/src/GlyphRenderer.ts index f33aad4b..35b6770c 100644 --- a/addons/xterm-addon-webgl/src/GlyphRenderer.ts +++ b/addons/xterm-addon-webgl/src/GlyphRenderer.ts @@ -108,7 +108,7 @@ export class GlyphRenderer extends Disposable { private _atlas: ITextureAtlas | undefined; private _activeBuffer: number = 0; - private _vertices: IVertices = { + private readonly _vertices: IVertices = { count: 0, attributes: new Float32Array(0), attributesBuffers: [ @@ -346,10 +346,7 @@ export class GlyphRenderer extends Disposable { for (let i = 0; i < this._atlas.pages.length; i++) { if (this._atlas.pages[i].hasCanvasChanged) { this._atlas.pages[i].hasCanvasChanged = false; - gl.activeTexture(gl.TEXTURE0 + i); - gl.bindTexture(gl.TEXTURE_2D, this._atlasTextures[i]); - gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, this._atlas.pages[i].canvas); - gl.generateMipmap(gl.TEXTURE_2D); + this._bindAtlasPageTexture(gl, this._atlas, i); } } @@ -363,15 +360,19 @@ export class GlyphRenderer extends Disposable { // TODO: Share code for (let i = 0; i < this._atlas.pages.length; i++) { - gl.activeTexture(gl.TEXTURE0 + i); - gl.bindTexture(gl.TEXTURE_2D, this._atlasTextures[i]); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); - gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, this._atlas.pages[i].canvas); - gl.generateMipmap(gl.TEXTURE_2D); + this._bindAtlasPageTexture(gl, atlas, i); } } + private _bindAtlasPageTexture(gl: IWebGL2RenderingContext, atlas: ITextureAtlas, i: number): void { + gl.activeTexture(gl.TEXTURE0 + i); + gl.bindTexture(gl.TEXTURE_2D, this._atlasTextures[i]); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); + gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, atlas.pages[i].canvas); + gl.generateMipmap(gl.TEXTURE_2D); + } + public setDimensions(dimensions: IRenderDimensions): void { this._dimensions = dimensions; }