forked from 3Shain/dxmt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwsi_platform_sdl2.cpp
More file actions
48 lines (36 loc) · 1.3 KB
/
Copy pathwsi_platform_sdl2.cpp
File metadata and controls
48 lines (36 loc) · 1.3 KB
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
#if defined(DXMT_WSI_SDL2)
#include "wsi_platform_sdl2.hpp"
#include "log/log.hpp"
#include "util_string.hpp"
#include <dlfcn.h>
#include <SDL2/SDL.h>
#include <mach-o/dyld.h>
namespace dxmt::wsi {
// this is messy, but dynamically linking on macos seems pretty finicky
SDL2Initializer::SDL2Initializer() {
// first, try to see if we already loaded the dylib in the process...
uint32_t image_count = _dyld_image_count();
for (uint32_t i = 0; i < image_count; i++) {
const char* image_name = _dyld_get_image_name(i);
if(strstr(image_name, "SDL2") != nullptr) {
libsdl = dlopen(image_name, RTLD_NOW | RTLD_LOCAL);
if (libsdl) {
Logger::trace(str::format("SDL2 WSI: Found SDL2 in loaded images: ", image_name));
break;
}
}
}
// if there's no sdl, the app might've statically linked against sdl, so we can try dlsym with RTLD_DEFAULT
#define SDL_PROC(ret, name, params) \
name = reinterpret_cast<pfn_##name>(dlsym((libsdl == nullptr ? RTLD_DEFAULT : libsdl), #name)); \
if (!name) { \
Logger::err(str::format("SDL2 WSI: Failed to get function named ", #name)); \
}
#include "wsi_platform_sdl2_funcs.h"
if (!SDL_GetClosestDisplayMode) {
ERR("SDL2 WSI: failed to get SDL function pointers.");
abort();
}
}
}
#endif // defined(DXMT_WSI_SDL2)