Repository navigation
Expand file tree
/
Copy pathDekiRenderPassRegistry.cpp
More file actions
96 lines (80 loc) · 2.01 KB
/
Copy pathDekiRenderPassRegistry.cpp
File metadata and controls
96 lines (80 loc) · 2.01 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
#include "DekiRenderPassRegistry.h"
#include <unordered_map>
#include <string>
namespace DekiRendering
{
// From DekiRenderingInit.h, declared here so this registry does not include
// the init header.
void DekiRenderingDetachPass(const char* name);
namespace DekiRenderPassRegistry
{
static std::unordered_map<std::string, RenderPassInfo>& GetRegistry()
{
static std::unordered_map<std::string, RenderPassInfo> s_Reg;
return s_Reg;
}
static AutoAttachCallback& GetAutoAttachCallback()
{
static AutoAttachCallback s_Cb;
return s_Cb;
}
void Register(const char* name, RenderPassInfo info)
{
if (!name || !info.factory)
{
return;
}
GetRegistry()[name] = info;
// Attach passes of packages that load after DekiRenderingInitSystem's
// scan. DekiRenderingInitSystem installs the callback.
if (info.autoAttach)
{
auto& cb = GetAutoAttachCallback();
if (cb)
{
cb(name, info);
}
}
}
const RenderPassInfo* Get(const char* name)
{
if (!name || name[0] == '\0')
{
return nullptr;
}
auto& reg = GetRegistry();
auto it = reg.find(name);
if (it != reg.end())
{
return &it->second;
}
return nullptr;
}
void Unregister(const char* name)
{
if (!name)
{
return;
}
// Destroy the live pass before removing the factory. Its vtable lives in
// the caller's DLL, which is usually about to unload (the static
// destructor calling this runs during DLL detach); otherwise
// deki-rendering's later shutdown would delete the pass through a freed
// vtable.
DekiRenderingDetachPass(name);
GetRegistry().erase(name);
}
void GetAllNames(std::vector<std::string>& outNames)
{
outNames.clear();
for (const auto& [name, info] : GetRegistry())
{
outNames.push_back(name);
}
}
void SetAutoAttachCallback(AutoAttachCallback cb)
{
GetAutoAttachCallback() = std::move(cb);
}
} // namespace DekiRenderPassRegistry
} // namespace DekiRendering