summaryrefslogtreecommitdiffstats
path: root/video/out/opengl/angle_dynamic.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2016-05-11 12:33:49 +0200
committerwm4 <wm4@nowhere>2016-05-11 15:39:29 +0200
commitfde20d10bcacebf61aff42ab1f48ac72023a2aa5 (patch)
tree32208ac416db568fa7286f83a69b7c225df05f04 /video/out/opengl/angle_dynamic.c
parentbea76753078c2602c2fc67dc06ce13141560cf0d (diff)
downloadmpv-fde20d10bcacebf61aff42ab1f48ac72023a2aa5.tar.bz2
mpv-fde20d10bcacebf61aff42ab1f48ac72023a2aa5.tar.xz
vo_opengl: angle: dynamically load ANGLE
ANGLE is _really_ annoying to build. (Requires special toolchain and a recent MSVC version.) This results in various issues with people having trouble to build mpv against ANGLE (apparently linking it against a prebuilt binary doesn't count, or using binaries from potentially untrusted sources is not wanted). Dynamically loading ANGLE is going to be a huge convenience. This commit implements this, with special focus on keeping it source compatible to a normal build with ANGLE linked at build-time.
Diffstat (limited to 'video/out/opengl/angle_dynamic.c')
-rw-r--r--video/out/opengl/angle_dynamic.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/video/out/opengl/angle_dynamic.c b/video/out/opengl/angle_dynamic.c
new file mode 100644
index 0000000000..f4540c473a
--- /dev/null
+++ b/video/out/opengl/angle_dynamic.c
@@ -0,0 +1,33 @@
+#include <pthread.h>
+#include <windows.h>
+
+#define ANGLE_NO_ALIASES
+#include "angle_dynamic.h"
+
+#include "common/common.h"
+
+#define ANGLE_DECL(NAME, VAR) \
+ VAR;
+ANGLE_FNS(ANGLE_DECL)
+
+static bool angle_loaded;
+static pthread_once_t angle_load_once = PTHREAD_ONCE_INIT;
+
+static void angle_do_load(void)
+{
+ // Note: we let this handle "leak", as the functions remain valid forever.
+ HANDLE angle_dll = LoadLibraryW(L"LIBEGL.DLL");
+ if (!angle_dll)
+ return;
+#define ANGLE_LOAD_ENTRY(NAME, VAR) \
+ MP_CONCAT(PFN_, NAME) = (void *)GetProcAddress(angle_dll, #NAME); \
+ if (!MP_CONCAT(PFN_, NAME)) return;
+ ANGLE_FNS(ANGLE_LOAD_ENTRY)
+ angle_loaded = true;
+}
+
+bool angle_load(void)
+{
+ pthread_once(&angle_load_once, angle_do_load);
+ return angle_loaded;
+}