mirror of
https://github.com/glfw/glfw.git
synced 2024-11-22 10:05:10 +00:00
Cocoa: Add support for MoltenVK dynamic library
Tested with MoltenVK 0.18.0. Related to #870.
This commit is contained in:
parent
d55c57b504
commit
8e899ccc29
@ -28,12 +28,12 @@ if (WIN32)
|
||||
"$ENV{VK_SDK_PATH}/Bin32")
|
||||
endif()
|
||||
elseif (APPLE)
|
||||
set(CMAKE_FIND_FRAMEWORK NEVER)
|
||||
find_library(VULKAN_LIBRARY MoltenVK)
|
||||
if (VULKAN_LIBRARY)
|
||||
set(VULKAN_STATIC_LIBRARY ${VULKAN_LIBRARY})
|
||||
find_path(VULKAN_INCLUDE_DIR NAMES vulkan/vulkan.h HINTS
|
||||
"${VULKAN_LIBRARY}/Headers")
|
||||
endif()
|
||||
set(CMAKE_FIND_FRAMEWORK ONLY)
|
||||
find_library(VULKAN_STATIC_LIBRARY MoltenVK)
|
||||
find_path(VULKAN_INCLUDE_DIR NAMES vulkan/vulkan.h HINTS
|
||||
"${VULKAN_LIBRARY}/Headers")
|
||||
else()
|
||||
find_path(VULKAN_INCLUDE_DIR NAMES vulkan/vulkan.h HINTS
|
||||
"$ENV{VULKAN_SDK}/include")
|
||||
|
@ -108,8 +108,9 @@ located in the `deps/` directory.
|
||||
- [Vulkan headers](https://www.khronos.org/registry/vulkan/) for Vulkan tests
|
||||
|
||||
The Vulkan example additionally requires the Vulkan SDK to be installed, or it
|
||||
will not be included in the build. On macOS you need to set the path to the
|
||||
MoltenVK SDK manually as it has no standard location.
|
||||
will not be included in the build. On macOS you need to
|
||||
[provide the path](@ref vulkan_loader) to the MoltenVK SDK manually as it has no
|
||||
standard installation location.
|
||||
|
||||
The documentation is generated with [Doxygen](http://doxygen.org/). If CMake
|
||||
does not find Doxygen, the documentation will not be generated when you build.
|
||||
|
@ -20,6 +20,11 @@ The GLFW library does not need the Vulkan SDK to enable support for Vulkan.
|
||||
However, any Vulkan-specific test and example programs are built only if the
|
||||
CMake files find a Vulkan SDK.
|
||||
|
||||
@macos Because MoltenVK is typically not installed system-wide, you will need to
|
||||
point CMake to it using the `CMAKE_FRAMEWORK_PATH` variable when configuring the
|
||||
GLFW source tree. Set this variable to the `MoltenVK/macOS` subdirectory of the
|
||||
SDK, either on the command-line or in the CMake GUI.
|
||||
|
||||
For details on a specific function in this category, see the @ref vulkan. There
|
||||
are also guides for the other areas of the GLFW API.
|
||||
|
||||
@ -34,19 +39,18 @@ are also guides for the other areas of the GLFW API.
|
||||
|
||||
By default, GLFW will look for the Vulkan loader on demand at runtime via its
|
||||
standard name (`vulkan-1.dll` on Windows, `libvulkan.so.1` on Linux and other
|
||||
Unix-like systems). This means that GLFW does not need to be linked against the
|
||||
loader. However, it also means that if you are using the static library form of
|
||||
the Vulkan loader GLFW will either fail to find it or (worse) use the wrong one.
|
||||
Unix-like systems and `libMoltenVK.dylib` on macOS). This means that GLFW does
|
||||
not need to be linked against the loader. However, it also means that if you
|
||||
are using the static library form of the Vulkan loader GLFW will either fail to
|
||||
find it or (worse) use the wrong one.
|
||||
|
||||
The @ref GLFW_VULKAN_STATIC CMake option makes GLFW link directly against the
|
||||
static form. Not linking against the Vulkan loader will then be a compile-time
|
||||
error.
|
||||
static library form. Not linking against the Vulkan loader will then be
|
||||
a compile-time error.
|
||||
|
||||
@macos MoltenVK only provides the static library form of the Vulkan loader, but
|
||||
GLFW is able to find it without @ref GLFW_VULKAN_STATIC as long as it is linked
|
||||
into any of the binaries already loaded into the process. As it is a static
|
||||
library, you must also link against its dependencies: the `Cocoa`, `Metal` and
|
||||
`QuartzCore` frameworks and the `libc++` library.
|
||||
@macos When using the static library form of MoltenVK (i.e. `MetalVK.framework`
|
||||
and not `libMoltenVK.dylib`) you must also link against its dependencies: the
|
||||
`Cocoa`, `Metal` and `QuartzCore` system frameworks and the `libc++` library.
|
||||
|
||||
|
||||
@section vulkan_include Including the Vulkan and GLFW header files
|
||||
|
@ -211,13 +211,7 @@ extern "C" {
|
||||
#endif /* OpenGL and OpenGL ES headers */
|
||||
|
||||
#if defined(GLFW_INCLUDE_VULKAN)
|
||||
|
||||
#if defined(__APPLE__)
|
||||
#include <MoltenVK/vulkan/vulkan.h>
|
||||
#else
|
||||
#include <vulkan/vulkan.h>
|
||||
#endif
|
||||
|
||||
#endif /* Vulkan header */
|
||||
|
||||
#if defined(GLFW_DLL) && defined(_GLFW_BUILD_DLL)
|
||||
|
11
src/vulkan.c
11
src/vulkan.c
@ -52,8 +52,7 @@ GLFWbool _glfwInitVulkan(int mode)
|
||||
#if defined(_GLFW_WIN32)
|
||||
_glfw.vk.handle = _glfw_dlopen("vulkan-1.dll");
|
||||
#elif defined(_GLFW_COCOA)
|
||||
// NULL maps to RTLD_DEFAULT, which searches all loaded binaries
|
||||
_glfw.vk.handle = _glfw_dlopen(NULL);
|
||||
_glfw.vk.handle = _glfw_dlopen("libMoltenVK.dylib");
|
||||
#else
|
||||
_glfw.vk.handle = _glfw_dlopen("libvulkan.so.1");
|
||||
#endif
|
||||
@ -69,16 +68,8 @@ GLFWbool _glfwInitVulkan(int mode)
|
||||
_glfw_dlsym(_glfw.vk.handle, "vkGetInstanceProcAddr");
|
||||
if (!_glfw.vk.GetInstanceProcAddr)
|
||||
{
|
||||
#if defined(_GLFW_COCOA)
|
||||
if (mode == _GLFW_REQUIRE_LOADER)
|
||||
{
|
||||
_glfwInputError(GLFW_API_UNAVAILABLE,
|
||||
"Vulkan: vkGetInstanceProcAddr not found in process");
|
||||
}
|
||||
#else
|
||||
_glfwInputError(GLFW_API_UNAVAILABLE,
|
||||
"Vulkan: Loader does not export vkGetInstanceProcAddr");
|
||||
#endif
|
||||
|
||||
_glfwTerminateVulkan();
|
||||
return GLFW_FALSE;
|
||||
|
@ -53,8 +53,10 @@ set(CONSOLE_BINARIES clipboard events msaa glfwinfo iconify monitors reopen
|
||||
if (VULKAN_FOUND)
|
||||
add_executable(vulkan WIN32 vulkan.c ${ICON})
|
||||
target_include_directories(vulkan PRIVATE "${VULKAN_INCLUDE_DIR}")
|
||||
if (NOT GLFW_VULKAN_STATIC)
|
||||
target_link_libraries(vulkan "${VULKAN_LIBRARY}" ${GLFW_VULKAN_DEPS})
|
||||
if (GLFW_VULKAN_STATIC)
|
||||
target_link_libraries(vulkan "${VULKAN_STATIC_LIBRARY}" ${GLFW_VULKAN_DEPS})
|
||||
else()
|
||||
target_link_libraries(vulkan "${VULKAN_LIBRARY}")
|
||||
endif()
|
||||
list(APPEND WINDOWS_BINARIES vulkan)
|
||||
endif()
|
||||
|
Loading…
Reference in New Issue
Block a user