From fd5612e30ae754c4bdab0e1af4ef1fa470b02067 Mon Sep 17 00:00:00 2001 From: baldurk Date: Thu, 12 Jul 2018 14:05:52 +0100 Subject: [PATCH] Change RENDERDOC_HOOK_EGL to a runtime option on an env var * Environment variables are not user-friendly, but I don't want to promote this to a capture option since it's so niche. * In future perhaps it will be feasible to support selecting an arbitrary API to capture, or even capturing multiple APIs simultaneously - though with GLES- on-GL that will be quite difficult. --- renderdoc/driver/gl/egl_hooks.cpp | 27 ++++++++++++++++++++------- renderdoc/driver/gl/gl_common.h | 6 +++--- renderdoc/driver/gl/gl_hooks.cpp | 13 ++++++++----- 3 files changed, 31 insertions(+), 15 deletions(-) diff --git a/renderdoc/driver/gl/egl_hooks.cpp b/renderdoc/driver/gl/egl_hooks.cpp index 0061cc2cf..4f3bc7af6 100644 --- a/renderdoc/driver/gl/egl_hooks.cpp +++ b/renderdoc/driver/gl/egl_hooks.cpp @@ -551,9 +551,28 @@ static void EGLHooked(void *handle) }); } +#if ENABLED(RDOC_WIN32) +bool ShouldHookEGL() +{ + const char *toggle = Process::GetEnvVariable("RENDERDOC_HOOK_EGL"); + + // if the var is set to 0, then don't hook EGL + if(toggle && toggle[0] == '0') + return false; + + return true; +} +#endif + void EGLHook::RegisterHooks() { -#if ENABLED(RENDERDOC_HOOK_EGL) +#if ENABLED(RDOC_WIN32) + if(!ShouldHookEGL()) + { + RDCLOG("EGL hooks disabled - if GLES emulator is in use, underlying API will be captured"); + return; + } +#endif RDCLOG("Registering EGL hooks"); @@ -591,10 +610,4 @@ void EGLHook::RegisterHooks() FunctionHook("egl" STRINGIZE(func), (void **)&EGL.func, (void *)&CONCAT(egl, func))); EGL_HOOKED_SYMBOLS(EGL_REGISTER) #undef EGL_REGISTER - -#else - - RDCLOG("EGL hooks disabled - if GLES emulator is in use, underlying API will be captured"); - -#endif } diff --git a/renderdoc/driver/gl/gl_common.h b/renderdoc/driver/gl/gl_common.h index efaa217a9..59cb0cb2d 100644 --- a/renderdoc/driver/gl/gl_common.h +++ b/renderdoc/driver/gl/gl_common.h @@ -49,9 +49,9 @@ DECLARE_REFLECTION_ENUM(RDCGLenum); #define RENDERDOC_SUPPORT_GL #define RENDERDOC_SUPPORT_GLES -// disable this option to disallow hooking EGL on windows. This means that the underlying GL or D3D -// calls will be captured instead. -#define RENDERDOC_HOOK_EGL OPTION_ON +// checks a runtime opt-out option to disallow hooking EGL on windows. This means that the +// underlying GL or D3D calls will be captured instead. +bool ShouldHookEGL(); #else diff --git a/renderdoc/driver/gl/gl_hooks.cpp b/renderdoc/driver/gl/gl_hooks.cpp index 97420de44..8fb8e855e 100644 --- a/renderdoc/driver/gl/gl_hooks.cpp +++ b/renderdoc/driver/gl/gl_hooks.cpp @@ -185,11 +185,14 @@ void GLHook::RegisterHooks() ForEachSupported(RegisterFunc); -#if ENABLED(RDOC_WIN32) && defined(RENDERDOC_SUPPORT_GLES) - // on windows where hooking is per-library, we also need to register these hooks for any GLES2/3 - // wrapper library, when GLES support is enabled. - libraryName = "libGLESv2.dll"; +#if ENABLED(RDOC_WIN32) + if(ShouldHookEGL()) + { + // on windows where hooking is per-library, we also need to register these hooks for any GLES2/3 + // wrapper library, when GLES support is enabled. + libraryName = "libGLESv2.dll"; - ForEachSupported(RegisterFunc); + ForEachSupported(RegisterFunc); + } #endif }