From 7670c125c0362d749df3a7e0ca1760262328ca30 Mon Sep 17 00:00:00 2001 From: baldurk Date: Thu, 12 Jul 2018 13:48:29 +0100 Subject: [PATCH] Fix EGL order-of-operations on windows * On windows we can load libEGL which then loads opengl32.dll, so we ensure that opengl32.dll is loaded first at startup rather than have it appear last-minute in a recursive call. * Likewise, when using EGL we forcibly forget all GL function pointers and fetch them through eglGetProcAddress, rather than having a mix-and-match dispatch table. --- renderdoc/driver/gl/egl_hooks.cpp | 6 ++++++ renderdoc/driver/gl/wgl_hooks.cpp | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/renderdoc/driver/gl/egl_hooks.cpp b/renderdoc/driver/gl/egl_hooks.cpp index de037bdb5..0061cc2cf 100644 --- a/renderdoc/driver/gl/egl_hooks.cpp +++ b/renderdoc/driver/gl/egl_hooks.cpp @@ -535,6 +535,12 @@ static void EGLHooked(void *handle) EGL_NONHOOKED_SYMBOLS(EGL_FETCH) #undef EGL_FETCH +#if ENABLED(RDOC_WIN32) + // On windows we completely erase all GL function pointers. These might point into opengl32.dll + // which is not what we want to call when we're using a libEGL emulator + RDCEraseEl(GL); +#endif + // Now that libEGL is loaded, we can immediately fill out any missing functions that weren't // library hooked by calling eglGetProcAddress. GL.PopulateWithCallback([](const char *funcName) { diff --git a/renderdoc/driver/gl/wgl_hooks.cpp b/renderdoc/driver/gl/wgl_hooks.cpp index 1d5681f08..6d070816b 100644 --- a/renderdoc/driver/gl/wgl_hooks.cpp +++ b/renderdoc/driver/gl/wgl_hooks.cpp @@ -534,6 +534,11 @@ void WGLHook::RegisterHooks() { RDCLOG("Registering WGL hooks"); + // we load GL here to ensure that it is loaded by the time that we end hook registration and apply + // any callbacks. That ensures that it doesn't get loaded later e.g. while we're in the middle of + // loading libEGL, and break due to recursive calls. + LoadLibraryA("opengl32.dll"); + LibraryHooks::RegisterLibraryHook("opengl32.dll", &WGLHooked); LibraryHooks::RegisterLibraryHook("gdi32.dll", NULL); LibraryHooks::RegisterLibraryHook("user32.dll", NULL);