diff --git a/base/vulkanexamplebase.cpp b/base/vulkanexamplebase.cpp index 824dd014..e0d9866e 100644 --- a/base/vulkanexamplebase.cpp +++ b/base/vulkanexamplebase.cpp @@ -8,6 +8,8 @@ #include "vulkanexamplebase.h" +std::vector VulkanExampleBase::args; + VkResult VulkanExampleBase::createInstance(bool enableValidation) { this->enableValidation = enableValidation; @@ -676,20 +678,19 @@ void VulkanExampleBase::submitFrame() VulkanExampleBase::VulkanExampleBase(bool enableValidation, PFN_GetEnabledFeatures enabledFeaturesFn) { - // Check for validation command line flag -#if defined(_WIN32) - for (int32_t i = 0; i < __argc; i++) + // Parse command line arguments + for (auto arg : args) { - if (__argv[i] == std::string("-validation")) + if (arg == std::string("-validation")) { enableValidation = true; } - if (__argv[i] == std::string("-vsync")) + if (arg == std::string("-vsync")) { enableVSync = true; } } -#elif defined(__ANDROID__) +#if defined(__ANDROID__) // Vulkan library is loaded dynamically on Android bool libLoaded = loadVulkanLibrary(); assert(libLoaded); @@ -894,11 +895,9 @@ HWND VulkanExampleBase::setupWindow(HINSTANCE hinstance, WNDPROC wndproc) this->windowInstance = hinstance; bool fullscreen = false; - - // Check command line arguments - for (int32_t i = 0; i < __argc; i++) + for (auto arg : args) { - if (__argv[i] == std::string("-fullscreen")) + if (arg == std::string("-fullscreen")) { fullscreen = true; } diff --git a/base/vulkanexamplebase.h b/base/vulkanexamplebase.h index acf8cb3b..f49adbe2 100644 --- a/base/vulkanexamplebase.h +++ b/base/vulkanexamplebase.h @@ -145,6 +145,8 @@ public: float zoom = 0; + static std::vector args; + // Defines a frame rate independent timer value clamped from -1.0...1.0 // For use in animations, rotations, etc. float timer = 0.0f; @@ -368,6 +370,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) } \ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR pCmdLine, int nCmdShow) \ { \ + for (size_t i = 0; i < __argc; i++) { VulkanExample::args.push_back(__argv[i]); }; \ vulkanExample = new VulkanExample(); \ vulkanExample->setupWindow(hInstance, WndProc); \ vulkanExample->initSwapchain(); \ @@ -402,7 +405,7 @@ static void handleEvent() \ } \ int main(const int argc, const char *argv[]) \ { \ - vulkanExample = new VulkanExample(); \ + vulkanExample = new VulkanExample(); \ vulkanExample->initSwapchain(); \ vulkanExample->prepare(); \ vulkanExample->renderLoop(); \ @@ -423,6 +426,7 @@ static void handleEvent(const xcb_generic_event_t *event) \ } \ int main(const int argc, const char *argv[]) \ { \ + for (size_t i = 0; i < argc; i++) { VulkanExample::args.push_back(argv[i]); }; \ vulkanExample = new VulkanExample(); \ vulkanExample->setupWindow(); \ vulkanExample->initSwapchain(); \