diff --git a/DDrawCompat/Config/Config.cpp b/DDrawCompat/Config/Config.cpp index 7c86f15..9d310ce 100644 --- a/DDrawCompat/Config/Config.cpp +++ b/DDrawCompat/Config/Config.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -46,6 +47,7 @@ namespace Config Settings::ConfigHotKey configHotKey; Settings::CpuAffinity cpuAffinity; Settings::CpuAffinityRotation cpuAffinityRotation; + Settings::DepthFormat depthFormat; Settings::DesktopColorDepth desktopColorDepth; Settings::DisplayFilter displayFilter; Settings::DisplayRefreshRate displayRefreshRate; diff --git a/DDrawCompat/Config/Settings/DepthFormat.h b/DDrawCompat/Config/Settings/DepthFormat.h new file mode 100644 index 0000000..4507e04 --- /dev/null +++ b/DDrawCompat/Config/Settings/DepthFormat.h @@ -0,0 +1,21 @@ +#pragma once + +#include + +namespace Config +{ + namespace Settings + { + class DepthFormat : public MappedSetting + { + public: + static const UINT APP = 0; + + DepthFormat() : MappedSetting("DepthFormat", "app", { {"app", APP}, {"16", 16}, {"24", 24}, {"32", 32} }) + { + } + }; + } + + extern Settings::DepthFormat depthFormat; +} diff --git a/DDrawCompat/D3dDdi/Device.cpp b/DDrawCompat/D3dDdi/Device.cpp index 383de9c..f05d8ef 100644 --- a/DDrawCompat/D3dDdi/Device.cpp +++ b/DDrawCompat/D3dDdi/Device.cpp @@ -47,6 +47,30 @@ namespace D3dDdi s_devices.try_emplace(device, adapter, device); } + HRESULT Device::clear(D3DDDIARG_CLEAR data, UINT numRect, const RECT* rect, Resource* resource, DWORD flags) + { + if (0 == flags) + { + return S_OK; + } + + data.Flags &= ~(D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER | D3DCLEAR_STENCIL); + data.Flags |= flags; + + if (resource) + { + static std::vector scaledRects; + scaledRects.assign(rect, rect + numRect); + for (UINT i = 0; i < numRect; ++i) + { + resource->scaleRect(scaledRects[i]); + } + rect = scaledRects.data(); + } + + return m_origVtable.pfnClear(m_device, &data, numRect, rect); + } + HRESULT Device::createPrivateResource(D3DDDIARG_CREATERESOURCE2& data) { const bool isPalettized = D3DDDIFMT_P8 == data.Format; @@ -179,18 +203,17 @@ namespace D3dDdi prepareForGpuWrite(); m_state.flush(); - if ((m_renderTarget || m_depthStencil) && rect) + if (0 == numRect || !rect) { - std::vector scaledRect(rect, rect + numRect); - auto resource = m_renderTarget ? m_renderTarget : m_depthStencil; - for (UINT i = 0; i < numRect; ++i) - { - resource->scaleRect(scaledRect[i]); - } - return m_origVtable.pfnClear(m_device, data, numRect, scaledRect.data()); + return m_origVtable.pfnClear(m_device, data, numRect, rect); } - return m_origVtable.pfnClear(m_device, data, numRect, rect); + HRESULT result = clear(*data, numRect, rect, m_renderTarget, data->Flags & D3DCLEAR_TARGET); + if (SUCCEEDED(result)) + { + result = clear(*data, numRect, rect, m_depthStencil, data->Flags & (D3DCLEAR_ZBUFFER | D3DCLEAR_STENCIL)); + } + return result; } HRESULT Device::pfnColorFill(const D3DDDIARG_COLORFILL* data) diff --git a/DDrawCompat/D3dDdi/Device.h b/DDrawCompat/D3dDdi/Device.h index ac7bac8..c61b394 100644 --- a/DDrawCompat/D3dDdi/Device.h +++ b/DDrawCompat/D3dDdi/Device.h @@ -78,6 +78,7 @@ namespace D3dDdi static void updateAllConfig(); private: + HRESULT clear(D3DDDIARG_CLEAR data, UINT numRect, const RECT* rect, Resource* resource, DWORD flags); static void updateAllConfigNow(); D3DDDI_DEVICEFUNCS m_origVtable; diff --git a/DDrawCompat/D3dDdi/DeviceState.cpp b/DDrawCompat/D3dDdi/DeviceState.cpp index 375f000..dd15817 100644 --- a/DDrawCompat/D3dDdi/DeviceState.cpp +++ b/DDrawCompat/D3dDdi/DeviceState.cpp @@ -953,12 +953,12 @@ namespace D3dDdi { resource->scaleRect(reinterpret_cast(vp)); renderTarget.hRenderTarget = *resource->getCustomResource(); - - resource = m_device.getResource(depthStencil.hZBuffer); - if (resource && resource->getCustomResource()) - { - depthStencil.hZBuffer = *resource->getCustomResource(); - } + } + + resource = m_device.getResource(depthStencil.hZBuffer); + if (resource && resource->getCustomResource()) + { + depthStencil.hZBuffer = *resource->getCustomResource(); } setRenderTarget(renderTarget); diff --git a/DDrawCompat/D3dDdi/Resource.cpp b/DDrawCompat/D3dDdi/Resource.cpp index e67dbbe..e833af2 100644 --- a/DDrawCompat/D3dDdi/Resource.cpp +++ b/DDrawCompat/D3dDdi/Resource.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -161,8 +162,6 @@ namespace D3dDdi } m_handle = m_fixedData.hResource; - updateConfig(); - if (D3DDDIPOOL_SYSTEMMEM != m_fixedData.Pool && m_origData.Flags.ZBuffer) { m_lockData.resize(m_origData.SurfCount); @@ -191,6 +190,7 @@ namespace D3dDdi } data.hResource = m_fixedData.hResource; + updateConfig(); } Resource::~Resource() @@ -707,7 +707,7 @@ namespace D3dDdi if (D3DDDIFMT_UNKNOWN != g_formatOverride) { m_fixedData.Format = g_formatOverride; - if (m_fixedData.Flags.ZBuffer) + if (FOURCC_INTZ == g_formatOverride) { m_fixedData.Flags.Texture = 1; } @@ -749,6 +749,27 @@ namespace D3dDdi case 32: return D3DDDIFMT_X8R8G8B8; } } + else if (m_fixedData.Flags.ZBuffer && Config::Settings::DepthFormat::APP != Config::depthFormat.get() && + getFormatInfo(m_fixedData.Format).depth.bitCount != Config::depthFormat.get()) + { + auto& formatOps = m_device.getAdapter().getInfo().formatOps; + switch (Config::depthFormat.get()) + { +#define USE_FORMAT(format) if (formatOps.find(format) != formatOps.end()) return format + case 32: + USE_FORMAT(D3DDDIFMT_D32); + USE_FORMAT(D3DDDIFMT_D32_LOCKABLE); + USE_FORMAT(D3DDDIFMT_D32F_LOCKABLE); + case 24: + USE_FORMAT(D3DDDIFMT_S8D24); + USE_FORMAT(D3DDDIFMT_D24S8); + USE_FORMAT(D3DDDIFMT_X8D24); + USE_FORMAT(D3DDDIFMT_D24X8); + case 16: + USE_FORMAT(D3DDDIFMT_D16); +#undef USE_FORMAT + } + } return m_fixedData.Format; } @@ -815,7 +836,7 @@ namespace D3dDdi if (!m_fixedData.Flags.Texture) { auto& repo = SurfaceRepository::get(m_device.getAdapter()); - auto& texture = repo.getTempTexture(si.Width, si.Height, getPixelFormat(m_fixedData.Format)); + auto& texture = repo.getTempTexture(si.Width, si.Height, m_fixedData.Format); if (!texture.resource) { return; @@ -1207,7 +1228,7 @@ namespace D3dDdi if (D3DDDIPOOL_SYSTEMMEM == srcResource->m_fixedData.Pool) { - srcResource = repo.getTempTexture(srcWidth, srcHeight, getPixelFormat(srcResource->m_fixedData.Format)).resource; + srcResource = repo.getTempTexture(srcWidth, srcHeight, srcResource->m_fixedData.Format).resource; if (!srcResource) { return LOG_RESULT(E_OUTOFMEMORY); @@ -1319,7 +1340,7 @@ namespace D3dDdi RECT srcRect = { 0, 0, visibleRect.right - visibleRect.left, visibleRect.bottom - visibleRect.top }; auto& windowSurface = repo.getTempSysMemSurface(srcRect.right, srcRect.bottom); - auto& texture = repo.getTempTexture(srcRect.right, srcRect.bottom, getPixelFormat(D3DDDIFMT_A8R8G8B8)); + auto& texture = repo.getTempTexture(srcRect.right, srcRect.bottom, D3DDDIFMT_A8R8G8B8); if (!windowSurface.resource || !texture.resource) { continue; @@ -1407,6 +1428,11 @@ namespace D3dDdi } } + void Resource::setFormatOverride(D3DDDIFORMAT format) + { + g_formatOverride = format; + } + void Resource::setFullscreenMode(bool isFullscreen) { if (!IsRectEmpty(&g_presentationRect) == isFullscreen) @@ -1469,7 +1495,7 @@ namespace D3dDdi DWORD height = data.SrcRect.bottom - data.SrcRect.top; auto texture = m_fixedData.Flags.ZBuffer ? m_msaaResolvedSurface.resource - : repo.getTempTexture(width, height, getPixelFormat(srcResource.m_fixedData.Format)).resource; + : repo.getTempTexture(width, height, srcResource.m_fixedData.Format).resource; if (!texture) { return LOG_RESULT(E_OUTOFMEMORY); @@ -1492,7 +1518,7 @@ namespace D3dDdi } } - if (!m_fixedData.Flags.RenderTarget) + if (!m_fixedData.Flags.RenderTarget && !m_fixedData.Flags.ZBuffer) { LONG width = data.DstRect.right - data.DstRect.left; LONG height = data.DstRect.bottom - data.DstRect.top; @@ -1540,7 +1566,7 @@ namespace D3dDdi data.Flags.Linear ? D3DTEXF_LINEAR : D3DTEXF_POINT, data.Flags.SrcColorKey ? &ck : nullptr); } - if (!m_fixedData.Flags.RenderTarget) + if (!m_fixedData.Flags.RenderTarget && !m_fixedData.Flags.ZBuffer) { HRESULT result = copySubResourceRegion(data.hDstResource, data.DstSubResourceIndex, data.DstRect, *dstRes, dstIndex, dstRect); @@ -1563,6 +1589,9 @@ namespace D3dDdi return false; } + D3DDDIARG_BLT blt = {}; + DDraw::setBltSrc(blt); + if (D3DDDIPOOL_SYSTEMMEM == m_fixedData.Pool || D3DDDIFMT_P8 == m_fixedData.Format || m_isOversized || srcResource.m_isOversized) @@ -1604,9 +1633,6 @@ namespace D3dDdi { return; } - m_multiSampleConfig = msaa; - m_formatConfig = formatConfig; - m_scaledSize = scaledSize; if (m_msaaSurface.resource || m_msaaResolvedSurface.resource) { @@ -1622,6 +1648,10 @@ namespace D3dDdi } } + m_multiSampleConfig = msaa; + m_formatConfig = formatConfig; + m_scaledSize = scaledSize; + m_msaaSurface = {}; m_msaaResolvedSurface = {}; m_nullSurface = {}; @@ -1636,39 +1666,35 @@ namespace D3dDdi { g_msaaOverride = msaa; SurfaceRepository::get(m_device.getAdapter()).getSurface(m_msaaSurface, - scaledSize.cx, scaledSize.cy, getPixelFormat(formatConfig), caps, m_fixedData.SurfCount); + scaledSize.cx, scaledSize.cy, formatConfig, caps, m_fixedData.SurfCount); g_msaaOverride = {}; } if (m_fixedData.Flags.ZBuffer && m_msaaSurface.resource && m_device.getAdapter().getInfo().isMsaaDepthResolveSupported) { - g_formatOverride = FOURCC_NULL; g_msaaOverride = msaa; SurfaceRepository::get(m_device.getAdapter()).getSurface(m_nullSurface, - scaledSize.cx, scaledSize.cy, getPixelFormat(D3DDDIFMT_X8R8G8B8), + scaledSize.cx, scaledSize.cy, FOURCC_NULL, DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY, m_fixedData.SurfCount); g_msaaOverride = {}; - g_formatOverride = m_nullSurface.resource ? FOURCC_INTZ : D3DDDIFMT_UNKNOWN; } auto msaaResolvedSurfaceCaps = caps | ((m_fixedData.Flags.ZBuffer || !isScaled) ? 0 : DDSCAPS_TEXTURE); - auto msaaResolvedSurfaceFormat = - (m_fixedData.Flags.ZBuffer || !isScaled) ? getPixelFormat(formatConfig) : getPixelFormat(D3DDDIFMT_A8R8G8B8); SurfaceRepository::get(m_device.getAdapter()).getSurface(m_msaaResolvedSurface, - scaledSize.cx, scaledSize.cy, msaaResolvedSurfaceFormat, msaaResolvedSurfaceCaps, m_fixedData.SurfCount); - g_formatOverride = D3DDDIFMT_UNKNOWN; + scaledSize.cx, scaledSize.cy, m_nullSurface.resource ? FOURCC_INTZ : formatConfig, + msaaResolvedSurfaceCaps, m_fixedData.SurfCount); if (!m_msaaResolvedSurface.resource && m_msaaSurface.resource) { m_msaaSurface = {}; SurfaceRepository::get(m_device.getAdapter()).getSurface(m_msaaResolvedSurface, - scaledSize.cx, scaledSize.cy, msaaResolvedSurfaceFormat, msaaResolvedSurfaceCaps, m_fixedData.SurfCount); + scaledSize.cx, scaledSize.cy, formatConfig, msaaResolvedSurfaceCaps, m_fixedData.SurfCount); } if (!m_fixedData.Flags.ZBuffer && m_msaaResolvedSurface.resource) { SurfaceRepository::get(m_device.getAdapter()).getSurface(m_lockRefSurface, - m_fixedData.pSurfList[0].Width, m_fixedData.pSurfList[0].Height, getPixelFormat(m_fixedData.Format), + m_fixedData.pSurfList[0].Width, m_fixedData.pSurfList[0].Height, m_fixedData.Format, DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY, m_fixedData.SurfCount); if (isScaled) diff --git a/DDrawCompat/D3dDdi/Resource.h b/DDrawCompat/D3dDdi/Resource.h index 6448daa..8827764 100644 --- a/DDrawCompat/D3dDdi/Resource.h +++ b/DDrawCompat/D3dDdi/Resource.h @@ -27,7 +27,7 @@ namespace D3dDdi ~Resource(); operator HANDLE() const { return m_handle; } - const Resource* getCustomResource() { return m_msaaSurface.resource ? m_msaaSurface.resource : m_msaaResolvedSurface.resource; } + Resource* getCustomResource() const { return m_msaaSurface.resource ? m_msaaSurface.resource : m_msaaResolvedSurface.resource; } Device& getDevice() const { return m_device; } const D3DDDIARG_CREATERESOURCE2& getFixedDesc() const { return m_fixedData; } const D3DDDIARG_CREATERESOURCE2& getOrigDesc() const { return m_origData; } @@ -60,6 +60,8 @@ namespace D3dDdi void updateConfig(); void updatePalettizedTexture(UINT stage); + static void setFormatOverride(D3DDDIFORMAT format); + private: class Data : public D3DDDIARG_CREATERESOURCE2 { diff --git a/DDrawCompat/D3dDdi/SurfaceRepository.cpp b/DDrawCompat/D3dDdi/SurfaceRepository.cpp index 324c6b8..c84fc6b 100644 --- a/DDrawCompat/D3dDdi/SurfaceRepository.cpp +++ b/DDrawCompat/D3dDdi/SurfaceRepository.cpp @@ -31,7 +31,7 @@ namespace D3dDdi } CompatPtr SurfaceRepository::createSurface( - DWORD width, DWORD height, const DDPIXELFORMAT& pf, DWORD caps, UINT surfaceCount) + DWORD width, DWORD height, D3DDDIFORMAT format, DWORD caps, UINT surfaceCount) { auto dd(m_adapter.getRepository()); if (!dd) @@ -48,7 +48,7 @@ namespace D3dDdi desc.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CAPS; desc.dwWidth = width; desc.dwHeight = height; - desc.ddpfPixelFormat = pf; + desc.ddpfPixelFormat = getPixelFormat(format); desc.ddsCaps.dwCaps = caps; if (surfaceCount > 1) { @@ -57,10 +57,17 @@ namespace D3dDdi desc.dwBackBufferCount = surfaceCount - 1; } + if (0 == desc.ddpfPixelFormat.dwFlags) + { + desc.ddpfPixelFormat = getPixelFormat((caps & DDSCAPS_ZBUFFER) ? D3DDDIFMT_D16 : D3DDDIFMT_X8R8G8B8); + D3dDdi::Resource::setFormatOverride(format); + } + DDraw::SuppressResourceFormatLogs suppressResourceFormatLogs; s_inCreateSurface = true; HRESULT result = dd.get()->lpVtbl->CreateSurface(dd, &desc, &surface.getRef(), nullptr); s_inCreateSurface = false; + D3dDdi::Resource::setFormatOverride(D3DDDIFMT_UNKNOWN); if (FAILED(result)) { LOG_ONCE("ERROR: Failed to create repository surface: " << Compat::hex(result) << " " << desc); @@ -137,7 +144,7 @@ namespace D3dDdi { result.maskTexture = m_cursorMaskTexture.resource; result.tempTexture = getSurface(m_cursorTempTexture, m_cursorSize.cx, m_cursorSize.cy, - DDraw::DirectDraw::getRgbPixelFormat(32), DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY).resource; + D3DDDIFMT_X8R8G8B8, DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY).resource; if (!result.tempTexture) { return {}; @@ -148,8 +155,7 @@ namespace D3dDdi bool SurfaceRepository::getCursorImage(Surface& surface, HCURSOR cursor, DWORD width, DWORD height, UINT flags) { - if (!getSurface(surface, width, height, getPixelFormat(D3DDDIFMT_A8R8G8B8), - DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY).resource) + if (!getSurface(surface, width, height, D3DDDIFMT_A8R8G8B8, DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY).resource) { return false; } @@ -167,18 +173,12 @@ namespace D3dDdi Resource* SurfaceRepository::getGammaRampTexture() { - DDPIXELFORMAT pf = {}; - pf.dwSize = sizeof(pf); - pf.dwFlags = DDPF_LUMINANCE; - pf.dwLuminanceBitCount = 8; - pf.dwLuminanceBitMask = 0xFF; - return getSurface(m_gammaRampTexture, 256, 3, pf, DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY).resource; + return getSurface(m_gammaRampTexture, 256, 3, D3DDDIFMT_L8, DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY).resource; } Resource* SurfaceRepository::getLogicalXorTexture() { - return getInitializedResource(m_logicalXorTexture, 256, 256, DDraw::DirectDraw::getRgbPixelFormat(8), - DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY, + return getInitializedResource(m_logicalXorTexture, 256, 256, D3DDDIFMT_L8, DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY, [](const DDSURFACEDESC2& desc) { BYTE* p = static_cast(desc.lpSurface); for (UINT y = 0; y < 256; ++y) @@ -193,9 +193,9 @@ namespace D3dDdi } Resource* SurfaceRepository::getInitializedResource(Surface& surface, DWORD width, DWORD height, - const DDPIXELFORMAT& pf, DWORD caps, std::function initFunc) + D3DDDIFORMAT format, DWORD caps, std::function initFunc) { - if (!isLost(surface) || !getSurface(surface, width, height, pf, caps).resource) + if (!isLost(surface) || !getSurface(surface, width, height, format, caps).resource) { return surface.resource; } @@ -216,34 +216,32 @@ namespace D3dDdi Resource* SurfaceRepository::getPaletteTexture() { - return getSurface(m_paletteTexture, 256, 1, getPixelFormat(D3DDDIFMT_A8R8G8B8), - DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY).resource; + return getSurface(m_paletteTexture, 256, 1, D3DDDIFMT_A8R8G8B8, DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY).resource; } SurfaceRepository::Surface& SurfaceRepository::getSurface(Surface& surface, DWORD width, DWORD height, - const DDPIXELFORMAT& pf, DWORD caps, UINT surfaceCount) + D3DDDIFORMAT format, DWORD caps, UINT surfaceCount) { if (!g_enableSurfaceCheck) { return surface; } - if (surface.surface && (surface.width != width || surface.height != height || - 0 != memcmp(&surface.pixelFormat, &pf, sizeof(pf)) || isLost(surface))) + if (surface.width != width || surface.height != height || surface.format != format || isLost(surface)) { surface = {}; } if (!surface.surface) { - surface.surface = createSurface(width, height, pf, caps, surfaceCount); + surface.surface = createSurface(width, height, format, caps, surfaceCount); if (surface.surface) { surface.resource = D3dDdi::Device::findResource( DDraw::DirectDrawSurface::getDriverResourceHandle(*surface.surface)); surface.width = width; surface.height = height; - surface.pixelFormat = pf; + surface.format = format; } } @@ -256,26 +254,26 @@ namespace D3dDdi { m_renderTargets.resize(index + 1); } - return getTempSurface(m_renderTargets[index], width, height, getPixelFormat(D3DDDIFMT_A8R8G8B8), + return getTempSurface(m_renderTargets[index], width, height, D3DDDIFMT_A8R8G8B8, DDSCAPS_3DDEVICE | DDSCAPS_TEXTURE | DDSCAPS_VIDEOMEMORY); } SurfaceRepository::Surface& SurfaceRepository::getTempSurface(Surface& surface, DWORD width, DWORD height, - const DDPIXELFORMAT& pf, DWORD caps, UINT surfaceCount) + D3DDDIFORMAT format, DWORD caps, UINT surfaceCount) { - return getSurface(surface, max(width, surface.width), max(height, surface.height), pf, caps, surfaceCount); + return getSurface(surface, max(width, surface.width), max(height, surface.height), format, caps, surfaceCount); } SurfaceRepository::Surface& SurfaceRepository::getTempSysMemSurface(DWORD width, DWORD height) { - return getTempSurface(m_sysMemSurface, width, height, getPixelFormat(D3DDDIFMT_A8R8G8B8), + return getTempSurface(m_sysMemSurface, width, height, D3DDDIFMT_A8R8G8B8, DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY); } - const SurfaceRepository::Surface& SurfaceRepository::getTempTexture(DWORD width, DWORD height, const DDPIXELFORMAT& pf) + const SurfaceRepository::Surface& SurfaceRepository::getTempTexture(DWORD width, DWORD height, D3DDDIFORMAT format) { - return getTempSurface(m_textures[pf], width, height, pf, - (pf.dwRGBBitCount > 8 ? DDSCAPS_TEXTURE : 0) | DDSCAPS_VIDEOMEMORY); + return getTempSurface(m_textures[format], width, height, format, + (D3DDDIFMT_P8 == format ? 0 : DDSCAPS_TEXTURE) | DDSCAPS_VIDEOMEMORY); } bool SurfaceRepository::hasAlpha(CompatRef surface) diff --git a/DDrawCompat/D3dDdi/SurfaceRepository.h b/DDrawCompat/D3dDdi/SurfaceRepository.h index 8afb47a..d8e0c63 100644 --- a/DDrawCompat/D3dDdi/SurfaceRepository.h +++ b/DDrawCompat/D3dDdi/SurfaceRepository.h @@ -7,7 +7,6 @@ #include #include -#include namespace D3dDdi { @@ -33,7 +32,7 @@ namespace D3dDdi Resource* resource = nullptr; DWORD width = 0; DWORD height = 0; - DDPIXELFORMAT pixelFormat = {}; + D3DDDIFORMAT format = D3DDDIFMT_UNKNOWN; }; Cursor getCursor(HCURSOR cursor); @@ -41,12 +40,12 @@ namespace D3dDdi Resource* getPaletteTexture(); Resource* getGammaRampTexture(); Surface& getSurface(Surface& surface, DWORD width, DWORD height, - const DDPIXELFORMAT& pf, DWORD caps, UINT surfaceCount = 1); + D3DDDIFORMAT format, DWORD caps, UINT surfaceCount = 1); const Surface& getTempRenderTarget(DWORD width, DWORD height, UINT index = 0); Surface& getTempSysMemSurface(DWORD width, DWORD height); Surface& getTempSurface(Surface& surface, DWORD width, DWORD height, - const DDPIXELFORMAT& pf, DWORD caps, UINT surfaceCount = 1); - const Surface& getTempTexture(DWORD width, DWORD height, const DDPIXELFORMAT& pf); + D3DDDIFORMAT format, DWORD caps, UINT surfaceCount = 1); + const Surface& getTempTexture(DWORD width, DWORD height, D3DDDIFORMAT format); void release(Surface& surface); static SurfaceRepository& get(const Adapter& adapter); @@ -57,9 +56,9 @@ namespace D3dDdi SurfaceRepository(const Adapter& adapter); CompatPtr createSurface(DWORD width, DWORD height, - const DDPIXELFORMAT& pf, DWORD caps, UINT surfaceCount); + D3DDDIFORMAT format, DWORD caps, UINT surfaceCount); bool getCursorImage(Surface& surface, HCURSOR cursor, DWORD width, DWORD height, UINT flags); - Resource* getInitializedResource(Surface& surface, DWORD width, DWORD height, const DDPIXELFORMAT& pf, DWORD caps, + Resource* getInitializedResource(Surface& surface, DWORD width, DWORD height, D3DDDIFORMAT format, DWORD caps, std::function initFunc); bool hasAlpha(CompatRef surface); bool isLost(Surface& surface); @@ -75,7 +74,7 @@ namespace D3dDdi Surface m_logicalXorTexture; Surface m_paletteTexture; std::vector m_renderTargets; - std::map m_textures; + std::map m_textures; std::vector m_releasedSurfaces; Surface m_sysMemSurface; diff --git a/DDrawCompat/DDraw/RealPrimarySurface.cpp b/DDrawCompat/DDraw/RealPrimarySurface.cpp index a8fee56..db99135 100644 --- a/DDrawCompat/DDraw/RealPrimarySurface.cpp +++ b/DDrawCompat/DDraw/RealPrimarySurface.cpp @@ -194,7 +194,7 @@ namespace auto& repo = D3dDdi::SurfaceRepository::get(device->getAdapter()); D3dDdi::SurfaceRepository::Surface surface = {}; - repo.getSurface(surface, width, height, DDraw::DirectDraw::getRgbPixelFormat(32), + repo.getSurface(surface, width, height, D3DDDIFMT_X8R8G8B8, DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY); if (!surface.surface) { diff --git a/DDrawCompat/DDraw/Surfaces/PrimarySurface.cpp b/DDrawCompat/DDraw/Surfaces/PrimarySurface.cpp index 5729a68..4222d4d 100644 --- a/DDrawCompat/DDraw/Surfaces/PrimarySurface.cpp +++ b/DDrawCompat/DDraw/Surfaces/PrimarySurface.cpp @@ -52,7 +52,7 @@ namespace auto& repo = D3dDdi::SurfaceRepository::get(device->getAdapter()); D3dDdi::SurfaceRepository::Surface surface = {}; - repo.getSurface(surface, 1, 1, DDraw::DirectDraw::getRgbPixelFormat(32), DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY); + repo.getSurface(surface, 1, 1, D3DDDIFMT_X8R8G8B8, DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY); LOG_RESULT(surface.surface.get()); return surface.surface; diff --git a/DDrawCompat/DDraw/Surfaces/SurfaceImpl.cpp b/DDrawCompat/DDraw/Surfaces/SurfaceImpl.cpp index 1f0bb91..445dfec 100644 --- a/DDrawCompat/DDraw/Surfaces/SurfaceImpl.cpp +++ b/DDrawCompat/DDraw/Surfaces/SurfaceImpl.cpp @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -65,17 +66,16 @@ namespace return bltFunc(This, lpDDSrcSurface, lpSrcRect); } - auto srcResource = DDraw::DirectDrawSurface::getDriverResourceHandle(*lpDDSrcSurface); - auto device = D3dDdi::Device::findDeviceByResource(srcResource); - if (!device) + auto srcResource = D3dDdi::Device::findResource(DDraw::DirectDrawSurface::getDriverResourceHandle(*lpDDSrcSurface)); + if (!srcResource) { return bltFunc(This, lpDDSrcSurface, lpSrcRect); } - auto& repo = D3dDdi::SurfaceRepository::get(device->getAdapter()); + auto& repo = D3dDdi::SurfaceRepository::get(srcResource->getDevice().getAdapter()); RECT srcRect = getRect(lpSrcRect, srcDesc); auto& tex = repo.getTempTexture(srcRect.right - srcRect.left, srcRect.bottom - srcRect.top, - srcDesc.ddpfPixelFormat); + srcResource->getOrigDesc().Format); if (!tex.resource) { return bltFunc(This, lpDDSrcSurface, lpSrcRect); @@ -86,7 +86,7 @@ namespace HRESULT result = getOrigVtable(This).GetColorKey(lpDDSrcSurface, DDCKEY_SRCBLT, &ck); getOrigVtable(This).SetColorKey(newSrcSurface, DDCKEY_SRCBLT, SUCCEEDED(result) ? &ck : nullptr); - g_bltSrcResource = srcResource; + g_bltSrcResource = *srcResource; g_bltSrcSubResourceIndex = DDraw::DirectDrawSurface::getSubResourceIndex(*lpDDSrcSurface); g_bltSrcRect = getRect(lpSrcRect, srcDesc); diff --git a/DDrawCompat/DDrawCompat.vcxproj b/DDrawCompat/DDrawCompat.vcxproj index 93b4f5f..cebe649 100644 --- a/DDrawCompat/DDrawCompat.vcxproj +++ b/DDrawCompat/DDrawCompat.vcxproj @@ -167,6 +167,7 @@ + diff --git a/DDrawCompat/DDrawCompat.vcxproj.filters b/DDrawCompat/DDrawCompat.vcxproj.filters index 07aa254..c092d4a 100644 --- a/DDrawCompat/DDrawCompat.vcxproj.filters +++ b/DDrawCompat/DDrawCompat.vcxproj.filters @@ -648,6 +648,9 @@ Header Files\Config\Settings + + Header Files\Config\Settings + diff --git a/DDrawCompat/Overlay/ConfigWindow.cpp b/DDrawCompat/Overlay/ConfigWindow.cpp index 9ce0eeb..d6bf5b7 100644 --- a/DDrawCompat/Overlay/ConfigWindow.cpp +++ b/DDrawCompat/Overlay/ConfigWindow.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -30,7 +31,7 @@ namespace namespace Overlay { ConfigWindow::ConfigWindow() - : Window(nullptr, { 0, 0, SettingControl::TOTAL_WIDTH, 430 }, WS_BORDER, Config::configHotKey.get()) + : Window(nullptr, { 0, 0, SettingControl::TOTAL_WIDTH, 455 }, WS_BORDER, Config::configHotKey.get()) , m_buttonCount(0) , m_focus(nullptr) { @@ -43,6 +44,7 @@ namespace Overlay addControl(Config::alternatePixelCenter); addControl(Config::antialiasing); addControl(Config::bltFilter); + addControl(Config::depthFormat); addControl(Config::displayFilter); addControl(Config::fontAntialiasing); addControl(Config::fpsLimiter); diff --git a/DDrawCompat/Overlay/SettingControl.cpp b/DDrawCompat/Overlay/SettingControl.cpp index 3cbd32a..ccac3e8 100644 --- a/DDrawCompat/Overlay/SettingControl.cpp +++ b/DDrawCompat/Overlay/SettingControl.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -82,6 +83,7 @@ namespace Overlay } if (&Config::antialiasing == &m_setting || + &Config::depthFormat == &m_setting || &Config::renderColorDepth == &m_setting || &Config::resolutionScale == &m_setting || &Config::spriteFilter == &m_setting ||