contour-terminal / contour

Modern C++ Terminal Emulator
http://contour-terminal.org/
Apache License 2.0
2.39k stars 101 forks source link

Texture atlas overlap in glyphs when rendering, result in ghost-boxed characters #1022

Closed whisperity closed 11 months ago

whisperity commented 1 year ago

Contour Terminal version

0.3.10.4591

Installer source

Github: CI actions

Operating System

Ubuntu 20.04

Architecture

x86-64

Other Software

(Irrelevant.)

Steps to reproduce

  1. echo "%"
  2. The % looks reasonably okay, but there is a faint | at the right side:

Screenshot_20230209_101041

  1. echo "&"
  2. The "belly" of the & gets rendered into the %'s space, resulting in a broken looking glyph:

Screenshot_20230209_101110

:warning: N.b.: This only appears on "normal" zoom level. If I do nine (9) "zoom in" actions (Ctrl + MouseWheelUp) the effect is barely noticeable:

Screenshot_20230209_101300

However, after doing another (that is, in total, ten) zoom ins, the full vertical bars come back:

Screenshot_20230209_101305

Restoring to default zoom (Ctrl+0) restores the visuals seen in step 4.zoom-ins

Expected Behavior

Characters do not expect each others' rendering.

Actual Behavior

Ugly glyphs.

Additional notes

profile:
  master:
    font:
      size: 12
      dpi_scale: 1.0
      render_mode: lcd
      regular:
        family: "JetBrainsMono Nerd Font"
[2023-02-09 10:15:19.663721] [gui.display] TerminalWindow.resizeEvent: size 200x100 (200x100)
[2023-02-09 10:15:19.670078] [gui.display] initializeGL: size=179x100, scale=1
[2023-02-09 10:15:19.670157] [gui.display] Assigning session to terminal widget: shell=/bin/zsh, terminalSize=80x24, fontSize=12pt, contentScale=1
[2023-02-09 10:15:19.710613] [gui.display] Loading vertex shader: :/contour/display/shaders/text.vert
[2023-02-09 10:15:19.713248] [gui.display] Loading fragment shader: :/contour/display/shaders/text.frag
[2023-02-09 10:15:19.714026] [gui.display] Loading vertex shader: :/contour/display/shaders/background_image.vert
[2023-02-09 10:15:19.714070] [gui.display] Loading fragment shader: :/contour/display/shaders/background_image.frag
[2023-02-09 10:15:19.714458] [gui.display] Loading vertex shader: :/contour/display/shaders/background.vert
[2023-02-09 10:15:19.714479] [gui.display] Loading fragment shader: :/contour/display/shaders/background.frag
[2023-02-09 10:15:19.715027] [gui.display] configureAtlas: 1024x2048 RGBA
[2023-02-09 10:15:19.801055] [gui.display] Blur: Loading shader source :/contour/display/shaders/simple.vert
[2023-02-09 10:15:19.801235] [gui.display] Blur: Loading shader source :/contour/display/shaders/blur_gaussian.frag
[2023-02-09 10:15:19.802315] [gui.display] Blur: Loading shader source :/contour/display/shaders/simple.vert
[2023-02-09 10:15:19.802400] [gui.display] Blur: Loading shader source :/contour/display/shaders/dual_kawase_up.frag
[2023-02-09 10:15:19.802958] [gui.display] Blur: Loading shader source :/contour/display/shaders/simple.vert
[2023-02-09 10:15:19.802994] [gui.display] Blur: Loading shader source :/contour/display/shaders/dual_kawase_down.frag
[2023-02-09 10:15:19.931259] [gui.display] Blur: Gaussian run performance: 0.226s CPU.
[2023-02-09 10:15:19.943315] [gui.display] Background image from disk: 3840x2160 RGBA
[2023-02-09 10:15:19.959257] [gui.display] [FYI] Build type          : RelWithDebInfo
[2023-02-09 10:15:19.959291] [gui.display] [FYI] Application PID     : 17300
[2023-02-09 10:15:19.959293] [gui.display] [FYI] OpenGL type         : OpenGL
[2023-02-09 10:15:19.959302] [gui.display] [FYI] OpenGL renderer     : Mesa Intel(R) Xe Graphics (TGL GT2)
[2023-02-09 10:15:19.959308] [gui.display] [FYI] Qt platform         : xcb
[2023-02-09 10:15:19.959319] [gui.display] [FYI] OpenGL version      : 4.6
[2023-02-09 10:15:19.959330] [gui.display] [FYI] Content scaling     : 1
[2023-02-09 10:15:19.959336] [gui.display] [FYI] GLSL version        : 4.60 (460, 450, 440, 430, 420, 410, 400, 330, 150, 140, 130, 120, 320 es, 310 es, 300 es, 100)
[2023-02-09 10:15:19.959367] [gui.display] [FYI] Refresh rate        : 59 Hz
[2023-02-09 10:15:19.959370] [gui.display] [FYI] Screen size         : 1920x1080
[2023-02-09 10:15:19.959375] [gui.display] [FYI] Logical DPI         : 96x96
[2023-02-09 10:15:19.959383] [gui.display] [FYI] Physical DPI        : 142x141
[2023-02-09 10:15:19.959386] [gui.display] [FYI] Device pixel ratio  : 1
[2023-02-09 10:15:19.959397] [gui.display] [FYI] Content scale       : 1
[2023-02-09 10:15:19.959406] [gui.display] [FYI] Font DPI            : 96x96 (96x96)
[2023-02-09 10:15:19.959409] [gui.display] [FYI] Font size           : 12pt (16 px)
[2023-02-09 10:15:19.959411] [gui.display] [FYI] Cell size           : 10x22 px
[2023-02-09 10:15:19.959414] [gui.display] [FYI] Page size           : 80x24
[2023-02-09 10:15:19.959416] [gui.display] [FYI] Font baseline       : 5 px
[2023-02-09 10:15:19.959418] [gui.display] [FYI] Underline position  : 3 px
[2023-02-09 10:15:19.959421] [gui.display] [FYI] Underline thickness : 1 px
[2023-02-09 10:15:20.039373] [gui.display] Blur: Loading shader source :/contour/display/shaders/simple.vert
[2023-02-09 10:15:20.039560] [gui.display] Blur: Loading shader source :/contour/display/shaders/blur_gaussian.frag
[2023-02-09 10:15:20.040294] [gui.display] Blur: Loading shader source :/contour/display/shaders/simple.vert
[2023-02-09 10:15:20.040353] [gui.display] Blur: Loading shader source :/contour/display/shaders/dual_kawase_up.frag
[2023-02-09 10:15:20.040712] [gui.display] Blur: Loading shader source :/contour/display/shaders/simple.vert
[2023-02-09 10:15:20.040739] [gui.display] Blur: Loading shader source :/contour/display/shaders/dual_kawase_down.frag
[2023-02-09 10:15:20.139597] [gui.display] Blur: Gaussian run performance: 0.193s CPU.
[2023-02-09 10:15:20.146300] [gui.display] Background image from disk: 3840x2160 RGBA
[2023-02-09 10:15:20.160054] [gui.display] TerminalWindow.resizeEvent: size 821x528 (821x528)
[2023-02-09 10:15:20.161423] [gui.display] Resizing view to 800x528 virtual (800x528 actual).
[2023-02-09 10:15:20.161689] [gui.display] GL configure atlas: 1024x2048 RGBA GL texture Id 4
[2023-02-09 10:15:20.176440] [gui.display] Resizing view to 800x528 virtual (800x528 actual).
[2023-02-09 10:15:20.193589] [gui.display] Screen changed.

