evan 2026.1.4
Evan
Loading...
Searching...
No Matches
ASwapchainContext.hpp
1/*
2** ETIB PROJECT, 2026
3** evan
4** File description:
5** ASwapchainContext
6*/
7
8#pragma once
9
10#include "evan/EvanPlatform.hpp"
11#include "evan/ADeviceBackend.hpp"
12#include "evan/ASwapchainImage.hpp"
13#include "evan/RenderSettings.hpp"
14#include "evan/ViewSet.hpp"
15
16#include <utility/graphic/view.hpp>
17
18#include <utility/logging/loggable.hpp>
19#include <utility/logging/default_logger.hpp>
20
21#include <map>
22#include <memory>
23#include <iostream>
24
25namespace evan
26{
27
42 protected utility::logging::Loggable<ASwapchainContext,
43 utility::logging::DefaultLogger>
44 {
45 public:
46 virtual ~ASwapchainContext() = default;
47
63 VkSurfaceCapabilitiesKHR capabilities;
64
69 std::vector<VkSurfaceFormatKHR> formats;
70
75 std::vector<VkPresentModeKHR> presentModes;
76 };
77
96 virtual void destroy(VkDevice device) = 0;
97
117 virtual void recreateSwapchain(const DeviceContext &deviceContext,
118 VkRenderPass renderpass) = 0;
119
134 VkRenderPass getRenderPass() const;
135
148 virtual VkSampleCountFlagBits getMsaaSamples() const = 0;
149
180 virtual VkResult aquireImage(uint32_t index, VkDevice device,
181 VkSemaphore imageAvailableSemaphore,
182 VkFence inFlightFence,
183 uint32_t &imageIndex) = 0;
184
203 virtual void waitForImage(uint32_t index) = 0;
204
218 std::vector<std::shared_ptr<ASwapchainImage>> _swapchainImages;
219
231 virtual ViewSet &getViewSet() = 0;
232
238 virtual const ViewSet &getViewSet() const = 0;
239
245 std::size_t getSwapchainCount() const;
246
258 virtual bool usesImageAvailableSemaphore() const;
259
270 virtual bool needsSwapchainRecreation() const;
271
285 virtual bool usesMultiview() const;
286
297 utility::graphic::ViewF getView(std::size_t index) const;
298
309 virtual void setView(std::size_t index,
310 const utility::graphic::ViewF &view);
311
323 const utility::graphic::PoseF &getViewOffset(void) const;
324
332 std::size_t getViewCount(void) const;
333
344 glm::mat4 getProjection(std::size_t index) const;
345
361 utility::math::Vector2F getViewportSize() const;
362
375 static void updateViewForExtent(utility::graphic::ViewF &view,
376 VkExtent2D extent);
377
378 protected:
393 VkRenderPass _renderPass;
394
404 utility::graphic::PoseF _viewOffset {};
405
453 const std::shared_ptr<ADeviceBackend> &deviceBackend,
454 VkSampleCountFlagBits msaaSamples, ColorAttachmentMode mode,
455 uint32_t viewMask = 0);
456
499 VkFormat
500 selectSwapchainFormat(VkPhysicalDevice physicalDevice,
501 const std::vector<int64_t> &swapchainFormats);
502
544 VkFormat findSupportedFormat(VkPhysicalDevice physicalDevice,
545 const std::vector<VkFormat> &candidates,
546 VkImageTiling tiling,
547 VkFormatFeatureFlags features);
548
549 private:
562 static bool isPlausibleVkFormat(int64_t value);
563
573 static bool supportsColorAttachment(VkPhysicalDevice physicalDevice,
574 VkFormat format);
575
589 static VkFormat
590 fallbackSwapchainFormat(VkPhysicalDevice physicalDevice);
591 };
592} // namespace evan
Represents the context for managing the swapchain in the rendering system.
const utility::graphic::PoseF & getViewOffset(void) const
Retrieves the persistent world-space view offset.
std::size_t getViewCount(void) const
Retrieves the number of views in the swapchain context.
utility::graphic::PoseF _viewOffset
Persistent world-space offset applied on top of the tracked poses.
utility::graphic::ViewF getView(std::size_t index) const
Retrieves the view matrix for the specified view index.
virtual void setView(std::size_t index, const utility::graphic::ViewF &view)
Sets the view state for the specified view index.
virtual const ViewSet & getViewSet() const =0
Retrieves the set of views to render (const version).
virtual VkResult aquireImage(uint32_t index, VkDevice device, VkSemaphore imageAvailableSemaphore, VkFence inFlightFence, uint32_t &imageIndex)=0
Acquires the next available image from the swapchain for rendering.
virtual void waitForImage(uint32_t index)=0
Waits for the specified image in the swapchain to become available for rendering.
VkRenderPass getRenderPass() const
Retrieves the render pass associated with the swapchain context.
static void updateViewForExtent(utility::graphic::ViewF &view, VkExtent2D extent)
Updates a view's viewport size and perspective for a new swapchain extent.
virtual ViewSet & getViewSet()=0
Retrieves the set of views to render for this swapchain context.
virtual void destroy(VkDevice device)=0
Destroys the swapchain and releases associated resources.
virtual void recreateSwapchain(const DeviceContext &deviceContext, VkRenderPass renderpass)=0
Recreates the swapchain and associated resources.
VkFormat selectSwapchainFormat(VkPhysicalDevice physicalDevice, const std::vector< int64_t > &swapchainFormats)
Selects the appropriate swapchain format from the available formats.
glm::mat4 getProjection(std::size_t index) const
Retrieves the projection matrix for the specified view index.
virtual bool usesImageAvailableSemaphore() const
Indicates whether aquireImage signals the image-available semaphore.
utility::math::Vector2F getViewportSize() const
Retrieves the current viewport size in pixels.
std::vector< std::shared_ptr< ASwapchainImage > > _swapchainImages
virtual VkSampleCountFlagBits getMsaaSamples() const =0
Retrieves the MSAA sample count used by this swapchain context.
virtual bool needsSwapchainRecreation() const
Indicates whether the swapchain needs to be recreated.
virtual bool usesMultiview() const
Indicates whether the frame renders every view in one pass.
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.
std::size_t getSwapchainCount() const
Retrieves the number of swapchain image sets in the context.
VkFormat findSupportedFormat(VkPhysicalDevice physicalDevice, const std::vector< VkFormat > &candidates, VkImageTiling tiling, VkFormatFeatureFlags features)
Finds a supported format from a list of candidates based on the specified tiling and feature requirem...
Represents the device context for the engine, managing Vulkan-related resources and operations.
Describes a set of views to render, independent of the swapchain image sets.
Definition ViewSet.hpp:37
Struct to encapsulate details about swap chain support.
std::vector< VkPresentModeKHR > presentModes
A list of supported presentation modes (e.g., FIFO, Mailbox, etc.).
std::vector< VkSurfaceFormatKHR > formats
A list of supported surface formats (color space and pixel format).
VkSurfaceCapabilitiesKHR capabilities
Vulkan surface capabilities, such as the minimum and maximum image count, extent, and supported trans...