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

There should be a way to get retina support on Mac #934

Closed
SDLBugzilla opened this issue Feb 10, 2021 · 0 comments
Closed

There should be a way to get retina support on Mac #934

SDLBugzilla opened this issue Feb 10, 2021 · 0 comments
Labels
enhancement New feature or request

Comments

@SDLBugzilla
Copy link
Collaborator

SDLBugzilla commented Feb 10, 2021

This bug report was migrated from our old Bugzilla tracker.

These attachments are available in the static archive:

Reported in version: HG 2.0
Reported for operating system, platform: Mac OS X 10.7, x86_64

Comments on the original bug report:

On 2013-06-27 18:19:20 +0000, (disabled) Jørgen Tjernø wrote:

Created attachment 1200
Add new SDL_GL_GetDrawableSize and SDL_WINDOW_ALLOW_HIGHDPI flag

Currently, there's no way to generate a Retina backing surface on OS X, so that you can render native resolution on retina displays.

I've attached a proposed patch that adds this functionality, via a new SDL_CreateWindow flag (SDL_WINDOW_ALLOW_HIGHDPI), a hint (SDL_HINT_VIDEO_HIGHDPI_DISABLED) and a new API (SDL_GL_GetDrawableSize) that can be used for getting the size for viewports etc.

On 2013-07-06 10:40:46 +0000, Philipp Wiesemann wrote:

s/AppKite/AppKit/

On 2013-07-12 17:01:22 +0000, Ryan C. Gordon wrote:

My Retina MBP already reports 2880x1800 as an available mode in SDL2, and lets me SDL_CreateWindow() at that resolution...does this really not give you a 2880x1800 context?

--ryan.

On 2013-07-12 17:04:01 +0000, (disabled) Jørgen Tjernø wrote:

I believe it does if you're using SDL_WINDOW_FULLSCREEN, Ryan, but not for SDL_WINDOW_FULLSCREEN_DESKTOP or regular windowed mode.

On 2013-07-12 18:58:43 +0000, Ryan C. Gordon wrote:

(In reply to comment # 3)

I believe it does if you're using SDL_WINDOW_FULLSCREEN, Ryan, but not for
SDL_WINDOW_FULLSCREEN_DESKTOP or regular windowed mode.

Oh, hmm, good point.

--ryan.

On 2013-07-13 16:42:12 +0000, Alex Szpakowski wrote:

GLFW did something very similar for its retina support: https://github.com/elmindreda/glfw/pull/36#issuecomment-18849606

I don't think it can really get much better than your implementation, given what's available in Apple's APIs.

As I mentioned on IRC, your SDL_WINDOW_ALLOW_HIGHDPI flag uses the same value as the mask used for SDL_WINDOW_FULLSCREEN_DESKTOP, so WindowFlags of (SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_FULLSCREEN) have an identical value to SDL_WINDOW_FULLSCREEN_DESKTOP.

Also (mentioned on IRC as well), since the mouse coordinates in SDL_MOUSEMOTION events and SDL_GetMouseState/SDL_SetMouseState are integers, the reported mouse position will change once for every 2 real pixels moved in 2x scale highdpi. I discovered that the cursor seems to do this all the time anyway in a retina resolution in OS X, so at least on OS X it's probably not something that can be fixed even with API/ABI changes to SDL.

On 2013-07-19 01:06:37 +0000, Edward Rudd wrote:

Created attachment 1242
Alternate HIDPI support proposal.

My current HIDPI proposal for SDL2..

(not completely finished as it doesn't do any changes to the Renderer APIs yet to support it)

Note that there are some issues that SDL2 in general isn't handling well with this.. Not sure if your patch handles it or not.. But a regular fullscreen mode fails horribly (mode switch) and renders nothing.. and popping back out of fullscreen mode (mode switch) causes the window rendering to be "off" until the window is moved.. (not sure why).

A couple of other things that we need to make sure are handled somehow.. If the user changes their desktop mode to a non-retina resolution the running SDL2 window will "lose" the retina backing.. that needs to be somehow handled and an event somehow sent.

Also, if a user has dual monitors (one retina and one not retina) when they "move" between the monitors the retina backing will turn on and off. Thus the backing store size changes as well..

It's a very "fun" thing to get working 'Cleanly'.

On 2013-07-20 03:35:11 +0000, Sam Lantinga wrote:

High Resolution Guidelines for OS X:
https://developer.apple.com/library/mac/#documentation/GraphicsAnimation/Conceptual/HighResolutionOSX/Introduction/Introduction.html

Writing High-DPI Win32 Applications:
http://msdn.microsoft.com/en-us/library/windows/desktop/dd464660.aspx

On 2013-07-26 20:35:29 +0000, (disabled) Jørgen Tjernø wrote:

Edward, do you have any specific reasons to prefer your patch's approach over mine?

On 2013-07-26 20:43:23 +0000, Edward Rudd wrote:

not necessarily.. I wonder why we need the hint AND the flag? wouldn't just hte SDL_WINDOW_HIDPI flag suffice to request HiDPI? I do prefer my shorter Window flag name though:) Mainly because it's shorter..

The other main thing we need to decide on is exactly HOW we want to get the scaling factor.. e.g. my patch uses GetWindowScale vs your GetDrawableSize.

I know the Apple docs are VERY adamant about always request the API to "Scale" your points (bounds, mouse cursor points etc..).. thus leaning more toward GetDrawableSize being more "correct". Though should we also have a "scale point" type method to adjust some window relative point to the drawable scale?

Also, have you experienced the oddities I documented with my patch? (I'll be getting back to work on this next week and will try out your patch over mine to see if I can recreate them).

I need to sift through MS's docs and see how their philosophy differs from apple's.

On 2013-07-26 20:58:50 +0000, (disabled) Jørgen Tjernø wrote:

The hint and the flag was because people upgrading to newer SDLs might not do the required changes to their glViewport etc calls, and still call SDL_GetWindowSize. This means it's guaranteed to not work until the developer has done the work to support retina.

The hint is to disable retina support, since the developer might enable retina support without having a way of turning it off -- and if that causes performance to be too poor for the end-user, they can force it off (or for the developer to test on lower resolutions).

I personally like us returning the size of the drawable, since that deals with rounding and other weirdness consistently when it comes to non-2.0 scaling factors. The APIs you're passing these values to don't understand floating point, so it should be integer values anyway.

I never tried any of the things that'll cause a retina window to drop down to non-retina runtime. I'm guessing I probably have the same issues you do - but I'd hope we get a "resize" event from the OS when that happens, so we can call glViewport with the new SDL_GetDrawableSize? Have you seen any docs from Apple on how to best handle this when you have an NSOpenGLView/Context?

I haven't done any more work on my patch, since I decided to postpone the work to add retina support to Dota 2 for the time being (due to the required amount of digging around inside the guts of the engine).

On 2013-07-26 21:03:02 +0000, Edward Rudd wrote:

those are some good points.. And yes I did read some docs about how to handle those in apple's docs.. I'll have to dig them up again.. it's been a few weeks since I last played with this.. I had switched focus on that project to getting it ported to from SDL 1.2 to SDL2 and ran into some new issues with touch input and mouse wheel scrolling stuff that I need to push out fixes for first.

I'll post any new docs/updates here though.. so we can figure out the best solution.

On 2013-07-26 22:58:22 +0000, Edward Rudd wrote:

(In reply to comment # 2)

My Retina MBP already reports 2880x1800 as an available mode in SDL2, and
lets me SDL_CreateWindow() at that resolution...does this really not give
you a 2880x1800 context?

--ryan.

Also, when you consider using things like Gamecenter integration you really want to be in a "retina" resolution if you want the hidpi otherwise the overlayed GC UI will appear "very tiny" and the native 2880x1800 resolution...

Retina just makes things "Oh so fun".

On 2013-09-01 07:18:50 +0000, Daniel Bünzli wrote:

Tangentially related it would be nice to have an API to get the physical screen dpi. See e.g.

http://stackoverflow.com/questions/2621439/how-to-get-screen-dpi-linux-mac-programatically

On 2013-09-20 17:46:01 +0000, Edward Rudd wrote:

Created attachment 1333
Updated patch based on Jørgen's patch

This is a rebased patch against tip with a few fixes..

First use a different enum value for the ALLOW_HIGHDPI flag so it doesn't collide with FULLSCREEN_DESKTOP

Second, remove need for extra state variable when the flags can be used..

On 2013-09-28 06:20:58 +0000, Sam Lantinga wrote:

This looks good, thanks guys!

Can one of you add the appropriate documentation to the SDL wiki?

@SDLBugzilla SDLBugzilla added the enhancement New feature or request label Feb 10, 2021
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