Blender V4.3
renderdoc_api.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#include "renderdoc_api.hh"
6
7#ifdef _WIN32
8# define WIN32_LEAN_AND_MEAN
9# include <Windows.h>
10#else
11# include <dlfcn.h>
12#endif
13#include <iostream>
14
15namespace renderdoc::api {
16bool Renderdoc::start_frame_capture(RENDERDOC_DevicePointer device_handle,
17 RENDERDOC_WindowHandle window_handle)
18{
19 if (!check_loaded()) {
20 return false;
21 }
22 renderdoc_api_->StartFrameCapture(device_handle, window_handle);
23 return true;
24}
25
26void Renderdoc::end_frame_capture(RENDERDOC_DevicePointer device_handle,
27 RENDERDOC_WindowHandle window_handle)
28
29{
30 if (!check_loaded()) {
31 return;
32 }
33 renderdoc_api_->EndFrameCapture(device_handle, window_handle);
34}
35
37{
38 if (!check_loaded()) {
39 return;
40 }
41 renderdoc_api_->SetCaptureTitle(title);
42}
43
44bool Renderdoc::check_loaded()
45{
46 switch (state_) {
47 case State::UNINITIALIZED:
48 load();
49 return renderdoc_api_ != nullptr;
50 break;
51 case State::NOT_FOUND:
52 return false;
53 case State::LOADED:
54 return true;
55 }
56 return false;
57}
58
59void Renderdoc::load()
60{
61#ifdef _WIN32
62 if (HMODULE mod = GetModuleHandleA("renderdoc.dll")) {
63 pRENDERDOC_GetAPI RENDERDOC_GetAPI = (pRENDERDOC_GetAPI)GetProcAddress(mod,
64 "RENDERDOC_GetAPI");
65 RENDERDOC_GetAPI(eRENDERDOC_API_Version_1_1_2, (void **)&renderdoc_api_);
66 }
67#else
68 if (void *mod = dlopen("librenderdoc.so", RTLD_NOW | RTLD_NOLOAD)) {
69 pRENDERDOC_GetAPI RENDERDOC_GetAPI = (pRENDERDOC_GetAPI)dlsym(mod, "RENDERDOC_GetAPI");
70 RENDERDOC_GetAPI(eRENDERDOC_API_Version_1_1_2, (void **)&renderdoc_api_);
71 }
72#endif
73}
74
75} // namespace renderdoc::api
void set_frame_capture_title(const char *capture_title)
void end_frame_capture(RENDERDOC_DevicePointer device_handle, RENDERDOC_WindowHandle window_handle)
bool start_frame_capture(RENDERDOC_DevicePointer device_handle, RENDERDOC_WindowHandle window_handle)
ccl_device_inline int mod(int x, int m)
Definition util/math.h:520