Skip to content

Commit

Permalink
Add depthfill Blt() support
Browse files Browse the repository at this point in the history
  • Loading branch information
elishacloud committed Apr 18, 2024
1 parent 606800c commit 7e4007e
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 10 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 7000
#define BUILD_NUMBER 7001
4 changes: 4 additions & 0 deletions d3d9/IDirect3DDevice9Ex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,8 @@ HRESULT m_IDirect3DDevice9Ex::SetPixelShader(THIS_ IDirect3DPixelShader9* pShade

HRESULT m_IDirect3DDevice9Ex::Present(CONST RECT *pSourceRect, CONST RECT *pDestRect, HWND hDestWindowOverride, CONST RGNDATA *pDirtyRegion)
{
__asm { fninit } // Reset FPU before presenting

Logging::LogDebug() << __FUNCTION__ << " (" << this << ")";

HRESULT hr = ProxyInterface->Present(pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);
Expand Down Expand Up @@ -2078,6 +2080,8 @@ HRESULT m_IDirect3DDevice9Ex::ComposeRects(THIS_ IDirect3DSurface9* pSrc, IDirec

HRESULT m_IDirect3DDevice9Ex::PresentEx(THIS_ CONST RECT* pSourceRect, CONST RECT* pDestRect, HWND hDestWindowOverride, CONST RGNDATA* pDirtyRegion, DWORD dwFlags)
{
__asm { fninit } // Reset FPU before presenting

Logging::LogDebug() << __FUNCTION__ << " (" << this << ")";

if (!ProxyInterfaceEx)
Expand Down
19 changes: 12 additions & 7 deletions ddraw/IDirectDrawSurfaceX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -465,13 +465,6 @@ HRESULT m_IDirectDrawSurfaceX::Blt(LPRECT lpDestRect, LPDIRECTDRAWSURFACE7 lpDDS
return DDERR_INVALIDPARAMS;
}

// Check for depth fill flag
if (dwFlags & DDBLT_DEPTHFILL)
{
LOG_LIMIT(100, __FUNCTION__ << " Error: Depth Fill Not Implemented");
return DDERR_NOZBUFFERHW;
}

// Check for rotation flags
// ToDo: add support for other rotation flags (90,180, 270). Not sure if any game uses these other flags.
if ((dwFlags & DDBLT_ROTATIONANGLE) || ((dwFlags & DDBLT_DDFX) && (lpDDBltFx->dwDDFX & (DDBLTFX_ROTATE90 | DDBLTFX_ROTATE180 | DDBLTFX_ROTATE270))))
Expand Down Expand Up @@ -520,6 +513,18 @@ HRESULT m_IDirectDrawSurfaceX::Blt(LPRECT lpDestRect, LPDIRECTDRAWSURFACE7 lpDDS
return (c_hr == DDERR_SURFACELOST || s_hr == DDERR_SURFACELOST) ? DDERR_SURFACELOST : FAILED(c_hr) ? c_hr : s_hr;
}

// Clear the depth stencil surface
if (dwFlags & DDBLT_DEPTHFILL)
{
// ToDo: check surface is stencil is the currently used stencil
if (!(surfaceDesc2.ddpfPixelFormat.dwFlags & DDPF_ZBUFFER))
{
LOG_LIMIT(100, __FUNCTION__ << " Error: not Depth Stencil format: " << surfaceDesc2);
return DDERR_INVALIDPARAMS;
}
return (*d3d9Device)->Clear(0, NULL, D3DCLEAR_ZBUFFER, 0, ConvertDepthValue(lpDDBltFx->dwFillDepth, surfaceFormat), 0);
}

// Set critical section
SetLockCriticalSection();
lpDDSrcSurfaceX->SetLockCriticalSection();
Expand Down
42 changes: 40 additions & 2 deletions ddraw/IDirectDrawTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ void ConvertCaps(DDCAPS &Caps7, D3DCAPS9 &Caps9)
(DDCAPS_BLT | /*DDCAPS_BLTQUEUE |*/ DDCAPS_BLTFOURCC | DDCAPS_BLTSTRETCH | DDCAPS_GDI /*| DDCAPS_OVERLAYCANTCLIP | DDCAPS_OVERLAYFOURCC |
DDCAPS_OVERLAYSTRETCH*/ | DDCAPS_PALETTE | DDCAPS_PALETTEVSYNC | DDCAPS_VBI | DDCAPS_COLORKEY | /*DDCAPS_ALPHA | DDCAPS_COLORKEYHWASSIST |*/
DDCAPS_BLTCOLORFILL | DDCAPS_CANCLIP | DDCAPS_CANCLIPSTRETCHED | DDCAPS_CANBLTSYSMEM) |
(!Config.DdrawDisableDirect3DCaps ? DDCAPS_3D /*| DDCAPS_BLTDEPTHFILL | DDCAPS_ZBLTS | DDCAPS_ZOVERLAYS*/ : 0);
(!Config.DdrawDisableDirect3DCaps ? DDCAPS_3D | DDCAPS_BLTDEPTHFILL /*| DDCAPS_ZBLTS | DDCAPS_ZOVERLAYS*/ : 0);
Caps7.dwCaps2 = (Caps9.Caps2 & (D3DCAPS2_FULLSCREENGAMMA /*| D3DCAPS2_CANCALIBRATEGAMMA*/ | D3DCAPS2_CANMANAGERESOURCE | D3DCAPS2_DYNAMICTEXTURES /*| D3DCAPS2_CANAUTOGENMIPMAP | D3DCAPS2_CANSHARERESOURCE*/)) |
(/*DDCAPS2_CANBOBINTERLEAVED | DDCAPS2_CANBOBNONINTERLEAVED | DDCAPS2_NONLOCALVIDMEM |*/ DDCAPS2_WIDESURFACES | /*DDCAPS2_CANFLIPODDEVEN |*/ DDCAPS2_COPYFOURCC | DDCAPS2_NOPAGELOCKREQUIRED |
DDCAPS2_PRIMARYGAMMA | DDCAPS2_CANRENDERWINDOWED /*| DDCAPS2_FLIPINTERVAL*/ | DDCAPS2_FLIPNOVSYNC);
Expand Down Expand Up @@ -445,11 +445,49 @@ DWORD GetBitCount(D3DFORMAT Format)
return 8;

default:
LOG_LIMIT(100, __FUNCTION__ << " Display format not Implemented: " << Format);
LOG_LIMIT(100, __FUNCTION__ << " Error: Display format not Implemented: " << Format);
return 0;
};
}

float ConvertDepthValue(DWORD dwFillDepth, D3DFORMAT Format)
{
switch ((DWORD)Format)
{
case D3DFMT_S1D15:
return static_cast<float>(dwFillDepth & 0x7FFF) / 0x7FFF; // 15-bit depth

case D3DFMT_D15S1:
// Shift the depth value to the right by 1 bits before extracting
return static_cast<float>((dwFillDepth >> 1) & 0x7FFF) / 0x7FFF; // 15-bit depth

case D3DFMT_D16:
case D3DFMT_D16_LOCKABLE:
return static_cast<float>(dwFillDepth & 0xFFFF) / 0xFFFF; // 16-bit depth

case D3DFMT_X8D24:
case D3DFMT_S8D24:
case D3DFMT_X4S4D24:
return static_cast<float>(dwFillDepth & 0xFFFFFF) / 0xFFFFFF; // 24-bit depth

case D3DFMT_D24X8:
case D3DFMT_D24S8:
case D3DFMT_D24FS8:
case D3DFMT_D24X4S4:
// Shift the depth value to the right by 8 bits before extracting
return static_cast<float>((dwFillDepth >> 8) & 0xFFFFFF) / 0xFFFFFF; // 24-bit depth

case D3DFMT_D32:
case D3DFMT_D32_LOCKABLE:
case D3DFMT_D32F_LOCKABLE:
return (float)(static_cast<double>(dwFillDepth & 0xFFFFFFFF) / 0xFFFFFFFF); // 32-bit depth

default:
LOG_LIMIT(100, __FUNCTION__ << " Error: Depth Stencil format not Implemented: " << Format);
return 0.0f;
}
}

DWORD GetSurfaceSize(D3DFORMAT Format, DWORD Width, DWORD Height, INT Pitch)
{
if (ISDXTEX(Format))
Expand Down
1 change: 1 addition & 0 deletions ddraw/IDirectDrawTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ void ConvertCaps(DDCAPS &Caps7, D3DCAPS9 &Caps9);
DWORD GetByteAlignedWidth(DWORD Width, DWORD BitCount);
DWORD GetBitCount(DDPIXELFORMAT ddpfPixelFormat);
DWORD GetBitCount(D3DFORMAT Format);
float ConvertDepthValue(DWORD dwFillDepth, D3DFORMAT Format);
DWORD GetSurfaceSize(D3DFORMAT Format, DWORD Width, DWORD Height, INT Pitch);
void GetColorKeyArray(float(&lowColorKey)[4], float(&highColorKey)[4], DWORD lowColorSpace, DWORD highColorSpace, DDPIXELFORMAT& pixelFormat);
D3DFORMAT ConvertSurfaceFormat(D3DFORMAT Format);
Expand Down

0 comments on commit 7e4007e

Please sign in to comment.