| 1 | // SPDX-License-Identifier: LGPL-2.1-only |
| 2 | // Copyright (C) 2021 James Hogan <[email protected]> |
| 3 | |
| 4 | #include "SwapchainGroup.h" |
| 5 | |
| 6 | #include <osg/Notify> |
| 7 | |
| 8 | using namespace osgXR::OpenXR; |
| 9 | |
| 10 | SwapchainGroup::SwapchainGroup(osg::ref_ptr<Session> session, |
| 11 | const System::ViewConfiguration::View &view, |
| 12 | XrSwapchainUsageFlags usageFlags, |
| 13 | int64_t format, |
| 14 | XrSwapchainUsageFlags depthUsageFlags, |
| 15 | int64_t depthFormat) : |
| 16 | _swapchain(new Swapchain(session, view, usageFlags, format)) |
| 17 | { |
| 18 | if (depthFormat) |
| 19 | _depthSwapchain = new Swapchain(session, view, depthUsageFlags, depthFormat); |
| 20 | } |
| 21 | |
| 22 | SwapchainGroup::~SwapchainGroup() |
| 23 | { |
| 24 | } |
| 25 | |
| 26 | int SwapchainGroup::acquireImages() const |
| 27 | { |
| 28 | int imageIndex = _swapchain->acquireImage(); |
| 29 | if (depthValid()) |
| 30 | { |
| 31 | int depthImageIndex = _depthSwapchain->acquireImage(); |
| 32 | if (imageIndex != depthImageIndex) |
| 33 | OSG_WARN << "osgXR: Depth swapchain image mismatch, expected " << imageIndex |
| 34 | << ", got " << depthImageIndex << std::endl; |
| 35 | } |
| 36 | return imageIndex; |
| 37 | } |
| 38 | |
| 39 | bool SwapchainGroup::waitImages(XrDuration timeoutNs) const |
| 40 | { |
| 41 | bool ret = _swapchain->waitImage(timeoutNs); |
| 42 | if (depthValid()) |
| 43 | { |
| 44 | bool depthRet = _depthSwapchain->waitImage(timeoutNs); |
| 45 | ret = ret && depthRet; |
| 46 | } |
| 47 | return ret; |
| 48 | } |
| 49 | |
| 50 | void SwapchainGroup::releaseImages() const |
| 51 | { |
| 52 | _swapchain->releaseImage(); |
| 53 | if (depthValid()) |
| 54 | _depthSwapchain->releaseImage(); |
| 55 | } |