HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
render_doc.hpp
1// Copyright Take Vos 2020.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
5#pragma once
6
8
9#include "renderdoc_app.h"
10#include "../telemetry/telemetry.hpp"
11#include "../macros.hpp"
12#include <type_traits>
13#include <filesystem>
14
15namespace hi { inline namespace v1 {
16
17inline void *render_doc_api = nullptr;
18
19inline void render_doc_set_overlay(bool frameRate, bool frameNumber, bool captureList) noexcept
20{
21 if (not render_doc_api) {
22 return;
23 }
24
25 uint32_t or_mask = eRENDERDOC_Overlay_None;
26 uint32_t and_mask = eRENDERDOC_Overlay_None;
27
29 or_mask |= eRENDERDOC_Overlay_Enabled;
30 } else {
31 and_mask |= eRENDERDOC_Overlay_Enabled;
32 }
33
34 if (frameRate) {
35 or_mask |= eRENDERDOC_Overlay_FrameRate;
36 } else {
37 and_mask |= eRENDERDOC_Overlay_FrameRate;
38 }
39
40 if (frameNumber) {
41 or_mask |= eRENDERDOC_Overlay_FrameNumber;
42 } else {
43 and_mask |= eRENDERDOC_Overlay_FrameNumber;
44 }
45
46 if (captureList) {
47 or_mask |= eRENDERDOC_Overlay_CaptureList;
48 } else {
49 and_mask |= eRENDERDOC_Overlay_CaptureList;
50 }
51
52 auto& api_ = *static_cast<RENDERDOC_API_1_4_1 *>(render_doc_api);
53
55 api_.MaskOverlayBits(and_mask, or_mask);
56}
57
58inline void start_render_doc() noexcept
59{
60#ifndef NDEBUG
61#if HI_OPERATING_SYSTEM == HI_OS_WINDOWS
62 hilet dll_urls = std::vector{
63 std::filesystem::path{"renderdoc.dll"},
64 std::filesystem::path{"C:/Program Files/RenderDoc/renderdoc.dll"},
65 std::filesystem::path{"C:/Program Files (x86)/RenderDoc/renderdoc.dll"}};
66
67 auto mod = [&]() -> HMODULE {
68 for (hilet& dll_url : dll_urls) {
69 hi_log_debug("Trying to load: {}", dll_url.string());
70
71 if (auto mod = LoadLibraryW(dll_url.native().c_str())) {
72 return mod;
73 }
74 }
75 return nullptr;
76 }();
77
78 if (mod == nullptr) {
79 hi_log_warning("Could not load renderdoc.dll");
80 return;
81 }
82
83 auto RENDERDOC_GetAPI = (pRENDERDOC_GetAPI)GetProcAddress(mod, "RENDERDOC_GetAPI");
84 if (RENDERDOC_GetAPI == nullptr) {
85 hi_log_error("Could not find RENDERDOC_GetAPI in renderdoc.dll");
86 return;
87 }
88
89 int ret = RENDERDOC_GetAPI(eRENDERDOC_API_Version_1_4_1, &render_doc_api);
90 if (ret != 1) {
91 hi_log_error("RENDERDOC_GetAPI returns invalid value {}", ret);
92 render_doc_api = nullptr;
93 }
94
95 // At init, on linux/android.
96 // For android replace librenderdoc.so with libVkLayer_GLES_RenderDoc.so
97 // if(void *mod = dlopen("librenderdoc.so", RTLD_NOW | RTLD_NOLOAD))
98 //{
99 // pRENDERDOC_GetAPI RENDERDOC_GetAPI = (pRENDERDOC_GetAPI)dlsym(mod, "RENDERDOC_GetAPI");
100 // int ret = RENDERDOC_GetAPI(eRENDERDOC_API_Version_1_1_2, (void **)&rdoc_api);
101 // assert(ret == 1);
102 //}
103
104 render_doc_set_overlay(false, false, false);
105#endif
106#endif
107}
108
109
110}} // namespace hi::inline v1
Rules for working with win32 headers.
DOXYGEN BUG.
Definition algorithm.hpp:16
geometry/margins.hpp
Definition lookahead_iterator.hpp:5
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:377
Definition renderdoc_app.h:579