From 0b9e48fa3df9c184ff1abfb2452fd1a4b696ecd8 Mon Sep 17 00:00:00 2001 From: Bhee Date: Mon, 14 Dec 2020 02:37:20 -0500 Subject: [PATCH 01/50] Fix minor typo: If if -> If. --- docs/vulkan.dox | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/vulkan.dox b/docs/vulkan.dox index 2585c2bb..68e3d5fe 100644 --- a/docs/vulkan.dox +++ b/docs/vulkan.dox @@ -93,7 +93,7 @@ if (glfwVulkanSupported()) This function returns `GLFW_TRUE` if the Vulkan loader and any minimally functional ICD was found. -If if one or both were not found, calling any other Vulkan related GLFW function +If one or both were not found, calling any other Vulkan related GLFW function will generate a @ref GLFW_API_UNAVAILABLE error. From 761f97d6b600794062bc2c6055d7d09ae6a567fc Mon Sep 17 00:00:00 2001 From: ashishgamedev <66940640+ashishgamedev@users.noreply.github.com> Date: Thu, 10 Dec 2020 19:48:55 +0530 Subject: [PATCH 02/50] Fix indentation in internal.h Closes #1818. --- src/internal.h | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/internal.h b/src/internal.h index 48053cde..f87c2f93 100644 --- a/src/internal.h +++ b/src/internal.h @@ -350,9 +350,9 @@ struct _GLFWcontext int robustness; int release; - PFNGLGETSTRINGIPROC GetStringi; + PFNGLGETSTRINGIPROC GetStringi; PFNGLGETINTEGERVPROC GetIntegerv; - PFNGLGETSTRINGPROC GetString; + PFNGLGETSTRINGPROC GetString; _GLFWmakecontextcurrentfun makeCurrent; _GLFWswapbuffersfun swapBuffers; @@ -405,23 +405,23 @@ struct _GLFWwindow _GLFWcontext context; struct { - GLFWwindowposfun pos; - GLFWwindowsizefun size; - GLFWwindowclosefun close; - GLFWwindowrefreshfun refresh; - GLFWwindowfocusfun focus; - GLFWwindowiconifyfun iconify; - GLFWwindowmaximizefun maximize; - GLFWframebuffersizefun fbsize; + GLFWwindowposfun pos; + GLFWwindowsizefun size; + GLFWwindowclosefun close; + GLFWwindowrefreshfun refresh; + GLFWwindowfocusfun focus; + GLFWwindowiconifyfun iconify; + GLFWwindowmaximizefun maximize; + GLFWframebuffersizefun fbsize; GLFWwindowcontentscalefun scale; - GLFWmousebuttonfun mouseButton; - GLFWcursorposfun cursorPos; - GLFWcursorenterfun cursorEnter; - GLFWscrollfun scroll; - GLFWkeyfun key; - GLFWcharfun character; - GLFWcharmodsfun charmods; - GLFWdropfun drop; + GLFWmousebuttonfun mouseButton; + GLFWcursorposfun cursorPos; + GLFWcursorenterfun cursorEnter; + GLFWscrollfun scroll; + GLFWkeyfun key; + GLFWcharfun character; + GLFWcharmodsfun charmods; + GLFWdropfun drop; } callbacks; // This is defined in the window API's platform.h From 6ce6b50787e058177aad547aac33015ab298f1f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Tue, 15 Dec 2020 02:13:24 +0100 Subject: [PATCH 03/50] Add credit Related to #1818. --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index b4d798b9..71266cf7 100644 --- a/README.md +++ b/README.md @@ -247,6 +247,7 @@ skills. - Bobyshev Alexander - Matt Arsenault + - ashishgamedev - David Avedissian - Keith Bauer - John Bartholomew From 3a8ebb1903bd556c21c80c23c42da361b143a051 Mon Sep 17 00:00:00 2001 From: Luke Bayes Date: Sat, 2 Jan 2021 19:55:31 -0500 Subject: [PATCH 04/50] Added 2 entries to the gitignores file. I downloaded and built from sources as as submodule for a personal exploration that I'm working on and discovered that the glfw submodule shows changed files after a build. Adding these 2 entries fixes the issue. Closes #1827. --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index b34fc452..84636a0a 100644 --- a/.gitignore +++ b/.gitignore @@ -77,6 +77,7 @@ examples/splitview examples/sharing examples/triangle-opengl examples/wave +examples/windows tests/*.app tests/*.exe tests/clipboard @@ -87,6 +88,7 @@ tests/gamma tests/glfwinfo tests/icon tests/iconify +tests/inputlag tests/joysticks tests/monitors tests/msaa From 5d1d1a01e3a05c068289487831940896d9a5902e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Sun, 3 Jan 2021 21:13:02 +0100 Subject: [PATCH 05/50] Update repo URL for Nuklear Fixes #1826. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 71266cf7..a7a1d738 100644 --- a/README.md +++ b/README.md @@ -99,7 +99,7 @@ located in the `deps/` directory. functions - [linmath.h](https://github.com/datenwolf/linmath.h) for linear algebra in examples - - [Nuklear](https://github.com/vurtun/nuklear) for test and example UI + - [Nuklear](https://github.com/Immediate-Mode-UI/Nuklear) for test and example UI - [stb\_image\_write](https://github.com/nothings/stb) for writing images to disk The documentation is generated with [Doxygen](http://doxygen.org/) if CMake can From f5af421a6b9910ae8d02c4f468ec6d130052c351 Mon Sep 17 00:00:00 2001 From: Philip Rideout Date: Tue, 5 Jan 2021 20:42:46 -0800 Subject: [PATCH 06/50] Cocoa: Fix duplicate video mode detection Closes #1830. --- src/cocoa_monitor.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cocoa_monitor.m b/src/cocoa_monitor.m index 2bb83738..d0112d26 100644 --- a/src/cocoa_monitor.m +++ b/src/cocoa_monitor.m @@ -527,7 +527,7 @@ GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* count) } // Skip duplicate modes - if (i < *count) + if (j < *count) continue; (*count)++; From 552209fe465b3c3d8bc4e2b02e0b259364d2a3a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Mon, 18 Jan 2021 16:24:27 +0100 Subject: [PATCH 07/50] Update changelog --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index a7a1d738..5e06e990 100644 --- a/README.md +++ b/README.md @@ -178,6 +178,7 @@ information on what to include when reporting a bug. - [Cocoa] Bugfix: Failing to retrieve the refresh rate of built-in displays could leak memory - [Cocoa] Bugfix: Objective-C files were compiled as C with CMake 3.19 (#1787) + - [Cocoa] Bugfix: Duplicate video modes were not filtered out (#1830) - [X11] Bugfix: The CMake files did not check for the XInput headers (#1480) - [X11] Bugfix: Key names were not updated when the keyboard layout changed (#1462,#1528) From 8b118674643b199fc28d11dc22039ffe528970b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Tue, 8 Dec 2020 23:23:20 +0100 Subject: [PATCH 08/50] Cocoa: Fix menubar for unbundled apps on 10.15 NSApp setActivationPolicy: was being called too soon when the app was not bundled and launched from the command line. This fix is based on #1802 by @richardwilkes. Fixes #1648. Closes #1802. --- README.md | 3 +++ src/cocoa_init.m | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 5e06e990..5b76f5bb 100644 --- a/README.md +++ b/README.md @@ -179,6 +179,8 @@ information on what to include when reporting a bug. could leak memory - [Cocoa] Bugfix: Objective-C files were compiled as C with CMake 3.19 (#1787) - [Cocoa] Bugfix: Duplicate video modes were not filtered out (#1830) + - [Cocoa] Bugfix: Menubar was not clickable on macOS 10.15+ until it lost and + regained focus (#1648,#1802) - [X11] Bugfix: The CMake files did not check for the XInput headers (#1480) - [X11] Bugfix: Key names were not updated when the keyboard layout changed (#1462,#1528) @@ -441,6 +443,7 @@ skills. - Frank Wille - Andy Williams - Joel Winarske + - Richard A. Wilkes - Tatsuya Yatagawa - Ryogo Yoshimura - Lukas Zanner diff --git a/src/cocoa_init.m b/src/cocoa_init.m index edd174be..88decab6 100644 --- a/src/cocoa_init.m +++ b/src/cocoa_init.m @@ -428,9 +428,6 @@ static GLFWbool initializeTIS(void) { if (_glfw.hints.init.ns.menubar) { - // In case we are unbundled, make us a proper UI application - [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular]; - // Menu bar setup must go between sharedApplication and finishLaunching // in order to properly emulate the behavior of NSApplicationMain @@ -557,6 +554,9 @@ int _glfwPlatformInit(void) if (![[NSRunningApplication currentApplication] isFinishedLaunching]) [NSApp run]; + // In case we are unbundled, make us a proper UI application + [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular]; + return GLFW_TRUE; } // autoreleasepool From 5aff72aa0016105477b9ce16f2da590939cec981 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Mon, 18 Jan 2021 01:26:00 +0100 Subject: [PATCH 09/50] Cocoa: Fix duplicate monitor connection events --- src/cocoa_monitor.m | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/cocoa_monitor.m b/src/cocoa_monitor.m index d0112d26..8891f8a6 100644 --- a/src/cocoa_monitor.m +++ b/src/cocoa_monitor.m @@ -338,7 +338,8 @@ void _glfwPollMonitorsNS(void) // display replacement on machines with automatic graphics // switching const uint32_t unitNumber = CGDisplayUnitNumber(displays[i]); - for (uint32_t j = 0; j < disconnectedCount; j++) + uint32_t j; + for (j = 0; j < disconnectedCount; j++) { if (disconnected[j] && disconnected[j]->ns.unitNumber == unitNumber) { @@ -347,6 +348,9 @@ void _glfwPollMonitorsNS(void) } } + if (j < disconnectedCount) + continue; + const CGSize size = CGDisplayScreenSize(displays[i]); char* name = getDisplayName(displays[i]); if (!name) From 2bc52ca82e46f6f238007b8e80b7253328bd080d Mon Sep 17 00:00:00 2001 From: Nevyn Bengtsson Date: Mon, 11 Jan 2021 17:27:27 +0100 Subject: [PATCH 10/50] Cocoa: Use modern API to get display name On Apple Silicon, IOKit is deprecated and there will be no matching io_service that we can query for name. Luckilly, NSScreen got an API to fetch the display name in 10.15. This is a blocker to get glfw running on Apple Silicon. Fixes #1809. Closes #1833. --- src/cocoa_monitor.m | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/cocoa_monitor.m b/src/cocoa_monitor.m index 8891f8a6..d85d2621 100644 --- a/src/cocoa_monitor.m +++ b/src/cocoa_monitor.m @@ -41,6 +41,22 @@ // static char* getDisplayName(CGDirectDisplayID displayID) { + // IOKit doesn't work on Apple Silicon anymore. Luckilly, 10.15 introduced -[NSScreen localizedName]. + // Use it if available, and fall back to IOKit otherwise. + if ([NSScreen instancesRespondToSelector:@selector(localizedName)]) + { + for(NSScreen *screen in [NSScreen screens]) + { + if ([[[screen deviceDescription] objectForKey:@"NSScreenNumber"] intValue] == displayID) + { + NSString *name = [screen valueForKey:@"localizedName"]; + if (name) + { + return _glfw_strdup([name UTF8String]); + } + } + } + } io_iterator_t it; io_service_t service; CFDictionaryRef info; From 8ab40399d3bdbf8fb9501e42e53f36b5e5528da1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Mon, 18 Jan 2021 01:34:55 +0100 Subject: [PATCH 11/50] Update changelog and add credit Related to #1833. --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 5b76f5bb..f5783f5c 100644 --- a/README.md +++ b/README.md @@ -181,6 +181,7 @@ information on what to include when reporting a bug. - [Cocoa] Bugfix: Duplicate video modes were not filtered out (#1830) - [Cocoa] Bugfix: Menubar was not clickable on macOS 10.15+ until it lost and regained focus (#1648,#1802) + - [Cocoa] Bugfix: Monitor name query could segfault on macOS 11 (#1809,#1833) - [X11] Bugfix: The CMake files did not check for the XInput headers (#1480) - [X11] Bugfix: Key names were not updated when the keyboard layout changed (#1462,#1528) @@ -257,6 +258,7 @@ skills. - Coşku Baş - Niklas Behrens - Andrew Belt + - Nevyn Bengtsson - Niklas Bergström - Denis Bernard - Doug Binks From 3959ee894952f7dcba4e46bdd5d34e4528701cd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Sun, 17 Jan 2021 19:49:51 +0100 Subject: [PATCH 12/50] Cocoa: Unify CG display to NS screen mapping This moves the matching of CG displays to NS screens to monitor enumeration time. --- src/cocoa_monitor.m | 79 +++++++++++++++++++++------------------------ 1 file changed, 36 insertions(+), 43 deletions(-) diff --git a/src/cocoa_monitor.m b/src/cocoa_monitor.m index d85d2621..8eb3f70d 100644 --- a/src/cocoa_monitor.m +++ b/src/cocoa_monitor.m @@ -39,24 +39,21 @@ // Get the name of the specified display, or NULL // -static char* getDisplayName(CGDirectDisplayID displayID) +static char* getMonitorName(CGDirectDisplayID displayID, NSScreen* screen) { - // IOKit doesn't work on Apple Silicon anymore. Luckilly, 10.15 introduced -[NSScreen localizedName]. + // IOKit doesn't work on Apple Silicon anymore + // Luckily, 10.15 introduced -[NSScreen localizedName]. // Use it if available, and fall back to IOKit otherwise. - if ([NSScreen instancesRespondToSelector:@selector(localizedName)]) + if (screen) { - for(NSScreen *screen in [NSScreen screens]) + if ([screen respondsToSelector:@selector(localizedName)]) { - if ([[[screen deviceDescription] objectForKey:@"NSScreenNumber"] intValue] == displayID) - { - NSString *name = [screen valueForKey:@"localizedName"]; - if (name) - { - return _glfw_strdup([name UTF8String]); - } - } + NSString* name = [screen valueForKey:@"localizedName"]; + if (name) + return _glfw_strdup([name UTF8String]); } } + io_iterator_t it; io_service_t service; CFDictionaryRef info; @@ -225,31 +222,6 @@ static void endFadeReservation(CGDisplayFadeReservationToken token) } } -// Finds and caches the NSScreen corresponding to the specified monitor -// -static GLFWbool refreshMonitorScreen(_GLFWmonitor* monitor) -{ - if (monitor->ns.screen) - return GLFW_TRUE; - - for (NSScreen* screen in [NSScreen screens]) - { - NSNumber* displayID = [screen deviceDescription][@"NSScreenNumber"]; - - // HACK: Compare unit numbers instead of display IDs to work around - // display replacement on machines with automatic graphics - // switching - if (monitor->ns.unitNumber == CGDisplayUnitNumber([displayID unsignedIntValue])) - { - monitor->ns.screen = screen; - return GLFW_TRUE; - } - } - - _glfwInputError(GLFW_PLATFORM_ERROR, "Cocoa: Failed to find a screen for monitor"); - return GLFW_FALSE; -} - // Returns the display refresh rate queried from the I/O registry // static double getFallbackRefreshRate(CGDirectDisplayID displayID) @@ -350,15 +322,29 @@ void _glfwPollMonitorsNS(void) if (CGDisplayIsAsleep(displays[i])) continue; + const uint32_t unitNumber = CGDisplayUnitNumber(displays[i]); + NSScreen* screen = nil; + + for (screen in [NSScreen screens]) + { + NSNumber* screenNumber = [screen deviceDescription][@"NSScreenNumber"]; + + // HACK: Compare unit numbers instead of display IDs to work around + // display replacement on machines with automatic graphics + // switching + if (CGDisplayUnitNumber([screenNumber unsignedIntValue]) == unitNumber) + break; + } + // HACK: Compare unit numbers instead of display IDs to work around // display replacement on machines with automatic graphics // switching - const uint32_t unitNumber = CGDisplayUnitNumber(displays[i]); uint32_t j; for (j = 0; j < disconnectedCount; j++) { if (disconnected[j] && disconnected[j]->ns.unitNumber == unitNumber) { + disconnected[j]->ns.screen = screen; disconnected[j] = NULL; break; } @@ -368,13 +354,14 @@ void _glfwPollMonitorsNS(void) continue; const CGSize size = CGDisplayScreenSize(displays[i]); - char* name = getDisplayName(displays[i]); + char* name = getMonitorName(displays[i], screen); if (!name) name = _glfw_strdup("Unknown"); _GLFWmonitor* monitor = _glfwAllocMonitor(name, size.width, size.height); monitor->ns.displayID = displays[i]; monitor->ns.unitNumber = unitNumber; + monitor->ns.screen = screen; free(name); @@ -483,8 +470,11 @@ void _glfwPlatformGetMonitorContentScale(_GLFWmonitor* monitor, { @autoreleasepool { - if (!refreshMonitorScreen(monitor)) - return; + if (!monitor->ns.screen) + { + _glfwInputError(GLFW_PLATFORM_ERROR, + "Cocoa: Cannot query content scale without screen"); + } const NSRect points = [monitor->ns.screen frame]; const NSRect pixels = [monitor->ns.screen convertRectToBacking:points]; @@ -503,8 +493,11 @@ void _glfwPlatformGetMonitorWorkarea(_GLFWmonitor* monitor, { @autoreleasepool { - if (!refreshMonitorScreen(monitor)) - return; + if (!monitor->ns.screen) + { + _glfwInputError(GLFW_PLATFORM_ERROR, + "Cocoa: Cannot query workarea without screen"); + } const NSRect frameRect = [monitor->ns.screen visibleFrame]; From f8d6801a507ff5a5b41f30347dd03f1e38a0f9e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Mon, 18 Jan 2021 16:04:51 +0100 Subject: [PATCH 13/50] Simplify references in CMake if-statements --- src/CMakeLists.txt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3a45ea50..4a0f5340 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -37,7 +37,7 @@ elseif (_GLFW_OSMESA) endif() if (_GLFW_X11 OR _GLFW_WAYLAND) - if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") + if (CMAKE_SYSTEM_NAME STREQUAL "Linux") target_sources(glfw PRIVATE linux_joystick.h linux_joystick.c) else() target_sources(glfw PRIVATE null_joystick.h null_joystick.c) @@ -120,7 +120,7 @@ endif() # Make GCC warn about declarations that VS 2010 and 2012 won't accept for all # source files that VS will build (Clang ignores this because we set -std=c99) -if ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU") +if (CMAKE_C_COMPILER_ID STREQUAL "GNU") set_source_files_properties(context.c init.c input.c monitor.c vulkan.c window.c win32_init.c win32_joystick.c win32_monitor.c win32_time.c win32_thread.c @@ -130,11 +130,11 @@ if ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU") endif() # Enable a reasonable set of warnings -if ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU" OR - "${CMAKE_C_COMPILER_ID}" STREQUAL "Clang" OR - "${CMAKE_C_COMPILER_ID}" STREQUAL "AppleClang") +if (CMAKE_C_COMPILER_ID STREQUAL "GNU" OR + CMAKE_C_COMPILER_ID STREQUAL "Clang" OR + CMAKE_C_COMPILER_ID STREQUAL "AppleClang") - if ("${CMAKE_C_SIMULATE_ID}" STREQUAL "MSVC") + if (CMAKE_C_SIMULATE_ID STREQUAL "MSVC") # Tell Clang-CL that this is a Clang flag target_compile_options(glfw PRIVATE "/clang:-Wall") else() From 384ff74a4645347bbc5726fc572138b38f87ae8b Mon Sep 17 00:00:00 2001 From: Laurent Aphecetche Date: Fri, 14 Jun 2019 16:42:50 +0200 Subject: [PATCH 14/50] Cocoa: Fix install name for installed dylib The install name was incorrectly set to a relative path. This change leaves the install name of the installed dylib as @rpath/soname. Those who wish to override this can set the CMAKE_INSTALL_NAME_DIR variable. Closes #1504. --- src/CMakeLists.txt | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4a0f5340..2e6a1fa2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -203,9 +203,6 @@ if (BUILD_SHARED_LIBS) endif() target_compile_definitions(glfw INTERFACE GLFW_DLL) - elseif (APPLE) - set_target_properties(glfw PROPERTIES - INSTALL_NAME_DIR "${CMAKE_INSTALL_LIBDIR}") endif() if (MINGW) From 94773111300fee0453844a4c9407af7e880b4df8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Mon, 18 Jan 2021 18:55:17 +0100 Subject: [PATCH 15/50] Update changelog and add credit --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index f5783f5c..3185b6cc 100644 --- a/README.md +++ b/README.md @@ -182,6 +182,7 @@ information on what to include when reporting a bug. - [Cocoa] Bugfix: Menubar was not clickable on macOS 10.15+ until it lost and regained focus (#1648,#1802) - [Cocoa] Bugfix: Monitor name query could segfault on macOS 11 (#1809,#1833) + - [Cocoa] Bugfix: The install name of the installed dylib was relative (#1504) - [X11] Bugfix: The CMake files did not check for the XInput headers (#1480) - [X11] Bugfix: Key names were not updated when the keyboard layout changed (#1462,#1528) @@ -250,6 +251,7 @@ GLFW exists because people around the world donated their time and lent their skills. - Bobyshev Alexander + - Laurent Aphecetche - Matt Arsenault - ashishgamedev - David Avedissian From 6de084000bbebec345f4e5845a92fb2f4f931c00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Wed, 10 Feb 2021 17:23:43 +0100 Subject: [PATCH 16/50] Cocoa: Fix console apps getting a dock icon Regression introduced by @elmindreda in 8b118674643b199fc28d11dc22039ffe528970b3. --- src/cocoa_init.m | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cocoa_init.m b/src/cocoa_init.m index 88decab6..626d95c2 100644 --- a/src/cocoa_init.m +++ b/src/cocoa_init.m @@ -555,7 +555,8 @@ int _glfwPlatformInit(void) [NSApp run]; // In case we are unbundled, make us a proper UI application - [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular]; + if (_glfw.hints.init.ns.menubar) + [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular]; return GLFW_TRUE; From 410890aa8058a0c5a33f2e00d750326ba412e466 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Tue, 19 Jan 2021 22:25:05 +0100 Subject: [PATCH 17/50] Win32: Fix full screen windows affected by scaling Per-monitor DPI scaling should not affect full screen windows. Fixes #1582. --- README.md | 2 ++ src/win32_window.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3185b6cc..73dc1acd 100644 --- a/README.md +++ b/README.md @@ -159,6 +159,8 @@ information on what to include when reporting a bug. configuration change (#1761) - [Win32] Bugfix: Initialization would segfault on Windows 8 (not 8.1) (#1775) - [Win32] Bugfix: Duplicate size events were not filtered (#1610) + - [Win32] Bugfix: Full screen windows were incorrectly resized by DPI changes + (#1582) - [Cocoa] Added support for `VK_EXT_metal_surface` (#1619) - [Cocoa] Added locating the Vulkan loader at runtime in an application bundle - [Cocoa] Moved main menu creation to GLFW initialization time (#1649) diff --git a/src/win32_window.c b/src/win32_window.c index febafae4..1fa4570a 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -1140,7 +1140,7 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, // Only apply the suggested size if the OS is new enough to have // sent a WM_GETDPISCALEDSIZE before this - if (_glfwIsWindows10CreatorsUpdateOrGreaterWin32()) + if (_glfwIsWindows10CreatorsUpdateOrGreaterWin32() && !window->monitor) { RECT* suggested = (RECT*) lParam; SetWindowPos(window->win32.handle, HWND_TOP, From 729c9988d02004faac1663c18c7628bae193a95d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Wed, 20 Jan 2021 01:02:24 +0100 Subject: [PATCH 18/50] Win32: Fix content area rescaling on older systems GLFW_SCALE_TO_MONITOR had no effect on Windows 8.1 up to and including Windows 10 version 1607 (Anniversary Update), despite those having support for per-monitor DPI. That done was to avoid handling systems that have non-client scaling, introduced in Windows 10 version 1607, without reliable overriding of the new window size, introduced in Windows 10 version 1703 (Creators Update). Both are needed to keep the content area at a fixed size for windows that have GLFW_SCALE_TO_MONITOR disabled. This change enables window rescaling on Windows 8.1 and all later versions but disables non-client scaling for unscaled windows on Windows 10 version 1607. Versions after 1607 are unaffected. Fixes #1511. --- README.md | 2 ++ src/win32_window.c | 22 +++++++++++++++++----- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 73dc1acd..b0774fc4 100644 --- a/README.md +++ b/README.md @@ -161,6 +161,8 @@ information on what to include when reporting a bug. - [Win32] Bugfix: Duplicate size events were not filtered (#1610) - [Win32] Bugfix: Full screen windows were incorrectly resized by DPI changes (#1582) + - [Win32] Bugfix: `GLFW_SCALE_TO_MONITOR` had no effect on systems older than + Windows 10 version 1703 (#1511) - [Cocoa] Added support for `VK_EXT_metal_surface` (#1619) - [Cocoa] Added locating the Vulkan loader at runtime in an application bundle - [Cocoa] Moved main menu creation to GLFW initialization time (#1649) diff --git a/src/win32_window.c b/src/win32_window.c index 1fa4570a..52a9c680 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -501,7 +501,17 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, case WM_NCCREATE: { if (_glfwIsWindows10AnniversaryUpdateOrGreaterWin32()) - EnableNonClientDpiScaling(hWnd); + { + const CREATESTRUCTW* cs = (const CREATESTRUCTW*) lParam; + const _GLFWwndconfig* wndconfig = cs->lpCreateParams; + + // On per-monitor DPI aware V1 systems, only enable + // non-client scaling for windows that scale the client area + // We need WM_GETDPISCALEDSIZE from V2 to keep the client + // area static when the non-client area is scaled + if (wndconfig && wndconfig->scaleToMonitor) + EnableNonClientDpiScaling(hWnd); + } break; } @@ -1138,9 +1148,11 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, const float xscale = HIWORD(wParam) / (float) USER_DEFAULT_SCREEN_DPI; const float yscale = LOWORD(wParam) / (float) USER_DEFAULT_SCREEN_DPI; - // Only apply the suggested size if the OS is new enough to have - // sent a WM_GETDPISCALEDSIZE before this - if (_glfwIsWindows10CreatorsUpdateOrGreaterWin32() && !window->monitor) + // Resize windowed mode windows that either permit rescaling or that + // need it to compensate for non-client area scaling + if (!window->monitor && + (window->win32.scaleToMonitor || + _glfwIsWindows10CreatorsUpdateOrGreaterWin32())) { RECT* suggested = (RECT*) lParam; SetWindowPos(window->win32.handle, HWND_TOP, @@ -1255,7 +1267,7 @@ static int createNativeWindow(_GLFWwindow* window, NULL, // No parent window NULL, // No window menu GetModuleHandleW(NULL), - NULL); + (LPVOID) wndconfig); free(wideTitle); From b925a54ef11adab250e4e9592afe918c1f8caebb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Tue, 9 Feb 2021 21:33:23 +0100 Subject: [PATCH 19/50] Wayland: Move DPI fallback work to output done This removes the dependency on the (unspecified) ordering of geometry and mode events in wl_output. Based on feedback from @linkmauve and @caramelli. Related to #1792. --- src/wl_monitor.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/wl_monitor.c b/src/wl_monitor.c index 4cbfb51d..d722beaa 100644 --- a/src/wl_monitor.c +++ b/src/wl_monitor.c @@ -81,22 +81,21 @@ static void outputHandleMode(void* data, monitor->modes[monitor->modeCount - 1] = mode; if (flags & WL_OUTPUT_MODE_CURRENT) - { monitor->wl.currentMode = monitor->modeCount - 1; - - if (monitor->widthMM <= 0 || monitor->heightMM <= 0) - { - // If Wayland does not provide a physical size, assume the default 96 DPI - monitor->widthMM = (int) (width * 25.4f / 96.f); - monitor->heightMM = (int) (height * 25.4f / 96.f); - } - } } static void outputHandleDone(void* data, struct wl_output* output) { struct _GLFWmonitor *monitor = data; + if (monitor->widthMM <= 0 || monitor->heightMM <= 0) + { + // If Wayland does not provide a physical size, assume the default 96 DPI + const GLFWvidmode* mode = &monitor->modes[monitor->wl.currentMode]; + monitor->widthMM = (int) (mode->width * 25.4f / 96.f); + monitor->heightMM = (int) (mode->height * 25.4f / 96.f); + } + _glfwInputMonitor(monitor, GLFW_CONNECTED, _GLFW_INSERT_LAST); } From 2c7f3ce91b4f22773855c43d6480824ed4ac9907 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Wed, 17 Feb 2021 21:21:49 +0100 Subject: [PATCH 20/50] Update changelog --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index b0774fc4..b9b047f0 100644 --- a/README.md +++ b/README.md @@ -221,6 +221,7 @@ information on what to include when reporting a bug. (#1463) - [Wayland] Bugfix: Client-Side Decorations were destroyed in the wrong worder (#1798) + - [Wayland] Bugfix: Monitors physical size could report zero (#1784,#1792) - [POSIX] Bugfix: `CLOCK_MONOTONIC` was not correctly tested for or enabled - [NSGL] Removed enforcement of forward-compatible flag for core contexts - [NSGL] Bugfix: `GLFW_COCOA_RETINA_FRAMEBUFFER` had no effect on newer From 4afa227a056681d2628894b0893527bf69496a41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Mon, 8 Mar 2021 19:32:36 +0100 Subject: [PATCH 21/50] X11: Fix attribs not applied on leaving fullscreen If the GLFW_DECORATED and/or GLFW_FLOATING window attributes were changed while in fullscreen mode, the changes did not take effect when the window entered windowed mode. Bug reported on the GLFW forum. https://discourse.glfw.org/t/turning-on-off-window-decorations-while-in-full-screen-wont-work-properly/1780 --- README.md | 1 + src/x11_window.c | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/README.md b/README.md index b9b047f0..9e4f2df9 100644 --- a/README.md +++ b/README.md @@ -212,6 +212,7 @@ information on what to include when reporting a bug. combinaitons (#1598) - [X11] Bugfix: Keys pressed simultaneously with others were not always reported (#1112,#1415,#1472,#1616) + - [X11] Bugfix: Some window attributes were not applied on leaving fullscreen - [Wayland] Removed support for `wl_shell` (#1443) - [Wayland] Bugfix: The `GLFW_HAND_CURSOR` shape used the wrong image (#1432) - [Wayland] Bugfix: `CLOCK_MONOTONIC` was not correctly enabled diff --git a/src/x11_window.c b/src/x11_window.c index a85688e1..3f2277d6 100644 --- a/src/x11_window.c +++ b/src/x11_window.c @@ -2485,7 +2485,11 @@ void _glfwPlatformSetWindowMonitor(_GLFWwindow* window, } if (window->monitor) + { + _glfwPlatformSetWindowDecorated(window, window->decorated); + _glfwPlatformSetWindowFloating(window, window->floating); releaseMonitor(window); + } _glfwInputWindowMonitor(window, monitor); updateNormalHints(window, width, height); From 1f34295a74ecbbe87d95ad39ce1cd0d943f88dcb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Tue, 9 Mar 2021 23:36:05 +0100 Subject: [PATCH 22/50] Win32: Add MinGW-w64 detection to version string --- src/win32_init.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/win32_init.c b/src/win32_init.c index f6995e51..4cd6f158 100644 --- a/src/win32_init.c +++ b/src/win32_init.c @@ -614,7 +614,9 @@ void _glfwPlatformTerminate(void) const char* _glfwPlatformGetVersionString(void) { return _GLFW_VERSION_NUMBER " Win32 WGL EGL OSMesa" -#if defined(__MINGW32__) +#if defined(__MINGW64_VERSION_MAJOR) + " MinGW-w64" +#elif defined(__MINGW32__) " MinGW" #elif defined(_MSC_VER) " VisualC" From 9c62a21ba91d347617856dee9ccdf6da1175a83f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Wed, 10 Mar 2021 21:39:16 +0100 Subject: [PATCH 23/50] Update linmath.h --- deps/linmath.h | 151 +++++++++++++++++++++---------------------------- 1 file changed, 66 insertions(+), 85 deletions(-) diff --git a/deps/linmath.h b/deps/linmath.h index 8b2a8c2e..be37caf6 100644 --- a/deps/linmath.h +++ b/deps/linmath.h @@ -1,13 +1,8 @@ #ifndef LINMATH_H #define LINMATH_H +#include #include - -/* 2020-03-02 Camilla Löwy - * - Added inclusion of string.h for memcpy - * - Replaced tan and acos with tanf and acosf - * - Replaced double constants with float equivalents - */ #include #ifdef LINMATH_NO_INLINE @@ -38,7 +33,7 @@ LINMATH_H_FUNC void vec##n##_scale(vec##n r, vec##n const v, float const s) \ } \ LINMATH_H_FUNC float vec##n##_mul_inner(vec##n const a, vec##n const b) \ { \ - float p = 0.; \ + float p = 0.f; \ int i; \ for(i=0; ib[i] ? a[i] : b[i]; \ +} \ +LINMATH_H_FUNC void vec##n##_dup(vec##n r, vec##n const src) \ +{ \ + int i; \ + for(i=0; i Date: Thu, 20 Aug 2020 12:54:07 +0200 Subject: [PATCH 24/50] Ignore cached state when setting window attributes This filtering prevented valid changes if the native window state was changed externally. --- src/window.c | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/window.c b/src/window.c index efcb4125..d2196e2f 100644 --- a/src/window.c +++ b/src/window.c @@ -882,27 +882,18 @@ GLFWAPI void glfwSetWindowAttrib(GLFWwindow* handle, int attrib, int value) window->autoIconify = value; else if (attrib == GLFW_RESIZABLE) { - if (window->resizable == value) - return; - window->resizable = value; if (!window->monitor) _glfwPlatformSetWindowResizable(window, value); } else if (attrib == GLFW_DECORATED) { - if (window->decorated == value) - return; - window->decorated = value; if (!window->monitor) _glfwPlatformSetWindowDecorated(window, value); } else if (attrib == GLFW_FLOATING) { - if (window->floating == value) - return; - window->floating = value; if (!window->monitor) _glfwPlatformSetWindowFloating(window, value); @@ -911,9 +902,6 @@ GLFWAPI void glfwSetWindowAttrib(GLFWwindow* handle, int attrib, int value) window->focusOnShow = value; else if (attrib == GLFW_MOUSE_PASSTHROUGH) { - if (window->mousePassthrough == value) - return; - window->mousePassthrough = value; _glfwPlatformSetWindowMousePassthrough(window, value); } From 52ba8c7f07574d56955099179f35569e07e2001c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Mon, 15 Mar 2021 00:48:05 +0100 Subject: [PATCH 25/50] Win32: Add warning when option will have no effect The GPU driver only looks in the executable for the symbol requesting the high-performance GPU, so enabling them when buidling GLFW as a DLL will have no effect. --- src/win32_init.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/win32_init.c b/src/win32_init.c index 4cd6f158..970da06e 100644 --- a/src/win32_init.c +++ b/src/win32_init.c @@ -39,6 +39,10 @@ static const GUID _glfw_GUID_DEVINTERFACE_HID = #if defined(_GLFW_USE_HYBRID_HPG) || defined(_GLFW_USE_OPTIMUS_HPG) +#if defined(_GLFW_BUILD_DLL) + #warning "These symbols must be exported by the executable and have no effect in a DLL" +#endif + // Executables (but not DLLs) exporting this symbol with this value will be // automatically directed to the high-performance GPU on Nvidia Optimus systems // with up-to-date drivers From 291f6dc32c6d6359f56dd495374aea8291357b29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Fri, 19 Mar 2021 14:24:50 +0100 Subject: [PATCH 26/50] Remove deprecated Doxygen tag Fixes #1867. --- docs/Doxyfile.in | 7 ------- 1 file changed, 7 deletions(-) diff --git a/docs/Doxyfile.in b/docs/Doxyfile.in index c3682222..f5504a83 100644 --- a/docs/Doxyfile.in +++ b/docs/Doxyfile.in @@ -1074,13 +1074,6 @@ VERBATIM_HEADERS = YES ALPHABETICAL_INDEX = YES -# The COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns in -# which the alphabetical index list will be split. -# Minimum value: 1, maximum value: 20, default value: 5. -# This tag requires that the tag ALPHABETICAL_INDEX is set to YES. - -COLS_IN_ALPHA_INDEX = 5 - # In case all classes in a project start with a common prefix, all classes will # be put under the same header in the alphabetical index. The IGNORE_PREFIX tag # can be used to specify a prefix (or a list of prefixes) that should be ignored From 33cd8b865d9289cfbcf3d95e6e68e4050b94fcd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Fri, 19 Mar 2021 14:47:28 +0100 Subject: [PATCH 27/50] Add issue number to changelog Related to #1863. --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 9e4f2df9..26e88828 100644 --- a/README.md +++ b/README.md @@ -213,6 +213,7 @@ information on what to include when reporting a bug. - [X11] Bugfix: Keys pressed simultaneously with others were not always reported (#1112,#1415,#1472,#1616) - [X11] Bugfix: Some window attributes were not applied on leaving fullscreen + (#1863) - [Wayland] Removed support for `wl_shell` (#1443) - [Wayland] Bugfix: The `GLFW_HAND_CURSOR` shape used the wrong image (#1432) - [Wayland] Bugfix: `CLOCK_MONOTONIC` was not correctly enabled From 9416a43404934cc54136e988a233bee64d4d48fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Sun, 21 Mar 2021 16:01:45 +0100 Subject: [PATCH 28/50] Fix implicit double-to-float in linmath.h --- deps/linmath.h | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/deps/linmath.h b/deps/linmath.h index be37caf6..5c802656 100644 --- a/deps/linmath.h +++ b/deps/linmath.h @@ -5,6 +5,10 @@ #include #include +/* 2021-03-21 Camilla Löwy + * - Replaced double constants with float equivalents + */ + #ifdef LINMATH_NO_INLINE #define LINMATH_H_FUNC static #else @@ -575,17 +579,17 @@ LINMATH_H_FUNC void mat4x4_arcball(mat4x4 R, mat4x4 const M, vec2 const _a, vec2 vec2 a; memcpy(a, _a, sizeof(a)); vec2 b; memcpy(b, _b, sizeof(b)); - float z_a = 0.; - float z_b = 0.; + float z_a = 0.f; + float z_b = 0.f; - if(vec2_len(a) < 1.) { - z_a = sqrtf(1. - vec2_mul_inner(a, a)); + if(vec2_len(a) < 1.f) { + z_a = sqrtf(1.f - vec2_mul_inner(a, a)); } else { vec2_norm(a, a); } - if(vec2_len(b) < 1.) { - z_b = sqrtf(1. - vec2_mul_inner(b, b)); + if(vec2_len(b) < 1.f) { + z_b = sqrtf(1.f - vec2_mul_inner(b, b)); } else { vec2_norm(b, b); } From f4a73296049b432720c9b6c230e479f9b41d74d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Mon, 12 Oct 2020 23:47:35 +0200 Subject: [PATCH 29/50] Update USE_MSVC_RUNTIME_LIBRARY_DLL for CMake 3.15 This makes USE_MSVC_RUNTIME_LIBRARY_DLL update the directory scope CMAKE_MSVC_RUNTIME_LIBRARY variable instead of CMAKE_C_FLAGS on CMake 3.15 and later. Solution proposed by @moritz-h. Fixes #1783. Closes #1796. --- CMakeLists.txt | 6 ++++-- README.md | 2 ++ docs/compile.dox | 4 ++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 39482752..59ab473c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -69,8 +69,8 @@ endif() #-------------------------------------------------------------------- # Set compiler specific flags #-------------------------------------------------------------------- -if (MSVC) - if (NOT USE_MSVC_RUNTIME_LIBRARY_DLL) +if (MSVC AND NOT USE_MSVC_RUNTIME_LIBRARY_DLL) + if (${CMAKE_VERSION} VERSION_LESS 3.15) foreach (flag CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE @@ -85,6 +85,8 @@ if (MSVC) endif() endforeach() + else() + set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") endif() endif() diff --git a/README.md b/README.md index 26e88828..f7d9d75a 100644 --- a/README.md +++ b/README.md @@ -163,6 +163,8 @@ information on what to include when reporting a bug. (#1582) - [Win32] Bugfix: `GLFW_SCALE_TO_MONITOR` had no effect on systems older than Windows 10 version 1703 (#1511) + - [Win32] Bugfix: `USE_MSVC_RUNTIME_LIBRARY_DLL` had no effect on CMake 3.15 or + later (#1783,#1796) - [Cocoa] Added support for `VK_EXT_metal_surface` (#1619) - [Cocoa] Added locating the Vulkan loader at runtime in an application bundle - [Cocoa] Moved main menu creation to GLFW initialization time (#1649) diff --git a/docs/compile.dox b/docs/compile.dox index 5a4c6d88..7c88281b 100644 --- a/docs/compile.dox +++ b/docs/compile.dox @@ -235,6 +235,10 @@ __USE_MSVC_RUNTIME_LIBRARY_DLL__ determines whether to use the DLL version or th static library version of the Visual C++ runtime library. If set to `ON`, the DLL version of the Visual C++ library is used. +@note On CMake 3.15 and later you can set the +[CMAKE_MSVC_RUNTIME_LIBRARY](https://cmake.org/cmake/help/latest/variable/CMAKE_MSVC_RUNTIME_LIBRARY.html) +variable instead of this option. + @anchor GLFW_USE_HYBRID_HPG __GLFW_USE_HYBRID_HPG__ determines whether to export the `NvOptimusEnablement` and `AmdPowerXpressRequestHighPerformance` symbols, which force the use of the From 84f95a7d7fa454ca99efcdd49da89472294b16bf Mon Sep 17 00:00:00 2001 From: Nicolas Caramelli Date: Fri, 23 Oct 2020 18:55:37 +0200 Subject: [PATCH 30/50] Add GLFW_X11_XCB_VULKAN_SURFACE init hint This hint controls whether GLFW will try to use VK_KHR_xcb_surface before falling back to VK_KHR_xlib_surface. Closes #1793. --- include/GLFW/glfw3.h | 5 +++++ src/init.c | 8 +++++++- src/internal.h | 3 +++ src/x11_init.c | 8 ++++++-- 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/include/GLFW/glfw3.h b/include/GLFW/glfw3.h index 7d9dee02..ac696cd8 100644 --- a/include/GLFW/glfw3.h +++ b/include/GLFW/glfw3.h @@ -1250,6 +1250,11 @@ extern "C" { * macOS specific [init hint](@ref GLFW_COCOA_MENUBAR_hint). */ #define GLFW_COCOA_MENUBAR 0x00051002 +/*! @brief X11 specific init hint. + * + * X11 specific [init hint](@ref GLFW_X11_XCB_VULKAN_SURFACE_hint). + */ +#define GLFW_X11_XCB_VULKAN_SURFACE 0x00052001 /*! @} */ #define GLFW_DONT_CARE -1 diff --git a/src/init.c b/src/init.c index a7b5af63..bca59baa 100644 --- a/src/init.c +++ b/src/init.c @@ -57,7 +57,10 @@ static _GLFWinitconfig _glfwInitHints = { GLFW_TRUE, // macOS menu bar GLFW_TRUE // macOS bundle chdir - } + }, + { + GLFW_TRUE, // X11 XCB Vulkan surface + }, }; // Terminate the library @@ -298,6 +301,9 @@ GLFWAPI void glfwInitHint(int hint, int value) case GLFW_COCOA_MENUBAR: _glfwInitHints.ns.menubar = value; return; + case GLFW_X11_XCB_VULKAN_SURFACE: + _glfwInitHints.x11.xcbVulkanSurface = value; + return; } _glfwInputError(GLFW_INVALID_ENUM, diff --git a/src/internal.h b/src/internal.h index f87c2f93..32761b1e 100644 --- a/src/internal.h +++ b/src/internal.h @@ -248,6 +248,9 @@ struct _GLFWinitconfig GLFWbool menubar; GLFWbool chdir; } ns; + struct { + GLFWbool xcbVulkanSurface; + } x11; }; // Window configuration diff --git a/src/x11_init.c b/src/x11_init.c index dd24f112..fc9ac427 100644 --- a/src/x11_init.c +++ b/src/x11_init.c @@ -813,11 +813,15 @@ static GLFWbool initExtensions(void) XkbGroupStateMask, XkbGroupStateMask); } + if (_glfw.hints.init.x11.xcbVulkanSurface) + { #if defined(__CYGWIN__) - _glfw.x11.x11xcb.handle = _glfw_dlopen("libX11-xcb-1.so"); + _glfw.x11.x11xcb.handle = _glfw_dlopen("libX11-xcb-1.so"); #else - _glfw.x11.x11xcb.handle = _glfw_dlopen("libX11-xcb.so.1"); + _glfw.x11.x11xcb.handle = _glfw_dlopen("libX11-xcb.so.1"); #endif + } + if (_glfw.x11.x11xcb.handle) { _glfw.x11.x11xcb.GetXCBConnection = (PFN_XGetXCBConnection) From a25e8eb50dcaccc4c6d55a83819a769581d3ee5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Thu, 10 Dec 2020 00:11:44 +0100 Subject: [PATCH 31/50] Add docs for GLFW_X11_XCB_VULKAN_SURFACE Related to #1793. --- README.md | 2 ++ docs/intro.dox | 22 ++++++++++++++++------ docs/news.dox | 1 + include/GLFW/glfw3.h | 6 ++++++ 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index f7d9d75a..1e4b8cc9 100644 --- a/README.md +++ b/README.md @@ -127,6 +127,8 @@ information on what to include when reporting a bug. - Added `GLFW_FEATURE_UNIMPLEMENTED` error for incomplete backends (#1692) - Added `GLFW_ANGLE_PLATFORM_TYPE` init hint and `GLFW_ANGLE_PLATFORM_TYPE_*` values to select ANGLE backend (#1380) + - Added `GLFW_X11_XCB_VULKAN_SURFACE` init hint for selecting X11 Vulkan + surface extension (#1793) - Made joystick subsystem initialize at first use (#1284,#1646) - Updated the minimum required CMake version to 3.1 - Disabled tests and examples by default when built as a CMake subdirectory diff --git a/docs/intro.dox b/docs/intro.dox index efc7c34c..54c8549c 100644 --- a/docs/intro.dox +++ b/docs/intro.dox @@ -124,14 +124,24 @@ a nib or manually by GLFW. Possible values are `GLFW_TRUE` and `GLFW_FALSE`. This is ignored on other platforms. +@subsubsection init_hints_x11 X11 specific init hints + +@anchor GLFW_X11_XCB_VULKAN_SURFACE_hint +__GLFW_X11_XCB_VULKAN_SURFACE__ specifies whether to prefer the +`VK_KHR_xcb_surface` extension for creating Vulkan surfaces, or whether to use +the `VK_KHR_xlib_surface` extension. Possible values are `GLFW_TRUE` and +`GLFW_FALSE`. This is ignored on other platforms. + + @subsubsection init_hints_values Supported and default values -Initialization hint | Default value | Supported values -------------------------------- | ------------------------------- | ---------------- -@ref GLFW_JOYSTICK_HAT_BUTTONS | `GLFW_TRUE` | `GLFW_TRUE` or `GLFW_FALSE` -@ref GLFW_ANGLE_PLATFORM_TYPE | `GLFW_ANGLE_PLATFORM_TYPE_NONE` | `GLFW_ANGLE_PLATFORM_TYPE_NONE`, `GLFW_ANGLE_PLATFORM_TYPE_OPENGL`, `GLFW_ANGLE_PLATFORM_TYPE_OPENGLES`, `GLFW_ANGLE_PLATFORM_TYPE_D3D9`, `GLFW_ANGLE_PLATFORM_TYPE_D3D11`, `GLFW_ANGLE_PLATFORM_TYPE_VULKAN` or `GLFW_ANGLE_PLATFORM_TYPE_METAL` -@ref GLFW_COCOA_CHDIR_RESOURCES | `GLFW_TRUE` | `GLFW_TRUE` or `GLFW_FALSE` -@ref GLFW_COCOA_MENUBAR | `GLFW_TRUE` | `GLFW_TRUE` or `GLFW_FALSE` +Initialization hint | Default value | Supported values +-------------------------------- | ------------------------------- | ---------------- +@ref GLFW_JOYSTICK_HAT_BUTTONS | `GLFW_TRUE` | `GLFW_TRUE` or `GLFW_FALSE` +@ref GLFW_ANGLE_PLATFORM_TYPE | `GLFW_ANGLE_PLATFORM_TYPE_NONE` | `GLFW_ANGLE_PLATFORM_TYPE_NONE`, `GLFW_ANGLE_PLATFORM_TYPE_OPENGL`, `GLFW_ANGLE_PLATFORM_TYPE_OPENGLES`, `GLFW_ANGLE_PLATFORM_TYPE_D3D9`, `GLFW_ANGLE_PLATFORM_TYPE_D3D11`, `GLFW_ANGLE_PLATFORM_TYPE_VULKAN` or `GLFW_ANGLE_PLATFORM_TYPE_METAL` +@ref GLFW_COCOA_CHDIR_RESOURCES | `GLFW_TRUE` | `GLFW_TRUE` or `GLFW_FALSE` +@ref GLFW_COCOA_MENUBAR | `GLFW_TRUE` | `GLFW_TRUE` or `GLFW_FALSE` +@ref GLFW_X11_XCB_VULKAN_SURFACE | `GLFW_TRUE` | `GLFW_TRUE` or `GLFW_FALSE` @subsection intro_init_terminate Terminating GLFW diff --git a/docs/news.dox b/docs/news.dox index 19df848a..d9ed0b1d 100644 --- a/docs/news.dox +++ b/docs/news.dox @@ -142,6 +142,7 @@ then GLFW will fail to initialize. - @ref GLFW_ANGLE_PLATFORM_TYPE_D3D11 - @ref GLFW_ANGLE_PLATFORM_TYPE_VULKAN - @ref GLFW_ANGLE_PLATFORM_TYPE_METAL + - @ref GLFW_X11_XCB_VULKAN_SURFACE @section news_archive Release notes for earlier versions diff --git a/include/GLFW/glfw3.h b/include/GLFW/glfw3.h index ac696cd8..d62d82fa 100644 --- a/include/GLFW/glfw3.h +++ b/include/GLFW/glfw3.h @@ -6018,6 +6018,12 @@ GLFWAPI int glfwGetPhysicalDevicePresentationSupport(VkInstance instance, VkPhys * @remark @macos This function creates and sets a `CAMetalLayer` instance for * the window content view, which is required for MoltenVK to function. * + * @remark @x11 GLFW by default attempts to use the `VK_KHR_xcb_surface` + * extension, if available. You can make it prefer the `VK_KHR_xlib_surface` + * extension by setting the + * [GLFW_X11_XCB_VULKAN_SURFACE](@ref GLFW_X11_XCB_VULKAN_SURFACE_hint) init + * hint. + * * @thread_safety This function may be called from any thread. For * synchronization details of Vulkan objects, see the Vulkan specification. * From f90df2424401e13dc5a81bd9a67f111a83782ecd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Sun, 11 Apr 2021 21:44:02 +0200 Subject: [PATCH 32/50] Add GLFW_X11_XCB_VULKAN_SURFACE flag to glfwinfo --- tests/glfwinfo.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/glfwinfo.c b/tests/glfwinfo.c index 9789f98a..e5b7af10 100644 --- a/tests/glfwinfo.c +++ b/tests/glfwinfo.c @@ -116,6 +116,7 @@ static void usage(void) ANGLE_TYPE_VULKAN " or " ANGLE_TYPE_METAL ")\n"); printf(" --graphics-switching request macOS graphics switching\n"); + printf(" --disable-xcb-surface disable VK_KHR_xcb_surface extension\n"); } static void error_callback(int error, const char* description) @@ -360,6 +361,7 @@ int main(int argc, char** argv) bool fb_doublebuffer = true; int angle_type = GLFW_ANGLE_PLATFORM_TYPE_NONE; bool cocoa_graphics_switching = false; + bool disable_xcb_surface = false; enum { CLIENT, CONTEXT, BEHAVIOR, DEBUG_CONTEXT, FORWARD, HELP, EXTENSIONS, LAYERS, @@ -367,7 +369,7 @@ int main(int argc, char** argv) REDBITS, GREENBITS, BLUEBITS, ALPHABITS, DEPTHBITS, STENCILBITS, ACCUMREDBITS, ACCUMGREENBITS, ACCUMBLUEBITS, ACCUMALPHABITS, AUXBUFFERS, SAMPLES, STEREO, SRGB, SINGLEBUFFER, NOERROR_SRSLY, - ANGLE_TYPE, GRAPHICS_SWITCHING }; + ANGLE_TYPE, GRAPHICS_SWITCHING, XCB_SURFACE }; const struct option options[] = { { "behavior", 1, NULL, BEHAVIOR }, @@ -401,6 +403,7 @@ int main(int argc, char** argv) { "no-error", 0, NULL, NOERROR_SRSLY }, { "angle-type", 1, NULL, ANGLE_TYPE }, { "graphics-switching", 0, NULL, GRAPHICS_SWITCHING }, + { "vk-xcb-surface", 0, NULL, XCB_SURFACE }, { NULL, 0, NULL, 0 } }; @@ -607,6 +610,9 @@ int main(int argc, char** argv) case GRAPHICS_SWITCHING: cocoa_graphics_switching = true; break; + case XCB_SURFACE: + disable_xcb_surface = true; + break; default: usage(); exit(EXIT_FAILURE); @@ -623,6 +629,7 @@ int main(int argc, char** argv) glfwInitHint(GLFW_COCOA_MENUBAR, false); glfwInitHint(GLFW_ANGLE_PLATFORM_TYPE, angle_type); + glfwInitHint(GLFW_X11_XCB_VULKAN_SURFACE, !disable_xcb_surface); if (!glfwInit()) exit(EXIT_FAILURE); From 4c90e21e8f2d2b1edf5741527385cad9b71bc526 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Thu, 10 Dec 2020 00:28:09 +0100 Subject: [PATCH 33/50] Fix grammar in MoltenVK support docs --- include/GLFW/glfw3.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/include/GLFW/glfw3.h b/include/GLFW/glfw3.h index d62d82fa..ffb49c1a 100644 --- a/include/GLFW/glfw3.h +++ b/include/GLFW/glfw3.h @@ -5870,9 +5870,8 @@ GLFWAPI int glfwVulkanSupported(void); * returned array, as it is an error to specify an extension more than once in * the `VkInstanceCreateInfo` struct. * - * @remark @macos This function currently supports either the - * `VK_MVK_macos_surface` extension from MoltenVK or `VK_EXT_metal_surface` - * extension. + * @remark @macos GLFW currently supports both the `VK_MVK_macos_surface` and + * the newer `VK_EXT_metal_surface` extensions. * * @pointer_lifetime The returned array is allocated and freed by GLFW. You * should not free it yourself. It is guaranteed to be valid only until the @@ -5955,7 +5954,7 @@ GLFWAPI GLFWvkproc glfwGetInstanceProcAddress(VkInstance instance, const char* p * GLFW_API_UNAVAILABLE and @ref GLFW_PLATFORM_ERROR. * * @remark @macos This function currently always returns `GLFW_TRUE`, as the - * `VK_MVK_macos_surface` extension does not provide + * `VK_MVK_macos_surface` and `VK_EXT_metal_surface` extensions do not provide * a `vkGetPhysicalDevice*PresentationSupport` type function. * * @thread_safety This function may be called from any thread. For From 0beadfdc667622d59b173ccce8674dc1ff12bb90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Sun, 11 Apr 2021 21:26:27 +0200 Subject: [PATCH 34/50] Add window surface creation to glfwinfo The glfwinfo tool now attempts Vulkan surface creation via glfwCreateWindowSurface and reports the results. --- tests/glfwinfo.c | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/tests/glfwinfo.c b/tests/glfwinfo.c index e5b7af10..d5d14885 100644 --- a/tests/glfwinfo.c +++ b/tests/glfwinfo.c @@ -850,6 +850,17 @@ int main(int argc, char** argv) if (list_extensions) list_context_extensions(client, major, minor); + glfwDestroyWindow(window); + + glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); + + window = glfwCreateWindow(200, 200, "Version", NULL, NULL); + if (!window) + { + glfwTerminate(); + exit(EXIT_FAILURE); + } + printf("Vulkan loader: %s\n", glfwVulkanSupported() ? "available" : "missing"); @@ -873,15 +884,14 @@ int main(int argc, char** argv) uint32_t re_count; const char** re = glfwGetRequiredInstanceExtensions(&re_count); - printf("Vulkan required instance extensions:"); if (re) { + printf("Vulkan window surface required instance extensions:\n"); for (uint32_t i = 0; i < re_count; i++) - printf(" %s", re[i]); - putchar('\n'); + printf(" %s\n", re[i]); } else - printf(" missing\n"); + printf("Vulkan window surface extensions missing\n"); if (list_extensions) list_vulkan_instance_extensions(); @@ -915,6 +925,19 @@ int main(int argc, char** argv) gladLoadVulkanUserPtr(NULL, glad_vulkan_callback, instance); + if (re) + { + VkSurfaceKHR surface = VK_NULL_HANDLE; + + if (glfwCreateWindowSurface(instance, window, NULL, &surface) == VK_SUCCESS) + { + printf("Vulkan window surface created successfully\n"); + vkDestroySurfaceKHR(instance, surface, NULL); + } + else + printf("Failed to create Vulkan window surface\n"); + } + uint32_t pd_count; vkEnumeratePhysicalDevices(instance, &pd_count, NULL); VkPhysicalDevice* pd = calloc(pd_count, sizeof(VkPhysicalDevice)); @@ -943,6 +966,8 @@ int main(int argc, char** argv) vkDestroyInstance(instance, NULL); } + glfwDestroyWindow(window); + glfwTerminate(); exit(EXIT_SUCCESS); } From 330f7da746717dc17532180ff784bc086279d82a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Sun, 11 Apr 2021 22:12:15 +0200 Subject: [PATCH 35/50] Add Vulkan device presentation support to glfwinfo The glfwinfo tool now reports the results of glfwGetPhysicalDevicePresentationSupport for each physical device. --- tests/glfwinfo.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tests/glfwinfo.c b/tests/glfwinfo.c index d5d14885..4b61a776 100644 --- a/tests/glfwinfo.c +++ b/tests/glfwinfo.c @@ -946,7 +946,6 @@ int main(int argc, char** argv) for (uint32_t i = 0; i < pd_count; i++) { VkPhysicalDeviceProperties pdp; - vkGetPhysicalDeviceProperties(pd[i], &pdp); printf("Vulkan %s device: \"%s\" (API version %i.%i)\n", @@ -955,6 +954,19 @@ int main(int argc, char** argv) VK_VERSION_MAJOR(pdp.apiVersion), VK_VERSION_MINOR(pdp.apiVersion)); + uint32_t qfp_count; + vkGetPhysicalDeviceQueueFamilyProperties(pd[i], &qfp_count, NULL); + + printf("Vulkan device queue family presentation support:\n"); + for (uint32_t j = 0; j < qfp_count; j++) + { + printf(" %u: ", j); + if (glfwGetPhysicalDevicePresentationSupport(instance, pd[i], j)) + printf("supported\n"); + else + printf("no\n"); + } + if (list_extensions) list_vulkan_device_extensions(instance, pd[i]); From ec621a00bd96cbc41a7e1f630adf155ae2d08267 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Mon, 12 Apr 2021 00:00:40 +0200 Subject: [PATCH 36/50] Replace GL_ARB_debug_output in context guide New code should use GL_KHR_debug instead but it's not as good an example to use in this case as the symbols it adds has no suffixes. --- docs/context.dox | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/docs/context.dox b/docs/context.dox index dd952122..c51e268c 100644 --- a/docs/context.dox +++ b/docs/context.dox @@ -138,9 +138,9 @@ as extensions until they become obsolete. An extension is defined by: -- An extension name (e.g. `GL_ARB_debug_output`) -- New OpenGL tokens (e.g. `GL_DEBUG_SEVERITY_HIGH_ARB`) -- New OpenGL functions (e.g. `glGetDebugMessageLogARB`) +- An extension name (e.g. `GL_ARB_gl_spirv`) +- New OpenGL tokens (e.g. `GL_SPIR_V_BINARY_ARB`) +- New OpenGL functions (e.g. `glSpecializeShaderARB`) Note the `ARB` affix, which stands for Architecture Review Board and is used for official extensions. The extension above was created by the ARB, but there @@ -225,9 +225,9 @@ To check whether a specific extension is supported, use the `GLAD_GL_xxx` booleans. @code -if (GLAD_GL_ARB_debug_output) +if (GLAD_GL_ARB_gl_spirv) { - // Use GL_ARB_debug_output + // Use GL_ARB_gl_spirv } @endcode @@ -259,8 +259,8 @@ included in your development environment may be several years out of date and may not include the extensions you wish to use. The header defines function pointer types for all functions of all extensions it -supports. These have names like `PFNGLGETDEBUGMESSAGELOGARBPROC` (for -`glGetDebugMessageLogARB`), i.e. the name is made uppercase and `PFN` (pointer +supports. These have names like `PFNGLSPECIALIZESHADERARBPROC` (for +`glSpecializeShaderARB`), i.e. the name is made uppercase and `PFN` (pointer to function) and `PROC` (procedure) are added to the ends. To include the extension header, define @ref GLFW_INCLUDE_GLEXT before including @@ -280,7 +280,7 @@ is necessary to check at run-time whether the context supports the extension. This is done with @ref glfwExtensionSupported. @code -if (glfwExtensionSupported("GL_ARB_debug_output")) +if (glfwExtensionSupported("GL_ARB_gl_spirv")) { // The extension is supported by the current context } @@ -299,7 +299,7 @@ your operating system, making it necessary to fetch them at run time. You can retrieve pointers to these functions with @ref glfwGetProcAddress. @code -PFNGLGETDEBUGMESSAGELOGARBPROC pfnGetDebugMessageLog = glfwGetProcAddress("glGetDebugMessageLogARB"); +PFNGLSPECIALIZESHADERARBPROC pfnSpecializeShaderARB = glfwGetProcAddress("glSpecializeShaderARB"); @endcode In general, you should avoid giving the function pointer variables the (exact) @@ -313,28 +313,28 @@ when used together. #define GLFW_INCLUDE_GLEXT #include -#define glGetDebugMessageLogARB pfnGetDebugMessageLog -PFNGLGETDEBUGMESSAGELOGARBPROC pfnGetDebugMessageLog; +#define glSpecializeShaderARB pfnSpecializeShaderARB +PFNGLSPECIALIZESHADERARBPROC pfnSpecializeShaderARB; // Flag indicating whether the extension is supported -int has_ARB_debug_output = 0; +int has_ARB_gl_spirv = 0; void load_extensions(void) { - if (glfwExtensionSupported("GL_ARB_debug_output")) + if (glfwExtensionSupported("GL_ARB_gl_spirv")) { - pfnGetDebugMessageLog = (PFNGLGETDEBUGMESSAGELOGARBPROC) - glfwGetProcAddress("glGetDebugMessageLogARB"); - has_ARB_debug_output = 1; + pfnSpecializeShaderARB = (PFNGLSPECIALIZESHADERARBPROC) + glfwGetProcAddress("glSpecializeShaderARB"); + has_ARB_gl_spirv = 1; } } void some_function(void) { - if (has_ARB_debug_output) + if (has_ARB_gl_spirv) { // Now the extension function can be called as usual - glGetDebugMessageLogARB(...); + glSpecializeShaderARB(...); } } @endcode From 85bce8a8ead47214404bc66c73aa49f13976a102 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Mon, 12 Apr 2021 00:04:33 +0200 Subject: [PATCH 37/50] Replace GL_ARB_debug_output in comments --- include/GLFW/glfw3native.h | 4 ++-- src/win32_platform.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/GLFW/glfw3native.h b/include/GLFW/glfw3native.h index e680c1e3..108be68b 100644 --- a/include/GLFW/glfw3native.h +++ b/include/GLFW/glfw3native.h @@ -83,8 +83,8 @@ extern "C" { #if defined(GLFW_EXPOSE_NATIVE_WIN32) || defined(GLFW_EXPOSE_NATIVE_WGL) // This is a workaround for the fact that glfw3.h needs to export APIENTRY (for - // example to allow applications to correctly declare a GL_ARB_debug_output - // callback) but windows.h assumes no one will define APIENTRY before it does + // example to allow applications to correctly declare a GL_KHR_debug callback) + // but windows.h assumes no one will define APIENTRY before it does #if defined(GLFW_APIENTRY_DEFINED) #undef APIENTRY #undef GLFW_APIENTRY_DEFINED diff --git a/src/win32_platform.h b/src/win32_platform.h index 6c81d4b5..6449a711 100644 --- a/src/win32_platform.h +++ b/src/win32_platform.h @@ -39,8 +39,8 @@ #endif // This is a workaround for the fact that glfw3.h needs to export APIENTRY (for -// example to allow applications to correctly declare a GL_ARB_debug_output -// callback) but windows.h assumes no one will define APIENTRY before it does +// example to allow applications to correctly declare a GL_KHR_debug callback) +// but windows.h assumes no one will define APIENTRY before it does #undef APIENTRY // GLFW on Windows is Unicode only and does not work in MBCS mode From 061a0263a9783c1442ad96a061c717c167ab4a76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Mon, 12 Apr 2021 20:56:53 +0200 Subject: [PATCH 38/50] Win32: Fix compilation with standalone LLVM The /clang: suffix passed to Clang-CL was accidentally also passed to the regular standalone Clang, which caused compilation to fail. We now pass /W3 to Clang-CL, which it interprets as -Wall. The _CRT_SECURE_NO_WARNINGS macro is now defined for both Clang and Clang-CL. The /entry: flag passed to link.exe is now also passed to lld-link, letting the windows subsystem tests and examples link. Fixes #1807. Closes #1824. Closes #1874. --- README.md | 1 + examples/CMakeLists.txt | 9 +++++++-- src/CMakeLists.txt | 22 +++++++++------------- tests/CMakeLists.txt | 9 +++++++-- 4 files changed, 24 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 1e4b8cc9..29c988b5 100644 --- a/README.md +++ b/README.md @@ -167,6 +167,7 @@ information on what to include when reporting a bug. Windows 10 version 1703 (#1511) - [Win32] Bugfix: `USE_MSVC_RUNTIME_LIBRARY_DLL` had no effect on CMake 3.15 or later (#1783,#1796) + - [Win32] Bugfix: Compilation with LLVM for Windows failed (#1807,#1824,#1874) - [Cocoa] Added support for `VK_EXT_metal_surface` (#1619) - [Cocoa] Added locating the Vulkan loader at runtime in an application bundle - [Cocoa] Moved main menu creation to GLFW initialization time (#1649) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 21ba4838..c93dbe5f 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -7,7 +7,8 @@ if (MATH_LIBRARY) link_libraries("${MATH_LIBRARY}") endif() -if (MSVC) +# Workaround for the MS CRT deprecating parts of the standard library +if (MSVC OR CMAKE_C_SIMULATE_ID STREQUAL "MSVC") add_definitions(-D_CRT_SECURE_NO_WARNINGS) endif() @@ -54,9 +55,13 @@ if (GLFW_USE_OSMESA) endif() if (MSVC) - # Tell MSVC to use main instead of WinMain for Windows subsystem executables + # Tell MSVC to use main instead of WinMain set_target_properties(${GUI_ONLY_BINARIES} PROPERTIES LINK_FLAGS "/ENTRY:mainCRTStartup") +elseif (CMAKE_C_SIMULATE_ID STREQUAL "MSVC") + # Tell Clang using MS CRT to use main instead of WinMain + set_target_properties(${GUI_ONLY_BINARIES} PROPERTIES + LINK_FLAGS "-Wl,/entry:mainCRTStartup") endif() if (APPLE) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2e6a1fa2..80a0d753 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -130,18 +130,14 @@ if (CMAKE_C_COMPILER_ID STREQUAL "GNU") endif() # Enable a reasonable set of warnings -if (CMAKE_C_COMPILER_ID STREQUAL "GNU" OR - CMAKE_C_COMPILER_ID STREQUAL "Clang" OR - CMAKE_C_COMPILER_ID STREQUAL "AppleClang") - - if (CMAKE_C_SIMULATE_ID STREQUAL "MSVC") - # Tell Clang-CL that this is a Clang flag - target_compile_options(glfw PRIVATE "/clang:-Wall") - else() - target_compile_options(glfw PRIVATE "-Wall") - endif() -elseif (MSVC) +# NOTE: The order matters here, Clang-CL matches both MSVC and Clang +if (MSVC) target_compile_options(glfw PRIVATE "/W3") +elseif (CMAKE_C_COMPILER_ID STREQUAL "GNU" OR + CMAKE_C_COMPILER_ID STREQUAL "Clang" OR + CMAKE_C_COMPILER_ID STREQUAL "AppleClang") + + target_compile_options(glfw PRIVATE "-Wall") endif() if (WIN32) @@ -166,8 +162,8 @@ if (MINGW) endif() endif() -# Workaround for VS deprecating parts of the standard library -if (MSVC) +# Workaround for the MS CRT deprecating parts of the standard library +if (MSVC OR CMAKE_C_SIMULATE_ID STREQUAL "MSVC") target_compile_definitions(glfw PRIVATE _CRT_SECURE_NO_WARNINGS) endif() diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 52588244..a704bc07 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -7,7 +7,8 @@ if (MATH_LIBRARY) link_libraries("${MATH_LIBRARY}") endif() -if (MSVC) +# Workaround for the MS CRT deprecating parts of the standard library +if (MSVC OR CMAKE_C_SIMULATE_ID STREQUAL "MSVC") add_definitions(-D_CRT_SECURE_NO_WARNINGS) endif() @@ -58,9 +59,13 @@ set_target_properties(${GUI_ONLY_BINARIES} ${CONSOLE_BINARIES} PROPERTIES FOLDER "GLFW3/Tests") if (MSVC) - # Tell MSVC to use main instead of WinMain for Windows subsystem executables + # Tell MSVC to use main instead of WinMain set_target_properties(${GUI_ONLY_BINARIES} PROPERTIES LINK_FLAGS "/ENTRY:mainCRTStartup") +elseif (CMAKE_C_SIMULATE_ID STREQUAL "MSVC") + # Tell Clang using MS CRT to use main instead of WinMain + set_target_properties(${GUI_ONLY_BINARIES} PROPERTIES + LINK_FLAGS "-Wl,/entry:mainCRTStartup") endif() if (APPLE) From e3f916808ddc9b1064d7d585a2d5bbac9fa53038 Mon Sep 17 00:00:00 2001 From: Konstantin Podsvirov Date: Thu, 15 Apr 2021 18:54:45 +0300 Subject: [PATCH 39/50] Fix hardcoded runtime destination in CMake install Closes #1883. Closes #1884. --- src/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 80a0d753..d29ad8df 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -239,7 +239,7 @@ endif() if (GLFW_INSTALL) install(TARGETS glfw EXPORT glfwTargets - RUNTIME DESTINATION "bin" + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}") endif() From 0e9ec7788b4985a0df698080258e4091d18dcc3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Thu, 22 Apr 2021 23:07:50 +0200 Subject: [PATCH 40/50] Fix description of video mode ordering in docs The two final sorting criteria were not included in the documentation. Fixes #1889. --- README.md | 1 + include/GLFW/glfw3.h | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 29c988b5..54dcec80 100644 --- a/README.md +++ b/README.md @@ -294,6 +294,7 @@ skills. - Andrew Corrigan - Bailey Cosier - Noel Cower + - CuriouserThing - Jason Daly - Jarrod Davis - Olivier Delannoy diff --git a/include/GLFW/glfw3.h b/include/GLFW/glfw3.h index ffb49c1a..d38acbb0 100644 --- a/include/GLFW/glfw3.h +++ b/include/GLFW/glfw3.h @@ -2422,8 +2422,9 @@ GLFWAPI GLFWmonitorfun glfwSetMonitorCallback(GLFWmonitorfun callback); * * This function returns an array of all video modes supported by the specified * monitor. The returned array is sorted in ascending order, first by color - * bit depth (the sum of all channel depths) and then by resolution area (the - * product of width and height). + * bit depth (the sum of all channel depths), then by resolution area (the + * product of width and height), then resolution width and finally by refresh + * rate. * * @param[in] monitor The monitor to query. * @param[out] count Where to store the number of video modes in the returned From a646f51bca867e04254c5fdcb741741265bc4d6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Fri, 16 Apr 2021 17:09:44 +0200 Subject: [PATCH 41/50] Win32: Fix macros being enabled for other backends _UNICODE should not be defined for other backends even when built on Windows. --- src/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d29ad8df..f09775a3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -140,7 +140,7 @@ elseif (CMAKE_C_COMPILER_ID STREQUAL "GNU" OR target_compile_options(glfw PRIVATE "-Wall") endif() -if (WIN32) +if (_GLFW_WIN32) target_compile_definitions(glfw PRIVATE _UNICODE) endif() From 9a3a8bc26799f9a57f62ab7980537a48090c89e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Tue, 20 Apr 2021 15:37:48 +0200 Subject: [PATCH 42/50] Win32: Always define UNICODE and _UNICODE --- src/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f09775a3..f6e404f2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -141,7 +141,7 @@ elseif (CMAKE_C_COMPILER_ID STREQUAL "GNU" OR endif() if (_GLFW_WIN32) - target_compile_definitions(glfw PRIVATE _UNICODE) + target_compile_definitions(glfw PRIVATE UNICODE _UNICODE) endif() # HACK: When building on MinGW, WINVER and UNICODE need to be defined before @@ -149,7 +149,7 @@ endif() # win32_platform.h. We define them here until a saner solution can be found # NOTE: MinGW-w64 and Visual C++ do /not/ need this hack. if (MINGW) - target_compile_definitions(glfw PRIVATE UNICODE WINVER=0x0501) + target_compile_definitions(glfw PRIVATE WINVER=0x0501) endif() # Workaround for legacy MinGW not providing XInput and DirectInput From e17ffcd0db4541816ebf4cf973ebcee18e287733 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Wed, 12 May 2021 18:49:35 +0200 Subject: [PATCH 43/50] Fix header version macro descriptions in docs --- include/GLFW/glfw3.h | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/include/GLFW/glfw3.h b/include/GLFW/glfw3.h index d38acbb0..e3cda682 100644 --- a/include/GLFW/glfw3.h +++ b/include/GLFW/glfw3.h @@ -276,23 +276,24 @@ extern "C" { /*! @name GLFW version macros * @{ */ -/*! @brief The major version number of the GLFW library. +/*! @brief The major version number of the GLFW header. * - * This is incremented when the API is changed in non-compatible ways. + * The major version number of the GLFW header. This is incremented when the + * API is changed in non-compatible ways. * @ingroup init */ #define GLFW_VERSION_MAJOR 3 -/*! @brief The minor version number of the GLFW library. +/*! @brief The minor version number of the GLFW header. * - * This is incremented when features are added to the API but it remains - * backward-compatible. + * The minor version number of the GLFW header. This is incremented when + * features are added to the API but it remains backward-compatible. * @ingroup init */ #define GLFW_VERSION_MINOR 4 -/*! @brief The revision number of the GLFW library. +/*! @brief The revision number of the GLFW header. * - * This is incremented when a bug fix release is made that does not contain any - * API changes. + * The revision number of the GLFW header. This is incremented when a bug fix + * release is made that does not contain any API changes. * @ingroup init */ #define GLFW_VERSION_REVISION 0 From bbbbd3e87094d44191197659ab07081262f07d06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Wed, 12 May 2021 18:53:06 +0200 Subject: [PATCH 44/50] Clarify documentation for hints --- docs/intro.dox | 1 - docs/window.dox | 91 ++++++++++++++++++++----------------------------- 2 files changed, 37 insertions(+), 55 deletions(-) diff --git a/docs/intro.dox b/docs/intro.dox index 54c8549c..3593ab1e 100644 --- a/docs/intro.dox +++ b/docs/intro.dox @@ -103,7 +103,6 @@ one of `GLFW_ANGLE_PLATFORM_TYPE_NONE`, `GLFW_ANGLE_PLATFORM_TYPE_OPENGL`, `GLFW_ANGLE_PLATFORM_TYPE_D3D11`, `GLFW_ANGLE_PLATFORM_TYPE_VULKAN` and `GLFW_ANGLE_PLATFORM_TYPE_METAL`. -@par The ANGLE platform type is specified via the `EGL_ANGLE_platform_angle` extension. This extension is not used if this hint is `GLFW_ANGLE_PLATFORM_TYPE_NONE`, which is the default value. diff --git a/docs/window.dox b/docs/window.dox index 0eb2b24a..b145e364 100644 --- a/docs/window.dox +++ b/docs/window.dox @@ -236,7 +236,8 @@ does not affect window decorations. Possible values are `GLFW_TRUE` and @anchor GLFW_FOCUS_ON_SHOW_hint __GLFW_FOCUS_ON_SHOW__ specifies whether the window will be given input -focus when @ref glfwShowWindow is called. Possible values are `GLFW_TRUE` and `GLFW_FALSE`. +focus when @ref glfwShowWindow is called. Possible values are `GLFW_TRUE` and +`GLFW_FALSE`. @anchor GLFW_SCALE_TO_MONITOR __GLFW_SCALE_TO_MONITOR__ specified whether the window content area should be @@ -278,7 +279,6 @@ __GLFW_ACCUM_ALPHA_BITS__ specify the desired bit depths of the various components of the accumulation buffer. A value of `GLFW_DONT_CARE` means the application has no preference. -@par Accumulation buffers are a legacy OpenGL feature and should not be used in new code. @@ -286,7 +286,6 @@ code. __GLFW_AUX_BUFFERS__ specifies the desired number of auxiliary buffers. A value of `GLFW_DONT_CARE` means the application has no preference. -@par Auxiliary buffers are a legacy OpenGL feature and should not be used in new code. @@ -303,14 +302,12 @@ the application has no preference. __GLFW_SRGB_CAPABLE__ specifies whether the framebuffer should be sRGB capable. Possible values are `GLFW_TRUE` and `GLFW_FALSE`. -@par -__OpenGL:__ If enabled and supported by the system, the `GL_FRAMEBUFFER_SRGB` -enable will control sRGB rendering. By default, sRGB rendering will be -disabled. +@note __OpenGL:__ If enabled and supported by the system, the +`GL_FRAMEBUFFER_SRGB` enable will control sRGB rendering. By default, sRGB +rendering will be disabled. -@par -__OpenGL ES:__ If enabled and supported by the system, the context will always -have sRGB rendering enabled. +@note __OpenGL ES:__ If enabled and supported by the system, the context will +always have sRGB rendering enabled. @anchor GLFW_DOUBLEBUFFER __GLFW_DOUBLEBUFFER__ specifies whether the framebuffer should be double @@ -339,28 +336,25 @@ create the context. Possible values are `GLFW_NATIVE_CONTEXT_API`, `GLFW_EGL_CONTEXT_API` and `GLFW_OSMESA_CONTEXT_API`. This is a hard constraint. If no client API is requested, this hint is ignored. -@par -@macos The EGL API is not available on this platform and requests to use it -will fail. +An [extension loader library](@ref context_glext_auto) that assumes it knows +which API was used to create the current context may fail if you change this +hint. This can be resolved by having it load functions via @ref +glfwGetProcAddress. -@par -__Wayland:__ The EGL API _is_ the native context creation API, so this hint +@note @macos The EGL API is not available on this platform and requests to use +it will fail. + +@note @wayland The EGL API _is_ the native context creation API, so this hint will have no effect. -@par -__OSMesa:__ As its name implies, an OpenGL context created with OSMesa does not -update the window contents when its buffers are swapped. Use OpenGL functions -or the OSMesa native access functions @ref glfwGetOSMesaColorBuffer and @ref -glfwGetOSMesaDepthBuffer to retrieve the framebuffer contents. +@note @x11 On some Linux systems, creating contexts via both the native and EGL +APIs in a single process will cause the application to segfault. Stick to one +API or the other on Linux for now. -@note An OpenGL extension loader library that assumes it knows which context -creation API is used on a given platform may fail if you change this hint. This -can be resolved by having it load via @ref glfwGetProcAddress, which always uses -the selected API. - -@bug On some Linux systems, creating contexts via both the native and EGL APIs -in a single process will cause the application to segfault. Stick to one API or -the other on Linux for now. +@note __OSMesa:__ As its name implies, an OpenGL context created with OSMesa +does not update the window contents when its buffers are swapped. Use OpenGL +functions or the OSMesa native access functions @ref glfwGetOSMesaColorBuffer +and @ref glfwGetOSMesaDepthBuffer to retrieve the framebuffer contents. @anchor GLFW_CONTEXT_VERSION_MAJOR_hint @anchor GLFW_CONTEXT_VERSION_MINOR_hint @@ -368,27 +362,24 @@ __GLFW_CONTEXT_VERSION_MAJOR__ and __GLFW_CONTEXT_VERSION_MINOR__ specify the client API version that the created context must be compatible with. The exact behavior of these hints depend on the requested client API. -@note Do not confuse these hints with `GLFW_VERSION_MAJOR` and -`GLFW_VERSION_MINOR`, which provide the API version of the GLFW header. - -@par -__OpenGL:__ These hints are not hard constraints, but creation will fail if the -OpenGL version of the created context is less than the one requested. It is -therefore perfectly safe to use the default of version 1.0 for legacy code and -you will still get backwards-compatible contexts of version 3.0 and above when -available. - -@par While there is no way to ask the driver for a context of the highest supported version, GLFW will attempt to provide this when you ask for a version 1.0 context, which is the default for these hints. -@par -__OpenGL ES:__ These hints are not hard constraints, but creation will fail if -the OpenGL ES version of the created context is less than the one requested. -Additionally, OpenGL ES 1.x cannot be returned if 2.0 or later was requested, -and vice versa. This is because OpenGL ES 3.x is backward compatible with 2.0, -but OpenGL ES 2.0 is not backward compatible with 1.x. +Do not confuse these hints with @ref GLFW_VERSION_MAJOR and @ref +GLFW_VERSION_MINOR, which provide the API version of the GLFW header. + +@note __OpenGL:__ These hints are not hard constraints, but creation will fail +if the OpenGL version of the created context is less than the one requested. It +is therefore perfectly safe to use the default of version 1.0 for legacy code +and you will still get backwards-compatible contexts of version 3.0 and above +when available. + +@note __OpenGL ES:__ These hints are not hard constraints, but creation will +fail if the OpenGL ES version of the created context is less than the one +requested. Additionally, OpenGL ES 1.x cannot be returned if 2.0 or later was +requested, and vice versa. This is because OpenGL ES 3.x is backward compatible +with 2.0, but OpenGL ES 2.0 is not backward compatible with 1.x. @note @macos The OS only supports core profile contexts for OpenGL versions 3.2 and later. Before creating an OpenGL context of version 3.2 or later you must @@ -401,7 +392,6 @@ forward-compatible, i.e. one where all functionality deprecated in the requested version of OpenGL is removed. This must only be used if the requested OpenGL version is 3.0 or above. If OpenGL ES is requested, this hint is ignored. -@par Forward-compatibility is described in detail in the [OpenGL Reference Manual](https://www.opengl.org/registry/). @@ -411,13 +401,11 @@ __GLFW_CONTEXT_DEBUG__ specifies whether the context should be created in debug mode, which may provide additional error and diagnostic reporting functionality. Possible values are `GLFW_TRUE` and `GLFW_FALSE`. -@par Debug contexts for OpenGL and OpenGL ES are described in detail by the [GL_KHR_debug](https://www.khronos.org/registry/OpenGL/extensions/KHR/KHR_debug.txt) extension. -@par -This is the new name, introduced in GLFW 3.4. The older +@note `GLFW_CONTEXT_DEBUG` is the new name introduced in GLFW 3.4. The older `GLFW_OPENGL_DEBUG_CONTEXT` name is also available for compatibility. @anchor GLFW_OPENGL_PROFILE_hint @@ -428,7 +416,6 @@ a specific profile. If requesting an OpenGL version below 3.2, `GLFW_OPENGL_ANY_PROFILE` must be used. If OpenGL ES is requested, this hint is ignored. -@par OpenGL profiles are described in detail in the [OpenGL Reference Manual](https://www.opengl.org/registry/). @@ -448,7 +435,6 @@ the pipeline will be flushed whenever the context is released from being the current one. If the behavior is `GLFW_RELEASE_BEHAVIOR_NONE`, the pipeline will not be flushed on release. -@par Context release behaviors are described in detail by the [GL_KHR_context_flush_control](https://www.opengl.org/registry/specs/KHR/context_flush_control.txt) extension. @@ -458,7 +444,6 @@ __GLFW_CONTEXT_NO_ERROR__ specifies whether errors should be generated by the context. Possible values are `GLFW_TRUE` and `GLFW_FALSE`. If enabled, situations that would have generated errors instead cause undefined behavior. -@par The no error mode for OpenGL and OpenGL ES is described in detail by the [GL_KHR_no_error](https://www.opengl.org/registry/specs/KHR/no_error.txt) extension. @@ -492,12 +477,10 @@ run on the discrete GPU. This only affects systems with both integrated and discrete GPUs. Possible values are `GLFW_TRUE` and `GLFW_FALSE`. This is ignored on other platforms. -@par Simpler programs and tools may want to enable this to save power, while games and other applications performing advanced rendering will want to leave it disabled. -@par A bundled application that wishes to participate in Automatic Graphics Switching should also declare this in its `Info.plist` by setting the `NSSupportsAutomaticGraphicsSwitching` key to `true`. From a39115a27b3f4695729e1a72e41b3217a841b94f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Thu, 13 May 2021 15:03:49 +0200 Subject: [PATCH 45/50] Remove claim that EGL is not supported on macOS --- docs/window.dox | 3 --- 1 file changed, 3 deletions(-) diff --git a/docs/window.dox b/docs/window.dox index b145e364..f72edaed 100644 --- a/docs/window.dox +++ b/docs/window.dox @@ -341,9 +341,6 @@ which API was used to create the current context may fail if you change this hint. This can be resolved by having it load functions via @ref glfwGetProcAddress. -@note @macos The EGL API is not available on this platform and requests to use -it will fail. - @note @wayland The EGL API _is_ the native context creation API, so this hint will have no effect. From da236ba807b73fb8050e52f1f1450266e7529659 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Thu, 13 May 2021 17:32:31 +0200 Subject: [PATCH 46/50] Make monitor and joystick names static strings Related to #478. --- src/cocoa_monitor.m | 8 ++++---- src/input.c | 3 +-- src/internal.h | 4 ++-- src/monitor.c | 4 +--- src/wl_monitor.c | 6 ++---- 5 files changed, 10 insertions(+), 15 deletions(-) diff --git a/src/cocoa_monitor.m b/src/cocoa_monitor.m index 8eb3f70d..31bf0434 100644 --- a/src/cocoa_monitor.m +++ b/src/cocoa_monitor.m @@ -63,7 +63,7 @@ static char* getMonitorName(CGDirectDisplayID displayID, NSScreen* screen) &it) != 0) { // This may happen if a desktop Mac is running headless - return NULL; + return _glfw_strdup("Display"); } while ((service = IOIteratorNext(it)) != 0) @@ -101,7 +101,7 @@ static char* getMonitorName(CGDirectDisplayID displayID, NSScreen* screen) { _glfwInputError(GLFW_PLATFORM_ERROR, "Cocoa: Failed to find service port for display"); - return NULL; + return _glfw_strdup("Display"); } CFDictionaryRef names = @@ -114,7 +114,7 @@ static char* getMonitorName(CGDirectDisplayID displayID, NSScreen* screen) { // This may happen if a desktop Mac is running headless CFRelease(info); - return NULL; + return _glfw_strdup("Display"); } const CFIndex size = @@ -356,7 +356,7 @@ void _glfwPollMonitorsNS(void) const CGSize size = CGDisplayScreenSize(displays[i]); char* name = getMonitorName(displays[i], screen); if (!name) - name = _glfw_strdup("Unknown"); + continue; _GLFWmonitor* monitor = _glfwAllocMonitor(name, size.width, size.height); monitor->ns.displayID = displays[i]; diff --git a/src/input.c b/src/input.c index 226f835d..9cc0c366 100644 --- a/src/input.c +++ b/src/input.c @@ -446,7 +446,6 @@ _GLFWjoystick* _glfwAllocJoystick(const char* name, js = _glfw.joysticks + jid; js->present = GLFW_TRUE; - js->name = _glfw_strdup(name); js->axes = calloc(axisCount, sizeof(float)); js->buttons = calloc(buttonCount + (size_t) hatCount * 4, 1); js->hats = calloc(hatCount, 1); @@ -454,6 +453,7 @@ _GLFWjoystick* _glfwAllocJoystick(const char* name, js->buttonCount = buttonCount; js->hatCount = hatCount; + strncpy(js->name, name, sizeof(js->name) - 1); strncpy(js->guid, guid, sizeof(js->guid) - 1); js->mapping = findValidMapping(js); @@ -464,7 +464,6 @@ _GLFWjoystick* _glfwAllocJoystick(const char* name, // void _glfwFreeJoystick(_GLFWjoystick* js) { - free(js->name); free(js->axes); free(js->buttons); free(js->hats); diff --git a/src/internal.h b/src/internal.h index 32761b1e..dc1771a7 100644 --- a/src/internal.h +++ b/src/internal.h @@ -435,7 +435,7 @@ struct _GLFWwindow // struct _GLFWmonitor { - char* name; + char name[128]; void* userPointer; // Physical dimensions in millimeters. @@ -496,7 +496,7 @@ struct _GLFWjoystick int buttonCount; unsigned char* hats; int hatCount; - char* name; + char name[128]; void* userPointer; char guid[33]; _GLFWmapping* mapping; diff --git a/src/monitor.c b/src/monitor.c index 394026f5..bde93010 100644 --- a/src/monitor.c +++ b/src/monitor.c @@ -170,8 +170,7 @@ _GLFWmonitor* _glfwAllocMonitor(const char* name, int widthMM, int heightMM) monitor->widthMM = widthMM; monitor->heightMM = heightMM; - if (name) - monitor->name = _glfw_strdup(name); + strncpy(monitor->name, name, sizeof(monitor->name) - 1); return monitor; } @@ -189,7 +188,6 @@ void _glfwFreeMonitor(_GLFWmonitor* monitor) _glfwFreeGammaArrays(&monitor->currentRamp); free(monitor->modes); - free(monitor->name); free(monitor); } diff --git a/src/wl_monitor.c b/src/wl_monitor.c index d722beaa..62037618 100644 --- a/src/wl_monitor.c +++ b/src/wl_monitor.c @@ -47,15 +47,13 @@ static void outputHandleGeometry(void* data, int32_t transform) { struct _GLFWmonitor *monitor = data; - char name[1024]; monitor->wl.x = x; monitor->wl.y = y; monitor->widthMM = physicalWidth; monitor->heightMM = physicalHeight; - snprintf(name, sizeof(name), "%s %s", make, model); - monitor->name = _glfw_strdup(name); + snprintf(monitor->name, sizeof(monitor->name), "%s %s", make, model); } static void outputHandleMode(void* data, @@ -133,7 +131,7 @@ void _glfwAddOutputWayland(uint32_t name, uint32_t version) } // The actual name of this output will be set in the geometry handler. - monitor = _glfwAllocMonitor(NULL, 0, 0); + monitor = _glfwAllocMonitor("", 0, 0); output = wl_registry_bind(_glfw.wl.registry, name, From 04f21abb52e557addb932af1634b29658fd3a6ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Thu, 13 May 2021 21:38:46 +0200 Subject: [PATCH 47/50] Make GLFW_DOUBLEBUFFER a window attribute --- README.md | 1 + docs/window.dox | 14 +++++++++++--- include/GLFW/glfw3.h | 5 +++-- src/internal.h | 1 + src/window.c | 4 ++++ 5 files changed, 20 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 54dcec80..8f81dc67 100644 --- a/README.md +++ b/README.md @@ -130,6 +130,7 @@ information on what to include when reporting a bug. - Added `GLFW_X11_XCB_VULKAN_SURFACE` init hint for selecting X11 Vulkan surface extension (#1793) - Made joystick subsystem initialize at first use (#1284,#1646) + - Made `GLFW_DOUBLEBUFFER` a read-only window attribute - Updated the minimum required CMake version to 3.1 - Disabled tests and examples by default when built as a CMake subdirectory - Bugfix: The CMake config-file package used an absolute path and was not diff --git a/docs/window.dox b/docs/window.dox index f72edaed..5e482431 100644 --- a/docs/window.dox +++ b/docs/window.dox @@ -310,6 +310,7 @@ rendering will be disabled. always have sRGB rendering enabled. @anchor GLFW_DOUBLEBUFFER +@anchor GLFW_DOUBLEBUFFER_hint __GLFW_DOUBLEBUFFER__ specifies whether the framebuffer should be double buffered. You nearly always want to use double buffering. This is a hard constraint. Possible values are `GLFW_TRUE` and `GLFW_FALSE`. @@ -1377,9 +1378,11 @@ if the window's context supports robustness, or `GLFW_NO_ROBUSTNESS` otherwise. @subsubsection window_attribs_fb Framebuffer related attributes -GLFW does not expose attributes of the default framebuffer (i.e. the framebuffer -attached to the window) as these can be queried directly with either OpenGL, -OpenGL ES or Vulkan. +GLFW does not expose most attributes of the default framebuffer (i.e. the +framebuffer attached to the window) as these can be queried directly with either +OpenGL, OpenGL ES or Vulkan. The one exception is +[GLFW_DOUBLEBUFFER](@ref GLFW_DOUBLEBUFFER_attrib), as this is not provided by +OpenGL ES. If you are using version 3.0 or later of OpenGL or OpenGL ES, the `glGetFramebufferAttachmentParameteriv` function can be used to retrieve the @@ -1405,6 +1408,11 @@ alpha sizes are queried from the `GL_BACK_LEFT`, while the depth and stencil sizes are queried from the `GL_DEPTH` and `GL_STENCIL` attachments, respectively. +@anchor GLFW_DOUBLEBUFFER_attrib +__GLFW_DOUBLEBUFFER__ indicates whether the specified window is double-buffered +when rendering with OpenGL or OpenGL ES. This can be set before creation with +the [GLFW_DOUBLEBUFFER](@ref GLFW_DOUBLEBUFFER_hint) window hint. + @section buffer_swap Buffer swapping diff --git a/include/GLFW/glfw3.h b/include/GLFW/glfw3.h index e3cda682..7728dad1 100644 --- a/include/GLFW/glfw3.h +++ b/include/GLFW/glfw3.h @@ -978,9 +978,10 @@ extern "C" { * Monitor refresh rate [hint](@ref GLFW_REFRESH_RATE). */ #define GLFW_REFRESH_RATE 0x0002100F -/*! @brief Framebuffer double buffering hint. +/*! @brief Framebuffer double buffering hint and attribute. * - * Framebuffer double buffering [hint](@ref GLFW_DOUBLEBUFFER). + * Framebuffer double buffering [hint](@ref GLFW_DOUBLEBUFFER_hint) and + * [attribute](@ref GLFW_DOUBLEBUFFER_attrib). */ #define GLFW_DOUBLEBUFFER 0x00021010 diff --git a/src/internal.h b/src/internal.h index dc1771a7..ce9783f9 100644 --- a/src/internal.h +++ b/src/internal.h @@ -387,6 +387,7 @@ struct _GLFWwindow GLFWbool mousePassthrough; GLFWbool shouldClose; void* userPointer; + GLFWbool doublebuffer; GLFWvidmode videoMode; _GLFWmonitor* monitor; _GLFWcursor* cursor; diff --git a/src/window.c b/src/window.c index d2196e2f..518b27fd 100644 --- a/src/window.c +++ b/src/window.c @@ -206,6 +206,8 @@ GLFWAPI GLFWwindow* glfwCreateWindow(int width, int height, window->mousePassthrough = wndconfig.mousePassthrough; window->cursorMode = GLFW_CURSOR_NORMAL; + window->doublebuffer = fbconfig.doublebuffer; + window->minwidth = GLFW_DONT_CARE; window->minheight = GLFW_DONT_CARE; window->maxwidth = GLFW_DONT_CARE; @@ -841,6 +843,8 @@ GLFWAPI int glfwGetWindowAttrib(GLFWwindow* handle, int attrib) return window->floating; case GLFW_AUTO_ICONIFY: return window->autoIconify; + case GLFW_DOUBLEBUFFER: + return window->doublebuffer; case GLFW_CLIENT_API: return window->context.client; case GLFW_CONTEXT_CREATION_API: From 184377b493cd382485914624b30574cfd39216ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Thu, 13 May 2021 21:41:51 +0200 Subject: [PATCH 48/50] Skip initial buffer swap when single-buffered This skips the buffer swap after the initial glClear performed during window creation, if the window is single-buffered. This call confused apitrace into thinking the window was double-buffered. Fixes #1873. --- README.md | 1 + src/context.c | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8f81dc67..b5b4f7ea 100644 --- a/README.md +++ b/README.md @@ -140,6 +140,7 @@ information on what to include when reporting a bug. - Bugfix: Built-in mappings failed because some OEMs re-used VID/PID (#1583) - Bugfix: Some extension loader headers did not prevent default OpenGL header inclusion (#1695) + - Bugfix: Buffers were swapped at creation on single-buffered windows (#1873) - [Win32] Added the `GLFW_WIN32_KEYBOARD_MENU` window hint for enabling access to the window menu - [Win32] Added a version info resource to the GLFW DLL diff --git a/src/context.c b/src/context.c index 48311e5f..12a06e0b 100644 --- a/src/context.c +++ b/src/context.c @@ -570,7 +570,9 @@ GLFWbool _glfwRefreshContextAttribs(_GLFWwindow* window, PFNGLCLEARPROC glClear = (PFNGLCLEARPROC) window->context.getProcAddress("glClear"); glClear(GL_COLOR_BUFFER_BIT); - window->context.swapBuffers(window); + + if (window->doublebuffer) + window->context.swapBuffers(window); } glfwMakeContextCurrent((GLFWwindow*) previous); From fd79b02840a36b74e4289cc53dc332de6403b8fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Fri, 14 May 2021 17:14:13 +0200 Subject: [PATCH 49/50] Move single/double-buffer filtering to backends There is no need to enumerate framebuffer configs that will just be filtered out later by the GLFW_DOUBLEBUFFER hard constraint. --- src/context.c | 6 ------ src/glx_context.c | 5 +++-- src/wgl_context.c | 10 ++++++---- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/context.c b/src/context.c index 12a06e0b..f6629f55 100644 --- a/src/context.c +++ b/src/context.c @@ -196,12 +196,6 @@ const _GLFWfbconfig* _glfwChooseFBConfig(const _GLFWfbconfig* desired, continue; } - if (desired->doublebuffer != current->doublebuffer) - { - // Double buffering is a hard constraint - continue; - } - // Count number of missing buffers { missing = 0; diff --git a/src/glx_context.c b/src/glx_context.c index 7ccd1374..374c15e0 100644 --- a/src/glx_context.c +++ b/src/glx_context.c @@ -92,6 +92,9 @@ static GLFWbool chooseGLXFBConfig(const _GLFWfbconfig* desired, continue; } + if (getGLXFBConfigAttrib(n, GLX_DOUBLEBUFFER) != desired->doublebuffer) + continue; + if (desired->transparent) { XVisualInfo* vi = glXGetVisualFromFBConfig(_glfw.x11.display, n); @@ -119,8 +122,6 @@ static GLFWbool chooseGLXFBConfig(const _GLFWfbconfig* desired, if (getGLXFBConfigAttrib(n, GLX_STEREO)) u->stereo = GLFW_TRUE; - if (getGLXFBConfigAttrib(n, GLX_DOUBLEBUFFER)) - u->doublebuffer = GLFW_TRUE; if (_glfw.glx.ARB_multisample) u->samples = getGLXFBConfigAttrib(n, GLX_SAMPLES); diff --git a/src/wgl_context.c b/src/wgl_context.c index 4f9a6ffe..5b69f8bc 100644 --- a/src/wgl_context.c +++ b/src/wgl_context.c @@ -165,6 +165,9 @@ static int choosePixelFormat(_GLFWwindow* window, if (findAttribValue(WGL_ACCELERATION_ARB) == WGL_NO_ACCELERATION_ARB) continue; + if (findAttribValue(WGL_DOUBLE_BUFFER_ARB) != fbconfig->doublebuffer) + continue; + u->redBits = findAttribValue(WGL_RED_BITS_ARB); u->greenBits = findAttribValue(WGL_GREEN_BITS_ARB); u->blueBits = findAttribValue(WGL_BLUE_BITS_ARB); @@ -182,8 +185,6 @@ static int choosePixelFormat(_GLFWwindow* window, if (findAttribValue(WGL_STEREO_ARB)) u->stereo = GLFW_TRUE; - if (findAttribValue(WGL_DOUBLE_BUFFER_ARB)) - u->doublebuffer = GLFW_TRUE; if (_glfw.wgl.ARB_multisample) u->samples = findAttribValue(WGL_SAMPLES_ARB); @@ -239,6 +240,9 @@ static int choosePixelFormat(_GLFWwindow* window, if (pfd.iPixelType != PFD_TYPE_RGBA) continue; + if (!!(pfd.dwFlags & PFD_DOUBLEBUFFER) != fbconfig->doublebuffer) + continue; + u->redBits = pfd.cRedBits; u->greenBits = pfd.cGreenBits; u->blueBits = pfd.cBlueBits; @@ -256,8 +260,6 @@ static int choosePixelFormat(_GLFWwindow* window, if (pfd.dwFlags & PFD_STEREO) u->stereo = GLFW_TRUE; - if (pfd.dwFlags & PFD_DOUBLEBUFFER) - u->doublebuffer = GLFW_TRUE; } u->handle = pixelFormat; From 114776a24605418e6d719d2f30141e351e93c6e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Fri, 14 May 2021 17:22:26 +0200 Subject: [PATCH 50/50] EGL: Fix creation of single-buffered windows The EGL backend ignored the state of GLFW_DOUBLEBUFFER and always created a double-buffered EGL window. This sets the EGL_RENDER_BUFFER attribute at EGL window creation appropriately. Fixes #1843. --- src/egl_context.c | 5 ++++- src/egl_context.h | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/egl_context.c b/src/egl_context.c index 533ed8e7..975c67be 100644 --- a/src/egl_context.c +++ b/src/egl_context.c @@ -173,7 +173,7 @@ static GLFWbool chooseEGLConfig(const _GLFWctxconfig* ctxconfig, u->stencilBits = getEGLConfigAttrib(n, EGL_STENCIL_SIZE); u->samples = getEGLConfigAttrib(n, EGL_SAMPLES); - u->doublebuffer = GLFW_TRUE; + u->doublebuffer = desired->doublebuffer; u->handle = (uintptr_t) n; usableCount++; @@ -643,6 +643,9 @@ GLFWbool _glfwCreateContextEGL(_GLFWwindow* window, setAttrib(EGL_GL_COLORSPACE_KHR, EGL_GL_COLORSPACE_SRGB_KHR); } + if (!fbconfig->doublebuffer) + setAttrib(EGL_RENDER_BUFFER, EGL_SINGLE_BUFFER); + setAttrib(EGL_NONE, EGL_NONE); native = _glfwPlatformGetEGLNativeWindow(window); diff --git a/src/egl_context.h b/src/egl_context.h index 9de424c9..4c84072e 100644 --- a/src/egl_context.h +++ b/src/egl_context.h @@ -64,6 +64,8 @@ #define EGL_OPENGL_ES_API 0x30a0 #define EGL_OPENGL_API 0x30a2 #define EGL_NONE 0x3038 +#define EGL_RENDER_BUFFER 0x3086 +#define EGL_SINGLE_BUFFER 0x3085 #define EGL_EXTENSIONS 0x3055 #define EGL_CONTEXT_CLIENT_VERSION 0x3098 #define EGL_NATIVE_VISUAL_ID 0x302e