3#include <glm/ext/matrix_float4x4.hpp>
4#include <glm/gtc/quaternion.hpp>
6#include <openxr/openxr.h>
8#include <vulkan/vulkan_core.h>
The application context is the core class which stores the basic openxr and vulkan objects.
void requestExitSession()
Requests the XR runtime to exit the session gracefully. This should be called when the application wa...
std::vector< RenderTarget > swapchainRenderTargets
Render target wrappers for OpenXR swapchain images.
void endXrFrameNoRender()
Ends an OpenXR frame without releasing a swapchain image or submitting projection layers.
void beginXrSession() const
Begins the OpenXR session for the configured primary view type.
bool isExistRequested
True once OpenXR or the application requests session exit.
glm::quat transformPlaySpaceOrientation(const glm::quat &orientation) const
Converts an OpenXR play-space orientation into world space.
void setSessionStateCallback(std::function< void(XrSessionState)> callback)
Registers a callback invoked whenever the OpenXR session state changes.
std::vector< XrViewConfigurationView > eyeImageInfos
Runtime-recommended image settings per eye.
XrSpace getReferenceSpace() const
Returns the OpenXR reference space used for view location and layer submission.
std::vector< XrView > eyePoses
Eye poses and fields of view from the latest xrLocateViews() call.
std::vector< XrCompositionLayerProjectionView > eyeRenderInfos
Projection-layer views submitted to xrEndFrame().
VkImage getDepthBufferImage() const
Returns the depth image used by headset rendering.
glm::quat getHeadsetLocalOrientation() const
Gets the headset's local orientation relative to the play space.
XrFrameState getXrFrameState() const
Returns the latest OpenXR frame state.
VkImage getColorBufferImage() const
Returns the multisampled color image used by headset rendering.
VkRenderPass getRenderPass() const
Returns the legacy multiview render pass.
VkImage getSwapchainImage(size_t swapchainImageIndex) const
Returns a borrowed OpenXR swapchain image handle.
VkImageView getDepthBufferView() const
Returns the depth image view used by headset rendering.
void setPlayerRotation(const glm::quat &rotation)
Setter for the player/play-space rotation applied around the world origin.
BeginFrameResult beginXrFrame(uint32_t &swapchainImageIndex, Renderer *renderer)
Runs waitForXrFrame() and beginXrFrameAfterWait() as a single legacy call.
glm::vec3 getPlayerPosition() const
Returns the current player/play-space world position.
std::function< void(XrSessionState)> sessionStateCallback_
Invoked on OpenXR session state changes.
XrSpace xrReferenceSpace
Reference space used to locate views and submit layers.
XrReferenceSpaceType xrReferenceSpaceType
Configured reference-space type.
XrSessionState xrSessionState
Current OpenXR session lifecycle state.
VkFormat getColorFormat() const
Returns the format used by XR swapchain color attachment views.
void endXrSession() const
Ends the active OpenXR session.
uint32_t getEyeCount() const
Returns the number of configured XR views.
glm::mat4 getEyeProjectionMatrix(size_t eyeIndex) const
Gets the projection matrix for an eye.
glm::vec3 transformPlaySpacePosition(const glm::vec3 &position) const
Converts an OpenXR play-space position into world space.
VkFormat getSceneColorFormat() const
Returns the HDR scene color format used for engine-owned color and resolve buffers.
VkRenderPass vkRenderPass
Legacy multiview render pass used by framebuffer rendering.
ImageBuffer depthBuffer
Multisampled depth attachment, also sampled by Hi-Z generation.
VkImage getResolveBufferImage() const
Returns the single-sample resolve image used before XR swapchain tonemapping.
XrViewState xrViewState
Validity flags for the latest xrLocateViews() result.
ImageBuffer resolveBuffer
Single-sample HDR resolve target before tonemapping to the XR swapchain.
VkFormat colorFormat_
VkFormat used for OpenXR swapchain image views.
glm::mat4 getRawEyeViewMatrix(size_t eyeIndex) const
Returns the raw OpenXR view matrix for an eye.
VkFormat swapchainFormat_
VkFormat used when creating the OpenXR swapchain.
Headset(const Core::ApplicationContext *context=nullptr)
Creates OpenXR session, reference space, render pass, images, swapchain, and eye state.
const Core::ApplicationContext * context
Application context that owns Vulkan and OpenXR handles.
glm::vec3 playerPosition_
World-space player/play-space offset.
glm::quat playerRotation_
World-space player/play-space rotation.
XrFrameState xrFrameState
State returned by the latest xrWaitFrame() call.
~Headset()
Does not release GPU or OpenXR resources; call cleanup() before destruction.
void endXrFrame()
Releases the acquired swapchain image and submits projection layers to xrEndFrame().
XrSwapchain xrSwapchain
OpenXR color swapchain submitted to the runtime.
XrSession getSession() const
Returns the OpenXR session handle.
std::unique_ptr< NamedThreadPool > xrWaitThreadPool_
Thread pool used to timeout xrWaitFrame() safely.
void setInteractionProfileChangedCallback(std::function< void()> callback)
Registers a callback invoked when the runtime reports an interaction profile change.
XrSession xrSession
OpenXR session created for the application context's system id.
ImageBuffer colorBuffer
Multisampled HDR color attachment for multiview rendering.
BeginFrameResult
Frame-begin outcome returned by XR frame lifecycle functions.
@ ComputeOnly
Run compute work but skip XR and mesh rendering.
@ RenderFully
Render this frame normally.
@ SkipFully
Skip processing the frame without calling xrEndFrame().
@ SkipRender
Skip rendering but still end the OpenXR frame.
@ Error
An OpenXR error occurred.
std::vector< Eye > eyes
Cached eye matrices indexed by zero-based eye index.
void setPlayerPosition(const glm::vec3 &position)
Sets the player/play-space world position.
bool useMutableSwapchainFormat_
True when swapchain views use a different color format.
void updateViewMatrix()
Updates cached eye view and projection matrices from the latest OpenXR eye poses.
uint32_t eyeCount
Number of views reported by the OpenXR runtime.
WaitFrameResult waitForXrFrame(Rendering::Renderer *renderer)
First part of frame setup: calls xrWaitFrame. Can be called before previous xrEndFrame completes....
glm::vec3 getHeadsetLocalPosition() const
Gets the headset's local position relative to the play space origin.
BeginFrameResult beginXrFrameAfterWait(uint32_t &swapchainImageIndex)
Second part of frame setup: calls xrBeginFrame, acquires swapchain image. MUST be called after previo...
void cleanup()
Releases owned Vulkan image buffers, swapchain render targets, render pass, reference space,...
std::vector< RenderTarget > getSwapchainRenderTargets()
Returns a copy of the swapchain render-target list.
glm::quat getHeadsetWorldOrientation() const
Gets the headset orientation after player rotation is applied.
std::function< void()> interactionProfileChangedCallback_
Invoked on OpenXR interaction profile changes.
bool getIsExitRequested() const
Returns whether OpenXR requested application exit or session shutdown.
VkFormat sceneColorFormat_
HDR format for engine-owned scene buffers.
glm::mat4 getEyeViewMatrix(size_t eyeIndex) const
Returns the world-adjusted view matrix for an eye.
glm::mat4 getViewProjectionMatrix(size_t eyeIndex) const
Gets the projection-view matrix for an eye.
glm::quat getPlayerRotation() const
Returns the player/play-space rotation.
glm::vec3 getHeadsetWorldPosition() const
Gets the headset position after player position/rotation are applied.
XrTime lastUpdateTime
Reserved timestamp for future pose update tracking.
VkExtent2D getEyeResolution(size_t eyeIndex) const
Returns the recommended render resolution for an eye.
const RenderTarget * getRenderTarget(size_t swapchainImageIndex) const
Returns the render target for a swapchain image.
VkImageView getColorBufferView() const
Returns the multisampled color image view used by headset rendering.
VkImageView getResolveBufferView() const
Returns the single-sample resolve image view used before XR swapchain tonemapping.
Cached matrices for one eye.
glm::mat4 eyeViewMatrix
Raw OpenXR eye view matrix before player transform.
glm::mat4 eyeProjectionMatrix
Projection matrix built from the OpenXR eye field of view.
Engine-owned Vulkan image, memory, and view tuple.
void cleanup(const Core::ApplicationContext *context)
Destroys image view, image, and device memory.
VkImageView imageView
Image view for rendering or sampling.
VkImage image
Vulkan image owned by Headset.
VkDeviceMemory deviceMemory
Device-local memory bound to image.
Result from waitForXrFrame() indicating how the main loop should continue.
bool shouldCallBeginFrame
True when beginXrFrameAfterWait() must be called before ending the frame.
BeginFrameResult result
Recommended frame action after xrWaitFrame() and event polling.
bool needsGpuSyncForStateTransition
True when the main loop must perform deferred GPU sync.
Render target wrapper for one OpenXR swapchain image.
VkImageView imageView
View used when sampling or copying the swapchain image.
VkImageLayout imageLayout
Tracked layout for legacy render-target paths.
VkImage image
Borrowed swapchain image for this render target.
VkFramebuffer framebuffer
Legacy render-pass framebuffer for this swapchain image.
void cleanup(const Core::ApplicationContext *context)
Destroys framebuffer and image view resources for this render target.