Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix else branch of chooseSwapExtent for HDPI/retina displays#210

Merged
Overv merged 3 commits intoOverv:masterfrom
maltekliemann:fix/hdpi-swapchain-extent
Oct 27, 2020
Merged

Fix else branch of chooseSwapExtent for HDPI/retina displays#210
Overv merged 3 commits intoOverv:masterfrom
maltekliemann:fix/hdpi-swapchain-extent

Conversation

@maltekliemann
Copy link
Copy Markdown
Contributor

When using an HDPI display, using the window size {WIDTH, HEIGHT} to determine swapchain image size is incorrect. See the following links:

Short version: The window size in GLFW is specified in screen coordinates, but Vulkan requires the swapchain image extent to be specified in pixel. On HDPI displays, these are not the same thing.

Instead, the framebuffer size is now used to determine the swapchain extent. Using the implementation of chooseSwapExtent from 16_swap_chain_recreation.cpp seemed appropriate. Beyond "Swap chain recreation" no changes are necessary.

I'm a little bit suprised that this hasn't been an issue for anyone. I'm using macOS, and my app doesn't enter the else branch, so I don't experience any problems either (Vulkan automatically suggests doubled width and height). The specification doesn't seem to say when width == UINT32_MAX occurs.

When using an HDPI display, using the window size `{WIDTH, HEIGHT}` to
determine swapchain image size is incorrect. See the following links:

* https://www.glfw.org/docs/latest/window.html#window_size
* https://www.glfw.org/docs/latest/window.html#window_fbsize
* https://www.glfw.org/faq.html#43---why-is-my-output-in-the-lower-left-corner-of-the-window

Instead, the framebuffer size is now used to determine the swapchain
extent. Using the implementation of `chooseSwapExtent` from
`16_swap_chain_recreation.cpp` seemed appropriate. Beyond "Swap chain
recreation" no changes are necessary.
@maltekliemann
Copy link
Copy Markdown
Contributor Author

The tutorial is now changed accordingly. I've tried to keep the explanation of the problem as short as possible. I don't know if there is a more elegant solution for this problem. glfwGetFramebufferSize is now shoved in a bit awkwardly, instead of being introduced naturally during Swap chain recreation.

When I write "GLFW uses two units when measuring sizes: pixels and screen coordinates [...]", that's a bit of a lie. There are other measurements, but these are the two that count.

@Overv
Copy link
Copy Markdown
Owner

Overv commented Oct 10, 2020

Could you elaborate on the changes besides glfwGetFramebufferSize?

@maltekliemann maltekliemann force-pushed the fix/hdpi-swapchain-extent branch from c53a03e to f0f4207 Compare October 11, 2020 08:16
@maltekliemann
Copy link
Copy Markdown
Contributor Author

maltekliemann commented Oct 11, 2020

My bad, I was careless when I pushed that. Sorry! :(

I've amended the commit. Now it should only contain changes relevant to swapchain extent.

@Overv Overv merged commit 4ece62e into Overv:master Oct 27, 2020
@Overv
Copy link
Copy Markdown
Owner

Overv commented Oct 27, 2020

Apologies for not getting back to this sooner, thanks for the work! 👍

@maltekliemann
Copy link
Copy Markdown
Contributor Author

Not to worry! Thanks for the tutorial! :)

Overv added a commit that referenced this pull request Mar 8, 2023
Fix else branch of chooseSwapExtent for HDPI/retina displays
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants