diff --git a/DDrawCompat/D3dDdi/Adapter.cpp b/DDrawCompat/D3dDdi/Adapter.cpp index 580f518..2974a28 100644 --- a/DDrawCompat/D3dDdi/Adapter.cpp +++ b/DDrawCompat/D3dDdi/Adapter.cpp @@ -145,10 +145,6 @@ namespace D3dDdi auto p8FormatOp = formatOp.second; p8FormatOp.Format = D3DDDIFMT_P8; p8FormatOp.Operations |= FORMATOP_OFFSCREENPLAIN; - if (!Config::palettizedTextures.get()) - { - p8FormatOp.Operations &= ~(FORMATOP_TEXTURE | FORMATOP_VOLUMETEXTURE | FORMATOP_CUBETEXTURE); - } fixedFormatOps[D3DDDIFMT_P8] = p8FormatOp; } diff --git a/DDrawCompat/DDraw/DirectDraw.cpp b/DDrawCompat/DDraw/DirectDraw.cpp index cf01c57..dcb4d1c 100644 --- a/DDrawCompat/DDraw/DirectDraw.cpp +++ b/DDrawCompat/DDraw/DirectDraw.cpp @@ -1,6 +1,5 @@ #include #include -#include #include #include @@ -23,6 +22,7 @@ #include #include #include +#include namespace { @@ -47,12 +47,15 @@ namespace TSurfaceDesc desc = *lpDDSurfaceDesc; if (!D3dDdi::SurfaceRepository::inCreateSurface()) { + const bool isPalettized = (desc.dwFlags & DDSD_PIXELFORMAT) + ? (desc.ddpfPixelFormat.dwFlags & DDPF_PALETTEINDEXED8) + : (Win32::DisplayMode::getBpp() <= 8); + if (&IID_IDirect3DHALDevice == Config::softwareDevice.get()) { if ((desc.ddsCaps.dwCaps & DDSCAPS_SYSTEMMEMORY) && !(desc.ddsCaps.dwCaps & DDSCAPS_3DDEVICE) && - (desc.dwFlags & DDSD_PIXELFORMAT) && - (DDPF_RGB | DDPF_PALETTEINDEXED8) == desc.ddpfPixelFormat.dwFlags) + isPalettized) { desc.ddsCaps.dwCaps |= DDSCAPS_TEXTURE; desc.ddsCaps.dwCaps &= ~DDSCAPS_OFFSCREENPLAIN; @@ -66,18 +69,28 @@ namespace } } - if (Config::palettizedTextures.get() && - (desc.ddsCaps.dwCaps & DDSCAPS_TEXTURE) && - !(desc.ddsCaps.dwCaps & DDSCAPS_SYSTEMMEMORY) && - (desc.dwFlags & DDSD_PIXELFORMAT) && - (DDPF_RGB | DDPF_PALETTEINDEXED8) == desc.ddpfPixelFormat.dwFlags) + if (isPalettized && (desc.ddsCaps.dwCaps & DDSCAPS_TEXTURE)) { - return DDraw::PalettizedTexture::create(*This, desc, *lplpDDSurface); + if (Config::palettizedTextures.get()) + { + if (!(desc.ddsCaps.dwCaps & DDSCAPS_SYSTEMMEMORY)) + { + return DDraw::PalettizedTexture::create(*This, desc, *lplpDDSurface); + } + } + else if (desc.ddsCaps.dwCaps & DDSCAPS_VIDEOMEMORY) + { + return DDERR_UNSUPPORTED; + } + else + { + desc.ddsCaps.dwCaps |= DDSCAPS_SYSTEMMEMORY; + } } } - return DDraw::Surface::create( - *This, desc, *lplpDDSurface, std::make_unique(desc.dwFlags, desc.ddsCaps.dwCaps)); + return DDraw::Surface::create(*This, desc, *lplpDDSurface, + std::make_unique(desc.dwFlags, lpDDSurfaceDesc->ddsCaps.dwCaps)); } template diff --git a/DDrawCompat/DDraw/Surfaces/Surface.cpp b/DDrawCompat/DDraw/Surfaces/Surface.cpp index 2a439c0..c82b118 100644 --- a/DDrawCompat/DDraw/Surfaces/Surface.cpp +++ b/DDrawCompat/DDraw/Surfaces/Surface.cpp @@ -91,8 +91,9 @@ namespace DDraw CompatRef dd, TSurfaceDesc desc, TSurface*& surface, std::unique_ptr privateData) { if ((desc.ddsCaps.dwCaps & DDSCAPS_3DDEVICE) && - ((desc.dwFlags & DDSD_PIXELFORMAT) && (desc.ddpfPixelFormat.dwRGBBitCount <= 8)) || - (!(desc.dwFlags & DDSD_PIXELFORMAT) && Win32::DisplayMode::getBpp() <= 8)) + ((desc.dwFlags & DDSD_PIXELFORMAT) + ? (desc.ddpfPixelFormat.dwFlags & DDPF_PALETTEINDEXED8) + : (Win32::DisplayMode::getBpp() <= 8))) { desc.ddsCaps.dwCaps &= ~DDSCAPS_3DDEVICE; } diff --git a/DDrawCompat/Direct3d/Direct3dDevice.cpp b/DDrawCompat/Direct3d/Direct3dDevice.cpp index fa44015..b8f2fbc 100644 --- a/DDrawCompat/Direct3d/Direct3dDevice.cpp +++ b/DDrawCompat/Direct3d/Direct3dDevice.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include @@ -27,6 +28,10 @@ namespace // and with proper pixel formats these cannot be created in video memory anyway. return false; } + if ((pf.dwFlags & DDPF_PALETTEINDEXED8) && !Config::palettizedTextures.get()) + { + return false; + } return Config::supportedTextureFormats.isSupported(D3dDdi::getFormat(pf)); }