From 21d2e16584d257a66de871ce1ce58d4e2ddf273d Mon Sep 17 00:00:00 2001 From: Karim Naaji Date: Fri, 24 Jan 2020 12:11:37 -0500 Subject: [PATCH] Reduce size of line atlas by removing unused channels Saves roughly ~100kb of uncompressed gpu memory, potentially saving texture fetches in the shader --- src/render/line_atlas.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/render/line_atlas.js b/src/render/line_atlas.js index d3208e9bac4..2f5c857f3b2 100644 --- a/src/render/line_atlas.js +++ b/src/render/line_atlas.js @@ -28,8 +28,7 @@ class LineAtlas { this.height = height; this.nextRow = 0; - this.bytes = 4; - this.data = new Uint8Array(this.width * this.height * this.bytes); + this.data = new Uint8Array(this.width * this.height); this.positions = {}; } @@ -114,7 +113,7 @@ class LineAtlas { signedDistance = (inside ? 1 : -1) * dist; } - this.data[3 + (index + x) * 4] = Math.max(0, Math.min(255, signedDistance + offset)); + this.data[index + x] = Math.max(0, Math.min(255, signedDistance + offset)); } } @@ -139,14 +138,14 @@ class LineAtlas { gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR); - gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, this.width, this.height, 0, gl.RGBA, gl.UNSIGNED_BYTE, this.data); + gl.texImage2D(gl.TEXTURE_2D, 0, gl.ALPHA, this.width, this.height, 0, gl.ALPHA, gl.UNSIGNED_BYTE, this.data); } else { gl.bindTexture(gl.TEXTURE_2D, this.texture); if (this.dirty) { this.dirty = false; - gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, this.width, this.height, gl.RGBA, gl.UNSIGNED_BYTE, this.data); + gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, this.width, this.height, gl.ALPHA, gl.UNSIGNED_BYTE, this.data); } } }