1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2025-03-15 16:29:16 +01:00
dxvk/src/wsi/glfw/wsi_platform_glfw.cpp
Ethan Lee 10b83d184b [native] Dynamically load SDL2/GLFW at runtime.
Removing these link-time dependencies is important for making a single binary that is compatible with either backend, regardless of whether or not each one is currently available to the program.
2024-05-13 13:18:03 +00:00

58 lines
1.6 KiB
C++

#include "wsi_platform_glfw.h"
#include "../../util/util_error.h"
#include "../../util/util_string.h"
#include "../../util/util_win32_compat.h"
namespace dxvk::wsi {
GlfwWsiDriver::GlfwWsiDriver() {
libglfw = LoadLibraryA( // FIXME: Get soname as string from meson
#if defined(_WIN32)
"glfw.dll"
#elif defined(__APPLE__)
"libglfw.3.dylib"
#else
"libglfw.so.3"
#endif
);
if (libglfw == nullptr)
throw DxvkError("GLFW WSI: Failed to load GLFW DLL.");
#define GLFW_PROC(ret, name, params) \
name = reinterpret_cast<pfn_##name>(GetProcAddress(libglfw, #name)); \
if (name == nullptr) { \
FreeLibrary(libglfw); \
libglfw = nullptr; \
throw DxvkError("GLFW WSI: Failed to load " #name "."); \
}
#include "wsi_platform_glfw_funcs.h"
}
GlfwWsiDriver::~GlfwWsiDriver() {
FreeLibrary(libglfw);
}
std::vector<const char *> GlfwWsiDriver::getInstanceExtensions() {
if (!glfwVulkanSupported())
throw DxvkError(str::format("GLFW WSI: Vulkan is not supported in any capacity!"));
uint32_t extensionCount = 0;
const char** extensionArray = glfwGetRequiredInstanceExtensions(&extensionCount);
if (extensionCount == 0)
throw DxvkError(str::format("GLFW WSI: Failed to get required instance extensions"));
std::vector<const char *> names(extensionCount);
for (uint32_t i = 0; i < extensionCount; ++i) {
names.push_back(extensionArray[i]);
}
return names;
}
WsiDriver* platformCreateWsiDriver() {
return new GlfwWsiDriver();
}
}