From 92c48784924d99c3df5c1dd394eb54e2fab561b6 Mon Sep 17 00:00:00 2001 From: elasota Date: Sun, 26 Apr 2020 01:56:55 -0400 Subject: [PATCH] Fix scaling behavior when the window size doesn't divide evenly into the pixel scale --- GpDisplayDriver_D3D11/GpDisplayDriverD3D11.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/GpDisplayDriver_D3D11/GpDisplayDriverD3D11.cpp b/GpDisplayDriver_D3D11/GpDisplayDriverD3D11.cpp index f31fa1d..e31f343 100644 --- a/GpDisplayDriver_D3D11/GpDisplayDriverD3D11.cpp +++ b/GpDisplayDriver_D3D11/GpDisplayDriverD3D11.cpp @@ -631,11 +631,15 @@ void GpDisplayDriverD3D11::ScaleVirtualScreen() const float twoDivWidth = 2.0f / static_cast(m_windowWidthPhysical); const float negativeTwoDivHeight = -2.0f / static_cast(m_windowHeightPhysical); + // Use the scaled virtual width instead of the physical width to correctly handle cases where the window boundary is in the middle of a pixel + float fWidth = static_cast(m_windowWidthVirtual) * m_pixelScaleX; + float fHeight = static_cast(m_windowHeightVirtual) * m_pixelScaleY; + DrawQuadVertexConstants vConstantsData; - vConstantsData.m_ndcOriginX = -1.0f; - vConstantsData.m_ndcOriginY = 1.0f; - vConstantsData.m_ndcWidth = 2.0f; - vConstantsData.m_ndcHeight = -2.0f; + vConstantsData.m_ndcOriginX = twoDivWidth - 1.0f; + vConstantsData.m_ndcOriginY = negativeTwoDivHeight + 1.0f; + vConstantsData.m_ndcWidth = fWidth * twoDivWidth; + vConstantsData.m_ndcHeight = fHeight * negativeTwoDivHeight; vConstantsData.m_surfaceDimensionX = static_cast(m_windowWidthVirtual); vConstantsData.m_surfaceDimensionY = static_cast(m_windowHeightVirtual);