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

[#89] change imageView handling to SwapchainManager and changed Swapchain creation

parent c6d9823c
No related branches found
No related tags found
1 merge request!90Resolve "Mehrere Fenster, Abhängigkeiten von Core zu Fenster+Swapchain etc"
......@@ -17,6 +17,7 @@ namespace vkcv {
private:
Context *m_context;
void destroySwapchainById(uint64_t id);
public:
......@@ -32,10 +33,15 @@ namespace vkcv {
SwapchainManager &operator=(const SwapchainManager &other) = delete;
SwapchainHandle createSwapchain(Window &window, Context &context);
SwapchainHandle createSwapchain(Window &window);
[[nodiscard]]
Swapchain &getSwapchain(const SwapchainHandle handle) const;
void signalRecreation(const SwapchainHandle handle);
std::vector<vk::Image> getSwapchainImages(const SwapchainHandle handle);
std::vector<vk::ImageView> createSwapchainImageViews(SwapchainHandle handle);
};
}
\ No newline at end of file
......@@ -5,9 +5,11 @@
#include "vkcv/Window.hpp"
#include "vkcv/Handles.hpp"
#include "vkcv/SwapchainManager.hpp"
namespace vkcv {
class Core;
class Context;
class SwapchainManager;
class WindowManager {
friend class Core;
......@@ -29,7 +31,7 @@ namespace vkcv {
WindowManager &operator=(const WindowManager &other) = delete;
WindowHandle createWindow(Core &core, const char *applicationName, uint32_t windowWidth, uint32_t windowHeight,
WindowHandle createWindow( SwapchainManager &swapchainManager, const char *applicationName, uint32_t windowWidth, uint32_t windowHeight,
bool resizeable);
[[nodiscard]]
......
......@@ -13,13 +13,15 @@ namespace vkcv {
m_swapchains.clear();
}
[[maybe_unused]] SwapchainHandle SwapchainManager::createSwapchain(Window &window, Context &context) {
SwapchainHandle SwapchainManager::createSwapchain(Window &window) {
const uint64_t id = m_swapchains.size();
Swapchain swapchain = Swapchain::create(window, context);
Swapchain swapchain = Swapchain::create(window, *m_context);
m_swapchains.push_back(swapchain);
return SwapchainHandle(id, [&](uint64_t id) { destroySwapchainById(id); });
SwapchainHandle swapchainHandle = SwapchainHandle(id, [&](uint64_t id) { destroySwapchainById(id); });
window.m_swapchainHandle = swapchainHandle;
return swapchainHandle;
}
Swapchain &SwapchainManager::getSwapchain(const SwapchainHandle handle) const {
......@@ -32,5 +34,45 @@ namespace vkcv {
vkcv_log(LogLevel::ERROR, "Invalid id");
return;
}
m_context->getDevice().destroySwapchainKHR(m_swapchains[id].getSwapchain());
m_context->getInstance().destroySurfaceKHR(m_swapchains[id].getSurface());
}
void SwapchainManager::signalRecreation(const SwapchainHandle handle) {
m_swapchains[handle.getId()].signalSwapchainRecreation();
}
std::vector<vk::Image> SwapchainManager::getSwapchainImages(const SwapchainHandle handle) {
return m_context->getDevice().getSwapchainImagesKHR(m_swapchains[handle.getId()].getSwapchain());
}
std::vector<vk::ImageView> SwapchainManager::createSwapchainImageViews(SwapchainHandle handle){
std::vector<vk::Image> images = getSwapchainImages(handle);
Swapchain &swapchain = m_swapchains[handle.getId()];
std::vector<vk::ImageView> imageViews;
imageViews.reserve( images.size() );
//here can be swizzled with vk::ComponentSwizzle if needed
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 : images )
{
vk::ImageViewCreateInfo imageViewCreateInfo(
vk::ImageViewCreateFlags(),
image,
vk::ImageViewType::e2D,
swapchain.getFormat(),
componentMapping,
subResourceRange);
imageViews.push_back(m_context->getDevice().createImageView(imageViewCreateInfo));
}
return imageViews;
}
}
\ No newline at end of file
#include "vkcv/WindowManager.hpp"
#include "vkcv/Core.hpp"
#include "vkcv/Context.hpp"
namespace vkcv {
static std::vector<Window> m_windows;
......@@ -15,7 +15,7 @@ namespace vkcv {
}
WindowHandle WindowManager::createWindow(
Core &core,
SwapchainManager &swapchainManager,
const char *applicationName,
uint32_t windowWidth,
uint32_t windowHeight,
......@@ -24,11 +24,11 @@ namespace vkcv {
vkcv::Window window = vkcv::Window(applicationName, windowWidth, windowHeight, resizeable);
Swapchain swapChain = Swapchain::create(window, core.getContext());
SwapchainHandle swapchainHandle = swapchainManager.createSwapchain(window);
if (resizeable) {
window.e_resize.add([&](int width, int height) {
// m_swapchain.signalSwapchainRecreation(); // swapchain signal
swapchainManager.signalRecreation(swapchainHandle);
});
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment