diff --git a/samples/hellomorphing.cpp b/samples/hellomorphing.cpp index b5886d3b7b..af5124bf4b 100644 --- a/samples/hellomorphing.cpp +++ b/samples/hellomorphing.cpp @@ -27,17 +27,22 @@ #include #include +#include + +#include #include #include #include +#include #include "generated/resources/resources.h" using namespace filament; using utils::Entity; using utils::EntityManager; +using utils::Path; using namespace filament::math; struct App { @@ -83,10 +88,65 @@ static const short4 targets_tan[9] = { static constexpr uint16_t TRIANGLE_INDICES[3] = { 0, 1, 2 }; +static void printUsage(char* name) { + std::string exec_name(Path(name).getName()); + std::string usage( + "SAMPLE is a command-line tool for testing Filament skinning buffers.\n" + "Usage:\n" + " SAMPLE [options]\n" + "Options:\n" + " --help, -h\n" + " Prints this message\n\n" + " --api, -a\n" + " Specify the backend API: opengl (default), vulkan, or metal\n\n" + ); + const std::string from("SAMPLE"); + for (size_t pos = usage.find(from); pos != std::string::npos; pos = usage.find(from, pos)) { + usage.replace(pos, from.length(), exec_name); + } + std::cout << usage; +} + +static int handleCommandLineArgments(int argc, char* argv[], Config* config) { + static constexpr const char* OPTSTR = "ha:"; + static const struct option OPTIONS[] = { + { "help", no_argument, nullptr, 'h' }, + { "api", required_argument, nullptr, 'a' }, + { nullptr, 0, nullptr, 0 } // termination of the option list + }; + int opt; + int option_index = 0; + while ((opt = getopt_long(argc, argv, OPTSTR, OPTIONS, &option_index)) >= 0) { + std::string arg(optarg != nullptr ? optarg : ""); + switch (opt) { + default: + case 'h': + printUsage(argv[0]); + exit(0); + case 'a': + if (arg == "opengl") { + config->backend = Engine::Backend::OPENGL; + } else if (arg == "vulkan") { + config->backend = Engine::Backend::VULKAN; + } else if (arg == "metal") { + config->backend = Engine::Backend::METAL; + } else { + std::cerr << "Unrecognized backend. Must be 'opengl'|'vulkan'|'metal'." + << std::endl; + } + break; + } + } + + return optind; +} + int main(int argc, char** argv) { Config config; config.title = "helloMorphing"; + handleCommandLineArgments(argc, argv, &config); + App app; auto setup = [&app](Engine* engine, View* view, Scene* scene) { app.skybox = Skybox::Builder().color({0.1, 0.125, 0.25, 1.0}).build(*engine); diff --git a/samples/helloskinning.cpp b/samples/helloskinning.cpp index d15f78ba1f..f3d50464a0 100644 --- a/samples/helloskinning.cpp +++ b/samples/helloskinning.cpp @@ -27,17 +27,22 @@ #include #include +#include #include #include #include +#include + +#include #include "generated/resources/resources.h" using namespace filament; using utils::Entity; using utils::EntityManager; +using utils::Path; using namespace filament::math; struct App { @@ -58,6 +63,60 @@ struct VertexWithBones { filament::math::float4 weighs; }; +static void printUsage(char* name) { + std::string exec_name(Path(name).getName()); + std::string usage( + "SAMPLE is a command-line tool for testing Filament skinning.\n" + "Usage:\n" + " SAMPLE [options]\n" + "Options:\n" + " --help, -h\n" + " Prints this message\n\n" + " --api, -a\n" + " Specify the backend API: opengl (default), vulkan, or metal\n\n" + ); + const std::string from("SAMPLE"); + for (size_t pos = usage.find(from); pos != std::string::npos; pos = usage.find(from, pos)) { + usage.replace(pos, from.length(), exec_name); + } + std::cout << usage; +} + +static int handleCommandLineArgments(int argc, char* argv[], Config* config) { + static constexpr const char* OPTSTR = "ha:"; + static const struct option OPTIONS[] = { + { "help", no_argument, nullptr, 'h' }, + { "api", required_argument, nullptr, 'a' }, + { nullptr, 0, nullptr, 0 } // termination of the option list + }; + int opt; + int option_index = 0; + while ((opt = getopt_long(argc, argv, OPTSTR, OPTIONS, &option_index)) >= 0) { + std::string arg(optarg != nullptr ? optarg : ""); + switch (opt) { + default: + case 'h': + printUsage(argv[0]); + exit(0); + case 'a': + if (arg == "opengl") { + config->backend = Engine::Backend::OPENGL; + } else if (arg == "vulkan") { + config->backend = Engine::Backend::VULKAN; + } else if (arg == "metal") { + config->backend = Engine::Backend::METAL; + } else { + std::cerr << "Unrecognized backend. Must be 'opengl'|'vulkan'|'metal'." + << std::endl; + } + break; + } + } + + return optind; +} + + static const VertexWithBones TRIANGLE_VERTICES_WITHBONES[6] = { {{1, 0}, 0xffff0000u, {0,1,0,0}, {1.0f,0.f,0.f,0.f}}, {{cos(M_PI * 2 / 3), sin(M_PI * 2 / 3)}, 0xff00ff00u, {0,1,0,0}, {0.f,1.f,0.f,0.f}}, @@ -78,6 +137,8 @@ int main(int argc, char** argv) { Config config; config.title = "hello skinning"; + handleCommandLineArgments(argc, argv, &config); + App app; auto setup = [&app](Engine* engine, View* view, Scene* scene) { app.skybox = Skybox::Builder().color({0.1, 0.125, 0.25, 1.0}).build(*engine); diff --git a/samples/helloskinningbuffer.cpp b/samples/helloskinningbuffer.cpp index c69f962855..175c62c81a 100644 --- a/samples/helloskinningbuffer.cpp +++ b/samples/helloskinningbuffer.cpp @@ -27,17 +27,22 @@ #include #include +#include + +#include #include #include #include +#include #include "generated/resources/resources.h" using namespace filament; using utils::Entity; using utils::EntityManager; +using utils::Path; using namespace filament::math; struct App { @@ -85,10 +90,65 @@ mat4f transforms[] = {math::mat4f(1.f), mat4f::translation(float3(0, -1, 0)), mat4f::translation(float3(1, -1, 0))}; +static void printUsage(char* name) { + std::string exec_name(Path(name).getName()); + std::string usage( + "SAMPLE is a command-line tool for testing Filament skinning buffers.\n" + "Usage:\n" + " SAMPLE [options]\n" + "Options:\n" + " --help, -h\n" + " Prints this message\n\n" + " --api, -a\n" + " Specify the backend API: opengl (default), vulkan, or metal\n\n" + ); + const std::string from("SAMPLE"); + for (size_t pos = usage.find(from); pos != std::string::npos; pos = usage.find(from, pos)) { + usage.replace(pos, from.length(), exec_name); + } + std::cout << usage; +} + +static int handleCommandLineArgments(int argc, char* argv[], Config* config) { + static constexpr const char* OPTSTR = "ha:"; + static const struct option OPTIONS[] = { + { "help", no_argument, nullptr, 'h' }, + { "api", required_argument, nullptr, 'a' }, + { nullptr, 0, nullptr, 0 } // termination of the option list + }; + int opt; + int option_index = 0; + while ((opt = getopt_long(argc, argv, OPTSTR, OPTIONS, &option_index)) >= 0) { + std::string arg(optarg != nullptr ? optarg : ""); + switch (opt) { + default: + case 'h': + printUsage(argv[0]); + exit(0); + case 'a': + if (arg == "opengl") { + config->backend = Engine::Backend::OPENGL; + } else if (arg == "vulkan") { + config->backend = Engine::Backend::VULKAN; + } else if (arg == "metal") { + config->backend = Engine::Backend::METAL; + } else { + std::cerr << "Unrecognized backend. Must be 'opengl'|'vulkan'|'metal'." + << std::endl; + } + break; + } + } + + return optind; +} + int main(int argc, char** argv) { Config config; config.title = "skinning buffer common for two renderables"; + handleCommandLineArgments(argc, argv, &config); + App app; auto setup = [&app](Engine* engine, View* view, Scene* scene) { app.skybox = Skybox::Builder().color({0.1, 0.125, 0.25, 1.0}).build(*engine); diff --git a/samples/helloskinningbuffer_morebones.cpp b/samples/helloskinningbuffer_morebones.cpp index 48fe174e15..184d799b7f 100644 --- a/samples/helloskinningbuffer_morebones.cpp +++ b/samples/helloskinningbuffer_morebones.cpp @@ -27,17 +27,22 @@ #include #include +#include + +#include #include #include #include +#include #include "generated/resources/resources.h" using namespace filament; using utils::Entity; using utils::EntityManager; +using utils::Path; using namespace filament::math; struct App { @@ -77,9 +82,65 @@ mat4f transforms[] = {math::mat4f(1.f), utils::FixedCapacityVector> boneDataPerPrimitive(3); +static void printUsage(char* name) { + std::string exec_name(Path(name).getName()); + std::string usage( + "SAMPLE is a command-line tool for testing Filament skinning buffers.\n" + "Usage:\n" + " SAMPLE [options]\n" + "Options:\n" + " --help, -h\n" + " Prints this message\n\n" + " --api, -a\n" + " Specify the backend API: opengl (default), vulkan, or metal\n\n" + ); + const std::string from("SAMPLE"); + for (size_t pos = usage.find(from); pos != std::string::npos; pos = usage.find(from, pos)) { + usage.replace(pos, from.length(), exec_name); + } + std::cout << usage; +} + +static int handleCommandLineArgments(int argc, char* argv[], Config* config) { + static constexpr const char* OPTSTR = "ha:"; + static const struct option OPTIONS[] = { + { "help", no_argument, nullptr, 'h' }, + { "api", required_argument, nullptr, 'a' }, + { nullptr, 0, nullptr, 0 } // termination of the option list + }; + int opt; + int option_index = 0; + while ((opt = getopt_long(argc, argv, OPTSTR, OPTIONS, &option_index)) >= 0) { + std::string arg(optarg != nullptr ? optarg : ""); + switch (opt) { + default: + case 'h': + printUsage(argv[0]); + exit(0); + case 'a': + if (arg == "opengl") { + config->backend = Engine::Backend::OPENGL; + } else if (arg == "vulkan") { + config->backend = Engine::Backend::VULKAN; + } else if (arg == "metal") { + config->backend = Engine::Backend::METAL; + } else { + std::cerr << "Unrecognized backend. Must be 'opengl'|'vulkan'|'metal'." + << std::endl; + } + break; + } + } + + return optind; +} + int main(int argc, char** argv) { Config config; config.title = "skinning buffer common for two renderables"; + + handleCommandLineArgments(argc, argv, &config); + size_t boneCount = 9; utils::FixedCapacityVector boneDataPerVertex(9); float weight = 1.f / boneCount; diff --git a/samples/skinningtest.cpp b/samples/skinningtest.cpp index 7d148a14ae..8ae6d3f966 100644 --- a/samples/skinningtest.cpp +++ b/samples/skinningtest.cpp @@ -28,17 +28,22 @@ #include #include +#include + +#include #include #include #include +#include #include "generated/resources/resources.h" using namespace filament; using utils::Entity; using utils::EntityManager; +using utils::Path; using utils::FixedCapacityVector; using namespace filament::math; @@ -128,6 +133,60 @@ mat4f transforms[] = {math::mat4f(1), mat4f::translation(float3(0, -1, 0)), mat4f::translation(float3(1, -1, 0))}; + +static void printUsage(char* name) { + std::string exec_name(Path(name).getName()); + std::string usage( + "SAMPLE is a command-line tool for testing Filament skinning buffers.\n" + "Usage:\n" + " SAMPLE [options]\n" + "Options:\n" + " --help, -h\n" + " Prints this message\n\n" + " --api, -a\n" + " Specify the backend API: opengl (default), vulkan, or metal\n\n" + ); + const std::string from("SAMPLE"); + for (size_t pos = usage.find(from); pos != std::string::npos; pos = usage.find(from, pos)) { + usage.replace(pos, from.length(), exec_name); + } + std::cout << usage; +} + +static int handleCommandLineArgments(int argc, char* argv[], Config* config) { + static constexpr const char* OPTSTR = "ha:"; + static const struct option OPTIONS[] = { + { "help", no_argument, nullptr, 'h' }, + { "api", required_argument, nullptr, 'a' }, + { nullptr, 0, nullptr, 0 } // termination of the option list + }; + int opt; + int option_index = 0; + while ((opt = getopt_long(argc, argv, OPTSTR, OPTIONS, &option_index)) >= 0) { + std::string arg(optarg != nullptr ? optarg : ""); + switch (opt) { + default: + case 'h': + printUsage(argv[0]); + exit(0); + case 'a': + if (arg == "opengl") { + config->backend = Engine::Backend::OPENGL; + } else if (arg == "vulkan") { + config->backend = Engine::Backend::VULKAN; + } else if (arg == "metal") { + config->backend = Engine::Backend::METAL; + } else { + std::cerr << "Unrecognized backend. Must be 'opengl'|'vulkan'|'metal'." + << std::endl; + } + break; + } + } + + return optind; +} + int main(int argc, char** argv) { App app; @@ -138,6 +197,8 @@ int main(int argc, char** argv) { Config config; config.title = "skinning test with more than 4 bones per vertex"; + handleCommandLineArgments(argc, argv, &config); + size_t boneCount = app.bonesPerVertex; float weight = 1.f / boneCount; FixedCapacityVector boneDataPerVertex(boneCount);