diff --git a/src/main.c b/src/main.c index 1c61bd4..c946b65 100644 --- a/src/main.c +++ b/src/main.c @@ -18,8 +18,8 @@ #include #include #include +#include #include "ddraw.h" - #include "main.h" #include "palette.h" #include "surface.h" @@ -38,6 +38,9 @@ void mouse_unlock(); BOOL screenshot(struct IDirectDrawSurfaceImpl *); #endif +extern HMODULE hD3D9; +extern D3DPRESENT_PARAMETERS D3dpp; + IDirectDrawImpl *ddraw = NULL; DWORD WINAPI render_main(void); @@ -237,6 +240,7 @@ HRESULT __stdcall ddraw_RestoreDisplayMode(IDirectDrawImpl *This) if(!ddraw->windowed) { ChangeDisplaySettings(&This->mode, 0); + InterlockedExchange(&ddraw->resetDirect3D9, TRUE); } return DD_OK; @@ -504,11 +508,12 @@ void ToggleFullscreen() mouse_unlock(); if(ChangeDisplaySettings(&ddraw->render.mode, CDS_FULLSCREEN) == DISP_CHANGE_SUCCESSFUL) { - ddraw->windowed = FALSE; + D3dpp.Windowed = ddraw->windowed = FALSE; SetWindowLong(ddraw->hWnd, GWL_STYLE, GetWindowLong(ddraw->hWnd, GWL_STYLE) & ~(WS_CAPTION | WS_THICKFRAME | WS_MINIMIZE | WS_MAXIMIZE | WS_SYSMENU)); SetWindowPos(ddraw->hWnd, HWND_TOPMOST, 0, 0, ddraw->render.width, ddraw->render.height, SWP_SHOWWINDOW); LastSetWindowPosTick = timeGetTime(); + InterlockedExchange(&ddraw->resetDirect3D9, TRUE); } mouse_lock(); } @@ -534,8 +539,9 @@ void ToggleFullscreen() SetWindowPos(ddraw->hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); MoveWindow(ddraw->hWnd, dst.left, dst.top, (dst.right - dst.left), (dst.bottom - dst.top), TRUE); - ddraw->windowed = TRUE; + D3dpp.Windowed = ddraw->windowed = TRUE; ddraw->windowed_init = TRUE; + InterlockedExchange(&ddraw->resetDirect3D9, TRUE); } mouse_lock(); } @@ -1224,28 +1230,9 @@ HRESULT WINAPI DirectDrawCreate(GUID FAR* lpGUID, LPDIRECTDRAW FAR* lplpDD, IUnk DWORD version = GetVersion(); DWORD major = (DWORD)(LOBYTE(LOWORD(version))); DWORD minor = (DWORD)(HIBYTE(LOWORD(version))); - BOOL useDirect3D = FALSE; - if (!This->wine && (major < 6 || (major == 6 && minor <= 1))) - { - BOOL dwmEnabled = TRUE; - - HMODULE hDwmapi = LoadLibrary("Dwmapi.dll"); - if (hDwmapi) - { - HRESULT(WINAPI *DwmIsCompositionEnabled)(BOOL*) = - (HRESULT(WINAPI *)(BOOL*))GetProcAddress(hDwmapi, "DwmIsCompositionEnabled"); - - if (DwmIsCompositionEnabled) - DwmIsCompositionEnabled(&dwmEnabled); - - FreeLibrary(hDwmapi); - } - - useDirect3D = !hDwmapi || !dwmEnabled; - } - - if (useDirect3D && FreeLibrary(LoadLibrary("d3d9.dll"))) + // Win 7 and below use Direct3D 9 - Win 8/10 and wine use OpenGL + if (!This->wine && (major < 6 || (major == 6 && minor <= 1)) && (hD3D9 = LoadLibrary("d3d9.dll"))) This->renderer = render_d3d9_main; else This->renderer = render_main; diff --git a/src/render_d3d9.c b/src/render_d3d9.c index 362608d..b2f456e 100644 --- a/src/render_d3d9.c +++ b/src/render_d3d9.c @@ -7,14 +7,14 @@ typedef struct CUSTOMVERTEX { float x, y, z, rhw, u, v; } CUSTOMVERTEX; -static HMODULE hD3D9; +HMODULE hD3D9; +D3DPRESENT_PARAMETERS D3dpp; static LPDIRECT3D9 D3d; static LPDIRECT3DDEVICE9 D3ddev; static LPDIRECT3DVERTEXBUFFER9 D3dvb; static IDirect3DTexture9 *SurfaceTex; static IDirect3DTexture9 *PaletteTex; static IDirect3DPixelShader9 *PixelShader; -static D3DPRESENT_PARAMETERS D3dpp; static float ScaleW; static float ScaleH; static int MaxFPS; @@ -246,6 +246,7 @@ static void Render() if (InterlockedExchange(&ddraw->render.surfaceUpdated, FALSE)) { RECT rc = { 0,0,ddraw->width,ddraw->height }; + if (SUCCEEDED(SurfaceTex->lpVtbl->LockRect(SurfaceTex, 0, &lock_rc, &rc, 0))) { unsigned char *src = (unsigned char *)ddraw->primary->surface; @@ -267,9 +268,11 @@ static void Render() if (InterlockedExchange(&ddraw->render.paletteUpdated, FALSE)) { RECT rc = { 0,0,256,1 }; + if (SUCCEEDED(PaletteTex->lpVtbl->LockRect(PaletteTex, 0, &lock_rc, &rc, 0))) { memcpy(lock_rc.pBits, ddraw->primary->palette->data_rgb, 4 * 256); + PaletteTex->lpVtbl->UnlockRect(PaletteTex, 0); } }