From ee83a95c52c2a5b24335bdde4a7d088702e16262 Mon Sep 17 00:00:00 2001 From: narzoul Date: Thu, 26 May 2016 00:00:48 +0200 Subject: [PATCH] Added DDSCAPS_OFFSCREENPLAIN to surfaces with no type capability When a surface is created without an explicit capability to specify the type of surface to create, it only accepts a pixel format that matches the current display mode. Since the display mode is forced to 32 bit color depth under DDrawCompat, creating such surfaces could either fail if a different pixel format is specified (even though it could match the emulated color depth), or it could be created with the wrong color depth if no pixel format is given. To prevent these issues, the DDSCAPS_OFFSCREENPLAIN capability is added to all "untyped" surfaces, which accepts any color depth and already has code in place to match the emulated display mode's color depth when no pixel format is given. Fixes #1 --- DDrawCompat/CompatDirectDraw.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/DDrawCompat/CompatDirectDraw.cpp b/DDrawCompat/CompatDirectDraw.cpp index bf8c82a..d8388d1 100644 --- a/DDrawCompat/CompatDirectDraw.cpp +++ b/DDrawCompat/CompatDirectDraw.cpp @@ -117,18 +117,27 @@ HRESULT STDMETHODCALLTYPE CompatDirectDraw::CreateSurface( else { if (lpDDSurfaceDesc && - !(lpDDSurfaceDesc->dwFlags & DDSD_PIXELFORMAT) && (lpDDSurfaceDesc->dwFlags & DDSD_WIDTH) && (lpDDSurfaceDesc->dwFlags & DDSD_HEIGHT) && !((lpDDSurfaceDesc->dwFlags & DDSD_CAPS) && - (lpDDSurfaceDesc->ddsCaps.dwCaps & (DDSCAPS_ALPHA | DDSCAPS_ZBUFFER)))) + (lpDDSurfaceDesc->ddsCaps.dwCaps & (DDSCAPS_ALPHA | DDSCAPS_ZBUFFER)))) { CompatPtr dd(Compat::queryInterface(This)); auto dm = CompatDisplayMode::getDisplayMode(*dd); TSurfaceDesc desc = *lpDDSurfaceDesc; - desc.dwFlags |= DDSD_PIXELFORMAT; - desc.ddpfPixelFormat = dm.pixelFormat; + if (!(desc.dwFlags & DDSD_PIXELFORMAT)) + { + desc.dwFlags |= DDSD_PIXELFORMAT; + desc.ddpfPixelFormat = dm.pixelFormat; + } + if (!((desc.dwFlags & DDSD_CAPS) && + (desc.ddsCaps.dwCaps & (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_OVERLAY | DDSCAPS_TEXTURE | + DDSCAPS_FRONTBUFFER | DDSCAPS_BACKBUFFER)))) + { + desc.dwFlags |= DDSD_CAPS; + desc.ddsCaps.dwCaps |= DDSCAPS_OFFSCREENPLAIN; + } result = s_origVtable.CreateSurface(This, &desc, lplpDDSurface, pUnkOuter); } else