From 236e9c27c727db734ff46f519af39c70d44ec338 Mon Sep 17 00:00:00 2001 From: David Svez Date: Sat, 1 Aug 2026 20:15:18 -0500 Subject: [PATCH] Window live resize + second monitor High DPI support without turning black --- .../Engine/Platform/Windows/WindowsWindow.cpp | 38 ++++++++++++------- .../Engine/Platform/Windows/WindowsWindow.h | 3 +- Source/Engine/Renderer/PostProcessingPass.cpp | 3 +- 3 files changed, 29 insertions(+), 15 deletions(-) diff --git a/Source/Engine/Platform/Windows/WindowsWindow.cpp b/Source/Engine/Platform/Windows/WindowsWindow.cpp index bd682c7c1..7a6f53507 100644 --- a/Source/Engine/Platform/Windows/WindowsWindow.cpp +++ b/Source/Engine/Platform/Windows/WindowsWindow.cpp @@ -5,7 +5,7 @@ #include "WindowsWindow.h" #include "WindowsPlatform.h" #include "WindowsInput.h" -#include "Engine/Core/Log.h" +#include "Engine/Engine/Engine.h" #include "Engine/Core/Math/Math.h" #include "Engine/Graphics/GPUSwapChain.h" #include "Engine/Graphics/RenderTask.h" @@ -731,7 +731,7 @@ void WindowsWindow::SetCursor(CursorType type) UpdateCursor(); } -void WindowsWindow::CheckForWindowResize() +void WindowsWindow::CheckForWindowResize(bool force) { // Skip for minimized window (GetClientRect for minimized window returns 0) if (_minimized) @@ -766,7 +766,7 @@ void WindowsWindow::CheckForWindowResize() _clientSize = Float2(static_cast(width), static_cast(height)); // Check if window size has been changed - if (width > 0 && height > 0 && (_swapChain == nullptr || width != _swapChain->GetWidth() || height != _swapChain->GetHeight())) + if (width > 0 && height > 0 && (force || _swapChain == nullptr || width != _swapChain->GetWidth() || height != _swapChain->GetHeight())) { UpdateRegion(); OnResize(width, height); @@ -919,16 +919,24 @@ LRESULT WindowsWindow::WndProc(UINT msg, WPARAM wParam, LPARAM lParam) case WM_PAINT: { // Check if window is during resizing - if (_isResizing && _swapChain) + if ((_isResizing || _forceRedrawOnPaint) && _swapChain) { - // Redraw window backbuffer on DX11 - switch (GPUDevice::Instance->GetRendererType()) + _forceRedrawOnPaint = false; + if (GPUDevice::Instance && !GPUDevice::Instance->IsRendering() && GPUDevice::Instance->CanDraw()) { - case RendererType::DirectX10: - case RendererType::DirectX10_1: - case RendererType::DirectX11: - _swapChain->Present(false); - break; + Engine::OnDraw(); + } + else if (GPUDevice::Instance) + { + // Redraw window backbuffer on DX11 + switch (GPUDevice::Instance->GetRendererType()) + { + case RendererType::DirectX10: + case RendererType::DirectX10_1: + case RendererType::DirectX11: + _swapChain->Present(false); + break; + } } } break; @@ -1228,8 +1236,8 @@ LRESULT WindowsWindow::WndProc(UINT msg, WPARAM wParam, LPARAM lParam) else if (_isResizing) { // If we're neither maximized nor minimized, the window size is changing by the user dragging the window edges. - // In this case, we don't resize yet -- we wait until the user stops dragging, and a WM_EXITSIZEMOVE message comes. - UpdateRegion(); + CheckForWindowResize(); + RedrawWindow(_handle, nullptr, nullptr, RDW_INVALIDATE | RDW_UPDATENOW); } else if (_isSwitchingFullScreen) { @@ -1251,6 +1259,10 @@ LRESULT WindowsWindow::WndProc(UINT msg, WPARAM wParam, LPARAM lParam) _dpiScale = (float)_dpi / (float)DefaultDPI; RECT* windowRect = (RECT*)lParam; SetWindowPos(_handle, nullptr, windowRect->left, windowRect->top, windowRect->right - windowRect->left, windowRect->bottom - windowRect->top, SWP_NOZORDER | SWP_NOACTIVATE); + CheckForWindowResize(true); + UpdateRegion(); + _forceRedrawOnPaint = true; + RedrawWindow(_handle, nullptr, nullptr, RDW_INVALIDATE | RDW_UPDATENOW); // TODO: Recalculate fonts return 0; } diff --git a/Source/Engine/Platform/Windows/WindowsWindow.h b/Source/Engine/Platform/Windows/WindowsWindow.h index 7055f641e..2a3da4cdb 100644 --- a/Source/Engine/Platform/Windows/WindowsWindow.h +++ b/Source/Engine/Platform/Windows/WindowsWindow.h @@ -25,6 +25,7 @@ private: Windows::ULONG _refCount; #endif bool _isResizing = false; + bool _forceRedrawOnPaint = false; bool _isSwitchingFullScreen = false; bool _trackingMouse = false; bool _clipCursorSet = false; @@ -92,7 +93,7 @@ public: private: - void CheckForWindowResize(); + void CheckForWindowResize(bool force = false); void UpdateCursor(); void UpdateRegion(); diff --git a/Source/Engine/Renderer/PostProcessingPass.cpp b/Source/Engine/Renderer/PostProcessingPass.cpp index 206087303..db21c04d7 100644 --- a/Source/Engine/Renderer/PostProcessingPass.cpp +++ b/Source/Engine/Renderer/PostProcessingPass.cpp @@ -273,6 +273,7 @@ void PostProcessingPass::Render(RenderContext& renderContext, GPUTexture* input, int32 h4 = h2 >> 1; int32 h8 = h4 >> 1; int32 bloomMipCount = CalculateBloomMipCount(w1, h1); + useLensFlares &= bloomMipCount > 1; // Ensure to have valid data and if at least one effect should be applied if (!(useBloom || useToneMapping || useCameraArtifacts || colorGradingLUT) || checkIfSkipPass() || w8 <= 1 || h8 <= 1) @@ -450,7 +451,7 @@ void PostProcessingPass::Render(RenderContext& renderContext, GPUTexture* input, // Set bloom output context->UnBindSR(0); context->UnBindSR(1); - context->BindSR(2, bloomBuffer2->View(0, 0)); + context->BindSR(2, (bloomMipCount > 1 ? bloomBuffer2 : bloomBuffer1)->View(0, 0)); } else {