27 std::vector<XrSwapchainImageBaseHeader *> images;
30 CHECK_XR(xrEnumerateSwapchainImages(swapchain, 0, &image_count,
nullptr),
31 "Failed to get count of swapchain images to create for the VR session.");
33 CHECK_XR(xrEnumerateSwapchainImages(swapchain, images.size(), &image_count, images[0]),
34 "Failed to create swapchain images for the VR session.");
40 const XrSession &session,
41 const XrViewConfigurationView &view_config)
44 XrSwapchainCreateInfo create_info = {XR_TYPE_SWAPCHAIN_CREATE_INFO};
45 uint32_t format_count = 0;
47 CHECK_XR(xrEnumerateSwapchainFormats(session, 0, &format_count,
nullptr),
48 "Failed to get count of swapchain image formats.");
49 std::vector<int64_t> swapchain_formats(format_count);
50 CHECK_XR(xrEnumerateSwapchainFormats(
51 session, swapchain_formats.size(), &format_count, swapchain_formats.data()),
52 "Failed to get swapchain image formats.");
53 assert(swapchain_formats.size() == format_count);
56 swapchain_formats, format_, is_srgb_buffer_);
59 "Error: No format matching OpenXR runtime supported swapchain formats found.");
61 gpu_format_ = *chosen_format;
63 create_info.usageFlags = XR_SWAPCHAIN_USAGE_SAMPLED_BIT | XR_SWAPCHAIN_USAGE_TRANSFER_DST_BIT |
64 XR_SWAPCHAIN_USAGE_COLOR_ATTACHMENT_BIT;
65 create_info.format = *chosen_format;
66 create_info.sampleCount = view_config.recommendedSwapchainSampleCount;
67 create_info.width = view_config.recommendedImageRectWidth;
68 create_info.height = view_config.recommendedImageRectHeight;
69 create_info.faceCount = 1;
70 create_info.arraySize = 1;
71 create_info.mipCount = 1;
73 CHECK_XR(xrCreateSwapchain(session, &create_info, &oxr_->swapchain),
74 "Failed to create OpenXR swapchain.");
76 image_width_ = create_info.width;
77 image_height_ = create_info.height;
83 : oxr_(std::move(other.oxr_)),
84 image_width_(other.image_width_),
85 image_height_(other.image_height_),
86 format_(other.format_),
87 gpu_format_(other.gpu_format_),
88 is_srgb_buffer_(other.is_srgb_buffer_)
105 XrSwapchainImageAcquireInfo acquire_info = {XR_TYPE_SWAPCHAIN_IMAGE_ACQUIRE_INFO};
106 XrSwapchainImageWaitInfo wait_info = {XR_TYPE_SWAPCHAIN_IMAGE_WAIT_INFO};
109 CHECK_XR(xrAcquireSwapchainImage(oxr_->swapchain, &acquire_info, &image_idx),
110 "Failed to acquire swapchain image for the VR session.");
111 wait_info.timeout = XR_INFINITE_DURATION;
112 CHECK_XR(xrWaitSwapchainImage(oxr_->swapchain, &wait_info),
113 "Failed to acquire swapchain image for the VR session.");
115 return oxr_->swapchain_images[image_idx];