evan 2026.1.4
Evan
Loading...
Searching...
No Matches
XrSwapchainContext.hpp
1/*
2** ETIB PROJECT, 2026
3** evan
4** File description:
5** XrSwapchainContext
6*/
7
8#pragma once
9
10#include "evan/ASwapchainContext.hpp"
11#include "evan/ASwapchainImage.hpp"
12#include "evan/DeviceContext.hpp"
13#include "evan/openxr/XrDeviceBackend.hpp"
14#include "evan/openxr/XrSwapchainImage.hpp"
15
16#include <map>
17#include <memory>
18#include <optional>
19#include <vector>
20
21namespace evan
22{
41 {
42 public:
69 XrSwapchainContext(const DeviceContext &deviceContext);
70
87 void destroy(VkDevice device) override;
88
106 void recreateSwapchain(const DeviceContext &deviceContext,
107 VkRenderPass renderpass) override;
108
138 uint32_t &imageIndex) override;
139
154 void waitForImage(uint32_t index) override;
155
182
203 const std::vector<XrCompositionLayerProjectionView> &
205
211 ViewSet &getViewSet() override;
212
218 const ViewSet &getViewSet() const override;
219
229 VkSampleCountFlagBits getMsaaSamples() const override;
230
241 bool usesMultiview() const override;
242
250 void syncViewSet();
251
264 void setView(std::size_t index,
265 const utility::graphic::ViewF &view) override;
266
270 std::vector<XrView> _views;
271
277 std::vector<XrViewConfigurationView> _viewsConfigurations;
278
279 private:
292 void selectMsaaSamples(const DeviceContext &deviceContext);
293
301 struct SwapchainHandle {
302 XrSwapchain swapchain = XR_NULL_HANDLE;
303 XrSwapchainCreateInfo createInfo {};
304 };
305
318 std::optional<SwapchainHandle>
319 createMultiviewSwapchain(const DeviceContext &deviceContext,
320 VkFormat swapchainFormat);
321
329 std::vector<SwapchainHandle>
330 createPerViewSwapchains(const DeviceContext &deviceContext,
331 VkFormat swapchainFormat);
332
342 void buildSwapchainImages(const DeviceContext &deviceContext,
343 const std::vector<SwapchainHandle> &handles);
344
354 bool viewConfigurationsShareLayout() const;
355
361 ViewSet _viewSet;
362
367 VkSampleCountFlagBits _msaaSamples = VK_SAMPLE_COUNT_1_BIT;
368
377 bool _multiviewEnabled = false;
378
386 ColorAttachmentMode _colorAttachmentMode =
387 ColorAttachmentMode::SwapchainImageAttachment;
388
393 std::vector<XrCompositionLayerProjectionView> _projectionLayerViews;
394
401 float _nearPlane;
402
409 float _farPlane;
410
417 utility::graphic::PoseF _baseCenterPose {};
418
422 bool _hasBaseCenter { false };
423 };
424} // namespace evan
Represents the context for managing the swapchain in the rendering system.
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
The XrSwapchainContext class manages the swapchain context for an OpenXR application using Vulkan....
void updateProjectionLayerViews()
Updates the projection layer views based on current swapchain images and view data.
void syncViewSet()
Rebuilds the ViewSet from the latest OpenXR view state.
std::vector< XrView > _views
void recreateSwapchain(const DeviceContext &deviceContext, VkRenderPass renderpass) override
Recreates the swapchain and associated resources.
bool usesMultiview() const override
Indicates whether all views render into one layered swapchain.
void destroy(VkDevice device) override
Destroys all swapchain images and clears the swapchain image collection.
VkResult aquireImage(uint32_t index, VkDevice device, VkSemaphore imageAvailableSemaphore, VkFence inFlightFence, uint32_t &imageIndex) override
Acquires an image from the swapchain for rendering.
VkSampleCountFlagBits getMsaaSamples() const override
Retrieves the MSAA sample count used by this swapchain context.
std::vector< XrViewConfigurationView > _viewsConfigurations
ViewSet & getViewSet() override
Retrieves the set of views to render (mutable).
const std::vector< XrCompositionLayerProjectionView > & getProjectionLayerViews() const
Retrieves the projection layer views for the current view configurations.
void setView(std::size_t index, const utility::graphic::ViewF &view) override
Sets the view matrix for a specific view index.
void waitForImage(uint32_t index) override
Waits for a swapchain image to become available.
Small result wrapper used by helpers that must return both a status and a value (e....
Definition Error.hpp:89