Skip to content

Commit

Permalink
Update types formatting and add RGB surface check
Browse files Browse the repository at this point in the history
  • Loading branch information
elishacloud committed Dec 9, 2024
1 parent 85766f7 commit b110ddd
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 99 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 7368
#define BUILD_NUMBER 7369
28 changes: 14 additions & 14 deletions ddraw/IDirect3DTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#include "ddraw.h"

void ConvertLight(D3DLIGHT7& Light7, D3DLIGHT& Light)
void ConvertLight(D3DLIGHT7& Light7, const D3DLIGHT& Light)
{
if (Light.dwSize != sizeof(D3DLIGHT) && Light.dwSize != sizeof(D3DLIGHT2))
{
Expand Down Expand Up @@ -48,7 +48,7 @@ void ConvertLight(D3DLIGHT7& Light7, D3DLIGHT& Light)
}
}

void ConvertMaterial(D3DMATERIAL& Material, D3DMATERIAL7& Material7)
void ConvertMaterial(D3DMATERIAL& Material, const D3DMATERIAL7& Material7)
{
if (Material.dwSize != sizeof(D3DMATERIAL))
{
Expand All @@ -64,7 +64,7 @@ void ConvertMaterial(D3DMATERIAL& Material, D3DMATERIAL7& Material7)
Material.dwRampSize = 0;
}

void ConvertMaterial(D3DMATERIAL7 &Material7, D3DMATERIAL &Material)
void ConvertMaterial(D3DMATERIAL7& Material7, const D3DMATERIAL& Material)
{
if (Material.dwSize != sizeof(D3DMATERIAL))
{
Expand All @@ -78,7 +78,7 @@ void ConvertMaterial(D3DMATERIAL7 &Material7, D3DMATERIAL &Material)
Material7.dvPower = Material.dvPower;
}

void ConvertViewport(D3DVIEWPORT &ViewPort, D3DVIEWPORT2 &ViewPort2)
void ConvertViewport(D3DVIEWPORT& ViewPort, const D3DVIEWPORT2& ViewPort2)
{
if (ViewPort.dwSize != sizeof(D3DVIEWPORT) || ViewPort2.dwSize != sizeof(D3DVIEWPORT2))
{
Expand All @@ -99,7 +99,7 @@ void ConvertViewport(D3DVIEWPORT &ViewPort, D3DVIEWPORT2 &ViewPort2)
ViewPort.dvMaxY = 0; /* Min/max homogeneous y coord */
}

void ConvertViewport(D3DVIEWPORT2 &ViewPort2, D3DVIEWPORT &ViewPort)
void ConvertViewport(D3DVIEWPORT2& ViewPort2, const D3DVIEWPORT& ViewPort)
{
if (ViewPort2.dwSize != sizeof(D3DVIEWPORT2) || ViewPort.dwSize != sizeof(D3DVIEWPORT))
{
Expand All @@ -120,7 +120,7 @@ void ConvertViewport(D3DVIEWPORT2 &ViewPort2, D3DVIEWPORT &ViewPort)
ViewPort2.dvClipHeight = 0;
}

void ConvertViewport(D3DVIEWPORT &ViewPort, D3DVIEWPORT7 &ViewPort7)
void ConvertViewport(D3DVIEWPORT& ViewPort, const D3DVIEWPORT7& ViewPort7)
{
if (ViewPort.dwSize != sizeof(D3DVIEWPORT))
{
Expand All @@ -141,7 +141,7 @@ void ConvertViewport(D3DVIEWPORT &ViewPort, D3DVIEWPORT7 &ViewPort7)
ViewPort.dvMaxY = 0; /* Min/max homogeneous y coord */
}

void ConvertViewport(D3DVIEWPORT2 &ViewPort2, D3DVIEWPORT7 &ViewPort7)
void ConvertViewport(D3DVIEWPORT2& ViewPort2, const D3DVIEWPORT7& ViewPort7)
{
if (ViewPort2.dwSize != sizeof(D3DVIEWPORT2))
{
Expand All @@ -162,7 +162,7 @@ void ConvertViewport(D3DVIEWPORT2 &ViewPort2, D3DVIEWPORT7 &ViewPort7)
ViewPort2.dvClipHeight = 0;
}

void ConvertViewport(D3DVIEWPORT7 &ViewPort7, D3DVIEWPORT &ViewPort)
void ConvertViewport(D3DVIEWPORT7& ViewPort7, const D3DVIEWPORT& ViewPort)
{
if (ViewPort.dwSize != sizeof(D3DVIEWPORT))
{
Expand All @@ -178,7 +178,7 @@ void ConvertViewport(D3DVIEWPORT7 &ViewPort7, D3DVIEWPORT &ViewPort)
ViewPort7.dvMaxZ = ViewPort.dvMaxZ;
}

void ConvertViewport(D3DVIEWPORT7 &ViewPort7, D3DVIEWPORT2 &ViewPort2)
void ConvertViewport(D3DVIEWPORT7& ViewPort7, const D3DVIEWPORT2& ViewPort2)
{
if (ViewPort2.dwSize != sizeof(D3DVIEWPORT2))
{
Expand All @@ -194,7 +194,7 @@ void ConvertViewport(D3DVIEWPORT7 &ViewPort7, D3DVIEWPORT2 &ViewPort2)
ViewPort7.dvMaxZ = ViewPort2.dvMaxZ;
}

void ConvertViewport(D3DVIEWPORT7 &ViewPort, D3DVIEWPORT7 &ViewPort7)
void ConvertViewport(D3DVIEWPORT7& ViewPort, const D3DVIEWPORT7& ViewPort7)
{
ViewPort.dwX = ViewPort7.dwX;
ViewPort.dwY = ViewPort7.dwY;
Expand All @@ -204,7 +204,7 @@ void ConvertViewport(D3DVIEWPORT7 &ViewPort, D3DVIEWPORT7 &ViewPort7)
ViewPort.dvMaxZ = ViewPort7.dvMaxZ;
}

void ConvertDeviceDesc(D3DDEVICEDESC &Desc, D3DDEVICEDESC7 &Desc7)
void ConvertDeviceDesc(D3DDEVICEDESC& Desc, const D3DDEVICEDESC7& Desc7)
{
if (Desc.dwSize != D3DDEVICEDESC1_SIZE && Desc.dwSize != D3DDEVICEDESC5_SIZE && Desc.dwSize != D3DDEVICEDESC6_SIZE)
{
Expand Down Expand Up @@ -279,7 +279,7 @@ void ConvertDeviceDesc(D3DDEVICEDESC &Desc, D3DDEVICEDESC7 &Desc7)
// Desc.dwVertexProcessingCaps = Desc7.dwVertexProcessingCaps;
}

void ConvertDeviceDesc(D3DDEVICEDESC7 &Desc7, D3DCAPS9 &Caps9)
void ConvertDeviceDesc(D3DDEVICEDESC7& Desc7, const D3DCAPS9& Caps9)
{
// Initialize the output structure
ZeroMemory(&Desc7, sizeof(D3DDEVICEDESC7));
Expand Down Expand Up @@ -571,7 +571,7 @@ void ConvertDeviceDesc(D3DDEVICEDESC7 &Desc7, D3DCAPS9 &Caps9)
Desc7.dwReserved4 = 0;
}

void ConvertVertices(D3DLVERTEX* lFVF, D3DLVERTEX9* lFVF9, DWORD NumVertices)
void ConvertVertices(D3DLVERTEX* lFVF, const D3DLVERTEX9* lFVF9, DWORD NumVertices)
{
for (UINT x = 0; x < NumVertices; x++)
{
Expand All @@ -585,7 +585,7 @@ void ConvertVertices(D3DLVERTEX* lFVF, D3DLVERTEX9* lFVF9, DWORD NumVertices)
}
}

void ConvertVertices(D3DLVERTEX9* lFVF9, D3DLVERTEX* lFVF, DWORD NumVertices)
void ConvertVertices(D3DLVERTEX9* lFVF9, const D3DLVERTEX* lFVF, DWORD NumVertices)
{
for (UINT x = 0; x < NumVertices; x++)
{
Expand Down
28 changes: 14 additions & 14 deletions ddraw/IDirect3DTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,20 +83,20 @@ typedef enum _D3DSURFACETYPE {
D3DTYPE_DEPTHSTENCIL = 4
} D3DSURFACETYPE;

void ConvertLight(D3DLIGHT7& Light7, D3DLIGHT& Light);
void ConvertMaterial(D3DMATERIAL& Material, D3DMATERIAL7& Material7);
void ConvertMaterial(D3DMATERIAL7 &Material7, D3DMATERIAL &Material);
void ConvertViewport(D3DVIEWPORT &ViewPort, D3DVIEWPORT2 &ViewPort2);
void ConvertViewport(D3DVIEWPORT2 &ViewPort2, D3DVIEWPORT &ViewPort);
void ConvertViewport(D3DVIEWPORT &ViewPort, D3DVIEWPORT7 &ViewPort7);
void ConvertViewport(D3DVIEWPORT2 &ViewPort2, D3DVIEWPORT7 &ViewPort7);
void ConvertViewport(D3DVIEWPORT7 &ViewPort7, D3DVIEWPORT &ViewPort);
void ConvertViewport(D3DVIEWPORT7 &ViewPort7, D3DVIEWPORT2 &ViewPort2);
void ConvertViewport(D3DVIEWPORT7 &ViewPort, D3DVIEWPORT7 &ViewPort7);
void ConvertDeviceDesc(D3DDEVICEDESC &Desc, D3DDEVICEDESC7 &Desc7);
void ConvertDeviceDesc(D3DDEVICEDESC7 &Desc7, D3DCAPS9 &Caps9);
void ConvertVertices(D3DLVERTEX* lFVF, D3DLVERTEX9* lFVF9, DWORD NumVertices);
void ConvertVertices(D3DLVERTEX9* lFVF9, D3DLVERTEX* lFVF, DWORD NumVertices);
void ConvertLight(D3DLIGHT7& Light7, const D3DLIGHT& Light);
void ConvertMaterial(D3DMATERIAL& Material, const D3DMATERIAL7& Material7);
void ConvertMaterial(D3DMATERIAL7& Material7, const D3DMATERIAL& Material);
void ConvertViewport(D3DVIEWPORT& ViewPort, const D3DVIEWPORT2& ViewPort2);
void ConvertViewport(D3DVIEWPORT2& ViewPort2, const D3DVIEWPORT& ViewPort);
void ConvertViewport(D3DVIEWPORT& ViewPort, const D3DVIEWPORT7& ViewPort7);
void ConvertViewport(D3DVIEWPORT2& ViewPort2, const D3DVIEWPORT7& ViewPort7);
void ConvertViewport(D3DVIEWPORT7& ViewPort7, const D3DVIEWPORT& ViewPort);
void ConvertViewport(D3DVIEWPORT7& ViewPort7, const D3DVIEWPORT2& ViewPort2);
void ConvertViewport(D3DVIEWPORT7& ViewPort, const D3DVIEWPORT7& ViewPort7);
void ConvertDeviceDesc(D3DDEVICEDESC& Desc, const D3DDEVICEDESC7& Desc7);
void ConvertDeviceDesc(D3DDEVICEDESC7& Desc7, const D3DCAPS9& Caps9);
void ConvertVertices(D3DLVERTEX* lFVF, const D3DLVERTEX9* lFVF9, DWORD NumVertices);
void ConvertVertices(D3DLVERTEX9* lFVF9, const D3DLVERTEX* lFVF, DWORD NumVertices);
bool CheckTextureStageStateType(D3DTEXTURESTAGESTATETYPE dwState);
bool CheckRenderStateType(D3DRENDERSTATETYPE dwRenderStateType);
void ConvertVertex(BYTE* pDestVertex, DWORD DestFVF, const BYTE* pSrcVertex, DWORD SrcFVF);
Expand Down
19 changes: 7 additions & 12 deletions ddraw/IDirectDrawSurfaceX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4593,7 +4593,7 @@ HRESULT m_IDirectDrawSurfaceX::CreateD9Surface()
// Get texture format
surface.Format = GetDisplayFormat(surfaceDesc2.ddpfPixelFormat);
surface.BitCount = GetBitCount(surface.Format);
const bool CanUseEmulation = (!IsSurface3D() && !IsDepthStencil() && !(surface.Format & 0xFF000000 /*FOURCC or D3DFMT_DXTx*/) && !surface.UsingSurfaceMemory);
const bool CanUseEmulation = ((IsPixelFormatRGB(surfaceDesc2.ddpfPixelFormat) || IsPixelFormatPalette(surfaceDesc2.ddpfPixelFormat)) && !IsSurface3D() && !surface.UsingSurfaceMemory);
SurfaceRequiresEmulation = (CanUseEmulation && (Config.DdrawEmulateSurface || ShouldEmulate == SC_FORCE_EMULATED ||
surface.Format == D3DFMT_A8B8G8R8 || surface.Format == D3DFMT_X8B8G8R8 || surface.Format == D3DFMT_B8G8R8 || surface.Format == D3DFMT_R8G8B8));
const bool CreateSurfaceEmulated = (CanUseEmulation && (SurfaceRequiresEmulation ||
Expand Down Expand Up @@ -4810,7 +4810,7 @@ HRESULT m_IDirectDrawSurfaceX::CreateD9Surface()
{
ColorFill(nullptr, 10 * (Count + 1), 0);
}
else if (!(surface.Format & 0xFF000000))
else if (IsPixelFormatRGB(surfaceDesc2.ddpfPixelFormat))
{
ColorFill(nullptr,
(Colors[Count].a & surfaceDesc2.ddpfPixelFormat.dwRGBAlphaBitMask) +
Expand Down Expand Up @@ -4984,7 +4984,7 @@ inline bool m_IDirectDrawSurfaceX::DoesDCMatch(EMUSURFACE* pEmuSurface)

if (pEmuSurface->bmi->bmiHeader.biWidth == (LONG)Width &&
pEmuSurface->bmi->bmiHeader.biHeight == -(LONG)Height &&
pEmuSurface->bmi->bmiHeader.biBitCount == surface.BitCount &&
pEmuSurface->bmi->bmiHeader.biBitCount == (WORD)surface.BitCount &&
pEmuSurface->Format == surface.Format &&
pEmuSurface->Pitch == Pitch)
{
Expand Down Expand Up @@ -5050,6 +5050,7 @@ HRESULT m_IDirectDrawSurfaceX::CreateDCSurface()
// Adjust Width to be byte-aligned
DWORD Width = GetByteAlignedWidth(surfaceDesc2.dwWidth, surface.BitCount);
DWORD Height = surfaceDesc2.dwHeight;
DWORD Pitch = ComputePitch(surface.Format, Width, surface.BitCount);

// Check if emulated surface already exists
if (surface.emu)
Expand Down Expand Up @@ -5177,8 +5178,8 @@ HRESULT m_IDirectDrawSurfaceX::CreateDCSurface()
}
surface.emu->bmi->bmiHeader.biHeight = -(LONG)Height;
surface.emu->Format = surface.Format;
surface.emu->Pitch = ComputePitch(surface.Format, surface.emu->bmi->bmiHeader.biWidth, surface.emu->bmi->bmiHeader.biBitCount);
surface.emu->Size = Height * surface.emu->Pitch;
surface.emu->Pitch = Pitch;
surface.emu->Size = Height * Pitch;

return DD_OK;
}
Expand Down Expand Up @@ -6856,13 +6857,7 @@ HRESULT m_IDirectDrawSurfaceX::CopySurface(m_IDirectDrawSurfaceX* pSourceSurface

// Decode DirectX textures and FourCCs
if ((FormatMismatch && !IsUsingEmulation() && !IsColorKey && !IsMirrorLeftRight && !IsMirrorUpDown) ||
(SrcFormat & 0xFF000000 /*FOURCC or D3DFMT_DXTx*/) ||
SrcFormat == D3DFMT_V8U8 ||
SrcFormat == D3DFMT_L6V5U5 ||
SrcFormat == D3DFMT_X8L8V8U8 ||
SrcFormat == D3DFMT_Q8W8V8U8 ||
SrcFormat == D3DFMT_V16U16 ||
SrcFormat == D3DFMT_A2W10V10U10)
(!IsPixelFormatRGB(pSourceSurface->surfaceDesc2.ddpfPixelFormat) && !IsPixelFormatPalette(pSourceSurface->surfaceDesc2.ddpfPixelFormat)))
{
if (IsColorKey)
{
Expand Down
Loading

0 comments on commit b110ddd

Please sign in to comment.