Texture atlas with only rendering %: texture-atlas-rgba

Texture atlas after rendering the &: texture-atlas-rgba

Yaraslaut commented 1 year ago

culprit is this function

https://github.com/contour-terminal/contour/blob/2d490c86cbd52ff25250a71a130eb226ba21d8ac/src/vtrasterizer/TextRenderer.cpp#L358

Info from debug on cutting sizes

Cutting off oversized RGB tile from 11x13 down to 10x21.
christianparpart commented 1 year ago

oh very nice catch @Yaraslaut. the question is how do we want to fix this.

we could add a 1px padding in between the texture atlas tiles. I think I have no better idea as of right now.

11x13 down to 10x21

okay, horizontally from 11 down to 10 makes sense. this might be the reason why it was triggered anyways. but 13 to 21 looks like THE bug here? hmmm 🤔

Yaraslaut commented 1 year ago

oh very nice catch @Yaraslaut. the question is how do we want to fix this.

we could add a 1px padding in between the texture atlas tiles. I think I have no better idea as of right now.

11x13 down to 10x21

okay, horizontally from 11 down to 10 makes sense. this might be the reason why it was triggered anyways. but 13 to 21 looks like THE bug here? hmmm 🤔

I tried disabling this thing and didn't notice any changes, so I wonder why this is required in the first place? Shouldn't harfbuzz create properly aligned buffer ?

christianparpart commented 1 year ago

you mean FreeType. yeah, but some glyphs are wider, some are tinner (horizontally and vertically). The glyphs that are horizontally wider, must be cut down to avoid accidentally writing into a tile in the texture atlas that belong to a different bitmap.

On the other hand, we have the tile splitting functionality that e.g. is used to still render programming ligatures correctly - so why do we end up cutting in that function in the first place. 🤔

Yaraslaut commented 1 year ago

Agree, adding 1 px sound like a good idea, since i noticed that disabling this function does not solve the problem completely