Skip to content

Commit

Permalink
perf: micro-optimization of sdf texture insertion loop
Browse files Browse the repository at this point in the history
  • Loading branch information
lojjic committed Oct 19, 2020
1 parent aed02c4 commit 995c2a6
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/troika-three-text/src/TextBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,13 @@ function getTextRenderInfo(args, callback) {

// Insert the new glyph's data into the full texture image at the correct offsets
const cols = texImg.width / sdfGlyphSize
const baseStartIndex = texImg.width * sdfGlyphSize * Math.floor(atlasIndex / cols) //full rows
+ (atlasIndex % cols) * sdfGlyphSize //partial row
for (let y = 0; y < sdfGlyphSize; y++) {
const srcStartIndex = y * sdfGlyphSize
const tgtStartIndex = texImg.width * sdfGlyphSize * Math.floor(atlasIndex / cols) //full rows
+ (atlasIndex % cols) * sdfGlyphSize //partial row
+ (y * texImg.width) //row within glyph
const rowStartIndex = baseStartIndex + (y * texImg.width)
for (let x = 0; x < sdfGlyphSize; x++) {
texImg.data[tgtStartIndex + x] = textureData[srcStartIndex + x]
texImg.data[rowStartIndex + x] = textureData[srcStartIndex + x]
}
}
})
Expand Down

0 comments on commit 995c2a6

Please sign in to comment.