Skip to content

Commit

Permalink
fix(troika-three-text): fix SDF texture resizing in Three r136+
Browse files Browse the repository at this point in the history
  • Loading branch information
lojjic committed Mar 6, 2022
1 parent 81f6e1d commit 0fab679
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/troika-three-text/src/TextBuilder.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Color, CanvasTexture, DataTexture, LinearFilter } from 'three'
import { Color, CanvasTexture, LinearFilter } from 'three'
import { defineWorkerModule, ThenableWorkerModule, Thenable } from 'troika-worker-utils'
import { createTypesetter } from './Typesetter.js'
import { generateSDF, warmUpSDFCanvas, resizeWebGLCanvasWithoutClearing } from './SDFGenerator.js'
Expand Down Expand Up @@ -74,7 +74,7 @@ const atlases = Object.create(null)
/**
* @typedef {object} TroikaTextRenderInfo - Format of the result from `getTextRenderInfo`.
* @property {object} parameters - The normalized input arguments to the render call.
* @property {DataTexture} sdfTexture - The SDF atlas texture.
* @property {Texture} sdfTexture - The SDF atlas texture.
* @property {number} sdfGlyphSize - The size of each glyph's SDF; see `configureTextBuilder`.
* @property {number} sdfExponent - The exponent used in encoding the SDF's values; see `configureTextBuilder`.
* @property {Float32Array} glyphBounds - List of [minX, minY, maxX, maxY] quad bounds for each glyph.
Expand Down Expand Up @@ -236,6 +236,8 @@ function getTextRenderInfo(args, callback) {
// Since resizing the canvas clears its render buffer, it needs special handling to copy the old contents over
console.info(`Increasing SDF texture size ${currentHeight}->${neededHeight}`)
resizeWebGLCanvasWithoutClearing(sdfTexture.image, textureWidth, neededHeight)
// As of Three r136 textures cannot be resized, we must recreate it
sdfTexture.dispose()
}

Thenable.all(neededSDFs.map(glyphInfo =>
Expand Down

0 comments on commit 0fab679

Please sign in to comment.