Skip to content

Commit

Permalink
Fix DrawPrimarySurface() viewport
Browse files Browse the repository at this point in the history
  • Loading branch information
elishacloud committed Nov 12, 2024
1 parent add8705 commit cc14a3a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Dllmain/BuildNo.rc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#define BUILD_NUMBER 7319
#define BUILD_NUMBER 7320
42 changes: 41 additions & 1 deletion ddraw/IDirectDrawX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4494,7 +4494,47 @@ HRESULT m_IDirectDrawX::DrawPrimarySurface()
d3d9Device->GetViewport(&DrawStates.ViewPort);
D3DSURFACE_DESC Desc = {};
displayTexture->GetLevelDesc(0, &Desc);
D3DVIEWPORT9 ViewPort = { 0, 0, Desc.Width, Desc.Height, 0.0f, 1.0f };
D3DVIEWPORT9 ViewPort = { 0, 0, presParams.BackBufferWidth, presParams.BackBufferHeight, 0.0f, 1.0f };

// Calculate width and height with original aspect ratio
DWORD DisplayBufferWidth = presParams.BackBufferWidth;
DWORD DisplayBufferHeight = presParams.BackBufferHeight;
DWORD TexWidth = Desc.Width;
DWORD TexHeight = Desc.Height;
if (Config.DdrawIntegerScalingClamp)
{
DWORD xScaleRatio = DisplayBufferWidth / TexWidth;
DWORD yScaleRatio = DisplayBufferHeight / TexHeight;

if (Config.DdrawMaintainAspectRatio)
{
xScaleRatio = min(xScaleRatio, yScaleRatio);
yScaleRatio = min(xScaleRatio, yScaleRatio);
}

ViewPort.Width = xScaleRatio * TexWidth;
ViewPort.Height = yScaleRatio * TexHeight;

ViewPort.X = (DisplayBufferWidth - ViewPort.Width) / 2;
ViewPort.Y = (DisplayBufferHeight - ViewPort.Height) / 2;
}
else if (Config.DdrawMaintainAspectRatio)
{
if (TexWidth * DisplayBufferHeight < TexHeight * DisplayBufferWidth)
{
// 4:3 displayed on 16:9
ViewPort.Width = DisplayBufferHeight * TexWidth / TexHeight;
}
else
{
// 16:9 displayed on 4:3
ViewPort.Height = DisplayBufferWidth * TexHeight / TexWidth;
}
ViewPort.X = (DisplayBufferWidth - ViewPort.Width) / 2;
ViewPort.Y = (DisplayBufferHeight - ViewPort.Height) / 2;
}

// Set the viewport with the calculated values
d3d9Device->SetViewport(&ViewPort);

// Trasform
Expand Down

0 comments on commit cc14a3a

Please sign in to comment.