Moved settings into separate public struct, read fullscreen arg for all platforms (Refs #268)
This commit is contained in:
parent
792d8347be
commit
06cd53e7b3
2 changed files with 33 additions and 30 deletions
|
|
@ -12,7 +12,7 @@ std::vector<const char*> VulkanExampleBase::args;
|
||||||
|
|
||||||
VkResult VulkanExampleBase::createInstance(bool enableValidation)
|
VkResult VulkanExampleBase::createInstance(bool enableValidation)
|
||||||
{
|
{
|
||||||
this->enableValidation = enableValidation;
|
this->settings.validation = enableValidation;
|
||||||
|
|
||||||
VkApplicationInfo appInfo = {};
|
VkApplicationInfo appInfo = {};
|
||||||
appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
|
appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
|
||||||
|
|
@ -39,14 +39,14 @@ VkResult VulkanExampleBase::createInstance(bool enableValidation)
|
||||||
instanceCreateInfo.pApplicationInfo = &appInfo;
|
instanceCreateInfo.pApplicationInfo = &appInfo;
|
||||||
if (enabledExtensions.size() > 0)
|
if (enabledExtensions.size() > 0)
|
||||||
{
|
{
|
||||||
if (enableValidation)
|
if (settings.validation)
|
||||||
{
|
{
|
||||||
enabledExtensions.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
|
enabledExtensions.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
|
||||||
}
|
}
|
||||||
instanceCreateInfo.enabledExtensionCount = (uint32_t)enabledExtensions.size();
|
instanceCreateInfo.enabledExtensionCount = (uint32_t)enabledExtensions.size();
|
||||||
instanceCreateInfo.ppEnabledExtensionNames = enabledExtensions.data();
|
instanceCreateInfo.ppEnabledExtensionNames = enabledExtensions.data();
|
||||||
}
|
}
|
||||||
if (enableValidation)
|
if (settings.validation)
|
||||||
{
|
{
|
||||||
instanceCreateInfo.enabledLayerCount = vkDebug::validationLayerCount;
|
instanceCreateInfo.enabledLayerCount = vkDebug::validationLayerCount;
|
||||||
instanceCreateInfo.ppEnabledLayerNames = vkDebug::validationLayerNames;
|
instanceCreateInfo.ppEnabledLayerNames = vkDebug::validationLayerNames;
|
||||||
|
|
@ -564,16 +564,22 @@ void VulkanExampleBase::submitFrame()
|
||||||
|
|
||||||
VulkanExampleBase::VulkanExampleBase(bool enableValidation)
|
VulkanExampleBase::VulkanExampleBase(bool enableValidation)
|
||||||
{
|
{
|
||||||
|
settings.validation = enableValidation;
|
||||||
|
|
||||||
// Parse command line arguments
|
// Parse command line arguments
|
||||||
for (size_t i = 0; i < args.size(); i++)
|
for (size_t i = 0; i < args.size(); i++)
|
||||||
{
|
{
|
||||||
if (args[i] == std::string("-validation"))
|
if (args[i] == std::string("-validation"))
|
||||||
{
|
{
|
||||||
this->enableValidation = true;
|
settings.validation = true;
|
||||||
}
|
}
|
||||||
if (args[i] == std::string("-vsync"))
|
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")))
|
if ((args[i] == std::string("-w")) || (args[i] == std::string("-width")))
|
||||||
{
|
{
|
||||||
|
|
@ -601,7 +607,7 @@ VulkanExampleBase::VulkanExampleBase(bool enableValidation)
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
// Enable console if validation is active
|
// Enable console if validation is active
|
||||||
// Debug message callback will output to it
|
// Debug message callback will output to it
|
||||||
if (this->enableValidation)
|
if (this->settings.validation)
|
||||||
{
|
{
|
||||||
setupConsole("Vulkan validation output");
|
setupConsole("Vulkan validation output");
|
||||||
}
|
}
|
||||||
|
|
@ -651,7 +657,7 @@ VulkanExampleBase::~VulkanExampleBase()
|
||||||
|
|
||||||
delete vulkanDevice;
|
delete vulkanDevice;
|
||||||
|
|
||||||
if (enableValidation)
|
if (settings.validation)
|
||||||
{
|
{
|
||||||
vkDebug::freeDebugCallback(instance);
|
vkDebug::freeDebugCallback(instance);
|
||||||
}
|
}
|
||||||
|
|
@ -675,7 +681,7 @@ void VulkanExampleBase::initVulkan()
|
||||||
VkResult err;
|
VkResult err;
|
||||||
|
|
||||||
// Vulkan instance
|
// Vulkan instance
|
||||||
err = createInstance(enableValidation);
|
err = createInstance(settings.validation);
|
||||||
if (err)
|
if (err)
|
||||||
{
|
{
|
||||||
vkTools::exitFatal("Could not create Vulkan instance : \n" + vkTools::errorString(err), "Fatal error");
|
vkTools::exitFatal("Could not create Vulkan instance : \n" + vkTools::errorString(err), "Fatal error");
|
||||||
|
|
@ -686,7 +692,7 @@ void VulkanExampleBase::initVulkan()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// If requested, we enable the default validation layers for debugging
|
// 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
|
// 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
|
// 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;
|
this->windowInstance = hinstance;
|
||||||
|
|
||||||
bool fullscreen = false;
|
|
||||||
for (auto arg : args)
|
|
||||||
{
|
|
||||||
if (arg == std::string("-fullscreen"))
|
|
||||||
{
|
|
||||||
fullscreen = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
WNDCLASSEX wndClass;
|
WNDCLASSEX wndClass;
|
||||||
|
|
||||||
wndClass.cbSize = sizeof(WNDCLASSEX);
|
wndClass.cbSize = sizeof(WNDCLASSEX);
|
||||||
|
|
@ -811,7 +808,7 @@ HWND VulkanExampleBase::setupWindow(HINSTANCE hinstance, WNDPROC wndproc)
|
||||||
int screenWidth = GetSystemMetrics(SM_CXSCREEN);
|
int screenWidth = GetSystemMetrics(SM_CXSCREEN);
|
||||||
int screenHeight = GetSystemMetrics(SM_CYSCREEN);
|
int screenHeight = GetSystemMetrics(SM_CYSCREEN);
|
||||||
|
|
||||||
if (fullscreen)
|
if (settings.fullscreen)
|
||||||
{
|
{
|
||||||
DEVMODE dmScreenSettings;
|
DEVMODE dmScreenSettings;
|
||||||
memset(&dmScreenSettings, 0, sizeof(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)
|
if (MessageBox(NULL, "Fullscreen Mode not supported!\n Switch to window mode?", "Error", MB_YESNO | MB_ICONEXCLAMATION) == IDYES)
|
||||||
{
|
{
|
||||||
fullscreen = FALSE;
|
settings.fullscreen = false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -841,7 +838,7 @@ HWND VulkanExampleBase::setupWindow(HINSTANCE hinstance, WNDPROC wndproc)
|
||||||
DWORD dwExStyle;
|
DWORD dwExStyle;
|
||||||
DWORD dwStyle;
|
DWORD dwStyle;
|
||||||
|
|
||||||
if (fullscreen)
|
if (settings.fullscreen)
|
||||||
{
|
{
|
||||||
dwExStyle = WS_EX_APPWINDOW;
|
dwExStyle = WS_EX_APPWINDOW;
|
||||||
dwStyle = WS_POPUP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
|
dwStyle = WS_POPUP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
|
||||||
|
|
@ -855,8 +852,8 @@ HWND VulkanExampleBase::setupWindow(HINSTANCE hinstance, WNDPROC wndproc)
|
||||||
RECT windowRect;
|
RECT windowRect;
|
||||||
windowRect.left = 0L;
|
windowRect.left = 0L;
|
||||||
windowRect.top = 0L;
|
windowRect.top = 0L;
|
||||||
windowRect.right = fullscreen ? (long)screenWidth : (long)width;
|
windowRect.right = settings.fullscreen ? (long)screenWidth : (long)width;
|
||||||
windowRect.bottom = fullscreen ? (long)screenHeight : (long)height;
|
windowRect.bottom = settings.fullscreen ? (long)screenHeight : (long)height;
|
||||||
|
|
||||||
AdjustWindowRectEx(&windowRect, dwStyle, FALSE, dwExStyle);
|
AdjustWindowRectEx(&windowRect, dwStyle, FALSE, dwExStyle);
|
||||||
|
|
||||||
|
|
@ -874,7 +871,7 @@ HWND VulkanExampleBase::setupWindow(HINSTANCE hinstance, WNDPROC wndproc)
|
||||||
hinstance,
|
hinstance,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
if (!fullscreen)
|
if (!settings.fullscreen)
|
||||||
{
|
{
|
||||||
// Center on screen
|
// Center on screen
|
||||||
uint32_t x = (GetSystemMetrics(SM_CXSCREEN) - windowRect.right) / 2;
|
uint32_t x = (GetSystemMetrics(SM_CXSCREEN) - windowRect.right) / 2;
|
||||||
|
|
@ -1584,5 +1581,5 @@ void VulkanExampleBase::initSwapchain()
|
||||||
|
|
||||||
void VulkanExampleBase::setupSwapChain()
|
void VulkanExampleBase::setupSwapChain()
|
||||||
{
|
{
|
||||||
swapChain.create(&width, &height, enableVSync);
|
swapChain.create(&width, &height, settings.vsync);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -48,8 +48,6 @@
|
||||||
class VulkanExampleBase
|
class VulkanExampleBase
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
// Set to true if v-sync will be forced for the swapchain
|
|
||||||
bool enableVSync = false;
|
|
||||||
// fps timer (one second interval)
|
// fps timer (one second interval)
|
||||||
float fpsTimer = 0.0f;
|
float fpsTimer = 0.0f;
|
||||||
// Get window title with example name, device, et.
|
// 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
|
// Called if the window is resized and some resources have to be recreatesd
|
||||||
void windowResize();
|
void windowResize();
|
||||||
protected:
|
protected:
|
||||||
// Is true when example is created validation layers enabled
|
|
||||||
bool enableValidation = false;
|
|
||||||
// Last frame time, measured using a high performance timer (if available)
|
// Last frame time, measured using a high performance timer (if available)
|
||||||
float frameTimer = 1.0f;
|
float frameTimer = 1.0f;
|
||||||
// Frame counter to display fps
|
// Frame counter to display fps
|
||||||
|
|
@ -138,6 +134,16 @@ public:
|
||||||
uint32_t width = 1280;
|
uint32_t width = 1280;
|
||||||
uint32_t height = 720;
|
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 } };
|
VkClearColorValue defaultClearColor = { { 0.025f, 0.025f, 0.025f, 1.0f } };
|
||||||
|
|
||||||
float zoom = 0;
|
float zoom = 0;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue