8#include "evan/glfw/DesktopSwapchainContext.hpp"
10#include "evan/CheckedCast.hpp"
11#include "evan/DeviceContext.hpp"
13std::unordered_map<GLFWwindow *, evan::DesktopSwapchainContext *>
14 evan::DesktopSwapchainContext::_contexts {};
19 , _msaaSamples(deviceContext.getMsaaSamples())
21 this->
getLogger().info() <<
"Initializing DesktopSwapchainContext...";
24 desktopColorAttachmentMode(_msaaSamples));
27 <<
"Creating swapchain images for DesktopSwapchainContext...";
34 <<
"Registering GLFW framebuffer size callback for proactive swapchain "
38 window, &DesktopSwapchainContext::framebufferSizeCallback);
41evan::DesktopSwapchainContext::~DesktopSwapchainContext()
43 this->
getLogger().info() <<
"Destroying DesktopSwapchainContext...";
44 if (_referenceWindow) {
46 _contexts.erase(_referenceWindow);
56 this->
getLogger().info() <<
"Destroying swapchain and associated resources "
57 "for DesktopSwapchainContext...";
60 <<
"Destroying render pass for DesktopSwapchainContext...";
64 <<
"Destroying swapchain images for DesktopSwapchainContext...";
66 this->
getLogger().info() <<
"Destroying swapchain image and releasing "
67 "associated resources...";
75 this->
getLogger().info() <<
"Recreating swapchain and associated resources "
76 "for DesktopSwapchainContext...";
81 <<
"Waiting for the device to be idle before recreating the "
86 if (!_swapchainImages.empty()) {
93 <<
"Creating new swapchain image with the previous swapchain as "
98 this->
getLogger().info() <<
"Destroying existing swapchain images for "
99 "DesktopSwapchainContext...";
101 this->
getLogger().info() <<
"Destroying swapchain image and releasing "
102 "associated resources...";
105 _swapchainImages.clear();
109 <<
"Updating view for the new swapchain extent while preserving the "
110 "camera transform...";
111 auto view = this->getViewSet()[0].view;
114 this->getViewSet().setView(0, view);
116 _framebufferResized =
false;
123 this->
getLogger().info() <<
"Acquiring next available image from swapchain "
124 "for DesktopSwapchainContext...";
130 <<
"Calling vkAcquireNextImageKHR to acquire image from swapchain...";
158 return _framebufferResized;
161void evan::DesktopSwapchainContext::framebufferSizeCallback(
GLFWwindow *
window,
168 if (
it != _contexts.end()) {
169 it->second->_framebufferResized =
true;
static void updateViewForExtent(utility::graphic::ViewF &view, VkExtent2D extent)
Updates a view's viewport size and perspective for a new swapchain extent.
std::vector< std::shared_ptr< ASwapchainImage > > _swapchainImages
void createRenderPass(const std::shared_ptr< ADeviceBackend > &deviceBackend, VkSampleCountFlagBits msaaSamples, ColorAttachmentMode mode, uint32_t viewMask=0)
Creates the Vulkan render pass for the swapchain context.
void recreateSwapchain(const DeviceContext &deviceContext, VkRenderPass renderpass) override
Recreates the swapchain and associated resources.
void destroy(VkDevice device) override
Destroys the swapchain and releases associated resources.
ViewSet & getViewSet() override
Retrieves the set of views to render (mutable).
DesktopSwapchainContext(const DeviceContext &deviceContext, GLFWwindow *window)
Constructs a DesktopSwapchainContext instance with the provided device context and GLFW window.
VkSampleCountFlagBits getMsaaSamples() const override
Retrieves the MSAA sample count used by this swapchain context.
VkResult aquireImage(uint32_t index, VkDevice device, VkSemaphore imageAvailableSemaphore, VkFence inFlightFence, uint32_t &imageIndex) override
Acquires the next available image from the swapchain for rendering.
bool needsSwapchainRecreation() const override
Desktop swapchains must be recreated when the GLFW window is resized.
bool usesImageAvailableSemaphore() const override
Desktop swapchains signal the image-available semaphore through vkAcquireNextImageKHR.
A swapchain image implementation for desktop platforms using GLFW.
Represents the device context for the engine, managing Vulkan-related resources and operations.
std::shared_ptr< ADeviceBackend > getDeviceBackend() const
Retrieves a shared pointer to the ADeviceBackend instance associated with this device context.
Describes a set of views to render, independent of the swapchain image sets.
void resize(std::size_t count)
Resizes the view set to contain exactly count views.
Small result wrapper used by helpers that must return both a status and a value (e....