Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tracking issue: new scaling system #239

Closed
thebracket opened this issue Nov 1, 2021 · 10 comments
Closed

Tracking issue: new scaling system #239

thebracket opened this issue Nov 1, 2021 · 10 comments
Assignees
Labels
enhancement New feature or request

Comments

@thebracket
Copy link
Collaborator

Making the next feature branch a scaling system. I'm hoping that this will resolve quite a few issues that have been reported, while not breaking the API (I'm not asking much, eh?). Since there's a lot of moving parts related to the two scaling systems (simply scaling consoles and growing/shrinking the terminal size dynamically), this deserves its own branch while the kinks are worked out.

Goals:

  • Support gutters around the render area. This alleviates the window rounding seen with Big Sur (and in danger of hitting Win11 by the looks of it), and supports other scaling enhancements.
  • Accurate font size in texture coordinates when blitting, to avoid the missing-pixel issues that have caused so many problems.
  • Probably optional, but "perfect" scaling: add to the gutter until the size is a multiple of the font size, and then scale the font by a consistent amount (or expand/shrink the console by a fixed amount).

Developing will take place in the https://github.com/amethyst/bracket-lib/tree/scaling branch.

This directly affects the following issues:
#226 #220 #213 #178 #171

@thebracket thebracket added the enhancement New feature or request label Nov 1, 2021
@thebracket thebracket self-assigned this Nov 1, 2021
thebracket added a commit that referenced this issue Nov 2, 2021
@thebracket
Copy link
Collaborator Author

The first commit to this branch sets up a new FontScaler type, which takes over the duties of calculating font sizes for all console types. It's actually pretty simple, but instead of each console doing the math - its now in one place. Using accurate math has fixed the issue with the bottom row of pixels not always rendering:

image

This has been applied to all OpenGL and WGPU supported consoles and is working well. It's actually slightly faster, too.

You'll also notice that the second commit is being used to add a gutter. This only applies to simple consoles at the moment, and only in OpenGL mode. So the adventurer isn't quite centered properly, because the secondary console doesn't have gutters yet. I also haven't applied it to other renderers or the input chain yet. Not a bad proof-of-concept, and performance is good.

thebracket added a commit that referenced this issue Nov 2, 2021
thebracket added a commit that referenced this issue Nov 2, 2021
thebracket added a commit that referenced this issue Nov 2, 2021
…dd gutters to constrain scaled font sizes to multiples of natural font size, avoiding distortion.
@thebracket
Copy link
Collaborator Author

constrained_scaling

Hopefully the gif will work. The last patch:

  • Sets the minimum window size to the natural size. This makes it easy to go back to the "normal" size and avoids scaling confusion.
  • Divides the desired window size by the largest font size, and adds the remainder to an extra gutter. This keeps fonts scaling at natural levels on the x/y axes (no attempt at aspect ratio yet). This makes the result look better as you upscale it.

thebracket added a commit that referenced this issue Nov 2, 2021
thebracket added a commit that referenced this issue Nov 2, 2021
thebracket added a commit that referenced this issue Nov 2, 2021
…Check if their contents has changed (or a resize occurred). If they are identical, skip uploading the vertex/index buffers. Applies to WebGPU and both OpenGL paths.
@thebracket
Copy link
Collaborator Author

Signing off for the day on this, but there's some solid progress. The bottom row not rendering issue appears to be fixed. Scaling windows works, and tries to pick reasonable sizes based on fonts to keep things looking decent. Added in an optimization (that probably doesn't really belong in this issue) to not update vertex/index buffers if a console hasn't changed between frames. On turn-based roguelikes, that's usually the case - so it saves quite a bit of cpu/gpu traffic. It remains to be seen if its worth the effort for real-time games.

This appears to work with consoles that change their character buffer size rather than scaling - but work remains to be done. There are also issues to resolve with WASM builds.

thebracket added a commit that referenced this issue Nov 4, 2021
…screen scaler's available_* fields for size, giving smooth scaling.
@thebracket
Copy link
Collaborator Author

OpenGL now has pretty nice aspect-ratio constrained scaling.
constrained_scaling3

I've got some really odd behavior happening in WGPU. When you resize the window, holes appear in it - and moving the window instantly fixes it. Spying on the buffer in renderdoc shows that the buffer looks great - so it must be a problem with how the surface is reconfigured on move. Once I figure this out, I'll push the commit with this change.

thebracket added a commit that referenced this issue Nov 4, 2021
thebracket added a commit that referenced this issue Nov 4, 2021
@thebracket
Copy link
Collaborator Author

Haha. I guess it had to happen eventually... it works great on my Mac in wgpu, and on Linux. DX12 on Windows has the issue!

@thebracket
Copy link
Collaborator Author

More research indicates that its the driver! https://github.com/gfx-rs/wgpu/wiki/Known-Driver-Issues#intel--directx-12

thebracket added a commit that referenced this issue Nov 5, 2021
…he render surface, which turned out not to work on Metal.
thebracket added a commit that referenced this issue Nov 5, 2021
…a gutter of 8px for win/mac and 0px for everything else.
@thebracket
Copy link
Collaborator Author

thebracket commented Nov 5, 2021

Now working on compatibility testing with the Hands-on Rust code-base.

  • Flappy Dragon (bonus edition) works in both OpenGL and WGPU.
  • dungeon_crawl_player works in both OpenGL and WGPU.
  • dungeon_crawl_graphics works in OpenGL. Player rendering layer is broken in WGPU.

So I'll work on fixing that.

thebracket added a commit that referenced this issue Nov 5, 2021
@thebracket
Copy link
Collaborator Author

More compatibility:

  • dungeon_crawl_graphics now works with both GL and WebGPU.
  • loot_tables and the final examples work with both GL and WebGPU.

So Hands-on Rust code now works with the latest builds. (I have to test that one first, since a large chunk of my livelihood comes from my book writing!)

Moving on to the Roguelike Tutorial. The most recent chapter compiles and runs great. Thanks to the new scheduling system, it consumes only 1% of CPU while running (Windows), spiking higher when you take a turn.

So I think this branch is good. :-)

thebracket added a commit that referenced this issue Nov 5, 2021
…enhancements. (#242)

* #239: Use a consistent font scalar for all terminal types on both opengl and wgpu.

* #239 - Proof of concept. Simple terminal on OpenGL supports gutters (output only at this point).

* #239 - Apply same changes to sparse and fancy consoles, try to fix a winit path that broke the CI.

* Oops - I'd made WebGPU the RLTK default.

* Fix default terminal type for bracket-lib also

* #239 - Simple/Sparse/Fancy consoles have working output gutters for OpenGL and WebGPU. Input isn't done yet.

* #239 Constrain minimum window size to the natural size. Dynamically add gutters to constrain scaled font sizes to multiples of natural font size, avoiding distortion.

* Oops - didn't mean to double the gutter size!

* #239 - A Star Mouse example has working mouse control now. Pretty sure this breaks wasm, will fix later.

* #239 - Forced resize event on start in wgpu, just like OpenGL - it helps ensure things are consistent.

* #239 - Simple/Sparse consoles don't change much in turn-based games. Check if their contents has changed (or a resize occurred). If they are identical, skip uploading the vertex/index buffers. Applies to WebGPU and both OpenGL paths.

* #239 - Scalable (auto-resize console rather than scale) now uses the screen scaler's available_* fields for size, giving smooth scaling.

* #239 - Quick doc update.

* #239 - OpenGL aspect ratio scaling working great. Resize is doing really odd things on wgpu.

* Unbreak rendering on non-dx12 platforms.

* #239 #241 Fixes screenshots. No longer require the COPY_SRC flag on the render surface, which turned out not to work on Metal.

* #239 Move to a single default gutter function, conditionally compile a gutter of 8px for win/mac and 0px for everything else.

* #239 - Unbreak WASM32 compilation. Still testing it.

* #239 - Doc update, reminder that you have to use resolver=2 if you are using wgpu.

* #239 - Fix console without background discard detection, fixing the Hands-on Rust dungeon_graphics example.

* #239 - Remove println I left in by mistake.
@thebracket
Copy link
Collaborator Author

Woot - the new scaling system and associated enhancements are merged.

@thebracket
Copy link
Collaborator Author

Now that its merged, closing the tracking issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant