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

integer scaling on a Mac Retina screen #173

Closed
mbunkin opened this issue Apr 20, 2018 · 22 comments
Closed

integer scaling on a Mac Retina screen #173

mbunkin opened this issue Apr 20, 2018 · 22 comments
Labels

Comments

@mbunkin
Copy link

mbunkin commented Apr 20, 2018

I don't think pixel perfect integer scaling works on my Retina screen. It requires 1600x1200 minimum, my full screen resolution is 2880x1800. Perhaps SDL is not utilising the full Retina resolution.

@Falcury
Copy link
Contributor

Falcury commented Apr 20, 2018

It requires 1600x1200 minimum

That is only the case if 4:3 aspect ratio is also enabled.
It may be helpful to have some more details on the problem you are experiencing?

@mbunkin
Copy link
Author

mbunkin commented Apr 20, 2018

The problem is simple, switching on the integer scaling doesn't change the visual appearance. I can send a screenshot, if it helps? I believe it's because the SDL uses the non-Retina resolution of 1440x900. Can I assist somehow? I have this idea of integer scaling myself for several years - with a few black margins 320x200 can be emulated very precisely on my Retina screen. So I'm eager to see it in action.

@Falcury
Copy link
Contributor

Falcury commented Apr 20, 2018

Are you running in fullscreen mode then?
In windowed mode, you should notice the difference only when you resize the window (because the default window size 640x400 is already an integer multiple of 320x200).

@mbunkin
Copy link
Author

mbunkin commented Apr 20, 2018

Yes, it's full screen. I made a small screenshot and compared the pixel width. It's either 6 or 8 pixels, never 7 or 5. Which means that SDL is not using the full Retina resolution.

@Falcury
Copy link
Contributor

Falcury commented Apr 20, 2018

What version of SDL2 are you on?
Note that SDL_RenderSetIntegerScale is a recent feature, it was introduced in version 2.0.5.

@mbunkin
Copy link
Author

mbunkin commented Apr 21, 2018

I downloaded the latest stable SDLPoP 1.18.1, but I can't see what SDL version is inside. I assumed if it has that option in the menu, it should have the feature?

@NagyD
Copy link
Owner

NagyD commented Apr 22, 2018

but I can't see what SDL version is inside.

Hm, maybe there should be a debugging option to display this somewhere?

I made a small screenshot and compared the pixel width. It's either 6 or 8 pixels, never 7 or 5. Which means that SDL is not using the full Retina resolution.

From what I know, Retina Display automatically upscales the output of Retina-unaware applications to double size; and correspondingly, applications probably see half of the actual resolution.
(source 1) (source 2)
(Documentation by Apple, section "Apps That Aren’t Yet Ready")

There is some documentation about SDL and Retina (high-DPI) in the SDL docs.
This remark seems to be of interest:

On Apple's OS X you must set the NSHighResolutionCapable Info.plist property to YES

In the latest DMG file, this setting is not even present in the Info.plist file.
Maybe you (or someone else) could try adding these lines:

	<key>NSHighResolutionCapable</key>
	<true/>

(I don't have Mac OS X, so I can't test this.)

@NagyD NagyD added the bug label Apr 22, 2018
@Falcury
Copy link
Contributor

Falcury commented Apr 22, 2018

Ah. If I remember correctly, I built the bundle in the .dmg file using SDL 2.0.5, so that should be fine.

Maybe you (or someone else) could try adding these lines:

OK, I will try to reproduce the issue (I will need to ask someone who has a Retina machine nicely...), then see if that fixes it.

Hm, there is also the SDL_WINDOW_ALLOW_HIGHDPI window creation flag, described here:
https://wiki.libsdl.org/SDL_CreateWindow

I guess that needs to be set as well.

@mbunkin
Copy link
Author

mbunkin commented Apr 23, 2018

I tried adding NSHighResolutionCapable to Info.plist, it didn't enable Retina support. Let me know what else to try. I'll be delighted to help, as far as my schedule allows.

I would also suggest forcing discrete GPU when using Retina, because on laptops with integrated and discrete GPUs, when switching to Retina mode without forcing discrete GPU first, it can enter a mode with lower physical resolution and larger framebuffer, which effectively shows only a portion of the framebuffer on the screen. I've seen games suffering from it, but it may be simple to work around, I found this article, maybe it will work: https://stackoverflow.com/questions/16823372/forcing-machine-to-use-dedicated-graphics-card#39047129 - seems like just a single line of code.

Let me know how can I assist.

@NagyD
Copy link
Owner

NagyD commented Apr 28, 2018

Let me know what else to try.

You could try adding the flag that Falcury mentioned above.
That is, here in seg009.c, add this new line:

	flags |= SDL_WINDOW_ALLOW_HIGHDPI;

And recompile.

I found this article, maybe it will work: https://stackoverflow.com/questions/16823372/forcing-machine-to-use-dedicated-graphics-card#39047129 - seems like just a single line of code.

It says it's for Windows, and that it might not work on MacOS.

@Falcury
Copy link
Contributor

Falcury commented Apr 28, 2018

I attached a test build, can you try it and see if it works?
SDLPoP.macOS.Retina.test.zip

Commit: Falcury@f1f6496

@mbunkin
Copy link
Author

mbunkin commented Apr 28, 2018 via email

@Falcury
Copy link
Contributor

Falcury commented Apr 28, 2018

It always starts in windowed mode, I can’t tell if there are any problems when it would start in fullscreen.

You could test that by switching on the 'Start fullscreen' setting in the pause menu (Settings -> Visuals), then quitting and restarting the game.

Integer scaling does not change anything (in 4:3), either it doesn’t work, or works always - in either case, the pixel size is greatly improved on Retina screens, which is great, and it’s officially the best looking Prince on a Mac :)

That's good to hear :)
Although it's still strange that the integer scaling doesn't seem to do anything in your case.

@mbunkin
Copy link
Author

mbunkin commented Apr 28, 2018 via email

@EndeavourAccuracy
Copy link
Contributor

but I can't see what SDL version is inside.

Hm, maybe there should be a debugging option to display this somewhere?

If you put SDL_version verc, verl; in a .h somewhere, you could make Ctrl+c show the version numbers by adding inside the switch(key) of seg000.c this:

    case SDL_SCANCODE_C | WITH_CTRL: // ctrl-c
      SDL_VERSION (&verc);
      SDL_GetVersion (&verl);
      snprintf (sprintf_temp, sizeof (sprintf_temp),
        "SDL COMP v%u.%u.%u LINK v%u.%u.%u",
        verc.major, verc.minor, verc.patch,
        verl.major, verl.minor, verl.patch);
      answer_text = sprintf_temp;
      need_show_text = 1;
      break;

By the way, unrelated, in the master branch, the start-up info screen currently shows up only a fraction of a second, so something probably broke somewhere...

@NagyD
Copy link
Owner

NagyD commented Apr 29, 2018

you could make Ctrl+c show the version numbers

Done: b35b3f3

It is indeed strange that integer scaling doesn’t work.

I figured out what might cause this.
Integer scaling is enabled only if the window size is bigger than the render size: https://github.com/NagyD/SDLPoP/blob/master/src/seg009.c#L2192
(Render size is 320×200 by default and 1600×1200 in 4:3 mode)
Now, the question is, how does SDL measure the window size on high-DPI screens, in points or pixels? (See Apple's docs for the difference between the two.)
Your screen is 2880×1800 pixels but 1440×900 points.
If SDLPoP sees the latter as the size of the fullscreen window, then it won't enable integer scaling in 4:3 mode.

You (or Falcury) could add a debug printout to the source line I linked, to see what is SDLPoP's idea about these two sizes.

with a resolution of 2880x1800 at 16:9

That is 16:10, by the way. :)

@mbunkin
Copy link
Author

mbunkin commented Apr 29, 2018 via email

@mbunkin
Copy link
Author

mbunkin commented Apr 29, 2018

I checked and indeed window_width / window_height contain the "points", 1440x900.
Furthermore, trying to set makes_sense to true resulted in screen going black when I switch to integer scaling.

@NagyD
Copy link
Owner

NagyD commented Apr 30, 2018

I checked and indeed window_width / window_height contain the "points", 1440x900.

Indeed, https://wiki.libsdl.org/SDL_GetWindowSize recommends other functions that will return the correct value on a high-DPI screens.

I changed the way I read the window size: abdd7bd

Furthermore, trying to set makes_sense to true resulted in screen going black when I switch to integer scaling.

That happens when the window is smaller than the render size.
Which source did you compile?
On the master branch, SDL_WINDOW_ALLOW_HIGHDPI wasn't enabled.
So I also added that in the commit above.
Please pull the latest source from GIT and try that.
Don't forget the NSHighResolutionCapable in the Info.plist file. (That file is not yet on the master branch.)

@mbunkin
Copy link
Author

mbunkin commented Apr 30, 2018 via email

@NagyD
Copy link
Owner

NagyD commented May 1, 2018

It's good to hear that.

Can I close this now?

@mbunkin
Copy link
Author

mbunkin commented May 1, 2018 via email

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

No branches or pull requests

4 participants