From bdd3d9b66a8a2f8bd1bec8777afcde3d82117787 Mon Sep 17 00:00:00 2001 From: Squareys Date: Tue, 26 Apr 2016 17:36:47 +0200 Subject: [PATCH] Vk: Continue context setup Signed-off-by: Squareys --- src/Magnum/Platform/GlfwApplication.h | 9 +++++---- src/Magnum/Vk/Context.cpp | 15 ++++++++++++++- src/Magnum/Vk/Context.h | 1 + src/Magnum/Vk/Test/ContextTest.cpp | 10 +++++++++- 4 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/Magnum/Platform/GlfwApplication.h b/src/Magnum/Platform/GlfwApplication.h index 4e6d17bec..368b06080 100644 --- a/src/Magnum/Platform/GlfwApplication.h +++ b/src/Magnum/Platform/GlfwApplication.h @@ -220,6 +220,11 @@ class GlfwApplication { glfwSetCursorPos(_window, Double(position.x()), Double(position.y())); } + + #ifdef MAGNUM_TARGET_VULKAN + VkSurfaceKHR createVkSurface(); + #endif + #ifdef DOXYGEN_GENERATING_OUTPUT protected: #else @@ -244,10 +249,6 @@ class GlfwApplication { /*@}*/ - #ifdef MAGNUM_TARGET_VULKAN - VkSurfaceKHR createVkSurface(); - #endif - private: static void staticViewportEvent(GLFWwindow*, int w, int h) { _instance->viewportEvent({w, h}); diff --git a/src/Magnum/Vk/Context.cpp b/src/Magnum/Vk/Context.cpp index 6a63e3b6e..8704c00b4 100644 --- a/src/Magnum/Vk/Context.cpp +++ b/src/Magnum/Vk/Context.cpp @@ -102,11 +102,13 @@ VkBool32 messageCallback(VkDebugReportFlagsEXT flags, VkDebugReportObjectTypeEXT } bool Context::tryCreate() { + _version = Version::Vulkan_1_0; + VkApplicationInfo appInfo = {}; appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; appInfo.pApplicationName = "Vulkan Example"; appInfo.pEngineName = "Magnum"; - appInfo.apiVersion = UnsignedInt(Version::Vulkan_1_0); + appInfo.apiVersion = UnsignedInt(_version); std::vector enabledExtensions = { VK_KHR_SURFACE_EXTENSION_NAME }; @@ -204,4 +206,15 @@ Debug& operator<<(Debug& debug, Context::Flag value) { return debug << "Context::Flag::(invalid)"; } +Debug& operator<<(Debug& debug, Version value) { + switch(value) { + #define _c(value) case Version::value: return debug << "Vk::Version::" #value; + _c(None) + _c(Vulkan_1_0) + #undef _c + } + + return debug << "Vk::Version::(invalid)"; +} + }} diff --git a/src/Magnum/Vk/Context.h b/src/Magnum/Vk/Context.h index 429054371..0d63b1b6e 100644 --- a/src/Magnum/Vk/Context.h +++ b/src/Magnum/Vk/Context.h @@ -185,6 +185,7 @@ class MAGNUM_VK_EXPORT Context { MAGNUM_VK_EXPORT Debug& operator<<(Debug& debug, Result value); MAGNUM_VK_EXPORT Debug& operator<<(Debug& debug, Context::Flag value); +MAGNUM_VK_EXPORT Debug& operator<<(Debug& debug, Version value); }} diff --git a/src/Magnum/Vk/Test/ContextTest.cpp b/src/Magnum/Vk/Test/ContextTest.cpp index 768505e79..41262f61d 100644 --- a/src/Magnum/Vk/Test/ContextTest.cpp +++ b/src/Magnum/Vk/Test/ContextTest.cpp @@ -3,6 +3,7 @@ Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016 Vladimír Vondruš + Copyright © 2016 Jonathan Hale Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), @@ -33,15 +34,22 @@ namespace Magnum { namespace Test { struct ContextTest: TestSuite::Tester { explicit ContextTest(); + void createAndDestroy(); void flag(); void result(); }; ContextTest::ContextTest() { - addTests({&ContextTest::flag, + addTests({&ContextTest::createAndDestroy, + &ContextTest::flag, &ContextTest::result}); } +void ContextTest::createAndDestroy() { + Vk::Context c{{}}; + CORRADE_COMPARE(c.version(), Vk::Version::Vulkan_1_0); +} + void ContextTest::flag() { std::ostringstream out; Debug(&out) << Vk::Context::Flag::EnableValidation;