diff --git a/Dllmain/BuildNo.rc b/Dllmain/BuildNo.rc index 3cbc178d..2798fe53 100644 --- a/Dllmain/BuildNo.rc +++ b/Dllmain/BuildNo.rc @@ -1 +1 @@ -#define BUILD_NUMBER 7368 +#define BUILD_NUMBER 7369 diff --git a/ddraw/IDirect3DTypes.cpp b/ddraw/IDirect3DTypes.cpp index adfe90e0..686c3aa0 100644 --- a/ddraw/IDirect3DTypes.cpp +++ b/ddraw/IDirect3DTypes.cpp @@ -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)) { @@ -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)) { @@ -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)) { @@ -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)) { @@ -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)) { @@ -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)) { @@ -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)) { @@ -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)) { @@ -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)) { @@ -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; @@ -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) { @@ -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)); @@ -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++) { @@ -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++) { diff --git a/ddraw/IDirect3DTypes.h b/ddraw/IDirect3DTypes.h index 8424b0b4..2bc490fe 100644 --- a/ddraw/IDirect3DTypes.h +++ b/ddraw/IDirect3DTypes.h @@ -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); diff --git a/ddraw/IDirectDrawSurfaceX.cpp b/ddraw/IDirectDrawSurfaceX.cpp index eb41bd32..79b9b8ed 100644 --- a/ddraw/IDirectDrawSurfaceX.cpp +++ b/ddraw/IDirectDrawSurfaceX.cpp @@ -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 || @@ -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) + @@ -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) { @@ -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) @@ -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; } @@ -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) { diff --git a/ddraw/IDirectDrawTypes.cpp b/ddraw/IDirectDrawTypes.cpp index fde20bd6..a15138af 100644 --- a/ddraw/IDirectDrawTypes.cpp +++ b/ddraw/IDirectDrawTypes.cpp @@ -63,7 +63,7 @@ bool GetOverlappingRect(const RECT& rect1, const RECT& rect2, RECT& outOverlapRe return false; } -void ConvertSurfaceDesc(DDSURFACEDESC &Desc, DDSURFACEDESC2 &Desc2) +void ConvertSurfaceDesc(DDSURFACEDESC& Desc, const DDSURFACEDESC2& Desc2) { // Check for supported dwSize if (Desc.dwSize != sizeof(DDSURFACEDESC) || (Desc2.dwSize != sizeof(DDSURFACEDESC2) && Desc2.dwSize != sizeof(DDSURFACEDESC))) @@ -110,7 +110,7 @@ void ConvertSurfaceDesc(DDSURFACEDESC &Desc, DDSURFACEDESC2 &Desc2) } } -void ConvertSurfaceDesc(DDSURFACEDESC2 &Desc2, DDSURFACEDESC &Desc) +void ConvertSurfaceDesc(DDSURFACEDESC2& Desc2, const DDSURFACEDESC& Desc) { // Check for supported dwSize if (Desc2.dwSize != sizeof(DDSURFACEDESC2) || Desc.dwSize != sizeof(DDSURFACEDESC)) @@ -242,7 +242,7 @@ void ClearUnusedValues(DDSURFACEDESC2& Desc2) if (!(Desc2.dwFlags & DDSD_TEXTURESTAGE)) Desc2.dwTextureStage = 0; } -void ConvertPixelFormat(DDPIXELFORMAT& Format, DDS_PIXELFORMAT& Format2) +void ConvertPixelFormat(DDPIXELFORMAT& Format, const DDS_PIXELFORMAT& Format2) { if (Format.dwSize != sizeof(DDPIXELFORMAT) || Format2.dwSize != sizeof(DDS_PIXELFORMAT)) { @@ -258,19 +258,19 @@ void ConvertPixelFormat(DDPIXELFORMAT& Format, DDS_PIXELFORMAT& Format2) Format.dwRGBAlphaBitMask = Format2.dwABitMask; } -void ConvertDeviceIdentifier(DDDEVICEIDENTIFIER &DeviceID, DDDEVICEIDENTIFIER2 &DeviceID2) +void ConvertDeviceIdentifier(DDDEVICEIDENTIFIER& DeviceID, const DDDEVICEIDENTIFIER2& DeviceID2) { CopyMemory(&DeviceID, &DeviceID2, sizeof(DDDEVICEIDENTIFIER)); } -void ConvertDeviceIdentifier(DDDEVICEIDENTIFIER2 &DeviceID2, DDDEVICEIDENTIFIER &DeviceID) +void ConvertDeviceIdentifier(DDDEVICEIDENTIFIER2& DeviceID2, const DDDEVICEIDENTIFIER& DeviceID) { CopyMemory(&DeviceID2, &DeviceID, sizeof(DDDEVICEIDENTIFIER)); // Extra parameters DeviceID2.dwWHQLLevel = 0; } -void ConvertDeviceIdentifier(DDDEVICEIDENTIFIER2 &DeviceID2, D3DADAPTER_IDENTIFIER9 &Identifier9) +void ConvertDeviceIdentifier(DDDEVICEIDENTIFIER2& DeviceID2, const D3DADAPTER_IDENTIFIER9& Identifier9) { memcpy(DeviceID2.szDriver, Identifier9.Driver, MAX_DDDEVICEID_STRING); memcpy(DeviceID2.szDescription, Identifier9.Description, MAX_DDDEVICEID_STRING); @@ -284,7 +284,7 @@ void ConvertDeviceIdentifier(DDDEVICEIDENTIFIER2 &DeviceID2, D3DADAPTER_IDENTIFI DeviceID2.dwWHQLLevel = Identifier9.WHQLLevel; } -void ConvertCaps(DDSCAPS &Caps, DDSCAPS2 &Caps2) +void ConvertCaps(DDSCAPS& Caps, const DDSCAPS2& Caps2) { Caps.dwCaps = Caps2.dwCaps; // Check for dwFlags that did not get converted @@ -294,7 +294,7 @@ void ConvertCaps(DDSCAPS &Caps, DDSCAPS2 &Caps2) } } -void ConvertCaps(DDSCAPS2 &Caps2, DDSCAPS &Caps) +void ConvertCaps(DDSCAPS2& Caps2, const DDSCAPS& Caps) { Caps2.dwCaps = Caps.dwCaps; // Extra parameters @@ -304,7 +304,7 @@ void ConvertCaps(DDSCAPS2 &Caps2, DDSCAPS &Caps) Caps2.dwVolumeDepth = 0; // Not used } -void ConvertCaps(DDCAPS &Caps, DDCAPS &Caps2) +void ConvertCaps(DDCAPS& Caps, const DDCAPS& Caps2) { if ((Caps.dwSize != sizeof(DDCAPS_DX1) && Caps.dwSize != sizeof(DDCAPS_DX3) && Caps.dwSize != sizeof(DDCAPS_DX5) && Caps.dwSize != sizeof(DDCAPS_DX6) && @@ -322,7 +322,7 @@ void ConvertCaps(DDCAPS &Caps, DDCAPS &Caps2) AdjustVidMemory(&Caps.dwVidMemTotal, &Caps.dwVidMemFree); } -void ConvertCaps(DDCAPS &Caps7, D3DCAPS9 &Caps9) +void ConvertCaps(DDCAPS& Caps7, D3DCAPS9& Caps9) { // Note: dwVidMemTotal, dwVidMemFree and dwNumFourCCCodes are not part of D3DCAPS9 and need to be set separately if (Caps7.dwSize != sizeof(DDCAPS)) @@ -547,7 +547,7 @@ DWORD GetMaxMipMapLevel(DWORD Width, DWORD Height) return 1 + static_cast(std::floor(std::log2(min(Width, Height)))); } -DWORD GetBitCount(DDPIXELFORMAT ddpfPixelFormat) +DWORD GetBitCount(const DDPIXELFORMAT& ddpfPixelFormat) { if (ddpfPixelFormat.dwSize != sizeof(DDPIXELFORMAT)) { @@ -790,54 +790,54 @@ inline void CountBits(DWORD value, DWORD& LeadingZeros, DWORD& TotalBits) } } -DWORD GetARGBColorKey(DWORD ColorKey, DDPIXELFORMAT& pixelFormat) +DWORD GetARGBColorKey(DWORD ColorKey, const DDPIXELFORMAT& ddpfPixelFormat) { - if (!pixelFormat.dwRBitMask || !pixelFormat.dwGBitMask || !pixelFormat.dwBBitMask) + if (!ddpfPixelFormat.dwRBitMask || !ddpfPixelFormat.dwGBitMask || !ddpfPixelFormat.dwBBitMask) { - LOG_LIMIT(100, __FUNCTION__ << " Error: pixel format not Implemented: " << pixelFormat); + LOG_LIMIT(100, __FUNCTION__ << " Error: pixel format not Implemented: " << ddpfPixelFormat); return 0; } DWORD dwRBitCount, dwGBitCount, dwBBitCount, rShift, gShift, bShift; // Calculate bits for each color component - CountBits(pixelFormat.dwRBitMask, rShift, dwRBitCount); - CountBits(pixelFormat.dwGBitMask, gShift, dwGBitCount); - CountBits(pixelFormat.dwBBitMask, bShift, dwBBitCount); + CountBits(ddpfPixelFormat.dwRBitMask, rShift, dwRBitCount); + CountBits(ddpfPixelFormat.dwGBitMask, gShift, dwGBitCount); + CountBits(ddpfPixelFormat.dwBBitMask, bShift, dwBBitCount); // Calculate size of color space for bit depth - const float rColorRange = 255.0f / (pixelFormat.dwRBitMask >> rShift); - const float gColorRange = 255.0f / (pixelFormat.dwGBitMask >> gShift); - const float bColorRange = 255.0f / (pixelFormat.dwBBitMask >> bShift); + const float rColorRange = 255.0f / (ddpfPixelFormat.dwRBitMask >> rShift); + const float gColorRange = 255.0f / (ddpfPixelFormat.dwGBitMask >> gShift); + const float bColorRange = 255.0f / (ddpfPixelFormat.dwBBitMask >> bShift); // Extract individual components according to pixel format for low color key - DWORD r = static_cast(((ColorKey & pixelFormat.dwRBitMask) >> rShift) * rColorRange); - DWORD g = static_cast(((ColorKey & pixelFormat.dwGBitMask) >> gShift) * gColorRange); - DWORD b = static_cast(((ColorKey & pixelFormat.dwBBitMask) >> bShift) * bColorRange); + DWORD r = static_cast(((ColorKey & ddpfPixelFormat.dwRBitMask) >> rShift) * rColorRange); + DWORD g = static_cast(((ColorKey & ddpfPixelFormat.dwGBitMask) >> gShift) * gColorRange); + DWORD b = static_cast(((ColorKey & ddpfPixelFormat.dwBBitMask) >> bShift) * bColorRange); // Return ARGB color key return D3DCOLOR_ARGB(0xFF, r, g, b); } -void GetColorKeyArray(float(&lowColorKey)[4], float(&highColorKey)[4], DWORD lowColorSpace, DWORD highColorSpace, DDPIXELFORMAT& pixelFormat) +void GetColorKeyArray(float(&lowColorKey)[4], float(&highColorKey)[4], DWORD lowColorSpace, DWORD highColorSpace, const DDPIXELFORMAT& ddpfPixelFormat) { - if (!pixelFormat.dwRBitMask || !pixelFormat.dwGBitMask || !pixelFormat.dwBBitMask) + if (!ddpfPixelFormat.dwRBitMask || !ddpfPixelFormat.dwGBitMask || !ddpfPixelFormat.dwBBitMask) { - LOG_LIMIT(100, __FUNCTION__ << " Error: pixel format not Implemented: " << pixelFormat); + LOG_LIMIT(100, __FUNCTION__ << " Error: pixel format not Implemented: " << ddpfPixelFormat); return; } DWORD dwRBitCount, dwGBitCount, dwBBitCount, rShift, gShift, bShift; // Calculate bits for each color component - CountBits(pixelFormat.dwRBitMask, rShift, dwRBitCount); - CountBits(pixelFormat.dwGBitMask, gShift, dwGBitCount); - CountBits(pixelFormat.dwBBitMask, bShift, dwBBitCount); + CountBits(ddpfPixelFormat.dwRBitMask, rShift, dwRBitCount); + CountBits(ddpfPixelFormat.dwGBitMask, gShift, dwGBitCount); + CountBits(ddpfPixelFormat.dwBBitMask, bShift, dwBBitCount); // Calculate size of color space for bit depth - const float rColorRange = 255.0f / (pixelFormat.dwRBitMask >> rShift); - const float gColorRange = 255.0f / (pixelFormat.dwGBitMask >> gShift); - const float bColorRange = 255.0f / (pixelFormat.dwBBitMask >> bShift); + const float rColorRange = 255.0f / (ddpfPixelFormat.dwRBitMask >> rShift); + const float gColorRange = 255.0f / (ddpfPixelFormat.dwGBitMask >> gShift); + const float bColorRange = 255.0f / (ddpfPixelFormat.dwBBitMask >> bShift); // Allow some range for padding (half of a pixel's color range) const float rPadding = (rColorRange / 255.0f) * 0.1f; @@ -845,9 +845,9 @@ void GetColorKeyArray(float(&lowColorKey)[4], float(&highColorKey)[4], DWORD low const float bPadding = (bColorRange / 255.0f) * 0.1f; // Extract individual components according to pixel format for low color key - BYTE r = (BYTE)((lowColorSpace & pixelFormat.dwRBitMask) >> rShift); - BYTE g = (BYTE)((lowColorSpace & pixelFormat.dwGBitMask) >> gShift); - BYTE b = (BYTE)((lowColorSpace & pixelFormat.dwBBitMask) >> bShift); + BYTE r = (BYTE)((lowColorSpace & ddpfPixelFormat.dwRBitMask) >> rShift); + BYTE g = (BYTE)((lowColorSpace & ddpfPixelFormat.dwGBitMask) >> gShift); + BYTE b = (BYTE)((lowColorSpace & ddpfPixelFormat.dwBBitMask) >> bShift); // Convert to float and normalize to range [0, 1] for low color key lowColorKey[0] = (r * rColorRange / 255.0f) - rPadding; @@ -859,9 +859,9 @@ void GetColorKeyArray(float(&lowColorKey)[4], float(&highColorKey)[4], DWORD low lowColorKey[3] = 0.0f; // Extract individual components according to pixel format for high color key - r = (BYTE)((highColorSpace & pixelFormat.dwRBitMask) >> rShift); - g = (BYTE)((highColorSpace & pixelFormat.dwGBitMask) >> gShift); - b = (BYTE)((highColorSpace & pixelFormat.dwBBitMask) >> bShift); + r = (BYTE)((highColorSpace & ddpfPixelFormat.dwRBitMask) >> rShift); + g = (BYTE)((highColorSpace & ddpfPixelFormat.dwGBitMask) >> gShift); + b = (BYTE)((highColorSpace & ddpfPixelFormat.dwBBitMask) >> bShift); // Convert to float and normalize to range [0, 1] for high color key highColorKey[0] = (r * rColorRange / 255.0f) + rPadding; @@ -873,6 +873,37 @@ void GetColorKeyArray(float(&lowColorKey)[4], float(&highColorKey)[4], DWORD low highColorKey[3] = 0.0f; } +bool IsPixelFormatRGB(const DDPIXELFORMAT& ddpfPixelFormat) +{ + if (ddpfPixelFormat.dwFlags & (DDPF_ALPHA | DDPF_ALPHAPREMULT | DDPF_FOURCC | DDPF_COMPRESSED | + DDPF_PALETTEINDEXED8 | DDPF_PALETTEINDEXEDTO8 | DDPF_PALETTEINDEXED4 | DDPF_PALETTEINDEXED2 | DDPF_PALETTEINDEXED1 | + DDPF_LUMINANCE | DDPF_BUMPLUMINANCE | DDPF_BUMPDUDV | DDPF_RGBTOYUV | DDPF_YUV | + DDPF_ZBUFFER | DDPF_ZPIXELS | DDPF_STENCILBUFFER)) + { + return false; + } + if (ddpfPixelFormat.dwFlags & (DDPF_RGB)) + { + return true; + } + return false; +} + +bool IsPixelFormatPalette(const DDPIXELFORMAT& ddpfPixelFormat) +{ + if (ddpfPixelFormat.dwFlags & (DDPF_ALPHA | DDPF_ALPHAPREMULT | DDPF_FOURCC | DDPF_COMPRESSED | + DDPF_LUMINANCE | DDPF_BUMPLUMINANCE | DDPF_BUMPDUDV | DDPF_RGBTOYUV | DDPF_YUV | + DDPF_ZBUFFER | DDPF_ZPIXELS | DDPF_STENCILBUFFER)) + { + return false; + } + if (ddpfPixelFormat.dwFlags & (DDPF_PALETTEINDEXED8 | DDPF_PALETTEINDEXEDTO8 | DDPF_PALETTEINDEXED4 | DDPF_PALETTEINDEXED2 | DDPF_PALETTEINDEXED1)) + { + return true; + } + return false; +} + D3DFORMAT ConvertSurfaceFormat(D3DFORMAT Format) { return (Format == D3DFMT_X8B8G8R8 || Format == D3DFMT_B8G8R8 || Format == D3DFMT_R8G8B8) ? D3DFMT_X8R8G8B8 : @@ -903,7 +934,7 @@ D3DFORMAT GetFailoverFormat(D3DFORMAT Format) return Format; } -D3DFORMAT GetDisplayFormat(DDPIXELFORMAT ddpfPixelFormat) +D3DFORMAT GetDisplayFormat(const DDPIXELFORMAT& ddpfPixelFormat) { if (ddpfPixelFormat.dwSize != sizeof(DDPIXELFORMAT)) { @@ -1058,7 +1089,7 @@ D3DFORMAT GetDisplayFormat(DDPIXELFORMAT ddpfPixelFormat) LOG_LIMIT(100, __FUNCTION__ << " Error: could not find RGB format for PixelFormat: " << ddpfPixelFormat); return D3DFMT_UNKNOWN; } - + // Bump formats if (ddpfPixelFormat.dwFlags & DDPF_BUMPDUDV) { @@ -1140,7 +1171,7 @@ D3DFORMAT GetDisplayFormat(DDPIXELFORMAT ddpfPixelFormat) return D3DFMT_UNKNOWN; } -void SetPixelDisplayFormat(D3DFORMAT Format, DDPIXELFORMAT &ddpfPixelFormat) +void SetPixelDisplayFormat(D3DFORMAT Format, DDPIXELFORMAT& ddpfPixelFormat) { if (ddpfPixelFormat.dwSize != sizeof(DDPIXELFORMAT)) { @@ -1374,7 +1405,7 @@ void SetPixelDisplayFormat(D3DFORMAT Format, DDPIXELFORMAT &ddpfPixelFormat) } } -D3DFORMAT SetDisplayFormat(DDPIXELFORMAT &ddpfPixelFormat, DWORD BPP) +D3DFORMAT SetDisplayFormat(DDPIXELFORMAT& ddpfPixelFormat, DWORD BPP) { D3DFORMAT Format = D3DFMT_UNKNOWN; switch (BPP) diff --git a/ddraw/IDirectDrawTypes.h b/ddraw/IDirectDrawTypes.h index d08c7b4f..1096e379 100644 --- a/ddraw/IDirectDrawTypes.h +++ b/ddraw/IDirectDrawTypes.h @@ -132,29 +132,31 @@ void AddDisplayResolution(DWORD Width, DWORD Height); bool IsDisplayResolution(DWORD Width, DWORD Height); bool DoRectsMatch(const RECT& lhs, const RECT& rhs); bool GetOverlappingRect(const RECT& rect1, const RECT& rect2, RECT& outOverlapRect); -void ConvertSurfaceDesc(DDSURFACEDESC &Desc, DDSURFACEDESC2 &Desc2); -void ConvertSurfaceDesc(DDSURFACEDESC2 &Desc2, DDSURFACEDESC &Desc); +void ConvertSurfaceDesc(DDSURFACEDESC& Desc, const DDSURFACEDESC2& Desc2); +void ConvertSurfaceDesc(DDSURFACEDESC2& Desc2, const DDSURFACEDESC& Desc); void ClearUnusedValues(DDSURFACEDESC2& Desc2); -void ConvertPixelFormat(DDPIXELFORMAT& Format, DDS_PIXELFORMAT &Format2); -void ConvertDeviceIdentifier(DDDEVICEIDENTIFIER &DeviceID, DDDEVICEIDENTIFIER2 &DeviceID2); -void ConvertDeviceIdentifier(DDDEVICEIDENTIFIER2 &DeviceID2, DDDEVICEIDENTIFIER &DeviceID); -void ConvertDeviceIdentifier(DDDEVICEIDENTIFIER2 &DeviceID, D3DADAPTER_IDENTIFIER9 &Identifier9); -void ConvertCaps(DDSCAPS &Caps, DDSCAPS2 &Caps2); -void ConvertCaps(DDSCAPS2 &Caps2, DDSCAPS &Caps); -void ConvertCaps(DDCAPS &Caps, DDCAPS &Caps2); -void ConvertCaps(DDCAPS &Caps7, D3DCAPS9 &Caps9); +void ConvertPixelFormat(DDPIXELFORMAT& Format, const DDS_PIXELFORMAT& Format2); +void ConvertDeviceIdentifier(DDDEVICEIDENTIFIER& DeviceID, const DDDEVICEIDENTIFIER2& DeviceID2); +void ConvertDeviceIdentifier(DDDEVICEIDENTIFIER2& DeviceID2, const DDDEVICEIDENTIFIER& DeviceID); +void ConvertDeviceIdentifier(DDDEVICEIDENTIFIER2& DeviceID, const D3DADAPTER_IDENTIFIER9& Identifier9); +void ConvertCaps(DDSCAPS& Caps, const DDSCAPS2& Caps2); +void ConvertCaps(DDSCAPS2& Caps2, const DDSCAPS& Caps); +void ConvertCaps(DDCAPS& Caps, const DDCAPS& Caps2); +void ConvertCaps(DDCAPS& Caps7, D3DCAPS9& Caps9); void AdjustVidMemory(LPDWORD lpdwTotal, LPDWORD lpdwFree); DWORD GetByteAlignedWidth(DWORD Width, DWORD BitCount); DWORD GetMaxMipMapLevel(DWORD Width, DWORD Height); -DWORD GetBitCount(DDPIXELFORMAT ddpfPixelFormat); +DWORD GetBitCount(const DDPIXELFORMAT& ddpfPixelFormat); DWORD GetBitCount(D3DFORMAT Format); float ConvertDepthValue(DWORD dwFillDepth, D3DFORMAT Format); DWORD ComputePitch(D3DFORMAT Format, DWORD Width, DWORD Height); DWORD GetSurfaceSize(D3DFORMAT Format, DWORD Width, DWORD Height, INT Pitch); -DWORD GetARGBColorKey(DWORD ColorKey, DDPIXELFORMAT& pixelFormat); -void GetColorKeyArray(float(&lowColorKey)[4], float(&highColorKey)[4], DWORD lowColorSpace, DWORD highColorSpace, DDPIXELFORMAT& pixelFormat); +DWORD GetARGBColorKey(DWORD ColorKey, const DDPIXELFORMAT& ddpfPixelFormat); +void GetColorKeyArray(float(&lowColorKey)[4], float(&highColorKey)[4], DWORD lowColorSpace, DWORD highColorSpace, const DDPIXELFORMAT& pixelFormat); +bool IsPixelFormatRGB(const DDPIXELFORMAT& ddpfPixelFormat); +bool IsPixelFormatPalette(const DDPIXELFORMAT& ddpfPixelFormat); D3DFORMAT ConvertSurfaceFormat(D3DFORMAT Format); D3DFORMAT GetFailoverFormat(D3DFORMAT Format); -D3DFORMAT GetDisplayFormat(DDPIXELFORMAT ddpfPixelFormat); -void SetPixelDisplayFormat(D3DFORMAT Format, DDPIXELFORMAT &lpPixelFormat); -D3DFORMAT SetDisplayFormat(DDPIXELFORMAT &ddpfPixelFormat, DWORD BPP); +D3DFORMAT GetDisplayFormat(const DDPIXELFORMAT& ddpfPixelFormat); +void SetPixelDisplayFormat(D3DFORMAT Format, DDPIXELFORMAT& ddpfPixelFormat); +D3DFORMAT SetDisplayFormat(DDPIXELFORMAT& ddpfPixelFormat, DWORD BPP);