platform agnostic argument handling

This commit is contained in:
saschawillems 2016-11-10 22:29:55 +01:00
parent ddaf4943e3
commit db66e81721
2 changed files with 14 additions and 11 deletions

View file

@ -8,6 +8,8 @@
#include "vulkanexamplebase.h"
std::vector<char*> 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;
}

View file

@ -145,6 +145,8 @@ public:
float zoom = 0;
static std::vector<char*> 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(); \