- Add -dwfont option to specify the name of the double-width font. The default setting '18x18ja' matches the default main font '9x18', otherwise a font with matching geometry must be specified. - If the double-width font is not present or cannot be loaded (e.g., because its geometry does not match the main font), double-width characters will obviously not appear on screen, but spacing will still be correct and copy-pasting them will still work (as we have the unicode points, we just cannot render them). - Unicode display correctness has marginally improved in a few cases: U+0080 was drawn as a missing glyph (hinting the user that a better font would perhaps make it visible), whereas it is really a control character with no valid visual, hence the Unicode Replacement Char should be shown. The opposite change happened to U+10000 which is in fact a valid (if uncommon) character, but was rendered as RC. U+D7FF is now also correctly shown as a RC (as it belongs to a reserved range). Finally, the same correction was applied to the non-characters in the range U+FDD0..U+FDEF. - As a bonus, the Fontpack now releases all fonts from host memory (previously held for the rest of the program's life) once all font data is loaded into GL. This frees several megabytes of host RAM (the issue became more pronounced with CJK fonts having tens of thousands of glyphs).
Showing the changes to src/charvdev.cc (1 of 22 files). Show all
Unified · Split
| @@ -25,6 +25,8 @@ layout (local_size_x = 1, local_size_y = 1) in; · 24 unmodified lines | |||
| 25 | layout (rgba32f, binding = 0) writeonly lowp uniform image2D imgOut; | 25 | layout (rgba32f, binding = 0) writeonly lowp uniform image2D imgOut; |
| 26 | layout (binding = 1) uniform lowp sampler2DArray atlas; | 26 | layout (binding = 1) uniform lowp sampler2DArray atlas; |
| 27 | layout (binding = 2) uniform lowp sampler2D atlasMap; | 27 | layout (binding = 2) uniform lowp sampler2D atlasMap; |
| 28 | layout (binding = 3) uniform lowp sampler2DArray atlas_dw; | ||
| 29 | layout (binding = 4) uniform lowp sampler2D atlasMap_dw; | ||
| 28 | uniform lowp ivec2 glyphPixels; | 30 | uniform lowp ivec2 glyphPixels; |
| 29 | uniform lowp ivec2 sizeChars; | 31 | uniform lowp ivec2 sizeChars; |
| 30 | uniform lowp ivec3 cursorColor; | 32 | uniform lowp ivec3 cursorColor; |
| @@ -35,6 +37,7 @@ uniform lowp int selectRectMode; · 4 unmodified lines | |||
| 35 | uniform highp ivec2 selectDamage; | 37 | uniform highp ivec2 selectDamage; |
| 36 | uniform lowp int deltaFrame; | 38 | uniform lowp int deltaFrame; |
| 37 | uniform lowp int showWraps; | 39 | uniform lowp int showWraps; |
| 40 | uniform lowp int hasDoubleWidth; | ||
| 38 | 41 | ||
| 39 | struct Cell | 42 | struct Cell |
| 40 | { | 43 | { |
| @@ -56,25 +59,42 @@ void main () · 15 unmodified lines | |||
| 56 | 59 | ||
| 57 | if (deltaFrame == 1) | 60 | if (deltaFrame == 1) |
| 58 | { | 61 | { |
| 59 | uint dirty = bitfieldExtract (cell.charData, 21, 1); | 62 | uint dirty = bitfieldExtract (cell.charData, 23, 1); |
| 60 | if (dirty == 0u && | 63 | if (dirty == 0u && |
| 61 | charPos != cursorPos.xy && charPos != cursorPos.zw && | 64 | charPos != cursorPos.xy && charPos != cursorPos.zw && |
| 62 | (idx < selectDamage.x || idx >= selectDamage.y)) | 65 | (idx < selectDamage.x || idx >= selectDamage.y)) |
| 63 | return; | 66 | return; |
| 64 | } | 67 | } |
| 65 | vmem.cells[idx].charData = bitfieldInsert (cell.charData, 0u, 21, 1); | 68 | vmem.cells[idx].charData = bitfieldInsert (cell.charData, 0u, 23, 1); |
| 66 | 69 | ||
| 67 | ivec2 charCode = | 70 | ivec2 charCode = |
| 68 | ivec2 (bitfieldExtract (cell.charData, 0, 8), // Lowest byte | 71 | ivec2 (bitfieldExtract (cell.charData, 0, 8), // Lowest byte |
| 69 | bitfieldExtract (cell.charData, 8, 8)); // Next-lowest byte | 72 | bitfieldExtract (cell.charData, 8, 8)); // Next-lowest byte |
| 70 | 73 | ||
| 71 | // fontIdx == 0 -> Normal; 1 -> Bold; 2 -> Italic; 3 -> BoldItalic | 74 | uint dwidth = bitfieldExtract (cell.charData, 16, 1); |
| 72 | uint fontIdx = bitfieldExtract (cell.charData, 16, 2); | 75 | uint dwidth_cont = bitfieldExtract (cell.charData, 17, 1); |
| 73 | uint underline = bitfieldExtract (cell.charData, 18, 1); | 76 | if (dwidth_cont == 1u) // double-width cell continuation - drawn by left half |
| 74 | uint inverse = bitfieldExtract (cell.charData, 19, 1); | 77 | return; |
| 75 | uint wrap = bitfieldExtract (cell.charData, 20, 1); | ||
| 76 | 78 | ||
| 77 | ivec2 atlasPos = ivec2 (vec2 (256) * texelFetch (atlasMap, charCode, 0).zw); | 79 | if (dwidth == 1u && charPos.x < sizeChars.x - 1) |
| 80 | { | ||
| 81 | // check validity (dwidth_cont marker in the cell to the right) | ||
| 82 | if (bitfieldExtract (vmem.cells[idx + 1].charData, 17, 1) != 1u) | ||
| 83 | dwidth = 0u; | ||
| 84 | } | ||
| 85 | |||
| 86 | uint fontIdx = 0u; // 0 -> Normal; 1 -> Bold; 2 -> Italic; 3 -> BoldItalic | ||
| 87 | if (dwidth == 0u) | ||
| 88 | fontIdx = bitfieldExtract (cell.charData, 18, 2); | ||
| 89 | uint underline = bitfieldExtract (cell.charData, 20, 1); | ||
| 90 | uint inverse = bitfieldExtract (cell.charData, 21, 1); | ||
| 91 | uint wrap = bitfieldExtract (cell.charData, 22, 1); | ||
| 92 | |||
| 93 | ivec2 atlasPos; | ||
| 94 | if (dwidth == 0u) | ||
| 95 | atlasPos = ivec2 (vec2 (256) * texelFetch (atlasMap, charCode, 0).zw); | ||
| 96 | else | ||
| 97 | atlasPos = ivec2 (vec2 (256) * texelFetch (atlasMap_dw, charCode, 0).zw); | ||
| 78 | 98 | ||
| 79 | vec3 fgColor = vec3 (float (bitfieldExtract (cell.fg, 0, 8)), | 99 | vec3 fgColor = vec3 (float (bitfieldExtract (cell.fg, 0, 8)), |
| 80 | float (bitfieldExtract (cell.fg, 8, 8)), | 100 | float (bitfieldExtract (cell.fg, 8, 8)), |
| @@ -115,25 +135,66 @@ void main () · 34 unmodified lines | |||
| 115 | bgColor = crColor; | 135 | bgColor = crColor; |
| 116 | } | 136 | } |
| 117 | 137 | ||
| 118 | for (int j = 0; j < glyphPixels.x; j++) | 138 | ivec2 srcGlyphPixels = glyphPixels; |
| 119 | { | 139 | if (dwidth == 1u) |
| 120 | for (int k = 0; k < glyphPixels.y; k++) | 140 | srcGlyphPixels = ivec2 (2, 1) * glyphPixels; |
| 141 | |||
| 142 | if (dwidth == 0u) | ||
| 143 | { // render regular cell | ||
| 144 | for (int j = 0; j < glyphPixels.x; j++) | ||
| 121 | { | 145 | { |
| 122 | ivec2 txCoords = atlasPos * glyphPixels + ivec2 (j, k); | 146 | for (int k = 0; k < glyphPixels.y; k++) |
| 123 | ivec3 txc = ivec3 (txCoords, fontIdx); | 147 | { |
| 124 | float lumi = texelFetch (atlas, txc, 0).r; | 148 | ivec2 txCoords = atlasPos * srcGlyphPixels + ivec2 (j, k); |
| 125 | vec4 pixel = vec4 (fgColor * lumi + bgColor * (1.0 - lumi), 1.0); | 149 | ivec3 txc = ivec3 (txCoords, fontIdx); |
| 126 | ivec2 pxCoords = charPos * glyphPixels + ivec2 (j, k); | 150 | float lumi = texelFetch (atlas, txc, 0).r; |
| 127 | imageStore (imgOut, pxCoords, pixel); | 151 | vec4 pixel = vec4 (fgColor * lumi + bgColor * (1.0 - lumi), 1.0); |
| 152 | ivec2 pxCoords = charPos * glyphPixels + ivec2 (j, k); | ||
| 153 | imageStore (imgOut, pxCoords, pixel); | ||
| 154 | } | ||
| 155 | } | ||
| 156 | } | ||
| 157 | else if (hasDoubleWidth == 1) | ||
| 158 | { // render double-width cell | ||
| 159 | for (int j = 0; j < srcGlyphPixels.x; j++) | ||
| 160 | { | ||
| 161 | for (int k = 0; k < srcGlyphPixels.y; k++) | ||
| 162 | { | ||
| 163 | ivec2 txCoords = atlasPos * srcGlyphPixels + ivec2 (j, k); | ||
| 164 | ivec3 txc = ivec3 (txCoords, fontIdx); | ||
| 165 | float lumi = texelFetch (atlas_dw, txc, 0).r; | ||
| 166 | vec4 pixel = vec4 (fgColor * lumi + bgColor * (1.0 - lumi), 1.0); | ||
| 167 | ivec2 pxCoords = charPos * glyphPixels + ivec2 (j, k); | ||
| 168 | imageStore (imgOut, pxCoords, pixel); | ||
| 169 | } | ||
| 170 | } | ||
| 171 | } | ||
| 172 | else | ||
| 173 | { // no double-width font -- draw an empty box | ||
| 174 | for (int j = 0; j < srcGlyphPixels.x; j++) | ||
| 175 | { | ||
| 176 | for (int k = 0; k < srcGlyphPixels.y; k++) | ||
| 177 | { | ||
| 178 | float lumi = 0.0; | ||
| 179 | if ((0 < j && j < srcGlyphPixels.x - 1) && | ||
| 180 | (0 < k && k < srcGlyphPixels.y - 1) && | ||
| 181 | (j == 1 || j == srcGlyphPixels.x - 2 || | ||
| 182 | k == 1 || k == srcGlyphPixels.y - 2)) | ||
| 183 | lumi = 0.7; | ||
| 184 | vec4 pixel = vec4 (fgColor * lumi + bgColor * (1.0 - lumi), 1.0); | ||
| 185 | ivec2 pxCoords = charPos * glyphPixels + ivec2 (j, k); | ||
| 186 | imageStore (imgOut, pxCoords, pixel); | ||
| 187 | } | ||
| 128 | } | 188 | } |
| 129 | } | 189 | } |
| 130 | 190 | ||
| 131 | if (underline == 1u) | 191 | if (underline == 1u) |
| 132 | { | 192 | { |
| 133 | for (int j = 0; j < glyphPixels.x; j++) | 193 | for (int j = 0; j < srcGlyphPixels.x; j++) |
| 134 | { | 194 | { |
| 135 | vec4 pixel = vec4 (fgColor, 1.0); | 195 | vec4 pixel = vec4 (fgColor, 1.0); |
| 136 | ivec2 pxCoords = charPos * glyphPixels + ivec2 (j, glyphPixels.y - 1); | 196 | ivec2 pxCoords = charPos * glyphPixels + |
| 197 | ivec2 (j, srcGlyphPixels.y - 1); | ||
| 137 | imageStore (imgOut, pxCoords, pixel); | 198 | imageStore (imgOut, pxCoords, pixel); |
| 138 | } | 199 | } |
| 139 | } | 200 | } |
| @@ -141,9 +202,10 @@ void main () · 1 unmodified line | |||
| 141 | if (showWraps == 1 && wrap == 1u) | 202 | if (showWraps == 1 && wrap == 1u) |
| 142 | { | 203 | { |
| 143 | vec4 pixel = vec4 (fgColor, 1.0); | 204 | vec4 pixel = vec4 (fgColor, 1.0); |
| 144 | for (int k = 0; k < glyphPixels.y; k += 2) | 205 | for (int k = 0; k < srcGlyphPixels.y; k += 2) |
| 145 | { | 206 | { |
| 146 | ivec2 pxCoords = charPos * glyphPixels + ivec2 (glyphPixels.x - 1, k); | 207 | ivec2 pxCoords = charPos * glyphPixels + |
| 208 | ivec2 (srcGlyphPixels.x - 1, k); | ||
| 147 | imageStore (imgOut, pxCoords, pixel); | 209 | imageStore (imgOut, pxCoords, pixel); |
| 148 | } | 210 | } |
| 149 | } | 211 | } |
| @@ -151,18 +213,18 @@ void main () · 1 unmodified line | |||
| 151 | if (charPos == cursorPos.xy && cursorStyle == 2) | 213 | if (charPos == cursorPos.xy && cursorStyle == 2) |
| 152 | { | 214 | { |
| 153 | vec4 pixel = vec4 (crColor, 1.0); | 215 | vec4 pixel = vec4 (crColor, 1.0); |
| 154 | for (int j = 0; j < glyphPixels.x; j++) | 216 | for (int j = 0; j < srcGlyphPixels.x; j++) |
| 155 | { | 217 | { |
| 156 | ivec2 pxCoords = charPos * glyphPixels + ivec2 (j, 0); | 218 | ivec2 pxCoords = charPos * glyphPixels + ivec2 (j, 0); |
| 157 | imageStore (imgOut, pxCoords, pixel); | 219 | imageStore (imgOut, pxCoords, pixel); |
| 158 | pxCoords += ivec2 (0, glyphPixels.y - 1); | 220 | pxCoords += ivec2 (0, srcGlyphPixels.y - 1); |
| 159 | imageStore (imgOut, pxCoords, pixel); | 221 | imageStore (imgOut, pxCoords, pixel); |
| 160 | } | 222 | } |
| 161 | for (int k = 1; k < glyphPixels.y - 1; k++) | 223 | for (int k = 1; k < srcGlyphPixels.y - 1; k++) |
| 162 | { | 224 | { |
| 163 | ivec2 pxCoords = charPos * glyphPixels + ivec2 (0, k); | 225 | ivec2 pxCoords = charPos * glyphPixels + ivec2 (0, k); |
| 164 | imageStore (imgOut, pxCoords, pixel); | 226 | imageStore (imgOut, pxCoords, pixel); |
| 165 | pxCoords += ivec2 (glyphPixels.x - 1, 0); | 227 | pxCoords += ivec2 (srcGlyphPixels.x - 1, 0); |
| 166 | imageStore (imgOut, pxCoords, pixel); | 228 | imageStore (imgOut, pxCoords, pixel); |
| 167 | } | 229 | } |
| 168 | } | 230 | } |
| @@ -266,6 +328,52 @@ void main () · 97 unmodified lines | |||
| 266 | glCheckError (); | 328 | glCheckError (); |
| 267 | } | 329 | } |
| 268 | 330 | ||
| 331 | void | ||
| 332 | setupAtlasMappingTexture (const zutty::Font& fnt, | ||
| 333 | GLuint target, GLuint& texture) | ||
| 334 | { | ||
| 335 | auto atlasMap = std::vector <uint8_t> (); | ||
| 336 | atlasMap.resize (2 * 256 * 256, 0); | ||
| 337 | |||
| 338 | // Pre-fill the mapping texture with references to "missing glyph" | ||
| 339 | // and "replacement character" glyphs, if available in the font atlas. | ||
| 340 | const auto itEnd = fnt.getAtlasMap ().end (); | ||
| 341 | |||
| 342 | zutty::Font::AtlasPos apRC {}; | ||
| 343 | { | ||
| 344 | auto rcIt = | ||
| 345 | fnt.getAtlasMap ().find (zutty::Unicode_Replacement_Character); | ||
| 346 | if (rcIt != itEnd) | ||
| 347 | apRC = rcIt->second; | ||
| 348 | } | ||
| 349 | |||
| 350 | zutty::Font::AtlasPos apMG {}; | ||
| 351 | { | ||
| 352 | auto mgIt = fnt.getAtlasMap ().find (zutty::Missing_Glyph_Marker); | ||
| 353 | if (mgIt != itEnd) | ||
| 354 | apMG = mgIt->second; | ||
| 355 | } | ||
| 356 | |||
| 357 | for (int k = 0; k < 256 * 256; ++k) | ||
| 358 | { | ||
| 359 | const auto& apos = ((k >= 0xd800 && k < 0xe000) || k >= 0xfffe) | ||
| 360 | ? apRC | ||
| 361 | : apMG; | ||
| 362 | atlasMap [2 * k] = apos.x; | ||
| 363 | atlasMap [2 * k + 1] = apos.y; | ||
| 364 | } | ||
| 365 | |||
| 366 | // Fill the mapping texture with supported characters | ||
| 367 | for (auto it = fnt.getAtlasMap ().begin (); it != itEnd; ++it) | ||
| 368 | { | ||
| 369 | atlasMap [2 * it->first] = it->second.x; | ||
| 370 | atlasMap [2 * it->first + 1] = it->second.y; | ||
| 371 | } | ||
| 372 | setupTexture (target, GL_TEXTURE_2D, texture); | ||
| 373 | glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, 256, 256, 0, | ||
| 374 | GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, atlasMap.data ()); | ||
| 375 | } | ||
| 376 | |||
| 269 | template <typename T> void | 377 | template <typename T> void |
| 270 | setupStorageBuffer (GLuint index, GLuint& buffer, uint32_t n_items) | 378 | setupStorageBuffer (GLuint index, GLuint& buffer, uint32_t n_items) |
| 271 | { | 379 | { |
| @@ -284,8 +392,9 @@ void main () · 12 unmodified lines | |||
| 284 | 392 | ||
| 285 | namespace zutty | 393 | namespace zutty |
| 286 | { | 394 | { |
| 287 | CharVdev::CharVdev (const Fontpack* fontpk_) | 395 | CharVdev::CharVdev (Fontpack* fontpk) |
| 288 | : fontpk (* fontpk_) | 396 | : px (fontpk->getPx ()) |
| 397 | , py (fontpk->getPy ()) | ||
| 289 | { | 398 | { |
| 290 | createShaders (); | 399 | createShaders (); |
| 291 | 400 | ||
| @@ -322,75 +431,62 @@ namespace zutty · 30 unmodified lines | |||
| 322 | * Setup compute program | 431 | * Setup compute program |
| 323 | */ | 432 | */ |
| 324 | glUseProgram (P_compute); | 433 | glUseProgram (P_compute); |
| 325 | glUniform2i (compU_glyphPixels, fontpk.getPx (), fontpk.getPy ()); | 434 | glUniform2i (compU_glyphPixels, px, py); |
| 326 | glUniform2i (compU_sizeChars, nCols, nRows); | 435 | glUniform2i (compU_sizeChars, nCols, nRows); |
| 327 | glUniform1i (compU_showWraps, opts.showWraps ? 1 : 0); | 436 | glUniform1i (compU_showWraps, opts.showWraps ? 1 : 0); |
| 328 | 437 | ||
| 329 | // Setup atlas texture | 438 | // Setup atlas texture |
| 330 | setupTexture (GL_TEXTURE1, GL_TEXTURE_2D_ARRAY, T_atlas); | 439 | setupTexture (GL_TEXTURE1, GL_TEXTURE_2D_ARRAY, T_atlas); |
| 331 | const Font& reg = fontpk.getRegular (); | 440 | const Font& reg = fontpk->getRegular (); |
| 332 | glTexStorage3D(GL_TEXTURE_2D_ARRAY, 1, GL_R8, | 441 | glTexStorage3D (GL_TEXTURE_2D_ARRAY, 1, GL_R8, |
| 333 | reg.getPx () * reg.getNx (), | 442 | reg.getPx () * reg.getNx (), |
| 334 | reg.getPy () * reg.getNy (), | 443 | reg.getPy () * reg.getNy (), |
| 335 | 4); // number of layers | 444 | 4); // number of layers |
| 336 | glCheckError (); | 445 | glCheckError (); |
| 337 | 446 | ||
| 338 | setupAtlasTexture (reg, 0); | 447 | setupAtlasTexture (reg, 0); |
| 339 | 448 | ||
| 340 | if (fontpk.hasBold ()) | 449 | if (fontpk->hasBold ()) |
| 341 | setupAtlasTexture (fontpk.getBold (), 1); | 450 | setupAtlasTexture (fontpk->getBold (), 1); |
| 342 | else | 451 | else |
| 343 | setupAtlasTexture (fontpk.getRegular (), 1); | 452 | setupAtlasTexture (fontpk->getRegular (), 1); |
| 344 | 453 | ||
| 345 | if (fontpk.hasItalic ()) | 454 | if (fontpk->hasItalic ()) |
| 346 | setupAtlasTexture (fontpk.getItalic (), 2); | 455 | setupAtlasTexture (fontpk->getItalic (), 2); |
| 347 | else | 456 | else |
| 348 | setupAtlasTexture (fontpk.getRegular (), 2); | 457 | setupAtlasTexture (fontpk->getRegular (), 2); |
| 349 | 458 | ||
| 350 | if (fontpk.hasBoldItalic ()) | 459 | if (fontpk->hasBoldItalic ()) |
| 351 | setupAtlasTexture (fontpk.getBoldItalic (), 3); | 460 | setupAtlasTexture (fontpk->getBoldItalic (), 3); |
| 352 | else if (fontpk.hasItalic ()) | 461 | else if (fontpk->hasItalic ()) |
| 353 | setupAtlasTexture (fontpk.getItalic (), 3); | 462 | setupAtlasTexture (fontpk->getItalic (), 3); |
| 354 | else if (fontpk.hasBold ()) | 463 | else if (fontpk->hasBold ()) |
| 355 | setupAtlasTexture (fontpk.getBold (), 3); | 464 | setupAtlasTexture (fontpk->getBold (), 3); |
| 356 | else | 465 | else |
| 357 | setupAtlasTexture (fontpk.getRegular (), 3); | 466 | setupAtlasTexture (fontpk->getRegular (), 3); |
| 358 | 467 | ||
| 359 | // Setup atlas mapping texture | 468 | setupAtlasMappingTexture (reg, GL_TEXTURE2, T_atlasMap); |
| 360 | auto atlasMap = std::vector <uint8_t> (); | ||
| 361 | atlasMap.resize (2 * 256 * 256, 0); | ||
| 362 | 469 | ||
| 363 | // Pre-fill the mapping texture with references to "missing glyph" | 470 | // Setup atlas texture for double-width characters |
| 364 | // and "replacement character" glyphs, if available in the font atlas. | 471 | if (fontpk->hasDoubleWidth ()) |
| 365 | const auto itEnd = reg.getAtlasMap ().end (); | ||
| 366 | auto rcIt = reg.getAtlasMap ().find (Unicode_Replacement_Character); | ||
| 367 | if (rcIt == itEnd) | ||
| 368 | rcIt = reg.getAtlasMap ().find (' '); | ||
| 369 | assert (rcIt != itEnd); | ||
| 370 | auto mgIt = reg.getAtlasMap ().find (Missing_Glyph_Marker); | ||
| 371 | if (mgIt == itEnd) | ||
| 372 | mgIt = reg.getAtlasMap ().find (' '); | ||
| 373 | assert (mgIt != itEnd); | ||
| 374 | for (int k = 0; k < 256 * 256; ++k) | ||
| 375 | { | 472 | { |
| 376 | const auto& apos = | 473 | hasDoubleWidth = true; |
| 377 | ((k >= 0xd800 && k < 0xe000) || k >= 0xfffe) | 474 | |
| 378 | ? rcIt->second | 475 | setupTexture (GL_TEXTURE3, GL_TEXTURE_2D_ARRAY, T_atlas_dw); |
| 379 | : mgIt->second; | 476 | const Font& dw = fontpk->getDoubleWidth (); |
| 380 | atlasMap [2 * k] = apos.x; | 477 | glTexStorage3D (GL_TEXTURE_2D_ARRAY, 1, GL_R8, |
| 381 | atlasMap [2 * k + 1] = apos.y; | 478 | dw.getPx () * dw.getNx (), |
| 479 | dw.getPy () * dw.getNy (), | ||
| 480 | 1); // number of layers | ||
| 481 | glCheckError (); | ||
| 482 | |||
| 483 | setupAtlasTexture (dw, 0); | ||
| 484 | setupAtlasMappingTexture (dw, GL_TEXTURE3, T_atlasMap_dw); | ||
| 382 | } | 485 | } |
| 486 | glUniform1i (compU_hasDoubleWidth, hasDoubleWidth ? 1 : 0); | ||
| 383 | 487 | ||
| 384 | // Fill the mapping texture with supported characters | 488 | // Now that it's all loaded into GL, no need to keep font data in-memory |
| 385 | auto it = reg.getAtlasMap ().begin (); | 489 | fontpk->releaseFonts (); |
| 386 | for (; it != itEnd; ++it) | ||
| 387 | { | ||
| 388 | atlasMap [2 * it->first] = it->second.x; | ||
| 389 | atlasMap [2 * it->first + 1] = it->second.y; | ||
| 390 | } | ||
| 391 | setupTexture (GL_TEXTURE2, GL_TEXTURE_2D, T_atlasMap); | ||
| 392 | glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, 256, 256, 0, | ||
| 393 | GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, atlasMap.data ()); | ||
| 394 | } | 490 | } |
| 395 | 491 | ||
| 396 | CharVdev::~CharVdev () | 492 | CharVdev::~CharVdev () |
| @@ -407,15 +503,15 @@ namespace zutty · 10 unmodified lines | |||
| 407 | 503 | ||
| 408 | pxWidth = pxWidth_; | 504 | pxWidth = pxWidth_; |
| 409 | pxHeight = pxHeight_; | 505 | pxHeight = pxHeight_; |
| 410 | nCols = std::max (1, (pxWidth - 2 * opts.border) / fontpk.getPx ()); | 506 | nCols = std::max (1, (pxWidth - 2 * opts.border) / px); |
| 411 | nRows = std::max (1, (pxHeight - 2 * opts.border) / fontpk.getPy ()); | 507 | nRows = std::max (1, (pxHeight - 2 * opts.border) / py); |
| 412 | 508 | ||
| 413 | logI << "Resize to " << pxWidth << " x " << pxHeight | 509 | logI << "Resize to " << pxWidth << " x " << pxHeight |
| 414 | << " pixels, " << nCols << " x " << nRows << " chars" | 510 | << " pixels, " << nCols << " x " << nRows << " chars" |
| 415 | << std::endl; | 511 | << std::endl; |
| 416 | 512 | ||
| 417 | GLint viewWidth = nCols * fontpk.getPx (); | 513 | GLint viewWidth = nCols * px; |
| 418 | GLint viewHeight = nRows * fontpk.getPy (); | 514 | GLint viewHeight = nRows * py; |
| 419 | glViewport (opts.border, pxHeight - viewHeight - opts.border, | 515 | glViewport (opts.border, pxHeight - viewHeight - opts.border, |
| 420 | viewWidth, viewHeight); | 516 | viewWidth, viewHeight); |
| 421 | 517 | ||
| @@ -487,6 +583,13 @@ namespace zutty · 65 unmodified lines | |||
| 487 | glBindTexture (GL_TEXTURE_2D_ARRAY, T_atlas); | 583 | glBindTexture (GL_TEXTURE_2D_ARRAY, T_atlas); |
| 488 | glActiveTexture (GL_TEXTURE2); | 584 | glActiveTexture (GL_TEXTURE2); |
| 489 | glBindTexture (GL_TEXTURE_2D, T_atlasMap); | 585 | glBindTexture (GL_TEXTURE_2D, T_atlasMap); |
| 586 | if (hasDoubleWidth) | ||
| 587 | { | ||
| 588 | glActiveTexture (GL_TEXTURE3); | ||
| 589 | glBindTexture (GL_TEXTURE_2D_ARRAY, T_atlas_dw); | ||
| 590 | glActiveTexture (GL_TEXTURE4); | ||
| 591 | glBindTexture (GL_TEXTURE_2D, T_atlasMap_dw); | ||
| 592 | } | ||
| 490 | glCheckError (); | 593 | glCheckError (); |
| 491 | 594 | ||
| 492 | glDispatchCompute (nCols, nRows, 1); | 595 | glDispatchCompute (nCols, nRows, 1); |
| @@ -562,6 +665,7 @@ namespace zutty · 69 unmodified lines | |||
| 562 | compU_selectDamage = glGetUniformLocation (P_compute, "selectDamage"); | 665 | compU_selectDamage = glGetUniformLocation (P_compute, "selectDamage"); |
| 563 | compU_deltaFrame = glGetUniformLocation (P_compute, "deltaFrame"); | 666 | compU_deltaFrame = glGetUniformLocation (P_compute, "deltaFrame"); |
| 564 | compU_showWraps = glGetUniformLocation (P_compute, "showWraps"); | 667 | compU_showWraps = glGetUniformLocation (P_compute, "showWraps"); |
| 668 | compU_hasDoubleWidth = glGetUniformLocation (P_compute, "hasDoubleWidth"); | ||
| 565 | 669 | ||
| 566 | logT << "compute program:" | 670 | logT << "compute program:" |
| 567 | << " uniform glyphPixels=" << compU_glyphPixels | 671 | << " uniform glyphPixels=" << compU_glyphPixels |
| @@ -574,6 +678,7 @@ namespace zutty · 6 unmodified lines | |||
| 574 | << " selectDamage=" << compU_selectDamage | 678 | << " selectDamage=" << compU_selectDamage |
| 575 | << " deltaFrame=" << compU_deltaFrame | 679 | << " deltaFrame=" << compU_deltaFrame |
| 576 | << " showWraps=" << compU_showWraps | 680 | << " showWraps=" << compU_showWraps |
| 681 | << " hasDoubleWidth=" << compU_hasDoubleWidth | ||
| 577 | << std::endl; | 682 | << std::endl; |
| 578 | 683 | ||
| 579 | P_draw = glCreateProgram (); | 684 | P_draw = glCreateProgram (); |