diff --git a/config/Sources.cmake b/config/Sources.cmake index 9a9f55747194ab9972254d5bf57ac11735607b06..2e84f23760e07322cac0b688c1c821526be0b0e5 100644 --- a/config/Sources.cmake +++ b/config/Sources.cmake @@ -6,4 +6,6 @@ set(vkcv_sources ${vkcv_source}/vkcv/Window.cpp ${vkcv_source}/vkcv/CoreManager.hpp ${vkcv_source}/vkcv/CoreManager.cpp + ${vkcv_source}/vkcv/SwapChain.hpp + ${vkcv_source}/vkcv/SwapChain.cpp ) diff --git a/projects/first_triangle/src/main.cpp b/projects/first_triangle/src/main.cpp index cc592f468e0c3e95d64a1558404873c4ca19f8b9..624d1a40f62520fb4ee988c8751fd0aff9e67153 100644 --- a/projects/first_triangle/src/main.cpp +++ b/projects/first_triangle/src/main.cpp @@ -1,6 +1,7 @@ #include <iostream> #include <vkcv/Context.hpp> #include <vkcv/Window.hpp> +#include <vkcv/SwapChain.hpp> int main(int argc, const char** argv) { const char* applicationName = "First Triangle"; @@ -14,12 +15,16 @@ int main(int argc, const char** argv) { applicationName, VK_MAKE_VERSION(0, 0, 1), 20, - {vk::QueueFlagBits::eGraphics, vk::QueueFlagBits::eTransfer} + {vk::QueueFlagBits::eGraphics, vk::QueueFlagBits::eTransfer}, + {}, + {"VK_KHR_swapchain"} ); + GLFWwindow *glWindow = window.getWindow(); const vk::Instance& instance = context.getInstance(); const vk::PhysicalDevice& physicalDevice = context.getPhysicalDevice(); const vk::Device& device = context.getDevice(); + const vkcv::SwapChain& swapChain = vkcv::SwapChain::create(glWindow, instance, physicalDevice, device); std::cout << "Physical device: " << physicalDevice.getProperties().deviceName << std::endl; diff --git a/src/vkcv/SwapChain.cpp b/src/vkcv/SwapChain.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ed999fcda4bc34f04c7ccbdee04aed2f65c268c8 --- /dev/null +++ b/src/vkcv/SwapChain.cpp @@ -0,0 +1,40 @@ +#include "SwapChain.hpp" +#include "CoreManager.hpp" +#include <iostream> + +namespace vkcv { + + SwapChain::SwapChain(vk::SurfaceKHR surface) + : m_surface(surface) + {} + + SwapChain SwapChain::create(GLFWwindow* window, const vk::Instance& instance, const vk::PhysicalDevice& physicalDevice, const vk::Device& device){ + vk::SurfaceKHR surface = VK_NULL_HANDLE; + createSurface(window,surface,instance,physicalDevice); + vk::SurfaceCapabilitiesKHR surfaceCapabilities; + if(physicalDevice.getSurfaceCapabilitiesKHR(surface,&surfaceCapabilities) != vk::Result::eSuccess){ + throw std::runtime_error("cannot get surface capabilites. There is an issue with the surface."); + } + + + + + return SwapChain(surface); + + } + + void SwapChain::createSurface(GLFWwindow *window, vk::SurfaceKHR &surface, const vk::Instance &instance, const vk::PhysicalDevice& physicalDevice) { + //create surface + auto newSurface = VkSurfaceKHR(surface); + // 0 means VK_SUCCESS + //std::cout << "FAIL: " << glfwCreateWindowSurface(VkInstance(instance), window, nullptr, &newSurface) << std::endl; + if(glfwCreateWindowSurface(VkInstance(instance), window, nullptr, &newSurface) != VK_SUCCESS) { + throw std::runtime_error("failed to create a window surface!"); + } + vk::Bool32 surfaceSupport = false; + // ToDo: hierfuer brauchen wir jetzt den queuefamiliy Index -> siehe ToDo in Context.cpp + //if(physicalDevice.getSurfaceSupportKHR()) + + } + +} \ No newline at end of file diff --git a/src/vkcv/SwapChain.hpp b/src/vkcv/SwapChain.hpp new file mode 100644 index 0000000000000000000000000000000000000000..925cc694260aada0fd59a2729b2038e47507297d --- /dev/null +++ b/src/vkcv/SwapChain.hpp @@ -0,0 +1,28 @@ +#pragma once +#include "vulkan/vulkan.hpp" +#include "Context.hpp" +#include "Window.hpp" + + +// glfw is not initialized in this class because ist must be sure that there exists a context first +// glfw is already initialized by the context or the window class + +namespace vkcv { + + class SwapChain final { + private: + vk::SurfaceKHR m_surface; + + SwapChain(vk::SurfaceKHR); + + public: + // bin mir grade unsicher wegen der Mehrfachinstanziierung der Klasse + // es muessen ja oefter mal neue erstellt werden, aber diese existieren ja nicht gleichzeitig, oder? + SwapChain(const SwapChain &other) = delete; + SwapChain(SwapChain &&other) = default; + static SwapChain create(GLFWwindow *window, const vk::Instance& instance,const vk::PhysicalDevice& physicalDevice,const vk::Device& device); + static void createSurface(GLFWwindow *window, vk::SurfaceKHR& surface, const vk::Instance& instance, const vk::PhysicalDevice& physicalDevice); + + }; + +} \ No newline at end of file