From eb3afbb73e4ee26d7c2215f79bd06be6dac8e0ed Mon Sep 17 00:00:00 2001 From: Elisha Riedlinger Date: Mon, 9 Sep 2024 20:34:07 -0700 Subject: [PATCH] Add support for D3DFMT_NV12 --- Dllmain/BuildNo.rc | 2 +- Logging/Logging.cpp | 2 ++ ddraw/IDirectDrawSurfaceX.cpp | 2 +- ddraw/IDirectDrawTypes.cpp | 5 ++++- ddraw/IDirectDrawTypes.h | 3 ++- 5 files changed, 10 insertions(+), 4 deletions(-) diff --git a/Dllmain/BuildNo.rc b/Dllmain/BuildNo.rc index b84f4b34..1d086b49 100644 --- a/Dllmain/BuildNo.rc +++ b/Dllmain/BuildNo.rc @@ -1 +1 @@ -#define BUILD_NUMBER 7129 +#define BUILD_NUMBER 7130 diff --git a/Logging/Logging.cpp b/Logging/Logging.cpp index 961ede10..7059659e 100644 --- a/Logging/Logging.cpp +++ b/Logging/Logging.cpp @@ -149,6 +149,8 @@ std::ostream& operator<<(std::ostream& os, const D3DFORMAT& format) return os << "D3DFMT_YUY2"; case MAKEFOURCC('Y', 'V', '1', '2'): return os << "D3DFMT_YV12"; + case MAKEFOURCC('N', 'V', '1', '2'): + return os << "D3DFMT_NV12"; case MAKEFOURCC('A', 'Y', 'U', 'V'): return os << "D3DFMT_AYUV"; case MAKEFOURCC('G', 'R', 'G', 'B'): diff --git a/ddraw/IDirectDrawSurfaceX.cpp b/ddraw/IDirectDrawSurfaceX.cpp index bacd6ca1..0c4b801b 100644 --- a/ddraw/IDirectDrawSurfaceX.cpp +++ b/ddraw/IDirectDrawSurfaceX.cpp @@ -2810,7 +2810,7 @@ HRESULT m_IDirectDrawSurfaceX::Lock2(LPRECT lpDestRect, LPDDSURFACEDESC2 lpDDSur // Pitch for DXT surfaces in DirectDraw is the full surface byte size LockedRect.Pitch = ISDXTEX(surface.Format) ? ((surface.Width + 3) / 4) * ((lpDDSurfaceDesc2->dwHeight + 3) / 4) * (surface.Format == D3DFMT_DXT1 ? 8 : 16) : - (surface.Format == D3DFMT_YV12) ? surface.Width : + (surface.Format == D3DFMT_YV12 || surface.Format == D3DFMT_NV12) ? surface.Width : LockedRect.Pitch; lpDDSurfaceDesc2->lPitch = LockedRect.Pitch; lpDDSurfaceDesc2->dwFlags |= DDSD_PITCH; diff --git a/ddraw/IDirectDrawTypes.cpp b/ddraw/IDirectDrawTypes.cpp index 2f18bdde..de5cd801 100644 --- a/ddraw/IDirectDrawTypes.cpp +++ b/ddraw/IDirectDrawTypes.cpp @@ -546,6 +546,7 @@ DWORD GetBitCount(D3DFORMAT Format) return 16; case D3DFMT_YV12: + case D3DFMT_NV12: return 12; case D3DFMT_P8: @@ -607,7 +608,7 @@ DWORD GetSurfaceSize(D3DFORMAT Format, DWORD Width, DWORD Height, INT Pitch) { return ((GetByteAlignedWidth(Width, GetBitCount(Format)) + 3) / 4) * ((Height + 3) / 4) * (Format == D3DFMT_DXT1 ? 8 : 16); } - else if (Format == D3DFMT_YV12) + else if (Format == D3DFMT_YV12 || Format == D3DFMT_NV12) { return GetByteAlignedWidth(Width, GetBitCount(Format)) * Height; } @@ -776,6 +777,7 @@ D3DFORMAT GetDisplayFormat(DDPIXELFORMAT ddpfPixelFormat) case D3DFMT_UYVY: case D3DFMT_YUY2: case D3DFMT_YV12: + case D3DFMT_NV12: case D3DFMT_MULTI2_ARGB8: case D3DFMT_G8R8_G8B8: case D3DFMT_R8G8_B8G8: @@ -1198,6 +1200,7 @@ void SetPixelDisplayFormat(D3DFORMAT Format, DDPIXELFORMAT &ddpfPixelFormat) case D3DFMT_UYVY: case D3DFMT_YUY2: case D3DFMT_YV12: + case D3DFMT_NV12: ddpfPixelFormat.dwFlags = DDPF_FOURCC; ddpfPixelFormat.dwFourCC = Format; break; diff --git a/ddraw/IDirectDrawTypes.h b/ddraw/IDirectDrawTypes.h index 2c3a8a2a..4e5a314e 100644 --- a/ddraw/IDirectDrawTypes.h +++ b/ddraw/IDirectDrawTypes.h @@ -20,8 +20,9 @@ constexpr DWORD MinUsedVidMemory = 8 * 1024; // 8 KBs #define D3DCOLOR_GETBLUE(c) ((c) & 0xFF) #define D3DFMT_B8G8R8 (D3DFORMAT)19 -#define D3DFMT_YV12 (D3DFORMAT)MAKEFOURCC('Y','V','1','2') #define D3DFMT_AYUV (D3DFORMAT)MAKEFOURCC('A', 'Y', 'U', 'V') +#define D3DFMT_YV12 (D3DFORMAT)MAKEFOURCC('Y', 'V', '1', '2') +#define D3DFMT_NV12 (D3DFORMAT)MAKEFOURCC('N', 'V', '1', '2') #define D3DFMT_R5G6B5_TO_X8R8G8B8(w) \ ((((DWORD)((w>>11)&0x1f)*8)<<16)+(((DWORD)((w>>5)&0x3f)*4)<<8)+((DWORD)(w&0x1f)*8))