111 lines
2.9 KiB
C++
111 lines
2.9 KiB
C++
|
|
#include <argparse/argparse.hpp>
|
|
#include <mijin/debug/stacktrace.hpp>
|
|
|
|
#include "./0_clear_swapchain/app.hpp"
|
|
#include "./1_green_triangle/app.hpp"
|
|
#include "./2_triangle_with_texcoords/app.hpp"
|
|
#include "./3_textured_quad/app.hpp"
|
|
#include "./4_textured_cube/app.hpp"
|
|
#include "./5_input/app.hpp"
|
|
#include "./6_ui/app.hpp"
|
|
#include "./7_3d_scene/app.hpp"
|
|
#include "./8_post_process/app.hpp"
|
|
#include "./util/spdlog_wrapper.hpp"
|
|
#include "8_post_process/app.hpp"
|
|
|
|
namespace
|
|
{
|
|
inline constexpr int APP_ERROR = 1;
|
|
inline constexpr int USER_ERROR = 2;
|
|
|
|
struct AppListEntry
|
|
{
|
|
std::string name;
|
|
std::function<std::unique_ptr<sdl_gpu_test::Application>()> factoryFn;
|
|
};
|
|
|
|
template<typename TApp>
|
|
AppListEntry makeAppHelper(std::string name) noexcept
|
|
{
|
|
return {
|
|
.name = std::move(name),
|
|
.factoryFn = []() { return std::make_unique<TApp>(); }
|
|
};
|
|
}
|
|
|
|
const std::array APPS = {
|
|
makeAppHelper<sdl_gpu_test::ClearSwapchainApp>("clear_swapchain"),
|
|
makeAppHelper<sdl_gpu_test::GreenTriangleApp>("green_triangle"),
|
|
makeAppHelper<sdl_gpu_test::TriangleWithTexcoordsApp>("triangle_with_texcoords"),
|
|
makeAppHelper<sdl_gpu_test::TexturedQuadApp>("textured_quad"),
|
|
makeAppHelper<sdl_gpu_test::TexturedCubeApp>("textured_cube"),
|
|
makeAppHelper<sdl_gpu_test::InputApp>("input"),
|
|
makeAppHelper<sdl_gpu_test::UIApp>("ui"),
|
|
makeAppHelper<sdl_gpu_test::ThreeDSceneApp>("3d_scene"),
|
|
makeAppHelper<sdl_gpu_test::PostProcessApp>("post_process")
|
|
};
|
|
}
|
|
|
|
int main(int argc, char* argv[])
|
|
{
|
|
if (argc < 1)
|
|
{
|
|
return APP_ERROR;
|
|
}
|
|
|
|
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMEPAD) != SDL_TRUE)
|
|
{
|
|
spdlog::error("Error initializing SDL.");
|
|
return APP_ERROR;
|
|
}
|
|
|
|
std::string appString = APPS.back().name;
|
|
argparse::ArgumentParser parser("sdl_gpu_test");
|
|
argparse::Argument& appArg = parser.add_argument("--app")
|
|
.help("Application to run")
|
|
.store_into(appString);
|
|
for (const AppListEntry& appHelper : APPS)
|
|
{
|
|
appArg.add_choice(appHelper.name);
|
|
}
|
|
|
|
// now parse
|
|
try
|
|
{
|
|
parser.parse_args(argc, argv);
|
|
}
|
|
catch (std::runtime_error& error)
|
|
{
|
|
spdlog::error("{}", error.what());
|
|
return USER_ERROR;
|
|
}
|
|
|
|
try
|
|
{
|
|
std::unique_ptr<sdl_gpu_test::Application> app;
|
|
for (const AppListEntry& appHelper : APPS)
|
|
{
|
|
if (appHelper.name == appString)
|
|
{
|
|
app = appHelper.factoryFn();
|
|
break;
|
|
}
|
|
}
|
|
MIJIN_ASSERT_FATAL(app != nullptr, "Error creating app.");
|
|
app->run(std::span(const_cast<const char**>(argv), argc));
|
|
}
|
|
catch (std::exception& exception)
|
|
{
|
|
spdlog::error("Exception while running application: {}", exception.what());
|
|
mijin::getExceptionStacktrace().then([](const mijin::Stacktrace& stacktrace)
|
|
{
|
|
spdlog::error("{}", stacktrace);
|
|
});
|
|
}
|
|
|
|
SDL_Quit();
|
|
|
|
return 0;
|
|
}
|