blob: 3adf7575e96a03f5d1433493dfce6d6e262fba21 (
plain)
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
|
#include "Entrypoint/Common.hpp"
#include "Entrypoint/DirectX11.hpp"
#include "Entrypoint/DirectX12.hpp"
#include "Entrypoint/Metal.hpp"
#include "Entrypoint/OpenGL2.hpp"
#include "Entrypoint/OpenGL3.hpp"
#include "Entrypoint/Vulkan.hpp"
#include <glad/glad.h>
#include <GLFW/glfw3.h>
#include <imgui.h>
#include <argparse/argparse.hpp>
#include <iostream>
#include <memory>
#include <string>
using namespace std::literals::string_literals;
int main(int argc, char* argv[]) {
argparse::ArgumentParser parser;
parser.add_argument("--rendering-backend")
.help("Which rendering backend to use. If equals 'default', the preferred API for each platform will be used")
.default_value("default"s);
try {
parser.parse_args(argc, argv);
} catch (const std::runtime_error& error) {
std::cout << error.what() << '\n';
std::cout << parser;
return -1;
}
std::unique_ptr<RenderingBackend> backend;
auto backendOption = parser.get<std::string>("--rendering-backend");
if (backendOption == "default") {
// TODO better api selection mechanism, use lower tier if higher tier is unavilable instead of bailing
#if PLATFORM_WIN32
# if IMGUI_INCLUDE_DX12_BACKEND
backend = std::make_unique<DirectX12Backend>();
# elif IMGUI_INCLUDE_DX11_BACKEND
backend = std::make_unique<DirectX11Backend>();
# elif IMGUI_INCLUDE_VULKAN_BACKEND
backend = std::make_unique<VulkanBackend>();
# elif IMGUI_INCLUDE_OPENGL3_BACKEND
backend = std::make_unique<OpenGL3Backend>();
# elif IMGUI_INCLUDE_OPENGL2_BACKEND
backend = std::make_unique<OpenGL2Backend>();
# endif
#elif PLATFORM_MACOS
backend = std::make_unique<MetalBackend>();
#elif PLATFORM_LINUX
# if IMGUI_INCLUDE_VULKAN_BACKEND
backend = std::make_unique<VulkanBackend>();
// # elif IMGUI_INCLUDE_OPENGL3_BACKEND
// backend = std::make_unique<OpenGL3Backend>();
# elif IMGUI_INCLUDE_OPENGL2_BACKEND
backend = std::make_unique<OpenGL2Backend>();
# endif
#endif
} else if (backendOption == "opengl2") {
backend = std::make_unique<OpenGL2Backend>();
} else if (backendOption == "opengl3") {
backend = std::make_unique<OpenGL3Backend>();
} else if (backendOption == "vulkan") {
backend = std::make_unique<VulkanBackend>();
} else if (backendOption == "dx11") {
backend = std::make_unique<DirectX11Backend>();
} else if (backendOption == "dx12") {
backend = std::make_unique<DirectX12Backend>();
} else if (backendOption == "metal") {
backend = std::make_unique<MetalBackend>();
} else {
std::cout << "Unknown backend '" << backendOption << "'.\n";
return -1;
}
auto& io = ImGui::GetIO();
io.Fonts->AddFontFromFileTTF("fonts/NotoSansSC-Regular.otf", 18, nullptr, io.Fonts->GetGlyphRangesChineseSimplifiedCommon());
auto window = backend->GetWindow();
bool showDemo = true;
while (!glfwWindowShouldClose(window)) {
backend->BeginFrame();
if (showDemo)
ImGui::ShowDemoWindow(&showDemo);
backend->EndFrame();
}
return 0;
}
|