Skip to content
Snippets Groups Projects
Commit 5d385670 authored by Sebastian Gaida's avatar Sebastian Gaida
Browse files

[#16] adjust code according to MR

removed some temp debug code and removed context out of swapchain
parent a48f433a
No related branches found
No related tags found
4 merge requests!12Resolve "Swapchain Class",!7Resolve "Shader Program Class",!5Resolve "Pipeline State Object",!4Resolve "Renderpass Class"
Pipeline #24730 passed
......@@ -4,24 +4,17 @@
#include "vkcv/Window.hpp"
#include <iostream>
// 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;
const vkcv::Context& m_context;
vk::SwapchainKHR m_swapchain;
vk::SurfaceFormatKHR m_format;
SwapChain(vk::SurfaceKHR surface, const vkcv::Context &context, vk::SwapchainKHR swapchain, vk::SurfaceFormatKHR format);
SwapChain(vk::SurfaceKHR surface, vk::SwapchainKHR swapchain, vk::SurfaceFormatKHR format);
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) = default;
SwapChain(SwapChain &&other) = default;
......
......@@ -36,7 +36,6 @@ namespace vkcv
Context::~Context() noexcept
{
std::cout<< " Context " << std::endl;
m_Device.destroy();
m_Instance.destroy();
}
......
......@@ -301,20 +301,18 @@ namespace vkcv
if(transferQueueFamilyIndex == -1){
throw std::runtime_error("It is not possible to access another queue as a transfer queue.");
}
vk::Queue graphicsQueue = device.getQueue( graphicsQueueFamilyIndex, 0 );
vk::Queue computeQueue = device.getQueue(computeQueueFamilyIndex,1);
vk::Queue transferQueue = device.getQueue(transferQueueFamilyIndex,2);
vk::Queue graphicsQueue = device.getQueue(graphicsQueueFamilyIndex, 0);
vk::Queue computeQueue = device.getQueue(computeQueueFamilyIndex, 1);
vk::Queue transferQueue = device.getQueue(transferQueueFamilyIndex, 2);
Context context(instance, physicalDevice, device);
SwapChain swapChain = SwapChain::create(window, context);
std::vector<vk::Image> swapChainImages = device.getSwapchainImagesKHR(swapChain.getSwapchain());
std::vector<vk::ImageView> imageViews;
imageViews.reserve( swapChainImages.size() );
//here can be swizzled with vk::ComponentSwizzle if needed
// ToDo: we need the format from the surface object
vk::ComponentMapping componentMapping(
vk::ComponentSwizzle::eR,
vk::ComponentSwizzle::eG,
......@@ -353,8 +351,6 @@ namespace vkcv
{}
Core::~Core() {
std::cout<< " Core " << std::endl;
for( auto image: m_swapchainImageViews ){
m_Context.getDevice().destroyImageView(image);
}
......
......@@ -3,8 +3,8 @@
namespace vkcv {
SwapChain::SwapChain(vk::SurfaceKHR surface, const vkcv::Context &context, vk::SwapchainKHR swapchain, vk::SurfaceFormatKHR format )
: m_surface(surface), m_context(context), m_swapchain(swapchain), m_format( format)
SwapChain::SwapChain(vk::SurfaceKHR surface, vk::SwapchainKHR swapchain, vk::SurfaceFormatKHR format )
: m_surface(surface), m_swapchain(swapchain), m_format( format)
{}
vk::SwapchainKHR SwapChain::getSwapchain() {
......@@ -22,14 +22,10 @@ namespace vkcv {
vk::SurfaceKHR createSurface(GLFWwindow *window, const vk::Instance &instance, const vk::PhysicalDevice& physicalDevice) {
//create surface
VkSurfaceKHR surface;
// 0 means VK_SUCCESS
//std::cout << "FAIL: " << glfwCreateWindowSurface(VkInstance(instance), window, nullptr, &newSurface) << std::endl;
if (glfwCreateWindowSurface(VkInstance(instance), window, nullptr, &surface) != 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
// frage: nimmt die Swapchain automatisch den 0'ten Index (Graphics Queue Family)?
if (physicalDevice.getSurfaceSupportKHR(0, vk::SurfaceKHR(surface), &surfaceSupport) != vk::Result::eSuccess && surfaceSupport != true) {
throw std::runtime_error("surface is not supported by the device!");
}
......@@ -37,7 +33,6 @@ namespace vkcv {
return vk::SurfaceKHR(surface);
}
vk::Extent2D chooseSwapExtent(vk::PhysicalDevice physicalDevice, vk::SurfaceKHR surface, const Window &window){
vk::SurfaceCapabilitiesKHR surfaceCapabilities;
if(physicalDevice.getSurfaceCapabilitiesKHR(surface,&surfaceCapabilities) != vk::Result::eSuccess){
......@@ -89,6 +84,7 @@ namespace vkcv {
return availablePresentMode;
}
}
// The FIFO present mode is guaranteed by the spec to be supported
return vk::PresentModeKHR::eFifo;
}
......@@ -140,14 +136,12 @@ namespace vkcv {
vk::SwapchainKHR swapchain = device.createSwapchainKHR(swapchainCreateInfo);
return SwapChain(surface, context, swapchain, surfaceFormat);
return SwapChain(surface, swapchain, surfaceFormat);
}
SwapChain::~SwapChain() {
std::cout<< " Swap " << std::endl;
// m_context.getDevice().destroySwapchainKHR( m_swapchain );
// m_context.getInstance().destroySurfaceKHR( m_surface );
// needs to be destroyed by creator
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment