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

Assorted SDL improvements #4927

Closed
wants to merge 4 commits into from

Conversation

Clownacy
Copy link
Contributor

@Clownacy Clownacy commented Jan 22, 2022

No description provided.

This is (kind of) an OpenGL-only function, which should be avoided
when SDL2 isn't using OpenGL.

The only alternative that is recommended is
SDL_GetRendererOutputSize, which limits this fix to the SDL_Renderer
backend. Still, I think it's better than nothing.

I say that SDL_GL_GetDrawableSize is "kind of" OpenGL-only because it
does technically work even when SDL2 isn't using OpenGL. It's just
that it becomes a shim to SDL_GetWindowSize, which is not suitable
for high-DPI usage because it reflects the size of the window in
screen coordinates, not actual pixels, so it really should be avoided
when not using OpenGL.
@Clownacy Clownacy changed the title Avoiding using SDL_GL_GetDrawableSize Assorted SDL improvements Jan 22, 2022
@ocornut
Copy link
Owner

ocornut commented Jan 24, 2022

Hello,

Thank you for the PR.

  • I don't think using SDL_memset etc are required nor provide any extra value, could you undo that and squash?
  • For calls to SDL_Renderer functions in SDL.h you would need to check the compatible SDL version. If the function was introduced after SDL 2.0.4 it needs appropriate ifdef.
  • I think we need a general solution for situation where neither SDL_Renderer neither OpenGL are used.

@Clownacy
Copy link
Contributor Author

Clownacy commented Jan 24, 2022

Thanks for the feedback! I'm not at a PC right now to make any changes, but I can respond to a few things here:

I think the point of the SDL libc functions is to support platforms that don't have an adequate C standard library, or to avoid having the user's program become dependent on said library. An instance I saw where the libc replacement functions were recommended was for avoiding a dependency on a particular version of msvcr###.dll. Though, if Dear ImGui itself uses libc functions directly without any way of shimming them, then I guess using the SDL libc functions really is pointless.

According to its documentation, SDL_GetRendererOutputSize was introduced in SDL 2.0.0, so I don't think it needs an ifdef.

I'm not sure what can be done to add a general solution for when neither SDL_Renderer nor OpenGL are being used. I think that would have to be tackled in a separate PR by someone else.

@Clownacy
Copy link
Contributor Author

The SDL libc commit has been reverted. Sorry for the delay.

SDL_PIXELFORMAT_RGBA32 is intended for byte arrays where the channels
are specifically in the RGBA order. However, this is not what
GetTexDataAsRGBA32 does: rather, it constructs an array where each
pixel is an unsigned int in ABGR order. On little-endian platforms,
this does indeed result in an RGBA byte order, however, on big-endian
platforms, this results in an ABGR byte order, which does not match
the PIXELFORMAT enum.

What should be used is the SDL_PIXELFORMAT_ABGR8888 enum, which
specifies that the pixels are in native-endian ABGR, which they are.
`SDL_WINDOW_OPENGL` is only necessary when using OpenGL directly,
bypassing SDL2's Renderer API. There's a similar flag for doing the
same with Vulkan - `SDL_WINDOW_VULKAN`.

I imagine that this flag was used because of the SDL backend's
dependency on an OpenGL-specific function, but that has been
eliminated as of ccf4c24.
ocornut pushed a commit that referenced this pull request Feb 4, 2022
…re (#4927)

SDL_PIXELFORMAT_RGBA32 is intended for byte arrays where the channels
are specifically in the RGBA order. However, this is not what
GetTexDataAsRGBA32 does: rather, it constructs an array where each
pixel is an unsigned int in ABGR order. On little-endian platforms,
this does indeed result in an RGBA byte order, however, on big-endian
platforms, this results in an ABGR byte order, which does not match
the PIXELFORMAT enum.

What should be used is the SDL_PIXELFORMAT_ABGR8888 enum, which
specifies that the pixels are in native-endian ABGR, which they are.
ocornut pushed a commit that referenced this pull request Feb 4, 2022
…rSDLRenderer(). Use SDL_GetRendererOutputSize() instead of SDL_GL_GetDrawableSize() when bound to a SDL_Renderer. (#4927)

This is (kind of) an OpenGL-only function, which should be avoided when SDL2 isn't using OpenGL.
The only alternative that is recommended is SDL_GetRendererOutputSize, which limits this fix to the SDL_Renderer backend. Still, I think it's better than nothing.
I say that SDL_GL_GetDrawableSize is "kind of" OpenGL-only because it does technically work even when SDL2 isn't using OpenGL.
It's just that it becomes a shim to SDL_GetWindowSize, which is not suitable for high-DPI usage because it reflects the size of the window in screen coordinates, not actual pixels, so it really should be avoided when not using OpenGL.
@ocornut
Copy link
Owner

ocornut commented Feb 4, 2022

Thank you !
Now merged as c39192b and c6cab1f

@ocornut ocornut closed this Feb 4, 2022
sergeyn pushed a commit to sergeyn/imgui that referenced this pull request Mar 19, 2022
…re (ocornut#4927)

SDL_PIXELFORMAT_RGBA32 is intended for byte arrays where the channels
are specifically in the RGBA order. However, this is not what
GetTexDataAsRGBA32 does: rather, it constructs an array where each
pixel is an unsigned int in ABGR order. On little-endian platforms,
this does indeed result in an RGBA byte order, however, on big-endian
platforms, this results in an ABGR byte order, which does not match
the PIXELFORMAT enum.

What should be used is the SDL_PIXELFORMAT_ABGR8888 enum, which
specifies that the pixels are in native-endian ABGR, which they are.
sergeyn pushed a commit to sergeyn/imgui that referenced this pull request Mar 19, 2022
…rSDLRenderer(). Use SDL_GetRendererOutputSize() instead of SDL_GL_GetDrawableSize() when bound to a SDL_Renderer. (ocornut#4927)

This is (kind of) an OpenGL-only function, which should be avoided when SDL2 isn't using OpenGL.
The only alternative that is recommended is SDL_GetRendererOutputSize, which limits this fix to the SDL_Renderer backend. Still, I think it's better than nothing.
I say that SDL_GL_GetDrawableSize is "kind of" OpenGL-only because it does technically work even when SDL2 isn't using OpenGL.
It's just that it becomes a shim to SDL_GetWindowSize, which is not suitable for high-DPI usage because it reflects the size of the window in screen coordinates, not actual pixels, so it really should be avoided when not using OpenGL.
ocornut added a commit that referenced this pull request Apr 7, 2022
… + Backends: SDL_Renderer: Explicitely call SDL_SetTextureScaleMode(). (#4927)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants