From f6048a074e80f3b9675ce6b5fbf7a3f4cafbd03b Mon Sep 17 00:00:00 2001 From: baldurk Date: Tue, 8 May 2018 14:56:04 +0100 Subject: [PATCH] Clarify how to use dlopen to open the library for in-application API use --- docs/in_application_api.rst | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/docs/in_application_api.rst b/docs/in_application_api.rst index 1b9011be4..b4fa3c812 100644 --- a/docs/in_application_api.rst +++ b/docs/in_application_api.rst @@ -11,7 +11,7 @@ To begin using the API you need to fetch the ``RENDERDOC_GetAPI`` function. You There are two common ways to integrate RenderDoc. The first is to passively check if the DLL is loaded, and use the API. This lets you continue to use RenderDoc entirely as normal, launching your program through the UI, but you can access additional functionality to e.g. trigger captures at custom times. -To do this you'll use your platforms dynamic library functions to see if the library is open already - e.g. ``GetModuleHandle`` on Windows, or ``dlopen`` with the ``RTLD_NOLOAD`` flag if available on \*nix systems. Just searching for the module name - ``renderdoc.dll`` or ``librenderdoc.so`` is sufficient here, so you don't need to know the path to where RenderDoc is running from. Then you can use ``GetProcAddress`` or ``dlsym`` to fetch the ``RENDERDOC_GetAPI`` function using the typedef above. +To do this you'll use your platforms dynamic library functions to see if the library is open already - e.g. ``GetModuleHandle`` on Windows, or ``dlopen`` with the ``RTLD_NOW | RTLD_NOLOAD`` flags if available on \*nix systems. Just searching for the module name - ``renderdoc.dll`` or ``librenderdoc.so`` is sufficient here, so you don't need to know the path to where RenderDoc is running from. Then you can use ``GetProcAddress`` or ``dlsym`` to fetch the ``RENDERDOC_GetAPI`` function using the typedef above. The other way is a closer integration, where your code will explicitly load RenderDoc's library at runtime. This needs more care taken as it can be a bit more complex. You will need to locate the RenderDoc module yourself, and load it as soon as possible after startup of your program. Due to the nature of RenderDoc's API hooking, the earlier you can load it the better in general. Once you've loaded it you can fetch the ``RENDERDOC_GetAPI`` entry point as above, and use the API as normal. @@ -39,6 +39,14 @@ The other way is a closer integration, where your code will explicitly load Rend assert(ret == 1); } + // At init, on linux + if(void *mod = dlopen("librenderdoc.so", RTLD_NOW | RTLD_NOLOAD)) + { + pRENDERDOC_GetAPI RENDERDOC_GetAPI = (pRENDERDOC_GetAPI)dlsym(mod, "RENDERDOC_GetAPI"); + int ret = RENDERDOC_GetAPI(eRENDERDOC_API_Version_1_1_2, (void **)&rdoc_api); + assert(ret == 1); + } + // When you wish to trigger the capture if(rdoc_api) rdoc_api->TriggerCapture();