diff --git a/DDrawCompat/DDraw/DirectDraw.cpp b/DDrawCompat/DDraw/DirectDraw.cpp index 7d4155c..f88d9f7 100644 --- a/DDrawCompat/DDraw/DirectDraw.cpp +++ b/DDrawCompat/DDraw/DirectDraw.cpp @@ -69,7 +69,7 @@ namespace } return DDraw::Surface::create( - *This, desc, *lplpDDSurface, std::make_unique(desc.ddsCaps.dwCaps)); + *This, desc, *lplpDDSurface, std::make_unique(desc.dwFlags, desc.ddsCaps.dwCaps)); } template diff --git a/DDrawCompat/DDraw/Surfaces/PalettizedTexture.cpp b/DDrawCompat/DDraw/Surfaces/PalettizedTexture.cpp index 2dd62c1..4049215 100644 --- a/DDrawCompat/DDraw/Surfaces/PalettizedTexture.cpp +++ b/DDrawCompat/DDraw/Surfaces/PalettizedTexture.cpp @@ -22,21 +22,22 @@ namespace DDraw auto dd1(CompatPtr::from(&dd)); CompatPtr palettizedSurface; HRESULT result = Surface::create(*dd1, d, palettizedSurface.getRef(), - std::make_unique(desc.ddsCaps.dwCaps)); + std::make_unique(desc.dwFlags, desc.ddsCaps.dwCaps)); if (FAILED(result)) { return LOG_RESULT(result); } - auto privateData(std::make_unique(desc.ddsCaps.dwCaps)); - auto data = privateData.get(); - data->m_palettizedSurface = palettizedSurface; - desc.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CAPS | (desc.dwFlags & (DDSD_CKSRCBLT | DDSD_CKDESTBLT)); desc.ddpfPixelFormat = D3dDdi::getPixelFormat(D3DDDIFMT_A8R8G8B8); desc.ddsCaps = {}; desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY; + + auto privateData(std::make_unique(desc.dwFlags, desc.ddsCaps.dwCaps)); + auto data = privateData.get(); + data->m_palettizedSurface = palettizedSurface; + result = Surface::create(dd, desc, surface, std::move(privateData)); if (FAILED(result)) { diff --git a/DDrawCompat/DDraw/Surfaces/PalettizedTexture.h b/DDrawCompat/DDraw/Surfaces/PalettizedTexture.h index d1a2675..af111ea 100644 --- a/DDrawCompat/DDraw/Surfaces/PalettizedTexture.h +++ b/DDrawCompat/DDraw/Surfaces/PalettizedTexture.h @@ -11,7 +11,7 @@ namespace DDraw class PalettizedTexture : public Surface { public: - PalettizedTexture(DWORD origCaps) : Surface(origCaps) {} + PalettizedTexture(DWORD origFlags, DWORD origCaps) : Surface(origFlags, origCaps) {} virtual ~PalettizedTexture() override; template diff --git a/DDrawCompat/DDraw/Surfaces/PrimarySurface.cpp b/DDrawCompat/DDraw/Surfaces/PrimarySurface.cpp index f1b9c35..7404a29 100644 --- a/DDrawCompat/DDraw/Surfaces/PrimarySurface.cpp +++ b/DDrawCompat/DDraw/Surfaces/PrimarySurface.cpp @@ -106,6 +106,8 @@ namespace DDraw } const DWORD origCaps = desc.ddsCaps.dwCaps; + auto privateData(std::make_unique(desc.dwFlags, origCaps)); + auto data = privateData.get(); desc.dwFlags |= DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT; desc.dwWidth = dm.dwWidth; @@ -115,8 +117,6 @@ namespace DDraw desc.ddsCaps.dwCaps |= DDSCAPS_OFFSCREENPLAIN; desc.ddpfPixelFormat = dm.ddpfPixelFormat; - auto privateData(std::make_unique(origCaps)); - auto data = privateData.get(); result = Surface::create(dd, desc, surface, std::move(privateData)); if (FAILED(result)) { diff --git a/DDrawCompat/DDraw/Surfaces/PrimarySurface.h b/DDrawCompat/DDraw/Surfaces/PrimarySurface.h index 099ad09..a5e6bf7 100644 --- a/DDrawCompat/DDraw/Surfaces/PrimarySurface.h +++ b/DDrawCompat/DDraw/Surfaces/PrimarySurface.h @@ -11,7 +11,7 @@ namespace DDraw class PrimarySurface : public Surface { public: - PrimarySurface(DWORD origCaps) : Surface(origCaps) {} + PrimarySurface(DWORD origFlags, DWORD origCaps) : Surface(origFlags, origCaps) {} virtual ~PrimarySurface(); template diff --git a/DDrawCompat/DDraw/Surfaces/Surface.cpp b/DDrawCompat/DDraw/Surfaces/Surface.cpp index 14edfce..fb13fd3 100644 --- a/DDrawCompat/DDraw/Surfaces/Surface.cpp +++ b/DDrawCompat/DDraw/Surfaces/Surface.cpp @@ -46,8 +46,9 @@ namespace DDraw return refCount; } - Surface::Surface(DWORD origCaps) - : m_origCaps(origCaps) + Surface::Surface(DWORD origFlags, DWORD origCaps) + : m_origFlags(origFlags) + , m_origCaps(origCaps) , m_refCount(0) , m_sizeOverride{} , m_sysMemBuffer(nullptr, &heapFree) @@ -96,6 +97,12 @@ namespace DDraw desc.ddsCaps.dwCaps &= ~DDSCAPS_3DDEVICE; } + if ((desc.dwFlags & DDSD_MIPMAPCOUNT) && 1 == desc.dwMipMapCount) + { + desc.dwFlags &= ~DDSD_MIPMAPCOUNT; + desc.ddsCaps.dwCaps &= ~(DDSCAPS_COMPLEX | DDSCAPS_MIPMAP); + } + HRESULT result = dd->CreateSurface(&dd, &desc, &surface, nullptr); if (FAILED(result)) { @@ -108,7 +115,7 @@ namespace DDraw auto attachedSurfaces(DirectDrawSurface::getAllAttachedSurfaces(*surface7)); for (DWORD i = 0; i < attachedSurfaces.size(); ++i) { - attach(*attachedSurfaces[i], std::make_unique(privateData->m_origCaps)); + attach(*attachedSurfaces[i], std::make_unique(privateData->m_origFlags, privateData->m_origCaps)); } } else if ((desc.ddsCaps.dwCaps & DDSCAPS_SYSTEMMEMORY) && !(desc.dwFlags & DDSD_LPSURFACE)) diff --git a/DDrawCompat/DDraw/Surfaces/Surface.h b/DDrawCompat/DDraw/Surfaces/Surface.h index e46862a..60907c2 100644 --- a/DDrawCompat/DDraw/Surfaces/Surface.h +++ b/DDrawCompat/DDraw/Surfaces/Surface.h @@ -23,7 +23,7 @@ namespace DDraw virtual ULONG STDMETHODCALLTYPE AddRef(); virtual ULONG STDMETHODCALLTYPE Release(); - Surface(DWORD origCaps); + Surface(DWORD origFlags, DWORD origCaps); virtual ~Surface(); static void* alignBuffer(void* buffer); @@ -65,6 +65,7 @@ namespace DDraw template friend class SurfaceImpl; + DWORD m_origFlags; DWORD m_origCaps; DWORD m_refCount; SIZE m_sizeOverride; diff --git a/DDrawCompat/DDraw/Surfaces/SurfaceImpl.cpp b/DDrawCompat/DDraw/Surfaces/SurfaceImpl.cpp index 9157634..4fb072b 100644 --- a/DDrawCompat/DDraw/Surfaces/SurfaceImpl.cpp +++ b/DDrawCompat/DDraw/Surfaces/SurfaceImpl.cpp @@ -189,7 +189,14 @@ namespace DDraw lpDDSurfaceDesc->dwHeight = m_data->m_sizeOverride.cy; m_data->m_sizeOverride = {}; } + restoreOrigCaps(lpDDSurfaceDesc->ddsCaps.dwCaps); + + if ((m_data->m_origFlags & DDSD_MIPMAPCOUNT) && !(lpDDSurfaceDesc->dwFlags & DDSD_MIPMAPCOUNT)) + { + lpDDSurfaceDesc->dwFlags |= DDSD_MIPMAPCOUNT; + lpDDSurfaceDesc->dwMipMapCount = 1; + } } return result; } @@ -299,10 +306,7 @@ namespace DDraw template void SurfaceImpl::restoreOrigCaps(DWORD& caps) { - if (m_data->m_origCaps & DDSCAPS_3DDEVICE) - { - caps |= DDSCAPS_3DDEVICE; - } + caps |= m_data->m_origCaps & (DDSCAPS_3DDEVICE | DDSCAPS_MIPMAP | DDSCAPS_COMPLEX); } template SurfaceImpl; diff --git a/DDrawCompat/DDraw/Surfaces/TagSurface.cpp b/DDrawCompat/DDraw/Surfaces/TagSurface.cpp index c8bc3b8..b2ff9df 100644 --- a/DDrawCompat/DDraw/Surfaces/TagSurface.cpp +++ b/DDrawCompat/DDraw/Surfaces/TagSurface.cpp @@ -11,14 +11,14 @@ namespace namespace DDraw { - TagSurface::TagSurface(DWORD origCaps, DDRAWI_DIRECTDRAW_LCL* ddLcl) - : Surface(origCaps) + TagSurface::TagSurface(DWORD origFlags, DWORD origCaps, DDRAWI_DIRECTDRAW_LCL* ddLcl) + : Surface(origFlags, origCaps) , m_ddInt{} , m_fullscreenWindow(nullptr) , m_fullscreenWindowStyle(0) , m_fullscreenWindowExStyle(0) { - LOG_FUNC("TagSurface::TagSurface", Compat::hex(origCaps), ddLcl); + LOG_FUNC("TagSurface::TagSurface", Compat::hex(origFlags), Compat::hex(origCaps), ddLcl); m_ddInt.lpVtbl = &CompatVtable::s_origVtable; m_ddInt.lpLcl = ddLcl; m_ddInt.dwIntRefCnt = 1; @@ -41,7 +41,7 @@ namespace DDraw desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY; auto ddLcl = DDraw::DirectDraw::getInt(dd.get()).lpLcl; - auto privateData(std::make_unique(desc.ddsCaps.dwCaps, ddLcl)); + auto privateData(std::make_unique(desc.dwFlags, desc.ddsCaps.dwCaps, ddLcl)); g_ddObjects[ddLcl] = privateData.get(); IDirectDrawSurface* surface = nullptr; diff --git a/DDrawCompat/DDraw/Surfaces/TagSurface.h b/DDrawCompat/DDraw/Surfaces/TagSurface.h index 1b23f62..f544bc3 100644 --- a/DDrawCompat/DDraw/Surfaces/TagSurface.h +++ b/DDrawCompat/DDraw/Surfaces/TagSurface.h @@ -11,7 +11,7 @@ namespace DDraw class TagSurface : public Surface { public: - TagSurface(DWORD origCaps, DDRAWI_DIRECTDRAW_LCL* ddLcl); + TagSurface(DWORD origFlags, DWORD origCaps, DDRAWI_DIRECTDRAW_LCL* ddLcl); virtual ~TagSurface() override; static TagSurface* get(DDRAWI_DIRECTDRAW_LCL* ddLcl);