Added argument for selecting the app to run.
This commit is contained in:
parent
b552a09885
commit
f364998933
@ -23,6 +23,7 @@ prog_app = env.UnityProgram(
|
|||||||
target = env['BIN_DIR'] + '/sdl_gpu_test',
|
target = env['BIN_DIR'] + '/sdl_gpu_test',
|
||||||
source = src_files,
|
source = src_files,
|
||||||
dependencies = {
|
dependencies = {
|
||||||
|
'argparse': {},
|
||||||
'glm': {},
|
'glm': {},
|
||||||
'mijin': {},
|
'mijin': {},
|
||||||
'SDL': {
|
'SDL': {
|
||||||
|
@ -1,35 +1,89 @@
|
|||||||
|
|
||||||
|
#include <argparse/argparse.hpp>
|
||||||
|
#include <mijin/debug/stacktrace.hpp>
|
||||||
|
|
||||||
#include "./0_clear_swapchain/app.hpp"
|
#include "./0_clear_swapchain/app.hpp"
|
||||||
#include "./1_green_triangle/app.hpp"
|
#include "./1_green_triangle/app.hpp"
|
||||||
#include "./2_triangle_with_texcoords/app.hpp"
|
#include "./2_triangle_with_texcoords/app.hpp"
|
||||||
#include "./3_textured_quad/app.hpp"
|
#include "./3_textured_quad/app.hpp"
|
||||||
#include "./4_textured_cube/app.hpp"
|
#include "./4_textured_cube/app.hpp"
|
||||||
|
#include "./util/spdlog_wrapper.hpp"
|
||||||
|
|
||||||
#include <mijin/debug/stacktrace.hpp>
|
namespace
|
||||||
#include <spdlog/spdlog.h>
|
{
|
||||||
#include <mijin/util/winundef.hpp>
|
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")
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
if (argc < 1)
|
if (argc < 1)
|
||||||
{
|
{
|
||||||
return 1;
|
return APP_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SDL_Init(0) != SDL_TRUE)
|
if (SDL_Init(0) != SDL_TRUE)
|
||||||
{
|
{
|
||||||
spdlog::error("Error initializing SDL.");
|
spdlog::error("Error initializing SDL.");
|
||||||
return 1;
|
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
|
try
|
||||||
{
|
{
|
||||||
// make sure app is destructed before shutting down SDL
|
std::unique_ptr<sdl_gpu_test::Application> app;
|
||||||
// std::unique_ptr<sdl_gpu_test::Application> app = std::make_unique<sdl_gpu_test::ClearSwapchainApp>();
|
for (const AppListEntry& appHelper : APPS)
|
||||||
// std::unique_ptr<sdl_gpu_test::Application> app = std::make_unique<sdl_gpu_test::GreenTriangleApp>();
|
{
|
||||||
// std::unique_ptr<sdl_gpu_test::Application> app = std::make_unique<sdl_gpu_test::TriangleWithTexcoordsApp>();
|
if (appHelper.name == appString)
|
||||||
// std::unique_ptr<sdl_gpu_test::Application> app = std::make_unique<sdl_gpu_test::TexturedQuadApp>();
|
{
|
||||||
std::unique_ptr<sdl_gpu_test::Application> app = std::make_unique<sdl_gpu_test::TexturedCubeApp>();
|
app = appHelper.factoryFn();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
MIJIN_ASSERT_FATAL(app != nullptr, "Error creating app.");
|
||||||
app->run(std::span(const_cast<const char**>(argv), argc));
|
app->run(std::span(const_cast<const char**>(argv), argc));
|
||||||
}
|
}
|
||||||
catch (std::exception& exception)
|
catch (std::exception& exception)
|
||||||
|
11
private/sdl_gpu_test/util/spdlog_wrapper.hpp
Normal file
11
private/sdl_gpu_test/util/spdlog_wrapper.hpp
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#if !defined(SDL_GPU_TEST_PRIVATE_SDL_GPU_TEST_UTIL_SPDLOG_WRAPPER_HPP_INCLUDED)
|
||||||
|
#define SDL_GPU_TEST_PRIVATE_SDL_GPU_TEST_UTIL_SPDLOG_WRAPPER_HPP_INCLUDED 1
|
||||||
|
|
||||||
|
// spdlog includes windows.h ...
|
||||||
|
#include <spdlog/spdlog.h>
|
||||||
|
#include <mijin/util/winundef.hpp>
|
||||||
|
|
||||||
|
#endif // !defined(SDL_GPU_TEST_PRIVATE_SDL_GPU_TEST_UTIL_SPDLOG_WRAPPER_HPP_INCLUDED)
|
Loading…
x
Reference in New Issue
Block a user