From 06cd53e7b3a6e9437c53c446d7d809d832ee8af7 Mon Sep 17 00:00:00 2001 From: saschawillems Date: Sun, 22 Jan 2017 13:38:57 +0100 Subject: [PATCH] Moved settings into separate public struct, read fullscreen arg for all platforms (Refs #268) --- base/vulkanexamplebase.cpp | 49 ++++++++++++++++++-------------------- base/vulkanexamplebase.h | 14 +++++++---- 2 files changed, 33 insertions(+), 30 deletions(-) diff --git a/base/vulkanexamplebase.cpp b/base/vulkanexamplebase.cpp index 287b3295..65657dda 100644 --- a/base/vulkanexamplebase.cpp +++ b/base/vulkanexamplebase.cpp @@ -12,7 +12,7 @@ std::vector VulkanExampleBase::args; VkResult VulkanExampleBase::createInstance(bool enableValidation) { - this->enableValidation = enableValidation; + this->settings.validation = enableValidation; VkApplicationInfo appInfo = {}; appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; @@ -39,14 +39,14 @@ VkResult VulkanExampleBase::createInstance(bool enableValidation) instanceCreateInfo.pApplicationInfo = &appInfo; if (enabledExtensions.size() > 0) { - if (enableValidation) + if (settings.validation) { enabledExtensions.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME); } instanceCreateInfo.enabledExtensionCount = (uint32_t)enabledExtensions.size(); instanceCreateInfo.ppEnabledExtensionNames = enabledExtensions.data(); } - if (enableValidation) + if (settings.validation) { instanceCreateInfo.enabledLayerCount = vkDebug::validationLayerCount; instanceCreateInfo.ppEnabledLayerNames = vkDebug::validationLayerNames; @@ -564,16 +564,22 @@ void VulkanExampleBase::submitFrame() VulkanExampleBase::VulkanExampleBase(bool enableValidation) { + settings.validation = enableValidation; + // Parse command line arguments for (size_t i = 0; i < args.size(); i++) { if (args[i] == std::string("-validation")) { - this->enableValidation = true; + settings.validation = true; } if (args[i] == std::string("-vsync")) { - enableVSync = true; + settings.vsync = true; + } + if (args[i] == std::string("-fullscreen")) + { + settings.fullscreen = true; } if ((args[i] == std::string("-w")) || (args[i] == std::string("-width"))) { @@ -601,7 +607,7 @@ VulkanExampleBase::VulkanExampleBase(bool enableValidation) #if defined(_WIN32) // Enable console if validation is active // Debug message callback will output to it - if (this->enableValidation) + if (this->settings.validation) { setupConsole("Vulkan validation output"); } @@ -651,7 +657,7 @@ VulkanExampleBase::~VulkanExampleBase() delete vulkanDevice; - if (enableValidation) + if (settings.validation) { vkDebug::freeDebugCallback(instance); } @@ -675,7 +681,7 @@ void VulkanExampleBase::initVulkan() VkResult err; // Vulkan instance - err = createInstance(enableValidation); + err = createInstance(settings.validation); if (err) { vkTools::exitFatal("Could not create Vulkan instance : \n" + vkTools::errorString(err), "Fatal error"); @@ -686,7 +692,7 @@ void VulkanExampleBase::initVulkan() #endif // If requested, we enable the default validation layers for debugging - if (enableValidation) + if (settings.validation) { // The report flags determine what type of messages for the layers will be displayed // For validating (debugging) an appplication the error and warning bits should suffice @@ -777,15 +783,6 @@ HWND VulkanExampleBase::setupWindow(HINSTANCE hinstance, WNDPROC wndproc) { this->windowInstance = hinstance; - bool fullscreen = false; - for (auto arg : args) - { - if (arg == std::string("-fullscreen")) - { - fullscreen = true; - } - } - WNDCLASSEX wndClass; wndClass.cbSize = sizeof(WNDCLASSEX); @@ -811,7 +808,7 @@ HWND VulkanExampleBase::setupWindow(HINSTANCE hinstance, WNDPROC wndproc) int screenWidth = GetSystemMetrics(SM_CXSCREEN); int screenHeight = GetSystemMetrics(SM_CYSCREEN); - if (fullscreen) + if (settings.fullscreen) { DEVMODE dmScreenSettings; memset(&dmScreenSettings, 0, sizeof(dmScreenSettings)); @@ -827,11 +824,11 @@ HWND VulkanExampleBase::setupWindow(HINSTANCE hinstance, WNDPROC wndproc) { if (MessageBox(NULL, "Fullscreen Mode not supported!\n Switch to window mode?", "Error", MB_YESNO | MB_ICONEXCLAMATION) == IDYES) { - fullscreen = FALSE; + settings.fullscreen = false; } else { - return FALSE; + return false; } } } @@ -841,7 +838,7 @@ HWND VulkanExampleBase::setupWindow(HINSTANCE hinstance, WNDPROC wndproc) DWORD dwExStyle; DWORD dwStyle; - if (fullscreen) + if (settings.fullscreen) { dwExStyle = WS_EX_APPWINDOW; dwStyle = WS_POPUP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN; @@ -855,8 +852,8 @@ HWND VulkanExampleBase::setupWindow(HINSTANCE hinstance, WNDPROC wndproc) RECT windowRect; windowRect.left = 0L; windowRect.top = 0L; - windowRect.right = fullscreen ? (long)screenWidth : (long)width; - windowRect.bottom = fullscreen ? (long)screenHeight : (long)height; + windowRect.right = settings.fullscreen ? (long)screenWidth : (long)width; + windowRect.bottom = settings.fullscreen ? (long)screenHeight : (long)height; AdjustWindowRectEx(&windowRect, dwStyle, FALSE, dwExStyle); @@ -874,7 +871,7 @@ HWND VulkanExampleBase::setupWindow(HINSTANCE hinstance, WNDPROC wndproc) hinstance, NULL); - if (!fullscreen) + if (!settings.fullscreen) { // Center on screen uint32_t x = (GetSystemMetrics(SM_CXSCREEN) - windowRect.right) / 2; @@ -1584,5 +1581,5 @@ void VulkanExampleBase::initSwapchain() void VulkanExampleBase::setupSwapChain() { - swapChain.create(&width, &height, enableVSync); + swapChain.create(&width, &height, settings.vsync); } diff --git a/base/vulkanexamplebase.h b/base/vulkanexamplebase.h index 1d6e17e0..65c88f56 100644 --- a/base/vulkanexamplebase.h +++ b/base/vulkanexamplebase.h @@ -48,8 +48,6 @@ class VulkanExampleBase { private: - // Set to true if v-sync will be forced for the swapchain - bool enableVSync = false; // fps timer (one second interval) float fpsTimer = 0.0f; // Get window title with example name, device, et. @@ -63,8 +61,6 @@ private: // Called if the window is resized and some resources have to be recreatesd void windowResize(); protected: - // Is true when example is created validation layers enabled - bool enableValidation = false; // Last frame time, measured using a high performance timer (if available) float frameTimer = 1.0f; // Frame counter to display fps @@ -138,6 +134,16 @@ public: uint32_t width = 1280; uint32_t height = 720; + /** @brief Example settings that can be changed e.g. by command line arguments */ + struct Settings { + /** @brief Activates validation layers (and message output) when set to true */ + bool validation = false; + /** @brief Set to true if fullscreen mode has been requested via command line */ + bool fullscreen = false; + /** @brief Set to true if v-sync will be forced for the swapchain */ + bool vsync = false; + } settings; + VkClearColorValue defaultClearColor = { { 0.025f, 0.025f, 0.025f, 1.0f } }; float zoom = 0;