From 95f31cdd7e6f1821c810952b01a1c06ff782cb2e Mon Sep 17 00:00:00 2001 From: Ritchie Swann Date: Sun, 11 Aug 2024 09:29:41 +0100 Subject: [PATCH 01/13] mingw64 requires including cstdint --- libraries/ZVulkan/src/glslang/glslang/Include/Common.h | 1 + 1 file changed, 1 insertion(+) diff --git a/libraries/ZVulkan/src/glslang/glslang/Include/Common.h b/libraries/ZVulkan/src/glslang/glslang/Include/Common.h index 4f888ae16..87ec92f27 100644 --- a/libraries/ZVulkan/src/glslang/glslang/Include/Common.h +++ b/libraries/ZVulkan/src/glslang/glslang/Include/Common.h @@ -41,6 +41,7 @@ #include #include #include +#include #include #include #include From e3795c762a4bc9c72cf7b23278897a835776132b Mon Sep 17 00:00:00 2001 From: Ritchie Swann Date: Sun, 11 Aug 2024 09:30:06 +0100 Subject: [PATCH 02/13] Fix preprocessor symbol for Windows --- libraries/ZWidget/src/window/window.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/ZWidget/src/window/window.cpp b/libraries/ZWidget/src/window/window.cpp index 234be61e4..b67b1a296 100644 --- a/libraries/ZWidget/src/window/window.cpp +++ b/libraries/ZWidget/src/window/window.cpp @@ -2,7 +2,7 @@ #include "window/window.h" #include -#ifdef WIN32 +#ifdef _WIN32 #include "win32/win32window.h" From 67d573cd41fdc4c78e5c38b1448da4b2b21179c4 Mon Sep 17 00:00:00 2001 From: Ritchie Swann Date: Sun, 11 Aug 2024 09:30:20 +0100 Subject: [PATCH 03/13] Use TCHAR for Windows --- libraries/ZWidget/src/window/win32/win32window.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/libraries/ZWidget/src/window/win32/win32window.cpp b/libraries/ZWidget/src/window/win32/win32window.cpp index 3ba21698a..54350513d 100644 --- a/libraries/ZWidget/src/window/win32/win32window.cpp +++ b/libraries/ZWidget/src/window/win32/win32window.cpp @@ -1,6 +1,7 @@ #include "win32window.h" #include +#include #include #include #include @@ -65,7 +66,7 @@ Win32Window::Win32Window(DisplayWindowHost* windowHost) : WindowHost(windowHost) classdesc.cbSize = sizeof(WNDCLASSEX); classdesc.hInstance = GetModuleHandle(0); classdesc.style = CS_VREDRAW | CS_HREDRAW | CS_DBLCLKS; - classdesc.lpszClassName = L"ZWidgetWindow"; + classdesc.lpszClassName = _T( "ZWidgetWindow" ); classdesc.lpfnWndProc = &Win32Window::WndProc; RegisterClassEx(&classdesc); @@ -74,7 +75,7 @@ Win32Window::Win32Window(DisplayWindowHost* windowHost) : WindowHost(windowHost) // WS_CAPTION shows the caption (yay! actually a flag that does what it says it does!) // WS_SYSMENU shows the min/max/close buttons // WS_THICKFRAME makes the window resizable - CreateWindowEx(WS_EX_APPWINDOW | WS_EX_DLGMODALFRAME, L"ZWidgetWindow", L"", WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX, 0, 0, 100, 100, 0, 0, GetModuleHandle(0), this); + CreateWindowEx(WS_EX_APPWINDOW | WS_EX_DLGMODALFRAME, _T( "ZWidgetWindow" ), _T( "" ), WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX, 0, 0, 100, 100, 0, 0, GetModuleHandle(0), this); /* RAWINPUTDEVICE rid; @@ -278,7 +279,7 @@ double Win32Window::GetDpiScale() const static bool done = false; if (!done) { - HMODULE hMod = GetModuleHandleA("User32.dll"); + HMODULE hMod = GetModuleHandle( _T( "User32.dll" )); if (hMod != nullptr) pGetDpiForWindow = reinterpret_cast(GetProcAddress(hMod, "GetDpiForWindow")); done = true; } @@ -387,8 +388,10 @@ void Win32Window::PresentBitmap(int width, int height, const uint32_t* pixels) LRESULT Win32Window::OnWindowMessage(UINT msg, WPARAM wparam, LPARAM lparam) { LPARAM result = 0; - if (DwmDefWindowProc(WindowHandle, msg, wparam, lparam, &result)) - return result; + + // DwmDefWindowProc is not a publicly defined symbol on Windows 11 + /*if (DwmDefWindowProc(WindowHandle, msg, wparam, lparam, &result)) + return result;*/ if (msg == WM_INPUT) { From 8f7b0ef4eb958501ee785ff96ae318914fb4d9b0 Mon Sep 17 00:00:00 2001 From: Ritchie Swann Date: Sun, 11 Aug 2024 09:31:20 +0100 Subject: [PATCH 04/13] Fix libraries on mingw64 dxguid and dwmapi are required on mingw64 and give linker errors if missing legacy_studio_definitions is not in the latest mingw64 --- src/CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 37d5d4839..dabeb3642 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -69,7 +69,9 @@ if( WIN32 ) setupapi oleaut32 dbghelp - legacy_stdio_definitions ) + dxguid + dwmapi + ) if( DEM_CMAKE_COMPILER_IS_GNUCXX_COMPATIBLE ) if( DX_dxguid_LIBRARY ) From e1e5ae16e2501858e3ec5fec5fdb4132abc3d737 Mon Sep 17 00:00:00 2001 From: Ritchie Swann Date: Sun, 11 Aug 2024 09:32:05 +0100 Subject: [PATCH 05/13] Fix namespace issue windows.h must be included in the main namespace on mingw64, otherwise there are loads of compile errors --- src/common/filesystem/source/critsec.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/common/filesystem/source/critsec.cpp b/src/common/filesystem/source/critsec.cpp index 874ade79f..b8b8c5522 100644 --- a/src/common/filesystem/source/critsec.cpp +++ b/src/common/filesystem/source/critsec.cpp @@ -31,8 +31,6 @@ ** */ -namespace FileSys { - #ifdef _WIN32 #ifndef _WINNT_ @@ -40,6 +38,8 @@ namespace FileSys { #include #endif +namespace FileSys { + class FInternalCriticalSection { public: @@ -82,6 +82,8 @@ void LeaveCriticalSection(FInternalCriticalSection *c) #include +namespace FileSys { + class FInternalCriticalSection { public: From 801dc4aaac3dbd0c46477d175091d6219fbfa8ac Mon Sep 17 00:00:00 2001 From: Ritchie Swann Date: Sun, 11 Aug 2024 09:32:19 +0100 Subject: [PATCH 06/13] sys/stat.h is required on all platforms --- src/common/filesystem/source/fs_findfile.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/common/filesystem/source/fs_findfile.cpp b/src/common/filesystem/source/fs_findfile.cpp index 9bc32e75e..e3d515ab1 100644 --- a/src/common/filesystem/source/fs_findfile.cpp +++ b/src/common/filesystem/source/fs_findfile.cpp @@ -35,6 +35,7 @@ #include "fs_findfile.h" #include #include +#include #ifndef _WIN32 @@ -45,8 +46,6 @@ #endif #include #include -#include - #include #endif From 120c0fb5caa41fb49de123d2e637a7e3baea9aee Mon Sep 17 00:00:00 2001 From: Ritchie Swann Date: Sun, 11 Aug 2024 09:32:33 +0100 Subject: [PATCH 07/13] Use TCHAR on Windows --- src/common/rendering/gl_load/gl_load.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/common/rendering/gl_load/gl_load.c b/src/common/rendering/gl_load/gl_load.c index 14aba7a70..f50830528 100644 --- a/src/common/rendering/gl_load/gl_load.c +++ b/src/common/rendering/gl_load/gl_load.c @@ -46,6 +46,7 @@ static void* PosixGetProcAddress (const GLubyte* name) #undef APIENTRY #endif #include +#include #ifdef _MSC_VER @@ -76,7 +77,7 @@ static void CheckOpenGL(void) { if (opengl32dll == 0) { - opengl32dll = LoadLibrary(L"OpenGL32.DLL"); + opengl32dll = LoadLibrary(_T("OpenGL32.DLL")); if (opengl32dll != 0) { createcontext = (HGLRC(WINAPI*)(HDC)) GetProcAddress(opengl32dll, "wglCreateContext"); From 709d5dd742ae0d18185a10d42916aa6d858dc097 Mon Sep 17 00:00:00 2001 From: Ritchie Swann Date: Sun, 11 Aug 2024 10:08:32 +0100 Subject: [PATCH 08/13] Keep legacy_studio_definitions for non mingw64 toolchain --- src/CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index dabeb3642..e10d2cd1f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -73,11 +73,16 @@ if( WIN32 ) dwmapi ) + if( NOT MINGW ) + list( APPEND PROJECT_LIBRARIES legacy_stdio_definitions ) + endif() + if( DEM_CMAKE_COMPILER_IS_GNUCXX_COMPATIBLE ) if( DX_dxguid_LIBRARY ) list( APPEND PROJECT_LIBRARIES "${DX_dxguid_LIBRARY}" ) endif() endif() + else() if( APPLE ) set( NO_GTK ON ) From 699bef1316f9b44572489537a1c869e9dbbd0268 Mon Sep 17 00:00:00 2001 From: Ritchie Swann Date: Sun, 11 Aug 2024 10:33:10 +0100 Subject: [PATCH 09/13] Better solution for DwmDefWindowProc on mingw64 On mingw, create our own thunk for DwmDefWindowProc. It should exist in libdwmapi.a (and exists in MSVC), but doesn't. --- libraries/ZWidget/CMakeLists.txt | 3 +++ .../ZWidget/src/window/win32/win32window.cpp | 25 ++++++++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/libraries/ZWidget/CMakeLists.txt b/libraries/ZWidget/CMakeLists.txt index dd836cd6d..68c048e22 100644 --- a/libraries/ZWidget/CMakeLists.txt +++ b/libraries/ZWidget/CMakeLists.txt @@ -120,6 +120,9 @@ include_directories(include include/zwidget src) if(WIN32) set(ZWIDGET_SOURCES ${ZWIDGET_SOURCES} ${ZWIDGET_WIN32_SOURCES}) add_definitions(-DUNICODE -D_UNICODE) + if(MINGW) + add_definitions(-DMINGW) + endif() elseif(APPLE) set(ZWIDGET_SOURCES ${ZWIDGET_SOURCES} ${ZWIDGET_COCOA_SOURCES}) set(ZWIDGET_LIBS ${CMAKE_DL_LIBS} -ldl) diff --git a/libraries/ZWidget/src/window/win32/win32window.cpp b/libraries/ZWidget/src/window/win32/win32window.cpp index 54350513d..958c3fef6 100644 --- a/libraries/ZWidget/src/window/win32/win32window.cpp +++ b/libraries/ZWidget/src/window/win32/win32window.cpp @@ -29,6 +29,26 @@ #define RIDEV_INPUTSINK (0x100) #endif +#ifdef MINGW +// MinGW's library doesn't contain a thunk for DwmDefWindowProc, so we need to create our own + +BOOL DwmDefWindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, LRESULT *plResult ) +{ + typedef LRESULT(* dwmdwp)(HWND, UINT, WPARAM, LPARAM ); + BOOL result(false); + HMODULE module = LoadLibrary( _T( "dwmapi.dll" ) ); + if( module ) { + dwmdwp proc = reinterpret_cast( GetProcAddress( module, "DwmDefWindowProc" ) ); + if( proc ) { + *plResult = proc( hWnd, msg, wParam, lParam ); + } + FreeLibrary(module); + } + return result; +} + +#endif + static std::string from_utf16(const std::wstring& str) { if (str.empty()) return {}; @@ -389,9 +409,8 @@ LRESULT Win32Window::OnWindowMessage(UINT msg, WPARAM wparam, LPARAM lparam) { LPARAM result = 0; - // DwmDefWindowProc is not a publicly defined symbol on Windows 11 - /*if (DwmDefWindowProc(WindowHandle, msg, wparam, lparam, &result)) - return result;*/ + if (DwmDefWindowProc(WindowHandle, msg, wparam, lparam, &result)) + return result; if (msg == WM_INPUT) { From 42c64e438f5b5020e9e281f61c54c7e43cbda648 Mon Sep 17 00:00:00 2001 From: Ritchie Swann Date: Sun, 11 Aug 2024 10:34:34 +0100 Subject: [PATCH 10/13] fix faux pas --- libraries/ZWidget/src/window/win32/win32window.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libraries/ZWidget/src/window/win32/win32window.cpp b/libraries/ZWidget/src/window/win32/win32window.cpp index 958c3fef6..f86fc669d 100644 --- a/libraries/ZWidget/src/window/win32/win32window.cpp +++ b/libraries/ZWidget/src/window/win32/win32window.cpp @@ -35,12 +35,13 @@ BOOL DwmDefWindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, LRESULT *plResult ) { typedef LRESULT(* dwmdwp)(HWND, UINT, WPARAM, LPARAM ); - BOOL result(false); + BOOL result(FALSE); HMODULE module = LoadLibrary( _T( "dwmapi.dll" ) ); if( module ) { dwmdwp proc = reinterpret_cast( GetProcAddress( module, "DwmDefWindowProc" ) ); if( proc ) { *plResult = proc( hWnd, msg, wParam, lParam ); + result = TRUE; } FreeLibrary(module); } From d17bde151fd34076172ed9d6f83b51db5dcde4c3 Mon Sep 17 00:00:00 2001 From: Ritchie Swann Date: Sun, 11 Aug 2024 10:51:05 +0100 Subject: [PATCH 11/13] Fix to use the correct definition of DwmDefWindowProc --- libraries/ZWidget/src/window/win32/win32window.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/libraries/ZWidget/src/window/win32/win32window.cpp b/libraries/ZWidget/src/window/win32/win32window.cpp index f86fc669d..32caafacf 100644 --- a/libraries/ZWidget/src/window/win32/win32window.cpp +++ b/libraries/ZWidget/src/window/win32/win32window.cpp @@ -34,14 +34,13 @@ BOOL DwmDefWindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, LRESULT *plResult ) { - typedef LRESULT(* dwmdwp)(HWND, UINT, WPARAM, LPARAM ); + typedef LRESULT(* dwmdwp)(HWND, UINT, WPARAM, LPARAM, LRESULT* ); BOOL result(FALSE); HMODULE module = LoadLibrary( _T( "dwmapi.dll" ) ); if( module ) { dwmdwp proc = reinterpret_cast( GetProcAddress( module, "DwmDefWindowProc" ) ); if( proc ) { - *plResult = proc( hWnd, msg, wParam, lParam ); - result = TRUE; + result = proc( hWnd, msg, wParam, lParam, plResult ); } FreeLibrary(module); } From 0d5e35985d2240f64e2f9dfb6307310ace5ac865 Mon Sep 17 00:00:00 2001 From: Ritchie Swann Date: Sun, 11 Aug 2024 10:52:32 +0100 Subject: [PATCH 12/13] Fix incorrect return type --- libraries/ZWidget/src/window/win32/win32window.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/ZWidget/src/window/win32/win32window.cpp b/libraries/ZWidget/src/window/win32/win32window.cpp index 32caafacf..48531372c 100644 --- a/libraries/ZWidget/src/window/win32/win32window.cpp +++ b/libraries/ZWidget/src/window/win32/win32window.cpp @@ -34,7 +34,7 @@ BOOL DwmDefWindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, LRESULT *plResult ) { - typedef LRESULT(* dwmdwp)(HWND, UINT, WPARAM, LPARAM, LRESULT* ); + typedef BOOL(* dwmdwp)(HWND, UINT, WPARAM, LPARAM, LRESULT* ); BOOL result(FALSE); HMODULE module = LoadLibrary( _T( "dwmapi.dll" ) ); if( module ) { From 958721e2b87f9d1f0280221224a7ad0cfcda424d Mon Sep 17 00:00:00 2001 From: "Dileep V. Reddy" Date: Wed, 14 Aug 2024 20:43:09 -0600 Subject: [PATCH 13/13] Forgot on check. --- src/rendering/hwrenderer/scene/hw_drawinfo.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/rendering/hwrenderer/scene/hw_drawinfo.cpp b/src/rendering/hwrenderer/scene/hw_drawinfo.cpp index 50a81b2c4..19478c30c 100644 --- a/src/rendering/hwrenderer/scene/hw_drawinfo.cpp +++ b/src/rendering/hwrenderer/scene/hw_drawinfo.cpp @@ -452,9 +452,12 @@ void HWDrawInfo::CreateScene(bool drawpsprites) angle_t a1 = FrustumAngle(); // horizontally clip the back of the viewport mClipper->SafeAddClipRangeRealAngles(vp.Angles.Yaw.BAMs() + a1, vp.Angles.Yaw.BAMs() - a1); Viewpoint.FrustAngle = a1; - double a2 = 20.0 + 0.5*Viewpoint.FieldOfView.Degrees(); // FrustumPitch for vertical clipping - if (a2 > 179.0) a2 = 179.0; - vClipper->SafeAddClipRangeDegPitches(vp.HWAngles.Pitch.Degrees() - a2, vp.HWAngles.Pitch.Degrees() + a2); // clip the suplex range + if (Viewpoint.IsAllowedOoB()) // No need for vertical clipper if viewpoint not allowed out of bounds + { + double a2 = 20.0 + 0.5*Viewpoint.FieldOfView.Degrees(); // FrustumPitch for vertical clipping + if (a2 > 179.0) a2 = 179.0; + vClipper->SafeAddClipRangeDegPitches(vp.HWAngles.Pitch.Degrees() - a2, vp.HWAngles.Pitch.Degrees() + a2); // clip the suplex range + } // reset the portal manager portalState.StartFrame();