|
evan 2026.1.4
Evan
|
The XrSwapchainContext class manages the swapchain context for an OpenXR application using Vulkan. It inherits from ASwapchainContext and provides implementations for acquiring images from the swapchain, waiting for images to be available, and updating projection layer views based on the current view configurations. The class also maintains a vector of XrCompositionLayerProjectionView structures that represent the projection layer views for each view configuration, allowing for efficient management of rendering resources in a VR application. More...
#include <headers/evan/openxr/XrSwapchainContext.hpp>


Public Member Functions | |
| XrSwapchainContext (const DeviceContext &deviceContext) | |
| Constructs an XrSwapchainContext instance using the provided DeviceContext. | |
| void | destroy (VkDevice device) override |
| Destroys all swapchain images and clears the swapchain image collection. | |
| void | recreateSwapchain (const DeviceContext &deviceContext, VkRenderPass renderpass) override |
| Recreates the swapchain and associated resources. | |
| VkResult | aquireImage (uint32_t index, VkDevice device, VkSemaphore imageAvailableSemaphore, VkFence inFlightFence, uint32_t &imageIndex) override |
| Acquires an image from the swapchain for rendering. | |
| void | waitForImage (uint32_t index) override |
| Waits for a swapchain image to become available. | |
| void | updateProjectionLayerViews () |
| Updates the projection layer views based on current swapchain images and view data. | |
| const std::vector< XrCompositionLayerProjectionView > & | getProjectionLayerViews () const |
| Retrieves the projection layer views for the current view configurations. | |
| ViewSet & | getViewSet () override |
| Retrieves the set of views to render (mutable). | |
| const ViewSet & | getViewSet () const override |
| Retrieves the set of views to render (const). | |
| VkSampleCountFlagBits | getMsaaSamples () const override |
| Retrieves the MSAA sample count used by this swapchain context. | |
| bool | usesMultiview () const override |
| Indicates whether all views render into one layered swapchain. | |
| void | syncViewSet () |
| Rebuilds the ViewSet from the latest OpenXR view state. | |
| void | setView (std::size_t index, const utility::graphic::ViewF &view) override |
| Sets the view matrix for a specific view index. | |
Public Member Functions inherited from evan::ASwapchainContext | |
| VkRenderPass | getRenderPass () const |
| Retrieves the render pass associated with the swapchain context. | |
| std::size_t | getSwapchainCount () const |
| Retrieves the number of swapchain image sets in the context. | |
| virtual bool | usesImageAvailableSemaphore () const |
| Indicates whether aquireImage signals the image-available semaphore. | |
| virtual bool | needsSwapchainRecreation () const |
| Indicates whether the swapchain needs to be recreated. | |
| utility::graphic::ViewF | getView (std::size_t index) const |
| Retrieves the view matrix for the specified view index. | |
| 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. | |
| glm::mat4 | getProjection (std::size_t index) const |
| Retrieves the projection matrix for the specified view index. | |
| utility::math::Vector2F | getViewportSize () const |
| Retrieves the current viewport size in pixels. | |
Public Attributes | |
| std::vector< XrView > | _views |
| std::vector< XrViewConfigurationView > | _viewsConfigurations |
Public Attributes inherited from evan::ASwapchainContext | |
| std::vector< std::shared_ptr< ASwapchainImage > > | _swapchainImages |
Additional Inherited Members | |
Static Public Member Functions inherited from evan::ASwapchainContext | |
| static void | updateViewForExtent (utility::graphic::ViewF &view, VkExtent2D extent) |
| Updates a view's viewport size and perspective for a new swapchain extent. | |
Protected Member Functions inherited from evan::ASwapchainContext | |
| 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. | |
| VkFormat | selectSwapchainFormat (VkPhysicalDevice physicalDevice, const std::vector< int64_t > &swapchainFormats) |
| Selects the appropriate swapchain format from the available formats. | |
| 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 requirements. | |
Protected Attributes inherited from evan::ASwapchainContext | |
| VkRenderPass | _renderPass |
| utility::graphic::PoseF | _viewOffset {} |
| Persistent world-space offset applied on top of the tracked poses. | |
The XrSwapchainContext class manages the swapchain context for an OpenXR application using Vulkan. It inherits from ASwapchainContext and provides implementations for acquiring images from the swapchain, waiting for images to be available, and updating projection layer views based on the current view configurations. The class also maintains a vector of XrCompositionLayerProjectionView structures that represent the projection layer views for each view configuration, allowing for efficient management of rendering resources in a VR application.
Definition at line 40 of file XrSwapchainContext.hpp.
| evan::XrSwapchainContext::XrSwapchainContext | ( | const DeviceContext & | deviceContext | ) |
Constructs an XrSwapchainContext instance using the provided DeviceContext.
This constructor initializes the XrSwapchainContext by setting up the necessary Vulkan resources and configurations based on the provided DeviceContext. It may involve querying the swapchain support details, creating projection layer views, and preparing for image acquisition from the swapchain. Implement this constructor to ensure that the XrSwapchainContext is properly initialized and ready for use in rendering operations within an OpenXR application.
| deviceContext | A reference to a DeviceContext instance that provides access to Vulkan resources and configurations needed for initializing the XrSwapchainContext. This context is essential for managing the swapchain and ensuring proper synchronization when acquiring images for rendering. |
Definition at line 46 of file XrSwapchainContext.cpp.

