| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
#ifndef OSGXR_OPENXR_SWAPCHAIN |
| 5 |
#define OSGXR_OPENXR_SWAPCHAIN 1 |
| 6 |
|
| 7 |
#include "Session.h" |
| 8 |
#include "System.h" |
| 9 |
|
| 10 |
#include <osg/Referenced> |
| 11 |
#include <osg/Texture2D> |
| 12 |
#include <osg/ref_ptr> |
| 13 |
|
| 14 |
#include <cinttypes> |
| 15 |
#include <openxr/openxr.h> |
| 16 |
|
| 17 |
namespace osgXR { |
| 18 |
|
| 19 |
namespace OpenXR { |
| 20 |
|
| 21 |
class Swapchain : public osg::Referenced |
| 22 |
{ |
| 23 |
public: |
| 24 |
|
| 25 |
|
| 26 |
Swapchain(osg::ref_ptr<Session> session, |
| 27 |
const System::ViewConfiguration::View &view, |
| 28 |
XrSwapchainUsageFlags usageFlags, |
| 29 |
int64_t format); |
| 30 |
|
| 31 |
virtual ~Swapchain(); |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
inline bool valid() const |
| 36 |
{ |
| 37 |
return _swapchain != XR_NULL_HANDLE; |
| 38 |
} |
| 39 |
|
| 40 |
|
| 41 |
inline bool released() const |
| 42 |
{ |
| 43 |
return _released; |
| 44 |
} |
| 45 |
|
| 46 |
inline bool check(XrResult result, const char *actionMsg) const |
| 47 |
{ |
| 48 |
return _session->check(result, actionMsg); |
| 49 |
} |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
inline XrSession getXrSession() const |
| 54 |
{ |
| 55 |
return _session->getXrSession(); |
| 56 |
} |
| 57 |
|
| 58 |
inline XrSwapchain getXrSwapchain() const |
| 59 |
{ |
| 60 |
return _swapchain; |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
inline uint32_t getWidth() const |
| 66 |
{ |
| 67 |
return _width; |
| 68 |
} |
| 69 |
|
| 70 |
inline uint32_t getHeight() const |
| 71 |
{ |
| 72 |
return _height; |
| 73 |
} |
| 74 |
|
| 75 |
inline uint32_t getSamples() const |
| 76 |
{ |
| 77 |
return _samples; |
| 78 |
} |
| 79 |
|
| 80 |
inline int64_t getFormat() const |
| 81 |
{ |
| 82 |
return _format; |
| 83 |
} |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
typedef std::vector<GLuint> ImageTextures; |
| 88 |
|
| 89 |
const ImageTextures &getImageTextures() const; |
| 90 |
|
| 91 |
osg::ref_ptr<osg::Texture2D> getImageOsgTexture(unsigned int index) const; |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
int acquireImage() const; |
| 97 |
|
| 98 |
bool waitImage(XrDuration timeoutNs) const; |
| 99 |
|
| 100 |
void releaseImage() const; |
| 101 |
|
| 102 |
protected: |
| 103 |
|
| 104 |
|
| 105 |
osg::ref_ptr<Session> _session; |
| 106 |
XrSwapchain _swapchain; |
| 107 |
uint32_t _width; |
| 108 |
uint32_t _height; |
| 109 |
uint32_t _samples; |
| 110 |
int64_t _format; |
| 111 |
|
| 112 |
|
| 113 |
mutable bool _readImageTextures; |
| 114 |
mutable ImageTextures _imageTextures; |
| 115 |
mutable std::vector<osg::ref_ptr<osg::Texture2D>> _imageOsgTextures; |
| 116 |
|
| 117 |
mutable bool _released; |
| 118 |
}; |
| 119 |
|
| 120 |
} |
| 121 |
|
| 122 |
} |
| 123 |
|
| 124 |
#endif |