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 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 b4d798b9..b5b4f7ea 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 @@ -127,7 +127,10 @@ 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) + - 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 @@ -137,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 @@ -159,6 +163,13 @@ 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) + - [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) + - [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) @@ -178,6 +189,11 @@ 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) + - [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) @@ -203,6 +219,8 @@ 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 + (#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 @@ -212,6 +230,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 @@ -246,13 +265,16 @@ GLFW exists because people around the world donated their time and lent their skills. - Bobyshev Alexander + - Laurent Aphecetche - Matt Arsenault + - ashishgamedev - David Avedissian - Keith Bauer - John Bartholomew - Coşku Baş - Niklas Behrens - Andrew Belt + - Nevyn Bengtsson - Niklas Bergström - Denis Bernard - Doug Binks @@ -274,6 +296,7 @@ skills. - Andrew Corrigan - Bailey Cosier - Noel Cower + - CuriouserThing - Jason Daly - Jarrod Davis - Olivier Delannoy @@ -439,6 +462,7 @@ skills. - Frank Wille - Andy Williams - Joel Winarske + - Richard A. Wilkes - Tatsuya Yatagawa - Ryogo Yoshimura - Lukas Zanner diff --git a/deps/linmath.h b/deps/linmath.h index 8b2a8c2e..5c802656 100644 --- a/deps/linmath.h +++ b/deps/linmath.h @@ -1,14 +1,13 @@ #ifndef LINMATH_H #define LINMATH_H +#include #include +#include -/* 2020-03-02 Camilla Löwy - * - Added inclusion of string.h for memcpy - * - Replaced tan and acos with tanf and acosf +/* 2021-03-21 Camilla Löwy * - Replaced double constants with float equivalents */ -#include #ifdef LINMATH_NO_INLINE #define LINMATH_H_FUNC static @@ -38,7 +37,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 -#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 diff --git a/docs/intro.dox b/docs/intro.dox index efc7c34c..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. @@ -124,14 +123,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/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. diff --git a/docs/window.dox b/docs/window.dox index 0eb2b24a..5e482431 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,16 +302,15 @@ 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 +@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`. @@ -339,28 +337,22 @@ 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 @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 +360,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 +390,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 +399,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 +414,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 +433,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 +442,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 +475,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`. @@ -1397,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 @@ -1425,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/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/include/GLFW/glfw3.h b/include/GLFW/glfw3.h index 7d9dee02..7728dad1 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 @@ -977,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 @@ -1250,6 +1252,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 @@ -2417,8 +2424,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 @@ -5865,9 +5873,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 @@ -5950,7 +5957,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 @@ -6013,6 +6020,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. * diff --git a/include/GLFW/glfw3native.h b/include/GLFW/glfw3native.h index bc0376cc..92dc1148 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/CMakeLists.txt b/src/CMakeLists.txt index 3a45ea50..f6e404f2 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,22 +130,18 @@ 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) - target_compile_definitions(glfw PRIVATE _UNICODE) +if (_GLFW_WIN32) + target_compile_definitions(glfw PRIVATE UNICODE _UNICODE) endif() # HACK: When building on MinGW, WINVER and UNICODE need to be defined before @@ -153,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 @@ -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() @@ -203,9 +199,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) @@ -246,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() diff --git a/src/cocoa_init.m b/src/cocoa_init.m index edd174be..626d95c2 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,10 @@ int _glfwPlatformInit(void) if (![[NSRunningApplication currentApplication] isFinishedLaunching]) [NSApp run]; + // In case we are unbundled, make us a proper UI application + if (_glfw.hints.init.ns.menubar) + [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular]; + return GLFW_TRUE; } // autoreleasepool diff --git a/src/cocoa_monitor.m b/src/cocoa_monitor.m index 2bb83738..31bf0434 100644 --- a/src/cocoa_monitor.m +++ b/src/cocoa_monitor.m @@ -39,8 +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 + // Luckily, 10.15 introduced -[NSScreen localizedName]. + // Use it if available, and fall back to IOKit otherwise. + if (screen) + { + if ([screen respondsToSelector:@selector(localizedName)]) + { + NSString* name = [screen valueForKey:@"localizedName"]; + if (name) + return _glfw_strdup([name UTF8String]); + } + } + io_iterator_t it; io_service_t service; CFDictionaryRef info; @@ -50,7 +63,7 @@ static char* getDisplayName(CGDirectDisplayID displayID) &it) != 0) { // This may happen if a desktop Mac is running headless - return NULL; + return _glfw_strdup("Display"); } while ((service = IOIteratorNext(it)) != 0) @@ -88,7 +101,7 @@ static char* getDisplayName(CGDirectDisplayID displayID) { _glfwInputError(GLFW_PLATFORM_ERROR, "Cocoa: Failed to find service port for display"); - return NULL; + return _glfw_strdup("Display"); } CFDictionaryRef names = @@ -101,7 +114,7 @@ static char* getDisplayName(CGDirectDisplayID displayID) { // This may happen if a desktop Mac is running headless CFRelease(info); - return NULL; + return _glfw_strdup("Display"); } const CFIndex size = @@ -209,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) @@ -334,27 +322,46 @@ 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]); - 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) { + disconnected[j]->ns.screen = screen; disconnected[j] = NULL; break; } } + if (j < disconnectedCount) + continue; + const CGSize size = CGDisplayScreenSize(displays[i]); - char* name = getDisplayName(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]; monitor->ns.unitNumber = unitNumber; + monitor->ns.screen = screen; free(name); @@ -463,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]; @@ -483,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]; @@ -527,7 +540,7 @@ GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* count) } // Skip duplicate modes - if (i < *count) + if (j < *count) continue; (*count)++; diff --git a/src/context.c b/src/context.c index 48311e5f..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; @@ -570,7 +564,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); 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 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/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/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 48053cde..ce9783f9 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 @@ -350,9 +353,9 @@ struct _GLFWcontext int robustness; int release; - PFNGLGETSTRINGIPROC GetStringi; + PFNGLGETSTRINGIPROC GetStringi; PFNGLGETINTEGERVPROC GetIntegerv; - PFNGLGETSTRINGPROC GetString; + PFNGLGETSTRINGPROC GetString; _GLFWmakecontextcurrentfun makeCurrent; _GLFWswapbuffersfun swapBuffers; @@ -384,6 +387,7 @@ struct _GLFWwindow GLFWbool mousePassthrough; GLFWbool shouldClose; void* userPointer; + GLFWbool doublebuffer; GLFWvidmode videoMode; _GLFWmonitor* monitor; _GLFWcursor* cursor; @@ -405,23 +409,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 @@ -432,7 +436,7 @@ struct _GLFWwindow // struct _GLFWmonitor { - char* name; + char name[128]; void* userPointer; // Physical dimensions in millimeters. @@ -493,7 +497,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/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; diff --git a/src/win32_init.c b/src/win32_init.c index f6995e51..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 @@ -614,7 +618,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" 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 diff --git a/src/win32_window.c b/src/win32_window.c index febafae4..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()) + // 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); diff --git a/src/window.c b/src/window.c index efcb4125..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: @@ -882,27 +886,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 +906,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); } diff --git a/src/wl_monitor.c b/src/wl_monitor.c index 4cbfb51d..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, @@ -81,22 +79,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); } @@ -134,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, 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) 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); 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) diff --git a/tests/glfwinfo.c b/tests/glfwinfo.c index 9789f98a..4b61a776 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); @@ -843,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"); @@ -866,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(); @@ -908,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)); @@ -916,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", @@ -925,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]); @@ -936,6 +978,8 @@ int main(int argc, char** argv) vkDestroyInstance(instance, NULL); } + glfwDestroyWindow(window); + glfwTerminate(); exit(EXIT_SUCCESS); }