Cleanup: Avoid complex template type for XR-Swapchain

I rather avoid types like
`std::vector<std::unique_ptr<GHOST_XrSwapchain>>`, which is easy to do
in this case.
This commit is contained in:
Julian Eisel 2020-04-02 13:49:08 +02:00
parent 782e6ea4ed
commit 53d029d6da
3 changed files with 15 additions and 5 deletions

View File

@ -45,7 +45,7 @@ struct OpenXRSessionData {
XrSpace reference_space;
XrSpace view_space;
std::vector<XrView> views;
std::vector<std::unique_ptr<GHOST_XrSwapchain>> swapchains;
std::vector<GHOST_XrSwapchain> swapchains;
};
struct GHOST_XrDrawInfo {
@ -267,8 +267,7 @@ void GHOST_XrSession::prepareDrawing()
"Failed to get count of view configurations.");
for (const XrViewConfigurationView &view_config : view_configs) {
m_oxr->swapchains.push_back(std::unique_ptr<GHOST_XrSwapchain>(
new GHOST_XrSwapchain(*m_gpu_binding, m_oxr->session, view_config)));
m_oxr->swapchains.emplace_back(*m_gpu_binding, m_oxr->session, view_config);
}
m_oxr->views.resize(view_count, {XR_TYPE_VIEW});
@ -443,7 +442,7 @@ XrCompositionLayerProjection GHOST_XrSession::drawLayer(
r_proj_layer_views.resize(view_count);
for (uint32_t view_idx = 0; view_idx < view_count; view_idx++) {
drawView(*m_oxr->swapchains[view_idx],
drawView(m_oxr->swapchains[view_idx],
r_proj_layer_views[view_idx],
view_location,
m_oxr->views[view_idx],

View File

@ -92,9 +92,19 @@ GHOST_XrSwapchain::GHOST_XrSwapchain(GHOST_IXrGraphicsBinding &gpu_binding,
m_oxr->swapchain_images = swapchain_images_create(m_oxr->swapchain, gpu_binding);
}
GHOST_XrSwapchain::GHOST_XrSwapchain(GHOST_XrSwapchain &&other)
: m_oxr(std::move(other.m_oxr)),
m_image_width(other.m_image_width),
m_image_height(other.m_image_height)
{
/* Prevent xrDestroySwapchain call for the moved out item. */
other.m_oxr = nullptr;
}
GHOST_XrSwapchain::~GHOST_XrSwapchain()
{
if (m_oxr->swapchain != XR_NULL_HANDLE) {
/* m_oxr may be NULL after move. */
if (m_oxr && m_oxr->swapchain != XR_NULL_HANDLE) {
CHECK_XR_ASSERT(xrDestroySwapchain(m_oxr->swapchain));
}
}

View File

@ -30,6 +30,7 @@ class GHOST_XrSwapchain {
GHOST_XrSwapchain(GHOST_IXrGraphicsBinding &gpu_binding,
const XrSession &session,
const XrViewConfigurationView &view_config);
GHOST_XrSwapchain(GHOST_XrSwapchain &&other);
~GHOST_XrSwapchain();
XrSwapchainImageBaseHeader *acquireDrawableSwapchainImage();