|
overridevirtual |
Acquires an image from the swapchain for rendering.
This method is responsible for acquiring an image from the swapchain, which can then be used for rendering operations. It takes the index of the swapchain image to acquire, the Vulkan device, a semaphore to signal when the image is available, a fence to ensure synchronization, and a reference to store the acquired image index. Implement this method to properly acquire images from the swapchain and ensure synchronization with rendering operations in an OpenXR application.
| index | The index of the swapchain image to acquire. |
| device | The Vulkan device used for acquiring the image. |
| imageAvailableSemaphore | A Vulkan semaphore that will be signaled when the image is available for rendering. |
| inFlightFence | A Vulkan fence used to ensure synchronization when acquiring the image. |
| imageIndex | A reference to store the index of the acquired image from the swapchain. |
Implements evan::ASwapchainContext.
Definition at line 358 of file XrSwapchainContext.cpp.
Destroys all swapchain images and clears the swapchain image collection.
This function iterates through all swapchain images stored in the context, destroys each image using the provided Vulkan device, and then clears the swapchain image collection.
| device | The Vulkan device handle used to destroy the swapchain images. |
Implements evan::ASwapchainContext.
Definition at line 303 of file XrSwapchainContext.cpp.
|
overridevirtual |
Retrieves the MSAA sample count used by this swapchain context.
The count is derived from the OpenXR runtime's recommended swapchain sample count.
Implements evan::ASwapchainContext.
Definition at line 466 of file XrSwapchainContext.cpp.
| const std::vector< XrCompositionLayerProjectionView > & evan::XrSwapchainContext::getProjectionLayerViews | ( | ) | const |
Retrieves the projection layer views for the current view configurations.
This method returns a reference to a vector of XrCompositionLayerProjectionView structures that represent the projection layer views for the current view configurations. These views are essential for rendering the scene accurately in an OpenXR application, as they provide the necessary information for projecting the scene onto the display. Implement this method to return the appropriate projection layer views based on the current view configurations.
Definition at line 451 of file XrSwapchainContext.cpp.
|
overridevirtual |
Retrieves the set of views to render (const).
Implements evan::ASwapchainContext.
Definition at line 461 of file XrSwapchainContext.cpp.
|
overridevirtual |
Retrieves the set of views to render (mutable).
Implements evan::ASwapchainContext.
Definition at line 456 of file XrSwapchainContext.cpp.
|
overridevirtual |
Recreates the swapchain and associated resources.
This function is responsible for recreating the swapchain and any associated resources when the swapchain becomes out of date or needs to be recreated due to changes in the window size or other factors. It takes a reference to the DeviceContext instance, which provides access to Vulkan resources and synchronization mechanisms, and the Vulkan render pass used for rendering operations. Implement this function to ensure that the swapchain is properly recreated and that all necessary resources are reinitialized for rendering operations.
| deviceContext | A reference to the DeviceContext instance that provides access to Vulkan resources and synchronization mechanisms. |
| renderpass | The Vulkan render pass that will be used with the swapchain images during rendering operations. |
Implements evan::ASwapchainContext.
Definition at line 316 of file XrSwapchainContext.cpp.

|
overridevirtual |
Sets the view matrix for a specific view index.
For OpenXR this method updates the near and far clipping planes used to build the per-eye projection matrices. The eye pose and field of view are refreshed by syncViewSet each frame. The requested pose is reduced to a persistent world-space offset relative to the tracked head center so locomotion survives the per-frame pose refresh.
| index | The index of the view for which to set the view matrix. |
| view | The view matrix to set for the specified view index. |
Reimplemented from evan::ASwapchainContext.
Definition at line 558 of file XrSwapchainContext.cpp.
| void evan::XrSwapchainContext::syncViewSet | ( | ) |
Rebuilds the ViewSet from the latest OpenXR view state.
Must be called after xrLocateViews (done in preprocessFrame) so the ViewSet reflects the current eye poses, fields of view and clipping planes before the renderer iterates over it.
Definition at line 476 of file XrSwapchainContext.cpp.
| void evan::XrSwapchainContext::updateProjectionLayerViews | ( | ) |
Updates the projection layer views based on current swapchain images and view data.
This function synchronizes the projection layer views with the available swapchain images and view information. It resizes the projection layer views container to match the smaller of the two collections (views or swapchain images) and populates each view with:
Each projection layer view is initialized with zero extent and offset (0, 0), and the image rectangle extent is set to the swapchain image dimensions. Dynamic cast is used to safely retrieve XrSwapchainImage instances; if a cast fails, that index is skipped.
Definition at line 398 of file XrSwapchainContext.cpp.
|
overridevirtual |
Indicates whether all views render into one layered swapchain.
True when the device supports multiview and the runtime accepted a swapchain with one array layer per view, so the renderer records a single pass covering every eye. False keeps the two-pass fallback (one swapchain per view).
Reimplemented from evan::ASwapchainContext.
Definition at line 471 of file XrSwapchainContext.cpp.
Waits for a swapchain image to become available.
Blocks until the swapchain image at the specified index is ready for rendering. Uses an infinite timeout duration to wait indefinitely for the image to be available.
| index | The index of the swapchain image to wait for. |
Implements evan::ASwapchainContext.
Definition at line 379 of file XrSwapchainContext.cpp.
| std::vector<XrView> evan::XrSwapchainContext::_views |
Vector of XrView structures for each view configuration.
Definition at line 270 of file XrSwapchainContext.hpp.
| std::vector<XrViewConfigurationView> evan::XrSwapchainContext::_viewsConfigurations |
Vector of XrViewConfigurationView structures for each view configuration, containing details about the recommended image rect dimensions and swapchain sample counts for each view.
Definition at line 277 of file XrSwapchainContext.hpp.