-
Notifications
You must be signed in to change notification settings - Fork 81
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
Introducing backing scale #1269
Conversation
46ccb75
to
228b610
Compare
I'm looking at cursor scale again. Cursor scale is its own function right now in the Mac client. In some ways this makes sense - plMouseDevice is not owned by plClient and can't trivially just inherit settings. There are accessibility reasons that the cursor may also want to be its own scale down the road. I may reintroduce the cursor scale as is - even though it's parallel to the backing scale and not directly affected by it. There could be further iteration on cursor scale later. |
Something weird is going on in Windows font rendering. It's not behaving how I expect it to, and this pull request is causing font spacing to not behave correctly on Windows. Still checking it over. |
I'm kind of fumbling around in the Win32 client (never done serious Win32 before) and I've got backing and cursor scale hooked up in Windows as well. I enabled HiDPI in Windows by tweaking the manifest. I have not committed that change in since it probably requires more testing, and there have been known issues around HiDPI.
|
I haven't read the code yet, but we probably want to avoid using the manifest for this because DPI Awareness v2 in the manifest will lock us to Windows 10 v1703. Instead, we'll want to use LoadLibrary to call the appropriate SetThreadDpiAwareness function. |
Thanks! I was unsure how to opt in to functions from newer versions of Windows. There are better DPI check functions to use on newer Windows as well. I'm also unsure if cursor scale and backing scale should be more closely related or stay separate options - but that's why this PR is a draft. |
I've built a set of DPI awareness changes for Windows on top of this PR on my fork that might be useful. My branch seems to fix the problems in #636. |
cb24c65
to
0e91d15
Compare
Your changes look good to me. I'll reset this to your branch's head and then graduate this to a full PR. Your comments indicate there might be a few things not done yet, but we can look at that on deeper review. |
I wrote that I'd bring in your branch's head. It's already here! Never mind. |
@Hoikas - I'm going to look at this again on macOS. Was there any more work you wanted to do on Windows? So far this has worked well on Windows for me, but I know there are some todos in the code comments. |
I don't think there's anything else I want to do right now. |
I'll do a final checkover. I'm fine dealing with any Mac specific issues directly on the Mac branch. But I do want to make sure there isn't anything critical with the core implementation. |
Something is subtlety wrong with Windows font rendering at HiDPI. The spacing is off. I think it's due to an issue with the font map that's created. I'll investigate more. |
It's probable that there are some non-DPI aware APIs being called in the debug text renderer that I didn't catch. 😞 |
Possible. But this code is strange in that Cyan created it to be DPI aware - but it may have never really worked. AFAIK the DPI check would never have been tested at anything but the default 96 DPI. |
Alternatively, maybe we write an implementation of this using freetype2 so that it's cross-platform? (Since I'm going to end up needing to do that for OpenGL anyways, if someone wants to do that work for me... 😛) |
I feel like you might have just volunteered yourself. 😛 With FreeType2 we'd still want to make sure that everything lines up the same which might be tricky. I'm getting the sense a lot of this font code just happened to work and had some amount of magic numbers, which is being upset by the DPI work. I cleaned a lot of that up on the renderer side. And while I don't see any magic numbers in the font map code - something is clearly up. |
4bb5dc8
to
c25f554
Compare
@@ -136,23 +157,57 @@ uint16_t *plTextFont::IInitFontTexture() | |||
// Loop through characters, drawing them one at a time | |||
RECT r; | |||
r.left = r.top = 0; | |||
r.right = r.bottom = 10; | |||
r.right = 1; | |||
r.bottom = 10; | |||
FillRect( hDC, &r, (HBRUSH)GetStockObject( GRAY_BRUSH ) ); | |||
|
|||
// (Make first character a black dot, for filling rectangles) | |||
SetPixel( hDC, 0, 0, RGB( 255, 255, 255 ) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That looks a little bit like it's drawing a cursor, assuming you mean:
RECT r;
r.left = r.top = 0;
r.right = r.bottom = 10;
FillRect( hDC, &r, (HBRUSH)GetStockObject( GRAY_BRUSH ) );
// (Make first character a black dot, for filling rectangles)
SetPixel( hDC, 0, 0, RGB( 255, 255, 255 ) );
Not sure about the SetPixel()
call though.
9049200
to
c41e984
Compare
2b611b3
to
5dcb92f
Compare
ca29f47
to
020a9a4
Compare
@@ -3337,6 +3337,7 @@ bool plDXPipeline::CaptureScreen( plMipmap *dest, bool flipVertical, uint16_t d | |||
} | |||
else | |||
{ | |||
// FIXME: DPI awareness |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is never used anywhere, so omitting should be fine for now, IMO.
nHeight = -MulDiv( fSize, GetDeviceCaps( hDC, LOGPIXELSY ), 72 ); | ||
fFontHeight = -nHeight; | ||
|
||
int nHeight = -MulDiv( fSize, plWinDpi::Instance().GetDpi(), 72); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this ever re-done when the DPI changes while the game is running?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DPI change is treated as a device reset IIRC just like any other resolution change - which should flush textures like this one.
I don't know that this path has ever been fully tested however.
Co-authored-by: Adam Johnson <[email protected]>
Still waiting on the update to cmake/Dependencies.cmake, then we should be good to go. |
Not seeing that comment, guessing it's just buried in the others. But I'm guessing the change you'd like to see is FreeType moving to required from optional? |
This change introduces the idea of a backing scale into the engine. Backing scale refers to the difference between the resolution of the window that Uru is running in, and the resolution of the frame buffer backing it.
For example, on a 4k Retina display, the window may only have a resolution of 1920x1080, while the actual Metal/DX/OpenGL frame buffer has a resolution of 3840x2160. The backing scale would be 2.
Different UI elements can use the backing scale to resize accordingly. This change alters the behavior of progress bars and the intro movie to account for the backing scale. Cursor should also change with the backing scale - I'm still working on pulling that together for this pull request.
Text rendering should also take into account the backing scale (although this PR does not make all the required changes.) A backing scale of 2 would imply that a 12 point font should render at twice the DPI. I've made some initial progress for this on macOS.
Backing scale is also useful if Uru ever chose to use DLSS/MetalFX upscaling. If the engine is under-rendering, backing scale can be used to push the UI elements back into a size the user expects.