-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix minimized window raw client size handling #3230
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -196,25 +196,28 @@ protected override void Destroy() | |
| /// <summary> | ||
| /// Determines the requested size for the Back-Buffer based on the current window bounds and user preferences. | ||
| /// </summary> | ||
| /// <param name="size"> | ||
| /// When this method returns, contains the requested size for the Back-Buffer. | ||
| /// </param> | ||
| /// <param name="format"> | ||
| /// When this method returns, contains the pixel format to be used for the Back-Buffer. | ||
| /// This will be the preferred Back-Buffer format if specified; | ||
| /// otherwise, it defaults to <see cref="PixelFormat.R8G8B8A8_UNorm"/>. | ||
| /// </param> | ||
| /// <returns> | ||
| /// An <see cref="Int2"/> structure representing the width and height of the requested Back-Buffer size. | ||
| /// If the preferred Back-Buffer dimensions are not set or the window has been resized by the user, | ||
| /// the current window dimensions are used. | ||
| /// <see langword="true"/> when a valid requested size could be determined; otherwise, <see langword="false"/>. | ||
| /// </returns> | ||
| private Int2 GetRequestedSize(out PixelFormat format) | ||
|
Comment on lines
-205
to
-209
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you are changing the return type and transforming it into an |
||
| private bool TryGetRequestedSize(out Int2 size, out PixelFormat format) | ||
| { | ||
| var bounds = Window.ClientBounds; | ||
| var rawClientSize = Window.RawClientSize; | ||
|
|
||
| format = PreferredBackBufferFormat == PixelFormat.None ? PixelFormat.R8G8B8A8_UNorm : PreferredBackBufferFormat; | ||
|
|
||
| return new Int2( | ||
| PreferredBackBufferWidth == 0 || windowUserResized ? bounds.Width : PreferredBackBufferWidth, | ||
| PreferredBackBufferHeight == 0 || windowUserResized ? bounds.Height : PreferredBackBufferHeight); | ||
| size = new Int2( | ||
| PreferredBackBufferWidth == 0 || windowUserResized ? rawClientSize.X : PreferredBackBufferWidth, | ||
| PreferredBackBufferHeight == 0 || windowUserResized ? rawClientSize.Y : PreferredBackBufferHeight); | ||
|
|
||
| return size.X > 0 && size.Y > 0; | ||
| } | ||
|
|
||
| /// <summary> | ||
|
|
@@ -225,11 +228,18 @@ private Int2 GetRequestedSize(out PixelFormat format) | |
| /// using the requested size and format. It configures the presentation parameters, | ||
| /// including Depth-Stencil format and presentation interval. | ||
| /// </remarks> | ||
| protected virtual void CreateOrUpdatePresenter() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The new |
||
| /// <returns> | ||
| /// <see langword="true"/> when the presenter exists or could be created; otherwise, <see langword="false"/>. | ||
| /// </returns> | ||
| protected virtual bool CreateOrUpdatePresenter() | ||
| { | ||
| if (Presenter is null || isColorSpaceToChange) | ||
| { | ||
| var size = GetRequestedSize(out PixelFormat resizeFormat); | ||
| if (!TryGetRequestedSize(out var size, out PixelFormat resizeFormat)) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| var presentationParameters = new PresentationParameters(size.X, size.Y, Window.NativeWindow, resizeFormat) | ||
| { | ||
| DepthStencilFormat = PreferredDepthStencilFormat, | ||
|
|
@@ -251,6 +261,8 @@ protected virtual void CreateOrUpdatePresenter() | |
| isBackBufferToResize = false; | ||
| isColorSpaceToChange = false; | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| /// <inheritdoc/> | ||
|
|
@@ -260,11 +272,20 @@ public override bool BeginDraw() | |
| { | ||
| savedPresenter = GraphicsDevice.Presenter; | ||
|
|
||
| CreateOrUpdatePresenter(); | ||
| if (!CreateOrUpdatePresenter()) | ||
| { | ||
| beginDrawOk = false; | ||
| return false; | ||
| } | ||
|
|
||
| if (isBackBufferToResize || windowUserResized) | ||
| { | ||
| var size = GetRequestedSize(out PixelFormat resizeFormat); | ||
| if (!TryGetRequestedSize(out var size, out PixelFormat resizeFormat)) | ||
| { | ||
| beginDrawOk = false; | ||
| return false; | ||
| } | ||
|
|
||
| Presenter.Resize(size.X, size.Y, resizeFormat); | ||
|
|
||
| isBackBufferToResize = false; | ||
|
|
||
This comment was marked as resolved.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.