diff options
Diffstat (limited to 'core/src/Entrypoint/main.cpp')
-rw-r--r-- | core/src/Entrypoint/main.cpp | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/core/src/Entrypoint/main.cpp b/core/src/Entrypoint/main.cpp new file mode 100644 index 0000000..3adf757 --- /dev/null +++ b/core/src/Entrypoint/main.cpp @@ -0,0 +1,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; +} |