Skip to content

Conversation

almarklein
Copy link
Member

We already have renderer.pixel_ratio, but its behavior is not so great when the screen's pixel_ratio is a fractional.

With this PR:

  • renderer.pixel_scale is the factor between the internal texture and target physical size.
    • For values > 1 it represents the amount of ssaa.
    • Setting to 1 matches the internal texture size with the target resolution.
  • renderer.pixel_ratio is the factor between the internal texture and target logical size.
    • It represents the total pixel_ratio.
  • Setting either to None will chose a pixel_scale of either 1 or 2, depending on whether the screen looks like it's hiDPI.
    • The current code already intended to do this, but kindof failed for e.g. 125% OS scaling on Windows/Linux.

For reference, the behavior of OS display scaling

  • MacOS
    • Can select among a few different "text sizes".
    • MacOS uses an internal framebuffer that is sized smaller for "large text" mode, and then rendered to screen.
    • In effect the pixel_ratio is always 2.0.
  • Windows:
    • Select resolution, and then a scale (100%, 125%, 150%, 175%).
    • On a HiDPI display, can also select scales 200% and beyond.
    • The display scale percentage is directly reflected in the canvas.pixel_ratio. E.g. 225%-> 2.25
  • Linux Wayland
    • Select resolution, and then a scale. Fractional scales are experimental.
    • Qt backend:
      • Scale 100% and 200% result in pixel ratios 1 and 2.
      • Fractional scales work too, e.g. pixel_ratio 1.25
    • Glfw backend:
      • Stuck to pixel_ratio 1.0 -> a bug in glfw (I checked that its not our wrapper).
  • Linux X11
    • Select resolution, and then a scale. Fractional scales are experimental.
    • Need to restart IDE / pygfx to take effect.
    • Scale 100% and 200% result in pixel ratios 1 and 2.
    • Fractional scales don't work 150% -> 2.0, 250% -> 3.0
    • Same behavior for glfw and Qt.

What this means

  • On MacOS the canvas.pixel_ratio is always 2.0, as far as I can see.
  • Mac simply scales the whole rendered screen (it can do that because it can assume it has a Retina display).
  • Windows and Linux work more or less the same.
  • Users may have a pixel_ratio of 1.25 or 1.5 (i.e. if they use a large screen and place it further away).
  • We can assume that with a pixel_ratio of 2.0+ we're dealing with a HiDPI display.

To summarize this PR in the context of the above; we use pixel_ratio>=2 to detect HiDPI displays and turn on SSAA automatically if its not, being careful to select either a factor of 1 or 2, because the ssaa.wgsl shader is optimized for these values.

@almarklein almarklein requested a review from Korijn as a code owner August 25, 2025 14:15
@almarklein almarklein enabled auto-merge (squash) August 26, 2025 07:32
@almarklein almarklein merged commit 812a1a7 into main Aug 26, 2025
13 checks passed
@almarklein almarklein deleted the pixel-scale branch August 26, 2025 07:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants