forked from vulkan-go/vulkan
-
Notifications
You must be signed in to change notification settings - Fork 1
/
vk_default_loader.c
52 lines (50 loc) · 1.74 KB
/
vk_default_loader.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include "vk_default_loader.h"
#include "vulkan/vulkan.h"
#if defined(_WIN32)
#include <windows.h>
typedef void* (*vkGetInstanceProcAddrFn)(void* lib, const char* procname);
static vkGetInstanceProcAddrFn symLoader;
static void* loaderWrap(VkInstance instance, const char* vkproc) {
return (*symLoader)(instance, vkproc);
}
#elif defined(unix) || defined(__unix__) || defined(__unix)
#include <dlfcn.h>
static void* (*symLoader)(void* lib, const char* procname);
static void* loaderWrap(VkInstance instance, const char* vkproc) {
return (*symLoader)(instance, vkproc);
}
#elif defined(__APPLE__) && defined(__MACH__)
// #include <GLFW/glfw3.h>
// static void* loaderWrap(VkInstance instance, const char* vkproc) {
// return glfwGetInstanceProcAddress(instance, vkproc);
// }
#endif
void* getDefaultProcAddr() {
#if defined(_WIN32)
HMODULE libvulkan = LoadLibrary(TEXT("vulkan-1.dll"));
if (libvulkan == NULL) {
return NULL;
}
symLoader = (vkGetInstanceProcAddrFn)GetProcAddress(libvulkan, "vkGetInstanceProcAddr");
if (symLoader == NULL) {
return NULL;
}
return &loaderWrap;
#elif defined(__APPLE__) && defined(__MACH__)
// return &loaderWrap;
return NULL;
#elif defined(unix) || defined(__unix__) || defined(__unix)
void* libvulkan = dlopen("libvulkan.so", RTLD_NOW | RTLD_LOCAL);
if (libvulkan == NULL) {
return NULL;
}
symLoader = dlsym(libvulkan, "vkGetInstanceProcAddr");
if (symLoader == NULL) {
return NULL;
}
return &loaderWrap;
#else
// Unknown operating system
return NULL;
#endif
}