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

[#16] added ImageViews and temp fixed exception

added functionality to ImageViews
temporarily fixed the access violation to be able to compile
parent 207874d5
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 #24723 passed
......@@ -26,19 +26,20 @@ namespace vkcv
*
* @param context encapsulates various Vulkan objects
*/
Core(Context &&context, const Window &window, SwapChain &swapChain) noexcept;
Core(Context &&context, const Window &window, SwapChain swapChain, std::vector<vk::ImageView> imageViews) noexcept;
// explicit destruction of default constructor
Core() = delete;
Context m_Context;
SwapChain& m_swapchain;
SwapChain m_swapchain;
std::vector<vk::ImageView> m_swapchainImageViews;
const Window& m_window;
public:
/**
* Destructor of #Core destroys the Vulkan objects contained in the core's context.
*/
~Core() noexcept = default;
~Core();
/**
* Copy-constructor of #Core is deleted!
......
......@@ -15,13 +15,14 @@ namespace vkcv {
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);
SwapChain(vk::SurfaceKHR surface, const vkcv::Context &context, 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) = delete;
SwapChain(const SwapChain &other) = default;
SwapChain(SwapChain &&other) = default;
/**
......@@ -31,8 +32,13 @@ namespace vkcv {
[[nodiscard]]
vk::SwapchainKHR getSwapchain();
[[nodiscard]]
vk::SurfaceKHR getSurface();
[[nodiscard]]
vk::SurfaceFormatKHR getSurfaceFormat();
static SwapChain create(const Window &window, const Context &context);
virtual ~SwapChain();
};
......
#include <iostream>
#include "vkcv/Context.hpp"
namespace vkcv
......@@ -35,6 +36,7 @@ namespace vkcv
Context::~Context() noexcept
{
std::cout<< " Context " << std::endl;
m_Device.destroy();
m_Instance.destroy();
}
......
......@@ -308,7 +308,36 @@ namespace vkcv
Context context(instance, physicalDevice, device);
SwapChain swapChain = SwapChain::create(window, context);
return Core(std::move(context) , window, swapChain);
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,
vk::ComponentSwizzle::eB,
vk::ComponentSwizzle::eA );
vk::ImageSubresourceRange subResourceRange( vk::ImageAspectFlagBits::eColor, 0, 1, 0, 1 );
for ( auto image : swapChainImages )
{
vk::ImageViewCreateInfo imageViewCreateInfo(
vk::ImageViewCreateFlags(),
image,
vk::ImageViewType::e2D,
swapChain.getSurfaceFormat().format,
componentMapping,
subResourceRange
);
imageViews.push_back( device.createImageView( imageViewCreateInfo ) );
}
return Core(std::move(context) , window, swapChain, imageViews);
}
const Context &Core::getContext() const
......@@ -316,9 +345,21 @@ namespace vkcv
return m_Context;
}
Core::Core(Context &&context, const Window &window , SwapChain &swapChain) noexcept :
Core::Core(Context &&context, const Window &window , SwapChain swapChain, std::vector<vk::ImageView> imageViews) noexcept :
m_Context(std::move(context)),
m_window(window),
m_swapchain(swapChain)
m_swapchain(swapChain),
m_swapchainImageViews(imageViews)
{}
Core::~Core() {
std::cout<< " Core " << std::endl;
for( auto image: m_swapchainImageViews ){
m_Context.getDevice().destroyImageView(image);
}
m_Context.getDevice().destroySwapchainKHR(m_swapchain.getSwapchain());
m_Context.getInstance().destroySurfaceKHR( m_swapchain.getSurface() );
}
}
......@@ -3,14 +3,22 @@
namespace vkcv {
SwapChain::SwapChain(vk::SurfaceKHR surface, const vkcv::Context &context, vk::SwapchainKHR swapchain)
: m_surface(surface), m_context(context), m_swapchain(swapchain)
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)
{}
vk::SwapchainKHR SwapChain::getSwapchain() {
return m_swapchain;
}
vk::SurfaceKHR SwapChain::getSurface() {
return m_surface;
}
vk::SurfaceFormatKHR SwapChain::getSurfaceFormat(){
return m_format;
}
vk::SurfaceKHR createSurface(GLFWwindow *window, const vk::Instance &instance, const vk::PhysicalDevice& physicalDevice) {
//create surface
VkSurfaceKHR surface;
......@@ -132,13 +140,14 @@ namespace vkcv {
vk::SwapchainKHR swapchain = device.createSwapchainKHR(swapchainCreateInfo);
return SwapChain(surface, context, swapchain);
return SwapChain(surface, context, swapchain, surfaceFormat);
}
SwapChain::~SwapChain() {
m_context.getDevice().destroySwapchainKHR( m_swapchain );
m_context.getInstance().destroySurfaceKHR( m_surface );
std::cout<< " Swap " << std::endl;
// m_context.getDevice().destroySwapchainKHR( m_swapchain );
// m_context.getInstance().destroySurfaceKHR( m_surface );
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment