From f6360eadee2f1cb21208477ebe65cee89ffca35a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Tue, 20 Feb 2024 13:04:57 +0100 Subject: [PATCH 1/8] NSGL: Fix missing check for OpenGL profile macOS only provides the core profile for OpenGL 3.2 and later. --- README.md | 2 ++ src/nsgl_context.m | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/README.md b/README.md index 787560a6..b7ea493a 100644 --- a/README.md +++ b/README.md @@ -201,6 +201,8 @@ information on what to include when reporting a bug. - [POSIX] Bugfix: `CLOCK_MONOTONIC` was not correctly tested for or enabled - [WGL] Disabled the DWM swap interval hack for Windows 8 and later (#1072) - [NSGL] Removed enforcement of forward-compatible flag for core contexts + - [NSGL] Bugfix: A core profile OpenGL context was returned if 3.2+ + compatibility profile was requested - [EGL] Added platform selection via the `EGL_EXT_platform_base` extension (#442) - [EGL] Added ANGLE backend selection via `EGL_ANGLE_platform_angle` extension diff --git a/src/nsgl_context.m b/src/nsgl_context.m index d19622c6..0b58e20a 100644 --- a/src/nsgl_context.m +++ b/src/nsgl_context.m @@ -175,6 +175,13 @@ GLFWbool _glfwCreateContextNSGL(_GLFWwindow* window, } } + if (ctxconfig->major >= 3 && ctxconfig->profile == GLFW_OPENGL_COMPAT_PROFILE) + { + _glfwInputError(GLFW_VERSION_UNAVAILABLE, + "NSGL: The compatibility profile is not available on macOS"); + return GLFW_FALSE; + } + // Context robustness modes (GL_KHR_robustness) are not yet supported by // macOS but are not a hard constraint, so ignore and continue From 8f2f766f0d2ed476c03a2ae02e48ac41a9602b03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Tue, 20 Feb 2024 16:26:01 +0100 Subject: [PATCH 2/8] NSGL: ANGLE exists --- src/nsgl_context.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nsgl_context.m b/src/nsgl_context.m index 0b58e20a..daa8367a 100644 --- a/src/nsgl_context.m +++ b/src/nsgl_context.m @@ -161,7 +161,7 @@ GLFWbool _glfwCreateContextNSGL(_GLFWwindow* window, if (ctxconfig->client == GLFW_OPENGL_ES_API) { _glfwInputError(GLFW_API_UNAVAILABLE, - "NSGL: OpenGL ES is not available on macOS"); + "NSGL: OpenGL ES is not available via NSGL"); return GLFW_FALSE; } From e28397bda08e75ba0aed67cbbf28f9c2701d5013 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Tue, 20 Feb 2024 12:50:59 +0100 Subject: [PATCH 3/8] Cocoa: Fix glfwGetCocoaWindow error return value --- src/cocoa_window.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cocoa_window.m b/src/cocoa_window.m index 96b6ca61..0dcf0a38 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -2047,7 +2047,7 @@ GLFWAPI id glfwGetCocoaWindow(GLFWwindow* handle) { _glfwInputError(GLFW_PLATFORM_UNAVAILABLE, "Cocoa: Platform not initialized"); - return NULL; + return nil; } return window->ns.object; From 961e45bded3fcee8dffbbcd0e4bc1b1c096a3e37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Tue, 20 Feb 2024 13:21:21 +0100 Subject: [PATCH 4/8] Include declarations from native access header --- src/internal.h | 3 +++ src/platform.h | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/src/internal.h b/src/internal.h index 24750adc..0d528875 100644 --- a/src/internal.h +++ b/src/internal.h @@ -324,6 +324,9 @@ typedef VkResult (APIENTRY * PFN_vkEnumerateInstanceExtensionProperties)(const c #include "platform.h" +#define GLFW_NATIVE_INCLUDE_NONE +#include "../include/GLFW/glfw3native.h" + // Checks for whether the library has been initialized #define _GLFW_REQUIRE_INIT() \ if (!_glfw.initialized) \ diff --git a/src/platform.h b/src/platform.h index 4e924a69..75652dcc 100644 --- a/src/platform.h +++ b/src/platform.h @@ -38,9 +38,13 @@ #endif #include "null_platform.h" +#define GLFW_EXPOSE_NATIVE_EGL +#define GLFW_EXPOSE_NATIVE_OSMESA #if defined(_GLFW_WIN32) #include "win32_platform.h" + #define GLFW_EXPOSE_NATIVE_WIN32 + #define GLFW_EXPOSE_NATIVE_WGL #else #define GLFW_WIN32_WINDOW_STATE #define GLFW_WIN32_MONITOR_STATE @@ -52,6 +56,8 @@ #if defined(_GLFW_COCOA) #include "cocoa_platform.h" + #define GLFW_EXPOSE_NATIVE_COCOA + #define GLFW_EXPOSE_NATIVE_NSGL #else #define GLFW_COCOA_WINDOW_STATE #define GLFW_COCOA_MONITOR_STATE @@ -63,6 +69,7 @@ #if defined(_GLFW_WAYLAND) #include "wl_platform.h" + #define GLFW_EXPOSE_NATIVE_WAYLAND #else #define GLFW_WAYLAND_WINDOW_STATE #define GLFW_WAYLAND_MONITOR_STATE @@ -72,6 +79,8 @@ #if defined(_GLFW_X11) #include "x11_platform.h" + #define GLFW_EXPOSE_NATIVE_X11 + #define GLFW_EXPOSE_NATIVE_GLX #else #define GLFW_X11_WINDOW_STATE #define GLFW_X11_MONITOR_STATE From f6f7ee22843ac1d6e7e7872ca71d30431fbaeb0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Tue, 20 Feb 2024 17:38:54 +0100 Subject: [PATCH 5/8] Add new symbol to list --- docs/news.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/news.md b/docs/news.md index 2eefc1b9..e68464f6 100644 --- a/docs/news.md +++ b/docs/news.md @@ -270,6 +270,7 @@ then GLFW will fail to initialize. - @ref glfwPlatformSupported - @ref glfwInitVulkanLoader - @ref glfwGetWindowTitle + - @ref glfwGetCocoaView #### New types in version 3.4 {#types_34} From b864e4baeb590465700744a68d083fe0ebce5d74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Tue, 20 Feb 2024 19:23:52 +0100 Subject: [PATCH 6/8] Improved build guide slightly --- docs/build.md | 112 ++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 95 insertions(+), 17 deletions(-) diff --git a/docs/build.md b/docs/build.md index 6a5b4a0f..d00d676e 100644 --- a/docs/build.md +++ b/docs/build.md @@ -161,20 +161,95 @@ Linkers][linker_guide] by David Drysdale. [linker_guide]: https://www.lurklurk.org/linkers/linkers.html -### With MinGW or Visual C++ on Windows {#build_link_win32} +### With Visual C++ and GLFW binaries {#build_link_win32} -The static version of the GLFW library is named `glfw3`. When using this -version, it is also necessary to link with some libraries that GLFW uses. +If you are using a downloaded [binary +archive](https://www.glfw.org/download.html), first make sure you have the +archive matching the architecture you are building for (32-bit or 64-bit), or +you will get link errors. Also make sure you are using the binaries for your +version of Visual C++ or you may get other link errors. -When using MinGW to link an application with the static version of GLFW, you -must also explicitly link with `gdi32`. Other toolchains including MinGW-w64 -include it in the set of default libraries along with other dependencies like -`user32` and `kernel32`. +There are two version of the static GLFW library in the binary archive, because +it needs to use the same base run-time library variant as the rest of your +executable. -The link library for the GLFW DLL is named `glfw3dll`. When compiling an -application that uses the DLL version of GLFW, you need to define the @ref -GLFW_DLL macro _before_ any inclusion of the GLFW header. This can be done -either with a compiler switch or by defining it in your source code. +One is named `glfw3.lib` and is for projects with the _Runtime Library_ project +option set to _Multi-threaded DLL_ or _Multi-threaded Debug DLL_. The other is +named `glfw3_mt.lib` and is for projects with _Runtime Library_ set to +_Multi-threaded_ or _Multi-threaded Debug_. To use the static GLFW library you +will need to add `path/to/glfw3.lib` or `path/to/glfw3_mt.lib` to the +_Additional Dependencies_ project option. + +If you compiled a GLFW static library yourself then there will only be one, +named `glfw3.lib`, and you have to make sure the run-time library variant +matches. + +The DLL version of the GLFW library is named `glfw3.dll`, but you will be +linking against the `glfw3dll.lib` link library. To use the DLL you will need +to add `path/to/glfw3dll.lib` to the _Additional Dependencies_ project option. +All of its dependencies are already listed there by default, but when building +with the DLL version of GLFW, you also need to define the @ref GLFW_DLL. This +can be done either in the _Preprocessor Definitions_ project option or by +defining it in your source code before including the GLFW header. + +```c +#define GLFW_DLL +#include +``` + +All link-time dependencies for GLFW are already listed in the _Additional +Dependencies_ option by default. + + +### With MinGW-w64 and GLFW binaries {#build_link_mingw} + +This is intended for building a program from the command-line or by writing +a makefile, on Windows with [MinGW-w64][] and GLFW binaries. These can be from +a downloaded and extracted [binary archive](https://www.glfw.org/download.html) +or by compiling GLFW yourself. The paths below assume a binary archive is used. + +If you are using a downloaded binary archive, first make sure you have the +archive matching the architecture you are building for (32-bit or 64-bit) or you +will get link errors. + +Note that the order of source files and libraries matter for GCC. Dependencies +must be listed after the files that depend on them. Any source files that +depend on GLFW must be listed before the GLFW library. GLFW in turn depends on +`gdi32` and must be listed before it. + +[MinGW-w64]: https://www.mingw-w64.org/ + +If you are using the static version of the GLFW library, which is named +`libglfw3.a`, do: + +```sh +gcc -o myprog myprog.c -I path/to/glfw/include path/to/glfw/lib-mingw-w64/libglfw3.a -lgdi32 +``` + +If you are using the DLL version of the GLFW library, which is named +`glfw3.dll`, you will need to use the `libglfw3dll.a` link library. + +```sh +gcc -o myprog myprog.c -I path/to/glfw/include path/to/glfw/lib-mingw-w64/libglfw3dll.a -lgdi32 +``` + +The resulting executable will need to find `glfw3.dll` to run, typically by +keeping both files in the same directory. + +When you are building with the DLL version of GLFW, you will also need to define +the @ref GLFW_DLL macro. This can be done in your source files, as long as it +done before including the GLFW header: + +```c +#define GLFW_DLL +#include +``` + +It can also be done on the command-line: + +```sh +gcc -o myprog myprog.c -D GLFW_DLL -I path/to/glfw/include path/to/glfw/lib-mingw-w64/libglfw3dll.a -lgdi32 +``` ### With CMake and GLFW source {#build_link_cmake_source} @@ -264,7 +339,10 @@ target_link_libraries(myapp OpenGL::GL) ``` -### With makefiles and pkg-config on Unix {#build_link_pkgconfig} +### With pkg-config and GLFW binaries on Unix {#build_link_pkgconfig} + +This is intended for building a program from the command-line or by writing +a makefile, on macOS or any Unix-like system like Linux, FreeBSD and Cygwin. GLFW supports [pkg-config][], and the `glfw3.pc` pkg-config file is generated when the GLFW library is built and is installed along with it. A pkg-config @@ -316,13 +394,13 @@ OpenGL and IOKit frameworks to the project as dependencies. They can all be found in `/System/Library/Frameworks`. -### With command-line on macOS {#build_link_osx} +### With command-line or makefile on macOS {#build_link_osx} It is recommended that you use [pkg-config](@ref build_link_pkgconfig) when -building from the command line on macOS. That way you will get any new -dependencies added automatically. If you still wish to build manually, you need -to add the required frameworks and libraries to your command-line yourself using -the `-l` and `-framework` switches. +using installed GLFW binaries from the command line on macOS. That way you will +get any new dependencies added automatically. If you still wish to build +manually, you need to add the required frameworks and libraries to your +command-line yourself using the `-l` and `-framework` switches. If you are using the dynamic GLFW library, which is named `libglfw.3.dylib`, do: From 421dc66afb383950cc3b49bc6d57d69e50e518c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Tue, 20 Feb 2024 23:38:16 +0100 Subject: [PATCH 7/8] Remove reference to stale Coverity result --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index b7ea493a..1ea70614 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,6 @@ [![Build status](https://github.com/glfw/glfw/actions/workflows/build.yml/badge.svg)](https://github.com/glfw/glfw/actions) [![Build status](https://ci.appveyor.com/api/projects/status/0kf0ct9831i5l6sp/branch/master?svg=true)](https://ci.appveyor.com/project/elmindreda/glfw) -[![Coverity Scan](https://scan.coverity.com/projects/4884/badge.svg)](https://scan.coverity.com/projects/glfw-glfw) ## Introduction From d7e7b164bc0df637d120f1f0543553f454ced091 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Wed, 21 Feb 2024 00:17:32 +0100 Subject: [PATCH 8/8] Add credit Related to #2359 --- CONTRIBUTORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 26a2936a..c4c74ade 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -179,6 +179,7 @@ video tutorials. - n3rdopolis - Kristian Nielsen - Joel Niemelä + - Victor Nova - Kamil Nowakowski - onox - Denis Ovod