Lugdunum  0.1.0
Loader.cpp
Go to the documentation of this file.
2 
5 
6 namespace lug {
7 namespace Graphics {
8 namespace Vulkan {
9 namespace API {
10 
12 #if defined(LUG_SYSTEM_WINDOWS)
13  _handle = System::Library::open("vulkan-1.dll");
14 #elif defined(LUG_SYSTEM_ANDROID)
15  _handle = System::Library::open("libvulkan.so");
16 #else
17  _handle = System::Library::open("libvulkan.so.1");
18 #endif
19 
20  if (!_handle) {
21  return false;
22  }
23 
24 #define LUG_LOAD_VULKAN_FUNCTIONS(name) \
25  { \
26  name = System::Library::sym<PFN_##name>(_handle, #name); \
27  if (!name) { \
28  return false; \
29  } \
30  }
31 
33 
34 #undef LUG_LOAD_VULKAN_FUNCTIONS
35 
36 #define LUG_LOAD_VULKAN_FUNCTIONS(name) \
37  { \
38  name = reinterpret_cast<PFN_##name>(vkGetInstanceProcAddr(nullptr, #name)); \
39  if (!name) { \
40  LUG_LOG.error("Vulkan: Can't load symbol {}", #name); \
41  return false; \
42  } \
43  }
44 
46 
47 #undef LUG_LOAD_VULKAN_FUNCTIONS
48 
49  return true;
50 }
51 
52 bool Loader::loadInstanceFunctions(const Instance& instance) {
53 #define LUG_LOAD_VULKAN_FUNCTIONS(name) \
54  { \
55  name = instance.getProcAddr<PFN_##name>(#name); \
56  if (!name) { \
57  LUG_LOG.error("Vulkan: Can't load symbol {}", #name); \
58  return false; \
59  } \
60  }
61 
63 
64 #undef LUG_LOAD_VULKAN_FUNCTIONS
65 
66  return true;
67 }
68 
69 bool Loader::loadDeviceFunctions(const Device& device) {
70 #define LUG_LOAD_VULKAN_FUNCTIONS(name) \
71  { \
72  name = device.getProcAddr<PFN_##name>(#name); \
73  if (!name) { \
74  LUG_LOG.error("Vulkan: Can't load symbol {}", #name); \
75  return false; \
76  } \
77  }
78 
80 
81 #undef LUG_LOAD_VULKAN_FUNCTIONS
82 
83  return true;
84 }
85 
87 #define LUG_UNLOAD_VULKAN_FUNCTIONS(name) name = nullptr;
92 #undef LUG_UNLOAD_VULKAN_FUNCTIONS
93 
95 }
96 
97 } // API
98 } // Vulkan
99 } // Graphics
100 } // lug
#define LUG_CORE_VULKAN_FUNCTIONS(macro)
Definition: Vulkan.hpp:32
#define LUG_INSTANCE_VULKAN_FUNCTIONS(macro)
Definition: Vulkan.hpp:59
#define LUG_EXPORTED_VULKAN_FUNCTIONS(macro)
Definition: Vulkan.hpp:29
#define LUG_UNLOAD_VULKAN_FUNCTIONS(name)
#define LUG_DEVICE_VULKAN_FUNCTIONS(macro)
Definition: Vulkan.hpp:80
bool loadInstanceFunctions(const Instance &instance)
Definition: Loader.cpp:52
bool loadDeviceFunctions(const Device &device)
Definition: Loader.cpp:69
Handle open(const char *name)
Definition: Library.inl:28
System::Library::Handle _handle
Definition: Loader.hpp:34
#define LUG_LOAD_VULKAN_FUNCTIONS(name)
void close(Handle handle)