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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
#include "renderdoc.h"
#include "renderdoc_app.h"
#include "globalincs/pstypes.h"
#ifdef SCP_UNIX
#include <dlfcn.h>
#endif
namespace {
bool api_loaded = false;
RENDERDOC_API_1_1_1* api = nullptr;
pRENDERDOC_GetAPI load_getAPI() {
#ifdef SCP_UNIX
auto handle = dlopen("librenderdoc.so", RTLD_NOLOAD);
auto symbol = dlsym(handle, "RENDERDOC_GetAPI");
if (handle != nullptr) {
dlclose(handle);
}
return (pRENDERDOC_GetAPI)symbol;
#else
// Renderdoc API loading is not implemented for this platform yet!
return nullptr;
#endif
}
}
namespace renderdoc {
bool loadApi() {
if (api_loaded) {
return true;
}
auto getAPI = load_getAPI();
if (getAPI == nullptr) {
return false;
}
auto res = getAPI(eRENDERDOC_API_Version_1_1_1, reinterpret_cast<void**>(&api));
if (res != 1) {
return false;
}
api_loaded = true;
return true;
}
void triggerCapture() {
if (!api_loaded) {
// Do nothing if API is not available
return;
}
api->TriggerCapture();
}
void startCapture() {
if (api_loaded) {
api->StartFrameCapture(nullptr, nullptr);
}
}
bool isCapturing() {
if (api_loaded) {
return api->IsFrameCapturing() == 1;
}
return false;
}
void endCapture() {
if (api_loaded) {
api->EndFrameCapture(nullptr, nullptr);
}
}
}
|