@@ -30,13 +30,12 @@ class FontGlyphs(font: Font) {
3030 var y = 0
3131 var rowHeight = 0
3232
33- // Because UTF16 takes 2 bytes per character, we can't use the full range of characters
34- (Char .MIN_VALUE .. <TEXTURE_SIZE .toChar()).forEach { char - >
33+ (Char .MIN_VALUE .. <CHAR_AMOUNT .toChar()).forEach { char - >
3534 val charImage = getCharImage(font, char) ? : return @forEach
3635
37- rowHeight = max(rowHeight, charImage.height)
36+ rowHeight = max(rowHeight, charImage.height + STEP )
3837
39- if (x + charImage.width >= TEXTURE_SIZE ) {
38+ if (x + charImage.width + STEP >= TEXTURE_SIZE ) {
4039 y + = rowHeight
4140 x = 0
4241 rowHeight = 0
@@ -53,7 +52,7 @@ class FontGlyphs(font: Font) {
5352 charMap[char.code] = CharInfo (size, uv1, uv2)
5453 fontHeight = max(fontHeight, size.y)
5554
56- x + = charImage.width
55+ x + = charImage.width + STEP
5756 }
5857
5958 fontTexture = MipmapTexture (image)
@@ -73,13 +72,12 @@ class FontGlyphs(font: Font) {
7372 charMap[char.code]
7473
7574 companion object {
76- // The size cannot be bigger than 2^15 because the rasterizer needs to be fed with dimensions that when multiplied together are less than 2^31
77- // This can be bypassed by using a custom rasterizer, but it's not worth the effort
78- // The size is also limited by the java heap size, as the image is stored in memory
79- // and then uploaded to the GPU
8075 // Since most Lambda users probably have bad pc, the default size is 2048, which includes latin, cyrillic, greek and arabic
8176 // and in the future we could grow the textures when needed
82- private val TEXTURE_SIZE = FontSettings .amountOfGlyphs * 2
83- private val ONE_TEXEL_SIZE = 1.0 / TEXTURE_SIZE
77+ private const val CHAR_AMOUNT = 2048
78+ private const val TEXTURE_SIZE = 4096
79+ private const val ONE_TEXEL_SIZE = 1.0 / TEXTURE_SIZE
80+ // The space between glyphs is necessary to prevent artifacts from appearing when the font texture is blurred
81+ private const val STEP = 2
8482 }
8583}
0 commit comments