#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 #include #include #include #include #include #include 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 backend; auto backendOption = parser.get("--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(); # elif IMGUI_INCLUDE_DX11_BACKEND backend = std::make_unique(); # elif IMGUI_INCLUDE_VULKAN_BACKEND backend = std::make_unique(); # elif IMGUI_INCLUDE_OPENGL3_BACKEND backend = std::make_unique(); # elif IMGUI_INCLUDE_OPENGL2_BACKEND backend = std::make_unique(); # endif #elif PLATFORM_MACOS backend = std::make_unique(); #elif PLATFORM_LINUX # if IMGUI_INCLUDE_VULKAN_BACKEND backend = std::make_unique(); // # elif IMGUI_INCLUDE_OPENGL3_BACKEND // backend = std::make_unique(); # elif IMGUI_INCLUDE_OPENGL2_BACKEND backend = std::make_unique(); # endif #endif } else if (backendOption == "opengl2") { backend = std::make_unique(); } else if (backendOption == "opengl3") { backend = std::make_unique(); } else if (backendOption == "vulkan") { backend = std::make_unique(); } else if (backendOption == "dx11") { backend = std::make_unique(); } else if (backendOption == "dx12") { backend = std::make_unique(); } else if (backendOption == "metal") { backend = std::make_unique(); } 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; }