-
Notifications
You must be signed in to change notification settings - Fork 260
/
Copy pathgraphicsplugin_factory.cpp
102 lines (93 loc) · 4.58 KB
/
graphicsplugin_factory.cpp
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
97
98
99
100
101
102
// Copyright (c) 2017-2024, The Khronos Group Inc.
//
// SPDX-License-Identifier: Apache-2.0
#include <utility>
#include "pch.h"
#include "common.h"
#include "options.h"
#include "platformdata.h"
#include "graphicsplugin.h"
// Graphics API factories are forward declared here.
#ifdef XR_USE_GRAPHICS_API_OPENGL_ES
std::shared_ptr<IGraphicsPlugin> CreateGraphicsPlugin_OpenGLES(const std::shared_ptr<Options>& options,
std::shared_ptr<IPlatformPlugin> platformPlugin);
#endif
#ifdef XR_USE_GRAPHICS_API_OPENGL
std::shared_ptr<IGraphicsPlugin> CreateGraphicsPlugin_OpenGL(const std::shared_ptr<Options>& options,
std::shared_ptr<IPlatformPlugin> platformPlugin);
#endif
#ifdef XR_USE_GRAPHICS_API_VULKAN
std::shared_ptr<IGraphicsPlugin> CreateGraphicsPlugin_VulkanLegacy(const std::shared_ptr<Options>& options,
std::shared_ptr<IPlatformPlugin> platformPlugin);
std::shared_ptr<IGraphicsPlugin> CreateGraphicsPlugin_Vulkan(const std::shared_ptr<Options>& options,
std::shared_ptr<IPlatformPlugin> platformPlugin);
#endif
#ifdef XR_USE_GRAPHICS_API_D3D11
std::shared_ptr<IGraphicsPlugin> CreateGraphicsPlugin_D3D11(const std::shared_ptr<Options>& options,
std::shared_ptr<IPlatformPlugin> platformPlugin);
#endif
#ifdef XR_USE_GRAPHICS_API_D3D12
std::shared_ptr<IGraphicsPlugin> CreateGraphicsPlugin_D3D12(const std::shared_ptr<Options>& options,
std::shared_ptr<IPlatformPlugin> platformPlugin);
#endif
#ifdef XR_USE_GRAPHICS_API_METAL
std::shared_ptr<IGraphicsPlugin> CreateGraphicsPlugin_Metal(const std::shared_ptr<Options>& options,
std::shared_ptr<IPlatformPlugin> platformPlugin);
#endif
namespace {
using GraphicsPluginFactory = std::function<std::shared_ptr<IGraphicsPlugin>(const std::shared_ptr<Options>& options,
std::shared_ptr<IPlatformPlugin> platformPlugin)>;
std::map<std::string, GraphicsPluginFactory, IgnoreCaseStringLess> graphicsPluginMap = {
#ifdef XR_USE_GRAPHICS_API_OPENGL_ES
{"OpenGLES",
[](const std::shared_ptr<Options>& options, std::shared_ptr<IPlatformPlugin> platformPlugin) {
return CreateGraphicsPlugin_OpenGLES(options, std::move(platformPlugin));
}},
#endif
#ifdef XR_USE_GRAPHICS_API_OPENGL
{"OpenGL",
[](const std::shared_ptr<Options>& options, std::shared_ptr<IPlatformPlugin> platformPlugin) {
return CreateGraphicsPlugin_OpenGL(options, std::move(platformPlugin));
}},
#endif
#ifdef XR_USE_GRAPHICS_API_VULKAN
{"Vulkan",
[](const std::shared_ptr<Options>& options, std::shared_ptr<IPlatformPlugin> platformPlugin) {
return CreateGraphicsPlugin_VulkanLegacy(options, std::move(platformPlugin));
}},
{"Vulkan2",
[](const std::shared_ptr<Options>& options, std::shared_ptr<IPlatformPlugin> platformPlugin) {
return CreateGraphicsPlugin_Vulkan(options, std::move(platformPlugin));
}},
#endif
#ifdef XR_USE_GRAPHICS_API_D3D11
{"D3D11",
[](const std::shared_ptr<Options>& options, std::shared_ptr<IPlatformPlugin> platformPlugin) {
return CreateGraphicsPlugin_D3D11(options, std::move(platformPlugin));
}},
#endif
#ifdef XR_USE_GRAPHICS_API_D3D12
{"D3D12",
[](const std::shared_ptr<Options>& options, std::shared_ptr<IPlatformPlugin> platformPlugin) {
return CreateGraphicsPlugin_D3D12(options, std::move(platformPlugin));
}},
#endif
#ifdef XR_USE_GRAPHICS_API_METAL
{"Metal",
[](const std::shared_ptr<Options>& options, std::shared_ptr<IPlatformPlugin> platformPlugin) {
return CreateGraphicsPlugin_Metal(options, std::move(platformPlugin));
}},
#endif
};
} // namespace
std::shared_ptr<IGraphicsPlugin> CreateGraphicsPlugin(const std::shared_ptr<Options>& options,
std::shared_ptr<IPlatformPlugin> platformPlugin) {
if (options->GraphicsPlugin.empty()) {
throw std::invalid_argument("No graphics API specified");
}
const auto apiIt = graphicsPluginMap.find(options->GraphicsPlugin);
if (apiIt == graphicsPluginMap.end()) {
throw std::invalid_argument(Fmt("Unsupported graphics API '%s'", options->GraphicsPlugin.c_str()));
}
return apiIt->second(options, std::move(platformPlugin));
}